iwl-core.c 8.2 KB

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