iwl-core.c 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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-core.h"
  36. #include "iwl-4965.h" /* FIXME: remove */
  37. MODULE_DESCRIPTION("iwl core");
  38. MODULE_VERSION(IWLWIFI_VERSION);
  39. MODULE_AUTHOR(DRV_COPYRIGHT);
  40. MODULE_LICENSE("GPL");
  41. #ifdef CONFIG_IWLWIFI_DEBUG
  42. u32 iwl_debug_level;
  43. EXPORT_SYMBOL(iwl_debug_level);
  44. #endif
  45. /* This function both allocates and initializes hw and priv. */
  46. struct ieee80211_hw *iwl_alloc_all(struct iwl_cfg *cfg,
  47. struct ieee80211_ops *hw_ops)
  48. {
  49. struct iwl_priv *priv;
  50. /* mac80211 allocates memory for this device instance, including
  51. * space for this driver's private structure */
  52. struct ieee80211_hw *hw =
  53. ieee80211_alloc_hw(sizeof(struct iwl_priv), hw_ops);
  54. if (hw == NULL) {
  55. IWL_ERROR("Can not allocate network device\n");
  56. goto out;
  57. }
  58. priv = hw->priv;
  59. priv->hw = hw;
  60. out:
  61. return hw;
  62. }
  63. EXPORT_SYMBOL(iwl_alloc_all);
  64. /**
  65. * iwlcore_clear_stations_table - Clear the driver's station table
  66. *
  67. * NOTE: This does not clear or otherwise alter the device's station table.
  68. */
  69. void iwlcore_clear_stations_table(struct iwl_priv *priv)
  70. {
  71. unsigned long flags;
  72. spin_lock_irqsave(&priv->sta_lock, flags);
  73. priv->num_stations = 0;
  74. memset(priv->stations, 0, sizeof(priv->stations));
  75. spin_unlock_irqrestore(&priv->sta_lock, flags);
  76. }
  77. EXPORT_SYMBOL(iwlcore_clear_stations_table);
  78. void iwlcore_reset_qos(struct iwl_priv *priv)
  79. {
  80. u16 cw_min = 15;
  81. u16 cw_max = 1023;
  82. u8 aifs = 2;
  83. u8 is_legacy = 0;
  84. unsigned long flags;
  85. int i;
  86. spin_lock_irqsave(&priv->lock, flags);
  87. priv->qos_data.qos_active = 0;
  88. if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS) {
  89. if (priv->qos_data.qos_enable)
  90. priv->qos_data.qos_active = 1;
  91. if (!(priv->active_rate & 0xfff0)) {
  92. cw_min = 31;
  93. is_legacy = 1;
  94. }
  95. } else if (priv->iw_mode == IEEE80211_IF_TYPE_AP) {
  96. if (priv->qos_data.qos_enable)
  97. priv->qos_data.qos_active = 1;
  98. } else if (!(priv->staging_rxon.flags & RXON_FLG_SHORT_SLOT_MSK)) {
  99. cw_min = 31;
  100. is_legacy = 1;
  101. }
  102. if (priv->qos_data.qos_active)
  103. aifs = 3;
  104. priv->qos_data.def_qos_parm.ac[0].cw_min = cpu_to_le16(cw_min);
  105. priv->qos_data.def_qos_parm.ac[0].cw_max = cpu_to_le16(cw_max);
  106. priv->qos_data.def_qos_parm.ac[0].aifsn = aifs;
  107. priv->qos_data.def_qos_parm.ac[0].edca_txop = 0;
  108. priv->qos_data.def_qos_parm.ac[0].reserved1 = 0;
  109. if (priv->qos_data.qos_active) {
  110. i = 1;
  111. priv->qos_data.def_qos_parm.ac[i].cw_min = cpu_to_le16(cw_min);
  112. priv->qos_data.def_qos_parm.ac[i].cw_max = cpu_to_le16(cw_max);
  113. priv->qos_data.def_qos_parm.ac[i].aifsn = 7;
  114. priv->qos_data.def_qos_parm.ac[i].edca_txop = 0;
  115. priv->qos_data.def_qos_parm.ac[i].reserved1 = 0;
  116. i = 2;
  117. priv->qos_data.def_qos_parm.ac[i].cw_min =
  118. cpu_to_le16((cw_min + 1) / 2 - 1);
  119. priv->qos_data.def_qos_parm.ac[i].cw_max =
  120. cpu_to_le16(cw_max);
  121. priv->qos_data.def_qos_parm.ac[i].aifsn = 2;
  122. if (is_legacy)
  123. priv->qos_data.def_qos_parm.ac[i].edca_txop =
  124. cpu_to_le16(6016);
  125. else
  126. priv->qos_data.def_qos_parm.ac[i].edca_txop =
  127. cpu_to_le16(3008);
  128. priv->qos_data.def_qos_parm.ac[i].reserved1 = 0;
  129. i = 3;
  130. priv->qos_data.def_qos_parm.ac[i].cw_min =
  131. cpu_to_le16((cw_min + 1) / 4 - 1);
  132. priv->qos_data.def_qos_parm.ac[i].cw_max =
  133. cpu_to_le16((cw_max + 1) / 2 - 1);
  134. priv->qos_data.def_qos_parm.ac[i].aifsn = 2;
  135. priv->qos_data.def_qos_parm.ac[i].reserved1 = 0;
  136. if (is_legacy)
  137. priv->qos_data.def_qos_parm.ac[i].edca_txop =
  138. cpu_to_le16(3264);
  139. else
  140. priv->qos_data.def_qos_parm.ac[i].edca_txop =
  141. cpu_to_le16(1504);
  142. } else {
  143. for (i = 1; i < 4; i++) {
  144. priv->qos_data.def_qos_parm.ac[i].cw_min =
  145. cpu_to_le16(cw_min);
  146. priv->qos_data.def_qos_parm.ac[i].cw_max =
  147. cpu_to_le16(cw_max);
  148. priv->qos_data.def_qos_parm.ac[i].aifsn = aifs;
  149. priv->qos_data.def_qos_parm.ac[i].edca_txop = 0;
  150. priv->qos_data.def_qos_parm.ac[i].reserved1 = 0;
  151. }
  152. }
  153. IWL_DEBUG_QOS("set QoS to default \n");
  154. spin_unlock_irqrestore(&priv->lock, flags);
  155. }
  156. EXPORT_SYMBOL(iwlcore_reset_qos);
  157. /**
  158. * iwlcore_set_rxon_channel - Set the phymode and channel values in staging RXON
  159. * @phymode: MODE_IEEE80211A sets to 5.2GHz; all else set to 2.4GHz
  160. * @channel: Any channel valid for the requested phymode
  161. * In addition to setting the staging RXON, priv->phymode is also set.
  162. *
  163. * NOTE: Does not commit to the hardware; it sets appropriate bit fields
  164. * in the staging RXON flag structure based on the phymode
  165. */
  166. int iwlcore_set_rxon_channel(struct iwl_priv *priv,
  167. enum ieee80211_band band,
  168. u16 channel)
  169. {
  170. if (!iwl_get_channel_info(priv, band, channel)) {
  171. IWL_DEBUG_INFO("Could not set channel to %d [%d]\n",
  172. channel, band);
  173. return -EINVAL;
  174. }
  175. if ((le16_to_cpu(priv->staging_rxon.channel) == channel) &&
  176. (priv->band == band))
  177. return 0;
  178. priv->staging_rxon.channel = cpu_to_le16(channel);
  179. if (band == IEEE80211_BAND_5GHZ)
  180. priv->staging_rxon.flags &= ~RXON_FLG_BAND_24G_MSK;
  181. else
  182. priv->staging_rxon.flags |= RXON_FLG_BAND_24G_MSK;
  183. priv->band = band;
  184. IWL_DEBUG_INFO("Staging channel set to %d [%d]\n", channel, band);
  185. return 0;
  186. }
  187. EXPORT_SYMBOL(iwlcore_set_rxon_channel);
  188. static void iwlcore_init_hw(struct iwl_priv *priv)
  189. {
  190. struct ieee80211_hw *hw = priv->hw;
  191. hw->rate_control_algorithm = "iwl-4965-rs";
  192. /* Tell mac80211 and its clients (e.g. Wireless Extensions)
  193. * the range of signal quality values that we'll provide.
  194. * Negative values for level/noise indicate that we'll provide dBm.
  195. * For WE, at least, non-0 values here *enable* display of values
  196. * in app (iwconfig). */
  197. hw->max_rssi = -20; /* signal level, negative indicates dBm */
  198. hw->max_noise = -20; /* noise level, negative indicates dBm */
  199. hw->max_signal = 100; /* link quality indication (%) */
  200. /* Tell mac80211 our Tx characteristics */
  201. hw->flags = IEEE80211_HW_HOST_GEN_BEACON_TEMPLATE;
  202. /* Default value; 4 EDCA QOS priorities */
  203. hw->queues = 4;
  204. #ifdef CONFIG_IWL4965_HT
  205. /* Enhanced value; more queues, to support 11n aggregation */
  206. hw->queues = 16;
  207. #endif /* CONFIG_IWL4965_HT */
  208. }
  209. int iwl_setup(struct iwl_priv *priv)
  210. {
  211. int ret = 0;
  212. iwlcore_init_hw(priv);
  213. ret = priv->cfg->ops->lib->init_drv(priv);
  214. return ret;
  215. }
  216. EXPORT_SYMBOL(iwl_setup);