iwl-4965.c 67 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2003 - 2008 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/skbuff.h>
  33. #include <linux/netdevice.h>
  34. #include <linux/wireless.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-calib.h"
  44. #include "iwl-sta.h"
  45. static int iwl4965_send_tx_power(struct iwl_priv *priv);
  46. static int iwl4965_hw_get_temperature(const struct iwl_priv *priv);
  47. /* Highest firmware API version supported */
  48. #define IWL4965_UCODE_API_MAX 2
  49. /* Lowest firmware API version supported */
  50. #define IWL4965_UCODE_API_MIN 2
  51. #define IWL4965_FW_PRE "iwlwifi-4965-"
  52. #define _IWL4965_MODULE_FIRMWARE(api) IWL4965_FW_PRE #api ".ucode"
  53. #define IWL4965_MODULE_FIRMWARE(api) _IWL4965_MODULE_FIRMWARE(api)
  54. /* module parameters */
  55. static struct iwl_mod_params iwl4965_mod_params = {
  56. .num_of_queues = IWL49_NUM_QUEUES,
  57. .num_of_ampdu_queues = IWL49_NUM_AMPDU_QUEUES,
  58. .amsdu_size_8K = 1,
  59. .restart_fw = 1,
  60. /* the rest are 0 by default */
  61. };
  62. /* check contents of special bootstrap uCode SRAM */
  63. static int iwl4965_verify_bsm(struct iwl_priv *priv)
  64. {
  65. __le32 *image = priv->ucode_boot.v_addr;
  66. u32 len = priv->ucode_boot.len;
  67. u32 reg;
  68. u32 val;
  69. IWL_DEBUG_INFO("Begin verify bsm\n");
  70. /* verify BSM SRAM contents */
  71. val = iwl_read_prph(priv, BSM_WR_DWCOUNT_REG);
  72. for (reg = BSM_SRAM_LOWER_BOUND;
  73. reg < BSM_SRAM_LOWER_BOUND + len;
  74. reg += sizeof(u32), image++) {
  75. val = iwl_read_prph(priv, reg);
  76. if (val != le32_to_cpu(*image)) {
  77. IWL_ERROR("BSM uCode verification failed at "
  78. "addr 0x%08X+%u (of %u), is 0x%x, s/b 0x%x\n",
  79. BSM_SRAM_LOWER_BOUND,
  80. reg - BSM_SRAM_LOWER_BOUND, len,
  81. val, le32_to_cpu(*image));
  82. return -EIO;
  83. }
  84. }
  85. IWL_DEBUG_INFO("BSM bootstrap uCode image OK\n");
  86. return 0;
  87. }
  88. /**
  89. * iwl4965_load_bsm - Load bootstrap instructions
  90. *
  91. * BSM operation:
  92. *
  93. * The Bootstrap State Machine (BSM) stores a short bootstrap uCode program
  94. * in special SRAM that does not power down during RFKILL. When powering back
  95. * up after power-saving sleeps (or during initial uCode load), the BSM loads
  96. * the bootstrap program into the on-board processor, and starts it.
  97. *
  98. * The bootstrap program loads (via DMA) instructions and data for a new
  99. * program from host DRAM locations indicated by the host driver in the
  100. * BSM_DRAM_* registers. Once the new program is loaded, it starts
  101. * automatically.
  102. *
  103. * When initializing the NIC, the host driver points the BSM to the
  104. * "initialize" uCode image. This uCode sets up some internal data, then
  105. * notifies host via "initialize alive" that it is complete.
  106. *
  107. * The host then replaces the BSM_DRAM_* pointer values to point to the
  108. * normal runtime uCode instructions and a backup uCode data cache buffer
  109. * (filled initially with starting data values for the on-board processor),
  110. * then triggers the "initialize" uCode to load and launch the runtime uCode,
  111. * which begins normal operation.
  112. *
  113. * When doing a power-save shutdown, runtime uCode saves data SRAM into
  114. * the backup data cache in DRAM before SRAM is powered down.
  115. *
  116. * When powering back up, the BSM loads the bootstrap program. This reloads
  117. * the runtime uCode instructions and the backup data cache into SRAM,
  118. * and re-launches the runtime uCode from where it left off.
  119. */
  120. static int iwl4965_load_bsm(struct iwl_priv *priv)
  121. {
  122. __le32 *image = priv->ucode_boot.v_addr;
  123. u32 len = priv->ucode_boot.len;
  124. dma_addr_t pinst;
  125. dma_addr_t pdata;
  126. u32 inst_len;
  127. u32 data_len;
  128. int i;
  129. u32 done;
  130. u32 reg_offset;
  131. int ret;
  132. IWL_DEBUG_INFO("Begin load bsm\n");
  133. priv->ucode_type = UCODE_RT;
  134. /* make sure bootstrap program is no larger than BSM's SRAM size */
  135. if (len > IWL49_MAX_BSM_SIZE)
  136. return -EINVAL;
  137. /* Tell bootstrap uCode where to find the "Initialize" uCode
  138. * in host DRAM ... host DRAM physical address bits 35:4 for 4965.
  139. * NOTE: iwl_init_alive_start() will replace these values,
  140. * after the "initialize" uCode has run, to point to
  141. * runtime/protocol instructions and backup data cache.
  142. */
  143. pinst = priv->ucode_init.p_addr >> 4;
  144. pdata = priv->ucode_init_data.p_addr >> 4;
  145. inst_len = priv->ucode_init.len;
  146. data_len = priv->ucode_init_data.len;
  147. ret = iwl_grab_nic_access(priv);
  148. if (ret)
  149. return ret;
  150. iwl_write_prph(priv, BSM_DRAM_INST_PTR_REG, pinst);
  151. iwl_write_prph(priv, BSM_DRAM_DATA_PTR_REG, pdata);
  152. iwl_write_prph(priv, BSM_DRAM_INST_BYTECOUNT_REG, inst_len);
  153. iwl_write_prph(priv, BSM_DRAM_DATA_BYTECOUNT_REG, data_len);
  154. /* Fill BSM memory with bootstrap instructions */
  155. for (reg_offset = BSM_SRAM_LOWER_BOUND;
  156. reg_offset < BSM_SRAM_LOWER_BOUND + len;
  157. reg_offset += sizeof(u32), image++)
  158. _iwl_write_prph(priv, reg_offset, le32_to_cpu(*image));
  159. ret = iwl4965_verify_bsm(priv);
  160. if (ret) {
  161. iwl_release_nic_access(priv);
  162. return ret;
  163. }
  164. /* Tell BSM to copy from BSM SRAM into instruction SRAM, when asked */
  165. iwl_write_prph(priv, BSM_WR_MEM_SRC_REG, 0x0);
  166. iwl_write_prph(priv, BSM_WR_MEM_DST_REG, IWL49_RTC_INST_LOWER_BOUND);
  167. iwl_write_prph(priv, BSM_WR_DWCOUNT_REG, len / sizeof(u32));
  168. /* Load bootstrap code into instruction SRAM now,
  169. * to prepare to load "initialize" uCode */
  170. iwl_write_prph(priv, BSM_WR_CTRL_REG, BSM_WR_CTRL_REG_BIT_START);
  171. /* Wait for load of bootstrap uCode to finish */
  172. for (i = 0; i < 100; i++) {
  173. done = iwl_read_prph(priv, BSM_WR_CTRL_REG);
  174. if (!(done & BSM_WR_CTRL_REG_BIT_START))
  175. break;
  176. udelay(10);
  177. }
  178. if (i < 100)
  179. IWL_DEBUG_INFO("BSM write complete, poll %d iterations\n", i);
  180. else {
  181. IWL_ERROR("BSM write did not complete!\n");
  182. return -EIO;
  183. }
  184. /* Enable future boot loads whenever power management unit triggers it
  185. * (e.g. when powering back up after power-save shutdown) */
  186. iwl_write_prph(priv, BSM_WR_CTRL_REG, BSM_WR_CTRL_REG_BIT_START_EN);
  187. iwl_release_nic_access(priv);
  188. return 0;
  189. }
  190. /**
  191. * iwl4965_set_ucode_ptrs - Set uCode address location
  192. *
  193. * Tell initialization uCode where to find runtime uCode.
  194. *
  195. * BSM registers initially contain pointers to initialization uCode.
  196. * We need to replace them to load runtime uCode inst and data,
  197. * and to save runtime data when powering down.
  198. */
  199. static int iwl4965_set_ucode_ptrs(struct iwl_priv *priv)
  200. {
  201. dma_addr_t pinst;
  202. dma_addr_t pdata;
  203. unsigned long flags;
  204. int ret = 0;
  205. /* bits 35:4 for 4965 */
  206. pinst = priv->ucode_code.p_addr >> 4;
  207. pdata = priv->ucode_data_backup.p_addr >> 4;
  208. spin_lock_irqsave(&priv->lock, flags);
  209. ret = iwl_grab_nic_access(priv);
  210. if (ret) {
  211. spin_unlock_irqrestore(&priv->lock, flags);
  212. return ret;
  213. }
  214. /* Tell bootstrap uCode where to find image to load */
  215. iwl_write_prph(priv, BSM_DRAM_INST_PTR_REG, pinst);
  216. iwl_write_prph(priv, BSM_DRAM_DATA_PTR_REG, pdata);
  217. iwl_write_prph(priv, BSM_DRAM_DATA_BYTECOUNT_REG,
  218. priv->ucode_data.len);
  219. /* Inst byte count must be last to set up, bit 31 signals uCode
  220. * that all new ptr/size info is in place */
  221. iwl_write_prph(priv, BSM_DRAM_INST_BYTECOUNT_REG,
  222. priv->ucode_code.len | BSM_DRAM_INST_LOAD);
  223. iwl_release_nic_access(priv);
  224. spin_unlock_irqrestore(&priv->lock, flags);
  225. IWL_DEBUG_INFO("Runtime uCode pointers are set.\n");
  226. return ret;
  227. }
  228. /**
  229. * iwl4965_init_alive_start - Called after REPLY_ALIVE notification received
  230. *
  231. * Called after REPLY_ALIVE notification received from "initialize" uCode.
  232. *
  233. * The 4965 "initialize" ALIVE reply contains calibration data for:
  234. * Voltage, temperature, and MIMO tx gain correction, now stored in priv
  235. * (3945 does not contain this data).
  236. *
  237. * Tell "initialize" uCode to go ahead and load the runtime uCode.
  238. */
  239. static void iwl4965_init_alive_start(struct iwl_priv *priv)
  240. {
  241. /* Check alive response for "valid" sign from uCode */
  242. if (priv->card_alive_init.is_valid != UCODE_VALID_OK) {
  243. /* We had an error bringing up the hardware, so take it
  244. * all the way back down so we can try again */
  245. IWL_DEBUG_INFO("Initialize Alive failed.\n");
  246. goto restart;
  247. }
  248. /* Bootstrap uCode has loaded initialize uCode ... verify inst image.
  249. * This is a paranoid check, because we would not have gotten the
  250. * "initialize" alive if code weren't properly loaded. */
  251. if (iwl_verify_ucode(priv)) {
  252. /* Runtime instruction load was bad;
  253. * take it all the way back down so we can try again */
  254. IWL_DEBUG_INFO("Bad \"initialize\" uCode load.\n");
  255. goto restart;
  256. }
  257. /* Calculate temperature */
  258. priv->temperature = iwl4965_hw_get_temperature(priv);
  259. /* Send pointers to protocol/runtime uCode image ... init code will
  260. * load and launch runtime uCode, which will send us another "Alive"
  261. * notification. */
  262. IWL_DEBUG_INFO("Initialization Alive received.\n");
  263. if (iwl4965_set_ucode_ptrs(priv)) {
  264. /* Runtime instruction load won't happen;
  265. * take it all the way back down so we can try again */
  266. IWL_DEBUG_INFO("Couldn't set up uCode pointers.\n");
  267. goto restart;
  268. }
  269. return;
  270. restart:
  271. queue_work(priv->workqueue, &priv->restart);
  272. }
  273. static int is_fat_channel(__le32 rxon_flags)
  274. {
  275. return (rxon_flags & RXON_FLG_CHANNEL_MODE_PURE_40_MSK) ||
  276. (rxon_flags & RXON_FLG_CHANNEL_MODE_MIXED_MSK);
  277. }
  278. /*
  279. * EEPROM handlers
  280. */
  281. static u16 iwl4965_eeprom_calib_version(struct iwl_priv *priv)
  282. {
  283. return iwl_eeprom_query16(priv, EEPROM_4965_CALIB_VERSION_OFFSET);
  284. }
  285. /*
  286. * Activate/Deactivate Tx DMA/FIFO channels according tx fifos mask
  287. * must be called under priv->lock and mac access
  288. */
  289. static void iwl4965_txq_set_sched(struct iwl_priv *priv, u32 mask)
  290. {
  291. iwl_write_prph(priv, IWL49_SCD_TXFACT, mask);
  292. }
  293. static int iwl4965_apm_init(struct iwl_priv *priv)
  294. {
  295. int ret = 0;
  296. iwl_set_bit(priv, CSR_GIO_CHICKEN_BITS,
  297. CSR_GIO_CHICKEN_BITS_REG_BIT_DIS_L0S_EXIT_TIMER);
  298. /* disable L0s without affecting L1 :don't wait for ICH L0s bug W/A) */
  299. iwl_set_bit(priv, CSR_GIO_CHICKEN_BITS,
  300. CSR_GIO_CHICKEN_BITS_REG_BIT_L1A_NO_L0S_RX);
  301. /* set "initialization complete" bit to move adapter
  302. * D0U* --> D0A* state */
  303. iwl_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
  304. /* wait for clock stabilization */
  305. ret = iwl_poll_direct_bit(priv, CSR_GP_CNTRL,
  306. CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, 25000);
  307. if (ret < 0) {
  308. IWL_DEBUG_INFO("Failed to init the card\n");
  309. goto out;
  310. }
  311. ret = iwl_grab_nic_access(priv);
  312. if (ret)
  313. goto out;
  314. /* enable DMA */
  315. iwl_write_prph(priv, APMG_CLK_CTRL_REG, APMG_CLK_VAL_DMA_CLK_RQT |
  316. APMG_CLK_VAL_BSM_CLK_RQT);
  317. udelay(20);
  318. /* disable L1-Active */
  319. iwl_set_bits_prph(priv, APMG_PCIDEV_STT_REG,
  320. APMG_PCIDEV_STT_VAL_L1_ACT_DIS);
  321. iwl_release_nic_access(priv);
  322. out:
  323. return ret;
  324. }
  325. static void iwl4965_nic_config(struct iwl_priv *priv)
  326. {
  327. unsigned long flags;
  328. u32 val;
  329. u16 radio_cfg;
  330. u16 link;
  331. spin_lock_irqsave(&priv->lock, flags);
  332. if ((priv->rev_id & 0x80) == 0x80 && (priv->rev_id & 0x7f) < 8) {
  333. pci_read_config_dword(priv->pci_dev, PCI_REG_WUM8, &val);
  334. /* Enable No Snoop field */
  335. pci_write_config_dword(priv->pci_dev, PCI_REG_WUM8,
  336. val & ~(1 << 11));
  337. }
  338. pci_read_config_word(priv->pci_dev, PCI_CFG_LINK_CTRL, &link);
  339. /* L1 is enabled by BIOS */
  340. if ((link & PCI_CFG_LINK_CTRL_VAL_L1_EN) == PCI_CFG_LINK_CTRL_VAL_L1_EN)
  341. /* disable L0S disabled L1A enabled */
  342. iwl_set_bit(priv, CSR_GIO_REG, CSR_GIO_REG_VAL_L0S_ENABLED);
  343. else
  344. /* L0S enabled L1A disabled */
  345. iwl_clear_bit(priv, CSR_GIO_REG, CSR_GIO_REG_VAL_L0S_ENABLED);
  346. radio_cfg = iwl_eeprom_query16(priv, EEPROM_RADIO_CONFIG);
  347. /* write radio config values to register */
  348. if (EEPROM_RF_CFG_TYPE_MSK(radio_cfg) == EEPROM_4965_RF_CFG_TYPE_MAX)
  349. iwl_set_bit(priv, CSR_HW_IF_CONFIG_REG,
  350. EEPROM_RF_CFG_TYPE_MSK(radio_cfg) |
  351. EEPROM_RF_CFG_STEP_MSK(radio_cfg) |
  352. EEPROM_RF_CFG_DASH_MSK(radio_cfg));
  353. /* set CSR_HW_CONFIG_REG for uCode use */
  354. iwl_set_bit(priv, CSR_HW_IF_CONFIG_REG,
  355. CSR_HW_IF_CONFIG_REG_BIT_RADIO_SI |
  356. CSR_HW_IF_CONFIG_REG_BIT_MAC_SI);
  357. priv->calib_info = (struct iwl_eeprom_calib_info *)
  358. iwl_eeprom_query_addr(priv, EEPROM_4965_CALIB_TXPOWER_OFFSET);
  359. spin_unlock_irqrestore(&priv->lock, flags);
  360. }
  361. static int iwl4965_apm_stop_master(struct iwl_priv *priv)
  362. {
  363. unsigned long flags;
  364. spin_lock_irqsave(&priv->lock, flags);
  365. /* set stop master bit */
  366. iwl_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_STOP_MASTER);
  367. iwl_poll_direct_bit(priv, CSR_RESET,
  368. CSR_RESET_REG_FLAG_MASTER_DISABLED, 100);
  369. spin_unlock_irqrestore(&priv->lock, flags);
  370. IWL_DEBUG_INFO("stop master\n");
  371. return 0;
  372. }
  373. static void iwl4965_apm_stop(struct iwl_priv *priv)
  374. {
  375. unsigned long flags;
  376. iwl4965_apm_stop_master(priv);
  377. spin_lock_irqsave(&priv->lock, flags);
  378. iwl_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_SW_RESET);
  379. udelay(10);
  380. /* clear "init complete" move adapter D0A* --> D0U state */
  381. iwl_clear_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
  382. spin_unlock_irqrestore(&priv->lock, flags);
  383. }
  384. static int iwl4965_apm_reset(struct iwl_priv *priv)
  385. {
  386. int ret = 0;
  387. unsigned long flags;
  388. iwl4965_apm_stop_master(priv);
  389. spin_lock_irqsave(&priv->lock, flags);
  390. iwl_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_SW_RESET);
  391. udelay(10);
  392. /* FIXME: put here L1A -L0S w/a */
  393. iwl_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
  394. ret = iwl_poll_direct_bit(priv, CSR_GP_CNTRL,
  395. CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, 25000);
  396. if (ret < 0)
  397. goto out;
  398. udelay(10);
  399. ret = iwl_grab_nic_access(priv);
  400. if (ret)
  401. goto out;
  402. /* Enable DMA and BSM Clock */
  403. iwl_write_prph(priv, APMG_CLK_EN_REG, APMG_CLK_VAL_DMA_CLK_RQT |
  404. APMG_CLK_VAL_BSM_CLK_RQT);
  405. udelay(10);
  406. /* disable L1A */
  407. iwl_set_bits_prph(priv, APMG_PCIDEV_STT_REG,
  408. APMG_PCIDEV_STT_VAL_L1_ACT_DIS);
  409. iwl_release_nic_access(priv);
  410. clear_bit(STATUS_HCMD_ACTIVE, &priv->status);
  411. wake_up_interruptible(&priv->wait_command_queue);
  412. out:
  413. spin_unlock_irqrestore(&priv->lock, flags);
  414. return ret;
  415. }
  416. /* Reset differential Rx gains in NIC to prepare for chain noise calibration.
  417. * Called after every association, but this runs only once!
  418. * ... once chain noise is calibrated the first time, it's good forever. */
  419. static void iwl4965_chain_noise_reset(struct iwl_priv *priv)
  420. {
  421. struct iwl_chain_noise_data *data = &(priv->chain_noise_data);
  422. if ((data->state == IWL_CHAIN_NOISE_ALIVE) && iwl_is_associated(priv)) {
  423. struct iwl_calib_diff_gain_cmd cmd;
  424. memset(&cmd, 0, sizeof(cmd));
  425. cmd.hdr.op_code = IWL_PHY_CALIBRATE_DIFF_GAIN_CMD;
  426. cmd.diff_gain_a = 0;
  427. cmd.diff_gain_b = 0;
  428. cmd.diff_gain_c = 0;
  429. if (iwl_send_cmd_pdu(priv, REPLY_PHY_CALIBRATION_CMD,
  430. sizeof(cmd), &cmd))
  431. IWL_ERROR("Could not send REPLY_PHY_CALIBRATION_CMD\n");
  432. data->state = IWL_CHAIN_NOISE_ACCUMULATE;
  433. IWL_DEBUG_CALIB("Run chain_noise_calibrate\n");
  434. }
  435. }
  436. static void iwl4965_gain_computation(struct iwl_priv *priv,
  437. u32 *average_noise,
  438. u16 min_average_noise_antenna_i,
  439. u32 min_average_noise)
  440. {
  441. int i, ret;
  442. struct iwl_chain_noise_data *data = &priv->chain_noise_data;
  443. data->delta_gain_code[min_average_noise_antenna_i] = 0;
  444. for (i = 0; i < NUM_RX_CHAINS; i++) {
  445. s32 delta_g = 0;
  446. if (!(data->disconn_array[i]) &&
  447. (data->delta_gain_code[i] ==
  448. CHAIN_NOISE_DELTA_GAIN_INIT_VAL)) {
  449. delta_g = average_noise[i] - min_average_noise;
  450. data->delta_gain_code[i] = (u8)((delta_g * 10) / 15);
  451. data->delta_gain_code[i] =
  452. min(data->delta_gain_code[i],
  453. (u8) CHAIN_NOISE_MAX_DELTA_GAIN_CODE);
  454. data->delta_gain_code[i] =
  455. (data->delta_gain_code[i] | (1 << 2));
  456. } else {
  457. data->delta_gain_code[i] = 0;
  458. }
  459. }
  460. IWL_DEBUG_CALIB("delta_gain_codes: a %d b %d c %d\n",
  461. data->delta_gain_code[0],
  462. data->delta_gain_code[1],
  463. data->delta_gain_code[2]);
  464. /* Differential gain gets sent to uCode only once */
  465. if (!data->radio_write) {
  466. struct iwl_calib_diff_gain_cmd cmd;
  467. data->radio_write = 1;
  468. memset(&cmd, 0, sizeof(cmd));
  469. cmd.hdr.op_code = IWL_PHY_CALIBRATE_DIFF_GAIN_CMD;
  470. cmd.diff_gain_a = data->delta_gain_code[0];
  471. cmd.diff_gain_b = data->delta_gain_code[1];
  472. cmd.diff_gain_c = data->delta_gain_code[2];
  473. ret = iwl_send_cmd_pdu(priv, REPLY_PHY_CALIBRATION_CMD,
  474. sizeof(cmd), &cmd);
  475. if (ret)
  476. IWL_DEBUG_CALIB("fail sending cmd "
  477. "REPLY_PHY_CALIBRATION_CMD \n");
  478. /* TODO we might want recalculate
  479. * rx_chain in rxon cmd */
  480. /* Mark so we run this algo only once! */
  481. data->state = IWL_CHAIN_NOISE_CALIBRATED;
  482. }
  483. data->chain_noise_a = 0;
  484. data->chain_noise_b = 0;
  485. data->chain_noise_c = 0;
  486. data->chain_signal_a = 0;
  487. data->chain_signal_b = 0;
  488. data->chain_signal_c = 0;
  489. data->beacon_count = 0;
  490. }
  491. static void iwl4965_rts_tx_cmd_flag(struct ieee80211_tx_info *info,
  492. __le32 *tx_flags)
  493. {
  494. if (info->control.rates[0].flags & IEEE80211_TX_RC_USE_RTS_CTS) {
  495. *tx_flags |= TX_CMD_FLG_RTS_MSK;
  496. *tx_flags &= ~TX_CMD_FLG_CTS_MSK;
  497. } else if (info->control.rates[0].flags & IEEE80211_TX_RC_USE_CTS_PROTECT) {
  498. *tx_flags &= ~TX_CMD_FLG_RTS_MSK;
  499. *tx_flags |= TX_CMD_FLG_CTS_MSK;
  500. }
  501. }
  502. static void iwl4965_bg_txpower_work(struct work_struct *work)
  503. {
  504. struct iwl_priv *priv = container_of(work, struct iwl_priv,
  505. txpower_work);
  506. /* If a scan happened to start before we got here
  507. * then just return; the statistics notification will
  508. * kick off another scheduled work to compensate for
  509. * any temperature delta we missed here. */
  510. if (test_bit(STATUS_EXIT_PENDING, &priv->status) ||
  511. test_bit(STATUS_SCANNING, &priv->status))
  512. return;
  513. mutex_lock(&priv->mutex);
  514. /* Regardless of if we are associated, we must reconfigure the
  515. * TX power since frames can be sent on non-radar channels while
  516. * not associated */
  517. iwl4965_send_tx_power(priv);
  518. /* Update last_temperature to keep is_calib_needed from running
  519. * when it isn't needed... */
  520. priv->last_temperature = priv->temperature;
  521. mutex_unlock(&priv->mutex);
  522. }
  523. /*
  524. * Acquire priv->lock before calling this function !
  525. */
  526. static void iwl4965_set_wr_ptrs(struct iwl_priv *priv, int txq_id, u32 index)
  527. {
  528. iwl_write_direct32(priv, HBUS_TARG_WRPTR,
  529. (index & 0xff) | (txq_id << 8));
  530. iwl_write_prph(priv, IWL49_SCD_QUEUE_RDPTR(txq_id), index);
  531. }
  532. /**
  533. * iwl4965_tx_queue_set_status - (optionally) start Tx/Cmd queue
  534. * @tx_fifo_id: Tx DMA/FIFO channel (range 0-7) that the queue will feed
  535. * @scd_retry: (1) Indicates queue will be used in aggregation mode
  536. *
  537. * NOTE: Acquire priv->lock before calling this function !
  538. */
  539. static void iwl4965_tx_queue_set_status(struct iwl_priv *priv,
  540. struct iwl_tx_queue *txq,
  541. int tx_fifo_id, int scd_retry)
  542. {
  543. int txq_id = txq->q.id;
  544. /* Find out whether to activate Tx queue */
  545. int active = test_bit(txq_id, &priv->txq_ctx_active_msk) ? 1 : 0;
  546. /* Set up and activate */
  547. iwl_write_prph(priv, IWL49_SCD_QUEUE_STATUS_BITS(txq_id),
  548. (active << IWL49_SCD_QUEUE_STTS_REG_POS_ACTIVE) |
  549. (tx_fifo_id << IWL49_SCD_QUEUE_STTS_REG_POS_TXF) |
  550. (scd_retry << IWL49_SCD_QUEUE_STTS_REG_POS_WSL) |
  551. (scd_retry << IWL49_SCD_QUEUE_STTS_REG_POS_SCD_ACK) |
  552. IWL49_SCD_QUEUE_STTS_REG_MSK);
  553. txq->sched_retry = scd_retry;
  554. IWL_DEBUG_INFO("%s %s Queue %d on AC %d\n",
  555. active ? "Activate" : "Deactivate",
  556. scd_retry ? "BA" : "AC", txq_id, tx_fifo_id);
  557. }
  558. static const u16 default_queue_to_tx_fifo[] = {
  559. IWL_TX_FIFO_AC3,
  560. IWL_TX_FIFO_AC2,
  561. IWL_TX_FIFO_AC1,
  562. IWL_TX_FIFO_AC0,
  563. IWL49_CMD_FIFO_NUM,
  564. IWL_TX_FIFO_HCCA_1,
  565. IWL_TX_FIFO_HCCA_2
  566. };
  567. static int iwl4965_alive_notify(struct iwl_priv *priv)
  568. {
  569. u32 a;
  570. unsigned long flags;
  571. int ret;
  572. int i, chan;
  573. u32 reg_val;
  574. spin_lock_irqsave(&priv->lock, flags);
  575. ret = iwl_grab_nic_access(priv);
  576. if (ret) {
  577. spin_unlock_irqrestore(&priv->lock, flags);
  578. return ret;
  579. }
  580. /* Clear 4965's internal Tx Scheduler data base */
  581. priv->scd_base_addr = iwl_read_prph(priv, IWL49_SCD_SRAM_BASE_ADDR);
  582. a = priv->scd_base_addr + IWL49_SCD_CONTEXT_DATA_OFFSET;
  583. for (; a < priv->scd_base_addr + IWL49_SCD_TX_STTS_BITMAP_OFFSET; a += 4)
  584. iwl_write_targ_mem(priv, a, 0);
  585. for (; a < priv->scd_base_addr + IWL49_SCD_TRANSLATE_TBL_OFFSET; a += 4)
  586. iwl_write_targ_mem(priv, a, 0);
  587. for (; a < sizeof(u16) * priv->hw_params.max_txq_num; a += 4)
  588. iwl_write_targ_mem(priv, a, 0);
  589. /* Tel 4965 where to find Tx byte count tables */
  590. iwl_write_prph(priv, IWL49_SCD_DRAM_BASE_ADDR,
  591. priv->scd_bc_tbls.dma >> 10);
  592. /* Enable DMA channel */
  593. for (chan = 0; chan < FH49_TCSR_CHNL_NUM ; chan++)
  594. iwl_write_direct32(priv, FH_TCSR_CHNL_TX_CONFIG_REG(chan),
  595. FH_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_ENABLE |
  596. FH_TCSR_TX_CONFIG_REG_VAL_DMA_CREDIT_ENABLE);
  597. /* Update FH chicken bits */
  598. reg_val = iwl_read_direct32(priv, FH_TX_CHICKEN_BITS_REG);
  599. iwl_write_direct32(priv, FH_TX_CHICKEN_BITS_REG,
  600. reg_val | FH_TX_CHICKEN_BITS_SCD_AUTO_RETRY_EN);
  601. /* Disable chain mode for all queues */
  602. iwl_write_prph(priv, IWL49_SCD_QUEUECHAIN_SEL, 0);
  603. /* Initialize each Tx queue (including the command queue) */
  604. for (i = 0; i < priv->hw_params.max_txq_num; i++) {
  605. /* TFD circular buffer read/write indexes */
  606. iwl_write_prph(priv, IWL49_SCD_QUEUE_RDPTR(i), 0);
  607. iwl_write_direct32(priv, HBUS_TARG_WRPTR, 0 | (i << 8));
  608. /* Max Tx Window size for Scheduler-ACK mode */
  609. iwl_write_targ_mem(priv, priv->scd_base_addr +
  610. IWL49_SCD_CONTEXT_QUEUE_OFFSET(i),
  611. (SCD_WIN_SIZE <<
  612. IWL49_SCD_QUEUE_CTX_REG1_WIN_SIZE_POS) &
  613. IWL49_SCD_QUEUE_CTX_REG1_WIN_SIZE_MSK);
  614. /* Frame limit */
  615. iwl_write_targ_mem(priv, priv->scd_base_addr +
  616. IWL49_SCD_CONTEXT_QUEUE_OFFSET(i) +
  617. sizeof(u32),
  618. (SCD_FRAME_LIMIT <<
  619. IWL49_SCD_QUEUE_CTX_REG2_FRAME_LIMIT_POS) &
  620. IWL49_SCD_QUEUE_CTX_REG2_FRAME_LIMIT_MSK);
  621. }
  622. iwl_write_prph(priv, IWL49_SCD_INTERRUPT_MASK,
  623. (1 << priv->hw_params.max_txq_num) - 1);
  624. /* Activate all Tx DMA/FIFO channels */
  625. priv->cfg->ops->lib->txq_set_sched(priv, IWL_MASK(0, 6));
  626. iwl4965_set_wr_ptrs(priv, IWL_CMD_QUEUE_NUM, 0);
  627. /* Map each Tx/cmd queue to its corresponding fifo */
  628. for (i = 0; i < ARRAY_SIZE(default_queue_to_tx_fifo); i++) {
  629. int ac = default_queue_to_tx_fifo[i];
  630. iwl_txq_ctx_activate(priv, i);
  631. iwl4965_tx_queue_set_status(priv, &priv->txq[i], ac, 0);
  632. }
  633. iwl_release_nic_access(priv);
  634. spin_unlock_irqrestore(&priv->lock, flags);
  635. return ret;
  636. }
  637. static struct iwl_sensitivity_ranges iwl4965_sensitivity = {
  638. .min_nrg_cck = 97,
  639. .max_nrg_cck = 0,
  640. .auto_corr_min_ofdm = 85,
  641. .auto_corr_min_ofdm_mrc = 170,
  642. .auto_corr_min_ofdm_x1 = 105,
  643. .auto_corr_min_ofdm_mrc_x1 = 220,
  644. .auto_corr_max_ofdm = 120,
  645. .auto_corr_max_ofdm_mrc = 210,
  646. .auto_corr_max_ofdm_x1 = 140,
  647. .auto_corr_max_ofdm_mrc_x1 = 270,
  648. .auto_corr_min_cck = 125,
  649. .auto_corr_max_cck = 200,
  650. .auto_corr_min_cck_mrc = 200,
  651. .auto_corr_max_cck_mrc = 400,
  652. .nrg_th_cck = 100,
  653. .nrg_th_ofdm = 100,
  654. };
  655. /**
  656. * iwl4965_hw_set_hw_params
  657. *
  658. * Called when initializing driver
  659. */
  660. static int iwl4965_hw_set_hw_params(struct iwl_priv *priv)
  661. {
  662. if ((priv->cfg->mod_params->num_of_queues > IWL49_NUM_QUEUES) ||
  663. (priv->cfg->mod_params->num_of_queues < IWL_MIN_NUM_QUEUES)) {
  664. IWL_ERROR("invalid queues_num, should be between %d and %d\n",
  665. IWL_MIN_NUM_QUEUES, IWL49_NUM_QUEUES);
  666. return -EINVAL;
  667. }
  668. priv->hw_params.max_txq_num = priv->cfg->mod_params->num_of_queues;
  669. priv->hw_params.dma_chnl_num = FH49_TCSR_CHNL_NUM;
  670. priv->hw_params.scd_bc_tbls_size =
  671. IWL49_NUM_QUEUES * sizeof(struct iwl4965_scd_bc_tbl);
  672. priv->hw_params.max_stations = IWL4965_STATION_COUNT;
  673. priv->hw_params.bcast_sta_id = IWL4965_BROADCAST_ID;
  674. priv->hw_params.max_data_size = IWL49_RTC_DATA_SIZE;
  675. priv->hw_params.max_inst_size = IWL49_RTC_INST_SIZE;
  676. priv->hw_params.max_bsm_size = BSM_SRAM_SIZE;
  677. priv->hw_params.fat_channel = BIT(IEEE80211_BAND_5GHZ);
  678. priv->hw_params.tx_chains_num = 2;
  679. priv->hw_params.rx_chains_num = 2;
  680. priv->hw_params.valid_tx_ant = ANT_A | ANT_B;
  681. priv->hw_params.valid_rx_ant = ANT_A | ANT_B;
  682. priv->hw_params.ct_kill_threshold = CELSIUS_TO_KELVIN(CT_KILL_THRESHOLD);
  683. priv->hw_params.sens = &iwl4965_sensitivity;
  684. return 0;
  685. }
  686. static s32 iwl4965_math_div_round(s32 num, s32 denom, s32 *res)
  687. {
  688. s32 sign = 1;
  689. if (num < 0) {
  690. sign = -sign;
  691. num = -num;
  692. }
  693. if (denom < 0) {
  694. sign = -sign;
  695. denom = -denom;
  696. }
  697. *res = 1;
  698. *res = ((num * 2 + denom) / (denom * 2)) * sign;
  699. return 1;
  700. }
  701. /**
  702. * iwl4965_get_voltage_compensation - Power supply voltage comp for txpower
  703. *
  704. * Determines power supply voltage compensation for txpower calculations.
  705. * Returns number of 1/2-dB steps to subtract from gain table index,
  706. * to compensate for difference between power supply voltage during
  707. * factory measurements, vs. current power supply voltage.
  708. *
  709. * Voltage indication is higher for lower voltage.
  710. * Lower voltage requires more gain (lower gain table index).
  711. */
  712. static s32 iwl4965_get_voltage_compensation(s32 eeprom_voltage,
  713. s32 current_voltage)
  714. {
  715. s32 comp = 0;
  716. if ((TX_POWER_IWL_ILLEGAL_VOLTAGE == eeprom_voltage) ||
  717. (TX_POWER_IWL_ILLEGAL_VOLTAGE == current_voltage))
  718. return 0;
  719. iwl4965_math_div_round(current_voltage - eeprom_voltage,
  720. TX_POWER_IWL_VOLTAGE_CODES_PER_03V, &comp);
  721. if (current_voltage > eeprom_voltage)
  722. comp *= 2;
  723. if ((comp < -2) || (comp > 2))
  724. comp = 0;
  725. return comp;
  726. }
  727. static s32 iwl4965_get_tx_atten_grp(u16 channel)
  728. {
  729. if (channel >= CALIB_IWL_TX_ATTEN_GR5_FCH &&
  730. channel <= CALIB_IWL_TX_ATTEN_GR5_LCH)
  731. return CALIB_CH_GROUP_5;
  732. if (channel >= CALIB_IWL_TX_ATTEN_GR1_FCH &&
  733. channel <= CALIB_IWL_TX_ATTEN_GR1_LCH)
  734. return CALIB_CH_GROUP_1;
  735. if (channel >= CALIB_IWL_TX_ATTEN_GR2_FCH &&
  736. channel <= CALIB_IWL_TX_ATTEN_GR2_LCH)
  737. return CALIB_CH_GROUP_2;
  738. if (channel >= CALIB_IWL_TX_ATTEN_GR3_FCH &&
  739. channel <= CALIB_IWL_TX_ATTEN_GR3_LCH)
  740. return CALIB_CH_GROUP_3;
  741. if (channel >= CALIB_IWL_TX_ATTEN_GR4_FCH &&
  742. channel <= CALIB_IWL_TX_ATTEN_GR4_LCH)
  743. return CALIB_CH_GROUP_4;
  744. return -1;
  745. }
  746. static u32 iwl4965_get_sub_band(const struct iwl_priv *priv, u32 channel)
  747. {
  748. s32 b = -1;
  749. for (b = 0; b < EEPROM_TX_POWER_BANDS; b++) {
  750. if (priv->calib_info->band_info[b].ch_from == 0)
  751. continue;
  752. if ((channel >= priv->calib_info->band_info[b].ch_from)
  753. && (channel <= priv->calib_info->band_info[b].ch_to))
  754. break;
  755. }
  756. return b;
  757. }
  758. static s32 iwl4965_interpolate_value(s32 x, s32 x1, s32 y1, s32 x2, s32 y2)
  759. {
  760. s32 val;
  761. if (x2 == x1)
  762. return y1;
  763. else {
  764. iwl4965_math_div_round((x2 - x) * (y1 - y2), (x2 - x1), &val);
  765. return val + y2;
  766. }
  767. }
  768. /**
  769. * iwl4965_interpolate_chan - Interpolate factory measurements for one channel
  770. *
  771. * Interpolates factory measurements from the two sample channels within a
  772. * sub-band, to apply to channel of interest. Interpolation is proportional to
  773. * differences in channel frequencies, which is proportional to differences
  774. * in channel number.
  775. */
  776. static int iwl4965_interpolate_chan(struct iwl_priv *priv, u32 channel,
  777. struct iwl_eeprom_calib_ch_info *chan_info)
  778. {
  779. s32 s = -1;
  780. u32 c;
  781. u32 m;
  782. const struct iwl_eeprom_calib_measure *m1;
  783. const struct iwl_eeprom_calib_measure *m2;
  784. struct iwl_eeprom_calib_measure *omeas;
  785. u32 ch_i1;
  786. u32 ch_i2;
  787. s = iwl4965_get_sub_band(priv, channel);
  788. if (s >= EEPROM_TX_POWER_BANDS) {
  789. IWL_ERROR("Tx Power can not find channel %d\n", channel);
  790. return -1;
  791. }
  792. ch_i1 = priv->calib_info->band_info[s].ch1.ch_num;
  793. ch_i2 = priv->calib_info->band_info[s].ch2.ch_num;
  794. chan_info->ch_num = (u8) channel;
  795. IWL_DEBUG_TXPOWER("channel %d subband %d factory cal ch %d & %d\n",
  796. channel, s, ch_i1, ch_i2);
  797. for (c = 0; c < EEPROM_TX_POWER_TX_CHAINS; c++) {
  798. for (m = 0; m < EEPROM_TX_POWER_MEASUREMENTS; m++) {
  799. m1 = &(priv->calib_info->band_info[s].ch1.
  800. measurements[c][m]);
  801. m2 = &(priv->calib_info->band_info[s].ch2.
  802. measurements[c][m]);
  803. omeas = &(chan_info->measurements[c][m]);
  804. omeas->actual_pow =
  805. (u8) iwl4965_interpolate_value(channel, ch_i1,
  806. m1->actual_pow,
  807. ch_i2,
  808. m2->actual_pow);
  809. omeas->gain_idx =
  810. (u8) iwl4965_interpolate_value(channel, ch_i1,
  811. m1->gain_idx, ch_i2,
  812. m2->gain_idx);
  813. omeas->temperature =
  814. (u8) iwl4965_interpolate_value(channel, ch_i1,
  815. m1->temperature,
  816. ch_i2,
  817. m2->temperature);
  818. omeas->pa_det =
  819. (s8) iwl4965_interpolate_value(channel, ch_i1,
  820. m1->pa_det, ch_i2,
  821. m2->pa_det);
  822. IWL_DEBUG_TXPOWER
  823. ("chain %d meas %d AP1=%d AP2=%d AP=%d\n", c, m,
  824. m1->actual_pow, m2->actual_pow, omeas->actual_pow);
  825. IWL_DEBUG_TXPOWER
  826. ("chain %d meas %d NI1=%d NI2=%d NI=%d\n", c, m,
  827. m1->gain_idx, m2->gain_idx, omeas->gain_idx);
  828. IWL_DEBUG_TXPOWER
  829. ("chain %d meas %d PA1=%d PA2=%d PA=%d\n", c, m,
  830. m1->pa_det, m2->pa_det, omeas->pa_det);
  831. IWL_DEBUG_TXPOWER
  832. ("chain %d meas %d T1=%d T2=%d T=%d\n", c, m,
  833. m1->temperature, m2->temperature,
  834. omeas->temperature);
  835. }
  836. }
  837. return 0;
  838. }
  839. /* bit-rate-dependent table to prevent Tx distortion, in half-dB units,
  840. * for OFDM 6, 12, 18, 24, 36, 48, 54, 60 MBit, and CCK all rates. */
  841. static s32 back_off_table[] = {
  842. 10, 10, 10, 10, 10, 15, 17, 20, /* OFDM SISO 20 MHz */
  843. 10, 10, 10, 10, 10, 15, 17, 20, /* OFDM MIMO 20 MHz */
  844. 10, 10, 10, 10, 10, 15, 17, 20, /* OFDM SISO 40 MHz */
  845. 10, 10, 10, 10, 10, 15, 17, 20, /* OFDM MIMO 40 MHz */
  846. 10 /* CCK */
  847. };
  848. /* Thermal compensation values for txpower for various frequency ranges ...
  849. * ratios from 3:1 to 4.5:1 of degrees (Celsius) per half-dB gain adjust */
  850. static struct iwl4965_txpower_comp_entry {
  851. s32 degrees_per_05db_a;
  852. s32 degrees_per_05db_a_denom;
  853. } tx_power_cmp_tble[CALIB_CH_GROUP_MAX] = {
  854. {9, 2}, /* group 0 5.2, ch 34-43 */
  855. {4, 1}, /* group 1 5.2, ch 44-70 */
  856. {4, 1}, /* group 2 5.2, ch 71-124 */
  857. {4, 1}, /* group 3 5.2, ch 125-200 */
  858. {3, 1} /* group 4 2.4, ch all */
  859. };
  860. static s32 get_min_power_index(s32 rate_power_index, u32 band)
  861. {
  862. if (!band) {
  863. if ((rate_power_index & 7) <= 4)
  864. return MIN_TX_GAIN_INDEX_52GHZ_EXT;
  865. }
  866. return MIN_TX_GAIN_INDEX;
  867. }
  868. struct gain_entry {
  869. u8 dsp;
  870. u8 radio;
  871. };
  872. static const struct gain_entry gain_table[2][108] = {
  873. /* 5.2GHz power gain index table */
  874. {
  875. {123, 0x3F}, /* highest txpower */
  876. {117, 0x3F},
  877. {110, 0x3F},
  878. {104, 0x3F},
  879. {98, 0x3F},
  880. {110, 0x3E},
  881. {104, 0x3E},
  882. {98, 0x3E},
  883. {110, 0x3D},
  884. {104, 0x3D},
  885. {98, 0x3D},
  886. {110, 0x3C},
  887. {104, 0x3C},
  888. {98, 0x3C},
  889. {110, 0x3B},
  890. {104, 0x3B},
  891. {98, 0x3B},
  892. {110, 0x3A},
  893. {104, 0x3A},
  894. {98, 0x3A},
  895. {110, 0x39},
  896. {104, 0x39},
  897. {98, 0x39},
  898. {110, 0x38},
  899. {104, 0x38},
  900. {98, 0x38},
  901. {110, 0x37},
  902. {104, 0x37},
  903. {98, 0x37},
  904. {110, 0x36},
  905. {104, 0x36},
  906. {98, 0x36},
  907. {110, 0x35},
  908. {104, 0x35},
  909. {98, 0x35},
  910. {110, 0x34},
  911. {104, 0x34},
  912. {98, 0x34},
  913. {110, 0x33},
  914. {104, 0x33},
  915. {98, 0x33},
  916. {110, 0x32},
  917. {104, 0x32},
  918. {98, 0x32},
  919. {110, 0x31},
  920. {104, 0x31},
  921. {98, 0x31},
  922. {110, 0x30},
  923. {104, 0x30},
  924. {98, 0x30},
  925. {110, 0x25},
  926. {104, 0x25},
  927. {98, 0x25},
  928. {110, 0x24},
  929. {104, 0x24},
  930. {98, 0x24},
  931. {110, 0x23},
  932. {104, 0x23},
  933. {98, 0x23},
  934. {110, 0x22},
  935. {104, 0x18},
  936. {98, 0x18},
  937. {110, 0x17},
  938. {104, 0x17},
  939. {98, 0x17},
  940. {110, 0x16},
  941. {104, 0x16},
  942. {98, 0x16},
  943. {110, 0x15},
  944. {104, 0x15},
  945. {98, 0x15},
  946. {110, 0x14},
  947. {104, 0x14},
  948. {98, 0x14},
  949. {110, 0x13},
  950. {104, 0x13},
  951. {98, 0x13},
  952. {110, 0x12},
  953. {104, 0x08},
  954. {98, 0x08},
  955. {110, 0x07},
  956. {104, 0x07},
  957. {98, 0x07},
  958. {110, 0x06},
  959. {104, 0x06},
  960. {98, 0x06},
  961. {110, 0x05},
  962. {104, 0x05},
  963. {98, 0x05},
  964. {110, 0x04},
  965. {104, 0x04},
  966. {98, 0x04},
  967. {110, 0x03},
  968. {104, 0x03},
  969. {98, 0x03},
  970. {110, 0x02},
  971. {104, 0x02},
  972. {98, 0x02},
  973. {110, 0x01},
  974. {104, 0x01},
  975. {98, 0x01},
  976. {110, 0x00},
  977. {104, 0x00},
  978. {98, 0x00},
  979. {93, 0x00},
  980. {88, 0x00},
  981. {83, 0x00},
  982. {78, 0x00},
  983. },
  984. /* 2.4GHz power gain index table */
  985. {
  986. {110, 0x3f}, /* highest txpower */
  987. {104, 0x3f},
  988. {98, 0x3f},
  989. {110, 0x3e},
  990. {104, 0x3e},
  991. {98, 0x3e},
  992. {110, 0x3d},
  993. {104, 0x3d},
  994. {98, 0x3d},
  995. {110, 0x3c},
  996. {104, 0x3c},
  997. {98, 0x3c},
  998. {110, 0x3b},
  999. {104, 0x3b},
  1000. {98, 0x3b},
  1001. {110, 0x3a},
  1002. {104, 0x3a},
  1003. {98, 0x3a},
  1004. {110, 0x39},
  1005. {104, 0x39},
  1006. {98, 0x39},
  1007. {110, 0x38},
  1008. {104, 0x38},
  1009. {98, 0x38},
  1010. {110, 0x37},
  1011. {104, 0x37},
  1012. {98, 0x37},
  1013. {110, 0x36},
  1014. {104, 0x36},
  1015. {98, 0x36},
  1016. {110, 0x35},
  1017. {104, 0x35},
  1018. {98, 0x35},
  1019. {110, 0x34},
  1020. {104, 0x34},
  1021. {98, 0x34},
  1022. {110, 0x33},
  1023. {104, 0x33},
  1024. {98, 0x33},
  1025. {110, 0x32},
  1026. {104, 0x32},
  1027. {98, 0x32},
  1028. {110, 0x31},
  1029. {104, 0x31},
  1030. {98, 0x31},
  1031. {110, 0x30},
  1032. {104, 0x30},
  1033. {98, 0x30},
  1034. {110, 0x6},
  1035. {104, 0x6},
  1036. {98, 0x6},
  1037. {110, 0x5},
  1038. {104, 0x5},
  1039. {98, 0x5},
  1040. {110, 0x4},
  1041. {104, 0x4},
  1042. {98, 0x4},
  1043. {110, 0x3},
  1044. {104, 0x3},
  1045. {98, 0x3},
  1046. {110, 0x2},
  1047. {104, 0x2},
  1048. {98, 0x2},
  1049. {110, 0x1},
  1050. {104, 0x1},
  1051. {98, 0x1},
  1052. {110, 0x0},
  1053. {104, 0x0},
  1054. {98, 0x0},
  1055. {97, 0},
  1056. {96, 0},
  1057. {95, 0},
  1058. {94, 0},
  1059. {93, 0},
  1060. {92, 0},
  1061. {91, 0},
  1062. {90, 0},
  1063. {89, 0},
  1064. {88, 0},
  1065. {87, 0},
  1066. {86, 0},
  1067. {85, 0},
  1068. {84, 0},
  1069. {83, 0},
  1070. {82, 0},
  1071. {81, 0},
  1072. {80, 0},
  1073. {79, 0},
  1074. {78, 0},
  1075. {77, 0},
  1076. {76, 0},
  1077. {75, 0},
  1078. {74, 0},
  1079. {73, 0},
  1080. {72, 0},
  1081. {71, 0},
  1082. {70, 0},
  1083. {69, 0},
  1084. {68, 0},
  1085. {67, 0},
  1086. {66, 0},
  1087. {65, 0},
  1088. {64, 0},
  1089. {63, 0},
  1090. {62, 0},
  1091. {61, 0},
  1092. {60, 0},
  1093. {59, 0},
  1094. }
  1095. };
  1096. static int iwl4965_fill_txpower_tbl(struct iwl_priv *priv, u8 band, u16 channel,
  1097. u8 is_fat, u8 ctrl_chan_high,
  1098. struct iwl4965_tx_power_db *tx_power_tbl)
  1099. {
  1100. u8 saturation_power;
  1101. s32 target_power;
  1102. s32 user_target_power;
  1103. s32 power_limit;
  1104. s32 current_temp;
  1105. s32 reg_limit;
  1106. s32 current_regulatory;
  1107. s32 txatten_grp = CALIB_CH_GROUP_MAX;
  1108. int i;
  1109. int c;
  1110. const struct iwl_channel_info *ch_info = NULL;
  1111. struct iwl_eeprom_calib_ch_info ch_eeprom_info;
  1112. const struct iwl_eeprom_calib_measure *measurement;
  1113. s16 voltage;
  1114. s32 init_voltage;
  1115. s32 voltage_compensation;
  1116. s32 degrees_per_05db_num;
  1117. s32 degrees_per_05db_denom;
  1118. s32 factory_temp;
  1119. s32 temperature_comp[2];
  1120. s32 factory_gain_index[2];
  1121. s32 factory_actual_pwr[2];
  1122. s32 power_index;
  1123. /* user_txpower_limit is in dBm, convert to half-dBm (half-dB units
  1124. * are used for indexing into txpower table) */
  1125. user_target_power = 2 * priv->tx_power_user_lmt;
  1126. /* Get current (RXON) channel, band, width */
  1127. IWL_DEBUG_TXPOWER("chan %d band %d is_fat %d\n", channel, band,
  1128. is_fat);
  1129. ch_info = iwl_get_channel_info(priv, priv->band, channel);
  1130. if (!is_channel_valid(ch_info))
  1131. return -EINVAL;
  1132. /* get txatten group, used to select 1) thermal txpower adjustment
  1133. * and 2) mimo txpower balance between Tx chains. */
  1134. txatten_grp = iwl4965_get_tx_atten_grp(channel);
  1135. if (txatten_grp < 0) {
  1136. IWL_ERROR("Can't find txatten group for channel %d.\n",
  1137. channel);
  1138. return -EINVAL;
  1139. }
  1140. IWL_DEBUG_TXPOWER("channel %d belongs to txatten group %d\n",
  1141. channel, txatten_grp);
  1142. if (is_fat) {
  1143. if (ctrl_chan_high)
  1144. channel -= 2;
  1145. else
  1146. channel += 2;
  1147. }
  1148. /* hardware txpower limits ...
  1149. * saturation (clipping distortion) txpowers are in half-dBm */
  1150. if (band)
  1151. saturation_power = priv->calib_info->saturation_power24;
  1152. else
  1153. saturation_power = priv->calib_info->saturation_power52;
  1154. if (saturation_power < IWL_TX_POWER_SATURATION_MIN ||
  1155. saturation_power > IWL_TX_POWER_SATURATION_MAX) {
  1156. if (band)
  1157. saturation_power = IWL_TX_POWER_DEFAULT_SATURATION_24;
  1158. else
  1159. saturation_power = IWL_TX_POWER_DEFAULT_SATURATION_52;
  1160. }
  1161. /* regulatory txpower limits ... reg_limit values are in half-dBm,
  1162. * max_power_avg values are in dBm, convert * 2 */
  1163. if (is_fat)
  1164. reg_limit = ch_info->fat_max_power_avg * 2;
  1165. else
  1166. reg_limit = ch_info->max_power_avg * 2;
  1167. if ((reg_limit < IWL_TX_POWER_REGULATORY_MIN) ||
  1168. (reg_limit > IWL_TX_POWER_REGULATORY_MAX)) {
  1169. if (band)
  1170. reg_limit = IWL_TX_POWER_DEFAULT_REGULATORY_24;
  1171. else
  1172. reg_limit = IWL_TX_POWER_DEFAULT_REGULATORY_52;
  1173. }
  1174. /* Interpolate txpower calibration values for this channel,
  1175. * based on factory calibration tests on spaced channels. */
  1176. iwl4965_interpolate_chan(priv, channel, &ch_eeprom_info);
  1177. /* calculate tx gain adjustment based on power supply voltage */
  1178. voltage = priv->calib_info->voltage;
  1179. init_voltage = (s32)le32_to_cpu(priv->card_alive_init.voltage);
  1180. voltage_compensation =
  1181. iwl4965_get_voltage_compensation(voltage, init_voltage);
  1182. IWL_DEBUG_TXPOWER("curr volt %d eeprom volt %d volt comp %d\n",
  1183. init_voltage,
  1184. voltage, voltage_compensation);
  1185. /* get current temperature (Celsius) */
  1186. current_temp = max(priv->temperature, IWL_TX_POWER_TEMPERATURE_MIN);
  1187. current_temp = min(priv->temperature, IWL_TX_POWER_TEMPERATURE_MAX);
  1188. current_temp = KELVIN_TO_CELSIUS(current_temp);
  1189. /* select thermal txpower adjustment params, based on channel group
  1190. * (same frequency group used for mimo txatten adjustment) */
  1191. degrees_per_05db_num =
  1192. tx_power_cmp_tble[txatten_grp].degrees_per_05db_a;
  1193. degrees_per_05db_denom =
  1194. tx_power_cmp_tble[txatten_grp].degrees_per_05db_a_denom;
  1195. /* get per-chain txpower values from factory measurements */
  1196. for (c = 0; c < 2; c++) {
  1197. measurement = &ch_eeprom_info.measurements[c][1];
  1198. /* txgain adjustment (in half-dB steps) based on difference
  1199. * between factory and current temperature */
  1200. factory_temp = measurement->temperature;
  1201. iwl4965_math_div_round((current_temp - factory_temp) *
  1202. degrees_per_05db_denom,
  1203. degrees_per_05db_num,
  1204. &temperature_comp[c]);
  1205. factory_gain_index[c] = measurement->gain_idx;
  1206. factory_actual_pwr[c] = measurement->actual_pow;
  1207. IWL_DEBUG_TXPOWER("chain = %d\n", c);
  1208. IWL_DEBUG_TXPOWER("fctry tmp %d, "
  1209. "curr tmp %d, comp %d steps\n",
  1210. factory_temp, current_temp,
  1211. temperature_comp[c]);
  1212. IWL_DEBUG_TXPOWER("fctry idx %d, fctry pwr %d\n",
  1213. factory_gain_index[c],
  1214. factory_actual_pwr[c]);
  1215. }
  1216. /* for each of 33 bit-rates (including 1 for CCK) */
  1217. for (i = 0; i < POWER_TABLE_NUM_ENTRIES; i++) {
  1218. u8 is_mimo_rate;
  1219. union iwl4965_tx_power_dual_stream tx_power;
  1220. /* for mimo, reduce each chain's txpower by half
  1221. * (3dB, 6 steps), so total output power is regulatory
  1222. * compliant. */
  1223. if (i & 0x8) {
  1224. current_regulatory = reg_limit -
  1225. IWL_TX_POWER_MIMO_REGULATORY_COMPENSATION;
  1226. is_mimo_rate = 1;
  1227. } else {
  1228. current_regulatory = reg_limit;
  1229. is_mimo_rate = 0;
  1230. }
  1231. /* find txpower limit, either hardware or regulatory */
  1232. power_limit = saturation_power - back_off_table[i];
  1233. if (power_limit > current_regulatory)
  1234. power_limit = current_regulatory;
  1235. /* reduce user's txpower request if necessary
  1236. * for this rate on this channel */
  1237. target_power = user_target_power;
  1238. if (target_power > power_limit)
  1239. target_power = power_limit;
  1240. IWL_DEBUG_TXPOWER("rate %d sat %d reg %d usr %d tgt %d\n",
  1241. i, saturation_power - back_off_table[i],
  1242. current_regulatory, user_target_power,
  1243. target_power);
  1244. /* for each of 2 Tx chains (radio transmitters) */
  1245. for (c = 0; c < 2; c++) {
  1246. s32 atten_value;
  1247. if (is_mimo_rate)
  1248. atten_value =
  1249. (s32)le32_to_cpu(priv->card_alive_init.
  1250. tx_atten[txatten_grp][c]);
  1251. else
  1252. atten_value = 0;
  1253. /* calculate index; higher index means lower txpower */
  1254. power_index = (u8) (factory_gain_index[c] -
  1255. (target_power -
  1256. factory_actual_pwr[c]) -
  1257. temperature_comp[c] -
  1258. voltage_compensation +
  1259. atten_value);
  1260. /* IWL_DEBUG_TXPOWER("calculated txpower index %d\n",
  1261. power_index); */
  1262. if (power_index < get_min_power_index(i, band))
  1263. power_index = get_min_power_index(i, band);
  1264. /* adjust 5 GHz index to support negative indexes */
  1265. if (!band)
  1266. power_index += 9;
  1267. /* CCK, rate 32, reduce txpower for CCK */
  1268. if (i == POWER_TABLE_CCK_ENTRY)
  1269. power_index +=
  1270. IWL_TX_POWER_CCK_COMPENSATION_C_STEP;
  1271. /* stay within the table! */
  1272. if (power_index > 107) {
  1273. IWL_WARN(priv, "txpower index %d > 107\n",
  1274. power_index);
  1275. power_index = 107;
  1276. }
  1277. if (power_index < 0) {
  1278. IWL_WARN(priv, "txpower index %d < 0\n",
  1279. power_index);
  1280. power_index = 0;
  1281. }
  1282. /* fill txpower command for this rate/chain */
  1283. tx_power.s.radio_tx_gain[c] =
  1284. gain_table[band][power_index].radio;
  1285. tx_power.s.dsp_predis_atten[c] =
  1286. gain_table[band][power_index].dsp;
  1287. IWL_DEBUG_TXPOWER("chain %d mimo %d index %d "
  1288. "gain 0x%02x dsp %d\n",
  1289. c, atten_value, power_index,
  1290. tx_power.s.radio_tx_gain[c],
  1291. tx_power.s.dsp_predis_atten[c]);
  1292. } /* for each chain */
  1293. tx_power_tbl->power_tbl[i].dw = cpu_to_le32(tx_power.dw);
  1294. } /* for each rate */
  1295. return 0;
  1296. }
  1297. /**
  1298. * iwl4965_send_tx_power - Configure the TXPOWER level user limit
  1299. *
  1300. * Uses the active RXON for channel, band, and characteristics (fat, high)
  1301. * The power limit is taken from priv->tx_power_user_lmt.
  1302. */
  1303. static int iwl4965_send_tx_power(struct iwl_priv *priv)
  1304. {
  1305. struct iwl4965_txpowertable_cmd cmd = { 0 };
  1306. int ret;
  1307. u8 band = 0;
  1308. u8 is_fat = 0;
  1309. u8 ctrl_chan_high = 0;
  1310. if (test_bit(STATUS_SCANNING, &priv->status)) {
  1311. /* If this gets hit a lot, switch it to a BUG() and catch
  1312. * the stack trace to find out who is calling this during
  1313. * a scan. */
  1314. IWL_WARN(priv, "TX Power requested while scanning!\n");
  1315. return -EAGAIN;
  1316. }
  1317. band = priv->band == IEEE80211_BAND_2GHZ;
  1318. is_fat = is_fat_channel(priv->active_rxon.flags);
  1319. if (is_fat &&
  1320. (priv->active_rxon.flags & RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK))
  1321. ctrl_chan_high = 1;
  1322. cmd.band = band;
  1323. cmd.channel = priv->active_rxon.channel;
  1324. ret = iwl4965_fill_txpower_tbl(priv, band,
  1325. le16_to_cpu(priv->active_rxon.channel),
  1326. is_fat, ctrl_chan_high, &cmd.tx_power);
  1327. if (ret)
  1328. goto out;
  1329. ret = iwl_send_cmd_pdu(priv, REPLY_TX_PWR_TABLE_CMD, sizeof(cmd), &cmd);
  1330. out:
  1331. return ret;
  1332. }
  1333. static int iwl4965_send_rxon_assoc(struct iwl_priv *priv)
  1334. {
  1335. int ret = 0;
  1336. struct iwl4965_rxon_assoc_cmd rxon_assoc;
  1337. const struct iwl_rxon_cmd *rxon1 = &priv->staging_rxon;
  1338. const struct iwl_rxon_cmd *rxon2 = &priv->active_rxon;
  1339. if ((rxon1->flags == rxon2->flags) &&
  1340. (rxon1->filter_flags == rxon2->filter_flags) &&
  1341. (rxon1->cck_basic_rates == rxon2->cck_basic_rates) &&
  1342. (rxon1->ofdm_ht_single_stream_basic_rates ==
  1343. rxon2->ofdm_ht_single_stream_basic_rates) &&
  1344. (rxon1->ofdm_ht_dual_stream_basic_rates ==
  1345. rxon2->ofdm_ht_dual_stream_basic_rates) &&
  1346. (rxon1->rx_chain == rxon2->rx_chain) &&
  1347. (rxon1->ofdm_basic_rates == rxon2->ofdm_basic_rates)) {
  1348. IWL_DEBUG_INFO("Using current RXON_ASSOC. Not resending.\n");
  1349. return 0;
  1350. }
  1351. rxon_assoc.flags = priv->staging_rxon.flags;
  1352. rxon_assoc.filter_flags = priv->staging_rxon.filter_flags;
  1353. rxon_assoc.ofdm_basic_rates = priv->staging_rxon.ofdm_basic_rates;
  1354. rxon_assoc.cck_basic_rates = priv->staging_rxon.cck_basic_rates;
  1355. rxon_assoc.reserved = 0;
  1356. rxon_assoc.ofdm_ht_single_stream_basic_rates =
  1357. priv->staging_rxon.ofdm_ht_single_stream_basic_rates;
  1358. rxon_assoc.ofdm_ht_dual_stream_basic_rates =
  1359. priv->staging_rxon.ofdm_ht_dual_stream_basic_rates;
  1360. rxon_assoc.rx_chain_select_flags = priv->staging_rxon.rx_chain;
  1361. ret = iwl_send_cmd_pdu_async(priv, REPLY_RXON_ASSOC,
  1362. sizeof(rxon_assoc), &rxon_assoc, NULL);
  1363. if (ret)
  1364. return ret;
  1365. return ret;
  1366. }
  1367. #ifdef IEEE80211_CONF_CHANNEL_SWITCH
  1368. static int iwl4965_hw_channel_switch(struct iwl_priv *priv, u16 channel)
  1369. {
  1370. int rc;
  1371. u8 band = 0;
  1372. u8 is_fat = 0;
  1373. u8 ctrl_chan_high = 0;
  1374. struct iwl4965_channel_switch_cmd cmd = { 0 };
  1375. const struct iwl_channel_info *ch_info;
  1376. band = priv->band == IEEE80211_BAND_2GHZ;
  1377. ch_info = iwl_get_channel_info(priv, priv->band, channel);
  1378. is_fat = is_fat_channel(priv->staging_rxon.flags);
  1379. if (is_fat &&
  1380. (priv->active_rxon.flags & RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK))
  1381. ctrl_chan_high = 1;
  1382. cmd.band = band;
  1383. cmd.expect_beacon = 0;
  1384. cmd.channel = cpu_to_le16(channel);
  1385. cmd.rxon_flags = priv->active_rxon.flags;
  1386. cmd.rxon_filter_flags = priv->active_rxon.filter_flags;
  1387. cmd.switch_time = cpu_to_le32(priv->ucode_beacon_time);
  1388. if (ch_info)
  1389. cmd.expect_beacon = is_channel_radar(ch_info);
  1390. else
  1391. cmd.expect_beacon = 1;
  1392. rc = iwl4965_fill_txpower_tbl(priv, band, channel, is_fat,
  1393. ctrl_chan_high, &cmd.tx_power);
  1394. if (rc) {
  1395. IWL_DEBUG_11H("error:%d fill txpower_tbl\n", rc);
  1396. return rc;
  1397. }
  1398. rc = iwl_send_cmd_pdu(priv, REPLY_CHANNEL_SWITCH, sizeof(cmd), &cmd);
  1399. return rc;
  1400. }
  1401. #endif
  1402. /**
  1403. * iwl4965_txq_update_byte_cnt_tbl - Set up entry in Tx byte-count array
  1404. */
  1405. static void iwl4965_txq_update_byte_cnt_tbl(struct iwl_priv *priv,
  1406. struct iwl_tx_queue *txq,
  1407. u16 byte_cnt)
  1408. {
  1409. struct iwl4965_scd_bc_tbl *scd_bc_tbl = priv->scd_bc_tbls.addr;
  1410. int txq_id = txq->q.id;
  1411. int write_ptr = txq->q.write_ptr;
  1412. int len = byte_cnt + IWL_TX_CRC_SIZE + IWL_TX_DELIMITER_SIZE;
  1413. __le16 bc_ent;
  1414. WARN_ON(len > 0xFFF || write_ptr >= TFD_QUEUE_SIZE_MAX);
  1415. bc_ent = cpu_to_le16(len & 0xFFF);
  1416. /* Set up byte count within first 256 entries */
  1417. scd_bc_tbl[txq_id].tfd_offset[write_ptr] = bc_ent;
  1418. /* If within first 64 entries, duplicate at end */
  1419. if (write_ptr < TFD_QUEUE_SIZE_BC_DUP)
  1420. scd_bc_tbl[txq_id].
  1421. tfd_offset[TFD_QUEUE_SIZE_MAX + write_ptr] = bc_ent;
  1422. }
  1423. /**
  1424. * sign_extend - Sign extend a value using specified bit as sign-bit
  1425. *
  1426. * Example: sign_extend(9, 3) would return -7 as bit3 of 1001b is 1
  1427. * and bit0..2 is 001b which when sign extended to 1111111111111001b is -7.
  1428. *
  1429. * @param oper value to sign extend
  1430. * @param index 0 based bit index (0<=index<32) to sign bit
  1431. */
  1432. static s32 sign_extend(u32 oper, int index)
  1433. {
  1434. u8 shift = 31 - index;
  1435. return (s32)(oper << shift) >> shift;
  1436. }
  1437. /**
  1438. * iwl4965_hw_get_temperature - return the calibrated temperature (in Kelvin)
  1439. * @statistics: Provides the temperature reading from the uCode
  1440. *
  1441. * A return of <0 indicates bogus data in the statistics
  1442. */
  1443. static int iwl4965_hw_get_temperature(const struct iwl_priv *priv)
  1444. {
  1445. s32 temperature;
  1446. s32 vt;
  1447. s32 R1, R2, R3;
  1448. u32 R4;
  1449. if (test_bit(STATUS_TEMPERATURE, &priv->status) &&
  1450. (priv->statistics.flag & STATISTICS_REPLY_FLG_FAT_MODE_MSK)) {
  1451. IWL_DEBUG_TEMP("Running FAT temperature calibration\n");
  1452. R1 = (s32)le32_to_cpu(priv->card_alive_init.therm_r1[1]);
  1453. R2 = (s32)le32_to_cpu(priv->card_alive_init.therm_r2[1]);
  1454. R3 = (s32)le32_to_cpu(priv->card_alive_init.therm_r3[1]);
  1455. R4 = le32_to_cpu(priv->card_alive_init.therm_r4[1]);
  1456. } else {
  1457. IWL_DEBUG_TEMP("Running temperature calibration\n");
  1458. R1 = (s32)le32_to_cpu(priv->card_alive_init.therm_r1[0]);
  1459. R2 = (s32)le32_to_cpu(priv->card_alive_init.therm_r2[0]);
  1460. R3 = (s32)le32_to_cpu(priv->card_alive_init.therm_r3[0]);
  1461. R4 = le32_to_cpu(priv->card_alive_init.therm_r4[0]);
  1462. }
  1463. /*
  1464. * Temperature is only 23 bits, so sign extend out to 32.
  1465. *
  1466. * NOTE If we haven't received a statistics notification yet
  1467. * with an updated temperature, use R4 provided to us in the
  1468. * "initialize" ALIVE response.
  1469. */
  1470. if (!test_bit(STATUS_TEMPERATURE, &priv->status))
  1471. vt = sign_extend(R4, 23);
  1472. else
  1473. vt = sign_extend(
  1474. le32_to_cpu(priv->statistics.general.temperature), 23);
  1475. IWL_DEBUG_TEMP("Calib values R[1-3]: %d %d %d R4: %d\n", R1, R2, R3, vt);
  1476. if (R3 == R1) {
  1477. IWL_ERROR("Calibration conflict R1 == R3\n");
  1478. return -1;
  1479. }
  1480. /* Calculate temperature in degrees Kelvin, adjust by 97%.
  1481. * Add offset to center the adjustment around 0 degrees Centigrade. */
  1482. temperature = TEMPERATURE_CALIB_A_VAL * (vt - R2);
  1483. temperature /= (R3 - R1);
  1484. temperature = (temperature * 97) / 100 + TEMPERATURE_CALIB_KELVIN_OFFSET;
  1485. IWL_DEBUG_TEMP("Calibrated temperature: %dK, %dC\n",
  1486. temperature, KELVIN_TO_CELSIUS(temperature));
  1487. return temperature;
  1488. }
  1489. /* Adjust Txpower only if temperature variance is greater than threshold. */
  1490. #define IWL_TEMPERATURE_THRESHOLD 3
  1491. /**
  1492. * iwl4965_is_temp_calib_needed - determines if new calibration is needed
  1493. *
  1494. * If the temperature changed has changed sufficiently, then a recalibration
  1495. * is needed.
  1496. *
  1497. * Assumes caller will replace priv->last_temperature once calibration
  1498. * executed.
  1499. */
  1500. static int iwl4965_is_temp_calib_needed(struct iwl_priv *priv)
  1501. {
  1502. int temp_diff;
  1503. if (!test_bit(STATUS_STATISTICS, &priv->status)) {
  1504. IWL_DEBUG_TEMP("Temperature not updated -- no statistics.\n");
  1505. return 0;
  1506. }
  1507. temp_diff = priv->temperature - priv->last_temperature;
  1508. /* get absolute value */
  1509. if (temp_diff < 0) {
  1510. IWL_DEBUG_POWER("Getting cooler, delta %d, \n", temp_diff);
  1511. temp_diff = -temp_diff;
  1512. } else if (temp_diff == 0)
  1513. IWL_DEBUG_POWER("Same temp, \n");
  1514. else
  1515. IWL_DEBUG_POWER("Getting warmer, delta %d, \n", temp_diff);
  1516. if (temp_diff < IWL_TEMPERATURE_THRESHOLD) {
  1517. IWL_DEBUG_POWER("Thermal txpower calib not needed\n");
  1518. return 0;
  1519. }
  1520. IWL_DEBUG_POWER("Thermal txpower calib needed\n");
  1521. return 1;
  1522. }
  1523. static void iwl4965_temperature_calib(struct iwl_priv *priv)
  1524. {
  1525. s32 temp;
  1526. temp = iwl4965_hw_get_temperature(priv);
  1527. if (temp < 0)
  1528. return;
  1529. if (priv->temperature != temp) {
  1530. if (priv->temperature)
  1531. IWL_DEBUG_TEMP("Temperature changed "
  1532. "from %dC to %dC\n",
  1533. KELVIN_TO_CELSIUS(priv->temperature),
  1534. KELVIN_TO_CELSIUS(temp));
  1535. else
  1536. IWL_DEBUG_TEMP("Temperature "
  1537. "initialized to %dC\n",
  1538. KELVIN_TO_CELSIUS(temp));
  1539. }
  1540. priv->temperature = temp;
  1541. set_bit(STATUS_TEMPERATURE, &priv->status);
  1542. if (!priv->disable_tx_power_cal &&
  1543. unlikely(!test_bit(STATUS_SCANNING, &priv->status)) &&
  1544. iwl4965_is_temp_calib_needed(priv))
  1545. queue_work(priv->workqueue, &priv->txpower_work);
  1546. }
  1547. /**
  1548. * iwl4965_tx_queue_stop_scheduler - Stop queue, but keep configuration
  1549. */
  1550. static void iwl4965_tx_queue_stop_scheduler(struct iwl_priv *priv,
  1551. u16 txq_id)
  1552. {
  1553. /* Simply stop the queue, but don't change any configuration;
  1554. * the SCD_ACT_EN bit is the write-enable mask for the ACTIVE bit. */
  1555. iwl_write_prph(priv,
  1556. IWL49_SCD_QUEUE_STATUS_BITS(txq_id),
  1557. (0 << IWL49_SCD_QUEUE_STTS_REG_POS_ACTIVE)|
  1558. (1 << IWL49_SCD_QUEUE_STTS_REG_POS_SCD_ACT_EN));
  1559. }
  1560. /**
  1561. * txq_id must be greater than IWL49_FIRST_AMPDU_QUEUE
  1562. * priv->lock must be held by the caller
  1563. */
  1564. static int iwl4965_txq_agg_disable(struct iwl_priv *priv, u16 txq_id,
  1565. u16 ssn_idx, u8 tx_fifo)
  1566. {
  1567. int ret = 0;
  1568. if ((IWL49_FIRST_AMPDU_QUEUE > txq_id) ||
  1569. (IWL49_FIRST_AMPDU_QUEUE + IWL49_NUM_AMPDU_QUEUES <= txq_id)) {
  1570. IWL_WARN(priv,
  1571. "queue number out of range: %d, must be %d to %d\n",
  1572. txq_id, IWL49_FIRST_AMPDU_QUEUE,
  1573. IWL49_FIRST_AMPDU_QUEUE + IWL49_NUM_AMPDU_QUEUES - 1);
  1574. return -EINVAL;
  1575. }
  1576. ret = iwl_grab_nic_access(priv);
  1577. if (ret)
  1578. return ret;
  1579. iwl4965_tx_queue_stop_scheduler(priv, txq_id);
  1580. iwl_clear_bits_prph(priv, IWL49_SCD_QUEUECHAIN_SEL, (1 << txq_id));
  1581. priv->txq[txq_id].q.read_ptr = (ssn_idx & 0xff);
  1582. priv->txq[txq_id].q.write_ptr = (ssn_idx & 0xff);
  1583. /* supposes that ssn_idx is valid (!= 0xFFF) */
  1584. iwl4965_set_wr_ptrs(priv, txq_id, ssn_idx);
  1585. iwl_clear_bits_prph(priv, IWL49_SCD_INTERRUPT_MASK, (1 << txq_id));
  1586. iwl_txq_ctx_deactivate(priv, txq_id);
  1587. iwl4965_tx_queue_set_status(priv, &priv->txq[txq_id], tx_fifo, 0);
  1588. iwl_release_nic_access(priv);
  1589. return 0;
  1590. }
  1591. /**
  1592. * iwl4965_tx_queue_set_q2ratid - Map unique receiver/tid combination to a queue
  1593. */
  1594. static int iwl4965_tx_queue_set_q2ratid(struct iwl_priv *priv, u16 ra_tid,
  1595. u16 txq_id)
  1596. {
  1597. u32 tbl_dw_addr;
  1598. u32 tbl_dw;
  1599. u16 scd_q2ratid;
  1600. scd_q2ratid = ra_tid & IWL_SCD_QUEUE_RA_TID_MAP_RATID_MSK;
  1601. tbl_dw_addr = priv->scd_base_addr +
  1602. IWL49_SCD_TRANSLATE_TBL_OFFSET_QUEUE(txq_id);
  1603. tbl_dw = iwl_read_targ_mem(priv, tbl_dw_addr);
  1604. if (txq_id & 0x1)
  1605. tbl_dw = (scd_q2ratid << 16) | (tbl_dw & 0x0000FFFF);
  1606. else
  1607. tbl_dw = scd_q2ratid | (tbl_dw & 0xFFFF0000);
  1608. iwl_write_targ_mem(priv, tbl_dw_addr, tbl_dw);
  1609. return 0;
  1610. }
  1611. /**
  1612. * iwl4965_tx_queue_agg_enable - Set up & enable aggregation for selected queue
  1613. *
  1614. * NOTE: txq_id must be greater than IWL49_FIRST_AMPDU_QUEUE,
  1615. * i.e. it must be one of the higher queues used for aggregation
  1616. */
  1617. static int iwl4965_txq_agg_enable(struct iwl_priv *priv, int txq_id,
  1618. int tx_fifo, int sta_id, int tid, u16 ssn_idx)
  1619. {
  1620. unsigned long flags;
  1621. int ret;
  1622. u16 ra_tid;
  1623. if ((IWL49_FIRST_AMPDU_QUEUE > txq_id) ||
  1624. (IWL49_FIRST_AMPDU_QUEUE + IWL49_NUM_AMPDU_QUEUES <= txq_id)) {
  1625. IWL_WARN(priv,
  1626. "queue number out of range: %d, must be %d to %d\n",
  1627. txq_id, IWL49_FIRST_AMPDU_QUEUE,
  1628. IWL49_FIRST_AMPDU_QUEUE + IWL49_NUM_AMPDU_QUEUES - 1);
  1629. return -EINVAL;
  1630. }
  1631. ra_tid = BUILD_RAxTID(sta_id, tid);
  1632. /* Modify device's station table to Tx this TID */
  1633. iwl_sta_tx_modify_enable_tid(priv, sta_id, tid);
  1634. spin_lock_irqsave(&priv->lock, flags);
  1635. ret = iwl_grab_nic_access(priv);
  1636. if (ret) {
  1637. spin_unlock_irqrestore(&priv->lock, flags);
  1638. return ret;
  1639. }
  1640. /* Stop this Tx queue before configuring it */
  1641. iwl4965_tx_queue_stop_scheduler(priv, txq_id);
  1642. /* Map receiver-address / traffic-ID to this queue */
  1643. iwl4965_tx_queue_set_q2ratid(priv, ra_tid, txq_id);
  1644. /* Set this queue as a chain-building queue */
  1645. iwl_set_bits_prph(priv, IWL49_SCD_QUEUECHAIN_SEL, (1 << txq_id));
  1646. /* Place first TFD at index corresponding to start sequence number.
  1647. * Assumes that ssn_idx is valid (!= 0xFFF) */
  1648. priv->txq[txq_id].q.read_ptr = (ssn_idx & 0xff);
  1649. priv->txq[txq_id].q.write_ptr = (ssn_idx & 0xff);
  1650. iwl4965_set_wr_ptrs(priv, txq_id, ssn_idx);
  1651. /* Set up Tx window size and frame limit for this queue */
  1652. iwl_write_targ_mem(priv,
  1653. priv->scd_base_addr + IWL49_SCD_CONTEXT_QUEUE_OFFSET(txq_id),
  1654. (SCD_WIN_SIZE << IWL49_SCD_QUEUE_CTX_REG1_WIN_SIZE_POS) &
  1655. IWL49_SCD_QUEUE_CTX_REG1_WIN_SIZE_MSK);
  1656. iwl_write_targ_mem(priv, priv->scd_base_addr +
  1657. IWL49_SCD_CONTEXT_QUEUE_OFFSET(txq_id) + sizeof(u32),
  1658. (SCD_FRAME_LIMIT << IWL49_SCD_QUEUE_CTX_REG2_FRAME_LIMIT_POS)
  1659. & IWL49_SCD_QUEUE_CTX_REG2_FRAME_LIMIT_MSK);
  1660. iwl_set_bits_prph(priv, IWL49_SCD_INTERRUPT_MASK, (1 << txq_id));
  1661. /* Set up Status area in SRAM, map to Tx DMA/FIFO, activate the queue */
  1662. iwl4965_tx_queue_set_status(priv, &priv->txq[txq_id], tx_fifo, 1);
  1663. iwl_release_nic_access(priv);
  1664. spin_unlock_irqrestore(&priv->lock, flags);
  1665. return 0;
  1666. }
  1667. static u16 iwl4965_get_hcmd_size(u8 cmd_id, u16 len)
  1668. {
  1669. switch (cmd_id) {
  1670. case REPLY_RXON:
  1671. return (u16) sizeof(struct iwl4965_rxon_cmd);
  1672. default:
  1673. return len;
  1674. }
  1675. }
  1676. static u16 iwl4965_build_addsta_hcmd(const struct iwl_addsta_cmd *cmd, u8 *data)
  1677. {
  1678. struct iwl4965_addsta_cmd *addsta = (struct iwl4965_addsta_cmd *)data;
  1679. addsta->mode = cmd->mode;
  1680. memcpy(&addsta->sta, &cmd->sta, sizeof(struct sta_id_modify));
  1681. memcpy(&addsta->key, &cmd->key, sizeof(struct iwl4965_keyinfo));
  1682. addsta->station_flags = cmd->station_flags;
  1683. addsta->station_flags_msk = cmd->station_flags_msk;
  1684. addsta->tid_disable_tx = cmd->tid_disable_tx;
  1685. addsta->add_immediate_ba_tid = cmd->add_immediate_ba_tid;
  1686. addsta->remove_immediate_ba_tid = cmd->remove_immediate_ba_tid;
  1687. addsta->add_immediate_ba_ssn = cmd->add_immediate_ba_ssn;
  1688. addsta->reserved1 = __constant_cpu_to_le16(0);
  1689. addsta->reserved2 = __constant_cpu_to_le32(0);
  1690. return (u16)sizeof(struct iwl4965_addsta_cmd);
  1691. }
  1692. static inline u32 iwl4965_get_scd_ssn(struct iwl4965_tx_resp *tx_resp)
  1693. {
  1694. return le32_to_cpup(&tx_resp->u.status + tx_resp->frame_count) & MAX_SN;
  1695. }
  1696. /**
  1697. * iwl4965_tx_status_reply_tx - Handle Tx response for frames in aggregation queue
  1698. */
  1699. static int iwl4965_tx_status_reply_tx(struct iwl_priv *priv,
  1700. struct iwl_ht_agg *agg,
  1701. struct iwl4965_tx_resp *tx_resp,
  1702. int txq_id, u16 start_idx)
  1703. {
  1704. u16 status;
  1705. struct agg_tx_status *frame_status = tx_resp->u.agg_status;
  1706. struct ieee80211_tx_info *info = NULL;
  1707. struct ieee80211_hdr *hdr = NULL;
  1708. u32 rate_n_flags = le32_to_cpu(tx_resp->rate_n_flags);
  1709. int i, sh, idx;
  1710. u16 seq;
  1711. if (agg->wait_for_ba)
  1712. IWL_DEBUG_TX_REPLY("got tx response w/o block-ack\n");
  1713. agg->frame_count = tx_resp->frame_count;
  1714. agg->start_idx = start_idx;
  1715. agg->rate_n_flags = rate_n_flags;
  1716. agg->bitmap = 0;
  1717. /* num frames attempted by Tx command */
  1718. if (agg->frame_count == 1) {
  1719. /* Only one frame was attempted; no block-ack will arrive */
  1720. status = le16_to_cpu(frame_status[0].status);
  1721. idx = start_idx;
  1722. /* FIXME: code repetition */
  1723. IWL_DEBUG_TX_REPLY("FrameCnt = %d, StartIdx=%d idx=%d\n",
  1724. agg->frame_count, agg->start_idx, idx);
  1725. info = IEEE80211_SKB_CB(priv->txq[txq_id].txb[idx].skb[0]);
  1726. info->status.rates[0].count = tx_resp->failure_frame + 1;
  1727. info->flags &= ~IEEE80211_TX_CTL_AMPDU;
  1728. info->flags |= iwl_is_tx_success(status) ?
  1729. IEEE80211_TX_STAT_ACK : 0;
  1730. iwl_hwrate_to_tx_control(priv, rate_n_flags, info);
  1731. /* FIXME: code repetition end */
  1732. IWL_DEBUG_TX_REPLY("1 Frame 0x%x failure :%d\n",
  1733. status & 0xff, tx_resp->failure_frame);
  1734. IWL_DEBUG_TX_REPLY("Rate Info rate_n_flags=%x\n", rate_n_flags);
  1735. agg->wait_for_ba = 0;
  1736. } else {
  1737. /* Two or more frames were attempted; expect block-ack */
  1738. u64 bitmap = 0;
  1739. int start = agg->start_idx;
  1740. /* Construct bit-map of pending frames within Tx window */
  1741. for (i = 0; i < agg->frame_count; i++) {
  1742. u16 sc;
  1743. status = le16_to_cpu(frame_status[i].status);
  1744. seq = le16_to_cpu(frame_status[i].sequence);
  1745. idx = SEQ_TO_INDEX(seq);
  1746. txq_id = SEQ_TO_QUEUE(seq);
  1747. if (status & (AGG_TX_STATE_FEW_BYTES_MSK |
  1748. AGG_TX_STATE_ABORT_MSK))
  1749. continue;
  1750. IWL_DEBUG_TX_REPLY("FrameCnt = %d, txq_id=%d idx=%d\n",
  1751. agg->frame_count, txq_id, idx);
  1752. hdr = iwl_tx_queue_get_hdr(priv, txq_id, idx);
  1753. sc = le16_to_cpu(hdr->seq_ctrl);
  1754. if (idx != (SEQ_TO_SN(sc) & 0xff)) {
  1755. IWL_ERROR("BUG_ON idx doesn't match seq control"
  1756. " idx=%d, seq_idx=%d, seq=%d\n",
  1757. idx, SEQ_TO_SN(sc),
  1758. hdr->seq_ctrl);
  1759. return -1;
  1760. }
  1761. IWL_DEBUG_TX_REPLY("AGG Frame i=%d idx %d seq=%d\n",
  1762. i, idx, SEQ_TO_SN(sc));
  1763. sh = idx - start;
  1764. if (sh > 64) {
  1765. sh = (start - idx) + 0xff;
  1766. bitmap = bitmap << sh;
  1767. sh = 0;
  1768. start = idx;
  1769. } else if (sh < -64)
  1770. sh = 0xff - (start - idx);
  1771. else if (sh < 0) {
  1772. sh = start - idx;
  1773. start = idx;
  1774. bitmap = bitmap << sh;
  1775. sh = 0;
  1776. }
  1777. bitmap |= 1ULL << sh;
  1778. IWL_DEBUG_TX_REPLY("start=%d bitmap=0x%llx\n",
  1779. start, (unsigned long long)bitmap);
  1780. }
  1781. agg->bitmap = bitmap;
  1782. agg->start_idx = start;
  1783. IWL_DEBUG_TX_REPLY("Frames %d start_idx=%d bitmap=0x%llx\n",
  1784. agg->frame_count, agg->start_idx,
  1785. (unsigned long long)agg->bitmap);
  1786. if (bitmap)
  1787. agg->wait_for_ba = 1;
  1788. }
  1789. return 0;
  1790. }
  1791. /**
  1792. * iwl4965_rx_reply_tx - Handle standard (non-aggregation) Tx response
  1793. */
  1794. static void iwl4965_rx_reply_tx(struct iwl_priv *priv,
  1795. struct iwl_rx_mem_buffer *rxb)
  1796. {
  1797. struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
  1798. u16 sequence = le16_to_cpu(pkt->hdr.sequence);
  1799. int txq_id = SEQ_TO_QUEUE(sequence);
  1800. int index = SEQ_TO_INDEX(sequence);
  1801. struct iwl_tx_queue *txq = &priv->txq[txq_id];
  1802. struct ieee80211_hdr *hdr;
  1803. struct ieee80211_tx_info *info;
  1804. struct iwl4965_tx_resp *tx_resp = (void *)&pkt->u.raw[0];
  1805. u32 status = le32_to_cpu(tx_resp->u.status);
  1806. int tid = MAX_TID_COUNT;
  1807. int sta_id;
  1808. int freed;
  1809. u8 *qc = NULL;
  1810. if ((index >= txq->q.n_bd) || (iwl_queue_used(&txq->q, index) == 0)) {
  1811. IWL_ERROR("Read index for DMA queue txq_id (%d) index %d "
  1812. "is out of range [0-%d] %d %d\n", txq_id,
  1813. index, txq->q.n_bd, txq->q.write_ptr,
  1814. txq->q.read_ptr);
  1815. return;
  1816. }
  1817. info = IEEE80211_SKB_CB(txq->txb[txq->q.read_ptr].skb[0]);
  1818. memset(&info->status, 0, sizeof(info->status));
  1819. hdr = iwl_tx_queue_get_hdr(priv, txq_id, index);
  1820. if (ieee80211_is_data_qos(hdr->frame_control)) {
  1821. qc = ieee80211_get_qos_ctl(hdr);
  1822. tid = qc[0] & 0xf;
  1823. }
  1824. sta_id = iwl_get_ra_sta_id(priv, hdr);
  1825. if (txq->sched_retry && unlikely(sta_id == IWL_INVALID_STATION)) {
  1826. IWL_ERROR("Station not known\n");
  1827. return;
  1828. }
  1829. if (txq->sched_retry) {
  1830. const u32 scd_ssn = iwl4965_get_scd_ssn(tx_resp);
  1831. struct iwl_ht_agg *agg = NULL;
  1832. WARN_ON(!qc);
  1833. agg = &priv->stations[sta_id].tid[tid].agg;
  1834. iwl4965_tx_status_reply_tx(priv, agg, tx_resp, txq_id, index);
  1835. /* check if BAR is needed */
  1836. if ((tx_resp->frame_count == 1) && !iwl_is_tx_success(status))
  1837. info->flags |= IEEE80211_TX_STAT_AMPDU_NO_BACK;
  1838. if (txq->q.read_ptr != (scd_ssn & 0xff)) {
  1839. index = iwl_queue_dec_wrap(scd_ssn & 0xff, txq->q.n_bd);
  1840. IWL_DEBUG_TX_REPLY("Retry scheduler reclaim scd_ssn "
  1841. "%d index %d\n", scd_ssn , index);
  1842. freed = iwl_tx_queue_reclaim(priv, txq_id, index);
  1843. priv->stations[sta_id].tid[tid].tfds_in_queue -= freed;
  1844. if (priv->mac80211_registered &&
  1845. (iwl_queue_space(&txq->q) > txq->q.low_mark) &&
  1846. (agg->state != IWL_EMPTYING_HW_QUEUE_DELBA)) {
  1847. if (agg->state == IWL_AGG_OFF)
  1848. ieee80211_wake_queue(priv->hw, txq_id);
  1849. else
  1850. ieee80211_wake_queue(priv->hw,
  1851. txq->swq_id);
  1852. }
  1853. }
  1854. } else {
  1855. info->status.rates[0].count = tx_resp->failure_frame + 1;
  1856. info->flags |= iwl_is_tx_success(status) ?
  1857. IEEE80211_TX_STAT_ACK : 0;
  1858. iwl_hwrate_to_tx_control(priv,
  1859. le32_to_cpu(tx_resp->rate_n_flags),
  1860. info);
  1861. IWL_DEBUG_TX_REPLY("TXQ %d status %s (0x%08x) "
  1862. "rate_n_flags 0x%x retries %d\n",
  1863. txq_id,
  1864. iwl_get_tx_fail_reason(status), status,
  1865. le32_to_cpu(tx_resp->rate_n_flags),
  1866. tx_resp->failure_frame);
  1867. freed = iwl_tx_queue_reclaim(priv, txq_id, index);
  1868. if (qc && likely(sta_id != IWL_INVALID_STATION))
  1869. priv->stations[sta_id].tid[tid].tfds_in_queue -= freed;
  1870. if (priv->mac80211_registered &&
  1871. (iwl_queue_space(&txq->q) > txq->q.low_mark))
  1872. ieee80211_wake_queue(priv->hw, txq_id);
  1873. }
  1874. if (qc && likely(sta_id != IWL_INVALID_STATION))
  1875. iwl_txq_check_empty(priv, sta_id, tid, txq_id);
  1876. if (iwl_check_bits(status, TX_ABORT_REQUIRED_MSK))
  1877. IWL_ERROR("TODO: Implement Tx ABORT REQUIRED!!!\n");
  1878. }
  1879. static int iwl4965_calc_rssi(struct iwl_priv *priv,
  1880. struct iwl_rx_phy_res *rx_resp)
  1881. {
  1882. /* data from PHY/DSP regarding signal strength, etc.,
  1883. * contents are always there, not configurable by host. */
  1884. struct iwl4965_rx_non_cfg_phy *ncphy =
  1885. (struct iwl4965_rx_non_cfg_phy *)rx_resp->non_cfg_phy_buf;
  1886. u32 agc = (le16_to_cpu(ncphy->agc_info) & IWL49_AGC_DB_MASK)
  1887. >> IWL49_AGC_DB_POS;
  1888. u32 valid_antennae =
  1889. (le16_to_cpu(rx_resp->phy_flags) & IWL49_RX_PHY_FLAGS_ANTENNAE_MASK)
  1890. >> IWL49_RX_PHY_FLAGS_ANTENNAE_OFFSET;
  1891. u8 max_rssi = 0;
  1892. u32 i;
  1893. /* Find max rssi among 3 possible receivers.
  1894. * These values are measured by the digital signal processor (DSP).
  1895. * They should stay fairly constant even as the signal strength varies,
  1896. * if the radio's automatic gain control (AGC) is working right.
  1897. * AGC value (see below) will provide the "interesting" info. */
  1898. for (i = 0; i < 3; i++)
  1899. if (valid_antennae & (1 << i))
  1900. max_rssi = max(ncphy->rssi_info[i << 1], max_rssi);
  1901. IWL_DEBUG_STATS("Rssi In A %d B %d C %d Max %d AGC dB %d\n",
  1902. ncphy->rssi_info[0], ncphy->rssi_info[2], ncphy->rssi_info[4],
  1903. max_rssi, agc);
  1904. /* dBm = max_rssi dB - agc dB - constant.
  1905. * Higher AGC (higher radio gain) means lower signal. */
  1906. return max_rssi - agc - IWL49_RSSI_OFFSET;
  1907. }
  1908. /* Set up 4965-specific Rx frame reply handlers */
  1909. static void iwl4965_rx_handler_setup(struct iwl_priv *priv)
  1910. {
  1911. /* Legacy Rx frames */
  1912. priv->rx_handlers[REPLY_RX] = iwl_rx_reply_rx;
  1913. /* Tx response */
  1914. priv->rx_handlers[REPLY_TX] = iwl4965_rx_reply_tx;
  1915. }
  1916. static void iwl4965_setup_deferred_work(struct iwl_priv *priv)
  1917. {
  1918. INIT_WORK(&priv->txpower_work, iwl4965_bg_txpower_work);
  1919. }
  1920. static void iwl4965_cancel_deferred_work(struct iwl_priv *priv)
  1921. {
  1922. cancel_work_sync(&priv->txpower_work);
  1923. }
  1924. static struct iwl_hcmd_ops iwl4965_hcmd = {
  1925. .rxon_assoc = iwl4965_send_rxon_assoc,
  1926. };
  1927. static struct iwl_hcmd_utils_ops iwl4965_hcmd_utils = {
  1928. .get_hcmd_size = iwl4965_get_hcmd_size,
  1929. .build_addsta_hcmd = iwl4965_build_addsta_hcmd,
  1930. .chain_noise_reset = iwl4965_chain_noise_reset,
  1931. .gain_computation = iwl4965_gain_computation,
  1932. .rts_tx_cmd_flag = iwl4965_rts_tx_cmd_flag,
  1933. .calc_rssi = iwl4965_calc_rssi,
  1934. };
  1935. static struct iwl_lib_ops iwl4965_lib = {
  1936. .set_hw_params = iwl4965_hw_set_hw_params,
  1937. .txq_update_byte_cnt_tbl = iwl4965_txq_update_byte_cnt_tbl,
  1938. .txq_set_sched = iwl4965_txq_set_sched,
  1939. .txq_agg_enable = iwl4965_txq_agg_enable,
  1940. .txq_agg_disable = iwl4965_txq_agg_disable,
  1941. .rx_handler_setup = iwl4965_rx_handler_setup,
  1942. .setup_deferred_work = iwl4965_setup_deferred_work,
  1943. .cancel_deferred_work = iwl4965_cancel_deferred_work,
  1944. .is_valid_rtc_data_addr = iwl4965_hw_valid_rtc_data_addr,
  1945. .alive_notify = iwl4965_alive_notify,
  1946. .init_alive_start = iwl4965_init_alive_start,
  1947. .load_ucode = iwl4965_load_bsm,
  1948. .apm_ops = {
  1949. .init = iwl4965_apm_init,
  1950. .reset = iwl4965_apm_reset,
  1951. .stop = iwl4965_apm_stop,
  1952. .config = iwl4965_nic_config,
  1953. .set_pwr_src = iwl_set_pwr_src,
  1954. },
  1955. .eeprom_ops = {
  1956. .regulatory_bands = {
  1957. EEPROM_REGULATORY_BAND_1_CHANNELS,
  1958. EEPROM_REGULATORY_BAND_2_CHANNELS,
  1959. EEPROM_REGULATORY_BAND_3_CHANNELS,
  1960. EEPROM_REGULATORY_BAND_4_CHANNELS,
  1961. EEPROM_REGULATORY_BAND_5_CHANNELS,
  1962. EEPROM_4965_REGULATORY_BAND_24_FAT_CHANNELS,
  1963. EEPROM_4965_REGULATORY_BAND_52_FAT_CHANNELS
  1964. },
  1965. .verify_signature = iwlcore_eeprom_verify_signature,
  1966. .acquire_semaphore = iwlcore_eeprom_acquire_semaphore,
  1967. .release_semaphore = iwlcore_eeprom_release_semaphore,
  1968. .calib_version = iwl4965_eeprom_calib_version,
  1969. .query_addr = iwlcore_eeprom_query_addr,
  1970. },
  1971. .send_tx_power = iwl4965_send_tx_power,
  1972. .update_chain_flags = iwl_update_chain_flags,
  1973. .temperature = iwl4965_temperature_calib,
  1974. };
  1975. static struct iwl_ops iwl4965_ops = {
  1976. .lib = &iwl4965_lib,
  1977. .hcmd = &iwl4965_hcmd,
  1978. .utils = &iwl4965_hcmd_utils,
  1979. };
  1980. struct iwl_cfg iwl4965_agn_cfg = {
  1981. .name = "4965AGN",
  1982. .fw_name_pre = IWL4965_FW_PRE,
  1983. .ucode_api_max = IWL4965_UCODE_API_MAX,
  1984. .ucode_api_min = IWL4965_UCODE_API_MIN,
  1985. .sku = IWL_SKU_A|IWL_SKU_G|IWL_SKU_N,
  1986. .eeprom_size = IWL4965_EEPROM_IMG_SIZE,
  1987. .eeprom_ver = EEPROM_4965_EEPROM_VERSION,
  1988. .eeprom_calib_ver = EEPROM_4965_TX_POWER_VERSION,
  1989. .ops = &iwl4965_ops,
  1990. .mod_params = &iwl4965_mod_params,
  1991. };
  1992. /* Module firmware */
  1993. MODULE_FIRMWARE(IWL4965_MODULE_FIRMWARE(IWL4965_UCODE_API_MAX));
  1994. module_param_named(antenna, iwl4965_mod_params.antenna, int, 0444);
  1995. MODULE_PARM_DESC(antenna, "select antenna (1=Main, 2=Aux, default 0 [both])");
  1996. module_param_named(disable, iwl4965_mod_params.disable, int, 0444);
  1997. MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])");
  1998. module_param_named(swcrypto, iwl4965_mod_params.sw_crypto, int, 0444);
  1999. MODULE_PARM_DESC(swcrypto, "using crypto in software (default 0 [hardware])");
  2000. module_param_named(debug, iwl4965_mod_params.debug, uint, 0444);
  2001. MODULE_PARM_DESC(debug, "debug output mask");
  2002. module_param_named(
  2003. disable_hw_scan, iwl4965_mod_params.disable_hw_scan, int, 0444);
  2004. MODULE_PARM_DESC(disable_hw_scan, "disable hardware scanning (default 0)");
  2005. module_param_named(queues_num, iwl4965_mod_params.num_of_queues, int, 0444);
  2006. MODULE_PARM_DESC(queues_num, "number of hw queues.");
  2007. /* 11n */
  2008. module_param_named(11n_disable, iwl4965_mod_params.disable_11n, int, 0444);
  2009. MODULE_PARM_DESC(11n_disable, "disable 11n functionality");
  2010. module_param_named(amsdu_size_8K, iwl4965_mod_params.amsdu_size_8K, int, 0444);
  2011. MODULE_PARM_DESC(amsdu_size_8K, "enable 8K amsdu size");
  2012. module_param_named(fw_restart4965, iwl4965_mod_params.restart_fw, int, 0444);
  2013. MODULE_PARM_DESC(fw_restart4965, "restart firmware in case of error");