nvm.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. /******************************************************************************
  2. *
  3. * This file is provided under a dual BSD/GPLv2 license. When using or
  4. * redistributing this file, you may do so under either license.
  5. *
  6. * GPL LICENSE SUMMARY
  7. *
  8. * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
  9. * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
  10. * Copyright(c) 2016 - 2017 Intel Deutschland GmbH
  11. *
  12. * This program is free software; you can redistribute it and/or modify
  13. * it under the terms of version 2 of the GNU General Public License as
  14. * published by the Free Software Foundation.
  15. *
  16. * This program is distributed in the hope that it will be useful, but
  17. * WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  19. * General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
  24. * USA
  25. *
  26. * The full GNU General Public License is included in this distribution
  27. * in the file called COPYING.
  28. *
  29. * Contact Information:
  30. * Intel Linux Wireless <linuxwifi@intel.com>
  31. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  32. *
  33. * BSD LICENSE
  34. *
  35. * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
  36. * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
  37. * Copyright(c) 2016 - 2017 Intel Deutschland GmbH
  38. * All rights reserved.
  39. *
  40. * Redistribution and use in source and binary forms, with or without
  41. * modification, are permitted provided that the following conditions
  42. * are met:
  43. *
  44. * * Redistributions of source code must retain the above copyright
  45. * notice, this list of conditions and the following disclaimer.
  46. * * Redistributions in binary form must reproduce the above copyright
  47. * notice, this list of conditions and the following disclaimer in
  48. * the documentation and/or other materials provided with the
  49. * distribution.
  50. * * Neither the name Intel Corporation nor the names of its
  51. * contributors may be used to endorse or promote products derived
  52. * from this software without specific prior written permission.
  53. *
  54. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  55. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  56. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  57. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  58. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  59. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  60. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  61. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  62. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  63. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  64. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  65. *
  66. *****************************************************************************/
  67. #include "iwl-drv.h"
  68. #include "runtime.h"
  69. #include "fw/api/nvm-reg.h"
  70. #include "fw/api/commands.h"
  71. #include "iwl-nvm-parse.h"
  72. struct iwl_nvm_data *iwl_fw_get_nvm(struct iwl_fw_runtime *fwrt)
  73. {
  74. struct iwl_nvm_get_info cmd = {};
  75. struct iwl_nvm_get_info_rsp *rsp;
  76. struct iwl_trans *trans = fwrt->trans;
  77. struct iwl_nvm_data *nvm;
  78. struct iwl_host_cmd hcmd = {
  79. .flags = CMD_WANT_SKB | CMD_SEND_IN_RFKILL,
  80. .data = { &cmd, },
  81. .len = { sizeof(cmd) },
  82. .id = WIDE_ID(REGULATORY_AND_NVM_GROUP, NVM_GET_INFO)
  83. };
  84. int ret;
  85. bool lar_fw_supported = !iwlwifi_mod_params.lar_disable &&
  86. fw_has_capa(&fwrt->fw->ucode_capa,
  87. IWL_UCODE_TLV_CAPA_LAR_SUPPORT);
  88. ret = iwl_trans_send_cmd(trans, &hcmd);
  89. if (ret)
  90. return ERR_PTR(ret);
  91. if (WARN(iwl_rx_packet_payload_len(hcmd.resp_pkt) != sizeof(*rsp),
  92. "Invalid payload len in NVM response from FW %d",
  93. iwl_rx_packet_payload_len(hcmd.resp_pkt))) {
  94. ret = -EINVAL;
  95. goto out;
  96. }
  97. rsp = (void *)hcmd.resp_pkt->data;
  98. if (le32_to_cpu(rsp->general.flags) & NVM_GENERAL_FLAGS_EMPTY_OTP)
  99. IWL_INFO(fwrt, "OTP is empty\n");
  100. nvm = kzalloc(sizeof(*nvm) +
  101. sizeof(struct ieee80211_channel) * IWL_NUM_CHANNELS,
  102. GFP_KERNEL);
  103. if (!nvm) {
  104. ret = -ENOMEM;
  105. goto out;
  106. }
  107. iwl_set_hw_address_from_csr(trans, nvm);
  108. /* TODO: if platform NVM has MAC address - override it here */
  109. if (!is_valid_ether_addr(nvm->hw_addr)) {
  110. IWL_ERR(fwrt, "no valid mac address was found\n");
  111. ret = -EINVAL;
  112. goto err_free;
  113. }
  114. IWL_INFO(trans, "base HW address: %pM\n", nvm->hw_addr);
  115. /* Initialize general data */
  116. nvm->nvm_version = le16_to_cpu(rsp->general.nvm_version);
  117. /* Initialize MAC sku data */
  118. nvm->sku_cap_11ac_enable =
  119. le32_to_cpu(rsp->mac_sku.enable_11ac);
  120. nvm->sku_cap_11n_enable =
  121. le32_to_cpu(rsp->mac_sku.enable_11n);
  122. nvm->sku_cap_band_24GHz_enable =
  123. le32_to_cpu(rsp->mac_sku.enable_24g);
  124. nvm->sku_cap_band_52GHz_enable =
  125. le32_to_cpu(rsp->mac_sku.enable_5g);
  126. nvm->sku_cap_mimo_disabled =
  127. le32_to_cpu(rsp->mac_sku.mimo_disable);
  128. /* Initialize PHY sku data */
  129. nvm->valid_tx_ant = (u8)le32_to_cpu(rsp->phy_sku.tx_chains);
  130. nvm->valid_rx_ant = (u8)le32_to_cpu(rsp->phy_sku.rx_chains);
  131. /* Initialize regulatory data */
  132. nvm->lar_enabled =
  133. le32_to_cpu(rsp->regulatory.lar_enabled) && lar_fw_supported;
  134. iwl_init_sbands(trans->dev, trans->cfg, nvm,
  135. rsp->regulatory.channel_profile,
  136. nvm->valid_tx_ant & fwrt->fw->valid_tx_ant,
  137. nvm->valid_rx_ant & fwrt->fw->valid_rx_ant,
  138. nvm->lar_enabled, false);
  139. iwl_free_resp(&hcmd);
  140. return nvm;
  141. err_free:
  142. kfree(nvm);
  143. out:
  144. iwl_free_resp(&hcmd);
  145. return ERR_PTR(ret);
  146. }
  147. IWL_EXPORT_SYMBOL(iwl_fw_get_nvm);