4965.c 65 KB

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