Merge tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost
[cris-mirror.git] / drivers / net / wireless / intel / iwlwifi / fw / nvm.c
blobbd2e1fb43f5a216810f4ed202e15123498145a9a
1 /******************************************************************************
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.
6 * GPL LICENSE SUMMARY
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
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.
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.
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
26 * The full GNU General Public License is included in this distribution
27 * in the file called COPYING.
29 * Contact Information:
30 * Intel Linux Wireless <linuxwifi@intel.com>
31 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
33 * BSD LICENSE
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.
40 * Redistribution and use in source and binary forms, with or without
41 * modification, are permitted provided that the following conditions
42 * are met:
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.
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.
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"
73 struct iwl_nvm_data *iwl_fw_get_nvm(struct iwl_fw_runtime *fwrt)
75 struct iwl_nvm_get_info cmd = {};
76 struct iwl_nvm_get_info_rsp *rsp;
77 struct iwl_trans *trans = fwrt->trans;
78 struct iwl_nvm_data *nvm;
79 struct iwl_host_cmd hcmd = {
80 .flags = CMD_WANT_SKB | CMD_SEND_IN_RFKILL,
81 .data = { &cmd, },
82 .len = { sizeof(cmd) },
83 .id = WIDE_ID(REGULATORY_AND_NVM_GROUP, NVM_GET_INFO)
85 int ret;
86 bool lar_fw_supported = !iwlwifi_mod_params.lar_disable &&
87 fw_has_capa(&fwrt->fw->ucode_capa,
88 IWL_UCODE_TLV_CAPA_LAR_SUPPORT);
90 ret = iwl_trans_send_cmd(trans, &hcmd);
91 if (ret)
92 return ERR_PTR(ret);
94 if (WARN(iwl_rx_packet_payload_len(hcmd.resp_pkt) != sizeof(*rsp),
95 "Invalid payload len in NVM response from FW %d",
96 iwl_rx_packet_payload_len(hcmd.resp_pkt))) {
97 ret = -EINVAL;
98 goto out;
101 rsp = (void *)hcmd.resp_pkt->data;
102 if (le32_to_cpu(rsp->general.flags) & NVM_GENERAL_FLAGS_EMPTY_OTP)
103 IWL_INFO(fwrt, "OTP is empty\n");
105 nvm = kzalloc(sizeof(*nvm) +
106 sizeof(struct ieee80211_channel) * IWL_NUM_CHANNELS,
107 GFP_KERNEL);
108 if (!nvm) {
109 ret = -ENOMEM;
110 goto out;
113 iwl_set_hw_address_from_csr(trans, nvm);
114 /* TODO: if platform NVM has MAC address - override it here */
116 if (!is_valid_ether_addr(nvm->hw_addr)) {
117 IWL_ERR(fwrt, "no valid mac address was found\n");
118 ret = -EINVAL;
119 goto err_free;
122 IWL_INFO(trans, "base HW address: %pM\n", nvm->hw_addr);
124 /* Initialize general data */
125 nvm->nvm_version = le16_to_cpu(rsp->general.nvm_version);
127 /* Initialize MAC sku data */
128 nvm->sku_cap_11ac_enable =
129 le32_to_cpu(rsp->mac_sku.enable_11ac);
130 nvm->sku_cap_11n_enable =
131 le32_to_cpu(rsp->mac_sku.enable_11n);
132 nvm->sku_cap_band_24GHz_enable =
133 le32_to_cpu(rsp->mac_sku.enable_24g);
134 nvm->sku_cap_band_52GHz_enable =
135 le32_to_cpu(rsp->mac_sku.enable_5g);
136 nvm->sku_cap_mimo_disabled =
137 le32_to_cpu(rsp->mac_sku.mimo_disable);
139 /* Initialize PHY sku data */
140 nvm->valid_tx_ant = (u8)le32_to_cpu(rsp->phy_sku.tx_chains);
141 nvm->valid_rx_ant = (u8)le32_to_cpu(rsp->phy_sku.rx_chains);
143 /* Initialize regulatory data */
144 nvm->lar_enabled =
145 le32_to_cpu(rsp->regulatory.lar_enabled) && lar_fw_supported;
147 iwl_init_sbands(trans->dev, trans->cfg, nvm,
148 rsp->regulatory.channel_profile,
149 nvm->valid_tx_ant & fwrt->fw->valid_tx_ant,
150 nvm->valid_rx_ant & fwrt->fw->valid_rx_ant,
151 nvm->lar_enabled, false);
153 iwl_free_resp(&hcmd);
154 return nvm;
156 err_free:
157 kfree(nvm);
158 out:
159 iwl_free_resp(&hcmd);
160 return ERR_PTR(ret);
162 IWL_EXPORT_SYMBOL(iwl_fw_get_nvm);