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 /* HACK Alert: Use 11NG for 2.4, use 11NA for 5 */
28 static enum htc_phymode ath9k_htc_get_curmode(struct ath9k_htc_priv *priv,
29 struct ath9k_channel *ichan)
31 enum htc_phymode mode;
35 switch (ichan->chanmode) {
38 case CHANNEL_G_HT40PLUS:
39 case CHANNEL_G_HT40MINUS:
44 case CHANNEL_A_HT40PLUS:
45 case CHANNEL_A_HT40MINUS:
55 bool ath9k_htc_setpower(struct ath9k_htc_priv *priv,
56 enum ath9k_power_mode mode)
60 mutex_lock(&priv->htc_pm_lock);
61 ret = ath9k_hw_setpower(priv->ah, mode);
62 mutex_unlock(&priv->htc_pm_lock);
67 void ath9k_htc_ps_wakeup(struct ath9k_htc_priv *priv)
69 mutex_lock(&priv->htc_pm_lock);
70 if (++priv->ps_usecount != 1)
72 ath9k_hw_setpower(priv->ah, ATH9K_PM_AWAKE);
75 mutex_unlock(&priv->htc_pm_lock);
78 void ath9k_htc_ps_restore(struct ath9k_htc_priv *priv)
80 mutex_lock(&priv->htc_pm_lock);
81 if (--priv->ps_usecount != 0)
85 ath9k_hw_setpower(priv->ah, ATH9K_PM_FULL_SLEEP);
86 else if (priv->ps_enabled)
87 ath9k_hw_setpower(priv->ah, ATH9K_PM_NETWORK_SLEEP);
90 mutex_unlock(&priv->htc_pm_lock);
93 void ath9k_ps_work(struct work_struct *work)
95 struct ath9k_htc_priv *priv =
96 container_of(work, struct ath9k_htc_priv,
98 ath9k_htc_setpower(priv, ATH9K_PM_AWAKE);
100 /* The chip wakes up after receiving the first beacon
101 while network sleep is enabled. For the driver to
102 be in sync with the hw, set the chip to awake and
103 only then set it to sleep.
105 ath9k_htc_setpower(priv, ATH9K_PM_NETWORK_SLEEP);
108 static void ath9k_htc_vif_iter(void *data, u8 *mac, struct ieee80211_vif *vif)
110 struct ath9k_htc_priv *priv = data;
111 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
113 if (bss_conf->assoc) {
114 priv->rearm_ani = true;
115 priv->reconfig_beacon = true;
119 static void ath9k_htc_vif_reconfig(struct ath9k_htc_priv *priv)
121 priv->rearm_ani = false;
122 priv->reconfig_beacon = false;
124 ieee80211_iterate_active_interfaces_atomic(priv->hw,
125 ath9k_htc_vif_iter, priv);
129 if (priv->reconfig_beacon) {
130 ath9k_htc_ps_wakeup(priv);
131 ath9k_htc_beacon_reconfig(priv);
132 ath9k_htc_ps_restore(priv);
136 static void ath9k_htc_bssid_iter(void *data, u8 *mac, struct ieee80211_vif *vif)
138 struct ath9k_vif_iter_data *iter_data = data;
141 for (i = 0; i < ETH_ALEN; i++)
142 iter_data->mask[i] &= ~(iter_data->hw_macaddr[i] ^ mac[i]);
145 static void ath9k_htc_set_bssid_mask(struct ath9k_htc_priv *priv,
146 struct ieee80211_vif *vif)
148 struct ath_common *common = ath9k_hw_common(priv->ah);
149 struct ath9k_vif_iter_data iter_data;
152 * Use the hardware MAC address as reference, the hardware uses it
153 * together with the BSSID mask when matching addresses.
155 iter_data.hw_macaddr = common->macaddr;
156 memset(&iter_data.mask, 0xff, ETH_ALEN);
159 ath9k_htc_bssid_iter(&iter_data, vif->addr, vif);
161 /* Get list of all active MAC addresses */
162 ieee80211_iterate_active_interfaces_atomic(priv->hw, ath9k_htc_bssid_iter,
165 memcpy(common->bssidmask, iter_data.mask, ETH_ALEN);
166 ath_hw_setbssidmask(common);
169 void ath9k_htc_reset(struct ath9k_htc_priv *priv)
171 struct ath_hw *ah = priv->ah;
172 struct ath_common *common = ath9k_hw_common(ah);
173 struct ieee80211_channel *channel = priv->hw->conf.channel;
174 struct ath9k_hw_cal_data *caldata = NULL;
175 enum htc_phymode mode;
180 mutex_lock(&priv->mutex);
181 ath9k_htc_ps_wakeup(priv);
183 cancel_delayed_work_sync(&priv->ath9k_ani_work);
184 ieee80211_stop_queues(priv->hw);
186 WMI_CMD(WMI_DISABLE_INTR_CMDID);
187 WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID);
188 WMI_CMD(WMI_STOP_RECV_CMDID);
190 caldata = &priv->caldata;
191 ret = ath9k_hw_reset(ah, ah->curchan, caldata, false);
194 "Unable to reset device (%u Mhz) reset status %d\n",
195 channel->center_freq, ret);
198 ath9k_cmn_update_txpow(ah, priv->curtxpow, priv->txpowlimit,
201 WMI_CMD(WMI_START_RECV_CMDID);
202 ath9k_host_rx_init(priv);
204 mode = ath9k_htc_get_curmode(priv, ah->curchan);
205 htc_mode = cpu_to_be16(mode);
206 WMI_CMD_BUF(WMI_SET_MODE_CMDID, &htc_mode);
208 WMI_CMD(WMI_ENABLE_INTR_CMDID);
209 htc_start(priv->htc);
210 ath9k_htc_vif_reconfig(priv);
211 ieee80211_wake_queues(priv->hw);
213 ath9k_htc_ps_restore(priv);
214 mutex_unlock(&priv->mutex);
217 static int ath9k_htc_set_channel(struct ath9k_htc_priv *priv,
218 struct ieee80211_hw *hw,
219 struct ath9k_channel *hchan)
221 struct ath_hw *ah = priv->ah;
222 struct ath_common *common = ath9k_hw_common(ah);
223 struct ieee80211_conf *conf = &common->hw->conf;
225 struct ieee80211_channel *channel = hw->conf.channel;
226 struct ath9k_hw_cal_data *caldata = NULL;
227 enum htc_phymode mode;
232 if (priv->op_flags & OP_INVALID)
235 fastcc = !!(hw->conf.flags & IEEE80211_CONF_OFFCHANNEL);
237 ath9k_htc_ps_wakeup(priv);
239 WMI_CMD(WMI_DISABLE_INTR_CMDID);
240 WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID);
241 WMI_CMD(WMI_STOP_RECV_CMDID);
243 ath_dbg(common, ATH_DBG_CONFIG,
244 "(%u MHz) -> (%u MHz), HT: %d, HT40: %d fastcc: %d\n",
245 priv->ah->curchan->channel,
246 channel->center_freq, conf_is_ht(conf), conf_is_ht40(conf),
250 caldata = &priv->caldata;
251 ret = ath9k_hw_reset(ah, hchan, caldata, fastcc);
254 "Unable to reset channel (%u Mhz) reset status %d\n",
255 channel->center_freq, ret);
259 ath9k_cmn_update_txpow(ah, priv->curtxpow, priv->txpowlimit,
262 WMI_CMD(WMI_START_RECV_CMDID);
266 ath9k_host_rx_init(priv);
268 mode = ath9k_htc_get_curmode(priv, hchan);
269 htc_mode = cpu_to_be16(mode);
270 WMI_CMD_BUF(WMI_SET_MODE_CMDID, &htc_mode);
274 WMI_CMD(WMI_ENABLE_INTR_CMDID);
278 htc_start(priv->htc);
280 ath9k_htc_ps_restore(priv);
285 * Monitor mode handling is a tad complicated because the firmware requires
286 * an interface to be created exclusively, while mac80211 doesn't associate
287 * an interface with the mode.
289 * So, for now, only one monitor interface can be configured.
291 static void __ath9k_htc_remove_monitor_interface(struct ath9k_htc_priv *priv)
293 struct ath_common *common = ath9k_hw_common(priv->ah);
294 struct ath9k_htc_target_vif hvif;
298 memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif));
299 memcpy(&hvif.myaddr, common->macaddr, ETH_ALEN);
300 hvif.index = priv->mon_vif_idx;
301 WMI_CMD_BUF(WMI_VAP_REMOVE_CMDID, &hvif);
303 priv->vif_slot &= ~(1 << priv->mon_vif_idx);
306 static int ath9k_htc_add_monitor_interface(struct ath9k_htc_priv *priv)
308 struct ath_common *common = ath9k_hw_common(priv->ah);
309 struct ath9k_htc_target_vif hvif;
310 struct ath9k_htc_target_sta tsta;
311 int ret = 0, sta_idx;
314 if ((priv->nvifs >= ATH9K_HTC_MAX_VIF) ||
315 (priv->nstations >= ATH9K_HTC_MAX_STA)) {
320 sta_idx = ffz(priv->sta_slot);
321 if ((sta_idx < 0) || (sta_idx > ATH9K_HTC_MAX_STA)) {
329 memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif));
330 memcpy(&hvif.myaddr, common->macaddr, ETH_ALEN);
332 hvif.opmode = cpu_to_be32(HTC_M_MONITOR);
333 hvif.index = ffz(priv->vif_slot);
335 WMI_CMD_BUF(WMI_VAP_CREATE_CMDID, &hvif);
340 * Assign the monitor interface index as a special case here.
341 * This is needed when the interface is brought down.
343 priv->mon_vif_idx = hvif.index;
344 priv->vif_slot |= (1 << hvif.index);
347 * Set the hardware mode to monitor only if there are no
351 priv->ah->opmode = NL80211_IFTYPE_MONITOR;
356 * Associate a station with the interface for packet injection.
358 memset(&tsta, 0, sizeof(struct ath9k_htc_target_sta));
360 memcpy(&tsta.macaddr, common->macaddr, ETH_ALEN);
363 tsta.sta_index = sta_idx;
364 tsta.vif_index = hvif.index;
365 tsta.maxampdu = 0xffff;
367 WMI_CMD_BUF(WMI_NODE_CREATE_CMDID, &tsta);
369 ath_err(common, "Unable to add station entry for monitor mode\n");
373 priv->sta_slot |= (1 << sta_idx);
375 priv->vif_sta_pos[priv->mon_vif_idx] = sta_idx;
376 priv->ah->is_monitoring = true;
378 ath_dbg(common, ATH_DBG_CONFIG,
379 "Attached a monitor interface at idx: %d, sta idx: %d\n",
380 priv->mon_vif_idx, sta_idx);
386 * Remove the interface from the target.
388 __ath9k_htc_remove_monitor_interface(priv);
390 ath_dbg(common, ATH_DBG_FATAL, "Unable to attach a monitor interface\n");
395 static int ath9k_htc_remove_monitor_interface(struct ath9k_htc_priv *priv)
397 struct ath_common *common = ath9k_hw_common(priv->ah);
401 __ath9k_htc_remove_monitor_interface(priv);
403 sta_idx = priv->vif_sta_pos[priv->mon_vif_idx];
405 WMI_CMD_BUF(WMI_NODE_REMOVE_CMDID, &sta_idx);
407 ath_err(common, "Unable to remove station entry for monitor mode\n");
411 priv->sta_slot &= ~(1 << sta_idx);
413 priv->ah->is_monitoring = false;
415 ath_dbg(common, ATH_DBG_CONFIG,
416 "Removed a monitor interface at idx: %d, sta idx: %d\n",
417 priv->mon_vif_idx, sta_idx);
422 static int ath9k_htc_add_station(struct ath9k_htc_priv *priv,
423 struct ieee80211_vif *vif,
424 struct ieee80211_sta *sta)
426 struct ath_common *common = ath9k_hw_common(priv->ah);
427 struct ath9k_htc_target_sta tsta;
428 struct ath9k_htc_vif *avp = (struct ath9k_htc_vif *) vif->drv_priv;
429 struct ath9k_htc_sta *ista;
433 if (priv->nstations >= ATH9K_HTC_MAX_STA)
436 sta_idx = ffz(priv->sta_slot);
437 if ((sta_idx < 0) || (sta_idx > ATH9K_HTC_MAX_STA))
440 memset(&tsta, 0, sizeof(struct ath9k_htc_target_sta));
443 ista = (struct ath9k_htc_sta *) sta->drv_priv;
444 memcpy(&tsta.macaddr, sta->addr, ETH_ALEN);
445 memcpy(&tsta.bssid, common->curbssid, ETH_ALEN);
446 tsta.associd = common->curaid;
449 ista->index = sta_idx;
451 memcpy(&tsta.macaddr, vif->addr, ETH_ALEN);
455 tsta.sta_index = sta_idx;
456 tsta.vif_index = avp->index;
457 tsta.maxampdu = 0xffff;
458 if (sta && sta->ht_cap.ht_supported)
459 tsta.flags = cpu_to_be16(ATH_HTC_STA_HT);
461 WMI_CMD_BUF(WMI_NODE_CREATE_CMDID, &tsta);
465 "Unable to add station entry for: %pM\n",
471 ath_dbg(common, ATH_DBG_CONFIG,
472 "Added a station entry for: %pM (idx: %d)\n",
473 sta->addr, tsta.sta_index);
475 ath_dbg(common, ATH_DBG_CONFIG,
476 "Added a station entry for VIF %d (idx: %d)\n",
477 avp->index, tsta.sta_index);
480 priv->sta_slot |= (1 << sta_idx);
483 priv->vif_sta_pos[avp->index] = sta_idx;
488 static int ath9k_htc_remove_station(struct ath9k_htc_priv *priv,
489 struct ieee80211_vif *vif,
490 struct ieee80211_sta *sta)
492 struct ath_common *common = ath9k_hw_common(priv->ah);
493 struct ath9k_htc_vif *avp = (struct ath9k_htc_vif *) vif->drv_priv;
494 struct ath9k_htc_sta *ista;
499 ista = (struct ath9k_htc_sta *) sta->drv_priv;
500 sta_idx = ista->index;
502 sta_idx = priv->vif_sta_pos[avp->index];
505 WMI_CMD_BUF(WMI_NODE_REMOVE_CMDID, &sta_idx);
509 "Unable to remove station entry for: %pM\n",
515 ath_dbg(common, ATH_DBG_CONFIG,
516 "Removed a station entry for: %pM (idx: %d)\n",
519 ath_dbg(common, ATH_DBG_CONFIG,
520 "Removed a station entry for VIF %d (idx: %d)\n",
521 avp->index, sta_idx);
524 priv->sta_slot &= ~(1 << sta_idx);
530 int ath9k_htc_update_cap_target(struct ath9k_htc_priv *priv)
532 struct ath9k_htc_cap_target tcap;
536 memset(&tcap, 0, sizeof(struct ath9k_htc_cap_target));
538 /* FIXME: Values are hardcoded */
539 tcap.flags = 0x240c40;
540 tcap.flags_ext = 0x80601000;
541 tcap.ampdu_limit = 0xffff0000;
542 tcap.ampdu_subframes = 20;
543 tcap.tx_chainmask_legacy = priv->ah->caps.tx_chainmask;
545 tcap.tx_chainmask = priv->ah->caps.tx_chainmask;
547 WMI_CMD_BUF(WMI_TARGET_IC_UPDATE_CMDID, &tcap);
552 static void ath9k_htc_setup_rate(struct ath9k_htc_priv *priv,
553 struct ieee80211_sta *sta,
554 struct ath9k_htc_target_rate *trate)
556 struct ath9k_htc_sta *ista = (struct ath9k_htc_sta *) sta->drv_priv;
557 struct ieee80211_supported_band *sband;
561 sband = priv->hw->wiphy->bands[priv->hw->conf.channel->band];
563 for (i = 0, j = 0; i < sband->n_bitrates; i++) {
564 if (sta->supp_rates[sband->band] & BIT(i)) {
565 trate->rates.legacy_rates.rs_rates[j]
566 = (sband->bitrates[i].bitrate * 2) / 10;
570 trate->rates.legacy_rates.rs_nrates = j;
572 if (sta->ht_cap.ht_supported) {
573 for (i = 0, j = 0; i < 77; i++) {
574 if (sta->ht_cap.mcs.rx_mask[i/8] & (1<<(i%8)))
575 trate->rates.ht_rates.rs_rates[j++] = i;
576 if (j == ATH_HTC_RATE_MAX)
579 trate->rates.ht_rates.rs_nrates = j;
581 caps = WLAN_RC_HT_FLAG;
582 if (sta->ht_cap.mcs.rx_mask[1])
583 caps |= WLAN_RC_DS_FLAG;
584 if ((sta->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) &&
585 (conf_is_ht40(&priv->hw->conf)))
586 caps |= WLAN_RC_40_FLAG;
587 if (conf_is_ht40(&priv->hw->conf) &&
588 (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_40))
589 caps |= WLAN_RC_SGI_FLAG;
590 else if (conf_is_ht20(&priv->hw->conf) &&
591 (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_20))
592 caps |= WLAN_RC_SGI_FLAG;
595 trate->sta_index = ista->index;
597 trate->capflags = cpu_to_be32(caps);
600 static int ath9k_htc_send_rate_cmd(struct ath9k_htc_priv *priv,
601 struct ath9k_htc_target_rate *trate)
603 struct ath_common *common = ath9k_hw_common(priv->ah);
607 WMI_CMD_BUF(WMI_RC_RATE_UPDATE_CMDID, trate);
610 "Unable to initialize Rate information on target\n");
616 static void ath9k_htc_init_rate(struct ath9k_htc_priv *priv,
617 struct ieee80211_sta *sta)
619 struct ath_common *common = ath9k_hw_common(priv->ah);
620 struct ath9k_htc_target_rate trate;
623 memset(&trate, 0, sizeof(struct ath9k_htc_target_rate));
624 ath9k_htc_setup_rate(priv, sta, &trate);
625 ret = ath9k_htc_send_rate_cmd(priv, &trate);
627 ath_dbg(common, ATH_DBG_CONFIG,
628 "Updated target sta: %pM, rate caps: 0x%X\n",
629 sta->addr, be32_to_cpu(trate.capflags));
632 static void ath9k_htc_update_rate(struct ath9k_htc_priv *priv,
633 struct ieee80211_vif *vif,
634 struct ieee80211_bss_conf *bss_conf)
636 struct ath_common *common = ath9k_hw_common(priv->ah);
637 struct ath9k_htc_target_rate trate;
638 struct ieee80211_sta *sta;
641 memset(&trate, 0, sizeof(struct ath9k_htc_target_rate));
644 sta = ieee80211_find_sta(vif, bss_conf->bssid);
649 ath9k_htc_setup_rate(priv, sta, &trate);
652 ret = ath9k_htc_send_rate_cmd(priv, &trate);
654 ath_dbg(common, ATH_DBG_CONFIG,
655 "Updated target sta: %pM, rate caps: 0x%X\n",
656 bss_conf->bssid, be32_to_cpu(trate.capflags));
659 static int ath9k_htc_tx_aggr_oper(struct ath9k_htc_priv *priv,
660 struct ieee80211_vif *vif,
661 struct ieee80211_sta *sta,
662 enum ieee80211_ampdu_mlme_action action,
665 struct ath_common *common = ath9k_hw_common(priv->ah);
666 struct ath9k_htc_target_aggr aggr;
667 struct ath9k_htc_sta *ista;
671 if (tid >= ATH9K_HTC_MAX_TID)
674 memset(&aggr, 0, sizeof(struct ath9k_htc_target_aggr));
675 ista = (struct ath9k_htc_sta *) sta->drv_priv;
677 aggr.sta_index = ista->index;
678 aggr.tidno = tid & 0xf;
679 aggr.aggr_enable = (action == IEEE80211_AMPDU_TX_START) ? true : false;
681 WMI_CMD_BUF(WMI_TX_AGGR_ENABLE_CMDID, &aggr);
683 ath_dbg(common, ATH_DBG_CONFIG,
684 "Unable to %s TX aggregation for (%pM, %d)\n",
685 (aggr.aggr_enable) ? "start" : "stop", sta->addr, tid);
687 ath_dbg(common, ATH_DBG_CONFIG,
688 "%s TX aggregation for (%pM, %d)\n",
689 (aggr.aggr_enable) ? "Starting" : "Stopping",
692 spin_lock_bh(&priv->tx_lock);
693 ista->tid_state[tid] = (aggr.aggr_enable && !ret) ? AGGR_START : AGGR_STOP;
694 spin_unlock_bh(&priv->tx_lock);
703 #ifdef CONFIG_ATH9K_HTC_DEBUGFS
705 static int ath9k_debugfs_open(struct inode *inode, struct file *file)
707 file->private_data = inode->i_private;
711 static ssize_t read_file_tgt_stats(struct file *file, char __user *user_buf,
712 size_t count, loff_t *ppos)
714 struct ath9k_htc_priv *priv = file->private_data;
715 struct ath9k_htc_target_stats cmd_rsp;
717 unsigned int len = 0;
720 memset(&cmd_rsp, 0, sizeof(cmd_rsp));
722 WMI_CMD(WMI_TGT_STATS_CMDID);
727 len += snprintf(buf + len, sizeof(buf) - len,
728 "%19s : %10u\n", "TX Short Retries",
729 be32_to_cpu(cmd_rsp.tx_shortretry));
730 len += snprintf(buf + len, sizeof(buf) - len,
731 "%19s : %10u\n", "TX Long Retries",
732 be32_to_cpu(cmd_rsp.tx_longretry));
733 len += snprintf(buf + len, sizeof(buf) - len,
734 "%19s : %10u\n", "TX Xretries",
735 be32_to_cpu(cmd_rsp.tx_xretries));
736 len += snprintf(buf + len, sizeof(buf) - len,
737 "%19s : %10u\n", "TX Unaggr. Xretries",
738 be32_to_cpu(cmd_rsp.ht_txunaggr_xretry));
739 len += snprintf(buf + len, sizeof(buf) - len,
740 "%19s : %10u\n", "TX Xretries (HT)",
741 be32_to_cpu(cmd_rsp.ht_tx_xretries));
742 len += snprintf(buf + len, sizeof(buf) - len,
743 "%19s : %10u\n", "TX Rate", priv->debug.txrate);
745 if (len > sizeof(buf))
748 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
751 static const struct file_operations fops_tgt_stats = {
752 .read = read_file_tgt_stats,
753 .open = ath9k_debugfs_open,
754 .owner = THIS_MODULE,
755 .llseek = default_llseek,
758 static ssize_t read_file_xmit(struct file *file, char __user *user_buf,
759 size_t count, loff_t *ppos)
761 struct ath9k_htc_priv *priv = file->private_data;
763 unsigned int len = 0;
765 len += snprintf(buf + len, sizeof(buf) - len,
766 "%20s : %10u\n", "Buffers queued",
767 priv->debug.tx_stats.buf_queued);
768 len += snprintf(buf + len, sizeof(buf) - len,
769 "%20s : %10u\n", "Buffers completed",
770 priv->debug.tx_stats.buf_completed);
771 len += snprintf(buf + len, sizeof(buf) - len,
772 "%20s : %10u\n", "SKBs queued",
773 priv->debug.tx_stats.skb_queued);
774 len += snprintf(buf + len, sizeof(buf) - len,
775 "%20s : %10u\n", "SKBs completed",
776 priv->debug.tx_stats.skb_completed);
777 len += snprintf(buf + len, sizeof(buf) - len,
778 "%20s : %10u\n", "SKBs dropped",
779 priv->debug.tx_stats.skb_dropped);
781 len += snprintf(buf + len, sizeof(buf) - len,
782 "%20s : %10u\n", "BE queued",
783 priv->debug.tx_stats.queue_stats[WME_AC_BE]);
784 len += snprintf(buf + len, sizeof(buf) - len,
785 "%20s : %10u\n", "BK queued",
786 priv->debug.tx_stats.queue_stats[WME_AC_BK]);
787 len += snprintf(buf + len, sizeof(buf) - len,
788 "%20s : %10u\n", "VI queued",
789 priv->debug.tx_stats.queue_stats[WME_AC_VI]);
790 len += snprintf(buf + len, sizeof(buf) - len,
791 "%20s : %10u\n", "VO queued",
792 priv->debug.tx_stats.queue_stats[WME_AC_VO]);
794 if (len > sizeof(buf))
797 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
800 static const struct file_operations fops_xmit = {
801 .read = read_file_xmit,
802 .open = ath9k_debugfs_open,
803 .owner = THIS_MODULE,
804 .llseek = default_llseek,
807 static ssize_t read_file_recv(struct file *file, char __user *user_buf,
808 size_t count, loff_t *ppos)
810 struct ath9k_htc_priv *priv = file->private_data;
812 unsigned int len = 0;
814 len += snprintf(buf + len, sizeof(buf) - len,
815 "%20s : %10u\n", "SKBs allocated",
816 priv->debug.rx_stats.skb_allocated);
817 len += snprintf(buf + len, sizeof(buf) - len,
818 "%20s : %10u\n", "SKBs completed",
819 priv->debug.rx_stats.skb_completed);
820 len += snprintf(buf + len, sizeof(buf) - len,
821 "%20s : %10u\n", "SKBs Dropped",
822 priv->debug.rx_stats.skb_dropped);
824 if (len > sizeof(buf))
827 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
830 static const struct file_operations fops_recv = {
831 .read = read_file_recv,
832 .open = ath9k_debugfs_open,
833 .owner = THIS_MODULE,
834 .llseek = default_llseek,
837 int ath9k_htc_init_debug(struct ath_hw *ah)
839 struct ath_common *common = ath9k_hw_common(ah);
840 struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *) common->priv;
842 if (!ath9k_debugfs_root)
845 priv->debug.debugfs_phy = debugfs_create_dir(wiphy_name(priv->hw->wiphy),
847 if (!priv->debug.debugfs_phy)
850 priv->debug.debugfs_tgt_stats = debugfs_create_file("tgt_stats", S_IRUSR,
851 priv->debug.debugfs_phy,
852 priv, &fops_tgt_stats);
853 if (!priv->debug.debugfs_tgt_stats)
857 priv->debug.debugfs_xmit = debugfs_create_file("xmit", S_IRUSR,
858 priv->debug.debugfs_phy,
860 if (!priv->debug.debugfs_xmit)
863 priv->debug.debugfs_recv = debugfs_create_file("recv", S_IRUSR,
864 priv->debug.debugfs_phy,
866 if (!priv->debug.debugfs_recv)
872 ath9k_htc_exit_debug(ah);
876 void ath9k_htc_exit_debug(struct ath_hw *ah)
878 struct ath_common *common = ath9k_hw_common(ah);
879 struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *) common->priv;
881 debugfs_remove(priv->debug.debugfs_recv);
882 debugfs_remove(priv->debug.debugfs_xmit);
883 debugfs_remove(priv->debug.debugfs_tgt_stats);
884 debugfs_remove(priv->debug.debugfs_phy);
887 int ath9k_htc_debug_create_root(void)
889 ath9k_debugfs_root = debugfs_create_dir(KBUILD_MODNAME, NULL);
890 if (!ath9k_debugfs_root)
896 void ath9k_htc_debug_remove_root(void)
898 debugfs_remove(ath9k_debugfs_root);
899 ath9k_debugfs_root = NULL;
902 #endif /* CONFIG_ATH9K_HTC_DEBUGFS */
908 void ath_start_ani(struct ath9k_htc_priv *priv)
910 struct ath_common *common = ath9k_hw_common(priv->ah);
911 unsigned long timestamp = jiffies_to_msecs(jiffies);
913 common->ani.longcal_timer = timestamp;
914 common->ani.shortcal_timer = timestamp;
915 common->ani.checkani_timer = timestamp;
917 ieee80211_queue_delayed_work(common->hw, &priv->ath9k_ani_work,
918 msecs_to_jiffies(ATH_ANI_POLLINTERVAL));
921 void ath9k_ani_work(struct work_struct *work)
923 struct ath9k_htc_priv *priv =
924 container_of(work, struct ath9k_htc_priv,
925 ath9k_ani_work.work);
926 struct ath_hw *ah = priv->ah;
927 struct ath_common *common = ath9k_hw_common(ah);
928 bool longcal = false;
929 bool shortcal = false;
930 bool aniflag = false;
931 unsigned int timestamp = jiffies_to_msecs(jiffies);
932 u32 cal_interval, short_cal_interval;
934 short_cal_interval = ATH_STA_SHORT_CALINTERVAL;
936 /* Only calibrate if awake */
937 if (ah->power_mode != ATH9K_PM_AWAKE)
940 /* Long calibration runs independently of short calibration. */
941 if ((timestamp - common->ani.longcal_timer) >= ATH_LONG_CALINTERVAL) {
943 ath_dbg(common, ATH_DBG_ANI, "longcal @%lu\n", jiffies);
944 common->ani.longcal_timer = timestamp;
947 /* Short calibration applies only while caldone is false */
948 if (!common->ani.caldone) {
949 if ((timestamp - common->ani.shortcal_timer) >=
950 short_cal_interval) {
952 ath_dbg(common, ATH_DBG_ANI,
953 "shortcal @%lu\n", jiffies);
954 common->ani.shortcal_timer = timestamp;
955 common->ani.resetcal_timer = timestamp;
958 if ((timestamp - common->ani.resetcal_timer) >=
959 ATH_RESTART_CALINTERVAL) {
960 common->ani.caldone = ath9k_hw_reset_calvalid(ah);
961 if (common->ani.caldone)
962 common->ani.resetcal_timer = timestamp;
966 /* Verify whether we must check ANI */
967 if ((timestamp - common->ani.checkani_timer) >= ATH_ANI_POLLINTERVAL) {
969 common->ani.checkani_timer = timestamp;
972 /* Skip all processing if there's nothing to do. */
973 if (longcal || shortcal || aniflag) {
975 ath9k_htc_ps_wakeup(priv);
977 /* Call ANI routine if necessary */
979 ath9k_hw_ani_monitor(ah, ah->curchan);
981 /* Perform calibration if necessary */
982 if (longcal || shortcal)
983 common->ani.caldone =
984 ath9k_hw_calibrate(ah, ah->curchan,
985 common->rx_chainmask,
988 ath9k_htc_ps_restore(priv);
993 * Set timer interval based on previous results.
994 * The interval must be the shortest necessary to satisfy ANI,
995 * short calibration and long calibration.
997 cal_interval = ATH_LONG_CALINTERVAL;
998 if (priv->ah->config.enable_ani)
999 cal_interval = min(cal_interval, (u32)ATH_ANI_POLLINTERVAL);
1000 if (!common->ani.caldone)
1001 cal_interval = min(cal_interval, (u32)short_cal_interval);
1003 ieee80211_queue_delayed_work(common->hw, &priv->ath9k_ani_work,
1004 msecs_to_jiffies(cal_interval));
1007 /**********************/
1008 /* mac80211 Callbacks */
1009 /**********************/
1011 static int ath9k_htc_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
1013 struct ieee80211_hdr *hdr;
1014 struct ath9k_htc_priv *priv = hw->priv;
1015 int padpos, padsize, ret;
1017 hdr = (struct ieee80211_hdr *) skb->data;
1019 /* Add the padding after the header if this is not already done */
1020 padpos = ath9k_cmn_padpos(hdr->frame_control);
1021 padsize = padpos & 3;
1022 if (padsize && skb->len > padpos) {
1023 if (skb_headroom(skb) < padsize)
1025 skb_push(skb, padsize);
1026 memmove(skb->data, skb->data + padsize, padpos);
1029 ret = ath9k_htc_tx_start(priv, skb);
1031 if (ret == -ENOMEM) {
1032 ath_dbg(ath9k_hw_common(priv->ah), ATH_DBG_XMIT,
1033 "Stopping TX queues\n");
1034 ieee80211_stop_queues(hw);
1035 spin_lock_bh(&priv->tx_lock);
1036 priv->tx_queues_stop = true;
1037 spin_unlock_bh(&priv->tx_lock);
1039 ath_dbg(ath9k_hw_common(priv->ah), ATH_DBG_XMIT,
1048 dev_kfree_skb_any(skb);
1052 static int ath9k_htc_start(struct ieee80211_hw *hw)
1054 struct ath9k_htc_priv *priv = hw->priv;
1055 struct ath_hw *ah = priv->ah;
1056 struct ath_common *common = ath9k_hw_common(ah);
1057 struct ieee80211_channel *curchan = hw->conf.channel;
1058 struct ath9k_channel *init_channel;
1060 enum htc_phymode mode;
1064 mutex_lock(&priv->mutex);
1066 ath_dbg(common, ATH_DBG_CONFIG,
1067 "Starting driver with initial channel: %d MHz\n",
1068 curchan->center_freq);
1070 /* Ensure that HW is awake before flushing RX */
1071 ath9k_htc_setpower(priv, ATH9K_PM_AWAKE);
1072 WMI_CMD(WMI_FLUSH_RECV_CMDID);
1074 /* setup initial channel */
1075 init_channel = ath9k_cmn_get_curchannel(hw, ah);
1077 ath9k_hw_htc_resetinit(ah);
1078 ret = ath9k_hw_reset(ah, init_channel, ah->caldata, false);
1081 "Unable to reset hardware; reset status %d (freq %u MHz)\n",
1082 ret, curchan->center_freq);
1083 mutex_unlock(&priv->mutex);
1087 ath9k_cmn_update_txpow(ah, priv->curtxpow, priv->txpowlimit,
1090 mode = ath9k_htc_get_curmode(priv, init_channel);
1091 htc_mode = cpu_to_be16(mode);
1092 WMI_CMD_BUF(WMI_SET_MODE_CMDID, &htc_mode);
1093 WMI_CMD(WMI_ATH_INIT_CMDID);
1094 WMI_CMD(WMI_START_RECV_CMDID);
1096 ath9k_host_rx_init(priv);
1098 ret = ath9k_htc_update_cap_target(priv);
1100 ath_dbg(common, ATH_DBG_CONFIG,
1101 "Failed to update capability in target\n");
1103 priv->op_flags &= ~OP_INVALID;
1104 htc_start(priv->htc);
1106 spin_lock_bh(&priv->tx_lock);
1107 priv->tx_queues_stop = false;
1108 spin_unlock_bh(&priv->tx_lock);
1110 ieee80211_wake_queues(hw);
1112 if (ah->btcoex_hw.scheme == ATH_BTCOEX_CFG_3WIRE) {
1113 ath9k_hw_btcoex_set_weight(ah, AR_BT_COEX_WGHT,
1114 AR_STOMP_LOW_WLAN_WGHT);
1115 ath9k_hw_btcoex_enable(ah);
1116 ath_htc_resume_btcoex_work(priv);
1118 mutex_unlock(&priv->mutex);
1123 static void ath9k_htc_stop(struct ieee80211_hw *hw)
1125 struct ath9k_htc_priv *priv = hw->priv;
1126 struct ath_hw *ah = priv->ah;
1127 struct ath_common *common = ath9k_hw_common(ah);
1131 mutex_lock(&priv->mutex);
1133 if (priv->op_flags & OP_INVALID) {
1134 ath_dbg(common, ATH_DBG_ANY, "Device not present\n");
1135 mutex_unlock(&priv->mutex);
1139 ath9k_htc_ps_wakeup(priv);
1140 htc_stop(priv->htc);
1141 WMI_CMD(WMI_DISABLE_INTR_CMDID);
1142 WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID);
1143 WMI_CMD(WMI_STOP_RECV_CMDID);
1145 tasklet_kill(&priv->swba_tasklet);
1146 tasklet_kill(&priv->rx_tasklet);
1147 tasklet_kill(&priv->tx_tasklet);
1149 skb_queue_purge(&priv->tx_queue);
1151 mutex_unlock(&priv->mutex);
1153 /* Cancel all the running timers/work .. */
1154 cancel_work_sync(&priv->fatal_work);
1155 cancel_work_sync(&priv->ps_work);
1156 cancel_delayed_work_sync(&priv->ath9k_led_blink_work);
1157 cancel_delayed_work_sync(&priv->ath9k_ani_work);
1158 ath9k_led_stop_brightness(priv);
1160 mutex_lock(&priv->mutex);
1162 if (ah->btcoex_hw.enabled) {
1163 ath9k_hw_btcoex_disable(ah);
1164 if (ah->btcoex_hw.scheme == ATH_BTCOEX_CFG_3WIRE)
1165 ath_htc_cancel_btcoex_work(priv);
1168 /* Remove a monitor interface if it's present. */
1169 if (priv->ah->is_monitoring)
1170 ath9k_htc_remove_monitor_interface(priv);
1172 ath9k_hw_phy_disable(ah);
1173 ath9k_hw_disable(ah);
1174 ath9k_htc_ps_restore(priv);
1175 ath9k_htc_setpower(priv, ATH9K_PM_FULL_SLEEP);
1177 priv->op_flags |= OP_INVALID;
1179 ath_dbg(common, ATH_DBG_CONFIG, "Driver halt\n");
1180 mutex_unlock(&priv->mutex);
1183 static int ath9k_htc_add_interface(struct ieee80211_hw *hw,
1184 struct ieee80211_vif *vif)
1186 struct ath9k_htc_priv *priv = hw->priv;
1187 struct ath9k_htc_vif *avp = (void *)vif->drv_priv;
1188 struct ath_common *common = ath9k_hw_common(priv->ah);
1189 struct ath9k_htc_target_vif hvif;
1193 mutex_lock(&priv->mutex);
1195 if (priv->nvifs >= ATH9K_HTC_MAX_VIF) {
1196 mutex_unlock(&priv->mutex);
1200 if (priv->num_ibss_vif ||
1201 (priv->nvifs && vif->type == NL80211_IFTYPE_ADHOC)) {
1202 ath_err(common, "IBSS coexistence with other modes is not allowed\n");
1203 mutex_unlock(&priv->mutex);
1207 ath9k_htc_ps_wakeup(priv);
1208 memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif));
1209 memcpy(&hvif.myaddr, vif->addr, ETH_ALEN);
1211 switch (vif->type) {
1212 case NL80211_IFTYPE_STATION:
1213 hvif.opmode = cpu_to_be32(HTC_M_STA);
1215 case NL80211_IFTYPE_ADHOC:
1216 hvif.opmode = cpu_to_be32(HTC_M_IBSS);
1220 "Interface type %d not yet supported\n", vif->type);
1225 /* Index starts from zero on the target */
1226 avp->index = hvif.index = ffz(priv->vif_slot);
1227 hvif.rtsthreshold = cpu_to_be16(2304);
1228 WMI_CMD_BUF(WMI_VAP_CREATE_CMDID, &hvif);
1233 * We need a node in target to tx mgmt frames
1234 * before association.
1236 ret = ath9k_htc_add_station(priv, vif, NULL);
1238 WMI_CMD_BUF(WMI_VAP_REMOVE_CMDID, &hvif);
1242 ath9k_htc_set_bssid_mask(priv, vif);
1244 priv->ah->opmode = vif->type;
1245 priv->vif_slot |= (1 << avp->index);
1249 INC_VIF(priv, vif->type);
1251 ath_dbg(common, ATH_DBG_CONFIG,
1252 "Attach a VIF of type: %d at idx: %d\n", vif->type, avp->index);
1255 ath9k_htc_ps_restore(priv);
1256 mutex_unlock(&priv->mutex);
1261 static void ath9k_htc_remove_interface(struct ieee80211_hw *hw,
1262 struct ieee80211_vif *vif)
1264 struct ath9k_htc_priv *priv = hw->priv;
1265 struct ath_common *common = ath9k_hw_common(priv->ah);
1266 struct ath9k_htc_vif *avp = (void *)vif->drv_priv;
1267 struct ath9k_htc_target_vif hvif;
1271 mutex_lock(&priv->mutex);
1272 ath9k_htc_ps_wakeup(priv);
1274 memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif));
1275 memcpy(&hvif.myaddr, vif->addr, ETH_ALEN);
1276 hvif.index = avp->index;
1277 WMI_CMD_BUF(WMI_VAP_REMOVE_CMDID, &hvif);
1279 priv->vif_slot &= ~(1 << avp->index);
1281 ath9k_htc_remove_station(priv, vif, NULL);
1284 DEC_VIF(priv, vif->type);
1286 ath_dbg(common, ATH_DBG_CONFIG, "Detach Interface at idx: %d\n", avp->index);
1288 ath9k_htc_ps_restore(priv);
1289 mutex_unlock(&priv->mutex);
1292 static int ath9k_htc_config(struct ieee80211_hw *hw, u32 changed)
1294 struct ath9k_htc_priv *priv = hw->priv;
1295 struct ath_common *common = ath9k_hw_common(priv->ah);
1296 struct ieee80211_conf *conf = &hw->conf;
1298 mutex_lock(&priv->mutex);
1300 if (changed & IEEE80211_CONF_CHANGE_IDLE) {
1301 bool enable_radio = false;
1302 bool idle = !!(conf->flags & IEEE80211_CONF_IDLE);
1304 mutex_lock(&priv->htc_pm_lock);
1305 if (!idle && priv->ps_idle)
1306 enable_radio = true;
1307 priv->ps_idle = idle;
1308 mutex_unlock(&priv->htc_pm_lock);
1311 ath_dbg(common, ATH_DBG_CONFIG,
1312 "not-idle: enabling radio\n");
1313 ath9k_htc_setpower(priv, ATH9K_PM_AWAKE);
1314 ath9k_htc_radio_enable(hw);
1319 * Monitor interface should be added before
1320 * IEEE80211_CONF_CHANGE_CHANNEL is handled.
1322 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
1323 if ((conf->flags & IEEE80211_CONF_MONITOR) &&
1324 !priv->ah->is_monitoring)
1325 ath9k_htc_add_monitor_interface(priv);
1326 else if (priv->ah->is_monitoring)
1327 ath9k_htc_remove_monitor_interface(priv);
1330 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
1331 struct ieee80211_channel *curchan = hw->conf.channel;
1332 int pos = curchan->hw_value;
1334 ath_dbg(common, ATH_DBG_CONFIG, "Set channel: %d MHz\n",
1335 curchan->center_freq);
1337 ath9k_cmn_update_ichannel(&priv->ah->channels[pos],
1339 hw->conf.channel_type);
1341 if (ath9k_htc_set_channel(priv, hw, &priv->ah->channels[pos]) < 0) {
1342 ath_err(common, "Unable to set channel\n");
1343 mutex_unlock(&priv->mutex);
1349 if (changed & IEEE80211_CONF_CHANGE_PS) {
1350 if (conf->flags & IEEE80211_CONF_PS) {
1351 ath9k_htc_setpower(priv, ATH9K_PM_NETWORK_SLEEP);
1352 priv->ps_enabled = true;
1354 priv->ps_enabled = false;
1355 cancel_work_sync(&priv->ps_work);
1356 ath9k_htc_setpower(priv, ATH9K_PM_AWAKE);
1360 if (changed & IEEE80211_CONF_CHANGE_POWER) {
1361 priv->txpowlimit = 2 * conf->power_level;
1362 ath9k_cmn_update_txpow(priv->ah, priv->curtxpow,
1363 priv->txpowlimit, &priv->curtxpow);
1366 if (changed & IEEE80211_CONF_CHANGE_IDLE) {
1367 mutex_lock(&priv->htc_pm_lock);
1368 if (!priv->ps_idle) {
1369 mutex_unlock(&priv->htc_pm_lock);
1372 mutex_unlock(&priv->htc_pm_lock);
1374 ath_dbg(common, ATH_DBG_CONFIG,
1375 "idle: disabling radio\n");
1376 ath9k_htc_radio_disable(hw);
1380 mutex_unlock(&priv->mutex);
1384 #define SUPPORTED_FILTERS \
1385 (FIF_PROMISC_IN_BSS | \
1390 FIF_BCN_PRBRESP_PROMISC | \
1394 static void ath9k_htc_configure_filter(struct ieee80211_hw *hw,
1395 unsigned int changed_flags,
1396 unsigned int *total_flags,
1399 struct ath9k_htc_priv *priv = hw->priv;
1402 mutex_lock(&priv->mutex);
1403 ath9k_htc_ps_wakeup(priv);
1405 changed_flags &= SUPPORTED_FILTERS;
1406 *total_flags &= SUPPORTED_FILTERS;
1408 priv->rxfilter = *total_flags;
1409 rfilt = ath9k_htc_calcrxfilter(priv);
1410 ath9k_hw_setrxfilter(priv->ah, rfilt);
1412 ath_dbg(ath9k_hw_common(priv->ah), ATH_DBG_CONFIG,
1413 "Set HW RX filter: 0x%x\n", rfilt);
1415 ath9k_htc_ps_restore(priv);
1416 mutex_unlock(&priv->mutex);
1419 static int ath9k_htc_sta_add(struct ieee80211_hw *hw,
1420 struct ieee80211_vif *vif,
1421 struct ieee80211_sta *sta)
1423 struct ath9k_htc_priv *priv = hw->priv;
1426 mutex_lock(&priv->mutex);
1427 ath9k_htc_ps_wakeup(priv);
1428 ret = ath9k_htc_add_station(priv, vif, sta);
1430 ath9k_htc_init_rate(priv, sta);
1431 ath9k_htc_ps_restore(priv);
1432 mutex_unlock(&priv->mutex);
1437 static int ath9k_htc_sta_remove(struct ieee80211_hw *hw,
1438 struct ieee80211_vif *vif,
1439 struct ieee80211_sta *sta)
1441 struct ath9k_htc_priv *priv = hw->priv;
1444 mutex_lock(&priv->mutex);
1445 ath9k_htc_ps_wakeup(priv);
1446 ret = ath9k_htc_remove_station(priv, vif, sta);
1447 ath9k_htc_ps_restore(priv);
1448 mutex_unlock(&priv->mutex);
1453 static int ath9k_htc_conf_tx(struct ieee80211_hw *hw, u16 queue,
1454 const struct ieee80211_tx_queue_params *params)
1456 struct ath9k_htc_priv *priv = hw->priv;
1457 struct ath_common *common = ath9k_hw_common(priv->ah);
1458 struct ath9k_tx_queue_info qi;
1461 if (queue >= WME_NUM_AC)
1464 mutex_lock(&priv->mutex);
1465 ath9k_htc_ps_wakeup(priv);
1467 memset(&qi, 0, sizeof(struct ath9k_tx_queue_info));
1469 qi.tqi_aifs = params->aifs;
1470 qi.tqi_cwmin = params->cw_min;
1471 qi.tqi_cwmax = params->cw_max;
1472 qi.tqi_burstTime = params->txop;
1474 qnum = get_hw_qnum(queue, priv->hwq_map);
1476 ath_dbg(common, ATH_DBG_CONFIG,
1477 "Configure tx [queue/hwq] [%d/%d], aifs: %d, cw_min: %d, cw_max: %d, txop: %d\n",
1478 queue, qnum, params->aifs, params->cw_min,
1479 params->cw_max, params->txop);
1481 ret = ath_htc_txq_update(priv, qnum, &qi);
1483 ath_err(common, "TXQ Update failed\n");
1487 if ((priv->ah->opmode == NL80211_IFTYPE_ADHOC) &&
1488 (qnum == priv->hwq_map[WME_AC_BE]))
1489 ath9k_htc_beaconq_config(priv);
1491 ath9k_htc_ps_restore(priv);
1492 mutex_unlock(&priv->mutex);
1497 static int ath9k_htc_set_key(struct ieee80211_hw *hw,
1498 enum set_key_cmd cmd,
1499 struct ieee80211_vif *vif,
1500 struct ieee80211_sta *sta,
1501 struct ieee80211_key_conf *key)
1503 struct ath9k_htc_priv *priv = hw->priv;
1504 struct ath_common *common = ath9k_hw_common(priv->ah);
1507 if (htc_modparam_nohwcrypt)
1510 mutex_lock(&priv->mutex);
1511 ath_dbg(common, ATH_DBG_CONFIG, "Set HW Key\n");
1512 ath9k_htc_ps_wakeup(priv);
1516 ret = ath_key_config(common, vif, sta, key);
1518 key->hw_key_idx = ret;
1519 /* push IV and Michael MIC generation to stack */
1520 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
1521 if (key->cipher == WLAN_CIPHER_SUITE_TKIP)
1522 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
1523 if (priv->ah->sw_mgmt_crypto &&
1524 key->cipher == WLAN_CIPHER_SUITE_CCMP)
1525 key->flags |= IEEE80211_KEY_FLAG_SW_MGMT;
1530 ath_key_delete(common, key);
1536 ath9k_htc_ps_restore(priv);
1537 mutex_unlock(&priv->mutex);
1542 static void ath9k_htc_bss_info_changed(struct ieee80211_hw *hw,
1543 struct ieee80211_vif *vif,
1544 struct ieee80211_bss_conf *bss_conf,
1547 struct ath9k_htc_priv *priv = hw->priv;
1548 struct ath_hw *ah = priv->ah;
1549 struct ath_common *common = ath9k_hw_common(ah);
1551 mutex_lock(&priv->mutex);
1552 ath9k_htc_ps_wakeup(priv);
1554 if (changed & BSS_CHANGED_ASSOC) {
1555 common->curaid = bss_conf->assoc ?
1557 ath_dbg(common, ATH_DBG_CONFIG, "BSS Changed ASSOC %d\n",
1560 if (bss_conf->assoc)
1561 ath_start_ani(priv);
1563 cancel_delayed_work_sync(&priv->ath9k_ani_work);
1566 if (changed & BSS_CHANGED_BSSID) {
1568 memcpy(common->curbssid, bss_conf->bssid, ETH_ALEN);
1569 ath9k_hw_write_associd(ah);
1571 ath_dbg(common, ATH_DBG_CONFIG,
1572 "BSSID: %pM aid: 0x%x\n",
1573 common->curbssid, common->curaid);
1576 if ((changed & BSS_CHANGED_BEACON_INT) ||
1577 (changed & BSS_CHANGED_BEACON) ||
1578 ((changed & BSS_CHANGED_BEACON_ENABLED) &&
1579 bss_conf->enable_beacon)) {
1580 priv->op_flags |= OP_ENABLE_BEACON;
1581 ath9k_htc_beacon_config(priv, vif);
1584 if ((changed & BSS_CHANGED_BEACON_ENABLED) &&
1585 !bss_conf->enable_beacon) {
1586 priv->op_flags &= ~OP_ENABLE_BEACON;
1587 ath9k_htc_beacon_config(priv, vif);
1590 if (changed & BSS_CHANGED_ERP_SLOT) {
1591 if (bss_conf->use_short_slot)
1596 ath9k_hw_init_global_settings(ah);
1599 if (changed & BSS_CHANGED_HT)
1600 ath9k_htc_update_rate(priv, vif, bss_conf);
1602 ath9k_htc_ps_restore(priv);
1603 mutex_unlock(&priv->mutex);
1606 static u64 ath9k_htc_get_tsf(struct ieee80211_hw *hw)
1608 struct ath9k_htc_priv *priv = hw->priv;
1611 mutex_lock(&priv->mutex);
1612 ath9k_htc_ps_wakeup(priv);
1613 tsf = ath9k_hw_gettsf64(priv->ah);
1614 ath9k_htc_ps_restore(priv);
1615 mutex_unlock(&priv->mutex);
1620 static void ath9k_htc_set_tsf(struct ieee80211_hw *hw, u64 tsf)
1622 struct ath9k_htc_priv *priv = hw->priv;
1624 mutex_lock(&priv->mutex);
1625 ath9k_htc_ps_wakeup(priv);
1626 ath9k_hw_settsf64(priv->ah, tsf);
1627 ath9k_htc_ps_restore(priv);
1628 mutex_unlock(&priv->mutex);
1631 static void ath9k_htc_reset_tsf(struct ieee80211_hw *hw)
1633 struct ath9k_htc_priv *priv = hw->priv;
1635 mutex_lock(&priv->mutex);
1636 ath9k_htc_ps_wakeup(priv);
1637 ath9k_hw_reset_tsf(priv->ah);
1638 ath9k_htc_ps_restore(priv);
1639 mutex_unlock(&priv->mutex);
1642 static int ath9k_htc_ampdu_action(struct ieee80211_hw *hw,
1643 struct ieee80211_vif *vif,
1644 enum ieee80211_ampdu_mlme_action action,
1645 struct ieee80211_sta *sta,
1646 u16 tid, u16 *ssn, u8 buf_size)
1648 struct ath9k_htc_priv *priv = hw->priv;
1649 struct ath9k_htc_sta *ista;
1652 mutex_lock(&priv->mutex);
1655 case IEEE80211_AMPDU_RX_START:
1657 case IEEE80211_AMPDU_RX_STOP:
1659 case IEEE80211_AMPDU_TX_START:
1660 ret = ath9k_htc_tx_aggr_oper(priv, vif, sta, action, tid);
1662 ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid);
1664 case IEEE80211_AMPDU_TX_STOP:
1665 ath9k_htc_tx_aggr_oper(priv, vif, sta, action, tid);
1666 ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid);
1668 case IEEE80211_AMPDU_TX_OPERATIONAL:
1669 ista = (struct ath9k_htc_sta *) sta->drv_priv;
1670 spin_lock_bh(&priv->tx_lock);
1671 ista->tid_state[tid] = AGGR_OPERATIONAL;
1672 spin_unlock_bh(&priv->tx_lock);
1675 ath_err(ath9k_hw_common(priv->ah), "Unknown AMPDU action\n");
1678 mutex_unlock(&priv->mutex);
1683 static void ath9k_htc_sw_scan_start(struct ieee80211_hw *hw)
1685 struct ath9k_htc_priv *priv = hw->priv;
1687 mutex_lock(&priv->mutex);
1688 spin_lock_bh(&priv->beacon_lock);
1689 priv->op_flags |= OP_SCANNING;
1690 spin_unlock_bh(&priv->beacon_lock);
1691 cancel_work_sync(&priv->ps_work);
1692 cancel_delayed_work_sync(&priv->ath9k_ani_work);
1693 mutex_unlock(&priv->mutex);
1696 static void ath9k_htc_sw_scan_complete(struct ieee80211_hw *hw)
1698 struct ath9k_htc_priv *priv = hw->priv;
1700 mutex_lock(&priv->mutex);
1701 spin_lock_bh(&priv->beacon_lock);
1702 priv->op_flags &= ~OP_SCANNING;
1703 spin_unlock_bh(&priv->beacon_lock);
1704 ath9k_htc_ps_wakeup(priv);
1705 ath9k_htc_vif_reconfig(priv);
1706 ath9k_htc_ps_restore(priv);
1707 mutex_unlock(&priv->mutex);
1710 static int ath9k_htc_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
1715 static void ath9k_htc_set_coverage_class(struct ieee80211_hw *hw,
1718 struct ath9k_htc_priv *priv = hw->priv;
1720 mutex_lock(&priv->mutex);
1721 ath9k_htc_ps_wakeup(priv);
1722 priv->ah->coverage_class = coverage_class;
1723 ath9k_hw_init_global_settings(priv->ah);
1724 ath9k_htc_ps_restore(priv);
1725 mutex_unlock(&priv->mutex);
1728 struct ieee80211_ops ath9k_htc_ops = {
1730 .start = ath9k_htc_start,
1731 .stop = ath9k_htc_stop,
1732 .add_interface = ath9k_htc_add_interface,
1733 .remove_interface = ath9k_htc_remove_interface,
1734 .config = ath9k_htc_config,
1735 .configure_filter = ath9k_htc_configure_filter,
1736 .sta_add = ath9k_htc_sta_add,
1737 .sta_remove = ath9k_htc_sta_remove,
1738 .conf_tx = ath9k_htc_conf_tx,
1739 .bss_info_changed = ath9k_htc_bss_info_changed,
1740 .set_key = ath9k_htc_set_key,
1741 .get_tsf = ath9k_htc_get_tsf,
1742 .set_tsf = ath9k_htc_set_tsf,
1743 .reset_tsf = ath9k_htc_reset_tsf,
1744 .ampdu_action = ath9k_htc_ampdu_action,
1745 .sw_scan_start = ath9k_htc_sw_scan_start,
1746 .sw_scan_complete = ath9k_htc_sw_scan_complete,
1747 .set_rts_threshold = ath9k_htc_set_rts_threshold,
1748 .rfkill_poll = ath9k_htc_rfkill_poll_state,
1749 .set_coverage_class = ath9k_htc_set_coverage_class,