4965.c 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2003 - 2011 Intel Corporation. All rights reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of version 2 of the GNU General Public License as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along with
  15. * this program; if not, write to the Free Software Foundation, Inc.,
  16. * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
  17. *
  18. * The full GNU General Public License is included in this distribution in the
  19. * file called LICENSE.
  20. *
  21. * Contact Information:
  22. * Intel Linux Wireless <ilw@linux.intel.com>
  23. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  24. *
  25. *****************************************************************************/
  26. #include <linux/kernel.h>
  27. #include <linux/module.h>
  28. #include <linux/pci.h>
  29. #include <linux/dma-mapping.h>
  30. #include <linux/delay.h>
  31. #include <linux/sched.h>
  32. #include <linux/skbuff.h>
  33. #include <linux/netdevice.h>
  34. #include <net/mac80211.h>
  35. #include <linux/etherdevice.h>
  36. #include <asm/unaligned.h>
  37. #include "common.h"
  38. #include "4965.h"
  39. /**
  40. * il_verify_inst_sparse - verify runtime uCode image in card vs. host,
  41. * using sample data 100 bytes apart. If these sample points are good,
  42. * it's a pretty good bet that everything between them is good, too.
  43. */
  44. static int
  45. il4965_verify_inst_sparse(struct il_priv *il, __le32 * image, u32 len)
  46. {
  47. u32 val;
  48. int ret = 0;
  49. u32 errcnt = 0;
  50. u32 i;
  51. D_INFO("ucode inst image size is %u\n", len);
  52. for (i = 0; i < len; i += 100, image += 100 / sizeof(u32)) {
  53. /* read data comes through single port, auto-incr addr */
  54. /* NOTE: Use the debugless read so we don't flood kernel log
  55. * if IL_DL_IO is set */
  56. il_wr(il, HBUS_TARG_MEM_RADDR, i + IL4965_RTC_INST_LOWER_BOUND);
  57. val = _il_rd(il, HBUS_TARG_MEM_RDAT);
  58. if (val != le32_to_cpu(*image)) {
  59. ret = -EIO;
  60. errcnt++;
  61. if (errcnt >= 3)
  62. break;
  63. }
  64. }
  65. return ret;
  66. }
  67. /**
  68. * il4965_verify_inst_full - verify runtime uCode image in card vs. host,
  69. * looking at all data.
  70. */
  71. static int
  72. il4965_verify_inst_full(struct il_priv *il, __le32 * image, u32 len)
  73. {
  74. u32 val;
  75. u32 save_len = len;
  76. int ret = 0;
  77. u32 errcnt;
  78. D_INFO("ucode inst image size is %u\n", len);
  79. il_wr(il, HBUS_TARG_MEM_RADDR, IL4965_RTC_INST_LOWER_BOUND);
  80. errcnt = 0;
  81. for (; len > 0; len -= sizeof(u32), image++) {
  82. /* read data comes through single port, auto-incr addr */
  83. /* NOTE: Use the debugless read so we don't flood kernel log
  84. * if IL_DL_IO is set */
  85. val = _il_rd(il, HBUS_TARG_MEM_RDAT);
  86. if (val != le32_to_cpu(*image)) {
  87. IL_ERR("uCode INST section is invalid at "
  88. "offset 0x%x, is 0x%x, s/b 0x%x\n",
  89. save_len - len, val, le32_to_cpu(*image));
  90. ret = -EIO;
  91. errcnt++;
  92. if (errcnt >= 20)
  93. break;
  94. }
  95. }
  96. if (!errcnt)
  97. D_INFO("ucode image in INSTRUCTION memory is good\n");
  98. return ret;
  99. }
  100. /**
  101. * il4965_verify_ucode - determine which instruction image is in SRAM,
  102. * and verify its contents
  103. */
  104. int
  105. il4965_verify_ucode(struct il_priv *il)
  106. {
  107. __le32 *image;
  108. u32 len;
  109. int ret;
  110. /* Try bootstrap */
  111. image = (__le32 *) il->ucode_boot.v_addr;
  112. len = il->ucode_boot.len;
  113. ret = il4965_verify_inst_sparse(il, image, len);
  114. if (!ret) {
  115. D_INFO("Bootstrap uCode is good in inst SRAM\n");
  116. return 0;
  117. }
  118. /* Try initialize */
  119. image = (__le32 *) il->ucode_init.v_addr;
  120. len = il->ucode_init.len;
  121. ret = il4965_verify_inst_sparse(il, image, len);
  122. if (!ret) {
  123. D_INFO("Initialize uCode is good in inst SRAM\n");
  124. return 0;
  125. }
  126. /* Try runtime/protocol */
  127. image = (__le32 *) il->ucode_code.v_addr;
  128. len = il->ucode_code.len;
  129. ret = il4965_verify_inst_sparse(il, image, len);
  130. if (!ret) {
  131. D_INFO("Runtime uCode is good in inst SRAM\n");
  132. return 0;
  133. }
  134. IL_ERR("NO VALID UCODE IMAGE IN INSTRUCTION SRAM!!\n");
  135. /* Since nothing seems to match, show first several data entries in
  136. * instruction SRAM, so maybe visual inspection will give a clue.
  137. * Selection of bootstrap image (vs. other images) is arbitrary. */
  138. image = (__le32 *) il->ucode_boot.v_addr;
  139. len = il->ucode_boot.len;
  140. ret = il4965_verify_inst_full(il, image, len);
  141. return ret;
  142. }
  143. /******************************************************************************
  144. *
  145. * EEPROM related functions
  146. *
  147. ******************************************************************************/
  148. /*
  149. * The device's EEPROM semaphore prevents conflicts between driver and uCode
  150. * when accessing the EEPROM; each access is a series of pulses to/from the
  151. * EEPROM chip, not a single event, so even reads could conflict if they
  152. * weren't arbitrated by the semaphore.
  153. */
  154. int
  155. il4965_eeprom_acquire_semaphore(struct il_priv *il)
  156. {
  157. u16 count;
  158. int ret;
  159. for (count = 0; count < EEPROM_SEM_RETRY_LIMIT; count++) {
  160. /* Request semaphore */
  161. il_set_bit(il, CSR_HW_IF_CONFIG_REG,
  162. CSR_HW_IF_CONFIG_REG_BIT_EEPROM_OWN_SEM);
  163. /* See if we got it */
  164. ret =
  165. _il_poll_bit(il, CSR_HW_IF_CONFIG_REG,
  166. CSR_HW_IF_CONFIG_REG_BIT_EEPROM_OWN_SEM,
  167. CSR_HW_IF_CONFIG_REG_BIT_EEPROM_OWN_SEM,
  168. EEPROM_SEM_TIMEOUT);
  169. if (ret >= 0)
  170. return ret;
  171. }
  172. return ret;
  173. }
  174. void
  175. il4965_eeprom_release_semaphore(struct il_priv *il)
  176. {
  177. il_clear_bit(il, CSR_HW_IF_CONFIG_REG,
  178. CSR_HW_IF_CONFIG_REG_BIT_EEPROM_OWN_SEM);
  179. }
  180. int
  181. il4965_eeprom_check_version(struct il_priv *il)
  182. {
  183. u16 eeprom_ver;
  184. u16 calib_ver;
  185. eeprom_ver = il_eeprom_query16(il, EEPROM_VERSION);
  186. calib_ver = il_eeprom_query16(il, EEPROM_4965_CALIB_VERSION_OFFSET);
  187. if (eeprom_ver < il->cfg->eeprom_ver ||
  188. calib_ver < il->cfg->eeprom_calib_ver)
  189. goto err;
  190. IL_INFO("device EEPROM VER=0x%x, CALIB=0x%x\n", eeprom_ver, calib_ver);
  191. return 0;
  192. err:
  193. IL_ERR("Unsupported (too old) EEPROM VER=0x%x < 0x%x "
  194. "CALIB=0x%x < 0x%x\n", eeprom_ver, il->cfg->eeprom_ver,
  195. calib_ver, il->cfg->eeprom_calib_ver);
  196. return -EINVAL;
  197. }
  198. void
  199. il4965_eeprom_get_mac(const struct il_priv *il, u8 * mac)
  200. {
  201. const u8 *addr = il_eeprom_query_addr(il,
  202. EEPROM_MAC_ADDRESS);
  203. memcpy(mac, addr, ETH_ALEN);
  204. }
  205. /* Send led command */
  206. static int
  207. il4965_send_led_cmd(struct il_priv *il, struct il_led_cmd *led_cmd)
  208. {
  209. struct il_host_cmd cmd = {
  210. .id = C_LEDS,
  211. .len = sizeof(struct il_led_cmd),
  212. .data = led_cmd,
  213. .flags = CMD_ASYNC,
  214. .callback = NULL,
  215. };
  216. u32 reg;
  217. reg = _il_rd(il, CSR_LED_REG);
  218. if (reg != (reg & CSR_LED_BSM_CTRL_MSK))
  219. _il_wr(il, CSR_LED_REG, reg & CSR_LED_BSM_CTRL_MSK);
  220. return il_send_cmd(il, &cmd);
  221. }
  222. /* Set led register off */
  223. void
  224. il4965_led_enable(struct il_priv *il)
  225. {
  226. _il_wr(il, CSR_LED_REG, CSR_LED_REG_TRUN_ON);
  227. }
  228. static int il4965_send_tx_power(struct il_priv *il);
  229. static int il4965_hw_get_temperature(struct il_priv *il);
  230. /* Highest firmware API version supported */
  231. #define IL4965_UCODE_API_MAX 2
  232. /* Lowest firmware API version supported */
  233. #define IL4965_UCODE_API_MIN 2
  234. #define IL4965_FW_PRE "iwlwifi-4965-"
  235. #define _IL4965_MODULE_FIRMWARE(api) IL4965_FW_PRE #api ".ucode"
  236. #define IL4965_MODULE_FIRMWARE(api) _IL4965_MODULE_FIRMWARE(api)
  237. /* check contents of special bootstrap uCode SRAM */
  238. static int
  239. il4965_verify_bsm(struct il_priv *il)
  240. {
  241. __le32 *image = il->ucode_boot.v_addr;
  242. u32 len = il->ucode_boot.len;
  243. u32 reg;
  244. u32 val;
  245. D_INFO("Begin verify bsm\n");
  246. /* verify BSM SRAM contents */
  247. val = il_rd_prph(il, BSM_WR_DWCOUNT_REG);
  248. for (reg = BSM_SRAM_LOWER_BOUND; reg < BSM_SRAM_LOWER_BOUND + len;
  249. reg += sizeof(u32), image++) {
  250. val = il_rd_prph(il, reg);
  251. if (val != le32_to_cpu(*image)) {
  252. IL_ERR("BSM uCode verification failed at "
  253. "addr 0x%08X+%u (of %u), is 0x%x, s/b 0x%x\n",
  254. BSM_SRAM_LOWER_BOUND, reg - BSM_SRAM_LOWER_BOUND,
  255. len, val, le32_to_cpu(*image));
  256. return -EIO;
  257. }
  258. }
  259. D_INFO("BSM bootstrap uCode image OK\n");
  260. return 0;
  261. }
  262. /**
  263. * il4965_load_bsm - Load bootstrap instructions
  264. *
  265. * BSM operation:
  266. *
  267. * The Bootstrap State Machine (BSM) stores a short bootstrap uCode program
  268. * in special SRAM that does not power down during RFKILL. When powering back
  269. * up after power-saving sleeps (or during initial uCode load), the BSM loads
  270. * the bootstrap program into the on-board processor, and starts it.
  271. *
  272. * The bootstrap program loads (via DMA) instructions and data for a new
  273. * program from host DRAM locations indicated by the host driver in the
  274. * BSM_DRAM_* registers. Once the new program is loaded, it starts
  275. * automatically.
  276. *
  277. * When initializing the NIC, the host driver points the BSM to the
  278. * "initialize" uCode image. This uCode sets up some internal data, then
  279. * notifies host via "initialize alive" that it is complete.
  280. *
  281. * The host then replaces the BSM_DRAM_* pointer values to point to the
  282. * normal runtime uCode instructions and a backup uCode data cache buffer
  283. * (filled initially with starting data values for the on-board processor),
  284. * then triggers the "initialize" uCode to load and launch the runtime uCode,
  285. * which begins normal operation.
  286. *
  287. * When doing a power-save shutdown, runtime uCode saves data SRAM into
  288. * the backup data cache in DRAM before SRAM is powered down.
  289. *
  290. * When powering back up, the BSM loads the bootstrap program. This reloads
  291. * the runtime uCode instructions and the backup data cache into SRAM,
  292. * and re-launches the runtime uCode from where it left off.
  293. */
  294. static int
  295. il4965_load_bsm(struct il_priv *il)
  296. {
  297. __le32 *image = il->ucode_boot.v_addr;
  298. u32 len = il->ucode_boot.len;
  299. dma_addr_t pinst;
  300. dma_addr_t pdata;
  301. u32 inst_len;
  302. u32 data_len;
  303. int i;
  304. u32 done;
  305. u32 reg_offset;
  306. int ret;
  307. D_INFO("Begin load bsm\n");
  308. il->ucode_type = UCODE_RT;
  309. /* make sure bootstrap program is no larger than BSM's SRAM size */
  310. if (len > IL49_MAX_BSM_SIZE)
  311. return -EINVAL;
  312. /* Tell bootstrap uCode where to find the "Initialize" uCode
  313. * in host DRAM ... host DRAM physical address bits 35:4 for 4965.
  314. * NOTE: il_init_alive_start() will replace these values,
  315. * after the "initialize" uCode has run, to point to
  316. * runtime/protocol instructions and backup data cache.
  317. */
  318. pinst = il->ucode_init.p_addr >> 4;
  319. pdata = il->ucode_init_data.p_addr >> 4;
  320. inst_len = il->ucode_init.len;
  321. data_len = il->ucode_init_data.len;
  322. il_wr_prph(il, BSM_DRAM_INST_PTR_REG, pinst);
  323. il_wr_prph(il, BSM_DRAM_DATA_PTR_REG, pdata);
  324. il_wr_prph(il, BSM_DRAM_INST_BYTECOUNT_REG, inst_len);
  325. il_wr_prph(il, BSM_DRAM_DATA_BYTECOUNT_REG, data_len);
  326. /* Fill BSM memory with bootstrap instructions */
  327. for (reg_offset = BSM_SRAM_LOWER_BOUND;
  328. reg_offset < BSM_SRAM_LOWER_BOUND + len;
  329. reg_offset += sizeof(u32), image++)
  330. _il_wr_prph(il, reg_offset, le32_to_cpu(*image));
  331. ret = il4965_verify_bsm(il);
  332. if (ret)
  333. return ret;
  334. /* Tell BSM to copy from BSM SRAM into instruction SRAM, when asked */
  335. il_wr_prph(il, BSM_WR_MEM_SRC_REG, 0x0);
  336. il_wr_prph(il, BSM_WR_MEM_DST_REG, IL49_RTC_INST_LOWER_BOUND);
  337. il_wr_prph(il, BSM_WR_DWCOUNT_REG, len / sizeof(u32));
  338. /* Load bootstrap code into instruction SRAM now,
  339. * to prepare to load "initialize" uCode */
  340. il_wr_prph(il, BSM_WR_CTRL_REG, BSM_WR_CTRL_REG_BIT_START);
  341. /* Wait for load of bootstrap uCode to finish */
  342. for (i = 0; i < 100; i++) {
  343. done = il_rd_prph(il, BSM_WR_CTRL_REG);
  344. if (!(done & BSM_WR_CTRL_REG_BIT_START))
  345. break;
  346. udelay(10);
  347. }
  348. if (i < 100)
  349. D_INFO("BSM write complete, poll %d iterations\n", i);
  350. else {
  351. IL_ERR("BSM write did not complete!\n");
  352. return -EIO;
  353. }
  354. /* Enable future boot loads whenever power management unit triggers it
  355. * (e.g. when powering back up after power-save shutdown) */
  356. il_wr_prph(il, BSM_WR_CTRL_REG, BSM_WR_CTRL_REG_BIT_START_EN);
  357. return 0;
  358. }
  359. /**
  360. * il4965_set_ucode_ptrs - Set uCode address location
  361. *
  362. * Tell initialization uCode where to find runtime uCode.
  363. *
  364. * BSM registers initially contain pointers to initialization uCode.
  365. * We need to replace them to load runtime uCode inst and data,
  366. * and to save runtime data when powering down.
  367. */
  368. static int
  369. il4965_set_ucode_ptrs(struct il_priv *il)
  370. {
  371. dma_addr_t pinst;
  372. dma_addr_t pdata;
  373. int ret = 0;
  374. /* bits 35:4 for 4965 */
  375. pinst = il->ucode_code.p_addr >> 4;
  376. pdata = il->ucode_data_backup.p_addr >> 4;
  377. /* Tell bootstrap uCode where to find image to load */
  378. il_wr_prph(il, BSM_DRAM_INST_PTR_REG, pinst);
  379. il_wr_prph(il, BSM_DRAM_DATA_PTR_REG, pdata);
  380. il_wr_prph(il, BSM_DRAM_DATA_BYTECOUNT_REG, il->ucode_data.len);
  381. /* Inst byte count must be last to set up, bit 31 signals uCode
  382. * that all new ptr/size info is in place */
  383. il_wr_prph(il, BSM_DRAM_INST_BYTECOUNT_REG,
  384. il->ucode_code.len | BSM_DRAM_INST_LOAD);
  385. D_INFO("Runtime uCode pointers are set.\n");
  386. return ret;
  387. }
  388. /**
  389. * il4965_init_alive_start - Called after N_ALIVE notification received
  390. *
  391. * Called after N_ALIVE notification received from "initialize" uCode.
  392. *
  393. * The 4965 "initialize" ALIVE reply contains calibration data for:
  394. * Voltage, temperature, and MIMO tx gain correction, now stored in il
  395. * (3945 does not contain this data).
  396. *
  397. * Tell "initialize" uCode to go ahead and load the runtime uCode.
  398. */
  399. static void
  400. il4965_init_alive_start(struct il_priv *il)
  401. {
  402. /* Bootstrap uCode has loaded initialize uCode ... verify inst image.
  403. * This is a paranoid check, because we would not have gotten the
  404. * "initialize" alive if code weren't properly loaded. */
  405. if (il4965_verify_ucode(il)) {
  406. /* Runtime instruction load was bad;
  407. * take it all the way back down so we can try again */
  408. D_INFO("Bad \"initialize\" uCode load.\n");
  409. goto restart;
  410. }
  411. /* Calculate temperature */
  412. il->temperature = il4965_hw_get_temperature(il);
  413. /* Send pointers to protocol/runtime uCode image ... init code will
  414. * load and launch runtime uCode, which will send us another "Alive"
  415. * notification. */
  416. D_INFO("Initialization Alive received.\n");
  417. if (il4965_set_ucode_ptrs(il)) {
  418. /* Runtime instruction load won't happen;
  419. * take it all the way back down so we can try again */
  420. D_INFO("Couldn't set up uCode pointers.\n");
  421. goto restart;
  422. }
  423. return;
  424. restart:
  425. queue_work(il->workqueue, &il->restart);
  426. }
  427. static bool
  428. iw4965_is_ht40_channel(__le32 rxon_flags)
  429. {
  430. int chan_mod =
  431. le32_to_cpu(rxon_flags & RXON_FLG_CHANNEL_MODE_MSK) >>
  432. RXON_FLG_CHANNEL_MODE_POS;
  433. return (chan_mod == CHANNEL_MODE_PURE_40 ||
  434. chan_mod == CHANNEL_MODE_MIXED);
  435. }
  436. void
  437. il4965_nic_config(struct il_priv *il)
  438. {
  439. unsigned long flags;
  440. u16 radio_cfg;
  441. spin_lock_irqsave(&il->lock, flags);
  442. radio_cfg = il_eeprom_query16(il, EEPROM_RADIO_CONFIG);
  443. /* write radio config values to register */
  444. if (EEPROM_RF_CFG_TYPE_MSK(radio_cfg) == EEPROM_4965_RF_CFG_TYPE_MAX)
  445. il_set_bit(il, CSR_HW_IF_CONFIG_REG,
  446. EEPROM_RF_CFG_TYPE_MSK(radio_cfg) |
  447. EEPROM_RF_CFG_STEP_MSK(radio_cfg) |
  448. EEPROM_RF_CFG_DASH_MSK(radio_cfg));
  449. /* set CSR_HW_CONFIG_REG for uCode use */
  450. il_set_bit(il, CSR_HW_IF_CONFIG_REG,
  451. CSR_HW_IF_CONFIG_REG_BIT_RADIO_SI |
  452. CSR_HW_IF_CONFIG_REG_BIT_MAC_SI);
  453. il->calib_info =
  454. (struct il_eeprom_calib_info *)
  455. il_eeprom_query_addr(il, EEPROM_4965_CALIB_TXPOWER_OFFSET);
  456. spin_unlock_irqrestore(&il->lock, flags);
  457. }
  458. /* Reset differential Rx gains in NIC to prepare for chain noise calibration.
  459. * Called after every association, but this runs only once!
  460. * ... once chain noise is calibrated the first time, it's good forever. */
  461. static void
  462. il4965_chain_noise_reset(struct il_priv *il)
  463. {
  464. struct il_chain_noise_data *data = &(il->chain_noise_data);
  465. if (data->state == IL_CHAIN_NOISE_ALIVE && il_is_any_associated(il)) {
  466. struct il_calib_diff_gain_cmd cmd;
  467. /* clear data for chain noise calibration algorithm */
  468. data->chain_noise_a = 0;
  469. data->chain_noise_b = 0;
  470. data->chain_noise_c = 0;
  471. data->chain_signal_a = 0;
  472. data->chain_signal_b = 0;
  473. data->chain_signal_c = 0;
  474. data->beacon_count = 0;
  475. memset(&cmd, 0, sizeof(cmd));
  476. cmd.hdr.op_code = IL_PHY_CALIBRATE_DIFF_GAIN_CMD;
  477. cmd.diff_gain_a = 0;
  478. cmd.diff_gain_b = 0;
  479. cmd.diff_gain_c = 0;
  480. if (il_send_cmd_pdu(il, C_PHY_CALIBRATION, sizeof(cmd), &cmd))
  481. IL_ERR("Could not send C_PHY_CALIBRATION\n");
  482. data->state = IL_CHAIN_NOISE_ACCUMULATE;
  483. D_CALIB("Run chain_noise_calibrate\n");
  484. }
  485. }
  486. static s32
  487. il4965_math_div_round(s32 num, s32 denom, s32 * res)
  488. {
  489. s32 sign = 1;
  490. if (num < 0) {
  491. sign = -sign;
  492. num = -num;
  493. }
  494. if (denom < 0) {
  495. sign = -sign;
  496. denom = -denom;
  497. }
  498. *res = 1;
  499. *res = ((num * 2 + denom) / (denom * 2)) * sign;
  500. return 1;
  501. }
  502. /**
  503. * il4965_get_voltage_compensation - Power supply voltage comp for txpower
  504. *
  505. * Determines power supply voltage compensation for txpower calculations.
  506. * Returns number of 1/2-dB steps to subtract from gain table idx,
  507. * to compensate for difference between power supply voltage during
  508. * factory measurements, vs. current power supply voltage.
  509. *
  510. * Voltage indication is higher for lower voltage.
  511. * Lower voltage requires more gain (lower gain table idx).
  512. */
  513. static s32
  514. il4965_get_voltage_compensation(s32 eeprom_voltage, s32 current_voltage)
  515. {
  516. s32 comp = 0;
  517. if (TX_POWER_IL_ILLEGAL_VOLTAGE == eeprom_voltage ||
  518. TX_POWER_IL_ILLEGAL_VOLTAGE == current_voltage)
  519. return 0;
  520. il4965_math_div_round(current_voltage - eeprom_voltage,
  521. TX_POWER_IL_VOLTAGE_CODES_PER_03V, &comp);
  522. if (current_voltage > eeprom_voltage)
  523. comp *= 2;
  524. if ((comp < -2) || (comp > 2))
  525. comp = 0;
  526. return comp;
  527. }
  528. static s32
  529. il4965_get_tx_atten_grp(u16 channel)
  530. {
  531. if (channel >= CALIB_IL_TX_ATTEN_GR5_FCH &&
  532. channel <= CALIB_IL_TX_ATTEN_GR5_LCH)
  533. return CALIB_CH_GROUP_5;
  534. if (channel >= CALIB_IL_TX_ATTEN_GR1_FCH &&
  535. channel <= CALIB_IL_TX_ATTEN_GR1_LCH)
  536. return CALIB_CH_GROUP_1;
  537. if (channel >= CALIB_IL_TX_ATTEN_GR2_FCH &&
  538. channel <= CALIB_IL_TX_ATTEN_GR2_LCH)
  539. return CALIB_CH_GROUP_2;
  540. if (channel >= CALIB_IL_TX_ATTEN_GR3_FCH &&
  541. channel <= CALIB_IL_TX_ATTEN_GR3_LCH)
  542. return CALIB_CH_GROUP_3;
  543. if (channel >= CALIB_IL_TX_ATTEN_GR4_FCH &&
  544. channel <= CALIB_IL_TX_ATTEN_GR4_LCH)
  545. return CALIB_CH_GROUP_4;
  546. return -EINVAL;
  547. }
  548. static u32
  549. il4965_get_sub_band(const struct il_priv *il, u32 channel)
  550. {
  551. s32 b = -1;
  552. for (b = 0; b < EEPROM_TX_POWER_BANDS; b++) {
  553. if (il->calib_info->band_info[b].ch_from == 0)
  554. continue;
  555. if (channel >= il->calib_info->band_info[b].ch_from &&
  556. channel <= il->calib_info->band_info[b].ch_to)
  557. break;
  558. }
  559. return b;
  560. }
  561. static s32
  562. il4965_interpolate_value(s32 x, s32 x1, s32 y1, s32 x2, s32 y2)
  563. {
  564. s32 val;
  565. if (x2 == x1)
  566. return y1;
  567. else {
  568. il4965_math_div_round((x2 - x) * (y1 - y2), (x2 - x1), &val);
  569. return val + y2;
  570. }
  571. }
  572. /**
  573. * il4965_interpolate_chan - Interpolate factory measurements for one channel
  574. *
  575. * Interpolates factory measurements from the two sample channels within a
  576. * sub-band, to apply to channel of interest. Interpolation is proportional to
  577. * differences in channel frequencies, which is proportional to differences
  578. * in channel number.
  579. */
  580. static int
  581. il4965_interpolate_chan(struct il_priv *il, u32 channel,
  582. struct il_eeprom_calib_ch_info *chan_info)
  583. {
  584. s32 s = -1;
  585. u32 c;
  586. u32 m;
  587. const struct il_eeprom_calib_measure *m1;
  588. const struct il_eeprom_calib_measure *m2;
  589. struct il_eeprom_calib_measure *omeas;
  590. u32 ch_i1;
  591. u32 ch_i2;
  592. s = il4965_get_sub_band(il, channel);
  593. if (s >= EEPROM_TX_POWER_BANDS) {
  594. IL_ERR("Tx Power can not find channel %d\n", channel);
  595. return -1;
  596. }
  597. ch_i1 = il->calib_info->band_info[s].ch1.ch_num;
  598. ch_i2 = il->calib_info->band_info[s].ch2.ch_num;
  599. chan_info->ch_num = (u8) channel;
  600. D_TXPOWER("channel %d subband %d factory cal ch %d & %d\n", channel, s,
  601. ch_i1, ch_i2);
  602. for (c = 0; c < EEPROM_TX_POWER_TX_CHAINS; c++) {
  603. for (m = 0; m < EEPROM_TX_POWER_MEASUREMENTS; m++) {
  604. m1 = &(il->calib_info->band_info[s].ch1.
  605. measurements[c][m]);
  606. m2 = &(il->calib_info->band_info[s].ch2.
  607. measurements[c][m]);
  608. omeas = &(chan_info->measurements[c][m]);
  609. omeas->actual_pow =
  610. (u8) il4965_interpolate_value(channel, ch_i1,
  611. m1->actual_pow, ch_i2,
  612. m2->actual_pow);
  613. omeas->gain_idx =
  614. (u8) il4965_interpolate_value(channel, ch_i1,
  615. m1->gain_idx, ch_i2,
  616. m2->gain_idx);
  617. omeas->temperature =
  618. (u8) il4965_interpolate_value(channel, ch_i1,
  619. m1->temperature,
  620. ch_i2,
  621. m2->temperature);
  622. omeas->pa_det =
  623. (s8) il4965_interpolate_value(channel, ch_i1,
  624. m1->pa_det, ch_i2,
  625. m2->pa_det);
  626. D_TXPOWER("chain %d meas %d AP1=%d AP2=%d AP=%d\n", c,
  627. m, m1->actual_pow, m2->actual_pow,
  628. omeas->actual_pow);
  629. D_TXPOWER("chain %d meas %d NI1=%d NI2=%d NI=%d\n", c,
  630. m, m1->gain_idx, m2->gain_idx,
  631. omeas->gain_idx);
  632. D_TXPOWER("chain %d meas %d PA1=%d PA2=%d PA=%d\n", c,
  633. m, m1->pa_det, m2->pa_det, omeas->pa_det);
  634. D_TXPOWER("chain %d meas %d T1=%d T2=%d T=%d\n", c,
  635. m, m1->temperature, m2->temperature,
  636. omeas->temperature);
  637. }
  638. }
  639. return 0;
  640. }
  641. /* bit-rate-dependent table to prevent Tx distortion, in half-dB units,
  642. * for OFDM 6, 12, 18, 24, 36, 48, 54, 60 MBit, and CCK all rates. */
  643. static s32 back_off_table[] = {
  644. 10, 10, 10, 10, 10, 15, 17, 20, /* OFDM SISO 20 MHz */
  645. 10, 10, 10, 10, 10, 15, 17, 20, /* OFDM MIMO 20 MHz */
  646. 10, 10, 10, 10, 10, 15, 17, 20, /* OFDM SISO 40 MHz */
  647. 10, 10, 10, 10, 10, 15, 17, 20, /* OFDM MIMO 40 MHz */
  648. 10 /* CCK */
  649. };
  650. /* Thermal compensation values for txpower for various frequency ranges ...
  651. * ratios from 3:1 to 4.5:1 of degrees (Celsius) per half-dB gain adjust */
  652. static struct il4965_txpower_comp_entry {
  653. s32 degrees_per_05db_a;
  654. s32 degrees_per_05db_a_denom;
  655. } tx_power_cmp_tble[CALIB_CH_GROUP_MAX] = {
  656. {
  657. 9, 2}, /* group 0 5.2, ch 34-43 */
  658. {
  659. 4, 1}, /* group 1 5.2, ch 44-70 */
  660. {
  661. 4, 1}, /* group 2 5.2, ch 71-124 */
  662. {
  663. 4, 1}, /* group 3 5.2, ch 125-200 */
  664. {
  665. 3, 1} /* group 4 2.4, ch all */
  666. };
  667. static s32
  668. get_min_power_idx(s32 rate_power_idx, u32 band)
  669. {
  670. if (!band) {
  671. if ((rate_power_idx & 7) <= 4)
  672. return MIN_TX_GAIN_IDX_52GHZ_EXT;
  673. }
  674. return MIN_TX_GAIN_IDX;
  675. }
  676. struct gain_entry {
  677. u8 dsp;
  678. u8 radio;
  679. };
  680. static const struct gain_entry gain_table[2][108] = {
  681. /* 5.2GHz power gain idx table */
  682. {
  683. {123, 0x3F}, /* highest txpower */
  684. {117, 0x3F},
  685. {110, 0x3F},
  686. {104, 0x3F},
  687. {98, 0x3F},
  688. {110, 0x3E},
  689. {104, 0x3E},
  690. {98, 0x3E},
  691. {110, 0x3D},
  692. {104, 0x3D},
  693. {98, 0x3D},
  694. {110, 0x3C},
  695. {104, 0x3C},
  696. {98, 0x3C},
  697. {110, 0x3B},
  698. {104, 0x3B},
  699. {98, 0x3B},
  700. {110, 0x3A},
  701. {104, 0x3A},
  702. {98, 0x3A},
  703. {110, 0x39},
  704. {104, 0x39},
  705. {98, 0x39},
  706. {110, 0x38},
  707. {104, 0x38},
  708. {98, 0x38},
  709. {110, 0x37},
  710. {104, 0x37},
  711. {98, 0x37},
  712. {110, 0x36},
  713. {104, 0x36},
  714. {98, 0x36},
  715. {110, 0x35},
  716. {104, 0x35},
  717. {98, 0x35},
  718. {110, 0x34},
  719. {104, 0x34},
  720. {98, 0x34},
  721. {110, 0x33},
  722. {104, 0x33},
  723. {98, 0x33},
  724. {110, 0x32},
  725. {104, 0x32},
  726. {98, 0x32},
  727. {110, 0x31},
  728. {104, 0x31},
  729. {98, 0x31},
  730. {110, 0x30},
  731. {104, 0x30},
  732. {98, 0x30},
  733. {110, 0x25},
  734. {104, 0x25},
  735. {98, 0x25},
  736. {110, 0x24},
  737. {104, 0x24},
  738. {98, 0x24},
  739. {110, 0x23},
  740. {104, 0x23},
  741. {98, 0x23},
  742. {110, 0x22},
  743. {104, 0x18},
  744. {98, 0x18},
  745. {110, 0x17},
  746. {104, 0x17},
  747. {98, 0x17},
  748. {110, 0x16},
  749. {104, 0x16},
  750. {98, 0x16},
  751. {110, 0x15},
  752. {104, 0x15},
  753. {98, 0x15},
  754. {110, 0x14},
  755. {104, 0x14},
  756. {98, 0x14},
  757. {110, 0x13},
  758. {104, 0x13},
  759. {98, 0x13},
  760. {110, 0x12},
  761. {104, 0x08},
  762. {98, 0x08},
  763. {110, 0x07},
  764. {104, 0x07},
  765. {98, 0x07},
  766. {110, 0x06},
  767. {104, 0x06},
  768. {98, 0x06},
  769. {110, 0x05},
  770. {104, 0x05},
  771. {98, 0x05},
  772. {110, 0x04},
  773. {104, 0x04},
  774. {98, 0x04},
  775. {110, 0x03},
  776. {104, 0x03},
  777. {98, 0x03},
  778. {110, 0x02},
  779. {104, 0x02},
  780. {98, 0x02},
  781. {110, 0x01},
  782. {104, 0x01},
  783. {98, 0x01},
  784. {110, 0x00},
  785. {104, 0x00},
  786. {98, 0x00},
  787. {93, 0x00},
  788. {88, 0x00},
  789. {83, 0x00},
  790. {78, 0x00},
  791. },
  792. /* 2.4GHz power gain idx table */
  793. {
  794. {110, 0x3f}, /* highest txpower */
  795. {104, 0x3f},
  796. {98, 0x3f},
  797. {110, 0x3e},
  798. {104, 0x3e},
  799. {98, 0x3e},
  800. {110, 0x3d},
  801. {104, 0x3d},
  802. {98, 0x3d},
  803. {110, 0x3c},
  804. {104, 0x3c},
  805. {98, 0x3c},
  806. {110, 0x3b},
  807. {104, 0x3b},
  808. {98, 0x3b},
  809. {110, 0x3a},
  810. {104, 0x3a},
  811. {98, 0x3a},
  812. {110, 0x39},
  813. {104, 0x39},
  814. {98, 0x39},
  815. {110, 0x38},
  816. {104, 0x38},
  817. {98, 0x38},
  818. {110, 0x37},
  819. {104, 0x37},
  820. {98, 0x37},
  821. {110, 0x36},
  822. {104, 0x36},
  823. {98, 0x36},
  824. {110, 0x35},
  825. {104, 0x35},
  826. {98, 0x35},
  827. {110, 0x34},
  828. {104, 0x34},
  829. {98, 0x34},
  830. {110, 0x33},
  831. {104, 0x33},
  832. {98, 0x33},
  833. {110, 0x32},
  834. {104, 0x32},
  835. {98, 0x32},
  836. {110, 0x31},
  837. {104, 0x31},
  838. {98, 0x31},
  839. {110, 0x30},
  840. {104, 0x30},
  841. {98, 0x30},
  842. {110, 0x6},
  843. {104, 0x6},
  844. {98, 0x6},
  845. {110, 0x5},
  846. {104, 0x5},
  847. {98, 0x5},
  848. {110, 0x4},
  849. {104, 0x4},
  850. {98, 0x4},
  851. {110, 0x3},
  852. {104, 0x3},
  853. {98, 0x3},
  854. {110, 0x2},
  855. {104, 0x2},
  856. {98, 0x2},
  857. {110, 0x1},
  858. {104, 0x1},
  859. {98, 0x1},
  860. {110, 0x0},
  861. {104, 0x0},
  862. {98, 0x0},
  863. {97, 0},
  864. {96, 0},
  865. {95, 0},
  866. {94, 0},
  867. {93, 0},
  868. {92, 0},
  869. {91, 0},
  870. {90, 0},
  871. {89, 0},
  872. {88, 0},
  873. {87, 0},
  874. {86, 0},
  875. {85, 0},
  876. {84, 0},
  877. {83, 0},
  878. {82, 0},
  879. {81, 0},
  880. {80, 0},
  881. {79, 0},
  882. {78, 0},
  883. {77, 0},
  884. {76, 0},
  885. {75, 0},
  886. {74, 0},
  887. {73, 0},
  888. {72, 0},
  889. {71, 0},
  890. {70, 0},
  891. {69, 0},
  892. {68, 0},
  893. {67, 0},
  894. {66, 0},
  895. {65, 0},
  896. {64, 0},
  897. {63, 0},
  898. {62, 0},
  899. {61, 0},
  900. {60, 0},
  901. {59, 0},
  902. }
  903. };
  904. static int
  905. il4965_fill_txpower_tbl(struct il_priv *il, u8 band, u16 channel, u8 is_ht40,
  906. u8 ctrl_chan_high,
  907. struct il4965_tx_power_db *tx_power_tbl)
  908. {
  909. u8 saturation_power;
  910. s32 target_power;
  911. s32 user_target_power;
  912. s32 power_limit;
  913. s32 current_temp;
  914. s32 reg_limit;
  915. s32 current_regulatory;
  916. s32 txatten_grp = CALIB_CH_GROUP_MAX;
  917. int i;
  918. int c;
  919. const struct il_channel_info *ch_info = NULL;
  920. struct il_eeprom_calib_ch_info ch_eeprom_info;
  921. const struct il_eeprom_calib_measure *measurement;
  922. s16 voltage;
  923. s32 init_voltage;
  924. s32 voltage_compensation;
  925. s32 degrees_per_05db_num;
  926. s32 degrees_per_05db_denom;
  927. s32 factory_temp;
  928. s32 temperature_comp[2];
  929. s32 factory_gain_idx[2];
  930. s32 factory_actual_pwr[2];
  931. s32 power_idx;
  932. /* tx_power_user_lmt is in dBm, convert to half-dBm (half-dB units
  933. * are used for idxing into txpower table) */
  934. user_target_power = 2 * il->tx_power_user_lmt;
  935. /* Get current (RXON) channel, band, width */
  936. D_TXPOWER("chan %d band %d is_ht40 %d\n", channel, band, is_ht40);
  937. ch_info = il_get_channel_info(il, il->band, channel);
  938. if (!il_is_channel_valid(ch_info))
  939. return -EINVAL;
  940. /* get txatten group, used to select 1) thermal txpower adjustment
  941. * and 2) mimo txpower balance between Tx chains. */
  942. txatten_grp = il4965_get_tx_atten_grp(channel);
  943. if (txatten_grp < 0) {
  944. IL_ERR("Can't find txatten group for channel %d.\n", channel);
  945. return txatten_grp;
  946. }
  947. D_TXPOWER("channel %d belongs to txatten group %d\n", channel,
  948. txatten_grp);
  949. if (is_ht40) {
  950. if (ctrl_chan_high)
  951. channel -= 2;
  952. else
  953. channel += 2;
  954. }
  955. /* hardware txpower limits ...
  956. * saturation (clipping distortion) txpowers are in half-dBm */
  957. if (band)
  958. saturation_power = il->calib_info->saturation_power24;
  959. else
  960. saturation_power = il->calib_info->saturation_power52;
  961. if (saturation_power < IL_TX_POWER_SATURATION_MIN ||
  962. saturation_power > IL_TX_POWER_SATURATION_MAX) {
  963. if (band)
  964. saturation_power = IL_TX_POWER_DEFAULT_SATURATION_24;
  965. else
  966. saturation_power = IL_TX_POWER_DEFAULT_SATURATION_52;
  967. }
  968. /* regulatory txpower limits ... reg_limit values are in half-dBm,
  969. * max_power_avg values are in dBm, convert * 2 */
  970. if (is_ht40)
  971. reg_limit = ch_info->ht40_max_power_avg * 2;
  972. else
  973. reg_limit = ch_info->max_power_avg * 2;
  974. if ((reg_limit < IL_TX_POWER_REGULATORY_MIN) ||
  975. (reg_limit > IL_TX_POWER_REGULATORY_MAX)) {
  976. if (band)
  977. reg_limit = IL_TX_POWER_DEFAULT_REGULATORY_24;
  978. else
  979. reg_limit = IL_TX_POWER_DEFAULT_REGULATORY_52;
  980. }
  981. /* Interpolate txpower calibration values for this channel,
  982. * based on factory calibration tests on spaced channels. */
  983. il4965_interpolate_chan(il, channel, &ch_eeprom_info);
  984. /* calculate tx gain adjustment based on power supply voltage */
  985. voltage = le16_to_cpu(il->calib_info->voltage);
  986. init_voltage = (s32) le32_to_cpu(il->card_alive_init.voltage);
  987. voltage_compensation =
  988. il4965_get_voltage_compensation(voltage, init_voltage);
  989. D_TXPOWER("curr volt %d eeprom volt %d volt comp %d\n", init_voltage,
  990. voltage, voltage_compensation);
  991. /* get current temperature (Celsius) */
  992. current_temp = max(il->temperature, IL_TX_POWER_TEMPERATURE_MIN);
  993. current_temp = min(il->temperature, IL_TX_POWER_TEMPERATURE_MAX);
  994. current_temp = KELVIN_TO_CELSIUS(current_temp);
  995. /* select thermal txpower adjustment params, based on channel group
  996. * (same frequency group used for mimo txatten adjustment) */
  997. degrees_per_05db_num =
  998. tx_power_cmp_tble[txatten_grp].degrees_per_05db_a;
  999. degrees_per_05db_denom =
  1000. tx_power_cmp_tble[txatten_grp].degrees_per_05db_a_denom;
  1001. /* get per-chain txpower values from factory measurements */
  1002. for (c = 0; c < 2; c++) {
  1003. measurement = &ch_eeprom_info.measurements[c][1];
  1004. /* txgain adjustment (in half-dB steps) based on difference
  1005. * between factory and current temperature */
  1006. factory_temp = measurement->temperature;
  1007. il4965_math_div_round((current_temp -
  1008. factory_temp) * degrees_per_05db_denom,
  1009. degrees_per_05db_num,
  1010. &temperature_comp[c]);
  1011. factory_gain_idx[c] = measurement->gain_idx;
  1012. factory_actual_pwr[c] = measurement->actual_pow;
  1013. D_TXPOWER("chain = %d\n", c);
  1014. D_TXPOWER("fctry tmp %d, " "curr tmp %d, comp %d steps\n",
  1015. factory_temp, current_temp, temperature_comp[c]);
  1016. D_TXPOWER("fctry idx %d, fctry pwr %d\n", factory_gain_idx[c],
  1017. factory_actual_pwr[c]);
  1018. }
  1019. /* for each of 33 bit-rates (including 1 for CCK) */
  1020. for (i = 0; i < POWER_TBL_NUM_ENTRIES; i++) {
  1021. u8 is_mimo_rate;
  1022. union il4965_tx_power_dual_stream tx_power;
  1023. /* for mimo, reduce each chain's txpower by half
  1024. * (3dB, 6 steps), so total output power is regulatory
  1025. * compliant. */
  1026. if (i & 0x8) {
  1027. current_regulatory =
  1028. reg_limit -
  1029. IL_TX_POWER_MIMO_REGULATORY_COMPENSATION;
  1030. is_mimo_rate = 1;
  1031. } else {
  1032. current_regulatory = reg_limit;
  1033. is_mimo_rate = 0;
  1034. }
  1035. /* find txpower limit, either hardware or regulatory */
  1036. power_limit = saturation_power - back_off_table[i];
  1037. if (power_limit > current_regulatory)
  1038. power_limit = current_regulatory;
  1039. /* reduce user's txpower request if necessary
  1040. * for this rate on this channel */
  1041. target_power = user_target_power;
  1042. if (target_power > power_limit)
  1043. target_power = power_limit;
  1044. D_TXPOWER("rate %d sat %d reg %d usr %d tgt %d\n", i,
  1045. saturation_power - back_off_table[i],
  1046. current_regulatory, user_target_power, target_power);
  1047. /* for each of 2 Tx chains (radio transmitters) */
  1048. for (c = 0; c < 2; c++) {
  1049. s32 atten_value;
  1050. if (is_mimo_rate)
  1051. atten_value =
  1052. (s32) le32_to_cpu(il->card_alive_init.
  1053. tx_atten[txatten_grp][c]);
  1054. else
  1055. atten_value = 0;
  1056. /* calculate idx; higher idx means lower txpower */
  1057. power_idx =
  1058. (u8) (factory_gain_idx[c] -
  1059. (target_power - factory_actual_pwr[c]) -
  1060. temperature_comp[c] - voltage_compensation +
  1061. atten_value);
  1062. /* D_TXPOWER("calculated txpower idx %d\n",
  1063. power_idx); */
  1064. if (power_idx < get_min_power_idx(i, band))
  1065. power_idx = get_min_power_idx(i, band);
  1066. /* adjust 5 GHz idx to support negative idxes */
  1067. if (!band)
  1068. power_idx += 9;
  1069. /* CCK, rate 32, reduce txpower for CCK */
  1070. if (i == POWER_TBL_CCK_ENTRY)
  1071. power_idx +=
  1072. IL_TX_POWER_CCK_COMPENSATION_C_STEP;
  1073. /* stay within the table! */
  1074. if (power_idx > 107) {
  1075. IL_WARN("txpower idx %d > 107\n", power_idx);
  1076. power_idx = 107;
  1077. }
  1078. if (power_idx < 0) {
  1079. IL_WARN("txpower idx %d < 0\n", power_idx);
  1080. power_idx = 0;
  1081. }
  1082. /* fill txpower command for this rate/chain */
  1083. tx_power.s.radio_tx_gain[c] =
  1084. gain_table[band][power_idx].radio;
  1085. tx_power.s.dsp_predis_atten[c] =
  1086. gain_table[band][power_idx].dsp;
  1087. D_TXPOWER("chain %d mimo %d idx %d "
  1088. "gain 0x%02x dsp %d\n", c, atten_value,
  1089. power_idx, tx_power.s.radio_tx_gain[c],
  1090. tx_power.s.dsp_predis_atten[c]);
  1091. } /* for each chain */
  1092. tx_power_tbl->power_tbl[i].dw = cpu_to_le32(tx_power.dw);
  1093. } /* for each rate */
  1094. return 0;
  1095. }
  1096. /**
  1097. * il4965_send_tx_power - Configure the TXPOWER level user limit
  1098. *
  1099. * Uses the active RXON for channel, band, and characteristics (ht40, high)
  1100. * The power limit is taken from il->tx_power_user_lmt.
  1101. */
  1102. static int
  1103. il4965_send_tx_power(struct il_priv *il)
  1104. {
  1105. struct il4965_txpowertable_cmd cmd = { 0 };
  1106. int ret;
  1107. u8 band = 0;
  1108. bool is_ht40 = false;
  1109. u8 ctrl_chan_high = 0;
  1110. if (WARN_ONCE
  1111. (test_bit(S_SCAN_HW, &il->status),
  1112. "TX Power requested while scanning!\n"))
  1113. return -EAGAIN;
  1114. band = il->band == IEEE80211_BAND_2GHZ;
  1115. is_ht40 = iw4965_is_ht40_channel(il->active.flags);
  1116. if (is_ht40 && (il->active.flags & RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK))
  1117. ctrl_chan_high = 1;
  1118. cmd.band = band;
  1119. cmd.channel = il->active.channel;
  1120. ret =
  1121. il4965_fill_txpower_tbl(il, band, le16_to_cpu(il->active.channel),
  1122. is_ht40, ctrl_chan_high, &cmd.tx_power);
  1123. if (ret)
  1124. goto out;
  1125. ret = il_send_cmd_pdu(il, C_TX_PWR_TBL, sizeof(cmd), &cmd);
  1126. out:
  1127. return ret;
  1128. }
  1129. static int
  1130. il4965_send_rxon_assoc(struct il_priv *il)
  1131. {
  1132. int ret = 0;
  1133. struct il4965_rxon_assoc_cmd rxon_assoc;
  1134. const struct il_rxon_cmd *rxon1 = &il->staging;
  1135. const struct il_rxon_cmd *rxon2 = &il->active;
  1136. if (rxon1->flags == rxon2->flags &&
  1137. rxon1->filter_flags == rxon2->filter_flags &&
  1138. rxon1->cck_basic_rates == rxon2->cck_basic_rates &&
  1139. rxon1->ofdm_ht_single_stream_basic_rates ==
  1140. rxon2->ofdm_ht_single_stream_basic_rates &&
  1141. rxon1->ofdm_ht_dual_stream_basic_rates ==
  1142. rxon2->ofdm_ht_dual_stream_basic_rates &&
  1143. rxon1->rx_chain == rxon2->rx_chain &&
  1144. rxon1->ofdm_basic_rates == rxon2->ofdm_basic_rates) {
  1145. D_INFO("Using current RXON_ASSOC. Not resending.\n");
  1146. return 0;
  1147. }
  1148. rxon_assoc.flags = il->staging.flags;
  1149. rxon_assoc.filter_flags = il->staging.filter_flags;
  1150. rxon_assoc.ofdm_basic_rates = il->staging.ofdm_basic_rates;
  1151. rxon_assoc.cck_basic_rates = il->staging.cck_basic_rates;
  1152. rxon_assoc.reserved = 0;
  1153. rxon_assoc.ofdm_ht_single_stream_basic_rates =
  1154. il->staging.ofdm_ht_single_stream_basic_rates;
  1155. rxon_assoc.ofdm_ht_dual_stream_basic_rates =
  1156. il->staging.ofdm_ht_dual_stream_basic_rates;
  1157. rxon_assoc.rx_chain_select_flags = il->staging.rx_chain;
  1158. ret =
  1159. il_send_cmd_pdu_async(il, C_RXON_ASSOC, sizeof(rxon_assoc),
  1160. &rxon_assoc, NULL);
  1161. return ret;
  1162. }
  1163. static int
  1164. il4965_commit_rxon(struct il_priv *il)
  1165. {
  1166. /* cast away the const for active_rxon in this function */
  1167. struct il_rxon_cmd *active_rxon = (void *)&il->active;
  1168. int ret;
  1169. bool new_assoc = !!(il->staging.filter_flags & RXON_FILTER_ASSOC_MSK);
  1170. if (!il_is_alive(il))
  1171. return -EBUSY;
  1172. /* always get timestamp with Rx frame */
  1173. il->staging.flags |= RXON_FLG_TSF2HOST_MSK;
  1174. ret = il_check_rxon_cmd(il);
  1175. if (ret) {
  1176. IL_ERR("Invalid RXON configuration. Not committing.\n");
  1177. return -EINVAL;
  1178. }
  1179. /*
  1180. * receive commit_rxon request
  1181. * abort any previous channel switch if still in process
  1182. */
  1183. if (test_bit(S_CHANNEL_SWITCH_PENDING, &il->status) &&
  1184. il->switch_channel != il->staging.channel) {
  1185. D_11H("abort channel switch on %d\n",
  1186. le16_to_cpu(il->switch_channel));
  1187. il_chswitch_done(il, false);
  1188. }
  1189. /* If we don't need to send a full RXON, we can use
  1190. * il_rxon_assoc_cmd which is used to reconfigure filter
  1191. * and other flags for the current radio configuration. */
  1192. if (!il_full_rxon_required(il)) {
  1193. ret = il_send_rxon_assoc(il);
  1194. if (ret) {
  1195. IL_ERR("Error setting RXON_ASSOC (%d)\n", ret);
  1196. return ret;
  1197. }
  1198. memcpy(active_rxon, &il->staging, sizeof(*active_rxon));
  1199. il_print_rx_config_cmd(il);
  1200. /*
  1201. * We do not commit tx power settings while channel changing,
  1202. * do it now if tx power changed.
  1203. */
  1204. il_set_tx_power(il, il->tx_power_next, false);
  1205. return 0;
  1206. }
  1207. /* If we are currently associated and the new config requires
  1208. * an RXON_ASSOC and the new config wants the associated mask enabled,
  1209. * we must clear the associated from the active configuration
  1210. * before we apply the new config */
  1211. if (il_is_associated(il) && new_assoc) {
  1212. D_INFO("Toggling associated bit on current RXON\n");
  1213. active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  1214. ret =
  1215. il_send_cmd_pdu(il, C_RXON,
  1216. sizeof(struct il_rxon_cmd), active_rxon);
  1217. /* If the mask clearing failed then we set
  1218. * active_rxon back to what it was previously */
  1219. if (ret) {
  1220. active_rxon->filter_flags |= RXON_FILTER_ASSOC_MSK;
  1221. IL_ERR("Error clearing ASSOC_MSK (%d)\n", ret);
  1222. return ret;
  1223. }
  1224. il_clear_ucode_stations(il);
  1225. il_restore_stations(il);
  1226. ret = il4965_restore_default_wep_keys(il);
  1227. if (ret) {
  1228. IL_ERR("Failed to restore WEP keys (%d)\n", ret);
  1229. return ret;
  1230. }
  1231. }
  1232. D_INFO("Sending RXON\n" "* with%s RXON_FILTER_ASSOC_MSK\n"
  1233. "* channel = %d\n" "* bssid = %pM\n", (new_assoc ? "" : "out"),
  1234. le16_to_cpu(il->staging.channel), il->staging.bssid_addr);
  1235. il_set_rxon_hwcrypto(il, !il->cfg->mod_params->sw_crypto);
  1236. /* Apply the new configuration
  1237. * RXON unassoc clears the station table in uCode so restoration of
  1238. * stations is needed after it (the RXON command) completes
  1239. */
  1240. if (!new_assoc) {
  1241. ret =
  1242. il_send_cmd_pdu(il, C_RXON,
  1243. sizeof(struct il_rxon_cmd), &il->staging);
  1244. if (ret) {
  1245. IL_ERR("Error setting new RXON (%d)\n", ret);
  1246. return ret;
  1247. }
  1248. D_INFO("Return from !new_assoc RXON.\n");
  1249. memcpy(active_rxon, &il->staging, sizeof(*active_rxon));
  1250. il_clear_ucode_stations(il);
  1251. il_restore_stations(il);
  1252. ret = il4965_restore_default_wep_keys(il);
  1253. if (ret) {
  1254. IL_ERR("Failed to restore WEP keys (%d)\n", ret);
  1255. return ret;
  1256. }
  1257. }
  1258. if (new_assoc) {
  1259. il->start_calib = 0;
  1260. /* Apply the new configuration
  1261. * RXON assoc doesn't clear the station table in uCode,
  1262. */
  1263. ret =
  1264. il_send_cmd_pdu(il, C_RXON,
  1265. sizeof(struct il_rxon_cmd), &il->staging);
  1266. if (ret) {
  1267. IL_ERR("Error setting new RXON (%d)\n", ret);
  1268. return ret;
  1269. }
  1270. memcpy(active_rxon, &il->staging, sizeof(*active_rxon));
  1271. }
  1272. il_print_rx_config_cmd(il);
  1273. il4965_init_sensitivity(il);
  1274. /* If we issue a new RXON command which required a tune then we must
  1275. * send a new TXPOWER command or we won't be able to Tx any frames */
  1276. ret = il_set_tx_power(il, il->tx_power_next, true);
  1277. if (ret) {
  1278. IL_ERR("Error sending TX power (%d)\n", ret);
  1279. return ret;
  1280. }
  1281. return 0;
  1282. }
  1283. static int
  1284. il4965_hw_channel_switch(struct il_priv *il,
  1285. struct ieee80211_channel_switch *ch_switch)
  1286. {
  1287. int rc;
  1288. u8 band = 0;
  1289. bool is_ht40 = false;
  1290. u8 ctrl_chan_high = 0;
  1291. struct il4965_channel_switch_cmd cmd;
  1292. const struct il_channel_info *ch_info;
  1293. u32 switch_time_in_usec, ucode_switch_time;
  1294. u16 ch;
  1295. u32 tsf_low;
  1296. u8 switch_count;
  1297. u16 beacon_interval = le16_to_cpu(il->timing.beacon_interval);
  1298. struct ieee80211_vif *vif = il->vif;
  1299. band = (il->band == IEEE80211_BAND_2GHZ);
  1300. if (WARN_ON_ONCE(vif == NULL))
  1301. return -EIO;
  1302. is_ht40 = iw4965_is_ht40_channel(il->staging.flags);
  1303. if (is_ht40 && (il->staging.flags & RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK))
  1304. ctrl_chan_high = 1;
  1305. cmd.band = band;
  1306. cmd.expect_beacon = 0;
  1307. ch = ch_switch->chandef.chan->hw_value;
  1308. cmd.channel = cpu_to_le16(ch);
  1309. cmd.rxon_flags = il->staging.flags;
  1310. cmd.rxon_filter_flags = il->staging.filter_flags;
  1311. switch_count = ch_switch->count;
  1312. tsf_low = ch_switch->timestamp & 0x0ffffffff;
  1313. /*
  1314. * calculate the ucode channel switch time
  1315. * adding TSF as one of the factor for when to switch
  1316. */
  1317. if (il->ucode_beacon_time > tsf_low && beacon_interval) {
  1318. if (switch_count >
  1319. ((il->ucode_beacon_time - tsf_low) / beacon_interval)) {
  1320. switch_count -=
  1321. (il->ucode_beacon_time - tsf_low) / beacon_interval;
  1322. } else
  1323. switch_count = 0;
  1324. }
  1325. if (switch_count <= 1)
  1326. cmd.switch_time = cpu_to_le32(il->ucode_beacon_time);
  1327. else {
  1328. switch_time_in_usec =
  1329. vif->bss_conf.beacon_int * switch_count * TIME_UNIT;
  1330. ucode_switch_time =
  1331. il_usecs_to_beacons(il, switch_time_in_usec,
  1332. beacon_interval);
  1333. cmd.switch_time =
  1334. il_add_beacon_time(il, il->ucode_beacon_time,
  1335. ucode_switch_time, beacon_interval);
  1336. }
  1337. D_11H("uCode time for the switch is 0x%x\n", cmd.switch_time);
  1338. ch_info = il_get_channel_info(il, il->band, ch);
  1339. if (ch_info)
  1340. cmd.expect_beacon = il_is_channel_radar(ch_info);
  1341. else {
  1342. IL_ERR("invalid channel switch from %u to %u\n",
  1343. il->active.channel, ch);
  1344. return -EFAULT;
  1345. }
  1346. rc = il4965_fill_txpower_tbl(il, band, ch, is_ht40, ctrl_chan_high,
  1347. &cmd.tx_power);
  1348. if (rc) {
  1349. D_11H("error:%d fill txpower_tbl\n", rc);
  1350. return rc;
  1351. }
  1352. return il_send_cmd_pdu(il, C_CHANNEL_SWITCH, sizeof(cmd), &cmd);
  1353. }
  1354. /**
  1355. * il4965_txq_update_byte_cnt_tbl - Set up entry in Tx byte-count array
  1356. */
  1357. static void
  1358. il4965_txq_update_byte_cnt_tbl(struct il_priv *il, struct il_tx_queue *txq,
  1359. u16 byte_cnt)
  1360. {
  1361. struct il4965_scd_bc_tbl *scd_bc_tbl = il->scd_bc_tbls.addr;
  1362. int txq_id = txq->q.id;
  1363. int write_ptr = txq->q.write_ptr;
  1364. int len = byte_cnt + IL_TX_CRC_SIZE + IL_TX_DELIMITER_SIZE;
  1365. __le16 bc_ent;
  1366. WARN_ON(len > 0xFFF || write_ptr >= TFD_QUEUE_SIZE_MAX);
  1367. bc_ent = cpu_to_le16(len & 0xFFF);
  1368. /* Set up byte count within first 256 entries */
  1369. scd_bc_tbl[txq_id].tfd_offset[write_ptr] = bc_ent;
  1370. /* If within first 64 entries, duplicate at end */
  1371. if (write_ptr < TFD_QUEUE_SIZE_BC_DUP)
  1372. scd_bc_tbl[txq_id].tfd_offset[TFD_QUEUE_SIZE_MAX + write_ptr] =
  1373. bc_ent;
  1374. }
  1375. /**
  1376. * il4965_hw_get_temperature - return the calibrated temperature (in Kelvin)
  1377. * @stats: Provides the temperature reading from the uCode
  1378. *
  1379. * A return of <0 indicates bogus data in the stats
  1380. */
  1381. static int
  1382. il4965_hw_get_temperature(struct il_priv *il)
  1383. {
  1384. s32 temperature;
  1385. s32 vt;
  1386. s32 R1, R2, R3;
  1387. u32 R4;
  1388. if (test_bit(S_TEMPERATURE, &il->status) &&
  1389. (il->_4965.stats.flag & STATS_REPLY_FLG_HT40_MODE_MSK)) {
  1390. D_TEMP("Running HT40 temperature calibration\n");
  1391. R1 = (s32) le32_to_cpu(il->card_alive_init.therm_r1[1]);
  1392. R2 = (s32) le32_to_cpu(il->card_alive_init.therm_r2[1]);
  1393. R3 = (s32) le32_to_cpu(il->card_alive_init.therm_r3[1]);
  1394. R4 = le32_to_cpu(il->card_alive_init.therm_r4[1]);
  1395. } else {
  1396. D_TEMP("Running temperature calibration\n");
  1397. R1 = (s32) le32_to_cpu(il->card_alive_init.therm_r1[0]);
  1398. R2 = (s32) le32_to_cpu(il->card_alive_init.therm_r2[0]);
  1399. R3 = (s32) le32_to_cpu(il->card_alive_init.therm_r3[0]);
  1400. R4 = le32_to_cpu(il->card_alive_init.therm_r4[0]);
  1401. }
  1402. /*
  1403. * Temperature is only 23 bits, so sign extend out to 32.
  1404. *
  1405. * NOTE If we haven't received a stats notification yet
  1406. * with an updated temperature, use R4 provided to us in the
  1407. * "initialize" ALIVE response.
  1408. */
  1409. if (!test_bit(S_TEMPERATURE, &il->status))
  1410. vt = sign_extend32(R4, 23);
  1411. else
  1412. vt = sign_extend32(le32_to_cpu
  1413. (il->_4965.stats.general.common.temperature),
  1414. 23);
  1415. D_TEMP("Calib values R[1-3]: %d %d %d R4: %d\n", R1, R2, R3, vt);
  1416. if (R3 == R1) {
  1417. IL_ERR("Calibration conflict R1 == R3\n");
  1418. return -1;
  1419. }
  1420. /* Calculate temperature in degrees Kelvin, adjust by 97%.
  1421. * Add offset to center the adjustment around 0 degrees Centigrade. */
  1422. temperature = TEMPERATURE_CALIB_A_VAL * (vt - R2);
  1423. temperature /= (R3 - R1);
  1424. temperature =
  1425. (temperature * 97) / 100 + TEMPERATURE_CALIB_KELVIN_OFFSET;
  1426. D_TEMP("Calibrated temperature: %dK, %dC\n", temperature,
  1427. KELVIN_TO_CELSIUS(temperature));
  1428. return temperature;
  1429. }
  1430. /* Adjust Txpower only if temperature variance is greater than threshold. */
  1431. #define IL_TEMPERATURE_THRESHOLD 3
  1432. /**
  1433. * il4965_is_temp_calib_needed - determines if new calibration is needed
  1434. *
  1435. * If the temperature changed has changed sufficiently, then a recalibration
  1436. * is needed.
  1437. *
  1438. * Assumes caller will replace il->last_temperature once calibration
  1439. * executed.
  1440. */
  1441. static int
  1442. il4965_is_temp_calib_needed(struct il_priv *il)
  1443. {
  1444. int temp_diff;
  1445. if (!test_bit(S_STATS, &il->status)) {
  1446. D_TEMP("Temperature not updated -- no stats.\n");
  1447. return 0;
  1448. }
  1449. temp_diff = il->temperature - il->last_temperature;
  1450. /* get absolute value */
  1451. if (temp_diff < 0) {
  1452. D_POWER("Getting cooler, delta %d\n", temp_diff);
  1453. temp_diff = -temp_diff;
  1454. } else if (temp_diff == 0)
  1455. D_POWER("Temperature unchanged\n");
  1456. else
  1457. D_POWER("Getting warmer, delta %d\n", temp_diff);
  1458. if (temp_diff < IL_TEMPERATURE_THRESHOLD) {
  1459. D_POWER(" => thermal txpower calib not needed\n");
  1460. return 0;
  1461. }
  1462. D_POWER(" => thermal txpower calib needed\n");
  1463. return 1;
  1464. }
  1465. void
  1466. il4965_temperature_calib(struct il_priv *il)
  1467. {
  1468. s32 temp;
  1469. temp = il4965_hw_get_temperature(il);
  1470. if (IL_TX_POWER_TEMPERATURE_OUT_OF_RANGE(temp))
  1471. return;
  1472. if (il->temperature != temp) {
  1473. if (il->temperature)
  1474. D_TEMP("Temperature changed " "from %dC to %dC\n",
  1475. KELVIN_TO_CELSIUS(il->temperature),
  1476. KELVIN_TO_CELSIUS(temp));
  1477. else
  1478. D_TEMP("Temperature " "initialized to %dC\n",
  1479. KELVIN_TO_CELSIUS(temp));
  1480. }
  1481. il->temperature = temp;
  1482. set_bit(S_TEMPERATURE, &il->status);
  1483. if (!il->disable_tx_power_cal &&
  1484. unlikely(!test_bit(S_SCANNING, &il->status)) &&
  1485. il4965_is_temp_calib_needed(il))
  1486. queue_work(il->workqueue, &il->txpower_work);
  1487. }
  1488. static u16
  1489. il4965_get_hcmd_size(u8 cmd_id, u16 len)
  1490. {
  1491. switch (cmd_id) {
  1492. case C_RXON:
  1493. return (u16) sizeof(struct il4965_rxon_cmd);
  1494. default:
  1495. return len;
  1496. }
  1497. }
  1498. static u16
  1499. il4965_build_addsta_hcmd(const struct il_addsta_cmd *cmd, u8 * data)
  1500. {
  1501. struct il4965_addsta_cmd *addsta = (struct il4965_addsta_cmd *)data;
  1502. addsta->mode = cmd->mode;
  1503. memcpy(&addsta->sta, &cmd->sta, sizeof(struct sta_id_modify));
  1504. memcpy(&addsta->key, &cmd->key, sizeof(struct il4965_keyinfo));
  1505. addsta->station_flags = cmd->station_flags;
  1506. addsta->station_flags_msk = cmd->station_flags_msk;
  1507. addsta->tid_disable_tx = cmd->tid_disable_tx;
  1508. addsta->add_immediate_ba_tid = cmd->add_immediate_ba_tid;
  1509. addsta->remove_immediate_ba_tid = cmd->remove_immediate_ba_tid;
  1510. addsta->add_immediate_ba_ssn = cmd->add_immediate_ba_ssn;
  1511. addsta->sleep_tx_count = cmd->sleep_tx_count;
  1512. addsta->reserved1 = cpu_to_le16(0);
  1513. addsta->reserved2 = cpu_to_le16(0);
  1514. return (u16) sizeof(struct il4965_addsta_cmd);
  1515. }
  1516. static void
  1517. il4965_post_scan(struct il_priv *il)
  1518. {
  1519. /*
  1520. * Since setting the RXON may have been deferred while
  1521. * performing the scan, fire one off if needed
  1522. */
  1523. if (memcmp(&il->staging, &il->active, sizeof(il->staging)))
  1524. il_commit_rxon(il);
  1525. }
  1526. static void
  1527. il4965_post_associate(struct il_priv *il)
  1528. {
  1529. struct ieee80211_vif *vif = il->vif;
  1530. int ret = 0;
  1531. if (!vif || !il->is_open)
  1532. return;
  1533. if (test_bit(S_EXIT_PENDING, &il->status))
  1534. return;
  1535. il_scan_cancel_timeout(il, 200);
  1536. il->staging.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  1537. il_commit_rxon(il);
  1538. ret = il_send_rxon_timing(il);
  1539. if (ret)
  1540. IL_WARN("RXON timing - " "Attempting to continue.\n");
  1541. il->staging.filter_flags |= RXON_FILTER_ASSOC_MSK;
  1542. il_set_rxon_ht(il, &il->current_ht_config);
  1543. if (il->ops->set_rxon_chain)
  1544. il->ops->set_rxon_chain(il);
  1545. il->staging.assoc_id = cpu_to_le16(vif->bss_conf.aid);
  1546. D_ASSOC("assoc id %d beacon interval %d\n", vif->bss_conf.aid,
  1547. vif->bss_conf.beacon_int);
  1548. if (vif->bss_conf.use_short_preamble)
  1549. il->staging.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
  1550. else
  1551. il->staging.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
  1552. if (il->staging.flags & RXON_FLG_BAND_24G_MSK) {
  1553. if (vif->bss_conf.use_short_slot)
  1554. il->staging.flags |= RXON_FLG_SHORT_SLOT_MSK;
  1555. else
  1556. il->staging.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
  1557. }
  1558. il_commit_rxon(il);
  1559. D_ASSOC("Associated as %d to: %pM\n", vif->bss_conf.aid,
  1560. il->active.bssid_addr);
  1561. switch (vif->type) {
  1562. case NL80211_IFTYPE_STATION:
  1563. break;
  1564. case NL80211_IFTYPE_ADHOC:
  1565. il4965_send_beacon_cmd(il);
  1566. break;
  1567. default:
  1568. IL_ERR("%s Should not be called in %d mode\n", __func__,
  1569. vif->type);
  1570. break;
  1571. }
  1572. /* the chain noise calibration will enabled PM upon completion
  1573. * If chain noise has already been run, then we need to enable
  1574. * power management here */
  1575. if (il->chain_noise_data.state == IL_CHAIN_NOISE_DONE)
  1576. il_power_update_mode(il, false);
  1577. /* Enable Rx differential gain and sensitivity calibrations */
  1578. il4965_chain_noise_reset(il);
  1579. il->start_calib = 1;
  1580. }
  1581. static void
  1582. il4965_config_ap(struct il_priv *il)
  1583. {
  1584. struct ieee80211_vif *vif = il->vif;
  1585. int ret = 0;
  1586. lockdep_assert_held(&il->mutex);
  1587. if (test_bit(S_EXIT_PENDING, &il->status))
  1588. return;
  1589. /* The following should be done only at AP bring up */
  1590. if (!il_is_associated(il)) {
  1591. /* RXON - unassoc (to set timing command) */
  1592. il->staging.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  1593. il_commit_rxon(il);
  1594. /* RXON Timing */
  1595. ret = il_send_rxon_timing(il);
  1596. if (ret)
  1597. IL_WARN("RXON timing failed - "
  1598. "Attempting to continue.\n");
  1599. /* AP has all antennas */
  1600. il->chain_noise_data.active_chains = il->hw_params.valid_rx_ant;
  1601. il_set_rxon_ht(il, &il->current_ht_config);
  1602. if (il->ops->set_rxon_chain)
  1603. il->ops->set_rxon_chain(il);
  1604. il->staging.assoc_id = 0;
  1605. if (vif->bss_conf.use_short_preamble)
  1606. il->staging.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
  1607. else
  1608. il->staging.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
  1609. if (il->staging.flags & RXON_FLG_BAND_24G_MSK) {
  1610. if (vif->bss_conf.use_short_slot)
  1611. il->staging.flags |= RXON_FLG_SHORT_SLOT_MSK;
  1612. else
  1613. il->staging.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
  1614. }
  1615. /* need to send beacon cmd before committing assoc RXON! */
  1616. il4965_send_beacon_cmd(il);
  1617. /* restore RXON assoc */
  1618. il->staging.filter_flags |= RXON_FILTER_ASSOC_MSK;
  1619. il_commit_rxon(il);
  1620. }
  1621. il4965_send_beacon_cmd(il);
  1622. }
  1623. const struct il_ops il4965_ops = {
  1624. .txq_update_byte_cnt_tbl = il4965_txq_update_byte_cnt_tbl,
  1625. .txq_attach_buf_to_tfd = il4965_hw_txq_attach_buf_to_tfd,
  1626. .txq_free_tfd = il4965_hw_txq_free_tfd,
  1627. .txq_init = il4965_hw_tx_queue_init,
  1628. .is_valid_rtc_data_addr = il4965_hw_valid_rtc_data_addr,
  1629. .init_alive_start = il4965_init_alive_start,
  1630. .load_ucode = il4965_load_bsm,
  1631. .dump_nic_error_log = il4965_dump_nic_error_log,
  1632. .dump_fh = il4965_dump_fh,
  1633. .set_channel_switch = il4965_hw_channel_switch,
  1634. .apm_init = il_apm_init,
  1635. .send_tx_power = il4965_send_tx_power,
  1636. .update_chain_flags = il4965_update_chain_flags,
  1637. .eeprom_acquire_semaphore = il4965_eeprom_acquire_semaphore,
  1638. .eeprom_release_semaphore = il4965_eeprom_release_semaphore,
  1639. .rxon_assoc = il4965_send_rxon_assoc,
  1640. .commit_rxon = il4965_commit_rxon,
  1641. .set_rxon_chain = il4965_set_rxon_chain,
  1642. .get_hcmd_size = il4965_get_hcmd_size,
  1643. .build_addsta_hcmd = il4965_build_addsta_hcmd,
  1644. .request_scan = il4965_request_scan,
  1645. .post_scan = il4965_post_scan,
  1646. .post_associate = il4965_post_associate,
  1647. .config_ap = il4965_config_ap,
  1648. .manage_ibss_station = il4965_manage_ibss_station,
  1649. .update_bcast_stations = il4965_update_bcast_stations,
  1650. .send_led_cmd = il4965_send_led_cmd,
  1651. };
  1652. struct il_cfg il4965_cfg = {
  1653. .name = "Intel(R) Wireless WiFi Link 4965AGN",
  1654. .fw_name_pre = IL4965_FW_PRE,
  1655. .ucode_api_max = IL4965_UCODE_API_MAX,
  1656. .ucode_api_min = IL4965_UCODE_API_MIN,
  1657. .sku = IL_SKU_A | IL_SKU_G | IL_SKU_N,
  1658. .valid_tx_ant = ANT_AB,
  1659. .valid_rx_ant = ANT_ABC,
  1660. .eeprom_ver = EEPROM_4965_EEPROM_VERSION,
  1661. .eeprom_calib_ver = EEPROM_4965_TX_POWER_VERSION,
  1662. .mod_params = &il4965_mod_params,
  1663. .led_mode = IL_LED_BLINK,
  1664. /*
  1665. * Force use of chains B and C for scan RX on 5 GHz band
  1666. * because the device has off-channel reception on chain A.
  1667. */
  1668. .scan_rx_antennas[IEEE80211_BAND_5GHZ] = ANT_BC,
  1669. .eeprom_size = IL4965_EEPROM_IMG_SIZE,
  1670. .num_of_queues = IL49_NUM_QUEUES,
  1671. .num_of_ampdu_queues = IL49_NUM_AMPDU_QUEUES,
  1672. .pll_cfg_val = 0,
  1673. .set_l0s = true,
  1674. .use_bsm = true,
  1675. .led_compensation = 61,
  1676. .chain_noise_num_beacons = IL4965_CAL_NUM_BEACONS,
  1677. .wd_timeout = IL_DEF_WD_TIMEOUT,
  1678. .temperature_kelvin = true,
  1679. .ucode_tracing = true,
  1680. .sensitivity_calib_by_driver = true,
  1681. .chain_noise_calib_by_driver = true,
  1682. .regulatory_bands = {
  1683. EEPROM_REGULATORY_BAND_1_CHANNELS,
  1684. EEPROM_REGULATORY_BAND_2_CHANNELS,
  1685. EEPROM_REGULATORY_BAND_3_CHANNELS,
  1686. EEPROM_REGULATORY_BAND_4_CHANNELS,
  1687. EEPROM_REGULATORY_BAND_5_CHANNELS,
  1688. EEPROM_4965_REGULATORY_BAND_24_HT40_CHANNELS,
  1689. EEPROM_4965_REGULATORY_BAND_52_HT40_CHANNELS
  1690. },
  1691. };
  1692. /* Module firmware */
  1693. MODULE_FIRMWARE(IL4965_MODULE_FIRMWARE(IL4965_UCODE_API_MAX));