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.

ath9k_hw.c 50KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067
  1. /*
  2. * Copyright (c) 2008-2011 Atheros Communications Inc.
  3. *
  4. * Modified for iPXE by Scott K Logan <logans@cottsay.net> July 2011
  5. * Original from Linux kernel 3.0.1
  6. *
  7. * Permission to use, copy, modify, and/or distribute this software for any
  8. * purpose with or without fee is hereby granted, provided that the above
  9. * copyright notice and this permission notice appear in all copies.
  10. *
  11. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  12. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  13. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  14. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  15. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  16. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  17. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  18. */
  19. #include <ipxe/vsprintf.h>
  20. #include <ipxe/io.h>
  21. #include "hw.h"
  22. #include "hw-ops.h"
  23. #include "ar9003_mac.h"
  24. static int ath9k_hw_set_reset_reg(struct ath_hw *ah, u32 type);
  25. /* Private hardware callbacks */
  26. static void ath9k_hw_init_cal_settings(struct ath_hw *ah)
  27. {
  28. ath9k_hw_private_ops(ah)->init_cal_settings(ah);
  29. }
  30. static void ath9k_hw_init_mode_regs(struct ath_hw *ah)
  31. {
  32. ath9k_hw_private_ops(ah)->init_mode_regs(ah);
  33. }
  34. static u32 ath9k_hw_compute_pll_control(struct ath_hw *ah,
  35. struct ath9k_channel *chan)
  36. {
  37. return ath9k_hw_private_ops(ah)->compute_pll_control(ah, chan);
  38. }
  39. static void ath9k_hw_init_mode_gain_regs(struct ath_hw *ah)
  40. {
  41. if (!ath9k_hw_private_ops(ah)->init_mode_gain_regs)
  42. return;
  43. ath9k_hw_private_ops(ah)->init_mode_gain_regs(ah);
  44. }
  45. static void ath9k_hw_ani_cache_ini_regs(struct ath_hw *ah)
  46. {
  47. /* You will not have this callback if using the old ANI */
  48. if (!ath9k_hw_private_ops(ah)->ani_cache_ini_regs)
  49. return;
  50. ath9k_hw_private_ops(ah)->ani_cache_ini_regs(ah);
  51. }
  52. /********************/
  53. /* Helper Functions */
  54. /********************/
  55. static void ath9k_hw_set_clockrate(struct ath_hw *ah)
  56. {
  57. struct ath_common *common = ath9k_hw_common(ah);
  58. struct net80211_device *dev = common->dev;
  59. unsigned int clockrate;
  60. if (!ah->curchan) /* should really check for CCK instead */
  61. clockrate = ATH9K_CLOCK_RATE_CCK;
  62. else if ((dev->channels + dev->channel)->band == NET80211_BAND_2GHZ)
  63. clockrate = ATH9K_CLOCK_RATE_2GHZ_OFDM;
  64. else if (ah->caps.hw_caps & ATH9K_HW_CAP_FASTCLOCK)
  65. clockrate = ATH9K_CLOCK_FAST_RATE_5GHZ_OFDM;
  66. else
  67. clockrate = ATH9K_CLOCK_RATE_5GHZ_OFDM;
  68. common->clockrate = clockrate;
  69. }
  70. static u32 ath9k_hw_mac_to_clks(struct ath_hw *ah, u32 usecs)
  71. {
  72. struct ath_common *common = ath9k_hw_common(ah);
  73. return usecs * common->clockrate;
  74. }
  75. int ath9k_hw_wait(struct ath_hw *ah, u32 reg, u32 mask, u32 val, u32 timeout)
  76. {
  77. unsigned int i;
  78. for (i = 0; i < (timeout / AH_TIME_QUANTUM); i++) {
  79. if ((REG_READ(ah, reg) & mask) == val)
  80. return 1;
  81. udelay(AH_TIME_QUANTUM);
  82. }
  83. DBG("ath9k: "
  84. "timeout (%d us) on reg 0x%x: 0x%08x & 0x%08x != 0x%08x\n",
  85. timeout, reg, REG_READ(ah, reg), mask, val);
  86. return 0;
  87. }
  88. void ath9k_hw_write_array(struct ath_hw *ah, struct ar5416IniArray *array,
  89. int column, unsigned int *writecnt)
  90. {
  91. unsigned int r;
  92. ENABLE_REGWRITE_BUFFER(ah);
  93. for (r = 0; r < array->ia_rows; r++) {
  94. REG_WRITE(ah, INI_RA(array, r, 0),
  95. INI_RA(array, r, column));
  96. DO_DELAY(*writecnt);
  97. }
  98. REGWRITE_BUFFER_FLUSH(ah);
  99. }
  100. u32 ath9k_hw_reverse_bits(u32 val, u32 n)
  101. {
  102. u32 retval;
  103. unsigned int i;
  104. for (i = 0, retval = 0; i < n; i++) {
  105. retval = (retval << 1) | (val & 1);
  106. val >>= 1;
  107. }
  108. return retval;
  109. }
  110. u16 ath9k_hw_computetxtime(struct ath_hw *ah,
  111. u8 phy, int kbps,
  112. u32 frameLen, u16 rateix,
  113. int shortPreamble)
  114. {
  115. u32 bitsPerSymbol, numBits, numSymbols, phyTime, txTime;
  116. if (kbps == 0)
  117. return 0;
  118. switch (phy) {
  119. case CHANNEL_CCK:
  120. phyTime = CCK_PREAMBLE_BITS + CCK_PLCP_BITS;
  121. if (shortPreamble)
  122. phyTime >>= 1;
  123. numBits = frameLen << 3;
  124. txTime = CCK_SIFS_TIME + phyTime + ((numBits * 1000) / kbps);
  125. break;
  126. case CHANNEL_OFDM:
  127. if (ah->curchan && IS_CHAN_QUARTER_RATE(ah->curchan)) {
  128. bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME_QUARTER) / 1000;
  129. numBits = OFDM_PLCP_BITS + (frameLen << 3);
  130. numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
  131. txTime = OFDM_SIFS_TIME_QUARTER
  132. + OFDM_PREAMBLE_TIME_QUARTER
  133. + (numSymbols * OFDM_SYMBOL_TIME_QUARTER);
  134. } else if (ah->curchan &&
  135. IS_CHAN_HALF_RATE(ah->curchan)) {
  136. bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME_HALF) / 1000;
  137. numBits = OFDM_PLCP_BITS + (frameLen << 3);
  138. numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
  139. txTime = OFDM_SIFS_TIME_HALF +
  140. OFDM_PREAMBLE_TIME_HALF
  141. + (numSymbols * OFDM_SYMBOL_TIME_HALF);
  142. } else {
  143. bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME) / 1000;
  144. numBits = OFDM_PLCP_BITS + (frameLen << 3);
  145. numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
  146. txTime = OFDM_SIFS_TIME + OFDM_PREAMBLE_TIME
  147. + (numSymbols * OFDM_SYMBOL_TIME);
  148. }
  149. break;
  150. default:
  151. DBG("ath9k: "
  152. "Unknown phy %d (rate ix %d)\n", phy, rateix);
  153. txTime = 0;
  154. break;
  155. }
  156. return txTime;
  157. }
  158. void ath9k_hw_get_channel_centers(struct ath_hw *ah __unused,
  159. struct ath9k_channel *chan,
  160. struct chan_centers *centers)
  161. {
  162. int8_t extoff;
  163. if (!IS_CHAN_HT40(chan)) {
  164. centers->ctl_center = centers->ext_center =
  165. centers->synth_center = chan->channel;
  166. return;
  167. }
  168. if ((chan->chanmode == CHANNEL_A_HT40PLUS) ||
  169. (chan->chanmode == CHANNEL_G_HT40PLUS)) {
  170. centers->synth_center =
  171. chan->channel + HT40_CHANNEL_CENTER_SHIFT;
  172. extoff = 1;
  173. } else {
  174. centers->synth_center =
  175. chan->channel - HT40_CHANNEL_CENTER_SHIFT;
  176. extoff = -1;
  177. }
  178. centers->ctl_center =
  179. centers->synth_center - (extoff * HT40_CHANNEL_CENTER_SHIFT);
  180. /* 25 MHz spacing is supported by hw but not on upper layers */
  181. centers->ext_center =
  182. centers->synth_center + (extoff * HT40_CHANNEL_CENTER_SHIFT);
  183. }
  184. /******************/
  185. /* Chip Revisions */
  186. /******************/
  187. static void ath9k_hw_read_revisions(struct ath_hw *ah)
  188. {
  189. u32 val;
  190. switch (ah->hw_version.devid) {
  191. case AR5416_AR9100_DEVID:
  192. ah->hw_version.macVersion = AR_SREV_VERSION_9100;
  193. break;
  194. case AR9300_DEVID_AR9340:
  195. ah->hw_version.macVersion = AR_SREV_VERSION_9340;
  196. val = REG_READ(ah, AR_SREV);
  197. ah->hw_version.macRev = MS(val, AR_SREV_REVISION2);
  198. return;
  199. }
  200. val = REG_READ(ah, AR_SREV) & AR_SREV_ID;
  201. if (val == 0xFF) {
  202. val = REG_READ(ah, AR_SREV);
  203. ah->hw_version.macVersion =
  204. (val & AR_SREV_VERSION2) >> AR_SREV_TYPE2_S;
  205. ah->hw_version.macRev = MS(val, AR_SREV_REVISION2);
  206. ah->is_pciexpress = (val & AR_SREV_TYPE2_HOST_MODE) ? 0 : 1;
  207. } else {
  208. if (!AR_SREV_9100(ah))
  209. ah->hw_version.macVersion = MS(val, AR_SREV_VERSION);
  210. ah->hw_version.macRev = val & AR_SREV_REVISION;
  211. if (ah->hw_version.macVersion == AR_SREV_VERSION_5416_PCIE)
  212. ah->is_pciexpress = 1;
  213. }
  214. }
  215. /************************************/
  216. /* HW Attach, Detach, Init Routines */
  217. /************************************/
  218. static void ath9k_hw_disablepcie(struct ath_hw *ah)
  219. {
  220. if (!AR_SREV_5416(ah))
  221. return;
  222. REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fc00);
  223. REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
  224. REG_WRITE(ah, AR_PCIE_SERDES, 0x28000029);
  225. REG_WRITE(ah, AR_PCIE_SERDES, 0x57160824);
  226. REG_WRITE(ah, AR_PCIE_SERDES, 0x25980579);
  227. REG_WRITE(ah, AR_PCIE_SERDES, 0x00000000);
  228. REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
  229. REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
  230. REG_WRITE(ah, AR_PCIE_SERDES, 0x000e1007);
  231. REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
  232. }
  233. /* This should work for all families including legacy */
  234. static int ath9k_hw_chip_test(struct ath_hw *ah)
  235. {
  236. u32 regAddr[2] = { AR_STA_ID0 };
  237. u32 regHold[2];
  238. static const u32 patternData[4] = {
  239. 0x55555555, 0xaaaaaaaa, 0x66666666, 0x99999999
  240. };
  241. int i, j, loop_max;
  242. if (!AR_SREV_9300_20_OR_LATER(ah)) {
  243. loop_max = 2;
  244. regAddr[1] = AR_PHY_BASE + (8 << 2);
  245. } else
  246. loop_max = 1;
  247. for (i = 0; i < loop_max; i++) {
  248. u32 addr = regAddr[i];
  249. u32 wrData, rdData;
  250. regHold[i] = REG_READ(ah, addr);
  251. for (j = 0; j < 0x100; j++) {
  252. wrData = (j << 16) | j;
  253. REG_WRITE(ah, addr, wrData);
  254. rdData = REG_READ(ah, addr);
  255. if (rdData != wrData) {
  256. DBG("ath9k: "
  257. "address test failed addr: 0x%08x - wr:0x%08x != rd:0x%08x\n",
  258. addr, wrData, rdData);
  259. return 0;
  260. }
  261. }
  262. for (j = 0; j < 4; j++) {
  263. wrData = patternData[j];
  264. REG_WRITE(ah, addr, wrData);
  265. rdData = REG_READ(ah, addr);
  266. if (wrData != rdData) {
  267. DBG("ath9k: "
  268. "address test failed addr: 0x%08x - wr:0x%08x != rd:0x%08x\n",
  269. addr, wrData, rdData);
  270. return 0;
  271. }
  272. }
  273. REG_WRITE(ah, regAddr[i], regHold[i]);
  274. }
  275. udelay(100);
  276. return 1;
  277. }
  278. static void ath9k_hw_init_config(struct ath_hw *ah)
  279. {
  280. int i;
  281. ah->config.dma_beacon_response_time = 2;
  282. ah->config.sw_beacon_response_time = 10;
  283. ah->config.additional_swba_backoff = 0;
  284. ah->config.ack_6mb = 0x0;
  285. ah->config.cwm_ignore_extcca = 0;
  286. ah->config.pcie_powersave_enable = 0;
  287. ah->config.pcie_clock_req = 0;
  288. ah->config.pcie_waen = 0;
  289. ah->config.analog_shiftreg = 1;
  290. ah->config.enable_ani = 1;
  291. for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) {
  292. ah->config.spurchans[i][0] = AR_NO_SPUR;
  293. ah->config.spurchans[i][1] = AR_NO_SPUR;
  294. }
  295. /* PAPRD needs some more work to be enabled */
  296. ah->config.paprd_disable = 1;
  297. ah->config.rx_intr_mitigation = 1;
  298. ah->config.pcieSerDesWrite = 1;
  299. }
  300. static void ath9k_hw_init_defaults(struct ath_hw *ah)
  301. {
  302. struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
  303. regulatory->country_code = CTRY_DEFAULT;
  304. regulatory->power_limit = MAX_RATE_POWER;
  305. regulatory->tp_scale = ATH9K_TP_SCALE_MAX;
  306. ah->hw_version.magic = AR5416_MAGIC;
  307. ah->hw_version.subvendorid = 0;
  308. ah->atim_window = 0;
  309. ah->sta_id1_defaults =
  310. AR_STA_ID1_CRPT_MIC_ENABLE |
  311. AR_STA_ID1_MCAST_KSRCH;
  312. if (AR_SREV_9100(ah))
  313. ah->sta_id1_defaults |= AR_STA_ID1_AR9100_BA_FIX;
  314. ah->enable_32kHz_clock = DONT_USE_32KHZ;
  315. ah->slottime = 20;
  316. ah->globaltxtimeout = (u32) -1;
  317. ah->power_mode = ATH9K_PM_UNDEFINED;
  318. }
  319. static int ath9k_hw_init_macaddr(struct ath_hw *ah)
  320. {
  321. struct ath_common *common = ath9k_hw_common(ah);
  322. u32 sum;
  323. int i;
  324. u16 eeval;
  325. static const u32 EEP_MAC[] = { EEP_MAC_LSW, EEP_MAC_MID, EEP_MAC_MSW };
  326. sum = 0;
  327. for (i = 0; i < 3; i++) {
  328. eeval = ah->eep_ops->get_eeprom(ah, EEP_MAC[i]);
  329. sum += eeval;
  330. common->macaddr[2 * i] = eeval >> 8;
  331. common->macaddr[2 * i + 1] = eeval & 0xff;
  332. }
  333. if (sum == 0 || sum == 0xffff * 3)
  334. return -EADDRNOTAVAIL;
  335. return 0;
  336. }
  337. static int ath9k_hw_post_init(struct ath_hw *ah)
  338. {
  339. struct ath_common *common = ath9k_hw_common(ah);
  340. int ecode;
  341. if (common->bus_ops->ath_bus_type != ATH_USB) {
  342. if (!ath9k_hw_chip_test(ah))
  343. return -ENODEV;
  344. }
  345. if (!AR_SREV_9300_20_OR_LATER(ah)) {
  346. ecode = ar9002_hw_rf_claim(ah);
  347. if (ecode != 0)
  348. return ecode;
  349. }
  350. ecode = ath9k_hw_eeprom_init(ah);
  351. if (ecode != 0)
  352. return ecode;
  353. DBG("ath9k: "
  354. "Eeprom VER: %d, REV: %d\n",
  355. ah->eep_ops->get_eeprom_ver(ah),
  356. ah->eep_ops->get_eeprom_rev(ah));
  357. ecode = ath9k_hw_rf_alloc_ext_banks(ah);
  358. if (ecode) {
  359. DBG("ath9k: "
  360. "Failed allocating banks for external radio\n");
  361. ath9k_hw_rf_free_ext_banks(ah);
  362. return ecode;
  363. }
  364. if (!AR_SREV_9100(ah) && !AR_SREV_9340(ah)) {
  365. ath9k_hw_ani_setup(ah);
  366. ath9k_hw_ani_init(ah);
  367. }
  368. return 0;
  369. }
  370. static void ath9k_hw_attach_ops(struct ath_hw *ah)
  371. {
  372. if (AR_SREV_9300_20_OR_LATER(ah))
  373. ar9003_hw_attach_ops(ah);
  374. else
  375. ar9002_hw_attach_ops(ah);
  376. }
  377. /* Called for all hardware families */
  378. static int __ath9k_hw_init(struct ath_hw *ah)
  379. {
  380. struct ath_common *common = ath9k_hw_common(ah);
  381. int r = 0;
  382. ath9k_hw_read_revisions(ah);
  383. /*
  384. * Read back AR_WA into a permanent copy and set bits 14 and 17.
  385. * We need to do this to avoid RMW of this register. We cannot
  386. * read the reg when chip is asleep.
  387. */
  388. ah->WARegVal = REG_READ(ah, AR_WA);
  389. ah->WARegVal |= (AR_WA_D3_L1_DISABLE |
  390. AR_WA_ASPM_TIMER_BASED_DISABLE);
  391. if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_POWER_ON)) {
  392. DBG("ath9k: Couldn't reset chip\n");
  393. return -EIO;
  394. }
  395. ath9k_hw_init_defaults(ah);
  396. ath9k_hw_init_config(ah);
  397. ath9k_hw_attach_ops(ah);
  398. if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE)) {
  399. DBG("ath9k: Couldn't wakeup chip\n");
  400. return -EIO;
  401. }
  402. if (ah->config.serialize_regmode == SER_REG_MODE_AUTO) {
  403. if (ah->hw_version.macVersion == AR_SREV_VERSION_5416_PCI ||
  404. ((AR_SREV_9160(ah) || AR_SREV_9280(ah)) &&
  405. !ah->is_pciexpress)) {
  406. ah->config.serialize_regmode =
  407. SER_REG_MODE_ON;
  408. } else {
  409. ah->config.serialize_regmode =
  410. SER_REG_MODE_OFF;
  411. }
  412. }
  413. DBG2("ath9k: serialize_regmode is %d\n",
  414. ah->config.serialize_regmode);
  415. if (AR_SREV_9285(ah) || AR_SREV_9271(ah))
  416. ah->config.max_txtrig_level = MAX_TX_FIFO_THRESHOLD >> 1;
  417. else
  418. ah->config.max_txtrig_level = MAX_TX_FIFO_THRESHOLD;
  419. switch (ah->hw_version.macVersion) {
  420. case AR_SREV_VERSION_5416_PCI:
  421. case AR_SREV_VERSION_5416_PCIE:
  422. case AR_SREV_VERSION_9160:
  423. case AR_SREV_VERSION_9100:
  424. case AR_SREV_VERSION_9280:
  425. case AR_SREV_VERSION_9285:
  426. case AR_SREV_VERSION_9287:
  427. case AR_SREV_VERSION_9271:
  428. case AR_SREV_VERSION_9300:
  429. case AR_SREV_VERSION_9485:
  430. case AR_SREV_VERSION_9340:
  431. break;
  432. default:
  433. DBG("ath9k: "
  434. "Mac Chip Rev 0x%02x.%x is not supported by this driver\n",
  435. ah->hw_version.macVersion, ah->hw_version.macRev);
  436. return -EOPNOTSUPP;
  437. }
  438. if (AR_SREV_9271(ah) || AR_SREV_9100(ah) || AR_SREV_9340(ah))
  439. ah->is_pciexpress = 0;
  440. ah->hw_version.phyRev = REG_READ(ah, AR_PHY_CHIP_ID);
  441. ath9k_hw_init_cal_settings(ah);
  442. ah->ani_function = ATH9K_ANI_ALL;
  443. if (AR_SREV_9280_20_OR_LATER(ah) && !AR_SREV_9300_20_OR_LATER(ah))
  444. ah->ani_function &= ~ATH9K_ANI_NOISE_IMMUNITY_LEVEL;
  445. if (!AR_SREV_9300_20_OR_LATER(ah))
  446. ah->ani_function &= ~ATH9K_ANI_MRC_CCK;
  447. ath9k_hw_init_mode_regs(ah);
  448. if (ah->is_pciexpress)
  449. ath9k_hw_configpcipowersave(ah, 0, 0);
  450. else
  451. ath9k_hw_disablepcie(ah);
  452. if (!AR_SREV_9300_20_OR_LATER(ah))
  453. ar9002_hw_cck_chan14_spread(ah);
  454. r = ath9k_hw_post_init(ah);
  455. if (r)
  456. return r;
  457. ath9k_hw_init_mode_gain_regs(ah);
  458. r = ath9k_hw_fill_cap_info(ah);
  459. if (r)
  460. return r;
  461. r = ath9k_hw_init_macaddr(ah);
  462. if (r) {
  463. DBG("ath9k: Failed to initialize MAC address\n");
  464. return r;
  465. }
  466. if (AR_SREV_9285(ah) || AR_SREV_9271(ah))
  467. ah->tx_trig_level = (AR_FTRIG_256B >> AR_FTRIG_S);
  468. else
  469. ah->tx_trig_level = (AR_FTRIG_512B >> AR_FTRIG_S);
  470. common->state = ATH_HW_INITIALIZED;
  471. return 0;
  472. }
  473. int ath9k_hw_init(struct ath_hw *ah)
  474. {
  475. int ret;
  476. struct ath_common *common = ath9k_hw_common(ah);
  477. /* These are all the AR5008/AR9001/AR9002 hardware family of chipsets */
  478. switch (ah->hw_version.devid) {
  479. case AR5416_DEVID_PCI:
  480. case AR5416_DEVID_PCIE:
  481. case AR5416_AR9100_DEVID:
  482. case AR9160_DEVID_PCI:
  483. case AR9280_DEVID_PCI:
  484. case AR9280_DEVID_PCIE:
  485. case AR9285_DEVID_PCIE:
  486. case AR9287_DEVID_PCI:
  487. case AR9287_DEVID_PCIE:
  488. case AR2427_DEVID_PCIE:
  489. case AR9300_DEVID_PCIE:
  490. case AR9300_DEVID_AR9485_PCIE:
  491. case AR9300_DEVID_AR9340:
  492. break;
  493. default:
  494. if (common->bus_ops->ath_bus_type == ATH_USB)
  495. break;
  496. DBG("ath9k: Hardware device ID 0x%04x not supported\n",
  497. ah->hw_version.devid);
  498. return -EOPNOTSUPP;
  499. }
  500. ret = __ath9k_hw_init(ah);
  501. if (ret) {
  502. DBG("ath9k: "
  503. "Unable to initialize hardware; initialization status: %d\n",
  504. ret);
  505. return ret;
  506. }
  507. return 0;
  508. }
  509. u32 ar9003_get_pll_sqsum_dvc(struct ath_hw *ah)
  510. {
  511. REG_CLR_BIT(ah, PLL3, PLL3_DO_MEAS_MASK);
  512. udelay(100);
  513. REG_SET_BIT(ah, PLL3, PLL3_DO_MEAS_MASK);
  514. while ((REG_READ(ah, PLL4) & PLL4_MEAS_DONE) == 0)
  515. udelay(100);
  516. return (REG_READ(ah, PLL3) & SQSUM_DVC_MASK) >> 3;
  517. }
  518. static void ath9k_hw_init_pll(struct ath_hw *ah,
  519. struct ath9k_channel *chan)
  520. {
  521. u32 pll;
  522. if (AR_SREV_9485(ah)) {
  523. /* program BB PLL ki and kd value, ki=0x4, kd=0x40 */
  524. REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2,
  525. AR_CH0_BB_DPLL2_PLL_PWD, 0x1);
  526. REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2,
  527. AR_CH0_DPLL2_KD, 0x40);
  528. REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2,
  529. AR_CH0_DPLL2_KI, 0x4);
  530. REG_RMW_FIELD(ah, AR_CH0_BB_DPLL1,
  531. AR_CH0_BB_DPLL1_REFDIV, 0x5);
  532. REG_RMW_FIELD(ah, AR_CH0_BB_DPLL1,
  533. AR_CH0_BB_DPLL1_NINI, 0x58);
  534. REG_RMW_FIELD(ah, AR_CH0_BB_DPLL1,
  535. AR_CH0_BB_DPLL1_NFRAC, 0x0);
  536. REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2,
  537. AR_CH0_BB_DPLL2_OUTDIV, 0x1);
  538. REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2,
  539. AR_CH0_BB_DPLL2_LOCAL_PLL, 0x1);
  540. REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2,
  541. AR_CH0_BB_DPLL2_EN_NEGTRIG, 0x1);
  542. /* program BB PLL phase_shift to 0x6 */
  543. REG_RMW_FIELD(ah, AR_CH0_BB_DPLL3,
  544. AR_CH0_BB_DPLL3_PHASE_SHIFT, 0x6);
  545. REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2,
  546. AR_CH0_BB_DPLL2_PLL_PWD, 0x0);
  547. udelay(1000);
  548. } else if (AR_SREV_9340(ah)) {
  549. u32 regval, pll2_divint, pll2_divfrac, refdiv;
  550. REG_WRITE(ah, AR_RTC_PLL_CONTROL, 0x1142c);
  551. udelay(1000);
  552. REG_SET_BIT(ah, AR_PHY_PLL_MODE, 0x1 << 16);
  553. udelay(100);
  554. if (ah->is_clk_25mhz) {
  555. pll2_divint = 0x54;
  556. pll2_divfrac = 0x1eb85;
  557. refdiv = 3;
  558. } else {
  559. pll2_divint = 88;
  560. pll2_divfrac = 0;
  561. refdiv = 5;
  562. }
  563. regval = REG_READ(ah, AR_PHY_PLL_MODE);
  564. regval |= (0x1 << 16);
  565. REG_WRITE(ah, AR_PHY_PLL_MODE, regval);
  566. udelay(100);
  567. REG_WRITE(ah, AR_PHY_PLL_CONTROL, (refdiv << 27) |
  568. (pll2_divint << 18) | pll2_divfrac);
  569. udelay(100);
  570. regval = REG_READ(ah, AR_PHY_PLL_MODE);
  571. regval = (regval & 0x80071fff) | (0x1 << 30) | (0x1 << 13) |
  572. (0x4 << 26) | (0x18 << 19);
  573. REG_WRITE(ah, AR_PHY_PLL_MODE, regval);
  574. REG_WRITE(ah, AR_PHY_PLL_MODE,
  575. REG_READ(ah, AR_PHY_PLL_MODE) & 0xfffeffff);
  576. udelay(1000);
  577. }
  578. pll = ath9k_hw_compute_pll_control(ah, chan);
  579. REG_WRITE(ah, AR_RTC_PLL_CONTROL, pll);
  580. if (AR_SREV_9485(ah) || AR_SREV_9340(ah))
  581. udelay(1000);
  582. /* Switch the core clock for ar9271 to 117Mhz */
  583. if (AR_SREV_9271(ah)) {
  584. udelay(500);
  585. REG_WRITE(ah, 0x50040, 0x304);
  586. }
  587. udelay(RTC_PLL_SETTLE_DELAY);
  588. REG_WRITE(ah, AR_RTC_SLEEP_CLK, AR_RTC_FORCE_DERIVED_CLK);
  589. if (AR_SREV_9340(ah)) {
  590. if (ah->is_clk_25mhz) {
  591. REG_WRITE(ah, AR_RTC_DERIVED_CLK, 0x17c << 1);
  592. REG_WRITE(ah, AR_SLP32_MODE, 0x0010f3d7);
  593. REG_WRITE(ah, AR_SLP32_INC, 0x0001e7ae);
  594. } else {
  595. REG_WRITE(ah, AR_RTC_DERIVED_CLK, 0x261 << 1);
  596. REG_WRITE(ah, AR_SLP32_MODE, 0x0010f400);
  597. REG_WRITE(ah, AR_SLP32_INC, 0x0001e800);
  598. }
  599. udelay(100);
  600. }
  601. }
  602. static void ath9k_hw_init_interrupt_masks(struct ath_hw *ah)
  603. {
  604. u32 sync_default = AR_INTR_SYNC_DEFAULT;
  605. u32 imr_reg = AR_IMR_TXERR |
  606. AR_IMR_TXURN |
  607. AR_IMR_RXERR |
  608. AR_IMR_RXORN;;
  609. if (AR_SREV_9340(ah))
  610. sync_default &= ~AR_INTR_SYNC_HOST1_FATAL;
  611. if (AR_SREV_9300_20_OR_LATER(ah)) {
  612. imr_reg |= AR_IMR_RXOK_HP;
  613. if (ah->config.rx_intr_mitigation)
  614. imr_reg |= AR_IMR_RXINTM | AR_IMR_RXMINTR;
  615. else
  616. imr_reg |= AR_IMR_RXOK_LP;
  617. } else {
  618. if (ah->config.rx_intr_mitigation)
  619. imr_reg |= AR_IMR_RXINTM | AR_IMR_RXMINTR;
  620. else
  621. imr_reg |= AR_IMR_RXOK;
  622. }
  623. if (ah->config.tx_intr_mitigation)
  624. imr_reg |= AR_IMR_TXINTM | AR_IMR_TXMINTR;
  625. else
  626. imr_reg |= AR_IMR_TXOK;
  627. ENABLE_REGWRITE_BUFFER(ah);
  628. REG_WRITE(ah, AR_IMR, imr_reg);
  629. // ah->imrs2_reg |= AR_IMR_S2_GTT;
  630. REG_WRITE(ah, AR_IMR_S2, ah->imrs2_reg);
  631. if (!AR_SREV_9100(ah)) {
  632. REG_WRITE(ah, AR_INTR_SYNC_CAUSE, 0xFFFFFFFF);
  633. REG_WRITE(ah, AR_INTR_SYNC_ENABLE, sync_default);
  634. REG_WRITE(ah, AR_INTR_SYNC_MASK, 0);
  635. }
  636. REGWRITE_BUFFER_FLUSH(ah);
  637. if (AR_SREV_9300_20_OR_LATER(ah)) {
  638. REG_WRITE(ah, AR_INTR_PRIO_ASYNC_ENABLE, 0);
  639. REG_WRITE(ah, AR_INTR_PRIO_ASYNC_MASK, 0);
  640. REG_WRITE(ah, AR_INTR_PRIO_SYNC_ENABLE, 0);
  641. REG_WRITE(ah, AR_INTR_PRIO_SYNC_MASK, 0);
  642. }
  643. }
  644. static void ath9k_hw_setslottime(struct ath_hw *ah, u32 us)
  645. {
  646. u32 val = ath9k_hw_mac_to_clks(ah, us);
  647. val = min(val, (u32) 0xFFFF);
  648. REG_WRITE(ah, AR_D_GBL_IFS_SLOT, val);
  649. }
  650. static void ath9k_hw_set_ack_timeout(struct ath_hw *ah, u32 us)
  651. {
  652. u32 val = ath9k_hw_mac_to_clks(ah, us);
  653. val = min(val, (u32) MS(0xFFFFFFFF, AR_TIME_OUT_ACK));
  654. REG_RMW_FIELD(ah, AR_TIME_OUT, AR_TIME_OUT_ACK, val);
  655. }
  656. static void ath9k_hw_set_cts_timeout(struct ath_hw *ah, u32 us)
  657. {
  658. u32 val = ath9k_hw_mac_to_clks(ah, us);
  659. val = min(val, (u32) MS(0xFFFFFFFF, AR_TIME_OUT_CTS));
  660. REG_RMW_FIELD(ah, AR_TIME_OUT, AR_TIME_OUT_CTS, val);
  661. }
  662. static int ath9k_hw_set_global_txtimeout(struct ath_hw *ah, u32 tu)
  663. {
  664. if (tu > 0xFFFF) {
  665. DBG("ath9k: "
  666. "bad global tx timeout %d\n", tu);
  667. ah->globaltxtimeout = (u32) -1;
  668. return 0;
  669. } else {
  670. REG_RMW_FIELD(ah, AR_GTXTO, AR_GTXTO_TIMEOUT_LIMIT, tu);
  671. ah->globaltxtimeout = tu;
  672. return 1;
  673. }
  674. }
  675. void ath9k_hw_init_global_settings(struct ath_hw *ah)
  676. {
  677. int acktimeout;
  678. int slottime;
  679. int sifstime;
  680. DBG2("ath9k: ah->misc_mode 0x%x\n",
  681. ah->misc_mode);
  682. if (ah->misc_mode != 0)
  683. REG_SET_BIT(ah, AR_PCU_MISC, ah->misc_mode);
  684. if ((ah->dev->channels + ah->dev->channel)->band == NET80211_BAND_5GHZ)
  685. sifstime = 16;
  686. else
  687. sifstime = 10;
  688. /* As defined by IEEE 802.11-2007 17.3.8.6 */
  689. slottime = ah->slottime + 3 * ah->coverage_class;
  690. acktimeout = slottime + sifstime;
  691. /*
  692. * Workaround for early ACK timeouts, add an offset to match the
  693. * initval's 64us ack timeout value.
  694. * This was initially only meant to work around an issue with delayed
  695. * BA frames in some implementations, but it has been found to fix ACK
  696. * timeout issues in other cases as well.
  697. */
  698. if ((ah->dev->channels + ah->dev->channel)->band == NET80211_BAND_2GHZ)
  699. acktimeout += 64 - sifstime - ah->slottime;
  700. ath9k_hw_setslottime(ah, ah->slottime);
  701. ath9k_hw_set_ack_timeout(ah, acktimeout);
  702. ath9k_hw_set_cts_timeout(ah, acktimeout);
  703. if (ah->globaltxtimeout != (u32) -1)
  704. ath9k_hw_set_global_txtimeout(ah, ah->globaltxtimeout);
  705. }
  706. void ath9k_hw_deinit(struct ath_hw *ah)
  707. {
  708. struct ath_common *common = ath9k_hw_common(ah);
  709. if (common->state < ATH_HW_INITIALIZED)
  710. goto free_hw;
  711. ath9k_hw_setpower(ah, ATH9K_PM_FULL_SLEEP);
  712. free_hw:
  713. ath9k_hw_rf_free_ext_banks(ah);
  714. }
  715. /*******/
  716. /* INI */
  717. /*******/
  718. u32 ath9k_regd_get_ctl(struct ath_regulatory *reg, struct ath9k_channel *chan)
  719. {
  720. u32 ctl = ath_regd_get_band_ctl(reg, chan->chan->band);
  721. if (IS_CHAN_B(chan))
  722. ctl |= CTL_11B;
  723. else if (IS_CHAN_G(chan))
  724. ctl |= CTL_11G;
  725. else
  726. ctl |= CTL_11A;
  727. return ctl;
  728. }
  729. /****************************************/
  730. /* Reset and Channel Switching Routines */
  731. /****************************************/
  732. static inline void ath9k_hw_set_dma(struct ath_hw *ah)
  733. {
  734. struct ath_common *common = ath9k_hw_common(ah);
  735. ENABLE_REGWRITE_BUFFER(ah);
  736. /*
  737. * set AHB_MODE not to do cacheline prefetches
  738. */
  739. if (!AR_SREV_9300_20_OR_LATER(ah))
  740. REG_SET_BIT(ah, AR_AHB_MODE, AR_AHB_PREFETCH_RD_EN);
  741. /*
  742. * let mac dma reads be in 128 byte chunks
  743. */
  744. REG_RMW(ah, AR_TXCFG, AR_TXCFG_DMASZ_128B, AR_TXCFG_DMASZ_MASK);
  745. REGWRITE_BUFFER_FLUSH(ah);
  746. /*
  747. * Restore TX Trigger Level to its pre-reset value.
  748. * The initial value depends on whether aggregation is enabled, and is
  749. * adjusted whenever underruns are detected.
  750. */
  751. if (!AR_SREV_9300_20_OR_LATER(ah))
  752. REG_RMW_FIELD(ah, AR_TXCFG, AR_FTRIG, ah->tx_trig_level);
  753. ENABLE_REGWRITE_BUFFER(ah);
  754. /*
  755. * let mac dma writes be in 128 byte chunks
  756. */
  757. REG_RMW(ah, AR_RXCFG, AR_RXCFG_DMASZ_128B, AR_RXCFG_DMASZ_MASK);
  758. /*
  759. * Setup receive FIFO threshold to hold off TX activities
  760. */
  761. REG_WRITE(ah, AR_RXFIFO_CFG, 0x200);
  762. if (AR_SREV_9300_20_OR_LATER(ah)) {
  763. REG_RMW_FIELD(ah, AR_RXBP_THRESH, AR_RXBP_THRESH_HP, 0x1);
  764. REG_RMW_FIELD(ah, AR_RXBP_THRESH, AR_RXBP_THRESH_LP, 0x1);
  765. ath9k_hw_set_rx_bufsize(ah, common->rx_bufsize -
  766. ah->caps.rx_status_len);
  767. }
  768. /*
  769. * reduce the number of usable entries in PCU TXBUF to avoid
  770. * wrap around issues.
  771. */
  772. if (AR_SREV_9285(ah)) {
  773. /* For AR9285 the number of Fifos are reduced to half.
  774. * So set the usable tx buf size also to half to
  775. * avoid data/delimiter underruns
  776. */
  777. REG_WRITE(ah, AR_PCU_TXBUF_CTRL,
  778. AR_9285_PCU_TXBUF_CTRL_USABLE_SIZE);
  779. } else if (!AR_SREV_9271(ah)) {
  780. REG_WRITE(ah, AR_PCU_TXBUF_CTRL,
  781. AR_PCU_TXBUF_CTRL_USABLE_SIZE);
  782. }
  783. REGWRITE_BUFFER_FLUSH(ah);
  784. if (AR_SREV_9300_20_OR_LATER(ah))
  785. ath9k_hw_reset_txstatus_ring(ah);
  786. }
  787. static void ath9k_hw_set_operating_mode(struct ath_hw *ah)
  788. {
  789. u32 mask = AR_STA_ID1_STA_AP | AR_STA_ID1_ADHOC;
  790. u32 set = AR_STA_ID1_KSRCH_MODE;
  791. REG_CLR_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION);
  792. REG_RMW(ah, AR_STA_ID1, set, mask);
  793. }
  794. void ath9k_hw_get_delta_slope_vals(struct ath_hw *ah __unused, u32 coef_scaled,
  795. u32 *coef_mantissa, u32 *coef_exponent)
  796. {
  797. u32 coef_exp, coef_man;
  798. for (coef_exp = 31; coef_exp > 0; coef_exp--)
  799. if ((coef_scaled >> coef_exp) & 0x1)
  800. break;
  801. coef_exp = 14 - (coef_exp - COEF_SCALE_S);
  802. coef_man = coef_scaled + (1 << (COEF_SCALE_S - coef_exp - 1));
  803. *coef_mantissa = coef_man >> (COEF_SCALE_S - coef_exp);
  804. *coef_exponent = coef_exp - 16;
  805. }
  806. static int ath9k_hw_set_reset(struct ath_hw *ah, int type)
  807. {
  808. u32 rst_flags;
  809. u32 tmpReg;
  810. if (AR_SREV_9100(ah)) {
  811. REG_RMW_FIELD(ah, AR_RTC_DERIVED_CLK,
  812. AR_RTC_DERIVED_CLK_PERIOD, 1);
  813. (void)REG_READ(ah, AR_RTC_DERIVED_CLK);
  814. }
  815. ENABLE_REGWRITE_BUFFER(ah);
  816. if (AR_SREV_9300_20_OR_LATER(ah)) {
  817. REG_WRITE(ah, AR_WA, ah->WARegVal);
  818. udelay(10);
  819. }
  820. REG_WRITE(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN |
  821. AR_RTC_FORCE_WAKE_ON_INT);
  822. if (AR_SREV_9100(ah)) {
  823. rst_flags = AR_RTC_RC_MAC_WARM | AR_RTC_RC_MAC_COLD |
  824. AR_RTC_RC_COLD_RESET | AR_RTC_RC_WARM_RESET;
  825. } else {
  826. tmpReg = REG_READ(ah, AR_INTR_SYNC_CAUSE);
  827. if (tmpReg &
  828. (AR_INTR_SYNC_LOCAL_TIMEOUT |
  829. AR_INTR_SYNC_RADM_CPL_TIMEOUT)) {
  830. u32 val;
  831. REG_WRITE(ah, AR_INTR_SYNC_ENABLE, 0);
  832. val = AR_RC_HOSTIF;
  833. if (!AR_SREV_9300_20_OR_LATER(ah))
  834. val |= AR_RC_AHB;
  835. REG_WRITE(ah, AR_RC, val);
  836. } else if (!AR_SREV_9300_20_OR_LATER(ah))
  837. REG_WRITE(ah, AR_RC, AR_RC_AHB);
  838. rst_flags = AR_RTC_RC_MAC_WARM;
  839. if (type == ATH9K_RESET_COLD)
  840. rst_flags |= AR_RTC_RC_MAC_COLD;
  841. }
  842. REG_WRITE(ah, AR_RTC_RC, rst_flags);
  843. REGWRITE_BUFFER_FLUSH(ah);
  844. udelay(50);
  845. REG_WRITE(ah, AR_RTC_RC, 0);
  846. if (!ath9k_hw_wait(ah, AR_RTC_RC, AR_RTC_RC_M, 0, AH_WAIT_TIMEOUT)) {
  847. DBG("ath9k: "
  848. "RTC stuck in MAC reset\n");
  849. return 0;
  850. }
  851. if (!AR_SREV_9100(ah))
  852. REG_WRITE(ah, AR_RC, 0);
  853. if (AR_SREV_9100(ah))
  854. udelay(50);
  855. return 1;
  856. }
  857. static int ath9k_hw_set_reset_power_on(struct ath_hw *ah)
  858. {
  859. ENABLE_REGWRITE_BUFFER(ah);
  860. if (AR_SREV_9300_20_OR_LATER(ah)) {
  861. REG_WRITE(ah, AR_WA, ah->WARegVal);
  862. udelay(10);
  863. }
  864. REG_WRITE(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN |
  865. AR_RTC_FORCE_WAKE_ON_INT);
  866. if (!AR_SREV_9100(ah) && !AR_SREV_9300_20_OR_LATER(ah))
  867. REG_WRITE(ah, AR_RC, AR_RC_AHB);
  868. REG_WRITE(ah, AR_RTC_RESET, 0);
  869. REGWRITE_BUFFER_FLUSH(ah);
  870. if (!AR_SREV_9300_20_OR_LATER(ah))
  871. udelay(2);
  872. if (!AR_SREV_9100(ah) && !AR_SREV_9300_20_OR_LATER(ah))
  873. REG_WRITE(ah, AR_RC, 0);
  874. REG_WRITE(ah, AR_RTC_RESET, 1);
  875. if (!ath9k_hw_wait(ah,
  876. AR_RTC_STATUS,
  877. AR_RTC_STATUS_M,
  878. AR_RTC_STATUS_ON,
  879. AH_WAIT_TIMEOUT)) {
  880. DBG("ath9k: "
  881. "RTC not waking up\n");
  882. return 0;
  883. }
  884. return ath9k_hw_set_reset(ah, ATH9K_RESET_WARM);
  885. }
  886. static int ath9k_hw_set_reset_reg(struct ath_hw *ah, u32 type)
  887. {
  888. if (AR_SREV_9300_20_OR_LATER(ah)) {
  889. REG_WRITE(ah, AR_WA, ah->WARegVal);
  890. udelay(10);
  891. }
  892. REG_WRITE(ah, AR_RTC_FORCE_WAKE,
  893. AR_RTC_FORCE_WAKE_EN | AR_RTC_FORCE_WAKE_ON_INT);
  894. switch (type) {
  895. case ATH9K_RESET_POWER_ON:
  896. return ath9k_hw_set_reset_power_on(ah);
  897. case ATH9K_RESET_WARM:
  898. case ATH9K_RESET_COLD:
  899. return ath9k_hw_set_reset(ah, type);
  900. default:
  901. return 0;
  902. }
  903. }
  904. static int ath9k_hw_chip_reset(struct ath_hw *ah,
  905. struct ath9k_channel *chan)
  906. {
  907. if (AR_SREV_9280(ah) && ah->eep_ops->get_eeprom(ah, EEP_OL_PWRCTRL)) {
  908. if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_POWER_ON))
  909. return 0;
  910. } else if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_WARM))
  911. return 0;
  912. if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
  913. return 0;
  914. ah->chip_fullsleep = 0;
  915. ath9k_hw_init_pll(ah, chan);
  916. ath9k_hw_set_rfmode(ah, chan);
  917. return 1;
  918. }
  919. static int ath9k_hw_channel_change(struct ath_hw *ah,
  920. struct ath9k_channel *chan)
  921. {
  922. struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
  923. struct net80211_channel *channel = chan->chan;
  924. u32 qnum;
  925. int r;
  926. for (qnum = 0; qnum < AR_NUM_QCU; qnum++) {
  927. if (ath9k_hw_numtxpending(ah, qnum)) {
  928. DBG("ath9k: "
  929. "Transmit frames pending on queue %d\n", qnum);
  930. return 0;
  931. }
  932. }
  933. if (!ath9k_hw_rfbus_req(ah)) {
  934. DBG("ath9k: Could not kill baseband RX\n");
  935. return 0;
  936. }
  937. ath9k_hw_set_channel_regs(ah, chan);
  938. r = ath9k_hw_rf_set_freq(ah, chan);
  939. if (r) {
  940. DBG("ath9k: Failed to set channel\n");
  941. return 0;
  942. }
  943. ath9k_hw_set_clockrate(ah);
  944. ah->eep_ops->set_txpower(ah, chan,
  945. ath9k_regd_get_ctl(regulatory, chan),
  946. 0,
  947. channel->maxpower * 2,
  948. min((u32) MAX_RATE_POWER,
  949. (u32) regulatory->power_limit), 0);
  950. ath9k_hw_rfbus_done(ah);
  951. if (IS_CHAN_OFDM(chan) || IS_CHAN_HT(chan))
  952. ath9k_hw_set_delta_slope(ah, chan);
  953. ath9k_hw_spur_mitigate_freq(ah, chan);
  954. return 1;
  955. }
  956. static void ath9k_hw_apply_gpio_override(struct ath_hw *ah)
  957. {
  958. u32 gpio_mask = ah->gpio_mask;
  959. int i;
  960. for (i = 0; gpio_mask; i++, gpio_mask >>= 1) {
  961. if (!(gpio_mask & 1))
  962. continue;
  963. ath9k_hw_cfg_output(ah, i, AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
  964. ath9k_hw_set_gpio(ah, i, !!(ah->gpio_val & BIT(i)));
  965. }
  966. }
  967. int ath9k_hw_check_alive(struct ath_hw *ah)
  968. {
  969. int count = 50;
  970. u32 reg;
  971. if (AR_SREV_9285_12_OR_LATER(ah))
  972. return 1;
  973. do {
  974. reg = REG_READ(ah, AR_OBS_BUS_1);
  975. if ((reg & 0x7E7FFFEF) == 0x00702400)
  976. continue;
  977. switch (reg & 0x7E000B00) {
  978. case 0x1E000000:
  979. case 0x52000B00:
  980. case 0x18000B00:
  981. continue;
  982. default:
  983. return 1;
  984. }
  985. } while (count-- > 0);
  986. return 0;
  987. }
  988. int ath9k_hw_reset(struct ath_hw *ah, struct ath9k_channel *chan,
  989. struct ath9k_hw_cal_data *caldata, int bChannelChange)
  990. {
  991. struct ath_common *common = ath9k_hw_common(ah);
  992. u32 saveLedState;
  993. struct ath9k_channel *curchan = ah->curchan;
  994. u32 saveDefAntenna;
  995. u32 macStaId1;
  996. int i, r;
  997. ah->txchainmask = common->tx_chainmask;
  998. ah->rxchainmask = common->rx_chainmask;
  999. if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
  1000. return -EIO;
  1001. if (curchan && !ah->chip_fullsleep)
  1002. ath9k_hw_getnf(ah, curchan);
  1003. ah->caldata = caldata;
  1004. if (caldata &&
  1005. (chan->channel != caldata->channel ||
  1006. (chan->channelFlags & ~CHANNEL_CW_INT) !=
  1007. (caldata->channelFlags & ~CHANNEL_CW_INT))) {
  1008. /* Operating channel changed, reset channel calibration data */
  1009. memset(caldata, 0, sizeof(*caldata));
  1010. ath9k_init_nfcal_hist_buffer(ah, chan);
  1011. }
  1012. if (bChannelChange &&
  1013. (ah->chip_fullsleep != 1) &&
  1014. (ah->curchan != NULL) &&
  1015. (chan->channel != ah->curchan->channel) &&
  1016. ((chan->channelFlags & CHANNEL_ALL) ==
  1017. (ah->curchan->channelFlags & CHANNEL_ALL)) &&
  1018. (!AR_SREV_9280(ah) || AR_DEVID_7010(ah))) {
  1019. if (ath9k_hw_channel_change(ah, chan)) {
  1020. ath9k_hw_loadnf(ah, ah->curchan);
  1021. ath9k_hw_start_nfcal(ah, 1);
  1022. if (AR_SREV_9271(ah))
  1023. ar9002_hw_load_ani_reg(ah, chan);
  1024. return 0;
  1025. }
  1026. }
  1027. saveDefAntenna = REG_READ(ah, AR_DEF_ANTENNA);
  1028. if (saveDefAntenna == 0)
  1029. saveDefAntenna = 1;
  1030. macStaId1 = REG_READ(ah, AR_STA_ID1) & AR_STA_ID1_BASE_RATE_11B;
  1031. saveLedState = REG_READ(ah, AR_CFG_LED) &
  1032. (AR_CFG_LED_ASSOC_CTL | AR_CFG_LED_MODE_SEL |
  1033. AR_CFG_LED_BLINK_THRESH_SEL | AR_CFG_LED_BLINK_SLOW);
  1034. ath9k_hw_mark_phy_inactive(ah);
  1035. ah->paprd_table_write_done = 0;
  1036. /* Only required on the first reset */
  1037. if (AR_SREV_9271(ah) && ah->htc_reset_init) {
  1038. REG_WRITE(ah,
  1039. AR9271_RESET_POWER_DOWN_CONTROL,
  1040. AR9271_RADIO_RF_RST);
  1041. udelay(50);
  1042. }
  1043. if (!ath9k_hw_chip_reset(ah, chan)) {
  1044. DBG("ath9k: Chip reset failed\n");
  1045. return -EINVAL;
  1046. }
  1047. /* Only required on the first reset */
  1048. if (AR_SREV_9271(ah) && ah->htc_reset_init) {
  1049. ah->htc_reset_init = 0;
  1050. REG_WRITE(ah,
  1051. AR9271_RESET_POWER_DOWN_CONTROL,
  1052. AR9271_GATE_MAC_CTL);
  1053. udelay(50);
  1054. }
  1055. if (AR_SREV_9280_20_OR_LATER(ah))
  1056. REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL, AR_GPIO_JTAG_DISABLE);
  1057. if (!AR_SREV_9300_20_OR_LATER(ah))
  1058. ar9002_hw_enable_async_fifo(ah);
  1059. r = ath9k_hw_process_ini(ah, chan);
  1060. if (r)
  1061. return r;
  1062. /* Setup MFP options for CCMP */
  1063. if (AR_SREV_9280_20_OR_LATER(ah)) {
  1064. /* Mask Retry(b11), PwrMgt(b12), MoreData(b13) to 0 in mgmt
  1065. * frames when constructing CCMP AAD. */
  1066. REG_RMW_FIELD(ah, AR_AES_MUTE_MASK1, AR_AES_MUTE_MASK1_FC_MGMT,
  1067. 0xc7ff);
  1068. ah->sw_mgmt_crypto = 0;
  1069. } else if (AR_SREV_9160_10_OR_LATER(ah)) {
  1070. /* Disable hardware crypto for management frames */
  1071. REG_CLR_BIT(ah, AR_PCU_MISC_MODE2,
  1072. AR_PCU_MISC_MODE2_MGMT_CRYPTO_ENABLE);
  1073. REG_SET_BIT(ah, AR_PCU_MISC_MODE2,
  1074. AR_PCU_MISC_MODE2_NO_CRYPTO_FOR_NON_DATA_PKT);
  1075. ah->sw_mgmt_crypto = 1;
  1076. } else
  1077. ah->sw_mgmt_crypto = 1;
  1078. if (IS_CHAN_OFDM(chan) || IS_CHAN_HT(chan))
  1079. ath9k_hw_set_delta_slope(ah, chan);
  1080. ath9k_hw_spur_mitigate_freq(ah, chan);
  1081. ah->eep_ops->set_board_values(ah, chan);
  1082. ENABLE_REGWRITE_BUFFER(ah);
  1083. REG_WRITE(ah, AR_STA_ID0, get_unaligned_le32(common->macaddr));
  1084. REG_WRITE(ah, AR_STA_ID1, get_unaligned_le16(common->macaddr + 4)
  1085. | macStaId1
  1086. | AR_STA_ID1_RTS_USE_DEF
  1087. | (ah->config.
  1088. ack_6mb ? AR_STA_ID1_ACKCTS_6MB : 0)
  1089. | ah->sta_id1_defaults);
  1090. ath_hw_setbssidmask(common);
  1091. REG_WRITE(ah, AR_DEF_ANTENNA, saveDefAntenna);
  1092. ath9k_hw_write_associd(ah);
  1093. REG_WRITE(ah, AR_ISR, ~0);
  1094. REG_WRITE(ah, AR_RSSI_THR, INIT_RSSI_THR);
  1095. REGWRITE_BUFFER_FLUSH(ah);
  1096. ath9k_hw_set_operating_mode(ah);
  1097. r = ath9k_hw_rf_set_freq(ah, chan);
  1098. if (r)
  1099. return r;
  1100. ath9k_hw_set_clockrate(ah);
  1101. ENABLE_REGWRITE_BUFFER(ah);
  1102. for (i = 0; i < AR_NUM_DCU; i++)
  1103. REG_WRITE(ah, AR_DQCUMASK(i), 1 << i);
  1104. REGWRITE_BUFFER_FLUSH(ah);
  1105. ah->intr_txqs = 0;
  1106. for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++)
  1107. ath9k_hw_resettxqueue(ah, i);
  1108. ath9k_hw_init_interrupt_masks(ah);
  1109. ath9k_hw_ani_cache_ini_regs(ah);
  1110. if (ah->caps.hw_caps & ATH9K_HW_CAP_RFSILENT)
  1111. ath9k_hw_cfg_gpio_input(ah, ah->rfkill_gpio);
  1112. ath9k_hw_init_global_settings(ah);
  1113. if (!AR_SREV_9300_20_OR_LATER(ah)) {
  1114. ar9002_hw_update_async_fifo(ah);
  1115. ar9002_hw_enable_wep_aggregation(ah);
  1116. }
  1117. REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PRESERVE_SEQNUM);
  1118. ath9k_hw_set_dma(ah);
  1119. REG_WRITE(ah, AR_OBS, 8);
  1120. if (ah->config.rx_intr_mitigation) {
  1121. REG_RMW_FIELD(ah, AR_RIMT, AR_RIMT_LAST, 500);
  1122. REG_RMW_FIELD(ah, AR_RIMT, AR_RIMT_FIRST, 2000);
  1123. }
  1124. if (ah->config.tx_intr_mitigation) {
  1125. REG_RMW_FIELD(ah, AR_TIMT, AR_TIMT_LAST, 300);
  1126. REG_RMW_FIELD(ah, AR_TIMT, AR_TIMT_FIRST, 750);
  1127. }
  1128. ath9k_hw_init_bb(ah, chan);
  1129. if (!ath9k_hw_init_cal(ah, chan))
  1130. return -EIO;
  1131. ENABLE_REGWRITE_BUFFER(ah);
  1132. ath9k_hw_restore_chainmask(ah);
  1133. REG_WRITE(ah, AR_CFG_LED, saveLedState | AR_CFG_SCLK_32KHZ);
  1134. REGWRITE_BUFFER_FLUSH(ah);
  1135. /*
  1136. * For big endian systems turn on swapping for descriptors
  1137. */
  1138. if (AR_SREV_9100(ah)) {
  1139. u32 mask;
  1140. mask = REG_READ(ah, AR_CFG);
  1141. if (mask & (AR_CFG_SWRB | AR_CFG_SWTB | AR_CFG_SWRG)) {
  1142. DBG2("ath9k: "
  1143. "CFG Byte Swap Set 0x%x\n", mask);
  1144. } else {
  1145. mask =
  1146. INIT_CONFIG_STATUS | AR_CFG_SWRB | AR_CFG_SWTB;
  1147. REG_WRITE(ah, AR_CFG, mask);
  1148. DBG2("ath9k: "
  1149. "Setting CFG 0x%x\n", REG_READ(ah, AR_CFG));
  1150. }
  1151. } else {
  1152. if (common->bus_ops->ath_bus_type == ATH_USB) {
  1153. /* Configure AR9271 target WLAN */
  1154. if (AR_SREV_9271(ah))
  1155. REG_WRITE(ah, AR_CFG, AR_CFG_SWRB | AR_CFG_SWTB);
  1156. else
  1157. REG_WRITE(ah, AR_CFG, AR_CFG_SWTD | AR_CFG_SWRD);
  1158. }
  1159. #if __BYTE_ORDER == __BIG_ENDIAN
  1160. else if (AR_SREV_9340(ah))
  1161. REG_RMW(ah, AR_CFG, AR_CFG_SWRB | AR_CFG_SWTB, 0);
  1162. else
  1163. REG_WRITE(ah, AR_CFG, AR_CFG_SWTD | AR_CFG_SWRD);
  1164. #endif
  1165. }
  1166. if (AR_SREV_9300_20_OR_LATER(ah)) {
  1167. ar9003_hw_disable_phy_restart(ah);
  1168. }
  1169. ath9k_hw_apply_gpio_override(ah);
  1170. return 0;
  1171. }
  1172. /******************************/
  1173. /* Power Management (Chipset) */
  1174. /******************************/
  1175. /*
  1176. * Notify Power Mgt is disabled in self-generated frames.
  1177. * If requested, force chip to sleep.
  1178. */
  1179. static void ath9k_set_power_sleep(struct ath_hw *ah, int setChip)
  1180. {
  1181. REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
  1182. if (setChip) {
  1183. /*
  1184. * Clear the RTC force wake bit to allow the
  1185. * mac to go to sleep.
  1186. */
  1187. REG_CLR_BIT(ah, AR_RTC_FORCE_WAKE,
  1188. AR_RTC_FORCE_WAKE_EN);
  1189. if (!AR_SREV_9100(ah) && !AR_SREV_9300_20_OR_LATER(ah))
  1190. REG_WRITE(ah, AR_RC, AR_RC_AHB | AR_RC_HOSTIF);
  1191. /* Shutdown chip. Active low */
  1192. if (!AR_SREV_5416(ah) && !AR_SREV_9271(ah))
  1193. REG_CLR_BIT(ah, (AR_RTC_RESET),
  1194. AR_RTC_RESET_EN);
  1195. }
  1196. /* Clear Bit 14 of AR_WA after putting chip into Full Sleep mode. */
  1197. if (AR_SREV_9300_20_OR_LATER(ah))
  1198. REG_WRITE(ah, AR_WA,
  1199. ah->WARegVal & ~AR_WA_D3_L1_DISABLE);
  1200. }
  1201. static int ath9k_hw_set_power_awake(struct ath_hw *ah, int setChip)
  1202. {
  1203. u32 val;
  1204. int i;
  1205. /* Set Bits 14 and 17 of AR_WA before powering on the chip. */
  1206. if (AR_SREV_9300_20_OR_LATER(ah)) {
  1207. REG_WRITE(ah, AR_WA, ah->WARegVal);
  1208. udelay(10);
  1209. }
  1210. if (setChip) {
  1211. if ((REG_READ(ah, AR_RTC_STATUS) &
  1212. AR_RTC_STATUS_M) == AR_RTC_STATUS_SHUTDOWN) {
  1213. if (ath9k_hw_set_reset_reg(ah,
  1214. ATH9K_RESET_POWER_ON) != 1) {
  1215. return 0;
  1216. }
  1217. if (!AR_SREV_9300_20_OR_LATER(ah))
  1218. ath9k_hw_init_pll(ah, NULL);
  1219. }
  1220. if (AR_SREV_9100(ah))
  1221. REG_SET_BIT(ah, AR_RTC_RESET,
  1222. AR_RTC_RESET_EN);
  1223. REG_SET_BIT(ah, AR_RTC_FORCE_WAKE,
  1224. AR_RTC_FORCE_WAKE_EN);
  1225. udelay(50);
  1226. for (i = POWER_UP_TIME / 50; i > 0; i--) {
  1227. val = REG_READ(ah, AR_RTC_STATUS) & AR_RTC_STATUS_M;
  1228. if (val == AR_RTC_STATUS_ON)
  1229. break;
  1230. udelay(50);
  1231. REG_SET_BIT(ah, AR_RTC_FORCE_WAKE,
  1232. AR_RTC_FORCE_WAKE_EN);
  1233. }
  1234. if (i == 0) {
  1235. DBG("ath9k: "
  1236. "Failed to wakeup in %dus\n",
  1237. POWER_UP_TIME / 20);
  1238. return 0;
  1239. }
  1240. }
  1241. REG_CLR_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
  1242. return 1;
  1243. }
  1244. int ath9k_hw_setpower(struct ath_hw *ah, enum ath9k_power_mode mode)
  1245. {
  1246. int status = 1, setChip = 1;
  1247. static const char *modes[] = {
  1248. "AWAKE",
  1249. "FULL-SLEEP",
  1250. "NETWORK SLEEP",
  1251. "UNDEFINED"
  1252. };
  1253. if (ah->power_mode == mode)
  1254. return status;
  1255. DBG2("ath9k: %s -> %s\n",
  1256. modes[ah->power_mode], modes[mode]);
  1257. switch (mode) {
  1258. case ATH9K_PM_AWAKE:
  1259. status = ath9k_hw_set_power_awake(ah, setChip);
  1260. break;
  1261. case ATH9K_PM_FULL_SLEEP:
  1262. ath9k_set_power_sleep(ah, setChip);
  1263. ah->chip_fullsleep = 1;
  1264. break;
  1265. default:
  1266. DBG("ath9k: Unknown power mode %d\n", mode);
  1267. return 0;
  1268. }
  1269. ah->power_mode = mode;
  1270. return status;
  1271. }
  1272. /*******************/
  1273. /* HW Capabilities */
  1274. /*******************/
  1275. int ath9k_hw_fill_cap_info(struct ath_hw *ah)
  1276. {
  1277. struct ath9k_hw_capabilities *pCap = &ah->caps;
  1278. struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
  1279. struct ath_common *common = ath9k_hw_common(ah);
  1280. u16 eeval;
  1281. u8 ant_div_ctl1, tx_chainmask, rx_chainmask;
  1282. eeval = ah->eep_ops->get_eeprom(ah, EEP_REG_0);
  1283. regulatory->current_rd = eeval;
  1284. eeval = ah->eep_ops->get_eeprom(ah, EEP_REG_1);
  1285. if (AR_SREV_9285_12_OR_LATER(ah))
  1286. eeval |= AR9285_RDEXT_DEFAULT;
  1287. regulatory->current_rd_ext = eeval;
  1288. if (ah->hw_version.subvendorid == AR_SUBVENDOR_ID_NEW_A) {
  1289. if (regulatory->current_rd == 0x64 ||
  1290. regulatory->current_rd == 0x65)
  1291. regulatory->current_rd += 5;
  1292. else if (regulatory->current_rd == 0x41)
  1293. regulatory->current_rd = 0x43;
  1294. DBG2("ath9k: "
  1295. "regdomain mapped to 0x%x\n", regulatory->current_rd);
  1296. }
  1297. eeval = ah->eep_ops->get_eeprom(ah, EEP_OP_MODE);
  1298. if ((eeval & (AR5416_OPFLAGS_11G | AR5416_OPFLAGS_11A)) == 0) {
  1299. DBG("ath9k: "
  1300. "no band has been marked as supported in EEPROM\n");
  1301. return -EINVAL;
  1302. }
  1303. if (eeval & AR5416_OPFLAGS_11A)
  1304. pCap->hw_caps |= ATH9K_HW_CAP_5GHZ;
  1305. if (eeval & AR5416_OPFLAGS_11G)
  1306. pCap->hw_caps |= ATH9K_HW_CAP_2GHZ;
  1307. pCap->tx_chainmask = ah->eep_ops->get_eeprom(ah, EEP_TX_MASK);
  1308. /*
  1309. * For AR9271 we will temporarilly uses the rx chainmax as read from
  1310. * the EEPROM.
  1311. */
  1312. if ((ah->hw_version.devid == AR5416_DEVID_PCI) &&
  1313. !(eeval & AR5416_OPFLAGS_11A) &&
  1314. !(AR_SREV_9271(ah)))
  1315. /* CB71: GPIO 0 is pulled down to indicate 3 rx chains */
  1316. pCap->rx_chainmask = ath9k_hw_gpio_get(ah, 0) ? 0x5 : 0x7;
  1317. else if (AR_SREV_9100(ah))
  1318. pCap->rx_chainmask = 0x7;
  1319. else
  1320. /* Use rx_chainmask from EEPROM. */
  1321. pCap->rx_chainmask = ah->eep_ops->get_eeprom(ah, EEP_RX_MASK);
  1322. ah->misc_mode |= AR_PCU_MIC_NEW_LOC_ENA;
  1323. /* enable key search for every frame in an aggregate */
  1324. if (AR_SREV_9300_20_OR_LATER(ah))
  1325. ah->misc_mode |= AR_PCU_ALWAYS_PERFORM_KEYSEARCH;
  1326. common->crypt_caps |= ATH_CRYPT_CAP_CIPHER_AESCCM;
  1327. pCap->hw_caps &= ~ATH9K_HW_CAP_HT;
  1328. if (AR_SREV_9271(ah))
  1329. pCap->num_gpio_pins = AR9271_NUM_GPIO;
  1330. else if (AR_DEVID_7010(ah))
  1331. pCap->num_gpio_pins = AR7010_NUM_GPIO;
  1332. else if (AR_SREV_9285_12_OR_LATER(ah))
  1333. pCap->num_gpio_pins = AR9285_NUM_GPIO;
  1334. else if (AR_SREV_9280_20_OR_LATER(ah))
  1335. pCap->num_gpio_pins = AR928X_NUM_GPIO;
  1336. else
  1337. pCap->num_gpio_pins = AR_NUM_GPIO;
  1338. if (AR_SREV_9160_10_OR_LATER(ah) || AR_SREV_9100(ah)) {
  1339. pCap->hw_caps |= ATH9K_HW_CAP_CST;
  1340. pCap->rts_aggr_limit = ATH_AMPDU_LIMIT_MAX;
  1341. } else {
  1342. pCap->rts_aggr_limit = (8 * 1024);
  1343. }
  1344. ah->rfsilent = ah->eep_ops->get_eeprom(ah, EEP_RF_SILENT);
  1345. if (ah->rfsilent & EEP_RFSILENT_ENABLED) {
  1346. ah->rfkill_gpio =
  1347. MS(ah->rfsilent, EEP_RFSILENT_GPIO_SEL);
  1348. ah->rfkill_polarity =
  1349. MS(ah->rfsilent, EEP_RFSILENT_POLARITY);
  1350. pCap->hw_caps |= ATH9K_HW_CAP_RFSILENT;
  1351. }
  1352. pCap->hw_caps &= ~ATH9K_HW_CAP_AUTOSLEEP;
  1353. if (AR_SREV_9280(ah) || AR_SREV_9285(ah))
  1354. pCap->hw_caps &= ~ATH9K_HW_CAP_4KB_SPLITTRANS;
  1355. else
  1356. pCap->hw_caps |= ATH9K_HW_CAP_4KB_SPLITTRANS;
  1357. if (AR_SREV_9300_20_OR_LATER(ah)) {
  1358. pCap->hw_caps |= ATH9K_HW_CAP_FASTCLOCK;
  1359. if (!AR_SREV_9485(ah))
  1360. pCap->hw_caps |= ATH9K_HW_CAP_LDPC;
  1361. pCap->rx_hp_qdepth = ATH9K_HW_RX_HP_QDEPTH;
  1362. pCap->rx_lp_qdepth = ATH9K_HW_RX_LP_QDEPTH;
  1363. pCap->rx_status_len = sizeof(struct ar9003_rxs);
  1364. pCap->tx_desc_len = sizeof(struct ar9003_txc);
  1365. pCap->txs_len = sizeof(struct ar9003_txs);
  1366. if (!ah->config.paprd_disable &&
  1367. ah->eep_ops->get_eeprom(ah, EEP_PAPRD))
  1368. pCap->hw_caps |= ATH9K_HW_CAP_PAPRD;
  1369. } else {
  1370. pCap->tx_desc_len = sizeof(struct ath_desc);
  1371. if (AR_SREV_9280_20(ah) &&
  1372. ((ah->eep_ops->get_eeprom(ah, EEP_MINOR_REV) <=
  1373. AR5416_EEP_MINOR_VER_16) ||
  1374. ah->eep_ops->get_eeprom(ah, EEP_FSTCLK_5G)))
  1375. pCap->hw_caps |= ATH9K_HW_CAP_FASTCLOCK;
  1376. }
  1377. if (AR_SREV_9300_20_OR_LATER(ah))
  1378. pCap->hw_caps |= ATH9K_HW_CAP_RAC_SUPPORTED;
  1379. if (AR_SREV_9300_20_OR_LATER(ah))
  1380. ah->ent_mode = REG_READ(ah, AR_ENT_OTP);
  1381. if (AR_SREV_9287_11_OR_LATER(ah) || AR_SREV_9271(ah))
  1382. pCap->hw_caps |= ATH9K_HW_CAP_SGI_20;
  1383. if (AR_SREV_9285(ah))
  1384. if (ah->eep_ops->get_eeprom(ah, EEP_MODAL_VER) >= 3) {
  1385. ant_div_ctl1 =
  1386. ah->eep_ops->get_eeprom(ah, EEP_ANT_DIV_CTL1);
  1387. if ((ant_div_ctl1 & 0x1) && ((ant_div_ctl1 >> 3) & 0x1))
  1388. pCap->hw_caps |= ATH9K_HW_CAP_ANT_DIV_COMB;
  1389. }
  1390. if (AR_SREV_9300_20_OR_LATER(ah)) {
  1391. if (ah->eep_ops->get_eeprom(ah, EEP_CHAIN_MASK_REDUCE))
  1392. pCap->hw_caps |= ATH9K_HW_CAP_APM;
  1393. }
  1394. if (AR_SREV_9485(ah)) {
  1395. ant_div_ctl1 = ah->eep_ops->get_eeprom(ah, EEP_ANT_DIV_CTL1);
  1396. /*
  1397. * enable the diversity-combining algorithm only when
  1398. * both enable_lna_div and enable_fast_div are set
  1399. * Table for Diversity
  1400. * ant_div_alt_lnaconf bit 0-1
  1401. * ant_div_main_lnaconf bit 2-3
  1402. * ant_div_alt_gaintb bit 4
  1403. * ant_div_main_gaintb bit 5
  1404. * enable_ant_div_lnadiv bit 6
  1405. * enable_ant_fast_div bit 7
  1406. */
  1407. if ((ant_div_ctl1 >> 0x6) == 0x3)
  1408. pCap->hw_caps |= ATH9K_HW_CAP_ANT_DIV_COMB;
  1409. }
  1410. if (AR_SREV_9485_10(ah)) {
  1411. pCap->pcie_lcr_extsync_en = 1;
  1412. pCap->pcie_lcr_offset = 0x80;
  1413. }
  1414. tx_chainmask = pCap->tx_chainmask;
  1415. rx_chainmask = pCap->rx_chainmask;
  1416. while (tx_chainmask || rx_chainmask) {
  1417. if (tx_chainmask & BIT(0))
  1418. pCap->max_txchains++;
  1419. if (rx_chainmask & BIT(0))
  1420. pCap->max_rxchains++;
  1421. tx_chainmask >>= 1;
  1422. rx_chainmask >>= 1;
  1423. }
  1424. return 0;
  1425. }
  1426. /****************************/
  1427. /* GPIO / RFKILL / Antennae */
  1428. /****************************/
  1429. static void ath9k_hw_gpio_cfg_output_mux(struct ath_hw *ah,
  1430. u32 gpio, u32 type)
  1431. {
  1432. int addr;
  1433. u32 gpio_shift, tmp;
  1434. if (gpio > 11)
  1435. addr = AR_GPIO_OUTPUT_MUX3;
  1436. else if (gpio > 5)
  1437. addr = AR_GPIO_OUTPUT_MUX2;
  1438. else
  1439. addr = AR_GPIO_OUTPUT_MUX1;
  1440. gpio_shift = (gpio % 6) * 5;
  1441. if (AR_SREV_9280_20_OR_LATER(ah)
  1442. || (addr != AR_GPIO_OUTPUT_MUX1)) {
  1443. REG_RMW(ah, addr, (type << gpio_shift),
  1444. (0x1f << gpio_shift));
  1445. } else {
  1446. tmp = REG_READ(ah, addr);
  1447. tmp = ((tmp & 0x1F0) << 1) | (tmp & ~0x1F0);
  1448. tmp &= ~(0x1f << gpio_shift);
  1449. tmp |= (type << gpio_shift);
  1450. REG_WRITE(ah, addr, tmp);
  1451. }
  1452. }
  1453. void ath9k_hw_cfg_gpio_input(struct ath_hw *ah, u32 gpio)
  1454. {
  1455. u32 gpio_shift;
  1456. if (AR_DEVID_7010(ah)) {
  1457. gpio_shift = gpio;
  1458. REG_RMW(ah, AR7010_GPIO_OE,
  1459. (AR7010_GPIO_OE_AS_INPUT << gpio_shift),
  1460. (AR7010_GPIO_OE_MASK << gpio_shift));
  1461. return;
  1462. }
  1463. gpio_shift = gpio << 1;
  1464. REG_RMW(ah,
  1465. AR_GPIO_OE_OUT,
  1466. (AR_GPIO_OE_OUT_DRV_NO << gpio_shift),
  1467. (AR_GPIO_OE_OUT_DRV << gpio_shift));
  1468. }
  1469. u32 ath9k_hw_gpio_get(struct ath_hw *ah, u32 gpio)
  1470. {
  1471. #define MS_REG_READ(x, y) \
  1472. (MS(REG_READ(ah, AR_GPIO_IN_OUT), x##_GPIO_IN_VAL) & (AR_GPIO_BIT(y)))
  1473. if (gpio >= ah->caps.num_gpio_pins)
  1474. return 0xffffffff;
  1475. if (AR_DEVID_7010(ah)) {
  1476. u32 val;
  1477. val = REG_READ(ah, AR7010_GPIO_IN);
  1478. return (MS(val, AR7010_GPIO_IN_VAL) & AR_GPIO_BIT(gpio)) == 0;
  1479. } else if (AR_SREV_9300_20_OR_LATER(ah))
  1480. return (MS(REG_READ(ah, AR_GPIO_IN), AR9300_GPIO_IN_VAL) &
  1481. AR_GPIO_BIT(gpio)) != 0;
  1482. else if (AR_SREV_9271(ah))
  1483. return MS_REG_READ(AR9271, gpio) != 0;
  1484. else if (AR_SREV_9287_11_OR_LATER(ah))
  1485. return MS_REG_READ(AR9287, gpio) != 0;
  1486. else if (AR_SREV_9285_12_OR_LATER(ah))
  1487. return MS_REG_READ(AR9285, gpio) != 0;
  1488. else if (AR_SREV_9280_20_OR_LATER(ah))
  1489. return MS_REG_READ(AR928X, gpio) != 0;
  1490. else
  1491. return MS_REG_READ(AR, gpio) != 0;
  1492. }
  1493. void ath9k_hw_cfg_output(struct ath_hw *ah, u32 gpio,
  1494. u32 ah_signal_type)
  1495. {
  1496. u32 gpio_shift;
  1497. if (AR_DEVID_7010(ah)) {
  1498. gpio_shift = gpio;
  1499. REG_RMW(ah, AR7010_GPIO_OE,
  1500. (AR7010_GPIO_OE_AS_OUTPUT << gpio_shift),
  1501. (AR7010_GPIO_OE_MASK << gpio_shift));
  1502. return;
  1503. }
  1504. ath9k_hw_gpio_cfg_output_mux(ah, gpio, ah_signal_type);
  1505. gpio_shift = 2 * gpio;
  1506. REG_RMW(ah,
  1507. AR_GPIO_OE_OUT,
  1508. (AR_GPIO_OE_OUT_DRV_ALL << gpio_shift),
  1509. (AR_GPIO_OE_OUT_DRV << gpio_shift));
  1510. }
  1511. void ath9k_hw_set_gpio(struct ath_hw *ah, u32 gpio, u32 val)
  1512. {
  1513. if (AR_DEVID_7010(ah)) {
  1514. val = val ? 0 : 1;
  1515. REG_RMW(ah, AR7010_GPIO_OUT, ((val&1) << gpio),
  1516. AR_GPIO_BIT(gpio));
  1517. return;
  1518. }
  1519. if (AR_SREV_9271(ah))
  1520. val = ~val;
  1521. REG_RMW(ah, AR_GPIO_IN_OUT, ((val & 1) << gpio),
  1522. AR_GPIO_BIT(gpio));
  1523. }
  1524. u32 ath9k_hw_getdefantenna(struct ath_hw *ah)
  1525. {
  1526. return REG_READ(ah, AR_DEF_ANTENNA) & 0x7;
  1527. }
  1528. void ath9k_hw_setantenna(struct ath_hw *ah, u32 antenna)
  1529. {
  1530. REG_WRITE(ah, AR_DEF_ANTENNA, (antenna & 0x7));
  1531. }
  1532. /*********************/
  1533. /* General Operation */
  1534. /*********************/
  1535. u32 ath9k_hw_getrxfilter(struct ath_hw *ah)
  1536. {
  1537. u32 bits = REG_READ(ah, AR_RX_FILTER);
  1538. u32 phybits = REG_READ(ah, AR_PHY_ERR);
  1539. if (phybits & AR_PHY_ERR_RADAR)
  1540. bits |= ATH9K_RX_FILTER_PHYRADAR;
  1541. if (phybits & (AR_PHY_ERR_OFDM_TIMING | AR_PHY_ERR_CCK_TIMING))
  1542. bits |= ATH9K_RX_FILTER_PHYERR;
  1543. return bits;
  1544. }
  1545. void ath9k_hw_setrxfilter(struct ath_hw *ah, u32 bits)
  1546. {
  1547. u32 phybits;
  1548. ENABLE_REGWRITE_BUFFER(ah);
  1549. REG_WRITE(ah, AR_RX_FILTER, bits);
  1550. phybits = 0;
  1551. if (bits & ATH9K_RX_FILTER_PHYRADAR)
  1552. phybits |= AR_PHY_ERR_RADAR;
  1553. if (bits & ATH9K_RX_FILTER_PHYERR)
  1554. phybits |= AR_PHY_ERR_OFDM_TIMING | AR_PHY_ERR_CCK_TIMING;
  1555. REG_WRITE(ah, AR_PHY_ERR, phybits);
  1556. if (phybits)
  1557. REG_SET_BIT(ah, AR_RXCFG, AR_RXCFG_ZLFDMA);
  1558. else
  1559. REG_CLR_BIT(ah, AR_RXCFG, AR_RXCFG_ZLFDMA);
  1560. REGWRITE_BUFFER_FLUSH(ah);
  1561. }
  1562. int ath9k_hw_phy_disable(struct ath_hw *ah)
  1563. {
  1564. if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_WARM))
  1565. return 0;
  1566. ath9k_hw_init_pll(ah, NULL);
  1567. return 1;
  1568. }
  1569. int ath9k_hw_disable(struct ath_hw *ah)
  1570. {
  1571. if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
  1572. return 0;
  1573. if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_COLD))
  1574. return 0;
  1575. ath9k_hw_init_pll(ah, NULL);
  1576. return 1;
  1577. }
  1578. void ath9k_hw_set_txpowerlimit(struct ath_hw *ah, u32 limit, int test)
  1579. {
  1580. struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
  1581. struct ath9k_channel *chan = ah->curchan;
  1582. struct net80211_channel *channel = chan->chan;
  1583. regulatory->power_limit = min(limit, (u32) MAX_RATE_POWER);
  1584. ah->eep_ops->set_txpower(ah, chan,
  1585. ath9k_regd_get_ctl(regulatory, chan),
  1586. 0,
  1587. channel->maxpower * 2,
  1588. min((u32) MAX_RATE_POWER,
  1589. (u32) regulatory->power_limit), test);
  1590. }
  1591. void ath9k_hw_setopmode(struct ath_hw *ah)
  1592. {
  1593. ath9k_hw_set_operating_mode(ah);
  1594. }
  1595. void ath9k_hw_setmcastfilter(struct ath_hw *ah, u32 filter0, u32 filter1)
  1596. {
  1597. REG_WRITE(ah, AR_MCAST_FIL0, filter0);
  1598. REG_WRITE(ah, AR_MCAST_FIL1, filter1);
  1599. }
  1600. void ath9k_hw_write_associd(struct ath_hw *ah)
  1601. {
  1602. struct ath_common *common = ath9k_hw_common(ah);
  1603. REG_WRITE(ah, AR_BSS_ID0, get_unaligned_le32(common->curbssid));
  1604. REG_WRITE(ah, AR_BSS_ID1, get_unaligned_le16(common->curbssid + 4) |
  1605. ((common->curaid & 0x3fff) << AR_BSS_ID1_AID_S));
  1606. }
  1607. void ath9k_hw_set11nmac2040(struct ath_hw *ah)
  1608. {
  1609. u32 macmode;
  1610. macmode = 0;
  1611. REG_WRITE(ah, AR_2040_MODE, macmode);
  1612. }
  1613. static struct {
  1614. u32 version;
  1615. const char * name;
  1616. } ath_mac_bb_names[] = {
  1617. /* Devices with external radios */
  1618. { AR_SREV_VERSION_5416_PCI, "5416" },
  1619. { AR_SREV_VERSION_5416_PCIE, "5418" },
  1620. { AR_SREV_VERSION_9100, "9100" },
  1621. { AR_SREV_VERSION_9160, "9160" },
  1622. /* Single-chip solutions */
  1623. { AR_SREV_VERSION_9280, "9280" },
  1624. { AR_SREV_VERSION_9285, "9285" },
  1625. { AR_SREV_VERSION_9287, "9287" },
  1626. { AR_SREV_VERSION_9271, "9271" },
  1627. { AR_SREV_VERSION_9300, "9300" },
  1628. { AR_SREV_VERSION_9485, "9485" },
  1629. };
  1630. /* For devices with external radios */
  1631. static struct {
  1632. u16 version;
  1633. const char * name;
  1634. } ath_rf_names[] = {
  1635. { 0, "5133" },
  1636. { AR_RAD5133_SREV_MAJOR, "5133" },
  1637. { AR_RAD5122_SREV_MAJOR, "5122" },
  1638. { AR_RAD2133_SREV_MAJOR, "2133" },
  1639. { AR_RAD2122_SREV_MAJOR, "2122" }
  1640. };
  1641. /*
  1642. * Return the MAC/BB name. "????" is returned if the MAC/BB is unknown.
  1643. */
  1644. static const char *ath9k_hw_mac_bb_name(u32 mac_bb_version)
  1645. {
  1646. unsigned int i;
  1647. for (i=0; i<ARRAY_SIZE(ath_mac_bb_names); i++) {
  1648. if (ath_mac_bb_names[i].version == mac_bb_version) {
  1649. return ath_mac_bb_names[i].name;
  1650. }
  1651. }
  1652. return "????";
  1653. }
  1654. /*
  1655. * Return the RF name. "????" is returned if the RF is unknown.
  1656. * Used for devices with external radios.
  1657. */
  1658. static const char *ath9k_hw_rf_name(u16 rf_version)
  1659. {
  1660. unsigned int i;
  1661. for (i=0; i<ARRAY_SIZE(ath_rf_names); i++) {
  1662. if (ath_rf_names[i].version == rf_version) {
  1663. return ath_rf_names[i].name;
  1664. }
  1665. }
  1666. return "????";
  1667. }
  1668. void ath9k_hw_name(struct ath_hw *ah, char *hw_name, size_t len)
  1669. {
  1670. int used;
  1671. /* chipsets >= AR9280 are single-chip */
  1672. if (AR_SREV_9280_20_OR_LATER(ah)) {
  1673. used = snprintf(hw_name, len,
  1674. "Atheros AR%s Rev:%x",
  1675. ath9k_hw_mac_bb_name(ah->hw_version.macVersion),
  1676. ah->hw_version.macRev);
  1677. }
  1678. else {
  1679. used = snprintf(hw_name, len,
  1680. "Atheros AR%s MAC/BB Rev:%x AR%s RF Rev:%x",
  1681. ath9k_hw_mac_bb_name(ah->hw_version.macVersion),
  1682. ah->hw_version.macRev,
  1683. ath9k_hw_rf_name((ah->hw_version.analog5GhzRev &
  1684. AR_RADIO_SREV_MAJOR)),
  1685. ah->hw_version.phyRev);
  1686. }
  1687. hw_name[used] = '\0';
  1688. }