init.c 25 KB

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