init.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897
  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_wiphy *aphy = hw->priv;
  217. struct ath_softc *sc = aphy->sc;
  218. struct ath_regulatory *reg = ath9k_hw_regulatory(sc->sc_ah);
  219. return ath_reg_notifier_apply(wiphy, request, reg);
  220. }
  221. /*
  222. * This function will allocate both the DMA descriptor structure, and the
  223. * buffers it contains. These are used to contain the descriptors used
  224. * by the system.
  225. */
  226. int ath_descdma_setup(struct ath_softc *sc, struct ath_descdma *dd,
  227. struct list_head *head, const char *name,
  228. int nbuf, int ndesc, bool is_tx)
  229. {
  230. #define DS2PHYS(_dd, _ds) \
  231. ((_dd)->dd_desc_paddr + ((caddr_t)(_ds) - (caddr_t)(_dd)->dd_desc))
  232. #define ATH_DESC_4KB_BOUND_CHECK(_daddr) ((((_daddr) & 0xFFF) > 0xF7F) ? 1 : 0)
  233. #define ATH_DESC_4KB_BOUND_NUM_SKIPPED(_len) ((_len) / 4096)
  234. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  235. u8 *ds;
  236. struct ath_buf *bf;
  237. int i, bsize, error, desc_len;
  238. ath_dbg(common, ATH_DBG_CONFIG, "%s DMA: %u buffers %u desc/buf\n",
  239. name, nbuf, ndesc);
  240. INIT_LIST_HEAD(head);
  241. if (is_tx)
  242. desc_len = sc->sc_ah->caps.tx_desc_len;
  243. else
  244. desc_len = sizeof(struct ath_desc);
  245. /* ath_desc must be a multiple of DWORDs */
  246. if ((desc_len % 4) != 0) {
  247. ath_err(common, "ath_desc not DWORD aligned\n");
  248. BUG_ON((desc_len % 4) != 0);
  249. error = -ENOMEM;
  250. goto fail;
  251. }
  252. dd->dd_desc_len = desc_len * nbuf * ndesc;
  253. /*
  254. * Need additional DMA memory because we can't use
  255. * descriptors that cross the 4K page boundary. Assume
  256. * one skipped descriptor per 4K page.
  257. */
  258. if (!(sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_4KB_SPLITTRANS)) {
  259. u32 ndesc_skipped =
  260. ATH_DESC_4KB_BOUND_NUM_SKIPPED(dd->dd_desc_len);
  261. u32 dma_len;
  262. while (ndesc_skipped) {
  263. dma_len = ndesc_skipped * desc_len;
  264. dd->dd_desc_len += dma_len;
  265. ndesc_skipped = ATH_DESC_4KB_BOUND_NUM_SKIPPED(dma_len);
  266. }
  267. }
  268. /* allocate descriptors */
  269. dd->dd_desc = dma_alloc_coherent(sc->dev, dd->dd_desc_len,
  270. &dd->dd_desc_paddr, GFP_KERNEL);
  271. if (dd->dd_desc == NULL) {
  272. error = -ENOMEM;
  273. goto fail;
  274. }
  275. ds = (u8 *) dd->dd_desc;
  276. ath_dbg(common, ATH_DBG_CONFIG, "%s DMA map: %p (%u) -> %llx (%u)\n",
  277. name, ds, (u32) dd->dd_desc_len,
  278. ito64(dd->dd_desc_paddr), /*XXX*/(u32) dd->dd_desc_len);
  279. /* allocate buffers */
  280. bsize = sizeof(struct ath_buf) * nbuf;
  281. bf = kzalloc(bsize, GFP_KERNEL);
  282. if (bf == NULL) {
  283. error = -ENOMEM;
  284. goto fail2;
  285. }
  286. dd->dd_bufptr = bf;
  287. for (i = 0; i < nbuf; i++, bf++, ds += (desc_len * ndesc)) {
  288. bf->bf_desc = ds;
  289. bf->bf_daddr = DS2PHYS(dd, ds);
  290. if (!(sc->sc_ah->caps.hw_caps &
  291. ATH9K_HW_CAP_4KB_SPLITTRANS)) {
  292. /*
  293. * Skip descriptor addresses which can cause 4KB
  294. * boundary crossing (addr + length) with a 32 dword
  295. * descriptor fetch.
  296. */
  297. while (ATH_DESC_4KB_BOUND_CHECK(bf->bf_daddr)) {
  298. BUG_ON((caddr_t) bf->bf_desc >=
  299. ((caddr_t) dd->dd_desc +
  300. dd->dd_desc_len));
  301. ds += (desc_len * ndesc);
  302. bf->bf_desc = ds;
  303. bf->bf_daddr = DS2PHYS(dd, ds);
  304. }
  305. }
  306. list_add_tail(&bf->list, head);
  307. }
  308. return 0;
  309. fail2:
  310. dma_free_coherent(sc->dev, dd->dd_desc_len, dd->dd_desc,
  311. dd->dd_desc_paddr);
  312. fail:
  313. memset(dd, 0, sizeof(*dd));
  314. return error;
  315. #undef ATH_DESC_4KB_BOUND_CHECK
  316. #undef ATH_DESC_4KB_BOUND_NUM_SKIPPED
  317. #undef DS2PHYS
  318. }
  319. void ath9k_init_crypto(struct ath_softc *sc)
  320. {
  321. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  322. int i = 0;
  323. /* Get the hardware key cache size. */
  324. common->keymax = sc->sc_ah->caps.keycache_size;
  325. if (common->keymax > ATH_KEYMAX) {
  326. ath_dbg(common, ATH_DBG_ANY,
  327. "Warning, using only %u entries in %u key cache\n",
  328. ATH_KEYMAX, common->keymax);
  329. common->keymax = ATH_KEYMAX;
  330. }
  331. /*
  332. * Reset the key cache since some parts do not
  333. * reset the contents on initial power up.
  334. */
  335. for (i = 0; i < common->keymax; i++)
  336. ath_hw_keyreset(common, (u16) i);
  337. /*
  338. * Check whether the separate key cache entries
  339. * are required to handle both tx+rx MIC keys.
  340. * With split mic keys the number of stations is limited
  341. * to 27 otherwise 59.
  342. */
  343. if (sc->sc_ah->misc_mode & AR_PCU_MIC_NEW_LOC_ENA)
  344. common->crypt_caps |= ATH_CRYPT_CAP_MIC_COMBINED;
  345. }
  346. static int ath9k_init_btcoex(struct ath_softc *sc)
  347. {
  348. struct ath_txq *txq;
  349. int r;
  350. switch (sc->sc_ah->btcoex_hw.scheme) {
  351. case ATH_BTCOEX_CFG_NONE:
  352. break;
  353. case ATH_BTCOEX_CFG_2WIRE:
  354. ath9k_hw_btcoex_init_2wire(sc->sc_ah);
  355. break;
  356. case ATH_BTCOEX_CFG_3WIRE:
  357. ath9k_hw_btcoex_init_3wire(sc->sc_ah);
  358. r = ath_init_btcoex_timer(sc);
  359. if (r)
  360. return -1;
  361. txq = sc->tx.txq_map[WME_AC_BE];
  362. ath9k_hw_init_btcoex_hw(sc->sc_ah, txq->axq_qnum);
  363. sc->btcoex.bt_stomp_type = ATH_BTCOEX_STOMP_LOW;
  364. break;
  365. default:
  366. WARN_ON(1);
  367. break;
  368. }
  369. return 0;
  370. }
  371. static int ath9k_init_queues(struct ath_softc *sc)
  372. {
  373. int i = 0;
  374. sc->beacon.beaconq = ath9k_hw_beaconq_setup(sc->sc_ah);
  375. sc->beacon.cabq = ath_txq_setup(sc, ATH9K_TX_QUEUE_CAB, 0);
  376. sc->config.cabqReadytime = ATH_CABQ_READY_TIME;
  377. ath_cabq_update(sc);
  378. for (i = 0; i < WME_NUM_AC; i++)
  379. sc->tx.txq_map[i] = ath_txq_setup(sc, ATH9K_TX_QUEUE_DATA, i);
  380. return 0;
  381. }
  382. static int ath9k_init_channels_rates(struct ath_softc *sc)
  383. {
  384. void *channels;
  385. BUILD_BUG_ON(ARRAY_SIZE(ath9k_2ghz_chantable) +
  386. ARRAY_SIZE(ath9k_5ghz_chantable) !=
  387. ATH9K_NUM_CHANNELS);
  388. if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_2GHZ) {
  389. channels = kmemdup(ath9k_2ghz_chantable,
  390. sizeof(ath9k_2ghz_chantable), GFP_KERNEL);
  391. if (!channels)
  392. return -ENOMEM;
  393. sc->sbands[IEEE80211_BAND_2GHZ].channels = channels;
  394. sc->sbands[IEEE80211_BAND_2GHZ].band = IEEE80211_BAND_2GHZ;
  395. sc->sbands[IEEE80211_BAND_2GHZ].n_channels =
  396. ARRAY_SIZE(ath9k_2ghz_chantable);
  397. sc->sbands[IEEE80211_BAND_2GHZ].bitrates = ath9k_legacy_rates;
  398. sc->sbands[IEEE80211_BAND_2GHZ].n_bitrates =
  399. ARRAY_SIZE(ath9k_legacy_rates);
  400. }
  401. if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_5GHZ) {
  402. channels = kmemdup(ath9k_5ghz_chantable,
  403. sizeof(ath9k_5ghz_chantable), GFP_KERNEL);
  404. if (!channels) {
  405. if (sc->sbands[IEEE80211_BAND_2GHZ].channels)
  406. kfree(sc->sbands[IEEE80211_BAND_2GHZ].channels);
  407. return -ENOMEM;
  408. }
  409. sc->sbands[IEEE80211_BAND_5GHZ].channels = channels;
  410. sc->sbands[IEEE80211_BAND_5GHZ].band = IEEE80211_BAND_5GHZ;
  411. sc->sbands[IEEE80211_BAND_5GHZ].n_channels =
  412. ARRAY_SIZE(ath9k_5ghz_chantable);
  413. sc->sbands[IEEE80211_BAND_5GHZ].bitrates =
  414. ath9k_legacy_rates + 4;
  415. sc->sbands[IEEE80211_BAND_5GHZ].n_bitrates =
  416. ARRAY_SIZE(ath9k_legacy_rates) - 4;
  417. }
  418. return 0;
  419. }
  420. static void ath9k_init_misc(struct ath_softc *sc)
  421. {
  422. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  423. int i = 0;
  424. setup_timer(&common->ani.timer, ath_ani_calibrate, (unsigned long)sc);
  425. sc->config.txpowlimit = ATH_TXPOWER_MAX;
  426. if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_HT) {
  427. sc->sc_flags |= SC_OP_TXAGGR;
  428. sc->sc_flags |= SC_OP_RXAGGR;
  429. }
  430. common->tx_chainmask = sc->sc_ah->caps.tx_chainmask;
  431. common->rx_chainmask = sc->sc_ah->caps.rx_chainmask;
  432. ath9k_hw_set_diversity(sc->sc_ah, true);
  433. sc->rx.defant = ath9k_hw_getdefantenna(sc->sc_ah);
  434. memcpy(common->bssidmask, ath_bcast_mac, ETH_ALEN);
  435. sc->beacon.slottime = ATH9K_SLOT_TIME_9;
  436. for (i = 0; i < ARRAY_SIZE(sc->beacon.bslot); i++) {
  437. sc->beacon.bslot[i] = NULL;
  438. sc->beacon.bslot_aphy[i] = NULL;
  439. }
  440. if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_ANT_DIV_COMB)
  441. sc->ant_comb.count = ATH_ANT_DIV_COMB_INIT_COUNT;
  442. }
  443. static int ath9k_init_softc(u16 devid, struct ath_softc *sc, u16 subsysid,
  444. const struct ath_bus_ops *bus_ops)
  445. {
  446. struct ath_hw *ah = NULL;
  447. struct ath_common *common;
  448. int ret = 0, i;
  449. int csz = 0;
  450. ah = kzalloc(sizeof(struct ath_hw), GFP_KERNEL);
  451. if (!ah)
  452. return -ENOMEM;
  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->wiphy_lock);
  468. spin_lock_init(&sc->sc_serial_rw);
  469. spin_lock_init(&sc->sc_pm_lock);
  470. mutex_init(&sc->mutex);
  471. tasklet_init(&sc->intr_tq, ath9k_tasklet, (unsigned long)sc);
  472. tasklet_init(&sc->bcon_tasklet, ath_beacon_tasklet,
  473. (unsigned long)sc);
  474. /*
  475. * Cache line size is used to size and align various
  476. * structures used to communicate with the hardware.
  477. */
  478. ath_read_cachesize(common, &csz);
  479. common->cachelsz = csz << 2; /* convert to bytes */
  480. /* Initializes the hardware for all supported chipsets */
  481. ret = ath9k_hw_init(ah);
  482. if (ret)
  483. goto err_hw;
  484. ret = ath9k_init_queues(sc);
  485. if (ret)
  486. goto err_queues;
  487. ret = ath9k_init_btcoex(sc);
  488. if (ret)
  489. goto err_btcoex;
  490. ret = ath9k_init_channels_rates(sc);
  491. if (ret)
  492. goto err_btcoex;
  493. ath9k_init_crypto(sc);
  494. ath9k_init_misc(sc);
  495. return 0;
  496. err_btcoex:
  497. for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++)
  498. if (ATH_TXQ_SETUP(sc, i))
  499. ath_tx_cleanupq(sc, &sc->tx.txq[i]);
  500. err_queues:
  501. ath9k_hw_deinit(ah);
  502. err_hw:
  503. kfree(ah);
  504. sc->sc_ah = NULL;
  505. return ret;
  506. }
  507. static void ath9k_init_band_txpower(struct ath_softc *sc, int band)
  508. {
  509. struct ieee80211_supported_band *sband;
  510. struct ieee80211_channel *chan;
  511. struct ath_hw *ah = sc->sc_ah;
  512. struct ath_regulatory *reg = ath9k_hw_regulatory(ah);
  513. int i;
  514. sband = &sc->sbands[band];
  515. for (i = 0; i < sband->n_channels; i++) {
  516. chan = &sband->channels[i];
  517. ah->curchan = &ah->channels[chan->hw_value];
  518. ath9k_cmn_update_ichannel(ah->curchan, chan, NL80211_CHAN_HT20);
  519. ath9k_hw_set_txpowerlimit(ah, MAX_RATE_POWER, true);
  520. chan->max_power = reg->max_power_level / 2;
  521. }
  522. }
  523. static void ath9k_init_txpower_limits(struct ath_softc *sc)
  524. {
  525. struct ath_hw *ah = sc->sc_ah;
  526. struct ath9k_channel *curchan = ah->curchan;
  527. if (ah->caps.hw_caps & ATH9K_HW_CAP_2GHZ)
  528. ath9k_init_band_txpower(sc, IEEE80211_BAND_2GHZ);
  529. if (ah->caps.hw_caps & ATH9K_HW_CAP_5GHZ)
  530. ath9k_init_band_txpower(sc, IEEE80211_BAND_5GHZ);
  531. ah->curchan = curchan;
  532. }
  533. void ath9k_set_hw_capab(struct ath_softc *sc, struct ieee80211_hw *hw)
  534. {
  535. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  536. hw->flags = IEEE80211_HW_RX_INCLUDES_FCS |
  537. IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING |
  538. IEEE80211_HW_SIGNAL_DBM |
  539. IEEE80211_HW_SUPPORTS_PS |
  540. IEEE80211_HW_PS_NULLFUNC_STACK |
  541. IEEE80211_HW_SPECTRUM_MGMT |
  542. IEEE80211_HW_REPORTS_TX_ACK_STATUS;
  543. if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_HT)
  544. hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION;
  545. if (AR_SREV_9160_10_OR_LATER(sc->sc_ah) || ath9k_modparam_nohwcrypt)
  546. hw->flags |= IEEE80211_HW_MFP_CAPABLE;
  547. hw->wiphy->interface_modes =
  548. BIT(NL80211_IFTYPE_P2P_GO) |
  549. BIT(NL80211_IFTYPE_P2P_CLIENT) |
  550. BIT(NL80211_IFTYPE_AP) |
  551. BIT(NL80211_IFTYPE_WDS) |
  552. BIT(NL80211_IFTYPE_STATION) |
  553. BIT(NL80211_IFTYPE_ADHOC) |
  554. BIT(NL80211_IFTYPE_MESH_POINT);
  555. if (AR_SREV_5416(sc->sc_ah))
  556. hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
  557. hw->queues = 4;
  558. hw->max_rates = 4;
  559. hw->channel_change_time = 5000;
  560. hw->max_listen_interval = 10;
  561. hw->max_rate_tries = 10;
  562. hw->sta_data_size = sizeof(struct ath_node);
  563. hw->vif_data_size = sizeof(struct ath_vif);
  564. #ifdef CONFIG_ATH9K_RATE_CONTROL
  565. hw->rate_control_algorithm = "ath9k_rate_control";
  566. #endif
  567. if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_2GHZ)
  568. hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
  569. &sc->sbands[IEEE80211_BAND_2GHZ];
  570. if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_5GHZ)
  571. hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
  572. &sc->sbands[IEEE80211_BAND_5GHZ];
  573. if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_HT) {
  574. if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_2GHZ)
  575. setup_ht_cap(sc, &sc->sbands[IEEE80211_BAND_2GHZ].ht_cap);
  576. if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_5GHZ)
  577. setup_ht_cap(sc, &sc->sbands[IEEE80211_BAND_5GHZ].ht_cap);
  578. }
  579. SET_IEEE80211_PERM_ADDR(hw, common->macaddr);
  580. }
  581. int ath9k_init_device(u16 devid, struct ath_softc *sc, u16 subsysid,
  582. const struct ath_bus_ops *bus_ops)
  583. {
  584. struct ieee80211_hw *hw = sc->hw;
  585. struct ath_wiphy *aphy = hw->priv;
  586. struct ath_common *common;
  587. struct ath_hw *ah;
  588. int error = 0;
  589. struct ath_regulatory *reg;
  590. /* Bring up device */
  591. error = ath9k_init_softc(devid, sc, subsysid, bus_ops);
  592. if (error != 0)
  593. goto error_init;
  594. ah = sc->sc_ah;
  595. common = ath9k_hw_common(ah);
  596. ath9k_set_hw_capab(sc, hw);
  597. /* Initialize regulatory */
  598. error = ath_regd_init(&common->regulatory, sc->hw->wiphy,
  599. ath9k_reg_notifier);
  600. if (error)
  601. goto error_regd;
  602. reg = &common->regulatory;
  603. /* Setup TX DMA */
  604. error = ath_tx_init(sc, ATH_TXBUF);
  605. if (error != 0)
  606. goto error_tx;
  607. /* Setup RX DMA */
  608. error = ath_rx_init(sc, ATH_RXBUF);
  609. if (error != 0)
  610. goto error_rx;
  611. ath9k_init_txpower_limits(sc);
  612. /* Register with mac80211 */
  613. error = ieee80211_register_hw(hw);
  614. if (error)
  615. goto error_register;
  616. error = ath9k_init_debug(ah);
  617. if (error) {
  618. ath_err(common, "Unable to create debugfs files\n");
  619. goto error_world;
  620. }
  621. /* Handle world regulatory */
  622. if (!ath_is_world_regd(reg)) {
  623. error = regulatory_hint(hw->wiphy, reg->alpha2);
  624. if (error)
  625. goto error_world;
  626. }
  627. INIT_WORK(&sc->hw_check_work, ath_hw_check);
  628. INIT_WORK(&sc->paprd_work, ath_paprd_calibrate);
  629. INIT_WORK(&sc->chan_work, ath9k_wiphy_chan_work);
  630. INIT_DELAYED_WORK(&sc->wiphy_work, ath9k_wiphy_work);
  631. sc->wiphy_scheduler_int = msecs_to_jiffies(500);
  632. aphy->last_rssi = ATH_RSSI_DUMMY_MARKER;
  633. ath_init_leds(sc);
  634. ath_start_rfkill_poll(sc);
  635. return 0;
  636. error_world:
  637. ieee80211_unregister_hw(hw);
  638. error_register:
  639. ath_rx_cleanup(sc);
  640. error_rx:
  641. ath_tx_cleanup(sc);
  642. error_tx:
  643. /* Nothing */
  644. error_regd:
  645. ath9k_deinit_softc(sc);
  646. error_init:
  647. return error;
  648. }
  649. /*****************************/
  650. /* De-Initialization */
  651. /*****************************/
  652. static void ath9k_deinit_softc(struct ath_softc *sc)
  653. {
  654. int i = 0;
  655. if (sc->sbands[IEEE80211_BAND_2GHZ].channels)
  656. kfree(sc->sbands[IEEE80211_BAND_2GHZ].channels);
  657. if (sc->sbands[IEEE80211_BAND_5GHZ].channels)
  658. kfree(sc->sbands[IEEE80211_BAND_5GHZ].channels);
  659. if ((sc->btcoex.no_stomp_timer) &&
  660. sc->sc_ah->btcoex_hw.scheme == ATH_BTCOEX_CFG_3WIRE)
  661. ath_gen_timer_free(sc->sc_ah, sc->btcoex.no_stomp_timer);
  662. for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++)
  663. if (ATH_TXQ_SETUP(sc, i))
  664. ath_tx_cleanupq(sc, &sc->tx.txq[i]);
  665. ath9k_hw_deinit(sc->sc_ah);
  666. kfree(sc->sc_ah);
  667. sc->sc_ah = NULL;
  668. }
  669. void ath9k_deinit_device(struct ath_softc *sc)
  670. {
  671. struct ieee80211_hw *hw = sc->hw;
  672. int i = 0;
  673. ath9k_ps_wakeup(sc);
  674. wiphy_rfkill_stop_polling(sc->hw->wiphy);
  675. ath_deinit_leds(sc);
  676. ath9k_ps_restore(sc);
  677. for (i = 0; i < sc->num_sec_wiphy; i++) {
  678. struct ath_wiphy *aphy = sc->sec_wiphy[i];
  679. if (aphy == NULL)
  680. continue;
  681. sc->sec_wiphy[i] = NULL;
  682. ieee80211_unregister_hw(aphy->hw);
  683. ieee80211_free_hw(aphy->hw);
  684. }
  685. ieee80211_unregister_hw(hw);
  686. ath_rx_cleanup(sc);
  687. ath_tx_cleanup(sc);
  688. ath9k_deinit_softc(sc);
  689. kfree(sc->sec_wiphy);
  690. }
  691. void ath_descdma_cleanup(struct ath_softc *sc,
  692. struct ath_descdma *dd,
  693. struct list_head *head)
  694. {
  695. dma_free_coherent(sc->dev, dd->dd_desc_len, dd->dd_desc,
  696. dd->dd_desc_paddr);
  697. INIT_LIST_HEAD(head);
  698. kfree(dd->dd_bufptr);
  699. memset(dd, 0, sizeof(*dd));
  700. }
  701. /************************/
  702. /* Module Hooks */
  703. /************************/
  704. static int __init ath9k_init(void)
  705. {
  706. int error;
  707. /* Register rate control algorithm */
  708. error = ath_rate_control_register();
  709. if (error != 0) {
  710. printk(KERN_ERR
  711. "ath9k: Unable to register rate control "
  712. "algorithm: %d\n",
  713. error);
  714. goto err_out;
  715. }
  716. error = ath_pci_init();
  717. if (error < 0) {
  718. printk(KERN_ERR
  719. "ath9k: No PCI devices found, driver not installed.\n");
  720. error = -ENODEV;
  721. goto err_rate_unregister;
  722. }
  723. error = ath_ahb_init();
  724. if (error < 0) {
  725. error = -ENODEV;
  726. goto err_pci_exit;
  727. }
  728. return 0;
  729. err_pci_exit:
  730. ath_pci_exit();
  731. err_rate_unregister:
  732. ath_rate_control_unregister();
  733. err_out:
  734. return error;
  735. }
  736. module_init(ath9k_init);
  737. static void __exit ath9k_exit(void)
  738. {
  739. is_ath9k_unloaded = true;
  740. ath_ahb_exit();
  741. ath_pci_exit();
  742. ath_rate_control_unregister();
  743. printk(KERN_INFO "%s: Driver unloaded\n", dev_info);
  744. }
  745. module_exit(ath9k_exit);