iwl-agn-hcmd.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. /******************************************************************************
  2. *
  3. * GPL LICENSE SUMMARY
  4. *
  5. * Copyright(c) 2008 - 2011 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. * Intel Linux Wireless <ilw@linux.intel.com>
  26. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  27. *
  28. *****************************************************************************/
  29. #include <linux/kernel.h>
  30. #include <linux/module.h>
  31. #include <linux/init.h>
  32. #include <linux/sched.h>
  33. #include "iwl-dev.h"
  34. #include "iwl-core.h"
  35. #include "iwl-io.h"
  36. #include "iwl-agn.h"
  37. #include "iwl-trans.h"
  38. int iwlagn_send_tx_ant_config(struct iwl_priv *priv, u8 valid_tx_ant)
  39. {
  40. struct iwl_tx_ant_config_cmd tx_ant_cmd = {
  41. .valid = cpu_to_le32(valid_tx_ant),
  42. };
  43. if (IWL_UCODE_API(priv->ucode_ver) > 1) {
  44. IWL_DEBUG_HC(priv, "select valid tx ant: %u\n", valid_tx_ant);
  45. return trans_send_cmd_pdu(priv,
  46. TX_ANT_CONFIGURATION_CMD,
  47. CMD_SYNC,
  48. sizeof(struct iwl_tx_ant_config_cmd),
  49. &tx_ant_cmd);
  50. } else {
  51. IWL_DEBUG_HC(priv, "TX_ANT_CONFIGURATION_CMD not supported\n");
  52. return -EOPNOTSUPP;
  53. }
  54. }
  55. void iwlagn_gain_computation(struct iwl_priv *priv,
  56. u32 average_noise[NUM_RX_CHAINS],
  57. u16 min_average_noise_antenna_i,
  58. u32 min_average_noise,
  59. u8 default_chain)
  60. {
  61. int i;
  62. s32 delta_g;
  63. struct iwl_chain_noise_data *data = &priv->chain_noise_data;
  64. /*
  65. * Find Gain Code for the chains based on "default chain"
  66. */
  67. for (i = default_chain + 1; i < NUM_RX_CHAINS; i++) {
  68. if ((data->disconn_array[i])) {
  69. data->delta_gain_code[i] = 0;
  70. continue;
  71. }
  72. delta_g = (priv->cfg->base_params->chain_noise_scale *
  73. ((s32)average_noise[default_chain] -
  74. (s32)average_noise[i])) / 1500;
  75. /* bound gain by 2 bits value max, 3rd bit is sign */
  76. data->delta_gain_code[i] =
  77. min(abs(delta_g), (long) CHAIN_NOISE_MAX_DELTA_GAIN_CODE);
  78. if (delta_g < 0)
  79. /*
  80. * set negative sign ...
  81. * note to Intel developers: This is uCode API format,
  82. * not the format of any internal device registers.
  83. * Do not change this format for e.g. 6050 or similar
  84. * devices. Change format only if more resolution
  85. * (i.e. more than 2 bits magnitude) is needed.
  86. */
  87. data->delta_gain_code[i] |= (1 << 2);
  88. }
  89. IWL_DEBUG_CALIB(priv, "Delta gains: ANT_B = %d ANT_C = %d\n",
  90. data->delta_gain_code[1], data->delta_gain_code[2]);
  91. if (!data->radio_write) {
  92. struct iwl_calib_chain_noise_gain_cmd cmd;
  93. memset(&cmd, 0, sizeof(cmd));
  94. iwl_set_calib_hdr(&cmd.hdr,
  95. priv->_agn.phy_calib_chain_noise_gain_cmd);
  96. cmd.delta_gain_1 = data->delta_gain_code[1];
  97. cmd.delta_gain_2 = data->delta_gain_code[2];
  98. trans_send_cmd_pdu(priv, REPLY_PHY_CALIBRATION_CMD,
  99. CMD_ASYNC, sizeof(cmd), &cmd);
  100. data->radio_write = 1;
  101. data->state = IWL_CHAIN_NOISE_CALIBRATED;
  102. }
  103. }
  104. int iwlagn_set_pan_params(struct iwl_priv *priv)
  105. {
  106. struct iwl_wipan_params_cmd cmd;
  107. struct iwl_rxon_context *ctx_bss, *ctx_pan;
  108. int slot0 = 300, slot1 = 0;
  109. int ret;
  110. if (priv->valid_contexts == BIT(IWL_RXON_CTX_BSS))
  111. return 0;
  112. BUILD_BUG_ON(NUM_IWL_RXON_CTX != 2);
  113. lockdep_assert_held(&priv->mutex);
  114. ctx_bss = &priv->contexts[IWL_RXON_CTX_BSS];
  115. ctx_pan = &priv->contexts[IWL_RXON_CTX_PAN];
  116. /*
  117. * If the PAN context is inactive, then we don't need
  118. * to update the PAN parameters, the last thing we'll
  119. * have done before it goes inactive is making the PAN
  120. * parameters be WLAN-only.
  121. */
  122. if (!ctx_pan->is_active)
  123. return 0;
  124. memset(&cmd, 0, sizeof(cmd));
  125. /* only 2 slots are currently allowed */
  126. cmd.num_slots = 2;
  127. cmd.slots[0].type = 0; /* BSS */
  128. cmd.slots[1].type = 1; /* PAN */
  129. if (priv->_agn.hw_roc_channel) {
  130. /* both contexts must be used for this to happen */
  131. slot1 = priv->_agn.hw_roc_duration;
  132. slot0 = IWL_MIN_SLOT_TIME;
  133. } else if (ctx_bss->vif && ctx_pan->vif) {
  134. int bcnint = ctx_pan->vif->bss_conf.beacon_int;
  135. int dtim = ctx_pan->vif->bss_conf.dtim_period ?: 1;
  136. /* should be set, but seems unused?? */
  137. cmd.flags |= cpu_to_le16(IWL_WIPAN_PARAMS_FLG_SLOTTED_MODE);
  138. if (ctx_pan->vif->type == NL80211_IFTYPE_AP &&
  139. bcnint &&
  140. bcnint != ctx_bss->vif->bss_conf.beacon_int) {
  141. IWL_ERR(priv,
  142. "beacon intervals don't match (%d, %d)\n",
  143. ctx_bss->vif->bss_conf.beacon_int,
  144. ctx_pan->vif->bss_conf.beacon_int);
  145. } else
  146. bcnint = max_t(int, bcnint,
  147. ctx_bss->vif->bss_conf.beacon_int);
  148. if (!bcnint)
  149. bcnint = DEFAULT_BEACON_INTERVAL;
  150. slot0 = bcnint / 2;
  151. slot1 = bcnint - slot0;
  152. if (test_bit(STATUS_SCAN_HW, &priv->status) ||
  153. (!ctx_bss->vif->bss_conf.idle &&
  154. !ctx_bss->vif->bss_conf.assoc)) {
  155. slot0 = dtim * bcnint * 3 - IWL_MIN_SLOT_TIME;
  156. slot1 = IWL_MIN_SLOT_TIME;
  157. } else if (!ctx_pan->vif->bss_conf.idle &&
  158. !ctx_pan->vif->bss_conf.assoc) {
  159. slot1 = bcnint * 3 - IWL_MIN_SLOT_TIME;
  160. slot0 = IWL_MIN_SLOT_TIME;
  161. }
  162. } else if (ctx_pan->vif) {
  163. slot0 = 0;
  164. slot1 = max_t(int, 1, ctx_pan->vif->bss_conf.dtim_period) *
  165. ctx_pan->vif->bss_conf.beacon_int;
  166. slot1 = max_t(int, DEFAULT_BEACON_INTERVAL, slot1);
  167. if (test_bit(STATUS_SCAN_HW, &priv->status)) {
  168. slot0 = slot1 * 3 - IWL_MIN_SLOT_TIME;
  169. slot1 = IWL_MIN_SLOT_TIME;
  170. }
  171. }
  172. cmd.slots[0].width = cpu_to_le16(slot0);
  173. cmd.slots[1].width = cpu_to_le16(slot1);
  174. ret = trans_send_cmd_pdu(priv, REPLY_WIPAN_PARAMS, CMD_SYNC,
  175. sizeof(cmd), &cmd);
  176. if (ret)
  177. IWL_ERR(priv, "Error setting PAN parameters (%d)\n", ret);
  178. return ret;
  179. }