iwl-5000.c 52 KB

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