iwl-core.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840
  1. /******************************************************************************
  2. *
  3. * GPL LICENSE SUMMARY
  4. *
  5. * Copyright(c) 2008 Intel Corporation. All rights reserved.
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of version 2 of the GNU General Public License as
  9. * published by the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
  19. * USA
  20. *
  21. * The full GNU General Public License is included in this distribution
  22. * in the file called LICENSE.GPL.
  23. *
  24. * Contact Information:
  25. * Tomas Winkler <tomas.winkler@intel.com>
  26. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  27. *****************************************************************************/
  28. #include <linux/kernel.h>
  29. #include <linux/module.h>
  30. #include <linux/version.h>
  31. #include <net/mac80211.h>
  32. struct iwl_priv; /* FIXME: remove */
  33. #include "iwl-debug.h"
  34. #include "iwl-eeprom.h"
  35. #include "iwl-dev.h" /* FIXME: remove */
  36. #include "iwl-core.h"
  37. #include "iwl-io.h"
  38. #include "iwl-rfkill.h"
  39. #include "iwl-power.h"
  40. MODULE_DESCRIPTION("iwl core");
  41. MODULE_VERSION(IWLWIFI_VERSION);
  42. MODULE_AUTHOR(DRV_COPYRIGHT);
  43. MODULE_LICENSE("GPL");
  44. #ifdef CONFIG_IWLWIFI_DEBUG
  45. u32 iwl_debug_level;
  46. EXPORT_SYMBOL(iwl_debug_level);
  47. #endif
  48. #define IWL_DECLARE_RATE_INFO(r, s, ip, in, rp, rn, pp, np) \
  49. [IWL_RATE_##r##M_INDEX] = { IWL_RATE_##r##M_PLCP, \
  50. IWL_RATE_SISO_##s##M_PLCP, \
  51. IWL_RATE_MIMO2_##s##M_PLCP,\
  52. IWL_RATE_MIMO3_##s##M_PLCP,\
  53. IWL_RATE_##r##M_IEEE, \
  54. IWL_RATE_##ip##M_INDEX, \
  55. IWL_RATE_##in##M_INDEX, \
  56. IWL_RATE_##rp##M_INDEX, \
  57. IWL_RATE_##rn##M_INDEX, \
  58. IWL_RATE_##pp##M_INDEX, \
  59. IWL_RATE_##np##M_INDEX }
  60. /*
  61. * Parameter order:
  62. * rate, ht rate, prev rate, next rate, prev tgg rate, next tgg rate
  63. *
  64. * If there isn't a valid next or previous rate then INV is used which
  65. * maps to IWL_RATE_INVALID
  66. *
  67. */
  68. const struct iwl4965_rate_info iwl4965_rates[IWL_RATE_COUNT] = {
  69. IWL_DECLARE_RATE_INFO(1, INV, INV, 2, INV, 2, INV, 2), /* 1mbps */
  70. IWL_DECLARE_RATE_INFO(2, INV, 1, 5, 1, 5, 1, 5), /* 2mbps */
  71. IWL_DECLARE_RATE_INFO(5, INV, 2, 6, 2, 11, 2, 11), /*5.5mbps */
  72. IWL_DECLARE_RATE_INFO(11, INV, 9, 12, 9, 12, 5, 18), /* 11mbps */
  73. IWL_DECLARE_RATE_INFO(6, 6, 5, 9, 5, 11, 5, 11), /* 6mbps */
  74. IWL_DECLARE_RATE_INFO(9, 6, 6, 11, 6, 11, 5, 11), /* 9mbps */
  75. IWL_DECLARE_RATE_INFO(12, 12, 11, 18, 11, 18, 11, 18), /* 12mbps */
  76. IWL_DECLARE_RATE_INFO(18, 18, 12, 24, 12, 24, 11, 24), /* 18mbps */
  77. IWL_DECLARE_RATE_INFO(24, 24, 18, 36, 18, 36, 18, 36), /* 24mbps */
  78. IWL_DECLARE_RATE_INFO(36, 36, 24, 48, 24, 48, 24, 48), /* 36mbps */
  79. IWL_DECLARE_RATE_INFO(48, 48, 36, 54, 36, 54, 36, 54), /* 48mbps */
  80. IWL_DECLARE_RATE_INFO(54, 54, 48, INV, 48, INV, 48, INV),/* 54mbps */
  81. IWL_DECLARE_RATE_INFO(60, 60, 48, INV, 48, INV, 48, INV),/* 60mbps */
  82. /* FIXME:RS: ^^ should be INV (legacy) */
  83. };
  84. EXPORT_SYMBOL(iwl4965_rates);
  85. /* This function both allocates and initializes hw and priv. */
  86. struct ieee80211_hw *iwl_alloc_all(struct iwl_cfg *cfg,
  87. struct ieee80211_ops *hw_ops)
  88. {
  89. struct iwl_priv *priv;
  90. /* mac80211 allocates memory for this device instance, including
  91. * space for this driver's private structure */
  92. struct ieee80211_hw *hw =
  93. ieee80211_alloc_hw(sizeof(struct iwl_priv), hw_ops);
  94. if (hw == NULL) {
  95. IWL_ERROR("Can not allocate network device\n");
  96. goto out;
  97. }
  98. priv = hw->priv;
  99. priv->hw = hw;
  100. out:
  101. return hw;
  102. }
  103. EXPORT_SYMBOL(iwl_alloc_all);
  104. void iwl_hw_detect(struct iwl_priv *priv)
  105. {
  106. priv->hw_rev = _iwl_read32(priv, CSR_HW_REV);
  107. priv->hw_wa_rev = _iwl_read32(priv, CSR_HW_REV_WA_REG);
  108. pci_read_config_byte(priv->pci_dev, PCI_REVISION_ID, &priv->rev_id);
  109. }
  110. EXPORT_SYMBOL(iwl_hw_detect);
  111. /**
  112. * iwlcore_clear_stations_table - Clear the driver's station table
  113. *
  114. * NOTE: This does not clear or otherwise alter the device's station table.
  115. */
  116. void iwlcore_clear_stations_table(struct iwl_priv *priv)
  117. {
  118. unsigned long flags;
  119. spin_lock_irqsave(&priv->sta_lock, flags);
  120. priv->num_stations = 0;
  121. memset(priv->stations, 0, sizeof(priv->stations));
  122. spin_unlock_irqrestore(&priv->sta_lock, flags);
  123. }
  124. EXPORT_SYMBOL(iwlcore_clear_stations_table);
  125. void iwl_reset_qos(struct iwl_priv *priv)
  126. {
  127. u16 cw_min = 15;
  128. u16 cw_max = 1023;
  129. u8 aifs = 2;
  130. u8 is_legacy = 0;
  131. unsigned long flags;
  132. int i;
  133. spin_lock_irqsave(&priv->lock, flags);
  134. priv->qos_data.qos_active = 0;
  135. if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS) {
  136. if (priv->qos_data.qos_enable)
  137. priv->qos_data.qos_active = 1;
  138. if (!(priv->active_rate & 0xfff0)) {
  139. cw_min = 31;
  140. is_legacy = 1;
  141. }
  142. } else if (priv->iw_mode == IEEE80211_IF_TYPE_AP) {
  143. if (priv->qos_data.qos_enable)
  144. priv->qos_data.qos_active = 1;
  145. } else if (!(priv->staging_rxon.flags & RXON_FLG_SHORT_SLOT_MSK)) {
  146. cw_min = 31;
  147. is_legacy = 1;
  148. }
  149. if (priv->qos_data.qos_active)
  150. aifs = 3;
  151. priv->qos_data.def_qos_parm.ac[0].cw_min = cpu_to_le16(cw_min);
  152. priv->qos_data.def_qos_parm.ac[0].cw_max = cpu_to_le16(cw_max);
  153. priv->qos_data.def_qos_parm.ac[0].aifsn = aifs;
  154. priv->qos_data.def_qos_parm.ac[0].edca_txop = 0;
  155. priv->qos_data.def_qos_parm.ac[0].reserved1 = 0;
  156. if (priv->qos_data.qos_active) {
  157. i = 1;
  158. priv->qos_data.def_qos_parm.ac[i].cw_min = cpu_to_le16(cw_min);
  159. priv->qos_data.def_qos_parm.ac[i].cw_max = cpu_to_le16(cw_max);
  160. priv->qos_data.def_qos_parm.ac[i].aifsn = 7;
  161. priv->qos_data.def_qos_parm.ac[i].edca_txop = 0;
  162. priv->qos_data.def_qos_parm.ac[i].reserved1 = 0;
  163. i = 2;
  164. priv->qos_data.def_qos_parm.ac[i].cw_min =
  165. cpu_to_le16((cw_min + 1) / 2 - 1);
  166. priv->qos_data.def_qos_parm.ac[i].cw_max =
  167. cpu_to_le16(cw_max);
  168. priv->qos_data.def_qos_parm.ac[i].aifsn = 2;
  169. if (is_legacy)
  170. priv->qos_data.def_qos_parm.ac[i].edca_txop =
  171. cpu_to_le16(6016);
  172. else
  173. priv->qos_data.def_qos_parm.ac[i].edca_txop =
  174. cpu_to_le16(3008);
  175. priv->qos_data.def_qos_parm.ac[i].reserved1 = 0;
  176. i = 3;
  177. priv->qos_data.def_qos_parm.ac[i].cw_min =
  178. cpu_to_le16((cw_min + 1) / 4 - 1);
  179. priv->qos_data.def_qos_parm.ac[i].cw_max =
  180. cpu_to_le16((cw_max + 1) / 2 - 1);
  181. priv->qos_data.def_qos_parm.ac[i].aifsn = 2;
  182. priv->qos_data.def_qos_parm.ac[i].reserved1 = 0;
  183. if (is_legacy)
  184. priv->qos_data.def_qos_parm.ac[i].edca_txop =
  185. cpu_to_le16(3264);
  186. else
  187. priv->qos_data.def_qos_parm.ac[i].edca_txop =
  188. cpu_to_le16(1504);
  189. } else {
  190. for (i = 1; i < 4; i++) {
  191. priv->qos_data.def_qos_parm.ac[i].cw_min =
  192. cpu_to_le16(cw_min);
  193. priv->qos_data.def_qos_parm.ac[i].cw_max =
  194. cpu_to_le16(cw_max);
  195. priv->qos_data.def_qos_parm.ac[i].aifsn = aifs;
  196. priv->qos_data.def_qos_parm.ac[i].edca_txop = 0;
  197. priv->qos_data.def_qos_parm.ac[i].reserved1 = 0;
  198. }
  199. }
  200. IWL_DEBUG_QOS("set QoS to default \n");
  201. spin_unlock_irqrestore(&priv->lock, flags);
  202. }
  203. EXPORT_SYMBOL(iwl_reset_qos);
  204. #ifdef CONFIG_IWL4965_HT
  205. static void iwlcore_init_ht_hw_capab(const struct iwl_priv *priv,
  206. struct ieee80211_ht_info *ht_info,
  207. enum ieee80211_band band)
  208. {
  209. ht_info->cap = 0;
  210. memset(ht_info->supp_mcs_set, 0, 16);
  211. ht_info->ht_supported = 1;
  212. if (priv->hw_params.fat_channel & BIT(band)) {
  213. ht_info->cap |= (u16)IEEE80211_HT_CAP_SUP_WIDTH;
  214. ht_info->cap |= (u16)IEEE80211_HT_CAP_SGI_40;
  215. ht_info->supp_mcs_set[4] = 0x01;
  216. }
  217. ht_info->cap |= (u16)IEEE80211_HT_CAP_GRN_FLD;
  218. ht_info->cap |= (u16)IEEE80211_HT_CAP_SGI_20;
  219. ht_info->cap |= (u16)(IEEE80211_HT_CAP_MIMO_PS &
  220. (IWL_MIMO_PS_NONE << 2));
  221. if (priv->cfg->mod_params->amsdu_size_8K)
  222. ht_info->cap |= (u16)IEEE80211_HT_CAP_MAX_AMSDU;
  223. ht_info->ampdu_factor = CFG_HT_RX_AMPDU_FACTOR_DEF;
  224. ht_info->ampdu_density = CFG_HT_MPDU_DENSITY_DEF;
  225. ht_info->supp_mcs_set[0] = 0xFF;
  226. if (priv->hw_params.tx_chains_num >= 2)
  227. ht_info->supp_mcs_set[1] = 0xFF;
  228. if (priv->hw_params.tx_chains_num >= 3)
  229. ht_info->supp_mcs_set[2] = 0xFF;
  230. }
  231. #endif /* CONFIG_IWL4965_HT */
  232. static void iwlcore_init_hw_rates(struct iwl_priv *priv,
  233. struct ieee80211_rate *rates)
  234. {
  235. int i;
  236. for (i = 0; i < IWL_RATE_COUNT; i++) {
  237. rates[i].bitrate = iwl4965_rates[i].ieee * 5;
  238. rates[i].hw_value = i; /* Rate scaling will work on indexes */
  239. rates[i].hw_value_short = i;
  240. rates[i].flags = 0;
  241. if ((i > IWL_LAST_OFDM_RATE) || (i < IWL_FIRST_OFDM_RATE)) {
  242. /*
  243. * If CCK != 1M then set short preamble rate flag.
  244. */
  245. rates[i].flags |=
  246. (iwl4965_rates[i].plcp == IWL_RATE_1M_PLCP) ?
  247. 0 : IEEE80211_RATE_SHORT_PREAMBLE;
  248. }
  249. }
  250. }
  251. /**
  252. * iwlcore_init_geos - Initialize mac80211's geo/channel info based from eeprom
  253. */
  254. static int iwlcore_init_geos(struct iwl_priv *priv)
  255. {
  256. struct iwl_channel_info *ch;
  257. struct ieee80211_supported_band *sband;
  258. struct ieee80211_channel *channels;
  259. struct ieee80211_channel *geo_ch;
  260. struct ieee80211_rate *rates;
  261. int i = 0;
  262. if (priv->bands[IEEE80211_BAND_2GHZ].n_bitrates ||
  263. priv->bands[IEEE80211_BAND_5GHZ].n_bitrates) {
  264. IWL_DEBUG_INFO("Geography modes already initialized.\n");
  265. set_bit(STATUS_GEO_CONFIGURED, &priv->status);
  266. return 0;
  267. }
  268. channels = kzalloc(sizeof(struct ieee80211_channel) *
  269. priv->channel_count, GFP_KERNEL);
  270. if (!channels)
  271. return -ENOMEM;
  272. rates = kzalloc((sizeof(struct ieee80211_rate) * (IWL_RATE_COUNT + 1)),
  273. GFP_KERNEL);
  274. if (!rates) {
  275. kfree(channels);
  276. return -ENOMEM;
  277. }
  278. /* 5.2GHz channels start after the 2.4GHz channels */
  279. sband = &priv->bands[IEEE80211_BAND_5GHZ];
  280. sband->channels = &channels[ARRAY_SIZE(iwl_eeprom_band_1)];
  281. /* just OFDM */
  282. sband->bitrates = &rates[IWL_FIRST_OFDM_RATE];
  283. sband->n_bitrates = IWL_RATE_COUNT - IWL_FIRST_OFDM_RATE;
  284. iwlcore_init_ht_hw_capab(priv, &sband->ht_info, IEEE80211_BAND_5GHZ);
  285. sband = &priv->bands[IEEE80211_BAND_2GHZ];
  286. sband->channels = channels;
  287. /* OFDM & CCK */
  288. sband->bitrates = rates;
  289. sband->n_bitrates = IWL_RATE_COUNT;
  290. iwlcore_init_ht_hw_capab(priv, &sband->ht_info, IEEE80211_BAND_2GHZ);
  291. priv->ieee_channels = channels;
  292. priv->ieee_rates = rates;
  293. iwlcore_init_hw_rates(priv, rates);
  294. for (i = 0; i < priv->channel_count; i++) {
  295. ch = &priv->channel_info[i];
  296. /* FIXME: might be removed if scan is OK */
  297. if (!is_channel_valid(ch))
  298. continue;
  299. if (is_channel_a_band(ch))
  300. sband = &priv->bands[IEEE80211_BAND_5GHZ];
  301. else
  302. sband = &priv->bands[IEEE80211_BAND_2GHZ];
  303. geo_ch = &sband->channels[sband->n_channels++];
  304. geo_ch->center_freq =
  305. ieee80211_channel_to_frequency(ch->channel);
  306. geo_ch->max_power = ch->max_power_avg;
  307. geo_ch->max_antenna_gain = 0xff;
  308. geo_ch->hw_value = ch->channel;
  309. if (is_channel_valid(ch)) {
  310. if (!(ch->flags & EEPROM_CHANNEL_IBSS))
  311. geo_ch->flags |= IEEE80211_CHAN_NO_IBSS;
  312. if (!(ch->flags & EEPROM_CHANNEL_ACTIVE))
  313. geo_ch->flags |= IEEE80211_CHAN_PASSIVE_SCAN;
  314. if (ch->flags & EEPROM_CHANNEL_RADAR)
  315. geo_ch->flags |= IEEE80211_CHAN_RADAR;
  316. if (ch->max_power_avg > priv->max_channel_txpower_limit)
  317. priv->max_channel_txpower_limit =
  318. ch->max_power_avg;
  319. } else {
  320. geo_ch->flags |= IEEE80211_CHAN_DISABLED;
  321. }
  322. /* Save flags for reg domain usage */
  323. geo_ch->orig_flags = geo_ch->flags;
  324. IWL_DEBUG_INFO("Channel %d Freq=%d[%sGHz] %s flag=0%X\n",
  325. ch->channel, geo_ch->center_freq,
  326. is_channel_a_band(ch) ? "5.2" : "2.4",
  327. geo_ch->flags & IEEE80211_CHAN_DISABLED ?
  328. "restricted" : "valid",
  329. geo_ch->flags);
  330. }
  331. if ((priv->bands[IEEE80211_BAND_5GHZ].n_channels == 0) &&
  332. priv->cfg->sku & IWL_SKU_A) {
  333. printk(KERN_INFO DRV_NAME
  334. ": Incorrectly detected BG card as ABG. Please send "
  335. "your PCI ID 0x%04X:0x%04X to maintainer.\n",
  336. priv->pci_dev->device, priv->pci_dev->subsystem_device);
  337. priv->cfg->sku &= ~IWL_SKU_A;
  338. }
  339. printk(KERN_INFO DRV_NAME
  340. ": Tunable channels: %d 802.11bg, %d 802.11a channels\n",
  341. priv->bands[IEEE80211_BAND_2GHZ].n_channels,
  342. priv->bands[IEEE80211_BAND_5GHZ].n_channels);
  343. if (priv->bands[IEEE80211_BAND_2GHZ].n_channels)
  344. priv->hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
  345. &priv->bands[IEEE80211_BAND_2GHZ];
  346. if (priv->bands[IEEE80211_BAND_5GHZ].n_channels)
  347. priv->hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
  348. &priv->bands[IEEE80211_BAND_5GHZ];
  349. set_bit(STATUS_GEO_CONFIGURED, &priv->status);
  350. return 0;
  351. }
  352. /*
  353. * iwlcore_free_geos - undo allocations in iwlcore_init_geos
  354. */
  355. void iwlcore_free_geos(struct iwl_priv *priv)
  356. {
  357. kfree(priv->ieee_channels);
  358. kfree(priv->ieee_rates);
  359. clear_bit(STATUS_GEO_CONFIGURED, &priv->status);
  360. }
  361. EXPORT_SYMBOL(iwlcore_free_geos);
  362. #ifdef CONFIG_IWL4965_HT
  363. static u8 is_single_rx_stream(struct iwl_priv *priv)
  364. {
  365. return !priv->current_ht_config.is_ht ||
  366. ((priv->current_ht_config.supp_mcs_set[1] == 0) &&
  367. (priv->current_ht_config.supp_mcs_set[2] == 0)) ||
  368. priv->ps_mode == IWL_MIMO_PS_STATIC;
  369. }
  370. #else
  371. static inline u8 is_single_rx_stream(struct iwl_priv *priv)
  372. {
  373. return 1;
  374. }
  375. #endif /*CONFIG_IWL4965_HT */
  376. /*
  377. * Determine how many receiver/antenna chains to use.
  378. * More provides better reception via diversity. Fewer saves power.
  379. * MIMO (dual stream) requires at least 2, but works better with 3.
  380. * This does not determine *which* chains to use, just how many.
  381. */
  382. static int iwlcore_get_rx_chain_counter(struct iwl_priv *priv,
  383. u8 *idle_state, u8 *rx_state)
  384. {
  385. u8 is_single = is_single_rx_stream(priv);
  386. u8 is_cam = test_bit(STATUS_POWER_PMI, &priv->status) ? 0 : 1;
  387. /* # of Rx chains to use when expecting MIMO. */
  388. if (is_single || (!is_cam && (priv->ps_mode == IWL_MIMO_PS_STATIC)))
  389. *rx_state = 2;
  390. else
  391. *rx_state = 3;
  392. /* # Rx chains when idling and maybe trying to save power */
  393. switch (priv->ps_mode) {
  394. case IWL_MIMO_PS_STATIC:
  395. case IWL_MIMO_PS_DYNAMIC:
  396. *idle_state = (is_cam) ? 2 : 1;
  397. break;
  398. case IWL_MIMO_PS_NONE:
  399. *idle_state = (is_cam) ? *rx_state : 1;
  400. break;
  401. default:
  402. *idle_state = 1;
  403. break;
  404. }
  405. return 0;
  406. }
  407. /**
  408. * iwl_set_rxon_chain - Set up Rx chain usage in "staging" RXON image
  409. *
  410. * Selects how many and which Rx receivers/antennas/chains to use.
  411. * This should not be used for scan command ... it puts data in wrong place.
  412. */
  413. void iwl_set_rxon_chain(struct iwl_priv *priv)
  414. {
  415. u8 is_single = is_single_rx_stream(priv);
  416. u8 idle_state, rx_state;
  417. priv->staging_rxon.rx_chain = 0;
  418. rx_state = idle_state = 3;
  419. /* Tell uCode which antennas are actually connected.
  420. * Before first association, we assume all antennas are connected.
  421. * Just after first association, iwl_chain_noise_calibration()
  422. * checks which antennas actually *are* connected. */
  423. priv->staging_rxon.rx_chain |=
  424. cpu_to_le16(priv->hw_params.valid_rx_ant <<
  425. RXON_RX_CHAIN_VALID_POS);
  426. /* How many receivers should we use? */
  427. iwlcore_get_rx_chain_counter(priv, &idle_state, &rx_state);
  428. priv->staging_rxon.rx_chain |=
  429. cpu_to_le16(rx_state << RXON_RX_CHAIN_MIMO_CNT_POS);
  430. priv->staging_rxon.rx_chain |=
  431. cpu_to_le16(idle_state << RXON_RX_CHAIN_CNT_POS);
  432. if (!is_single && (rx_state >= 2) &&
  433. !test_bit(STATUS_POWER_PMI, &priv->status))
  434. priv->staging_rxon.rx_chain |= RXON_RX_CHAIN_MIMO_FORCE_MSK;
  435. else
  436. priv->staging_rxon.rx_chain &= ~RXON_RX_CHAIN_MIMO_FORCE_MSK;
  437. IWL_DEBUG_ASSOC("rx chain %X\n", priv->staging_rxon.rx_chain);
  438. }
  439. EXPORT_SYMBOL(iwl_set_rxon_chain);
  440. /**
  441. * iwlcore_set_rxon_channel - Set the phymode and channel values in staging RXON
  442. * @phymode: MODE_IEEE80211A sets to 5.2GHz; all else set to 2.4GHz
  443. * @channel: Any channel valid for the requested phymode
  444. * In addition to setting the staging RXON, priv->phymode is also set.
  445. *
  446. * NOTE: Does not commit to the hardware; it sets appropriate bit fields
  447. * in the staging RXON flag structure based on the phymode
  448. */
  449. int iwl_set_rxon_channel(struct iwl_priv *priv,
  450. enum ieee80211_band band,
  451. u16 channel)
  452. {
  453. if (!iwl_get_channel_info(priv, band, channel)) {
  454. IWL_DEBUG_INFO("Could not set channel to %d [%d]\n",
  455. channel, band);
  456. return -EINVAL;
  457. }
  458. if ((le16_to_cpu(priv->staging_rxon.channel) == channel) &&
  459. (priv->band == band))
  460. return 0;
  461. priv->staging_rxon.channel = cpu_to_le16(channel);
  462. if (band == IEEE80211_BAND_5GHZ)
  463. priv->staging_rxon.flags &= ~RXON_FLG_BAND_24G_MSK;
  464. else
  465. priv->staging_rxon.flags |= RXON_FLG_BAND_24G_MSK;
  466. priv->band = band;
  467. IWL_DEBUG_INFO("Staging channel set to %d [%d]\n", channel, band);
  468. return 0;
  469. }
  470. EXPORT_SYMBOL(iwl_set_rxon_channel);
  471. static void iwlcore_init_hw(struct iwl_priv *priv)
  472. {
  473. struct ieee80211_hw *hw = priv->hw;
  474. hw->rate_control_algorithm = "iwl-4965-rs";
  475. /* Tell mac80211 and its clients (e.g. Wireless Extensions)
  476. * the range of signal quality values that we'll provide.
  477. * Negative values for level/noise indicate that we'll provide dBm.
  478. * For WE, at least, non-0 values here *enable* display of values
  479. * in app (iwconfig). */
  480. hw->max_rssi = -20; /* signal level, negative indicates dBm */
  481. hw->max_noise = -20; /* noise level, negative indicates dBm */
  482. hw->max_signal = 100; /* link quality indication (%) */
  483. /* Tell mac80211 our Tx characteristics */
  484. hw->flags = IEEE80211_HW_HOST_GEN_BEACON_TEMPLATE;
  485. /* Default value; 4 EDCA QOS priorities */
  486. hw->queues = 4;
  487. #ifdef CONFIG_IWL4965_HT
  488. /* Enhanced value; more queues, to support 11n aggregation */
  489. hw->queues = 16;
  490. #endif /* CONFIG_IWL4965_HT */
  491. }
  492. static int iwlcore_init_drv(struct iwl_priv *priv)
  493. {
  494. int ret;
  495. int i;
  496. priv->retry_rate = 1;
  497. priv->ibss_beacon = NULL;
  498. spin_lock_init(&priv->lock);
  499. spin_lock_init(&priv->power_data.lock);
  500. spin_lock_init(&priv->sta_lock);
  501. spin_lock_init(&priv->hcmd_lock);
  502. spin_lock_init(&priv->lq_mngr.lock);
  503. for (i = 0; i < IWL_IBSS_MAC_HASH_SIZE; i++)
  504. INIT_LIST_HEAD(&priv->ibss_mac_hash[i]);
  505. INIT_LIST_HEAD(&priv->free_frames);
  506. mutex_init(&priv->mutex);
  507. /* Clear the driver's (not device's) station table */
  508. iwlcore_clear_stations_table(priv);
  509. priv->data_retry_limit = -1;
  510. priv->ieee_channels = NULL;
  511. priv->ieee_rates = NULL;
  512. priv->band = IEEE80211_BAND_2GHZ;
  513. priv->iw_mode = IEEE80211_IF_TYPE_STA;
  514. priv->use_ant_b_for_management_frame = 1; /* start with ant B */
  515. priv->ps_mode = IWL_MIMO_PS_NONE;
  516. /* Choose which receivers/antennas to use */
  517. iwl_set_rxon_chain(priv);
  518. iwl_reset_qos(priv);
  519. priv->qos_data.qos_active = 0;
  520. priv->qos_data.qos_cap.val = 0;
  521. iwl_set_rxon_channel(priv, IEEE80211_BAND_2GHZ, 6);
  522. priv->rates_mask = IWL_RATES_MASK;
  523. /* If power management is turned on, default to AC mode */
  524. priv->power_mode = IWL_POWER_AC;
  525. priv->user_txpower_limit = IWL_DEFAULT_TX_POWER;
  526. ret = iwl_init_channel_map(priv);
  527. if (ret) {
  528. IWL_ERROR("initializing regulatory failed: %d\n", ret);
  529. goto err;
  530. }
  531. ret = iwlcore_init_geos(priv);
  532. if (ret) {
  533. IWL_ERROR("initializing geos failed: %d\n", ret);
  534. goto err_free_channel_map;
  535. }
  536. ret = ieee80211_register_hw(priv->hw);
  537. if (ret) {
  538. IWL_ERROR("Failed to register network device (error %d)\n",
  539. ret);
  540. goto err_free_geos;
  541. }
  542. priv->hw->conf.beacon_int = 100;
  543. priv->mac80211_registered = 1;
  544. return 0;
  545. err_free_geos:
  546. iwlcore_free_geos(priv);
  547. err_free_channel_map:
  548. iwl_free_channel_map(priv);
  549. err:
  550. return ret;
  551. }
  552. int iwl_setup(struct iwl_priv *priv)
  553. {
  554. int ret = 0;
  555. iwlcore_init_hw(priv);
  556. ret = iwlcore_init_drv(priv);
  557. return ret;
  558. }
  559. EXPORT_SYMBOL(iwl_setup);
  560. /* Low level driver call this function to update iwlcore with
  561. * driver status.
  562. */
  563. int iwlcore_low_level_notify(struct iwl_priv *priv,
  564. enum iwlcore_card_notify notify)
  565. {
  566. int ret;
  567. switch (notify) {
  568. case IWLCORE_INIT_EVT:
  569. ret = iwl_rfkill_init(priv);
  570. if (ret)
  571. IWL_ERROR("Unable to initialize RFKILL system. "
  572. "Ignoring error: %d\n", ret);
  573. iwl_power_initialize(priv);
  574. break;
  575. case IWLCORE_START_EVT:
  576. iwl_power_update_mode(priv, 1);
  577. break;
  578. case IWLCORE_STOP_EVT:
  579. break;
  580. case IWLCORE_REMOVE_EVT:
  581. iwl_rfkill_unregister(priv);
  582. break;
  583. }
  584. return 0;
  585. }
  586. EXPORT_SYMBOL(iwlcore_low_level_notify);
  587. int iwl_send_statistics_request(struct iwl_priv *priv, u8 flags)
  588. {
  589. u32 stat_flags = 0;
  590. struct iwl_host_cmd cmd = {
  591. .id = REPLY_STATISTICS_CMD,
  592. .meta.flags = flags,
  593. .len = sizeof(stat_flags),
  594. .data = (u8 *) &stat_flags,
  595. };
  596. return iwl_send_cmd(priv, &cmd);
  597. }
  598. EXPORT_SYMBOL(iwl_send_statistics_request);
  599. /**
  600. * iwl_verify_inst_sparse - verify runtime uCode image in card vs. host,
  601. * using sample data 100 bytes apart. If these sample points are good,
  602. * it's a pretty good bet that everything between them is good, too.
  603. */
  604. static int iwlcore_verify_inst_sparse(struct iwl_priv *priv, __le32 *image, u32 len)
  605. {
  606. u32 val;
  607. int ret = 0;
  608. u32 errcnt = 0;
  609. u32 i;
  610. IWL_DEBUG_INFO("ucode inst image size is %u\n", len);
  611. ret = iwl_grab_nic_access(priv);
  612. if (ret)
  613. return ret;
  614. for (i = 0; i < len; i += 100, image += 100/sizeof(u32)) {
  615. /* read data comes through single port, auto-incr addr */
  616. /* NOTE: Use the debugless read so we don't flood kernel log
  617. * if IWL_DL_IO is set */
  618. iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR,
  619. i + RTC_INST_LOWER_BOUND);
  620. val = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
  621. if (val != le32_to_cpu(*image)) {
  622. ret = -EIO;
  623. errcnt++;
  624. if (errcnt >= 3)
  625. break;
  626. }
  627. }
  628. iwl_release_nic_access(priv);
  629. return ret;
  630. }
  631. /**
  632. * iwlcore_verify_inst_full - verify runtime uCode image in card vs. host,
  633. * looking at all data.
  634. */
  635. static int iwl_verify_inst_full(struct iwl_priv *priv, __le32 *image,
  636. u32 len)
  637. {
  638. u32 val;
  639. u32 save_len = len;
  640. int ret = 0;
  641. u32 errcnt;
  642. IWL_DEBUG_INFO("ucode inst image size is %u\n", len);
  643. ret = iwl_grab_nic_access(priv);
  644. if (ret)
  645. return ret;
  646. iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR, RTC_INST_LOWER_BOUND);
  647. errcnt = 0;
  648. for (; len > 0; len -= sizeof(u32), image++) {
  649. /* read data comes through single port, auto-incr addr */
  650. /* NOTE: Use the debugless read so we don't flood kernel log
  651. * if IWL_DL_IO is set */
  652. val = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
  653. if (val != le32_to_cpu(*image)) {
  654. IWL_ERROR("uCode INST section is invalid at "
  655. "offset 0x%x, is 0x%x, s/b 0x%x\n",
  656. save_len - len, val, le32_to_cpu(*image));
  657. ret = -EIO;
  658. errcnt++;
  659. if (errcnt >= 20)
  660. break;
  661. }
  662. }
  663. iwl_release_nic_access(priv);
  664. if (!errcnt)
  665. IWL_DEBUG_INFO
  666. ("ucode image in INSTRUCTION memory is good\n");
  667. return ret;
  668. }
  669. /**
  670. * iwl_verify_ucode - determine which instruction image is in SRAM,
  671. * and verify its contents
  672. */
  673. int iwl_verify_ucode(struct iwl_priv *priv)
  674. {
  675. __le32 *image;
  676. u32 len;
  677. int ret;
  678. /* Try bootstrap */
  679. image = (__le32 *)priv->ucode_boot.v_addr;
  680. len = priv->ucode_boot.len;
  681. ret = iwlcore_verify_inst_sparse(priv, image, len);
  682. if (!ret) {
  683. IWL_DEBUG_INFO("Bootstrap uCode is good in inst SRAM\n");
  684. return 0;
  685. }
  686. /* Try initialize */
  687. image = (__le32 *)priv->ucode_init.v_addr;
  688. len = priv->ucode_init.len;
  689. ret = iwlcore_verify_inst_sparse(priv, image, len);
  690. if (!ret) {
  691. IWL_DEBUG_INFO("Initialize uCode is good in inst SRAM\n");
  692. return 0;
  693. }
  694. /* Try runtime/protocol */
  695. image = (__le32 *)priv->ucode_code.v_addr;
  696. len = priv->ucode_code.len;
  697. ret = iwlcore_verify_inst_sparse(priv, image, len);
  698. if (!ret) {
  699. IWL_DEBUG_INFO("Runtime uCode is good in inst SRAM\n");
  700. return 0;
  701. }
  702. IWL_ERROR("NO VALID UCODE IMAGE IN INSTRUCTION SRAM!!\n");
  703. /* Since nothing seems to match, show first several data entries in
  704. * instruction SRAM, so maybe visual inspection will give a clue.
  705. * Selection of bootstrap image (vs. other images) is arbitrary. */
  706. image = (__le32 *)priv->ucode_boot.v_addr;
  707. len = priv->ucode_boot.len;
  708. ret = iwl_verify_inst_full(priv, image, len);
  709. return ret;
  710. }
  711. EXPORT_SYMBOL(iwl_verify_ucode);