Sujith | 5562420 | 2010-01-08 10:36:02 +0530 | [diff] [blame] | 1 | /* |
Sujith Manoharan | 5b68138 | 2011-05-17 13:36:18 +0530 | [diff] [blame] | 2 | * Copyright (c) 2008-2011 Atheros Communications Inc. |
Sujith | 5562420 | 2010-01-08 10:36:02 +0530 | [diff] [blame] | 3 | * |
| 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 Perches | 516304b | 2012-03-18 17:30:52 -0700 | [diff] [blame] | 17 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 18 | |
Alexey Dobriyan | b7f080c | 2011-06-16 11:01:34 +0000 | [diff] [blame] | 19 | #include <linux/dma-mapping.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 20 | #include <linux/slab.h> |
Felix Fietkau | 6fb1b1e | 2011-03-19 13:55:39 +0100 | [diff] [blame] | 21 | #include <linux/ath9k_platform.h> |
Paul Gortmaker | 9d9779e | 2011-07-03 15:21:01 -0400 | [diff] [blame] | 22 | #include <linux/module.h> |
Martin Blumenstingl | 138b412 | 2016-10-16 22:59:07 +0200 | [diff] [blame] | 23 | #include <linux/of.h> |
| 24 | #include <linux/of_net.h> |
Simon Wunderlich | e93d083 | 2013-01-08 14:48:58 +0100 | [diff] [blame] | 25 | #include <linux/relay.h> |
Oleksij Rempel | b0a1ae9 | 2013-05-24 20:30:59 +0200 | [diff] [blame] | 26 | #include <net/ieee80211_radiotap.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 27 | |
Sujith | 5562420 | 2010-01-08 10:36:02 +0530 | [diff] [blame] | 28 | #include "ath9k.h" |
| 29 | |
Gabor Juhos | ab5c4f7 | 2012-12-10 15:30:28 +0100 | [diff] [blame] | 30 | struct ath9k_eeprom_ctx { |
| 31 | struct completion complete; |
| 32 | struct ath_hw *ah; |
| 33 | }; |
| 34 | |
Sujith | 5562420 | 2010-01-08 10:36:02 +0530 | [diff] [blame] | 35 | static char *dev_info = "ath9k"; |
| 36 | |
| 37 | MODULE_AUTHOR("Atheros Communications"); |
| 38 | MODULE_DESCRIPTION("Support for Atheros 802.11n wireless LAN cards."); |
| 39 | MODULE_SUPPORTED_DEVICE("Atheros 802.11n WLAN cards"); |
| 40 | MODULE_LICENSE("Dual BSD/GPL"); |
| 41 | |
| 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"); |
| 45 | |
John W. Linville | 3e6109c | 2011-01-05 09:39:17 -0500 | [diff] [blame] | 46 | int ath9k_modparam_nohwcrypt; |
| 47 | module_param_named(nohwcrypt, ath9k_modparam_nohwcrypt, int, 0444); |
Sujith | 5562420 | 2010-01-08 10:36:02 +0530 | [diff] [blame] | 48 | MODULE_PARM_DESC(nohwcrypt, "Disable hardware encryption"); |
| 49 | |
Hong Xu | 0c8a1e4 | 2015-01-24 03:34:03 -0800 | [diff] [blame] | 50 | int ath9k_led_blink; |
| 51 | module_param_named(blink, ath9k_led_blink, int, 0444); |
Vivek Natarajan | 9a75c2f | 2010-06-22 11:52:37 +0530 | [diff] [blame] | 52 | MODULE_PARM_DESC(blink, "Enable LED blink on activity"); |
| 53 | |
Vittorio Gambaletta (VittGam) | cd84042 | 2016-04-11 04:48:54 +0200 | [diff] [blame] | 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"); |
| 57 | |
Vasanthakumar Thiagarajan | 8f5dcb1 | 2010-11-26 06:10:06 -0800 | [diff] [blame] | 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"); |
| 61 | |
Sujith Manoharan | 6308130 | 2013-08-04 14:21:55 +0530 | [diff] [blame] | 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"); |
Sujith Manoharan | e09f2dc | 2012-09-16 08:06:56 +0530 | [diff] [blame] | 65 | |
Sujith Manoharan | 8298383 | 2014-02-04 08:37:53 +0530 | [diff] [blame] | 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"); |
| 69 | |
Sujith Manoharan | 499afac | 2014-08-22 20:39:31 +0530 | [diff] [blame] | 70 | #ifdef CONFIG_ATH9K_CHANNEL_CONTEXT |
| 71 | |
Felix Fietkau | 78b2194 | 2014-06-11 16:17:55 +0530 | [diff] [blame] | 72 | int ath9k_use_chanctx; |
Rajkumar Manoharan | 71a5f88 | 2014-05-29 15:11:09 +0530 | [diff] [blame] | 73 | module_param_named(use_chanctx, ath9k_use_chanctx, int, 0444); |
| 74 | MODULE_PARM_DESC(use_chanctx, "Enable channel context for concurrency"); |
| 75 | |
Sujith Manoharan | 499afac | 2014-08-22 20:39:31 +0530 | [diff] [blame] | 76 | #endif /* CONFIG_ATH9K_CHANNEL_CONTEXT */ |
| 77 | |
Rajkumar Manoharan | d584747 | 2010-12-20 14:39:51 +0530 | [diff] [blame] | 78 | bool is_ath9k_unloaded; |
Sujith | 5562420 | 2010-01-08 10:36:02 +0530 | [diff] [blame] | 79 | |
Felix Fietkau | 0cf55c2 | 2011-02-27 22:26:40 +0100 | [diff] [blame] | 80 | #ifdef CONFIG_MAC80211_LEDS |
| 81 | static const struct ieee80211_tpt_blink ath9k_tpt_blink[] = { |
| 82 | { .throughput = 0 * 1024, .blink_time = 334 }, |
| 83 | { .throughput = 1 * 1024, .blink_time = 260 }, |
| 84 | { .throughput = 5 * 1024, .blink_time = 220 }, |
| 85 | { .throughput = 10 * 1024, .blink_time = 190 }, |
| 86 | { .throughput = 20 * 1024, .blink_time = 170 }, |
| 87 | { .throughput = 50 * 1024, .blink_time = 150 }, |
| 88 | { .throughput = 70 * 1024, .blink_time = 130 }, |
| 89 | { .throughput = 100 * 1024, .blink_time = 110 }, |
| 90 | { .throughput = 200 * 1024, .blink_time = 80 }, |
| 91 | { .throughput = 300 * 1024, .blink_time = 50 }, |
| 92 | }; |
| 93 | #endif |
| 94 | |
Sujith | 285f2dd | 2010-01-08 10:36:07 +0530 | [diff] [blame] | 95 | static void ath9k_deinit_softc(struct ath_softc *sc); |
Sujith | 5562420 | 2010-01-08 10:36:02 +0530 | [diff] [blame] | 96 | |
kbuild test robot | d81f9a0 | 2014-11-12 06:19:48 +0800 | [diff] [blame] | 97 | static void ath9k_op_ps_wakeup(struct ath_common *common) |
Oleksij Rempel | 99d2217 | 2014-11-06 08:53:25 +0100 | [diff] [blame] | 98 | { |
| 99 | ath9k_ps_wakeup((struct ath_softc *) common->priv); |
| 100 | } |
| 101 | |
kbuild test robot | d81f9a0 | 2014-11-12 06:19:48 +0800 | [diff] [blame] | 102 | static void ath9k_op_ps_restore(struct ath_common *common) |
Oleksij Rempel | 99d2217 | 2014-11-06 08:53:25 +0100 | [diff] [blame] | 103 | { |
| 104 | ath9k_ps_restore((struct ath_softc *) common->priv); |
| 105 | } |
| 106 | |
kbuild test robot | d81f9a0 | 2014-11-12 06:19:48 +0800 | [diff] [blame] | 107 | static struct ath_ps_ops ath9k_ps_ops = { |
Oleksij Rempel | 99d2217 | 2014-11-06 08:53:25 +0100 | [diff] [blame] | 108 | .wakeup = ath9k_op_ps_wakeup, |
| 109 | .restore = ath9k_op_ps_restore, |
| 110 | }; |
| 111 | |
Sujith | 5562420 | 2010-01-08 10:36:02 +0530 | [diff] [blame] | 112 | /* |
| 113 | * Read and write, they both share the same lock. We do this to serialize |
| 114 | * reads and writes on Atheros 802.11n PCI devices only. This is required |
| 115 | * as the FIFO on these devices can only accept sanely 2 requests. |
| 116 | */ |
| 117 | |
| 118 | static void ath9k_iowrite32(void *hw_priv, u32 val, u32 reg_offset) |
| 119 | { |
| 120 | struct ath_hw *ah = (struct ath_hw *) hw_priv; |
| 121 | struct ath_common *common = ath9k_hw_common(ah); |
| 122 | struct ath_softc *sc = (struct ath_softc *) common->priv; |
| 123 | |
Felix Fietkau | f3eef64 | 2012-03-14 16:40:25 +0100 | [diff] [blame] | 124 | if (NR_CPUS > 1 && ah->config.serialize_regmode == SER_REG_MODE_ON) { |
Sujith | 5562420 | 2010-01-08 10:36:02 +0530 | [diff] [blame] | 125 | unsigned long flags; |
| 126 | spin_lock_irqsave(&sc->sc_serial_rw, flags); |
| 127 | iowrite32(val, sc->mem + reg_offset); |
| 128 | spin_unlock_irqrestore(&sc->sc_serial_rw, flags); |
| 129 | } else |
| 130 | iowrite32(val, sc->mem + reg_offset); |
| 131 | } |
| 132 | |
| 133 | static unsigned int ath9k_ioread32(void *hw_priv, u32 reg_offset) |
| 134 | { |
| 135 | struct ath_hw *ah = (struct ath_hw *) hw_priv; |
| 136 | struct ath_common *common = ath9k_hw_common(ah); |
| 137 | struct ath_softc *sc = (struct ath_softc *) common->priv; |
| 138 | u32 val; |
| 139 | |
Felix Fietkau | f3eef64 | 2012-03-14 16:40:25 +0100 | [diff] [blame] | 140 | if (NR_CPUS > 1 && ah->config.serialize_regmode == SER_REG_MODE_ON) { |
Sujith | 5562420 | 2010-01-08 10:36:02 +0530 | [diff] [blame] | 141 | unsigned long flags; |
| 142 | spin_lock_irqsave(&sc->sc_serial_rw, flags); |
| 143 | val = ioread32(sc->mem + reg_offset); |
| 144 | spin_unlock_irqrestore(&sc->sc_serial_rw, flags); |
| 145 | } else |
| 146 | val = ioread32(sc->mem + reg_offset); |
| 147 | return val; |
| 148 | } |
| 149 | |
Oleksij Rempel | d55ce0a | 2015-03-22 19:29:50 +0100 | [diff] [blame] | 150 | static void ath9k_multi_ioread32(void *hw_priv, u32 *addr, |
| 151 | u32 *val, u16 count) |
| 152 | { |
| 153 | int i; |
| 154 | |
| 155 | for (i = 0; i < count; i++) |
| 156 | val[i] = ath9k_ioread32(hw_priv, addr[i]); |
| 157 | } |
| 158 | |
| 159 | |
Rajkumar Manoharan | 5479de6 | 2011-07-17 11:43:02 +0530 | [diff] [blame] | 160 | static unsigned int __ath9k_reg_rmw(struct ath_softc *sc, u32 reg_offset, |
| 161 | u32 set, u32 clr) |
| 162 | { |
| 163 | u32 val; |
| 164 | |
| 165 | val = ioread32(sc->mem + reg_offset); |
| 166 | val &= ~clr; |
| 167 | val |= set; |
| 168 | iowrite32(val, sc->mem + reg_offset); |
| 169 | |
| 170 | return val; |
| 171 | } |
| 172 | |
Felix Fietkau | 845e03c | 2011-03-23 20:57:25 +0100 | [diff] [blame] | 173 | static unsigned int ath9k_reg_rmw(void *hw_priv, u32 reg_offset, u32 set, u32 clr) |
| 174 | { |
| 175 | struct ath_hw *ah = (struct ath_hw *) hw_priv; |
| 176 | struct ath_common *common = ath9k_hw_common(ah); |
| 177 | struct ath_softc *sc = (struct ath_softc *) common->priv; |
| 178 | unsigned long uninitialized_var(flags); |
| 179 | u32 val; |
| 180 | |
Felix Fietkau | f3eef64 | 2012-03-14 16:40:25 +0100 | [diff] [blame] | 181 | if (NR_CPUS > 1 && ah->config.serialize_regmode == SER_REG_MODE_ON) { |
Felix Fietkau | 845e03c | 2011-03-23 20:57:25 +0100 | [diff] [blame] | 182 | spin_lock_irqsave(&sc->sc_serial_rw, flags); |
Rajkumar Manoharan | 5479de6 | 2011-07-17 11:43:02 +0530 | [diff] [blame] | 183 | val = __ath9k_reg_rmw(sc, reg_offset, set, clr); |
Felix Fietkau | 845e03c | 2011-03-23 20:57:25 +0100 | [diff] [blame] | 184 | spin_unlock_irqrestore(&sc->sc_serial_rw, flags); |
Rajkumar Manoharan | 5479de6 | 2011-07-17 11:43:02 +0530 | [diff] [blame] | 185 | } else |
| 186 | val = __ath9k_reg_rmw(sc, reg_offset, set, clr); |
Felix Fietkau | 845e03c | 2011-03-23 20:57:25 +0100 | [diff] [blame] | 187 | |
| 188 | return val; |
| 189 | } |
| 190 | |
Sujith | 5562420 | 2010-01-08 10:36:02 +0530 | [diff] [blame] | 191 | /**************************/ |
| 192 | /* Initialization */ |
| 193 | /**************************/ |
| 194 | |
Luis R. Rodriguez | 0c0280b | 2013-01-11 18:39:36 +0000 | [diff] [blame] | 195 | static void ath9k_reg_notifier(struct wiphy *wiphy, |
| 196 | struct regulatory_request *request) |
Sujith | 5562420 | 2010-01-08 10:36:02 +0530 | [diff] [blame] | 197 | { |
| 198 | struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy); |
Felix Fietkau | 9ac58615 | 2011-01-24 19:23:18 +0100 | [diff] [blame] | 199 | struct ath_softc *sc = hw->priv; |
Rajkumar Manoharan | 687f545 | 2011-12-08 23:59:25 +0530 | [diff] [blame] | 200 | struct ath_hw *ah = sc->sc_ah; |
| 201 | struct ath_regulatory *reg = ath9k_hw_regulatory(ah); |
Sujith | 5562420 | 2010-01-08 10:36:02 +0530 | [diff] [blame] | 202 | |
Luis R. Rodriguez | 0c0280b | 2013-01-11 18:39:36 +0000 | [diff] [blame] | 203 | ath_reg_notifier_apply(wiphy, request, reg); |
Rajkumar Manoharan | 687f545 | 2011-12-08 23:59:25 +0530 | [diff] [blame] | 204 | |
| 205 | /* Set tx power */ |
Felix Fietkau | d385c5c | 2014-11-04 16:56:57 +0100 | [diff] [blame] | 206 | if (!ah->curchan) |
| 207 | return; |
| 208 | |
| 209 | sc->cur_chan->txpower = 2 * ah->curchan->chan->max_power; |
| 210 | ath9k_ps_wakeup(sc); |
| 211 | ath9k_hw_set_txpowerlimit(ah, sc->cur_chan->txpower, false); |
| 212 | ath9k_cmn_update_txpow(ah, sc->cur_chan->cur_txpower, |
| 213 | sc->cur_chan->txpower, |
| 214 | &sc->cur_chan->cur_txpower); |
| 215 | /* synchronize DFS detector if regulatory domain changed */ |
| 216 | if (sc->dfs_detector != NULL) |
| 217 | sc->dfs_detector->set_dfs_domain(sc->dfs_detector, |
| 218 | request->dfs_region); |
| 219 | ath9k_ps_restore(sc); |
Sujith | 5562420 | 2010-01-08 10:36:02 +0530 | [diff] [blame] | 220 | } |
| 221 | |
| 222 | /* |
| 223 | * This function will allocate both the DMA descriptor structure, and the |
| 224 | * buffers it contains. These are used to contain the descriptors used |
| 225 | * by the system. |
| 226 | */ |
| 227 | int ath_descdma_setup(struct ath_softc *sc, struct ath_descdma *dd, |
| 228 | struct list_head *head, const char *name, |
Vasanthakumar Thiagarajan | 4adfcde | 2010-04-15 17:39:33 -0400 | [diff] [blame] | 229 | int nbuf, int ndesc, bool is_tx) |
Sujith | 5562420 | 2010-01-08 10:36:02 +0530 | [diff] [blame] | 230 | { |
Sujith | 5562420 | 2010-01-08 10:36:02 +0530 | [diff] [blame] | 231 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
Vasanthakumar Thiagarajan | 4adfcde | 2010-04-15 17:39:33 -0400 | [diff] [blame] | 232 | u8 *ds; |
Felix Fietkau | b81950b1 | 2012-12-12 13:14:22 +0100 | [diff] [blame] | 233 | int i, bsize, desc_len; |
Sujith | 5562420 | 2010-01-08 10:36:02 +0530 | [diff] [blame] | 234 | |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 235 | ath_dbg(common, CONFIG, "%s DMA: %u buffers %u desc/buf\n", |
Joe Perches | 226afe6 | 2010-12-02 19:12:37 -0800 | [diff] [blame] | 236 | name, nbuf, ndesc); |
Sujith | 5562420 | 2010-01-08 10:36:02 +0530 | [diff] [blame] | 237 | |
| 238 | INIT_LIST_HEAD(head); |
Vasanthakumar Thiagarajan | 4adfcde | 2010-04-15 17:39:33 -0400 | [diff] [blame] | 239 | |
| 240 | if (is_tx) |
| 241 | desc_len = sc->sc_ah->caps.tx_desc_len; |
| 242 | else |
| 243 | desc_len = sizeof(struct ath_desc); |
| 244 | |
Sujith | 5562420 | 2010-01-08 10:36:02 +0530 | [diff] [blame] | 245 | /* ath_desc must be a multiple of DWORDs */ |
Vasanthakumar Thiagarajan | 4adfcde | 2010-04-15 17:39:33 -0400 | [diff] [blame] | 246 | if ((desc_len % 4) != 0) { |
Joe Perches | 3800276 | 2010-12-02 19:12:36 -0800 | [diff] [blame] | 247 | ath_err(common, "ath_desc not DWORD aligned\n"); |
Vasanthakumar Thiagarajan | 4adfcde | 2010-04-15 17:39:33 -0400 | [diff] [blame] | 248 | BUG_ON((desc_len % 4) != 0); |
Felix Fietkau | b81950b1 | 2012-12-12 13:14:22 +0100 | [diff] [blame] | 249 | return -ENOMEM; |
Sujith | 5562420 | 2010-01-08 10:36:02 +0530 | [diff] [blame] | 250 | } |
| 251 | |
Vasanthakumar Thiagarajan | 4adfcde | 2010-04-15 17:39:33 -0400 | [diff] [blame] | 252 | dd->dd_desc_len = desc_len * nbuf * ndesc; |
Sujith | 5562420 | 2010-01-08 10:36:02 +0530 | [diff] [blame] | 253 | |
| 254 | /* |
| 255 | * Need additional DMA memory because we can't use |
| 256 | * descriptors that cross the 4K page boundary. Assume |
| 257 | * one skipped descriptor per 4K page. |
| 258 | */ |
| 259 | if (!(sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_4KB_SPLITTRANS)) { |
| 260 | u32 ndesc_skipped = |
| 261 | ATH_DESC_4KB_BOUND_NUM_SKIPPED(dd->dd_desc_len); |
| 262 | u32 dma_len; |
| 263 | |
| 264 | while (ndesc_skipped) { |
Vasanthakumar Thiagarajan | 4adfcde | 2010-04-15 17:39:33 -0400 | [diff] [blame] | 265 | dma_len = ndesc_skipped * desc_len; |
Sujith | 5562420 | 2010-01-08 10:36:02 +0530 | [diff] [blame] | 266 | dd->dd_desc_len += dma_len; |
| 267 | |
| 268 | ndesc_skipped = ATH_DESC_4KB_BOUND_NUM_SKIPPED(dma_len); |
Joe Perches | ee289b6 | 2010-05-17 22:47:34 -0700 | [diff] [blame] | 269 | } |
Sujith | 5562420 | 2010-01-08 10:36:02 +0530 | [diff] [blame] | 270 | } |
| 271 | |
| 272 | /* allocate descriptors */ |
Felix Fietkau | b81950b1 | 2012-12-12 13:14:22 +0100 | [diff] [blame] | 273 | dd->dd_desc = dmam_alloc_coherent(sc->dev, dd->dd_desc_len, |
| 274 | &dd->dd_desc_paddr, GFP_KERNEL); |
| 275 | if (!dd->dd_desc) |
| 276 | return -ENOMEM; |
| 277 | |
Vasanthakumar Thiagarajan | 4adfcde | 2010-04-15 17:39:33 -0400 | [diff] [blame] | 278 | ds = (u8 *) dd->dd_desc; |
Joe Perches | d2182b6 | 2011-12-15 14:55:53 -0800 | [diff] [blame] | 279 | ath_dbg(common, CONFIG, "%s DMA map: %p (%u) -> %llx (%u)\n", |
Joe Perches | 226afe6 | 2010-12-02 19:12:37 -0800 | [diff] [blame] | 280 | name, ds, (u32) dd->dd_desc_len, |
| 281 | ito64(dd->dd_desc_paddr), /*XXX*/(u32) dd->dd_desc_len); |
Sujith | 5562420 | 2010-01-08 10:36:02 +0530 | [diff] [blame] | 282 | |
| 283 | /* allocate buffers */ |
Felix Fietkau | 1a04d59 | 2013-10-11 23:30:52 +0200 | [diff] [blame] | 284 | if (is_tx) { |
| 285 | struct ath_buf *bf; |
Sujith | 5562420 | 2010-01-08 10:36:02 +0530 | [diff] [blame] | 286 | |
Felix Fietkau | 1a04d59 | 2013-10-11 23:30:52 +0200 | [diff] [blame] | 287 | bsize = sizeof(struct ath_buf) * nbuf; |
| 288 | bf = devm_kzalloc(sc->dev, bsize, GFP_KERNEL); |
| 289 | if (!bf) |
| 290 | return -ENOMEM; |
Sujith | 5562420 | 2010-01-08 10:36:02 +0530 | [diff] [blame] | 291 | |
Felix Fietkau | 1a04d59 | 2013-10-11 23:30:52 +0200 | [diff] [blame] | 292 | for (i = 0; i < nbuf; i++, bf++, ds += (desc_len * ndesc)) { |
| 293 | bf->bf_desc = ds; |
| 294 | bf->bf_daddr = DS2PHYS(dd, ds); |
Sujith | 5562420 | 2010-01-08 10:36:02 +0530 | [diff] [blame] | 295 | |
Felix Fietkau | 1a04d59 | 2013-10-11 23:30:52 +0200 | [diff] [blame] | 296 | if (!(sc->sc_ah->caps.hw_caps & |
| 297 | ATH9K_HW_CAP_4KB_SPLITTRANS)) { |
| 298 | /* |
| 299 | * Skip descriptor addresses which can cause 4KB |
| 300 | * boundary crossing (addr + length) with a 32 dword |
| 301 | * descriptor fetch. |
| 302 | */ |
| 303 | while (ATH_DESC_4KB_BOUND_CHECK(bf->bf_daddr)) { |
| 304 | BUG_ON((caddr_t) bf->bf_desc >= |
| 305 | ((caddr_t) dd->dd_desc + |
| 306 | dd->dd_desc_len)); |
| 307 | |
| 308 | ds += (desc_len * ndesc); |
| 309 | bf->bf_desc = ds; |
| 310 | bf->bf_daddr = DS2PHYS(dd, ds); |
| 311 | } |
Sujith | 5562420 | 2010-01-08 10:36:02 +0530 | [diff] [blame] | 312 | } |
Felix Fietkau | 1a04d59 | 2013-10-11 23:30:52 +0200 | [diff] [blame] | 313 | list_add_tail(&bf->list, head); |
Sujith | 5562420 | 2010-01-08 10:36:02 +0530 | [diff] [blame] | 314 | } |
Felix Fietkau | 1a04d59 | 2013-10-11 23:30:52 +0200 | [diff] [blame] | 315 | } else { |
| 316 | struct ath_rxbuf *bf; |
| 317 | |
| 318 | bsize = sizeof(struct ath_rxbuf) * nbuf; |
| 319 | bf = devm_kzalloc(sc->dev, bsize, GFP_KERNEL); |
| 320 | if (!bf) |
| 321 | return -ENOMEM; |
| 322 | |
| 323 | for (i = 0; i < nbuf; i++, bf++, ds += (desc_len * ndesc)) { |
| 324 | bf->bf_desc = ds; |
| 325 | bf->bf_daddr = DS2PHYS(dd, ds); |
| 326 | |
| 327 | if (!(sc->sc_ah->caps.hw_caps & |
| 328 | ATH9K_HW_CAP_4KB_SPLITTRANS)) { |
| 329 | /* |
| 330 | * Skip descriptor addresses which can cause 4KB |
| 331 | * boundary crossing (addr + length) with a 32 dword |
| 332 | * descriptor fetch. |
| 333 | */ |
| 334 | while (ATH_DESC_4KB_BOUND_CHECK(bf->bf_daddr)) { |
| 335 | BUG_ON((caddr_t) bf->bf_desc >= |
| 336 | ((caddr_t) dd->dd_desc + |
| 337 | dd->dd_desc_len)); |
| 338 | |
| 339 | ds += (desc_len * ndesc); |
| 340 | bf->bf_desc = ds; |
| 341 | bf->bf_daddr = DS2PHYS(dd, ds); |
| 342 | } |
| 343 | } |
| 344 | list_add_tail(&bf->list, head); |
| 345 | } |
Sujith | 5562420 | 2010-01-08 10:36:02 +0530 | [diff] [blame] | 346 | } |
| 347 | return 0; |
Sujith | 5562420 | 2010-01-08 10:36:02 +0530 | [diff] [blame] | 348 | } |
| 349 | |
Sujith | 285f2dd | 2010-01-08 10:36:07 +0530 | [diff] [blame] | 350 | static int ath9k_init_queues(struct ath_softc *sc) |
| 351 | { |
Sujith | 285f2dd | 2010-01-08 10:36:07 +0530 | [diff] [blame] | 352 | int i = 0; |
Sujith | 5562420 | 2010-01-08 10:36:02 +0530 | [diff] [blame] | 353 | |
Sujith | 285f2dd | 2010-01-08 10:36:07 +0530 | [diff] [blame] | 354 | sc->beacon.beaconq = ath9k_hw_beaconq_setup(sc->sc_ah); |
Sujith | 285f2dd | 2010-01-08 10:36:07 +0530 | [diff] [blame] | 355 | sc->beacon.cabq = ath_txq_setup(sc, ATH9K_TX_QUEUE_CAB, 0); |
Sujith | 285f2dd | 2010-01-08 10:36:07 +0530 | [diff] [blame] | 356 | ath_cabq_update(sc); |
| 357 | |
Felix Fietkau | f2c7a79 | 2013-06-07 18:12:00 +0200 | [diff] [blame] | 358 | sc->tx.uapsdq = ath_txq_setup(sc, ATH9K_TX_QUEUE_UAPSD, 0); |
| 359 | |
Sujith Manoharan | bea843c | 2012-11-21 18:13:10 +0530 | [diff] [blame] | 360 | for (i = 0; i < IEEE80211_NUM_ACS; i++) { |
Felix Fietkau | 066dae9 | 2010-11-07 14:59:39 +0100 | [diff] [blame] | 361 | sc->tx.txq_map[i] = ath_txq_setup(sc, ATH9K_TX_QUEUE_DATA, i); |
Ben Greear | 60f2d1d | 2011-01-09 23:11:52 -0800 | [diff] [blame] | 362 | sc->tx.txq_map[i]->mac80211_qnum = i; |
Ben Greear | 60f2d1d | 2011-01-09 23:11:52 -0800 | [diff] [blame] | 363 | } |
Sujith | 285f2dd | 2010-01-08 10:36:07 +0530 | [diff] [blame] | 364 | return 0; |
Sujith | 285f2dd | 2010-01-08 10:36:07 +0530 | [diff] [blame] | 365 | } |
| 366 | |
Sujith | 285f2dd | 2010-01-08 10:36:07 +0530 | [diff] [blame] | 367 | static void ath9k_init_misc(struct ath_softc *sc) |
| 368 | { |
| 369 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); |
| 370 | int i = 0; |
Sujith Manoharan | 3d4e20f | 2012-03-14 14:40:58 +0530 | [diff] [blame] | 371 | |
Sujith | 285f2dd | 2010-01-08 10:36:07 +0530 | [diff] [blame] | 372 | setup_timer(&common->ani.timer, ath_ani_calibrate, (unsigned long)sc); |
| 373 | |
Oleksij Rempel | 32efb0c | 2014-02-04 10:27:39 +0100 | [diff] [blame] | 374 | common->last_rssi = ATH_RSSI_DUMMY_MARKER; |
Felix Fietkau | 364734f | 2010-09-14 20:22:44 +0200 | [diff] [blame] | 375 | memcpy(common->bssidmask, ath_bcast_mac, ETH_ALEN); |
Benjamin Berg | 11b0ac2 | 2016-07-04 14:37:24 +0200 | [diff] [blame] | 376 | sc->beacon.slottime = 9; |
Sujith | 285f2dd | 2010-01-08 10:36:07 +0530 | [diff] [blame] | 377 | |
Felix Fietkau | 7545daf | 2011-01-24 19:23:16 +0100 | [diff] [blame] | 378 | for (i = 0; i < ARRAY_SIZE(sc->beacon.bslot); i++) |
Sujith | 285f2dd | 2010-01-08 10:36:07 +0530 | [diff] [blame] | 379 | sc->beacon.bslot[i] = NULL; |
Vasanthakumar Thiagarajan | 102885a | 2010-09-02 01:34:43 -0700 | [diff] [blame] | 380 | |
| 381 | if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_ANT_DIV_COMB) |
| 382 | sc->ant_comb.count = ATH_ANT_DIV_COMB_INIT_COUNT; |
Simon Wunderlich | 04ccd4a | 2013-01-23 17:38:04 +0100 | [diff] [blame] | 383 | |
Oleksij Rempel | dd7657b | 2014-11-06 08:53:22 +0100 | [diff] [blame] | 384 | sc->spec_priv.ah = sc->sc_ah; |
Oleksij Rempel | 21af25d | 2014-11-06 08:53:20 +0100 | [diff] [blame] | 385 | sc->spec_priv.spec_config.enabled = 0; |
| 386 | sc->spec_priv.spec_config.short_repeat = true; |
| 387 | sc->spec_priv.spec_config.count = 8; |
| 388 | sc->spec_priv.spec_config.endless = false; |
| 389 | sc->spec_priv.spec_config.period = 0xFF; |
| 390 | sc->spec_priv.spec_config.fft_period = 0xF; |
Sujith | 285f2dd | 2010-01-08 10:36:07 +0530 | [diff] [blame] | 391 | } |
| 392 | |
Sujith Manoharan | 0f978bf | 2013-12-06 16:28:45 +0530 | [diff] [blame] | 393 | static void ath9k_init_pcoem_platform(struct ath_softc *sc) |
Sujith Manoharan | 9b60b64 | 2013-06-13 22:51:26 +0530 | [diff] [blame] | 394 | { |
| 395 | struct ath_hw *ah = sc->sc_ah; |
Sujith Manoharan | 3f2da95 | 2013-08-04 14:21:56 +0530 | [diff] [blame] | 396 | struct ath9k_hw_capabilities *pCap = &ah->caps; |
Sujith Manoharan | 9b60b64 | 2013-06-13 22:51:26 +0530 | [diff] [blame] | 397 | struct ath_common *common = ath9k_hw_common(ah); |
| 398 | |
Felix Fietkau | 935477e | 2014-10-25 17:19:26 +0200 | [diff] [blame] | 399 | if (!IS_ENABLED(CONFIG_ATH9K_PCOEM)) |
| 400 | return; |
| 401 | |
Sujith Manoharan | 9b60b64 | 2013-06-13 22:51:26 +0530 | [diff] [blame] | 402 | if (common->bus_ops->ath_bus_type != ATH_PCI) |
| 403 | return; |
| 404 | |
Sujith Manoharan | e861ef5 | 2013-06-18 10:13:43 +0530 | [diff] [blame] | 405 | if (sc->driver_data & (ATH9K_PCI_CUS198 | |
| 406 | ATH9K_PCI_CUS230)) { |
Sujith Manoharan | 9b60b64 | 2013-06-13 22:51:26 +0530 | [diff] [blame] | 407 | ah->config.xlna_gpio = 9; |
| 408 | ah->config.xatten_margin_cfg = true; |
Sujith Manoharan | e083a42 | 2013-08-19 11:04:01 +0530 | [diff] [blame] | 409 | ah->config.alt_mingainidx = true; |
Sujith Manoharan | 31fd216 | 2013-08-04 14:22:01 +0530 | [diff] [blame] | 410 | ah->config.ant_ctrl_comm2g_switch_enable = 0x000BBB88; |
Sujith Manoharan | 3afa6b4 | 2013-08-04 14:21:54 +0530 | [diff] [blame] | 411 | sc->ant_comb.low_rssi_thresh = 20; |
| 412 | sc->ant_comb.fast_div_bias = 3; |
Sujith Manoharan | 9b60b64 | 2013-06-13 22:51:26 +0530 | [diff] [blame] | 413 | |
Sujith Manoharan | e861ef5 | 2013-06-18 10:13:43 +0530 | [diff] [blame] | 414 | ath_info(common, "Set parameters for %s\n", |
| 415 | (sc->driver_data & ATH9K_PCI_CUS198) ? |
| 416 | "CUS198" : "CUS230"); |
Sujith Manoharan | 3f2da95 | 2013-08-04 14:21:56 +0530 | [diff] [blame] | 417 | } |
| 418 | |
| 419 | if (sc->driver_data & ATH9K_PCI_CUS217) |
Sujith Manoharan | 12eea64 | 2013-06-18 15:42:36 +0530 | [diff] [blame] | 420 | ath_info(common, "CUS217 card detected\n"); |
Sujith Manoharan | 3f2da95 | 2013-08-04 14:21:56 +0530 | [diff] [blame] | 421 | |
Sujith Manoharan | 1063133 | 2013-09-02 13:59:05 +0530 | [diff] [blame] | 422 | if (sc->driver_data & ATH9K_PCI_CUS252) |
| 423 | ath_info(common, "CUS252 card detected\n"); |
| 424 | |
Sujith Manoharan | 3fcdd0a | 2013-09-02 13:59:06 +0530 | [diff] [blame] | 425 | if (sc->driver_data & ATH9K_PCI_AR9565_1ANT) |
| 426 | ath_info(common, "WB335 1-ANT card detected\n"); |
| 427 | |
| 428 | if (sc->driver_data & ATH9K_PCI_AR9565_2ANT) |
| 429 | ath_info(common, "WB335 2-ANT card detected\n"); |
| 430 | |
Sujith Manoharan | 4dd3564 | 2013-10-23 14:26:04 +0530 | [diff] [blame] | 431 | if (sc->driver_data & ATH9K_PCI_KILLER) |
| 432 | ath_info(common, "Killer Wireless card detected\n"); |
| 433 | |
Sujith Manoharan | 3fcdd0a | 2013-09-02 13:59:06 +0530 | [diff] [blame] | 434 | /* |
| 435 | * Some WB335 cards do not support antenna diversity. Since |
| 436 | * we use a hardcoded value for AR9565 instead of using the |
| 437 | * EEPROM/OTP data, remove the combining feature from |
| 438 | * the HW capabilities bitmap. |
| 439 | */ |
| 440 | if (sc->driver_data & (ATH9K_PCI_AR9565_1ANT | ATH9K_PCI_AR9565_2ANT)) { |
| 441 | if (!(sc->driver_data & ATH9K_PCI_BT_ANT_DIV)) |
| 442 | pCap->hw_caps &= ~ATH9K_HW_CAP_ANT_DIV_COMB; |
| 443 | } |
| 444 | |
Sujith Manoharan | 3f2da95 | 2013-08-04 14:21:56 +0530 | [diff] [blame] | 445 | if (sc->driver_data & ATH9K_PCI_BT_ANT_DIV) { |
| 446 | pCap->hw_caps |= ATH9K_HW_CAP_BT_ANT_DIV; |
| 447 | ath_info(common, "Set BT/WLAN RX diversity capability\n"); |
Sujith Manoharan | 9b60b64 | 2013-06-13 22:51:26 +0530 | [diff] [blame] | 448 | } |
Sujith Manoharan | d1ae25a | 2013-08-25 16:30:40 +0530 | [diff] [blame] | 449 | |
| 450 | if (sc->driver_data & ATH9K_PCI_D3_L1_WAR) { |
| 451 | ah->config.pcie_waen = 0x0040473b; |
| 452 | ath_info(common, "Enable WAR for ASPM D3/L1\n"); |
| 453 | } |
Sujith Manoharan | 2d22c7d | 2013-11-08 11:45:25 +0530 | [diff] [blame] | 454 | |
Sujith Manoharan | afa7e6d | 2015-03-09 14:20:07 +0530 | [diff] [blame] | 455 | /* |
| 456 | * The default value of pll_pwrsave is 1. |
| 457 | * For certain AR9485 cards, it is set to 0. |
Sujith Manoharan | 656cd75 | 2015-03-09 14:20:08 +0530 | [diff] [blame] | 458 | * For AR9462, AR9565 it's set to 7. |
Sujith Manoharan | afa7e6d | 2015-03-09 14:20:07 +0530 | [diff] [blame] | 459 | */ |
| 460 | ah->config.pll_pwrsave = 1; |
| 461 | |
Sujith Manoharan | 2d22c7d | 2013-11-08 11:45:25 +0530 | [diff] [blame] | 462 | if (sc->driver_data & ATH9K_PCI_NO_PLL_PWRSAVE) { |
Sujith Manoharan | afa7e6d | 2015-03-09 14:20:07 +0530 | [diff] [blame] | 463 | ah->config.pll_pwrsave = 0; |
Sujith Manoharan | 2d22c7d | 2013-11-08 11:45:25 +0530 | [diff] [blame] | 464 | ath_info(common, "Disable PLL PowerSave\n"); |
| 465 | } |
Sujith Manoharan | aeeb206 | 2014-11-16 06:11:02 +0530 | [diff] [blame] | 466 | |
| 467 | if (sc->driver_data & ATH9K_PCI_LED_ACT_HI) |
| 468 | ah->config.led_active_high = true; |
Sujith Manoharan | 9b60b64 | 2013-06-13 22:51:26 +0530 | [diff] [blame] | 469 | } |
| 470 | |
Gabor Juhos | ab5c4f7 | 2012-12-10 15:30:28 +0100 | [diff] [blame] | 471 | static void ath9k_eeprom_request_cb(const struct firmware *eeprom_blob, |
| 472 | void *ctx) |
| 473 | { |
| 474 | struct ath9k_eeprom_ctx *ec = ctx; |
| 475 | |
| 476 | if (eeprom_blob) |
| 477 | ec->ah->eeprom_blob = eeprom_blob; |
| 478 | |
| 479 | complete(&ec->complete); |
| 480 | } |
| 481 | |
| 482 | static int ath9k_eeprom_request(struct ath_softc *sc, const char *name) |
| 483 | { |
| 484 | struct ath9k_eeprom_ctx ec; |
Colin Ian King | 47f58b1 | 2016-04-10 12:25:31 +0100 | [diff] [blame] | 485 | struct ath_hw *ah = sc->sc_ah; |
Gabor Juhos | ab5c4f7 | 2012-12-10 15:30:28 +0100 | [diff] [blame] | 486 | int err; |
| 487 | |
| 488 | /* try to load the EEPROM content asynchronously */ |
| 489 | init_completion(&ec.complete); |
| 490 | ec.ah = sc->sc_ah; |
| 491 | |
| 492 | err = request_firmware_nowait(THIS_MODULE, 1, name, sc->dev, GFP_KERNEL, |
| 493 | &ec, ath9k_eeprom_request_cb); |
| 494 | if (err < 0) { |
| 495 | ath_err(ath9k_hw_common(ah), |
| 496 | "EEPROM request failed\n"); |
| 497 | return err; |
| 498 | } |
| 499 | |
| 500 | wait_for_completion(&ec.complete); |
| 501 | |
| 502 | if (!ah->eeprom_blob) { |
| 503 | ath_err(ath9k_hw_common(ah), |
| 504 | "Unable to load EEPROM file %s\n", name); |
| 505 | return -EINVAL; |
| 506 | } |
| 507 | |
| 508 | return 0; |
| 509 | } |
| 510 | |
| 511 | static void ath9k_eeprom_release(struct ath_softc *sc) |
| 512 | { |
| 513 | release_firmware(sc->sc_ah->eeprom_blob); |
| 514 | } |
| 515 | |
Martin Blumenstingl | 28755b8 | 2016-06-23 16:57:13 +0200 | [diff] [blame] | 516 | static int ath9k_init_platform(struct ath_softc *sc) |
Sujith Manoharan | 0f978bf | 2013-12-06 16:28:45 +0530 | [diff] [blame] | 517 | { |
| 518 | struct ath9k_platform_data *pdata = sc->dev->platform_data; |
| 519 | struct ath_hw *ah = sc->sc_ah; |
Martin Blumenstingl | 28755b8 | 2016-06-23 16:57:13 +0200 | [diff] [blame] | 520 | struct ath_common *common = ath9k_hw_common(ah); |
| 521 | int ret; |
Sujith Manoharan | 0f978bf | 2013-12-06 16:28:45 +0530 | [diff] [blame] | 522 | |
| 523 | if (!pdata) |
| 524 | return 0; |
| 525 | |
Martin Blumenstingl | 28755b8 | 2016-06-23 16:57:13 +0200 | [diff] [blame] | 526 | if (!pdata->use_eeprom) { |
| 527 | ah->ah_flags &= ~AH_USE_EEPROM; |
| 528 | ah->gpio_mask = pdata->gpio_mask; |
| 529 | ah->gpio_val = pdata->gpio_val; |
| 530 | ah->led_pin = pdata->led_pin; |
| 531 | ah->is_clk_25mhz = pdata->is_clk_25mhz; |
| 532 | ah->get_mac_revision = pdata->get_mac_revision; |
| 533 | ah->external_reset = pdata->external_reset; |
| 534 | ah->disable_2ghz = pdata->disable_2ghz; |
| 535 | ah->disable_5ghz = pdata->disable_5ghz; |
| 536 | |
| 537 | if (!pdata->endian_check) |
| 538 | ah->ah_flags |= AH_NO_EEP_SWAP; |
| 539 | } |
| 540 | |
Sujith Manoharan | 0f978bf | 2013-12-06 16:28:45 +0530 | [diff] [blame] | 541 | if (pdata->eeprom_name) { |
| 542 | ret = ath9k_eeprom_request(sc, pdata->eeprom_name); |
| 543 | if (ret) |
| 544 | return ret; |
| 545 | } |
| 546 | |
Martin Blumenstingl | 3467f0d | 2016-06-23 16:57:09 +0200 | [diff] [blame] | 547 | if (pdata->led_active_high) |
| 548 | ah->config.led_active_high = true; |
| 549 | |
Sujith Manoharan | 0f978bf | 2013-12-06 16:28:45 +0530 | [diff] [blame] | 550 | if (pdata->tx_gain_buffalo) |
| 551 | ah->config.tx_gain_buffalo = true; |
| 552 | |
Martin Blumenstingl | 28755b8 | 2016-06-23 16:57:13 +0200 | [diff] [blame] | 553 | if (pdata->macaddr) |
| 554 | ether_addr_copy(common->macaddr, pdata->macaddr); |
| 555 | |
| 556 | return 0; |
Sujith Manoharan | 0f978bf | 2013-12-06 16:28:45 +0530 | [diff] [blame] | 557 | } |
| 558 | |
Martin Blumenstingl | 138b412 | 2016-10-16 22:59:07 +0200 | [diff] [blame] | 559 | static int ath9k_of_init(struct ath_softc *sc) |
| 560 | { |
| 561 | struct device_node *np = sc->dev->of_node; |
| 562 | struct ath_hw *ah = sc->sc_ah; |
| 563 | struct ath_common *common = ath9k_hw_common(ah); |
| 564 | enum ath_bus_type bus_type = common->bus_ops->ath_bus_type; |
| 565 | const char *mac; |
| 566 | char eeprom_name[100]; |
| 567 | int ret; |
| 568 | |
| 569 | if (!of_device_is_available(np)) |
| 570 | return 0; |
| 571 | |
| 572 | ath_dbg(common, CONFIG, "parsing configuration from OF node\n"); |
| 573 | |
| 574 | if (of_property_read_bool(np, "qca,no-eeprom")) { |
| 575 | /* ath9k-eeprom-<bus>-<id>.bin */ |
| 576 | scnprintf(eeprom_name, sizeof(eeprom_name), |
| 577 | "ath9k-eeprom-%s-%s.bin", |
| 578 | ath_bus_type_to_string(bus_type), dev_name(ah->dev)); |
| 579 | |
| 580 | ret = ath9k_eeprom_request(sc, eeprom_name); |
| 581 | if (ret) |
| 582 | return ret; |
| 583 | } |
| 584 | |
| 585 | mac = of_get_mac_address(np); |
| 586 | if (mac) |
| 587 | ether_addr_copy(common->macaddr, mac); |
| 588 | |
| 589 | ah->ah_flags &= ~AH_USE_EEPROM; |
| 590 | ah->ah_flags |= AH_NO_EEP_SWAP; |
| 591 | |
| 592 | return 0; |
| 593 | } |
| 594 | |
Pavel Roskin | eb93e89 | 2011-07-23 03:55:39 -0400 | [diff] [blame] | 595 | static int ath9k_init_softc(u16 devid, struct ath_softc *sc, |
Sujith | 285f2dd | 2010-01-08 10:36:07 +0530 | [diff] [blame] | 596 | const struct ath_bus_ops *bus_ops) |
| 597 | { |
Sujith | 285f2dd | 2010-01-08 10:36:07 +0530 | [diff] [blame] | 598 | struct ath_hw *ah = NULL; |
Sujith Manoharan | 3f2da95 | 2013-08-04 14:21:56 +0530 | [diff] [blame] | 599 | struct ath9k_hw_capabilities *pCap; |
Sujith | 285f2dd | 2010-01-08 10:36:07 +0530 | [diff] [blame] | 600 | struct ath_common *common; |
| 601 | int ret = 0, i; |
| 602 | int csz = 0; |
| 603 | |
Felix Fietkau | b81950b1 | 2012-12-12 13:14:22 +0100 | [diff] [blame] | 604 | ah = devm_kzalloc(sc->dev, sizeof(struct ath_hw), GFP_KERNEL); |
Sujith | 285f2dd | 2010-01-08 10:36:07 +0530 | [diff] [blame] | 605 | if (!ah) |
| 606 | return -ENOMEM; |
| 607 | |
Felix Fietkau | c1b976d | 2012-12-12 13:14:23 +0100 | [diff] [blame] | 608 | ah->dev = sc->dev; |
Ben Greear | 233536e | 2011-01-09 23:11:44 -0800 | [diff] [blame] | 609 | ah->hw = sc->hw; |
Sujith | 285f2dd | 2010-01-08 10:36:07 +0530 | [diff] [blame] | 610 | ah->hw_version.devid = devid; |
Martin Blumenstingl | 28755b8 | 2016-06-23 16:57:13 +0200 | [diff] [blame] | 611 | ah->ah_flags |= AH_USE_EEPROM; |
| 612 | ah->led_pin = -1; |
Felix Fietkau | f9f84e9 | 2011-03-23 20:57:24 +0100 | [diff] [blame] | 613 | ah->reg_ops.read = ath9k_ioread32; |
Oleksij Rempel | d55ce0a | 2015-03-22 19:29:50 +0100 | [diff] [blame] | 614 | ah->reg_ops.multi_read = ath9k_multi_ioread32; |
Felix Fietkau | f9f84e9 | 2011-03-23 20:57:24 +0100 | [diff] [blame] | 615 | ah->reg_ops.write = ath9k_iowrite32; |
Felix Fietkau | 845e03c | 2011-03-23 20:57:25 +0100 | [diff] [blame] | 616 | ah->reg_ops.rmw = ath9k_reg_rmw; |
Sujith Manoharan | 3f2da95 | 2013-08-04 14:21:56 +0530 | [diff] [blame] | 617 | pCap = &ah->caps; |
Sujith | 285f2dd | 2010-01-08 10:36:07 +0530 | [diff] [blame] | 618 | |
Janusz Dziedzic | 95a5992 | 2013-10-14 11:06:03 +0200 | [diff] [blame] | 619 | common = ath9k_hw_common(ah); |
Felix Fietkau | 56bdbe0 | 2014-11-30 21:58:30 +0100 | [diff] [blame] | 620 | |
| 621 | /* Will be cleared in ath9k_start() */ |
| 622 | set_bit(ATH_OP_INVALID, &common->op_flags); |
| 623 | |
| 624 | sc->sc_ah = ah; |
Janusz Dziedzic | 95a5992 | 2013-10-14 11:06:03 +0200 | [diff] [blame] | 625 | sc->dfs_detector = dfs_pattern_detector_init(common, NL80211_DFS_UNSET); |
Luis R. Rodriguez | 89f927a | 2013-10-14 17:42:11 -0700 | [diff] [blame] | 626 | sc->tx99_power = MAX_RATE_POWER + 1; |
Felix Fietkau | 10e2318 | 2013-11-11 22:23:35 +0100 | [diff] [blame] | 627 | init_waitqueue_head(&sc->tx_wait); |
Rajkumar Manoharan | ca900ac | 2014-06-11 16:18:02 +0530 | [diff] [blame] | 628 | sc->cur_chan = &sc->chanctx[0]; |
Sujith Manoharan | 499afac | 2014-08-22 20:39:31 +0530 | [diff] [blame] | 629 | if (!ath9k_is_chanctx_enabled()) |
Rajkumar Manoharan | 3ad9c38 | 2014-06-11 16:18:15 +0530 | [diff] [blame] | 630 | sc->cur_chan->hw_queue_base = 0; |
Zefir Kurtisi | 8e92d3f | 2012-04-03 17:15:50 +0200 | [diff] [blame] | 631 | |
Felix Fietkau | f9f84e9 | 2011-03-23 20:57:24 +0100 | [diff] [blame] | 632 | common->ops = &ah->reg_ops; |
Sujith | 285f2dd | 2010-01-08 10:36:07 +0530 | [diff] [blame] | 633 | common->bus_ops = bus_ops; |
Oleksij Rempel | 99d2217 | 2014-11-06 08:53:25 +0100 | [diff] [blame] | 634 | common->ps_ops = &ath9k_ps_ops; |
Sujith | 285f2dd | 2010-01-08 10:36:07 +0530 | [diff] [blame] | 635 | common->ah = ah; |
| 636 | common->hw = sc->hw; |
| 637 | common->priv = sc; |
| 638 | common->debug_mask = ath9k_debug; |
Vasanthakumar Thiagarajan | 8f5dcb1 | 2010-11-26 06:10:06 -0800 | [diff] [blame] | 639 | common->btcoex_enabled = ath9k_btcoex_enable == 1; |
Mohammed Shafi Shajakhan | 05c0be2 | 2011-05-26 10:56:15 +0530 | [diff] [blame] | 640 | common->disable_ani = false; |
Sujith Manoharan | e09f2dc | 2012-09-16 08:06:56 +0530 | [diff] [blame] | 641 | |
| 642 | /* |
Sujith Manoharan | 9b60b64 | 2013-06-13 22:51:26 +0530 | [diff] [blame] | 643 | * Platform quirks. |
| 644 | */ |
Sujith Manoharan | 0f978bf | 2013-12-06 16:28:45 +0530 | [diff] [blame] | 645 | ath9k_init_pcoem_platform(sc); |
| 646 | |
Martin Blumenstingl | 28755b8 | 2016-06-23 16:57:13 +0200 | [diff] [blame] | 647 | ret = ath9k_init_platform(sc); |
Sujith Manoharan | 0f978bf | 2013-12-06 16:28:45 +0530 | [diff] [blame] | 648 | if (ret) |
| 649 | return ret; |
Sujith Manoharan | 9b60b64 | 2013-06-13 22:51:26 +0530 | [diff] [blame] | 650 | |
Martin Blumenstingl | 138b412 | 2016-10-16 22:59:07 +0200 | [diff] [blame] | 651 | ret = ath9k_of_init(sc); |
| 652 | if (ret) |
| 653 | return ret; |
| 654 | |
Vittorio Gambaletta (VittGam) | cd84042 | 2016-04-11 04:48:54 +0200 | [diff] [blame] | 655 | if (ath9k_led_active_high != -1) |
| 656 | ah->config.led_active_high = ath9k_led_active_high == 1; |
| 657 | |
Sujith Manoharan | 9b60b64 | 2013-06-13 22:51:26 +0530 | [diff] [blame] | 658 | /* |
Sujith Manoharan | 3f2da95 | 2013-08-04 14:21:56 +0530 | [diff] [blame] | 659 | * Enable WLAN/BT RX Antenna diversity only when: |
| 660 | * |
Sujith Manoharan | 7d84587 | 2013-08-07 12:29:27 +0530 | [diff] [blame] | 661 | * - BTCOEX is disabled. |
Sujith Manoharan | 3f2da95 | 2013-08-04 14:21:56 +0530 | [diff] [blame] | 662 | * - the user manually requests the feature. |
| 663 | * - the HW cap is set using the platform data. |
Sujith Manoharan | e09f2dc | 2012-09-16 08:06:56 +0530 | [diff] [blame] | 664 | */ |
Sujith Manoharan | 7d84587 | 2013-08-07 12:29:27 +0530 | [diff] [blame] | 665 | if (!common->btcoex_enabled && ath9k_bt_ant_diversity && |
Sujith Manoharan | 3f2da95 | 2013-08-04 14:21:56 +0530 | [diff] [blame] | 666 | (pCap->hw_caps & ATH9K_HW_CAP_BT_ANT_DIV)) |
Sujith Manoharan | 6308130 | 2013-08-04 14:21:55 +0530 | [diff] [blame] | 667 | common->bt_ant_diversity = 1; |
Sujith Manoharan | e09f2dc | 2012-09-16 08:06:56 +0530 | [diff] [blame] | 668 | |
Ben Greear | 20b25744 | 2010-10-15 15:04:09 -0700 | [diff] [blame] | 669 | spin_lock_init(&common->cc_lock); |
Sujith | 285f2dd | 2010-01-08 10:36:07 +0530 | [diff] [blame] | 670 | spin_lock_init(&sc->sc_serial_rw); |
| 671 | spin_lock_init(&sc->sc_pm_lock); |
Felix Fietkau | bff1176 | 2014-06-11 16:17:52 +0530 | [diff] [blame] | 672 | spin_lock_init(&sc->chan_lock); |
Sujith | 285f2dd | 2010-01-08 10:36:07 +0530 | [diff] [blame] | 673 | mutex_init(&sc->mutex); |
| 674 | tasklet_init(&sc->intr_tq, ath9k_tasklet, (unsigned long)sc); |
Sujith Manoharan | fb6e252 | 2012-07-17 17:16:22 +0530 | [diff] [blame] | 675 | tasklet_init(&sc->bcon_tasklet, ath9k_beacon_tasklet, |
Sujith | 285f2dd | 2010-01-08 10:36:07 +0530 | [diff] [blame] | 676 | (unsigned long)sc); |
| 677 | |
Felix Fietkau | bf3dac5 | 2013-11-11 22:23:33 +0100 | [diff] [blame] | 678 | setup_timer(&sc->sleep_timer, ath_ps_full_sleep, (unsigned long)sc); |
Sujith Manoharan | aaa1ec4 | 2012-06-04 16:27:08 +0530 | [diff] [blame] | 679 | INIT_WORK(&sc->hw_reset_work, ath_reset_work); |
Sujith Manoharan | aaa1ec4 | 2012-06-04 16:27:08 +0530 | [diff] [blame] | 680 | INIT_WORK(&sc->paprd_work, ath_paprd_calibrate); |
| 681 | INIT_DELAYED_WORK(&sc->hw_pll_work, ath_hw_pll_work); |
Sujith Manoharan | 705d0bf | 2014-08-23 13:29:06 +0530 | [diff] [blame] | 682 | |
| 683 | ath9k_init_channel_context(sc); |
Sujith Manoharan | aaa1ec4 | 2012-06-04 16:27:08 +0530 | [diff] [blame] | 684 | |
Sujith | 285f2dd | 2010-01-08 10:36:07 +0530 | [diff] [blame] | 685 | /* |
| 686 | * Cache line size is used to size and align various |
| 687 | * structures used to communicate with the hardware. |
| 688 | */ |
| 689 | ath_read_cachesize(common, &csz); |
| 690 | common->cachelsz = csz << 2; /* convert to bytes */ |
| 691 | |
Luis R. Rodriguez | d70357d | 2010-04-15 17:38:06 -0400 | [diff] [blame] | 692 | /* Initializes the hardware for all supported chipsets */ |
Sujith | 285f2dd | 2010-01-08 10:36:07 +0530 | [diff] [blame] | 693 | ret = ath9k_hw_init(ah); |
Luis R. Rodriguez | d70357d | 2010-04-15 17:38:06 -0400 | [diff] [blame] | 694 | if (ret) |
Sujith | 285f2dd | 2010-01-08 10:36:07 +0530 | [diff] [blame] | 695 | goto err_hw; |
Sujith | 285f2dd | 2010-01-08 10:36:07 +0530 | [diff] [blame] | 696 | |
Sujith | 285f2dd | 2010-01-08 10:36:07 +0530 | [diff] [blame] | 697 | ret = ath9k_init_queues(sc); |
| 698 | if (ret) |
| 699 | goto err_queues; |
| 700 | |
| 701 | ret = ath9k_init_btcoex(sc); |
| 702 | if (ret) |
| 703 | goto err_btcoex; |
| 704 | |
Oleksij Rempel | 13f7105 | 2014-02-25 14:48:50 +0100 | [diff] [blame] | 705 | ret = ath9k_cmn_init_channels_rates(common); |
Felix Fietkau | f209f52 | 2010-10-01 01:06:53 +0200 | [diff] [blame] | 706 | if (ret) |
| 707 | goto err_btcoex; |
| 708 | |
Sujith Manoharan | c7dd40c | 2014-08-22 20:39:30 +0530 | [diff] [blame] | 709 | ret = ath9k_init_p2p(sc); |
| 710 | if (ret) |
Sujith Manoharan | 4f68169 | 2014-08-22 20:39:25 +0530 | [diff] [blame] | 711 | goto err_btcoex; |
Felix Fietkau | d463af4 | 2014-04-06 00:37:03 +0200 | [diff] [blame] | 712 | |
Rajkumar Manoharan | f82b4bd | 2011-08-13 10:28:15 +0530 | [diff] [blame] | 713 | ath9k_cmn_init_crypto(sc->sc_ah); |
Sujith | 285f2dd | 2010-01-08 10:36:07 +0530 | [diff] [blame] | 714 | ath9k_init_misc(sc); |
Felix Fietkau | fbbcd14 | 2014-06-11 16:17:49 +0530 | [diff] [blame] | 715 | ath_chanctx_init(sc); |
Sujith Manoharan | e90e302 | 2014-08-23 13:29:20 +0530 | [diff] [blame] | 716 | ath9k_offchannel_init(sc); |
Sujith | 285f2dd | 2010-01-08 10:36:07 +0530 | [diff] [blame] | 717 | |
Sujith Manoharan | d09f5f4 | 2012-06-04 16:27:14 +0530 | [diff] [blame] | 718 | if (common->bus_ops->aspm_init) |
| 719 | common->bus_ops->aspm_init(common); |
| 720 | |
Sujith | 5562420 | 2010-01-08 10:36:02 +0530 | [diff] [blame] | 721 | return 0; |
Sujith | 285f2dd | 2010-01-08 10:36:07 +0530 | [diff] [blame] | 722 | |
| 723 | err_btcoex: |
Sujith | 5562420 | 2010-01-08 10:36:02 +0530 | [diff] [blame] | 724 | for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++) |
| 725 | if (ATH_TXQ_SETUP(sc, i)) |
| 726 | ath_tx_cleanupq(sc, &sc->tx.txq[i]); |
Sujith | 285f2dd | 2010-01-08 10:36:07 +0530 | [diff] [blame] | 727 | err_queues: |
Sujith | 285f2dd | 2010-01-08 10:36:07 +0530 | [diff] [blame] | 728 | ath9k_hw_deinit(ah); |
| 729 | err_hw: |
Gabor Juhos | ab5c4f7 | 2012-12-10 15:30:28 +0100 | [diff] [blame] | 730 | ath9k_eeprom_release(sc); |
Luis R. Rodriguez | 89f927a | 2013-10-14 17:42:11 -0700 | [diff] [blame] | 731 | dev_kfree_skb_any(sc->tx99_skb); |
Sujith | 285f2dd | 2010-01-08 10:36:07 +0530 | [diff] [blame] | 732 | return ret; |
Sujith | 5562420 | 2010-01-08 10:36:02 +0530 | [diff] [blame] | 733 | } |
| 734 | |
Felix Fietkau | babcbc2 | 2010-10-20 02:09:46 +0200 | [diff] [blame] | 735 | static void ath9k_init_band_txpower(struct ath_softc *sc, int band) |
| 736 | { |
| 737 | struct ieee80211_supported_band *sband; |
| 738 | struct ieee80211_channel *chan; |
| 739 | struct ath_hw *ah = sc->sc_ah; |
Oleksij Rempel | 13f7105 | 2014-02-25 14:48:50 +0100 | [diff] [blame] | 740 | struct ath_common *common = ath9k_hw_common(ah); |
Simon Wunderlich | 0671894 | 2013-08-16 10:46:04 +0200 | [diff] [blame] | 741 | struct cfg80211_chan_def chandef; |
Felix Fietkau | babcbc2 | 2010-10-20 02:09:46 +0200 | [diff] [blame] | 742 | int i; |
| 743 | |
Oleksij Rempel | 13f7105 | 2014-02-25 14:48:50 +0100 | [diff] [blame] | 744 | sband = &common->sbands[band]; |
Felix Fietkau | babcbc2 | 2010-10-20 02:09:46 +0200 | [diff] [blame] | 745 | for (i = 0; i < sband->n_channels; i++) { |
| 746 | chan = &sband->channels[i]; |
| 747 | ah->curchan = &ah->channels[chan->hw_value]; |
Simon Wunderlich | 0671894 | 2013-08-16 10:46:04 +0200 | [diff] [blame] | 748 | cfg80211_chandef_create(&chandef, chan, NL80211_CHAN_HT20); |
Felix Fietkau | 2297f1c | 2013-10-11 23:30:57 +0200 | [diff] [blame] | 749 | ath9k_cmn_get_channel(sc->hw, ah, &chandef); |
Felix Fietkau | babcbc2 | 2010-10-20 02:09:46 +0200 | [diff] [blame] | 750 | ath9k_hw_set_txpowerlimit(ah, MAX_RATE_POWER, true); |
Felix Fietkau | babcbc2 | 2010-10-20 02:09:46 +0200 | [diff] [blame] | 751 | } |
| 752 | } |
| 753 | |
| 754 | static void ath9k_init_txpower_limits(struct ath_softc *sc) |
| 755 | { |
| 756 | struct ath_hw *ah = sc->sc_ah; |
| 757 | struct ath9k_channel *curchan = ah->curchan; |
| 758 | |
| 759 | if (ah->caps.hw_caps & ATH9K_HW_CAP_2GHZ) |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 760 | ath9k_init_band_txpower(sc, NL80211_BAND_2GHZ); |
Felix Fietkau | babcbc2 | 2010-10-20 02:09:46 +0200 | [diff] [blame] | 761 | if (ah->caps.hw_caps & ATH9K_HW_CAP_5GHZ) |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 762 | ath9k_init_band_txpower(sc, NL80211_BAND_5GHZ); |
Felix Fietkau | babcbc2 | 2010-10-20 02:09:46 +0200 | [diff] [blame] | 763 | |
| 764 | ah->curchan = curchan; |
| 765 | } |
| 766 | |
Felix Fietkau | 20c8e8d | 2012-04-17 02:40:07 +0200 | [diff] [blame] | 767 | static const struct ieee80211_iface_limit if_limits[] = { |
Rajkumar Manoharan | 71a5f88 | 2014-05-29 15:11:09 +0530 | [diff] [blame] | 768 | { .max = 2048, .types = BIT(NL80211_IFTYPE_STATION) }, |
Felix Fietkau | 20c8e8d | 2012-04-17 02:40:07 +0200 | [diff] [blame] | 769 | { .max = 8, .types = |
| 770 | #ifdef CONFIG_MAC80211_MESH |
| 771 | BIT(NL80211_IFTYPE_MESH_POINT) | |
| 772 | #endif |
Felix Fietkau | 95ae481 | 2014-04-06 00:37:02 +0200 | [diff] [blame] | 773 | BIT(NL80211_IFTYPE_AP) }, |
| 774 | { .max = 1, .types = BIT(NL80211_IFTYPE_P2P_CLIENT) | |
Felix Fietkau | 20c8e8d | 2012-04-17 02:40:07 +0200 | [diff] [blame] | 775 | BIT(NL80211_IFTYPE_P2P_GO) }, |
| 776 | }; |
| 777 | |
Rajkumar Manoharan | 71a5f88 | 2014-05-29 15:11:09 +0530 | [diff] [blame] | 778 | static const struct ieee80211_iface_limit wds_limits[] = { |
| 779 | { .max = 2048, .types = BIT(NL80211_IFTYPE_WDS) }, |
| 780 | }; |
| 781 | |
Sujith Manoharan | 499afac | 2014-08-22 20:39:31 +0530 | [diff] [blame] | 782 | #ifdef CONFIG_ATH9K_CHANNEL_CONTEXT |
| 783 | |
Rajkumar Manoharan | a406832 | 2014-06-11 16:18:16 +0530 | [diff] [blame] | 784 | static const struct ieee80211_iface_limit if_limits_multi[] = { |
Sujith Manoharan | 86162d4 | 2014-08-24 21:16:12 +0530 | [diff] [blame] | 785 | { .max = 2, .types = BIT(NL80211_IFTYPE_STATION) | |
| 786 | BIT(NL80211_IFTYPE_AP) | |
| 787 | BIT(NL80211_IFTYPE_P2P_CLIENT) | |
Rajkumar Manoharan | a406832 | 2014-06-11 16:18:16 +0530 | [diff] [blame] | 788 | BIT(NL80211_IFTYPE_P2P_GO) }, |
Sujith Manoharan | 86162d4 | 2014-08-24 21:16:12 +0530 | [diff] [blame] | 789 | { .max = 1, .types = BIT(NL80211_IFTYPE_ADHOC) }, |
[email protected] | eb61f9f | 2015-07-21 11:11:40 +0200 | [diff] [blame] | 790 | { .max = 1, .types = BIT(NL80211_IFTYPE_P2P_DEVICE) }, |
Rajkumar Manoharan | a406832 | 2014-06-11 16:18:16 +0530 | [diff] [blame] | 791 | }; |
| 792 | |
Rajkumar Manoharan | a406832 | 2014-06-11 16:18:16 +0530 | [diff] [blame] | 793 | static const struct ieee80211_iface_combination if_comb_multi[] = { |
| 794 | { |
| 795 | .limits = if_limits_multi, |
| 796 | .n_limits = ARRAY_SIZE(if_limits_multi), |
[email protected] | eb61f9f | 2015-07-21 11:11:40 +0200 | [diff] [blame] | 797 | .max_interfaces = 3, |
Rajkumar Manoharan | a406832 | 2014-06-11 16:18:16 +0530 | [diff] [blame] | 798 | .num_different_channels = 2, |
| 799 | .beacon_int_infra_match = true, |
| 800 | }, |
| 801 | }; |
| 802 | |
Sujith Manoharan | 499afac | 2014-08-22 20:39:31 +0530 | [diff] [blame] | 803 | #endif /* CONFIG_ATH9K_CHANNEL_CONTEXT */ |
| 804 | |
Zefir Kurtisi | e9cdedf | 2013-04-03 18:31:29 +0200 | [diff] [blame] | 805 | static const struct ieee80211_iface_combination if_comb[] = { |
| 806 | { |
| 807 | .limits = if_limits, |
| 808 | .n_limits = ARRAY_SIZE(if_limits), |
| 809 | .max_interfaces = 2048, |
| 810 | .num_different_channels = 1, |
| 811 | .beacon_int_infra_match = true, |
Felix Fietkau | 1286558 | 2016-01-22 01:56:30 +0100 | [diff] [blame] | 812 | #ifdef CONFIG_ATH9K_DFS_CERTIFIED |
| 813 | .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) | |
| 814 | BIT(NL80211_CHAN_WIDTH_20) | |
| 815 | BIT(NL80211_CHAN_WIDTH_40), |
| 816 | #endif |
Zefir Kurtisi | e9cdedf | 2013-04-03 18:31:29 +0200 | [diff] [blame] | 817 | }, |
Rajkumar Manoharan | 71a5f88 | 2014-05-29 15:11:09 +0530 | [diff] [blame] | 818 | { |
| 819 | .limits = wds_limits, |
| 820 | .n_limits = ARRAY_SIZE(wds_limits), |
| 821 | .max_interfaces = 2048, |
| 822 | .num_different_channels = 1, |
| 823 | .beacon_int_infra_match = true, |
| 824 | }, |
Felix Fietkau | 20c8e8d | 2012-04-17 02:40:07 +0200 | [diff] [blame] | 825 | }; |
Felix Fietkau | 43c3528 | 2011-09-03 01:40:27 +0200 | [diff] [blame] | 826 | |
Sujith Manoharan | 868caae | 2014-10-21 19:23:02 +0530 | [diff] [blame] | 827 | #ifdef CONFIG_ATH9K_CHANNEL_CONTEXT |
| 828 | static void ath9k_set_mcc_capab(struct ath_softc *sc, struct ieee80211_hw *hw) |
| 829 | { |
| 830 | struct ath_hw *ah = sc->sc_ah; |
| 831 | struct ath_common *common = ath9k_hw_common(ah); |
| 832 | |
| 833 | if (!ath9k_is_chanctx_enabled()) |
| 834 | return; |
| 835 | |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 836 | ieee80211_hw_set(hw, QUEUE_CONTROL); |
Sujith Manoharan | 868caae | 2014-10-21 19:23:02 +0530 | [diff] [blame] | 837 | hw->queues = ATH9K_NUM_TX_QUEUES; |
| 838 | hw->offchannel_tx_hw_queue = hw->queues - 1; |
| 839 | hw->wiphy->interface_modes &= ~ BIT(NL80211_IFTYPE_WDS); |
| 840 | hw->wiphy->iface_combinations = if_comb_multi; |
| 841 | hw->wiphy->n_iface_combinations = ARRAY_SIZE(if_comb_multi); |
| 842 | hw->wiphy->max_scan_ssids = 255; |
| 843 | hw->wiphy->max_scan_ie_len = IEEE80211_MAX_DATA_LEN; |
| 844 | hw->wiphy->max_remain_on_channel_duration = 10000; |
| 845 | hw->chanctx_data_size = sizeof(void *); |
| 846 | hw->extra_beacon_tailroom = |
| 847 | sizeof(struct ieee80211_p2p_noa_attr) + 9; |
| 848 | |
| 849 | ath_dbg(common, CHAN_CTX, "Use channel contexts\n"); |
| 850 | } |
| 851 | #endif /* CONFIG_ATH9K_CHANNEL_CONTEXT */ |
| 852 | |
Sujith Manoharan | 7b6ef99 | 2013-12-18 09:53:19 +0530 | [diff] [blame] | 853 | static void ath9k_set_hw_capab(struct ath_softc *sc, struct ieee80211_hw *hw) |
Sujith | 5562420 | 2010-01-08 10:36:02 +0530 | [diff] [blame] | 854 | { |
Felix Fietkau | 43c3528 | 2011-09-03 01:40:27 +0200 | [diff] [blame] | 855 | struct ath_hw *ah = sc->sc_ah; |
| 856 | struct ath_common *common = ath9k_hw_common(ah); |
Sujith | 285f2dd | 2010-01-08 10:36:07 +0530 | [diff] [blame] | 857 | |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 858 | ieee80211_hw_set(hw, SUPPORTS_HT_CCK_RATES); |
| 859 | ieee80211_hw_set(hw, SUPPORTS_RC_TABLE); |
| 860 | ieee80211_hw_set(hw, REPORTS_TX_ACK_STATUS); |
| 861 | ieee80211_hw_set(hw, SPECTRUM_MGMT); |
| 862 | ieee80211_hw_set(hw, PS_NULLFUNC_STACK); |
| 863 | ieee80211_hw_set(hw, SIGNAL_DBM); |
| 864 | ieee80211_hw_set(hw, RX_INCLUDES_FCS); |
| 865 | ieee80211_hw_set(hw, HOST_BROADCAST_PS_BUFFERING); |
Felix Fietkau | f419c5f | 2015-07-22 13:06:12 +0200 | [diff] [blame] | 866 | ieee80211_hw_set(hw, SUPPORT_FAST_XMIT); |
Pawel Kulakowski | 50e81e2 | 2015-12-18 10:48:57 +0100 | [diff] [blame] | 867 | ieee80211_hw_set(hw, SUPPORTS_CLONED_SKBS); |
Sujith | 5562420 | 2010-01-08 10:36:02 +0530 | [diff] [blame] | 868 | |
Sujith Manoharan | 8298383 | 2014-02-04 08:37:53 +0530 | [diff] [blame] | 869 | if (ath9k_ps_enable) |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 870 | ieee80211_hw_set(hw, SUPPORTS_PS); |
Sujith Manoharan | 8298383 | 2014-02-04 08:37:53 +0530 | [diff] [blame] | 871 | |
Oleksij Rempel | b0a1ae9 | 2013-05-24 20:30:59 +0200 | [diff] [blame] | 872 | if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_HT) { |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 873 | ieee80211_hw_set(hw, AMPDU_AGGREGATION); |
Oleksij Rempel | b0a1ae9 | 2013-05-24 20:30:59 +0200 | [diff] [blame] | 874 | |
| 875 | if (AR_SREV_9280_20_OR_LATER(ah)) |
| 876 | hw->radiotap_mcs_details |= |
| 877 | IEEE80211_RADIOTAP_MCS_HAVE_STBC; |
| 878 | } |
Luis R. Rodriguez | 5ffaf8a | 2010-02-02 11:58:33 -0500 | [diff] [blame] | 879 | |
John W. Linville | 3e6109c | 2011-01-05 09:39:17 -0500 | [diff] [blame] | 880 | if (AR_SREV_9160_10_OR_LATER(sc->sc_ah) || ath9k_modparam_nohwcrypt) |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 881 | ieee80211_hw_set(hw, MFP_CAPABLE); |
Sujith | 5562420 | 2010-01-08 10:36:02 +0530 | [diff] [blame] | 882 | |
Sujith Manoharan | fdcf1bd | 2014-09-05 08:03:14 +0530 | [diff] [blame] | 883 | hw->wiphy->features |= NL80211_FEATURE_ACTIVE_MONITOR | |
| 884 | NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE | |
| 885 | NL80211_FEATURE_P2P_GO_CTWIN; |
Felix Fietkau | ec26bcc | 2013-05-28 13:01:54 +0200 | [diff] [blame] | 886 | |
Masahiro Yamada | 97f2645 | 2016-08-03 13:45:50 -0700 | [diff] [blame] | 887 | if (!IS_ENABLED(CONFIG_ATH9K_TX99)) { |
Luis R. Rodriguez | 89f927a | 2013-10-14 17:42:11 -0700 | [diff] [blame] | 888 | hw->wiphy->interface_modes = |
| 889 | BIT(NL80211_IFTYPE_P2P_GO) | |
| 890 | BIT(NL80211_IFTYPE_P2P_CLIENT) | |
| 891 | BIT(NL80211_IFTYPE_AP) | |
Luis R. Rodriguez | 89f927a | 2013-10-14 17:42:11 -0700 | [diff] [blame] | 892 | BIT(NL80211_IFTYPE_STATION) | |
| 893 | BIT(NL80211_IFTYPE_ADHOC) | |
Sujith Manoharan | 499afac | 2014-08-22 20:39:31 +0530 | [diff] [blame] | 894 | BIT(NL80211_IFTYPE_MESH_POINT) | |
Jan Kaisrlik | 862a336 | 2015-09-17 14:03:46 +0200 | [diff] [blame] | 895 | BIT(NL80211_IFTYPE_WDS) | |
| 896 | BIT(NL80211_IFTYPE_OCB); |
Sujith Manoharan | 499afac | 2014-08-22 20:39:31 +0530 | [diff] [blame] | 897 | |
[email protected] | eb61f9f | 2015-07-21 11:11:40 +0200 | [diff] [blame] | 898 | if (ath9k_is_chanctx_enabled()) |
| 899 | hw->wiphy->interface_modes |= |
| 900 | BIT(NL80211_IFTYPE_P2P_DEVICE); |
| 901 | |
Arnd Bergmann | 362210e | 2016-03-14 15:18:37 +0100 | [diff] [blame] | 902 | hw->wiphy->iface_combinations = if_comb; |
| 903 | hw->wiphy->n_iface_combinations = ARRAY_SIZE(if_comb); |
Luis R. Rodriguez | 89f927a | 2013-10-14 17:42:11 -0700 | [diff] [blame] | 904 | } |
Felix Fietkau | 20c8e8d | 2012-04-17 02:40:07 +0200 | [diff] [blame] | 905 | |
Sujith Manoharan | 531671c | 2013-06-01 07:08:09 +0530 | [diff] [blame] | 906 | hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT; |
Sujith | 5562420 | 2010-01-08 10:36:02 +0530 | [diff] [blame] | 907 | |
Jouni Malinen | cfdc9a8 | 2011-03-23 14:52:19 +0200 | [diff] [blame] | 908 | hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN; |
Jouni Malinen | fd65623 | 2011-10-27 17:31:50 +0300 | [diff] [blame] | 909 | hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS; |
Johannes Berg | 81ddbb5 | 2012-03-26 18:47:18 +0200 | [diff] [blame] | 910 | hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL; |
Simon Wunderlich | 6fac8bb | 2013-08-14 08:01:34 +0200 | [diff] [blame] | 911 | hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_5_10_MHZ; |
Simon Wunderlich | d074e8d | 2013-08-14 08:01:38 +0200 | [diff] [blame] | 912 | hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH; |
Jouni Malinen | 7b4f663 | 2014-02-18 20:41:08 +0200 | [diff] [blame] | 913 | hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD; |
Jouni Malinen | cfdc9a8 | 2011-03-23 14:52:19 +0200 | [diff] [blame] | 914 | |
Sujith Manoharan | 868caae | 2014-10-21 19:23:02 +0530 | [diff] [blame] | 915 | hw->queues = 4; |
Sujith | 5562420 | 2010-01-08 10:36:02 +0530 | [diff] [blame] | 916 | hw->max_rates = 4; |
Rajkumar Manoharan | 5f2f9e4 | 2014-06-26 16:54:41 +0530 | [diff] [blame] | 917 | hw->max_listen_interval = 10; |
Felix Fietkau | 6589651 | 2010-01-24 03:26:11 +0100 | [diff] [blame] | 918 | hw->max_rate_tries = 10; |
Sujith | 5562420 | 2010-01-08 10:36:02 +0530 | [diff] [blame] | 919 | hw->sta_data_size = sizeof(struct ath_node); |
| 920 | hw->vif_data_size = sizeof(struct ath_vif); |
Toke Høiland-Jørgensen | 50f08ed | 2016-11-09 12:31:49 +0100 | [diff] [blame^] | 921 | hw->txq_data_size = sizeof(struct ath_atx_tid); |
Felix Fietkau | 029cd03 | 2015-09-24 16:59:46 +0200 | [diff] [blame] | 922 | hw->extra_tx_headroom = 4; |
Sujith | 5562420 | 2010-01-08 10:36:02 +0530 | [diff] [blame] | 923 | |
Felix Fietkau | 43c3528 | 2011-09-03 01:40:27 +0200 | [diff] [blame] | 924 | hw->wiphy->available_antennas_rx = BIT(ah->caps.max_rxchains) - 1; |
| 925 | hw->wiphy->available_antennas_tx = BIT(ah->caps.max_txchains) - 1; |
| 926 | |
| 927 | /* single chain devices with rx diversity */ |
| 928 | if (ah->caps.hw_caps & ATH9K_HW_CAP_ANT_DIV_COMB) |
| 929 | hw->wiphy->available_antennas_rx = BIT(0) | BIT(1); |
| 930 | |
| 931 | sc->ant_rx = hw->wiphy->available_antennas_rx; |
| 932 | sc->ant_tx = hw->wiphy->available_antennas_tx; |
| 933 | |
Felix Fietkau | d465991 | 2010-10-14 16:02:39 +0200 | [diff] [blame] | 934 | if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_2GHZ) |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 935 | hw->wiphy->bands[NL80211_BAND_2GHZ] = |
| 936 | &common->sbands[NL80211_BAND_2GHZ]; |
Felix Fietkau | d465991 | 2010-10-14 16:02:39 +0200 | [diff] [blame] | 937 | if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_5GHZ) |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 938 | hw->wiphy->bands[NL80211_BAND_5GHZ] = |
| 939 | &common->sbands[NL80211_BAND_5GHZ]; |
Sujith | 285f2dd | 2010-01-08 10:36:07 +0530 | [diff] [blame] | 940 | |
Sujith Manoharan | 868caae | 2014-10-21 19:23:02 +0530 | [diff] [blame] | 941 | #ifdef CONFIG_ATH9K_CHANNEL_CONTEXT |
| 942 | ath9k_set_mcc_capab(sc, hw); |
| 943 | #endif |
Sujith Manoharan | babaa80 | 2013-10-28 13:01:28 +0530 | [diff] [blame] | 944 | ath9k_init_wow(hw); |
Oleksij Rempel | b57ba3b | 2014-02-25 14:48:55 +0100 | [diff] [blame] | 945 | ath9k_cmn_reload_chainmask(ah); |
Sujith | 285f2dd | 2010-01-08 10:36:07 +0530 | [diff] [blame] | 946 | |
| 947 | SET_IEEE80211_PERM_ADDR(hw, common->macaddr); |
Sujith | 5562420 | 2010-01-08 10:36:02 +0530 | [diff] [blame] | 948 | } |
| 949 | |
Pavel Roskin | eb93e89 | 2011-07-23 03:55:39 -0400 | [diff] [blame] | 950 | int ath9k_init_device(u16 devid, struct ath_softc *sc, |
Sujith | 5562420 | 2010-01-08 10:36:02 +0530 | [diff] [blame] | 951 | const struct ath_bus_ops *bus_ops) |
| 952 | { |
| 953 | struct ieee80211_hw *hw = sc->hw; |
| 954 | struct ath_common *common; |
| 955 | struct ath_hw *ah; |
Sujith | 285f2dd | 2010-01-08 10:36:07 +0530 | [diff] [blame] | 956 | int error = 0; |
Sujith | 5562420 | 2010-01-08 10:36:02 +0530 | [diff] [blame] | 957 | struct ath_regulatory *reg; |
| 958 | |
Sujith | 285f2dd | 2010-01-08 10:36:07 +0530 | [diff] [blame] | 959 | /* Bring up device */ |
Pavel Roskin | eb93e89 | 2011-07-23 03:55:39 -0400 | [diff] [blame] | 960 | error = ath9k_init_softc(devid, sc, bus_ops); |
Felix Fietkau | b81950b1 | 2012-12-12 13:14:22 +0100 | [diff] [blame] | 961 | if (error) |
| 962 | return error; |
Sujith | 5562420 | 2010-01-08 10:36:02 +0530 | [diff] [blame] | 963 | |
| 964 | ah = sc->sc_ah; |
| 965 | common = ath9k_hw_common(ah); |
Sujith | 285f2dd | 2010-01-08 10:36:07 +0530 | [diff] [blame] | 966 | ath9k_set_hw_capab(sc, hw); |
Sujith | 5562420 | 2010-01-08 10:36:02 +0530 | [diff] [blame] | 967 | |
Sujith | 285f2dd | 2010-01-08 10:36:07 +0530 | [diff] [blame] | 968 | /* Initialize regulatory */ |
Sujith | 5562420 | 2010-01-08 10:36:02 +0530 | [diff] [blame] | 969 | error = ath_regd_init(&common->regulatory, sc->hw->wiphy, |
| 970 | ath9k_reg_notifier); |
| 971 | if (error) |
Felix Fietkau | b81950b1 | 2012-12-12 13:14:22 +0100 | [diff] [blame] | 972 | goto deinit; |
Sujith | 5562420 | 2010-01-08 10:36:02 +0530 | [diff] [blame] | 973 | |
| 974 | reg = &common->regulatory; |
| 975 | |
Sujith | 285f2dd | 2010-01-08 10:36:07 +0530 | [diff] [blame] | 976 | /* Setup TX DMA */ |
Sujith | 5562420 | 2010-01-08 10:36:02 +0530 | [diff] [blame] | 977 | error = ath_tx_init(sc, ATH_TXBUF); |
| 978 | if (error != 0) |
Felix Fietkau | b81950b1 | 2012-12-12 13:14:22 +0100 | [diff] [blame] | 979 | goto deinit; |
Sujith | 5562420 | 2010-01-08 10:36:02 +0530 | [diff] [blame] | 980 | |
Sujith | 285f2dd | 2010-01-08 10:36:07 +0530 | [diff] [blame] | 981 | /* Setup RX DMA */ |
Sujith | 5562420 | 2010-01-08 10:36:02 +0530 | [diff] [blame] | 982 | error = ath_rx_init(sc, ATH_RXBUF); |
| 983 | if (error != 0) |
Felix Fietkau | b81950b1 | 2012-12-12 13:14:22 +0100 | [diff] [blame] | 984 | goto deinit; |
Sujith | 285f2dd | 2010-01-08 10:36:07 +0530 | [diff] [blame] | 985 | |
Felix Fietkau | babcbc2 | 2010-10-20 02:09:46 +0200 | [diff] [blame] | 986 | ath9k_init_txpower_limits(sc); |
| 987 | |
Felix Fietkau | 0cf55c2 | 2011-02-27 22:26:40 +0100 | [diff] [blame] | 988 | #ifdef CONFIG_MAC80211_LEDS |
| 989 | /* must be initialized before ieee80211_register_hw */ |
| 990 | sc->led_cdev.default_trigger = ieee80211_create_tpt_led_trigger(sc->hw, |
| 991 | IEEE80211_TPT_LEDTRIG_FL_RADIO, ath9k_tpt_blink, |
| 992 | ARRAY_SIZE(ath9k_tpt_blink)); |
| 993 | #endif |
| 994 | |
Sujith | 285f2dd | 2010-01-08 10:36:07 +0530 | [diff] [blame] | 995 | /* Register with mac80211 */ |
| 996 | error = ieee80211_register_hw(hw); |
| 997 | if (error) |
Felix Fietkau | b81950b1 | 2012-12-12 13:14:22 +0100 | [diff] [blame] | 998 | goto rx_cleanup; |
Sujith | 285f2dd | 2010-01-08 10:36:07 +0530 | [diff] [blame] | 999 | |
Ben Greear | eb27244 | 2010-11-29 14:13:22 -0800 | [diff] [blame] | 1000 | error = ath9k_init_debug(ah); |
| 1001 | if (error) { |
Joe Perches | 3800276 | 2010-12-02 19:12:36 -0800 | [diff] [blame] | 1002 | ath_err(common, "Unable to create debugfs files\n"); |
Felix Fietkau | b81950b1 | 2012-12-12 13:14:22 +0100 | [diff] [blame] | 1003 | goto unregister; |
Ben Greear | eb27244 | 2010-11-29 14:13:22 -0800 | [diff] [blame] | 1004 | } |
| 1005 | |
Sujith | 285f2dd | 2010-01-08 10:36:07 +0530 | [diff] [blame] | 1006 | /* Handle world regulatory */ |
| 1007 | if (!ath_is_world_regd(reg)) { |
| 1008 | error = regulatory_hint(hw->wiphy, reg->alpha2); |
| 1009 | if (error) |
Sujith Manoharan | af69009 | 2013-05-10 18:41:06 +0530 | [diff] [blame] | 1010 | goto debug_cleanup; |
Sujith | 285f2dd | 2010-01-08 10:36:07 +0530 | [diff] [blame] | 1011 | } |
Sujith | 5562420 | 2010-01-08 10:36:02 +0530 | [diff] [blame] | 1012 | |
Sujith | 5562420 | 2010-01-08 10:36:02 +0530 | [diff] [blame] | 1013 | ath_init_leds(sc); |
Sujith | 5562420 | 2010-01-08 10:36:02 +0530 | [diff] [blame] | 1014 | ath_start_rfkill_poll(sc); |
| 1015 | |
| 1016 | return 0; |
| 1017 | |
Sujith Manoharan | af69009 | 2013-05-10 18:41:06 +0530 | [diff] [blame] | 1018 | debug_cleanup: |
| 1019 | ath9k_deinit_debug(sc); |
Felix Fietkau | b81950b1 | 2012-12-12 13:14:22 +0100 | [diff] [blame] | 1020 | unregister: |
Sujith | 285f2dd | 2010-01-08 10:36:07 +0530 | [diff] [blame] | 1021 | ieee80211_unregister_hw(hw); |
Felix Fietkau | b81950b1 | 2012-12-12 13:14:22 +0100 | [diff] [blame] | 1022 | rx_cleanup: |
Sujith | 285f2dd | 2010-01-08 10:36:07 +0530 | [diff] [blame] | 1023 | ath_rx_cleanup(sc); |
Felix Fietkau | b81950b1 | 2012-12-12 13:14:22 +0100 | [diff] [blame] | 1024 | deinit: |
Sujith | 285f2dd | 2010-01-08 10:36:07 +0530 | [diff] [blame] | 1025 | ath9k_deinit_softc(sc); |
Sujith | 5562420 | 2010-01-08 10:36:02 +0530 | [diff] [blame] | 1026 | return error; |
| 1027 | } |
| 1028 | |
| 1029 | /*****************************/ |
| 1030 | /* De-Initialization */ |
| 1031 | /*****************************/ |
| 1032 | |
Sujith | 285f2dd | 2010-01-08 10:36:07 +0530 | [diff] [blame] | 1033 | static void ath9k_deinit_softc(struct ath_softc *sc) |
Sujith | 5562420 | 2010-01-08 10:36:02 +0530 | [diff] [blame] | 1034 | { |
Sujith | 285f2dd | 2010-01-08 10:36:07 +0530 | [diff] [blame] | 1035 | int i = 0; |
Sujith | 5562420 | 2010-01-08 10:36:02 +0530 | [diff] [blame] | 1036 | |
Sujith Manoharan | c7dd40c | 2014-08-22 20:39:30 +0530 | [diff] [blame] | 1037 | ath9k_deinit_p2p(sc); |
Sujith Manoharan | 5908120 | 2012-02-22 12:40:21 +0530 | [diff] [blame] | 1038 | ath9k_deinit_btcoex(sc); |
Mohammed Shafi Shajakhan | 19686dd | 2011-11-30 10:41:28 +0530 | [diff] [blame] | 1039 | |
Sujith | 285f2dd | 2010-01-08 10:36:07 +0530 | [diff] [blame] | 1040 | for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++) |
| 1041 | if (ATH_TXQ_SETUP(sc, i)) |
| 1042 | ath_tx_cleanupq(sc, &sc->tx.txq[i]); |
| 1043 | |
Felix Fietkau | bf3dac5 | 2013-11-11 22:23:33 +0100 | [diff] [blame] | 1044 | del_timer_sync(&sc->sleep_timer); |
Sujith | 285f2dd | 2010-01-08 10:36:07 +0530 | [diff] [blame] | 1045 | ath9k_hw_deinit(sc->sc_ah); |
Zefir Kurtisi | 8e92d3f | 2012-04-03 17:15:50 +0200 | [diff] [blame] | 1046 | if (sc->dfs_detector != NULL) |
| 1047 | sc->dfs_detector->exit(sc->dfs_detector); |
Sujith | 285f2dd | 2010-01-08 10:36:07 +0530 | [diff] [blame] | 1048 | |
Gabor Juhos | ab5c4f7 | 2012-12-10 15:30:28 +0100 | [diff] [blame] | 1049 | ath9k_eeprom_release(sc); |
Sujith | 5562420 | 2010-01-08 10:36:02 +0530 | [diff] [blame] | 1050 | } |
| 1051 | |
Sujith | 285f2dd | 2010-01-08 10:36:07 +0530 | [diff] [blame] | 1052 | void ath9k_deinit_device(struct ath_softc *sc) |
Sujith | 5562420 | 2010-01-08 10:36:02 +0530 | [diff] [blame] | 1053 | { |
| 1054 | struct ieee80211_hw *hw = sc->hw; |
Sujith | 5562420 | 2010-01-08 10:36:02 +0530 | [diff] [blame] | 1055 | |
| 1056 | ath9k_ps_wakeup(sc); |
| 1057 | |
Sujith | 5562420 | 2010-01-08 10:36:02 +0530 | [diff] [blame] | 1058 | wiphy_rfkill_stop_polling(sc->hw->wiphy); |
Sujith | 285f2dd | 2010-01-08 10:36:07 +0530 | [diff] [blame] | 1059 | ath_deinit_leds(sc); |
Sujith | 5562420 | 2010-01-08 10:36:02 +0530 | [diff] [blame] | 1060 | |
Rajkumar Manoharan | c7c1806 | 2011-01-27 18:39:38 +0530 | [diff] [blame] | 1061 | ath9k_ps_restore(sc); |
| 1062 | |
Sujith Manoharan | af69009 | 2013-05-10 18:41:06 +0530 | [diff] [blame] | 1063 | ath9k_deinit_debug(sc); |
Sujith Manoharan | 661d258 | 2015-01-30 19:05:26 +0530 | [diff] [blame] | 1064 | ath9k_deinit_wow(hw); |
Sujith | 5562420 | 2010-01-08 10:36:02 +0530 | [diff] [blame] | 1065 | ieee80211_unregister_hw(hw); |
| 1066 | ath_rx_cleanup(sc); |
Sujith | 285f2dd | 2010-01-08 10:36:07 +0530 | [diff] [blame] | 1067 | ath9k_deinit_softc(sc); |
Sujith | 5562420 | 2010-01-08 10:36:02 +0530 | [diff] [blame] | 1068 | } |
| 1069 | |
Sujith | 5562420 | 2010-01-08 10:36:02 +0530 | [diff] [blame] | 1070 | /************************/ |
| 1071 | /* Module Hooks */ |
| 1072 | /************************/ |
| 1073 | |
| 1074 | static int __init ath9k_init(void) |
| 1075 | { |
| 1076 | int error; |
| 1077 | |
Sujith | 5562420 | 2010-01-08 10:36:02 +0530 | [diff] [blame] | 1078 | error = ath_pci_init(); |
| 1079 | if (error < 0) { |
Joe Perches | 516304b | 2012-03-18 17:30:52 -0700 | [diff] [blame] | 1080 | pr_err("No PCI devices found, driver not installed\n"); |
Sujith | 5562420 | 2010-01-08 10:36:02 +0530 | [diff] [blame] | 1081 | error = -ENODEV; |
Sujith Manoharan | 9e495a2 | 2014-02-06 10:22:55 +0530 | [diff] [blame] | 1082 | goto err_out; |
Sujith | 5562420 | 2010-01-08 10:36:02 +0530 | [diff] [blame] | 1083 | } |
| 1084 | |
| 1085 | error = ath_ahb_init(); |
| 1086 | if (error < 0) { |
| 1087 | error = -ENODEV; |
| 1088 | goto err_pci_exit; |
| 1089 | } |
| 1090 | |
| 1091 | return 0; |
| 1092 | |
| 1093 | err_pci_exit: |
| 1094 | ath_pci_exit(); |
Sujith | 5562420 | 2010-01-08 10:36:02 +0530 | [diff] [blame] | 1095 | err_out: |
| 1096 | return error; |
| 1097 | } |
| 1098 | module_init(ath9k_init); |
| 1099 | |
| 1100 | static void __exit ath9k_exit(void) |
| 1101 | { |
Rajkumar Manoharan | d584747 | 2010-12-20 14:39:51 +0530 | [diff] [blame] | 1102 | is_ath9k_unloaded = true; |
Sujith | 5562420 | 2010-01-08 10:36:02 +0530 | [diff] [blame] | 1103 | ath_ahb_exit(); |
| 1104 | ath_pci_exit(); |
Joe Perches | 516304b | 2012-03-18 17:30:52 -0700 | [diff] [blame] | 1105 | pr_info("%s: Driver unloaded\n", dev_info); |
Sujith | 5562420 | 2010-01-08 10:36:02 +0530 | [diff] [blame] | 1106 | } |
| 1107 | module_exit(ath9k_exit); |