iwl-4965.c 67 KB

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