blob: 839db2312ca5a78666606224a625f75076ea690d [file] [log] [blame]
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001/*
2 * Copyright (c) 2008 Atheros Communications Inc.
3 *
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.
7 *
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.
15 */
16
17/* mac80211 and PCI callbacks */
18
19#include <linux/nl80211.h>
20#include "core.h"
21
22#define ATH_PCI_VERSION "0.1"
23
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070024static char *dev_info = "ath9k";
25
26MODULE_AUTHOR("Atheros Communications");
27MODULE_DESCRIPTION("Support for Atheros 802.11n wireless LAN cards.");
28MODULE_SUPPORTED_DEVICE("Atheros 802.11n WLAN cards");
29MODULE_LICENSE("Dual BSD/GPL");
30
31static struct pci_device_id ath_pci_id_table[] __devinitdata = {
32 { PCI_VDEVICE(ATHEROS, 0x0023) }, /* PCI */
33 { PCI_VDEVICE(ATHEROS, 0x0024) }, /* PCI-E */
34 { PCI_VDEVICE(ATHEROS, 0x0027) }, /* PCI */
35 { PCI_VDEVICE(ATHEROS, 0x0029) }, /* PCI */
36 { PCI_VDEVICE(ATHEROS, 0x002A) }, /* PCI-E */
37 { 0 }
38};
39
40static int ath_get_channel(struct ath_softc *sc,
41 struct ieee80211_channel *chan)
42{
43 int i;
44
45 for (i = 0; i < sc->sc_ah->ah_nchan; i++) {
46 if (sc->sc_ah->ah_channels[i].channel == chan->center_freq)
47 return i;
48 }
49
50 return -1;
51}
52
53static u32 ath_get_extchanmode(struct ath_softc *sc,
54 struct ieee80211_channel *chan)
55{
56 u32 chanmode = 0;
57 u8 ext_chan_offset = sc->sc_ht_info.ext_chan_offset;
58 enum ath9k_ht_macmode tx_chan_width = sc->sc_ht_info.tx_chan_width;
59
60 switch (chan->band) {
61 case IEEE80211_BAND_2GHZ:
Johannes Bergd9fe60d2008-10-09 12:13:49 +020062 if ((ext_chan_offset == IEEE80211_HT_PARAM_CHA_SEC_NONE) &&
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070063 (tx_chan_width == ATH9K_HT_MACMODE_20))
64 chanmode = CHANNEL_G_HT20;
Johannes Bergd9fe60d2008-10-09 12:13:49 +020065 if ((ext_chan_offset == IEEE80211_HT_PARAM_CHA_SEC_ABOVE) &&
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070066 (tx_chan_width == ATH9K_HT_MACMODE_2040))
67 chanmode = CHANNEL_G_HT40PLUS;
Johannes Bergd9fe60d2008-10-09 12:13:49 +020068 if ((ext_chan_offset == IEEE80211_HT_PARAM_CHA_SEC_BELOW) &&
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070069 (tx_chan_width == ATH9K_HT_MACMODE_2040))
70 chanmode = CHANNEL_G_HT40MINUS;
71 break;
72 case IEEE80211_BAND_5GHZ:
Johannes Bergd9fe60d2008-10-09 12:13:49 +020073 if ((ext_chan_offset == IEEE80211_HT_PARAM_CHA_SEC_NONE) &&
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070074 (tx_chan_width == ATH9K_HT_MACMODE_20))
75 chanmode = CHANNEL_A_HT20;
Johannes Bergd9fe60d2008-10-09 12:13:49 +020076 if ((ext_chan_offset == IEEE80211_HT_PARAM_CHA_SEC_ABOVE) &&
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070077 (tx_chan_width == ATH9K_HT_MACMODE_2040))
78 chanmode = CHANNEL_A_HT40PLUS;
Johannes Bergd9fe60d2008-10-09 12:13:49 +020079 if ((ext_chan_offset == IEEE80211_HT_PARAM_CHA_SEC_BELOW) &&
Luis R. Rodriguezf078f202008-08-04 00:16:41 -070080 (tx_chan_width == ATH9K_HT_MACMODE_2040))
81 chanmode = CHANNEL_A_HT40MINUS;
82 break;
83 default:
84 break;
85 }
86
87 return chanmode;
88}
89
90
91static int ath_setkey_tkip(struct ath_softc *sc,
92 struct ieee80211_key_conf *key,
93 struct ath9k_keyval *hk,
94 const u8 *addr)
95{
96 u8 *key_rxmic = NULL;
97 u8 *key_txmic = NULL;
98
99 key_txmic = key->key + NL80211_TKIP_DATA_OFFSET_TX_MIC_KEY;
100 key_rxmic = key->key + NL80211_TKIP_DATA_OFFSET_RX_MIC_KEY;
101
102 if (addr == NULL) {
103 /* Group key installation */
104 memcpy(hk->kv_mic, key_rxmic, sizeof(hk->kv_mic));
105 return ath_keyset(sc, key->keyidx, hk, addr);
106 }
107 if (!sc->sc_splitmic) {
108 /*
109 * data key goes at first index,
110 * the hal handles the MIC keys at index+64.
111 */
112 memcpy(hk->kv_mic, key_rxmic, sizeof(hk->kv_mic));
113 memcpy(hk->kv_txmic, key_txmic, sizeof(hk->kv_txmic));
114 return ath_keyset(sc, key->keyidx, hk, addr);
115 }
116 /*
117 * TX key goes at first index, RX key at +32.
118 * The hal handles the MIC keys at index+64.
119 */
120 memcpy(hk->kv_mic, key_txmic, sizeof(hk->kv_mic));
121 if (!ath_keyset(sc, key->keyidx, hk, NULL)) {
122 /* Txmic entry failed. No need to proceed further */
123 DPRINTF(sc, ATH_DBG_KEYCACHE,
124 "%s Setting TX MIC Key Failed\n", __func__);
125 return 0;
126 }
127
128 memcpy(hk->kv_mic, key_rxmic, sizeof(hk->kv_mic));
129 /* XXX delete tx key on failure? */
130 return ath_keyset(sc, key->keyidx+32, hk, addr);
131}
132
133static int ath_key_config(struct ath_softc *sc,
134 const u8 *addr,
135 struct ieee80211_key_conf *key)
136{
137 struct ieee80211_vif *vif;
138 struct ath9k_keyval hk;
139 const u8 *mac = NULL;
140 int ret = 0;
Johannes Berg05c914f2008-09-11 00:01:58 +0200141 enum nl80211_iftype opmode;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700142
143 memset(&hk, 0, sizeof(hk));
144
145 switch (key->alg) {
146 case ALG_WEP:
147 hk.kv_type = ATH9K_CIPHER_WEP;
148 break;
149 case ALG_TKIP:
150 hk.kv_type = ATH9K_CIPHER_TKIP;
151 break;
152 case ALG_CCMP:
153 hk.kv_type = ATH9K_CIPHER_AES_CCM;
154 break;
155 default:
156 return -EINVAL;
157 }
158
159 hk.kv_len = key->keylen;
160 memcpy(hk.kv_val, key->key, key->keylen);
161
162 if (!sc->sc_vaps[0])
163 return -EIO;
164
165 vif = sc->sc_vaps[0]->av_if_data;
166 opmode = vif->type;
167
168 /*
169 * Strategy:
170 * For _M_STA mc tx, we will not setup a key at all since we never
171 * tx mc.
172 * _M_STA mc rx, we will use the keyID.
173 * for _M_IBSS mc tx, we will use the keyID, and no macaddr.
174 * for _M_IBSS mc rx, we will alloc a slot and plumb the mac of the
175 * peer node. BUT we will plumb a cleartext key so that we can do
176 * perSta default key table lookup in software.
177 */
178 if (is_broadcast_ether_addr(addr)) {
179 switch (opmode) {
Johannes Berg05c914f2008-09-11 00:01:58 +0200180 case NL80211_IFTYPE_STATION:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700181 /* default key: could be group WPA key
182 * or could be static WEP key */
183 mac = NULL;
184 break;
Johannes Berg05c914f2008-09-11 00:01:58 +0200185 case NL80211_IFTYPE_ADHOC:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700186 break;
Johannes Berg05c914f2008-09-11 00:01:58 +0200187 case NL80211_IFTYPE_AP:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700188 break;
189 default:
190 ASSERT(0);
191 break;
192 }
193 } else {
194 mac = addr;
195 }
196
197 if (key->alg == ALG_TKIP)
198 ret = ath_setkey_tkip(sc, key, &hk, mac);
199 else
200 ret = ath_keyset(sc, key->keyidx, &hk, mac);
201
202 if (!ret)
203 return -EIO;
204
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700205 return 0;
206}
207
208static void ath_key_delete(struct ath_softc *sc, struct ieee80211_key_conf *key)
209{
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700210 int freeslot;
211
Sujithff9b6622008-08-14 13:27:16 +0530212 freeslot = (key->keyidx >= 4) ? 1 : 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700213 ath_key_reset(sc, key->keyidx, freeslot);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700214}
215
Johannes Bergd9fe60d2008-10-09 12:13:49 +0200216static void setup_ht_cap(struct ieee80211_sta_ht_cap *ht_info)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700217{
Sujith60653672008-08-14 13:28:02 +0530218#define ATH9K_HT_CAP_MAXRXAMPDU_65536 0x3 /* 2 ^ 16 */
219#define ATH9K_HT_CAP_MPDUDENSITY_8 0x6 /* 8 usec */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700220
Johannes Bergd9fe60d2008-10-09 12:13:49 +0200221 ht_info->ht_supported = true;
222 ht_info->cap = IEEE80211_HT_CAP_SUP_WIDTH_20_40 |
223 IEEE80211_HT_CAP_SM_PS |
224 IEEE80211_HT_CAP_SGI_40 |
225 IEEE80211_HT_CAP_DSSSCCK40;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700226
Sujith60653672008-08-14 13:28:02 +0530227 ht_info->ampdu_factor = ATH9K_HT_CAP_MAXRXAMPDU_65536;
228 ht_info->ampdu_density = ATH9K_HT_CAP_MPDUDENSITY_8;
Johannes Bergd9fe60d2008-10-09 12:13:49 +0200229 /* set up supported mcs set */
230 memset(&ht_info->mcs, 0, sizeof(ht_info->mcs));
231 ht_info->mcs.rx_mask[0] = 0xff;
232 ht_info->mcs.rx_mask[1] = 0xff;
233 ht_info->mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700234}
235
236static int ath_rate2idx(struct ath_softc *sc, int rate)
237{
238 int i = 0, cur_band, n_rates;
239 struct ieee80211_hw *hw = sc->hw;
240
241 cur_band = hw->conf.channel->band;
242 n_rates = sc->sbands[cur_band].n_bitrates;
243
244 for (i = 0; i < n_rates; i++) {
245 if (sc->sbands[cur_band].bitrates[i].bitrate == rate)
246 break;
247 }
248
249 /*
250 * NB:mac80211 validates rx rate index against the supported legacy rate
251 * index only (should be done against ht rates also), return the highest
252 * legacy rate index for rx rate which does not match any one of the
253 * supported basic and extended rates to make mac80211 happy.
254 * The following hack will be cleaned up once the issue with
255 * the rx rate index validation in mac80211 is fixed.
256 */
257 if (i == n_rates)
258 return n_rates - 1;
259 return i;
260}
261
262static void ath9k_rx_prepare(struct ath_softc *sc,
263 struct sk_buff *skb,
264 struct ath_recv_status *status,
265 struct ieee80211_rx_status *rx_status)
266{
267 struct ieee80211_hw *hw = sc->hw;
268 struct ieee80211_channel *curchan = hw->conf.channel;
269
270 memset(rx_status, 0, sizeof(struct ieee80211_rx_status));
271
272 rx_status->mactime = status->tsf;
273 rx_status->band = curchan->band;
274 rx_status->freq = curchan->center_freq;
Luis R. Rodriguez6f255422008-10-03 15:45:27 -0700275 rx_status->noise = sc->sc_ani.sc_noise_floor;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700276 rx_status->signal = rx_status->noise + status->rssi;
277 rx_status->rate_idx = ath_rate2idx(sc, (status->rateKbps / 100));
278 rx_status->antenna = status->antenna;
Luis R. Rodriguez6f255422008-10-03 15:45:27 -0700279
Luis R. Rodriguezc49d1542008-10-13 14:08:09 -0700280 /* at 45 you will be able to use MCS 15 reliably. A more elaborate
281 * scheme can be used here but it requires tables of SNR/throughput for
282 * each possible mode used. */
283 rx_status->qual = status->rssi * 100 / 45;
284
285 /* rssi can be more than 45 though, anything above that
286 * should be considered at 100% */
287 if (rx_status->qual > 100)
288 rx_status->qual = 100;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700289
290 if (status->flags & ATH_RX_MIC_ERROR)
291 rx_status->flag |= RX_FLAG_MMIC_ERROR;
292 if (status->flags & ATH_RX_FCS_ERROR)
293 rx_status->flag |= RX_FLAG_FAILED_FCS_CRC;
294
295 rx_status->flag |= RX_FLAG_TSFT;
296}
297
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +0530298static void ath9k_ht_conf(struct ath_softc *sc,
299 struct ieee80211_bss_conf *bss_conf)
300{
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +0530301 struct ath_ht_info *ht_info = &sc->sc_ht_info;
302
Johannes Bergae5eb022008-10-14 16:58:37 +0200303 if (sc->hw->conf.ht.enabled) {
304 ht_info->ext_chan_offset = bss_conf->ht.secondary_channel_offset;
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +0530305
Johannes Bergae5eb022008-10-14 16:58:37 +0200306 if (bss_conf->ht.width_40_ok)
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +0530307 ht_info->tx_chan_width = ATH9K_HT_MACMODE_2040;
308 else
309 ht_info->tx_chan_width = ATH9K_HT_MACMODE_20;
310
311 ath9k_hw_set11nmac2040(sc->sc_ah, ht_info->tx_chan_width);
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +0530312 }
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +0530313}
314
315static void ath9k_bss_assoc_info(struct ath_softc *sc,
316 struct ieee80211_bss_conf *bss_conf)
317{
318 struct ieee80211_hw *hw = sc->hw;
319 struct ieee80211_channel *curchan = hw->conf.channel;
320 struct ath_vap *avp;
321 int pos;
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +0530322
323 if (bss_conf->assoc) {
324 DPRINTF(sc, ATH_DBG_CONFIG, "%s: Bss Info ASSOC %d\n",
325 __func__,
326 bss_conf->aid);
327
328 avp = sc->sc_vaps[0];
329 if (avp == NULL) {
330 DPRINTF(sc, ATH_DBG_FATAL, "%s: Invalid interface\n",
331 __func__);
332 return;
333 }
334
335 /* New association, store aid */
336 if (avp->av_opmode == ATH9K_M_STA) {
337 sc->sc_curaid = bss_conf->aid;
338 ath9k_hw_write_associd(sc->sc_ah, sc->sc_curbssid,
339 sc->sc_curaid);
340 }
341
342 /* Configure the beacon */
343 ath_beacon_config(sc, 0);
344 sc->sc_flags |= SC_OP_BEACONS;
345
346 /* Reset rssi stats */
347 sc->sc_halstats.ns_avgbrssi = ATH_RSSI_DUMMY_MARKER;
348 sc->sc_halstats.ns_avgrssi = ATH_RSSI_DUMMY_MARKER;
349 sc->sc_halstats.ns_avgtxrssi = ATH_RSSI_DUMMY_MARKER;
350 sc->sc_halstats.ns_avgtxrate = ATH_RATE_DUMMY_MARKER;
351
352 /* Update chainmask */
Johannes Bergae5eb022008-10-14 16:58:37 +0200353 ath_update_chainmask(sc, hw->conf.ht.enabled);
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +0530354
355 DPRINTF(sc, ATH_DBG_CONFIG,
Johannes Berge1749612008-10-27 15:59:26 -0700356 "%s: bssid %pM aid 0x%x\n",
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +0530357 __func__,
Johannes Berge1749612008-10-27 15:59:26 -0700358 sc->sc_curbssid, sc->sc_curaid);
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +0530359
360 DPRINTF(sc, ATH_DBG_CONFIG, "%s: Set channel: %d MHz\n",
361 __func__,
362 curchan->center_freq);
363
364 pos = ath_get_channel(sc, curchan);
365 if (pos == -1) {
366 DPRINTF(sc, ATH_DBG_FATAL,
367 "%s: Invalid channel\n", __func__);
368 return;
369 }
370
Johannes Bergae5eb022008-10-14 16:58:37 +0200371 if (hw->conf.ht.enabled)
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +0530372 sc->sc_ah->ah_channels[pos].chanmode =
373 ath_get_extchanmode(sc, curchan);
374 else
375 sc->sc_ah->ah_channels[pos].chanmode =
376 (curchan->band == IEEE80211_BAND_2GHZ) ?
377 CHANNEL_G : CHANNEL_A;
378
379 /* set h/w channel */
380 if (ath_set_channel(sc, &sc->sc_ah->ah_channels[pos]) < 0)
381 DPRINTF(sc, ATH_DBG_FATAL,
382 "%s: Unable to set channel\n",
383 __func__);
384
385 ath_rate_newstate(sc, avp);
386 /* Update ratectrl about the new state */
387 ath_rc_node_update(hw, avp->rc_node);
Luis R. Rodriguez6f255422008-10-03 15:45:27 -0700388
389 /* Start ANI */
390 mod_timer(&sc->sc_ani.timer,
391 jiffies + msecs_to_jiffies(ATH_ANI_POLLINTERVAL));
392
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +0530393 } else {
394 DPRINTF(sc, ATH_DBG_CONFIG,
395 "%s: Bss Info DISSOC\n", __func__);
396 sc->sc_curaid = 0;
397 }
398}
399
400void ath_get_beaconconfig(struct ath_softc *sc,
401 int if_id,
402 struct ath_beacon_config *conf)
403{
404 struct ieee80211_hw *hw = sc->hw;
405
406 /* fill in beacon config data */
407
408 conf->beacon_interval = hw->conf.beacon_int;
409 conf->listen_interval = 100;
410 conf->dtim_count = 1;
411 conf->bmiss_timeout = ATH_DEFAULT_BMISS_LIMIT * conf->listen_interval;
412}
413
414void ath_tx_complete(struct ath_softc *sc, struct sk_buff *skb,
Sujith528f0c62008-10-29 10:14:26 +0530415 struct ath_xmit_status *tx_status)
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +0530416{
417 struct ieee80211_hw *hw = sc->hw;
418 struct ieee80211_tx_info *tx_info = IEEE80211_SKB_CB(skb);
419
420 DPRINTF(sc, ATH_DBG_XMIT,
421 "%s: TX complete: skb: %p\n", __func__, skb);
422
Johannes Berge6a98542008-10-21 12:40:02 +0200423 ieee80211_tx_info_clear_status(tx_info);
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +0530424 if (tx_info->flags & IEEE80211_TX_CTL_NO_ACK ||
425 tx_info->flags & IEEE80211_TX_STAT_TX_FILTERED) {
Johannes Berge6a98542008-10-21 12:40:02 +0200426 /* free driver's private data area of tx_info, XXX: HACK! */
427 if (tx_info->control.vif != NULL)
428 kfree(tx_info->control.vif);
429 tx_info->control.vif = NULL;
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +0530430 }
431
432 if (tx_status->flags & ATH_TX_BAR) {
433 tx_info->flags |= IEEE80211_TX_STAT_AMPDU_NO_BACK;
434 tx_status->flags &= ~ATH_TX_BAR;
435 }
436
Johannes Berge6a98542008-10-21 12:40:02 +0200437 if (!(tx_status->flags & (ATH_TX_ERROR | ATH_TX_XRETRY))) {
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +0530438 /* Frame was ACKed */
439 tx_info->flags |= IEEE80211_TX_STAT_ACK;
440 }
441
Johannes Berge6a98542008-10-21 12:40:02 +0200442 tx_info->status.rates[0].count = tx_status->retries + 1;
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +0530443
444 ieee80211_tx_status(hw, skb);
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +0530445}
446
447int _ath_rx_indicate(struct ath_softc *sc,
448 struct sk_buff *skb,
449 struct ath_recv_status *status,
450 u16 keyix)
451{
452 struct ieee80211_hw *hw = sc->hw;
453 struct ath_node *an = NULL;
454 struct ieee80211_rx_status rx_status;
455 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
456 int hdrlen = ieee80211_get_hdrlen_from_skb(skb);
457 int padsize;
458 enum ATH_RX_TYPE st;
459
460 /* see if any padding is done by the hw and remove it */
461 if (hdrlen & 3) {
462 padsize = hdrlen % 4;
463 memmove(skb->data + padsize, skb->data, hdrlen);
464 skb_pull(skb, padsize);
465 }
466
467 /* Prepare rx status */
468 ath9k_rx_prepare(sc, skb, status, &rx_status);
469
470 if (!(keyix == ATH9K_RXKEYIX_INVALID) &&
471 !(status->flags & ATH_RX_DECRYPT_ERROR)) {
472 rx_status.flag |= RX_FLAG_DECRYPTED;
473 } else if ((le16_to_cpu(hdr->frame_control) & IEEE80211_FCTL_PROTECTED)
474 && !(status->flags & ATH_RX_DECRYPT_ERROR)
475 && skb->len >= hdrlen + 4) {
476 keyix = skb->data[hdrlen + 3] >> 6;
477
478 if (test_bit(keyix, sc->sc_keymap))
479 rx_status.flag |= RX_FLAG_DECRYPTED;
480 }
481
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +0530482 if (an) {
483 ath_rx_input(sc, an,
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +0530484 skb, status, &st);
485 }
486 if (!an || (st != ATH_RX_CONSUMED))
487 __ieee80211_rx(hw, skb, &rx_status);
488
489 return 0;
490}
491
492int ath_rx_subframe(struct ath_node *an,
493 struct sk_buff *skb,
494 struct ath_recv_status *status)
495{
496 struct ath_softc *sc = an->an_sc;
497 struct ieee80211_hw *hw = sc->hw;
498 struct ieee80211_rx_status rx_status;
499
500 /* Prepare rx status */
501 ath9k_rx_prepare(sc, skb, status, &rx_status);
502 if (!(status->flags & ATH_RX_DECRYPT_ERROR))
503 rx_status.flag |= RX_FLAG_DECRYPTED;
504
505 __ieee80211_rx(hw, skb, &rx_status);
506
507 return 0;
508}
509
510/********************************/
511/* LED functions */
512/********************************/
513
514static void ath_led_brightness(struct led_classdev *led_cdev,
515 enum led_brightness brightness)
516{
517 struct ath_led *led = container_of(led_cdev, struct ath_led, led_cdev);
518 struct ath_softc *sc = led->sc;
519
520 switch (brightness) {
521 case LED_OFF:
522 if (led->led_type == ATH_LED_ASSOC ||
523 led->led_type == ATH_LED_RADIO)
524 sc->sc_flags &= ~SC_OP_LED_ASSOCIATED;
525 ath9k_hw_set_gpio(sc->sc_ah, ATH_LED_PIN,
526 (led->led_type == ATH_LED_RADIO) ? 1 :
527 !!(sc->sc_flags & SC_OP_LED_ASSOCIATED));
528 break;
529 case LED_FULL:
530 if (led->led_type == ATH_LED_ASSOC)
531 sc->sc_flags |= SC_OP_LED_ASSOCIATED;
532 ath9k_hw_set_gpio(sc->sc_ah, ATH_LED_PIN, 0);
533 break;
534 default:
535 break;
536 }
537}
538
539static int ath_register_led(struct ath_softc *sc, struct ath_led *led,
540 char *trigger)
541{
542 int ret;
543
544 led->sc = sc;
545 led->led_cdev.name = led->name;
546 led->led_cdev.default_trigger = trigger;
547 led->led_cdev.brightness_set = ath_led_brightness;
548
549 ret = led_classdev_register(wiphy_dev(sc->hw->wiphy), &led->led_cdev);
550 if (ret)
551 DPRINTF(sc, ATH_DBG_FATAL,
552 "Failed to register led:%s", led->name);
553 else
554 led->registered = 1;
555 return ret;
556}
557
558static void ath_unregister_led(struct ath_led *led)
559{
560 if (led->registered) {
561 led_classdev_unregister(&led->led_cdev);
562 led->registered = 0;
563 }
564}
565
566static void ath_deinit_leds(struct ath_softc *sc)
567{
568 ath_unregister_led(&sc->assoc_led);
569 sc->sc_flags &= ~SC_OP_LED_ASSOCIATED;
570 ath_unregister_led(&sc->tx_led);
571 ath_unregister_led(&sc->rx_led);
572 ath_unregister_led(&sc->radio_led);
573 ath9k_hw_set_gpio(sc->sc_ah, ATH_LED_PIN, 1);
574}
575
576static void ath_init_leds(struct ath_softc *sc)
577{
578 char *trigger;
579 int ret;
580
581 /* Configure gpio 1 for output */
582 ath9k_hw_cfg_output(sc->sc_ah, ATH_LED_PIN,
583 AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
584 /* LED off, active low */
585 ath9k_hw_set_gpio(sc->sc_ah, ATH_LED_PIN, 1);
586
587 trigger = ieee80211_get_radio_led_name(sc->hw);
588 snprintf(sc->radio_led.name, sizeof(sc->radio_led.name),
589 "ath9k-%s:radio", wiphy_name(sc->hw->wiphy));
590 ret = ath_register_led(sc, &sc->radio_led, trigger);
591 sc->radio_led.led_type = ATH_LED_RADIO;
592 if (ret)
593 goto fail;
594
595 trigger = ieee80211_get_assoc_led_name(sc->hw);
596 snprintf(sc->assoc_led.name, sizeof(sc->assoc_led.name),
597 "ath9k-%s:assoc", wiphy_name(sc->hw->wiphy));
598 ret = ath_register_led(sc, &sc->assoc_led, trigger);
599 sc->assoc_led.led_type = ATH_LED_ASSOC;
600 if (ret)
601 goto fail;
602
603 trigger = ieee80211_get_tx_led_name(sc->hw);
604 snprintf(sc->tx_led.name, sizeof(sc->tx_led.name),
605 "ath9k-%s:tx", wiphy_name(sc->hw->wiphy));
606 ret = ath_register_led(sc, &sc->tx_led, trigger);
607 sc->tx_led.led_type = ATH_LED_TX;
608 if (ret)
609 goto fail;
610
611 trigger = ieee80211_get_rx_led_name(sc->hw);
612 snprintf(sc->rx_led.name, sizeof(sc->rx_led.name),
613 "ath9k-%s:rx", wiphy_name(sc->hw->wiphy));
614 ret = ath_register_led(sc, &sc->rx_led, trigger);
615 sc->rx_led.led_type = ATH_LED_RX;
616 if (ret)
617 goto fail;
618
619 return;
620
621fail:
622 ath_deinit_leds(sc);
623}
624
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +0530625#ifdef CONFIG_RFKILL
626/*******************/
627/* Rfkill */
628/*******************/
629
630static void ath_radio_enable(struct ath_softc *sc)
631{
632 struct ath_hal *ah = sc->sc_ah;
633 int status;
634
635 spin_lock_bh(&sc->sc_resetlock);
636 if (!ath9k_hw_reset(ah, ah->ah_curchan,
637 sc->sc_ht_info.tx_chan_width,
638 sc->sc_tx_chainmask,
639 sc->sc_rx_chainmask,
640 sc->sc_ht_extprotspacing,
641 false, &status)) {
642 DPRINTF(sc, ATH_DBG_FATAL,
643 "%s: unable to reset channel %u (%uMhz) "
644 "flags 0x%x hal status %u\n", __func__,
645 ath9k_hw_mhz2ieee(ah,
646 ah->ah_curchan->channel,
647 ah->ah_curchan->channelFlags),
648 ah->ah_curchan->channel,
649 ah->ah_curchan->channelFlags, status);
650 }
651 spin_unlock_bh(&sc->sc_resetlock);
652
653 ath_update_txpow(sc);
654 if (ath_startrecv(sc) != 0) {
655 DPRINTF(sc, ATH_DBG_FATAL,
656 "%s: unable to restart recv logic\n", __func__);
657 return;
658 }
659
660 if (sc->sc_flags & SC_OP_BEACONS)
661 ath_beacon_config(sc, ATH_IF_ID_ANY); /* restart beacons */
662
663 /* Re-Enable interrupts */
664 ath9k_hw_set_interrupts(ah, sc->sc_imask);
665
666 /* Enable LED */
667 ath9k_hw_cfg_output(ah, ATH_LED_PIN,
668 AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
669 ath9k_hw_set_gpio(ah, ATH_LED_PIN, 0);
670
671 ieee80211_wake_queues(sc->hw);
672}
673
674static void ath_radio_disable(struct ath_softc *sc)
675{
676 struct ath_hal *ah = sc->sc_ah;
677 int status;
678
679
680 ieee80211_stop_queues(sc->hw);
681
682 /* Disable LED */
683 ath9k_hw_set_gpio(ah, ATH_LED_PIN, 1);
684 ath9k_hw_cfg_gpio_input(ah, ATH_LED_PIN);
685
686 /* Disable interrupts */
687 ath9k_hw_set_interrupts(ah, 0);
688
689 ath_draintxq(sc, false); /* clear pending tx frames */
690 ath_stoprecv(sc); /* turn off frame recv */
691 ath_flushrecv(sc); /* flush recv queue */
692
693 spin_lock_bh(&sc->sc_resetlock);
694 if (!ath9k_hw_reset(ah, ah->ah_curchan,
695 sc->sc_ht_info.tx_chan_width,
696 sc->sc_tx_chainmask,
697 sc->sc_rx_chainmask,
698 sc->sc_ht_extprotspacing,
699 false, &status)) {
700 DPRINTF(sc, ATH_DBG_FATAL,
701 "%s: unable to reset channel %u (%uMhz) "
702 "flags 0x%x hal status %u\n", __func__,
703 ath9k_hw_mhz2ieee(ah,
704 ah->ah_curchan->channel,
705 ah->ah_curchan->channelFlags),
706 ah->ah_curchan->channel,
707 ah->ah_curchan->channelFlags, status);
708 }
709 spin_unlock_bh(&sc->sc_resetlock);
710
711 ath9k_hw_phy_disable(ah);
712 ath9k_hw_setpower(ah, ATH9K_PM_FULL_SLEEP);
713}
714
715static bool ath_is_rfkill_set(struct ath_softc *sc)
716{
717 struct ath_hal *ah = sc->sc_ah;
718
719 return ath9k_hw_gpio_get(ah, ah->ah_rfkill_gpio) ==
720 ah->ah_rfkill_polarity;
721}
722
723/* h/w rfkill poll function */
724static void ath_rfkill_poll(struct work_struct *work)
725{
726 struct ath_softc *sc = container_of(work, struct ath_softc,
727 rf_kill.rfkill_poll.work);
728 bool radio_on;
729
730 if (sc->sc_flags & SC_OP_INVALID)
731 return;
732
733 radio_on = !ath_is_rfkill_set(sc);
734
735 /*
736 * enable/disable radio only when there is a
737 * state change in RF switch
738 */
739 if (radio_on == !!(sc->sc_flags & SC_OP_RFKILL_HW_BLOCKED)) {
740 enum rfkill_state state;
741
742 if (sc->sc_flags & SC_OP_RFKILL_SW_BLOCKED) {
743 state = radio_on ? RFKILL_STATE_SOFT_BLOCKED
744 : RFKILL_STATE_HARD_BLOCKED;
745 } else if (radio_on) {
746 ath_radio_enable(sc);
747 state = RFKILL_STATE_UNBLOCKED;
748 } else {
749 ath_radio_disable(sc);
750 state = RFKILL_STATE_HARD_BLOCKED;
751 }
752
753 if (state == RFKILL_STATE_HARD_BLOCKED)
754 sc->sc_flags |= SC_OP_RFKILL_HW_BLOCKED;
755 else
756 sc->sc_flags &= ~SC_OP_RFKILL_HW_BLOCKED;
757
758 rfkill_force_state(sc->rf_kill.rfkill, state);
759 }
760
761 queue_delayed_work(sc->hw->workqueue, &sc->rf_kill.rfkill_poll,
762 msecs_to_jiffies(ATH_RFKILL_POLL_INTERVAL));
763}
764
765/* s/w rfkill handler */
766static int ath_sw_toggle_radio(void *data, enum rfkill_state state)
767{
768 struct ath_softc *sc = data;
769
770 switch (state) {
771 case RFKILL_STATE_SOFT_BLOCKED:
772 if (!(sc->sc_flags & (SC_OP_RFKILL_HW_BLOCKED |
773 SC_OP_RFKILL_SW_BLOCKED)))
774 ath_radio_disable(sc);
775 sc->sc_flags |= SC_OP_RFKILL_SW_BLOCKED;
776 return 0;
777 case RFKILL_STATE_UNBLOCKED:
778 if ((sc->sc_flags & SC_OP_RFKILL_SW_BLOCKED)) {
779 sc->sc_flags &= ~SC_OP_RFKILL_SW_BLOCKED;
780 if (sc->sc_flags & SC_OP_RFKILL_HW_BLOCKED) {
781 DPRINTF(sc, ATH_DBG_FATAL, "Can't turn on the"
782 "radio as it is disabled by h/w \n");
783 return -EPERM;
784 }
785 ath_radio_enable(sc);
786 }
787 return 0;
788 default:
789 return -EINVAL;
790 }
791}
792
793/* Init s/w rfkill */
794static int ath_init_sw_rfkill(struct ath_softc *sc)
795{
796 sc->rf_kill.rfkill = rfkill_allocate(wiphy_dev(sc->hw->wiphy),
797 RFKILL_TYPE_WLAN);
798 if (!sc->rf_kill.rfkill) {
799 DPRINTF(sc, ATH_DBG_FATAL, "Failed to allocate rfkill\n");
800 return -ENOMEM;
801 }
802
803 snprintf(sc->rf_kill.rfkill_name, sizeof(sc->rf_kill.rfkill_name),
804 "ath9k-%s:rfkill", wiphy_name(sc->hw->wiphy));
805 sc->rf_kill.rfkill->name = sc->rf_kill.rfkill_name;
806 sc->rf_kill.rfkill->data = sc;
807 sc->rf_kill.rfkill->toggle_radio = ath_sw_toggle_radio;
808 sc->rf_kill.rfkill->state = RFKILL_STATE_UNBLOCKED;
809 sc->rf_kill.rfkill->user_claim_unsupported = 1;
810
811 return 0;
812}
813
814/* Deinitialize rfkill */
815static void ath_deinit_rfkill(struct ath_softc *sc)
816{
817 if (sc->sc_ah->ah_caps.hw_caps & ATH9K_HW_CAP_RFSILENT)
818 cancel_delayed_work_sync(&sc->rf_kill.rfkill_poll);
819
820 if (sc->sc_flags & SC_OP_RFKILL_REGISTERED) {
821 rfkill_unregister(sc->rf_kill.rfkill);
822 sc->sc_flags &= ~SC_OP_RFKILL_REGISTERED;
823 sc->rf_kill.rfkill = NULL;
824 }
825}
826#endif /* CONFIG_RFKILL */
827
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +0530828static int ath_detach(struct ath_softc *sc)
829{
830 struct ieee80211_hw *hw = sc->hw;
831
832 DPRINTF(sc, ATH_DBG_CONFIG, "%s: Detach ATH hw\n", __func__);
833
834 /* Deinit LED control */
835 ath_deinit_leds(sc);
836
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +0530837#ifdef CONFIG_RFKILL
838 /* deinit rfkill */
839 ath_deinit_rfkill(sc);
840#endif
841
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +0530842 /* Unregister hw */
843
844 ieee80211_unregister_hw(hw);
845
846 /* unregister Rate control */
847 ath_rate_control_unregister();
848
849 /* tx/rx cleanup */
850
851 ath_rx_cleanup(sc);
852 ath_tx_cleanup(sc);
853
854 /* Deinit */
855
856 ath_deinit(sc);
857
858 return 0;
859}
860
861static int ath_attach(u16 devid,
862 struct ath_softc *sc)
863{
864 struct ieee80211_hw *hw = sc->hw;
865 int error = 0;
866
867 DPRINTF(sc, ATH_DBG_CONFIG, "%s: Attach ATH hw\n", __func__);
868
869 error = ath_init(devid, sc);
870 if (error != 0)
871 return error;
872
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +0530873 /* get mac address from hardware and set in mac80211 */
874
875 SET_IEEE80211_PERM_ADDR(hw, sc->sc_myaddr);
876
877 /* setup channels and rates */
878
879 sc->sbands[IEEE80211_BAND_2GHZ].channels =
880 sc->channels[IEEE80211_BAND_2GHZ];
881 sc->sbands[IEEE80211_BAND_2GHZ].bitrates =
882 sc->rates[IEEE80211_BAND_2GHZ];
883 sc->sbands[IEEE80211_BAND_2GHZ].band = IEEE80211_BAND_2GHZ;
884
885 if (sc->sc_ah->ah_caps.hw_caps & ATH9K_HW_CAP_HT)
886 /* Setup HT capabilities for 2.4Ghz*/
Johannes Bergd9fe60d2008-10-09 12:13:49 +0200887 setup_ht_cap(&sc->sbands[IEEE80211_BAND_2GHZ].ht_cap);
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +0530888
889 hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
890 &sc->sbands[IEEE80211_BAND_2GHZ];
891
892 if (test_bit(ATH9K_MODE_11A, sc->sc_ah->ah_caps.wireless_modes)) {
893 sc->sbands[IEEE80211_BAND_5GHZ].channels =
894 sc->channels[IEEE80211_BAND_5GHZ];
895 sc->sbands[IEEE80211_BAND_5GHZ].bitrates =
896 sc->rates[IEEE80211_BAND_5GHZ];
897 sc->sbands[IEEE80211_BAND_5GHZ].band =
898 IEEE80211_BAND_5GHZ;
899
900 if (sc->sc_ah->ah_caps.hw_caps & ATH9K_HW_CAP_HT)
901 /* Setup HT capabilities for 5Ghz*/
Johannes Bergd9fe60d2008-10-09 12:13:49 +0200902 setup_ht_cap(&sc->sbands[IEEE80211_BAND_5GHZ].ht_cap);
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +0530903
904 hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
905 &sc->sbands[IEEE80211_BAND_5GHZ];
906 }
907
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +0530908 hw->queues = 4;
Sujith528f0c62008-10-29 10:14:26 +0530909 hw->sta_data_size = sizeof(struct ath_node);
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +0530910
911 /* Register rate control */
912 hw->rate_control_algorithm = "ath9k_rate_control";
913 error = ath_rate_control_register();
914 if (error != 0) {
915 DPRINTF(sc, ATH_DBG_FATAL,
916 "%s: Unable to register rate control "
917 "algorithm:%d\n", __func__, error);
918 ath_rate_control_unregister();
919 goto bad;
920 }
921
922 error = ieee80211_register_hw(hw);
923 if (error != 0) {
924 ath_rate_control_unregister();
925 goto bad;
926 }
927
928 /* Initialize LED control */
929 ath_init_leds(sc);
930
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +0530931#ifdef CONFIG_RFKILL
932 /* Initialze h/w Rfkill */
933 if (sc->sc_ah->ah_caps.hw_caps & ATH9K_HW_CAP_RFSILENT)
934 INIT_DELAYED_WORK(&sc->rf_kill.rfkill_poll, ath_rfkill_poll);
935
936 /* Initialize s/w rfkill */
937 if (ath_init_sw_rfkill(sc))
938 goto detach;
939#endif
940
Vasanthakumar Thiagarajan8feceb62008-09-10 18:49:27 +0530941 /* initialize tx/rx engine */
942
943 error = ath_tx_init(sc, ATH_TXBUF);
944 if (error != 0)
945 goto detach;
946
947 error = ath_rx_init(sc, ATH_RXBUF);
948 if (error != 0)
949 goto detach;
950
951 return 0;
952detach:
953 ath_detach(sc);
954bad:
955 return error;
956}
957
Luis R. Rodriguezf078f202008-08-04 00:16:41 -0700958static int ath9k_start(struct ieee80211_hw *hw)
959{
960 struct ath_softc *sc = hw->priv;
961 struct ieee80211_channel *curchan = hw->conf.channel;
962 int error = 0, pos;
963
964 DPRINTF(sc, ATH_DBG_CONFIG, "%s: Starting driver with "
965 "initial channel: %d MHz\n", __func__, curchan->center_freq);
966
967 /* setup initial channel */
968
969 pos = ath_get_channel(sc, curchan);
970 if (pos == -1) {
971 DPRINTF(sc, ATH_DBG_FATAL, "%s: Invalid channel\n", __func__);
972 return -EINVAL;
973 }
974
975 sc->sc_ah->ah_channels[pos].chanmode =
976 (curchan->band == IEEE80211_BAND_2GHZ) ? CHANNEL_G : CHANNEL_A;
977
978 /* open ath_dev */
979 error = ath_open(sc, &sc->sc_ah->ah_channels[pos]);
980 if (error) {
981 DPRINTF(sc, ATH_DBG_FATAL,
982 "%s: Unable to complete ath_open\n", __func__);
983 return error;
984 }
985
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +0530986#ifdef CONFIG_RFKILL
987 /* Start rfkill polling */
988 if (sc->sc_ah->ah_caps.hw_caps & ATH9K_HW_CAP_RFSILENT)
989 queue_delayed_work(sc->hw->workqueue,
990 &sc->rf_kill.rfkill_poll, 0);
991
992 if (!(sc->sc_flags & SC_OP_RFKILL_REGISTERED)) {
993 if (rfkill_register(sc->rf_kill.rfkill)) {
994 DPRINTF(sc, ATH_DBG_FATAL,
995 "Unable to register rfkill\n");
996 rfkill_free(sc->rf_kill.rfkill);
997
998 /* Deinitialize the device */
999 if (sc->pdev->irq)
1000 free_irq(sc->pdev->irq, sc);
1001 ath_detach(sc);
1002 pci_iounmap(sc->pdev, sc->mem);
1003 pci_release_region(sc->pdev, 0);
1004 pci_disable_device(sc->pdev);
1005 ieee80211_free_hw(hw);
1006 return -EIO;
1007 } else {
1008 sc->sc_flags |= SC_OP_RFKILL_REGISTERED;
1009 }
1010 }
1011#endif
1012
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001013 ieee80211_wake_queues(hw);
1014 return 0;
1015}
1016
1017static int ath9k_tx(struct ieee80211_hw *hw,
1018 struct sk_buff *skb)
1019{
Jouni Malinen147583c2008-08-11 14:01:50 +03001020 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
Sujith528f0c62008-10-29 10:14:26 +05301021 struct ath_softc *sc = hw->priv;
1022 struct ath_tx_control txctl;
1023 int hdrlen, padsize;
1024
1025 memset(&txctl, 0, sizeof(struct ath_tx_control));
Jouni Malinen147583c2008-08-11 14:01:50 +03001026
1027 /*
1028 * As a temporary workaround, assign seq# here; this will likely need
1029 * to be cleaned up to work better with Beacon transmission and virtual
1030 * BSSes.
1031 */
1032 if (info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) {
1033 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
1034 if (info->flags & IEEE80211_TX_CTL_FIRST_FRAGMENT)
1035 sc->seq_no += 0x10;
1036 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
1037 hdr->seq_ctrl |= cpu_to_le16(sc->seq_no);
1038 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001039
1040 /* Add the padding after the header if this is not already done */
1041 hdrlen = ieee80211_get_hdrlen_from_skb(skb);
1042 if (hdrlen & 3) {
1043 padsize = hdrlen % 4;
1044 if (skb_headroom(skb) < padsize)
1045 return -1;
1046 skb_push(skb, padsize);
1047 memmove(skb->data, skb->data + padsize, hdrlen);
1048 }
1049
Sujith528f0c62008-10-29 10:14:26 +05301050 /* Check if a tx queue is available */
1051
1052 txctl.txq = ath_test_get_txq(sc, skb);
1053 if (!txctl.txq)
1054 goto exit;
1055
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001056 DPRINTF(sc, ATH_DBG_XMIT, "%s: transmitting packet, skb: %p\n",
1057 __func__,
1058 skb);
1059
Sujith528f0c62008-10-29 10:14:26 +05301060 if (ath_tx_start(sc, skb, &txctl) != 0) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001061 DPRINTF(sc, ATH_DBG_XMIT, "%s: TX failed\n", __func__);
Sujith528f0c62008-10-29 10:14:26 +05301062 goto exit;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001063 }
1064
1065 return 0;
Sujith528f0c62008-10-29 10:14:26 +05301066exit:
1067 dev_kfree_skb_any(skb);
1068 return 0;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001069}
1070
1071static void ath9k_stop(struct ieee80211_hw *hw)
1072{
1073 struct ath_softc *sc = hw->priv;
1074 int error;
1075
1076 DPRINTF(sc, ATH_DBG_CONFIG, "%s: Driver halt\n", __func__);
1077
1078 error = ath_suspend(sc);
1079 if (error)
1080 DPRINTF(sc, ATH_DBG_CONFIG,
1081 "%s: Device is no longer present\n", __func__);
1082
1083 ieee80211_stop_queues(hw);
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301084
1085#ifdef CONFIG_RFKILL
1086 if (sc->sc_ah->ah_caps.hw_caps & ATH9K_HW_CAP_RFSILENT)
1087 cancel_delayed_work_sync(&sc->rf_kill.rfkill_poll);
1088#endif
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001089}
1090
1091static int ath9k_add_interface(struct ieee80211_hw *hw,
1092 struct ieee80211_if_init_conf *conf)
1093{
1094 struct ath_softc *sc = hw->priv;
1095 int error, ic_opmode = 0;
1096
1097 /* Support only vap for now */
1098
1099 if (sc->sc_nvaps)
1100 return -ENOBUFS;
1101
1102 switch (conf->type) {
Johannes Berg05c914f2008-09-11 00:01:58 +02001103 case NL80211_IFTYPE_STATION:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001104 ic_opmode = ATH9K_M_STA;
1105 break;
Johannes Berg05c914f2008-09-11 00:01:58 +02001106 case NL80211_IFTYPE_ADHOC:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001107 ic_opmode = ATH9K_M_IBSS;
1108 break;
Johannes Berg05c914f2008-09-11 00:01:58 +02001109 case NL80211_IFTYPE_AP:
Jouni Malinen2ad67de2008-08-11 14:01:47 +03001110 ic_opmode = ATH9K_M_HOSTAP;
1111 break;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001112 default:
1113 DPRINTF(sc, ATH_DBG_FATAL,
Jouni Malinen2ad67de2008-08-11 14:01:47 +03001114 "%s: Interface type %d not yet supported\n",
1115 __func__, conf->type);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001116 return -EOPNOTSUPP;
1117 }
1118
1119 DPRINTF(sc, ATH_DBG_CONFIG, "%s: Attach a VAP of type: %d\n",
1120 __func__,
1121 ic_opmode);
1122
1123 error = ath_vap_attach(sc, 0, conf->vif, ic_opmode);
1124 if (error) {
1125 DPRINTF(sc, ATH_DBG_FATAL,
1126 "%s: Unable to attach vap, error: %d\n",
1127 __func__, error);
1128 return error;
1129 }
1130
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07001131 if (conf->type == NL80211_IFTYPE_AP) {
1132 /* TODO: is this a suitable place to start ANI for AP mode? */
1133 /* Start ANI */
1134 mod_timer(&sc->sc_ani.timer,
1135 jiffies + msecs_to_jiffies(ATH_ANI_POLLINTERVAL));
1136 }
1137
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001138 return 0;
1139}
1140
1141static void ath9k_remove_interface(struct ieee80211_hw *hw,
1142 struct ieee80211_if_init_conf *conf)
1143{
1144 struct ath_softc *sc = hw->priv;
1145 struct ath_vap *avp;
1146 int error;
1147
1148 DPRINTF(sc, ATH_DBG_CONFIG, "%s: Detach VAP\n", __func__);
1149
1150 avp = sc->sc_vaps[0];
1151 if (avp == NULL) {
1152 DPRINTF(sc, ATH_DBG_FATAL, "%s: Invalid interface\n",
1153 __func__);
1154 return;
1155 }
1156
1157#ifdef CONFIG_SLOW_ANT_DIV
1158 ath_slow_ant_div_stop(&sc->sc_antdiv);
1159#endif
Luis R. Rodriguez6f255422008-10-03 15:45:27 -07001160 /* Stop ANI */
1161 del_timer_sync(&sc->sc_ani.timer);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001162
1163 /* Update ratectrl */
1164 ath_rate_newstate(sc, avp);
1165
1166 /* Reclaim beacon resources */
Sujithb4696c8b2008-08-11 14:04:52 +05301167 if (sc->sc_ah->ah_opmode == ATH9K_M_HOSTAP ||
1168 sc->sc_ah->ah_opmode == ATH9K_M_IBSS) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001169 ath9k_hw_stoptxdma(sc->sc_ah, sc->sc_bhalq);
1170 ath_beacon_return(sc, avp);
1171 }
1172
1173 /* Set interrupt mask */
1174 sc->sc_imask &= ~(ATH9K_INT_SWBA | ATH9K_INT_BMISS);
1175 ath9k_hw_set_interrupts(sc->sc_ah, sc->sc_imask & ~ATH9K_INT_GLOBAL);
Sujith672840a2008-08-11 14:05:08 +05301176 sc->sc_flags &= ~SC_OP_BEACONS;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001177
1178 error = ath_vap_detach(sc, 0);
1179 if (error)
1180 DPRINTF(sc, ATH_DBG_FATAL,
1181 "%s: Unable to detach vap, error: %d\n",
1182 __func__, error);
1183}
1184
Johannes Berge8975582008-10-09 12:18:51 +02001185static int ath9k_config(struct ieee80211_hw *hw, u32 changed)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001186{
1187 struct ath_softc *sc = hw->priv;
1188 struct ieee80211_channel *curchan = hw->conf.channel;
Johannes Berge8975582008-10-09 12:18:51 +02001189 struct ieee80211_conf *conf = &hw->conf;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001190 int pos;
1191
1192 DPRINTF(sc, ATH_DBG_CONFIG, "%s: Set channel: %d MHz\n",
1193 __func__,
1194 curchan->center_freq);
1195
Johannes Bergae5eb022008-10-14 16:58:37 +02001196 /* Update chainmask */
1197 ath_update_chainmask(sc, conf->ht.enabled);
1198
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001199 pos = ath_get_channel(sc, curchan);
1200 if (pos == -1) {
1201 DPRINTF(sc, ATH_DBG_FATAL, "%s: Invalid channel\n", __func__);
1202 return -EINVAL;
1203 }
1204
1205 sc->sc_ah->ah_channels[pos].chanmode =
Sujith86b89ee2008-08-07 10:54:57 +05301206 (curchan->band == IEEE80211_BAND_2GHZ) ?
1207 CHANNEL_G : CHANNEL_A;
1208
Johannes Bergae5eb022008-10-14 16:58:37 +02001209 if (sc->sc_curaid && hw->conf.ht.enabled)
Sujith86b89ee2008-08-07 10:54:57 +05301210 sc->sc_ah->ah_channels[pos].chanmode =
1211 ath_get_extchanmode(sc, curchan);
1212
Luis R. Rodriguez5c020dc2008-10-22 13:28:45 -07001213 if (changed & IEEE80211_CONF_CHANGE_POWER)
1214 sc->sc_config.txpowlimit = 2 * conf->power_level;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001215
1216 /* set h/w channel */
1217 if (ath_set_channel(sc, &sc->sc_ah->ah_channels[pos]) < 0)
1218 DPRINTF(sc, ATH_DBG_FATAL, "%s: Unable to set channel\n",
1219 __func__);
1220
1221 return 0;
1222}
1223
1224static int ath9k_config_interface(struct ieee80211_hw *hw,
1225 struct ieee80211_vif *vif,
1226 struct ieee80211_if_conf *conf)
1227{
1228 struct ath_softc *sc = hw->priv;
Jouni Malinen2ad67de2008-08-11 14:01:47 +03001229 struct ath_hal *ah = sc->sc_ah;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001230 struct ath_vap *avp;
1231 u32 rfilt = 0;
1232 int error, i;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001233
1234 avp = sc->sc_vaps[0];
1235 if (avp == NULL) {
1236 DPRINTF(sc, ATH_DBG_FATAL, "%s: Invalid interface\n",
1237 __func__);
1238 return -EINVAL;
1239 }
1240
Jouni Malinen2ad67de2008-08-11 14:01:47 +03001241 /* TODO: Need to decide which hw opmode to use for multi-interface
1242 * cases */
Johannes Berg05c914f2008-09-11 00:01:58 +02001243 if (vif->type == NL80211_IFTYPE_AP &&
Jouni Malinen2ad67de2008-08-11 14:01:47 +03001244 ah->ah_opmode != ATH9K_M_HOSTAP) {
1245 ah->ah_opmode = ATH9K_M_HOSTAP;
1246 ath9k_hw_setopmode(ah);
1247 ath9k_hw_write_associd(ah, sc->sc_myaddr, 0);
1248 /* Request full reset to get hw opmode changed properly */
1249 sc->sc_flags |= SC_OP_FULL_RESET;
1250 }
1251
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001252 if ((conf->changed & IEEE80211_IFCC_BSSID) &&
1253 !is_zero_ether_addr(conf->bssid)) {
1254 switch (vif->type) {
Johannes Berg05c914f2008-09-11 00:01:58 +02001255 case NL80211_IFTYPE_STATION:
1256 case NL80211_IFTYPE_ADHOC:
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001257 /* Update ratectrl about the new state */
1258 ath_rate_newstate(sc, avp);
1259
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001260 /* Set BSSID */
1261 memcpy(sc->sc_curbssid, conf->bssid, ETH_ALEN);
1262 sc->sc_curaid = 0;
1263 ath9k_hw_write_associd(sc->sc_ah, sc->sc_curbssid,
1264 sc->sc_curaid);
1265
1266 /* Set aggregation protection mode parameters */
1267 sc->sc_config.ath_aggr_prot = 0;
1268
1269 /*
1270 * Reset our TSF so that its value is lower than the
1271 * beacon that we are trying to catch.
1272 * Only then hw will update its TSF register with the
1273 * new beacon. Reset the TSF before setting the BSSID
1274 * to avoid allowing in any frames that would update
1275 * our TSF only to have us clear it
1276 * immediately thereafter.
1277 */
1278 ath9k_hw_reset_tsf(sc->sc_ah);
1279
1280 /* Disable BMISS interrupt when we're not associated */
1281 ath9k_hw_set_interrupts(sc->sc_ah,
1282 sc->sc_imask &
1283 ~(ATH9K_INT_SWBA | ATH9K_INT_BMISS));
1284 sc->sc_imask &= ~(ATH9K_INT_SWBA | ATH9K_INT_BMISS);
1285
1286 DPRINTF(sc, ATH_DBG_CONFIG,
Johannes Berge1749612008-10-27 15:59:26 -07001287 "%s: RX filter 0x%x bssid %pM aid 0x%x\n",
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001288 __func__, rfilt,
Johannes Berge1749612008-10-27 15:59:26 -07001289 sc->sc_curbssid, sc->sc_curaid);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001290
1291 /* need to reconfigure the beacon */
Sujith672840a2008-08-11 14:05:08 +05301292 sc->sc_flags &= ~SC_OP_BEACONS ;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001293
1294 break;
1295 default:
1296 break;
1297 }
1298 }
1299
1300 if ((conf->changed & IEEE80211_IFCC_BEACON) &&
Johannes Berg05c914f2008-09-11 00:01:58 +02001301 ((vif->type == NL80211_IFTYPE_ADHOC) ||
1302 (vif->type == NL80211_IFTYPE_AP))) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001303 /*
1304 * Allocate and setup the beacon frame.
1305 *
1306 * Stop any previous beacon DMA. This may be
1307 * necessary, for example, when an ibss merge
1308 * causes reconfiguration; we may be called
1309 * with beacon transmission active.
1310 */
1311 ath9k_hw_stoptxdma(sc->sc_ah, sc->sc_bhalq);
1312
1313 error = ath_beacon_alloc(sc, 0);
1314 if (error != 0)
1315 return error;
1316
1317 ath_beacon_sync(sc, 0);
1318 }
1319
1320 /* Check for WLAN_CAPABILITY_PRIVACY ? */
Johannes Berg05c914f2008-09-11 00:01:58 +02001321 if ((avp->av_opmode != NL80211_IFTYPE_STATION)) {
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001322 for (i = 0; i < IEEE80211_WEP_NKID; i++)
1323 if (ath9k_hw_keyisvalid(sc->sc_ah, (u16)i))
1324 ath9k_hw_keysetmac(sc->sc_ah,
1325 (u16)i,
1326 sc->sc_curbssid);
1327 }
1328
1329 /* Only legacy IBSS for now */
Johannes Berg05c914f2008-09-11 00:01:58 +02001330 if (vif->type == NL80211_IFTYPE_ADHOC)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001331 ath_update_chainmask(sc, 0);
1332
1333 return 0;
1334}
1335
1336#define SUPPORTED_FILTERS \
1337 (FIF_PROMISC_IN_BSS | \
1338 FIF_ALLMULTI | \
1339 FIF_CONTROL | \
1340 FIF_OTHER_BSS | \
1341 FIF_BCN_PRBRESP_PROMISC | \
1342 FIF_FCSFAIL)
1343
Sujith7dcfdcd2008-08-11 14:03:13 +05301344/* FIXME: sc->sc_full_reset ? */
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001345static void ath9k_configure_filter(struct ieee80211_hw *hw,
1346 unsigned int changed_flags,
1347 unsigned int *total_flags,
1348 int mc_count,
1349 struct dev_mc_list *mclist)
1350{
1351 struct ath_softc *sc = hw->priv;
Sujith7dcfdcd2008-08-11 14:03:13 +05301352 u32 rfilt;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001353
1354 changed_flags &= SUPPORTED_FILTERS;
1355 *total_flags &= SUPPORTED_FILTERS;
1356
Sujith7dcfdcd2008-08-11 14:03:13 +05301357 sc->rx_filter = *total_flags;
1358 rfilt = ath_calcrxfilter(sc);
1359 ath9k_hw_setrxfilter(sc->sc_ah, rfilt);
1360
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001361 if (changed_flags & FIF_BCN_PRBRESP_PROMISC) {
1362 if (*total_flags & FIF_BCN_PRBRESP_PROMISC)
Sujith7dcfdcd2008-08-11 14:03:13 +05301363 ath9k_hw_write_associd(sc->sc_ah, ath_bcast_mac, 0);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001364 }
Sujith7dcfdcd2008-08-11 14:03:13 +05301365
1366 DPRINTF(sc, ATH_DBG_CONFIG, "%s: Set HW RX filter: 0x%x\n",
1367 __func__, sc->rx_filter);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001368}
1369
Sujithb5aa9bf2008-10-29 10:13:31 +05301370/* Only a single interface is currently supported,
1371 so pass 0 as the interface id to ath_node_attach */
1372
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001373static void ath9k_sta_notify(struct ieee80211_hw *hw,
1374 struct ieee80211_vif *vif,
1375 enum sta_notify_cmd cmd,
Johannes Berg17741cd2008-09-11 00:02:02 +02001376 struct ieee80211_sta *sta)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001377{
1378 struct ath_softc *sc = hw->priv;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001379
1380 switch (cmd) {
1381 case STA_NOTIFY_ADD:
Sujithb5aa9bf2008-10-29 10:13:31 +05301382 ath_node_attach(sc, sta, 0);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001383 break;
1384 case STA_NOTIFY_REMOVE:
Sujithb5aa9bf2008-10-29 10:13:31 +05301385 ath_node_detach(sc, sta);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001386 break;
1387 default:
1388 break;
1389 }
1390}
1391
1392static int ath9k_conf_tx(struct ieee80211_hw *hw,
1393 u16 queue,
1394 const struct ieee80211_tx_queue_params *params)
1395{
1396 struct ath_softc *sc = hw->priv;
Sujithea9880f2008-08-07 10:53:10 +05301397 struct ath9k_tx_queue_info qi;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001398 int ret = 0, qnum;
1399
1400 if (queue >= WME_NUM_AC)
1401 return 0;
1402
1403 qi.tqi_aifs = params->aifs;
1404 qi.tqi_cwmin = params->cw_min;
1405 qi.tqi_cwmax = params->cw_max;
1406 qi.tqi_burstTime = params->txop;
1407 qnum = ath_get_hal_qnum(queue, sc);
1408
1409 DPRINTF(sc, ATH_DBG_CONFIG,
1410 "%s: Configure tx [queue/halq] [%d/%d], "
1411 "aifs: %d, cw_min: %d, cw_max: %d, txop: %d\n",
1412 __func__,
1413 queue,
1414 qnum,
1415 params->aifs,
1416 params->cw_min,
1417 params->cw_max,
1418 params->txop);
1419
1420 ret = ath_txq_update(sc, qnum, &qi);
1421 if (ret)
1422 DPRINTF(sc, ATH_DBG_FATAL,
1423 "%s: TXQ Update failed\n", __func__);
1424
1425 return ret;
1426}
1427
1428static int ath9k_set_key(struct ieee80211_hw *hw,
1429 enum set_key_cmd cmd,
1430 const u8 *local_addr,
1431 const u8 *addr,
1432 struct ieee80211_key_conf *key)
1433{
1434 struct ath_softc *sc = hw->priv;
1435 int ret = 0;
1436
1437 DPRINTF(sc, ATH_DBG_KEYCACHE, " %s: Set HW Key\n", __func__);
1438
1439 switch (cmd) {
1440 case SET_KEY:
1441 ret = ath_key_config(sc, addr, key);
1442 if (!ret) {
1443 set_bit(key->keyidx, sc->sc_keymap);
1444 key->hw_key_idx = key->keyidx;
1445 /* push IV and Michael MIC generation to stack */
1446 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
Senthil Balasubramanian1b961752008-09-01 19:45:21 +05301447 if (key->alg == ALG_TKIP)
1448 key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001449 }
1450 break;
1451 case DISABLE_KEY:
1452 ath_key_delete(sc, key);
1453 clear_bit(key->keyidx, sc->sc_keymap);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001454 break;
1455 default:
1456 ret = -EINVAL;
1457 }
1458
1459 return ret;
1460}
1461
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001462static void ath9k_bss_info_changed(struct ieee80211_hw *hw,
1463 struct ieee80211_vif *vif,
1464 struct ieee80211_bss_conf *bss_conf,
1465 u32 changed)
1466{
1467 struct ath_softc *sc = hw->priv;
1468
1469 if (changed & BSS_CHANGED_ERP_PREAMBLE) {
1470 DPRINTF(sc, ATH_DBG_CONFIG, "%s: BSS Changed PREAMBLE %d\n",
1471 __func__,
1472 bss_conf->use_short_preamble);
1473 if (bss_conf->use_short_preamble)
Sujith672840a2008-08-11 14:05:08 +05301474 sc->sc_flags |= SC_OP_PREAMBLE_SHORT;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001475 else
Sujith672840a2008-08-11 14:05:08 +05301476 sc->sc_flags &= ~SC_OP_PREAMBLE_SHORT;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001477 }
1478
1479 if (changed & BSS_CHANGED_ERP_CTS_PROT) {
1480 DPRINTF(sc, ATH_DBG_CONFIG, "%s: BSS Changed CTS PROT %d\n",
1481 __func__,
1482 bss_conf->use_cts_prot);
1483 if (bss_conf->use_cts_prot &&
1484 hw->conf.channel->band != IEEE80211_BAND_5GHZ)
Sujith672840a2008-08-11 14:05:08 +05301485 sc->sc_flags |= SC_OP_PROTECT_ENABLE;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001486 else
Sujith672840a2008-08-11 14:05:08 +05301487 sc->sc_flags &= ~SC_OP_PROTECT_ENABLE;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001488 }
1489
1490 if (changed & BSS_CHANGED_HT) {
Johannes Bergae5eb022008-10-14 16:58:37 +02001491 DPRINTF(sc, ATH_DBG_CONFIG, "%s: BSS Changed HT\n",
1492 __func__);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001493 ath9k_ht_conf(sc, bss_conf);
1494 }
1495
1496 if (changed & BSS_CHANGED_ASSOC) {
1497 DPRINTF(sc, ATH_DBG_CONFIG, "%s: BSS Changed ASSOC %d\n",
1498 __func__,
1499 bss_conf->assoc);
1500 ath9k_bss_assoc_info(sc, bss_conf);
1501 }
1502}
1503
1504static u64 ath9k_get_tsf(struct ieee80211_hw *hw)
1505{
1506 u64 tsf;
1507 struct ath_softc *sc = hw->priv;
1508 struct ath_hal *ah = sc->sc_ah;
1509
1510 tsf = ath9k_hw_gettsf64(ah);
1511
1512 return tsf;
1513}
1514
1515static void ath9k_reset_tsf(struct ieee80211_hw *hw)
1516{
1517 struct ath_softc *sc = hw->priv;
1518 struct ath_hal *ah = sc->sc_ah;
1519
1520 ath9k_hw_reset_tsf(ah);
1521}
1522
1523static int ath9k_ampdu_action(struct ieee80211_hw *hw,
1524 enum ieee80211_ampdu_mlme_action action,
Johannes Berg17741cd2008-09-11 00:02:02 +02001525 struct ieee80211_sta *sta,
1526 u16 tid, u16 *ssn)
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001527{
1528 struct ath_softc *sc = hw->priv;
1529 int ret = 0;
1530
1531 switch (action) {
1532 case IEEE80211_AMPDU_RX_START:
Sujithb5aa9bf2008-10-29 10:13:31 +05301533 ret = ath_rx_aggr_start(sc, sta, tid, ssn);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001534 if (ret < 0)
1535 DPRINTF(sc, ATH_DBG_FATAL,
1536 "%s: Unable to start RX aggregation\n",
1537 __func__);
1538 break;
1539 case IEEE80211_AMPDU_RX_STOP:
Sujithb5aa9bf2008-10-29 10:13:31 +05301540 ret = ath_rx_aggr_stop(sc, sta, tid);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001541 if (ret < 0)
1542 DPRINTF(sc, ATH_DBG_FATAL,
1543 "%s: Unable to stop RX aggregation\n",
1544 __func__);
1545 break;
1546 case IEEE80211_AMPDU_TX_START:
Sujithb5aa9bf2008-10-29 10:13:31 +05301547 ret = ath_tx_aggr_start(sc, sta, tid, ssn);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001548 if (ret < 0)
1549 DPRINTF(sc, ATH_DBG_FATAL,
1550 "%s: Unable to start TX aggregation\n",
1551 __func__);
1552 else
Johannes Berg17741cd2008-09-11 00:02:02 +02001553 ieee80211_start_tx_ba_cb_irqsafe(hw, sta->addr, tid);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001554 break;
1555 case IEEE80211_AMPDU_TX_STOP:
Sujithb5aa9bf2008-10-29 10:13:31 +05301556 ret = ath_tx_aggr_stop(sc, sta, tid);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001557 if (ret < 0)
1558 DPRINTF(sc, ATH_DBG_FATAL,
1559 "%s: Unable to stop TX aggregation\n",
1560 __func__);
1561
Johannes Berg17741cd2008-09-11 00:02:02 +02001562 ieee80211_stop_tx_ba_cb_irqsafe(hw, sta->addr, tid);
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001563 break;
1564 default:
1565 DPRINTF(sc, ATH_DBG_FATAL,
1566 "%s: Unknown AMPDU action\n", __func__);
1567 }
1568
1569 return ret;
1570}
1571
Johannes Berg4233df62008-10-13 13:35:05 +02001572static int ath9k_no_fragmentation(struct ieee80211_hw *hw, u32 value)
1573{
1574 return -EOPNOTSUPP;
1575}
1576
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001577static struct ieee80211_ops ath9k_ops = {
1578 .tx = ath9k_tx,
1579 .start = ath9k_start,
1580 .stop = ath9k_stop,
1581 .add_interface = ath9k_add_interface,
1582 .remove_interface = ath9k_remove_interface,
1583 .config = ath9k_config,
1584 .config_interface = ath9k_config_interface,
1585 .configure_filter = ath9k_configure_filter,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001586 .sta_notify = ath9k_sta_notify,
1587 .conf_tx = ath9k_conf_tx,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001588 .bss_info_changed = ath9k_bss_info_changed,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001589 .set_key = ath9k_set_key,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001590 .get_tsf = ath9k_get_tsf,
1591 .reset_tsf = ath9k_reset_tsf,
Johannes Berg4233df62008-10-13 13:35:05 +02001592 .ampdu_action = ath9k_ampdu_action,
1593 .set_frag_threshold = ath9k_no_fragmentation,
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001594};
1595
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001596static int ath_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
1597{
1598 void __iomem *mem;
1599 struct ath_softc *sc;
1600 struct ieee80211_hw *hw;
1601 const char *athname;
1602 u8 csz;
1603 u32 val;
1604 int ret = 0;
1605
1606 if (pci_enable_device(pdev))
1607 return -EIO;
1608
1609 /* XXX 32-bit addressing only */
1610 if (pci_set_dma_mask(pdev, 0xffffffff)) {
1611 printk(KERN_ERR "ath_pci: 32-bit DMA not available\n");
1612 ret = -ENODEV;
1613 goto bad;
1614 }
1615
1616 /*
1617 * Cache line size is used to size and align various
1618 * structures used to communicate with the hardware.
1619 */
1620 pci_read_config_byte(pdev, PCI_CACHE_LINE_SIZE, &csz);
1621 if (csz == 0) {
1622 /*
1623 * Linux 2.4.18 (at least) writes the cache line size
1624 * register as a 16-bit wide register which is wrong.
1625 * We must have this setup properly for rx buffer
1626 * DMA to work so force a reasonable value here if it
1627 * comes up zero.
1628 */
1629 csz = L1_CACHE_BYTES / sizeof(u32);
1630 pci_write_config_byte(pdev, PCI_CACHE_LINE_SIZE, csz);
1631 }
1632 /*
1633 * The default setting of latency timer yields poor results,
1634 * set it to the value used by other systems. It may be worth
1635 * tweaking this setting more.
1636 */
1637 pci_write_config_byte(pdev, PCI_LATENCY_TIMER, 0xa8);
1638
1639 pci_set_master(pdev);
1640
1641 /*
1642 * Disable the RETRY_TIMEOUT register (0x41) to keep
1643 * PCI Tx retries from interfering with C3 CPU state.
1644 */
1645 pci_read_config_dword(pdev, 0x40, &val);
1646 if ((val & 0x0000ff00) != 0)
1647 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
1648
1649 ret = pci_request_region(pdev, 0, "ath9k");
1650 if (ret) {
1651 dev_err(&pdev->dev, "PCI memory region reserve error\n");
1652 ret = -ENODEV;
1653 goto bad;
1654 }
1655
1656 mem = pci_iomap(pdev, 0, 0);
1657 if (!mem) {
1658 printk(KERN_ERR "PCI memory map error\n") ;
1659 ret = -EIO;
1660 goto bad1;
1661 }
1662
1663 hw = ieee80211_alloc_hw(sizeof(struct ath_softc), &ath9k_ops);
1664 if (hw == NULL) {
1665 printk(KERN_ERR "ath_pci: no memory for ieee80211_hw\n");
1666 goto bad2;
1667 }
1668
Sujith19b73c72008-08-14 13:28:20 +05301669 hw->flags = IEEE80211_HW_RX_INCLUDES_FCS |
Jouni Malinene022edb2008-08-22 17:31:33 +03001670 IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING |
Sujith19b73c72008-08-14 13:28:20 +05301671 IEEE80211_HW_SIGNAL_DBM |
Sujith8b30b1f2008-10-24 09:55:27 +05301672 IEEE80211_HW_NOISE_DBM |
1673 IEEE80211_HW_AMPDU_AGGREGATION;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001674
Luis R. Rodriguezf59ac042008-08-29 16:26:43 -07001675 hw->wiphy->interface_modes =
1676 BIT(NL80211_IFTYPE_AP) |
1677 BIT(NL80211_IFTYPE_STATION) |
1678 BIT(NL80211_IFTYPE_ADHOC);
1679
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001680 SET_IEEE80211_DEV(hw, &pdev->dev);
1681 pci_set_drvdata(pdev, hw);
1682
1683 sc = hw->priv;
1684 sc->hw = hw;
1685 sc->pdev = pdev;
1686 sc->mem = mem;
1687
1688 if (ath_attach(id->device, sc) != 0) {
1689 ret = -ENODEV;
1690 goto bad3;
1691 }
1692
1693 /* setup interrupt service routine */
1694
1695 if (request_irq(pdev->irq, ath_isr, IRQF_SHARED, "ath", sc)) {
1696 printk(KERN_ERR "%s: request_irq failed\n",
1697 wiphy_name(hw->wiphy));
1698 ret = -EIO;
1699 goto bad4;
1700 }
1701
1702 athname = ath9k_hw_probe(id->vendor, id->device);
1703
1704 printk(KERN_INFO "%s: %s: mem=0x%lx, irq=%d\n",
1705 wiphy_name(hw->wiphy),
1706 athname ? athname : "Atheros ???",
1707 (unsigned long)mem, pdev->irq);
1708
1709 return 0;
1710bad4:
1711 ath_detach(sc);
1712bad3:
1713 ieee80211_free_hw(hw);
1714bad2:
1715 pci_iounmap(pdev, mem);
1716bad1:
1717 pci_release_region(pdev, 0);
1718bad:
1719 pci_disable_device(pdev);
1720 return ret;
1721}
1722
1723static void ath_pci_remove(struct pci_dev *pdev)
1724{
1725 struct ieee80211_hw *hw = pci_get_drvdata(pdev);
1726 struct ath_softc *sc = hw->priv;
Senthil Balasubramanian6115e852008-09-22 14:22:39 +05301727 enum ath9k_int status;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001728
Senthil Balasubramanian6115e852008-09-22 14:22:39 +05301729 if (pdev->irq) {
1730 ath9k_hw_set_interrupts(sc->sc_ah, 0);
1731 /* clear the ISR */
1732 ath9k_hw_getisr(sc->sc_ah, &status);
David S. Millerb262e602008-10-01 06:12:56 -07001733 sc->sc_flags |= SC_OP_INVALID;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001734 free_irq(pdev->irq, sc);
Senthil Balasubramanian6115e852008-09-22 14:22:39 +05301735 }
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001736 ath_detach(sc);
Senthil Balasubramanian6115e852008-09-22 14:22:39 +05301737
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001738 pci_iounmap(pdev, sc->mem);
1739 pci_release_region(pdev, 0);
1740 pci_disable_device(pdev);
1741 ieee80211_free_hw(hw);
1742}
1743
1744#ifdef CONFIG_PM
1745
1746static int ath_pci_suspend(struct pci_dev *pdev, pm_message_t state)
1747{
Vasanthakumar Thiagarajanc83be682008-08-25 20:47:29 +05301748 struct ieee80211_hw *hw = pci_get_drvdata(pdev);
1749 struct ath_softc *sc = hw->priv;
1750
1751 ath9k_hw_set_gpio(sc->sc_ah, ATH_LED_PIN, 1);
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301752
1753#ifdef CONFIG_RFKILL
1754 if (sc->sc_ah->ah_caps.hw_caps & ATH9K_HW_CAP_RFSILENT)
1755 cancel_delayed_work_sync(&sc->rf_kill.rfkill_poll);
1756#endif
1757
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001758 pci_save_state(pdev);
1759 pci_disable_device(pdev);
1760 pci_set_power_state(pdev, 3);
1761
1762 return 0;
1763}
1764
1765static int ath_pci_resume(struct pci_dev *pdev)
1766{
Vasanthakumar Thiagarajanc83be682008-08-25 20:47:29 +05301767 struct ieee80211_hw *hw = pci_get_drvdata(pdev);
1768 struct ath_softc *sc = hw->priv;
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001769 u32 val;
1770 int err;
1771
1772 err = pci_enable_device(pdev);
1773 if (err)
1774 return err;
1775 pci_restore_state(pdev);
1776 /*
1777 * Suspend/Resume resets the PCI configuration space, so we have to
1778 * re-disable the RETRY_TIMEOUT register (0x41) to keep
1779 * PCI Tx retries from interfering with C3 CPU state
1780 */
1781 pci_read_config_dword(pdev, 0x40, &val);
1782 if ((val & 0x0000ff00) != 0)
1783 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
1784
Vasanthakumar Thiagarajanc83be682008-08-25 20:47:29 +05301785 /* Enable LED */
1786 ath9k_hw_cfg_output(sc->sc_ah, ATH_LED_PIN,
1787 AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
1788 ath9k_hw_set_gpio(sc->sc_ah, ATH_LED_PIN, 1);
1789
Vasanthakumar Thiagarajan500c0642008-09-10 18:50:17 +05301790#ifdef CONFIG_RFKILL
1791 /*
1792 * check the h/w rfkill state on resume
1793 * and start the rfkill poll timer
1794 */
1795 if (sc->sc_ah->ah_caps.hw_caps & ATH9K_HW_CAP_RFSILENT)
1796 queue_delayed_work(sc->hw->workqueue,
1797 &sc->rf_kill.rfkill_poll, 0);
1798#endif
1799
Luis R. Rodriguezf078f202008-08-04 00:16:41 -07001800 return 0;
1801}
1802
1803#endif /* CONFIG_PM */
1804
1805MODULE_DEVICE_TABLE(pci, ath_pci_id_table);
1806
1807static struct pci_driver ath_pci_driver = {
1808 .name = "ath9k",
1809 .id_table = ath_pci_id_table,
1810 .probe = ath_pci_probe,
1811 .remove = ath_pci_remove,
1812#ifdef CONFIG_PM
1813 .suspend = ath_pci_suspend,
1814 .resume = ath_pci_resume,
1815#endif /* CONFIG_PM */
1816};
1817
1818static int __init init_ath_pci(void)
1819{
1820 printk(KERN_INFO "%s: %s\n", dev_info, ATH_PCI_VERSION);
1821
1822 if (pci_register_driver(&ath_pci_driver) < 0) {
1823 printk(KERN_ERR
1824 "ath_pci: No devices found, driver not installed.\n");
1825 pci_unregister_driver(&ath_pci_driver);
1826 return -ENODEV;
1827 }
1828
1829 return 0;
1830}
1831module_init(init_ath_pci);
1832
1833static void __exit exit_ath_pci(void)
1834{
1835 pci_unregister_driver(&ath_pci_driver);
1836 printk(KERN_INFO "%s: driver unloaded\n", dev_info);
1837}
1838module_exit(exit_ath_pci);