blob: 546bae93647b859e46bd95cc68f37ed0aef4526a [file] [log] [blame]
Sujith55624202010-01-08 10:36:02 +05301/*
Sujith Manoharan5b681382011-05-17 13:36:18 +05302 * Copyright (c) 2008-2011 Atheros Communications Inc.
Sujith55624202010-01-08 10:36:02 +05303 *
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
Joe Perches516304b2012-03-18 17:30:52 -070017#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
18
Alexey Dobriyanb7f080c2011-06-16 11:01:34 +000019#include <linux/dma-mapping.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090020#include <linux/slab.h>
Felix Fietkau6fb1b1e2011-03-19 13:55:39 +010021#include <linux/ath9k_platform.h>
Paul Gortmaker9d9779e2011-07-03 15:21:01 -040022#include <linux/module.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090023
Sujith55624202010-01-08 10:36:02 +053024#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
John W. Linville3e6109c2011-01-05 09:39:17 -050037int ath9k_modparam_nohwcrypt;
38module_param_named(nohwcrypt, ath9k_modparam_nohwcrypt, int, 0444);
Sujith55624202010-01-08 10:36:02 +053039MODULE_PARM_DESC(nohwcrypt, "Disable hardware encryption");
40
Vivek Natarajan93dbbcc2010-08-25 19:34:52 +053041int led_blink;
Vivek Natarajan9a75c2f2010-06-22 11:52:37 +053042module_param_named(blink, led_blink, int, 0444);
43MODULE_PARM_DESC(blink, "Enable LED blink on activity");
44
Vasanthakumar Thiagarajan8f5dcb12010-11-26 06:10:06 -080045static int ath9k_btcoex_enable;
46module_param_named(btcoex_enable, ath9k_btcoex_enable, int, 0444);
47MODULE_PARM_DESC(btcoex_enable, "Enable wifi-BT coexistence");
48
Sujith Manoharane09f2dc2012-09-16 08:06:56 +053049static 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
Rajkumar Manoharand5847472010-12-20 14:39:51 +053053bool is_ath9k_unloaded;
Sujith55624202010-01-08 10:36:02 +053054/* We use the hw_value as an index into our private channel structure */
55
56#define CHAN2G(_freq, _idx) { \
Mohammed Shafi Shajakhanb1c1d002010-12-17 20:44:36 +053057 .band = IEEE80211_BAND_2GHZ, \
Sujith55624202010-01-08 10:36:02 +053058 .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 */
Felix Fietkauf209f522010-10-01 01:06:53 +020074static const struct ieee80211_channel ath9k_2ghz_chantable[] = {
Sujith55624202010-01-08 10:36:02 +053075 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 */
Felix Fietkauf209f522010-10-01 01:06:53 +020095static const struct ieee80211_channel ath9k_5ghz_chantable[] = {
Sujith55624202010-01-08 10:36:02 +053096 /* _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
Felix Fietkau0cf55c22011-02-27 22:26:40 +0100152#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
Sujith285f2dd2010-01-08 10:36:07 +0530167static void ath9k_deinit_softc(struct ath_softc *sc);
Sujith55624202010-01-08 10:36:02 +0530168
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
Felix Fietkauf3eef642012-03-14 16:40:25 +0100181 if (NR_CPUS > 1 && ah->config.serialize_regmode == SER_REG_MODE_ON) {
Sujith55624202010-01-08 10:36:02 +0530182 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
Felix Fietkauf3eef642012-03-14 16:40:25 +0100197 if (NR_CPUS > 1 && ah->config.serialize_regmode == SER_REG_MODE_ON) {
Sujith55624202010-01-08 10:36:02 +0530198 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
Rajkumar Manoharan5479de62011-07-17 11:43:02 +0530207static 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
Felix Fietkau845e03c2011-03-23 20:57:25 +0100220static 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
Felix Fietkauf3eef642012-03-14 16:40:25 +0100228 if (NR_CPUS > 1 && ah->config.serialize_regmode == SER_REG_MODE_ON) {
Felix Fietkau845e03c2011-03-23 20:57:25 +0100229 spin_lock_irqsave(&sc->sc_serial_rw, flags);
Rajkumar Manoharan5479de62011-07-17 11:43:02 +0530230 val = __ath9k_reg_rmw(sc, reg_offset, set, clr);
Felix Fietkau845e03c2011-03-23 20:57:25 +0100231 spin_unlock_irqrestore(&sc->sc_serial_rw, flags);
Rajkumar Manoharan5479de62011-07-17 11:43:02 +0530232 } else
233 val = __ath9k_reg_rmw(sc, reg_offset, set, clr);
Felix Fietkau845e03c2011-03-23 20:57:25 +0100234
235 return val;
236}
237
Sujith55624202010-01-08 10:36:02 +0530238/**************************/
239/* Initialization */
240/**************************/
241
242static void setup_ht_cap(struct ath_softc *sc,
243 struct ieee80211_sta_ht_cap *ht_info)
244{
Felix Fietkau3bb065a2010-04-19 19:57:34 +0200245 struct ath_hw *ah = sc->sc_ah;
246 struct ath_common *common = ath9k_hw_common(ah);
Sujith55624202010-01-08 10:36:02 +0530247 u8 tx_streams, rx_streams;
Felix Fietkau3bb065a2010-04-19 19:57:34 +0200248 int i, max_streams;
Sujith55624202010-01-08 10:36:02 +0530249
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
Luis R. Rodriguezb0a33442010-04-15 17:39:39 -0400256 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_LDPC)
257 ht_info->cap |= IEEE80211_HT_CAP_LDPC_CODING;
258
Vasanthakumar Thiagarajan6473d242010-05-13 18:42:38 -0700259 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_SGI_20)
260 ht_info->cap |= IEEE80211_HT_CAP_SGI_20;
261
Sujith55624202010-01-08 10:36:02 +0530262 ht_info->ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
263 ht_info->ampdu_density = IEEE80211_HT_MPDU_DENSITY_8;
264
Sujith Manoharane41db612012-09-10 09:20:12 +0530265 if (AR_SREV_9330(ah) || AR_SREV_9485(ah) || AR_SREV_9565(ah))
Vasanthakumar Thiagarajan7f1c7a62010-12-06 04:27:41 -0800266 max_streams = 1;
Mohammed Shafi Shajakhane7104192011-12-01 18:14:01 +0530267 else if (AR_SREV_9462(ah))
268 max_streams = 2;
Vasanthakumar Thiagarajan7f1c7a62010-12-06 04:27:41 -0800269 else if (AR_SREV_9300_20_OR_LATER(ah))
Felix Fietkau3bb065a2010-04-19 19:57:34 +0200270 max_streams = 3;
271 else
272 max_streams = 2;
273
Felix Fietkau7a370812010-09-22 12:34:52 +0200274 if (AR_SREV_9280_20_OR_LATER(ah)) {
Felix Fietkau074a8c02010-04-19 19:57:36 +0200275 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
Sujith55624202010-01-08 10:36:02 +0530280 /* set up supported mcs set */
281 memset(&ht_info->mcs, 0, sizeof(ht_info->mcs));
Felix Fietkau82b2d332011-09-03 01:40:23 +0200282 tx_streams = ath9k_cmn_count_streams(ah->txchainmask, max_streams);
283 rx_streams = ath9k_cmn_count_streams(ah->rxchainmask, max_streams);
Felix Fietkau3bb065a2010-04-19 19:57:34 +0200284
Joe Perchesd2182b62011-12-15 14:55:53 -0800285 ath_dbg(common, CONFIG, "TX streams %d, RX streams: %d\n",
Joe Perches226afe62010-12-02 19:12:37 -0800286 tx_streams, rx_streams);
Sujith55624202010-01-08 10:36:02 +0530287
288 if (tx_streams != rx_streams) {
Sujith55624202010-01-08 10:36:02 +0530289 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
Felix Fietkau3bb065a2010-04-19 19:57:34 +0200294 for (i = 0; i < rx_streams; i++)
295 ht_info->mcs.rx_mask[i] = 0xff;
Sujith55624202010-01-08 10:36:02 +0530296
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);
Felix Fietkau9ac586152011-01-24 19:23:18 +0100304 struct ath_softc *sc = hw->priv;
Rajkumar Manoharan687f5452011-12-08 23:59:25 +0530305 struct ath_hw *ah = sc->sc_ah;
306 struct ath_regulatory *reg = ath9k_hw_regulatory(ah);
307 int ret;
Sujith55624202010-01-08 10:36:02 +0530308
Rajkumar Manoharan687f5452011-12-08 23:59:25 +0530309 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 }
319
320 return ret;
Sujith55624202010-01-08 10:36:02 +0530321}
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,
Vasanthakumar Thiagarajan4adfcde2010-04-15 17:39:33 -0400330 int nbuf, int ndesc, bool is_tx)
Sujith55624202010-01-08 10:36:02 +0530331{
Sujith55624202010-01-08 10:36:02 +0530332 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Vasanthakumar Thiagarajan4adfcde2010-04-15 17:39:33 -0400333 u8 *ds;
Sujith55624202010-01-08 10:36:02 +0530334 struct ath_buf *bf;
Vasanthakumar Thiagarajan4adfcde2010-04-15 17:39:33 -0400335 int i, bsize, error, desc_len;
Sujith55624202010-01-08 10:36:02 +0530336
Joe Perchesd2182b62011-12-15 14:55:53 -0800337 ath_dbg(common, CONFIG, "%s DMA: %u buffers %u desc/buf\n",
Joe Perches226afe62010-12-02 19:12:37 -0800338 name, nbuf, ndesc);
Sujith55624202010-01-08 10:36:02 +0530339
340 INIT_LIST_HEAD(head);
Vasanthakumar Thiagarajan4adfcde2010-04-15 17:39:33 -0400341
342 if (is_tx)
343 desc_len = sc->sc_ah->caps.tx_desc_len;
344 else
345 desc_len = sizeof(struct ath_desc);
346
Sujith55624202010-01-08 10:36:02 +0530347 /* ath_desc must be a multiple of DWORDs */
Vasanthakumar Thiagarajan4adfcde2010-04-15 17:39:33 -0400348 if ((desc_len % 4) != 0) {
Joe Perches38002762010-12-02 19:12:36 -0800349 ath_err(common, "ath_desc not DWORD aligned\n");
Vasanthakumar Thiagarajan4adfcde2010-04-15 17:39:33 -0400350 BUG_ON((desc_len % 4) != 0);
Sujith55624202010-01-08 10:36:02 +0530351 error = -ENOMEM;
352 goto fail;
353 }
354
Vasanthakumar Thiagarajan4adfcde2010-04-15 17:39:33 -0400355 dd->dd_desc_len = desc_len * nbuf * ndesc;
Sujith55624202010-01-08 10:36:02 +0530356
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) {
Vasanthakumar Thiagarajan4adfcde2010-04-15 17:39:33 -0400368 dma_len = ndesc_skipped * desc_len;
Sujith55624202010-01-08 10:36:02 +0530369 dd->dd_desc_len += dma_len;
370
371 ndesc_skipped = ATH_DESC_4KB_BOUND_NUM_SKIPPED(dma_len);
Joe Perchesee289b62010-05-17 22:47:34 -0700372 }
Sujith55624202010-01-08 10:36:02 +0530373 }
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 }
Vasanthakumar Thiagarajan4adfcde2010-04-15 17:39:33 -0400382 ds = (u8 *) dd->dd_desc;
Joe Perchesd2182b62011-12-15 14:55:53 -0800383 ath_dbg(common, CONFIG, "%s DMA map: %p (%u) -> %llx (%u)\n",
Joe Perches226afe62010-12-02 19:12:37 -0800384 name, ds, (u32) dd->dd_desc_len,
385 ito64(dd->dd_desc_paddr), /*XXX*/(u32) dd->dd_desc_len);
Sujith55624202010-01-08 10:36:02 +0530386
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
Vasanthakumar Thiagarajan4adfcde2010-04-15 17:39:33 -0400396 for (i = 0; i < nbuf; i++, bf++, ds += (desc_len * ndesc)) {
Sujith55624202010-01-08 10:36:02 +0530397 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
Vasanthakumar Thiagarajan4adfcde2010-04-15 17:39:33 -0400412 ds += (desc_len * ndesc);
Sujith55624202010-01-08 10:36:02 +0530413 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;
Sujith55624202010-01-08 10:36:02 +0530426}
427
Sujith285f2dd2010-01-08 10:36:07 +0530428static int ath9k_init_queues(struct ath_softc *sc)
429{
Sujith285f2dd2010-01-08 10:36:07 +0530430 int i = 0;
Sujith55624202010-01-08 10:36:02 +0530431
Sujith285f2dd2010-01-08 10:36:07 +0530432 sc->beacon.beaconq = ath9k_hw_beaconq_setup(sc->sc_ah);
Sujith285f2dd2010-01-08 10:36:07 +0530433 sc->beacon.cabq = ath_txq_setup(sc, ATH9K_TX_QUEUE_CAB, 0);
Sujith55624202010-01-08 10:36:02 +0530434
Sujith285f2dd2010-01-08 10:36:07 +0530435 sc->config.cabqReadytime = ATH_CABQ_READY_TIME;
436 ath_cabq_update(sc);
437
Ben Greear60f2d1d2011-01-09 23:11:52 -0800438 for (i = 0; i < WME_NUM_AC; i++) {
Felix Fietkau066dae92010-11-07 14:59:39 +0100439 sc->tx.txq_map[i] = ath_txq_setup(sc, ATH9K_TX_QUEUE_DATA, i);
Ben Greear60f2d1d2011-01-09 23:11:52 -0800440 sc->tx.txq_map[i]->mac80211_qnum = i;
Felix Fietkau7702e782012-07-15 19:53:35 +0200441 sc->tx.txq_max_pending[i] = ATH_MAX_QDEPTH;
Ben Greear60f2d1d2011-01-09 23:11:52 -0800442 }
Sujith285f2dd2010-01-08 10:36:07 +0530443 return 0;
Sujith285f2dd2010-01-08 10:36:07 +0530444}
445
Felix Fietkauf209f522010-10-01 01:06:53 +0200446static int ath9k_init_channels_rates(struct ath_softc *sc)
Sujith285f2dd2010-01-08 10:36:07 +0530447{
Felix Fietkauf209f522010-10-01 01:06:53 +0200448 void *channels;
449
Felix Fietkaucac42202010-10-09 02:39:30 +0200450 BUILD_BUG_ON(ARRAY_SIZE(ath9k_2ghz_chantable) +
451 ARRAY_SIZE(ath9k_5ghz_chantable) !=
452 ATH9K_NUM_CHANNELS);
453
Felix Fietkaud4659912010-10-14 16:02:39 +0200454 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_2GHZ) {
Felix Fietkauf209f522010-10-01 01:06:53 +0200455 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;
Sujith55624202010-01-08 10:36:02 +0530461 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);
467 }
468
Felix Fietkaud4659912010-10-14 16:02:39 +0200469 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_5GHZ) {
Felix Fietkauf209f522010-10-01 01:06:53 +0200470 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;
Sujith55624202010-01-08 10:36:02 +0530479 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 }
Felix Fietkauf209f522010-10-01 01:06:53 +0200487 return 0;
Sujith285f2dd2010-01-08 10:36:07 +0530488}
Sujith55624202010-01-08 10:36:02 +0530489
Sujith285f2dd2010-01-08 10:36:07 +0530490static void ath9k_init_misc(struct ath_softc *sc)
491{
492 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
493 int i = 0;
Sujith Manoharan3d4e20f2012-03-14 14:40:58 +0530494
Sujith285f2dd2010-01-08 10:36:07 +0530495 setup_timer(&common->ani.timer, ath_ani_calibrate, (unsigned long)sc);
496
Sujith Manoharanaaa1ec42012-06-04 16:27:08 +0530497 sc->last_rssi = ATH_RSSI_DUMMY_MARKER;
Sujith285f2dd2010-01-08 10:36:07 +0530498 sc->config.txpowlimit = ATH_TXPOWER_MAX;
Felix Fietkau364734f2010-09-14 20:22:44 +0200499 memcpy(common->bssidmask, ath_bcast_mac, ETH_ALEN);
Sujith285f2dd2010-01-08 10:36:07 +0530500 sc->beacon.slottime = ATH9K_SLOT_TIME_9;
501
Felix Fietkau7545daf2011-01-24 19:23:16 +0100502 for (i = 0; i < ARRAY_SIZE(sc->beacon.bslot); i++)
Sujith285f2dd2010-01-08 10:36:07 +0530503 sc->beacon.bslot[i] = NULL;
Vasanthakumar Thiagarajan102885a2010-09-02 01:34:43 -0700504
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;
Sujith285f2dd2010-01-08 10:36:07 +0530507}
508
Pavel Roskineb93e892011-07-23 03:55:39 -0400509static int ath9k_init_softc(u16 devid, struct ath_softc *sc,
Sujith285f2dd2010-01-08 10:36:07 +0530510 const struct ath_bus_ops *bus_ops)
511{
Felix Fietkau6fb1b1e2011-03-19 13:55:39 +0100512 struct ath9k_platform_data *pdata = sc->dev->platform_data;
Sujith285f2dd2010-01-08 10:36:07 +0530513 struct ath_hw *ah = NULL;
514 struct ath_common *common;
515 int ret = 0, i;
516 int csz = 0;
517
Sujith285f2dd2010-01-08 10:36:07 +0530518 ah = kzalloc(sizeof(struct ath_hw), GFP_KERNEL);
519 if (!ah)
520 return -ENOMEM;
521
Ben Greear233536e2011-01-09 23:11:44 -0800522 ah->hw = sc->hw;
Sujith285f2dd2010-01-08 10:36:07 +0530523 ah->hw_version.devid = devid;
Felix Fietkauf9f84e92011-03-23 20:57:24 +0100524 ah->reg_ops.read = ath9k_ioread32;
525 ah->reg_ops.write = ath9k_iowrite32;
Felix Fietkau845e03c2011-03-23 20:57:25 +0100526 ah->reg_ops.rmw = ath9k_reg_rmw;
Rajkumar Manoharane8fe7332011-08-05 18:59:41 +0530527 atomic_set(&ah->intr_ref_cnt, -1);
Sujith285f2dd2010-01-08 10:36:07 +0530528 sc->sc_ah = ah;
529
Zefir Kurtisi8e92d3f2012-04-03 17:15:50 +0200530 sc->dfs_detector = dfs_pattern_detector_init(NL80211_DFS_UNSET);
531
Felix Fietkau6de66dd2011-03-19 13:55:40 +0100532 if (!pdata) {
Felix Fietkaua05b5d452010-11-17 04:25:33 +0100533 ah->ah_flags |= AH_USE_EEPROM;
Felix Fietkau6de66dd2011-03-19 13:55:40 +0100534 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;
Vasanthakumar Thiagarajanf2f5f2a2011-04-19 19:29:01 +0530539 ah->is_clk_25mhz = pdata->is_clk_25mhz;
Gabor Juhos37625612011-06-21 11:23:23 +0200540 ah->get_mac_revision = pdata->get_mac_revision;
Gabor Juhos7d95847c2011-06-21 11:23:51 +0200541 ah->external_reset = pdata->external_reset;
Felix Fietkau6de66dd2011-03-19 13:55:40 +0100542 }
Felix Fietkaua05b5d452010-11-17 04:25:33 +0100543
Sujith285f2dd2010-01-08 10:36:07 +0530544 common = ath9k_hw_common(ah);
Felix Fietkauf9f84e92011-03-23 20:57:24 +0100545 common->ops = &ah->reg_ops;
Sujith285f2dd2010-01-08 10:36:07 +0530546 common->bus_ops = bus_ops;
547 common->ah = ah;
548 common->hw = sc->hw;
549 common->priv = sc;
550 common->debug_mask = ath9k_debug;
Vasanthakumar Thiagarajan8f5dcb12010-11-26 06:10:06 -0800551 common->btcoex_enabled = ath9k_btcoex_enable == 1;
Mohammed Shafi Shajakhan05c0be22011-05-26 10:56:15 +0530552 common->disable_ani = false;
Sujith Manoharane09f2dc2012-09-16 08:06:56 +0530553
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
Ben Greear20b257442010-10-15 15:04:09 -0700561 spin_lock_init(&common->cc_lock);
Sujith285f2dd2010-01-08 10:36:07 +0530562
Sujith285f2dd2010-01-08 10:36:07 +0530563 spin_lock_init(&sc->sc_serial_rw);
564 spin_lock_init(&sc->sc_pm_lock);
565 mutex_init(&sc->mutex);
Ben Greear7f010c92011-01-09 23:11:49 -0800566#ifdef CONFIG_ATH9K_DEBUGFS
567 spin_lock_init(&sc->nodes_lock);
568 INIT_LIST_HEAD(&sc->nodes);
569#endif
Felix Fietkau5baec742012-03-03 15:17:03 +0100570#ifdef CONFIG_ATH9K_MAC_DEBUG
571 spin_lock_init(&sc->debug.samp_lock);
572#endif
Sujith285f2dd2010-01-08 10:36:07 +0530573 tasklet_init(&sc->intr_tq, ath9k_tasklet, (unsigned long)sc);
Sujith Manoharanfb6e2522012-07-17 17:16:22 +0530574 tasklet_init(&sc->bcon_tasklet, ath9k_beacon_tasklet,
Sujith285f2dd2010-01-08 10:36:07 +0530575 (unsigned long)sc);
576
Sujith Manoharanaaa1ec42012-06-04 16:27:08 +0530577 INIT_WORK(&sc->hw_reset_work, ath_reset_work);
578 INIT_WORK(&sc->hw_check_work, ath_hw_check);
579 INIT_WORK(&sc->paprd_work, ath_paprd_calibrate);
580 INIT_DELAYED_WORK(&sc->hw_pll_work, ath_hw_pll_work);
581 setup_timer(&sc->rx_poll_timer, ath_rx_poll, (unsigned long)sc);
582
Sujith285f2dd2010-01-08 10:36:07 +0530583 /*
584 * Cache line size is used to size and align various
585 * structures used to communicate with the hardware.
586 */
587 ath_read_cachesize(common, &csz);
588 common->cachelsz = csz << 2; /* convert to bytes */
589
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400590 /* Initializes the hardware for all supported chipsets */
Sujith285f2dd2010-01-08 10:36:07 +0530591 ret = ath9k_hw_init(ah);
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400592 if (ret)
Sujith285f2dd2010-01-08 10:36:07 +0530593 goto err_hw;
Sujith285f2dd2010-01-08 10:36:07 +0530594
Felix Fietkau6fb1b1e2011-03-19 13:55:39 +0100595 if (pdata && pdata->macaddr)
596 memcpy(common->macaddr, pdata->macaddr, ETH_ALEN);
597
Sujith285f2dd2010-01-08 10:36:07 +0530598 ret = ath9k_init_queues(sc);
599 if (ret)
600 goto err_queues;
601
602 ret = ath9k_init_btcoex(sc);
603 if (ret)
604 goto err_btcoex;
605
Felix Fietkauf209f522010-10-01 01:06:53 +0200606 ret = ath9k_init_channels_rates(sc);
607 if (ret)
608 goto err_btcoex;
609
Rajkumar Manoharanf82b4bd2011-08-13 10:28:15 +0530610 ath9k_cmn_init_crypto(sc->sc_ah);
Sujith285f2dd2010-01-08 10:36:07 +0530611 ath9k_init_misc(sc);
Rajkumar Manoharan8f176a32012-09-12 18:59:23 +0530612 ath_fill_led_pin(sc);
Sujith285f2dd2010-01-08 10:36:07 +0530613
Sujith Manoharand09f5f42012-06-04 16:27:14 +0530614 if (common->bus_ops->aspm_init)
615 common->bus_ops->aspm_init(common);
616
Sujith55624202010-01-08 10:36:02 +0530617 return 0;
Sujith285f2dd2010-01-08 10:36:07 +0530618
619err_btcoex:
Sujith55624202010-01-08 10:36:02 +0530620 for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++)
621 if (ATH_TXQ_SETUP(sc, i))
622 ath_tx_cleanupq(sc, &sc->tx.txq[i]);
Sujith285f2dd2010-01-08 10:36:07 +0530623err_queues:
Sujith285f2dd2010-01-08 10:36:07 +0530624 ath9k_hw_deinit(ah);
625err_hw:
Sujith55624202010-01-08 10:36:02 +0530626
Sujith285f2dd2010-01-08 10:36:07 +0530627 kfree(ah);
628 sc->sc_ah = NULL;
629
630 return ret;
Sujith55624202010-01-08 10:36:02 +0530631}
632
Felix Fietkaubabcbc22010-10-20 02:09:46 +0200633static void ath9k_init_band_txpower(struct ath_softc *sc, int band)
634{
635 struct ieee80211_supported_band *sband;
636 struct ieee80211_channel *chan;
637 struct ath_hw *ah = sc->sc_ah;
Felix Fietkaubabcbc22010-10-20 02:09:46 +0200638 int i;
639
640 sband = &sc->sbands[band];
641 for (i = 0; i < sband->n_channels; i++) {
642 chan = &sband->channels[i];
643 ah->curchan = &ah->channels[chan->hw_value];
644 ath9k_cmn_update_ichannel(ah->curchan, chan, NL80211_CHAN_HT20);
645 ath9k_hw_set_txpowerlimit(ah, MAX_RATE_POWER, true);
Felix Fietkaubabcbc22010-10-20 02:09:46 +0200646 }
647}
648
649static void ath9k_init_txpower_limits(struct ath_softc *sc)
650{
651 struct ath_hw *ah = sc->sc_ah;
652 struct ath9k_channel *curchan = ah->curchan;
653
654 if (ah->caps.hw_caps & ATH9K_HW_CAP_2GHZ)
655 ath9k_init_band_txpower(sc, IEEE80211_BAND_2GHZ);
656 if (ah->caps.hw_caps & ATH9K_HW_CAP_5GHZ)
657 ath9k_init_band_txpower(sc, IEEE80211_BAND_5GHZ);
658
659 ah->curchan = curchan;
660}
661
Felix Fietkau43c35282011-09-03 01:40:27 +0200662void ath9k_reload_chainmask_settings(struct ath_softc *sc)
663{
664 if (!(sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_HT))
665 return;
666
667 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_2GHZ)
668 setup_ht_cap(sc, &sc->sbands[IEEE80211_BAND_2GHZ].ht_cap);
669 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_5GHZ)
670 setup_ht_cap(sc, &sc->sbands[IEEE80211_BAND_5GHZ].ht_cap);
671}
672
Felix Fietkau20c8e8d2012-04-17 02:40:07 +0200673static const struct ieee80211_iface_limit if_limits[] = {
674 { .max = 2048, .types = BIT(NL80211_IFTYPE_STATION) |
675 BIT(NL80211_IFTYPE_P2P_CLIENT) |
676 BIT(NL80211_IFTYPE_WDS) },
677 { .max = 8, .types =
678#ifdef CONFIG_MAC80211_MESH
679 BIT(NL80211_IFTYPE_MESH_POINT) |
680#endif
681 BIT(NL80211_IFTYPE_AP) |
682 BIT(NL80211_IFTYPE_P2P_GO) },
683};
684
685static const struct ieee80211_iface_combination if_comb = {
686 .limits = if_limits,
687 .n_limits = ARRAY_SIZE(if_limits),
688 .max_interfaces = 2048,
689 .num_different_channels = 1,
Mohammed Shafi Shajakhanaebc0d42012-10-08 21:30:54 +0530690 .beacon_int_infra_match = true,
Felix Fietkau20c8e8d2012-04-17 02:40:07 +0200691};
Felix Fietkau43c35282011-09-03 01:40:27 +0200692
Sujith285f2dd2010-01-08 10:36:07 +0530693void ath9k_set_hw_capab(struct ath_softc *sc, struct ieee80211_hw *hw)
Sujith55624202010-01-08 10:36:02 +0530694{
Felix Fietkau43c35282011-09-03 01:40:27 +0200695 struct ath_hw *ah = sc->sc_ah;
696 struct ath_common *common = ath9k_hw_common(ah);
Sujith285f2dd2010-01-08 10:36:07 +0530697
Sujith55624202010-01-08 10:36:02 +0530698 hw->flags = IEEE80211_HW_RX_INCLUDES_FCS |
699 IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING |
700 IEEE80211_HW_SIGNAL_DBM |
Sujith55624202010-01-08 10:36:02 +0530701 IEEE80211_HW_SUPPORTS_PS |
702 IEEE80211_HW_PS_NULLFUNC_STACK |
Vivek Natarajan05df4982010-02-09 11:34:50 +0530703 IEEE80211_HW_SPECTRUM_MGMT |
Mohammed Shafi Shajakhanbd8027a2010-12-30 12:18:01 +0530704 IEEE80211_HW_REPORTS_TX_ACK_STATUS;
Sujith55624202010-01-08 10:36:02 +0530705
Luis R. Rodriguez5ffaf8a2010-02-02 11:58:33 -0500706 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_HT)
707 hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION;
708
John W. Linville3e6109c2011-01-05 09:39:17 -0500709 if (AR_SREV_9160_10_OR_LATER(sc->sc_ah) || ath9k_modparam_nohwcrypt)
Sujith55624202010-01-08 10:36:02 +0530710 hw->flags |= IEEE80211_HW_MFP_CAPABLE;
711
712 hw->wiphy->interface_modes =
Johannes Bergc426ee22010-11-26 11:38:04 +0100713 BIT(NL80211_IFTYPE_P2P_GO) |
714 BIT(NL80211_IFTYPE_P2P_CLIENT) |
Sujith55624202010-01-08 10:36:02 +0530715 BIT(NL80211_IFTYPE_AP) |
Bill Jordane51f3ef2010-10-01 11:20:39 -0400716 BIT(NL80211_IFTYPE_WDS) |
Sujith55624202010-01-08 10:36:02 +0530717 BIT(NL80211_IFTYPE_STATION) |
718 BIT(NL80211_IFTYPE_ADHOC) |
719 BIT(NL80211_IFTYPE_MESH_POINT);
720
Felix Fietkau20c8e8d2012-04-17 02:40:07 +0200721 hw->wiphy->iface_combinations = &if_comb;
722 hw->wiphy->n_iface_combinations = 1;
723
Luis R. Rodriguez008443d2010-09-16 15:12:36 -0400724 if (AR_SREV_5416(sc->sc_ah))
725 hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
Sujith55624202010-01-08 10:36:02 +0530726
Jouni Malinencfdc9a82011-03-23 14:52:19 +0200727 hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
Jouni Malinenfd656232011-10-27 17:31:50 +0300728 hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS;
Johannes Berg81ddbb52012-03-26 18:47:18 +0200729 hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
Jouni Malinencfdc9a82011-03-23 14:52:19 +0200730
Mohammed Shafi Shajakhan9f11e162012-07-10 14:55:35 +0530731#ifdef CONFIG_PM_SLEEP
732
733 if ((ah->caps.hw_caps & ATH9K_HW_WOW_DEVICE_CAPABLE) &&
734 device_can_wakeup(sc->dev)) {
735
736 hw->wiphy->wowlan.flags = WIPHY_WOWLAN_MAGIC_PKT |
737 WIPHY_WOWLAN_DISCONNECT;
738 hw->wiphy->wowlan.n_patterns = MAX_NUM_USER_PATTERN;
739 hw->wiphy->wowlan.pattern_min_len = 1;
740 hw->wiphy->wowlan.pattern_max_len = MAX_PATTERN_SIZE;
741
742 }
743
744 atomic_set(&sc->wow_sleep_proc_intr, -1);
745 atomic_set(&sc->wow_got_bmiss_intr, -1);
746
747#endif
748
Sujith55624202010-01-08 10:36:02 +0530749 hw->queues = 4;
750 hw->max_rates = 4;
751 hw->channel_change_time = 5000;
Rajkumar Manoharan195ca3b2012-03-15 23:05:28 +0530752 hw->max_listen_interval = 1;
Felix Fietkau65896512010-01-24 03:26:11 +0100753 hw->max_rate_tries = 10;
Sujith55624202010-01-08 10:36:02 +0530754 hw->sta_data_size = sizeof(struct ath_node);
755 hw->vif_data_size = sizeof(struct ath_vif);
756
Felix Fietkau43c35282011-09-03 01:40:27 +0200757 hw->wiphy->available_antennas_rx = BIT(ah->caps.max_rxchains) - 1;
758 hw->wiphy->available_antennas_tx = BIT(ah->caps.max_txchains) - 1;
759
760 /* single chain devices with rx diversity */
761 if (ah->caps.hw_caps & ATH9K_HW_CAP_ANT_DIV_COMB)
762 hw->wiphy->available_antennas_rx = BIT(0) | BIT(1);
763
764 sc->ant_rx = hw->wiphy->available_antennas_rx;
765 sc->ant_tx = hw->wiphy->available_antennas_tx;
766
Felix Fietkau6e5c2b42010-09-20 13:45:40 +0200767#ifdef CONFIG_ATH9K_RATE_CONTROL
Sujith55624202010-01-08 10:36:02 +0530768 hw->rate_control_algorithm = "ath9k_rate_control";
Felix Fietkau6e5c2b42010-09-20 13:45:40 +0200769#endif
Sujith55624202010-01-08 10:36:02 +0530770
Felix Fietkaud4659912010-10-14 16:02:39 +0200771 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_2GHZ)
Sujith55624202010-01-08 10:36:02 +0530772 hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
773 &sc->sbands[IEEE80211_BAND_2GHZ];
Felix Fietkaud4659912010-10-14 16:02:39 +0200774 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_5GHZ)
Sujith55624202010-01-08 10:36:02 +0530775 hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
776 &sc->sbands[IEEE80211_BAND_5GHZ];
Sujith285f2dd2010-01-08 10:36:07 +0530777
Felix Fietkau43c35282011-09-03 01:40:27 +0200778 ath9k_reload_chainmask_settings(sc);
Sujith285f2dd2010-01-08 10:36:07 +0530779
780 SET_IEEE80211_PERM_ADDR(hw, common->macaddr);
Sujith55624202010-01-08 10:36:02 +0530781}
782
Pavel Roskineb93e892011-07-23 03:55:39 -0400783int ath9k_init_device(u16 devid, struct ath_softc *sc,
Sujith55624202010-01-08 10:36:02 +0530784 const struct ath_bus_ops *bus_ops)
785{
786 struct ieee80211_hw *hw = sc->hw;
787 struct ath_common *common;
788 struct ath_hw *ah;
Sujith285f2dd2010-01-08 10:36:07 +0530789 int error = 0;
Sujith55624202010-01-08 10:36:02 +0530790 struct ath_regulatory *reg;
791
Sujith285f2dd2010-01-08 10:36:07 +0530792 /* Bring up device */
Pavel Roskineb93e892011-07-23 03:55:39 -0400793 error = ath9k_init_softc(devid, sc, bus_ops);
Sujith55624202010-01-08 10:36:02 +0530794 if (error != 0)
Sujith285f2dd2010-01-08 10:36:07 +0530795 goto error_init;
Sujith55624202010-01-08 10:36:02 +0530796
797 ah = sc->sc_ah;
798 common = ath9k_hw_common(ah);
Sujith285f2dd2010-01-08 10:36:07 +0530799 ath9k_set_hw_capab(sc, hw);
Sujith55624202010-01-08 10:36:02 +0530800
Sujith285f2dd2010-01-08 10:36:07 +0530801 /* Initialize regulatory */
Sujith55624202010-01-08 10:36:02 +0530802 error = ath_regd_init(&common->regulatory, sc->hw->wiphy,
803 ath9k_reg_notifier);
804 if (error)
Sujith285f2dd2010-01-08 10:36:07 +0530805 goto error_regd;
Sujith55624202010-01-08 10:36:02 +0530806
807 reg = &common->regulatory;
808
Sujith285f2dd2010-01-08 10:36:07 +0530809 /* Setup TX DMA */
Sujith55624202010-01-08 10:36:02 +0530810 error = ath_tx_init(sc, ATH_TXBUF);
811 if (error != 0)
Sujith285f2dd2010-01-08 10:36:07 +0530812 goto error_tx;
Sujith55624202010-01-08 10:36:02 +0530813
Sujith285f2dd2010-01-08 10:36:07 +0530814 /* Setup RX DMA */
Sujith55624202010-01-08 10:36:02 +0530815 error = ath_rx_init(sc, ATH_RXBUF);
816 if (error != 0)
Sujith285f2dd2010-01-08 10:36:07 +0530817 goto error_rx;
818
Felix Fietkaubabcbc22010-10-20 02:09:46 +0200819 ath9k_init_txpower_limits(sc);
820
Felix Fietkau0cf55c22011-02-27 22:26:40 +0100821#ifdef CONFIG_MAC80211_LEDS
822 /* must be initialized before ieee80211_register_hw */
823 sc->led_cdev.default_trigger = ieee80211_create_tpt_led_trigger(sc->hw,
824 IEEE80211_TPT_LEDTRIG_FL_RADIO, ath9k_tpt_blink,
825 ARRAY_SIZE(ath9k_tpt_blink));
826#endif
827
Sujith285f2dd2010-01-08 10:36:07 +0530828 /* Register with mac80211 */
829 error = ieee80211_register_hw(hw);
830 if (error)
831 goto error_register;
832
Ben Greeareb272442010-11-29 14:13:22 -0800833 error = ath9k_init_debug(ah);
834 if (error) {
Joe Perches38002762010-12-02 19:12:36 -0800835 ath_err(common, "Unable to create debugfs files\n");
Ben Greeareb272442010-11-29 14:13:22 -0800836 goto error_world;
837 }
838
Sujith285f2dd2010-01-08 10:36:07 +0530839 /* Handle world regulatory */
840 if (!ath_is_world_regd(reg)) {
841 error = regulatory_hint(hw->wiphy, reg->alpha2);
842 if (error)
843 goto error_world;
844 }
Sujith55624202010-01-08 10:36:02 +0530845
Sujith55624202010-01-08 10:36:02 +0530846 ath_init_leds(sc);
Sujith55624202010-01-08 10:36:02 +0530847 ath_start_rfkill_poll(sc);
848
849 return 0;
850
Sujith285f2dd2010-01-08 10:36:07 +0530851error_world:
852 ieee80211_unregister_hw(hw);
853error_register:
854 ath_rx_cleanup(sc);
855error_rx:
856 ath_tx_cleanup(sc);
857error_tx:
858 /* Nothing */
859error_regd:
860 ath9k_deinit_softc(sc);
861error_init:
Sujith55624202010-01-08 10:36:02 +0530862 return error;
863}
864
865/*****************************/
866/* De-Initialization */
867/*****************************/
868
Sujith285f2dd2010-01-08 10:36:07 +0530869static void ath9k_deinit_softc(struct ath_softc *sc)
Sujith55624202010-01-08 10:36:02 +0530870{
Sujith285f2dd2010-01-08 10:36:07 +0530871 int i = 0;
Sujith55624202010-01-08 10:36:02 +0530872
Felix Fietkauf209f522010-10-01 01:06:53 +0200873 if (sc->sbands[IEEE80211_BAND_2GHZ].channels)
874 kfree(sc->sbands[IEEE80211_BAND_2GHZ].channels);
875
876 if (sc->sbands[IEEE80211_BAND_5GHZ].channels)
877 kfree(sc->sbands[IEEE80211_BAND_5GHZ].channels);
878
Sujith Manoharan59081202012-02-22 12:40:21 +0530879 ath9k_deinit_btcoex(sc);
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530880
Sujith285f2dd2010-01-08 10:36:07 +0530881 for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++)
882 if (ATH_TXQ_SETUP(sc, i))
883 ath_tx_cleanupq(sc, &sc->tx.txq[i]);
884
Sujith285f2dd2010-01-08 10:36:07 +0530885 ath9k_hw_deinit(sc->sc_ah);
Zefir Kurtisi8e92d3f2012-04-03 17:15:50 +0200886 if (sc->dfs_detector != NULL)
887 sc->dfs_detector->exit(sc->dfs_detector);
Sujith285f2dd2010-01-08 10:36:07 +0530888
Sujith736b3a22010-03-17 14:25:24 +0530889 kfree(sc->sc_ah);
890 sc->sc_ah = NULL;
Sujith55624202010-01-08 10:36:02 +0530891}
892
Sujith285f2dd2010-01-08 10:36:07 +0530893void ath9k_deinit_device(struct ath_softc *sc)
Sujith55624202010-01-08 10:36:02 +0530894{
895 struct ieee80211_hw *hw = sc->hw;
Sujith55624202010-01-08 10:36:02 +0530896
897 ath9k_ps_wakeup(sc);
898
Sujith55624202010-01-08 10:36:02 +0530899 wiphy_rfkill_stop_polling(sc->hw->wiphy);
Sujith285f2dd2010-01-08 10:36:07 +0530900 ath_deinit_leds(sc);
Sujith55624202010-01-08 10:36:02 +0530901
Rajkumar Manoharanc7c18062011-01-27 18:39:38 +0530902 ath9k_ps_restore(sc);
903
Sujith55624202010-01-08 10:36:02 +0530904 ieee80211_unregister_hw(hw);
905 ath_rx_cleanup(sc);
906 ath_tx_cleanup(sc);
Sujith285f2dd2010-01-08 10:36:07 +0530907 ath9k_deinit_softc(sc);
Sujith55624202010-01-08 10:36:02 +0530908}
909
910void ath_descdma_cleanup(struct ath_softc *sc,
911 struct ath_descdma *dd,
912 struct list_head *head)
913{
914 dma_free_coherent(sc->dev, dd->dd_desc_len, dd->dd_desc,
915 dd->dd_desc_paddr);
916
917 INIT_LIST_HEAD(head);
918 kfree(dd->dd_bufptr);
919 memset(dd, 0, sizeof(*dd));
920}
921
Sujith55624202010-01-08 10:36:02 +0530922/************************/
923/* Module Hooks */
924/************************/
925
926static int __init ath9k_init(void)
927{
928 int error;
929
930 /* Register rate control algorithm */
931 error = ath_rate_control_register();
932 if (error != 0) {
Joe Perches516304b2012-03-18 17:30:52 -0700933 pr_err("Unable to register rate control algorithm: %d\n",
934 error);
Sujith55624202010-01-08 10:36:02 +0530935 goto err_out;
936 }
937
Sujith55624202010-01-08 10:36:02 +0530938 error = ath_pci_init();
939 if (error < 0) {
Joe Perches516304b2012-03-18 17:30:52 -0700940 pr_err("No PCI devices found, driver not installed\n");
Sujith55624202010-01-08 10:36:02 +0530941 error = -ENODEV;
Ben Greeareb272442010-11-29 14:13:22 -0800942 goto err_rate_unregister;
Sujith55624202010-01-08 10:36:02 +0530943 }
944
945 error = ath_ahb_init();
946 if (error < 0) {
947 error = -ENODEV;
948 goto err_pci_exit;
949 }
950
951 return 0;
952
953 err_pci_exit:
954 ath_pci_exit();
955
Sujith55624202010-01-08 10:36:02 +0530956 err_rate_unregister:
957 ath_rate_control_unregister();
958 err_out:
959 return error;
960}
961module_init(ath9k_init);
962
963static void __exit ath9k_exit(void)
964{
Rajkumar Manoharand5847472010-12-20 14:39:51 +0530965 is_ath9k_unloaded = true;
Sujith55624202010-01-08 10:36:02 +0530966 ath_ahb_exit();
967 ath_pci_exit();
Sujith55624202010-01-08 10:36:02 +0530968 ath_rate_control_unregister();
Joe Perches516304b2012-03-18 17:30:52 -0700969 pr_info("%s: Driver unloaded\n", dev_info);
Sujith55624202010-01-08 10:36:02 +0530970}
971module_exit(ath9k_exit);