init.c 26 KB

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