init.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856
  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 "ath9k.h"
  17. static char *dev_info = "ath9k";
  18. MODULE_AUTHOR("Atheros Communications");
  19. MODULE_DESCRIPTION("Support for Atheros 802.11n wireless LAN cards.");
  20. MODULE_SUPPORTED_DEVICE("Atheros 802.11n WLAN cards");
  21. MODULE_LICENSE("Dual BSD/GPL");
  22. static unsigned int ath9k_debug = ATH_DBG_DEFAULT;
  23. module_param_named(debug, ath9k_debug, uint, 0);
  24. MODULE_PARM_DESC(debug, "Debugging mask");
  25. int modparam_nohwcrypt;
  26. module_param_named(nohwcrypt, modparam_nohwcrypt, int, 0444);
  27. MODULE_PARM_DESC(nohwcrypt, "Disable hardware encryption");
  28. /* We use the hw_value as an index into our private channel structure */
  29. #define CHAN2G(_freq, _idx) { \
  30. .center_freq = (_freq), \
  31. .hw_value = (_idx), \
  32. .max_power = 20, \
  33. }
  34. #define CHAN5G(_freq, _idx) { \
  35. .band = IEEE80211_BAND_5GHZ, \
  36. .center_freq = (_freq), \
  37. .hw_value = (_idx), \
  38. .max_power = 20, \
  39. }
  40. /* Some 2 GHz radios are actually tunable on 2312-2732
  41. * on 5 MHz steps, we support the channels which we know
  42. * we have calibration data for all cards though to make
  43. * this static */
  44. static struct ieee80211_channel ath9k_2ghz_chantable[] = {
  45. CHAN2G(2412, 0), /* Channel 1 */
  46. CHAN2G(2417, 1), /* Channel 2 */
  47. CHAN2G(2422, 2), /* Channel 3 */
  48. CHAN2G(2427, 3), /* Channel 4 */
  49. CHAN2G(2432, 4), /* Channel 5 */
  50. CHAN2G(2437, 5), /* Channel 6 */
  51. CHAN2G(2442, 6), /* Channel 7 */
  52. CHAN2G(2447, 7), /* Channel 8 */
  53. CHAN2G(2452, 8), /* Channel 9 */
  54. CHAN2G(2457, 9), /* Channel 10 */
  55. CHAN2G(2462, 10), /* Channel 11 */
  56. CHAN2G(2467, 11), /* Channel 12 */
  57. CHAN2G(2472, 12), /* Channel 13 */
  58. CHAN2G(2484, 13), /* Channel 14 */
  59. };
  60. /* Some 5 GHz radios are actually tunable on XXXX-YYYY
  61. * on 5 MHz steps, we support the channels which we know
  62. * we have calibration data for all cards though to make
  63. * this static */
  64. static struct ieee80211_channel ath9k_5ghz_chantable[] = {
  65. /* _We_ call this UNII 1 */
  66. CHAN5G(5180, 14), /* Channel 36 */
  67. CHAN5G(5200, 15), /* Channel 40 */
  68. CHAN5G(5220, 16), /* Channel 44 */
  69. CHAN5G(5240, 17), /* Channel 48 */
  70. /* _We_ call this UNII 2 */
  71. CHAN5G(5260, 18), /* Channel 52 */
  72. CHAN5G(5280, 19), /* Channel 56 */
  73. CHAN5G(5300, 20), /* Channel 60 */
  74. CHAN5G(5320, 21), /* Channel 64 */
  75. /* _We_ call this "Middle band" */
  76. CHAN5G(5500, 22), /* Channel 100 */
  77. CHAN5G(5520, 23), /* Channel 104 */
  78. CHAN5G(5540, 24), /* Channel 108 */
  79. CHAN5G(5560, 25), /* Channel 112 */
  80. CHAN5G(5580, 26), /* Channel 116 */
  81. CHAN5G(5600, 27), /* Channel 120 */
  82. CHAN5G(5620, 28), /* Channel 124 */
  83. CHAN5G(5640, 29), /* Channel 128 */
  84. CHAN5G(5660, 30), /* Channel 132 */
  85. CHAN5G(5680, 31), /* Channel 136 */
  86. CHAN5G(5700, 32), /* Channel 140 */
  87. /* _We_ call this UNII 3 */
  88. CHAN5G(5745, 33), /* Channel 149 */
  89. CHAN5G(5765, 34), /* Channel 153 */
  90. CHAN5G(5785, 35), /* Channel 157 */
  91. CHAN5G(5805, 36), /* Channel 161 */
  92. CHAN5G(5825, 37), /* Channel 165 */
  93. };
  94. /* Atheros hardware rate code addition for short premble */
  95. #define SHPCHECK(__hw_rate, __flags) \
  96. ((__flags & IEEE80211_RATE_SHORT_PREAMBLE) ? (__hw_rate | 0x04 ) : 0)
  97. #define RATE(_bitrate, _hw_rate, _flags) { \
  98. .bitrate = (_bitrate), \
  99. .flags = (_flags), \
  100. .hw_value = (_hw_rate), \
  101. .hw_value_short = (SHPCHECK(_hw_rate, _flags)) \
  102. }
  103. static struct ieee80211_rate ath9k_legacy_rates[] = {
  104. RATE(10, 0x1b, 0),
  105. RATE(20, 0x1a, IEEE80211_RATE_SHORT_PREAMBLE),
  106. RATE(55, 0x19, IEEE80211_RATE_SHORT_PREAMBLE),
  107. RATE(110, 0x18, IEEE80211_RATE_SHORT_PREAMBLE),
  108. RATE(60, 0x0b, 0),
  109. RATE(90, 0x0f, 0),
  110. RATE(120, 0x0a, 0),
  111. RATE(180, 0x0e, 0),
  112. RATE(240, 0x09, 0),
  113. RATE(360, 0x0d, 0),
  114. RATE(480, 0x08, 0),
  115. RATE(540, 0x0c, 0),
  116. };
  117. static void ath9k_uninit_hw(struct ath_softc *sc);
  118. /*
  119. * Read and write, they both share the same lock. We do this to serialize
  120. * reads and writes on Atheros 802.11n PCI devices only. This is required
  121. * as the FIFO on these devices can only accept sanely 2 requests.
  122. */
  123. static void ath9k_iowrite32(void *hw_priv, u32 val, u32 reg_offset)
  124. {
  125. struct ath_hw *ah = (struct ath_hw *) hw_priv;
  126. struct ath_common *common = ath9k_hw_common(ah);
  127. struct ath_softc *sc = (struct ath_softc *) common->priv;
  128. if (ah->config.serialize_regmode == SER_REG_MODE_ON) {
  129. unsigned long flags;
  130. spin_lock_irqsave(&sc->sc_serial_rw, flags);
  131. iowrite32(val, sc->mem + reg_offset);
  132. spin_unlock_irqrestore(&sc->sc_serial_rw, flags);
  133. } else
  134. iowrite32(val, sc->mem + reg_offset);
  135. }
  136. static unsigned int ath9k_ioread32(void *hw_priv, u32 reg_offset)
  137. {
  138. struct ath_hw *ah = (struct ath_hw *) hw_priv;
  139. struct ath_common *common = ath9k_hw_common(ah);
  140. struct ath_softc *sc = (struct ath_softc *) common->priv;
  141. u32 val;
  142. if (ah->config.serialize_regmode == SER_REG_MODE_ON) {
  143. unsigned long flags;
  144. spin_lock_irqsave(&sc->sc_serial_rw, flags);
  145. val = ioread32(sc->mem + reg_offset);
  146. spin_unlock_irqrestore(&sc->sc_serial_rw, flags);
  147. } else
  148. val = ioread32(sc->mem + reg_offset);
  149. return val;
  150. }
  151. static const struct ath_ops ath9k_common_ops = {
  152. .read = ath9k_ioread32,
  153. .write = ath9k_iowrite32,
  154. };
  155. /**************************/
  156. /* Initialization */
  157. /**************************/
  158. static void setup_ht_cap(struct ath_softc *sc,
  159. struct ieee80211_sta_ht_cap *ht_info)
  160. {
  161. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  162. u8 tx_streams, rx_streams;
  163. ht_info->ht_supported = true;
  164. ht_info->cap = IEEE80211_HT_CAP_SUP_WIDTH_20_40 |
  165. IEEE80211_HT_CAP_SM_PS |
  166. IEEE80211_HT_CAP_SGI_40 |
  167. IEEE80211_HT_CAP_DSSSCCK40;
  168. ht_info->ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
  169. ht_info->ampdu_density = IEEE80211_HT_MPDU_DENSITY_8;
  170. /* set up supported mcs set */
  171. memset(&ht_info->mcs, 0, sizeof(ht_info->mcs));
  172. tx_streams = !(common->tx_chainmask & (common->tx_chainmask - 1)) ?
  173. 1 : 2;
  174. rx_streams = !(common->rx_chainmask & (common->rx_chainmask - 1)) ?
  175. 1 : 2;
  176. if (tx_streams != rx_streams) {
  177. ath_print(common, ATH_DBG_CONFIG,
  178. "TX streams %d, RX streams: %d\n",
  179. tx_streams, rx_streams);
  180. ht_info->mcs.tx_params |= IEEE80211_HT_MCS_TX_RX_DIFF;
  181. ht_info->mcs.tx_params |= ((tx_streams - 1) <<
  182. IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT);
  183. }
  184. ht_info->mcs.rx_mask[0] = 0xff;
  185. if (rx_streams >= 2)
  186. ht_info->mcs.rx_mask[1] = 0xff;
  187. ht_info->mcs.tx_params |= IEEE80211_HT_MCS_TX_DEFINED;
  188. }
  189. static int ath9k_reg_notifier(struct wiphy *wiphy,
  190. struct regulatory_request *request)
  191. {
  192. struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
  193. struct ath_wiphy *aphy = hw->priv;
  194. struct ath_softc *sc = aphy->sc;
  195. struct ath_regulatory *reg = ath9k_hw_regulatory(sc->sc_ah);
  196. return ath_reg_notifier_apply(wiphy, request, reg);
  197. }
  198. /*
  199. * This function will allocate both the DMA descriptor structure, and the
  200. * buffers it contains. These are used to contain the descriptors used
  201. * by the system.
  202. */
  203. int ath_descdma_setup(struct ath_softc *sc, struct ath_descdma *dd,
  204. struct list_head *head, const char *name,
  205. int nbuf, int ndesc)
  206. {
  207. #define DS2PHYS(_dd, _ds) \
  208. ((_dd)->dd_desc_paddr + ((caddr_t)(_ds) - (caddr_t)(_dd)->dd_desc))
  209. #define ATH_DESC_4KB_BOUND_CHECK(_daddr) ((((_daddr) & 0xFFF) > 0xF7F) ? 1 : 0)
  210. #define ATH_DESC_4KB_BOUND_NUM_SKIPPED(_len) ((_len) / 4096)
  211. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  212. struct ath_desc *ds;
  213. struct ath_buf *bf;
  214. int i, bsize, error;
  215. ath_print(common, ATH_DBG_CONFIG, "%s DMA: %u buffers %u desc/buf\n",
  216. name, nbuf, ndesc);
  217. INIT_LIST_HEAD(head);
  218. /* ath_desc must be a multiple of DWORDs */
  219. if ((sizeof(struct ath_desc) % 4) != 0) {
  220. ath_print(common, ATH_DBG_FATAL,
  221. "ath_desc not DWORD aligned\n");
  222. BUG_ON((sizeof(struct ath_desc) % 4) != 0);
  223. error = -ENOMEM;
  224. goto fail;
  225. }
  226. dd->dd_desc_len = sizeof(struct ath_desc) * nbuf * ndesc;
  227. /*
  228. * Need additional DMA memory because we can't use
  229. * descriptors that cross the 4K page boundary. Assume
  230. * one skipped descriptor per 4K page.
  231. */
  232. if (!(sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_4KB_SPLITTRANS)) {
  233. u32 ndesc_skipped =
  234. ATH_DESC_4KB_BOUND_NUM_SKIPPED(dd->dd_desc_len);
  235. u32 dma_len;
  236. while (ndesc_skipped) {
  237. dma_len = ndesc_skipped * sizeof(struct ath_desc);
  238. dd->dd_desc_len += dma_len;
  239. ndesc_skipped = ATH_DESC_4KB_BOUND_NUM_SKIPPED(dma_len);
  240. };
  241. }
  242. /* allocate descriptors */
  243. dd->dd_desc = dma_alloc_coherent(sc->dev, dd->dd_desc_len,
  244. &dd->dd_desc_paddr, GFP_KERNEL);
  245. if (dd->dd_desc == NULL) {
  246. error = -ENOMEM;
  247. goto fail;
  248. }
  249. ds = dd->dd_desc;
  250. ath_print(common, ATH_DBG_CONFIG, "%s DMA map: %p (%u) -> %llx (%u)\n",
  251. name, ds, (u32) dd->dd_desc_len,
  252. ito64(dd->dd_desc_paddr), /*XXX*/(u32) dd->dd_desc_len);
  253. /* allocate buffers */
  254. bsize = sizeof(struct ath_buf) * nbuf;
  255. bf = kzalloc(bsize, GFP_KERNEL);
  256. if (bf == NULL) {
  257. error = -ENOMEM;
  258. goto fail2;
  259. }
  260. dd->dd_bufptr = bf;
  261. for (i = 0; i < nbuf; i++, bf++, ds += ndesc) {
  262. bf->bf_desc = ds;
  263. bf->bf_daddr = DS2PHYS(dd, ds);
  264. if (!(sc->sc_ah->caps.hw_caps &
  265. ATH9K_HW_CAP_4KB_SPLITTRANS)) {
  266. /*
  267. * Skip descriptor addresses which can cause 4KB
  268. * boundary crossing (addr + length) with a 32 dword
  269. * descriptor fetch.
  270. */
  271. while (ATH_DESC_4KB_BOUND_CHECK(bf->bf_daddr)) {
  272. BUG_ON((caddr_t) bf->bf_desc >=
  273. ((caddr_t) dd->dd_desc +
  274. dd->dd_desc_len));
  275. ds += ndesc;
  276. bf->bf_desc = ds;
  277. bf->bf_daddr = DS2PHYS(dd, ds);
  278. }
  279. }
  280. list_add_tail(&bf->list, head);
  281. }
  282. return 0;
  283. fail2:
  284. dma_free_coherent(sc->dev, dd->dd_desc_len, dd->dd_desc,
  285. dd->dd_desc_paddr);
  286. fail:
  287. memset(dd, 0, sizeof(*dd));
  288. return error;
  289. #undef ATH_DESC_4KB_BOUND_CHECK
  290. #undef ATH_DESC_4KB_BOUND_NUM_SKIPPED
  291. #undef DS2PHYS
  292. }
  293. static int ath_init_softc(u16 devid, struct ath_softc *sc, u16 subsysid,
  294. const struct ath_bus_ops *bus_ops)
  295. {
  296. struct ath_hw *ah = NULL;
  297. struct ath_common *common;
  298. int r = 0, i;
  299. int csz = 0;
  300. int qnum;
  301. /* XXX: hardware will not be ready until ath_open() being called */
  302. sc->sc_flags |= SC_OP_INVALID;
  303. spin_lock_init(&sc->wiphy_lock);
  304. spin_lock_init(&sc->sc_resetlock);
  305. spin_lock_init(&sc->sc_serial_rw);
  306. spin_lock_init(&sc->sc_pm_lock);
  307. mutex_init(&sc->mutex);
  308. tasklet_init(&sc->intr_tq, ath9k_tasklet, (unsigned long)sc);
  309. tasklet_init(&sc->bcon_tasklet, ath_beacon_tasklet,
  310. (unsigned long)sc);
  311. ah = kzalloc(sizeof(struct ath_hw), GFP_KERNEL);
  312. if (!ah)
  313. return -ENOMEM;
  314. ah->hw_version.devid = devid;
  315. ah->hw_version.subsysid = subsysid;
  316. sc->sc_ah = ah;
  317. common = ath9k_hw_common(ah);
  318. common->ops = &ath9k_common_ops;
  319. common->bus_ops = bus_ops;
  320. common->ah = ah;
  321. common->hw = sc->hw;
  322. common->priv = sc;
  323. common->debug_mask = ath9k_debug;
  324. /*
  325. * Cache line size is used to size and align various
  326. * structures used to communicate with the hardware.
  327. */
  328. ath_read_cachesize(common, &csz);
  329. /* XXX assert csz is non-zero */
  330. common->cachelsz = csz << 2; /* convert to bytes */
  331. r = ath9k_hw_init(ah);
  332. if (r) {
  333. ath_print(common, ATH_DBG_FATAL,
  334. "Unable to initialize hardware; "
  335. "initialization status: %d\n", r);
  336. goto bad_free_hw;
  337. }
  338. if (ath9k_init_debug(ah) < 0) {
  339. ath_print(common, ATH_DBG_FATAL,
  340. "Unable to create debugfs files\n");
  341. goto bad_free_hw;
  342. }
  343. /* Get the hardware key cache size. */
  344. common->keymax = ah->caps.keycache_size;
  345. if (common->keymax > ATH_KEYMAX) {
  346. ath_print(common, ATH_DBG_ANY,
  347. "Warning, using only %u entries in %u key cache\n",
  348. ATH_KEYMAX, common->keymax);
  349. common->keymax = ATH_KEYMAX;
  350. }
  351. /*
  352. * Reset the key cache since some parts do not
  353. * reset the contents on initial power up.
  354. */
  355. for (i = 0; i < common->keymax; i++)
  356. ath9k_hw_keyreset(ah, (u16) i);
  357. /* default to MONITOR mode */
  358. sc->sc_ah->opmode = NL80211_IFTYPE_MONITOR;
  359. /*
  360. * Allocate hardware transmit queues: one queue for
  361. * beacon frames and one data queue for each QoS
  362. * priority. Note that the hal handles reseting
  363. * these queues at the needed time.
  364. */
  365. sc->beacon.beaconq = ath9k_hw_beaconq_setup(ah);
  366. if (sc->beacon.beaconq == -1) {
  367. ath_print(common, ATH_DBG_FATAL,
  368. "Unable to setup a beacon xmit queue\n");
  369. r = -EIO;
  370. goto bad2;
  371. }
  372. sc->beacon.cabq = ath_txq_setup(sc, ATH9K_TX_QUEUE_CAB, 0);
  373. if (sc->beacon.cabq == NULL) {
  374. ath_print(common, ATH_DBG_FATAL,
  375. "Unable to setup CAB xmit queue\n");
  376. r = -EIO;
  377. goto bad2;
  378. }
  379. sc->config.cabqReadytime = ATH_CABQ_READY_TIME;
  380. ath_cabq_update(sc);
  381. for (i = 0; i < ARRAY_SIZE(sc->tx.hwq_map); i++)
  382. sc->tx.hwq_map[i] = -1;
  383. /* Setup data queues */
  384. /* NB: ensure BK queue is the lowest priority h/w queue */
  385. if (!ath_tx_setup(sc, ATH9K_WME_AC_BK)) {
  386. ath_print(common, ATH_DBG_FATAL,
  387. "Unable to setup xmit queue for BK traffic\n");
  388. r = -EIO;
  389. goto bad2;
  390. }
  391. if (!ath_tx_setup(sc, ATH9K_WME_AC_BE)) {
  392. ath_print(common, ATH_DBG_FATAL,
  393. "Unable to setup xmit queue for BE traffic\n");
  394. r = -EIO;
  395. goto bad2;
  396. }
  397. if (!ath_tx_setup(sc, ATH9K_WME_AC_VI)) {
  398. ath_print(common, ATH_DBG_FATAL,
  399. "Unable to setup xmit queue for VI traffic\n");
  400. r = -EIO;
  401. goto bad2;
  402. }
  403. if (!ath_tx_setup(sc, ATH9K_WME_AC_VO)) {
  404. ath_print(common, ATH_DBG_FATAL,
  405. "Unable to setup xmit queue for VO traffic\n");
  406. r = -EIO;
  407. goto bad2;
  408. }
  409. /* Initializes the noise floor to a reasonable default value.
  410. * Later on this will be updated during ANI processing. */
  411. common->ani.noise_floor = ATH_DEFAULT_NOISE_FLOOR;
  412. setup_timer(&common->ani.timer, ath_ani_calibrate, (unsigned long)sc);
  413. if (ath9k_hw_getcapability(ah, ATH9K_CAP_CIPHER,
  414. ATH9K_CIPHER_TKIP, NULL)) {
  415. /*
  416. * Whether we should enable h/w TKIP MIC.
  417. * XXX: if we don't support WME TKIP MIC, then we wouldn't
  418. * report WMM capable, so it's always safe to turn on
  419. * TKIP MIC in this case.
  420. */
  421. ath9k_hw_setcapability(sc->sc_ah, ATH9K_CAP_TKIP_MIC,
  422. 0, 1, NULL);
  423. }
  424. /*
  425. * Check whether the separate key cache entries
  426. * are required to handle both tx+rx MIC keys.
  427. * With split mic keys the number of stations is limited
  428. * to 27 otherwise 59.
  429. */
  430. if (ath9k_hw_getcapability(ah, ATH9K_CAP_CIPHER,
  431. ATH9K_CIPHER_TKIP, NULL)
  432. && ath9k_hw_getcapability(ah, ATH9K_CAP_CIPHER,
  433. ATH9K_CIPHER_MIC, NULL)
  434. && ath9k_hw_getcapability(ah, ATH9K_CAP_TKIP_SPLIT,
  435. 0, NULL))
  436. common->splitmic = 1;
  437. /* turn on mcast key search if possible */
  438. if (!ath9k_hw_getcapability(ah, ATH9K_CAP_MCAST_KEYSRCH, 0, NULL))
  439. (void)ath9k_hw_setcapability(ah, ATH9K_CAP_MCAST_KEYSRCH, 1,
  440. 1, NULL);
  441. sc->config.txpowlimit = ATH_TXPOWER_MAX;
  442. /* 11n Capabilities */
  443. if (ah->caps.hw_caps & ATH9K_HW_CAP_HT) {
  444. sc->sc_flags |= SC_OP_TXAGGR;
  445. sc->sc_flags |= SC_OP_RXAGGR;
  446. }
  447. common->tx_chainmask = ah->caps.tx_chainmask;
  448. common->rx_chainmask = ah->caps.rx_chainmask;
  449. ath9k_hw_setcapability(ah, ATH9K_CAP_DIVERSITY, 1, true, NULL);
  450. sc->rx.defant = ath9k_hw_getdefantenna(ah);
  451. if (ah->caps.hw_caps & ATH9K_HW_CAP_BSSIDMASK)
  452. memcpy(common->bssidmask, ath_bcast_mac, ETH_ALEN);
  453. sc->beacon.slottime = ATH9K_SLOT_TIME_9; /* default to short slot time */
  454. /* initialize beacon slots */
  455. for (i = 0; i < ARRAY_SIZE(sc->beacon.bslot); i++) {
  456. sc->beacon.bslot[i] = NULL;
  457. sc->beacon.bslot_aphy[i] = NULL;
  458. }
  459. /* setup channels and rates */
  460. if (test_bit(ATH9K_MODE_11G, sc->sc_ah->caps.wireless_modes)) {
  461. sc->sbands[IEEE80211_BAND_2GHZ].channels = ath9k_2ghz_chantable;
  462. sc->sbands[IEEE80211_BAND_2GHZ].band = IEEE80211_BAND_2GHZ;
  463. sc->sbands[IEEE80211_BAND_2GHZ].n_channels =
  464. ARRAY_SIZE(ath9k_2ghz_chantable);
  465. sc->sbands[IEEE80211_BAND_2GHZ].bitrates = ath9k_legacy_rates;
  466. sc->sbands[IEEE80211_BAND_2GHZ].n_bitrates =
  467. ARRAY_SIZE(ath9k_legacy_rates);
  468. }
  469. if (test_bit(ATH9K_MODE_11A, sc->sc_ah->caps.wireless_modes)) {
  470. sc->sbands[IEEE80211_BAND_5GHZ].channels = ath9k_5ghz_chantable;
  471. sc->sbands[IEEE80211_BAND_5GHZ].band = IEEE80211_BAND_5GHZ;
  472. sc->sbands[IEEE80211_BAND_5GHZ].n_channels =
  473. ARRAY_SIZE(ath9k_5ghz_chantable);
  474. sc->sbands[IEEE80211_BAND_5GHZ].bitrates =
  475. ath9k_legacy_rates + 4;
  476. sc->sbands[IEEE80211_BAND_5GHZ].n_bitrates =
  477. ARRAY_SIZE(ath9k_legacy_rates) - 4;
  478. }
  479. switch (ah->btcoex_hw.scheme) {
  480. case ATH_BTCOEX_CFG_NONE:
  481. break;
  482. case ATH_BTCOEX_CFG_2WIRE:
  483. ath9k_hw_btcoex_init_2wire(ah);
  484. break;
  485. case ATH_BTCOEX_CFG_3WIRE:
  486. ath9k_hw_btcoex_init_3wire(ah);
  487. r = ath_init_btcoex_timer(sc);
  488. if (r)
  489. goto bad2;
  490. qnum = ath_tx_get_qnum(sc, ATH9K_TX_QUEUE_DATA, ATH9K_WME_AC_BE);
  491. ath9k_hw_init_btcoex_hw(ah, qnum);
  492. sc->btcoex.bt_stomp_type = ATH_BTCOEX_STOMP_LOW;
  493. break;
  494. default:
  495. WARN_ON(1);
  496. break;
  497. }
  498. return 0;
  499. bad2:
  500. /* cleanup tx queues */
  501. for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++)
  502. if (ATH_TXQ_SETUP(sc, i))
  503. ath_tx_cleanupq(sc, &sc->tx.txq[i]);
  504. bad_free_hw:
  505. ath9k_uninit_hw(sc);
  506. return r;
  507. }
  508. void ath_set_hw_capab(struct ath_softc *sc, struct ieee80211_hw *hw)
  509. {
  510. hw->flags = IEEE80211_HW_RX_INCLUDES_FCS |
  511. IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING |
  512. IEEE80211_HW_SIGNAL_DBM |
  513. IEEE80211_HW_AMPDU_AGGREGATION |
  514. IEEE80211_HW_SUPPORTS_PS |
  515. IEEE80211_HW_PS_NULLFUNC_STACK |
  516. IEEE80211_HW_SPECTRUM_MGMT;
  517. if (AR_SREV_9160_10_OR_LATER(sc->sc_ah) || modparam_nohwcrypt)
  518. hw->flags |= IEEE80211_HW_MFP_CAPABLE;
  519. hw->wiphy->interface_modes =
  520. BIT(NL80211_IFTYPE_AP) |
  521. BIT(NL80211_IFTYPE_STATION) |
  522. BIT(NL80211_IFTYPE_ADHOC) |
  523. BIT(NL80211_IFTYPE_MESH_POINT);
  524. hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
  525. hw->queues = 4;
  526. hw->max_rates = 4;
  527. hw->channel_change_time = 5000;
  528. hw->max_listen_interval = 10;
  529. /* Hardware supports 10 but we use 4 */
  530. hw->max_rate_tries = 4;
  531. hw->sta_data_size = sizeof(struct ath_node);
  532. hw->vif_data_size = sizeof(struct ath_vif);
  533. hw->rate_control_algorithm = "ath9k_rate_control";
  534. if (test_bit(ATH9K_MODE_11G, sc->sc_ah->caps.wireless_modes))
  535. hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
  536. &sc->sbands[IEEE80211_BAND_2GHZ];
  537. if (test_bit(ATH9K_MODE_11A, sc->sc_ah->caps.wireless_modes))
  538. hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
  539. &sc->sbands[IEEE80211_BAND_5GHZ];
  540. }
  541. /* Device driver core initialization */
  542. int ath_init_device(u16 devid, struct ath_softc *sc, u16 subsysid,
  543. const struct ath_bus_ops *bus_ops)
  544. {
  545. struct ieee80211_hw *hw = sc->hw;
  546. struct ath_common *common;
  547. struct ath_hw *ah;
  548. int error = 0, i;
  549. struct ath_regulatory *reg;
  550. dev_dbg(sc->dev, "Attach ATH hw\n");
  551. error = ath_init_softc(devid, sc, subsysid, bus_ops);
  552. if (error != 0)
  553. return error;
  554. ah = sc->sc_ah;
  555. common = ath9k_hw_common(ah);
  556. /* get mac address from hardware and set in mac80211 */
  557. SET_IEEE80211_PERM_ADDR(hw, common->macaddr);
  558. ath_set_hw_capab(sc, hw);
  559. error = ath_regd_init(&common->regulatory, sc->hw->wiphy,
  560. ath9k_reg_notifier);
  561. if (error)
  562. return error;
  563. reg = &common->regulatory;
  564. if (ah->caps.hw_caps & ATH9K_HW_CAP_HT) {
  565. if (test_bit(ATH9K_MODE_11G, ah->caps.wireless_modes))
  566. setup_ht_cap(sc,
  567. &sc->sbands[IEEE80211_BAND_2GHZ].ht_cap);
  568. if (test_bit(ATH9K_MODE_11A, ah->caps.wireless_modes))
  569. setup_ht_cap(sc,
  570. &sc->sbands[IEEE80211_BAND_5GHZ].ht_cap);
  571. }
  572. /* initialize tx/rx engine */
  573. error = ath_tx_init(sc, ATH_TXBUF);
  574. if (error != 0)
  575. goto error_attach;
  576. error = ath_rx_init(sc, ATH_RXBUF);
  577. if (error != 0)
  578. goto error_attach;
  579. INIT_WORK(&sc->chan_work, ath9k_wiphy_chan_work);
  580. INIT_DELAYED_WORK(&sc->wiphy_work, ath9k_wiphy_work);
  581. sc->wiphy_scheduler_int = msecs_to_jiffies(500);
  582. error = ieee80211_register_hw(hw);
  583. if (!ath_is_world_regd(reg)) {
  584. error = regulatory_hint(hw->wiphy, reg->alpha2);
  585. if (error)
  586. goto error_attach;
  587. }
  588. /* Initialize LED control */
  589. ath_init_leds(sc);
  590. ath_start_rfkill_poll(sc);
  591. return 0;
  592. error_attach:
  593. /* cleanup tx queues */
  594. for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++)
  595. if (ATH_TXQ_SETUP(sc, i))
  596. ath_tx_cleanupq(sc, &sc->tx.txq[i]);
  597. ath9k_uninit_hw(sc);
  598. return error;
  599. }
  600. /*****************************/
  601. /* De-Initialization */
  602. /*****************************/
  603. static void ath9k_uninit_hw(struct ath_softc *sc)
  604. {
  605. struct ath_hw *ah = sc->sc_ah;
  606. BUG_ON(!ah);
  607. ath9k_exit_debug(ah);
  608. ath9k_hw_detach(ah);
  609. sc->sc_ah = NULL;
  610. }
  611. static void ath_clean_core(struct ath_softc *sc)
  612. {
  613. struct ieee80211_hw *hw = sc->hw;
  614. struct ath_hw *ah = sc->sc_ah;
  615. int i = 0;
  616. ath9k_ps_wakeup(sc);
  617. dev_dbg(sc->dev, "Detach ATH hw\n");
  618. ath_deinit_leds(sc);
  619. wiphy_rfkill_stop_polling(sc->hw->wiphy);
  620. for (i = 0; i < sc->num_sec_wiphy; i++) {
  621. struct ath_wiphy *aphy = sc->sec_wiphy[i];
  622. if (aphy == NULL)
  623. continue;
  624. sc->sec_wiphy[i] = NULL;
  625. ieee80211_unregister_hw(aphy->hw);
  626. ieee80211_free_hw(aphy->hw);
  627. }
  628. ieee80211_unregister_hw(hw);
  629. ath_rx_cleanup(sc);
  630. ath_tx_cleanup(sc);
  631. tasklet_kill(&sc->intr_tq);
  632. tasklet_kill(&sc->bcon_tasklet);
  633. if (!(sc->sc_flags & SC_OP_INVALID))
  634. ath9k_setpower(sc, ATH9K_PM_AWAKE);
  635. /* cleanup tx queues */
  636. for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++)
  637. if (ATH_TXQ_SETUP(sc, i))
  638. ath_tx_cleanupq(sc, &sc->tx.txq[i]);
  639. if ((sc->btcoex.no_stomp_timer) &&
  640. ah->btcoex_hw.scheme == ATH_BTCOEX_CFG_3WIRE)
  641. ath_gen_timer_free(ah, sc->btcoex.no_stomp_timer);
  642. }
  643. void ath_descdma_cleanup(struct ath_softc *sc,
  644. struct ath_descdma *dd,
  645. struct list_head *head)
  646. {
  647. dma_free_coherent(sc->dev, dd->dd_desc_len, dd->dd_desc,
  648. dd->dd_desc_paddr);
  649. INIT_LIST_HEAD(head);
  650. kfree(dd->dd_bufptr);
  651. memset(dd, 0, sizeof(*dd));
  652. }
  653. void ath_detach(struct ath_softc *sc)
  654. {
  655. ath_clean_core(sc);
  656. ath9k_uninit_hw(sc);
  657. }
  658. void ath_cleanup(struct ath_softc *sc)
  659. {
  660. struct ath_hw *ah = sc->sc_ah;
  661. struct ath_common *common = ath9k_hw_common(ah);
  662. ath_clean_core(sc);
  663. free_irq(sc->irq, sc);
  664. ath_bus_cleanup(common);
  665. kfree(sc->sec_wiphy);
  666. ieee80211_free_hw(sc->hw);
  667. ath9k_uninit_hw(sc);
  668. }
  669. /************************/
  670. /* Module Hooks */
  671. /************************/
  672. static int __init ath9k_init(void)
  673. {
  674. int error;
  675. /* Register rate control algorithm */
  676. error = ath_rate_control_register();
  677. if (error != 0) {
  678. printk(KERN_ERR
  679. "ath9k: Unable to register rate control "
  680. "algorithm: %d\n",
  681. error);
  682. goto err_out;
  683. }
  684. error = ath9k_debug_create_root();
  685. if (error) {
  686. printk(KERN_ERR
  687. "ath9k: Unable to create debugfs root: %d\n",
  688. error);
  689. goto err_rate_unregister;
  690. }
  691. error = ath_pci_init();
  692. if (error < 0) {
  693. printk(KERN_ERR
  694. "ath9k: No PCI devices found, driver not installed.\n");
  695. error = -ENODEV;
  696. goto err_remove_root;
  697. }
  698. error = ath_ahb_init();
  699. if (error < 0) {
  700. error = -ENODEV;
  701. goto err_pci_exit;
  702. }
  703. return 0;
  704. err_pci_exit:
  705. ath_pci_exit();
  706. err_remove_root:
  707. ath9k_debug_remove_root();
  708. err_rate_unregister:
  709. ath_rate_control_unregister();
  710. err_out:
  711. return error;
  712. }
  713. module_init(ath9k_init);
  714. static void __exit ath9k_exit(void)
  715. {
  716. ath_ahb_exit();
  717. ath_pci_exit();
  718. ath9k_debug_remove_root();
  719. ath_rate_control_unregister();
  720. printk(KERN_INFO "%s: Driver unloaded\n", dev_info);
  721. }
  722. module_exit(ath9k_exit);