iwl-5000.c 53 KB

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