init.c 28 KB

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