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 int ath9k_htc_set_channel(struct ath9k_htc_priv *priv,
69 struct ieee80211_hw *hw,
70 struct ath9k_channel *hchan)
72 struct ath_hw *ah = priv->ah;
73 struct ath_common *common = ath9k_hw_common(ah);
74 struct ieee80211_conf *conf = &common->hw->conf;
76 struct ieee80211_channel *channel = hw->conf.channel;
77 enum htc_phymode mode;
82 if (priv->op_flags & OP_INVALID)
85 if (priv->op_flags & OP_FULL_RESET)
88 /* Fiddle around with fastcc later on, for now just use full reset */
92 WMI_CMD(WMI_DISABLE_INTR_CMDID);
93 WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID);
94 WMI_CMD(WMI_STOP_RECV_CMDID);
96 ath_print(common, ATH_DBG_CONFIG,
97 "(%u MHz) -> (%u MHz), HT: %d, HT40: %d\n",
98 priv->ah->curchan->channel,
99 channel->center_freq, conf_is_ht(conf), conf_is_ht40(conf));
101 ret = ath9k_hw_reset(ah, hchan, fastcc);
103 ath_print(common, ATH_DBG_FATAL,
104 "Unable to reset channel (%u Mhz) "
105 "reset status %d\n", channel->center_freq, ret);
109 ath_update_txpow(priv);
111 WMI_CMD(WMI_START_RECV_CMDID);
115 ath9k_host_rx_init(priv);
117 mode = ath9k_htc_get_curmode(priv, hchan);
118 htc_mode = cpu_to_be16(mode);
119 WMI_CMD_BUF(WMI_SET_MODE_CMDID, &htc_mode);
123 WMI_CMD(WMI_ENABLE_INTR_CMDID);
127 htc_start(priv->htc);
129 priv->op_flags &= ~OP_FULL_RESET;
134 static int ath9k_htc_add_monitor_interface(struct ath9k_htc_priv *priv)
136 struct ath_common *common = ath9k_hw_common(priv->ah);
137 struct ath9k_htc_target_vif hvif;
144 memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif));
145 memcpy(&hvif.myaddr, common->macaddr, ETH_ALEN);
147 hvif.opmode = cpu_to_be32(HTC_M_MONITOR);
148 priv->ah->opmode = NL80211_IFTYPE_MONITOR;
149 hvif.index = priv->nvifs;
151 WMI_CMD_BUF(WMI_VAP_CREATE_CMDID, &hvif);
159 static int ath9k_htc_remove_monitor_interface(struct ath9k_htc_priv *priv)
161 struct ath_common *common = ath9k_hw_common(priv->ah);
162 struct ath9k_htc_target_vif hvif;
166 memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif));
167 memcpy(&hvif.myaddr, common->macaddr, ETH_ALEN);
168 hvif.index = 0; /* Should do for now */
169 WMI_CMD_BUF(WMI_VAP_REMOVE_CMDID, &hvif);
175 static int ath9k_htc_add_station(struct ath9k_htc_priv *priv,
176 struct ieee80211_vif *vif,
177 struct ieee80211_sta *sta)
179 struct ath_common *common = ath9k_hw_common(priv->ah);
180 struct ath9k_htc_target_sta tsta;
181 struct ath9k_htc_vif *avp = (struct ath9k_htc_vif *) vif->drv_priv;
182 struct ath9k_htc_sta *ista;
186 if (priv->nstations >= ATH9K_HTC_MAX_STA)
189 memset(&tsta, 0, sizeof(struct ath9k_htc_target_sta));
192 ista = (struct ath9k_htc_sta *) sta->drv_priv;
193 memcpy(&tsta.macaddr, sta->addr, ETH_ALEN);
194 memcpy(&tsta.bssid, common->curbssid, ETH_ALEN);
195 tsta.associd = common->curaid;
198 ista->index = priv->nstations;
200 memcpy(&tsta.macaddr, vif->addr, ETH_ALEN);
204 tsta.sta_index = priv->nstations;
205 tsta.vif_index = avp->index;
206 tsta.maxampdu = 0xffff;
207 if (sta && sta->ht_cap.ht_supported)
208 tsta.flags = cpu_to_be16(ATH_HTC_STA_HT);
210 WMI_CMD_BUF(WMI_NODE_CREATE_CMDID, &tsta);
213 ath_print(common, ATH_DBG_FATAL,
214 "Unable to add station entry for: %pM\n", sta->addr);
219 ath_print(common, ATH_DBG_CONFIG,
220 "Added a station entry for: %pM (idx: %d)\n",
221 sta->addr, tsta.sta_index);
227 static int ath9k_htc_remove_station(struct ath9k_htc_priv *priv,
228 struct ieee80211_vif *vif,
229 struct ieee80211_sta *sta)
231 struct ath_common *common = ath9k_hw_common(priv->ah);
232 struct ath9k_htc_sta *ista;
237 ista = (struct ath9k_htc_sta *) sta->drv_priv;
238 sta_idx = ista->index;
243 WMI_CMD_BUF(WMI_NODE_REMOVE_CMDID, &sta_idx);
246 ath_print(common, ATH_DBG_FATAL,
247 "Unable to remove station entry for: %pM\n",
253 ath_print(common, ATH_DBG_CONFIG,
254 "Removed a station entry for: %pM (idx: %d)\n",
261 static int ath9k_htc_update_cap_target(struct ath9k_htc_priv *priv)
263 struct ath9k_htc_cap_target tcap;
267 memset(&tcap, 0, sizeof(struct ath9k_htc_cap_target));
269 /* FIXME: Values are hardcoded */
270 tcap.flags = 0x240c40;
271 tcap.flags_ext = 0x80601000;
272 tcap.ampdu_limit = 0xffff0000;
273 tcap.ampdu_subframes = 20;
274 tcap.tx_chainmask_legacy = 1;
276 tcap.tx_chainmask = 1;
278 WMI_CMD_BUF(WMI_TARGET_IC_UPDATE_CMDID, &tcap);
283 static int ath9k_htc_init_rate(struct ath9k_htc_priv *priv,
284 struct ieee80211_vif *vif,
285 struct ieee80211_sta *sta)
287 struct ath_common *common = ath9k_hw_common(priv->ah);
288 struct ath9k_htc_sta *ista = (struct ath9k_htc_sta *) sta->drv_priv;
289 struct ieee80211_supported_band *sband;
290 struct ath9k_htc_target_rate trate;
295 memset(&trate, 0, sizeof(trate));
297 /* Only 2GHz is supported */
298 sband = priv->hw->wiphy->bands[IEEE80211_BAND_2GHZ];
300 for (i = 0, j = 0; i < sband->n_bitrates; i++) {
301 if (sta->supp_rates[sband->band] & BIT(i)) {
302 priv->tgt_rate.rates.legacy_rates.rs_rates[j]
303 = (sband->bitrates[i].bitrate * 2) / 10;
307 priv->tgt_rate.rates.legacy_rates.rs_nrates = j;
309 if (sta->ht_cap.ht_supported) {
310 for (i = 0, j = 0; i < 77; i++) {
311 if (sta->ht_cap.mcs.rx_mask[i/8] & (1<<(i%8)))
312 priv->tgt_rate.rates.ht_rates.rs_rates[j++] = i;
313 if (j == ATH_HTC_RATE_MAX)
316 priv->tgt_rate.rates.ht_rates.rs_nrates = j;
318 caps = WLAN_RC_HT_FLAG;
319 if (sta->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40)
320 caps |= WLAN_RC_40_FLAG;
321 if (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_40)
322 caps |= WLAN_RC_SGI_FLAG;
326 priv->tgt_rate.sta_index = ista->index;
327 priv->tgt_rate.isnew = 1;
328 trate = priv->tgt_rate;
329 priv->tgt_rate.capflags = caps;
330 trate.capflags = cpu_to_be32(caps);
332 WMI_CMD_BUF(WMI_RC_RATE_UPDATE_CMDID, &trate);
334 ath_print(common, ATH_DBG_FATAL,
335 "Unable to initialize Rate information on target\n");
339 ath_print(common, ATH_DBG_CONFIG,
340 "Updated target STA: %pM (caps: 0x%x)\n", sta->addr, caps);
344 static bool check_rc_update(struct ieee80211_hw *hw, bool *cw40)
346 struct ath9k_htc_priv *priv = hw->priv;
347 struct ieee80211_conf *conf = &hw->conf;
349 if (!conf_is_ht(conf))
352 if (!(priv->op_flags & OP_ASSOCIATED) ||
353 (priv->op_flags & OP_SCANNING))
356 if (conf_is_ht40(conf)) {
357 if (priv->ah->curchan->chanmode &
358 (CHANNEL_HT40PLUS | CHANNEL_HT40MINUS)) {
365 if (priv->ah->curchan->chanmode & CHANNEL_HT20)
372 static void ath9k_htc_rc_update(struct ath9k_htc_priv *priv, bool is_cw40)
374 struct ath9k_htc_target_rate trate;
375 struct ath_common *common = ath9k_hw_common(priv->ah);
379 memset(&trate, 0, sizeof(trate));
381 trate = priv->tgt_rate;
384 priv->tgt_rate.capflags |= WLAN_RC_40_FLAG;
386 priv->tgt_rate.capflags &= ~WLAN_RC_40_FLAG;
388 trate.capflags = cpu_to_be32(priv->tgt_rate.capflags);
390 WMI_CMD_BUF(WMI_RC_RATE_UPDATE_CMDID, &trate);
392 ath_print(common, ATH_DBG_FATAL,
393 "Unable to update Rate information on target\n");
397 ath_print(common, ATH_DBG_CONFIG, "Rate control updated with "
398 "caps:0x%x on target\n", priv->tgt_rate.capflags);
401 static int ath9k_htc_aggr_oper(struct ath9k_htc_priv *priv,
402 struct ieee80211_vif *vif,
403 u8 *sta_addr, u8 tid, bool oper)
405 struct ath_common *common = ath9k_hw_common(priv->ah);
406 struct ath9k_htc_target_aggr aggr;
407 struct ieee80211_sta *sta = NULL;
408 struct ath9k_htc_sta *ista = (struct ath9k_htc_sta *) sta->drv_priv;
412 if (tid > ATH9K_HTC_MAX_TID)
415 memset(&aggr, 0, sizeof(struct ath9k_htc_target_aggr));
419 /* Check if we are able to retrieve the station */
420 sta = ieee80211_find_sta(vif, sta_addr);
426 ista = (struct ath9k_htc_sta *) sta->drv_priv;
429 ista->tid_state[tid] = AGGR_START;
431 ista->tid_state[tid] = AGGR_STOP;
433 aggr.sta_index = ista->index;
438 aggr.aggr_enable = oper;
440 WMI_CMD_BUF(WMI_TX_AGGR_ENABLE_CMDID, &aggr);
442 ath_print(common, ATH_DBG_CONFIG,
443 "Unable to %s TX aggregation for (%pM, %d)\n",
444 (oper) ? "start" : "stop", sta->addr, tid);
446 ath_print(common, ATH_DBG_CONFIG,
447 "%s aggregation for (%pM, %d)\n",
448 (oper) ? "Starting" : "Stopping", sta->addr, tid);
453 void ath9k_htc_aggr_work(struct work_struct *work)
456 struct ath9k_htc_priv *priv =
457 container_of(work, struct ath9k_htc_priv,
458 ath9k_aggr_work.work);
459 struct ath9k_htc_aggr_work *wk = &priv->aggr_work;
461 mutex_lock(&wk->mutex);
463 switch (wk->action) {
464 case IEEE80211_AMPDU_TX_START:
465 ret = ath9k_htc_aggr_oper(priv, wk->vif, wk->sta_addr,
468 ieee80211_start_tx_ba_cb(wk->vif, wk->sta_addr,
471 case IEEE80211_AMPDU_TX_STOP:
472 ath9k_htc_aggr_oper(priv, wk->vif, wk->sta_addr,
474 ieee80211_stop_tx_ba_cb(wk->vif, wk->sta_addr, wk->tid);
477 ath_print(ath9k_hw_common(priv->ah), ATH_DBG_FATAL,
478 "Unknown AMPDU action\n");
481 mutex_unlock(&wk->mutex);
488 #ifdef CONFIG_ATH9K_HTC_DEBUGFS
490 static int ath9k_debugfs_open(struct inode *inode, struct file *file)
492 file->private_data = inode->i_private;
496 static ssize_t read_file_tgt_stats(struct file *file, char __user *user_buf,
497 size_t count, loff_t *ppos)
499 struct ath9k_htc_priv *priv =
500 (struct ath9k_htc_priv *) file->private_data;
501 struct ath9k_htc_target_stats cmd_rsp;
503 unsigned int len = 0;
506 memset(&cmd_rsp, 0, sizeof(cmd_rsp));
508 WMI_CMD(WMI_TGT_STATS_CMDID);
513 len += snprintf(buf + len, sizeof(buf) - len,
514 "%19s : %10u\n", "TX Short Retries",
515 be32_to_cpu(cmd_rsp.tx_shortretry));
516 len += snprintf(buf + len, sizeof(buf) - len,
517 "%19s : %10u\n", "TX Long Retries",
518 be32_to_cpu(cmd_rsp.tx_longretry));
519 len += snprintf(buf + len, sizeof(buf) - len,
520 "%19s : %10u\n", "TX Xretries",
521 be32_to_cpu(cmd_rsp.tx_xretries));
522 len += snprintf(buf + len, sizeof(buf) - len,
523 "%19s : %10u\n", "TX Unaggr. Xretries",
524 be32_to_cpu(cmd_rsp.ht_txunaggr_xretry));
525 len += snprintf(buf + len, sizeof(buf) - len,
526 "%19s : %10u\n", "TX Xretries (HT)",
527 be32_to_cpu(cmd_rsp.ht_tx_xretries));
528 len += snprintf(buf + len, sizeof(buf) - len,
529 "%19s : %10u\n", "TX Rate", priv->debug.txrate);
531 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
534 static const struct file_operations fops_tgt_stats = {
535 .read = read_file_tgt_stats,
536 .open = ath9k_debugfs_open,
540 static ssize_t read_file_xmit(struct file *file, char __user *user_buf,
541 size_t count, loff_t *ppos)
543 struct ath9k_htc_priv *priv =
544 (struct ath9k_htc_priv *) file->private_data;
546 unsigned int len = 0;
548 len += snprintf(buf + len, sizeof(buf) - len,
549 "%20s : %10u\n", "Buffers queued",
550 priv->debug.tx_stats.buf_queued);
551 len += snprintf(buf + len, sizeof(buf) - len,
552 "%20s : %10u\n", "Buffers completed",
553 priv->debug.tx_stats.buf_completed);
554 len += snprintf(buf + len, sizeof(buf) - len,
555 "%20s : %10u\n", "SKBs queued",
556 priv->debug.tx_stats.skb_queued);
557 len += snprintf(buf + len, sizeof(buf) - len,
558 "%20s : %10u\n", "SKBs completed",
559 priv->debug.tx_stats.skb_completed);
561 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
564 static const struct file_operations fops_xmit = {
565 .read = read_file_xmit,
566 .open = ath9k_debugfs_open,
570 static ssize_t read_file_recv(struct file *file, char __user *user_buf,
571 size_t count, loff_t *ppos)
573 struct ath9k_htc_priv *priv =
574 (struct ath9k_htc_priv *) file->private_data;
576 unsigned int len = 0;
578 len += snprintf(buf + len, sizeof(buf) - len,
579 "%20s : %10u\n", "SKBs allocated",
580 priv->debug.rx_stats.skb_allocated);
581 len += snprintf(buf + len, sizeof(buf) - len,
582 "%20s : %10u\n", "SKBs completed",
583 priv->debug.rx_stats.skb_completed);
584 len += snprintf(buf + len, sizeof(buf) - len,
585 "%20s : %10u\n", "SKBs Dropped",
586 priv->debug.rx_stats.skb_dropped);
588 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
591 static const struct file_operations fops_recv = {
592 .read = read_file_recv,
593 .open = ath9k_debugfs_open,
597 int ath9k_htc_init_debug(struct ath_hw *ah)
599 struct ath_common *common = ath9k_hw_common(ah);
600 struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *) common->priv;
602 if (!ath9k_debugfs_root)
605 priv->debug.debugfs_phy = debugfs_create_dir(wiphy_name(priv->hw->wiphy),
607 if (!priv->debug.debugfs_phy)
610 priv->debug.debugfs_tgt_stats = debugfs_create_file("tgt_stats", S_IRUSR,
611 priv->debug.debugfs_phy,
612 priv, &fops_tgt_stats);
613 if (!priv->debug.debugfs_tgt_stats)
617 priv->debug.debugfs_xmit = debugfs_create_file("xmit", S_IRUSR,
618 priv->debug.debugfs_phy,
620 if (!priv->debug.debugfs_xmit)
623 priv->debug.debugfs_recv = debugfs_create_file("recv", S_IRUSR,
624 priv->debug.debugfs_phy,
626 if (!priv->debug.debugfs_recv)
632 ath9k_htc_exit_debug(ah);
636 void ath9k_htc_exit_debug(struct ath_hw *ah)
638 struct ath_common *common = ath9k_hw_common(ah);
639 struct ath9k_htc_priv *priv = (struct ath9k_htc_priv *) common->priv;
641 debugfs_remove(priv->debug.debugfs_recv);
642 debugfs_remove(priv->debug.debugfs_xmit);
643 debugfs_remove(priv->debug.debugfs_tgt_stats);
644 debugfs_remove(priv->debug.debugfs_phy);
647 int ath9k_htc_debug_create_root(void)
649 ath9k_debugfs_root = debugfs_create_dir(KBUILD_MODNAME, NULL);
650 if (!ath9k_debugfs_root)
656 void ath9k_htc_debug_remove_root(void)
658 debugfs_remove(ath9k_debugfs_root);
659 ath9k_debugfs_root = NULL;
662 #endif /* CONFIG_ATH9K_HTC_DEBUGFS */
668 static void ath_start_ani(struct ath9k_htc_priv *priv)
670 struct ath_common *common = ath9k_hw_common(priv->ah);
671 unsigned long timestamp = jiffies_to_msecs(jiffies);
673 common->ani.longcal_timer = timestamp;
674 common->ani.shortcal_timer = timestamp;
675 common->ani.checkani_timer = timestamp;
677 ieee80211_queue_delayed_work(common->hw, &priv->ath9k_ani_work,
678 msecs_to_jiffies(ATH_ANI_POLLINTERVAL));
681 void ath9k_ani_work(struct work_struct *work)
683 struct ath9k_htc_priv *priv =
684 container_of(work, struct ath9k_htc_priv,
685 ath9k_ani_work.work);
686 struct ath_hw *ah = priv->ah;
687 struct ath_common *common = ath9k_hw_common(ah);
688 bool longcal = false;
689 bool shortcal = false;
690 bool aniflag = false;
691 unsigned int timestamp = jiffies_to_msecs(jiffies);
692 u32 cal_interval, short_cal_interval;
694 short_cal_interval = ATH_STA_SHORT_CALINTERVAL;
696 /* Long calibration runs independently of short calibration. */
697 if ((timestamp - common->ani.longcal_timer) >= ATH_LONG_CALINTERVAL) {
699 ath_print(common, ATH_DBG_ANI, "longcal @%lu\n", jiffies);
700 common->ani.longcal_timer = timestamp;
703 /* Short calibration applies only while caldone is false */
704 if (!common->ani.caldone) {
705 if ((timestamp - common->ani.shortcal_timer) >=
706 short_cal_interval) {
708 ath_print(common, ATH_DBG_ANI,
709 "shortcal @%lu\n", jiffies);
710 common->ani.shortcal_timer = timestamp;
711 common->ani.resetcal_timer = timestamp;
714 if ((timestamp - common->ani.resetcal_timer) >=
715 ATH_RESTART_CALINTERVAL) {
716 common->ani.caldone = ath9k_hw_reset_calvalid(ah);
717 if (common->ani.caldone)
718 common->ani.resetcal_timer = timestamp;
722 /* Verify whether we must check ANI */
723 if ((timestamp - common->ani.checkani_timer) >= ATH_ANI_POLLINTERVAL) {
725 common->ani.checkani_timer = timestamp;
728 /* Skip all processing if there's nothing to do. */
729 if (longcal || shortcal || aniflag) {
730 /* Call ANI routine if necessary */
732 ath9k_hw_ani_monitor(ah, ah->curchan);
734 /* Perform calibration if necessary */
735 if (longcal || shortcal) {
736 common->ani.caldone =
737 ath9k_hw_calibrate(ah, ah->curchan,
738 common->rx_chainmask,
742 common->ani.noise_floor =
743 ath9k_hw_getchan_noise(ah, ah->curchan);
745 ath_print(common, ATH_DBG_ANI,
746 " calibrate chan %u/%x nf: %d\n",
747 ah->curchan->channel,
748 ah->curchan->channelFlags,
749 common->ani.noise_floor);
754 * Set timer interval based on previous results.
755 * The interval must be the shortest necessary to satisfy ANI,
756 * short calibration and long calibration.
758 cal_interval = ATH_LONG_CALINTERVAL;
759 if (priv->ah->config.enable_ani)
760 cal_interval = min(cal_interval, (u32)ATH_ANI_POLLINTERVAL);
761 if (!common->ani.caldone)
762 cal_interval = min(cal_interval, (u32)short_cal_interval);
764 ieee80211_queue_delayed_work(common->hw, &priv->ath9k_ani_work,
765 msecs_to_jiffies(cal_interval));
772 static void ath9k_led_blink_work(struct work_struct *work)
774 struct ath9k_htc_priv *priv = container_of(work, struct ath9k_htc_priv,
775 ath9k_led_blink_work.work);
777 if (!(priv->op_flags & OP_LED_ASSOCIATED))
780 if ((priv->led_on_duration == ATH_LED_ON_DURATION_IDLE) ||
781 (priv->led_off_duration == ATH_LED_OFF_DURATION_IDLE))
782 ath9k_hw_set_gpio(priv->ah, priv->ah->led_pin, 0);
784 ath9k_hw_set_gpio(priv->ah, priv->ah->led_pin,
785 (priv->op_flags & OP_LED_ON) ? 1 : 0);
787 ieee80211_queue_delayed_work(priv->hw,
788 &priv->ath9k_led_blink_work,
789 (priv->op_flags & OP_LED_ON) ?
790 msecs_to_jiffies(priv->led_off_duration) :
791 msecs_to_jiffies(priv->led_on_duration));
793 priv->led_on_duration = priv->led_on_cnt ?
794 max((ATH_LED_ON_DURATION_IDLE - priv->led_on_cnt), 25) :
795 ATH_LED_ON_DURATION_IDLE;
796 priv->led_off_duration = priv->led_off_cnt ?
797 max((ATH_LED_OFF_DURATION_IDLE - priv->led_off_cnt), 10) :
798 ATH_LED_OFF_DURATION_IDLE;
799 priv->led_on_cnt = priv->led_off_cnt = 0;
801 if (priv->op_flags & OP_LED_ON)
802 priv->op_flags &= ~OP_LED_ON;
804 priv->op_flags |= OP_LED_ON;
807 static void ath9k_led_brightness_work(struct work_struct *work)
809 struct ath_led *led = container_of(work, struct ath_led,
810 brightness_work.work);
811 struct ath9k_htc_priv *priv = led->priv;
813 switch (led->brightness) {
815 if (led->led_type == ATH_LED_ASSOC ||
816 led->led_type == ATH_LED_RADIO) {
817 ath9k_hw_set_gpio(priv->ah, priv->ah->led_pin,
818 (led->led_type == ATH_LED_RADIO));
819 priv->op_flags &= ~OP_LED_ASSOCIATED;
820 if (led->led_type == ATH_LED_RADIO)
821 priv->op_flags &= ~OP_LED_ON;
827 if (led->led_type == ATH_LED_ASSOC) {
828 priv->op_flags |= OP_LED_ASSOCIATED;
829 ieee80211_queue_delayed_work(priv->hw,
830 &priv->ath9k_led_blink_work, 0);
831 } else if (led->led_type == ATH_LED_RADIO) {
832 ath9k_hw_set_gpio(priv->ah, priv->ah->led_pin, 0);
833 priv->op_flags |= OP_LED_ON;
843 static void ath9k_led_brightness(struct led_classdev *led_cdev,
844 enum led_brightness brightness)
846 struct ath_led *led = container_of(led_cdev, struct ath_led, led_cdev);
847 struct ath9k_htc_priv *priv = led->priv;
849 led->brightness = brightness;
850 if (!(priv->op_flags & OP_LED_DEINIT))
851 ieee80211_queue_delayed_work(priv->hw,
852 &led->brightness_work, 0);
855 static void ath9k_led_stop_brightness(struct ath9k_htc_priv *priv)
857 cancel_delayed_work_sync(&priv->radio_led.brightness_work);
858 cancel_delayed_work_sync(&priv->assoc_led.brightness_work);
859 cancel_delayed_work_sync(&priv->tx_led.brightness_work);
860 cancel_delayed_work_sync(&priv->rx_led.brightness_work);
863 static int ath9k_register_led(struct ath9k_htc_priv *priv, struct ath_led *led,
869 led->led_cdev.name = led->name;
870 led->led_cdev.default_trigger = trigger;
871 led->led_cdev.brightness_set = ath9k_led_brightness;
873 ret = led_classdev_register(wiphy_dev(priv->hw->wiphy), &led->led_cdev);
875 ath_print(ath9k_hw_common(priv->ah), ATH_DBG_FATAL,
876 "Failed to register led:%s", led->name);
880 INIT_DELAYED_WORK(&led->brightness_work, ath9k_led_brightness_work);
885 static void ath9k_unregister_led(struct ath_led *led)
887 if (led->registered) {
888 led_classdev_unregister(&led->led_cdev);
893 void ath9k_deinit_leds(struct ath9k_htc_priv *priv)
895 priv->op_flags |= OP_LED_DEINIT;
896 ath9k_unregister_led(&priv->assoc_led);
897 priv->op_flags &= ~OP_LED_ASSOCIATED;
898 ath9k_unregister_led(&priv->tx_led);
899 ath9k_unregister_led(&priv->rx_led);
900 ath9k_unregister_led(&priv->radio_led);
901 ath9k_hw_set_gpio(priv->ah, priv->ah->led_pin, 1);
904 void ath9k_init_leds(struct ath9k_htc_priv *priv)
909 if (AR_SREV_9287(priv->ah))
910 priv->ah->led_pin = ATH_LED_PIN_9287;
911 else if (AR_SREV_9271(priv->ah))
912 priv->ah->led_pin = ATH_LED_PIN_9271;
914 priv->ah->led_pin = ATH_LED_PIN_DEF;
916 /* Configure gpio 1 for output */
917 ath9k_hw_cfg_output(priv->ah, priv->ah->led_pin,
918 AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
919 /* LED off, active low */
920 ath9k_hw_set_gpio(priv->ah, priv->ah->led_pin, 1);
922 INIT_DELAYED_WORK(&priv->ath9k_led_blink_work, ath9k_led_blink_work);
924 trigger = ieee80211_get_radio_led_name(priv->hw);
925 snprintf(priv->radio_led.name, sizeof(priv->radio_led.name),
926 "ath9k-%s::radio", wiphy_name(priv->hw->wiphy));
927 ret = ath9k_register_led(priv, &priv->radio_led, trigger);
928 priv->radio_led.led_type = ATH_LED_RADIO;
932 trigger = ieee80211_get_assoc_led_name(priv->hw);
933 snprintf(priv->assoc_led.name, sizeof(priv->assoc_led.name),
934 "ath9k-%s::assoc", wiphy_name(priv->hw->wiphy));
935 ret = ath9k_register_led(priv, &priv->assoc_led, trigger);
936 priv->assoc_led.led_type = ATH_LED_ASSOC;
940 trigger = ieee80211_get_tx_led_name(priv->hw);
941 snprintf(priv->tx_led.name, sizeof(priv->tx_led.name),
942 "ath9k-%s::tx", wiphy_name(priv->hw->wiphy));
943 ret = ath9k_register_led(priv, &priv->tx_led, trigger);
944 priv->tx_led.led_type = ATH_LED_TX;
948 trigger = ieee80211_get_rx_led_name(priv->hw);
949 snprintf(priv->rx_led.name, sizeof(priv->rx_led.name),
950 "ath9k-%s::rx", wiphy_name(priv->hw->wiphy));
951 ret = ath9k_register_led(priv, &priv->rx_led, trigger);
952 priv->rx_led.led_type = ATH_LED_RX;
956 priv->op_flags &= ~OP_LED_DEINIT;
961 cancel_delayed_work_sync(&priv->ath9k_led_blink_work);
962 ath9k_deinit_leds(priv);
965 /*******************/
967 /*******************/
969 static bool ath_is_rfkill_set(struct ath9k_htc_priv *priv)
971 return ath9k_hw_gpio_get(priv->ah, priv->ah->rfkill_gpio) ==
972 priv->ah->rfkill_polarity;
975 static void ath9k_htc_rfkill_poll_state(struct ieee80211_hw *hw)
977 struct ath9k_htc_priv *priv = hw->priv;
978 bool blocked = !!ath_is_rfkill_set(priv);
980 wiphy_rfkill_set_hw_state(hw->wiphy, blocked);
983 void ath9k_start_rfkill_poll(struct ath9k_htc_priv *priv)
985 if (priv->ah->caps.hw_caps & ATH9K_HW_CAP_RFSILENT)
986 wiphy_rfkill_start_polling(priv->hw->wiphy);
989 /**********************/
990 /* mac80211 Callbacks */
991 /**********************/
993 static int ath9k_htc_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
995 struct ieee80211_hdr *hdr;
996 struct ath9k_htc_priv *priv = hw->priv;
997 int padpos, padsize, ret;
999 hdr = (struct ieee80211_hdr *) skb->data;
1001 /* Add the padding after the header if this is not already done */
1002 padpos = ath9k_cmn_padpos(hdr->frame_control);
1003 padsize = padpos & 3;
1004 if (padsize && skb->len > padpos) {
1005 if (skb_headroom(skb) < padsize)
1007 skb_push(skb, padsize);
1008 memmove(skb->data, skb->data + padsize, padpos);
1011 ret = ath9k_htc_tx_start(priv, skb);
1013 if (ret == -ENOMEM) {
1014 ath_print(ath9k_hw_common(priv->ah), ATH_DBG_XMIT,
1015 "Stopping TX queues\n");
1016 ieee80211_stop_queues(hw);
1017 spin_lock_bh(&priv->tx_lock);
1018 priv->tx_queues_stop = true;
1019 spin_unlock_bh(&priv->tx_lock);
1021 ath_print(ath9k_hw_common(priv->ah), ATH_DBG_XMIT,
1030 dev_kfree_skb_any(skb);
1034 static int ath9k_htc_start(struct ieee80211_hw *hw)
1036 struct ath9k_htc_priv *priv = hw->priv;
1037 struct ath_hw *ah = priv->ah;
1038 struct ath_common *common = ath9k_hw_common(ah);
1039 struct ieee80211_channel *curchan = hw->conf.channel;
1040 struct ath9k_channel *init_channel;
1042 enum htc_phymode mode;
1046 ath_print(common, ATH_DBG_CONFIG,
1047 "Starting driver with initial channel: %d MHz\n",
1048 curchan->center_freq);
1050 mutex_lock(&priv->mutex);
1052 /* setup initial channel */
1053 init_channel = ath9k_cmn_get_curchannel(hw, ah);
1055 /* Reset SERDES registers */
1056 ath9k_hw_configpcipowersave(ah, 0, 0);
1058 ath9k_hw_htc_resetinit(ah);
1059 ret = ath9k_hw_reset(ah, init_channel, false);
1061 ath_print(common, ATH_DBG_FATAL,
1062 "Unable to reset hardware; reset status %d "
1063 "(freq %u MHz)\n", ret, curchan->center_freq);
1067 ath_update_txpow(priv);
1069 mode = ath9k_htc_get_curmode(priv, init_channel);
1070 htc_mode = cpu_to_be16(mode);
1071 WMI_CMD_BUF(WMI_SET_MODE_CMDID, &htc_mode);
1075 WMI_CMD(WMI_ATH_INIT_CMDID);
1079 WMI_CMD(WMI_START_RECV_CMDID);
1083 ath9k_host_rx_init(priv);
1085 priv->op_flags &= ~OP_INVALID;
1086 htc_start(priv->htc);
1088 spin_lock_bh(&priv->tx_lock);
1089 priv->tx_queues_stop = false;
1090 spin_unlock_bh(&priv->tx_lock);
1092 ieee80211_wake_queues(hw);
1095 mutex_unlock(&priv->mutex);
1099 static void ath9k_htc_stop(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 mutex_lock(&priv->mutex);
1109 if (priv->op_flags & OP_INVALID) {
1110 ath_print(common, ATH_DBG_ANY, "Device not present\n");
1111 mutex_unlock(&priv->mutex);
1115 htc_stop(priv->htc);
1116 WMI_CMD(WMI_DISABLE_INTR_CMDID);
1117 WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID);
1118 WMI_CMD(WMI_STOP_RECV_CMDID);
1119 ath9k_hw_phy_disable(ah);
1120 ath9k_hw_disable(ah);
1121 ath9k_hw_configpcipowersave(ah, 1, 1);
1122 ath9k_hw_setpower(ah, ATH9K_PM_FULL_SLEEP);
1124 cancel_delayed_work_sync(&priv->ath9k_ani_work);
1125 cancel_delayed_work_sync(&priv->ath9k_aggr_work);
1126 cancel_delayed_work_sync(&priv->ath9k_led_blink_work);
1127 ath9k_led_stop_brightness(priv);
1128 skb_queue_purge(&priv->tx_queue);
1130 /* Remove monitor interface here */
1131 if (ah->opmode == NL80211_IFTYPE_MONITOR) {
1132 if (ath9k_htc_remove_monitor_interface(priv))
1133 ath_print(common, ATH_DBG_FATAL,
1134 "Unable to remove monitor interface\n");
1136 ath_print(common, ATH_DBG_CONFIG,
1137 "Monitor interface removed\n");
1140 priv->op_flags |= OP_INVALID;
1141 mutex_unlock(&priv->mutex);
1143 ath_print(common, ATH_DBG_CONFIG, "Driver halt\n");
1146 static int ath9k_htc_add_interface(struct ieee80211_hw *hw,
1147 struct ieee80211_vif *vif)
1149 struct ath9k_htc_priv *priv = hw->priv;
1150 struct ath9k_htc_vif *avp = (void *)vif->drv_priv;
1151 struct ath_common *common = ath9k_hw_common(priv->ah);
1152 struct ath9k_htc_target_vif hvif;
1156 mutex_lock(&priv->mutex);
1158 /* Only one interface for now */
1159 if (priv->nvifs > 0) {
1164 memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif));
1165 memcpy(&hvif.myaddr, vif->addr, ETH_ALEN);
1167 switch (vif->type) {
1168 case NL80211_IFTYPE_STATION:
1169 hvif.opmode = cpu_to_be32(HTC_M_STA);
1171 case NL80211_IFTYPE_ADHOC:
1172 hvif.opmode = cpu_to_be32(HTC_M_IBSS);
1175 ath_print(common, ATH_DBG_FATAL,
1176 "Interface type %d not yet supported\n", vif->type);
1181 ath_print(common, ATH_DBG_CONFIG,
1182 "Attach a VIF of type: %d\n", vif->type);
1184 priv->ah->opmode = vif->type;
1186 /* Index starts from zero on the target */
1187 avp->index = hvif.index = priv->nvifs;
1188 hvif.rtsthreshold = cpu_to_be16(2304);
1189 WMI_CMD_BUF(WMI_VAP_CREATE_CMDID, &hvif);
1196 * We need a node in target to tx mgmt frames
1197 * before association.
1199 ret = ath9k_htc_add_station(priv, vif, NULL);
1203 ret = ath9k_htc_update_cap_target(priv);
1205 ath_print(common, ATH_DBG_CONFIG, "Failed to update"
1206 " capability in target \n");
1210 mutex_unlock(&priv->mutex);
1214 static void ath9k_htc_remove_interface(struct ieee80211_hw *hw,
1215 struct ieee80211_vif *vif)
1217 struct ath9k_htc_priv *priv = hw->priv;
1218 struct ath_common *common = ath9k_hw_common(priv->ah);
1219 struct ath9k_htc_vif *avp = (void *)vif->drv_priv;
1220 struct ath9k_htc_target_vif hvif;
1224 ath_print(common, ATH_DBG_CONFIG, "Detach Interface\n");
1226 mutex_lock(&priv->mutex);
1228 memset(&hvif, 0, sizeof(struct ath9k_htc_target_vif));
1229 memcpy(&hvif.myaddr, vif->addr, ETH_ALEN);
1230 hvif.index = avp->index;
1231 WMI_CMD_BUF(WMI_VAP_REMOVE_CMDID, &hvif);
1234 ath9k_htc_remove_station(priv, vif, NULL);
1236 if (vif->type == NL80211_IFTYPE_ADHOC) {
1237 spin_lock_bh(&priv->beacon_lock);
1239 dev_kfree_skb_any(priv->beacon);
1240 priv->beacon = NULL;
1241 spin_unlock_bh(&priv->beacon_lock);
1246 mutex_unlock(&priv->mutex);
1249 static int ath9k_htc_config(struct ieee80211_hw *hw, u32 changed)
1251 struct ath9k_htc_priv *priv = hw->priv;
1252 struct ath_common *common = ath9k_hw_common(priv->ah);
1253 struct ieee80211_conf *conf = &hw->conf;
1255 mutex_lock(&priv->mutex);
1257 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
1258 struct ieee80211_channel *curchan = hw->conf.channel;
1259 int pos = curchan->hw_value;
1260 bool is_cw40 = false;
1262 ath_print(common, ATH_DBG_CONFIG, "Set channel: %d MHz\n",
1263 curchan->center_freq);
1265 if (check_rc_update(hw, &is_cw40))
1266 ath9k_htc_rc_update(priv, is_cw40);
1268 ath9k_cmn_update_ichannel(hw, &priv->ah->channels[pos]);
1270 if (ath9k_htc_set_channel(priv, hw, &priv->ah->channels[pos]) < 0) {
1271 ath_print(common, ATH_DBG_FATAL,
1272 "Unable to set channel\n");
1273 mutex_unlock(&priv->mutex);
1279 if (changed & IEEE80211_CONF_CHANGE_MONITOR) {
1280 if (conf->flags & IEEE80211_CONF_MONITOR) {
1281 if (ath9k_htc_add_monitor_interface(priv))
1282 ath_print(common, ATH_DBG_FATAL,
1283 "Failed to set monitor mode\n");
1285 ath_print(common, ATH_DBG_CONFIG,
1286 "HW opmode set to Monitor mode\n");
1290 mutex_unlock(&priv->mutex);
1295 #define SUPPORTED_FILTERS \
1296 (FIF_PROMISC_IN_BSS | \
1301 FIF_BCN_PRBRESP_PROMISC | \
1304 static void ath9k_htc_configure_filter(struct ieee80211_hw *hw,
1305 unsigned int changed_flags,
1306 unsigned int *total_flags,
1309 struct ath9k_htc_priv *priv = hw->priv;
1312 mutex_lock(&priv->mutex);
1314 changed_flags &= SUPPORTED_FILTERS;
1315 *total_flags &= SUPPORTED_FILTERS;
1317 priv->rxfilter = *total_flags;
1318 rfilt = ath9k_htc_calcrxfilter(priv);
1319 ath9k_hw_setrxfilter(priv->ah, rfilt);
1321 ath_print(ath9k_hw_common(priv->ah), ATH_DBG_CONFIG,
1322 "Set HW RX filter: 0x%x\n", rfilt);
1324 mutex_unlock(&priv->mutex);
1327 static void ath9k_htc_sta_notify(struct ieee80211_hw *hw,
1328 struct ieee80211_vif *vif,
1329 enum sta_notify_cmd cmd,
1330 struct ieee80211_sta *sta)
1332 struct ath9k_htc_priv *priv = hw->priv;
1336 case STA_NOTIFY_ADD:
1337 ret = ath9k_htc_add_station(priv, vif, sta);
1339 ath9k_htc_init_rate(priv, vif, sta);
1341 case STA_NOTIFY_REMOVE:
1342 ath9k_htc_remove_station(priv, vif, sta);
1349 static int ath9k_htc_conf_tx(struct ieee80211_hw *hw, u16 queue,
1350 const struct ieee80211_tx_queue_params *params)
1352 struct ath9k_htc_priv *priv = hw->priv;
1353 struct ath_common *common = ath9k_hw_common(priv->ah);
1354 struct ath9k_tx_queue_info qi;
1357 if (queue >= WME_NUM_AC)
1360 mutex_lock(&priv->mutex);
1362 memset(&qi, 0, sizeof(struct ath9k_tx_queue_info));
1364 qi.tqi_aifs = params->aifs;
1365 qi.tqi_cwmin = params->cw_min;
1366 qi.tqi_cwmax = params->cw_max;
1367 qi.tqi_burstTime = params->txop;
1369 qnum = get_hw_qnum(queue, priv->hwq_map);
1371 ath_print(common, ATH_DBG_CONFIG,
1372 "Configure tx [queue/hwq] [%d/%d], "
1373 "aifs: %d, cw_min: %d, cw_max: %d, txop: %d\n",
1374 queue, qnum, params->aifs, params->cw_min,
1375 params->cw_max, params->txop);
1377 ret = ath_htc_txq_update(priv, qnum, &qi);
1379 ath_print(common, ATH_DBG_FATAL, "TXQ Update failed\n");
1381 mutex_unlock(&priv->mutex);
1386 static int ath9k_htc_set_key(struct ieee80211_hw *hw,
1387 enum set_key_cmd cmd,
1388 struct ieee80211_vif *vif,
1389 struct ieee80211_sta *sta,
1390 struct ieee80211_key_conf *key)
1392 struct ath9k_htc_priv *priv = hw->priv;
1393 struct ath_common *common = ath9k_hw_common(priv->ah);
1396 if (htc_modparam_nohwcrypt)
1399 mutex_lock(&priv->mutex);
1400 ath_print(common, ATH_DBG_CONFIG, "Set HW Key\n");
1404 ret = ath9k_cmn_key_config(common, vif, sta, key);
1406 key->hw_key_idx = ret;
1407 /* push IV and Michael MIC generation to stack */
1408 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
1409 if (key->alg == ALG_TKIP)
1410 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
1411 if (priv->ah->sw_mgmt_crypto && key->alg == ALG_CCMP)
1412 key->flags |= IEEE80211_KEY_FLAG_SW_MGMT;
1417 ath9k_cmn_key_delete(common, key);
1423 mutex_unlock(&priv->mutex);
1428 static void ath9k_htc_bss_info_changed(struct ieee80211_hw *hw,
1429 struct ieee80211_vif *vif,
1430 struct ieee80211_bss_conf *bss_conf,
1433 struct ath9k_htc_priv *priv = hw->priv;
1434 struct ath_hw *ah = priv->ah;
1435 struct ath_common *common = ath9k_hw_common(ah);
1437 mutex_lock(&priv->mutex);
1439 if (changed & BSS_CHANGED_ASSOC) {
1440 common->curaid = bss_conf->assoc ?
1442 ath_print(common, ATH_DBG_CONFIG, "BSS Changed ASSOC %d\n",
1445 if (bss_conf->assoc) {
1446 priv->op_flags |= OP_ASSOCIATED;
1447 ath_start_ani(priv);
1449 priv->op_flags &= ~OP_ASSOCIATED;
1450 cancel_delayed_work_sync(&priv->ath9k_ani_work);
1454 if (changed & BSS_CHANGED_BSSID) {
1456 memcpy(common->curbssid, bss_conf->bssid, ETH_ALEN);
1457 ath9k_hw_write_associd(ah);
1459 ath_print(common, ATH_DBG_CONFIG,
1460 "BSSID: %pM aid: 0x%x\n",
1461 common->curbssid, common->curaid);
1464 if ((changed & BSS_CHANGED_BEACON_INT) ||
1465 (changed & BSS_CHANGED_BEACON) ||
1466 ((changed & BSS_CHANGED_BEACON_ENABLED) &&
1467 bss_conf->enable_beacon)) {
1468 priv->op_flags |= OP_ENABLE_BEACON;
1469 ath9k_htc_beacon_config(priv, vif, bss_conf);
1472 if (changed & BSS_CHANGED_BEACON)
1473 ath9k_htc_beacon_update(priv, vif);
1475 if ((changed & BSS_CHANGED_BEACON_ENABLED) &&
1476 !bss_conf->enable_beacon) {
1477 priv->op_flags &= ~OP_ENABLE_BEACON;
1478 ath9k_htc_beacon_config(priv, vif, bss_conf);
1481 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
1482 ath_print(common, ATH_DBG_CONFIG, "BSS Changed PREAMBLE %d\n",
1483 bss_conf->use_short_preamble);
1484 if (bss_conf->use_short_preamble)
1485 priv->op_flags |= OP_PREAMBLE_SHORT;
1487 priv->op_flags &= ~OP_PREAMBLE_SHORT;
1490 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
1491 ath_print(common, ATH_DBG_CONFIG, "BSS Changed CTS PROT %d\n",
1492 bss_conf->use_cts_prot);
1493 if (bss_conf->use_cts_prot &&
1494 hw->conf.channel->band != IEEE80211_BAND_5GHZ)
1495 priv->op_flags |= OP_PROTECT_ENABLE;
1497 priv->op_flags &= ~OP_PROTECT_ENABLE;
1500 if (changed & BSS_CHANGED_ERP_SLOT) {
1501 if (bss_conf->use_short_slot)
1506 ath9k_hw_init_global_settings(ah);
1509 mutex_unlock(&priv->mutex);
1512 static u64 ath9k_htc_get_tsf(struct ieee80211_hw *hw)
1514 struct ath9k_htc_priv *priv = hw->priv;
1517 mutex_lock(&priv->mutex);
1518 tsf = ath9k_hw_gettsf64(priv->ah);
1519 mutex_unlock(&priv->mutex);
1524 static void ath9k_htc_set_tsf(struct ieee80211_hw *hw, u64 tsf)
1526 struct ath9k_htc_priv *priv = hw->priv;
1528 mutex_lock(&priv->mutex);
1529 ath9k_hw_settsf64(priv->ah, tsf);
1530 mutex_unlock(&priv->mutex);
1533 static void ath9k_htc_reset_tsf(struct ieee80211_hw *hw)
1535 struct ath9k_htc_priv *priv = hw->priv;
1537 mutex_lock(&priv->mutex);
1538 ath9k_hw_reset_tsf(priv->ah);
1539 mutex_unlock(&priv->mutex);
1542 static int ath9k_htc_ampdu_action(struct ieee80211_hw *hw,
1543 struct ieee80211_vif *vif,
1544 enum ieee80211_ampdu_mlme_action action,
1545 struct ieee80211_sta *sta,
1548 struct ath9k_htc_priv *priv = hw->priv;
1549 struct ath9k_htc_aggr_work *work = &priv->aggr_work;
1550 struct ath9k_htc_sta *ista;
1553 case IEEE80211_AMPDU_RX_START:
1555 case IEEE80211_AMPDU_RX_STOP:
1557 case IEEE80211_AMPDU_TX_START:
1558 case IEEE80211_AMPDU_TX_STOP:
1559 if (!(priv->op_flags & OP_TXAGGR))
1561 memcpy(work->sta_addr, sta->addr, ETH_ALEN);
1564 work->action = action;
1566 ieee80211_queue_delayed_work(hw, &priv->ath9k_aggr_work, 0);
1568 case IEEE80211_AMPDU_TX_OPERATIONAL:
1569 ista = (struct ath9k_htc_sta *) sta->drv_priv;
1570 ista->tid_state[tid] = AGGR_OPERATIONAL;
1573 ath_print(ath9k_hw_common(priv->ah), ATH_DBG_FATAL,
1574 "Unknown AMPDU action\n");
1580 static void ath9k_htc_sw_scan_start(struct ieee80211_hw *hw)
1582 struct ath9k_htc_priv *priv = hw->priv;
1584 mutex_lock(&priv->mutex);
1585 spin_lock_bh(&priv->beacon_lock);
1586 priv->op_flags |= OP_SCANNING;
1587 spin_unlock_bh(&priv->beacon_lock);
1588 cancel_delayed_work_sync(&priv->ath9k_ani_work);
1589 mutex_unlock(&priv->mutex);
1592 static void ath9k_htc_sw_scan_complete(struct ieee80211_hw *hw)
1594 struct ath9k_htc_priv *priv = hw->priv;
1596 mutex_lock(&priv->mutex);
1597 spin_lock_bh(&priv->beacon_lock);
1598 priv->op_flags &= ~OP_SCANNING;
1599 spin_unlock_bh(&priv->beacon_lock);
1600 priv->op_flags |= OP_FULL_RESET;
1601 ath_start_ani(priv);
1602 mutex_unlock(&priv->mutex);
1605 static int ath9k_htc_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
1610 static void ath9k_htc_set_coverage_class(struct ieee80211_hw *hw,
1613 struct ath9k_htc_priv *priv = hw->priv;
1615 mutex_lock(&priv->mutex);
1616 priv->ah->coverage_class = coverage_class;
1617 ath9k_hw_init_global_settings(priv->ah);
1618 mutex_unlock(&priv->mutex);
1621 struct ieee80211_ops ath9k_htc_ops = {
1623 .start = ath9k_htc_start,
1624 .stop = ath9k_htc_stop,
1625 .add_interface = ath9k_htc_add_interface,
1626 .remove_interface = ath9k_htc_remove_interface,
1627 .config = ath9k_htc_config,
1628 .configure_filter = ath9k_htc_configure_filter,
1629 .sta_notify = ath9k_htc_sta_notify,
1630 .conf_tx = ath9k_htc_conf_tx,
1631 .bss_info_changed = ath9k_htc_bss_info_changed,
1632 .set_key = ath9k_htc_set_key,
1633 .get_tsf = ath9k_htc_get_tsf,
1634 .set_tsf = ath9k_htc_set_tsf,
1635 .reset_tsf = ath9k_htc_reset_tsf,
1636 .ampdu_action = ath9k_htc_ampdu_action,
1637 .sw_scan_start = ath9k_htc_sw_scan_start,
1638 .sw_scan_complete = ath9k_htc_sw_scan_complete,
1639 .set_rts_threshold = ath9k_htc_set_rts_threshold,
1640 .rfkill_poll = ath9k_htc_rfkill_poll_state,
1641 .set_coverage_class = ath9k_htc_set_coverage_class,