init.c 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213
  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/of.h>
  22. #include <linux/of_net.h>
  23. #include <linux/nvmem-consumer.h>
  24. #include <linux/relay.h>
  25. #include <linux/dmi.h>
  26. #include <net/ieee80211_radiotap.h>
  27. #include "ath9k.h"
  28. struct ath9k_eeprom_ctx {
  29. struct completion complete;
  30. struct ath_hw *ah;
  31. };
  32. static char *dev_info = "ath9k";
  33. MODULE_AUTHOR("Atheros Communications");
  34. MODULE_DESCRIPTION("Support for Atheros 802.11n wireless LAN cards.");
  35. MODULE_LICENSE("Dual BSD/GPL");
  36. static unsigned int ath9k_debug = ATH_DBG_DEFAULT;
  37. module_param_named(debug, ath9k_debug, uint, 0);
  38. MODULE_PARM_DESC(debug, "Debugging mask");
  39. int ath9k_modparam_nohwcrypt;
  40. module_param_named(nohwcrypt, ath9k_modparam_nohwcrypt, int, 0444);
  41. MODULE_PARM_DESC(nohwcrypt, "Disable hardware encryption");
  42. int ath9k_led_blink;
  43. module_param_named(blink, ath9k_led_blink, int, 0444);
  44. MODULE_PARM_DESC(blink, "Enable LED blink on activity");
  45. static int ath9k_led_active_high = -1;
  46. module_param_named(led_active_high, ath9k_led_active_high, int, 0444);
  47. MODULE_PARM_DESC(led_active_high, "Invert LED polarity");
  48. static int ath9k_btcoex_enable;
  49. module_param_named(btcoex_enable, ath9k_btcoex_enable, int, 0444);
  50. MODULE_PARM_DESC(btcoex_enable, "Enable wifi-BT coexistence");
  51. static int ath9k_bt_ant_diversity;
  52. module_param_named(bt_ant_diversity, ath9k_bt_ant_diversity, int, 0444);
  53. MODULE_PARM_DESC(bt_ant_diversity, "Enable WLAN/BT RX antenna diversity");
  54. static int ath9k_ps_enable;
  55. module_param_named(ps_enable, ath9k_ps_enable, int, 0444);
  56. MODULE_PARM_DESC(ps_enable, "Enable WLAN PowerSave");
  57. #ifdef CONFIG_ATH9K_CHANNEL_CONTEXT
  58. int ath9k_use_chanctx;
  59. module_param_named(use_chanctx, ath9k_use_chanctx, int, 0444);
  60. MODULE_PARM_DESC(use_chanctx, "Enable channel context for concurrency");
  61. #endif /* CONFIG_ATH9K_CHANNEL_CONTEXT */
  62. int ath9k_use_msi;
  63. module_param_named(use_msi, ath9k_use_msi, int, 0444);
  64. MODULE_PARM_DESC(use_msi, "Use MSI instead of INTx if possible");
  65. bool is_ath9k_unloaded;
  66. #ifdef CONFIG_MAC80211_LEDS
  67. static const struct ieee80211_tpt_blink ath9k_tpt_blink[] = {
  68. { .throughput = 0 * 1024, .blink_time = 334 },
  69. { .throughput = 1 * 1024, .blink_time = 260 },
  70. { .throughput = 5 * 1024, .blink_time = 220 },
  71. { .throughput = 10 * 1024, .blink_time = 190 },
  72. { .throughput = 20 * 1024, .blink_time = 170 },
  73. { .throughput = 50 * 1024, .blink_time = 150 },
  74. { .throughput = 70 * 1024, .blink_time = 130 },
  75. { .throughput = 100 * 1024, .blink_time = 110 },
  76. { .throughput = 200 * 1024, .blink_time = 80 },
  77. { .throughput = 300 * 1024, .blink_time = 50 },
  78. };
  79. #endif
  80. static int __init set_use_msi(const struct dmi_system_id *dmi)
  81. {
  82. ath9k_use_msi = 1;
  83. return 1;
  84. }
  85. static const struct dmi_system_id ath9k_quirks[] __initconst = {
  86. {
  87. .callback = set_use_msi,
  88. .ident = "Dell Inspiron 24-3460",
  89. .matches = {
  90. DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
  91. DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 24-3460"),
  92. },
  93. },
  94. {
  95. .callback = set_use_msi,
  96. .ident = "Dell Vostro 3262",
  97. .matches = {
  98. DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
  99. DMI_MATCH(DMI_PRODUCT_NAME, "Vostro 3262"),
  100. },
  101. },
  102. {
  103. .callback = set_use_msi,
  104. .ident = "Dell Inspiron 3472",
  105. .matches = {
  106. DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
  107. DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 3472"),
  108. },
  109. },
  110. {
  111. .callback = set_use_msi,
  112. .ident = "Dell Vostro 15-3572",
  113. .matches = {
  114. DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
  115. DMI_MATCH(DMI_PRODUCT_NAME, "Vostro 15-3572"),
  116. },
  117. },
  118. {
  119. .callback = set_use_msi,
  120. .ident = "Dell Inspiron 14-3473",
  121. .matches = {
  122. DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
  123. DMI_MATCH(DMI_PRODUCT_NAME, "Inspiron 14-3473"),
  124. },
  125. },
  126. {}
  127. };
  128. static void ath9k_deinit_softc(struct ath_softc *sc);
  129. static void ath9k_op_ps_wakeup(struct ath_common *common)
  130. {
  131. ath9k_ps_wakeup((struct ath_softc *) common->priv);
  132. }
  133. static void ath9k_op_ps_restore(struct ath_common *common)
  134. {
  135. ath9k_ps_restore((struct ath_softc *) common->priv);
  136. }
  137. static const struct ath_ps_ops ath9k_ps_ops = {
  138. .wakeup = ath9k_op_ps_wakeup,
  139. .restore = ath9k_op_ps_restore,
  140. };
  141. /*
  142. * Read and write, they both share the same lock. We do this to serialize
  143. * reads and writes on Atheros 802.11n PCI devices only. This is required
  144. * as the FIFO on these devices can only accept sanely 2 requests.
  145. */
  146. static void ath9k_iowrite32(void *hw_priv, u32 val, u32 reg_offset)
  147. {
  148. struct ath_hw *ah = hw_priv;
  149. struct ath_common *common = ath9k_hw_common(ah);
  150. struct ath_softc *sc = (struct ath_softc *) common->priv;
  151. if (NR_CPUS > 1 && ah->config.serialize_regmode == SER_REG_MODE_ON) {
  152. unsigned long flags;
  153. spin_lock_irqsave(&sc->sc_serial_rw, flags);
  154. iowrite32(val, sc->mem + reg_offset);
  155. spin_unlock_irqrestore(&sc->sc_serial_rw, flags);
  156. } else
  157. iowrite32(val, sc->mem + reg_offset);
  158. }
  159. static unsigned int ath9k_ioread32(void *hw_priv, u32 reg_offset)
  160. {
  161. struct ath_hw *ah = hw_priv;
  162. struct ath_common *common = ath9k_hw_common(ah);
  163. struct ath_softc *sc = (struct ath_softc *) common->priv;
  164. u32 val;
  165. if (NR_CPUS > 1 && ah->config.serialize_regmode == SER_REG_MODE_ON) {
  166. unsigned long flags;
  167. spin_lock_irqsave(&sc->sc_serial_rw, flags);
  168. val = ioread32(sc->mem + reg_offset);
  169. spin_unlock_irqrestore(&sc->sc_serial_rw, flags);
  170. } else
  171. val = ioread32(sc->mem + reg_offset);
  172. return val;
  173. }
  174. static void ath9k_multi_ioread32(void *hw_priv, u32 *addr,
  175. u32 *val, u16 count)
  176. {
  177. int i;
  178. for (i = 0; i < count; i++)
  179. val[i] = ath9k_ioread32(hw_priv, addr[i]);
  180. }
  181. static unsigned int __ath9k_reg_rmw(struct ath_softc *sc, u32 reg_offset,
  182. u32 set, u32 clr)
  183. {
  184. u32 val;
  185. val = ioread32(sc->mem + reg_offset);
  186. val &= ~clr;
  187. val |= set;
  188. iowrite32(val, sc->mem + reg_offset);
  189. return val;
  190. }
  191. static unsigned int ath9k_reg_rmw(void *hw_priv, u32 reg_offset, u32 set, u32 clr)
  192. {
  193. struct ath_hw *ah = hw_priv;
  194. struct ath_common *common = ath9k_hw_common(ah);
  195. struct ath_softc *sc = (struct ath_softc *) common->priv;
  196. unsigned long flags;
  197. u32 val;
  198. if (NR_CPUS > 1 && ah->config.serialize_regmode == SER_REG_MODE_ON) {
  199. spin_lock_irqsave(&sc->sc_serial_rw, flags);
  200. val = __ath9k_reg_rmw(sc, reg_offset, set, clr);
  201. spin_unlock_irqrestore(&sc->sc_serial_rw, flags);
  202. } else
  203. val = __ath9k_reg_rmw(sc, reg_offset, set, clr);
  204. return val;
  205. }
  206. /**************************/
  207. /* Initialization */
  208. /**************************/
  209. static void ath9k_reg_notifier(struct wiphy *wiphy,
  210. struct regulatory_request *request)
  211. {
  212. struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
  213. struct ath_softc *sc = hw->priv;
  214. struct ath_hw *ah = sc->sc_ah;
  215. struct ath_regulatory *reg = ath9k_hw_regulatory(ah);
  216. ath_reg_notifier_apply(wiphy, request, reg);
  217. /* synchronize DFS detector if regulatory domain changed */
  218. if (sc->dfs_detector != NULL)
  219. sc->dfs_detector->set_dfs_domain(sc->dfs_detector,
  220. request->dfs_region);
  221. /* Set tx power */
  222. if (!ah->curchan)
  223. return;
  224. sc->cur_chan->txpower = 2 * ah->curchan->chan->max_power;
  225. ath9k_ps_wakeup(sc);
  226. ath9k_hw_set_txpowerlimit(ah, sc->cur_chan->txpower, false);
  227. ath9k_cmn_update_txpow(ah, sc->cur_chan->cur_txpower,
  228. sc->cur_chan->txpower,
  229. &sc->cur_chan->cur_txpower);
  230. ath9k_ps_restore(sc);
  231. }
  232. /*
  233. * This function will allocate both the DMA descriptor structure, and the
  234. * buffers it contains. These are used to contain the descriptors used
  235. * by the system.
  236. */
  237. int ath_descdma_setup(struct ath_softc *sc, struct ath_descdma *dd,
  238. struct list_head *head, const char *name,
  239. int nbuf, int ndesc, bool is_tx)
  240. {
  241. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  242. u8 *ds;
  243. int i, bsize, desc_len;
  244. ath_dbg(common, CONFIG, "%s DMA: %u buffers %u desc/buf\n",
  245. name, nbuf, ndesc);
  246. INIT_LIST_HEAD(head);
  247. if (is_tx)
  248. desc_len = sc->sc_ah->caps.tx_desc_len;
  249. else
  250. desc_len = sizeof(struct ath_desc);
  251. /* ath_desc must be a multiple of DWORDs */
  252. if ((desc_len % 4) != 0) {
  253. ath_err(common, "ath_desc not DWORD aligned\n");
  254. BUG_ON((desc_len % 4) != 0);
  255. return -ENOMEM;
  256. }
  257. dd->dd_desc_len = desc_len * nbuf * ndesc;
  258. /*
  259. * Need additional DMA memory because we can't use
  260. * descriptors that cross the 4K page boundary. Assume
  261. * one skipped descriptor per 4K page.
  262. */
  263. if (!(sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_4KB_SPLITTRANS)) {
  264. u32 ndesc_skipped =
  265. ATH_DESC_4KB_BOUND_NUM_SKIPPED(dd->dd_desc_len);
  266. u32 dma_len;
  267. while (ndesc_skipped) {
  268. dma_len = ndesc_skipped * desc_len;
  269. dd->dd_desc_len += dma_len;
  270. ndesc_skipped = ATH_DESC_4KB_BOUND_NUM_SKIPPED(dma_len);
  271. }
  272. }
  273. /* allocate descriptors */
  274. dd->dd_desc = dmam_alloc_coherent(sc->dev, dd->dd_desc_len,
  275. &dd->dd_desc_paddr, GFP_KERNEL);
  276. if (!dd->dd_desc)
  277. return -ENOMEM;
  278. ds = dd->dd_desc;
  279. ath_dbg(common, CONFIG, "%s DMA map: %p (%u) -> %llx (%u)\n",
  280. name, ds, (u32) dd->dd_desc_len,
  281. ito64(dd->dd_desc_paddr), /*XXX*/(u32) dd->dd_desc_len);
  282. /* allocate buffers */
  283. if (is_tx) {
  284. struct ath_buf *bf;
  285. bsize = sizeof(struct ath_buf) * nbuf;
  286. bf = devm_kzalloc(sc->dev, bsize, GFP_KERNEL);
  287. if (!bf)
  288. return -ENOMEM;
  289. for (i = 0; i < nbuf; i++, bf++, ds += (desc_len * ndesc)) {
  290. bf->bf_desc = ds;
  291. bf->bf_daddr = DS2PHYS(dd, ds);
  292. if (!(sc->sc_ah->caps.hw_caps &
  293. ATH9K_HW_CAP_4KB_SPLITTRANS)) {
  294. /*
  295. * Skip descriptor addresses which can cause 4KB
  296. * boundary crossing (addr + length) with a 32 dword
  297. * descriptor fetch.
  298. */
  299. while (ATH_DESC_4KB_BOUND_CHECK(bf->bf_daddr)) {
  300. BUG_ON((caddr_t) bf->bf_desc >=
  301. ((caddr_t) dd->dd_desc +
  302. dd->dd_desc_len));
  303. ds += (desc_len * ndesc);
  304. bf->bf_desc = ds;
  305. bf->bf_daddr = DS2PHYS(dd, ds);
  306. }
  307. }
  308. list_add_tail(&bf->list, head);
  309. }
  310. } else {
  311. struct ath_rxbuf *bf;
  312. bsize = sizeof(struct ath_rxbuf) * nbuf;
  313. bf = devm_kzalloc(sc->dev, bsize, GFP_KERNEL);
  314. if (!bf)
  315. return -ENOMEM;
  316. for (i = 0; i < nbuf; i++, bf++, ds += (desc_len * ndesc)) {
  317. bf->bf_desc = ds;
  318. bf->bf_daddr = DS2PHYS(dd, ds);
  319. if (!(sc->sc_ah->caps.hw_caps &
  320. ATH9K_HW_CAP_4KB_SPLITTRANS)) {
  321. /*
  322. * Skip descriptor addresses which can cause 4KB
  323. * boundary crossing (addr + length) with a 32 dword
  324. * descriptor fetch.
  325. */
  326. while (ATH_DESC_4KB_BOUND_CHECK(bf->bf_daddr)) {
  327. BUG_ON((caddr_t) bf->bf_desc >=
  328. ((caddr_t) dd->dd_desc +
  329. dd->dd_desc_len));
  330. ds += (desc_len * ndesc);
  331. bf->bf_desc = ds;
  332. bf->bf_daddr = DS2PHYS(dd, ds);
  333. }
  334. }
  335. list_add_tail(&bf->list, head);
  336. }
  337. }
  338. return 0;
  339. }
  340. static int ath9k_init_queues(struct ath_softc *sc)
  341. {
  342. int i = 0;
  343. sc->beacon.beaconq = ath9k_hw_beaconq_setup(sc->sc_ah);
  344. sc->beacon.cabq = ath_txq_setup(sc, ATH9K_TX_QUEUE_CAB, 0);
  345. ath_cabq_update(sc);
  346. sc->tx.uapsdq = ath_txq_setup(sc, ATH9K_TX_QUEUE_UAPSD, 0);
  347. for (i = 0; i < IEEE80211_NUM_ACS; i++) {
  348. sc->tx.txq_map[i] = ath_txq_setup(sc, ATH9K_TX_QUEUE_DATA, i);
  349. sc->tx.txq_map[i]->mac80211_qnum = i;
  350. }
  351. return 0;
  352. }
  353. static void ath9k_init_misc(struct ath_softc *sc)
  354. {
  355. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  356. int i = 0;
  357. timer_setup(&common->ani.timer, ath_ani_calibrate, 0);
  358. common->last_rssi = ATH_RSSI_DUMMY_MARKER;
  359. eth_broadcast_addr(common->bssidmask);
  360. sc->beacon.slottime = 9;
  361. for (i = 0; i < ARRAY_SIZE(sc->beacon.bslot); i++)
  362. sc->beacon.bslot[i] = NULL;
  363. if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_ANT_DIV_COMB)
  364. sc->ant_comb.count = ATH_ANT_DIV_COMB_INIT_COUNT;
  365. sc->spec_priv.ah = sc->sc_ah;
  366. sc->spec_priv.spec_config.enabled = 0;
  367. sc->spec_priv.spec_config.short_repeat = true;
  368. sc->spec_priv.spec_config.count = 8;
  369. sc->spec_priv.spec_config.endless = false;
  370. sc->spec_priv.spec_config.period = 0xFF;
  371. sc->spec_priv.spec_config.fft_period = 0xF;
  372. }
  373. static void ath9k_init_pcoem_platform(struct ath_softc *sc)
  374. {
  375. struct ath_hw *ah = sc->sc_ah;
  376. struct ath9k_hw_capabilities *pCap = &ah->caps;
  377. struct ath_common *common = ath9k_hw_common(ah);
  378. if (!IS_ENABLED(CONFIG_ATH9K_PCOEM))
  379. return;
  380. if (common->bus_ops->ath_bus_type != ATH_PCI)
  381. return;
  382. if (sc->driver_data & (ATH9K_PCI_CUS198 |
  383. ATH9K_PCI_CUS230)) {
  384. ah->config.xlna_gpio = 9;
  385. ah->config.xatten_margin_cfg = true;
  386. ah->config.alt_mingainidx = true;
  387. ah->config.ant_ctrl_comm2g_switch_enable = 0x000BBB88;
  388. sc->ant_comb.low_rssi_thresh = 20;
  389. sc->ant_comb.fast_div_bias = 3;
  390. ath_info(common, "Set parameters for %s\n",
  391. (sc->driver_data & ATH9K_PCI_CUS198) ?
  392. "CUS198" : "CUS230");
  393. }
  394. if (sc->driver_data & ATH9K_PCI_CUS217)
  395. ath_info(common, "CUS217 card detected\n");
  396. if (sc->driver_data & ATH9K_PCI_CUS252)
  397. ath_info(common, "CUS252 card detected\n");
  398. if (sc->driver_data & ATH9K_PCI_AR9565_1ANT)
  399. ath_info(common, "WB335 1-ANT card detected\n");
  400. if (sc->driver_data & ATH9K_PCI_AR9565_2ANT)
  401. ath_info(common, "WB335 2-ANT card detected\n");
  402. if (sc->driver_data & ATH9K_PCI_KILLER)
  403. ath_info(common, "Killer Wireless card detected\n");
  404. /*
  405. * Some WB335 cards do not support antenna diversity. Since
  406. * we use a hardcoded value for AR9565 instead of using the
  407. * EEPROM/OTP data, remove the combining feature from
  408. * the HW capabilities bitmap.
  409. */
  410. if (sc->driver_data & (ATH9K_PCI_AR9565_1ANT | ATH9K_PCI_AR9565_2ANT)) {
  411. if (!(sc->driver_data & ATH9K_PCI_BT_ANT_DIV))
  412. pCap->hw_caps &= ~ATH9K_HW_CAP_ANT_DIV_COMB;
  413. }
  414. if (sc->driver_data & ATH9K_PCI_BT_ANT_DIV) {
  415. pCap->hw_caps |= ATH9K_HW_CAP_BT_ANT_DIV;
  416. ath_info(common, "Set BT/WLAN RX diversity capability\n");
  417. }
  418. if (sc->driver_data & ATH9K_PCI_D3_L1_WAR) {
  419. ah->config.pcie_waen = 0x0040473b;
  420. ath_info(common, "Enable WAR for ASPM D3/L1\n");
  421. }
  422. /*
  423. * The default value of pll_pwrsave is 1.
  424. * For certain AR9485 cards, it is set to 0.
  425. * For AR9462, AR9565 it's set to 7.
  426. */
  427. ah->config.pll_pwrsave = 1;
  428. if (sc->driver_data & ATH9K_PCI_NO_PLL_PWRSAVE) {
  429. ah->config.pll_pwrsave = 0;
  430. ath_info(common, "Disable PLL PowerSave\n");
  431. }
  432. if (sc->driver_data & ATH9K_PCI_LED_ACT_HI)
  433. ah->config.led_active_high = true;
  434. }
  435. static void ath9k_eeprom_request_cb(const struct firmware *eeprom_blob,
  436. void *ctx)
  437. {
  438. struct ath9k_eeprom_ctx *ec = ctx;
  439. if (eeprom_blob)
  440. ec->ah->eeprom_blob = eeprom_blob;
  441. complete(&ec->complete);
  442. }
  443. static int ath9k_eeprom_request(struct ath_softc *sc, const char *name)
  444. {
  445. struct ath9k_eeprom_ctx ec;
  446. struct ath_hw *ah = sc->sc_ah;
  447. int err;
  448. /* try to load the EEPROM content asynchronously */
  449. init_completion(&ec.complete);
  450. ec.ah = sc->sc_ah;
  451. err = request_firmware_nowait(THIS_MODULE, 1, name, sc->dev, GFP_KERNEL,
  452. &ec, ath9k_eeprom_request_cb);
  453. if (err < 0) {
  454. ath_err(ath9k_hw_common(ah),
  455. "EEPROM request failed\n");
  456. return err;
  457. }
  458. wait_for_completion(&ec.complete);
  459. if (!ah->eeprom_blob) {
  460. ath_err(ath9k_hw_common(ah),
  461. "Unable to load EEPROM file %s\n", name);
  462. return -EINVAL;
  463. }
  464. return 0;
  465. }
  466. static void ath9k_eeprom_release(struct ath_softc *sc)
  467. {
  468. release_firmware(sc->sc_ah->eeprom_blob);
  469. }
  470. static int ath9k_nvmem_request_eeprom(struct ath_softc *sc)
  471. {
  472. struct ath_hw *ah = sc->sc_ah;
  473. struct nvmem_cell *cell;
  474. void *buf;
  475. size_t len;
  476. int err;
  477. cell = devm_nvmem_cell_get(sc->dev, "calibration");
  478. if (IS_ERR(cell)) {
  479. err = PTR_ERR(cell);
  480. /* nvmem cell might not be defined, or the nvmem
  481. * subsystem isn't included. In this case, follow
  482. * the established "just return 0;" convention of
  483. * ath9k_init_platform to say:
  484. * "All good. Nothing to see here. Please go on."
  485. */
  486. if (err == -ENOENT || err == -EOPNOTSUPP)
  487. return 0;
  488. return err;
  489. }
  490. buf = nvmem_cell_read(cell, &len);
  491. if (IS_ERR(buf))
  492. return PTR_ERR(buf);
  493. /* run basic sanity checks on the returned nvram cell length.
  494. * That length has to be a multiple of a "u16" (i.e.: & 1).
  495. * Furthermore, it has to be more than "let's say" 512 bytes
  496. * but less than the maximum of AR9300_EEPROM_SIZE (16kb).
  497. */
  498. if ((len & 1) == 1 || len < 512 || len >= AR9300_EEPROM_SIZE) {
  499. kfree(buf);
  500. return -EINVAL;
  501. }
  502. /* devres manages the calibration values release on shutdown */
  503. ah->nvmem_blob = (u16 *)devm_kmemdup(sc->dev, buf, len, GFP_KERNEL);
  504. kfree(buf);
  505. if (!ah->nvmem_blob)
  506. return -ENOMEM;
  507. ah->nvmem_blob_len = len;
  508. ah->ah_flags &= ~AH_USE_EEPROM;
  509. ah->ah_flags |= AH_NO_EEP_SWAP;
  510. return 0;
  511. }
  512. static int ath9k_init_platform(struct ath_softc *sc)
  513. {
  514. struct ath9k_platform_data *pdata = sc->dev->platform_data;
  515. struct ath_hw *ah = sc->sc_ah;
  516. struct ath_common *common = ath9k_hw_common(ah);
  517. int ret;
  518. if (!pdata)
  519. return 0;
  520. if (!pdata->use_eeprom) {
  521. ah->ah_flags &= ~AH_USE_EEPROM;
  522. ah->gpio_mask = pdata->gpio_mask;
  523. ah->gpio_val = pdata->gpio_val;
  524. ah->led_pin = pdata->led_pin;
  525. ah->is_clk_25mhz = pdata->is_clk_25mhz;
  526. ah->get_mac_revision = pdata->get_mac_revision;
  527. ah->external_reset = pdata->external_reset;
  528. ah->disable_2ghz = pdata->disable_2ghz;
  529. ah->disable_5ghz = pdata->disable_5ghz;
  530. if (!pdata->endian_check)
  531. ah->ah_flags |= AH_NO_EEP_SWAP;
  532. }
  533. if (pdata->eeprom_name) {
  534. ret = ath9k_eeprom_request(sc, pdata->eeprom_name);
  535. if (ret)
  536. return ret;
  537. }
  538. if (pdata->led_active_high)
  539. ah->config.led_active_high = true;
  540. if (pdata->tx_gain_buffalo)
  541. ah->config.tx_gain_buffalo = true;
  542. if (pdata->macaddr)
  543. ether_addr_copy(common->macaddr, pdata->macaddr);
  544. return 0;
  545. }
  546. static int ath9k_of_init(struct ath_softc *sc)
  547. {
  548. struct device_node *np = sc->dev->of_node;
  549. struct ath_hw *ah = sc->sc_ah;
  550. struct ath_common *common = ath9k_hw_common(ah);
  551. enum ath_bus_type bus_type = common->bus_ops->ath_bus_type;
  552. char eeprom_name[100];
  553. int ret;
  554. if (!of_device_is_available(np))
  555. return 0;
  556. ath_dbg(common, CONFIG, "parsing configuration from OF node\n");
  557. if (of_property_read_bool(np, "qca,no-eeprom")) {
  558. /* ath9k-eeprom-<bus>-<id>.bin */
  559. scnprintf(eeprom_name, sizeof(eeprom_name),
  560. "ath9k-eeprom-%s-%s.bin",
  561. ath_bus_type_to_string(bus_type), dev_name(ah->dev));
  562. ret = ath9k_eeprom_request(sc, eeprom_name);
  563. if (ret)
  564. return ret;
  565. ah->ah_flags &= ~AH_USE_EEPROM;
  566. ah->ah_flags |= AH_NO_EEP_SWAP;
  567. }
  568. of_get_mac_address(np, common->macaddr);
  569. return 0;
  570. }
  571. static int ath9k_init_softc(u16 devid, struct ath_softc *sc,
  572. const struct ath_bus_ops *bus_ops)
  573. {
  574. struct ath_hw *ah = NULL;
  575. struct ath9k_hw_capabilities *pCap;
  576. struct ath_common *common;
  577. int ret = 0, i;
  578. int csz = 0;
  579. ah = devm_kzalloc(sc->dev, sizeof(struct ath_hw), GFP_KERNEL);
  580. if (!ah)
  581. return -ENOMEM;
  582. ah->dev = sc->dev;
  583. ah->hw = sc->hw;
  584. ah->hw_version.devid = devid;
  585. ah->ah_flags |= AH_USE_EEPROM;
  586. ah->led_pin = -1;
  587. ah->reg_ops.read = ath9k_ioread32;
  588. ah->reg_ops.multi_read = ath9k_multi_ioread32;
  589. ah->reg_ops.write = ath9k_iowrite32;
  590. ah->reg_ops.rmw = ath9k_reg_rmw;
  591. pCap = &ah->caps;
  592. common = ath9k_hw_common(ah);
  593. /* Will be cleared in ath9k_start() */
  594. set_bit(ATH_OP_INVALID, &common->op_flags);
  595. sc->sc_ah = ah;
  596. sc->dfs_detector = dfs_pattern_detector_init(common, NL80211_DFS_UNSET);
  597. sc->tx99_power = MAX_RATE_POWER + 1;
  598. init_waitqueue_head(&sc->tx_wait);
  599. sc->cur_chan = &sc->chanctx[0];
  600. if (!ath9k_is_chanctx_enabled())
  601. sc->cur_chan->hw_queue_base = 0;
  602. common->ops = &ah->reg_ops;
  603. common->bus_ops = bus_ops;
  604. common->ps_ops = &ath9k_ps_ops;
  605. common->ah = ah;
  606. common->hw = sc->hw;
  607. common->priv = sc;
  608. common->debug_mask = ath9k_debug;
  609. common->btcoex_enabled = ath9k_btcoex_enable == 1;
  610. common->disable_ani = false;
  611. /*
  612. * Platform quirks.
  613. */
  614. ath9k_init_pcoem_platform(sc);
  615. ret = ath9k_init_platform(sc);
  616. if (ret)
  617. return ret;
  618. ret = ath9k_of_init(sc);
  619. if (ret)
  620. return ret;
  621. ret = ath9k_nvmem_request_eeprom(sc);
  622. if (ret)
  623. return ret;
  624. if (ath9k_led_active_high != -1)
  625. ah->config.led_active_high = ath9k_led_active_high == 1;
  626. /*
  627. * Enable WLAN/BT RX Antenna diversity only when:
  628. *
  629. * - BTCOEX is disabled.
  630. * - the user manually requests the feature.
  631. * - the HW cap is set using the platform data.
  632. */
  633. if (!common->btcoex_enabled && ath9k_bt_ant_diversity &&
  634. (pCap->hw_caps & ATH9K_HW_CAP_BT_ANT_DIV))
  635. common->bt_ant_diversity = 1;
  636. spin_lock_init(&common->cc_lock);
  637. spin_lock_init(&sc->intr_lock);
  638. spin_lock_init(&sc->sc_serial_rw);
  639. spin_lock_init(&sc->sc_pm_lock);
  640. spin_lock_init(&sc->chan_lock);
  641. mutex_init(&sc->mutex);
  642. tasklet_setup(&sc->intr_tq, ath9k_tasklet);
  643. tasklet_setup(&sc->bcon_tasklet, ath9k_beacon_tasklet);
  644. timer_setup(&sc->sleep_timer, ath_ps_full_sleep, 0);
  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. INIT_DELAYED_WORK(&sc->hw_check_work, ath_hw_check_work);
  649. ath9k_init_channel_context(sc);
  650. /*
  651. * Cache line size is used to size and align various
  652. * structures used to communicate with the hardware.
  653. */
  654. ath_read_cachesize(common, &csz);
  655. common->cachelsz = csz << 2; /* convert to bytes */
  656. /* Initializes the hardware for all supported chipsets */
  657. ret = ath9k_hw_init(ah);
  658. if (ret)
  659. goto err_hw;
  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_cmn_init_channels_rates(common);
  667. if (ret)
  668. goto err_btcoex;
  669. ret = ath9k_init_p2p(sc);
  670. if (ret)
  671. goto err_btcoex;
  672. ath9k_cmn_init_crypto(sc->sc_ah);
  673. ath9k_init_misc(sc);
  674. ath_chanctx_init(sc);
  675. ath9k_offchannel_init(sc);
  676. if (common->bus_ops->aspm_init)
  677. common->bus_ops->aspm_init(common);
  678. return 0;
  679. err_btcoex:
  680. for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++)
  681. if (ATH_TXQ_SETUP(sc, i))
  682. ath_tx_cleanupq(sc, &sc->tx.txq[i]);
  683. err_queues:
  684. ath9k_hw_deinit(ah);
  685. err_hw:
  686. ath9k_eeprom_release(sc);
  687. dev_kfree_skb_any(sc->tx99_skb);
  688. return ret;
  689. }
  690. static void ath9k_init_band_txpower(struct ath_softc *sc, int band)
  691. {
  692. struct ieee80211_supported_band *sband;
  693. struct ieee80211_channel *chan;
  694. struct ath_hw *ah = sc->sc_ah;
  695. struct ath_common *common = ath9k_hw_common(ah);
  696. struct cfg80211_chan_def chandef;
  697. int i;
  698. sband = &common->sbands[band];
  699. for (i = 0; i < sband->n_channels; i++) {
  700. chan = &sband->channels[i];
  701. ah->curchan = &ah->channels[chan->hw_value];
  702. cfg80211_chandef_create(&chandef, chan, NL80211_CHAN_HT20);
  703. ath9k_cmn_get_channel(sc->hw, ah, &chandef);
  704. ath9k_hw_set_txpowerlimit(ah, MAX_COMBINED_POWER, true);
  705. }
  706. }
  707. static void ath9k_init_txpower_limits(struct ath_softc *sc)
  708. {
  709. struct ath_hw *ah = sc->sc_ah;
  710. struct ath9k_channel *curchan = ah->curchan;
  711. if (ah->caps.hw_caps & ATH9K_HW_CAP_2GHZ)
  712. ath9k_init_band_txpower(sc, NL80211_BAND_2GHZ);
  713. if (ah->caps.hw_caps & ATH9K_HW_CAP_5GHZ)
  714. ath9k_init_band_txpower(sc, NL80211_BAND_5GHZ);
  715. ah->curchan = curchan;
  716. }
  717. static const struct ieee80211_iface_limit if_limits[] = {
  718. { .max = 2048, .types = BIT(NL80211_IFTYPE_STATION) },
  719. { .max = 8, .types =
  720. #ifdef CONFIG_MAC80211_MESH
  721. BIT(NL80211_IFTYPE_MESH_POINT) |
  722. #endif
  723. BIT(NL80211_IFTYPE_AP) },
  724. { .max = 1, .types = BIT(NL80211_IFTYPE_P2P_CLIENT) |
  725. BIT(NL80211_IFTYPE_P2P_GO) },
  726. };
  727. #ifdef CONFIG_ATH9K_CHANNEL_CONTEXT
  728. static const struct ieee80211_iface_limit if_limits_multi[] = {
  729. { .max = 2, .types = BIT(NL80211_IFTYPE_STATION) |
  730. BIT(NL80211_IFTYPE_AP) |
  731. BIT(NL80211_IFTYPE_P2P_CLIENT) |
  732. BIT(NL80211_IFTYPE_P2P_GO) },
  733. { .max = 1, .types = BIT(NL80211_IFTYPE_ADHOC) },
  734. { .max = 1, .types = BIT(NL80211_IFTYPE_P2P_DEVICE) },
  735. };
  736. static const struct ieee80211_iface_combination if_comb_multi[] = {
  737. {
  738. .limits = if_limits_multi,
  739. .n_limits = ARRAY_SIZE(if_limits_multi),
  740. .max_interfaces = 3,
  741. .num_different_channels = 2,
  742. .beacon_int_infra_match = true,
  743. },
  744. };
  745. #endif /* CONFIG_ATH9K_CHANNEL_CONTEXT */
  746. static const struct ieee80211_iface_combination if_comb[] = {
  747. {
  748. .limits = if_limits,
  749. .n_limits = ARRAY_SIZE(if_limits),
  750. .max_interfaces = 2048,
  751. .num_different_channels = 1,
  752. .beacon_int_infra_match = true,
  753. #ifdef CONFIG_ATH9K_DFS_CERTIFIED
  754. .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
  755. BIT(NL80211_CHAN_WIDTH_20) |
  756. BIT(NL80211_CHAN_WIDTH_40),
  757. #endif
  758. },
  759. };
  760. #ifdef CONFIG_ATH9K_CHANNEL_CONTEXT
  761. static void ath9k_set_mcc_capab(struct ath_softc *sc, struct ieee80211_hw *hw)
  762. {
  763. struct ath_hw *ah = sc->sc_ah;
  764. struct ath_common *common = ath9k_hw_common(ah);
  765. if (!ath9k_is_chanctx_enabled())
  766. return;
  767. ieee80211_hw_set(hw, QUEUE_CONTROL);
  768. hw->queues = ATH9K_NUM_TX_QUEUES;
  769. hw->offchannel_tx_hw_queue = hw->queues - 1;
  770. hw->wiphy->iface_combinations = if_comb_multi;
  771. hw->wiphy->n_iface_combinations = ARRAY_SIZE(if_comb_multi);
  772. hw->wiphy->max_scan_ssids = 255;
  773. hw->wiphy->max_scan_ie_len = IEEE80211_MAX_DATA_LEN;
  774. hw->wiphy->max_remain_on_channel_duration = 10000;
  775. hw->chanctx_data_size = sizeof(void *);
  776. hw->extra_beacon_tailroom =
  777. sizeof(struct ieee80211_p2p_noa_attr) + 9;
  778. ath_dbg(common, CHAN_CTX, "Use channel contexts\n");
  779. }
  780. #endif /* CONFIG_ATH9K_CHANNEL_CONTEXT */
  781. static void ath9k_set_hw_capab(struct ath_softc *sc, struct ieee80211_hw *hw)
  782. {
  783. struct ath_hw *ah = sc->sc_ah;
  784. struct ath_common *common = ath9k_hw_common(ah);
  785. ieee80211_hw_set(hw, SUPPORTS_HT_CCK_RATES);
  786. ieee80211_hw_set(hw, SUPPORTS_RC_TABLE);
  787. ieee80211_hw_set(hw, REPORTS_TX_ACK_STATUS);
  788. ieee80211_hw_set(hw, SPECTRUM_MGMT);
  789. ieee80211_hw_set(hw, PS_NULLFUNC_STACK);
  790. ieee80211_hw_set(hw, SIGNAL_DBM);
  791. ieee80211_hw_set(hw, RX_INCLUDES_FCS);
  792. ieee80211_hw_set(hw, HOST_BROADCAST_PS_BUFFERING);
  793. ieee80211_hw_set(hw, SUPPORT_FAST_XMIT);
  794. ieee80211_hw_set(hw, SUPPORTS_CLONED_SKBS);
  795. if (ath9k_ps_enable)
  796. ieee80211_hw_set(hw, SUPPORTS_PS);
  797. if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_HT) {
  798. ieee80211_hw_set(hw, AMPDU_AGGREGATION);
  799. if (AR_SREV_9280_20_OR_LATER(ah))
  800. hw->radiotap_mcs_details |=
  801. IEEE80211_RADIOTAP_MCS_HAVE_STBC;
  802. }
  803. if (AR_SREV_9160_10_OR_LATER(sc->sc_ah) || ath9k_modparam_nohwcrypt)
  804. ieee80211_hw_set(hw, MFP_CAPABLE);
  805. hw->wiphy->features |= NL80211_FEATURE_ACTIVE_MONITOR |
  806. NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE |
  807. NL80211_FEATURE_P2P_GO_CTWIN;
  808. if (!IS_ENABLED(CONFIG_ATH9K_TX99)) {
  809. hw->wiphy->interface_modes =
  810. BIT(NL80211_IFTYPE_P2P_GO) |
  811. BIT(NL80211_IFTYPE_P2P_CLIENT) |
  812. BIT(NL80211_IFTYPE_AP) |
  813. BIT(NL80211_IFTYPE_STATION) |
  814. BIT(NL80211_IFTYPE_ADHOC) |
  815. BIT(NL80211_IFTYPE_MESH_POINT) |
  816. BIT(NL80211_IFTYPE_OCB);
  817. if (ath9k_is_chanctx_enabled())
  818. hw->wiphy->interface_modes |=
  819. BIT(NL80211_IFTYPE_P2P_DEVICE);
  820. hw->wiphy->iface_combinations = if_comb;
  821. hw->wiphy->n_iface_combinations = ARRAY_SIZE(if_comb);
  822. }
  823. hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
  824. hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
  825. hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS;
  826. hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
  827. hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_5_10_MHZ;
  828. hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
  829. hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
  830. hw->queues = 4;
  831. hw->max_rates = 4;
  832. hw->max_listen_interval = 10;
  833. hw->max_rate_tries = 10;
  834. hw->sta_data_size = sizeof(struct ath_node);
  835. hw->vif_data_size = sizeof(struct ath_vif);
  836. hw->txq_data_size = sizeof(struct ath_atx_tid);
  837. hw->extra_tx_headroom = 4;
  838. hw->wiphy->available_antennas_rx = BIT(ah->caps.max_rxchains) - 1;
  839. hw->wiphy->available_antennas_tx = BIT(ah->caps.max_txchains) - 1;
  840. /* single chain devices with rx diversity */
  841. if (ah->caps.hw_caps & ATH9K_HW_CAP_ANT_DIV_COMB)
  842. hw->wiphy->available_antennas_rx = BIT(0) | BIT(1);
  843. sc->ant_rx = hw->wiphy->available_antennas_rx;
  844. sc->ant_tx = hw->wiphy->available_antennas_tx;
  845. if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_2GHZ)
  846. hw->wiphy->bands[NL80211_BAND_2GHZ] =
  847. &common->sbands[NL80211_BAND_2GHZ];
  848. if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_5GHZ)
  849. hw->wiphy->bands[NL80211_BAND_5GHZ] =
  850. &common->sbands[NL80211_BAND_5GHZ];
  851. #ifdef CONFIG_ATH9K_CHANNEL_CONTEXT
  852. ath9k_set_mcc_capab(sc, hw);
  853. #endif
  854. ath9k_init_wow(hw);
  855. ath9k_cmn_reload_chainmask(ah);
  856. SET_IEEE80211_PERM_ADDR(hw, common->macaddr);
  857. wiphy_ext_feature_set(hw->wiphy, NL80211_EXT_FEATURE_CQM_RSSI_LIST);
  858. wiphy_ext_feature_set(hw->wiphy, NL80211_EXT_FEATURE_AIRTIME_FAIRNESS);
  859. wiphy_ext_feature_set(hw->wiphy,
  860. NL80211_EXT_FEATURE_MULTICAST_REGISTRATIONS);
  861. wiphy_ext_feature_set(hw->wiphy, NL80211_EXT_FEATURE_CAN_REPLACE_PTK0);
  862. }
  863. int ath9k_init_device(u16 devid, struct ath_softc *sc,
  864. const struct ath_bus_ops *bus_ops)
  865. {
  866. struct ieee80211_hw *hw = sc->hw;
  867. struct ath_common *common;
  868. struct ath_hw *ah;
  869. int error = 0;
  870. struct ath_regulatory *reg;
  871. /* Bring up device */
  872. error = ath9k_init_softc(devid, sc, bus_ops);
  873. if (error)
  874. return error;
  875. ah = sc->sc_ah;
  876. common = ath9k_hw_common(ah);
  877. ath9k_set_hw_capab(sc, hw);
  878. /* Initialize regulatory */
  879. error = ath_regd_init(&common->regulatory, sc->hw->wiphy,
  880. ath9k_reg_notifier);
  881. if (error)
  882. goto deinit;
  883. reg = &common->regulatory;
  884. /* Setup TX DMA */
  885. error = ath_tx_init(sc, ATH_TXBUF);
  886. if (error != 0)
  887. goto deinit;
  888. /* Setup RX DMA */
  889. error = ath_rx_init(sc, ATH_RXBUF);
  890. if (error != 0)
  891. goto deinit;
  892. ath9k_init_txpower_limits(sc);
  893. #ifdef CONFIG_MAC80211_LEDS
  894. /* must be initialized before ieee80211_register_hw */
  895. sc->led_cdev.default_trigger = ieee80211_create_tpt_led_trigger(sc->hw,
  896. IEEE80211_TPT_LEDTRIG_FL_RADIO, ath9k_tpt_blink,
  897. ARRAY_SIZE(ath9k_tpt_blink));
  898. #endif
  899. wiphy_read_of_freq_limits(hw->wiphy);
  900. /* Register with mac80211 */
  901. error = ieee80211_register_hw(hw);
  902. if (error)
  903. goto rx_cleanup;
  904. error = ath9k_init_debug(ah);
  905. if (error) {
  906. ath_err(common, "Unable to create debugfs files\n");
  907. goto unregister;
  908. }
  909. /* Handle world regulatory */
  910. if (!ath_is_world_regd(reg)) {
  911. error = regulatory_hint(hw->wiphy, reg->alpha2);
  912. if (error)
  913. goto debug_cleanup;
  914. }
  915. ath_init_leds(sc);
  916. ath_start_rfkill_poll(sc);
  917. return 0;
  918. debug_cleanup:
  919. ath9k_deinit_debug(sc);
  920. unregister:
  921. ieee80211_unregister_hw(hw);
  922. rx_cleanup:
  923. ath_rx_cleanup(sc);
  924. deinit:
  925. ath9k_deinit_softc(sc);
  926. return error;
  927. }
  928. /*****************************/
  929. /* De-Initialization */
  930. /*****************************/
  931. static void ath9k_deinit_softc(struct ath_softc *sc)
  932. {
  933. int i = 0;
  934. ath9k_deinit_p2p(sc);
  935. ath9k_deinit_btcoex(sc);
  936. for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++)
  937. if (ATH_TXQ_SETUP(sc, i))
  938. ath_tx_cleanupq(sc, &sc->tx.txq[i]);
  939. del_timer_sync(&sc->sleep_timer);
  940. ath9k_hw_deinit(sc->sc_ah);
  941. if (sc->dfs_detector != NULL)
  942. sc->dfs_detector->exit(sc->dfs_detector);
  943. ath9k_eeprom_release(sc);
  944. }
  945. void ath9k_deinit_device(struct ath_softc *sc)
  946. {
  947. struct ieee80211_hw *hw = sc->hw;
  948. ath9k_ps_wakeup(sc);
  949. wiphy_rfkill_stop_polling(sc->hw->wiphy);
  950. ath_deinit_leds(sc);
  951. ath9k_ps_restore(sc);
  952. ath9k_deinit_debug(sc);
  953. ath9k_deinit_wow(hw);
  954. ieee80211_unregister_hw(hw);
  955. ath_rx_cleanup(sc);
  956. ath9k_deinit_softc(sc);
  957. }
  958. /************************/
  959. /* Module Hooks */
  960. /************************/
  961. static int __init ath9k_init(void)
  962. {
  963. int error;
  964. error = ath_pci_init();
  965. if (error < 0) {
  966. pr_err("No PCI devices found, driver not installed\n");
  967. error = -ENODEV;
  968. goto err_out;
  969. }
  970. error = ath_ahb_init();
  971. if (error < 0) {
  972. error = -ENODEV;
  973. goto err_pci_exit;
  974. }
  975. dmi_check_system(ath9k_quirks);
  976. return 0;
  977. err_pci_exit:
  978. ath_pci_exit();
  979. err_out:
  980. return error;
  981. }
  982. module_init(ath9k_init);
  983. static void __exit ath9k_exit(void)
  984. {
  985. is_ath9k_unloaded = true;
  986. ath_ahb_exit();
  987. ath_pci_exit();
  988. pr_info("%s: Driver unloaded\n", dev_info);
  989. }
  990. module_exit(ath9k_exit);