ath9k: use 'struct ath_hw *' as the first argument for 'ath9k_hw_nvram_read'
[deliverable/linux.git] / drivers / net / wireless / ath / ath9k / init.c
CommitLineData
55624204 1/*
5b68138e 2 * Copyright (c) 2008-2011 Atheros Communications Inc.
55624204
S
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
516304b0
JP
17#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
18
b7f080cf 19#include <linux/dma-mapping.h>
5a0e3ad6 20#include <linux/slab.h>
6fb1b1e1 21#include <linux/ath9k_platform.h>
9d9779e7 22#include <linux/module.h>
5a0e3ad6 23
55624204
S
24#include "ath9k.h"
25
26static char *dev_info = "ath9k";
27
28MODULE_AUTHOR("Atheros Communications");
29MODULE_DESCRIPTION("Support for Atheros 802.11n wireless LAN cards.");
30MODULE_SUPPORTED_DEVICE("Atheros 802.11n WLAN cards");
31MODULE_LICENSE("Dual BSD/GPL");
32
33static unsigned int ath9k_debug = ATH_DBG_DEFAULT;
34module_param_named(debug, ath9k_debug, uint, 0);
35MODULE_PARM_DESC(debug, "Debugging mask");
36
3e6109c5
JL
37int ath9k_modparam_nohwcrypt;
38module_param_named(nohwcrypt, ath9k_modparam_nohwcrypt, int, 0444);
55624204
S
39MODULE_PARM_DESC(nohwcrypt, "Disable hardware encryption");
40
93dbbcc4 41int led_blink;
9a75c2ff
VN
42module_param_named(blink, led_blink, int, 0444);
43MODULE_PARM_DESC(blink, "Enable LED blink on activity");
44
8f5dcb1c
VT
45static int ath9k_btcoex_enable;
46module_param_named(btcoex_enable, ath9k_btcoex_enable, int, 0444);
47MODULE_PARM_DESC(btcoex_enable, "Enable wifi-BT coexistence");
48
e09f2dc7
SM
49static int ath9k_enable_diversity;
50module_param_named(enable_diversity, ath9k_enable_diversity, int, 0444);
51MODULE_PARM_DESC(enable_diversity, "Enable Antenna diversity for AR9565");
52
d584747b 53bool is_ath9k_unloaded;
55624204
S
54/* We use the hw_value as an index into our private channel structure */
55
56#define CHAN2G(_freq, _idx) { \
b1c1d000 57 .band = IEEE80211_BAND_2GHZ, \
55624204
S
58 .center_freq = (_freq), \
59 .hw_value = (_idx), \
60 .max_power = 20, \
61}
62
63#define CHAN5G(_freq, _idx) { \
64 .band = IEEE80211_BAND_5GHZ, \
65 .center_freq = (_freq), \
66 .hw_value = (_idx), \
67 .max_power = 20, \
68}
69
70/* Some 2 GHz radios are actually tunable on 2312-2732
71 * on 5 MHz steps, we support the channels which we know
72 * we have calibration data for all cards though to make
73 * this static */
f209f529 74static const struct ieee80211_channel ath9k_2ghz_chantable[] = {
55624204
S
75 CHAN2G(2412, 0), /* Channel 1 */
76 CHAN2G(2417, 1), /* Channel 2 */
77 CHAN2G(2422, 2), /* Channel 3 */
78 CHAN2G(2427, 3), /* Channel 4 */
79 CHAN2G(2432, 4), /* Channel 5 */
80 CHAN2G(2437, 5), /* Channel 6 */
81 CHAN2G(2442, 6), /* Channel 7 */
82 CHAN2G(2447, 7), /* Channel 8 */
83 CHAN2G(2452, 8), /* Channel 9 */
84 CHAN2G(2457, 9), /* Channel 10 */
85 CHAN2G(2462, 10), /* Channel 11 */
86 CHAN2G(2467, 11), /* Channel 12 */
87 CHAN2G(2472, 12), /* Channel 13 */
88 CHAN2G(2484, 13), /* Channel 14 */
89};
90
91/* Some 5 GHz radios are actually tunable on XXXX-YYYY
92 * on 5 MHz steps, we support the channels which we know
93 * we have calibration data for all cards though to make
94 * this static */
f209f529 95static const struct ieee80211_channel ath9k_5ghz_chantable[] = {
55624204
S
96 /* _We_ call this UNII 1 */
97 CHAN5G(5180, 14), /* Channel 36 */
98 CHAN5G(5200, 15), /* Channel 40 */
99 CHAN5G(5220, 16), /* Channel 44 */
100 CHAN5G(5240, 17), /* Channel 48 */
101 /* _We_ call this UNII 2 */
102 CHAN5G(5260, 18), /* Channel 52 */
103 CHAN5G(5280, 19), /* Channel 56 */
104 CHAN5G(5300, 20), /* Channel 60 */
105 CHAN5G(5320, 21), /* Channel 64 */
106 /* _We_ call this "Middle band" */
107 CHAN5G(5500, 22), /* Channel 100 */
108 CHAN5G(5520, 23), /* Channel 104 */
109 CHAN5G(5540, 24), /* Channel 108 */
110 CHAN5G(5560, 25), /* Channel 112 */
111 CHAN5G(5580, 26), /* Channel 116 */
112 CHAN5G(5600, 27), /* Channel 120 */
113 CHAN5G(5620, 28), /* Channel 124 */
114 CHAN5G(5640, 29), /* Channel 128 */
115 CHAN5G(5660, 30), /* Channel 132 */
116 CHAN5G(5680, 31), /* Channel 136 */
117 CHAN5G(5700, 32), /* Channel 140 */
118 /* _We_ call this UNII 3 */
119 CHAN5G(5745, 33), /* Channel 149 */
120 CHAN5G(5765, 34), /* Channel 153 */
121 CHAN5G(5785, 35), /* Channel 157 */
122 CHAN5G(5805, 36), /* Channel 161 */
123 CHAN5G(5825, 37), /* Channel 165 */
124};
125
126/* Atheros hardware rate code addition for short premble */
127#define SHPCHECK(__hw_rate, __flags) \
128 ((__flags & IEEE80211_RATE_SHORT_PREAMBLE) ? (__hw_rate | 0x04 ) : 0)
129
130#define RATE(_bitrate, _hw_rate, _flags) { \
131 .bitrate = (_bitrate), \
132 .flags = (_flags), \
133 .hw_value = (_hw_rate), \
134 .hw_value_short = (SHPCHECK(_hw_rate, _flags)) \
135}
136
137static struct ieee80211_rate ath9k_legacy_rates[] = {
138 RATE(10, 0x1b, 0),
139 RATE(20, 0x1a, IEEE80211_RATE_SHORT_PREAMBLE),
140 RATE(55, 0x19, IEEE80211_RATE_SHORT_PREAMBLE),
141 RATE(110, 0x18, IEEE80211_RATE_SHORT_PREAMBLE),
142 RATE(60, 0x0b, 0),
143 RATE(90, 0x0f, 0),
144 RATE(120, 0x0a, 0),
145 RATE(180, 0x0e, 0),
146 RATE(240, 0x09, 0),
147 RATE(360, 0x0d, 0),
148 RATE(480, 0x08, 0),
149 RATE(540, 0x0c, 0),
150};
151
0cf55c21
FF
152#ifdef CONFIG_MAC80211_LEDS
153static const struct ieee80211_tpt_blink ath9k_tpt_blink[] = {
154 { .throughput = 0 * 1024, .blink_time = 334 },
155 { .throughput = 1 * 1024, .blink_time = 260 },
156 { .throughput = 5 * 1024, .blink_time = 220 },
157 { .throughput = 10 * 1024, .blink_time = 190 },
158 { .throughput = 20 * 1024, .blink_time = 170 },
159 { .throughput = 50 * 1024, .blink_time = 150 },
160 { .throughput = 70 * 1024, .blink_time = 130 },
161 { .throughput = 100 * 1024, .blink_time = 110 },
162 { .throughput = 200 * 1024, .blink_time = 80 },
163 { .throughput = 300 * 1024, .blink_time = 50 },
164};
165#endif
166
285f2dda 167static void ath9k_deinit_softc(struct ath_softc *sc);
55624204
S
168
169/*
170 * Read and write, they both share the same lock. We do this to serialize
171 * reads and writes on Atheros 802.11n PCI devices only. This is required
172 * as the FIFO on these devices can only accept sanely 2 requests.
173 */
174
175static void ath9k_iowrite32(void *hw_priv, u32 val, u32 reg_offset)
176{
177 struct ath_hw *ah = (struct ath_hw *) hw_priv;
178 struct ath_common *common = ath9k_hw_common(ah);
179 struct ath_softc *sc = (struct ath_softc *) common->priv;
180
f3eef645 181 if (NR_CPUS > 1 && ah->config.serialize_regmode == SER_REG_MODE_ON) {
55624204
S
182 unsigned long flags;
183 spin_lock_irqsave(&sc->sc_serial_rw, flags);
184 iowrite32(val, sc->mem + reg_offset);
185 spin_unlock_irqrestore(&sc->sc_serial_rw, flags);
186 } else
187 iowrite32(val, sc->mem + reg_offset);
188}
189
190static unsigned int ath9k_ioread32(void *hw_priv, u32 reg_offset)
191{
192 struct ath_hw *ah = (struct ath_hw *) hw_priv;
193 struct ath_common *common = ath9k_hw_common(ah);
194 struct ath_softc *sc = (struct ath_softc *) common->priv;
195 u32 val;
196
f3eef645 197 if (NR_CPUS > 1 && ah->config.serialize_regmode == SER_REG_MODE_ON) {
55624204
S
198 unsigned long flags;
199 spin_lock_irqsave(&sc->sc_serial_rw, flags);
200 val = ioread32(sc->mem + reg_offset);
201 spin_unlock_irqrestore(&sc->sc_serial_rw, flags);
202 } else
203 val = ioread32(sc->mem + reg_offset);
204 return val;
205}
206
5479de6e
RM
207static unsigned int __ath9k_reg_rmw(struct ath_softc *sc, u32 reg_offset,
208 u32 set, u32 clr)
209{
210 u32 val;
211
212 val = ioread32(sc->mem + reg_offset);
213 val &= ~clr;
214 val |= set;
215 iowrite32(val, sc->mem + reg_offset);
216
217 return val;
218}
219
845e03c9
FF
220static unsigned int ath9k_reg_rmw(void *hw_priv, u32 reg_offset, u32 set, u32 clr)
221{
222 struct ath_hw *ah = (struct ath_hw *) hw_priv;
223 struct ath_common *common = ath9k_hw_common(ah);
224 struct ath_softc *sc = (struct ath_softc *) common->priv;
225 unsigned long uninitialized_var(flags);
226 u32 val;
227
f3eef645 228 if (NR_CPUS > 1 && ah->config.serialize_regmode == SER_REG_MODE_ON) {
845e03c9 229 spin_lock_irqsave(&sc->sc_serial_rw, flags);
5479de6e 230 val = __ath9k_reg_rmw(sc, reg_offset, set, clr);
845e03c9 231 spin_unlock_irqrestore(&sc->sc_serial_rw, flags);
5479de6e
RM
232 } else
233 val = __ath9k_reg_rmw(sc, reg_offset, set, clr);
845e03c9
FF
234
235 return val;
236}
237
55624204
S
238/**************************/
239/* Initialization */
240/**************************/
241
242static void setup_ht_cap(struct ath_softc *sc,
243 struct ieee80211_sta_ht_cap *ht_info)
244{
3bb065a7
FF
245 struct ath_hw *ah = sc->sc_ah;
246 struct ath_common *common = ath9k_hw_common(ah);
55624204 247 u8 tx_streams, rx_streams;
3bb065a7 248 int i, max_streams;
55624204
S
249
250 ht_info->ht_supported = true;
251 ht_info->cap = IEEE80211_HT_CAP_SUP_WIDTH_20_40 |
252 IEEE80211_HT_CAP_SM_PS |
253 IEEE80211_HT_CAP_SGI_40 |
254 IEEE80211_HT_CAP_DSSSCCK40;
255
b0a33448
LR
256 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_LDPC)
257 ht_info->cap |= IEEE80211_HT_CAP_LDPC_CODING;
258
6473d24d
VT
259 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_SGI_20)
260 ht_info->cap |= IEEE80211_HT_CAP_SGI_20;
261
55624204
S
262 ht_info->ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
263 ht_info->ampdu_density = IEEE80211_HT_MPDU_DENSITY_8;
264
e41db61d 265 if (AR_SREV_9330(ah) || AR_SREV_9485(ah) || AR_SREV_9565(ah))
7f1c7a6a 266 max_streams = 1;
e7104195
MSS
267 else if (AR_SREV_9462(ah))
268 max_streams = 2;
7f1c7a6a 269 else if (AR_SREV_9300_20_OR_LATER(ah))
3bb065a7
FF
270 max_streams = 3;
271 else
272 max_streams = 2;
273
7a37081e 274 if (AR_SREV_9280_20_OR_LATER(ah)) {
074a8c0d
FF
275 if (max_streams >= 2)
276 ht_info->cap |= IEEE80211_HT_CAP_TX_STBC;
277 ht_info->cap |= (1 << IEEE80211_HT_CAP_RX_STBC_SHIFT);
278 }
279
55624204
S
280 /* set up supported mcs set */
281 memset(&ht_info->mcs, 0, sizeof(ht_info->mcs));
82b2d334
FF
282 tx_streams = ath9k_cmn_count_streams(ah->txchainmask, max_streams);
283 rx_streams = ath9k_cmn_count_streams(ah->rxchainmask, max_streams);
3bb065a7 284
d2182b69 285 ath_dbg(common, CONFIG, "TX streams %d, RX streams: %d\n",
226afe68 286 tx_streams, rx_streams);
55624204
S
287
288 if (tx_streams != rx_streams) {
55624204
S
289 ht_info->mcs.tx_params |= IEEE80211_HT_MCS_TX_RX_DIFF;
290 ht_info->mcs.tx_params |= ((tx_streams - 1) <<
291 IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT);
292 }
293
3bb065a7
FF
294 for (i = 0; i < rx_streams; i++)
295 ht_info->mcs.rx_mask[i] = 0xff;
55624204
S
296
297 ht_info->mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
298}
299
300static int ath9k_reg_notifier(struct wiphy *wiphy,
301 struct regulatory_request *request)
302{
303 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
9ac58615 304 struct ath_softc *sc = hw->priv;
687f545e
RM
305 struct ath_hw *ah = sc->sc_ah;
306 struct ath_regulatory *reg = ath9k_hw_regulatory(ah);
307 int ret;
308
309 ret = ath_reg_notifier_apply(wiphy, request, reg);
310
311 /* Set tx power */
312 if (ah->curchan) {
313 sc->config.txpowlimit = 2 * ah->curchan->chan->max_power;
314 ath9k_ps_wakeup(sc);
315 ath9k_hw_set_txpowerlimit(ah, sc->config.txpowlimit, false);
316 sc->curtxpow = ath9k_hw_regulatory(ah)->power_limit;
317 ath9k_ps_restore(sc);
318 }
55624204 319
687f545e 320 return ret;
55624204
S
321}
322
323/*
324 * This function will allocate both the DMA descriptor structure, and the
325 * buffers it contains. These are used to contain the descriptors used
326 * by the system.
327*/
328int ath_descdma_setup(struct ath_softc *sc, struct ath_descdma *dd,
329 struct list_head *head, const char *name,
4adfcded 330 int nbuf, int ndesc, bool is_tx)
55624204 331{
55624204 332 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
4adfcded 333 u8 *ds;
55624204 334 struct ath_buf *bf;
4adfcded 335 int i, bsize, error, desc_len;
55624204 336
d2182b69 337 ath_dbg(common, CONFIG, "%s DMA: %u buffers %u desc/buf\n",
226afe68 338 name, nbuf, ndesc);
55624204
S
339
340 INIT_LIST_HEAD(head);
4adfcded
VT
341
342 if (is_tx)
343 desc_len = sc->sc_ah->caps.tx_desc_len;
344 else
345 desc_len = sizeof(struct ath_desc);
346
55624204 347 /* ath_desc must be a multiple of DWORDs */
4adfcded 348 if ((desc_len % 4) != 0) {
3800276a 349 ath_err(common, "ath_desc not DWORD aligned\n");
4adfcded 350 BUG_ON((desc_len % 4) != 0);
55624204
S
351 error = -ENOMEM;
352 goto fail;
353 }
354
4adfcded 355 dd->dd_desc_len = desc_len * nbuf * ndesc;
55624204
S
356
357 /*
358 * Need additional DMA memory because we can't use
359 * descriptors that cross the 4K page boundary. Assume
360 * one skipped descriptor per 4K page.
361 */
362 if (!(sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_4KB_SPLITTRANS)) {
363 u32 ndesc_skipped =
364 ATH_DESC_4KB_BOUND_NUM_SKIPPED(dd->dd_desc_len);
365 u32 dma_len;
366
367 while (ndesc_skipped) {
4adfcded 368 dma_len = ndesc_skipped * desc_len;
55624204
S
369 dd->dd_desc_len += dma_len;
370
371 ndesc_skipped = ATH_DESC_4KB_BOUND_NUM_SKIPPED(dma_len);
ee289b64 372 }
55624204
S
373 }
374
375 /* allocate descriptors */
376 dd->dd_desc = dma_alloc_coherent(sc->dev, dd->dd_desc_len,
377 &dd->dd_desc_paddr, GFP_KERNEL);
378 if (dd->dd_desc == NULL) {
379 error = -ENOMEM;
380 goto fail;
381 }
4adfcded 382 ds = (u8 *) dd->dd_desc;
d2182b69 383 ath_dbg(common, CONFIG, "%s DMA map: %p (%u) -> %llx (%u)\n",
226afe68
JP
384 name, ds, (u32) dd->dd_desc_len,
385 ito64(dd->dd_desc_paddr), /*XXX*/(u32) dd->dd_desc_len);
55624204
S
386
387 /* allocate buffers */
388 bsize = sizeof(struct ath_buf) * nbuf;
389 bf = kzalloc(bsize, GFP_KERNEL);
390 if (bf == NULL) {
391 error = -ENOMEM;
392 goto fail2;
393 }
394 dd->dd_bufptr = bf;
395
4adfcded 396 for (i = 0; i < nbuf; i++, bf++, ds += (desc_len * ndesc)) {
55624204
S
397 bf->bf_desc = ds;
398 bf->bf_daddr = DS2PHYS(dd, ds);
399
400 if (!(sc->sc_ah->caps.hw_caps &
401 ATH9K_HW_CAP_4KB_SPLITTRANS)) {
402 /*
403 * Skip descriptor addresses which can cause 4KB
404 * boundary crossing (addr + length) with a 32 dword
405 * descriptor fetch.
406 */
407 while (ATH_DESC_4KB_BOUND_CHECK(bf->bf_daddr)) {
408 BUG_ON((caddr_t) bf->bf_desc >=
409 ((caddr_t) dd->dd_desc +
410 dd->dd_desc_len));
411
4adfcded 412 ds += (desc_len * ndesc);
55624204
S
413 bf->bf_desc = ds;
414 bf->bf_daddr = DS2PHYS(dd, ds);
415 }
416 }
417 list_add_tail(&bf->list, head);
418 }
419 return 0;
420fail2:
421 dma_free_coherent(sc->dev, dd->dd_desc_len, dd->dd_desc,
422 dd->dd_desc_paddr);
423fail:
424 memset(dd, 0, sizeof(*dd));
425 return error;
55624204
S
426}
427
285f2dda
S
428static int ath9k_init_queues(struct ath_softc *sc)
429{
285f2dda
S
430 int i = 0;
431
285f2dda 432 sc->beacon.beaconq = ath9k_hw_beaconq_setup(sc->sc_ah);
55624204 433 sc->beacon.cabq = ath_txq_setup(sc, ATH9K_TX_QUEUE_CAB, 0);
55624204
S
434
435 sc->config.cabqReadytime = ATH_CABQ_READY_TIME;
436 ath_cabq_update(sc);
437
bea843c7 438 for (i = 0; i < IEEE80211_NUM_ACS; i++) {
066dae93 439 sc->tx.txq_map[i] = ath_txq_setup(sc, ATH9K_TX_QUEUE_DATA, i);
60f2d1d5 440 sc->tx.txq_map[i]->mac80211_qnum = i;
7702e788 441 sc->tx.txq_max_pending[i] = ATH_MAX_QDEPTH;
60f2d1d5 442 }
285f2dda 443 return 0;
285f2dda
S
444}
445
f209f529 446static int ath9k_init_channels_rates(struct ath_softc *sc)
285f2dda 447{
f209f529
FF
448 void *channels;
449
cac4220b
FF
450 BUILD_BUG_ON(ARRAY_SIZE(ath9k_2ghz_chantable) +
451 ARRAY_SIZE(ath9k_5ghz_chantable) !=
452 ATH9K_NUM_CHANNELS);
453
d4659912 454 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_2GHZ) {
f209f529
FF
455 channels = kmemdup(ath9k_2ghz_chantable,
456 sizeof(ath9k_2ghz_chantable), GFP_KERNEL);
457 if (!channels)
458 return -ENOMEM;
459
460 sc->sbands[IEEE80211_BAND_2GHZ].channels = channels;
285f2dda
S
461 sc->sbands[IEEE80211_BAND_2GHZ].band = IEEE80211_BAND_2GHZ;
462 sc->sbands[IEEE80211_BAND_2GHZ].n_channels =
463 ARRAY_SIZE(ath9k_2ghz_chantable);
464 sc->sbands[IEEE80211_BAND_2GHZ].bitrates = ath9k_legacy_rates;
465 sc->sbands[IEEE80211_BAND_2GHZ].n_bitrates =
466 ARRAY_SIZE(ath9k_legacy_rates);
55624204
S
467 }
468
d4659912 469 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_5GHZ) {
f209f529
FF
470 channels = kmemdup(ath9k_5ghz_chantable,
471 sizeof(ath9k_5ghz_chantable), GFP_KERNEL);
472 if (!channels) {
473 if (sc->sbands[IEEE80211_BAND_2GHZ].channels)
474 kfree(sc->sbands[IEEE80211_BAND_2GHZ].channels);
475 return -ENOMEM;
476 }
477
478 sc->sbands[IEEE80211_BAND_5GHZ].channels = channels;
285f2dda
S
479 sc->sbands[IEEE80211_BAND_5GHZ].band = IEEE80211_BAND_5GHZ;
480 sc->sbands[IEEE80211_BAND_5GHZ].n_channels =
481 ARRAY_SIZE(ath9k_5ghz_chantable);
482 sc->sbands[IEEE80211_BAND_5GHZ].bitrates =
483 ath9k_legacy_rates + 4;
484 sc->sbands[IEEE80211_BAND_5GHZ].n_bitrates =
485 ARRAY_SIZE(ath9k_legacy_rates) - 4;
486 }
f209f529 487 return 0;
285f2dda 488}
55624204 489
285f2dda
S
490static void ath9k_init_misc(struct ath_softc *sc)
491{
492 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
493 int i = 0;
3d4e20f2 494
285f2dda 495 setup_timer(&common->ani.timer, ath_ani_calibrate, (unsigned long)sc);
55624204 496
aaa1ec46 497 sc->last_rssi = ATH_RSSI_DUMMY_MARKER;
55624204 498 sc->config.txpowlimit = ATH_TXPOWER_MAX;
364734fa 499 memcpy(common->bssidmask, ath_bcast_mac, ETH_ALEN);
285f2dda 500 sc->beacon.slottime = ATH9K_SLOT_TIME_9;
55624204 501
7545daf4 502 for (i = 0; i < ARRAY_SIZE(sc->beacon.bslot); i++)
55624204 503 sc->beacon.bslot[i] = NULL;
102885a5
VT
504
505 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_ANT_DIV_COMB)
506 sc->ant_comb.count = ATH_ANT_DIV_COMB_INIT_COUNT;
285f2dda 507}
55624204 508
eb93e891 509static int ath9k_init_softc(u16 devid, struct ath_softc *sc,
285f2dda
S
510 const struct ath_bus_ops *bus_ops)
511{
6fb1b1e1 512 struct ath9k_platform_data *pdata = sc->dev->platform_data;
285f2dda
S
513 struct ath_hw *ah = NULL;
514 struct ath_common *common;
515 int ret = 0, i;
516 int csz = 0;
55624204 517
285f2dda
S
518 ah = kzalloc(sizeof(struct ath_hw), GFP_KERNEL);
519 if (!ah)
520 return -ENOMEM;
521
233536e1 522 ah->hw = sc->hw;
285f2dda 523 ah->hw_version.devid = devid;
f9f84e96
FF
524 ah->reg_ops.read = ath9k_ioread32;
525 ah->reg_ops.write = ath9k_iowrite32;
845e03c9 526 ah->reg_ops.rmw = ath9k_reg_rmw;
e8fe7336 527 atomic_set(&ah->intr_ref_cnt, -1);
285f2dda
S
528 sc->sc_ah = ah;
529
8e92d3f2
ZK
530 sc->dfs_detector = dfs_pattern_detector_init(NL80211_DFS_UNSET);
531
6de66dd9 532 if (!pdata) {
a05b5d45 533 ah->ah_flags |= AH_USE_EEPROM;
6de66dd9
FF
534 sc->sc_ah->led_pin = -1;
535 } else {
536 sc->sc_ah->gpio_mask = pdata->gpio_mask;
537 sc->sc_ah->gpio_val = pdata->gpio_val;
538 sc->sc_ah->led_pin = pdata->led_pin;
f2f5f2a1 539 ah->is_clk_25mhz = pdata->is_clk_25mhz;
3762561a 540 ah->get_mac_revision = pdata->get_mac_revision;
7d95847c 541 ah->external_reset = pdata->external_reset;
6de66dd9 542 }
a05b5d45 543
285f2dda 544 common = ath9k_hw_common(ah);
f9f84e96 545 common->ops = &ah->reg_ops;
285f2dda
S
546 common->bus_ops = bus_ops;
547 common->ah = ah;
548 common->hw = sc->hw;
549 common->priv = sc;
550 common->debug_mask = ath9k_debug;
8f5dcb1c 551 common->btcoex_enabled = ath9k_btcoex_enable == 1;
05c0be2f 552 common->disable_ani = false;
e09f2dc7
SM
553
554 /*
555 * Enable Antenna diversity only when BTCOEX is disabled
556 * and the user manually requests the feature.
557 */
558 if (!common->btcoex_enabled && ath9k_enable_diversity)
559 common->antenna_diversity = 1;
560
20b25744 561 spin_lock_init(&common->cc_lock);
285f2dda 562
285f2dda
S
563 spin_lock_init(&sc->sc_serial_rw);
564 spin_lock_init(&sc->sc_pm_lock);
565 mutex_init(&sc->mutex);
5baec742
FF
566#ifdef CONFIG_ATH9K_MAC_DEBUG
567 spin_lock_init(&sc->debug.samp_lock);
7f010c93 568#endif
285f2dda 569 tasklet_init(&sc->intr_tq, ath9k_tasklet, (unsigned long)sc);
fb6e252f 570 tasklet_init(&sc->bcon_tasklet, ath9k_beacon_tasklet,
285f2dda
S
571 (unsigned long)sc);
572
aaa1ec46
SM
573 INIT_WORK(&sc->hw_reset_work, ath_reset_work);
574 INIT_WORK(&sc->hw_check_work, ath_hw_check);
575 INIT_WORK(&sc->paprd_work, ath_paprd_calibrate);
576 INIT_DELAYED_WORK(&sc->hw_pll_work, ath_hw_pll_work);
577 setup_timer(&sc->rx_poll_timer, ath_rx_poll, (unsigned long)sc);
578
285f2dda
S
579 /*
580 * Cache line size is used to size and align various
581 * structures used to communicate with the hardware.
582 */
583 ath_read_cachesize(common, &csz);
584 common->cachelsz = csz << 2; /* convert to bytes */
585
d70357d5 586 /* Initializes the hardware for all supported chipsets */
285f2dda 587 ret = ath9k_hw_init(ah);
d70357d5 588 if (ret)
285f2dda 589 goto err_hw;
55624204 590
6fb1b1e1
FF
591 if (pdata && pdata->macaddr)
592 memcpy(common->macaddr, pdata->macaddr, ETH_ALEN);
593
285f2dda
S
594 ret = ath9k_init_queues(sc);
595 if (ret)
596 goto err_queues;
597
598 ret = ath9k_init_btcoex(sc);
599 if (ret)
600 goto err_btcoex;
601
f209f529
FF
602 ret = ath9k_init_channels_rates(sc);
603 if (ret)
604 goto err_btcoex;
605
f82b4bde 606 ath9k_cmn_init_crypto(sc->sc_ah);
285f2dda 607 ath9k_init_misc(sc);
8f176a3a 608 ath_fill_led_pin(sc);
285f2dda 609
d09f5f4c
SM
610 if (common->bus_ops->aspm_init)
611 common->bus_ops->aspm_init(common);
612
55624204 613 return 0;
285f2dda
S
614
615err_btcoex:
55624204
S
616 for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++)
617 if (ATH_TXQ_SETUP(sc, i))
618 ath_tx_cleanupq(sc, &sc->tx.txq[i]);
285f2dda 619err_queues:
285f2dda
S
620 ath9k_hw_deinit(ah);
621err_hw:
55624204 622
285f2dda
S
623 kfree(ah);
624 sc->sc_ah = NULL;
625
626 return ret;
55624204
S
627}
628
babcbc29
FF
629static void ath9k_init_band_txpower(struct ath_softc *sc, int band)
630{
631 struct ieee80211_supported_band *sband;
632 struct ieee80211_channel *chan;
633 struct ath_hw *ah = sc->sc_ah;
babcbc29
FF
634 int i;
635
636 sband = &sc->sbands[band];
637 for (i = 0; i < sband->n_channels; i++) {
638 chan = &sband->channels[i];
639 ah->curchan = &ah->channels[chan->hw_value];
640 ath9k_cmn_update_ichannel(ah->curchan, chan, NL80211_CHAN_HT20);
641 ath9k_hw_set_txpowerlimit(ah, MAX_RATE_POWER, true);
babcbc29
FF
642 }
643}
644
645static void ath9k_init_txpower_limits(struct ath_softc *sc)
646{
647 struct ath_hw *ah = sc->sc_ah;
648 struct ath9k_channel *curchan = ah->curchan;
649
650 if (ah->caps.hw_caps & ATH9K_HW_CAP_2GHZ)
651 ath9k_init_band_txpower(sc, IEEE80211_BAND_2GHZ);
652 if (ah->caps.hw_caps & ATH9K_HW_CAP_5GHZ)
653 ath9k_init_band_txpower(sc, IEEE80211_BAND_5GHZ);
654
655 ah->curchan = curchan;
656}
657
43c35284
FF
658void ath9k_reload_chainmask_settings(struct ath_softc *sc)
659{
660 if (!(sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_HT))
661 return;
662
663 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_2GHZ)
664 setup_ht_cap(sc, &sc->sbands[IEEE80211_BAND_2GHZ].ht_cap);
665 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_5GHZ)
666 setup_ht_cap(sc, &sc->sbands[IEEE80211_BAND_5GHZ].ht_cap);
667}
668
20c8e8dc
FF
669static const struct ieee80211_iface_limit if_limits[] = {
670 { .max = 2048, .types = BIT(NL80211_IFTYPE_STATION) |
671 BIT(NL80211_IFTYPE_P2P_CLIENT) |
672 BIT(NL80211_IFTYPE_WDS) },
673 { .max = 8, .types =
674#ifdef CONFIG_MAC80211_MESH
675 BIT(NL80211_IFTYPE_MESH_POINT) |
676#endif
677 BIT(NL80211_IFTYPE_AP) |
678 BIT(NL80211_IFTYPE_P2P_GO) },
679};
680
681static const struct ieee80211_iface_combination if_comb = {
682 .limits = if_limits,
683 .n_limits = ARRAY_SIZE(if_limits),
684 .max_interfaces = 2048,
685 .num_different_channels = 1,
aebc0d40 686 .beacon_int_infra_match = true,
20c8e8dc 687};
43c35284 688
285f2dda 689void ath9k_set_hw_capab(struct ath_softc *sc, struct ieee80211_hw *hw)
55624204 690{
43c35284
FF
691 struct ath_hw *ah = sc->sc_ah;
692 struct ath_common *common = ath9k_hw_common(ah);
285f2dda 693
55624204
S
694 hw->flags = IEEE80211_HW_RX_INCLUDES_FCS |
695 IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING |
696 IEEE80211_HW_SIGNAL_DBM |
55624204
S
697 IEEE80211_HW_SUPPORTS_PS |
698 IEEE80211_HW_PS_NULLFUNC_STACK |
05df4986 699 IEEE80211_HW_SPECTRUM_MGMT |
bd8027a7 700 IEEE80211_HW_REPORTS_TX_ACK_STATUS;
55624204 701
5ffaf8a3
LR
702 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_HT)
703 hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION;
704
3e6109c5 705 if (AR_SREV_9160_10_OR_LATER(sc->sc_ah) || ath9k_modparam_nohwcrypt)
55624204
S
706 hw->flags |= IEEE80211_HW_MFP_CAPABLE;
707
708 hw->wiphy->interface_modes =
c426ee24
JB
709 BIT(NL80211_IFTYPE_P2P_GO) |
710 BIT(NL80211_IFTYPE_P2P_CLIENT) |
55624204 711 BIT(NL80211_IFTYPE_AP) |
e51f3eff 712 BIT(NL80211_IFTYPE_WDS) |
55624204
S
713 BIT(NL80211_IFTYPE_STATION) |
714 BIT(NL80211_IFTYPE_ADHOC) |
715 BIT(NL80211_IFTYPE_MESH_POINT);
716
20c8e8dc
FF
717 hw->wiphy->iface_combinations = &if_comb;
718 hw->wiphy->n_iface_combinations = 1;
719
008443de
LR
720 if (AR_SREV_5416(sc->sc_ah))
721 hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
55624204 722
cfdc9a8b 723 hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
fd656234 724 hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS;
81ddbb5c 725 hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
cfdc9a8b 726
9f11e16e
MSS
727#ifdef CONFIG_PM_SLEEP
728
729 if ((ah->caps.hw_caps & ATH9K_HW_WOW_DEVICE_CAPABLE) &&
730 device_can_wakeup(sc->dev)) {
731
732 hw->wiphy->wowlan.flags = WIPHY_WOWLAN_MAGIC_PKT |
733 WIPHY_WOWLAN_DISCONNECT;
734 hw->wiphy->wowlan.n_patterns = MAX_NUM_USER_PATTERN;
735 hw->wiphy->wowlan.pattern_min_len = 1;
736 hw->wiphy->wowlan.pattern_max_len = MAX_PATTERN_SIZE;
737
738 }
739
740 atomic_set(&sc->wow_sleep_proc_intr, -1);
741 atomic_set(&sc->wow_got_bmiss_intr, -1);
742
743#endif
744
55624204
S
745 hw->queues = 4;
746 hw->max_rates = 4;
747 hw->channel_change_time = 5000;
195ca3b1 748 hw->max_listen_interval = 1;
65896510 749 hw->max_rate_tries = 10;
55624204
S
750 hw->sta_data_size = sizeof(struct ath_node);
751 hw->vif_data_size = sizeof(struct ath_vif);
752
43c35284
FF
753 hw->wiphy->available_antennas_rx = BIT(ah->caps.max_rxchains) - 1;
754 hw->wiphy->available_antennas_tx = BIT(ah->caps.max_txchains) - 1;
755
756 /* single chain devices with rx diversity */
757 if (ah->caps.hw_caps & ATH9K_HW_CAP_ANT_DIV_COMB)
758 hw->wiphy->available_antennas_rx = BIT(0) | BIT(1);
759
760 sc->ant_rx = hw->wiphy->available_antennas_rx;
761 sc->ant_tx = hw->wiphy->available_antennas_tx;
762
6e5c2b4e 763#ifdef CONFIG_ATH9K_RATE_CONTROL
55624204 764 hw->rate_control_algorithm = "ath9k_rate_control";
6e5c2b4e 765#endif
55624204 766
d4659912 767 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_2GHZ)
55624204
S
768 hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
769 &sc->sbands[IEEE80211_BAND_2GHZ];
d4659912 770 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_5GHZ)
55624204
S
771 hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
772 &sc->sbands[IEEE80211_BAND_5GHZ];
285f2dda 773
43c35284 774 ath9k_reload_chainmask_settings(sc);
285f2dda
S
775
776 SET_IEEE80211_PERM_ADDR(hw, common->macaddr);
55624204
S
777}
778
eb93e891 779int ath9k_init_device(u16 devid, struct ath_softc *sc,
55624204
S
780 const struct ath_bus_ops *bus_ops)
781{
782 struct ieee80211_hw *hw = sc->hw;
783 struct ath_common *common;
784 struct ath_hw *ah;
285f2dda 785 int error = 0;
55624204
S
786 struct ath_regulatory *reg;
787
285f2dda 788 /* Bring up device */
eb93e891 789 error = ath9k_init_softc(devid, sc, bus_ops);
55624204 790 if (error != 0)
285f2dda 791 goto error_init;
55624204
S
792
793 ah = sc->sc_ah;
794 common = ath9k_hw_common(ah);
285f2dda 795 ath9k_set_hw_capab(sc, hw);
55624204 796
285f2dda 797 /* Initialize regulatory */
55624204
S
798 error = ath_regd_init(&common->regulatory, sc->hw->wiphy,
799 ath9k_reg_notifier);
800 if (error)
285f2dda 801 goto error_regd;
55624204
S
802
803 reg = &common->regulatory;
804
285f2dda 805 /* Setup TX DMA */
55624204
S
806 error = ath_tx_init(sc, ATH_TXBUF);
807 if (error != 0)
285f2dda 808 goto error_tx;
55624204 809
285f2dda 810 /* Setup RX DMA */
55624204
S
811 error = ath_rx_init(sc, ATH_RXBUF);
812 if (error != 0)
285f2dda 813 goto error_rx;
55624204 814
babcbc29
FF
815 ath9k_init_txpower_limits(sc);
816
0cf55c21
FF
817#ifdef CONFIG_MAC80211_LEDS
818 /* must be initialized before ieee80211_register_hw */
819 sc->led_cdev.default_trigger = ieee80211_create_tpt_led_trigger(sc->hw,
820 IEEE80211_TPT_LEDTRIG_FL_RADIO, ath9k_tpt_blink,
821 ARRAY_SIZE(ath9k_tpt_blink));
822#endif
823
285f2dda 824 /* Register with mac80211 */
55624204 825 error = ieee80211_register_hw(hw);
285f2dda
S
826 if (error)
827 goto error_register;
55624204 828
eb272441
BG
829 error = ath9k_init_debug(ah);
830 if (error) {
3800276a 831 ath_err(common, "Unable to create debugfs files\n");
eb272441
BG
832 goto error_world;
833 }
834
285f2dda 835 /* Handle world regulatory */
55624204
S
836 if (!ath_is_world_regd(reg)) {
837 error = regulatory_hint(hw->wiphy, reg->alpha2);
838 if (error)
285f2dda 839 goto error_world;
55624204
S
840 }
841
285f2dda 842 ath_init_leds(sc);
55624204
S
843 ath_start_rfkill_poll(sc);
844
845 return 0;
846
285f2dda
S
847error_world:
848 ieee80211_unregister_hw(hw);
849error_register:
850 ath_rx_cleanup(sc);
851error_rx:
852 ath_tx_cleanup(sc);
853error_tx:
854 /* Nothing */
855error_regd:
856 ath9k_deinit_softc(sc);
857error_init:
55624204
S
858 return error;
859}
860
861/*****************************/
862/* De-Initialization */
863/*****************************/
864
285f2dda 865static void ath9k_deinit_softc(struct ath_softc *sc)
55624204 866{
285f2dda 867 int i = 0;
55624204 868
f209f529
FF
869 if (sc->sbands[IEEE80211_BAND_2GHZ].channels)
870 kfree(sc->sbands[IEEE80211_BAND_2GHZ].channels);
871
872 if (sc->sbands[IEEE80211_BAND_5GHZ].channels)
873 kfree(sc->sbands[IEEE80211_BAND_5GHZ].channels);
874
5908120f 875 ath9k_deinit_btcoex(sc);
19686ddf 876
285f2dda
S
877 for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++)
878 if (ATH_TXQ_SETUP(sc, i))
879 ath_tx_cleanupq(sc, &sc->tx.txq[i]);
880
285f2dda 881 ath9k_hw_deinit(sc->sc_ah);
8e92d3f2
ZK
882 if (sc->dfs_detector != NULL)
883 sc->dfs_detector->exit(sc->dfs_detector);
285f2dda 884
736b3a27
S
885 kfree(sc->sc_ah);
886 sc->sc_ah = NULL;
55624204
S
887}
888
285f2dda 889void ath9k_deinit_device(struct ath_softc *sc)
55624204
S
890{
891 struct ieee80211_hw *hw = sc->hw;
55624204
S
892
893 ath9k_ps_wakeup(sc);
894
55624204 895 wiphy_rfkill_stop_polling(sc->hw->wiphy);
285f2dda 896 ath_deinit_leds(sc);
55624204 897
c7c18060
RM
898 ath9k_ps_restore(sc);
899
55624204
S
900 ieee80211_unregister_hw(hw);
901 ath_rx_cleanup(sc);
902 ath_tx_cleanup(sc);
285f2dda 903 ath9k_deinit_softc(sc);
55624204
S
904}
905
906void ath_descdma_cleanup(struct ath_softc *sc,
907 struct ath_descdma *dd,
908 struct list_head *head)
909{
910 dma_free_coherent(sc->dev, dd->dd_desc_len, dd->dd_desc,
911 dd->dd_desc_paddr);
912
913 INIT_LIST_HEAD(head);
914 kfree(dd->dd_bufptr);
915 memset(dd, 0, sizeof(*dd));
916}
917
55624204
S
918/************************/
919/* Module Hooks */
920/************************/
921
922static int __init ath9k_init(void)
923{
924 int error;
925
926 /* Register rate control algorithm */
927 error = ath_rate_control_register();
928 if (error != 0) {
516304b0
JP
929 pr_err("Unable to register rate control algorithm: %d\n",
930 error);
55624204
S
931 goto err_out;
932 }
933
55624204
S
934 error = ath_pci_init();
935 if (error < 0) {
516304b0 936 pr_err("No PCI devices found, driver not installed\n");
55624204 937 error = -ENODEV;
eb272441 938 goto err_rate_unregister;
55624204
S
939 }
940
941 error = ath_ahb_init();
942 if (error < 0) {
943 error = -ENODEV;
944 goto err_pci_exit;
945 }
946
947 return 0;
948
949 err_pci_exit:
950 ath_pci_exit();
951
55624204
S
952 err_rate_unregister:
953 ath_rate_control_unregister();
954 err_out:
955 return error;
956}
957module_init(ath9k_init);
958
959static void __exit ath9k_exit(void)
960{
d584747b 961 is_ath9k_unloaded = true;
55624204
S
962 ath_ahb_exit();
963 ath_pci_exit();
55624204 964 ath_rate_control_unregister();
516304b0 965 pr_info("%s: Driver unloaded\n", dev_info);
55624204
S
966}
967module_exit(ath9k_exit);
This page took 0.411759 seconds and 5 git commands to generate.