4965.c 51 KB

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