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
;
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 if (priv
->op_flags
& OP_FULL_RESET
)
194 ath9k_htc_ps_wakeup(priv
);
196 WMI_CMD(WMI_DISABLE_INTR_CMDID
);
197 WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID
);
198 WMI_CMD(WMI_STOP_RECV_CMDID
);
200 ath_dbg(common
, ATH_DBG_CONFIG
,
201 "(%u MHz) -> (%u MHz), HT: %d, HT40: %d fastcc: %d\n",
202 priv
->ah
->curchan
->channel
,
203 channel
->center_freq
, conf_is_ht(conf
), conf_is_ht40(conf
),
206 caldata
= &priv
->caldata
[channel
->hw_value
];
207 ret
= ath9k_hw_reset(ah
, hchan
, caldata
, fastcc
);
210 "Unable to reset channel (%u Mhz) reset status %d\n",
211 channel
->center_freq
, ret
);
215 ath_update_txpow(priv
);
217 WMI_CMD(WMI_START_RECV_CMDID
);
221 ath9k_host_rx_init(priv
);
223 mode
= ath9k_htc_get_curmode(priv
, hchan
);
224 htc_mode
= cpu_to_be16(mode
);
225 WMI_CMD_BUF(WMI_SET_MODE_CMDID
, &htc_mode
);
229 WMI_CMD(WMI_ENABLE_INTR_CMDID
);
233 htc_start(priv
->htc
);
235 priv
->op_flags
&= ~OP_FULL_RESET
;
237 ath9k_htc_ps_restore(priv
);
241 static int ath9k_htc_add_monitor_interface(struct ath9k_htc_priv
*priv
)
243 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
244 struct ath9k_htc_target_vif hvif
;
251 memset(&hvif
, 0, sizeof(struct ath9k_htc_target_vif
));
252 memcpy(&hvif
.myaddr
, common
->macaddr
, ETH_ALEN
);
254 hvif
.opmode
= cpu_to_be32(HTC_M_MONITOR
);
255 priv
->ah
->opmode
= NL80211_IFTYPE_MONITOR
;
256 hvif
.index
= priv
->nvifs
;
258 WMI_CMD_BUF(WMI_VAP_CREATE_CMDID
, &hvif
);
266 static int ath9k_htc_remove_monitor_interface(struct ath9k_htc_priv
*priv
)
268 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
269 struct ath9k_htc_target_vif hvif
;
273 memset(&hvif
, 0, sizeof(struct ath9k_htc_target_vif
));
274 memcpy(&hvif
.myaddr
, common
->macaddr
, ETH_ALEN
);
275 hvif
.index
= 0; /* Should do for now */
276 WMI_CMD_BUF(WMI_VAP_REMOVE_CMDID
, &hvif
);
282 static int ath9k_htc_add_station(struct ath9k_htc_priv
*priv
,
283 struct ieee80211_vif
*vif
,
284 struct ieee80211_sta
*sta
)
286 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
287 struct ath9k_htc_target_sta tsta
;
288 struct ath9k_htc_vif
*avp
= (struct ath9k_htc_vif
*) vif
->drv_priv
;
289 struct ath9k_htc_sta
*ista
;
293 if (priv
->nstations
>= ATH9K_HTC_MAX_STA
)
296 memset(&tsta
, 0, sizeof(struct ath9k_htc_target_sta
));
299 ista
= (struct ath9k_htc_sta
*) sta
->drv_priv
;
300 memcpy(&tsta
.macaddr
, sta
->addr
, ETH_ALEN
);
301 memcpy(&tsta
.bssid
, common
->curbssid
, ETH_ALEN
);
302 tsta
.associd
= common
->curaid
;
305 ista
->index
= priv
->nstations
;
307 memcpy(&tsta
.macaddr
, vif
->addr
, ETH_ALEN
);
311 tsta
.sta_index
= priv
->nstations
;
312 tsta
.vif_index
= avp
->index
;
313 tsta
.maxampdu
= 0xffff;
314 if (sta
&& sta
->ht_cap
.ht_supported
)
315 tsta
.flags
= cpu_to_be16(ATH_HTC_STA_HT
);
317 WMI_CMD_BUF(WMI_NODE_CREATE_CMDID
, &tsta
);
321 "Unable to add station entry for: %pM\n",
327 ath_dbg(common
, ATH_DBG_CONFIG
,
328 "Added a station entry for: %pM (idx: %d)\n",
329 sta
->addr
, tsta
.sta_index
);
335 static int ath9k_htc_remove_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_sta
*ista
;
345 ista
= (struct ath9k_htc_sta
*) sta
->drv_priv
;
346 sta_idx
= ista
->index
;
351 WMI_CMD_BUF(WMI_NODE_REMOVE_CMDID
, &sta_idx
);
355 "Unable to remove station entry for: %pM\n",
361 ath_dbg(common
, ATH_DBG_CONFIG
,
362 "Removed a station entry for: %pM (idx: %d)\n",
369 static int ath9k_htc_update_cap_target(struct ath9k_htc_priv
*priv
)
371 struct ath9k_htc_cap_target tcap
;
375 memset(&tcap
, 0, sizeof(struct ath9k_htc_cap_target
));
377 /* FIXME: Values are hardcoded */
378 tcap
.flags
= 0x240c40;
379 tcap
.flags_ext
= 0x80601000;
380 tcap
.ampdu_limit
= 0xffff0000;
381 tcap
.ampdu_subframes
= 20;
382 tcap
.tx_chainmask_legacy
= priv
->ah
->caps
.tx_chainmask
;
384 tcap
.tx_chainmask
= priv
->ah
->caps
.tx_chainmask
;
386 WMI_CMD_BUF(WMI_TARGET_IC_UPDATE_CMDID
, &tcap
);
391 static void ath9k_htc_setup_rate(struct ath9k_htc_priv
*priv
,
392 struct ieee80211_sta
*sta
,
393 struct ath9k_htc_target_rate
*trate
)
395 struct ath9k_htc_sta
*ista
= (struct ath9k_htc_sta
*) sta
->drv_priv
;
396 struct ieee80211_supported_band
*sband
;
400 sband
= priv
->hw
->wiphy
->bands
[priv
->hw
->conf
.channel
->band
];
402 for (i
= 0, j
= 0; i
< sband
->n_bitrates
; i
++) {
403 if (sta
->supp_rates
[sband
->band
] & BIT(i
)) {
404 trate
->rates
.legacy_rates
.rs_rates
[j
]
405 = (sband
->bitrates
[i
].bitrate
* 2) / 10;
409 trate
->rates
.legacy_rates
.rs_nrates
= j
;
411 if (sta
->ht_cap
.ht_supported
) {
412 for (i
= 0, j
= 0; i
< 77; i
++) {
413 if (sta
->ht_cap
.mcs
.rx_mask
[i
/8] & (1<<(i
%8)))
414 trate
->rates
.ht_rates
.rs_rates
[j
++] = i
;
415 if (j
== ATH_HTC_RATE_MAX
)
418 trate
->rates
.ht_rates
.rs_nrates
= j
;
420 caps
= WLAN_RC_HT_FLAG
;
421 if (sta
->ht_cap
.mcs
.rx_mask
[1])
422 caps
|= WLAN_RC_DS_FLAG
;
423 if ((sta
->ht_cap
.cap
& IEEE80211_HT_CAP_SUP_WIDTH_20_40
) &&
424 (conf_is_ht40(&priv
->hw
->conf
)))
425 caps
|= WLAN_RC_40_FLAG
;
426 if (conf_is_ht40(&priv
->hw
->conf
) &&
427 (sta
->ht_cap
.cap
& IEEE80211_HT_CAP_SGI_40
))
428 caps
|= WLAN_RC_SGI_FLAG
;
429 else if (conf_is_ht20(&priv
->hw
->conf
) &&
430 (sta
->ht_cap
.cap
& IEEE80211_HT_CAP_SGI_20
))
431 caps
|= WLAN_RC_SGI_FLAG
;
434 trate
->sta_index
= ista
->index
;
436 trate
->capflags
= cpu_to_be32(caps
);
439 static int ath9k_htc_send_rate_cmd(struct ath9k_htc_priv
*priv
,
440 struct ath9k_htc_target_rate
*trate
)
442 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
446 WMI_CMD_BUF(WMI_RC_RATE_UPDATE_CMDID
, trate
);
449 "Unable to initialize Rate information on target\n");
455 static void ath9k_htc_init_rate(struct ath9k_htc_priv
*priv
,
456 struct ieee80211_sta
*sta
)
458 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
459 struct ath9k_htc_target_rate trate
;
462 memset(&trate
, 0, sizeof(struct ath9k_htc_target_rate
));
463 ath9k_htc_setup_rate(priv
, sta
, &trate
);
464 ret
= ath9k_htc_send_rate_cmd(priv
, &trate
);
466 ath_dbg(common
, ATH_DBG_CONFIG
,
467 "Updated target sta: %pM, rate caps: 0x%X\n",
468 sta
->addr
, be32_to_cpu(trate
.capflags
));
471 static void ath9k_htc_update_rate(struct ath9k_htc_priv
*priv
,
472 struct ieee80211_vif
*vif
,
473 struct ieee80211_bss_conf
*bss_conf
)
475 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
476 struct ath9k_htc_target_rate trate
;
477 struct ieee80211_sta
*sta
;
480 memset(&trate
, 0, sizeof(struct ath9k_htc_target_rate
));
483 sta
= ieee80211_find_sta(vif
, bss_conf
->bssid
);
488 ath9k_htc_setup_rate(priv
, sta
, &trate
);
491 ret
= ath9k_htc_send_rate_cmd(priv
, &trate
);
493 ath_dbg(common
, ATH_DBG_CONFIG
,
494 "Updated target sta: %pM, rate caps: 0x%X\n",
495 bss_conf
->bssid
, be32_to_cpu(trate
.capflags
));
498 static int ath9k_htc_tx_aggr_oper(struct ath9k_htc_priv
*priv
,
499 struct ieee80211_vif
*vif
,
500 struct ieee80211_sta
*sta
,
501 enum ieee80211_ampdu_mlme_action action
,
504 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
505 struct ath9k_htc_target_aggr aggr
;
506 struct ath9k_htc_sta
*ista
;
510 if (tid
>= ATH9K_HTC_MAX_TID
)
513 memset(&aggr
, 0, sizeof(struct ath9k_htc_target_aggr
));
514 ista
= (struct ath9k_htc_sta
*) sta
->drv_priv
;
516 aggr
.sta_index
= ista
->index
;
517 aggr
.tidno
= tid
& 0xf;
518 aggr
.aggr_enable
= (action
== IEEE80211_AMPDU_TX_START
) ? true : false;
520 WMI_CMD_BUF(WMI_TX_AGGR_ENABLE_CMDID
, &aggr
);
522 ath_dbg(common
, ATH_DBG_CONFIG
,
523 "Unable to %s TX aggregation for (%pM, %d)\n",
524 (aggr
.aggr_enable
) ? "start" : "stop", sta
->addr
, tid
);
526 ath_dbg(common
, ATH_DBG_CONFIG
,
527 "%s TX aggregation for (%pM, %d)\n",
528 (aggr
.aggr_enable
) ? "Starting" : "Stopping",
531 spin_lock_bh(&priv
->tx_lock
);
532 ista
->tid_state
[tid
] = (aggr
.aggr_enable
&& !ret
) ? AGGR_START
: AGGR_STOP
;
533 spin_unlock_bh(&priv
->tx_lock
);
542 #ifdef CONFIG_ATH9K_HTC_DEBUGFS
544 static int ath9k_debugfs_open(struct inode
*inode
, struct file
*file
)
546 file
->private_data
= inode
->i_private
;
550 static ssize_t
read_file_tgt_stats(struct file
*file
, char __user
*user_buf
,
551 size_t count
, loff_t
*ppos
)
553 struct ath9k_htc_priv
*priv
= file
->private_data
;
554 struct ath9k_htc_target_stats cmd_rsp
;
556 unsigned int len
= 0;
559 memset(&cmd_rsp
, 0, sizeof(cmd_rsp
));
561 WMI_CMD(WMI_TGT_STATS_CMDID
);
566 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
567 "%19s : %10u\n", "TX Short Retries",
568 be32_to_cpu(cmd_rsp
.tx_shortretry
));
569 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
570 "%19s : %10u\n", "TX Long Retries",
571 be32_to_cpu(cmd_rsp
.tx_longretry
));
572 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
573 "%19s : %10u\n", "TX Xretries",
574 be32_to_cpu(cmd_rsp
.tx_xretries
));
575 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
576 "%19s : %10u\n", "TX Unaggr. Xretries",
577 be32_to_cpu(cmd_rsp
.ht_txunaggr_xretry
));
578 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
579 "%19s : %10u\n", "TX Xretries (HT)",
580 be32_to_cpu(cmd_rsp
.ht_tx_xretries
));
581 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
582 "%19s : %10u\n", "TX Rate", priv
->debug
.txrate
);
584 if (len
> sizeof(buf
))
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
,
593 .owner
= THIS_MODULE
,
594 .llseek
= default_llseek
,
597 static ssize_t
read_file_xmit(struct file
*file
, char __user
*user_buf
,
598 size_t count
, loff_t
*ppos
)
600 struct ath9k_htc_priv
*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 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
621 "%20s : %10u\n", "BE queued",
622 priv
->debug
.tx_stats
.queue_stats
[WME_AC_BE
]);
623 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
624 "%20s : %10u\n", "BK queued",
625 priv
->debug
.tx_stats
.queue_stats
[WME_AC_BK
]);
626 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
627 "%20s : %10u\n", "VI queued",
628 priv
->debug
.tx_stats
.queue_stats
[WME_AC_VI
]);
629 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
630 "%20s : %10u\n", "VO queued",
631 priv
->debug
.tx_stats
.queue_stats
[WME_AC_VO
]);
633 if (len
> sizeof(buf
))
636 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, len
);
639 static const struct file_operations fops_xmit
= {
640 .read
= read_file_xmit
,
641 .open
= ath9k_debugfs_open
,
642 .owner
= THIS_MODULE
,
643 .llseek
= default_llseek
,
646 static ssize_t
read_file_recv(struct file
*file
, char __user
*user_buf
,
647 size_t count
, loff_t
*ppos
)
649 struct ath9k_htc_priv
*priv
= file
->private_data
;
651 unsigned int len
= 0;
653 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
654 "%20s : %10u\n", "SKBs allocated",
655 priv
->debug
.rx_stats
.skb_allocated
);
656 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
657 "%20s : %10u\n", "SKBs completed",
658 priv
->debug
.rx_stats
.skb_completed
);
659 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
660 "%20s : %10u\n", "SKBs Dropped",
661 priv
->debug
.rx_stats
.skb_dropped
);
663 if (len
> sizeof(buf
))
666 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, len
);
669 static const struct file_operations fops_recv
= {
670 .read
= read_file_recv
,
671 .open
= ath9k_debugfs_open
,
672 .owner
= THIS_MODULE
,
673 .llseek
= default_llseek
,
676 int ath9k_htc_init_debug(struct ath_hw
*ah
)
678 struct ath_common
*common
= ath9k_hw_common(ah
);
679 struct ath9k_htc_priv
*priv
= (struct ath9k_htc_priv
*) common
->priv
;
681 if (!ath9k_debugfs_root
)
684 priv
->debug
.debugfs_phy
= debugfs_create_dir(wiphy_name(priv
->hw
->wiphy
),
686 if (!priv
->debug
.debugfs_phy
)
689 priv
->debug
.debugfs_tgt_stats
= debugfs_create_file("tgt_stats", S_IRUSR
,
690 priv
->debug
.debugfs_phy
,
691 priv
, &fops_tgt_stats
);
692 if (!priv
->debug
.debugfs_tgt_stats
)
696 priv
->debug
.debugfs_xmit
= debugfs_create_file("xmit", S_IRUSR
,
697 priv
->debug
.debugfs_phy
,
699 if (!priv
->debug
.debugfs_xmit
)
702 priv
->debug
.debugfs_recv
= debugfs_create_file("recv", S_IRUSR
,
703 priv
->debug
.debugfs_phy
,
705 if (!priv
->debug
.debugfs_recv
)
711 ath9k_htc_exit_debug(ah
);
715 void ath9k_htc_exit_debug(struct ath_hw
*ah
)
717 struct ath_common
*common
= ath9k_hw_common(ah
);
718 struct ath9k_htc_priv
*priv
= (struct ath9k_htc_priv
*) common
->priv
;
720 debugfs_remove(priv
->debug
.debugfs_recv
);
721 debugfs_remove(priv
->debug
.debugfs_xmit
);
722 debugfs_remove(priv
->debug
.debugfs_tgt_stats
);
723 debugfs_remove(priv
->debug
.debugfs_phy
);
726 int ath9k_htc_debug_create_root(void)
728 ath9k_debugfs_root
= debugfs_create_dir(KBUILD_MODNAME
, NULL
);
729 if (!ath9k_debugfs_root
)
735 void ath9k_htc_debug_remove_root(void)
737 debugfs_remove(ath9k_debugfs_root
);
738 ath9k_debugfs_root
= NULL
;
741 #endif /* CONFIG_ATH9K_HTC_DEBUGFS */
747 void ath_start_ani(struct ath9k_htc_priv
*priv
)
749 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
750 unsigned long timestamp
= jiffies_to_msecs(jiffies
);
752 common
->ani
.longcal_timer
= timestamp
;
753 common
->ani
.shortcal_timer
= timestamp
;
754 common
->ani
.checkani_timer
= timestamp
;
756 ieee80211_queue_delayed_work(common
->hw
, &priv
->ath9k_ani_work
,
757 msecs_to_jiffies(ATH_ANI_POLLINTERVAL
));
760 void ath9k_ani_work(struct work_struct
*work
)
762 struct ath9k_htc_priv
*priv
=
763 container_of(work
, struct ath9k_htc_priv
,
764 ath9k_ani_work
.work
);
765 struct ath_hw
*ah
= priv
->ah
;
766 struct ath_common
*common
= ath9k_hw_common(ah
);
767 bool longcal
= false;
768 bool shortcal
= false;
769 bool aniflag
= false;
770 unsigned int timestamp
= jiffies_to_msecs(jiffies
);
771 u32 cal_interval
, short_cal_interval
;
773 short_cal_interval
= ATH_STA_SHORT_CALINTERVAL
;
775 /* Only calibrate if awake */
776 if (ah
->power_mode
!= ATH9K_PM_AWAKE
)
779 /* Long calibration runs independently of short calibration. */
780 if ((timestamp
- common
->ani
.longcal_timer
) >= ATH_LONG_CALINTERVAL
) {
782 ath_dbg(common
, ATH_DBG_ANI
, "longcal @%lu\n", jiffies
);
783 common
->ani
.longcal_timer
= timestamp
;
786 /* Short calibration applies only while caldone is false */
787 if (!common
->ani
.caldone
) {
788 if ((timestamp
- common
->ani
.shortcal_timer
) >=
789 short_cal_interval
) {
791 ath_dbg(common
, ATH_DBG_ANI
,
792 "shortcal @%lu\n", jiffies
);
793 common
->ani
.shortcal_timer
= timestamp
;
794 common
->ani
.resetcal_timer
= timestamp
;
797 if ((timestamp
- common
->ani
.resetcal_timer
) >=
798 ATH_RESTART_CALINTERVAL
) {
799 common
->ani
.caldone
= ath9k_hw_reset_calvalid(ah
);
800 if (common
->ani
.caldone
)
801 common
->ani
.resetcal_timer
= timestamp
;
805 /* Verify whether we must check ANI */
806 if ((timestamp
- common
->ani
.checkani_timer
) >= ATH_ANI_POLLINTERVAL
) {
808 common
->ani
.checkani_timer
= timestamp
;
811 /* Skip all processing if there's nothing to do. */
812 if (longcal
|| shortcal
|| aniflag
) {
814 ath9k_htc_ps_wakeup(priv
);
816 /* Call ANI routine if necessary */
818 ath9k_hw_ani_monitor(ah
, ah
->curchan
);
820 /* Perform calibration if necessary */
821 if (longcal
|| shortcal
)
822 common
->ani
.caldone
=
823 ath9k_hw_calibrate(ah
, ah
->curchan
,
824 common
->rx_chainmask
,
827 ath9k_htc_ps_restore(priv
);
832 * Set timer interval based on previous results.
833 * The interval must be the shortest necessary to satisfy ANI,
834 * short calibration and long calibration.
836 cal_interval
= ATH_LONG_CALINTERVAL
;
837 if (priv
->ah
->config
.enable_ani
)
838 cal_interval
= min(cal_interval
, (u32
)ATH_ANI_POLLINTERVAL
);
839 if (!common
->ani
.caldone
)
840 cal_interval
= min(cal_interval
, (u32
)short_cal_interval
);
842 ieee80211_queue_delayed_work(common
->hw
, &priv
->ath9k_ani_work
,
843 msecs_to_jiffies(cal_interval
));
850 static void ath9k_led_blink_work(struct work_struct
*work
)
852 struct ath9k_htc_priv
*priv
= container_of(work
, struct ath9k_htc_priv
,
853 ath9k_led_blink_work
.work
);
855 if (!(priv
->op_flags
& OP_LED_ASSOCIATED
))
858 if ((priv
->led_on_duration
== ATH_LED_ON_DURATION_IDLE
) ||
859 (priv
->led_off_duration
== ATH_LED_OFF_DURATION_IDLE
))
860 ath9k_hw_set_gpio(priv
->ah
, priv
->ah
->led_pin
, 0);
862 ath9k_hw_set_gpio(priv
->ah
, priv
->ah
->led_pin
,
863 (priv
->op_flags
& OP_LED_ON
) ? 1 : 0);
865 ieee80211_queue_delayed_work(priv
->hw
,
866 &priv
->ath9k_led_blink_work
,
867 (priv
->op_flags
& OP_LED_ON
) ?
868 msecs_to_jiffies(priv
->led_off_duration
) :
869 msecs_to_jiffies(priv
->led_on_duration
));
871 priv
->led_on_duration
= priv
->led_on_cnt
?
872 max((ATH_LED_ON_DURATION_IDLE
- priv
->led_on_cnt
), 25) :
873 ATH_LED_ON_DURATION_IDLE
;
874 priv
->led_off_duration
= priv
->led_off_cnt
?
875 max((ATH_LED_OFF_DURATION_IDLE
- priv
->led_off_cnt
), 10) :
876 ATH_LED_OFF_DURATION_IDLE
;
877 priv
->led_on_cnt
= priv
->led_off_cnt
= 0;
879 if (priv
->op_flags
& OP_LED_ON
)
880 priv
->op_flags
&= ~OP_LED_ON
;
882 priv
->op_flags
|= OP_LED_ON
;
885 static void ath9k_led_brightness_work(struct work_struct
*work
)
887 struct ath_led
*led
= container_of(work
, struct ath_led
,
888 brightness_work
.work
);
889 struct ath9k_htc_priv
*priv
= led
->priv
;
891 switch (led
->brightness
) {
893 if (led
->led_type
== ATH_LED_ASSOC
||
894 led
->led_type
== ATH_LED_RADIO
) {
895 ath9k_hw_set_gpio(priv
->ah
, priv
->ah
->led_pin
,
896 (led
->led_type
== ATH_LED_RADIO
));
897 priv
->op_flags
&= ~OP_LED_ASSOCIATED
;
898 if (led
->led_type
== ATH_LED_RADIO
)
899 priv
->op_flags
&= ~OP_LED_ON
;
905 if (led
->led_type
== ATH_LED_ASSOC
) {
906 priv
->op_flags
|= OP_LED_ASSOCIATED
;
907 ieee80211_queue_delayed_work(priv
->hw
,
908 &priv
->ath9k_led_blink_work
, 0);
909 } else if (led
->led_type
== ATH_LED_RADIO
) {
910 ath9k_hw_set_gpio(priv
->ah
, priv
->ah
->led_pin
, 0);
911 priv
->op_flags
|= OP_LED_ON
;
921 static void ath9k_led_brightness(struct led_classdev
*led_cdev
,
922 enum led_brightness brightness
)
924 struct ath_led
*led
= container_of(led_cdev
, struct ath_led
, led_cdev
);
925 struct ath9k_htc_priv
*priv
= led
->priv
;
927 led
->brightness
= brightness
;
928 if (!(priv
->op_flags
& OP_LED_DEINIT
))
929 ieee80211_queue_delayed_work(priv
->hw
,
930 &led
->brightness_work
, 0);
933 static void ath9k_led_stop_brightness(struct ath9k_htc_priv
*priv
)
935 cancel_delayed_work_sync(&priv
->radio_led
.brightness_work
);
936 cancel_delayed_work_sync(&priv
->assoc_led
.brightness_work
);
937 cancel_delayed_work_sync(&priv
->tx_led
.brightness_work
);
938 cancel_delayed_work_sync(&priv
->rx_led
.brightness_work
);
941 static int ath9k_register_led(struct ath9k_htc_priv
*priv
, struct ath_led
*led
,
947 led
->led_cdev
.name
= led
->name
;
948 led
->led_cdev
.default_trigger
= trigger
;
949 led
->led_cdev
.brightness_set
= ath9k_led_brightness
;
951 ret
= led_classdev_register(wiphy_dev(priv
->hw
->wiphy
), &led
->led_cdev
);
953 ath_err(ath9k_hw_common(priv
->ah
),
954 "Failed to register led:%s", led
->name
);
958 INIT_DELAYED_WORK(&led
->brightness_work
, ath9k_led_brightness_work
);
963 static void ath9k_unregister_led(struct ath_led
*led
)
965 if (led
->registered
) {
966 led_classdev_unregister(&led
->led_cdev
);
971 void ath9k_deinit_leds(struct ath9k_htc_priv
*priv
)
973 priv
->op_flags
|= OP_LED_DEINIT
;
974 ath9k_unregister_led(&priv
->assoc_led
);
975 priv
->op_flags
&= ~OP_LED_ASSOCIATED
;
976 ath9k_unregister_led(&priv
->tx_led
);
977 ath9k_unregister_led(&priv
->rx_led
);
978 ath9k_unregister_led(&priv
->radio_led
);
981 void ath9k_init_leds(struct ath9k_htc_priv
*priv
)
986 if (AR_SREV_9287(priv
->ah
))
987 priv
->ah
->led_pin
= ATH_LED_PIN_9287
;
988 else if (AR_SREV_9271(priv
->ah
))
989 priv
->ah
->led_pin
= ATH_LED_PIN_9271
;
990 else if (AR_DEVID_7010(priv
->ah
))
991 priv
->ah
->led_pin
= ATH_LED_PIN_7010
;
993 priv
->ah
->led_pin
= ATH_LED_PIN_DEF
;
995 /* Configure gpio 1 for output */
996 ath9k_hw_cfg_output(priv
->ah
, priv
->ah
->led_pin
,
997 AR_GPIO_OUTPUT_MUX_AS_OUTPUT
);
998 /* LED off, active low */
999 ath9k_hw_set_gpio(priv
->ah
, priv
->ah
->led_pin
, 1);
1001 INIT_DELAYED_WORK(&priv
->ath9k_led_blink_work
, ath9k_led_blink_work
);
1003 trigger
= ieee80211_get_radio_led_name(priv
->hw
);
1004 snprintf(priv
->radio_led
.name
, sizeof(priv
->radio_led
.name
),
1005 "ath9k-%s::radio", wiphy_name(priv
->hw
->wiphy
));
1006 ret
= ath9k_register_led(priv
, &priv
->radio_led
, trigger
);
1007 priv
->radio_led
.led_type
= ATH_LED_RADIO
;
1011 trigger
= ieee80211_get_assoc_led_name(priv
->hw
);
1012 snprintf(priv
->assoc_led
.name
, sizeof(priv
->assoc_led
.name
),
1013 "ath9k-%s::assoc", wiphy_name(priv
->hw
->wiphy
));
1014 ret
= ath9k_register_led(priv
, &priv
->assoc_led
, trigger
);
1015 priv
->assoc_led
.led_type
= ATH_LED_ASSOC
;
1019 trigger
= ieee80211_get_tx_led_name(priv
->hw
);
1020 snprintf(priv
->tx_led
.name
, sizeof(priv
->tx_led
.name
),
1021 "ath9k-%s::tx", wiphy_name(priv
->hw
->wiphy
));
1022 ret
= ath9k_register_led(priv
, &priv
->tx_led
, trigger
);
1023 priv
->tx_led
.led_type
= ATH_LED_TX
;
1027 trigger
= ieee80211_get_rx_led_name(priv
->hw
);
1028 snprintf(priv
->rx_led
.name
, sizeof(priv
->rx_led
.name
),
1029 "ath9k-%s::rx", wiphy_name(priv
->hw
->wiphy
));
1030 ret
= ath9k_register_led(priv
, &priv
->rx_led
, trigger
);
1031 priv
->rx_led
.led_type
= ATH_LED_RX
;
1035 priv
->op_flags
&= ~OP_LED_DEINIT
;
1040 cancel_delayed_work_sync(&priv
->ath9k_led_blink_work
);
1041 ath9k_deinit_leds(priv
);
1044 /*******************/
1046 /*******************/
1048 static bool ath_is_rfkill_set(struct ath9k_htc_priv
*priv
)
1050 return ath9k_hw_gpio_get(priv
->ah
, priv
->ah
->rfkill_gpio
) ==
1051 priv
->ah
->rfkill_polarity
;
1054 static void ath9k_htc_rfkill_poll_state(struct ieee80211_hw
*hw
)
1056 struct ath9k_htc_priv
*priv
= hw
->priv
;
1057 bool blocked
= !!ath_is_rfkill_set(priv
);
1059 wiphy_rfkill_set_hw_state(hw
->wiphy
, blocked
);
1062 void ath9k_start_rfkill_poll(struct ath9k_htc_priv
*priv
)
1064 if (priv
->ah
->caps
.hw_caps
& ATH9K_HW_CAP_RFSILENT
)
1065 wiphy_rfkill_start_polling(priv
->hw
->wiphy
);
1068 static void ath9k_htc_radio_enable(struct ieee80211_hw
*hw
)
1070 struct ath9k_htc_priv
*priv
= hw
->priv
;
1071 struct ath_hw
*ah
= priv
->ah
;
1072 struct ath_common
*common
= ath9k_hw_common(ah
);
1077 ah
->curchan
= ath9k_cmn_get_curchannel(hw
, ah
);
1080 ret
= ath9k_hw_reset(ah
, ah
->curchan
, ah
->caldata
, false);
1083 "Unable to reset hardware; reset status %d (freq %u MHz)\n",
1084 ret
, ah
->curchan
->channel
);
1087 ath_update_txpow(priv
);
1090 WMI_CMD(WMI_START_RECV_CMDID
);
1091 ath9k_host_rx_init(priv
);
1094 htc_start(priv
->htc
);
1095 spin_lock_bh(&priv
->tx_lock
);
1096 priv
->tx_queues_stop
= false;
1097 spin_unlock_bh(&priv
->tx_lock
);
1098 ieee80211_wake_queues(hw
);
1100 WMI_CMD(WMI_ENABLE_INTR_CMDID
);
1103 ath9k_hw_cfg_output(ah
, ah
->led_pin
,
1104 AR_GPIO_OUTPUT_MUX_AS_OUTPUT
);
1105 ath9k_hw_set_gpio(ah
, ah
->led_pin
, 0);
1108 static void ath9k_htc_radio_disable(struct ieee80211_hw
*hw
)
1110 struct ath9k_htc_priv
*priv
= hw
->priv
;
1111 struct ath_hw
*ah
= priv
->ah
;
1112 struct ath_common
*common
= ath9k_hw_common(ah
);
1116 ath9k_htc_ps_wakeup(priv
);
1119 ath9k_hw_set_gpio(ah
, ah
->led_pin
, 1);
1120 ath9k_hw_cfg_gpio_input(ah
, ah
->led_pin
);
1122 WMI_CMD(WMI_DISABLE_INTR_CMDID
);
1125 ieee80211_stop_queues(hw
);
1126 htc_stop(priv
->htc
);
1127 WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID
);
1128 skb_queue_purge(&priv
->tx_queue
);
1131 WMI_CMD(WMI_STOP_RECV_CMDID
);
1134 * The MIB counters have to be disabled here,
1135 * since the target doesn't do it.
1137 ath9k_hw_disable_mib_counters(ah
);
1140 ah
->curchan
= ath9k_cmn_get_curchannel(hw
, ah
);
1143 ret
= ath9k_hw_reset(ah
, ah
->curchan
, ah
->caldata
, false);
1146 "Unable to reset hardware; reset status %d (freq %u MHz)\n",
1147 ret
, ah
->curchan
->channel
);
1150 /* Disable the PHY */
1151 ath9k_hw_phy_disable(ah
);
1153 ath9k_htc_ps_restore(priv
);
1154 ath9k_htc_setpower(priv
, ATH9K_PM_FULL_SLEEP
);
1157 /**********************/
1158 /* mac80211 Callbacks */
1159 /**********************/
1161 static int ath9k_htc_tx(struct ieee80211_hw
*hw
, struct sk_buff
*skb
)
1163 struct ieee80211_hdr
*hdr
;
1164 struct ath9k_htc_priv
*priv
= hw
->priv
;
1165 int padpos
, padsize
, ret
;
1167 hdr
= (struct ieee80211_hdr
*) skb
->data
;
1169 /* Add the padding after the header if this is not already done */
1170 padpos
= ath9k_cmn_padpos(hdr
->frame_control
);
1171 padsize
= padpos
& 3;
1172 if (padsize
&& skb
->len
> padpos
) {
1173 if (skb_headroom(skb
) < padsize
)
1175 skb_push(skb
, padsize
);
1176 memmove(skb
->data
, skb
->data
+ padsize
, padpos
);
1179 ret
= ath9k_htc_tx_start(priv
, skb
);
1181 if (ret
== -ENOMEM
) {
1182 ath_dbg(ath9k_hw_common(priv
->ah
), ATH_DBG_XMIT
,
1183 "Stopping TX queues\n");
1184 ieee80211_stop_queues(hw
);
1185 spin_lock_bh(&priv
->tx_lock
);
1186 priv
->tx_queues_stop
= true;
1187 spin_unlock_bh(&priv
->tx_lock
);
1189 ath_dbg(ath9k_hw_common(priv
->ah
), ATH_DBG_XMIT
,
1198 dev_kfree_skb_any(skb
);
1202 static int ath9k_htc_start(struct ieee80211_hw
*hw
)
1204 struct ath9k_htc_priv
*priv
= hw
->priv
;
1205 struct ath_hw
*ah
= priv
->ah
;
1206 struct ath_common
*common
= ath9k_hw_common(ah
);
1207 struct ieee80211_channel
*curchan
= hw
->conf
.channel
;
1208 struct ath9k_channel
*init_channel
;
1210 enum htc_phymode mode
;
1214 mutex_lock(&priv
->mutex
);
1216 ath_dbg(common
, ATH_DBG_CONFIG
,
1217 "Starting driver with initial channel: %d MHz\n",
1218 curchan
->center_freq
);
1220 /* Ensure that HW is awake before flushing RX */
1221 ath9k_htc_setpower(priv
, ATH9K_PM_AWAKE
);
1222 WMI_CMD(WMI_FLUSH_RECV_CMDID
);
1224 /* setup initial channel */
1225 init_channel
= ath9k_cmn_get_curchannel(hw
, ah
);
1227 ath9k_hw_htc_resetinit(ah
);
1228 ret
= ath9k_hw_reset(ah
, init_channel
, ah
->caldata
, false);
1231 "Unable to reset hardware; reset status %d (freq %u MHz)\n",
1232 ret
, curchan
->center_freq
);
1233 mutex_unlock(&priv
->mutex
);
1237 ath_update_txpow(priv
);
1239 mode
= ath9k_htc_get_curmode(priv
, init_channel
);
1240 htc_mode
= cpu_to_be16(mode
);
1241 WMI_CMD_BUF(WMI_SET_MODE_CMDID
, &htc_mode
);
1242 WMI_CMD(WMI_ATH_INIT_CMDID
);
1243 WMI_CMD(WMI_START_RECV_CMDID
);
1245 ath9k_host_rx_init(priv
);
1247 priv
->op_flags
&= ~OP_INVALID
;
1248 htc_start(priv
->htc
);
1250 spin_lock_bh(&priv
->tx_lock
);
1251 priv
->tx_queues_stop
= false;
1252 spin_unlock_bh(&priv
->tx_lock
);
1254 ieee80211_wake_queues(hw
);
1256 if (ah
->btcoex_hw
.scheme
== ATH_BTCOEX_CFG_3WIRE
) {
1257 ath9k_hw_btcoex_set_weight(ah
, AR_BT_COEX_WGHT
,
1258 AR_STOMP_LOW_WLAN_WGHT
);
1259 ath9k_hw_btcoex_enable(ah
);
1260 ath_htc_resume_btcoex_work(priv
);
1262 mutex_unlock(&priv
->mutex
);
1267 static void ath9k_htc_stop(struct ieee80211_hw
*hw
)
1269 struct ath9k_htc_priv
*priv
= hw
->priv
;
1270 struct ath_hw
*ah
= priv
->ah
;
1271 struct ath_common
*common
= ath9k_hw_common(ah
);
1275 /* Cancel all the running timers/work .. */
1276 cancel_work_sync(&priv
->fatal_work
);
1277 cancel_work_sync(&priv
->ps_work
);
1278 cancel_delayed_work_sync(&priv
->ath9k_led_blink_work
);
1279 ath9k_led_stop_brightness(priv
);
1281 mutex_lock(&priv
->mutex
);
1283 if (priv
->op_flags
& OP_INVALID
) {
1284 ath_dbg(common
, ATH_DBG_ANY
, "Device not present\n");
1285 mutex_unlock(&priv
->mutex
);
1289 ath9k_htc_ps_wakeup(priv
);
1290 htc_stop(priv
->htc
);
1291 WMI_CMD(WMI_DISABLE_INTR_CMDID
);
1292 WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID
);
1293 WMI_CMD(WMI_STOP_RECV_CMDID
);
1294 skb_queue_purge(&priv
->tx_queue
);
1296 /* Remove monitor interface here */
1297 if (ah
->opmode
== NL80211_IFTYPE_MONITOR
) {
1298 if (ath9k_htc_remove_monitor_interface(priv
))
1299 ath_err(common
, "Unable to remove monitor interface\n");
1301 ath_dbg(common
, ATH_DBG_CONFIG
,
1302 "Monitor interface removed\n");
1305 if (ah
->btcoex_hw
.enabled
) {
1306 ath9k_hw_btcoex_disable(ah
);
1307 if (ah
->btcoex_hw
.scheme
== ATH_BTCOEX_CFG_3WIRE
)
1308 ath_htc_cancel_btcoex_work(priv
);
1311 ath9k_hw_phy_disable(ah
);
1312 ath9k_hw_disable(ah
);
1313 ath9k_htc_ps_restore(priv
);
1314 ath9k_htc_setpower(priv
, ATH9K_PM_FULL_SLEEP
);
1316 priv
->op_flags
|= OP_INVALID
;
1318 ath_dbg(common
, ATH_DBG_CONFIG
, "Driver halt\n");
1319 mutex_unlock(&priv
->mutex
);
1322 static int ath9k_htc_add_interface(struct ieee80211_hw
*hw
,
1323 struct ieee80211_vif
*vif
)
1325 struct ath9k_htc_priv
*priv
= hw
->priv
;
1326 struct ath9k_htc_vif
*avp
= (void *)vif
->drv_priv
;
1327 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
1328 struct ath9k_htc_target_vif hvif
;
1332 mutex_lock(&priv
->mutex
);
1334 /* Only one interface for now */
1335 if (priv
->nvifs
> 0) {
1340 ath9k_htc_ps_wakeup(priv
);
1341 memset(&hvif
, 0, sizeof(struct ath9k_htc_target_vif
));
1342 memcpy(&hvif
.myaddr
, vif
->addr
, ETH_ALEN
);
1344 switch (vif
->type
) {
1345 case NL80211_IFTYPE_STATION
:
1346 hvif
.opmode
= cpu_to_be32(HTC_M_STA
);
1348 case NL80211_IFTYPE_ADHOC
:
1349 hvif
.opmode
= cpu_to_be32(HTC_M_IBSS
);
1353 "Interface type %d not yet supported\n", vif
->type
);
1358 ath_dbg(common
, ATH_DBG_CONFIG
,
1359 "Attach a VIF of type: %d\n", vif
->type
);
1361 priv
->ah
->opmode
= vif
->type
;
1363 /* Index starts from zero on the target */
1364 avp
->index
= hvif
.index
= priv
->nvifs
;
1365 hvif
.rtsthreshold
= cpu_to_be16(2304);
1366 WMI_CMD_BUF(WMI_VAP_CREATE_CMDID
, &hvif
);
1373 * We need a node in target to tx mgmt frames
1374 * before association.
1376 ret
= ath9k_htc_add_station(priv
, vif
, NULL
);
1380 ret
= ath9k_htc_update_cap_target(priv
);
1382 ath_dbg(common
, ATH_DBG_CONFIG
,
1383 "Failed to update capability in target\n");
1387 ath9k_htc_ps_restore(priv
);
1388 mutex_unlock(&priv
->mutex
);
1393 static void ath9k_htc_remove_interface(struct ieee80211_hw
*hw
,
1394 struct ieee80211_vif
*vif
)
1396 struct ath9k_htc_priv
*priv
= hw
->priv
;
1397 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
1398 struct ath9k_htc_vif
*avp
= (void *)vif
->drv_priv
;
1399 struct ath9k_htc_target_vif hvif
;
1403 ath_dbg(common
, ATH_DBG_CONFIG
, "Detach Interface\n");
1405 mutex_lock(&priv
->mutex
);
1406 ath9k_htc_ps_wakeup(priv
);
1408 memset(&hvif
, 0, sizeof(struct ath9k_htc_target_vif
));
1409 memcpy(&hvif
.myaddr
, vif
->addr
, ETH_ALEN
);
1410 hvif
.index
= avp
->index
;
1411 WMI_CMD_BUF(WMI_VAP_REMOVE_CMDID
, &hvif
);
1414 ath9k_htc_remove_station(priv
, vif
, NULL
);
1417 ath9k_htc_ps_restore(priv
);
1418 mutex_unlock(&priv
->mutex
);
1421 static int ath9k_htc_config(struct ieee80211_hw
*hw
, u32 changed
)
1423 struct ath9k_htc_priv
*priv
= hw
->priv
;
1424 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
1425 struct ieee80211_conf
*conf
= &hw
->conf
;
1427 mutex_lock(&priv
->mutex
);
1429 if (changed
& IEEE80211_CONF_CHANGE_IDLE
) {
1430 bool enable_radio
= false;
1431 bool idle
= !!(conf
->flags
& IEEE80211_CONF_IDLE
);
1433 mutex_lock(&priv
->htc_pm_lock
);
1434 if (!idle
&& priv
->ps_idle
)
1435 enable_radio
= true;
1436 priv
->ps_idle
= idle
;
1437 mutex_unlock(&priv
->htc_pm_lock
);
1440 ath_dbg(common
, ATH_DBG_CONFIG
,
1441 "not-idle: enabling radio\n");
1442 ath9k_htc_setpower(priv
, ATH9K_PM_AWAKE
);
1443 ath9k_htc_radio_enable(hw
);
1447 if (changed
& IEEE80211_CONF_CHANGE_CHANNEL
) {
1448 struct ieee80211_channel
*curchan
= hw
->conf
.channel
;
1449 int pos
= curchan
->hw_value
;
1451 ath_dbg(common
, ATH_DBG_CONFIG
, "Set channel: %d MHz\n",
1452 curchan
->center_freq
);
1454 ath9k_cmn_update_ichannel(&priv
->ah
->channels
[pos
],
1456 hw
->conf
.channel_type
);
1458 if (ath9k_htc_set_channel(priv
, hw
, &priv
->ah
->channels
[pos
]) < 0) {
1459 ath_err(common
, "Unable to set channel\n");
1460 mutex_unlock(&priv
->mutex
);
1466 if (changed
& IEEE80211_CONF_CHANGE_PS
) {
1467 if (conf
->flags
& IEEE80211_CONF_PS
) {
1468 ath9k_htc_setpower(priv
, ATH9K_PM_NETWORK_SLEEP
);
1469 priv
->ps_enabled
= true;
1471 priv
->ps_enabled
= false;
1472 cancel_work_sync(&priv
->ps_work
);
1473 ath9k_htc_setpower(priv
, ATH9K_PM_AWAKE
);
1477 if (changed
& IEEE80211_CONF_CHANGE_POWER
) {
1478 priv
->txpowlimit
= 2 * conf
->power_level
;
1479 ath_update_txpow(priv
);
1482 if (changed
& IEEE80211_CONF_CHANGE_MONITOR
) {
1483 if (conf
->flags
& IEEE80211_CONF_MONITOR
) {
1484 if (ath9k_htc_add_monitor_interface(priv
))
1485 ath_err(common
, "Failed to set monitor mode\n");
1487 ath_dbg(common
, ATH_DBG_CONFIG
,
1488 "HW opmode set to Monitor mode\n");
1492 if (changed
& IEEE80211_CONF_CHANGE_IDLE
) {
1493 mutex_lock(&priv
->htc_pm_lock
);
1494 if (!priv
->ps_idle
) {
1495 mutex_unlock(&priv
->htc_pm_lock
);
1498 mutex_unlock(&priv
->htc_pm_lock
);
1500 ath_dbg(common
, ATH_DBG_CONFIG
,
1501 "idle: disabling radio\n");
1502 ath9k_htc_radio_disable(hw
);
1506 mutex_unlock(&priv
->mutex
);
1510 #define SUPPORTED_FILTERS \
1511 (FIF_PROMISC_IN_BSS | \
1516 FIF_BCN_PRBRESP_PROMISC | \
1520 static void ath9k_htc_configure_filter(struct ieee80211_hw
*hw
,
1521 unsigned int changed_flags
,
1522 unsigned int *total_flags
,
1525 struct ath9k_htc_priv
*priv
= hw
->priv
;
1528 mutex_lock(&priv
->mutex
);
1529 ath9k_htc_ps_wakeup(priv
);
1531 changed_flags
&= SUPPORTED_FILTERS
;
1532 *total_flags
&= SUPPORTED_FILTERS
;
1534 priv
->rxfilter
= *total_flags
;
1535 rfilt
= ath9k_htc_calcrxfilter(priv
);
1536 ath9k_hw_setrxfilter(priv
->ah
, rfilt
);
1538 ath_dbg(ath9k_hw_common(priv
->ah
), ATH_DBG_CONFIG
,
1539 "Set HW RX filter: 0x%x\n", rfilt
);
1541 ath9k_htc_ps_restore(priv
);
1542 mutex_unlock(&priv
->mutex
);
1545 static int ath9k_htc_sta_add(struct ieee80211_hw
*hw
,
1546 struct ieee80211_vif
*vif
,
1547 struct ieee80211_sta
*sta
)
1549 struct ath9k_htc_priv
*priv
= hw
->priv
;
1552 mutex_lock(&priv
->mutex
);
1553 ath9k_htc_ps_wakeup(priv
);
1554 ret
= ath9k_htc_add_station(priv
, vif
, sta
);
1556 ath9k_htc_init_rate(priv
, sta
);
1557 ath9k_htc_ps_restore(priv
);
1558 mutex_unlock(&priv
->mutex
);
1563 static int ath9k_htc_sta_remove(struct ieee80211_hw
*hw
,
1564 struct ieee80211_vif
*vif
,
1565 struct ieee80211_sta
*sta
)
1567 struct ath9k_htc_priv
*priv
= hw
->priv
;
1570 mutex_lock(&priv
->mutex
);
1571 ath9k_htc_ps_wakeup(priv
);
1572 ret
= ath9k_htc_remove_station(priv
, vif
, sta
);
1573 ath9k_htc_ps_restore(priv
);
1574 mutex_unlock(&priv
->mutex
);
1579 static int ath9k_htc_conf_tx(struct ieee80211_hw
*hw
, u16 queue
,
1580 const struct ieee80211_tx_queue_params
*params
)
1582 struct ath9k_htc_priv
*priv
= hw
->priv
;
1583 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
1584 struct ath9k_tx_queue_info qi
;
1587 if (queue
>= WME_NUM_AC
)
1590 mutex_lock(&priv
->mutex
);
1591 ath9k_htc_ps_wakeup(priv
);
1593 memset(&qi
, 0, sizeof(struct ath9k_tx_queue_info
));
1595 qi
.tqi_aifs
= params
->aifs
;
1596 qi
.tqi_cwmin
= params
->cw_min
;
1597 qi
.tqi_cwmax
= params
->cw_max
;
1598 qi
.tqi_burstTime
= params
->txop
;
1600 qnum
= get_hw_qnum(queue
, priv
->hwq_map
);
1602 ath_dbg(common
, ATH_DBG_CONFIG
,
1603 "Configure tx [queue/hwq] [%d/%d], aifs: %d, cw_min: %d, cw_max: %d, txop: %d\n",
1604 queue
, qnum
, params
->aifs
, params
->cw_min
,
1605 params
->cw_max
, params
->txop
);
1607 ret
= ath_htc_txq_update(priv
, qnum
, &qi
);
1609 ath_err(common
, "TXQ Update failed\n");
1613 if ((priv
->ah
->opmode
== NL80211_IFTYPE_ADHOC
) &&
1614 (qnum
== priv
->hwq_map
[WME_AC_BE
]))
1615 ath9k_htc_beaconq_config(priv
);
1617 ath9k_htc_ps_restore(priv
);
1618 mutex_unlock(&priv
->mutex
);
1623 static int ath9k_htc_set_key(struct ieee80211_hw
*hw
,
1624 enum set_key_cmd cmd
,
1625 struct ieee80211_vif
*vif
,
1626 struct ieee80211_sta
*sta
,
1627 struct ieee80211_key_conf
*key
)
1629 struct ath9k_htc_priv
*priv
= hw
->priv
;
1630 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
1633 if (htc_modparam_nohwcrypt
)
1636 mutex_lock(&priv
->mutex
);
1637 ath_dbg(common
, ATH_DBG_CONFIG
, "Set HW Key\n");
1638 ath9k_htc_ps_wakeup(priv
);
1642 ret
= ath_key_config(common
, vif
, sta
, key
);
1644 key
->hw_key_idx
= ret
;
1645 /* push IV and Michael MIC generation to stack */
1646 key
->flags
|= IEEE80211_KEY_FLAG_GENERATE_IV
;
1647 if (key
->cipher
== WLAN_CIPHER_SUITE_TKIP
)
1648 key
->flags
|= IEEE80211_KEY_FLAG_GENERATE_MMIC
;
1649 if (priv
->ah
->sw_mgmt_crypto
&&
1650 key
->cipher
== WLAN_CIPHER_SUITE_CCMP
)
1651 key
->flags
|= IEEE80211_KEY_FLAG_SW_MGMT
;
1656 ath_key_delete(common
, key
);
1662 ath9k_htc_ps_restore(priv
);
1663 mutex_unlock(&priv
->mutex
);
1668 static void ath9k_htc_bss_info_changed(struct ieee80211_hw
*hw
,
1669 struct ieee80211_vif
*vif
,
1670 struct ieee80211_bss_conf
*bss_conf
,
1673 struct ath9k_htc_priv
*priv
= hw
->priv
;
1674 struct ath_hw
*ah
= priv
->ah
;
1675 struct ath_common
*common
= ath9k_hw_common(ah
);
1677 mutex_lock(&priv
->mutex
);
1678 ath9k_htc_ps_wakeup(priv
);
1680 if (changed
& BSS_CHANGED_ASSOC
) {
1681 common
->curaid
= bss_conf
->assoc
?
1683 ath_dbg(common
, ATH_DBG_CONFIG
, "BSS Changed ASSOC %d\n",
1686 if (bss_conf
->assoc
) {
1687 priv
->op_flags
|= OP_ASSOCIATED
;
1688 ath_start_ani(priv
);
1690 priv
->op_flags
&= ~OP_ASSOCIATED
;
1691 cancel_delayed_work_sync(&priv
->ath9k_ani_work
);
1695 if (changed
& BSS_CHANGED_BSSID
) {
1697 memcpy(common
->curbssid
, bss_conf
->bssid
, ETH_ALEN
);
1698 ath9k_hw_write_associd(ah
);
1700 ath_dbg(common
, ATH_DBG_CONFIG
,
1701 "BSSID: %pM aid: 0x%x\n",
1702 common
->curbssid
, common
->curaid
);
1705 if ((changed
& BSS_CHANGED_BEACON_INT
) ||
1706 (changed
& BSS_CHANGED_BEACON
) ||
1707 ((changed
& BSS_CHANGED_BEACON_ENABLED
) &&
1708 bss_conf
->enable_beacon
)) {
1709 priv
->op_flags
|= OP_ENABLE_BEACON
;
1710 ath9k_htc_beacon_config(priv
, vif
);
1713 if ((changed
& BSS_CHANGED_BEACON_ENABLED
) &&
1714 !bss_conf
->enable_beacon
) {
1715 priv
->op_flags
&= ~OP_ENABLE_BEACON
;
1716 ath9k_htc_beacon_config(priv
, vif
);
1719 if (changed
& BSS_CHANGED_ERP_PREAMBLE
) {
1720 ath_dbg(common
, ATH_DBG_CONFIG
, "BSS Changed PREAMBLE %d\n",
1721 bss_conf
->use_short_preamble
);
1722 if (bss_conf
->use_short_preamble
)
1723 priv
->op_flags
|= OP_PREAMBLE_SHORT
;
1725 priv
->op_flags
&= ~OP_PREAMBLE_SHORT
;
1728 if (changed
& BSS_CHANGED_ERP_CTS_PROT
) {
1729 ath_dbg(common
, ATH_DBG_CONFIG
, "BSS Changed CTS PROT %d\n",
1730 bss_conf
->use_cts_prot
);
1731 if (bss_conf
->use_cts_prot
&&
1732 hw
->conf
.channel
->band
!= IEEE80211_BAND_5GHZ
)
1733 priv
->op_flags
|= OP_PROTECT_ENABLE
;
1735 priv
->op_flags
&= ~OP_PROTECT_ENABLE
;
1738 if (changed
& BSS_CHANGED_ERP_SLOT
) {
1739 if (bss_conf
->use_short_slot
)
1744 ath9k_hw_init_global_settings(ah
);
1747 if (changed
& BSS_CHANGED_HT
)
1748 ath9k_htc_update_rate(priv
, vif
, bss_conf
);
1750 ath9k_htc_ps_restore(priv
);
1751 mutex_unlock(&priv
->mutex
);
1754 static u64
ath9k_htc_get_tsf(struct ieee80211_hw
*hw
)
1756 struct ath9k_htc_priv
*priv
= hw
->priv
;
1759 mutex_lock(&priv
->mutex
);
1760 ath9k_htc_ps_wakeup(priv
);
1761 tsf
= ath9k_hw_gettsf64(priv
->ah
);
1762 ath9k_htc_ps_restore(priv
);
1763 mutex_unlock(&priv
->mutex
);
1768 static void ath9k_htc_set_tsf(struct ieee80211_hw
*hw
, u64 tsf
)
1770 struct ath9k_htc_priv
*priv
= hw
->priv
;
1772 mutex_lock(&priv
->mutex
);
1773 ath9k_htc_ps_wakeup(priv
);
1774 ath9k_hw_settsf64(priv
->ah
, tsf
);
1775 ath9k_htc_ps_restore(priv
);
1776 mutex_unlock(&priv
->mutex
);
1779 static void ath9k_htc_reset_tsf(struct ieee80211_hw
*hw
)
1781 struct ath9k_htc_priv
*priv
= hw
->priv
;
1783 mutex_lock(&priv
->mutex
);
1784 ath9k_htc_ps_wakeup(priv
);
1785 ath9k_hw_reset_tsf(priv
->ah
);
1786 ath9k_htc_ps_restore(priv
);
1787 mutex_unlock(&priv
->mutex
);
1790 static int ath9k_htc_ampdu_action(struct ieee80211_hw
*hw
,
1791 struct ieee80211_vif
*vif
,
1792 enum ieee80211_ampdu_mlme_action action
,
1793 struct ieee80211_sta
*sta
,
1796 struct ath9k_htc_priv
*priv
= hw
->priv
;
1797 struct ath9k_htc_sta
*ista
;
1801 case IEEE80211_AMPDU_RX_START
:
1803 case IEEE80211_AMPDU_RX_STOP
:
1805 case IEEE80211_AMPDU_TX_START
:
1806 ret
= ath9k_htc_tx_aggr_oper(priv
, vif
, sta
, action
, tid
);
1808 ieee80211_start_tx_ba_cb_irqsafe(vif
, sta
->addr
, tid
);
1810 case IEEE80211_AMPDU_TX_STOP
:
1811 ath9k_htc_tx_aggr_oper(priv
, vif
, sta
, action
, tid
);
1812 ieee80211_stop_tx_ba_cb_irqsafe(vif
, sta
->addr
, tid
);
1814 case IEEE80211_AMPDU_TX_OPERATIONAL
:
1815 ista
= (struct ath9k_htc_sta
*) sta
->drv_priv
;
1816 spin_lock_bh(&priv
->tx_lock
);
1817 ista
->tid_state
[tid
] = AGGR_OPERATIONAL
;
1818 spin_unlock_bh(&priv
->tx_lock
);
1821 ath_err(ath9k_hw_common(priv
->ah
), "Unknown AMPDU action\n");
1827 static void ath9k_htc_sw_scan_start(struct ieee80211_hw
*hw
)
1829 struct ath9k_htc_priv
*priv
= hw
->priv
;
1831 mutex_lock(&priv
->mutex
);
1832 spin_lock_bh(&priv
->beacon_lock
);
1833 priv
->op_flags
|= OP_SCANNING
;
1834 spin_unlock_bh(&priv
->beacon_lock
);
1835 cancel_work_sync(&priv
->ps_work
);
1836 if (priv
->op_flags
& OP_ASSOCIATED
)
1837 cancel_delayed_work_sync(&priv
->ath9k_ani_work
);
1838 mutex_unlock(&priv
->mutex
);
1841 static void ath9k_htc_sw_scan_complete(struct ieee80211_hw
*hw
)
1843 struct ath9k_htc_priv
*priv
= hw
->priv
;
1845 mutex_lock(&priv
->mutex
);
1846 ath9k_htc_ps_wakeup(priv
);
1847 spin_lock_bh(&priv
->beacon_lock
);
1848 priv
->op_flags
&= ~OP_SCANNING
;
1849 spin_unlock_bh(&priv
->beacon_lock
);
1850 priv
->op_flags
|= OP_FULL_RESET
;
1851 if (priv
->op_flags
& OP_ASSOCIATED
) {
1852 ath9k_htc_beacon_config(priv
, priv
->vif
);
1853 ath_start_ani(priv
);
1855 ath9k_htc_ps_restore(priv
);
1856 mutex_unlock(&priv
->mutex
);
1859 static int ath9k_htc_set_rts_threshold(struct ieee80211_hw
*hw
, u32 value
)
1864 static void ath9k_htc_set_coverage_class(struct ieee80211_hw
*hw
,
1867 struct ath9k_htc_priv
*priv
= hw
->priv
;
1869 mutex_lock(&priv
->mutex
);
1870 ath9k_htc_ps_wakeup(priv
);
1871 priv
->ah
->coverage_class
= coverage_class
;
1872 ath9k_hw_init_global_settings(priv
->ah
);
1873 ath9k_htc_ps_restore(priv
);
1874 mutex_unlock(&priv
->mutex
);
1877 struct ieee80211_ops ath9k_htc_ops
= {
1879 .start
= ath9k_htc_start
,
1880 .stop
= ath9k_htc_stop
,
1881 .add_interface
= ath9k_htc_add_interface
,
1882 .remove_interface
= ath9k_htc_remove_interface
,
1883 .config
= ath9k_htc_config
,
1884 .configure_filter
= ath9k_htc_configure_filter
,
1885 .sta_add
= ath9k_htc_sta_add
,
1886 .sta_remove
= ath9k_htc_sta_remove
,
1887 .conf_tx
= ath9k_htc_conf_tx
,
1888 .bss_info_changed
= ath9k_htc_bss_info_changed
,
1889 .set_key
= ath9k_htc_set_key
,
1890 .get_tsf
= ath9k_htc_get_tsf
,
1891 .set_tsf
= ath9k_htc_set_tsf
,
1892 .reset_tsf
= ath9k_htc_reset_tsf
,
1893 .ampdu_action
= ath9k_htc_ampdu_action
,
1894 .sw_scan_start
= ath9k_htc_sw_scan_start
,
1895 .sw_scan_complete
= ath9k_htc_sw_scan_complete
,
1896 .set_rts_threshold
= ath9k_htc_set_rts_threshold
,
1897 .rfkill_poll
= ath9k_htc_rfkill_poll_state
,
1898 .set_coverage_class
= ath9k_htc_set_coverage_class
,