1*4882a593Smuzhiyun /*-
2*4882a593Smuzhiyun * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting
3*4882a593Smuzhiyun * Copyright (c) 2004-2005 Atheros Communications, Inc.
4*4882a593Smuzhiyun * Copyright (c) 2006 Devicescape Software, Inc.
5*4882a593Smuzhiyun * Copyright (c) 2007 Jiri Slaby <jirislaby@gmail.com>
6*4882a593Smuzhiyun * Copyright (c) 2007 Luis R. Rodriguez <mcgrof@winlab.rutgers.edu>
7*4882a593Smuzhiyun * Copyright (c) 2010 Bruno Randolf <br1@einfach.org>
8*4882a593Smuzhiyun *
9*4882a593Smuzhiyun * All rights reserved.
10*4882a593Smuzhiyun *
11*4882a593Smuzhiyun * Redistribution and use in source and binary forms, with or without
12*4882a593Smuzhiyun * modification, are permitted provided that the following conditions
13*4882a593Smuzhiyun * are met:
14*4882a593Smuzhiyun * 1. Redistributions of source code must retain the above copyright
15*4882a593Smuzhiyun * notice, this list of conditions and the following disclaimer,
16*4882a593Smuzhiyun * without modification.
17*4882a593Smuzhiyun * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18*4882a593Smuzhiyun * similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
19*4882a593Smuzhiyun * redistribution must be conditioned upon including a substantially
20*4882a593Smuzhiyun * similar Disclaimer requirement for further binary redistribution.
21*4882a593Smuzhiyun * 3. Neither the names of the above-listed copyright holders nor the names
22*4882a593Smuzhiyun * of any contributors may be used to endorse or promote products derived
23*4882a593Smuzhiyun * from this software without specific prior written permission.
24*4882a593Smuzhiyun *
25*4882a593Smuzhiyun * Alternatively, this software may be distributed under the terms of the
26*4882a593Smuzhiyun * GNU General Public License ("GPL") version 2 as published by the Free
27*4882a593Smuzhiyun * Software Foundation.
28*4882a593Smuzhiyun *
29*4882a593Smuzhiyun * NO WARRANTY
30*4882a593Smuzhiyun * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
31*4882a593Smuzhiyun * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
32*4882a593Smuzhiyun * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
33*4882a593Smuzhiyun * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
34*4882a593Smuzhiyun * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
35*4882a593Smuzhiyun * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
36*4882a593Smuzhiyun * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
37*4882a593Smuzhiyun * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
38*4882a593Smuzhiyun * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
39*4882a593Smuzhiyun * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
40*4882a593Smuzhiyun * THE POSSIBILITY OF SUCH DAMAGES.
41*4882a593Smuzhiyun *
42*4882a593Smuzhiyun */
43*4882a593Smuzhiyun
44*4882a593Smuzhiyun #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
45*4882a593Smuzhiyun
46*4882a593Smuzhiyun #include <net/mac80211.h>
47*4882a593Smuzhiyun #include <asm/unaligned.h>
48*4882a593Smuzhiyun
49*4882a593Smuzhiyun #include "ath5k.h"
50*4882a593Smuzhiyun #include "base.h"
51*4882a593Smuzhiyun #include "reg.h"
52*4882a593Smuzhiyun
53*4882a593Smuzhiyun /********************\
54*4882a593Smuzhiyun * Mac80211 functions *
55*4882a593Smuzhiyun \********************/
56*4882a593Smuzhiyun
57*4882a593Smuzhiyun static void
ath5k_tx(struct ieee80211_hw * hw,struct ieee80211_tx_control * control,struct sk_buff * skb)58*4882a593Smuzhiyun ath5k_tx(struct ieee80211_hw *hw, struct ieee80211_tx_control *control,
59*4882a593Smuzhiyun struct sk_buff *skb)
60*4882a593Smuzhiyun {
61*4882a593Smuzhiyun struct ath5k_hw *ah = hw->priv;
62*4882a593Smuzhiyun u16 qnum = skb_get_queue_mapping(skb);
63*4882a593Smuzhiyun
64*4882a593Smuzhiyun if (WARN_ON(qnum >= ah->ah_capabilities.cap_queues.q_tx_num)) {
65*4882a593Smuzhiyun ieee80211_free_txskb(hw, skb);
66*4882a593Smuzhiyun return;
67*4882a593Smuzhiyun }
68*4882a593Smuzhiyun
69*4882a593Smuzhiyun ath5k_tx_queue(hw, skb, &ah->txqs[qnum], control);
70*4882a593Smuzhiyun }
71*4882a593Smuzhiyun
72*4882a593Smuzhiyun
73*4882a593Smuzhiyun static int
ath5k_add_interface(struct ieee80211_hw * hw,struct ieee80211_vif * vif)74*4882a593Smuzhiyun ath5k_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
75*4882a593Smuzhiyun {
76*4882a593Smuzhiyun struct ath5k_hw *ah = hw->priv;
77*4882a593Smuzhiyun int ret;
78*4882a593Smuzhiyun struct ath5k_vif *avf = (void *)vif->drv_priv;
79*4882a593Smuzhiyun
80*4882a593Smuzhiyun mutex_lock(&ah->lock);
81*4882a593Smuzhiyun
82*4882a593Smuzhiyun if ((vif->type == NL80211_IFTYPE_AP ||
83*4882a593Smuzhiyun vif->type == NL80211_IFTYPE_ADHOC)
84*4882a593Smuzhiyun && (ah->num_ap_vifs + ah->num_adhoc_vifs) >= ATH_BCBUF) {
85*4882a593Smuzhiyun ret = -ELNRNG;
86*4882a593Smuzhiyun goto end;
87*4882a593Smuzhiyun }
88*4882a593Smuzhiyun
89*4882a593Smuzhiyun /* Don't allow other interfaces if one ad-hoc is configured.
90*4882a593Smuzhiyun * TODO: Fix the problems with ad-hoc and multiple other interfaces.
91*4882a593Smuzhiyun * We would need to operate the HW in ad-hoc mode to allow TSF updates
92*4882a593Smuzhiyun * for the IBSS, but this breaks with additional AP or STA interfaces
93*4882a593Smuzhiyun * at the moment. */
94*4882a593Smuzhiyun if (ah->num_adhoc_vifs ||
95*4882a593Smuzhiyun (ah->nvifs && vif->type == NL80211_IFTYPE_ADHOC)) {
96*4882a593Smuzhiyun ATH5K_ERR(ah, "Only one single ad-hoc interface is allowed.\n");
97*4882a593Smuzhiyun ret = -ELNRNG;
98*4882a593Smuzhiyun goto end;
99*4882a593Smuzhiyun }
100*4882a593Smuzhiyun
101*4882a593Smuzhiyun switch (vif->type) {
102*4882a593Smuzhiyun case NL80211_IFTYPE_AP:
103*4882a593Smuzhiyun case NL80211_IFTYPE_STATION:
104*4882a593Smuzhiyun case NL80211_IFTYPE_ADHOC:
105*4882a593Smuzhiyun case NL80211_IFTYPE_MESH_POINT:
106*4882a593Smuzhiyun avf->opmode = vif->type;
107*4882a593Smuzhiyun break;
108*4882a593Smuzhiyun default:
109*4882a593Smuzhiyun ret = -EOPNOTSUPP;
110*4882a593Smuzhiyun goto end;
111*4882a593Smuzhiyun }
112*4882a593Smuzhiyun
113*4882a593Smuzhiyun ah->nvifs++;
114*4882a593Smuzhiyun ATH5K_DBG(ah, ATH5K_DEBUG_MODE, "add interface mode %d\n", avf->opmode);
115*4882a593Smuzhiyun
116*4882a593Smuzhiyun /* Assign the vap/adhoc to a beacon xmit slot. */
117*4882a593Smuzhiyun if ((avf->opmode == NL80211_IFTYPE_AP) ||
118*4882a593Smuzhiyun (avf->opmode == NL80211_IFTYPE_ADHOC) ||
119*4882a593Smuzhiyun (avf->opmode == NL80211_IFTYPE_MESH_POINT)) {
120*4882a593Smuzhiyun int slot;
121*4882a593Smuzhiyun
122*4882a593Smuzhiyun WARN_ON(list_empty(&ah->bcbuf));
123*4882a593Smuzhiyun avf->bbuf = list_first_entry(&ah->bcbuf, struct ath5k_buf,
124*4882a593Smuzhiyun list);
125*4882a593Smuzhiyun list_del(&avf->bbuf->list);
126*4882a593Smuzhiyun
127*4882a593Smuzhiyun avf->bslot = 0;
128*4882a593Smuzhiyun for (slot = 0; slot < ATH_BCBUF; slot++) {
129*4882a593Smuzhiyun if (!ah->bslot[slot]) {
130*4882a593Smuzhiyun avf->bslot = slot;
131*4882a593Smuzhiyun break;
132*4882a593Smuzhiyun }
133*4882a593Smuzhiyun }
134*4882a593Smuzhiyun BUG_ON(ah->bslot[avf->bslot] != NULL);
135*4882a593Smuzhiyun ah->bslot[avf->bslot] = vif;
136*4882a593Smuzhiyun if (avf->opmode == NL80211_IFTYPE_AP)
137*4882a593Smuzhiyun ah->num_ap_vifs++;
138*4882a593Smuzhiyun else if (avf->opmode == NL80211_IFTYPE_ADHOC)
139*4882a593Smuzhiyun ah->num_adhoc_vifs++;
140*4882a593Smuzhiyun else if (avf->opmode == NL80211_IFTYPE_MESH_POINT)
141*4882a593Smuzhiyun ah->num_mesh_vifs++;
142*4882a593Smuzhiyun }
143*4882a593Smuzhiyun
144*4882a593Smuzhiyun /* Any MAC address is fine, all others are included through the
145*4882a593Smuzhiyun * filter.
146*4882a593Smuzhiyun */
147*4882a593Smuzhiyun ath5k_hw_set_lladdr(ah, vif->addr);
148*4882a593Smuzhiyun
149*4882a593Smuzhiyun ath5k_update_bssid_mask_and_opmode(ah, vif);
150*4882a593Smuzhiyun ret = 0;
151*4882a593Smuzhiyun end:
152*4882a593Smuzhiyun mutex_unlock(&ah->lock);
153*4882a593Smuzhiyun return ret;
154*4882a593Smuzhiyun }
155*4882a593Smuzhiyun
156*4882a593Smuzhiyun
157*4882a593Smuzhiyun static void
ath5k_remove_interface(struct ieee80211_hw * hw,struct ieee80211_vif * vif)158*4882a593Smuzhiyun ath5k_remove_interface(struct ieee80211_hw *hw,
159*4882a593Smuzhiyun struct ieee80211_vif *vif)
160*4882a593Smuzhiyun {
161*4882a593Smuzhiyun struct ath5k_hw *ah = hw->priv;
162*4882a593Smuzhiyun struct ath5k_vif *avf = (void *)vif->drv_priv;
163*4882a593Smuzhiyun unsigned int i;
164*4882a593Smuzhiyun
165*4882a593Smuzhiyun mutex_lock(&ah->lock);
166*4882a593Smuzhiyun ah->nvifs--;
167*4882a593Smuzhiyun
168*4882a593Smuzhiyun if (avf->bbuf) {
169*4882a593Smuzhiyun ath5k_txbuf_free_skb(ah, avf->bbuf);
170*4882a593Smuzhiyun list_add_tail(&avf->bbuf->list, &ah->bcbuf);
171*4882a593Smuzhiyun for (i = 0; i < ATH_BCBUF; i++) {
172*4882a593Smuzhiyun if (ah->bslot[i] == vif) {
173*4882a593Smuzhiyun ah->bslot[i] = NULL;
174*4882a593Smuzhiyun break;
175*4882a593Smuzhiyun }
176*4882a593Smuzhiyun }
177*4882a593Smuzhiyun avf->bbuf = NULL;
178*4882a593Smuzhiyun }
179*4882a593Smuzhiyun if (avf->opmode == NL80211_IFTYPE_AP)
180*4882a593Smuzhiyun ah->num_ap_vifs--;
181*4882a593Smuzhiyun else if (avf->opmode == NL80211_IFTYPE_ADHOC)
182*4882a593Smuzhiyun ah->num_adhoc_vifs--;
183*4882a593Smuzhiyun else if (avf->opmode == NL80211_IFTYPE_MESH_POINT)
184*4882a593Smuzhiyun ah->num_mesh_vifs--;
185*4882a593Smuzhiyun
186*4882a593Smuzhiyun ath5k_update_bssid_mask_and_opmode(ah, NULL);
187*4882a593Smuzhiyun mutex_unlock(&ah->lock);
188*4882a593Smuzhiyun }
189*4882a593Smuzhiyun
190*4882a593Smuzhiyun
191*4882a593Smuzhiyun /*
192*4882a593Smuzhiyun * TODO: Phy disable/diversity etc
193*4882a593Smuzhiyun */
194*4882a593Smuzhiyun static int
ath5k_config(struct ieee80211_hw * hw,u32 changed)195*4882a593Smuzhiyun ath5k_config(struct ieee80211_hw *hw, u32 changed)
196*4882a593Smuzhiyun {
197*4882a593Smuzhiyun struct ath5k_hw *ah = hw->priv;
198*4882a593Smuzhiyun struct ieee80211_conf *conf = &hw->conf;
199*4882a593Smuzhiyun int ret = 0;
200*4882a593Smuzhiyun int i;
201*4882a593Smuzhiyun
202*4882a593Smuzhiyun mutex_lock(&ah->lock);
203*4882a593Smuzhiyun
204*4882a593Smuzhiyun if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
205*4882a593Smuzhiyun ret = ath5k_chan_set(ah, &conf->chandef);
206*4882a593Smuzhiyun if (ret < 0)
207*4882a593Smuzhiyun goto unlock;
208*4882a593Smuzhiyun }
209*4882a593Smuzhiyun
210*4882a593Smuzhiyun if ((changed & IEEE80211_CONF_CHANGE_POWER) &&
211*4882a593Smuzhiyun (ah->ah_txpower.txp_requested != conf->power_level)) {
212*4882a593Smuzhiyun ah->ah_txpower.txp_requested = conf->power_level;
213*4882a593Smuzhiyun
214*4882a593Smuzhiyun /* Half dB steps */
215*4882a593Smuzhiyun ath5k_hw_set_txpower_limit(ah, (conf->power_level * 2));
216*4882a593Smuzhiyun }
217*4882a593Smuzhiyun
218*4882a593Smuzhiyun if (changed & IEEE80211_CONF_CHANGE_RETRY_LIMITS) {
219*4882a593Smuzhiyun ah->ah_retry_long = conf->long_frame_max_tx_count;
220*4882a593Smuzhiyun ah->ah_retry_short = conf->short_frame_max_tx_count;
221*4882a593Smuzhiyun
222*4882a593Smuzhiyun for (i = 0; i < ah->ah_capabilities.cap_queues.q_tx_num; i++)
223*4882a593Smuzhiyun ath5k_hw_set_tx_retry_limits(ah, i);
224*4882a593Smuzhiyun }
225*4882a593Smuzhiyun
226*4882a593Smuzhiyun /* TODO:
227*4882a593Smuzhiyun * 1) Move this on config_interface and handle each case
228*4882a593Smuzhiyun * separately eg. when we have only one STA vif, use
229*4882a593Smuzhiyun * AR5K_ANTMODE_SINGLE_AP
230*4882a593Smuzhiyun *
231*4882a593Smuzhiyun * 2) Allow the user to change antenna mode eg. when only
232*4882a593Smuzhiyun * one antenna is present
233*4882a593Smuzhiyun *
234*4882a593Smuzhiyun * 3) Allow the user to set default/tx antenna when possible
235*4882a593Smuzhiyun *
236*4882a593Smuzhiyun * 4) Default mode should handle 90% of the cases, together
237*4882a593Smuzhiyun * with fixed a/b and single AP modes we should be able to
238*4882a593Smuzhiyun * handle 99%. Sectored modes are extreme cases and i still
239*4882a593Smuzhiyun * haven't found a usage for them. If we decide to support them,
240*4882a593Smuzhiyun * then we must allow the user to set how many tx antennas we
241*4882a593Smuzhiyun * have available
242*4882a593Smuzhiyun */
243*4882a593Smuzhiyun ath5k_hw_set_antenna_mode(ah, ah->ah_ant_mode);
244*4882a593Smuzhiyun
245*4882a593Smuzhiyun unlock:
246*4882a593Smuzhiyun mutex_unlock(&ah->lock);
247*4882a593Smuzhiyun return ret;
248*4882a593Smuzhiyun }
249*4882a593Smuzhiyun
250*4882a593Smuzhiyun
251*4882a593Smuzhiyun static void
ath5k_bss_info_changed(struct ieee80211_hw * hw,struct ieee80211_vif * vif,struct ieee80211_bss_conf * bss_conf,u32 changes)252*4882a593Smuzhiyun ath5k_bss_info_changed(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
253*4882a593Smuzhiyun struct ieee80211_bss_conf *bss_conf, u32 changes)
254*4882a593Smuzhiyun {
255*4882a593Smuzhiyun struct ath5k_vif *avf = (void *)vif->drv_priv;
256*4882a593Smuzhiyun struct ath5k_hw *ah = hw->priv;
257*4882a593Smuzhiyun struct ath_common *common = ath5k_hw_common(ah);
258*4882a593Smuzhiyun
259*4882a593Smuzhiyun mutex_lock(&ah->lock);
260*4882a593Smuzhiyun
261*4882a593Smuzhiyun if (changes & BSS_CHANGED_BSSID) {
262*4882a593Smuzhiyun /* Cache for later use during resets */
263*4882a593Smuzhiyun memcpy(common->curbssid, bss_conf->bssid, ETH_ALEN);
264*4882a593Smuzhiyun common->curaid = 0;
265*4882a593Smuzhiyun ath5k_hw_set_bssid(ah);
266*4882a593Smuzhiyun }
267*4882a593Smuzhiyun
268*4882a593Smuzhiyun if (changes & BSS_CHANGED_BEACON_INT)
269*4882a593Smuzhiyun ah->bintval = bss_conf->beacon_int;
270*4882a593Smuzhiyun
271*4882a593Smuzhiyun if (changes & BSS_CHANGED_ERP_SLOT) {
272*4882a593Smuzhiyun int slot_time;
273*4882a593Smuzhiyun
274*4882a593Smuzhiyun ah->ah_short_slot = bss_conf->use_short_slot;
275*4882a593Smuzhiyun slot_time = ath5k_hw_get_default_slottime(ah) +
276*4882a593Smuzhiyun 3 * ah->ah_coverage_class;
277*4882a593Smuzhiyun ath5k_hw_set_ifs_intervals(ah, slot_time);
278*4882a593Smuzhiyun }
279*4882a593Smuzhiyun
280*4882a593Smuzhiyun if (changes & BSS_CHANGED_ASSOC) {
281*4882a593Smuzhiyun avf->assoc = bss_conf->assoc;
282*4882a593Smuzhiyun if (bss_conf->assoc)
283*4882a593Smuzhiyun ah->assoc = bss_conf->assoc;
284*4882a593Smuzhiyun else
285*4882a593Smuzhiyun ah->assoc = ath5k_any_vif_assoc(ah);
286*4882a593Smuzhiyun
287*4882a593Smuzhiyun if (ah->opmode == NL80211_IFTYPE_STATION)
288*4882a593Smuzhiyun ath5k_set_beacon_filter(hw, ah->assoc);
289*4882a593Smuzhiyun ath5k_hw_set_ledstate(ah, ah->assoc ?
290*4882a593Smuzhiyun AR5K_LED_ASSOC : AR5K_LED_INIT);
291*4882a593Smuzhiyun if (bss_conf->assoc) {
292*4882a593Smuzhiyun ATH5K_DBG(ah, ATH5K_DEBUG_ANY,
293*4882a593Smuzhiyun "Bss Info ASSOC %d, bssid: %pM\n",
294*4882a593Smuzhiyun bss_conf->aid, common->curbssid);
295*4882a593Smuzhiyun common->curaid = bss_conf->aid;
296*4882a593Smuzhiyun ath5k_hw_set_bssid(ah);
297*4882a593Smuzhiyun /* Once ANI is available you would start it here */
298*4882a593Smuzhiyun }
299*4882a593Smuzhiyun }
300*4882a593Smuzhiyun
301*4882a593Smuzhiyun if (changes & BSS_CHANGED_BEACON) {
302*4882a593Smuzhiyun spin_lock_bh(&ah->block);
303*4882a593Smuzhiyun ath5k_beacon_update(hw, vif);
304*4882a593Smuzhiyun spin_unlock_bh(&ah->block);
305*4882a593Smuzhiyun }
306*4882a593Smuzhiyun
307*4882a593Smuzhiyun if (changes & BSS_CHANGED_BEACON_ENABLED)
308*4882a593Smuzhiyun ah->enable_beacon = bss_conf->enable_beacon;
309*4882a593Smuzhiyun
310*4882a593Smuzhiyun if (changes & (BSS_CHANGED_BEACON | BSS_CHANGED_BEACON_ENABLED |
311*4882a593Smuzhiyun BSS_CHANGED_BEACON_INT))
312*4882a593Smuzhiyun ath5k_beacon_config(ah);
313*4882a593Smuzhiyun
314*4882a593Smuzhiyun mutex_unlock(&ah->lock);
315*4882a593Smuzhiyun }
316*4882a593Smuzhiyun
317*4882a593Smuzhiyun
318*4882a593Smuzhiyun static u64
ath5k_prepare_multicast(struct ieee80211_hw * hw,struct netdev_hw_addr_list * mc_list)319*4882a593Smuzhiyun ath5k_prepare_multicast(struct ieee80211_hw *hw,
320*4882a593Smuzhiyun struct netdev_hw_addr_list *mc_list)
321*4882a593Smuzhiyun {
322*4882a593Smuzhiyun u32 mfilt[2], val;
323*4882a593Smuzhiyun u8 pos;
324*4882a593Smuzhiyun struct netdev_hw_addr *ha;
325*4882a593Smuzhiyun
326*4882a593Smuzhiyun mfilt[0] = 0;
327*4882a593Smuzhiyun mfilt[1] = 0;
328*4882a593Smuzhiyun
329*4882a593Smuzhiyun netdev_hw_addr_list_for_each(ha, mc_list) {
330*4882a593Smuzhiyun /* calculate XOR of eight 6-bit values */
331*4882a593Smuzhiyun val = get_unaligned_le32(ha->addr + 0);
332*4882a593Smuzhiyun pos = (val >> 18) ^ (val >> 12) ^ (val >> 6) ^ val;
333*4882a593Smuzhiyun val = get_unaligned_le32(ha->addr + 3);
334*4882a593Smuzhiyun pos ^= (val >> 18) ^ (val >> 12) ^ (val >> 6) ^ val;
335*4882a593Smuzhiyun pos &= 0x3f;
336*4882a593Smuzhiyun mfilt[pos / 32] |= (1 << (pos % 32));
337*4882a593Smuzhiyun /* XXX: we might be able to just do this instead,
338*4882a593Smuzhiyun * but not sure, needs testing, if we do use this we'd
339*4882a593Smuzhiyun * need to inform below not to reset the mcast */
340*4882a593Smuzhiyun /* ath5k_hw_set_mcast_filterindex(ah,
341*4882a593Smuzhiyun * ha->addr[5]); */
342*4882a593Smuzhiyun }
343*4882a593Smuzhiyun
344*4882a593Smuzhiyun return ((u64)(mfilt[1]) << 32) | mfilt[0];
345*4882a593Smuzhiyun }
346*4882a593Smuzhiyun
347*4882a593Smuzhiyun
348*4882a593Smuzhiyun /*
349*4882a593Smuzhiyun * o always accept unicast, broadcast, and multicast traffic
350*4882a593Smuzhiyun * o multicast traffic for all BSSIDs will be enabled if mac80211
351*4882a593Smuzhiyun * says it should be
352*4882a593Smuzhiyun * o maintain current state of phy ofdm or phy cck error reception.
353*4882a593Smuzhiyun * If the hardware detects any of these type of errors then
354*4882a593Smuzhiyun * ath5k_hw_get_rx_filter() will pass to us the respective
355*4882a593Smuzhiyun * hardware filters to be able to receive these type of frames.
356*4882a593Smuzhiyun * o probe request frames are accepted only when operating in
357*4882a593Smuzhiyun * hostap, adhoc, or monitor modes
358*4882a593Smuzhiyun * o enable promiscuous mode according to the interface state
359*4882a593Smuzhiyun * o accept beacons:
360*4882a593Smuzhiyun * - when operating in adhoc mode so the 802.11 layer creates
361*4882a593Smuzhiyun * node table entries for peers,
362*4882a593Smuzhiyun * - when operating in station mode for collecting rssi data when
363*4882a593Smuzhiyun * the station is otherwise quiet, or
364*4882a593Smuzhiyun * - when scanning
365*4882a593Smuzhiyun */
366*4882a593Smuzhiyun static void
ath5k_configure_filter(struct ieee80211_hw * hw,unsigned int changed_flags,unsigned int * new_flags,u64 multicast)367*4882a593Smuzhiyun ath5k_configure_filter(struct ieee80211_hw *hw, unsigned int changed_flags,
368*4882a593Smuzhiyun unsigned int *new_flags, u64 multicast)
369*4882a593Smuzhiyun {
370*4882a593Smuzhiyun #define SUPPORTED_FIF_FLAGS \
371*4882a593Smuzhiyun (FIF_ALLMULTI | FIF_FCSFAIL | \
372*4882a593Smuzhiyun FIF_PLCPFAIL | FIF_CONTROL | FIF_OTHER_BSS | \
373*4882a593Smuzhiyun FIF_BCN_PRBRESP_PROMISC)
374*4882a593Smuzhiyun
375*4882a593Smuzhiyun struct ath5k_hw *ah = hw->priv;
376*4882a593Smuzhiyun u32 mfilt[2], rfilt;
377*4882a593Smuzhiyun struct ath5k_vif_iter_data iter_data; /* to count STA interfaces */
378*4882a593Smuzhiyun
379*4882a593Smuzhiyun mutex_lock(&ah->lock);
380*4882a593Smuzhiyun
381*4882a593Smuzhiyun mfilt[0] = multicast;
382*4882a593Smuzhiyun mfilt[1] = multicast >> 32;
383*4882a593Smuzhiyun
384*4882a593Smuzhiyun /* Only deal with supported flags */
385*4882a593Smuzhiyun changed_flags &= SUPPORTED_FIF_FLAGS;
386*4882a593Smuzhiyun *new_flags &= SUPPORTED_FIF_FLAGS;
387*4882a593Smuzhiyun
388*4882a593Smuzhiyun /* If HW detects any phy or radar errors, leave those filters on.
389*4882a593Smuzhiyun * Also, always enable Unicast, Broadcasts and Multicast
390*4882a593Smuzhiyun * XXX: move unicast, bssid broadcasts and multicast to mac80211 */
391*4882a593Smuzhiyun rfilt = (ath5k_hw_get_rx_filter(ah) & (AR5K_RX_FILTER_PHYERR)) |
392*4882a593Smuzhiyun (AR5K_RX_FILTER_UCAST | AR5K_RX_FILTER_BCAST |
393*4882a593Smuzhiyun AR5K_RX_FILTER_MCAST);
394*4882a593Smuzhiyun
395*4882a593Smuzhiyun /* Note, AR5K_RX_FILTER_MCAST is already enabled */
396*4882a593Smuzhiyun if (*new_flags & FIF_ALLMULTI) {
397*4882a593Smuzhiyun mfilt[0] = ~0;
398*4882a593Smuzhiyun mfilt[1] = ~0;
399*4882a593Smuzhiyun }
400*4882a593Smuzhiyun
401*4882a593Smuzhiyun /* This is the best we can do */
402*4882a593Smuzhiyun if (*new_flags & (FIF_FCSFAIL | FIF_PLCPFAIL))
403*4882a593Smuzhiyun rfilt |= AR5K_RX_FILTER_PHYERR;
404*4882a593Smuzhiyun
405*4882a593Smuzhiyun /* FIF_BCN_PRBRESP_PROMISC really means to enable beacons
406*4882a593Smuzhiyun * and probes for any BSSID */
407*4882a593Smuzhiyun if ((*new_flags & FIF_BCN_PRBRESP_PROMISC) || (ah->nvifs > 1))
408*4882a593Smuzhiyun rfilt |= AR5K_RX_FILTER_BEACON;
409*4882a593Smuzhiyun
410*4882a593Smuzhiyun /* FIF_CONTROL doc says we should only pass on control frames for this
411*4882a593Smuzhiyun * station. This needs testing. I believe right now this
412*4882a593Smuzhiyun * enables *all* control frames, which is OK.. but
413*4882a593Smuzhiyun * but we should see if we can improve on granularity */
414*4882a593Smuzhiyun if (*new_flags & FIF_CONTROL)
415*4882a593Smuzhiyun rfilt |= AR5K_RX_FILTER_CONTROL;
416*4882a593Smuzhiyun
417*4882a593Smuzhiyun /* Additional settings per mode -- this is per ath5k */
418*4882a593Smuzhiyun
419*4882a593Smuzhiyun /* XXX move these to mac80211, and add a beacon IFF flag to mac80211 */
420*4882a593Smuzhiyun
421*4882a593Smuzhiyun switch (ah->opmode) {
422*4882a593Smuzhiyun case NL80211_IFTYPE_MESH_POINT:
423*4882a593Smuzhiyun rfilt |= AR5K_RX_FILTER_CONTROL |
424*4882a593Smuzhiyun AR5K_RX_FILTER_BEACON |
425*4882a593Smuzhiyun AR5K_RX_FILTER_PROBEREQ |
426*4882a593Smuzhiyun AR5K_RX_FILTER_PROM;
427*4882a593Smuzhiyun break;
428*4882a593Smuzhiyun case NL80211_IFTYPE_AP:
429*4882a593Smuzhiyun case NL80211_IFTYPE_ADHOC:
430*4882a593Smuzhiyun rfilt |= AR5K_RX_FILTER_PROBEREQ |
431*4882a593Smuzhiyun AR5K_RX_FILTER_BEACON;
432*4882a593Smuzhiyun break;
433*4882a593Smuzhiyun case NL80211_IFTYPE_STATION:
434*4882a593Smuzhiyun if (ah->assoc)
435*4882a593Smuzhiyun rfilt |= AR5K_RX_FILTER_BEACON;
436*4882a593Smuzhiyun default:
437*4882a593Smuzhiyun break;
438*4882a593Smuzhiyun }
439*4882a593Smuzhiyun
440*4882a593Smuzhiyun iter_data.hw_macaddr = NULL;
441*4882a593Smuzhiyun iter_data.n_stas = 0;
442*4882a593Smuzhiyun iter_data.need_set_hw_addr = false;
443*4882a593Smuzhiyun ieee80211_iterate_active_interfaces_atomic(
444*4882a593Smuzhiyun ah->hw, IEEE80211_IFACE_ITER_RESUME_ALL,
445*4882a593Smuzhiyun ath5k_vif_iter, &iter_data);
446*4882a593Smuzhiyun
447*4882a593Smuzhiyun /* Set up RX Filter */
448*4882a593Smuzhiyun if (iter_data.n_stas > 1) {
449*4882a593Smuzhiyun /* If you have multiple STA interfaces connected to
450*4882a593Smuzhiyun * different APs, ARPs are not received (most of the time?)
451*4882a593Smuzhiyun * Enabling PROMISC appears to fix that problem.
452*4882a593Smuzhiyun */
453*4882a593Smuzhiyun rfilt |= AR5K_RX_FILTER_PROM;
454*4882a593Smuzhiyun }
455*4882a593Smuzhiyun
456*4882a593Smuzhiyun /* Set filters */
457*4882a593Smuzhiyun ath5k_hw_set_rx_filter(ah, rfilt);
458*4882a593Smuzhiyun
459*4882a593Smuzhiyun /* Set multicast bits */
460*4882a593Smuzhiyun ath5k_hw_set_mcast_filter(ah, mfilt[0], mfilt[1]);
461*4882a593Smuzhiyun /* Set the cached hw filter flags, this will later actually
462*4882a593Smuzhiyun * be set in HW */
463*4882a593Smuzhiyun ah->filter_flags = rfilt;
464*4882a593Smuzhiyun /* Store current FIF filter flags */
465*4882a593Smuzhiyun ah->fif_filter_flags = *new_flags;
466*4882a593Smuzhiyun
467*4882a593Smuzhiyun mutex_unlock(&ah->lock);
468*4882a593Smuzhiyun }
469*4882a593Smuzhiyun
470*4882a593Smuzhiyun
471*4882a593Smuzhiyun static int
ath5k_set_key(struct ieee80211_hw * hw,enum set_key_cmd cmd,struct ieee80211_vif * vif,struct ieee80211_sta * sta,struct ieee80211_key_conf * key)472*4882a593Smuzhiyun ath5k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
473*4882a593Smuzhiyun struct ieee80211_vif *vif, struct ieee80211_sta *sta,
474*4882a593Smuzhiyun struct ieee80211_key_conf *key)
475*4882a593Smuzhiyun {
476*4882a593Smuzhiyun struct ath5k_hw *ah = hw->priv;
477*4882a593Smuzhiyun struct ath_common *common = ath5k_hw_common(ah);
478*4882a593Smuzhiyun int ret = 0;
479*4882a593Smuzhiyun
480*4882a593Smuzhiyun if (ath5k_modparam_nohwcrypt)
481*4882a593Smuzhiyun return -EOPNOTSUPP;
482*4882a593Smuzhiyun
483*4882a593Smuzhiyun if (key->flags & IEEE80211_KEY_FLAG_RX_MGMT)
484*4882a593Smuzhiyun return -EOPNOTSUPP;
485*4882a593Smuzhiyun
486*4882a593Smuzhiyun if (vif->type == NL80211_IFTYPE_ADHOC &&
487*4882a593Smuzhiyun (key->cipher == WLAN_CIPHER_SUITE_TKIP ||
488*4882a593Smuzhiyun key->cipher == WLAN_CIPHER_SUITE_CCMP) &&
489*4882a593Smuzhiyun !(key->flags & IEEE80211_KEY_FLAG_PAIRWISE)) {
490*4882a593Smuzhiyun /* don't program group keys when using IBSS_RSN */
491*4882a593Smuzhiyun return -EOPNOTSUPP;
492*4882a593Smuzhiyun }
493*4882a593Smuzhiyun
494*4882a593Smuzhiyun switch (key->cipher) {
495*4882a593Smuzhiyun case WLAN_CIPHER_SUITE_WEP40:
496*4882a593Smuzhiyun case WLAN_CIPHER_SUITE_WEP104:
497*4882a593Smuzhiyun case WLAN_CIPHER_SUITE_TKIP:
498*4882a593Smuzhiyun break;
499*4882a593Smuzhiyun case WLAN_CIPHER_SUITE_CCMP:
500*4882a593Smuzhiyun if (common->crypt_caps & ATH_CRYPT_CAP_CIPHER_AESCCM)
501*4882a593Smuzhiyun break;
502*4882a593Smuzhiyun return -EOPNOTSUPP;
503*4882a593Smuzhiyun default:
504*4882a593Smuzhiyun return -EOPNOTSUPP;
505*4882a593Smuzhiyun }
506*4882a593Smuzhiyun
507*4882a593Smuzhiyun mutex_lock(&ah->lock);
508*4882a593Smuzhiyun
509*4882a593Smuzhiyun switch (cmd) {
510*4882a593Smuzhiyun case SET_KEY:
511*4882a593Smuzhiyun ret = ath_key_config(common, vif, sta, key);
512*4882a593Smuzhiyun if (ret >= 0) {
513*4882a593Smuzhiyun key->hw_key_idx = ret;
514*4882a593Smuzhiyun /* push IV and Michael MIC generation to stack */
515*4882a593Smuzhiyun key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
516*4882a593Smuzhiyun if (key->cipher == WLAN_CIPHER_SUITE_TKIP)
517*4882a593Smuzhiyun key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
518*4882a593Smuzhiyun if (key->cipher == WLAN_CIPHER_SUITE_CCMP)
519*4882a593Smuzhiyun key->flags |= IEEE80211_KEY_FLAG_SW_MGMT_TX;
520*4882a593Smuzhiyun ret = 0;
521*4882a593Smuzhiyun }
522*4882a593Smuzhiyun break;
523*4882a593Smuzhiyun case DISABLE_KEY:
524*4882a593Smuzhiyun ath_key_delete(common, key->hw_key_idx);
525*4882a593Smuzhiyun break;
526*4882a593Smuzhiyun default:
527*4882a593Smuzhiyun ret = -EINVAL;
528*4882a593Smuzhiyun }
529*4882a593Smuzhiyun
530*4882a593Smuzhiyun mutex_unlock(&ah->lock);
531*4882a593Smuzhiyun return ret;
532*4882a593Smuzhiyun }
533*4882a593Smuzhiyun
534*4882a593Smuzhiyun
535*4882a593Smuzhiyun static void
ath5k_sw_scan_start(struct ieee80211_hw * hw,struct ieee80211_vif * vif,const u8 * mac_addr)536*4882a593Smuzhiyun ath5k_sw_scan_start(struct ieee80211_hw *hw,
537*4882a593Smuzhiyun struct ieee80211_vif *vif,
538*4882a593Smuzhiyun const u8 *mac_addr)
539*4882a593Smuzhiyun {
540*4882a593Smuzhiyun struct ath5k_hw *ah = hw->priv;
541*4882a593Smuzhiyun if (!ah->assoc)
542*4882a593Smuzhiyun ath5k_hw_set_ledstate(ah, AR5K_LED_SCAN);
543*4882a593Smuzhiyun }
544*4882a593Smuzhiyun
545*4882a593Smuzhiyun
546*4882a593Smuzhiyun static void
ath5k_sw_scan_complete(struct ieee80211_hw * hw,struct ieee80211_vif * vif)547*4882a593Smuzhiyun ath5k_sw_scan_complete(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
548*4882a593Smuzhiyun {
549*4882a593Smuzhiyun struct ath5k_hw *ah = hw->priv;
550*4882a593Smuzhiyun ath5k_hw_set_ledstate(ah, ah->assoc ?
551*4882a593Smuzhiyun AR5K_LED_ASSOC : AR5K_LED_INIT);
552*4882a593Smuzhiyun }
553*4882a593Smuzhiyun
554*4882a593Smuzhiyun
555*4882a593Smuzhiyun static int
ath5k_get_stats(struct ieee80211_hw * hw,struct ieee80211_low_level_stats * stats)556*4882a593Smuzhiyun ath5k_get_stats(struct ieee80211_hw *hw,
557*4882a593Smuzhiyun struct ieee80211_low_level_stats *stats)
558*4882a593Smuzhiyun {
559*4882a593Smuzhiyun struct ath5k_hw *ah = hw->priv;
560*4882a593Smuzhiyun
561*4882a593Smuzhiyun /* Force update */
562*4882a593Smuzhiyun ath5k_hw_update_mib_counters(ah);
563*4882a593Smuzhiyun
564*4882a593Smuzhiyun stats->dot11ACKFailureCount = ah->stats.ack_fail;
565*4882a593Smuzhiyun stats->dot11RTSFailureCount = ah->stats.rts_fail;
566*4882a593Smuzhiyun stats->dot11RTSSuccessCount = ah->stats.rts_ok;
567*4882a593Smuzhiyun stats->dot11FCSErrorCount = ah->stats.fcs_error;
568*4882a593Smuzhiyun
569*4882a593Smuzhiyun return 0;
570*4882a593Smuzhiyun }
571*4882a593Smuzhiyun
572*4882a593Smuzhiyun
573*4882a593Smuzhiyun static int
ath5k_conf_tx(struct ieee80211_hw * hw,struct ieee80211_vif * vif,u16 queue,const struct ieee80211_tx_queue_params * params)574*4882a593Smuzhiyun ath5k_conf_tx(struct ieee80211_hw *hw, struct ieee80211_vif *vif, u16 queue,
575*4882a593Smuzhiyun const struct ieee80211_tx_queue_params *params)
576*4882a593Smuzhiyun {
577*4882a593Smuzhiyun struct ath5k_hw *ah = hw->priv;
578*4882a593Smuzhiyun struct ath5k_txq_info qi;
579*4882a593Smuzhiyun int ret = 0;
580*4882a593Smuzhiyun
581*4882a593Smuzhiyun if (queue >= ah->ah_capabilities.cap_queues.q_tx_num)
582*4882a593Smuzhiyun return 0;
583*4882a593Smuzhiyun
584*4882a593Smuzhiyun mutex_lock(&ah->lock);
585*4882a593Smuzhiyun
586*4882a593Smuzhiyun ath5k_hw_get_tx_queueprops(ah, queue, &qi);
587*4882a593Smuzhiyun
588*4882a593Smuzhiyun qi.tqi_aifs = params->aifs;
589*4882a593Smuzhiyun qi.tqi_cw_min = params->cw_min;
590*4882a593Smuzhiyun qi.tqi_cw_max = params->cw_max;
591*4882a593Smuzhiyun qi.tqi_burst_time = params->txop * 32;
592*4882a593Smuzhiyun
593*4882a593Smuzhiyun ATH5K_DBG(ah, ATH5K_DEBUG_ANY,
594*4882a593Smuzhiyun "Configure tx [queue %d], "
595*4882a593Smuzhiyun "aifs: %d, cw_min: %d, cw_max: %d, txop: %d\n",
596*4882a593Smuzhiyun queue, params->aifs, params->cw_min,
597*4882a593Smuzhiyun params->cw_max, params->txop);
598*4882a593Smuzhiyun
599*4882a593Smuzhiyun if (ath5k_hw_set_tx_queueprops(ah, queue, &qi)) {
600*4882a593Smuzhiyun ATH5K_ERR(ah,
601*4882a593Smuzhiyun "Unable to update hardware queue %u!\n", queue);
602*4882a593Smuzhiyun ret = -EIO;
603*4882a593Smuzhiyun } else
604*4882a593Smuzhiyun ath5k_hw_reset_tx_queue(ah, queue);
605*4882a593Smuzhiyun
606*4882a593Smuzhiyun mutex_unlock(&ah->lock);
607*4882a593Smuzhiyun
608*4882a593Smuzhiyun return ret;
609*4882a593Smuzhiyun }
610*4882a593Smuzhiyun
611*4882a593Smuzhiyun
612*4882a593Smuzhiyun static u64
ath5k_get_tsf(struct ieee80211_hw * hw,struct ieee80211_vif * vif)613*4882a593Smuzhiyun ath5k_get_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
614*4882a593Smuzhiyun {
615*4882a593Smuzhiyun struct ath5k_hw *ah = hw->priv;
616*4882a593Smuzhiyun
617*4882a593Smuzhiyun return ath5k_hw_get_tsf64(ah);
618*4882a593Smuzhiyun }
619*4882a593Smuzhiyun
620*4882a593Smuzhiyun
621*4882a593Smuzhiyun static void
ath5k_set_tsf(struct ieee80211_hw * hw,struct ieee80211_vif * vif,u64 tsf)622*4882a593Smuzhiyun ath5k_set_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif, u64 tsf)
623*4882a593Smuzhiyun {
624*4882a593Smuzhiyun struct ath5k_hw *ah = hw->priv;
625*4882a593Smuzhiyun
626*4882a593Smuzhiyun ath5k_hw_set_tsf64(ah, tsf);
627*4882a593Smuzhiyun }
628*4882a593Smuzhiyun
629*4882a593Smuzhiyun
630*4882a593Smuzhiyun static void
ath5k_reset_tsf(struct ieee80211_hw * hw,struct ieee80211_vif * vif)631*4882a593Smuzhiyun ath5k_reset_tsf(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
632*4882a593Smuzhiyun {
633*4882a593Smuzhiyun struct ath5k_hw *ah = hw->priv;
634*4882a593Smuzhiyun
635*4882a593Smuzhiyun /*
636*4882a593Smuzhiyun * in IBSS mode we need to update the beacon timers too.
637*4882a593Smuzhiyun * this will also reset the TSF if we call it with 0
638*4882a593Smuzhiyun */
639*4882a593Smuzhiyun if (ah->opmode == NL80211_IFTYPE_ADHOC)
640*4882a593Smuzhiyun ath5k_beacon_update_timers(ah, 0);
641*4882a593Smuzhiyun else
642*4882a593Smuzhiyun ath5k_hw_reset_tsf(ah);
643*4882a593Smuzhiyun }
644*4882a593Smuzhiyun
645*4882a593Smuzhiyun
646*4882a593Smuzhiyun static int
ath5k_get_survey(struct ieee80211_hw * hw,int idx,struct survey_info * survey)647*4882a593Smuzhiyun ath5k_get_survey(struct ieee80211_hw *hw, int idx, struct survey_info *survey)
648*4882a593Smuzhiyun {
649*4882a593Smuzhiyun struct ath5k_hw *ah = hw->priv;
650*4882a593Smuzhiyun struct ieee80211_conf *conf = &hw->conf;
651*4882a593Smuzhiyun struct ath_common *common = ath5k_hw_common(ah);
652*4882a593Smuzhiyun struct ath_cycle_counters *cc = &common->cc_survey;
653*4882a593Smuzhiyun unsigned int div = common->clockrate * 1000;
654*4882a593Smuzhiyun
655*4882a593Smuzhiyun if (idx != 0)
656*4882a593Smuzhiyun return -ENOENT;
657*4882a593Smuzhiyun
658*4882a593Smuzhiyun spin_lock_bh(&common->cc_lock);
659*4882a593Smuzhiyun ath_hw_cycle_counters_update(common);
660*4882a593Smuzhiyun if (cc->cycles > 0) {
661*4882a593Smuzhiyun ah->survey.time += cc->cycles / div;
662*4882a593Smuzhiyun ah->survey.time_busy += cc->rx_busy / div;
663*4882a593Smuzhiyun ah->survey.time_rx += cc->rx_frame / div;
664*4882a593Smuzhiyun ah->survey.time_tx += cc->tx_frame / div;
665*4882a593Smuzhiyun }
666*4882a593Smuzhiyun memset(cc, 0, sizeof(*cc));
667*4882a593Smuzhiyun spin_unlock_bh(&common->cc_lock);
668*4882a593Smuzhiyun
669*4882a593Smuzhiyun memcpy(survey, &ah->survey, sizeof(*survey));
670*4882a593Smuzhiyun
671*4882a593Smuzhiyun survey->channel = conf->chandef.chan;
672*4882a593Smuzhiyun survey->noise = ah->ah_noise_floor;
673*4882a593Smuzhiyun survey->filled = SURVEY_INFO_NOISE_DBM |
674*4882a593Smuzhiyun SURVEY_INFO_IN_USE |
675*4882a593Smuzhiyun SURVEY_INFO_TIME |
676*4882a593Smuzhiyun SURVEY_INFO_TIME_BUSY |
677*4882a593Smuzhiyun SURVEY_INFO_TIME_RX |
678*4882a593Smuzhiyun SURVEY_INFO_TIME_TX;
679*4882a593Smuzhiyun
680*4882a593Smuzhiyun return 0;
681*4882a593Smuzhiyun }
682*4882a593Smuzhiyun
683*4882a593Smuzhiyun
684*4882a593Smuzhiyun /**
685*4882a593Smuzhiyun * ath5k_set_coverage_class - Set IEEE 802.11 coverage class
686*4882a593Smuzhiyun *
687*4882a593Smuzhiyun * @hw: struct ieee80211_hw pointer
688*4882a593Smuzhiyun * @coverage_class: IEEE 802.11 coverage class number
689*4882a593Smuzhiyun *
690*4882a593Smuzhiyun * Mac80211 callback. Sets slot time, ACK timeout and CTS timeout for given
691*4882a593Smuzhiyun * coverage class. The values are persistent, they are restored after device
692*4882a593Smuzhiyun * reset.
693*4882a593Smuzhiyun */
694*4882a593Smuzhiyun static void
ath5k_set_coverage_class(struct ieee80211_hw * hw,s16 coverage_class)695*4882a593Smuzhiyun ath5k_set_coverage_class(struct ieee80211_hw *hw, s16 coverage_class)
696*4882a593Smuzhiyun {
697*4882a593Smuzhiyun struct ath5k_hw *ah = hw->priv;
698*4882a593Smuzhiyun
699*4882a593Smuzhiyun mutex_lock(&ah->lock);
700*4882a593Smuzhiyun ath5k_hw_set_coverage_class(ah, coverage_class);
701*4882a593Smuzhiyun mutex_unlock(&ah->lock);
702*4882a593Smuzhiyun }
703*4882a593Smuzhiyun
704*4882a593Smuzhiyun
705*4882a593Smuzhiyun static int
ath5k_set_antenna(struct ieee80211_hw * hw,u32 tx_ant,u32 rx_ant)706*4882a593Smuzhiyun ath5k_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
707*4882a593Smuzhiyun {
708*4882a593Smuzhiyun struct ath5k_hw *ah = hw->priv;
709*4882a593Smuzhiyun
710*4882a593Smuzhiyun if (tx_ant == 1 && rx_ant == 1)
711*4882a593Smuzhiyun ath5k_hw_set_antenna_mode(ah, AR5K_ANTMODE_FIXED_A);
712*4882a593Smuzhiyun else if (tx_ant == 2 && rx_ant == 2)
713*4882a593Smuzhiyun ath5k_hw_set_antenna_mode(ah, AR5K_ANTMODE_FIXED_B);
714*4882a593Smuzhiyun else if ((tx_ant & 3) == 3 && (rx_ant & 3) == 3)
715*4882a593Smuzhiyun ath5k_hw_set_antenna_mode(ah, AR5K_ANTMODE_DEFAULT);
716*4882a593Smuzhiyun else
717*4882a593Smuzhiyun return -EINVAL;
718*4882a593Smuzhiyun return 0;
719*4882a593Smuzhiyun }
720*4882a593Smuzhiyun
721*4882a593Smuzhiyun
722*4882a593Smuzhiyun static int
ath5k_get_antenna(struct ieee80211_hw * hw,u32 * tx_ant,u32 * rx_ant)723*4882a593Smuzhiyun ath5k_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant)
724*4882a593Smuzhiyun {
725*4882a593Smuzhiyun struct ath5k_hw *ah = hw->priv;
726*4882a593Smuzhiyun
727*4882a593Smuzhiyun switch (ah->ah_ant_mode) {
728*4882a593Smuzhiyun case AR5K_ANTMODE_FIXED_A:
729*4882a593Smuzhiyun *tx_ant = 1; *rx_ant = 1; break;
730*4882a593Smuzhiyun case AR5K_ANTMODE_FIXED_B:
731*4882a593Smuzhiyun *tx_ant = 2; *rx_ant = 2; break;
732*4882a593Smuzhiyun case AR5K_ANTMODE_DEFAULT:
733*4882a593Smuzhiyun *tx_ant = 3; *rx_ant = 3; break;
734*4882a593Smuzhiyun }
735*4882a593Smuzhiyun return 0;
736*4882a593Smuzhiyun }
737*4882a593Smuzhiyun
738*4882a593Smuzhiyun
ath5k_get_ringparam(struct ieee80211_hw * hw,u32 * tx,u32 * tx_max,u32 * rx,u32 * rx_max)739*4882a593Smuzhiyun static void ath5k_get_ringparam(struct ieee80211_hw *hw,
740*4882a593Smuzhiyun u32 *tx, u32 *tx_max, u32 *rx, u32 *rx_max)
741*4882a593Smuzhiyun {
742*4882a593Smuzhiyun struct ath5k_hw *ah = hw->priv;
743*4882a593Smuzhiyun
744*4882a593Smuzhiyun *tx = ah->txqs[AR5K_TX_QUEUE_ID_DATA_MIN].txq_max;
745*4882a593Smuzhiyun
746*4882a593Smuzhiyun *tx_max = ATH5K_TXQ_LEN_MAX;
747*4882a593Smuzhiyun *rx = *rx_max = ATH_RXBUF;
748*4882a593Smuzhiyun }
749*4882a593Smuzhiyun
750*4882a593Smuzhiyun
ath5k_set_ringparam(struct ieee80211_hw * hw,u32 tx,u32 rx)751*4882a593Smuzhiyun static int ath5k_set_ringparam(struct ieee80211_hw *hw, u32 tx, u32 rx)
752*4882a593Smuzhiyun {
753*4882a593Smuzhiyun struct ath5k_hw *ah = hw->priv;
754*4882a593Smuzhiyun u16 qnum;
755*4882a593Smuzhiyun
756*4882a593Smuzhiyun /* only support setting tx ring size for now */
757*4882a593Smuzhiyun if (rx != ATH_RXBUF)
758*4882a593Smuzhiyun return -EINVAL;
759*4882a593Smuzhiyun
760*4882a593Smuzhiyun /* restrict tx ring size min/max */
761*4882a593Smuzhiyun if (!tx || tx > ATH5K_TXQ_LEN_MAX)
762*4882a593Smuzhiyun return -EINVAL;
763*4882a593Smuzhiyun
764*4882a593Smuzhiyun for (qnum = 0; qnum < ARRAY_SIZE(ah->txqs); qnum++) {
765*4882a593Smuzhiyun if (!ah->txqs[qnum].setup)
766*4882a593Smuzhiyun continue;
767*4882a593Smuzhiyun if (ah->txqs[qnum].qnum < AR5K_TX_QUEUE_ID_DATA_MIN ||
768*4882a593Smuzhiyun ah->txqs[qnum].qnum > AR5K_TX_QUEUE_ID_DATA_MAX)
769*4882a593Smuzhiyun continue;
770*4882a593Smuzhiyun
771*4882a593Smuzhiyun ah->txqs[qnum].txq_max = tx;
772*4882a593Smuzhiyun if (ah->txqs[qnum].txq_len >= ah->txqs[qnum].txq_max)
773*4882a593Smuzhiyun ieee80211_stop_queue(hw, ah->txqs[qnum].qnum);
774*4882a593Smuzhiyun }
775*4882a593Smuzhiyun
776*4882a593Smuzhiyun return 0;
777*4882a593Smuzhiyun }
778*4882a593Smuzhiyun
779*4882a593Smuzhiyun
780*4882a593Smuzhiyun const struct ieee80211_ops ath5k_hw_ops = {
781*4882a593Smuzhiyun .tx = ath5k_tx,
782*4882a593Smuzhiyun .start = ath5k_start,
783*4882a593Smuzhiyun .stop = ath5k_stop,
784*4882a593Smuzhiyun .add_interface = ath5k_add_interface,
785*4882a593Smuzhiyun /* .change_interface = not implemented */
786*4882a593Smuzhiyun .remove_interface = ath5k_remove_interface,
787*4882a593Smuzhiyun .config = ath5k_config,
788*4882a593Smuzhiyun .bss_info_changed = ath5k_bss_info_changed,
789*4882a593Smuzhiyun .prepare_multicast = ath5k_prepare_multicast,
790*4882a593Smuzhiyun .configure_filter = ath5k_configure_filter,
791*4882a593Smuzhiyun /* .set_tim = not implemented */
792*4882a593Smuzhiyun .set_key = ath5k_set_key,
793*4882a593Smuzhiyun /* .update_tkip_key = not implemented */
794*4882a593Smuzhiyun /* .hw_scan = not implemented */
795*4882a593Smuzhiyun .sw_scan_start = ath5k_sw_scan_start,
796*4882a593Smuzhiyun .sw_scan_complete = ath5k_sw_scan_complete,
797*4882a593Smuzhiyun .get_stats = ath5k_get_stats,
798*4882a593Smuzhiyun /* .set_frag_threshold = not implemented */
799*4882a593Smuzhiyun /* .set_rts_threshold = not implemented */
800*4882a593Smuzhiyun /* .sta_add = not implemented */
801*4882a593Smuzhiyun /* .sta_remove = not implemented */
802*4882a593Smuzhiyun /* .sta_notify = not implemented */
803*4882a593Smuzhiyun .conf_tx = ath5k_conf_tx,
804*4882a593Smuzhiyun .get_tsf = ath5k_get_tsf,
805*4882a593Smuzhiyun .set_tsf = ath5k_set_tsf,
806*4882a593Smuzhiyun .reset_tsf = ath5k_reset_tsf,
807*4882a593Smuzhiyun /* .tx_last_beacon = not implemented */
808*4882a593Smuzhiyun /* .ampdu_action = not needed */
809*4882a593Smuzhiyun .get_survey = ath5k_get_survey,
810*4882a593Smuzhiyun .set_coverage_class = ath5k_set_coverage_class,
811*4882a593Smuzhiyun /* .rfkill_poll = not implemented */
812*4882a593Smuzhiyun /* .flush = not implemented */
813*4882a593Smuzhiyun /* .channel_switch = not implemented */
814*4882a593Smuzhiyun /* .napi_poll = not implemented */
815*4882a593Smuzhiyun .set_antenna = ath5k_set_antenna,
816*4882a593Smuzhiyun .get_antenna = ath5k_get_antenna,
817*4882a593Smuzhiyun .set_ringparam = ath5k_set_ringparam,
818*4882a593Smuzhiyun .get_ringparam = ath5k_get_ringparam,
819*4882a593Smuzhiyun };
820