1*4882a593Smuzhiyun /******************************************************************************
2*4882a593Smuzhiyun *
3*4882a593Smuzhiyun * This file is provided under a dual BSD/GPLv2 license. When using or
4*4882a593Smuzhiyun * redistributing this file, you may do so under either license.
5*4882a593Smuzhiyun *
6*4882a593Smuzhiyun * GPL LICENSE SUMMARY
7*4882a593Smuzhiyun *
8*4882a593Smuzhiyun * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
9*4882a593Smuzhiyun * Copyright(c) 2016 Intel Deutschland GmbH
10*4882a593Smuzhiyun * Copyright(c) 2008 - 2014, 2018 - 2020 Intel Corporation
11*4882a593Smuzhiyun *
12*4882a593Smuzhiyun * This program is free software; you can redistribute it and/or modify
13*4882a593Smuzhiyun * it under the terms of version 2 of the GNU General Public License as
14*4882a593Smuzhiyun * published by the Free Software Foundation.
15*4882a593Smuzhiyun *
16*4882a593Smuzhiyun * This program is distributed in the hope that it will be useful, but
17*4882a593Smuzhiyun * WITHOUT ANY WARRANTY; without even the implied warranty of
18*4882a593Smuzhiyun * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19*4882a593Smuzhiyun * General Public License for more details.
20*4882a593Smuzhiyun *
21*4882a593Smuzhiyun * The full GNU General Public License is included in this distribution
22*4882a593Smuzhiyun * in the file called COPYING.
23*4882a593Smuzhiyun *
24*4882a593Smuzhiyun * Contact Information:
25*4882a593Smuzhiyun * Intel Linux Wireless <linuxwifi@intel.com>
26*4882a593Smuzhiyun * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27*4882a593Smuzhiyun *
28*4882a593Smuzhiyun * BSD LICENSE
29*4882a593Smuzhiyun *
30*4882a593Smuzhiyun * Copyright(c) 2005 - 2014 Intel Corporation. All rights reserved.
31*4882a593Smuzhiyun * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
32*4882a593Smuzhiyun * Copyright(c) 2016 Intel Deutschland GmbH
33*4882a593Smuzhiyun * Copyright(c) 2008 - 2014, 2018 - 2020 Intel Corporation
34*4882a593Smuzhiyun * All rights reserved.
35*4882a593Smuzhiyun *
36*4882a593Smuzhiyun * Redistribution and use in source and binary forms, with or without
37*4882a593Smuzhiyun * modification, are permitted provided that the following conditions
38*4882a593Smuzhiyun * are met:
39*4882a593Smuzhiyun *
40*4882a593Smuzhiyun * * Redistributions of source code must retain the above copyright
41*4882a593Smuzhiyun * notice, this list of conditions and the following disclaimer.
42*4882a593Smuzhiyun * * Redistributions in binary form must reproduce the above copyright
43*4882a593Smuzhiyun * notice, this list of conditions and the following disclaimer in
44*4882a593Smuzhiyun * the documentation and/or other materials provided with the
45*4882a593Smuzhiyun * distribution.
46*4882a593Smuzhiyun * * Neither the name Intel Corporation nor the names of its
47*4882a593Smuzhiyun * contributors may be used to endorse or promote products derived
48*4882a593Smuzhiyun * from this software without specific prior written permission.
49*4882a593Smuzhiyun *
50*4882a593Smuzhiyun * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
51*4882a593Smuzhiyun * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
52*4882a593Smuzhiyun * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
53*4882a593Smuzhiyun * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
54*4882a593Smuzhiyun * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
55*4882a593Smuzhiyun * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
56*4882a593Smuzhiyun * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
57*4882a593Smuzhiyun * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
58*4882a593Smuzhiyun * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
59*4882a593Smuzhiyun * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
60*4882a593Smuzhiyun * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
61*4882a593Smuzhiyun *****************************************************************************/
62*4882a593Smuzhiyun
63*4882a593Smuzhiyun #ifndef __iwl_fw_img_h__
64*4882a593Smuzhiyun #define __iwl_fw_img_h__
65*4882a593Smuzhiyun #include <linux/types.h>
66*4882a593Smuzhiyun
67*4882a593Smuzhiyun #include "api/dbg-tlv.h"
68*4882a593Smuzhiyun
69*4882a593Smuzhiyun #include "file.h"
70*4882a593Smuzhiyun #include "error-dump.h"
71*4882a593Smuzhiyun
72*4882a593Smuzhiyun /**
73*4882a593Smuzhiyun * enum iwl_ucode_type
74*4882a593Smuzhiyun *
75*4882a593Smuzhiyun * The type of ucode.
76*4882a593Smuzhiyun *
77*4882a593Smuzhiyun * @IWL_UCODE_REGULAR: Normal runtime ucode
78*4882a593Smuzhiyun * @IWL_UCODE_INIT: Initial ucode
79*4882a593Smuzhiyun * @IWL_UCODE_WOWLAN: Wake on Wireless enabled ucode
80*4882a593Smuzhiyun * @IWL_UCODE_REGULAR_USNIFFER: Normal runtime ucode when using usniffer image
81*4882a593Smuzhiyun */
82*4882a593Smuzhiyun enum iwl_ucode_type {
83*4882a593Smuzhiyun IWL_UCODE_REGULAR,
84*4882a593Smuzhiyun IWL_UCODE_INIT,
85*4882a593Smuzhiyun IWL_UCODE_WOWLAN,
86*4882a593Smuzhiyun IWL_UCODE_REGULAR_USNIFFER,
87*4882a593Smuzhiyun IWL_UCODE_TYPE_MAX,
88*4882a593Smuzhiyun };
89*4882a593Smuzhiyun
90*4882a593Smuzhiyun /*
91*4882a593Smuzhiyun * enumeration of ucode section.
92*4882a593Smuzhiyun * This enumeration is used directly for older firmware (before 16.0).
93*4882a593Smuzhiyun * For new firmware, there can be up to 4 sections (see below) but the
94*4882a593Smuzhiyun * first one packaged into the firmware file is the DATA section and
95*4882a593Smuzhiyun * some debugging code accesses that.
96*4882a593Smuzhiyun */
97*4882a593Smuzhiyun enum iwl_ucode_sec {
98*4882a593Smuzhiyun IWL_UCODE_SECTION_DATA,
99*4882a593Smuzhiyun IWL_UCODE_SECTION_INST,
100*4882a593Smuzhiyun };
101*4882a593Smuzhiyun
102*4882a593Smuzhiyun struct iwl_ucode_capabilities {
103*4882a593Smuzhiyun u32 max_probe_length;
104*4882a593Smuzhiyun u32 n_scan_channels;
105*4882a593Smuzhiyun u32 standard_phy_calibration_size;
106*4882a593Smuzhiyun u32 flags;
107*4882a593Smuzhiyun u32 error_log_addr;
108*4882a593Smuzhiyun u32 error_log_size;
109*4882a593Smuzhiyun u32 num_stations;
110*4882a593Smuzhiyun unsigned long _api[BITS_TO_LONGS(NUM_IWL_UCODE_TLV_API)];
111*4882a593Smuzhiyun unsigned long _capa[BITS_TO_LONGS(NUM_IWL_UCODE_TLV_CAPA)];
112*4882a593Smuzhiyun
113*4882a593Smuzhiyun const struct iwl_fw_cmd_version *cmd_versions;
114*4882a593Smuzhiyun u32 n_cmd_versions;
115*4882a593Smuzhiyun };
116*4882a593Smuzhiyun
117*4882a593Smuzhiyun static inline bool
fw_has_api(const struct iwl_ucode_capabilities * capabilities,iwl_ucode_tlv_api_t api)118*4882a593Smuzhiyun fw_has_api(const struct iwl_ucode_capabilities *capabilities,
119*4882a593Smuzhiyun iwl_ucode_tlv_api_t api)
120*4882a593Smuzhiyun {
121*4882a593Smuzhiyun return test_bit((__force long)api, capabilities->_api);
122*4882a593Smuzhiyun }
123*4882a593Smuzhiyun
124*4882a593Smuzhiyun static inline bool
fw_has_capa(const struct iwl_ucode_capabilities * capabilities,iwl_ucode_tlv_capa_t capa)125*4882a593Smuzhiyun fw_has_capa(const struct iwl_ucode_capabilities *capabilities,
126*4882a593Smuzhiyun iwl_ucode_tlv_capa_t capa)
127*4882a593Smuzhiyun {
128*4882a593Smuzhiyun return test_bit((__force long)capa, capabilities->_capa);
129*4882a593Smuzhiyun }
130*4882a593Smuzhiyun
131*4882a593Smuzhiyun /* one for each uCode image (inst/data, init/runtime/wowlan) */
132*4882a593Smuzhiyun struct fw_desc {
133*4882a593Smuzhiyun const void *data; /* vmalloc'ed data */
134*4882a593Smuzhiyun u32 len; /* size in bytes */
135*4882a593Smuzhiyun u32 offset; /* offset in the device */
136*4882a593Smuzhiyun };
137*4882a593Smuzhiyun
138*4882a593Smuzhiyun struct fw_img {
139*4882a593Smuzhiyun struct fw_desc *sec;
140*4882a593Smuzhiyun int num_sec;
141*4882a593Smuzhiyun bool is_dual_cpus;
142*4882a593Smuzhiyun u32 paging_mem_size;
143*4882a593Smuzhiyun };
144*4882a593Smuzhiyun
145*4882a593Smuzhiyun /*
146*4882a593Smuzhiyun * Block paging calculations
147*4882a593Smuzhiyun */
148*4882a593Smuzhiyun #define PAGE_2_EXP_SIZE 12 /* 4K == 2^12 */
149*4882a593Smuzhiyun #define FW_PAGING_SIZE BIT(PAGE_2_EXP_SIZE) /* page size is 4KB */
150*4882a593Smuzhiyun #define PAGE_PER_GROUP_2_EXP_SIZE 3
151*4882a593Smuzhiyun /* 8 pages per group */
152*4882a593Smuzhiyun #define NUM_OF_PAGE_PER_GROUP BIT(PAGE_PER_GROUP_2_EXP_SIZE)
153*4882a593Smuzhiyun /* don't change, support only 32KB size */
154*4882a593Smuzhiyun #define PAGING_BLOCK_SIZE (NUM_OF_PAGE_PER_GROUP * FW_PAGING_SIZE)
155*4882a593Smuzhiyun /* 32K == 2^15 */
156*4882a593Smuzhiyun #define BLOCK_2_EXP_SIZE (PAGE_2_EXP_SIZE + PAGE_PER_GROUP_2_EXP_SIZE)
157*4882a593Smuzhiyun
158*4882a593Smuzhiyun /*
159*4882a593Smuzhiyun * Image paging calculations
160*4882a593Smuzhiyun */
161*4882a593Smuzhiyun #define BLOCK_PER_IMAGE_2_EXP_SIZE 5
162*4882a593Smuzhiyun /* 2^5 == 32 blocks per image */
163*4882a593Smuzhiyun #define NUM_OF_BLOCK_PER_IMAGE BIT(BLOCK_PER_IMAGE_2_EXP_SIZE)
164*4882a593Smuzhiyun /* maximum image size 1024KB */
165*4882a593Smuzhiyun #define MAX_PAGING_IMAGE_SIZE (NUM_OF_BLOCK_PER_IMAGE * PAGING_BLOCK_SIZE)
166*4882a593Smuzhiyun
167*4882a593Smuzhiyun /* Virtual address signature */
168*4882a593Smuzhiyun #define PAGING_ADDR_SIG 0xAA000000
169*4882a593Smuzhiyun
170*4882a593Smuzhiyun #define PAGING_CMD_IS_SECURED BIT(9)
171*4882a593Smuzhiyun #define PAGING_CMD_IS_ENABLED BIT(8)
172*4882a593Smuzhiyun #define PAGING_CMD_NUM_OF_PAGES_IN_LAST_GRP_POS 0
173*4882a593Smuzhiyun #define PAGING_TLV_SECURE_MASK 1
174*4882a593Smuzhiyun
175*4882a593Smuzhiyun /**
176*4882a593Smuzhiyun * struct iwl_fw_paging
177*4882a593Smuzhiyun * @fw_paging_phys: page phy pointer
178*4882a593Smuzhiyun * @fw_paging_block: pointer to the allocated block
179*4882a593Smuzhiyun * @fw_paging_size: page size
180*4882a593Smuzhiyun */
181*4882a593Smuzhiyun struct iwl_fw_paging {
182*4882a593Smuzhiyun dma_addr_t fw_paging_phys;
183*4882a593Smuzhiyun struct page *fw_paging_block;
184*4882a593Smuzhiyun u32 fw_paging_size;
185*4882a593Smuzhiyun };
186*4882a593Smuzhiyun
187*4882a593Smuzhiyun /**
188*4882a593Smuzhiyun * struct iwl_fw_cscheme_list - a cipher scheme list
189*4882a593Smuzhiyun * @size: a number of entries
190*4882a593Smuzhiyun * @cs: cipher scheme entries
191*4882a593Smuzhiyun */
192*4882a593Smuzhiyun struct iwl_fw_cscheme_list {
193*4882a593Smuzhiyun u8 size;
194*4882a593Smuzhiyun struct iwl_fw_cipher_scheme cs[];
195*4882a593Smuzhiyun } __packed;
196*4882a593Smuzhiyun
197*4882a593Smuzhiyun /**
198*4882a593Smuzhiyun * enum iwl_fw_type - iwlwifi firmware type
199*4882a593Smuzhiyun * @IWL_FW_DVM: DVM firmware
200*4882a593Smuzhiyun * @IWL_FW_MVM: MVM firmware
201*4882a593Smuzhiyun */
202*4882a593Smuzhiyun enum iwl_fw_type {
203*4882a593Smuzhiyun IWL_FW_DVM,
204*4882a593Smuzhiyun IWL_FW_MVM,
205*4882a593Smuzhiyun };
206*4882a593Smuzhiyun
207*4882a593Smuzhiyun /**
208*4882a593Smuzhiyun * struct iwl_fw_dbg - debug data
209*4882a593Smuzhiyun *
210*4882a593Smuzhiyun * @dest_tlv: points to debug destination TLV (typically SRAM or DRAM)
211*4882a593Smuzhiyun * @n_dest_reg: num of reg_ops in dest_tlv
212*4882a593Smuzhiyun * @conf_tlv: array of pointers to configuration HCMDs
213*4882a593Smuzhiyun * @trigger_tlv: array of pointers to triggers TLVs
214*4882a593Smuzhiyun * @trigger_tlv_len: lengths of the @dbg_trigger_tlv entries
215*4882a593Smuzhiyun * @mem_tlv: Runtime addresses to dump
216*4882a593Smuzhiyun * @n_mem_tlv: number of runtime addresses
217*4882a593Smuzhiyun * @dump_mask: bitmask of dump regions
218*4882a593Smuzhiyun */
219*4882a593Smuzhiyun struct iwl_fw_dbg {
220*4882a593Smuzhiyun struct iwl_fw_dbg_dest_tlv_v1 *dest_tlv;
221*4882a593Smuzhiyun u8 n_dest_reg;
222*4882a593Smuzhiyun struct iwl_fw_dbg_conf_tlv *conf_tlv[FW_DBG_CONF_MAX];
223*4882a593Smuzhiyun struct iwl_fw_dbg_trigger_tlv *trigger_tlv[FW_DBG_TRIGGER_MAX];
224*4882a593Smuzhiyun size_t trigger_tlv_len[FW_DBG_TRIGGER_MAX];
225*4882a593Smuzhiyun struct iwl_fw_dbg_mem_seg_tlv *mem_tlv;
226*4882a593Smuzhiyun size_t n_mem_tlv;
227*4882a593Smuzhiyun u32 dump_mask;
228*4882a593Smuzhiyun };
229*4882a593Smuzhiyun
230*4882a593Smuzhiyun /**
231*4882a593Smuzhiyun * struct iwl_fw - variables associated with the firmware
232*4882a593Smuzhiyun *
233*4882a593Smuzhiyun * @ucode_ver: ucode version from the ucode file
234*4882a593Smuzhiyun * @fw_version: firmware version string
235*4882a593Smuzhiyun * @img: ucode image like ucode_rt, ucode_init, ucode_wowlan.
236*4882a593Smuzhiyun * @iml_len: length of the image loader image
237*4882a593Smuzhiyun * @iml: image loader fw image
238*4882a593Smuzhiyun * @ucode_capa: capabilities parsed from the ucode file.
239*4882a593Smuzhiyun * @enhance_sensitivity_table: device can do enhanced sensitivity.
240*4882a593Smuzhiyun * @init_evtlog_ptr: event log offset for init ucode.
241*4882a593Smuzhiyun * @init_evtlog_size: event log size for init ucode.
242*4882a593Smuzhiyun * @init_errlog_ptr: error log offfset for init ucode.
243*4882a593Smuzhiyun * @inst_evtlog_ptr: event log offset for runtime ucode.
244*4882a593Smuzhiyun * @inst_evtlog_size: event log size for runtime ucode.
245*4882a593Smuzhiyun * @inst_errlog_ptr: error log offfset for runtime ucode.
246*4882a593Smuzhiyun * @type: firmware type (&enum iwl_fw_type)
247*4882a593Smuzhiyun * @cipher_scheme: optional external cipher scheme.
248*4882a593Smuzhiyun * @human_readable: human readable version
249*4882a593Smuzhiyun * we get the ALIVE from the uCode
250*4882a593Smuzhiyun */
251*4882a593Smuzhiyun struct iwl_fw {
252*4882a593Smuzhiyun u32 ucode_ver;
253*4882a593Smuzhiyun
254*4882a593Smuzhiyun char fw_version[64];
255*4882a593Smuzhiyun
256*4882a593Smuzhiyun /* ucode images */
257*4882a593Smuzhiyun struct fw_img img[IWL_UCODE_TYPE_MAX];
258*4882a593Smuzhiyun size_t iml_len;
259*4882a593Smuzhiyun u8 *iml;
260*4882a593Smuzhiyun
261*4882a593Smuzhiyun struct iwl_ucode_capabilities ucode_capa;
262*4882a593Smuzhiyun bool enhance_sensitivity_table;
263*4882a593Smuzhiyun
264*4882a593Smuzhiyun u32 init_evtlog_ptr, init_evtlog_size, init_errlog_ptr;
265*4882a593Smuzhiyun u32 inst_evtlog_ptr, inst_evtlog_size, inst_errlog_ptr;
266*4882a593Smuzhiyun
267*4882a593Smuzhiyun struct iwl_tlv_calib_ctrl default_calib[IWL_UCODE_TYPE_MAX];
268*4882a593Smuzhiyun u32 phy_config;
269*4882a593Smuzhiyun u8 valid_tx_ant;
270*4882a593Smuzhiyun u8 valid_rx_ant;
271*4882a593Smuzhiyun
272*4882a593Smuzhiyun enum iwl_fw_type type;
273*4882a593Smuzhiyun
274*4882a593Smuzhiyun struct iwl_fw_cipher_scheme cs[IWL_UCODE_MAX_CS];
275*4882a593Smuzhiyun u8 human_readable[FW_VER_HUMAN_READABLE_SZ];
276*4882a593Smuzhiyun
277*4882a593Smuzhiyun struct iwl_fw_dbg dbg;
278*4882a593Smuzhiyun };
279*4882a593Smuzhiyun
get_fw_dbg_mode_string(int mode)280*4882a593Smuzhiyun static inline const char *get_fw_dbg_mode_string(int mode)
281*4882a593Smuzhiyun {
282*4882a593Smuzhiyun switch (mode) {
283*4882a593Smuzhiyun case SMEM_MODE:
284*4882a593Smuzhiyun return "SMEM";
285*4882a593Smuzhiyun case EXTERNAL_MODE:
286*4882a593Smuzhiyun return "EXTERNAL_DRAM";
287*4882a593Smuzhiyun case MARBH_MODE:
288*4882a593Smuzhiyun return "MARBH";
289*4882a593Smuzhiyun case MIPI_MODE:
290*4882a593Smuzhiyun return "MIPI";
291*4882a593Smuzhiyun default:
292*4882a593Smuzhiyun return "UNKNOWN";
293*4882a593Smuzhiyun }
294*4882a593Smuzhiyun }
295*4882a593Smuzhiyun
296*4882a593Smuzhiyun static inline bool
iwl_fw_dbg_conf_usniffer(const struct iwl_fw * fw,u8 id)297*4882a593Smuzhiyun iwl_fw_dbg_conf_usniffer(const struct iwl_fw *fw, u8 id)
298*4882a593Smuzhiyun {
299*4882a593Smuzhiyun const struct iwl_fw_dbg_conf_tlv *conf_tlv = fw->dbg.conf_tlv[id];
300*4882a593Smuzhiyun
301*4882a593Smuzhiyun if (!conf_tlv)
302*4882a593Smuzhiyun return false;
303*4882a593Smuzhiyun
304*4882a593Smuzhiyun return conf_tlv->usniffer;
305*4882a593Smuzhiyun }
306*4882a593Smuzhiyun
307*4882a593Smuzhiyun static inline const struct fw_img *
iwl_get_ucode_image(const struct iwl_fw * fw,enum iwl_ucode_type ucode_type)308*4882a593Smuzhiyun iwl_get_ucode_image(const struct iwl_fw *fw, enum iwl_ucode_type ucode_type)
309*4882a593Smuzhiyun {
310*4882a593Smuzhiyun if (ucode_type >= IWL_UCODE_TYPE_MAX)
311*4882a593Smuzhiyun return NULL;
312*4882a593Smuzhiyun
313*4882a593Smuzhiyun return &fw->img[ucode_type];
314*4882a593Smuzhiyun }
315*4882a593Smuzhiyun
316*4882a593Smuzhiyun u8 iwl_fw_lookup_cmd_ver(const struct iwl_fw *fw, u8 grp, u8 cmd, u8 def);
317*4882a593Smuzhiyun
318*4882a593Smuzhiyun u8 iwl_fw_lookup_notif_ver(const struct iwl_fw *fw, u8 grp, u8 cmd, u8 def);
319*4882a593Smuzhiyun const char *iwl_fw_lookup_assert_desc(u32 num);
320*4882a593Smuzhiyun #endif /* __iwl_fw_img_h__ */
321