init.c 24 KB

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