init.c 23 KB

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