init.c 25 KB

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