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 /* HACK Alert: Use 11NG for 2.4, use 11NA for 5 */
28 static enum htc_phymode
ath9k_htc_get_curmode(struct ath9k_htc_priv
*priv
,
29 struct ath9k_channel
*ichan
)
31 enum htc_phymode mode
;
35 switch (ichan
->chanmode
) {
38 case CHANNEL_G_HT40PLUS
:
39 case CHANNEL_G_HT40MINUS
:
44 case CHANNEL_A_HT40PLUS
:
45 case CHANNEL_A_HT40MINUS
:
55 bool ath9k_htc_setpower(struct ath9k_htc_priv
*priv
,
56 enum ath9k_power_mode mode
)
60 mutex_lock(&priv
->htc_pm_lock
);
61 ret
= ath9k_hw_setpower(priv
->ah
, mode
);
62 mutex_unlock(&priv
->htc_pm_lock
);
67 void ath9k_htc_ps_wakeup(struct ath9k_htc_priv
*priv
)
69 mutex_lock(&priv
->htc_pm_lock
);
70 if (++priv
->ps_usecount
!= 1)
72 ath9k_hw_setpower(priv
->ah
, ATH9K_PM_AWAKE
);
75 mutex_unlock(&priv
->htc_pm_lock
);
78 void ath9k_htc_ps_restore(struct ath9k_htc_priv
*priv
)
80 mutex_lock(&priv
->htc_pm_lock
);
81 if (--priv
->ps_usecount
!= 0)
85 ath9k_hw_setpower(priv
->ah
, ATH9K_PM_FULL_SLEEP
);
86 else if (priv
->ps_enabled
)
87 ath9k_hw_setpower(priv
->ah
, ATH9K_PM_NETWORK_SLEEP
);
90 mutex_unlock(&priv
->htc_pm_lock
);
93 void ath9k_ps_work(struct work_struct
*work
)
95 struct ath9k_htc_priv
*priv
=
96 container_of(work
, struct ath9k_htc_priv
,
98 ath9k_htc_setpower(priv
, ATH9K_PM_AWAKE
);
100 /* The chip wakes up after receiving the first beacon
101 while network sleep is enabled. For the driver to
102 be in sync with the hw, set the chip to awake and
103 only then set it to sleep.
105 ath9k_htc_setpower(priv
, ATH9K_PM_NETWORK_SLEEP
);
108 static void ath9k_htc_vif_iter(void *data
, u8
*mac
, struct ieee80211_vif
*vif
)
110 struct ath9k_htc_priv
*priv
= data
;
111 struct ieee80211_bss_conf
*bss_conf
= &vif
->bss_conf
;
113 if ((vif
->type
== NL80211_IFTYPE_AP
) && bss_conf
->enable_beacon
)
114 priv
->reconfig_beacon
= true;
116 if (bss_conf
->assoc
) {
117 priv
->rearm_ani
= true;
118 priv
->reconfig_beacon
= true;
122 static void ath9k_htc_vif_reconfig(struct ath9k_htc_priv
*priv
)
124 priv
->rearm_ani
= false;
125 priv
->reconfig_beacon
= false;
127 ieee80211_iterate_active_interfaces_atomic(priv
->hw
,
128 ath9k_htc_vif_iter
, priv
);
130 ath9k_htc_start_ani(priv
);
132 if (priv
->reconfig_beacon
) {
133 ath9k_htc_ps_wakeup(priv
);
134 ath9k_htc_beacon_reconfig(priv
);
135 ath9k_htc_ps_restore(priv
);
139 static void ath9k_htc_bssid_iter(void *data
, u8
*mac
, struct ieee80211_vif
*vif
)
141 struct ath9k_vif_iter_data
*iter_data
= data
;
144 for (i
= 0; i
< ETH_ALEN
; i
++)
145 iter_data
->mask
[i
] &= ~(iter_data
->hw_macaddr
[i
] ^ mac
[i
]);
148 static void ath9k_htc_set_bssid_mask(struct ath9k_htc_priv
*priv
,
149 struct ieee80211_vif
*vif
)
151 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
152 struct ath9k_vif_iter_data iter_data
;
155 * Use the hardware MAC address as reference, the hardware uses it
156 * together with the BSSID mask when matching addresses.
158 iter_data
.hw_macaddr
= common
->macaddr
;
159 memset(&iter_data
.mask
, 0xff, ETH_ALEN
);
162 ath9k_htc_bssid_iter(&iter_data
, vif
->addr
, vif
);
164 /* Get list of all active MAC addresses */
165 ieee80211_iterate_active_interfaces_atomic(priv
->hw
, ath9k_htc_bssid_iter
,
168 memcpy(common
->bssidmask
, iter_data
.mask
, ETH_ALEN
);
169 ath_hw_setbssidmask(common
);
172 static void ath9k_htc_set_opmode(struct ath9k_htc_priv
*priv
)
174 if (priv
->num_ibss_vif
)
175 priv
->ah
->opmode
= NL80211_IFTYPE_ADHOC
;
176 else if (priv
->num_ap_vif
)
177 priv
->ah
->opmode
= NL80211_IFTYPE_AP
;
179 priv
->ah
->opmode
= NL80211_IFTYPE_STATION
;
181 ath9k_hw_setopmode(priv
->ah
);
184 void ath9k_htc_reset(struct ath9k_htc_priv
*priv
)
186 struct ath_hw
*ah
= priv
->ah
;
187 struct ath_common
*common
= ath9k_hw_common(ah
);
188 struct ieee80211_channel
*channel
= priv
->hw
->conf
.channel
;
189 struct ath9k_hw_cal_data
*caldata
= NULL
;
190 enum htc_phymode mode
;
195 mutex_lock(&priv
->mutex
);
196 ath9k_htc_ps_wakeup(priv
);
198 ath9k_htc_stop_ani(priv
);
199 ieee80211_stop_queues(priv
->hw
);
201 WMI_CMD(WMI_DISABLE_INTR_CMDID
);
202 WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID
);
203 WMI_CMD(WMI_STOP_RECV_CMDID
);
205 caldata
= &priv
->caldata
;
206 ret
= ath9k_hw_reset(ah
, ah
->curchan
, caldata
, false);
209 "Unable to reset device (%u Mhz) reset status %d\n",
210 channel
->center_freq
, ret
);
213 ath9k_cmn_update_txpow(ah
, priv
->curtxpow
, priv
->txpowlimit
,
216 WMI_CMD(WMI_START_RECV_CMDID
);
217 ath9k_host_rx_init(priv
);
219 mode
= ath9k_htc_get_curmode(priv
, ah
->curchan
);
220 htc_mode
= cpu_to_be16(mode
);
221 WMI_CMD_BUF(WMI_SET_MODE_CMDID
, &htc_mode
);
223 WMI_CMD(WMI_ENABLE_INTR_CMDID
);
224 htc_start(priv
->htc
);
225 ath9k_htc_vif_reconfig(priv
);
226 ieee80211_wake_queues(priv
->hw
);
228 ath9k_htc_ps_restore(priv
);
229 mutex_unlock(&priv
->mutex
);
232 static int ath9k_htc_set_channel(struct ath9k_htc_priv
*priv
,
233 struct ieee80211_hw
*hw
,
234 struct ath9k_channel
*hchan
)
236 struct ath_hw
*ah
= priv
->ah
;
237 struct ath_common
*common
= ath9k_hw_common(ah
);
238 struct ieee80211_conf
*conf
= &common
->hw
->conf
;
240 struct ieee80211_channel
*channel
= hw
->conf
.channel
;
241 struct ath9k_hw_cal_data
*caldata
= NULL
;
242 enum htc_phymode mode
;
247 if (priv
->op_flags
& OP_INVALID
)
250 fastcc
= !!(hw
->conf
.flags
& IEEE80211_CONF_OFFCHANNEL
);
252 ath9k_htc_ps_wakeup(priv
);
254 WMI_CMD(WMI_DISABLE_INTR_CMDID
);
255 WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID
);
256 WMI_CMD(WMI_STOP_RECV_CMDID
);
258 ath_dbg(common
, ATH_DBG_CONFIG
,
259 "(%u MHz) -> (%u MHz), HT: %d, HT40: %d fastcc: %d\n",
260 priv
->ah
->curchan
->channel
,
261 channel
->center_freq
, conf_is_ht(conf
), conf_is_ht40(conf
),
265 caldata
= &priv
->caldata
;
266 ret
= ath9k_hw_reset(ah
, hchan
, caldata
, fastcc
);
269 "Unable to reset channel (%u Mhz) reset status %d\n",
270 channel
->center_freq
, ret
);
274 ath9k_cmn_update_txpow(ah
, priv
->curtxpow
, priv
->txpowlimit
,
277 WMI_CMD(WMI_START_RECV_CMDID
);
281 ath9k_host_rx_init(priv
);
283 mode
= ath9k_htc_get_curmode(priv
, hchan
);
284 htc_mode
= cpu_to_be16(mode
);
285 WMI_CMD_BUF(WMI_SET_MODE_CMDID
, &htc_mode
);
289 WMI_CMD(WMI_ENABLE_INTR_CMDID
);
293 htc_start(priv
->htc
);
295 if (!(priv
->op_flags
& OP_SCANNING
) &&
296 !(hw
->conf
.flags
& IEEE80211_CONF_OFFCHANNEL
))
297 ath9k_htc_vif_reconfig(priv
);
300 ath9k_htc_ps_restore(priv
);
305 * Monitor mode handling is a tad complicated because the firmware requires
306 * an interface to be created exclusively, while mac80211 doesn't associate
307 * an interface with the mode.
309 * So, for now, only one monitor interface can be configured.
311 static void __ath9k_htc_remove_monitor_interface(struct ath9k_htc_priv
*priv
)
313 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
314 struct ath9k_htc_target_vif hvif
;
318 memset(&hvif
, 0, sizeof(struct ath9k_htc_target_vif
));
319 memcpy(&hvif
.myaddr
, common
->macaddr
, ETH_ALEN
);
320 hvif
.index
= priv
->mon_vif_idx
;
321 WMI_CMD_BUF(WMI_VAP_REMOVE_CMDID
, &hvif
);
323 priv
->vif_slot
&= ~(1 << priv
->mon_vif_idx
);
326 static int ath9k_htc_add_monitor_interface(struct ath9k_htc_priv
*priv
)
328 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
329 struct ath9k_htc_target_vif hvif
;
330 struct ath9k_htc_target_sta tsta
;
331 int ret
= 0, sta_idx
;
334 if ((priv
->nvifs
>= ATH9K_HTC_MAX_VIF
) ||
335 (priv
->nstations
>= ATH9K_HTC_MAX_STA
)) {
340 sta_idx
= ffz(priv
->sta_slot
);
341 if ((sta_idx
< 0) || (sta_idx
> ATH9K_HTC_MAX_STA
)) {
349 memset(&hvif
, 0, sizeof(struct ath9k_htc_target_vif
));
350 memcpy(&hvif
.myaddr
, common
->macaddr
, ETH_ALEN
);
352 hvif
.opmode
= cpu_to_be32(HTC_M_MONITOR
);
353 hvif
.index
= ffz(priv
->vif_slot
);
355 WMI_CMD_BUF(WMI_VAP_CREATE_CMDID
, &hvif
);
360 * Assign the monitor interface index as a special case here.
361 * This is needed when the interface is brought down.
363 priv
->mon_vif_idx
= hvif
.index
;
364 priv
->vif_slot
|= (1 << hvif
.index
);
367 * Set the hardware mode to monitor only if there are no
371 priv
->ah
->opmode
= NL80211_IFTYPE_MONITOR
;
376 * Associate a station with the interface for packet injection.
378 memset(&tsta
, 0, sizeof(struct ath9k_htc_target_sta
));
380 memcpy(&tsta
.macaddr
, common
->macaddr
, ETH_ALEN
);
383 tsta
.sta_index
= sta_idx
;
384 tsta
.vif_index
= hvif
.index
;
385 tsta
.maxampdu
= 0xffff;
387 WMI_CMD_BUF(WMI_NODE_CREATE_CMDID
, &tsta
);
389 ath_err(common
, "Unable to add station entry for monitor mode\n");
393 priv
->sta_slot
|= (1 << sta_idx
);
395 priv
->vif_sta_pos
[priv
->mon_vif_idx
] = sta_idx
;
396 priv
->ah
->is_monitoring
= true;
398 ath_dbg(common
, ATH_DBG_CONFIG
,
399 "Attached a monitor interface at idx: %d, sta idx: %d\n",
400 priv
->mon_vif_idx
, sta_idx
);
406 * Remove the interface from the target.
408 __ath9k_htc_remove_monitor_interface(priv
);
410 ath_dbg(common
, ATH_DBG_FATAL
, "Unable to attach a monitor interface\n");
415 static int ath9k_htc_remove_monitor_interface(struct ath9k_htc_priv
*priv
)
417 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
421 __ath9k_htc_remove_monitor_interface(priv
);
423 sta_idx
= priv
->vif_sta_pos
[priv
->mon_vif_idx
];
425 WMI_CMD_BUF(WMI_NODE_REMOVE_CMDID
, &sta_idx
);
427 ath_err(common
, "Unable to remove station entry for monitor mode\n");
431 priv
->sta_slot
&= ~(1 << sta_idx
);
433 priv
->ah
->is_monitoring
= false;
435 ath_dbg(common
, ATH_DBG_CONFIG
,
436 "Removed a monitor interface at idx: %d, sta idx: %d\n",
437 priv
->mon_vif_idx
, sta_idx
);
442 static int ath9k_htc_add_station(struct ath9k_htc_priv
*priv
,
443 struct ieee80211_vif
*vif
,
444 struct ieee80211_sta
*sta
)
446 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
447 struct ath9k_htc_target_sta tsta
;
448 struct ath9k_htc_vif
*avp
= (struct ath9k_htc_vif
*) vif
->drv_priv
;
449 struct ath9k_htc_sta
*ista
;
453 if (priv
->nstations
>= ATH9K_HTC_MAX_STA
)
456 sta_idx
= ffz(priv
->sta_slot
);
457 if ((sta_idx
< 0) || (sta_idx
> ATH9K_HTC_MAX_STA
))
460 memset(&tsta
, 0, sizeof(struct ath9k_htc_target_sta
));
463 ista
= (struct ath9k_htc_sta
*) sta
->drv_priv
;
464 memcpy(&tsta
.macaddr
, sta
->addr
, ETH_ALEN
);
465 memcpy(&tsta
.bssid
, common
->curbssid
, ETH_ALEN
);
466 tsta
.associd
= common
->curaid
;
469 ista
->index
= sta_idx
;
471 memcpy(&tsta
.macaddr
, vif
->addr
, ETH_ALEN
);
475 tsta
.sta_index
= sta_idx
;
476 tsta
.vif_index
= avp
->index
;
477 tsta
.maxampdu
= 0xffff;
478 if (sta
&& sta
->ht_cap
.ht_supported
)
479 tsta
.flags
= cpu_to_be16(ATH_HTC_STA_HT
);
481 WMI_CMD_BUF(WMI_NODE_CREATE_CMDID
, &tsta
);
485 "Unable to add station entry for: %pM\n",
491 ath_dbg(common
, ATH_DBG_CONFIG
,
492 "Added a station entry for: %pM (idx: %d)\n",
493 sta
->addr
, tsta
.sta_index
);
495 ath_dbg(common
, ATH_DBG_CONFIG
,
496 "Added a station entry for VIF %d (idx: %d)\n",
497 avp
->index
, tsta
.sta_index
);
500 priv
->sta_slot
|= (1 << sta_idx
);
503 priv
->vif_sta_pos
[avp
->index
] = sta_idx
;
508 static int ath9k_htc_remove_station(struct ath9k_htc_priv
*priv
,
509 struct ieee80211_vif
*vif
,
510 struct ieee80211_sta
*sta
)
512 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
513 struct ath9k_htc_vif
*avp
= (struct ath9k_htc_vif
*) vif
->drv_priv
;
514 struct ath9k_htc_sta
*ista
;
519 ista
= (struct ath9k_htc_sta
*) sta
->drv_priv
;
520 sta_idx
= ista
->index
;
522 sta_idx
= priv
->vif_sta_pos
[avp
->index
];
525 WMI_CMD_BUF(WMI_NODE_REMOVE_CMDID
, &sta_idx
);
529 "Unable to remove station entry for: %pM\n",
535 ath_dbg(common
, ATH_DBG_CONFIG
,
536 "Removed a station entry for: %pM (idx: %d)\n",
539 ath_dbg(common
, ATH_DBG_CONFIG
,
540 "Removed a station entry for VIF %d (idx: %d)\n",
541 avp
->index
, sta_idx
);
544 priv
->sta_slot
&= ~(1 << sta_idx
);
550 int ath9k_htc_update_cap_target(struct ath9k_htc_priv
*priv
)
552 struct ath9k_htc_cap_target tcap
;
556 memset(&tcap
, 0, sizeof(struct ath9k_htc_cap_target
));
558 /* FIXME: Values are hardcoded */
559 tcap
.flags
= 0x240c40;
560 tcap
.flags_ext
= 0x80601000;
561 tcap
.ampdu_limit
= 0xffff0000;
562 tcap
.ampdu_subframes
= 20;
563 tcap
.tx_chainmask_legacy
= priv
->ah
->caps
.tx_chainmask
;
565 tcap
.tx_chainmask
= priv
->ah
->caps
.tx_chainmask
;
567 WMI_CMD_BUF(WMI_TARGET_IC_UPDATE_CMDID
, &tcap
);
572 static void ath9k_htc_setup_rate(struct ath9k_htc_priv
*priv
,
573 struct ieee80211_sta
*sta
,
574 struct ath9k_htc_target_rate
*trate
)
576 struct ath9k_htc_sta
*ista
= (struct ath9k_htc_sta
*) sta
->drv_priv
;
577 struct ieee80211_supported_band
*sband
;
581 sband
= priv
->hw
->wiphy
->bands
[priv
->hw
->conf
.channel
->band
];
583 for (i
= 0, j
= 0; i
< sband
->n_bitrates
; i
++) {
584 if (sta
->supp_rates
[sband
->band
] & BIT(i
)) {
585 trate
->rates
.legacy_rates
.rs_rates
[j
]
586 = (sband
->bitrates
[i
].bitrate
* 2) / 10;
590 trate
->rates
.legacy_rates
.rs_nrates
= j
;
592 if (sta
->ht_cap
.ht_supported
) {
593 for (i
= 0, j
= 0; i
< 77; i
++) {
594 if (sta
->ht_cap
.mcs
.rx_mask
[i
/8] & (1<<(i
%8)))
595 trate
->rates
.ht_rates
.rs_rates
[j
++] = i
;
596 if (j
== ATH_HTC_RATE_MAX
)
599 trate
->rates
.ht_rates
.rs_nrates
= j
;
601 caps
= WLAN_RC_HT_FLAG
;
602 if (sta
->ht_cap
.mcs
.rx_mask
[1])
603 caps
|= WLAN_RC_DS_FLAG
;
604 if ((sta
->ht_cap
.cap
& IEEE80211_HT_CAP_SUP_WIDTH_20_40
) &&
605 (conf_is_ht40(&priv
->hw
->conf
)))
606 caps
|= WLAN_RC_40_FLAG
;
607 if (conf_is_ht40(&priv
->hw
->conf
) &&
608 (sta
->ht_cap
.cap
& IEEE80211_HT_CAP_SGI_40
))
609 caps
|= WLAN_RC_SGI_FLAG
;
610 else if (conf_is_ht20(&priv
->hw
->conf
) &&
611 (sta
->ht_cap
.cap
& IEEE80211_HT_CAP_SGI_20
))
612 caps
|= WLAN_RC_SGI_FLAG
;
615 trate
->sta_index
= ista
->index
;
617 trate
->capflags
= cpu_to_be32(caps
);
620 static int ath9k_htc_send_rate_cmd(struct ath9k_htc_priv
*priv
,
621 struct ath9k_htc_target_rate
*trate
)
623 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
627 WMI_CMD_BUF(WMI_RC_RATE_UPDATE_CMDID
, trate
);
630 "Unable to initialize Rate information on target\n");
636 static void ath9k_htc_init_rate(struct ath9k_htc_priv
*priv
,
637 struct ieee80211_sta
*sta
)
639 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
640 struct ath9k_htc_target_rate trate
;
643 memset(&trate
, 0, sizeof(struct ath9k_htc_target_rate
));
644 ath9k_htc_setup_rate(priv
, sta
, &trate
);
645 ret
= ath9k_htc_send_rate_cmd(priv
, &trate
);
647 ath_dbg(common
, ATH_DBG_CONFIG
,
648 "Updated target sta: %pM, rate caps: 0x%X\n",
649 sta
->addr
, be32_to_cpu(trate
.capflags
));
652 static void ath9k_htc_update_rate(struct ath9k_htc_priv
*priv
,
653 struct ieee80211_vif
*vif
,
654 struct ieee80211_bss_conf
*bss_conf
)
656 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
657 struct ath9k_htc_target_rate trate
;
658 struct ieee80211_sta
*sta
;
661 memset(&trate
, 0, sizeof(struct ath9k_htc_target_rate
));
664 sta
= ieee80211_find_sta(vif
, bss_conf
->bssid
);
669 ath9k_htc_setup_rate(priv
, sta
, &trate
);
672 ret
= ath9k_htc_send_rate_cmd(priv
, &trate
);
674 ath_dbg(common
, ATH_DBG_CONFIG
,
675 "Updated target sta: %pM, rate caps: 0x%X\n",
676 bss_conf
->bssid
, be32_to_cpu(trate
.capflags
));
679 static int ath9k_htc_tx_aggr_oper(struct ath9k_htc_priv
*priv
,
680 struct ieee80211_vif
*vif
,
681 struct ieee80211_sta
*sta
,
682 enum ieee80211_ampdu_mlme_action action
,
685 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
686 struct ath9k_htc_target_aggr aggr
;
687 struct ath9k_htc_sta
*ista
;
691 if (tid
>= ATH9K_HTC_MAX_TID
)
694 memset(&aggr
, 0, sizeof(struct ath9k_htc_target_aggr
));
695 ista
= (struct ath9k_htc_sta
*) sta
->drv_priv
;
697 aggr
.sta_index
= ista
->index
;
698 aggr
.tidno
= tid
& 0xf;
699 aggr
.aggr_enable
= (action
== IEEE80211_AMPDU_TX_START
) ? true : false;
701 WMI_CMD_BUF(WMI_TX_AGGR_ENABLE_CMDID
, &aggr
);
703 ath_dbg(common
, ATH_DBG_CONFIG
,
704 "Unable to %s TX aggregation for (%pM, %d)\n",
705 (aggr
.aggr_enable
) ? "start" : "stop", sta
->addr
, tid
);
707 ath_dbg(common
, ATH_DBG_CONFIG
,
708 "%s TX aggregation for (%pM, %d)\n",
709 (aggr
.aggr_enable
) ? "Starting" : "Stopping",
712 spin_lock_bh(&priv
->tx_lock
);
713 ista
->tid_state
[tid
] = (aggr
.aggr_enable
&& !ret
) ? AGGR_START
: AGGR_STOP
;
714 spin_unlock_bh(&priv
->tx_lock
);
723 #ifdef CONFIG_ATH9K_HTC_DEBUGFS
725 static int ath9k_debugfs_open(struct inode
*inode
, struct file
*file
)
727 file
->private_data
= inode
->i_private
;
731 static ssize_t
read_file_tgt_stats(struct file
*file
, char __user
*user_buf
,
732 size_t count
, loff_t
*ppos
)
734 struct ath9k_htc_priv
*priv
= file
->private_data
;
735 struct ath9k_htc_target_stats cmd_rsp
;
737 unsigned int len
= 0;
740 memset(&cmd_rsp
, 0, sizeof(cmd_rsp
));
742 WMI_CMD(WMI_TGT_STATS_CMDID
);
747 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
748 "%19s : %10u\n", "TX Short Retries",
749 be32_to_cpu(cmd_rsp
.tx_shortretry
));
750 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
751 "%19s : %10u\n", "TX Long Retries",
752 be32_to_cpu(cmd_rsp
.tx_longretry
));
753 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
754 "%19s : %10u\n", "TX Xretries",
755 be32_to_cpu(cmd_rsp
.tx_xretries
));
756 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
757 "%19s : %10u\n", "TX Unaggr. Xretries",
758 be32_to_cpu(cmd_rsp
.ht_txunaggr_xretry
));
759 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
760 "%19s : %10u\n", "TX Xretries (HT)",
761 be32_to_cpu(cmd_rsp
.ht_tx_xretries
));
762 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
763 "%19s : %10u\n", "TX Rate", priv
->debug
.txrate
);
765 if (len
> sizeof(buf
))
768 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, len
);
771 static const struct file_operations fops_tgt_stats
= {
772 .read
= read_file_tgt_stats
,
773 .open
= ath9k_debugfs_open
,
774 .owner
= THIS_MODULE
,
775 .llseek
= default_llseek
,
778 static ssize_t
read_file_xmit(struct file
*file
, char __user
*user_buf
,
779 size_t count
, loff_t
*ppos
)
781 struct ath9k_htc_priv
*priv
= file
->private_data
;
783 unsigned int len
= 0;
785 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
786 "%20s : %10u\n", "Buffers queued",
787 priv
->debug
.tx_stats
.buf_queued
);
788 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
789 "%20s : %10u\n", "Buffers completed",
790 priv
->debug
.tx_stats
.buf_completed
);
791 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
792 "%20s : %10u\n", "SKBs queued",
793 priv
->debug
.tx_stats
.skb_queued
);
794 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
795 "%20s : %10u\n", "SKBs completed",
796 priv
->debug
.tx_stats
.skb_completed
);
797 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
798 "%20s : %10u\n", "SKBs dropped",
799 priv
->debug
.tx_stats
.skb_dropped
);
801 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
802 "%20s : %10u\n", "BE queued",
803 priv
->debug
.tx_stats
.queue_stats
[WME_AC_BE
]);
804 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
805 "%20s : %10u\n", "BK queued",
806 priv
->debug
.tx_stats
.queue_stats
[WME_AC_BK
]);
807 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
808 "%20s : %10u\n", "VI queued",
809 priv
->debug
.tx_stats
.queue_stats
[WME_AC_VI
]);
810 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
811 "%20s : %10u\n", "VO queued",
812 priv
->debug
.tx_stats
.queue_stats
[WME_AC_VO
]);
814 if (len
> sizeof(buf
))
817 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, len
);
820 static const struct file_operations fops_xmit
= {
821 .read
= read_file_xmit
,
822 .open
= ath9k_debugfs_open
,
823 .owner
= THIS_MODULE
,
824 .llseek
= default_llseek
,
827 static ssize_t
read_file_recv(struct file
*file
, char __user
*user_buf
,
828 size_t count
, loff_t
*ppos
)
830 struct ath9k_htc_priv
*priv
= file
->private_data
;
832 unsigned int len
= 0;
834 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
835 "%20s : %10u\n", "SKBs allocated",
836 priv
->debug
.rx_stats
.skb_allocated
);
837 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
838 "%20s : %10u\n", "SKBs completed",
839 priv
->debug
.rx_stats
.skb_completed
);
840 len
+= snprintf(buf
+ len
, sizeof(buf
) - len
,
841 "%20s : %10u\n", "SKBs Dropped",
842 priv
->debug
.rx_stats
.skb_dropped
);
844 if (len
> sizeof(buf
))
847 return simple_read_from_buffer(user_buf
, count
, ppos
, buf
, len
);
850 static const struct file_operations fops_recv
= {
851 .read
= read_file_recv
,
852 .open
= ath9k_debugfs_open
,
853 .owner
= THIS_MODULE
,
854 .llseek
= default_llseek
,
857 int ath9k_htc_init_debug(struct ath_hw
*ah
)
859 struct ath_common
*common
= ath9k_hw_common(ah
);
860 struct ath9k_htc_priv
*priv
= (struct ath9k_htc_priv
*) common
->priv
;
862 if (!ath9k_debugfs_root
)
865 priv
->debug
.debugfs_phy
= debugfs_create_dir(wiphy_name(priv
->hw
->wiphy
),
867 if (!priv
->debug
.debugfs_phy
)
870 priv
->debug
.debugfs_tgt_stats
= debugfs_create_file("tgt_stats", S_IRUSR
,
871 priv
->debug
.debugfs_phy
,
872 priv
, &fops_tgt_stats
);
873 if (!priv
->debug
.debugfs_tgt_stats
)
877 priv
->debug
.debugfs_xmit
= debugfs_create_file("xmit", S_IRUSR
,
878 priv
->debug
.debugfs_phy
,
880 if (!priv
->debug
.debugfs_xmit
)
883 priv
->debug
.debugfs_recv
= debugfs_create_file("recv", S_IRUSR
,
884 priv
->debug
.debugfs_phy
,
886 if (!priv
->debug
.debugfs_recv
)
892 ath9k_htc_exit_debug(ah
);
896 void ath9k_htc_exit_debug(struct ath_hw
*ah
)
898 struct ath_common
*common
= ath9k_hw_common(ah
);
899 struct ath9k_htc_priv
*priv
= (struct ath9k_htc_priv
*) common
->priv
;
901 debugfs_remove(priv
->debug
.debugfs_recv
);
902 debugfs_remove(priv
->debug
.debugfs_xmit
);
903 debugfs_remove(priv
->debug
.debugfs_tgt_stats
);
904 debugfs_remove(priv
->debug
.debugfs_phy
);
907 int ath9k_htc_debug_create_root(void)
909 ath9k_debugfs_root
= debugfs_create_dir(KBUILD_MODNAME
, NULL
);
910 if (!ath9k_debugfs_root
)
916 void ath9k_htc_debug_remove_root(void)
918 debugfs_remove(ath9k_debugfs_root
);
919 ath9k_debugfs_root
= NULL
;
922 #endif /* CONFIG_ATH9K_HTC_DEBUGFS */
928 void ath9k_htc_start_ani(struct ath9k_htc_priv
*priv
)
930 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
931 unsigned long timestamp
= jiffies_to_msecs(jiffies
);
933 common
->ani
.longcal_timer
= timestamp
;
934 common
->ani
.shortcal_timer
= timestamp
;
935 common
->ani
.checkani_timer
= timestamp
;
937 priv
->op_flags
|= OP_ANI_RUNNING
;
939 ieee80211_queue_delayed_work(common
->hw
, &priv
->ani_work
,
940 msecs_to_jiffies(ATH_ANI_POLLINTERVAL
));
943 void ath9k_htc_stop_ani(struct ath9k_htc_priv
*priv
)
945 cancel_delayed_work_sync(&priv
->ani_work
);
946 priv
->op_flags
&= ~OP_ANI_RUNNING
;
949 void ath9k_htc_ani_work(struct work_struct
*work
)
951 struct ath9k_htc_priv
*priv
=
952 container_of(work
, struct ath9k_htc_priv
, ani_work
.work
);
953 struct ath_hw
*ah
= priv
->ah
;
954 struct ath_common
*common
= ath9k_hw_common(ah
);
955 bool longcal
= false;
956 bool shortcal
= false;
957 bool aniflag
= false;
958 unsigned int timestamp
= jiffies_to_msecs(jiffies
);
959 u32 cal_interval
, short_cal_interval
;
961 short_cal_interval
= (ah
->opmode
== NL80211_IFTYPE_AP
) ?
962 ATH_AP_SHORT_CALINTERVAL
: ATH_STA_SHORT_CALINTERVAL
;
964 /* Only calibrate if awake */
965 if (ah
->power_mode
!= ATH9K_PM_AWAKE
)
968 /* Long calibration runs independently of short calibration. */
969 if ((timestamp
- common
->ani
.longcal_timer
) >= ATH_LONG_CALINTERVAL
) {
971 ath_dbg(common
, ATH_DBG_ANI
, "longcal @%lu\n", jiffies
);
972 common
->ani
.longcal_timer
= timestamp
;
975 /* Short calibration applies only while caldone is false */
976 if (!common
->ani
.caldone
) {
977 if ((timestamp
- common
->ani
.shortcal_timer
) >=
978 short_cal_interval
) {
980 ath_dbg(common
, ATH_DBG_ANI
,
981 "shortcal @%lu\n", jiffies
);
982 common
->ani
.shortcal_timer
= timestamp
;
983 common
->ani
.resetcal_timer
= timestamp
;
986 if ((timestamp
- common
->ani
.resetcal_timer
) >=
987 ATH_RESTART_CALINTERVAL
) {
988 common
->ani
.caldone
= ath9k_hw_reset_calvalid(ah
);
989 if (common
->ani
.caldone
)
990 common
->ani
.resetcal_timer
= timestamp
;
994 /* Verify whether we must check ANI */
995 if ((timestamp
- common
->ani
.checkani_timer
) >= ATH_ANI_POLLINTERVAL
) {
997 common
->ani
.checkani_timer
= timestamp
;
1000 /* Skip all processing if there's nothing to do. */
1001 if (longcal
|| shortcal
|| aniflag
) {
1003 ath9k_htc_ps_wakeup(priv
);
1005 /* Call ANI routine if necessary */
1007 ath9k_hw_ani_monitor(ah
, ah
->curchan
);
1009 /* Perform calibration if necessary */
1010 if (longcal
|| shortcal
)
1011 common
->ani
.caldone
=
1012 ath9k_hw_calibrate(ah
, ah
->curchan
,
1013 common
->rx_chainmask
,
1016 ath9k_htc_ps_restore(priv
);
1021 * Set timer interval based on previous results.
1022 * The interval must be the shortest necessary to satisfy ANI,
1023 * short calibration and long calibration.
1025 cal_interval
= ATH_LONG_CALINTERVAL
;
1026 if (priv
->ah
->config
.enable_ani
)
1027 cal_interval
= min(cal_interval
, (u32
)ATH_ANI_POLLINTERVAL
);
1028 if (!common
->ani
.caldone
)
1029 cal_interval
= min(cal_interval
, (u32
)short_cal_interval
);
1031 ieee80211_queue_delayed_work(common
->hw
, &priv
->ani_work
,
1032 msecs_to_jiffies(cal_interval
));
1035 /**********************/
1036 /* mac80211 Callbacks */
1037 /**********************/
1039 static void ath9k_htc_tx(struct ieee80211_hw
*hw
, struct sk_buff
*skb
)
1041 struct ieee80211_hdr
*hdr
;
1042 struct ath9k_htc_priv
*priv
= hw
->priv
;
1043 int padpos
, padsize
, ret
;
1045 hdr
= (struct ieee80211_hdr
*) skb
->data
;
1047 /* Add the padding after the header if this is not already done */
1048 padpos
= ath9k_cmn_padpos(hdr
->frame_control
);
1049 padsize
= padpos
& 3;
1050 if (padsize
&& skb
->len
> padpos
) {
1051 if (skb_headroom(skb
) < padsize
)
1053 skb_push(skb
, padsize
);
1054 memmove(skb
->data
, skb
->data
+ padsize
, padpos
);
1057 ret
= ath9k_htc_tx_start(priv
, skb
);
1059 if (ret
== -ENOMEM
) {
1060 ath_dbg(ath9k_hw_common(priv
->ah
), ATH_DBG_XMIT
,
1061 "Stopping TX queues\n");
1062 ieee80211_stop_queues(hw
);
1063 spin_lock_bh(&priv
->tx_lock
);
1064 priv
->tx_queues_stop
= true;
1065 spin_unlock_bh(&priv
->tx_lock
);
1067 ath_dbg(ath9k_hw_common(priv
->ah
), ATH_DBG_XMIT
,
1076 dev_kfree_skb_any(skb
);
1079 static int ath9k_htc_start(struct ieee80211_hw
*hw
)
1081 struct ath9k_htc_priv
*priv
= hw
->priv
;
1082 struct ath_hw
*ah
= priv
->ah
;
1083 struct ath_common
*common
= ath9k_hw_common(ah
);
1084 struct ieee80211_channel
*curchan
= hw
->conf
.channel
;
1085 struct ath9k_channel
*init_channel
;
1087 enum htc_phymode mode
;
1091 mutex_lock(&priv
->mutex
);
1093 ath_dbg(common
, ATH_DBG_CONFIG
,
1094 "Starting driver with initial channel: %d MHz\n",
1095 curchan
->center_freq
);
1097 /* Ensure that HW is awake before flushing RX */
1098 ath9k_htc_setpower(priv
, ATH9K_PM_AWAKE
);
1099 WMI_CMD(WMI_FLUSH_RECV_CMDID
);
1101 /* setup initial channel */
1102 init_channel
= ath9k_cmn_get_curchannel(hw
, ah
);
1104 ath9k_hw_htc_resetinit(ah
);
1105 ret
= ath9k_hw_reset(ah
, init_channel
, ah
->caldata
, false);
1108 "Unable to reset hardware; reset status %d (freq %u MHz)\n",
1109 ret
, curchan
->center_freq
);
1110 mutex_unlock(&priv
->mutex
);
1114 ath9k_cmn_update_txpow(ah
, priv
->curtxpow
, priv
->txpowlimit
,
1117 mode
= ath9k_htc_get_curmode(priv
, init_channel
);
1118 htc_mode
= cpu_to_be16(mode
);
1119 WMI_CMD_BUF(WMI_SET_MODE_CMDID
, &htc_mode
);
1120 WMI_CMD(WMI_ATH_INIT_CMDID
);
1121 WMI_CMD(WMI_START_RECV_CMDID
);
1123 ath9k_host_rx_init(priv
);
1125 ret
= ath9k_htc_update_cap_target(priv
);
1127 ath_dbg(common
, ATH_DBG_CONFIG
,
1128 "Failed to update capability in target\n");
1130 priv
->op_flags
&= ~OP_INVALID
;
1131 htc_start(priv
->htc
);
1133 spin_lock_bh(&priv
->tx_lock
);
1134 priv
->tx_queues_stop
= false;
1135 spin_unlock_bh(&priv
->tx_lock
);
1137 ieee80211_wake_queues(hw
);
1139 if (ah
->btcoex_hw
.scheme
== ATH_BTCOEX_CFG_3WIRE
) {
1140 ath9k_hw_btcoex_set_weight(ah
, AR_BT_COEX_WGHT
,
1141 AR_STOMP_LOW_WLAN_WGHT
);
1142 ath9k_hw_btcoex_enable(ah
);
1143 ath_htc_resume_btcoex_work(priv
);
1145 mutex_unlock(&priv
->mutex
);
1150 static void ath9k_htc_stop(struct ieee80211_hw
*hw
)
1152 struct ath9k_htc_priv
*priv
= hw
->priv
;
1153 struct ath_hw
*ah
= priv
->ah
;
1154 struct ath_common
*common
= ath9k_hw_common(ah
);
1158 mutex_lock(&priv
->mutex
);
1160 if (priv
->op_flags
& OP_INVALID
) {
1161 ath_dbg(common
, ATH_DBG_ANY
, "Device not present\n");
1162 mutex_unlock(&priv
->mutex
);
1166 ath9k_htc_ps_wakeup(priv
);
1167 htc_stop(priv
->htc
);
1168 WMI_CMD(WMI_DISABLE_INTR_CMDID
);
1169 WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID
);
1170 WMI_CMD(WMI_STOP_RECV_CMDID
);
1172 tasklet_kill(&priv
->swba_tasklet
);
1173 tasklet_kill(&priv
->rx_tasklet
);
1174 tasklet_kill(&priv
->tx_tasklet
);
1176 skb_queue_purge(&priv
->tx_queue
);
1178 mutex_unlock(&priv
->mutex
);
1180 /* Cancel all the running timers/work .. */
1181 cancel_work_sync(&priv
->fatal_work
);
1182 cancel_work_sync(&priv
->ps_work
);
1183 cancel_delayed_work_sync(&priv
->ath9k_led_blink_work
);
1184 ath9k_htc_stop_ani(priv
);
1185 ath9k_led_stop_brightness(priv
);
1187 mutex_lock(&priv
->mutex
);
1189 if (ah
->btcoex_hw
.enabled
) {
1190 ath9k_hw_btcoex_disable(ah
);
1191 if (ah
->btcoex_hw
.scheme
== ATH_BTCOEX_CFG_3WIRE
)
1192 ath_htc_cancel_btcoex_work(priv
);
1195 /* Remove a monitor interface if it's present. */
1196 if (priv
->ah
->is_monitoring
)
1197 ath9k_htc_remove_monitor_interface(priv
);
1199 ath9k_hw_phy_disable(ah
);
1200 ath9k_hw_disable(ah
);
1201 ath9k_htc_ps_restore(priv
);
1202 ath9k_htc_setpower(priv
, ATH9K_PM_FULL_SLEEP
);
1204 priv
->op_flags
|= OP_INVALID
;
1206 ath_dbg(common
, ATH_DBG_CONFIG
, "Driver halt\n");
1207 mutex_unlock(&priv
->mutex
);
1210 static int ath9k_htc_add_interface(struct ieee80211_hw
*hw
,
1211 struct ieee80211_vif
*vif
)
1213 struct ath9k_htc_priv
*priv
= hw
->priv
;
1214 struct ath9k_htc_vif
*avp
= (void *)vif
->drv_priv
;
1215 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
1216 struct ath9k_htc_target_vif hvif
;
1220 mutex_lock(&priv
->mutex
);
1222 if (priv
->nvifs
>= ATH9K_HTC_MAX_VIF
) {
1223 mutex_unlock(&priv
->mutex
);
1227 if (priv
->num_ibss_vif
||
1228 (priv
->nvifs
&& vif
->type
== NL80211_IFTYPE_ADHOC
)) {
1229 ath_err(common
, "IBSS coexistence with other modes is not allowed\n");
1230 mutex_unlock(&priv
->mutex
);
1234 if (((vif
->type
== NL80211_IFTYPE_AP
) ||
1235 (vif
->type
== NL80211_IFTYPE_ADHOC
)) &&
1236 ((priv
->num_ap_vif
+ priv
->num_ibss_vif
) >= ATH9K_HTC_MAX_BCN_VIF
)) {
1237 ath_err(common
, "Max. number of beaconing interfaces reached\n");
1238 mutex_unlock(&priv
->mutex
);
1242 ath9k_htc_ps_wakeup(priv
);
1243 memset(&hvif
, 0, sizeof(struct ath9k_htc_target_vif
));
1244 memcpy(&hvif
.myaddr
, vif
->addr
, ETH_ALEN
);
1246 switch (vif
->type
) {
1247 case NL80211_IFTYPE_STATION
:
1248 hvif
.opmode
= cpu_to_be32(HTC_M_STA
);
1250 case NL80211_IFTYPE_ADHOC
:
1251 hvif
.opmode
= cpu_to_be32(HTC_M_IBSS
);
1253 case NL80211_IFTYPE_AP
:
1254 hvif
.opmode
= cpu_to_be32(HTC_M_HOSTAP
);
1258 "Interface type %d not yet supported\n", vif
->type
);
1263 /* Index starts from zero on the target */
1264 avp
->index
= hvif
.index
= ffz(priv
->vif_slot
);
1265 hvif
.rtsthreshold
= cpu_to_be16(2304);
1266 WMI_CMD_BUF(WMI_VAP_CREATE_CMDID
, &hvif
);
1271 * We need a node in target to tx mgmt frames
1272 * before association.
1274 ret
= ath9k_htc_add_station(priv
, vif
, NULL
);
1276 WMI_CMD_BUF(WMI_VAP_REMOVE_CMDID
, &hvif
);
1280 ath9k_htc_set_bssid_mask(priv
, vif
);
1282 priv
->vif_slot
|= (1 << avp
->index
);
1285 INC_VIF(priv
, vif
->type
);
1287 if ((vif
->type
== NL80211_IFTYPE_AP
) ||
1288 (vif
->type
== NL80211_IFTYPE_ADHOC
))
1289 ath9k_htc_assign_bslot(priv
, vif
);
1291 ath9k_htc_set_opmode(priv
);
1293 if ((priv
->ah
->opmode
== NL80211_IFTYPE_AP
) &&
1294 !(priv
->op_flags
& OP_ANI_RUNNING
))
1295 ath9k_htc_start_ani(priv
);
1297 ath_dbg(common
, ATH_DBG_CONFIG
,
1298 "Attach a VIF of type: %d at idx: %d\n", vif
->type
, avp
->index
);
1301 ath9k_htc_ps_restore(priv
);
1302 mutex_unlock(&priv
->mutex
);
1307 static void ath9k_htc_remove_interface(struct ieee80211_hw
*hw
,
1308 struct ieee80211_vif
*vif
)
1310 struct ath9k_htc_priv
*priv
= hw
->priv
;
1311 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
1312 struct ath9k_htc_vif
*avp
= (void *)vif
->drv_priv
;
1313 struct ath9k_htc_target_vif hvif
;
1317 mutex_lock(&priv
->mutex
);
1318 ath9k_htc_ps_wakeup(priv
);
1320 memset(&hvif
, 0, sizeof(struct ath9k_htc_target_vif
));
1321 memcpy(&hvif
.myaddr
, vif
->addr
, ETH_ALEN
);
1322 hvif
.index
= avp
->index
;
1323 WMI_CMD_BUF(WMI_VAP_REMOVE_CMDID
, &hvif
);
1325 priv
->vif_slot
&= ~(1 << avp
->index
);
1327 ath9k_htc_remove_station(priv
, vif
, NULL
);
1329 DEC_VIF(priv
, vif
->type
);
1331 if ((vif
->type
== NL80211_IFTYPE_AP
) ||
1332 (vif
->type
== NL80211_IFTYPE_ADHOC
))
1333 ath9k_htc_remove_bslot(priv
, vif
);
1335 ath9k_htc_set_opmode(priv
);
1338 * Stop ANI only if there are no associated station interfaces.
1340 if ((vif
->type
== NL80211_IFTYPE_AP
) && (priv
->num_ap_vif
== 0)) {
1341 priv
->rearm_ani
= false;
1342 ieee80211_iterate_active_interfaces_atomic(priv
->hw
,
1343 ath9k_htc_vif_iter
, priv
);
1344 if (!priv
->rearm_ani
)
1345 ath9k_htc_stop_ani(priv
);
1348 ath_dbg(common
, ATH_DBG_CONFIG
, "Detach Interface at idx: %d\n", avp
->index
);
1350 ath9k_htc_ps_restore(priv
);
1351 mutex_unlock(&priv
->mutex
);
1354 static int ath9k_htc_config(struct ieee80211_hw
*hw
, u32 changed
)
1356 struct ath9k_htc_priv
*priv
= hw
->priv
;
1357 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
1358 struct ieee80211_conf
*conf
= &hw
->conf
;
1360 mutex_lock(&priv
->mutex
);
1362 if (changed
& IEEE80211_CONF_CHANGE_IDLE
) {
1363 bool enable_radio
= false;
1364 bool idle
= !!(conf
->flags
& IEEE80211_CONF_IDLE
);
1366 mutex_lock(&priv
->htc_pm_lock
);
1367 if (!idle
&& priv
->ps_idle
)
1368 enable_radio
= true;
1369 priv
->ps_idle
= idle
;
1370 mutex_unlock(&priv
->htc_pm_lock
);
1373 ath_dbg(common
, ATH_DBG_CONFIG
,
1374 "not-idle: enabling radio\n");
1375 ath9k_htc_setpower(priv
, ATH9K_PM_AWAKE
);
1376 ath9k_htc_radio_enable(hw
);
1381 * Monitor interface should be added before
1382 * IEEE80211_CONF_CHANGE_CHANNEL is handled.
1384 if (changed
& IEEE80211_CONF_CHANGE_MONITOR
) {
1385 if ((conf
->flags
& IEEE80211_CONF_MONITOR
) &&
1386 !priv
->ah
->is_monitoring
)
1387 ath9k_htc_add_monitor_interface(priv
);
1388 else if (priv
->ah
->is_monitoring
)
1389 ath9k_htc_remove_monitor_interface(priv
);
1392 if (changed
& IEEE80211_CONF_CHANGE_CHANNEL
) {
1393 struct ieee80211_channel
*curchan
= hw
->conf
.channel
;
1394 int pos
= curchan
->hw_value
;
1396 ath_dbg(common
, ATH_DBG_CONFIG
, "Set channel: %d MHz\n",
1397 curchan
->center_freq
);
1399 ath9k_cmn_update_ichannel(&priv
->ah
->channels
[pos
],
1401 hw
->conf
.channel_type
);
1403 if (ath9k_htc_set_channel(priv
, hw
, &priv
->ah
->channels
[pos
]) < 0) {
1404 ath_err(common
, "Unable to set channel\n");
1405 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_POWER
) {
1423 priv
->txpowlimit
= 2 * conf
->power_level
;
1424 ath9k_cmn_update_txpow(priv
->ah
, priv
->curtxpow
,
1425 priv
->txpowlimit
, &priv
->curtxpow
);
1428 if (changed
& IEEE80211_CONF_CHANGE_IDLE
) {
1429 mutex_lock(&priv
->htc_pm_lock
);
1430 if (!priv
->ps_idle
) {
1431 mutex_unlock(&priv
->htc_pm_lock
);
1434 mutex_unlock(&priv
->htc_pm_lock
);
1436 ath_dbg(common
, ATH_DBG_CONFIG
,
1437 "idle: disabling radio\n");
1438 ath9k_htc_radio_disable(hw
);
1442 mutex_unlock(&priv
->mutex
);
1446 #define SUPPORTED_FILTERS \
1447 (FIF_PROMISC_IN_BSS | \
1452 FIF_BCN_PRBRESP_PROMISC | \
1456 static void ath9k_htc_configure_filter(struct ieee80211_hw
*hw
,
1457 unsigned int changed_flags
,
1458 unsigned int *total_flags
,
1461 struct ath9k_htc_priv
*priv
= hw
->priv
;
1464 mutex_lock(&priv
->mutex
);
1465 ath9k_htc_ps_wakeup(priv
);
1467 changed_flags
&= SUPPORTED_FILTERS
;
1468 *total_flags
&= SUPPORTED_FILTERS
;
1470 priv
->rxfilter
= *total_flags
;
1471 rfilt
= ath9k_htc_calcrxfilter(priv
);
1472 ath9k_hw_setrxfilter(priv
->ah
, rfilt
);
1474 ath_dbg(ath9k_hw_common(priv
->ah
), ATH_DBG_CONFIG
,
1475 "Set HW RX filter: 0x%x\n", rfilt
);
1477 ath9k_htc_ps_restore(priv
);
1478 mutex_unlock(&priv
->mutex
);
1481 static int ath9k_htc_sta_add(struct ieee80211_hw
*hw
,
1482 struct ieee80211_vif
*vif
,
1483 struct ieee80211_sta
*sta
)
1485 struct ath9k_htc_priv
*priv
= hw
->priv
;
1488 mutex_lock(&priv
->mutex
);
1489 ath9k_htc_ps_wakeup(priv
);
1490 ret
= ath9k_htc_add_station(priv
, vif
, sta
);
1492 ath9k_htc_init_rate(priv
, sta
);
1493 ath9k_htc_ps_restore(priv
);
1494 mutex_unlock(&priv
->mutex
);
1499 static int ath9k_htc_sta_remove(struct ieee80211_hw
*hw
,
1500 struct ieee80211_vif
*vif
,
1501 struct ieee80211_sta
*sta
)
1503 struct ath9k_htc_priv
*priv
= hw
->priv
;
1506 mutex_lock(&priv
->mutex
);
1507 ath9k_htc_ps_wakeup(priv
);
1508 ret
= ath9k_htc_remove_station(priv
, vif
, sta
);
1509 ath9k_htc_ps_restore(priv
);
1510 mutex_unlock(&priv
->mutex
);
1515 static int ath9k_htc_conf_tx(struct ieee80211_hw
*hw
, u16 queue
,
1516 const struct ieee80211_tx_queue_params
*params
)
1518 struct ath9k_htc_priv
*priv
= hw
->priv
;
1519 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
1520 struct ath9k_tx_queue_info qi
;
1523 if (queue
>= WME_NUM_AC
)
1526 mutex_lock(&priv
->mutex
);
1527 ath9k_htc_ps_wakeup(priv
);
1529 memset(&qi
, 0, sizeof(struct ath9k_tx_queue_info
));
1531 qi
.tqi_aifs
= params
->aifs
;
1532 qi
.tqi_cwmin
= params
->cw_min
;
1533 qi
.tqi_cwmax
= params
->cw_max
;
1534 qi
.tqi_burstTime
= params
->txop
;
1536 qnum
= get_hw_qnum(queue
, priv
->hwq_map
);
1538 ath_dbg(common
, ATH_DBG_CONFIG
,
1539 "Configure tx [queue/hwq] [%d/%d], aifs: %d, cw_min: %d, cw_max: %d, txop: %d\n",
1540 queue
, qnum
, params
->aifs
, params
->cw_min
,
1541 params
->cw_max
, params
->txop
);
1543 ret
= ath_htc_txq_update(priv
, qnum
, &qi
);
1545 ath_err(common
, "TXQ Update failed\n");
1549 if ((priv
->ah
->opmode
== NL80211_IFTYPE_ADHOC
) &&
1550 (qnum
== priv
->hwq_map
[WME_AC_BE
]))
1551 ath9k_htc_beaconq_config(priv
);
1553 ath9k_htc_ps_restore(priv
);
1554 mutex_unlock(&priv
->mutex
);
1559 static int ath9k_htc_set_key(struct ieee80211_hw
*hw
,
1560 enum set_key_cmd cmd
,
1561 struct ieee80211_vif
*vif
,
1562 struct ieee80211_sta
*sta
,
1563 struct ieee80211_key_conf
*key
)
1565 struct ath9k_htc_priv
*priv
= hw
->priv
;
1566 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
1569 if (htc_modparam_nohwcrypt
)
1572 mutex_lock(&priv
->mutex
);
1573 ath_dbg(common
, ATH_DBG_CONFIG
, "Set HW Key\n");
1574 ath9k_htc_ps_wakeup(priv
);
1578 ret
= ath_key_config(common
, vif
, sta
, key
);
1580 key
->hw_key_idx
= ret
;
1581 /* push IV and Michael MIC generation to stack */
1582 key
->flags
|= IEEE80211_KEY_FLAG_GENERATE_IV
;
1583 if (key
->cipher
== WLAN_CIPHER_SUITE_TKIP
)
1584 key
->flags
|= IEEE80211_KEY_FLAG_GENERATE_MMIC
;
1585 if (priv
->ah
->sw_mgmt_crypto
&&
1586 key
->cipher
== WLAN_CIPHER_SUITE_CCMP
)
1587 key
->flags
|= IEEE80211_KEY_FLAG_SW_MGMT
;
1592 ath_key_delete(common
, key
);
1598 ath9k_htc_ps_restore(priv
);
1599 mutex_unlock(&priv
->mutex
);
1604 static void ath9k_htc_bss_info_changed(struct ieee80211_hw
*hw
,
1605 struct ieee80211_vif
*vif
,
1606 struct ieee80211_bss_conf
*bss_conf
,
1609 struct ath9k_htc_priv
*priv
= hw
->priv
;
1610 struct ath_hw
*ah
= priv
->ah
;
1611 struct ath_common
*common
= ath9k_hw_common(ah
);
1614 mutex_lock(&priv
->mutex
);
1615 ath9k_htc_ps_wakeup(priv
);
1618 * Set the HW AID/BSSID only for the first station interface
1621 set_assoc
= !!((priv
->ah
->opmode
== NL80211_IFTYPE_ADHOC
) ||
1622 ((priv
->ah
->opmode
== NL80211_IFTYPE_STATION
) &&
1623 (priv
->num_sta_vif
== 1)));
1626 if (changed
& BSS_CHANGED_ASSOC
) {
1628 ath_dbg(common
, ATH_DBG_CONFIG
, "BSS Changed ASSOC %d\n",
1631 common
->curaid
= bss_conf
->assoc
?
1634 if (bss_conf
->assoc
)
1635 ath9k_htc_start_ani(priv
);
1637 ath9k_htc_stop_ani(priv
);
1641 if (changed
& BSS_CHANGED_BSSID
) {
1643 memcpy(common
->curbssid
, bss_conf
->bssid
, ETH_ALEN
);
1644 ath9k_hw_write_associd(ah
);
1646 ath_dbg(common
, ATH_DBG_CONFIG
,
1647 "BSSID: %pM aid: 0x%x\n",
1648 common
->curbssid
, common
->curaid
);
1652 if ((changed
& BSS_CHANGED_BEACON_ENABLED
) && bss_conf
->enable_beacon
) {
1653 ath_dbg(common
, ATH_DBG_CONFIG
,
1654 "Beacon enabled for BSS: %pM\n", bss_conf
->bssid
);
1655 priv
->op_flags
|= OP_ENABLE_BEACON
;
1656 ath9k_htc_beacon_config(priv
, vif
);
1659 if ((changed
& BSS_CHANGED_BEACON_ENABLED
) && !bss_conf
->enable_beacon
) {
1661 * Disable SWBA interrupt only if there are no
1662 * AP/IBSS interfaces.
1664 if ((priv
->num_ap_vif
<= 1) || priv
->num_ibss_vif
) {
1665 ath_dbg(common
, ATH_DBG_CONFIG
,
1666 "Beacon disabled for BSS: %pM\n",
1668 priv
->op_flags
&= ~OP_ENABLE_BEACON
;
1669 ath9k_htc_beacon_config(priv
, vif
);
1673 if (changed
& BSS_CHANGED_BEACON_INT
) {
1675 * Reset the HW TSF for the first AP interface.
1677 if ((priv
->ah
->opmode
== NL80211_IFTYPE_AP
) &&
1678 (priv
->nvifs
== 1) &&
1679 (priv
->num_ap_vif
== 1) &&
1680 (vif
->type
== NL80211_IFTYPE_AP
)) {
1681 priv
->op_flags
|= OP_TSF_RESET
;
1683 ath_dbg(common
, ATH_DBG_CONFIG
,
1684 "Beacon interval changed for BSS: %pM\n",
1686 ath9k_htc_beacon_config(priv
, vif
);
1689 if (changed
& BSS_CHANGED_ERP_SLOT
) {
1690 if (bss_conf
->use_short_slot
)
1695 ath9k_hw_init_global_settings(ah
);
1698 if (changed
& BSS_CHANGED_HT
)
1699 ath9k_htc_update_rate(priv
, vif
, bss_conf
);
1701 ath9k_htc_ps_restore(priv
);
1702 mutex_unlock(&priv
->mutex
);
1705 static u64
ath9k_htc_get_tsf(struct ieee80211_hw
*hw
)
1707 struct ath9k_htc_priv
*priv
= hw
->priv
;
1710 mutex_lock(&priv
->mutex
);
1711 ath9k_htc_ps_wakeup(priv
);
1712 tsf
= ath9k_hw_gettsf64(priv
->ah
);
1713 ath9k_htc_ps_restore(priv
);
1714 mutex_unlock(&priv
->mutex
);
1719 static void ath9k_htc_set_tsf(struct ieee80211_hw
*hw
, u64 tsf
)
1721 struct ath9k_htc_priv
*priv
= hw
->priv
;
1723 mutex_lock(&priv
->mutex
);
1724 ath9k_htc_ps_wakeup(priv
);
1725 ath9k_hw_settsf64(priv
->ah
, tsf
);
1726 ath9k_htc_ps_restore(priv
);
1727 mutex_unlock(&priv
->mutex
);
1730 static void ath9k_htc_reset_tsf(struct ieee80211_hw
*hw
)
1732 struct ath9k_htc_priv
*priv
= hw
->priv
;
1734 mutex_lock(&priv
->mutex
);
1735 ath9k_htc_ps_wakeup(priv
);
1736 ath9k_hw_reset_tsf(priv
->ah
);
1737 ath9k_htc_ps_restore(priv
);
1738 mutex_unlock(&priv
->mutex
);
1741 static int ath9k_htc_ampdu_action(struct ieee80211_hw
*hw
,
1742 struct ieee80211_vif
*vif
,
1743 enum ieee80211_ampdu_mlme_action action
,
1744 struct ieee80211_sta
*sta
,
1745 u16 tid
, u16
*ssn
, u8 buf_size
)
1747 struct ath9k_htc_priv
*priv
= hw
->priv
;
1748 struct ath9k_htc_sta
*ista
;
1751 mutex_lock(&priv
->mutex
);
1754 case IEEE80211_AMPDU_RX_START
:
1756 case IEEE80211_AMPDU_RX_STOP
:
1758 case IEEE80211_AMPDU_TX_START
:
1759 ret
= ath9k_htc_tx_aggr_oper(priv
, vif
, sta
, action
, tid
);
1761 ieee80211_start_tx_ba_cb_irqsafe(vif
, sta
->addr
, tid
);
1763 case IEEE80211_AMPDU_TX_STOP
:
1764 ath9k_htc_tx_aggr_oper(priv
, vif
, sta
, action
, tid
);
1765 ieee80211_stop_tx_ba_cb_irqsafe(vif
, sta
->addr
, tid
);
1767 case IEEE80211_AMPDU_TX_OPERATIONAL
:
1768 ista
= (struct ath9k_htc_sta
*) sta
->drv_priv
;
1769 spin_lock_bh(&priv
->tx_lock
);
1770 ista
->tid_state
[tid
] = AGGR_OPERATIONAL
;
1771 spin_unlock_bh(&priv
->tx_lock
);
1774 ath_err(ath9k_hw_common(priv
->ah
), "Unknown AMPDU action\n");
1777 mutex_unlock(&priv
->mutex
);
1782 static void ath9k_htc_sw_scan_start(struct ieee80211_hw
*hw
)
1784 struct ath9k_htc_priv
*priv
= hw
->priv
;
1786 mutex_lock(&priv
->mutex
);
1787 spin_lock_bh(&priv
->beacon_lock
);
1788 priv
->op_flags
|= OP_SCANNING
;
1789 spin_unlock_bh(&priv
->beacon_lock
);
1790 cancel_work_sync(&priv
->ps_work
);
1791 ath9k_htc_stop_ani(priv
);
1792 mutex_unlock(&priv
->mutex
);
1795 static void ath9k_htc_sw_scan_complete(struct ieee80211_hw
*hw
)
1797 struct ath9k_htc_priv
*priv
= hw
->priv
;
1799 mutex_lock(&priv
->mutex
);
1800 spin_lock_bh(&priv
->beacon_lock
);
1801 priv
->op_flags
&= ~OP_SCANNING
;
1802 spin_unlock_bh(&priv
->beacon_lock
);
1803 ath9k_htc_ps_wakeup(priv
);
1804 ath9k_htc_vif_reconfig(priv
);
1805 ath9k_htc_ps_restore(priv
);
1806 mutex_unlock(&priv
->mutex
);
1809 static int ath9k_htc_set_rts_threshold(struct ieee80211_hw
*hw
, u32 value
)
1814 static void ath9k_htc_set_coverage_class(struct ieee80211_hw
*hw
,
1817 struct ath9k_htc_priv
*priv
= hw
->priv
;
1819 mutex_lock(&priv
->mutex
);
1820 ath9k_htc_ps_wakeup(priv
);
1821 priv
->ah
->coverage_class
= coverage_class
;
1822 ath9k_hw_init_global_settings(priv
->ah
);
1823 ath9k_htc_ps_restore(priv
);
1824 mutex_unlock(&priv
->mutex
);
1827 struct ieee80211_ops ath9k_htc_ops
= {
1829 .start
= ath9k_htc_start
,
1830 .stop
= ath9k_htc_stop
,
1831 .add_interface
= ath9k_htc_add_interface
,
1832 .remove_interface
= ath9k_htc_remove_interface
,
1833 .config
= ath9k_htc_config
,
1834 .configure_filter
= ath9k_htc_configure_filter
,
1835 .sta_add
= ath9k_htc_sta_add
,
1836 .sta_remove
= ath9k_htc_sta_remove
,
1837 .conf_tx
= ath9k_htc_conf_tx
,
1838 .bss_info_changed
= ath9k_htc_bss_info_changed
,
1839 .set_key
= ath9k_htc_set_key
,
1840 .get_tsf
= ath9k_htc_get_tsf
,
1841 .set_tsf
= ath9k_htc_set_tsf
,
1842 .reset_tsf
= ath9k_htc_reset_tsf
,
1843 .ampdu_action
= ath9k_htc_ampdu_action
,
1844 .sw_scan_start
= ath9k_htc_sw_scan_start
,
1845 .sw_scan_complete
= ath9k_htc_sw_scan_complete
,
1846 .set_rts_threshold
= ath9k_htc_set_rts_threshold
,
1847 .rfkill_poll
= ath9k_htc_rfkill_poll_state
,
1848 .set_coverage_class
= ath9k_htc_set_coverage_class
,