iwl-5000.c 48 KB

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