162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */ 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * Copyright (C) 2005-2014, 2018-2021 Intel Corporation 462306a36Sopenharmony_ci * Copyright (C) 2013-2015 Intel Mobile Communications GmbH 562306a36Sopenharmony_ci * Copyright (C) 2016 Intel Deutschland GmbH 662306a36Sopenharmony_ci */ 762306a36Sopenharmony_ci#ifndef __iwl_fw_img_h__ 862306a36Sopenharmony_ci#define __iwl_fw_img_h__ 962306a36Sopenharmony_ci#include <linux/types.h> 1062306a36Sopenharmony_ci 1162306a36Sopenharmony_ci#include "api/dbg-tlv.h" 1262306a36Sopenharmony_ci 1362306a36Sopenharmony_ci#include "file.h" 1462306a36Sopenharmony_ci#include "error-dump.h" 1562306a36Sopenharmony_ci 1662306a36Sopenharmony_ci/** 1762306a36Sopenharmony_ci * enum iwl_ucode_type 1862306a36Sopenharmony_ci * 1962306a36Sopenharmony_ci * The type of ucode. 2062306a36Sopenharmony_ci * 2162306a36Sopenharmony_ci * @IWL_UCODE_REGULAR: Normal runtime ucode 2262306a36Sopenharmony_ci * @IWL_UCODE_INIT: Initial ucode 2362306a36Sopenharmony_ci * @IWL_UCODE_WOWLAN: Wake on Wireless enabled ucode 2462306a36Sopenharmony_ci * @IWL_UCODE_REGULAR_USNIFFER: Normal runtime ucode when using usniffer image 2562306a36Sopenharmony_ci */ 2662306a36Sopenharmony_cienum iwl_ucode_type { 2762306a36Sopenharmony_ci IWL_UCODE_REGULAR, 2862306a36Sopenharmony_ci IWL_UCODE_INIT, 2962306a36Sopenharmony_ci IWL_UCODE_WOWLAN, 3062306a36Sopenharmony_ci IWL_UCODE_REGULAR_USNIFFER, 3162306a36Sopenharmony_ci IWL_UCODE_TYPE_MAX, 3262306a36Sopenharmony_ci}; 3362306a36Sopenharmony_ci 3462306a36Sopenharmony_ci/* 3562306a36Sopenharmony_ci * enumeration of ucode section. 3662306a36Sopenharmony_ci * This enumeration is used directly for older firmware (before 16.0). 3762306a36Sopenharmony_ci * For new firmware, there can be up to 4 sections (see below) but the 3862306a36Sopenharmony_ci * first one packaged into the firmware file is the DATA section and 3962306a36Sopenharmony_ci * some debugging code accesses that. 4062306a36Sopenharmony_ci */ 4162306a36Sopenharmony_cienum iwl_ucode_sec { 4262306a36Sopenharmony_ci IWL_UCODE_SECTION_DATA, 4362306a36Sopenharmony_ci IWL_UCODE_SECTION_INST, 4462306a36Sopenharmony_ci}; 4562306a36Sopenharmony_ci 4662306a36Sopenharmony_cistruct iwl_ucode_capabilities { 4762306a36Sopenharmony_ci u32 max_probe_length; 4862306a36Sopenharmony_ci u32 n_scan_channels; 4962306a36Sopenharmony_ci u32 standard_phy_calibration_size; 5062306a36Sopenharmony_ci u32 flags; 5162306a36Sopenharmony_ci u32 error_log_addr; 5262306a36Sopenharmony_ci u32 error_log_size; 5362306a36Sopenharmony_ci u32 num_stations; 5462306a36Sopenharmony_ci u32 num_beacons; 5562306a36Sopenharmony_ci unsigned long _api[BITS_TO_LONGS(NUM_IWL_UCODE_TLV_API)]; 5662306a36Sopenharmony_ci unsigned long _capa[BITS_TO_LONGS(NUM_IWL_UCODE_TLV_CAPA)]; 5762306a36Sopenharmony_ci 5862306a36Sopenharmony_ci const struct iwl_fw_cmd_version *cmd_versions; 5962306a36Sopenharmony_ci u32 n_cmd_versions; 6062306a36Sopenharmony_ci}; 6162306a36Sopenharmony_ci 6262306a36Sopenharmony_cistatic inline bool 6362306a36Sopenharmony_cifw_has_api(const struct iwl_ucode_capabilities *capabilities, 6462306a36Sopenharmony_ci iwl_ucode_tlv_api_t api) 6562306a36Sopenharmony_ci{ 6662306a36Sopenharmony_ci return test_bit((__force long)api, capabilities->_api); 6762306a36Sopenharmony_ci} 6862306a36Sopenharmony_ci 6962306a36Sopenharmony_cistatic inline bool 7062306a36Sopenharmony_cifw_has_capa(const struct iwl_ucode_capabilities *capabilities, 7162306a36Sopenharmony_ci iwl_ucode_tlv_capa_t capa) 7262306a36Sopenharmony_ci{ 7362306a36Sopenharmony_ci return test_bit((__force long)capa, capabilities->_capa); 7462306a36Sopenharmony_ci} 7562306a36Sopenharmony_ci 7662306a36Sopenharmony_ci/* one for each uCode image (inst/data, init/runtime/wowlan) */ 7762306a36Sopenharmony_cistruct fw_desc { 7862306a36Sopenharmony_ci const void *data; /* vmalloc'ed data */ 7962306a36Sopenharmony_ci u32 len; /* size in bytes */ 8062306a36Sopenharmony_ci u32 offset; /* offset in the device */ 8162306a36Sopenharmony_ci}; 8262306a36Sopenharmony_ci 8362306a36Sopenharmony_cistruct fw_img { 8462306a36Sopenharmony_ci struct fw_desc *sec; 8562306a36Sopenharmony_ci int num_sec; 8662306a36Sopenharmony_ci bool is_dual_cpus; 8762306a36Sopenharmony_ci u32 paging_mem_size; 8862306a36Sopenharmony_ci}; 8962306a36Sopenharmony_ci 9062306a36Sopenharmony_ci/* 9162306a36Sopenharmony_ci * Block paging calculations 9262306a36Sopenharmony_ci */ 9362306a36Sopenharmony_ci#define PAGE_2_EXP_SIZE 12 /* 4K == 2^12 */ 9462306a36Sopenharmony_ci#define FW_PAGING_SIZE BIT(PAGE_2_EXP_SIZE) /* page size is 4KB */ 9562306a36Sopenharmony_ci#define PAGE_PER_GROUP_2_EXP_SIZE 3 9662306a36Sopenharmony_ci/* 8 pages per group */ 9762306a36Sopenharmony_ci#define NUM_OF_PAGE_PER_GROUP BIT(PAGE_PER_GROUP_2_EXP_SIZE) 9862306a36Sopenharmony_ci/* don't change, support only 32KB size */ 9962306a36Sopenharmony_ci#define PAGING_BLOCK_SIZE (NUM_OF_PAGE_PER_GROUP * FW_PAGING_SIZE) 10062306a36Sopenharmony_ci/* 32K == 2^15 */ 10162306a36Sopenharmony_ci#define BLOCK_2_EXP_SIZE (PAGE_2_EXP_SIZE + PAGE_PER_GROUP_2_EXP_SIZE) 10262306a36Sopenharmony_ci 10362306a36Sopenharmony_ci/* 10462306a36Sopenharmony_ci * Image paging calculations 10562306a36Sopenharmony_ci */ 10662306a36Sopenharmony_ci#define BLOCK_PER_IMAGE_2_EXP_SIZE 5 10762306a36Sopenharmony_ci/* 2^5 == 32 blocks per image */ 10862306a36Sopenharmony_ci#define NUM_OF_BLOCK_PER_IMAGE BIT(BLOCK_PER_IMAGE_2_EXP_SIZE) 10962306a36Sopenharmony_ci/* maximum image size 1024KB */ 11062306a36Sopenharmony_ci#define MAX_PAGING_IMAGE_SIZE (NUM_OF_BLOCK_PER_IMAGE * PAGING_BLOCK_SIZE) 11162306a36Sopenharmony_ci 11262306a36Sopenharmony_ci/* Virtual address signature */ 11362306a36Sopenharmony_ci#define PAGING_ADDR_SIG 0xAA000000 11462306a36Sopenharmony_ci 11562306a36Sopenharmony_ci#define PAGING_CMD_IS_SECURED BIT(9) 11662306a36Sopenharmony_ci#define PAGING_CMD_IS_ENABLED BIT(8) 11762306a36Sopenharmony_ci#define PAGING_CMD_NUM_OF_PAGES_IN_LAST_GRP_POS 0 11862306a36Sopenharmony_ci#define PAGING_TLV_SECURE_MASK 1 11962306a36Sopenharmony_ci 12062306a36Sopenharmony_ci/* FW MSB Mask for regions/cache_control */ 12162306a36Sopenharmony_ci#define FW_ADDR_CACHE_CONTROL 0xC0000000UL 12262306a36Sopenharmony_ci 12362306a36Sopenharmony_ci/** 12462306a36Sopenharmony_ci * struct iwl_fw_paging 12562306a36Sopenharmony_ci * @fw_paging_phys: page phy pointer 12662306a36Sopenharmony_ci * @fw_paging_block: pointer to the allocated block 12762306a36Sopenharmony_ci * @fw_paging_size: page size 12862306a36Sopenharmony_ci * @fw_offs: offset in the device 12962306a36Sopenharmony_ci */ 13062306a36Sopenharmony_cistruct iwl_fw_paging { 13162306a36Sopenharmony_ci dma_addr_t fw_paging_phys; 13262306a36Sopenharmony_ci struct page *fw_paging_block; 13362306a36Sopenharmony_ci u32 fw_paging_size; 13462306a36Sopenharmony_ci u32 fw_offs; 13562306a36Sopenharmony_ci}; 13662306a36Sopenharmony_ci 13762306a36Sopenharmony_ci/** 13862306a36Sopenharmony_ci * enum iwl_fw_type - iwlwifi firmware type 13962306a36Sopenharmony_ci * @IWL_FW_DVM: DVM firmware 14062306a36Sopenharmony_ci * @IWL_FW_MVM: MVM firmware 14162306a36Sopenharmony_ci */ 14262306a36Sopenharmony_cienum iwl_fw_type { 14362306a36Sopenharmony_ci IWL_FW_DVM, 14462306a36Sopenharmony_ci IWL_FW_MVM, 14562306a36Sopenharmony_ci}; 14662306a36Sopenharmony_ci 14762306a36Sopenharmony_ci/** 14862306a36Sopenharmony_ci * struct iwl_fw_dbg - debug data 14962306a36Sopenharmony_ci * 15062306a36Sopenharmony_ci * @dest_tlv: points to debug destination TLV (typically SRAM or DRAM) 15162306a36Sopenharmony_ci * @n_dest_reg: num of reg_ops in dest_tlv 15262306a36Sopenharmony_ci * @conf_tlv: array of pointers to configuration HCMDs 15362306a36Sopenharmony_ci * @trigger_tlv: array of pointers to triggers TLVs 15462306a36Sopenharmony_ci * @trigger_tlv_len: lengths of the @dbg_trigger_tlv entries 15562306a36Sopenharmony_ci * @mem_tlv: Runtime addresses to dump 15662306a36Sopenharmony_ci * @n_mem_tlv: number of runtime addresses 15762306a36Sopenharmony_ci * @dump_mask: bitmask of dump regions 15862306a36Sopenharmony_ci*/ 15962306a36Sopenharmony_cistruct iwl_fw_dbg { 16062306a36Sopenharmony_ci struct iwl_fw_dbg_dest_tlv_v1 *dest_tlv; 16162306a36Sopenharmony_ci u8 n_dest_reg; 16262306a36Sopenharmony_ci struct iwl_fw_dbg_conf_tlv *conf_tlv[FW_DBG_CONF_MAX]; 16362306a36Sopenharmony_ci struct iwl_fw_dbg_trigger_tlv *trigger_tlv[FW_DBG_TRIGGER_MAX]; 16462306a36Sopenharmony_ci size_t trigger_tlv_len[FW_DBG_TRIGGER_MAX]; 16562306a36Sopenharmony_ci struct iwl_fw_dbg_mem_seg_tlv *mem_tlv; 16662306a36Sopenharmony_ci size_t n_mem_tlv; 16762306a36Sopenharmony_ci u32 dump_mask; 16862306a36Sopenharmony_ci}; 16962306a36Sopenharmony_ci 17062306a36Sopenharmony_cistruct iwl_dump_exclude { 17162306a36Sopenharmony_ci u32 addr, size; 17262306a36Sopenharmony_ci}; 17362306a36Sopenharmony_ci 17462306a36Sopenharmony_ci/** 17562306a36Sopenharmony_ci * struct iwl_fw - variables associated with the firmware 17662306a36Sopenharmony_ci * 17762306a36Sopenharmony_ci * @ucode_ver: ucode version from the ucode file 17862306a36Sopenharmony_ci * @fw_version: firmware version string 17962306a36Sopenharmony_ci * @img: ucode image like ucode_rt, ucode_init, ucode_wowlan. 18062306a36Sopenharmony_ci * @iml_len: length of the image loader image 18162306a36Sopenharmony_ci * @iml: image loader fw image 18262306a36Sopenharmony_ci * @ucode_capa: capabilities parsed from the ucode file. 18362306a36Sopenharmony_ci * @enhance_sensitivity_table: device can do enhanced sensitivity. 18462306a36Sopenharmony_ci * @init_evtlog_ptr: event log offset for init ucode. 18562306a36Sopenharmony_ci * @init_evtlog_size: event log size for init ucode. 18662306a36Sopenharmony_ci * @init_errlog_ptr: error log offset for init ucode. 18762306a36Sopenharmony_ci * @inst_evtlog_ptr: event log offset for runtime ucode. 18862306a36Sopenharmony_ci * @inst_evtlog_size: event log size for runtime ucode. 18962306a36Sopenharmony_ci * @inst_errlog_ptr: error log offset for runtime ucode. 19062306a36Sopenharmony_ci * @type: firmware type (&enum iwl_fw_type) 19162306a36Sopenharmony_ci * @human_readable: human readable version 19262306a36Sopenharmony_ci * we get the ALIVE from the uCode 19362306a36Sopenharmony_ci * @phy_integration_ver: PHY integration version string 19462306a36Sopenharmony_ci * @phy_integration_ver_len: length of @phy_integration_ver 19562306a36Sopenharmony_ci * @dump_excl: image dump exclusion areas for RT image 19662306a36Sopenharmony_ci * @dump_excl_wowlan: image dump exclusion areas for WoWLAN image 19762306a36Sopenharmony_ci */ 19862306a36Sopenharmony_cistruct iwl_fw { 19962306a36Sopenharmony_ci u32 ucode_ver; 20062306a36Sopenharmony_ci 20162306a36Sopenharmony_ci char fw_version[64]; 20262306a36Sopenharmony_ci 20362306a36Sopenharmony_ci /* ucode images */ 20462306a36Sopenharmony_ci struct fw_img img[IWL_UCODE_TYPE_MAX]; 20562306a36Sopenharmony_ci size_t iml_len; 20662306a36Sopenharmony_ci u8 *iml; 20762306a36Sopenharmony_ci 20862306a36Sopenharmony_ci struct iwl_ucode_capabilities ucode_capa; 20962306a36Sopenharmony_ci bool enhance_sensitivity_table; 21062306a36Sopenharmony_ci 21162306a36Sopenharmony_ci u32 init_evtlog_ptr, init_evtlog_size, init_errlog_ptr; 21262306a36Sopenharmony_ci u32 inst_evtlog_ptr, inst_evtlog_size, inst_errlog_ptr; 21362306a36Sopenharmony_ci 21462306a36Sopenharmony_ci struct iwl_tlv_calib_ctrl default_calib[IWL_UCODE_TYPE_MAX]; 21562306a36Sopenharmony_ci u32 phy_config; 21662306a36Sopenharmony_ci u8 valid_tx_ant; 21762306a36Sopenharmony_ci u8 valid_rx_ant; 21862306a36Sopenharmony_ci 21962306a36Sopenharmony_ci enum iwl_fw_type type; 22062306a36Sopenharmony_ci 22162306a36Sopenharmony_ci u8 human_readable[FW_VER_HUMAN_READABLE_SZ]; 22262306a36Sopenharmony_ci 22362306a36Sopenharmony_ci struct iwl_fw_dbg dbg; 22462306a36Sopenharmony_ci 22562306a36Sopenharmony_ci u8 *phy_integration_ver; 22662306a36Sopenharmony_ci u32 phy_integration_ver_len; 22762306a36Sopenharmony_ci 22862306a36Sopenharmony_ci struct iwl_dump_exclude dump_excl[2], dump_excl_wowlan[2]; 22962306a36Sopenharmony_ci}; 23062306a36Sopenharmony_ci 23162306a36Sopenharmony_cistatic inline const char *get_fw_dbg_mode_string(int mode) 23262306a36Sopenharmony_ci{ 23362306a36Sopenharmony_ci switch (mode) { 23462306a36Sopenharmony_ci case SMEM_MODE: 23562306a36Sopenharmony_ci return "SMEM"; 23662306a36Sopenharmony_ci case EXTERNAL_MODE: 23762306a36Sopenharmony_ci return "EXTERNAL_DRAM"; 23862306a36Sopenharmony_ci case MARBH_MODE: 23962306a36Sopenharmony_ci return "MARBH"; 24062306a36Sopenharmony_ci case MIPI_MODE: 24162306a36Sopenharmony_ci return "MIPI"; 24262306a36Sopenharmony_ci default: 24362306a36Sopenharmony_ci return "UNKNOWN"; 24462306a36Sopenharmony_ci } 24562306a36Sopenharmony_ci} 24662306a36Sopenharmony_ci 24762306a36Sopenharmony_cistatic inline bool 24862306a36Sopenharmony_ciiwl_fw_dbg_conf_usniffer(const struct iwl_fw *fw, u8 id) 24962306a36Sopenharmony_ci{ 25062306a36Sopenharmony_ci const struct iwl_fw_dbg_conf_tlv *conf_tlv = fw->dbg.conf_tlv[id]; 25162306a36Sopenharmony_ci 25262306a36Sopenharmony_ci if (!conf_tlv) 25362306a36Sopenharmony_ci return false; 25462306a36Sopenharmony_ci 25562306a36Sopenharmony_ci return conf_tlv->usniffer; 25662306a36Sopenharmony_ci} 25762306a36Sopenharmony_ci 25862306a36Sopenharmony_cistatic inline const struct fw_img * 25962306a36Sopenharmony_ciiwl_get_ucode_image(const struct iwl_fw *fw, enum iwl_ucode_type ucode_type) 26062306a36Sopenharmony_ci{ 26162306a36Sopenharmony_ci if (ucode_type >= IWL_UCODE_TYPE_MAX) 26262306a36Sopenharmony_ci return NULL; 26362306a36Sopenharmony_ci 26462306a36Sopenharmony_ci return &fw->img[ucode_type]; 26562306a36Sopenharmony_ci} 26662306a36Sopenharmony_ci 26762306a36Sopenharmony_ciu8 iwl_fw_lookup_cmd_ver(const struct iwl_fw *fw, u32 cmd_id, u8 def); 26862306a36Sopenharmony_ci 26962306a36Sopenharmony_ciu8 iwl_fw_lookup_notif_ver(const struct iwl_fw *fw, u8 grp, u8 cmd, u8 def); 27062306a36Sopenharmony_ciconst char *iwl_fw_lookup_assert_desc(u32 num); 27162306a36Sopenharmony_ci 27262306a36Sopenharmony_ci#define FW_SYSASSERT_CPU_MASK 0xf0000000 27362306a36Sopenharmony_ci#define FW_SYSASSERT_PNVM_MISSING 0x0010070d 27462306a36Sopenharmony_ci 27562306a36Sopenharmony_ci#endif /* __iwl_fw_img_h__ */ 276