iwl-4965.c 65 KB

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