init.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900
  1. /*
  2. * Copyright (c) 2008-2009 Atheros Communications Inc.
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for any
  5. * purpose with or without fee is hereby granted, provided that the above
  6. * copyright notice and this permission notice appear in all copies.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  11. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  13. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  14. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #include <linux/slab.h>
  17. #include "ath9k.h"
  18. static char *dev_info = "ath9k";
  19. MODULE_AUTHOR("Atheros Communications");
  20. MODULE_DESCRIPTION("Support for Atheros 802.11n wireless LAN cards.");
  21. MODULE_SUPPORTED_DEVICE("Atheros 802.11n WLAN cards");
  22. MODULE_LICENSE("Dual BSD/GPL");
  23. static unsigned int ath9k_debug = ATH_DBG_DEFAULT;
  24. module_param_named(debug, ath9k_debug, uint, 0);
  25. MODULE_PARM_DESC(debug, "Debugging mask");
  26. int modparam_nohwcrypt;
  27. module_param_named(nohwcrypt, modparam_nohwcrypt, int, 0444);
  28. MODULE_PARM_DESC(nohwcrypt, "Disable hardware encryption");
  29. /* We use the hw_value as an index into our private channel structure */
  30. #define CHAN2G(_freq, _idx) { \
  31. .center_freq = (_freq), \
  32. .hw_value = (_idx), \
  33. .max_power = 20, \
  34. }
  35. #define CHAN5G(_freq, _idx) { \
  36. .band = IEEE80211_BAND_5GHZ, \
  37. .center_freq = (_freq), \
  38. .hw_value = (_idx), \
  39. .max_power = 20, \
  40. }
  41. /* Some 2 GHz radios are actually tunable on 2312-2732
  42. * on 5 MHz steps, we support the channels which we know
  43. * we have calibration data for all cards though to make
  44. * this static */
  45. static struct ieee80211_channel ath9k_2ghz_chantable[] = {
  46. CHAN2G(2412, 0), /* Channel 1 */
  47. CHAN2G(2417, 1), /* Channel 2 */
  48. CHAN2G(2422, 2), /* Channel 3 */
  49. CHAN2G(2427, 3), /* Channel 4 */
  50. CHAN2G(2432, 4), /* Channel 5 */
  51. CHAN2G(2437, 5), /* Channel 6 */
  52. CHAN2G(2442, 6), /* Channel 7 */
  53. CHAN2G(2447, 7), /* Channel 8 */
  54. CHAN2G(2452, 8), /* Channel 9 */
  55. CHAN2G(2457, 9), /* Channel 10 */
  56. CHAN2G(2462, 10), /* Channel 11 */
  57. CHAN2G(2467, 11), /* Channel 12 */
  58. CHAN2G(2472, 12), /* Channel 13 */
  59. CHAN2G(2484, 13), /* Channel 14 */
  60. };
  61. /* Some 5 GHz radios are actually tunable on XXXX-YYYY
  62. * on 5 MHz steps, we support the channels which we know
  63. * we have calibration data for all cards though to make
  64. * this static */
  65. static struct ieee80211_channel ath9k_5ghz_chantable[] = {
  66. /* _We_ call this UNII 1 */
  67. CHAN5G(5180, 14), /* Channel 36 */
  68. CHAN5G(5200, 15), /* Channel 40 */
  69. CHAN5G(5220, 16), /* Channel 44 */
  70. CHAN5G(5240, 17), /* Channel 48 */
  71. /* _We_ call this UNII 2 */
  72. CHAN5G(5260, 18), /* Channel 52 */
  73. CHAN5G(5280, 19), /* Channel 56 */
  74. CHAN5G(5300, 20), /* Channel 60 */
  75. CHAN5G(5320, 21), /* Channel 64 */
  76. /* _We_ call this "Middle band" */
  77. CHAN5G(5500, 22), /* Channel 100 */
  78. CHAN5G(5520, 23), /* Channel 104 */
  79. CHAN5G(5540, 24), /* Channel 108 */
  80. CHAN5G(5560, 25), /* Channel 112 */
  81. CHAN5G(5580, 26), /* Channel 116 */
  82. CHAN5G(5600, 27), /* Channel 120 */
  83. CHAN5G(5620, 28), /* Channel 124 */
  84. CHAN5G(5640, 29), /* Channel 128 */
  85. CHAN5G(5660, 30), /* Channel 132 */
  86. CHAN5G(5680, 31), /* Channel 136 */
  87. CHAN5G(5700, 32), /* Channel 140 */
  88. /* _We_ call this UNII 3 */
  89. CHAN5G(5745, 33), /* Channel 149 */
  90. CHAN5G(5765, 34), /* Channel 153 */
  91. CHAN5G(5785, 35), /* Channel 157 */
  92. CHAN5G(5805, 36), /* Channel 161 */
  93. CHAN5G(5825, 37), /* Channel 165 */
  94. };
  95. /* Atheros hardware rate code addition for short premble */
  96. #define SHPCHECK(__hw_rate, __flags) \
  97. ((__flags & IEEE80211_RATE_SHORT_PREAMBLE) ? (__hw_rate | 0x04 ) : 0)
  98. #define RATE(_bitrate, _hw_rate, _flags) { \
  99. .bitrate = (_bitrate), \
  100. .flags = (_flags), \
  101. .hw_value = (_hw_rate), \
  102. .hw_value_short = (SHPCHECK(_hw_rate, _flags)) \
  103. }
  104. static struct ieee80211_rate ath9k_legacy_rates[] = {
  105. RATE(10, 0x1b, 0),
  106. RATE(20, 0x1a, IEEE80211_RATE_SHORT_PREAMBLE),
  107. RATE(55, 0x19, IEEE80211_RATE_SHORT_PREAMBLE),
  108. RATE(110, 0x18, IEEE80211_RATE_SHORT_PREAMBLE),
  109. RATE(60, 0x0b, 0),
  110. RATE(90, 0x0f, 0),
  111. RATE(120, 0x0a, 0),
  112. RATE(180, 0x0e, 0),
  113. RATE(240, 0x09, 0),
  114. RATE(360, 0x0d, 0),
  115. RATE(480, 0x08, 0),
  116. RATE(540, 0x0c, 0),
  117. };
  118. static void ath9k_deinit_softc(struct ath_softc *sc);
  119. /*
  120. * Read and write, they both share the same lock. We do this to serialize
  121. * reads and writes on Atheros 802.11n PCI devices only. This is required
  122. * as the FIFO on these devices can only accept sanely 2 requests.
  123. */
  124. static void ath9k_iowrite32(void *hw_priv, u32 val, u32 reg_offset)
  125. {
  126. struct ath_hw *ah = (struct ath_hw *) hw_priv;
  127. struct ath_common *common = ath9k_hw_common(ah);
  128. struct ath_softc *sc = (struct ath_softc *) common->priv;
  129. if (ah->config.serialize_regmode == SER_REG_MODE_ON) {
  130. unsigned long flags;
  131. spin_lock_irqsave(&sc->sc_serial_rw, flags);
  132. iowrite32(val, sc->mem + reg_offset);
  133. spin_unlock_irqrestore(&sc->sc_serial_rw, flags);
  134. } else
  135. iowrite32(val, sc->mem + reg_offset);
  136. }
  137. static unsigned int ath9k_ioread32(void *hw_priv, u32 reg_offset)
  138. {
  139. struct ath_hw *ah = (struct ath_hw *) hw_priv;
  140. struct ath_common *common = ath9k_hw_common(ah);
  141. struct ath_softc *sc = (struct ath_softc *) common->priv;
  142. u32 val;
  143. if (ah->config.serialize_regmode == SER_REG_MODE_ON) {
  144. unsigned long flags;
  145. spin_lock_irqsave(&sc->sc_serial_rw, flags);
  146. val = ioread32(sc->mem + reg_offset);
  147. spin_unlock_irqrestore(&sc->sc_serial_rw, flags);
  148. } else
  149. val = ioread32(sc->mem + reg_offset);
  150. return val;
  151. }
  152. static const struct ath_ops ath9k_common_ops = {
  153. .read = ath9k_ioread32,
  154. .write = ath9k_iowrite32,
  155. };
  156. static int count_streams(unsigned int chainmask, int max)
  157. {
  158. int streams = 0;
  159. do {
  160. if (++streams == max)
  161. break;
  162. } while ((chainmask = chainmask & (chainmask - 1)));
  163. return streams;
  164. }
  165. /**************************/
  166. /* Initialization */
  167. /**************************/
  168. static void setup_ht_cap(struct ath_softc *sc,
  169. struct ieee80211_sta_ht_cap *ht_info)
  170. {
  171. struct ath_hw *ah = sc->sc_ah;
  172. struct ath_common *common = ath9k_hw_common(ah);
  173. u8 tx_streams, rx_streams;
  174. int i, max_streams;
  175. ht_info->ht_supported = true;
  176. ht_info->cap = IEEE80211_HT_CAP_SUP_WIDTH_20_40 |
  177. IEEE80211_HT_CAP_SM_PS |
  178. IEEE80211_HT_CAP_SGI_40 |
  179. IEEE80211_HT_CAP_DSSSCCK40;
  180. if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_LDPC)
  181. ht_info->cap |= IEEE80211_HT_CAP_LDPC_CODING;
  182. if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_SGI_20)
  183. ht_info->cap |= IEEE80211_HT_CAP_SGI_20;
  184. ht_info->ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
  185. ht_info->ampdu_density = IEEE80211_HT_MPDU_DENSITY_8;
  186. if (AR_SREV_9300_20_OR_LATER(ah))
  187. max_streams = 3;
  188. else
  189. max_streams = 2;
  190. if (AR_SREV_9280_10_OR_LATER(ah)) {
  191. if (max_streams >= 2)
  192. ht_info->cap |= IEEE80211_HT_CAP_TX_STBC;
  193. ht_info->cap |= (1 << IEEE80211_HT_CAP_RX_STBC_SHIFT);
  194. }
  195. /* set up supported mcs set */
  196. memset(&ht_info->mcs, 0, sizeof(ht_info->mcs));
  197. tx_streams = count_streams(common->tx_chainmask, max_streams);
  198. rx_streams = count_streams(common->rx_chainmask, max_streams);
  199. ath_print(common, ATH_DBG_CONFIG,
  200. "TX streams %d, RX streams: %d\n",
  201. tx_streams, rx_streams);
  202. if (tx_streams != rx_streams) {
  203. ht_info->mcs.tx_params |= IEEE80211_HT_MCS_TX_RX_DIFF;
  204. ht_info->mcs.tx_params |= ((tx_streams - 1) <<
  205. IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT);
  206. }
  207. for (i = 0; i < rx_streams; i++)
  208. ht_info->mcs.rx_mask[i] = 0xff;
  209. ht_info->mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
  210. }
  211. static int ath9k_reg_notifier(struct wiphy *wiphy,
  212. struct regulatory_request *request)
  213. {
  214. struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
  215. struct ath_wiphy *aphy = hw->priv;
  216. struct ath_softc *sc = aphy->sc;
  217. struct ath_regulatory *reg = ath9k_hw_regulatory(sc->sc_ah);
  218. return ath_reg_notifier_apply(wiphy, request, reg);
  219. }
  220. /*
  221. * This function will allocate both the DMA descriptor structure, and the
  222. * buffers it contains. These are used to contain the descriptors used
  223. * by the system.
  224. */
  225. int ath_descdma_setup(struct ath_softc *sc, struct ath_descdma *dd,
  226. struct list_head *head, const char *name,
  227. int nbuf, int ndesc, bool is_tx)
  228. {
  229. #define DS2PHYS(_dd, _ds) \
  230. ((_dd)->dd_desc_paddr + ((caddr_t)(_ds) - (caddr_t)(_dd)->dd_desc))
  231. #define ATH_DESC_4KB_BOUND_CHECK(_daddr) ((((_daddr) & 0xFFF) > 0xF7F) ? 1 : 0)
  232. #define ATH_DESC_4KB_BOUND_NUM_SKIPPED(_len) ((_len) / 4096)
  233. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  234. u8 *ds;
  235. struct ath_buf *bf;
  236. int i, bsize, error, desc_len;
  237. ath_print(common, ATH_DBG_CONFIG, "%s DMA: %u buffers %u desc/buf\n",
  238. name, nbuf, ndesc);
  239. INIT_LIST_HEAD(head);
  240. if (is_tx)
  241. desc_len = sc->sc_ah->caps.tx_desc_len;
  242. else
  243. desc_len = sizeof(struct ath_desc);
  244. /* ath_desc must be a multiple of DWORDs */
  245. if ((desc_len % 4) != 0) {
  246. ath_print(common, ATH_DBG_FATAL,
  247. "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_print(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. static 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_print(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. ath9k_hw_keyreset(sc->sc_ah, (u16) i);
  337. if (ath9k_hw_getcapability(sc->sc_ah, ATH9K_CAP_CIPHER,
  338. ATH9K_CIPHER_TKIP, NULL)) {
  339. /*
  340. * Whether we should enable h/w TKIP MIC.
  341. * XXX: if we don't support WME TKIP MIC, then we wouldn't
  342. * report WMM capable, so it's always safe to turn on
  343. * TKIP MIC in this case.
  344. */
  345. ath9k_hw_setcapability(sc->sc_ah, ATH9K_CAP_TKIP_MIC, 0, 1, NULL);
  346. }
  347. /*
  348. * Check whether the separate key cache entries
  349. * are required to handle both tx+rx MIC keys.
  350. * With split mic keys the number of stations is limited
  351. * to 27 otherwise 59.
  352. */
  353. if (ath9k_hw_getcapability(sc->sc_ah, ATH9K_CAP_CIPHER,
  354. ATH9K_CIPHER_TKIP, NULL)
  355. && ath9k_hw_getcapability(sc->sc_ah, ATH9K_CAP_CIPHER,
  356. ATH9K_CIPHER_MIC, NULL)
  357. && ath9k_hw_getcapability(sc->sc_ah, ATH9K_CAP_TKIP_SPLIT,
  358. 0, NULL))
  359. common->splitmic = 1;
  360. /* turn on mcast key search if possible */
  361. if (!ath9k_hw_getcapability(sc->sc_ah, ATH9K_CAP_MCAST_KEYSRCH, 0, NULL))
  362. (void)ath9k_hw_setcapability(sc->sc_ah, ATH9K_CAP_MCAST_KEYSRCH,
  363. 1, 1, NULL);
  364. }
  365. static int ath9k_init_btcoex(struct ath_softc *sc)
  366. {
  367. int r, qnum;
  368. switch (sc->sc_ah->btcoex_hw.scheme) {
  369. case ATH_BTCOEX_CFG_NONE:
  370. break;
  371. case ATH_BTCOEX_CFG_2WIRE:
  372. ath9k_hw_btcoex_init_2wire(sc->sc_ah);
  373. break;
  374. case ATH_BTCOEX_CFG_3WIRE:
  375. ath9k_hw_btcoex_init_3wire(sc->sc_ah);
  376. r = ath_init_btcoex_timer(sc);
  377. if (r)
  378. return -1;
  379. qnum = ath_tx_get_qnum(sc, ATH9K_TX_QUEUE_DATA, ATH9K_WME_AC_BE);
  380. ath9k_hw_init_btcoex_hw(sc->sc_ah, qnum);
  381. sc->btcoex.bt_stomp_type = ATH_BTCOEX_STOMP_LOW;
  382. break;
  383. default:
  384. WARN_ON(1);
  385. break;
  386. }
  387. return 0;
  388. }
  389. static int ath9k_init_queues(struct ath_softc *sc)
  390. {
  391. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  392. int i = 0;
  393. for (i = 0; i < ARRAY_SIZE(sc->tx.hwq_map); i++)
  394. sc->tx.hwq_map[i] = -1;
  395. sc->beacon.beaconq = ath9k_hw_beaconq_setup(sc->sc_ah);
  396. if (sc->beacon.beaconq == -1) {
  397. ath_print(common, ATH_DBG_FATAL,
  398. "Unable to setup a beacon xmit queue\n");
  399. goto err;
  400. }
  401. sc->beacon.cabq = ath_txq_setup(sc, ATH9K_TX_QUEUE_CAB, 0);
  402. if (sc->beacon.cabq == NULL) {
  403. ath_print(common, ATH_DBG_FATAL,
  404. "Unable to setup CAB xmit queue\n");
  405. goto err;
  406. }
  407. sc->config.cabqReadytime = ATH_CABQ_READY_TIME;
  408. ath_cabq_update(sc);
  409. if (!ath_tx_setup(sc, ATH9K_WME_AC_BK)) {
  410. ath_print(common, ATH_DBG_FATAL,
  411. "Unable to setup xmit queue for BK traffic\n");
  412. goto err;
  413. }
  414. if (!ath_tx_setup(sc, ATH9K_WME_AC_BE)) {
  415. ath_print(common, ATH_DBG_FATAL,
  416. "Unable to setup xmit queue for BE traffic\n");
  417. goto err;
  418. }
  419. if (!ath_tx_setup(sc, ATH9K_WME_AC_VI)) {
  420. ath_print(common, ATH_DBG_FATAL,
  421. "Unable to setup xmit queue for VI traffic\n");
  422. goto err;
  423. }
  424. if (!ath_tx_setup(sc, ATH9K_WME_AC_VO)) {
  425. ath_print(common, ATH_DBG_FATAL,
  426. "Unable to setup xmit queue for VO traffic\n");
  427. goto err;
  428. }
  429. return 0;
  430. err:
  431. for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++)
  432. if (ATH_TXQ_SETUP(sc, i))
  433. ath_tx_cleanupq(sc, &sc->tx.txq[i]);
  434. return -EIO;
  435. }
  436. static void ath9k_init_channels_rates(struct ath_softc *sc)
  437. {
  438. if (test_bit(ATH9K_MODE_11G, sc->sc_ah->caps.wireless_modes)) {
  439. sc->sbands[IEEE80211_BAND_2GHZ].channels = ath9k_2ghz_chantable;
  440. sc->sbands[IEEE80211_BAND_2GHZ].band = IEEE80211_BAND_2GHZ;
  441. sc->sbands[IEEE80211_BAND_2GHZ].n_channels =
  442. ARRAY_SIZE(ath9k_2ghz_chantable);
  443. sc->sbands[IEEE80211_BAND_2GHZ].bitrates = ath9k_legacy_rates;
  444. sc->sbands[IEEE80211_BAND_2GHZ].n_bitrates =
  445. ARRAY_SIZE(ath9k_legacy_rates);
  446. }
  447. if (test_bit(ATH9K_MODE_11A, sc->sc_ah->caps.wireless_modes)) {
  448. sc->sbands[IEEE80211_BAND_5GHZ].channels = ath9k_5ghz_chantable;
  449. sc->sbands[IEEE80211_BAND_5GHZ].band = IEEE80211_BAND_5GHZ;
  450. sc->sbands[IEEE80211_BAND_5GHZ].n_channels =
  451. ARRAY_SIZE(ath9k_5ghz_chantable);
  452. sc->sbands[IEEE80211_BAND_5GHZ].bitrates =
  453. ath9k_legacy_rates + 4;
  454. sc->sbands[IEEE80211_BAND_5GHZ].n_bitrates =
  455. ARRAY_SIZE(ath9k_legacy_rates) - 4;
  456. }
  457. }
  458. static void ath9k_init_misc(struct ath_softc *sc)
  459. {
  460. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  461. int i = 0;
  462. common->ani.noise_floor = ATH_DEFAULT_NOISE_FLOOR;
  463. setup_timer(&common->ani.timer, ath_ani_calibrate, (unsigned long)sc);
  464. sc->config.txpowlimit = ATH_TXPOWER_MAX;
  465. if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_HT) {
  466. sc->sc_flags |= SC_OP_TXAGGR;
  467. sc->sc_flags |= SC_OP_RXAGGR;
  468. }
  469. common->tx_chainmask = sc->sc_ah->caps.tx_chainmask;
  470. common->rx_chainmask = sc->sc_ah->caps.rx_chainmask;
  471. ath9k_hw_set_diversity(sc->sc_ah, true);
  472. sc->rx.defant = ath9k_hw_getdefantenna(sc->sc_ah);
  473. if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_BSSIDMASK)
  474. memcpy(common->bssidmask, ath_bcast_mac, ETH_ALEN);
  475. sc->beacon.slottime = ATH9K_SLOT_TIME_9;
  476. for (i = 0; i < ARRAY_SIZE(sc->beacon.bslot); i++) {
  477. sc->beacon.bslot[i] = NULL;
  478. sc->beacon.bslot_aphy[i] = NULL;
  479. }
  480. }
  481. static int ath9k_init_softc(u16 devid, struct ath_softc *sc, u16 subsysid,
  482. const struct ath_bus_ops *bus_ops)
  483. {
  484. struct ath_hw *ah = NULL;
  485. struct ath_common *common;
  486. int ret = 0, i;
  487. int csz = 0;
  488. ah = kzalloc(sizeof(struct ath_hw), GFP_KERNEL);
  489. if (!ah)
  490. return -ENOMEM;
  491. ah->hw_version.devid = devid;
  492. ah->hw_version.subsysid = subsysid;
  493. sc->sc_ah = ah;
  494. common = ath9k_hw_common(ah);
  495. common->ops = &ath9k_common_ops;
  496. common->bus_ops = bus_ops;
  497. common->ah = ah;
  498. common->hw = sc->hw;
  499. common->priv = sc;
  500. common->debug_mask = ath9k_debug;
  501. spin_lock_init(&sc->wiphy_lock);
  502. spin_lock_init(&sc->sc_resetlock);
  503. spin_lock_init(&sc->sc_serial_rw);
  504. spin_lock_init(&sc->sc_pm_lock);
  505. mutex_init(&sc->mutex);
  506. tasklet_init(&sc->intr_tq, ath9k_tasklet, (unsigned long)sc);
  507. tasklet_init(&sc->bcon_tasklet, ath_beacon_tasklet,
  508. (unsigned long)sc);
  509. /*
  510. * Cache line size is used to size and align various
  511. * structures used to communicate with the hardware.
  512. */
  513. ath_read_cachesize(common, &csz);
  514. common->cachelsz = csz << 2; /* convert to bytes */
  515. /* Initializes the hardware for all supported chipsets */
  516. ret = ath9k_hw_init(ah);
  517. if (ret)
  518. goto err_hw;
  519. ret = ath9k_init_debug(ah);
  520. if (ret) {
  521. ath_print(common, ATH_DBG_FATAL,
  522. "Unable to create debugfs files\n");
  523. goto err_debug;
  524. }
  525. ret = ath9k_init_queues(sc);
  526. if (ret)
  527. goto err_queues;
  528. ret = ath9k_init_btcoex(sc);
  529. if (ret)
  530. goto err_btcoex;
  531. ath9k_init_crypto(sc);
  532. ath9k_init_channels_rates(sc);
  533. ath9k_init_misc(sc);
  534. return 0;
  535. err_btcoex:
  536. for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++)
  537. if (ATH_TXQ_SETUP(sc, i))
  538. ath_tx_cleanupq(sc, &sc->tx.txq[i]);
  539. err_queues:
  540. ath9k_exit_debug(ah);
  541. err_debug:
  542. ath9k_hw_deinit(ah);
  543. err_hw:
  544. tasklet_kill(&sc->intr_tq);
  545. tasklet_kill(&sc->bcon_tasklet);
  546. kfree(ah);
  547. sc->sc_ah = NULL;
  548. return ret;
  549. }
  550. void ath9k_set_hw_capab(struct ath_softc *sc, struct ieee80211_hw *hw)
  551. {
  552. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  553. hw->flags = IEEE80211_HW_RX_INCLUDES_FCS |
  554. IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING |
  555. IEEE80211_HW_SIGNAL_DBM |
  556. IEEE80211_HW_SUPPORTS_PS |
  557. IEEE80211_HW_PS_NULLFUNC_STACK |
  558. IEEE80211_HW_SPECTRUM_MGMT |
  559. IEEE80211_HW_REPORTS_TX_ACK_STATUS;
  560. if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_HT)
  561. hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION;
  562. if (AR_SREV_9160_10_OR_LATER(sc->sc_ah) || modparam_nohwcrypt)
  563. hw->flags |= IEEE80211_HW_MFP_CAPABLE;
  564. hw->wiphy->interface_modes =
  565. BIT(NL80211_IFTYPE_AP) |
  566. BIT(NL80211_IFTYPE_STATION) |
  567. BIT(NL80211_IFTYPE_ADHOC) |
  568. BIT(NL80211_IFTYPE_MESH_POINT);
  569. hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
  570. hw->queues = 4;
  571. hw->max_rates = 4;
  572. hw->channel_change_time = 5000;
  573. hw->max_listen_interval = 10;
  574. hw->max_rate_tries = 10;
  575. hw->sta_data_size = sizeof(struct ath_node);
  576. hw->vif_data_size = sizeof(struct ath_vif);
  577. hw->rate_control_algorithm = "ath9k_rate_control";
  578. if (test_bit(ATH9K_MODE_11G, sc->sc_ah->caps.wireless_modes))
  579. hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
  580. &sc->sbands[IEEE80211_BAND_2GHZ];
  581. if (test_bit(ATH9K_MODE_11A, sc->sc_ah->caps.wireless_modes))
  582. hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
  583. &sc->sbands[IEEE80211_BAND_5GHZ];
  584. if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_HT) {
  585. if (test_bit(ATH9K_MODE_11G, sc->sc_ah->caps.wireless_modes))
  586. setup_ht_cap(sc, &sc->sbands[IEEE80211_BAND_2GHZ].ht_cap);
  587. if (test_bit(ATH9K_MODE_11A, sc->sc_ah->caps.wireless_modes))
  588. setup_ht_cap(sc, &sc->sbands[IEEE80211_BAND_5GHZ].ht_cap);
  589. }
  590. SET_IEEE80211_PERM_ADDR(hw, common->macaddr);
  591. }
  592. int ath9k_init_device(u16 devid, struct ath_softc *sc, u16 subsysid,
  593. const struct ath_bus_ops *bus_ops)
  594. {
  595. struct ieee80211_hw *hw = sc->hw;
  596. struct ath_common *common;
  597. struct ath_hw *ah;
  598. int error = 0;
  599. struct ath_regulatory *reg;
  600. /* Bring up device */
  601. error = ath9k_init_softc(devid, sc, subsysid, bus_ops);
  602. if (error != 0)
  603. goto error_init;
  604. ah = sc->sc_ah;
  605. common = ath9k_hw_common(ah);
  606. ath9k_set_hw_capab(sc, hw);
  607. /* Initialize regulatory */
  608. error = ath_regd_init(&common->regulatory, sc->hw->wiphy,
  609. ath9k_reg_notifier);
  610. if (error)
  611. goto error_regd;
  612. reg = &common->regulatory;
  613. /* Setup TX DMA */
  614. error = ath_tx_init(sc, ATH_TXBUF);
  615. if (error != 0)
  616. goto error_tx;
  617. /* Setup RX DMA */
  618. error = ath_rx_init(sc, ATH_RXBUF);
  619. if (error != 0)
  620. goto error_rx;
  621. /* Register with mac80211 */
  622. error = ieee80211_register_hw(hw);
  623. if (error)
  624. goto error_register;
  625. /* Handle world regulatory */
  626. if (!ath_is_world_regd(reg)) {
  627. error = regulatory_hint(hw->wiphy, reg->alpha2);
  628. if (error)
  629. goto error_world;
  630. }
  631. INIT_WORK(&sc->chan_work, ath9k_wiphy_chan_work);
  632. INIT_DELAYED_WORK(&sc->wiphy_work, ath9k_wiphy_work);
  633. sc->wiphy_scheduler_int = msecs_to_jiffies(500);
  634. ath_init_leds(sc);
  635. ath_start_rfkill_poll(sc);
  636. return 0;
  637. error_world:
  638. ieee80211_unregister_hw(hw);
  639. error_register:
  640. ath_rx_cleanup(sc);
  641. error_rx:
  642. ath_tx_cleanup(sc);
  643. error_tx:
  644. /* Nothing */
  645. error_regd:
  646. ath9k_deinit_softc(sc);
  647. error_init:
  648. return error;
  649. }
  650. /*****************************/
  651. /* De-Initialization */
  652. /*****************************/
  653. static void ath9k_deinit_softc(struct ath_softc *sc)
  654. {
  655. int i = 0;
  656. if ((sc->btcoex.no_stomp_timer) &&
  657. sc->sc_ah->btcoex_hw.scheme == ATH_BTCOEX_CFG_3WIRE)
  658. ath_gen_timer_free(sc->sc_ah, sc->btcoex.no_stomp_timer);
  659. for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++)
  660. if (ATH_TXQ_SETUP(sc, i))
  661. ath_tx_cleanupq(sc, &sc->tx.txq[i]);
  662. ath9k_exit_debug(sc->sc_ah);
  663. ath9k_hw_deinit(sc->sc_ah);
  664. tasklet_kill(&sc->intr_tq);
  665. tasklet_kill(&sc->bcon_tasklet);
  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. for (i = 0; i < sc->num_sec_wiphy; i++) {
  677. struct ath_wiphy *aphy = sc->sec_wiphy[i];
  678. if (aphy == NULL)
  679. continue;
  680. sc->sec_wiphy[i] = NULL;
  681. ieee80211_unregister_hw(aphy->hw);
  682. ieee80211_free_hw(aphy->hw);
  683. }
  684. kfree(sc->sec_wiphy);
  685. ieee80211_unregister_hw(hw);
  686. ath_rx_cleanup(sc);
  687. ath_tx_cleanup(sc);
  688. ath9k_deinit_softc(sc);
  689. }
  690. void ath_descdma_cleanup(struct ath_softc *sc,
  691. struct ath_descdma *dd,
  692. struct list_head *head)
  693. {
  694. dma_free_coherent(sc->dev, dd->dd_desc_len, dd->dd_desc,
  695. dd->dd_desc_paddr);
  696. INIT_LIST_HEAD(head);
  697. kfree(dd->dd_bufptr);
  698. memset(dd, 0, sizeof(*dd));
  699. }
  700. /************************/
  701. /* Module Hooks */
  702. /************************/
  703. static int __init ath9k_init(void)
  704. {
  705. int error;
  706. /* Register rate control algorithm */
  707. error = ath_rate_control_register();
  708. if (error != 0) {
  709. printk(KERN_ERR
  710. "ath9k: Unable to register rate control "
  711. "algorithm: %d\n",
  712. error);
  713. goto err_out;
  714. }
  715. error = ath9k_debug_create_root();
  716. if (error) {
  717. printk(KERN_ERR
  718. "ath9k: Unable to create debugfs root: %d\n",
  719. error);
  720. goto err_rate_unregister;
  721. }
  722. error = ath_pci_init();
  723. if (error < 0) {
  724. printk(KERN_ERR
  725. "ath9k: No PCI devices found, driver not installed.\n");
  726. error = -ENODEV;
  727. goto err_remove_root;
  728. }
  729. error = ath_ahb_init();
  730. if (error < 0) {
  731. error = -ENODEV;
  732. goto err_pci_exit;
  733. }
  734. return 0;
  735. err_pci_exit:
  736. ath_pci_exit();
  737. err_remove_root:
  738. ath9k_debug_remove_root();
  739. err_rate_unregister:
  740. ath_rate_control_unregister();
  741. err_out:
  742. return error;
  743. }
  744. module_init(ath9k_init);
  745. static void __exit ath9k_exit(void)
  746. {
  747. ath_ahb_exit();
  748. ath_pci_exit();
  749. ath9k_debug_remove_root();
  750. ath_rate_control_unregister();
  751. printk(KERN_INFO "%s: Driver unloaded\n", dev_info);
  752. }
  753. module_exit(ath9k_exit);