1 /* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */
2 /*
3  * Copyright (C) 2018, 2020-2021 Intel Corporation
4  */
5 #ifndef __iwl_context_info_file_gen3_h__
6 #define __iwl_context_info_file_gen3_h__
7 
8 #include "iwl-context-info.h"
9 
10 #define CSR_CTXT_INFO_BOOT_CTRL         0x0
11 #define CSR_CTXT_INFO_ADDR              0x118
12 #define CSR_IML_DATA_ADDR               0x120
13 #define CSR_IML_SIZE_ADDR               0x128
14 #define CSR_IML_RESP_ADDR               0x12c
15 
16 /* Set bit for enabling automatic function boot */
17 #define CSR_AUTO_FUNC_BOOT_ENA          BIT(1)
18 /* Set bit for initiating function boot */
19 #define CSR_AUTO_FUNC_INIT              BIT(7)
20 
21 /**
22  * enum iwl_prph_scratch_mtr_format - tfd size configuration
23  * @IWL_PRPH_MTR_FORMAT_16B: 16 bit tfd
24  * @IWL_PRPH_MTR_FORMAT_32B: 32 bit tfd
25  * @IWL_PRPH_MTR_FORMAT_64B: 64 bit tfd
26  * @IWL_PRPH_MTR_FORMAT_256B: 256 bit tfd
27  */
28 enum iwl_prph_scratch_mtr_format {
29 	IWL_PRPH_MTR_FORMAT_16B = 0x0,
30 	IWL_PRPH_MTR_FORMAT_32B = 0x40000,
31 	IWL_PRPH_MTR_FORMAT_64B = 0x80000,
32 	IWL_PRPH_MTR_FORMAT_256B = 0xC0000,
33 };
34 
35 /**
36  * enum iwl_prph_scratch_flags - PRPH scratch control flags
37  * @IWL_PRPH_SCRATCH_EARLY_DEBUG_EN: enable early debug conf
38  * @IWL_PRPH_SCRATCH_EDBG_DEST_DRAM: use DRAM, with size allocated
39  *	in hwm config.
40  * @IWL_PRPH_SCRATCH_EDBG_DEST_INTERNAL: use buffer on SRAM
41  * @IWL_PRPH_SCRATCH_EDBG_DEST_ST_ARBITER: use st arbiter, mainly for
42  *	multicomm.
43  * @IWL_PRPH_SCRATCH_EDBG_DEST_TB22DTF: route debug data to SoC HW
44  * @IWL_PRPH_SCTATCH_RB_SIZE_4K: Use 4K RB size (the default is 2K)
45  * @IWL_PRPH_SCRATCH_MTR_MODE: format used for completion - 0: for
46  *	completion descriptor, 1 for responses (legacy)
47  * @IWL_PRPH_SCRATCH_MTR_FORMAT: a mask for the size of the tfd.
48  *	There are 4 optional values: 0: 16 bit, 1: 32 bit, 2: 64 bit,
49  *	3: 256 bit.
50  * @IWL_PRPH_SCRATCH_RB_SIZE_EXT_MASK: RB size full information, ignored
51  *	by older firmware versions, so set IWL_PRPH_SCRATCH_RB_SIZE_4K
52  *	appropriately; use the below values for this.
53  * @IWL_PRPH_SCRATCH_RB_SIZE_EXT_8K: 8kB RB size
54  * @IWL_PRPH_SCRATCH_RB_SIZE_EXT_12K: 12kB RB size
55  * @IWL_PRPH_SCRATCH_RB_SIZE_EXT_16K: 16kB RB size
56  */
57 enum iwl_prph_scratch_flags {
58 	IWL_PRPH_SCRATCH_EARLY_DEBUG_EN		= BIT(4),
59 	IWL_PRPH_SCRATCH_EDBG_DEST_DRAM		= BIT(8),
60 	IWL_PRPH_SCRATCH_EDBG_DEST_INTERNAL	= BIT(9),
61 	IWL_PRPH_SCRATCH_EDBG_DEST_ST_ARBITER	= BIT(10),
62 	IWL_PRPH_SCRATCH_EDBG_DEST_TB22DTF	= BIT(11),
63 	IWL_PRPH_SCRATCH_RB_SIZE_4K		= BIT(16),
64 	IWL_PRPH_SCRATCH_MTR_MODE		= BIT(17),
65 	IWL_PRPH_SCRATCH_MTR_FORMAT		= BIT(18) | BIT(19),
66 	IWL_PRPH_SCRATCH_RB_SIZE_EXT_MASK	= 0xf << 20,
67 	IWL_PRPH_SCRATCH_RB_SIZE_EXT_8K		= 8 << 20,
68 	IWL_PRPH_SCRATCH_RB_SIZE_EXT_12K	= 9 << 20,
69 	IWL_PRPH_SCRATCH_RB_SIZE_EXT_16K	= 10 << 20,
70 };
71 
72 /*
73  * struct iwl_prph_scratch_version - version structure
74  * @mac_id: SKU and revision id
75  * @version: prph scratch information version id
76  * @size: the size of the context information in DWs
77  * @reserved: reserved
78  */
79 struct iwl_prph_scratch_version {
80 	__le16 mac_id;
81 	__le16 version;
82 	__le16 size;
83 	__le16 reserved;
84 } __packed; /* PERIPH_SCRATCH_VERSION_S */
85 
86 /*
87  * struct iwl_prph_scratch_control - control structure
88  * @control_flags: context information flags see &enum iwl_prph_scratch_flags
89  * @reserved: reserved
90  */
91 struct iwl_prph_scratch_control {
92 	__le32 control_flags;
93 	__le32 reserved;
94 } __packed; /* PERIPH_SCRATCH_CONTROL_S */
95 
96 /*
97  * struct iwl_prph_scratch_pnvm_cfg - ror config
98  * @pnvm_base_addr: PNVM start address
99  * @pnvm_size: PNVM size in DWs
100  * @reserved: reserved
101  */
102 struct iwl_prph_scratch_pnvm_cfg {
103 	__le64 pnvm_base_addr;
104 	__le32 pnvm_size;
105 	__le32 reserved;
106 } __packed; /* PERIPH_SCRATCH_PNVM_CFG_S */
107 
108 /*
109  * struct iwl_prph_scratch_hwm_cfg - hwm config
110  * @hwm_base_addr: hwm start address
111  * @hwm_size: hwm size in DWs
112  * @debug_token_config: debug preset
113  */
114 struct iwl_prph_scratch_hwm_cfg {
115 	__le64 hwm_base_addr;
116 	__le32 hwm_size;
117 	__le32 debug_token_config;
118 } __packed; /* PERIPH_SCRATCH_HWM_CFG_S */
119 
120 /*
121  * struct iwl_prph_scratch_rbd_cfg - RBDs configuration
122  * @free_rbd_addr: default queue free RB CB base address
123  * @reserved: reserved
124  */
125 struct iwl_prph_scratch_rbd_cfg {
126 	__le64 free_rbd_addr;
127 	__le32 reserved;
128 } __packed; /* PERIPH_SCRATCH_RBD_CFG_S */
129 
130 /*
131  * struct iwl_prph_scratch_uefi_cfg - prph scratch reduce power table
132  * @base_addr: reduce power table address
133  * @size: table size in dwords
134  */
135 struct iwl_prph_scratch_uefi_cfg {
136 	__le64 base_addr;
137 	__le32 size;
138 	__le32 reserved;
139 } __packed; /* PERIPH_SCRATCH_UEFI_CFG_S */
140 
141 /*
142  * struct iwl_prph_scratch_ctrl_cfg - prph scratch ctrl and config
143  * @version: version information of context info and HW
144  * @control: control flags of FH configurations
145  * @pnvm_cfg: ror configuration
146  * @hwm_cfg: hwm configuration
147  * @rbd_cfg: default RX queue configuration
148  */
149 struct iwl_prph_scratch_ctrl_cfg {
150 	struct iwl_prph_scratch_version version;
151 	struct iwl_prph_scratch_control control;
152 	struct iwl_prph_scratch_pnvm_cfg pnvm_cfg;
153 	struct iwl_prph_scratch_hwm_cfg hwm_cfg;
154 	struct iwl_prph_scratch_rbd_cfg rbd_cfg;
155 	struct iwl_prph_scratch_uefi_cfg reduce_power_cfg;
156 } __packed; /* PERIPH_SCRATCH_CTRL_CFG_S */
157 
158 /*
159  * struct iwl_prph_scratch - peripheral scratch mapping
160  * @ctrl_cfg: control and configuration of prph scratch
161  * @dram: firmware images addresses in DRAM
162  * @reserved: reserved
163  */
164 struct iwl_prph_scratch {
165 	struct iwl_prph_scratch_ctrl_cfg ctrl_cfg;
166 	__le32 reserved[12];
167 	struct iwl_context_info_dram dram;
168 } __packed; /* PERIPH_SCRATCH_S */
169 
170 /*
171  * struct iwl_prph_info - peripheral information
172  * @boot_stage_mirror: reflects the value in the Boot Stage CSR register
173  * @ipc_status_mirror: reflects the value in the IPC Status CSR register
174  * @sleep_notif: indicates the peripheral sleep status
175  * @reserved: reserved
176  */
177 struct iwl_prph_info {
178 	__le32 boot_stage_mirror;
179 	__le32 ipc_status_mirror;
180 	__le32 sleep_notif;
181 	__le32 reserved;
182 } __packed; /* PERIPH_INFO_S */
183 
184 /*
185  * struct iwl_context_info_gen3 - device INIT configuration
186  * @version: version of the context information
187  * @size: size of context information in DWs
188  * @config: context in which the peripheral would execute - a subset of
189  *	capability csr register published by the peripheral
190  * @prph_info_base_addr: the peripheral information structure start address
191  * @cr_head_idx_arr_base_addr: the completion ring head index array
192  *	start address
193  * @tr_tail_idx_arr_base_addr: the transfer ring tail index array
194  *	start address
195  * @cr_tail_idx_arr_base_addr: the completion ring tail index array
196  *	start address
197  * @tr_head_idx_arr_base_addr: the transfer ring head index array
198  *	start address
199  * @cr_idx_arr_size: number of entries in the completion ring index array
200  * @tr_idx_arr_size: number of entries in the transfer ring index array
201  * @mtr_base_addr: the message transfer ring start address
202  * @mcr_base_addr: the message completion ring start address
203  * @mtr_size: number of entries which the message transfer ring can hold
204  * @mcr_size: number of entries which the message completion ring can hold
205  * @mtr_doorbell_vec: the doorbell vector associated with the message
206  *	transfer ring
207  * @mcr_doorbell_vec: the doorbell vector associated with the message
208  *	completion ring
209  * @mtr_msi_vec: the MSI which shall be generated by the peripheral after
210  *	completing a transfer descriptor in the message transfer ring
211  * @mcr_msi_vec: the MSI which shall be generated by the peripheral after
212  *	completing a completion descriptor in the message completion ring
213  * @mtr_opt_header_size: the size of the optional header in the transfer
214  *	descriptor associated with the message transfer ring in DWs
215  * @mtr_opt_footer_size: the size of the optional footer in the transfer
216  *	descriptor associated with the message transfer ring in DWs
217  * @mcr_opt_header_size: the size of the optional header in the completion
218  *	descriptor associated with the message completion ring in DWs
219  * @mcr_opt_footer_size: the size of the optional footer in the completion
220  *	descriptor associated with the message completion ring in DWs
221  * @msg_rings_ctrl_flags: message rings control flags
222  * @prph_info_msi_vec: the MSI which shall be generated by the peripheral
223  *	after updating the Peripheral Information structure
224  * @prph_scratch_base_addr: the peripheral scratch structure start address
225  * @prph_scratch_size: the size of the peripheral scratch structure in DWs
226  * @reserved: reserved
227  */
228 struct iwl_context_info_gen3 {
229 	__le16 version;
230 	__le16 size;
231 	__le32 config;
232 	__le64 prph_info_base_addr;
233 	__le64 cr_head_idx_arr_base_addr;
234 	__le64 tr_tail_idx_arr_base_addr;
235 	__le64 cr_tail_idx_arr_base_addr;
236 	__le64 tr_head_idx_arr_base_addr;
237 	__le16 cr_idx_arr_size;
238 	__le16 tr_idx_arr_size;
239 	__le64 mtr_base_addr;
240 	__le64 mcr_base_addr;
241 	__le16 mtr_size;
242 	__le16 mcr_size;
243 	__le16 mtr_doorbell_vec;
244 	__le16 mcr_doorbell_vec;
245 	__le16 mtr_msi_vec;
246 	__le16 mcr_msi_vec;
247 	u8 mtr_opt_header_size;
248 	u8 mtr_opt_footer_size;
249 	u8 mcr_opt_header_size;
250 	u8 mcr_opt_footer_size;
251 	__le16 msg_rings_ctrl_flags;
252 	__le16 prph_info_msi_vec;
253 	__le64 prph_scratch_base_addr;
254 	__le32 prph_scratch_size;
255 	__le32 reserved;
256 } __packed; /* IPC_CONTEXT_INFO_S */
257 
258 int iwl_pcie_ctxt_info_gen3_init(struct iwl_trans *trans,
259 				 const struct fw_img *fw);
260 void iwl_pcie_ctxt_info_gen3_free(struct iwl_trans *trans, bool alive);
261 
262 int iwl_trans_pcie_ctx_info_gen3_set_pnvm(struct iwl_trans *trans,
263 					  const void *data, u32 len);
264 int iwl_trans_pcie_ctx_info_gen3_set_reduce_power(struct iwl_trans *trans,
265 						  const void *data, u32 len);
266 
267 #endif /* __iwl_context_info_file_gen3_h__ */
268