init.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215
  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(common->priv);
  132. }
  133. static void ath9k_op_ps_restore(struct ath_common *common)
  134. {
  135. ath9k_ps_restore(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 = 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 = 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 = 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 = 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. ret = of_get_mac_address(np, common->macaddr);
  569. if (ret == -EPROBE_DEFER)
  570. return ret;
  571. return 0;
  572. }
  573. static int ath9k_init_softc(u16 devid, struct ath_softc *sc,
  574. const struct ath_bus_ops *bus_ops)
  575. {
  576. struct ath_hw *ah = NULL;
  577. struct ath9k_hw_capabilities *pCap;
  578. struct ath_common *common;
  579. int ret = 0, i;
  580. int csz = 0;
  581. ah = devm_kzalloc(sc->dev, sizeof(struct ath_hw), GFP_KERNEL);
  582. if (!ah)
  583. return -ENOMEM;
  584. ah->dev = sc->dev;
  585. ah->hw = sc->hw;
  586. ah->hw_version.devid = devid;
  587. ah->ah_flags |= AH_USE_EEPROM;
  588. ah->led_pin = -1;
  589. ah->reg_ops.read = ath9k_ioread32;
  590. ah->reg_ops.multi_read = ath9k_multi_ioread32;
  591. ah->reg_ops.write = ath9k_iowrite32;
  592. ah->reg_ops.rmw = ath9k_reg_rmw;
  593. pCap = &ah->caps;
  594. common = ath9k_hw_common(ah);
  595. /* Will be cleared in ath9k_start() */
  596. set_bit(ATH_OP_INVALID, &common->op_flags);
  597. sc->sc_ah = 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. sc->cur_chan = &sc->chanctx[0];
  602. if (!ath9k_is_chanctx_enabled())
  603. sc->cur_chan->hw_queue_base = 0;
  604. common->ops = &ah->reg_ops;
  605. common->bus_ops = bus_ops;
  606. common->ps_ops = &ath9k_ps_ops;
  607. common->ah = ah;
  608. common->hw = sc->hw;
  609. common->priv = sc;
  610. common->debug_mask = ath9k_debug;
  611. common->btcoex_enabled = ath9k_btcoex_enable == 1;
  612. common->disable_ani = false;
  613. /*
  614. * Platform quirks.
  615. */
  616. ath9k_init_pcoem_platform(sc);
  617. ret = ath9k_init_platform(sc);
  618. if (ret)
  619. return ret;
  620. ret = ath9k_of_init(sc);
  621. if (ret)
  622. return ret;
  623. ret = ath9k_nvmem_request_eeprom(sc);
  624. if (ret)
  625. return ret;
  626. if (ath9k_led_active_high != -1)
  627. ah->config.led_active_high = ath9k_led_active_high == 1;
  628. /*
  629. * Enable WLAN/BT RX Antenna diversity only when:
  630. *
  631. * - BTCOEX is disabled.
  632. * - the user manually requests the feature.
  633. * - the HW cap is set using the platform data.
  634. */
  635. if (!common->btcoex_enabled && ath9k_bt_ant_diversity &&
  636. (pCap->hw_caps & ATH9K_HW_CAP_BT_ANT_DIV))
  637. common->bt_ant_diversity = 1;
  638. spin_lock_init(&common->cc_lock);
  639. spin_lock_init(&sc->intr_lock);
  640. spin_lock_init(&sc->sc_serial_rw);
  641. spin_lock_init(&sc->sc_pm_lock);
  642. spin_lock_init(&sc->chan_lock);
  643. mutex_init(&sc->mutex);
  644. tasklet_setup(&sc->intr_tq, ath9k_tasklet);
  645. tasklet_setup(&sc->bcon_tasklet, ath9k_beacon_tasklet);
  646. timer_setup(&sc->sleep_timer, ath_ps_full_sleep, 0);
  647. INIT_WORK(&sc->hw_reset_work, ath_reset_work);
  648. INIT_WORK(&sc->paprd_work, ath_paprd_calibrate);
  649. INIT_DELAYED_WORK(&sc->hw_pll_work, ath_hw_pll_work);
  650. INIT_DELAYED_WORK(&sc->hw_check_work, ath_hw_check_work);
  651. ath9k_init_channel_context(sc);
  652. /*
  653. * Cache line size is used to size and align various
  654. * structures used to communicate with the hardware.
  655. */
  656. ath_read_cachesize(common, &csz);
  657. common->cachelsz = csz << 2; /* convert to bytes */
  658. /* Initializes the hardware for all supported chipsets */
  659. ret = ath9k_hw_init(ah);
  660. if (ret)
  661. goto err_hw;
  662. ret = ath9k_init_queues(sc);
  663. if (ret)
  664. goto err_queues;
  665. ret = ath9k_init_btcoex(sc);
  666. if (ret)
  667. goto err_btcoex;
  668. ret = ath9k_cmn_init_channels_rates(common);
  669. if (ret)
  670. goto err_btcoex;
  671. ret = ath9k_init_p2p(sc);
  672. if (ret)
  673. goto err_btcoex;
  674. ath9k_cmn_init_crypto(sc->sc_ah);
  675. ath9k_init_misc(sc);
  676. ath_chanctx_init(sc);
  677. ath9k_offchannel_init(sc);
  678. if (common->bus_ops->aspm_init)
  679. common->bus_ops->aspm_init(common);
  680. return 0;
  681. err_btcoex:
  682. for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++)
  683. if (ATH_TXQ_SETUP(sc, i))
  684. ath_tx_cleanupq(sc, &sc->tx.txq[i]);
  685. err_queues:
  686. ath9k_hw_deinit(ah);
  687. err_hw:
  688. ath9k_eeprom_release(sc);
  689. dev_kfree_skb_any(sc->tx99_skb);
  690. return ret;
  691. }
  692. static void ath9k_init_band_txpower(struct ath_softc *sc, int band)
  693. {
  694. struct ieee80211_supported_band *sband;
  695. struct ieee80211_channel *chan;
  696. struct ath_hw *ah = sc->sc_ah;
  697. struct ath_common *common = ath9k_hw_common(ah);
  698. struct cfg80211_chan_def chandef;
  699. int i;
  700. sband = &common->sbands[band];
  701. for (i = 0; i < sband->n_channels; i++) {
  702. chan = &sband->channels[i];
  703. ah->curchan = &ah->channels[chan->hw_value];
  704. cfg80211_chandef_create(&chandef, chan, NL80211_CHAN_HT20);
  705. ath9k_cmn_get_channel(sc->hw, ah, &chandef);
  706. ath9k_hw_set_txpowerlimit(ah, MAX_COMBINED_POWER, true);
  707. }
  708. }
  709. static void ath9k_init_txpower_limits(struct ath_softc *sc)
  710. {
  711. struct ath_hw *ah = sc->sc_ah;
  712. struct ath9k_channel *curchan = ah->curchan;
  713. if (ah->caps.hw_caps & ATH9K_HW_CAP_2GHZ)
  714. ath9k_init_band_txpower(sc, NL80211_BAND_2GHZ);
  715. if (ah->caps.hw_caps & ATH9K_HW_CAP_5GHZ)
  716. ath9k_init_band_txpower(sc, NL80211_BAND_5GHZ);
  717. ah->curchan = curchan;
  718. }
  719. static const struct ieee80211_iface_limit if_limits[] = {
  720. { .max = 2048, .types = BIT(NL80211_IFTYPE_STATION) },
  721. { .max = 8, .types =
  722. #ifdef CONFIG_MAC80211_MESH
  723. BIT(NL80211_IFTYPE_MESH_POINT) |
  724. #endif
  725. BIT(NL80211_IFTYPE_AP) },
  726. { .max = 1, .types = BIT(NL80211_IFTYPE_P2P_CLIENT) |
  727. BIT(NL80211_IFTYPE_P2P_GO) },
  728. };
  729. #ifdef CONFIG_ATH9K_CHANNEL_CONTEXT
  730. static const struct ieee80211_iface_limit if_limits_multi[] = {
  731. { .max = 2, .types = BIT(NL80211_IFTYPE_STATION) |
  732. BIT(NL80211_IFTYPE_AP) |
  733. BIT(NL80211_IFTYPE_P2P_CLIENT) |
  734. BIT(NL80211_IFTYPE_P2P_GO) },
  735. { .max = 1, .types = BIT(NL80211_IFTYPE_ADHOC) },
  736. { .max = 1, .types = BIT(NL80211_IFTYPE_P2P_DEVICE) },
  737. };
  738. static const struct ieee80211_iface_combination if_comb_multi[] = {
  739. {
  740. .limits = if_limits_multi,
  741. .n_limits = ARRAY_SIZE(if_limits_multi),
  742. .max_interfaces = 3,
  743. .num_different_channels = 2,
  744. .beacon_int_infra_match = true,
  745. },
  746. };
  747. #endif /* CONFIG_ATH9K_CHANNEL_CONTEXT */
  748. static const struct ieee80211_iface_combination if_comb[] = {
  749. {
  750. .limits = if_limits,
  751. .n_limits = ARRAY_SIZE(if_limits),
  752. .max_interfaces = 2048,
  753. .num_different_channels = 1,
  754. .beacon_int_infra_match = true,
  755. #ifdef CONFIG_ATH9K_DFS_CERTIFIED
  756. .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
  757. BIT(NL80211_CHAN_WIDTH_20) |
  758. BIT(NL80211_CHAN_WIDTH_40),
  759. #endif
  760. },
  761. };
  762. #ifdef CONFIG_ATH9K_CHANNEL_CONTEXT
  763. static void ath9k_set_mcc_capab(struct ath_softc *sc, struct ieee80211_hw *hw)
  764. {
  765. struct ath_hw *ah = sc->sc_ah;
  766. struct ath_common *common = ath9k_hw_common(ah);
  767. if (!ath9k_is_chanctx_enabled())
  768. return;
  769. ieee80211_hw_set(hw, QUEUE_CONTROL);
  770. hw->queues = ATH9K_NUM_TX_QUEUES;
  771. hw->offchannel_tx_hw_queue = hw->queues - 1;
  772. hw->wiphy->iface_combinations = if_comb_multi;
  773. hw->wiphy->n_iface_combinations = ARRAY_SIZE(if_comb_multi);
  774. hw->wiphy->max_scan_ssids = 255;
  775. hw->wiphy->max_scan_ie_len = IEEE80211_MAX_DATA_LEN;
  776. hw->wiphy->max_remain_on_channel_duration = 10000;
  777. hw->chanctx_data_size = sizeof(void *);
  778. hw->extra_beacon_tailroom =
  779. sizeof(struct ieee80211_p2p_noa_attr) + 9;
  780. ath_dbg(common, CHAN_CTX, "Use channel contexts\n");
  781. }
  782. #endif /* CONFIG_ATH9K_CHANNEL_CONTEXT */
  783. static void ath9k_set_hw_capab(struct ath_softc *sc, struct ieee80211_hw *hw)
  784. {
  785. struct ath_hw *ah = sc->sc_ah;
  786. struct ath_common *common = ath9k_hw_common(ah);
  787. ieee80211_hw_set(hw, SUPPORTS_HT_CCK_RATES);
  788. ieee80211_hw_set(hw, SUPPORTS_RC_TABLE);
  789. ieee80211_hw_set(hw, REPORTS_TX_ACK_STATUS);
  790. ieee80211_hw_set(hw, SPECTRUM_MGMT);
  791. ieee80211_hw_set(hw, PS_NULLFUNC_STACK);
  792. ieee80211_hw_set(hw, SIGNAL_DBM);
  793. ieee80211_hw_set(hw, RX_INCLUDES_FCS);
  794. ieee80211_hw_set(hw, HOST_BROADCAST_PS_BUFFERING);
  795. ieee80211_hw_set(hw, SUPPORT_FAST_XMIT);
  796. ieee80211_hw_set(hw, SUPPORTS_CLONED_SKBS);
  797. if (ath9k_ps_enable)
  798. ieee80211_hw_set(hw, SUPPORTS_PS);
  799. if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_HT) {
  800. ieee80211_hw_set(hw, AMPDU_AGGREGATION);
  801. if (AR_SREV_9280_20_OR_LATER(ah))
  802. hw->radiotap_mcs_details |=
  803. IEEE80211_RADIOTAP_MCS_HAVE_STBC;
  804. }
  805. if (AR_SREV_9160_10_OR_LATER(sc->sc_ah) || ath9k_modparam_nohwcrypt)
  806. ieee80211_hw_set(hw, MFP_CAPABLE);
  807. hw->wiphy->features |= NL80211_FEATURE_ACTIVE_MONITOR |
  808. NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE |
  809. NL80211_FEATURE_P2P_GO_CTWIN;
  810. if (!IS_ENABLED(CONFIG_ATH9K_TX99)) {
  811. hw->wiphy->interface_modes =
  812. BIT(NL80211_IFTYPE_P2P_GO) |
  813. BIT(NL80211_IFTYPE_P2P_CLIENT) |
  814. BIT(NL80211_IFTYPE_AP) |
  815. BIT(NL80211_IFTYPE_STATION) |
  816. BIT(NL80211_IFTYPE_ADHOC) |
  817. BIT(NL80211_IFTYPE_MESH_POINT) |
  818. BIT(NL80211_IFTYPE_OCB);
  819. if (ath9k_is_chanctx_enabled())
  820. hw->wiphy->interface_modes |=
  821. BIT(NL80211_IFTYPE_P2P_DEVICE);
  822. hw->wiphy->iface_combinations = if_comb;
  823. hw->wiphy->n_iface_combinations = ARRAY_SIZE(if_comb);
  824. }
  825. hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
  826. hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
  827. hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS;
  828. hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
  829. hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_5_10_MHZ;
  830. hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
  831. hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
  832. hw->queues = 4;
  833. hw->max_rates = 4;
  834. hw->max_listen_interval = 10;
  835. hw->max_rate_tries = 10;
  836. hw->sta_data_size = sizeof(struct ath_node);
  837. hw->vif_data_size = sizeof(struct ath_vif);
  838. hw->txq_data_size = sizeof(struct ath_atx_tid);
  839. hw->extra_tx_headroom = 4;
  840. hw->wiphy->available_antennas_rx = BIT(ah->caps.max_rxchains) - 1;
  841. hw->wiphy->available_antennas_tx = BIT(ah->caps.max_txchains) - 1;
  842. /* single chain devices with rx diversity */
  843. if (ah->caps.hw_caps & ATH9K_HW_CAP_ANT_DIV_COMB)
  844. hw->wiphy->available_antennas_rx = BIT(0) | BIT(1);
  845. sc->ant_rx = hw->wiphy->available_antennas_rx;
  846. sc->ant_tx = hw->wiphy->available_antennas_tx;
  847. if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_2GHZ)
  848. hw->wiphy->bands[NL80211_BAND_2GHZ] =
  849. &common->sbands[NL80211_BAND_2GHZ];
  850. if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_5GHZ)
  851. hw->wiphy->bands[NL80211_BAND_5GHZ] =
  852. &common->sbands[NL80211_BAND_5GHZ];
  853. #ifdef CONFIG_ATH9K_CHANNEL_CONTEXT
  854. ath9k_set_mcc_capab(sc, hw);
  855. #endif
  856. ath9k_init_wow(hw);
  857. ath9k_cmn_reload_chainmask(ah);
  858. SET_IEEE80211_PERM_ADDR(hw, common->macaddr);
  859. wiphy_ext_feature_set(hw->wiphy, NL80211_EXT_FEATURE_CQM_RSSI_LIST);
  860. wiphy_ext_feature_set(hw->wiphy, NL80211_EXT_FEATURE_AIRTIME_FAIRNESS);
  861. wiphy_ext_feature_set(hw->wiphy,
  862. NL80211_EXT_FEATURE_MULTICAST_REGISTRATIONS);
  863. wiphy_ext_feature_set(hw->wiphy, NL80211_EXT_FEATURE_CAN_REPLACE_PTK0);
  864. }
  865. int ath9k_init_device(u16 devid, struct ath_softc *sc,
  866. const struct ath_bus_ops *bus_ops)
  867. {
  868. struct ieee80211_hw *hw = sc->hw;
  869. struct ath_common *common;
  870. struct ath_hw *ah;
  871. int error = 0;
  872. struct ath_regulatory *reg;
  873. /* Bring up device */
  874. error = ath9k_init_softc(devid, sc, bus_ops);
  875. if (error)
  876. return error;
  877. ah = sc->sc_ah;
  878. common = ath9k_hw_common(ah);
  879. ath9k_set_hw_capab(sc, hw);
  880. /* Initialize regulatory */
  881. error = ath_regd_init(&common->regulatory, sc->hw->wiphy,
  882. ath9k_reg_notifier);
  883. if (error)
  884. goto deinit;
  885. reg = &common->regulatory;
  886. /* Setup TX DMA */
  887. error = ath_tx_init(sc, ATH_TXBUF);
  888. if (error != 0)
  889. goto deinit;
  890. /* Setup RX DMA */
  891. error = ath_rx_init(sc, ATH_RXBUF);
  892. if (error != 0)
  893. goto deinit;
  894. ath9k_init_txpower_limits(sc);
  895. #ifdef CONFIG_MAC80211_LEDS
  896. /* must be initialized before ieee80211_register_hw */
  897. sc->led_cdev.default_trigger = ieee80211_create_tpt_led_trigger(sc->hw,
  898. IEEE80211_TPT_LEDTRIG_FL_RADIO, ath9k_tpt_blink,
  899. ARRAY_SIZE(ath9k_tpt_blink));
  900. #endif
  901. wiphy_read_of_freq_limits(hw->wiphy);
  902. /* Register with mac80211 */
  903. error = ieee80211_register_hw(hw);
  904. if (error)
  905. goto rx_cleanup;
  906. error = ath9k_init_debug(ah);
  907. if (error) {
  908. ath_err(common, "Unable to create debugfs files\n");
  909. goto unregister;
  910. }
  911. /* Handle world regulatory */
  912. if (!ath_is_world_regd(reg)) {
  913. error = regulatory_hint(hw->wiphy, reg->alpha2);
  914. if (error)
  915. goto debug_cleanup;
  916. }
  917. ath_init_leds(sc);
  918. ath_start_rfkill_poll(sc);
  919. return 0;
  920. debug_cleanup:
  921. ath9k_deinit_debug(sc);
  922. unregister:
  923. ieee80211_unregister_hw(hw);
  924. rx_cleanup:
  925. ath_rx_cleanup(sc);
  926. deinit:
  927. ath9k_deinit_softc(sc);
  928. return error;
  929. }
  930. /*****************************/
  931. /* De-Initialization */
  932. /*****************************/
  933. static void ath9k_deinit_softc(struct ath_softc *sc)
  934. {
  935. int i = 0;
  936. ath9k_deinit_p2p(sc);
  937. ath9k_deinit_btcoex(sc);
  938. for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++)
  939. if (ATH_TXQ_SETUP(sc, i))
  940. ath_tx_cleanupq(sc, &sc->tx.txq[i]);
  941. del_timer_sync(&sc->sleep_timer);
  942. ath9k_hw_deinit(sc->sc_ah);
  943. if (sc->dfs_detector != NULL)
  944. sc->dfs_detector->exit(sc->dfs_detector);
  945. ath9k_eeprom_release(sc);
  946. }
  947. void ath9k_deinit_device(struct ath_softc *sc)
  948. {
  949. struct ieee80211_hw *hw = sc->hw;
  950. ath9k_ps_wakeup(sc);
  951. wiphy_rfkill_stop_polling(sc->hw->wiphy);
  952. ath_deinit_leds(sc);
  953. ath9k_ps_restore(sc);
  954. ath9k_deinit_debug(sc);
  955. ath9k_deinit_wow(hw);
  956. ieee80211_unregister_hw(hw);
  957. ath_rx_cleanup(sc);
  958. ath9k_deinit_softc(sc);
  959. }
  960. /************************/
  961. /* Module Hooks */
  962. /************************/
  963. static int __init ath9k_init(void)
  964. {
  965. int error;
  966. error = ath_pci_init();
  967. if (error < 0) {
  968. pr_err("No PCI devices found, driver not installed\n");
  969. error = -ENODEV;
  970. goto err_out;
  971. }
  972. error = ath_ahb_init();
  973. if (error < 0) {
  974. error = -ENODEV;
  975. goto err_pci_exit;
  976. }
  977. dmi_check_system(ath9k_quirks);
  978. return 0;
  979. err_pci_exit:
  980. ath_pci_exit();
  981. err_out:
  982. return error;
  983. }
  984. module_init(ath9k_init);
  985. static void __exit ath9k_exit(void)
  986. {
  987. is_ath9k_unloaded = true;
  988. ath_ahb_exit();
  989. ath_pci_exit();
  990. pr_info("%s: Driver unloaded\n", dev_info);
  991. }
  992. module_exit(ath9k_exit);