2 * Copyright (c) 2008-2011 Atheros Communications Inc.
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.
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.
17 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
19 #include <linux/dma-mapping.h>
20 #include <linux/slab.h>
21 #include <linux/ath9k_platform.h>
22 #include <linux/module.h>
24 #include <linux/of_net.h>
25 #include <linux/relay.h>
26 #include <linux/dmi.h>
27 #include <net/ieee80211_radiotap.h>
31 struct ath9k_eeprom_ctx {
32 struct completion complete;
36 static char *dev_info = "ath9k";
38 MODULE_AUTHOR("Atheros Communications");
39 MODULE_DESCRIPTION("Support for Atheros 802.11n wireless LAN cards.");
40 MODULE_LICENSE("Dual BSD/GPL");
42 static unsigned int ath9k_debug = ATH_DBG_DEFAULT;
43 module_param_named(debug, ath9k_debug, uint, 0);
44 MODULE_PARM_DESC(debug, "Debugging mask");
46 int ath9k_modparam_nohwcrypt;
47 module_param_named(nohwcrypt, ath9k_modparam_nohwcrypt, int, 0444);
48 MODULE_PARM_DESC(nohwcrypt, "Disable hardware encryption");
51 module_param_named(blink, ath9k_led_blink, int, 0444);
52 MODULE_PARM_DESC(blink, "Enable LED blink on activity");
54 static int ath9k_led_active_high = -1;
55 module_param_named(led_active_high, ath9k_led_active_high, int, 0444);
56 MODULE_PARM_DESC(led_active_high, "Invert LED polarity");
58 static int ath9k_btcoex_enable;
59 module_param_named(btcoex_enable, ath9k_btcoex_enable, int, 0444);
60 MODULE_PARM_DESC(btcoex_enable, "Enable wifi-BT coexistence");
62 static int ath9k_bt_ant_diversity;
63 module_param_named(bt_ant_diversity, ath9k_bt_ant_diversity, int, 0444);
64 MODULE_PARM_DESC(bt_ant_diversity, "Enable WLAN/BT RX antenna diversity");
66 static int ath9k_ps_enable;
67 module_param_named(ps_enable, ath9k_ps_enable, int, 0444);
68 MODULE_PARM_DESC(ps_enable, "Enable WLAN PowerSave");
70 #ifdef CONFIG_ATH9K_CHANNEL_CONTEXT
72 int ath9k_use_chanctx;
73 module_param_named(use_chanctx, ath9k_use_chanctx, int, 0444);
74 MODULE_PARM_DESC(use_chanctx, "Enable channel context for concurrency");
76 #endif /* CONFIG_ATH9K_CHANNEL_CONTEXT */
79 module_param_named(use_msi, ath9k_use_msi, int, 0444);
80 MODULE_PARM_DESC(use_msi, "Use MSI instead of INTx if possible");
82 bool is_ath9k_unloaded;
84 #ifdef CONFIG_MAC80211_LEDS
85 static const struct ieee80211_tpt_blink ath9k_tpt_blink[] = {
86 { .throughput = 0 * 1024, .blink_time = 334 },
87 { .throughput = 1 * 1024, .blink_time = 260 },
88 { .throughput = 5 * 1024, .blink_time = 220 },
89 { .throughput = 10 * 1024, .blink_time = 190 },
90 { .throughput = 20 * 1024, .blink_time = 170 },
91 { .throughput = 50 * 1024, .blink_time = 150 },
92 { .throughput = 70 * 1024, .blink_time = 130 },
93 { .throughput = 100 * 1024, .blink_time = 110 },
94 { .throughput = 200 * 1024, .blink_time = 80 },
95 { .throughput = 300 * 1024, .blink_time = 50 },
99 static int __init set_use_msi(const struct dmi_system_id *dmi)
105 static const struct dmi_system_id ath9k_quirks[] __initconst = {
107 .callback = set_use_msi,
108 .ident = "Dell Inspiron 24-3460",
110 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
111 DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 24-3460"),
115 .callback = set_use_msi,
116 .ident = "Dell Vostro 3262",
118 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
119 DMI_MATCH(DMI_PRODUCT_NAME, "Vostro 3262"),
123 .callback = set_use_msi,
124 .ident = "Dell Inspiron 3472",
126 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
127 DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 3472"),
131 .callback = set_use_msi,
132 .ident = "Dell Vostro 15-3572",
134 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
135 DMI_MATCH(DMI_PRODUCT_NAME, "Vostro 15-3572"),
139 .callback = set_use_msi,
140 .ident = "Dell Inspiron 14-3473",
142 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
143 DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 14-3473"),
149 static void ath9k_deinit_softc(struct ath_softc *sc);
151 static void ath9k_op_ps_wakeup(struct ath_common *common)
153 ath9k_ps_wakeup((struct ath_softc *) common->priv);
156 static void ath9k_op_ps_restore(struct ath_common *common)
158 ath9k_ps_restore((struct ath_softc *) common->priv);
161 static const struct ath_ps_ops ath9k_ps_ops = {
162 .wakeup = ath9k_op_ps_wakeup,
163 .restore = ath9k_op_ps_restore,
167 * Read and write, they both share the same lock. We do this to serialize
168 * reads and writes on Atheros 802.11n PCI devices only. This is required
169 * as the FIFO on these devices can only accept sanely 2 requests.
172 static void ath9k_iowrite32(void *hw_priv, u32 val, u32 reg_offset)
174 struct ath_hw *ah = hw_priv;
175 struct ath_common *common = ath9k_hw_common(ah);
176 struct ath_softc *sc = (struct ath_softc *) common->priv;
178 if (NR_CPUS > 1 && ah->config.serialize_regmode == SER_REG_MODE_ON) {
180 spin_lock_irqsave(&sc->sc_serial_rw, flags);
181 iowrite32(val, sc->mem + reg_offset);
182 spin_unlock_irqrestore(&sc->sc_serial_rw, flags);
184 iowrite32(val, sc->mem + reg_offset);
187 static unsigned int ath9k_ioread32(void *hw_priv, u32 reg_offset)
189 struct ath_hw *ah = hw_priv;
190 struct ath_common *common = ath9k_hw_common(ah);
191 struct ath_softc *sc = (struct ath_softc *) common->priv;
194 if (NR_CPUS > 1 && ah->config.serialize_regmode == SER_REG_MODE_ON) {
196 spin_lock_irqsave(&sc->sc_serial_rw, flags);
197 val = ioread32(sc->mem + reg_offset);
198 spin_unlock_irqrestore(&sc->sc_serial_rw, flags);
200 val = ioread32(sc->mem + reg_offset);
204 static void ath9k_multi_ioread32(void *hw_priv, u32 *addr,
209 for (i = 0; i < count; i++)
210 val[i] = ath9k_ioread32(hw_priv, addr[i]);
214 static unsigned int __ath9k_reg_rmw(struct ath_softc *sc, u32 reg_offset,
219 val = ioread32(sc->mem + reg_offset);
222 iowrite32(val, sc->mem + reg_offset);
227 static unsigned int ath9k_reg_rmw(void *hw_priv, u32 reg_offset, u32 set, u32 clr)
229 struct ath_hw *ah = hw_priv;
230 struct ath_common *common = ath9k_hw_common(ah);
231 struct ath_softc *sc = (struct ath_softc *) common->priv;
235 if (NR_CPUS > 1 && ah->config.serialize_regmode == SER_REG_MODE_ON) {
236 spin_lock_irqsave(&sc->sc_serial_rw, flags);
237 val = __ath9k_reg_rmw(sc, reg_offset, set, clr);
238 spin_unlock_irqrestore(&sc->sc_serial_rw, flags);
240 val = __ath9k_reg_rmw(sc, reg_offset, set, clr);
245 /**************************/
247 /**************************/
249 static void ath9k_reg_notifier(struct wiphy *wiphy,
250 struct regulatory_request *request)
252 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
253 struct ath_softc *sc = hw->priv;
254 struct ath_hw *ah = sc->sc_ah;
255 struct ath_regulatory *reg = ath9k_hw_regulatory(ah);
257 ath_reg_notifier_apply(wiphy, request, reg);
259 /* synchronize DFS detector if regulatory domain changed */
260 if (sc->dfs_detector != NULL)
261 sc->dfs_detector->set_dfs_domain(sc->dfs_detector,
262 request->dfs_region);
268 sc->cur_chan->txpower = 2 * ah->curchan->chan->max_power;
270 ath9k_hw_set_txpowerlimit(ah, sc->cur_chan->txpower, false);
271 ath9k_cmn_update_txpow(ah, sc->cur_chan->cur_txpower,
272 sc->cur_chan->txpower,
273 &sc->cur_chan->cur_txpower);
274 ath9k_ps_restore(sc);
278 * This function will allocate both the DMA descriptor structure, and the
279 * buffers it contains. These are used to contain the descriptors used
282 int ath_descdma_setup(struct ath_softc *sc, struct ath_descdma *dd,
283 struct list_head *head, const char *name,
284 int nbuf, int ndesc, bool is_tx)
286 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
288 int i, bsize, desc_len;
290 ath_dbg(common, CONFIG, "%s DMA: %u buffers %u desc/buf\n",
293 INIT_LIST_HEAD(head);
296 desc_len = sc->sc_ah->caps.tx_desc_len;
298 desc_len = sizeof(struct ath_desc);
300 /* ath_desc must be a multiple of DWORDs */
301 if ((desc_len % 4) != 0) {
302 ath_err(common, "ath_desc not DWORD aligned\n");
303 BUG_ON((desc_len % 4) != 0);
307 dd->dd_desc_len = desc_len * nbuf * ndesc;
310 * Need additional DMA memory because we can't use
311 * descriptors that cross the 4K page boundary. Assume
312 * one skipped descriptor per 4K page.
314 if (!(sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_4KB_SPLITTRANS)) {
316 ATH_DESC_4KB_BOUND_NUM_SKIPPED(dd->dd_desc_len);
319 while (ndesc_skipped) {
320 dma_len = ndesc_skipped * desc_len;
321 dd->dd_desc_len += dma_len;
323 ndesc_skipped = ATH_DESC_4KB_BOUND_NUM_SKIPPED(dma_len);
327 /* allocate descriptors */
328 dd->dd_desc = dmam_alloc_coherent(sc->dev, dd->dd_desc_len,
329 &dd->dd_desc_paddr, GFP_KERNEL);
334 ath_dbg(common, CONFIG, "%s DMA map: %p (%u) -> %llx (%u)\n",
335 name, ds, (u32) dd->dd_desc_len,
336 ito64(dd->dd_desc_paddr), /*XXX*/(u32) dd->dd_desc_len);
338 /* allocate buffers */
342 bsize = sizeof(struct ath_buf) * nbuf;
343 bf = devm_kzalloc(sc->dev, bsize, GFP_KERNEL);
347 for (i = 0; i < nbuf; i++, bf++, ds += (desc_len * ndesc)) {
349 bf->bf_daddr = DS2PHYS(dd, ds);
351 if (!(sc->sc_ah->caps.hw_caps &
352 ATH9K_HW_CAP_4KB_SPLITTRANS)) {
354 * Skip descriptor addresses which can cause 4KB
355 * boundary crossing (addr + length) with a 32 dword
358 while (ATH_DESC_4KB_BOUND_CHECK(bf->bf_daddr)) {
359 BUG_ON((caddr_t) bf->bf_desc >=
360 ((caddr_t) dd->dd_desc +
363 ds += (desc_len * ndesc);
365 bf->bf_daddr = DS2PHYS(dd, ds);
368 list_add_tail(&bf->list, head);
371 struct ath_rxbuf *bf;
373 bsize = sizeof(struct ath_rxbuf) * nbuf;
374 bf = devm_kzalloc(sc->dev, bsize, GFP_KERNEL);
378 for (i = 0; i < nbuf; i++, bf++, ds += (desc_len * ndesc)) {
380 bf->bf_daddr = DS2PHYS(dd, ds);
382 if (!(sc->sc_ah->caps.hw_caps &
383 ATH9K_HW_CAP_4KB_SPLITTRANS)) {
385 * Skip descriptor addresses which can cause 4KB
386 * boundary crossing (addr + length) with a 32 dword
389 while (ATH_DESC_4KB_BOUND_CHECK(bf->bf_daddr)) {
390 BUG_ON((caddr_t) bf->bf_desc >=
391 ((caddr_t) dd->dd_desc +
394 ds += (desc_len * ndesc);
396 bf->bf_daddr = DS2PHYS(dd, ds);
399 list_add_tail(&bf->list, head);
405 static int ath9k_init_queues(struct ath_softc *sc)
409 sc->beacon.beaconq = ath9k_hw_beaconq_setup(sc->sc_ah);
410 sc->beacon.cabq = ath_txq_setup(sc, ATH9K_TX_QUEUE_CAB, 0);
413 sc->tx.uapsdq = ath_txq_setup(sc, ATH9K_TX_QUEUE_UAPSD, 0);
415 for (i = 0; i < IEEE80211_NUM_ACS; i++) {
416 sc->tx.txq_map[i] = ath_txq_setup(sc, ATH9K_TX_QUEUE_DATA, i);
417 sc->tx.txq_map[i]->mac80211_qnum = i;
422 static void ath9k_init_misc(struct ath_softc *sc)
424 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
427 timer_setup(&common->ani.timer, ath_ani_calibrate, 0);
429 common->last_rssi = ATH_RSSI_DUMMY_MARKER;
430 eth_broadcast_addr(common->bssidmask);
431 sc->beacon.slottime = 9;
433 for (i = 0; i < ARRAY_SIZE(sc->beacon.bslot); i++)
434 sc->beacon.bslot[i] = NULL;
436 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_ANT_DIV_COMB)
437 sc->ant_comb.count = ATH_ANT_DIV_COMB_INIT_COUNT;
439 sc->spec_priv.ah = sc->sc_ah;
440 sc->spec_priv.spec_config.enabled = 0;
441 sc->spec_priv.spec_config.short_repeat = true;
442 sc->spec_priv.spec_config.count = 8;
443 sc->spec_priv.spec_config.endless = false;
444 sc->spec_priv.spec_config.period = 0xFF;
445 sc->spec_priv.spec_config.fft_period = 0xF;
448 static void ath9k_init_pcoem_platform(struct ath_softc *sc)
450 struct ath_hw *ah = sc->sc_ah;
451 struct ath9k_hw_capabilities *pCap = &ah->caps;
452 struct ath_common *common = ath9k_hw_common(ah);
454 if (!IS_ENABLED(CONFIG_ATH9K_PCOEM))
457 if (common->bus_ops->ath_bus_type != ATH_PCI)
460 if (sc->driver_data & (ATH9K_PCI_CUS198 |
462 ah->config.xlna_gpio = 9;
463 ah->config.xatten_margin_cfg = true;
464 ah->config.alt_mingainidx = true;
465 ah->config.ant_ctrl_comm2g_switch_enable = 0x000BBB88;
466 sc->ant_comb.low_rssi_thresh = 20;
467 sc->ant_comb.fast_div_bias = 3;
469 ath_info(common, "Set parameters for %s\n",
470 (sc->driver_data & ATH9K_PCI_CUS198) ?
471 "CUS198" : "CUS230");
474 if (sc->driver_data & ATH9K_PCI_CUS217)
475 ath_info(common, "CUS217 card detected\n");
477 if (sc->driver_data & ATH9K_PCI_CUS252)
478 ath_info(common, "CUS252 card detected\n");
480 if (sc->driver_data & ATH9K_PCI_AR9565_1ANT)
481 ath_info(common, "WB335 1-ANT card detected\n");
483 if (sc->driver_data & ATH9K_PCI_AR9565_2ANT)
484 ath_info(common, "WB335 2-ANT card detected\n");
486 if (sc->driver_data & ATH9K_PCI_KILLER)
487 ath_info(common, "Killer Wireless card detected\n");
490 * Some WB335 cards do not support antenna diversity. Since
491 * we use a hardcoded value for AR9565 instead of using the
492 * EEPROM/OTP data, remove the combining feature from
493 * the HW capabilities bitmap.
495 if (sc->driver_data & (ATH9K_PCI_AR9565_1ANT | ATH9K_PCI_AR9565_2ANT)) {
496 if (!(sc->driver_data & ATH9K_PCI_BT_ANT_DIV))
497 pCap->hw_caps &= ~ATH9K_HW_CAP_ANT_DIV_COMB;
500 if (sc->driver_data & ATH9K_PCI_BT_ANT_DIV) {
501 pCap->hw_caps |= ATH9K_HW_CAP_BT_ANT_DIV;
502 ath_info(common, "Set BT/WLAN RX diversity capability\n");
505 if (sc->driver_data & ATH9K_PCI_D3_L1_WAR) {
506 ah->config.pcie_waen = 0x0040473b;
507 ath_info(common, "Enable WAR for ASPM D3/L1\n");
511 * The default value of pll_pwrsave is 1.
512 * For certain AR9485 cards, it is set to 0.
513 * For AR9462, AR9565 it's set to 7.
515 ah->config.pll_pwrsave = 1;
517 if (sc->driver_data & ATH9K_PCI_NO_PLL_PWRSAVE) {
518 ah->config.pll_pwrsave = 0;
519 ath_info(common, "Disable PLL PowerSave\n");
522 if (sc->driver_data & ATH9K_PCI_LED_ACT_HI)
523 ah->config.led_active_high = true;
526 static void ath9k_eeprom_request_cb(const struct firmware *eeprom_blob,
529 struct ath9k_eeprom_ctx *ec = ctx;
532 ec->ah->eeprom_blob = eeprom_blob;
534 complete(&ec->complete);
537 static int ath9k_eeprom_request(struct ath_softc *sc, const char *name)
539 struct ath9k_eeprom_ctx ec;
540 struct ath_hw *ah = sc->sc_ah;
543 /* try to load the EEPROM content asynchronously */
544 init_completion(&ec.complete);
547 err = request_firmware_nowait(THIS_MODULE, 1, name, sc->dev, GFP_KERNEL,
548 &ec, ath9k_eeprom_request_cb);
550 ath_err(ath9k_hw_common(ah),
551 "EEPROM request failed\n");
555 wait_for_completion(&ec.complete);
557 if (!ah->eeprom_blob) {
558 ath_err(ath9k_hw_common(ah),
559 "Unable to load EEPROM file %s\n", name);
566 static void ath9k_eeprom_release(struct ath_softc *sc)
568 release_firmware(sc->sc_ah->eeprom_blob);
571 static int ath9k_init_platform(struct ath_softc *sc)
573 struct ath9k_platform_data *pdata = sc->dev->platform_data;
574 struct ath_hw *ah = sc->sc_ah;
575 struct ath_common *common = ath9k_hw_common(ah);
581 if (!pdata->use_eeprom) {
582 ah->ah_flags &= ~AH_USE_EEPROM;
583 ah->gpio_mask = pdata->gpio_mask;
584 ah->gpio_val = pdata->gpio_val;
585 ah->led_pin = pdata->led_pin;
586 ah->is_clk_25mhz = pdata->is_clk_25mhz;
587 ah->get_mac_revision = pdata->get_mac_revision;
588 ah->external_reset = pdata->external_reset;
589 ah->disable_2ghz = pdata->disable_2ghz;
590 ah->disable_5ghz = pdata->disable_5ghz;
592 if (!pdata->endian_check)
593 ah->ah_flags |= AH_NO_EEP_SWAP;
596 if (pdata->eeprom_name) {
597 ret = ath9k_eeprom_request(sc, pdata->eeprom_name);
602 if (pdata->led_active_high)
603 ah->config.led_active_high = true;
605 if (pdata->tx_gain_buffalo)
606 ah->config.tx_gain_buffalo = true;
609 ether_addr_copy(common->macaddr, pdata->macaddr);
614 static int ath9k_of_init(struct ath_softc *sc)
616 struct device_node *np = sc->dev->of_node;
617 struct ath_hw *ah = sc->sc_ah;
618 struct ath_common *common = ath9k_hw_common(ah);
619 enum ath_bus_type bus_type = common->bus_ops->ath_bus_type;
621 char eeprom_name[100];
624 if (!of_device_is_available(np))
627 ath_dbg(common, CONFIG, "parsing configuration from OF node\n");
629 if (of_property_read_bool(np, "qca,no-eeprom")) {
630 /* ath9k-eeprom-<bus>-<id>.bin */
631 scnprintf(eeprom_name, sizeof(eeprom_name),
632 "ath9k-eeprom-%s-%s.bin",
633 ath_bus_type_to_string(bus_type), dev_name(ah->dev));
635 ret = ath9k_eeprom_request(sc, eeprom_name);
639 ah->ah_flags &= ~AH_USE_EEPROM;
640 ah->ah_flags |= AH_NO_EEP_SWAP;
643 mac = of_get_mac_address(np);
645 ether_addr_copy(common->macaddr, mac);
650 static int ath9k_init_softc(u16 devid, struct ath_softc *sc,
651 const struct ath_bus_ops *bus_ops)
653 struct ath_hw *ah = NULL;
654 struct ath9k_hw_capabilities *pCap;
655 struct ath_common *common;
659 ah = devm_kzalloc(sc->dev, sizeof(struct ath_hw), GFP_KERNEL);
665 ah->hw_version.devid = devid;
666 ah->ah_flags |= AH_USE_EEPROM;
668 ah->reg_ops.read = ath9k_ioread32;
669 ah->reg_ops.multi_read = ath9k_multi_ioread32;
670 ah->reg_ops.write = ath9k_iowrite32;
671 ah->reg_ops.rmw = ath9k_reg_rmw;
674 common = ath9k_hw_common(ah);
676 /* Will be cleared in ath9k_start() */
677 set_bit(ATH_OP_INVALID, &common->op_flags);
680 sc->dfs_detector = dfs_pattern_detector_init(common, NL80211_DFS_UNSET);
681 sc->tx99_power = MAX_RATE_POWER + 1;
682 init_waitqueue_head(&sc->tx_wait);
683 sc->cur_chan = &sc->chanctx[0];
684 if (!ath9k_is_chanctx_enabled())
685 sc->cur_chan->hw_queue_base = 0;
687 common->ops = &ah->reg_ops;
688 common->bus_ops = bus_ops;
689 common->ps_ops = &ath9k_ps_ops;
693 common->debug_mask = ath9k_debug;
694 common->btcoex_enabled = ath9k_btcoex_enable == 1;
695 common->disable_ani = false;
700 ath9k_init_pcoem_platform(sc);
702 ret = ath9k_init_platform(sc);
706 ret = ath9k_of_init(sc);
710 if (ath9k_led_active_high != -1)
711 ah->config.led_active_high = ath9k_led_active_high == 1;
714 * Enable WLAN/BT RX Antenna diversity only when:
716 * - BTCOEX is disabled.
717 * - the user manually requests the feature.
718 * - the HW cap is set using the platform data.
720 if (!common->btcoex_enabled && ath9k_bt_ant_diversity &&
721 (pCap->hw_caps & ATH9K_HW_CAP_BT_ANT_DIV))
722 common->bt_ant_diversity = 1;
724 spin_lock_init(&common->cc_lock);
725 spin_lock_init(&sc->intr_lock);
726 spin_lock_init(&sc->sc_serial_rw);
727 spin_lock_init(&sc->sc_pm_lock);
728 spin_lock_init(&sc->chan_lock);
729 mutex_init(&sc->mutex);
730 tasklet_setup(&sc->intr_tq, ath9k_tasklet);
731 tasklet_setup(&sc->bcon_tasklet, ath9k_beacon_tasklet);
733 timer_setup(&sc->sleep_timer, ath_ps_full_sleep, 0);
734 INIT_WORK(&sc->hw_reset_work, ath_reset_work);
735 INIT_WORK(&sc->paprd_work, ath_paprd_calibrate);
736 INIT_DELAYED_WORK(&sc->hw_pll_work, ath_hw_pll_work);
737 INIT_DELAYED_WORK(&sc->hw_check_work, ath_hw_check_work);
739 ath9k_init_channel_context(sc);
742 * Cache line size is used to size and align various
743 * structures used to communicate with the hardware.
745 ath_read_cachesize(common, &csz);
746 common->cachelsz = csz << 2; /* convert to bytes */
748 /* Initializes the hardware for all supported chipsets */
749 ret = ath9k_hw_init(ah);
753 ret = ath9k_init_queues(sc);
757 ret = ath9k_init_btcoex(sc);
761 ret = ath9k_cmn_init_channels_rates(common);
765 ret = ath9k_init_p2p(sc);
769 ath9k_cmn_init_crypto(sc->sc_ah);
771 ath_chanctx_init(sc);
772 ath9k_offchannel_init(sc);
774 if (common->bus_ops->aspm_init)
775 common->bus_ops->aspm_init(common);
780 for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++)
781 if (ATH_TXQ_SETUP(sc, i))
782 ath_tx_cleanupq(sc, &sc->tx.txq[i]);
786 ath9k_eeprom_release(sc);
787 dev_kfree_skb_any(sc->tx99_skb);
791 static void ath9k_init_band_txpower(struct ath_softc *sc, int band)
793 struct ieee80211_supported_band *sband;
794 struct ieee80211_channel *chan;
795 struct ath_hw *ah = sc->sc_ah;
796 struct ath_common *common = ath9k_hw_common(ah);
797 struct cfg80211_chan_def chandef;
800 sband = &common->sbands[band];
801 for (i = 0; i < sband->n_channels; i++) {
802 chan = &sband->channels[i];
803 ah->curchan = &ah->channels[chan->hw_value];
804 cfg80211_chandef_create(&chandef, chan, NL80211_CHAN_HT20);
805 ath9k_cmn_get_channel(sc->hw, ah, &chandef);
806 ath9k_hw_set_txpowerlimit(ah, MAX_COMBINED_POWER, true);
810 static void ath9k_init_txpower_limits(struct ath_softc *sc)
812 struct ath_hw *ah = sc->sc_ah;
813 struct ath9k_channel *curchan = ah->curchan;
815 if (ah->caps.hw_caps & ATH9K_HW_CAP_2GHZ)
816 ath9k_init_band_txpower(sc, NL80211_BAND_2GHZ);
817 if (ah->caps.hw_caps & ATH9K_HW_CAP_5GHZ)
818 ath9k_init_band_txpower(sc, NL80211_BAND_5GHZ);
820 ah->curchan = curchan;
823 static const struct ieee80211_iface_limit if_limits[] = {
824 { .max = 2048, .types = BIT(NL80211_IFTYPE_STATION) },
826 #ifdef CONFIG_MAC80211_MESH
827 BIT(NL80211_IFTYPE_MESH_POINT) |
829 BIT(NL80211_IFTYPE_AP) },
830 { .max = 1, .types = BIT(NL80211_IFTYPE_P2P_CLIENT) |
831 BIT(NL80211_IFTYPE_P2P_GO) },
834 #ifdef CONFIG_ATH9K_CHANNEL_CONTEXT
836 static const struct ieee80211_iface_limit if_limits_multi[] = {
837 { .max = 2, .types = BIT(NL80211_IFTYPE_STATION) |
838 BIT(NL80211_IFTYPE_AP) |
839 BIT(NL80211_IFTYPE_P2P_CLIENT) |
840 BIT(NL80211_IFTYPE_P2P_GO) },
841 { .max = 1, .types = BIT(NL80211_IFTYPE_ADHOC) },
842 { .max = 1, .types = BIT(NL80211_IFTYPE_P2P_DEVICE) },
845 static const struct ieee80211_iface_combination if_comb_multi[] = {
847 .limits = if_limits_multi,
848 .n_limits = ARRAY_SIZE(if_limits_multi),
850 .num_different_channels = 2,
851 .beacon_int_infra_match = true,
855 #endif /* CONFIG_ATH9K_CHANNEL_CONTEXT */
857 static const struct ieee80211_iface_combination if_comb[] = {
860 .n_limits = ARRAY_SIZE(if_limits),
861 .max_interfaces = 2048,
862 .num_different_channels = 1,
863 .beacon_int_infra_match = true,
864 #ifdef CONFIG_ATH9K_DFS_CERTIFIED
865 .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
866 BIT(NL80211_CHAN_WIDTH_20) |
867 BIT(NL80211_CHAN_WIDTH_40),
872 #ifdef CONFIG_ATH9K_CHANNEL_CONTEXT
873 static void ath9k_set_mcc_capab(struct ath_softc *sc, struct ieee80211_hw *hw)
875 struct ath_hw *ah = sc->sc_ah;
876 struct ath_common *common = ath9k_hw_common(ah);
878 if (!ath9k_is_chanctx_enabled())
881 ieee80211_hw_set(hw, QUEUE_CONTROL);
882 hw->queues = ATH9K_NUM_TX_QUEUES;
883 hw->offchannel_tx_hw_queue = hw->queues - 1;
884 hw->wiphy->iface_combinations = if_comb_multi;
885 hw->wiphy->n_iface_combinations = ARRAY_SIZE(if_comb_multi);
886 hw->wiphy->max_scan_ssids = 255;
887 hw->wiphy->max_scan_ie_len = IEEE80211_MAX_DATA_LEN;
888 hw->wiphy->max_remain_on_channel_duration = 10000;
889 hw->chanctx_data_size = sizeof(void *);
890 hw->extra_beacon_tailroom =
891 sizeof(struct ieee80211_p2p_noa_attr) + 9;
893 ath_dbg(common, CHAN_CTX, "Use channel contexts\n");
895 #endif /* CONFIG_ATH9K_CHANNEL_CONTEXT */
897 static void ath9k_set_hw_capab(struct ath_softc *sc, struct ieee80211_hw *hw)
899 struct ath_hw *ah = sc->sc_ah;
900 struct ath_common *common = ath9k_hw_common(ah);
902 ieee80211_hw_set(hw, SUPPORTS_HT_CCK_RATES);
903 ieee80211_hw_set(hw, SUPPORTS_RC_TABLE);
904 ieee80211_hw_set(hw, REPORTS_TX_ACK_STATUS);
905 ieee80211_hw_set(hw, SPECTRUM_MGMT);
906 ieee80211_hw_set(hw, PS_NULLFUNC_STACK);
907 ieee80211_hw_set(hw, SIGNAL_DBM);
908 ieee80211_hw_set(hw, RX_INCLUDES_FCS);
909 ieee80211_hw_set(hw, HOST_BROADCAST_PS_BUFFERING);
910 ieee80211_hw_set(hw, SUPPORT_FAST_XMIT);
911 ieee80211_hw_set(hw, SUPPORTS_CLONED_SKBS);
914 ieee80211_hw_set(hw, SUPPORTS_PS);
916 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_HT) {
917 ieee80211_hw_set(hw, AMPDU_AGGREGATION);
919 if (AR_SREV_9280_20_OR_LATER(ah))
920 hw->radiotap_mcs_details |=
921 IEEE80211_RADIOTAP_MCS_HAVE_STBC;
924 if (AR_SREV_9160_10_OR_LATER(sc->sc_ah) || ath9k_modparam_nohwcrypt)
925 ieee80211_hw_set(hw, MFP_CAPABLE);
927 hw->wiphy->features |= NL80211_FEATURE_ACTIVE_MONITOR |
928 NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE |
929 NL80211_FEATURE_P2P_GO_CTWIN;
931 if (!IS_ENABLED(CONFIG_ATH9K_TX99)) {
932 hw->wiphy->interface_modes =
933 BIT(NL80211_IFTYPE_P2P_GO) |
934 BIT(NL80211_IFTYPE_P2P_CLIENT) |
935 BIT(NL80211_IFTYPE_AP) |
936 BIT(NL80211_IFTYPE_STATION) |
937 BIT(NL80211_IFTYPE_ADHOC) |
938 BIT(NL80211_IFTYPE_MESH_POINT) |
939 BIT(NL80211_IFTYPE_OCB);
941 if (ath9k_is_chanctx_enabled())
942 hw->wiphy->interface_modes |=
943 BIT(NL80211_IFTYPE_P2P_DEVICE);
945 hw->wiphy->iface_combinations = if_comb;
946 hw->wiphy->n_iface_combinations = ARRAY_SIZE(if_comb);
949 hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
951 hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
952 hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS;
953 hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
954 hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_5_10_MHZ;
955 hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
956 hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
960 hw->max_listen_interval = 10;
961 hw->max_rate_tries = 10;
962 hw->sta_data_size = sizeof(struct ath_node);
963 hw->vif_data_size = sizeof(struct ath_vif);
964 hw->txq_data_size = sizeof(struct ath_atx_tid);
965 hw->extra_tx_headroom = 4;
967 hw->wiphy->available_antennas_rx = BIT(ah->caps.max_rxchains) - 1;
968 hw->wiphy->available_antennas_tx = BIT(ah->caps.max_txchains) - 1;
970 /* single chain devices with rx diversity */
971 if (ah->caps.hw_caps & ATH9K_HW_CAP_ANT_DIV_COMB)
972 hw->wiphy->available_antennas_rx = BIT(0) | BIT(1);
974 sc->ant_rx = hw->wiphy->available_antennas_rx;
975 sc->ant_tx = hw->wiphy->available_antennas_tx;
977 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_2GHZ)
978 hw->wiphy->bands[NL80211_BAND_2GHZ] =
979 &common->sbands[NL80211_BAND_2GHZ];
980 if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_5GHZ)
981 hw->wiphy->bands[NL80211_BAND_5GHZ] =
982 &common->sbands[NL80211_BAND_5GHZ];
984 #ifdef CONFIG_ATH9K_CHANNEL_CONTEXT
985 ath9k_set_mcc_capab(sc, hw);
988 ath9k_cmn_reload_chainmask(ah);
990 SET_IEEE80211_PERM_ADDR(hw, common->macaddr);
992 wiphy_ext_feature_set(hw->wiphy, NL80211_EXT_FEATURE_CQM_RSSI_LIST);
993 wiphy_ext_feature_set(hw->wiphy, NL80211_EXT_FEATURE_AIRTIME_FAIRNESS);
994 wiphy_ext_feature_set(hw->wiphy,
995 NL80211_EXT_FEATURE_MULTICAST_REGISTRATIONS);
996 wiphy_ext_feature_set(hw->wiphy, NL80211_EXT_FEATURE_CAN_REPLACE_PTK0);
999 int ath9k_init_device(u16 devid, struct ath_softc *sc,
1000 const struct ath_bus_ops *bus_ops)
1002 struct ieee80211_hw *hw = sc->hw;
1003 struct ath_common *common;
1006 struct ath_regulatory *reg;
1008 /* Bring up device */
1009 error = ath9k_init_softc(devid, sc, bus_ops);
1014 common = ath9k_hw_common(ah);
1015 ath9k_set_hw_capab(sc, hw);
1017 /* Initialize regulatory */
1018 error = ath_regd_init(&common->regulatory, sc->hw->wiphy,
1019 ath9k_reg_notifier);
1023 reg = &common->regulatory;
1026 error = ath_tx_init(sc, ATH_TXBUF);
1031 error = ath_rx_init(sc, ATH_RXBUF);
1035 ath9k_init_txpower_limits(sc);
1037 #ifdef CONFIG_MAC80211_LEDS
1038 /* must be initialized before ieee80211_register_hw */
1039 sc->led_cdev.default_trigger = ieee80211_create_tpt_led_trigger(sc->hw,
1040 IEEE80211_TPT_LEDTRIG_FL_RADIO, ath9k_tpt_blink,
1041 ARRAY_SIZE(ath9k_tpt_blink));
1044 /* Register with mac80211 */
1045 error = ieee80211_register_hw(hw);
1049 error = ath9k_init_debug(ah);
1051 ath_err(common, "Unable to create debugfs files\n");
1055 /* Handle world regulatory */
1056 if (!ath_is_world_regd(reg)) {
1057 error = regulatory_hint(hw->wiphy, reg->alpha2);
1063 ath_start_rfkill_poll(sc);
1068 ath9k_deinit_debug(sc);
1070 ieee80211_unregister_hw(hw);
1074 ath9k_deinit_softc(sc);
1078 /*****************************/
1079 /* De-Initialization */
1080 /*****************************/
1082 static void ath9k_deinit_softc(struct ath_softc *sc)
1086 ath9k_deinit_p2p(sc);
1087 ath9k_deinit_btcoex(sc);
1089 for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++)
1090 if (ATH_TXQ_SETUP(sc, i))
1091 ath_tx_cleanupq(sc, &sc->tx.txq[i]);
1093 del_timer_sync(&sc->sleep_timer);
1094 ath9k_hw_deinit(sc->sc_ah);
1095 if (sc->dfs_detector != NULL)
1096 sc->dfs_detector->exit(sc->dfs_detector);
1098 ath9k_eeprom_release(sc);
1101 void ath9k_deinit_device(struct ath_softc *sc)
1103 struct ieee80211_hw *hw = sc->hw;
1105 ath9k_ps_wakeup(sc);
1107 wiphy_rfkill_stop_polling(sc->hw->wiphy);
1108 ath_deinit_leds(sc);
1110 ath9k_ps_restore(sc);
1112 ath9k_deinit_debug(sc);
1113 ath9k_deinit_wow(hw);
1114 ieee80211_unregister_hw(hw);
1116 ath9k_deinit_softc(sc);
1119 /************************/
1121 /************************/
1123 static int __init ath9k_init(void)
1127 error = ath_pci_init();
1129 pr_err("No PCI devices found, driver not installed\n");
1134 error = ath_ahb_init();
1140 dmi_check_system(ath9k_quirks);
1149 module_init(ath9k_init);
1151 static void __exit ath9k_exit(void)
1153 is_ath9k_unloaded = true;
1156 pr_info("%s: Driver unloaded\n", dev_info);
1158 module_exit(ath9k_exit);