2 * Copyright (c) 2010-2011 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.
23 /* HACK Alert: Use 11NG for 2.4, use 11NA for 5 */
24 static enum htc_phymode
ath9k_htc_get_curmode(struct ath9k_htc_priv
*priv
,
25 struct ath9k_channel
*ichan
)
27 enum htc_phymode mode
;
31 switch (ichan
->chanmode
) {
34 case CHANNEL_G_HT40PLUS
:
35 case CHANNEL_G_HT40MINUS
:
40 case CHANNEL_A_HT40PLUS
:
41 case CHANNEL_A_HT40MINUS
:
53 bool ath9k_htc_setpower(struct ath9k_htc_priv
*priv
,
54 enum ath9k_power_mode mode
)
58 mutex_lock(&priv
->htc_pm_lock
);
59 ret
= ath9k_hw_setpower(priv
->ah
, mode
);
60 mutex_unlock(&priv
->htc_pm_lock
);
65 void ath9k_htc_ps_wakeup(struct ath9k_htc_priv
*priv
)
67 mutex_lock(&priv
->htc_pm_lock
);
68 if (++priv
->ps_usecount
!= 1)
70 ath9k_hw_setpower(priv
->ah
, ATH9K_PM_AWAKE
);
73 mutex_unlock(&priv
->htc_pm_lock
);
76 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_setrxabort(priv
->ah
, true);
86 ath9k_hw_stopdmarecv(priv
->ah
, &reset
);
87 ath9k_hw_setpower(priv
->ah
, ATH9K_PM_FULL_SLEEP
);
88 } else if (priv
->ps_enabled
) {
89 ath9k_hw_setpower(priv
->ah
, ATH9K_PM_NETWORK_SLEEP
);
93 mutex_unlock(&priv
->htc_pm_lock
);
96 void ath9k_ps_work(struct work_struct
*work
)
98 struct ath9k_htc_priv
*priv
=
99 container_of(work
, struct ath9k_htc_priv
,
101 ath9k_htc_setpower(priv
, ATH9K_PM_AWAKE
);
103 /* The chip wakes up after receiving the first beacon
104 while network sleep is enabled. For the driver to
105 be in sync with the hw, set the chip to awake and
106 only then set it to sleep.
108 ath9k_htc_setpower(priv
, ATH9K_PM_NETWORK_SLEEP
);
111 static void ath9k_htc_vif_iter(void *data
, u8
*mac
, struct ieee80211_vif
*vif
)
113 struct ath9k_htc_priv
*priv
= data
;
114 struct ieee80211_bss_conf
*bss_conf
= &vif
->bss_conf
;
116 if ((vif
->type
== NL80211_IFTYPE_AP
||
117 vif
->type
== NL80211_IFTYPE_MESH_POINT
) &&
118 bss_conf
->enable_beacon
)
119 priv
->reconfig_beacon
= true;
121 if (bss_conf
->assoc
) {
122 priv
->rearm_ani
= true;
123 priv
->reconfig_beacon
= true;
127 static void ath9k_htc_vif_reconfig(struct ath9k_htc_priv
*priv
)
129 priv
->rearm_ani
= false;
130 priv
->reconfig_beacon
= false;
132 ieee80211_iterate_active_interfaces_atomic(
133 priv
->hw
, IEEE80211_IFACE_ITER_RESUME_ALL
,
134 ath9k_htc_vif_iter
, priv
);
136 ath9k_htc_start_ani(priv
);
138 if (priv
->reconfig_beacon
) {
139 ath9k_htc_ps_wakeup(priv
);
140 ath9k_htc_beacon_reconfig(priv
);
141 ath9k_htc_ps_restore(priv
);
145 static void ath9k_htc_bssid_iter(void *data
, u8
*mac
, struct ieee80211_vif
*vif
)
147 struct ath9k_vif_iter_data
*iter_data
= data
;
150 for (i
= 0; i
< ETH_ALEN
; i
++)
151 iter_data
->mask
[i
] &= ~(iter_data
->hw_macaddr
[i
] ^ mac
[i
]);
154 static void ath9k_htc_set_bssid_mask(struct ath9k_htc_priv
*priv
,
155 struct ieee80211_vif
*vif
)
157 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
158 struct ath9k_vif_iter_data iter_data
;
161 * Use the hardware MAC address as reference, the hardware uses it
162 * together with the BSSID mask when matching addresses.
164 iter_data
.hw_macaddr
= common
->macaddr
;
165 memset(&iter_data
.mask
, 0xff, ETH_ALEN
);
168 ath9k_htc_bssid_iter(&iter_data
, vif
->addr
, vif
);
170 /* Get list of all active MAC addresses */
171 ieee80211_iterate_active_interfaces_atomic(
172 priv
->hw
, IEEE80211_IFACE_ITER_RESUME_ALL
,
173 ath9k_htc_bssid_iter
, &iter_data
);
175 memcpy(common
->bssidmask
, iter_data
.mask
, ETH_ALEN
);
176 ath_hw_setbssidmask(common
);
179 static void ath9k_htc_set_opmode(struct ath9k_htc_priv
*priv
)
181 if (priv
->num_ibss_vif
)
182 priv
->ah
->opmode
= NL80211_IFTYPE_ADHOC
;
183 else if (priv
->num_ap_vif
)
184 priv
->ah
->opmode
= NL80211_IFTYPE_AP
;
185 else if (priv
->num_mbss_vif
)
186 priv
->ah
->opmode
= NL80211_IFTYPE_MESH_POINT
;
188 priv
->ah
->opmode
= NL80211_IFTYPE_STATION
;
190 ath9k_hw_setopmode(priv
->ah
);
193 void ath9k_htc_reset(struct ath9k_htc_priv
*priv
)
195 struct ath_hw
*ah
= priv
->ah
;
196 struct ath_common
*common
= ath9k_hw_common(ah
);
197 struct ieee80211_channel
*channel
= priv
->hw
->conf
.chandef
.chan
;
198 struct ath9k_hw_cal_data
*caldata
= NULL
;
199 enum htc_phymode mode
;
204 mutex_lock(&priv
->mutex
);
205 ath9k_htc_ps_wakeup(priv
);
207 ath9k_htc_stop_ani(priv
);
208 ieee80211_stop_queues(priv
->hw
);
210 del_timer_sync(&priv
->tx
.cleanup_timer
);
211 ath9k_htc_tx_drain(priv
);
213 WMI_CMD(WMI_DISABLE_INTR_CMDID
);
214 WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID
);
215 WMI_CMD(WMI_STOP_RECV_CMDID
);
217 ath9k_wmi_event_drain(priv
);
219 caldata
= &priv
->caldata
;
220 ret
= ath9k_hw_reset(ah
, ah
->curchan
, caldata
, false);
223 "Unable to reset device (%u Mhz) reset status %d\n",
224 channel
->center_freq
, ret
);
227 ath9k_cmn_update_txpow(ah
, priv
->curtxpow
, priv
->txpowlimit
,
230 WMI_CMD(WMI_START_RECV_CMDID
);
231 ath9k_host_rx_init(priv
);
233 mode
= ath9k_htc_get_curmode(priv
, ah
->curchan
);
234 htc_mode
= cpu_to_be16(mode
);
235 WMI_CMD_BUF(WMI_SET_MODE_CMDID
, &htc_mode
);
237 WMI_CMD(WMI_ENABLE_INTR_CMDID
);
238 htc_start(priv
->htc
);
239 ath9k_htc_vif_reconfig(priv
);
240 ieee80211_wake_queues(priv
->hw
);
242 mod_timer(&priv
->tx
.cleanup_timer
,
243 jiffies
+ msecs_to_jiffies(ATH9K_HTC_TX_CLEANUP_INTERVAL
));
245 ath9k_htc_ps_restore(priv
);
246 mutex_unlock(&priv
->mutex
);
249 static int ath9k_htc_set_channel(struct ath9k_htc_priv
*priv
,
250 struct ieee80211_hw
*hw
,
251 struct ath9k_channel
*hchan
)
253 struct ath_hw
*ah
= priv
->ah
;
254 struct ath_common
*common
= ath9k_hw_common(ah
);
255 struct ieee80211_conf
*conf
= &common
->hw
->conf
;
257 struct ieee80211_channel
*channel
= hw
->conf
.chandef
.chan
;
258 struct ath9k_hw_cal_data
*caldata
= NULL
;
259 enum htc_phymode mode
;
264 if (test_bit(OP_INVALID
, &priv
->op_flags
))
267 fastcc
= !!(hw
->conf
.flags
& IEEE80211_CONF_OFFCHANNEL
);
269 ath9k_htc_ps_wakeup(priv
);
271 del_timer_sync(&priv
->tx
.cleanup_timer
);
272 ath9k_htc_tx_drain(priv
);
274 WMI_CMD(WMI_DISABLE_INTR_CMDID
);
275 WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID
);
276 WMI_CMD(WMI_STOP_RECV_CMDID
);
278 ath9k_wmi_event_drain(priv
);
280 ath_dbg(common
, CONFIG
,
281 "(%u MHz) -> (%u MHz), HT: %d, HT40: %d fastcc: %d\n",
282 priv
->ah
->curchan
->channel
,
283 channel
->center_freq
, conf_is_ht(conf
), conf_is_ht40(conf
),
287 caldata
= &priv
->caldata
;
289 ret
= ath9k_hw_reset(ah
, hchan
, caldata
, fastcc
);
292 "Unable to reset channel (%u Mhz) reset status %d\n",
293 channel
->center_freq
, ret
);
297 ath9k_cmn_update_txpow(ah
, priv
->curtxpow
, priv
->txpowlimit
,
300 WMI_CMD(WMI_START_RECV_CMDID
);
304 ath9k_host_rx_init(priv
);
306 mode
= ath9k_htc_get_curmode(priv
, hchan
);
307 htc_mode
= cpu_to_be16(mode
);
308 WMI_CMD_BUF(WMI_SET_MODE_CMDID
, &htc_mode
);
312 WMI_CMD(WMI_ENABLE_INTR_CMDID
);
316 htc_start(priv
->htc
);
318 if (!test_bit(OP_SCANNING
, &priv
->op_flags
) &&
319 !(hw
->conf
.flags
& IEEE80211_CONF_OFFCHANNEL
))
320 ath9k_htc_vif_reconfig(priv
);
322 mod_timer(&priv
->tx
.cleanup_timer
,
323 jiffies
+ msecs_to_jiffies(ATH9K_HTC_TX_CLEANUP_INTERVAL
));
326 ath9k_htc_ps_restore(priv
);
331 * Monitor mode handling is a tad complicated because the firmware requires
332 * an interface to be created exclusively, while mac80211 doesn't associate
333 * an interface with the mode.
335 * So, for now, only one monitor interface can be configured.
337 static void __ath9k_htc_remove_monitor_interface(struct ath9k_htc_priv
*priv
)
339 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
340 struct ath9k_htc_target_vif hvif
;
344 memset(&hvif
, 0, sizeof(struct ath9k_htc_target_vif
));
345 memcpy(&hvif
.myaddr
, common
->macaddr
, ETH_ALEN
);
346 hvif
.index
= priv
->mon_vif_idx
;
347 WMI_CMD_BUF(WMI_VAP_REMOVE_CMDID
, &hvif
);
349 ath_err(common
, "Unable to remove monitor interface at idx: %d\n",
354 priv
->vif_slot
&= ~(1 << priv
->mon_vif_idx
);
357 static int ath9k_htc_add_monitor_interface(struct ath9k_htc_priv
*priv
)
359 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
360 struct ath9k_htc_target_vif hvif
;
361 struct ath9k_htc_target_sta tsta
;
362 int ret
= 0, sta_idx
;
365 if ((priv
->nvifs
>= ATH9K_HTC_MAX_VIF
) ||
366 (priv
->nstations
>= ATH9K_HTC_MAX_STA
)) {
371 sta_idx
= ffz(priv
->sta_slot
);
372 if ((sta_idx
< 0) || (sta_idx
> ATH9K_HTC_MAX_STA
)) {
380 memset(&hvif
, 0, sizeof(struct ath9k_htc_target_vif
));
381 memcpy(&hvif
.myaddr
, common
->macaddr
, ETH_ALEN
);
383 hvif
.opmode
= HTC_M_MONITOR
;
384 hvif
.index
= ffz(priv
->vif_slot
);
386 WMI_CMD_BUF(WMI_VAP_CREATE_CMDID
, &hvif
);
391 * Assign the monitor interface index as a special case here.
392 * This is needed when the interface is brought down.
394 priv
->mon_vif_idx
= hvif
.index
;
395 priv
->vif_slot
|= (1 << hvif
.index
);
398 * Set the hardware mode to monitor only if there are no
402 priv
->ah
->opmode
= NL80211_IFTYPE_MONITOR
;
407 * Associate a station with the interface for packet injection.
409 memset(&tsta
, 0, sizeof(struct ath9k_htc_target_sta
));
411 memcpy(&tsta
.macaddr
, common
->macaddr
, ETH_ALEN
);
414 tsta
.sta_index
= sta_idx
;
415 tsta
.vif_index
= hvif
.index
;
416 tsta
.maxampdu
= cpu_to_be16(0xffff);
418 WMI_CMD_BUF(WMI_NODE_CREATE_CMDID
, &tsta
);
420 ath_err(common
, "Unable to add station entry for monitor mode\n");
424 priv
->sta_slot
|= (1 << sta_idx
);
426 priv
->vif_sta_pos
[priv
->mon_vif_idx
] = sta_idx
;
427 priv
->ah
->is_monitoring
= true;
429 ath_dbg(common
, CONFIG
,
430 "Attached a monitor interface at idx: %d, sta idx: %d\n",
431 priv
->mon_vif_idx
, sta_idx
);
437 * Remove the interface from the target.
439 __ath9k_htc_remove_monitor_interface(priv
);
441 ath_dbg(common
, FATAL
, "Unable to attach a monitor interface\n");
446 static int ath9k_htc_remove_monitor_interface(struct ath9k_htc_priv
*priv
)
448 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
452 __ath9k_htc_remove_monitor_interface(priv
);
454 sta_idx
= priv
->vif_sta_pos
[priv
->mon_vif_idx
];
456 WMI_CMD_BUF(WMI_NODE_REMOVE_CMDID
, &sta_idx
);
458 ath_err(common
, "Unable to remove station entry for monitor mode\n");
462 priv
->sta_slot
&= ~(1 << sta_idx
);
464 priv
->ah
->is_monitoring
= false;
466 ath_dbg(common
, CONFIG
,
467 "Removed a monitor interface at idx: %d, sta idx: %d\n",
468 priv
->mon_vif_idx
, sta_idx
);
473 static int ath9k_htc_add_station(struct ath9k_htc_priv
*priv
,
474 struct ieee80211_vif
*vif
,
475 struct ieee80211_sta
*sta
)
477 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
478 struct ath9k_htc_target_sta tsta
;
479 struct ath9k_htc_vif
*avp
= (struct ath9k_htc_vif
*) vif
->drv_priv
;
480 struct ath9k_htc_sta
*ista
;
485 if (priv
->nstations
>= ATH9K_HTC_MAX_STA
)
488 sta_idx
= ffz(priv
->sta_slot
);
489 if ((sta_idx
< 0) || (sta_idx
> ATH9K_HTC_MAX_STA
))
492 memset(&tsta
, 0, sizeof(struct ath9k_htc_target_sta
));
495 ista
= (struct ath9k_htc_sta
*) sta
->drv_priv
;
496 memcpy(&tsta
.macaddr
, sta
->addr
, ETH_ALEN
);
497 memcpy(&tsta
.bssid
, common
->curbssid
, ETH_ALEN
);
498 ista
->index
= sta_idx
;
500 maxampdu
= 1 << (IEEE80211_HT_MAX_AMPDU_FACTOR
+
501 sta
->ht_cap
.ampdu_factor
);
502 tsta
.maxampdu
= cpu_to_be16(maxampdu
);
504 memcpy(&tsta
.macaddr
, vif
->addr
, ETH_ALEN
);
506 tsta
.maxampdu
= cpu_to_be16(0xffff);
509 tsta
.sta_index
= sta_idx
;
510 tsta
.vif_index
= avp
->index
;
512 WMI_CMD_BUF(WMI_NODE_CREATE_CMDID
, &tsta
);
516 "Unable to add station entry for: %pM\n",
522 ath_dbg(common
, CONFIG
,
523 "Added a station entry for: %pM (idx: %d)\n",
524 sta
->addr
, tsta
.sta_index
);
526 ath_dbg(common
, CONFIG
,
527 "Added a station entry for VIF %d (idx: %d)\n",
528 avp
->index
, tsta
.sta_index
);
531 priv
->sta_slot
|= (1 << sta_idx
);
534 priv
->vif_sta_pos
[avp
->index
] = sta_idx
;
539 static int ath9k_htc_remove_station(struct ath9k_htc_priv
*priv
,
540 struct ieee80211_vif
*vif
,
541 struct ieee80211_sta
*sta
)
543 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
544 struct ath9k_htc_vif
*avp
= (struct ath9k_htc_vif
*) vif
->drv_priv
;
545 struct ath9k_htc_sta
*ista
;
550 ista
= (struct ath9k_htc_sta
*) sta
->drv_priv
;
551 sta_idx
= ista
->index
;
553 sta_idx
= priv
->vif_sta_pos
[avp
->index
];
556 WMI_CMD_BUF(WMI_NODE_REMOVE_CMDID
, &sta_idx
);
560 "Unable to remove station entry for: %pM\n",
566 ath_dbg(common
, CONFIG
,
567 "Removed a station entry for: %pM (idx: %d)\n",
570 ath_dbg(common
, CONFIG
,
571 "Removed a station entry for VIF %d (idx: %d)\n",
572 avp
->index
, sta_idx
);
575 priv
->sta_slot
&= ~(1 << sta_idx
);
581 int ath9k_htc_update_cap_target(struct ath9k_htc_priv
*priv
,
584 struct ath9k_htc_cap_target tcap
;
588 memset(&tcap
, 0, sizeof(struct ath9k_htc_cap_target
));
590 tcap
.ampdu_limit
= cpu_to_be32(0xffff);
591 tcap
.ampdu_subframes
= 0xff;
592 tcap
.enable_coex
= enable_coex
;
593 tcap
.tx_chainmask
= priv
->ah
->caps
.tx_chainmask
;
595 WMI_CMD_BUF(WMI_TARGET_IC_UPDATE_CMDID
, &tcap
);
600 static void ath9k_htc_setup_rate(struct ath9k_htc_priv
*priv
,
601 struct ieee80211_sta
*sta
,
602 struct ath9k_htc_target_rate
*trate
)
604 struct ath9k_htc_sta
*ista
= (struct ath9k_htc_sta
*) sta
->drv_priv
;
605 struct ieee80211_supported_band
*sband
;
609 sband
= priv
->hw
->wiphy
->bands
[priv
->hw
->conf
.chandef
.chan
->band
];
611 for (i
= 0, j
= 0; i
< sband
->n_bitrates
; i
++) {
612 if (sta
->supp_rates
[sband
->band
] & BIT(i
)) {
613 trate
->rates
.legacy_rates
.rs_rates
[j
]
614 = (sband
->bitrates
[i
].bitrate
* 2) / 10;
618 trate
->rates
.legacy_rates
.rs_nrates
= j
;
620 if (sta
->ht_cap
.ht_supported
) {
621 for (i
= 0, j
= 0; i
< 77; i
++) {
622 if (sta
->ht_cap
.mcs
.rx_mask
[i
/8] & (1<<(i
%8)))
623 trate
->rates
.ht_rates
.rs_rates
[j
++] = i
;
624 if (j
== ATH_HTC_RATE_MAX
)
627 trate
->rates
.ht_rates
.rs_nrates
= j
;
629 caps
= WLAN_RC_HT_FLAG
;
630 if (sta
->ht_cap
.cap
& IEEE80211_HT_CAP_RX_STBC
)
631 caps
|= ATH_RC_TX_STBC_FLAG
;
632 if (sta
->ht_cap
.mcs
.rx_mask
[1])
633 caps
|= WLAN_RC_DS_FLAG
;
634 if ((sta
->ht_cap
.cap
& IEEE80211_HT_CAP_SUP_WIDTH_20_40
) &&
635 (conf_is_ht40(&priv
->hw
->conf
)))
636 caps
|= WLAN_RC_40_FLAG
;
637 if (conf_is_ht40(&priv
->hw
->conf
) &&
638 (sta
->ht_cap
.cap
& IEEE80211_HT_CAP_SGI_40
))
639 caps
|= WLAN_RC_SGI_FLAG
;
640 else if (conf_is_ht20(&priv
->hw
->conf
) &&
641 (sta
->ht_cap
.cap
& IEEE80211_HT_CAP_SGI_20
))
642 caps
|= WLAN_RC_SGI_FLAG
;
645 trate
->sta_index
= ista
->index
;
647 trate
->capflags
= cpu_to_be32(caps
);
650 static int ath9k_htc_send_rate_cmd(struct ath9k_htc_priv
*priv
,
651 struct ath9k_htc_target_rate
*trate
)
653 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
657 WMI_CMD_BUF(WMI_RC_RATE_UPDATE_CMDID
, trate
);
660 "Unable to initialize Rate information on target\n");
666 static void ath9k_htc_init_rate(struct ath9k_htc_priv
*priv
,
667 struct ieee80211_sta
*sta
)
669 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
670 struct ath9k_htc_target_rate trate
;
673 memset(&trate
, 0, sizeof(struct ath9k_htc_target_rate
));
674 ath9k_htc_setup_rate(priv
, sta
, &trate
);
675 ret
= ath9k_htc_send_rate_cmd(priv
, &trate
);
677 ath_dbg(common
, CONFIG
,
678 "Updated target sta: %pM, rate caps: 0x%X\n",
679 sta
->addr
, be32_to_cpu(trate
.capflags
));
682 static void ath9k_htc_update_rate(struct ath9k_htc_priv
*priv
,
683 struct ieee80211_vif
*vif
,
684 struct ieee80211_bss_conf
*bss_conf
)
686 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
687 struct ath9k_htc_target_rate trate
;
688 struct ieee80211_sta
*sta
;
691 memset(&trate
, 0, sizeof(struct ath9k_htc_target_rate
));
694 sta
= ieee80211_find_sta(vif
, bss_conf
->bssid
);
699 ath9k_htc_setup_rate(priv
, sta
, &trate
);
702 ret
= ath9k_htc_send_rate_cmd(priv
, &trate
);
704 ath_dbg(common
, CONFIG
,
705 "Updated target sta: %pM, rate caps: 0x%X\n",
706 bss_conf
->bssid
, be32_to_cpu(trate
.capflags
));
709 static int ath9k_htc_tx_aggr_oper(struct ath9k_htc_priv
*priv
,
710 struct ieee80211_vif
*vif
,
711 struct ieee80211_sta
*sta
,
712 enum ieee80211_ampdu_mlme_action action
,
715 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
716 struct ath9k_htc_target_aggr aggr
;
717 struct ath9k_htc_sta
*ista
;
721 if (tid
>= ATH9K_HTC_MAX_TID
)
724 memset(&aggr
, 0, sizeof(struct ath9k_htc_target_aggr
));
725 ista
= (struct ath9k_htc_sta
*) sta
->drv_priv
;
727 aggr
.sta_index
= ista
->index
;
728 aggr
.tidno
= tid
& 0xf;
729 aggr
.aggr_enable
= (action
== IEEE80211_AMPDU_TX_START
) ? true : false;
731 WMI_CMD_BUF(WMI_TX_AGGR_ENABLE_CMDID
, &aggr
);
733 ath_dbg(common
, CONFIG
,
734 "Unable to %s TX aggregation for (%pM, %d)\n",
735 (aggr
.aggr_enable
) ? "start" : "stop", sta
->addr
, tid
);
737 ath_dbg(common
, CONFIG
,
738 "%s TX aggregation for (%pM, %d)\n",
739 (aggr
.aggr_enable
) ? "Starting" : "Stopping",
742 spin_lock_bh(&priv
->tx
.tx_lock
);
743 ista
->tid_state
[tid
] = (aggr
.aggr_enable
&& !ret
) ? AGGR_START
: AGGR_STOP
;
744 spin_unlock_bh(&priv
->tx
.tx_lock
);
753 void ath9k_htc_start_ani(struct ath9k_htc_priv
*priv
)
755 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
756 unsigned long timestamp
= jiffies_to_msecs(jiffies
);
758 common
->ani
.longcal_timer
= timestamp
;
759 common
->ani
.shortcal_timer
= timestamp
;
760 common
->ani
.checkani_timer
= timestamp
;
762 set_bit(OP_ANI_RUNNING
, &priv
->op_flags
);
764 ieee80211_queue_delayed_work(common
->hw
, &priv
->ani_work
,
765 msecs_to_jiffies(ATH_ANI_POLLINTERVAL
));
768 void ath9k_htc_stop_ani(struct ath9k_htc_priv
*priv
)
770 cancel_delayed_work_sync(&priv
->ani_work
);
771 clear_bit(OP_ANI_RUNNING
, &priv
->op_flags
);
774 void ath9k_htc_ani_work(struct work_struct
*work
)
776 struct ath9k_htc_priv
*priv
=
777 container_of(work
, struct ath9k_htc_priv
, ani_work
.work
);
778 struct ath_hw
*ah
= priv
->ah
;
779 struct ath_common
*common
= ath9k_hw_common(ah
);
780 bool longcal
= false;
781 bool shortcal
= false;
782 bool aniflag
= false;
783 unsigned int timestamp
= jiffies_to_msecs(jiffies
);
784 u32 cal_interval
, short_cal_interval
;
786 short_cal_interval
= (ah
->opmode
== NL80211_IFTYPE_AP
) ?
787 ATH_AP_SHORT_CALINTERVAL
: ATH_STA_SHORT_CALINTERVAL
;
789 /* Only calibrate if awake */
790 if (ah
->power_mode
!= ATH9K_PM_AWAKE
)
793 /* Long calibration runs independently of short calibration. */
794 if ((timestamp
- common
->ani
.longcal_timer
) >= ATH_LONG_CALINTERVAL
) {
796 ath_dbg(common
, ANI
, "longcal @%lu\n", jiffies
);
797 common
->ani
.longcal_timer
= timestamp
;
800 /* Short calibration applies only while caldone is false */
801 if (!common
->ani
.caldone
) {
802 if ((timestamp
- common
->ani
.shortcal_timer
) >=
803 short_cal_interval
) {
805 ath_dbg(common
, ANI
, "shortcal @%lu\n", jiffies
);
806 common
->ani
.shortcal_timer
= timestamp
;
807 common
->ani
.resetcal_timer
= timestamp
;
810 if ((timestamp
- common
->ani
.resetcal_timer
) >=
811 ATH_RESTART_CALINTERVAL
) {
812 common
->ani
.caldone
= ath9k_hw_reset_calvalid(ah
);
813 if (common
->ani
.caldone
)
814 common
->ani
.resetcal_timer
= timestamp
;
818 /* Verify whether we must check ANI */
819 if ((timestamp
- common
->ani
.checkani_timer
) >= ATH_ANI_POLLINTERVAL
) {
821 common
->ani
.checkani_timer
= timestamp
;
824 /* Skip all processing if there's nothing to do. */
825 if (longcal
|| shortcal
|| aniflag
) {
827 ath9k_htc_ps_wakeup(priv
);
829 /* Call ANI routine if necessary */
831 ath9k_hw_ani_monitor(ah
, ah
->curchan
);
833 /* Perform calibration if necessary */
834 if (longcal
|| shortcal
)
835 common
->ani
.caldone
=
836 ath9k_hw_calibrate(ah
, ah
->curchan
,
837 ah
->rxchainmask
, longcal
);
839 ath9k_htc_ps_restore(priv
);
844 * Set timer interval based on previous results.
845 * The interval must be the shortest necessary to satisfy ANI,
846 * short calibration and long calibration.
848 cal_interval
= ATH_LONG_CALINTERVAL
;
849 cal_interval
= min(cal_interval
, (u32
)ATH_ANI_POLLINTERVAL
);
850 if (!common
->ani
.caldone
)
851 cal_interval
= min(cal_interval
, (u32
)short_cal_interval
);
853 ieee80211_queue_delayed_work(common
->hw
, &priv
->ani_work
,
854 msecs_to_jiffies(cal_interval
));
857 /**********************/
858 /* mac80211 Callbacks */
859 /**********************/
861 static void ath9k_htc_tx(struct ieee80211_hw
*hw
,
862 struct ieee80211_tx_control
*control
,
865 struct ieee80211_hdr
*hdr
;
866 struct ath9k_htc_priv
*priv
= hw
->priv
;
867 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
868 int padpos
, padsize
, ret
, slot
;
870 hdr
= (struct ieee80211_hdr
*) skb
->data
;
872 /* Add the padding after the header if this is not already done */
873 padpos
= ieee80211_hdrlen(hdr
->frame_control
);
874 padsize
= padpos
& 3;
875 if (padsize
&& skb
->len
> padpos
) {
876 if (skb_headroom(skb
) < padsize
) {
877 ath_dbg(common
, XMIT
, "No room for padding\n");
880 skb_push(skb
, padsize
);
881 memmove(skb
->data
, skb
->data
+ padsize
, padpos
);
884 slot
= ath9k_htc_tx_get_slot(priv
);
886 ath_dbg(common
, XMIT
, "No free TX slot\n");
890 ret
= ath9k_htc_tx_start(priv
, control
->sta
, skb
, slot
, false);
892 ath_dbg(common
, XMIT
, "Tx failed\n");
896 ath9k_htc_check_stop_queues(priv
);
901 ath9k_htc_tx_clear_slot(priv
, slot
);
903 dev_kfree_skb_any(skb
);
906 static int ath9k_htc_start(struct ieee80211_hw
*hw
)
908 struct ath9k_htc_priv
*priv
= hw
->priv
;
909 struct ath_hw
*ah
= priv
->ah
;
910 struct ath_common
*common
= ath9k_hw_common(ah
);
911 struct ieee80211_channel
*curchan
= hw
->conf
.chandef
.chan
;
912 struct ath9k_channel
*init_channel
;
914 enum htc_phymode mode
;
918 mutex_lock(&priv
->mutex
);
920 ath_dbg(common
, CONFIG
,
921 "Starting driver with initial channel: %d MHz\n",
922 curchan
->center_freq
);
924 /* Ensure that HW is awake before flushing RX */
925 ath9k_htc_setpower(priv
, ATH9K_PM_AWAKE
);
926 WMI_CMD(WMI_FLUSH_RECV_CMDID
);
928 /* setup initial channel */
929 init_channel
= ath9k_cmn_get_curchannel(hw
, ah
);
931 ret
= ath9k_hw_reset(ah
, init_channel
, ah
->caldata
, false);
934 "Unable to reset hardware; reset status %d (freq %u MHz)\n",
935 ret
, curchan
->center_freq
);
936 mutex_unlock(&priv
->mutex
);
940 ath9k_cmn_update_txpow(ah
, priv
->curtxpow
, priv
->txpowlimit
,
943 mode
= ath9k_htc_get_curmode(priv
, init_channel
);
944 htc_mode
= cpu_to_be16(mode
);
945 WMI_CMD_BUF(WMI_SET_MODE_CMDID
, &htc_mode
);
946 WMI_CMD(WMI_ATH_INIT_CMDID
);
947 WMI_CMD(WMI_START_RECV_CMDID
);
949 ath9k_host_rx_init(priv
);
951 ret
= ath9k_htc_update_cap_target(priv
, 0);
953 ath_dbg(common
, CONFIG
,
954 "Failed to update capability in target\n");
956 clear_bit(OP_INVALID
, &priv
->op_flags
);
957 htc_start(priv
->htc
);
959 spin_lock_bh(&priv
->tx
.tx_lock
);
960 priv
->tx
.flags
&= ~ATH9K_HTC_OP_TX_QUEUES_STOP
;
961 spin_unlock_bh(&priv
->tx
.tx_lock
);
963 ieee80211_wake_queues(hw
);
965 mod_timer(&priv
->tx
.cleanup_timer
,
966 jiffies
+ msecs_to_jiffies(ATH9K_HTC_TX_CLEANUP_INTERVAL
));
968 ath9k_htc_start_btcoex(priv
);
970 mutex_unlock(&priv
->mutex
);
975 static void ath9k_htc_stop(struct ieee80211_hw
*hw
)
977 struct ath9k_htc_priv
*priv
= hw
->priv
;
978 struct ath_hw
*ah
= priv
->ah
;
979 struct ath_common
*common
= ath9k_hw_common(ah
);
980 int ret
__attribute__ ((unused
));
983 mutex_lock(&priv
->mutex
);
985 if (test_bit(OP_INVALID
, &priv
->op_flags
)) {
986 ath_dbg(common
, ANY
, "Device not present\n");
987 mutex_unlock(&priv
->mutex
);
991 ath9k_htc_ps_wakeup(priv
);
993 WMI_CMD(WMI_DISABLE_INTR_CMDID
);
994 WMI_CMD(WMI_DRAIN_TXQ_ALL_CMDID
);
995 WMI_CMD(WMI_STOP_RECV_CMDID
);
997 tasklet_kill(&priv
->rx_tasklet
);
999 del_timer_sync(&priv
->tx
.cleanup_timer
);
1000 ath9k_htc_tx_drain(priv
);
1001 ath9k_wmi_event_drain(priv
);
1003 mutex_unlock(&priv
->mutex
);
1005 /* Cancel all the running timers/work .. */
1006 cancel_work_sync(&priv
->fatal_work
);
1007 cancel_work_sync(&priv
->ps_work
);
1009 #ifdef CONFIG_MAC80211_LEDS
1010 cancel_work_sync(&priv
->led_work
);
1012 ath9k_htc_stop_ani(priv
);
1014 mutex_lock(&priv
->mutex
);
1016 ath9k_htc_stop_btcoex(priv
);
1018 /* Remove a monitor interface if it's present. */
1019 if (priv
->ah
->is_monitoring
)
1020 ath9k_htc_remove_monitor_interface(priv
);
1022 ath9k_hw_phy_disable(ah
);
1023 ath9k_hw_disable(ah
);
1024 ath9k_htc_ps_restore(priv
);
1025 ath9k_htc_setpower(priv
, ATH9K_PM_FULL_SLEEP
);
1027 set_bit(OP_INVALID
, &priv
->op_flags
);
1029 ath_dbg(common
, CONFIG
, "Driver halt\n");
1030 mutex_unlock(&priv
->mutex
);
1033 static int ath9k_htc_add_interface(struct ieee80211_hw
*hw
,
1034 struct ieee80211_vif
*vif
)
1036 struct ath9k_htc_priv
*priv
= hw
->priv
;
1037 struct ath9k_htc_vif
*avp
= (void *)vif
->drv_priv
;
1038 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
1039 struct ath9k_htc_target_vif hvif
;
1043 mutex_lock(&priv
->mutex
);
1045 ath9k_htc_ps_wakeup(priv
);
1046 memset(&hvif
, 0, sizeof(struct ath9k_htc_target_vif
));
1047 memcpy(&hvif
.myaddr
, vif
->addr
, ETH_ALEN
);
1049 switch (vif
->type
) {
1050 case NL80211_IFTYPE_STATION
:
1051 hvif
.opmode
= HTC_M_STA
;
1053 case NL80211_IFTYPE_ADHOC
:
1054 hvif
.opmode
= HTC_M_IBSS
;
1056 case NL80211_IFTYPE_AP
:
1057 hvif
.opmode
= HTC_M_HOSTAP
;
1059 case NL80211_IFTYPE_MESH_POINT
:
1060 hvif
.opmode
= HTC_M_WDS
; /* close enough */
1064 "Interface type %d not yet supported\n", vif
->type
);
1069 /* Index starts from zero on the target */
1070 avp
->index
= hvif
.index
= ffz(priv
->vif_slot
);
1071 hvif
.rtsthreshold
= cpu_to_be16(2304);
1072 WMI_CMD_BUF(WMI_VAP_CREATE_CMDID
, &hvif
);
1077 * We need a node in target to tx mgmt frames
1078 * before association.
1080 ret
= ath9k_htc_add_station(priv
, vif
, NULL
);
1082 WMI_CMD_BUF(WMI_VAP_REMOVE_CMDID
, &hvif
);
1086 ath9k_htc_set_bssid_mask(priv
, vif
);
1088 priv
->vif_slot
|= (1 << avp
->index
);
1091 INC_VIF(priv
, vif
->type
);
1093 if ((vif
->type
== NL80211_IFTYPE_AP
) ||
1094 (vif
->type
== NL80211_IFTYPE_MESH_POINT
) ||
1095 (vif
->type
== NL80211_IFTYPE_ADHOC
))
1096 ath9k_htc_assign_bslot(priv
, vif
);
1098 ath9k_htc_set_opmode(priv
);
1100 if ((priv
->ah
->opmode
== NL80211_IFTYPE_AP
) &&
1101 !test_bit(OP_ANI_RUNNING
, &priv
->op_flags
)) {
1102 ath9k_hw_set_tsfadjust(priv
->ah
, true);
1103 ath9k_htc_start_ani(priv
);
1106 ath_dbg(common
, CONFIG
, "Attach a VIF of type: %d at idx: %d\n",
1107 vif
->type
, avp
->index
);
1110 ath9k_htc_ps_restore(priv
);
1111 mutex_unlock(&priv
->mutex
);
1116 static void ath9k_htc_remove_interface(struct ieee80211_hw
*hw
,
1117 struct ieee80211_vif
*vif
)
1119 struct ath9k_htc_priv
*priv
= hw
->priv
;
1120 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
1121 struct ath9k_htc_vif
*avp
= (void *)vif
->drv_priv
;
1122 struct ath9k_htc_target_vif hvif
;
1126 mutex_lock(&priv
->mutex
);
1127 ath9k_htc_ps_wakeup(priv
);
1129 memset(&hvif
, 0, sizeof(struct ath9k_htc_target_vif
));
1130 memcpy(&hvif
.myaddr
, vif
->addr
, ETH_ALEN
);
1131 hvif
.index
= avp
->index
;
1132 WMI_CMD_BUF(WMI_VAP_REMOVE_CMDID
, &hvif
);
1134 ath_err(common
, "Unable to remove interface at idx: %d\n",
1138 priv
->vif_slot
&= ~(1 << avp
->index
);
1140 ath9k_htc_remove_station(priv
, vif
, NULL
);
1142 DEC_VIF(priv
, vif
->type
);
1144 if ((vif
->type
== NL80211_IFTYPE_AP
) ||
1145 vif
->type
== NL80211_IFTYPE_MESH_POINT
||
1146 (vif
->type
== NL80211_IFTYPE_ADHOC
))
1147 ath9k_htc_remove_bslot(priv
, vif
);
1149 ath9k_htc_set_opmode(priv
);
1151 ath9k_htc_set_bssid_mask(priv
, vif
);
1154 * Stop ANI only if there are no associated station interfaces.
1156 if ((vif
->type
== NL80211_IFTYPE_AP
) && (priv
->num_ap_vif
== 0)) {
1157 priv
->rearm_ani
= false;
1158 ieee80211_iterate_active_interfaces_atomic(
1159 priv
->hw
, IEEE80211_IFACE_ITER_RESUME_ALL
,
1160 ath9k_htc_vif_iter
, priv
);
1161 if (!priv
->rearm_ani
)
1162 ath9k_htc_stop_ani(priv
);
1165 ath_dbg(common
, CONFIG
, "Detach Interface at idx: %d\n", avp
->index
);
1167 ath9k_htc_ps_restore(priv
);
1168 mutex_unlock(&priv
->mutex
);
1171 static int ath9k_htc_config(struct ieee80211_hw
*hw
, u32 changed
)
1173 struct ath9k_htc_priv
*priv
= hw
->priv
;
1174 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
1175 struct ieee80211_conf
*conf
= &hw
->conf
;
1176 bool chip_reset
= false;
1179 mutex_lock(&priv
->mutex
);
1180 ath9k_htc_ps_wakeup(priv
);
1182 if (changed
& IEEE80211_CONF_CHANGE_IDLE
) {
1183 mutex_lock(&priv
->htc_pm_lock
);
1185 priv
->ps_idle
= !!(conf
->flags
& IEEE80211_CONF_IDLE
);
1189 mutex_unlock(&priv
->htc_pm_lock
);
1193 * Monitor interface should be added before
1194 * IEEE80211_CONF_CHANGE_CHANNEL is handled.
1196 if (changed
& IEEE80211_CONF_CHANGE_MONITOR
) {
1197 if ((conf
->flags
& IEEE80211_CONF_MONITOR
) &&
1198 !priv
->ah
->is_monitoring
)
1199 ath9k_htc_add_monitor_interface(priv
);
1200 else if (priv
->ah
->is_monitoring
)
1201 ath9k_htc_remove_monitor_interface(priv
);
1204 if ((changed
& IEEE80211_CONF_CHANGE_CHANNEL
) || chip_reset
) {
1205 struct ieee80211_channel
*curchan
= hw
->conf
.chandef
.chan
;
1206 int pos
= curchan
->hw_value
;
1208 ath_dbg(common
, CONFIG
, "Set channel: %d MHz\n",
1209 curchan
->center_freq
);
1211 ath9k_cmn_update_ichannel(&priv
->ah
->channels
[pos
],
1214 if (ath9k_htc_set_channel(priv
, hw
, &priv
->ah
->channels
[pos
]) < 0) {
1215 ath_err(common
, "Unable to set channel\n");
1222 if (changed
& IEEE80211_CONF_CHANGE_PS
) {
1223 if (conf
->flags
& IEEE80211_CONF_PS
) {
1224 ath9k_htc_setpower(priv
, ATH9K_PM_NETWORK_SLEEP
);
1225 priv
->ps_enabled
= true;
1227 priv
->ps_enabled
= false;
1228 cancel_work_sync(&priv
->ps_work
);
1229 ath9k_htc_setpower(priv
, ATH9K_PM_AWAKE
);
1233 if (changed
& IEEE80211_CONF_CHANGE_POWER
) {
1234 priv
->txpowlimit
= 2 * conf
->power_level
;
1235 ath9k_cmn_update_txpow(priv
->ah
, priv
->curtxpow
,
1236 priv
->txpowlimit
, &priv
->curtxpow
);
1240 ath9k_htc_ps_restore(priv
);
1241 mutex_unlock(&priv
->mutex
);
1245 #define SUPPORTED_FILTERS \
1246 (FIF_PROMISC_IN_BSS | \
1251 FIF_BCN_PRBRESP_PROMISC | \
1255 static void ath9k_htc_configure_filter(struct ieee80211_hw
*hw
,
1256 unsigned int changed_flags
,
1257 unsigned int *total_flags
,
1260 struct ath9k_htc_priv
*priv
= hw
->priv
;
1263 mutex_lock(&priv
->mutex
);
1264 changed_flags
&= SUPPORTED_FILTERS
;
1265 *total_flags
&= SUPPORTED_FILTERS
;
1267 if (test_bit(OP_INVALID
, &priv
->op_flags
)) {
1268 ath_dbg(ath9k_hw_common(priv
->ah
), ANY
,
1269 "Unable to configure filter on invalid state\n");
1270 mutex_unlock(&priv
->mutex
);
1273 ath9k_htc_ps_wakeup(priv
);
1275 priv
->rxfilter
= *total_flags
;
1276 rfilt
= ath9k_htc_calcrxfilter(priv
);
1277 ath9k_hw_setrxfilter(priv
->ah
, rfilt
);
1279 ath_dbg(ath9k_hw_common(priv
->ah
), CONFIG
, "Set HW RX filter: 0x%x\n",
1282 ath9k_htc_ps_restore(priv
);
1283 mutex_unlock(&priv
->mutex
);
1286 static int ath9k_htc_sta_add(struct ieee80211_hw
*hw
,
1287 struct ieee80211_vif
*vif
,
1288 struct ieee80211_sta
*sta
)
1290 struct ath9k_htc_priv
*priv
= hw
->priv
;
1293 mutex_lock(&priv
->mutex
);
1294 ath9k_htc_ps_wakeup(priv
);
1295 ret
= ath9k_htc_add_station(priv
, vif
, sta
);
1297 ath9k_htc_init_rate(priv
, sta
);
1298 ath9k_htc_ps_restore(priv
);
1299 mutex_unlock(&priv
->mutex
);
1304 static int ath9k_htc_sta_remove(struct ieee80211_hw
*hw
,
1305 struct ieee80211_vif
*vif
,
1306 struct ieee80211_sta
*sta
)
1308 struct ath9k_htc_priv
*priv
= hw
->priv
;
1309 struct ath9k_htc_sta
*ista
;
1312 mutex_lock(&priv
->mutex
);
1313 ath9k_htc_ps_wakeup(priv
);
1314 ista
= (struct ath9k_htc_sta
*) sta
->drv_priv
;
1315 htc_sta_drain(priv
->htc
, ista
->index
);
1316 ret
= ath9k_htc_remove_station(priv
, vif
, sta
);
1317 ath9k_htc_ps_restore(priv
);
1318 mutex_unlock(&priv
->mutex
);
1323 static void ath9k_htc_sta_rc_update(struct ieee80211_hw
*hw
,
1324 struct ieee80211_vif
*vif
,
1325 struct ieee80211_sta
*sta
, u32 changed
)
1327 struct ath9k_htc_priv
*priv
= hw
->priv
;
1328 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
1329 struct ath9k_htc_target_rate trate
;
1331 mutex_lock(&priv
->mutex
);
1332 ath9k_htc_ps_wakeup(priv
);
1334 if (changed
& IEEE80211_RC_SUPP_RATES_CHANGED
) {
1335 memset(&trate
, 0, sizeof(struct ath9k_htc_target_rate
));
1336 ath9k_htc_setup_rate(priv
, sta
, &trate
);
1337 if (!ath9k_htc_send_rate_cmd(priv
, &trate
))
1338 ath_dbg(common
, CONFIG
,
1339 "Supported rates for sta: %pM updated, rate caps: 0x%X\n",
1340 sta
->addr
, be32_to_cpu(trate
.capflags
));
1342 ath_dbg(common
, CONFIG
,
1343 "Unable to update supported rates for sta: %pM\n",
1347 ath9k_htc_ps_restore(priv
);
1348 mutex_unlock(&priv
->mutex
);
1351 static int ath9k_htc_conf_tx(struct ieee80211_hw
*hw
,
1352 struct ieee80211_vif
*vif
, u16 queue
,
1353 const struct ieee80211_tx_queue_params
*params
)
1355 struct ath9k_htc_priv
*priv
= hw
->priv
;
1356 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
1357 struct ath9k_tx_queue_info qi
;
1360 if (queue
>= IEEE80211_NUM_ACS
)
1363 mutex_lock(&priv
->mutex
);
1364 ath9k_htc_ps_wakeup(priv
);
1366 memset(&qi
, 0, sizeof(struct ath9k_tx_queue_info
));
1368 qi
.tqi_aifs
= params
->aifs
;
1369 qi
.tqi_cwmin
= params
->cw_min
;
1370 qi
.tqi_cwmax
= params
->cw_max
;
1371 qi
.tqi_burstTime
= params
->txop
* 32;
1373 qnum
= get_hw_qnum(queue
, priv
->hwq_map
);
1375 ath_dbg(common
, CONFIG
,
1376 "Configure tx [queue/hwq] [%d/%d], aifs: %d, cw_min: %d, cw_max: %d, txop: %d\n",
1377 queue
, qnum
, params
->aifs
, params
->cw_min
,
1378 params
->cw_max
, params
->txop
);
1380 ret
= ath_htc_txq_update(priv
, qnum
, &qi
);
1382 ath_err(common
, "TXQ Update failed\n");
1386 if ((priv
->ah
->opmode
== NL80211_IFTYPE_ADHOC
) &&
1387 (qnum
== priv
->hwq_map
[IEEE80211_AC_BE
]))
1388 ath9k_htc_beaconq_config(priv
);
1390 ath9k_htc_ps_restore(priv
);
1391 mutex_unlock(&priv
->mutex
);
1396 static int ath9k_htc_set_key(struct ieee80211_hw
*hw
,
1397 enum set_key_cmd cmd
,
1398 struct ieee80211_vif
*vif
,
1399 struct ieee80211_sta
*sta
,
1400 struct ieee80211_key_conf
*key
)
1402 struct ath9k_htc_priv
*priv
= hw
->priv
;
1403 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
1406 if (htc_modparam_nohwcrypt
)
1409 if ((vif
->type
== NL80211_IFTYPE_ADHOC
||
1410 vif
->type
== NL80211_IFTYPE_MESH_POINT
) &&
1411 (key
->cipher
== WLAN_CIPHER_SUITE_TKIP
||
1412 key
->cipher
== WLAN_CIPHER_SUITE_CCMP
) &&
1413 !(key
->flags
& IEEE80211_KEY_FLAG_PAIRWISE
)) {
1415 * For now, disable hw crypto for the RSN IBSS group keys. This
1416 * could be optimized in the future to use a modified key cache
1417 * design to support per-STA RX GTK, but until that gets
1418 * implemented, use of software crypto for group addressed
1419 * frames is a acceptable to allow RSN IBSS to be used.
1424 mutex_lock(&priv
->mutex
);
1425 ath_dbg(common
, CONFIG
, "Set HW Key\n");
1426 ath9k_htc_ps_wakeup(priv
);
1430 ret
= ath_key_config(common
, vif
, sta
, key
);
1432 key
->hw_key_idx
= ret
;
1433 /* push IV and Michael MIC generation to stack */
1434 key
->flags
|= IEEE80211_KEY_FLAG_GENERATE_IV
;
1435 if (key
->cipher
== WLAN_CIPHER_SUITE_TKIP
)
1436 key
->flags
|= IEEE80211_KEY_FLAG_GENERATE_MMIC
;
1437 if (priv
->ah
->sw_mgmt_crypto
&&
1438 key
->cipher
== WLAN_CIPHER_SUITE_CCMP
)
1439 key
->flags
|= IEEE80211_KEY_FLAG_SW_MGMT_TX
;
1444 ath_key_delete(common
, key
);
1450 ath9k_htc_ps_restore(priv
);
1451 mutex_unlock(&priv
->mutex
);
1456 static void ath9k_htc_set_bssid(struct ath9k_htc_priv
*priv
)
1458 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
1460 ath9k_hw_write_associd(priv
->ah
);
1461 ath_dbg(common
, CONFIG
, "BSSID: %pM aid: 0x%x\n",
1462 common
->curbssid
, common
->curaid
);
1465 static void ath9k_htc_bss_iter(void *data
, u8
*mac
, struct ieee80211_vif
*vif
)
1467 struct ath9k_htc_priv
*priv
= (struct ath9k_htc_priv
*)data
;
1468 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
1469 struct ieee80211_bss_conf
*bss_conf
= &vif
->bss_conf
;
1471 if ((vif
->type
== NL80211_IFTYPE_STATION
) && bss_conf
->assoc
) {
1472 common
->curaid
= bss_conf
->aid
;
1473 memcpy(common
->curbssid
, bss_conf
->bssid
, ETH_ALEN
);
1477 static void ath9k_htc_choose_set_bssid(struct ath9k_htc_priv
*priv
)
1479 if (priv
->num_sta_assoc_vif
== 1) {
1480 ieee80211_iterate_active_interfaces_atomic(
1481 priv
->hw
, IEEE80211_IFACE_ITER_RESUME_ALL
,
1482 ath9k_htc_bss_iter
, priv
);
1483 ath9k_htc_set_bssid(priv
);
1487 static void ath9k_htc_bss_info_changed(struct ieee80211_hw
*hw
,
1488 struct ieee80211_vif
*vif
,
1489 struct ieee80211_bss_conf
*bss_conf
,
1492 struct ath9k_htc_priv
*priv
= hw
->priv
;
1493 struct ath_hw
*ah
= priv
->ah
;
1494 struct ath_common
*common
= ath9k_hw_common(ah
);
1496 mutex_lock(&priv
->mutex
);
1497 ath9k_htc_ps_wakeup(priv
);
1499 if (changed
& BSS_CHANGED_ASSOC
) {
1500 ath_dbg(common
, CONFIG
, "BSS Changed ASSOC %d\n",
1504 priv
->num_sta_assoc_vif
++ : priv
->num_sta_assoc_vif
--;
1506 if (priv
->ah
->opmode
== NL80211_IFTYPE_STATION
) {
1507 ath9k_htc_choose_set_bssid(priv
);
1508 if (bss_conf
->assoc
&& (priv
->num_sta_assoc_vif
== 1))
1509 ath9k_htc_start_ani(priv
);
1510 else if (priv
->num_sta_assoc_vif
== 0)
1511 ath9k_htc_stop_ani(priv
);
1515 if (changed
& BSS_CHANGED_IBSS
) {
1516 if (priv
->ah
->opmode
== NL80211_IFTYPE_ADHOC
) {
1517 common
->curaid
= bss_conf
->aid
;
1518 memcpy(common
->curbssid
, bss_conf
->bssid
, ETH_ALEN
);
1519 ath9k_htc_set_bssid(priv
);
1523 if ((changed
& BSS_CHANGED_BEACON_ENABLED
) && bss_conf
->enable_beacon
) {
1524 ath_dbg(common
, CONFIG
, "Beacon enabled for BSS: %pM\n",
1526 ath9k_htc_set_tsfadjust(priv
, vif
);
1527 set_bit(OP_ENABLE_BEACON
, &priv
->op_flags
);
1528 ath9k_htc_beacon_config(priv
, vif
);
1531 if ((changed
& BSS_CHANGED_BEACON_ENABLED
) && !bss_conf
->enable_beacon
) {
1533 * Disable SWBA interrupt only if there are no
1534 * concurrent AP/mesh or IBSS interfaces.
1536 if ((priv
->num_ap_vif
+ priv
->num_mbss_vif
<= 1) ||
1537 priv
->num_ibss_vif
) {
1538 ath_dbg(common
, CONFIG
,
1539 "Beacon disabled for BSS: %pM\n",
1541 clear_bit(OP_ENABLE_BEACON
, &priv
->op_flags
);
1542 ath9k_htc_beacon_config(priv
, vif
);
1546 if (changed
& BSS_CHANGED_BEACON_INT
) {
1548 * Reset the HW TSF for the first AP or mesh interface.
1550 if (priv
->nvifs
== 1 &&
1551 ((priv
->ah
->opmode
== NL80211_IFTYPE_AP
&&
1552 vif
->type
== NL80211_IFTYPE_AP
&&
1553 priv
->num_ap_vif
== 1) ||
1554 (priv
->ah
->opmode
== NL80211_IFTYPE_MESH_POINT
&&
1555 vif
->type
== NL80211_IFTYPE_MESH_POINT
&&
1556 priv
->num_mbss_vif
== 1))) {
1557 set_bit(OP_TSF_RESET
, &priv
->op_flags
);
1559 ath_dbg(common
, CONFIG
,
1560 "Beacon interval changed for BSS: %pM\n",
1562 ath9k_htc_beacon_config(priv
, vif
);
1565 if (changed
& BSS_CHANGED_ERP_SLOT
) {
1566 if (bss_conf
->use_short_slot
)
1571 ath9k_hw_init_global_settings(ah
);
1574 if (changed
& BSS_CHANGED_HT
)
1575 ath9k_htc_update_rate(priv
, vif
, bss_conf
);
1577 ath9k_htc_ps_restore(priv
);
1578 mutex_unlock(&priv
->mutex
);
1581 static u64
ath9k_htc_get_tsf(struct ieee80211_hw
*hw
,
1582 struct ieee80211_vif
*vif
)
1584 struct ath9k_htc_priv
*priv
= hw
->priv
;
1587 mutex_lock(&priv
->mutex
);
1588 ath9k_htc_ps_wakeup(priv
);
1589 tsf
= ath9k_hw_gettsf64(priv
->ah
);
1590 ath9k_htc_ps_restore(priv
);
1591 mutex_unlock(&priv
->mutex
);
1596 static void ath9k_htc_set_tsf(struct ieee80211_hw
*hw
,
1597 struct ieee80211_vif
*vif
, u64 tsf
)
1599 struct ath9k_htc_priv
*priv
= hw
->priv
;
1601 mutex_lock(&priv
->mutex
);
1602 ath9k_htc_ps_wakeup(priv
);
1603 ath9k_hw_settsf64(priv
->ah
, tsf
);
1604 ath9k_htc_ps_restore(priv
);
1605 mutex_unlock(&priv
->mutex
);
1608 static void ath9k_htc_reset_tsf(struct ieee80211_hw
*hw
,
1609 struct ieee80211_vif
*vif
)
1611 struct ath9k_htc_priv
*priv
= hw
->priv
;
1613 mutex_lock(&priv
->mutex
);
1614 ath9k_htc_ps_wakeup(priv
);
1615 ath9k_hw_reset_tsf(priv
->ah
);
1616 ath9k_htc_ps_restore(priv
);
1617 mutex_unlock(&priv
->mutex
);
1620 static int ath9k_htc_ampdu_action(struct ieee80211_hw
*hw
,
1621 struct ieee80211_vif
*vif
,
1622 enum ieee80211_ampdu_mlme_action action
,
1623 struct ieee80211_sta
*sta
,
1624 u16 tid
, u16
*ssn
, u8 buf_size
)
1626 struct ath9k_htc_priv
*priv
= hw
->priv
;
1627 struct ath9k_htc_sta
*ista
;
1630 mutex_lock(&priv
->mutex
);
1631 ath9k_htc_ps_wakeup(priv
);
1634 case IEEE80211_AMPDU_RX_START
:
1636 case IEEE80211_AMPDU_RX_STOP
:
1638 case IEEE80211_AMPDU_TX_START
:
1639 ret
= ath9k_htc_tx_aggr_oper(priv
, vif
, sta
, action
, tid
);
1641 ieee80211_start_tx_ba_cb_irqsafe(vif
, sta
->addr
, tid
);
1643 case IEEE80211_AMPDU_TX_STOP_CONT
:
1644 case IEEE80211_AMPDU_TX_STOP_FLUSH
:
1645 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT
:
1646 ath9k_htc_tx_aggr_oper(priv
, vif
, sta
, action
, tid
);
1647 ieee80211_stop_tx_ba_cb_irqsafe(vif
, sta
->addr
, tid
);
1649 case IEEE80211_AMPDU_TX_OPERATIONAL
:
1650 ista
= (struct ath9k_htc_sta
*) sta
->drv_priv
;
1651 spin_lock_bh(&priv
->tx
.tx_lock
);
1652 ista
->tid_state
[tid
] = AGGR_OPERATIONAL
;
1653 spin_unlock_bh(&priv
->tx
.tx_lock
);
1656 ath_err(ath9k_hw_common(priv
->ah
), "Unknown AMPDU action\n");
1659 ath9k_htc_ps_restore(priv
);
1660 mutex_unlock(&priv
->mutex
);
1665 static void ath9k_htc_sw_scan_start(struct ieee80211_hw
*hw
)
1667 struct ath9k_htc_priv
*priv
= hw
->priv
;
1669 mutex_lock(&priv
->mutex
);
1670 spin_lock_bh(&priv
->beacon_lock
);
1671 set_bit(OP_SCANNING
, &priv
->op_flags
);
1672 spin_unlock_bh(&priv
->beacon_lock
);
1673 cancel_work_sync(&priv
->ps_work
);
1674 ath9k_htc_stop_ani(priv
);
1675 mutex_unlock(&priv
->mutex
);
1678 static void ath9k_htc_sw_scan_complete(struct ieee80211_hw
*hw
)
1680 struct ath9k_htc_priv
*priv
= hw
->priv
;
1682 mutex_lock(&priv
->mutex
);
1683 spin_lock_bh(&priv
->beacon_lock
);
1684 clear_bit(OP_SCANNING
, &priv
->op_flags
);
1685 spin_unlock_bh(&priv
->beacon_lock
);
1686 ath9k_htc_ps_wakeup(priv
);
1687 ath9k_htc_vif_reconfig(priv
);
1688 ath9k_htc_ps_restore(priv
);
1689 mutex_unlock(&priv
->mutex
);
1692 static int ath9k_htc_set_rts_threshold(struct ieee80211_hw
*hw
, u32 value
)
1697 static void ath9k_htc_set_coverage_class(struct ieee80211_hw
*hw
,
1700 struct ath9k_htc_priv
*priv
= hw
->priv
;
1702 mutex_lock(&priv
->mutex
);
1703 ath9k_htc_ps_wakeup(priv
);
1704 priv
->ah
->coverage_class
= coverage_class
;
1705 ath9k_hw_init_global_settings(priv
->ah
);
1706 ath9k_htc_ps_restore(priv
);
1707 mutex_unlock(&priv
->mutex
);
1711 * Currently, this is used only for selecting the minimum rate
1712 * for management frames, rate selection for data frames remain
1715 static int ath9k_htc_set_bitrate_mask(struct ieee80211_hw
*hw
,
1716 struct ieee80211_vif
*vif
,
1717 const struct cfg80211_bitrate_mask
*mask
)
1719 struct ath9k_htc_priv
*priv
= hw
->priv
;
1720 struct ath_common
*common
= ath9k_hw_common(priv
->ah
);
1721 struct ath9k_htc_target_rate_mask tmask
;
1722 struct ath9k_htc_vif
*avp
= (void *)vif
->drv_priv
;
1726 memset(&tmask
, 0, sizeof(struct ath9k_htc_target_rate_mask
));
1728 tmask
.vif_index
= avp
->index
;
1729 tmask
.band
= IEEE80211_BAND_2GHZ
;
1730 tmask
.mask
= cpu_to_be32(mask
->control
[IEEE80211_BAND_2GHZ
].legacy
);
1732 WMI_CMD_BUF(WMI_BITRATE_MASK_CMDID
, &tmask
);
1735 "Unable to set 2G rate mask for "
1736 "interface at idx: %d\n", avp
->index
);
1740 tmask
.band
= IEEE80211_BAND_5GHZ
;
1741 tmask
.mask
= cpu_to_be32(mask
->control
[IEEE80211_BAND_5GHZ
].legacy
);
1743 WMI_CMD_BUF(WMI_BITRATE_MASK_CMDID
, &tmask
);
1746 "Unable to set 5G rate mask for "
1747 "interface at idx: %d\n", avp
->index
);
1751 ath_dbg(common
, CONFIG
, "Set bitrate masks: 0x%x, 0x%x\n",
1752 mask
->control
[IEEE80211_BAND_2GHZ
].legacy
,
1753 mask
->control
[IEEE80211_BAND_5GHZ
].legacy
);
1759 static int ath9k_htc_get_stats(struct ieee80211_hw
*hw
,
1760 struct ieee80211_low_level_stats
*stats
)
1762 struct ath9k_htc_priv
*priv
= hw
->priv
;
1763 struct ath_hw
*ah
= priv
->ah
;
1764 struct ath9k_mib_stats
*mib_stats
= &ah
->ah_mibStats
;
1766 stats
->dot11ACKFailureCount
= mib_stats
->ackrcv_bad
;
1767 stats
->dot11RTSFailureCount
= mib_stats
->rts_bad
;
1768 stats
->dot11FCSErrorCount
= mib_stats
->fcs_bad
;
1769 stats
->dot11RTSSuccessCount
= mib_stats
->rts_good
;
1774 struct base_eep_header
*ath9k_htc_get_eeprom_base(struct ath9k_htc_priv
*priv
)
1776 struct base_eep_header
*pBase
= NULL
;
1778 * This can be done since all the 3 EEPROM families have the
1779 * same base header upto a certain point, and we are interested in
1780 * the data only upto that point.
1783 if (AR_SREV_9271(priv
->ah
))
1784 pBase
= (struct base_eep_header
*)
1785 &priv
->ah
->eeprom
.map4k
.baseEepHeader
;
1786 else if (priv
->ah
->hw_version
.usbdev
== AR9280_USB
)
1787 pBase
= (struct base_eep_header
*)
1788 &priv
->ah
->eeprom
.def
.baseEepHeader
;
1789 else if (priv
->ah
->hw_version
.usbdev
== AR9287_USB
)
1790 pBase
= (struct base_eep_header
*)
1791 &priv
->ah
->eeprom
.map9287
.baseEepHeader
;
1796 static int ath9k_htc_get_antenna(struct ieee80211_hw
*hw
, u32
*tx_ant
,
1799 struct ath9k_htc_priv
*priv
= hw
->priv
;
1800 struct base_eep_header
*pBase
= ath9k_htc_get_eeprom_base(priv
);
1802 *tx_ant
= pBase
->txMask
;
1803 *rx_ant
= pBase
->rxMask
;
1811 struct ieee80211_ops ath9k_htc_ops
= {
1813 .start
= ath9k_htc_start
,
1814 .stop
= ath9k_htc_stop
,
1815 .add_interface
= ath9k_htc_add_interface
,
1816 .remove_interface
= ath9k_htc_remove_interface
,
1817 .config
= ath9k_htc_config
,
1818 .configure_filter
= ath9k_htc_configure_filter
,
1819 .sta_add
= ath9k_htc_sta_add
,
1820 .sta_remove
= ath9k_htc_sta_remove
,
1821 .conf_tx
= ath9k_htc_conf_tx
,
1822 .sta_rc_update
= ath9k_htc_sta_rc_update
,
1823 .bss_info_changed
= ath9k_htc_bss_info_changed
,
1824 .set_key
= ath9k_htc_set_key
,
1825 .get_tsf
= ath9k_htc_get_tsf
,
1826 .set_tsf
= ath9k_htc_set_tsf
,
1827 .reset_tsf
= ath9k_htc_reset_tsf
,
1828 .ampdu_action
= ath9k_htc_ampdu_action
,
1829 .sw_scan_start
= ath9k_htc_sw_scan_start
,
1830 .sw_scan_complete
= ath9k_htc_sw_scan_complete
,
1831 .set_rts_threshold
= ath9k_htc_set_rts_threshold
,
1832 .rfkill_poll
= ath9k_htc_rfkill_poll_state
,
1833 .set_coverage_class
= ath9k_htc_set_coverage_class
,
1834 .set_bitrate_mask
= ath9k_htc_set_bitrate_mask
,
1835 .get_stats
= ath9k_htc_get_stats
,
1836 .get_antenna
= ath9k_htc_get_antenna
,
1838 #ifdef CONFIG_ATH9K_HTC_DEBUGFS
1839 .get_et_sset_count
= ath9k_htc_get_et_sset_count
,
1840 .get_et_stats
= ath9k_htc_get_et_stats
,
1841 .get_et_strings
= ath9k_htc_get_et_strings
,