init.c 27 KB

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