~yolanda.robla/ubuntu/saucy/ipxe/ftbfs

« back to all changes in this revision

Viewing changes to src/drivers/net/ath/ath9k/ath9k_init.c

  • Committer: Package Import Robot
  • Author(s): Marc Cluet, Marc Cluet, James Page
  • Date: 2012-02-10 16:21:23 UTC
  • mfrom: (1.1.2)
  • Revision ID: package-import@ubuntu.com-20120210162123-csroncqqnf8f7aw4
Tags: 1.0.0+git-3.55f6c88-0ubuntu1
[ Marc Cluet ]
* New upstream snapshot.
* Added rules for automatic git branch refresh.
* Changed rom target from allbaseroms to allroms.
  - recommended behaviour by upstream, building all full roms is neither
    recommended nor a desired user experience
* Added new target allqemu for qemu package.
  - created new build target to build full rom drivers just for qemu
    package purposes
* Cleaned lintian errors from debian package
  - Removed brace extension in ipxe.install
  - Updated standards to 3.9.2
  - Fixed copyright file not machine readable

[ James Page ]
* Updated get-orig-source target to generate git snapshots inline
  with upstream version numbering being used by this package. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (c) 2008-2011 Atheros Communications Inc.
 
3
 *
 
4
 * Modified for iPXE by Scott K Logan <logans@cottsay.net> July 2011
 
5
 * Original from Linux kernel 3.0.1
 
6
 *
 
7
 * Permission to use, copy, modify, and/or distribute this software for any
 
8
 * purpose with or without fee is hereby granted, provided that the above
 
9
 * copyright notice and this permission notice appear in all copies.
 
10
 *
 
11
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 
12
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 
13
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 
14
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 
15
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 
16
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 
17
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 
18
 */
 
19
 
 
20
#include <ipxe/malloc.h>
 
21
#include <ipxe/pci_io.h>
 
22
#include <ipxe/pci.h>
 
23
 
 
24
#include "ath9k.h"
 
25
 
 
26
int is_ath9k_unloaded;
 
27
/* We use the hw_value as an index into our private channel structure */
 
28
 
 
29
#define CHAN2G(_freq, _idx)  { \
 
30
        .band = NET80211_BAND_2GHZ, \
 
31
        .center_freq = (_freq), \
 
32
        .hw_value = (_idx), \
 
33
        .maxpower = 20, \
 
34
}
 
35
 
 
36
#define CHAN5G(_freq, _idx) { \
 
37
        .band = NET80211_BAND_5GHZ, \
 
38
        .center_freq = (_freq), \
 
39
        .hw_value = (_idx), \
 
40
        .maxpower = 20, \
 
41
}
 
42
 
 
43
/* Some 2 GHz radios are actually tunable on 2312-2732
 
44
 * on 5 MHz steps, we support the channels which we know
 
45
 * we have calibration data for all cards though to make
 
46
 * this static */
 
47
static const struct net80211_channel ath9k_2ghz_chantable[] = {
 
48
        CHAN2G(2412, 0), /* Channel 1 */
 
49
        CHAN2G(2417, 1), /* Channel 2 */
 
50
        CHAN2G(2422, 2), /* Channel 3 */
 
51
        CHAN2G(2427, 3), /* Channel 4 */
 
52
        CHAN2G(2432, 4), /* Channel 5 */
 
53
        CHAN2G(2437, 5), /* Channel 6 */
 
54
        CHAN2G(2442, 6), /* Channel 7 */
 
55
        CHAN2G(2447, 7), /* Channel 8 */
 
56
        CHAN2G(2452, 8), /* Channel 9 */
 
57
        CHAN2G(2457, 9), /* Channel 10 */
 
58
        CHAN2G(2462, 10), /* Channel 11 */
 
59
        CHAN2G(2467, 11), /* Channel 12 */
 
60
        CHAN2G(2472, 12), /* Channel 13 */
 
61
        CHAN2G(2484, 13), /* Channel 14 */
 
62
};
 
63
 
 
64
/* Some 5 GHz radios are actually tunable on XXXX-YYYY
 
65
 * on 5 MHz steps, we support the channels which we know
 
66
 * we have calibration data for all cards though to make
 
67
 * this static */
 
68
static const struct net80211_channel ath9k_5ghz_chantable[] = {
 
69
        /* _We_ call this UNII 1 */
 
70
        CHAN5G(5180, 14), /* Channel 36 */
 
71
        CHAN5G(5200, 15), /* Channel 40 */
 
72
        CHAN5G(5220, 16), /* Channel 44 */
 
73
        CHAN5G(5240, 17), /* Channel 48 */
 
74
        /* _We_ call this UNII 2 */
 
75
        CHAN5G(5260, 18), /* Channel 52 */
 
76
        CHAN5G(5280, 19), /* Channel 56 */
 
77
        CHAN5G(5300, 20), /* Channel 60 */
 
78
        CHAN5G(5320, 21), /* Channel 64 */
 
79
        /* _We_ call this "Middle band" */
 
80
        CHAN5G(5500, 22), /* Channel 100 */
 
81
        CHAN5G(5520, 23), /* Channel 104 */
 
82
        CHAN5G(5540, 24), /* Channel 108 */
 
83
        CHAN5G(5560, 25), /* Channel 112 */
 
84
        CHAN5G(5580, 26), /* Channel 116 */
 
85
        CHAN5G(5600, 27), /* Channel 120 */
 
86
        CHAN5G(5620, 28), /* Channel 124 */
 
87
        CHAN5G(5640, 29), /* Channel 128 */
 
88
        CHAN5G(5660, 30), /* Channel 132 */
 
89
        CHAN5G(5680, 31), /* Channel 136 */
 
90
        CHAN5G(5700, 32), /* Channel 140 */
 
91
        /* _We_ call this UNII 3 */
 
92
        CHAN5G(5745, 33), /* Channel 149 */
 
93
        CHAN5G(5765, 34), /* Channel 153 */
 
94
        CHAN5G(5785, 35), /* Channel 157 */
 
95
        CHAN5G(5805, 36), /* Channel 161 */
 
96
        CHAN5G(5825, 37), /* Channel 165 */
 
97
};
 
98
 
 
99
/* Atheros hardware rate code addition for short premble */
 
100
#define SHPCHECK(__hw_rate, __flags) \
 
101
        ((__flags & IEEE80211_TX_RC_USE_SHORT_PREAMBLE) ? (__hw_rate | 0x04 ) : 0)
 
102
 
 
103
#define RATE(_bitrate, _hw_rate, _flags) {              \
 
104
        .bitrate        = (_bitrate),                   \
 
105
        .flags          = (_flags),                     \
 
106
        .hw_value       = (_hw_rate),                   \
 
107
        .hw_value_short = (SHPCHECK(_hw_rate, _flags))  \
 
108
}
 
109
 
 
110
static struct ath9k_legacy_rate ath9k_legacy_rates[] = {
 
111
        RATE(10, 0x1b, 0),
 
112
        RATE(20, 0x1a, IEEE80211_TX_RC_USE_SHORT_PREAMBLE),
 
113
        RATE(55, 0x19, IEEE80211_TX_RC_USE_SHORT_PREAMBLE),
 
114
        RATE(110, 0x18, IEEE80211_TX_RC_USE_SHORT_PREAMBLE),
 
115
        RATE(60, 0x0b, 0),
 
116
        RATE(90, 0x0f, 0),
 
117
        RATE(120, 0x0a, 0),
 
118
        RATE(180, 0x0e, 0),
 
119
        RATE(240, 0x09, 0),
 
120
        RATE(360, 0x0d, 0),
 
121
        RATE(480, 0x08, 0),
 
122
        RATE(540, 0x0c, 0),
 
123
};
 
124
 
 
125
static void ath9k_deinit_softc(struct ath_softc *sc);
 
126
 
 
127
/*
 
128
 * Read and write, they both share the same lock. We do this to serialize
 
129
 * reads and writes on Atheros 802.11n PCI devices only. This is required
 
130
 * as the FIFO on these devices can only accept sanely 2 requests.
 
131
 */
 
132
 
 
133
static void ath9k_iowrite32(void *hw_priv, u32 val, u32 reg_offset)
 
134
{
 
135
        struct ath_hw *ah = (struct ath_hw *) hw_priv;
 
136
        struct ath_common *common = ath9k_hw_common(ah);
 
137
        struct ath_softc *sc = (struct ath_softc *) common->priv;
 
138
 
 
139
        writel(val, sc->mem + reg_offset);
 
140
}
 
141
 
 
142
static unsigned int ath9k_ioread32(void *hw_priv, u32 reg_offset)
 
143
{
 
144
        struct ath_hw *ah = (struct ath_hw *) hw_priv;
 
145
        struct ath_common *common = ath9k_hw_common(ah);
 
146
        struct ath_softc *sc = (struct ath_softc *) common->priv;
 
147
        u32 val;
 
148
 
 
149
        val = readl(sc->mem + reg_offset);
 
150
        return val;
 
151
}
 
152
 
 
153
static unsigned int ath9k_reg_rmw(void *hw_priv, u32 reg_offset, u32 set, u32 clr)
 
154
{
 
155
        struct ath_hw *ah = (struct ath_hw *) hw_priv;
 
156
        struct ath_common *common = ath9k_hw_common(ah);
 
157
        struct ath_softc *sc = (struct ath_softc *) common->priv;
 
158
        u32 val;
 
159
 
 
160
        val = readl(sc->mem + reg_offset);
 
161
        val &= ~clr;
 
162
        val |= set;
 
163
        writel(val, sc->mem + reg_offset);
 
164
 
 
165
        return val;
 
166
}
 
167
 
 
168
/**************************/
 
169
/*     Initialization     */
 
170
/**************************/
 
171
 
 
172
/*
 
173
 *  This function will allocate both the DMA descriptor structure, and the
 
174
 *  buffers it contains.  These are used to contain the descriptors used
 
175
 *  by the system.
 
176
*/
 
177
int ath_descdma_setup(struct ath_softc *sc, struct ath_descdma *dd,
 
178
                      struct list_head *head, const char *name,
 
179
                      int nbuf, int ndesc, int is_tx)
 
180
{
 
181
#define DS2PHYS(_dd, _ds)                                               \
 
182
        ((_dd)->dd_desc_paddr + ((char *)(_ds) - (char *)(_dd)->dd_desc))
 
183
#define ATH_DESC_4KB_BOUND_CHECK(_daddr) ((((_daddr) & 0xFFF) > 0xF9F) ? 1 : 0)
 
184
        u8 *ds;
 
185
        struct ath_buf *bf;
 
186
        int i, bsize, error, desc_len;
 
187
 
 
188
        DBG2("ath9k: %s DMA: %d buffers %d desc/buf\n",
 
189
                name, nbuf, ndesc);
 
190
 
 
191
        INIT_LIST_HEAD(head);
 
192
 
 
193
        if (is_tx)
 
194
                desc_len = sc->sc_ah->caps.tx_desc_len;
 
195
        else
 
196
                desc_len = sizeof(struct ath_desc);
 
197
 
 
198
        /* ath_desc must be a multiple of DWORDs */
 
199
        if ((desc_len % 4) != 0) {
 
200
                DBG("ath9k: ath_desc not DWORD aligned\n");
 
201
                error = -ENOMEM;
 
202
                goto fail;
 
203
        }
 
204
 
 
205
        dd->dd_desc_len = desc_len * nbuf * ndesc;
 
206
 
 
207
        /*
 
208
         * Need additional DMA memory because we can't use
 
209
         * descriptors that cross the 4K page boundary.
 
210
         * However, iPXE only utilizes 16 buffers, which
 
211
         * will never make up more than half of one page,
 
212
         * so we will only ever skip 1 descriptor, if that.
 
213
         */
 
214
        if (!(sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_4KB_SPLITTRANS)) {
 
215
                u32 ndesc_skipped = 1;
 
216
                u32 dma_len;
 
217
 
 
218
                dma_len = ndesc_skipped * desc_len;
 
219
                dd->dd_desc_len += dma_len;
 
220
        }
 
221
 
 
222
        /* allocate descriptors */
 
223
        dd->dd_desc = malloc_dma(dd->dd_desc_len, 16);
 
224
        if (dd->dd_desc == NULL) {
 
225
                error = -ENOMEM;
 
226
                goto fail;
 
227
        }
 
228
        dd->dd_desc_paddr = virt_to_bus(dd->dd_desc);
 
229
        ds = (u8 *) dd->dd_desc;
 
230
        DBG2("ath9k: %s DMA map: %p (%d) -> %llx (%d)\n",
 
231
                name, ds, (u32) dd->dd_desc_len,
 
232
                ito64(dd->dd_desc_paddr), /*XXX*/(u32) dd->dd_desc_len);
 
233
 
 
234
        /* allocate buffers */
 
235
        bsize = sizeof(struct ath_buf) * nbuf;
 
236
        bf = zalloc(bsize);
 
237
        if (bf == NULL) {
 
238
                error = -ENOMEM;
 
239
                goto fail2;
 
240
        }
 
241
        dd->dd_bufptr = bf;
 
242
 
 
243
        for (i = 0; i < nbuf; i++, bf++, ds += (desc_len * ndesc)) {
 
244
                bf->bf_desc = ds;
 
245
                bf->bf_daddr = DS2PHYS(dd, ds);
 
246
 
 
247
                if (!(sc->sc_ah->caps.hw_caps &
 
248
                      ATH9K_HW_CAP_4KB_SPLITTRANS)) {
 
249
                        /*
 
250
                         * Skip descriptor addresses which can cause 4KB
 
251
                         * boundary crossing (addr + length) with a 32 dword
 
252
                         * descriptor fetch.
 
253
                         */
 
254
                        while (ATH_DESC_4KB_BOUND_CHECK(bf->bf_daddr)) {
 
255
                                ds += (desc_len * ndesc);
 
256
                                bf->bf_desc = ds;
 
257
                                bf->bf_daddr = DS2PHYS(dd, ds);
 
258
                        }
 
259
                }
 
260
                list_add_tail(&bf->list, head);
 
261
        }
 
262
        return 0;
 
263
fail2:
 
264
        free_dma(dd->dd_desc, dd->dd_desc_len);
 
265
fail:
 
266
        memset(dd, 0, sizeof(*dd));
 
267
        return error;
 
268
#undef ATH_DESC_4KB_BOUND_CHECK
 
269
#undef DS2PHYS
 
270
}
 
271
 
 
272
void ath9k_init_crypto(struct ath_softc *sc)
 
273
{
 
274
        struct ath_common *common = ath9k_hw_common(sc->sc_ah);
 
275
        unsigned int i = 0;
 
276
 
 
277
        /* Get the hardware key cache size. */
 
278
        common->keymax = AR_KEYTABLE_SIZE;
 
279
 
 
280
        /*
 
281
         * Reset the key cache since some parts do not
 
282
         * reset the contents on initial power up.
 
283
         */
 
284
        for (i = 0; i < common->keymax; i++)
 
285
                ath_hw_keyreset(common, (u16) i);
 
286
 
 
287
        /*
 
288
         * Check whether the separate key cache entries
 
289
         * are required to handle both tx+rx MIC keys.
 
290
         * With split mic keys the number of stations is limited
 
291
         * to 27 otherwise 59.
 
292
         */
 
293
        if (sc->sc_ah->misc_mode & AR_PCU_MIC_NEW_LOC_ENA)
 
294
                common->crypt_caps |= ATH_CRYPT_CAP_MIC_COMBINED;
 
295
}
 
296
 
 
297
static int ath9k_init_queues(struct ath_softc *sc)
 
298
{
 
299
        int i = 0;
 
300
 
 
301
        for (i = 0; i < WME_NUM_AC; i++) {
 
302
                sc->tx.txq_map[i] = ath_txq_setup(sc, ATH9K_TX_QUEUE_DATA, i);
 
303
                sc->tx.txq_map[i]->mac80211_qnum = i;
 
304
        }
 
305
        return 0;
 
306
}
 
307
 
 
308
static int ath9k_init_channels_rates(struct ath_softc *sc)
 
309
{
 
310
        unsigned int i;
 
311
 
 
312
        memcpy(&sc->rates, ath9k_legacy_rates, sizeof(ath9k_legacy_rates));
 
313
 
 
314
        if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_2GHZ) {
 
315
                memcpy(&sc->hwinfo->channels[sc->hwinfo->nr_channels], ath9k_2ghz_chantable, sizeof(ath9k_2ghz_chantable));
 
316
 
 
317
                sc->hwinfo->nr_channels += ARRAY_SIZE(ath9k_2ghz_chantable);
 
318
 
 
319
                for (i = 0; i < ARRAY_SIZE(ath9k_legacy_rates); i++)
 
320
                        sc->hwinfo->rates[NET80211_BAND_2GHZ][i] = ath9k_legacy_rates[i].bitrate;
 
321
                sc->hwinfo->nr_rates[NET80211_BAND_2GHZ] = ARRAY_SIZE(ath9k_legacy_rates);
 
322
        }
 
323
 
 
324
        if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_5GHZ) {
 
325
                memcpy(&sc->hwinfo->channels[sc->hwinfo->nr_channels], ath9k_5ghz_chantable, sizeof(ath9k_5ghz_chantable));
 
326
 
 
327
                sc->hwinfo->nr_channels += ARRAY_SIZE(ath9k_5ghz_chantable);
 
328
 
 
329
                for (i = 4; i < ARRAY_SIZE(ath9k_legacy_rates); i++)
 
330
                        sc->hwinfo->rates[NET80211_BAND_5GHZ][i - 4] = ath9k_legacy_rates[i].bitrate;
 
331
                sc->hwinfo->nr_rates[NET80211_BAND_5GHZ] = ARRAY_SIZE(ath9k_legacy_rates) - 4;
 
332
        }
 
333
        return 0;
 
334
}
 
335
 
 
336
static void ath9k_init_misc(struct ath_softc *sc)
 
337
{
 
338
        struct ath_common *common = ath9k_hw_common(sc->sc_ah);
 
339
 
 
340
        common->ani.timer = 0;
 
341
 
 
342
        sc->config.txpowlimit = ATH_TXPOWER_MAX;
 
343
 
 
344
        common->tx_chainmask = sc->sc_ah->caps.tx_chainmask;
 
345
        common->rx_chainmask = sc->sc_ah->caps.rx_chainmask;
 
346
 
 
347
        ath9k_hw_set_diversity(sc->sc_ah, 1);
 
348
        sc->rx.defant = ath9k_hw_getdefantenna(sc->sc_ah);
 
349
 
 
350
        memcpy(common->bssidmask, ath_bcast_mac, ETH_ALEN);
 
351
}
 
352
 
 
353
static int ath9k_init_softc(u16 devid, struct ath_softc *sc, u16 subsysid,
 
354
                            const struct ath_bus_ops *bus_ops)
 
355
{
 
356
        struct ath_hw *ah = NULL;
 
357
        struct ath_common *common;
 
358
        int ret = 0, i;
 
359
        int csz = 0;
 
360
 
 
361
        ah = zalloc(sizeof(struct ath_hw));
 
362
        if (!ah)
 
363
                return -ENOMEM;
 
364
 
 
365
        ah->dev = sc->dev;
 
366
        ah->hw_version.devid = devid;
 
367
        ah->hw_version.subsysid = subsysid;
 
368
        ah->reg_ops.read = ath9k_ioread32;
 
369
        ah->reg_ops.write = ath9k_iowrite32;
 
370
        ah->reg_ops.rmw = ath9k_reg_rmw;
 
371
        sc->sc_ah = ah;
 
372
 
 
373
        sc->hwinfo = zalloc(sizeof(*sc->hwinfo));
 
374
        if (!sc->hwinfo) {
 
375
                DBG("ath9k: cannot allocate 802.11 hardware info structure\n");
 
376
                return -ENOMEM;
 
377
        }
 
378
 
 
379
        ah->ah_flags |= AH_USE_EEPROM;
 
380
        sc->sc_ah->led_pin = -1;
 
381
 
 
382
        common = ath9k_hw_common(ah);
 
383
        common->ops = &ah->reg_ops;
 
384
        common->bus_ops = bus_ops;
 
385
        common->ah = ah;
 
386
        common->dev = sc->dev;
 
387
        common->priv = sc;
 
388
 
 
389
        sc->intr_tq = ath9k_tasklet;
 
390
 
 
391
        /*
 
392
         * Cache line size is used to size and align various
 
393
         * structures used to communicate with the hardware.
 
394
         */
 
395
        ath_read_cachesize(common, &csz);
 
396
        common->cachelsz = csz << 2; /* convert to bytes */
 
397
 
 
398
        /* Initializes the hardware for all supported chipsets */
 
399
        ret = ath9k_hw_init(ah);
 
400
        if (ret)
 
401
                goto err_hw;
 
402
 
 
403
        memcpy(sc->hwinfo->hwaddr, common->macaddr, ETH_ALEN);
 
404
 
 
405
        ret = ath9k_init_queues(sc);
 
406
        if (ret)
 
407
                goto err_queues;
 
408
 
 
409
        ret = ath9k_init_channels_rates(sc);
 
410
        if (ret)
 
411
                goto err_btcoex;
 
412
 
 
413
        ath9k_init_crypto(sc);
 
414
        ath9k_init_misc(sc);
 
415
 
 
416
        return 0;
 
417
 
 
418
err_btcoex:
 
419
        for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++)
 
420
                if (ATH_TXQ_SETUP(sc, i))
 
421
                        ath_tx_cleanupq(sc, &sc->tx.txq[i]);
 
422
err_queues:
 
423
        ath9k_hw_deinit(ah);
 
424
err_hw:
 
425
        free(sc->hwinfo);
 
426
        sc->hwinfo = NULL;
 
427
 
 
428
        free(ah);
 
429
        sc->sc_ah = NULL;
 
430
 
 
431
        return ret;
 
432
}
 
433
 
 
434
static void ath9k_init_band_txpower(struct ath_softc *sc, int band)
 
435
{
 
436
        struct net80211_channel *chan;
 
437
        struct ath_hw *ah = sc->sc_ah;
 
438
        struct ath_regulatory *reg = ath9k_hw_regulatory(ah);
 
439
        int i;
 
440
 
 
441
        for (i = 0; i < sc->hwinfo->nr_channels; i++) {
 
442
                chan = &sc->hwinfo->channels[i];
 
443
                if(chan->band != band)
 
444
                        continue;
 
445
                ah->curchan = &ah->channels[chan->hw_value];
 
446
                ath9k_hw_set_txpowerlimit(ah, MAX_RATE_POWER, 1);
 
447
                chan->maxpower = reg->max_power_level / 2;
 
448
        }
 
449
}
 
450
 
 
451
static void ath9k_init_txpower_limits(struct ath_softc *sc)
 
452
{
 
453
        struct ath_hw *ah = sc->sc_ah;
 
454
        struct ath9k_channel *curchan = ah->curchan;
 
455
 
 
456
        if (ah->caps.hw_caps & ATH9K_HW_CAP_2GHZ)
 
457
                ath9k_init_band_txpower(sc, NET80211_BAND_2GHZ);
 
458
        if (ah->caps.hw_caps & ATH9K_HW_CAP_5GHZ)
 
459
                ath9k_init_band_txpower(sc, NET80211_BAND_5GHZ);
 
460
 
 
461
        ah->curchan = curchan;
 
462
}
 
463
 
 
464
void ath9k_set_hw_capab(struct ath_softc *sc, struct net80211_device *dev __unused)
 
465
{
 
466
        sc->hwinfo->flags = NET80211_HW_RX_HAS_FCS;
 
467
        sc->hwinfo->signal_type = NET80211_SIGNAL_DB;
 
468
        sc->hwinfo->signal_max = 40; /* 35dB should give perfect 54Mbps */
 
469
        sc->hwinfo->channel_change_time = 5000;
 
470
 
 
471
        if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_2GHZ)
 
472
        {
 
473
                sc->hwinfo->bands |= NET80211_BAND_BIT_2GHZ;
 
474
                sc->hwinfo->modes |= NET80211_MODE_B | NET80211_MODE_G;
 
475
        }
 
476
        if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_5GHZ)
 
477
        {
 
478
                sc->hwinfo->bands |= NET80211_BAND_BIT_5GHZ;
 
479
                sc->hwinfo->modes |= NET80211_MODE_A;
 
480
        }
 
481
}
 
482
 
 
483
int ath9k_init_device(u16 devid, struct ath_softc *sc, u16 subsysid,
 
484
                    const struct ath_bus_ops *bus_ops)
 
485
{
 
486
        struct net80211_device *dev = sc->dev;
 
487
        /*struct ath_common *common;
 
488
        struct ath_hw *ah;*/
 
489
        int error = 0;
 
490
        /*struct ath_regulatory *reg;*/
 
491
 
 
492
        /* Bring up device */
 
493
        error = ath9k_init_softc(devid, sc, subsysid, bus_ops);
 
494
        if (error != 0)
 
495
                goto error_init;
 
496
 
 
497
        /*ah = sc->sc_ah;
 
498
        common = ath9k_hw_common(ah);*/
 
499
        ath9k_set_hw_capab(sc, dev);
 
500
        /* TODO Cottsay: reg */
 
501
        /* Initialize regulatory */
 
502
        /*error = ath_regd_init(&common->regulatory, sc->dev->wiphy,
 
503
                              ath9k_reg_notifier);
 
504
        if (error)
 
505
                goto error_regd;
 
506
 
 
507
        reg = &common->regulatory;*/
 
508
 
 
509
        /* Setup TX DMA */
 
510
        error = ath_tx_init(sc, ATH_TXBUF);
 
511
        if (error != 0)
 
512
                goto error_tx;
 
513
 
 
514
        /* Setup RX DMA */
 
515
        error = ath_rx_init(sc, ATH_RXBUF);
 
516
        if (error != 0)
 
517
                goto error_rx;
 
518
 
 
519
        ath9k_init_txpower_limits(sc);
 
520
 
 
521
        /* Register with mac80211 */
 
522
        error = net80211_register(dev, &ath9k_ops, sc->hwinfo);
 
523
        if (error)
 
524
                goto error_register;
 
525
 
 
526
        /* TODO Cottsay: reg */
 
527
        /* Handle world regulatory */
 
528
        /*if (!ath_is_world_regd(reg)) {
 
529
                error = regulatory_hint(hw->wiphy, reg->alpha2);
 
530
                if (error)
 
531
                        goto error_world;
 
532
        }*/
 
533
 
 
534
        sc->hw_pll_work = ath_hw_pll_work;
 
535
        sc->last_rssi = ATH_RSSI_DUMMY_MARKER;
 
536
 
 
537
        /* TODO Cottsay: rfkill */
 
538
        /*ath_start_rfkill_poll(sc);*/
 
539
 
 
540
        return 0;
 
541
 
 
542
//error_world:
 
543
//      net80211_unregister(dev);
 
544
error_register:
 
545
        ath_rx_cleanup(sc);
 
546
error_rx:
 
547
        ath_tx_cleanup(sc);
 
548
error_tx:
 
549
        ath9k_deinit_softc(sc);
 
550
error_init:
 
551
        return error;
 
552
}
 
553
 
 
554
/*****************************/
 
555
/*     De-Initialization     */
 
556
/*****************************/
 
557
 
 
558
static void ath9k_deinit_softc(struct ath_softc *sc)
 
559
{
 
560
        int i = 0;
 
561
 
 
562
        for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++)
 
563
                if (ATH_TXQ_SETUP(sc, i))
 
564
                        ath_tx_cleanupq(sc, &sc->tx.txq[i]);
 
565
 
 
566
        ath9k_hw_deinit(sc->sc_ah);
 
567
 
 
568
        free(sc->hwinfo);
 
569
        sc->hwinfo = NULL;
 
570
        free(sc->sc_ah);
 
571
        sc->sc_ah = NULL;
 
572
}
 
573
 
 
574
void ath9k_deinit_device(struct ath_softc *sc)
 
575
{
 
576
        struct net80211_device *dev = sc->dev;
 
577
 
 
578
        net80211_unregister(dev);
 
579
        ath_rx_cleanup(sc);
 
580
        ath_tx_cleanup(sc);
 
581
        ath9k_deinit_softc(sc);
 
582
}
 
583
 
 
584
void ath_descdma_cleanup(struct ath_softc *sc __unused,
 
585
                         struct ath_descdma *dd,
 
586
                         struct list_head *head)
 
587
{
 
588
        free_dma(dd->dd_desc, dd->dd_desc_len);
 
589
 
 
590
        INIT_LIST_HEAD(head);
 
591
        free(dd->dd_bufptr);
 
592
        memset(dd, 0, sizeof(*dd));
 
593
}