iwl-core.c 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945
  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. #else
  232. static inline void iwlcore_init_ht_hw_capab(const struct iwl_priv *priv,
  233. struct ieee80211_ht_info *ht_info,
  234. enum ieee80211_band band)
  235. {
  236. }
  237. #endif /* CONFIG_IWL4965_HT */
  238. static void iwlcore_init_hw_rates(struct iwl_priv *priv,
  239. struct ieee80211_rate *rates)
  240. {
  241. int i;
  242. for (i = 0; i < IWL_RATE_COUNT; i++) {
  243. rates[i].bitrate = iwl4965_rates[i].ieee * 5;
  244. rates[i].hw_value = i; /* Rate scaling will work on indexes */
  245. rates[i].hw_value_short = i;
  246. rates[i].flags = 0;
  247. if ((i > IWL_LAST_OFDM_RATE) || (i < IWL_FIRST_OFDM_RATE)) {
  248. /*
  249. * If CCK != 1M then set short preamble rate flag.
  250. */
  251. rates[i].flags |=
  252. (iwl4965_rates[i].plcp == IWL_RATE_1M_PLCP) ?
  253. 0 : IEEE80211_RATE_SHORT_PREAMBLE;
  254. }
  255. }
  256. }
  257. /**
  258. * iwlcore_init_geos - Initialize mac80211's geo/channel info based from eeprom
  259. */
  260. static int iwlcore_init_geos(struct iwl_priv *priv)
  261. {
  262. struct iwl_channel_info *ch;
  263. struct ieee80211_supported_band *sband;
  264. struct ieee80211_channel *channels;
  265. struct ieee80211_channel *geo_ch;
  266. struct ieee80211_rate *rates;
  267. int i = 0;
  268. if (priv->bands[IEEE80211_BAND_2GHZ].n_bitrates ||
  269. priv->bands[IEEE80211_BAND_5GHZ].n_bitrates) {
  270. IWL_DEBUG_INFO("Geography modes already initialized.\n");
  271. set_bit(STATUS_GEO_CONFIGURED, &priv->status);
  272. return 0;
  273. }
  274. channels = kzalloc(sizeof(struct ieee80211_channel) *
  275. priv->channel_count, GFP_KERNEL);
  276. if (!channels)
  277. return -ENOMEM;
  278. rates = kzalloc((sizeof(struct ieee80211_rate) * (IWL_RATE_COUNT + 1)),
  279. GFP_KERNEL);
  280. if (!rates) {
  281. kfree(channels);
  282. return -ENOMEM;
  283. }
  284. /* 5.2GHz channels start after the 2.4GHz channels */
  285. sband = &priv->bands[IEEE80211_BAND_5GHZ];
  286. sband->channels = &channels[ARRAY_SIZE(iwl_eeprom_band_1)];
  287. /* just OFDM */
  288. sband->bitrates = &rates[IWL_FIRST_OFDM_RATE];
  289. sband->n_bitrates = IWL_RATE_COUNT - IWL_FIRST_OFDM_RATE;
  290. iwlcore_init_ht_hw_capab(priv, &sband->ht_info, IEEE80211_BAND_5GHZ);
  291. sband = &priv->bands[IEEE80211_BAND_2GHZ];
  292. sband->channels = channels;
  293. /* OFDM & CCK */
  294. sband->bitrates = rates;
  295. sband->n_bitrates = IWL_RATE_COUNT;
  296. iwlcore_init_ht_hw_capab(priv, &sband->ht_info, IEEE80211_BAND_2GHZ);
  297. priv->ieee_channels = channels;
  298. priv->ieee_rates = rates;
  299. iwlcore_init_hw_rates(priv, rates);
  300. for (i = 0; i < priv->channel_count; i++) {
  301. ch = &priv->channel_info[i];
  302. /* FIXME: might be removed if scan is OK */
  303. if (!is_channel_valid(ch))
  304. continue;
  305. if (is_channel_a_band(ch))
  306. sband = &priv->bands[IEEE80211_BAND_5GHZ];
  307. else
  308. sband = &priv->bands[IEEE80211_BAND_2GHZ];
  309. geo_ch = &sband->channels[sband->n_channels++];
  310. geo_ch->center_freq =
  311. ieee80211_channel_to_frequency(ch->channel);
  312. geo_ch->max_power = ch->max_power_avg;
  313. geo_ch->max_antenna_gain = 0xff;
  314. geo_ch->hw_value = ch->channel;
  315. if (is_channel_valid(ch)) {
  316. if (!(ch->flags & EEPROM_CHANNEL_IBSS))
  317. geo_ch->flags |= IEEE80211_CHAN_NO_IBSS;
  318. if (!(ch->flags & EEPROM_CHANNEL_ACTIVE))
  319. geo_ch->flags |= IEEE80211_CHAN_PASSIVE_SCAN;
  320. if (ch->flags & EEPROM_CHANNEL_RADAR)
  321. geo_ch->flags |= IEEE80211_CHAN_RADAR;
  322. if (ch->max_power_avg > priv->max_channel_txpower_limit)
  323. priv->max_channel_txpower_limit =
  324. ch->max_power_avg;
  325. } else {
  326. geo_ch->flags |= IEEE80211_CHAN_DISABLED;
  327. }
  328. /* Save flags for reg domain usage */
  329. geo_ch->orig_flags = geo_ch->flags;
  330. IWL_DEBUG_INFO("Channel %d Freq=%d[%sGHz] %s flag=0%X\n",
  331. ch->channel, geo_ch->center_freq,
  332. is_channel_a_band(ch) ? "5.2" : "2.4",
  333. geo_ch->flags & IEEE80211_CHAN_DISABLED ?
  334. "restricted" : "valid",
  335. geo_ch->flags);
  336. }
  337. if ((priv->bands[IEEE80211_BAND_5GHZ].n_channels == 0) &&
  338. priv->cfg->sku & IWL_SKU_A) {
  339. printk(KERN_INFO DRV_NAME
  340. ": Incorrectly detected BG card as ABG. Please send "
  341. "your PCI ID 0x%04X:0x%04X to maintainer.\n",
  342. priv->pci_dev->device, priv->pci_dev->subsystem_device);
  343. priv->cfg->sku &= ~IWL_SKU_A;
  344. }
  345. printk(KERN_INFO DRV_NAME
  346. ": Tunable channels: %d 802.11bg, %d 802.11a channels\n",
  347. priv->bands[IEEE80211_BAND_2GHZ].n_channels,
  348. priv->bands[IEEE80211_BAND_5GHZ].n_channels);
  349. if (priv->bands[IEEE80211_BAND_2GHZ].n_channels)
  350. priv->hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
  351. &priv->bands[IEEE80211_BAND_2GHZ];
  352. if (priv->bands[IEEE80211_BAND_5GHZ].n_channels)
  353. priv->hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
  354. &priv->bands[IEEE80211_BAND_5GHZ];
  355. set_bit(STATUS_GEO_CONFIGURED, &priv->status);
  356. return 0;
  357. }
  358. /*
  359. * iwlcore_free_geos - undo allocations in iwlcore_init_geos
  360. */
  361. void iwlcore_free_geos(struct iwl_priv *priv)
  362. {
  363. kfree(priv->ieee_channels);
  364. kfree(priv->ieee_rates);
  365. clear_bit(STATUS_GEO_CONFIGURED, &priv->status);
  366. }
  367. EXPORT_SYMBOL(iwlcore_free_geos);
  368. #ifdef CONFIG_IWL4965_HT
  369. static u8 is_single_rx_stream(struct iwl_priv *priv)
  370. {
  371. return !priv->current_ht_config.is_ht ||
  372. ((priv->current_ht_config.supp_mcs_set[1] == 0) &&
  373. (priv->current_ht_config.supp_mcs_set[2] == 0)) ||
  374. priv->ps_mode == IWL_MIMO_PS_STATIC;
  375. }
  376. static u8 iwl_is_channel_extension(struct iwl_priv *priv,
  377. enum ieee80211_band band,
  378. u16 channel, u8 extension_chan_offset)
  379. {
  380. const struct iwl_channel_info *ch_info;
  381. ch_info = iwl_get_channel_info(priv, band, channel);
  382. if (!is_channel_valid(ch_info))
  383. return 0;
  384. if (extension_chan_offset == IWL_EXT_CHANNEL_OFFSET_NONE)
  385. return 0;
  386. if ((ch_info->fat_extension_channel == extension_chan_offset) ||
  387. (ch_info->fat_extension_channel == HT_IE_EXT_CHANNEL_MAX))
  388. return 1;
  389. return 0;
  390. }
  391. u8 iwl_is_fat_tx_allowed(struct iwl_priv *priv,
  392. struct ieee80211_ht_info *sta_ht_inf)
  393. {
  394. struct iwl_ht_info *iwl_ht_conf = &priv->current_ht_config;
  395. if ((!iwl_ht_conf->is_ht) ||
  396. (iwl_ht_conf->supported_chan_width != IWL_CHANNEL_WIDTH_40MHZ) ||
  397. (iwl_ht_conf->extension_chan_offset == IWL_EXT_CHANNEL_OFFSET_NONE))
  398. return 0;
  399. if (sta_ht_inf) {
  400. if ((!sta_ht_inf->ht_supported) ||
  401. (!(sta_ht_inf->cap & IEEE80211_HT_CAP_SUP_WIDTH)))
  402. return 0;
  403. }
  404. return iwl_is_channel_extension(priv, priv->band,
  405. iwl_ht_conf->control_channel,
  406. iwl_ht_conf->extension_chan_offset);
  407. }
  408. EXPORT_SYMBOL(iwl_is_fat_tx_allowed);
  409. void iwl_set_rxon_ht(struct iwl_priv *priv, struct iwl_ht_info *ht_info)
  410. {
  411. struct iwl4965_rxon_cmd *rxon = &priv->staging_rxon;
  412. u32 val;
  413. if (!ht_info->is_ht)
  414. return;
  415. /* Set up channel bandwidth: 20 MHz only, or 20/40 mixed if fat ok */
  416. if (iwl_is_fat_tx_allowed(priv, NULL))
  417. rxon->flags |= RXON_FLG_CHANNEL_MODE_MIXED_MSK;
  418. else
  419. rxon->flags &= ~(RXON_FLG_CHANNEL_MODE_MIXED_MSK |
  420. RXON_FLG_CHANNEL_MODE_PURE_40_MSK);
  421. if (le16_to_cpu(rxon->channel) != ht_info->control_channel) {
  422. IWL_DEBUG_ASSOC("control diff than current %d %d\n",
  423. le16_to_cpu(rxon->channel),
  424. ht_info->control_channel);
  425. rxon->channel = cpu_to_le16(ht_info->control_channel);
  426. return;
  427. }
  428. /* Note: control channel is opposite of extension channel */
  429. switch (ht_info->extension_chan_offset) {
  430. case IWL_EXT_CHANNEL_OFFSET_ABOVE:
  431. rxon->flags &= ~(RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK);
  432. break;
  433. case IWL_EXT_CHANNEL_OFFSET_BELOW:
  434. rxon->flags |= RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK;
  435. break;
  436. case IWL_EXT_CHANNEL_OFFSET_NONE:
  437. default:
  438. rxon->flags &= ~RXON_FLG_CHANNEL_MODE_MIXED_MSK;
  439. break;
  440. }
  441. val = ht_info->ht_protection;
  442. rxon->flags |= cpu_to_le32(val << RXON_FLG_HT_OPERATING_MODE_POS);
  443. iwl_set_rxon_chain(priv);
  444. IWL_DEBUG_ASSOC("supported HT rate 0x%X 0x%X 0x%X "
  445. "rxon flags 0x%X operation mode :0x%X "
  446. "extension channel offset 0x%x "
  447. "control chan %d\n",
  448. ht_info->supp_mcs_set[0],
  449. ht_info->supp_mcs_set[1],
  450. ht_info->supp_mcs_set[2],
  451. le32_to_cpu(rxon->flags), ht_info->ht_protection,
  452. ht_info->extension_chan_offset,
  453. ht_info->control_channel);
  454. return;
  455. }
  456. EXPORT_SYMBOL(iwl_set_rxon_ht);
  457. #else
  458. static inline u8 is_single_rx_stream(struct iwl_priv *priv)
  459. {
  460. return 1;
  461. }
  462. #endif /*CONFIG_IWL4965_HT */
  463. /*
  464. * Determine how many receiver/antenna chains to use.
  465. * More provides better reception via diversity. Fewer saves power.
  466. * MIMO (dual stream) requires at least 2, but works better with 3.
  467. * This does not determine *which* chains to use, just how many.
  468. */
  469. static int iwlcore_get_rx_chain_counter(struct iwl_priv *priv,
  470. u8 *idle_state, u8 *rx_state)
  471. {
  472. u8 is_single = is_single_rx_stream(priv);
  473. u8 is_cam = test_bit(STATUS_POWER_PMI, &priv->status) ? 0 : 1;
  474. /* # of Rx chains to use when expecting MIMO. */
  475. if (is_single || (!is_cam && (priv->ps_mode == IWL_MIMO_PS_STATIC)))
  476. *rx_state = 2;
  477. else
  478. *rx_state = 3;
  479. /* # Rx chains when idling and maybe trying to save power */
  480. switch (priv->ps_mode) {
  481. case IWL_MIMO_PS_STATIC:
  482. case IWL_MIMO_PS_DYNAMIC:
  483. *idle_state = (is_cam) ? 2 : 1;
  484. break;
  485. case IWL_MIMO_PS_NONE:
  486. *idle_state = (is_cam) ? *rx_state : 1;
  487. break;
  488. default:
  489. *idle_state = 1;
  490. break;
  491. }
  492. return 0;
  493. }
  494. /**
  495. * iwl_set_rxon_chain - Set up Rx chain usage in "staging" RXON image
  496. *
  497. * Selects how many and which Rx receivers/antennas/chains to use.
  498. * This should not be used for scan command ... it puts data in wrong place.
  499. */
  500. void iwl_set_rxon_chain(struct iwl_priv *priv)
  501. {
  502. u8 is_single = is_single_rx_stream(priv);
  503. u8 idle_state, rx_state;
  504. priv->staging_rxon.rx_chain = 0;
  505. rx_state = idle_state = 3;
  506. /* Tell uCode which antennas are actually connected.
  507. * Before first association, we assume all antennas are connected.
  508. * Just after first association, iwl_chain_noise_calibration()
  509. * checks which antennas actually *are* connected. */
  510. priv->staging_rxon.rx_chain |=
  511. cpu_to_le16(priv->hw_params.valid_rx_ant <<
  512. RXON_RX_CHAIN_VALID_POS);
  513. /* How many receivers should we use? */
  514. iwlcore_get_rx_chain_counter(priv, &idle_state, &rx_state);
  515. priv->staging_rxon.rx_chain |=
  516. cpu_to_le16(rx_state << RXON_RX_CHAIN_MIMO_CNT_POS);
  517. priv->staging_rxon.rx_chain |=
  518. cpu_to_le16(idle_state << RXON_RX_CHAIN_CNT_POS);
  519. if (!is_single && (rx_state >= 2) &&
  520. !test_bit(STATUS_POWER_PMI, &priv->status))
  521. priv->staging_rxon.rx_chain |= RXON_RX_CHAIN_MIMO_FORCE_MSK;
  522. else
  523. priv->staging_rxon.rx_chain &= ~RXON_RX_CHAIN_MIMO_FORCE_MSK;
  524. IWL_DEBUG_ASSOC("rx chain %X\n", priv->staging_rxon.rx_chain);
  525. }
  526. EXPORT_SYMBOL(iwl_set_rxon_chain);
  527. /**
  528. * iwlcore_set_rxon_channel - Set the phymode and channel values in staging RXON
  529. * @phymode: MODE_IEEE80211A sets to 5.2GHz; all else set to 2.4GHz
  530. * @channel: Any channel valid for the requested phymode
  531. * In addition to setting the staging RXON, priv->phymode is also set.
  532. *
  533. * NOTE: Does not commit to the hardware; it sets appropriate bit fields
  534. * in the staging RXON flag structure based on the phymode
  535. */
  536. int iwl_set_rxon_channel(struct iwl_priv *priv,
  537. enum ieee80211_band band,
  538. u16 channel)
  539. {
  540. if (!iwl_get_channel_info(priv, band, channel)) {
  541. IWL_DEBUG_INFO("Could not set channel to %d [%d]\n",
  542. channel, band);
  543. return -EINVAL;
  544. }
  545. if ((le16_to_cpu(priv->staging_rxon.channel) == channel) &&
  546. (priv->band == band))
  547. return 0;
  548. priv->staging_rxon.channel = cpu_to_le16(channel);
  549. if (band == IEEE80211_BAND_5GHZ)
  550. priv->staging_rxon.flags &= ~RXON_FLG_BAND_24G_MSK;
  551. else
  552. priv->staging_rxon.flags |= RXON_FLG_BAND_24G_MSK;
  553. priv->band = band;
  554. IWL_DEBUG_INFO("Staging channel set to %d [%d]\n", channel, band);
  555. return 0;
  556. }
  557. EXPORT_SYMBOL(iwl_set_rxon_channel);
  558. static void iwlcore_init_hw(struct iwl_priv *priv)
  559. {
  560. struct ieee80211_hw *hw = priv->hw;
  561. hw->rate_control_algorithm = "iwl-4965-rs";
  562. /* Tell mac80211 and its clients (e.g. Wireless Extensions)
  563. * the range of signal quality values that we'll provide.
  564. * Negative values for level/noise indicate that we'll provide dBm.
  565. * For WE, at least, non-0 values here *enable* display of values
  566. * in app (iwconfig). */
  567. hw->max_rssi = -20; /* signal level, negative indicates dBm */
  568. hw->max_noise = -20; /* noise level, negative indicates dBm */
  569. hw->max_signal = 100; /* link quality indication (%) */
  570. /* Tell mac80211 our Tx characteristics */
  571. hw->flags = IEEE80211_HW_HOST_GEN_BEACON_TEMPLATE;
  572. /* Default value; 4 EDCA QOS priorities */
  573. hw->queues = 4;
  574. #ifdef CONFIG_IWL4965_HT
  575. /* Enhanced value; more queues, to support 11n aggregation */
  576. hw->ampdu_queues = 12;
  577. #endif /* CONFIG_IWL4965_HT */
  578. }
  579. static int iwlcore_init_drv(struct iwl_priv *priv)
  580. {
  581. int ret;
  582. int i;
  583. priv->retry_rate = 1;
  584. priv->ibss_beacon = NULL;
  585. spin_lock_init(&priv->lock);
  586. spin_lock_init(&priv->power_data.lock);
  587. spin_lock_init(&priv->sta_lock);
  588. spin_lock_init(&priv->hcmd_lock);
  589. spin_lock_init(&priv->lq_mngr.lock);
  590. for (i = 0; i < IWL_IBSS_MAC_HASH_SIZE; i++)
  591. INIT_LIST_HEAD(&priv->ibss_mac_hash[i]);
  592. INIT_LIST_HEAD(&priv->free_frames);
  593. mutex_init(&priv->mutex);
  594. /* Clear the driver's (not device's) station table */
  595. iwlcore_clear_stations_table(priv);
  596. priv->data_retry_limit = -1;
  597. priv->ieee_channels = NULL;
  598. priv->ieee_rates = NULL;
  599. priv->band = IEEE80211_BAND_2GHZ;
  600. priv->iw_mode = IEEE80211_IF_TYPE_STA;
  601. priv->use_ant_b_for_management_frame = 1; /* start with ant B */
  602. priv->ps_mode = IWL_MIMO_PS_NONE;
  603. /* Choose which receivers/antennas to use */
  604. iwl_set_rxon_chain(priv);
  605. iwl_reset_qos(priv);
  606. priv->qos_data.qos_active = 0;
  607. priv->qos_data.qos_cap.val = 0;
  608. iwl_set_rxon_channel(priv, IEEE80211_BAND_2GHZ, 6);
  609. priv->rates_mask = IWL_RATES_MASK;
  610. /* If power management is turned on, default to AC mode */
  611. priv->power_mode = IWL_POWER_AC;
  612. priv->user_txpower_limit = IWL_DEFAULT_TX_POWER;
  613. ret = iwl_init_channel_map(priv);
  614. if (ret) {
  615. IWL_ERROR("initializing regulatory failed: %d\n", ret);
  616. goto err;
  617. }
  618. ret = iwlcore_init_geos(priv);
  619. if (ret) {
  620. IWL_ERROR("initializing geos failed: %d\n", ret);
  621. goto err_free_channel_map;
  622. }
  623. ret = ieee80211_register_hw(priv->hw);
  624. if (ret) {
  625. IWL_ERROR("Failed to register network device (error %d)\n",
  626. ret);
  627. goto err_free_geos;
  628. }
  629. priv->hw->conf.beacon_int = 100;
  630. priv->mac80211_registered = 1;
  631. return 0;
  632. err_free_geos:
  633. iwlcore_free_geos(priv);
  634. err_free_channel_map:
  635. iwl_free_channel_map(priv);
  636. err:
  637. return ret;
  638. }
  639. int iwl_setup(struct iwl_priv *priv)
  640. {
  641. int ret = 0;
  642. iwlcore_init_hw(priv);
  643. ret = iwlcore_init_drv(priv);
  644. return ret;
  645. }
  646. EXPORT_SYMBOL(iwl_setup);
  647. /* Low level driver call this function to update iwlcore with
  648. * driver status.
  649. */
  650. int iwlcore_low_level_notify(struct iwl_priv *priv,
  651. enum iwlcore_card_notify notify)
  652. {
  653. int ret;
  654. switch (notify) {
  655. case IWLCORE_INIT_EVT:
  656. ret = iwl_rfkill_init(priv);
  657. if (ret)
  658. IWL_ERROR("Unable to initialize RFKILL system. "
  659. "Ignoring error: %d\n", ret);
  660. iwl_power_initialize(priv);
  661. break;
  662. case IWLCORE_START_EVT:
  663. iwl_power_update_mode(priv, 1);
  664. break;
  665. case IWLCORE_STOP_EVT:
  666. break;
  667. case IWLCORE_REMOVE_EVT:
  668. iwl_rfkill_unregister(priv);
  669. break;
  670. }
  671. return 0;
  672. }
  673. EXPORT_SYMBOL(iwlcore_low_level_notify);
  674. int iwl_send_statistics_request(struct iwl_priv *priv, u8 flags)
  675. {
  676. u32 stat_flags = 0;
  677. struct iwl_host_cmd cmd = {
  678. .id = REPLY_STATISTICS_CMD,
  679. .meta.flags = flags,
  680. .len = sizeof(stat_flags),
  681. .data = (u8 *) &stat_flags,
  682. };
  683. return iwl_send_cmd(priv, &cmd);
  684. }
  685. EXPORT_SYMBOL(iwl_send_statistics_request);
  686. /**
  687. * iwl_verify_inst_sparse - verify runtime uCode image in card vs. host,
  688. * using sample data 100 bytes apart. If these sample points are good,
  689. * it's a pretty good bet that everything between them is good, too.
  690. */
  691. static int iwlcore_verify_inst_sparse(struct iwl_priv *priv, __le32 *image, u32 len)
  692. {
  693. u32 val;
  694. int ret = 0;
  695. u32 errcnt = 0;
  696. u32 i;
  697. IWL_DEBUG_INFO("ucode inst image size is %u\n", len);
  698. ret = iwl_grab_nic_access(priv);
  699. if (ret)
  700. return ret;
  701. for (i = 0; i < len; i += 100, image += 100/sizeof(u32)) {
  702. /* read data comes through single port, auto-incr addr */
  703. /* NOTE: Use the debugless read so we don't flood kernel log
  704. * if IWL_DL_IO is set */
  705. iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR,
  706. i + RTC_INST_LOWER_BOUND);
  707. val = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
  708. if (val != le32_to_cpu(*image)) {
  709. ret = -EIO;
  710. errcnt++;
  711. if (errcnt >= 3)
  712. break;
  713. }
  714. }
  715. iwl_release_nic_access(priv);
  716. return ret;
  717. }
  718. /**
  719. * iwlcore_verify_inst_full - verify runtime uCode image in card vs. host,
  720. * looking at all data.
  721. */
  722. static int iwl_verify_inst_full(struct iwl_priv *priv, __le32 *image,
  723. u32 len)
  724. {
  725. u32 val;
  726. u32 save_len = len;
  727. int ret = 0;
  728. u32 errcnt;
  729. IWL_DEBUG_INFO("ucode inst image size is %u\n", len);
  730. ret = iwl_grab_nic_access(priv);
  731. if (ret)
  732. return ret;
  733. iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR, RTC_INST_LOWER_BOUND);
  734. errcnt = 0;
  735. for (; len > 0; len -= sizeof(u32), image++) {
  736. /* read data comes through single port, auto-incr addr */
  737. /* NOTE: Use the debugless read so we don't flood kernel log
  738. * if IWL_DL_IO is set */
  739. val = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
  740. if (val != le32_to_cpu(*image)) {
  741. IWL_ERROR("uCode INST section is invalid at "
  742. "offset 0x%x, is 0x%x, s/b 0x%x\n",
  743. save_len - len, val, le32_to_cpu(*image));
  744. ret = -EIO;
  745. errcnt++;
  746. if (errcnt >= 20)
  747. break;
  748. }
  749. }
  750. iwl_release_nic_access(priv);
  751. if (!errcnt)
  752. IWL_DEBUG_INFO
  753. ("ucode image in INSTRUCTION memory is good\n");
  754. return ret;
  755. }
  756. /**
  757. * iwl_verify_ucode - determine which instruction image is in SRAM,
  758. * and verify its contents
  759. */
  760. int iwl_verify_ucode(struct iwl_priv *priv)
  761. {
  762. __le32 *image;
  763. u32 len;
  764. int ret;
  765. /* Try bootstrap */
  766. image = (__le32 *)priv->ucode_boot.v_addr;
  767. len = priv->ucode_boot.len;
  768. ret = iwlcore_verify_inst_sparse(priv, image, len);
  769. if (!ret) {
  770. IWL_DEBUG_INFO("Bootstrap uCode is good in inst SRAM\n");
  771. return 0;
  772. }
  773. /* Try initialize */
  774. image = (__le32 *)priv->ucode_init.v_addr;
  775. len = priv->ucode_init.len;
  776. ret = iwlcore_verify_inst_sparse(priv, image, len);
  777. if (!ret) {
  778. IWL_DEBUG_INFO("Initialize uCode is good in inst SRAM\n");
  779. return 0;
  780. }
  781. /* Try runtime/protocol */
  782. image = (__le32 *)priv->ucode_code.v_addr;
  783. len = priv->ucode_code.len;
  784. ret = iwlcore_verify_inst_sparse(priv, image, len);
  785. if (!ret) {
  786. IWL_DEBUG_INFO("Runtime uCode is good in inst SRAM\n");
  787. return 0;
  788. }
  789. IWL_ERROR("NO VALID UCODE IMAGE IN INSTRUCTION SRAM!!\n");
  790. /* Since nothing seems to match, show first several data entries in
  791. * instruction SRAM, so maybe visual inspection will give a clue.
  792. * Selection of bootstrap image (vs. other images) is arbitrary. */
  793. image = (__le32 *)priv->ucode_boot.v_addr;
  794. len = priv->ucode_boot.len;
  795. ret = iwl_verify_inst_full(priv, image, len);
  796. return ret;
  797. }
  798. EXPORT_SYMBOL(iwl_verify_ucode);