iwl-5000.c 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408
  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/version.h>
  28. #include <linux/init.h>
  29. #include <linux/pci.h>
  30. #include <linux/dma-mapping.h>
  31. #include <linux/delay.h>
  32. #include <linux/skbuff.h>
  33. #include <linux/netdevice.h>
  34. #include <linux/wireless.h>
  35. #include <net/mac80211.h>
  36. #include <linux/etherdevice.h>
  37. #include <asm/unaligned.h>
  38. #include "iwl-eeprom.h"
  39. #include "iwl-dev.h"
  40. #include "iwl-core.h"
  41. #include "iwl-io.h"
  42. #include "iwl-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. iwl_set_bit(priv, CSR_ANA_PLL_CFG, CSR50_ANA_PLL_CFG_VAL);
  81. /* set "initialization complete" bit to move adapter
  82. * D0U* --> D0A* state */
  83. iwl_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
  84. /* wait for clock stabilization */
  85. ret = iwl_poll_bit(priv, CSR_GP_CNTRL,
  86. CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY,
  87. CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, 25000);
  88. if (ret < 0) {
  89. IWL_DEBUG_INFO("Failed to init the card\n");
  90. return ret;
  91. }
  92. ret = iwl_grab_nic_access(priv);
  93. if (ret)
  94. return ret;
  95. /* enable DMA */
  96. iwl_write_prph(priv, APMG_CLK_EN_REG, APMG_CLK_VAL_DMA_CLK_RQT);
  97. udelay(20);
  98. /* disable L1-Active */
  99. iwl_set_bits_prph(priv, APMG_PCIDEV_STT_REG,
  100. APMG_PCIDEV_STT_VAL_L1_ACT_DIS);
  101. iwl_release_nic_access(priv);
  102. return ret;
  103. }
  104. /* FIXME: this is indentical to 4965 */
  105. static void iwl5000_apm_stop(struct iwl_priv *priv)
  106. {
  107. unsigned long flags;
  108. iwl5000_apm_stop_master(priv);
  109. spin_lock_irqsave(&priv->lock, flags);
  110. iwl_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_SW_RESET);
  111. udelay(10);
  112. iwl_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
  113. spin_unlock_irqrestore(&priv->lock, flags);
  114. }
  115. static int iwl5000_apm_reset(struct iwl_priv *priv)
  116. {
  117. int ret = 0;
  118. unsigned long flags;
  119. iwl5000_apm_stop_master(priv);
  120. spin_lock_irqsave(&priv->lock, flags);
  121. iwl_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_SW_RESET);
  122. udelay(10);
  123. /* FIXME: put here L1A -L0S w/a */
  124. iwl_set_bit(priv, CSR_ANA_PLL_CFG, CSR50_ANA_PLL_CFG_VAL);
  125. /* set "initialization complete" bit to move adapter
  126. * D0U* --> D0A* state */
  127. iwl_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
  128. /* wait for clock stabilization */
  129. ret = iwl_poll_bit(priv, CSR_GP_CNTRL,
  130. CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY,
  131. CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, 25000);
  132. if (ret < 0) {
  133. IWL_DEBUG_INFO("Failed to init the card\n");
  134. goto out;
  135. }
  136. ret = iwl_grab_nic_access(priv);
  137. if (ret)
  138. goto out;
  139. /* enable DMA */
  140. iwl_write_prph(priv, APMG_CLK_EN_REG, APMG_CLK_VAL_DMA_CLK_RQT);
  141. udelay(20);
  142. /* disable L1-Active */
  143. iwl_set_bits_prph(priv, APMG_PCIDEV_STT_REG,
  144. APMG_PCIDEV_STT_VAL_L1_ACT_DIS);
  145. iwl_release_nic_access(priv);
  146. out:
  147. spin_unlock_irqrestore(&priv->lock, flags);
  148. return ret;
  149. }
  150. static void iwl5000_nic_config(struct iwl_priv *priv)
  151. {
  152. unsigned long flags;
  153. u16 radio_cfg;
  154. u8 val_link;
  155. spin_lock_irqsave(&priv->lock, flags);
  156. pci_read_config_byte(priv->pci_dev, PCI_LINK_CTRL, &val_link);
  157. /* L1 is enabled by BIOS */
  158. if ((val_link & PCI_LINK_VAL_L1_EN) == PCI_LINK_VAL_L1_EN)
  159. /* diable L0S disabled L1A enabled */
  160. iwl_set_bit(priv, CSR_GIO_REG, CSR_GIO_REG_VAL_L0S_ENABLED);
  161. else
  162. /* L0S enabled L1A disabled */
  163. iwl_clear_bit(priv, CSR_GIO_REG, CSR_GIO_REG_VAL_L0S_ENABLED);
  164. radio_cfg = iwl_eeprom_query16(priv, EEPROM_RADIO_CONFIG);
  165. /* write radio config values to register */
  166. if (EEPROM_RF_CFG_TYPE_MSK(radio_cfg) < EEPROM_5000_RF_CFG_TYPE_MAX)
  167. iwl_set_bit(priv, CSR_HW_IF_CONFIG_REG,
  168. EEPROM_RF_CFG_TYPE_MSK(radio_cfg) |
  169. EEPROM_RF_CFG_STEP_MSK(radio_cfg) |
  170. EEPROM_RF_CFG_DASH_MSK(radio_cfg));
  171. /* set CSR_HW_CONFIG_REG for uCode use */
  172. iwl_set_bit(priv, CSR_HW_IF_CONFIG_REG,
  173. CSR_HW_IF_CONFIG_REG_BIT_RADIO_SI |
  174. CSR_HW_IF_CONFIG_REG_BIT_MAC_SI);
  175. spin_unlock_irqrestore(&priv->lock, flags);
  176. }
  177. /*
  178. * EEPROM
  179. */
  180. static u32 eeprom_indirect_address(const struct iwl_priv *priv, u32 address)
  181. {
  182. u16 offset = 0;
  183. if ((address & INDIRECT_ADDRESS) == 0)
  184. return address;
  185. switch (address & INDIRECT_TYPE_MSK) {
  186. case INDIRECT_HOST:
  187. offset = iwl_eeprom_query16(priv, EEPROM_5000_LINK_HOST);
  188. break;
  189. case INDIRECT_GENERAL:
  190. offset = iwl_eeprom_query16(priv, EEPROM_5000_LINK_GENERAL);
  191. break;
  192. case INDIRECT_REGULATORY:
  193. offset = iwl_eeprom_query16(priv, EEPROM_5000_LINK_REGULATORY);
  194. break;
  195. case INDIRECT_CALIBRATION:
  196. offset = iwl_eeprom_query16(priv, EEPROM_5000_LINK_CALIBRATION);
  197. break;
  198. case INDIRECT_PROCESS_ADJST:
  199. offset = iwl_eeprom_query16(priv, EEPROM_5000_LINK_PROCESS_ADJST);
  200. break;
  201. case INDIRECT_OTHERS:
  202. offset = iwl_eeprom_query16(priv, EEPROM_5000_LINK_OTHERS);
  203. break;
  204. default:
  205. IWL_ERROR("illegal indirect type: 0x%X\n",
  206. address & INDIRECT_TYPE_MSK);
  207. break;
  208. }
  209. /* translate the offset from words to byte */
  210. return (address & ADDRESS_MSK) + (offset << 1);
  211. }
  212. static int iwl5000_eeprom_check_version(struct iwl_priv *priv)
  213. {
  214. u16 eeprom_ver;
  215. struct iwl_eeprom_calib_hdr {
  216. u8 version;
  217. u8 pa_type;
  218. u16 voltage;
  219. } *hdr;
  220. eeprom_ver = iwl_eeprom_query16(priv, EEPROM_VERSION);
  221. hdr = (struct iwl_eeprom_calib_hdr *)iwl_eeprom_query_addr(priv,
  222. EEPROM_5000_CALIB_ALL);
  223. if (eeprom_ver < EEPROM_5000_EEPROM_VERSION ||
  224. hdr->version < EEPROM_5000_TX_POWER_VERSION)
  225. goto err;
  226. return 0;
  227. err:
  228. IWL_ERROR("Unsuported EEPROM VER=0x%x < 0x%x CALIB=0x%x < 0x%x\n",
  229. eeprom_ver, EEPROM_5000_EEPROM_VERSION,
  230. hdr->version, EEPROM_5000_TX_POWER_VERSION);
  231. return -EINVAL;
  232. }
  233. #ifdef CONFIG_IWL5000_RUN_TIME_CALIB
  234. static void iwl5000_gain_computation(struct iwl_priv *priv,
  235. u32 average_noise[NUM_RX_CHAINS],
  236. u16 min_average_noise_antenna_i,
  237. u32 min_average_noise)
  238. {
  239. int i;
  240. s32 delta_g;
  241. struct iwl_chain_noise_data *data = &priv->chain_noise_data;
  242. /* Find Gain Code for the antennas B and C */
  243. for (i = 1; i < NUM_RX_CHAINS; i++) {
  244. if ((data->disconn_array[i])) {
  245. data->delta_gain_code[i] = 0;
  246. continue;
  247. }
  248. delta_g = (1000 * ((s32)average_noise[0] -
  249. (s32)average_noise[i])) / 1500;
  250. /* bound gain by 2 bits value max, 3rd bit is sign */
  251. data->delta_gain_code[i] =
  252. min(abs(delta_g), CHAIN_NOISE_MAX_DELTA_GAIN_CODE);
  253. if (delta_g < 0)
  254. /* set negative sign */
  255. data->delta_gain_code[i] |= (1 << 2);
  256. }
  257. IWL_DEBUG_CALIB("Delta gains: ANT_B = %d ANT_C = %d\n",
  258. data->delta_gain_code[1], data->delta_gain_code[2]);
  259. if (!data->radio_write) {
  260. struct iwl5000_calibration_chain_noise_gain_cmd cmd;
  261. memset(&cmd, 0, sizeof(cmd));
  262. cmd.op_code = IWL5000_PHY_CALIBRATE_CHAIN_NOISE_GAIN_CMD;
  263. cmd.delta_gain_1 = data->delta_gain_code[1];
  264. cmd.delta_gain_2 = data->delta_gain_code[2];
  265. iwl_send_cmd_pdu_async(priv, REPLY_PHY_CALIBRATION_CMD,
  266. sizeof(cmd), &cmd, NULL);
  267. data->radio_write = 1;
  268. data->state = IWL_CHAIN_NOISE_CALIBRATED;
  269. }
  270. data->chain_noise_a = 0;
  271. data->chain_noise_b = 0;
  272. data->chain_noise_c = 0;
  273. data->chain_signal_a = 0;
  274. data->chain_signal_b = 0;
  275. data->chain_signal_c = 0;
  276. data->beacon_count = 0;
  277. }
  278. static void iwl5000_chain_noise_reset(struct iwl_priv *priv)
  279. {
  280. struct iwl_chain_noise_data *data = &priv->chain_noise_data;
  281. if ((data->state == IWL_CHAIN_NOISE_ALIVE) && iwl_is_associated(priv)) {
  282. struct iwl5000_calibration_chain_noise_reset_cmd cmd;
  283. memset(&cmd, 0, sizeof(cmd));
  284. cmd.op_code = IWL5000_PHY_CALIBRATE_CHAIN_NOISE_RESET_CMD;
  285. if (iwl_send_cmd_pdu(priv, REPLY_PHY_CALIBRATION_CMD,
  286. sizeof(cmd), &cmd))
  287. IWL_ERROR("Could not send REPLY_PHY_CALIBRATION_CMD\n");
  288. data->state = IWL_CHAIN_NOISE_ACCUMULATE;
  289. IWL_DEBUG_CALIB("Run chain_noise_calibrate\n");
  290. }
  291. }
  292. static struct iwl_sensitivity_ranges iwl5000_sensitivity = {
  293. .min_nrg_cck = 95,
  294. .max_nrg_cck = 0,
  295. .auto_corr_min_ofdm = 90,
  296. .auto_corr_min_ofdm_mrc = 170,
  297. .auto_corr_min_ofdm_x1 = 120,
  298. .auto_corr_min_ofdm_mrc_x1 = 240,
  299. .auto_corr_max_ofdm = 120,
  300. .auto_corr_max_ofdm_mrc = 210,
  301. .auto_corr_max_ofdm_x1 = 155,
  302. .auto_corr_max_ofdm_mrc_x1 = 290,
  303. .auto_corr_min_cck = 125,
  304. .auto_corr_max_cck = 200,
  305. .auto_corr_min_cck_mrc = 170,
  306. .auto_corr_max_cck_mrc = 400,
  307. .nrg_th_cck = 95,
  308. .nrg_th_ofdm = 95,
  309. };
  310. #endif /* CONFIG_IWL5000_RUN_TIME_CALIB */
  311. static const u8 *iwl5000_eeprom_query_addr(const struct iwl_priv *priv,
  312. size_t offset)
  313. {
  314. u32 address = eeprom_indirect_address(priv, offset);
  315. BUG_ON(address >= priv->cfg->eeprom_size);
  316. return &priv->eeprom[address];
  317. }
  318. /*
  319. * Calibration
  320. */
  321. static int iwl5000_send_Xtal_calib(struct iwl_priv *priv)
  322. {
  323. u16 *xtal_calib = (u16 *)iwl_eeprom_query_addr(priv, EEPROM_5000_XTAL);
  324. struct iwl5000_calibration cal_cmd = {
  325. .op_code = IWL5000_PHY_CALIBRATE_CRYSTAL_FRQ_CMD,
  326. .data = {
  327. (u8)xtal_calib[0],
  328. (u8)xtal_calib[1],
  329. }
  330. };
  331. return iwl_send_cmd_pdu(priv, REPLY_PHY_CALIBRATION_CMD,
  332. sizeof(cal_cmd), &cal_cmd);
  333. }
  334. static int iwl5000_send_calib_results(struct iwl_priv *priv)
  335. {
  336. int ret = 0;
  337. if (priv->calib_results.lo_res)
  338. ret = iwl_send_cmd_pdu(priv, REPLY_PHY_CALIBRATION_CMD,
  339. priv->calib_results.lo_res_len,
  340. priv->calib_results.lo_res);
  341. if (ret)
  342. goto err;
  343. if (priv->calib_results.tx_iq_res)
  344. ret = iwl_send_cmd_pdu(priv, REPLY_PHY_CALIBRATION_CMD,
  345. priv->calib_results.tx_iq_res_len,
  346. priv->calib_results.tx_iq_res);
  347. if (ret)
  348. goto err;
  349. if (priv->calib_results.tx_iq_perd_res)
  350. ret = iwl_send_cmd_pdu(priv, REPLY_PHY_CALIBRATION_CMD,
  351. priv->calib_results.tx_iq_perd_res_len,
  352. priv->calib_results.tx_iq_perd_res);
  353. if (ret)
  354. goto err;
  355. return 0;
  356. err:
  357. IWL_ERROR("Error %d\n", ret);
  358. return ret;
  359. }
  360. static int iwl5000_send_calib_cfg(struct iwl_priv *priv)
  361. {
  362. struct iwl5000_calib_cfg_cmd calib_cfg_cmd;
  363. struct iwl_host_cmd cmd = {
  364. .id = CALIBRATION_CFG_CMD,
  365. .len = sizeof(struct iwl5000_calib_cfg_cmd),
  366. .data = &calib_cfg_cmd,
  367. };
  368. memset(&calib_cfg_cmd, 0, sizeof(calib_cfg_cmd));
  369. calib_cfg_cmd.ucd_calib_cfg.once.is_enable = IWL_CALIB_INIT_CFG_ALL;
  370. calib_cfg_cmd.ucd_calib_cfg.once.start = IWL_CALIB_INIT_CFG_ALL;
  371. calib_cfg_cmd.ucd_calib_cfg.once.send_res = IWL_CALIB_INIT_CFG_ALL;
  372. calib_cfg_cmd.ucd_calib_cfg.flags = IWL_CALIB_INIT_CFG_ALL;
  373. return iwl_send_cmd(priv, &cmd);
  374. }
  375. static void iwl5000_rx_calib_result(struct iwl_priv *priv,
  376. struct iwl_rx_mem_buffer *rxb)
  377. {
  378. struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
  379. struct iwl5000_calib_hdr *hdr = (struct iwl5000_calib_hdr *)pkt->u.raw;
  380. int len = le32_to_cpu(pkt->len) & FH_RSCSR_FRAME_SIZE_MSK;
  381. iwl_free_calib_results(priv);
  382. /* reduce the size of the length field itself */
  383. len -= 4;
  384. switch (hdr->op_code) {
  385. case IWL5000_PHY_CALIBRATE_LO_CMD:
  386. priv->calib_results.lo_res = kzalloc(len, GFP_ATOMIC);
  387. priv->calib_results.lo_res_len = len;
  388. memcpy(priv->calib_results.lo_res, pkt->u.raw, len);
  389. break;
  390. case IWL5000_PHY_CALIBRATE_TX_IQ_CMD:
  391. priv->calib_results.tx_iq_res = kzalloc(len, GFP_ATOMIC);
  392. priv->calib_results.tx_iq_res_len = len;
  393. memcpy(priv->calib_results.tx_iq_res, pkt->u.raw, len);
  394. break;
  395. case IWL5000_PHY_CALIBRATE_TX_IQ_PERD_CMD:
  396. priv->calib_results.tx_iq_perd_res = kzalloc(len, GFP_ATOMIC);
  397. priv->calib_results.tx_iq_perd_res_len = len;
  398. memcpy(priv->calib_results.tx_iq_perd_res, pkt->u.raw, len);
  399. break;
  400. default:
  401. IWL_ERROR("Unknown calibration notification %d\n",
  402. hdr->op_code);
  403. return;
  404. }
  405. }
  406. static void iwl5000_rx_calib_complete(struct iwl_priv *priv,
  407. struct iwl_rx_mem_buffer *rxb)
  408. {
  409. IWL_DEBUG_INFO("Init. calibration is completed, restarting fw.\n");
  410. queue_work(priv->workqueue, &priv->restart);
  411. }
  412. /*
  413. * ucode
  414. */
  415. static int iwl5000_load_section(struct iwl_priv *priv,
  416. struct fw_desc *image,
  417. u32 dst_addr)
  418. {
  419. int ret = 0;
  420. unsigned long flags;
  421. dma_addr_t phy_addr = image->p_addr;
  422. u32 byte_cnt = image->len;
  423. spin_lock_irqsave(&priv->lock, flags);
  424. ret = iwl_grab_nic_access(priv);
  425. if (ret) {
  426. spin_unlock_irqrestore(&priv->lock, flags);
  427. return ret;
  428. }
  429. iwl_write_direct32(priv,
  430. FH_TCSR_CHNL_TX_CONFIG_REG(FH_SRVC_CHNL),
  431. FH_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_PAUSE);
  432. iwl_write_direct32(priv,
  433. FH_SRVC_CHNL_SRAM_ADDR_REG(FH_SRVC_CHNL), dst_addr);
  434. iwl_write_direct32(priv,
  435. FH_TFDIB_CTRL0_REG(FH_SRVC_CHNL),
  436. phy_addr & FH_MEM_TFDIB_DRAM_ADDR_LSB_MSK);
  437. /* FIME: write the MSB of the phy_addr in CTRL1
  438. * iwl_write_direct32(priv,
  439. IWL_FH_TFDIB_CTRL1_REG(IWL_FH_SRVC_CHNL),
  440. ((phy_addr & MSB_MSK)
  441. << FH_MEM_TFDIB_REG1_ADDR_BITSHIFT) | byte_count);
  442. */
  443. iwl_write_direct32(priv,
  444. FH_TFDIB_CTRL1_REG(FH_SRVC_CHNL), byte_cnt);
  445. iwl_write_direct32(priv,
  446. FH_TCSR_CHNL_TX_BUF_STS_REG(FH_SRVC_CHNL),
  447. 1 << FH_TCSR_CHNL_TX_BUF_STS_REG_POS_TB_NUM |
  448. 1 << FH_TCSR_CHNL_TX_BUF_STS_REG_POS_TB_IDX |
  449. FH_TCSR_CHNL_TX_BUF_STS_REG_VAL_TFDB_VALID);
  450. iwl_write_direct32(priv,
  451. FH_TCSR_CHNL_TX_CONFIG_REG(FH_SRVC_CHNL),
  452. FH_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_ENABLE |
  453. FH_TCSR_TX_CONFIG_REG_VAL_DMA_CREDIT_DISABLE_VAL |
  454. FH_TCSR_TX_CONFIG_REG_VAL_CIRQ_HOST_ENDTFD);
  455. iwl_release_nic_access(priv);
  456. spin_unlock_irqrestore(&priv->lock, flags);
  457. return 0;
  458. }
  459. static int iwl5000_load_given_ucode(struct iwl_priv *priv,
  460. struct fw_desc *inst_image,
  461. struct fw_desc *data_image)
  462. {
  463. int ret = 0;
  464. ret = iwl5000_load_section(
  465. priv, inst_image, RTC_INST_LOWER_BOUND);
  466. if (ret)
  467. return ret;
  468. IWL_DEBUG_INFO("INST uCode section being loaded...\n");
  469. ret = wait_event_interruptible_timeout(priv->wait_command_queue,
  470. priv->ucode_write_complete, 5 * HZ);
  471. if (ret == -ERESTARTSYS) {
  472. IWL_ERROR("Could not load the INST uCode section due "
  473. "to interrupt\n");
  474. return ret;
  475. }
  476. if (!ret) {
  477. IWL_ERROR("Could not load the INST uCode section\n");
  478. return -ETIMEDOUT;
  479. }
  480. priv->ucode_write_complete = 0;
  481. ret = iwl5000_load_section(
  482. priv, data_image, RTC_DATA_LOWER_BOUND);
  483. if (ret)
  484. return ret;
  485. IWL_DEBUG_INFO("DATA uCode section being loaded...\n");
  486. ret = wait_event_interruptible_timeout(priv->wait_command_queue,
  487. priv->ucode_write_complete, 5 * HZ);
  488. if (ret == -ERESTARTSYS) {
  489. IWL_ERROR("Could not load the INST uCode section due "
  490. "to interrupt\n");
  491. return ret;
  492. } else if (!ret) {
  493. IWL_ERROR("Could not load the DATA uCode section\n");
  494. return -ETIMEDOUT;
  495. } else
  496. ret = 0;
  497. priv->ucode_write_complete = 0;
  498. return ret;
  499. }
  500. static int iwl5000_load_ucode(struct iwl_priv *priv)
  501. {
  502. int ret = 0;
  503. /* check whether init ucode should be loaded, or rather runtime ucode */
  504. if (priv->ucode_init.len && (priv->ucode_type == UCODE_NONE)) {
  505. IWL_DEBUG_INFO("Init ucode found. Loading init ucode...\n");
  506. ret = iwl5000_load_given_ucode(priv,
  507. &priv->ucode_init, &priv->ucode_init_data);
  508. if (!ret) {
  509. IWL_DEBUG_INFO("Init ucode load complete.\n");
  510. priv->ucode_type = UCODE_INIT;
  511. }
  512. } else {
  513. IWL_DEBUG_INFO("Init ucode not found, or already loaded. "
  514. "Loading runtime ucode...\n");
  515. ret = iwl5000_load_given_ucode(priv,
  516. &priv->ucode_code, &priv->ucode_data);
  517. if (!ret) {
  518. IWL_DEBUG_INFO("Runtime ucode load complete.\n");
  519. priv->ucode_type = UCODE_RT;
  520. }
  521. }
  522. return ret;
  523. }
  524. static void iwl5000_init_alive_start(struct iwl_priv *priv)
  525. {
  526. int ret = 0;
  527. /* Check alive response for "valid" sign from uCode */
  528. if (priv->card_alive_init.is_valid != UCODE_VALID_OK) {
  529. /* We had an error bringing up the hardware, so take it
  530. * all the way back down so we can try again */
  531. IWL_DEBUG_INFO("Initialize Alive failed.\n");
  532. goto restart;
  533. }
  534. /* initialize uCode was loaded... verify inst image.
  535. * This is a paranoid check, because we would not have gotten the
  536. * "initialize" alive if code weren't properly loaded. */
  537. if (iwl_verify_ucode(priv)) {
  538. /* Runtime instruction load was bad;
  539. * take it all the way back down so we can try again */
  540. IWL_DEBUG_INFO("Bad \"initialize\" uCode load.\n");
  541. goto restart;
  542. }
  543. iwlcore_clear_stations_table(priv);
  544. ret = priv->cfg->ops->lib->alive_notify(priv);
  545. if (ret) {
  546. IWL_WARNING("Could not complete ALIVE transition: %d\n", ret);
  547. goto restart;
  548. }
  549. iwl5000_send_calib_cfg(priv);
  550. return;
  551. restart:
  552. /* real restart (first load init_ucode) */
  553. queue_work(priv->workqueue, &priv->restart);
  554. }
  555. static void iwl5000_set_wr_ptrs(struct iwl_priv *priv,
  556. int txq_id, u32 index)
  557. {
  558. iwl_write_direct32(priv, HBUS_TARG_WRPTR,
  559. (index & 0xff) | (txq_id << 8));
  560. iwl_write_prph(priv, IWL50_SCD_QUEUE_RDPTR(txq_id), index);
  561. }
  562. static void iwl5000_tx_queue_set_status(struct iwl_priv *priv,
  563. struct iwl_tx_queue *txq,
  564. int tx_fifo_id, int scd_retry)
  565. {
  566. int txq_id = txq->q.id;
  567. int active = test_bit(txq_id, &priv->txq_ctx_active_msk)?1:0;
  568. iwl_write_prph(priv, IWL50_SCD_QUEUE_STATUS_BITS(txq_id),
  569. (active << IWL50_SCD_QUEUE_STTS_REG_POS_ACTIVE) |
  570. (tx_fifo_id << IWL50_SCD_QUEUE_STTS_REG_POS_TXF) |
  571. (1 << IWL50_SCD_QUEUE_STTS_REG_POS_WSL) |
  572. IWL50_SCD_QUEUE_STTS_REG_MSK);
  573. txq->sched_retry = scd_retry;
  574. IWL_DEBUG_INFO("%s %s Queue %d on AC %d\n",
  575. active ? "Activate" : "Deactivate",
  576. scd_retry ? "BA" : "AC", txq_id, tx_fifo_id);
  577. }
  578. static int iwl5000_send_wimax_coex(struct iwl_priv *priv)
  579. {
  580. struct iwl_wimax_coex_cmd coex_cmd;
  581. memset(&coex_cmd, 0, sizeof(coex_cmd));
  582. return iwl_send_cmd_pdu(priv, COEX_PRIORITY_TABLE_CMD,
  583. sizeof(coex_cmd), &coex_cmd);
  584. }
  585. static int iwl5000_alive_notify(struct iwl_priv *priv)
  586. {
  587. u32 a;
  588. int i = 0;
  589. unsigned long flags;
  590. int ret;
  591. spin_lock_irqsave(&priv->lock, flags);
  592. ret = iwl_grab_nic_access(priv);
  593. if (ret) {
  594. spin_unlock_irqrestore(&priv->lock, flags);
  595. return ret;
  596. }
  597. priv->scd_base_addr = iwl_read_prph(priv, IWL50_SCD_SRAM_BASE_ADDR);
  598. a = priv->scd_base_addr + IWL50_SCD_CONTEXT_DATA_OFFSET;
  599. for (; a < priv->scd_base_addr + IWL50_SCD_TX_STTS_BITMAP_OFFSET;
  600. a += 4)
  601. iwl_write_targ_mem(priv, a, 0);
  602. for (; a < priv->scd_base_addr + IWL50_SCD_TRANSLATE_TBL_OFFSET;
  603. a += 4)
  604. iwl_write_targ_mem(priv, a, 0);
  605. for (; a < sizeof(u16) * priv->hw_params.max_txq_num; a += 4)
  606. iwl_write_targ_mem(priv, a, 0);
  607. iwl_write_prph(priv, IWL50_SCD_DRAM_BASE_ADDR,
  608. (priv->shared_phys +
  609. offsetof(struct iwl5000_shared, queues_byte_cnt_tbls)) >> 10);
  610. iwl_write_prph(priv, IWL50_SCD_QUEUECHAIN_SEL,
  611. IWL50_SCD_QUEUECHAIN_SEL_ALL(
  612. priv->hw_params.max_txq_num));
  613. iwl_write_prph(priv, IWL50_SCD_AGGR_SEL, 0);
  614. /* initiate the queues */
  615. for (i = 0; i < priv->hw_params.max_txq_num; i++) {
  616. iwl_write_prph(priv, IWL50_SCD_QUEUE_RDPTR(i), 0);
  617. iwl_write_direct32(priv, HBUS_TARG_WRPTR, 0 | (i << 8));
  618. iwl_write_targ_mem(priv, priv->scd_base_addr +
  619. IWL50_SCD_CONTEXT_QUEUE_OFFSET(i), 0);
  620. iwl_write_targ_mem(priv, priv->scd_base_addr +
  621. IWL50_SCD_CONTEXT_QUEUE_OFFSET(i) +
  622. sizeof(u32),
  623. ((SCD_WIN_SIZE <<
  624. IWL50_SCD_QUEUE_CTX_REG2_WIN_SIZE_POS) &
  625. IWL50_SCD_QUEUE_CTX_REG2_WIN_SIZE_MSK) |
  626. ((SCD_FRAME_LIMIT <<
  627. IWL50_SCD_QUEUE_CTX_REG2_FRAME_LIMIT_POS) &
  628. IWL50_SCD_QUEUE_CTX_REG2_FRAME_LIMIT_MSK));
  629. }
  630. iwl_write_prph(priv, IWL50_SCD_INTERRUPT_MASK,
  631. IWL_MASK(0, priv->hw_params.max_txq_num));
  632. /* Activate all Tx DMA/FIFO channels */
  633. priv->cfg->ops->lib->txq_set_sched(priv, IWL_MASK(0, 7));
  634. iwl5000_set_wr_ptrs(priv, IWL_CMD_QUEUE_NUM, 0);
  635. /* map qos queues to fifos one-to-one */
  636. for (i = 0; i < ARRAY_SIZE(iwl5000_default_queue_to_tx_fifo); i++) {
  637. int ac = iwl5000_default_queue_to_tx_fifo[i];
  638. iwl_txq_ctx_activate(priv, i);
  639. iwl5000_tx_queue_set_status(priv, &priv->txq[i], ac, 0);
  640. }
  641. /* TODO - need to initialize those FIFOs inside the loop above,
  642. * not only mark them as active */
  643. iwl_txq_ctx_activate(priv, 4);
  644. iwl_txq_ctx_activate(priv, 7);
  645. iwl_txq_ctx_activate(priv, 8);
  646. iwl_txq_ctx_activate(priv, 9);
  647. iwl_release_nic_access(priv);
  648. spin_unlock_irqrestore(&priv->lock, flags);
  649. iwl5000_send_wimax_coex(priv);
  650. iwl5000_send_Xtal_calib(priv);
  651. if (priv->ucode_type == UCODE_RT) {
  652. iwl5000_send_calib_results(priv);
  653. set_bit(STATUS_READY, &priv->status);
  654. priv->is_open = 1;
  655. }
  656. return 0;
  657. }
  658. static int iwl5000_hw_set_hw_params(struct iwl_priv *priv)
  659. {
  660. if ((priv->cfg->mod_params->num_of_queues > IWL50_NUM_QUEUES) ||
  661. (priv->cfg->mod_params->num_of_queues < IWL_MIN_NUM_QUEUES)) {
  662. IWL_ERROR("invalid queues_num, should be between %d and %d\n",
  663. IWL_MIN_NUM_QUEUES, IWL50_NUM_QUEUES);
  664. return -EINVAL;
  665. }
  666. priv->hw_params.max_txq_num = priv->cfg->mod_params->num_of_queues;
  667. priv->hw_params.sw_crypto = priv->cfg->mod_params->sw_crypto;
  668. priv->hw_params.max_rxq_size = RX_QUEUE_SIZE;
  669. priv->hw_params.max_rxq_log = RX_QUEUE_SIZE_LOG;
  670. if (priv->cfg->mod_params->amsdu_size_8K)
  671. priv->hw_params.rx_buf_size = IWL_RX_BUF_SIZE_8K;
  672. else
  673. priv->hw_params.rx_buf_size = IWL_RX_BUF_SIZE_4K;
  674. priv->hw_params.max_pkt_size = priv->hw_params.rx_buf_size - 256;
  675. priv->hw_params.max_stations = IWL5000_STATION_COUNT;
  676. priv->hw_params.bcast_sta_id = IWL5000_BROADCAST_ID;
  677. priv->hw_params.max_data_size = IWL50_RTC_DATA_SIZE;
  678. priv->hw_params.max_inst_size = IWL50_RTC_INST_SIZE;
  679. priv->hw_params.max_bsm_size = BSM_SRAM_SIZE;
  680. priv->hw_params.fat_channel = BIT(IEEE80211_BAND_2GHZ) |
  681. BIT(IEEE80211_BAND_5GHZ);
  682. #ifdef CONFIG_IWL5000_RUN_TIME_CALIB
  683. priv->hw_params.sens = &iwl5000_sensitivity;
  684. #endif
  685. switch (priv->hw_rev & CSR_HW_REV_TYPE_MSK) {
  686. case CSR_HW_REV_TYPE_5100:
  687. case CSR_HW_REV_TYPE_5150:
  688. priv->hw_params.tx_chains_num = 1;
  689. priv->hw_params.rx_chains_num = 2;
  690. /* FIXME: move to ANT_A, ANT_B, ANT_C enum */
  691. priv->hw_params.valid_tx_ant = ANT_A;
  692. priv->hw_params.valid_rx_ant = ANT_AB;
  693. break;
  694. case CSR_HW_REV_TYPE_5300:
  695. case CSR_HW_REV_TYPE_5350:
  696. priv->hw_params.tx_chains_num = 3;
  697. priv->hw_params.rx_chains_num = 3;
  698. priv->hw_params.valid_tx_ant = ANT_ABC;
  699. priv->hw_params.valid_rx_ant = ANT_ABC;
  700. break;
  701. }
  702. switch (priv->hw_rev & CSR_HW_REV_TYPE_MSK) {
  703. case CSR_HW_REV_TYPE_5100:
  704. case CSR_HW_REV_TYPE_5300:
  705. /* 5X00 wants in Celsius */
  706. priv->hw_params.ct_kill_threshold = CT_KILL_THRESHOLD;
  707. break;
  708. case CSR_HW_REV_TYPE_5150:
  709. case CSR_HW_REV_TYPE_5350:
  710. /* 5X50 wants in Kelvin */
  711. priv->hw_params.ct_kill_threshold =
  712. CELSIUS_TO_KELVIN(CT_KILL_THRESHOLD);
  713. break;
  714. }
  715. return 0;
  716. }
  717. static int iwl5000_alloc_shared_mem(struct iwl_priv *priv)
  718. {
  719. priv->shared_virt = pci_alloc_consistent(priv->pci_dev,
  720. sizeof(struct iwl5000_shared),
  721. &priv->shared_phys);
  722. if (!priv->shared_virt)
  723. return -ENOMEM;
  724. memset(priv->shared_virt, 0, sizeof(struct iwl5000_shared));
  725. priv->rb_closed_offset = offsetof(struct iwl5000_shared, rb_closed);
  726. return 0;
  727. }
  728. static void iwl5000_free_shared_mem(struct iwl_priv *priv)
  729. {
  730. if (priv->shared_virt)
  731. pci_free_consistent(priv->pci_dev,
  732. sizeof(struct iwl5000_shared),
  733. priv->shared_virt,
  734. priv->shared_phys);
  735. }
  736. static int iwl5000_shared_mem_rx_idx(struct iwl_priv *priv)
  737. {
  738. struct iwl5000_shared *s = priv->shared_virt;
  739. return le32_to_cpu(s->rb_closed) & 0xFFF;
  740. }
  741. /**
  742. * iwl5000_txq_update_byte_cnt_tbl - Set up entry in Tx byte-count array
  743. */
  744. static void iwl5000_txq_update_byte_cnt_tbl(struct iwl_priv *priv,
  745. struct iwl_tx_queue *txq,
  746. u16 byte_cnt)
  747. {
  748. struct iwl5000_shared *shared_data = priv->shared_virt;
  749. int txq_id = txq->q.id;
  750. u8 sec_ctl = 0;
  751. u8 sta = 0;
  752. int len;
  753. len = byte_cnt + IWL_TX_CRC_SIZE + IWL_TX_DELIMITER_SIZE;
  754. if (txq_id != IWL_CMD_QUEUE_NUM) {
  755. sta = txq->cmd[txq->q.write_ptr].cmd.tx.sta_id;
  756. sec_ctl = txq->cmd[txq->q.write_ptr].cmd.tx.sec_ctl;
  757. switch (sec_ctl & TX_CMD_SEC_MSK) {
  758. case TX_CMD_SEC_CCM:
  759. len += CCMP_MIC_LEN;
  760. break;
  761. case TX_CMD_SEC_TKIP:
  762. len += TKIP_ICV_LEN;
  763. break;
  764. case TX_CMD_SEC_WEP:
  765. len += WEP_IV_LEN + WEP_ICV_LEN;
  766. break;
  767. }
  768. }
  769. IWL_SET_BITS16(shared_data->queues_byte_cnt_tbls[txq_id].
  770. tfd_offset[txq->q.write_ptr], byte_cnt, len);
  771. IWL_SET_BITS16(shared_data->queues_byte_cnt_tbls[txq_id].
  772. tfd_offset[txq->q.write_ptr], sta_id, sta);
  773. if (txq->q.write_ptr < IWL50_MAX_WIN_SIZE) {
  774. IWL_SET_BITS16(shared_data->queues_byte_cnt_tbls[txq_id].
  775. tfd_offset[IWL50_QUEUE_SIZE + txq->q.write_ptr],
  776. byte_cnt, len);
  777. IWL_SET_BITS16(shared_data->queues_byte_cnt_tbls[txq_id].
  778. tfd_offset[IWL50_QUEUE_SIZE + txq->q.write_ptr],
  779. sta_id, sta);
  780. }
  781. }
  782. static void iwl5000_txq_inval_byte_cnt_tbl(struct iwl_priv *priv,
  783. struct iwl_tx_queue *txq)
  784. {
  785. int txq_id = txq->q.id;
  786. struct iwl5000_shared *shared_data = priv->shared_virt;
  787. u8 sta = 0;
  788. if (txq_id != IWL_CMD_QUEUE_NUM)
  789. sta = txq->cmd[txq->q.read_ptr].cmd.tx.sta_id;
  790. shared_data->queues_byte_cnt_tbls[txq_id].tfd_offset[txq->q.read_ptr].
  791. val = cpu_to_le16(1 | (sta << 12));
  792. if (txq->q.write_ptr < IWL50_MAX_WIN_SIZE) {
  793. shared_data->queues_byte_cnt_tbls[txq_id].
  794. tfd_offset[IWL50_QUEUE_SIZE + txq->q.read_ptr].
  795. val = cpu_to_le16(1 | (sta << 12));
  796. }
  797. }
  798. static u16 iwl5000_build_addsta_hcmd(const struct iwl_addsta_cmd *cmd, u8 *data)
  799. {
  800. u16 size = (u16)sizeof(struct iwl_addsta_cmd);
  801. memcpy(data, cmd, size);
  802. return size;
  803. }
  804. /*
  805. * Activate/Deactivat Tx DMA/FIFO channels according tx fifos mask
  806. * must be called under priv->lock and mac access
  807. */
  808. static void iwl5000_txq_set_sched(struct iwl_priv *priv, u32 mask)
  809. {
  810. iwl_write_prph(priv, IWL50_SCD_TXFACT, mask);
  811. }
  812. static inline u32 iwl5000_get_scd_ssn(struct iwl5000_tx_resp *tx_resp)
  813. {
  814. __le32 *scd_ssn = (__le32 *)((u32 *)&tx_resp->status +
  815. tx_resp->frame_count);
  816. return le32_to_cpu(*scd_ssn) & MAX_SN;
  817. }
  818. static int iwl5000_tx_status_reply_tx(struct iwl_priv *priv,
  819. struct iwl_ht_agg *agg,
  820. struct iwl5000_tx_resp *tx_resp,
  821. u16 start_idx)
  822. {
  823. u16 status;
  824. struct agg_tx_status *frame_status = &tx_resp->status;
  825. struct ieee80211_tx_info *info = NULL;
  826. struct ieee80211_hdr *hdr = NULL;
  827. int i, sh;
  828. int txq_id, idx;
  829. u16 seq;
  830. if (agg->wait_for_ba)
  831. IWL_DEBUG_TX_REPLY("got tx response w/o block-ack\n");
  832. agg->frame_count = tx_resp->frame_count;
  833. agg->start_idx = start_idx;
  834. agg->rate_n_flags = le32_to_cpu(tx_resp->rate_n_flags);
  835. agg->bitmap = 0;
  836. /* # frames attempted by Tx command */
  837. if (agg->frame_count == 1) {
  838. /* Only one frame was attempted; no block-ack will arrive */
  839. status = le16_to_cpu(frame_status[0].status);
  840. seq = le16_to_cpu(frame_status[0].sequence);
  841. idx = SEQ_TO_INDEX(seq);
  842. txq_id = SEQ_TO_QUEUE(seq);
  843. /* FIXME: code repetition */
  844. IWL_DEBUG_TX_REPLY("FrameCnt = %d, StartIdx=%d idx=%d\n",
  845. agg->frame_count, agg->start_idx, idx);
  846. info = IEEE80211_SKB_CB(priv->txq[txq_id].txb[idx].skb[0]);
  847. info->status.retry_count = tx_resp->failure_frame;
  848. info->flags &= ~IEEE80211_TX_CTL_AMPDU;
  849. info->flags |= iwl_is_tx_success(status)?
  850. IEEE80211_TX_STAT_ACK : 0;
  851. iwl4965_hwrate_to_tx_control(priv,
  852. le32_to_cpu(tx_resp->rate_n_flags),
  853. info);
  854. /* FIXME: code repetition end */
  855. IWL_DEBUG_TX_REPLY("1 Frame 0x%x failure :%d\n",
  856. status & 0xff, tx_resp->failure_frame);
  857. IWL_DEBUG_TX_REPLY("Rate Info rate_n_flags=%x\n",
  858. iwl4965_hw_get_rate_n_flags(tx_resp->rate_n_flags));
  859. agg->wait_for_ba = 0;
  860. } else {
  861. /* Two or more frames were attempted; expect block-ack */
  862. u64 bitmap = 0;
  863. int start = agg->start_idx;
  864. /* Construct bit-map of pending frames within Tx window */
  865. for (i = 0; i < agg->frame_count; i++) {
  866. u16 sc;
  867. status = le16_to_cpu(frame_status[i].status);
  868. seq = le16_to_cpu(frame_status[i].sequence);
  869. idx = SEQ_TO_INDEX(seq);
  870. txq_id = SEQ_TO_QUEUE(seq);
  871. if (status & (AGG_TX_STATE_FEW_BYTES_MSK |
  872. AGG_TX_STATE_ABORT_MSK))
  873. continue;
  874. IWL_DEBUG_TX_REPLY("FrameCnt = %d, txq_id=%d idx=%d\n",
  875. agg->frame_count, txq_id, idx);
  876. hdr = iwl_tx_queue_get_hdr(priv, txq_id, idx);
  877. sc = le16_to_cpu(hdr->seq_ctrl);
  878. if (idx != (SEQ_TO_SN(sc) & 0xff)) {
  879. IWL_ERROR("BUG_ON idx doesn't match seq control"
  880. " idx=%d, seq_idx=%d, seq=%d\n",
  881. idx, SEQ_TO_SN(sc),
  882. hdr->seq_ctrl);
  883. return -1;
  884. }
  885. IWL_DEBUG_TX_REPLY("AGG Frame i=%d idx %d seq=%d\n",
  886. i, idx, SEQ_TO_SN(sc));
  887. sh = idx - start;
  888. if (sh > 64) {
  889. sh = (start - idx) + 0xff;
  890. bitmap = bitmap << sh;
  891. sh = 0;
  892. start = idx;
  893. } else if (sh < -64)
  894. sh = 0xff - (start - idx);
  895. else if (sh < 0) {
  896. sh = start - idx;
  897. start = idx;
  898. bitmap = bitmap << sh;
  899. sh = 0;
  900. }
  901. bitmap |= (1 << sh);
  902. IWL_DEBUG_TX_REPLY("start=%d bitmap=0x%x\n",
  903. start, (u32)(bitmap & 0xFFFFFFFF));
  904. }
  905. agg->bitmap = bitmap;
  906. agg->start_idx = start;
  907. agg->rate_n_flags = le32_to_cpu(tx_resp->rate_n_flags);
  908. IWL_DEBUG_TX_REPLY("Frames %d start_idx=%d bitmap=0x%llx\n",
  909. agg->frame_count, agg->start_idx,
  910. (unsigned long long)agg->bitmap);
  911. if (bitmap)
  912. agg->wait_for_ba = 1;
  913. }
  914. return 0;
  915. }
  916. static void iwl5000_rx_reply_tx(struct iwl_priv *priv,
  917. struct iwl_rx_mem_buffer *rxb)
  918. {
  919. struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
  920. u16 sequence = le16_to_cpu(pkt->hdr.sequence);
  921. int txq_id = SEQ_TO_QUEUE(sequence);
  922. int index = SEQ_TO_INDEX(sequence);
  923. struct iwl_tx_queue *txq = &priv->txq[txq_id];
  924. struct ieee80211_tx_info *info;
  925. struct iwl5000_tx_resp *tx_resp = (void *)&pkt->u.raw[0];
  926. u32 status = le16_to_cpu(tx_resp->status.status);
  927. #ifdef CONFIG_IWL4965_HT
  928. int tid = MAX_TID_COUNT, sta_id = IWL_INVALID_STATION;
  929. u16 fc;
  930. struct ieee80211_hdr *hdr;
  931. u8 *qc = NULL;
  932. #endif
  933. if ((index >= txq->q.n_bd) || (iwl_queue_used(&txq->q, index) == 0)) {
  934. IWL_ERROR("Read index for DMA queue txq_id (%d) index %d "
  935. "is out of range [0-%d] %d %d\n", txq_id,
  936. index, txq->q.n_bd, txq->q.write_ptr,
  937. txq->q.read_ptr);
  938. return;
  939. }
  940. info = IEEE80211_SKB_CB(txq->txb[txq->q.read_ptr].skb[0]);
  941. memset(&info->status, 0, sizeof(info->status));
  942. #ifdef CONFIG_IWL4965_HT
  943. hdr = iwl_tx_queue_get_hdr(priv, txq_id, index);
  944. fc = le16_to_cpu(hdr->frame_control);
  945. if (ieee80211_is_qos_data(fc)) {
  946. qc = ieee80211_get_qos_ctrl(hdr, ieee80211_get_hdrlen(fc));
  947. tid = qc[0] & 0xf;
  948. }
  949. sta_id = iwl_get_ra_sta_id(priv, hdr);
  950. if (txq->sched_retry && unlikely(sta_id == IWL_INVALID_STATION)) {
  951. IWL_ERROR("Station not known\n");
  952. return;
  953. }
  954. if (txq->sched_retry) {
  955. const u32 scd_ssn = iwl5000_get_scd_ssn(tx_resp);
  956. struct iwl_ht_agg *agg = NULL;
  957. if (!qc)
  958. return;
  959. agg = &priv->stations[sta_id].tid[tid].agg;
  960. iwl5000_tx_status_reply_tx(priv, agg, tx_resp, index);
  961. if ((tx_resp->frame_count == 1) && !iwl_is_tx_success(status)) {
  962. /* TODO: send BAR */
  963. }
  964. if (txq->q.read_ptr != (scd_ssn & 0xff)) {
  965. int freed, ampdu_q;
  966. index = iwl_queue_dec_wrap(scd_ssn & 0xff, txq->q.n_bd);
  967. IWL_DEBUG_TX_REPLY("Retry scheduler reclaim scd_ssn "
  968. "%d index %d\n", scd_ssn , index);
  969. freed = iwl_tx_queue_reclaim(priv, txq_id, index);
  970. priv->stations[sta_id].tid[tid].tfds_in_queue -= freed;
  971. if (iwl_queue_space(&txq->q) > txq->q.low_mark &&
  972. txq_id >= 0 && priv->mac80211_registered &&
  973. agg->state != IWL_EMPTYING_HW_QUEUE_DELBA) {
  974. /* calculate mac80211 ampdu sw queue to wake */
  975. ampdu_q = txq_id - IWL_BACK_QUEUE_FIRST_ID +
  976. priv->hw->queues;
  977. if (agg->state == IWL_AGG_OFF)
  978. ieee80211_wake_queue(priv->hw, txq_id);
  979. else
  980. ieee80211_wake_queue(priv->hw, ampdu_q);
  981. }
  982. iwl_txq_check_empty(priv, sta_id, tid, txq_id);
  983. }
  984. } else {
  985. #endif /* CONFIG_IWL4965_HT */
  986. info->status.retry_count = tx_resp->failure_frame;
  987. info->flags = iwl_is_tx_success(status) ? IEEE80211_TX_STAT_ACK : 0;
  988. iwl4965_hwrate_to_tx_control(priv, le32_to_cpu(tx_resp->rate_n_flags),
  989. info);
  990. IWL_DEBUG_TX("Tx queue %d Status %s (0x%08x) rate_n_flags 0x%x "
  991. "retries %d\n", txq_id, iwl_get_tx_fail_reason(status),
  992. status, le32_to_cpu(tx_resp->rate_n_flags),
  993. tx_resp->failure_frame);
  994. IWL_DEBUG_TX_REPLY("Tx queue reclaim %d\n", index);
  995. #ifdef CONFIG_IWL4965_HT
  996. if (index != -1) {
  997. int freed = iwl_tx_queue_reclaim(priv, txq_id, index);
  998. if (tid != MAX_TID_COUNT)
  999. priv->stations[sta_id].tid[tid].tfds_in_queue -= freed;
  1000. if (iwl_queue_space(&txq->q) > txq->q.low_mark &&
  1001. (txq_id >= 0) && priv->mac80211_registered)
  1002. ieee80211_wake_queue(priv->hw, txq_id);
  1003. if (tid != MAX_TID_COUNT)
  1004. iwl_txq_check_empty(priv, sta_id, tid, txq_id);
  1005. }
  1006. }
  1007. #endif /* CONFIG_IWL4965_HT */
  1008. if (iwl_check_bits(status, TX_ABORT_REQUIRED_MSK))
  1009. IWL_ERROR("TODO: Implement Tx ABORT REQUIRED!!!\n");
  1010. }
  1011. /* Currently 5000 is the supperset of everything */
  1012. static u16 iwl5000_get_hcmd_size(u8 cmd_id, u16 len)
  1013. {
  1014. return len;
  1015. }
  1016. static void iwl5000_rx_handler_setup(struct iwl_priv *priv)
  1017. {
  1018. /* init calibration handlers */
  1019. priv->rx_handlers[CALIBRATION_RES_NOTIFICATION] =
  1020. iwl5000_rx_calib_result;
  1021. priv->rx_handlers[CALIBRATION_COMPLETE_NOTIFICATION] =
  1022. iwl5000_rx_calib_complete;
  1023. priv->rx_handlers[REPLY_TX] = iwl5000_rx_reply_tx;
  1024. }
  1025. static int iwl5000_hw_valid_rtc_data_addr(u32 addr)
  1026. {
  1027. return (addr >= RTC_DATA_LOWER_BOUND) &&
  1028. (addr < IWL50_RTC_DATA_UPPER_BOUND);
  1029. }
  1030. static int iwl5000_send_rxon_assoc(struct iwl_priv *priv)
  1031. {
  1032. int ret = 0;
  1033. struct iwl5000_rxon_assoc_cmd rxon_assoc;
  1034. const struct iwl_rxon_cmd *rxon1 = &priv->staging_rxon;
  1035. const struct iwl_rxon_cmd *rxon2 = &priv->active_rxon;
  1036. if ((rxon1->flags == rxon2->flags) &&
  1037. (rxon1->filter_flags == rxon2->filter_flags) &&
  1038. (rxon1->cck_basic_rates == rxon2->cck_basic_rates) &&
  1039. (rxon1->ofdm_ht_single_stream_basic_rates ==
  1040. rxon2->ofdm_ht_single_stream_basic_rates) &&
  1041. (rxon1->ofdm_ht_dual_stream_basic_rates ==
  1042. rxon2->ofdm_ht_dual_stream_basic_rates) &&
  1043. (rxon1->ofdm_ht_triple_stream_basic_rates ==
  1044. rxon2->ofdm_ht_triple_stream_basic_rates) &&
  1045. (rxon1->acquisition_data == rxon2->acquisition_data) &&
  1046. (rxon1->rx_chain == rxon2->rx_chain) &&
  1047. (rxon1->ofdm_basic_rates == rxon2->ofdm_basic_rates)) {
  1048. IWL_DEBUG_INFO("Using current RXON_ASSOC. Not resending.\n");
  1049. return 0;
  1050. }
  1051. rxon_assoc.flags = priv->staging_rxon.flags;
  1052. rxon_assoc.filter_flags = priv->staging_rxon.filter_flags;
  1053. rxon_assoc.ofdm_basic_rates = priv->staging_rxon.ofdm_basic_rates;
  1054. rxon_assoc.cck_basic_rates = priv->staging_rxon.cck_basic_rates;
  1055. rxon_assoc.reserved1 = 0;
  1056. rxon_assoc.reserved2 = 0;
  1057. rxon_assoc.reserved3 = 0;
  1058. rxon_assoc.ofdm_ht_single_stream_basic_rates =
  1059. priv->staging_rxon.ofdm_ht_single_stream_basic_rates;
  1060. rxon_assoc.ofdm_ht_dual_stream_basic_rates =
  1061. priv->staging_rxon.ofdm_ht_dual_stream_basic_rates;
  1062. rxon_assoc.rx_chain_select_flags = priv->staging_rxon.rx_chain;
  1063. rxon_assoc.ofdm_ht_triple_stream_basic_rates =
  1064. priv->staging_rxon.ofdm_ht_triple_stream_basic_rates;
  1065. rxon_assoc.acquisition_data = priv->staging_rxon.acquisition_data;
  1066. ret = iwl_send_cmd_pdu_async(priv, REPLY_RXON_ASSOC,
  1067. sizeof(rxon_assoc), &rxon_assoc, NULL);
  1068. if (ret)
  1069. return ret;
  1070. return ret;
  1071. }
  1072. static struct iwl_hcmd_ops iwl5000_hcmd = {
  1073. .rxon_assoc = iwl5000_send_rxon_assoc,
  1074. };
  1075. static struct iwl_hcmd_utils_ops iwl5000_hcmd_utils = {
  1076. .get_hcmd_size = iwl5000_get_hcmd_size,
  1077. .build_addsta_hcmd = iwl5000_build_addsta_hcmd,
  1078. #ifdef CONFIG_IWL5000_RUN_TIME_CALIB
  1079. .gain_computation = iwl5000_gain_computation,
  1080. .chain_noise_reset = iwl5000_chain_noise_reset,
  1081. #endif
  1082. };
  1083. static struct iwl_lib_ops iwl5000_lib = {
  1084. .set_hw_params = iwl5000_hw_set_hw_params,
  1085. .alloc_shared_mem = iwl5000_alloc_shared_mem,
  1086. .free_shared_mem = iwl5000_free_shared_mem,
  1087. .shared_mem_rx_idx = iwl5000_shared_mem_rx_idx,
  1088. .txq_update_byte_cnt_tbl = iwl5000_txq_update_byte_cnt_tbl,
  1089. .txq_inval_byte_cnt_tbl = iwl5000_txq_inval_byte_cnt_tbl,
  1090. .txq_set_sched = iwl5000_txq_set_sched,
  1091. .rx_handler_setup = iwl5000_rx_handler_setup,
  1092. .is_valid_rtc_data_addr = iwl5000_hw_valid_rtc_data_addr,
  1093. .load_ucode = iwl5000_load_ucode,
  1094. .init_alive_start = iwl5000_init_alive_start,
  1095. .alive_notify = iwl5000_alive_notify,
  1096. .apm_ops = {
  1097. .init = iwl5000_apm_init,
  1098. .reset = iwl5000_apm_reset,
  1099. .stop = iwl5000_apm_stop,
  1100. .config = iwl5000_nic_config,
  1101. .set_pwr_src = iwl4965_set_pwr_src,
  1102. },
  1103. .eeprom_ops = {
  1104. .regulatory_bands = {
  1105. EEPROM_5000_REG_BAND_1_CHANNELS,
  1106. EEPROM_5000_REG_BAND_2_CHANNELS,
  1107. EEPROM_5000_REG_BAND_3_CHANNELS,
  1108. EEPROM_5000_REG_BAND_4_CHANNELS,
  1109. EEPROM_5000_REG_BAND_5_CHANNELS,
  1110. EEPROM_5000_REG_BAND_24_FAT_CHANNELS,
  1111. EEPROM_5000_REG_BAND_52_FAT_CHANNELS
  1112. },
  1113. .verify_signature = iwlcore_eeprom_verify_signature,
  1114. .acquire_semaphore = iwlcore_eeprom_acquire_semaphore,
  1115. .release_semaphore = iwlcore_eeprom_release_semaphore,
  1116. .check_version = iwl5000_eeprom_check_version,
  1117. .query_addr = iwl5000_eeprom_query_addr,
  1118. },
  1119. };
  1120. static struct iwl_ops iwl5000_ops = {
  1121. .lib = &iwl5000_lib,
  1122. .hcmd = &iwl5000_hcmd,
  1123. .utils = &iwl5000_hcmd_utils,
  1124. };
  1125. static struct iwl_mod_params iwl50_mod_params = {
  1126. .num_of_queues = IWL50_NUM_QUEUES,
  1127. .enable_qos = 1,
  1128. .amsdu_size_8K = 1,
  1129. .restart_fw = 1,
  1130. /* the rest are 0 by default */
  1131. };
  1132. struct iwl_cfg iwl5300_agn_cfg = {
  1133. .name = "5300AGN",
  1134. .fw_name = "iwlwifi-5000" IWL5000_UCODE_API ".ucode",
  1135. .sku = IWL_SKU_A|IWL_SKU_G|IWL_SKU_N,
  1136. .ops = &iwl5000_ops,
  1137. .eeprom_size = IWL_5000_EEPROM_IMG_SIZE,
  1138. .mod_params = &iwl50_mod_params,
  1139. };
  1140. struct iwl_cfg iwl5100_agn_cfg = {
  1141. .name = "5100AGN",
  1142. .fw_name = "iwlwifi-5000" IWL5000_UCODE_API ".ucode",
  1143. .sku = IWL_SKU_A|IWL_SKU_G|IWL_SKU_N,
  1144. .ops = &iwl5000_ops,
  1145. .eeprom_size = IWL_5000_EEPROM_IMG_SIZE,
  1146. .mod_params = &iwl50_mod_params,
  1147. };
  1148. struct iwl_cfg iwl5350_agn_cfg = {
  1149. .name = "5350AGN",
  1150. .fw_name = "iwlwifi-5000" IWL5000_UCODE_API ".ucode",
  1151. .sku = IWL_SKU_A|IWL_SKU_G|IWL_SKU_N,
  1152. .ops = &iwl5000_ops,
  1153. .eeprom_size = IWL_5000_EEPROM_IMG_SIZE,
  1154. .mod_params = &iwl50_mod_params,
  1155. };
  1156. module_param_named(disable50, iwl50_mod_params.disable, int, 0444);
  1157. MODULE_PARM_DESC(disable50,
  1158. "manually disable the 50XX radio (default 0 [radio on])");
  1159. module_param_named(swcrypto50, iwl50_mod_params.sw_crypto, bool, 0444);
  1160. MODULE_PARM_DESC(swcrypto50,
  1161. "using software crypto engine (default 0 [hardware])\n");
  1162. module_param_named(debug50, iwl50_mod_params.debug, int, 0444);
  1163. MODULE_PARM_DESC(debug50, "50XX debug output mask");
  1164. module_param_named(queues_num50, iwl50_mod_params.num_of_queues, int, 0444);
  1165. MODULE_PARM_DESC(queues_num50, "number of hw queues in 50xx series");
  1166. module_param_named(qos_enable50, iwl50_mod_params.enable_qos, int, 0444);
  1167. MODULE_PARM_DESC(qos_enable50, "enable all 50XX QoS functionality");
  1168. module_param_named(amsdu_size_8K50, iwl50_mod_params.amsdu_size_8K, int, 0444);
  1169. MODULE_PARM_DESC(amsdu_size_8K50, "enable 8K amsdu size in 50XX series");
  1170. module_param_named(fw_restart50, iwl50_mod_params.restart_fw, int, 0444);
  1171. MODULE_PARM_DESC(fw_restart50, "restart firmware in case of error");