iwl-5000.c 50 KB

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