init.c 29 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060
  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. bool is_ath9k_unloaded;
  49. /* We use the hw_value as an index into our private channel structure */
  50. #define CHAN2G(_freq, _idx) { \
  51. .band = IEEE80211_BAND_2GHZ, \
  52. .center_freq = (_freq), \
  53. .hw_value = (_idx), \
  54. .max_power = 20, \
  55. }
  56. #define CHAN5G(_freq, _idx) { \
  57. .band = IEEE80211_BAND_5GHZ, \
  58. .center_freq = (_freq), \
  59. .hw_value = (_idx), \
  60. .max_power = 20, \
  61. }
  62. /* Some 2 GHz radios are actually tunable on 2312-2732
  63. * on 5 MHz steps, we support the channels which we know
  64. * we have calibration data for all cards though to make
  65. * this static */
  66. static const struct ieee80211_channel ath9k_2ghz_chantable[] = {
  67. CHAN2G(2412, 0), /* Channel 1 */
  68. CHAN2G(2417, 1), /* Channel 2 */
  69. CHAN2G(2422, 2), /* Channel 3 */
  70. CHAN2G(2427, 3), /* Channel 4 */
  71. CHAN2G(2432, 4), /* Channel 5 */
  72. CHAN2G(2437, 5), /* Channel 6 */
  73. CHAN2G(2442, 6), /* Channel 7 */
  74. CHAN2G(2447, 7), /* Channel 8 */
  75. CHAN2G(2452, 8), /* Channel 9 */
  76. CHAN2G(2457, 9), /* Channel 10 */
  77. CHAN2G(2462, 10), /* Channel 11 */
  78. CHAN2G(2467, 11), /* Channel 12 */
  79. CHAN2G(2472, 12), /* Channel 13 */
  80. CHAN2G(2484, 13), /* Channel 14 */
  81. };
  82. /* Some 5 GHz radios are actually tunable on XXXX-YYYY
  83. * on 5 MHz steps, we support the channels which we know
  84. * we have calibration data for all cards though to make
  85. * this static */
  86. static const struct ieee80211_channel ath9k_5ghz_chantable[] = {
  87. /* _We_ call this UNII 1 */
  88. CHAN5G(5180, 14), /* Channel 36 */
  89. CHAN5G(5200, 15), /* Channel 40 */
  90. CHAN5G(5220, 16), /* Channel 44 */
  91. CHAN5G(5240, 17), /* Channel 48 */
  92. /* _We_ call this UNII 2 */
  93. CHAN5G(5260, 18), /* Channel 52 */
  94. CHAN5G(5280, 19), /* Channel 56 */
  95. CHAN5G(5300, 20), /* Channel 60 */
  96. CHAN5G(5320, 21), /* Channel 64 */
  97. /* _We_ call this "Middle band" */
  98. CHAN5G(5500, 22), /* Channel 100 */
  99. CHAN5G(5520, 23), /* Channel 104 */
  100. CHAN5G(5540, 24), /* Channel 108 */
  101. CHAN5G(5560, 25), /* Channel 112 */
  102. CHAN5G(5580, 26), /* Channel 116 */
  103. CHAN5G(5600, 27), /* Channel 120 */
  104. CHAN5G(5620, 28), /* Channel 124 */
  105. CHAN5G(5640, 29), /* Channel 128 */
  106. CHAN5G(5660, 30), /* Channel 132 */
  107. CHAN5G(5680, 31), /* Channel 136 */
  108. CHAN5G(5700, 32), /* Channel 140 */
  109. /* _We_ call this UNII 3 */
  110. CHAN5G(5745, 33), /* Channel 149 */
  111. CHAN5G(5765, 34), /* Channel 153 */
  112. CHAN5G(5785, 35), /* Channel 157 */
  113. CHAN5G(5805, 36), /* Channel 161 */
  114. CHAN5G(5825, 37), /* Channel 165 */
  115. };
  116. /* Atheros hardware rate code addition for short premble */
  117. #define SHPCHECK(__hw_rate, __flags) \
  118. ((__flags & IEEE80211_RATE_SHORT_PREAMBLE) ? (__hw_rate | 0x04 ) : 0)
  119. #define RATE(_bitrate, _hw_rate, _flags) { \
  120. .bitrate = (_bitrate), \
  121. .flags = (_flags), \
  122. .hw_value = (_hw_rate), \
  123. .hw_value_short = (SHPCHECK(_hw_rate, _flags)) \
  124. }
  125. static struct ieee80211_rate ath9k_legacy_rates[] = {
  126. RATE(10, 0x1b, 0),
  127. RATE(20, 0x1a, IEEE80211_RATE_SHORT_PREAMBLE),
  128. RATE(55, 0x19, IEEE80211_RATE_SHORT_PREAMBLE),
  129. RATE(110, 0x18, IEEE80211_RATE_SHORT_PREAMBLE),
  130. RATE(60, 0x0b, 0),
  131. RATE(90, 0x0f, 0),
  132. RATE(120, 0x0a, 0),
  133. RATE(180, 0x0e, 0),
  134. RATE(240, 0x09, 0),
  135. RATE(360, 0x0d, 0),
  136. RATE(480, 0x08, 0),
  137. RATE(540, 0x0c, 0),
  138. };
  139. #ifdef CONFIG_MAC80211_LEDS
  140. static const struct ieee80211_tpt_blink ath9k_tpt_blink[] = {
  141. { .throughput = 0 * 1024, .blink_time = 334 },
  142. { .throughput = 1 * 1024, .blink_time = 260 },
  143. { .throughput = 5 * 1024, .blink_time = 220 },
  144. { .throughput = 10 * 1024, .blink_time = 190 },
  145. { .throughput = 20 * 1024, .blink_time = 170 },
  146. { .throughput = 50 * 1024, .blink_time = 150 },
  147. { .throughput = 70 * 1024, .blink_time = 130 },
  148. { .throughput = 100 * 1024, .blink_time = 110 },
  149. { .throughput = 200 * 1024, .blink_time = 80 },
  150. { .throughput = 300 * 1024, .blink_time = 50 },
  151. };
  152. #endif
  153. static void ath9k_deinit_softc(struct ath_softc *sc);
  154. /*
  155. * Read and write, they both share the same lock. We do this to serialize
  156. * reads and writes on Atheros 802.11n PCI devices only. This is required
  157. * as the FIFO on these devices can only accept sanely 2 requests.
  158. */
  159. static void ath9k_iowrite32(void *hw_priv, u32 val, u32 reg_offset)
  160. {
  161. struct ath_hw *ah = (struct ath_hw *) hw_priv;
  162. struct ath_common *common = ath9k_hw_common(ah);
  163. struct ath_softc *sc = (struct ath_softc *) common->priv;
  164. if (NR_CPUS > 1 && ah->config.serialize_regmode == SER_REG_MODE_ON) {
  165. unsigned long flags;
  166. spin_lock_irqsave(&sc->sc_serial_rw, flags);
  167. iowrite32(val, sc->mem + reg_offset);
  168. spin_unlock_irqrestore(&sc->sc_serial_rw, flags);
  169. } else
  170. iowrite32(val, sc->mem + reg_offset);
  171. }
  172. static unsigned int ath9k_ioread32(void *hw_priv, u32 reg_offset)
  173. {
  174. struct ath_hw *ah = (struct ath_hw *) hw_priv;
  175. struct ath_common *common = ath9k_hw_common(ah);
  176. struct ath_softc *sc = (struct ath_softc *) common->priv;
  177. u32 val;
  178. if (NR_CPUS > 1 && ah->config.serialize_regmode == SER_REG_MODE_ON) {
  179. unsigned long flags;
  180. spin_lock_irqsave(&sc->sc_serial_rw, flags);
  181. val = ioread32(sc->mem + reg_offset);
  182. spin_unlock_irqrestore(&sc->sc_serial_rw, flags);
  183. } else
  184. val = ioread32(sc->mem + reg_offset);
  185. return val;
  186. }
  187. static unsigned int __ath9k_reg_rmw(struct ath_softc *sc, u32 reg_offset,
  188. u32 set, u32 clr)
  189. {
  190. u32 val;
  191. val = ioread32(sc->mem + reg_offset);
  192. val &= ~clr;
  193. val |= set;
  194. iowrite32(val, sc->mem + reg_offset);
  195. return val;
  196. }
  197. static unsigned int ath9k_reg_rmw(void *hw_priv, u32 reg_offset, u32 set, u32 clr)
  198. {
  199. struct ath_hw *ah = (struct ath_hw *) hw_priv;
  200. struct ath_common *common = ath9k_hw_common(ah);
  201. struct ath_softc *sc = (struct ath_softc *) common->priv;
  202. unsigned long uninitialized_var(flags);
  203. u32 val;
  204. if (NR_CPUS > 1 && ah->config.serialize_regmode == SER_REG_MODE_ON) {
  205. spin_lock_irqsave(&sc->sc_serial_rw, flags);
  206. val = __ath9k_reg_rmw(sc, reg_offset, set, clr);
  207. spin_unlock_irqrestore(&sc->sc_serial_rw, flags);
  208. } else
  209. val = __ath9k_reg_rmw(sc, reg_offset, set, clr);
  210. return val;
  211. }
  212. /**************************/
  213. /* Initialization */
  214. /**************************/
  215. static void setup_ht_cap(struct ath_softc *sc,
  216. struct ieee80211_sta_ht_cap *ht_info)
  217. {
  218. struct ath_hw *ah = sc->sc_ah;
  219. struct ath_common *common = ath9k_hw_common(ah);
  220. u8 tx_streams, rx_streams;
  221. int i, max_streams;
  222. ht_info->ht_supported = true;
  223. ht_info->cap = IEEE80211_HT_CAP_SUP_WIDTH_20_40 |
  224. IEEE80211_HT_CAP_SM_PS |
  225. IEEE80211_HT_CAP_SGI_40 |
  226. IEEE80211_HT_CAP_DSSSCCK40;
  227. if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_LDPC)
  228. ht_info->cap |= IEEE80211_HT_CAP_LDPC_CODING;
  229. if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_SGI_20)
  230. ht_info->cap |= IEEE80211_HT_CAP_SGI_20;
  231. ht_info->ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
  232. ht_info->ampdu_density = IEEE80211_HT_MPDU_DENSITY_8;
  233. if (AR_SREV_9330(ah) || AR_SREV_9485(ah) || AR_SREV_9565(ah))
  234. max_streams = 1;
  235. else if (AR_SREV_9462(ah))
  236. max_streams = 2;
  237. else if (AR_SREV_9300_20_OR_LATER(ah))
  238. max_streams = 3;
  239. else
  240. max_streams = 2;
  241. if (AR_SREV_9280_20_OR_LATER(ah)) {
  242. if (max_streams >= 2)
  243. ht_info->cap |= IEEE80211_HT_CAP_TX_STBC;
  244. ht_info->cap |= (1 << IEEE80211_HT_CAP_RX_STBC_SHIFT);
  245. }
  246. /* set up supported mcs set */
  247. memset(&ht_info->mcs, 0, sizeof(ht_info->mcs));
  248. tx_streams = ath9k_cmn_count_streams(ah->txchainmask, max_streams);
  249. rx_streams = ath9k_cmn_count_streams(ah->rxchainmask, max_streams);
  250. ath_dbg(common, CONFIG, "TX streams %d, RX streams: %d\n",
  251. tx_streams, rx_streams);
  252. if (tx_streams != rx_streams) {
  253. ht_info->mcs.tx_params |= IEEE80211_HT_MCS_TX_RX_DIFF;
  254. ht_info->mcs.tx_params |= ((tx_streams - 1) <<
  255. IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT);
  256. }
  257. for (i = 0; i < rx_streams; i++)
  258. ht_info->mcs.rx_mask[i] = 0xff;
  259. ht_info->mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
  260. }
  261. static void ath9k_reg_notifier(struct wiphy *wiphy,
  262. struct regulatory_request *request)
  263. {
  264. struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
  265. struct ath_softc *sc = hw->priv;
  266. struct ath_hw *ah = sc->sc_ah;
  267. struct ath_regulatory *reg = ath9k_hw_regulatory(ah);
  268. ath_reg_notifier_apply(wiphy, request, reg);
  269. /* Set tx power */
  270. if (ah->curchan) {
  271. sc->config.txpowlimit = 2 * ah->curchan->chan->max_power;
  272. ath9k_ps_wakeup(sc);
  273. ath9k_hw_set_txpowerlimit(ah, sc->config.txpowlimit, false);
  274. sc->curtxpow = ath9k_hw_regulatory(ah)->power_limit;
  275. /* synchronize DFS detector if regulatory domain changed */
  276. if (sc->dfs_detector != NULL)
  277. sc->dfs_detector->set_dfs_domain(sc->dfs_detector,
  278. request->dfs_region);
  279. ath9k_ps_restore(sc);
  280. }
  281. }
  282. /*
  283. * This function will allocate both the DMA descriptor structure, and the
  284. * buffers it contains. These are used to contain the descriptors used
  285. * by the system.
  286. */
  287. int ath_descdma_setup(struct ath_softc *sc, struct ath_descdma *dd,
  288. struct list_head *head, const char *name,
  289. int nbuf, int ndesc, bool is_tx)
  290. {
  291. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  292. u8 *ds;
  293. struct ath_buf *bf;
  294. int i, bsize, desc_len;
  295. ath_dbg(common, CONFIG, "%s DMA: %u buffers %u desc/buf\n",
  296. name, nbuf, ndesc);
  297. INIT_LIST_HEAD(head);
  298. if (is_tx)
  299. desc_len = sc->sc_ah->caps.tx_desc_len;
  300. else
  301. desc_len = sizeof(struct ath_desc);
  302. /* ath_desc must be a multiple of DWORDs */
  303. if ((desc_len % 4) != 0) {
  304. ath_err(common, "ath_desc not DWORD aligned\n");
  305. BUG_ON((desc_len % 4) != 0);
  306. return -ENOMEM;
  307. }
  308. dd->dd_desc_len = desc_len * nbuf * ndesc;
  309. /*
  310. * Need additional DMA memory because we can't use
  311. * descriptors that cross the 4K page boundary. Assume
  312. * one skipped descriptor per 4K page.
  313. */
  314. if (!(sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_4KB_SPLITTRANS)) {
  315. u32 ndesc_skipped =
  316. ATH_DESC_4KB_BOUND_NUM_SKIPPED(dd->dd_desc_len);
  317. u32 dma_len;
  318. while (ndesc_skipped) {
  319. dma_len = ndesc_skipped * desc_len;
  320. dd->dd_desc_len += dma_len;
  321. ndesc_skipped = ATH_DESC_4KB_BOUND_NUM_SKIPPED(dma_len);
  322. }
  323. }
  324. /* allocate descriptors */
  325. dd->dd_desc = dmam_alloc_coherent(sc->dev, dd->dd_desc_len,
  326. &dd->dd_desc_paddr, GFP_KERNEL);
  327. if (!dd->dd_desc)
  328. return -ENOMEM;
  329. ds = (u8 *) dd->dd_desc;
  330. ath_dbg(common, CONFIG, "%s DMA map: %p (%u) -> %llx (%u)\n",
  331. name, ds, (u32) dd->dd_desc_len,
  332. ito64(dd->dd_desc_paddr), /*XXX*/(u32) dd->dd_desc_len);
  333. /* allocate buffers */
  334. bsize = sizeof(struct ath_buf) * nbuf;
  335. bf = devm_kzalloc(sc->dev, bsize, GFP_KERNEL);
  336. if (!bf)
  337. return -ENOMEM;
  338. for (i = 0; i < nbuf; i++, bf++, ds += (desc_len * ndesc)) {
  339. bf->bf_desc = ds;
  340. bf->bf_daddr = DS2PHYS(dd, ds);
  341. if (!(sc->sc_ah->caps.hw_caps &
  342. ATH9K_HW_CAP_4KB_SPLITTRANS)) {
  343. /*
  344. * Skip descriptor addresses which can cause 4KB
  345. * boundary crossing (addr + length) with a 32 dword
  346. * descriptor fetch.
  347. */
  348. while (ATH_DESC_4KB_BOUND_CHECK(bf->bf_daddr)) {
  349. BUG_ON((caddr_t) bf->bf_desc >=
  350. ((caddr_t) dd->dd_desc +
  351. dd->dd_desc_len));
  352. ds += (desc_len * ndesc);
  353. bf->bf_desc = ds;
  354. bf->bf_daddr = DS2PHYS(dd, ds);
  355. }
  356. }
  357. list_add_tail(&bf->list, head);
  358. }
  359. return 0;
  360. }
  361. static int ath9k_init_queues(struct ath_softc *sc)
  362. {
  363. int i = 0;
  364. sc->beacon.beaconq = ath9k_hw_beaconq_setup(sc->sc_ah);
  365. sc->beacon.cabq = ath_txq_setup(sc, ATH9K_TX_QUEUE_CAB, 0);
  366. sc->config.cabqReadytime = ATH_CABQ_READY_TIME;
  367. ath_cabq_update(sc);
  368. sc->tx.uapsdq = ath_txq_setup(sc, ATH9K_TX_QUEUE_UAPSD, 0);
  369. for (i = 0; i < IEEE80211_NUM_ACS; i++) {
  370. sc->tx.txq_map[i] = ath_txq_setup(sc, ATH9K_TX_QUEUE_DATA, i);
  371. sc->tx.txq_map[i]->mac80211_qnum = i;
  372. sc->tx.txq_max_pending[i] = ATH_MAX_QDEPTH;
  373. }
  374. return 0;
  375. }
  376. static int ath9k_init_channels_rates(struct ath_softc *sc)
  377. {
  378. void *channels;
  379. BUILD_BUG_ON(ARRAY_SIZE(ath9k_2ghz_chantable) +
  380. ARRAY_SIZE(ath9k_5ghz_chantable) !=
  381. ATH9K_NUM_CHANNELS);
  382. if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_2GHZ) {
  383. channels = devm_kzalloc(sc->dev,
  384. sizeof(ath9k_2ghz_chantable), GFP_KERNEL);
  385. if (!channels)
  386. return -ENOMEM;
  387. memcpy(channels, ath9k_2ghz_chantable,
  388. sizeof(ath9k_2ghz_chantable));
  389. sc->sbands[IEEE80211_BAND_2GHZ].channels = channels;
  390. sc->sbands[IEEE80211_BAND_2GHZ].band = IEEE80211_BAND_2GHZ;
  391. sc->sbands[IEEE80211_BAND_2GHZ].n_channels =
  392. ARRAY_SIZE(ath9k_2ghz_chantable);
  393. sc->sbands[IEEE80211_BAND_2GHZ].bitrates = ath9k_legacy_rates;
  394. sc->sbands[IEEE80211_BAND_2GHZ].n_bitrates =
  395. ARRAY_SIZE(ath9k_legacy_rates);
  396. }
  397. if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_5GHZ) {
  398. channels = devm_kzalloc(sc->dev,
  399. sizeof(ath9k_5ghz_chantable), GFP_KERNEL);
  400. if (!channels)
  401. return -ENOMEM;
  402. memcpy(channels, ath9k_5ghz_chantable,
  403. sizeof(ath9k_5ghz_chantable));
  404. sc->sbands[IEEE80211_BAND_5GHZ].channels = channels;
  405. sc->sbands[IEEE80211_BAND_5GHZ].band = IEEE80211_BAND_5GHZ;
  406. sc->sbands[IEEE80211_BAND_5GHZ].n_channels =
  407. ARRAY_SIZE(ath9k_5ghz_chantable);
  408. sc->sbands[IEEE80211_BAND_5GHZ].bitrates =
  409. ath9k_legacy_rates + 4;
  410. sc->sbands[IEEE80211_BAND_5GHZ].n_bitrates =
  411. ARRAY_SIZE(ath9k_legacy_rates) - 4;
  412. }
  413. return 0;
  414. }
  415. static void ath9k_init_misc(struct ath_softc *sc)
  416. {
  417. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  418. int i = 0;
  419. setup_timer(&common->ani.timer, ath_ani_calibrate, (unsigned long)sc);
  420. sc->last_rssi = ATH_RSSI_DUMMY_MARKER;
  421. sc->config.txpowlimit = ATH_TXPOWER_MAX;
  422. memcpy(common->bssidmask, ath_bcast_mac, ETH_ALEN);
  423. sc->beacon.slottime = ATH9K_SLOT_TIME_9;
  424. for (i = 0; i < ARRAY_SIZE(sc->beacon.bslot); i++)
  425. sc->beacon.bslot[i] = NULL;
  426. if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_ANT_DIV_COMB)
  427. sc->ant_comb.count = ATH_ANT_DIV_COMB_INIT_COUNT;
  428. sc->spec_config.enabled = 0;
  429. sc->spec_config.short_repeat = true;
  430. sc->spec_config.count = 8;
  431. sc->spec_config.endless = false;
  432. sc->spec_config.period = 0xFF;
  433. sc->spec_config.fft_period = 0xF;
  434. }
  435. static void ath9k_init_platform(struct ath_softc *sc)
  436. {
  437. struct ath_hw *ah = sc->sc_ah;
  438. struct ath9k_hw_capabilities *pCap = &ah->caps;
  439. struct ath_common *common = ath9k_hw_common(ah);
  440. if (common->bus_ops->ath_bus_type != ATH_PCI)
  441. return;
  442. if (sc->driver_data & (ATH9K_PCI_CUS198 |
  443. ATH9K_PCI_CUS230)) {
  444. ah->config.xlna_gpio = 9;
  445. ah->config.xatten_margin_cfg = true;
  446. ah->config.ant_ctrl_comm2g_switch_enable = 0x000BBB88;
  447. sc->ant_comb.low_rssi_thresh = 20;
  448. sc->ant_comb.fast_div_bias = 3;
  449. ath_info(common, "Set parameters for %s\n",
  450. (sc->driver_data & ATH9K_PCI_CUS198) ?
  451. "CUS198" : "CUS230");
  452. }
  453. if (sc->driver_data & ATH9K_PCI_CUS217)
  454. ath_info(common, "CUS217 card detected\n");
  455. if (sc->driver_data & ATH9K_PCI_BT_ANT_DIV) {
  456. pCap->hw_caps |= ATH9K_HW_CAP_BT_ANT_DIV;
  457. ath_info(common, "Set BT/WLAN RX diversity capability\n");
  458. }
  459. }
  460. static void ath9k_eeprom_request_cb(const struct firmware *eeprom_blob,
  461. void *ctx)
  462. {
  463. struct ath9k_eeprom_ctx *ec = ctx;
  464. if (eeprom_blob)
  465. ec->ah->eeprom_blob = eeprom_blob;
  466. complete(&ec->complete);
  467. }
  468. static int ath9k_eeprom_request(struct ath_softc *sc, const char *name)
  469. {
  470. struct ath9k_eeprom_ctx ec;
  471. struct ath_hw *ah = ah = sc->sc_ah;
  472. int err;
  473. /* try to load the EEPROM content asynchronously */
  474. init_completion(&ec.complete);
  475. ec.ah = sc->sc_ah;
  476. err = request_firmware_nowait(THIS_MODULE, 1, name, sc->dev, GFP_KERNEL,
  477. &ec, ath9k_eeprom_request_cb);
  478. if (err < 0) {
  479. ath_err(ath9k_hw_common(ah),
  480. "EEPROM request failed\n");
  481. return err;
  482. }
  483. wait_for_completion(&ec.complete);
  484. if (!ah->eeprom_blob) {
  485. ath_err(ath9k_hw_common(ah),
  486. "Unable to load EEPROM file %s\n", name);
  487. return -EINVAL;
  488. }
  489. return 0;
  490. }
  491. static void ath9k_eeprom_release(struct ath_softc *sc)
  492. {
  493. release_firmware(sc->sc_ah->eeprom_blob);
  494. }
  495. static int ath9k_init_softc(u16 devid, struct ath_softc *sc,
  496. const struct ath_bus_ops *bus_ops)
  497. {
  498. struct ath9k_platform_data *pdata = sc->dev->platform_data;
  499. struct ath_hw *ah = NULL;
  500. struct ath9k_hw_capabilities *pCap;
  501. struct ath_common *common;
  502. int ret = 0, i;
  503. int csz = 0;
  504. ah = devm_kzalloc(sc->dev, sizeof(struct ath_hw), GFP_KERNEL);
  505. if (!ah)
  506. return -ENOMEM;
  507. ah->dev = sc->dev;
  508. ah->hw = sc->hw;
  509. ah->hw_version.devid = devid;
  510. ah->reg_ops.read = ath9k_ioread32;
  511. ah->reg_ops.write = ath9k_iowrite32;
  512. ah->reg_ops.rmw = ath9k_reg_rmw;
  513. atomic_set(&ah->intr_ref_cnt, -1);
  514. sc->sc_ah = ah;
  515. pCap = &ah->caps;
  516. sc->dfs_detector = dfs_pattern_detector_init(ah, NL80211_DFS_UNSET);
  517. if (!pdata) {
  518. ah->ah_flags |= AH_USE_EEPROM;
  519. sc->sc_ah->led_pin = -1;
  520. } else {
  521. sc->sc_ah->gpio_mask = pdata->gpio_mask;
  522. sc->sc_ah->gpio_val = pdata->gpio_val;
  523. sc->sc_ah->led_pin = pdata->led_pin;
  524. ah->is_clk_25mhz = pdata->is_clk_25mhz;
  525. ah->get_mac_revision = pdata->get_mac_revision;
  526. ah->external_reset = pdata->external_reset;
  527. }
  528. common = ath9k_hw_common(ah);
  529. common->ops = &ah->reg_ops;
  530. common->bus_ops = bus_ops;
  531. common->ah = ah;
  532. common->hw = sc->hw;
  533. common->priv = sc;
  534. common->debug_mask = ath9k_debug;
  535. common->btcoex_enabled = ath9k_btcoex_enable == 1;
  536. common->disable_ani = false;
  537. /*
  538. * Platform quirks.
  539. */
  540. ath9k_init_platform(sc);
  541. /*
  542. * Enable WLAN/BT RX Antenna diversity only when:
  543. *
  544. * - BTCOEX is disabled.
  545. * - the user manually requests the feature.
  546. * - the HW cap is set using the platform data.
  547. */
  548. if (!common->btcoex_enabled && ath9k_bt_ant_diversity &&
  549. (pCap->hw_caps & ATH9K_HW_CAP_BT_ANT_DIV))
  550. common->bt_ant_diversity = 1;
  551. spin_lock_init(&common->cc_lock);
  552. spin_lock_init(&sc->sc_serial_rw);
  553. spin_lock_init(&sc->sc_pm_lock);
  554. mutex_init(&sc->mutex);
  555. tasklet_init(&sc->intr_tq, ath9k_tasklet, (unsigned long)sc);
  556. tasklet_init(&sc->bcon_tasklet, ath9k_beacon_tasklet,
  557. (unsigned long)sc);
  558. INIT_WORK(&sc->hw_reset_work, ath_reset_work);
  559. INIT_WORK(&sc->hw_check_work, ath_hw_check);
  560. INIT_WORK(&sc->paprd_work, ath_paprd_calibrate);
  561. INIT_DELAYED_WORK(&sc->hw_pll_work, ath_hw_pll_work);
  562. setup_timer(&sc->rx_poll_timer, ath_rx_poll, (unsigned long)sc);
  563. /*
  564. * Cache line size is used to size and align various
  565. * structures used to communicate with the hardware.
  566. */
  567. ath_read_cachesize(common, &csz);
  568. common->cachelsz = csz << 2; /* convert to bytes */
  569. if (pdata && pdata->eeprom_name) {
  570. ret = ath9k_eeprom_request(sc, pdata->eeprom_name);
  571. if (ret)
  572. return ret;
  573. }
  574. /* Initializes the hardware for all supported chipsets */
  575. ret = ath9k_hw_init(ah);
  576. if (ret)
  577. goto err_hw;
  578. if (pdata && pdata->macaddr)
  579. memcpy(common->macaddr, pdata->macaddr, ETH_ALEN);
  580. ret = ath9k_init_queues(sc);
  581. if (ret)
  582. goto err_queues;
  583. ret = ath9k_init_btcoex(sc);
  584. if (ret)
  585. goto err_btcoex;
  586. ret = ath9k_init_channels_rates(sc);
  587. if (ret)
  588. goto err_btcoex;
  589. ath9k_cmn_init_crypto(sc->sc_ah);
  590. ath9k_init_misc(sc);
  591. ath_fill_led_pin(sc);
  592. if (common->bus_ops->aspm_init)
  593. common->bus_ops->aspm_init(common);
  594. return 0;
  595. err_btcoex:
  596. for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++)
  597. if (ATH_TXQ_SETUP(sc, i))
  598. ath_tx_cleanupq(sc, &sc->tx.txq[i]);
  599. err_queues:
  600. ath9k_hw_deinit(ah);
  601. err_hw:
  602. ath9k_eeprom_release(sc);
  603. return ret;
  604. }
  605. static void ath9k_init_band_txpower(struct ath_softc *sc, int band)
  606. {
  607. struct ieee80211_supported_band *sband;
  608. struct ieee80211_channel *chan;
  609. struct ath_hw *ah = sc->sc_ah;
  610. int i;
  611. sband = &sc->sbands[band];
  612. for (i = 0; i < sband->n_channels; i++) {
  613. chan = &sband->channels[i];
  614. ah->curchan = &ah->channels[chan->hw_value];
  615. ath9k_cmn_update_ichannel(ah->curchan, chan, NL80211_CHAN_HT20);
  616. ath9k_hw_set_txpowerlimit(ah, MAX_RATE_POWER, true);
  617. }
  618. }
  619. static void ath9k_init_txpower_limits(struct ath_softc *sc)
  620. {
  621. struct ath_hw *ah = sc->sc_ah;
  622. struct ath9k_channel *curchan = ah->curchan;
  623. if (ah->caps.hw_caps & ATH9K_HW_CAP_2GHZ)
  624. ath9k_init_band_txpower(sc, IEEE80211_BAND_2GHZ);
  625. if (ah->caps.hw_caps & ATH9K_HW_CAP_5GHZ)
  626. ath9k_init_band_txpower(sc, IEEE80211_BAND_5GHZ);
  627. ah->curchan = curchan;
  628. }
  629. void ath9k_reload_chainmask_settings(struct ath_softc *sc)
  630. {
  631. if (!(sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_HT))
  632. return;
  633. if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_2GHZ)
  634. setup_ht_cap(sc, &sc->sbands[IEEE80211_BAND_2GHZ].ht_cap);
  635. if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_5GHZ)
  636. setup_ht_cap(sc, &sc->sbands[IEEE80211_BAND_5GHZ].ht_cap);
  637. }
  638. static const struct ieee80211_iface_limit if_limits[] = {
  639. { .max = 2048, .types = BIT(NL80211_IFTYPE_STATION) |
  640. BIT(NL80211_IFTYPE_P2P_CLIENT) |
  641. BIT(NL80211_IFTYPE_WDS) },
  642. { .max = 8, .types =
  643. #ifdef CONFIG_MAC80211_MESH
  644. BIT(NL80211_IFTYPE_MESH_POINT) |
  645. #endif
  646. BIT(NL80211_IFTYPE_AP) |
  647. BIT(NL80211_IFTYPE_P2P_GO) },
  648. };
  649. static const struct ieee80211_iface_limit if_dfs_limits[] = {
  650. { .max = 1, .types = BIT(NL80211_IFTYPE_AP) },
  651. };
  652. static const struct ieee80211_iface_combination if_comb[] = {
  653. {
  654. .limits = if_limits,
  655. .n_limits = ARRAY_SIZE(if_limits),
  656. .max_interfaces = 2048,
  657. .num_different_channels = 1,
  658. .beacon_int_infra_match = true,
  659. },
  660. {
  661. .limits = if_dfs_limits,
  662. .n_limits = ARRAY_SIZE(if_dfs_limits),
  663. .max_interfaces = 1,
  664. .num_different_channels = 1,
  665. .beacon_int_infra_match = true,
  666. .radar_detect_widths = BIT(NL80211_CHAN_NO_HT) |
  667. BIT(NL80211_CHAN_HT20),
  668. }
  669. };
  670. #ifdef CONFIG_PM
  671. static const struct wiphy_wowlan_support ath9k_wowlan_support = {
  672. .flags = WIPHY_WOWLAN_MAGIC_PKT | WIPHY_WOWLAN_DISCONNECT,
  673. .n_patterns = MAX_NUM_USER_PATTERN,
  674. .pattern_min_len = 1,
  675. .pattern_max_len = MAX_PATTERN_SIZE,
  676. };
  677. #endif
  678. void ath9k_set_hw_capab(struct ath_softc *sc, struct ieee80211_hw *hw)
  679. {
  680. struct ath_hw *ah = sc->sc_ah;
  681. struct ath_common *common = ath9k_hw_common(ah);
  682. hw->flags = IEEE80211_HW_RX_INCLUDES_FCS |
  683. IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING |
  684. IEEE80211_HW_SIGNAL_DBM |
  685. IEEE80211_HW_SUPPORTS_PS |
  686. IEEE80211_HW_PS_NULLFUNC_STACK |
  687. IEEE80211_HW_SPECTRUM_MGMT |
  688. IEEE80211_HW_REPORTS_TX_ACK_STATUS |
  689. IEEE80211_HW_SUPPORTS_RC_TABLE;
  690. if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_HT) {
  691. hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION;
  692. if (AR_SREV_9280_20_OR_LATER(ah))
  693. hw->radiotap_mcs_details |=
  694. IEEE80211_RADIOTAP_MCS_HAVE_STBC;
  695. }
  696. if (AR_SREV_9160_10_OR_LATER(sc->sc_ah) || ath9k_modparam_nohwcrypt)
  697. hw->flags |= IEEE80211_HW_MFP_CAPABLE;
  698. hw->wiphy->features |= NL80211_FEATURE_ACTIVE_MONITOR;
  699. hw->wiphy->interface_modes =
  700. BIT(NL80211_IFTYPE_P2P_GO) |
  701. BIT(NL80211_IFTYPE_P2P_CLIENT) |
  702. BIT(NL80211_IFTYPE_AP) |
  703. BIT(NL80211_IFTYPE_WDS) |
  704. BIT(NL80211_IFTYPE_STATION) |
  705. BIT(NL80211_IFTYPE_ADHOC) |
  706. BIT(NL80211_IFTYPE_MESH_POINT);
  707. hw->wiphy->iface_combinations = if_comb;
  708. hw->wiphy->n_iface_combinations = ARRAY_SIZE(if_comb);
  709. hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
  710. hw->wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
  711. hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_TDLS;
  712. hw->wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
  713. #ifdef CONFIG_PM_SLEEP
  714. if ((ah->caps.hw_caps & ATH9K_HW_WOW_DEVICE_CAPABLE) &&
  715. (sc->driver_data & ATH9K_PCI_WOW) &&
  716. device_can_wakeup(sc->dev))
  717. hw->wiphy->wowlan = &ath9k_wowlan_support;
  718. atomic_set(&sc->wow_sleep_proc_intr, -1);
  719. atomic_set(&sc->wow_got_bmiss_intr, -1);
  720. #endif
  721. hw->queues = 4;
  722. hw->max_rates = 4;
  723. hw->channel_change_time = 5000;
  724. hw->max_listen_interval = 1;
  725. hw->max_rate_tries = 10;
  726. hw->sta_data_size = sizeof(struct ath_node);
  727. hw->vif_data_size = sizeof(struct ath_vif);
  728. hw->wiphy->available_antennas_rx = BIT(ah->caps.max_rxchains) - 1;
  729. hw->wiphy->available_antennas_tx = BIT(ah->caps.max_txchains) - 1;
  730. /* single chain devices with rx diversity */
  731. if (ah->caps.hw_caps & ATH9K_HW_CAP_ANT_DIV_COMB)
  732. hw->wiphy->available_antennas_rx = BIT(0) | BIT(1);
  733. sc->ant_rx = hw->wiphy->available_antennas_rx;
  734. sc->ant_tx = hw->wiphy->available_antennas_tx;
  735. if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_2GHZ)
  736. hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
  737. &sc->sbands[IEEE80211_BAND_2GHZ];
  738. if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_5GHZ)
  739. hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
  740. &sc->sbands[IEEE80211_BAND_5GHZ];
  741. ath9k_reload_chainmask_settings(sc);
  742. SET_IEEE80211_PERM_ADDR(hw, common->macaddr);
  743. }
  744. int ath9k_init_device(u16 devid, struct ath_softc *sc,
  745. const struct ath_bus_ops *bus_ops)
  746. {
  747. struct ieee80211_hw *hw = sc->hw;
  748. struct ath_common *common;
  749. struct ath_hw *ah;
  750. int error = 0;
  751. struct ath_regulatory *reg;
  752. /* Bring up device */
  753. error = ath9k_init_softc(devid, sc, bus_ops);
  754. if (error)
  755. return error;
  756. ah = sc->sc_ah;
  757. common = ath9k_hw_common(ah);
  758. ath9k_set_hw_capab(sc, hw);
  759. /* Initialize regulatory */
  760. error = ath_regd_init(&common->regulatory, sc->hw->wiphy,
  761. ath9k_reg_notifier);
  762. if (error)
  763. goto deinit;
  764. reg = &common->regulatory;
  765. /* Setup TX DMA */
  766. error = ath_tx_init(sc, ATH_TXBUF);
  767. if (error != 0)
  768. goto deinit;
  769. /* Setup RX DMA */
  770. error = ath_rx_init(sc, ATH_RXBUF);
  771. if (error != 0)
  772. goto deinit;
  773. ath9k_init_txpower_limits(sc);
  774. #ifdef CONFIG_MAC80211_LEDS
  775. /* must be initialized before ieee80211_register_hw */
  776. sc->led_cdev.default_trigger = ieee80211_create_tpt_led_trigger(sc->hw,
  777. IEEE80211_TPT_LEDTRIG_FL_RADIO, ath9k_tpt_blink,
  778. ARRAY_SIZE(ath9k_tpt_blink));
  779. #endif
  780. /* Register with mac80211 */
  781. error = ieee80211_register_hw(hw);
  782. if (error)
  783. goto rx_cleanup;
  784. error = ath9k_init_debug(ah);
  785. if (error) {
  786. ath_err(common, "Unable to create debugfs files\n");
  787. goto unregister;
  788. }
  789. /* Handle world regulatory */
  790. if (!ath_is_world_regd(reg)) {
  791. error = regulatory_hint(hw->wiphy, reg->alpha2);
  792. if (error)
  793. goto debug_cleanup;
  794. }
  795. ath_init_leds(sc);
  796. ath_start_rfkill_poll(sc);
  797. return 0;
  798. debug_cleanup:
  799. ath9k_deinit_debug(sc);
  800. unregister:
  801. ieee80211_unregister_hw(hw);
  802. rx_cleanup:
  803. ath_rx_cleanup(sc);
  804. deinit:
  805. ath9k_deinit_softc(sc);
  806. return error;
  807. }
  808. /*****************************/
  809. /* De-Initialization */
  810. /*****************************/
  811. static void ath9k_deinit_softc(struct ath_softc *sc)
  812. {
  813. int i = 0;
  814. ath9k_deinit_btcoex(sc);
  815. for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++)
  816. if (ATH_TXQ_SETUP(sc, i))
  817. ath_tx_cleanupq(sc, &sc->tx.txq[i]);
  818. ath9k_hw_deinit(sc->sc_ah);
  819. if (sc->dfs_detector != NULL)
  820. sc->dfs_detector->exit(sc->dfs_detector);
  821. ath9k_eeprom_release(sc);
  822. }
  823. void ath9k_deinit_device(struct ath_softc *sc)
  824. {
  825. struct ieee80211_hw *hw = sc->hw;
  826. ath9k_ps_wakeup(sc);
  827. wiphy_rfkill_stop_polling(sc->hw->wiphy);
  828. ath_deinit_leds(sc);
  829. ath9k_ps_restore(sc);
  830. ath9k_deinit_debug(sc);
  831. ieee80211_unregister_hw(hw);
  832. ath_rx_cleanup(sc);
  833. ath9k_deinit_softc(sc);
  834. }
  835. /************************/
  836. /* Module Hooks */
  837. /************************/
  838. static int __init ath9k_init(void)
  839. {
  840. int error;
  841. /* Register rate control algorithm */
  842. error = ath_rate_control_register();
  843. if (error != 0) {
  844. pr_err("Unable to register rate control algorithm: %d\n",
  845. error);
  846. goto err_out;
  847. }
  848. error = ath_pci_init();
  849. if (error < 0) {
  850. pr_err("No PCI devices found, driver not installed\n");
  851. error = -ENODEV;
  852. goto err_rate_unregister;
  853. }
  854. error = ath_ahb_init();
  855. if (error < 0) {
  856. error = -ENODEV;
  857. goto err_pci_exit;
  858. }
  859. return 0;
  860. err_pci_exit:
  861. ath_pci_exit();
  862. err_rate_unregister:
  863. ath_rate_control_unregister();
  864. err_out:
  865. return error;
  866. }
  867. module_init(ath9k_init);
  868. static void __exit ath9k_exit(void)
  869. {
  870. is_ath9k_unloaded = true;
  871. ath_ahb_exit();
  872. ath_pci_exit();
  873. ath_rate_control_unregister();
  874. pr_info("%s: Driver unloaded\n", dev_info);
  875. }
  876. module_exit(ath9k_exit);