4965.c 51 KB

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