xref: /wlan-driver/qcacld-3.0/core/bmi/src/i_bmi.h (revision 5113495b16420b49004c444715d2daae2066e7dc)
1*5113495bSYour Name /*
2*5113495bSYour Name  * Copyright (c) 2014-2020 The Linux Foundation. All rights reserved.
3*5113495bSYour Name  * Copyright (c) 2021-2023 Qualcomm Innovation Center, Inc. All rights reserved.
4*5113495bSYour Name  *
5*5113495bSYour Name  * Permission to use, copy, modify, and/or distribute this software for
6*5113495bSYour Name  * any purpose with or without fee is hereby granted, provided that the
7*5113495bSYour Name  * above copyright notice and this permission notice appear in all
8*5113495bSYour Name  * copies.
9*5113495bSYour Name  *
10*5113495bSYour Name  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
11*5113495bSYour Name  * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
12*5113495bSYour Name  * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
13*5113495bSYour Name  * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
14*5113495bSYour Name  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
15*5113495bSYour Name  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
16*5113495bSYour Name  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17*5113495bSYour Name  * PERFORMANCE OF THIS SOFTWARE.
18*5113495bSYour Name  */
19*5113495bSYour Name 
20*5113495bSYour Name /* ===================================================================
21*5113495bSYour Name  * Internal BMI Header File
22*5113495bSYour Name  */
23*5113495bSYour Name 
24*5113495bSYour Name #ifndef _I_BMI_H_
25*5113495bSYour Name #define _I_BMI_H_
26*5113495bSYour Name 
27*5113495bSYour Name #include "qdf_types.h"
28*5113495bSYour Name #include "qdf_defer.h"
29*5113495bSYour Name #include "hif.h"
30*5113495bSYour Name #include "bmi_msg.h"
31*5113495bSYour Name #include "bmi.h"
32*5113495bSYour Name #include "ol_fw.h"
33*5113495bSYour Name #include "pld_common.h"
34*5113495bSYour Name 
35*5113495bSYour Name /*
36*5113495bSYour Name  * Note that not all the register locations are accessible.
37*5113495bSYour Name  * A list of accessible target registers are specified with
38*5113495bSYour Name  * their start and end addresses in a table for given target
39*5113495bSYour Name  * version. We should NOT access other locations as either
40*5113495bSYour Name  * they are invalid locations or host does not have read
41*5113495bSYour Name  * access to it or the value of the particular register
42*5113495bSYour Name  * read might change
43*5113495bSYour Name  */
44*5113495bSYour Name #define REGISTER_LOCATION       0x00000800
45*5113495bSYour Name 
46*5113495bSYour Name #define DRAM_LOCATION           0x00400000
47*5113495bSYour Name #ifdef HIF_PCI
48*5113495bSYour Name #define DRAM_SIZE               0x000a8000
49*5113495bSYour Name #else
50*5113495bSYour Name #define DRAM_SIZE               0x00098000
51*5113495bSYour Name #endif
52*5113495bSYour Name /* The local base addr is used to read the target dump using pcie I/O reads */
53*5113495bSYour Name #define DRAM_LOCAL_BASE_ADDR    (0x100000)
54*5113495bSYour Name 
55*5113495bSYour Name /* Target IRAM config */
56*5113495bSYour Name #define FW_RAM_CONFIG_ADDRESS   0x0018
57*5113495bSYour Name #define IRAM1_LOCATION          0x00980000
58*5113495bSYour Name #define IRAM1_SIZE              0x00080000
59*5113495bSYour Name #define IRAM2_LOCATION          0x00a00000
60*5113495bSYour Name #define IRAM2_SIZE              0x00040000
61*5113495bSYour Name #ifdef HIF_SDIO
62*5113495bSYour Name #define IRAM_LOCATION           0x00980000
63*5113495bSYour Name #define IRAM_SIZE               0x000C0000
64*5113495bSYour Name #else
65*5113495bSYour Name #define IRAM_LOCATION           0x00980000
66*5113495bSYour Name #define IRAM_SIZE               0x00038000
67*5113495bSYour Name #endif
68*5113495bSYour Name 
69*5113495bSYour Name #define AXI_LOCATION            0x000a0000
70*5113495bSYour Name #ifdef HIF_PCI
71*5113495bSYour Name #define AXI_SIZE                0x00018000
72*5113495bSYour Name #else
73*5113495bSYour Name #define AXI_SIZE                0x00020000
74*5113495bSYour Name #endif
75*5113495bSYour Name 
76*5113495bSYour Name #define PCIE_READ_LIMIT         0x00040000
77*5113495bSYour Name 
78*5113495bSYour Name #define SHA256_DIGEST_SIZE      32
79*5113495bSYour Name 
80*5113495bSYour Name /* BMI LOGGING WRAPPERS */
81*5113495bSYour Name 
82*5113495bSYour Name #define BMI_LOG(level, args...) QDF_TRACE(QDF_MODULE_ID_BMI, \
83*5113495bSYour Name 					level, ##args)
84*5113495bSYour Name #define BMI_ERR(args ...)	BMI_LOG(QDF_TRACE_LEVEL_ERROR, args)
85*5113495bSYour Name #define BMI_DBG(args ...)	BMI_LOG(QDF_TRACE_LEVEL_DEBUG, args)
86*5113495bSYour Name #define BMI_WARN(args ...)	BMI_LOG(QDF_TRACE_LEVEL_WARN, args)
87*5113495bSYour Name #define BMI_INFO(args ...)	BMI_LOG(QDF_TRACE_LEVEL_INFO, args)
88*5113495bSYour Name /* End of BMI Logging Wrappers */
89*5113495bSYour Name 
90*5113495bSYour Name /* BMI Assert Wrappers */
91*5113495bSYour Name #define bmi_assert QDF_BUG
92*5113495bSYour Name /*
93*5113495bSYour Name  * Although we had envisioned BMI to run on top of HTC, this is not how the
94*5113495bSYour Name  * final implementation ended up. On the Target side, BMI is a part of the BSP
95*5113495bSYour Name  * and does not use the HTC protocol nor even DMA -- it is intentionally kept
96*5113495bSYour Name  * very simple.
97*5113495bSYour Name  */
98*5113495bSYour Name 
99*5113495bSYour Name #define MAX_BMI_CMDBUF_SZ (BMI_DATASZ_MAX + \
100*5113495bSYour Name 			sizeof(uint32_t) /* cmd */ + \
101*5113495bSYour Name 			sizeof(uint32_t) /* addr */ + \
102*5113495bSYour Name 			sizeof(uint32_t))    /* length */
103*5113495bSYour Name #define BMI_COMMAND_FITS(sz) ((sz) <= MAX_BMI_CMDBUF_SZ)
104*5113495bSYour Name #define BMI_EXCHANGE_TIMEOUT_MS  1000
105*5113495bSYour Name 
106*5113495bSYour Name struct hash_fw {
107*5113495bSYour Name 	u8 qwlan[SHA256_DIGEST_SIZE];
108*5113495bSYour Name 	u8 otp[SHA256_DIGEST_SIZE];
109*5113495bSYour Name 	u8 bdwlan[SHA256_DIGEST_SIZE];
110*5113495bSYour Name 	u8 utf[SHA256_DIGEST_SIZE];
111*5113495bSYour Name };
112*5113495bSYour Name 
113*5113495bSYour Name enum ATH_BIN_FILE {
114*5113495bSYour Name 	ATH_OTP_FILE,
115*5113495bSYour Name 	ATH_FIRMWARE_FILE,
116*5113495bSYour Name 	ATH_PATCH_FILE,
117*5113495bSYour Name 	ATH_BOARD_DATA_FILE,
118*5113495bSYour Name 	ATH_FLASH_FILE,
119*5113495bSYour Name 	ATH_SETUP_FILE,
120*5113495bSYour Name };
121*5113495bSYour Name 
122*5113495bSYour Name #if defined(QCA_WIFI_3_0_ADRASTEA)
123*5113495bSYour Name #define NO_BMI 1
124*5113495bSYour Name #else
125*5113495bSYour Name #define NO_BMI 0
126*5113495bSYour Name #endif
127*5113495bSYour Name 
128*5113495bSYour Name /**
129*5113495bSYour Name  * struct bmi_info - Structure to hold BMI Specific information
130*5113495bSYour Name  * @bmi_cmd_buff: BMI Command Buffer
131*5113495bSYour Name  * @bmi_rsp_buff: BMI Response Buffer
132*5113495bSYour Name  * @bmi_cmd_da: BMI Command Physical address
133*5113495bSYour Name  * @bmi_rsp_da: BMI Response Physical address
134*5113495bSYour Name  * @bmi_done: Flag to check if BMI Phase is complete
135*5113495bSYour Name  * @board_id: board ID
136*5113495bSYour Name  * @fw_files: FW files
137*5113495bSYour Name  *
138*5113495bSYour Name  */
139*5113495bSYour Name struct bmi_info {
140*5113495bSYour Name 	uint8_t *bmi_cmd_buff;
141*5113495bSYour Name 	uint8_t *bmi_rsp_buff;
142*5113495bSYour Name 	dma_addr_t bmi_cmd_da;
143*5113495bSYour Name 	dma_addr_t bmi_rsp_da;
144*5113495bSYour Name 	bool bmi_done;
145*5113495bSYour Name 	uint16_t board_id;
146*5113495bSYour Name 	struct pld_fw_files fw_files;
147*5113495bSYour Name };
148*5113495bSYour Name 
149*5113495bSYour Name /**
150*5113495bSYour Name  * struct ol_context - Structure to hold OL context
151*5113495bSYour Name  * @bmi: BMI info
152*5113495bSYour Name  * @cfg_info: OL config info
153*5113495bSYour Name  * @cal_in_flash: For Firmware Flash Download
154*5113495bSYour Name  * @qdf_dev: QDF Device
155*5113495bSYour Name  * @ramdump_work: Work for Ramdump collection
156*5113495bSYour Name  * @fw_indication_work: Work for Fw indication
157*5113495bSYour Name  * @fw_dl_wakelock: Firmware download wakelock
158*5113495bSYour Name  * @scn: HIF Context
159*5113495bSYour Name  * @tgt_def: Target Defnition pointer
160*5113495bSYour Name  * @fw_crashed_cb: Callback for firmware crashed ind
161*5113495bSYour Name  *
162*5113495bSYour Name  * Structure to hold all ol BMI/Ramdump info
163*5113495bSYour Name  */
164*5113495bSYour Name struct ol_context {
165*5113495bSYour Name 	struct bmi_info bmi;
166*5113495bSYour Name 	struct ol_config_info cfg_info;
167*5113495bSYour Name 	uint8_t *cal_in_flash;
168*5113495bSYour Name 	qdf_device_t qdf_dev;
169*5113495bSYour Name 	qdf_work_t ramdump_work;
170*5113495bSYour Name 	qdf_work_t fw_indication_work;
171*5113495bSYour Name 	qdf_wake_lock_t fw_dl_wakelock;
172*5113495bSYour Name 	struct hif_opaque_softc *scn;
173*5113495bSYour Name 	struct targetdef_t {
174*5113495bSYour Name 		struct targetdef_s *targetdef;
175*5113495bSYour Name 	} tgt_def;
176*5113495bSYour Name 	void (*fw_crashed_cb)(void);
177*5113495bSYour Name };
178*5113495bSYour Name 
179*5113495bSYour Name #define GET_BMI_CONTEXT(ol_ctx) ((struct bmi_info *)ol_ctx)
180*5113495bSYour Name 
181*5113495bSYour Name QDF_STATUS bmi_execute(uint32_t address, uint32_t *param,
182*5113495bSYour Name 				struct ol_context *ol_ctx);
183*5113495bSYour Name QDF_STATUS bmi_init(struct ol_context *ol_ctx);
184*5113495bSYour Name QDF_STATUS bmi_no_command(struct ol_context *ol_ctx);
185*5113495bSYour Name QDF_STATUS bmi_read_memory(uint32_t address, uint8_t *buffer, uint32_t length,
186*5113495bSYour Name 					struct ol_context *ol_ctx);
187*5113495bSYour Name QDF_STATUS bmi_write_memory(uint32_t address, uint8_t *buffer, uint32_t length,
188*5113495bSYour Name 					struct ol_context *ol_ctx);
189*5113495bSYour Name QDF_STATUS bmi_fast_download(uint32_t address, uint8_t *buffer, uint32_t length,
190*5113495bSYour Name 					struct ol_context *ol_ctx);
191*5113495bSYour Name QDF_STATUS bmi_read_soc_register(uint32_t address,
192*5113495bSYour Name 				uint32_t *param, struct ol_context *ol_ctx);
193*5113495bSYour Name QDF_STATUS bmi_write_soc_register(uint32_t address, uint32_t param,
194*5113495bSYour Name 					struct ol_context *ol_ctx);
195*5113495bSYour Name QDF_STATUS bmi_get_target_info(struct bmi_target_info *targ_info,
196*5113495bSYour Name 			       struct ol_context *ol_ctx);
197*5113495bSYour Name QDF_STATUS bmi_firmware_download(struct ol_context *ol_ctx);
198*5113495bSYour Name QDF_STATUS bmi_done_local(struct ol_context *ol_ctx);
199*5113495bSYour Name QDF_STATUS ol_download_firmware(struct ol_context *ol_ctx);
200*5113495bSYour Name QDF_STATUS ol_configure_target(struct ol_context *ol_ctx);
201*5113495bSYour Name QDF_STATUS bmi_sign_stream_start(uint32_t address, uint8_t *buffer,
202*5113495bSYour Name 				 uint32_t length, struct ol_context *ol_ctx);
203*5113495bSYour Name void ramdump_work_handler(void *arg);
204*5113495bSYour Name void fw_indication_work_handler(void *arg);
205*5113495bSYour Name struct ol_config_info *ol_get_ini_handle(struct ol_context *ol_ctx);
206*5113495bSYour Name 
207*5113495bSYour Name #ifdef HIF_SDIO
208*5113495bSYour Name QDF_STATUS hif_reg_based_get_target_info(struct hif_opaque_softc *hif_ctx,
209*5113495bSYour Name 		  struct bmi_target_info *targ_info);
210*5113495bSYour Name #endif
211*5113495bSYour Name #if defined(HIF_PCI) || defined(HIF_SNOC) || defined(HIF_AHB) || defined(HIF_USB)
212*5113495bSYour Name static inline QDF_STATUS
hif_reg_based_get_target_info(struct hif_opaque_softc * hif_ctx,struct bmi_target_info * targ_info)213*5113495bSYour Name hif_reg_based_get_target_info(struct hif_opaque_softc *hif_ctx,
214*5113495bSYour Name 		  struct bmi_target_info *targ_info)
215*5113495bSYour Name {
216*5113495bSYour Name 	return QDF_STATUS_SUCCESS;
217*5113495bSYour Name }
218*5113495bSYour Name #endif
219*5113495bSYour Name #endif
220