4965.c 64 KB

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