iwl-4965.c 66 KB

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