iwl-5000.c 40 KB

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