init.c 29 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079
  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. struct ath_buf *bf;
  302. int i, bsize, desc_len;
  303. ath_dbg(common, CONFIG, "%s DMA: %u buffers %u desc/buf\n",
  304. name, nbuf, ndesc);
  305. INIT_LIST_HEAD(head);
  306. if (is_tx)
  307. desc_len = sc->sc_ah->caps.tx_desc_len;
  308. else
  309. desc_len = sizeof(struct ath_desc);
  310. /* ath_desc must be a multiple of DWORDs */
  311. if ((desc_len % 4) != 0) {
  312. ath_err(common, "ath_desc not DWORD aligned\n");
  313. BUG_ON((desc_len % 4) != 0);
  314. return -ENOMEM;
  315. }
  316. dd->dd_desc_len = desc_len * nbuf * ndesc;
  317. /*
  318. * Need additional DMA memory because we can't use
  319. * descriptors that cross the 4K page boundary. Assume
  320. * one skipped descriptor per 4K page.
  321. */
  322. if (!(sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_4KB_SPLITTRANS)) {
  323. u32 ndesc_skipped =
  324. ATH_DESC_4KB_BOUND_NUM_SKIPPED(dd->dd_desc_len);
  325. u32 dma_len;
  326. while (ndesc_skipped) {
  327. dma_len = ndesc_skipped * desc_len;
  328. dd->dd_desc_len += dma_len;
  329. ndesc_skipped = ATH_DESC_4KB_BOUND_NUM_SKIPPED(dma_len);
  330. }
  331. }
  332. /* allocate descriptors */
  333. dd->dd_desc = dmam_alloc_coherent(sc->dev, dd->dd_desc_len,
  334. &dd->dd_desc_paddr, GFP_KERNEL);
  335. if (!dd->dd_desc)
  336. return -ENOMEM;
  337. ds = (u8 *) dd->dd_desc;
  338. ath_dbg(common, CONFIG, "%s DMA map: %p (%u) -> %llx (%u)\n",
  339. name, ds, (u32) dd->dd_desc_len,
  340. ito64(dd->dd_desc_paddr), /*XXX*/(u32) dd->dd_desc_len);
  341. /* allocate buffers */
  342. bsize = sizeof(struct ath_buf) * nbuf;
  343. bf = devm_kzalloc(sc->dev, bsize, GFP_KERNEL);
  344. if (!bf)
  345. return -ENOMEM;
  346. for (i = 0; i < nbuf; i++, bf++, ds += (desc_len * ndesc)) {
  347. bf->bf_desc = ds;
  348. bf->bf_daddr = DS2PHYS(dd, ds);
  349. if (!(sc->sc_ah->caps.hw_caps &
  350. ATH9K_HW_CAP_4KB_SPLITTRANS)) {
  351. /*
  352. * Skip descriptor addresses which can cause 4KB
  353. * boundary crossing (addr + length) with a 32 dword
  354. * descriptor fetch.
  355. */
  356. while (ATH_DESC_4KB_BOUND_CHECK(bf->bf_daddr)) {
  357. BUG_ON((caddr_t) bf->bf_desc >=
  358. ((caddr_t) dd->dd_desc +
  359. dd->dd_desc_len));
  360. ds += (desc_len * ndesc);
  361. bf->bf_desc = ds;
  362. bf->bf_daddr = DS2PHYS(dd, ds);
  363. }
  364. }
  365. list_add_tail(&bf->list, head);
  366. }
  367. return 0;
  368. }
  369. static int ath9k_init_queues(struct ath_softc *sc)
  370. {
  371. int i = 0;
  372. sc->beacon.beaconq = ath9k_hw_beaconq_setup(sc->sc_ah);
  373. sc->beacon.cabq = ath_txq_setup(sc, ATH9K_TX_QUEUE_CAB, 0);
  374. sc->config.cabqReadytime = ATH_CABQ_READY_TIME;
  375. ath_cabq_update(sc);
  376. sc->tx.uapsdq = ath_txq_setup(sc, ATH9K_TX_QUEUE_UAPSD, 0);
  377. for (i = 0; i < IEEE80211_NUM_ACS; i++) {
  378. sc->tx.txq_map[i] = ath_txq_setup(sc, ATH9K_TX_QUEUE_DATA, i);
  379. sc->tx.txq_map[i]->mac80211_qnum = i;
  380. sc->tx.txq_max_pending[i] = ATH_MAX_QDEPTH;
  381. }
  382. return 0;
  383. }
  384. static int ath9k_init_channels_rates(struct ath_softc *sc)
  385. {
  386. void *channels;
  387. BUILD_BUG_ON(ARRAY_SIZE(ath9k_2ghz_chantable) +
  388. ARRAY_SIZE(ath9k_5ghz_chantable) !=
  389. ATH9K_NUM_CHANNELS);
  390. if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_2GHZ) {
  391. channels = devm_kzalloc(sc->dev,
  392. sizeof(ath9k_2ghz_chantable), GFP_KERNEL);
  393. if (!channels)
  394. return -ENOMEM;
  395. memcpy(channels, ath9k_2ghz_chantable,
  396. sizeof(ath9k_2ghz_chantable));
  397. sc->sbands[IEEE80211_BAND_2GHZ].channels = channels;
  398. sc->sbands[IEEE80211_BAND_2GHZ].band = IEEE80211_BAND_2GHZ;
  399. sc->sbands[IEEE80211_BAND_2GHZ].n_channels =
  400. ARRAY_SIZE(ath9k_2ghz_chantable);
  401. sc->sbands[IEEE80211_BAND_2GHZ].bitrates = ath9k_legacy_rates;
  402. sc->sbands[IEEE80211_BAND_2GHZ].n_bitrates =
  403. ARRAY_SIZE(ath9k_legacy_rates);
  404. }
  405. if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_5GHZ) {
  406. channels = devm_kzalloc(sc->dev,
  407. sizeof(ath9k_5ghz_chantable), GFP_KERNEL);
  408. if (!channels)
  409. return -ENOMEM;
  410. memcpy(channels, ath9k_5ghz_chantable,
  411. sizeof(ath9k_5ghz_chantable));
  412. sc->sbands[IEEE80211_BAND_5GHZ].channels = channels;
  413. sc->sbands[IEEE80211_BAND_5GHZ].band = IEEE80211_BAND_5GHZ;
  414. sc->sbands[IEEE80211_BAND_5GHZ].n_channels =
  415. ARRAY_SIZE(ath9k_5ghz_chantable);
  416. sc->sbands[IEEE80211_BAND_5GHZ].bitrates =
  417. ath9k_legacy_rates + 4;
  418. sc->sbands[IEEE80211_BAND_5GHZ].n_bitrates =
  419. ARRAY_SIZE(ath9k_legacy_rates) - 4;
  420. }
  421. return 0;
  422. }
  423. static void ath9k_init_misc(struct ath_softc *sc)
  424. {
  425. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  426. int i = 0;
  427. setup_timer(&common->ani.timer, ath_ani_calibrate, (unsigned long)sc);
  428. sc->last_rssi = ATH_RSSI_DUMMY_MARKER;
  429. sc->config.txpowlimit = ATH_TXPOWER_MAX;
  430. memcpy(common->bssidmask, ath_bcast_mac, ETH_ALEN);
  431. sc->beacon.slottime = ATH9K_SLOT_TIME_9;
  432. for (i = 0; i < ARRAY_SIZE(sc->beacon.bslot); i++)
  433. sc->beacon.bslot[i] = NULL;
  434. if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_ANT_DIV_COMB)
  435. sc->ant_comb.count = ATH_ANT_DIV_COMB_INIT_COUNT;
  436. sc->spec_config.enabled = 0;
  437. sc->spec_config.short_repeat = true;
  438. sc->spec_config.count = 8;
  439. sc->spec_config.endless = false;
  440. sc->spec_config.period = 0xFF;
  441. sc->spec_config.fft_period = 0xF;
  442. }
  443. static void ath9k_init_platform(struct ath_softc *sc)
  444. {
  445. struct ath_hw *ah = sc->sc_ah;
  446. struct ath9k_hw_capabilities *pCap = &ah->caps;
  447. struct ath_common *common = ath9k_hw_common(ah);
  448. if (common->bus_ops->ath_bus_type != ATH_PCI)
  449. return;
  450. if (sc->driver_data & (ATH9K_PCI_CUS198 |
  451. ATH9K_PCI_CUS230)) {
  452. ah->config.xlna_gpio = 9;
  453. ah->config.xatten_margin_cfg = true;
  454. ah->config.alt_mingainidx = true;
  455. ah->config.ant_ctrl_comm2g_switch_enable = 0x000BBB88;
  456. sc->ant_comb.low_rssi_thresh = 20;
  457. sc->ant_comb.fast_div_bias = 3;
  458. ath_info(common, "Set parameters for %s\n",
  459. (sc->driver_data & ATH9K_PCI_CUS198) ?
  460. "CUS198" : "CUS230");
  461. }
  462. if (sc->driver_data & ATH9K_PCI_CUS217)
  463. ath_info(common, "CUS217 card detected\n");
  464. if (sc->driver_data & ATH9K_PCI_BT_ANT_DIV) {
  465. pCap->hw_caps |= ATH9K_HW_CAP_BT_ANT_DIV;
  466. ath_info(common, "Set BT/WLAN RX diversity capability\n");
  467. }
  468. if (sc->driver_data & ATH9K_PCI_D3_L1_WAR) {
  469. ah->config.pcie_waen = 0x0040473b;
  470. ath_info(common, "Enable WAR for ASPM D3/L1\n");
  471. }
  472. }
  473. static void ath9k_eeprom_request_cb(const struct firmware *eeprom_blob,
  474. void *ctx)
  475. {
  476. struct ath9k_eeprom_ctx *ec = ctx;
  477. if (eeprom_blob)
  478. ec->ah->eeprom_blob = eeprom_blob;
  479. complete(&ec->complete);
  480. }
  481. static int ath9k_eeprom_request(struct ath_softc *sc, const char *name)
  482. {
  483. struct ath9k_eeprom_ctx ec;
  484. struct ath_hw *ah = ah = sc->sc_ah;
  485. int err;
  486. /* try to load the EEPROM content asynchronously */
  487. init_completion(&ec.complete);
  488. ec.ah = sc->sc_ah;
  489. err = request_firmware_nowait(THIS_MODULE, 1, name, sc->dev, GFP_KERNEL,
  490. &ec, ath9k_eeprom_request_cb);
  491. if (err < 0) {
  492. ath_err(ath9k_hw_common(ah),
  493. "EEPROM request failed\n");
  494. return err;
  495. }
  496. wait_for_completion(&ec.complete);
  497. if (!ah->eeprom_blob) {
  498. ath_err(ath9k_hw_common(ah),
  499. "Unable to load EEPROM file %s\n", name);
  500. return -EINVAL;
  501. }
  502. return 0;
  503. }
  504. static void ath9k_eeprom_release(struct ath_softc *sc)
  505. {
  506. release_firmware(sc->sc_ah->eeprom_blob);
  507. }
  508. static int ath9k_init_softc(u16 devid, struct ath_softc *sc,
  509. const struct ath_bus_ops *bus_ops)
  510. {
  511. struct ath9k_platform_data *pdata = sc->dev->platform_data;
  512. struct ath_hw *ah = NULL;
  513. struct ath9k_hw_capabilities *pCap;
  514. struct ath_common *common;
  515. int ret = 0, i;
  516. int csz = 0;
  517. ah = devm_kzalloc(sc->dev, sizeof(struct ath_hw), GFP_KERNEL);
  518. if (!ah)
  519. return -ENOMEM;
  520. ah->dev = sc->dev;
  521. ah->hw = sc->hw;
  522. ah->hw_version.devid = devid;
  523. ah->reg_ops.read = ath9k_ioread32;
  524. ah->reg_ops.write = ath9k_iowrite32;
  525. ah->reg_ops.rmw = ath9k_reg_rmw;
  526. atomic_set(&ah->intr_ref_cnt, -1);
  527. sc->sc_ah = ah;
  528. pCap = &ah->caps;
  529. sc->dfs_detector = dfs_pattern_detector_init(ah, NL80211_DFS_UNSET);
  530. if (!pdata) {
  531. ah->ah_flags |= AH_USE_EEPROM;
  532. sc->sc_ah->led_pin = -1;
  533. } else {
  534. sc->sc_ah->gpio_mask = pdata->gpio_mask;
  535. sc->sc_ah->gpio_val = pdata->gpio_val;
  536. sc->sc_ah->led_pin = pdata->led_pin;
  537. ah->is_clk_25mhz = pdata->is_clk_25mhz;
  538. ah->get_mac_revision = pdata->get_mac_revision;
  539. ah->external_reset = pdata->external_reset;
  540. }
  541. common = ath9k_hw_common(ah);
  542. common->ops = &ah->reg_ops;
  543. common->bus_ops = bus_ops;
  544. common->ah = ah;
  545. common->hw = sc->hw;
  546. common->priv = sc;
  547. common->debug_mask = ath9k_debug;
  548. common->btcoex_enabled = ath9k_btcoex_enable == 1;
  549. common->disable_ani = false;
  550. /*
  551. * Platform quirks.
  552. */
  553. ath9k_init_platform(sc);
  554. /*
  555. * Enable WLAN/BT RX Antenna diversity only when:
  556. *
  557. * - BTCOEX is disabled.
  558. * - the user manually requests the feature.
  559. * - the HW cap is set using the platform data.
  560. */
  561. if (!common->btcoex_enabled && ath9k_bt_ant_diversity &&
  562. (pCap->hw_caps & ATH9K_HW_CAP_BT_ANT_DIV))
  563. common->bt_ant_diversity = 1;
  564. spin_lock_init(&common->cc_lock);
  565. spin_lock_init(&sc->sc_serial_rw);
  566. spin_lock_init(&sc->sc_pm_lock);
  567. mutex_init(&sc->mutex);
  568. tasklet_init(&sc->intr_tq, ath9k_tasklet, (unsigned long)sc);
  569. tasklet_init(&sc->bcon_tasklet, ath9k_beacon_tasklet,
  570. (unsigned long)sc);
  571. INIT_WORK(&sc->hw_reset_work, ath_reset_work);
  572. INIT_WORK(&sc->hw_check_work, ath_hw_check);
  573. INIT_WORK(&sc->paprd_work, ath_paprd_calibrate);
  574. INIT_DELAYED_WORK(&sc->hw_pll_work, ath_hw_pll_work);
  575. setup_timer(&sc->rx_poll_timer, ath_rx_poll, (unsigned long)sc);
  576. /*
  577. * Cache line size is used to size and align various
  578. * structures used to communicate with the hardware.
  579. */
  580. ath_read_cachesize(common, &csz);
  581. common->cachelsz = csz << 2; /* convert to bytes */
  582. if (pdata && pdata->eeprom_name) {
  583. ret = ath9k_eeprom_request(sc, pdata->eeprom_name);
  584. if (ret)
  585. return ret;
  586. }
  587. /* Initializes the hardware for all supported chipsets */
  588. ret = ath9k_hw_init(ah);
  589. if (ret)
  590. goto err_hw;
  591. if (pdata && pdata->macaddr)
  592. memcpy(common->macaddr, pdata->macaddr, ETH_ALEN);
  593. ret = ath9k_init_queues(sc);
  594. if (ret)
  595. goto err_queues;
  596. ret = ath9k_init_btcoex(sc);
  597. if (ret)
  598. goto err_btcoex;
  599. ret = ath9k_init_channels_rates(sc);
  600. if (ret)
  601. goto err_btcoex;
  602. ath9k_cmn_init_crypto(sc->sc_ah);
  603. ath9k_init_misc(sc);
  604. ath_fill_led_pin(sc);
  605. if (common->bus_ops->aspm_init)
  606. common->bus_ops->aspm_init(common);
  607. return 0;
  608. err_btcoex:
  609. for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++)
  610. if (ATH_TXQ_SETUP(sc, i))
  611. ath_tx_cleanupq(sc, &sc->tx.txq[i]);
  612. err_queues:
  613. ath9k_hw_deinit(ah);
  614. err_hw:
  615. ath9k_eeprom_release(sc);
  616. return ret;
  617. }
  618. static void ath9k_init_band_txpower(struct ath_softc *sc, int band)
  619. {
  620. struct ieee80211_supported_band *sband;
  621. struct ieee80211_channel *chan;
  622. struct ath_hw *ah = sc->sc_ah;
  623. struct cfg80211_chan_def chandef;
  624. int i;
  625. sband = &sc->sbands[band];
  626. for (i = 0; i < sband->n_channels; i++) {
  627. chan = &sband->channels[i];
  628. ah->curchan = &ah->channels[chan->hw_value];
  629. cfg80211_chandef_create(&chandef, chan, NL80211_CHAN_HT20);
  630. ath9k_cmn_update_ichannel(ah->curchan, &chandef);
  631. ath9k_hw_set_txpowerlimit(ah, MAX_RATE_POWER, true);
  632. }
  633. }
  634. static void ath9k_init_txpower_limits(struct ath_softc *sc)
  635. {
  636. struct ath_hw *ah = sc->sc_ah;
  637. struct ath9k_channel *curchan = ah->curchan;
  638. if (ah->caps.hw_caps & ATH9K_HW_CAP_2GHZ)
  639. ath9k_init_band_txpower(sc, IEEE80211_BAND_2GHZ);
  640. if (ah->caps.hw_caps & ATH9K_HW_CAP_5GHZ)
  641. ath9k_init_band_txpower(sc, IEEE80211_BAND_5GHZ);
  642. ah->curchan = curchan;
  643. }
  644. void ath9k_reload_chainmask_settings(struct ath_softc *sc)
  645. {
  646. if (!(sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_HT))
  647. return;
  648. if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_2GHZ)
  649. setup_ht_cap(sc, &sc->sbands[IEEE80211_BAND_2GHZ].ht_cap);
  650. if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_5GHZ)
  651. setup_ht_cap(sc, &sc->sbands[IEEE80211_BAND_5GHZ].ht_cap);
  652. }
  653. static const struct ieee80211_iface_limit if_limits[] = {
  654. { .max = 2048, .types = BIT(NL80211_IFTYPE_STATION) |
  655. BIT(NL80211_IFTYPE_P2P_CLIENT) |
  656. BIT(NL80211_IFTYPE_WDS) },
  657. { .max = 8, .types =
  658. #ifdef CONFIG_MAC80211_MESH
  659. BIT(NL80211_IFTYPE_MESH_POINT) |
  660. #endif
  661. BIT(NL80211_IFTYPE_AP) |
  662. BIT(NL80211_IFTYPE_P2P_GO) },
  663. };
  664. static const struct ieee80211_iface_limit if_dfs_limits[] = {
  665. { .max = 1, .types = BIT(NL80211_IFTYPE_AP) },
  666. };
  667. static const struct ieee80211_iface_combination if_comb[] = {
  668. {
  669. .limits = if_limits,
  670. .n_limits = ARRAY_SIZE(if_limits),
  671. .max_interfaces = 2048,
  672. .num_different_channels = 1,
  673. .beacon_int_infra_match = true,
  674. },
  675. {
  676. .limits = if_dfs_limits,
  677. .n_limits = ARRAY_SIZE(if_dfs_limits),
  678. .max_interfaces = 1,
  679. .num_different_channels = 1,
  680. .beacon_int_infra_match = true,
  681. .radar_detect_widths = BIT(NL80211_CHAN_NO_HT) |
  682. BIT(NL80211_CHAN_HT20),
  683. }
  684. };
  685. #ifdef CONFIG_PM
  686. static const struct wiphy_wowlan_support ath9k_wowlan_support = {
  687. .flags = WIPHY_WOWLAN_MAGIC_PKT | WIPHY_WOWLAN_DISCONNECT,
  688. .n_patterns = MAX_NUM_USER_PATTERN,
  689. .pattern_min_len = 1,
  690. .pattern_max_len = MAX_PATTERN_SIZE,
  691. };
  692. #endif
  693. void ath9k_set_hw_capab(struct ath_softc *sc, struct ieee80211_hw *hw)
  694. {
  695. struct ath_hw *ah = sc->sc_ah;
  696. struct ath_common *common = ath9k_hw_common(ah);
  697. hw->flags = IEEE80211_HW_RX_INCLUDES_FCS |
  698. IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING |
  699. IEEE80211_HW_SIGNAL_DBM |
  700. IEEE80211_HW_SUPPORTS_PS |
  701. IEEE80211_HW_PS_NULLFUNC_STACK |
  702. IEEE80211_HW_SPECTRUM_MGMT |
  703. IEEE80211_HW_REPORTS_TX_ACK_STATUS |
  704. IEEE80211_HW_SUPPORTS_RC_TABLE |
  705. IEEE80211_HW_SUPPORTS_HT_CCK_RATES;
  706. if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_HT) {
  707. hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION;
  708. if (AR_SREV_9280_20_OR_LATER(ah))
  709. hw->radiotap_mcs_details |=
  710. IEEE80211_RADIOTAP_MCS_HAVE_STBC;
  711. }
  712. if (AR_SREV_9160_10_OR_LATER(sc->sc_ah) || ath9k_modparam_nohwcrypt)
  713. hw->flags |= IEEE80211_HW_MFP_CAPABLE;
  714. hw->wiphy->features |= NL80211_FEATURE_ACTIVE_MONITOR;
  715. hw->wiphy->interface_modes =
  716. BIT(NL80211_IFTYPE_P2P_GO) |
  717. BIT(NL80211_IFTYPE_P2P_CLIENT) |
  718. BIT(NL80211_IFTYPE_AP) |
  719. BIT(NL80211_IFTYPE_WDS) |
  720. BIT(NL80211_IFTYPE_STATION) |
  721. BIT(NL80211_IFTYPE_ADHOC) |
  722. BIT(NL80211_IFTYPE_MESH_POINT);
  723. hw->wiphy->iface_combinations = if_comb;
  724. hw->wiphy->n_iface_combinations = ARRAY_SIZE(if_comb);
  725. hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
  726. hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
  727. hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS;
  728. hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
  729. hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_5_10_MHZ;
  730. hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
  731. #ifdef CONFIG_PM_SLEEP
  732. if ((ah->caps.hw_caps & ATH9K_HW_WOW_DEVICE_CAPABLE) &&
  733. (sc->driver_data & ATH9K_PCI_WOW) &&
  734. device_can_wakeup(sc->dev))
  735. hw->wiphy->wowlan = &ath9k_wowlan_support;
  736. atomic_set(&sc->wow_sleep_proc_intr, -1);
  737. atomic_set(&sc->wow_got_bmiss_intr, -1);
  738. #endif
  739. hw->queues = 4;
  740. hw->max_rates = 4;
  741. hw->channel_change_time = 5000;
  742. hw->max_listen_interval = 1;
  743. hw->max_rate_tries = 10;
  744. hw->sta_data_size = sizeof(struct ath_node);
  745. hw->vif_data_size = sizeof(struct ath_vif);
  746. hw->wiphy->available_antennas_rx = BIT(ah->caps.max_rxchains) - 1;
  747. hw->wiphy->available_antennas_tx = BIT(ah->caps.max_txchains) - 1;
  748. /* single chain devices with rx diversity */
  749. if (ah->caps.hw_caps & ATH9K_HW_CAP_ANT_DIV_COMB)
  750. hw->wiphy->available_antennas_rx = BIT(0) | BIT(1);
  751. sc->ant_rx = hw->wiphy->available_antennas_rx;
  752. sc->ant_tx = hw->wiphy->available_antennas_tx;
  753. if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_2GHZ)
  754. hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
  755. &sc->sbands[IEEE80211_BAND_2GHZ];
  756. if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_5GHZ)
  757. hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
  758. &sc->sbands[IEEE80211_BAND_5GHZ];
  759. ath9k_reload_chainmask_settings(sc);
  760. SET_IEEE80211_PERM_ADDR(hw, common->macaddr);
  761. }
  762. int ath9k_init_device(u16 devid, struct ath_softc *sc,
  763. const struct ath_bus_ops *bus_ops)
  764. {
  765. struct ieee80211_hw *hw = sc->hw;
  766. struct ath_common *common;
  767. struct ath_hw *ah;
  768. int error = 0;
  769. struct ath_regulatory *reg;
  770. /* Bring up device */
  771. error = ath9k_init_softc(devid, sc, bus_ops);
  772. if (error)
  773. return error;
  774. ah = sc->sc_ah;
  775. common = ath9k_hw_common(ah);
  776. ath9k_set_hw_capab(sc, hw);
  777. /* Initialize regulatory */
  778. error = ath_regd_init(&common->regulatory, sc->hw->wiphy,
  779. ath9k_reg_notifier);
  780. if (error)
  781. goto deinit;
  782. reg = &common->regulatory;
  783. /* Setup TX DMA */
  784. error = ath_tx_init(sc, ATH_TXBUF);
  785. if (error != 0)
  786. goto deinit;
  787. /* Setup RX DMA */
  788. error = ath_rx_init(sc, ATH_RXBUF);
  789. if (error != 0)
  790. goto deinit;
  791. ath9k_init_txpower_limits(sc);
  792. #ifdef CONFIG_MAC80211_LEDS
  793. /* must be initialized before ieee80211_register_hw */
  794. sc->led_cdev.default_trigger = ieee80211_create_tpt_led_trigger(sc->hw,
  795. IEEE80211_TPT_LEDTRIG_FL_RADIO, ath9k_tpt_blink,
  796. ARRAY_SIZE(ath9k_tpt_blink));
  797. #endif
  798. /* Register with mac80211 */
  799. error = ieee80211_register_hw(hw);
  800. if (error)
  801. goto rx_cleanup;
  802. error = ath9k_init_debug(ah);
  803. if (error) {
  804. ath_err(common, "Unable to create debugfs files\n");
  805. goto unregister;
  806. }
  807. /* Handle world regulatory */
  808. if (!ath_is_world_regd(reg)) {
  809. error = regulatory_hint(hw->wiphy, reg->alpha2);
  810. if (error)
  811. goto debug_cleanup;
  812. }
  813. ath_init_leds(sc);
  814. ath_start_rfkill_poll(sc);
  815. return 0;
  816. debug_cleanup:
  817. ath9k_deinit_debug(sc);
  818. unregister:
  819. ieee80211_unregister_hw(hw);
  820. rx_cleanup:
  821. ath_rx_cleanup(sc);
  822. deinit:
  823. ath9k_deinit_softc(sc);
  824. return error;
  825. }
  826. /*****************************/
  827. /* De-Initialization */
  828. /*****************************/
  829. static void ath9k_deinit_softc(struct ath_softc *sc)
  830. {
  831. int i = 0;
  832. ath9k_deinit_btcoex(sc);
  833. for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++)
  834. if (ATH_TXQ_SETUP(sc, i))
  835. ath_tx_cleanupq(sc, &sc->tx.txq[i]);
  836. ath9k_hw_deinit(sc->sc_ah);
  837. if (sc->dfs_detector != NULL)
  838. sc->dfs_detector->exit(sc->dfs_detector);
  839. ath9k_eeprom_release(sc);
  840. }
  841. void ath9k_deinit_device(struct ath_softc *sc)
  842. {
  843. struct ieee80211_hw *hw = sc->hw;
  844. ath9k_ps_wakeup(sc);
  845. wiphy_rfkill_stop_polling(sc->hw->wiphy);
  846. ath_deinit_leds(sc);
  847. ath9k_ps_restore(sc);
  848. ath9k_deinit_debug(sc);
  849. ieee80211_unregister_hw(hw);
  850. ath_rx_cleanup(sc);
  851. ath9k_deinit_softc(sc);
  852. }
  853. /************************/
  854. /* Module Hooks */
  855. /************************/
  856. static int __init ath9k_init(void)
  857. {
  858. int error;
  859. /* Register rate control algorithm */
  860. error = ath_rate_control_register();
  861. if (error != 0) {
  862. pr_err("Unable to register rate control algorithm: %d\n",
  863. error);
  864. goto err_out;
  865. }
  866. error = ath_pci_init();
  867. if (error < 0) {
  868. pr_err("No PCI devices found, driver not installed\n");
  869. error = -ENODEV;
  870. goto err_rate_unregister;
  871. }
  872. error = ath_ahb_init();
  873. if (error < 0) {
  874. error = -ENODEV;
  875. goto err_pci_exit;
  876. }
  877. return 0;
  878. err_pci_exit:
  879. ath_pci_exit();
  880. err_rate_unregister:
  881. ath_rate_control_unregister();
  882. err_out:
  883. return error;
  884. }
  885. module_init(ath9k_init);
  886. static void __exit ath9k_exit(void)
  887. {
  888. is_ath9k_unloaded = true;
  889. ath_ahb_exit();
  890. ath_pci_exit();
  891. ath_rate_control_unregister();
  892. pr_info("%s: Driver unloaded\n", dev_info);
  893. }
  894. module_exit(ath9k_exit);