init.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929
  1. /*
  2. * Copyright (c) 2008-2011 Atheros Communications Inc.
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for any
  5. * purpose with or without fee is hereby granted, provided that the above
  6. * copyright notice and this permission notice appear in all copies.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  11. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  13. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  14. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  17. #include <linux/dma-mapping.h>
  18. #include <linux/slab.h>
  19. #include <linux/ath9k_platform.h>
  20. #include <linux/module.h>
  21. #include <linux/relay.h>
  22. #include <net/ieee80211_radiotap.h>
  23. #include "ath9k.h"
  24. struct ath9k_eeprom_ctx {
  25. struct completion complete;
  26. struct ath_hw *ah;
  27. };
  28. static char *dev_info = "ath9k";
  29. MODULE_AUTHOR("Atheros Communications");
  30. MODULE_DESCRIPTION("Support for Atheros 802.11n wireless LAN cards.");
  31. MODULE_SUPPORTED_DEVICE("Atheros 802.11n WLAN cards");
  32. MODULE_LICENSE("Dual BSD/GPL");
  33. static unsigned int ath9k_debug = ATH_DBG_DEFAULT;
  34. module_param_named(debug, ath9k_debug, uint, 0);
  35. MODULE_PARM_DESC(debug, "Debugging mask");
  36. int ath9k_modparam_nohwcrypt;
  37. module_param_named(nohwcrypt, ath9k_modparam_nohwcrypt, int, 0444);
  38. MODULE_PARM_DESC(nohwcrypt, "Disable hardware encryption");
  39. int led_blink;
  40. module_param_named(blink, led_blink, int, 0444);
  41. MODULE_PARM_DESC(blink, "Enable LED blink on activity");
  42. static int ath9k_btcoex_enable;
  43. module_param_named(btcoex_enable, ath9k_btcoex_enable, int, 0444);
  44. MODULE_PARM_DESC(btcoex_enable, "Enable wifi-BT coexistence");
  45. static int ath9k_bt_ant_diversity;
  46. module_param_named(bt_ant_diversity, ath9k_bt_ant_diversity, int, 0444);
  47. MODULE_PARM_DESC(bt_ant_diversity, "Enable WLAN/BT RX antenna diversity");
  48. static int ath9k_ps_enable;
  49. module_param_named(ps_enable, ath9k_ps_enable, int, 0444);
  50. MODULE_PARM_DESC(ps_enable, "Enable WLAN PowerSave");
  51. bool is_ath9k_unloaded;
  52. #ifdef CONFIG_MAC80211_LEDS
  53. static const struct ieee80211_tpt_blink ath9k_tpt_blink[] = {
  54. { .throughput = 0 * 1024, .blink_time = 334 },
  55. { .throughput = 1 * 1024, .blink_time = 260 },
  56. { .throughput = 5 * 1024, .blink_time = 220 },
  57. { .throughput = 10 * 1024, .blink_time = 190 },
  58. { .throughput = 20 * 1024, .blink_time = 170 },
  59. { .throughput = 50 * 1024, .blink_time = 150 },
  60. { .throughput = 70 * 1024, .blink_time = 130 },
  61. { .throughput = 100 * 1024, .blink_time = 110 },
  62. { .throughput = 200 * 1024, .blink_time = 80 },
  63. { .throughput = 300 * 1024, .blink_time = 50 },
  64. };
  65. #endif
  66. static void ath9k_deinit_softc(struct ath_softc *sc);
  67. /*
  68. * Read and write, they both share the same lock. We do this to serialize
  69. * reads and writes on Atheros 802.11n PCI devices only. This is required
  70. * as the FIFO on these devices can only accept sanely 2 requests.
  71. */
  72. static void ath9k_iowrite32(void *hw_priv, u32 val, u32 reg_offset)
  73. {
  74. struct ath_hw *ah = (struct ath_hw *) hw_priv;
  75. struct ath_common *common = ath9k_hw_common(ah);
  76. struct ath_softc *sc = (struct ath_softc *) common->priv;
  77. if (NR_CPUS > 1 && ah->config.serialize_regmode == SER_REG_MODE_ON) {
  78. unsigned long flags;
  79. spin_lock_irqsave(&sc->sc_serial_rw, flags);
  80. iowrite32(val, sc->mem + reg_offset);
  81. spin_unlock_irqrestore(&sc->sc_serial_rw, flags);
  82. } else
  83. iowrite32(val, sc->mem + reg_offset);
  84. }
  85. static unsigned int ath9k_ioread32(void *hw_priv, u32 reg_offset)
  86. {
  87. struct ath_hw *ah = (struct ath_hw *) hw_priv;
  88. struct ath_common *common = ath9k_hw_common(ah);
  89. struct ath_softc *sc = (struct ath_softc *) common->priv;
  90. u32 val;
  91. if (NR_CPUS > 1 && ah->config.serialize_regmode == SER_REG_MODE_ON) {
  92. unsigned long flags;
  93. spin_lock_irqsave(&sc->sc_serial_rw, flags);
  94. val = ioread32(sc->mem + reg_offset);
  95. spin_unlock_irqrestore(&sc->sc_serial_rw, flags);
  96. } else
  97. val = ioread32(sc->mem + reg_offset);
  98. return val;
  99. }
  100. static unsigned int __ath9k_reg_rmw(struct ath_softc *sc, u32 reg_offset,
  101. u32 set, u32 clr)
  102. {
  103. u32 val;
  104. val = ioread32(sc->mem + reg_offset);
  105. val &= ~clr;
  106. val |= set;
  107. iowrite32(val, sc->mem + reg_offset);
  108. return val;
  109. }
  110. static unsigned int ath9k_reg_rmw(void *hw_priv, u32 reg_offset, u32 set, u32 clr)
  111. {
  112. struct ath_hw *ah = (struct ath_hw *) hw_priv;
  113. struct ath_common *common = ath9k_hw_common(ah);
  114. struct ath_softc *sc = (struct ath_softc *) common->priv;
  115. unsigned long uninitialized_var(flags);
  116. u32 val;
  117. if (NR_CPUS > 1 && ah->config.serialize_regmode == SER_REG_MODE_ON) {
  118. spin_lock_irqsave(&sc->sc_serial_rw, flags);
  119. val = __ath9k_reg_rmw(sc, reg_offset, set, clr);
  120. spin_unlock_irqrestore(&sc->sc_serial_rw, flags);
  121. } else
  122. val = __ath9k_reg_rmw(sc, reg_offset, set, clr);
  123. return val;
  124. }
  125. /**************************/
  126. /* Initialization */
  127. /**************************/
  128. static void ath9k_reg_notifier(struct wiphy *wiphy,
  129. struct regulatory_request *request)
  130. {
  131. struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
  132. struct ath_softc *sc = hw->priv;
  133. struct ath_hw *ah = sc->sc_ah;
  134. struct ath_regulatory *reg = ath9k_hw_regulatory(ah);
  135. ath_reg_notifier_apply(wiphy, request, reg);
  136. /* Set tx power */
  137. if (ah->curchan) {
  138. sc->config.txpowlimit = 2 * ah->curchan->chan->max_power;
  139. ath9k_ps_wakeup(sc);
  140. ath9k_hw_set_txpowerlimit(ah, sc->config.txpowlimit, false);
  141. sc->curtxpow = ath9k_hw_regulatory(ah)->power_limit;
  142. /* synchronize DFS detector if regulatory domain changed */
  143. if (sc->dfs_detector != NULL)
  144. sc->dfs_detector->set_dfs_domain(sc->dfs_detector,
  145. request->dfs_region);
  146. ath9k_ps_restore(sc);
  147. }
  148. }
  149. /*
  150. * This function will allocate both the DMA descriptor structure, and the
  151. * buffers it contains. These are used to contain the descriptors used
  152. * by the system.
  153. */
  154. int ath_descdma_setup(struct ath_softc *sc, struct ath_descdma *dd,
  155. struct list_head *head, const char *name,
  156. int nbuf, int ndesc, bool is_tx)
  157. {
  158. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  159. u8 *ds;
  160. int i, bsize, desc_len;
  161. ath_dbg(common, CONFIG, "%s DMA: %u buffers %u desc/buf\n",
  162. name, nbuf, ndesc);
  163. INIT_LIST_HEAD(head);
  164. if (is_tx)
  165. desc_len = sc->sc_ah->caps.tx_desc_len;
  166. else
  167. desc_len = sizeof(struct ath_desc);
  168. /* ath_desc must be a multiple of DWORDs */
  169. if ((desc_len % 4) != 0) {
  170. ath_err(common, "ath_desc not DWORD aligned\n");
  171. BUG_ON((desc_len % 4) != 0);
  172. return -ENOMEM;
  173. }
  174. dd->dd_desc_len = desc_len * nbuf * ndesc;
  175. /*
  176. * Need additional DMA memory because we can't use
  177. * descriptors that cross the 4K page boundary. Assume
  178. * one skipped descriptor per 4K page.
  179. */
  180. if (!(sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_4KB_SPLITTRANS)) {
  181. u32 ndesc_skipped =
  182. ATH_DESC_4KB_BOUND_NUM_SKIPPED(dd->dd_desc_len);
  183. u32 dma_len;
  184. while (ndesc_skipped) {
  185. dma_len = ndesc_skipped * desc_len;
  186. dd->dd_desc_len += dma_len;
  187. ndesc_skipped = ATH_DESC_4KB_BOUND_NUM_SKIPPED(dma_len);
  188. }
  189. }
  190. /* allocate descriptors */
  191. dd->dd_desc = dmam_alloc_coherent(sc->dev, dd->dd_desc_len,
  192. &dd->dd_desc_paddr, GFP_KERNEL);
  193. if (!dd->dd_desc)
  194. return -ENOMEM;
  195. ds = (u8 *) dd->dd_desc;
  196. ath_dbg(common, CONFIG, "%s DMA map: %p (%u) -> %llx (%u)\n",
  197. name, ds, (u32) dd->dd_desc_len,
  198. ito64(dd->dd_desc_paddr), /*XXX*/(u32) dd->dd_desc_len);
  199. /* allocate buffers */
  200. if (is_tx) {
  201. struct ath_buf *bf;
  202. bsize = sizeof(struct ath_buf) * nbuf;
  203. bf = devm_kzalloc(sc->dev, bsize, GFP_KERNEL);
  204. if (!bf)
  205. return -ENOMEM;
  206. for (i = 0; i < nbuf; i++, bf++, ds += (desc_len * ndesc)) {
  207. bf->bf_desc = ds;
  208. bf->bf_daddr = DS2PHYS(dd, ds);
  209. if (!(sc->sc_ah->caps.hw_caps &
  210. ATH9K_HW_CAP_4KB_SPLITTRANS)) {
  211. /*
  212. * Skip descriptor addresses which can cause 4KB
  213. * boundary crossing (addr + length) with a 32 dword
  214. * descriptor fetch.
  215. */
  216. while (ATH_DESC_4KB_BOUND_CHECK(bf->bf_daddr)) {
  217. BUG_ON((caddr_t) bf->bf_desc >=
  218. ((caddr_t) dd->dd_desc +
  219. dd->dd_desc_len));
  220. ds += (desc_len * ndesc);
  221. bf->bf_desc = ds;
  222. bf->bf_daddr = DS2PHYS(dd, ds);
  223. }
  224. }
  225. list_add_tail(&bf->list, head);
  226. }
  227. } else {
  228. struct ath_rxbuf *bf;
  229. bsize = sizeof(struct ath_rxbuf) * nbuf;
  230. bf = devm_kzalloc(sc->dev, bsize, GFP_KERNEL);
  231. if (!bf)
  232. return -ENOMEM;
  233. for (i = 0; i < nbuf; i++, bf++, ds += (desc_len * ndesc)) {
  234. bf->bf_desc = ds;
  235. bf->bf_daddr = DS2PHYS(dd, ds);
  236. if (!(sc->sc_ah->caps.hw_caps &
  237. ATH9K_HW_CAP_4KB_SPLITTRANS)) {
  238. /*
  239. * Skip descriptor addresses which can cause 4KB
  240. * boundary crossing (addr + length) with a 32 dword
  241. * descriptor fetch.
  242. */
  243. while (ATH_DESC_4KB_BOUND_CHECK(bf->bf_daddr)) {
  244. BUG_ON((caddr_t) bf->bf_desc >=
  245. ((caddr_t) dd->dd_desc +
  246. dd->dd_desc_len));
  247. ds += (desc_len * ndesc);
  248. bf->bf_desc = ds;
  249. bf->bf_daddr = DS2PHYS(dd, ds);
  250. }
  251. }
  252. list_add_tail(&bf->list, head);
  253. }
  254. }
  255. return 0;
  256. }
  257. static int ath9k_init_queues(struct ath_softc *sc)
  258. {
  259. int i = 0;
  260. sc->beacon.beaconq = ath9k_hw_beaconq_setup(sc->sc_ah);
  261. sc->beacon.cabq = ath_txq_setup(sc, ATH9K_TX_QUEUE_CAB, 0);
  262. ath_cabq_update(sc);
  263. sc->tx.uapsdq = ath_txq_setup(sc, ATH9K_TX_QUEUE_UAPSD, 0);
  264. for (i = 0; i < IEEE80211_NUM_ACS; i++) {
  265. sc->tx.txq_map[i] = ath_txq_setup(sc, ATH9K_TX_QUEUE_DATA, i);
  266. sc->tx.txq_map[i]->mac80211_qnum = i;
  267. sc->tx.txq_max_pending[i] = ATH_MAX_QDEPTH;
  268. }
  269. return 0;
  270. }
  271. static void ath9k_init_misc(struct ath_softc *sc)
  272. {
  273. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  274. int i = 0;
  275. setup_timer(&common->ani.timer, ath_ani_calibrate, (unsigned long)sc);
  276. common->last_rssi = ATH_RSSI_DUMMY_MARKER;
  277. sc->config.txpowlimit = ATH_TXPOWER_MAX;
  278. memcpy(common->bssidmask, ath_bcast_mac, ETH_ALEN);
  279. sc->beacon.slottime = ATH9K_SLOT_TIME_9;
  280. for (i = 0; i < ARRAY_SIZE(sc->beacon.bslot); i++)
  281. sc->beacon.bslot[i] = NULL;
  282. if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_ANT_DIV_COMB)
  283. sc->ant_comb.count = ATH_ANT_DIV_COMB_INIT_COUNT;
  284. sc->spec_config.enabled = 0;
  285. sc->spec_config.short_repeat = true;
  286. sc->spec_config.count = 8;
  287. sc->spec_config.endless = false;
  288. sc->spec_config.period = 0xFF;
  289. sc->spec_config.fft_period = 0xF;
  290. }
  291. static void ath9k_init_pcoem_platform(struct ath_softc *sc)
  292. {
  293. struct ath_hw *ah = sc->sc_ah;
  294. struct ath9k_hw_capabilities *pCap = &ah->caps;
  295. struct ath_common *common = ath9k_hw_common(ah);
  296. if (common->bus_ops->ath_bus_type != ATH_PCI)
  297. return;
  298. if (sc->driver_data & (ATH9K_PCI_CUS198 |
  299. ATH9K_PCI_CUS230)) {
  300. ah->config.xlna_gpio = 9;
  301. ah->config.xatten_margin_cfg = true;
  302. ah->config.alt_mingainidx = true;
  303. ah->config.ant_ctrl_comm2g_switch_enable = 0x000BBB88;
  304. sc->ant_comb.low_rssi_thresh = 20;
  305. sc->ant_comb.fast_div_bias = 3;
  306. ath_info(common, "Set parameters for %s\n",
  307. (sc->driver_data & ATH9K_PCI_CUS198) ?
  308. "CUS198" : "CUS230");
  309. }
  310. if (sc->driver_data & ATH9K_PCI_CUS217)
  311. ath_info(common, "CUS217 card detected\n");
  312. if (sc->driver_data & ATH9K_PCI_CUS252)
  313. ath_info(common, "CUS252 card detected\n");
  314. if (sc->driver_data & ATH9K_PCI_AR9565_1ANT)
  315. ath_info(common, "WB335 1-ANT card detected\n");
  316. if (sc->driver_data & ATH9K_PCI_AR9565_2ANT)
  317. ath_info(common, "WB335 2-ANT card detected\n");
  318. if (sc->driver_data & ATH9K_PCI_KILLER)
  319. ath_info(common, "Killer Wireless card detected\n");
  320. /*
  321. * Some WB335 cards do not support antenna diversity. Since
  322. * we use a hardcoded value for AR9565 instead of using the
  323. * EEPROM/OTP data, remove the combining feature from
  324. * the HW capabilities bitmap.
  325. */
  326. if (sc->driver_data & (ATH9K_PCI_AR9565_1ANT | ATH9K_PCI_AR9565_2ANT)) {
  327. if (!(sc->driver_data & ATH9K_PCI_BT_ANT_DIV))
  328. pCap->hw_caps &= ~ATH9K_HW_CAP_ANT_DIV_COMB;
  329. }
  330. if (sc->driver_data & ATH9K_PCI_BT_ANT_DIV) {
  331. pCap->hw_caps |= ATH9K_HW_CAP_BT_ANT_DIV;
  332. ath_info(common, "Set BT/WLAN RX diversity capability\n");
  333. }
  334. if (sc->driver_data & ATH9K_PCI_D3_L1_WAR) {
  335. ah->config.pcie_waen = 0x0040473b;
  336. ath_info(common, "Enable WAR for ASPM D3/L1\n");
  337. }
  338. if (sc->driver_data & ATH9K_PCI_NO_PLL_PWRSAVE) {
  339. ah->config.no_pll_pwrsave = true;
  340. ath_info(common, "Disable PLL PowerSave\n");
  341. }
  342. }
  343. static void ath9k_eeprom_request_cb(const struct firmware *eeprom_blob,
  344. void *ctx)
  345. {
  346. struct ath9k_eeprom_ctx *ec = ctx;
  347. if (eeprom_blob)
  348. ec->ah->eeprom_blob = eeprom_blob;
  349. complete(&ec->complete);
  350. }
  351. static int ath9k_eeprom_request(struct ath_softc *sc, const char *name)
  352. {
  353. struct ath9k_eeprom_ctx ec;
  354. struct ath_hw *ah = ah = sc->sc_ah;
  355. int err;
  356. /* try to load the EEPROM content asynchronously */
  357. init_completion(&ec.complete);
  358. ec.ah = sc->sc_ah;
  359. err = request_firmware_nowait(THIS_MODULE, 1, name, sc->dev, GFP_KERNEL,
  360. &ec, ath9k_eeprom_request_cb);
  361. if (err < 0) {
  362. ath_err(ath9k_hw_common(ah),
  363. "EEPROM request failed\n");
  364. return err;
  365. }
  366. wait_for_completion(&ec.complete);
  367. if (!ah->eeprom_blob) {
  368. ath_err(ath9k_hw_common(ah),
  369. "Unable to load EEPROM file %s\n", name);
  370. return -EINVAL;
  371. }
  372. return 0;
  373. }
  374. static void ath9k_eeprom_release(struct ath_softc *sc)
  375. {
  376. release_firmware(sc->sc_ah->eeprom_blob);
  377. }
  378. static int ath9k_init_soc_platform(struct ath_softc *sc)
  379. {
  380. struct ath9k_platform_data *pdata = sc->dev->platform_data;
  381. struct ath_hw *ah = sc->sc_ah;
  382. int ret = 0;
  383. if (!pdata)
  384. return 0;
  385. if (pdata->eeprom_name) {
  386. ret = ath9k_eeprom_request(sc, pdata->eeprom_name);
  387. if (ret)
  388. return ret;
  389. }
  390. if (pdata->tx_gain_buffalo)
  391. ah->config.tx_gain_buffalo = true;
  392. return ret;
  393. }
  394. static int ath9k_init_softc(u16 devid, struct ath_softc *sc,
  395. const struct ath_bus_ops *bus_ops)
  396. {
  397. struct ath9k_platform_data *pdata = sc->dev->platform_data;
  398. struct ath_hw *ah = NULL;
  399. struct ath9k_hw_capabilities *pCap;
  400. struct ath_common *common;
  401. int ret = 0, i;
  402. int csz = 0;
  403. ah = devm_kzalloc(sc->dev, sizeof(struct ath_hw), GFP_KERNEL);
  404. if (!ah)
  405. return -ENOMEM;
  406. ah->dev = sc->dev;
  407. ah->hw = sc->hw;
  408. ah->hw_version.devid = devid;
  409. ah->reg_ops.read = ath9k_ioread32;
  410. ah->reg_ops.write = ath9k_iowrite32;
  411. ah->reg_ops.rmw = ath9k_reg_rmw;
  412. sc->sc_ah = ah;
  413. pCap = &ah->caps;
  414. common = ath9k_hw_common(ah);
  415. sc->dfs_detector = dfs_pattern_detector_init(common, NL80211_DFS_UNSET);
  416. sc->tx99_power = MAX_RATE_POWER + 1;
  417. init_waitqueue_head(&sc->tx_wait);
  418. if (!pdata) {
  419. ah->ah_flags |= AH_USE_EEPROM;
  420. sc->sc_ah->led_pin = -1;
  421. } else {
  422. sc->sc_ah->gpio_mask = pdata->gpio_mask;
  423. sc->sc_ah->gpio_val = pdata->gpio_val;
  424. sc->sc_ah->led_pin = pdata->led_pin;
  425. ah->is_clk_25mhz = pdata->is_clk_25mhz;
  426. ah->get_mac_revision = pdata->get_mac_revision;
  427. ah->external_reset = pdata->external_reset;
  428. }
  429. common->ops = &ah->reg_ops;
  430. common->bus_ops = bus_ops;
  431. common->ah = ah;
  432. common->hw = sc->hw;
  433. common->priv = sc;
  434. common->debug_mask = ath9k_debug;
  435. common->btcoex_enabled = ath9k_btcoex_enable == 1;
  436. common->disable_ani = false;
  437. /*
  438. * Platform quirks.
  439. */
  440. ath9k_init_pcoem_platform(sc);
  441. ret = ath9k_init_soc_platform(sc);
  442. if (ret)
  443. return ret;
  444. /*
  445. * Enable WLAN/BT RX Antenna diversity only when:
  446. *
  447. * - BTCOEX is disabled.
  448. * - the user manually requests the feature.
  449. * - the HW cap is set using the platform data.
  450. */
  451. if (!common->btcoex_enabled && ath9k_bt_ant_diversity &&
  452. (pCap->hw_caps & ATH9K_HW_CAP_BT_ANT_DIV))
  453. common->bt_ant_diversity = 1;
  454. spin_lock_init(&common->cc_lock);
  455. spin_lock_init(&sc->sc_serial_rw);
  456. spin_lock_init(&sc->sc_pm_lock);
  457. mutex_init(&sc->mutex);
  458. tasklet_init(&sc->intr_tq, ath9k_tasklet, (unsigned long)sc);
  459. tasklet_init(&sc->bcon_tasklet, ath9k_beacon_tasklet,
  460. (unsigned long)sc);
  461. setup_timer(&sc->sleep_timer, ath_ps_full_sleep, (unsigned long)sc);
  462. INIT_WORK(&sc->hw_reset_work, ath_reset_work);
  463. INIT_WORK(&sc->paprd_work, ath_paprd_calibrate);
  464. INIT_DELAYED_WORK(&sc->hw_pll_work, ath_hw_pll_work);
  465. /*
  466. * Cache line size is used to size and align various
  467. * structures used to communicate with the hardware.
  468. */
  469. ath_read_cachesize(common, &csz);
  470. common->cachelsz = csz << 2; /* convert to bytes */
  471. /* Initializes the hardware for all supported chipsets */
  472. ret = ath9k_hw_init(ah);
  473. if (ret)
  474. goto err_hw;
  475. if (pdata && pdata->macaddr)
  476. memcpy(common->macaddr, pdata->macaddr, ETH_ALEN);
  477. ret = ath9k_init_queues(sc);
  478. if (ret)
  479. goto err_queues;
  480. ret = ath9k_init_btcoex(sc);
  481. if (ret)
  482. goto err_btcoex;
  483. ret = ath9k_cmn_init_channels_rates(common);
  484. if (ret)
  485. goto err_btcoex;
  486. sc->p2p_ps_timer = ath_gen_timer_alloc(sc->sc_ah, ath9k_p2p_ps_timer,
  487. NULL, sc, AR_FIRST_NDP_TIMER);
  488. ath9k_cmn_init_crypto(sc->sc_ah);
  489. ath9k_init_misc(sc);
  490. ath_fill_led_pin(sc);
  491. if (common->bus_ops->aspm_init)
  492. common->bus_ops->aspm_init(common);
  493. return 0;
  494. err_btcoex:
  495. for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++)
  496. if (ATH_TXQ_SETUP(sc, i))
  497. ath_tx_cleanupq(sc, &sc->tx.txq[i]);
  498. err_queues:
  499. ath9k_hw_deinit(ah);
  500. err_hw:
  501. ath9k_eeprom_release(sc);
  502. dev_kfree_skb_any(sc->tx99_skb);
  503. return ret;
  504. }
  505. static void ath9k_init_band_txpower(struct ath_softc *sc, int band)
  506. {
  507. struct ieee80211_supported_band *sband;
  508. struct ieee80211_channel *chan;
  509. struct ath_hw *ah = sc->sc_ah;
  510. struct ath_common *common = ath9k_hw_common(ah);
  511. struct cfg80211_chan_def chandef;
  512. int i;
  513. sband = &common->sbands[band];
  514. for (i = 0; i < sband->n_channels; i++) {
  515. chan = &sband->channels[i];
  516. ah->curchan = &ah->channels[chan->hw_value];
  517. cfg80211_chandef_create(&chandef, chan, NL80211_CHAN_HT20);
  518. ath9k_cmn_get_channel(sc->hw, ah, &chandef);
  519. ath9k_hw_set_txpowerlimit(ah, MAX_RATE_POWER, true);
  520. }
  521. }
  522. static void ath9k_init_txpower_limits(struct ath_softc *sc)
  523. {
  524. struct ath_hw *ah = sc->sc_ah;
  525. struct ath9k_channel *curchan = ah->curchan;
  526. if (ah->caps.hw_caps & ATH9K_HW_CAP_2GHZ)
  527. ath9k_init_band_txpower(sc, IEEE80211_BAND_2GHZ);
  528. if (ah->caps.hw_caps & ATH9K_HW_CAP_5GHZ)
  529. ath9k_init_band_txpower(sc, IEEE80211_BAND_5GHZ);
  530. ah->curchan = curchan;
  531. }
  532. static const struct ieee80211_iface_limit if_limits[] = {
  533. { .max = 2048, .types = BIT(NL80211_IFTYPE_STATION) |
  534. BIT(NL80211_IFTYPE_WDS) },
  535. { .max = 8, .types =
  536. #ifdef CONFIG_MAC80211_MESH
  537. BIT(NL80211_IFTYPE_MESH_POINT) |
  538. #endif
  539. BIT(NL80211_IFTYPE_AP) },
  540. { .max = 1, .types = BIT(NL80211_IFTYPE_P2P_CLIENT) |
  541. BIT(NL80211_IFTYPE_P2P_GO) },
  542. };
  543. static const struct ieee80211_iface_limit if_dfs_limits[] = {
  544. { .max = 1, .types = BIT(NL80211_IFTYPE_AP) |
  545. #ifdef CONFIG_MAC80211_MESH
  546. BIT(NL80211_IFTYPE_MESH_POINT) |
  547. #endif
  548. BIT(NL80211_IFTYPE_ADHOC) },
  549. };
  550. static const struct ieee80211_iface_combination if_comb[] = {
  551. {
  552. .limits = if_limits,
  553. .n_limits = ARRAY_SIZE(if_limits),
  554. .max_interfaces = 2048,
  555. .num_different_channels = 1,
  556. .beacon_int_infra_match = true,
  557. },
  558. #ifdef CONFIG_ATH9K_DFS_CERTIFIED
  559. {
  560. .limits = if_dfs_limits,
  561. .n_limits = ARRAY_SIZE(if_dfs_limits),
  562. .max_interfaces = 1,
  563. .num_different_channels = 1,
  564. .beacon_int_infra_match = true,
  565. .radar_detect_widths = BIT(NL80211_CHAN_WIDTH_20_NOHT) |
  566. BIT(NL80211_CHAN_WIDTH_20),
  567. }
  568. #endif
  569. };
  570. static void ath9k_set_hw_capab(struct ath_softc *sc, struct ieee80211_hw *hw)
  571. {
  572. struct ath_hw *ah = sc->sc_ah;
  573. struct ath_common *common = ath9k_hw_common(ah);
  574. hw->flags = IEEE80211_HW_RX_INCLUDES_FCS |
  575. IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING |
  576. IEEE80211_HW_SIGNAL_DBM |
  577. IEEE80211_HW_PS_NULLFUNC_STACK |
  578. IEEE80211_HW_SPECTRUM_MGMT |
  579. IEEE80211_HW_REPORTS_TX_ACK_STATUS |
  580. IEEE80211_HW_SUPPORTS_RC_TABLE |
  581. IEEE80211_HW_SUPPORTS_HT_CCK_RATES;
  582. if (ath9k_ps_enable)
  583. hw->flags |= IEEE80211_HW_SUPPORTS_PS;
  584. if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_HT) {
  585. hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION;
  586. if (AR_SREV_9280_20_OR_LATER(ah))
  587. hw->radiotap_mcs_details |=
  588. IEEE80211_RADIOTAP_MCS_HAVE_STBC;
  589. }
  590. if (AR_SREV_9160_10_OR_LATER(sc->sc_ah) || ath9k_modparam_nohwcrypt)
  591. hw->flags |= IEEE80211_HW_MFP_CAPABLE;
  592. hw->wiphy->features |= NL80211_FEATURE_ACTIVE_MONITOR;
  593. if (!config_enabled(CONFIG_ATH9K_TX99)) {
  594. hw->wiphy->interface_modes =
  595. BIT(NL80211_IFTYPE_P2P_GO) |
  596. BIT(NL80211_IFTYPE_P2P_CLIENT) |
  597. BIT(NL80211_IFTYPE_AP) |
  598. BIT(NL80211_IFTYPE_WDS) |
  599. BIT(NL80211_IFTYPE_STATION) |
  600. BIT(NL80211_IFTYPE_ADHOC) |
  601. BIT(NL80211_IFTYPE_MESH_POINT);
  602. hw->wiphy->iface_combinations = if_comb;
  603. hw->wiphy->n_iface_combinations = ARRAY_SIZE(if_comb);
  604. }
  605. hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
  606. hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
  607. hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS;
  608. hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
  609. hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_5_10_MHZ;
  610. hw->wiphy->flags |= WIPHY_FLAG_HAS_CHANNEL_SWITCH;
  611. hw->wiphy->flags |= WIPHY_FLAG_AP_UAPSD;
  612. hw->queues = 4;
  613. hw->max_rates = 4;
  614. hw->max_listen_interval = 1;
  615. hw->max_rate_tries = 10;
  616. hw->sta_data_size = sizeof(struct ath_node);
  617. hw->vif_data_size = sizeof(struct ath_vif);
  618. hw->wiphy->available_antennas_rx = BIT(ah->caps.max_rxchains) - 1;
  619. hw->wiphy->available_antennas_tx = BIT(ah->caps.max_txchains) - 1;
  620. /* single chain devices with rx diversity */
  621. if (ah->caps.hw_caps & ATH9K_HW_CAP_ANT_DIV_COMB)
  622. hw->wiphy->available_antennas_rx = BIT(0) | BIT(1);
  623. sc->ant_rx = hw->wiphy->available_antennas_rx;
  624. sc->ant_tx = hw->wiphy->available_antennas_tx;
  625. if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_2GHZ)
  626. hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
  627. &common->sbands[IEEE80211_BAND_2GHZ];
  628. if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_5GHZ)
  629. hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
  630. &common->sbands[IEEE80211_BAND_5GHZ];
  631. ath9k_init_wow(hw);
  632. ath9k_cmn_reload_chainmask(ah);
  633. SET_IEEE80211_PERM_ADDR(hw, common->macaddr);
  634. }
  635. int ath9k_init_device(u16 devid, struct ath_softc *sc,
  636. const struct ath_bus_ops *bus_ops)
  637. {
  638. struct ieee80211_hw *hw = sc->hw;
  639. struct ath_common *common;
  640. struct ath_hw *ah;
  641. int error = 0;
  642. struct ath_regulatory *reg;
  643. /* Bring up device */
  644. error = ath9k_init_softc(devid, sc, bus_ops);
  645. if (error)
  646. return error;
  647. ah = sc->sc_ah;
  648. common = ath9k_hw_common(ah);
  649. ath9k_set_hw_capab(sc, hw);
  650. /* Initialize regulatory */
  651. error = ath_regd_init(&common->regulatory, sc->hw->wiphy,
  652. ath9k_reg_notifier);
  653. if (error)
  654. goto deinit;
  655. reg = &common->regulatory;
  656. /* Setup TX DMA */
  657. error = ath_tx_init(sc, ATH_TXBUF);
  658. if (error != 0)
  659. goto deinit;
  660. /* Setup RX DMA */
  661. error = ath_rx_init(sc, ATH_RXBUF);
  662. if (error != 0)
  663. goto deinit;
  664. ath9k_init_txpower_limits(sc);
  665. #ifdef CONFIG_MAC80211_LEDS
  666. /* must be initialized before ieee80211_register_hw */
  667. sc->led_cdev.default_trigger = ieee80211_create_tpt_led_trigger(sc->hw,
  668. IEEE80211_TPT_LEDTRIG_FL_RADIO, ath9k_tpt_blink,
  669. ARRAY_SIZE(ath9k_tpt_blink));
  670. #endif
  671. /* Register with mac80211 */
  672. error = ieee80211_register_hw(hw);
  673. if (error)
  674. goto rx_cleanup;
  675. error = ath9k_init_debug(ah);
  676. if (error) {
  677. ath_err(common, "Unable to create debugfs files\n");
  678. goto unregister;
  679. }
  680. /* Handle world regulatory */
  681. if (!ath_is_world_regd(reg)) {
  682. error = regulatory_hint(hw->wiphy, reg->alpha2);
  683. if (error)
  684. goto debug_cleanup;
  685. }
  686. ath_init_leds(sc);
  687. ath_start_rfkill_poll(sc);
  688. return 0;
  689. debug_cleanup:
  690. ath9k_deinit_debug(sc);
  691. unregister:
  692. ieee80211_unregister_hw(hw);
  693. rx_cleanup:
  694. ath_rx_cleanup(sc);
  695. deinit:
  696. ath9k_deinit_softc(sc);
  697. return error;
  698. }
  699. /*****************************/
  700. /* De-Initialization */
  701. /*****************************/
  702. static void ath9k_deinit_softc(struct ath_softc *sc)
  703. {
  704. int i = 0;
  705. if (sc->p2p_ps_timer)
  706. ath_gen_timer_free(sc->sc_ah, sc->p2p_ps_timer);
  707. ath9k_deinit_btcoex(sc);
  708. for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++)
  709. if (ATH_TXQ_SETUP(sc, i))
  710. ath_tx_cleanupq(sc, &sc->tx.txq[i]);
  711. del_timer_sync(&sc->sleep_timer);
  712. ath9k_hw_deinit(sc->sc_ah);
  713. if (sc->dfs_detector != NULL)
  714. sc->dfs_detector->exit(sc->dfs_detector);
  715. ath9k_eeprom_release(sc);
  716. }
  717. void ath9k_deinit_device(struct ath_softc *sc)
  718. {
  719. struct ieee80211_hw *hw = sc->hw;
  720. ath9k_ps_wakeup(sc);
  721. wiphy_rfkill_stop_polling(sc->hw->wiphy);
  722. ath_deinit_leds(sc);
  723. ath9k_ps_restore(sc);
  724. ath9k_deinit_debug(sc);
  725. ieee80211_unregister_hw(hw);
  726. ath_rx_cleanup(sc);
  727. ath9k_deinit_softc(sc);
  728. }
  729. /************************/
  730. /* Module Hooks */
  731. /************************/
  732. static int __init ath9k_init(void)
  733. {
  734. int error;
  735. error = ath_pci_init();
  736. if (error < 0) {
  737. pr_err("No PCI devices found, driver not installed\n");
  738. error = -ENODEV;
  739. goto err_out;
  740. }
  741. error = ath_ahb_init();
  742. if (error < 0) {
  743. error = -ENODEV;
  744. goto err_pci_exit;
  745. }
  746. return 0;
  747. err_pci_exit:
  748. ath_pci_exit();
  749. err_out:
  750. return error;
  751. }
  752. module_init(ath9k_init);
  753. static void __exit ath9k_exit(void)
  754. {
  755. is_ath9k_unloaded = true;
  756. ath_ahb_exit();
  757. ath_pci_exit();
  758. pr_info("%s: Driver unloaded\n", dev_info);
  759. }
  760. module_exit(ath9k_exit);