iwl-4965.c 63 KB

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