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.
8 * Copyright (C) 2018 - 2019 Intel Corporation
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of version 2 of the GNU General Public License as
12 * published by the Free Software Foundation.
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program.
22 * The full GNU General Public License is included in this distribution
23 * in the file called COPYING.
25 * Contact Information:
26 * Intel Linux Wireless <linuxwifi@intel.com>
27 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
31 * Copyright (C) 2018 - 2019 Intel Corporation
32 * All rights reserved.
34 * Redistribution and use in source and binary forms, with or without
35 * modification, are permitted provided that the following conditions
38 * * Redistributions of source code must retain the above copyright
39 * notice, this list of conditions and the following disclaimer.
40 * * Redistributions in binary form must reproduce the above copyright
41 * notice, this list of conditions and the following disclaimer in
42 * the documentation and/or other materials provided with the
44 * * Neither the name Intel Corporation nor the names of its
45 * contributors may be used to endorse or promote products derived
46 * from this software without specific prior written permission.
48 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
49 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
50 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
51 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
52 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
53 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
54 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
55 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
56 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
57 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
58 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
60 *****************************************************************************/
62 #include <linux/firmware.h>
64 #include "iwl-trans.h"
65 #include "iwl-dbg-tlv.h"
67 #include "fw/runtime.h"
70 * enum iwl_dbg_tlv_type - debug TLV types
71 * @IWL_DBG_TLV_TYPE_DEBUG_INFO: debug info TLV
72 * @IWL_DBG_TLV_TYPE_BUF_ALLOC: buffer allocation TLV
73 * @IWL_DBG_TLV_TYPE_HCMD: host command TLV
74 * @IWL_DBG_TLV_TYPE_REGION: region TLV
75 * @IWL_DBG_TLV_TYPE_TRIGGER: trigger TLV
76 * @IWL_DBG_TLV_TYPE_NUM: number of debug TLVs
78 enum iwl_dbg_tlv_type {
79 IWL_DBG_TLV_TYPE_DEBUG_INFO =
80 IWL_UCODE_TLV_TYPE_DEBUG_INFO - IWL_UCODE_TLV_DEBUG_BASE,
81 IWL_DBG_TLV_TYPE_BUF_ALLOC,
82 IWL_DBG_TLV_TYPE_HCMD,
83 IWL_DBG_TLV_TYPE_REGION,
84 IWL_DBG_TLV_TYPE_TRIGGER,
89 * struct iwl_dbg_tlv_ver_data - debug TLV version struct
90 * @min_ver: min version supported
91 * @max_ver: max version supported
93 struct iwl_dbg_tlv_ver_data {
98 static const struct iwl_dbg_tlv_ver_data
99 dbg_ver_table[IWL_DBG_TLV_TYPE_NUM] = {
100 [IWL_DBG_TLV_TYPE_DEBUG_INFO] = {.min_ver = 1, .max_ver = 1,},
101 [IWL_DBG_TLV_TYPE_BUF_ALLOC] = {.min_ver = 1, .max_ver = 1,},
102 [IWL_DBG_TLV_TYPE_HCMD] = {.min_ver = 1, .max_ver = 1,},
103 [IWL_DBG_TLV_TYPE_REGION] = {.min_ver = 1, .max_ver = 1,},
104 [IWL_DBG_TLV_TYPE_TRIGGER] = {.min_ver = 1, .max_ver = 1,},
107 static bool iwl_dbg_tlv_ver_support(struct iwl_ucode_tlv *tlv)
109 struct iwl_fw_ini_header *hdr = (void *)&tlv->data[0];
110 u32 type = le32_to_cpu(tlv->type);
111 u32 tlv_idx = type - IWL_UCODE_TLV_DEBUG_BASE;
112 u32 ver = le32_to_cpu(hdr->tlv_version);
114 if (ver < dbg_ver_table[tlv_idx].min_ver ||
115 ver > dbg_ver_table[tlv_idx].max_ver)
121 void iwl_dbg_tlv_alloc(struct iwl_trans *trans, struct iwl_ucode_tlv *tlv,
124 struct iwl_fw_ini_header *hdr = (void *)&tlv->data[0];
125 u32 type = le32_to_cpu(tlv->type);
126 u32 pnt = le32_to_cpu(hdr->apply_point);
127 u32 tlv_idx = type - IWL_UCODE_TLV_DEBUG_BASE;
128 enum iwl_ini_cfg_state *cfg_state = ext ?
129 &trans->dbg.external_ini_cfg : &trans->dbg.internal_ini_cfg;
131 IWL_DEBUG_FW(trans, "WRT: read TLV 0x%x, apply point %d\n",
134 if (tlv_idx >= IWL_DBG_TLV_TYPE_NUM) {
135 IWL_ERR(trans, "WRT: Unsupported TLV 0x%x\n", type);
139 if (!iwl_dbg_tlv_ver_support(tlv)) {
140 IWL_ERR(trans, "WRT: Unsupported TLV 0x%x version %u\n", type,
141 le32_to_cpu(hdr->tlv_version));
145 if (*cfg_state == IWL_INI_CFG_STATE_NOT_LOADED)
146 *cfg_state = IWL_INI_CFG_STATE_LOADED;
151 *cfg_state = IWL_INI_CFG_STATE_CORRUPTED;
154 void iwl_dbg_tlv_del_timers(struct iwl_trans *trans)
156 /* will be used later */
158 IWL_EXPORT_SYMBOL(iwl_dbg_tlv_del_timers);
160 void iwl_dbg_tlv_free(struct iwl_trans *trans)
162 /* will be used again later */
165 static int iwl_dbg_tlv_parse_bin(struct iwl_trans *trans, const u8 *data,
168 struct iwl_ucode_tlv *tlv;
171 while (len >= sizeof(*tlv)) {
175 tlv_len = le32_to_cpu(tlv->length);
178 IWL_ERR(trans, "invalid TLV len: %zd/%u\n",
182 len -= ALIGN(tlv_len, 4);
183 data += sizeof(*tlv) + ALIGN(tlv_len, 4);
185 iwl_dbg_tlv_alloc(trans, tlv, true);
191 void iwl_dbg_tlv_load_bin(struct device *dev, struct iwl_trans *trans)
193 const struct firmware *fw;
196 if (!iwlwifi_mod_params.enable_ini)
199 res = request_firmware(&fw, "iwl-dbg-tlv.ini", dev);
203 iwl_dbg_tlv_parse_bin(trans, fw->data, fw->size);
205 release_firmware(fw);
208 void iwl_dbg_tlv_time_point(struct iwl_fw_runtime *fwrt,
209 enum iwl_fw_ini_time_point tp_id,
210 union iwl_dbg_tlv_tp_data *tp_data)
212 /* will be used later */
214 IWL_EXPORT_SYMBOL(iwl_dbg_tlv_time_point);