init.c 27 KB

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