iwl-5000.c 47 KB

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