iwl-4965.c 76 KB

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