init.c 28 KB

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