iwl-4965.c 62 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184
  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 -EINVAL;
  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 txatten_grp;
  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. return ret;
  1043. }
  1044. static int iwl4965_commit_rxon(struct iwl_priv *priv, struct iwl_rxon_context *ctx)
  1045. {
  1046. /* cast away the const for active_rxon in this function */
  1047. struct iwl_legacy_rxon_cmd *active_rxon = (void *)&ctx->active;
  1048. int ret;
  1049. bool new_assoc =
  1050. !!(ctx->staging.filter_flags & RXON_FILTER_ASSOC_MSK);
  1051. if (!iwl_legacy_is_alive(priv))
  1052. return -EBUSY;
  1053. if (!ctx->is_active)
  1054. return 0;
  1055. /* always get timestamp with Rx frame */
  1056. ctx->staging.flags |= RXON_FLG_TSF2HOST_MSK;
  1057. ret = iwl_legacy_check_rxon_cmd(priv, ctx);
  1058. if (ret) {
  1059. IWL_ERR(priv, "Invalid RXON configuration. Not committing.\n");
  1060. return -EINVAL;
  1061. }
  1062. /*
  1063. * receive commit_rxon request
  1064. * abort any previous channel switch if still in process
  1065. */
  1066. if (test_bit(STATUS_CHANNEL_SWITCH_PENDING, &priv->status) &&
  1067. (priv->switch_channel != ctx->staging.channel)) {
  1068. IWL_DEBUG_11H(priv, "abort channel switch on %d\n",
  1069. le16_to_cpu(priv->switch_channel));
  1070. iwl_legacy_chswitch_done(priv, false);
  1071. }
  1072. /* If we don't need to send a full RXON, we can use
  1073. * iwl_rxon_assoc_cmd which is used to reconfigure filter
  1074. * and other flags for the current radio configuration. */
  1075. if (!iwl_legacy_full_rxon_required(priv, ctx)) {
  1076. ret = iwl_legacy_send_rxon_assoc(priv, ctx);
  1077. if (ret) {
  1078. IWL_ERR(priv, "Error setting RXON_ASSOC (%d)\n", ret);
  1079. return ret;
  1080. }
  1081. memcpy(active_rxon, &ctx->staging, sizeof(*active_rxon));
  1082. iwl_legacy_print_rx_config_cmd(priv, ctx);
  1083. /*
  1084. * We do not commit tx power settings while channel changing,
  1085. * do it now if tx power changed.
  1086. */
  1087. iwl_legacy_set_tx_power(priv, priv->tx_power_next, false);
  1088. return 0;
  1089. }
  1090. /* If we are currently associated and the new config requires
  1091. * an RXON_ASSOC and the new config wants the associated mask enabled,
  1092. * we must clear the associated from the active configuration
  1093. * before we apply the new config */
  1094. if (iwl_legacy_is_associated_ctx(ctx) && new_assoc) {
  1095. IWL_DEBUG_INFO(priv, "Toggling associated bit on current RXON\n");
  1096. active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  1097. ret = iwl_legacy_send_cmd_pdu(priv, ctx->rxon_cmd,
  1098. sizeof(struct iwl_legacy_rxon_cmd),
  1099. active_rxon);
  1100. /* If the mask clearing failed then we set
  1101. * active_rxon back to what it was previously */
  1102. if (ret) {
  1103. active_rxon->filter_flags |= RXON_FILTER_ASSOC_MSK;
  1104. IWL_ERR(priv, "Error clearing ASSOC_MSK (%d)\n", ret);
  1105. return ret;
  1106. }
  1107. iwl_legacy_clear_ucode_stations(priv, ctx);
  1108. iwl_legacy_restore_stations(priv, ctx);
  1109. ret = iwl4965_restore_default_wep_keys(priv, ctx);
  1110. if (ret) {
  1111. IWL_ERR(priv, "Failed to restore WEP keys (%d)\n", ret);
  1112. return ret;
  1113. }
  1114. }
  1115. IWL_DEBUG_INFO(priv, "Sending RXON\n"
  1116. "* with%s RXON_FILTER_ASSOC_MSK\n"
  1117. "* channel = %d\n"
  1118. "* bssid = %pM\n",
  1119. (new_assoc ? "" : "out"),
  1120. le16_to_cpu(ctx->staging.channel),
  1121. ctx->staging.bssid_addr);
  1122. iwl_legacy_set_rxon_hwcrypto(priv, ctx,
  1123. !priv->cfg->mod_params->sw_crypto);
  1124. /* Apply the new configuration
  1125. * RXON unassoc clears the station table in uCode so restoration of
  1126. * stations is needed after it (the RXON command) completes
  1127. */
  1128. if (!new_assoc) {
  1129. ret = iwl_legacy_send_cmd_pdu(priv, ctx->rxon_cmd,
  1130. sizeof(struct iwl_legacy_rxon_cmd), &ctx->staging);
  1131. if (ret) {
  1132. IWL_ERR(priv, "Error setting new RXON (%d)\n", ret);
  1133. return ret;
  1134. }
  1135. IWL_DEBUG_INFO(priv, "Return from !new_assoc RXON.\n");
  1136. memcpy(active_rxon, &ctx->staging, sizeof(*active_rxon));
  1137. iwl_legacy_clear_ucode_stations(priv, ctx);
  1138. iwl_legacy_restore_stations(priv, ctx);
  1139. ret = iwl4965_restore_default_wep_keys(priv, ctx);
  1140. if (ret) {
  1141. IWL_ERR(priv, "Failed to restore WEP keys (%d)\n", ret);
  1142. return ret;
  1143. }
  1144. }
  1145. if (new_assoc) {
  1146. priv->start_calib = 0;
  1147. /* Apply the new configuration
  1148. * RXON assoc doesn't clear the station table in uCode,
  1149. */
  1150. ret = iwl_legacy_send_cmd_pdu(priv, ctx->rxon_cmd,
  1151. sizeof(struct iwl_legacy_rxon_cmd), &ctx->staging);
  1152. if (ret) {
  1153. IWL_ERR(priv, "Error setting new RXON (%d)\n", ret);
  1154. return ret;
  1155. }
  1156. memcpy(active_rxon, &ctx->staging, sizeof(*active_rxon));
  1157. }
  1158. iwl_legacy_print_rx_config_cmd(priv, ctx);
  1159. iwl4965_init_sensitivity(priv);
  1160. /* If we issue a new RXON command which required a tune then we must
  1161. * send a new TXPOWER command or we won't be able to Tx any frames */
  1162. ret = iwl_legacy_set_tx_power(priv, priv->tx_power_next, true);
  1163. if (ret) {
  1164. IWL_ERR(priv, "Error sending TX power (%d)\n", ret);
  1165. return ret;
  1166. }
  1167. return 0;
  1168. }
  1169. static int iwl4965_hw_channel_switch(struct iwl_priv *priv,
  1170. struct ieee80211_channel_switch *ch_switch)
  1171. {
  1172. struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
  1173. int rc;
  1174. u8 band = 0;
  1175. bool is_ht40 = false;
  1176. u8 ctrl_chan_high = 0;
  1177. struct iwl4965_channel_switch_cmd cmd;
  1178. const struct iwl_channel_info *ch_info;
  1179. u32 switch_time_in_usec, ucode_switch_time;
  1180. u16 ch;
  1181. u32 tsf_low;
  1182. u8 switch_count;
  1183. u16 beacon_interval = le16_to_cpu(ctx->timing.beacon_interval);
  1184. struct ieee80211_vif *vif = ctx->vif;
  1185. band = priv->band == IEEE80211_BAND_2GHZ;
  1186. is_ht40 = iw4965_is_ht40_channel(ctx->staging.flags);
  1187. if (is_ht40 &&
  1188. (ctx->staging.flags & RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK))
  1189. ctrl_chan_high = 1;
  1190. cmd.band = band;
  1191. cmd.expect_beacon = 0;
  1192. ch = ch_switch->channel->hw_value;
  1193. cmd.channel = cpu_to_le16(ch);
  1194. cmd.rxon_flags = ctx->staging.flags;
  1195. cmd.rxon_filter_flags = ctx->staging.filter_flags;
  1196. switch_count = ch_switch->count;
  1197. tsf_low = ch_switch->timestamp & 0x0ffffffff;
  1198. /*
  1199. * calculate the ucode channel switch time
  1200. * adding TSF as one of the factor for when to switch
  1201. */
  1202. if ((priv->ucode_beacon_time > tsf_low) && beacon_interval) {
  1203. if (switch_count > ((priv->ucode_beacon_time - tsf_low) /
  1204. beacon_interval)) {
  1205. switch_count -= (priv->ucode_beacon_time -
  1206. tsf_low) / beacon_interval;
  1207. } else
  1208. switch_count = 0;
  1209. }
  1210. if (switch_count <= 1)
  1211. cmd.switch_time = cpu_to_le32(priv->ucode_beacon_time);
  1212. else {
  1213. switch_time_in_usec =
  1214. vif->bss_conf.beacon_int * switch_count * TIME_UNIT;
  1215. ucode_switch_time = iwl_legacy_usecs_to_beacons(priv,
  1216. switch_time_in_usec,
  1217. beacon_interval);
  1218. cmd.switch_time = iwl_legacy_add_beacon_time(priv,
  1219. priv->ucode_beacon_time,
  1220. ucode_switch_time,
  1221. beacon_interval);
  1222. }
  1223. IWL_DEBUG_11H(priv, "uCode time for the switch is 0x%x\n",
  1224. cmd.switch_time);
  1225. ch_info = iwl_legacy_get_channel_info(priv, priv->band, ch);
  1226. if (ch_info)
  1227. cmd.expect_beacon = iwl_legacy_is_channel_radar(ch_info);
  1228. else {
  1229. IWL_ERR(priv, "invalid channel switch from %u to %u\n",
  1230. ctx->active.channel, ch);
  1231. return -EFAULT;
  1232. }
  1233. rc = iwl4965_fill_txpower_tbl(priv, band, ch, is_ht40,
  1234. ctrl_chan_high, &cmd.tx_power);
  1235. if (rc) {
  1236. IWL_DEBUG_11H(priv, "error:%d fill txpower_tbl\n", rc);
  1237. return rc;
  1238. }
  1239. return iwl_legacy_send_cmd_pdu(priv,
  1240. REPLY_CHANNEL_SWITCH, sizeof(cmd), &cmd);
  1241. }
  1242. /**
  1243. * iwl4965_txq_update_byte_cnt_tbl - Set up entry in Tx byte-count array
  1244. */
  1245. static void iwl4965_txq_update_byte_cnt_tbl(struct iwl_priv *priv,
  1246. struct iwl_tx_queue *txq,
  1247. u16 byte_cnt)
  1248. {
  1249. struct iwl4965_scd_bc_tbl *scd_bc_tbl = priv->scd_bc_tbls.addr;
  1250. int txq_id = txq->q.id;
  1251. int write_ptr = txq->q.write_ptr;
  1252. int len = byte_cnt + IWL_TX_CRC_SIZE + IWL_TX_DELIMITER_SIZE;
  1253. __le16 bc_ent;
  1254. WARN_ON(len > 0xFFF || write_ptr >= TFD_QUEUE_SIZE_MAX);
  1255. bc_ent = cpu_to_le16(len & 0xFFF);
  1256. /* Set up byte count within first 256 entries */
  1257. scd_bc_tbl[txq_id].tfd_offset[write_ptr] = bc_ent;
  1258. /* If within first 64 entries, duplicate at end */
  1259. if (write_ptr < TFD_QUEUE_SIZE_BC_DUP)
  1260. scd_bc_tbl[txq_id].
  1261. tfd_offset[TFD_QUEUE_SIZE_MAX + write_ptr] = bc_ent;
  1262. }
  1263. /**
  1264. * iwl4965_hw_get_temperature - return the calibrated temperature (in Kelvin)
  1265. * @statistics: Provides the temperature reading from the uCode
  1266. *
  1267. * A return of <0 indicates bogus data in the statistics
  1268. */
  1269. static int iwl4965_hw_get_temperature(struct iwl_priv *priv)
  1270. {
  1271. s32 temperature;
  1272. s32 vt;
  1273. s32 R1, R2, R3;
  1274. u32 R4;
  1275. if (test_bit(STATUS_TEMPERATURE, &priv->status) &&
  1276. (priv->_4965.statistics.flag &
  1277. STATISTICS_REPLY_FLG_HT40_MODE_MSK)) {
  1278. IWL_DEBUG_TEMP(priv, "Running HT40 temperature calibration\n");
  1279. R1 = (s32)le32_to_cpu(priv->card_alive_init.therm_r1[1]);
  1280. R2 = (s32)le32_to_cpu(priv->card_alive_init.therm_r2[1]);
  1281. R3 = (s32)le32_to_cpu(priv->card_alive_init.therm_r3[1]);
  1282. R4 = le32_to_cpu(priv->card_alive_init.therm_r4[1]);
  1283. } else {
  1284. IWL_DEBUG_TEMP(priv, "Running temperature calibration\n");
  1285. R1 = (s32)le32_to_cpu(priv->card_alive_init.therm_r1[0]);
  1286. R2 = (s32)le32_to_cpu(priv->card_alive_init.therm_r2[0]);
  1287. R3 = (s32)le32_to_cpu(priv->card_alive_init.therm_r3[0]);
  1288. R4 = le32_to_cpu(priv->card_alive_init.therm_r4[0]);
  1289. }
  1290. /*
  1291. * Temperature is only 23 bits, so sign extend out to 32.
  1292. *
  1293. * NOTE If we haven't received a statistics notification yet
  1294. * with an updated temperature, use R4 provided to us in the
  1295. * "initialize" ALIVE response.
  1296. */
  1297. if (!test_bit(STATUS_TEMPERATURE, &priv->status))
  1298. vt = sign_extend32(R4, 23);
  1299. else
  1300. vt = sign_extend32(le32_to_cpu(priv->_4965.statistics.
  1301. general.common.temperature), 23);
  1302. IWL_DEBUG_TEMP(priv, "Calib values R[1-3]: %d %d %d R4: %d\n", R1, R2, R3, vt);
  1303. if (R3 == R1) {
  1304. IWL_ERR(priv, "Calibration conflict R1 == R3\n");
  1305. return -1;
  1306. }
  1307. /* Calculate temperature in degrees Kelvin, adjust by 97%.
  1308. * Add offset to center the adjustment around 0 degrees Centigrade. */
  1309. temperature = TEMPERATURE_CALIB_A_VAL * (vt - R2);
  1310. temperature /= (R3 - R1);
  1311. temperature = (temperature * 97) / 100 + TEMPERATURE_CALIB_KELVIN_OFFSET;
  1312. IWL_DEBUG_TEMP(priv, "Calibrated temperature: %dK, %dC\n",
  1313. temperature, KELVIN_TO_CELSIUS(temperature));
  1314. return temperature;
  1315. }
  1316. /* Adjust Txpower only if temperature variance is greater than threshold. */
  1317. #define IWL_TEMPERATURE_THRESHOLD 3
  1318. /**
  1319. * iwl4965_is_temp_calib_needed - determines if new calibration is needed
  1320. *
  1321. * If the temperature changed has changed sufficiently, then a recalibration
  1322. * is needed.
  1323. *
  1324. * Assumes caller will replace priv->last_temperature once calibration
  1325. * executed.
  1326. */
  1327. static int iwl4965_is_temp_calib_needed(struct iwl_priv *priv)
  1328. {
  1329. int temp_diff;
  1330. if (!test_bit(STATUS_STATISTICS, &priv->status)) {
  1331. IWL_DEBUG_TEMP(priv, "Temperature not updated -- no statistics.\n");
  1332. return 0;
  1333. }
  1334. temp_diff = priv->temperature - priv->last_temperature;
  1335. /* get absolute value */
  1336. if (temp_diff < 0) {
  1337. IWL_DEBUG_POWER(priv, "Getting cooler, delta %d\n", temp_diff);
  1338. temp_diff = -temp_diff;
  1339. } else if (temp_diff == 0)
  1340. IWL_DEBUG_POWER(priv, "Temperature unchanged\n");
  1341. else
  1342. IWL_DEBUG_POWER(priv, "Getting warmer, delta %d\n", temp_diff);
  1343. if (temp_diff < IWL_TEMPERATURE_THRESHOLD) {
  1344. IWL_DEBUG_POWER(priv, " => thermal txpower calib not needed\n");
  1345. return 0;
  1346. }
  1347. IWL_DEBUG_POWER(priv, " => thermal txpower calib needed\n");
  1348. return 1;
  1349. }
  1350. static void iwl4965_temperature_calib(struct iwl_priv *priv)
  1351. {
  1352. s32 temp;
  1353. temp = iwl4965_hw_get_temperature(priv);
  1354. if (IWL_TX_POWER_TEMPERATURE_OUT_OF_RANGE(temp))
  1355. return;
  1356. if (priv->temperature != temp) {
  1357. if (priv->temperature)
  1358. IWL_DEBUG_TEMP(priv, "Temperature changed "
  1359. "from %dC to %dC\n",
  1360. KELVIN_TO_CELSIUS(priv->temperature),
  1361. KELVIN_TO_CELSIUS(temp));
  1362. else
  1363. IWL_DEBUG_TEMP(priv, "Temperature "
  1364. "initialized to %dC\n",
  1365. KELVIN_TO_CELSIUS(temp));
  1366. }
  1367. priv->temperature = temp;
  1368. set_bit(STATUS_TEMPERATURE, &priv->status);
  1369. if (!priv->disable_tx_power_cal &&
  1370. unlikely(!test_bit(STATUS_SCANNING, &priv->status)) &&
  1371. iwl4965_is_temp_calib_needed(priv))
  1372. queue_work(priv->workqueue, &priv->txpower_work);
  1373. }
  1374. static u16 iwl4965_get_hcmd_size(u8 cmd_id, u16 len)
  1375. {
  1376. switch (cmd_id) {
  1377. case REPLY_RXON:
  1378. return (u16) sizeof(struct iwl4965_rxon_cmd);
  1379. default:
  1380. return len;
  1381. }
  1382. }
  1383. static u16 iwl4965_build_addsta_hcmd(const struct iwl_legacy_addsta_cmd *cmd,
  1384. u8 *data)
  1385. {
  1386. struct iwl4965_addsta_cmd *addsta = (struct iwl4965_addsta_cmd *)data;
  1387. addsta->mode = cmd->mode;
  1388. memcpy(&addsta->sta, &cmd->sta, sizeof(struct sta_id_modify));
  1389. memcpy(&addsta->key, &cmd->key, sizeof(struct iwl4965_keyinfo));
  1390. addsta->station_flags = cmd->station_flags;
  1391. addsta->station_flags_msk = cmd->station_flags_msk;
  1392. addsta->tid_disable_tx = cmd->tid_disable_tx;
  1393. addsta->add_immediate_ba_tid = cmd->add_immediate_ba_tid;
  1394. addsta->remove_immediate_ba_tid = cmd->remove_immediate_ba_tid;
  1395. addsta->add_immediate_ba_ssn = cmd->add_immediate_ba_ssn;
  1396. addsta->sleep_tx_count = cmd->sleep_tx_count;
  1397. addsta->reserved1 = cpu_to_le16(0);
  1398. addsta->reserved2 = cpu_to_le16(0);
  1399. return (u16)sizeof(struct iwl4965_addsta_cmd);
  1400. }
  1401. static inline u32 iwl4965_get_scd_ssn(struct iwl4965_tx_resp *tx_resp)
  1402. {
  1403. return le32_to_cpup(&tx_resp->u.status + tx_resp->frame_count) & MAX_SN;
  1404. }
  1405. /**
  1406. * iwl4965_tx_status_reply_tx - Handle Tx response for frames in aggregation queue
  1407. */
  1408. static int iwl4965_tx_status_reply_tx(struct iwl_priv *priv,
  1409. struct iwl_ht_agg *agg,
  1410. struct iwl4965_tx_resp *tx_resp,
  1411. int txq_id, u16 start_idx)
  1412. {
  1413. u16 status;
  1414. struct agg_tx_status *frame_status = tx_resp->u.agg_status;
  1415. struct ieee80211_tx_info *info = NULL;
  1416. struct ieee80211_hdr *hdr = NULL;
  1417. u32 rate_n_flags = le32_to_cpu(tx_resp->rate_n_flags);
  1418. int i, sh, idx;
  1419. u16 seq;
  1420. if (agg->wait_for_ba)
  1421. IWL_DEBUG_TX_REPLY(priv, "got tx response w/o block-ack\n");
  1422. agg->frame_count = tx_resp->frame_count;
  1423. agg->start_idx = start_idx;
  1424. agg->rate_n_flags = rate_n_flags;
  1425. agg->bitmap = 0;
  1426. /* num frames attempted by Tx command */
  1427. if (agg->frame_count == 1) {
  1428. /* Only one frame was attempted; no block-ack will arrive */
  1429. status = le16_to_cpu(frame_status[0].status);
  1430. idx = start_idx;
  1431. IWL_DEBUG_TX_REPLY(priv, "FrameCnt = %d, StartIdx=%d idx=%d\n",
  1432. agg->frame_count, agg->start_idx, idx);
  1433. info = IEEE80211_SKB_CB(priv->txq[txq_id].txb[idx].skb);
  1434. info->status.rates[0].count = tx_resp->failure_frame + 1;
  1435. info->flags &= ~IEEE80211_TX_CTL_AMPDU;
  1436. info->flags |= iwl4965_tx_status_to_mac80211(status);
  1437. iwl4965_hwrate_to_tx_control(priv, rate_n_flags, info);
  1438. IWL_DEBUG_TX_REPLY(priv, "1 Frame 0x%x failure :%d\n",
  1439. status & 0xff, tx_resp->failure_frame);
  1440. IWL_DEBUG_TX_REPLY(priv, "Rate Info rate_n_flags=%x\n", rate_n_flags);
  1441. agg->wait_for_ba = 0;
  1442. } else {
  1443. /* Two or more frames were attempted; expect block-ack */
  1444. u64 bitmap = 0;
  1445. int start = agg->start_idx;
  1446. /* Construct bit-map of pending frames within Tx window */
  1447. for (i = 0; i < agg->frame_count; i++) {
  1448. u16 sc;
  1449. status = le16_to_cpu(frame_status[i].status);
  1450. seq = le16_to_cpu(frame_status[i].sequence);
  1451. idx = SEQ_TO_INDEX(seq);
  1452. txq_id = SEQ_TO_QUEUE(seq);
  1453. if (status & (AGG_TX_STATE_FEW_BYTES_MSK |
  1454. AGG_TX_STATE_ABORT_MSK))
  1455. continue;
  1456. IWL_DEBUG_TX_REPLY(priv, "FrameCnt = %d, txq_id=%d idx=%d\n",
  1457. agg->frame_count, txq_id, idx);
  1458. hdr = iwl_legacy_tx_queue_get_hdr(priv, txq_id, idx);
  1459. if (!hdr) {
  1460. IWL_ERR(priv,
  1461. "BUG_ON idx doesn't point to valid skb"
  1462. " idx=%d, txq_id=%d\n", idx, txq_id);
  1463. return -1;
  1464. }
  1465. sc = le16_to_cpu(hdr->seq_ctrl);
  1466. if (idx != (SEQ_TO_SN(sc) & 0xff)) {
  1467. IWL_ERR(priv,
  1468. "BUG_ON idx doesn't match seq control"
  1469. " idx=%d, seq_idx=%d, seq=%d\n",
  1470. idx, SEQ_TO_SN(sc), hdr->seq_ctrl);
  1471. return -1;
  1472. }
  1473. IWL_DEBUG_TX_REPLY(priv, "AGG Frame i=%d idx %d seq=%d\n",
  1474. i, idx, SEQ_TO_SN(sc));
  1475. sh = idx - start;
  1476. if (sh > 64) {
  1477. sh = (start - idx) + 0xff;
  1478. bitmap = bitmap << sh;
  1479. sh = 0;
  1480. start = idx;
  1481. } else if (sh < -64)
  1482. sh = 0xff - (start - idx);
  1483. else if (sh < 0) {
  1484. sh = start - idx;
  1485. start = idx;
  1486. bitmap = bitmap << sh;
  1487. sh = 0;
  1488. }
  1489. bitmap |= 1ULL << sh;
  1490. IWL_DEBUG_TX_REPLY(priv, "start=%d bitmap=0x%llx\n",
  1491. start, (unsigned long long)bitmap);
  1492. }
  1493. agg->bitmap = bitmap;
  1494. agg->start_idx = start;
  1495. IWL_DEBUG_TX_REPLY(priv, "Frames %d start_idx=%d bitmap=0x%llx\n",
  1496. agg->frame_count, agg->start_idx,
  1497. (unsigned long long)agg->bitmap);
  1498. if (bitmap)
  1499. agg->wait_for_ba = 1;
  1500. }
  1501. return 0;
  1502. }
  1503. static u8 iwl4965_find_station(struct iwl_priv *priv, const u8 *addr)
  1504. {
  1505. int i;
  1506. int start = 0;
  1507. int ret = IWL_INVALID_STATION;
  1508. unsigned long flags;
  1509. if ((priv->iw_mode == NL80211_IFTYPE_ADHOC))
  1510. start = IWL_STA_ID;
  1511. if (is_broadcast_ether_addr(addr))
  1512. return priv->contexts[IWL_RXON_CTX_BSS].bcast_sta_id;
  1513. spin_lock_irqsave(&priv->sta_lock, flags);
  1514. for (i = start; i < priv->hw_params.max_stations; i++)
  1515. if (priv->stations[i].used &&
  1516. (!compare_ether_addr(priv->stations[i].sta.sta.addr,
  1517. addr))) {
  1518. ret = i;
  1519. goto out;
  1520. }
  1521. IWL_DEBUG_ASSOC_LIMIT(priv, "can not find STA %pM total %d\n",
  1522. addr, priv->num_stations);
  1523. out:
  1524. /*
  1525. * It may be possible that more commands interacting with stations
  1526. * arrive before we completed processing the adding of
  1527. * station
  1528. */
  1529. if (ret != IWL_INVALID_STATION &&
  1530. (!(priv->stations[ret].used & IWL_STA_UCODE_ACTIVE) ||
  1531. ((priv->stations[ret].used & IWL_STA_UCODE_ACTIVE) &&
  1532. (priv->stations[ret].used & IWL_STA_UCODE_INPROGRESS)))) {
  1533. IWL_ERR(priv, "Requested station info for sta %d before ready.\n",
  1534. ret);
  1535. ret = IWL_INVALID_STATION;
  1536. }
  1537. spin_unlock_irqrestore(&priv->sta_lock, flags);
  1538. return ret;
  1539. }
  1540. static int iwl4965_get_ra_sta_id(struct iwl_priv *priv, struct ieee80211_hdr *hdr)
  1541. {
  1542. if (priv->iw_mode == NL80211_IFTYPE_STATION) {
  1543. return IWL_AP_ID;
  1544. } else {
  1545. u8 *da = ieee80211_get_DA(hdr);
  1546. return iwl4965_find_station(priv, da);
  1547. }
  1548. }
  1549. /**
  1550. * iwl4965_rx_reply_tx - Handle standard (non-aggregation) Tx response
  1551. */
  1552. static void iwl4965_rx_reply_tx(struct iwl_priv *priv,
  1553. struct iwl_rx_mem_buffer *rxb)
  1554. {
  1555. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  1556. u16 sequence = le16_to_cpu(pkt->hdr.sequence);
  1557. int txq_id = SEQ_TO_QUEUE(sequence);
  1558. int index = SEQ_TO_INDEX(sequence);
  1559. struct iwl_tx_queue *txq = &priv->txq[txq_id];
  1560. struct ieee80211_hdr *hdr;
  1561. struct ieee80211_tx_info *info;
  1562. struct iwl4965_tx_resp *tx_resp = (void *)&pkt->u.raw[0];
  1563. u32 status = le32_to_cpu(tx_resp->u.status);
  1564. int uninitialized_var(tid);
  1565. int sta_id;
  1566. int freed;
  1567. u8 *qc = NULL;
  1568. unsigned long flags;
  1569. if ((index >= txq->q.n_bd) || (iwl_legacy_queue_used(&txq->q, index) == 0)) {
  1570. IWL_ERR(priv, "Read index for DMA queue txq_id (%d) index %d "
  1571. "is out of range [0-%d] %d %d\n", txq_id,
  1572. index, txq->q.n_bd, txq->q.write_ptr,
  1573. txq->q.read_ptr);
  1574. return;
  1575. }
  1576. txq->time_stamp = jiffies;
  1577. info = IEEE80211_SKB_CB(txq->txb[txq->q.read_ptr].skb);
  1578. memset(&info->status, 0, sizeof(info->status));
  1579. hdr = iwl_legacy_tx_queue_get_hdr(priv, txq_id, index);
  1580. if (ieee80211_is_data_qos(hdr->frame_control)) {
  1581. qc = ieee80211_get_qos_ctl(hdr);
  1582. tid = qc[0] & 0xf;
  1583. }
  1584. sta_id = iwl4965_get_ra_sta_id(priv, hdr);
  1585. if (txq->sched_retry && unlikely(sta_id == IWL_INVALID_STATION)) {
  1586. IWL_ERR(priv, "Station not known\n");
  1587. return;
  1588. }
  1589. spin_lock_irqsave(&priv->sta_lock, flags);
  1590. if (txq->sched_retry) {
  1591. const u32 scd_ssn = iwl4965_get_scd_ssn(tx_resp);
  1592. struct iwl_ht_agg *agg = NULL;
  1593. WARN_ON(!qc);
  1594. agg = &priv->stations[sta_id].tid[tid].agg;
  1595. iwl4965_tx_status_reply_tx(priv, agg, tx_resp, txq_id, index);
  1596. /* check if BAR is needed */
  1597. if ((tx_resp->frame_count == 1) && !iwl4965_is_tx_success(status))
  1598. info->flags |= IEEE80211_TX_STAT_AMPDU_NO_BACK;
  1599. if (txq->q.read_ptr != (scd_ssn & 0xff)) {
  1600. index = iwl_legacy_queue_dec_wrap(scd_ssn & 0xff,
  1601. txq->q.n_bd);
  1602. IWL_DEBUG_TX_REPLY(priv, "Retry scheduler reclaim scd_ssn "
  1603. "%d index %d\n", scd_ssn , index);
  1604. freed = iwl4965_tx_queue_reclaim(priv, txq_id, index);
  1605. if (qc)
  1606. iwl4965_free_tfds_in_queue(priv, sta_id,
  1607. tid, freed);
  1608. if (priv->mac80211_registered &&
  1609. (iwl_legacy_queue_space(&txq->q) > txq->q.low_mark)
  1610. && (agg->state != IWL_EMPTYING_HW_QUEUE_DELBA))
  1611. iwl_legacy_wake_queue(priv, txq);
  1612. }
  1613. } else {
  1614. info->status.rates[0].count = tx_resp->failure_frame + 1;
  1615. info->flags |= iwl4965_tx_status_to_mac80211(status);
  1616. iwl4965_hwrate_to_tx_control(priv,
  1617. le32_to_cpu(tx_resp->rate_n_flags),
  1618. info);
  1619. IWL_DEBUG_TX_REPLY(priv, "TXQ %d status %s (0x%08x) "
  1620. "rate_n_flags 0x%x retries %d\n",
  1621. txq_id,
  1622. iwl4965_get_tx_fail_reason(status), status,
  1623. le32_to_cpu(tx_resp->rate_n_flags),
  1624. tx_resp->failure_frame);
  1625. freed = iwl4965_tx_queue_reclaim(priv, txq_id, index);
  1626. if (qc && likely(sta_id != IWL_INVALID_STATION))
  1627. iwl4965_free_tfds_in_queue(priv, sta_id, tid, freed);
  1628. else if (sta_id == IWL_INVALID_STATION)
  1629. IWL_DEBUG_TX_REPLY(priv, "Station not known\n");
  1630. if (priv->mac80211_registered &&
  1631. (iwl_legacy_queue_space(&txq->q) > txq->q.low_mark))
  1632. iwl_legacy_wake_queue(priv, txq);
  1633. }
  1634. if (qc && likely(sta_id != IWL_INVALID_STATION))
  1635. iwl4965_txq_check_empty(priv, sta_id, tid, txq_id);
  1636. iwl4965_check_abort_status(priv, tx_resp->frame_count, status);
  1637. spin_unlock_irqrestore(&priv->sta_lock, flags);
  1638. }
  1639. static void iwl4965_rx_beacon_notif(struct iwl_priv *priv,
  1640. struct iwl_rx_mem_buffer *rxb)
  1641. {
  1642. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  1643. struct iwl4965_beacon_notif *beacon = (void *)pkt->u.raw;
  1644. u8 rate __maybe_unused =
  1645. iwl4965_hw_get_rate(beacon->beacon_notify_hdr.rate_n_flags);
  1646. IWL_DEBUG_RX(priv, "beacon status %#x, retries:%d ibssmgr:%d "
  1647. "tsf:0x%.8x%.8x rate:%d\n",
  1648. le32_to_cpu(beacon->beacon_notify_hdr.u.status) & TX_STATUS_MSK,
  1649. beacon->beacon_notify_hdr.failure_frame,
  1650. le32_to_cpu(beacon->ibss_mgr_status),
  1651. le32_to_cpu(beacon->high_tsf),
  1652. le32_to_cpu(beacon->low_tsf), rate);
  1653. priv->ibss_manager = le32_to_cpu(beacon->ibss_mgr_status);
  1654. }
  1655. /* Set up 4965-specific Rx frame reply handlers */
  1656. static void iwl4965_rx_handler_setup(struct iwl_priv *priv)
  1657. {
  1658. /* Legacy Rx frames */
  1659. priv->rx_handlers[REPLY_RX] = iwl4965_rx_reply_rx;
  1660. /* Tx response */
  1661. priv->rx_handlers[REPLY_TX] = iwl4965_rx_reply_tx;
  1662. priv->rx_handlers[BEACON_NOTIFICATION] = iwl4965_rx_beacon_notif;
  1663. }
  1664. static struct iwl_hcmd_ops iwl4965_hcmd = {
  1665. .rxon_assoc = iwl4965_send_rxon_assoc,
  1666. .commit_rxon = iwl4965_commit_rxon,
  1667. .set_rxon_chain = iwl4965_set_rxon_chain,
  1668. };
  1669. static void iwl4965_post_scan(struct iwl_priv *priv)
  1670. {
  1671. struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
  1672. /*
  1673. * Since setting the RXON may have been deferred while
  1674. * performing the scan, fire one off if needed
  1675. */
  1676. if (memcmp(&ctx->staging, &ctx->active, sizeof(ctx->staging)))
  1677. iwl_legacy_commit_rxon(priv, ctx);
  1678. }
  1679. static void iwl4965_post_associate(struct iwl_priv *priv)
  1680. {
  1681. struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
  1682. struct ieee80211_vif *vif = ctx->vif;
  1683. struct ieee80211_conf *conf = NULL;
  1684. int ret = 0;
  1685. if (!vif || !priv->is_open)
  1686. return;
  1687. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  1688. return;
  1689. iwl_legacy_scan_cancel_timeout(priv, 200);
  1690. conf = iwl_legacy_ieee80211_get_hw_conf(priv->hw);
  1691. ctx->staging.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  1692. iwl_legacy_commit_rxon(priv, ctx);
  1693. ret = iwl_legacy_send_rxon_timing(priv, ctx);
  1694. if (ret)
  1695. IWL_WARN(priv, "RXON timing - "
  1696. "Attempting to continue.\n");
  1697. ctx->staging.filter_flags |= RXON_FILTER_ASSOC_MSK;
  1698. iwl_legacy_set_rxon_ht(priv, &priv->current_ht_config);
  1699. if (priv->cfg->ops->hcmd->set_rxon_chain)
  1700. priv->cfg->ops->hcmd->set_rxon_chain(priv, ctx);
  1701. ctx->staging.assoc_id = cpu_to_le16(vif->bss_conf.aid);
  1702. IWL_DEBUG_ASSOC(priv, "assoc id %d beacon interval %d\n",
  1703. vif->bss_conf.aid, vif->bss_conf.beacon_int);
  1704. if (vif->bss_conf.use_short_preamble)
  1705. ctx->staging.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
  1706. else
  1707. ctx->staging.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
  1708. if (ctx->staging.flags & RXON_FLG_BAND_24G_MSK) {
  1709. if (vif->bss_conf.use_short_slot)
  1710. ctx->staging.flags |= RXON_FLG_SHORT_SLOT_MSK;
  1711. else
  1712. ctx->staging.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
  1713. }
  1714. iwl_legacy_commit_rxon(priv, ctx);
  1715. IWL_DEBUG_ASSOC(priv, "Associated as %d to: %pM\n",
  1716. vif->bss_conf.aid, ctx->active.bssid_addr);
  1717. switch (vif->type) {
  1718. case NL80211_IFTYPE_STATION:
  1719. break;
  1720. case NL80211_IFTYPE_ADHOC:
  1721. iwl4965_send_beacon_cmd(priv);
  1722. break;
  1723. default:
  1724. IWL_ERR(priv, "%s Should not be called in %d mode\n",
  1725. __func__, vif->type);
  1726. break;
  1727. }
  1728. /* the chain noise calibration will enabled PM upon completion
  1729. * If chain noise has already been run, then we need to enable
  1730. * power management here */
  1731. if (priv->chain_noise_data.state == IWL_CHAIN_NOISE_DONE)
  1732. iwl_legacy_power_update_mode(priv, false);
  1733. /* Enable Rx differential gain and sensitivity calibrations */
  1734. iwl4965_chain_noise_reset(priv);
  1735. priv->start_calib = 1;
  1736. }
  1737. static void iwl4965_config_ap(struct iwl_priv *priv)
  1738. {
  1739. struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
  1740. struct ieee80211_vif *vif = ctx->vif;
  1741. int ret = 0;
  1742. lockdep_assert_held(&priv->mutex);
  1743. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  1744. return;
  1745. /* The following should be done only at AP bring up */
  1746. if (!iwl_legacy_is_associated_ctx(ctx)) {
  1747. /* RXON - unassoc (to set timing command) */
  1748. ctx->staging.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  1749. iwl_legacy_commit_rxon(priv, ctx);
  1750. /* RXON Timing */
  1751. ret = iwl_legacy_send_rxon_timing(priv, ctx);
  1752. if (ret)
  1753. IWL_WARN(priv, "RXON timing failed - "
  1754. "Attempting to continue.\n");
  1755. /* AP has all antennas */
  1756. priv->chain_noise_data.active_chains =
  1757. priv->hw_params.valid_rx_ant;
  1758. iwl_legacy_set_rxon_ht(priv, &priv->current_ht_config);
  1759. if (priv->cfg->ops->hcmd->set_rxon_chain)
  1760. priv->cfg->ops->hcmd->set_rxon_chain(priv, ctx);
  1761. ctx->staging.assoc_id = 0;
  1762. if (vif->bss_conf.use_short_preamble)
  1763. ctx->staging.flags |=
  1764. RXON_FLG_SHORT_PREAMBLE_MSK;
  1765. else
  1766. ctx->staging.flags &=
  1767. ~RXON_FLG_SHORT_PREAMBLE_MSK;
  1768. if (ctx->staging.flags & RXON_FLG_BAND_24G_MSK) {
  1769. if (vif->bss_conf.use_short_slot)
  1770. ctx->staging.flags |=
  1771. RXON_FLG_SHORT_SLOT_MSK;
  1772. else
  1773. ctx->staging.flags &=
  1774. ~RXON_FLG_SHORT_SLOT_MSK;
  1775. }
  1776. /* need to send beacon cmd before committing assoc RXON! */
  1777. iwl4965_send_beacon_cmd(priv);
  1778. /* restore RXON assoc */
  1779. ctx->staging.filter_flags |= RXON_FILTER_ASSOC_MSK;
  1780. iwl_legacy_commit_rxon(priv, ctx);
  1781. }
  1782. iwl4965_send_beacon_cmd(priv);
  1783. }
  1784. static struct iwl_hcmd_utils_ops iwl4965_hcmd_utils = {
  1785. .get_hcmd_size = iwl4965_get_hcmd_size,
  1786. .build_addsta_hcmd = iwl4965_build_addsta_hcmd,
  1787. .request_scan = iwl4965_request_scan,
  1788. .post_scan = iwl4965_post_scan,
  1789. };
  1790. static struct iwl_lib_ops iwl4965_lib = {
  1791. .set_hw_params = iwl4965_hw_set_hw_params,
  1792. .txq_update_byte_cnt_tbl = iwl4965_txq_update_byte_cnt_tbl,
  1793. .txq_attach_buf_to_tfd = iwl4965_hw_txq_attach_buf_to_tfd,
  1794. .txq_free_tfd = iwl4965_hw_txq_free_tfd,
  1795. .txq_init = iwl4965_hw_tx_queue_init,
  1796. .rx_handler_setup = iwl4965_rx_handler_setup,
  1797. .is_valid_rtc_data_addr = iwl4965_hw_valid_rtc_data_addr,
  1798. .init_alive_start = iwl4965_init_alive_start,
  1799. .load_ucode = iwl4965_load_bsm,
  1800. .dump_nic_error_log = iwl4965_dump_nic_error_log,
  1801. .dump_fh = iwl4965_dump_fh,
  1802. .set_channel_switch = iwl4965_hw_channel_switch,
  1803. .apm_ops = {
  1804. .init = iwl_legacy_apm_init,
  1805. .config = iwl4965_nic_config,
  1806. },
  1807. .eeprom_ops = {
  1808. .regulatory_bands = {
  1809. EEPROM_REGULATORY_BAND_1_CHANNELS,
  1810. EEPROM_REGULATORY_BAND_2_CHANNELS,
  1811. EEPROM_REGULATORY_BAND_3_CHANNELS,
  1812. EEPROM_REGULATORY_BAND_4_CHANNELS,
  1813. EEPROM_REGULATORY_BAND_5_CHANNELS,
  1814. EEPROM_4965_REGULATORY_BAND_24_HT40_CHANNELS,
  1815. EEPROM_4965_REGULATORY_BAND_52_HT40_CHANNELS
  1816. },
  1817. .acquire_semaphore = iwl4965_eeprom_acquire_semaphore,
  1818. .release_semaphore = iwl4965_eeprom_release_semaphore,
  1819. },
  1820. .send_tx_power = iwl4965_send_tx_power,
  1821. .update_chain_flags = iwl4965_update_chain_flags,
  1822. .temp_ops = {
  1823. .temperature = iwl4965_temperature_calib,
  1824. },
  1825. .debugfs_ops = {
  1826. .rx_stats_read = iwl4965_ucode_rx_stats_read,
  1827. .tx_stats_read = iwl4965_ucode_tx_stats_read,
  1828. .general_stats_read = iwl4965_ucode_general_stats_read,
  1829. },
  1830. };
  1831. static const struct iwl_legacy_ops iwl4965_legacy_ops = {
  1832. .post_associate = iwl4965_post_associate,
  1833. .config_ap = iwl4965_config_ap,
  1834. .manage_ibss_station = iwl4965_manage_ibss_station,
  1835. .update_bcast_stations = iwl4965_update_bcast_stations,
  1836. };
  1837. struct ieee80211_ops iwl4965_hw_ops = {
  1838. .tx = iwl4965_mac_tx,
  1839. .start = iwl4965_mac_start,
  1840. .stop = iwl4965_mac_stop,
  1841. .add_interface = iwl_legacy_mac_add_interface,
  1842. .remove_interface = iwl_legacy_mac_remove_interface,
  1843. .change_interface = iwl_legacy_mac_change_interface,
  1844. .config = iwl_legacy_mac_config,
  1845. .configure_filter = iwl4965_configure_filter,
  1846. .set_key = iwl4965_mac_set_key,
  1847. .update_tkip_key = iwl4965_mac_update_tkip_key,
  1848. .conf_tx = iwl_legacy_mac_conf_tx,
  1849. .reset_tsf = iwl_legacy_mac_reset_tsf,
  1850. .bss_info_changed = iwl_legacy_mac_bss_info_changed,
  1851. .ampdu_action = iwl4965_mac_ampdu_action,
  1852. .hw_scan = iwl_legacy_mac_hw_scan,
  1853. .sta_add = iwl4965_mac_sta_add,
  1854. .sta_remove = iwl_legacy_mac_sta_remove,
  1855. .channel_switch = iwl4965_mac_channel_switch,
  1856. .tx_last_beacon = iwl_legacy_mac_tx_last_beacon,
  1857. };
  1858. static const struct iwl_ops iwl4965_ops = {
  1859. .lib = &iwl4965_lib,
  1860. .hcmd = &iwl4965_hcmd,
  1861. .utils = &iwl4965_hcmd_utils,
  1862. .led = &iwl4965_led_ops,
  1863. .legacy = &iwl4965_legacy_ops,
  1864. .ieee80211_ops = &iwl4965_hw_ops,
  1865. };
  1866. static struct iwl_base_params iwl4965_base_params = {
  1867. .eeprom_size = IWL4965_EEPROM_IMG_SIZE,
  1868. .num_of_queues = IWL49_NUM_QUEUES,
  1869. .num_of_ampdu_queues = IWL49_NUM_AMPDU_QUEUES,
  1870. .pll_cfg_val = 0,
  1871. .set_l0s = true,
  1872. .use_bsm = true,
  1873. .led_compensation = 61,
  1874. .chain_noise_num_beacons = IWL4965_CAL_NUM_BEACONS,
  1875. .wd_timeout = IWL_DEF_WD_TIMEOUT,
  1876. .temperature_kelvin = true,
  1877. .ucode_tracing = true,
  1878. .sensitivity_calib_by_driver = true,
  1879. .chain_noise_calib_by_driver = true,
  1880. };
  1881. struct iwl_cfg iwl4965_cfg = {
  1882. .name = "Intel(R) Wireless WiFi Link 4965AGN",
  1883. .fw_name_pre = IWL4965_FW_PRE,
  1884. .ucode_api_max = IWL4965_UCODE_API_MAX,
  1885. .ucode_api_min = IWL4965_UCODE_API_MIN,
  1886. .sku = IWL_SKU_A|IWL_SKU_G|IWL_SKU_N,
  1887. .valid_tx_ant = ANT_AB,
  1888. .valid_rx_ant = ANT_ABC,
  1889. .eeprom_ver = EEPROM_4965_EEPROM_VERSION,
  1890. .eeprom_calib_ver = EEPROM_4965_TX_POWER_VERSION,
  1891. .ops = &iwl4965_ops,
  1892. .mod_params = &iwl4965_mod_params,
  1893. .base_params = &iwl4965_base_params,
  1894. .led_mode = IWL_LED_BLINK,
  1895. /*
  1896. * Force use of chains B and C for scan RX on 5 GHz band
  1897. * because the device has off-channel reception on chain A.
  1898. */
  1899. .scan_rx_antennas[IEEE80211_BAND_5GHZ] = ANT_BC,
  1900. };
  1901. /* Module firmware */
  1902. MODULE_FIRMWARE(IWL4965_MODULE_FIRMWARE(IWL4965_UCODE_API_MAX));