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 void ath_update_txpow(struct ath9k_htc_priv
*priv
)
29 struct ath_hw
*ah
= priv
->ah
;
31 if (priv
->curtxpow
!= priv
->txpowlimit
) {
32 ath9k_hw_set_txpowerlimit(ah
, priv
->txpowlimit
, false);
33 /* read back in case value is clamped */
34 priv
->curtxpow
= ath9k_hw_regulatory(ah
)->power_limit
;
38 /* HACK Alert: Use 11NG for 2.4, use 11NA for 5 */
39 static enum htc_phymode
ath9k_htc_get_curmode(struct ath9k_htc_priv
*priv
,
40 struct ath9k_channel
*ichan
)
42 enum htc_phymode mode
;
46 switch (ichan
->chanmode
) {
49 case CHANNEL_G_HT40PLUS
:
50 case CHANNEL_G_HT40MINUS
:
55 case CHANNEL_A_HT40PLUS
:
56 case CHANNEL_A_HT40MINUS
:
66 bool ath9k_htc_setpower(struct ath9k_htc_priv
*priv
,
67 enum ath9k_power_mode mode
)
71 mutex_lock(&priv
->htc_pm_lock
);
72 ret
= ath9k_hw_setpower(priv
->ah
, mode
);
73 mutex_unlock(&priv
->htc_pm_lock
);
78 void ath9k_htc_ps_wakeup(struct ath9k_htc_priv
*priv
)
80 mutex_lock(&priv
->htc_pm_lock
);
81 if (++priv
->ps_usecount
!= 1)
83 ath9k_hw_setpower(priv
->ah
, ATH9K_PM_AWAKE
);
86 mutex_unlock(&priv
->htc_pm_lock
);
89 void ath9k_htc_ps_restore(struct ath9k_htc_priv
*priv
)
91 mutex_lock(&priv
->htc_pm_lock
);
92 if (--priv
->ps_usecount
!= 0)
96 ath9k_hw_setpower(priv
->ah
, ATH9K_PM_FULL_SLEEP
);
97 else if (priv
->ps_enabled
)
98 ath9k_hw_setpower(priv
->ah
, ATH9K_PM_NETWORK_SLEEP
);
101 mutex_unlock(&priv
->htc_pm_lock
);
104 void ath9k_ps_work(struct work_struct
*work
)
106 struct ath9k_htc_priv
*priv
=
107 container_of(work
, struct ath9k_htc_priv
,
109 ath9k_htc_setpower(priv
, ATH9K_PM_AWAKE
);
111 /* The chip wakes up after receiving the first beacon
112 while network sleep is enabled. For the driver to
113 be in sync with the hw, set the chip to awake and
114 only then set it to sleep.
116 ath9k_htc_setpower(priv
, ATH9K_PM_NETWORK_SLEEP
);
119 void ath9k_htc_reset(struct ath9k_htc_priv
*priv
)
121 struct ath_hw
*ah
= priv
->ah
;
122 struct ath_common
*common
= ath9k_hw_common(ah
);
123 struct ieee80211_channel
*channel
= priv
->hw
->conf
.channel
;
124 struct ath9k_hw_cal_data
*caldata
;
125 enum htc_phymode mode
;
130 mutex_lock(&priv
->mutex
);
131 ath9k_htc_ps_wakeup(priv
);
133 if (priv
->op_flags
& OP_ASSOCIATED
)
134 cancel_delayed_work_sync(&priv
->ath9k_ani_work
);
136 ieee80211_stop_queues(priv
->hw
);
138 WMI_CMD(WMI_DISABLE_INTR_CMDID
);
139 WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID
);
140 WMI_CMD(WMI_STOP_RECV_CMDID
);
142 caldata
= &priv
->caldata
[channel
->hw_value
];
143 ret
= ath9k_hw_reset(ah
, ah
->curchan
, caldata
, false);
146 "Unable to reset device (%u Mhz) reset status %d\n",
147 channel
->center_freq
, ret
);
150 ath_update_txpow(priv
);
152 WMI_CMD(WMI_START_RECV_CMDID
);
153 ath9k_host_rx_init(priv
);
155 mode
= ath9k_htc_get_curmode(priv
, ah
->curchan
);
156 htc_mode
= cpu_to_be16(mode
);
157 WMI_CMD_BUF(WMI_SET_MODE_CMDID
, &htc_mode
);
159 WMI_CMD(WMI_ENABLE_INTR_CMDID
);
160 htc_start(priv
->htc
);
162 if (priv
->op_flags
& OP_ASSOCIATED
) {
163 ath9k_htc_beacon_config(priv
, priv
->vif
);
167 ieee80211_wake_queues(priv
->hw
);
169 ath9k_htc_ps_restore(priv
);
170 mutex_unlock(&priv
->mutex
);
173 static int ath9k_htc_set_channel(struct ath9k_htc_priv
*priv
,
174 struct ieee80211_hw
*hw
,
175 struct ath9k_channel
*hchan
)
177 struct ath_hw
*ah
= priv
->ah
;
178 struct ath_common
*common
= ath9k_hw_common(ah
);
179 struct ieee80211_conf
*conf
= &common
->hw
->conf
;
181 struct ieee80211_channel
*channel
= hw
->conf
.channel
;
182 struct ath9k_hw_cal_data
*caldata
;
183 enum htc_phymode mode
;
188 if (priv
->op_flags
& OP_INVALID
)
191 fastcc
= !!(hw
->conf
.flags
& IEEE80211_CONF_OFFCHANNEL
);
193 ath9k_htc_ps_wakeup(priv
);
195 WMI_CMD(WMI_DISABLE_INTR_CMDID
);
196 WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID
);
197 WMI_CMD(WMI_STOP_RECV_CMDID
);
199 ath_dbg(common
, ATH_DBG_CONFIG
,
200 "(%u MHz) -> (%u MHz), HT: %d, HT40: %d fastcc: %d\n",
201 priv
->ah
->curchan
->channel
,
202 channel
->center_freq
, conf_is_ht(conf
), conf_is_ht40(conf
),
205 caldata
= &priv
->caldata
[channel
->hw_value
];
206 ret
= ath9k_hw_reset(ah
, hchan
, caldata
, fastcc
);
209 "Unable to reset channel (%u Mhz) reset status %d\n",
210 channel
->center_freq
, ret
);
214 ath_update_txpow(priv
);
216 WMI_CMD(WMI_START_RECV_CMDID
);
220 ath9k_host_rx_init(priv
);
222 mode
= ath9k_htc_get_curmode(priv
, hchan
);
223 htc_mode
= cpu_to_be16(mode
);
224 WMI_CMD_BUF(WMI_SET_MODE_CMDID
, &htc_mode
);
228 WMI_CMD(WMI_ENABLE_INTR_CMDID
);
232 htc_start(priv
->htc
);
234 ath9k_htc_ps_restore(priv
);
238 static void __ath9k_htc_remove_monitor_interface(struct ath9k_htc_priv
*priv
)
240 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
241 struct ath9k_htc_target_vif hvif
;
245 memset(&hvif
, 0, sizeof(struct ath9k_htc_target_vif
));
246 memcpy(&hvif
.myaddr
, common
->macaddr
, ETH_ALEN
);
247 hvif
.index
= 0; /* Should do for now */
248 WMI_CMD_BUF(WMI_VAP_REMOVE_CMDID
, &hvif
);
252 static int ath9k_htc_add_monitor_interface(struct ath9k_htc_priv
*priv
)
254 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
255 struct ath9k_htc_target_vif hvif
;
256 struct ath9k_htc_target_sta tsta
;
263 if (priv
->nstations
>= ATH9K_HTC_MAX_STA
)
270 memset(&hvif
, 0, sizeof(struct ath9k_htc_target_vif
));
271 memcpy(&hvif
.myaddr
, common
->macaddr
, ETH_ALEN
);
273 hvif
.opmode
= cpu_to_be32(HTC_M_MONITOR
);
274 priv
->ah
->opmode
= NL80211_IFTYPE_MONITOR
;
275 hvif
.index
= priv
->nvifs
;
277 WMI_CMD_BUF(WMI_VAP_CREATE_CMDID
, &hvif
);
284 * Associate a station with the interface for packet injection.
287 memset(&tsta
, 0, sizeof(struct ath9k_htc_target_sta
));
289 memcpy(&tsta
.macaddr
, common
->macaddr
, ETH_ALEN
);
292 tsta
.sta_index
= priv
->nstations
;
293 tsta
.vif_index
= hvif
.index
;
294 tsta
.maxampdu
= 0xffff;
296 WMI_CMD_BUF(WMI_NODE_CREATE_CMDID
, &tsta
);
298 ath_err(common
, "Unable to add station entry for monitor mode\n");
308 * Remove the interface from the target.
310 __ath9k_htc_remove_monitor_interface(priv
);
314 static int ath9k_htc_remove_monitor_interface(struct ath9k_htc_priv
*priv
)
316 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
320 __ath9k_htc_remove_monitor_interface(priv
);
322 sta_idx
= 0; /* Only single interface, for now */
324 WMI_CMD_BUF(WMI_NODE_REMOVE_CMDID
, &sta_idx
);
326 ath_err(common
, "Unable to remove station entry for monitor mode\n");
335 static int ath9k_htc_add_station(struct ath9k_htc_priv
*priv
,
336 struct ieee80211_vif
*vif
,
337 struct ieee80211_sta
*sta
)
339 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
340 struct ath9k_htc_target_sta tsta
;
341 struct ath9k_htc_vif
*avp
= (struct ath9k_htc_vif
*) vif
->drv_priv
;
342 struct ath9k_htc_sta
*ista
;
346 if (priv
->nstations
>= ATH9K_HTC_MAX_STA
)
349 memset(&tsta
, 0, sizeof(struct ath9k_htc_target_sta
));
352 ista
= (struct ath9k_htc_sta
*) sta
->drv_priv
;
353 memcpy(&tsta
.macaddr
, sta
->addr
, ETH_ALEN
);
354 memcpy(&tsta
.bssid
, common
->curbssid
, ETH_ALEN
);
355 tsta
.associd
= common
->curaid
;
358 ista
->index
= priv
->nstations
;
360 memcpy(&tsta
.macaddr
, vif
->addr
, ETH_ALEN
);
364 tsta
.sta_index
= priv
->nstations
;
365 tsta
.vif_index
= avp
->index
;
366 tsta
.maxampdu
= 0xffff;
367 if (sta
&& sta
->ht_cap
.ht_supported
)
368 tsta
.flags
= cpu_to_be16(ATH_HTC_STA_HT
);
370 WMI_CMD_BUF(WMI_NODE_CREATE_CMDID
, &tsta
);
374 "Unable to add station entry for: %pM\n",
380 ath_dbg(common
, ATH_DBG_CONFIG
,
381 "Added a station entry for: %pM (idx: %d)\n",
382 sta
->addr
, tsta
.sta_index
);
388 static int ath9k_htc_remove_station(struct ath9k_htc_priv
*priv
,
389 struct ieee80211_vif
*vif
,
390 struct ieee80211_sta
*sta
)
392 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
393 struct ath9k_htc_sta
*ista
;
398 ista
= (struct ath9k_htc_sta
*) sta
->drv_priv
;
399 sta_idx
= ista
->index
;
404 WMI_CMD_BUF(WMI_NODE_REMOVE_CMDID
, &sta_idx
);
408 "Unable to remove station entry for: %pM\n",
414 ath_dbg(common
, ATH_DBG_CONFIG
,
415 "Removed a station entry for: %pM (idx: %d)\n",
422 static int ath9k_htc_update_cap_target(struct ath9k_htc_priv
*priv
)
424 struct ath9k_htc_cap_target tcap
;
428 memset(&tcap
, 0, sizeof(struct ath9k_htc_cap_target
));
430 /* FIXME: Values are hardcoded */
431 tcap
.flags
= 0x240c40;
432 tcap
.flags_ext
= 0x80601000;
433 tcap
.ampdu_limit
= 0xffff0000;
434 tcap
.ampdu_subframes
= 20;
435 tcap
.tx_chainmask_legacy
= priv
->ah
->caps
.tx_chainmask
;
437 tcap
.tx_chainmask
= priv
->ah
->caps
.tx_chainmask
;
439 WMI_CMD_BUF(WMI_TARGET_IC_UPDATE_CMDID
, &tcap
);
444 static void ath9k_htc_setup_rate(struct ath9k_htc_priv
*priv
,
445 struct ieee80211_sta
*sta
,
446 struct ath9k_htc_target_rate
*trate
)
448 struct ath9k_htc_sta
*ista
= (struct ath9k_htc_sta
*) sta
->drv_priv
;
449 struct ieee80211_supported_band
*sband
;
453 sband
= priv
->hw
->wiphy
->bands
[priv
->hw
->conf
.channel
->band
];
455 for (i
= 0, j
= 0; i
< sband
->n_bitrates
; i
++) {
456 if (sta
->supp_rates
[sband
->band
] & BIT(i
)) {
457 trate
->rates
.legacy_rates
.rs_rates
[j
]
458 = (sband
->bitrates
[i
].bitrate
* 2) / 10;
462 trate
->rates
.legacy_rates
.rs_nrates
= j
;
464 if (sta
->ht_cap
.ht_supported
) {
465 for (i
= 0, j
= 0; i
< 77; i
++) {
466 if (sta
->ht_cap
.mcs
.rx_mask
[i
/8] & (1<<(i
%8)))
467 trate
->rates
.ht_rates
.rs_rates
[j
++] = i
;
468 if (j
== ATH_HTC_RATE_MAX
)
471 trate
->rates
.ht_rates
.rs_nrates
= j
;
473 caps
= WLAN_RC_HT_FLAG
;
474 if (sta
->ht_cap
.mcs
.rx_mask
[1])
475 caps
|= WLAN_RC_DS_FLAG
;
476 if ((sta
->ht_cap
.cap
& IEEE80211_HT_CAP_SUP_WIDTH_20_40
) &&
477 (conf_is_ht40(&priv
->hw
->conf
)))
478 caps
|= WLAN_RC_40_FLAG
;
479 if (conf_is_ht40(&priv
->hw
->conf
) &&
480 (sta
->ht_cap
.cap
& IEEE80211_HT_CAP_SGI_40
))
481 caps
|= WLAN_RC_SGI_FLAG
;
482 else if (conf_is_ht20(&priv
->hw
->conf
) &&
483 (sta
->ht_cap
.cap
& IEEE80211_HT_CAP_SGI_20
))
484 caps
|= WLAN_RC_SGI_FLAG
;
487 trate
->sta_index
= ista
->index
;
489 trate
->capflags
= cpu_to_be32(caps
);
492 static int ath9k_htc_send_rate_cmd(struct ath9k_htc_priv
*priv
,
493 struct ath9k_htc_target_rate
*trate
)
495 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
499 WMI_CMD_BUF(WMI_RC_RATE_UPDATE_CMDID
, trate
);
502 "Unable to initialize Rate information on target\n");
508 static void ath9k_htc_init_rate(struct ath9k_htc_priv
*priv
,
509 struct ieee80211_sta
*sta
)
511 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
512 struct ath9k_htc_target_rate trate
;
515 memset(&trate
, 0, sizeof(struct ath9k_htc_target_rate
));
516 ath9k_htc_setup_rate(priv
, sta
, &trate
);
517 ret
= ath9k_htc_send_rate_cmd(priv
, &trate
);
519 ath_dbg(common
, ATH_DBG_CONFIG
,
520 "Updated target sta: %pM, rate caps: 0x%X\n",
521 sta
->addr
, be32_to_cpu(trate
.capflags
));
524 static void ath9k_htc_update_rate(struct ath9k_htc_priv
*priv
,
525 struct ieee80211_vif
*vif
,
526 struct ieee80211_bss_conf
*bss_conf
)
528 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
529 struct ath9k_htc_target_rate trate
;
530 struct ieee80211_sta
*sta
;
533 memset(&trate
, 0, sizeof(struct ath9k_htc_target_rate
));
536 sta
= ieee80211_find_sta(vif
, bss_conf
->bssid
);
541 ath9k_htc_setup_rate(priv
, sta
, &trate
);
544 ret
= ath9k_htc_send_rate_cmd(priv
, &trate
);
546 ath_dbg(common
, ATH_DBG_CONFIG
,
547 "Updated target sta: %pM, rate caps: 0x%X\n",
548 bss_conf
->bssid
, be32_to_cpu(trate
.capflags
));
551 static int ath9k_htc_tx_aggr_oper(struct ath9k_htc_priv
*priv
,
552 struct ieee80211_vif
*vif
,
553 struct ieee80211_sta
*sta
,
554 enum ieee80211_ampdu_mlme_action action
,
557 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
558 struct ath9k_htc_target_aggr aggr
;
559 struct ath9k_htc_sta
*ista
;
563 if (tid
>= ATH9K_HTC_MAX_TID
)
566 memset(&aggr
, 0, sizeof(struct ath9k_htc_target_aggr
));
567 ista
= (struct ath9k_htc_sta
*) sta
->drv_priv
;
569 aggr
.sta_index
= ista
->index
;
570 aggr
.tidno
= tid
& 0xf;
571 aggr
.aggr_enable
= (action
== IEEE80211_AMPDU_TX_START
) ? true : false;
573 WMI_CMD_BUF(WMI_TX_AGGR_ENABLE_CMDID
, &aggr
);
575 ath_dbg(common
, ATH_DBG_CONFIG
,
576 "Unable to %s TX aggregation for (%pM, %d)\n",
577 (aggr
.aggr_enable
) ? "start" : "stop", sta
->addr
, tid
);
579 ath_dbg(common
, ATH_DBG_CONFIG
,
580 "%s TX aggregation for (%pM, %d)\n",
581 (aggr
.aggr_enable
) ? "Starting" : "Stopping",
584 spin_lock_bh(&priv
->tx_lock
);
585 ista
->tid_state
[tid
] = (aggr
.aggr_enable
&& !ret
) ? AGGR_START
: AGGR_STOP
;
586 spin_unlock_bh(&priv
->tx_lock
);
595 #ifdef CONFIG_ATH9K_HTC_DEBUGFS
597 static int ath9k_debugfs_open(struct inode
*inode
, struct file
*file
)
599 file
->private_data
= inode
->i_private
;
603 static ssize_t
read_file_tgt_stats(struct file
*file
, char __user
*user_buf
,
604 size_t count
, loff_t
*ppos
)
606 struct ath9k_htc_priv
*priv
= file
->private_data
;
607 struct ath9k_htc_target_stats cmd_rsp
;
609 unsigned int len
= 0;
612 memset(&cmd_rsp
, 0, sizeof(cmd_rsp
));
614 WMI_CMD(WMI_TGT_STATS_CMDID
);
619 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
620 "%19s : %10u\n", "TX Short Retries",
621 be32_to_cpu(cmd_rsp
.tx_shortretry
));
622 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
623 "%19s : %10u\n", "TX Long Retries",
624 be32_to_cpu(cmd_rsp
.tx_longretry
));
625 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
626 "%19s : %10u\n", "TX Xretries",
627 be32_to_cpu(cmd_rsp
.tx_xretries
));
628 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
629 "%19s : %10u\n", "TX Unaggr. Xretries",
630 be32_to_cpu(cmd_rsp
.ht_txunaggr_xretry
));
631 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
632 "%19s : %10u\n", "TX Xretries (HT)",
633 be32_to_cpu(cmd_rsp
.ht_tx_xretries
));
634 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
635 "%19s : %10u\n", "TX Rate", priv
->debug
.txrate
);
637 if (len
> sizeof(buf
))
640 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, len
);
643 static const struct file_operations fops_tgt_stats
= {
644 .read
= read_file_tgt_stats
,
645 .open
= ath9k_debugfs_open
,
646 .owner
= THIS_MODULE
,
647 .llseek
= default_llseek
,
650 static ssize_t
read_file_xmit(struct file
*file
, char __user
*user_buf
,
651 size_t count
, loff_t
*ppos
)
653 struct ath9k_htc_priv
*priv
= file
->private_data
;
655 unsigned int len
= 0;
657 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
658 "%20s : %10u\n", "Buffers queued",
659 priv
->debug
.tx_stats
.buf_queued
);
660 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
661 "%20s : %10u\n", "Buffers completed",
662 priv
->debug
.tx_stats
.buf_completed
);
663 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
664 "%20s : %10u\n", "SKBs queued",
665 priv
->debug
.tx_stats
.skb_queued
);
666 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
667 "%20s : %10u\n", "SKBs completed",
668 priv
->debug
.tx_stats
.skb_completed
);
669 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
670 "%20s : %10u\n", "SKBs dropped",
671 priv
->debug
.tx_stats
.skb_dropped
);
673 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
674 "%20s : %10u\n", "BE queued",
675 priv
->debug
.tx_stats
.queue_stats
[WME_AC_BE
]);
676 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
677 "%20s : %10u\n", "BK queued",
678 priv
->debug
.tx_stats
.queue_stats
[WME_AC_BK
]);
679 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
680 "%20s : %10u\n", "VI queued",
681 priv
->debug
.tx_stats
.queue_stats
[WME_AC_VI
]);
682 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
683 "%20s : %10u\n", "VO queued",
684 priv
->debug
.tx_stats
.queue_stats
[WME_AC_VO
]);
686 if (len
> sizeof(buf
))
689 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, len
);
692 static const struct file_operations fops_xmit
= {
693 .read
= read_file_xmit
,
694 .open
= ath9k_debugfs_open
,
695 .owner
= THIS_MODULE
,
696 .llseek
= default_llseek
,
699 static ssize_t
read_file_recv(struct file
*file
, char __user
*user_buf
,
700 size_t count
, loff_t
*ppos
)
702 struct ath9k_htc_priv
*priv
= file
->private_data
;
704 unsigned int len
= 0;
706 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
707 "%20s : %10u\n", "SKBs allocated",
708 priv
->debug
.rx_stats
.skb_allocated
);
709 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
710 "%20s : %10u\n", "SKBs completed",
711 priv
->debug
.rx_stats
.skb_completed
);
712 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
713 "%20s : %10u\n", "SKBs Dropped",
714 priv
->debug
.rx_stats
.skb_dropped
);
716 if (len
> sizeof(buf
))
719 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, len
);
722 static const struct file_operations fops_recv
= {
723 .read
= read_file_recv
,
724 .open
= ath9k_debugfs_open
,
725 .owner
= THIS_MODULE
,
726 .llseek
= default_llseek
,
729 int ath9k_htc_init_debug(struct ath_hw
*ah
)
731 struct ath_common
*common
= ath9k_hw_common(ah
);
732 struct ath9k_htc_priv
*priv
= (struct ath9k_htc_priv
*) common
->priv
;
734 if (!ath9k_debugfs_root
)
737 priv
->debug
.debugfs_phy
= debugfs_create_dir(wiphy_name(priv
->hw
->wiphy
),
739 if (!priv
->debug
.debugfs_phy
)
742 priv
->debug
.debugfs_tgt_stats
= debugfs_create_file("tgt_stats", S_IRUSR
,
743 priv
->debug
.debugfs_phy
,
744 priv
, &fops_tgt_stats
);
745 if (!priv
->debug
.debugfs_tgt_stats
)
749 priv
->debug
.debugfs_xmit
= debugfs_create_file("xmit", S_IRUSR
,
750 priv
->debug
.debugfs_phy
,
752 if (!priv
->debug
.debugfs_xmit
)
755 priv
->debug
.debugfs_recv
= debugfs_create_file("recv", S_IRUSR
,
756 priv
->debug
.debugfs_phy
,
758 if (!priv
->debug
.debugfs_recv
)
764 ath9k_htc_exit_debug(ah
);
768 void ath9k_htc_exit_debug(struct ath_hw
*ah
)
770 struct ath_common
*common
= ath9k_hw_common(ah
);
771 struct ath9k_htc_priv
*priv
= (struct ath9k_htc_priv
*) common
->priv
;
773 debugfs_remove(priv
->debug
.debugfs_recv
);
774 debugfs_remove(priv
->debug
.debugfs_xmit
);
775 debugfs_remove(priv
->debug
.debugfs_tgt_stats
);
776 debugfs_remove(priv
->debug
.debugfs_phy
);
779 int ath9k_htc_debug_create_root(void)
781 ath9k_debugfs_root
= debugfs_create_dir(KBUILD_MODNAME
, NULL
);
782 if (!ath9k_debugfs_root
)
788 void ath9k_htc_debug_remove_root(void)
790 debugfs_remove(ath9k_debugfs_root
);
791 ath9k_debugfs_root
= NULL
;
794 #endif /* CONFIG_ATH9K_HTC_DEBUGFS */
800 void ath_start_ani(struct ath9k_htc_priv
*priv
)
802 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
803 unsigned long timestamp
= jiffies_to_msecs(jiffies
);
805 common
->ani
.longcal_timer
= timestamp
;
806 common
->ani
.shortcal_timer
= timestamp
;
807 common
->ani
.checkani_timer
= timestamp
;
809 ieee80211_queue_delayed_work(common
->hw
, &priv
->ath9k_ani_work
,
810 msecs_to_jiffies(ATH_ANI_POLLINTERVAL
));
813 void ath9k_ani_work(struct work_struct
*work
)
815 struct ath9k_htc_priv
*priv
=
816 container_of(work
, struct ath9k_htc_priv
,
817 ath9k_ani_work
.work
);
818 struct ath_hw
*ah
= priv
->ah
;
819 struct ath_common
*common
= ath9k_hw_common(ah
);
820 bool longcal
= false;
821 bool shortcal
= false;
822 bool aniflag
= false;
823 unsigned int timestamp
= jiffies_to_msecs(jiffies
);
824 u32 cal_interval
, short_cal_interval
;
826 short_cal_interval
= ATH_STA_SHORT_CALINTERVAL
;
828 /* Only calibrate if awake */
829 if (ah
->power_mode
!= ATH9K_PM_AWAKE
)
832 /* Long calibration runs independently of short calibration. */
833 if ((timestamp
- common
->ani
.longcal_timer
) >= ATH_LONG_CALINTERVAL
) {
835 ath_dbg(common
, ATH_DBG_ANI
, "longcal @%lu\n", jiffies
);
836 common
->ani
.longcal_timer
= timestamp
;
839 /* Short calibration applies only while caldone is false */
840 if (!common
->ani
.caldone
) {
841 if ((timestamp
- common
->ani
.shortcal_timer
) >=
842 short_cal_interval
) {
844 ath_dbg(common
, ATH_DBG_ANI
,
845 "shortcal @%lu\n", jiffies
);
846 common
->ani
.shortcal_timer
= timestamp
;
847 common
->ani
.resetcal_timer
= timestamp
;
850 if ((timestamp
- common
->ani
.resetcal_timer
) >=
851 ATH_RESTART_CALINTERVAL
) {
852 common
->ani
.caldone
= ath9k_hw_reset_calvalid(ah
);
853 if (common
->ani
.caldone
)
854 common
->ani
.resetcal_timer
= timestamp
;
858 /* Verify whether we must check ANI */
859 if ((timestamp
- common
->ani
.checkani_timer
) >= ATH_ANI_POLLINTERVAL
) {
861 common
->ani
.checkani_timer
= timestamp
;
864 /* Skip all processing if there's nothing to do. */
865 if (longcal
|| shortcal
|| aniflag
) {
867 ath9k_htc_ps_wakeup(priv
);
869 /* Call ANI routine if necessary */
871 ath9k_hw_ani_monitor(ah
, ah
->curchan
);
873 /* Perform calibration if necessary */
874 if (longcal
|| shortcal
)
875 common
->ani
.caldone
=
876 ath9k_hw_calibrate(ah
, ah
->curchan
,
877 common
->rx_chainmask
,
880 ath9k_htc_ps_restore(priv
);
885 * Set timer interval based on previous results.
886 * The interval must be the shortest necessary to satisfy ANI,
887 * short calibration and long calibration.
889 cal_interval
= ATH_LONG_CALINTERVAL
;
890 if (priv
->ah
->config
.enable_ani
)
891 cal_interval
= min(cal_interval
, (u32
)ATH_ANI_POLLINTERVAL
);
892 if (!common
->ani
.caldone
)
893 cal_interval
= min(cal_interval
, (u32
)short_cal_interval
);
895 ieee80211_queue_delayed_work(common
->hw
, &priv
->ath9k_ani_work
,
896 msecs_to_jiffies(cal_interval
));
899 /**********************/
900 /* mac80211 Callbacks */
901 /**********************/
903 static int ath9k_htc_tx(struct ieee80211_hw
*hw
, struct sk_buff
*skb
)
905 struct ieee80211_hdr
*hdr
;
906 struct ath9k_htc_priv
*priv
= hw
->priv
;
907 int padpos
, padsize
, ret
;
909 hdr
= (struct ieee80211_hdr
*) skb
->data
;
911 /* Add the padding after the header if this is not already done */
912 padpos
= ath9k_cmn_padpos(hdr
->frame_control
);
913 padsize
= padpos
& 3;
914 if (padsize
&& skb
->len
> padpos
) {
915 if (skb_headroom(skb
) < padsize
)
917 skb_push(skb
, padsize
);
918 memmove(skb
->data
, skb
->data
+ padsize
, padpos
);
921 ret
= ath9k_htc_tx_start(priv
, skb
);
923 if (ret
== -ENOMEM
) {
924 ath_dbg(ath9k_hw_common(priv
->ah
), ATH_DBG_XMIT
,
925 "Stopping TX queues\n");
926 ieee80211_stop_queues(hw
);
927 spin_lock_bh(&priv
->tx_lock
);
928 priv
->tx_queues_stop
= true;
929 spin_unlock_bh(&priv
->tx_lock
);
931 ath_dbg(ath9k_hw_common(priv
->ah
), ATH_DBG_XMIT
,
940 dev_kfree_skb_any(skb
);
944 static int ath9k_htc_start(struct ieee80211_hw
*hw
)
946 struct ath9k_htc_priv
*priv
= hw
->priv
;
947 struct ath_hw
*ah
= priv
->ah
;
948 struct ath_common
*common
= ath9k_hw_common(ah
);
949 struct ieee80211_channel
*curchan
= hw
->conf
.channel
;
950 struct ath9k_channel
*init_channel
;
952 enum htc_phymode mode
;
956 mutex_lock(&priv
->mutex
);
958 ath_dbg(common
, ATH_DBG_CONFIG
,
959 "Starting driver with initial channel: %d MHz\n",
960 curchan
->center_freq
);
962 /* Ensure that HW is awake before flushing RX */
963 ath9k_htc_setpower(priv
, ATH9K_PM_AWAKE
);
964 WMI_CMD(WMI_FLUSH_RECV_CMDID
);
966 /* setup initial channel */
967 init_channel
= ath9k_cmn_get_curchannel(hw
, ah
);
969 ath9k_hw_htc_resetinit(ah
);
970 ret
= ath9k_hw_reset(ah
, init_channel
, ah
->caldata
, false);
973 "Unable to reset hardware; reset status %d (freq %u MHz)\n",
974 ret
, curchan
->center_freq
);
975 mutex_unlock(&priv
->mutex
);
979 ath_update_txpow(priv
);
981 mode
= ath9k_htc_get_curmode(priv
, init_channel
);
982 htc_mode
= cpu_to_be16(mode
);
983 WMI_CMD_BUF(WMI_SET_MODE_CMDID
, &htc_mode
);
984 WMI_CMD(WMI_ATH_INIT_CMDID
);
985 WMI_CMD(WMI_START_RECV_CMDID
);
987 ath9k_host_rx_init(priv
);
989 priv
->op_flags
&= ~OP_INVALID
;
990 htc_start(priv
->htc
);
992 spin_lock_bh(&priv
->tx_lock
);
993 priv
->tx_queues_stop
= false;
994 spin_unlock_bh(&priv
->tx_lock
);
996 ieee80211_wake_queues(hw
);
998 if (ah
->btcoex_hw
.scheme
== ATH_BTCOEX_CFG_3WIRE
) {
999 ath9k_hw_btcoex_set_weight(ah
, AR_BT_COEX_WGHT
,
1000 AR_STOMP_LOW_WLAN_WGHT
);
1001 ath9k_hw_btcoex_enable(ah
);
1002 ath_htc_resume_btcoex_work(priv
);
1004 mutex_unlock(&priv
->mutex
);
1009 static void ath9k_htc_stop(struct ieee80211_hw
*hw
)
1011 struct ath9k_htc_priv
*priv
= hw
->priv
;
1012 struct ath_hw
*ah
= priv
->ah
;
1013 struct ath_common
*common
= ath9k_hw_common(ah
);
1017 /* Cancel all the running timers/work .. */
1018 cancel_work_sync(&priv
->fatal_work
);
1019 cancel_work_sync(&priv
->ps_work
);
1020 cancel_delayed_work_sync(&priv
->ath9k_led_blink_work
);
1021 ath9k_led_stop_brightness(priv
);
1023 mutex_lock(&priv
->mutex
);
1025 if (priv
->op_flags
& OP_INVALID
) {
1026 ath_dbg(common
, ATH_DBG_ANY
, "Device not present\n");
1027 mutex_unlock(&priv
->mutex
);
1031 ath9k_htc_ps_wakeup(priv
);
1032 htc_stop(priv
->htc
);
1033 WMI_CMD(WMI_DISABLE_INTR_CMDID
);
1034 WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID
);
1035 WMI_CMD(WMI_STOP_RECV_CMDID
);
1036 skb_queue_purge(&priv
->tx_queue
);
1038 /* Remove monitor interface here */
1039 if (ah
->opmode
== NL80211_IFTYPE_MONITOR
) {
1040 if (ath9k_htc_remove_monitor_interface(priv
))
1041 ath_err(common
, "Unable to remove monitor interface\n");
1043 ath_dbg(common
, ATH_DBG_CONFIG
,
1044 "Monitor interface removed\n");
1047 if (ah
->btcoex_hw
.enabled
) {
1048 ath9k_hw_btcoex_disable(ah
);
1049 if (ah
->btcoex_hw
.scheme
== ATH_BTCOEX_CFG_3WIRE
)
1050 ath_htc_cancel_btcoex_work(priv
);
1053 ath9k_hw_phy_disable(ah
);
1054 ath9k_hw_disable(ah
);
1055 ath9k_htc_ps_restore(priv
);
1056 ath9k_htc_setpower(priv
, ATH9K_PM_FULL_SLEEP
);
1058 priv
->op_flags
|= OP_INVALID
;
1060 ath_dbg(common
, ATH_DBG_CONFIG
, "Driver halt\n");
1061 mutex_unlock(&priv
->mutex
);
1064 static int ath9k_htc_add_interface(struct ieee80211_hw
*hw
,
1065 struct ieee80211_vif
*vif
)
1067 struct ath9k_htc_priv
*priv
= hw
->priv
;
1068 struct ath9k_htc_vif
*avp
= (void *)vif
->drv_priv
;
1069 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
1070 struct ath9k_htc_target_vif hvif
;
1074 mutex_lock(&priv
->mutex
);
1076 /* Only one interface for now */
1077 if (priv
->nvifs
> 0) {
1082 ath9k_htc_ps_wakeup(priv
);
1083 memset(&hvif
, 0, sizeof(struct ath9k_htc_target_vif
));
1084 memcpy(&hvif
.myaddr
, vif
->addr
, ETH_ALEN
);
1086 switch (vif
->type
) {
1087 case NL80211_IFTYPE_STATION
:
1088 hvif
.opmode
= cpu_to_be32(HTC_M_STA
);
1090 case NL80211_IFTYPE_ADHOC
:
1091 hvif
.opmode
= cpu_to_be32(HTC_M_IBSS
);
1095 "Interface type %d not yet supported\n", vif
->type
);
1100 ath_dbg(common
, ATH_DBG_CONFIG
,
1101 "Attach a VIF of type: %d\n", vif
->type
);
1103 priv
->ah
->opmode
= vif
->type
;
1105 /* Index starts from zero on the target */
1106 avp
->index
= hvif
.index
= priv
->nvifs
;
1107 hvif
.rtsthreshold
= cpu_to_be16(2304);
1108 WMI_CMD_BUF(WMI_VAP_CREATE_CMDID
, &hvif
);
1115 * We need a node in target to tx mgmt frames
1116 * before association.
1118 ret
= ath9k_htc_add_station(priv
, vif
, NULL
);
1122 ret
= ath9k_htc_update_cap_target(priv
);
1124 ath_dbg(common
, ATH_DBG_CONFIG
,
1125 "Failed to update capability in target\n");
1129 ath9k_htc_ps_restore(priv
);
1130 mutex_unlock(&priv
->mutex
);
1135 static void ath9k_htc_remove_interface(struct ieee80211_hw
*hw
,
1136 struct ieee80211_vif
*vif
)
1138 struct ath9k_htc_priv
*priv
= hw
->priv
;
1139 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
1140 struct ath9k_htc_vif
*avp
= (void *)vif
->drv_priv
;
1141 struct ath9k_htc_target_vif hvif
;
1145 ath_dbg(common
, ATH_DBG_CONFIG
, "Detach Interface\n");
1147 mutex_lock(&priv
->mutex
);
1148 ath9k_htc_ps_wakeup(priv
);
1150 memset(&hvif
, 0, sizeof(struct ath9k_htc_target_vif
));
1151 memcpy(&hvif
.myaddr
, vif
->addr
, ETH_ALEN
);
1152 hvif
.index
= avp
->index
;
1153 WMI_CMD_BUF(WMI_VAP_REMOVE_CMDID
, &hvif
);
1156 ath9k_htc_remove_station(priv
, vif
, NULL
);
1159 ath9k_htc_ps_restore(priv
);
1160 mutex_unlock(&priv
->mutex
);
1163 static int ath9k_htc_config(struct ieee80211_hw
*hw
, u32 changed
)
1165 struct ath9k_htc_priv
*priv
= hw
->priv
;
1166 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
1167 struct ieee80211_conf
*conf
= &hw
->conf
;
1169 mutex_lock(&priv
->mutex
);
1171 if (changed
& IEEE80211_CONF_CHANGE_IDLE
) {
1172 bool enable_radio
= false;
1173 bool idle
= !!(conf
->flags
& IEEE80211_CONF_IDLE
);
1175 mutex_lock(&priv
->htc_pm_lock
);
1176 if (!idle
&& priv
->ps_idle
)
1177 enable_radio
= true;
1178 priv
->ps_idle
= idle
;
1179 mutex_unlock(&priv
->htc_pm_lock
);
1182 ath_dbg(common
, ATH_DBG_CONFIG
,
1183 "not-idle: enabling radio\n");
1184 ath9k_htc_setpower(priv
, ATH9K_PM_AWAKE
);
1185 ath9k_htc_radio_enable(hw
);
1189 if (changed
& IEEE80211_CONF_CHANGE_CHANNEL
) {
1190 struct ieee80211_channel
*curchan
= hw
->conf
.channel
;
1191 int pos
= curchan
->hw_value
;
1193 ath_dbg(common
, ATH_DBG_CONFIG
, "Set channel: %d MHz\n",
1194 curchan
->center_freq
);
1196 ath9k_cmn_update_ichannel(&priv
->ah
->channels
[pos
],
1198 hw
->conf
.channel_type
);
1200 if (ath9k_htc_set_channel(priv
, hw
, &priv
->ah
->channels
[pos
]) < 0) {
1201 ath_err(common
, "Unable to set channel\n");
1202 mutex_unlock(&priv
->mutex
);
1208 if (changed
& IEEE80211_CONF_CHANGE_PS
) {
1209 if (conf
->flags
& IEEE80211_CONF_PS
) {
1210 ath9k_htc_setpower(priv
, ATH9K_PM_NETWORK_SLEEP
);
1211 priv
->ps_enabled
= true;
1213 priv
->ps_enabled
= false;
1214 cancel_work_sync(&priv
->ps_work
);
1215 ath9k_htc_setpower(priv
, ATH9K_PM_AWAKE
);
1219 if (changed
& IEEE80211_CONF_CHANGE_POWER
) {
1220 priv
->txpowlimit
= 2 * conf
->power_level
;
1221 ath_update_txpow(priv
);
1224 if (changed
& IEEE80211_CONF_CHANGE_MONITOR
) {
1225 if (conf
->flags
& IEEE80211_CONF_MONITOR
) {
1226 if (ath9k_htc_add_monitor_interface(priv
))
1227 ath_err(common
, "Failed to set monitor mode\n");
1229 ath_dbg(common
, ATH_DBG_CONFIG
,
1230 "HW opmode set to Monitor mode\n");
1234 if (changed
& IEEE80211_CONF_CHANGE_IDLE
) {
1235 mutex_lock(&priv
->htc_pm_lock
);
1236 if (!priv
->ps_idle
) {
1237 mutex_unlock(&priv
->htc_pm_lock
);
1240 mutex_unlock(&priv
->htc_pm_lock
);
1242 ath_dbg(common
, ATH_DBG_CONFIG
,
1243 "idle: disabling radio\n");
1244 ath9k_htc_radio_disable(hw
);
1248 mutex_unlock(&priv
->mutex
);
1252 #define SUPPORTED_FILTERS \
1253 (FIF_PROMISC_IN_BSS | \
1258 FIF_BCN_PRBRESP_PROMISC | \
1262 static void ath9k_htc_configure_filter(struct ieee80211_hw
*hw
,
1263 unsigned int changed_flags
,
1264 unsigned int *total_flags
,
1267 struct ath9k_htc_priv
*priv
= hw
->priv
;
1270 mutex_lock(&priv
->mutex
);
1271 ath9k_htc_ps_wakeup(priv
);
1273 changed_flags
&= SUPPORTED_FILTERS
;
1274 *total_flags
&= SUPPORTED_FILTERS
;
1276 priv
->rxfilter
= *total_flags
;
1277 rfilt
= ath9k_htc_calcrxfilter(priv
);
1278 ath9k_hw_setrxfilter(priv
->ah
, rfilt
);
1280 ath_dbg(ath9k_hw_common(priv
->ah
), ATH_DBG_CONFIG
,
1281 "Set HW RX filter: 0x%x\n", rfilt
);
1283 ath9k_htc_ps_restore(priv
);
1284 mutex_unlock(&priv
->mutex
);
1287 static int ath9k_htc_sta_add(struct ieee80211_hw
*hw
,
1288 struct ieee80211_vif
*vif
,
1289 struct ieee80211_sta
*sta
)
1291 struct ath9k_htc_priv
*priv
= hw
->priv
;
1294 mutex_lock(&priv
->mutex
);
1295 ath9k_htc_ps_wakeup(priv
);
1296 ret
= ath9k_htc_add_station(priv
, vif
, sta
);
1298 ath9k_htc_init_rate(priv
, sta
);
1299 ath9k_htc_ps_restore(priv
);
1300 mutex_unlock(&priv
->mutex
);
1305 static int ath9k_htc_sta_remove(struct ieee80211_hw
*hw
,
1306 struct ieee80211_vif
*vif
,
1307 struct ieee80211_sta
*sta
)
1309 struct ath9k_htc_priv
*priv
= hw
->priv
;
1312 mutex_lock(&priv
->mutex
);
1313 ath9k_htc_ps_wakeup(priv
);
1314 ret
= ath9k_htc_remove_station(priv
, vif
, sta
);
1315 ath9k_htc_ps_restore(priv
);
1316 mutex_unlock(&priv
->mutex
);
1321 static int ath9k_htc_conf_tx(struct ieee80211_hw
*hw
, u16 queue
,
1322 const struct ieee80211_tx_queue_params
*params
)
1324 struct ath9k_htc_priv
*priv
= hw
->priv
;
1325 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
1326 struct ath9k_tx_queue_info qi
;
1329 if (queue
>= WME_NUM_AC
)
1332 mutex_lock(&priv
->mutex
);
1333 ath9k_htc_ps_wakeup(priv
);
1335 memset(&qi
, 0, sizeof(struct ath9k_tx_queue_info
));
1337 qi
.tqi_aifs
= params
->aifs
;
1338 qi
.tqi_cwmin
= params
->cw_min
;
1339 qi
.tqi_cwmax
= params
->cw_max
;
1340 qi
.tqi_burstTime
= params
->txop
;
1342 qnum
= get_hw_qnum(queue
, priv
->hwq_map
);
1344 ath_dbg(common
, ATH_DBG_CONFIG
,
1345 "Configure tx [queue/hwq] [%d/%d], aifs: %d, cw_min: %d, cw_max: %d, txop: %d\n",
1346 queue
, qnum
, params
->aifs
, params
->cw_min
,
1347 params
->cw_max
, params
->txop
);
1349 ret
= ath_htc_txq_update(priv
, qnum
, &qi
);
1351 ath_err(common
, "TXQ Update failed\n");
1355 if ((priv
->ah
->opmode
== NL80211_IFTYPE_ADHOC
) &&
1356 (qnum
== priv
->hwq_map
[WME_AC_BE
]))
1357 ath9k_htc_beaconq_config(priv
);
1359 ath9k_htc_ps_restore(priv
);
1360 mutex_unlock(&priv
->mutex
);
1365 static int ath9k_htc_set_key(struct ieee80211_hw
*hw
,
1366 enum set_key_cmd cmd
,
1367 struct ieee80211_vif
*vif
,
1368 struct ieee80211_sta
*sta
,
1369 struct ieee80211_key_conf
*key
)
1371 struct ath9k_htc_priv
*priv
= hw
->priv
;
1372 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
1375 if (htc_modparam_nohwcrypt
)
1378 mutex_lock(&priv
->mutex
);
1379 ath_dbg(common
, ATH_DBG_CONFIG
, "Set HW Key\n");
1380 ath9k_htc_ps_wakeup(priv
);
1384 ret
= ath_key_config(common
, vif
, sta
, key
);
1386 key
->hw_key_idx
= ret
;
1387 /* push IV and Michael MIC generation to stack */
1388 key
->flags
|= IEEE80211_KEY_FLAG_GENERATE_IV
;
1389 if (key
->cipher
== WLAN_CIPHER_SUITE_TKIP
)
1390 key
->flags
|= IEEE80211_KEY_FLAG_GENERATE_MMIC
;
1391 if (priv
->ah
->sw_mgmt_crypto
&&
1392 key
->cipher
== WLAN_CIPHER_SUITE_CCMP
)
1393 key
->flags
|= IEEE80211_KEY_FLAG_SW_MGMT
;
1398 ath_key_delete(common
, key
);
1404 ath9k_htc_ps_restore(priv
);
1405 mutex_unlock(&priv
->mutex
);
1410 static void ath9k_htc_bss_info_changed(struct ieee80211_hw
*hw
,
1411 struct ieee80211_vif
*vif
,
1412 struct ieee80211_bss_conf
*bss_conf
,
1415 struct ath9k_htc_priv
*priv
= hw
->priv
;
1416 struct ath_hw
*ah
= priv
->ah
;
1417 struct ath_common
*common
= ath9k_hw_common(ah
);
1419 mutex_lock(&priv
->mutex
);
1420 ath9k_htc_ps_wakeup(priv
);
1422 if (changed
& BSS_CHANGED_ASSOC
) {
1423 common
->curaid
= bss_conf
->assoc
?
1425 ath_dbg(common
, ATH_DBG_CONFIG
, "BSS Changed ASSOC %d\n",
1428 if (bss_conf
->assoc
) {
1429 priv
->op_flags
|= OP_ASSOCIATED
;
1430 ath_start_ani(priv
);
1432 priv
->op_flags
&= ~OP_ASSOCIATED
;
1433 cancel_delayed_work_sync(&priv
->ath9k_ani_work
);
1437 if (changed
& BSS_CHANGED_BSSID
) {
1439 memcpy(common
->curbssid
, bss_conf
->bssid
, ETH_ALEN
);
1440 ath9k_hw_write_associd(ah
);
1442 ath_dbg(common
, ATH_DBG_CONFIG
,
1443 "BSSID: %pM aid: 0x%x\n",
1444 common
->curbssid
, common
->curaid
);
1447 if ((changed
& BSS_CHANGED_BEACON_INT
) ||
1448 (changed
& BSS_CHANGED_BEACON
) ||
1449 ((changed
& BSS_CHANGED_BEACON_ENABLED
) &&
1450 bss_conf
->enable_beacon
)) {
1451 priv
->op_flags
|= OP_ENABLE_BEACON
;
1452 ath9k_htc_beacon_config(priv
, vif
);
1455 if ((changed
& BSS_CHANGED_BEACON_ENABLED
) &&
1456 !bss_conf
->enable_beacon
) {
1457 priv
->op_flags
&= ~OP_ENABLE_BEACON
;
1458 ath9k_htc_beacon_config(priv
, vif
);
1461 if (changed
& BSS_CHANGED_ERP_PREAMBLE
) {
1462 ath_dbg(common
, ATH_DBG_CONFIG
, "BSS Changed PREAMBLE %d\n",
1463 bss_conf
->use_short_preamble
);
1464 if (bss_conf
->use_short_preamble
)
1465 priv
->op_flags
|= OP_PREAMBLE_SHORT
;
1467 priv
->op_flags
&= ~OP_PREAMBLE_SHORT
;
1470 if (changed
& BSS_CHANGED_ERP_CTS_PROT
) {
1471 ath_dbg(common
, ATH_DBG_CONFIG
, "BSS Changed CTS PROT %d\n",
1472 bss_conf
->use_cts_prot
);
1473 if (bss_conf
->use_cts_prot
&&
1474 hw
->conf
.channel
->band
!= IEEE80211_BAND_5GHZ
)
1475 priv
->op_flags
|= OP_PROTECT_ENABLE
;
1477 priv
->op_flags
&= ~OP_PROTECT_ENABLE
;
1480 if (changed
& BSS_CHANGED_ERP_SLOT
) {
1481 if (bss_conf
->use_short_slot
)
1486 ath9k_hw_init_global_settings(ah
);
1489 if (changed
& BSS_CHANGED_HT
)
1490 ath9k_htc_update_rate(priv
, vif
, bss_conf
);
1492 ath9k_htc_ps_restore(priv
);
1493 mutex_unlock(&priv
->mutex
);
1496 static u64
ath9k_htc_get_tsf(struct ieee80211_hw
*hw
)
1498 struct ath9k_htc_priv
*priv
= hw
->priv
;
1501 mutex_lock(&priv
->mutex
);
1502 ath9k_htc_ps_wakeup(priv
);
1503 tsf
= ath9k_hw_gettsf64(priv
->ah
);
1504 ath9k_htc_ps_restore(priv
);
1505 mutex_unlock(&priv
->mutex
);
1510 static void ath9k_htc_set_tsf(struct ieee80211_hw
*hw
, u64 tsf
)
1512 struct ath9k_htc_priv
*priv
= hw
->priv
;
1514 mutex_lock(&priv
->mutex
);
1515 ath9k_htc_ps_wakeup(priv
);
1516 ath9k_hw_settsf64(priv
->ah
, tsf
);
1517 ath9k_htc_ps_restore(priv
);
1518 mutex_unlock(&priv
->mutex
);
1521 static void ath9k_htc_reset_tsf(struct ieee80211_hw
*hw
)
1523 struct ath9k_htc_priv
*priv
= hw
->priv
;
1525 mutex_lock(&priv
->mutex
);
1526 ath9k_htc_ps_wakeup(priv
);
1527 ath9k_hw_reset_tsf(priv
->ah
);
1528 ath9k_htc_ps_restore(priv
);
1529 mutex_unlock(&priv
->mutex
);
1532 static int ath9k_htc_ampdu_action(struct ieee80211_hw
*hw
,
1533 struct ieee80211_vif
*vif
,
1534 enum ieee80211_ampdu_mlme_action action
,
1535 struct ieee80211_sta
*sta
,
1538 struct ath9k_htc_priv
*priv
= hw
->priv
;
1539 struct ath9k_htc_sta
*ista
;
1543 case IEEE80211_AMPDU_RX_START
:
1545 case IEEE80211_AMPDU_RX_STOP
:
1547 case IEEE80211_AMPDU_TX_START
:
1548 ret
= ath9k_htc_tx_aggr_oper(priv
, vif
, sta
, action
, tid
);
1550 ieee80211_start_tx_ba_cb_irqsafe(vif
, sta
->addr
, tid
);
1552 case IEEE80211_AMPDU_TX_STOP
:
1553 ath9k_htc_tx_aggr_oper(priv
, vif
, sta
, action
, tid
);
1554 ieee80211_stop_tx_ba_cb_irqsafe(vif
, sta
->addr
, tid
);
1556 case IEEE80211_AMPDU_TX_OPERATIONAL
:
1557 ista
= (struct ath9k_htc_sta
*) sta
->drv_priv
;
1558 spin_lock_bh(&priv
->tx_lock
);
1559 ista
->tid_state
[tid
] = AGGR_OPERATIONAL
;
1560 spin_unlock_bh(&priv
->tx_lock
);
1563 ath_err(ath9k_hw_common(priv
->ah
), "Unknown AMPDU action\n");
1569 static void ath9k_htc_sw_scan_start(struct ieee80211_hw
*hw
)
1571 struct ath9k_htc_priv
*priv
= hw
->priv
;
1573 mutex_lock(&priv
->mutex
);
1574 spin_lock_bh(&priv
->beacon_lock
);
1575 priv
->op_flags
|= OP_SCANNING
;
1576 spin_unlock_bh(&priv
->beacon_lock
);
1577 cancel_work_sync(&priv
->ps_work
);
1578 if (priv
->op_flags
& OP_ASSOCIATED
)
1579 cancel_delayed_work_sync(&priv
->ath9k_ani_work
);
1580 mutex_unlock(&priv
->mutex
);
1583 static void ath9k_htc_sw_scan_complete(struct ieee80211_hw
*hw
)
1585 struct ath9k_htc_priv
*priv
= hw
->priv
;
1587 mutex_lock(&priv
->mutex
);
1588 ath9k_htc_ps_wakeup(priv
);
1589 spin_lock_bh(&priv
->beacon_lock
);
1590 priv
->op_flags
&= ~OP_SCANNING
;
1591 spin_unlock_bh(&priv
->beacon_lock
);
1592 if (priv
->op_flags
& OP_ASSOCIATED
) {
1593 ath9k_htc_beacon_config(priv
, priv
->vif
);
1594 ath_start_ani(priv
);
1596 ath9k_htc_ps_restore(priv
);
1597 mutex_unlock(&priv
->mutex
);
1600 static int ath9k_htc_set_rts_threshold(struct ieee80211_hw
*hw
, u32 value
)
1605 static void ath9k_htc_set_coverage_class(struct ieee80211_hw
*hw
,
1608 struct ath9k_htc_priv
*priv
= hw
->priv
;
1610 mutex_lock(&priv
->mutex
);
1611 ath9k_htc_ps_wakeup(priv
);
1612 priv
->ah
->coverage_class
= coverage_class
;
1613 ath9k_hw_init_global_settings(priv
->ah
);
1614 ath9k_htc_ps_restore(priv
);
1615 mutex_unlock(&priv
->mutex
);
1618 struct ieee80211_ops ath9k_htc_ops
= {
1620 .start
= ath9k_htc_start
,
1621 .stop
= ath9k_htc_stop
,
1622 .add_interface
= ath9k_htc_add_interface
,
1623 .remove_interface
= ath9k_htc_remove_interface
,
1624 .config
= ath9k_htc_config
,
1625 .configure_filter
= ath9k_htc_configure_filter
,
1626 .sta_add
= ath9k_htc_sta_add
,
1627 .sta_remove
= ath9k_htc_sta_remove
,
1628 .conf_tx
= ath9k_htc_conf_tx
,
1629 .bss_info_changed
= ath9k_htc_bss_info_changed
,
1630 .set_key
= ath9k_htc_set_key
,
1631 .get_tsf
= ath9k_htc_get_tsf
,
1632 .set_tsf
= ath9k_htc_set_tsf
,
1633 .reset_tsf
= ath9k_htc_reset_tsf
,
1634 .ampdu_action
= ath9k_htc_ampdu_action
,
1635 .sw_scan_start
= ath9k_htc_sw_scan_start
,
1636 .sw_scan_complete
= ath9k_htc_sw_scan_complete
,
1637 .set_rts_threshold
= ath9k_htc_set_rts_threshold
,
1638 .rfkill_poll
= ath9k_htc_rfkill_poll_state
,
1639 .set_coverage_class
= ath9k_htc_set_coverage_class
,