4965.c 65 KB

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