cachepc-linux

Fork of AMDESE/linux with modifications for CachePC side-channel attack
git clone https://git.sinitax.com/sinitax/cachepc-linux
Log | Files | Refs | README | LICENSE | sfeed.txt

qmi.c (82982B)


      1// SPDX-License-Identifier: BSD-3-Clause-Clear
      2/*
      3 * Copyright (c) 2018-2019 The Linux Foundation. All rights reserved.
      4 * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
      5 */
      6
      7#include <linux/elf.h>
      8
      9#include "qmi.h"
     10#include "core.h"
     11#include "debug.h"
     12#include <linux/of.h>
     13#include <linux/of_address.h>
     14#include <linux/ioport.h>
     15#include <linux/firmware.h>
     16#include <linux/of_device.h>
     17#include <linux/of_irq.h>
     18
     19#define SLEEP_CLOCK_SELECT_INTERNAL_BIT	0x02
     20#define HOST_CSTATE_BIT			0x04
     21#define PLATFORM_CAP_PCIE_GLOBAL_RESET	0x08
     22
     23#define FW_BUILD_ID_MASK "QC_IMAGE_VERSION_STRING="
     24
     25bool ath11k_cold_boot_cal = 1;
     26EXPORT_SYMBOL(ath11k_cold_boot_cal);
     27module_param_named(cold_boot_cal, ath11k_cold_boot_cal, bool, 0644);
     28MODULE_PARM_DESC(cold_boot_cal,
     29		 "Decrease the channel switch time but increase the driver load time (Default: true)");
     30
     31static struct qmi_elem_info qmi_wlanfw_host_cap_req_msg_v01_ei[] = {
     32	{
     33		.data_type	= QMI_OPT_FLAG,
     34		.elem_len	= 1,
     35		.elem_size	= sizeof(u8),
     36		.array_type	= NO_ARRAY,
     37		.tlv_type	= 0x10,
     38		.offset		= offsetof(struct qmi_wlanfw_host_cap_req_msg_v01,
     39					   num_clients_valid),
     40	},
     41	{
     42		.data_type	= QMI_UNSIGNED_4_BYTE,
     43		.elem_len	= 1,
     44		.elem_size	= sizeof(u32),
     45		.array_type	= NO_ARRAY,
     46		.tlv_type	= 0x10,
     47		.offset		= offsetof(struct qmi_wlanfw_host_cap_req_msg_v01,
     48					   num_clients),
     49	},
     50	{
     51		.data_type	= QMI_OPT_FLAG,
     52		.elem_len	= 1,
     53		.elem_size	= sizeof(u8),
     54		.array_type	= NO_ARRAY,
     55		.tlv_type	= 0x11,
     56		.offset		= offsetof(struct qmi_wlanfw_host_cap_req_msg_v01,
     57					   wake_msi_valid),
     58	},
     59	{
     60		.data_type	= QMI_UNSIGNED_4_BYTE,
     61		.elem_len	= 1,
     62		.elem_size	= sizeof(u32),
     63		.array_type	= NO_ARRAY,
     64		.tlv_type	= 0x11,
     65		.offset		= offsetof(struct qmi_wlanfw_host_cap_req_msg_v01,
     66					   wake_msi),
     67	},
     68	{
     69		.data_type	= QMI_OPT_FLAG,
     70		.elem_len	= 1,
     71		.elem_size	= sizeof(u8),
     72		.array_type	= NO_ARRAY,
     73		.tlv_type	= 0x12,
     74		.offset		= offsetof(struct qmi_wlanfw_host_cap_req_msg_v01,
     75					   gpios_valid),
     76	},
     77	{
     78		.data_type	= QMI_DATA_LEN,
     79		.elem_len	= 1,
     80		.elem_size	= sizeof(u8),
     81		.array_type	= NO_ARRAY,
     82		.tlv_type	= 0x12,
     83		.offset		= offsetof(struct qmi_wlanfw_host_cap_req_msg_v01,
     84					   gpios_len),
     85	},
     86	{
     87		.data_type	= QMI_UNSIGNED_4_BYTE,
     88		.elem_len	= QMI_WLFW_MAX_NUM_GPIO_V01,
     89		.elem_size	= sizeof(u32),
     90		.array_type	= VAR_LEN_ARRAY,
     91		.tlv_type	= 0x12,
     92		.offset		= offsetof(struct qmi_wlanfw_host_cap_req_msg_v01,
     93					   gpios),
     94	},
     95	{
     96		.data_type	= QMI_OPT_FLAG,
     97		.elem_len	= 1,
     98		.elem_size	= sizeof(u8),
     99		.array_type	= NO_ARRAY,
    100		.tlv_type	= 0x13,
    101		.offset		= offsetof(struct qmi_wlanfw_host_cap_req_msg_v01,
    102					   nm_modem_valid),
    103	},
    104	{
    105		.data_type	= QMI_UNSIGNED_1_BYTE,
    106		.elem_len	= 1,
    107		.elem_size	= sizeof(u8),
    108		.array_type	= NO_ARRAY,
    109		.tlv_type	= 0x13,
    110		.offset		= offsetof(struct qmi_wlanfw_host_cap_req_msg_v01,
    111					   nm_modem),
    112	},
    113	{
    114		.data_type	= QMI_OPT_FLAG,
    115		.elem_len	= 1,
    116		.elem_size	= sizeof(u8),
    117		.array_type	= NO_ARRAY,
    118		.tlv_type	= 0x14,
    119		.offset		= offsetof(struct qmi_wlanfw_host_cap_req_msg_v01,
    120					   bdf_support_valid),
    121	},
    122	{
    123		.data_type	= QMI_UNSIGNED_1_BYTE,
    124		.elem_len	= 1,
    125		.elem_size	= sizeof(u8),
    126		.array_type	= NO_ARRAY,
    127		.tlv_type	= 0x14,
    128		.offset		= offsetof(struct qmi_wlanfw_host_cap_req_msg_v01,
    129					   bdf_support),
    130	},
    131	{
    132		.data_type	= QMI_OPT_FLAG,
    133		.elem_len	= 1,
    134		.elem_size	= sizeof(u8),
    135		.array_type	= NO_ARRAY,
    136		.tlv_type	= 0x15,
    137		.offset		= offsetof(struct qmi_wlanfw_host_cap_req_msg_v01,
    138					   bdf_cache_support_valid),
    139	},
    140	{
    141		.data_type	= QMI_UNSIGNED_1_BYTE,
    142		.elem_len	= 1,
    143		.elem_size	= sizeof(u8),
    144		.array_type	= NO_ARRAY,
    145		.tlv_type	= 0x15,
    146		.offset		= offsetof(struct qmi_wlanfw_host_cap_req_msg_v01,
    147					   bdf_cache_support),
    148	},
    149	{
    150		.data_type	= QMI_OPT_FLAG,
    151		.elem_len	= 1,
    152		.elem_size	= sizeof(u8),
    153		.array_type	= NO_ARRAY,
    154		.tlv_type	= 0x16,
    155		.offset		= offsetof(struct qmi_wlanfw_host_cap_req_msg_v01,
    156					   m3_support_valid),
    157	},
    158	{
    159		.data_type	= QMI_UNSIGNED_1_BYTE,
    160		.elem_len	= 1,
    161		.elem_size	= sizeof(u8),
    162		.array_type	= NO_ARRAY,
    163		.tlv_type	= 0x16,
    164		.offset		= offsetof(struct qmi_wlanfw_host_cap_req_msg_v01,
    165					   m3_support),
    166	},
    167	{
    168		.data_type	= QMI_OPT_FLAG,
    169		.elem_len	= 1,
    170		.elem_size	= sizeof(u8),
    171		.array_type	= NO_ARRAY,
    172		.tlv_type	= 0x17,
    173		.offset		= offsetof(struct qmi_wlanfw_host_cap_req_msg_v01,
    174					   m3_cache_support_valid),
    175	},
    176	{
    177		.data_type	= QMI_UNSIGNED_1_BYTE,
    178		.elem_len	= 1,
    179		.elem_size	= sizeof(u8),
    180		.array_type	= NO_ARRAY,
    181		.tlv_type	= 0x17,
    182		.offset		= offsetof(struct qmi_wlanfw_host_cap_req_msg_v01,
    183					   m3_cache_support),
    184	},
    185	{
    186		.data_type	= QMI_OPT_FLAG,
    187		.elem_len	= 1,
    188		.elem_size	= sizeof(u8),
    189		.array_type	= NO_ARRAY,
    190		.tlv_type	= 0x18,
    191		.offset		= offsetof(struct qmi_wlanfw_host_cap_req_msg_v01,
    192					   cal_filesys_support_valid),
    193	},
    194	{
    195		.data_type	= QMI_UNSIGNED_1_BYTE,
    196		.elem_len	= 1,
    197		.elem_size	= sizeof(u8),
    198		.array_type	= NO_ARRAY,
    199		.tlv_type	= 0x18,
    200		.offset		= offsetof(struct qmi_wlanfw_host_cap_req_msg_v01,
    201					   cal_filesys_support),
    202	},
    203	{
    204		.data_type	= QMI_OPT_FLAG,
    205		.elem_len	= 1,
    206		.elem_size	= sizeof(u8),
    207		.array_type	= NO_ARRAY,
    208		.tlv_type	= 0x19,
    209		.offset		= offsetof(struct qmi_wlanfw_host_cap_req_msg_v01,
    210					   cal_cache_support_valid),
    211	},
    212	{
    213		.data_type	= QMI_UNSIGNED_1_BYTE,
    214		.elem_len	= 1,
    215		.elem_size	= sizeof(u8),
    216		.array_type	= NO_ARRAY,
    217		.tlv_type	= 0x19,
    218		.offset		= offsetof(struct qmi_wlanfw_host_cap_req_msg_v01,
    219					   cal_cache_support),
    220	},
    221	{
    222		.data_type	= QMI_OPT_FLAG,
    223		.elem_len	= 1,
    224		.elem_size	= sizeof(u8),
    225		.array_type	= NO_ARRAY,
    226		.tlv_type	= 0x1A,
    227		.offset		= offsetof(struct qmi_wlanfw_host_cap_req_msg_v01,
    228					   cal_done_valid),
    229	},
    230	{
    231		.data_type	= QMI_UNSIGNED_1_BYTE,
    232		.elem_len	= 1,
    233		.elem_size	= sizeof(u8),
    234		.array_type	= NO_ARRAY,
    235		.tlv_type	= 0x1A,
    236		.offset		= offsetof(struct qmi_wlanfw_host_cap_req_msg_v01,
    237					   cal_done),
    238	},
    239	{
    240		.data_type	= QMI_OPT_FLAG,
    241		.elem_len	= 1,
    242		.elem_size	= sizeof(u8),
    243		.array_type	= NO_ARRAY,
    244		.tlv_type	= 0x1B,
    245		.offset		= offsetof(struct qmi_wlanfw_host_cap_req_msg_v01,
    246					   mem_bucket_valid),
    247	},
    248	{
    249		.data_type	= QMI_UNSIGNED_4_BYTE,
    250		.elem_len	= 1,
    251		.elem_size	= sizeof(u32),
    252		.array_type	= NO_ARRAY,
    253		.tlv_type	= 0x1B,
    254		.offset		= offsetof(struct qmi_wlanfw_host_cap_req_msg_v01,
    255					   mem_bucket),
    256	},
    257	{
    258		.data_type	= QMI_OPT_FLAG,
    259		.elem_len	= 1,
    260		.elem_size	= sizeof(u8),
    261		.array_type	= NO_ARRAY,
    262		.tlv_type	= 0x1C,
    263		.offset		= offsetof(struct qmi_wlanfw_host_cap_req_msg_v01,
    264					   mem_cfg_mode_valid),
    265	},
    266	{
    267		.data_type	= QMI_UNSIGNED_1_BYTE,
    268		.elem_len	= 1,
    269		.elem_size	= sizeof(u8),
    270		.array_type	= NO_ARRAY,
    271		.tlv_type	= 0x1C,
    272		.offset		= offsetof(struct qmi_wlanfw_host_cap_req_msg_v01,
    273					   mem_cfg_mode),
    274	},
    275	{
    276		.data_type	= QMI_EOTI,
    277		.array_type	= NO_ARRAY,
    278		.tlv_type	= QMI_COMMON_TLV_TYPE,
    279	},
    280};
    281
    282static struct qmi_elem_info qmi_wlanfw_host_cap_resp_msg_v01_ei[] = {
    283	{
    284		.data_type	= QMI_STRUCT,
    285		.elem_len	= 1,
    286		.elem_size	= sizeof(struct qmi_response_type_v01),
    287		.array_type	= NO_ARRAY,
    288		.tlv_type	= 0x02,
    289		.offset		= offsetof(struct qmi_wlanfw_host_cap_resp_msg_v01, resp),
    290		.ei_array	= qmi_response_type_v01_ei,
    291	},
    292	{
    293		.data_type	= QMI_EOTI,
    294		.array_type	= NO_ARRAY,
    295		.tlv_type	= QMI_COMMON_TLV_TYPE,
    296	},
    297};
    298
    299static struct qmi_elem_info qmi_wlanfw_ind_register_req_msg_v01_ei[] = {
    300	{
    301		.data_type	= QMI_OPT_FLAG,
    302		.elem_len	= 1,
    303		.elem_size	= sizeof(u8),
    304		.array_type	= NO_ARRAY,
    305		.tlv_type	= 0x10,
    306		.offset		= offsetof(struct qmi_wlanfw_ind_register_req_msg_v01,
    307					   fw_ready_enable_valid),
    308	},
    309	{
    310		.data_type	= QMI_UNSIGNED_1_BYTE,
    311		.elem_len	= 1,
    312		.elem_size	= sizeof(u8),
    313		.array_type	= NO_ARRAY,
    314		.tlv_type	= 0x10,
    315		.offset		= offsetof(struct qmi_wlanfw_ind_register_req_msg_v01,
    316					   fw_ready_enable),
    317	},
    318	{
    319		.data_type	= QMI_OPT_FLAG,
    320		.elem_len	= 1,
    321		.elem_size	= sizeof(u8),
    322		.array_type	= NO_ARRAY,
    323		.tlv_type	= 0x11,
    324		.offset		= offsetof(struct qmi_wlanfw_ind_register_req_msg_v01,
    325					   initiate_cal_download_enable_valid),
    326	},
    327	{
    328		.data_type	= QMI_UNSIGNED_1_BYTE,
    329		.elem_len	= 1,
    330		.elem_size	= sizeof(u8),
    331		.array_type	= NO_ARRAY,
    332		.tlv_type	= 0x11,
    333		.offset		= offsetof(struct qmi_wlanfw_ind_register_req_msg_v01,
    334					   initiate_cal_download_enable),
    335	},
    336	{
    337		.data_type	= QMI_OPT_FLAG,
    338		.elem_len	= 1,
    339		.elem_size	= sizeof(u8),
    340		.array_type	= NO_ARRAY,
    341		.tlv_type	= 0x12,
    342		.offset		= offsetof(struct qmi_wlanfw_ind_register_req_msg_v01,
    343					   initiate_cal_update_enable_valid),
    344	},
    345	{
    346		.data_type	= QMI_UNSIGNED_1_BYTE,
    347		.elem_len	= 1,
    348		.elem_size	= sizeof(u8),
    349		.array_type	= NO_ARRAY,
    350		.tlv_type	= 0x12,
    351		.offset		= offsetof(struct qmi_wlanfw_ind_register_req_msg_v01,
    352					   initiate_cal_update_enable),
    353	},
    354	{
    355		.data_type	= QMI_OPT_FLAG,
    356		.elem_len	= 1,
    357		.elem_size	= sizeof(u8),
    358		.array_type	= NO_ARRAY,
    359		.tlv_type	= 0x13,
    360		.offset		= offsetof(struct qmi_wlanfw_ind_register_req_msg_v01,
    361					   msa_ready_enable_valid),
    362	},
    363	{
    364		.data_type	= QMI_UNSIGNED_1_BYTE,
    365		.elem_len	= 1,
    366		.elem_size	= sizeof(u8),
    367		.array_type	= NO_ARRAY,
    368		.tlv_type	= 0x13,
    369		.offset		= offsetof(struct qmi_wlanfw_ind_register_req_msg_v01,
    370					   msa_ready_enable),
    371	},
    372	{
    373		.data_type	= QMI_OPT_FLAG,
    374		.elem_len	= 1,
    375		.elem_size	= sizeof(u8),
    376		.array_type	= NO_ARRAY,
    377		.tlv_type	= 0x14,
    378		.offset		= offsetof(struct qmi_wlanfw_ind_register_req_msg_v01,
    379					   pin_connect_result_enable_valid),
    380	},
    381	{
    382		.data_type	= QMI_UNSIGNED_1_BYTE,
    383		.elem_len	= 1,
    384		.elem_size	= sizeof(u8),
    385		.array_type	= NO_ARRAY,
    386		.tlv_type	= 0x14,
    387		.offset		= offsetof(struct qmi_wlanfw_ind_register_req_msg_v01,
    388					   pin_connect_result_enable),
    389	},
    390	{
    391		.data_type	= QMI_OPT_FLAG,
    392		.elem_len	= 1,
    393		.elem_size	= sizeof(u8),
    394		.array_type	= NO_ARRAY,
    395		.tlv_type	= 0x15,
    396		.offset		= offsetof(struct qmi_wlanfw_ind_register_req_msg_v01,
    397					   client_id_valid),
    398	},
    399	{
    400		.data_type	= QMI_UNSIGNED_4_BYTE,
    401		.elem_len	= 1,
    402		.elem_size	= sizeof(u32),
    403		.array_type	= NO_ARRAY,
    404		.tlv_type	= 0x15,
    405		.offset		= offsetof(struct qmi_wlanfw_ind_register_req_msg_v01,
    406					   client_id),
    407	},
    408	{
    409		.data_type	= QMI_OPT_FLAG,
    410		.elem_len	= 1,
    411		.elem_size	= sizeof(u8),
    412		.array_type	= NO_ARRAY,
    413		.tlv_type	= 0x16,
    414		.offset		= offsetof(struct qmi_wlanfw_ind_register_req_msg_v01,
    415					   request_mem_enable_valid),
    416	},
    417	{
    418		.data_type	= QMI_UNSIGNED_1_BYTE,
    419		.elem_len	= 1,
    420		.elem_size	= sizeof(u8),
    421		.array_type	= NO_ARRAY,
    422		.tlv_type	= 0x16,
    423		.offset		= offsetof(struct qmi_wlanfw_ind_register_req_msg_v01,
    424					   request_mem_enable),
    425	},
    426	{
    427		.data_type	= QMI_OPT_FLAG,
    428		.elem_len	= 1,
    429		.elem_size	= sizeof(u8),
    430		.array_type	= NO_ARRAY,
    431		.tlv_type	= 0x17,
    432		.offset		= offsetof(struct qmi_wlanfw_ind_register_req_msg_v01,
    433					   fw_mem_ready_enable_valid),
    434	},
    435	{
    436		.data_type	= QMI_UNSIGNED_1_BYTE,
    437		.elem_len	= 1,
    438		.elem_size	= sizeof(u8),
    439		.array_type	= NO_ARRAY,
    440		.tlv_type	= 0x17,
    441		.offset		= offsetof(struct qmi_wlanfw_ind_register_req_msg_v01,
    442					   fw_mem_ready_enable),
    443	},
    444	{
    445		.data_type	= QMI_OPT_FLAG,
    446		.elem_len	= 1,
    447		.elem_size	= sizeof(u8),
    448		.array_type	= NO_ARRAY,
    449		.tlv_type	= 0x18,
    450		.offset		= offsetof(struct qmi_wlanfw_ind_register_req_msg_v01,
    451					   fw_init_done_enable_valid),
    452	},
    453	{
    454		.data_type	= QMI_UNSIGNED_1_BYTE,
    455		.elem_len	= 1,
    456		.elem_size	= sizeof(u8),
    457		.array_type	= NO_ARRAY,
    458		.tlv_type	= 0x18,
    459		.offset		= offsetof(struct qmi_wlanfw_ind_register_req_msg_v01,
    460					   fw_init_done_enable),
    461	},
    462
    463	{
    464		.data_type	= QMI_OPT_FLAG,
    465		.elem_len	= 1,
    466		.elem_size	= sizeof(u8),
    467		.array_type	= NO_ARRAY,
    468		.tlv_type	= 0x19,
    469		.offset		= offsetof(struct qmi_wlanfw_ind_register_req_msg_v01,
    470					   rejuvenate_enable_valid),
    471	},
    472	{
    473		.data_type	= QMI_UNSIGNED_1_BYTE,
    474		.elem_len	= 1,
    475		.elem_size	= sizeof(u8),
    476		.array_type	= NO_ARRAY,
    477		.tlv_type	= 0x19,
    478		.offset		= offsetof(struct qmi_wlanfw_ind_register_req_msg_v01,
    479					   rejuvenate_enable),
    480	},
    481	{
    482		.data_type	= QMI_OPT_FLAG,
    483		.elem_len	= 1,
    484		.elem_size	= sizeof(u8),
    485		.array_type	= NO_ARRAY,
    486		.tlv_type	= 0x1A,
    487		.offset		= offsetof(struct qmi_wlanfw_ind_register_req_msg_v01,
    488					   xo_cal_enable_valid),
    489	},
    490	{
    491		.data_type	= QMI_UNSIGNED_1_BYTE,
    492		.elem_len	= 1,
    493		.elem_size	= sizeof(u8),
    494		.array_type	= NO_ARRAY,
    495		.tlv_type	= 0x1A,
    496		.offset		= offsetof(struct qmi_wlanfw_ind_register_req_msg_v01,
    497					   xo_cal_enable),
    498	},
    499	{
    500		.data_type	= QMI_OPT_FLAG,
    501		.elem_len	= 1,
    502		.elem_size	= sizeof(u8),
    503		.array_type	= NO_ARRAY,
    504		.tlv_type	= 0x1B,
    505		.offset		= offsetof(struct qmi_wlanfw_ind_register_req_msg_v01,
    506					   cal_done_enable_valid),
    507	},
    508	{
    509		.data_type	= QMI_UNSIGNED_1_BYTE,
    510		.elem_len	= 1,
    511		.elem_size	= sizeof(u8),
    512		.array_type	= NO_ARRAY,
    513		.tlv_type	= 0x1B,
    514		.offset		= offsetof(struct qmi_wlanfw_ind_register_req_msg_v01,
    515					   cal_done_enable),
    516	},
    517	{
    518		.data_type	= QMI_EOTI,
    519		.array_type	= NO_ARRAY,
    520		.tlv_type	= QMI_COMMON_TLV_TYPE,
    521	},
    522};
    523
    524static struct qmi_elem_info qmi_wlanfw_ind_register_resp_msg_v01_ei[] = {
    525	{
    526		.data_type	= QMI_STRUCT,
    527		.elem_len	= 1,
    528		.elem_size	= sizeof(struct qmi_response_type_v01),
    529		.array_type	= NO_ARRAY,
    530		.tlv_type	= 0x02,
    531		.offset		= offsetof(struct qmi_wlanfw_ind_register_resp_msg_v01,
    532					   resp),
    533		.ei_array	= qmi_response_type_v01_ei,
    534	},
    535	{
    536		.data_type	= QMI_OPT_FLAG,
    537		.elem_len	= 1,
    538		.elem_size	= sizeof(u8),
    539		.array_type	= NO_ARRAY,
    540		.tlv_type	= 0x10,
    541		.offset		= offsetof(struct qmi_wlanfw_ind_register_resp_msg_v01,
    542					   fw_status_valid),
    543	},
    544	{
    545		.data_type	= QMI_UNSIGNED_8_BYTE,
    546		.elem_len	= 1,
    547		.elem_size	= sizeof(u64),
    548		.array_type	= NO_ARRAY,
    549		.tlv_type	= 0x10,
    550		.offset		= offsetof(struct qmi_wlanfw_ind_register_resp_msg_v01,
    551					   fw_status),
    552	},
    553	{
    554		.data_type	= QMI_EOTI,
    555		.array_type	= NO_ARRAY,
    556		.tlv_type	= QMI_COMMON_TLV_TYPE,
    557	},
    558};
    559
    560static struct qmi_elem_info qmi_wlanfw_mem_cfg_s_v01_ei[] = {
    561	{
    562		.data_type	= QMI_UNSIGNED_8_BYTE,
    563		.elem_len	= 1,
    564		.elem_size	= sizeof(u64),
    565		.array_type	= NO_ARRAY,
    566		.tlv_type	= 0,
    567		.offset		= offsetof(struct qmi_wlanfw_mem_cfg_s_v01, offset),
    568	},
    569	{
    570		.data_type	= QMI_UNSIGNED_4_BYTE,
    571		.elem_len	= 1,
    572		.elem_size	= sizeof(u32),
    573		.array_type	= NO_ARRAY,
    574		.tlv_type	= 0,
    575		.offset		= offsetof(struct qmi_wlanfw_mem_cfg_s_v01, size),
    576	},
    577	{
    578		.data_type	= QMI_UNSIGNED_1_BYTE,
    579		.elem_len	= 1,
    580		.elem_size	= sizeof(u8),
    581		.array_type	= NO_ARRAY,
    582		.tlv_type	= 0,
    583		.offset		= offsetof(struct qmi_wlanfw_mem_cfg_s_v01, secure_flag),
    584	},
    585	{
    586		.data_type	= QMI_EOTI,
    587		.array_type	= NO_ARRAY,
    588		.tlv_type	= QMI_COMMON_TLV_TYPE,
    589	},
    590};
    591
    592static struct qmi_elem_info qmi_wlanfw_mem_seg_s_v01_ei[] = {
    593	{
    594		.data_type	= QMI_UNSIGNED_4_BYTE,
    595		.elem_len	= 1,
    596		.elem_size	= sizeof(u32),
    597		.array_type	= NO_ARRAY,
    598		.tlv_type	= 0,
    599		.offset		= offsetof(struct qmi_wlanfw_mem_seg_s_v01,
    600				  size),
    601	},
    602	{
    603		.data_type	= QMI_SIGNED_4_BYTE_ENUM,
    604		.elem_len	= 1,
    605		.elem_size	= sizeof(enum qmi_wlanfw_mem_type_enum_v01),
    606		.array_type	= NO_ARRAY,
    607		.tlv_type	= 0,
    608		.offset		= offsetof(struct qmi_wlanfw_mem_seg_s_v01, type),
    609	},
    610	{
    611		.data_type	= QMI_DATA_LEN,
    612		.elem_len	= 1,
    613		.elem_size	= sizeof(u8),
    614		.array_type	= NO_ARRAY,
    615		.tlv_type	= 0,
    616		.offset		= offsetof(struct qmi_wlanfw_mem_seg_s_v01, mem_cfg_len),
    617	},
    618	{
    619		.data_type	= QMI_STRUCT,
    620		.elem_len	= QMI_WLANFW_MAX_NUM_MEM_CFG_V01,
    621		.elem_size	= sizeof(struct qmi_wlanfw_mem_cfg_s_v01),
    622		.array_type	= VAR_LEN_ARRAY,
    623		.tlv_type	= 0,
    624		.offset		= offsetof(struct qmi_wlanfw_mem_seg_s_v01, mem_cfg),
    625		.ei_array	= qmi_wlanfw_mem_cfg_s_v01_ei,
    626	},
    627	{
    628		.data_type	= QMI_EOTI,
    629		.array_type	= NO_ARRAY,
    630		.tlv_type	= QMI_COMMON_TLV_TYPE,
    631	},
    632};
    633
    634static struct qmi_elem_info qmi_wlanfw_request_mem_ind_msg_v01_ei[] = {
    635	{
    636		.data_type	= QMI_DATA_LEN,
    637		.elem_len	= 1,
    638		.elem_size	= sizeof(u8),
    639		.array_type	= NO_ARRAY,
    640		.tlv_type	= 0x01,
    641		.offset		= offsetof(struct qmi_wlanfw_request_mem_ind_msg_v01,
    642					   mem_seg_len),
    643	},
    644	{
    645		.data_type	= QMI_STRUCT,
    646		.elem_len	= ATH11K_QMI_WLANFW_MAX_NUM_MEM_SEG_V01,
    647		.elem_size	= sizeof(struct qmi_wlanfw_mem_seg_s_v01),
    648		.array_type	= VAR_LEN_ARRAY,
    649		.tlv_type	= 0x01,
    650		.offset		= offsetof(struct qmi_wlanfw_request_mem_ind_msg_v01,
    651					   mem_seg),
    652		.ei_array	= qmi_wlanfw_mem_seg_s_v01_ei,
    653	},
    654	{
    655		.data_type	= QMI_EOTI,
    656		.array_type	= NO_ARRAY,
    657		.tlv_type	= QMI_COMMON_TLV_TYPE,
    658	},
    659};
    660
    661static struct qmi_elem_info qmi_wlanfw_mem_seg_resp_s_v01_ei[] = {
    662	{
    663		.data_type	= QMI_UNSIGNED_8_BYTE,
    664		.elem_len	= 1,
    665		.elem_size	= sizeof(u64),
    666		.array_type	= NO_ARRAY,
    667		.tlv_type	= 0,
    668		.offset		= offsetof(struct qmi_wlanfw_mem_seg_resp_s_v01, addr),
    669	},
    670	{
    671		.data_type	= QMI_UNSIGNED_4_BYTE,
    672		.elem_len	= 1,
    673		.elem_size	= sizeof(u32),
    674		.array_type	= NO_ARRAY,
    675		.tlv_type	= 0,
    676		.offset		= offsetof(struct qmi_wlanfw_mem_seg_resp_s_v01, size),
    677	},
    678	{
    679		.data_type	= QMI_SIGNED_4_BYTE_ENUM,
    680		.elem_len	= 1,
    681		.elem_size	= sizeof(enum qmi_wlanfw_mem_type_enum_v01),
    682		.array_type	= NO_ARRAY,
    683		.tlv_type	= 0,
    684		.offset		= offsetof(struct qmi_wlanfw_mem_seg_resp_s_v01, type),
    685	},
    686	{
    687		.data_type	= QMI_UNSIGNED_1_BYTE,
    688		.elem_len	= 1,
    689		.elem_size	= sizeof(u8),
    690		.array_type	= NO_ARRAY,
    691		.tlv_type	= 0,
    692		.offset		= offsetof(struct qmi_wlanfw_mem_seg_resp_s_v01, restore),
    693	},
    694	{
    695		.data_type	= QMI_EOTI,
    696		.array_type	= NO_ARRAY,
    697		.tlv_type	= QMI_COMMON_TLV_TYPE,
    698	},
    699};
    700
    701static struct qmi_elem_info qmi_wlanfw_respond_mem_req_msg_v01_ei[] = {
    702	{
    703		.data_type	= QMI_DATA_LEN,
    704		.elem_len	= 1,
    705		.elem_size	= sizeof(u8),
    706		.array_type	= NO_ARRAY,
    707		.tlv_type	= 0x01,
    708		.offset		= offsetof(struct qmi_wlanfw_respond_mem_req_msg_v01,
    709					   mem_seg_len),
    710	},
    711	{
    712		.data_type	= QMI_STRUCT,
    713		.elem_len	= ATH11K_QMI_WLANFW_MAX_NUM_MEM_SEG_V01,
    714		.elem_size	= sizeof(struct qmi_wlanfw_mem_seg_resp_s_v01),
    715		.array_type	= VAR_LEN_ARRAY,
    716		.tlv_type	= 0x01,
    717		.offset		= offsetof(struct qmi_wlanfw_respond_mem_req_msg_v01,
    718					   mem_seg),
    719		.ei_array	= qmi_wlanfw_mem_seg_resp_s_v01_ei,
    720	},
    721	{
    722		.data_type	= QMI_EOTI,
    723		.array_type	= NO_ARRAY,
    724		.tlv_type	= QMI_COMMON_TLV_TYPE,
    725	},
    726};
    727
    728static struct qmi_elem_info qmi_wlanfw_respond_mem_resp_msg_v01_ei[] = {
    729	{
    730		.data_type	= QMI_STRUCT,
    731		.elem_len	= 1,
    732		.elem_size	= sizeof(struct qmi_response_type_v01),
    733		.array_type	= NO_ARRAY,
    734		.tlv_type	= 0x02,
    735		.offset		= offsetof(struct qmi_wlanfw_respond_mem_resp_msg_v01,
    736					   resp),
    737		.ei_array	= qmi_response_type_v01_ei,
    738	},
    739	{
    740		.data_type	= QMI_EOTI,
    741		.array_type	= NO_ARRAY,
    742		.tlv_type	= QMI_COMMON_TLV_TYPE,
    743	},
    744};
    745
    746static struct qmi_elem_info qmi_wlanfw_cap_req_msg_v01_ei[] = {
    747	{
    748		.data_type	= QMI_EOTI,
    749		.array_type	= NO_ARRAY,
    750		.tlv_type	= QMI_COMMON_TLV_TYPE,
    751	},
    752};
    753
    754static struct qmi_elem_info qmi_wlanfw_device_info_req_msg_v01_ei[] = {
    755	{
    756		.data_type      = QMI_EOTI,
    757		.array_type     = NO_ARRAY,
    758		.tlv_type       = QMI_COMMON_TLV_TYPE,
    759	},
    760};
    761
    762static struct qmi_elem_info qmi_wlfw_device_info_resp_msg_v01_ei[] = {
    763	{
    764		.data_type	= QMI_STRUCT,
    765		.elem_len	= 1,
    766		.elem_size	= sizeof(struct qmi_response_type_v01),
    767		.array_type	= NO_ARRAY,
    768		.tlv_type	= 0x02,
    769		.offset		= offsetof(struct qmi_wlanfw_device_info_resp_msg_v01,
    770					   resp),
    771		.ei_array	= qmi_response_type_v01_ei,
    772	},
    773	{
    774		.data_type	= QMI_OPT_FLAG,
    775		.elem_len	= 1,
    776		.elem_size	= sizeof(u8),
    777		.array_type	= NO_ARRAY,
    778		.tlv_type	= 0x10,
    779		.offset		= offsetof(struct qmi_wlanfw_device_info_resp_msg_v01,
    780					   bar_addr_valid),
    781	},
    782	{
    783		.data_type	= QMI_UNSIGNED_8_BYTE,
    784		.elem_len	= 1,
    785		.elem_size	= sizeof(u64),
    786		.array_type	= NO_ARRAY,
    787		.tlv_type	= 0x10,
    788		.offset		= offsetof(struct qmi_wlanfw_device_info_resp_msg_v01,
    789					   bar_addr),
    790	},
    791	{
    792		.data_type	= QMI_OPT_FLAG,
    793		.elem_len	= 1,
    794		.elem_size	= sizeof(u8),
    795		.array_type	= NO_ARRAY,
    796		.tlv_type	= 0x11,
    797		.offset		= offsetof(struct qmi_wlanfw_device_info_resp_msg_v01,
    798					   bar_size_valid),
    799	},
    800	{
    801		.data_type	= QMI_UNSIGNED_4_BYTE,
    802		.elem_len	= 1,
    803		.elem_size	= sizeof(u32),
    804		.array_type	= NO_ARRAY,
    805		.tlv_type	= 0x11,
    806		.offset		= offsetof(struct qmi_wlanfw_device_info_resp_msg_v01,
    807					   bar_size),
    808	},
    809	{
    810		.data_type	= QMI_EOTI,
    811		.array_type	= NO_ARRAY,
    812		.tlv_type	= QMI_COMMON_TLV_TYPE,
    813	},
    814};
    815
    816static struct qmi_elem_info qmi_wlanfw_rf_chip_info_s_v01_ei[] = {
    817	{
    818		.data_type	= QMI_UNSIGNED_4_BYTE,
    819		.elem_len	= 1,
    820		.elem_size	= sizeof(u32),
    821		.array_type	= NO_ARRAY,
    822		.tlv_type	= 0,
    823		.offset		= offsetof(struct qmi_wlanfw_rf_chip_info_s_v01,
    824					   chip_id),
    825	},
    826	{
    827		.data_type	= QMI_UNSIGNED_4_BYTE,
    828		.elem_len	= 1,
    829		.elem_size	= sizeof(u32),
    830		.array_type	= NO_ARRAY,
    831		.tlv_type	= 0,
    832		.offset		= offsetof(struct qmi_wlanfw_rf_chip_info_s_v01,
    833					   chip_family),
    834	},
    835	{
    836		.data_type	= QMI_EOTI,
    837		.array_type	= NO_ARRAY,
    838		.tlv_type	= QMI_COMMON_TLV_TYPE,
    839	},
    840};
    841
    842static struct qmi_elem_info qmi_wlanfw_rf_board_info_s_v01_ei[] = {
    843	{
    844		.data_type	= QMI_UNSIGNED_4_BYTE,
    845		.elem_len	= 1,
    846		.elem_size	= sizeof(u32),
    847		.array_type	= NO_ARRAY,
    848		.tlv_type	= 0,
    849		.offset		= offsetof(struct qmi_wlanfw_rf_board_info_s_v01,
    850					   board_id),
    851	},
    852	{
    853		.data_type	= QMI_EOTI,
    854		.array_type	= NO_ARRAY,
    855		.tlv_type	= QMI_COMMON_TLV_TYPE,
    856	},
    857};
    858
    859static struct qmi_elem_info qmi_wlanfw_soc_info_s_v01_ei[] = {
    860	{
    861		.data_type	= QMI_UNSIGNED_4_BYTE,
    862		.elem_len	= 1,
    863		.elem_size	= sizeof(u32),
    864		.array_type	= NO_ARRAY,
    865		.tlv_type	= 0,
    866		.offset		= offsetof(struct qmi_wlanfw_soc_info_s_v01, soc_id),
    867	},
    868	{
    869		.data_type	= QMI_EOTI,
    870		.array_type	= NO_ARRAY,
    871		.tlv_type	= QMI_COMMON_TLV_TYPE,
    872	},
    873};
    874
    875static struct qmi_elem_info qmi_wlanfw_fw_version_info_s_v01_ei[] = {
    876	{
    877		.data_type	= QMI_UNSIGNED_4_BYTE,
    878		.elem_len	= 1,
    879		.elem_size	= sizeof(u32),
    880		.array_type	= NO_ARRAY,
    881		.tlv_type	= 0,
    882		.offset		= offsetof(struct qmi_wlanfw_fw_version_info_s_v01,
    883					   fw_version),
    884	},
    885	{
    886		.data_type	= QMI_STRING,
    887		.elem_len	= ATH11K_QMI_WLANFW_MAX_TIMESTAMP_LEN_V01 + 1,
    888		.elem_size	= sizeof(char),
    889		.array_type	= NO_ARRAY,
    890		.tlv_type	= 0,
    891		.offset		= offsetof(struct qmi_wlanfw_fw_version_info_s_v01,
    892					   fw_build_timestamp),
    893	},
    894	{
    895		.data_type	= QMI_EOTI,
    896		.array_type	= NO_ARRAY,
    897		.tlv_type	= QMI_COMMON_TLV_TYPE,
    898	},
    899};
    900
    901static struct qmi_elem_info qmi_wlanfw_cap_resp_msg_v01_ei[] = {
    902	{
    903		.data_type	= QMI_STRUCT,
    904		.elem_len	= 1,
    905		.elem_size	= sizeof(struct qmi_response_type_v01),
    906		.array_type	= NO_ARRAY,
    907		.tlv_type	= 0x02,
    908		.offset		= offsetof(struct qmi_wlanfw_cap_resp_msg_v01, resp),
    909		.ei_array	= qmi_response_type_v01_ei,
    910	},
    911	{
    912		.data_type	= QMI_OPT_FLAG,
    913		.elem_len	= 1,
    914		.elem_size	= sizeof(u8),
    915		.array_type	= NO_ARRAY,
    916		.tlv_type	= 0x10,
    917		.offset		= offsetof(struct qmi_wlanfw_cap_resp_msg_v01,
    918					   chip_info_valid),
    919	},
    920	{
    921		.data_type	= QMI_STRUCT,
    922		.elem_len	= 1,
    923		.elem_size	= sizeof(struct qmi_wlanfw_rf_chip_info_s_v01),
    924		.array_type	= NO_ARRAY,
    925		.tlv_type	= 0x10,
    926		.offset		= offsetof(struct qmi_wlanfw_cap_resp_msg_v01,
    927					   chip_info),
    928		.ei_array	= qmi_wlanfw_rf_chip_info_s_v01_ei,
    929	},
    930	{
    931		.data_type	= QMI_OPT_FLAG,
    932		.elem_len	= 1,
    933		.elem_size	= sizeof(u8),
    934		.array_type	= NO_ARRAY,
    935		.tlv_type	= 0x11,
    936		.offset		= offsetof(struct qmi_wlanfw_cap_resp_msg_v01,
    937					   board_info_valid),
    938	},
    939	{
    940		.data_type	= QMI_STRUCT,
    941		.elem_len	= 1,
    942		.elem_size	= sizeof(struct qmi_wlanfw_rf_board_info_s_v01),
    943		.array_type	= NO_ARRAY,
    944		.tlv_type	= 0x11,
    945		.offset		= offsetof(struct qmi_wlanfw_cap_resp_msg_v01,
    946					   board_info),
    947		.ei_array	= qmi_wlanfw_rf_board_info_s_v01_ei,
    948	},
    949	{
    950		.data_type	= QMI_OPT_FLAG,
    951		.elem_len	= 1,
    952		.elem_size	= sizeof(u8),
    953		.array_type	= NO_ARRAY,
    954		.tlv_type	= 0x12,
    955		.offset		= offsetof(struct qmi_wlanfw_cap_resp_msg_v01,
    956					   soc_info_valid),
    957	},
    958	{
    959		.data_type	= QMI_STRUCT,
    960		.elem_len	= 1,
    961		.elem_size	= sizeof(struct qmi_wlanfw_soc_info_s_v01),
    962		.array_type	= NO_ARRAY,
    963		.tlv_type	= 0x12,
    964		.offset		= offsetof(struct qmi_wlanfw_cap_resp_msg_v01,
    965					   soc_info),
    966		.ei_array	= qmi_wlanfw_soc_info_s_v01_ei,
    967	},
    968	{
    969		.data_type	= QMI_OPT_FLAG,
    970		.elem_len	= 1,
    971		.elem_size	= sizeof(u8),
    972		.array_type	= NO_ARRAY,
    973		.tlv_type	= 0x13,
    974		.offset		= offsetof(struct qmi_wlanfw_cap_resp_msg_v01,
    975					   fw_version_info_valid),
    976	},
    977	{
    978		.data_type	= QMI_STRUCT,
    979		.elem_len	= 1,
    980		.elem_size	= sizeof(struct qmi_wlanfw_fw_version_info_s_v01),
    981		.array_type	= NO_ARRAY,
    982		.tlv_type	= 0x13,
    983		.offset		= offsetof(struct qmi_wlanfw_cap_resp_msg_v01,
    984					   fw_version_info),
    985		.ei_array	= qmi_wlanfw_fw_version_info_s_v01_ei,
    986	},
    987	{
    988		.data_type	= QMI_OPT_FLAG,
    989		.elem_len	= 1,
    990		.elem_size	= sizeof(u8),
    991		.array_type	= NO_ARRAY,
    992		.tlv_type	= 0x14,
    993		.offset		= offsetof(struct qmi_wlanfw_cap_resp_msg_v01,
    994					   fw_build_id_valid),
    995	},
    996	{
    997		.data_type	= QMI_STRING,
    998		.elem_len	= ATH11K_QMI_WLANFW_MAX_BUILD_ID_LEN_V01 + 1,
    999		.elem_size	= sizeof(char),
   1000		.array_type	= NO_ARRAY,
   1001		.tlv_type	= 0x14,
   1002		.offset		= offsetof(struct qmi_wlanfw_cap_resp_msg_v01,
   1003					   fw_build_id),
   1004	},
   1005	{
   1006		.data_type	= QMI_OPT_FLAG,
   1007		.elem_len	= 1,
   1008		.elem_size	= sizeof(u8),
   1009		.array_type	= NO_ARRAY,
   1010		.tlv_type	= 0x15,
   1011		.offset		= offsetof(struct qmi_wlanfw_cap_resp_msg_v01,
   1012					   num_macs_valid),
   1013	},
   1014	{
   1015		.data_type	= QMI_UNSIGNED_1_BYTE,
   1016		.elem_len	= 1,
   1017		.elem_size	= sizeof(u8),
   1018		.array_type	= NO_ARRAY,
   1019		.tlv_type	= 0x15,
   1020		.offset		= offsetof(struct qmi_wlanfw_cap_resp_msg_v01,
   1021					   num_macs),
   1022	},
   1023	{
   1024		.data_type      = QMI_OPT_FLAG,
   1025		.elem_len       = 1,
   1026		.elem_size      = sizeof(u8),
   1027		.array_type     = NO_ARRAY,
   1028		.tlv_type       = 0x16,
   1029		.offset         = offsetof(struct qmi_wlanfw_cap_resp_msg_v01,
   1030					   voltage_mv_valid),
   1031	},
   1032	{
   1033		.data_type      = QMI_UNSIGNED_4_BYTE,
   1034		.elem_len       = 1,
   1035		.elem_size      = sizeof(u32),
   1036		.array_type     = NO_ARRAY,
   1037		.tlv_type       = 0x16,
   1038		.offset         = offsetof(struct qmi_wlanfw_cap_resp_msg_v01,
   1039					   voltage_mv),
   1040	},
   1041	{
   1042		.data_type      = QMI_OPT_FLAG,
   1043		.elem_len       = 1,
   1044		.elem_size      = sizeof(u8),
   1045		.array_type     = NO_ARRAY,
   1046		.tlv_type       = 0x17,
   1047		.offset         = offsetof(struct qmi_wlanfw_cap_resp_msg_v01,
   1048					   time_freq_hz_valid),
   1049	},
   1050	{
   1051		.data_type      = QMI_UNSIGNED_4_BYTE,
   1052		.elem_len       = 1,
   1053		.elem_size      = sizeof(u32),
   1054		.array_type     = NO_ARRAY,
   1055		.tlv_type       = 0x17,
   1056		.offset         = offsetof(struct qmi_wlanfw_cap_resp_msg_v01,
   1057					   time_freq_hz),
   1058	},
   1059	{
   1060		.data_type      = QMI_OPT_FLAG,
   1061		.elem_len       = 1,
   1062		.elem_size      = sizeof(u8),
   1063		.array_type     = NO_ARRAY,
   1064		.tlv_type       = 0x18,
   1065		.offset         = offsetof(struct qmi_wlanfw_cap_resp_msg_v01,
   1066					   otp_version_valid),
   1067	},
   1068	{
   1069		.data_type      = QMI_UNSIGNED_4_BYTE,
   1070		.elem_len       = 1,
   1071		.elem_size      = sizeof(u32),
   1072		.array_type     = NO_ARRAY,
   1073		.tlv_type       = 0x18,
   1074		.offset         = offsetof(struct qmi_wlanfw_cap_resp_msg_v01,
   1075					   otp_version),
   1076	},
   1077	{
   1078		.data_type      = QMI_OPT_FLAG,
   1079		.elem_len       = 1,
   1080		.elem_size      = sizeof(u8),
   1081		.array_type     = NO_ARRAY,
   1082		.tlv_type       = 0x19,
   1083		.offset         = offsetof(struct qmi_wlanfw_cap_resp_msg_v01,
   1084					   eeprom_read_timeout_valid),
   1085	},
   1086	{
   1087		.data_type      = QMI_UNSIGNED_4_BYTE,
   1088		.elem_len       = 1,
   1089		.elem_size      = sizeof(u32),
   1090		.array_type     = NO_ARRAY,
   1091		.tlv_type       = 0x19,
   1092		.offset         = offsetof(struct qmi_wlanfw_cap_resp_msg_v01,
   1093					   eeprom_read_timeout),
   1094	},
   1095	{
   1096		.data_type	= QMI_EOTI,
   1097		.array_type	= NO_ARRAY,
   1098		.tlv_type	= QMI_COMMON_TLV_TYPE,
   1099	},
   1100};
   1101
   1102static struct qmi_elem_info qmi_wlanfw_bdf_download_req_msg_v01_ei[] = {
   1103	{
   1104		.data_type	= QMI_UNSIGNED_1_BYTE,
   1105		.elem_len	= 1,
   1106		.elem_size	= sizeof(u8),
   1107		.array_type	= NO_ARRAY,
   1108		.tlv_type	= 0x01,
   1109		.offset		= offsetof(struct qmi_wlanfw_bdf_download_req_msg_v01,
   1110					   valid),
   1111	},
   1112	{
   1113		.data_type	= QMI_OPT_FLAG,
   1114		.elem_len	= 1,
   1115		.elem_size	= sizeof(u8),
   1116		.array_type	= NO_ARRAY,
   1117		.tlv_type	= 0x10,
   1118		.offset		= offsetof(struct qmi_wlanfw_bdf_download_req_msg_v01,
   1119					   file_id_valid),
   1120	},
   1121	{
   1122		.data_type	= QMI_SIGNED_4_BYTE_ENUM,
   1123		.elem_len	= 1,
   1124		.elem_size	= sizeof(enum qmi_wlanfw_cal_temp_id_enum_v01),
   1125		.array_type	= NO_ARRAY,
   1126		.tlv_type	= 0x10,
   1127		.offset		= offsetof(struct qmi_wlanfw_bdf_download_req_msg_v01,
   1128					   file_id),
   1129	},
   1130	{
   1131		.data_type	= QMI_OPT_FLAG,
   1132		.elem_len	= 1,
   1133		.elem_size	= sizeof(u8),
   1134		.array_type	= NO_ARRAY,
   1135		.tlv_type	= 0x11,
   1136		.offset		= offsetof(struct qmi_wlanfw_bdf_download_req_msg_v01,
   1137					   total_size_valid),
   1138	},
   1139	{
   1140		.data_type	= QMI_UNSIGNED_4_BYTE,
   1141		.elem_len	= 1,
   1142		.elem_size	= sizeof(u32),
   1143		.array_type	= NO_ARRAY,
   1144		.tlv_type	= 0x11,
   1145		.offset		= offsetof(struct qmi_wlanfw_bdf_download_req_msg_v01,
   1146					   total_size),
   1147	},
   1148	{
   1149		.data_type	= QMI_OPT_FLAG,
   1150		.elem_len	= 1,
   1151		.elem_size	= sizeof(u8),
   1152		.array_type	= NO_ARRAY,
   1153		.tlv_type	= 0x12,
   1154		.offset		= offsetof(struct qmi_wlanfw_bdf_download_req_msg_v01,
   1155					   seg_id_valid),
   1156	},
   1157	{
   1158		.data_type	= QMI_UNSIGNED_4_BYTE,
   1159		.elem_len	= 1,
   1160		.elem_size	= sizeof(u32),
   1161		.array_type	= NO_ARRAY,
   1162		.tlv_type	= 0x12,
   1163		.offset		= offsetof(struct qmi_wlanfw_bdf_download_req_msg_v01,
   1164					   seg_id),
   1165	},
   1166	{
   1167		.data_type	= QMI_OPT_FLAG,
   1168		.elem_len	= 1,
   1169		.elem_size	= sizeof(u8),
   1170		.array_type	= NO_ARRAY,
   1171		.tlv_type	= 0x13,
   1172		.offset		= offsetof(struct qmi_wlanfw_bdf_download_req_msg_v01,
   1173					   data_valid),
   1174	},
   1175	{
   1176		.data_type	= QMI_DATA_LEN,
   1177		.elem_len	= 1,
   1178		.elem_size	= sizeof(u16),
   1179		.array_type	= NO_ARRAY,
   1180		.tlv_type	= 0x13,
   1181		.offset		= offsetof(struct qmi_wlanfw_bdf_download_req_msg_v01,
   1182					   data_len),
   1183	},
   1184	{
   1185		.data_type	= QMI_UNSIGNED_1_BYTE,
   1186		.elem_len	= QMI_WLANFW_MAX_DATA_SIZE_V01,
   1187		.elem_size	= sizeof(u8),
   1188		.array_type	= VAR_LEN_ARRAY,
   1189		.tlv_type	= 0x13,
   1190		.offset		= offsetof(struct qmi_wlanfw_bdf_download_req_msg_v01,
   1191					   data),
   1192	},
   1193	{
   1194		.data_type	= QMI_OPT_FLAG,
   1195		.elem_len	= 1,
   1196		.elem_size	= sizeof(u8),
   1197		.array_type	= NO_ARRAY,
   1198		.tlv_type	= 0x14,
   1199		.offset		= offsetof(struct qmi_wlanfw_bdf_download_req_msg_v01,
   1200					   end_valid),
   1201	},
   1202	{
   1203		.data_type	= QMI_UNSIGNED_1_BYTE,
   1204		.elem_len	= 1,
   1205		.elem_size	= sizeof(u8),
   1206		.array_type	= NO_ARRAY,
   1207		.tlv_type	= 0x14,
   1208		.offset		= offsetof(struct qmi_wlanfw_bdf_download_req_msg_v01,
   1209					   end),
   1210	},
   1211	{
   1212		.data_type	= QMI_OPT_FLAG,
   1213		.elem_len	= 1,
   1214		.elem_size	= sizeof(u8),
   1215		.array_type	= NO_ARRAY,
   1216		.tlv_type	= 0x15,
   1217		.offset		= offsetof(struct qmi_wlanfw_bdf_download_req_msg_v01,
   1218					   bdf_type_valid),
   1219	},
   1220	{
   1221		.data_type	= QMI_UNSIGNED_1_BYTE,
   1222		.elem_len	= 1,
   1223		.elem_size	= sizeof(u8),
   1224		.array_type	= NO_ARRAY,
   1225		.tlv_type	= 0x15,
   1226		.offset		= offsetof(struct qmi_wlanfw_bdf_download_req_msg_v01,
   1227					   bdf_type),
   1228	},
   1229
   1230	{
   1231		.data_type	= QMI_EOTI,
   1232		.array_type	= NO_ARRAY,
   1233		.tlv_type	= QMI_COMMON_TLV_TYPE,
   1234	},
   1235};
   1236
   1237static struct qmi_elem_info qmi_wlanfw_bdf_download_resp_msg_v01_ei[] = {
   1238	{
   1239		.data_type	= QMI_STRUCT,
   1240		.elem_len	= 1,
   1241		.elem_size	= sizeof(struct qmi_response_type_v01),
   1242		.array_type	= NO_ARRAY,
   1243		.tlv_type	= 0x02,
   1244		.offset		= offsetof(struct qmi_wlanfw_bdf_download_resp_msg_v01,
   1245					   resp),
   1246		.ei_array	= qmi_response_type_v01_ei,
   1247	},
   1248	{
   1249		.data_type	= QMI_EOTI,
   1250		.array_type	= NO_ARRAY,
   1251		.tlv_type	= QMI_COMMON_TLV_TYPE,
   1252	},
   1253};
   1254
   1255static struct qmi_elem_info qmi_wlanfw_m3_info_req_msg_v01_ei[] = {
   1256	{
   1257		.data_type	= QMI_UNSIGNED_8_BYTE,
   1258		.elem_len	= 1,
   1259		.elem_size	= sizeof(u64),
   1260		.array_type	= NO_ARRAY,
   1261		.tlv_type	= 0x01,
   1262		.offset		= offsetof(struct qmi_wlanfw_m3_info_req_msg_v01, addr),
   1263	},
   1264	{
   1265		.data_type	= QMI_UNSIGNED_4_BYTE,
   1266		.elem_len	= 1,
   1267		.elem_size	= sizeof(u32),
   1268		.array_type	= NO_ARRAY,
   1269		.tlv_type	= 0x02,
   1270		.offset		= offsetof(struct qmi_wlanfw_m3_info_req_msg_v01, size),
   1271	},
   1272	{
   1273		.data_type	= QMI_EOTI,
   1274		.array_type	= NO_ARRAY,
   1275		.tlv_type	= QMI_COMMON_TLV_TYPE,
   1276	},
   1277};
   1278
   1279static struct qmi_elem_info qmi_wlanfw_m3_info_resp_msg_v01_ei[] = {
   1280	{
   1281		.data_type	= QMI_STRUCT,
   1282		.elem_len	= 1,
   1283		.elem_size	= sizeof(struct qmi_response_type_v01),
   1284		.array_type	= NO_ARRAY,
   1285		.tlv_type	= 0x02,
   1286		.offset		= offsetof(struct qmi_wlanfw_m3_info_resp_msg_v01, resp),
   1287		.ei_array	= qmi_response_type_v01_ei,
   1288	},
   1289	{
   1290		.data_type	= QMI_EOTI,
   1291		.array_type	= NO_ARRAY,
   1292		.tlv_type	= QMI_COMMON_TLV_TYPE,
   1293	},
   1294};
   1295
   1296static struct qmi_elem_info qmi_wlanfw_ce_tgt_pipe_cfg_s_v01_ei[] = {
   1297	{
   1298		.data_type	= QMI_UNSIGNED_4_BYTE,
   1299		.elem_len	= 1,
   1300		.elem_size	= sizeof(u32),
   1301		.array_type	= NO_ARRAY,
   1302		.tlv_type	= 0,
   1303		.offset		= offsetof(struct qmi_wlanfw_ce_tgt_pipe_cfg_s_v01,
   1304					   pipe_num),
   1305	},
   1306	{
   1307		.data_type	= QMI_SIGNED_4_BYTE_ENUM,
   1308		.elem_len	= 1,
   1309		.elem_size	= sizeof(enum qmi_wlanfw_pipedir_enum_v01),
   1310		.array_type	= NO_ARRAY,
   1311		.tlv_type	= 0,
   1312		.offset		= offsetof(struct qmi_wlanfw_ce_tgt_pipe_cfg_s_v01,
   1313					   pipe_dir),
   1314	},
   1315	{
   1316		.data_type	= QMI_UNSIGNED_4_BYTE,
   1317		.elem_len	= 1,
   1318		.elem_size	= sizeof(u32),
   1319		.array_type	= NO_ARRAY,
   1320		.tlv_type	= 0,
   1321		.offset		= offsetof(struct qmi_wlanfw_ce_tgt_pipe_cfg_s_v01,
   1322					   nentries),
   1323	},
   1324	{
   1325		.data_type	= QMI_UNSIGNED_4_BYTE,
   1326		.elem_len	= 1,
   1327		.elem_size	= sizeof(u32),
   1328		.array_type	= NO_ARRAY,
   1329		.tlv_type	= 0,
   1330		.offset		= offsetof(struct qmi_wlanfw_ce_tgt_pipe_cfg_s_v01,
   1331					   nbytes_max),
   1332	},
   1333	{
   1334		.data_type	= QMI_UNSIGNED_4_BYTE,
   1335		.elem_len	= 1,
   1336		.elem_size	= sizeof(u32),
   1337		.array_type	= NO_ARRAY,
   1338		.tlv_type	= 0,
   1339		.offset		= offsetof(struct qmi_wlanfw_ce_tgt_pipe_cfg_s_v01,
   1340					   flags),
   1341	},
   1342	{
   1343		.data_type	= QMI_EOTI,
   1344		.array_type	= NO_ARRAY,
   1345		.tlv_type	= QMI_COMMON_TLV_TYPE,
   1346	},
   1347};
   1348
   1349static struct qmi_elem_info qmi_wlanfw_ce_svc_pipe_cfg_s_v01_ei[] = {
   1350	{
   1351		.data_type	= QMI_UNSIGNED_4_BYTE,
   1352		.elem_len	= 1,
   1353		.elem_size	= sizeof(u32),
   1354		.array_type	= NO_ARRAY,
   1355		.tlv_type	= 0,
   1356		.offset		= offsetof(struct qmi_wlanfw_ce_svc_pipe_cfg_s_v01,
   1357					   service_id),
   1358	},
   1359	{
   1360		.data_type	= QMI_SIGNED_4_BYTE_ENUM,
   1361		.elem_len	= 1,
   1362		.elem_size	= sizeof(enum qmi_wlanfw_pipedir_enum_v01),
   1363		.array_type	= NO_ARRAY,
   1364		.tlv_type	= 0,
   1365		.offset		= offsetof(struct qmi_wlanfw_ce_svc_pipe_cfg_s_v01,
   1366					   pipe_dir),
   1367	},
   1368	{
   1369		.data_type	= QMI_UNSIGNED_4_BYTE,
   1370		.elem_len	= 1,
   1371		.elem_size	= sizeof(u32),
   1372		.array_type	= NO_ARRAY,
   1373		.tlv_type	= 0,
   1374		.offset		= offsetof(struct qmi_wlanfw_ce_svc_pipe_cfg_s_v01,
   1375					   pipe_num),
   1376	},
   1377	{
   1378		.data_type	= QMI_EOTI,
   1379		.array_type	= NO_ARRAY,
   1380		.tlv_type	= QMI_COMMON_TLV_TYPE,
   1381	},
   1382};
   1383
   1384static struct qmi_elem_info qmi_wlanfw_shadow_reg_cfg_s_v01_ei[] = {
   1385	{
   1386		.data_type	= QMI_UNSIGNED_2_BYTE,
   1387		.elem_len	= 1,
   1388		.elem_size	= sizeof(u16),
   1389		.array_type	= NO_ARRAY,
   1390		.tlv_type	= 0,
   1391		.offset		= offsetof(struct qmi_wlanfw_shadow_reg_cfg_s_v01, id),
   1392	},
   1393	{
   1394		.data_type	= QMI_UNSIGNED_2_BYTE,
   1395		.elem_len	= 1,
   1396		.elem_size	= sizeof(u16),
   1397		.array_type	= NO_ARRAY,
   1398		.tlv_type	= 0,
   1399		.offset		= offsetof(struct qmi_wlanfw_shadow_reg_cfg_s_v01,
   1400					   offset),
   1401	},
   1402	{
   1403		.data_type	= QMI_EOTI,
   1404		.array_type	= QMI_COMMON_TLV_TYPE,
   1405	},
   1406};
   1407
   1408static struct qmi_elem_info qmi_wlanfw_shadow_reg_v2_cfg_s_v01_ei[] = {
   1409	{
   1410		.data_type	= QMI_UNSIGNED_4_BYTE,
   1411		.elem_len	= 1,
   1412		.elem_size	= sizeof(u32),
   1413		.array_type	= NO_ARRAY,
   1414		.tlv_type	= 0,
   1415		.offset		= offsetof(struct qmi_wlanfw_shadow_reg_v2_cfg_s_v01,
   1416					   addr),
   1417	},
   1418	{
   1419		.data_type	= QMI_EOTI,
   1420		.array_type	= NO_ARRAY,
   1421		.tlv_type	= QMI_COMMON_TLV_TYPE,
   1422	},
   1423};
   1424
   1425static struct qmi_elem_info qmi_wlanfw_wlan_mode_req_msg_v01_ei[] = {
   1426	{
   1427		.data_type	= QMI_UNSIGNED_4_BYTE,
   1428		.elem_len	= 1,
   1429		.elem_size	= sizeof(u32),
   1430		.array_type	= NO_ARRAY,
   1431		.tlv_type	= 0x01,
   1432		.offset		= offsetof(struct qmi_wlanfw_wlan_mode_req_msg_v01,
   1433					   mode),
   1434	},
   1435	{
   1436		.data_type	= QMI_OPT_FLAG,
   1437		.elem_len	= 1,
   1438		.elem_size	= sizeof(u8),
   1439		.array_type	= NO_ARRAY,
   1440		.tlv_type	= 0x10,
   1441		.offset		= offsetof(struct qmi_wlanfw_wlan_mode_req_msg_v01,
   1442					   hw_debug_valid),
   1443	},
   1444	{
   1445		.data_type	= QMI_UNSIGNED_1_BYTE,
   1446		.elem_len	= 1,
   1447		.elem_size	= sizeof(u8),
   1448		.array_type	= NO_ARRAY,
   1449		.tlv_type	= 0x10,
   1450		.offset		= offsetof(struct qmi_wlanfw_wlan_mode_req_msg_v01,
   1451					   hw_debug),
   1452	},
   1453	{
   1454		.data_type	= QMI_EOTI,
   1455		.array_type	= NO_ARRAY,
   1456		.tlv_type	= QMI_COMMON_TLV_TYPE,
   1457	},
   1458};
   1459
   1460static struct qmi_elem_info qmi_wlanfw_wlan_mode_resp_msg_v01_ei[] = {
   1461	{
   1462		.data_type	= QMI_STRUCT,
   1463		.elem_len	= 1,
   1464		.elem_size	= sizeof(struct qmi_response_type_v01),
   1465		.array_type	= NO_ARRAY,
   1466		.tlv_type	= 0x02,
   1467		.offset		= offsetof(struct qmi_wlanfw_wlan_mode_resp_msg_v01,
   1468					   resp),
   1469		.ei_array	= qmi_response_type_v01_ei,
   1470	},
   1471	{
   1472		.data_type	= QMI_EOTI,
   1473		.array_type	= NO_ARRAY,
   1474		.tlv_type	= QMI_COMMON_TLV_TYPE,
   1475	},
   1476};
   1477
   1478static struct qmi_elem_info qmi_wlanfw_wlan_cfg_req_msg_v01_ei[] = {
   1479	{
   1480		.data_type	= QMI_OPT_FLAG,
   1481		.elem_len	= 1,
   1482		.elem_size	= sizeof(u8),
   1483		.array_type	= NO_ARRAY,
   1484		.tlv_type	= 0x10,
   1485		.offset		= offsetof(struct qmi_wlanfw_wlan_cfg_req_msg_v01,
   1486					   host_version_valid),
   1487	},
   1488	{
   1489		.data_type	= QMI_STRING,
   1490		.elem_len	= QMI_WLANFW_MAX_STR_LEN_V01 + 1,
   1491		.elem_size	= sizeof(char),
   1492		.array_type	= NO_ARRAY,
   1493		.tlv_type	= 0x10,
   1494		.offset		= offsetof(struct qmi_wlanfw_wlan_cfg_req_msg_v01,
   1495					   host_version),
   1496	},
   1497	{
   1498		.data_type	= QMI_OPT_FLAG,
   1499		.elem_len	= 1,
   1500		.elem_size	= sizeof(u8),
   1501		.array_type	= NO_ARRAY,
   1502		.tlv_type	= 0x11,
   1503		.offset		= offsetof(struct qmi_wlanfw_wlan_cfg_req_msg_v01,
   1504					   tgt_cfg_valid),
   1505	},
   1506	{
   1507		.data_type	= QMI_DATA_LEN,
   1508		.elem_len	= 1,
   1509		.elem_size	= sizeof(u8),
   1510		.array_type	= NO_ARRAY,
   1511		.tlv_type	= 0x11,
   1512		.offset		= offsetof(struct qmi_wlanfw_wlan_cfg_req_msg_v01,
   1513					   tgt_cfg_len),
   1514	},
   1515	{
   1516		.data_type	= QMI_STRUCT,
   1517		.elem_len	= QMI_WLANFW_MAX_NUM_CE_V01,
   1518		.elem_size	= sizeof(
   1519				struct qmi_wlanfw_ce_tgt_pipe_cfg_s_v01),
   1520		.array_type	= VAR_LEN_ARRAY,
   1521		.tlv_type	= 0x11,
   1522		.offset		= offsetof(struct qmi_wlanfw_wlan_cfg_req_msg_v01,
   1523					   tgt_cfg),
   1524		.ei_array	= qmi_wlanfw_ce_tgt_pipe_cfg_s_v01_ei,
   1525	},
   1526	{
   1527		.data_type	= QMI_OPT_FLAG,
   1528		.elem_len	= 1,
   1529		.elem_size	= sizeof(u8),
   1530		.array_type	= NO_ARRAY,
   1531		.tlv_type	= 0x12,
   1532		.offset		= offsetof(struct qmi_wlanfw_wlan_cfg_req_msg_v01,
   1533					   svc_cfg_valid),
   1534	},
   1535	{
   1536		.data_type	= QMI_DATA_LEN,
   1537		.elem_len	= 1,
   1538		.elem_size	= sizeof(u8),
   1539		.array_type	= NO_ARRAY,
   1540		.tlv_type	= 0x12,
   1541		.offset		= offsetof(struct qmi_wlanfw_wlan_cfg_req_msg_v01,
   1542					   svc_cfg_len),
   1543	},
   1544	{
   1545		.data_type	= QMI_STRUCT,
   1546		.elem_len	= QMI_WLANFW_MAX_NUM_SVC_V01,
   1547		.elem_size	= sizeof(struct qmi_wlanfw_ce_svc_pipe_cfg_s_v01),
   1548		.array_type	= VAR_LEN_ARRAY,
   1549		.tlv_type	= 0x12,
   1550		.offset		= offsetof(struct qmi_wlanfw_wlan_cfg_req_msg_v01,
   1551					   svc_cfg),
   1552		.ei_array	= qmi_wlanfw_ce_svc_pipe_cfg_s_v01_ei,
   1553	},
   1554	{
   1555		.data_type	= QMI_OPT_FLAG,
   1556		.elem_len	= 1,
   1557		.elem_size	= sizeof(u8),
   1558		.array_type	= NO_ARRAY,
   1559		.tlv_type	= 0x13,
   1560		.offset		= offsetof(struct qmi_wlanfw_wlan_cfg_req_msg_v01,
   1561					   shadow_reg_valid),
   1562	},
   1563	{
   1564		.data_type	= QMI_DATA_LEN,
   1565		.elem_len	= 1,
   1566		.elem_size	= sizeof(u8),
   1567		.array_type	= NO_ARRAY,
   1568		.tlv_type	= 0x13,
   1569		.offset		= offsetof(struct qmi_wlanfw_wlan_cfg_req_msg_v01,
   1570					   shadow_reg_len),
   1571	},
   1572	{
   1573		.data_type	= QMI_STRUCT,
   1574		.elem_len	= QMI_WLANFW_MAX_NUM_SHADOW_REG_V01,
   1575		.elem_size	= sizeof(struct qmi_wlanfw_shadow_reg_cfg_s_v01),
   1576		.array_type	= VAR_LEN_ARRAY,
   1577		.tlv_type	= 0x13,
   1578		.offset		= offsetof(struct qmi_wlanfw_wlan_cfg_req_msg_v01,
   1579					   shadow_reg),
   1580		.ei_array	= qmi_wlanfw_shadow_reg_cfg_s_v01_ei,
   1581	},
   1582	{
   1583		.data_type	= QMI_OPT_FLAG,
   1584		.elem_len	= 1,
   1585		.elem_size	= sizeof(u8),
   1586		.array_type	= NO_ARRAY,
   1587		.tlv_type	= 0x14,
   1588		.offset		= offsetof(struct qmi_wlanfw_wlan_cfg_req_msg_v01,
   1589					   shadow_reg_v2_valid),
   1590	},
   1591	{
   1592		.data_type	= QMI_DATA_LEN,
   1593		.elem_len	= 1,
   1594		.elem_size	= sizeof(u8),
   1595		.array_type	= NO_ARRAY,
   1596		.tlv_type	= 0x14,
   1597		.offset		= offsetof(struct qmi_wlanfw_wlan_cfg_req_msg_v01,
   1598					   shadow_reg_v2_len),
   1599	},
   1600	{
   1601		.data_type	= QMI_STRUCT,
   1602		.elem_len	= QMI_WLANFW_MAX_NUM_SHADOW_REG_V2_V01,
   1603		.elem_size	= sizeof(struct qmi_wlanfw_shadow_reg_v2_cfg_s_v01),
   1604		.array_type	= VAR_LEN_ARRAY,
   1605		.tlv_type	= 0x14,
   1606		.offset		= offsetof(struct qmi_wlanfw_wlan_cfg_req_msg_v01,
   1607					   shadow_reg_v2),
   1608		.ei_array	= qmi_wlanfw_shadow_reg_v2_cfg_s_v01_ei,
   1609	},
   1610	{
   1611		.data_type	= QMI_EOTI,
   1612		.array_type	= NO_ARRAY,
   1613		.tlv_type	= QMI_COMMON_TLV_TYPE,
   1614	},
   1615};
   1616
   1617static struct qmi_elem_info qmi_wlanfw_wlan_cfg_resp_msg_v01_ei[] = {
   1618	{
   1619		.data_type	= QMI_STRUCT,
   1620		.elem_len	= 1,
   1621		.elem_size	= sizeof(struct qmi_response_type_v01),
   1622		.array_type	= NO_ARRAY,
   1623		.tlv_type	= 0x02,
   1624		.offset		= offsetof(struct qmi_wlanfw_wlan_cfg_resp_msg_v01, resp),
   1625		.ei_array	= qmi_response_type_v01_ei,
   1626	},
   1627	{
   1628		.data_type	= QMI_EOTI,
   1629		.array_type	= NO_ARRAY,
   1630		.tlv_type	= QMI_COMMON_TLV_TYPE,
   1631	},
   1632};
   1633
   1634static struct qmi_elem_info qmi_wlanfw_mem_ready_ind_msg_v01_ei[] = {
   1635	{
   1636		.data_type = QMI_EOTI,
   1637		.array_type = NO_ARRAY,
   1638	},
   1639};
   1640
   1641static struct qmi_elem_info qmi_wlanfw_fw_ready_ind_msg_v01_ei[] = {
   1642	{
   1643		.data_type = QMI_EOTI,
   1644		.array_type = NO_ARRAY,
   1645	},
   1646};
   1647
   1648static struct qmi_elem_info qmi_wlanfw_cold_boot_cal_done_ind_msg_v01_ei[] = {
   1649	{
   1650		.data_type = QMI_EOTI,
   1651		.array_type = NO_ARRAY,
   1652	},
   1653};
   1654
   1655static struct qmi_elem_info qmi_wlanfw_wlan_ini_req_msg_v01_ei[] = {
   1656	{
   1657		.data_type	= QMI_OPT_FLAG,
   1658		.elem_len	= 1,
   1659		.elem_size	= sizeof(u8),
   1660		.array_type	= NO_ARRAY,
   1661		.tlv_type	= 0x10,
   1662		.offset		= offsetof(struct qmi_wlanfw_wlan_ini_req_msg_v01,
   1663					   enablefwlog_valid),
   1664	},
   1665	{
   1666		.data_type	= QMI_UNSIGNED_1_BYTE,
   1667		.elem_len	= 1,
   1668		.elem_size	= sizeof(u8),
   1669		.array_type	= NO_ARRAY,
   1670		.tlv_type	= 0x10,
   1671		.offset		= offsetof(struct qmi_wlanfw_wlan_ini_req_msg_v01,
   1672					   enablefwlog),
   1673	},
   1674	{
   1675		.data_type	= QMI_EOTI,
   1676		.array_type	= NO_ARRAY,
   1677		.tlv_type	= QMI_COMMON_TLV_TYPE,
   1678	},
   1679};
   1680
   1681static struct qmi_elem_info qmi_wlanfw_wlan_ini_resp_msg_v01_ei[] = {
   1682	{
   1683		.data_type	= QMI_STRUCT,
   1684		.elem_len	= 1,
   1685		.elem_size	= sizeof(struct qmi_response_type_v01),
   1686		.array_type	= NO_ARRAY,
   1687		.tlv_type	= 0x02,
   1688		.offset		= offsetof(struct qmi_wlanfw_wlan_ini_resp_msg_v01,
   1689					   resp),
   1690		.ei_array	= qmi_response_type_v01_ei,
   1691	},
   1692	{
   1693		.data_type	= QMI_EOTI,
   1694		.array_type	= NO_ARRAY,
   1695		.tlv_type	= QMI_COMMON_TLV_TYPE,
   1696	},
   1697};
   1698
   1699static int ath11k_qmi_host_cap_send(struct ath11k_base *ab)
   1700{
   1701	struct qmi_wlanfw_host_cap_req_msg_v01 req;
   1702	struct qmi_wlanfw_host_cap_resp_msg_v01 resp;
   1703	struct qmi_txn txn;
   1704	int ret = 0;
   1705
   1706	memset(&req, 0, sizeof(req));
   1707	memset(&resp, 0, sizeof(resp));
   1708
   1709	req.num_clients_valid = 1;
   1710	req.num_clients = 1;
   1711	req.mem_cfg_mode = ab->qmi.target_mem_mode;
   1712	req.mem_cfg_mode_valid = 1;
   1713	req.bdf_support_valid = 1;
   1714	req.bdf_support = 1;
   1715
   1716	if (ab->hw_params.m3_fw_support) {
   1717		req.m3_support_valid = 1;
   1718		req.m3_support = 1;
   1719		req.m3_cache_support_valid = 1;
   1720		req.m3_cache_support = 1;
   1721	} else {
   1722		req.m3_support_valid = 0;
   1723		req.m3_support = 0;
   1724		req.m3_cache_support_valid = 0;
   1725		req.m3_cache_support = 0;
   1726	}
   1727
   1728	req.cal_done_valid = 1;
   1729	req.cal_done = ab->qmi.cal_done;
   1730
   1731	if (ab->hw_params.internal_sleep_clock) {
   1732		req.nm_modem_valid = 1;
   1733
   1734		/* Notify firmware that this is non-qualcomm platform. */
   1735		req.nm_modem |= HOST_CSTATE_BIT;
   1736
   1737		/* Notify firmware about the sleep clock selection,
   1738		 * nm_modem_bit[1] is used for this purpose. Host driver on
   1739		 * non-qualcomm platforms should select internal sleep
   1740		 * clock.
   1741		 */
   1742		req.nm_modem |= SLEEP_CLOCK_SELECT_INTERNAL_BIT;
   1743	}
   1744
   1745	if (ab->hw_params.global_reset)
   1746		req.nm_modem |= PLATFORM_CAP_PCIE_GLOBAL_RESET;
   1747
   1748	ath11k_dbg(ab, ATH11K_DBG_QMI, "qmi host cap request\n");
   1749
   1750	ret = qmi_txn_init(&ab->qmi.handle, &txn,
   1751			   qmi_wlanfw_host_cap_resp_msg_v01_ei, &resp);
   1752	if (ret < 0)
   1753		goto out;
   1754
   1755	ret = qmi_send_request(&ab->qmi.handle, NULL, &txn,
   1756			       QMI_WLANFW_HOST_CAP_REQ_V01,
   1757			       QMI_WLANFW_HOST_CAP_REQ_MSG_V01_MAX_LEN,
   1758			       qmi_wlanfw_host_cap_req_msg_v01_ei, &req);
   1759	if (ret < 0) {
   1760		qmi_txn_cancel(&txn);
   1761		ath11k_warn(ab, "failed to send host capability request: %d\n", ret);
   1762		goto out;
   1763	}
   1764
   1765	ret = qmi_txn_wait(&txn, msecs_to_jiffies(ATH11K_QMI_WLANFW_TIMEOUT_MS));
   1766	if (ret < 0)
   1767		goto out;
   1768
   1769	if (resp.resp.result != QMI_RESULT_SUCCESS_V01) {
   1770		ath11k_warn(ab, "host capability request failed: %d %d\n",
   1771			    resp.resp.result, resp.resp.error);
   1772		ret = -EINVAL;
   1773		goto out;
   1774	}
   1775
   1776out:
   1777	return ret;
   1778}
   1779
   1780static int ath11k_qmi_fw_ind_register_send(struct ath11k_base *ab)
   1781{
   1782	struct qmi_wlanfw_ind_register_req_msg_v01 *req;
   1783	struct qmi_wlanfw_ind_register_resp_msg_v01 *resp;
   1784	struct qmi_handle *handle = &ab->qmi.handle;
   1785	struct qmi_txn txn;
   1786	int ret;
   1787
   1788	req = kzalloc(sizeof(*req), GFP_KERNEL);
   1789	if (!req)
   1790		return -ENOMEM;
   1791
   1792	resp = kzalloc(sizeof(*resp), GFP_KERNEL);
   1793	if (!resp) {
   1794		ret = -ENOMEM;
   1795		goto resp_out;
   1796	}
   1797
   1798	req->client_id_valid = 1;
   1799	req->client_id = QMI_WLANFW_CLIENT_ID;
   1800	req->fw_ready_enable_valid = 1;
   1801	req->fw_ready_enable = 1;
   1802	req->cal_done_enable_valid = 1;
   1803	req->cal_done_enable = 1;
   1804	req->fw_init_done_enable_valid = 1;
   1805	req->fw_init_done_enable = 1;
   1806
   1807	req->pin_connect_result_enable_valid = 0;
   1808	req->pin_connect_result_enable = 0;
   1809
   1810	/* WCN6750 doesn't request for DDR memory via QMI,
   1811	 * instead it uses a fixed 12MB reserved memory
   1812	 * region in DDR.
   1813	 */
   1814	if (!ab->hw_params.fixed_fw_mem) {
   1815		req->request_mem_enable_valid = 1;
   1816		req->request_mem_enable = 1;
   1817		req->fw_mem_ready_enable_valid = 1;
   1818		req->fw_mem_ready_enable = 1;
   1819	}
   1820
   1821	ret = qmi_txn_init(handle, &txn,
   1822			   qmi_wlanfw_ind_register_resp_msg_v01_ei, resp);
   1823	if (ret < 0)
   1824		goto out;
   1825
   1826	ath11k_dbg(ab, ATH11K_DBG_QMI, "qmi indication register request\n");
   1827
   1828	ret = qmi_send_request(&ab->qmi.handle, NULL, &txn,
   1829			       QMI_WLANFW_IND_REGISTER_REQ_V01,
   1830			       QMI_WLANFW_IND_REGISTER_REQ_MSG_V01_MAX_LEN,
   1831			       qmi_wlanfw_ind_register_req_msg_v01_ei, req);
   1832	if (ret < 0) {
   1833		qmi_txn_cancel(&txn);
   1834		ath11k_warn(ab, "failed to send indication register request: %d\n",
   1835			    ret);
   1836		goto out;
   1837	}
   1838
   1839	ret = qmi_txn_wait(&txn, msecs_to_jiffies(ATH11K_QMI_WLANFW_TIMEOUT_MS));
   1840	if (ret < 0) {
   1841		ath11k_warn(ab, "failed to register fw indication: %d\n", ret);
   1842		goto out;
   1843	}
   1844
   1845	if (resp->resp.result != QMI_RESULT_SUCCESS_V01) {
   1846		ath11k_warn(ab, "firmware indication register request failed: %d %d\n",
   1847			    resp->resp.result, resp->resp.error);
   1848		ret = -EINVAL;
   1849		goto out;
   1850	}
   1851
   1852out:
   1853	kfree(resp);
   1854resp_out:
   1855	kfree(req);
   1856	return ret;
   1857}
   1858
   1859static int ath11k_qmi_respond_fw_mem_request(struct ath11k_base *ab)
   1860{
   1861	struct qmi_wlanfw_respond_mem_req_msg_v01 *req;
   1862	struct qmi_wlanfw_respond_mem_resp_msg_v01 resp;
   1863	struct qmi_txn txn;
   1864	int ret = 0, i;
   1865	bool delayed;
   1866
   1867	req = kzalloc(sizeof(*req), GFP_KERNEL);
   1868	if (!req)
   1869		return -ENOMEM;
   1870
   1871	memset(&resp, 0, sizeof(resp));
   1872
   1873	/* For QCA6390 by default FW requests a block of ~4M contiguous
   1874	 * DMA memory, it's hard to allocate from OS. So host returns
   1875	 * failure to FW and FW will then request mulitple blocks of small
   1876	 * chunk size memory.
   1877	 */
   1878	if (!(ab->hw_params.fixed_mem_region ||
   1879	      test_bit(ATH11K_FLAG_FIXED_MEM_RGN, &ab->dev_flags)) &&
   1880	      ab->qmi.target_mem_delayed) {
   1881		delayed = true;
   1882		ath11k_dbg(ab, ATH11K_DBG_QMI, "qmi delays mem_request %d\n",
   1883			   ab->qmi.mem_seg_count);
   1884		memset(req, 0, sizeof(*req));
   1885	} else {
   1886		delayed = false;
   1887		req->mem_seg_len = ab->qmi.mem_seg_count;
   1888
   1889		for (i = 0; i < req->mem_seg_len ; i++) {
   1890			req->mem_seg[i].addr = ab->qmi.target_mem[i].paddr;
   1891			req->mem_seg[i].size = ab->qmi.target_mem[i].size;
   1892			req->mem_seg[i].type = ab->qmi.target_mem[i].type;
   1893			ath11k_dbg(ab, ATH11K_DBG_QMI,
   1894				   "qmi req mem_seg[%d] %pad %u %u\n", i,
   1895				    &ab->qmi.target_mem[i].paddr,
   1896				    ab->qmi.target_mem[i].size,
   1897				    ab->qmi.target_mem[i].type);
   1898		}
   1899	}
   1900
   1901	ret = qmi_txn_init(&ab->qmi.handle, &txn,
   1902			   qmi_wlanfw_respond_mem_resp_msg_v01_ei, &resp);
   1903	if (ret < 0)
   1904		goto out;
   1905
   1906	ath11k_dbg(ab, ATH11K_DBG_QMI, "qmi respond memory request delayed %i\n",
   1907		   delayed);
   1908
   1909	ret = qmi_send_request(&ab->qmi.handle, NULL, &txn,
   1910			       QMI_WLANFW_RESPOND_MEM_REQ_V01,
   1911			       QMI_WLANFW_RESPOND_MEM_REQ_MSG_V01_MAX_LEN,
   1912			       qmi_wlanfw_respond_mem_req_msg_v01_ei, req);
   1913	if (ret < 0) {
   1914		qmi_txn_cancel(&txn);
   1915		ath11k_warn(ab, "failed to respond qmi memory request: %d\n",
   1916			    ret);
   1917		goto out;
   1918	}
   1919
   1920	ret = qmi_txn_wait(&txn, msecs_to_jiffies(ATH11K_QMI_WLANFW_TIMEOUT_MS));
   1921	if (ret < 0) {
   1922		ath11k_warn(ab, "failed to wait qmi memory request: %d\n", ret);
   1923		goto out;
   1924	}
   1925
   1926	if (resp.resp.result != QMI_RESULT_SUCCESS_V01) {
   1927		/* the error response is expected when
   1928		 * target_mem_delayed is true.
   1929		 */
   1930		if (delayed && resp.resp.error == 0)
   1931			goto out;
   1932
   1933		ath11k_warn(ab, "qmi respond memory request failed: %d %d\n",
   1934			    resp.resp.result, resp.resp.error);
   1935		ret = -EINVAL;
   1936		goto out;
   1937	}
   1938out:
   1939	kfree(req);
   1940	return ret;
   1941}
   1942
   1943static void ath11k_qmi_free_target_mem_chunk(struct ath11k_base *ab)
   1944{
   1945	int i;
   1946
   1947	for (i = 0; i < ab->qmi.mem_seg_count; i++) {
   1948		if ((ab->hw_params.fixed_mem_region ||
   1949		     test_bit(ATH11K_FLAG_FIXED_MEM_RGN, &ab->dev_flags)) &&
   1950		     ab->qmi.target_mem[i].iaddr)
   1951			iounmap(ab->qmi.target_mem[i].iaddr);
   1952
   1953		if (!ab->qmi.target_mem[i].vaddr)
   1954			continue;
   1955
   1956		dma_free_coherent(ab->dev,
   1957				  ab->qmi.target_mem[i].size,
   1958				  ab->qmi.target_mem[i].vaddr,
   1959				  ab->qmi.target_mem[i].paddr);
   1960		ab->qmi.target_mem[i].vaddr = NULL;
   1961	}
   1962}
   1963
   1964static int ath11k_qmi_alloc_target_mem_chunk(struct ath11k_base *ab)
   1965{
   1966	int i;
   1967	struct target_mem_chunk *chunk;
   1968
   1969	ab->qmi.target_mem_delayed = false;
   1970
   1971	for (i = 0; i < ab->qmi.mem_seg_count; i++) {
   1972		chunk = &ab->qmi.target_mem[i];
   1973
   1974		/* Firmware reloads in coldboot/firmware recovery.
   1975		 * in such case, no need to allocate memory for FW again.
   1976		 */
   1977		if (chunk->vaddr) {
   1978			if (chunk->prev_type == chunk->type ||
   1979			    chunk->prev_size == chunk->size)
   1980				continue;
   1981
   1982			/* cannot reuse the existing chunk */
   1983			dma_free_coherent(ab->dev, chunk->size,
   1984					  chunk->vaddr, chunk->paddr);
   1985			chunk->vaddr = NULL;
   1986		}
   1987
   1988		chunk->vaddr = dma_alloc_coherent(ab->dev,
   1989						  chunk->size,
   1990						  &chunk->paddr,
   1991						  GFP_KERNEL | __GFP_NOWARN);
   1992		if (!chunk->vaddr) {
   1993			if (ab->qmi.mem_seg_count <= ATH11K_QMI_FW_MEM_REQ_SEGMENT_CNT) {
   1994				ath11k_dbg(ab, ATH11K_DBG_QMI,
   1995					   "qmi dma allocation failed (%d B type %u), will try later with small size\n",
   1996					    chunk->size,
   1997					    chunk->type);
   1998				ath11k_qmi_free_target_mem_chunk(ab);
   1999				ab->qmi.target_mem_delayed = true;
   2000				return 0;
   2001			}
   2002
   2003			ath11k_err(ab, "failed to allocate dma memory for qmi (%d B type %u)\n",
   2004				   chunk->size,
   2005				   chunk->type);
   2006			return -EINVAL;
   2007		}
   2008		chunk->prev_type = chunk->type;
   2009		chunk->prev_size = chunk->size;
   2010	}
   2011
   2012	return 0;
   2013}
   2014
   2015static int ath11k_qmi_assign_target_mem_chunk(struct ath11k_base *ab)
   2016{
   2017	struct device *dev = ab->dev;
   2018	struct device_node *hremote_node = NULL;
   2019	struct resource res;
   2020	u32 host_ddr_sz;
   2021	int i, idx, ret;
   2022
   2023	for (i = 0, idx = 0; i < ab->qmi.mem_seg_count; i++) {
   2024		switch (ab->qmi.target_mem[i].type) {
   2025		case HOST_DDR_REGION_TYPE:
   2026			hremote_node = of_parse_phandle(dev->of_node, "memory-region", 0);
   2027			if (!hremote_node) {
   2028				ath11k_dbg(ab, ATH11K_DBG_QMI,
   2029					   "qmi fail to get hremote_node\n");
   2030				return -ENODEV;
   2031			}
   2032
   2033			ret = of_address_to_resource(hremote_node, 0, &res);
   2034			of_node_put(hremote_node);
   2035			if (ret) {
   2036				ath11k_dbg(ab, ATH11K_DBG_QMI,
   2037					   "qmi fail to get reg from hremote\n");
   2038				return ret;
   2039			}
   2040
   2041			if (res.end - res.start + 1 < ab->qmi.target_mem[i].size) {
   2042				ath11k_dbg(ab, ATH11K_DBG_QMI,
   2043					   "qmi fail to assign memory of sz\n");
   2044				return -EINVAL;
   2045			}
   2046
   2047			ab->qmi.target_mem[idx].paddr = res.start;
   2048			ab->qmi.target_mem[idx].iaddr =
   2049				ioremap(ab->qmi.target_mem[idx].paddr,
   2050					ab->qmi.target_mem[i].size);
   2051			ab->qmi.target_mem[idx].size = ab->qmi.target_mem[i].size;
   2052			host_ddr_sz = ab->qmi.target_mem[i].size;
   2053			ab->qmi.target_mem[idx].type = ab->qmi.target_mem[i].type;
   2054			idx++;
   2055			break;
   2056		case BDF_MEM_REGION_TYPE:
   2057			ab->qmi.target_mem[idx].paddr = ab->hw_params.bdf_addr;
   2058			ab->qmi.target_mem[idx].vaddr = NULL;
   2059			ab->qmi.target_mem[idx].size = ab->qmi.target_mem[i].size;
   2060			ab->qmi.target_mem[idx].type = ab->qmi.target_mem[i].type;
   2061			idx++;
   2062			break;
   2063		case CALDB_MEM_REGION_TYPE:
   2064			if (ab->qmi.target_mem[i].size > ATH11K_QMI_CALDB_SIZE) {
   2065				ath11k_warn(ab, "qmi mem size is low to load caldata\n");
   2066				return -EINVAL;
   2067			}
   2068
   2069			if (ath11k_cold_boot_cal && ab->hw_params.cold_boot_calib) {
   2070				if (hremote_node) {
   2071					ab->qmi.target_mem[idx].paddr =
   2072							res.start + host_ddr_sz;
   2073					ab->qmi.target_mem[idx].iaddr =
   2074						ioremap(ab->qmi.target_mem[idx].paddr,
   2075							ab->qmi.target_mem[i].size);
   2076				} else {
   2077					ab->qmi.target_mem[idx].paddr =
   2078						ATH11K_QMI_CALDB_ADDRESS;
   2079				}
   2080			} else {
   2081				ab->qmi.target_mem[idx].paddr = 0;
   2082				ab->qmi.target_mem[idx].vaddr = NULL;
   2083			}
   2084			ab->qmi.target_mem[idx].size = ab->qmi.target_mem[i].size;
   2085			ab->qmi.target_mem[idx].type = ab->qmi.target_mem[i].type;
   2086			idx++;
   2087			break;
   2088		default:
   2089			ath11k_warn(ab, "qmi ignore invalid mem req type %d\n",
   2090				    ab->qmi.target_mem[i].type);
   2091			break;
   2092		}
   2093	}
   2094	ab->qmi.mem_seg_count = idx;
   2095
   2096	return 0;
   2097}
   2098
   2099static int ath11k_qmi_request_device_info(struct ath11k_base *ab)
   2100{
   2101	struct qmi_wlanfw_device_info_req_msg_v01 req = {};
   2102	struct qmi_wlanfw_device_info_resp_msg_v01 resp = {};
   2103	struct qmi_txn txn;
   2104	void __iomem *bar_addr_va;
   2105	int ret;
   2106
   2107	/* device info message req is only sent for hybrid bus devices */
   2108	if (!ab->hw_params.hybrid_bus_type)
   2109		return 0;
   2110
   2111	ret = qmi_txn_init(&ab->qmi.handle, &txn,
   2112			   qmi_wlfw_device_info_resp_msg_v01_ei, &resp);
   2113	if (ret < 0)
   2114		goto out;
   2115
   2116	ret = qmi_send_request(&ab->qmi.handle, NULL, &txn,
   2117			       QMI_WLANFW_DEVICE_INFO_REQ_V01,
   2118			       QMI_WLANFW_DEVICE_INFO_REQ_MSG_V01_MAX_LEN,
   2119			       qmi_wlanfw_device_info_req_msg_v01_ei, &req);
   2120	if (ret < 0) {
   2121		qmi_txn_cancel(&txn);
   2122		ath11k_warn(ab, "failed to send qmi target device info request: %d\n",
   2123			    ret);
   2124		goto out;
   2125	}
   2126
   2127	ret = qmi_txn_wait(&txn, msecs_to_jiffies(ATH11K_QMI_WLANFW_TIMEOUT_MS));
   2128	if (ret < 0) {
   2129		ath11k_warn(ab, "failed to wait qmi target device info request: %d\n",
   2130			    ret);
   2131		goto out;
   2132	}
   2133
   2134	if (resp.resp.result != QMI_RESULT_SUCCESS_V01) {
   2135		ath11k_warn(ab, "qmi device info request failed: %d %d\n",
   2136			    resp.resp.result, resp.resp.error);
   2137		ret = -EINVAL;
   2138		goto out;
   2139	}
   2140
   2141	if (!resp.bar_addr_valid || !resp.bar_size_valid) {
   2142		ath11k_warn(ab, "qmi device info response invalid: %d %d\n",
   2143			    resp.resp.result, resp.resp.error);
   2144		ret = -EINVAL;
   2145		goto out;
   2146	}
   2147
   2148	if (!resp.bar_addr ||
   2149	    resp.bar_size != ATH11K_QMI_DEVICE_BAR_SIZE) {
   2150		ath11k_warn(ab, "qmi device info invalid address and size: %llu %u\n",
   2151			    resp.bar_addr, resp.bar_size);
   2152		ret = -EINVAL;
   2153		goto out;
   2154	}
   2155
   2156	bar_addr_va = devm_ioremap(ab->dev, resp.bar_addr, resp.bar_size);
   2157
   2158	if (!bar_addr_va) {
   2159		ath11k_warn(ab, "qmi device info ioremap failed\n");
   2160		ab->mem_len = 0;
   2161		ret = -EIO;
   2162		goto out;
   2163	}
   2164
   2165	ab->mem = bar_addr_va;
   2166	ab->mem_len = resp.bar_size;
   2167
   2168	return 0;
   2169out:
   2170	return ret;
   2171}
   2172
   2173static int ath11k_qmi_request_target_cap(struct ath11k_base *ab)
   2174{
   2175	struct qmi_wlanfw_cap_req_msg_v01 req;
   2176	struct qmi_wlanfw_cap_resp_msg_v01 resp;
   2177	struct qmi_txn txn;
   2178	int ret = 0;
   2179	int r;
   2180	char *fw_build_id;
   2181	int fw_build_id_mask_len;
   2182
   2183	memset(&req, 0, sizeof(req));
   2184	memset(&resp, 0, sizeof(resp));
   2185
   2186	ret = qmi_txn_init(&ab->qmi.handle, &txn, qmi_wlanfw_cap_resp_msg_v01_ei,
   2187			   &resp);
   2188	if (ret < 0)
   2189		goto out;
   2190
   2191	ath11k_dbg(ab, ATH11K_DBG_QMI, "qmi target cap request\n");
   2192
   2193	ret = qmi_send_request(&ab->qmi.handle, NULL, &txn,
   2194			       QMI_WLANFW_CAP_REQ_V01,
   2195			       QMI_WLANFW_CAP_REQ_MSG_V01_MAX_LEN,
   2196			       qmi_wlanfw_cap_req_msg_v01_ei, &req);
   2197	if (ret < 0) {
   2198		qmi_txn_cancel(&txn);
   2199		ath11k_warn(ab, "failed to send qmi cap request: %d\n",
   2200			    ret);
   2201		goto out;
   2202	}
   2203
   2204	ret = qmi_txn_wait(&txn, msecs_to_jiffies(ATH11K_QMI_WLANFW_TIMEOUT_MS));
   2205	if (ret < 0) {
   2206		ath11k_warn(ab, "failed to wait qmi cap request: %d\n", ret);
   2207		goto out;
   2208	}
   2209
   2210	if (resp.resp.result != QMI_RESULT_SUCCESS_V01) {
   2211		ath11k_warn(ab, "qmi cap request failed: %d %d\n",
   2212			    resp.resp.result, resp.resp.error);
   2213		ret = -EINVAL;
   2214		goto out;
   2215	}
   2216
   2217	if (resp.chip_info_valid) {
   2218		ab->qmi.target.chip_id = resp.chip_info.chip_id;
   2219		ab->qmi.target.chip_family = resp.chip_info.chip_family;
   2220	}
   2221
   2222	if (resp.board_info_valid)
   2223		ab->qmi.target.board_id = resp.board_info.board_id;
   2224	else
   2225		ab->qmi.target.board_id = 0xFF;
   2226
   2227	if (resp.soc_info_valid)
   2228		ab->qmi.target.soc_id = resp.soc_info.soc_id;
   2229
   2230	if (resp.fw_version_info_valid) {
   2231		ab->qmi.target.fw_version = resp.fw_version_info.fw_version;
   2232		strlcpy(ab->qmi.target.fw_build_timestamp,
   2233			resp.fw_version_info.fw_build_timestamp,
   2234			sizeof(ab->qmi.target.fw_build_timestamp));
   2235	}
   2236
   2237	if (resp.fw_build_id_valid)
   2238		strlcpy(ab->qmi.target.fw_build_id, resp.fw_build_id,
   2239			sizeof(ab->qmi.target.fw_build_id));
   2240
   2241	if (resp.eeprom_read_timeout_valid) {
   2242		ab->qmi.target.eeprom_caldata =
   2243					resp.eeprom_read_timeout;
   2244		ath11k_dbg(ab, ATH11K_DBG_QMI, "qmi cal data supported from eeprom\n");
   2245	}
   2246
   2247	fw_build_id = ab->qmi.target.fw_build_id;
   2248	fw_build_id_mask_len = strlen(FW_BUILD_ID_MASK);
   2249	if (!strncmp(fw_build_id, FW_BUILD_ID_MASK, fw_build_id_mask_len))
   2250		fw_build_id = fw_build_id + fw_build_id_mask_len;
   2251
   2252	ath11k_info(ab, "chip_id 0x%x chip_family 0x%x board_id 0x%x soc_id 0x%x\n",
   2253		    ab->qmi.target.chip_id, ab->qmi.target.chip_family,
   2254		    ab->qmi.target.board_id, ab->qmi.target.soc_id);
   2255
   2256	ath11k_info(ab, "fw_version 0x%x fw_build_timestamp %s fw_build_id %s",
   2257		    ab->qmi.target.fw_version,
   2258		    ab->qmi.target.fw_build_timestamp,
   2259		    fw_build_id);
   2260
   2261	r = ath11k_core_check_smbios(ab);
   2262	if (r)
   2263		ath11k_dbg(ab, ATH11K_DBG_QMI, "SMBIOS bdf variant name not set.\n");
   2264
   2265	r = ath11k_core_check_dt(ab);
   2266	if (r)
   2267		ath11k_dbg(ab, ATH11K_DBG_QMI, "DT bdf variant name not set.\n");
   2268
   2269out:
   2270	return ret;
   2271}
   2272
   2273static int ath11k_qmi_load_file_target_mem(struct ath11k_base *ab,
   2274					   const u8 *data, u32 len, u8 type)
   2275{
   2276	struct qmi_wlanfw_bdf_download_req_msg_v01 *req;
   2277	struct qmi_wlanfw_bdf_download_resp_msg_v01 resp;
   2278	struct qmi_txn txn;
   2279	const u8 *temp = data;
   2280	void __iomem *bdf_addr = NULL;
   2281	int ret;
   2282	u32 remaining = len;
   2283
   2284	req = kzalloc(sizeof(*req), GFP_KERNEL);
   2285	if (!req)
   2286		return -ENOMEM;
   2287
   2288	memset(&resp, 0, sizeof(resp));
   2289
   2290	if (ab->hw_params.fixed_bdf_addr) {
   2291		bdf_addr = ioremap(ab->hw_params.bdf_addr, ab->hw_params.fw.board_size);
   2292		if (!bdf_addr) {
   2293			ath11k_warn(ab, "qmi ioremap error for bdf_addr\n");
   2294			ret = -EIO;
   2295			goto err_free_req;
   2296		}
   2297	}
   2298
   2299	while (remaining) {
   2300		req->valid = 1;
   2301		req->file_id_valid = 1;
   2302		req->file_id = ab->qmi.target.board_id;
   2303		req->total_size_valid = 1;
   2304		req->total_size = remaining;
   2305		req->seg_id_valid = 1;
   2306		req->data_valid = 1;
   2307		req->bdf_type = type;
   2308		req->bdf_type_valid = 1;
   2309		req->end_valid = 1;
   2310		req->end = 0;
   2311
   2312		if (remaining > QMI_WLANFW_MAX_DATA_SIZE_V01) {
   2313			req->data_len = QMI_WLANFW_MAX_DATA_SIZE_V01;
   2314		} else {
   2315			req->data_len = remaining;
   2316			req->end = 1;
   2317		}
   2318
   2319		if (ab->hw_params.fixed_bdf_addr ||
   2320		    type == ATH11K_QMI_FILE_TYPE_EEPROM) {
   2321			req->data_valid = 0;
   2322			req->end = 1;
   2323			req->data_len = ATH11K_QMI_MAX_BDF_FILE_NAME_SIZE;
   2324		} else {
   2325			memcpy(req->data, temp, req->data_len);
   2326		}
   2327
   2328		if (ab->hw_params.fixed_bdf_addr) {
   2329			if (type == ATH11K_QMI_FILE_TYPE_CALDATA)
   2330				bdf_addr += ab->hw_params.fw.cal_offset;
   2331
   2332			memcpy_toio(bdf_addr, temp, len);
   2333		}
   2334
   2335		ret = qmi_txn_init(&ab->qmi.handle, &txn,
   2336				   qmi_wlanfw_bdf_download_resp_msg_v01_ei,
   2337				   &resp);
   2338		if (ret < 0)
   2339			goto err_iounmap;
   2340
   2341		ath11k_dbg(ab, ATH11K_DBG_QMI, "qmi bdf download req fixed addr type %d\n",
   2342			   type);
   2343
   2344		ret = qmi_send_request(&ab->qmi.handle, NULL, &txn,
   2345				       QMI_WLANFW_BDF_DOWNLOAD_REQ_V01,
   2346				       QMI_WLANFW_BDF_DOWNLOAD_REQ_MSG_V01_MAX_LEN,
   2347				       qmi_wlanfw_bdf_download_req_msg_v01_ei, req);
   2348		if (ret < 0) {
   2349			qmi_txn_cancel(&txn);
   2350			goto err_iounmap;
   2351		}
   2352
   2353		ret = qmi_txn_wait(&txn, msecs_to_jiffies(ATH11K_QMI_WLANFW_TIMEOUT_MS));
   2354		if (ret < 0) {
   2355			ath11k_warn(ab, "failed to wait board file download request: %d\n",
   2356				    ret);
   2357			goto err_iounmap;
   2358		}
   2359
   2360		if (resp.resp.result != QMI_RESULT_SUCCESS_V01) {
   2361			ath11k_warn(ab, "board file download request failed: %d %d\n",
   2362				    resp.resp.result, resp.resp.error);
   2363			ret = -EINVAL;
   2364			goto err_iounmap;
   2365		}
   2366
   2367		if (ab->hw_params.fixed_bdf_addr ||
   2368		    type == ATH11K_QMI_FILE_TYPE_EEPROM) {
   2369			remaining = 0;
   2370		} else {
   2371			remaining -= req->data_len;
   2372			temp += req->data_len;
   2373			req->seg_id++;
   2374			ath11k_dbg(ab, ATH11K_DBG_QMI, "qmi bdf download request remaining %i\n",
   2375				   remaining);
   2376		}
   2377	}
   2378
   2379err_iounmap:
   2380	if (ab->hw_params.fixed_bdf_addr)
   2381		iounmap(bdf_addr);
   2382
   2383err_free_req:
   2384	kfree(req);
   2385
   2386	return ret;
   2387}
   2388
   2389static int ath11k_qmi_load_bdf_qmi(struct ath11k_base *ab,
   2390				   bool regdb)
   2391{
   2392	struct device *dev = ab->dev;
   2393	char filename[ATH11K_QMI_MAX_BDF_FILE_NAME_SIZE];
   2394	const struct firmware *fw_entry;
   2395	struct ath11k_board_data bd;
   2396	u32 fw_size, file_type;
   2397	int ret = 0, bdf_type;
   2398	const u8 *tmp;
   2399
   2400	memset(&bd, 0, sizeof(bd));
   2401
   2402	if (regdb) {
   2403		ret = ath11k_core_fetch_regdb(ab, &bd);
   2404	} else {
   2405		ret = ath11k_core_fetch_bdf(ab, &bd);
   2406		if (ret)
   2407			ath11k_warn(ab, "qmi failed to fetch board file: %d\n", ret);
   2408	}
   2409
   2410	if (ret)
   2411		goto out;
   2412
   2413	if (regdb)
   2414		bdf_type = ATH11K_QMI_BDF_TYPE_REGDB;
   2415	else if (bd.len >= SELFMAG && memcmp(bd.data, ELFMAG, SELFMAG) == 0)
   2416		bdf_type = ATH11K_QMI_BDF_TYPE_ELF;
   2417	else
   2418		bdf_type = ATH11K_QMI_BDF_TYPE_BIN;
   2419
   2420	ath11k_dbg(ab, ATH11K_DBG_QMI, "qmi bdf_type %d\n", bdf_type);
   2421
   2422	fw_size = min_t(u32, ab->hw_params.fw.board_size, bd.len);
   2423
   2424	ret = ath11k_qmi_load_file_target_mem(ab, bd.data, fw_size, bdf_type);
   2425	if (ret < 0) {
   2426		ath11k_warn(ab, "qmi failed to load bdf file\n");
   2427		goto out;
   2428	}
   2429
   2430	/* QCA6390/WCN6855 does not support cal data, skip it */
   2431	if (bdf_type == ATH11K_QMI_BDF_TYPE_ELF || bdf_type == ATH11K_QMI_BDF_TYPE_REGDB)
   2432		goto out;
   2433
   2434	if (ab->qmi.target.eeprom_caldata) {
   2435		file_type = ATH11K_QMI_FILE_TYPE_EEPROM;
   2436		tmp = filename;
   2437		fw_size = ATH11K_QMI_MAX_BDF_FILE_NAME_SIZE;
   2438	} else {
   2439		file_type = ATH11K_QMI_FILE_TYPE_CALDATA;
   2440
   2441		/* cal-<bus>-<id>.bin */
   2442		snprintf(filename, sizeof(filename), "cal-%s-%s.bin",
   2443			 ath11k_bus_str(ab->hif.bus), dev_name(dev));
   2444		fw_entry = ath11k_core_firmware_request(ab, filename);
   2445		if (!IS_ERR(fw_entry))
   2446			goto success;
   2447
   2448		fw_entry = ath11k_core_firmware_request(ab, ATH11K_DEFAULT_CAL_FILE);
   2449		if (IS_ERR(fw_entry)) {
   2450			ret = PTR_ERR(fw_entry);
   2451			ath11k_warn(ab,
   2452				    "qmi failed to load CAL data file:%s\n",
   2453				    filename);
   2454			goto out;
   2455		}
   2456success:
   2457		fw_size = min_t(u32, ab->hw_params.fw.board_size, fw_entry->size);
   2458		tmp = fw_entry->data;
   2459	}
   2460
   2461	ret = ath11k_qmi_load_file_target_mem(ab, tmp, fw_size, file_type);
   2462	if (ret < 0) {
   2463		ath11k_warn(ab, "qmi failed to load caldata\n");
   2464		goto out_qmi_cal;
   2465	}
   2466
   2467	ath11k_dbg(ab, ATH11K_DBG_QMI, "qmi caldata type: %u\n", file_type);
   2468
   2469out_qmi_cal:
   2470	if (!ab->qmi.target.eeprom_caldata)
   2471		release_firmware(fw_entry);
   2472out:
   2473	ath11k_core_free_bdf(ab, &bd);
   2474	ath11k_dbg(ab, ATH11K_DBG_QMI, "qmi BDF download sequence completed\n");
   2475
   2476	return ret;
   2477}
   2478
   2479static int ath11k_qmi_m3_load(struct ath11k_base *ab)
   2480{
   2481	struct m3_mem_region *m3_mem = &ab->qmi.m3_mem;
   2482	const struct firmware *fw;
   2483	char path[100];
   2484	int ret;
   2485
   2486	fw = ath11k_core_firmware_request(ab, ATH11K_M3_FILE);
   2487	if (IS_ERR(fw)) {
   2488		ret = PTR_ERR(fw);
   2489		ath11k_core_create_firmware_path(ab, ATH11K_M3_FILE,
   2490						 path, sizeof(path));
   2491		ath11k_err(ab, "failed to load %s: %d\n", path, ret);
   2492		return ret;
   2493	}
   2494
   2495	if (m3_mem->vaddr || m3_mem->size)
   2496		goto skip_m3_alloc;
   2497
   2498	m3_mem->vaddr = dma_alloc_coherent(ab->dev,
   2499					   fw->size, &m3_mem->paddr,
   2500					   GFP_KERNEL);
   2501	if (!m3_mem->vaddr) {
   2502		ath11k_err(ab, "failed to allocate memory for M3 with size %zu\n",
   2503			   fw->size);
   2504		release_firmware(fw);
   2505		return -ENOMEM;
   2506	}
   2507
   2508skip_m3_alloc:
   2509	memcpy(m3_mem->vaddr, fw->data, fw->size);
   2510	m3_mem->size = fw->size;
   2511	release_firmware(fw);
   2512
   2513	return 0;
   2514}
   2515
   2516static void ath11k_qmi_m3_free(struct ath11k_base *ab)
   2517{
   2518	struct m3_mem_region *m3_mem = &ab->qmi.m3_mem;
   2519
   2520	if (!ab->hw_params.m3_fw_support || !m3_mem->vaddr)
   2521		return;
   2522
   2523	dma_free_coherent(ab->dev, m3_mem->size,
   2524			  m3_mem->vaddr, m3_mem->paddr);
   2525	m3_mem->vaddr = NULL;
   2526	m3_mem->size = 0;
   2527}
   2528
   2529static int ath11k_qmi_wlanfw_m3_info_send(struct ath11k_base *ab)
   2530{
   2531	struct m3_mem_region *m3_mem = &ab->qmi.m3_mem;
   2532	struct qmi_wlanfw_m3_info_req_msg_v01 req;
   2533	struct qmi_wlanfw_m3_info_resp_msg_v01 resp;
   2534	struct qmi_txn txn;
   2535	int ret = 0;
   2536
   2537	memset(&req, 0, sizeof(req));
   2538	memset(&resp, 0, sizeof(resp));
   2539
   2540	if (ab->hw_params.m3_fw_support) {
   2541		ret = ath11k_qmi_m3_load(ab);
   2542		if (ret) {
   2543			ath11k_err(ab, "failed to load m3 firmware: %d", ret);
   2544			return ret;
   2545		}
   2546
   2547		req.addr = m3_mem->paddr;
   2548		req.size = m3_mem->size;
   2549	} else {
   2550		req.addr = 0;
   2551		req.size = 0;
   2552	}
   2553
   2554	ret = qmi_txn_init(&ab->qmi.handle, &txn,
   2555			   qmi_wlanfw_m3_info_resp_msg_v01_ei, &resp);
   2556	if (ret < 0)
   2557		goto out;
   2558
   2559	ath11k_dbg(ab, ATH11K_DBG_QMI, "qmi m3 info req\n");
   2560
   2561	ret = qmi_send_request(&ab->qmi.handle, NULL, &txn,
   2562			       QMI_WLANFW_M3_INFO_REQ_V01,
   2563			       QMI_WLANFW_M3_INFO_REQ_MSG_V01_MAX_MSG_LEN,
   2564			       qmi_wlanfw_m3_info_req_msg_v01_ei, &req);
   2565	if (ret < 0) {
   2566		qmi_txn_cancel(&txn);
   2567		ath11k_warn(ab, "failed to send m3 information request: %d\n",
   2568			    ret);
   2569		goto out;
   2570	}
   2571
   2572	ret = qmi_txn_wait(&txn, msecs_to_jiffies(ATH11K_QMI_WLANFW_TIMEOUT_MS));
   2573	if (ret < 0) {
   2574		ath11k_warn(ab, "failed to wait m3 information request: %d\n", ret);
   2575		goto out;
   2576	}
   2577
   2578	if (resp.resp.result != QMI_RESULT_SUCCESS_V01) {
   2579		ath11k_warn(ab, "m3 info request failed: %d %d\n",
   2580			    resp.resp.result, resp.resp.error);
   2581		ret = -EINVAL;
   2582		goto out;
   2583	}
   2584out:
   2585	return ret;
   2586}
   2587
   2588static int ath11k_qmi_wlanfw_mode_send(struct ath11k_base *ab,
   2589				       u32 mode)
   2590{
   2591	struct qmi_wlanfw_wlan_mode_req_msg_v01 req;
   2592	struct qmi_wlanfw_wlan_mode_resp_msg_v01 resp;
   2593	struct qmi_txn txn;
   2594	int ret = 0;
   2595
   2596	memset(&req, 0, sizeof(req));
   2597	memset(&resp, 0, sizeof(resp));
   2598
   2599	req.mode = mode;
   2600	req.hw_debug_valid = 1;
   2601	req.hw_debug = 0;
   2602
   2603	ret = qmi_txn_init(&ab->qmi.handle, &txn,
   2604			   qmi_wlanfw_wlan_mode_resp_msg_v01_ei, &resp);
   2605	if (ret < 0)
   2606		goto out;
   2607
   2608	ath11k_dbg(ab, ATH11K_DBG_QMI, "qmi wlan mode req mode %d\n", mode);
   2609
   2610	ret = qmi_send_request(&ab->qmi.handle, NULL, &txn,
   2611			       QMI_WLANFW_WLAN_MODE_REQ_V01,
   2612			       QMI_WLANFW_WLAN_MODE_REQ_MSG_V01_MAX_LEN,
   2613			       qmi_wlanfw_wlan_mode_req_msg_v01_ei, &req);
   2614	if (ret < 0) {
   2615		qmi_txn_cancel(&txn);
   2616		ath11k_warn(ab, "failed to send wlan mode request (mode %d): %d\n",
   2617			    mode, ret);
   2618		goto out;
   2619	}
   2620
   2621	ret = qmi_txn_wait(&txn, msecs_to_jiffies(ATH11K_QMI_WLANFW_TIMEOUT_MS));
   2622	if (ret < 0) {
   2623		if (mode == ATH11K_FIRMWARE_MODE_OFF && ret == -ENETRESET) {
   2624			ath11k_warn(ab, "WLFW service is dis-connected\n");
   2625			return 0;
   2626		}
   2627		ath11k_warn(ab, "failed to wait wlan mode request (mode %d): %d\n",
   2628			    mode, ret);
   2629		goto out;
   2630	}
   2631
   2632	if (resp.resp.result != QMI_RESULT_SUCCESS_V01) {
   2633		ath11k_warn(ab, "wlan mode request failed (mode: %d): %d %d\n",
   2634			    mode, resp.resp.result, resp.resp.error);
   2635		ret = -EINVAL;
   2636		goto out;
   2637	}
   2638
   2639out:
   2640	return ret;
   2641}
   2642
   2643static int ath11k_qmi_wlanfw_wlan_cfg_send(struct ath11k_base *ab)
   2644{
   2645	struct qmi_wlanfw_wlan_cfg_req_msg_v01 *req;
   2646	struct qmi_wlanfw_wlan_cfg_resp_msg_v01 resp;
   2647	struct ce_pipe_config *ce_cfg;
   2648	struct service_to_pipe *svc_cfg;
   2649	struct qmi_txn txn;
   2650	int ret = 0, pipe_num;
   2651
   2652	ce_cfg	= (struct ce_pipe_config *)ab->qmi.ce_cfg.tgt_ce;
   2653	svc_cfg	= (struct service_to_pipe *)ab->qmi.ce_cfg.svc_to_ce_map;
   2654
   2655	req = kzalloc(sizeof(*req), GFP_KERNEL);
   2656	if (!req)
   2657		return -ENOMEM;
   2658
   2659	memset(&resp, 0, sizeof(resp));
   2660
   2661	req->host_version_valid = 1;
   2662	strlcpy(req->host_version, ATH11K_HOST_VERSION_STRING,
   2663		sizeof(req->host_version));
   2664
   2665	req->tgt_cfg_valid = 1;
   2666	/* This is number of CE configs */
   2667	req->tgt_cfg_len = ab->qmi.ce_cfg.tgt_ce_len;
   2668	for (pipe_num = 0; pipe_num < req->tgt_cfg_len ; pipe_num++) {
   2669		req->tgt_cfg[pipe_num].pipe_num = ce_cfg[pipe_num].pipenum;
   2670		req->tgt_cfg[pipe_num].pipe_dir = ce_cfg[pipe_num].pipedir;
   2671		req->tgt_cfg[pipe_num].nentries = ce_cfg[pipe_num].nentries;
   2672		req->tgt_cfg[pipe_num].nbytes_max = ce_cfg[pipe_num].nbytes_max;
   2673		req->tgt_cfg[pipe_num].flags = ce_cfg[pipe_num].flags;
   2674	}
   2675
   2676	req->svc_cfg_valid = 1;
   2677	/* This is number of Service/CE configs */
   2678	req->svc_cfg_len = ab->qmi.ce_cfg.svc_to_ce_map_len;
   2679	for (pipe_num = 0; pipe_num < req->svc_cfg_len; pipe_num++) {
   2680		req->svc_cfg[pipe_num].service_id = svc_cfg[pipe_num].service_id;
   2681		req->svc_cfg[pipe_num].pipe_dir = svc_cfg[pipe_num].pipedir;
   2682		req->svc_cfg[pipe_num].pipe_num = svc_cfg[pipe_num].pipenum;
   2683	}
   2684	req->shadow_reg_valid = 0;
   2685
   2686	/* set shadow v2 configuration */
   2687	if (ab->hw_params.supports_shadow_regs) {
   2688		req->shadow_reg_v2_valid = 1;
   2689		req->shadow_reg_v2_len = min_t(u32,
   2690					       ab->qmi.ce_cfg.shadow_reg_v2_len,
   2691					       QMI_WLANFW_MAX_NUM_SHADOW_REG_V2_V01);
   2692		memcpy(&req->shadow_reg_v2, ab->qmi.ce_cfg.shadow_reg_v2,
   2693		       sizeof(u32) * req->shadow_reg_v2_len);
   2694	} else {
   2695		req->shadow_reg_v2_valid = 0;
   2696	}
   2697
   2698	ret = qmi_txn_init(&ab->qmi.handle, &txn,
   2699			   qmi_wlanfw_wlan_cfg_resp_msg_v01_ei, &resp);
   2700	if (ret < 0)
   2701		goto out;
   2702
   2703	ath11k_dbg(ab, ATH11K_DBG_QMI, "qmi wlan cfg req\n");
   2704
   2705	ret = qmi_send_request(&ab->qmi.handle, NULL, &txn,
   2706			       QMI_WLANFW_WLAN_CFG_REQ_V01,
   2707			       QMI_WLANFW_WLAN_CFG_REQ_MSG_V01_MAX_LEN,
   2708			       qmi_wlanfw_wlan_cfg_req_msg_v01_ei, req);
   2709	if (ret < 0) {
   2710		qmi_txn_cancel(&txn);
   2711		ath11k_warn(ab, "failed to send wlan config request: %d\n",
   2712			    ret);
   2713		goto out;
   2714	}
   2715
   2716	ret = qmi_txn_wait(&txn, msecs_to_jiffies(ATH11K_QMI_WLANFW_TIMEOUT_MS));
   2717	if (ret < 0) {
   2718		ath11k_warn(ab, "failed to wait wlan config request: %d\n", ret);
   2719		goto out;
   2720	}
   2721
   2722	if (resp.resp.result != QMI_RESULT_SUCCESS_V01) {
   2723		ath11k_warn(ab, "wlan config request failed: %d %d\n",
   2724			    resp.resp.result, resp.resp.error);
   2725		ret = -EINVAL;
   2726		goto out;
   2727	}
   2728
   2729out:
   2730	kfree(req);
   2731	return ret;
   2732}
   2733
   2734static int ath11k_qmi_wlanfw_wlan_ini_send(struct ath11k_base *ab, bool enable)
   2735{
   2736	int ret;
   2737	struct qmi_txn txn;
   2738	struct qmi_wlanfw_wlan_ini_req_msg_v01 req = {};
   2739	struct qmi_wlanfw_wlan_ini_resp_msg_v01 resp = {};
   2740
   2741	req.enablefwlog_valid = true;
   2742	req.enablefwlog = enable ? 1 : 0;
   2743
   2744	ret = qmi_txn_init(&ab->qmi.handle, &txn,
   2745			   qmi_wlanfw_wlan_ini_resp_msg_v01_ei, &resp);
   2746	if (ret < 0)
   2747		goto out;
   2748
   2749	ret = qmi_send_request(&ab->qmi.handle, NULL, &txn,
   2750			       QMI_WLANFW_WLAN_INI_REQ_V01,
   2751			       QMI_WLANFW_WLAN_INI_REQ_MSG_V01_MAX_LEN,
   2752			       qmi_wlanfw_wlan_ini_req_msg_v01_ei, &req);
   2753	if (ret < 0) {
   2754		ath11k_warn(ab, "qmi failed to send wlan ini request, err = %d\n",
   2755			    ret);
   2756		qmi_txn_cancel(&txn);
   2757		goto out;
   2758	}
   2759
   2760	ret = qmi_txn_wait(&txn, msecs_to_jiffies(ATH11K_QMI_WLANFW_TIMEOUT_MS));
   2761	if (ret < 0) {
   2762		ath11k_warn(ab, "qmi failed wlan ini request, err = %d\n", ret);
   2763		goto out;
   2764	}
   2765
   2766	if (resp.resp.result != QMI_RESULT_SUCCESS_V01) {
   2767		ath11k_warn(ab, "qmi wlan ini request failed, result: %d, err: %d\n",
   2768			    resp.resp.result, resp.resp.error);
   2769		ret = -EINVAL;
   2770	}
   2771
   2772out:
   2773	return ret;
   2774}
   2775
   2776void ath11k_qmi_firmware_stop(struct ath11k_base *ab)
   2777{
   2778	int ret;
   2779
   2780	ath11k_dbg(ab, ATH11K_DBG_QMI, "qmi firmware stop\n");
   2781
   2782	ret = ath11k_qmi_wlanfw_mode_send(ab, ATH11K_FIRMWARE_MODE_OFF);
   2783	if (ret < 0) {
   2784		ath11k_warn(ab, "qmi failed to send wlan mode off: %d\n", ret);
   2785		return;
   2786	}
   2787}
   2788
   2789int ath11k_qmi_firmware_start(struct ath11k_base *ab,
   2790			      u32 mode)
   2791{
   2792	int ret;
   2793
   2794	ath11k_dbg(ab, ATH11K_DBG_QMI, "qmi firmware start\n");
   2795
   2796	if (ab->hw_params.fw_wmi_diag_event) {
   2797		ret = ath11k_qmi_wlanfw_wlan_ini_send(ab, true);
   2798		if (ret < 0) {
   2799			ath11k_warn(ab, "qmi failed to send wlan fw ini:%d\n", ret);
   2800			return ret;
   2801		}
   2802	}
   2803
   2804	ret = ath11k_qmi_wlanfw_wlan_cfg_send(ab);
   2805	if (ret < 0) {
   2806		ath11k_warn(ab, "qmi failed to send wlan cfg: %d\n", ret);
   2807		return ret;
   2808	}
   2809
   2810	ret = ath11k_qmi_wlanfw_mode_send(ab, mode);
   2811	if (ret < 0) {
   2812		ath11k_warn(ab, "qmi failed to send wlan fw mode: %d\n", ret);
   2813		return ret;
   2814	}
   2815
   2816	return 0;
   2817}
   2818
   2819static int ath11k_qmi_process_coldboot_calibration(struct ath11k_base *ab)
   2820{
   2821	int timeout;
   2822	int ret;
   2823
   2824	ret = ath11k_qmi_wlanfw_mode_send(ab, ATH11K_FIRMWARE_MODE_COLD_BOOT);
   2825	if (ret < 0) {
   2826		ath11k_warn(ab, "qmi failed to send wlan fw mode: %d\n", ret);
   2827		return ret;
   2828	}
   2829
   2830	ath11k_dbg(ab, ATH11K_DBG_QMI, "Coldboot calibration wait started\n");
   2831
   2832	timeout = wait_event_timeout(ab->qmi.cold_boot_waitq,
   2833				     (ab->qmi.cal_done  == 1),
   2834				     ATH11K_COLD_BOOT_FW_RESET_DELAY);
   2835	if (timeout <= 0) {
   2836		ath11k_warn(ab, "coldboot calibration timed out\n");
   2837		return 0;
   2838	}
   2839
   2840	ath11k_dbg(ab, ATH11K_DBG_QMI, "Coldboot calibration done\n");
   2841
   2842	return 0;
   2843}
   2844
   2845static int
   2846ath11k_qmi_driver_event_post(struct ath11k_qmi *qmi,
   2847			     enum ath11k_qmi_event_type type,
   2848			     void *data)
   2849{
   2850	struct ath11k_qmi_driver_event *event;
   2851
   2852	event = kzalloc(sizeof(*event), GFP_ATOMIC);
   2853	if (!event)
   2854		return -ENOMEM;
   2855
   2856	event->type = type;
   2857	event->data = data;
   2858
   2859	spin_lock(&qmi->event_lock);
   2860	list_add_tail(&event->list, &qmi->event_list);
   2861	spin_unlock(&qmi->event_lock);
   2862
   2863	queue_work(qmi->event_wq, &qmi->event_work);
   2864
   2865	return 0;
   2866}
   2867
   2868static int ath11k_qmi_event_mem_request(struct ath11k_qmi *qmi)
   2869{
   2870	struct ath11k_base *ab = qmi->ab;
   2871	int ret;
   2872
   2873	ret = ath11k_qmi_respond_fw_mem_request(ab);
   2874	if (ret < 0) {
   2875		ath11k_warn(ab, "qmi failed to respond fw mem req: %d\n", ret);
   2876		return ret;
   2877	}
   2878
   2879	return ret;
   2880}
   2881
   2882static int ath11k_qmi_event_load_bdf(struct ath11k_qmi *qmi)
   2883{
   2884	struct ath11k_base *ab = qmi->ab;
   2885	int ret;
   2886
   2887	ret = ath11k_qmi_request_target_cap(ab);
   2888	if (ret < 0) {
   2889		ath11k_warn(ab, "failed to request qmi target capabilities: %d\n",
   2890			    ret);
   2891		return ret;
   2892	}
   2893
   2894	ret = ath11k_qmi_request_device_info(ab);
   2895	if (ret < 0) {
   2896		ath11k_warn(ab, "failed to request qmi device info: %d\n", ret);
   2897		return ret;
   2898	}
   2899
   2900	if (ab->hw_params.supports_regdb)
   2901		ath11k_qmi_load_bdf_qmi(ab, true);
   2902
   2903	ret = ath11k_qmi_load_bdf_qmi(ab, false);
   2904	if (ret < 0) {
   2905		ath11k_warn(ab, "failed to load board data file: %d\n", ret);
   2906		return ret;
   2907	}
   2908
   2909	return 0;
   2910}
   2911
   2912static int ath11k_qmi_event_server_arrive(struct ath11k_qmi *qmi)
   2913{
   2914	struct ath11k_base *ab = qmi->ab;
   2915	int ret;
   2916
   2917	ret = ath11k_qmi_fw_ind_register_send(ab);
   2918	if (ret < 0) {
   2919		ath11k_warn(ab, "failed to send qmi firmware indication: %d\n",
   2920			    ret);
   2921		return ret;
   2922	}
   2923
   2924	ret = ath11k_qmi_host_cap_send(ab);
   2925	if (ret < 0) {
   2926		ath11k_warn(ab, "failed to send qmi host cap: %d\n", ret);
   2927		return ret;
   2928	}
   2929
   2930	if (!ab->hw_params.fixed_fw_mem)
   2931		return ret;
   2932
   2933	ret = ath11k_qmi_event_load_bdf(qmi);
   2934	if (ret < 0) {
   2935		ath11k_warn(ab, "qmi failed to download BDF:%d\n", ret);
   2936		return ret;
   2937	}
   2938
   2939	return ret;
   2940}
   2941
   2942static void ath11k_qmi_msg_mem_request_cb(struct qmi_handle *qmi_hdl,
   2943					  struct sockaddr_qrtr *sq,
   2944					  struct qmi_txn *txn,
   2945					  const void *data)
   2946{
   2947	struct ath11k_qmi *qmi = container_of(qmi_hdl, struct ath11k_qmi, handle);
   2948	struct ath11k_base *ab = qmi->ab;
   2949	const struct qmi_wlanfw_request_mem_ind_msg_v01 *msg = data;
   2950	int i, ret;
   2951
   2952	ath11k_dbg(ab, ATH11K_DBG_QMI, "qmi firmware request memory request\n");
   2953
   2954	if (msg->mem_seg_len == 0 ||
   2955	    msg->mem_seg_len > ATH11K_QMI_WLANFW_MAX_NUM_MEM_SEG_V01)
   2956		ath11k_warn(ab, "invalid memory segment length: %u\n",
   2957			    msg->mem_seg_len);
   2958
   2959	ab->qmi.mem_seg_count = msg->mem_seg_len;
   2960
   2961	for (i = 0; i < qmi->mem_seg_count ; i++) {
   2962		ab->qmi.target_mem[i].type = msg->mem_seg[i].type;
   2963		ab->qmi.target_mem[i].size = msg->mem_seg[i].size;
   2964		ath11k_dbg(ab, ATH11K_DBG_QMI, "qmi mem seg type %d size %d\n",
   2965			   msg->mem_seg[i].type, msg->mem_seg[i].size);
   2966	}
   2967
   2968	if (ab->hw_params.fixed_mem_region ||
   2969	    test_bit(ATH11K_FLAG_FIXED_MEM_RGN, &ab->dev_flags)) {
   2970		ret = ath11k_qmi_assign_target_mem_chunk(ab);
   2971		if (ret) {
   2972			ath11k_warn(ab, "failed to assign qmi target memory: %d\n",
   2973				    ret);
   2974			return;
   2975		}
   2976	} else {
   2977		ret = ath11k_qmi_alloc_target_mem_chunk(ab);
   2978		if (ret) {
   2979			ath11k_warn(ab, "failed to allocate qmi target memory: %d\n",
   2980				    ret);
   2981			return;
   2982		}
   2983	}
   2984
   2985	ath11k_qmi_driver_event_post(qmi, ATH11K_QMI_EVENT_REQUEST_MEM, NULL);
   2986}
   2987
   2988static void ath11k_qmi_msg_mem_ready_cb(struct qmi_handle *qmi_hdl,
   2989					struct sockaddr_qrtr *sq,
   2990					struct qmi_txn *txn,
   2991					const void *decoded)
   2992{
   2993	struct ath11k_qmi *qmi = container_of(qmi_hdl, struct ath11k_qmi, handle);
   2994	struct ath11k_base *ab = qmi->ab;
   2995
   2996	ath11k_dbg(ab, ATH11K_DBG_QMI, "qmi firmware memory ready indication\n");
   2997	ath11k_qmi_driver_event_post(qmi, ATH11K_QMI_EVENT_FW_MEM_READY, NULL);
   2998}
   2999
   3000static void ath11k_qmi_msg_fw_ready_cb(struct qmi_handle *qmi_hdl,
   3001				       struct sockaddr_qrtr *sq,
   3002				       struct qmi_txn *txn,
   3003				       const void *decoded)
   3004{
   3005	struct ath11k_qmi *qmi = container_of(qmi_hdl, struct ath11k_qmi, handle);
   3006	struct ath11k_base *ab = qmi->ab;
   3007
   3008	ath11k_dbg(ab, ATH11K_DBG_QMI, "qmi firmware ready\n");
   3009	ath11k_qmi_driver_event_post(qmi, ATH11K_QMI_EVENT_FW_READY, NULL);
   3010}
   3011
   3012static void ath11k_qmi_msg_cold_boot_cal_done_cb(struct qmi_handle *qmi_hdl,
   3013						 struct sockaddr_qrtr *sq,
   3014						 struct qmi_txn *txn,
   3015						 const void *decoded)
   3016{
   3017	struct ath11k_qmi *qmi = container_of(qmi_hdl,
   3018					      struct ath11k_qmi, handle);
   3019	struct ath11k_base *ab = qmi->ab;
   3020
   3021	ab->qmi.cal_done = 1;
   3022	wake_up(&ab->qmi.cold_boot_waitq);
   3023	ath11k_dbg(ab, ATH11K_DBG_QMI, "qmi cold boot calibration done\n");
   3024}
   3025
   3026static const struct qmi_msg_handler ath11k_qmi_msg_handlers[] = {
   3027	{
   3028		.type = QMI_INDICATION,
   3029		.msg_id = QMI_WLFW_REQUEST_MEM_IND_V01,
   3030		.ei = qmi_wlanfw_request_mem_ind_msg_v01_ei,
   3031		.decoded_size = sizeof(struct qmi_wlanfw_request_mem_ind_msg_v01),
   3032		.fn = ath11k_qmi_msg_mem_request_cb,
   3033	},
   3034	{
   3035		.type = QMI_INDICATION,
   3036		.msg_id = QMI_WLFW_FW_MEM_READY_IND_V01,
   3037		.ei = qmi_wlanfw_mem_ready_ind_msg_v01_ei,
   3038		.decoded_size = sizeof(struct qmi_wlanfw_fw_mem_ready_ind_msg_v01),
   3039		.fn = ath11k_qmi_msg_mem_ready_cb,
   3040	},
   3041	{
   3042		.type = QMI_INDICATION,
   3043		.msg_id = QMI_WLFW_FW_READY_IND_V01,
   3044		.ei = qmi_wlanfw_fw_ready_ind_msg_v01_ei,
   3045		.decoded_size = sizeof(struct qmi_wlanfw_fw_ready_ind_msg_v01),
   3046		.fn = ath11k_qmi_msg_fw_ready_cb,
   3047	},
   3048	{
   3049		.type = QMI_INDICATION,
   3050		.msg_id = QMI_WLFW_COLD_BOOT_CAL_DONE_IND_V01,
   3051		.ei = qmi_wlanfw_cold_boot_cal_done_ind_msg_v01_ei,
   3052		.decoded_size =
   3053			sizeof(struct qmi_wlanfw_fw_cold_cal_done_ind_msg_v01),
   3054		.fn = ath11k_qmi_msg_cold_boot_cal_done_cb,
   3055	},
   3056};
   3057
   3058static int ath11k_qmi_ops_new_server(struct qmi_handle *qmi_hdl,
   3059				     struct qmi_service *service)
   3060{
   3061	struct ath11k_qmi *qmi = container_of(qmi_hdl, struct ath11k_qmi, handle);
   3062	struct ath11k_base *ab = qmi->ab;
   3063	struct sockaddr_qrtr *sq = &qmi->sq;
   3064	int ret;
   3065
   3066	sq->sq_family = AF_QIPCRTR;
   3067	sq->sq_node = service->node;
   3068	sq->sq_port = service->port;
   3069
   3070	ret = kernel_connect(qmi_hdl->sock, (struct sockaddr *)sq,
   3071			     sizeof(*sq), 0);
   3072	if (ret) {
   3073		ath11k_warn(ab, "failed to connect to qmi remote service: %d\n", ret);
   3074		return ret;
   3075	}
   3076
   3077	ath11k_dbg(ab, ATH11K_DBG_QMI, "qmi wifi fw qmi service connected\n");
   3078	ath11k_qmi_driver_event_post(qmi, ATH11K_QMI_EVENT_SERVER_ARRIVE, NULL);
   3079
   3080	return ret;
   3081}
   3082
   3083static void ath11k_qmi_ops_del_server(struct qmi_handle *qmi_hdl,
   3084				      struct qmi_service *service)
   3085{
   3086	struct ath11k_qmi *qmi = container_of(qmi_hdl, struct ath11k_qmi, handle);
   3087	struct ath11k_base *ab = qmi->ab;
   3088
   3089	ath11k_dbg(ab, ATH11K_DBG_QMI, "qmi wifi fw del server\n");
   3090	ath11k_qmi_driver_event_post(qmi, ATH11K_QMI_EVENT_SERVER_EXIT, NULL);
   3091}
   3092
   3093static const struct qmi_ops ath11k_qmi_ops = {
   3094	.new_server = ath11k_qmi_ops_new_server,
   3095	.del_server = ath11k_qmi_ops_del_server,
   3096};
   3097
   3098static void ath11k_qmi_driver_event_work(struct work_struct *work)
   3099{
   3100	struct ath11k_qmi *qmi = container_of(work, struct ath11k_qmi,
   3101					      event_work);
   3102	struct ath11k_qmi_driver_event *event;
   3103	struct ath11k_base *ab = qmi->ab;
   3104	int ret;
   3105
   3106	spin_lock(&qmi->event_lock);
   3107	while (!list_empty(&qmi->event_list)) {
   3108		event = list_first_entry(&qmi->event_list,
   3109					 struct ath11k_qmi_driver_event, list);
   3110		list_del(&event->list);
   3111		spin_unlock(&qmi->event_lock);
   3112
   3113		if (test_bit(ATH11K_FLAG_UNREGISTERING, &ab->dev_flags)) {
   3114			kfree(event);
   3115			return;
   3116		}
   3117
   3118		switch (event->type) {
   3119		case ATH11K_QMI_EVENT_SERVER_ARRIVE:
   3120			ret = ath11k_qmi_event_server_arrive(qmi);
   3121			if (ret < 0)
   3122				set_bit(ATH11K_FLAG_QMI_FAIL, &ab->dev_flags);
   3123			break;
   3124		case ATH11K_QMI_EVENT_SERVER_EXIT:
   3125			set_bit(ATH11K_FLAG_CRASH_FLUSH, &ab->dev_flags);
   3126			set_bit(ATH11K_FLAG_RECOVERY, &ab->dev_flags);
   3127			break;
   3128		case ATH11K_QMI_EVENT_REQUEST_MEM:
   3129			ret = ath11k_qmi_event_mem_request(qmi);
   3130			if (ret < 0)
   3131				set_bit(ATH11K_FLAG_QMI_FAIL, &ab->dev_flags);
   3132			break;
   3133		case ATH11K_QMI_EVENT_FW_MEM_READY:
   3134			ret = ath11k_qmi_event_load_bdf(qmi);
   3135			if (ret < 0) {
   3136				set_bit(ATH11K_FLAG_QMI_FAIL, &ab->dev_flags);
   3137				break;
   3138			}
   3139
   3140			ret = ath11k_qmi_wlanfw_m3_info_send(ab);
   3141			if (ret < 0) {
   3142				ath11k_warn(ab,
   3143					    "failed to send qmi m3 info req: %d\n", ret);
   3144				set_bit(ATH11K_FLAG_QMI_FAIL, &ab->dev_flags);
   3145			}
   3146
   3147			break;
   3148		case ATH11K_QMI_EVENT_FW_READY:
   3149			clear_bit(ATH11K_FLAG_QMI_FAIL, &ab->dev_flags);
   3150			if (test_bit(ATH11K_FLAG_REGISTERED, &ab->dev_flags)) {
   3151				ath11k_hal_dump_srng_stats(ab);
   3152				queue_work(ab->workqueue, &ab->restart_work);
   3153				break;
   3154			}
   3155
   3156			if (ath11k_cold_boot_cal && ab->qmi.cal_done == 0 &&
   3157			    ab->hw_params.cold_boot_calib) {
   3158				ath11k_qmi_process_coldboot_calibration(ab);
   3159			} else {
   3160				clear_bit(ATH11K_FLAG_CRASH_FLUSH,
   3161					  &ab->dev_flags);
   3162				clear_bit(ATH11K_FLAG_RECOVERY, &ab->dev_flags);
   3163				ret = ath11k_core_qmi_firmware_ready(ab);
   3164				if (ret) {
   3165					set_bit(ATH11K_FLAG_QMI_FAIL, &ab->dev_flags);
   3166					break;
   3167				}
   3168				set_bit(ATH11K_FLAG_REGISTERED, &ab->dev_flags);
   3169			}
   3170
   3171			break;
   3172		case ATH11K_QMI_EVENT_COLD_BOOT_CAL_DONE:
   3173			break;
   3174		default:
   3175			ath11k_warn(ab, "invalid qmi event type: %d", event->type);
   3176			break;
   3177		}
   3178		kfree(event);
   3179		spin_lock(&qmi->event_lock);
   3180	}
   3181	spin_unlock(&qmi->event_lock);
   3182}
   3183
   3184int ath11k_qmi_init_service(struct ath11k_base *ab)
   3185{
   3186	int ret;
   3187
   3188	memset(&ab->qmi.target, 0, sizeof(struct target_info));
   3189	memset(&ab->qmi.target_mem, 0, sizeof(struct target_mem_chunk));
   3190	ab->qmi.ab = ab;
   3191
   3192	ab->qmi.target_mem_mode = ab->hw_params.fw_mem_mode;
   3193	ret = qmi_handle_init(&ab->qmi.handle, ATH11K_QMI_RESP_LEN_MAX,
   3194			      &ath11k_qmi_ops, ath11k_qmi_msg_handlers);
   3195	if (ret < 0) {
   3196		ath11k_warn(ab, "failed to initialize qmi handle: %d\n", ret);
   3197		return ret;
   3198	}
   3199
   3200	ab->qmi.event_wq = alloc_workqueue("ath11k_qmi_driver_event",
   3201					   WQ_UNBOUND, 1);
   3202	if (!ab->qmi.event_wq) {
   3203		ath11k_err(ab, "failed to allocate workqueue\n");
   3204		return -EFAULT;
   3205	}
   3206
   3207	INIT_LIST_HEAD(&ab->qmi.event_list);
   3208	spin_lock_init(&ab->qmi.event_lock);
   3209	INIT_WORK(&ab->qmi.event_work, ath11k_qmi_driver_event_work);
   3210
   3211	ret = qmi_add_lookup(&ab->qmi.handle, ATH11K_QMI_WLFW_SERVICE_ID_V01,
   3212			     ATH11K_QMI_WLFW_SERVICE_VERS_V01,
   3213			     ab->qmi.service_ins_id);
   3214	if (ret < 0) {
   3215		ath11k_warn(ab, "failed to add qmi lookup: %d\n", ret);
   3216		destroy_workqueue(ab->qmi.event_wq);
   3217		return ret;
   3218	}
   3219
   3220	return ret;
   3221}
   3222
   3223void ath11k_qmi_deinit_service(struct ath11k_base *ab)
   3224{
   3225	qmi_handle_release(&ab->qmi.handle);
   3226	cancel_work_sync(&ab->qmi.event_work);
   3227	destroy_workqueue(ab->qmi.event_wq);
   3228	ath11k_qmi_m3_free(ab);
   3229	ath11k_qmi_free_target_mem_chunk(ab);
   3230}
   3231EXPORT_SYMBOL(ath11k_qmi_deinit_service);
   3232
   3233void ath11k_qmi_free_resource(struct ath11k_base *ab)
   3234{
   3235	ath11k_qmi_free_target_mem_chunk(ab);
   3236	ath11k_qmi_m3_free(ab);
   3237}