init.c 25 KB

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