Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

ath5k_reset.c 31KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176
  1. /*
  2. * Copyright (c) 2004-2008 Reyk Floeter <reyk@openbsd.org>
  3. * Copyright (c) 2006-2008 Nick Kossifidis <mickflemm@gmail.com>
  4. * Copyright (c) 2007-2008 Luis Rodriguez <mcgrof@winlab.rutgers.edu>
  5. * Copyright (c) 2007-2008 Pavel Roskin <proski@gnu.org>
  6. * Copyright (c) 2007-2008 Jiri Slaby <jirislaby@gmail.com>
  7. *
  8. * Lightly modified for gPXE, July 2009, by Joshua Oreman <oremanj@rwcr.net>.
  9. *
  10. * Permission to use, copy, modify, and distribute this software for any
  11. * purpose with or without fee is hereby granted, provided that the above
  12. * copyright notice and this permission notice appear in all copies.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  15. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  16. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  17. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  18. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  19. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  20. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  21. *
  22. */
  23. FILE_LICENCE ( MIT );
  24. #define _ATH5K_RESET
  25. /*****************************\
  26. Reset functions and helpers
  27. \*****************************/
  28. #include <gpxe/pci.h> /* To determine if a card is pci-e */
  29. #include <unistd.h>
  30. #include "ath5k.h"
  31. #include "reg.h"
  32. #include "base.h"
  33. /* Find last set bit; fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32 */
  34. static int fls(int x)
  35. {
  36. int r = 32;
  37. if (!x)
  38. return 0;
  39. if (!(x & 0xffff0000u)) {
  40. x <<= 16;
  41. r -= 16;
  42. }
  43. if (!(x & 0xff000000u)) {
  44. x <<= 8;
  45. r -= 8;
  46. }
  47. if (!(x & 0xf0000000u)) {
  48. x <<= 4;
  49. r -= 4;
  50. }
  51. if (!(x & 0xc0000000u)) {
  52. x <<= 2;
  53. r -= 2;
  54. }
  55. if (!(x & 0x80000000u)) {
  56. x <<= 1;
  57. r -= 1;
  58. }
  59. return r;
  60. }
  61. /**
  62. * ath5k_hw_write_ofdm_timings - set OFDM timings on AR5212
  63. *
  64. * @ah: the &struct ath5k_hw
  65. * @channel: the currently set channel upon reset
  66. *
  67. * Write the delta slope coefficient (used on pilot tracking ?) for OFDM
  68. * operation on the AR5212 upon reset. This is a helper for ath5k_hw_reset().
  69. *
  70. * Since delta slope is floating point we split it on its exponent and
  71. * mantissa and provide these values on hw.
  72. *
  73. * For more infos i think this patent is related
  74. * http://www.freepatentsonline.com/7184495.html
  75. */
  76. static int ath5k_hw_write_ofdm_timings(struct ath5k_hw *ah,
  77. struct net80211_channel *channel)
  78. {
  79. /* Get exponent and mantissa and set it */
  80. u32 coef_scaled, coef_exp, coef_man,
  81. ds_coef_exp, ds_coef_man, clock;
  82. if (!(ah->ah_version == AR5K_AR5212) ||
  83. !(channel->hw_value & CHANNEL_OFDM)) {
  84. DBG("ath5k: attempt to set OFDM timings on non-OFDM channel\n");
  85. return -EFAULT;
  86. }
  87. /* Get coefficient
  88. * ALGO: coef = (5 * clock * carrier_freq) / 2)
  89. * we scale coef by shifting clock value by 24 for
  90. * better precision since we use integers */
  91. /* TODO: Half/quarter rate */
  92. clock = ath5k_hw_htoclock(1, channel->hw_value & CHANNEL_TURBO);
  93. coef_scaled = ((5 * (clock << 24)) / 2) / channel->center_freq;
  94. /* Get exponent
  95. * ALGO: coef_exp = 14 - highest set bit position */
  96. coef_exp = fls(coef_scaled) - 1;
  97. /* Doesn't make sense if it's zero*/
  98. if (!coef_scaled || !coef_exp)
  99. return -EINVAL;
  100. /* Note: we've shifted coef_scaled by 24 */
  101. coef_exp = 14 - (coef_exp - 24);
  102. /* Get mantissa (significant digits)
  103. * ALGO: coef_mant = floor(coef_scaled* 2^coef_exp+0.5) */
  104. coef_man = coef_scaled +
  105. (1 << (24 - coef_exp - 1));
  106. /* Calculate delta slope coefficient exponent
  107. * and mantissa (remove scaling) and set them on hw */
  108. ds_coef_man = coef_man >> (24 - coef_exp);
  109. ds_coef_exp = coef_exp - 16;
  110. AR5K_REG_WRITE_BITS(ah, AR5K_PHY_TIMING_3,
  111. AR5K_PHY_TIMING_3_DSC_MAN, ds_coef_man);
  112. AR5K_REG_WRITE_BITS(ah, AR5K_PHY_TIMING_3,
  113. AR5K_PHY_TIMING_3_DSC_EXP, ds_coef_exp);
  114. return 0;
  115. }
  116. /*
  117. * index into rates for control rates, we can set it up like this because
  118. * this is only used for AR5212 and we know it supports G mode
  119. */
  120. static const unsigned int control_rates[] =
  121. { 0, 1, 1, 1, 4, 4, 6, 6, 8, 8, 8, 8 };
  122. /**
  123. * ath5k_hw_write_rate_duration - fill rate code to duration table
  124. *
  125. * @ah: the &struct ath5k_hw
  126. * @mode: one of enum ath5k_driver_mode
  127. *
  128. * Write the rate code to duration table upon hw reset. This is a helper for
  129. * ath5k_hw_reset(). It seems all this is doing is setting an ACK timeout on
  130. * the hardware, based on current mode, for each rate. The rates which are
  131. * capable of short preamble (802.11b rates 2Mbps, 5.5Mbps, and 11Mbps) have
  132. * different rate code so we write their value twice (one for long preample
  133. * and one for short).
  134. *
  135. * Note: Band doesn't matter here, if we set the values for OFDM it works
  136. * on both a and g modes. So all we have to do is set values for all g rates
  137. * that include all OFDM and CCK rates. If we operate in turbo or xr/half/
  138. * quarter rate mode, we need to use another set of bitrates (that's why we
  139. * need the mode parameter) but we don't handle these proprietary modes yet.
  140. */
  141. static inline void ath5k_hw_write_rate_duration(struct ath5k_hw *ah,
  142. unsigned int mode __unused)
  143. {
  144. struct ath5k_softc *sc = ah->ah_sc;
  145. u16 rate;
  146. int i;
  147. /* Write rate duration table */
  148. for (i = 0; i < sc->hwinfo->nr_rates[NET80211_BAND_2GHZ]; i++) {
  149. u32 reg;
  150. u16 tx_time;
  151. rate = sc->hwinfo->rates[NET80211_BAND_2GHZ][i];
  152. /* Set ACK timeout */
  153. reg = AR5K_RATE_DUR(ath5k_bitrate_to_hw_rix(rate));
  154. /* An ACK frame consists of 10 bytes. If you add the FCS,
  155. * it's 14 bytes. Note we use the control rate and not the
  156. * actual rate for this rate. See mac80211 tx.c
  157. * ieee80211_duration() for a brief description of
  158. * what rate we should choose to TX ACKs. */
  159. tx_time = net80211_duration(sc->dev, 14, rate);
  160. ath5k_hw_reg_write(ah, tx_time, reg);
  161. if (rate != 20 && rate != 55 && rate != 110)
  162. continue;
  163. /*
  164. * We're not distinguishing short preamble here,
  165. * This is true, all we'll get is a longer value here
  166. * which is not necessarilly bad.
  167. */
  168. ath5k_hw_reg_write(ah, tx_time,
  169. reg + (AR5K_SET_SHORT_PREAMBLE << 2));
  170. }
  171. }
  172. /*
  173. * Reset chipset
  174. */
  175. static int ath5k_hw_nic_reset(struct ath5k_hw *ah, u32 val)
  176. {
  177. int ret;
  178. u32 mask = val ? val : ~0U;
  179. /* Read-and-clear RX Descriptor Pointer*/
  180. ath5k_hw_reg_read(ah, AR5K_RXDP);
  181. /*
  182. * Reset the device and wait until success
  183. */
  184. ath5k_hw_reg_write(ah, val, AR5K_RESET_CTL);
  185. /* Wait at least 128 PCI clocks */
  186. udelay(15);
  187. if (ah->ah_version == AR5K_AR5210) {
  188. val &= AR5K_RESET_CTL_PCU | AR5K_RESET_CTL_DMA
  189. | AR5K_RESET_CTL_MAC | AR5K_RESET_CTL_PHY;
  190. mask &= AR5K_RESET_CTL_PCU | AR5K_RESET_CTL_DMA
  191. | AR5K_RESET_CTL_MAC | AR5K_RESET_CTL_PHY;
  192. } else {
  193. val &= AR5K_RESET_CTL_PCU | AR5K_RESET_CTL_BASEBAND;
  194. mask &= AR5K_RESET_CTL_PCU | AR5K_RESET_CTL_BASEBAND;
  195. }
  196. ret = ath5k_hw_register_timeout(ah, AR5K_RESET_CTL, mask, val, 0);
  197. /*
  198. * Reset configuration register (for hw byte-swap). Note that this
  199. * is only set for big endian. We do the necessary magic in
  200. * AR5K_INIT_CFG.
  201. */
  202. if ((val & AR5K_RESET_CTL_PCU) == 0)
  203. ath5k_hw_reg_write(ah, AR5K_INIT_CFG, AR5K_CFG);
  204. return ret;
  205. }
  206. /*
  207. * Sleep control
  208. */
  209. int ath5k_hw_wake(struct ath5k_hw *ah)
  210. {
  211. unsigned int i;
  212. u32 staid, data;
  213. staid = ath5k_hw_reg_read(ah, AR5K_STA_ID1);
  214. staid &= ~AR5K_STA_ID1_PWR_SV;
  215. /* Preserve sleep duration */
  216. data = ath5k_hw_reg_read(ah, AR5K_SLEEP_CTL);
  217. if (data & 0xffc00000)
  218. data = 0;
  219. else
  220. data = data & 0xfffcffff;
  221. ath5k_hw_reg_write(ah, data, AR5K_SLEEP_CTL);
  222. udelay(15);
  223. for (i = 50; i > 0; i--) {
  224. /* Check if the chip did wake up */
  225. if ((ath5k_hw_reg_read(ah, AR5K_PCICFG) &
  226. AR5K_PCICFG_SPWR_DN) == 0)
  227. break;
  228. /* Wait a bit and retry */
  229. udelay(200);
  230. ath5k_hw_reg_write(ah, data, AR5K_SLEEP_CTL);
  231. }
  232. /* Fail if the chip didn't wake up */
  233. if (i <= 0)
  234. return -EIO;
  235. ath5k_hw_reg_write(ah, staid, AR5K_STA_ID1);
  236. return 0;
  237. }
  238. /*
  239. * Bring up MAC + PHY Chips and program PLL
  240. * TODO: Half/Quarter rate support
  241. */
  242. int ath5k_hw_nic_wakeup(struct ath5k_hw *ah, int flags, int initial __unused)
  243. {
  244. struct pci_device *pdev = ah->ah_sc->pdev;
  245. u32 turbo, mode, clock, bus_flags;
  246. int ret;
  247. turbo = 0;
  248. mode = 0;
  249. clock = 0;
  250. /* Wakeup the device */
  251. ret = ath5k_hw_wake(ah);
  252. if (ret) {
  253. DBG("ath5k: failed to wake up the MAC chip\n");
  254. return ret;
  255. }
  256. if (ah->ah_version != AR5K_AR5210) {
  257. /*
  258. * Get channel mode flags
  259. */
  260. if (ah->ah_radio >= AR5K_RF5112) {
  261. mode = AR5K_PHY_MODE_RAD_RF5112;
  262. clock = AR5K_PHY_PLL_RF5112;
  263. } else {
  264. mode = AR5K_PHY_MODE_RAD_RF5111; /*Zero*/
  265. clock = AR5K_PHY_PLL_RF5111; /*Zero*/
  266. }
  267. if (flags & CHANNEL_2GHZ) {
  268. mode |= AR5K_PHY_MODE_FREQ_2GHZ;
  269. clock |= AR5K_PHY_PLL_44MHZ;
  270. if (flags & CHANNEL_CCK) {
  271. mode |= AR5K_PHY_MODE_MOD_CCK;
  272. } else if (flags & CHANNEL_OFDM) {
  273. /* XXX Dynamic OFDM/CCK is not supported by the
  274. * AR5211 so we set MOD_OFDM for plain g (no
  275. * CCK headers) operation. We need to test
  276. * this, 5211 might support ofdm-only g after
  277. * all, there are also initial register values
  278. * in the code for g mode (see initvals.c). */
  279. if (ah->ah_version == AR5K_AR5211)
  280. mode |= AR5K_PHY_MODE_MOD_OFDM;
  281. else
  282. mode |= AR5K_PHY_MODE_MOD_DYN;
  283. } else {
  284. DBG("ath5k: invalid radio modulation mode\n");
  285. return -EINVAL;
  286. }
  287. } else if (flags & CHANNEL_5GHZ) {
  288. mode |= AR5K_PHY_MODE_FREQ_5GHZ;
  289. if (ah->ah_radio == AR5K_RF5413)
  290. clock = AR5K_PHY_PLL_40MHZ_5413;
  291. else
  292. clock |= AR5K_PHY_PLL_40MHZ;
  293. if (flags & CHANNEL_OFDM)
  294. mode |= AR5K_PHY_MODE_MOD_OFDM;
  295. else {
  296. DBG("ath5k: invalid radio modulation mode\n");
  297. return -EINVAL;
  298. }
  299. } else {
  300. DBG("ath5k: invalid radio frequency mode\n");
  301. return -EINVAL;
  302. }
  303. if (flags & CHANNEL_TURBO)
  304. turbo = AR5K_PHY_TURBO_MODE | AR5K_PHY_TURBO_SHORT;
  305. } else { /* Reset the device */
  306. /* ...enable Atheros turbo mode if requested */
  307. if (flags & CHANNEL_TURBO)
  308. ath5k_hw_reg_write(ah, AR5K_PHY_TURBO_MODE,
  309. AR5K_PHY_TURBO);
  310. }
  311. /* reseting PCI on PCI-E cards results card to hang
  312. * and always return 0xffff... so we ingore that flag
  313. * for PCI-E cards */
  314. if (pci_find_capability(pdev, PCI_CAP_ID_EXP))
  315. bus_flags = 0;
  316. else
  317. bus_flags = AR5K_RESET_CTL_PCI;
  318. /* Reset chipset */
  319. if (ah->ah_version == AR5K_AR5210) {
  320. ret = ath5k_hw_nic_reset(ah, AR5K_RESET_CTL_PCU |
  321. AR5K_RESET_CTL_MAC | AR5K_RESET_CTL_DMA |
  322. AR5K_RESET_CTL_PHY | AR5K_RESET_CTL_PCI);
  323. mdelay(2);
  324. } else {
  325. ret = ath5k_hw_nic_reset(ah, AR5K_RESET_CTL_PCU |
  326. AR5K_RESET_CTL_BASEBAND | bus_flags);
  327. }
  328. if (ret) {
  329. DBG("ath5k: failed to reset the MAC chip\n");
  330. return -EIO;
  331. }
  332. /* ...wakeup again!*/
  333. ret = ath5k_hw_wake(ah);
  334. if (ret) {
  335. DBG("ath5k: failed to resume the MAC chip\n");
  336. return ret;
  337. }
  338. /* ...final warm reset */
  339. if (ath5k_hw_nic_reset(ah, 0)) {
  340. DBG("ath5k: failed to warm reset the MAC chip\n");
  341. return -EIO;
  342. }
  343. if (ah->ah_version != AR5K_AR5210) {
  344. /* ...update PLL if needed */
  345. if (ath5k_hw_reg_read(ah, AR5K_PHY_PLL) != clock) {
  346. ath5k_hw_reg_write(ah, clock, AR5K_PHY_PLL);
  347. udelay(300);
  348. }
  349. /* ...set the PHY operating mode */
  350. ath5k_hw_reg_write(ah, mode, AR5K_PHY_MODE);
  351. ath5k_hw_reg_write(ah, turbo, AR5K_PHY_TURBO);
  352. }
  353. return 0;
  354. }
  355. static int ath5k_hw_chan_has_spur_noise(struct ath5k_hw *ah,
  356. struct net80211_channel *channel)
  357. {
  358. u8 refclk_freq;
  359. if ((ah->ah_radio == AR5K_RF5112) ||
  360. (ah->ah_radio == AR5K_RF5413) ||
  361. (ah->ah_mac_version == (AR5K_SREV_AR2417 >> 4)))
  362. refclk_freq = 40;
  363. else
  364. refclk_freq = 32;
  365. if ((channel->center_freq % refclk_freq != 0) &&
  366. ((channel->center_freq % refclk_freq < 10) ||
  367. (channel->center_freq % refclk_freq > 22)))
  368. return 1;
  369. else
  370. return 0;
  371. }
  372. /* TODO: Half/Quarter rate */
  373. static void ath5k_hw_tweak_initval_settings(struct ath5k_hw *ah,
  374. struct net80211_channel *channel)
  375. {
  376. if (ah->ah_version == AR5K_AR5212 &&
  377. ah->ah_phy_revision >= AR5K_SREV_PHY_5212A) {
  378. /* Setup ADC control */
  379. ath5k_hw_reg_write(ah,
  380. (AR5K_REG_SM(2,
  381. AR5K_PHY_ADC_CTL_INBUFGAIN_OFF) |
  382. AR5K_REG_SM(2,
  383. AR5K_PHY_ADC_CTL_INBUFGAIN_ON) |
  384. AR5K_PHY_ADC_CTL_PWD_DAC_OFF |
  385. AR5K_PHY_ADC_CTL_PWD_ADC_OFF),
  386. AR5K_PHY_ADC_CTL);
  387. /* Disable barker RSSI threshold */
  388. AR5K_REG_DISABLE_BITS(ah, AR5K_PHY_DAG_CCK_CTL,
  389. AR5K_PHY_DAG_CCK_CTL_EN_RSSI_THR);
  390. AR5K_REG_WRITE_BITS(ah, AR5K_PHY_DAG_CCK_CTL,
  391. AR5K_PHY_DAG_CCK_CTL_RSSI_THR, 2);
  392. /* Set the mute mask */
  393. ath5k_hw_reg_write(ah, 0x0000000f, AR5K_SEQ_MASK);
  394. }
  395. /* Clear PHY_BLUETOOTH to allow RX_CLEAR line debug */
  396. if (ah->ah_phy_revision >= AR5K_SREV_PHY_5212B)
  397. ath5k_hw_reg_write(ah, 0, AR5K_PHY_BLUETOOTH);
  398. /* Enable DCU double buffering */
  399. if (ah->ah_phy_revision > AR5K_SREV_PHY_5212B)
  400. AR5K_REG_DISABLE_BITS(ah, AR5K_TXCFG,
  401. AR5K_TXCFG_DCU_DBL_BUF_DIS);
  402. /* Set DAC/ADC delays */
  403. if (ah->ah_version == AR5K_AR5212) {
  404. u32 scal;
  405. if (ah->ah_mac_version == (AR5K_SREV_AR2417 >> 4))
  406. scal = AR5K_PHY_SCAL_32MHZ_2417;
  407. else if (ath5k_eeprom_is_hb63(ah))
  408. scal = AR5K_PHY_SCAL_32MHZ_HB63;
  409. else
  410. scal = AR5K_PHY_SCAL_32MHZ;
  411. ath5k_hw_reg_write(ah, scal, AR5K_PHY_SCAL);
  412. }
  413. /* Set fast ADC */
  414. if ((ah->ah_radio == AR5K_RF5413) ||
  415. (ah->ah_mac_version == (AR5K_SREV_AR2417 >> 4))) {
  416. u32 fast_adc = 1;
  417. if (channel->center_freq == 2462 ||
  418. channel->center_freq == 2467)
  419. fast_adc = 0;
  420. /* Only update if needed */
  421. if (ath5k_hw_reg_read(ah, AR5K_PHY_FAST_ADC) != fast_adc)
  422. ath5k_hw_reg_write(ah, fast_adc,
  423. AR5K_PHY_FAST_ADC);
  424. }
  425. /* Fix for first revision of the RF5112 RF chipset */
  426. if (ah->ah_radio == AR5K_RF5112 &&
  427. ah->ah_radio_5ghz_revision <
  428. AR5K_SREV_RAD_5112A) {
  429. u32 data;
  430. ath5k_hw_reg_write(ah, AR5K_PHY_CCKTXCTL_WORLD,
  431. AR5K_PHY_CCKTXCTL);
  432. if (channel->hw_value & CHANNEL_5GHZ)
  433. data = 0xffb81020;
  434. else
  435. data = 0xffb80d20;
  436. ath5k_hw_reg_write(ah, data, AR5K_PHY_FRAME_CTL);
  437. }
  438. if (ah->ah_mac_srev < AR5K_SREV_AR5211) {
  439. u32 usec_reg;
  440. /* 5311 has different tx/rx latency masks
  441. * from 5211, since we deal 5311 the same
  442. * as 5211 when setting initvals, shift
  443. * values here to their proper locations */
  444. usec_reg = ath5k_hw_reg_read(ah, AR5K_USEC_5211);
  445. ath5k_hw_reg_write(ah, usec_reg & (AR5K_USEC_1 |
  446. AR5K_USEC_32 |
  447. AR5K_USEC_TX_LATENCY_5211 |
  448. AR5K_REG_SM(29,
  449. AR5K_USEC_RX_LATENCY_5210)),
  450. AR5K_USEC_5211);
  451. /* Clear QCU/DCU clock gating register */
  452. ath5k_hw_reg_write(ah, 0, AR5K_QCUDCU_CLKGT);
  453. /* Set DAC/ADC delays */
  454. ath5k_hw_reg_write(ah, 0x08, AR5K_PHY_SCAL);
  455. /* Enable PCU FIFO corruption ECO */
  456. AR5K_REG_ENABLE_BITS(ah, AR5K_DIAG_SW_5211,
  457. AR5K_DIAG_SW_ECO_ENABLE);
  458. }
  459. }
  460. static void ath5k_hw_commit_eeprom_settings(struct ath5k_hw *ah,
  461. struct net80211_channel *channel, u8 *ant, u8 ee_mode)
  462. {
  463. struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
  464. s16 cck_ofdm_pwr_delta;
  465. /* Adjust power delta for channel 14 */
  466. if (channel->center_freq == 2484)
  467. cck_ofdm_pwr_delta =
  468. ((ee->ee_cck_ofdm_power_delta -
  469. ee->ee_scaled_cck_delta) * 2) / 10;
  470. else
  471. cck_ofdm_pwr_delta =
  472. (ee->ee_cck_ofdm_power_delta * 2) / 10;
  473. /* Set CCK to OFDM power delta on tx power
  474. * adjustment register */
  475. if (ah->ah_phy_revision >= AR5K_SREV_PHY_5212A) {
  476. if (channel->hw_value == CHANNEL_G)
  477. ath5k_hw_reg_write(ah,
  478. AR5K_REG_SM((ee->ee_cck_ofdm_gain_delta * -1),
  479. AR5K_PHY_TX_PWR_ADJ_CCK_GAIN_DELTA) |
  480. AR5K_REG_SM((cck_ofdm_pwr_delta * -1),
  481. AR5K_PHY_TX_PWR_ADJ_CCK_PCDAC_INDEX),
  482. AR5K_PHY_TX_PWR_ADJ);
  483. else
  484. ath5k_hw_reg_write(ah, 0, AR5K_PHY_TX_PWR_ADJ);
  485. } else {
  486. /* For older revs we scale power on sw during tx power
  487. * setup */
  488. ah->ah_txpower.txp_cck_ofdm_pwr_delta = cck_ofdm_pwr_delta;
  489. ah->ah_txpower.txp_cck_ofdm_gainf_delta =
  490. ee->ee_cck_ofdm_gain_delta;
  491. }
  492. /* Set antenna idle switch table */
  493. AR5K_REG_WRITE_BITS(ah, AR5K_PHY_ANT_CTL,
  494. AR5K_PHY_ANT_CTL_SWTABLE_IDLE,
  495. (ah->ah_antenna[ee_mode][0] |
  496. AR5K_PHY_ANT_CTL_TXRX_EN));
  497. /* Set antenna switch table */
  498. ath5k_hw_reg_write(ah, ah->ah_antenna[ee_mode][ant[0]],
  499. AR5K_PHY_ANT_SWITCH_TABLE_0);
  500. ath5k_hw_reg_write(ah, ah->ah_antenna[ee_mode][ant[1]],
  501. AR5K_PHY_ANT_SWITCH_TABLE_1);
  502. /* Noise floor threshold */
  503. ath5k_hw_reg_write(ah,
  504. AR5K_PHY_NF_SVAL(ee->ee_noise_floor_thr[ee_mode]),
  505. AR5K_PHY_NFTHRES);
  506. if ((channel->hw_value & CHANNEL_TURBO) &&
  507. (ah->ah_ee_version >= AR5K_EEPROM_VERSION_5_0)) {
  508. /* Switch settling time (Turbo) */
  509. AR5K_REG_WRITE_BITS(ah, AR5K_PHY_SETTLING,
  510. AR5K_PHY_SETTLING_SWITCH,
  511. ee->ee_switch_settling_turbo[ee_mode]);
  512. /* Tx/Rx attenuation (Turbo) */
  513. AR5K_REG_WRITE_BITS(ah, AR5K_PHY_GAIN,
  514. AR5K_PHY_GAIN_TXRX_ATTEN,
  515. ee->ee_atn_tx_rx_turbo[ee_mode]);
  516. /* ADC/PGA desired size (Turbo) */
  517. AR5K_REG_WRITE_BITS(ah, AR5K_PHY_DESIRED_SIZE,
  518. AR5K_PHY_DESIRED_SIZE_ADC,
  519. ee->ee_adc_desired_size_turbo[ee_mode]);
  520. AR5K_REG_WRITE_BITS(ah, AR5K_PHY_DESIRED_SIZE,
  521. AR5K_PHY_DESIRED_SIZE_PGA,
  522. ee->ee_pga_desired_size_turbo[ee_mode]);
  523. /* Tx/Rx margin (Turbo) */
  524. AR5K_REG_WRITE_BITS(ah, AR5K_PHY_GAIN_2GHZ,
  525. AR5K_PHY_GAIN_2GHZ_MARGIN_TXRX,
  526. ee->ee_margin_tx_rx_turbo[ee_mode]);
  527. } else {
  528. /* Switch settling time */
  529. AR5K_REG_WRITE_BITS(ah, AR5K_PHY_SETTLING,
  530. AR5K_PHY_SETTLING_SWITCH,
  531. ee->ee_switch_settling[ee_mode]);
  532. /* Tx/Rx attenuation */
  533. AR5K_REG_WRITE_BITS(ah, AR5K_PHY_GAIN,
  534. AR5K_PHY_GAIN_TXRX_ATTEN,
  535. ee->ee_atn_tx_rx[ee_mode]);
  536. /* ADC/PGA desired size */
  537. AR5K_REG_WRITE_BITS(ah, AR5K_PHY_DESIRED_SIZE,
  538. AR5K_PHY_DESIRED_SIZE_ADC,
  539. ee->ee_adc_desired_size[ee_mode]);
  540. AR5K_REG_WRITE_BITS(ah, AR5K_PHY_DESIRED_SIZE,
  541. AR5K_PHY_DESIRED_SIZE_PGA,
  542. ee->ee_pga_desired_size[ee_mode]);
  543. /* Tx/Rx margin */
  544. if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_1)
  545. AR5K_REG_WRITE_BITS(ah, AR5K_PHY_GAIN_2GHZ,
  546. AR5K_PHY_GAIN_2GHZ_MARGIN_TXRX,
  547. ee->ee_margin_tx_rx[ee_mode]);
  548. }
  549. /* XPA delays */
  550. ath5k_hw_reg_write(ah,
  551. (ee->ee_tx_end2xpa_disable[ee_mode] << 24) |
  552. (ee->ee_tx_end2xpa_disable[ee_mode] << 16) |
  553. (ee->ee_tx_frm2xpa_enable[ee_mode] << 8) |
  554. (ee->ee_tx_frm2xpa_enable[ee_mode]), AR5K_PHY_RF_CTL4);
  555. /* XLNA delay */
  556. AR5K_REG_WRITE_BITS(ah, AR5K_PHY_RF_CTL3,
  557. AR5K_PHY_RF_CTL3_TXE2XLNA_ON,
  558. ee->ee_tx_end2xlna_enable[ee_mode]);
  559. /* Thresh64 (ANI) */
  560. AR5K_REG_WRITE_BITS(ah, AR5K_PHY_NF,
  561. AR5K_PHY_NF_THRESH62,
  562. ee->ee_thr_62[ee_mode]);
  563. /* False detect backoff for channels
  564. * that have spur noise. Write the new
  565. * cyclic power RSSI threshold. */
  566. if (ath5k_hw_chan_has_spur_noise(ah, channel))
  567. AR5K_REG_WRITE_BITS(ah, AR5K_PHY_OFDM_SELFCORR,
  568. AR5K_PHY_OFDM_SELFCORR_CYPWR_THR1,
  569. AR5K_INIT_CYCRSSI_THR1 +
  570. ee->ee_false_detect[ee_mode]);
  571. else
  572. AR5K_REG_WRITE_BITS(ah, AR5K_PHY_OFDM_SELFCORR,
  573. AR5K_PHY_OFDM_SELFCORR_CYPWR_THR1,
  574. AR5K_INIT_CYCRSSI_THR1);
  575. /* I/Q correction
  576. * TODO: Per channel i/q infos ? */
  577. AR5K_REG_ENABLE_BITS(ah, AR5K_PHY_IQ,
  578. AR5K_PHY_IQ_CORR_ENABLE |
  579. (ee->ee_i_cal[ee_mode] << AR5K_PHY_IQ_CORR_Q_I_COFF_S) |
  580. ee->ee_q_cal[ee_mode]);
  581. /* Heavy clipping -disable for now */
  582. if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_5_1)
  583. ath5k_hw_reg_write(ah, 0, AR5K_PHY_HEAVY_CLIP_ENABLE);
  584. return;
  585. }
  586. /*
  587. * Main reset function
  588. */
  589. int ath5k_hw_reset(struct ath5k_hw *ah,
  590. struct net80211_channel *channel, int change_channel)
  591. {
  592. u32 s_seq[10], s_ant, s_led[3], staid1_flags, tsf_up, tsf_lo;
  593. u32 phy_tst1;
  594. u8 mode, freq, ee_mode, ant[2];
  595. int i, ret;
  596. s_ant = 0;
  597. ee_mode = 0;
  598. staid1_flags = 0;
  599. tsf_up = 0;
  600. tsf_lo = 0;
  601. freq = 0;
  602. mode = 0;
  603. /*
  604. * Save some registers before a reset
  605. */
  606. /*DCU/Antenna selection not available on 5210*/
  607. if (ah->ah_version != AR5K_AR5210) {
  608. switch (channel->hw_value & CHANNEL_MODES) {
  609. case CHANNEL_A:
  610. mode = AR5K_MODE_11A;
  611. freq = AR5K_INI_RFGAIN_5GHZ;
  612. ee_mode = AR5K_EEPROM_MODE_11A;
  613. break;
  614. case CHANNEL_G:
  615. mode = AR5K_MODE_11G;
  616. freq = AR5K_INI_RFGAIN_2GHZ;
  617. ee_mode = AR5K_EEPROM_MODE_11G;
  618. break;
  619. case CHANNEL_B:
  620. mode = AR5K_MODE_11B;
  621. freq = AR5K_INI_RFGAIN_2GHZ;
  622. ee_mode = AR5K_EEPROM_MODE_11B;
  623. break;
  624. case CHANNEL_T:
  625. mode = AR5K_MODE_11A_TURBO;
  626. freq = AR5K_INI_RFGAIN_5GHZ;
  627. ee_mode = AR5K_EEPROM_MODE_11A;
  628. break;
  629. case CHANNEL_TG:
  630. if (ah->ah_version == AR5K_AR5211) {
  631. DBG("ath5k: TurboG not available on 5211\n");
  632. return -EINVAL;
  633. }
  634. mode = AR5K_MODE_11G_TURBO;
  635. freq = AR5K_INI_RFGAIN_2GHZ;
  636. ee_mode = AR5K_EEPROM_MODE_11G;
  637. break;
  638. case CHANNEL_XR:
  639. if (ah->ah_version == AR5K_AR5211) {
  640. DBG("ath5k: XR mode not available on 5211\n");
  641. return -EINVAL;
  642. }
  643. mode = AR5K_MODE_XR;
  644. freq = AR5K_INI_RFGAIN_5GHZ;
  645. ee_mode = AR5K_EEPROM_MODE_11A;
  646. break;
  647. default:
  648. DBG("ath5k: invalid channel (%d MHz)\n",
  649. channel->center_freq);
  650. return -EINVAL;
  651. }
  652. if (change_channel) {
  653. /*
  654. * Save frame sequence count
  655. * For revs. after Oahu, only save
  656. * seq num for DCU 0 (Global seq num)
  657. */
  658. if (ah->ah_mac_srev < AR5K_SREV_AR5211) {
  659. for (i = 0; i < 10; i++)
  660. s_seq[i] = ath5k_hw_reg_read(ah,
  661. AR5K_QUEUE_DCU_SEQNUM(i));
  662. } else {
  663. s_seq[0] = ath5k_hw_reg_read(ah,
  664. AR5K_QUEUE_DCU_SEQNUM(0));
  665. }
  666. }
  667. /* Save default antenna */
  668. s_ant = ath5k_hw_reg_read(ah, AR5K_DEFAULT_ANTENNA);
  669. if (ah->ah_version == AR5K_AR5212) {
  670. /* Since we are going to write rf buffer
  671. * check if we have any pending gain_F
  672. * optimization settings */
  673. if (change_channel && ah->ah_rf_banks != NULL)
  674. ath5k_hw_gainf_calibrate(ah);
  675. }
  676. }
  677. /*GPIOs*/
  678. s_led[0] = ath5k_hw_reg_read(ah, AR5K_PCICFG) &
  679. AR5K_PCICFG_LEDSTATE;
  680. s_led[1] = ath5k_hw_reg_read(ah, AR5K_GPIOCR);
  681. s_led[2] = ath5k_hw_reg_read(ah, AR5K_GPIODO);
  682. /* AR5K_STA_ID1 flags, only preserve antenna
  683. * settings and ack/cts rate mode */
  684. staid1_flags = ath5k_hw_reg_read(ah, AR5K_STA_ID1) &
  685. (AR5K_STA_ID1_DEFAULT_ANTENNA |
  686. AR5K_STA_ID1_DESC_ANTENNA |
  687. AR5K_STA_ID1_RTS_DEF_ANTENNA |
  688. AR5K_STA_ID1_ACKCTS_6MB |
  689. AR5K_STA_ID1_BASE_RATE_11B |
  690. AR5K_STA_ID1_SELFGEN_DEF_ANT);
  691. /* Wakeup the device */
  692. ret = ath5k_hw_nic_wakeup(ah, channel->hw_value, 0);
  693. if (ret)
  694. return ret;
  695. /* PHY access enable */
  696. if (ah->ah_mac_srev >= AR5K_SREV_AR5211)
  697. ath5k_hw_reg_write(ah, AR5K_PHY_SHIFT_5GHZ, AR5K_PHY(0));
  698. else
  699. ath5k_hw_reg_write(ah, AR5K_PHY_SHIFT_5GHZ | 0x40,
  700. AR5K_PHY(0));
  701. /* Write initial settings */
  702. ret = ath5k_hw_write_initvals(ah, mode, change_channel);
  703. if (ret)
  704. return ret;
  705. /*
  706. * 5211/5212 Specific
  707. */
  708. if (ah->ah_version != AR5K_AR5210) {
  709. /*
  710. * Write initial RF gain settings
  711. * This should work for both 5111/5112
  712. */
  713. ret = ath5k_hw_rfgain_init(ah, freq);
  714. if (ret)
  715. return ret;
  716. mdelay(1);
  717. /*
  718. * Tweak initval settings for revised
  719. * chipsets and add some more config
  720. * bits
  721. */
  722. ath5k_hw_tweak_initval_settings(ah, channel);
  723. /*
  724. * Set TX power (FIXME)
  725. */
  726. ret = ath5k_hw_txpower(ah, channel, ee_mode,
  727. AR5K_TUNE_DEFAULT_TXPOWER);
  728. if (ret)
  729. return ret;
  730. /* Write rate duration table only on AR5212 */
  731. if (ah->ah_version == AR5K_AR5212)
  732. ath5k_hw_write_rate_duration(ah, mode);
  733. /*
  734. * Write RF buffer
  735. */
  736. ret = ath5k_hw_rfregs_init(ah, channel, mode);
  737. if (ret)
  738. return ret;
  739. /* Write OFDM timings on 5212*/
  740. if (ah->ah_version == AR5K_AR5212 &&
  741. channel->hw_value & CHANNEL_OFDM) {
  742. ret = ath5k_hw_write_ofdm_timings(ah, channel);
  743. if (ret)
  744. return ret;
  745. }
  746. /*Enable/disable 802.11b mode on 5111
  747. (enable 2111 frequency converter + CCK)*/
  748. if (ah->ah_radio == AR5K_RF5111) {
  749. if (mode == AR5K_MODE_11B)
  750. AR5K_REG_ENABLE_BITS(ah, AR5K_TXCFG,
  751. AR5K_TXCFG_B_MODE);
  752. else
  753. AR5K_REG_DISABLE_BITS(ah, AR5K_TXCFG,
  754. AR5K_TXCFG_B_MODE);
  755. }
  756. /*
  757. * In case a fixed antenna was set as default
  758. * write the same settings on both AR5K_PHY_ANT_SWITCH_TABLE
  759. * registers.
  760. */
  761. if (s_ant != 0) {
  762. if (s_ant == AR5K_ANT_FIXED_A) /* 1 - Main */
  763. ant[0] = ant[1] = AR5K_ANT_FIXED_A;
  764. else /* 2 - Aux */
  765. ant[0] = ant[1] = AR5K_ANT_FIXED_B;
  766. } else {
  767. ant[0] = AR5K_ANT_FIXED_A;
  768. ant[1] = AR5K_ANT_FIXED_B;
  769. }
  770. /* Commit values from EEPROM */
  771. ath5k_hw_commit_eeprom_settings(ah, channel, ant, ee_mode);
  772. } else {
  773. /*
  774. * For 5210 we do all initialization using
  775. * initvals, so we don't have to modify
  776. * any settings (5210 also only supports
  777. * a/aturbo modes)
  778. */
  779. mdelay(1);
  780. /* Disable phy and wait */
  781. ath5k_hw_reg_write(ah, AR5K_PHY_ACT_DISABLE, AR5K_PHY_ACT);
  782. mdelay(1);
  783. }
  784. /*
  785. * Restore saved values
  786. */
  787. /*DCU/Antenna selection not available on 5210*/
  788. if (ah->ah_version != AR5K_AR5210) {
  789. if (change_channel) {
  790. if (ah->ah_mac_srev < AR5K_SREV_AR5211) {
  791. for (i = 0; i < 10; i++)
  792. ath5k_hw_reg_write(ah, s_seq[i],
  793. AR5K_QUEUE_DCU_SEQNUM(i));
  794. } else {
  795. ath5k_hw_reg_write(ah, s_seq[0],
  796. AR5K_QUEUE_DCU_SEQNUM(0));
  797. }
  798. }
  799. ath5k_hw_reg_write(ah, s_ant, AR5K_DEFAULT_ANTENNA);
  800. }
  801. /* Ledstate */
  802. AR5K_REG_ENABLE_BITS(ah, AR5K_PCICFG, s_led[0]);
  803. /* Gpio settings */
  804. ath5k_hw_reg_write(ah, s_led[1], AR5K_GPIOCR);
  805. ath5k_hw_reg_write(ah, s_led[2], AR5K_GPIODO);
  806. /* Restore sta_id flags and preserve our mac address*/
  807. ath5k_hw_reg_write(ah, AR5K_LOW_ID(ah->ah_sta_id),
  808. AR5K_STA_ID0);
  809. ath5k_hw_reg_write(ah, staid1_flags | AR5K_HIGH_ID(ah->ah_sta_id),
  810. AR5K_STA_ID1);
  811. /*
  812. * Configure PCU
  813. */
  814. /* Restore bssid and bssid mask */
  815. /* XXX: add ah->aid once mac80211 gives this to us */
  816. ath5k_hw_set_associd(ah, ah->ah_bssid, 0);
  817. /* Set PCU config */
  818. ath5k_hw_set_opmode(ah);
  819. /* Clear any pending interrupts
  820. * PISR/SISR Not available on 5210 */
  821. if (ah->ah_version != AR5K_AR5210)
  822. ath5k_hw_reg_write(ah, 0xffffffff, AR5K_PISR);
  823. /* Set RSSI/BRSSI thresholds
  824. *
  825. * Note: If we decide to set this value
  826. * dynamicaly, have in mind that when AR5K_RSSI_THR
  827. * register is read it might return 0x40 if we haven't
  828. * wrote anything to it plus BMISS RSSI threshold is zeroed.
  829. * So doing a save/restore procedure here isn't the right
  830. * choice. Instead store it on ath5k_hw */
  831. ath5k_hw_reg_write(ah, (AR5K_TUNE_RSSI_THRES |
  832. AR5K_TUNE_BMISS_THRES <<
  833. AR5K_RSSI_THR_BMISS_S),
  834. AR5K_RSSI_THR);
  835. /* MIC QoS support */
  836. if (ah->ah_mac_srev >= AR5K_SREV_AR2413) {
  837. ath5k_hw_reg_write(ah, 0x000100aa, AR5K_MIC_QOS_CTL);
  838. ath5k_hw_reg_write(ah, 0x00003210, AR5K_MIC_QOS_SEL);
  839. }
  840. /* QoS NOACK Policy */
  841. if (ah->ah_version == AR5K_AR5212) {
  842. ath5k_hw_reg_write(ah,
  843. AR5K_REG_SM(2, AR5K_QOS_NOACK_2BIT_VALUES) |
  844. AR5K_REG_SM(5, AR5K_QOS_NOACK_BIT_OFFSET) |
  845. AR5K_REG_SM(0, AR5K_QOS_NOACK_BYTE_OFFSET),
  846. AR5K_QOS_NOACK);
  847. }
  848. /*
  849. * Configure PHY
  850. */
  851. /* Set channel on PHY */
  852. ret = ath5k_hw_channel(ah, channel);
  853. if (ret)
  854. return ret;
  855. /*
  856. * Enable the PHY and wait until completion
  857. * This includes BaseBand and Synthesizer
  858. * activation.
  859. */
  860. ath5k_hw_reg_write(ah, AR5K_PHY_ACT_ENABLE, AR5K_PHY_ACT);
  861. /*
  862. * On 5211+ read activation -> rx delay
  863. * and use it.
  864. *
  865. * TODO: Half/quarter rate support
  866. */
  867. if (ah->ah_version != AR5K_AR5210) {
  868. u32 delay;
  869. delay = ath5k_hw_reg_read(ah, AR5K_PHY_RX_DELAY) &
  870. AR5K_PHY_RX_DELAY_M;
  871. delay = (channel->hw_value & CHANNEL_CCK) ?
  872. ((delay << 2) / 22) : (delay / 10);
  873. udelay(100 + (2 * delay));
  874. } else {
  875. mdelay(1);
  876. }
  877. /*
  878. * Perform ADC test to see if baseband is ready
  879. * Set tx hold and check adc test register
  880. */
  881. phy_tst1 = ath5k_hw_reg_read(ah, AR5K_PHY_TST1);
  882. ath5k_hw_reg_write(ah, AR5K_PHY_TST1_TXHOLD, AR5K_PHY_TST1);
  883. for (i = 0; i <= 20; i++) {
  884. if (!(ath5k_hw_reg_read(ah, AR5K_PHY_ADC_TEST) & 0x10))
  885. break;
  886. udelay(200);
  887. }
  888. ath5k_hw_reg_write(ah, phy_tst1, AR5K_PHY_TST1);
  889. /*
  890. * Start automatic gain control calibration
  891. *
  892. * During AGC calibration RX path is re-routed to
  893. * a power detector so we don't receive anything.
  894. *
  895. * This method is used to calibrate some static offsets
  896. * used together with on-the fly I/Q calibration (the
  897. * one performed via ath5k_hw_phy_calibrate), that doesn't
  898. * interrupt rx path.
  899. *
  900. * While rx path is re-routed to the power detector we also
  901. * start a noise floor calibration, to measure the
  902. * card's noise floor (the noise we measure when we are not
  903. * transmiting or receiving anything).
  904. *
  905. * If we are in a noisy environment AGC calibration may time
  906. * out and/or noise floor calibration might timeout.
  907. */
  908. AR5K_REG_ENABLE_BITS(ah, AR5K_PHY_AGCCTL,
  909. AR5K_PHY_AGCCTL_CAL);
  910. /* At the same time start I/Q calibration for QAM constellation
  911. * -no need for CCK- */
  912. ah->ah_calibration = 0;
  913. if (!(mode == AR5K_MODE_11B)) {
  914. ah->ah_calibration = 1;
  915. AR5K_REG_WRITE_BITS(ah, AR5K_PHY_IQ,
  916. AR5K_PHY_IQ_CAL_NUM_LOG_MAX, 15);
  917. AR5K_REG_ENABLE_BITS(ah, AR5K_PHY_IQ,
  918. AR5K_PHY_IQ_RUN);
  919. }
  920. /* Wait for gain calibration to finish (we check for I/Q calibration
  921. * during ath5k_phy_calibrate) */
  922. if (ath5k_hw_register_timeout(ah, AR5K_PHY_AGCCTL,
  923. AR5K_PHY_AGCCTL_CAL, 0, 0)) {
  924. DBG("ath5k: gain calibration timeout (%d MHz)\n",
  925. channel->center_freq);
  926. }
  927. /*
  928. * If we run NF calibration before AGC, it always times out.
  929. * Binary HAL starts NF and AGC calibration at the same time
  930. * and only waits for AGC to finish. Also if AGC or NF cal.
  931. * times out, reset doesn't fail on binary HAL. I believe
  932. * that's wrong because since rx path is routed to a detector,
  933. * if cal. doesn't finish we won't have RX. Sam's HAL for AR5210/5211
  934. * enables noise floor calibration after offset calibration and if noise
  935. * floor calibration fails, reset fails. I believe that's
  936. * a better approach, we just need to find a polling interval
  937. * that suits best, even if reset continues we need to make
  938. * sure that rx path is ready.
  939. */
  940. ath5k_hw_noise_floor_calibration(ah, channel->center_freq);
  941. /*
  942. * Configure QCUs/DCUs
  943. */
  944. /* TODO: HW Compression support for data queues */
  945. /* TODO: Burst prefetch for data queues */
  946. /*
  947. * Reset queues and start beacon timers at the end of the reset routine
  948. * This also sets QCU mask on each DCU for 1:1 qcu to dcu mapping
  949. * Note: If we want we can assign multiple qcus on one dcu.
  950. */
  951. ret = ath5k_hw_reset_tx_queue(ah);
  952. if (ret) {
  953. DBG("ath5k: failed to reset TX queue\n");
  954. return ret;
  955. }
  956. /*
  957. * Configure DMA/Interrupts
  958. */
  959. /*
  960. * Set Rx/Tx DMA Configuration
  961. *
  962. * Set standard DMA size (128). Note that
  963. * a DMA size of 512 causes rx overruns and tx errors
  964. * on pci-e cards (tested on 5424 but since rx overruns
  965. * also occur on 5416/5418 with madwifi we set 128
  966. * for all PCI-E cards to be safe).
  967. *
  968. * XXX: need to check 5210 for this
  969. * TODO: Check out tx triger level, it's always 64 on dumps but I
  970. * guess we can tweak it and see how it goes ;-)
  971. */
  972. if (ah->ah_version != AR5K_AR5210) {
  973. AR5K_REG_WRITE_BITS(ah, AR5K_TXCFG,
  974. AR5K_TXCFG_SDMAMR, AR5K_DMASIZE_128B);
  975. AR5K_REG_WRITE_BITS(ah, AR5K_RXCFG,
  976. AR5K_RXCFG_SDMAMW, AR5K_DMASIZE_128B);
  977. }
  978. /* Pre-enable interrupts on 5211/5212*/
  979. if (ah->ah_version != AR5K_AR5210)
  980. ath5k_hw_set_imr(ah, ah->ah_imr);
  981. /*
  982. * Setup RFKill interrupt if rfkill flag is set on eeprom.
  983. * TODO: Use gpio pin and polarity infos from eeprom
  984. * TODO: Handle this in ath5k_intr because it'll result
  985. * a nasty interrupt storm.
  986. */
  987. #if 0
  988. if (AR5K_EEPROM_HDR_RFKILL(ah->ah_capabilities.cap_eeprom.ee_header)) {
  989. ath5k_hw_set_gpio_input(ah, 0);
  990. ah->ah_gpio[0] = ath5k_hw_get_gpio(ah, 0);
  991. if (ah->ah_gpio[0] == 0)
  992. ath5k_hw_set_gpio_intr(ah, 0, 1);
  993. else
  994. ath5k_hw_set_gpio_intr(ah, 0, 0);
  995. }
  996. #endif
  997. /*
  998. * Disable beacons and reset the register
  999. */
  1000. AR5K_REG_DISABLE_BITS(ah, AR5K_BEACON, AR5K_BEACON_ENABLE |
  1001. AR5K_BEACON_RESET_TSF);
  1002. return 0;
  1003. }
  1004. #undef _ATH5K_RESET