init.c 29 KB

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