blob: 9f5e1e4931afc022445deafffaa7fe57bebade97 [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>
Simon Wunderliche93d0832013-01-08 14:48:58 +010023#include <linux/relay.h>
Oleksij Rempelb0a1ae92013-05-24 20:30:59 +020024#include <net/ieee80211_radiotap.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090025
Sujith55624202010-01-08 10:36:02 +053026#include "ath9k.h"
27
Gabor Juhosab5c4f72012-12-10 15:30:28 +010028struct ath9k_eeprom_ctx {
29 struct completion complete;
30 struct ath_hw *ah;
31};
32
Sujith55624202010-01-08 10:36:02 +053033static char *dev_info = "ath9k";
34
35MODULE_AUTHOR("Atheros Communications");
36MODULE_DESCRIPTION("Support for Atheros 802.11n wireless LAN cards.");
37MODULE_SUPPORTED_DEVICE("Atheros 802.11n WLAN cards");
38MODULE_LICENSE("Dual BSD/GPL");
39
40static unsigned int ath9k_debug = ATH_DBG_DEFAULT;
41module_param_named(debug, ath9k_debug, uint, 0);
42MODULE_PARM_DESC(debug, "Debugging mask");
43
John W. Linville3e6109c2011-01-05 09:39:17 -050044int ath9k_modparam_nohwcrypt;
45module_param_named(nohwcrypt, ath9k_modparam_nohwcrypt, int, 0444);
Sujith55624202010-01-08 10:36:02 +053046MODULE_PARM_DESC(nohwcrypt, "Disable hardware encryption");
47
Vivek Natarajan93dbbcc2010-08-25 19:34:52 +053048int led_blink;
Vivek Natarajan9a75c2f2010-06-22 11:52:37 +053049module_param_named(blink, led_blink, int, 0444);
50MODULE_PARM_DESC(blink, "Enable LED blink on activity");
51
Vasanthakumar Thiagarajan8f5dcb12010-11-26 06:10:06 -080052static int ath9k_btcoex_enable;
53module_param_named(btcoex_enable, ath9k_btcoex_enable, int, 0444);
54MODULE_PARM_DESC(btcoex_enable, "Enable wifi-BT coexistence");
55
Sujith Manoharan63081302013-08-04 14:21:55 +053056static int ath9k_bt_ant_diversity;
57module_param_named(bt_ant_diversity, ath9k_bt_ant_diversity, int, 0444);
58MODULE_PARM_DESC(bt_ant_diversity, "Enable WLAN/BT RX antenna diversity");
Sujith Manoharane09f2dc2012-09-16 08:06:56 +053059
Sujith Manoharan82983832014-02-04 08:37:53 +053060static int ath9k_ps_enable;
61module_param_named(ps_enable, ath9k_ps_enable, int, 0444);
62MODULE_PARM_DESC(ps_enable, "Enable WLAN PowerSave");
63
Felix Fietkau78b21942014-06-11 16:17:55 +053064int ath9k_use_chanctx;
Rajkumar Manoharan71a5f882014-05-29 15:11:09 +053065module_param_named(use_chanctx, ath9k_use_chanctx, int, 0444);
66MODULE_PARM_DESC(use_chanctx, "Enable channel context for concurrency");
67
Rajkumar Manoharand5847472010-12-20 14:39:51 +053068bool is_ath9k_unloaded;
Sujith55624202010-01-08 10:36:02 +053069
Felix Fietkau0cf55c22011-02-27 22:26:40 +010070#ifdef CONFIG_MAC80211_LEDS
71static const struct ieee80211_tpt_blink ath9k_tpt_blink[] = {
72 { .throughput = 0 * 1024, .blink_time = 334 },
73 { .throughput = 1 * 1024, .blink_time = 260 },
74 { .throughput = 5 * 1024, .blink_time = 220 },
75 { .throughput = 10 * 1024, .blink_time = 190 },
76 { .throughput = 20 * 1024, .blink_time = 170 },
77 { .throughput = 50 * 1024, .blink_time = 150 },
78 { .throughput = 70 * 1024, .blink_time = 130 },
79 { .throughput = 100 * 1024, .blink_time = 110 },
80 { .throughput = 200 * 1024, .blink_time = 80 },
81 { .throughput = 300 * 1024, .blink_time = 50 },
82};
83#endif
84
Sujith285f2dd2010-01-08 10:36:07 +053085static void ath9k_deinit_softc(struct ath_softc *sc);
Sujith55624202010-01-08 10:36:02 +053086
87/*
88 * Read and write, they both share the same lock. We do this to serialize
89 * reads and writes on Atheros 802.11n PCI devices only. This is required
90 * as the FIFO on these devices can only accept sanely 2 requests.
91 */
92
93static void ath9k_iowrite32(void *hw_priv, u32 val, u32 reg_offset)
94{
95 struct ath_hw *ah = (struct ath_hw *) hw_priv;
96 struct ath_common *common = ath9k_hw_common(ah);
97 struct ath_softc *sc = (struct ath_softc *) common->priv;
98
Felix Fietkauf3eef642012-03-14 16:40:25 +010099 if (NR_CPUS > 1 && ah->config.serialize_regmode == SER_REG_MODE_ON) {
Sujith55624202010-01-08 10:36:02 +0530100 unsigned long flags;
101 spin_lock_irqsave(&sc->sc_serial_rw, flags);
102 iowrite32(val, sc->mem + reg_offset);
103 spin_unlock_irqrestore(&sc->sc_serial_rw, flags);
104 } else
105 iowrite32(val, sc->mem + reg_offset);
106}
107
108static unsigned int ath9k_ioread32(void *hw_priv, u32 reg_offset)
109{
110 struct ath_hw *ah = (struct ath_hw *) hw_priv;
111 struct ath_common *common = ath9k_hw_common(ah);
112 struct ath_softc *sc = (struct ath_softc *) common->priv;
113 u32 val;
114
Felix Fietkauf3eef642012-03-14 16:40:25 +0100115 if (NR_CPUS > 1 && ah->config.serialize_regmode == SER_REG_MODE_ON) {
Sujith55624202010-01-08 10:36:02 +0530116 unsigned long flags;
117 spin_lock_irqsave(&sc->sc_serial_rw, flags);
118 val = ioread32(sc->mem + reg_offset);
119 spin_unlock_irqrestore(&sc->sc_serial_rw, flags);
120 } else
121 val = ioread32(sc->mem + reg_offset);
122 return val;
123}
124
Rajkumar Manoharan5479de62011-07-17 11:43:02 +0530125static unsigned int __ath9k_reg_rmw(struct ath_softc *sc, u32 reg_offset,
126 u32 set, u32 clr)
127{
128 u32 val;
129
130 val = ioread32(sc->mem + reg_offset);
131 val &= ~clr;
132 val |= set;
133 iowrite32(val, sc->mem + reg_offset);
134
135 return val;
136}
137
Felix Fietkau845e03c2011-03-23 20:57:25 +0100138static unsigned int ath9k_reg_rmw(void *hw_priv, u32 reg_offset, u32 set, u32 clr)
139{
140 struct ath_hw *ah = (struct ath_hw *) hw_priv;
141 struct ath_common *common = ath9k_hw_common(ah);
142 struct ath_softc *sc = (struct ath_softc *) common->priv;
143 unsigned long uninitialized_var(flags);
144 u32 val;
145
Felix Fietkauf3eef642012-03-14 16:40:25 +0100146 if (NR_CPUS > 1 && ah->config.serialize_regmode == SER_REG_MODE_ON) {
Felix Fietkau845e03c2011-03-23 20:57:25 +0100147 spin_lock_irqsave(&sc->sc_serial_rw, flags);
Rajkumar Manoharan5479de62011-07-17 11:43:02 +0530148 val = __ath9k_reg_rmw(sc, reg_offset, set, clr);
Felix Fietkau845e03c2011-03-23 20:57:25 +0100149 spin_unlock_irqrestore(&sc->sc_serial_rw, flags);
Rajkumar Manoharan5479de62011-07-17 11:43:02 +0530150 } else
151 val = __ath9k_reg_rmw(sc, reg_offset, set, clr);
Felix Fietkau845e03c2011-03-23 20:57:25 +0100152
153 return val;
154}
155
Sujith55624202010-01-08 10:36:02 +0530156/**************************/
157/* Initialization */
158/**************************/
159
Luis R. Rodriguez0c0280b2013-01-11 18:39:36 +0000160static void ath9k_reg_notifier(struct wiphy *wiphy,
161 struct regulatory_request *request)
Sujith55624202010-01-08 10:36:02 +0530162{
163 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
Felix Fietkau9ac58612011-01-24 19:23:18 +0100164 struct ath_softc *sc = hw->priv;
Rajkumar Manoharan687f5452011-12-08 23:59:25 +0530165 struct ath_hw *ah = sc->sc_ah;
166 struct ath_regulatory *reg = ath9k_hw_regulatory(ah);
Sujith55624202010-01-08 10:36:02 +0530167
Luis R. Rodriguez0c0280b2013-01-11 18:39:36 +0000168 ath_reg_notifier_apply(wiphy, request, reg);
Rajkumar Manoharan687f5452011-12-08 23:59:25 +0530169
170 /* Set tx power */
171 if (ah->curchan) {
Felix Fietkaubc7e1be2014-06-11 16:17:50 +0530172 sc->cur_chan->txpower = 2 * ah->curchan->chan->max_power;
Rajkumar Manoharan687f5452011-12-08 23:59:25 +0530173 ath9k_ps_wakeup(sc);
Felix Fietkaubc7e1be2014-06-11 16:17:50 +0530174 ath9k_hw_set_txpowerlimit(ah, sc->cur_chan->txpower, false);
Rajkumar Manoharan687f5452011-12-08 23:59:25 +0530175 sc->curtxpow = ath9k_hw_regulatory(ah)->power_limit;
Zefir Kurtisi73e49372013-04-03 18:31:31 +0200176 /* synchronize DFS detector if regulatory domain changed */
177 if (sc->dfs_detector != NULL)
178 sc->dfs_detector->set_dfs_domain(sc->dfs_detector,
179 request->dfs_region);
Rajkumar Manoharan687f5452011-12-08 23:59:25 +0530180 ath9k_ps_restore(sc);
181 }
Sujith55624202010-01-08 10:36:02 +0530182}
183
184/*
185 * This function will allocate both the DMA descriptor structure, and the
186 * buffers it contains. These are used to contain the descriptors used
187 * by the system.
188*/
189int ath_descdma_setup(struct ath_softc *sc, struct ath_descdma *dd,
190 struct list_head *head, const char *name,
Vasanthakumar Thiagarajan4adfcde2010-04-15 17:39:33 -0400191 int nbuf, int ndesc, bool is_tx)
Sujith55624202010-01-08 10:36:02 +0530192{
Sujith55624202010-01-08 10:36:02 +0530193 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Vasanthakumar Thiagarajan4adfcde2010-04-15 17:39:33 -0400194 u8 *ds;
Felix Fietkaub81950b12012-12-12 13:14:22 +0100195 int i, bsize, desc_len;
Sujith55624202010-01-08 10:36:02 +0530196
Joe Perchesd2182b62011-12-15 14:55:53 -0800197 ath_dbg(common, CONFIG, "%s DMA: %u buffers %u desc/buf\n",
Joe Perches226afe62010-12-02 19:12:37 -0800198 name, nbuf, ndesc);
Sujith55624202010-01-08 10:36:02 +0530199
200 INIT_LIST_HEAD(head);
Vasanthakumar Thiagarajan4adfcde2010-04-15 17:39:33 -0400201
202 if (is_tx)
203 desc_len = sc->sc_ah->caps.tx_desc_len;
204 else
205 desc_len = sizeof(struct ath_desc);
206
Sujith55624202010-01-08 10:36:02 +0530207 /* ath_desc must be a multiple of DWORDs */
Vasanthakumar Thiagarajan4adfcde2010-04-15 17:39:33 -0400208 if ((desc_len % 4) != 0) {
Joe Perches38002762010-12-02 19:12:36 -0800209 ath_err(common, "ath_desc not DWORD aligned\n");
Vasanthakumar Thiagarajan4adfcde2010-04-15 17:39:33 -0400210 BUG_ON((desc_len % 4) != 0);
Felix Fietkaub81950b12012-12-12 13:14:22 +0100211 return -ENOMEM;
Sujith55624202010-01-08 10:36:02 +0530212 }
213
Vasanthakumar Thiagarajan4adfcde2010-04-15 17:39:33 -0400214 dd->dd_desc_len = desc_len * nbuf * ndesc;
Sujith55624202010-01-08 10:36:02 +0530215
216 /*
217 * Need additional DMA memory because we can't use
218 * descriptors that cross the 4K page boundary. Assume
219 * one skipped descriptor per 4K page.
220 */
221 if (!(sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_4KB_SPLITTRANS)) {
222 u32 ndesc_skipped =
223 ATH_DESC_4KB_BOUND_NUM_SKIPPED(dd->dd_desc_len);
224 u32 dma_len;
225
226 while (ndesc_skipped) {
Vasanthakumar Thiagarajan4adfcde2010-04-15 17:39:33 -0400227 dma_len = ndesc_skipped * desc_len;
Sujith55624202010-01-08 10:36:02 +0530228 dd->dd_desc_len += dma_len;
229
230 ndesc_skipped = ATH_DESC_4KB_BOUND_NUM_SKIPPED(dma_len);
Joe Perchesee289b62010-05-17 22:47:34 -0700231 }
Sujith55624202010-01-08 10:36:02 +0530232 }
233
234 /* allocate descriptors */
Felix Fietkaub81950b12012-12-12 13:14:22 +0100235 dd->dd_desc = dmam_alloc_coherent(sc->dev, dd->dd_desc_len,
236 &dd->dd_desc_paddr, GFP_KERNEL);
237 if (!dd->dd_desc)
238 return -ENOMEM;
239
Vasanthakumar Thiagarajan4adfcde2010-04-15 17:39:33 -0400240 ds = (u8 *) dd->dd_desc;
Joe Perchesd2182b62011-12-15 14:55:53 -0800241 ath_dbg(common, CONFIG, "%s DMA map: %p (%u) -> %llx (%u)\n",
Joe Perches226afe62010-12-02 19:12:37 -0800242 name, ds, (u32) dd->dd_desc_len,
243 ito64(dd->dd_desc_paddr), /*XXX*/(u32) dd->dd_desc_len);
Sujith55624202010-01-08 10:36:02 +0530244
245 /* allocate buffers */
Felix Fietkau1a04d592013-10-11 23:30:52 +0200246 if (is_tx) {
247 struct ath_buf *bf;
Sujith55624202010-01-08 10:36:02 +0530248
Felix Fietkau1a04d592013-10-11 23:30:52 +0200249 bsize = sizeof(struct ath_buf) * nbuf;
250 bf = devm_kzalloc(sc->dev, bsize, GFP_KERNEL);
251 if (!bf)
252 return -ENOMEM;
Sujith55624202010-01-08 10:36:02 +0530253
Felix Fietkau1a04d592013-10-11 23:30:52 +0200254 for (i = 0; i < nbuf; i++, bf++, ds += (desc_len * ndesc)) {
255 bf->bf_desc = ds;
256 bf->bf_daddr = DS2PHYS(dd, ds);
Sujith55624202010-01-08 10:36:02 +0530257
Felix Fietkau1a04d592013-10-11 23:30:52 +0200258 if (!(sc->sc_ah->caps.hw_caps &
259 ATH9K_HW_CAP_4KB_SPLITTRANS)) {
260 /*
261 * Skip descriptor addresses which can cause 4KB
262 * boundary crossing (addr + length) with a 32 dword
263 * descriptor fetch.
264 */
265 while (ATH_DESC_4KB_BOUND_CHECK(bf->bf_daddr)) {
266 BUG_ON((caddr_t) bf->bf_desc >=
267 ((caddr_t) dd->dd_desc +
268 dd->dd_desc_len));
269
270 ds += (desc_len * ndesc);
271 bf->bf_desc = ds;
272 bf->bf_daddr = DS2PHYS(dd, ds);
273 }
Sujith55624202010-01-08 10:36:02 +0530274 }
Felix Fietkau1a04d592013-10-11 23:30:52 +0200275 list_add_tail(&bf->list, head);
Sujith55624202010-01-08 10:36:02 +0530276 }
Felix Fietkau1a04d592013-10-11 23:30:52 +0200277 } else {
278 struct ath_rxbuf *bf;
279
280 bsize = sizeof(struct ath_rxbuf) * nbuf;
281 bf = devm_kzalloc(sc->dev, bsize, GFP_KERNEL);
282 if (!bf)
283 return -ENOMEM;
284
285 for (i = 0; i < nbuf; i++, bf++, ds += (desc_len * ndesc)) {
286 bf->bf_desc = ds;
287 bf->bf_daddr = DS2PHYS(dd, ds);
288
289 if (!(sc->sc_ah->caps.hw_caps &
290 ATH9K_HW_CAP_4KB_SPLITTRANS)) {
291 /*
292 * Skip descriptor addresses which can cause 4KB
293 * boundary crossing (addr + length) with a 32 dword
294 * descriptor fetch.
295 */
296 while (ATH_DESC_4KB_BOUND_CHECK(bf->bf_daddr)) {
297 BUG_ON((caddr_t) bf->bf_desc >=
298 ((caddr_t) dd->dd_desc +
299 dd->dd_desc_len));
300
301 ds += (desc_len * ndesc);
302 bf->bf_desc = ds;
303 bf->bf_daddr = DS2PHYS(dd, ds);
304 }
305 }
306 list_add_tail(&bf->list, head);
307 }
Sujith55624202010-01-08 10:36:02 +0530308 }
309 return 0;
Sujith55624202010-01-08 10:36:02 +0530310}
311
Sujith285f2dd2010-01-08 10:36:07 +0530312static int ath9k_init_queues(struct ath_softc *sc)
313{
Sujith285f2dd2010-01-08 10:36:07 +0530314 int i = 0;
Sujith55624202010-01-08 10:36:02 +0530315
Sujith285f2dd2010-01-08 10:36:07 +0530316 sc->beacon.beaconq = ath9k_hw_beaconq_setup(sc->sc_ah);
Sujith285f2dd2010-01-08 10:36:07 +0530317 sc->beacon.cabq = ath_txq_setup(sc, ATH9K_TX_QUEUE_CAB, 0);
Sujith285f2dd2010-01-08 10:36:07 +0530318 ath_cabq_update(sc);
319
Felix Fietkauf2c7a792013-06-07 18:12:00 +0200320 sc->tx.uapsdq = ath_txq_setup(sc, ATH9K_TX_QUEUE_UAPSD, 0);
321
Sujith Manoharanbea843c2012-11-21 18:13:10 +0530322 for (i = 0; i < IEEE80211_NUM_ACS; i++) {
Felix Fietkau066dae92010-11-07 14:59:39 +0100323 sc->tx.txq_map[i] = ath_txq_setup(sc, ATH9K_TX_QUEUE_DATA, i);
Ben Greear60f2d1d2011-01-09 23:11:52 -0800324 sc->tx.txq_map[i]->mac80211_qnum = i;
Felix Fietkau7702e782012-07-15 19:53:35 +0200325 sc->tx.txq_max_pending[i] = ATH_MAX_QDEPTH;
Ben Greear60f2d1d2011-01-09 23:11:52 -0800326 }
Sujith285f2dd2010-01-08 10:36:07 +0530327 return 0;
Sujith285f2dd2010-01-08 10:36:07 +0530328}
329
Sujith285f2dd2010-01-08 10:36:07 +0530330static void ath9k_init_misc(struct ath_softc *sc)
331{
332 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
333 int i = 0;
Sujith Manoharan3d4e20f2012-03-14 14:40:58 +0530334
Sujith285f2dd2010-01-08 10:36:07 +0530335 setup_timer(&common->ani.timer, ath_ani_calibrate, (unsigned long)sc);
336
Oleksij Rempel32efb0c2014-02-04 10:27:39 +0100337 common->last_rssi = ATH_RSSI_DUMMY_MARKER;
Felix Fietkau364734f2010-09-14 20:22:44 +0200338 memcpy(common->bssidmask, ath_bcast_mac, ETH_ALEN);
Sujith285f2dd2010-01-08 10:36:07 +0530339 sc->beacon.slottime = ATH9K_SLOT_TIME_9;
340
Felix Fietkau7545daf2011-01-24 19:23:16 +0100341 for (i = 0; i < ARRAY_SIZE(sc->beacon.bslot); i++)
Sujith285f2dd2010-01-08 10:36:07 +0530342 sc->beacon.bslot[i] = NULL;
Vasanthakumar Thiagarajan102885a2010-09-02 01:34:43 -0700343
344 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_ANT_DIV_COMB)
345 sc->ant_comb.count = ATH_ANT_DIV_COMB_INIT_COUNT;
Simon Wunderlich04ccd4a2013-01-23 17:38:04 +0100346
347 sc->spec_config.enabled = 0;
348 sc->spec_config.short_repeat = true;
349 sc->spec_config.count = 8;
350 sc->spec_config.endless = false;
351 sc->spec_config.period = 0xFF;
352 sc->spec_config.fft_period = 0xF;
Sujith285f2dd2010-01-08 10:36:07 +0530353}
354
Sujith Manoharan0f978bf2013-12-06 16:28:45 +0530355static void ath9k_init_pcoem_platform(struct ath_softc *sc)
Sujith Manoharan9b60b642013-06-13 22:51:26 +0530356{
357 struct ath_hw *ah = sc->sc_ah;
Sujith Manoharan3f2da952013-08-04 14:21:56 +0530358 struct ath9k_hw_capabilities *pCap = &ah->caps;
Sujith Manoharan9b60b642013-06-13 22:51:26 +0530359 struct ath_common *common = ath9k_hw_common(ah);
360
361 if (common->bus_ops->ath_bus_type != ATH_PCI)
362 return;
363
Sujith Manoharane861ef52013-06-18 10:13:43 +0530364 if (sc->driver_data & (ATH9K_PCI_CUS198 |
365 ATH9K_PCI_CUS230)) {
Sujith Manoharan9b60b642013-06-13 22:51:26 +0530366 ah->config.xlna_gpio = 9;
367 ah->config.xatten_margin_cfg = true;
Sujith Manoharane083a422013-08-19 11:04:01 +0530368 ah->config.alt_mingainidx = true;
Sujith Manoharan31fd2162013-08-04 14:22:01 +0530369 ah->config.ant_ctrl_comm2g_switch_enable = 0x000BBB88;
Sujith Manoharan3afa6b42013-08-04 14:21:54 +0530370 sc->ant_comb.low_rssi_thresh = 20;
371 sc->ant_comb.fast_div_bias = 3;
Sujith Manoharan9b60b642013-06-13 22:51:26 +0530372
Sujith Manoharane861ef52013-06-18 10:13:43 +0530373 ath_info(common, "Set parameters for %s\n",
374 (sc->driver_data & ATH9K_PCI_CUS198) ?
375 "CUS198" : "CUS230");
Sujith Manoharan3f2da952013-08-04 14:21:56 +0530376 }
377
378 if (sc->driver_data & ATH9K_PCI_CUS217)
Sujith Manoharan12eea642013-06-18 15:42:36 +0530379 ath_info(common, "CUS217 card detected\n");
Sujith Manoharan3f2da952013-08-04 14:21:56 +0530380
Sujith Manoharan10631332013-09-02 13:59:05 +0530381 if (sc->driver_data & ATH9K_PCI_CUS252)
382 ath_info(common, "CUS252 card detected\n");
383
Sujith Manoharan3fcdd0a2013-09-02 13:59:06 +0530384 if (sc->driver_data & ATH9K_PCI_AR9565_1ANT)
385 ath_info(common, "WB335 1-ANT card detected\n");
386
387 if (sc->driver_data & ATH9K_PCI_AR9565_2ANT)
388 ath_info(common, "WB335 2-ANT card detected\n");
389
Sujith Manoharan4dd35642013-10-23 14:26:04 +0530390 if (sc->driver_data & ATH9K_PCI_KILLER)
391 ath_info(common, "Killer Wireless card detected\n");
392
Sujith Manoharan3fcdd0a2013-09-02 13:59:06 +0530393 /*
394 * Some WB335 cards do not support antenna diversity. Since
395 * we use a hardcoded value for AR9565 instead of using the
396 * EEPROM/OTP data, remove the combining feature from
397 * the HW capabilities bitmap.
398 */
399 if (sc->driver_data & (ATH9K_PCI_AR9565_1ANT | ATH9K_PCI_AR9565_2ANT)) {
400 if (!(sc->driver_data & ATH9K_PCI_BT_ANT_DIV))
401 pCap->hw_caps &= ~ATH9K_HW_CAP_ANT_DIV_COMB;
402 }
403
Sujith Manoharan3f2da952013-08-04 14:21:56 +0530404 if (sc->driver_data & ATH9K_PCI_BT_ANT_DIV) {
405 pCap->hw_caps |= ATH9K_HW_CAP_BT_ANT_DIV;
406 ath_info(common, "Set BT/WLAN RX diversity capability\n");
Sujith Manoharan9b60b642013-06-13 22:51:26 +0530407 }
Sujith Manoharand1ae25a2013-08-25 16:30:40 +0530408
409 if (sc->driver_data & ATH9K_PCI_D3_L1_WAR) {
410 ah->config.pcie_waen = 0x0040473b;
411 ath_info(common, "Enable WAR for ASPM D3/L1\n");
412 }
Sujith Manoharan2d22c7d2013-11-08 11:45:25 +0530413
414 if (sc->driver_data & ATH9K_PCI_NO_PLL_PWRSAVE) {
415 ah->config.no_pll_pwrsave = true;
416 ath_info(common, "Disable PLL PowerSave\n");
417 }
Sujith Manoharan9b60b642013-06-13 22:51:26 +0530418}
419
Gabor Juhosab5c4f72012-12-10 15:30:28 +0100420static void ath9k_eeprom_request_cb(const struct firmware *eeprom_blob,
421 void *ctx)
422{
423 struct ath9k_eeprom_ctx *ec = ctx;
424
425 if (eeprom_blob)
426 ec->ah->eeprom_blob = eeprom_blob;
427
428 complete(&ec->complete);
429}
430
431static int ath9k_eeprom_request(struct ath_softc *sc, const char *name)
432{
433 struct ath9k_eeprom_ctx ec;
434 struct ath_hw *ah = ah = sc->sc_ah;
435 int err;
436
437 /* try to load the EEPROM content asynchronously */
438 init_completion(&ec.complete);
439 ec.ah = sc->sc_ah;
440
441 err = request_firmware_nowait(THIS_MODULE, 1, name, sc->dev, GFP_KERNEL,
442 &ec, ath9k_eeprom_request_cb);
443 if (err < 0) {
444 ath_err(ath9k_hw_common(ah),
445 "EEPROM request failed\n");
446 return err;
447 }
448
449 wait_for_completion(&ec.complete);
450
451 if (!ah->eeprom_blob) {
452 ath_err(ath9k_hw_common(ah),
453 "Unable to load EEPROM file %s\n", name);
454 return -EINVAL;
455 }
456
457 return 0;
458}
459
460static void ath9k_eeprom_release(struct ath_softc *sc)
461{
462 release_firmware(sc->sc_ah->eeprom_blob);
463}
464
Sujith Manoharan0f978bf2013-12-06 16:28:45 +0530465static int ath9k_init_soc_platform(struct ath_softc *sc)
466{
467 struct ath9k_platform_data *pdata = sc->dev->platform_data;
468 struct ath_hw *ah = sc->sc_ah;
469 int ret = 0;
470
471 if (!pdata)
472 return 0;
473
474 if (pdata->eeprom_name) {
475 ret = ath9k_eeprom_request(sc, pdata->eeprom_name);
476 if (ret)
477 return ret;
478 }
479
480 if (pdata->tx_gain_buffalo)
481 ah->config.tx_gain_buffalo = true;
482
483 return ret;
484}
485
Pavel Roskineb93e892011-07-23 03:55:39 -0400486static int ath9k_init_softc(u16 devid, struct ath_softc *sc,
Sujith285f2dd2010-01-08 10:36:07 +0530487 const struct ath_bus_ops *bus_ops)
488{
Felix Fietkau6fb1b1e2011-03-19 13:55:39 +0100489 struct ath9k_platform_data *pdata = sc->dev->platform_data;
Sujith285f2dd2010-01-08 10:36:07 +0530490 struct ath_hw *ah = NULL;
Sujith Manoharan3f2da952013-08-04 14:21:56 +0530491 struct ath9k_hw_capabilities *pCap;
Sujith285f2dd2010-01-08 10:36:07 +0530492 struct ath_common *common;
493 int ret = 0, i;
494 int csz = 0;
495
Felix Fietkaub81950b12012-12-12 13:14:22 +0100496 ah = devm_kzalloc(sc->dev, sizeof(struct ath_hw), GFP_KERNEL);
Sujith285f2dd2010-01-08 10:36:07 +0530497 if (!ah)
498 return -ENOMEM;
499
Felix Fietkauc1b976d2012-12-12 13:14:23 +0100500 ah->dev = sc->dev;
Ben Greear233536e2011-01-09 23:11:44 -0800501 ah->hw = sc->hw;
Sujith285f2dd2010-01-08 10:36:07 +0530502 ah->hw_version.devid = devid;
Felix Fietkauf9f84e92011-03-23 20:57:24 +0100503 ah->reg_ops.read = ath9k_ioread32;
504 ah->reg_ops.write = ath9k_iowrite32;
Felix Fietkau845e03c2011-03-23 20:57:25 +0100505 ah->reg_ops.rmw = ath9k_reg_rmw;
Sujith285f2dd2010-01-08 10:36:07 +0530506 sc->sc_ah = ah;
Sujith Manoharan3f2da952013-08-04 14:21:56 +0530507 pCap = &ah->caps;
Sujith285f2dd2010-01-08 10:36:07 +0530508
Janusz Dziedzic95a59922013-10-14 11:06:03 +0200509 common = ath9k_hw_common(ah);
510 sc->dfs_detector = dfs_pattern_detector_init(common, NL80211_DFS_UNSET);
Luis R. Rodriguez89f927a2013-10-14 17:42:11 -0700511 sc->tx99_power = MAX_RATE_POWER + 1;
Felix Fietkau10e23182013-11-11 22:23:35 +0100512 init_waitqueue_head(&sc->tx_wait);
Zefir Kurtisi8e92d3f2012-04-03 17:15:50 +0200513
Helmut Schaa552a5152014-05-07 09:28:31 +0200514 if (!pdata || pdata->use_eeprom) {
Felix Fietkaua05b5d452010-11-17 04:25:33 +0100515 ah->ah_flags |= AH_USE_EEPROM;
Felix Fietkau6de66dd2011-03-19 13:55:40 +0100516 sc->sc_ah->led_pin = -1;
517 } else {
518 sc->sc_ah->gpio_mask = pdata->gpio_mask;
519 sc->sc_ah->gpio_val = pdata->gpio_val;
520 sc->sc_ah->led_pin = pdata->led_pin;
Vasanthakumar Thiagarajanf2f5f2a2011-04-19 19:29:01 +0530521 ah->is_clk_25mhz = pdata->is_clk_25mhz;
Gabor Juhos37625612011-06-21 11:23:23 +0200522 ah->get_mac_revision = pdata->get_mac_revision;
Gabor Juhos7d95847c2011-06-21 11:23:51 +0200523 ah->external_reset = pdata->external_reset;
Felix Fietkau6de66dd2011-03-19 13:55:40 +0100524 }
Felix Fietkaua05b5d452010-11-17 04:25:33 +0100525
Felix Fietkauf9f84e92011-03-23 20:57:24 +0100526 common->ops = &ah->reg_ops;
Sujith285f2dd2010-01-08 10:36:07 +0530527 common->bus_ops = bus_ops;
528 common->ah = ah;
529 common->hw = sc->hw;
530 common->priv = sc;
531 common->debug_mask = ath9k_debug;
Vasanthakumar Thiagarajan8f5dcb12010-11-26 06:10:06 -0800532 common->btcoex_enabled = ath9k_btcoex_enable == 1;
Mohammed Shafi Shajakhan05c0be22011-05-26 10:56:15 +0530533 common->disable_ani = false;
Sujith Manoharane09f2dc2012-09-16 08:06:56 +0530534
535 /*
Sujith Manoharan9b60b642013-06-13 22:51:26 +0530536 * Platform quirks.
537 */
Sujith Manoharan0f978bf2013-12-06 16:28:45 +0530538 ath9k_init_pcoem_platform(sc);
539
540 ret = ath9k_init_soc_platform(sc);
541 if (ret)
542 return ret;
Sujith Manoharan9b60b642013-06-13 22:51:26 +0530543
544 /*
Sujith Manoharan3f2da952013-08-04 14:21:56 +0530545 * Enable WLAN/BT RX Antenna diversity only when:
546 *
Sujith Manoharan7d845872013-08-07 12:29:27 +0530547 * - BTCOEX is disabled.
Sujith Manoharan3f2da952013-08-04 14:21:56 +0530548 * - the user manually requests the feature.
549 * - the HW cap is set using the platform data.
Sujith Manoharane09f2dc2012-09-16 08:06:56 +0530550 */
Sujith Manoharan7d845872013-08-07 12:29:27 +0530551 if (!common->btcoex_enabled && ath9k_bt_ant_diversity &&
Sujith Manoharan3f2da952013-08-04 14:21:56 +0530552 (pCap->hw_caps & ATH9K_HW_CAP_BT_ANT_DIV))
Sujith Manoharan63081302013-08-04 14:21:55 +0530553 common->bt_ant_diversity = 1;
Sujith Manoharane09f2dc2012-09-16 08:06:56 +0530554
Ben Greear20b257442010-10-15 15:04:09 -0700555 spin_lock_init(&common->cc_lock);
Sujith285f2dd2010-01-08 10:36:07 +0530556 spin_lock_init(&sc->sc_serial_rw);
557 spin_lock_init(&sc->sc_pm_lock);
Felix Fietkaubff11762014-06-11 16:17:52 +0530558 spin_lock_init(&sc->chan_lock);
Sujith285f2dd2010-01-08 10:36:07 +0530559 mutex_init(&sc->mutex);
560 tasklet_init(&sc->intr_tq, ath9k_tasklet, (unsigned long)sc);
Sujith Manoharanfb6e2522012-07-17 17:16:22 +0530561 tasklet_init(&sc->bcon_tasklet, ath9k_beacon_tasklet,
Sujith285f2dd2010-01-08 10:36:07 +0530562 (unsigned long)sc);
563
Felix Fietkaubf3dac52013-11-11 22:23:33 +0100564 setup_timer(&sc->sleep_timer, ath_ps_full_sleep, (unsigned long)sc);
Sujith Manoharanaaa1ec42012-06-04 16:27:08 +0530565 INIT_WORK(&sc->hw_reset_work, ath_reset_work);
Sujith Manoharanaaa1ec42012-06-04 16:27:08 +0530566 INIT_WORK(&sc->paprd_work, ath_paprd_calibrate);
Felix Fietkaubff11762014-06-11 16:17:52 +0530567 INIT_WORK(&sc->chanctx_work, ath_chanctx_work);
Sujith Manoharanaaa1ec42012-06-04 16:27:08 +0530568 INIT_DELAYED_WORK(&sc->hw_pll_work, ath_hw_pll_work);
Felix Fietkau78b21942014-06-11 16:17:55 +0530569 setup_timer(&sc->offchannel.timer, ath_offchannel_timer,
570 (unsigned long)sc);
Sujith Manoharanaaa1ec42012-06-04 16:27:08 +0530571
Sujith285f2dd2010-01-08 10:36:07 +0530572 /*
573 * Cache line size is used to size and align various
574 * structures used to communicate with the hardware.
575 */
576 ath_read_cachesize(common, &csz);
577 common->cachelsz = csz << 2; /* convert to bytes */
578
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400579 /* Initializes the hardware for all supported chipsets */
Sujith285f2dd2010-01-08 10:36:07 +0530580 ret = ath9k_hw_init(ah);
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400581 if (ret)
Sujith285f2dd2010-01-08 10:36:07 +0530582 goto err_hw;
Sujith285f2dd2010-01-08 10:36:07 +0530583
Felix Fietkau6fb1b1e2011-03-19 13:55:39 +0100584 if (pdata && pdata->macaddr)
585 memcpy(common->macaddr, pdata->macaddr, ETH_ALEN);
586
Sujith285f2dd2010-01-08 10:36:07 +0530587 ret = ath9k_init_queues(sc);
588 if (ret)
589 goto err_queues;
590
591 ret = ath9k_init_btcoex(sc);
592 if (ret)
593 goto err_btcoex;
594
Oleksij Rempel13f71052014-02-25 14:48:50 +0100595 ret = ath9k_cmn_init_channels_rates(common);
Felix Fietkauf209f522010-10-01 01:06:53 +0200596 if (ret)
597 goto err_btcoex;
598
Felix Fietkaud463af42014-04-06 00:37:03 +0200599 sc->p2p_ps_timer = ath_gen_timer_alloc(sc->sc_ah, ath9k_p2p_ps_timer,
600 NULL, sc, AR_FIRST_NDP_TIMER);
601
Rajkumar Manoharanf82b4bd2011-08-13 10:28:15 +0530602 ath9k_cmn_init_crypto(sc->sc_ah);
Sujith285f2dd2010-01-08 10:36:07 +0530603 ath9k_init_misc(sc);
Rajkumar Manoharan8f176a32012-09-12 18:59:23 +0530604 ath_fill_led_pin(sc);
Felix Fietkaufbbcd142014-06-11 16:17:49 +0530605 ath_chanctx_init(sc);
Sujith285f2dd2010-01-08 10:36:07 +0530606
Sujith Manoharand09f5f42012-06-04 16:27:14 +0530607 if (common->bus_ops->aspm_init)
608 common->bus_ops->aspm_init(common);
609
Sujith55624202010-01-08 10:36:02 +0530610 return 0;
Sujith285f2dd2010-01-08 10:36:07 +0530611
612err_btcoex:
Sujith55624202010-01-08 10:36:02 +0530613 for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++)
614 if (ATH_TXQ_SETUP(sc, i))
615 ath_tx_cleanupq(sc, &sc->tx.txq[i]);
Sujith285f2dd2010-01-08 10:36:07 +0530616err_queues:
Sujith285f2dd2010-01-08 10:36:07 +0530617 ath9k_hw_deinit(ah);
618err_hw:
Gabor Juhosab5c4f72012-12-10 15:30:28 +0100619 ath9k_eeprom_release(sc);
Luis R. Rodriguez89f927a2013-10-14 17:42:11 -0700620 dev_kfree_skb_any(sc->tx99_skb);
Sujith285f2dd2010-01-08 10:36:07 +0530621 return ret;
Sujith55624202010-01-08 10:36:02 +0530622}
623
Felix Fietkaubabcbc22010-10-20 02:09:46 +0200624static void ath9k_init_band_txpower(struct ath_softc *sc, int band)
625{
626 struct ieee80211_supported_band *sband;
627 struct ieee80211_channel *chan;
628 struct ath_hw *ah = sc->sc_ah;
Oleksij Rempel13f71052014-02-25 14:48:50 +0100629 struct ath_common *common = ath9k_hw_common(ah);
Simon Wunderlich06718942013-08-16 10:46:04 +0200630 struct cfg80211_chan_def chandef;
Felix Fietkaubabcbc22010-10-20 02:09:46 +0200631 int i;
632
Oleksij Rempel13f71052014-02-25 14:48:50 +0100633 sband = &common->sbands[band];
Felix Fietkaubabcbc22010-10-20 02:09:46 +0200634 for (i = 0; i < sband->n_channels; i++) {
635 chan = &sband->channels[i];
636 ah->curchan = &ah->channels[chan->hw_value];
Simon Wunderlich06718942013-08-16 10:46:04 +0200637 cfg80211_chandef_create(&chandef, chan, NL80211_CHAN_HT20);
Felix Fietkau2297f1c2013-10-11 23:30:57 +0200638 ath9k_cmn_get_channel(sc->hw, ah, &chandef);
Felix Fietkaubabcbc22010-10-20 02:09:46 +0200639 ath9k_hw_set_txpowerlimit(ah, MAX_RATE_POWER, true);
Felix Fietkaubabcbc22010-10-20 02:09:46 +0200640 }
641}
642
643static void ath9k_init_txpower_limits(struct ath_softc *sc)
644{
645 struct ath_hw *ah = sc->sc_ah;
646 struct ath9k_channel *curchan = ah->curchan;
647
648 if (ah->caps.hw_caps & ATH9K_HW_CAP_2GHZ)
649 ath9k_init_band_txpower(sc, IEEE80211_BAND_2GHZ);
650 if (ah->caps.hw_caps & ATH9K_HW_CAP_5GHZ)
651 ath9k_init_band_txpower(sc, IEEE80211_BAND_5GHZ);
652
653 ah->curchan = curchan;
654}
655
Felix Fietkau20c8e8d2012-04-17 02:40:07 +0200656static const struct ieee80211_iface_limit if_limits[] = {
Rajkumar Manoharan71a5f882014-05-29 15:11:09 +0530657 { .max = 2048, .types = BIT(NL80211_IFTYPE_STATION) },
Felix Fietkau20c8e8d2012-04-17 02:40:07 +0200658 { .max = 8, .types =
659#ifdef CONFIG_MAC80211_MESH
660 BIT(NL80211_IFTYPE_MESH_POINT) |
661#endif
Felix Fietkau95ae4812014-04-06 00:37:02 +0200662 BIT(NL80211_IFTYPE_AP) },
663 { .max = 1, .types = BIT(NL80211_IFTYPE_P2P_CLIENT) |
Felix Fietkau20c8e8d2012-04-17 02:40:07 +0200664 BIT(NL80211_IFTYPE_P2P_GO) },
665};
666
Rajkumar Manoharan71a5f882014-05-29 15:11:09 +0530667static const struct ieee80211_iface_limit wds_limits[] = {
668 { .max = 2048, .types = BIT(NL80211_IFTYPE_WDS) },
669};
670
Zefir Kurtisie9cdedf2013-04-03 18:31:29 +0200671static const struct ieee80211_iface_limit if_dfs_limits[] = {
Simon Wunderlich3c57e862013-10-07 16:41:07 +0100672 { .max = 1, .types = BIT(NL80211_IFTYPE_AP) |
Chun-Yeow Yeoh997b1792013-12-04 18:46:54 +0800673#ifdef CONFIG_MAC80211_MESH
674 BIT(NL80211_IFTYPE_MESH_POINT) |
675#endif
Simon Wunderlich3c57e862013-10-07 16:41:07 +0100676 BIT(NL80211_IFTYPE_ADHOC) },
Zefir Kurtisie9cdedf2013-04-03 18:31:29 +0200677};
678
679static const struct ieee80211_iface_combination if_comb[] = {
680 {
681 .limits = if_limits,
682 .n_limits = ARRAY_SIZE(if_limits),
683 .max_interfaces = 2048,
684 .num_different_channels = 1,
685 .beacon_int_infra_match = true,
686 },
Rajkumar Manoharan71a5f882014-05-29 15:11:09 +0530687 {
688 .limits = wds_limits,
689 .n_limits = ARRAY_SIZE(wds_limits),
690 .max_interfaces = 2048,
691 .num_different_channels = 1,
692 .beacon_int_infra_match = true,
693 },
Janusz Dziedzic4d762482014-04-08 13:38:43 +0200694#ifdef CONFIG_ATH9K_DFS_CERTIFIED
Zefir Kurtisie9cdedf2013-04-03 18:31:29 +0200695 {
696 .limits = if_dfs_limits,
697 .n_limits = ARRAY_SIZE(if_dfs_limits),
698 .max_interfaces = 1,
699 .num_different_channels = 1,
700 .beacon_int_infra_match = true,
Janusz Dziedzic87eb0162013-11-01 20:39:49 +0100701 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
702 BIT(NL80211_CHAN_WIDTH_20),
Zefir Kurtisie9cdedf2013-04-03 18:31:29 +0200703 }
Janusz Dziedzic4d762482014-04-08 13:38:43 +0200704#endif
Felix Fietkau20c8e8d2012-04-17 02:40:07 +0200705};
Felix Fietkau43c35282011-09-03 01:40:27 +0200706
Sujith Manoharan7b6ef992013-12-18 09:53:19 +0530707static void ath9k_set_hw_capab(struct ath_softc *sc, struct ieee80211_hw *hw)
Sujith55624202010-01-08 10:36:02 +0530708{
Felix Fietkau43c35282011-09-03 01:40:27 +0200709 struct ath_hw *ah = sc->sc_ah;
710 struct ath_common *common = ath9k_hw_common(ah);
Sujith285f2dd2010-01-08 10:36:07 +0530711
Sujith55624202010-01-08 10:36:02 +0530712 hw->flags = IEEE80211_HW_RX_INCLUDES_FCS |
713 IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING |
714 IEEE80211_HW_SIGNAL_DBM |
Sujith55624202010-01-08 10:36:02 +0530715 IEEE80211_HW_PS_NULLFUNC_STACK |
Vivek Natarajan05df4982010-02-09 11:34:50 +0530716 IEEE80211_HW_SPECTRUM_MGMT |
Felix Fietkau79acac02013-04-22 23:11:44 +0200717 IEEE80211_HW_REPORTS_TX_ACK_STATUS |
Felix Fietkau2dfca312013-08-20 19:43:54 +0200718 IEEE80211_HW_SUPPORTS_RC_TABLE |
719 IEEE80211_HW_SUPPORTS_HT_CCK_RATES;
Sujith55624202010-01-08 10:36:02 +0530720
Sujith Manoharan82983832014-02-04 08:37:53 +0530721 if (ath9k_ps_enable)
722 hw->flags |= IEEE80211_HW_SUPPORTS_PS;
723
Oleksij Rempelb0a1ae92013-05-24 20:30:59 +0200724 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_HT) {
725 hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION;
726
727 if (AR_SREV_9280_20_OR_LATER(ah))
728 hw->radiotap_mcs_details |=
729 IEEE80211_RADIOTAP_MCS_HAVE_STBC;
730 }
Luis R. Rodriguez5ffaf8a2010-02-02 11:58:33 -0500731
John W. Linville3e6109c2011-01-05 09:39:17 -0500732 if (AR_SREV_9160_10_OR_LATER(sc->sc_ah) || ath9k_modparam_nohwcrypt)
Sujith55624202010-01-08 10:36:02 +0530733 hw->flags |= IEEE80211_HW_MFP_CAPABLE;
734
Rajkumar Manoharanb59d45e2014-05-01 17:07:43 +0530735 hw->wiphy->features |= (NL80211_FEATURE_ACTIVE_MONITOR |
736 NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE);
Felix Fietkauec26bcc2013-05-28 13:01:54 +0200737
Luis R. Rodriguez89f927a2013-10-14 17:42:11 -0700738 if (!config_enabled(CONFIG_ATH9K_TX99)) {
739 hw->wiphy->interface_modes =
740 BIT(NL80211_IFTYPE_P2P_GO) |
741 BIT(NL80211_IFTYPE_P2P_CLIENT) |
742 BIT(NL80211_IFTYPE_AP) |
Luis R. Rodriguez89f927a2013-10-14 17:42:11 -0700743 BIT(NL80211_IFTYPE_STATION) |
744 BIT(NL80211_IFTYPE_ADHOC) |
745 BIT(NL80211_IFTYPE_MESH_POINT);
746 hw->wiphy->iface_combinations = if_comb;
Rajkumar Manoharan71a5f882014-05-29 15:11:09 +0530747 if (!ath9k_use_chanctx) {
748 hw->wiphy->n_iface_combinations = ARRAY_SIZE(if_comb);
749 hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_WDS);
Felix Fietkau78b21942014-06-11 16:17:55 +0530750 } else {
Rajkumar Manoharan71a5f882014-05-29 15:11:09 +0530751 hw->wiphy->n_iface_combinations = 1;
Felix Fietkau78b21942014-06-11 16:17:55 +0530752 hw->wiphy->max_scan_ssids = 255;
753 hw->wiphy->max_scan_ie_len = IEEE80211_MAX_DATA_LEN;
754 }
Luis R. Rodriguez89f927a2013-10-14 17:42:11 -0700755 }
Felix Fietkau20c8e8d2012-04-17 02:40:07 +0200756
Sujith Manoharan531671c2013-06-01 07:08:09 +0530757 hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
Sujith55624202010-01-08 10:36:02 +0530758
Jouni Malinencfdc9a82011-03-23 14:52:19 +0200759 hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
Jouni Malinenfd656232011-10-27 17:31:50 +0300760 hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS;
Johannes Berg81ddbb52012-03-26 18:47:18 +0200761 hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
Simon Wunderlich6fac8bb2013-08-14 08:01:34 +0200762 hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_5_10_MHZ;
Simon Wunderlichd074e8d2013-08-14 08:01:38 +0200763 hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
Jouni Malinen7b4f6632014-02-18 20:41:08 +0200764 hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
Jouni Malinencfdc9a82011-03-23 14:52:19 +0200765
Sujith55624202010-01-08 10:36:02 +0530766 hw->queues = 4;
767 hw->max_rates = 4;
Rajkumar Manoharan195ca3b2012-03-15 23:05:28 +0530768 hw->max_listen_interval = 1;
Felix Fietkau65896512010-01-24 03:26:11 +0100769 hw->max_rate_tries = 10;
Sujith55624202010-01-08 10:36:02 +0530770 hw->sta_data_size = sizeof(struct ath_node);
771 hw->vif_data_size = sizeof(struct ath_vif);
772
Felix Fietkau43c35282011-09-03 01:40:27 +0200773 hw->wiphy->available_antennas_rx = BIT(ah->caps.max_rxchains) - 1;
774 hw->wiphy->available_antennas_tx = BIT(ah->caps.max_txchains) - 1;
775
776 /* single chain devices with rx diversity */
777 if (ah->caps.hw_caps & ATH9K_HW_CAP_ANT_DIV_COMB)
778 hw->wiphy->available_antennas_rx = BIT(0) | BIT(1);
779
780 sc->ant_rx = hw->wiphy->available_antennas_rx;
781 sc->ant_tx = hw->wiphy->available_antennas_tx;
782
Felix Fietkaud4659912010-10-14 16:02:39 +0200783 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_2GHZ)
Sujith55624202010-01-08 10:36:02 +0530784 hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
Oleksij Rempel13f71052014-02-25 14:48:50 +0100785 &common->sbands[IEEE80211_BAND_2GHZ];
Felix Fietkaud4659912010-10-14 16:02:39 +0200786 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_5GHZ)
Sujith55624202010-01-08 10:36:02 +0530787 hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
Oleksij Rempel13f71052014-02-25 14:48:50 +0100788 &common->sbands[IEEE80211_BAND_5GHZ];
Sujith285f2dd2010-01-08 10:36:07 +0530789
Sujith Manoharanbabaa802013-10-28 13:01:28 +0530790 ath9k_init_wow(hw);
Oleksij Rempelb57ba3b2014-02-25 14:48:55 +0100791 ath9k_cmn_reload_chainmask(ah);
Sujith285f2dd2010-01-08 10:36:07 +0530792
793 SET_IEEE80211_PERM_ADDR(hw, common->macaddr);
Sujith55624202010-01-08 10:36:02 +0530794}
795
Pavel Roskineb93e892011-07-23 03:55:39 -0400796int ath9k_init_device(u16 devid, struct ath_softc *sc,
Sujith55624202010-01-08 10:36:02 +0530797 const struct ath_bus_ops *bus_ops)
798{
799 struct ieee80211_hw *hw = sc->hw;
800 struct ath_common *common;
801 struct ath_hw *ah;
Sujith285f2dd2010-01-08 10:36:07 +0530802 int error = 0;
Sujith55624202010-01-08 10:36:02 +0530803 struct ath_regulatory *reg;
804
Sujith285f2dd2010-01-08 10:36:07 +0530805 /* Bring up device */
Pavel Roskineb93e892011-07-23 03:55:39 -0400806 error = ath9k_init_softc(devid, sc, bus_ops);
Felix Fietkaub81950b12012-12-12 13:14:22 +0100807 if (error)
808 return error;
Sujith55624202010-01-08 10:36:02 +0530809
810 ah = sc->sc_ah;
811 common = ath9k_hw_common(ah);
Sujith285f2dd2010-01-08 10:36:07 +0530812 ath9k_set_hw_capab(sc, hw);
Sujith55624202010-01-08 10:36:02 +0530813
Rajkumar Manoharan8c7ae352014-04-23 15:07:57 +0530814 /* Will be cleared in ath9k_start() */
815 set_bit(ATH_OP_INVALID, &common->op_flags);
816
Sujith285f2dd2010-01-08 10:36:07 +0530817 /* Initialize regulatory */
Sujith55624202010-01-08 10:36:02 +0530818 error = ath_regd_init(&common->regulatory, sc->hw->wiphy,
819 ath9k_reg_notifier);
820 if (error)
Felix Fietkaub81950b12012-12-12 13:14:22 +0100821 goto deinit;
Sujith55624202010-01-08 10:36:02 +0530822
823 reg = &common->regulatory;
824
Sujith285f2dd2010-01-08 10:36:07 +0530825 /* Setup TX DMA */
Sujith55624202010-01-08 10:36:02 +0530826 error = ath_tx_init(sc, ATH_TXBUF);
827 if (error != 0)
Felix Fietkaub81950b12012-12-12 13:14:22 +0100828 goto deinit;
Sujith55624202010-01-08 10:36:02 +0530829
Sujith285f2dd2010-01-08 10:36:07 +0530830 /* Setup RX DMA */
Sujith55624202010-01-08 10:36:02 +0530831 error = ath_rx_init(sc, ATH_RXBUF);
832 if (error != 0)
Felix Fietkaub81950b12012-12-12 13:14:22 +0100833 goto deinit;
Sujith285f2dd2010-01-08 10:36:07 +0530834
Felix Fietkaubabcbc22010-10-20 02:09:46 +0200835 ath9k_init_txpower_limits(sc);
836
Felix Fietkau0cf55c22011-02-27 22:26:40 +0100837#ifdef CONFIG_MAC80211_LEDS
838 /* must be initialized before ieee80211_register_hw */
839 sc->led_cdev.default_trigger = ieee80211_create_tpt_led_trigger(sc->hw,
840 IEEE80211_TPT_LEDTRIG_FL_RADIO, ath9k_tpt_blink,
841 ARRAY_SIZE(ath9k_tpt_blink));
842#endif
843
Sujith285f2dd2010-01-08 10:36:07 +0530844 /* Register with mac80211 */
845 error = ieee80211_register_hw(hw);
846 if (error)
Felix Fietkaub81950b12012-12-12 13:14:22 +0100847 goto rx_cleanup;
Sujith285f2dd2010-01-08 10:36:07 +0530848
Ben Greeareb272442010-11-29 14:13:22 -0800849 error = ath9k_init_debug(ah);
850 if (error) {
Joe Perches38002762010-12-02 19:12:36 -0800851 ath_err(common, "Unable to create debugfs files\n");
Felix Fietkaub81950b12012-12-12 13:14:22 +0100852 goto unregister;
Ben Greeareb272442010-11-29 14:13:22 -0800853 }
854
Sujith285f2dd2010-01-08 10:36:07 +0530855 /* Handle world regulatory */
856 if (!ath_is_world_regd(reg)) {
857 error = regulatory_hint(hw->wiphy, reg->alpha2);
858 if (error)
Sujith Manoharanaf690092013-05-10 18:41:06 +0530859 goto debug_cleanup;
Sujith285f2dd2010-01-08 10:36:07 +0530860 }
Sujith55624202010-01-08 10:36:02 +0530861
Sujith55624202010-01-08 10:36:02 +0530862 ath_init_leds(sc);
Sujith55624202010-01-08 10:36:02 +0530863 ath_start_rfkill_poll(sc);
864
865 return 0;
866
Sujith Manoharanaf690092013-05-10 18:41:06 +0530867debug_cleanup:
868 ath9k_deinit_debug(sc);
Felix Fietkaub81950b12012-12-12 13:14:22 +0100869unregister:
Sujith285f2dd2010-01-08 10:36:07 +0530870 ieee80211_unregister_hw(hw);
Felix Fietkaub81950b12012-12-12 13:14:22 +0100871rx_cleanup:
Sujith285f2dd2010-01-08 10:36:07 +0530872 ath_rx_cleanup(sc);
Felix Fietkaub81950b12012-12-12 13:14:22 +0100873deinit:
Sujith285f2dd2010-01-08 10:36:07 +0530874 ath9k_deinit_softc(sc);
Sujith55624202010-01-08 10:36:02 +0530875 return error;
876}
877
878/*****************************/
879/* De-Initialization */
880/*****************************/
881
Sujith285f2dd2010-01-08 10:36:07 +0530882static void ath9k_deinit_softc(struct ath_softc *sc)
Sujith55624202010-01-08 10:36:02 +0530883{
Sujith285f2dd2010-01-08 10:36:07 +0530884 int i = 0;
Sujith55624202010-01-08 10:36:02 +0530885
Felix Fietkaud463af42014-04-06 00:37:03 +0200886 if (sc->p2p_ps_timer)
887 ath_gen_timer_free(sc->sc_ah, sc->p2p_ps_timer);
888
Sujith Manoharan59081202012-02-22 12:40:21 +0530889 ath9k_deinit_btcoex(sc);
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530890
Sujith285f2dd2010-01-08 10:36:07 +0530891 for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++)
892 if (ATH_TXQ_SETUP(sc, i))
893 ath_tx_cleanupq(sc, &sc->tx.txq[i]);
894
Felix Fietkaubf3dac52013-11-11 22:23:33 +0100895 del_timer_sync(&sc->sleep_timer);
Sujith285f2dd2010-01-08 10:36:07 +0530896 ath9k_hw_deinit(sc->sc_ah);
Zefir Kurtisi8e92d3f2012-04-03 17:15:50 +0200897 if (sc->dfs_detector != NULL)
898 sc->dfs_detector->exit(sc->dfs_detector);
Sujith285f2dd2010-01-08 10:36:07 +0530899
Gabor Juhosab5c4f72012-12-10 15:30:28 +0100900 ath9k_eeprom_release(sc);
Sujith55624202010-01-08 10:36:02 +0530901}
902
Sujith285f2dd2010-01-08 10:36:07 +0530903void ath9k_deinit_device(struct ath_softc *sc)
Sujith55624202010-01-08 10:36:02 +0530904{
905 struct ieee80211_hw *hw = sc->hw;
Sujith55624202010-01-08 10:36:02 +0530906
907 ath9k_ps_wakeup(sc);
908
Sujith55624202010-01-08 10:36:02 +0530909 wiphy_rfkill_stop_polling(sc->hw->wiphy);
Sujith285f2dd2010-01-08 10:36:07 +0530910 ath_deinit_leds(sc);
Sujith55624202010-01-08 10:36:02 +0530911
Rajkumar Manoharanc7c18062011-01-27 18:39:38 +0530912 ath9k_ps_restore(sc);
913
Sujith Manoharanaf690092013-05-10 18:41:06 +0530914 ath9k_deinit_debug(sc);
Sujith55624202010-01-08 10:36:02 +0530915 ieee80211_unregister_hw(hw);
916 ath_rx_cleanup(sc);
Sujith285f2dd2010-01-08 10:36:07 +0530917 ath9k_deinit_softc(sc);
Sujith55624202010-01-08 10:36:02 +0530918}
919
Sujith55624202010-01-08 10:36:02 +0530920/************************/
921/* Module Hooks */
922/************************/
923
924static int __init ath9k_init(void)
925{
926 int error;
927
Sujith55624202010-01-08 10:36:02 +0530928 error = ath_pci_init();
929 if (error < 0) {
Joe Perches516304b2012-03-18 17:30:52 -0700930 pr_err("No PCI devices found, driver not installed\n");
Sujith55624202010-01-08 10:36:02 +0530931 error = -ENODEV;
Sujith Manoharan9e495a22014-02-06 10:22:55 +0530932 goto err_out;
Sujith55624202010-01-08 10:36:02 +0530933 }
934
935 error = ath_ahb_init();
936 if (error < 0) {
937 error = -ENODEV;
938 goto err_pci_exit;
939 }
940
941 return 0;
942
943 err_pci_exit:
944 ath_pci_exit();
Sujith55624202010-01-08 10:36:02 +0530945 err_out:
946 return error;
947}
948module_init(ath9k_init);
949
950static void __exit ath9k_exit(void)
951{
Rajkumar Manoharand5847472010-12-20 14:39:51 +0530952 is_ath9k_unloaded = true;
Sujith55624202010-01-08 10:36:02 +0530953 ath_ahb_exit();
954 ath_pci_exit();
Joe Perches516304b2012-03-18 17:30:52 -0700955 pr_info("%s: Driver unloaded\n", dev_info);
Sujith55624202010-01-08 10:36:02 +0530956}
957module_exit(ath9k_exit);