You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ath5k_reset.c 31KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174
  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 iPXE, 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 <ipxe/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;
  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. freq = 0;
  600. mode = 0;
  601. /*
  602. * Save some registers before a reset
  603. */
  604. /*DCU/Antenna selection not available on 5210*/
  605. if (ah->ah_version != AR5K_AR5210) {
  606. switch (channel->hw_value & CHANNEL_MODES) {
  607. case CHANNEL_A:
  608. mode = AR5K_MODE_11A;
  609. freq = AR5K_INI_RFGAIN_5GHZ;
  610. ee_mode = AR5K_EEPROM_MODE_11A;
  611. break;
  612. case CHANNEL_G:
  613. mode = AR5K_MODE_11G;
  614. freq = AR5K_INI_RFGAIN_2GHZ;
  615. ee_mode = AR5K_EEPROM_MODE_11G;
  616. break;
  617. case CHANNEL_B:
  618. mode = AR5K_MODE_11B;
  619. freq = AR5K_INI_RFGAIN_2GHZ;
  620. ee_mode = AR5K_EEPROM_MODE_11B;
  621. break;
  622. case CHANNEL_T:
  623. mode = AR5K_MODE_11A_TURBO;
  624. freq = AR5K_INI_RFGAIN_5GHZ;
  625. ee_mode = AR5K_EEPROM_MODE_11A;
  626. break;
  627. case CHANNEL_TG:
  628. if (ah->ah_version == AR5K_AR5211) {
  629. DBG("ath5k: TurboG not available on 5211\n");
  630. return -EINVAL;
  631. }
  632. mode = AR5K_MODE_11G_TURBO;
  633. freq = AR5K_INI_RFGAIN_2GHZ;
  634. ee_mode = AR5K_EEPROM_MODE_11G;
  635. break;
  636. case CHANNEL_XR:
  637. if (ah->ah_version == AR5K_AR5211) {
  638. DBG("ath5k: XR mode not available on 5211\n");
  639. return -EINVAL;
  640. }
  641. mode = AR5K_MODE_XR;
  642. freq = AR5K_INI_RFGAIN_5GHZ;
  643. ee_mode = AR5K_EEPROM_MODE_11A;
  644. break;
  645. default:
  646. DBG("ath5k: invalid channel (%d MHz)\n",
  647. channel->center_freq);
  648. return -EINVAL;
  649. }
  650. if (change_channel) {
  651. /*
  652. * Save frame sequence count
  653. * For revs. after Oahu, only save
  654. * seq num for DCU 0 (Global seq num)
  655. */
  656. if (ah->ah_mac_srev < AR5K_SREV_AR5211) {
  657. for (i = 0; i < 10; i++)
  658. s_seq[i] = ath5k_hw_reg_read(ah,
  659. AR5K_QUEUE_DCU_SEQNUM(i));
  660. } else {
  661. s_seq[0] = ath5k_hw_reg_read(ah,
  662. AR5K_QUEUE_DCU_SEQNUM(0));
  663. }
  664. }
  665. /* Save default antenna */
  666. s_ant = ath5k_hw_reg_read(ah, AR5K_DEFAULT_ANTENNA);
  667. if (ah->ah_version == AR5K_AR5212) {
  668. /* Since we are going to write rf buffer
  669. * check if we have any pending gain_F
  670. * optimization settings */
  671. if (change_channel && ah->ah_rf_banks != NULL)
  672. ath5k_hw_gainf_calibrate(ah);
  673. }
  674. }
  675. /*GPIOs*/
  676. s_led[0] = ath5k_hw_reg_read(ah, AR5K_PCICFG) &
  677. AR5K_PCICFG_LEDSTATE;
  678. s_led[1] = ath5k_hw_reg_read(ah, AR5K_GPIOCR);
  679. s_led[2] = ath5k_hw_reg_read(ah, AR5K_GPIODO);
  680. /* AR5K_STA_ID1 flags, only preserve antenna
  681. * settings and ack/cts rate mode */
  682. staid1_flags = ath5k_hw_reg_read(ah, AR5K_STA_ID1) &
  683. (AR5K_STA_ID1_DEFAULT_ANTENNA |
  684. AR5K_STA_ID1_DESC_ANTENNA |
  685. AR5K_STA_ID1_RTS_DEF_ANTENNA |
  686. AR5K_STA_ID1_ACKCTS_6MB |
  687. AR5K_STA_ID1_BASE_RATE_11B |
  688. AR5K_STA_ID1_SELFGEN_DEF_ANT);
  689. /* Wakeup the device */
  690. ret = ath5k_hw_nic_wakeup(ah, channel->hw_value, 0);
  691. if (ret)
  692. return ret;
  693. /* PHY access enable */
  694. if (ah->ah_mac_srev >= AR5K_SREV_AR5211)
  695. ath5k_hw_reg_write(ah, AR5K_PHY_SHIFT_5GHZ, AR5K_PHY(0));
  696. else
  697. ath5k_hw_reg_write(ah, AR5K_PHY_SHIFT_5GHZ | 0x40,
  698. AR5K_PHY(0));
  699. /* Write initial settings */
  700. ret = ath5k_hw_write_initvals(ah, mode, change_channel);
  701. if (ret)
  702. return ret;
  703. /*
  704. * 5211/5212 Specific
  705. */
  706. if (ah->ah_version != AR5K_AR5210) {
  707. /*
  708. * Write initial RF gain settings
  709. * This should work for both 5111/5112
  710. */
  711. ret = ath5k_hw_rfgain_init(ah, freq);
  712. if (ret)
  713. return ret;
  714. mdelay(1);
  715. /*
  716. * Tweak initval settings for revised
  717. * chipsets and add some more config
  718. * bits
  719. */
  720. ath5k_hw_tweak_initval_settings(ah, channel);
  721. /*
  722. * Set TX power (FIXME)
  723. */
  724. ret = ath5k_hw_txpower(ah, channel, ee_mode,
  725. AR5K_TUNE_DEFAULT_TXPOWER);
  726. if (ret)
  727. return ret;
  728. /* Write rate duration table only on AR5212 */
  729. if (ah->ah_version == AR5K_AR5212)
  730. ath5k_hw_write_rate_duration(ah, mode);
  731. /*
  732. * Write RF buffer
  733. */
  734. ret = ath5k_hw_rfregs_init(ah, channel, mode);
  735. if (ret)
  736. return ret;
  737. /* Write OFDM timings on 5212*/
  738. if (ah->ah_version == AR5K_AR5212 &&
  739. channel->hw_value & CHANNEL_OFDM) {
  740. ret = ath5k_hw_write_ofdm_timings(ah, channel);
  741. if (ret)
  742. return ret;
  743. }
  744. /*Enable/disable 802.11b mode on 5111
  745. (enable 2111 frequency converter + CCK)*/
  746. if (ah->ah_radio == AR5K_RF5111) {
  747. if (mode == AR5K_MODE_11B)
  748. AR5K_REG_ENABLE_BITS(ah, AR5K_TXCFG,
  749. AR5K_TXCFG_B_MODE);
  750. else
  751. AR5K_REG_DISABLE_BITS(ah, AR5K_TXCFG,
  752. AR5K_TXCFG_B_MODE);
  753. }
  754. /*
  755. * In case a fixed antenna was set as default
  756. * write the same settings on both AR5K_PHY_ANT_SWITCH_TABLE
  757. * registers.
  758. */
  759. if (s_ant != 0) {
  760. if (s_ant == AR5K_ANT_FIXED_A) /* 1 - Main */
  761. ant[0] = ant[1] = AR5K_ANT_FIXED_A;
  762. else /* 2 - Aux */
  763. ant[0] = ant[1] = AR5K_ANT_FIXED_B;
  764. } else {
  765. ant[0] = AR5K_ANT_FIXED_A;
  766. ant[1] = AR5K_ANT_FIXED_B;
  767. }
  768. /* Commit values from EEPROM */
  769. ath5k_hw_commit_eeprom_settings(ah, channel, ant, ee_mode);
  770. } else {
  771. /*
  772. * For 5210 we do all initialization using
  773. * initvals, so we don't have to modify
  774. * any settings (5210 also only supports
  775. * a/aturbo modes)
  776. */
  777. mdelay(1);
  778. /* Disable phy and wait */
  779. ath5k_hw_reg_write(ah, AR5K_PHY_ACT_DISABLE, AR5K_PHY_ACT);
  780. mdelay(1);
  781. }
  782. /*
  783. * Restore saved values
  784. */
  785. /*DCU/Antenna selection not available on 5210*/
  786. if (ah->ah_version != AR5K_AR5210) {
  787. if (change_channel) {
  788. if (ah->ah_mac_srev < AR5K_SREV_AR5211) {
  789. for (i = 0; i < 10; i++)
  790. ath5k_hw_reg_write(ah, s_seq[i],
  791. AR5K_QUEUE_DCU_SEQNUM(i));
  792. } else {
  793. ath5k_hw_reg_write(ah, s_seq[0],
  794. AR5K_QUEUE_DCU_SEQNUM(0));
  795. }
  796. }
  797. ath5k_hw_reg_write(ah, s_ant, AR5K_DEFAULT_ANTENNA);
  798. }
  799. /* Ledstate */
  800. AR5K_REG_ENABLE_BITS(ah, AR5K_PCICFG, s_led[0]);
  801. /* Gpio settings */
  802. ath5k_hw_reg_write(ah, s_led[1], AR5K_GPIOCR);
  803. ath5k_hw_reg_write(ah, s_led[2], AR5K_GPIODO);
  804. /* Restore sta_id flags and preserve our mac address*/
  805. ath5k_hw_reg_write(ah, AR5K_LOW_ID(ah->ah_sta_id),
  806. AR5K_STA_ID0);
  807. ath5k_hw_reg_write(ah, staid1_flags | AR5K_HIGH_ID(ah->ah_sta_id),
  808. AR5K_STA_ID1);
  809. /*
  810. * Configure PCU
  811. */
  812. /* Restore bssid and bssid mask */
  813. /* XXX: add ah->aid once mac80211 gives this to us */
  814. ath5k_hw_set_associd(ah, ah->ah_bssid, 0);
  815. /* Set PCU config */
  816. ath5k_hw_set_opmode(ah);
  817. /* Clear any pending interrupts
  818. * PISR/SISR Not available on 5210 */
  819. if (ah->ah_version != AR5K_AR5210)
  820. ath5k_hw_reg_write(ah, 0xffffffff, AR5K_PISR);
  821. /* Set RSSI/BRSSI thresholds
  822. *
  823. * Note: If we decide to set this value
  824. * dynamicaly, have in mind that when AR5K_RSSI_THR
  825. * register is read it might return 0x40 if we haven't
  826. * wrote anything to it plus BMISS RSSI threshold is zeroed.
  827. * So doing a save/restore procedure here isn't the right
  828. * choice. Instead store it on ath5k_hw */
  829. ath5k_hw_reg_write(ah, (AR5K_TUNE_RSSI_THRES |
  830. AR5K_TUNE_BMISS_THRES <<
  831. AR5K_RSSI_THR_BMISS_S),
  832. AR5K_RSSI_THR);
  833. /* MIC QoS support */
  834. if (ah->ah_mac_srev >= AR5K_SREV_AR2413) {
  835. ath5k_hw_reg_write(ah, 0x000100aa, AR5K_MIC_QOS_CTL);
  836. ath5k_hw_reg_write(ah, 0x00003210, AR5K_MIC_QOS_SEL);
  837. }
  838. /* QoS NOACK Policy */
  839. if (ah->ah_version == AR5K_AR5212) {
  840. ath5k_hw_reg_write(ah,
  841. AR5K_REG_SM(2, AR5K_QOS_NOACK_2BIT_VALUES) |
  842. AR5K_REG_SM(5, AR5K_QOS_NOACK_BIT_OFFSET) |
  843. AR5K_REG_SM(0, AR5K_QOS_NOACK_BYTE_OFFSET),
  844. AR5K_QOS_NOACK);
  845. }
  846. /*
  847. * Configure PHY
  848. */
  849. /* Set channel on PHY */
  850. ret = ath5k_hw_channel(ah, channel);
  851. if (ret)
  852. return ret;
  853. /*
  854. * Enable the PHY and wait until completion
  855. * This includes BaseBand and Synthesizer
  856. * activation.
  857. */
  858. ath5k_hw_reg_write(ah, AR5K_PHY_ACT_ENABLE, AR5K_PHY_ACT);
  859. /*
  860. * On 5211+ read activation -> rx delay
  861. * and use it.
  862. *
  863. * TODO: Half/quarter rate support
  864. */
  865. if (ah->ah_version != AR5K_AR5210) {
  866. u32 delay;
  867. delay = ath5k_hw_reg_read(ah, AR5K_PHY_RX_DELAY) &
  868. AR5K_PHY_RX_DELAY_M;
  869. delay = (channel->hw_value & CHANNEL_CCK) ?
  870. ((delay << 2) / 22) : (delay / 10);
  871. udelay(100 + (2 * delay));
  872. } else {
  873. mdelay(1);
  874. }
  875. /*
  876. * Perform ADC test to see if baseband is ready
  877. * Set tx hold and check adc test register
  878. */
  879. phy_tst1 = ath5k_hw_reg_read(ah, AR5K_PHY_TST1);
  880. ath5k_hw_reg_write(ah, AR5K_PHY_TST1_TXHOLD, AR5K_PHY_TST1);
  881. for (i = 0; i <= 20; i++) {
  882. if (!(ath5k_hw_reg_read(ah, AR5K_PHY_ADC_TEST) & 0x10))
  883. break;
  884. udelay(200);
  885. }
  886. ath5k_hw_reg_write(ah, phy_tst1, AR5K_PHY_TST1);
  887. /*
  888. * Start automatic gain control calibration
  889. *
  890. * During AGC calibration RX path is re-routed to
  891. * a power detector so we don't receive anything.
  892. *
  893. * This method is used to calibrate some static offsets
  894. * used together with on-the fly I/Q calibration (the
  895. * one performed via ath5k_hw_phy_calibrate), that doesn't
  896. * interrupt rx path.
  897. *
  898. * While rx path is re-routed to the power detector we also
  899. * start a noise floor calibration, to measure the
  900. * card's noise floor (the noise we measure when we are not
  901. * transmiting or receiving anything).
  902. *
  903. * If we are in a noisy environment AGC calibration may time
  904. * out and/or noise floor calibration might timeout.
  905. */
  906. AR5K_REG_ENABLE_BITS(ah, AR5K_PHY_AGCCTL,
  907. AR5K_PHY_AGCCTL_CAL);
  908. /* At the same time start I/Q calibration for QAM constellation
  909. * -no need for CCK- */
  910. ah->ah_calibration = 0;
  911. if (!(mode == AR5K_MODE_11B)) {
  912. ah->ah_calibration = 1;
  913. AR5K_REG_WRITE_BITS(ah, AR5K_PHY_IQ,
  914. AR5K_PHY_IQ_CAL_NUM_LOG_MAX, 15);
  915. AR5K_REG_ENABLE_BITS(ah, AR5K_PHY_IQ,
  916. AR5K_PHY_IQ_RUN);
  917. }
  918. /* Wait for gain calibration to finish (we check for I/Q calibration
  919. * during ath5k_phy_calibrate) */
  920. if (ath5k_hw_register_timeout(ah, AR5K_PHY_AGCCTL,
  921. AR5K_PHY_AGCCTL_CAL, 0, 0)) {
  922. DBG("ath5k: gain calibration timeout (%d MHz)\n",
  923. channel->center_freq);
  924. }
  925. /*
  926. * If we run NF calibration before AGC, it always times out.
  927. * Binary HAL starts NF and AGC calibration at the same time
  928. * and only waits for AGC to finish. Also if AGC or NF cal.
  929. * times out, reset doesn't fail on binary HAL. I believe
  930. * that's wrong because since rx path is routed to a detector,
  931. * if cal. doesn't finish we won't have RX. Sam's HAL for AR5210/5211
  932. * enables noise floor calibration after offset calibration and if noise
  933. * floor calibration fails, reset fails. I believe that's
  934. * a better approach, we just need to find a polling interval
  935. * that suits best, even if reset continues we need to make
  936. * sure that rx path is ready.
  937. */
  938. ath5k_hw_noise_floor_calibration(ah, channel->center_freq);
  939. /*
  940. * Configure QCUs/DCUs
  941. */
  942. /* TODO: HW Compression support for data queues */
  943. /* TODO: Burst prefetch for data queues */
  944. /*
  945. * Reset queues and start beacon timers at the end of the reset routine
  946. * This also sets QCU mask on each DCU for 1:1 qcu to dcu mapping
  947. * Note: If we want we can assign multiple qcus on one dcu.
  948. */
  949. ret = ath5k_hw_reset_tx_queue(ah);
  950. if (ret) {
  951. DBG("ath5k: failed to reset TX queue\n");
  952. return ret;
  953. }
  954. /*
  955. * Configure DMA/Interrupts
  956. */
  957. /*
  958. * Set Rx/Tx DMA Configuration
  959. *
  960. * Set standard DMA size (128). Note that
  961. * a DMA size of 512 causes rx overruns and tx errors
  962. * on pci-e cards (tested on 5424 but since rx overruns
  963. * also occur on 5416/5418 with madwifi we set 128
  964. * for all PCI-E cards to be safe).
  965. *
  966. * XXX: need to check 5210 for this
  967. * TODO: Check out tx triger level, it's always 64 on dumps but I
  968. * guess we can tweak it and see how it goes ;-)
  969. */
  970. if (ah->ah_version != AR5K_AR5210) {
  971. AR5K_REG_WRITE_BITS(ah, AR5K_TXCFG,
  972. AR5K_TXCFG_SDMAMR, AR5K_DMASIZE_128B);
  973. AR5K_REG_WRITE_BITS(ah, AR5K_RXCFG,
  974. AR5K_RXCFG_SDMAMW, AR5K_DMASIZE_128B);
  975. }
  976. /* Pre-enable interrupts on 5211/5212*/
  977. if (ah->ah_version != AR5K_AR5210)
  978. ath5k_hw_set_imr(ah, ah->ah_imr);
  979. /*
  980. * Setup RFKill interrupt if rfkill flag is set on eeprom.
  981. * TODO: Use gpio pin and polarity infos from eeprom
  982. * TODO: Handle this in ath5k_intr because it'll result
  983. * a nasty interrupt storm.
  984. */
  985. #if 0
  986. if (AR5K_EEPROM_HDR_RFKILL(ah->ah_capabilities.cap_eeprom.ee_header)) {
  987. ath5k_hw_set_gpio_input(ah, 0);
  988. ah->ah_gpio[0] = ath5k_hw_get_gpio(ah, 0);
  989. if (ah->ah_gpio[0] == 0)
  990. ath5k_hw_set_gpio_intr(ah, 0, 1);
  991. else
  992. ath5k_hw_set_gpio_intr(ah, 0, 0);
  993. }
  994. #endif
  995. /*
  996. * Disable beacons and reset the register
  997. */
  998. AR5K_REG_DISABLE_BITS(ah, AR5K_BEACON, AR5K_BEACON_ENABLE |
  999. AR5K_BEACON_RESET_TSF);
  1000. return 0;
  1001. }
  1002. #undef _ATH5K_RESET