iwl-4965.c 64 KB

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