iwl-5000.c 51 KB

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