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
)
416 sta
= ieee80211_find_sta(vif
, sta_addr
);
418 ista
= (struct ath9k_htc_sta
*) sta
->drv_priv
;
429 memset(&aggr
, 0, sizeof(struct ath9k_htc_target_aggr
));
431 aggr
.sta_index
= ista
->index
;
434 aggr
.aggr_enable
= oper
;
437 ista
->tid_state
[tid
] = AGGR_START
;
439 ista
->tid_state
[tid
] = AGGR_STOP
;
441 WMI_CMD_BUF(WMI_TX_AGGR_ENABLE_CMDID
, &aggr
);
443 ath_print(common
, ATH_DBG_CONFIG
,
444 "Unable to %s TX aggregation for (%pM, %d)\n",
445 (oper
) ? "start" : "stop", sta
->addr
, tid
);
447 ath_print(common
, ATH_DBG_CONFIG
,
448 "%s aggregation for (%pM, %d)\n",
449 (oper
) ? "Starting" : "Stopping", sta
->addr
, tid
);
454 void ath9k_htc_aggr_work(struct work_struct
*work
)
457 struct ath9k_htc_priv
*priv
=
458 container_of(work
, struct ath9k_htc_priv
,
459 ath9k_aggr_work
.work
);
460 struct ath9k_htc_aggr_work
*wk
= &priv
->aggr_work
;
462 mutex_lock(&wk
->mutex
);
464 switch (wk
->action
) {
465 case IEEE80211_AMPDU_TX_START
:
466 ret
= ath9k_htc_aggr_oper(priv
, wk
->vif
, wk
->sta_addr
,
469 ieee80211_start_tx_ba_cb(wk
->vif
, wk
->sta_addr
,
472 case IEEE80211_AMPDU_TX_STOP
:
473 ath9k_htc_aggr_oper(priv
, wk
->vif
, wk
->sta_addr
,
475 ieee80211_stop_tx_ba_cb(wk
->vif
, wk
->sta_addr
, wk
->tid
);
478 ath_print(ath9k_hw_common(priv
->ah
), ATH_DBG_FATAL
,
479 "Unknown AMPDU action\n");
482 mutex_unlock(&wk
->mutex
);
489 #ifdef CONFIG_ATH9K_HTC_DEBUGFS
491 static int ath9k_debugfs_open(struct inode
*inode
, struct file
*file
)
493 file
->private_data
= inode
->i_private
;
497 static ssize_t
read_file_tgt_stats(struct file
*file
, char __user
*user_buf
,
498 size_t count
, loff_t
*ppos
)
500 struct ath9k_htc_priv
*priv
=
501 (struct ath9k_htc_priv
*) file
->private_data
;
502 struct ath9k_htc_target_stats cmd_rsp
;
504 unsigned int len
= 0;
507 memset(&cmd_rsp
, 0, sizeof(cmd_rsp
));
509 WMI_CMD(WMI_TGT_STATS_CMDID
);
514 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
515 "%19s : %10u\n", "TX Short Retries",
516 be32_to_cpu(cmd_rsp
.tx_shortretry
));
517 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
518 "%19s : %10u\n", "TX Long Retries",
519 be32_to_cpu(cmd_rsp
.tx_longretry
));
520 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
521 "%19s : %10u\n", "TX Xretries",
522 be32_to_cpu(cmd_rsp
.tx_xretries
));
523 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
524 "%19s : %10u\n", "TX Unaggr. Xretries",
525 be32_to_cpu(cmd_rsp
.ht_txunaggr_xretry
));
526 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
527 "%19s : %10u\n", "TX Xretries (HT)",
528 be32_to_cpu(cmd_rsp
.ht_tx_xretries
));
529 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
530 "%19s : %10u\n", "TX Rate", priv
->debug
.txrate
);
532 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, len
);
535 static const struct file_operations fops_tgt_stats
= {
536 .read
= read_file_tgt_stats
,
537 .open
= ath9k_debugfs_open
,
541 static ssize_t
read_file_xmit(struct file
*file
, char __user
*user_buf
,
542 size_t count
, loff_t
*ppos
)
544 struct ath9k_htc_priv
*priv
=
545 (struct ath9k_htc_priv
*) file
->private_data
;
547 unsigned int len
= 0;
549 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
550 "%20s : %10u\n", "Buffers queued",
551 priv
->debug
.tx_stats
.buf_queued
);
552 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
553 "%20s : %10u\n", "Buffers completed",
554 priv
->debug
.tx_stats
.buf_completed
);
555 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
556 "%20s : %10u\n", "SKBs queued",
557 priv
->debug
.tx_stats
.skb_queued
);
558 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
559 "%20s : %10u\n", "SKBs completed",
560 priv
->debug
.tx_stats
.skb_completed
);
562 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, len
);
565 static const struct file_operations fops_xmit
= {
566 .read
= read_file_xmit
,
567 .open
= ath9k_debugfs_open
,
571 static ssize_t
read_file_recv(struct file
*file
, char __user
*user_buf
,
572 size_t count
, loff_t
*ppos
)
574 struct ath9k_htc_priv
*priv
=
575 (struct ath9k_htc_priv
*) file
->private_data
;
577 unsigned int len
= 0;
579 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
580 "%20s : %10u\n", "SKBs allocated",
581 priv
->debug
.rx_stats
.skb_allocated
);
582 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
583 "%20s : %10u\n", "SKBs completed",
584 priv
->debug
.rx_stats
.skb_completed
);
585 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
586 "%20s : %10u\n", "SKBs Dropped",
587 priv
->debug
.rx_stats
.skb_dropped
);
589 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, len
);
592 static const struct file_operations fops_recv
= {
593 .read
= read_file_recv
,
594 .open
= ath9k_debugfs_open
,
598 int ath9k_htc_init_debug(struct ath_hw
*ah
)
600 struct ath_common
*common
= ath9k_hw_common(ah
);
601 struct ath9k_htc_priv
*priv
= (struct ath9k_htc_priv
*) common
->priv
;
603 if (!ath9k_debugfs_root
)
606 priv
->debug
.debugfs_phy
= debugfs_create_dir(wiphy_name(priv
->hw
->wiphy
),
608 if (!priv
->debug
.debugfs_phy
)
611 priv
->debug
.debugfs_tgt_stats
= debugfs_create_file("tgt_stats", S_IRUSR
,
612 priv
->debug
.debugfs_phy
,
613 priv
, &fops_tgt_stats
);
614 if (!priv
->debug
.debugfs_tgt_stats
)
618 priv
->debug
.debugfs_xmit
= debugfs_create_file("xmit", S_IRUSR
,
619 priv
->debug
.debugfs_phy
,
621 if (!priv
->debug
.debugfs_xmit
)
624 priv
->debug
.debugfs_recv
= debugfs_create_file("recv", S_IRUSR
,
625 priv
->debug
.debugfs_phy
,
627 if (!priv
->debug
.debugfs_recv
)
633 ath9k_htc_exit_debug(ah
);
637 void ath9k_htc_exit_debug(struct ath_hw
*ah
)
639 struct ath_common
*common
= ath9k_hw_common(ah
);
640 struct ath9k_htc_priv
*priv
= (struct ath9k_htc_priv
*) common
->priv
;
642 debugfs_remove(priv
->debug
.debugfs_recv
);
643 debugfs_remove(priv
->debug
.debugfs_xmit
);
644 debugfs_remove(priv
->debug
.debugfs_tgt_stats
);
645 debugfs_remove(priv
->debug
.debugfs_phy
);
648 int ath9k_htc_debug_create_root(void)
650 ath9k_debugfs_root
= debugfs_create_dir(KBUILD_MODNAME
, NULL
);
651 if (!ath9k_debugfs_root
)
657 void ath9k_htc_debug_remove_root(void)
659 debugfs_remove(ath9k_debugfs_root
);
660 ath9k_debugfs_root
= NULL
;
663 #endif /* CONFIG_ATH9K_HTC_DEBUGFS */
669 static void ath_start_ani(struct ath9k_htc_priv
*priv
)
671 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
672 unsigned long timestamp
= jiffies_to_msecs(jiffies
);
674 common
->ani
.longcal_timer
= timestamp
;
675 common
->ani
.shortcal_timer
= timestamp
;
676 common
->ani
.checkani_timer
= timestamp
;
678 ieee80211_queue_delayed_work(common
->hw
, &priv
->ath9k_ani_work
,
679 msecs_to_jiffies(ATH_ANI_POLLINTERVAL
));
682 void ath9k_ani_work(struct work_struct
*work
)
684 struct ath9k_htc_priv
*priv
=
685 container_of(work
, struct ath9k_htc_priv
,
686 ath9k_ani_work
.work
);
687 struct ath_hw
*ah
= priv
->ah
;
688 struct ath_common
*common
= ath9k_hw_common(ah
);
689 bool longcal
= false;
690 bool shortcal
= false;
691 bool aniflag
= false;
692 unsigned int timestamp
= jiffies_to_msecs(jiffies
);
693 u32 cal_interval
, short_cal_interval
;
695 short_cal_interval
= ATH_STA_SHORT_CALINTERVAL
;
697 /* Long calibration runs independently of short calibration. */
698 if ((timestamp
- common
->ani
.longcal_timer
) >= ATH_LONG_CALINTERVAL
) {
700 ath_print(common
, ATH_DBG_ANI
, "longcal @%lu\n", jiffies
);
701 common
->ani
.longcal_timer
= timestamp
;
704 /* Short calibration applies only while caldone is false */
705 if (!common
->ani
.caldone
) {
706 if ((timestamp
- common
->ani
.shortcal_timer
) >=
707 short_cal_interval
) {
709 ath_print(common
, ATH_DBG_ANI
,
710 "shortcal @%lu\n", jiffies
);
711 common
->ani
.shortcal_timer
= timestamp
;
712 common
->ani
.resetcal_timer
= timestamp
;
715 if ((timestamp
- common
->ani
.resetcal_timer
) >=
716 ATH_RESTART_CALINTERVAL
) {
717 common
->ani
.caldone
= ath9k_hw_reset_calvalid(ah
);
718 if (common
->ani
.caldone
)
719 common
->ani
.resetcal_timer
= timestamp
;
723 /* Verify whether we must check ANI */
724 if ((timestamp
- common
->ani
.checkani_timer
) >= ATH_ANI_POLLINTERVAL
) {
726 common
->ani
.checkani_timer
= timestamp
;
729 /* Skip all processing if there's nothing to do. */
730 if (longcal
|| shortcal
|| aniflag
) {
731 /* Call ANI routine if necessary */
733 ath9k_hw_ani_monitor(ah
, ah
->curchan
);
735 /* Perform calibration if necessary */
736 if (longcal
|| shortcal
) {
737 common
->ani
.caldone
=
738 ath9k_hw_calibrate(ah
, ah
->curchan
,
739 common
->rx_chainmask
,
743 common
->ani
.noise_floor
=
744 ath9k_hw_getchan_noise(ah
, ah
->curchan
);
746 ath_print(common
, ATH_DBG_ANI
,
747 " calibrate chan %u/%x nf: %d\n",
748 ah
->curchan
->channel
,
749 ah
->curchan
->channelFlags
,
750 common
->ani
.noise_floor
);
755 * Set timer interval based on previous results.
756 * The interval must be the shortest necessary to satisfy ANI,
757 * short calibration and long calibration.
759 cal_interval
= ATH_LONG_CALINTERVAL
;
760 if (priv
->ah
->config
.enable_ani
)
761 cal_interval
= min(cal_interval
, (u32
)ATH_ANI_POLLINTERVAL
);
762 if (!common
->ani
.caldone
)
763 cal_interval
= min(cal_interval
, (u32
)short_cal_interval
);
765 ieee80211_queue_delayed_work(common
->hw
, &priv
->ath9k_ani_work
,
766 msecs_to_jiffies(cal_interval
));
773 static void ath9k_led_blink_work(struct work_struct
*work
)
775 struct ath9k_htc_priv
*priv
= container_of(work
, struct ath9k_htc_priv
,
776 ath9k_led_blink_work
.work
);
778 if (!(priv
->op_flags
& OP_LED_ASSOCIATED
))
781 if ((priv
->led_on_duration
== ATH_LED_ON_DURATION_IDLE
) ||
782 (priv
->led_off_duration
== ATH_LED_OFF_DURATION_IDLE
))
783 ath9k_hw_set_gpio(priv
->ah
, priv
->ah
->led_pin
, 0);
785 ath9k_hw_set_gpio(priv
->ah
, priv
->ah
->led_pin
,
786 (priv
->op_flags
& OP_LED_ON
) ? 1 : 0);
788 ieee80211_queue_delayed_work(priv
->hw
,
789 &priv
->ath9k_led_blink_work
,
790 (priv
->op_flags
& OP_LED_ON
) ?
791 msecs_to_jiffies(priv
->led_off_duration
) :
792 msecs_to_jiffies(priv
->led_on_duration
));
794 priv
->led_on_duration
= priv
->led_on_cnt
?
795 max((ATH_LED_ON_DURATION_IDLE
- priv
->led_on_cnt
), 25) :
796 ATH_LED_ON_DURATION_IDLE
;
797 priv
->led_off_duration
= priv
->led_off_cnt
?
798 max((ATH_LED_OFF_DURATION_IDLE
- priv
->led_off_cnt
), 10) :
799 ATH_LED_OFF_DURATION_IDLE
;
800 priv
->led_on_cnt
= priv
->led_off_cnt
= 0;
802 if (priv
->op_flags
& OP_LED_ON
)
803 priv
->op_flags
&= ~OP_LED_ON
;
805 priv
->op_flags
|= OP_LED_ON
;
808 static void ath9k_led_brightness_work(struct work_struct
*work
)
810 struct ath_led
*led
= container_of(work
, struct ath_led
,
811 brightness_work
.work
);
812 struct ath9k_htc_priv
*priv
= led
->priv
;
814 switch (led
->brightness
) {
816 if (led
->led_type
== ATH_LED_ASSOC
||
817 led
->led_type
== ATH_LED_RADIO
) {
818 ath9k_hw_set_gpio(priv
->ah
, priv
->ah
->led_pin
,
819 (led
->led_type
== ATH_LED_RADIO
));
820 priv
->op_flags
&= ~OP_LED_ASSOCIATED
;
821 if (led
->led_type
== ATH_LED_RADIO
)
822 priv
->op_flags
&= ~OP_LED_ON
;
828 if (led
->led_type
== ATH_LED_ASSOC
) {
829 priv
->op_flags
|= OP_LED_ASSOCIATED
;
830 ieee80211_queue_delayed_work(priv
->hw
,
831 &priv
->ath9k_led_blink_work
, 0);
832 } else if (led
->led_type
== ATH_LED_RADIO
) {
833 ath9k_hw_set_gpio(priv
->ah
, priv
->ah
->led_pin
, 0);
834 priv
->op_flags
|= OP_LED_ON
;
844 static void ath9k_led_brightness(struct led_classdev
*led_cdev
,
845 enum led_brightness brightness
)
847 struct ath_led
*led
= container_of(led_cdev
, struct ath_led
, led_cdev
);
848 struct ath9k_htc_priv
*priv
= led
->priv
;
850 led
->brightness
= brightness
;
851 if (!(priv
->op_flags
& OP_LED_DEINIT
))
852 ieee80211_queue_delayed_work(priv
->hw
,
853 &led
->brightness_work
, 0);
856 static void ath9k_led_stop_brightness(struct ath9k_htc_priv
*priv
)
858 cancel_delayed_work_sync(&priv
->radio_led
.brightness_work
);
859 cancel_delayed_work_sync(&priv
->assoc_led
.brightness_work
);
860 cancel_delayed_work_sync(&priv
->tx_led
.brightness_work
);
861 cancel_delayed_work_sync(&priv
->rx_led
.brightness_work
);
864 static int ath9k_register_led(struct ath9k_htc_priv
*priv
, struct ath_led
*led
,
870 led
->led_cdev
.name
= led
->name
;
871 led
->led_cdev
.default_trigger
= trigger
;
872 led
->led_cdev
.brightness_set
= ath9k_led_brightness
;
874 ret
= led_classdev_register(wiphy_dev(priv
->hw
->wiphy
), &led
->led_cdev
);
876 ath_print(ath9k_hw_common(priv
->ah
), ATH_DBG_FATAL
,
877 "Failed to register led:%s", led
->name
);
881 INIT_DELAYED_WORK(&led
->brightness_work
, ath9k_led_brightness_work
);
886 static void ath9k_unregister_led(struct ath_led
*led
)
888 if (led
->registered
) {
889 led_classdev_unregister(&led
->led_cdev
);
894 void ath9k_deinit_leds(struct ath9k_htc_priv
*priv
)
896 priv
->op_flags
|= OP_LED_DEINIT
;
897 ath9k_unregister_led(&priv
->assoc_led
);
898 priv
->op_flags
&= ~OP_LED_ASSOCIATED
;
899 ath9k_unregister_led(&priv
->tx_led
);
900 ath9k_unregister_led(&priv
->rx_led
);
901 ath9k_unregister_led(&priv
->radio_led
);
902 ath9k_hw_set_gpio(priv
->ah
, priv
->ah
->led_pin
, 1);
905 void ath9k_init_leds(struct ath9k_htc_priv
*priv
)
910 if (AR_SREV_9287(priv
->ah
))
911 priv
->ah
->led_pin
= ATH_LED_PIN_9287
;
912 else if (AR_SREV_9271(priv
->ah
))
913 priv
->ah
->led_pin
= ATH_LED_PIN_9271
;
915 priv
->ah
->led_pin
= ATH_LED_PIN_DEF
;
917 /* Configure gpio 1 for output */
918 ath9k_hw_cfg_output(priv
->ah
, priv
->ah
->led_pin
,
919 AR_GPIO_OUTPUT_MUX_AS_OUTPUT
);
920 /* LED off, active low */
921 ath9k_hw_set_gpio(priv
->ah
, priv
->ah
->led_pin
, 1);
923 INIT_DELAYED_WORK(&priv
->ath9k_led_blink_work
, ath9k_led_blink_work
);
925 trigger
= ieee80211_get_radio_led_name(priv
->hw
);
926 snprintf(priv
->radio_led
.name
, sizeof(priv
->radio_led
.name
),
927 "ath9k-%s::radio", wiphy_name(priv
->hw
->wiphy
));
928 ret
= ath9k_register_led(priv
, &priv
->radio_led
, trigger
);
929 priv
->radio_led
.led_type
= ATH_LED_RADIO
;
933 trigger
= ieee80211_get_assoc_led_name(priv
->hw
);
934 snprintf(priv
->assoc_led
.name
, sizeof(priv
->assoc_led
.name
),
935 "ath9k-%s::assoc", wiphy_name(priv
->hw
->wiphy
));
936 ret
= ath9k_register_led(priv
, &priv
->assoc_led
, trigger
);
937 priv
->assoc_led
.led_type
= ATH_LED_ASSOC
;
941 trigger
= ieee80211_get_tx_led_name(priv
->hw
);
942 snprintf(priv
->tx_led
.name
, sizeof(priv
->tx_led
.name
),
943 "ath9k-%s::tx", wiphy_name(priv
->hw
->wiphy
));
944 ret
= ath9k_register_led(priv
, &priv
->tx_led
, trigger
);
945 priv
->tx_led
.led_type
= ATH_LED_TX
;
949 trigger
= ieee80211_get_rx_led_name(priv
->hw
);
950 snprintf(priv
->rx_led
.name
, sizeof(priv
->rx_led
.name
),
951 "ath9k-%s::rx", wiphy_name(priv
->hw
->wiphy
));
952 ret
= ath9k_register_led(priv
, &priv
->rx_led
, trigger
);
953 priv
->rx_led
.led_type
= ATH_LED_RX
;
957 priv
->op_flags
&= ~OP_LED_DEINIT
;
962 cancel_delayed_work_sync(&priv
->ath9k_led_blink_work
);
963 ath9k_deinit_leds(priv
);
966 /*******************/
968 /*******************/
970 static bool ath_is_rfkill_set(struct ath9k_htc_priv
*priv
)
972 return ath9k_hw_gpio_get(priv
->ah
, priv
->ah
->rfkill_gpio
) ==
973 priv
->ah
->rfkill_polarity
;
976 static void ath9k_htc_rfkill_poll_state(struct ieee80211_hw
*hw
)
978 struct ath9k_htc_priv
*priv
= hw
->priv
;
979 bool blocked
= !!ath_is_rfkill_set(priv
);
981 wiphy_rfkill_set_hw_state(hw
->wiphy
, blocked
);
984 void ath9k_start_rfkill_poll(struct ath9k_htc_priv
*priv
)
986 if (priv
->ah
->caps
.hw_caps
& ATH9K_HW_CAP_RFSILENT
)
987 wiphy_rfkill_start_polling(priv
->hw
->wiphy
);
990 /**********************/
991 /* mac80211 Callbacks */
992 /**********************/
994 static int ath9k_htc_tx(struct ieee80211_hw
*hw
, struct sk_buff
*skb
)
996 struct ieee80211_hdr
*hdr
;
997 struct ath9k_htc_priv
*priv
= hw
->priv
;
1000 hdr
= (struct ieee80211_hdr
*) skb
->data
;
1002 /* Add the padding after the header if this is not already done */
1003 padpos
= ath9k_cmn_padpos(hdr
->frame_control
);
1004 padsize
= padpos
& 3;
1005 if (padsize
&& skb
->len
> padpos
) {
1006 if (skb_headroom(skb
) < padsize
)
1008 skb_push(skb
, padsize
);
1009 memmove(skb
->data
, skb
->data
+ padsize
, padpos
);
1012 if (ath9k_htc_tx_start(priv
, skb
) != 0) {
1013 ath_print(ath9k_hw_common(priv
->ah
), ATH_DBG_XMIT
, "Tx failed");
1020 dev_kfree_skb_any(skb
);
1024 static int ath9k_htc_start(struct ieee80211_hw
*hw
)
1026 struct ath9k_htc_priv
*priv
= hw
->priv
;
1027 struct ath_hw
*ah
= priv
->ah
;
1028 struct ath_common
*common
= ath9k_hw_common(ah
);
1029 struct ieee80211_channel
*curchan
= hw
->conf
.channel
;
1030 struct ath9k_channel
*init_channel
;
1032 enum htc_phymode mode
;
1036 ath_print(common
, ATH_DBG_CONFIG
,
1037 "Starting driver with initial channel: %d MHz\n",
1038 curchan
->center_freq
);
1040 mutex_lock(&priv
->mutex
);
1042 /* setup initial channel */
1043 init_channel
= ath9k_cmn_get_curchannel(hw
, ah
);
1045 /* Reset SERDES registers */
1046 ath9k_hw_configpcipowersave(ah
, 0, 0);
1048 ath9k_hw_htc_resetinit(ah
);
1049 ret
= ath9k_hw_reset(ah
, init_channel
, false);
1051 ath_print(common
, ATH_DBG_FATAL
,
1052 "Unable to reset hardware; reset status %d "
1053 "(freq %u MHz)\n", ret
, curchan
->center_freq
);
1057 ath_update_txpow(priv
);
1059 mode
= ath9k_htc_get_curmode(priv
, init_channel
);
1060 htc_mode
= cpu_to_be16(mode
);
1061 WMI_CMD_BUF(WMI_SET_MODE_CMDID
, &htc_mode
);
1065 WMI_CMD(WMI_ATH_INIT_CMDID
);
1069 WMI_CMD(WMI_START_RECV_CMDID
);
1073 ath9k_host_rx_init(priv
);
1075 priv
->op_flags
&= ~OP_INVALID
;
1076 htc_start(priv
->htc
);
1079 mutex_unlock(&priv
->mutex
);
1083 static void ath9k_htc_stop(struct ieee80211_hw
*hw
)
1085 struct ath9k_htc_priv
*priv
= hw
->priv
;
1086 struct ath_hw
*ah
= priv
->ah
;
1087 struct ath_common
*common
= ath9k_hw_common(ah
);
1091 mutex_lock(&priv
->mutex
);
1093 if (priv
->op_flags
& OP_INVALID
) {
1094 ath_print(common
, ATH_DBG_ANY
, "Device not present\n");
1095 mutex_unlock(&priv
->mutex
);
1099 htc_stop(priv
->htc
);
1100 WMI_CMD(WMI_DISABLE_INTR_CMDID
);
1101 WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID
);
1102 WMI_CMD(WMI_STOP_RECV_CMDID
);
1103 ath9k_hw_phy_disable(ah
);
1104 ath9k_hw_disable(ah
);
1105 ath9k_hw_configpcipowersave(ah
, 1, 1);
1106 ath9k_hw_setpower(ah
, ATH9K_PM_FULL_SLEEP
);
1108 cancel_delayed_work_sync(&priv
->ath9k_ani_work
);
1109 cancel_delayed_work_sync(&priv
->ath9k_aggr_work
);
1110 cancel_delayed_work_sync(&priv
->ath9k_led_blink_work
);
1111 ath9k_led_stop_brightness(priv
);
1112 skb_queue_purge(&priv
->tx_queue
);
1114 /* Remove monitor interface here */
1115 if (ah
->opmode
== NL80211_IFTYPE_MONITOR
) {
1116 if (ath9k_htc_remove_monitor_interface(priv
))
1117 ath_print(common
, ATH_DBG_FATAL
,
1118 "Unable to remove monitor interface\n");
1120 ath_print(common
, ATH_DBG_CONFIG
,
1121 "Monitor interface removed\n");
1124 priv
->op_flags
|= OP_INVALID
;
1125 mutex_unlock(&priv
->mutex
);
1127 ath_print(common
, ATH_DBG_CONFIG
, "Driver halt\n");
1130 static int ath9k_htc_add_interface(struct ieee80211_hw
*hw
,
1131 struct ieee80211_vif
*vif
)
1133 struct ath9k_htc_priv
*priv
= hw
->priv
;
1134 struct ath9k_htc_vif
*avp
= (void *)vif
->drv_priv
;
1135 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
1136 struct ath9k_htc_target_vif hvif
;
1140 mutex_lock(&priv
->mutex
);
1142 /* Only one interface for now */
1143 if (priv
->nvifs
> 0) {
1148 memset(&hvif
, 0, sizeof(struct ath9k_htc_target_vif
));
1149 memcpy(&hvif
.myaddr
, vif
->addr
, ETH_ALEN
);
1151 switch (vif
->type
) {
1152 case NL80211_IFTYPE_STATION
:
1153 hvif
.opmode
= cpu_to_be32(HTC_M_STA
);
1155 case NL80211_IFTYPE_ADHOC
:
1156 hvif
.opmode
= cpu_to_be32(HTC_M_IBSS
);
1159 ath_print(common
, ATH_DBG_FATAL
,
1160 "Interface type %d not yet supported\n", vif
->type
);
1165 ath_print(common
, ATH_DBG_CONFIG
,
1166 "Attach a VIF of type: %d\n", vif
->type
);
1168 priv
->ah
->opmode
= vif
->type
;
1170 /* Index starts from zero on the target */
1171 avp
->index
= hvif
.index
= priv
->nvifs
;
1172 hvif
.rtsthreshold
= cpu_to_be16(2304);
1173 WMI_CMD_BUF(WMI_VAP_CREATE_CMDID
, &hvif
);
1180 * We need a node in target to tx mgmt frames
1181 * before association.
1183 ret
= ath9k_htc_add_station(priv
, vif
, NULL
);
1187 ret
= ath9k_htc_update_cap_target(priv
);
1189 ath_print(common
, ATH_DBG_CONFIG
, "Failed to update"
1190 " capability in target \n");
1194 mutex_unlock(&priv
->mutex
);
1198 static void ath9k_htc_remove_interface(struct ieee80211_hw
*hw
,
1199 struct ieee80211_vif
*vif
)
1201 struct ath9k_htc_priv
*priv
= hw
->priv
;
1202 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
1203 struct ath9k_htc_vif
*avp
= (void *)vif
->drv_priv
;
1204 struct ath9k_htc_target_vif hvif
;
1208 ath_print(common
, ATH_DBG_CONFIG
, "Detach Interface\n");
1210 mutex_lock(&priv
->mutex
);
1212 memset(&hvif
, 0, sizeof(struct ath9k_htc_target_vif
));
1213 memcpy(&hvif
.myaddr
, vif
->addr
, ETH_ALEN
);
1214 hvif
.index
= avp
->index
;
1215 WMI_CMD_BUF(WMI_VAP_REMOVE_CMDID
, &hvif
);
1218 ath9k_htc_remove_station(priv
, vif
, NULL
);
1220 if (vif
->type
== NL80211_IFTYPE_ADHOC
) {
1221 spin_lock_bh(&priv
->beacon_lock
);
1223 dev_kfree_skb_any(priv
->beacon
);
1224 priv
->beacon
= NULL
;
1225 spin_unlock_bh(&priv
->beacon_lock
);
1230 mutex_unlock(&priv
->mutex
);
1233 static int ath9k_htc_config(struct ieee80211_hw
*hw
, u32 changed
)
1235 struct ath9k_htc_priv
*priv
= hw
->priv
;
1236 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
1237 struct ieee80211_conf
*conf
= &hw
->conf
;
1239 mutex_lock(&priv
->mutex
);
1241 if (changed
& IEEE80211_CONF_CHANGE_CHANNEL
) {
1242 struct ieee80211_channel
*curchan
= hw
->conf
.channel
;
1243 int pos
= curchan
->hw_value
;
1244 bool is_cw40
= false;
1246 ath_print(common
, ATH_DBG_CONFIG
, "Set channel: %d MHz\n",
1247 curchan
->center_freq
);
1249 if (check_rc_update(hw
, &is_cw40
))
1250 ath9k_htc_rc_update(priv
, is_cw40
);
1252 ath9k_cmn_update_ichannel(hw
, &priv
->ah
->channels
[pos
]);
1254 if (ath9k_htc_set_channel(priv
, hw
, &priv
->ah
->channels
[pos
]) < 0) {
1255 ath_print(common
, ATH_DBG_FATAL
,
1256 "Unable to set channel\n");
1257 mutex_unlock(&priv
->mutex
);
1263 if (changed
& IEEE80211_CONF_CHANGE_MONITOR
) {
1264 if (conf
->flags
& IEEE80211_CONF_MONITOR
) {
1265 if (ath9k_htc_add_monitor_interface(priv
))
1266 ath_print(common
, ATH_DBG_FATAL
,
1267 "Failed to set monitor mode\n");
1269 ath_print(common
, ATH_DBG_CONFIG
,
1270 "HW opmode set to Monitor mode\n");
1274 mutex_unlock(&priv
->mutex
);
1279 #define SUPPORTED_FILTERS \
1280 (FIF_PROMISC_IN_BSS | \
1285 FIF_BCN_PRBRESP_PROMISC | \
1288 static void ath9k_htc_configure_filter(struct ieee80211_hw
*hw
,
1289 unsigned int changed_flags
,
1290 unsigned int *total_flags
,
1293 struct ath9k_htc_priv
*priv
= hw
->priv
;
1296 mutex_lock(&priv
->mutex
);
1298 changed_flags
&= SUPPORTED_FILTERS
;
1299 *total_flags
&= SUPPORTED_FILTERS
;
1301 priv
->rxfilter
= *total_flags
;
1302 rfilt
= ath9k_htc_calcrxfilter(priv
);
1303 ath9k_hw_setrxfilter(priv
->ah
, rfilt
);
1305 ath_print(ath9k_hw_common(priv
->ah
), ATH_DBG_CONFIG
,
1306 "Set HW RX filter: 0x%x\n", rfilt
);
1308 mutex_unlock(&priv
->mutex
);
1311 static void ath9k_htc_sta_notify(struct ieee80211_hw
*hw
,
1312 struct ieee80211_vif
*vif
,
1313 enum sta_notify_cmd cmd
,
1314 struct ieee80211_sta
*sta
)
1316 struct ath9k_htc_priv
*priv
= hw
->priv
;
1320 case STA_NOTIFY_ADD
:
1321 ret
= ath9k_htc_add_station(priv
, vif
, sta
);
1323 ath9k_htc_init_rate(priv
, vif
, sta
);
1325 case STA_NOTIFY_REMOVE
:
1326 ath9k_htc_remove_station(priv
, vif
, sta
);
1333 static int ath9k_htc_conf_tx(struct ieee80211_hw
*hw
, u16 queue
,
1334 const struct ieee80211_tx_queue_params
*params
)
1336 struct ath9k_htc_priv
*priv
= hw
->priv
;
1337 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
1338 struct ath9k_tx_queue_info qi
;
1341 if (queue
>= WME_NUM_AC
)
1344 mutex_lock(&priv
->mutex
);
1346 memset(&qi
, 0, sizeof(struct ath9k_tx_queue_info
));
1348 qi
.tqi_aifs
= params
->aifs
;
1349 qi
.tqi_cwmin
= params
->cw_min
;
1350 qi
.tqi_cwmax
= params
->cw_max
;
1351 qi
.tqi_burstTime
= params
->txop
;
1353 qnum
= get_hw_qnum(queue
, priv
->hwq_map
);
1355 ath_print(common
, ATH_DBG_CONFIG
,
1356 "Configure tx [queue/hwq] [%d/%d], "
1357 "aifs: %d, cw_min: %d, cw_max: %d, txop: %d\n",
1358 queue
, qnum
, params
->aifs
, params
->cw_min
,
1359 params
->cw_max
, params
->txop
);
1361 ret
= ath_htc_txq_update(priv
, qnum
, &qi
);
1363 ath_print(common
, ATH_DBG_FATAL
, "TXQ Update failed\n");
1365 mutex_unlock(&priv
->mutex
);
1370 static int ath9k_htc_set_key(struct ieee80211_hw
*hw
,
1371 enum set_key_cmd cmd
,
1372 struct ieee80211_vif
*vif
,
1373 struct ieee80211_sta
*sta
,
1374 struct ieee80211_key_conf
*key
)
1376 struct ath9k_htc_priv
*priv
= hw
->priv
;
1377 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
1380 if (htc_modparam_nohwcrypt
)
1383 mutex_lock(&priv
->mutex
);
1384 ath_print(common
, ATH_DBG_CONFIG
, "Set HW Key\n");
1388 ret
= ath9k_cmn_key_config(common
, vif
, sta
, key
);
1390 key
->hw_key_idx
= ret
;
1391 /* push IV and Michael MIC generation to stack */
1392 key
->flags
|= IEEE80211_KEY_FLAG_GENERATE_IV
;
1393 if (key
->alg
== ALG_TKIP
)
1394 key
->flags
|= IEEE80211_KEY_FLAG_GENERATE_MMIC
;
1395 if (priv
->ah
->sw_mgmt_crypto
&& key
->alg
== ALG_CCMP
)
1396 key
->flags
|= IEEE80211_KEY_FLAG_SW_MGMT
;
1401 ath9k_cmn_key_delete(common
, key
);
1407 mutex_unlock(&priv
->mutex
);
1412 static void ath9k_htc_bss_info_changed(struct ieee80211_hw
*hw
,
1413 struct ieee80211_vif
*vif
,
1414 struct ieee80211_bss_conf
*bss_conf
,
1417 struct ath9k_htc_priv
*priv
= hw
->priv
;
1418 struct ath_hw
*ah
= priv
->ah
;
1419 struct ath_common
*common
= ath9k_hw_common(ah
);
1421 mutex_lock(&priv
->mutex
);
1423 if (changed
& BSS_CHANGED_ASSOC
) {
1424 common
->curaid
= bss_conf
->assoc
?
1426 ath_print(common
, ATH_DBG_CONFIG
, "BSS Changed ASSOC %d\n",
1429 if (bss_conf
->assoc
) {
1430 priv
->op_flags
|= OP_ASSOCIATED
;
1431 ath_start_ani(priv
);
1433 priv
->op_flags
&= ~OP_ASSOCIATED
;
1434 cancel_delayed_work_sync(&priv
->ath9k_ani_work
);
1438 if (changed
& BSS_CHANGED_BSSID
) {
1440 memcpy(common
->curbssid
, bss_conf
->bssid
, ETH_ALEN
);
1441 ath9k_hw_write_associd(ah
);
1443 ath_print(common
, ATH_DBG_CONFIG
,
1444 "BSSID: %pM aid: 0x%x\n",
1445 common
->curbssid
, common
->curaid
);
1448 if ((changed
& BSS_CHANGED_BEACON_INT
) ||
1449 (changed
& BSS_CHANGED_BEACON
) ||
1450 ((changed
& BSS_CHANGED_BEACON_ENABLED
) &&
1451 bss_conf
->enable_beacon
)) {
1452 priv
->op_flags
|= OP_ENABLE_BEACON
;
1453 ath9k_htc_beacon_config(priv
, vif
, bss_conf
);
1456 if (changed
& BSS_CHANGED_BEACON
)
1457 ath9k_htc_beacon_update(priv
, vif
);
1459 if ((changed
& BSS_CHANGED_BEACON_ENABLED
) &&
1460 !bss_conf
->enable_beacon
) {
1461 priv
->op_flags
&= ~OP_ENABLE_BEACON
;
1462 ath9k_htc_beacon_config(priv
, vif
, bss_conf
);
1465 if (changed
& BSS_CHANGED_ERP_PREAMBLE
) {
1466 ath_print(common
, ATH_DBG_CONFIG
, "BSS Changed PREAMBLE %d\n",
1467 bss_conf
->use_short_preamble
);
1468 if (bss_conf
->use_short_preamble
)
1469 priv
->op_flags
|= OP_PREAMBLE_SHORT
;
1471 priv
->op_flags
&= ~OP_PREAMBLE_SHORT
;
1474 if (changed
& BSS_CHANGED_ERP_CTS_PROT
) {
1475 ath_print(common
, ATH_DBG_CONFIG
, "BSS Changed CTS PROT %d\n",
1476 bss_conf
->use_cts_prot
);
1477 if (bss_conf
->use_cts_prot
&&
1478 hw
->conf
.channel
->band
!= IEEE80211_BAND_5GHZ
)
1479 priv
->op_flags
|= OP_PROTECT_ENABLE
;
1481 priv
->op_flags
&= ~OP_PROTECT_ENABLE
;
1484 if (changed
& BSS_CHANGED_ERP_SLOT
) {
1485 if (bss_conf
->use_short_slot
)
1490 ath9k_hw_init_global_settings(ah
);
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 tsf
= ath9k_hw_gettsf64(priv
->ah
);
1503 mutex_unlock(&priv
->mutex
);
1508 static void ath9k_htc_set_tsf(struct ieee80211_hw
*hw
, u64 tsf
)
1510 struct ath9k_htc_priv
*priv
= hw
->priv
;
1512 mutex_lock(&priv
->mutex
);
1513 ath9k_hw_settsf64(priv
->ah
, tsf
);
1514 mutex_unlock(&priv
->mutex
);
1517 static void ath9k_htc_reset_tsf(struct ieee80211_hw
*hw
)
1519 struct ath9k_htc_priv
*priv
= hw
->priv
;
1521 mutex_lock(&priv
->mutex
);
1522 ath9k_hw_reset_tsf(priv
->ah
);
1523 mutex_unlock(&priv
->mutex
);
1526 static int ath9k_htc_ampdu_action(struct ieee80211_hw
*hw
,
1527 struct ieee80211_vif
*vif
,
1528 enum ieee80211_ampdu_mlme_action action
,
1529 struct ieee80211_sta
*sta
,
1532 struct ath9k_htc_priv
*priv
= hw
->priv
;
1533 struct ath9k_htc_aggr_work
*work
= &priv
->aggr_work
;
1534 struct ath9k_htc_sta
*ista
;
1537 case IEEE80211_AMPDU_RX_START
:
1539 case IEEE80211_AMPDU_RX_STOP
:
1541 case IEEE80211_AMPDU_TX_START
:
1542 case IEEE80211_AMPDU_TX_STOP
:
1543 if (!(priv
->op_flags
& OP_TXAGGR
))
1545 memcpy(work
->sta_addr
, sta
->addr
, ETH_ALEN
);
1548 work
->action
= action
;
1550 ieee80211_queue_delayed_work(hw
, &priv
->ath9k_aggr_work
, 0);
1552 case IEEE80211_AMPDU_TX_OPERATIONAL
:
1553 ista
= (struct ath9k_htc_sta
*) sta
->drv_priv
;
1554 ista
->tid_state
[tid
] = AGGR_OPERATIONAL
;
1557 ath_print(ath9k_hw_common(priv
->ah
), ATH_DBG_FATAL
,
1558 "Unknown AMPDU action\n");
1564 static void ath9k_htc_sw_scan_start(struct ieee80211_hw
*hw
)
1566 struct ath9k_htc_priv
*priv
= hw
->priv
;
1568 mutex_lock(&priv
->mutex
);
1569 spin_lock_bh(&priv
->beacon_lock
);
1570 priv
->op_flags
|= OP_SCANNING
;
1571 spin_unlock_bh(&priv
->beacon_lock
);
1572 cancel_delayed_work_sync(&priv
->ath9k_ani_work
);
1573 mutex_unlock(&priv
->mutex
);
1576 static void ath9k_htc_sw_scan_complete(struct ieee80211_hw
*hw
)
1578 struct ath9k_htc_priv
*priv
= hw
->priv
;
1580 mutex_lock(&priv
->mutex
);
1581 spin_lock_bh(&priv
->beacon_lock
);
1582 priv
->op_flags
&= ~OP_SCANNING
;
1583 spin_unlock_bh(&priv
->beacon_lock
);
1584 priv
->op_flags
|= OP_FULL_RESET
;
1585 ath_start_ani(priv
);
1586 mutex_unlock(&priv
->mutex
);
1589 static int ath9k_htc_set_rts_threshold(struct ieee80211_hw
*hw
, u32 value
)
1594 static void ath9k_htc_set_coverage_class(struct ieee80211_hw
*hw
,
1597 struct ath9k_htc_priv
*priv
= hw
->priv
;
1599 mutex_lock(&priv
->mutex
);
1600 priv
->ah
->coverage_class
= coverage_class
;
1601 ath9k_hw_init_global_settings(priv
->ah
);
1602 mutex_unlock(&priv
->mutex
);
1605 struct ieee80211_ops ath9k_htc_ops
= {
1607 .start
= ath9k_htc_start
,
1608 .stop
= ath9k_htc_stop
,
1609 .add_interface
= ath9k_htc_add_interface
,
1610 .remove_interface
= ath9k_htc_remove_interface
,
1611 .config
= ath9k_htc_config
,
1612 .configure_filter
= ath9k_htc_configure_filter
,
1613 .sta_notify
= ath9k_htc_sta_notify
,
1614 .conf_tx
= ath9k_htc_conf_tx
,
1615 .bss_info_changed
= ath9k_htc_bss_info_changed
,
1616 .set_key
= ath9k_htc_set_key
,
1617 .get_tsf
= ath9k_htc_get_tsf
,
1618 .set_tsf
= ath9k_htc_set_tsf
,
1619 .reset_tsf
= ath9k_htc_reset_tsf
,
1620 .ampdu_action
= ath9k_htc_ampdu_action
,
1621 .sw_scan_start
= ath9k_htc_sw_scan_start
,
1622 .sw_scan_complete
= ath9k_htc_sw_scan_complete
,
1623 .set_rts_threshold
= ath9k_htc_set_rts_threshold
,
1624 .rfkill_poll
= ath9k_htc_rfkill_poll_state
,
1625 .set_coverage_class
= ath9k_htc_set_coverage_class
,