iwl-5000.c 52 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731
  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. int iwl5000_alive_notify(struct iwl_priv *priv)
  506. {
  507. u32 a;
  508. unsigned long flags;
  509. int i, chan;
  510. u32 reg_val;
  511. spin_lock_irqsave(&priv->lock, flags);
  512. priv->scd_base_addr = iwl_read_prph(priv, IWL50_SCD_SRAM_BASE_ADDR);
  513. a = priv->scd_base_addr + IWL50_SCD_CONTEXT_DATA_OFFSET;
  514. for (; a < priv->scd_base_addr + IWL50_SCD_TX_STTS_BITMAP_OFFSET;
  515. a += 4)
  516. iwl_write_targ_mem(priv, a, 0);
  517. for (; a < priv->scd_base_addr + IWL50_SCD_TRANSLATE_TBL_OFFSET;
  518. a += 4)
  519. iwl_write_targ_mem(priv, a, 0);
  520. for (; a < priv->scd_base_addr +
  521. IWL50_SCD_TRANSLATE_TBL_OFFSET_QUEUE(priv->hw_params.max_txq_num); a += 4)
  522. iwl_write_targ_mem(priv, a, 0);
  523. iwl_write_prph(priv, IWL50_SCD_DRAM_BASE_ADDR,
  524. priv->scd_bc_tbls.dma >> 10);
  525. /* Enable DMA channel */
  526. for (chan = 0; chan < FH50_TCSR_CHNL_NUM ; chan++)
  527. iwl_write_direct32(priv, FH_TCSR_CHNL_TX_CONFIG_REG(chan),
  528. FH_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_ENABLE |
  529. FH_TCSR_TX_CONFIG_REG_VAL_DMA_CREDIT_ENABLE);
  530. /* Update FH chicken bits */
  531. reg_val = iwl_read_direct32(priv, FH_TX_CHICKEN_BITS_REG);
  532. iwl_write_direct32(priv, FH_TX_CHICKEN_BITS_REG,
  533. reg_val | FH_TX_CHICKEN_BITS_SCD_AUTO_RETRY_EN);
  534. iwl_write_prph(priv, IWL50_SCD_QUEUECHAIN_SEL,
  535. IWL50_SCD_QUEUECHAIN_SEL_ALL(priv->hw_params.max_txq_num));
  536. iwl_write_prph(priv, IWL50_SCD_AGGR_SEL, 0);
  537. /* initiate the queues */
  538. for (i = 0; i < priv->hw_params.max_txq_num; i++) {
  539. iwl_write_prph(priv, IWL50_SCD_QUEUE_RDPTR(i), 0);
  540. iwl_write_direct32(priv, HBUS_TARG_WRPTR, 0 | (i << 8));
  541. iwl_write_targ_mem(priv, priv->scd_base_addr +
  542. IWL50_SCD_CONTEXT_QUEUE_OFFSET(i), 0);
  543. iwl_write_targ_mem(priv, priv->scd_base_addr +
  544. IWL50_SCD_CONTEXT_QUEUE_OFFSET(i) +
  545. sizeof(u32),
  546. ((SCD_WIN_SIZE <<
  547. IWL50_SCD_QUEUE_CTX_REG2_WIN_SIZE_POS) &
  548. IWL50_SCD_QUEUE_CTX_REG2_WIN_SIZE_MSK) |
  549. ((SCD_FRAME_LIMIT <<
  550. IWL50_SCD_QUEUE_CTX_REG2_FRAME_LIMIT_POS) &
  551. IWL50_SCD_QUEUE_CTX_REG2_FRAME_LIMIT_MSK));
  552. }
  553. iwl_write_prph(priv, IWL50_SCD_INTERRUPT_MASK,
  554. IWL_MASK(0, priv->hw_params.max_txq_num));
  555. /* Activate all Tx DMA/FIFO channels */
  556. priv->cfg->ops->lib->txq_set_sched(priv, IWL_MASK(0, 7));
  557. iwl5000_set_wr_ptrs(priv, IWL_CMD_QUEUE_NUM, 0);
  558. /* map qos queues to fifos one-to-one */
  559. for (i = 0; i < ARRAY_SIZE(iwl5000_default_queue_to_tx_fifo); i++) {
  560. int ac = iwl5000_default_queue_to_tx_fifo[i];
  561. iwl_txq_ctx_activate(priv, i);
  562. iwl5000_tx_queue_set_status(priv, &priv->txq[i], ac, 0);
  563. }
  564. /*
  565. * TODO - need to initialize these queues and map them to FIFOs
  566. * in the loop above, not only mark them as active. We do this
  567. * because we want the first aggregation queue to be queue #10,
  568. * but do not use 8 or 9 otherwise yet.
  569. */
  570. iwl_txq_ctx_activate(priv, 7);
  571. iwl_txq_ctx_activate(priv, 8);
  572. iwl_txq_ctx_activate(priv, 9);
  573. spin_unlock_irqrestore(&priv->lock, flags);
  574. iwl_send_wimax_coex(priv);
  575. iwl5000_set_Xtal_calib(priv);
  576. iwl_send_calib_results(priv);
  577. return 0;
  578. }
  579. int iwl5000_hw_set_hw_params(struct iwl_priv *priv)
  580. {
  581. if (priv->cfg->mod_params->num_of_queues >= IWL_MIN_NUM_QUEUES &&
  582. priv->cfg->mod_params->num_of_queues <= IWL50_NUM_QUEUES)
  583. priv->cfg->num_of_queues =
  584. priv->cfg->mod_params->num_of_queues;
  585. priv->hw_params.max_txq_num = priv->cfg->num_of_queues;
  586. priv->hw_params.dma_chnl_num = FH50_TCSR_CHNL_NUM;
  587. priv->hw_params.scd_bc_tbls_size =
  588. priv->cfg->num_of_queues *
  589. sizeof(struct iwl5000_scd_bc_tbl);
  590. priv->hw_params.tfd_size = sizeof(struct iwl_tfd);
  591. priv->hw_params.max_stations = IWL5000_STATION_COUNT;
  592. priv->hw_params.bcast_sta_id = IWL5000_BROADCAST_ID;
  593. priv->hw_params.max_data_size = IWL50_RTC_DATA_SIZE;
  594. priv->hw_params.max_inst_size = IWL50_RTC_INST_SIZE;
  595. priv->hw_params.max_bsm_size = 0;
  596. priv->hw_params.ht40_channel = BIT(IEEE80211_BAND_2GHZ) |
  597. BIT(IEEE80211_BAND_5GHZ);
  598. priv->hw_params.rx_wrt_ptr_reg = FH_RSCSR_CHNL0_WPTR;
  599. priv->hw_params.tx_chains_num = num_of_ant(priv->cfg->valid_tx_ant);
  600. priv->hw_params.rx_chains_num = num_of_ant(priv->cfg->valid_rx_ant);
  601. priv->hw_params.valid_tx_ant = priv->cfg->valid_tx_ant;
  602. priv->hw_params.valid_rx_ant = priv->cfg->valid_rx_ant;
  603. if (priv->cfg->ops->lib->temp_ops.set_ct_kill)
  604. priv->cfg->ops->lib->temp_ops.set_ct_kill(priv);
  605. /* Set initial sensitivity parameters */
  606. /* Set initial calibration set */
  607. switch (priv->hw_rev & CSR_HW_REV_TYPE_MSK) {
  608. case CSR_HW_REV_TYPE_5150:
  609. priv->hw_params.sens = &iwl5150_sensitivity;
  610. priv->hw_params.calib_init_cfg =
  611. BIT(IWL_CALIB_DC) |
  612. BIT(IWL_CALIB_LO) |
  613. BIT(IWL_CALIB_TX_IQ) |
  614. BIT(IWL_CALIB_BASE_BAND);
  615. break;
  616. default:
  617. priv->hw_params.sens = &iwl5000_sensitivity;
  618. priv->hw_params.calib_init_cfg =
  619. BIT(IWL_CALIB_XTAL) |
  620. BIT(IWL_CALIB_LO) |
  621. BIT(IWL_CALIB_TX_IQ) |
  622. BIT(IWL_CALIB_TX_IQ_PERD) |
  623. BIT(IWL_CALIB_BASE_BAND);
  624. break;
  625. }
  626. return 0;
  627. }
  628. /**
  629. * iwl5000_txq_update_byte_cnt_tbl - Set up entry in Tx byte-count array
  630. */
  631. void iwl5000_txq_update_byte_cnt_tbl(struct iwl_priv *priv,
  632. struct iwl_tx_queue *txq,
  633. u16 byte_cnt)
  634. {
  635. struct iwl5000_scd_bc_tbl *scd_bc_tbl = priv->scd_bc_tbls.addr;
  636. int write_ptr = txq->q.write_ptr;
  637. int txq_id = txq->q.id;
  638. u8 sec_ctl = 0;
  639. u8 sta_id = 0;
  640. u16 len = byte_cnt + IWL_TX_CRC_SIZE + IWL_TX_DELIMITER_SIZE;
  641. __le16 bc_ent;
  642. WARN_ON(len > 0xFFF || write_ptr >= TFD_QUEUE_SIZE_MAX);
  643. if (txq_id != IWL_CMD_QUEUE_NUM) {
  644. sta_id = txq->cmd[txq->q.write_ptr]->cmd.tx.sta_id;
  645. sec_ctl = txq->cmd[txq->q.write_ptr]->cmd.tx.sec_ctl;
  646. switch (sec_ctl & TX_CMD_SEC_MSK) {
  647. case TX_CMD_SEC_CCM:
  648. len += CCMP_MIC_LEN;
  649. break;
  650. case TX_CMD_SEC_TKIP:
  651. len += TKIP_ICV_LEN;
  652. break;
  653. case TX_CMD_SEC_WEP:
  654. len += WEP_IV_LEN + WEP_ICV_LEN;
  655. break;
  656. }
  657. }
  658. bc_ent = cpu_to_le16((len & 0xFFF) | (sta_id << 12));
  659. scd_bc_tbl[txq_id].tfd_offset[write_ptr] = bc_ent;
  660. if (txq->q.write_ptr < TFD_QUEUE_SIZE_BC_DUP)
  661. scd_bc_tbl[txq_id].
  662. tfd_offset[TFD_QUEUE_SIZE_MAX + write_ptr] = bc_ent;
  663. }
  664. void iwl5000_txq_inval_byte_cnt_tbl(struct iwl_priv *priv,
  665. struct iwl_tx_queue *txq)
  666. {
  667. struct iwl5000_scd_bc_tbl *scd_bc_tbl = priv->scd_bc_tbls.addr;
  668. int txq_id = txq->q.id;
  669. int read_ptr = txq->q.read_ptr;
  670. u8 sta_id = 0;
  671. __le16 bc_ent;
  672. WARN_ON(read_ptr >= TFD_QUEUE_SIZE_MAX);
  673. if (txq_id != IWL_CMD_QUEUE_NUM)
  674. sta_id = txq->cmd[read_ptr]->cmd.tx.sta_id;
  675. bc_ent = cpu_to_le16(1 | (sta_id << 12));
  676. scd_bc_tbl[txq_id].tfd_offset[read_ptr] = bc_ent;
  677. if (txq->q.write_ptr < TFD_QUEUE_SIZE_BC_DUP)
  678. scd_bc_tbl[txq_id].
  679. tfd_offset[TFD_QUEUE_SIZE_MAX + read_ptr] = bc_ent;
  680. }
  681. static int iwl5000_tx_queue_set_q2ratid(struct iwl_priv *priv, u16 ra_tid,
  682. u16 txq_id)
  683. {
  684. u32 tbl_dw_addr;
  685. u32 tbl_dw;
  686. u16 scd_q2ratid;
  687. scd_q2ratid = ra_tid & IWL_SCD_QUEUE_RA_TID_MAP_RATID_MSK;
  688. tbl_dw_addr = priv->scd_base_addr +
  689. IWL50_SCD_TRANSLATE_TBL_OFFSET_QUEUE(txq_id);
  690. tbl_dw = iwl_read_targ_mem(priv, tbl_dw_addr);
  691. if (txq_id & 0x1)
  692. tbl_dw = (scd_q2ratid << 16) | (tbl_dw & 0x0000FFFF);
  693. else
  694. tbl_dw = scd_q2ratid | (tbl_dw & 0xFFFF0000);
  695. iwl_write_targ_mem(priv, tbl_dw_addr, tbl_dw);
  696. return 0;
  697. }
  698. static void iwl5000_tx_queue_stop_scheduler(struct iwl_priv *priv, u16 txq_id)
  699. {
  700. /* Simply stop the queue, but don't change any configuration;
  701. * the SCD_ACT_EN bit is the write-enable mask for the ACTIVE bit. */
  702. iwl_write_prph(priv,
  703. IWL50_SCD_QUEUE_STATUS_BITS(txq_id),
  704. (0 << IWL50_SCD_QUEUE_STTS_REG_POS_ACTIVE)|
  705. (1 << IWL50_SCD_QUEUE_STTS_REG_POS_SCD_ACT_EN));
  706. }
  707. int iwl5000_txq_agg_enable(struct iwl_priv *priv, int txq_id,
  708. int tx_fifo, int sta_id, int tid, u16 ssn_idx)
  709. {
  710. unsigned long flags;
  711. u16 ra_tid;
  712. if ((IWL50_FIRST_AMPDU_QUEUE > txq_id) ||
  713. (IWL50_FIRST_AMPDU_QUEUE + priv->cfg->num_of_ampdu_queues
  714. <= txq_id)) {
  715. IWL_WARN(priv,
  716. "queue number out of range: %d, must be %d to %d\n",
  717. txq_id, IWL50_FIRST_AMPDU_QUEUE,
  718. IWL50_FIRST_AMPDU_QUEUE +
  719. priv->cfg->num_of_ampdu_queues - 1);
  720. return -EINVAL;
  721. }
  722. ra_tid = BUILD_RAxTID(sta_id, tid);
  723. /* Modify device's station table to Tx this TID */
  724. iwl_sta_tx_modify_enable_tid(priv, sta_id, tid);
  725. spin_lock_irqsave(&priv->lock, flags);
  726. /* Stop this Tx queue before configuring it */
  727. iwl5000_tx_queue_stop_scheduler(priv, txq_id);
  728. /* Map receiver-address / traffic-ID to this queue */
  729. iwl5000_tx_queue_set_q2ratid(priv, ra_tid, txq_id);
  730. /* Set this queue as a chain-building queue */
  731. iwl_set_bits_prph(priv, IWL50_SCD_QUEUECHAIN_SEL, (1<<txq_id));
  732. /* enable aggregations for the queue */
  733. iwl_set_bits_prph(priv, IWL50_SCD_AGGR_SEL, (1<<txq_id));
  734. /* Place first TFD at index corresponding to start sequence number.
  735. * Assumes that ssn_idx is valid (!= 0xFFF) */
  736. priv->txq[txq_id].q.read_ptr = (ssn_idx & 0xff);
  737. priv->txq[txq_id].q.write_ptr = (ssn_idx & 0xff);
  738. iwl5000_set_wr_ptrs(priv, txq_id, ssn_idx);
  739. /* Set up Tx window size and frame limit for this queue */
  740. iwl_write_targ_mem(priv, priv->scd_base_addr +
  741. IWL50_SCD_CONTEXT_QUEUE_OFFSET(txq_id) +
  742. sizeof(u32),
  743. ((SCD_WIN_SIZE <<
  744. IWL50_SCD_QUEUE_CTX_REG2_WIN_SIZE_POS) &
  745. IWL50_SCD_QUEUE_CTX_REG2_WIN_SIZE_MSK) |
  746. ((SCD_FRAME_LIMIT <<
  747. IWL50_SCD_QUEUE_CTX_REG2_FRAME_LIMIT_POS) &
  748. IWL50_SCD_QUEUE_CTX_REG2_FRAME_LIMIT_MSK));
  749. iwl_set_bits_prph(priv, IWL50_SCD_INTERRUPT_MASK, (1 << txq_id));
  750. /* Set up Status area in SRAM, map to Tx DMA/FIFO, activate the queue */
  751. iwl5000_tx_queue_set_status(priv, &priv->txq[txq_id], tx_fifo, 1);
  752. spin_unlock_irqrestore(&priv->lock, flags);
  753. return 0;
  754. }
  755. int iwl5000_txq_agg_disable(struct iwl_priv *priv, u16 txq_id,
  756. u16 ssn_idx, u8 tx_fifo)
  757. {
  758. if ((IWL50_FIRST_AMPDU_QUEUE > txq_id) ||
  759. (IWL50_FIRST_AMPDU_QUEUE + priv->cfg->num_of_ampdu_queues
  760. <= txq_id)) {
  761. IWL_ERR(priv,
  762. "queue number out of range: %d, must be %d to %d\n",
  763. txq_id, IWL50_FIRST_AMPDU_QUEUE,
  764. IWL50_FIRST_AMPDU_QUEUE +
  765. priv->cfg->num_of_ampdu_queues - 1);
  766. return -EINVAL;
  767. }
  768. iwl5000_tx_queue_stop_scheduler(priv, txq_id);
  769. iwl_clear_bits_prph(priv, IWL50_SCD_AGGR_SEL, (1 << txq_id));
  770. priv->txq[txq_id].q.read_ptr = (ssn_idx & 0xff);
  771. priv->txq[txq_id].q.write_ptr = (ssn_idx & 0xff);
  772. /* supposes that ssn_idx is valid (!= 0xFFF) */
  773. iwl5000_set_wr_ptrs(priv, txq_id, ssn_idx);
  774. iwl_clear_bits_prph(priv, IWL50_SCD_INTERRUPT_MASK, (1 << txq_id));
  775. iwl_txq_ctx_deactivate(priv, txq_id);
  776. iwl5000_tx_queue_set_status(priv, &priv->txq[txq_id], tx_fifo, 0);
  777. return 0;
  778. }
  779. u16 iwl5000_build_addsta_hcmd(const struct iwl_addsta_cmd *cmd, u8 *data)
  780. {
  781. u16 size = (u16)sizeof(struct iwl_addsta_cmd);
  782. struct iwl_addsta_cmd *addsta = (struct iwl_addsta_cmd *)data;
  783. memcpy(addsta, cmd, size);
  784. /* resrved in 5000 */
  785. addsta->rate_n_flags = cpu_to_le16(0);
  786. return size;
  787. }
  788. /*
  789. * Activate/Deactivate Tx DMA/FIFO channels according tx fifos mask
  790. * must be called under priv->lock and mac access
  791. */
  792. void iwl5000_txq_set_sched(struct iwl_priv *priv, u32 mask)
  793. {
  794. iwl_write_prph(priv, IWL50_SCD_TXFACT, mask);
  795. }
  796. static inline u32 iwl5000_get_scd_ssn(struct iwl5000_tx_resp *tx_resp)
  797. {
  798. return le32_to_cpup((__le32 *)&tx_resp->status +
  799. tx_resp->frame_count) & MAX_SN;
  800. }
  801. static int iwl5000_tx_status_reply_tx(struct iwl_priv *priv,
  802. struct iwl_ht_agg *agg,
  803. struct iwl5000_tx_resp *tx_resp,
  804. int txq_id, u16 start_idx)
  805. {
  806. u16 status;
  807. struct agg_tx_status *frame_status = &tx_resp->status;
  808. struct ieee80211_tx_info *info = NULL;
  809. struct ieee80211_hdr *hdr = NULL;
  810. u32 rate_n_flags = le32_to_cpu(tx_resp->rate_n_flags);
  811. int i, sh, idx;
  812. u16 seq;
  813. if (agg->wait_for_ba)
  814. IWL_DEBUG_TX_REPLY(priv, "got tx response w/o block-ack\n");
  815. agg->frame_count = tx_resp->frame_count;
  816. agg->start_idx = start_idx;
  817. agg->rate_n_flags = rate_n_flags;
  818. agg->bitmap = 0;
  819. /* # frames attempted by Tx command */
  820. if (agg->frame_count == 1) {
  821. /* Only one frame was attempted; no block-ack will arrive */
  822. status = le16_to_cpu(frame_status[0].status);
  823. idx = start_idx;
  824. /* FIXME: code repetition */
  825. IWL_DEBUG_TX_REPLY(priv, "FrameCnt = %d, StartIdx=%d idx=%d\n",
  826. agg->frame_count, agg->start_idx, idx);
  827. info = IEEE80211_SKB_CB(priv->txq[txq_id].txb[idx].skb[0]);
  828. info->status.rates[0].count = tx_resp->failure_frame + 1;
  829. info->flags &= ~IEEE80211_TX_CTL_AMPDU;
  830. info->flags |= iwl_tx_status_to_mac80211(status);
  831. iwl_hwrate_to_tx_control(priv, rate_n_flags, info);
  832. /* FIXME: code repetition end */
  833. IWL_DEBUG_TX_REPLY(priv, "1 Frame 0x%x failure :%d\n",
  834. status & 0xff, tx_resp->failure_frame);
  835. IWL_DEBUG_TX_REPLY(priv, "Rate Info rate_n_flags=%x\n", rate_n_flags);
  836. agg->wait_for_ba = 0;
  837. } else {
  838. /* Two or more frames were attempted; expect block-ack */
  839. u64 bitmap = 0;
  840. int start = agg->start_idx;
  841. /* Construct bit-map of pending frames within Tx window */
  842. for (i = 0; i < agg->frame_count; i++) {
  843. u16 sc;
  844. status = le16_to_cpu(frame_status[i].status);
  845. seq = le16_to_cpu(frame_status[i].sequence);
  846. idx = SEQ_TO_INDEX(seq);
  847. txq_id = SEQ_TO_QUEUE(seq);
  848. if (status & (AGG_TX_STATE_FEW_BYTES_MSK |
  849. AGG_TX_STATE_ABORT_MSK))
  850. continue;
  851. IWL_DEBUG_TX_REPLY(priv, "FrameCnt = %d, txq_id=%d idx=%d\n",
  852. agg->frame_count, txq_id, idx);
  853. hdr = iwl_tx_queue_get_hdr(priv, txq_id, idx);
  854. if (!hdr) {
  855. IWL_ERR(priv,
  856. "BUG_ON idx doesn't point to valid skb"
  857. " idx=%d, txq_id=%d\n", idx, txq_id);
  858. return -1;
  859. }
  860. sc = le16_to_cpu(hdr->seq_ctrl);
  861. if (idx != (SEQ_TO_SN(sc) & 0xff)) {
  862. IWL_ERR(priv,
  863. "BUG_ON idx doesn't match seq control"
  864. " idx=%d, seq_idx=%d, seq=%d\n",
  865. idx, SEQ_TO_SN(sc),
  866. hdr->seq_ctrl);
  867. return -1;
  868. }
  869. IWL_DEBUG_TX_REPLY(priv, "AGG Frame i=%d idx %d seq=%d\n",
  870. i, idx, SEQ_TO_SN(sc));
  871. sh = idx - start;
  872. if (sh > 64) {
  873. sh = (start - idx) + 0xff;
  874. bitmap = bitmap << sh;
  875. sh = 0;
  876. start = idx;
  877. } else if (sh < -64)
  878. sh = 0xff - (start - idx);
  879. else if (sh < 0) {
  880. sh = start - idx;
  881. start = idx;
  882. bitmap = bitmap << sh;
  883. sh = 0;
  884. }
  885. bitmap |= 1ULL << sh;
  886. IWL_DEBUG_TX_REPLY(priv, "start=%d bitmap=0x%llx\n",
  887. start, (unsigned long long)bitmap);
  888. }
  889. agg->bitmap = bitmap;
  890. agg->start_idx = start;
  891. IWL_DEBUG_TX_REPLY(priv, "Frames %d start_idx=%d bitmap=0x%llx\n",
  892. agg->frame_count, agg->start_idx,
  893. (unsigned long long)agg->bitmap);
  894. if (bitmap)
  895. agg->wait_for_ba = 1;
  896. }
  897. return 0;
  898. }
  899. static void iwl5000_rx_reply_tx(struct iwl_priv *priv,
  900. struct iwl_rx_mem_buffer *rxb)
  901. {
  902. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  903. u16 sequence = le16_to_cpu(pkt->hdr.sequence);
  904. int txq_id = SEQ_TO_QUEUE(sequence);
  905. int index = SEQ_TO_INDEX(sequence);
  906. struct iwl_tx_queue *txq = &priv->txq[txq_id];
  907. struct ieee80211_tx_info *info;
  908. struct iwl5000_tx_resp *tx_resp = (void *)&pkt->u.raw[0];
  909. u32 status = le16_to_cpu(tx_resp->status.status);
  910. int tid;
  911. int sta_id;
  912. int freed;
  913. if ((index >= txq->q.n_bd) || (iwl_queue_used(&txq->q, index) == 0)) {
  914. IWL_ERR(priv, "Read index for DMA queue txq_id (%d) index %d "
  915. "is out of range [0-%d] %d %d\n", txq_id,
  916. index, txq->q.n_bd, txq->q.write_ptr,
  917. txq->q.read_ptr);
  918. return;
  919. }
  920. info = IEEE80211_SKB_CB(txq->txb[txq->q.read_ptr].skb[0]);
  921. memset(&info->status, 0, sizeof(info->status));
  922. tid = (tx_resp->ra_tid & IWL50_TX_RES_TID_MSK) >> IWL50_TX_RES_TID_POS;
  923. sta_id = (tx_resp->ra_tid & IWL50_TX_RES_RA_MSK) >> IWL50_TX_RES_RA_POS;
  924. if (txq->sched_retry) {
  925. const u32 scd_ssn = iwl5000_get_scd_ssn(tx_resp);
  926. struct iwl_ht_agg *agg = NULL;
  927. agg = &priv->stations[sta_id].tid[tid].agg;
  928. iwl5000_tx_status_reply_tx(priv, agg, tx_resp, txq_id, index);
  929. /* check if BAR is needed */
  930. if ((tx_resp->frame_count == 1) && !iwl_is_tx_success(status))
  931. info->flags |= IEEE80211_TX_STAT_AMPDU_NO_BACK;
  932. if (txq->q.read_ptr != (scd_ssn & 0xff)) {
  933. index = iwl_queue_dec_wrap(scd_ssn & 0xff, txq->q.n_bd);
  934. IWL_DEBUG_TX_REPLY(priv, "Retry scheduler reclaim "
  935. "scd_ssn=%d idx=%d txq=%d swq=%d\n",
  936. scd_ssn , index, txq_id, txq->swq_id);
  937. freed = iwl_tx_queue_reclaim(priv, txq_id, index);
  938. priv->stations[sta_id].tid[tid].tfds_in_queue -= freed;
  939. if (priv->mac80211_registered &&
  940. (iwl_queue_space(&txq->q) > txq->q.low_mark) &&
  941. (agg->state != IWL_EMPTYING_HW_QUEUE_DELBA)) {
  942. if (agg->state == IWL_AGG_OFF)
  943. iwl_wake_queue(priv, txq_id);
  944. else
  945. iwl_wake_queue(priv, txq->swq_id);
  946. }
  947. }
  948. } else {
  949. BUG_ON(txq_id != txq->swq_id);
  950. info->status.rates[0].count = tx_resp->failure_frame + 1;
  951. info->flags |= iwl_tx_status_to_mac80211(status);
  952. iwl_hwrate_to_tx_control(priv,
  953. le32_to_cpu(tx_resp->rate_n_flags),
  954. info);
  955. IWL_DEBUG_TX_REPLY(priv, "TXQ %d status %s (0x%08x) rate_n_flags "
  956. "0x%x retries %d\n",
  957. txq_id,
  958. iwl_get_tx_fail_reason(status), status,
  959. le32_to_cpu(tx_resp->rate_n_flags),
  960. tx_resp->failure_frame);
  961. freed = iwl_tx_queue_reclaim(priv, txq_id, index);
  962. if (ieee80211_is_data_qos(tx_resp->frame_ctrl))
  963. priv->stations[sta_id].tid[tid].tfds_in_queue -= freed;
  964. if (priv->mac80211_registered &&
  965. (iwl_queue_space(&txq->q) > txq->q.low_mark))
  966. iwl_wake_queue(priv, txq_id);
  967. }
  968. if (ieee80211_is_data_qos(tx_resp->frame_ctrl))
  969. iwl_txq_check_empty(priv, sta_id, tid, txq_id);
  970. if (iwl_check_bits(status, TX_ABORT_REQUIRED_MSK))
  971. IWL_ERR(priv, "TODO: Implement Tx ABORT REQUIRED!!!\n");
  972. }
  973. /* Currently 5000 is the superset of everything */
  974. u16 iwl5000_get_hcmd_size(u8 cmd_id, u16 len)
  975. {
  976. return len;
  977. }
  978. void iwl5000_setup_deferred_work(struct iwl_priv *priv)
  979. {
  980. /* in 5000 the tx power calibration is done in uCode */
  981. priv->disable_tx_power_cal = 1;
  982. }
  983. void iwl5000_rx_handler_setup(struct iwl_priv *priv)
  984. {
  985. /* init calibration handlers */
  986. priv->rx_handlers[CALIBRATION_RES_NOTIFICATION] =
  987. iwl5000_rx_calib_result;
  988. priv->rx_handlers[CALIBRATION_COMPLETE_NOTIFICATION] =
  989. iwl5000_rx_calib_complete;
  990. priv->rx_handlers[REPLY_TX] = iwl5000_rx_reply_tx;
  991. }
  992. int iwl5000_hw_valid_rtc_data_addr(u32 addr)
  993. {
  994. return (addr >= IWL50_RTC_DATA_LOWER_BOUND) &&
  995. (addr < IWL50_RTC_DATA_UPPER_BOUND);
  996. }
  997. static int iwl5000_send_rxon_assoc(struct iwl_priv *priv)
  998. {
  999. int ret = 0;
  1000. struct iwl5000_rxon_assoc_cmd rxon_assoc;
  1001. const struct iwl_rxon_cmd *rxon1 = &priv->staging_rxon;
  1002. const struct iwl_rxon_cmd *rxon2 = &priv->active_rxon;
  1003. if ((rxon1->flags == rxon2->flags) &&
  1004. (rxon1->filter_flags == rxon2->filter_flags) &&
  1005. (rxon1->cck_basic_rates == rxon2->cck_basic_rates) &&
  1006. (rxon1->ofdm_ht_single_stream_basic_rates ==
  1007. rxon2->ofdm_ht_single_stream_basic_rates) &&
  1008. (rxon1->ofdm_ht_dual_stream_basic_rates ==
  1009. rxon2->ofdm_ht_dual_stream_basic_rates) &&
  1010. (rxon1->ofdm_ht_triple_stream_basic_rates ==
  1011. rxon2->ofdm_ht_triple_stream_basic_rates) &&
  1012. (rxon1->acquisition_data == rxon2->acquisition_data) &&
  1013. (rxon1->rx_chain == rxon2->rx_chain) &&
  1014. (rxon1->ofdm_basic_rates == rxon2->ofdm_basic_rates)) {
  1015. IWL_DEBUG_INFO(priv, "Using current RXON_ASSOC. Not resending.\n");
  1016. return 0;
  1017. }
  1018. rxon_assoc.flags = priv->staging_rxon.flags;
  1019. rxon_assoc.filter_flags = priv->staging_rxon.filter_flags;
  1020. rxon_assoc.ofdm_basic_rates = priv->staging_rxon.ofdm_basic_rates;
  1021. rxon_assoc.cck_basic_rates = priv->staging_rxon.cck_basic_rates;
  1022. rxon_assoc.reserved1 = 0;
  1023. rxon_assoc.reserved2 = 0;
  1024. rxon_assoc.reserved3 = 0;
  1025. rxon_assoc.ofdm_ht_single_stream_basic_rates =
  1026. priv->staging_rxon.ofdm_ht_single_stream_basic_rates;
  1027. rxon_assoc.ofdm_ht_dual_stream_basic_rates =
  1028. priv->staging_rxon.ofdm_ht_dual_stream_basic_rates;
  1029. rxon_assoc.rx_chain_select_flags = priv->staging_rxon.rx_chain;
  1030. rxon_assoc.ofdm_ht_triple_stream_basic_rates =
  1031. priv->staging_rxon.ofdm_ht_triple_stream_basic_rates;
  1032. rxon_assoc.acquisition_data = priv->staging_rxon.acquisition_data;
  1033. ret = iwl_send_cmd_pdu_async(priv, REPLY_RXON_ASSOC,
  1034. sizeof(rxon_assoc), &rxon_assoc, NULL);
  1035. if (ret)
  1036. return ret;
  1037. return ret;
  1038. }
  1039. int iwl5000_send_tx_power(struct iwl_priv *priv)
  1040. {
  1041. struct iwl5000_tx_power_dbm_cmd tx_power_cmd;
  1042. u8 tx_ant_cfg_cmd;
  1043. /* half dBm need to multiply */
  1044. tx_power_cmd.global_lmt = (s8)(2 * priv->tx_power_user_lmt);
  1045. if (priv->tx_power_lmt_in_half_dbm &&
  1046. priv->tx_power_lmt_in_half_dbm < tx_power_cmd.global_lmt) {
  1047. /*
  1048. * For the newer devices which using enhanced/extend tx power
  1049. * table in EEPROM, the format is in half dBm. driver need to
  1050. * convert to dBm format before report to mac80211.
  1051. * By doing so, there is a possibility of 1/2 dBm resolution
  1052. * lost. driver will perform "round-up" operation before
  1053. * reporting, but it will cause 1/2 dBm tx power over the
  1054. * regulatory limit. Perform the checking here, if the
  1055. * "tx_power_user_lmt" is higher than EEPROM value (in
  1056. * half-dBm format), lower the tx power based on EEPROM
  1057. */
  1058. tx_power_cmd.global_lmt = priv->tx_power_lmt_in_half_dbm;
  1059. }
  1060. tx_power_cmd.flags = IWL50_TX_POWER_NO_CLOSED;
  1061. tx_power_cmd.srv_chan_lmt = IWL50_TX_POWER_AUTO;
  1062. if (IWL_UCODE_API(priv->ucode_ver) == 1)
  1063. tx_ant_cfg_cmd = REPLY_TX_POWER_DBM_CMD_V1;
  1064. else
  1065. tx_ant_cfg_cmd = REPLY_TX_POWER_DBM_CMD;
  1066. return iwl_send_cmd_pdu_async(priv, tx_ant_cfg_cmd,
  1067. sizeof(tx_power_cmd), &tx_power_cmd,
  1068. NULL);
  1069. }
  1070. void iwl5000_temperature(struct iwl_priv *priv)
  1071. {
  1072. /* store temperature from statistics (in Celsius) */
  1073. priv->temperature = le32_to_cpu(priv->statistics.general.temperature);
  1074. iwl_tt_handler(priv);
  1075. }
  1076. static void iwl5150_temperature(struct iwl_priv *priv)
  1077. {
  1078. u32 vt = 0;
  1079. s32 offset = iwl_temp_calib_to_offset(priv);
  1080. vt = le32_to_cpu(priv->statistics.general.temperature);
  1081. vt = vt / IWL_5150_VOLTAGE_TO_TEMPERATURE_COEFF + offset;
  1082. /* now vt hold the temperature in Kelvin */
  1083. priv->temperature = KELVIN_TO_CELSIUS(vt);
  1084. iwl_tt_handler(priv);
  1085. }
  1086. /* Calc max signal level (dBm) among 3 possible receivers */
  1087. int iwl5000_calc_rssi(struct iwl_priv *priv,
  1088. struct iwl_rx_phy_res *rx_resp)
  1089. {
  1090. /* data from PHY/DSP regarding signal strength, etc.,
  1091. * contents are always there, not configurable by host
  1092. */
  1093. struct iwl5000_non_cfg_phy *ncphy =
  1094. (struct iwl5000_non_cfg_phy *)rx_resp->non_cfg_phy_buf;
  1095. u32 val, rssi_a, rssi_b, rssi_c, max_rssi;
  1096. u8 agc;
  1097. val = le32_to_cpu(ncphy->non_cfg_phy[IWL50_RX_RES_AGC_IDX]);
  1098. agc = (val & IWL50_OFDM_AGC_MSK) >> IWL50_OFDM_AGC_BIT_POS;
  1099. /* Find max rssi among 3 possible receivers.
  1100. * These values are measured by the digital signal processor (DSP).
  1101. * They should stay fairly constant even as the signal strength varies,
  1102. * if the radio's automatic gain control (AGC) is working right.
  1103. * AGC value (see below) will provide the "interesting" info.
  1104. */
  1105. val = le32_to_cpu(ncphy->non_cfg_phy[IWL50_RX_RES_RSSI_AB_IDX]);
  1106. rssi_a = (val & IWL50_OFDM_RSSI_A_MSK) >> IWL50_OFDM_RSSI_A_BIT_POS;
  1107. rssi_b = (val & IWL50_OFDM_RSSI_B_MSK) >> IWL50_OFDM_RSSI_B_BIT_POS;
  1108. val = le32_to_cpu(ncphy->non_cfg_phy[IWL50_RX_RES_RSSI_C_IDX]);
  1109. rssi_c = (val & IWL50_OFDM_RSSI_C_MSK) >> IWL50_OFDM_RSSI_C_BIT_POS;
  1110. max_rssi = max_t(u32, rssi_a, rssi_b);
  1111. max_rssi = max_t(u32, max_rssi, rssi_c);
  1112. IWL_DEBUG_STATS(priv, "Rssi In A %d B %d C %d Max %d AGC dB %d\n",
  1113. rssi_a, rssi_b, rssi_c, max_rssi, agc);
  1114. /* dBm = max_rssi dB - agc dB - constant.
  1115. * Higher AGC (higher radio gain) means lower signal. */
  1116. return max_rssi - agc - IWL49_RSSI_OFFSET;
  1117. }
  1118. static int iwl5000_send_tx_ant_config(struct iwl_priv *priv, u8 valid_tx_ant)
  1119. {
  1120. struct iwl_tx_ant_config_cmd tx_ant_cmd = {
  1121. .valid = cpu_to_le32(valid_tx_ant),
  1122. };
  1123. if (IWL_UCODE_API(priv->ucode_ver) > 1) {
  1124. IWL_DEBUG_HC(priv, "select valid tx ant: %u\n", valid_tx_ant);
  1125. return iwl_send_cmd_pdu(priv, TX_ANT_CONFIGURATION_CMD,
  1126. sizeof(struct iwl_tx_ant_config_cmd),
  1127. &tx_ant_cmd);
  1128. } else {
  1129. IWL_DEBUG_HC(priv, "TX_ANT_CONFIGURATION_CMD not supported\n");
  1130. return -EOPNOTSUPP;
  1131. }
  1132. }
  1133. #define IWL5000_UCODE_GET(item) \
  1134. static u32 iwl5000_ucode_get_##item(const struct iwl_ucode_header *ucode,\
  1135. u32 api_ver) \
  1136. { \
  1137. if (api_ver <= 2) \
  1138. return le32_to_cpu(ucode->u.v1.item); \
  1139. return le32_to_cpu(ucode->u.v2.item); \
  1140. }
  1141. static u32 iwl5000_ucode_get_header_size(u32 api_ver)
  1142. {
  1143. if (api_ver <= 2)
  1144. return UCODE_HEADER_SIZE(1);
  1145. return UCODE_HEADER_SIZE(2);
  1146. }
  1147. static u32 iwl5000_ucode_get_build(const struct iwl_ucode_header *ucode,
  1148. u32 api_ver)
  1149. {
  1150. if (api_ver <= 2)
  1151. return 0;
  1152. return le32_to_cpu(ucode->u.v2.build);
  1153. }
  1154. static u8 *iwl5000_ucode_get_data(const struct iwl_ucode_header *ucode,
  1155. u32 api_ver)
  1156. {
  1157. if (api_ver <= 2)
  1158. return (u8 *) ucode->u.v1.data;
  1159. return (u8 *) ucode->u.v2.data;
  1160. }
  1161. IWL5000_UCODE_GET(inst_size);
  1162. IWL5000_UCODE_GET(data_size);
  1163. IWL5000_UCODE_GET(init_size);
  1164. IWL5000_UCODE_GET(init_data_size);
  1165. IWL5000_UCODE_GET(boot_size);
  1166. static int iwl5000_hw_channel_switch(struct iwl_priv *priv, u16 channel)
  1167. {
  1168. struct iwl5000_channel_switch_cmd cmd;
  1169. const struct iwl_channel_info *ch_info;
  1170. struct iwl_host_cmd hcmd = {
  1171. .id = REPLY_CHANNEL_SWITCH,
  1172. .len = sizeof(cmd),
  1173. .flags = CMD_SIZE_HUGE,
  1174. .data = &cmd,
  1175. };
  1176. IWL_DEBUG_11H(priv, "channel switch from %d to %d\n",
  1177. priv->active_rxon.channel, channel);
  1178. cmd.band = priv->band == IEEE80211_BAND_2GHZ;
  1179. cmd.channel = cpu_to_le16(channel);
  1180. cmd.rxon_flags = priv->staging_rxon.flags;
  1181. cmd.rxon_filter_flags = priv->staging_rxon.filter_flags;
  1182. cmd.switch_time = cpu_to_le32(priv->ucode_beacon_time);
  1183. ch_info = iwl_get_channel_info(priv, priv->band, channel);
  1184. if (ch_info)
  1185. cmd.expect_beacon = is_channel_radar(ch_info);
  1186. else {
  1187. IWL_ERR(priv, "invalid channel switch from %u to %u\n",
  1188. priv->active_rxon.channel, channel);
  1189. return -EFAULT;
  1190. }
  1191. priv->switch_rxon.channel = cpu_to_le16(channel);
  1192. priv->switch_rxon.switch_in_progress = true;
  1193. return iwl_send_cmd_sync(priv, &hcmd);
  1194. }
  1195. struct iwl_hcmd_ops iwl5000_hcmd = {
  1196. .rxon_assoc = iwl5000_send_rxon_assoc,
  1197. .commit_rxon = iwl_commit_rxon,
  1198. .set_rxon_chain = iwl_set_rxon_chain,
  1199. .set_tx_ant = iwl5000_send_tx_ant_config,
  1200. };
  1201. struct iwl_hcmd_utils_ops iwl5000_hcmd_utils = {
  1202. .get_hcmd_size = iwl5000_get_hcmd_size,
  1203. .build_addsta_hcmd = iwl5000_build_addsta_hcmd,
  1204. .gain_computation = iwl5000_gain_computation,
  1205. .chain_noise_reset = iwl5000_chain_noise_reset,
  1206. .rts_tx_cmd_flag = iwl5000_rts_tx_cmd_flag,
  1207. .calc_rssi = iwl5000_calc_rssi,
  1208. };
  1209. struct iwl_ucode_ops iwl5000_ucode = {
  1210. .get_header_size = iwl5000_ucode_get_header_size,
  1211. .get_build = iwl5000_ucode_get_build,
  1212. .get_inst_size = iwl5000_ucode_get_inst_size,
  1213. .get_data_size = iwl5000_ucode_get_data_size,
  1214. .get_init_size = iwl5000_ucode_get_init_size,
  1215. .get_init_data_size = iwl5000_ucode_get_init_data_size,
  1216. .get_boot_size = iwl5000_ucode_get_boot_size,
  1217. .get_data = iwl5000_ucode_get_data,
  1218. };
  1219. struct iwl_lib_ops iwl5000_lib = {
  1220. .set_hw_params = iwl5000_hw_set_hw_params,
  1221. .txq_update_byte_cnt_tbl = iwl5000_txq_update_byte_cnt_tbl,
  1222. .txq_inval_byte_cnt_tbl = iwl5000_txq_inval_byte_cnt_tbl,
  1223. .txq_set_sched = iwl5000_txq_set_sched,
  1224. .txq_agg_enable = iwl5000_txq_agg_enable,
  1225. .txq_agg_disable = iwl5000_txq_agg_disable,
  1226. .txq_attach_buf_to_tfd = iwl_hw_txq_attach_buf_to_tfd,
  1227. .txq_free_tfd = iwl_hw_txq_free_tfd,
  1228. .txq_init = iwl_hw_tx_queue_init,
  1229. .rx_handler_setup = iwl5000_rx_handler_setup,
  1230. .setup_deferred_work = iwl5000_setup_deferred_work,
  1231. .is_valid_rtc_data_addr = iwl5000_hw_valid_rtc_data_addr,
  1232. .dump_nic_event_log = iwl_dump_nic_event_log,
  1233. .dump_nic_error_log = iwl_dump_nic_error_log,
  1234. .load_ucode = iwl5000_load_ucode,
  1235. .init_alive_start = iwl5000_init_alive_start,
  1236. .alive_notify = iwl5000_alive_notify,
  1237. .send_tx_power = iwl5000_send_tx_power,
  1238. .update_chain_flags = iwl_update_chain_flags,
  1239. .set_channel_switch = iwl5000_hw_channel_switch,
  1240. .apm_ops = {
  1241. .init = iwl_apm_init,
  1242. .stop = iwl_apm_stop,
  1243. .config = iwl5000_nic_config,
  1244. .set_pwr_src = iwl_set_pwr_src,
  1245. },
  1246. .eeprom_ops = {
  1247. .regulatory_bands = {
  1248. EEPROM_5000_REG_BAND_1_CHANNELS,
  1249. EEPROM_5000_REG_BAND_2_CHANNELS,
  1250. EEPROM_5000_REG_BAND_3_CHANNELS,
  1251. EEPROM_5000_REG_BAND_4_CHANNELS,
  1252. EEPROM_5000_REG_BAND_5_CHANNELS,
  1253. EEPROM_5000_REG_BAND_24_HT40_CHANNELS,
  1254. EEPROM_5000_REG_BAND_52_HT40_CHANNELS
  1255. },
  1256. .verify_signature = iwlcore_eeprom_verify_signature,
  1257. .acquire_semaphore = iwlcore_eeprom_acquire_semaphore,
  1258. .release_semaphore = iwlcore_eeprom_release_semaphore,
  1259. .calib_version = iwl5000_eeprom_calib_version,
  1260. .query_addr = iwl5000_eeprom_query_addr,
  1261. },
  1262. .post_associate = iwl_post_associate,
  1263. .isr = iwl_isr_ict,
  1264. .config_ap = iwl_config_ap,
  1265. .temp_ops = {
  1266. .temperature = iwl5000_temperature,
  1267. .set_ct_kill = iwl5000_set_ct_threshold,
  1268. },
  1269. };
  1270. static struct iwl_lib_ops iwl5150_lib = {
  1271. .set_hw_params = iwl5000_hw_set_hw_params,
  1272. .txq_update_byte_cnt_tbl = iwl5000_txq_update_byte_cnt_tbl,
  1273. .txq_inval_byte_cnt_tbl = iwl5000_txq_inval_byte_cnt_tbl,
  1274. .txq_set_sched = iwl5000_txq_set_sched,
  1275. .txq_agg_enable = iwl5000_txq_agg_enable,
  1276. .txq_agg_disable = iwl5000_txq_agg_disable,
  1277. .txq_attach_buf_to_tfd = iwl_hw_txq_attach_buf_to_tfd,
  1278. .txq_free_tfd = iwl_hw_txq_free_tfd,
  1279. .txq_init = iwl_hw_tx_queue_init,
  1280. .rx_handler_setup = iwl5000_rx_handler_setup,
  1281. .setup_deferred_work = iwl5000_setup_deferred_work,
  1282. .is_valid_rtc_data_addr = iwl5000_hw_valid_rtc_data_addr,
  1283. .dump_nic_event_log = iwl_dump_nic_event_log,
  1284. .dump_nic_error_log = iwl_dump_nic_error_log,
  1285. .load_ucode = iwl5000_load_ucode,
  1286. .init_alive_start = iwl5000_init_alive_start,
  1287. .alive_notify = iwl5000_alive_notify,
  1288. .send_tx_power = iwl5000_send_tx_power,
  1289. .update_chain_flags = iwl_update_chain_flags,
  1290. .set_channel_switch = iwl5000_hw_channel_switch,
  1291. .apm_ops = {
  1292. .init = iwl_apm_init,
  1293. .stop = iwl_apm_stop,
  1294. .config = iwl5000_nic_config,
  1295. .set_pwr_src = iwl_set_pwr_src,
  1296. },
  1297. .eeprom_ops = {
  1298. .regulatory_bands = {
  1299. EEPROM_5000_REG_BAND_1_CHANNELS,
  1300. EEPROM_5000_REG_BAND_2_CHANNELS,
  1301. EEPROM_5000_REG_BAND_3_CHANNELS,
  1302. EEPROM_5000_REG_BAND_4_CHANNELS,
  1303. EEPROM_5000_REG_BAND_5_CHANNELS,
  1304. EEPROM_5000_REG_BAND_24_HT40_CHANNELS,
  1305. EEPROM_5000_REG_BAND_52_HT40_CHANNELS
  1306. },
  1307. .verify_signature = iwlcore_eeprom_verify_signature,
  1308. .acquire_semaphore = iwlcore_eeprom_acquire_semaphore,
  1309. .release_semaphore = iwlcore_eeprom_release_semaphore,
  1310. .calib_version = iwl5000_eeprom_calib_version,
  1311. .query_addr = iwl5000_eeprom_query_addr,
  1312. },
  1313. .post_associate = iwl_post_associate,
  1314. .isr = iwl_isr_ict,
  1315. .config_ap = iwl_config_ap,
  1316. .temp_ops = {
  1317. .temperature = iwl5150_temperature,
  1318. .set_ct_kill = iwl5150_set_ct_threshold,
  1319. },
  1320. };
  1321. static struct iwl_ops iwl5000_ops = {
  1322. .ucode = &iwl5000_ucode,
  1323. .lib = &iwl5000_lib,
  1324. .hcmd = &iwl5000_hcmd,
  1325. .utils = &iwl5000_hcmd_utils,
  1326. .led = &iwlagn_led_ops,
  1327. };
  1328. static struct iwl_ops iwl5150_ops = {
  1329. .ucode = &iwl5000_ucode,
  1330. .lib = &iwl5150_lib,
  1331. .hcmd = &iwl5000_hcmd,
  1332. .utils = &iwl5000_hcmd_utils,
  1333. .led = &iwlagn_led_ops,
  1334. };
  1335. struct iwl_mod_params iwl50_mod_params = {
  1336. .amsdu_size_8K = 1,
  1337. .restart_fw = 1,
  1338. /* the rest are 0 by default */
  1339. };
  1340. struct iwl_cfg iwl5300_agn_cfg = {
  1341. .name = "5300AGN",
  1342. .fw_name_pre = IWL5000_FW_PRE,
  1343. .ucode_api_max = IWL5000_UCODE_API_MAX,
  1344. .ucode_api_min = IWL5000_UCODE_API_MIN,
  1345. .sku = IWL_SKU_A|IWL_SKU_G|IWL_SKU_N,
  1346. .ops = &iwl5000_ops,
  1347. .eeprom_size = IWL_5000_EEPROM_IMG_SIZE,
  1348. .eeprom_ver = EEPROM_5000_EEPROM_VERSION,
  1349. .eeprom_calib_ver = EEPROM_5000_TX_POWER_VERSION,
  1350. .num_of_queues = IWL50_NUM_QUEUES,
  1351. .num_of_ampdu_queues = IWL50_NUM_AMPDU_QUEUES,
  1352. .mod_params = &iwl50_mod_params,
  1353. .valid_tx_ant = ANT_ABC,
  1354. .valid_rx_ant = ANT_ABC,
  1355. .pll_cfg_val = CSR50_ANA_PLL_CFG_VAL,
  1356. .set_l0s = true,
  1357. .use_bsm = false,
  1358. .ht_greenfield_support = true,
  1359. .led_compensation = 51,
  1360. .chain_noise_num_beacons = IWL_CAL_NUM_BEACONS,
  1361. };
  1362. struct iwl_cfg iwl5100_bg_cfg = {
  1363. .name = "5100BG",
  1364. .fw_name_pre = IWL5000_FW_PRE,
  1365. .ucode_api_max = IWL5000_UCODE_API_MAX,
  1366. .ucode_api_min = IWL5000_UCODE_API_MIN,
  1367. .sku = IWL_SKU_G,
  1368. .ops = &iwl5000_ops,
  1369. .eeprom_size = IWL_5000_EEPROM_IMG_SIZE,
  1370. .eeprom_ver = EEPROM_5000_EEPROM_VERSION,
  1371. .eeprom_calib_ver = EEPROM_5000_TX_POWER_VERSION,
  1372. .num_of_queues = IWL50_NUM_QUEUES,
  1373. .num_of_ampdu_queues = IWL50_NUM_AMPDU_QUEUES,
  1374. .mod_params = &iwl50_mod_params,
  1375. .valid_tx_ant = ANT_B,
  1376. .valid_rx_ant = ANT_AB,
  1377. .pll_cfg_val = CSR50_ANA_PLL_CFG_VAL,
  1378. .set_l0s = true,
  1379. .use_bsm = false,
  1380. .ht_greenfield_support = true,
  1381. .led_compensation = 51,
  1382. .chain_noise_num_beacons = IWL_CAL_NUM_BEACONS,
  1383. };
  1384. struct iwl_cfg iwl5100_abg_cfg = {
  1385. .name = "5100ABG",
  1386. .fw_name_pre = IWL5000_FW_PRE,
  1387. .ucode_api_max = IWL5000_UCODE_API_MAX,
  1388. .ucode_api_min = IWL5000_UCODE_API_MIN,
  1389. .sku = IWL_SKU_A|IWL_SKU_G,
  1390. .ops = &iwl5000_ops,
  1391. .eeprom_size = IWL_5000_EEPROM_IMG_SIZE,
  1392. .eeprom_ver = EEPROM_5000_EEPROM_VERSION,
  1393. .eeprom_calib_ver = EEPROM_5000_TX_POWER_VERSION,
  1394. .num_of_queues = IWL50_NUM_QUEUES,
  1395. .num_of_ampdu_queues = IWL50_NUM_AMPDU_QUEUES,
  1396. .mod_params = &iwl50_mod_params,
  1397. .valid_tx_ant = ANT_B,
  1398. .valid_rx_ant = ANT_AB,
  1399. .pll_cfg_val = CSR50_ANA_PLL_CFG_VAL,
  1400. .set_l0s = true,
  1401. .use_bsm = false,
  1402. .ht_greenfield_support = true,
  1403. .led_compensation = 51,
  1404. .chain_noise_num_beacons = IWL_CAL_NUM_BEACONS,
  1405. };
  1406. struct iwl_cfg iwl5100_agn_cfg = {
  1407. .name = "5100AGN",
  1408. .fw_name_pre = IWL5000_FW_PRE,
  1409. .ucode_api_max = IWL5000_UCODE_API_MAX,
  1410. .ucode_api_min = IWL5000_UCODE_API_MIN,
  1411. .sku = IWL_SKU_A|IWL_SKU_G|IWL_SKU_N,
  1412. .ops = &iwl5000_ops,
  1413. .eeprom_size = IWL_5000_EEPROM_IMG_SIZE,
  1414. .eeprom_ver = EEPROM_5000_EEPROM_VERSION,
  1415. .eeprom_calib_ver = EEPROM_5000_TX_POWER_VERSION,
  1416. .num_of_queues = IWL50_NUM_QUEUES,
  1417. .num_of_ampdu_queues = IWL50_NUM_AMPDU_QUEUES,
  1418. .mod_params = &iwl50_mod_params,
  1419. .valid_tx_ant = ANT_B,
  1420. .valid_rx_ant = ANT_AB,
  1421. .pll_cfg_val = CSR50_ANA_PLL_CFG_VAL,
  1422. .set_l0s = true,
  1423. .use_bsm = false,
  1424. .ht_greenfield_support = true,
  1425. .led_compensation = 51,
  1426. .chain_noise_num_beacons = IWL_CAL_NUM_BEACONS,
  1427. };
  1428. struct iwl_cfg iwl5350_agn_cfg = {
  1429. .name = "5350AGN",
  1430. .fw_name_pre = IWL5000_FW_PRE,
  1431. .ucode_api_max = IWL5000_UCODE_API_MAX,
  1432. .ucode_api_min = IWL5000_UCODE_API_MIN,
  1433. .sku = IWL_SKU_A|IWL_SKU_G|IWL_SKU_N,
  1434. .ops = &iwl5000_ops,
  1435. .eeprom_size = IWL_5000_EEPROM_IMG_SIZE,
  1436. .eeprom_ver = EEPROM_5050_EEPROM_VERSION,
  1437. .eeprom_calib_ver = EEPROM_5050_TX_POWER_VERSION,
  1438. .num_of_queues = IWL50_NUM_QUEUES,
  1439. .num_of_ampdu_queues = IWL50_NUM_AMPDU_QUEUES,
  1440. .mod_params = &iwl50_mod_params,
  1441. .valid_tx_ant = ANT_ABC,
  1442. .valid_rx_ant = ANT_ABC,
  1443. .pll_cfg_val = CSR50_ANA_PLL_CFG_VAL,
  1444. .set_l0s = true,
  1445. .use_bsm = false,
  1446. .ht_greenfield_support = true,
  1447. .led_compensation = 51,
  1448. .chain_noise_num_beacons = IWL_CAL_NUM_BEACONS,
  1449. };
  1450. struct iwl_cfg iwl5150_agn_cfg = {
  1451. .name = "5150AGN",
  1452. .fw_name_pre = IWL5150_FW_PRE,
  1453. .ucode_api_max = IWL5150_UCODE_API_MAX,
  1454. .ucode_api_min = IWL5150_UCODE_API_MIN,
  1455. .sku = IWL_SKU_A|IWL_SKU_G|IWL_SKU_N,
  1456. .ops = &iwl5150_ops,
  1457. .eeprom_size = IWL_5000_EEPROM_IMG_SIZE,
  1458. .eeprom_ver = EEPROM_5050_EEPROM_VERSION,
  1459. .eeprom_calib_ver = EEPROM_5050_TX_POWER_VERSION,
  1460. .num_of_queues = IWL50_NUM_QUEUES,
  1461. .num_of_ampdu_queues = IWL50_NUM_AMPDU_QUEUES,
  1462. .mod_params = &iwl50_mod_params,
  1463. .valid_tx_ant = ANT_A,
  1464. .valid_rx_ant = ANT_AB,
  1465. .pll_cfg_val = CSR50_ANA_PLL_CFG_VAL,
  1466. .set_l0s = true,
  1467. .use_bsm = false,
  1468. .ht_greenfield_support = true,
  1469. .led_compensation = 51,
  1470. .chain_noise_num_beacons = IWL_CAL_NUM_BEACONS,
  1471. };
  1472. MODULE_FIRMWARE(IWL5000_MODULE_FIRMWARE(IWL5000_UCODE_API_MAX));
  1473. MODULE_FIRMWARE(IWL5150_MODULE_FIRMWARE(IWL5150_UCODE_API_MAX));
  1474. module_param_named(swcrypto50, iwl50_mod_params.sw_crypto, bool, S_IRUGO);
  1475. MODULE_PARM_DESC(swcrypto50,
  1476. "using software crypto engine (default 0 [hardware])\n");
  1477. module_param_named(queues_num50, iwl50_mod_params.num_of_queues, int, S_IRUGO);
  1478. MODULE_PARM_DESC(queues_num50, "number of hw queues in 50xx series");
  1479. module_param_named(11n_disable50, iwl50_mod_params.disable_11n, int, S_IRUGO);
  1480. MODULE_PARM_DESC(11n_disable50, "disable 50XX 11n functionality");
  1481. module_param_named(amsdu_size_8K50, iwl50_mod_params.amsdu_size_8K,
  1482. int, S_IRUGO);
  1483. MODULE_PARM_DESC(amsdu_size_8K50, "enable 8K amsdu size in 50XX series");
  1484. module_param_named(fw_restart50, iwl50_mod_params.restart_fw, int, S_IRUGO);
  1485. MODULE_PARM_DESC(fw_restart50, "restart firmware in case of error");