Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */
0002 /*
0003  * Copyright (C) 2005-2014, 2018-2021 Intel Corporation
0004  * Copyright (C) 2013-2015 Intel Mobile Communications GmbH
0005  * Copyright (C) 2016 Intel Deutschland GmbH
0006  */
0007 #ifndef __iwl_fw_img_h__
0008 #define __iwl_fw_img_h__
0009 #include <linux/types.h>
0010 
0011 #include "api/dbg-tlv.h"
0012 
0013 #include "file.h"
0014 #include "error-dump.h"
0015 
0016 /**
0017  * enum iwl_ucode_type
0018  *
0019  * The type of ucode.
0020  *
0021  * @IWL_UCODE_REGULAR: Normal runtime ucode
0022  * @IWL_UCODE_INIT: Initial ucode
0023  * @IWL_UCODE_WOWLAN: Wake on Wireless enabled ucode
0024  * @IWL_UCODE_REGULAR_USNIFFER: Normal runtime ucode when using usniffer image
0025  */
0026 enum iwl_ucode_type {
0027     IWL_UCODE_REGULAR,
0028     IWL_UCODE_INIT,
0029     IWL_UCODE_WOWLAN,
0030     IWL_UCODE_REGULAR_USNIFFER,
0031     IWL_UCODE_TYPE_MAX,
0032 };
0033 
0034 /*
0035  * enumeration of ucode section.
0036  * This enumeration is used directly for older firmware (before 16.0).
0037  * For new firmware, there can be up to 4 sections (see below) but the
0038  * first one packaged into the firmware file is the DATA section and
0039  * some debugging code accesses that.
0040  */
0041 enum iwl_ucode_sec {
0042     IWL_UCODE_SECTION_DATA,
0043     IWL_UCODE_SECTION_INST,
0044 };
0045 
0046 struct iwl_ucode_capabilities {
0047     u32 max_probe_length;
0048     u32 n_scan_channels;
0049     u32 standard_phy_calibration_size;
0050     u32 flags;
0051     u32 error_log_addr;
0052     u32 error_log_size;
0053     u32 num_stations;
0054     unsigned long _api[BITS_TO_LONGS(NUM_IWL_UCODE_TLV_API)];
0055     unsigned long _capa[BITS_TO_LONGS(NUM_IWL_UCODE_TLV_CAPA)];
0056 
0057     const struct iwl_fw_cmd_version *cmd_versions;
0058     u32 n_cmd_versions;
0059 };
0060 
0061 static inline bool
0062 fw_has_api(const struct iwl_ucode_capabilities *capabilities,
0063        iwl_ucode_tlv_api_t api)
0064 {
0065     return test_bit((__force long)api, capabilities->_api);
0066 }
0067 
0068 static inline bool
0069 fw_has_capa(const struct iwl_ucode_capabilities *capabilities,
0070         iwl_ucode_tlv_capa_t capa)
0071 {
0072     return test_bit((__force long)capa, capabilities->_capa);
0073 }
0074 
0075 /* one for each uCode image (inst/data, init/runtime/wowlan) */
0076 struct fw_desc {
0077     const void *data;   /* vmalloc'ed data */
0078     u32 len;        /* size in bytes */
0079     u32 offset;     /* offset in the device */
0080 };
0081 
0082 struct fw_img {
0083     struct fw_desc *sec;
0084     int num_sec;
0085     bool is_dual_cpus;
0086     u32 paging_mem_size;
0087 };
0088 
0089 /*
0090  * Block paging calculations
0091  */
0092 #define PAGE_2_EXP_SIZE 12 /* 4K == 2^12 */
0093 #define FW_PAGING_SIZE BIT(PAGE_2_EXP_SIZE) /* page size is 4KB */
0094 #define PAGE_PER_GROUP_2_EXP_SIZE 3
0095 /* 8 pages per group */
0096 #define NUM_OF_PAGE_PER_GROUP BIT(PAGE_PER_GROUP_2_EXP_SIZE)
0097 /* don't change, support only 32KB size */
0098 #define PAGING_BLOCK_SIZE (NUM_OF_PAGE_PER_GROUP * FW_PAGING_SIZE)
0099 /* 32K == 2^15 */
0100 #define BLOCK_2_EXP_SIZE (PAGE_2_EXP_SIZE + PAGE_PER_GROUP_2_EXP_SIZE)
0101 
0102 /*
0103  * Image paging calculations
0104  */
0105 #define BLOCK_PER_IMAGE_2_EXP_SIZE 5
0106 /* 2^5 == 32 blocks per image */
0107 #define NUM_OF_BLOCK_PER_IMAGE BIT(BLOCK_PER_IMAGE_2_EXP_SIZE)
0108 /* maximum image size 1024KB */
0109 #define MAX_PAGING_IMAGE_SIZE (NUM_OF_BLOCK_PER_IMAGE * PAGING_BLOCK_SIZE)
0110 
0111 /* Virtual address signature */
0112 #define PAGING_ADDR_SIG 0xAA000000
0113 
0114 #define PAGING_CMD_IS_SECURED BIT(9)
0115 #define PAGING_CMD_IS_ENABLED BIT(8)
0116 #define PAGING_CMD_NUM_OF_PAGES_IN_LAST_GRP_POS 0
0117 #define PAGING_TLV_SECURE_MASK 1
0118 
0119 /* FW MSB Mask for regions/cache_control */
0120 #define FW_ADDR_CACHE_CONTROL 0xC0000000UL
0121 
0122 /**
0123  * struct iwl_fw_paging
0124  * @fw_paging_phys: page phy pointer
0125  * @fw_paging_block: pointer to the allocated block
0126  * @fw_paging_size: page size
0127  * @fw_offs: offset in the device
0128  */
0129 struct iwl_fw_paging {
0130     dma_addr_t fw_paging_phys;
0131     struct page *fw_paging_block;
0132     u32 fw_paging_size;
0133     u32 fw_offs;
0134 };
0135 
0136 /**
0137  * enum iwl_fw_type - iwlwifi firmware type
0138  * @IWL_FW_DVM: DVM firmware
0139  * @IWL_FW_MVM: MVM firmware
0140  */
0141 enum iwl_fw_type {
0142     IWL_FW_DVM,
0143     IWL_FW_MVM,
0144 };
0145 
0146 /**
0147  * struct iwl_fw_dbg - debug data
0148  *
0149  * @dest_tlv: points to debug destination TLV (typically SRAM or DRAM)
0150  * @n_dest_reg: num of reg_ops in dest_tlv
0151  * @conf_tlv: array of pointers to configuration HCMDs
0152  * @trigger_tlv: array of pointers to triggers TLVs
0153  * @trigger_tlv_len: lengths of the @dbg_trigger_tlv entries
0154  * @mem_tlv: Runtime addresses to dump
0155  * @n_mem_tlv: number of runtime addresses
0156  * @dump_mask: bitmask of dump regions
0157 */
0158 struct iwl_fw_dbg {
0159     struct iwl_fw_dbg_dest_tlv_v1 *dest_tlv;
0160     u8 n_dest_reg;
0161     struct iwl_fw_dbg_conf_tlv *conf_tlv[FW_DBG_CONF_MAX];
0162     struct iwl_fw_dbg_trigger_tlv *trigger_tlv[FW_DBG_TRIGGER_MAX];
0163     size_t trigger_tlv_len[FW_DBG_TRIGGER_MAX];
0164     struct iwl_fw_dbg_mem_seg_tlv *mem_tlv;
0165     size_t n_mem_tlv;
0166     u32 dump_mask;
0167 };
0168 
0169 struct iwl_dump_exclude {
0170     u32 addr, size;
0171 };
0172 
0173 /**
0174  * struct iwl_fw - variables associated with the firmware
0175  *
0176  * @ucode_ver: ucode version from the ucode file
0177  * @fw_version: firmware version string
0178  * @img: ucode image like ucode_rt, ucode_init, ucode_wowlan.
0179  * @iml_len: length of the image loader image
0180  * @iml: image loader fw image
0181  * @ucode_capa: capabilities parsed from the ucode file.
0182  * @enhance_sensitivity_table: device can do enhanced sensitivity.
0183  * @init_evtlog_ptr: event log offset for init ucode.
0184  * @init_evtlog_size: event log size for init ucode.
0185  * @init_errlog_ptr: error log offfset for init ucode.
0186  * @inst_evtlog_ptr: event log offset for runtime ucode.
0187  * @inst_evtlog_size: event log size for runtime ucode.
0188  * @inst_errlog_ptr: error log offfset for runtime ucode.
0189  * @type: firmware type (&enum iwl_fw_type)
0190  * @human_readable: human readable version
0191  *  we get the ALIVE from the uCode
0192  * @phy_integration_ver: PHY integration version string
0193  * @phy_integration_ver_len: length of @phy_integration_ver
0194  * @dump_excl: image dump exclusion areas for RT image
0195  * @dump_excl_wowlan: image dump exclusion areas for WoWLAN image
0196  */
0197 struct iwl_fw {
0198     u32 ucode_ver;
0199 
0200     char fw_version[64];
0201 
0202     /* ucode images */
0203     struct fw_img img[IWL_UCODE_TYPE_MAX];
0204     size_t iml_len;
0205     u8 *iml;
0206 
0207     struct iwl_ucode_capabilities ucode_capa;
0208     bool enhance_sensitivity_table;
0209 
0210     u32 init_evtlog_ptr, init_evtlog_size, init_errlog_ptr;
0211     u32 inst_evtlog_ptr, inst_evtlog_size, inst_errlog_ptr;
0212 
0213     struct iwl_tlv_calib_ctrl default_calib[IWL_UCODE_TYPE_MAX];
0214     u32 phy_config;
0215     u8 valid_tx_ant;
0216     u8 valid_rx_ant;
0217 
0218     enum iwl_fw_type type;
0219 
0220     u8 human_readable[FW_VER_HUMAN_READABLE_SZ];
0221 
0222     struct iwl_fw_dbg dbg;
0223 
0224     u8 *phy_integration_ver;
0225     u32 phy_integration_ver_len;
0226 
0227     struct iwl_dump_exclude dump_excl[2], dump_excl_wowlan[2];
0228 };
0229 
0230 static inline const char *get_fw_dbg_mode_string(int mode)
0231 {
0232     switch (mode) {
0233     case SMEM_MODE:
0234         return "SMEM";
0235     case EXTERNAL_MODE:
0236         return "EXTERNAL_DRAM";
0237     case MARBH_MODE:
0238         return "MARBH";
0239     case MIPI_MODE:
0240         return "MIPI";
0241     default:
0242         return "UNKNOWN";
0243     }
0244 }
0245 
0246 static inline bool
0247 iwl_fw_dbg_conf_usniffer(const struct iwl_fw *fw, u8 id)
0248 {
0249     const struct iwl_fw_dbg_conf_tlv *conf_tlv = fw->dbg.conf_tlv[id];
0250 
0251     if (!conf_tlv)
0252         return false;
0253 
0254     return conf_tlv->usniffer;
0255 }
0256 
0257 static inline const struct fw_img *
0258 iwl_get_ucode_image(const struct iwl_fw *fw, enum iwl_ucode_type ucode_type)
0259 {
0260     if (ucode_type >= IWL_UCODE_TYPE_MAX)
0261         return NULL;
0262 
0263     return &fw->img[ucode_type];
0264 }
0265 
0266 u8 iwl_fw_lookup_cmd_ver(const struct iwl_fw *fw, u32 cmd_id, u8 def);
0267 
0268 u8 iwl_fw_lookup_notif_ver(const struct iwl_fw *fw, u8 grp, u8 cmd, u8 def);
0269 const char *iwl_fw_lookup_assert_desc(u32 num);
0270 
0271 #define FW_SYSASSERT_CPU_MASK       0xf0000000
0272 #define FW_SYSASSERT_PNVM_MISSING   0x0010070d
0273 
0274 #endif  /* __iwl_fw_img_h__ */