2 * Copyright (c) 2010 Atheros Communications Inc.
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 #ifdef CONFIG_ATH9K_HTC_DEBUGFS
20 static struct dentry
*ath9k_debugfs_root
;
27 static void ath_update_txpow(struct ath9k_htc_priv
*priv
)
29 struct ath_hw
*ah
= priv
->ah
;
32 if (priv
->curtxpow
!= priv
->txpowlimit
) {
33 ath9k_hw_set_txpowerlimit(ah
, priv
->txpowlimit
);
34 /* read back in case value is clamped */
35 ath9k_hw_getcapability(ah
, ATH9K_CAP_TXPOW
, 1, &txpow
);
36 priv
->curtxpow
= txpow
;
40 /* HACK Alert: Use 11NG for 2.4, use 11NA for 5 */
41 static enum htc_phymode
ath9k_htc_get_curmode(struct ath9k_htc_priv
*priv
,
42 struct ath9k_channel
*ichan
)
44 enum htc_phymode mode
;
48 switch (ichan
->chanmode
) {
51 case CHANNEL_G_HT40PLUS
:
52 case CHANNEL_G_HT40MINUS
:
57 case CHANNEL_A_HT40PLUS
:
58 case CHANNEL_A_HT40MINUS
:
68 static bool ath9k_htc_setpower(struct ath9k_htc_priv
*priv
,
69 enum ath9k_power_mode mode
)
73 mutex_lock(&priv
->htc_pm_lock
);
74 ret
= ath9k_hw_setpower(priv
->ah
, mode
);
75 mutex_unlock(&priv
->htc_pm_lock
);
80 void ath9k_htc_ps_wakeup(struct ath9k_htc_priv
*priv
)
82 mutex_lock(&priv
->htc_pm_lock
);
83 if (++priv
->ps_usecount
!= 1)
85 ath9k_hw_setpower(priv
->ah
, ATH9K_PM_AWAKE
);
88 mutex_unlock(&priv
->htc_pm_lock
);
91 void ath9k_htc_ps_restore(struct ath9k_htc_priv
*priv
)
93 mutex_lock(&priv
->htc_pm_lock
);
94 if (--priv
->ps_usecount
!= 0)
98 ath9k_hw_setpower(priv
->ah
, ATH9K_PM_FULL_SLEEP
);
99 else if (priv
->ps_enabled
)
100 ath9k_hw_setpower(priv
->ah
, ATH9K_PM_NETWORK_SLEEP
);
103 mutex_unlock(&priv
->htc_pm_lock
);
106 void ath9k_ps_work(struct work_struct
*work
)
108 struct ath9k_htc_priv
*priv
=
109 container_of(work
, struct ath9k_htc_priv
,
111 ath9k_htc_setpower(priv
, ATH9K_PM_AWAKE
);
113 /* The chip wakes up after receiving the first beacon
114 while network sleep is enabled. For the driver to
115 be in sync with the hw, set the chip to awake and
116 only then set it to sleep.
118 ath9k_htc_setpower(priv
, ATH9K_PM_NETWORK_SLEEP
);
121 static int ath9k_htc_set_channel(struct ath9k_htc_priv
*priv
,
122 struct ieee80211_hw
*hw
,
123 struct ath9k_channel
*hchan
)
125 struct ath_hw
*ah
= priv
->ah
;
126 struct ath_common
*common
= ath9k_hw_common(ah
);
127 struct ieee80211_conf
*conf
= &common
->hw
->conf
;
129 struct ieee80211_channel
*channel
= hw
->conf
.channel
;
130 enum htc_phymode mode
;
135 if (priv
->op_flags
& OP_INVALID
)
138 if (priv
->op_flags
& OP_FULL_RESET
)
141 /* Fiddle around with fastcc later on, for now just use full reset */
143 ath9k_htc_ps_wakeup(priv
);
145 WMI_CMD(WMI_DISABLE_INTR_CMDID
);
146 WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID
);
147 WMI_CMD(WMI_STOP_RECV_CMDID
);
149 ath_print(common
, ATH_DBG_CONFIG
,
150 "(%u MHz) -> (%u MHz), HT: %d, HT40: %d\n",
151 priv
->ah
->curchan
->channel
,
152 channel
->center_freq
, conf_is_ht(conf
), conf_is_ht40(conf
));
154 ret
= ath9k_hw_reset(ah
, hchan
, fastcc
);
156 ath_print(common
, ATH_DBG_FATAL
,
157 "Unable to reset channel (%u Mhz) "
158 "reset status %d\n", channel
->center_freq
, ret
);
162 ath_update_txpow(priv
);
164 WMI_CMD(WMI_START_RECV_CMDID
);
168 ath9k_host_rx_init(priv
);
170 mode
= ath9k_htc_get_curmode(priv
, hchan
);
171 htc_mode
= cpu_to_be16(mode
);
172 WMI_CMD_BUF(WMI_SET_MODE_CMDID
, &htc_mode
);
176 WMI_CMD(WMI_ENABLE_INTR_CMDID
);
180 htc_start(priv
->htc
);
182 priv
->op_flags
&= ~OP_FULL_RESET
;
184 ath9k_htc_ps_restore(priv
);
188 static int ath9k_htc_add_monitor_interface(struct ath9k_htc_priv
*priv
)
190 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
191 struct ath9k_htc_target_vif hvif
;
198 memset(&hvif
, 0, sizeof(struct ath9k_htc_target_vif
));
199 memcpy(&hvif
.myaddr
, common
->macaddr
, ETH_ALEN
);
201 hvif
.opmode
= cpu_to_be32(HTC_M_MONITOR
);
202 priv
->ah
->opmode
= NL80211_IFTYPE_MONITOR
;
203 hvif
.index
= priv
->nvifs
;
205 WMI_CMD_BUF(WMI_VAP_CREATE_CMDID
, &hvif
);
213 static int ath9k_htc_remove_monitor_interface(struct ath9k_htc_priv
*priv
)
215 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
216 struct ath9k_htc_target_vif hvif
;
220 memset(&hvif
, 0, sizeof(struct ath9k_htc_target_vif
));
221 memcpy(&hvif
.myaddr
, common
->macaddr
, ETH_ALEN
);
222 hvif
.index
= 0; /* Should do for now */
223 WMI_CMD_BUF(WMI_VAP_REMOVE_CMDID
, &hvif
);
229 static int ath9k_htc_add_station(struct ath9k_htc_priv
*priv
,
230 struct ieee80211_vif
*vif
,
231 struct ieee80211_sta
*sta
)
233 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
234 struct ath9k_htc_target_sta tsta
;
235 struct ath9k_htc_vif
*avp
= (struct ath9k_htc_vif
*) vif
->drv_priv
;
236 struct ath9k_htc_sta
*ista
;
240 if (priv
->nstations
>= ATH9K_HTC_MAX_STA
)
243 memset(&tsta
, 0, sizeof(struct ath9k_htc_target_sta
));
246 ista
= (struct ath9k_htc_sta
*) sta
->drv_priv
;
247 memcpy(&tsta
.macaddr
, sta
->addr
, ETH_ALEN
);
248 memcpy(&tsta
.bssid
, common
->curbssid
, ETH_ALEN
);
249 tsta
.associd
= common
->curaid
;
252 ista
->index
= priv
->nstations
;
254 memcpy(&tsta
.macaddr
, vif
->addr
, ETH_ALEN
);
258 tsta
.sta_index
= priv
->nstations
;
259 tsta
.vif_index
= avp
->index
;
260 tsta
.maxampdu
= 0xffff;
261 if (sta
&& sta
->ht_cap
.ht_supported
)
262 tsta
.flags
= cpu_to_be16(ATH_HTC_STA_HT
);
264 WMI_CMD_BUF(WMI_NODE_CREATE_CMDID
, &tsta
);
267 ath_print(common
, ATH_DBG_FATAL
,
268 "Unable to add station entry for: %pM\n", sta
->addr
);
273 ath_print(common
, ATH_DBG_CONFIG
,
274 "Added a station entry for: %pM (idx: %d)\n",
275 sta
->addr
, tsta
.sta_index
);
281 static int ath9k_htc_remove_station(struct ath9k_htc_priv
*priv
,
282 struct ieee80211_vif
*vif
,
283 struct ieee80211_sta
*sta
)
285 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
286 struct ath9k_htc_sta
*ista
;
291 ista
= (struct ath9k_htc_sta
*) sta
->drv_priv
;
292 sta_idx
= ista
->index
;
297 WMI_CMD_BUF(WMI_NODE_REMOVE_CMDID
, &sta_idx
);
300 ath_print(common
, ATH_DBG_FATAL
,
301 "Unable to remove station entry for: %pM\n",
307 ath_print(common
, ATH_DBG_CONFIG
,
308 "Removed a station entry for: %pM (idx: %d)\n",
315 static int ath9k_htc_update_cap_target(struct ath9k_htc_priv
*priv
)
317 struct ath9k_htc_cap_target tcap
;
321 memset(&tcap
, 0, sizeof(struct ath9k_htc_cap_target
));
323 /* FIXME: Values are hardcoded */
324 tcap
.flags
= 0x240c40;
325 tcap
.flags_ext
= 0x80601000;
326 tcap
.ampdu_limit
= 0xffff0000;
327 tcap
.ampdu_subframes
= 20;
328 tcap
.tx_chainmask_legacy
= 1;
330 tcap
.tx_chainmask
= 1;
332 WMI_CMD_BUF(WMI_TARGET_IC_UPDATE_CMDID
, &tcap
);
337 static int ath9k_htc_init_rate(struct ath9k_htc_priv
*priv
,
338 struct ieee80211_vif
*vif
,
339 struct ieee80211_sta
*sta
)
341 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
342 struct ath9k_htc_sta
*ista
= (struct ath9k_htc_sta
*) sta
->drv_priv
;
343 struct ieee80211_supported_band
*sband
;
344 struct ath9k_htc_target_rate trate
;
349 memset(&trate
, 0, sizeof(trate
));
351 /* Only 2GHz is supported */
352 sband
= priv
->hw
->wiphy
->bands
[IEEE80211_BAND_2GHZ
];
354 for (i
= 0, j
= 0; i
< sband
->n_bitrates
; i
++) {
355 if (sta
->supp_rates
[sband
->band
] & BIT(i
)) {
356 priv
->tgt_rate
.rates
.legacy_rates
.rs_rates
[j
]
357 = (sband
->bitrates
[i
].bitrate
* 2) / 10;
361 priv
->tgt_rate
.rates
.legacy_rates
.rs_nrates
= j
;
363 if (sta
->ht_cap
.ht_supported
) {
364 for (i
= 0, j
= 0; i
< 77; i
++) {
365 if (sta
->ht_cap
.mcs
.rx_mask
[i
/8] & (1<<(i
%8)))
366 priv
->tgt_rate
.rates
.ht_rates
.rs_rates
[j
++] = i
;
367 if (j
== ATH_HTC_RATE_MAX
)
370 priv
->tgt_rate
.rates
.ht_rates
.rs_nrates
= j
;
372 caps
= WLAN_RC_HT_FLAG
;
373 if (sta
->ht_cap
.cap
& IEEE80211_HT_CAP_SUP_WIDTH_20_40
)
374 caps
|= WLAN_RC_40_FLAG
;
375 if (sta
->ht_cap
.cap
& IEEE80211_HT_CAP_SGI_40
)
376 caps
|= WLAN_RC_SGI_FLAG
;
380 priv
->tgt_rate
.sta_index
= ista
->index
;
381 priv
->tgt_rate
.isnew
= 1;
382 trate
= priv
->tgt_rate
;
383 priv
->tgt_rate
.capflags
= cpu_to_be32(caps
);
384 trate
.capflags
= cpu_to_be32(caps
);
386 WMI_CMD_BUF(WMI_RC_RATE_UPDATE_CMDID
, &trate
);
388 ath_print(common
, ATH_DBG_FATAL
,
389 "Unable to initialize Rate information on target\n");
393 ath_print(common
, ATH_DBG_CONFIG
,
394 "Updated target STA: %pM (caps: 0x%x)\n", sta
->addr
, caps
);
398 static bool check_rc_update(struct ieee80211_hw
*hw
, bool *cw40
)
400 struct ath9k_htc_priv
*priv
= hw
->priv
;
401 struct ieee80211_conf
*conf
= &hw
->conf
;
403 if (!conf_is_ht(conf
))
406 if (!(priv
->op_flags
& OP_ASSOCIATED
) ||
407 (priv
->op_flags
& OP_SCANNING
))
410 if (conf_is_ht40(conf
)) {
411 if (priv
->ah
->curchan
->chanmode
&
412 (CHANNEL_HT40PLUS
| CHANNEL_HT40MINUS
)) {
419 if (priv
->ah
->curchan
->chanmode
& CHANNEL_HT20
)
426 static void ath9k_htc_rc_update(struct ath9k_htc_priv
*priv
, bool is_cw40
)
428 struct ath9k_htc_target_rate trate
;
429 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
431 u32 caps
= be32_to_cpu(priv
->tgt_rate
.capflags
);
434 memset(&trate
, 0, sizeof(trate
));
436 trate
= priv
->tgt_rate
;
439 caps
|= WLAN_RC_40_FLAG
;
441 caps
&= ~WLAN_RC_40_FLAG
;
443 priv
->tgt_rate
.capflags
= cpu_to_be32(caps
);
444 trate
.capflags
= cpu_to_be32(caps
);
446 WMI_CMD_BUF(WMI_RC_RATE_UPDATE_CMDID
, &trate
);
448 ath_print(common
, ATH_DBG_FATAL
,
449 "Unable to update Rate information on target\n");
453 ath_print(common
, ATH_DBG_CONFIG
, "Rate control updated with "
454 "caps:0x%x on target\n", priv
->tgt_rate
.capflags
);
457 static int ath9k_htc_aggr_oper(struct ath9k_htc_priv
*priv
,
458 struct ieee80211_vif
*vif
,
459 u8
*sta_addr
, u8 tid
, bool oper
)
461 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
462 struct ath9k_htc_target_aggr aggr
;
463 struct ieee80211_sta
*sta
= NULL
;
464 struct ath9k_htc_sta
*ista
= (struct ath9k_htc_sta
*) sta
->drv_priv
;
468 if (tid
> ATH9K_HTC_MAX_TID
)
471 memset(&aggr
, 0, sizeof(struct ath9k_htc_target_aggr
));
475 /* Check if we are able to retrieve the station */
476 sta
= ieee80211_find_sta(vif
, sta_addr
);
482 ista
= (struct ath9k_htc_sta
*) sta
->drv_priv
;
485 ista
->tid_state
[tid
] = AGGR_START
;
487 ista
->tid_state
[tid
] = AGGR_STOP
;
489 aggr
.sta_index
= ista
->index
;
494 aggr
.aggr_enable
= oper
;
496 WMI_CMD_BUF(WMI_TX_AGGR_ENABLE_CMDID
, &aggr
);
498 ath_print(common
, ATH_DBG_CONFIG
,
499 "Unable to %s TX aggregation for (%pM, %d)\n",
500 (oper
) ? "start" : "stop", sta
->addr
, tid
);
502 ath_print(common
, ATH_DBG_CONFIG
,
503 "%s aggregation for (%pM, %d)\n",
504 (oper
) ? "Starting" : "Stopping", sta
->addr
, tid
);
509 void ath9k_htc_aggr_work(struct work_struct
*work
)
512 struct ath9k_htc_priv
*priv
=
513 container_of(work
, struct ath9k_htc_priv
,
514 ath9k_aggr_work
.work
);
515 struct ath9k_htc_aggr_work
*wk
= &priv
->aggr_work
;
517 mutex_lock(&wk
->mutex
);
519 switch (wk
->action
) {
520 case IEEE80211_AMPDU_TX_START
:
521 ret
= ath9k_htc_aggr_oper(priv
, wk
->vif
, wk
->sta_addr
,
524 ieee80211_start_tx_ba_cb(wk
->vif
, wk
->sta_addr
,
527 case IEEE80211_AMPDU_TX_STOP
:
528 ath9k_htc_aggr_oper(priv
, wk
->vif
, wk
->sta_addr
,
530 ieee80211_stop_tx_ba_cb(wk
->vif
, wk
->sta_addr
, wk
->tid
);
533 ath_print(ath9k_hw_common(priv
->ah
), ATH_DBG_FATAL
,
534 "Unknown AMPDU action\n");
537 mutex_unlock(&wk
->mutex
);
544 #ifdef CONFIG_ATH9K_HTC_DEBUGFS
546 static int ath9k_debugfs_open(struct inode
*inode
, struct file
*file
)
548 file
->private_data
= inode
->i_private
;
552 static ssize_t
read_file_tgt_stats(struct file
*file
, char __user
*user_buf
,
553 size_t count
, loff_t
*ppos
)
555 struct ath9k_htc_priv
*priv
=
556 (struct ath9k_htc_priv
*) file
->private_data
;
557 struct ath9k_htc_target_stats cmd_rsp
;
559 unsigned int len
= 0;
562 memset(&cmd_rsp
, 0, sizeof(cmd_rsp
));
564 WMI_CMD(WMI_TGT_STATS_CMDID
);
569 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
570 "%19s : %10u\n", "TX Short Retries",
571 be32_to_cpu(cmd_rsp
.tx_shortretry
));
572 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
573 "%19s : %10u\n", "TX Long Retries",
574 be32_to_cpu(cmd_rsp
.tx_longretry
));
575 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
576 "%19s : %10u\n", "TX Xretries",
577 be32_to_cpu(cmd_rsp
.tx_xretries
));
578 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
579 "%19s : %10u\n", "TX Unaggr. Xretries",
580 be32_to_cpu(cmd_rsp
.ht_txunaggr_xretry
));
581 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
582 "%19s : %10u\n", "TX Xretries (HT)",
583 be32_to_cpu(cmd_rsp
.ht_tx_xretries
));
584 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
585 "%19s : %10u\n", "TX Rate", priv
->debug
.txrate
);
587 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, len
);
590 static const struct file_operations fops_tgt_stats
= {
591 .read
= read_file_tgt_stats
,
592 .open
= ath9k_debugfs_open
,
596 static ssize_t
read_file_xmit(struct file
*file
, char __user
*user_buf
,
597 size_t count
, loff_t
*ppos
)
599 struct ath9k_htc_priv
*priv
=
600 (struct ath9k_htc_priv
*) file
->private_data
;
602 unsigned int len
= 0;
604 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
605 "%20s : %10u\n", "Buffers queued",
606 priv
->debug
.tx_stats
.buf_queued
);
607 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
608 "%20s : %10u\n", "Buffers completed",
609 priv
->debug
.tx_stats
.buf_completed
);
610 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
611 "%20s : %10u\n", "SKBs queued",
612 priv
->debug
.tx_stats
.skb_queued
);
613 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
614 "%20s : %10u\n", "SKBs completed",
615 priv
->debug
.tx_stats
.skb_completed
);
616 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
617 "%20s : %10u\n", "SKBs dropped",
618 priv
->debug
.tx_stats
.skb_dropped
);
620 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, len
);
623 static const struct file_operations fops_xmit
= {
624 .read
= read_file_xmit
,
625 .open
= ath9k_debugfs_open
,
629 static ssize_t
read_file_recv(struct file
*file
, char __user
*user_buf
,
630 size_t count
, loff_t
*ppos
)
632 struct ath9k_htc_priv
*priv
=
633 (struct ath9k_htc_priv
*) file
->private_data
;
635 unsigned int len
= 0;
637 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
638 "%20s : %10u\n", "SKBs allocated",
639 priv
->debug
.rx_stats
.skb_allocated
);
640 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
641 "%20s : %10u\n", "SKBs completed",
642 priv
->debug
.rx_stats
.skb_completed
);
643 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
644 "%20s : %10u\n", "SKBs Dropped",
645 priv
->debug
.rx_stats
.skb_dropped
);
647 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, len
);
650 static const struct file_operations fops_recv
= {
651 .read
= read_file_recv
,
652 .open
= ath9k_debugfs_open
,
656 int ath9k_htc_init_debug(struct ath_hw
*ah
)
658 struct ath_common
*common
= ath9k_hw_common(ah
);
659 struct ath9k_htc_priv
*priv
= (struct ath9k_htc_priv
*) common
->priv
;
661 if (!ath9k_debugfs_root
)
664 priv
->debug
.debugfs_phy
= debugfs_create_dir(wiphy_name(priv
->hw
->wiphy
),
666 if (!priv
->debug
.debugfs_phy
)
669 priv
->debug
.debugfs_tgt_stats
= debugfs_create_file("tgt_stats", S_IRUSR
,
670 priv
->debug
.debugfs_phy
,
671 priv
, &fops_tgt_stats
);
672 if (!priv
->debug
.debugfs_tgt_stats
)
676 priv
->debug
.debugfs_xmit
= debugfs_create_file("xmit", S_IRUSR
,
677 priv
->debug
.debugfs_phy
,
679 if (!priv
->debug
.debugfs_xmit
)
682 priv
->debug
.debugfs_recv
= debugfs_create_file("recv", S_IRUSR
,
683 priv
->debug
.debugfs_phy
,
685 if (!priv
->debug
.debugfs_recv
)
691 ath9k_htc_exit_debug(ah
);
695 void ath9k_htc_exit_debug(struct ath_hw
*ah
)
697 struct ath_common
*common
= ath9k_hw_common(ah
);
698 struct ath9k_htc_priv
*priv
= (struct ath9k_htc_priv
*) common
->priv
;
700 debugfs_remove(priv
->debug
.debugfs_recv
);
701 debugfs_remove(priv
->debug
.debugfs_xmit
);
702 debugfs_remove(priv
->debug
.debugfs_tgt_stats
);
703 debugfs_remove(priv
->debug
.debugfs_phy
);
706 int ath9k_htc_debug_create_root(void)
708 ath9k_debugfs_root
= debugfs_create_dir(KBUILD_MODNAME
, NULL
);
709 if (!ath9k_debugfs_root
)
715 void ath9k_htc_debug_remove_root(void)
717 debugfs_remove(ath9k_debugfs_root
);
718 ath9k_debugfs_root
= NULL
;
721 #endif /* CONFIG_ATH9K_HTC_DEBUGFS */
727 static void ath_start_ani(struct ath9k_htc_priv
*priv
)
729 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
730 unsigned long timestamp
= jiffies_to_msecs(jiffies
);
732 common
->ani
.longcal_timer
= timestamp
;
733 common
->ani
.shortcal_timer
= timestamp
;
734 common
->ani
.checkani_timer
= timestamp
;
736 ieee80211_queue_delayed_work(common
->hw
, &priv
->ath9k_ani_work
,
737 msecs_to_jiffies(ATH_ANI_POLLINTERVAL
));
740 void ath9k_ani_work(struct work_struct
*work
)
742 struct ath9k_htc_priv
*priv
=
743 container_of(work
, struct ath9k_htc_priv
,
744 ath9k_ani_work
.work
);
745 struct ath_hw
*ah
= priv
->ah
;
746 struct ath_common
*common
= ath9k_hw_common(ah
);
747 bool longcal
= false;
748 bool shortcal
= false;
749 bool aniflag
= false;
750 unsigned int timestamp
= jiffies_to_msecs(jiffies
);
751 u32 cal_interval
, short_cal_interval
;
753 short_cal_interval
= ATH_STA_SHORT_CALINTERVAL
;
755 /* Only calibrate if awake */
756 if (ah
->power_mode
!= ATH9K_PM_AWAKE
)
759 /* Long calibration runs independently of short calibration. */
760 if ((timestamp
- common
->ani
.longcal_timer
) >= ATH_LONG_CALINTERVAL
) {
762 ath_print(common
, ATH_DBG_ANI
, "longcal @%lu\n", jiffies
);
763 common
->ani
.longcal_timer
= timestamp
;
766 /* Short calibration applies only while caldone is false */
767 if (!common
->ani
.caldone
) {
768 if ((timestamp
- common
->ani
.shortcal_timer
) >=
769 short_cal_interval
) {
771 ath_print(common
, ATH_DBG_ANI
,
772 "shortcal @%lu\n", jiffies
);
773 common
->ani
.shortcal_timer
= timestamp
;
774 common
->ani
.resetcal_timer
= timestamp
;
777 if ((timestamp
- common
->ani
.resetcal_timer
) >=
778 ATH_RESTART_CALINTERVAL
) {
779 common
->ani
.caldone
= ath9k_hw_reset_calvalid(ah
);
780 if (common
->ani
.caldone
)
781 common
->ani
.resetcal_timer
= timestamp
;
785 /* Verify whether we must check ANI */
786 if ((timestamp
- common
->ani
.checkani_timer
) >= ATH_ANI_POLLINTERVAL
) {
788 common
->ani
.checkani_timer
= timestamp
;
791 /* Skip all processing if there's nothing to do. */
792 if (longcal
|| shortcal
|| aniflag
) {
794 ath9k_htc_ps_wakeup(priv
);
796 /* Call ANI routine if necessary */
798 ath9k_hw_ani_monitor(ah
, ah
->curchan
);
800 /* Perform calibration if necessary */
801 if (longcal
|| shortcal
) {
802 common
->ani
.caldone
=
803 ath9k_hw_calibrate(ah
, ah
->curchan
,
804 common
->rx_chainmask
,
808 common
->ani
.noise_floor
=
809 ath9k_hw_getchan_noise(ah
, ah
->curchan
);
811 ath_print(common
, ATH_DBG_ANI
,
812 " calibrate chan %u/%x nf: %d\n",
813 ah
->curchan
->channel
,
814 ah
->curchan
->channelFlags
,
815 common
->ani
.noise_floor
);
818 ath9k_htc_ps_restore(priv
);
823 * Set timer interval based on previous results.
824 * The interval must be the shortest necessary to satisfy ANI,
825 * short calibration and long calibration.
827 cal_interval
= ATH_LONG_CALINTERVAL
;
828 if (priv
->ah
->config
.enable_ani
)
829 cal_interval
= min(cal_interval
, (u32
)ATH_ANI_POLLINTERVAL
);
830 if (!common
->ani
.caldone
)
831 cal_interval
= min(cal_interval
, (u32
)short_cal_interval
);
833 ieee80211_queue_delayed_work(common
->hw
, &priv
->ath9k_ani_work
,
834 msecs_to_jiffies(cal_interval
));
841 static void ath9k_led_blink_work(struct work_struct
*work
)
843 struct ath9k_htc_priv
*priv
= container_of(work
, struct ath9k_htc_priv
,
844 ath9k_led_blink_work
.work
);
846 if (!(priv
->op_flags
& OP_LED_ASSOCIATED
))
849 if ((priv
->led_on_duration
== ATH_LED_ON_DURATION_IDLE
) ||
850 (priv
->led_off_duration
== ATH_LED_OFF_DURATION_IDLE
))
851 ath9k_hw_set_gpio(priv
->ah
, priv
->ah
->led_pin
, 0);
853 ath9k_hw_set_gpio(priv
->ah
, priv
->ah
->led_pin
,
854 (priv
->op_flags
& OP_LED_ON
) ? 1 : 0);
856 ieee80211_queue_delayed_work(priv
->hw
,
857 &priv
->ath9k_led_blink_work
,
858 (priv
->op_flags
& OP_LED_ON
) ?
859 msecs_to_jiffies(priv
->led_off_duration
) :
860 msecs_to_jiffies(priv
->led_on_duration
));
862 priv
->led_on_duration
= priv
->led_on_cnt
?
863 max((ATH_LED_ON_DURATION_IDLE
- priv
->led_on_cnt
), 25) :
864 ATH_LED_ON_DURATION_IDLE
;
865 priv
->led_off_duration
= priv
->led_off_cnt
?
866 max((ATH_LED_OFF_DURATION_IDLE
- priv
->led_off_cnt
), 10) :
867 ATH_LED_OFF_DURATION_IDLE
;
868 priv
->led_on_cnt
= priv
->led_off_cnt
= 0;
870 if (priv
->op_flags
& OP_LED_ON
)
871 priv
->op_flags
&= ~OP_LED_ON
;
873 priv
->op_flags
|= OP_LED_ON
;
876 static void ath9k_led_brightness_work(struct work_struct
*work
)
878 struct ath_led
*led
= container_of(work
, struct ath_led
,
879 brightness_work
.work
);
880 struct ath9k_htc_priv
*priv
= led
->priv
;
882 switch (led
->brightness
) {
884 if (led
->led_type
== ATH_LED_ASSOC
||
885 led
->led_type
== ATH_LED_RADIO
) {
886 ath9k_hw_set_gpio(priv
->ah
, priv
->ah
->led_pin
,
887 (led
->led_type
== ATH_LED_RADIO
));
888 priv
->op_flags
&= ~OP_LED_ASSOCIATED
;
889 if (led
->led_type
== ATH_LED_RADIO
)
890 priv
->op_flags
&= ~OP_LED_ON
;
896 if (led
->led_type
== ATH_LED_ASSOC
) {
897 priv
->op_flags
|= OP_LED_ASSOCIATED
;
898 ieee80211_queue_delayed_work(priv
->hw
,
899 &priv
->ath9k_led_blink_work
, 0);
900 } else if (led
->led_type
== ATH_LED_RADIO
) {
901 ath9k_hw_set_gpio(priv
->ah
, priv
->ah
->led_pin
, 0);
902 priv
->op_flags
|= OP_LED_ON
;
912 static void ath9k_led_brightness(struct led_classdev
*led_cdev
,
913 enum led_brightness brightness
)
915 struct ath_led
*led
= container_of(led_cdev
, struct ath_led
, led_cdev
);
916 struct ath9k_htc_priv
*priv
= led
->priv
;
918 led
->brightness
= brightness
;
919 if (!(priv
->op_flags
& OP_LED_DEINIT
))
920 ieee80211_queue_delayed_work(priv
->hw
,
921 &led
->brightness_work
, 0);
924 static void ath9k_led_stop_brightness(struct ath9k_htc_priv
*priv
)
926 cancel_delayed_work_sync(&priv
->radio_led
.brightness_work
);
927 cancel_delayed_work_sync(&priv
->assoc_led
.brightness_work
);
928 cancel_delayed_work_sync(&priv
->tx_led
.brightness_work
);
929 cancel_delayed_work_sync(&priv
->rx_led
.brightness_work
);
932 static int ath9k_register_led(struct ath9k_htc_priv
*priv
, struct ath_led
*led
,
938 led
->led_cdev
.name
= led
->name
;
939 led
->led_cdev
.default_trigger
= trigger
;
940 led
->led_cdev
.brightness_set
= ath9k_led_brightness
;
942 ret
= led_classdev_register(wiphy_dev(priv
->hw
->wiphy
), &led
->led_cdev
);
944 ath_print(ath9k_hw_common(priv
->ah
), ATH_DBG_FATAL
,
945 "Failed to register led:%s", led
->name
);
949 INIT_DELAYED_WORK(&led
->brightness_work
, ath9k_led_brightness_work
);
954 static void ath9k_unregister_led(struct ath_led
*led
)
956 if (led
->registered
) {
957 led_classdev_unregister(&led
->led_cdev
);
962 void ath9k_deinit_leds(struct ath9k_htc_priv
*priv
)
964 priv
->op_flags
|= OP_LED_DEINIT
;
965 ath9k_unregister_led(&priv
->assoc_led
);
966 priv
->op_flags
&= ~OP_LED_ASSOCIATED
;
967 ath9k_unregister_led(&priv
->tx_led
);
968 ath9k_unregister_led(&priv
->rx_led
);
969 ath9k_unregister_led(&priv
->radio_led
);
972 void ath9k_init_leds(struct ath9k_htc_priv
*priv
)
977 if (AR_SREV_9287(priv
->ah
))
978 priv
->ah
->led_pin
= ATH_LED_PIN_9287
;
979 else if (AR_SREV_9271(priv
->ah
))
980 priv
->ah
->led_pin
= ATH_LED_PIN_9271
;
982 priv
->ah
->led_pin
= ATH_LED_PIN_DEF
;
984 /* Configure gpio 1 for output */
985 ath9k_hw_cfg_output(priv
->ah
, priv
->ah
->led_pin
,
986 AR_GPIO_OUTPUT_MUX_AS_OUTPUT
);
987 /* LED off, active low */
988 ath9k_hw_set_gpio(priv
->ah
, priv
->ah
->led_pin
, 1);
990 INIT_DELAYED_WORK(&priv
->ath9k_led_blink_work
, ath9k_led_blink_work
);
992 trigger
= ieee80211_get_radio_led_name(priv
->hw
);
993 snprintf(priv
->radio_led
.name
, sizeof(priv
->radio_led
.name
),
994 "ath9k-%s::radio", wiphy_name(priv
->hw
->wiphy
));
995 ret
= ath9k_register_led(priv
, &priv
->radio_led
, trigger
);
996 priv
->radio_led
.led_type
= ATH_LED_RADIO
;
1000 trigger
= ieee80211_get_assoc_led_name(priv
->hw
);
1001 snprintf(priv
->assoc_led
.name
, sizeof(priv
->assoc_led
.name
),
1002 "ath9k-%s::assoc", wiphy_name(priv
->hw
->wiphy
));
1003 ret
= ath9k_register_led(priv
, &priv
->assoc_led
, trigger
);
1004 priv
->assoc_led
.led_type
= ATH_LED_ASSOC
;
1008 trigger
= ieee80211_get_tx_led_name(priv
->hw
);
1009 snprintf(priv
->tx_led
.name
, sizeof(priv
->tx_led
.name
),
1010 "ath9k-%s::tx", wiphy_name(priv
->hw
->wiphy
));
1011 ret
= ath9k_register_led(priv
, &priv
->tx_led
, trigger
);
1012 priv
->tx_led
.led_type
= ATH_LED_TX
;
1016 trigger
= ieee80211_get_rx_led_name(priv
->hw
);
1017 snprintf(priv
->rx_led
.name
, sizeof(priv
->rx_led
.name
),
1018 "ath9k-%s::rx", wiphy_name(priv
->hw
->wiphy
));
1019 ret
= ath9k_register_led(priv
, &priv
->rx_led
, trigger
);
1020 priv
->rx_led
.led_type
= ATH_LED_RX
;
1024 priv
->op_flags
&= ~OP_LED_DEINIT
;
1029 cancel_delayed_work_sync(&priv
->ath9k_led_blink_work
);
1030 ath9k_deinit_leds(priv
);
1033 /*******************/
1035 /*******************/
1037 static bool ath_is_rfkill_set(struct ath9k_htc_priv
*priv
)
1039 return ath9k_hw_gpio_get(priv
->ah
, priv
->ah
->rfkill_gpio
) ==
1040 priv
->ah
->rfkill_polarity
;
1043 static void ath9k_htc_rfkill_poll_state(struct ieee80211_hw
*hw
)
1045 struct ath9k_htc_priv
*priv
= hw
->priv
;
1046 bool blocked
= !!ath_is_rfkill_set(priv
);
1048 wiphy_rfkill_set_hw_state(hw
->wiphy
, blocked
);
1051 void ath9k_start_rfkill_poll(struct ath9k_htc_priv
*priv
)
1053 if (priv
->ah
->caps
.hw_caps
& ATH9K_HW_CAP_RFSILENT
)
1054 wiphy_rfkill_start_polling(priv
->hw
->wiphy
);
1057 /**********************/
1058 /* mac80211 Callbacks */
1059 /**********************/
1061 static int ath9k_htc_tx(struct ieee80211_hw
*hw
, struct sk_buff
*skb
)
1063 struct ieee80211_hdr
*hdr
;
1064 struct ath9k_htc_priv
*priv
= hw
->priv
;
1065 int padpos
, padsize
, ret
;
1067 hdr
= (struct ieee80211_hdr
*) skb
->data
;
1069 /* Add the padding after the header if this is not already done */
1070 padpos
= ath9k_cmn_padpos(hdr
->frame_control
);
1071 padsize
= padpos
& 3;
1072 if (padsize
&& skb
->len
> padpos
) {
1073 if (skb_headroom(skb
) < padsize
)
1075 skb_push(skb
, padsize
);
1076 memmove(skb
->data
, skb
->data
+ padsize
, padpos
);
1079 ret
= ath9k_htc_tx_start(priv
, skb
);
1081 if (ret
== -ENOMEM
) {
1082 ath_print(ath9k_hw_common(priv
->ah
), ATH_DBG_XMIT
,
1083 "Stopping TX queues\n");
1084 ieee80211_stop_queues(hw
);
1085 spin_lock_bh(&priv
->tx_lock
);
1086 priv
->tx_queues_stop
= true;
1087 spin_unlock_bh(&priv
->tx_lock
);
1089 ath_print(ath9k_hw_common(priv
->ah
), ATH_DBG_XMIT
,
1098 dev_kfree_skb_any(skb
);
1102 static int ath9k_htc_radio_enable(struct ieee80211_hw
*hw
)
1104 struct ath9k_htc_priv
*priv
= hw
->priv
;
1105 struct ath_hw
*ah
= priv
->ah
;
1106 struct ath_common
*common
= ath9k_hw_common(ah
);
1107 struct ieee80211_channel
*curchan
= hw
->conf
.channel
;
1108 struct ath9k_channel
*init_channel
;
1110 enum htc_phymode mode
;
1114 ath_print(common
, ATH_DBG_CONFIG
,
1115 "Starting driver with initial channel: %d MHz\n",
1116 curchan
->center_freq
);
1118 /* setup initial channel */
1119 init_channel
= ath9k_cmn_get_curchannel(hw
, ah
);
1121 /* Reset SERDES registers */
1122 ath9k_hw_configpcipowersave(ah
, 0, 0);
1124 ath9k_hw_htc_resetinit(ah
);
1125 ret
= ath9k_hw_reset(ah
, init_channel
, false);
1127 ath_print(common
, ATH_DBG_FATAL
,
1128 "Unable to reset hardware; reset status %d "
1129 "(freq %u MHz)\n", ret
, curchan
->center_freq
);
1133 ath_update_txpow(priv
);
1135 mode
= ath9k_htc_get_curmode(priv
, init_channel
);
1136 htc_mode
= cpu_to_be16(mode
);
1137 WMI_CMD_BUF(WMI_SET_MODE_CMDID
, &htc_mode
);
1138 WMI_CMD(WMI_ATH_INIT_CMDID
);
1139 WMI_CMD(WMI_START_RECV_CMDID
);
1141 ath9k_host_rx_init(priv
);
1143 priv
->op_flags
&= ~OP_INVALID
;
1144 htc_start(priv
->htc
);
1146 spin_lock_bh(&priv
->tx_lock
);
1147 priv
->tx_queues_stop
= false;
1148 spin_unlock_bh(&priv
->tx_lock
);
1150 ieee80211_wake_queues(hw
);
1155 static int ath9k_htc_start(struct ieee80211_hw
*hw
)
1157 struct ath9k_htc_priv
*priv
= hw
->priv
;
1160 mutex_lock(&priv
->mutex
);
1161 ret
= ath9k_htc_radio_enable(hw
);
1162 mutex_unlock(&priv
->mutex
);
1167 static void ath9k_htc_radio_disable(struct ieee80211_hw
*hw
)
1169 struct ath9k_htc_priv
*priv
= hw
->priv
;
1170 struct ath_hw
*ah
= priv
->ah
;
1171 struct ath_common
*common
= ath9k_hw_common(ah
);
1175 if (priv
->op_flags
& OP_INVALID
) {
1176 ath_print(common
, ATH_DBG_ANY
, "Device not present\n");
1180 /* Cancel all the running timers/work .. */
1181 cancel_work_sync(&priv
->ps_work
);
1182 cancel_delayed_work_sync(&priv
->ath9k_ani_work
);
1183 cancel_delayed_work_sync(&priv
->ath9k_aggr_work
);
1184 cancel_delayed_work_sync(&priv
->ath9k_led_blink_work
);
1185 ath9k_led_stop_brightness(priv
);
1187 ath9k_htc_ps_wakeup(priv
);
1188 htc_stop(priv
->htc
);
1189 WMI_CMD(WMI_DISABLE_INTR_CMDID
);
1190 WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID
);
1191 WMI_CMD(WMI_STOP_RECV_CMDID
);
1192 ath9k_hw_phy_disable(ah
);
1193 ath9k_hw_disable(ah
);
1194 ath9k_hw_configpcipowersave(ah
, 1, 1);
1195 ath9k_htc_ps_restore(priv
);
1196 ath9k_htc_setpower(priv
, ATH9K_PM_FULL_SLEEP
);
1198 skb_queue_purge(&priv
->tx_queue
);
1200 /* Remove monitor interface here */
1201 if (ah
->opmode
== NL80211_IFTYPE_MONITOR
) {
1202 if (ath9k_htc_remove_monitor_interface(priv
))
1203 ath_print(common
, ATH_DBG_FATAL
,
1204 "Unable to remove monitor interface\n");
1206 ath_print(common
, ATH_DBG_CONFIG
,
1207 "Monitor interface removed\n");
1210 priv
->op_flags
|= OP_INVALID
;
1212 ath_print(common
, ATH_DBG_CONFIG
, "Driver halt\n");
1215 static void ath9k_htc_stop(struct ieee80211_hw
*hw
)
1217 struct ath9k_htc_priv
*priv
= hw
->priv
;
1219 mutex_lock(&priv
->mutex
);
1220 ath9k_htc_radio_disable(hw
);
1221 mutex_unlock(&priv
->mutex
);
1225 static int ath9k_htc_add_interface(struct ieee80211_hw
*hw
,
1226 struct ieee80211_vif
*vif
)
1228 struct ath9k_htc_priv
*priv
= hw
->priv
;
1229 struct ath9k_htc_vif
*avp
= (void *)vif
->drv_priv
;
1230 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
1231 struct ath9k_htc_target_vif hvif
;
1235 mutex_lock(&priv
->mutex
);
1237 /* Only one interface for now */
1238 if (priv
->nvifs
> 0) {
1243 ath9k_htc_ps_wakeup(priv
);
1244 memset(&hvif
, 0, sizeof(struct ath9k_htc_target_vif
));
1245 memcpy(&hvif
.myaddr
, vif
->addr
, ETH_ALEN
);
1247 switch (vif
->type
) {
1248 case NL80211_IFTYPE_STATION
:
1249 hvif
.opmode
= cpu_to_be32(HTC_M_STA
);
1251 case NL80211_IFTYPE_ADHOC
:
1252 hvif
.opmode
= cpu_to_be32(HTC_M_IBSS
);
1255 ath_print(common
, ATH_DBG_FATAL
,
1256 "Interface type %d not yet supported\n", vif
->type
);
1261 ath_print(common
, ATH_DBG_CONFIG
,
1262 "Attach a VIF of type: %d\n", vif
->type
);
1264 priv
->ah
->opmode
= vif
->type
;
1266 /* Index starts from zero on the target */
1267 avp
->index
= hvif
.index
= priv
->nvifs
;
1268 hvif
.rtsthreshold
= cpu_to_be16(2304);
1269 WMI_CMD_BUF(WMI_VAP_CREATE_CMDID
, &hvif
);
1276 * We need a node in target to tx mgmt frames
1277 * before association.
1279 ret
= ath9k_htc_add_station(priv
, vif
, NULL
);
1283 ret
= ath9k_htc_update_cap_target(priv
);
1285 ath_print(common
, ATH_DBG_CONFIG
, "Failed to update"
1286 " capability in target \n");
1290 ath9k_htc_ps_restore(priv
);
1291 mutex_unlock(&priv
->mutex
);
1295 static void ath9k_htc_remove_interface(struct ieee80211_hw
*hw
,
1296 struct ieee80211_vif
*vif
)
1298 struct ath9k_htc_priv
*priv
= hw
->priv
;
1299 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
1300 struct ath9k_htc_vif
*avp
= (void *)vif
->drv_priv
;
1301 struct ath9k_htc_target_vif hvif
;
1305 ath_print(common
, ATH_DBG_CONFIG
, "Detach Interface\n");
1307 mutex_lock(&priv
->mutex
);
1309 memset(&hvif
, 0, sizeof(struct ath9k_htc_target_vif
));
1310 memcpy(&hvif
.myaddr
, vif
->addr
, ETH_ALEN
);
1311 hvif
.index
= avp
->index
;
1312 WMI_CMD_BUF(WMI_VAP_REMOVE_CMDID
, &hvif
);
1315 ath9k_htc_remove_station(priv
, vif
, NULL
);
1318 mutex_unlock(&priv
->mutex
);
1321 static int ath9k_htc_config(struct ieee80211_hw
*hw
, u32 changed
)
1323 struct ath9k_htc_priv
*priv
= hw
->priv
;
1324 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
1325 struct ieee80211_conf
*conf
= &hw
->conf
;
1327 mutex_lock(&priv
->mutex
);
1329 if (changed
& IEEE80211_CONF_CHANGE_IDLE
) {
1330 bool enable_radio
= false;
1331 bool idle
= !!(conf
->flags
& IEEE80211_CONF_IDLE
);
1333 if (!idle
&& priv
->ps_idle
)
1334 enable_radio
= true;
1336 priv
->ps_idle
= idle
;
1339 ath9k_htc_setpower(priv
, ATH9K_PM_AWAKE
);
1340 ath9k_htc_radio_enable(hw
);
1341 ath_print(common
, ATH_DBG_CONFIG
,
1342 "not-idle: enabling radio\n");
1346 if (changed
& IEEE80211_CONF_CHANGE_CHANNEL
) {
1347 struct ieee80211_channel
*curchan
= hw
->conf
.channel
;
1348 int pos
= curchan
->hw_value
;
1349 bool is_cw40
= false;
1351 ath_print(common
, ATH_DBG_CONFIG
, "Set channel: %d MHz\n",
1352 curchan
->center_freq
);
1354 if (check_rc_update(hw
, &is_cw40
))
1355 ath9k_htc_rc_update(priv
, is_cw40
);
1357 ath9k_cmn_update_ichannel(hw
, &priv
->ah
->channels
[pos
]);
1359 if (ath9k_htc_set_channel(priv
, hw
, &priv
->ah
->channels
[pos
]) < 0) {
1360 ath_print(common
, ATH_DBG_FATAL
,
1361 "Unable to set channel\n");
1362 mutex_unlock(&priv
->mutex
);
1367 if (changed
& IEEE80211_CONF_CHANGE_PS
) {
1368 if (conf
->flags
& IEEE80211_CONF_PS
) {
1369 ath9k_htc_setpower(priv
, ATH9K_PM_NETWORK_SLEEP
);
1370 priv
->ps_enabled
= true;
1372 priv
->ps_enabled
= false;
1373 cancel_work_sync(&priv
->ps_work
);
1374 ath9k_htc_setpower(priv
, ATH9K_PM_AWAKE
);
1378 if (changed
& IEEE80211_CONF_CHANGE_MONITOR
) {
1379 if (conf
->flags
& IEEE80211_CONF_MONITOR
) {
1380 if (ath9k_htc_add_monitor_interface(priv
))
1381 ath_print(common
, ATH_DBG_FATAL
,
1382 "Failed to set monitor mode\n");
1384 ath_print(common
, ATH_DBG_CONFIG
,
1385 "HW opmode set to Monitor mode\n");
1389 if (priv
->ps_idle
) {
1390 ath_print(common
, ATH_DBG_CONFIG
,
1391 "idle: disabling radio\n");
1392 ath9k_htc_radio_disable(hw
);
1396 mutex_unlock(&priv
->mutex
);
1401 #define SUPPORTED_FILTERS \
1402 (FIF_PROMISC_IN_BSS | \
1407 FIF_BCN_PRBRESP_PROMISC | \
1410 static void ath9k_htc_configure_filter(struct ieee80211_hw
*hw
,
1411 unsigned int changed_flags
,
1412 unsigned int *total_flags
,
1415 struct ath9k_htc_priv
*priv
= hw
->priv
;
1418 mutex_lock(&priv
->mutex
);
1420 ath9k_htc_ps_wakeup(priv
);
1421 changed_flags
&= SUPPORTED_FILTERS
;
1422 *total_flags
&= SUPPORTED_FILTERS
;
1424 priv
->rxfilter
= *total_flags
;
1425 rfilt
= ath9k_htc_calcrxfilter(priv
);
1426 ath9k_hw_setrxfilter(priv
->ah
, rfilt
);
1428 ath_print(ath9k_hw_common(priv
->ah
), ATH_DBG_CONFIG
,
1429 "Set HW RX filter: 0x%x\n", rfilt
);
1431 ath9k_htc_ps_restore(priv
);
1432 mutex_unlock(&priv
->mutex
);
1435 static void ath9k_htc_sta_notify(struct ieee80211_hw
*hw
,
1436 struct ieee80211_vif
*vif
,
1437 enum sta_notify_cmd cmd
,
1438 struct ieee80211_sta
*sta
)
1440 struct ath9k_htc_priv
*priv
= hw
->priv
;
1444 case STA_NOTIFY_ADD
:
1445 ret
= ath9k_htc_add_station(priv
, vif
, sta
);
1447 ath9k_htc_init_rate(priv
, vif
, sta
);
1449 case STA_NOTIFY_REMOVE
:
1450 ath9k_htc_remove_station(priv
, vif
, sta
);
1457 static int ath9k_htc_conf_tx(struct ieee80211_hw
*hw
, u16 queue
,
1458 const struct ieee80211_tx_queue_params
*params
)
1460 struct ath9k_htc_priv
*priv
= hw
->priv
;
1461 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
1462 struct ath9k_tx_queue_info qi
;
1465 if (queue
>= WME_NUM_AC
)
1468 mutex_lock(&priv
->mutex
);
1470 memset(&qi
, 0, sizeof(struct ath9k_tx_queue_info
));
1472 qi
.tqi_aifs
= params
->aifs
;
1473 qi
.tqi_cwmin
= params
->cw_min
;
1474 qi
.tqi_cwmax
= params
->cw_max
;
1475 qi
.tqi_burstTime
= params
->txop
;
1477 qnum
= get_hw_qnum(queue
, priv
->hwq_map
);
1479 ath_print(common
, ATH_DBG_CONFIG
,
1480 "Configure tx [queue/hwq] [%d/%d], "
1481 "aifs: %d, cw_min: %d, cw_max: %d, txop: %d\n",
1482 queue
, qnum
, params
->aifs
, params
->cw_min
,
1483 params
->cw_max
, params
->txop
);
1485 ret
= ath_htc_txq_update(priv
, qnum
, &qi
);
1487 ath_print(common
, ATH_DBG_FATAL
, "TXQ Update failed\n");
1489 mutex_unlock(&priv
->mutex
);
1494 static int ath9k_htc_set_key(struct ieee80211_hw
*hw
,
1495 enum set_key_cmd cmd
,
1496 struct ieee80211_vif
*vif
,
1497 struct ieee80211_sta
*sta
,
1498 struct ieee80211_key_conf
*key
)
1500 struct ath9k_htc_priv
*priv
= hw
->priv
;
1501 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
1504 if (htc_modparam_nohwcrypt
)
1507 mutex_lock(&priv
->mutex
);
1508 ath_print(common
, ATH_DBG_CONFIG
, "Set HW Key\n");
1509 ath9k_htc_ps_wakeup(priv
);
1513 ret
= ath9k_cmn_key_config(common
, vif
, sta
, key
);
1515 key
->hw_key_idx
= ret
;
1516 /* push IV and Michael MIC generation to stack */
1517 key
->flags
|= IEEE80211_KEY_FLAG_GENERATE_IV
;
1518 if (key
->alg
== ALG_TKIP
)
1519 key
->flags
|= IEEE80211_KEY_FLAG_GENERATE_MMIC
;
1520 if (priv
->ah
->sw_mgmt_crypto
&& key
->alg
== ALG_CCMP
)
1521 key
->flags
|= IEEE80211_KEY_FLAG_SW_MGMT
;
1526 ath9k_cmn_key_delete(common
, key
);
1532 ath9k_htc_ps_restore(priv
);
1533 mutex_unlock(&priv
->mutex
);
1538 static void ath9k_htc_bss_info_changed(struct ieee80211_hw
*hw
,
1539 struct ieee80211_vif
*vif
,
1540 struct ieee80211_bss_conf
*bss_conf
,
1543 struct ath9k_htc_priv
*priv
= hw
->priv
;
1544 struct ath_hw
*ah
= priv
->ah
;
1545 struct ath_common
*common
= ath9k_hw_common(ah
);
1547 mutex_lock(&priv
->mutex
);
1548 ath9k_htc_ps_wakeup(priv
);
1550 if (changed
& BSS_CHANGED_ASSOC
) {
1551 common
->curaid
= bss_conf
->assoc
?
1553 ath_print(common
, ATH_DBG_CONFIG
, "BSS Changed ASSOC %d\n",
1556 if (bss_conf
->assoc
) {
1557 priv
->op_flags
|= OP_ASSOCIATED
;
1558 ath_start_ani(priv
);
1560 priv
->op_flags
&= ~OP_ASSOCIATED
;
1561 cancel_work_sync(&priv
->ps_work
);
1562 cancel_delayed_work_sync(&priv
->ath9k_ani_work
);
1566 if (changed
& BSS_CHANGED_BSSID
) {
1568 memcpy(common
->curbssid
, bss_conf
->bssid
, ETH_ALEN
);
1569 ath9k_hw_write_associd(ah
);
1571 ath_print(common
, ATH_DBG_CONFIG
,
1572 "BSSID: %pM aid: 0x%x\n",
1573 common
->curbssid
, common
->curaid
);
1576 if ((changed
& BSS_CHANGED_BEACON_INT
) ||
1577 (changed
& BSS_CHANGED_BEACON
) ||
1578 ((changed
& BSS_CHANGED_BEACON_ENABLED
) &&
1579 bss_conf
->enable_beacon
)) {
1580 priv
->op_flags
|= OP_ENABLE_BEACON
;
1581 ath9k_htc_beacon_config(priv
, vif
);
1584 if ((changed
& BSS_CHANGED_BEACON_ENABLED
) &&
1585 !bss_conf
->enable_beacon
) {
1586 priv
->op_flags
&= ~OP_ENABLE_BEACON
;
1587 ath9k_htc_beacon_config(priv
, vif
);
1590 if (changed
& BSS_CHANGED_ERP_PREAMBLE
) {
1591 ath_print(common
, ATH_DBG_CONFIG
, "BSS Changed PREAMBLE %d\n",
1592 bss_conf
->use_short_preamble
);
1593 if (bss_conf
->use_short_preamble
)
1594 priv
->op_flags
|= OP_PREAMBLE_SHORT
;
1596 priv
->op_flags
&= ~OP_PREAMBLE_SHORT
;
1599 if (changed
& BSS_CHANGED_ERP_CTS_PROT
) {
1600 ath_print(common
, ATH_DBG_CONFIG
, "BSS Changed CTS PROT %d\n",
1601 bss_conf
->use_cts_prot
);
1602 if (bss_conf
->use_cts_prot
&&
1603 hw
->conf
.channel
->band
!= IEEE80211_BAND_5GHZ
)
1604 priv
->op_flags
|= OP_PROTECT_ENABLE
;
1606 priv
->op_flags
&= ~OP_PROTECT_ENABLE
;
1609 if (changed
& BSS_CHANGED_ERP_SLOT
) {
1610 if (bss_conf
->use_short_slot
)
1615 ath9k_hw_init_global_settings(ah
);
1618 ath9k_htc_ps_restore(priv
);
1619 mutex_unlock(&priv
->mutex
);
1622 static u64
ath9k_htc_get_tsf(struct ieee80211_hw
*hw
)
1624 struct ath9k_htc_priv
*priv
= hw
->priv
;
1627 mutex_lock(&priv
->mutex
);
1628 tsf
= ath9k_hw_gettsf64(priv
->ah
);
1629 mutex_unlock(&priv
->mutex
);
1634 static void ath9k_htc_set_tsf(struct ieee80211_hw
*hw
, u64 tsf
)
1636 struct ath9k_htc_priv
*priv
= hw
->priv
;
1638 mutex_lock(&priv
->mutex
);
1639 ath9k_hw_settsf64(priv
->ah
, tsf
);
1640 mutex_unlock(&priv
->mutex
);
1643 static void ath9k_htc_reset_tsf(struct ieee80211_hw
*hw
)
1645 struct ath9k_htc_priv
*priv
= hw
->priv
;
1647 ath9k_htc_ps_wakeup(priv
);
1648 mutex_lock(&priv
->mutex
);
1649 ath9k_hw_reset_tsf(priv
->ah
);
1650 mutex_unlock(&priv
->mutex
);
1651 ath9k_htc_ps_restore(priv
);
1654 static int ath9k_htc_ampdu_action(struct ieee80211_hw
*hw
,
1655 struct ieee80211_vif
*vif
,
1656 enum ieee80211_ampdu_mlme_action action
,
1657 struct ieee80211_sta
*sta
,
1660 struct ath9k_htc_priv
*priv
= hw
->priv
;
1661 struct ath9k_htc_aggr_work
*work
= &priv
->aggr_work
;
1662 struct ath9k_htc_sta
*ista
;
1665 case IEEE80211_AMPDU_RX_START
:
1667 case IEEE80211_AMPDU_RX_STOP
:
1669 case IEEE80211_AMPDU_TX_START
:
1670 case IEEE80211_AMPDU_TX_STOP
:
1671 if (!(priv
->op_flags
& OP_TXAGGR
))
1673 memcpy(work
->sta_addr
, sta
->addr
, ETH_ALEN
);
1676 work
->action
= action
;
1678 ieee80211_queue_delayed_work(hw
, &priv
->ath9k_aggr_work
, 0);
1680 case IEEE80211_AMPDU_TX_OPERATIONAL
:
1681 ista
= (struct ath9k_htc_sta
*) sta
->drv_priv
;
1682 ista
->tid_state
[tid
] = AGGR_OPERATIONAL
;
1685 ath_print(ath9k_hw_common(priv
->ah
), ATH_DBG_FATAL
,
1686 "Unknown AMPDU action\n");
1692 static void ath9k_htc_sw_scan_start(struct ieee80211_hw
*hw
)
1694 struct ath9k_htc_priv
*priv
= hw
->priv
;
1696 mutex_lock(&priv
->mutex
);
1697 spin_lock_bh(&priv
->beacon_lock
);
1698 priv
->op_flags
|= OP_SCANNING
;
1699 spin_unlock_bh(&priv
->beacon_lock
);
1700 cancel_work_sync(&priv
->ps_work
);
1701 cancel_delayed_work_sync(&priv
->ath9k_ani_work
);
1702 mutex_unlock(&priv
->mutex
);
1705 static void ath9k_htc_sw_scan_complete(struct ieee80211_hw
*hw
)
1707 struct ath9k_htc_priv
*priv
= hw
->priv
;
1709 ath9k_htc_ps_wakeup(priv
);
1710 mutex_lock(&priv
->mutex
);
1711 spin_lock_bh(&priv
->beacon_lock
);
1712 priv
->op_flags
&= ~OP_SCANNING
;
1713 spin_unlock_bh(&priv
->beacon_lock
);
1714 priv
->op_flags
|= OP_FULL_RESET
;
1715 if (priv
->op_flags
& OP_ASSOCIATED
)
1716 ath9k_htc_beacon_config(priv
, priv
->vif
);
1717 ath_start_ani(priv
);
1718 mutex_unlock(&priv
->mutex
);
1719 ath9k_htc_ps_restore(priv
);
1722 static int ath9k_htc_set_rts_threshold(struct ieee80211_hw
*hw
, u32 value
)
1727 static void ath9k_htc_set_coverage_class(struct ieee80211_hw
*hw
,
1730 struct ath9k_htc_priv
*priv
= hw
->priv
;
1732 mutex_lock(&priv
->mutex
);
1733 priv
->ah
->coverage_class
= coverage_class
;
1734 ath9k_hw_init_global_settings(priv
->ah
);
1735 mutex_unlock(&priv
->mutex
);
1738 struct ieee80211_ops ath9k_htc_ops
= {
1740 .start
= ath9k_htc_start
,
1741 .stop
= ath9k_htc_stop
,
1742 .add_interface
= ath9k_htc_add_interface
,
1743 .remove_interface
= ath9k_htc_remove_interface
,
1744 .config
= ath9k_htc_config
,
1745 .configure_filter
= ath9k_htc_configure_filter
,
1746 .sta_notify
= ath9k_htc_sta_notify
,
1747 .conf_tx
= ath9k_htc_conf_tx
,
1748 .bss_info_changed
= ath9k_htc_bss_info_changed
,
1749 .set_key
= ath9k_htc_set_key
,
1750 .get_tsf
= ath9k_htc_get_tsf
,
1751 .set_tsf
= ath9k_htc_set_tsf
,
1752 .reset_tsf
= ath9k_htc_reset_tsf
,
1753 .ampdu_action
= ath9k_htc_ampdu_action
,
1754 .sw_scan_start
= ath9k_htc_sw_scan_start
,
1755 .sw_scan_complete
= ath9k_htc_sw_scan_complete
,
1756 .set_rts_threshold
= ath9k_htc_set_rts_threshold
,
1757 .rfkill_poll
= ath9k_htc_rfkill_poll_state
,
1758 .set_coverage_class
= ath9k_htc_set_coverage_class
,