4965.c 64 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402
  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. struct il_rxon_context *ctx = &il->ctx;
  1177. if (WARN_ONCE
  1178. (test_bit(S_SCAN_HW, &il->status),
  1179. "TX Power requested while scanning!\n"))
  1180. return -EAGAIN;
  1181. band = il->band == IEEE80211_BAND_2GHZ;
  1182. is_ht40 = iw4965_is_ht40_channel(ctx->active.flags);
  1183. if (is_ht40 && (ctx->active.flags & RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK))
  1184. ctrl_chan_high = 1;
  1185. cmd.band = band;
  1186. cmd.channel = ctx->active.channel;
  1187. ret =
  1188. il4965_fill_txpower_tbl(il, band, le16_to_cpu(ctx->active.channel),
  1189. is_ht40, ctrl_chan_high, &cmd.tx_power);
  1190. if (ret)
  1191. goto out;
  1192. ret = il_send_cmd_pdu(il, C_TX_PWR_TBL, sizeof(cmd), &cmd);
  1193. out:
  1194. return ret;
  1195. }
  1196. static int
  1197. il4965_send_rxon_assoc(struct il_priv *il, struct il_rxon_context *ctx)
  1198. {
  1199. int ret = 0;
  1200. struct il4965_rxon_assoc_cmd rxon_assoc;
  1201. const struct il_rxon_cmd *rxon1 = &ctx->staging;
  1202. const struct il_rxon_cmd *rxon2 = &ctx->active;
  1203. if (rxon1->flags == rxon2->flags &&
  1204. rxon1->filter_flags == rxon2->filter_flags &&
  1205. rxon1->cck_basic_rates == rxon2->cck_basic_rates &&
  1206. rxon1->ofdm_ht_single_stream_basic_rates ==
  1207. rxon2->ofdm_ht_single_stream_basic_rates &&
  1208. rxon1->ofdm_ht_dual_stream_basic_rates ==
  1209. rxon2->ofdm_ht_dual_stream_basic_rates &&
  1210. rxon1->rx_chain == rxon2->rx_chain &&
  1211. rxon1->ofdm_basic_rates == rxon2->ofdm_basic_rates) {
  1212. D_INFO("Using current RXON_ASSOC. Not resending.\n");
  1213. return 0;
  1214. }
  1215. rxon_assoc.flags = ctx->staging.flags;
  1216. rxon_assoc.filter_flags = ctx->staging.filter_flags;
  1217. rxon_assoc.ofdm_basic_rates = ctx->staging.ofdm_basic_rates;
  1218. rxon_assoc.cck_basic_rates = ctx->staging.cck_basic_rates;
  1219. rxon_assoc.reserved = 0;
  1220. rxon_assoc.ofdm_ht_single_stream_basic_rates =
  1221. ctx->staging.ofdm_ht_single_stream_basic_rates;
  1222. rxon_assoc.ofdm_ht_dual_stream_basic_rates =
  1223. ctx->staging.ofdm_ht_dual_stream_basic_rates;
  1224. rxon_assoc.rx_chain_select_flags = ctx->staging.rx_chain;
  1225. ret =
  1226. il_send_cmd_pdu_async(il, C_RXON_ASSOC, sizeof(rxon_assoc),
  1227. &rxon_assoc, NULL);
  1228. return ret;
  1229. }
  1230. static int
  1231. il4965_commit_rxon(struct il_priv *il, struct il_rxon_context *ctx)
  1232. {
  1233. /* cast away the const for active_rxon in this function */
  1234. struct il_rxon_cmd *active_rxon = (void *)&ctx->active;
  1235. int ret;
  1236. bool new_assoc = !!(ctx->staging.filter_flags & RXON_FILTER_ASSOC_MSK);
  1237. if (!il_is_alive(il))
  1238. return -EBUSY;
  1239. if (!ctx->is_active)
  1240. return 0;
  1241. /* always get timestamp with Rx frame */
  1242. ctx->staging.flags |= RXON_FLG_TSF2HOST_MSK;
  1243. ret = il_check_rxon_cmd(il, ctx);
  1244. if (ret) {
  1245. IL_ERR("Invalid RXON configuration. Not committing.\n");
  1246. return -EINVAL;
  1247. }
  1248. /*
  1249. * receive commit_rxon request
  1250. * abort any previous channel switch if still in process
  1251. */
  1252. if (test_bit(S_CHANNEL_SWITCH_PENDING, &il->status) &&
  1253. il->switch_channel != ctx->staging.channel) {
  1254. D_11H("abort channel switch on %d\n",
  1255. le16_to_cpu(il->switch_channel));
  1256. il_chswitch_done(il, false);
  1257. }
  1258. /* If we don't need to send a full RXON, we can use
  1259. * il_rxon_assoc_cmd which is used to reconfigure filter
  1260. * and other flags for the current radio configuration. */
  1261. if (!il_full_rxon_required(il, ctx)) {
  1262. ret = il_send_rxon_assoc(il, ctx);
  1263. if (ret) {
  1264. IL_ERR("Error setting RXON_ASSOC (%d)\n", ret);
  1265. return ret;
  1266. }
  1267. memcpy(active_rxon, &ctx->staging, sizeof(*active_rxon));
  1268. il_print_rx_config_cmd(il, ctx);
  1269. /*
  1270. * We do not commit tx power settings while channel changing,
  1271. * do it now if tx power changed.
  1272. */
  1273. il_set_tx_power(il, il->tx_power_next, false);
  1274. return 0;
  1275. }
  1276. /* If we are currently associated and the new config requires
  1277. * an RXON_ASSOC and the new config wants the associated mask enabled,
  1278. * we must clear the associated from the active configuration
  1279. * before we apply the new config */
  1280. if (il_is_associated_ctx(ctx) && new_assoc) {
  1281. D_INFO("Toggling associated bit on current RXON\n");
  1282. active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  1283. ret =
  1284. il_send_cmd_pdu(il, ctx->rxon_cmd,
  1285. sizeof(struct il_rxon_cmd), active_rxon);
  1286. /* If the mask clearing failed then we set
  1287. * active_rxon back to what it was previously */
  1288. if (ret) {
  1289. active_rxon->filter_flags |= RXON_FILTER_ASSOC_MSK;
  1290. IL_ERR("Error clearing ASSOC_MSK (%d)\n", ret);
  1291. return ret;
  1292. }
  1293. il_clear_ucode_stations(il, ctx);
  1294. il_restore_stations(il, ctx);
  1295. ret = il4965_restore_default_wep_keys(il, ctx);
  1296. if (ret) {
  1297. IL_ERR("Failed to restore WEP keys (%d)\n", ret);
  1298. return ret;
  1299. }
  1300. }
  1301. D_INFO("Sending RXON\n" "* with%s RXON_FILTER_ASSOC_MSK\n"
  1302. "* channel = %d\n" "* bssid = %pM\n", (new_assoc ? "" : "out"),
  1303. le16_to_cpu(ctx->staging.channel), ctx->staging.bssid_addr);
  1304. il_set_rxon_hwcrypto(il, ctx, !il->cfg->mod_params->sw_crypto);
  1305. /* Apply the new configuration
  1306. * RXON unassoc clears the station table in uCode so restoration of
  1307. * stations is needed after it (the RXON command) completes
  1308. */
  1309. if (!new_assoc) {
  1310. ret =
  1311. il_send_cmd_pdu(il, ctx->rxon_cmd,
  1312. sizeof(struct il_rxon_cmd), &ctx->staging);
  1313. if (ret) {
  1314. IL_ERR("Error setting new RXON (%d)\n", ret);
  1315. return ret;
  1316. }
  1317. D_INFO("Return from !new_assoc RXON.\n");
  1318. memcpy(active_rxon, &ctx->staging, sizeof(*active_rxon));
  1319. il_clear_ucode_stations(il, ctx);
  1320. il_restore_stations(il, ctx);
  1321. ret = il4965_restore_default_wep_keys(il, ctx);
  1322. if (ret) {
  1323. IL_ERR("Failed to restore WEP keys (%d)\n", ret);
  1324. return ret;
  1325. }
  1326. }
  1327. if (new_assoc) {
  1328. il->start_calib = 0;
  1329. /* Apply the new configuration
  1330. * RXON assoc doesn't clear the station table in uCode,
  1331. */
  1332. ret =
  1333. il_send_cmd_pdu(il, ctx->rxon_cmd,
  1334. sizeof(struct il_rxon_cmd), &ctx->staging);
  1335. if (ret) {
  1336. IL_ERR("Error setting new RXON (%d)\n", ret);
  1337. return ret;
  1338. }
  1339. memcpy(active_rxon, &ctx->staging, sizeof(*active_rxon));
  1340. }
  1341. il_print_rx_config_cmd(il, ctx);
  1342. il4965_init_sensitivity(il);
  1343. /* If we issue a new RXON command which required a tune then we must
  1344. * send a new TXPOWER command or we won't be able to Tx any frames */
  1345. ret = il_set_tx_power(il, il->tx_power_next, true);
  1346. if (ret) {
  1347. IL_ERR("Error sending TX power (%d)\n", ret);
  1348. return ret;
  1349. }
  1350. return 0;
  1351. }
  1352. static int
  1353. il4965_hw_channel_switch(struct il_priv *il,
  1354. struct ieee80211_channel_switch *ch_switch)
  1355. {
  1356. struct il_rxon_context *ctx = &il->ctx;
  1357. int rc;
  1358. u8 band = 0;
  1359. bool is_ht40 = false;
  1360. u8 ctrl_chan_high = 0;
  1361. struct il4965_channel_switch_cmd cmd;
  1362. const struct il_channel_info *ch_info;
  1363. u32 switch_time_in_usec, ucode_switch_time;
  1364. u16 ch;
  1365. u32 tsf_low;
  1366. u8 switch_count;
  1367. u16 beacon_interval = le16_to_cpu(ctx->timing.beacon_interval);
  1368. struct ieee80211_vif *vif = ctx->vif;
  1369. band = il->band == IEEE80211_BAND_2GHZ;
  1370. is_ht40 = iw4965_is_ht40_channel(ctx->staging.flags);
  1371. if (is_ht40 && (ctx->staging.flags & RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK))
  1372. ctrl_chan_high = 1;
  1373. cmd.band = band;
  1374. cmd.expect_beacon = 0;
  1375. ch = ch_switch->channel->hw_value;
  1376. cmd.channel = cpu_to_le16(ch);
  1377. cmd.rxon_flags = ctx->staging.flags;
  1378. cmd.rxon_filter_flags = ctx->staging.filter_flags;
  1379. switch_count = ch_switch->count;
  1380. tsf_low = ch_switch->timestamp & 0x0ffffffff;
  1381. /*
  1382. * calculate the ucode channel switch time
  1383. * adding TSF as one of the factor for when to switch
  1384. */
  1385. if (il->ucode_beacon_time > tsf_low && beacon_interval) {
  1386. if (switch_count >
  1387. ((il->ucode_beacon_time - tsf_low) / beacon_interval)) {
  1388. switch_count -=
  1389. (il->ucode_beacon_time - tsf_low) / beacon_interval;
  1390. } else
  1391. switch_count = 0;
  1392. }
  1393. if (switch_count <= 1)
  1394. cmd.switch_time = cpu_to_le32(il->ucode_beacon_time);
  1395. else {
  1396. switch_time_in_usec =
  1397. vif->bss_conf.beacon_int * switch_count * TIME_UNIT;
  1398. ucode_switch_time =
  1399. il_usecs_to_beacons(il, switch_time_in_usec,
  1400. beacon_interval);
  1401. cmd.switch_time =
  1402. il_add_beacon_time(il, il->ucode_beacon_time,
  1403. ucode_switch_time, beacon_interval);
  1404. }
  1405. D_11H("uCode time for the switch is 0x%x\n", cmd.switch_time);
  1406. ch_info = il_get_channel_info(il, il->band, ch);
  1407. if (ch_info)
  1408. cmd.expect_beacon = il_is_channel_radar(ch_info);
  1409. else {
  1410. IL_ERR("invalid channel switch from %u to %u\n",
  1411. ctx->active.channel, ch);
  1412. return -EFAULT;
  1413. }
  1414. rc = il4965_fill_txpower_tbl(il, band, ch, is_ht40, ctrl_chan_high,
  1415. &cmd.tx_power);
  1416. if (rc) {
  1417. D_11H("error:%d fill txpower_tbl\n", rc);
  1418. return rc;
  1419. }
  1420. return il_send_cmd_pdu(il, C_CHANNEL_SWITCH, sizeof(cmd), &cmd);
  1421. }
  1422. /**
  1423. * il4965_txq_update_byte_cnt_tbl - Set up entry in Tx byte-count array
  1424. */
  1425. static void
  1426. il4965_txq_update_byte_cnt_tbl(struct il_priv *il, struct il_tx_queue *txq,
  1427. u16 byte_cnt)
  1428. {
  1429. struct il4965_scd_bc_tbl *scd_bc_tbl = il->scd_bc_tbls.addr;
  1430. int txq_id = txq->q.id;
  1431. int write_ptr = txq->q.write_ptr;
  1432. int len = byte_cnt + IL_TX_CRC_SIZE + IL_TX_DELIMITER_SIZE;
  1433. __le16 bc_ent;
  1434. WARN_ON(len > 0xFFF || write_ptr >= TFD_QUEUE_SIZE_MAX);
  1435. bc_ent = cpu_to_le16(len & 0xFFF);
  1436. /* Set up byte count within first 256 entries */
  1437. scd_bc_tbl[txq_id].tfd_offset[write_ptr] = bc_ent;
  1438. /* If within first 64 entries, duplicate at end */
  1439. if (write_ptr < TFD_QUEUE_SIZE_BC_DUP)
  1440. scd_bc_tbl[txq_id].tfd_offset[TFD_QUEUE_SIZE_MAX + write_ptr] =
  1441. bc_ent;
  1442. }
  1443. /**
  1444. * il4965_hw_get_temperature - return the calibrated temperature (in Kelvin)
  1445. * @stats: Provides the temperature reading from the uCode
  1446. *
  1447. * A return of <0 indicates bogus data in the stats
  1448. */
  1449. static int
  1450. il4965_hw_get_temperature(struct il_priv *il)
  1451. {
  1452. s32 temperature;
  1453. s32 vt;
  1454. s32 R1, R2, R3;
  1455. u32 R4;
  1456. if (test_bit(S_TEMPERATURE, &il->status) &&
  1457. (il->_4965.stats.flag & STATS_REPLY_FLG_HT40_MODE_MSK)) {
  1458. D_TEMP("Running HT40 temperature calibration\n");
  1459. R1 = (s32) le32_to_cpu(il->card_alive_init.therm_r1[1]);
  1460. R2 = (s32) le32_to_cpu(il->card_alive_init.therm_r2[1]);
  1461. R3 = (s32) le32_to_cpu(il->card_alive_init.therm_r3[1]);
  1462. R4 = le32_to_cpu(il->card_alive_init.therm_r4[1]);
  1463. } else {
  1464. D_TEMP("Running temperature calibration\n");
  1465. R1 = (s32) le32_to_cpu(il->card_alive_init.therm_r1[0]);
  1466. R2 = (s32) le32_to_cpu(il->card_alive_init.therm_r2[0]);
  1467. R3 = (s32) le32_to_cpu(il->card_alive_init.therm_r3[0]);
  1468. R4 = le32_to_cpu(il->card_alive_init.therm_r4[0]);
  1469. }
  1470. /*
  1471. * Temperature is only 23 bits, so sign extend out to 32.
  1472. *
  1473. * NOTE If we haven't received a stats notification yet
  1474. * with an updated temperature, use R4 provided to us in the
  1475. * "initialize" ALIVE response.
  1476. */
  1477. if (!test_bit(S_TEMPERATURE, &il->status))
  1478. vt = sign_extend32(R4, 23);
  1479. else
  1480. vt = sign_extend32(le32_to_cpu
  1481. (il->_4965.stats.general.common.temperature),
  1482. 23);
  1483. D_TEMP("Calib values R[1-3]: %d %d %d R4: %d\n", R1, R2, R3, vt);
  1484. if (R3 == R1) {
  1485. IL_ERR("Calibration conflict R1 == R3\n");
  1486. return -1;
  1487. }
  1488. /* Calculate temperature in degrees Kelvin, adjust by 97%.
  1489. * Add offset to center the adjustment around 0 degrees Centigrade. */
  1490. temperature = TEMPERATURE_CALIB_A_VAL * (vt - R2);
  1491. temperature /= (R3 - R1);
  1492. temperature =
  1493. (temperature * 97) / 100 + TEMPERATURE_CALIB_KELVIN_OFFSET;
  1494. D_TEMP("Calibrated temperature: %dK, %dC\n", temperature,
  1495. KELVIN_TO_CELSIUS(temperature));
  1496. return temperature;
  1497. }
  1498. /* Adjust Txpower only if temperature variance is greater than threshold. */
  1499. #define IL_TEMPERATURE_THRESHOLD 3
  1500. /**
  1501. * il4965_is_temp_calib_needed - determines if new calibration is needed
  1502. *
  1503. * If the temperature changed has changed sufficiently, then a recalibration
  1504. * is needed.
  1505. *
  1506. * Assumes caller will replace il->last_temperature once calibration
  1507. * executed.
  1508. */
  1509. static int
  1510. il4965_is_temp_calib_needed(struct il_priv *il)
  1511. {
  1512. int temp_diff;
  1513. if (!test_bit(S_STATS, &il->status)) {
  1514. D_TEMP("Temperature not updated -- no stats.\n");
  1515. return 0;
  1516. }
  1517. temp_diff = il->temperature - il->last_temperature;
  1518. /* get absolute value */
  1519. if (temp_diff < 0) {
  1520. D_POWER("Getting cooler, delta %d\n", temp_diff);
  1521. temp_diff = -temp_diff;
  1522. } else if (temp_diff == 0)
  1523. D_POWER("Temperature unchanged\n");
  1524. else
  1525. D_POWER("Getting warmer, delta %d\n", temp_diff);
  1526. if (temp_diff < IL_TEMPERATURE_THRESHOLD) {
  1527. D_POWER(" => thermal txpower calib not needed\n");
  1528. return 0;
  1529. }
  1530. D_POWER(" => thermal txpower calib needed\n");
  1531. return 1;
  1532. }
  1533. static void
  1534. il4965_temperature_calib(struct il_priv *il)
  1535. {
  1536. s32 temp;
  1537. temp = il4965_hw_get_temperature(il);
  1538. if (IL_TX_POWER_TEMPERATURE_OUT_OF_RANGE(temp))
  1539. return;
  1540. if (il->temperature != temp) {
  1541. if (il->temperature)
  1542. D_TEMP("Temperature changed " "from %dC to %dC\n",
  1543. KELVIN_TO_CELSIUS(il->temperature),
  1544. KELVIN_TO_CELSIUS(temp));
  1545. else
  1546. D_TEMP("Temperature " "initialized to %dC\n",
  1547. KELVIN_TO_CELSIUS(temp));
  1548. }
  1549. il->temperature = temp;
  1550. set_bit(S_TEMPERATURE, &il->status);
  1551. if (!il->disable_tx_power_cal &&
  1552. unlikely(!test_bit(S_SCANNING, &il->status)) &&
  1553. il4965_is_temp_calib_needed(il))
  1554. queue_work(il->workqueue, &il->txpower_work);
  1555. }
  1556. static u16
  1557. il4965_get_hcmd_size(u8 cmd_id, u16 len)
  1558. {
  1559. switch (cmd_id) {
  1560. case C_RXON:
  1561. return (u16) sizeof(struct il4965_rxon_cmd);
  1562. default:
  1563. return len;
  1564. }
  1565. }
  1566. static u16
  1567. il4965_build_addsta_hcmd(const struct il_addsta_cmd *cmd, u8 * data)
  1568. {
  1569. struct il4965_addsta_cmd *addsta = (struct il4965_addsta_cmd *)data;
  1570. addsta->mode = cmd->mode;
  1571. memcpy(&addsta->sta, &cmd->sta, sizeof(struct sta_id_modify));
  1572. memcpy(&addsta->key, &cmd->key, sizeof(struct il4965_keyinfo));
  1573. addsta->station_flags = cmd->station_flags;
  1574. addsta->station_flags_msk = cmd->station_flags_msk;
  1575. addsta->tid_disable_tx = cmd->tid_disable_tx;
  1576. addsta->add_immediate_ba_tid = cmd->add_immediate_ba_tid;
  1577. addsta->remove_immediate_ba_tid = cmd->remove_immediate_ba_tid;
  1578. addsta->add_immediate_ba_ssn = cmd->add_immediate_ba_ssn;
  1579. addsta->sleep_tx_count = cmd->sleep_tx_count;
  1580. addsta->reserved1 = cpu_to_le16(0);
  1581. addsta->reserved2 = cpu_to_le16(0);
  1582. return (u16) sizeof(struct il4965_addsta_cmd);
  1583. }
  1584. static inline u32
  1585. il4965_get_scd_ssn(struct il4965_tx_resp *tx_resp)
  1586. {
  1587. return le32_to_cpup(&tx_resp->u.status + tx_resp->frame_count) & MAX_SN;
  1588. }
  1589. static inline u32
  1590. il4965_tx_status_to_mac80211(u32 status)
  1591. {
  1592. status &= TX_STATUS_MSK;
  1593. switch (status) {
  1594. case TX_STATUS_SUCCESS:
  1595. case TX_STATUS_DIRECT_DONE:
  1596. return IEEE80211_TX_STAT_ACK;
  1597. case TX_STATUS_FAIL_DEST_PS:
  1598. return IEEE80211_TX_STAT_TX_FILTERED;
  1599. default:
  1600. return 0;
  1601. }
  1602. }
  1603. static inline bool
  1604. il4965_is_tx_success(u32 status)
  1605. {
  1606. status &= TX_STATUS_MSK;
  1607. return (status == TX_STATUS_SUCCESS || status == TX_STATUS_DIRECT_DONE);
  1608. }
  1609. /**
  1610. * il4965_tx_status_reply_tx - Handle Tx response for frames in aggregation queue
  1611. */
  1612. static int
  1613. il4965_tx_status_reply_tx(struct il_priv *il, struct il_ht_agg *agg,
  1614. struct il4965_tx_resp *tx_resp, int txq_id,
  1615. u16 start_idx)
  1616. {
  1617. u16 status;
  1618. struct agg_tx_status *frame_status = tx_resp->u.agg_status;
  1619. struct ieee80211_tx_info *info = NULL;
  1620. struct ieee80211_hdr *hdr = NULL;
  1621. u32 rate_n_flags = le32_to_cpu(tx_resp->rate_n_flags);
  1622. int i, sh, idx;
  1623. u16 seq;
  1624. if (agg->wait_for_ba)
  1625. D_TX_REPLY("got tx response w/o block-ack\n");
  1626. agg->frame_count = tx_resp->frame_count;
  1627. agg->start_idx = start_idx;
  1628. agg->rate_n_flags = rate_n_flags;
  1629. agg->bitmap = 0;
  1630. /* num frames attempted by Tx command */
  1631. if (agg->frame_count == 1) {
  1632. /* Only one frame was attempted; no block-ack will arrive */
  1633. status = le16_to_cpu(frame_status[0].status);
  1634. idx = start_idx;
  1635. D_TX_REPLY("FrameCnt = %d, StartIdx=%d idx=%d\n",
  1636. agg->frame_count, agg->start_idx, idx);
  1637. info = IEEE80211_SKB_CB(il->txq[txq_id].txb[idx].skb);
  1638. info->status.rates[0].count = tx_resp->failure_frame + 1;
  1639. info->flags &= ~IEEE80211_TX_CTL_AMPDU;
  1640. info->flags |= il4965_tx_status_to_mac80211(status);
  1641. il4965_hwrate_to_tx_control(il, rate_n_flags, info);
  1642. D_TX_REPLY("1 Frame 0x%x failure :%d\n", status & 0xff,
  1643. tx_resp->failure_frame);
  1644. D_TX_REPLY("Rate Info rate_n_flags=%x\n", rate_n_flags);
  1645. agg->wait_for_ba = 0;
  1646. } else {
  1647. /* Two or more frames were attempted; expect block-ack */
  1648. u64 bitmap = 0;
  1649. int start = agg->start_idx;
  1650. /* Construct bit-map of pending frames within Tx win */
  1651. for (i = 0; i < agg->frame_count; i++) {
  1652. u16 sc;
  1653. status = le16_to_cpu(frame_status[i].status);
  1654. seq = le16_to_cpu(frame_status[i].sequence);
  1655. idx = SEQ_TO_IDX(seq);
  1656. txq_id = SEQ_TO_QUEUE(seq);
  1657. if (status &
  1658. (AGG_TX_STATE_FEW_BYTES_MSK |
  1659. AGG_TX_STATE_ABORT_MSK))
  1660. continue;
  1661. D_TX_REPLY("FrameCnt = %d, txq_id=%d idx=%d\n",
  1662. agg->frame_count, txq_id, idx);
  1663. hdr = il_tx_queue_get_hdr(il, txq_id, idx);
  1664. if (!hdr) {
  1665. IL_ERR("BUG_ON idx doesn't point to valid skb"
  1666. " idx=%d, txq_id=%d\n", idx, txq_id);
  1667. return -1;
  1668. }
  1669. sc = le16_to_cpu(hdr->seq_ctrl);
  1670. if (idx != (SEQ_TO_SN(sc) & 0xff)) {
  1671. IL_ERR("BUG_ON idx doesn't match seq control"
  1672. " idx=%d, seq_idx=%d, seq=%d\n", idx,
  1673. SEQ_TO_SN(sc), hdr->seq_ctrl);
  1674. return -1;
  1675. }
  1676. D_TX_REPLY("AGG Frame i=%d idx %d seq=%d\n", i, idx,
  1677. SEQ_TO_SN(sc));
  1678. sh = idx - start;
  1679. if (sh > 64) {
  1680. sh = (start - idx) + 0xff;
  1681. bitmap = bitmap << sh;
  1682. sh = 0;
  1683. start = idx;
  1684. } else if (sh < -64)
  1685. sh = 0xff - (start - idx);
  1686. else if (sh < 0) {
  1687. sh = start - idx;
  1688. start = idx;
  1689. bitmap = bitmap << sh;
  1690. sh = 0;
  1691. }
  1692. bitmap |= 1ULL << sh;
  1693. D_TX_REPLY("start=%d bitmap=0x%llx\n", start,
  1694. (unsigned long long)bitmap);
  1695. }
  1696. agg->bitmap = bitmap;
  1697. agg->start_idx = start;
  1698. D_TX_REPLY("Frames %d start_idx=%d bitmap=0x%llx\n",
  1699. agg->frame_count, agg->start_idx,
  1700. (unsigned long long)agg->bitmap);
  1701. if (bitmap)
  1702. agg->wait_for_ba = 1;
  1703. }
  1704. return 0;
  1705. }
  1706. static u8
  1707. il4965_find_station(struct il_priv *il, const u8 * addr)
  1708. {
  1709. int i;
  1710. int start = 0;
  1711. int ret = IL_INVALID_STATION;
  1712. unsigned long flags;
  1713. if ((il->iw_mode == NL80211_IFTYPE_ADHOC))
  1714. start = IL_STA_ID;
  1715. if (is_broadcast_ether_addr(addr))
  1716. return il->ctx.bcast_sta_id;
  1717. spin_lock_irqsave(&il->sta_lock, flags);
  1718. for (i = start; i < il->hw_params.max_stations; i++)
  1719. if (il->stations[i].used &&
  1720. (!compare_ether_addr(il->stations[i].sta.sta.addr, addr))) {
  1721. ret = i;
  1722. goto out;
  1723. }
  1724. D_ASSOC("can not find STA %pM total %d\n", addr, il->num_stations);
  1725. out:
  1726. /*
  1727. * It may be possible that more commands interacting with stations
  1728. * arrive before we completed processing the adding of
  1729. * station
  1730. */
  1731. if (ret != IL_INVALID_STATION &&
  1732. (!(il->stations[ret].used & IL_STA_UCODE_ACTIVE) ||
  1733. ((il->stations[ret].used & IL_STA_UCODE_ACTIVE) &&
  1734. (il->stations[ret].used & IL_STA_UCODE_INPROGRESS)))) {
  1735. IL_ERR("Requested station info for sta %d before ready.\n",
  1736. ret);
  1737. ret = IL_INVALID_STATION;
  1738. }
  1739. spin_unlock_irqrestore(&il->sta_lock, flags);
  1740. return ret;
  1741. }
  1742. static int
  1743. il4965_get_ra_sta_id(struct il_priv *il, struct ieee80211_hdr *hdr)
  1744. {
  1745. if (il->iw_mode == NL80211_IFTYPE_STATION) {
  1746. return IL_AP_ID;
  1747. } else {
  1748. u8 *da = ieee80211_get_DA(hdr);
  1749. return il4965_find_station(il, da);
  1750. }
  1751. }
  1752. /**
  1753. * il4965_hdl_tx - Handle standard (non-aggregation) Tx response
  1754. */
  1755. static void
  1756. il4965_hdl_tx(struct il_priv *il, struct il_rx_buf *rxb)
  1757. {
  1758. struct il_rx_pkt *pkt = rxb_addr(rxb);
  1759. u16 sequence = le16_to_cpu(pkt->hdr.sequence);
  1760. int txq_id = SEQ_TO_QUEUE(sequence);
  1761. int idx = SEQ_TO_IDX(sequence);
  1762. struct il_tx_queue *txq = &il->txq[txq_id];
  1763. struct ieee80211_hdr *hdr;
  1764. struct ieee80211_tx_info *info;
  1765. struct il4965_tx_resp *tx_resp = (void *)&pkt->u.raw[0];
  1766. u32 status = le32_to_cpu(tx_resp->u.status);
  1767. int uninitialized_var(tid);
  1768. int sta_id;
  1769. int freed;
  1770. u8 *qc = NULL;
  1771. unsigned long flags;
  1772. if (idx >= txq->q.n_bd || il_queue_used(&txq->q, idx) == 0) {
  1773. IL_ERR("Read idx for DMA queue txq_id (%d) idx %d "
  1774. "is out of range [0-%d] %d %d\n", txq_id, idx,
  1775. txq->q.n_bd, txq->q.write_ptr, txq->q.read_ptr);
  1776. return;
  1777. }
  1778. txq->time_stamp = jiffies;
  1779. info = IEEE80211_SKB_CB(txq->txb[txq->q.read_ptr].skb);
  1780. memset(&info->status, 0, sizeof(info->status));
  1781. hdr = il_tx_queue_get_hdr(il, txq_id, idx);
  1782. if (ieee80211_is_data_qos(hdr->frame_control)) {
  1783. qc = ieee80211_get_qos_ctl(hdr);
  1784. tid = qc[0] & 0xf;
  1785. }
  1786. sta_id = il4965_get_ra_sta_id(il, hdr);
  1787. if (txq->sched_retry && unlikely(sta_id == IL_INVALID_STATION)) {
  1788. IL_ERR("Station not known\n");
  1789. return;
  1790. }
  1791. spin_lock_irqsave(&il->sta_lock, flags);
  1792. if (txq->sched_retry) {
  1793. const u32 scd_ssn = il4965_get_scd_ssn(tx_resp);
  1794. struct il_ht_agg *agg = NULL;
  1795. WARN_ON(!qc);
  1796. agg = &il->stations[sta_id].tid[tid].agg;
  1797. il4965_tx_status_reply_tx(il, agg, tx_resp, txq_id, idx);
  1798. /* check if BAR is needed */
  1799. if ((tx_resp->frame_count == 1) &&
  1800. !il4965_is_tx_success(status))
  1801. info->flags |= IEEE80211_TX_STAT_AMPDU_NO_BACK;
  1802. if (txq->q.read_ptr != (scd_ssn & 0xff)) {
  1803. idx = il_queue_dec_wrap(scd_ssn & 0xff, txq->q.n_bd);
  1804. D_TX_REPLY("Retry scheduler reclaim scd_ssn "
  1805. "%d idx %d\n", scd_ssn, idx);
  1806. freed = il4965_tx_queue_reclaim(il, txq_id, idx);
  1807. if (qc)
  1808. il4965_free_tfds_in_queue(il, sta_id, tid,
  1809. freed);
  1810. if (il->mac80211_registered &&
  1811. il_queue_space(&txq->q) > txq->q.low_mark &&
  1812. agg->state != IL_EMPTYING_HW_QUEUE_DELBA)
  1813. il_wake_queue(il, txq);
  1814. }
  1815. } else {
  1816. info->status.rates[0].count = tx_resp->failure_frame + 1;
  1817. info->flags |= il4965_tx_status_to_mac80211(status);
  1818. il4965_hwrate_to_tx_control(il,
  1819. le32_to_cpu(tx_resp->rate_n_flags),
  1820. info);
  1821. D_TX_REPLY("TXQ %d status %s (0x%08x) "
  1822. "rate_n_flags 0x%x retries %d\n", txq_id,
  1823. il4965_get_tx_fail_reason(status), status,
  1824. le32_to_cpu(tx_resp->rate_n_flags),
  1825. tx_resp->failure_frame);
  1826. freed = il4965_tx_queue_reclaim(il, txq_id, idx);
  1827. if (qc && likely(sta_id != IL_INVALID_STATION))
  1828. il4965_free_tfds_in_queue(il, sta_id, tid, freed);
  1829. else if (sta_id == IL_INVALID_STATION)
  1830. D_TX_REPLY("Station not known\n");
  1831. if (il->mac80211_registered &&
  1832. il_queue_space(&txq->q) > txq->q.low_mark)
  1833. il_wake_queue(il, txq);
  1834. }
  1835. if (qc && likely(sta_id != IL_INVALID_STATION))
  1836. il4965_txq_check_empty(il, sta_id, tid, txq_id);
  1837. il4965_check_abort_status(il, tx_resp->frame_count, status);
  1838. spin_unlock_irqrestore(&il->sta_lock, flags);
  1839. }
  1840. /* Set up 4965-specific Rx frame reply handlers */
  1841. static void
  1842. il4965_handler_setup(struct il_priv *il)
  1843. {
  1844. /* Legacy Rx frames */
  1845. il->handlers[N_RX] = il4965_hdl_rx;
  1846. /* Tx response */
  1847. il->handlers[C_TX] = il4965_hdl_tx;
  1848. }
  1849. static struct il_hcmd_ops il4965_hcmd = {
  1850. .rxon_assoc = il4965_send_rxon_assoc,
  1851. .commit_rxon = il4965_commit_rxon,
  1852. .set_rxon_chain = il4965_set_rxon_chain,
  1853. };
  1854. static void
  1855. il4965_post_scan(struct il_priv *il)
  1856. {
  1857. struct il_rxon_context *ctx = &il->ctx;
  1858. /*
  1859. * Since setting the RXON may have been deferred while
  1860. * performing the scan, fire one off if needed
  1861. */
  1862. if (memcmp(&ctx->staging, &ctx->active, sizeof(ctx->staging)))
  1863. il_commit_rxon(il, ctx);
  1864. }
  1865. static void
  1866. il4965_post_associate(struct il_priv *il)
  1867. {
  1868. struct il_rxon_context *ctx = &il->ctx;
  1869. struct ieee80211_vif *vif = ctx->vif;
  1870. struct ieee80211_conf *conf = NULL;
  1871. int ret = 0;
  1872. if (!vif || !il->is_open)
  1873. return;
  1874. if (test_bit(S_EXIT_PENDING, &il->status))
  1875. return;
  1876. il_scan_cancel_timeout(il, 200);
  1877. conf = &il->hw->conf;
  1878. ctx->staging.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  1879. il_commit_rxon(il, ctx);
  1880. ret = il_send_rxon_timing(il, ctx);
  1881. if (ret)
  1882. IL_WARN("RXON timing - " "Attempting to continue.\n");
  1883. ctx->staging.filter_flags |= RXON_FILTER_ASSOC_MSK;
  1884. il_set_rxon_ht(il, &il->current_ht_config);
  1885. if (il->cfg->ops->hcmd->set_rxon_chain)
  1886. il->cfg->ops->hcmd->set_rxon_chain(il, ctx);
  1887. ctx->staging.assoc_id = cpu_to_le16(vif->bss_conf.aid);
  1888. D_ASSOC("assoc id %d beacon interval %d\n", vif->bss_conf.aid,
  1889. vif->bss_conf.beacon_int);
  1890. if (vif->bss_conf.use_short_preamble)
  1891. ctx->staging.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
  1892. else
  1893. ctx->staging.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
  1894. if (ctx->staging.flags & RXON_FLG_BAND_24G_MSK) {
  1895. if (vif->bss_conf.use_short_slot)
  1896. ctx->staging.flags |= RXON_FLG_SHORT_SLOT_MSK;
  1897. else
  1898. ctx->staging.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
  1899. }
  1900. il_commit_rxon(il, ctx);
  1901. D_ASSOC("Associated as %d to: %pM\n", vif->bss_conf.aid,
  1902. ctx->active.bssid_addr);
  1903. switch (vif->type) {
  1904. case NL80211_IFTYPE_STATION:
  1905. break;
  1906. case NL80211_IFTYPE_ADHOC:
  1907. il4965_send_beacon_cmd(il);
  1908. break;
  1909. default:
  1910. IL_ERR("%s Should not be called in %d mode\n", __func__,
  1911. vif->type);
  1912. break;
  1913. }
  1914. /* the chain noise calibration will enabled PM upon completion
  1915. * If chain noise has already been run, then we need to enable
  1916. * power management here */
  1917. if (il->chain_noise_data.state == IL_CHAIN_NOISE_DONE)
  1918. il_power_update_mode(il, false);
  1919. /* Enable Rx differential gain and sensitivity calibrations */
  1920. il4965_chain_noise_reset(il);
  1921. il->start_calib = 1;
  1922. }
  1923. static void
  1924. il4965_config_ap(struct il_priv *il)
  1925. {
  1926. struct il_rxon_context *ctx = &il->ctx;
  1927. struct ieee80211_vif *vif = ctx->vif;
  1928. int ret = 0;
  1929. lockdep_assert_held(&il->mutex);
  1930. if (test_bit(S_EXIT_PENDING, &il->status))
  1931. return;
  1932. /* The following should be done only at AP bring up */
  1933. if (!il_is_associated_ctx(ctx)) {
  1934. /* RXON - unassoc (to set timing command) */
  1935. ctx->staging.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  1936. il_commit_rxon(il, ctx);
  1937. /* RXON Timing */
  1938. ret = il_send_rxon_timing(il, ctx);
  1939. if (ret)
  1940. IL_WARN("RXON timing failed - "
  1941. "Attempting to continue.\n");
  1942. /* AP has all antennas */
  1943. il->chain_noise_data.active_chains = il->hw_params.valid_rx_ant;
  1944. il_set_rxon_ht(il, &il->current_ht_config);
  1945. if (il->cfg->ops->hcmd->set_rxon_chain)
  1946. il->cfg->ops->hcmd->set_rxon_chain(il, ctx);
  1947. ctx->staging.assoc_id = 0;
  1948. if (vif->bss_conf.use_short_preamble)
  1949. ctx->staging.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
  1950. else
  1951. ctx->staging.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
  1952. if (ctx->staging.flags & RXON_FLG_BAND_24G_MSK) {
  1953. if (vif->bss_conf.use_short_slot)
  1954. ctx->staging.flags |= RXON_FLG_SHORT_SLOT_MSK;
  1955. else
  1956. ctx->staging.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
  1957. }
  1958. /* need to send beacon cmd before committing assoc RXON! */
  1959. il4965_send_beacon_cmd(il);
  1960. /* restore RXON assoc */
  1961. ctx->staging.filter_flags |= RXON_FILTER_ASSOC_MSK;
  1962. il_commit_rxon(il, ctx);
  1963. }
  1964. il4965_send_beacon_cmd(il);
  1965. }
  1966. static struct il_hcmd_utils_ops il4965_hcmd_utils = {
  1967. .get_hcmd_size = il4965_get_hcmd_size,
  1968. .build_addsta_hcmd = il4965_build_addsta_hcmd,
  1969. .request_scan = il4965_request_scan,
  1970. .post_scan = il4965_post_scan,
  1971. };
  1972. static struct il_lib_ops il4965_lib = {
  1973. .set_hw_params = il4965_hw_set_hw_params,
  1974. .txq_update_byte_cnt_tbl = il4965_txq_update_byte_cnt_tbl,
  1975. .txq_attach_buf_to_tfd = il4965_hw_txq_attach_buf_to_tfd,
  1976. .txq_free_tfd = il4965_hw_txq_free_tfd,
  1977. .txq_init = il4965_hw_tx_queue_init,
  1978. .handler_setup = il4965_handler_setup,
  1979. .is_valid_rtc_data_addr = il4965_hw_valid_rtc_data_addr,
  1980. .init_alive_start = il4965_init_alive_start,
  1981. .load_ucode = il4965_load_bsm,
  1982. .dump_nic_error_log = il4965_dump_nic_error_log,
  1983. .dump_fh = il4965_dump_fh,
  1984. .set_channel_switch = il4965_hw_channel_switch,
  1985. .apm_ops = {
  1986. .init = il_apm_init,
  1987. .config = il4965_nic_config,
  1988. },
  1989. .eeprom_ops = {
  1990. .regulatory_bands = {
  1991. EEPROM_REGULATORY_BAND_1_CHANNELS,
  1992. EEPROM_REGULATORY_BAND_2_CHANNELS,
  1993. EEPROM_REGULATORY_BAND_3_CHANNELS,
  1994. EEPROM_REGULATORY_BAND_4_CHANNELS,
  1995. EEPROM_REGULATORY_BAND_5_CHANNELS,
  1996. EEPROM_4965_REGULATORY_BAND_24_HT40_CHANNELS,
  1997. EEPROM_4965_REGULATORY_BAND_52_HT40_CHANNELS},
  1998. .acquire_semaphore = il4965_eeprom_acquire_semaphore,
  1999. .release_semaphore = il4965_eeprom_release_semaphore,
  2000. },
  2001. .send_tx_power = il4965_send_tx_power,
  2002. .update_chain_flags = il4965_update_chain_flags,
  2003. .temp_ops = {
  2004. .temperature = il4965_temperature_calib,
  2005. },
  2006. #ifdef CONFIG_IWLEGACY_DEBUGFS
  2007. .debugfs_ops = {
  2008. .rx_stats_read = il4965_ucode_rx_stats_read,
  2009. .tx_stats_read = il4965_ucode_tx_stats_read,
  2010. .general_stats_read = il4965_ucode_general_stats_read,
  2011. },
  2012. #endif
  2013. };
  2014. static const struct il_legacy_ops il4965_legacy_ops = {
  2015. .post_associate = il4965_post_associate,
  2016. .config_ap = il4965_config_ap,
  2017. .manage_ibss_station = il4965_manage_ibss_station,
  2018. .update_bcast_stations = il4965_update_bcast_stations,
  2019. };
  2020. struct ieee80211_ops il4965_hw_ops = {
  2021. .tx = il4965_mac_tx,
  2022. .start = il4965_mac_start,
  2023. .stop = il4965_mac_stop,
  2024. .add_interface = il_mac_add_interface,
  2025. .remove_interface = il_mac_remove_interface,
  2026. .change_interface = il_mac_change_interface,
  2027. .config = il_mac_config,
  2028. .configure_filter = il4965_configure_filter,
  2029. .set_key = il4965_mac_set_key,
  2030. .update_tkip_key = il4965_mac_update_tkip_key,
  2031. .conf_tx = il_mac_conf_tx,
  2032. .reset_tsf = il_mac_reset_tsf,
  2033. .bss_info_changed = il_mac_bss_info_changed,
  2034. .ampdu_action = il4965_mac_ampdu_action,
  2035. .hw_scan = il_mac_hw_scan,
  2036. .sta_add = il4965_mac_sta_add,
  2037. .sta_remove = il_mac_sta_remove,
  2038. .channel_switch = il4965_mac_channel_switch,
  2039. .tx_last_beacon = il_mac_tx_last_beacon,
  2040. };
  2041. static const struct il_ops il4965_ops = {
  2042. .lib = &il4965_lib,
  2043. .hcmd = &il4965_hcmd,
  2044. .utils = &il4965_hcmd_utils,
  2045. .led = &il4965_led_ops,
  2046. .legacy = &il4965_legacy_ops,
  2047. .ieee80211_ops = &il4965_hw_ops,
  2048. };
  2049. static struct il_base_params il4965_base_params = {
  2050. .eeprom_size = IL4965_EEPROM_IMG_SIZE,
  2051. .num_of_queues = IL49_NUM_QUEUES,
  2052. .num_of_ampdu_queues = IL49_NUM_AMPDU_QUEUES,
  2053. .pll_cfg_val = 0,
  2054. .set_l0s = true,
  2055. .use_bsm = true,
  2056. .led_compensation = 61,
  2057. .chain_noise_num_beacons = IL4965_CAL_NUM_BEACONS,
  2058. .wd_timeout = IL_DEF_WD_TIMEOUT,
  2059. .temperature_kelvin = true,
  2060. .ucode_tracing = true,
  2061. .sensitivity_calib_by_driver = true,
  2062. .chain_noise_calib_by_driver = true,
  2063. };
  2064. struct il_cfg il4965_cfg = {
  2065. .name = "Intel(R) Wireless WiFi Link 4965AGN",
  2066. .fw_name_pre = IL4965_FW_PRE,
  2067. .ucode_api_max = IL4965_UCODE_API_MAX,
  2068. .ucode_api_min = IL4965_UCODE_API_MIN,
  2069. .sku = IL_SKU_A | IL_SKU_G | IL_SKU_N,
  2070. .valid_tx_ant = ANT_AB,
  2071. .valid_rx_ant = ANT_ABC,
  2072. .eeprom_ver = EEPROM_4965_EEPROM_VERSION,
  2073. .eeprom_calib_ver = EEPROM_4965_TX_POWER_VERSION,
  2074. .ops = &il4965_ops,
  2075. .mod_params = &il4965_mod_params,
  2076. .base_params = &il4965_base_params,
  2077. .led_mode = IL_LED_BLINK,
  2078. /*
  2079. * Force use of chains B and C for scan RX on 5 GHz band
  2080. * because the device has off-channel reception on chain A.
  2081. */
  2082. .scan_rx_antennas[IEEE80211_BAND_5GHZ] = ANT_BC,
  2083. };
  2084. /* Module firmware */
  2085. MODULE_FIRMWARE(IL4965_MODULE_FIRMWARE(IL4965_UCODE_API_MAX));