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 sband = priv->hw->wiphy->bands[priv->hw->conf.channel->band];
348 for (i = 0, j = 0; i < sband->n_bitrates; i++) {
349 if (sta->supp_rates[sband->band] & BIT(i)) {
350 trate->rates.legacy_rates.rs_rates[j]
351 = (sband->bitrates[i].bitrate * 2) / 10;
355 trate->rates.legacy_rates.rs_nrates = j;
357 if (sta->ht_cap.ht_supported) {
358 for (i = 0, j = 0; i < 77; i++) {
359 if (sta->ht_cap.mcs.rx_mask[i/8] & (1<<(i%8)))
360 trate->rates.ht_rates.rs_rates[j++] = i;
361 if (j == ATH_HTC_RATE_MAX)
364 trate->rates.ht_rates.rs_nrates = j;
366 caps = WLAN_RC_HT_FLAG;
367 if (priv->ah->caps.tx_chainmask != 1 &&
368 ath9k_hw_getcapability(priv->ah, ATH9K_CAP_DS, 0, NULL)) {
369 if (sta->ht_cap.mcs.rx_mask[1])
370 caps |= WLAN_RC_DS_FLAG;
372 if (sta->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40)
373 caps |= WLAN_RC_40_FLAG;
374 if (conf_is_ht40(&priv->hw->conf) &&
375 (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_40))
376 caps |= WLAN_RC_SGI_FLAG;
377 else if (conf_is_ht20(&priv->hw->conf) &&
378 (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_20))
379 caps |= WLAN_RC_SGI_FLAG;
382 trate->sta_index = ista->index;
384 trate->capflags = cpu_to_be32(caps);
387 static int ath9k_htc_send_rate_cmd(struct ath9k_htc_priv *priv,
388 struct ath9k_htc_target_rate *trate)
390 struct ath_common *common = ath9k_hw_common(priv->ah);
394 WMI_CMD_BUF(WMI_RC_RATE_UPDATE_CMDID, trate);
396 ath_print(common, ATH_DBG_FATAL,
397 "Unable to initialize Rate information on target\n");
403 static void ath9k_htc_init_rate(struct ath9k_htc_priv *priv,
404 struct ieee80211_sta *sta)
406 struct ath_common *common = ath9k_hw_common(priv->ah);
407 struct ath9k_htc_target_rate trate;
410 memset(&trate, 0, sizeof(struct ath9k_htc_target_rate));
411 ath9k_htc_setup_rate(priv, sta, &trate);
412 ret = ath9k_htc_send_rate_cmd(priv, &trate);
414 ath_print(common, ATH_DBG_CONFIG,
415 "Updated target sta: %pM, rate caps: 0x%X\n",
416 sta->addr, be32_to_cpu(trate.capflags));
419 static void ath9k_htc_update_rate(struct ath9k_htc_priv *priv,
420 struct ieee80211_vif *vif,
421 struct ieee80211_bss_conf *bss_conf)
423 struct ath_common *common = ath9k_hw_common(priv->ah);
424 struct ath9k_htc_target_rate trate;
425 struct ieee80211_sta *sta;
428 memset(&trate, 0, sizeof(struct ath9k_htc_target_rate));
431 sta = ieee80211_find_sta(vif, bss_conf->bssid);
436 ath9k_htc_setup_rate(priv, sta, &trate);
439 ret = ath9k_htc_send_rate_cmd(priv, &trate);
441 ath_print(common, ATH_DBG_CONFIG,
442 "Updated target sta: %pM, rate caps: 0x%X\n",
443 bss_conf->bssid, be32_to_cpu(trate.capflags));
446 static int ath9k_htc_aggr_oper(struct ath9k_htc_priv *priv,
447 struct ieee80211_vif *vif,
448 u8 *sta_addr, u8 tid, bool oper)
450 struct ath_common *common = ath9k_hw_common(priv->ah);
451 struct ath9k_htc_target_aggr aggr;
452 struct ieee80211_sta *sta = NULL;
453 struct ath9k_htc_sta *ista;
457 if (tid >= ATH9K_HTC_MAX_TID)
460 memset(&aggr, 0, sizeof(struct ath9k_htc_target_aggr));
464 /* Check if we are able to retrieve the station */
465 sta = ieee80211_find_sta(vif, sta_addr);
471 ista = (struct ath9k_htc_sta *) sta->drv_priv;
474 ista->tid_state[tid] = AGGR_START;
476 ista->tid_state[tid] = AGGR_STOP;
478 aggr.sta_index = ista->index;
483 aggr.aggr_enable = oper;
485 WMI_CMD_BUF(WMI_TX_AGGR_ENABLE_CMDID, &aggr);
487 ath_print(common, ATH_DBG_CONFIG,
488 "Unable to %s TX aggregation for (%pM, %d)\n",
489 (oper) ? "start" : "stop", sta->addr, tid);
491 ath_print(common, ATH_DBG_CONFIG,
492 "%s aggregation for (%pM, %d)\n",
493 (oper) ? "Starting" : "Stopping", sta->addr, tid);
498 void ath9k_htc_aggr_work(struct work_struct *work)
501 struct ath9k_htc_priv *priv =
502 container_of(work, struct ath9k_htc_priv,
503 ath9k_aggr_work.work);
504 struct ath9k_htc_aggr_work *wk = &priv->aggr_work;
506 mutex_lock(&wk->mutex);
508 switch (wk->action) {
509 case IEEE80211_AMPDU_TX_START:
510 ret = ath9k_htc_aggr_oper(priv, wk->vif, wk->sta_addr,
513 ieee80211_start_tx_ba_cb(wk->vif, wk->sta_addr,
516 case IEEE80211_AMPDU_TX_STOP:
517 ath9k_htc_aggr_oper(priv, wk->vif, wk->sta_addr,
519 ieee80211_stop_tx_ba_cb(wk->vif, wk->sta_addr, wk->tid);
522 ath_print(ath9k_hw_common(priv->ah), ATH_DBG_FATAL,
523 "Unknown AMPDU action\n");
526 mutex_unlock(&wk->mutex);
533 #ifdef CONFIG_ATH9K_HTC_DEBUGFS
535 static int ath9k_debugfs_open(struct inode *inode, struct file *file)
537 file->private_data = inode->i_private;
541 static ssize_t read_file_tgt_stats(struct file *file, char __user *user_buf,
542 size_t count, loff_t *ppos)
544 struct ath9k_htc_priv *priv =
545 (struct ath9k_htc_priv *) file->private_data;
546 struct ath9k_htc_target_stats cmd_rsp;
548 unsigned int len = 0;
551 memset(&cmd_rsp, 0, sizeof(cmd_rsp));
553 WMI_CMD(WMI_TGT_STATS_CMDID);
558 len += snprintf(buf + len, sizeof(buf) - len,
559 "%19s : %10u\n", "TX Short Retries",
560 be32_to_cpu(cmd_rsp.tx_shortretry));
561 len += snprintf(buf + len, sizeof(buf) - len,
562 "%19s : %10u\n", "TX Long Retries",
563 be32_to_cpu(cmd_rsp.tx_longretry));
564 len += snprintf(buf + len, sizeof(buf) - len,
565 "%19s : %10u\n", "TX Xretries",
566 be32_to_cpu(cmd_rsp.tx_xretries));
567 len += snprintf(buf + len, sizeof(buf) - len,
568 "%19s : %10u\n", "TX Unaggr. Xretries",
569 be32_to_cpu(cmd_rsp.ht_txunaggr_xretry));
570 len += snprintf(buf + len, sizeof(buf) - len,
571 "%19s : %10u\n", "TX Xretries (HT)",
572 be32_to_cpu(cmd_rsp.ht_tx_xretries));
573 len += snprintf(buf + len, sizeof(buf) - len,
574 "%19s : %10u\n", "TX Rate", priv->debug.txrate);
576 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
579 static const struct file_operations fops_tgt_stats = {
580 .read = read_file_tgt_stats,
581 .open = ath9k_debugfs_open,
585 static ssize_t read_file_xmit(struct file *file, char __user *user_buf,
586 size_t count, loff_t *ppos)
588 struct ath9k_htc_priv *priv =
589 (struct ath9k_htc_priv *) file->private_data;
591 unsigned int len = 0;
593 len += snprintf(buf + len, sizeof(buf) - len,
594 "%20s : %10u\n", "Buffers queued",
595 priv->debug.tx_stats.buf_queued);
596 len += snprintf(buf + len, sizeof(buf) - len,
597 "%20s : %10u\n", "Buffers completed",
598 priv->debug.tx_stats.buf_completed);
599 len += snprintf(buf + len, sizeof(buf) - len,
600 "%20s : %10u\n", "SKBs queued",
601 priv->debug.tx_stats.skb_queued);
602 len += snprintf(buf + len, sizeof(buf) - len,
603 "%20s : %10u\n", "SKBs completed",
604 priv->debug.tx_stats.skb_completed);
605 len += snprintf(buf + len, sizeof(buf) - len,
606 "%20s : %10u\n", "SKBs dropped",
607 priv->debug.tx_stats.skb_dropped);
609 len += snprintf(buf + len, sizeof(buf) - len,
610 "%20s : %10u\n", "BE queued",
611 priv->debug.tx_stats.queue_stats[WME_AC_BE]);
612 len += snprintf(buf + len, sizeof(buf) - len,
613 "%20s : %10u\n", "BK queued",
614 priv->debug.tx_stats.queue_stats[WME_AC_BK]);
615 len += snprintf(buf + len, sizeof(buf) - len,
616 "%20s : %10u\n", "VI queued",
617 priv->debug.tx_stats.queue_stats[WME_AC_VI]);
618 len += snprintf(buf + len, sizeof(buf) - len,
619 "%20s : %10u\n", "VO queued",
620 priv->debug.tx_stats.queue_stats[WME_AC_VO]);
622 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
625 static const struct file_operations fops_xmit = {
626 .read = read_file_xmit,
627 .open = ath9k_debugfs_open,
631 static ssize_t read_file_recv(struct file *file, char __user *user_buf,
632 size_t count, loff_t *ppos)
634 struct ath9k_htc_priv *priv =
635 (struct ath9k_htc_priv *) file->private_data;
637 unsigned int len = 0;
639 len += snprintf(buf + len, sizeof(buf) - len,
640 "%20s : %10u\n", "SKBs allocated",
641 priv->debug.rx_stats.skb_allocated);
642 len += snprintf(buf + len, sizeof(buf) - len,
643 "%20s : %10u\n", "SKBs completed",
644 priv->debug.rx_stats.skb_completed);
645 len += snprintf(buf + len, sizeof(buf) - len,
646 "%20s : %10u\n", "SKBs Dropped",
647 priv->debug.rx_stats.skb_dropped);
649 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
652 static const struct file_operations fops_recv = {
653 .read = read_file_recv,
654 .open = ath9k_debugfs_open,
658 int ath9k_htc_init_debug(struct ath_hw *ah)
660 struct ath_common *common = ath9k_hw_common(ah);
661 struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *) common->priv;
663 if (!ath9k_debugfs_root)
666 priv->debug.debugfs_phy = debugfs_create_dir(wiphy_name(priv->hw->wiphy),
668 if (!priv->debug.debugfs_phy)
671 priv->debug.debugfs_tgt_stats = debugfs_create_file("tgt_stats", S_IRUSR,
672 priv->debug.debugfs_phy,
673 priv, &fops_tgt_stats);
674 if (!priv->debug.debugfs_tgt_stats)
678 priv->debug.debugfs_xmit = debugfs_create_file("xmit", S_IRUSR,
679 priv->debug.debugfs_phy,
681 if (!priv->debug.debugfs_xmit)
684 priv->debug.debugfs_recv = debugfs_create_file("recv", S_IRUSR,
685 priv->debug.debugfs_phy,
687 if (!priv->debug.debugfs_recv)
693 ath9k_htc_exit_debug(ah);
697 void ath9k_htc_exit_debug(struct ath_hw *ah)
699 struct ath_common *common = ath9k_hw_common(ah);
700 struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *) common->priv;
702 debugfs_remove(priv->debug.debugfs_recv);
703 debugfs_remove(priv->debug.debugfs_xmit);
704 debugfs_remove(priv->debug.debugfs_tgt_stats);
705 debugfs_remove(priv->debug.debugfs_phy);
708 int ath9k_htc_debug_create_root(void)
710 ath9k_debugfs_root = debugfs_create_dir(KBUILD_MODNAME, NULL);
711 if (!ath9k_debugfs_root)
717 void ath9k_htc_debug_remove_root(void)
719 debugfs_remove(ath9k_debugfs_root);
720 ath9k_debugfs_root = NULL;
723 #endif /* CONFIG_ATH9K_HTC_DEBUGFS */
729 static void ath_start_ani(struct ath9k_htc_priv *priv)
731 struct ath_common *common = ath9k_hw_common(priv->ah);
732 unsigned long timestamp = jiffies_to_msecs(jiffies);
734 common->ani.longcal_timer = timestamp;
735 common->ani.shortcal_timer = timestamp;
736 common->ani.checkani_timer = timestamp;
738 ieee80211_queue_delayed_work(common->hw, &priv->ath9k_ani_work,
739 msecs_to_jiffies(ATH_ANI_POLLINTERVAL));
742 void ath9k_ani_work(struct work_struct *work)
744 struct ath9k_htc_priv *priv =
745 container_of(work, struct ath9k_htc_priv,
746 ath9k_ani_work.work);
747 struct ath_hw *ah = priv->ah;
748 struct ath_common *common = ath9k_hw_common(ah);
749 bool longcal = false;
750 bool shortcal = false;
751 bool aniflag = false;
752 unsigned int timestamp = jiffies_to_msecs(jiffies);
753 u32 cal_interval, short_cal_interval;
755 short_cal_interval = ATH_STA_SHORT_CALINTERVAL;
757 /* Only calibrate if awake */
758 if (ah->power_mode != ATH9K_PM_AWAKE)
761 /* Long calibration runs independently of short calibration. */
762 if ((timestamp - common->ani.longcal_timer) >= ATH_LONG_CALINTERVAL) {
764 ath_print(common, ATH_DBG_ANI, "longcal @%lu\n", jiffies);
765 common->ani.longcal_timer = timestamp;
768 /* Short calibration applies only while caldone is false */
769 if (!common->ani.caldone) {
770 if ((timestamp - common->ani.shortcal_timer) >=
771 short_cal_interval) {
773 ath_print(common, ATH_DBG_ANI,
774 "shortcal @%lu\n", jiffies);
775 common->ani.shortcal_timer = timestamp;
776 common->ani.resetcal_timer = timestamp;
779 if ((timestamp - common->ani.resetcal_timer) >=
780 ATH_RESTART_CALINTERVAL) {
781 common->ani.caldone = ath9k_hw_reset_calvalid(ah);
782 if (common->ani.caldone)
783 common->ani.resetcal_timer = timestamp;
787 /* Verify whether we must check ANI */
788 if ((timestamp - common->ani.checkani_timer) >= ATH_ANI_POLLINTERVAL) {
790 common->ani.checkani_timer = timestamp;
793 /* Skip all processing if there's nothing to do. */
794 if (longcal || shortcal || aniflag) {
796 ath9k_htc_ps_wakeup(priv);
798 /* Call ANI routine if necessary */
800 ath9k_hw_ani_monitor(ah, ah->curchan);
802 /* Perform calibration if necessary */
803 if (longcal || shortcal) {
804 common->ani.caldone =
805 ath9k_hw_calibrate(ah, ah->curchan,
806 common->rx_chainmask,
810 common->ani.noise_floor =
811 ath9k_hw_getchan_noise(ah, ah->curchan);
813 ath_print(common, ATH_DBG_ANI,
814 " calibrate chan %u/%x nf: %d\n",
815 ah->curchan->channel,
816 ah->curchan->channelFlags,
817 common->ani.noise_floor);
820 ath9k_htc_ps_restore(priv);
825 * Set timer interval based on previous results.
826 * The interval must be the shortest necessary to satisfy ANI,
827 * short calibration and long calibration.
829 cal_interval = ATH_LONG_CALINTERVAL;
830 if (priv->ah->config.enable_ani)
831 cal_interval = min(cal_interval, (u32)ATH_ANI_POLLINTERVAL);
832 if (!common->ani.caldone)
833 cal_interval = min(cal_interval, (u32)short_cal_interval);
835 ieee80211_queue_delayed_work(common->hw, &priv->ath9k_ani_work,
836 msecs_to_jiffies(cal_interval));
843 static void ath9k_led_blink_work(struct work_struct *work)
845 struct ath9k_htc_priv *priv = container_of(work, struct ath9k_htc_priv,
846 ath9k_led_blink_work.work);
848 if (!(priv->op_flags & OP_LED_ASSOCIATED))
851 if ((priv->led_on_duration == ATH_LED_ON_DURATION_IDLE) ||
852 (priv->led_off_duration == ATH_LED_OFF_DURATION_IDLE))
853 ath9k_hw_set_gpio(priv->ah, priv->ah->led_pin, 0);
855 ath9k_hw_set_gpio(priv->ah, priv->ah->led_pin,
856 (priv->op_flags & OP_LED_ON) ? 1 : 0);
858 ieee80211_queue_delayed_work(priv->hw,
859 &priv->ath9k_led_blink_work,
860 (priv->op_flags & OP_LED_ON) ?
861 msecs_to_jiffies(priv->led_off_duration) :
862 msecs_to_jiffies(priv->led_on_duration));
864 priv->led_on_duration = priv->led_on_cnt ?
865 max((ATH_LED_ON_DURATION_IDLE - priv->led_on_cnt), 25) :
866 ATH_LED_ON_DURATION_IDLE;
867 priv->led_off_duration = priv->led_off_cnt ?
868 max((ATH_LED_OFF_DURATION_IDLE - priv->led_off_cnt), 10) :
869 ATH_LED_OFF_DURATION_IDLE;
870 priv->led_on_cnt = priv->led_off_cnt = 0;
872 if (priv->op_flags & OP_LED_ON)
873 priv->op_flags &= ~OP_LED_ON;
875 priv->op_flags |= OP_LED_ON;
878 static void ath9k_led_brightness_work(struct work_struct *work)
880 struct ath_led *led = container_of(work, struct ath_led,
881 brightness_work.work);
882 struct ath9k_htc_priv *priv = led->priv;
884 switch (led->brightness) {
886 if (led->led_type == ATH_LED_ASSOC ||
887 led->led_type == ATH_LED_RADIO) {
888 ath9k_hw_set_gpio(priv->ah, priv->ah->led_pin,
889 (led->led_type == ATH_LED_RADIO));
890 priv->op_flags &= ~OP_LED_ASSOCIATED;
891 if (led->led_type == ATH_LED_RADIO)
892 priv->op_flags &= ~OP_LED_ON;
898 if (led->led_type == ATH_LED_ASSOC) {
899 priv->op_flags |= OP_LED_ASSOCIATED;
900 ieee80211_queue_delayed_work(priv->hw,
901 &priv->ath9k_led_blink_work, 0);
902 } else if (led->led_type == ATH_LED_RADIO) {
903 ath9k_hw_set_gpio(priv->ah, priv->ah->led_pin, 0);
904 priv->op_flags |= OP_LED_ON;
914 static void ath9k_led_brightness(struct led_classdev *led_cdev,
915 enum led_brightness brightness)
917 struct ath_led *led = container_of(led_cdev, struct ath_led, led_cdev);
918 struct ath9k_htc_priv *priv = led->priv;
920 led->brightness = brightness;
921 if (!(priv->op_flags & OP_LED_DEINIT))
922 ieee80211_queue_delayed_work(priv->hw,
923 &led->brightness_work, 0);
926 static void ath9k_led_stop_brightness(struct ath9k_htc_priv *priv)
928 cancel_delayed_work_sync(&priv->radio_led.brightness_work);
929 cancel_delayed_work_sync(&priv->assoc_led.brightness_work);
930 cancel_delayed_work_sync(&priv->tx_led.brightness_work);
931 cancel_delayed_work_sync(&priv->rx_led.brightness_work);
934 static int ath9k_register_led(struct ath9k_htc_priv *priv, struct ath_led *led,
940 led->led_cdev.name = led->name;
941 led->led_cdev.default_trigger = trigger;
942 led->led_cdev.brightness_set = ath9k_led_brightness;
944 ret = led_classdev_register(wiphy_dev(priv->hw->wiphy), &led->led_cdev);
946 ath_print(ath9k_hw_common(priv->ah), ATH_DBG_FATAL,
947 "Failed to register led:%s", led->name);
951 INIT_DELAYED_WORK(&led->brightness_work, ath9k_led_brightness_work);
956 static void ath9k_unregister_led(struct ath_led *led)
958 if (led->registered) {
959 led_classdev_unregister(&led->led_cdev);
964 void ath9k_deinit_leds(struct ath9k_htc_priv *priv)
966 priv->op_flags |= OP_LED_DEINIT;
967 ath9k_unregister_led(&priv->assoc_led);
968 priv->op_flags &= ~OP_LED_ASSOCIATED;
969 ath9k_unregister_led(&priv->tx_led);
970 ath9k_unregister_led(&priv->rx_led);
971 ath9k_unregister_led(&priv->radio_led);
974 void ath9k_init_leds(struct ath9k_htc_priv *priv)
979 if (AR_SREV_9287(priv->ah))
980 priv->ah->led_pin = ATH_LED_PIN_9287;
981 else if (AR_SREV_9271(priv->ah))
982 priv->ah->led_pin = ATH_LED_PIN_9271;
984 priv->ah->led_pin = ATH_LED_PIN_DEF;
986 /* Configure gpio 1 for output */
987 ath9k_hw_cfg_output(priv->ah, priv->ah->led_pin,
988 AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
989 /* LED off, active low */
990 ath9k_hw_set_gpio(priv->ah, priv->ah->led_pin, 1);
992 INIT_DELAYED_WORK(&priv->ath9k_led_blink_work, ath9k_led_blink_work);
994 trigger = ieee80211_get_radio_led_name(priv->hw);
995 snprintf(priv->radio_led.name, sizeof(priv->radio_led.name),
996 "ath9k-%s::radio", wiphy_name(priv->hw->wiphy));
997 ret = ath9k_register_led(priv, &priv->radio_led, trigger);
998 priv->radio_led.led_type = ATH_LED_RADIO;
1002 trigger = ieee80211_get_assoc_led_name(priv->hw);
1003 snprintf(priv->assoc_led.name, sizeof(priv->assoc_led.name),
1004 "ath9k-%s::assoc", wiphy_name(priv->hw->wiphy));
1005 ret = ath9k_register_led(priv, &priv->assoc_led, trigger);
1006 priv->assoc_led.led_type = ATH_LED_ASSOC;
1010 trigger = ieee80211_get_tx_led_name(priv->hw);
1011 snprintf(priv->tx_led.name, sizeof(priv->tx_led.name),
1012 "ath9k-%s::tx", wiphy_name(priv->hw->wiphy));
1013 ret = ath9k_register_led(priv, &priv->tx_led, trigger);
1014 priv->tx_led.led_type = ATH_LED_TX;
1018 trigger = ieee80211_get_rx_led_name(priv->hw);
1019 snprintf(priv->rx_led.name, sizeof(priv->rx_led.name),
1020 "ath9k-%s::rx", wiphy_name(priv->hw->wiphy));
1021 ret = ath9k_register_led(priv, &priv->rx_led, trigger);
1022 priv->rx_led.led_type = ATH_LED_RX;
1026 priv->op_flags &= ~OP_LED_DEINIT;
1031 cancel_delayed_work_sync(&priv->ath9k_led_blink_work);
1032 ath9k_deinit_leds(priv);
1035 /*******************/
1037 /*******************/
1039 static bool ath_is_rfkill_set(struct ath9k_htc_priv *priv)
1041 return ath9k_hw_gpio_get(priv->ah, priv->ah->rfkill_gpio) ==
1042 priv->ah->rfkill_polarity;
1045 static void ath9k_htc_rfkill_poll_state(struct ieee80211_hw *hw)
1047 struct ath9k_htc_priv *priv = hw->priv;
1048 bool blocked = !!ath_is_rfkill_set(priv);
1050 wiphy_rfkill_set_hw_state(hw->wiphy, blocked);
1053 void ath9k_start_rfkill_poll(struct ath9k_htc_priv *priv)
1055 if (priv->ah->caps.hw_caps & ATH9K_HW_CAP_RFSILENT)
1056 wiphy_rfkill_start_polling(priv->hw->wiphy);
1059 static void ath9k_htc_radio_enable(struct ieee80211_hw *hw)
1061 struct ath9k_htc_priv *priv = hw->priv;
1062 struct ath_hw *ah = priv->ah;
1063 struct ath_common *common = ath9k_hw_common(ah);
1068 ah->curchan = ath9k_cmn_get_curchannel(hw, ah);
1071 ret = ath9k_hw_reset(ah, ah->curchan, false);
1073 ath_print(common, ATH_DBG_FATAL,
1074 "Unable to reset hardware; reset status %d "
1075 "(freq %u MHz)\n", ret, ah->curchan->channel);
1078 ath_update_txpow(priv);
1081 WMI_CMD(WMI_START_RECV_CMDID);
1082 ath9k_host_rx_init(priv);
1085 htc_start(priv->htc);
1086 spin_lock_bh(&priv->tx_lock);
1087 priv->tx_queues_stop = false;
1088 spin_unlock_bh(&priv->tx_lock);
1089 ieee80211_wake_queues(hw);
1091 WMI_CMD(WMI_ENABLE_INTR_CMDID);
1094 ath9k_hw_cfg_output(ah, ah->led_pin,
1095 AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
1096 ath9k_hw_set_gpio(ah, ah->led_pin, 0);
1099 static void ath9k_htc_radio_disable(struct ieee80211_hw *hw)
1101 struct ath9k_htc_priv *priv = hw->priv;
1102 struct ath_hw *ah = priv->ah;
1103 struct ath_common *common = ath9k_hw_common(ah);
1107 ath9k_htc_ps_wakeup(priv);
1110 ath9k_hw_set_gpio(ah, ah->led_pin, 1);
1111 ath9k_hw_cfg_gpio_input(ah, ah->led_pin);
1113 WMI_CMD(WMI_DISABLE_INTR_CMDID);
1116 ieee80211_stop_queues(hw);
1117 htc_stop(priv->htc);
1118 WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID);
1119 skb_queue_purge(&priv->tx_queue);
1122 WMI_CMD(WMI_STOP_RECV_CMDID);
1125 * The MIB counters have to be disabled here,
1126 * since the target doesn't do it.
1128 ath9k_hw_disable_mib_counters(ah);
1131 ah->curchan = ath9k_cmn_get_curchannel(hw, ah);
1134 ret = ath9k_hw_reset(ah, ah->curchan, false);
1136 ath_print(common, ATH_DBG_FATAL,
1137 "Unable to reset hardware; reset status %d "
1138 "(freq %u MHz)\n", ret, ah->curchan->channel);
1141 /* Disable the PHY */
1142 ath9k_hw_phy_disable(ah);
1144 ath9k_htc_ps_restore(priv);
1145 ath9k_htc_setpower(priv, ATH9K_PM_FULL_SLEEP);
1148 /**********************/
1149 /* mac80211 Callbacks */
1150 /**********************/
1152 static int ath9k_htc_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
1154 struct ieee80211_hdr *hdr;
1155 struct ath9k_htc_priv *priv = hw->priv;
1156 int padpos, padsize, ret;
1158 hdr = (struct ieee80211_hdr *) skb->data;
1160 /* Add the padding after the header if this is not already done */
1161 padpos = ath9k_cmn_padpos(hdr->frame_control);
1162 padsize = padpos & 3;
1163 if (padsize && skb->len > padpos) {
1164 if (skb_headroom(skb) < padsize)
1166 skb_push(skb, padsize);
1167 memmove(skb->data, skb->data + padsize, padpos);
1170 ret = ath9k_htc_tx_start(priv, skb);
1172 if (ret == -ENOMEM) {
1173 ath_print(ath9k_hw_common(priv->ah), ATH_DBG_XMIT,
1174 "Stopping TX queues\n");
1175 ieee80211_stop_queues(hw);
1176 spin_lock_bh(&priv->tx_lock);
1177 priv->tx_queues_stop = true;
1178 spin_unlock_bh(&priv->tx_lock);
1180 ath_print(ath9k_hw_common(priv->ah), ATH_DBG_XMIT,
1189 dev_kfree_skb_any(skb);
1193 static int ath9k_htc_start(struct ieee80211_hw *hw)
1195 struct ath9k_htc_priv *priv = hw->priv;
1196 struct ath_hw *ah = priv->ah;
1197 struct ath_common *common = ath9k_hw_common(ah);
1198 struct ieee80211_channel *curchan = hw->conf.channel;
1199 struct ath9k_channel *init_channel;
1201 enum htc_phymode mode;
1205 mutex_lock(&priv->mutex);
1207 ath_print(common, ATH_DBG_CONFIG,
1208 "Starting driver with initial channel: %d MHz\n",
1209 curchan->center_freq);
1211 /* Ensure that HW is awake before flushing RX */
1212 ath9k_htc_setpower(priv, ATH9K_PM_AWAKE);
1213 WMI_CMD(WMI_FLUSH_RECV_CMDID);
1215 /* setup initial channel */
1216 init_channel = ath9k_cmn_get_curchannel(hw, ah);
1218 /* Reset SERDES registers */
1219 ath9k_hw_configpcipowersave(ah, 0, 0);
1221 ath9k_hw_htc_resetinit(ah);
1222 ret = ath9k_hw_reset(ah, init_channel, false);
1224 ath_print(common, ATH_DBG_FATAL,
1225 "Unable to reset hardware; reset status %d "
1226 "(freq %u MHz)\n", ret, curchan->center_freq);
1227 mutex_unlock(&priv->mutex);
1231 ath_update_txpow(priv);
1233 mode = ath9k_htc_get_curmode(priv, init_channel);
1234 htc_mode = cpu_to_be16(mode);
1235 WMI_CMD_BUF(WMI_SET_MODE_CMDID, &htc_mode);
1236 WMI_CMD(WMI_ATH_INIT_CMDID);
1237 WMI_CMD(WMI_START_RECV_CMDID);
1239 ath9k_host_rx_init(priv);
1241 priv->op_flags &= ~OP_INVALID;
1242 htc_start(priv->htc);
1244 spin_lock_bh(&priv->tx_lock);
1245 priv->tx_queues_stop = false;
1246 spin_unlock_bh(&priv->tx_lock);
1248 ieee80211_wake_queues(hw);
1250 mutex_unlock(&priv->mutex);
1255 static void ath9k_htc_stop(struct ieee80211_hw *hw)
1257 struct ath9k_htc_priv *priv = hw->priv;
1258 struct ath_hw *ah = priv->ah;
1259 struct ath_common *common = ath9k_hw_common(ah);
1263 mutex_lock(&priv->mutex);
1265 if (priv->op_flags & OP_INVALID) {
1266 ath_print(common, ATH_DBG_ANY, "Device not present\n");
1267 mutex_unlock(&priv->mutex);
1271 /* Cancel all the running timers/work .. */
1272 cancel_work_sync(&priv->ps_work);
1273 cancel_delayed_work_sync(&priv->ath9k_ani_work);
1274 cancel_delayed_work_sync(&priv->ath9k_aggr_work);
1275 cancel_delayed_work_sync(&priv->ath9k_led_blink_work);
1276 ath9k_led_stop_brightness(priv);
1278 ath9k_htc_ps_wakeup(priv);
1279 htc_stop(priv->htc);
1280 WMI_CMD(WMI_DISABLE_INTR_CMDID);
1281 WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID);
1282 WMI_CMD(WMI_STOP_RECV_CMDID);
1283 skb_queue_purge(&priv->tx_queue);
1285 /* Remove monitor interface here */
1286 if (ah->opmode == NL80211_IFTYPE_MONITOR) {
1287 if (ath9k_htc_remove_monitor_interface(priv))
1288 ath_print(common, ATH_DBG_FATAL,
1289 "Unable to remove monitor interface\n");
1291 ath_print(common, ATH_DBG_CONFIG,
1292 "Monitor interface removed\n");
1295 ath9k_hw_phy_disable(ah);
1296 ath9k_hw_disable(ah);
1297 ath9k_hw_configpcipowersave(ah, 1, 1);
1298 ath9k_htc_ps_restore(priv);
1299 ath9k_htc_setpower(priv, ATH9K_PM_FULL_SLEEP);
1301 priv->op_flags |= OP_INVALID;
1303 ath_print(common, ATH_DBG_CONFIG, "Driver halt\n");
1304 mutex_unlock(&priv->mutex);
1307 static int ath9k_htc_add_interface(struct ieee80211_hw *hw,
1308 struct ieee80211_vif *vif)
1310 struct ath9k_htc_priv *priv = hw->priv;
1311 struct ath9k_htc_vif *avp = (void *)vif->drv_priv;
1312 struct ath_common *common = ath9k_hw_common(priv->ah);
1313 struct ath9k_htc_target_vif hvif;
1317 mutex_lock(&priv->mutex);
1319 /* Only one interface for now */
1320 if (priv->nvifs > 0) {
1325 ath9k_htc_ps_wakeup(priv);
1326 memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif));
1327 memcpy(&hvif.myaddr, vif->addr, ETH_ALEN);
1329 switch (vif->type) {
1330 case NL80211_IFTYPE_STATION:
1331 hvif.opmode = cpu_to_be32(HTC_M_STA);
1333 case NL80211_IFTYPE_ADHOC:
1334 hvif.opmode = cpu_to_be32(HTC_M_IBSS);
1337 ath_print(common, ATH_DBG_FATAL,
1338 "Interface type %d not yet supported\n", vif->type);
1343 ath_print(common, ATH_DBG_CONFIG,
1344 "Attach a VIF of type: %d\n", vif->type);
1346 priv->ah->opmode = vif->type;
1348 /* Index starts from zero on the target */
1349 avp->index = hvif.index = priv->nvifs;
1350 hvif.rtsthreshold = cpu_to_be16(2304);
1351 WMI_CMD_BUF(WMI_VAP_CREATE_CMDID, &hvif);
1358 * We need a node in target to tx mgmt frames
1359 * before association.
1361 ret = ath9k_htc_add_station(priv, vif, NULL);
1365 ret = ath9k_htc_update_cap_target(priv);
1367 ath_print(common, ATH_DBG_CONFIG, "Failed to update"
1368 " capability in target \n");
1372 ath9k_htc_ps_restore(priv);
1373 mutex_unlock(&priv->mutex);
1378 static void ath9k_htc_remove_interface(struct ieee80211_hw *hw,
1379 struct ieee80211_vif *vif)
1381 struct ath9k_htc_priv *priv = hw->priv;
1382 struct ath_common *common = ath9k_hw_common(priv->ah);
1383 struct ath9k_htc_vif *avp = (void *)vif->drv_priv;
1384 struct ath9k_htc_target_vif hvif;
1388 ath_print(common, ATH_DBG_CONFIG, "Detach Interface\n");
1390 mutex_lock(&priv->mutex);
1391 ath9k_htc_ps_wakeup(priv);
1393 memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif));
1394 memcpy(&hvif.myaddr, vif->addr, ETH_ALEN);
1395 hvif.index = avp->index;
1396 WMI_CMD_BUF(WMI_VAP_REMOVE_CMDID, &hvif);
1399 ath9k_htc_remove_station(priv, vif, NULL);
1402 ath9k_htc_ps_restore(priv);
1403 mutex_unlock(&priv->mutex);
1406 static int ath9k_htc_config(struct ieee80211_hw *hw, u32 changed)
1408 struct ath9k_htc_priv *priv = hw->priv;
1409 struct ath_common *common = ath9k_hw_common(priv->ah);
1410 struct ieee80211_conf *conf = &hw->conf;
1412 mutex_lock(&priv->mutex);
1414 if (changed & IEEE80211_CONF_CHANGE_IDLE) {
1415 bool enable_radio = false;
1416 bool idle = !!(conf->flags & IEEE80211_CONF_IDLE);
1418 mutex_lock(&priv->htc_pm_lock);
1419 if (!idle && priv->ps_idle)
1420 enable_radio = true;
1421 priv->ps_idle = idle;
1422 mutex_unlock(&priv->htc_pm_lock);
1425 ath_print(common, ATH_DBG_CONFIG,
1426 "not-idle: enabling radio\n");
1427 ath9k_htc_setpower(priv, ATH9K_PM_AWAKE);
1428 ath9k_htc_radio_enable(hw);
1432 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
1433 struct ieee80211_channel *curchan = hw->conf.channel;
1434 int pos = curchan->hw_value;
1436 ath_print(common, ATH_DBG_CONFIG, "Set channel: %d MHz\n",
1437 curchan->center_freq);
1439 ath9k_cmn_update_ichannel(hw, &priv->ah->channels[pos]);
1441 if (ath9k_htc_set_channel(priv, hw, &priv->ah->channels[pos]) < 0) {
1442 ath_print(common, ATH_DBG_FATAL,
1443 "Unable to set channel\n");
1444 mutex_unlock(&priv->mutex);
1449 if (changed & IEEE80211_CONF_CHANGE_PS) {
1450 if (conf->flags & IEEE80211_CONF_PS) {
1451 ath9k_htc_setpower(priv, ATH9K_PM_NETWORK_SLEEP);
1452 priv->ps_enabled = true;
1454 priv->ps_enabled = false;
1455 cancel_work_sync(&priv->ps_work);
1456 ath9k_htc_setpower(priv, ATH9K_PM_AWAKE);
1460 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
1461 if (conf->flags & IEEE80211_CONF_MONITOR) {
1462 if (ath9k_htc_add_monitor_interface(priv))
1463 ath_print(common, ATH_DBG_FATAL,
1464 "Failed to set monitor mode\n");
1466 ath_print(common, ATH_DBG_CONFIG,
1467 "HW opmode set to Monitor mode\n");
1471 if (changed & IEEE80211_CONF_CHANGE_IDLE) {
1472 mutex_lock(&priv->htc_pm_lock);
1473 if (!priv->ps_idle) {
1474 mutex_unlock(&priv->htc_pm_lock);
1477 mutex_unlock(&priv->htc_pm_lock);
1479 ath_print(common, ATH_DBG_CONFIG,
1480 "idle: disabling radio\n");
1481 ath9k_htc_radio_disable(hw);
1485 mutex_unlock(&priv->mutex);
1489 #define SUPPORTED_FILTERS \
1490 (FIF_PROMISC_IN_BSS | \
1495 FIF_BCN_PRBRESP_PROMISC | \
1498 static void ath9k_htc_configure_filter(struct ieee80211_hw *hw,
1499 unsigned int changed_flags,
1500 unsigned int *total_flags,
1503 struct ath9k_htc_priv *priv = hw->priv;
1506 mutex_lock(&priv->mutex);
1507 ath9k_htc_ps_wakeup(priv);
1509 changed_flags &= SUPPORTED_FILTERS;
1510 *total_flags &= SUPPORTED_FILTERS;
1512 priv->rxfilter = *total_flags;
1513 rfilt = ath9k_htc_calcrxfilter(priv);
1514 ath9k_hw_setrxfilter(priv->ah, rfilt);
1516 ath_print(ath9k_hw_common(priv->ah), ATH_DBG_CONFIG,
1517 "Set HW RX filter: 0x%x\n", rfilt);
1519 ath9k_htc_ps_restore(priv);
1520 mutex_unlock(&priv->mutex);
1523 static int ath9k_htc_sta_add(struct ieee80211_hw *hw,
1524 struct ieee80211_vif *vif,
1525 struct ieee80211_sta *sta)
1527 struct ath9k_htc_priv *priv = hw->priv;
1530 mutex_lock(&priv->mutex);
1531 ath9k_htc_ps_wakeup(priv);
1532 ret = ath9k_htc_add_station(priv, vif, sta);
1534 ath9k_htc_init_rate(priv, sta);
1535 ath9k_htc_ps_restore(priv);
1536 mutex_unlock(&priv->mutex);
1541 static int ath9k_htc_sta_remove(struct ieee80211_hw *hw,
1542 struct ieee80211_vif *vif,
1543 struct ieee80211_sta *sta)
1545 struct ath9k_htc_priv *priv = hw->priv;
1548 mutex_lock(&priv->mutex);
1549 ath9k_htc_ps_wakeup(priv);
1550 ret = ath9k_htc_remove_station(priv, vif, sta);
1551 ath9k_htc_ps_restore(priv);
1552 mutex_unlock(&priv->mutex);
1557 static int ath9k_htc_conf_tx(struct ieee80211_hw *hw, u16 queue,
1558 const struct ieee80211_tx_queue_params *params)
1560 struct ath9k_htc_priv *priv = hw->priv;
1561 struct ath_common *common = ath9k_hw_common(priv->ah);
1562 struct ath9k_tx_queue_info qi;
1565 if (queue >= WME_NUM_AC)
1568 mutex_lock(&priv->mutex);
1569 ath9k_htc_ps_wakeup(priv);
1571 memset(&qi, 0, sizeof(struct ath9k_tx_queue_info));
1573 qi.tqi_aifs = params->aifs;
1574 qi.tqi_cwmin = params->cw_min;
1575 qi.tqi_cwmax = params->cw_max;
1576 qi.tqi_burstTime = params->txop;
1578 qnum = get_hw_qnum(queue, priv->hwq_map);
1580 ath_print(common, ATH_DBG_CONFIG,
1581 "Configure tx [queue/hwq] [%d/%d], "
1582 "aifs: %d, cw_min: %d, cw_max: %d, txop: %d\n",
1583 queue, qnum, params->aifs, params->cw_min,
1584 params->cw_max, params->txop);
1586 ret = ath_htc_txq_update(priv, qnum, &qi);
1588 ath_print(common, ATH_DBG_FATAL, "TXQ Update failed\n");
1592 if ((priv->ah->opmode == NL80211_IFTYPE_ADHOC) &&
1593 (qnum == priv->hwq_map[ATH9K_WME_AC_BE]))
1594 ath9k_htc_beaconq_config(priv);
1596 ath9k_htc_ps_restore(priv);
1597 mutex_unlock(&priv->mutex);
1602 static int ath9k_htc_set_key(struct ieee80211_hw *hw,
1603 enum set_key_cmd cmd,
1604 struct ieee80211_vif *vif,
1605 struct ieee80211_sta *sta,
1606 struct ieee80211_key_conf *key)
1608 struct ath9k_htc_priv *priv = hw->priv;
1609 struct ath_common *common = ath9k_hw_common(priv->ah);
1612 if (htc_modparam_nohwcrypt)
1615 mutex_lock(&priv->mutex);
1616 ath_print(common, ATH_DBG_CONFIG, "Set HW Key\n");
1617 ath9k_htc_ps_wakeup(priv);
1621 ret = ath9k_cmn_key_config(common, vif, sta, key);
1623 key->hw_key_idx = ret;
1624 /* push IV and Michael MIC generation to stack */
1625 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
1626 if (key->alg == ALG_TKIP)
1627 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
1628 if (priv->ah->sw_mgmt_crypto && key->alg == ALG_CCMP)
1629 key->flags |= IEEE80211_KEY_FLAG_SW_MGMT;
1634 ath9k_cmn_key_delete(common, key);
1640 ath9k_htc_ps_restore(priv);
1641 mutex_unlock(&priv->mutex);
1646 static void ath9k_htc_bss_info_changed(struct ieee80211_hw *hw,
1647 struct ieee80211_vif *vif,
1648 struct ieee80211_bss_conf *bss_conf,
1651 struct ath9k_htc_priv *priv = hw->priv;
1652 struct ath_hw *ah = priv->ah;
1653 struct ath_common *common = ath9k_hw_common(ah);
1655 mutex_lock(&priv->mutex);
1656 ath9k_htc_ps_wakeup(priv);
1658 if (changed & BSS_CHANGED_ASSOC) {
1659 common->curaid = bss_conf->assoc ?
1661 ath_print(common, ATH_DBG_CONFIG, "BSS Changed ASSOC %d\n",
1664 if (bss_conf->assoc) {
1665 priv->op_flags |= OP_ASSOCIATED;
1666 ath_start_ani(priv);
1668 priv->op_flags &= ~OP_ASSOCIATED;
1669 cancel_delayed_work_sync(&priv->ath9k_ani_work);
1673 if (changed & BSS_CHANGED_BSSID) {
1675 memcpy(common->curbssid, bss_conf->bssid, ETH_ALEN);
1676 ath9k_hw_write_associd(ah);
1678 ath_print(common, ATH_DBG_CONFIG,
1679 "BSSID: %pM aid: 0x%x\n",
1680 common->curbssid, common->curaid);
1683 if ((changed & BSS_CHANGED_BEACON_INT) ||
1684 (changed & BSS_CHANGED_BEACON) ||
1685 ((changed & BSS_CHANGED_BEACON_ENABLED) &&
1686 bss_conf->enable_beacon)) {
1687 priv->op_flags |= OP_ENABLE_BEACON;
1688 ath9k_htc_beacon_config(priv, vif);
1691 if ((changed & BSS_CHANGED_BEACON_ENABLED) &&
1692 !bss_conf->enable_beacon) {
1693 priv->op_flags &= ~OP_ENABLE_BEACON;
1694 ath9k_htc_beacon_config(priv, vif);
1697 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
1698 ath_print(common, ATH_DBG_CONFIG, "BSS Changed PREAMBLE %d\n",
1699 bss_conf->use_short_preamble);
1700 if (bss_conf->use_short_preamble)
1701 priv->op_flags |= OP_PREAMBLE_SHORT;
1703 priv->op_flags &= ~OP_PREAMBLE_SHORT;
1706 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
1707 ath_print(common, ATH_DBG_CONFIG, "BSS Changed CTS PROT %d\n",
1708 bss_conf->use_cts_prot);
1709 if (bss_conf->use_cts_prot &&
1710 hw->conf.channel->band != IEEE80211_BAND_5GHZ)
1711 priv->op_flags |= OP_PROTECT_ENABLE;
1713 priv->op_flags &= ~OP_PROTECT_ENABLE;
1716 if (changed & BSS_CHANGED_ERP_SLOT) {
1717 if (bss_conf->use_short_slot)
1722 ath9k_hw_init_global_settings(ah);
1725 if (changed & BSS_CHANGED_HT)
1726 ath9k_htc_update_rate(priv, vif, bss_conf);
1728 ath9k_htc_ps_restore(priv);
1729 mutex_unlock(&priv->mutex);
1732 static u64 ath9k_htc_get_tsf(struct ieee80211_hw *hw)
1734 struct ath9k_htc_priv *priv = hw->priv;
1737 mutex_lock(&priv->mutex);
1738 ath9k_htc_ps_wakeup(priv);
1739 tsf = ath9k_hw_gettsf64(priv->ah);
1740 ath9k_htc_ps_restore(priv);
1741 mutex_unlock(&priv->mutex);
1746 static void ath9k_htc_set_tsf(struct ieee80211_hw *hw, u64 tsf)
1748 struct ath9k_htc_priv *priv = hw->priv;
1750 mutex_lock(&priv->mutex);
1751 ath9k_htc_ps_wakeup(priv);
1752 ath9k_hw_settsf64(priv->ah, tsf);
1753 ath9k_htc_ps_restore(priv);
1754 mutex_unlock(&priv->mutex);
1757 static void ath9k_htc_reset_tsf(struct ieee80211_hw *hw)
1759 struct ath9k_htc_priv *priv = hw->priv;
1761 mutex_lock(&priv->mutex);
1762 ath9k_htc_ps_wakeup(priv);
1763 ath9k_hw_reset_tsf(priv->ah);
1764 ath9k_htc_ps_restore(priv);
1765 mutex_unlock(&priv->mutex);
1768 static int ath9k_htc_ampdu_action(struct ieee80211_hw *hw,
1769 struct ieee80211_vif *vif,
1770 enum ieee80211_ampdu_mlme_action action,
1771 struct ieee80211_sta *sta,
1774 struct ath9k_htc_priv *priv = hw->priv;
1775 struct ath9k_htc_aggr_work *work = &priv->aggr_work;
1776 struct ath9k_htc_sta *ista;
1779 case IEEE80211_AMPDU_RX_START:
1781 case IEEE80211_AMPDU_RX_STOP:
1783 case IEEE80211_AMPDU_TX_START:
1784 case IEEE80211_AMPDU_TX_STOP:
1785 if (!(priv->op_flags & OP_TXAGGR))
1787 memcpy(work->sta_addr, sta->addr, ETH_ALEN);
1790 work->action = action;
1792 ieee80211_queue_delayed_work(hw, &priv->ath9k_aggr_work, 0);
1794 case IEEE80211_AMPDU_TX_OPERATIONAL:
1795 ista = (struct ath9k_htc_sta *) sta->drv_priv;
1796 ista->tid_state[tid] = AGGR_OPERATIONAL;
1799 ath_print(ath9k_hw_common(priv->ah), ATH_DBG_FATAL,
1800 "Unknown AMPDU action\n");
1806 static void ath9k_htc_sw_scan_start(struct ieee80211_hw *hw)
1808 struct ath9k_htc_priv *priv = hw->priv;
1810 mutex_lock(&priv->mutex);
1811 spin_lock_bh(&priv->beacon_lock);
1812 priv->op_flags |= OP_SCANNING;
1813 spin_unlock_bh(&priv->beacon_lock);
1814 cancel_work_sync(&priv->ps_work);
1815 cancel_delayed_work_sync(&priv->ath9k_ani_work);
1816 mutex_unlock(&priv->mutex);
1819 static void ath9k_htc_sw_scan_complete(struct ieee80211_hw *hw)
1821 struct ath9k_htc_priv *priv = hw->priv;
1823 mutex_lock(&priv->mutex);
1824 ath9k_htc_ps_wakeup(priv);
1825 spin_lock_bh(&priv->beacon_lock);
1826 priv->op_flags &= ~OP_SCANNING;
1827 spin_unlock_bh(&priv->beacon_lock);
1828 priv->op_flags |= OP_FULL_RESET;
1829 if (priv->op_flags & OP_ASSOCIATED)
1830 ath9k_htc_beacon_config(priv, priv->vif);
1831 ath_start_ani(priv);
1832 ath9k_htc_ps_restore(priv);
1833 mutex_unlock(&priv->mutex);
1836 static int ath9k_htc_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
1841 static void ath9k_htc_set_coverage_class(struct ieee80211_hw *hw,
1844 struct ath9k_htc_priv *priv = hw->priv;
1846 mutex_lock(&priv->mutex);
1847 ath9k_htc_ps_wakeup(priv);
1848 priv->ah->coverage_class = coverage_class;
1849 ath9k_hw_init_global_settings(priv->ah);
1850 ath9k_htc_ps_restore(priv);
1851 mutex_unlock(&priv->mutex);
1854 struct ieee80211_ops ath9k_htc_ops = {
1856 .start = ath9k_htc_start,
1857 .stop = ath9k_htc_stop,
1858 .add_interface = ath9k_htc_add_interface,
1859 .remove_interface = ath9k_htc_remove_interface,
1860 .config = ath9k_htc_config,
1861 .configure_filter = ath9k_htc_configure_filter,
1862 .sta_add = ath9k_htc_sta_add,
1863 .sta_remove = ath9k_htc_sta_remove,
1864 .conf_tx = ath9k_htc_conf_tx,
1865 .bss_info_changed = ath9k_htc_bss_info_changed,
1866 .set_key = ath9k_htc_set_key,
1867 .get_tsf = ath9k_htc_get_tsf,
1868 .set_tsf = ath9k_htc_set_tsf,
1869 .reset_tsf = ath9k_htc_reset_tsf,
1870 .ampdu_action = ath9k_htc_ampdu_action,
1871 .sw_scan_start = ath9k_htc_sw_scan_start,
1872 .sw_scan_complete = ath9k_htc_sw_scan_complete,
1873 .set_rts_threshold = ath9k_htc_set_rts_threshold,
1874 .rfkill_poll = ath9k_htc_rfkill_poll_state,
1875 .set_coverage_class = ath9k_htc_set_coverage_class,