iwl-4965.c 66 KB

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