init.c 27 KB

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