blob: 384929d7169656233de2fec7ba8d7cabb917d9d1 [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
Hong Xu0c8a1e42015-01-24 03:34:03 -080048int ath9k_led_blink;
49module_param_named(blink, ath9k_led_blink, int, 0444);
Vivek Natarajan9a75c2f2010-06-22 11:52:37 +053050MODULE_PARM_DESC(blink, "Enable LED blink on activity");
51
Vittorio Gambaletta (VittGam)cd840422016-04-11 04:48:54 +020052static int ath9k_led_active_high = -1;
53module_param_named(led_active_high, ath9k_led_active_high, int, 0444);
54MODULE_PARM_DESC(led_active_high, "Invert LED polarity");
55
Vasanthakumar Thiagarajan8f5dcb12010-11-26 06:10:06 -080056static int ath9k_btcoex_enable;
57module_param_named(btcoex_enable, ath9k_btcoex_enable, int, 0444);
58MODULE_PARM_DESC(btcoex_enable, "Enable wifi-BT coexistence");
59
Sujith Manoharan63081302013-08-04 14:21:55 +053060static int ath9k_bt_ant_diversity;
61module_param_named(bt_ant_diversity, ath9k_bt_ant_diversity, int, 0444);
62MODULE_PARM_DESC(bt_ant_diversity, "Enable WLAN/BT RX antenna diversity");
Sujith Manoharane09f2dc2012-09-16 08:06:56 +053063
Sujith Manoharan82983832014-02-04 08:37:53 +053064static int ath9k_ps_enable;
65module_param_named(ps_enable, ath9k_ps_enable, int, 0444);
66MODULE_PARM_DESC(ps_enable, "Enable WLAN PowerSave");
67
Sujith Manoharan499afac2014-08-22 20:39:31 +053068#ifdef CONFIG_ATH9K_CHANNEL_CONTEXT
69
Felix Fietkau78b21942014-06-11 16:17:55 +053070int ath9k_use_chanctx;
Rajkumar Manoharan71a5f882014-05-29 15:11:09 +053071module_param_named(use_chanctx, ath9k_use_chanctx, int, 0444);
72MODULE_PARM_DESC(use_chanctx, "Enable channel context for concurrency");
73
Sujith Manoharan499afac2014-08-22 20:39:31 +053074#endif /* CONFIG_ATH9K_CHANNEL_CONTEXT */
75
Rajkumar Manoharand5847472010-12-20 14:39:51 +053076bool is_ath9k_unloaded;
Sujith55624202010-01-08 10:36:02 +053077
Felix Fietkau0cf55c22011-02-27 22:26:40 +010078#ifdef CONFIG_MAC80211_LEDS
79static const struct ieee80211_tpt_blink ath9k_tpt_blink[] = {
80 { .throughput = 0 * 1024, .blink_time = 334 },
81 { .throughput = 1 * 1024, .blink_time = 260 },
82 { .throughput = 5 * 1024, .blink_time = 220 },
83 { .throughput = 10 * 1024, .blink_time = 190 },
84 { .throughput = 20 * 1024, .blink_time = 170 },
85 { .throughput = 50 * 1024, .blink_time = 150 },
86 { .throughput = 70 * 1024, .blink_time = 130 },
87 { .throughput = 100 * 1024, .blink_time = 110 },
88 { .throughput = 200 * 1024, .blink_time = 80 },
89 { .throughput = 300 * 1024, .blink_time = 50 },
90};
91#endif
92
Sujith285f2dd2010-01-08 10:36:07 +053093static void ath9k_deinit_softc(struct ath_softc *sc);
Sujith55624202010-01-08 10:36:02 +053094
kbuild test robotd81f9a02014-11-12 06:19:48 +080095static void ath9k_op_ps_wakeup(struct ath_common *common)
Oleksij Rempel99d22172014-11-06 08:53:25 +010096{
97 ath9k_ps_wakeup((struct ath_softc *) common->priv);
98}
99
kbuild test robotd81f9a02014-11-12 06:19:48 +0800100static void ath9k_op_ps_restore(struct ath_common *common)
Oleksij Rempel99d22172014-11-06 08:53:25 +0100101{
102 ath9k_ps_restore((struct ath_softc *) common->priv);
103}
104
kbuild test robotd81f9a02014-11-12 06:19:48 +0800105static struct ath_ps_ops ath9k_ps_ops = {
Oleksij Rempel99d22172014-11-06 08:53:25 +0100106 .wakeup = ath9k_op_ps_wakeup,
107 .restore = ath9k_op_ps_restore,
108};
109
Sujith55624202010-01-08 10:36:02 +0530110/*
111 * Read and write, they both share the same lock. We do this to serialize
112 * reads and writes on Atheros 802.11n PCI devices only. This is required
113 * as the FIFO on these devices can only accept sanely 2 requests.
114 */
115
116static void ath9k_iowrite32(void *hw_priv, u32 val, u32 reg_offset)
117{
118 struct ath_hw *ah = (struct ath_hw *) hw_priv;
119 struct ath_common *common = ath9k_hw_common(ah);
120 struct ath_softc *sc = (struct ath_softc *) common->priv;
121
Felix Fietkauf3eef642012-03-14 16:40:25 +0100122 if (NR_CPUS > 1 && ah->config.serialize_regmode == SER_REG_MODE_ON) {
Sujith55624202010-01-08 10:36:02 +0530123 unsigned long flags;
124 spin_lock_irqsave(&sc->sc_serial_rw, flags);
125 iowrite32(val, sc->mem + reg_offset);
126 spin_unlock_irqrestore(&sc->sc_serial_rw, flags);
127 } else
128 iowrite32(val, sc->mem + reg_offset);
129}
130
131static unsigned int ath9k_ioread32(void *hw_priv, u32 reg_offset)
132{
133 struct ath_hw *ah = (struct ath_hw *) hw_priv;
134 struct ath_common *common = ath9k_hw_common(ah);
135 struct ath_softc *sc = (struct ath_softc *) common->priv;
136 u32 val;
137
Felix Fietkauf3eef642012-03-14 16:40:25 +0100138 if (NR_CPUS > 1 && ah->config.serialize_regmode == SER_REG_MODE_ON) {
Sujith55624202010-01-08 10:36:02 +0530139 unsigned long flags;
140 spin_lock_irqsave(&sc->sc_serial_rw, flags);
141 val = ioread32(sc->mem + reg_offset);
142 spin_unlock_irqrestore(&sc->sc_serial_rw, flags);
143 } else
144 val = ioread32(sc->mem + reg_offset);
145 return val;
146}
147
Oleksij Rempeld55ce0a2015-03-22 19:29:50 +0100148static void ath9k_multi_ioread32(void *hw_priv, u32 *addr,
149 u32 *val, u16 count)
150{
151 int i;
152
153 for (i = 0; i < count; i++)
154 val[i] = ath9k_ioread32(hw_priv, addr[i]);
155}
156
157
Rajkumar Manoharan5479de62011-07-17 11:43:02 +0530158static unsigned int __ath9k_reg_rmw(struct ath_softc *sc, u32 reg_offset,
159 u32 set, u32 clr)
160{
161 u32 val;
162
163 val = ioread32(sc->mem + reg_offset);
164 val &= ~clr;
165 val |= set;
166 iowrite32(val, sc->mem + reg_offset);
167
168 return val;
169}
170
Felix Fietkau845e03c2011-03-23 20:57:25 +0100171static unsigned int ath9k_reg_rmw(void *hw_priv, u32 reg_offset, u32 set, u32 clr)
172{
173 struct ath_hw *ah = (struct ath_hw *) hw_priv;
174 struct ath_common *common = ath9k_hw_common(ah);
175 struct ath_softc *sc = (struct ath_softc *) common->priv;
176 unsigned long uninitialized_var(flags);
177 u32 val;
178
Felix Fietkauf3eef642012-03-14 16:40:25 +0100179 if (NR_CPUS > 1 && ah->config.serialize_regmode == SER_REG_MODE_ON) {
Felix Fietkau845e03c2011-03-23 20:57:25 +0100180 spin_lock_irqsave(&sc->sc_serial_rw, flags);
Rajkumar Manoharan5479de62011-07-17 11:43:02 +0530181 val = __ath9k_reg_rmw(sc, reg_offset, set, clr);
Felix Fietkau845e03c2011-03-23 20:57:25 +0100182 spin_unlock_irqrestore(&sc->sc_serial_rw, flags);
Rajkumar Manoharan5479de62011-07-17 11:43:02 +0530183 } else
184 val = __ath9k_reg_rmw(sc, reg_offset, set, clr);
Felix Fietkau845e03c2011-03-23 20:57:25 +0100185
186 return val;
187}
188
Sujith55624202010-01-08 10:36:02 +0530189/**************************/
190/* Initialization */
191/**************************/
192
Luis R. Rodriguez0c0280b2013-01-11 18:39:36 +0000193static void ath9k_reg_notifier(struct wiphy *wiphy,
194 struct regulatory_request *request)
Sujith55624202010-01-08 10:36:02 +0530195{
196 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
Felix Fietkau9ac586152011-01-24 19:23:18 +0100197 struct ath_softc *sc = hw->priv;
Rajkumar Manoharan687f5452011-12-08 23:59:25 +0530198 struct ath_hw *ah = sc->sc_ah;
199 struct ath_regulatory *reg = ath9k_hw_regulatory(ah);
Sujith55624202010-01-08 10:36:02 +0530200
Luis R. Rodriguez0c0280b2013-01-11 18:39:36 +0000201 ath_reg_notifier_apply(wiphy, request, reg);
Rajkumar Manoharan687f5452011-12-08 23:59:25 +0530202
203 /* Set tx power */
Felix Fietkaud385c5c2014-11-04 16:56:57 +0100204 if (!ah->curchan)
205 return;
206
207 sc->cur_chan->txpower = 2 * ah->curchan->chan->max_power;
208 ath9k_ps_wakeup(sc);
209 ath9k_hw_set_txpowerlimit(ah, sc->cur_chan->txpower, false);
210 ath9k_cmn_update_txpow(ah, sc->cur_chan->cur_txpower,
211 sc->cur_chan->txpower,
212 &sc->cur_chan->cur_txpower);
213 /* synchronize DFS detector if regulatory domain changed */
214 if (sc->dfs_detector != NULL)
215 sc->dfs_detector->set_dfs_domain(sc->dfs_detector,
216 request->dfs_region);
217 ath9k_ps_restore(sc);
Sujith55624202010-01-08 10:36:02 +0530218}
219
220/*
221 * This function will allocate both the DMA descriptor structure, and the
222 * buffers it contains. These are used to contain the descriptors used
223 * by the system.
224*/
225int ath_descdma_setup(struct ath_softc *sc, struct ath_descdma *dd,
226 struct list_head *head, const char *name,
Vasanthakumar Thiagarajan4adfcde2010-04-15 17:39:33 -0400227 int nbuf, int ndesc, bool is_tx)
Sujith55624202010-01-08 10:36:02 +0530228{
Sujith55624202010-01-08 10:36:02 +0530229 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Vasanthakumar Thiagarajan4adfcde2010-04-15 17:39:33 -0400230 u8 *ds;
Felix Fietkaub81950b12012-12-12 13:14:22 +0100231 int i, bsize, desc_len;
Sujith55624202010-01-08 10:36:02 +0530232
Joe Perchesd2182b62011-12-15 14:55:53 -0800233 ath_dbg(common, CONFIG, "%s DMA: %u buffers %u desc/buf\n",
Joe Perches226afe62010-12-02 19:12:37 -0800234 name, nbuf, ndesc);
Sujith55624202010-01-08 10:36:02 +0530235
236 INIT_LIST_HEAD(head);
Vasanthakumar Thiagarajan4adfcde2010-04-15 17:39:33 -0400237
238 if (is_tx)
239 desc_len = sc->sc_ah->caps.tx_desc_len;
240 else
241 desc_len = sizeof(struct ath_desc);
242
Sujith55624202010-01-08 10:36:02 +0530243 /* ath_desc must be a multiple of DWORDs */
Vasanthakumar Thiagarajan4adfcde2010-04-15 17:39:33 -0400244 if ((desc_len % 4) != 0) {
Joe Perches38002762010-12-02 19:12:36 -0800245 ath_err(common, "ath_desc not DWORD aligned\n");
Vasanthakumar Thiagarajan4adfcde2010-04-15 17:39:33 -0400246 BUG_ON((desc_len % 4) != 0);
Felix Fietkaub81950b12012-12-12 13:14:22 +0100247 return -ENOMEM;
Sujith55624202010-01-08 10:36:02 +0530248 }
249
Vasanthakumar Thiagarajan4adfcde2010-04-15 17:39:33 -0400250 dd->dd_desc_len = desc_len * nbuf * ndesc;
Sujith55624202010-01-08 10:36:02 +0530251
252 /*
253 * Need additional DMA memory because we can't use
254 * descriptors that cross the 4K page boundary. Assume
255 * one skipped descriptor per 4K page.
256 */
257 if (!(sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_4KB_SPLITTRANS)) {
258 u32 ndesc_skipped =
259 ATH_DESC_4KB_BOUND_NUM_SKIPPED(dd->dd_desc_len);
260 u32 dma_len;
261
262 while (ndesc_skipped) {
Vasanthakumar Thiagarajan4adfcde2010-04-15 17:39:33 -0400263 dma_len = ndesc_skipped * desc_len;
Sujith55624202010-01-08 10:36:02 +0530264 dd->dd_desc_len += dma_len;
265
266 ndesc_skipped = ATH_DESC_4KB_BOUND_NUM_SKIPPED(dma_len);
Joe Perchesee289b62010-05-17 22:47:34 -0700267 }
Sujith55624202010-01-08 10:36:02 +0530268 }
269
270 /* allocate descriptors */
Felix Fietkaub81950b12012-12-12 13:14:22 +0100271 dd->dd_desc = dmam_alloc_coherent(sc->dev, dd->dd_desc_len,
272 &dd->dd_desc_paddr, GFP_KERNEL);
273 if (!dd->dd_desc)
274 return -ENOMEM;
275
Vasanthakumar Thiagarajan4adfcde2010-04-15 17:39:33 -0400276 ds = (u8 *) dd->dd_desc;
Joe Perchesd2182b62011-12-15 14:55:53 -0800277 ath_dbg(common, CONFIG, "%s DMA map: %p (%u) -> %llx (%u)\n",
Joe Perches226afe62010-12-02 19:12:37 -0800278 name, ds, (u32) dd->dd_desc_len,
279 ito64(dd->dd_desc_paddr), /*XXX*/(u32) dd->dd_desc_len);
Sujith55624202010-01-08 10:36:02 +0530280
281 /* allocate buffers */
Felix Fietkau1a04d592013-10-11 23:30:52 +0200282 if (is_tx) {
283 struct ath_buf *bf;
Sujith55624202010-01-08 10:36:02 +0530284
Felix Fietkau1a04d592013-10-11 23:30:52 +0200285 bsize = sizeof(struct ath_buf) * nbuf;
286 bf = devm_kzalloc(sc->dev, bsize, GFP_KERNEL);
287 if (!bf)
288 return -ENOMEM;
Sujith55624202010-01-08 10:36:02 +0530289
Felix Fietkau1a04d592013-10-11 23:30:52 +0200290 for (i = 0; i < nbuf; i++, bf++, ds += (desc_len * ndesc)) {
291 bf->bf_desc = ds;
292 bf->bf_daddr = DS2PHYS(dd, ds);
Sujith55624202010-01-08 10:36:02 +0530293
Felix Fietkau1a04d592013-10-11 23:30:52 +0200294 if (!(sc->sc_ah->caps.hw_caps &
295 ATH9K_HW_CAP_4KB_SPLITTRANS)) {
296 /*
297 * Skip descriptor addresses which can cause 4KB
298 * boundary crossing (addr + length) with a 32 dword
299 * descriptor fetch.
300 */
301 while (ATH_DESC_4KB_BOUND_CHECK(bf->bf_daddr)) {
302 BUG_ON((caddr_t) bf->bf_desc >=
303 ((caddr_t) dd->dd_desc +
304 dd->dd_desc_len));
305
306 ds += (desc_len * ndesc);
307 bf->bf_desc = ds;
308 bf->bf_daddr = DS2PHYS(dd, ds);
309 }
Sujith55624202010-01-08 10:36:02 +0530310 }
Felix Fietkau1a04d592013-10-11 23:30:52 +0200311 list_add_tail(&bf->list, head);
Sujith55624202010-01-08 10:36:02 +0530312 }
Felix Fietkau1a04d592013-10-11 23:30:52 +0200313 } else {
314 struct ath_rxbuf *bf;
315
316 bsize = sizeof(struct ath_rxbuf) * nbuf;
317 bf = devm_kzalloc(sc->dev, bsize, GFP_KERNEL);
318 if (!bf)
319 return -ENOMEM;
320
321 for (i = 0; i < nbuf; i++, bf++, ds += (desc_len * ndesc)) {
322 bf->bf_desc = ds;
323 bf->bf_daddr = DS2PHYS(dd, ds);
324
325 if (!(sc->sc_ah->caps.hw_caps &
326 ATH9K_HW_CAP_4KB_SPLITTRANS)) {
327 /*
328 * Skip descriptor addresses which can cause 4KB
329 * boundary crossing (addr + length) with a 32 dword
330 * descriptor fetch.
331 */
332 while (ATH_DESC_4KB_BOUND_CHECK(bf->bf_daddr)) {
333 BUG_ON((caddr_t) bf->bf_desc >=
334 ((caddr_t) dd->dd_desc +
335 dd->dd_desc_len));
336
337 ds += (desc_len * ndesc);
338 bf->bf_desc = ds;
339 bf->bf_daddr = DS2PHYS(dd, ds);
340 }
341 }
342 list_add_tail(&bf->list, head);
343 }
Sujith55624202010-01-08 10:36:02 +0530344 }
345 return 0;
Sujith55624202010-01-08 10:36:02 +0530346}
347
Sujith285f2dd2010-01-08 10:36:07 +0530348static int ath9k_init_queues(struct ath_softc *sc)
349{
Sujith285f2dd2010-01-08 10:36:07 +0530350 int i = 0;
Sujith55624202010-01-08 10:36:02 +0530351
Sujith285f2dd2010-01-08 10:36:07 +0530352 sc->beacon.beaconq = ath9k_hw_beaconq_setup(sc->sc_ah);
Sujith285f2dd2010-01-08 10:36:07 +0530353 sc->beacon.cabq = ath_txq_setup(sc, ATH9K_TX_QUEUE_CAB, 0);
Sujith285f2dd2010-01-08 10:36:07 +0530354 ath_cabq_update(sc);
355
Felix Fietkauf2c7a792013-06-07 18:12:00 +0200356 sc->tx.uapsdq = ath_txq_setup(sc, ATH9K_TX_QUEUE_UAPSD, 0);
357
Sujith Manoharanbea843c2012-11-21 18:13:10 +0530358 for (i = 0; i < IEEE80211_NUM_ACS; i++) {
Felix Fietkau066dae92010-11-07 14:59:39 +0100359 sc->tx.txq_map[i] = ath_txq_setup(sc, ATH9K_TX_QUEUE_DATA, i);
Ben Greear60f2d1d2011-01-09 23:11:52 -0800360 sc->tx.txq_map[i]->mac80211_qnum = i;
Felix Fietkau7702e782012-07-15 19:53:35 +0200361 sc->tx.txq_max_pending[i] = ATH_MAX_QDEPTH;
Ben Greear60f2d1d2011-01-09 23:11:52 -0800362 }
Sujith285f2dd2010-01-08 10:36:07 +0530363 return 0;
Sujith285f2dd2010-01-08 10:36:07 +0530364}
365
Sujith285f2dd2010-01-08 10:36:07 +0530366static void ath9k_init_misc(struct ath_softc *sc)
367{
368 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
369 int i = 0;
Sujith Manoharan3d4e20f2012-03-14 14:40:58 +0530370
Sujith285f2dd2010-01-08 10:36:07 +0530371 setup_timer(&common->ani.timer, ath_ani_calibrate, (unsigned long)sc);
372
Oleksij Rempel32efb0c2014-02-04 10:27:39 +0100373 common->last_rssi = ATH_RSSI_DUMMY_MARKER;
Felix Fietkau364734f2010-09-14 20:22:44 +0200374 memcpy(common->bssidmask, ath_bcast_mac, ETH_ALEN);
Sujith285f2dd2010-01-08 10:36:07 +0530375 sc->beacon.slottime = ATH9K_SLOT_TIME_9;
376
Felix Fietkau7545daf2011-01-24 19:23:16 +0100377 for (i = 0; i < ARRAY_SIZE(sc->beacon.bslot); i++)
Sujith285f2dd2010-01-08 10:36:07 +0530378 sc->beacon.bslot[i] = NULL;
Vasanthakumar Thiagarajan102885a2010-09-02 01:34:43 -0700379
380 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_ANT_DIV_COMB)
381 sc->ant_comb.count = ATH_ANT_DIV_COMB_INIT_COUNT;
Simon Wunderlich04ccd4a2013-01-23 17:38:04 +0100382
Oleksij Rempeldd7657b2014-11-06 08:53:22 +0100383 sc->spec_priv.ah = sc->sc_ah;
Oleksij Rempel21af25d2014-11-06 08:53:20 +0100384 sc->spec_priv.spec_config.enabled = 0;
385 sc->spec_priv.spec_config.short_repeat = true;
386 sc->spec_priv.spec_config.count = 8;
387 sc->spec_priv.spec_config.endless = false;
388 sc->spec_priv.spec_config.period = 0xFF;
389 sc->spec_priv.spec_config.fft_period = 0xF;
Sujith285f2dd2010-01-08 10:36:07 +0530390}
391
Sujith Manoharan0f978bf2013-12-06 16:28:45 +0530392static void ath9k_init_pcoem_platform(struct ath_softc *sc)
Sujith Manoharan9b60b642013-06-13 22:51:26 +0530393{
394 struct ath_hw *ah = sc->sc_ah;
Sujith Manoharan3f2da952013-08-04 14:21:56 +0530395 struct ath9k_hw_capabilities *pCap = &ah->caps;
Sujith Manoharan9b60b642013-06-13 22:51:26 +0530396 struct ath_common *common = ath9k_hw_common(ah);
397
Felix Fietkau935477e2014-10-25 17:19:26 +0200398 if (!IS_ENABLED(CONFIG_ATH9K_PCOEM))
399 return;
400
Sujith Manoharan9b60b642013-06-13 22:51:26 +0530401 if (common->bus_ops->ath_bus_type != ATH_PCI)
402 return;
403
Sujith Manoharane861ef52013-06-18 10:13:43 +0530404 if (sc->driver_data & (ATH9K_PCI_CUS198 |
405 ATH9K_PCI_CUS230)) {
Sujith Manoharan9b60b642013-06-13 22:51:26 +0530406 ah->config.xlna_gpio = 9;
407 ah->config.xatten_margin_cfg = true;
Sujith Manoharane083a422013-08-19 11:04:01 +0530408 ah->config.alt_mingainidx = true;
Sujith Manoharan31fd2162013-08-04 14:22:01 +0530409 ah->config.ant_ctrl_comm2g_switch_enable = 0x000BBB88;
Sujith Manoharan3afa6b42013-08-04 14:21:54 +0530410 sc->ant_comb.low_rssi_thresh = 20;
411 sc->ant_comb.fast_div_bias = 3;
Sujith Manoharan9b60b642013-06-13 22:51:26 +0530412
Sujith Manoharane861ef52013-06-18 10:13:43 +0530413 ath_info(common, "Set parameters for %s\n",
414 (sc->driver_data & ATH9K_PCI_CUS198) ?
415 "CUS198" : "CUS230");
Sujith Manoharan3f2da952013-08-04 14:21:56 +0530416 }
417
418 if (sc->driver_data & ATH9K_PCI_CUS217)
Sujith Manoharan12eea642013-06-18 15:42:36 +0530419 ath_info(common, "CUS217 card detected\n");
Sujith Manoharan3f2da952013-08-04 14:21:56 +0530420
Sujith Manoharan10631332013-09-02 13:59:05 +0530421 if (sc->driver_data & ATH9K_PCI_CUS252)
422 ath_info(common, "CUS252 card detected\n");
423
Sujith Manoharan3fcdd0a2013-09-02 13:59:06 +0530424 if (sc->driver_data & ATH9K_PCI_AR9565_1ANT)
425 ath_info(common, "WB335 1-ANT card detected\n");
426
427 if (sc->driver_data & ATH9K_PCI_AR9565_2ANT)
428 ath_info(common, "WB335 2-ANT card detected\n");
429
Sujith Manoharan4dd35642013-10-23 14:26:04 +0530430 if (sc->driver_data & ATH9K_PCI_KILLER)
431 ath_info(common, "Killer Wireless card detected\n");
432
Sujith Manoharan3fcdd0a2013-09-02 13:59:06 +0530433 /*
434 * Some WB335 cards do not support antenna diversity. Since
435 * we use a hardcoded value for AR9565 instead of using the
436 * EEPROM/OTP data, remove the combining feature from
437 * the HW capabilities bitmap.
438 */
439 if (sc->driver_data & (ATH9K_PCI_AR9565_1ANT | ATH9K_PCI_AR9565_2ANT)) {
440 if (!(sc->driver_data & ATH9K_PCI_BT_ANT_DIV))
441 pCap->hw_caps &= ~ATH9K_HW_CAP_ANT_DIV_COMB;
442 }
443
Sujith Manoharan3f2da952013-08-04 14:21:56 +0530444 if (sc->driver_data & ATH9K_PCI_BT_ANT_DIV) {
445 pCap->hw_caps |= ATH9K_HW_CAP_BT_ANT_DIV;
446 ath_info(common, "Set BT/WLAN RX diversity capability\n");
Sujith Manoharan9b60b642013-06-13 22:51:26 +0530447 }
Sujith Manoharand1ae25a2013-08-25 16:30:40 +0530448
449 if (sc->driver_data & ATH9K_PCI_D3_L1_WAR) {
450 ah->config.pcie_waen = 0x0040473b;
451 ath_info(common, "Enable WAR for ASPM D3/L1\n");
452 }
Sujith Manoharan2d22c7d2013-11-08 11:45:25 +0530453
Sujith Manoharanafa7e6d2015-03-09 14:20:07 +0530454 /*
455 * The default value of pll_pwrsave is 1.
456 * For certain AR9485 cards, it is set to 0.
Sujith Manoharan656cd752015-03-09 14:20:08 +0530457 * For AR9462, AR9565 it's set to 7.
Sujith Manoharanafa7e6d2015-03-09 14:20:07 +0530458 */
459 ah->config.pll_pwrsave = 1;
460
Sujith Manoharan2d22c7d2013-11-08 11:45:25 +0530461 if (sc->driver_data & ATH9K_PCI_NO_PLL_PWRSAVE) {
Sujith Manoharanafa7e6d2015-03-09 14:20:07 +0530462 ah->config.pll_pwrsave = 0;
Sujith Manoharan2d22c7d2013-11-08 11:45:25 +0530463 ath_info(common, "Disable PLL PowerSave\n");
464 }
Sujith Manoharanaeeb2062014-11-16 06:11:02 +0530465
466 if (sc->driver_data & ATH9K_PCI_LED_ACT_HI)
467 ah->config.led_active_high = true;
Sujith Manoharan9b60b642013-06-13 22:51:26 +0530468}
469
Gabor Juhosab5c4f72012-12-10 15:30:28 +0100470static void ath9k_eeprom_request_cb(const struct firmware *eeprom_blob,
471 void *ctx)
472{
473 struct ath9k_eeprom_ctx *ec = ctx;
474
475 if (eeprom_blob)
476 ec->ah->eeprom_blob = eeprom_blob;
477
478 complete(&ec->complete);
479}
480
481static int ath9k_eeprom_request(struct ath_softc *sc, const char *name)
482{
483 struct ath9k_eeprom_ctx ec;
Colin Ian King47f58b12016-04-10 12:25:31 +0100484 struct ath_hw *ah = sc->sc_ah;
Gabor Juhosab5c4f72012-12-10 15:30:28 +0100485 int err;
486
487 /* try to load the EEPROM content asynchronously */
488 init_completion(&ec.complete);
489 ec.ah = sc->sc_ah;
490
491 err = request_firmware_nowait(THIS_MODULE, 1, name, sc->dev, GFP_KERNEL,
492 &ec, ath9k_eeprom_request_cb);
493 if (err < 0) {
494 ath_err(ath9k_hw_common(ah),
495 "EEPROM request failed\n");
496 return err;
497 }
498
499 wait_for_completion(&ec.complete);
500
501 if (!ah->eeprom_blob) {
502 ath_err(ath9k_hw_common(ah),
503 "Unable to load EEPROM file %s\n", name);
504 return -EINVAL;
505 }
506
507 return 0;
508}
509
510static void ath9k_eeprom_release(struct ath_softc *sc)
511{
512 release_firmware(sc->sc_ah->eeprom_blob);
513}
514
Sujith Manoharan0f978bf2013-12-06 16:28:45 +0530515static int ath9k_init_soc_platform(struct ath_softc *sc)
516{
517 struct ath9k_platform_data *pdata = sc->dev->platform_data;
518 struct ath_hw *ah = sc->sc_ah;
519 int ret = 0;
520
521 if (!pdata)
522 return 0;
523
524 if (pdata->eeprom_name) {
525 ret = ath9k_eeprom_request(sc, pdata->eeprom_name);
526 if (ret)
527 return ret;
528 }
529
Martin Blumenstingl3467f0d2016-06-23 16:57:09 +0200530 if (pdata->led_active_high)
531 ah->config.led_active_high = true;
532
Sujith Manoharan0f978bf2013-12-06 16:28:45 +0530533 if (pdata->tx_gain_buffalo)
534 ah->config.tx_gain_buffalo = true;
535
536 return ret;
537}
538
Pavel Roskineb93e892011-07-23 03:55:39 -0400539static int ath9k_init_softc(u16 devid, struct ath_softc *sc,
Sujith285f2dd2010-01-08 10:36:07 +0530540 const struct ath_bus_ops *bus_ops)
541{
Felix Fietkau6fb1b1e2011-03-19 13:55:39 +0100542 struct ath9k_platform_data *pdata = sc->dev->platform_data;
Sujith285f2dd2010-01-08 10:36:07 +0530543 struct ath_hw *ah = NULL;
Sujith Manoharan3f2da952013-08-04 14:21:56 +0530544 struct ath9k_hw_capabilities *pCap;
Sujith285f2dd2010-01-08 10:36:07 +0530545 struct ath_common *common;
546 int ret = 0, i;
547 int csz = 0;
548
Felix Fietkaub81950b12012-12-12 13:14:22 +0100549 ah = devm_kzalloc(sc->dev, sizeof(struct ath_hw), GFP_KERNEL);
Sujith285f2dd2010-01-08 10:36:07 +0530550 if (!ah)
551 return -ENOMEM;
552
Felix Fietkauc1b976d2012-12-12 13:14:23 +0100553 ah->dev = sc->dev;
Ben Greear233536e2011-01-09 23:11:44 -0800554 ah->hw = sc->hw;
Sujith285f2dd2010-01-08 10:36:07 +0530555 ah->hw_version.devid = devid;
Felix Fietkauf9f84e92011-03-23 20:57:24 +0100556 ah->reg_ops.read = ath9k_ioread32;
Oleksij Rempeld55ce0a2015-03-22 19:29:50 +0100557 ah->reg_ops.multi_read = ath9k_multi_ioread32;
Felix Fietkauf9f84e92011-03-23 20:57:24 +0100558 ah->reg_ops.write = ath9k_iowrite32;
Felix Fietkau845e03c2011-03-23 20:57:25 +0100559 ah->reg_ops.rmw = ath9k_reg_rmw;
Sujith Manoharan3f2da952013-08-04 14:21:56 +0530560 pCap = &ah->caps;
Sujith285f2dd2010-01-08 10:36:07 +0530561
Janusz Dziedzic95a59922013-10-14 11:06:03 +0200562 common = ath9k_hw_common(ah);
Felix Fietkau56bdbe02014-11-30 21:58:30 +0100563
564 /* Will be cleared in ath9k_start() */
565 set_bit(ATH_OP_INVALID, &common->op_flags);
566
567 sc->sc_ah = ah;
Janusz Dziedzic95a59922013-10-14 11:06:03 +0200568 sc->dfs_detector = dfs_pattern_detector_init(common, NL80211_DFS_UNSET);
Luis R. Rodriguez89f927a2013-10-14 17:42:11 -0700569 sc->tx99_power = MAX_RATE_POWER + 1;
Felix Fietkau10e23182013-11-11 22:23:35 +0100570 init_waitqueue_head(&sc->tx_wait);
Rajkumar Manoharanca900ac2014-06-11 16:18:02 +0530571 sc->cur_chan = &sc->chanctx[0];
Sujith Manoharan499afac2014-08-22 20:39:31 +0530572 if (!ath9k_is_chanctx_enabled())
Rajkumar Manoharan3ad9c382014-06-11 16:18:15 +0530573 sc->cur_chan->hw_queue_base = 0;
Zefir Kurtisi8e92d3f2012-04-03 17:15:50 +0200574
Helmut Schaa552a5152014-05-07 09:28:31 +0200575 if (!pdata || pdata->use_eeprom) {
Felix Fietkaua05b5d452010-11-17 04:25:33 +0100576 ah->ah_flags |= AH_USE_EEPROM;
Felix Fietkau6de66dd2011-03-19 13:55:40 +0100577 sc->sc_ah->led_pin = -1;
578 } else {
579 sc->sc_ah->gpio_mask = pdata->gpio_mask;
580 sc->sc_ah->gpio_val = pdata->gpio_val;
581 sc->sc_ah->led_pin = pdata->led_pin;
Vasanthakumar Thiagarajanf2f5f2a2011-04-19 19:29:01 +0530582 ah->is_clk_25mhz = pdata->is_clk_25mhz;
Gabor Juhos37625612011-06-21 11:23:23 +0200583 ah->get_mac_revision = pdata->get_mac_revision;
Gabor Juhos7d95847c2011-06-21 11:23:51 +0200584 ah->external_reset = pdata->external_reset;
Felix Fietkau34689682014-10-25 17:19:34 +0200585 ah->disable_2ghz = pdata->disable_2ghz;
586 ah->disable_5ghz = pdata->disable_5ghz;
Felix Fietkaua59dadb2014-10-25 17:19:33 +0200587 if (!pdata->endian_check)
588 ah->ah_flags |= AH_NO_EEP_SWAP;
Felix Fietkau6de66dd2011-03-19 13:55:40 +0100589 }
Felix Fietkaua05b5d452010-11-17 04:25:33 +0100590
Felix Fietkauf9f84e92011-03-23 20:57:24 +0100591 common->ops = &ah->reg_ops;
Sujith285f2dd2010-01-08 10:36:07 +0530592 common->bus_ops = bus_ops;
Oleksij Rempel99d22172014-11-06 08:53:25 +0100593 common->ps_ops = &ath9k_ps_ops;
Sujith285f2dd2010-01-08 10:36:07 +0530594 common->ah = ah;
595 common->hw = sc->hw;
596 common->priv = sc;
597 common->debug_mask = ath9k_debug;
Vasanthakumar Thiagarajan8f5dcb12010-11-26 06:10:06 -0800598 common->btcoex_enabled = ath9k_btcoex_enable == 1;
Mohammed Shafi Shajakhan05c0be22011-05-26 10:56:15 +0530599 common->disable_ani = false;
Sujith Manoharane09f2dc2012-09-16 08:06:56 +0530600
601 /*
Sujith Manoharan9b60b642013-06-13 22:51:26 +0530602 * Platform quirks.
603 */
Sujith Manoharan0f978bf2013-12-06 16:28:45 +0530604 ath9k_init_pcoem_platform(sc);
605
606 ret = ath9k_init_soc_platform(sc);
607 if (ret)
608 return ret;
Sujith Manoharan9b60b642013-06-13 22:51:26 +0530609
Vittorio Gambaletta (VittGam)cd840422016-04-11 04:48:54 +0200610 if (ath9k_led_active_high != -1)
611 ah->config.led_active_high = ath9k_led_active_high == 1;
612
Sujith Manoharan9b60b642013-06-13 22:51:26 +0530613 /*
Sujith Manoharan3f2da952013-08-04 14:21:56 +0530614 * Enable WLAN/BT RX Antenna diversity only when:
615 *
Sujith Manoharan7d845872013-08-07 12:29:27 +0530616 * - BTCOEX is disabled.
Sujith Manoharan3f2da952013-08-04 14:21:56 +0530617 * - the user manually requests the feature.
618 * - the HW cap is set using the platform data.
Sujith Manoharane09f2dc2012-09-16 08:06:56 +0530619 */
Sujith Manoharan7d845872013-08-07 12:29:27 +0530620 if (!common->btcoex_enabled && ath9k_bt_ant_diversity &&
Sujith Manoharan3f2da952013-08-04 14:21:56 +0530621 (pCap->hw_caps & ATH9K_HW_CAP_BT_ANT_DIV))
Sujith Manoharan63081302013-08-04 14:21:55 +0530622 common->bt_ant_diversity = 1;
Sujith Manoharane09f2dc2012-09-16 08:06:56 +0530623
Ben Greear20b257442010-10-15 15:04:09 -0700624 spin_lock_init(&common->cc_lock);
Sujith285f2dd2010-01-08 10:36:07 +0530625 spin_lock_init(&sc->sc_serial_rw);
626 spin_lock_init(&sc->sc_pm_lock);
Felix Fietkaubff11762014-06-11 16:17:52 +0530627 spin_lock_init(&sc->chan_lock);
Sujith285f2dd2010-01-08 10:36:07 +0530628 mutex_init(&sc->mutex);
629 tasklet_init(&sc->intr_tq, ath9k_tasklet, (unsigned long)sc);
Sujith Manoharanfb6e2522012-07-17 17:16:22 +0530630 tasklet_init(&sc->bcon_tasklet, ath9k_beacon_tasklet,
Sujith285f2dd2010-01-08 10:36:07 +0530631 (unsigned long)sc);
632
Felix Fietkaubf3dac52013-11-11 22:23:33 +0100633 setup_timer(&sc->sleep_timer, ath_ps_full_sleep, (unsigned long)sc);
Sujith Manoharanaaa1ec42012-06-04 16:27:08 +0530634 INIT_WORK(&sc->hw_reset_work, ath_reset_work);
Sujith Manoharanaaa1ec42012-06-04 16:27:08 +0530635 INIT_WORK(&sc->paprd_work, ath_paprd_calibrate);
636 INIT_DELAYED_WORK(&sc->hw_pll_work, ath_hw_pll_work);
Sujith Manoharan705d0bf2014-08-23 13:29:06 +0530637
638 ath9k_init_channel_context(sc);
Sujith Manoharanaaa1ec42012-06-04 16:27:08 +0530639
Sujith285f2dd2010-01-08 10:36:07 +0530640 /*
641 * Cache line size is used to size and align various
642 * structures used to communicate with the hardware.
643 */
644 ath_read_cachesize(common, &csz);
645 common->cachelsz = csz << 2; /* convert to bytes */
646
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400647 /* Initializes the hardware for all supported chipsets */
Sujith285f2dd2010-01-08 10:36:07 +0530648 ret = ath9k_hw_init(ah);
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400649 if (ret)
Sujith285f2dd2010-01-08 10:36:07 +0530650 goto err_hw;
Sujith285f2dd2010-01-08 10:36:07 +0530651
Felix Fietkau6fb1b1e2011-03-19 13:55:39 +0100652 if (pdata && pdata->macaddr)
653 memcpy(common->macaddr, pdata->macaddr, ETH_ALEN);
654
Sujith285f2dd2010-01-08 10:36:07 +0530655 ret = ath9k_init_queues(sc);
656 if (ret)
657 goto err_queues;
658
659 ret = ath9k_init_btcoex(sc);
660 if (ret)
661 goto err_btcoex;
662
Oleksij Rempel13f71052014-02-25 14:48:50 +0100663 ret = ath9k_cmn_init_channels_rates(common);
Felix Fietkauf209f522010-10-01 01:06:53 +0200664 if (ret)
665 goto err_btcoex;
666
Sujith Manoharanc7dd40c2014-08-22 20:39:30 +0530667 ret = ath9k_init_p2p(sc);
668 if (ret)
Sujith Manoharan4f681692014-08-22 20:39:25 +0530669 goto err_btcoex;
Felix Fietkaud463af42014-04-06 00:37:03 +0200670
Rajkumar Manoharanf82b4bd2011-08-13 10:28:15 +0530671 ath9k_cmn_init_crypto(sc->sc_ah);
Sujith285f2dd2010-01-08 10:36:07 +0530672 ath9k_init_misc(sc);
Felix Fietkaufbbcd142014-06-11 16:17:49 +0530673 ath_chanctx_init(sc);
Sujith Manoharane90e3022014-08-23 13:29:20 +0530674 ath9k_offchannel_init(sc);
Sujith285f2dd2010-01-08 10:36:07 +0530675
Sujith Manoharand09f5f42012-06-04 16:27:14 +0530676 if (common->bus_ops->aspm_init)
677 common->bus_ops->aspm_init(common);
678
Sujith55624202010-01-08 10:36:02 +0530679 return 0;
Sujith285f2dd2010-01-08 10:36:07 +0530680
681err_btcoex:
Sujith55624202010-01-08 10:36:02 +0530682 for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++)
683 if (ATH_TXQ_SETUP(sc, i))
684 ath_tx_cleanupq(sc, &sc->tx.txq[i]);
Sujith285f2dd2010-01-08 10:36:07 +0530685err_queues:
Sujith285f2dd2010-01-08 10:36:07 +0530686 ath9k_hw_deinit(ah);
687err_hw:
Gabor Juhosab5c4f72012-12-10 15:30:28 +0100688 ath9k_eeprom_release(sc);
Luis R. Rodriguez89f927a2013-10-14 17:42:11 -0700689 dev_kfree_skb_any(sc->tx99_skb);
Sujith285f2dd2010-01-08 10:36:07 +0530690 return ret;
Sujith55624202010-01-08 10:36:02 +0530691}
692
Felix Fietkaubabcbc22010-10-20 02:09:46 +0200693static void ath9k_init_band_txpower(struct ath_softc *sc, int band)
694{
695 struct ieee80211_supported_band *sband;
696 struct ieee80211_channel *chan;
697 struct ath_hw *ah = sc->sc_ah;
Oleksij Rempel13f71052014-02-25 14:48:50 +0100698 struct ath_common *common = ath9k_hw_common(ah);
Simon Wunderlich06718942013-08-16 10:46:04 +0200699 struct cfg80211_chan_def chandef;
Felix Fietkaubabcbc22010-10-20 02:09:46 +0200700 int i;
701
Oleksij Rempel13f71052014-02-25 14:48:50 +0100702 sband = &common->sbands[band];
Felix Fietkaubabcbc22010-10-20 02:09:46 +0200703 for (i = 0; i < sband->n_channels; i++) {
704 chan = &sband->channels[i];
705 ah->curchan = &ah->channels[chan->hw_value];
Simon Wunderlich06718942013-08-16 10:46:04 +0200706 cfg80211_chandef_create(&chandef, chan, NL80211_CHAN_HT20);
Felix Fietkau2297f1c2013-10-11 23:30:57 +0200707 ath9k_cmn_get_channel(sc->hw, ah, &chandef);
Felix Fietkaubabcbc22010-10-20 02:09:46 +0200708 ath9k_hw_set_txpowerlimit(ah, MAX_RATE_POWER, true);
Felix Fietkaubabcbc22010-10-20 02:09:46 +0200709 }
710}
711
712static void ath9k_init_txpower_limits(struct ath_softc *sc)
713{
714 struct ath_hw *ah = sc->sc_ah;
715 struct ath9k_channel *curchan = ah->curchan;
716
717 if (ah->caps.hw_caps & ATH9K_HW_CAP_2GHZ)
Johannes Berg57fbcce2016-04-12 15:56:15 +0200718 ath9k_init_band_txpower(sc, NL80211_BAND_2GHZ);
Felix Fietkaubabcbc22010-10-20 02:09:46 +0200719 if (ah->caps.hw_caps & ATH9K_HW_CAP_5GHZ)
Johannes Berg57fbcce2016-04-12 15:56:15 +0200720 ath9k_init_band_txpower(sc, NL80211_BAND_5GHZ);
Felix Fietkaubabcbc22010-10-20 02:09:46 +0200721
722 ah->curchan = curchan;
723}
724
Felix Fietkau20c8e8d2012-04-17 02:40:07 +0200725static const struct ieee80211_iface_limit if_limits[] = {
Rajkumar Manoharan71a5f882014-05-29 15:11:09 +0530726 { .max = 2048, .types = BIT(NL80211_IFTYPE_STATION) },
Felix Fietkau20c8e8d2012-04-17 02:40:07 +0200727 { .max = 8, .types =
728#ifdef CONFIG_MAC80211_MESH
729 BIT(NL80211_IFTYPE_MESH_POINT) |
730#endif
Felix Fietkau95ae4812014-04-06 00:37:02 +0200731 BIT(NL80211_IFTYPE_AP) },
732 { .max = 1, .types = BIT(NL80211_IFTYPE_P2P_CLIENT) |
Felix Fietkau20c8e8d2012-04-17 02:40:07 +0200733 BIT(NL80211_IFTYPE_P2P_GO) },
734};
735
Rajkumar Manoharan71a5f882014-05-29 15:11:09 +0530736static const struct ieee80211_iface_limit wds_limits[] = {
737 { .max = 2048, .types = BIT(NL80211_IFTYPE_WDS) },
738};
739
Sujith Manoharan499afac2014-08-22 20:39:31 +0530740#ifdef CONFIG_ATH9K_CHANNEL_CONTEXT
741
Rajkumar Manoharana4068322014-06-11 16:18:16 +0530742static const struct ieee80211_iface_limit if_limits_multi[] = {
Sujith Manoharan86162d42014-08-24 21:16:12 +0530743 { .max = 2, .types = BIT(NL80211_IFTYPE_STATION) |
744 BIT(NL80211_IFTYPE_AP) |
745 BIT(NL80211_IFTYPE_P2P_CLIENT) |
Rajkumar Manoharana4068322014-06-11 16:18:16 +0530746 BIT(NL80211_IFTYPE_P2P_GO) },
Sujith Manoharan86162d42014-08-24 21:16:12 +0530747 { .max = 1, .types = BIT(NL80211_IFTYPE_ADHOC) },
Janusz.Dziedzic@tieto.comeb61f9f2015-07-21 11:11:40 +0200748 { .max = 1, .types = BIT(NL80211_IFTYPE_P2P_DEVICE) },
Rajkumar Manoharana4068322014-06-11 16:18:16 +0530749};
750
Rajkumar Manoharana4068322014-06-11 16:18:16 +0530751static const struct ieee80211_iface_combination if_comb_multi[] = {
752 {
753 .limits = if_limits_multi,
754 .n_limits = ARRAY_SIZE(if_limits_multi),
Janusz.Dziedzic@tieto.comeb61f9f2015-07-21 11:11:40 +0200755 .max_interfaces = 3,
Rajkumar Manoharana4068322014-06-11 16:18:16 +0530756 .num_different_channels = 2,
757 .beacon_int_infra_match = true,
758 },
759};
760
Sujith Manoharan499afac2014-08-22 20:39:31 +0530761#endif /* CONFIG_ATH9K_CHANNEL_CONTEXT */
762
Zefir Kurtisie9cdedf2013-04-03 18:31:29 +0200763static const struct ieee80211_iface_combination if_comb[] = {
764 {
765 .limits = if_limits,
766 .n_limits = ARRAY_SIZE(if_limits),
767 .max_interfaces = 2048,
768 .num_different_channels = 1,
769 .beacon_int_infra_match = true,
Felix Fietkau12865582016-01-22 01:56:30 +0100770#ifdef CONFIG_ATH9K_DFS_CERTIFIED
771 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
772 BIT(NL80211_CHAN_WIDTH_20) |
773 BIT(NL80211_CHAN_WIDTH_40),
774#endif
Zefir Kurtisie9cdedf2013-04-03 18:31:29 +0200775 },
Rajkumar Manoharan71a5f882014-05-29 15:11:09 +0530776 {
777 .limits = wds_limits,
778 .n_limits = ARRAY_SIZE(wds_limits),
779 .max_interfaces = 2048,
780 .num_different_channels = 1,
781 .beacon_int_infra_match = true,
782 },
Felix Fietkau20c8e8d2012-04-17 02:40:07 +0200783};
Felix Fietkau43c35282011-09-03 01:40:27 +0200784
Sujith Manoharan868caae2014-10-21 19:23:02 +0530785#ifdef CONFIG_ATH9K_CHANNEL_CONTEXT
786static void ath9k_set_mcc_capab(struct ath_softc *sc, struct ieee80211_hw *hw)
787{
788 struct ath_hw *ah = sc->sc_ah;
789 struct ath_common *common = ath9k_hw_common(ah);
790
791 if (!ath9k_is_chanctx_enabled())
792 return;
793
Johannes Berg30686bf2015-06-02 21:39:54 +0200794 ieee80211_hw_set(hw, QUEUE_CONTROL);
Sujith Manoharan868caae2014-10-21 19:23:02 +0530795 hw->queues = ATH9K_NUM_TX_QUEUES;
796 hw->offchannel_tx_hw_queue = hw->queues - 1;
797 hw->wiphy->interface_modes &= ~ BIT(NL80211_IFTYPE_WDS);
798 hw->wiphy->iface_combinations = if_comb_multi;
799 hw->wiphy->n_iface_combinations = ARRAY_SIZE(if_comb_multi);
800 hw->wiphy->max_scan_ssids = 255;
801 hw->wiphy->max_scan_ie_len = IEEE80211_MAX_DATA_LEN;
802 hw->wiphy->max_remain_on_channel_duration = 10000;
803 hw->chanctx_data_size = sizeof(void *);
804 hw->extra_beacon_tailroom =
805 sizeof(struct ieee80211_p2p_noa_attr) + 9;
806
807 ath_dbg(common, CHAN_CTX, "Use channel contexts\n");
808}
809#endif /* CONFIG_ATH9K_CHANNEL_CONTEXT */
810
Sujith Manoharan7b6ef992013-12-18 09:53:19 +0530811static void ath9k_set_hw_capab(struct ath_softc *sc, struct ieee80211_hw *hw)
Sujith55624202010-01-08 10:36:02 +0530812{
Felix Fietkau43c35282011-09-03 01:40:27 +0200813 struct ath_hw *ah = sc->sc_ah;
814 struct ath_common *common = ath9k_hw_common(ah);
Sujith285f2dd2010-01-08 10:36:07 +0530815
Johannes Berg30686bf2015-06-02 21:39:54 +0200816 ieee80211_hw_set(hw, SUPPORTS_HT_CCK_RATES);
817 ieee80211_hw_set(hw, SUPPORTS_RC_TABLE);
818 ieee80211_hw_set(hw, REPORTS_TX_ACK_STATUS);
819 ieee80211_hw_set(hw, SPECTRUM_MGMT);
820 ieee80211_hw_set(hw, PS_NULLFUNC_STACK);
821 ieee80211_hw_set(hw, SIGNAL_DBM);
822 ieee80211_hw_set(hw, RX_INCLUDES_FCS);
823 ieee80211_hw_set(hw, HOST_BROADCAST_PS_BUFFERING);
Felix Fietkauf419c5f2015-07-22 13:06:12 +0200824 ieee80211_hw_set(hw, SUPPORT_FAST_XMIT);
Pawel Kulakowski50e81e22015-12-18 10:48:57 +0100825 ieee80211_hw_set(hw, SUPPORTS_CLONED_SKBS);
Sujith55624202010-01-08 10:36:02 +0530826
Sujith Manoharan82983832014-02-04 08:37:53 +0530827 if (ath9k_ps_enable)
Johannes Berg30686bf2015-06-02 21:39:54 +0200828 ieee80211_hw_set(hw, SUPPORTS_PS);
Sujith Manoharan82983832014-02-04 08:37:53 +0530829
Oleksij Rempelb0a1ae92013-05-24 20:30:59 +0200830 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_HT) {
Johannes Berg30686bf2015-06-02 21:39:54 +0200831 ieee80211_hw_set(hw, AMPDU_AGGREGATION);
Oleksij Rempelb0a1ae92013-05-24 20:30:59 +0200832
833 if (AR_SREV_9280_20_OR_LATER(ah))
834 hw->radiotap_mcs_details |=
835 IEEE80211_RADIOTAP_MCS_HAVE_STBC;
836 }
Luis R. Rodriguez5ffaf8a2010-02-02 11:58:33 -0500837
John W. Linville3e6109c2011-01-05 09:39:17 -0500838 if (AR_SREV_9160_10_OR_LATER(sc->sc_ah) || ath9k_modparam_nohwcrypt)
Johannes Berg30686bf2015-06-02 21:39:54 +0200839 ieee80211_hw_set(hw, MFP_CAPABLE);
Sujith55624202010-01-08 10:36:02 +0530840
Sujith Manoharanfdcf1bd2014-09-05 08:03:14 +0530841 hw->wiphy->features |= NL80211_FEATURE_ACTIVE_MONITOR |
842 NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE |
843 NL80211_FEATURE_P2P_GO_CTWIN;
Felix Fietkauec26bcc2013-05-28 13:01:54 +0200844
Luis R. Rodriguez89f927a2013-10-14 17:42:11 -0700845 if (!config_enabled(CONFIG_ATH9K_TX99)) {
846 hw->wiphy->interface_modes =
847 BIT(NL80211_IFTYPE_P2P_GO) |
848 BIT(NL80211_IFTYPE_P2P_CLIENT) |
849 BIT(NL80211_IFTYPE_AP) |
Luis R. Rodriguez89f927a2013-10-14 17:42:11 -0700850 BIT(NL80211_IFTYPE_STATION) |
851 BIT(NL80211_IFTYPE_ADHOC) |
Sujith Manoharan499afac2014-08-22 20:39:31 +0530852 BIT(NL80211_IFTYPE_MESH_POINT) |
Jan Kaisrlik862a3362015-09-17 14:03:46 +0200853 BIT(NL80211_IFTYPE_WDS) |
854 BIT(NL80211_IFTYPE_OCB);
Sujith Manoharan499afac2014-08-22 20:39:31 +0530855
Janusz.Dziedzic@tieto.comeb61f9f2015-07-21 11:11:40 +0200856 if (ath9k_is_chanctx_enabled())
857 hw->wiphy->interface_modes |=
858 BIT(NL80211_IFTYPE_P2P_DEVICE);
859
Arnd Bergmann362210e2016-03-14 15:18:37 +0100860 hw->wiphy->iface_combinations = if_comb;
861 hw->wiphy->n_iface_combinations = ARRAY_SIZE(if_comb);
Luis R. Rodriguez89f927a2013-10-14 17:42:11 -0700862 }
Felix Fietkau20c8e8d2012-04-17 02:40:07 +0200863
Sujith Manoharan531671c2013-06-01 07:08:09 +0530864 hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
Sujith55624202010-01-08 10:36:02 +0530865
Jouni Malinencfdc9a82011-03-23 14:52:19 +0200866 hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
Jouni Malinenfd656232011-10-27 17:31:50 +0300867 hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS;
Johannes Berg81ddbb52012-03-26 18:47:18 +0200868 hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
Simon Wunderlich6fac8bb2013-08-14 08:01:34 +0200869 hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_5_10_MHZ;
Simon Wunderlichd074e8d2013-08-14 08:01:38 +0200870 hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
Jouni Malinen7b4f6632014-02-18 20:41:08 +0200871 hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
Jouni Malinencfdc9a82011-03-23 14:52:19 +0200872
Sujith Manoharan868caae2014-10-21 19:23:02 +0530873 hw->queues = 4;
Sujith55624202010-01-08 10:36:02 +0530874 hw->max_rates = 4;
Rajkumar Manoharan5f2f9e42014-06-26 16:54:41 +0530875 hw->max_listen_interval = 10;
Felix Fietkau65896512010-01-24 03:26:11 +0100876 hw->max_rate_tries = 10;
Sujith55624202010-01-08 10:36:02 +0530877 hw->sta_data_size = sizeof(struct ath_node);
878 hw->vif_data_size = sizeof(struct ath_vif);
Felix Fietkau029cd032015-09-24 16:59:46 +0200879 hw->extra_tx_headroom = 4;
Sujith55624202010-01-08 10:36:02 +0530880
Felix Fietkau43c35282011-09-03 01:40:27 +0200881 hw->wiphy->available_antennas_rx = BIT(ah->caps.max_rxchains) - 1;
882 hw->wiphy->available_antennas_tx = BIT(ah->caps.max_txchains) - 1;
883
884 /* single chain devices with rx diversity */
885 if (ah->caps.hw_caps & ATH9K_HW_CAP_ANT_DIV_COMB)
886 hw->wiphy->available_antennas_rx = BIT(0) | BIT(1);
887
888 sc->ant_rx = hw->wiphy->available_antennas_rx;
889 sc->ant_tx = hw->wiphy->available_antennas_tx;
890
Felix Fietkaud4659912010-10-14 16:02:39 +0200891 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_2GHZ)
Johannes Berg57fbcce2016-04-12 15:56:15 +0200892 hw->wiphy->bands[NL80211_BAND_2GHZ] =
893 &common->sbands[NL80211_BAND_2GHZ];
Felix Fietkaud4659912010-10-14 16:02:39 +0200894 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_5GHZ)
Johannes Berg57fbcce2016-04-12 15:56:15 +0200895 hw->wiphy->bands[NL80211_BAND_5GHZ] =
896 &common->sbands[NL80211_BAND_5GHZ];
Sujith285f2dd2010-01-08 10:36:07 +0530897
Sujith Manoharan868caae2014-10-21 19:23:02 +0530898#ifdef CONFIG_ATH9K_CHANNEL_CONTEXT
899 ath9k_set_mcc_capab(sc, hw);
900#endif
Sujith Manoharanbabaa802013-10-28 13:01:28 +0530901 ath9k_init_wow(hw);
Oleksij Rempelb57ba3b2014-02-25 14:48:55 +0100902 ath9k_cmn_reload_chainmask(ah);
Sujith285f2dd2010-01-08 10:36:07 +0530903
904 SET_IEEE80211_PERM_ADDR(hw, common->macaddr);
Sujith55624202010-01-08 10:36:02 +0530905}
906
Pavel Roskineb93e892011-07-23 03:55:39 -0400907int ath9k_init_device(u16 devid, struct ath_softc *sc,
Sujith55624202010-01-08 10:36:02 +0530908 const struct ath_bus_ops *bus_ops)
909{
910 struct ieee80211_hw *hw = sc->hw;
911 struct ath_common *common;
912 struct ath_hw *ah;
Sujith285f2dd2010-01-08 10:36:07 +0530913 int error = 0;
Sujith55624202010-01-08 10:36:02 +0530914 struct ath_regulatory *reg;
915
Sujith285f2dd2010-01-08 10:36:07 +0530916 /* Bring up device */
Pavel Roskineb93e892011-07-23 03:55:39 -0400917 error = ath9k_init_softc(devid, sc, bus_ops);
Felix Fietkaub81950b12012-12-12 13:14:22 +0100918 if (error)
919 return error;
Sujith55624202010-01-08 10:36:02 +0530920
921 ah = sc->sc_ah;
922 common = ath9k_hw_common(ah);
Sujith285f2dd2010-01-08 10:36:07 +0530923 ath9k_set_hw_capab(sc, hw);
Sujith55624202010-01-08 10:36:02 +0530924
Sujith285f2dd2010-01-08 10:36:07 +0530925 /* Initialize regulatory */
Sujith55624202010-01-08 10:36:02 +0530926 error = ath_regd_init(&common->regulatory, sc->hw->wiphy,
927 ath9k_reg_notifier);
928 if (error)
Felix Fietkaub81950b12012-12-12 13:14:22 +0100929 goto deinit;
Sujith55624202010-01-08 10:36:02 +0530930
931 reg = &common->regulatory;
932
Sujith285f2dd2010-01-08 10:36:07 +0530933 /* Setup TX DMA */
Sujith55624202010-01-08 10:36:02 +0530934 error = ath_tx_init(sc, ATH_TXBUF);
935 if (error != 0)
Felix Fietkaub81950b12012-12-12 13:14:22 +0100936 goto deinit;
Sujith55624202010-01-08 10:36:02 +0530937
Sujith285f2dd2010-01-08 10:36:07 +0530938 /* Setup RX DMA */
Sujith55624202010-01-08 10:36:02 +0530939 error = ath_rx_init(sc, ATH_RXBUF);
940 if (error != 0)
Felix Fietkaub81950b12012-12-12 13:14:22 +0100941 goto deinit;
Sujith285f2dd2010-01-08 10:36:07 +0530942
Felix Fietkaubabcbc22010-10-20 02:09:46 +0200943 ath9k_init_txpower_limits(sc);
944
Felix Fietkau0cf55c22011-02-27 22:26:40 +0100945#ifdef CONFIG_MAC80211_LEDS
946 /* must be initialized before ieee80211_register_hw */
947 sc->led_cdev.default_trigger = ieee80211_create_tpt_led_trigger(sc->hw,
948 IEEE80211_TPT_LEDTRIG_FL_RADIO, ath9k_tpt_blink,
949 ARRAY_SIZE(ath9k_tpt_blink));
950#endif
951
Sujith285f2dd2010-01-08 10:36:07 +0530952 /* Register with mac80211 */
953 error = ieee80211_register_hw(hw);
954 if (error)
Felix Fietkaub81950b12012-12-12 13:14:22 +0100955 goto rx_cleanup;
Sujith285f2dd2010-01-08 10:36:07 +0530956
Ben Greeareb272442010-11-29 14:13:22 -0800957 error = ath9k_init_debug(ah);
958 if (error) {
Joe Perches38002762010-12-02 19:12:36 -0800959 ath_err(common, "Unable to create debugfs files\n");
Felix Fietkaub81950b12012-12-12 13:14:22 +0100960 goto unregister;
Ben Greeareb272442010-11-29 14:13:22 -0800961 }
962
Sujith285f2dd2010-01-08 10:36:07 +0530963 /* Handle world regulatory */
964 if (!ath_is_world_regd(reg)) {
965 error = regulatory_hint(hw->wiphy, reg->alpha2);
966 if (error)
Sujith Manoharanaf690092013-05-10 18:41:06 +0530967 goto debug_cleanup;
Sujith285f2dd2010-01-08 10:36:07 +0530968 }
Sujith55624202010-01-08 10:36:02 +0530969
Sujith55624202010-01-08 10:36:02 +0530970 ath_init_leds(sc);
Sujith55624202010-01-08 10:36:02 +0530971 ath_start_rfkill_poll(sc);
972
973 return 0;
974
Sujith Manoharanaf690092013-05-10 18:41:06 +0530975debug_cleanup:
976 ath9k_deinit_debug(sc);
Felix Fietkaub81950b12012-12-12 13:14:22 +0100977unregister:
Sujith285f2dd2010-01-08 10:36:07 +0530978 ieee80211_unregister_hw(hw);
Felix Fietkaub81950b12012-12-12 13:14:22 +0100979rx_cleanup:
Sujith285f2dd2010-01-08 10:36:07 +0530980 ath_rx_cleanup(sc);
Felix Fietkaub81950b12012-12-12 13:14:22 +0100981deinit:
Sujith285f2dd2010-01-08 10:36:07 +0530982 ath9k_deinit_softc(sc);
Sujith55624202010-01-08 10:36:02 +0530983 return error;
984}
985
986/*****************************/
987/* De-Initialization */
988/*****************************/
989
Sujith285f2dd2010-01-08 10:36:07 +0530990static void ath9k_deinit_softc(struct ath_softc *sc)
Sujith55624202010-01-08 10:36:02 +0530991{
Sujith285f2dd2010-01-08 10:36:07 +0530992 int i = 0;
Sujith55624202010-01-08 10:36:02 +0530993
Sujith Manoharanc7dd40c2014-08-22 20:39:30 +0530994 ath9k_deinit_p2p(sc);
Sujith Manoharan59081202012-02-22 12:40:21 +0530995 ath9k_deinit_btcoex(sc);
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +0530996
Sujith285f2dd2010-01-08 10:36:07 +0530997 for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++)
998 if (ATH_TXQ_SETUP(sc, i))
999 ath_tx_cleanupq(sc, &sc->tx.txq[i]);
1000
Felix Fietkaubf3dac52013-11-11 22:23:33 +01001001 del_timer_sync(&sc->sleep_timer);
Sujith285f2dd2010-01-08 10:36:07 +05301002 ath9k_hw_deinit(sc->sc_ah);
Zefir Kurtisi8e92d3f2012-04-03 17:15:50 +02001003 if (sc->dfs_detector != NULL)
1004 sc->dfs_detector->exit(sc->dfs_detector);
Sujith285f2dd2010-01-08 10:36:07 +05301005
Gabor Juhosab5c4f72012-12-10 15:30:28 +01001006 ath9k_eeprom_release(sc);
Sujith55624202010-01-08 10:36:02 +05301007}
1008
Sujith285f2dd2010-01-08 10:36:07 +05301009void ath9k_deinit_device(struct ath_softc *sc)
Sujith55624202010-01-08 10:36:02 +05301010{
1011 struct ieee80211_hw *hw = sc->hw;
Sujith55624202010-01-08 10:36:02 +05301012
1013 ath9k_ps_wakeup(sc);
1014
Sujith55624202010-01-08 10:36:02 +05301015 wiphy_rfkill_stop_polling(sc->hw->wiphy);
Sujith285f2dd2010-01-08 10:36:07 +05301016 ath_deinit_leds(sc);
Sujith55624202010-01-08 10:36:02 +05301017
Rajkumar Manoharanc7c18062011-01-27 18:39:38 +05301018 ath9k_ps_restore(sc);
1019
Sujith Manoharanaf690092013-05-10 18:41:06 +05301020 ath9k_deinit_debug(sc);
Sujith Manoharan661d2582015-01-30 19:05:26 +05301021 ath9k_deinit_wow(hw);
Sujith55624202010-01-08 10:36:02 +05301022 ieee80211_unregister_hw(hw);
1023 ath_rx_cleanup(sc);
Sujith285f2dd2010-01-08 10:36:07 +05301024 ath9k_deinit_softc(sc);
Sujith55624202010-01-08 10:36:02 +05301025}
1026
Sujith55624202010-01-08 10:36:02 +05301027/************************/
1028/* Module Hooks */
1029/************************/
1030
1031static int __init ath9k_init(void)
1032{
1033 int error;
1034
Sujith55624202010-01-08 10:36:02 +05301035 error = ath_pci_init();
1036 if (error < 0) {
Joe Perches516304b2012-03-18 17:30:52 -07001037 pr_err("No PCI devices found, driver not installed\n");
Sujith55624202010-01-08 10:36:02 +05301038 error = -ENODEV;
Sujith Manoharan9e495a22014-02-06 10:22:55 +05301039 goto err_out;
Sujith55624202010-01-08 10:36:02 +05301040 }
1041
1042 error = ath_ahb_init();
1043 if (error < 0) {
1044 error = -ENODEV;
1045 goto err_pci_exit;
1046 }
1047
1048 return 0;
1049
1050 err_pci_exit:
1051 ath_pci_exit();
Sujith55624202010-01-08 10:36:02 +05301052 err_out:
1053 return error;
1054}
1055module_init(ath9k_init);
1056
1057static void __exit ath9k_exit(void)
1058{
Rajkumar Manoharand5847472010-12-20 14:39:51 +05301059 is_ath9k_unloaded = true;
Sujith55624202010-01-08 10:36:02 +05301060 ath_ahb_exit();
1061 ath_pci_exit();
Joe Perches516304b2012-03-18 17:30:52 -07001062 pr_info("%s: Driver unloaded\n", dev_info);
Sujith55624202010-01-08 10:36:02 +05301063}
1064module_exit(ath9k_exit);