blob: 5d532c7b813fd1d356884134db2a4ebb7fb2d7f4 [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
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
Sujith Manoharan499afac2014-08-22 20:39:31 +053064#ifdef CONFIG_ATH9K_CHANNEL_CONTEXT
65
Felix Fietkau78b21942014-06-11 16:17:55 +053066int ath9k_use_chanctx;
Rajkumar Manoharan71a5f882014-05-29 15:11:09 +053067module_param_named(use_chanctx, ath9k_use_chanctx, int, 0444);
68MODULE_PARM_DESC(use_chanctx, "Enable channel context for concurrency");
69
Sujith Manoharan499afac2014-08-22 20:39:31 +053070#endif /* CONFIG_ATH9K_CHANNEL_CONTEXT */
71
Rajkumar Manoharand5847472010-12-20 14:39:51 +053072bool is_ath9k_unloaded;
Sujith55624202010-01-08 10:36:02 +053073
Felix Fietkau0cf55c22011-02-27 22:26:40 +010074#ifdef CONFIG_MAC80211_LEDS
75static const struct ieee80211_tpt_blink ath9k_tpt_blink[] = {
76 { .throughput = 0 * 1024, .blink_time = 334 },
77 { .throughput = 1 * 1024, .blink_time = 260 },
78 { .throughput = 5 * 1024, .blink_time = 220 },
79 { .throughput = 10 * 1024, .blink_time = 190 },
80 { .throughput = 20 * 1024, .blink_time = 170 },
81 { .throughput = 50 * 1024, .blink_time = 150 },
82 { .throughput = 70 * 1024, .blink_time = 130 },
83 { .throughput = 100 * 1024, .blink_time = 110 },
84 { .throughput = 200 * 1024, .blink_time = 80 },
85 { .throughput = 300 * 1024, .blink_time = 50 },
86};
87#endif
88
Sujith285f2dd2010-01-08 10:36:07 +053089static void ath9k_deinit_softc(struct ath_softc *sc);
Sujith55624202010-01-08 10:36:02 +053090
kbuild test robotd81f9a02014-11-12 06:19:48 +080091static void ath9k_op_ps_wakeup(struct ath_common *common)
Oleksij Rempel99d22172014-11-06 08:53:25 +010092{
93 ath9k_ps_wakeup((struct ath_softc *) common->priv);
94}
95
kbuild test robotd81f9a02014-11-12 06:19:48 +080096static void ath9k_op_ps_restore(struct ath_common *common)
Oleksij Rempel99d22172014-11-06 08:53:25 +010097{
98 ath9k_ps_restore((struct ath_softc *) common->priv);
99}
100
kbuild test robotd81f9a02014-11-12 06:19:48 +0800101static struct ath_ps_ops ath9k_ps_ops = {
Oleksij Rempel99d22172014-11-06 08:53:25 +0100102 .wakeup = ath9k_op_ps_wakeup,
103 .restore = ath9k_op_ps_restore,
104};
105
Sujith55624202010-01-08 10:36:02 +0530106/*
107 * Read and write, they both share the same lock. We do this to serialize
108 * reads and writes on Atheros 802.11n PCI devices only. This is required
109 * as the FIFO on these devices can only accept sanely 2 requests.
110 */
111
112static void ath9k_iowrite32(void *hw_priv, u32 val, u32 reg_offset)
113{
114 struct ath_hw *ah = (struct ath_hw *) hw_priv;
115 struct ath_common *common = ath9k_hw_common(ah);
116 struct ath_softc *sc = (struct ath_softc *) common->priv;
117
Felix Fietkauf3eef642012-03-14 16:40:25 +0100118 if (NR_CPUS > 1 && ah->config.serialize_regmode == SER_REG_MODE_ON) {
Sujith55624202010-01-08 10:36:02 +0530119 unsigned long flags;
120 spin_lock_irqsave(&sc->sc_serial_rw, flags);
121 iowrite32(val, sc->mem + reg_offset);
122 spin_unlock_irqrestore(&sc->sc_serial_rw, flags);
123 } else
124 iowrite32(val, sc->mem + reg_offset);
125}
126
127static unsigned int ath9k_ioread32(void *hw_priv, u32 reg_offset)
128{
129 struct ath_hw *ah = (struct ath_hw *) hw_priv;
130 struct ath_common *common = ath9k_hw_common(ah);
131 struct ath_softc *sc = (struct ath_softc *) common->priv;
132 u32 val;
133
Felix Fietkauf3eef642012-03-14 16:40:25 +0100134 if (NR_CPUS > 1 && ah->config.serialize_regmode == SER_REG_MODE_ON) {
Sujith55624202010-01-08 10:36:02 +0530135 unsigned long flags;
136 spin_lock_irqsave(&sc->sc_serial_rw, flags);
137 val = ioread32(sc->mem + reg_offset);
138 spin_unlock_irqrestore(&sc->sc_serial_rw, flags);
139 } else
140 val = ioread32(sc->mem + reg_offset);
141 return val;
142}
143
Oleksij Rempeld55ce0a2015-03-22 19:29:50 +0100144static void ath9k_multi_ioread32(void *hw_priv, u32 *addr,
145 u32 *val, u16 count)
146{
147 int i;
148
149 for (i = 0; i < count; i++)
150 val[i] = ath9k_ioread32(hw_priv, addr[i]);
151}
152
153
Rajkumar Manoharan5479de62011-07-17 11:43:02 +0530154static unsigned int __ath9k_reg_rmw(struct ath_softc *sc, u32 reg_offset,
155 u32 set, u32 clr)
156{
157 u32 val;
158
159 val = ioread32(sc->mem + reg_offset);
160 val &= ~clr;
161 val |= set;
162 iowrite32(val, sc->mem + reg_offset);
163
164 return val;
165}
166
Felix Fietkau845e03c2011-03-23 20:57:25 +0100167static unsigned int ath9k_reg_rmw(void *hw_priv, u32 reg_offset, u32 set, u32 clr)
168{
169 struct ath_hw *ah = (struct ath_hw *) hw_priv;
170 struct ath_common *common = ath9k_hw_common(ah);
171 struct ath_softc *sc = (struct ath_softc *) common->priv;
172 unsigned long uninitialized_var(flags);
173 u32 val;
174
Felix Fietkauf3eef642012-03-14 16:40:25 +0100175 if (NR_CPUS > 1 && ah->config.serialize_regmode == SER_REG_MODE_ON) {
Felix Fietkau845e03c2011-03-23 20:57:25 +0100176 spin_lock_irqsave(&sc->sc_serial_rw, flags);
Rajkumar Manoharan5479de62011-07-17 11:43:02 +0530177 val = __ath9k_reg_rmw(sc, reg_offset, set, clr);
Felix Fietkau845e03c2011-03-23 20:57:25 +0100178 spin_unlock_irqrestore(&sc->sc_serial_rw, flags);
Rajkumar Manoharan5479de62011-07-17 11:43:02 +0530179 } else
180 val = __ath9k_reg_rmw(sc, reg_offset, set, clr);
Felix Fietkau845e03c2011-03-23 20:57:25 +0100181
182 return val;
183}
184
Sujith55624202010-01-08 10:36:02 +0530185/**************************/
186/* Initialization */
187/**************************/
188
Luis R. Rodriguez0c0280b2013-01-11 18:39:36 +0000189static void ath9k_reg_notifier(struct wiphy *wiphy,
190 struct regulatory_request *request)
Sujith55624202010-01-08 10:36:02 +0530191{
192 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
Felix Fietkau9ac586152011-01-24 19:23:18 +0100193 struct ath_softc *sc = hw->priv;
Rajkumar Manoharan687f5452011-12-08 23:59:25 +0530194 struct ath_hw *ah = sc->sc_ah;
195 struct ath_regulatory *reg = ath9k_hw_regulatory(ah);
Sujith55624202010-01-08 10:36:02 +0530196
Luis R. Rodriguez0c0280b2013-01-11 18:39:36 +0000197 ath_reg_notifier_apply(wiphy, request, reg);
Rajkumar Manoharan687f5452011-12-08 23:59:25 +0530198
199 /* Set tx power */
Felix Fietkaud385c5c2014-11-04 16:56:57 +0100200 if (!ah->curchan)
201 return;
202
203 sc->cur_chan->txpower = 2 * ah->curchan->chan->max_power;
204 ath9k_ps_wakeup(sc);
205 ath9k_hw_set_txpowerlimit(ah, sc->cur_chan->txpower, false);
206 ath9k_cmn_update_txpow(ah, sc->cur_chan->cur_txpower,
207 sc->cur_chan->txpower,
208 &sc->cur_chan->cur_txpower);
209 /* synchronize DFS detector if regulatory domain changed */
210 if (sc->dfs_detector != NULL)
211 sc->dfs_detector->set_dfs_domain(sc->dfs_detector,
212 request->dfs_region);
213 ath9k_ps_restore(sc);
Sujith55624202010-01-08 10:36:02 +0530214}
215
216/*
217 * This function will allocate both the DMA descriptor structure, and the
218 * buffers it contains. These are used to contain the descriptors used
219 * by the system.
220*/
221int ath_descdma_setup(struct ath_softc *sc, struct ath_descdma *dd,
222 struct list_head *head, const char *name,
Vasanthakumar Thiagarajan4adfcde2010-04-15 17:39:33 -0400223 int nbuf, int ndesc, bool is_tx)
Sujith55624202010-01-08 10:36:02 +0530224{
Sujith55624202010-01-08 10:36:02 +0530225 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
Vasanthakumar Thiagarajan4adfcde2010-04-15 17:39:33 -0400226 u8 *ds;
Felix Fietkaub81950b12012-12-12 13:14:22 +0100227 int i, bsize, desc_len;
Sujith55624202010-01-08 10:36:02 +0530228
Joe Perchesd2182b62011-12-15 14:55:53 -0800229 ath_dbg(common, CONFIG, "%s DMA: %u buffers %u desc/buf\n",
Joe Perches226afe62010-12-02 19:12:37 -0800230 name, nbuf, ndesc);
Sujith55624202010-01-08 10:36:02 +0530231
232 INIT_LIST_HEAD(head);
Vasanthakumar Thiagarajan4adfcde2010-04-15 17:39:33 -0400233
234 if (is_tx)
235 desc_len = sc->sc_ah->caps.tx_desc_len;
236 else
237 desc_len = sizeof(struct ath_desc);
238
Sujith55624202010-01-08 10:36:02 +0530239 /* ath_desc must be a multiple of DWORDs */
Vasanthakumar Thiagarajan4adfcde2010-04-15 17:39:33 -0400240 if ((desc_len % 4) != 0) {
Joe Perches38002762010-12-02 19:12:36 -0800241 ath_err(common, "ath_desc not DWORD aligned\n");
Vasanthakumar Thiagarajan4adfcde2010-04-15 17:39:33 -0400242 BUG_ON((desc_len % 4) != 0);
Felix Fietkaub81950b12012-12-12 13:14:22 +0100243 return -ENOMEM;
Sujith55624202010-01-08 10:36:02 +0530244 }
245
Vasanthakumar Thiagarajan4adfcde2010-04-15 17:39:33 -0400246 dd->dd_desc_len = desc_len * nbuf * ndesc;
Sujith55624202010-01-08 10:36:02 +0530247
248 /*
249 * Need additional DMA memory because we can't use
250 * descriptors that cross the 4K page boundary. Assume
251 * one skipped descriptor per 4K page.
252 */
253 if (!(sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_4KB_SPLITTRANS)) {
254 u32 ndesc_skipped =
255 ATH_DESC_4KB_BOUND_NUM_SKIPPED(dd->dd_desc_len);
256 u32 dma_len;
257
258 while (ndesc_skipped) {
Vasanthakumar Thiagarajan4adfcde2010-04-15 17:39:33 -0400259 dma_len = ndesc_skipped * desc_len;
Sujith55624202010-01-08 10:36:02 +0530260 dd->dd_desc_len += dma_len;
261
262 ndesc_skipped = ATH_DESC_4KB_BOUND_NUM_SKIPPED(dma_len);
Joe Perchesee289b62010-05-17 22:47:34 -0700263 }
Sujith55624202010-01-08 10:36:02 +0530264 }
265
266 /* allocate descriptors */
Felix Fietkaub81950b12012-12-12 13:14:22 +0100267 dd->dd_desc = dmam_alloc_coherent(sc->dev, dd->dd_desc_len,
268 &dd->dd_desc_paddr, GFP_KERNEL);
269 if (!dd->dd_desc)
270 return -ENOMEM;
271
Vasanthakumar Thiagarajan4adfcde2010-04-15 17:39:33 -0400272 ds = (u8 *) dd->dd_desc;
Joe Perchesd2182b62011-12-15 14:55:53 -0800273 ath_dbg(common, CONFIG, "%s DMA map: %p (%u) -> %llx (%u)\n",
Joe Perches226afe62010-12-02 19:12:37 -0800274 name, ds, (u32) dd->dd_desc_len,
275 ito64(dd->dd_desc_paddr), /*XXX*/(u32) dd->dd_desc_len);
Sujith55624202010-01-08 10:36:02 +0530276
277 /* allocate buffers */
Felix Fietkau1a04d592013-10-11 23:30:52 +0200278 if (is_tx) {
279 struct ath_buf *bf;
Sujith55624202010-01-08 10:36:02 +0530280
Felix Fietkau1a04d592013-10-11 23:30:52 +0200281 bsize = sizeof(struct ath_buf) * nbuf;
282 bf = devm_kzalloc(sc->dev, bsize, GFP_KERNEL);
283 if (!bf)
284 return -ENOMEM;
Sujith55624202010-01-08 10:36:02 +0530285
Felix Fietkau1a04d592013-10-11 23:30:52 +0200286 for (i = 0; i < nbuf; i++, bf++, ds += (desc_len * ndesc)) {
287 bf->bf_desc = ds;
288 bf->bf_daddr = DS2PHYS(dd, ds);
Sujith55624202010-01-08 10:36:02 +0530289
Felix Fietkau1a04d592013-10-11 23:30:52 +0200290 if (!(sc->sc_ah->caps.hw_caps &
291 ATH9K_HW_CAP_4KB_SPLITTRANS)) {
292 /*
293 * Skip descriptor addresses which can cause 4KB
294 * boundary crossing (addr + length) with a 32 dword
295 * descriptor fetch.
296 */
297 while (ATH_DESC_4KB_BOUND_CHECK(bf->bf_daddr)) {
298 BUG_ON((caddr_t) bf->bf_desc >=
299 ((caddr_t) dd->dd_desc +
300 dd->dd_desc_len));
301
302 ds += (desc_len * ndesc);
303 bf->bf_desc = ds;
304 bf->bf_daddr = DS2PHYS(dd, ds);
305 }
Sujith55624202010-01-08 10:36:02 +0530306 }
Felix Fietkau1a04d592013-10-11 23:30:52 +0200307 list_add_tail(&bf->list, head);
Sujith55624202010-01-08 10:36:02 +0530308 }
Felix Fietkau1a04d592013-10-11 23:30:52 +0200309 } else {
310 struct ath_rxbuf *bf;
311
312 bsize = sizeof(struct ath_rxbuf) * nbuf;
313 bf = devm_kzalloc(sc->dev, bsize, GFP_KERNEL);
314 if (!bf)
315 return -ENOMEM;
316
317 for (i = 0; i < nbuf; i++, bf++, ds += (desc_len * ndesc)) {
318 bf->bf_desc = ds;
319 bf->bf_daddr = DS2PHYS(dd, ds);
320
321 if (!(sc->sc_ah->caps.hw_caps &
322 ATH9K_HW_CAP_4KB_SPLITTRANS)) {
323 /*
324 * Skip descriptor addresses which can cause 4KB
325 * boundary crossing (addr + length) with a 32 dword
326 * descriptor fetch.
327 */
328 while (ATH_DESC_4KB_BOUND_CHECK(bf->bf_daddr)) {
329 BUG_ON((caddr_t) bf->bf_desc >=
330 ((caddr_t) dd->dd_desc +
331 dd->dd_desc_len));
332
333 ds += (desc_len * ndesc);
334 bf->bf_desc = ds;
335 bf->bf_daddr = DS2PHYS(dd, ds);
336 }
337 }
338 list_add_tail(&bf->list, head);
339 }
Sujith55624202010-01-08 10:36:02 +0530340 }
341 return 0;
Sujith55624202010-01-08 10:36:02 +0530342}
343
Sujith285f2dd2010-01-08 10:36:07 +0530344static int ath9k_init_queues(struct ath_softc *sc)
345{
Sujith285f2dd2010-01-08 10:36:07 +0530346 int i = 0;
Sujith55624202010-01-08 10:36:02 +0530347
Sujith285f2dd2010-01-08 10:36:07 +0530348 sc->beacon.beaconq = ath9k_hw_beaconq_setup(sc->sc_ah);
Sujith285f2dd2010-01-08 10:36:07 +0530349 sc->beacon.cabq = ath_txq_setup(sc, ATH9K_TX_QUEUE_CAB, 0);
Sujith285f2dd2010-01-08 10:36:07 +0530350 ath_cabq_update(sc);
351
Felix Fietkauf2c7a792013-06-07 18:12:00 +0200352 sc->tx.uapsdq = ath_txq_setup(sc, ATH9K_TX_QUEUE_UAPSD, 0);
353
Sujith Manoharanbea843c2012-11-21 18:13:10 +0530354 for (i = 0; i < IEEE80211_NUM_ACS; i++) {
Felix Fietkau066dae92010-11-07 14:59:39 +0100355 sc->tx.txq_map[i] = ath_txq_setup(sc, ATH9K_TX_QUEUE_DATA, i);
Ben Greear60f2d1d2011-01-09 23:11:52 -0800356 sc->tx.txq_map[i]->mac80211_qnum = i;
Felix Fietkau7702e782012-07-15 19:53:35 +0200357 sc->tx.txq_max_pending[i] = ATH_MAX_QDEPTH;
Ben Greear60f2d1d2011-01-09 23:11:52 -0800358 }
Sujith285f2dd2010-01-08 10:36:07 +0530359 return 0;
Sujith285f2dd2010-01-08 10:36:07 +0530360}
361
Sujith285f2dd2010-01-08 10:36:07 +0530362static void ath9k_init_misc(struct ath_softc *sc)
363{
364 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
365 int i = 0;
Sujith Manoharan3d4e20f2012-03-14 14:40:58 +0530366
Sujith285f2dd2010-01-08 10:36:07 +0530367 setup_timer(&common->ani.timer, ath_ani_calibrate, (unsigned long)sc);
368
Oleksij Rempel32efb0c2014-02-04 10:27:39 +0100369 common->last_rssi = ATH_RSSI_DUMMY_MARKER;
Felix Fietkau364734f2010-09-14 20:22:44 +0200370 memcpy(common->bssidmask, ath_bcast_mac, ETH_ALEN);
Sujith285f2dd2010-01-08 10:36:07 +0530371 sc->beacon.slottime = ATH9K_SLOT_TIME_9;
372
Felix Fietkau7545daf2011-01-24 19:23:16 +0100373 for (i = 0; i < ARRAY_SIZE(sc->beacon.bslot); i++)
Sujith285f2dd2010-01-08 10:36:07 +0530374 sc->beacon.bslot[i] = NULL;
Vasanthakumar Thiagarajan102885a2010-09-02 01:34:43 -0700375
376 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_ANT_DIV_COMB)
377 sc->ant_comb.count = ATH_ANT_DIV_COMB_INIT_COUNT;
Simon Wunderlich04ccd4a2013-01-23 17:38:04 +0100378
Oleksij Rempeldd7657b2014-11-06 08:53:22 +0100379 sc->spec_priv.ah = sc->sc_ah;
Oleksij Rempel21af25d2014-11-06 08:53:20 +0100380 sc->spec_priv.spec_config.enabled = 0;
381 sc->spec_priv.spec_config.short_repeat = true;
382 sc->spec_priv.spec_config.count = 8;
383 sc->spec_priv.spec_config.endless = false;
384 sc->spec_priv.spec_config.period = 0xFF;
385 sc->spec_priv.spec_config.fft_period = 0xF;
Sujith285f2dd2010-01-08 10:36:07 +0530386}
387
Sujith Manoharan0f978bf2013-12-06 16:28:45 +0530388static void ath9k_init_pcoem_platform(struct ath_softc *sc)
Sujith Manoharan9b60b642013-06-13 22:51:26 +0530389{
390 struct ath_hw *ah = sc->sc_ah;
Sujith Manoharan3f2da952013-08-04 14:21:56 +0530391 struct ath9k_hw_capabilities *pCap = &ah->caps;
Sujith Manoharan9b60b642013-06-13 22:51:26 +0530392 struct ath_common *common = ath9k_hw_common(ah);
393
Felix Fietkau935477e2014-10-25 17:19:26 +0200394 if (!IS_ENABLED(CONFIG_ATH9K_PCOEM))
395 return;
396
Sujith Manoharan9b60b642013-06-13 22:51:26 +0530397 if (common->bus_ops->ath_bus_type != ATH_PCI)
398 return;
399
Sujith Manoharane861ef52013-06-18 10:13:43 +0530400 if (sc->driver_data & (ATH9K_PCI_CUS198 |
401 ATH9K_PCI_CUS230)) {
Sujith Manoharan9b60b642013-06-13 22:51:26 +0530402 ah->config.xlna_gpio = 9;
403 ah->config.xatten_margin_cfg = true;
Sujith Manoharane083a422013-08-19 11:04:01 +0530404 ah->config.alt_mingainidx = true;
Sujith Manoharan31fd2162013-08-04 14:22:01 +0530405 ah->config.ant_ctrl_comm2g_switch_enable = 0x000BBB88;
Sujith Manoharan3afa6b42013-08-04 14:21:54 +0530406 sc->ant_comb.low_rssi_thresh = 20;
407 sc->ant_comb.fast_div_bias = 3;
Sujith Manoharan9b60b642013-06-13 22:51:26 +0530408
Sujith Manoharane861ef52013-06-18 10:13:43 +0530409 ath_info(common, "Set parameters for %s\n",
410 (sc->driver_data & ATH9K_PCI_CUS198) ?
411 "CUS198" : "CUS230");
Sujith Manoharan3f2da952013-08-04 14:21:56 +0530412 }
413
414 if (sc->driver_data & ATH9K_PCI_CUS217)
Sujith Manoharan12eea642013-06-18 15:42:36 +0530415 ath_info(common, "CUS217 card detected\n");
Sujith Manoharan3f2da952013-08-04 14:21:56 +0530416
Sujith Manoharan10631332013-09-02 13:59:05 +0530417 if (sc->driver_data & ATH9K_PCI_CUS252)
418 ath_info(common, "CUS252 card detected\n");
419
Sujith Manoharan3fcdd0a2013-09-02 13:59:06 +0530420 if (sc->driver_data & ATH9K_PCI_AR9565_1ANT)
421 ath_info(common, "WB335 1-ANT card detected\n");
422
423 if (sc->driver_data & ATH9K_PCI_AR9565_2ANT)
424 ath_info(common, "WB335 2-ANT card detected\n");
425
Sujith Manoharan4dd35642013-10-23 14:26:04 +0530426 if (sc->driver_data & ATH9K_PCI_KILLER)
427 ath_info(common, "Killer Wireless card detected\n");
428
Sujith Manoharan3fcdd0a2013-09-02 13:59:06 +0530429 /*
430 * Some WB335 cards do not support antenna diversity. Since
431 * we use a hardcoded value for AR9565 instead of using the
432 * EEPROM/OTP data, remove the combining feature from
433 * the HW capabilities bitmap.
434 */
435 if (sc->driver_data & (ATH9K_PCI_AR9565_1ANT | ATH9K_PCI_AR9565_2ANT)) {
436 if (!(sc->driver_data & ATH9K_PCI_BT_ANT_DIV))
437 pCap->hw_caps &= ~ATH9K_HW_CAP_ANT_DIV_COMB;
438 }
439
Sujith Manoharan3f2da952013-08-04 14:21:56 +0530440 if (sc->driver_data & ATH9K_PCI_BT_ANT_DIV) {
441 pCap->hw_caps |= ATH9K_HW_CAP_BT_ANT_DIV;
442 ath_info(common, "Set BT/WLAN RX diversity capability\n");
Sujith Manoharan9b60b642013-06-13 22:51:26 +0530443 }
Sujith Manoharand1ae25a2013-08-25 16:30:40 +0530444
445 if (sc->driver_data & ATH9K_PCI_D3_L1_WAR) {
446 ah->config.pcie_waen = 0x0040473b;
447 ath_info(common, "Enable WAR for ASPM D3/L1\n");
448 }
Sujith Manoharan2d22c7d2013-11-08 11:45:25 +0530449
Sujith Manoharanafa7e6d2015-03-09 14:20:07 +0530450 /*
451 * The default value of pll_pwrsave is 1.
452 * For certain AR9485 cards, it is set to 0.
Sujith Manoharan656cd752015-03-09 14:20:08 +0530453 * For AR9462, AR9565 it's set to 7.
Sujith Manoharanafa7e6d2015-03-09 14:20:07 +0530454 */
455 ah->config.pll_pwrsave = 1;
456
Sujith Manoharan2d22c7d2013-11-08 11:45:25 +0530457 if (sc->driver_data & ATH9K_PCI_NO_PLL_PWRSAVE) {
Sujith Manoharanafa7e6d2015-03-09 14:20:07 +0530458 ah->config.pll_pwrsave = 0;
Sujith Manoharan2d22c7d2013-11-08 11:45:25 +0530459 ath_info(common, "Disable PLL PowerSave\n");
460 }
Sujith Manoharanaeeb2062014-11-16 06:11:02 +0530461
462 if (sc->driver_data & ATH9K_PCI_LED_ACT_HI)
463 ah->config.led_active_high = true;
Sujith Manoharan9b60b642013-06-13 22:51:26 +0530464}
465
Gabor Juhosab5c4f72012-12-10 15:30:28 +0100466static void ath9k_eeprom_request_cb(const struct firmware *eeprom_blob,
467 void *ctx)
468{
469 struct ath9k_eeprom_ctx *ec = ctx;
470
471 if (eeprom_blob)
472 ec->ah->eeprom_blob = eeprom_blob;
473
474 complete(&ec->complete);
475}
476
477static int ath9k_eeprom_request(struct ath_softc *sc, const char *name)
478{
479 struct ath9k_eeprom_ctx ec;
480 struct ath_hw *ah = ah = sc->sc_ah;
481 int err;
482
483 /* try to load the EEPROM content asynchronously */
484 init_completion(&ec.complete);
485 ec.ah = sc->sc_ah;
486
487 err = request_firmware_nowait(THIS_MODULE, 1, name, sc->dev, GFP_KERNEL,
488 &ec, ath9k_eeprom_request_cb);
489 if (err < 0) {
490 ath_err(ath9k_hw_common(ah),
491 "EEPROM request failed\n");
492 return err;
493 }
494
495 wait_for_completion(&ec.complete);
496
497 if (!ah->eeprom_blob) {
498 ath_err(ath9k_hw_common(ah),
499 "Unable to load EEPROM file %s\n", name);
500 return -EINVAL;
501 }
502
503 return 0;
504}
505
506static void ath9k_eeprom_release(struct ath_softc *sc)
507{
508 release_firmware(sc->sc_ah->eeprom_blob);
509}
510
Sujith Manoharan0f978bf2013-12-06 16:28:45 +0530511static int ath9k_init_soc_platform(struct ath_softc *sc)
512{
513 struct ath9k_platform_data *pdata = sc->dev->platform_data;
514 struct ath_hw *ah = sc->sc_ah;
515 int ret = 0;
516
517 if (!pdata)
518 return 0;
519
520 if (pdata->eeprom_name) {
521 ret = ath9k_eeprom_request(sc, pdata->eeprom_name);
522 if (ret)
523 return ret;
524 }
525
526 if (pdata->tx_gain_buffalo)
527 ah->config.tx_gain_buffalo = true;
528
529 return ret;
530}
531
Pavel Roskineb93e892011-07-23 03:55:39 -0400532static int ath9k_init_softc(u16 devid, struct ath_softc *sc,
Sujith285f2dd2010-01-08 10:36:07 +0530533 const struct ath_bus_ops *bus_ops)
534{
Felix Fietkau6fb1b1e2011-03-19 13:55:39 +0100535 struct ath9k_platform_data *pdata = sc->dev->platform_data;
Sujith285f2dd2010-01-08 10:36:07 +0530536 struct ath_hw *ah = NULL;
Sujith Manoharan3f2da952013-08-04 14:21:56 +0530537 struct ath9k_hw_capabilities *pCap;
Sujith285f2dd2010-01-08 10:36:07 +0530538 struct ath_common *common;
539 int ret = 0, i;
540 int csz = 0;
541
Felix Fietkaub81950b12012-12-12 13:14:22 +0100542 ah = devm_kzalloc(sc->dev, sizeof(struct ath_hw), GFP_KERNEL);
Sujith285f2dd2010-01-08 10:36:07 +0530543 if (!ah)
544 return -ENOMEM;
545
Felix Fietkauc1b976d2012-12-12 13:14:23 +0100546 ah->dev = sc->dev;
Ben Greear233536e2011-01-09 23:11:44 -0800547 ah->hw = sc->hw;
Sujith285f2dd2010-01-08 10:36:07 +0530548 ah->hw_version.devid = devid;
Felix Fietkauf9f84e92011-03-23 20:57:24 +0100549 ah->reg_ops.read = ath9k_ioread32;
Oleksij Rempeld55ce0a2015-03-22 19:29:50 +0100550 ah->reg_ops.multi_read = ath9k_multi_ioread32;
Felix Fietkauf9f84e92011-03-23 20:57:24 +0100551 ah->reg_ops.write = ath9k_iowrite32;
Felix Fietkau845e03c2011-03-23 20:57:25 +0100552 ah->reg_ops.rmw = ath9k_reg_rmw;
Sujith Manoharan3f2da952013-08-04 14:21:56 +0530553 pCap = &ah->caps;
Sujith285f2dd2010-01-08 10:36:07 +0530554
Janusz Dziedzic95a59922013-10-14 11:06:03 +0200555 common = ath9k_hw_common(ah);
Felix Fietkau56bdbe02014-11-30 21:58:30 +0100556
557 /* Will be cleared in ath9k_start() */
558 set_bit(ATH_OP_INVALID, &common->op_flags);
559
560 sc->sc_ah = ah;
Janusz Dziedzic95a59922013-10-14 11:06:03 +0200561 sc->dfs_detector = dfs_pattern_detector_init(common, NL80211_DFS_UNSET);
Luis R. Rodriguez89f927a2013-10-14 17:42:11 -0700562 sc->tx99_power = MAX_RATE_POWER + 1;
Felix Fietkau10e23182013-11-11 22:23:35 +0100563 init_waitqueue_head(&sc->tx_wait);
Rajkumar Manoharanca900ac2014-06-11 16:18:02 +0530564 sc->cur_chan = &sc->chanctx[0];
Sujith Manoharan499afac2014-08-22 20:39:31 +0530565 if (!ath9k_is_chanctx_enabled())
Rajkumar Manoharan3ad9c382014-06-11 16:18:15 +0530566 sc->cur_chan->hw_queue_base = 0;
Zefir Kurtisi8e92d3f2012-04-03 17:15:50 +0200567
Helmut Schaa552a5152014-05-07 09:28:31 +0200568 if (!pdata || pdata->use_eeprom) {
Felix Fietkaua05b5d452010-11-17 04:25:33 +0100569 ah->ah_flags |= AH_USE_EEPROM;
Felix Fietkau6de66dd2011-03-19 13:55:40 +0100570 sc->sc_ah->led_pin = -1;
571 } else {
572 sc->sc_ah->gpio_mask = pdata->gpio_mask;
573 sc->sc_ah->gpio_val = pdata->gpio_val;
574 sc->sc_ah->led_pin = pdata->led_pin;
Vasanthakumar Thiagarajanf2f5f2a2011-04-19 19:29:01 +0530575 ah->is_clk_25mhz = pdata->is_clk_25mhz;
Gabor Juhos37625612011-06-21 11:23:23 +0200576 ah->get_mac_revision = pdata->get_mac_revision;
Gabor Juhos7d95847c2011-06-21 11:23:51 +0200577 ah->external_reset = pdata->external_reset;
Felix Fietkau34689682014-10-25 17:19:34 +0200578 ah->disable_2ghz = pdata->disable_2ghz;
579 ah->disable_5ghz = pdata->disable_5ghz;
Felix Fietkaua59dadb2014-10-25 17:19:33 +0200580 if (!pdata->endian_check)
581 ah->ah_flags |= AH_NO_EEP_SWAP;
Felix Fietkau6de66dd2011-03-19 13:55:40 +0100582 }
Felix Fietkaua05b5d452010-11-17 04:25:33 +0100583
Felix Fietkauf9f84e92011-03-23 20:57:24 +0100584 common->ops = &ah->reg_ops;
Sujith285f2dd2010-01-08 10:36:07 +0530585 common->bus_ops = bus_ops;
Oleksij Rempel99d22172014-11-06 08:53:25 +0100586 common->ps_ops = &ath9k_ps_ops;
Sujith285f2dd2010-01-08 10:36:07 +0530587 common->ah = ah;
588 common->hw = sc->hw;
589 common->priv = sc;
590 common->debug_mask = ath9k_debug;
Vasanthakumar Thiagarajan8f5dcb12010-11-26 06:10:06 -0800591 common->btcoex_enabled = ath9k_btcoex_enable == 1;
Mohammed Shafi Shajakhan05c0be22011-05-26 10:56:15 +0530592 common->disable_ani = false;
Sujith Manoharane09f2dc2012-09-16 08:06:56 +0530593
594 /*
Sujith Manoharan9b60b642013-06-13 22:51:26 +0530595 * Platform quirks.
596 */
Sujith Manoharan0f978bf2013-12-06 16:28:45 +0530597 ath9k_init_pcoem_platform(sc);
598
599 ret = ath9k_init_soc_platform(sc);
600 if (ret)
601 return ret;
Sujith Manoharan9b60b642013-06-13 22:51:26 +0530602
603 /*
Sujith Manoharan3f2da952013-08-04 14:21:56 +0530604 * Enable WLAN/BT RX Antenna diversity only when:
605 *
Sujith Manoharan7d845872013-08-07 12:29:27 +0530606 * - BTCOEX is disabled.
Sujith Manoharan3f2da952013-08-04 14:21:56 +0530607 * - the user manually requests the feature.
608 * - the HW cap is set using the platform data.
Sujith Manoharane09f2dc2012-09-16 08:06:56 +0530609 */
Sujith Manoharan7d845872013-08-07 12:29:27 +0530610 if (!common->btcoex_enabled && ath9k_bt_ant_diversity &&
Sujith Manoharan3f2da952013-08-04 14:21:56 +0530611 (pCap->hw_caps & ATH9K_HW_CAP_BT_ANT_DIV))
Sujith Manoharan63081302013-08-04 14:21:55 +0530612 common->bt_ant_diversity = 1;
Sujith Manoharane09f2dc2012-09-16 08:06:56 +0530613
Ben Greear20b257442010-10-15 15:04:09 -0700614 spin_lock_init(&common->cc_lock);
Sujith285f2dd2010-01-08 10:36:07 +0530615 spin_lock_init(&sc->sc_serial_rw);
616 spin_lock_init(&sc->sc_pm_lock);
Felix Fietkaubff11762014-06-11 16:17:52 +0530617 spin_lock_init(&sc->chan_lock);
Sujith285f2dd2010-01-08 10:36:07 +0530618 mutex_init(&sc->mutex);
619 tasklet_init(&sc->intr_tq, ath9k_tasklet, (unsigned long)sc);
Sujith Manoharanfb6e2522012-07-17 17:16:22 +0530620 tasklet_init(&sc->bcon_tasklet, ath9k_beacon_tasklet,
Sujith285f2dd2010-01-08 10:36:07 +0530621 (unsigned long)sc);
622
Felix Fietkaubf3dac52013-11-11 22:23:33 +0100623 setup_timer(&sc->sleep_timer, ath_ps_full_sleep, (unsigned long)sc);
Sujith Manoharanaaa1ec42012-06-04 16:27:08 +0530624 INIT_WORK(&sc->hw_reset_work, ath_reset_work);
Sujith Manoharanaaa1ec42012-06-04 16:27:08 +0530625 INIT_WORK(&sc->paprd_work, ath_paprd_calibrate);
626 INIT_DELAYED_WORK(&sc->hw_pll_work, ath_hw_pll_work);
Sujith Manoharan705d0bf2014-08-23 13:29:06 +0530627
628 ath9k_init_channel_context(sc);
Sujith Manoharanaaa1ec42012-06-04 16:27:08 +0530629
Sujith285f2dd2010-01-08 10:36:07 +0530630 /*
631 * Cache line size is used to size and align various
632 * structures used to communicate with the hardware.
633 */
634 ath_read_cachesize(common, &csz);
635 common->cachelsz = csz << 2; /* convert to bytes */
636
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400637 /* Initializes the hardware for all supported chipsets */
Sujith285f2dd2010-01-08 10:36:07 +0530638 ret = ath9k_hw_init(ah);
Luis R. Rodriguezd70357d2010-04-15 17:38:06 -0400639 if (ret)
Sujith285f2dd2010-01-08 10:36:07 +0530640 goto err_hw;
Sujith285f2dd2010-01-08 10:36:07 +0530641
Felix Fietkau6fb1b1e2011-03-19 13:55:39 +0100642 if (pdata && pdata->macaddr)
643 memcpy(common->macaddr, pdata->macaddr, ETH_ALEN);
644
Sujith285f2dd2010-01-08 10:36:07 +0530645 ret = ath9k_init_queues(sc);
646 if (ret)
647 goto err_queues;
648
649 ret = ath9k_init_btcoex(sc);
650 if (ret)
651 goto err_btcoex;
652
Oleksij Rempel13f71052014-02-25 14:48:50 +0100653 ret = ath9k_cmn_init_channels_rates(common);
Felix Fietkauf209f522010-10-01 01:06:53 +0200654 if (ret)
655 goto err_btcoex;
656
Sujith Manoharanc7dd40c2014-08-22 20:39:30 +0530657 ret = ath9k_init_p2p(sc);
658 if (ret)
Sujith Manoharan4f681692014-08-22 20:39:25 +0530659 goto err_btcoex;
Felix Fietkaud463af42014-04-06 00:37:03 +0200660
Rajkumar Manoharanf82b4bd2011-08-13 10:28:15 +0530661 ath9k_cmn_init_crypto(sc->sc_ah);
Sujith285f2dd2010-01-08 10:36:07 +0530662 ath9k_init_misc(sc);
Rajkumar Manoharan8f176a32012-09-12 18:59:23 +0530663 ath_fill_led_pin(sc);
Felix Fietkaufbbcd142014-06-11 16:17:49 +0530664 ath_chanctx_init(sc);
Sujith Manoharane90e3022014-08-23 13:29:20 +0530665 ath9k_offchannel_init(sc);
Sujith285f2dd2010-01-08 10:36:07 +0530666
Sujith Manoharand09f5f42012-06-04 16:27:14 +0530667 if (common->bus_ops->aspm_init)
668 common->bus_ops->aspm_init(common);
669
Sujith55624202010-01-08 10:36:02 +0530670 return 0;
Sujith285f2dd2010-01-08 10:36:07 +0530671
672err_btcoex:
Sujith55624202010-01-08 10:36:02 +0530673 for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++)
674 if (ATH_TXQ_SETUP(sc, i))
675 ath_tx_cleanupq(sc, &sc->tx.txq[i]);
Sujith285f2dd2010-01-08 10:36:07 +0530676err_queues:
Sujith285f2dd2010-01-08 10:36:07 +0530677 ath9k_hw_deinit(ah);
678err_hw:
Gabor Juhosab5c4f72012-12-10 15:30:28 +0100679 ath9k_eeprom_release(sc);
Luis R. Rodriguez89f927a2013-10-14 17:42:11 -0700680 dev_kfree_skb_any(sc->tx99_skb);
Sujith285f2dd2010-01-08 10:36:07 +0530681 return ret;
Sujith55624202010-01-08 10:36:02 +0530682}
683
Felix Fietkaubabcbc22010-10-20 02:09:46 +0200684static void ath9k_init_band_txpower(struct ath_softc *sc, int band)
685{
686 struct ieee80211_supported_band *sband;
687 struct ieee80211_channel *chan;
688 struct ath_hw *ah = sc->sc_ah;
Oleksij Rempel13f71052014-02-25 14:48:50 +0100689 struct ath_common *common = ath9k_hw_common(ah);
Simon Wunderlich06718942013-08-16 10:46:04 +0200690 struct cfg80211_chan_def chandef;
Felix Fietkaubabcbc22010-10-20 02:09:46 +0200691 int i;
692
Oleksij Rempel13f71052014-02-25 14:48:50 +0100693 sband = &common->sbands[band];
Felix Fietkaubabcbc22010-10-20 02:09:46 +0200694 for (i = 0; i < sband->n_channels; i++) {
695 chan = &sband->channels[i];
696 ah->curchan = &ah->channels[chan->hw_value];
Simon Wunderlich06718942013-08-16 10:46:04 +0200697 cfg80211_chandef_create(&chandef, chan, NL80211_CHAN_HT20);
Felix Fietkau2297f1c2013-10-11 23:30:57 +0200698 ath9k_cmn_get_channel(sc->hw, ah, &chandef);
Felix Fietkaubabcbc22010-10-20 02:09:46 +0200699 ath9k_hw_set_txpowerlimit(ah, MAX_RATE_POWER, true);
Felix Fietkaubabcbc22010-10-20 02:09:46 +0200700 }
701}
702
703static void ath9k_init_txpower_limits(struct ath_softc *sc)
704{
705 struct ath_hw *ah = sc->sc_ah;
706 struct ath9k_channel *curchan = ah->curchan;
707
708 if (ah->caps.hw_caps & ATH9K_HW_CAP_2GHZ)
709 ath9k_init_band_txpower(sc, IEEE80211_BAND_2GHZ);
710 if (ah->caps.hw_caps & ATH9K_HW_CAP_5GHZ)
711 ath9k_init_band_txpower(sc, IEEE80211_BAND_5GHZ);
712
713 ah->curchan = curchan;
714}
715
Felix Fietkau20c8e8d2012-04-17 02:40:07 +0200716static const struct ieee80211_iface_limit if_limits[] = {
Rajkumar Manoharan71a5f882014-05-29 15:11:09 +0530717 { .max = 2048, .types = BIT(NL80211_IFTYPE_STATION) },
Felix Fietkau20c8e8d2012-04-17 02:40:07 +0200718 { .max = 8, .types =
719#ifdef CONFIG_MAC80211_MESH
720 BIT(NL80211_IFTYPE_MESH_POINT) |
721#endif
Felix Fietkau95ae4812014-04-06 00:37:02 +0200722 BIT(NL80211_IFTYPE_AP) },
723 { .max = 1, .types = BIT(NL80211_IFTYPE_P2P_CLIENT) |
Felix Fietkau20c8e8d2012-04-17 02:40:07 +0200724 BIT(NL80211_IFTYPE_P2P_GO) },
725};
726
Rajkumar Manoharan71a5f882014-05-29 15:11:09 +0530727static const struct ieee80211_iface_limit wds_limits[] = {
728 { .max = 2048, .types = BIT(NL80211_IFTYPE_WDS) },
729};
730
Sujith Manoharan499afac2014-08-22 20:39:31 +0530731#ifdef CONFIG_ATH9K_CHANNEL_CONTEXT
732
Rajkumar Manoharana4068322014-06-11 16:18:16 +0530733static const struct ieee80211_iface_limit if_limits_multi[] = {
Sujith Manoharan86162d42014-08-24 21:16:12 +0530734 { .max = 2, .types = BIT(NL80211_IFTYPE_STATION) |
735 BIT(NL80211_IFTYPE_AP) |
736 BIT(NL80211_IFTYPE_P2P_CLIENT) |
Rajkumar Manoharana4068322014-06-11 16:18:16 +0530737 BIT(NL80211_IFTYPE_P2P_GO) },
Sujith Manoharan86162d42014-08-24 21:16:12 +0530738 { .max = 1, .types = BIT(NL80211_IFTYPE_ADHOC) },
Janusz.Dziedzic@tieto.comeb61f9f2015-07-21 11:11:40 +0200739 { .max = 1, .types = BIT(NL80211_IFTYPE_P2P_DEVICE) },
Rajkumar Manoharana4068322014-06-11 16:18:16 +0530740};
741
Rajkumar Manoharana4068322014-06-11 16:18:16 +0530742static const struct ieee80211_iface_combination if_comb_multi[] = {
743 {
744 .limits = if_limits_multi,
745 .n_limits = ARRAY_SIZE(if_limits_multi),
Janusz.Dziedzic@tieto.comeb61f9f2015-07-21 11:11:40 +0200746 .max_interfaces = 3,
Rajkumar Manoharana4068322014-06-11 16:18:16 +0530747 .num_different_channels = 2,
748 .beacon_int_infra_match = true,
749 },
750};
751
Sujith Manoharan499afac2014-08-22 20:39:31 +0530752#endif /* CONFIG_ATH9K_CHANNEL_CONTEXT */
753
754static const struct ieee80211_iface_limit if_dfs_limits[] = {
755 { .max = 1, .types = BIT(NL80211_IFTYPE_AP) |
756#ifdef CONFIG_MAC80211_MESH
757 BIT(NL80211_IFTYPE_MESH_POINT) |
758#endif
759 BIT(NL80211_IFTYPE_ADHOC) },
760};
761
Zefir Kurtisie9cdedf2013-04-03 18:31:29 +0200762static const struct ieee80211_iface_combination if_comb[] = {
763 {
764 .limits = if_limits,
765 .n_limits = ARRAY_SIZE(if_limits),
766 .max_interfaces = 2048,
767 .num_different_channels = 1,
768 .beacon_int_infra_match = true,
769 },
Rajkumar Manoharan71a5f882014-05-29 15:11:09 +0530770 {
771 .limits = wds_limits,
772 .n_limits = ARRAY_SIZE(wds_limits),
773 .max_interfaces = 2048,
774 .num_different_channels = 1,
775 .beacon_int_infra_match = true,
776 },
Janusz Dziedzic4d762482014-04-08 13:38:43 +0200777#ifdef CONFIG_ATH9K_DFS_CERTIFIED
Zefir Kurtisie9cdedf2013-04-03 18:31:29 +0200778 {
779 .limits = if_dfs_limits,
780 .n_limits = ARRAY_SIZE(if_dfs_limits),
781 .max_interfaces = 1,
782 .num_different_channels = 1,
783 .beacon_int_infra_match = true,
Janusz Dziedzic87eb0162013-11-01 20:39:49 +0100784 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
Zefir Kurtisi387f1492015-03-10 17:49:31 +0100785 BIT(NL80211_CHAN_WIDTH_20) |
786 BIT(NL80211_CHAN_WIDTH_40),
Zefir Kurtisie9cdedf2013-04-03 18:31:29 +0200787 }
Janusz Dziedzic4d762482014-04-08 13:38:43 +0200788#endif
Felix Fietkau20c8e8d2012-04-17 02:40:07 +0200789};
Felix Fietkau43c35282011-09-03 01:40:27 +0200790
Sujith Manoharan868caae2014-10-21 19:23:02 +0530791#ifdef CONFIG_ATH9K_CHANNEL_CONTEXT
792static void ath9k_set_mcc_capab(struct ath_softc *sc, struct ieee80211_hw *hw)
793{
794 struct ath_hw *ah = sc->sc_ah;
795 struct ath_common *common = ath9k_hw_common(ah);
796
797 if (!ath9k_is_chanctx_enabled())
798 return;
799
Johannes Berg30686bf2015-06-02 21:39:54 +0200800 ieee80211_hw_set(hw, QUEUE_CONTROL);
Sujith Manoharan868caae2014-10-21 19:23:02 +0530801 hw->queues = ATH9K_NUM_TX_QUEUES;
802 hw->offchannel_tx_hw_queue = hw->queues - 1;
803 hw->wiphy->interface_modes &= ~ BIT(NL80211_IFTYPE_WDS);
804 hw->wiphy->iface_combinations = if_comb_multi;
805 hw->wiphy->n_iface_combinations = ARRAY_SIZE(if_comb_multi);
806 hw->wiphy->max_scan_ssids = 255;
807 hw->wiphy->max_scan_ie_len = IEEE80211_MAX_DATA_LEN;
808 hw->wiphy->max_remain_on_channel_duration = 10000;
809 hw->chanctx_data_size = sizeof(void *);
810 hw->extra_beacon_tailroom =
811 sizeof(struct ieee80211_p2p_noa_attr) + 9;
812
813 ath_dbg(common, CHAN_CTX, "Use channel contexts\n");
814}
815#endif /* CONFIG_ATH9K_CHANNEL_CONTEXT */
816
Sujith Manoharan7b6ef992013-12-18 09:53:19 +0530817static void ath9k_set_hw_capab(struct ath_softc *sc, struct ieee80211_hw *hw)
Sujith55624202010-01-08 10:36:02 +0530818{
Felix Fietkau43c35282011-09-03 01:40:27 +0200819 struct ath_hw *ah = sc->sc_ah;
820 struct ath_common *common = ath9k_hw_common(ah);
Sujith285f2dd2010-01-08 10:36:07 +0530821
Johannes Berg30686bf2015-06-02 21:39:54 +0200822 ieee80211_hw_set(hw, SUPPORTS_HT_CCK_RATES);
823 ieee80211_hw_set(hw, SUPPORTS_RC_TABLE);
824 ieee80211_hw_set(hw, REPORTS_TX_ACK_STATUS);
825 ieee80211_hw_set(hw, SPECTRUM_MGMT);
826 ieee80211_hw_set(hw, PS_NULLFUNC_STACK);
827 ieee80211_hw_set(hw, SIGNAL_DBM);
828 ieee80211_hw_set(hw, RX_INCLUDES_FCS);
829 ieee80211_hw_set(hw, HOST_BROADCAST_PS_BUFFERING);
Felix Fietkauf419c5f2015-07-22 13:06:12 +0200830 ieee80211_hw_set(hw, SUPPORT_FAST_XMIT);
Sujith55624202010-01-08 10:36:02 +0530831
Sujith Manoharan82983832014-02-04 08:37:53 +0530832 if (ath9k_ps_enable)
Johannes Berg30686bf2015-06-02 21:39:54 +0200833 ieee80211_hw_set(hw, SUPPORTS_PS);
Sujith Manoharan82983832014-02-04 08:37:53 +0530834
Oleksij Rempelb0a1ae92013-05-24 20:30:59 +0200835 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_HT) {
Johannes Berg30686bf2015-06-02 21:39:54 +0200836 ieee80211_hw_set(hw, AMPDU_AGGREGATION);
Oleksij Rempelb0a1ae92013-05-24 20:30:59 +0200837
838 if (AR_SREV_9280_20_OR_LATER(ah))
839 hw->radiotap_mcs_details |=
840 IEEE80211_RADIOTAP_MCS_HAVE_STBC;
841 }
Luis R. Rodriguez5ffaf8a2010-02-02 11:58:33 -0500842
John W. Linville3e6109c2011-01-05 09:39:17 -0500843 if (AR_SREV_9160_10_OR_LATER(sc->sc_ah) || ath9k_modparam_nohwcrypt)
Johannes Berg30686bf2015-06-02 21:39:54 +0200844 ieee80211_hw_set(hw, MFP_CAPABLE);
Sujith55624202010-01-08 10:36:02 +0530845
Sujith Manoharanfdcf1bd2014-09-05 08:03:14 +0530846 hw->wiphy->features |= NL80211_FEATURE_ACTIVE_MONITOR |
847 NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE |
848 NL80211_FEATURE_P2P_GO_CTWIN;
Felix Fietkauec26bcc2013-05-28 13:01:54 +0200849
Luis R. Rodriguez89f927a2013-10-14 17:42:11 -0700850 if (!config_enabled(CONFIG_ATH9K_TX99)) {
851 hw->wiphy->interface_modes =
852 BIT(NL80211_IFTYPE_P2P_GO) |
853 BIT(NL80211_IFTYPE_P2P_CLIENT) |
854 BIT(NL80211_IFTYPE_AP) |
Luis R. Rodriguez89f927a2013-10-14 17:42:11 -0700855 BIT(NL80211_IFTYPE_STATION) |
856 BIT(NL80211_IFTYPE_ADHOC) |
Sujith Manoharan499afac2014-08-22 20:39:31 +0530857 BIT(NL80211_IFTYPE_MESH_POINT) |
Jan Kaisrlik862a3362015-09-17 14:03:46 +0200858 BIT(NL80211_IFTYPE_WDS) |
859 BIT(NL80211_IFTYPE_OCB);
Sujith Manoharan499afac2014-08-22 20:39:31 +0530860
Janusz.Dziedzic@tieto.comeb61f9f2015-07-21 11:11:40 +0200861 if (ath9k_is_chanctx_enabled())
862 hw->wiphy->interface_modes |=
863 BIT(NL80211_IFTYPE_P2P_DEVICE);
864
Rajkumar Manoharana4068322014-06-11 16:18:16 +0530865 hw->wiphy->iface_combinations = if_comb;
Rajkumar Manoharan71a5f882014-05-29 15:11:09 +0530866 hw->wiphy->n_iface_combinations = ARRAY_SIZE(if_comb);
Luis R. Rodriguez89f927a2013-10-14 17:42:11 -0700867 }
Felix Fietkau20c8e8d2012-04-17 02:40:07 +0200868
Sujith Manoharan531671c2013-06-01 07:08:09 +0530869 hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
Sujith55624202010-01-08 10:36:02 +0530870
Jouni Malinencfdc9a82011-03-23 14:52:19 +0200871 hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
Jouni Malinenfd656232011-10-27 17:31:50 +0300872 hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS;
Johannes Berg81ddbb52012-03-26 18:47:18 +0200873 hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
Simon Wunderlich6fac8bb2013-08-14 08:01:34 +0200874 hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_5_10_MHZ;
Simon Wunderlichd074e8d2013-08-14 08:01:38 +0200875 hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
Jouni Malinen7b4f6632014-02-18 20:41:08 +0200876 hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
Jouni Malinencfdc9a82011-03-23 14:52:19 +0200877
Sujith Manoharan868caae2014-10-21 19:23:02 +0530878 hw->queues = 4;
Sujith55624202010-01-08 10:36:02 +0530879 hw->max_rates = 4;
Rajkumar Manoharan5f2f9e42014-06-26 16:54:41 +0530880 hw->max_listen_interval = 10;
Felix Fietkau65896512010-01-24 03:26:11 +0100881 hw->max_rate_tries = 10;
Sujith55624202010-01-08 10:36:02 +0530882 hw->sta_data_size = sizeof(struct ath_node);
883 hw->vif_data_size = sizeof(struct ath_vif);
884
Felix Fietkau43c35282011-09-03 01:40:27 +0200885 hw->wiphy->available_antennas_rx = BIT(ah->caps.max_rxchains) - 1;
886 hw->wiphy->available_antennas_tx = BIT(ah->caps.max_txchains) - 1;
887
888 /* single chain devices with rx diversity */
889 if (ah->caps.hw_caps & ATH9K_HW_CAP_ANT_DIV_COMB)
890 hw->wiphy->available_antennas_rx = BIT(0) | BIT(1);
891
892 sc->ant_rx = hw->wiphy->available_antennas_rx;
893 sc->ant_tx = hw->wiphy->available_antennas_tx;
894
Felix Fietkaud4659912010-10-14 16:02:39 +0200895 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_2GHZ)
Sujith55624202010-01-08 10:36:02 +0530896 hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
Oleksij Rempel13f71052014-02-25 14:48:50 +0100897 &common->sbands[IEEE80211_BAND_2GHZ];
Felix Fietkaud4659912010-10-14 16:02:39 +0200898 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_5GHZ)
Sujith55624202010-01-08 10:36:02 +0530899 hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
Oleksij Rempel13f71052014-02-25 14:48:50 +0100900 &common->sbands[IEEE80211_BAND_5GHZ];
Sujith285f2dd2010-01-08 10:36:07 +0530901
Sujith Manoharan868caae2014-10-21 19:23:02 +0530902#ifdef CONFIG_ATH9K_CHANNEL_CONTEXT
903 ath9k_set_mcc_capab(sc, hw);
904#endif
Sujith Manoharanbabaa802013-10-28 13:01:28 +0530905 ath9k_init_wow(hw);
Oleksij Rempelb57ba3b2014-02-25 14:48:55 +0100906 ath9k_cmn_reload_chainmask(ah);
Sujith285f2dd2010-01-08 10:36:07 +0530907
908 SET_IEEE80211_PERM_ADDR(hw, common->macaddr);
Sujith55624202010-01-08 10:36:02 +0530909}
910
Pavel Roskineb93e892011-07-23 03:55:39 -0400911int ath9k_init_device(u16 devid, struct ath_softc *sc,
Sujith55624202010-01-08 10:36:02 +0530912 const struct ath_bus_ops *bus_ops)
913{
914 struct ieee80211_hw *hw = sc->hw;
915 struct ath_common *common;
916 struct ath_hw *ah;
Sujith285f2dd2010-01-08 10:36:07 +0530917 int error = 0;
Sujith55624202010-01-08 10:36:02 +0530918 struct ath_regulatory *reg;
919
Sujith285f2dd2010-01-08 10:36:07 +0530920 /* Bring up device */
Pavel Roskineb93e892011-07-23 03:55:39 -0400921 error = ath9k_init_softc(devid, sc, bus_ops);
Felix Fietkaub81950b12012-12-12 13:14:22 +0100922 if (error)
923 return error;
Sujith55624202010-01-08 10:36:02 +0530924
925 ah = sc->sc_ah;
926 common = ath9k_hw_common(ah);
Sujith285f2dd2010-01-08 10:36:07 +0530927 ath9k_set_hw_capab(sc, hw);
Sujith55624202010-01-08 10:36:02 +0530928
Sujith285f2dd2010-01-08 10:36:07 +0530929 /* Initialize regulatory */
Sujith55624202010-01-08 10:36:02 +0530930 error = ath_regd_init(&common->regulatory, sc->hw->wiphy,
931 ath9k_reg_notifier);
932 if (error)
Felix Fietkaub81950b12012-12-12 13:14:22 +0100933 goto deinit;
Sujith55624202010-01-08 10:36:02 +0530934
935 reg = &common->regulatory;
936
Sujith285f2dd2010-01-08 10:36:07 +0530937 /* Setup TX DMA */
Sujith55624202010-01-08 10:36:02 +0530938 error = ath_tx_init(sc, ATH_TXBUF);
939 if (error != 0)
Felix Fietkaub81950b12012-12-12 13:14:22 +0100940 goto deinit;
Sujith55624202010-01-08 10:36:02 +0530941
Sujith285f2dd2010-01-08 10:36:07 +0530942 /* Setup RX DMA */
Sujith55624202010-01-08 10:36:02 +0530943 error = ath_rx_init(sc, ATH_RXBUF);
944 if (error != 0)
Felix Fietkaub81950b12012-12-12 13:14:22 +0100945 goto deinit;
Sujith285f2dd2010-01-08 10:36:07 +0530946
Felix Fietkaubabcbc22010-10-20 02:09:46 +0200947 ath9k_init_txpower_limits(sc);
948
Felix Fietkau0cf55c22011-02-27 22:26:40 +0100949#ifdef CONFIG_MAC80211_LEDS
950 /* must be initialized before ieee80211_register_hw */
951 sc->led_cdev.default_trigger = ieee80211_create_tpt_led_trigger(sc->hw,
952 IEEE80211_TPT_LEDTRIG_FL_RADIO, ath9k_tpt_blink,
953 ARRAY_SIZE(ath9k_tpt_blink));
954#endif
955
Sujith285f2dd2010-01-08 10:36:07 +0530956 /* Register with mac80211 */
957 error = ieee80211_register_hw(hw);
958 if (error)
Felix Fietkaub81950b12012-12-12 13:14:22 +0100959 goto rx_cleanup;
Sujith285f2dd2010-01-08 10:36:07 +0530960
Ben Greeareb272442010-11-29 14:13:22 -0800961 error = ath9k_init_debug(ah);
962 if (error) {
Joe Perches38002762010-12-02 19:12:36 -0800963 ath_err(common, "Unable to create debugfs files\n");
Felix Fietkaub81950b12012-12-12 13:14:22 +0100964 goto unregister;
Ben Greeareb272442010-11-29 14:13:22 -0800965 }
966
Sujith285f2dd2010-01-08 10:36:07 +0530967 /* Handle world regulatory */
968 if (!ath_is_world_regd(reg)) {
969 error = regulatory_hint(hw->wiphy, reg->alpha2);
970 if (error)
Sujith Manoharanaf690092013-05-10 18:41:06 +0530971 goto debug_cleanup;
Sujith285f2dd2010-01-08 10:36:07 +0530972 }
Sujith55624202010-01-08 10:36:02 +0530973
Sujith55624202010-01-08 10:36:02 +0530974 ath_init_leds(sc);
Sujith55624202010-01-08 10:36:02 +0530975 ath_start_rfkill_poll(sc);
976
977 return 0;
978
Sujith Manoharanaf690092013-05-10 18:41:06 +0530979debug_cleanup:
980 ath9k_deinit_debug(sc);
Felix Fietkaub81950b12012-12-12 13:14:22 +0100981unregister:
Sujith285f2dd2010-01-08 10:36:07 +0530982 ieee80211_unregister_hw(hw);
Felix Fietkaub81950b12012-12-12 13:14:22 +0100983rx_cleanup:
Sujith285f2dd2010-01-08 10:36:07 +0530984 ath_rx_cleanup(sc);
Felix Fietkaub81950b12012-12-12 13:14:22 +0100985deinit:
Sujith285f2dd2010-01-08 10:36:07 +0530986 ath9k_deinit_softc(sc);
Sujith55624202010-01-08 10:36:02 +0530987 return error;
988}
989
990/*****************************/
991/* De-Initialization */
992/*****************************/
993
Sujith285f2dd2010-01-08 10:36:07 +0530994static void ath9k_deinit_softc(struct ath_softc *sc)
Sujith55624202010-01-08 10:36:02 +0530995{
Sujith285f2dd2010-01-08 10:36:07 +0530996 int i = 0;
Sujith55624202010-01-08 10:36:02 +0530997
Sujith Manoharanc7dd40c2014-08-22 20:39:30 +0530998 ath9k_deinit_p2p(sc);
Sujith Manoharan59081202012-02-22 12:40:21 +0530999 ath9k_deinit_btcoex(sc);
Mohammed Shafi Shajakhan19686dd2011-11-30 10:41:28 +05301000
Sujith285f2dd2010-01-08 10:36:07 +05301001 for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++)
1002 if (ATH_TXQ_SETUP(sc, i))
1003 ath_tx_cleanupq(sc, &sc->tx.txq[i]);
1004
Felix Fietkaubf3dac52013-11-11 22:23:33 +01001005 del_timer_sync(&sc->sleep_timer);
Sujith285f2dd2010-01-08 10:36:07 +05301006 ath9k_hw_deinit(sc->sc_ah);
Zefir Kurtisi8e92d3f2012-04-03 17:15:50 +02001007 if (sc->dfs_detector != NULL)
1008 sc->dfs_detector->exit(sc->dfs_detector);
Sujith285f2dd2010-01-08 10:36:07 +05301009
Gabor Juhosab5c4f72012-12-10 15:30:28 +01001010 ath9k_eeprom_release(sc);
Sujith55624202010-01-08 10:36:02 +05301011}
1012
Sujith285f2dd2010-01-08 10:36:07 +05301013void ath9k_deinit_device(struct ath_softc *sc)
Sujith55624202010-01-08 10:36:02 +05301014{
1015 struct ieee80211_hw *hw = sc->hw;
Sujith55624202010-01-08 10:36:02 +05301016
1017 ath9k_ps_wakeup(sc);
1018
Sujith55624202010-01-08 10:36:02 +05301019 wiphy_rfkill_stop_polling(sc->hw->wiphy);
Sujith285f2dd2010-01-08 10:36:07 +05301020 ath_deinit_leds(sc);
Sujith55624202010-01-08 10:36:02 +05301021
Rajkumar Manoharanc7c18062011-01-27 18:39:38 +05301022 ath9k_ps_restore(sc);
1023
Sujith Manoharanaf690092013-05-10 18:41:06 +05301024 ath9k_deinit_debug(sc);
Sujith Manoharan661d2582015-01-30 19:05:26 +05301025 ath9k_deinit_wow(hw);
Sujith55624202010-01-08 10:36:02 +05301026 ieee80211_unregister_hw(hw);
1027 ath_rx_cleanup(sc);
Sujith285f2dd2010-01-08 10:36:07 +05301028 ath9k_deinit_softc(sc);
Sujith55624202010-01-08 10:36:02 +05301029}
1030
Sujith55624202010-01-08 10:36:02 +05301031/************************/
1032/* Module Hooks */
1033/************************/
1034
1035static int __init ath9k_init(void)
1036{
1037 int error;
1038
Sujith55624202010-01-08 10:36:02 +05301039 error = ath_pci_init();
1040 if (error < 0) {
Joe Perches516304b2012-03-18 17:30:52 -07001041 pr_err("No PCI devices found, driver not installed\n");
Sujith55624202010-01-08 10:36:02 +05301042 error = -ENODEV;
Sujith Manoharan9e495a22014-02-06 10:22:55 +05301043 goto err_out;
Sujith55624202010-01-08 10:36:02 +05301044 }
1045
1046 error = ath_ahb_init();
1047 if (error < 0) {
1048 error = -ENODEV;
1049 goto err_pci_exit;
1050 }
1051
1052 return 0;
1053
1054 err_pci_exit:
1055 ath_pci_exit();
Sujith55624202010-01-08 10:36:02 +05301056 err_out:
1057 return error;
1058}
1059module_init(ath9k_init);
1060
1061static void __exit ath9k_exit(void)
1062{
Rajkumar Manoharand5847472010-12-20 14:39:51 +05301063 is_ath9k_unloaded = true;
Sujith55624202010-01-08 10:36:02 +05301064 ath_ahb_exit();
1065 ath_pci_exit();
Joe Perches516304b2012-03-18 17:30:52 -07001066 pr_info("%s: Driver unloaded\n", dev_info);
Sujith55624202010-01-08 10:36:02 +05301067}
1068module_exit(ath9k_exit);