iwl-5000.c 52 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2007 - 2009 Intel Corporation. All rights reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of version 2 of the GNU General Public License as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along with
  15. * this program; if not, write to the Free Software Foundation, Inc.,
  16. * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
  17. *
  18. * The full GNU General Public License is included in this distribution in the
  19. * file called LICENSE.
  20. *
  21. * Contact Information:
  22. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  23. *
  24. *****************************************************************************/
  25. #include <linux/kernel.h>
  26. #include <linux/module.h>
  27. #include <linux/init.h>
  28. #include <linux/pci.h>
  29. #include <linux/dma-mapping.h>
  30. #include <linux/delay.h>
  31. #include <linux/skbuff.h>
  32. #include <linux/netdevice.h>
  33. #include <linux/wireless.h>
  34. #include <net/mac80211.h>
  35. #include <linux/etherdevice.h>
  36. #include <asm/unaligned.h>
  37. #include "iwl-eeprom.h"
  38. #include "iwl-dev.h"
  39. #include "iwl-core.h"
  40. #include "iwl-io.h"
  41. #include "iwl-sta.h"
  42. #include "iwl-helpers.h"
  43. #include "iwl-5000-hw.h"
  44. #include "iwl-6000-hw.h"
  45. /* Highest firmware API version supported */
  46. #define IWL5000_UCODE_API_MAX 2
  47. #define IWL5150_UCODE_API_MAX 2
  48. /* Lowest firmware API version supported */
  49. #define IWL5000_UCODE_API_MIN 1
  50. #define IWL5150_UCODE_API_MIN 1
  51. #define IWL5000_FW_PRE "iwlwifi-5000-"
  52. #define _IWL5000_MODULE_FIRMWARE(api) IWL5000_FW_PRE #api ".ucode"
  53. #define IWL5000_MODULE_FIRMWARE(api) _IWL5000_MODULE_FIRMWARE(api)
  54. #define IWL5150_FW_PRE "iwlwifi-5150-"
  55. #define _IWL5150_MODULE_FIRMWARE(api) IWL5150_FW_PRE #api ".ucode"
  56. #define IWL5150_MODULE_FIRMWARE(api) _IWL5150_MODULE_FIRMWARE(api)
  57. static const u16 iwl5000_default_queue_to_tx_fifo[] = {
  58. IWL_TX_FIFO_AC3,
  59. IWL_TX_FIFO_AC2,
  60. IWL_TX_FIFO_AC1,
  61. IWL_TX_FIFO_AC0,
  62. IWL50_CMD_FIFO_NUM,
  63. IWL_TX_FIFO_HCCA_1,
  64. IWL_TX_FIFO_HCCA_2
  65. };
  66. /* FIXME: same implementation as 4965 */
  67. static int iwl5000_apm_stop_master(struct iwl_priv *priv)
  68. {
  69. unsigned long flags;
  70. spin_lock_irqsave(&priv->lock, flags);
  71. /* set stop master bit */
  72. iwl_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_STOP_MASTER);
  73. iwl_poll_direct_bit(priv, CSR_RESET,
  74. CSR_RESET_REG_FLAG_MASTER_DISABLED, 100);
  75. spin_unlock_irqrestore(&priv->lock, flags);
  76. IWL_DEBUG_INFO(priv, "stop master\n");
  77. return 0;
  78. }
  79. int iwl5000_apm_init(struct iwl_priv *priv)
  80. {
  81. int ret = 0;
  82. iwl_set_bit(priv, CSR_GIO_CHICKEN_BITS,
  83. CSR_GIO_CHICKEN_BITS_REG_BIT_DIS_L0S_EXIT_TIMER);
  84. /* disable L0s without affecting L1 :don't wait for ICH L0s bug W/A) */
  85. iwl_set_bit(priv, CSR_GIO_CHICKEN_BITS,
  86. CSR_GIO_CHICKEN_BITS_REG_BIT_L1A_NO_L0S_RX);
  87. /* Set FH wait threshold to maximum (HW error during stress W/A) */
  88. iwl_set_bit(priv, CSR_DBG_HPET_MEM_REG, CSR_DBG_HPET_MEM_REG_VAL);
  89. /* enable HAP INTA to move device L1a -> L0s */
  90. iwl_set_bit(priv, CSR_HW_IF_CONFIG_REG,
  91. CSR_HW_IF_CONFIG_REG_BIT_HAP_WAKE_L1A);
  92. if (priv->cfg->need_pll_cfg)
  93. iwl_set_bit(priv, CSR_ANA_PLL_CFG, CSR50_ANA_PLL_CFG_VAL);
  94. /* set "initialization complete" bit to move adapter
  95. * D0U* --> D0A* state */
  96. iwl_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
  97. /* wait for clock stabilization */
  98. ret = iwl_poll_direct_bit(priv, CSR_GP_CNTRL,
  99. CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, 25000);
  100. if (ret < 0) {
  101. IWL_DEBUG_INFO(priv, "Failed to init the card\n");
  102. return ret;
  103. }
  104. /* enable DMA */
  105. iwl_write_prph(priv, APMG_CLK_EN_REG, APMG_CLK_VAL_DMA_CLK_RQT);
  106. udelay(20);
  107. /* disable L1-Active */
  108. iwl_set_bits_prph(priv, APMG_PCIDEV_STT_REG,
  109. APMG_PCIDEV_STT_VAL_L1_ACT_DIS);
  110. return ret;
  111. }
  112. /* FIXME: this is identical to 4965 */
  113. void iwl5000_apm_stop(struct iwl_priv *priv)
  114. {
  115. unsigned long flags;
  116. iwl5000_apm_stop_master(priv);
  117. spin_lock_irqsave(&priv->lock, flags);
  118. iwl_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_SW_RESET);
  119. udelay(10);
  120. /* clear "init complete" move adapter D0A* --> D0U state */
  121. iwl_clear_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
  122. spin_unlock_irqrestore(&priv->lock, flags);
  123. }
  124. int iwl5000_apm_reset(struct iwl_priv *priv)
  125. {
  126. int ret = 0;
  127. iwl5000_apm_stop_master(priv);
  128. iwl_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_SW_RESET);
  129. udelay(10);
  130. /* FIXME: put here L1A -L0S w/a */
  131. if (priv->cfg->need_pll_cfg)
  132. iwl_set_bit(priv, CSR_ANA_PLL_CFG, CSR50_ANA_PLL_CFG_VAL);
  133. /* set "initialization complete" bit to move adapter
  134. * D0U* --> D0A* state */
  135. iwl_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
  136. /* wait for clock stabilization */
  137. ret = iwl_poll_direct_bit(priv, CSR_GP_CNTRL,
  138. CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, 25000);
  139. if (ret < 0) {
  140. IWL_DEBUG_INFO(priv, "Failed to init the card\n");
  141. goto out;
  142. }
  143. /* enable DMA */
  144. iwl_write_prph(priv, APMG_CLK_EN_REG, APMG_CLK_VAL_DMA_CLK_RQT);
  145. udelay(20);
  146. /* disable L1-Active */
  147. iwl_set_bits_prph(priv, APMG_PCIDEV_STT_REG,
  148. APMG_PCIDEV_STT_VAL_L1_ACT_DIS);
  149. out:
  150. return ret;
  151. }
  152. /* NIC configuration for 5000 series and up */
  153. void iwl5000_nic_config(struct iwl_priv *priv)
  154. {
  155. unsigned long flags;
  156. u16 radio_cfg;
  157. u16 lctl;
  158. spin_lock_irqsave(&priv->lock, flags);
  159. lctl = iwl_pcie_link_ctl(priv);
  160. /* HW bug W/A */
  161. /* L1-ASPM is enabled by BIOS */
  162. if ((lctl & PCI_CFG_LINK_CTRL_VAL_L1_EN) == PCI_CFG_LINK_CTRL_VAL_L1_EN)
  163. /* L1-APSM enabled: disable L0S */
  164. iwl_set_bit(priv, CSR_GIO_REG, CSR_GIO_REG_VAL_L0S_ENABLED);
  165. else
  166. /* L1-ASPM disabled: enable L0S */
  167. iwl_clear_bit(priv, CSR_GIO_REG, CSR_GIO_REG_VAL_L0S_ENABLED);
  168. radio_cfg = iwl_eeprom_query16(priv, EEPROM_RADIO_CONFIG);
  169. /* write radio config values to register */
  170. if (EEPROM_RF_CFG_TYPE_MSK(radio_cfg) < EEPROM_5000_RF_CFG_TYPE_MAX)
  171. iwl_set_bit(priv, CSR_HW_IF_CONFIG_REG,
  172. EEPROM_RF_CFG_TYPE_MSK(radio_cfg) |
  173. EEPROM_RF_CFG_STEP_MSK(radio_cfg) |
  174. EEPROM_RF_CFG_DASH_MSK(radio_cfg));
  175. /* set CSR_HW_CONFIG_REG for uCode use */
  176. iwl_set_bit(priv, CSR_HW_IF_CONFIG_REG,
  177. CSR_HW_IF_CONFIG_REG_BIT_RADIO_SI |
  178. CSR_HW_IF_CONFIG_REG_BIT_MAC_SI);
  179. /* W/A : NIC is stuck in a reset state after Early PCIe power off
  180. * (PCIe power is lost before PERST# is asserted),
  181. * causing ME FW to lose ownership and not being able to obtain it back.
  182. */
  183. iwl_set_bits_mask_prph(priv, APMG_PS_CTRL_REG,
  184. APMG_PS_CTRL_EARLY_PWR_OFF_RESET_DIS,
  185. ~APMG_PS_CTRL_EARLY_PWR_OFF_RESET_DIS);
  186. spin_unlock_irqrestore(&priv->lock, flags);
  187. }
  188. /*
  189. * EEPROM
  190. */
  191. static u32 eeprom_indirect_address(const struct iwl_priv *priv, u32 address)
  192. {
  193. u16 offset = 0;
  194. if ((address & INDIRECT_ADDRESS) == 0)
  195. return address;
  196. switch (address & INDIRECT_TYPE_MSK) {
  197. case INDIRECT_HOST:
  198. offset = iwl_eeprom_query16(priv, EEPROM_5000_LINK_HOST);
  199. break;
  200. case INDIRECT_GENERAL:
  201. offset = iwl_eeprom_query16(priv, EEPROM_5000_LINK_GENERAL);
  202. break;
  203. case INDIRECT_REGULATORY:
  204. offset = iwl_eeprom_query16(priv, EEPROM_5000_LINK_REGULATORY);
  205. break;
  206. case INDIRECT_CALIBRATION:
  207. offset = iwl_eeprom_query16(priv, EEPROM_5000_LINK_CALIBRATION);
  208. break;
  209. case INDIRECT_PROCESS_ADJST:
  210. offset = iwl_eeprom_query16(priv, EEPROM_5000_LINK_PROCESS_ADJST);
  211. break;
  212. case INDIRECT_OTHERS:
  213. offset = iwl_eeprom_query16(priv, EEPROM_5000_LINK_OTHERS);
  214. break;
  215. default:
  216. IWL_ERR(priv, "illegal indirect type: 0x%X\n",
  217. address & INDIRECT_TYPE_MSK);
  218. break;
  219. }
  220. /* translate the offset from words to byte */
  221. return (address & ADDRESS_MSK) + (offset << 1);
  222. }
  223. u16 iwl5000_eeprom_calib_version(struct iwl_priv *priv)
  224. {
  225. struct iwl_eeprom_calib_hdr {
  226. u8 version;
  227. u8 pa_type;
  228. u16 voltage;
  229. } *hdr;
  230. hdr = (struct iwl_eeprom_calib_hdr *)iwl_eeprom_query_addr(priv,
  231. EEPROM_5000_CALIB_ALL);
  232. return hdr->version;
  233. }
  234. static void iwl5000_gain_computation(struct iwl_priv *priv,
  235. u32 average_noise[NUM_RX_CHAINS],
  236. u16 min_average_noise_antenna_i,
  237. u32 min_average_noise)
  238. {
  239. int i;
  240. s32 delta_g;
  241. struct iwl_chain_noise_data *data = &priv->chain_noise_data;
  242. /* Find Gain Code for the antennas B and C */
  243. for (i = 1; i < NUM_RX_CHAINS; i++) {
  244. if ((data->disconn_array[i])) {
  245. data->delta_gain_code[i] = 0;
  246. continue;
  247. }
  248. delta_g = (1000 * ((s32)average_noise[0] -
  249. (s32)average_noise[i])) / 1500;
  250. /* bound gain by 2 bits value max, 3rd bit is sign */
  251. data->delta_gain_code[i] =
  252. min(abs(delta_g), (long) CHAIN_NOISE_MAX_DELTA_GAIN_CODE);
  253. if (delta_g < 0)
  254. /* set negative sign */
  255. data->delta_gain_code[i] |= (1 << 2);
  256. }
  257. IWL_DEBUG_CALIB(priv, "Delta gains: ANT_B = %d ANT_C = %d\n",
  258. data->delta_gain_code[1], data->delta_gain_code[2]);
  259. if (!data->radio_write) {
  260. struct iwl_calib_chain_noise_gain_cmd cmd;
  261. memset(&cmd, 0, sizeof(cmd));
  262. cmd.hdr.op_code = IWL_PHY_CALIBRATE_CHAIN_NOISE_GAIN_CMD;
  263. cmd.hdr.first_group = 0;
  264. cmd.hdr.groups_num = 1;
  265. cmd.hdr.data_valid = 1;
  266. cmd.delta_gain_1 = data->delta_gain_code[1];
  267. cmd.delta_gain_2 = data->delta_gain_code[2];
  268. iwl_send_cmd_pdu_async(priv, REPLY_PHY_CALIBRATION_CMD,
  269. sizeof(cmd), &cmd, NULL);
  270. data->radio_write = 1;
  271. data->state = IWL_CHAIN_NOISE_CALIBRATED;
  272. }
  273. data->chain_noise_a = 0;
  274. data->chain_noise_b = 0;
  275. data->chain_noise_c = 0;
  276. data->chain_signal_a = 0;
  277. data->chain_signal_b = 0;
  278. data->chain_signal_c = 0;
  279. data->beacon_count = 0;
  280. }
  281. static void iwl5000_chain_noise_reset(struct iwl_priv *priv)
  282. {
  283. struct iwl_chain_noise_data *data = &priv->chain_noise_data;
  284. int ret;
  285. if ((data->state == IWL_CHAIN_NOISE_ALIVE) && iwl_is_associated(priv)) {
  286. struct iwl_calib_chain_noise_reset_cmd cmd;
  287. memset(&cmd, 0, sizeof(cmd));
  288. cmd.hdr.op_code = IWL_PHY_CALIBRATE_CHAIN_NOISE_RESET_CMD;
  289. cmd.hdr.first_group = 0;
  290. cmd.hdr.groups_num = 1;
  291. cmd.hdr.data_valid = 1;
  292. ret = iwl_send_cmd_pdu(priv, REPLY_PHY_CALIBRATION_CMD,
  293. sizeof(cmd), &cmd);
  294. if (ret)
  295. IWL_ERR(priv,
  296. "Could not send REPLY_PHY_CALIBRATION_CMD\n");
  297. data->state = IWL_CHAIN_NOISE_ACCUMULATE;
  298. IWL_DEBUG_CALIB(priv, "Run chain_noise_calibrate\n");
  299. }
  300. }
  301. void iwl5000_rts_tx_cmd_flag(struct ieee80211_tx_info *info,
  302. __le32 *tx_flags)
  303. {
  304. if ((info->control.rates[0].flags & IEEE80211_TX_RC_USE_RTS_CTS) ||
  305. (info->control.rates[0].flags & IEEE80211_TX_RC_USE_CTS_PROTECT))
  306. *tx_flags |= TX_CMD_FLG_RTS_CTS_MSK;
  307. else
  308. *tx_flags &= ~TX_CMD_FLG_RTS_CTS_MSK;
  309. }
  310. static struct iwl_sensitivity_ranges iwl5000_sensitivity = {
  311. .min_nrg_cck = 95,
  312. .max_nrg_cck = 0, /* not used, set to 0 */
  313. .auto_corr_min_ofdm = 90,
  314. .auto_corr_min_ofdm_mrc = 170,
  315. .auto_corr_min_ofdm_x1 = 120,
  316. .auto_corr_min_ofdm_mrc_x1 = 240,
  317. .auto_corr_max_ofdm = 120,
  318. .auto_corr_max_ofdm_mrc = 210,
  319. .auto_corr_max_ofdm_x1 = 155,
  320. .auto_corr_max_ofdm_mrc_x1 = 290,
  321. .auto_corr_min_cck = 125,
  322. .auto_corr_max_cck = 200,
  323. .auto_corr_min_cck_mrc = 170,
  324. .auto_corr_max_cck_mrc = 400,
  325. .nrg_th_cck = 95,
  326. .nrg_th_ofdm = 95,
  327. };
  328. static struct iwl_sensitivity_ranges iwl5150_sensitivity = {
  329. .min_nrg_cck = 95,
  330. .max_nrg_cck = 0, /* not used, set to 0 */
  331. .auto_corr_min_ofdm = 90,
  332. .auto_corr_min_ofdm_mrc = 170,
  333. .auto_corr_min_ofdm_x1 = 105,
  334. .auto_corr_min_ofdm_mrc_x1 = 220,
  335. .auto_corr_max_ofdm = 120,
  336. .auto_corr_max_ofdm_mrc = 210,
  337. /* max = min for performance bug in 5150 DSP */
  338. .auto_corr_max_ofdm_x1 = 105,
  339. .auto_corr_max_ofdm_mrc_x1 = 220,
  340. .auto_corr_min_cck = 125,
  341. .auto_corr_max_cck = 200,
  342. .auto_corr_min_cck_mrc = 170,
  343. .auto_corr_max_cck_mrc = 400,
  344. .nrg_th_cck = 95,
  345. .nrg_th_ofdm = 95,
  346. };
  347. const u8 *iwl5000_eeprom_query_addr(const struct iwl_priv *priv,
  348. size_t offset)
  349. {
  350. u32 address = eeprom_indirect_address(priv, offset);
  351. BUG_ON(address >= priv->cfg->eeprom_size);
  352. return &priv->eeprom[address];
  353. }
  354. static void iwl5150_set_ct_threshold(struct iwl_priv *priv)
  355. {
  356. const s32 volt2temp_coef = IWL_5150_VOLTAGE_TO_TEMPERATURE_COEFF;
  357. s32 threshold = (s32)CELSIUS_TO_KELVIN(CT_KILL_THRESHOLD_LEGACY) -
  358. iwl_temp_calib_to_offset(priv);
  359. priv->hw_params.ct_kill_threshold = threshold * volt2temp_coef;
  360. }
  361. static void iwl5000_set_ct_threshold(struct iwl_priv *priv)
  362. {
  363. /* want Celsius */
  364. priv->hw_params.ct_kill_threshold = CT_KILL_THRESHOLD_LEGACY;
  365. }
  366. /*
  367. * Calibration
  368. */
  369. static int iwl5000_set_Xtal_calib(struct iwl_priv *priv)
  370. {
  371. struct iwl_calib_xtal_freq_cmd cmd;
  372. u16 *xtal_calib = (u16 *)iwl_eeprom_query_addr(priv, EEPROM_5000_XTAL);
  373. cmd.hdr.op_code = IWL_PHY_CALIBRATE_CRYSTAL_FRQ_CMD;
  374. cmd.hdr.first_group = 0;
  375. cmd.hdr.groups_num = 1;
  376. cmd.hdr.data_valid = 1;
  377. cmd.cap_pin1 = (u8)xtal_calib[0];
  378. cmd.cap_pin2 = (u8)xtal_calib[1];
  379. return iwl_calib_set(&priv->calib_results[IWL_CALIB_XTAL],
  380. (u8 *)&cmd, sizeof(cmd));
  381. }
  382. static int iwl5000_send_calib_cfg(struct iwl_priv *priv)
  383. {
  384. struct iwl_calib_cfg_cmd calib_cfg_cmd;
  385. struct iwl_host_cmd cmd = {
  386. .id = CALIBRATION_CFG_CMD,
  387. .len = sizeof(struct iwl_calib_cfg_cmd),
  388. .data = &calib_cfg_cmd,
  389. };
  390. memset(&calib_cfg_cmd, 0, sizeof(calib_cfg_cmd));
  391. calib_cfg_cmd.ucd_calib_cfg.once.is_enable = IWL_CALIB_INIT_CFG_ALL;
  392. calib_cfg_cmd.ucd_calib_cfg.once.start = IWL_CALIB_INIT_CFG_ALL;
  393. calib_cfg_cmd.ucd_calib_cfg.once.send_res = IWL_CALIB_INIT_CFG_ALL;
  394. calib_cfg_cmd.ucd_calib_cfg.flags = IWL_CALIB_INIT_CFG_ALL;
  395. return iwl_send_cmd(priv, &cmd);
  396. }
  397. static void iwl5000_rx_calib_result(struct iwl_priv *priv,
  398. struct iwl_rx_mem_buffer *rxb)
  399. {
  400. struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
  401. struct iwl_calib_hdr *hdr = (struct iwl_calib_hdr *)pkt->u.raw;
  402. int len = le32_to_cpu(pkt->len_n_flags) & FH_RSCSR_FRAME_SIZE_MSK;
  403. int index;
  404. /* reduce the size of the length field itself */
  405. len -= 4;
  406. /* Define the order in which the results will be sent to the runtime
  407. * uCode. iwl_send_calib_results sends them in a row according to their
  408. * index. We sort them here */
  409. switch (hdr->op_code) {
  410. case IWL_PHY_CALIBRATE_DC_CMD:
  411. index = IWL_CALIB_DC;
  412. break;
  413. case IWL_PHY_CALIBRATE_LO_CMD:
  414. index = IWL_CALIB_LO;
  415. break;
  416. case IWL_PHY_CALIBRATE_TX_IQ_CMD:
  417. index = IWL_CALIB_TX_IQ;
  418. break;
  419. case IWL_PHY_CALIBRATE_TX_IQ_PERD_CMD:
  420. index = IWL_CALIB_TX_IQ_PERD;
  421. break;
  422. case IWL_PHY_CALIBRATE_BASE_BAND_CMD:
  423. index = IWL_CALIB_BASE_BAND;
  424. break;
  425. default:
  426. IWL_ERR(priv, "Unknown calibration notification %d\n",
  427. hdr->op_code);
  428. return;
  429. }
  430. iwl_calib_set(&priv->calib_results[index], pkt->u.raw, len);
  431. }
  432. static void iwl5000_rx_calib_complete(struct iwl_priv *priv,
  433. struct iwl_rx_mem_buffer *rxb)
  434. {
  435. IWL_DEBUG_INFO(priv, "Init. calibration is completed, restarting fw.\n");
  436. queue_work(priv->workqueue, &priv->restart);
  437. }
  438. /*
  439. * ucode
  440. */
  441. static int iwl5000_load_section(struct iwl_priv *priv,
  442. struct fw_desc *image,
  443. u32 dst_addr)
  444. {
  445. dma_addr_t phy_addr = image->p_addr;
  446. u32 byte_cnt = image->len;
  447. iwl_write_direct32(priv,
  448. FH_TCSR_CHNL_TX_CONFIG_REG(FH_SRVC_CHNL),
  449. FH_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_PAUSE);
  450. iwl_write_direct32(priv,
  451. FH_SRVC_CHNL_SRAM_ADDR_REG(FH_SRVC_CHNL), dst_addr);
  452. iwl_write_direct32(priv,
  453. FH_TFDIB_CTRL0_REG(FH_SRVC_CHNL),
  454. phy_addr & FH_MEM_TFDIB_DRAM_ADDR_LSB_MSK);
  455. iwl_write_direct32(priv,
  456. FH_TFDIB_CTRL1_REG(FH_SRVC_CHNL),
  457. (iwl_get_dma_hi_addr(phy_addr)
  458. << FH_MEM_TFDIB_REG1_ADDR_BITSHIFT) | byte_cnt);
  459. iwl_write_direct32(priv,
  460. FH_TCSR_CHNL_TX_BUF_STS_REG(FH_SRVC_CHNL),
  461. 1 << FH_TCSR_CHNL_TX_BUF_STS_REG_POS_TB_NUM |
  462. 1 << FH_TCSR_CHNL_TX_BUF_STS_REG_POS_TB_IDX |
  463. FH_TCSR_CHNL_TX_BUF_STS_REG_VAL_TFDB_VALID);
  464. iwl_write_direct32(priv,
  465. FH_TCSR_CHNL_TX_CONFIG_REG(FH_SRVC_CHNL),
  466. FH_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_ENABLE |
  467. FH_TCSR_TX_CONFIG_REG_VAL_DMA_CREDIT_DISABLE |
  468. FH_TCSR_TX_CONFIG_REG_VAL_CIRQ_HOST_ENDTFD);
  469. return 0;
  470. }
  471. static int iwl5000_load_given_ucode(struct iwl_priv *priv,
  472. struct fw_desc *inst_image,
  473. struct fw_desc *data_image)
  474. {
  475. int ret = 0;
  476. ret = iwl5000_load_section(priv, inst_image,
  477. IWL50_RTC_INST_LOWER_BOUND);
  478. if (ret)
  479. return ret;
  480. IWL_DEBUG_INFO(priv, "INST uCode section being loaded...\n");
  481. ret = wait_event_interruptible_timeout(priv->wait_command_queue,
  482. priv->ucode_write_complete, 5 * HZ);
  483. if (ret == -ERESTARTSYS) {
  484. IWL_ERR(priv, "Could not load the INST uCode section due "
  485. "to interrupt\n");
  486. return ret;
  487. }
  488. if (!ret) {
  489. IWL_ERR(priv, "Could not load the INST uCode section\n");
  490. return -ETIMEDOUT;
  491. }
  492. priv->ucode_write_complete = 0;
  493. ret = iwl5000_load_section(
  494. priv, data_image, IWL50_RTC_DATA_LOWER_BOUND);
  495. if (ret)
  496. return ret;
  497. IWL_DEBUG_INFO(priv, "DATA uCode section being loaded...\n");
  498. ret = wait_event_interruptible_timeout(priv->wait_command_queue,
  499. priv->ucode_write_complete, 5 * HZ);
  500. if (ret == -ERESTARTSYS) {
  501. IWL_ERR(priv, "Could not load the INST uCode section due "
  502. "to interrupt\n");
  503. return ret;
  504. } else if (!ret) {
  505. IWL_ERR(priv, "Could not load the DATA uCode section\n");
  506. return -ETIMEDOUT;
  507. } else
  508. ret = 0;
  509. priv->ucode_write_complete = 0;
  510. return ret;
  511. }
  512. int iwl5000_load_ucode(struct iwl_priv *priv)
  513. {
  514. int ret = 0;
  515. /* check whether init ucode should be loaded, or rather runtime ucode */
  516. if (priv->ucode_init.len && (priv->ucode_type == UCODE_NONE)) {
  517. IWL_DEBUG_INFO(priv, "Init ucode found. Loading init ucode...\n");
  518. ret = iwl5000_load_given_ucode(priv,
  519. &priv->ucode_init, &priv->ucode_init_data);
  520. if (!ret) {
  521. IWL_DEBUG_INFO(priv, "Init ucode load complete.\n");
  522. priv->ucode_type = UCODE_INIT;
  523. }
  524. } else {
  525. IWL_DEBUG_INFO(priv, "Init ucode not found, or already loaded. "
  526. "Loading runtime ucode...\n");
  527. ret = iwl5000_load_given_ucode(priv,
  528. &priv->ucode_code, &priv->ucode_data);
  529. if (!ret) {
  530. IWL_DEBUG_INFO(priv, "Runtime ucode load complete.\n");
  531. priv->ucode_type = UCODE_RT;
  532. }
  533. }
  534. return ret;
  535. }
  536. void iwl5000_init_alive_start(struct iwl_priv *priv)
  537. {
  538. int ret = 0;
  539. /* Check alive response for "valid" sign from uCode */
  540. if (priv->card_alive_init.is_valid != UCODE_VALID_OK) {
  541. /* We had an error bringing up the hardware, so take it
  542. * all the way back down so we can try again */
  543. IWL_DEBUG_INFO(priv, "Initialize Alive failed.\n");
  544. goto restart;
  545. }
  546. /* initialize uCode was loaded... verify inst image.
  547. * This is a paranoid check, because we would not have gotten the
  548. * "initialize" alive if code weren't properly loaded. */
  549. if (iwl_verify_ucode(priv)) {
  550. /* Runtime instruction load was bad;
  551. * take it all the way back down so we can try again */
  552. IWL_DEBUG_INFO(priv, "Bad \"initialize\" uCode load.\n");
  553. goto restart;
  554. }
  555. iwl_clear_stations_table(priv);
  556. ret = priv->cfg->ops->lib->alive_notify(priv);
  557. if (ret) {
  558. IWL_WARN(priv,
  559. "Could not complete ALIVE transition: %d\n", ret);
  560. goto restart;
  561. }
  562. iwl5000_send_calib_cfg(priv);
  563. return;
  564. restart:
  565. /* real restart (first load init_ucode) */
  566. queue_work(priv->workqueue, &priv->restart);
  567. }
  568. static void iwl5000_set_wr_ptrs(struct iwl_priv *priv,
  569. int txq_id, u32 index)
  570. {
  571. iwl_write_direct32(priv, HBUS_TARG_WRPTR,
  572. (index & 0xff) | (txq_id << 8));
  573. iwl_write_prph(priv, IWL50_SCD_QUEUE_RDPTR(txq_id), index);
  574. }
  575. static void iwl5000_tx_queue_set_status(struct iwl_priv *priv,
  576. struct iwl_tx_queue *txq,
  577. int tx_fifo_id, int scd_retry)
  578. {
  579. int txq_id = txq->q.id;
  580. int active = test_bit(txq_id, &priv->txq_ctx_active_msk) ? 1 : 0;
  581. iwl_write_prph(priv, IWL50_SCD_QUEUE_STATUS_BITS(txq_id),
  582. (active << IWL50_SCD_QUEUE_STTS_REG_POS_ACTIVE) |
  583. (tx_fifo_id << IWL50_SCD_QUEUE_STTS_REG_POS_TXF) |
  584. (1 << IWL50_SCD_QUEUE_STTS_REG_POS_WSL) |
  585. IWL50_SCD_QUEUE_STTS_REG_MSK);
  586. txq->sched_retry = scd_retry;
  587. IWL_DEBUG_INFO(priv, "%s %s Queue %d on AC %d\n",
  588. active ? "Activate" : "Deactivate",
  589. scd_retry ? "BA" : "AC", txq_id, tx_fifo_id);
  590. }
  591. static int iwl5000_send_wimax_coex(struct iwl_priv *priv)
  592. {
  593. struct iwl_wimax_coex_cmd coex_cmd;
  594. memset(&coex_cmd, 0, sizeof(coex_cmd));
  595. return iwl_send_cmd_pdu(priv, COEX_PRIORITY_TABLE_CMD,
  596. sizeof(coex_cmd), &coex_cmd);
  597. }
  598. int iwl5000_alive_notify(struct iwl_priv *priv)
  599. {
  600. u32 a;
  601. unsigned long flags;
  602. int i, chan;
  603. u32 reg_val;
  604. spin_lock_irqsave(&priv->lock, flags);
  605. priv->scd_base_addr = iwl_read_prph(priv, IWL50_SCD_SRAM_BASE_ADDR);
  606. a = priv->scd_base_addr + IWL50_SCD_CONTEXT_DATA_OFFSET;
  607. for (; a < priv->scd_base_addr + IWL50_SCD_TX_STTS_BITMAP_OFFSET;
  608. a += 4)
  609. iwl_write_targ_mem(priv, a, 0);
  610. for (; a < priv->scd_base_addr + IWL50_SCD_TRANSLATE_TBL_OFFSET;
  611. a += 4)
  612. iwl_write_targ_mem(priv, a, 0);
  613. for (; a < sizeof(u16) * priv->hw_params.max_txq_num; a += 4)
  614. iwl_write_targ_mem(priv, a, 0);
  615. iwl_write_prph(priv, IWL50_SCD_DRAM_BASE_ADDR,
  616. priv->scd_bc_tbls.dma >> 10);
  617. /* Enable DMA channel */
  618. for (chan = 0; chan < FH50_TCSR_CHNL_NUM ; chan++)
  619. iwl_write_direct32(priv, FH_TCSR_CHNL_TX_CONFIG_REG(chan),
  620. FH_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_ENABLE |
  621. FH_TCSR_TX_CONFIG_REG_VAL_DMA_CREDIT_ENABLE);
  622. /* Update FH chicken bits */
  623. reg_val = iwl_read_direct32(priv, FH_TX_CHICKEN_BITS_REG);
  624. iwl_write_direct32(priv, FH_TX_CHICKEN_BITS_REG,
  625. reg_val | FH_TX_CHICKEN_BITS_SCD_AUTO_RETRY_EN);
  626. iwl_write_prph(priv, IWL50_SCD_QUEUECHAIN_SEL,
  627. IWL50_SCD_QUEUECHAIN_SEL_ALL(priv->hw_params.max_txq_num));
  628. iwl_write_prph(priv, IWL50_SCD_AGGR_SEL, 0);
  629. /* initiate the queues */
  630. for (i = 0; i < priv->hw_params.max_txq_num; i++) {
  631. iwl_write_prph(priv, IWL50_SCD_QUEUE_RDPTR(i), 0);
  632. iwl_write_direct32(priv, HBUS_TARG_WRPTR, 0 | (i << 8));
  633. iwl_write_targ_mem(priv, priv->scd_base_addr +
  634. IWL50_SCD_CONTEXT_QUEUE_OFFSET(i), 0);
  635. iwl_write_targ_mem(priv, priv->scd_base_addr +
  636. IWL50_SCD_CONTEXT_QUEUE_OFFSET(i) +
  637. sizeof(u32),
  638. ((SCD_WIN_SIZE <<
  639. IWL50_SCD_QUEUE_CTX_REG2_WIN_SIZE_POS) &
  640. IWL50_SCD_QUEUE_CTX_REG2_WIN_SIZE_MSK) |
  641. ((SCD_FRAME_LIMIT <<
  642. IWL50_SCD_QUEUE_CTX_REG2_FRAME_LIMIT_POS) &
  643. IWL50_SCD_QUEUE_CTX_REG2_FRAME_LIMIT_MSK));
  644. }
  645. iwl_write_prph(priv, IWL50_SCD_INTERRUPT_MASK,
  646. IWL_MASK(0, priv->hw_params.max_txq_num));
  647. /* Activate all Tx DMA/FIFO channels */
  648. priv->cfg->ops->lib->txq_set_sched(priv, IWL_MASK(0, 7));
  649. iwl5000_set_wr_ptrs(priv, IWL_CMD_QUEUE_NUM, 0);
  650. /* map qos queues to fifos one-to-one */
  651. for (i = 0; i < ARRAY_SIZE(iwl5000_default_queue_to_tx_fifo); i++) {
  652. int ac = iwl5000_default_queue_to_tx_fifo[i];
  653. iwl_txq_ctx_activate(priv, i);
  654. iwl5000_tx_queue_set_status(priv, &priv->txq[i], ac, 0);
  655. }
  656. /* TODO - need to initialize those FIFOs inside the loop above,
  657. * not only mark them as active */
  658. iwl_txq_ctx_activate(priv, 4);
  659. iwl_txq_ctx_activate(priv, 7);
  660. iwl_txq_ctx_activate(priv, 8);
  661. iwl_txq_ctx_activate(priv, 9);
  662. spin_unlock_irqrestore(&priv->lock, flags);
  663. iwl5000_send_wimax_coex(priv);
  664. iwl5000_set_Xtal_calib(priv);
  665. iwl_send_calib_results(priv);
  666. return 0;
  667. }
  668. int iwl5000_hw_set_hw_params(struct iwl_priv *priv)
  669. {
  670. if ((priv->cfg->mod_params->num_of_queues > IWL50_NUM_QUEUES) ||
  671. (priv->cfg->mod_params->num_of_queues < IWL_MIN_NUM_QUEUES)) {
  672. IWL_ERR(priv,
  673. "invalid queues_num, should be between %d and %d\n",
  674. IWL_MIN_NUM_QUEUES, IWL50_NUM_QUEUES);
  675. return -EINVAL;
  676. }
  677. priv->hw_params.max_txq_num = priv->cfg->mod_params->num_of_queues;
  678. priv->hw_params.dma_chnl_num = FH50_TCSR_CHNL_NUM;
  679. priv->hw_params.scd_bc_tbls_size =
  680. IWL50_NUM_QUEUES * sizeof(struct iwl5000_scd_bc_tbl);
  681. priv->hw_params.tfd_size = sizeof(struct iwl_tfd);
  682. priv->hw_params.max_stations = IWL5000_STATION_COUNT;
  683. priv->hw_params.bcast_sta_id = IWL5000_BROADCAST_ID;
  684. switch (priv->hw_rev & CSR_HW_REV_TYPE_MSK) {
  685. case CSR_HW_REV_TYPE_6x00:
  686. case CSR_HW_REV_TYPE_6x50:
  687. priv->hw_params.max_data_size = IWL60_RTC_DATA_SIZE;
  688. priv->hw_params.max_inst_size = IWL60_RTC_INST_SIZE;
  689. break;
  690. default:
  691. priv->hw_params.max_data_size = IWL50_RTC_DATA_SIZE;
  692. priv->hw_params.max_inst_size = IWL50_RTC_INST_SIZE;
  693. }
  694. priv->hw_params.max_bsm_size = 0;
  695. priv->hw_params.ht40_channel = BIT(IEEE80211_BAND_2GHZ) |
  696. BIT(IEEE80211_BAND_5GHZ);
  697. priv->hw_params.rx_wrt_ptr_reg = FH_RSCSR_CHNL0_WPTR;
  698. priv->hw_params.tx_chains_num = num_of_ant(priv->cfg->valid_tx_ant);
  699. priv->hw_params.rx_chains_num = num_of_ant(priv->cfg->valid_rx_ant);
  700. priv->hw_params.valid_tx_ant = priv->cfg->valid_tx_ant;
  701. priv->hw_params.valid_rx_ant = priv->cfg->valid_rx_ant;
  702. if (priv->cfg->ops->lib->temp_ops.set_ct_kill)
  703. priv->cfg->ops->lib->temp_ops.set_ct_kill(priv);
  704. /* Set initial sensitivity parameters */
  705. /* Set initial calibration set */
  706. switch (priv->hw_rev & CSR_HW_REV_TYPE_MSK) {
  707. case CSR_HW_REV_TYPE_5150:
  708. priv->hw_params.sens = &iwl5150_sensitivity;
  709. priv->hw_params.calib_init_cfg =
  710. BIT(IWL_CALIB_DC) |
  711. BIT(IWL_CALIB_LO) |
  712. BIT(IWL_CALIB_TX_IQ) |
  713. BIT(IWL_CALIB_BASE_BAND);
  714. break;
  715. default:
  716. priv->hw_params.sens = &iwl5000_sensitivity;
  717. priv->hw_params.calib_init_cfg =
  718. BIT(IWL_CALIB_XTAL) |
  719. BIT(IWL_CALIB_LO) |
  720. BIT(IWL_CALIB_TX_IQ) |
  721. BIT(IWL_CALIB_TX_IQ_PERD) |
  722. BIT(IWL_CALIB_BASE_BAND);
  723. break;
  724. }
  725. return 0;
  726. }
  727. /**
  728. * iwl5000_txq_update_byte_cnt_tbl - Set up entry in Tx byte-count array
  729. */
  730. void iwl5000_txq_update_byte_cnt_tbl(struct iwl_priv *priv,
  731. struct iwl_tx_queue *txq,
  732. u16 byte_cnt)
  733. {
  734. struct iwl5000_scd_bc_tbl *scd_bc_tbl = priv->scd_bc_tbls.addr;
  735. int write_ptr = txq->q.write_ptr;
  736. int txq_id = txq->q.id;
  737. u8 sec_ctl = 0;
  738. u8 sta_id = 0;
  739. u16 len = byte_cnt + IWL_TX_CRC_SIZE + IWL_TX_DELIMITER_SIZE;
  740. __le16 bc_ent;
  741. WARN_ON(len > 0xFFF || write_ptr >= TFD_QUEUE_SIZE_MAX);
  742. if (txq_id != IWL_CMD_QUEUE_NUM) {
  743. sta_id = txq->cmd[txq->q.write_ptr]->cmd.tx.sta_id;
  744. sec_ctl = txq->cmd[txq->q.write_ptr]->cmd.tx.sec_ctl;
  745. switch (sec_ctl & TX_CMD_SEC_MSK) {
  746. case TX_CMD_SEC_CCM:
  747. len += CCMP_MIC_LEN;
  748. break;
  749. case TX_CMD_SEC_TKIP:
  750. len += TKIP_ICV_LEN;
  751. break;
  752. case TX_CMD_SEC_WEP:
  753. len += WEP_IV_LEN + WEP_ICV_LEN;
  754. break;
  755. }
  756. }
  757. bc_ent = cpu_to_le16((len & 0xFFF) | (sta_id << 12));
  758. scd_bc_tbl[txq_id].tfd_offset[write_ptr] = bc_ent;
  759. if (txq->q.write_ptr < TFD_QUEUE_SIZE_BC_DUP)
  760. scd_bc_tbl[txq_id].
  761. tfd_offset[TFD_QUEUE_SIZE_MAX + write_ptr] = bc_ent;
  762. }
  763. void iwl5000_txq_inval_byte_cnt_tbl(struct iwl_priv *priv,
  764. struct iwl_tx_queue *txq)
  765. {
  766. struct iwl5000_scd_bc_tbl *scd_bc_tbl = priv->scd_bc_tbls.addr;
  767. int txq_id = txq->q.id;
  768. int read_ptr = txq->q.read_ptr;
  769. u8 sta_id = 0;
  770. __le16 bc_ent;
  771. WARN_ON(read_ptr >= TFD_QUEUE_SIZE_MAX);
  772. if (txq_id != IWL_CMD_QUEUE_NUM)
  773. sta_id = txq->cmd[read_ptr]->cmd.tx.sta_id;
  774. bc_ent = cpu_to_le16(1 | (sta_id << 12));
  775. scd_bc_tbl[txq_id].tfd_offset[read_ptr] = bc_ent;
  776. if (txq->q.write_ptr < TFD_QUEUE_SIZE_BC_DUP)
  777. scd_bc_tbl[txq_id].
  778. tfd_offset[TFD_QUEUE_SIZE_MAX + read_ptr] = bc_ent;
  779. }
  780. static int iwl5000_tx_queue_set_q2ratid(struct iwl_priv *priv, u16 ra_tid,
  781. u16 txq_id)
  782. {
  783. u32 tbl_dw_addr;
  784. u32 tbl_dw;
  785. u16 scd_q2ratid;
  786. scd_q2ratid = ra_tid & IWL_SCD_QUEUE_RA_TID_MAP_RATID_MSK;
  787. tbl_dw_addr = priv->scd_base_addr +
  788. IWL50_SCD_TRANSLATE_TBL_OFFSET_QUEUE(txq_id);
  789. tbl_dw = iwl_read_targ_mem(priv, tbl_dw_addr);
  790. if (txq_id & 0x1)
  791. tbl_dw = (scd_q2ratid << 16) | (tbl_dw & 0x0000FFFF);
  792. else
  793. tbl_dw = scd_q2ratid | (tbl_dw & 0xFFFF0000);
  794. iwl_write_targ_mem(priv, tbl_dw_addr, tbl_dw);
  795. return 0;
  796. }
  797. static void iwl5000_tx_queue_stop_scheduler(struct iwl_priv *priv, u16 txq_id)
  798. {
  799. /* Simply stop the queue, but don't change any configuration;
  800. * the SCD_ACT_EN bit is the write-enable mask for the ACTIVE bit. */
  801. iwl_write_prph(priv,
  802. IWL50_SCD_QUEUE_STATUS_BITS(txq_id),
  803. (0 << IWL50_SCD_QUEUE_STTS_REG_POS_ACTIVE)|
  804. (1 << IWL50_SCD_QUEUE_STTS_REG_POS_SCD_ACT_EN));
  805. }
  806. int iwl5000_txq_agg_enable(struct iwl_priv *priv, int txq_id,
  807. int tx_fifo, int sta_id, int tid, u16 ssn_idx)
  808. {
  809. unsigned long flags;
  810. u16 ra_tid;
  811. if ((IWL50_FIRST_AMPDU_QUEUE > txq_id) ||
  812. (IWL50_FIRST_AMPDU_QUEUE + IWL50_NUM_AMPDU_QUEUES <= txq_id)) {
  813. IWL_WARN(priv,
  814. "queue number out of range: %d, must be %d to %d\n",
  815. txq_id, IWL50_FIRST_AMPDU_QUEUE,
  816. IWL50_FIRST_AMPDU_QUEUE + IWL50_NUM_AMPDU_QUEUES - 1);
  817. return -EINVAL;
  818. }
  819. ra_tid = BUILD_RAxTID(sta_id, tid);
  820. /* Modify device's station table to Tx this TID */
  821. iwl_sta_tx_modify_enable_tid(priv, sta_id, tid);
  822. spin_lock_irqsave(&priv->lock, flags);
  823. /* Stop this Tx queue before configuring it */
  824. iwl5000_tx_queue_stop_scheduler(priv, txq_id);
  825. /* Map receiver-address / traffic-ID to this queue */
  826. iwl5000_tx_queue_set_q2ratid(priv, ra_tid, txq_id);
  827. /* Set this queue as a chain-building queue */
  828. iwl_set_bits_prph(priv, IWL50_SCD_QUEUECHAIN_SEL, (1<<txq_id));
  829. /* enable aggregations for the queue */
  830. iwl_set_bits_prph(priv, IWL50_SCD_AGGR_SEL, (1<<txq_id));
  831. /* Place first TFD at index corresponding to start sequence number.
  832. * Assumes that ssn_idx is valid (!= 0xFFF) */
  833. priv->txq[txq_id].q.read_ptr = (ssn_idx & 0xff);
  834. priv->txq[txq_id].q.write_ptr = (ssn_idx & 0xff);
  835. iwl5000_set_wr_ptrs(priv, txq_id, ssn_idx);
  836. /* Set up Tx window size and frame limit for this queue */
  837. iwl_write_targ_mem(priv, priv->scd_base_addr +
  838. IWL50_SCD_CONTEXT_QUEUE_OFFSET(txq_id) +
  839. sizeof(u32),
  840. ((SCD_WIN_SIZE <<
  841. IWL50_SCD_QUEUE_CTX_REG2_WIN_SIZE_POS) &
  842. IWL50_SCD_QUEUE_CTX_REG2_WIN_SIZE_MSK) |
  843. ((SCD_FRAME_LIMIT <<
  844. IWL50_SCD_QUEUE_CTX_REG2_FRAME_LIMIT_POS) &
  845. IWL50_SCD_QUEUE_CTX_REG2_FRAME_LIMIT_MSK));
  846. iwl_set_bits_prph(priv, IWL50_SCD_INTERRUPT_MASK, (1 << txq_id));
  847. /* Set up Status area in SRAM, map to Tx DMA/FIFO, activate the queue */
  848. iwl5000_tx_queue_set_status(priv, &priv->txq[txq_id], tx_fifo, 1);
  849. spin_unlock_irqrestore(&priv->lock, flags);
  850. return 0;
  851. }
  852. int iwl5000_txq_agg_disable(struct iwl_priv *priv, u16 txq_id,
  853. u16 ssn_idx, u8 tx_fifo)
  854. {
  855. if ((IWL50_FIRST_AMPDU_QUEUE > txq_id) ||
  856. (IWL50_FIRST_AMPDU_QUEUE + IWL50_NUM_AMPDU_QUEUES <= txq_id)) {
  857. IWL_ERR(priv,
  858. "queue number out of range: %d, must be %d to %d\n",
  859. txq_id, IWL50_FIRST_AMPDU_QUEUE,
  860. IWL50_FIRST_AMPDU_QUEUE + IWL50_NUM_AMPDU_QUEUES - 1);
  861. return -EINVAL;
  862. }
  863. iwl5000_tx_queue_stop_scheduler(priv, txq_id);
  864. iwl_clear_bits_prph(priv, IWL50_SCD_AGGR_SEL, (1 << txq_id));
  865. priv->txq[txq_id].q.read_ptr = (ssn_idx & 0xff);
  866. priv->txq[txq_id].q.write_ptr = (ssn_idx & 0xff);
  867. /* supposes that ssn_idx is valid (!= 0xFFF) */
  868. iwl5000_set_wr_ptrs(priv, txq_id, ssn_idx);
  869. iwl_clear_bits_prph(priv, IWL50_SCD_INTERRUPT_MASK, (1 << txq_id));
  870. iwl_txq_ctx_deactivate(priv, txq_id);
  871. iwl5000_tx_queue_set_status(priv, &priv->txq[txq_id], tx_fifo, 0);
  872. return 0;
  873. }
  874. u16 iwl5000_build_addsta_hcmd(const struct iwl_addsta_cmd *cmd, u8 *data)
  875. {
  876. u16 size = (u16)sizeof(struct iwl_addsta_cmd);
  877. struct iwl_addsta_cmd *addsta = (struct iwl_addsta_cmd *)data;
  878. memcpy(addsta, cmd, size);
  879. /* resrved in 5000 */
  880. addsta->rate_n_flags = cpu_to_le16(0);
  881. return size;
  882. }
  883. /*
  884. * Activate/Deactivate Tx DMA/FIFO channels according tx fifos mask
  885. * must be called under priv->lock and mac access
  886. */
  887. void iwl5000_txq_set_sched(struct iwl_priv *priv, u32 mask)
  888. {
  889. iwl_write_prph(priv, IWL50_SCD_TXFACT, mask);
  890. }
  891. static inline u32 iwl5000_get_scd_ssn(struct iwl5000_tx_resp *tx_resp)
  892. {
  893. return le32_to_cpup((__le32 *)&tx_resp->status +
  894. tx_resp->frame_count) & MAX_SN;
  895. }
  896. static int iwl5000_tx_status_reply_tx(struct iwl_priv *priv,
  897. struct iwl_ht_agg *agg,
  898. struct iwl5000_tx_resp *tx_resp,
  899. int txq_id, u16 start_idx)
  900. {
  901. u16 status;
  902. struct agg_tx_status *frame_status = &tx_resp->status;
  903. struct ieee80211_tx_info *info = NULL;
  904. struct ieee80211_hdr *hdr = NULL;
  905. u32 rate_n_flags = le32_to_cpu(tx_resp->rate_n_flags);
  906. int i, sh, idx;
  907. u16 seq;
  908. if (agg->wait_for_ba)
  909. IWL_DEBUG_TX_REPLY(priv, "got tx response w/o block-ack\n");
  910. agg->frame_count = tx_resp->frame_count;
  911. agg->start_idx = start_idx;
  912. agg->rate_n_flags = rate_n_flags;
  913. agg->bitmap = 0;
  914. /* # frames attempted by Tx command */
  915. if (agg->frame_count == 1) {
  916. /* Only one frame was attempted; no block-ack will arrive */
  917. status = le16_to_cpu(frame_status[0].status);
  918. idx = start_idx;
  919. /* FIXME: code repetition */
  920. IWL_DEBUG_TX_REPLY(priv, "FrameCnt = %d, StartIdx=%d idx=%d\n",
  921. agg->frame_count, agg->start_idx, idx);
  922. info = IEEE80211_SKB_CB(priv->txq[txq_id].txb[idx].skb[0]);
  923. info->status.rates[0].count = tx_resp->failure_frame + 1;
  924. info->flags &= ~IEEE80211_TX_CTL_AMPDU;
  925. info->flags |= iwl_is_tx_success(status) ?
  926. IEEE80211_TX_STAT_ACK : 0;
  927. iwl_hwrate_to_tx_control(priv, rate_n_flags, info);
  928. /* FIXME: code repetition end */
  929. IWL_DEBUG_TX_REPLY(priv, "1 Frame 0x%x failure :%d\n",
  930. status & 0xff, tx_resp->failure_frame);
  931. IWL_DEBUG_TX_REPLY(priv, "Rate Info rate_n_flags=%x\n", rate_n_flags);
  932. agg->wait_for_ba = 0;
  933. } else {
  934. /* Two or more frames were attempted; expect block-ack */
  935. u64 bitmap = 0;
  936. int start = agg->start_idx;
  937. /* Construct bit-map of pending frames within Tx window */
  938. for (i = 0; i < agg->frame_count; i++) {
  939. u16 sc;
  940. status = le16_to_cpu(frame_status[i].status);
  941. seq = le16_to_cpu(frame_status[i].sequence);
  942. idx = SEQ_TO_INDEX(seq);
  943. txq_id = SEQ_TO_QUEUE(seq);
  944. if (status & (AGG_TX_STATE_FEW_BYTES_MSK |
  945. AGG_TX_STATE_ABORT_MSK))
  946. continue;
  947. IWL_DEBUG_TX_REPLY(priv, "FrameCnt = %d, txq_id=%d idx=%d\n",
  948. agg->frame_count, txq_id, idx);
  949. hdr = iwl_tx_queue_get_hdr(priv, txq_id, idx);
  950. if (!hdr) {
  951. IWL_ERR(priv,
  952. "BUG_ON idx doesn't point to valid skb"
  953. " idx=%d, txq_id=%d\n", idx, txq_id);
  954. return -1;
  955. }
  956. sc = le16_to_cpu(hdr->seq_ctrl);
  957. if (idx != (SEQ_TO_SN(sc) & 0xff)) {
  958. IWL_ERR(priv,
  959. "BUG_ON idx doesn't match seq control"
  960. " idx=%d, seq_idx=%d, seq=%d\n",
  961. idx, SEQ_TO_SN(sc),
  962. hdr->seq_ctrl);
  963. return -1;
  964. }
  965. IWL_DEBUG_TX_REPLY(priv, "AGG Frame i=%d idx %d seq=%d\n",
  966. i, idx, SEQ_TO_SN(sc));
  967. sh = idx - start;
  968. if (sh > 64) {
  969. sh = (start - idx) + 0xff;
  970. bitmap = bitmap << sh;
  971. sh = 0;
  972. start = idx;
  973. } else if (sh < -64)
  974. sh = 0xff - (start - idx);
  975. else if (sh < 0) {
  976. sh = start - idx;
  977. start = idx;
  978. bitmap = bitmap << sh;
  979. sh = 0;
  980. }
  981. bitmap |= 1ULL << sh;
  982. IWL_DEBUG_TX_REPLY(priv, "start=%d bitmap=0x%llx\n",
  983. start, (unsigned long long)bitmap);
  984. }
  985. agg->bitmap = bitmap;
  986. agg->start_idx = start;
  987. IWL_DEBUG_TX_REPLY(priv, "Frames %d start_idx=%d bitmap=0x%llx\n",
  988. agg->frame_count, agg->start_idx,
  989. (unsigned long long)agg->bitmap);
  990. if (bitmap)
  991. agg->wait_for_ba = 1;
  992. }
  993. return 0;
  994. }
  995. static void iwl5000_rx_reply_tx(struct iwl_priv *priv,
  996. struct iwl_rx_mem_buffer *rxb)
  997. {
  998. struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
  999. u16 sequence = le16_to_cpu(pkt->hdr.sequence);
  1000. int txq_id = SEQ_TO_QUEUE(sequence);
  1001. int index = SEQ_TO_INDEX(sequence);
  1002. struct iwl_tx_queue *txq = &priv->txq[txq_id];
  1003. struct ieee80211_tx_info *info;
  1004. struct iwl5000_tx_resp *tx_resp = (void *)&pkt->u.raw[0];
  1005. u32 status = le16_to_cpu(tx_resp->status.status);
  1006. int tid;
  1007. int sta_id;
  1008. int freed;
  1009. if ((index >= txq->q.n_bd) || (iwl_queue_used(&txq->q, index) == 0)) {
  1010. IWL_ERR(priv, "Read index for DMA queue txq_id (%d) index %d "
  1011. "is out of range [0-%d] %d %d\n", txq_id,
  1012. index, txq->q.n_bd, txq->q.write_ptr,
  1013. txq->q.read_ptr);
  1014. return;
  1015. }
  1016. info = IEEE80211_SKB_CB(txq->txb[txq->q.read_ptr].skb[0]);
  1017. memset(&info->status, 0, sizeof(info->status));
  1018. tid = (tx_resp->ra_tid & IWL50_TX_RES_TID_MSK) >> IWL50_TX_RES_TID_POS;
  1019. sta_id = (tx_resp->ra_tid & IWL50_TX_RES_RA_MSK) >> IWL50_TX_RES_RA_POS;
  1020. if (txq->sched_retry) {
  1021. const u32 scd_ssn = iwl5000_get_scd_ssn(tx_resp);
  1022. struct iwl_ht_agg *agg = NULL;
  1023. agg = &priv->stations[sta_id].tid[tid].agg;
  1024. iwl5000_tx_status_reply_tx(priv, agg, tx_resp, txq_id, index);
  1025. /* check if BAR is needed */
  1026. if ((tx_resp->frame_count == 1) && !iwl_is_tx_success(status))
  1027. info->flags |= IEEE80211_TX_STAT_AMPDU_NO_BACK;
  1028. if (txq->q.read_ptr != (scd_ssn & 0xff)) {
  1029. index = iwl_queue_dec_wrap(scd_ssn & 0xff, txq->q.n_bd);
  1030. IWL_DEBUG_TX_REPLY(priv, "Retry scheduler reclaim "
  1031. "scd_ssn=%d idx=%d txq=%d swq=%d\n",
  1032. scd_ssn , index, txq_id, txq->swq_id);
  1033. freed = iwl_tx_queue_reclaim(priv, txq_id, index);
  1034. priv->stations[sta_id].tid[tid].tfds_in_queue -= freed;
  1035. if (priv->mac80211_registered &&
  1036. (iwl_queue_space(&txq->q) > txq->q.low_mark) &&
  1037. (agg->state != IWL_EMPTYING_HW_QUEUE_DELBA)) {
  1038. if (agg->state == IWL_AGG_OFF)
  1039. iwl_wake_queue(priv, txq_id);
  1040. else
  1041. iwl_wake_queue(priv, txq->swq_id);
  1042. }
  1043. }
  1044. } else {
  1045. BUG_ON(txq_id != txq->swq_id);
  1046. info->status.rates[0].count = tx_resp->failure_frame + 1;
  1047. info->flags |= iwl_is_tx_success(status) ?
  1048. IEEE80211_TX_STAT_ACK : 0;
  1049. iwl_hwrate_to_tx_control(priv,
  1050. le32_to_cpu(tx_resp->rate_n_flags),
  1051. info);
  1052. IWL_DEBUG_TX_REPLY(priv, "TXQ %d status %s (0x%08x) rate_n_flags "
  1053. "0x%x retries %d\n",
  1054. txq_id,
  1055. iwl_get_tx_fail_reason(status), status,
  1056. le32_to_cpu(tx_resp->rate_n_flags),
  1057. tx_resp->failure_frame);
  1058. freed = iwl_tx_queue_reclaim(priv, txq_id, index);
  1059. if (ieee80211_is_data_qos(tx_resp->frame_ctrl))
  1060. priv->stations[sta_id].tid[tid].tfds_in_queue -= freed;
  1061. if (priv->mac80211_registered &&
  1062. (iwl_queue_space(&txq->q) > txq->q.low_mark))
  1063. iwl_wake_queue(priv, txq_id);
  1064. }
  1065. if (ieee80211_is_data_qos(tx_resp->frame_ctrl))
  1066. iwl_txq_check_empty(priv, sta_id, tid, txq_id);
  1067. if (iwl_check_bits(status, TX_ABORT_REQUIRED_MSK))
  1068. IWL_ERR(priv, "TODO: Implement Tx ABORT REQUIRED!!!\n");
  1069. }
  1070. /* Currently 5000 is the superset of everything */
  1071. u16 iwl5000_get_hcmd_size(u8 cmd_id, u16 len)
  1072. {
  1073. return len;
  1074. }
  1075. void iwl5000_setup_deferred_work(struct iwl_priv *priv)
  1076. {
  1077. /* in 5000 the tx power calibration is done in uCode */
  1078. priv->disable_tx_power_cal = 1;
  1079. }
  1080. void iwl5000_rx_handler_setup(struct iwl_priv *priv)
  1081. {
  1082. /* init calibration handlers */
  1083. priv->rx_handlers[CALIBRATION_RES_NOTIFICATION] =
  1084. iwl5000_rx_calib_result;
  1085. priv->rx_handlers[CALIBRATION_COMPLETE_NOTIFICATION] =
  1086. iwl5000_rx_calib_complete;
  1087. priv->rx_handlers[REPLY_TX] = iwl5000_rx_reply_tx;
  1088. }
  1089. int iwl5000_hw_valid_rtc_data_addr(u32 addr)
  1090. {
  1091. return (addr >= IWL50_RTC_DATA_LOWER_BOUND) &&
  1092. (addr < IWL50_RTC_DATA_UPPER_BOUND);
  1093. }
  1094. static int iwl5000_send_rxon_assoc(struct iwl_priv *priv)
  1095. {
  1096. int ret = 0;
  1097. struct iwl5000_rxon_assoc_cmd rxon_assoc;
  1098. const struct iwl_rxon_cmd *rxon1 = &priv->staging_rxon;
  1099. const struct iwl_rxon_cmd *rxon2 = &priv->active_rxon;
  1100. if ((rxon1->flags == rxon2->flags) &&
  1101. (rxon1->filter_flags == rxon2->filter_flags) &&
  1102. (rxon1->cck_basic_rates == rxon2->cck_basic_rates) &&
  1103. (rxon1->ofdm_ht_single_stream_basic_rates ==
  1104. rxon2->ofdm_ht_single_stream_basic_rates) &&
  1105. (rxon1->ofdm_ht_dual_stream_basic_rates ==
  1106. rxon2->ofdm_ht_dual_stream_basic_rates) &&
  1107. (rxon1->ofdm_ht_triple_stream_basic_rates ==
  1108. rxon2->ofdm_ht_triple_stream_basic_rates) &&
  1109. (rxon1->acquisition_data == rxon2->acquisition_data) &&
  1110. (rxon1->rx_chain == rxon2->rx_chain) &&
  1111. (rxon1->ofdm_basic_rates == rxon2->ofdm_basic_rates)) {
  1112. IWL_DEBUG_INFO(priv, "Using current RXON_ASSOC. Not resending.\n");
  1113. return 0;
  1114. }
  1115. rxon_assoc.flags = priv->staging_rxon.flags;
  1116. rxon_assoc.filter_flags = priv->staging_rxon.filter_flags;
  1117. rxon_assoc.ofdm_basic_rates = priv->staging_rxon.ofdm_basic_rates;
  1118. rxon_assoc.cck_basic_rates = priv->staging_rxon.cck_basic_rates;
  1119. rxon_assoc.reserved1 = 0;
  1120. rxon_assoc.reserved2 = 0;
  1121. rxon_assoc.reserved3 = 0;
  1122. rxon_assoc.ofdm_ht_single_stream_basic_rates =
  1123. priv->staging_rxon.ofdm_ht_single_stream_basic_rates;
  1124. rxon_assoc.ofdm_ht_dual_stream_basic_rates =
  1125. priv->staging_rxon.ofdm_ht_dual_stream_basic_rates;
  1126. rxon_assoc.rx_chain_select_flags = priv->staging_rxon.rx_chain;
  1127. rxon_assoc.ofdm_ht_triple_stream_basic_rates =
  1128. priv->staging_rxon.ofdm_ht_triple_stream_basic_rates;
  1129. rxon_assoc.acquisition_data = priv->staging_rxon.acquisition_data;
  1130. ret = iwl_send_cmd_pdu_async(priv, REPLY_RXON_ASSOC,
  1131. sizeof(rxon_assoc), &rxon_assoc, NULL);
  1132. if (ret)
  1133. return ret;
  1134. return ret;
  1135. }
  1136. int iwl5000_send_tx_power(struct iwl_priv *priv)
  1137. {
  1138. struct iwl5000_tx_power_dbm_cmd tx_power_cmd;
  1139. u8 tx_ant_cfg_cmd;
  1140. /* half dBm need to multiply */
  1141. tx_power_cmd.global_lmt = (s8)(2 * priv->tx_power_user_lmt);
  1142. tx_power_cmd.flags = IWL50_TX_POWER_NO_CLOSED;
  1143. tx_power_cmd.srv_chan_lmt = IWL50_TX_POWER_AUTO;
  1144. if (IWL_UCODE_API(priv->ucode_ver) == 1)
  1145. tx_ant_cfg_cmd = REPLY_TX_POWER_DBM_CMD_V1;
  1146. else
  1147. tx_ant_cfg_cmd = REPLY_TX_POWER_DBM_CMD;
  1148. return iwl_send_cmd_pdu_async(priv, tx_ant_cfg_cmd,
  1149. sizeof(tx_power_cmd), &tx_power_cmd,
  1150. NULL);
  1151. }
  1152. void iwl5000_temperature(struct iwl_priv *priv)
  1153. {
  1154. /* store temperature from statistics (in Celsius) */
  1155. priv->temperature = le32_to_cpu(priv->statistics.general.temperature);
  1156. iwl_tt_handler(priv);
  1157. }
  1158. static void iwl5150_temperature(struct iwl_priv *priv)
  1159. {
  1160. u32 vt = 0;
  1161. s32 offset = iwl_temp_calib_to_offset(priv);
  1162. vt = le32_to_cpu(priv->statistics.general.temperature);
  1163. vt = vt / IWL_5150_VOLTAGE_TO_TEMPERATURE_COEFF + offset;
  1164. /* now vt hold the temperature in Kelvin */
  1165. priv->temperature = KELVIN_TO_CELSIUS(vt);
  1166. iwl_tt_handler(priv);
  1167. }
  1168. /* Calc max signal level (dBm) among 3 possible receivers */
  1169. int iwl5000_calc_rssi(struct iwl_priv *priv,
  1170. struct iwl_rx_phy_res *rx_resp)
  1171. {
  1172. /* data from PHY/DSP regarding signal strength, etc.,
  1173. * contents are always there, not configurable by host
  1174. */
  1175. struct iwl5000_non_cfg_phy *ncphy =
  1176. (struct iwl5000_non_cfg_phy *)rx_resp->non_cfg_phy_buf;
  1177. u32 val, rssi_a, rssi_b, rssi_c, max_rssi;
  1178. u8 agc;
  1179. val = le32_to_cpu(ncphy->non_cfg_phy[IWL50_RX_RES_AGC_IDX]);
  1180. agc = (val & IWL50_OFDM_AGC_MSK) >> IWL50_OFDM_AGC_BIT_POS;
  1181. /* Find max rssi among 3 possible receivers.
  1182. * These values are measured by the digital signal processor (DSP).
  1183. * They should stay fairly constant even as the signal strength varies,
  1184. * if the radio's automatic gain control (AGC) is working right.
  1185. * AGC value (see below) will provide the "interesting" info.
  1186. */
  1187. val = le32_to_cpu(ncphy->non_cfg_phy[IWL50_RX_RES_RSSI_AB_IDX]);
  1188. rssi_a = (val & IWL50_OFDM_RSSI_A_MSK) >> IWL50_OFDM_RSSI_A_BIT_POS;
  1189. rssi_b = (val & IWL50_OFDM_RSSI_B_MSK) >> IWL50_OFDM_RSSI_B_BIT_POS;
  1190. val = le32_to_cpu(ncphy->non_cfg_phy[IWL50_RX_RES_RSSI_C_IDX]);
  1191. rssi_c = (val & IWL50_OFDM_RSSI_C_MSK) >> IWL50_OFDM_RSSI_C_BIT_POS;
  1192. max_rssi = max_t(u32, rssi_a, rssi_b);
  1193. max_rssi = max_t(u32, max_rssi, rssi_c);
  1194. IWL_DEBUG_STATS(priv, "Rssi In A %d B %d C %d Max %d AGC dB %d\n",
  1195. rssi_a, rssi_b, rssi_c, max_rssi, agc);
  1196. /* dBm = max_rssi dB - agc dB - constant.
  1197. * Higher AGC (higher radio gain) means lower signal. */
  1198. return max_rssi - agc - IWL49_RSSI_OFFSET;
  1199. }
  1200. #define IWL5000_UCODE_GET(item) \
  1201. static u32 iwl5000_ucode_get_##item(const struct iwl_ucode_header *ucode,\
  1202. u32 api_ver) \
  1203. { \
  1204. if (api_ver <= 2) \
  1205. return le32_to_cpu(ucode->u.v1.item); \
  1206. return le32_to_cpu(ucode->u.v2.item); \
  1207. }
  1208. static u32 iwl5000_ucode_get_header_size(u32 api_ver)
  1209. {
  1210. if (api_ver <= 2)
  1211. return UCODE_HEADER_SIZE(1);
  1212. return UCODE_HEADER_SIZE(2);
  1213. }
  1214. static u32 iwl5000_ucode_get_build(const struct iwl_ucode_header *ucode,
  1215. u32 api_ver)
  1216. {
  1217. if (api_ver <= 2)
  1218. return 0;
  1219. return le32_to_cpu(ucode->u.v2.build);
  1220. }
  1221. static u8 *iwl5000_ucode_get_data(const struct iwl_ucode_header *ucode,
  1222. u32 api_ver)
  1223. {
  1224. if (api_ver <= 2)
  1225. return (u8 *) ucode->u.v1.data;
  1226. return (u8 *) ucode->u.v2.data;
  1227. }
  1228. IWL5000_UCODE_GET(inst_size);
  1229. IWL5000_UCODE_GET(data_size);
  1230. IWL5000_UCODE_GET(init_size);
  1231. IWL5000_UCODE_GET(init_data_size);
  1232. IWL5000_UCODE_GET(boot_size);
  1233. struct iwl_hcmd_ops iwl5000_hcmd = {
  1234. .rxon_assoc = iwl5000_send_rxon_assoc,
  1235. .commit_rxon = iwl_commit_rxon,
  1236. .set_rxon_chain = iwl_set_rxon_chain,
  1237. };
  1238. struct iwl_hcmd_utils_ops iwl5000_hcmd_utils = {
  1239. .get_hcmd_size = iwl5000_get_hcmd_size,
  1240. .build_addsta_hcmd = iwl5000_build_addsta_hcmd,
  1241. .gain_computation = iwl5000_gain_computation,
  1242. .chain_noise_reset = iwl5000_chain_noise_reset,
  1243. .rts_tx_cmd_flag = iwl5000_rts_tx_cmd_flag,
  1244. .calc_rssi = iwl5000_calc_rssi,
  1245. };
  1246. struct iwl_ucode_ops iwl5000_ucode = {
  1247. .get_header_size = iwl5000_ucode_get_header_size,
  1248. .get_build = iwl5000_ucode_get_build,
  1249. .get_inst_size = iwl5000_ucode_get_inst_size,
  1250. .get_data_size = iwl5000_ucode_get_data_size,
  1251. .get_init_size = iwl5000_ucode_get_init_size,
  1252. .get_init_data_size = iwl5000_ucode_get_init_data_size,
  1253. .get_boot_size = iwl5000_ucode_get_boot_size,
  1254. .get_data = iwl5000_ucode_get_data,
  1255. };
  1256. struct iwl_lib_ops iwl5000_lib = {
  1257. .set_hw_params = iwl5000_hw_set_hw_params,
  1258. .txq_update_byte_cnt_tbl = iwl5000_txq_update_byte_cnt_tbl,
  1259. .txq_inval_byte_cnt_tbl = iwl5000_txq_inval_byte_cnt_tbl,
  1260. .txq_set_sched = iwl5000_txq_set_sched,
  1261. .txq_agg_enable = iwl5000_txq_agg_enable,
  1262. .txq_agg_disable = iwl5000_txq_agg_disable,
  1263. .txq_attach_buf_to_tfd = iwl_hw_txq_attach_buf_to_tfd,
  1264. .txq_free_tfd = iwl_hw_txq_free_tfd,
  1265. .txq_init = iwl_hw_tx_queue_init,
  1266. .rx_handler_setup = iwl5000_rx_handler_setup,
  1267. .setup_deferred_work = iwl5000_setup_deferred_work,
  1268. .is_valid_rtc_data_addr = iwl5000_hw_valid_rtc_data_addr,
  1269. .dump_nic_event_log = iwl_dump_nic_event_log,
  1270. .dump_nic_error_log = iwl_dump_nic_error_log,
  1271. .load_ucode = iwl5000_load_ucode,
  1272. .init_alive_start = iwl5000_init_alive_start,
  1273. .alive_notify = iwl5000_alive_notify,
  1274. .send_tx_power = iwl5000_send_tx_power,
  1275. .update_chain_flags = iwl_update_chain_flags,
  1276. .apm_ops = {
  1277. .init = iwl5000_apm_init,
  1278. .reset = iwl5000_apm_reset,
  1279. .stop = iwl5000_apm_stop,
  1280. .config = iwl5000_nic_config,
  1281. .set_pwr_src = iwl_set_pwr_src,
  1282. },
  1283. .eeprom_ops = {
  1284. .regulatory_bands = {
  1285. EEPROM_5000_REG_BAND_1_CHANNELS,
  1286. EEPROM_5000_REG_BAND_2_CHANNELS,
  1287. EEPROM_5000_REG_BAND_3_CHANNELS,
  1288. EEPROM_5000_REG_BAND_4_CHANNELS,
  1289. EEPROM_5000_REG_BAND_5_CHANNELS,
  1290. EEPROM_5000_REG_BAND_24_HT40_CHANNELS,
  1291. EEPROM_5000_REG_BAND_52_HT40_CHANNELS
  1292. },
  1293. .verify_signature = iwlcore_eeprom_verify_signature,
  1294. .acquire_semaphore = iwlcore_eeprom_acquire_semaphore,
  1295. .release_semaphore = iwlcore_eeprom_release_semaphore,
  1296. .calib_version = iwl5000_eeprom_calib_version,
  1297. .query_addr = iwl5000_eeprom_query_addr,
  1298. },
  1299. .post_associate = iwl_post_associate,
  1300. .isr = iwl_isr_ict,
  1301. .config_ap = iwl_config_ap,
  1302. .temp_ops = {
  1303. .temperature = iwl5000_temperature,
  1304. .set_ct_kill = iwl5000_set_ct_threshold,
  1305. },
  1306. };
  1307. static struct iwl_lib_ops iwl5150_lib = {
  1308. .set_hw_params = iwl5000_hw_set_hw_params,
  1309. .txq_update_byte_cnt_tbl = iwl5000_txq_update_byte_cnt_tbl,
  1310. .txq_inval_byte_cnt_tbl = iwl5000_txq_inval_byte_cnt_tbl,
  1311. .txq_set_sched = iwl5000_txq_set_sched,
  1312. .txq_agg_enable = iwl5000_txq_agg_enable,
  1313. .txq_agg_disable = iwl5000_txq_agg_disable,
  1314. .txq_attach_buf_to_tfd = iwl_hw_txq_attach_buf_to_tfd,
  1315. .txq_free_tfd = iwl_hw_txq_free_tfd,
  1316. .txq_init = iwl_hw_tx_queue_init,
  1317. .rx_handler_setup = iwl5000_rx_handler_setup,
  1318. .setup_deferred_work = iwl5000_setup_deferred_work,
  1319. .is_valid_rtc_data_addr = iwl5000_hw_valid_rtc_data_addr,
  1320. .dump_nic_event_log = iwl_dump_nic_event_log,
  1321. .dump_nic_error_log = iwl_dump_nic_error_log,
  1322. .load_ucode = iwl5000_load_ucode,
  1323. .init_alive_start = iwl5000_init_alive_start,
  1324. .alive_notify = iwl5000_alive_notify,
  1325. .send_tx_power = iwl5000_send_tx_power,
  1326. .update_chain_flags = iwl_update_chain_flags,
  1327. .apm_ops = {
  1328. .init = iwl5000_apm_init,
  1329. .reset = iwl5000_apm_reset,
  1330. .stop = iwl5000_apm_stop,
  1331. .config = iwl5000_nic_config,
  1332. .set_pwr_src = iwl_set_pwr_src,
  1333. },
  1334. .eeprom_ops = {
  1335. .regulatory_bands = {
  1336. EEPROM_5000_REG_BAND_1_CHANNELS,
  1337. EEPROM_5000_REG_BAND_2_CHANNELS,
  1338. EEPROM_5000_REG_BAND_3_CHANNELS,
  1339. EEPROM_5000_REG_BAND_4_CHANNELS,
  1340. EEPROM_5000_REG_BAND_5_CHANNELS,
  1341. EEPROM_5000_REG_BAND_24_HT40_CHANNELS,
  1342. EEPROM_5000_REG_BAND_52_HT40_CHANNELS
  1343. },
  1344. .verify_signature = iwlcore_eeprom_verify_signature,
  1345. .acquire_semaphore = iwlcore_eeprom_acquire_semaphore,
  1346. .release_semaphore = iwlcore_eeprom_release_semaphore,
  1347. .calib_version = iwl5000_eeprom_calib_version,
  1348. .query_addr = iwl5000_eeprom_query_addr,
  1349. },
  1350. .post_associate = iwl_post_associate,
  1351. .isr = iwl_isr_ict,
  1352. .config_ap = iwl_config_ap,
  1353. .temp_ops = {
  1354. .temperature = iwl5150_temperature,
  1355. .set_ct_kill = iwl5150_set_ct_threshold,
  1356. },
  1357. };
  1358. struct iwl_ops iwl5000_ops = {
  1359. .ucode = &iwl5000_ucode,
  1360. .lib = &iwl5000_lib,
  1361. .hcmd = &iwl5000_hcmd,
  1362. .utils = &iwl5000_hcmd_utils,
  1363. };
  1364. static struct iwl_ops iwl5150_ops = {
  1365. .ucode = &iwl5000_ucode,
  1366. .lib = &iwl5150_lib,
  1367. .hcmd = &iwl5000_hcmd,
  1368. .utils = &iwl5000_hcmd_utils,
  1369. };
  1370. struct iwl_mod_params iwl50_mod_params = {
  1371. .num_of_queues = IWL50_NUM_QUEUES,
  1372. .num_of_ampdu_queues = IWL50_NUM_AMPDU_QUEUES,
  1373. .amsdu_size_8K = 1,
  1374. .restart_fw = 1,
  1375. /* the rest are 0 by default */
  1376. };
  1377. struct iwl_cfg iwl5300_agn_cfg = {
  1378. .name = "5300AGN",
  1379. .fw_name_pre = IWL5000_FW_PRE,
  1380. .ucode_api_max = IWL5000_UCODE_API_MAX,
  1381. .ucode_api_min = IWL5000_UCODE_API_MIN,
  1382. .sku = IWL_SKU_A|IWL_SKU_G|IWL_SKU_N,
  1383. .ops = &iwl5000_ops,
  1384. .eeprom_size = IWL_5000_EEPROM_IMG_SIZE,
  1385. .eeprom_ver = EEPROM_5000_EEPROM_VERSION,
  1386. .eeprom_calib_ver = EEPROM_5000_TX_POWER_VERSION,
  1387. .mod_params = &iwl50_mod_params,
  1388. .valid_tx_ant = ANT_ABC,
  1389. .valid_rx_ant = ANT_ABC,
  1390. .need_pll_cfg = true,
  1391. .ht_greenfield_support = true,
  1392. };
  1393. struct iwl_cfg iwl5100_bg_cfg = {
  1394. .name = "5100BG",
  1395. .fw_name_pre = IWL5000_FW_PRE,
  1396. .ucode_api_max = IWL5000_UCODE_API_MAX,
  1397. .ucode_api_min = IWL5000_UCODE_API_MIN,
  1398. .sku = IWL_SKU_G,
  1399. .ops = &iwl5000_ops,
  1400. .eeprom_size = IWL_5000_EEPROM_IMG_SIZE,
  1401. .eeprom_ver = EEPROM_5000_EEPROM_VERSION,
  1402. .eeprom_calib_ver = EEPROM_5000_TX_POWER_VERSION,
  1403. .mod_params = &iwl50_mod_params,
  1404. .valid_tx_ant = ANT_B,
  1405. .valid_rx_ant = ANT_AB,
  1406. .need_pll_cfg = true,
  1407. .ht_greenfield_support = true,
  1408. };
  1409. struct iwl_cfg iwl5100_abg_cfg = {
  1410. .name = "5100ABG",
  1411. .fw_name_pre = IWL5000_FW_PRE,
  1412. .ucode_api_max = IWL5000_UCODE_API_MAX,
  1413. .ucode_api_min = IWL5000_UCODE_API_MIN,
  1414. .sku = IWL_SKU_A|IWL_SKU_G,
  1415. .ops = &iwl5000_ops,
  1416. .eeprom_size = IWL_5000_EEPROM_IMG_SIZE,
  1417. .eeprom_ver = EEPROM_5000_EEPROM_VERSION,
  1418. .eeprom_calib_ver = EEPROM_5000_TX_POWER_VERSION,
  1419. .mod_params = &iwl50_mod_params,
  1420. .valid_tx_ant = ANT_B,
  1421. .valid_rx_ant = ANT_AB,
  1422. .need_pll_cfg = true,
  1423. .ht_greenfield_support = true,
  1424. };
  1425. struct iwl_cfg iwl5100_agn_cfg = {
  1426. .name = "5100AGN",
  1427. .fw_name_pre = IWL5000_FW_PRE,
  1428. .ucode_api_max = IWL5000_UCODE_API_MAX,
  1429. .ucode_api_min = IWL5000_UCODE_API_MIN,
  1430. .sku = IWL_SKU_A|IWL_SKU_G|IWL_SKU_N,
  1431. .ops = &iwl5000_ops,
  1432. .eeprom_size = IWL_5000_EEPROM_IMG_SIZE,
  1433. .eeprom_ver = EEPROM_5000_EEPROM_VERSION,
  1434. .eeprom_calib_ver = EEPROM_5000_TX_POWER_VERSION,
  1435. .mod_params = &iwl50_mod_params,
  1436. .valid_tx_ant = ANT_B,
  1437. .valid_rx_ant = ANT_AB,
  1438. .need_pll_cfg = true,
  1439. .ht_greenfield_support = true,
  1440. };
  1441. struct iwl_cfg iwl5350_agn_cfg = {
  1442. .name = "5350AGN",
  1443. .fw_name_pre = IWL5000_FW_PRE,
  1444. .ucode_api_max = IWL5000_UCODE_API_MAX,
  1445. .ucode_api_min = IWL5000_UCODE_API_MIN,
  1446. .sku = IWL_SKU_A|IWL_SKU_G|IWL_SKU_N,
  1447. .ops = &iwl5000_ops,
  1448. .eeprom_size = IWL_5000_EEPROM_IMG_SIZE,
  1449. .eeprom_ver = EEPROM_5050_EEPROM_VERSION,
  1450. .eeprom_calib_ver = EEPROM_5050_TX_POWER_VERSION,
  1451. .mod_params = &iwl50_mod_params,
  1452. .valid_tx_ant = ANT_ABC,
  1453. .valid_rx_ant = ANT_ABC,
  1454. .need_pll_cfg = true,
  1455. .ht_greenfield_support = true,
  1456. };
  1457. struct iwl_cfg iwl5150_agn_cfg = {
  1458. .name = "5150AGN",
  1459. .fw_name_pre = IWL5150_FW_PRE,
  1460. .ucode_api_max = IWL5150_UCODE_API_MAX,
  1461. .ucode_api_min = IWL5150_UCODE_API_MIN,
  1462. .sku = IWL_SKU_A|IWL_SKU_G|IWL_SKU_N,
  1463. .ops = &iwl5150_ops,
  1464. .eeprom_size = IWL_5000_EEPROM_IMG_SIZE,
  1465. .eeprom_ver = EEPROM_5050_EEPROM_VERSION,
  1466. .eeprom_calib_ver = EEPROM_5050_TX_POWER_VERSION,
  1467. .mod_params = &iwl50_mod_params,
  1468. .valid_tx_ant = ANT_A,
  1469. .valid_rx_ant = ANT_AB,
  1470. .need_pll_cfg = true,
  1471. .ht_greenfield_support = true,
  1472. };
  1473. MODULE_FIRMWARE(IWL5000_MODULE_FIRMWARE(IWL5000_UCODE_API_MAX));
  1474. MODULE_FIRMWARE(IWL5150_MODULE_FIRMWARE(IWL5150_UCODE_API_MAX));
  1475. module_param_named(swcrypto50, iwl50_mod_params.sw_crypto, bool, 0444);
  1476. MODULE_PARM_DESC(swcrypto50,
  1477. "using software crypto engine (default 0 [hardware])\n");
  1478. module_param_named(queues_num50, iwl50_mod_params.num_of_queues, int, 0444);
  1479. MODULE_PARM_DESC(queues_num50, "number of hw queues in 50xx series");
  1480. module_param_named(11n_disable50, iwl50_mod_params.disable_11n, int, 0444);
  1481. MODULE_PARM_DESC(11n_disable50, "disable 50XX 11n functionality");
  1482. module_param_named(amsdu_size_8K50, iwl50_mod_params.amsdu_size_8K, int, 0444);
  1483. MODULE_PARM_DESC(amsdu_size_8K50, "enable 8K amsdu size in 50XX series");
  1484. module_param_named(fw_restart50, iwl50_mod_params.restart_fw, int, 0444);
  1485. MODULE_PARM_DESC(fw_restart50, "restart firmware in case of error");