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
);
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 static 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 static int ath9k_htc_set_channel(struct ath9k_htc_priv
*priv
,
120 struct ieee80211_hw
*hw
,
121 struct ath9k_channel
*hchan
)
123 struct ath_hw
*ah
= priv
->ah
;
124 struct ath_common
*common
= ath9k_hw_common(ah
);
125 struct ieee80211_conf
*conf
= &common
->hw
->conf
;
127 struct ieee80211_channel
*channel
= hw
->conf
.channel
;
128 struct ath9k_hw_cal_data
*caldata
;
129 enum htc_phymode mode
;
134 if (priv
->op_flags
& OP_INVALID
)
137 if (priv
->op_flags
& OP_FULL_RESET
)
140 /* Fiddle around with fastcc later on, for now just use full reset */
142 ath9k_htc_ps_wakeup(priv
);
144 WMI_CMD(WMI_DISABLE_INTR_CMDID
);
145 WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID
);
146 WMI_CMD(WMI_STOP_RECV_CMDID
);
148 ath_print(common
, ATH_DBG_CONFIG
,
149 "(%u MHz) -> (%u MHz), HT: %d, HT40: %d\n",
150 priv
->ah
->curchan
->channel
,
151 channel
->center_freq
, conf_is_ht(conf
), conf_is_ht40(conf
));
153 caldata
= &priv
->caldata
[channel
->hw_value
];
154 ret
= ath9k_hw_reset(ah
, hchan
, caldata
, 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
= priv
->ah
->caps
.tx_chainmask
;
330 tcap
.tx_chainmask
= priv
->ah
->caps
.tx_chainmask
;
332 WMI_CMD_BUF(WMI_TARGET_IC_UPDATE_CMDID
, &tcap
);
337 static void ath9k_htc_setup_rate(struct ath9k_htc_priv
*priv
,
338 struct ieee80211_sta
*sta
,
339 struct ath9k_htc_target_rate
*trate
)
341 struct ath9k_htc_sta
*ista
= (struct ath9k_htc_sta
*) sta
->drv_priv
;
342 struct ieee80211_supported_band
*sband
;
346 sband
= priv
->hw
->wiphy
->bands
[priv
->hw
->conf
.channel
->band
];
348 for (i
= 0, j
= 0; i
< sband
->n_bitrates
; i
++) {
349 if (sta
->supp_rates
[sband
->band
] & BIT(i
)) {
350 trate
->rates
.legacy_rates
.rs_rates
[j
]
351 = (sband
->bitrates
[i
].bitrate
* 2) / 10;
355 trate
->rates
.legacy_rates
.rs_nrates
= j
;
357 if (sta
->ht_cap
.ht_supported
) {
358 for (i
= 0, j
= 0; i
< 77; i
++) {
359 if (sta
->ht_cap
.mcs
.rx_mask
[i
/8] & (1<<(i
%8)))
360 trate
->rates
.ht_rates
.rs_rates
[j
++] = i
;
361 if (j
== ATH_HTC_RATE_MAX
)
364 trate
->rates
.ht_rates
.rs_nrates
= j
;
366 caps
= WLAN_RC_HT_FLAG
;
367 if (sta
->ht_cap
.mcs
.rx_mask
[1])
368 caps
|= WLAN_RC_DS_FLAG
;
369 if ((sta
->ht_cap
.cap
& IEEE80211_HT_CAP_SUP_WIDTH_20_40
) &&
370 (conf_is_ht40(&priv
->hw
->conf
)))
371 caps
|= WLAN_RC_40_FLAG
;
372 if (conf_is_ht40(&priv
->hw
->conf
) &&
373 (sta
->ht_cap
.cap
& IEEE80211_HT_CAP_SGI_40
))
374 caps
|= WLAN_RC_SGI_FLAG
;
375 else if (conf_is_ht20(&priv
->hw
->conf
) &&
376 (sta
->ht_cap
.cap
& IEEE80211_HT_CAP_SGI_20
))
377 caps
|= WLAN_RC_SGI_FLAG
;
380 trate
->sta_index
= ista
->index
;
382 trate
->capflags
= cpu_to_be32(caps
);
385 static int ath9k_htc_send_rate_cmd(struct ath9k_htc_priv
*priv
,
386 struct ath9k_htc_target_rate
*trate
)
388 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
392 WMI_CMD_BUF(WMI_RC_RATE_UPDATE_CMDID
, trate
);
394 ath_print(common
, ATH_DBG_FATAL
,
395 "Unable to initialize Rate information on target\n");
401 static void ath9k_htc_init_rate(struct ath9k_htc_priv
*priv
,
402 struct ieee80211_sta
*sta
)
404 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
405 struct ath9k_htc_target_rate trate
;
408 memset(&trate
, 0, sizeof(struct ath9k_htc_target_rate
));
409 ath9k_htc_setup_rate(priv
, sta
, &trate
);
410 ret
= ath9k_htc_send_rate_cmd(priv
, &trate
);
412 ath_print(common
, ATH_DBG_CONFIG
,
413 "Updated target sta: %pM, rate caps: 0x%X\n",
414 sta
->addr
, be32_to_cpu(trate
.capflags
));
417 static void ath9k_htc_update_rate(struct ath9k_htc_priv
*priv
,
418 struct ieee80211_vif
*vif
,
419 struct ieee80211_bss_conf
*bss_conf
)
421 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
422 struct ath9k_htc_target_rate trate
;
423 struct ieee80211_sta
*sta
;
426 memset(&trate
, 0, sizeof(struct ath9k_htc_target_rate
));
429 sta
= ieee80211_find_sta(vif
, bss_conf
->bssid
);
434 ath9k_htc_setup_rate(priv
, sta
, &trate
);
437 ret
= ath9k_htc_send_rate_cmd(priv
, &trate
);
439 ath_print(common
, ATH_DBG_CONFIG
,
440 "Updated target sta: %pM, rate caps: 0x%X\n",
441 bss_conf
->bssid
, be32_to_cpu(trate
.capflags
));
444 static int ath9k_htc_tx_aggr_oper(struct ath9k_htc_priv
*priv
,
445 struct ieee80211_vif
*vif
,
446 struct ieee80211_sta
*sta
,
447 enum ieee80211_ampdu_mlme_action action
,
450 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
451 struct ath9k_htc_target_aggr aggr
;
452 struct ath9k_htc_sta
*ista
;
456 if (tid
>= ATH9K_HTC_MAX_TID
)
459 memset(&aggr
, 0, sizeof(struct ath9k_htc_target_aggr
));
460 ista
= (struct ath9k_htc_sta
*) sta
->drv_priv
;
462 aggr
.sta_index
= ista
->index
;
463 aggr
.tidno
= tid
& 0xf;
464 aggr
.aggr_enable
= (action
== IEEE80211_AMPDU_TX_START
) ? true : false;
466 WMI_CMD_BUF(WMI_TX_AGGR_ENABLE_CMDID
, &aggr
);
468 ath_print(common
, ATH_DBG_CONFIG
,
469 "Unable to %s TX aggregation for (%pM, %d)\n",
470 (aggr
.aggr_enable
) ? "start" : "stop", sta
->addr
, tid
);
472 ath_print(common
, ATH_DBG_CONFIG
,
473 "%s TX aggregation for (%pM, %d)\n",
474 (aggr
.aggr_enable
) ? "Starting" : "Stopping",
477 spin_lock_bh(&priv
->tx_lock
);
478 ista
->tid_state
[tid
] = (aggr
.aggr_enable
&& !ret
) ? AGGR_START
: AGGR_STOP
;
479 spin_unlock_bh(&priv
->tx_lock
);
488 #ifdef CONFIG_ATH9K_HTC_DEBUGFS
490 static int ath9k_debugfs_open(struct inode
*inode
, struct file
*file
)
492 file
->private_data
= inode
->i_private
;
496 static ssize_t
read_file_tgt_stats(struct file
*file
, char __user
*user_buf
,
497 size_t count
, loff_t
*ppos
)
499 struct ath9k_htc_priv
*priv
= file
->private_data
;
500 struct ath9k_htc_target_stats cmd_rsp
;
502 unsigned int len
= 0;
505 memset(&cmd_rsp
, 0, sizeof(cmd_rsp
));
507 WMI_CMD(WMI_TGT_STATS_CMDID
);
512 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
513 "%19s : %10u\n", "TX Short Retries",
514 be32_to_cpu(cmd_rsp
.tx_shortretry
));
515 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
516 "%19s : %10u\n", "TX Long Retries",
517 be32_to_cpu(cmd_rsp
.tx_longretry
));
518 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
519 "%19s : %10u\n", "TX Xretries",
520 be32_to_cpu(cmd_rsp
.tx_xretries
));
521 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
522 "%19s : %10u\n", "TX Unaggr. Xretries",
523 be32_to_cpu(cmd_rsp
.ht_txunaggr_xretry
));
524 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
525 "%19s : %10u\n", "TX Xretries (HT)",
526 be32_to_cpu(cmd_rsp
.ht_tx_xretries
));
527 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
528 "%19s : %10u\n", "TX Rate", priv
->debug
.txrate
);
530 if (len
> sizeof(buf
))
533 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, len
);
536 static const struct file_operations fops_tgt_stats
= {
537 .read
= read_file_tgt_stats
,
538 .open
= ath9k_debugfs_open
,
542 static ssize_t
read_file_xmit(struct file
*file
, char __user
*user_buf
,
543 size_t count
, loff_t
*ppos
)
545 struct ath9k_htc_priv
*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
);
561 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
562 "%20s : %10u\n", "SKBs dropped",
563 priv
->debug
.tx_stats
.skb_dropped
);
565 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
566 "%20s : %10u\n", "BE queued",
567 priv
->debug
.tx_stats
.queue_stats
[WME_AC_BE
]);
568 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
569 "%20s : %10u\n", "BK queued",
570 priv
->debug
.tx_stats
.queue_stats
[WME_AC_BK
]);
571 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
572 "%20s : %10u\n", "VI queued",
573 priv
->debug
.tx_stats
.queue_stats
[WME_AC_VI
]);
574 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
575 "%20s : %10u\n", "VO queued",
576 priv
->debug
.tx_stats
.queue_stats
[WME_AC_VO
]);
578 if (len
> sizeof(buf
))
581 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, len
);
584 static const struct file_operations fops_xmit
= {
585 .read
= read_file_xmit
,
586 .open
= ath9k_debugfs_open
,
590 static ssize_t
read_file_recv(struct file
*file
, char __user
*user_buf
,
591 size_t count
, loff_t
*ppos
)
593 struct ath9k_htc_priv
*priv
= file
->private_data
;
595 unsigned int len
= 0;
597 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
598 "%20s : %10u\n", "SKBs allocated",
599 priv
->debug
.rx_stats
.skb_allocated
);
600 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
601 "%20s : %10u\n", "SKBs completed",
602 priv
->debug
.rx_stats
.skb_completed
);
603 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
604 "%20s : %10u\n", "SKBs Dropped",
605 priv
->debug
.rx_stats
.skb_dropped
);
607 if (len
> sizeof(buf
))
610 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, len
);
613 static const struct file_operations fops_recv
= {
614 .read
= read_file_recv
,
615 .open
= ath9k_debugfs_open
,
619 int ath9k_htc_init_debug(struct ath_hw
*ah
)
621 struct ath_common
*common
= ath9k_hw_common(ah
);
622 struct ath9k_htc_priv
*priv
= (struct ath9k_htc_priv
*) common
->priv
;
624 if (!ath9k_debugfs_root
)
627 priv
->debug
.debugfs_phy
= debugfs_create_dir(wiphy_name(priv
->hw
->wiphy
),
629 if (!priv
->debug
.debugfs_phy
)
632 priv
->debug
.debugfs_tgt_stats
= debugfs_create_file("tgt_stats", S_IRUSR
,
633 priv
->debug
.debugfs_phy
,
634 priv
, &fops_tgt_stats
);
635 if (!priv
->debug
.debugfs_tgt_stats
)
639 priv
->debug
.debugfs_xmit
= debugfs_create_file("xmit", S_IRUSR
,
640 priv
->debug
.debugfs_phy
,
642 if (!priv
->debug
.debugfs_xmit
)
645 priv
->debug
.debugfs_recv
= debugfs_create_file("recv", S_IRUSR
,
646 priv
->debug
.debugfs_phy
,
648 if (!priv
->debug
.debugfs_recv
)
654 ath9k_htc_exit_debug(ah
);
658 void ath9k_htc_exit_debug(struct ath_hw
*ah
)
660 struct ath_common
*common
= ath9k_hw_common(ah
);
661 struct ath9k_htc_priv
*priv
= (struct ath9k_htc_priv
*) common
->priv
;
663 debugfs_remove(priv
->debug
.debugfs_recv
);
664 debugfs_remove(priv
->debug
.debugfs_xmit
);
665 debugfs_remove(priv
->debug
.debugfs_tgt_stats
);
666 debugfs_remove(priv
->debug
.debugfs_phy
);
669 int ath9k_htc_debug_create_root(void)
671 ath9k_debugfs_root
= debugfs_create_dir(KBUILD_MODNAME
, NULL
);
672 if (!ath9k_debugfs_root
)
678 void ath9k_htc_debug_remove_root(void)
680 debugfs_remove(ath9k_debugfs_root
);
681 ath9k_debugfs_root
= NULL
;
684 #endif /* CONFIG_ATH9K_HTC_DEBUGFS */
690 static void ath_start_ani(struct ath9k_htc_priv
*priv
)
692 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
693 unsigned long timestamp
= jiffies_to_msecs(jiffies
);
695 common
->ani
.longcal_timer
= timestamp
;
696 common
->ani
.shortcal_timer
= timestamp
;
697 common
->ani
.checkani_timer
= timestamp
;
699 ieee80211_queue_delayed_work(common
->hw
, &priv
->ath9k_ani_work
,
700 msecs_to_jiffies(ATH_ANI_POLLINTERVAL
));
703 void ath9k_ani_work(struct work_struct
*work
)
705 struct ath9k_htc_priv
*priv
=
706 container_of(work
, struct ath9k_htc_priv
,
707 ath9k_ani_work
.work
);
708 struct ath_hw
*ah
= priv
->ah
;
709 struct ath_common
*common
= ath9k_hw_common(ah
);
710 bool longcal
= false;
711 bool shortcal
= false;
712 bool aniflag
= false;
713 unsigned int timestamp
= jiffies_to_msecs(jiffies
);
714 u32 cal_interval
, short_cal_interval
;
716 short_cal_interval
= ATH_STA_SHORT_CALINTERVAL
;
718 /* Only calibrate if awake */
719 if (ah
->power_mode
!= ATH9K_PM_AWAKE
)
722 /* Long calibration runs independently of short calibration. */
723 if ((timestamp
- common
->ani
.longcal_timer
) >= ATH_LONG_CALINTERVAL
) {
725 ath_print(common
, ATH_DBG_ANI
, "longcal @%lu\n", jiffies
);
726 common
->ani
.longcal_timer
= timestamp
;
729 /* Short calibration applies only while caldone is false */
730 if (!common
->ani
.caldone
) {
731 if ((timestamp
- common
->ani
.shortcal_timer
) >=
732 short_cal_interval
) {
734 ath_print(common
, ATH_DBG_ANI
,
735 "shortcal @%lu\n", jiffies
);
736 common
->ani
.shortcal_timer
= timestamp
;
737 common
->ani
.resetcal_timer
= timestamp
;
740 if ((timestamp
- common
->ani
.resetcal_timer
) >=
741 ATH_RESTART_CALINTERVAL
) {
742 common
->ani
.caldone
= ath9k_hw_reset_calvalid(ah
);
743 if (common
->ani
.caldone
)
744 common
->ani
.resetcal_timer
= timestamp
;
748 /* Verify whether we must check ANI */
749 if ((timestamp
- common
->ani
.checkani_timer
) >= ATH_ANI_POLLINTERVAL
) {
751 common
->ani
.checkani_timer
= timestamp
;
754 /* Skip all processing if there's nothing to do. */
755 if (longcal
|| shortcal
|| aniflag
) {
757 ath9k_htc_ps_wakeup(priv
);
759 /* Call ANI routine if necessary */
761 ath9k_hw_ani_monitor(ah
, ah
->curchan
);
763 /* Perform calibration if necessary */
764 if (longcal
|| shortcal
) {
765 common
->ani
.caldone
=
766 ath9k_hw_calibrate(ah
, ah
->curchan
,
767 common
->rx_chainmask
,
771 common
->ani
.noise_floor
=
772 ath9k_hw_getchan_noise(ah
, ah
->curchan
);
774 ath_print(common
, ATH_DBG_ANI
,
775 " calibrate chan %u/%x nf: %d\n",
776 ah
->curchan
->channel
,
777 ah
->curchan
->channelFlags
,
778 common
->ani
.noise_floor
);
781 ath9k_htc_ps_restore(priv
);
786 * Set timer interval based on previous results.
787 * The interval must be the shortest necessary to satisfy ANI,
788 * short calibration and long calibration.
790 cal_interval
= ATH_LONG_CALINTERVAL
;
791 if (priv
->ah
->config
.enable_ani
)
792 cal_interval
= min(cal_interval
, (u32
)ATH_ANI_POLLINTERVAL
);
793 if (!common
->ani
.caldone
)
794 cal_interval
= min(cal_interval
, (u32
)short_cal_interval
);
796 ieee80211_queue_delayed_work(common
->hw
, &priv
->ath9k_ani_work
,
797 msecs_to_jiffies(cal_interval
));
804 static void ath9k_led_blink_work(struct work_struct
*work
)
806 struct ath9k_htc_priv
*priv
= container_of(work
, struct ath9k_htc_priv
,
807 ath9k_led_blink_work
.work
);
809 if (!(priv
->op_flags
& OP_LED_ASSOCIATED
))
812 if ((priv
->led_on_duration
== ATH_LED_ON_DURATION_IDLE
) ||
813 (priv
->led_off_duration
== ATH_LED_OFF_DURATION_IDLE
))
814 ath9k_hw_set_gpio(priv
->ah
, priv
->ah
->led_pin
, 0);
816 ath9k_hw_set_gpio(priv
->ah
, priv
->ah
->led_pin
,
817 (priv
->op_flags
& OP_LED_ON
) ? 1 : 0);
819 ieee80211_queue_delayed_work(priv
->hw
,
820 &priv
->ath9k_led_blink_work
,
821 (priv
->op_flags
& OP_LED_ON
) ?
822 msecs_to_jiffies(priv
->led_off_duration
) :
823 msecs_to_jiffies(priv
->led_on_duration
));
825 priv
->led_on_duration
= priv
->led_on_cnt
?
826 max((ATH_LED_ON_DURATION_IDLE
- priv
->led_on_cnt
), 25) :
827 ATH_LED_ON_DURATION_IDLE
;
828 priv
->led_off_duration
= priv
->led_off_cnt
?
829 max((ATH_LED_OFF_DURATION_IDLE
- priv
->led_off_cnt
), 10) :
830 ATH_LED_OFF_DURATION_IDLE
;
831 priv
->led_on_cnt
= priv
->led_off_cnt
= 0;
833 if (priv
->op_flags
& OP_LED_ON
)
834 priv
->op_flags
&= ~OP_LED_ON
;
836 priv
->op_flags
|= OP_LED_ON
;
839 static void ath9k_led_brightness_work(struct work_struct
*work
)
841 struct ath_led
*led
= container_of(work
, struct ath_led
,
842 brightness_work
.work
);
843 struct ath9k_htc_priv
*priv
= led
->priv
;
845 switch (led
->brightness
) {
847 if (led
->led_type
== ATH_LED_ASSOC
||
848 led
->led_type
== ATH_LED_RADIO
) {
849 ath9k_hw_set_gpio(priv
->ah
, priv
->ah
->led_pin
,
850 (led
->led_type
== ATH_LED_RADIO
));
851 priv
->op_flags
&= ~OP_LED_ASSOCIATED
;
852 if (led
->led_type
== ATH_LED_RADIO
)
853 priv
->op_flags
&= ~OP_LED_ON
;
859 if (led
->led_type
== ATH_LED_ASSOC
) {
860 priv
->op_flags
|= OP_LED_ASSOCIATED
;
861 ieee80211_queue_delayed_work(priv
->hw
,
862 &priv
->ath9k_led_blink_work
, 0);
863 } else if (led
->led_type
== ATH_LED_RADIO
) {
864 ath9k_hw_set_gpio(priv
->ah
, priv
->ah
->led_pin
, 0);
865 priv
->op_flags
|= OP_LED_ON
;
875 static void ath9k_led_brightness(struct led_classdev
*led_cdev
,
876 enum led_brightness brightness
)
878 struct ath_led
*led
= container_of(led_cdev
, struct ath_led
, led_cdev
);
879 struct ath9k_htc_priv
*priv
= led
->priv
;
881 led
->brightness
= brightness
;
882 if (!(priv
->op_flags
& OP_LED_DEINIT
))
883 ieee80211_queue_delayed_work(priv
->hw
,
884 &led
->brightness_work
, 0);
887 static void ath9k_led_stop_brightness(struct ath9k_htc_priv
*priv
)
889 cancel_delayed_work_sync(&priv
->radio_led
.brightness_work
);
890 cancel_delayed_work_sync(&priv
->assoc_led
.brightness_work
);
891 cancel_delayed_work_sync(&priv
->tx_led
.brightness_work
);
892 cancel_delayed_work_sync(&priv
->rx_led
.brightness_work
);
895 static int ath9k_register_led(struct ath9k_htc_priv
*priv
, struct ath_led
*led
,
901 led
->led_cdev
.name
= led
->name
;
902 led
->led_cdev
.default_trigger
= trigger
;
903 led
->led_cdev
.brightness_set
= ath9k_led_brightness
;
905 ret
= led_classdev_register(wiphy_dev(priv
->hw
->wiphy
), &led
->led_cdev
);
907 ath_print(ath9k_hw_common(priv
->ah
), ATH_DBG_FATAL
,
908 "Failed to register led:%s", led
->name
);
912 INIT_DELAYED_WORK(&led
->brightness_work
, ath9k_led_brightness_work
);
917 static void ath9k_unregister_led(struct ath_led
*led
)
919 if (led
->registered
) {
920 led_classdev_unregister(&led
->led_cdev
);
925 void ath9k_deinit_leds(struct ath9k_htc_priv
*priv
)
927 priv
->op_flags
|= OP_LED_DEINIT
;
928 ath9k_unregister_led(&priv
->assoc_led
);
929 priv
->op_flags
&= ~OP_LED_ASSOCIATED
;
930 ath9k_unregister_led(&priv
->tx_led
);
931 ath9k_unregister_led(&priv
->rx_led
);
932 ath9k_unregister_led(&priv
->radio_led
);
935 void ath9k_init_leds(struct ath9k_htc_priv
*priv
)
940 if (AR_SREV_9287(priv
->ah
))
941 priv
->ah
->led_pin
= ATH_LED_PIN_9287
;
942 else if (AR_SREV_9271(priv
->ah
))
943 priv
->ah
->led_pin
= ATH_LED_PIN_9271
;
944 else if (AR_DEVID_7010(priv
->ah
))
945 priv
->ah
->led_pin
= ATH_LED_PIN_7010
;
947 priv
->ah
->led_pin
= ATH_LED_PIN_DEF
;
949 /* Configure gpio 1 for output */
950 ath9k_hw_cfg_output(priv
->ah
, priv
->ah
->led_pin
,
951 AR_GPIO_OUTPUT_MUX_AS_OUTPUT
);
952 /* LED off, active low */
953 ath9k_hw_set_gpio(priv
->ah
, priv
->ah
->led_pin
, 1);
955 INIT_DELAYED_WORK(&priv
->ath9k_led_blink_work
, ath9k_led_blink_work
);
957 trigger
= ieee80211_get_radio_led_name(priv
->hw
);
958 snprintf(priv
->radio_led
.name
, sizeof(priv
->radio_led
.name
),
959 "ath9k-%s::radio", wiphy_name(priv
->hw
->wiphy
));
960 ret
= ath9k_register_led(priv
, &priv
->radio_led
, trigger
);
961 priv
->radio_led
.led_type
= ATH_LED_RADIO
;
965 trigger
= ieee80211_get_assoc_led_name(priv
->hw
);
966 snprintf(priv
->assoc_led
.name
, sizeof(priv
->assoc_led
.name
),
967 "ath9k-%s::assoc", wiphy_name(priv
->hw
->wiphy
));
968 ret
= ath9k_register_led(priv
, &priv
->assoc_led
, trigger
);
969 priv
->assoc_led
.led_type
= ATH_LED_ASSOC
;
973 trigger
= ieee80211_get_tx_led_name(priv
->hw
);
974 snprintf(priv
->tx_led
.name
, sizeof(priv
->tx_led
.name
),
975 "ath9k-%s::tx", wiphy_name(priv
->hw
->wiphy
));
976 ret
= ath9k_register_led(priv
, &priv
->tx_led
, trigger
);
977 priv
->tx_led
.led_type
= ATH_LED_TX
;
981 trigger
= ieee80211_get_rx_led_name(priv
->hw
);
982 snprintf(priv
->rx_led
.name
, sizeof(priv
->rx_led
.name
),
983 "ath9k-%s::rx", wiphy_name(priv
->hw
->wiphy
));
984 ret
= ath9k_register_led(priv
, &priv
->rx_led
, trigger
);
985 priv
->rx_led
.led_type
= ATH_LED_RX
;
989 priv
->op_flags
&= ~OP_LED_DEINIT
;
994 cancel_delayed_work_sync(&priv
->ath9k_led_blink_work
);
995 ath9k_deinit_leds(priv
);
998 /*******************/
1000 /*******************/
1002 static bool ath_is_rfkill_set(struct ath9k_htc_priv
*priv
)
1004 return ath9k_hw_gpio_get(priv
->ah
, priv
->ah
->rfkill_gpio
) ==
1005 priv
->ah
->rfkill_polarity
;
1008 static void ath9k_htc_rfkill_poll_state(struct ieee80211_hw
*hw
)
1010 struct ath9k_htc_priv
*priv
= hw
->priv
;
1011 bool blocked
= !!ath_is_rfkill_set(priv
);
1013 wiphy_rfkill_set_hw_state(hw
->wiphy
, blocked
);
1016 void ath9k_start_rfkill_poll(struct ath9k_htc_priv
*priv
)
1018 if (priv
->ah
->caps
.hw_caps
& ATH9K_HW_CAP_RFSILENT
)
1019 wiphy_rfkill_start_polling(priv
->hw
->wiphy
);
1022 static void ath9k_htc_radio_enable(struct ieee80211_hw
*hw
)
1024 struct ath9k_htc_priv
*priv
= hw
->priv
;
1025 struct ath_hw
*ah
= priv
->ah
;
1026 struct ath_common
*common
= ath9k_hw_common(ah
);
1031 ah
->curchan
= ath9k_cmn_get_curchannel(hw
, ah
);
1034 ret
= ath9k_hw_reset(ah
, ah
->curchan
, ah
->caldata
, false);
1036 ath_print(common
, ATH_DBG_FATAL
,
1037 "Unable to reset hardware; reset status %d "
1038 "(freq %u MHz)\n", ret
, ah
->curchan
->channel
);
1041 ath_update_txpow(priv
);
1044 WMI_CMD(WMI_START_RECV_CMDID
);
1045 ath9k_host_rx_init(priv
);
1048 htc_start(priv
->htc
);
1049 spin_lock_bh(&priv
->tx_lock
);
1050 priv
->tx_queues_stop
= false;
1051 spin_unlock_bh(&priv
->tx_lock
);
1052 ieee80211_wake_queues(hw
);
1054 WMI_CMD(WMI_ENABLE_INTR_CMDID
);
1057 ath9k_hw_cfg_output(ah
, ah
->led_pin
,
1058 AR_GPIO_OUTPUT_MUX_AS_OUTPUT
);
1059 ath9k_hw_set_gpio(ah
, ah
->led_pin
, 0);
1062 static void ath9k_htc_radio_disable(struct ieee80211_hw
*hw
)
1064 struct ath9k_htc_priv
*priv
= hw
->priv
;
1065 struct ath_hw
*ah
= priv
->ah
;
1066 struct ath_common
*common
= ath9k_hw_common(ah
);
1070 ath9k_htc_ps_wakeup(priv
);
1073 ath9k_hw_set_gpio(ah
, ah
->led_pin
, 1);
1074 ath9k_hw_cfg_gpio_input(ah
, ah
->led_pin
);
1076 WMI_CMD(WMI_DISABLE_INTR_CMDID
);
1079 ieee80211_stop_queues(hw
);
1080 htc_stop(priv
->htc
);
1081 WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID
);
1082 skb_queue_purge(&priv
->tx_queue
);
1085 WMI_CMD(WMI_STOP_RECV_CMDID
);
1088 * The MIB counters have to be disabled here,
1089 * since the target doesn't do it.
1091 ath9k_hw_disable_mib_counters(ah
);
1094 ah
->curchan
= ath9k_cmn_get_curchannel(hw
, ah
);
1097 ret
= ath9k_hw_reset(ah
, ah
->curchan
, ah
->caldata
, false);
1099 ath_print(common
, ATH_DBG_FATAL
,
1100 "Unable to reset hardware; reset status %d "
1101 "(freq %u MHz)\n", ret
, ah
->curchan
->channel
);
1104 /* Disable the PHY */
1105 ath9k_hw_phy_disable(ah
);
1107 ath9k_htc_ps_restore(priv
);
1108 ath9k_htc_setpower(priv
, ATH9K_PM_FULL_SLEEP
);
1111 /**********************/
1112 /* mac80211 Callbacks */
1113 /**********************/
1115 static int ath9k_htc_tx(struct ieee80211_hw
*hw
, struct sk_buff
*skb
)
1117 struct ieee80211_hdr
*hdr
;
1118 struct ath9k_htc_priv
*priv
= hw
->priv
;
1119 int padpos
, padsize
, ret
;
1121 hdr
= (struct ieee80211_hdr
*) skb
->data
;
1123 /* Add the padding after the header if this is not already done */
1124 padpos
= ath9k_cmn_padpos(hdr
->frame_control
);
1125 padsize
= padpos
& 3;
1126 if (padsize
&& skb
->len
> padpos
) {
1127 if (skb_headroom(skb
) < padsize
)
1129 skb_push(skb
, padsize
);
1130 memmove(skb
->data
, skb
->data
+ padsize
, padpos
);
1133 ret
= ath9k_htc_tx_start(priv
, skb
);
1135 if (ret
== -ENOMEM
) {
1136 ath_print(ath9k_hw_common(priv
->ah
), ATH_DBG_XMIT
,
1137 "Stopping TX queues\n");
1138 ieee80211_stop_queues(hw
);
1139 spin_lock_bh(&priv
->tx_lock
);
1140 priv
->tx_queues_stop
= true;
1141 spin_unlock_bh(&priv
->tx_lock
);
1143 ath_print(ath9k_hw_common(priv
->ah
), ATH_DBG_XMIT
,
1152 dev_kfree_skb_any(skb
);
1156 static int ath9k_htc_start(struct ieee80211_hw
*hw
)
1158 struct ath9k_htc_priv
*priv
= hw
->priv
;
1159 struct ath_hw
*ah
= priv
->ah
;
1160 struct ath_common
*common
= ath9k_hw_common(ah
);
1161 struct ieee80211_channel
*curchan
= hw
->conf
.channel
;
1162 struct ath9k_channel
*init_channel
;
1164 enum htc_phymode mode
;
1168 mutex_lock(&priv
->mutex
);
1170 ath_print(common
, ATH_DBG_CONFIG
,
1171 "Starting driver with initial channel: %d MHz\n",
1172 curchan
->center_freq
);
1174 /* Ensure that HW is awake before flushing RX */
1175 ath9k_htc_setpower(priv
, ATH9K_PM_AWAKE
);
1176 WMI_CMD(WMI_FLUSH_RECV_CMDID
);
1178 /* setup initial channel */
1179 init_channel
= ath9k_cmn_get_curchannel(hw
, ah
);
1181 /* Reset SERDES registers */
1182 ath9k_hw_configpcipowersave(ah
, 0, 0);
1184 ath9k_hw_htc_resetinit(ah
);
1185 ret
= ath9k_hw_reset(ah
, init_channel
, ah
->caldata
, false);
1187 ath_print(common
, ATH_DBG_FATAL
,
1188 "Unable to reset hardware; reset status %d "
1189 "(freq %u MHz)\n", ret
, curchan
->center_freq
);
1190 mutex_unlock(&priv
->mutex
);
1194 ath_update_txpow(priv
);
1196 mode
= ath9k_htc_get_curmode(priv
, init_channel
);
1197 htc_mode
= cpu_to_be16(mode
);
1198 WMI_CMD_BUF(WMI_SET_MODE_CMDID
, &htc_mode
);
1199 WMI_CMD(WMI_ATH_INIT_CMDID
);
1200 WMI_CMD(WMI_START_RECV_CMDID
);
1202 ath9k_host_rx_init(priv
);
1204 priv
->op_flags
&= ~OP_INVALID
;
1205 htc_start(priv
->htc
);
1207 spin_lock_bh(&priv
->tx_lock
);
1208 priv
->tx_queues_stop
= false;
1209 spin_unlock_bh(&priv
->tx_lock
);
1211 ieee80211_wake_queues(hw
);
1213 mutex_unlock(&priv
->mutex
);
1218 static void ath9k_htc_stop(struct ieee80211_hw
*hw
)
1220 struct ath9k_htc_priv
*priv
= hw
->priv
;
1221 struct ath_hw
*ah
= priv
->ah
;
1222 struct ath_common
*common
= ath9k_hw_common(ah
);
1226 mutex_lock(&priv
->mutex
);
1228 if (priv
->op_flags
& OP_INVALID
) {
1229 ath_print(common
, ATH_DBG_ANY
, "Device not present\n");
1230 mutex_unlock(&priv
->mutex
);
1234 /* Cancel all the running timers/work .. */
1235 cancel_work_sync(&priv
->ps_work
);
1236 cancel_delayed_work_sync(&priv
->ath9k_ani_work
);
1237 cancel_delayed_work_sync(&priv
->ath9k_led_blink_work
);
1238 ath9k_led_stop_brightness(priv
);
1240 ath9k_htc_ps_wakeup(priv
);
1241 htc_stop(priv
->htc
);
1242 WMI_CMD(WMI_DISABLE_INTR_CMDID
);
1243 WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID
);
1244 WMI_CMD(WMI_STOP_RECV_CMDID
);
1245 skb_queue_purge(&priv
->tx_queue
);
1247 /* Remove monitor interface here */
1248 if (ah
->opmode
== NL80211_IFTYPE_MONITOR
) {
1249 if (ath9k_htc_remove_monitor_interface(priv
))
1250 ath_print(common
, ATH_DBG_FATAL
,
1251 "Unable to remove monitor interface\n");
1253 ath_print(common
, ATH_DBG_CONFIG
,
1254 "Monitor interface removed\n");
1257 ath9k_hw_phy_disable(ah
);
1258 ath9k_hw_disable(ah
);
1259 ath9k_hw_configpcipowersave(ah
, 1, 1);
1260 ath9k_htc_ps_restore(priv
);
1261 ath9k_htc_setpower(priv
, ATH9K_PM_FULL_SLEEP
);
1263 priv
->op_flags
|= OP_INVALID
;
1265 ath_print(common
, ATH_DBG_CONFIG
, "Driver halt\n");
1266 mutex_unlock(&priv
->mutex
);
1269 static int ath9k_htc_add_interface(struct ieee80211_hw
*hw
,
1270 struct ieee80211_vif
*vif
)
1272 struct ath9k_htc_priv
*priv
= hw
->priv
;
1273 struct ath9k_htc_vif
*avp
= (void *)vif
->drv_priv
;
1274 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
1275 struct ath9k_htc_target_vif hvif
;
1279 mutex_lock(&priv
->mutex
);
1281 /* Only one interface for now */
1282 if (priv
->nvifs
> 0) {
1287 ath9k_htc_ps_wakeup(priv
);
1288 memset(&hvif
, 0, sizeof(struct ath9k_htc_target_vif
));
1289 memcpy(&hvif
.myaddr
, vif
->addr
, ETH_ALEN
);
1291 switch (vif
->type
) {
1292 case NL80211_IFTYPE_STATION
:
1293 hvif
.opmode
= cpu_to_be32(HTC_M_STA
);
1295 case NL80211_IFTYPE_ADHOC
:
1296 hvif
.opmode
= cpu_to_be32(HTC_M_IBSS
);
1299 ath_print(common
, ATH_DBG_FATAL
,
1300 "Interface type %d not yet supported\n", vif
->type
);
1305 ath_print(common
, ATH_DBG_CONFIG
,
1306 "Attach a VIF of type: %d\n", vif
->type
);
1308 priv
->ah
->opmode
= vif
->type
;
1310 /* Index starts from zero on the target */
1311 avp
->index
= hvif
.index
= priv
->nvifs
;
1312 hvif
.rtsthreshold
= cpu_to_be16(2304);
1313 WMI_CMD_BUF(WMI_VAP_CREATE_CMDID
, &hvif
);
1320 * We need a node in target to tx mgmt frames
1321 * before association.
1323 ret
= ath9k_htc_add_station(priv
, vif
, NULL
);
1327 ret
= ath9k_htc_update_cap_target(priv
);
1329 ath_print(common
, ATH_DBG_CONFIG
, "Failed to update"
1330 " capability in target \n");
1334 ath9k_htc_ps_restore(priv
);
1335 mutex_unlock(&priv
->mutex
);
1340 static void ath9k_htc_remove_interface(struct ieee80211_hw
*hw
,
1341 struct ieee80211_vif
*vif
)
1343 struct ath9k_htc_priv
*priv
= hw
->priv
;
1344 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
1345 struct ath9k_htc_vif
*avp
= (void *)vif
->drv_priv
;
1346 struct ath9k_htc_target_vif hvif
;
1350 ath_print(common
, ATH_DBG_CONFIG
, "Detach Interface\n");
1352 mutex_lock(&priv
->mutex
);
1353 ath9k_htc_ps_wakeup(priv
);
1355 memset(&hvif
, 0, sizeof(struct ath9k_htc_target_vif
));
1356 memcpy(&hvif
.myaddr
, vif
->addr
, ETH_ALEN
);
1357 hvif
.index
= avp
->index
;
1358 WMI_CMD_BUF(WMI_VAP_REMOVE_CMDID
, &hvif
);
1361 ath9k_htc_remove_station(priv
, vif
, NULL
);
1364 ath9k_htc_ps_restore(priv
);
1365 mutex_unlock(&priv
->mutex
);
1368 static int ath9k_htc_config(struct ieee80211_hw
*hw
, u32 changed
)
1370 struct ath9k_htc_priv
*priv
= hw
->priv
;
1371 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
1372 struct ieee80211_conf
*conf
= &hw
->conf
;
1374 mutex_lock(&priv
->mutex
);
1376 if (changed
& IEEE80211_CONF_CHANGE_IDLE
) {
1377 bool enable_radio
= false;
1378 bool idle
= !!(conf
->flags
& IEEE80211_CONF_IDLE
);
1380 mutex_lock(&priv
->htc_pm_lock
);
1381 if (!idle
&& priv
->ps_idle
)
1382 enable_radio
= true;
1383 priv
->ps_idle
= idle
;
1384 mutex_unlock(&priv
->htc_pm_lock
);
1387 ath_print(common
, ATH_DBG_CONFIG
,
1388 "not-idle: enabling radio\n");
1389 ath9k_htc_setpower(priv
, ATH9K_PM_AWAKE
);
1390 ath9k_htc_radio_enable(hw
);
1394 if (changed
& IEEE80211_CONF_CHANGE_CHANNEL
) {
1395 struct ieee80211_channel
*curchan
= hw
->conf
.channel
;
1396 int pos
= curchan
->hw_value
;
1398 ath_print(common
, ATH_DBG_CONFIG
, "Set channel: %d MHz\n",
1399 curchan
->center_freq
);
1401 ath9k_cmn_update_ichannel(hw
, &priv
->ah
->channels
[pos
]);
1403 if (ath9k_htc_set_channel(priv
, hw
, &priv
->ah
->channels
[pos
]) < 0) {
1404 ath_print(common
, ATH_DBG_FATAL
,
1405 "Unable to set channel\n");
1406 mutex_unlock(&priv
->mutex
);
1411 if (changed
& IEEE80211_CONF_CHANGE_PS
) {
1412 if (conf
->flags
& IEEE80211_CONF_PS
) {
1413 ath9k_htc_setpower(priv
, ATH9K_PM_NETWORK_SLEEP
);
1414 priv
->ps_enabled
= true;
1416 priv
->ps_enabled
= false;
1417 cancel_work_sync(&priv
->ps_work
);
1418 ath9k_htc_setpower(priv
, ATH9K_PM_AWAKE
);
1422 if (changed
& IEEE80211_CONF_CHANGE_MONITOR
) {
1423 if (conf
->flags
& IEEE80211_CONF_MONITOR
) {
1424 if (ath9k_htc_add_monitor_interface(priv
))
1425 ath_print(common
, ATH_DBG_FATAL
,
1426 "Failed to set monitor mode\n");
1428 ath_print(common
, ATH_DBG_CONFIG
,
1429 "HW opmode set to Monitor mode\n");
1433 if (changed
& IEEE80211_CONF_CHANGE_IDLE
) {
1434 mutex_lock(&priv
->htc_pm_lock
);
1435 if (!priv
->ps_idle
) {
1436 mutex_unlock(&priv
->htc_pm_lock
);
1439 mutex_unlock(&priv
->htc_pm_lock
);
1441 ath_print(common
, ATH_DBG_CONFIG
,
1442 "idle: disabling radio\n");
1443 ath9k_htc_radio_disable(hw
);
1447 mutex_unlock(&priv
->mutex
);
1451 #define SUPPORTED_FILTERS \
1452 (FIF_PROMISC_IN_BSS | \
1457 FIF_BCN_PRBRESP_PROMISC | \
1460 static void ath9k_htc_configure_filter(struct ieee80211_hw
*hw
,
1461 unsigned int changed_flags
,
1462 unsigned int *total_flags
,
1465 struct ath9k_htc_priv
*priv
= hw
->priv
;
1468 mutex_lock(&priv
->mutex
);
1469 ath9k_htc_ps_wakeup(priv
);
1471 changed_flags
&= SUPPORTED_FILTERS
;
1472 *total_flags
&= SUPPORTED_FILTERS
;
1474 priv
->rxfilter
= *total_flags
;
1475 rfilt
= ath9k_htc_calcrxfilter(priv
);
1476 ath9k_hw_setrxfilter(priv
->ah
, rfilt
);
1478 ath_print(ath9k_hw_common(priv
->ah
), ATH_DBG_CONFIG
,
1479 "Set HW RX filter: 0x%x\n", rfilt
);
1481 ath9k_htc_ps_restore(priv
);
1482 mutex_unlock(&priv
->mutex
);
1485 static int ath9k_htc_sta_add(struct ieee80211_hw
*hw
,
1486 struct ieee80211_vif
*vif
,
1487 struct ieee80211_sta
*sta
)
1489 struct ath9k_htc_priv
*priv
= hw
->priv
;
1492 mutex_lock(&priv
->mutex
);
1493 ath9k_htc_ps_wakeup(priv
);
1494 ret
= ath9k_htc_add_station(priv
, vif
, sta
);
1496 ath9k_htc_init_rate(priv
, sta
);
1497 ath9k_htc_ps_restore(priv
);
1498 mutex_unlock(&priv
->mutex
);
1503 static int ath9k_htc_sta_remove(struct ieee80211_hw
*hw
,
1504 struct ieee80211_vif
*vif
,
1505 struct ieee80211_sta
*sta
)
1507 struct ath9k_htc_priv
*priv
= hw
->priv
;
1510 mutex_lock(&priv
->mutex
);
1511 ath9k_htc_ps_wakeup(priv
);
1512 ret
= ath9k_htc_remove_station(priv
, vif
, sta
);
1513 ath9k_htc_ps_restore(priv
);
1514 mutex_unlock(&priv
->mutex
);
1519 static int ath9k_htc_conf_tx(struct ieee80211_hw
*hw
, u16 queue
,
1520 const struct ieee80211_tx_queue_params
*params
)
1522 struct ath9k_htc_priv
*priv
= hw
->priv
;
1523 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
1524 struct ath9k_tx_queue_info qi
;
1527 if (queue
>= WME_NUM_AC
)
1530 mutex_lock(&priv
->mutex
);
1531 ath9k_htc_ps_wakeup(priv
);
1533 memset(&qi
, 0, sizeof(struct ath9k_tx_queue_info
));
1535 qi
.tqi_aifs
= params
->aifs
;
1536 qi
.tqi_cwmin
= params
->cw_min
;
1537 qi
.tqi_cwmax
= params
->cw_max
;
1538 qi
.tqi_burstTime
= params
->txop
;
1540 qnum
= get_hw_qnum(queue
, priv
->hwq_map
);
1542 ath_print(common
, ATH_DBG_CONFIG
,
1543 "Configure tx [queue/hwq] [%d/%d], "
1544 "aifs: %d, cw_min: %d, cw_max: %d, txop: %d\n",
1545 queue
, qnum
, params
->aifs
, params
->cw_min
,
1546 params
->cw_max
, params
->txop
);
1548 ret
= ath_htc_txq_update(priv
, qnum
, &qi
);
1550 ath_print(common
, ATH_DBG_FATAL
, "TXQ Update failed\n");
1554 if ((priv
->ah
->opmode
== NL80211_IFTYPE_ADHOC
) &&
1555 (qnum
== priv
->hwq_map
[WME_AC_BE
]))
1556 ath9k_htc_beaconq_config(priv
);
1558 ath9k_htc_ps_restore(priv
);
1559 mutex_unlock(&priv
->mutex
);
1564 static int ath9k_htc_set_key(struct ieee80211_hw
*hw
,
1565 enum set_key_cmd cmd
,
1566 struct ieee80211_vif
*vif
,
1567 struct ieee80211_sta
*sta
,
1568 struct ieee80211_key_conf
*key
)
1570 struct ath9k_htc_priv
*priv
= hw
->priv
;
1571 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
1574 if (htc_modparam_nohwcrypt
)
1577 mutex_lock(&priv
->mutex
);
1578 ath_print(common
, ATH_DBG_CONFIG
, "Set HW Key\n");
1579 ath9k_htc_ps_wakeup(priv
);
1583 ret
= ath9k_cmn_key_config(common
, vif
, sta
, key
);
1585 key
->hw_key_idx
= ret
;
1586 /* push IV and Michael MIC generation to stack */
1587 key
->flags
|= IEEE80211_KEY_FLAG_GENERATE_IV
;
1588 if (key
->alg
== ALG_TKIP
)
1589 key
->flags
|= IEEE80211_KEY_FLAG_GENERATE_MMIC
;
1590 if (priv
->ah
->sw_mgmt_crypto
&& key
->alg
== ALG_CCMP
)
1591 key
->flags
|= IEEE80211_KEY_FLAG_SW_MGMT
;
1596 ath9k_cmn_key_delete(common
, key
);
1602 ath9k_htc_ps_restore(priv
);
1603 mutex_unlock(&priv
->mutex
);
1608 static void ath9k_htc_bss_info_changed(struct ieee80211_hw
*hw
,
1609 struct ieee80211_vif
*vif
,
1610 struct ieee80211_bss_conf
*bss_conf
,
1613 struct ath9k_htc_priv
*priv
= hw
->priv
;
1614 struct ath_hw
*ah
= priv
->ah
;
1615 struct ath_common
*common
= ath9k_hw_common(ah
);
1617 mutex_lock(&priv
->mutex
);
1618 ath9k_htc_ps_wakeup(priv
);
1620 if (changed
& BSS_CHANGED_ASSOC
) {
1621 common
->curaid
= bss_conf
->assoc
?
1623 ath_print(common
, ATH_DBG_CONFIG
, "BSS Changed ASSOC %d\n",
1626 if (bss_conf
->assoc
) {
1627 priv
->op_flags
|= OP_ASSOCIATED
;
1628 ath_start_ani(priv
);
1630 priv
->op_flags
&= ~OP_ASSOCIATED
;
1631 cancel_delayed_work_sync(&priv
->ath9k_ani_work
);
1635 if (changed
& BSS_CHANGED_BSSID
) {
1637 memcpy(common
->curbssid
, bss_conf
->bssid
, ETH_ALEN
);
1638 ath9k_hw_write_associd(ah
);
1640 ath_print(common
, ATH_DBG_CONFIG
,
1641 "BSSID: %pM aid: 0x%x\n",
1642 common
->curbssid
, common
->curaid
);
1645 if ((changed
& BSS_CHANGED_BEACON_INT
) ||
1646 (changed
& BSS_CHANGED_BEACON
) ||
1647 ((changed
& BSS_CHANGED_BEACON_ENABLED
) &&
1648 bss_conf
->enable_beacon
)) {
1649 priv
->op_flags
|= OP_ENABLE_BEACON
;
1650 ath9k_htc_beacon_config(priv
, vif
);
1653 if ((changed
& BSS_CHANGED_BEACON_ENABLED
) &&
1654 !bss_conf
->enable_beacon
) {
1655 priv
->op_flags
&= ~OP_ENABLE_BEACON
;
1656 ath9k_htc_beacon_config(priv
, vif
);
1659 if (changed
& BSS_CHANGED_ERP_PREAMBLE
) {
1660 ath_print(common
, ATH_DBG_CONFIG
, "BSS Changed PREAMBLE %d\n",
1661 bss_conf
->use_short_preamble
);
1662 if (bss_conf
->use_short_preamble
)
1663 priv
->op_flags
|= OP_PREAMBLE_SHORT
;
1665 priv
->op_flags
&= ~OP_PREAMBLE_SHORT
;
1668 if (changed
& BSS_CHANGED_ERP_CTS_PROT
) {
1669 ath_print(common
, ATH_DBG_CONFIG
, "BSS Changed CTS PROT %d\n",
1670 bss_conf
->use_cts_prot
);
1671 if (bss_conf
->use_cts_prot
&&
1672 hw
->conf
.channel
->band
!= IEEE80211_BAND_5GHZ
)
1673 priv
->op_flags
|= OP_PROTECT_ENABLE
;
1675 priv
->op_flags
&= ~OP_PROTECT_ENABLE
;
1678 if (changed
& BSS_CHANGED_ERP_SLOT
) {
1679 if (bss_conf
->use_short_slot
)
1684 ath9k_hw_init_global_settings(ah
);
1687 if (changed
& BSS_CHANGED_HT
)
1688 ath9k_htc_update_rate(priv
, vif
, bss_conf
);
1690 ath9k_htc_ps_restore(priv
);
1691 mutex_unlock(&priv
->mutex
);
1694 static u64
ath9k_htc_get_tsf(struct ieee80211_hw
*hw
)
1696 struct ath9k_htc_priv
*priv
= hw
->priv
;
1699 mutex_lock(&priv
->mutex
);
1700 ath9k_htc_ps_wakeup(priv
);
1701 tsf
= ath9k_hw_gettsf64(priv
->ah
);
1702 ath9k_htc_ps_restore(priv
);
1703 mutex_unlock(&priv
->mutex
);
1708 static void ath9k_htc_set_tsf(struct ieee80211_hw
*hw
, u64 tsf
)
1710 struct ath9k_htc_priv
*priv
= hw
->priv
;
1712 mutex_lock(&priv
->mutex
);
1713 ath9k_htc_ps_wakeup(priv
);
1714 ath9k_hw_settsf64(priv
->ah
, tsf
);
1715 ath9k_htc_ps_restore(priv
);
1716 mutex_unlock(&priv
->mutex
);
1719 static void ath9k_htc_reset_tsf(struct ieee80211_hw
*hw
)
1721 struct ath9k_htc_priv
*priv
= hw
->priv
;
1723 mutex_lock(&priv
->mutex
);
1724 ath9k_htc_ps_wakeup(priv
);
1725 ath9k_hw_reset_tsf(priv
->ah
);
1726 ath9k_htc_ps_restore(priv
);
1727 mutex_unlock(&priv
->mutex
);
1730 static int ath9k_htc_ampdu_action(struct ieee80211_hw
*hw
,
1731 struct ieee80211_vif
*vif
,
1732 enum ieee80211_ampdu_mlme_action action
,
1733 struct ieee80211_sta
*sta
,
1736 struct ath9k_htc_priv
*priv
= hw
->priv
;
1737 struct ath9k_htc_sta
*ista
;
1741 case IEEE80211_AMPDU_RX_START
:
1743 case IEEE80211_AMPDU_RX_STOP
:
1745 case IEEE80211_AMPDU_TX_START
:
1746 ret
= ath9k_htc_tx_aggr_oper(priv
, vif
, sta
, action
, tid
);
1748 ieee80211_start_tx_ba_cb_irqsafe(vif
, sta
->addr
, tid
);
1750 case IEEE80211_AMPDU_TX_STOP
:
1751 ath9k_htc_tx_aggr_oper(priv
, vif
, sta
, action
, tid
);
1752 ieee80211_stop_tx_ba_cb_irqsafe(vif
, sta
->addr
, tid
);
1754 case IEEE80211_AMPDU_TX_OPERATIONAL
:
1755 ista
= (struct ath9k_htc_sta
*) sta
->drv_priv
;
1756 spin_lock_bh(&priv
->tx_lock
);
1757 ista
->tid_state
[tid
] = AGGR_OPERATIONAL
;
1758 spin_unlock_bh(&priv
->tx_lock
);
1761 ath_print(ath9k_hw_common(priv
->ah
), ATH_DBG_FATAL
,
1762 "Unknown AMPDU action\n");
1768 static void ath9k_htc_sw_scan_start(struct ieee80211_hw
*hw
)
1770 struct ath9k_htc_priv
*priv
= hw
->priv
;
1772 mutex_lock(&priv
->mutex
);
1773 spin_lock_bh(&priv
->beacon_lock
);
1774 priv
->op_flags
|= OP_SCANNING
;
1775 spin_unlock_bh(&priv
->beacon_lock
);
1776 cancel_work_sync(&priv
->ps_work
);
1777 cancel_delayed_work_sync(&priv
->ath9k_ani_work
);
1778 mutex_unlock(&priv
->mutex
);
1781 static void ath9k_htc_sw_scan_complete(struct ieee80211_hw
*hw
)
1783 struct ath9k_htc_priv
*priv
= hw
->priv
;
1785 mutex_lock(&priv
->mutex
);
1786 ath9k_htc_ps_wakeup(priv
);
1787 spin_lock_bh(&priv
->beacon_lock
);
1788 priv
->op_flags
&= ~OP_SCANNING
;
1789 spin_unlock_bh(&priv
->beacon_lock
);
1790 priv
->op_flags
|= OP_FULL_RESET
;
1791 if (priv
->op_flags
& OP_ASSOCIATED
)
1792 ath9k_htc_beacon_config(priv
, priv
->vif
);
1793 ath_start_ani(priv
);
1794 ath9k_htc_ps_restore(priv
);
1795 mutex_unlock(&priv
->mutex
);
1798 static int ath9k_htc_set_rts_threshold(struct ieee80211_hw
*hw
, u32 value
)
1803 static void ath9k_htc_set_coverage_class(struct ieee80211_hw
*hw
,
1806 struct ath9k_htc_priv
*priv
= hw
->priv
;
1808 mutex_lock(&priv
->mutex
);
1809 ath9k_htc_ps_wakeup(priv
);
1810 priv
->ah
->coverage_class
= coverage_class
;
1811 ath9k_hw_init_global_settings(priv
->ah
);
1812 ath9k_htc_ps_restore(priv
);
1813 mutex_unlock(&priv
->mutex
);
1816 struct ieee80211_ops ath9k_htc_ops
= {
1818 .start
= ath9k_htc_start
,
1819 .stop
= ath9k_htc_stop
,
1820 .add_interface
= ath9k_htc_add_interface
,
1821 .remove_interface
= ath9k_htc_remove_interface
,
1822 .config
= ath9k_htc_config
,
1823 .configure_filter
= ath9k_htc_configure_filter
,
1824 .sta_add
= ath9k_htc_sta_add
,
1825 .sta_remove
= ath9k_htc_sta_remove
,
1826 .conf_tx
= ath9k_htc_conf_tx
,
1827 .bss_info_changed
= ath9k_htc_bss_info_changed
,
1828 .set_key
= ath9k_htc_set_key
,
1829 .get_tsf
= ath9k_htc_get_tsf
,
1830 .set_tsf
= ath9k_htc_set_tsf
,
1831 .reset_tsf
= ath9k_htc_reset_tsf
,
1832 .ampdu_action
= ath9k_htc_ampdu_action
,
1833 .sw_scan_start
= ath9k_htc_sw_scan_start
,
1834 .sw_scan_complete
= ath9k_htc_sw_scan_complete
,
1835 .set_rts_threshold
= ath9k_htc_set_rts_threshold
,
1836 .rfkill_poll
= ath9k_htc_rfkill_poll_state
,
1837 .set_coverage_class
= ath9k_htc_set_coverage_class
,