init.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149
  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. bool is_ath9k_unloaded;
  49. /* We use the hw_value as an index into our private channel structure */
  50. #define CHAN2G(_freq, _idx) { \
  51. .band = IEEE80211_BAND_2GHZ, \
  52. .center_freq = (_freq), \
  53. .hw_value = (_idx), \
  54. .max_power = 20, \
  55. }
  56. #define CHAN5G(_freq, _idx) { \
  57. .band = IEEE80211_BAND_5GHZ, \
  58. .center_freq = (_freq), \
  59. .hw_value = (_idx), \
  60. .max_power = 20, \
  61. }
  62. /* Some 2 GHz radios are actually tunable on 2312-2732
  63. * on 5 MHz steps, we support the channels which we know
  64. * we have calibration data for all cards though to make
  65. * this static */
  66. static const struct ieee80211_channel ath9k_2ghz_chantable[] = {
  67. CHAN2G(2412, 0), /* Channel 1 */
  68. CHAN2G(2417, 1), /* Channel 2 */
  69. CHAN2G(2422, 2), /* Channel 3 */
  70. CHAN2G(2427, 3), /* Channel 4 */
  71. CHAN2G(2432, 4), /* Channel 5 */
  72. CHAN2G(2437, 5), /* Channel 6 */
  73. CHAN2G(2442, 6), /* Channel 7 */
  74. CHAN2G(2447, 7), /* Channel 8 */
  75. CHAN2G(2452, 8), /* Channel 9 */
  76. CHAN2G(2457, 9), /* Channel 10 */
  77. CHAN2G(2462, 10), /* Channel 11 */
  78. CHAN2G(2467, 11), /* Channel 12 */
  79. CHAN2G(2472, 12), /* Channel 13 */
  80. CHAN2G(2484, 13), /* Channel 14 */
  81. };
  82. /* Some 5 GHz radios are actually tunable on XXXX-YYYY
  83. * on 5 MHz steps, we support the channels which we know
  84. * we have calibration data for all cards though to make
  85. * this static */
  86. static const struct ieee80211_channel ath9k_5ghz_chantable[] = {
  87. /* _We_ call this UNII 1 */
  88. CHAN5G(5180, 14), /* Channel 36 */
  89. CHAN5G(5200, 15), /* Channel 40 */
  90. CHAN5G(5220, 16), /* Channel 44 */
  91. CHAN5G(5240, 17), /* Channel 48 */
  92. /* _We_ call this UNII 2 */
  93. CHAN5G(5260, 18), /* Channel 52 */
  94. CHAN5G(5280, 19), /* Channel 56 */
  95. CHAN5G(5300, 20), /* Channel 60 */
  96. CHAN5G(5320, 21), /* Channel 64 */
  97. /* _We_ call this "Middle band" */
  98. CHAN5G(5500, 22), /* Channel 100 */
  99. CHAN5G(5520, 23), /* Channel 104 */
  100. CHAN5G(5540, 24), /* Channel 108 */
  101. CHAN5G(5560, 25), /* Channel 112 */
  102. CHAN5G(5580, 26), /* Channel 116 */
  103. CHAN5G(5600, 27), /* Channel 120 */
  104. CHAN5G(5620, 28), /* Channel 124 */
  105. CHAN5G(5640, 29), /* Channel 128 */
  106. CHAN5G(5660, 30), /* Channel 132 */
  107. CHAN5G(5680, 31), /* Channel 136 */
  108. CHAN5G(5700, 32), /* Channel 140 */
  109. /* _We_ call this UNII 3 */
  110. CHAN5G(5745, 33), /* Channel 149 */
  111. CHAN5G(5765, 34), /* Channel 153 */
  112. CHAN5G(5785, 35), /* Channel 157 */
  113. CHAN5G(5805, 36), /* Channel 161 */
  114. CHAN5G(5825, 37), /* Channel 165 */
  115. };
  116. /* Atheros hardware rate code addition for short premble */
  117. #define SHPCHECK(__hw_rate, __flags) \
  118. ((__flags & IEEE80211_RATE_SHORT_PREAMBLE) ? (__hw_rate | 0x04 ) : 0)
  119. #define RATE(_bitrate, _hw_rate, _flags) { \
  120. .bitrate = (_bitrate), \
  121. .flags = (_flags), \
  122. .hw_value = (_hw_rate), \
  123. .hw_value_short = (SHPCHECK(_hw_rate, _flags)) \
  124. }
  125. static struct ieee80211_rate ath9k_legacy_rates[] = {
  126. RATE(10, 0x1b, 0),
  127. RATE(20, 0x1a, IEEE80211_RATE_SHORT_PREAMBLE),
  128. RATE(55, 0x19, IEEE80211_RATE_SHORT_PREAMBLE),
  129. RATE(110, 0x18, IEEE80211_RATE_SHORT_PREAMBLE),
  130. RATE(60, 0x0b, (IEEE80211_RATE_SUPPORTS_5MHZ |
  131. IEEE80211_RATE_SUPPORTS_10MHZ)),
  132. RATE(90, 0x0f, (IEEE80211_RATE_SUPPORTS_5MHZ |
  133. IEEE80211_RATE_SUPPORTS_10MHZ)),
  134. RATE(120, 0x0a, (IEEE80211_RATE_SUPPORTS_5MHZ |
  135. IEEE80211_RATE_SUPPORTS_10MHZ)),
  136. RATE(180, 0x0e, (IEEE80211_RATE_SUPPORTS_5MHZ |
  137. IEEE80211_RATE_SUPPORTS_10MHZ)),
  138. RATE(240, 0x09, (IEEE80211_RATE_SUPPORTS_5MHZ |
  139. IEEE80211_RATE_SUPPORTS_10MHZ)),
  140. RATE(360, 0x0d, (IEEE80211_RATE_SUPPORTS_5MHZ |
  141. IEEE80211_RATE_SUPPORTS_10MHZ)),
  142. RATE(480, 0x08, (IEEE80211_RATE_SUPPORTS_5MHZ |
  143. IEEE80211_RATE_SUPPORTS_10MHZ)),
  144. RATE(540, 0x0c, (IEEE80211_RATE_SUPPORTS_5MHZ |
  145. IEEE80211_RATE_SUPPORTS_10MHZ)),
  146. };
  147. #ifdef CONFIG_MAC80211_LEDS
  148. static const struct ieee80211_tpt_blink ath9k_tpt_blink[] = {
  149. { .throughput = 0 * 1024, .blink_time = 334 },
  150. { .throughput = 1 * 1024, .blink_time = 260 },
  151. { .throughput = 5 * 1024, .blink_time = 220 },
  152. { .throughput = 10 * 1024, .blink_time = 190 },
  153. { .throughput = 20 * 1024, .blink_time = 170 },
  154. { .throughput = 50 * 1024, .blink_time = 150 },
  155. { .throughput = 70 * 1024, .blink_time = 130 },
  156. { .throughput = 100 * 1024, .blink_time = 110 },
  157. { .throughput = 200 * 1024, .blink_time = 80 },
  158. { .throughput = 300 * 1024, .blink_time = 50 },
  159. };
  160. #endif
  161. static void ath9k_deinit_softc(struct ath_softc *sc);
  162. /*
  163. * Read and write, they both share the same lock. We do this to serialize
  164. * reads and writes on Atheros 802.11n PCI devices only. This is required
  165. * as the FIFO on these devices can only accept sanely 2 requests.
  166. */
  167. static void ath9k_iowrite32(void *hw_priv, u32 val, u32 reg_offset)
  168. {
  169. struct ath_hw *ah = (struct ath_hw *) hw_priv;
  170. struct ath_common *common = ath9k_hw_common(ah);
  171. struct ath_softc *sc = (struct ath_softc *) common->priv;
  172. if (NR_CPUS > 1 && ah->config.serialize_regmode == SER_REG_MODE_ON) {
  173. unsigned long flags;
  174. spin_lock_irqsave(&sc->sc_serial_rw, flags);
  175. iowrite32(val, sc->mem + reg_offset);
  176. spin_unlock_irqrestore(&sc->sc_serial_rw, flags);
  177. } else
  178. iowrite32(val, sc->mem + reg_offset);
  179. }
  180. static unsigned int ath9k_ioread32(void *hw_priv, u32 reg_offset)
  181. {
  182. struct ath_hw *ah = (struct ath_hw *) hw_priv;
  183. struct ath_common *common = ath9k_hw_common(ah);
  184. struct ath_softc *sc = (struct ath_softc *) common->priv;
  185. u32 val;
  186. if (NR_CPUS > 1 && ah->config.serialize_regmode == SER_REG_MODE_ON) {
  187. unsigned long flags;
  188. spin_lock_irqsave(&sc->sc_serial_rw, flags);
  189. val = ioread32(sc->mem + reg_offset);
  190. spin_unlock_irqrestore(&sc->sc_serial_rw, flags);
  191. } else
  192. val = ioread32(sc->mem + reg_offset);
  193. return val;
  194. }
  195. static unsigned int __ath9k_reg_rmw(struct ath_softc *sc, u32 reg_offset,
  196. u32 set, u32 clr)
  197. {
  198. u32 val;
  199. val = ioread32(sc->mem + reg_offset);
  200. val &= ~clr;
  201. val |= set;
  202. iowrite32(val, sc->mem + reg_offset);
  203. return val;
  204. }
  205. static unsigned int ath9k_reg_rmw(void *hw_priv, u32 reg_offset, u32 set, u32 clr)
  206. {
  207. struct ath_hw *ah = (struct ath_hw *) hw_priv;
  208. struct ath_common *common = ath9k_hw_common(ah);
  209. struct ath_softc *sc = (struct ath_softc *) common->priv;
  210. unsigned long uninitialized_var(flags);
  211. u32 val;
  212. if (NR_CPUS > 1 && ah->config.serialize_regmode == SER_REG_MODE_ON) {
  213. spin_lock_irqsave(&sc->sc_serial_rw, flags);
  214. val = __ath9k_reg_rmw(sc, reg_offset, set, clr);
  215. spin_unlock_irqrestore(&sc->sc_serial_rw, flags);
  216. } else
  217. val = __ath9k_reg_rmw(sc, reg_offset, set, clr);
  218. return val;
  219. }
  220. /**************************/
  221. /* Initialization */
  222. /**************************/
  223. static void setup_ht_cap(struct ath_softc *sc,
  224. struct ieee80211_sta_ht_cap *ht_info)
  225. {
  226. struct ath_hw *ah = sc->sc_ah;
  227. struct ath_common *common = ath9k_hw_common(ah);
  228. u8 tx_streams, rx_streams;
  229. int i, max_streams;
  230. ht_info->ht_supported = true;
  231. ht_info->cap = IEEE80211_HT_CAP_SUP_WIDTH_20_40 |
  232. IEEE80211_HT_CAP_SM_PS |
  233. IEEE80211_HT_CAP_SGI_40 |
  234. IEEE80211_HT_CAP_DSSSCCK40;
  235. if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_LDPC)
  236. ht_info->cap |= IEEE80211_HT_CAP_LDPC_CODING;
  237. if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_SGI_20)
  238. ht_info->cap |= IEEE80211_HT_CAP_SGI_20;
  239. ht_info->ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
  240. ht_info->ampdu_density = IEEE80211_HT_MPDU_DENSITY_8;
  241. if (AR_SREV_9330(ah) || AR_SREV_9485(ah) || AR_SREV_9565(ah))
  242. max_streams = 1;
  243. else if (AR_SREV_9462(ah))
  244. max_streams = 2;
  245. else if (AR_SREV_9300_20_OR_LATER(ah))
  246. max_streams = 3;
  247. else
  248. max_streams = 2;
  249. if (AR_SREV_9280_20_OR_LATER(ah)) {
  250. if (max_streams >= 2)
  251. ht_info->cap |= IEEE80211_HT_CAP_TX_STBC;
  252. ht_info->cap |= (1 << IEEE80211_HT_CAP_RX_STBC_SHIFT);
  253. }
  254. /* set up supported mcs set */
  255. memset(&ht_info->mcs, 0, sizeof(ht_info->mcs));
  256. tx_streams = ath9k_cmn_count_streams(ah->txchainmask, max_streams);
  257. rx_streams = ath9k_cmn_count_streams(ah->rxchainmask, max_streams);
  258. ath_dbg(common, CONFIG, "TX streams %d, RX streams: %d\n",
  259. tx_streams, rx_streams);
  260. if (tx_streams != rx_streams) {
  261. ht_info->mcs.tx_params |= IEEE80211_HT_MCS_TX_RX_DIFF;
  262. ht_info->mcs.tx_params |= ((tx_streams - 1) <<
  263. IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT);
  264. }
  265. for (i = 0; i < rx_streams; i++)
  266. ht_info->mcs.rx_mask[i] = 0xff;
  267. ht_info->mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
  268. }
  269. static void ath9k_reg_notifier(struct wiphy *wiphy,
  270. struct regulatory_request *request)
  271. {
  272. struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
  273. struct ath_softc *sc = hw->priv;
  274. struct ath_hw *ah = sc->sc_ah;
  275. struct ath_regulatory *reg = ath9k_hw_regulatory(ah);
  276. ath_reg_notifier_apply(wiphy, request, reg);
  277. /* Set tx power */
  278. if (ah->curchan) {
  279. sc->config.txpowlimit = 2 * ah->curchan->chan->max_power;
  280. ath9k_ps_wakeup(sc);
  281. ath9k_hw_set_txpowerlimit(ah, sc->config.txpowlimit, false);
  282. sc->curtxpow = ath9k_hw_regulatory(ah)->power_limit;
  283. /* synchronize DFS detector if regulatory domain changed */
  284. if (sc->dfs_detector != NULL)
  285. sc->dfs_detector->set_dfs_domain(sc->dfs_detector,
  286. request->dfs_region);
  287. ath9k_ps_restore(sc);
  288. }
  289. }
  290. /*
  291. * This function will allocate both the DMA descriptor structure, and the
  292. * buffers it contains. These are used to contain the descriptors used
  293. * by the system.
  294. */
  295. int ath_descdma_setup(struct ath_softc *sc, struct ath_descdma *dd,
  296. struct list_head *head, const char *name,
  297. int nbuf, int ndesc, bool is_tx)
  298. {
  299. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  300. u8 *ds;
  301. int i, bsize, desc_len;
  302. ath_dbg(common, CONFIG, "%s DMA: %u buffers %u desc/buf\n",
  303. name, nbuf, ndesc);
  304. INIT_LIST_HEAD(head);
  305. if (is_tx)
  306. desc_len = sc->sc_ah->caps.tx_desc_len;
  307. else
  308. desc_len = sizeof(struct ath_desc);
  309. /* ath_desc must be a multiple of DWORDs */
  310. if ((desc_len % 4) != 0) {
  311. ath_err(common, "ath_desc not DWORD aligned\n");
  312. BUG_ON((desc_len % 4) != 0);
  313. return -ENOMEM;
  314. }
  315. dd->dd_desc_len = desc_len * nbuf * ndesc;
  316. /*
  317. * Need additional DMA memory because we can't use
  318. * descriptors that cross the 4K page boundary. Assume
  319. * one skipped descriptor per 4K page.
  320. */
  321. if (!(sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_4KB_SPLITTRANS)) {
  322. u32 ndesc_skipped =
  323. ATH_DESC_4KB_BOUND_NUM_SKIPPED(dd->dd_desc_len);
  324. u32 dma_len;
  325. while (ndesc_skipped) {
  326. dma_len = ndesc_skipped * desc_len;
  327. dd->dd_desc_len += dma_len;
  328. ndesc_skipped = ATH_DESC_4KB_BOUND_NUM_SKIPPED(dma_len);
  329. }
  330. }
  331. /* allocate descriptors */
  332. dd->dd_desc = dmam_alloc_coherent(sc->dev, dd->dd_desc_len,
  333. &dd->dd_desc_paddr, GFP_KERNEL);
  334. if (!dd->dd_desc)
  335. return -ENOMEM;
  336. ds = (u8 *) dd->dd_desc;
  337. ath_dbg(common, CONFIG, "%s DMA map: %p (%u) -> %llx (%u)\n",
  338. name, ds, (u32) dd->dd_desc_len,
  339. ito64(dd->dd_desc_paddr), /*XXX*/(u32) dd->dd_desc_len);
  340. /* allocate buffers */
  341. if (is_tx) {
  342. struct ath_buf *bf;
  343. bsize = sizeof(struct ath_buf) * nbuf;
  344. bf = devm_kzalloc(sc->dev, bsize, GFP_KERNEL);
  345. if (!bf)
  346. return -ENOMEM;
  347. for (i = 0; i < nbuf; i++, bf++, ds += (desc_len * ndesc)) {
  348. bf->bf_desc = ds;
  349. bf->bf_daddr = DS2PHYS(dd, ds);
  350. if (!(sc->sc_ah->caps.hw_caps &
  351. ATH9K_HW_CAP_4KB_SPLITTRANS)) {
  352. /*
  353. * Skip descriptor addresses which can cause 4KB
  354. * boundary crossing (addr + length) with a 32 dword
  355. * descriptor fetch.
  356. */
  357. while (ATH_DESC_4KB_BOUND_CHECK(bf->bf_daddr)) {
  358. BUG_ON((caddr_t) bf->bf_desc >=
  359. ((caddr_t) dd->dd_desc +
  360. dd->dd_desc_len));
  361. ds += (desc_len * ndesc);
  362. bf->bf_desc = ds;
  363. bf->bf_daddr = DS2PHYS(dd, ds);
  364. }
  365. }
  366. list_add_tail(&bf->list, head);
  367. }
  368. } else {
  369. struct ath_rxbuf *bf;
  370. bsize = sizeof(struct ath_rxbuf) * nbuf;
  371. bf = devm_kzalloc(sc->dev, bsize, GFP_KERNEL);
  372. if (!bf)
  373. return -ENOMEM;
  374. for (i = 0; i < nbuf; i++, bf++, ds += (desc_len * ndesc)) {
  375. bf->bf_desc = ds;
  376. bf->bf_daddr = DS2PHYS(dd, ds);
  377. if (!(sc->sc_ah->caps.hw_caps &
  378. ATH9K_HW_CAP_4KB_SPLITTRANS)) {
  379. /*
  380. * Skip descriptor addresses which can cause 4KB
  381. * boundary crossing (addr + length) with a 32 dword
  382. * descriptor fetch.
  383. */
  384. while (ATH_DESC_4KB_BOUND_CHECK(bf->bf_daddr)) {
  385. BUG_ON((caddr_t) bf->bf_desc >=
  386. ((caddr_t) dd->dd_desc +
  387. dd->dd_desc_len));
  388. ds += (desc_len * ndesc);
  389. bf->bf_desc = ds;
  390. bf->bf_daddr = DS2PHYS(dd, ds);
  391. }
  392. }
  393. list_add_tail(&bf->list, head);
  394. }
  395. }
  396. return 0;
  397. }
  398. static int ath9k_init_queues(struct ath_softc *sc)
  399. {
  400. int i = 0;
  401. sc->beacon.beaconq = ath9k_hw_beaconq_setup(sc->sc_ah);
  402. sc->beacon.cabq = ath_txq_setup(sc, ATH9K_TX_QUEUE_CAB, 0);
  403. ath_cabq_update(sc);
  404. sc->tx.uapsdq = ath_txq_setup(sc, ATH9K_TX_QUEUE_UAPSD, 0);
  405. for (i = 0; i < IEEE80211_NUM_ACS; i++) {
  406. sc->tx.txq_map[i] = ath_txq_setup(sc, ATH9K_TX_QUEUE_DATA, i);
  407. sc->tx.txq_map[i]->mac80211_qnum = i;
  408. sc->tx.txq_max_pending[i] = ATH_MAX_QDEPTH;
  409. }
  410. return 0;
  411. }
  412. static int ath9k_init_channels_rates(struct ath_softc *sc)
  413. {
  414. void *channels;
  415. BUILD_BUG_ON(ARRAY_SIZE(ath9k_2ghz_chantable) +
  416. ARRAY_SIZE(ath9k_5ghz_chantable) !=
  417. ATH9K_NUM_CHANNELS);
  418. if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_2GHZ) {
  419. channels = devm_kzalloc(sc->dev,
  420. sizeof(ath9k_2ghz_chantable), GFP_KERNEL);
  421. if (!channels)
  422. return -ENOMEM;
  423. memcpy(channels, ath9k_2ghz_chantable,
  424. sizeof(ath9k_2ghz_chantable));
  425. sc->sbands[IEEE80211_BAND_2GHZ].channels = channels;
  426. sc->sbands[IEEE80211_BAND_2GHZ].band = IEEE80211_BAND_2GHZ;
  427. sc->sbands[IEEE80211_BAND_2GHZ].n_channels =
  428. ARRAY_SIZE(ath9k_2ghz_chantable);
  429. sc->sbands[IEEE80211_BAND_2GHZ].bitrates = ath9k_legacy_rates;
  430. sc->sbands[IEEE80211_BAND_2GHZ].n_bitrates =
  431. ARRAY_SIZE(ath9k_legacy_rates);
  432. }
  433. if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_5GHZ) {
  434. channels = devm_kzalloc(sc->dev,
  435. sizeof(ath9k_5ghz_chantable), GFP_KERNEL);
  436. if (!channels)
  437. return -ENOMEM;
  438. memcpy(channels, ath9k_5ghz_chantable,
  439. sizeof(ath9k_5ghz_chantable));
  440. sc->sbands[IEEE80211_BAND_5GHZ].channels = channels;
  441. sc->sbands[IEEE80211_BAND_5GHZ].band = IEEE80211_BAND_5GHZ;
  442. sc->sbands[IEEE80211_BAND_5GHZ].n_channels =
  443. ARRAY_SIZE(ath9k_5ghz_chantable);
  444. sc->sbands[IEEE80211_BAND_5GHZ].bitrates =
  445. ath9k_legacy_rates + 4;
  446. sc->sbands[IEEE80211_BAND_5GHZ].n_bitrates =
  447. ARRAY_SIZE(ath9k_legacy_rates) - 4;
  448. }
  449. return 0;
  450. }
  451. static void ath9k_init_misc(struct ath_softc *sc)
  452. {
  453. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  454. int i = 0;
  455. setup_timer(&common->ani.timer, ath_ani_calibrate, (unsigned long)sc);
  456. sc->last_rssi = ATH_RSSI_DUMMY_MARKER;
  457. sc->config.txpowlimit = ATH_TXPOWER_MAX;
  458. memcpy(common->bssidmask, ath_bcast_mac, ETH_ALEN);
  459. sc->beacon.slottime = ATH9K_SLOT_TIME_9;
  460. for (i = 0; i < ARRAY_SIZE(sc->beacon.bslot); i++)
  461. sc->beacon.bslot[i] = NULL;
  462. if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_ANT_DIV_COMB)
  463. sc->ant_comb.count = ATH_ANT_DIV_COMB_INIT_COUNT;
  464. sc->spec_config.enabled = 0;
  465. sc->spec_config.short_repeat = true;
  466. sc->spec_config.count = 8;
  467. sc->spec_config.endless = false;
  468. sc->spec_config.period = 0xFF;
  469. sc->spec_config.fft_period = 0xF;
  470. }
  471. static void ath9k_init_pcoem_platform(struct ath_softc *sc)
  472. {
  473. struct ath_hw *ah = sc->sc_ah;
  474. struct ath9k_hw_capabilities *pCap = &ah->caps;
  475. struct ath_common *common = ath9k_hw_common(ah);
  476. if (common->bus_ops->ath_bus_type != ATH_PCI)
  477. return;
  478. if (sc->driver_data & (ATH9K_PCI_CUS198 |
  479. ATH9K_PCI_CUS230)) {
  480. ah->config.xlna_gpio = 9;
  481. ah->config.xatten_margin_cfg = true;
  482. ah->config.alt_mingainidx = true;
  483. ah->config.ant_ctrl_comm2g_switch_enable = 0x000BBB88;
  484. sc->ant_comb.low_rssi_thresh = 20;
  485. sc->ant_comb.fast_div_bias = 3;
  486. ath_info(common, "Set parameters for %s\n",
  487. (sc->driver_data & ATH9K_PCI_CUS198) ?
  488. "CUS198" : "CUS230");
  489. }
  490. if (sc->driver_data & ATH9K_PCI_CUS217)
  491. ath_info(common, "CUS217 card detected\n");
  492. if (sc->driver_data & ATH9K_PCI_CUS252)
  493. ath_info(common, "CUS252 card detected\n");
  494. if (sc->driver_data & ATH9K_PCI_AR9565_1ANT)
  495. ath_info(common, "WB335 1-ANT card detected\n");
  496. if (sc->driver_data & ATH9K_PCI_AR9565_2ANT)
  497. ath_info(common, "WB335 2-ANT card detected\n");
  498. if (sc->driver_data & ATH9K_PCI_KILLER)
  499. ath_info(common, "Killer Wireless card detected\n");
  500. /*
  501. * Some WB335 cards do not support antenna diversity. Since
  502. * we use a hardcoded value for AR9565 instead of using the
  503. * EEPROM/OTP data, remove the combining feature from
  504. * the HW capabilities bitmap.
  505. */
  506. if (sc->driver_data & (ATH9K_PCI_AR9565_1ANT | ATH9K_PCI_AR9565_2ANT)) {
  507. if (!(sc->driver_data & ATH9K_PCI_BT_ANT_DIV))
  508. pCap->hw_caps &= ~ATH9K_HW_CAP_ANT_DIV_COMB;
  509. }
  510. if (sc->driver_data & ATH9K_PCI_BT_ANT_DIV) {
  511. pCap->hw_caps |= ATH9K_HW_CAP_BT_ANT_DIV;
  512. ath_info(common, "Set BT/WLAN RX diversity capability\n");
  513. }
  514. if (sc->driver_data & ATH9K_PCI_D3_L1_WAR) {
  515. ah->config.pcie_waen = 0x0040473b;
  516. ath_info(common, "Enable WAR for ASPM D3/L1\n");
  517. }
  518. if (sc->driver_data & ATH9K_PCI_NO_PLL_PWRSAVE) {
  519. ah->config.no_pll_pwrsave = true;
  520. ath_info(common, "Disable PLL PowerSave\n");
  521. }
  522. }
  523. static void ath9k_eeprom_request_cb(const struct firmware *eeprom_blob,
  524. void *ctx)
  525. {
  526. struct ath9k_eeprom_ctx *ec = ctx;
  527. if (eeprom_blob)
  528. ec->ah->eeprom_blob = eeprom_blob;
  529. complete(&ec->complete);
  530. }
  531. static int ath9k_eeprom_request(struct ath_softc *sc, const char *name)
  532. {
  533. struct ath9k_eeprom_ctx ec;
  534. struct ath_hw *ah = ah = sc->sc_ah;
  535. int err;
  536. /* try to load the EEPROM content asynchronously */
  537. init_completion(&ec.complete);
  538. ec.ah = sc->sc_ah;
  539. err = request_firmware_nowait(THIS_MODULE, 1, name, sc->dev, GFP_KERNEL,
  540. &ec, ath9k_eeprom_request_cb);
  541. if (err < 0) {
  542. ath_err(ath9k_hw_common(ah),
  543. "EEPROM request failed\n");
  544. return err;
  545. }
  546. wait_for_completion(&ec.complete);
  547. if (!ah->eeprom_blob) {
  548. ath_err(ath9k_hw_common(ah),
  549. "Unable to load EEPROM file %s\n", name);
  550. return -EINVAL;
  551. }
  552. return 0;
  553. }
  554. static void ath9k_eeprom_release(struct ath_softc *sc)
  555. {
  556. release_firmware(sc->sc_ah->eeprom_blob);
  557. }
  558. static int ath9k_init_soc_platform(struct ath_softc *sc)
  559. {
  560. struct ath9k_platform_data *pdata = sc->dev->platform_data;
  561. struct ath_hw *ah = sc->sc_ah;
  562. int ret = 0;
  563. if (!pdata)
  564. return 0;
  565. if (pdata->eeprom_name) {
  566. ret = ath9k_eeprom_request(sc, pdata->eeprom_name);
  567. if (ret)
  568. return ret;
  569. }
  570. if (pdata->tx_gain_buffalo)
  571. ah->config.tx_gain_buffalo = true;
  572. return ret;
  573. }
  574. static int ath9k_init_softc(u16 devid, struct ath_softc *sc,
  575. const struct ath_bus_ops *bus_ops)
  576. {
  577. struct ath9k_platform_data *pdata = sc->dev->platform_data;
  578. struct ath_hw *ah = NULL;
  579. struct ath9k_hw_capabilities *pCap;
  580. struct ath_common *common;
  581. int ret = 0, i;
  582. int csz = 0;
  583. ah = devm_kzalloc(sc->dev, sizeof(struct ath_hw), GFP_KERNEL);
  584. if (!ah)
  585. return -ENOMEM;
  586. ah->dev = sc->dev;
  587. ah->hw = sc->hw;
  588. ah->hw_version.devid = devid;
  589. ah->reg_ops.read = ath9k_ioread32;
  590. ah->reg_ops.write = ath9k_iowrite32;
  591. ah->reg_ops.rmw = ath9k_reg_rmw;
  592. atomic_set(&ah->intr_ref_cnt, -1);
  593. sc->sc_ah = ah;
  594. pCap = &ah->caps;
  595. common = ath9k_hw_common(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. if (!pdata) {
  600. ah->ah_flags |= AH_USE_EEPROM;
  601. sc->sc_ah->led_pin = -1;
  602. } else {
  603. sc->sc_ah->gpio_mask = pdata->gpio_mask;
  604. sc->sc_ah->gpio_val = pdata->gpio_val;
  605. sc->sc_ah->led_pin = pdata->led_pin;
  606. ah->is_clk_25mhz = pdata->is_clk_25mhz;
  607. ah->get_mac_revision = pdata->get_mac_revision;
  608. ah->external_reset = pdata->external_reset;
  609. }
  610. common->ops = &ah->reg_ops;
  611. common->bus_ops = bus_ops;
  612. common->ah = ah;
  613. common->hw = sc->hw;
  614. common->priv = sc;
  615. common->debug_mask = ath9k_debug;
  616. common->btcoex_enabled = ath9k_btcoex_enable == 1;
  617. common->disable_ani = false;
  618. /*
  619. * Platform quirks.
  620. */
  621. ath9k_init_pcoem_platform(sc);
  622. ret = ath9k_init_soc_platform(sc);
  623. if (ret)
  624. return ret;
  625. /*
  626. * Enable WLAN/BT RX Antenna diversity only when:
  627. *
  628. * - BTCOEX is disabled.
  629. * - the user manually requests the feature.
  630. * - the HW cap is set using the platform data.
  631. */
  632. if (!common->btcoex_enabled && ath9k_bt_ant_diversity &&
  633. (pCap->hw_caps & ATH9K_HW_CAP_BT_ANT_DIV))
  634. common->bt_ant_diversity = 1;
  635. spin_lock_init(&common->cc_lock);
  636. spin_lock_init(&sc->sc_serial_rw);
  637. spin_lock_init(&sc->sc_pm_lock);
  638. mutex_init(&sc->mutex);
  639. tasklet_init(&sc->intr_tq, ath9k_tasklet, (unsigned long)sc);
  640. tasklet_init(&sc->bcon_tasklet, ath9k_beacon_tasklet,
  641. (unsigned long)sc);
  642. setup_timer(&sc->sleep_timer, ath_ps_full_sleep, (unsigned long)sc);
  643. INIT_WORK(&sc->hw_reset_work, ath_reset_work);
  644. INIT_WORK(&sc->hw_check_work, ath_hw_check);
  645. INIT_WORK(&sc->paprd_work, ath_paprd_calibrate);
  646. INIT_DELAYED_WORK(&sc->hw_pll_work, ath_hw_pll_work);
  647. setup_timer(&sc->rx_poll_timer, ath_rx_poll, (unsigned long)sc);
  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. 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_SUPPORTS_PS |
  765. IEEE80211_HW_PS_NULLFUNC_STACK |
  766. IEEE80211_HW_SPECTRUM_MGMT |
  767. IEEE80211_HW_REPORTS_TX_ACK_STATUS |
  768. IEEE80211_HW_SUPPORTS_RC_TABLE |
  769. IEEE80211_HW_SUPPORTS_HT_CCK_RATES;
  770. if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_HT) {
  771. hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION;
  772. if (AR_SREV_9280_20_OR_LATER(ah))
  773. hw->radiotap_mcs_details |=
  774. IEEE80211_RADIOTAP_MCS_HAVE_STBC;
  775. }
  776. if (AR_SREV_9160_10_OR_LATER(sc->sc_ah) || ath9k_modparam_nohwcrypt)
  777. hw->flags |= IEEE80211_HW_MFP_CAPABLE;
  778. hw->wiphy->features |= NL80211_FEATURE_ACTIVE_MONITOR;
  779. if (!config_enabled(CONFIG_ATH9K_TX99)) {
  780. hw->wiphy->interface_modes =
  781. BIT(NL80211_IFTYPE_P2P_GO) |
  782. BIT(NL80211_IFTYPE_P2P_CLIENT) |
  783. BIT(NL80211_IFTYPE_AP) |
  784. BIT(NL80211_IFTYPE_WDS) |
  785. BIT(NL80211_IFTYPE_STATION) |
  786. BIT(NL80211_IFTYPE_ADHOC) |
  787. BIT(NL80211_IFTYPE_MESH_POINT);
  788. hw->wiphy->iface_combinations = if_comb;
  789. hw->wiphy->n_iface_combinations = ARRAY_SIZE(if_comb);
  790. }
  791. hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
  792. hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
  793. hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS;
  794. hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
  795. hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_5_10_MHZ;
  796. hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
  797. hw->queues = 4;
  798. hw->max_rates = 4;
  799. hw->channel_change_time = 5000;
  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);