init.c 28 KB

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