init.c 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150
  1. /*
  2. * Copyright (c) 2008-2011 Atheros Communications Inc.
  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. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  17. #include <linux/dma-mapping.h>
  18. #include <linux/slab.h>
  19. #include <linux/ath9k_platform.h>
  20. #include <linux/module.h>
  21. #include <linux/relay.h>
  22. #include <net/ieee80211_radiotap.h>
  23. #include "ath9k.h"
  24. struct ath9k_eeprom_ctx {
  25. struct completion complete;
  26. struct ath_hw *ah;
  27. };
  28. static char *dev_info = "ath9k";
  29. MODULE_AUTHOR("Atheros Communications");
  30. MODULE_DESCRIPTION("Support for Atheros 802.11n wireless LAN cards.");
  31. MODULE_SUPPORTED_DEVICE("Atheros 802.11n WLAN cards");
  32. MODULE_LICENSE("Dual BSD/GPL");
  33. static unsigned int ath9k_debug = ATH_DBG_DEFAULT;
  34. module_param_named(debug, ath9k_debug, uint, 0);
  35. MODULE_PARM_DESC(debug, "Debugging mask");
  36. int ath9k_modparam_nohwcrypt;
  37. module_param_named(nohwcrypt, ath9k_modparam_nohwcrypt, int, 0444);
  38. MODULE_PARM_DESC(nohwcrypt, "Disable hardware encryption");
  39. int led_blink;
  40. module_param_named(blink, led_blink, int, 0444);
  41. MODULE_PARM_DESC(blink, "Enable LED blink on activity");
  42. static int ath9k_btcoex_enable;
  43. module_param_named(btcoex_enable, ath9k_btcoex_enable, int, 0444);
  44. MODULE_PARM_DESC(btcoex_enable, "Enable wifi-BT coexistence");
  45. static int ath9k_bt_ant_diversity;
  46. module_param_named(bt_ant_diversity, ath9k_bt_ant_diversity, int, 0444);
  47. MODULE_PARM_DESC(bt_ant_diversity, "Enable WLAN/BT RX antenna diversity");
  48. static int ath9k_ps_enable;
  49. module_param_named(ps_enable, ath9k_ps_enable, int, 0444);
  50. MODULE_PARM_DESC(ps_enable, "Enable WLAN PowerSave");
  51. bool is_ath9k_unloaded;
  52. /* We use the hw_value as an index into our private channel structure */
  53. #define CHAN2G(_freq, _idx) { \
  54. .band = IEEE80211_BAND_2GHZ, \
  55. .center_freq = (_freq), \
  56. .hw_value = (_idx), \
  57. .max_power = 20, \
  58. }
  59. #define CHAN5G(_freq, _idx) { \
  60. .band = IEEE80211_BAND_5GHZ, \
  61. .center_freq = (_freq), \
  62. .hw_value = (_idx), \
  63. .max_power = 20, \
  64. }
  65. /* Some 2 GHz radios are actually tunable on 2312-2732
  66. * on 5 MHz steps, we support the channels which we know
  67. * we have calibration data for all cards though to make
  68. * this static */
  69. static const struct ieee80211_channel ath9k_2ghz_chantable[] = {
  70. CHAN2G(2412, 0), /* Channel 1 */
  71. CHAN2G(2417, 1), /* Channel 2 */
  72. CHAN2G(2422, 2), /* Channel 3 */
  73. CHAN2G(2427, 3), /* Channel 4 */
  74. CHAN2G(2432, 4), /* Channel 5 */
  75. CHAN2G(2437, 5), /* Channel 6 */
  76. CHAN2G(2442, 6), /* Channel 7 */
  77. CHAN2G(2447, 7), /* Channel 8 */
  78. CHAN2G(2452, 8), /* Channel 9 */
  79. CHAN2G(2457, 9), /* Channel 10 */
  80. CHAN2G(2462, 10), /* Channel 11 */
  81. CHAN2G(2467, 11), /* Channel 12 */
  82. CHAN2G(2472, 12), /* Channel 13 */
  83. CHAN2G(2484, 13), /* Channel 14 */
  84. };
  85. /* Some 5 GHz radios are actually tunable on XXXX-YYYY
  86. * on 5 MHz steps, we support the channels which we know
  87. * we have calibration data for all cards though to make
  88. * this static */
  89. static const struct ieee80211_channel ath9k_5ghz_chantable[] = {
  90. /* _We_ call this UNII 1 */
  91. CHAN5G(5180, 14), /* Channel 36 */
  92. CHAN5G(5200, 15), /* Channel 40 */
  93. CHAN5G(5220, 16), /* Channel 44 */
  94. CHAN5G(5240, 17), /* Channel 48 */
  95. /* _We_ call this UNII 2 */
  96. CHAN5G(5260, 18), /* Channel 52 */
  97. CHAN5G(5280, 19), /* Channel 56 */
  98. CHAN5G(5300, 20), /* Channel 60 */
  99. CHAN5G(5320, 21), /* Channel 64 */
  100. /* _We_ call this "Middle band" */
  101. CHAN5G(5500, 22), /* Channel 100 */
  102. CHAN5G(5520, 23), /* Channel 104 */
  103. CHAN5G(5540, 24), /* Channel 108 */
  104. CHAN5G(5560, 25), /* Channel 112 */
  105. CHAN5G(5580, 26), /* Channel 116 */
  106. CHAN5G(5600, 27), /* Channel 120 */
  107. CHAN5G(5620, 28), /* Channel 124 */
  108. CHAN5G(5640, 29), /* Channel 128 */
  109. CHAN5G(5660, 30), /* Channel 132 */
  110. CHAN5G(5680, 31), /* Channel 136 */
  111. CHAN5G(5700, 32), /* Channel 140 */
  112. /* _We_ call this UNII 3 */
  113. CHAN5G(5745, 33), /* Channel 149 */
  114. CHAN5G(5765, 34), /* Channel 153 */
  115. CHAN5G(5785, 35), /* Channel 157 */
  116. CHAN5G(5805, 36), /* Channel 161 */
  117. CHAN5G(5825, 37), /* Channel 165 */
  118. };
  119. /* Atheros hardware rate code addition for short premble */
  120. #define SHPCHECK(__hw_rate, __flags) \
  121. ((__flags & IEEE80211_RATE_SHORT_PREAMBLE) ? (__hw_rate | 0x04 ) : 0)
  122. #define RATE(_bitrate, _hw_rate, _flags) { \
  123. .bitrate = (_bitrate), \
  124. .flags = (_flags), \
  125. .hw_value = (_hw_rate), \
  126. .hw_value_short = (SHPCHECK(_hw_rate, _flags)) \
  127. }
  128. static struct ieee80211_rate ath9k_legacy_rates[] = {
  129. RATE(10, 0x1b, 0),
  130. RATE(20, 0x1a, IEEE80211_RATE_SHORT_PREAMBLE),
  131. RATE(55, 0x19, IEEE80211_RATE_SHORT_PREAMBLE),
  132. RATE(110, 0x18, IEEE80211_RATE_SHORT_PREAMBLE),
  133. RATE(60, 0x0b, (IEEE80211_RATE_SUPPORTS_5MHZ |
  134. IEEE80211_RATE_SUPPORTS_10MHZ)),
  135. RATE(90, 0x0f, (IEEE80211_RATE_SUPPORTS_5MHZ |
  136. IEEE80211_RATE_SUPPORTS_10MHZ)),
  137. RATE(120, 0x0a, (IEEE80211_RATE_SUPPORTS_5MHZ |
  138. IEEE80211_RATE_SUPPORTS_10MHZ)),
  139. RATE(180, 0x0e, (IEEE80211_RATE_SUPPORTS_5MHZ |
  140. IEEE80211_RATE_SUPPORTS_10MHZ)),
  141. RATE(240, 0x09, (IEEE80211_RATE_SUPPORTS_5MHZ |
  142. IEEE80211_RATE_SUPPORTS_10MHZ)),
  143. RATE(360, 0x0d, (IEEE80211_RATE_SUPPORTS_5MHZ |
  144. IEEE80211_RATE_SUPPORTS_10MHZ)),
  145. RATE(480, 0x08, (IEEE80211_RATE_SUPPORTS_5MHZ |
  146. IEEE80211_RATE_SUPPORTS_10MHZ)),
  147. RATE(540, 0x0c, (IEEE80211_RATE_SUPPORTS_5MHZ |
  148. IEEE80211_RATE_SUPPORTS_10MHZ)),
  149. };
  150. #ifdef CONFIG_MAC80211_LEDS
  151. static const struct ieee80211_tpt_blink ath9k_tpt_blink[] = {
  152. { .throughput = 0 * 1024, .blink_time = 334 },
  153. { .throughput = 1 * 1024, .blink_time = 260 },
  154. { .throughput = 5 * 1024, .blink_time = 220 },
  155. { .throughput = 10 * 1024, .blink_time = 190 },
  156. { .throughput = 20 * 1024, .blink_time = 170 },
  157. { .throughput = 50 * 1024, .blink_time = 150 },
  158. { .throughput = 70 * 1024, .blink_time = 130 },
  159. { .throughput = 100 * 1024, .blink_time = 110 },
  160. { .throughput = 200 * 1024, .blink_time = 80 },
  161. { .throughput = 300 * 1024, .blink_time = 50 },
  162. };
  163. #endif
  164. static void ath9k_deinit_softc(struct ath_softc *sc);
  165. /*
  166. * Read and write, they both share the same lock. We do this to serialize
  167. * reads and writes on Atheros 802.11n PCI devices only. This is required
  168. * as the FIFO on these devices can only accept sanely 2 requests.
  169. */
  170. static void ath9k_iowrite32(void *hw_priv, u32 val, u32 reg_offset)
  171. {
  172. struct ath_hw *ah = (struct ath_hw *) hw_priv;
  173. struct ath_common *common = ath9k_hw_common(ah);
  174. struct ath_softc *sc = (struct ath_softc *) common->priv;
  175. if (NR_CPUS > 1 && ah->config.serialize_regmode == SER_REG_MODE_ON) {
  176. unsigned long flags;
  177. spin_lock_irqsave(&sc->sc_serial_rw, flags);
  178. iowrite32(val, sc->mem + reg_offset);
  179. spin_unlock_irqrestore(&sc->sc_serial_rw, flags);
  180. } else
  181. iowrite32(val, sc->mem + reg_offset);
  182. }
  183. static unsigned int ath9k_ioread32(void *hw_priv, u32 reg_offset)
  184. {
  185. struct ath_hw *ah = (struct ath_hw *) hw_priv;
  186. struct ath_common *common = ath9k_hw_common(ah);
  187. struct ath_softc *sc = (struct ath_softc *) common->priv;
  188. u32 val;
  189. if (NR_CPUS > 1 && ah->config.serialize_regmode == SER_REG_MODE_ON) {
  190. unsigned long flags;
  191. spin_lock_irqsave(&sc->sc_serial_rw, flags);
  192. val = ioread32(sc->mem + reg_offset);
  193. spin_unlock_irqrestore(&sc->sc_serial_rw, flags);
  194. } else
  195. val = ioread32(sc->mem + reg_offset);
  196. return val;
  197. }
  198. static unsigned int __ath9k_reg_rmw(struct ath_softc *sc, u32 reg_offset,
  199. u32 set, u32 clr)
  200. {
  201. u32 val;
  202. val = ioread32(sc->mem + reg_offset);
  203. val &= ~clr;
  204. val |= set;
  205. iowrite32(val, sc->mem + reg_offset);
  206. return val;
  207. }
  208. static unsigned int ath9k_reg_rmw(void *hw_priv, u32 reg_offset, u32 set, u32 clr)
  209. {
  210. struct ath_hw *ah = (struct ath_hw *) hw_priv;
  211. struct ath_common *common = ath9k_hw_common(ah);
  212. struct ath_softc *sc = (struct ath_softc *) common->priv;
  213. unsigned long uninitialized_var(flags);
  214. u32 val;
  215. if (NR_CPUS > 1 && ah->config.serialize_regmode == SER_REG_MODE_ON) {
  216. spin_lock_irqsave(&sc->sc_serial_rw, flags);
  217. val = __ath9k_reg_rmw(sc, reg_offset, set, clr);
  218. spin_unlock_irqrestore(&sc->sc_serial_rw, flags);
  219. } else
  220. val = __ath9k_reg_rmw(sc, reg_offset, set, clr);
  221. return val;
  222. }
  223. /**************************/
  224. /* Initialization */
  225. /**************************/
  226. static void setup_ht_cap(struct ath_softc *sc,
  227. struct ieee80211_sta_ht_cap *ht_info)
  228. {
  229. struct ath_hw *ah = sc->sc_ah;
  230. struct ath_common *common = ath9k_hw_common(ah);
  231. u8 tx_streams, rx_streams;
  232. int i, max_streams;
  233. ht_info->ht_supported = true;
  234. ht_info->cap = IEEE80211_HT_CAP_SUP_WIDTH_20_40 |
  235. IEEE80211_HT_CAP_SM_PS |
  236. IEEE80211_HT_CAP_SGI_40 |
  237. IEEE80211_HT_CAP_DSSSCCK40;
  238. if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_LDPC)
  239. ht_info->cap |= IEEE80211_HT_CAP_LDPC_CODING;
  240. if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_SGI_20)
  241. ht_info->cap |= IEEE80211_HT_CAP_SGI_20;
  242. ht_info->ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
  243. ht_info->ampdu_density = IEEE80211_HT_MPDU_DENSITY_8;
  244. if (AR_SREV_9330(ah) || AR_SREV_9485(ah) || AR_SREV_9565(ah))
  245. max_streams = 1;
  246. else if (AR_SREV_9462(ah))
  247. max_streams = 2;
  248. else if (AR_SREV_9300_20_OR_LATER(ah))
  249. max_streams = 3;
  250. else
  251. max_streams = 2;
  252. if (AR_SREV_9280_20_OR_LATER(ah)) {
  253. if (max_streams >= 2)
  254. ht_info->cap |= IEEE80211_HT_CAP_TX_STBC;
  255. ht_info->cap |= (1 << IEEE80211_HT_CAP_RX_STBC_SHIFT);
  256. }
  257. /* set up supported mcs set */
  258. memset(&ht_info->mcs, 0, sizeof(ht_info->mcs));
  259. tx_streams = ath9k_cmn_count_streams(ah->txchainmask, max_streams);
  260. rx_streams = ath9k_cmn_count_streams(ah->rxchainmask, max_streams);
  261. ath_dbg(common, CONFIG, "TX streams %d, RX streams: %d\n",
  262. tx_streams, rx_streams);
  263. if (tx_streams != rx_streams) {
  264. ht_info->mcs.tx_params |= IEEE80211_HT_MCS_TX_RX_DIFF;
  265. ht_info->mcs.tx_params |= ((tx_streams - 1) <<
  266. IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT);
  267. }
  268. for (i = 0; i < rx_streams; i++)
  269. ht_info->mcs.rx_mask[i] = 0xff;
  270. ht_info->mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
  271. }
  272. static void ath9k_reg_notifier(struct wiphy *wiphy,
  273. struct regulatory_request *request)
  274. {
  275. struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
  276. struct ath_softc *sc = hw->priv;
  277. struct ath_hw *ah = sc->sc_ah;
  278. struct ath_regulatory *reg = ath9k_hw_regulatory(ah);
  279. ath_reg_notifier_apply(wiphy, request, reg);
  280. /* Set tx power */
  281. if (ah->curchan) {
  282. sc->config.txpowlimit = 2 * ah->curchan->chan->max_power;
  283. ath9k_ps_wakeup(sc);
  284. ath9k_hw_set_txpowerlimit(ah, sc->config.txpowlimit, false);
  285. sc->curtxpow = ath9k_hw_regulatory(ah)->power_limit;
  286. /* synchronize DFS detector if regulatory domain changed */
  287. if (sc->dfs_detector != NULL)
  288. sc->dfs_detector->set_dfs_domain(sc->dfs_detector,
  289. request->dfs_region);
  290. ath9k_ps_restore(sc);
  291. }
  292. }
  293. /*
  294. * This function will allocate both the DMA descriptor structure, and the
  295. * buffers it contains. These are used to contain the descriptors used
  296. * by the system.
  297. */
  298. int ath_descdma_setup(struct ath_softc *sc, struct ath_descdma *dd,
  299. struct list_head *head, const char *name,
  300. int nbuf, int ndesc, bool is_tx)
  301. {
  302. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  303. u8 *ds;
  304. int i, bsize, desc_len;
  305. ath_dbg(common, CONFIG, "%s DMA: %u buffers %u desc/buf\n",
  306. name, nbuf, ndesc);
  307. INIT_LIST_HEAD(head);
  308. if (is_tx)
  309. desc_len = sc->sc_ah->caps.tx_desc_len;
  310. else
  311. desc_len = sizeof(struct ath_desc);
  312. /* ath_desc must be a multiple of DWORDs */
  313. if ((desc_len % 4) != 0) {
  314. ath_err(common, "ath_desc not DWORD aligned\n");
  315. BUG_ON((desc_len % 4) != 0);
  316. return -ENOMEM;
  317. }
  318. dd->dd_desc_len = desc_len * nbuf * ndesc;
  319. /*
  320. * Need additional DMA memory because we can't use
  321. * descriptors that cross the 4K page boundary. Assume
  322. * one skipped descriptor per 4K page.
  323. */
  324. if (!(sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_4KB_SPLITTRANS)) {
  325. u32 ndesc_skipped =
  326. ATH_DESC_4KB_BOUND_NUM_SKIPPED(dd->dd_desc_len);
  327. u32 dma_len;
  328. while (ndesc_skipped) {
  329. dma_len = ndesc_skipped * desc_len;
  330. dd->dd_desc_len += dma_len;
  331. ndesc_skipped = ATH_DESC_4KB_BOUND_NUM_SKIPPED(dma_len);
  332. }
  333. }
  334. /* allocate descriptors */
  335. dd->dd_desc = dmam_alloc_coherent(sc->dev, dd->dd_desc_len,
  336. &dd->dd_desc_paddr, GFP_KERNEL);
  337. if (!dd->dd_desc)
  338. return -ENOMEM;
  339. ds = (u8 *) dd->dd_desc;
  340. ath_dbg(common, CONFIG, "%s DMA map: %p (%u) -> %llx (%u)\n",
  341. name, ds, (u32) dd->dd_desc_len,
  342. ito64(dd->dd_desc_paddr), /*XXX*/(u32) dd->dd_desc_len);
  343. /* allocate buffers */
  344. if (is_tx) {
  345. struct ath_buf *bf;
  346. bsize = sizeof(struct ath_buf) * nbuf;
  347. bf = devm_kzalloc(sc->dev, bsize, GFP_KERNEL);
  348. if (!bf)
  349. return -ENOMEM;
  350. for (i = 0; i < nbuf; i++, bf++, ds += (desc_len * ndesc)) {
  351. bf->bf_desc = ds;
  352. bf->bf_daddr = DS2PHYS(dd, ds);
  353. if (!(sc->sc_ah->caps.hw_caps &
  354. ATH9K_HW_CAP_4KB_SPLITTRANS)) {
  355. /*
  356. * Skip descriptor addresses which can cause 4KB
  357. * boundary crossing (addr + length) with a 32 dword
  358. * descriptor fetch.
  359. */
  360. while (ATH_DESC_4KB_BOUND_CHECK(bf->bf_daddr)) {
  361. BUG_ON((caddr_t) bf->bf_desc >=
  362. ((caddr_t) dd->dd_desc +
  363. dd->dd_desc_len));
  364. ds += (desc_len * ndesc);
  365. bf->bf_desc = ds;
  366. bf->bf_daddr = DS2PHYS(dd, ds);
  367. }
  368. }
  369. list_add_tail(&bf->list, head);
  370. }
  371. } else {
  372. struct ath_rxbuf *bf;
  373. bsize = sizeof(struct ath_rxbuf) * nbuf;
  374. bf = devm_kzalloc(sc->dev, bsize, GFP_KERNEL);
  375. if (!bf)
  376. return -ENOMEM;
  377. for (i = 0; i < nbuf; i++, bf++, ds += (desc_len * ndesc)) {
  378. bf->bf_desc = ds;
  379. bf->bf_daddr = DS2PHYS(dd, ds);
  380. if (!(sc->sc_ah->caps.hw_caps &
  381. ATH9K_HW_CAP_4KB_SPLITTRANS)) {
  382. /*
  383. * Skip descriptor addresses which can cause 4KB
  384. * boundary crossing (addr + length) with a 32 dword
  385. * descriptor fetch.
  386. */
  387. while (ATH_DESC_4KB_BOUND_CHECK(bf->bf_daddr)) {
  388. BUG_ON((caddr_t) bf->bf_desc >=
  389. ((caddr_t) dd->dd_desc +
  390. dd->dd_desc_len));
  391. ds += (desc_len * ndesc);
  392. bf->bf_desc = ds;
  393. bf->bf_daddr = DS2PHYS(dd, ds);
  394. }
  395. }
  396. list_add_tail(&bf->list, head);
  397. }
  398. }
  399. return 0;
  400. }
  401. static int ath9k_init_queues(struct ath_softc *sc)
  402. {
  403. int i = 0;
  404. sc->beacon.beaconq = ath9k_hw_beaconq_setup(sc->sc_ah);
  405. sc->beacon.cabq = ath_txq_setup(sc, ATH9K_TX_QUEUE_CAB, 0);
  406. ath_cabq_update(sc);
  407. sc->tx.uapsdq = ath_txq_setup(sc, ATH9K_TX_QUEUE_UAPSD, 0);
  408. for (i = 0; i < IEEE80211_NUM_ACS; i++) {
  409. sc->tx.txq_map[i] = ath_txq_setup(sc, ATH9K_TX_QUEUE_DATA, i);
  410. sc->tx.txq_map[i]->mac80211_qnum = i;
  411. sc->tx.txq_max_pending[i] = ATH_MAX_QDEPTH;
  412. }
  413. return 0;
  414. }
  415. static int ath9k_init_channels_rates(struct ath_softc *sc)
  416. {
  417. void *channels;
  418. BUILD_BUG_ON(ARRAY_SIZE(ath9k_2ghz_chantable) +
  419. ARRAY_SIZE(ath9k_5ghz_chantable) !=
  420. ATH9K_NUM_CHANNELS);
  421. if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_2GHZ) {
  422. channels = devm_kzalloc(sc->dev,
  423. sizeof(ath9k_2ghz_chantable), GFP_KERNEL);
  424. if (!channels)
  425. return -ENOMEM;
  426. memcpy(channels, ath9k_2ghz_chantable,
  427. sizeof(ath9k_2ghz_chantable));
  428. sc->sbands[IEEE80211_BAND_2GHZ].channels = channels;
  429. sc->sbands[IEEE80211_BAND_2GHZ].band = IEEE80211_BAND_2GHZ;
  430. sc->sbands[IEEE80211_BAND_2GHZ].n_channels =
  431. ARRAY_SIZE(ath9k_2ghz_chantable);
  432. sc->sbands[IEEE80211_BAND_2GHZ].bitrates = ath9k_legacy_rates;
  433. sc->sbands[IEEE80211_BAND_2GHZ].n_bitrates =
  434. ARRAY_SIZE(ath9k_legacy_rates);
  435. }
  436. if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_5GHZ) {
  437. channels = devm_kzalloc(sc->dev,
  438. sizeof(ath9k_5ghz_chantable), GFP_KERNEL);
  439. if (!channels)
  440. return -ENOMEM;
  441. memcpy(channels, ath9k_5ghz_chantable,
  442. sizeof(ath9k_5ghz_chantable));
  443. sc->sbands[IEEE80211_BAND_5GHZ].channels = channels;
  444. sc->sbands[IEEE80211_BAND_5GHZ].band = IEEE80211_BAND_5GHZ;
  445. sc->sbands[IEEE80211_BAND_5GHZ].n_channels =
  446. ARRAY_SIZE(ath9k_5ghz_chantable);
  447. sc->sbands[IEEE80211_BAND_5GHZ].bitrates =
  448. ath9k_legacy_rates + 4;
  449. sc->sbands[IEEE80211_BAND_5GHZ].n_bitrates =
  450. ARRAY_SIZE(ath9k_legacy_rates) - 4;
  451. }
  452. return 0;
  453. }
  454. static void ath9k_init_misc(struct ath_softc *sc)
  455. {
  456. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  457. int i = 0;
  458. setup_timer(&common->ani.timer, ath_ani_calibrate, (unsigned long)sc);
  459. sc->last_rssi = ATH_RSSI_DUMMY_MARKER;
  460. sc->config.txpowlimit = ATH_TXPOWER_MAX;
  461. memcpy(common->bssidmask, ath_bcast_mac, ETH_ALEN);
  462. sc->beacon.slottime = ATH9K_SLOT_TIME_9;
  463. for (i = 0; i < ARRAY_SIZE(sc->beacon.bslot); i++)
  464. sc->beacon.bslot[i] = NULL;
  465. if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_ANT_DIV_COMB)
  466. sc->ant_comb.count = ATH_ANT_DIV_COMB_INIT_COUNT;
  467. sc->spec_config.enabled = 0;
  468. sc->spec_config.short_repeat = true;
  469. sc->spec_config.count = 8;
  470. sc->spec_config.endless = false;
  471. sc->spec_config.period = 0xFF;
  472. sc->spec_config.fft_period = 0xF;
  473. }
  474. static void ath9k_init_pcoem_platform(struct ath_softc *sc)
  475. {
  476. struct ath_hw *ah = sc->sc_ah;
  477. struct ath9k_hw_capabilities *pCap = &ah->caps;
  478. struct ath_common *common = ath9k_hw_common(ah);
  479. if (common->bus_ops->ath_bus_type != ATH_PCI)
  480. return;
  481. if (sc->driver_data & (ATH9K_PCI_CUS198 |
  482. ATH9K_PCI_CUS230)) {
  483. ah->config.xlna_gpio = 9;
  484. ah->config.xatten_margin_cfg = true;
  485. ah->config.alt_mingainidx = true;
  486. ah->config.ant_ctrl_comm2g_switch_enable = 0x000BBB88;
  487. sc->ant_comb.low_rssi_thresh = 20;
  488. sc->ant_comb.fast_div_bias = 3;
  489. ath_info(common, "Set parameters for %s\n",
  490. (sc->driver_data & ATH9K_PCI_CUS198) ?
  491. "CUS198" : "CUS230");
  492. }
  493. if (sc->driver_data & ATH9K_PCI_CUS217)
  494. ath_info(common, "CUS217 card detected\n");
  495. if (sc->driver_data & ATH9K_PCI_CUS252)
  496. ath_info(common, "CUS252 card detected\n");
  497. if (sc->driver_data & ATH9K_PCI_AR9565_1ANT)
  498. ath_info(common, "WB335 1-ANT card detected\n");
  499. if (sc->driver_data & ATH9K_PCI_AR9565_2ANT)
  500. ath_info(common, "WB335 2-ANT card detected\n");
  501. if (sc->driver_data & ATH9K_PCI_KILLER)
  502. ath_info(common, "Killer Wireless card detected\n");
  503. /*
  504. * Some WB335 cards do not support antenna diversity. Since
  505. * we use a hardcoded value for AR9565 instead of using the
  506. * EEPROM/OTP data, remove the combining feature from
  507. * the HW capabilities bitmap.
  508. */
  509. if (sc->driver_data & (ATH9K_PCI_AR9565_1ANT | ATH9K_PCI_AR9565_2ANT)) {
  510. if (!(sc->driver_data & ATH9K_PCI_BT_ANT_DIV))
  511. pCap->hw_caps &= ~ATH9K_HW_CAP_ANT_DIV_COMB;
  512. }
  513. if (sc->driver_data & ATH9K_PCI_BT_ANT_DIV) {
  514. pCap->hw_caps |= ATH9K_HW_CAP_BT_ANT_DIV;
  515. ath_info(common, "Set BT/WLAN RX diversity capability\n");
  516. }
  517. if (sc->driver_data & ATH9K_PCI_D3_L1_WAR) {
  518. ah->config.pcie_waen = 0x0040473b;
  519. ath_info(common, "Enable WAR for ASPM D3/L1\n");
  520. }
  521. if (sc->driver_data & ATH9K_PCI_NO_PLL_PWRSAVE) {
  522. ah->config.no_pll_pwrsave = true;
  523. ath_info(common, "Disable PLL PowerSave\n");
  524. }
  525. }
  526. static void ath9k_eeprom_request_cb(const struct firmware *eeprom_blob,
  527. void *ctx)
  528. {
  529. struct ath9k_eeprom_ctx *ec = ctx;
  530. if (eeprom_blob)
  531. ec->ah->eeprom_blob = eeprom_blob;
  532. complete(&ec->complete);
  533. }
  534. static int ath9k_eeprom_request(struct ath_softc *sc, const char *name)
  535. {
  536. struct ath9k_eeprom_ctx ec;
  537. struct ath_hw *ah = ah = sc->sc_ah;
  538. int err;
  539. /* try to load the EEPROM content asynchronously */
  540. init_completion(&ec.complete);
  541. ec.ah = sc->sc_ah;
  542. err = request_firmware_nowait(THIS_MODULE, 1, name, sc->dev, GFP_KERNEL,
  543. &ec, ath9k_eeprom_request_cb);
  544. if (err < 0) {
  545. ath_err(ath9k_hw_common(ah),
  546. "EEPROM request failed\n");
  547. return err;
  548. }
  549. wait_for_completion(&ec.complete);
  550. if (!ah->eeprom_blob) {
  551. ath_err(ath9k_hw_common(ah),
  552. "Unable to load EEPROM file %s\n", name);
  553. return -EINVAL;
  554. }
  555. return 0;
  556. }
  557. static void ath9k_eeprom_release(struct ath_softc *sc)
  558. {
  559. release_firmware(sc->sc_ah->eeprom_blob);
  560. }
  561. static int ath9k_init_soc_platform(struct ath_softc *sc)
  562. {
  563. struct ath9k_platform_data *pdata = sc->dev->platform_data;
  564. struct ath_hw *ah = sc->sc_ah;
  565. int ret = 0;
  566. if (!pdata)
  567. return 0;
  568. if (pdata->eeprom_name) {
  569. ret = ath9k_eeprom_request(sc, pdata->eeprom_name);
  570. if (ret)
  571. return ret;
  572. }
  573. if (pdata->tx_gain_buffalo)
  574. ah->config.tx_gain_buffalo = true;
  575. return ret;
  576. }
  577. static int ath9k_init_softc(u16 devid, struct ath_softc *sc,
  578. const struct ath_bus_ops *bus_ops)
  579. {
  580. struct ath9k_platform_data *pdata = sc->dev->platform_data;
  581. struct ath_hw *ah = NULL;
  582. struct ath9k_hw_capabilities *pCap;
  583. struct ath_common *common;
  584. int ret = 0, i;
  585. int csz = 0;
  586. ah = devm_kzalloc(sc->dev, sizeof(struct ath_hw), GFP_KERNEL);
  587. if (!ah)
  588. return -ENOMEM;
  589. ah->dev = sc->dev;
  590. ah->hw = sc->hw;
  591. ah->hw_version.devid = devid;
  592. ah->reg_ops.read = ath9k_ioread32;
  593. ah->reg_ops.write = ath9k_iowrite32;
  594. ah->reg_ops.rmw = ath9k_reg_rmw;
  595. sc->sc_ah = ah;
  596. pCap = &ah->caps;
  597. common = ath9k_hw_common(ah);
  598. sc->dfs_detector = dfs_pattern_detector_init(common, NL80211_DFS_UNSET);
  599. sc->tx99_power = MAX_RATE_POWER + 1;
  600. init_waitqueue_head(&sc->tx_wait);
  601. if (!pdata) {
  602. ah->ah_flags |= AH_USE_EEPROM;
  603. sc->sc_ah->led_pin = -1;
  604. } else {
  605. sc->sc_ah->gpio_mask = pdata->gpio_mask;
  606. sc->sc_ah->gpio_val = pdata->gpio_val;
  607. sc->sc_ah->led_pin = pdata->led_pin;
  608. ah->is_clk_25mhz = pdata->is_clk_25mhz;
  609. ah->get_mac_revision = pdata->get_mac_revision;
  610. ah->external_reset = pdata->external_reset;
  611. }
  612. common->ops = &ah->reg_ops;
  613. common->bus_ops = bus_ops;
  614. common->ah = ah;
  615. common->hw = sc->hw;
  616. common->priv = sc;
  617. common->debug_mask = ath9k_debug;
  618. common->btcoex_enabled = ath9k_btcoex_enable == 1;
  619. common->disable_ani = false;
  620. /*
  621. * Platform quirks.
  622. */
  623. ath9k_init_pcoem_platform(sc);
  624. ret = ath9k_init_soc_platform(sc);
  625. if (ret)
  626. return ret;
  627. /*
  628. * Enable WLAN/BT RX Antenna diversity only when:
  629. *
  630. * - BTCOEX is disabled.
  631. * - the user manually requests the feature.
  632. * - the HW cap is set using the platform data.
  633. */
  634. if (!common->btcoex_enabled && ath9k_bt_ant_diversity &&
  635. (pCap->hw_caps & ATH9K_HW_CAP_BT_ANT_DIV))
  636. common->bt_ant_diversity = 1;
  637. spin_lock_init(&common->cc_lock);
  638. spin_lock_init(&sc->sc_serial_rw);
  639. spin_lock_init(&sc->sc_pm_lock);
  640. mutex_init(&sc->mutex);
  641. tasklet_init(&sc->intr_tq, ath9k_tasklet, (unsigned long)sc);
  642. tasklet_init(&sc->bcon_tasklet, ath9k_beacon_tasklet,
  643. (unsigned long)sc);
  644. setup_timer(&sc->sleep_timer, ath_ps_full_sleep, (unsigned long)sc);
  645. INIT_WORK(&sc->hw_reset_work, ath_reset_work);
  646. INIT_WORK(&sc->paprd_work, ath_paprd_calibrate);
  647. INIT_DELAYED_WORK(&sc->hw_pll_work, ath_hw_pll_work);
  648. /*
  649. * Cache line size is used to size and align various
  650. * structures used to communicate with the hardware.
  651. */
  652. ath_read_cachesize(common, &csz);
  653. common->cachelsz = csz << 2; /* convert to bytes */
  654. /* Initializes the hardware for all supported chipsets */
  655. ret = ath9k_hw_init(ah);
  656. if (ret)
  657. goto err_hw;
  658. if (pdata && pdata->macaddr)
  659. memcpy(common->macaddr, pdata->macaddr, ETH_ALEN);
  660. ret = ath9k_init_queues(sc);
  661. if (ret)
  662. goto err_queues;
  663. ret = ath9k_init_btcoex(sc);
  664. if (ret)
  665. goto err_btcoex;
  666. ret = ath9k_init_channels_rates(sc);
  667. if (ret)
  668. goto err_btcoex;
  669. ath9k_cmn_init_crypto(sc->sc_ah);
  670. ath9k_init_misc(sc);
  671. ath_fill_led_pin(sc);
  672. if (common->bus_ops->aspm_init)
  673. common->bus_ops->aspm_init(common);
  674. return 0;
  675. err_btcoex:
  676. for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++)
  677. if (ATH_TXQ_SETUP(sc, i))
  678. ath_tx_cleanupq(sc, &sc->tx.txq[i]);
  679. err_queues:
  680. ath9k_hw_deinit(ah);
  681. err_hw:
  682. ath9k_eeprom_release(sc);
  683. dev_kfree_skb_any(sc->tx99_skb);
  684. return ret;
  685. }
  686. static void ath9k_init_band_txpower(struct ath_softc *sc, int band)
  687. {
  688. struct ieee80211_supported_band *sband;
  689. struct ieee80211_channel *chan;
  690. struct ath_hw *ah = sc->sc_ah;
  691. struct cfg80211_chan_def chandef;
  692. int i;
  693. sband = &sc->sbands[band];
  694. for (i = 0; i < sband->n_channels; i++) {
  695. chan = &sband->channels[i];
  696. ah->curchan = &ah->channels[chan->hw_value];
  697. cfg80211_chandef_create(&chandef, chan, NL80211_CHAN_HT20);
  698. ath9k_cmn_get_channel(sc->hw, ah, &chandef);
  699. ath9k_hw_set_txpowerlimit(ah, MAX_RATE_POWER, true);
  700. }
  701. }
  702. static void ath9k_init_txpower_limits(struct ath_softc *sc)
  703. {
  704. struct ath_hw *ah = sc->sc_ah;
  705. struct ath9k_channel *curchan = ah->curchan;
  706. if (ah->caps.hw_caps & ATH9K_HW_CAP_2GHZ)
  707. ath9k_init_band_txpower(sc, IEEE80211_BAND_2GHZ);
  708. if (ah->caps.hw_caps & ATH9K_HW_CAP_5GHZ)
  709. ath9k_init_band_txpower(sc, IEEE80211_BAND_5GHZ);
  710. ah->curchan = curchan;
  711. }
  712. void ath9k_reload_chainmask_settings(struct ath_softc *sc)
  713. {
  714. if (!(sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_HT))
  715. return;
  716. if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_2GHZ)
  717. setup_ht_cap(sc, &sc->sbands[IEEE80211_BAND_2GHZ].ht_cap);
  718. if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_5GHZ)
  719. setup_ht_cap(sc, &sc->sbands[IEEE80211_BAND_5GHZ].ht_cap);
  720. }
  721. static const struct ieee80211_iface_limit if_limits[] = {
  722. { .max = 2048, .types = BIT(NL80211_IFTYPE_STATION) |
  723. BIT(NL80211_IFTYPE_P2P_CLIENT) |
  724. BIT(NL80211_IFTYPE_WDS) },
  725. { .max = 8, .types =
  726. #ifdef CONFIG_MAC80211_MESH
  727. BIT(NL80211_IFTYPE_MESH_POINT) |
  728. #endif
  729. BIT(NL80211_IFTYPE_AP) |
  730. BIT(NL80211_IFTYPE_P2P_GO) },
  731. };
  732. static const struct ieee80211_iface_limit if_dfs_limits[] = {
  733. { .max = 1, .types = BIT(NL80211_IFTYPE_AP) |
  734. #ifdef CONFIG_MAC80211_MESH
  735. BIT(NL80211_IFTYPE_MESH_POINT) |
  736. #endif
  737. BIT(NL80211_IFTYPE_ADHOC) },
  738. };
  739. static const struct ieee80211_iface_combination if_comb[] = {
  740. {
  741. .limits = if_limits,
  742. .n_limits = ARRAY_SIZE(if_limits),
  743. .max_interfaces = 2048,
  744. .num_different_channels = 1,
  745. .beacon_int_infra_match = true,
  746. },
  747. {
  748. .limits = if_dfs_limits,
  749. .n_limits = ARRAY_SIZE(if_dfs_limits),
  750. .max_interfaces = 1,
  751. .num_different_channels = 1,
  752. .beacon_int_infra_match = true,
  753. .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
  754. BIT(NL80211_CHAN_WIDTH_20),
  755. }
  756. };
  757. static void ath9k_set_hw_capab(struct ath_softc *sc, struct ieee80211_hw *hw)
  758. {
  759. struct ath_hw *ah = sc->sc_ah;
  760. struct ath_common *common = ath9k_hw_common(ah);
  761. hw->flags = IEEE80211_HW_RX_INCLUDES_FCS |
  762. IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING |
  763. IEEE80211_HW_SIGNAL_DBM |
  764. IEEE80211_HW_PS_NULLFUNC_STACK |
  765. IEEE80211_HW_SPECTRUM_MGMT |
  766. IEEE80211_HW_REPORTS_TX_ACK_STATUS |
  767. IEEE80211_HW_SUPPORTS_RC_TABLE |
  768. IEEE80211_HW_SUPPORTS_HT_CCK_RATES;
  769. if (ath9k_ps_enable)
  770. hw->flags |= IEEE80211_HW_SUPPORTS_PS;
  771. if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_HT) {
  772. hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION;
  773. if (AR_SREV_9280_20_OR_LATER(ah))
  774. hw->radiotap_mcs_details |=
  775. IEEE80211_RADIOTAP_MCS_HAVE_STBC;
  776. }
  777. if (AR_SREV_9160_10_OR_LATER(sc->sc_ah) || ath9k_modparam_nohwcrypt)
  778. hw->flags |= IEEE80211_HW_MFP_CAPABLE;
  779. hw->wiphy->features |= NL80211_FEATURE_ACTIVE_MONITOR;
  780. if (!config_enabled(CONFIG_ATH9K_TX99)) {
  781. hw->wiphy->interface_modes =
  782. BIT(NL80211_IFTYPE_P2P_GO) |
  783. BIT(NL80211_IFTYPE_P2P_CLIENT) |
  784. BIT(NL80211_IFTYPE_AP) |
  785. BIT(NL80211_IFTYPE_WDS) |
  786. BIT(NL80211_IFTYPE_STATION) |
  787. BIT(NL80211_IFTYPE_ADHOC) |
  788. BIT(NL80211_IFTYPE_MESH_POINT);
  789. hw->wiphy->iface_combinations = if_comb;
  790. hw->wiphy->n_iface_combinations = ARRAY_SIZE(if_comb);
  791. }
  792. hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
  793. hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
  794. hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS;
  795. hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
  796. hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_5_10_MHZ;
  797. hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
  798. hw->queues = 4;
  799. hw->max_rates = 4;
  800. hw->max_listen_interval = 1;
  801. hw->max_rate_tries = 10;
  802. hw->sta_data_size = sizeof(struct ath_node);
  803. hw->vif_data_size = sizeof(struct ath_vif);
  804. hw->wiphy->available_antennas_rx = BIT(ah->caps.max_rxchains) - 1;
  805. hw->wiphy->available_antennas_tx = BIT(ah->caps.max_txchains) - 1;
  806. /* single chain devices with rx diversity */
  807. if (ah->caps.hw_caps & ATH9K_HW_CAP_ANT_DIV_COMB)
  808. hw->wiphy->available_antennas_rx = BIT(0) | BIT(1);
  809. sc->ant_rx = hw->wiphy->available_antennas_rx;
  810. sc->ant_tx = hw->wiphy->available_antennas_tx;
  811. if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_2GHZ)
  812. hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
  813. &sc->sbands[IEEE80211_BAND_2GHZ];
  814. if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_5GHZ)
  815. hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
  816. &sc->sbands[IEEE80211_BAND_5GHZ];
  817. ath9k_init_wow(hw);
  818. ath9k_reload_chainmask_settings(sc);
  819. SET_IEEE80211_PERM_ADDR(hw, common->macaddr);
  820. }
  821. int ath9k_init_device(u16 devid, struct ath_softc *sc,
  822. const struct ath_bus_ops *bus_ops)
  823. {
  824. struct ieee80211_hw *hw = sc->hw;
  825. struct ath_common *common;
  826. struct ath_hw *ah;
  827. int error = 0;
  828. struct ath_regulatory *reg;
  829. /* Bring up device */
  830. error = ath9k_init_softc(devid, sc, bus_ops);
  831. if (error)
  832. return error;
  833. ah = sc->sc_ah;
  834. common = ath9k_hw_common(ah);
  835. ath9k_set_hw_capab(sc, hw);
  836. /* Initialize regulatory */
  837. error = ath_regd_init(&common->regulatory, sc->hw->wiphy,
  838. ath9k_reg_notifier);
  839. if (error)
  840. goto deinit;
  841. reg = &common->regulatory;
  842. /* Setup TX DMA */
  843. error = ath_tx_init(sc, ATH_TXBUF);
  844. if (error != 0)
  845. goto deinit;
  846. /* Setup RX DMA */
  847. error = ath_rx_init(sc, ATH_RXBUF);
  848. if (error != 0)
  849. goto deinit;
  850. ath9k_init_txpower_limits(sc);
  851. #ifdef CONFIG_MAC80211_LEDS
  852. /* must be initialized before ieee80211_register_hw */
  853. sc->led_cdev.default_trigger = ieee80211_create_tpt_led_trigger(sc->hw,
  854. IEEE80211_TPT_LEDTRIG_FL_RADIO, ath9k_tpt_blink,
  855. ARRAY_SIZE(ath9k_tpt_blink));
  856. #endif
  857. /* Register with mac80211 */
  858. error = ieee80211_register_hw(hw);
  859. if (error)
  860. goto rx_cleanup;
  861. error = ath9k_init_debug(ah);
  862. if (error) {
  863. ath_err(common, "Unable to create debugfs files\n");
  864. goto unregister;
  865. }
  866. /* Handle world regulatory */
  867. if (!ath_is_world_regd(reg)) {
  868. error = regulatory_hint(hw->wiphy, reg->alpha2);
  869. if (error)
  870. goto debug_cleanup;
  871. }
  872. ath_init_leds(sc);
  873. ath_start_rfkill_poll(sc);
  874. return 0;
  875. debug_cleanup:
  876. ath9k_deinit_debug(sc);
  877. unregister:
  878. ieee80211_unregister_hw(hw);
  879. rx_cleanup:
  880. ath_rx_cleanup(sc);
  881. deinit:
  882. ath9k_deinit_softc(sc);
  883. return error;
  884. }
  885. /*****************************/
  886. /* De-Initialization */
  887. /*****************************/
  888. static void ath9k_deinit_softc(struct ath_softc *sc)
  889. {
  890. int i = 0;
  891. ath9k_deinit_btcoex(sc);
  892. for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++)
  893. if (ATH_TXQ_SETUP(sc, i))
  894. ath_tx_cleanupq(sc, &sc->tx.txq[i]);
  895. del_timer_sync(&sc->sleep_timer);
  896. ath9k_hw_deinit(sc->sc_ah);
  897. if (sc->dfs_detector != NULL)
  898. sc->dfs_detector->exit(sc->dfs_detector);
  899. ath9k_eeprom_release(sc);
  900. }
  901. void ath9k_deinit_device(struct ath_softc *sc)
  902. {
  903. struct ieee80211_hw *hw = sc->hw;
  904. ath9k_ps_wakeup(sc);
  905. wiphy_rfkill_stop_polling(sc->hw->wiphy);
  906. ath_deinit_leds(sc);
  907. ath9k_ps_restore(sc);
  908. ath9k_deinit_debug(sc);
  909. ieee80211_unregister_hw(hw);
  910. ath_rx_cleanup(sc);
  911. ath9k_deinit_softc(sc);
  912. }
  913. /************************/
  914. /* Module Hooks */
  915. /************************/
  916. static int __init ath9k_init(void)
  917. {
  918. int error;
  919. /* Register rate control algorithm */
  920. error = ath_rate_control_register();
  921. if (error != 0) {
  922. pr_err("Unable to register rate control algorithm: %d\n",
  923. error);
  924. goto err_out;
  925. }
  926. error = ath_pci_init();
  927. if (error < 0) {
  928. pr_err("No PCI devices found, driver not installed\n");
  929. error = -ENODEV;
  930. goto err_rate_unregister;
  931. }
  932. error = ath_ahb_init();
  933. if (error < 0) {
  934. error = -ENODEV;
  935. goto err_pci_exit;
  936. }
  937. return 0;
  938. err_pci_exit:
  939. ath_pci_exit();
  940. err_rate_unregister:
  941. ath_rate_control_unregister();
  942. err_out:
  943. return error;
  944. }
  945. module_init(ath9k_init);
  946. static void __exit ath9k_exit(void)
  947. {
  948. is_ath9k_unloaded = true;
  949. ath_ahb_exit();
  950. ath_pci_exit();
  951. ath_rate_control_unregister();
  952. pr_info("%s: Driver unloaded\n", dev_info);
  953. }
  954. module_exit(ath9k_exit);