blob: b0528883a99594a867de7782e6b1144da6c08088 [file] [log] [blame]
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03001// SPDX-License-Identifier: GPL-2.0
2
3/*
4 * Copyright 2016-2020 HabanaLabs, Ltd.
5 * All Rights Reserved.
6 */
7
8#include "gaudiP.h"
Greg Kroah-Hartman7b16a152020-07-28 19:18:51 +02009#include "../include/hw_ip/mmu/mmu_general.h"
10#include "../include/hw_ip/mmu/mmu_v1_1.h"
11#include "../include/gaudi/gaudi_masks.h"
12#include "../include/gaudi/gaudi_fw_if.h"
13#include "../include/gaudi/gaudi_reg_map.h"
14#include "../include/gaudi/gaudi_async_ids_map_extended.h"
Oded Gabbayac0ae6a2020-05-11 10:29:27 +030015
16#include <linux/module.h>
17#include <linux/pci.h>
18#include <linux/firmware.h>
19#include <linux/hwmon.h>
Oded Gabbayac0ae6a2020-05-11 10:29:27 +030020#include <linux/iommu.h>
21#include <linux/seq_file.h>
22
23/*
24 * Gaudi security scheme:
25 *
26 * 1. Host is protected by:
27 * - Range registers
28 * - MMU
29 *
30 * 2. DDR is protected by:
31 * - Range registers (protect the first 512MB)
32 *
33 * 3. Configuration is protected by:
34 * - Range registers
35 * - Protection bits
36 *
37 * MMU is always enabled.
38 *
Ofir Bitton0940cab2020-08-31 08:52:56 +030039 * QMAN DMA channels 0,1 (PCI DMAN):
Oded Gabbayac0ae6a2020-05-11 10:29:27 +030040 * - DMA is not secured.
41 * - PQ and CQ are secured.
42 * - CP is secured: The driver needs to parse CB but WREG should be allowed
43 * because of TDMA (tensor DMA). Hence, WREG is always not
44 * secured.
45 *
46 * When the driver needs to use DMA it will check that Gaudi is idle, set DMA
47 * channel 0 to be secured, execute the DMA and change it back to not secured.
48 * Currently, the driver doesn't use the DMA while there are compute jobs
49 * running.
50 *
51 * The current use cases for the driver to use the DMA are:
52 * - Clear SRAM on context switch (happens on context switch when device is
53 * idle)
54 * - MMU page tables area clear (happens on init)
55 *
Ofir Bitton0940cab2020-08-31 08:52:56 +030056 * QMAN DMA 2-7, TPC, MME, NIC:
Oded Gabbayac0ae6a2020-05-11 10:29:27 +030057 * PQ is secured and is located on the Host (HBM CON TPC3 bug)
58 * CQ, CP and the engine are not secured
59 *
60 */
61
62#define GAUDI_BOOT_FIT_FILE "habanalabs/gaudi/gaudi-boot-fit.itb"
63#define GAUDI_LINUX_FW_FILE "habanalabs/gaudi/gaudi-fit.itb"
64#define GAUDI_TPC_FW_FILE "habanalabs/gaudi/gaudi_tpc.bin"
65
66#define GAUDI_DMA_POOL_BLK_SIZE 0x100 /* 256 bytes */
67
Ofir Bittonb90c8942020-11-08 12:59:04 +020068#define GAUDI_RESET_TIMEOUT_MSEC 2000 /* 2000ms */
Oded Gabbayac0ae6a2020-05-11 10:29:27 +030069#define GAUDI_RESET_WAIT_MSEC 1 /* 1ms */
70#define GAUDI_CPU_RESET_WAIT_MSEC 200 /* 200ms */
71#define GAUDI_TEST_QUEUE_WAIT_USEC 100000 /* 100ms */
72
73#define GAUDI_PLDM_RESET_WAIT_MSEC 1000 /* 1s */
74#define GAUDI_PLDM_HRESET_TIMEOUT_MSEC 20000 /* 20s */
Oded Gabbayac0ae6a2020-05-11 10:29:27 +030075#define GAUDI_PLDM_TEST_QUEUE_WAIT_USEC 1000000 /* 1s */
76#define GAUDI_PLDM_MMU_TIMEOUT_USEC (MMU_CONFIG_TIMEOUT_USEC * 100)
77#define GAUDI_PLDM_QMAN0_TIMEOUT_USEC (HL_DEVICE_TIMEOUT_USEC * 30)
78#define GAUDI_PLDM_TPC_KERNEL_WAIT_USEC (HL_DEVICE_TIMEOUT_USEC * 30)
79#define GAUDI_BOOT_FIT_REQ_TIMEOUT_USEC 1000000 /* 1s */
Oded Gabbay788cacf2020-07-07 17:30:13 +030080#define GAUDI_MSG_TO_CPU_TIMEOUT_USEC 4000000 /* 4s */
Oded Gabbayac0ae6a2020-05-11 10:29:27 +030081
82#define GAUDI_QMAN0_FENCE_VAL 0x72E91AB9
83
84#define GAUDI_MAX_STRING_LEN 20
85
86#define GAUDI_CB_POOL_CB_CNT 512
87#define GAUDI_CB_POOL_CB_SIZE 0x20000 /* 128KB */
88
89#define GAUDI_ALLOC_CPU_MEM_RETRY_CNT 3
90
91#define GAUDI_NUM_OF_TPC_INTR_CAUSE 20
92
93#define GAUDI_NUM_OF_QM_ERR_CAUSE 16
94
95#define GAUDI_NUM_OF_QM_ARB_ERR_CAUSE 3
96
Oded Gabbay647e8352020-06-07 11:26:48 +030097#define GAUDI_ARB_WDT_TIMEOUT 0x1000000
Oded Gabbayac0ae6a2020-05-11 10:29:27 +030098
Oded Gabbaye38bfd32020-07-03 20:46:12 +030099#define GAUDI_CLK_GATE_DEBUGFS_MASK (\
100 BIT(GAUDI_ENGINE_ID_MME_0) |\
101 BIT(GAUDI_ENGINE_ID_MME_2) |\
102 GENMASK_ULL(GAUDI_ENGINE_ID_TPC_7, GAUDI_ENGINE_ID_TPC_0))
103
farah kassabri03df1362020-05-06 11:17:38 +0300104#define HBM_SCRUBBING_TIMEOUT_US 1000000 /* 1s */
105
Alon Mizrahi41478642020-11-17 14:25:14 +0200106#define GAUDI_PLL_MAX 10
107
Oded Gabbayac0ae6a2020-05-11 10:29:27 +0300108static const char gaudi_irq_name[GAUDI_MSI_ENTRIES][GAUDI_MAX_STRING_LEN] = {
109 "gaudi cq 0_0", "gaudi cq 0_1", "gaudi cq 0_2", "gaudi cq 0_3",
110 "gaudi cq 1_0", "gaudi cq 1_1", "gaudi cq 1_2", "gaudi cq 1_3",
111 "gaudi cq 5_0", "gaudi cq 5_1", "gaudi cq 5_2", "gaudi cq 5_3",
112 "gaudi cpu eq"
113};
114
115static const u8 gaudi_dma_assignment[GAUDI_DMA_MAX] = {
Oded Gabbaye38bfd32020-07-03 20:46:12 +0300116 [GAUDI_PCI_DMA_1] = GAUDI_ENGINE_ID_DMA_0,
117 [GAUDI_PCI_DMA_2] = GAUDI_ENGINE_ID_DMA_1,
Oded Gabbaye38bfd32020-07-03 20:46:12 +0300118 [GAUDI_HBM_DMA_1] = GAUDI_ENGINE_ID_DMA_2,
119 [GAUDI_HBM_DMA_2] = GAUDI_ENGINE_ID_DMA_3,
120 [GAUDI_HBM_DMA_3] = GAUDI_ENGINE_ID_DMA_4,
Ofir Bitton0940cab2020-08-31 08:52:56 +0300121 [GAUDI_HBM_DMA_4] = GAUDI_ENGINE_ID_DMA_5,
122 [GAUDI_HBM_DMA_5] = GAUDI_ENGINE_ID_DMA_6,
123 [GAUDI_HBM_DMA_6] = GAUDI_ENGINE_ID_DMA_7
Oded Gabbayac0ae6a2020-05-11 10:29:27 +0300124};
125
126static const u8 gaudi_cq_assignment[NUMBER_OF_CMPLT_QUEUES] = {
127 [0] = GAUDI_QUEUE_ID_DMA_0_0,
128 [1] = GAUDI_QUEUE_ID_DMA_0_1,
129 [2] = GAUDI_QUEUE_ID_DMA_0_2,
130 [3] = GAUDI_QUEUE_ID_DMA_0_3,
131 [4] = GAUDI_QUEUE_ID_DMA_1_0,
132 [5] = GAUDI_QUEUE_ID_DMA_1_1,
133 [6] = GAUDI_QUEUE_ID_DMA_1_2,
134 [7] = GAUDI_QUEUE_ID_DMA_1_3,
Oded Gabbayac0ae6a2020-05-11 10:29:27 +0300135};
136
137static const u16 gaudi_packet_sizes[MAX_PACKET_ID] = {
138 [PACKET_WREG_32] = sizeof(struct packet_wreg32),
139 [PACKET_WREG_BULK] = sizeof(struct packet_wreg_bulk),
140 [PACKET_MSG_LONG] = sizeof(struct packet_msg_long),
141 [PACKET_MSG_SHORT] = sizeof(struct packet_msg_short),
142 [PACKET_CP_DMA] = sizeof(struct packet_cp_dma),
143 [PACKET_REPEAT] = sizeof(struct packet_repeat),
144 [PACKET_MSG_PROT] = sizeof(struct packet_msg_prot),
145 [PACKET_FENCE] = sizeof(struct packet_fence),
146 [PACKET_LIN_DMA] = sizeof(struct packet_lin_dma),
147 [PACKET_NOP] = sizeof(struct packet_nop),
148 [PACKET_STOP] = sizeof(struct packet_stop),
149 [PACKET_ARB_POINT] = sizeof(struct packet_arb_point),
150 [PACKET_WAIT] = sizeof(struct packet_wait),
151 [PACKET_LOAD_AND_EXE] = sizeof(struct packet_load_and_exe)
152};
153
Ofir Bittonbc75be22020-07-30 14:56:38 +0300154static inline bool validate_packet_id(enum packet_id id)
155{
156 switch (id) {
157 case PACKET_WREG_32:
158 case PACKET_WREG_BULK:
159 case PACKET_MSG_LONG:
160 case PACKET_MSG_SHORT:
161 case PACKET_CP_DMA:
162 case PACKET_REPEAT:
163 case PACKET_MSG_PROT:
164 case PACKET_FENCE:
165 case PACKET_LIN_DMA:
166 case PACKET_NOP:
167 case PACKET_STOP:
168 case PACKET_ARB_POINT:
169 case PACKET_WAIT:
170 case PACKET_LOAD_AND_EXE:
171 return true;
172 default:
173 return false;
174 }
175}
176
Oded Gabbayac0ae6a2020-05-11 10:29:27 +0300177static const char * const
178gaudi_tpc_interrupts_cause[GAUDI_NUM_OF_TPC_INTR_CAUSE] = {
179 "tpc_address_exceed_slm",
180 "tpc_div_by_0",
181 "tpc_spu_mac_overflow",
182 "tpc_spu_addsub_overflow",
183 "tpc_spu_abs_overflow",
184 "tpc_spu_fp_dst_nan_inf",
185 "tpc_spu_fp_dst_denorm",
186 "tpc_vpu_mac_overflow",
187 "tpc_vpu_addsub_overflow",
188 "tpc_vpu_abs_overflow",
189 "tpc_vpu_fp_dst_nan_inf",
190 "tpc_vpu_fp_dst_denorm",
191 "tpc_assertions",
192 "tpc_illegal_instruction",
193 "tpc_pc_wrap_around",
194 "tpc_qm_sw_err",
195 "tpc_hbw_rresp_err",
196 "tpc_hbw_bresp_err",
197 "tpc_lbw_rresp_err",
198 "tpc_lbw_bresp_err"
199};
200
201static const char * const
202gaudi_qman_error_cause[GAUDI_NUM_OF_QM_ERR_CAUSE] = {
203 "PQ AXI HBW error",
204 "CQ AXI HBW error",
205 "CP AXI HBW error",
206 "CP error due to undefined OPCODE",
207 "CP encountered STOP OPCODE",
208 "CP AXI LBW error",
209 "CP WRREG32 or WRBULK returned error",
210 "N/A",
211 "FENCE 0 inc over max value and clipped",
212 "FENCE 1 inc over max value and clipped",
213 "FENCE 2 inc over max value and clipped",
214 "FENCE 3 inc over max value and clipped",
215 "FENCE 0 dec under min value and clipped",
216 "FENCE 1 dec under min value and clipped",
217 "FENCE 2 dec under min value and clipped",
218 "FENCE 3 dec under min value and clipped"
219};
220
221static const char * const
222gaudi_qman_arb_error_cause[GAUDI_NUM_OF_QM_ARB_ERR_CAUSE] = {
223 "Choice push while full error",
224 "Choice Q watchdog error",
225 "MSG AXI LBW returned with error"
226};
227
228static enum hl_queue_type gaudi_queue_type[GAUDI_QUEUE_ID_SIZE] = {
229 QUEUE_TYPE_EXT, /* GAUDI_QUEUE_ID_DMA_0_0 */
230 QUEUE_TYPE_EXT, /* GAUDI_QUEUE_ID_DMA_0_1 */
231 QUEUE_TYPE_EXT, /* GAUDI_QUEUE_ID_DMA_0_2 */
232 QUEUE_TYPE_EXT, /* GAUDI_QUEUE_ID_DMA_0_3 */
233 QUEUE_TYPE_EXT, /* GAUDI_QUEUE_ID_DMA_1_0 */
234 QUEUE_TYPE_EXT, /* GAUDI_QUEUE_ID_DMA_1_1 */
235 QUEUE_TYPE_EXT, /* GAUDI_QUEUE_ID_DMA_1_2 */
236 QUEUE_TYPE_EXT, /* GAUDI_QUEUE_ID_DMA_1_3 */
237 QUEUE_TYPE_CPU, /* GAUDI_QUEUE_ID_CPU_PQ */
238 QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_DMA_2_0 */
239 QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_DMA_2_1 */
240 QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_DMA_2_2 */
241 QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_DMA_2_3 */
242 QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_DMA_3_0 */
243 QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_DMA_3_1 */
244 QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_DMA_3_2 */
245 QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_DMA_3_3 */
246 QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_DMA_4_0 */
247 QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_DMA_4_1 */
248 QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_DMA_4_2 */
249 QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_DMA_4_3 */
Ofir Bitton0940cab2020-08-31 08:52:56 +0300250 QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_DMA_5_0 */
251 QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_DMA_5_1 */
252 QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_DMA_5_2 */
253 QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_DMA_5_3 */
Oded Gabbayac0ae6a2020-05-11 10:29:27 +0300254 QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_DMA_6_0 */
255 QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_DMA_6_1 */
256 QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_DMA_6_2 */
257 QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_DMA_6_3 */
258 QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_DMA_7_0 */
259 QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_DMA_7_1 */
260 QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_DMA_7_2 */
261 QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_DMA_7_3 */
262 QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_MME_0_0 */
263 QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_MME_0_1 */
264 QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_MME_0_2 */
265 QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_MME_0_3 */
266 QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_MME_1_0 */
267 QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_MME_1_1 */
268 QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_MME_1_2 */
269 QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_MME_1_3 */
270 QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_TPC_0_0 */
271 QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_TPC_0_1 */
272 QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_TPC_0_2 */
273 QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_TPC_0_3 */
274 QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_TPC_1_0 */
275 QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_TPC_1_1 */
276 QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_TPC_1_2 */
277 QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_TPC_1_3 */
278 QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_TPC_2_0 */
279 QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_TPC_2_1 */
280 QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_TPC_2_2 */
281 QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_TPC_2_3 */
282 QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_TPC_3_0 */
283 QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_TPC_3_1 */
284 QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_TPC_3_2 */
285 QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_TPC_3_3 */
286 QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_TPC_4_0 */
287 QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_TPC_4_1 */
288 QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_TPC_4_2 */
289 QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_TPC_4_3 */
290 QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_TPC_5_0 */
291 QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_TPC_5_1 */
292 QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_TPC_5_2 */
293 QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_TPC_5_3 */
294 QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_TPC_6_0 */
295 QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_TPC_6_1 */
296 QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_TPC_6_2 */
297 QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_TPC_6_3 */
298 QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_TPC_7_0 */
299 QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_TPC_7_1 */
300 QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_TPC_7_2 */
301 QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_TPC_7_3 */
Oded Gabbay3c681572020-11-02 21:10:39 +0200302 QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_NIC_0_0 */
303 QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_NIC_0_1 */
304 QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_NIC_0_2 */
305 QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_NIC_0_3 */
306 QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_NIC_1_0 */
307 QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_NIC_1_1 */
308 QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_NIC_1_2 */
309 QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_NIC_1_3 */
310 QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_NIC_2_0 */
311 QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_NIC_2_1 */
312 QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_NIC_2_2 */
313 QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_NIC_2_3 */
314 QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_NIC_3_0 */
315 QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_NIC_3_1 */
316 QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_NIC_3_2 */
317 QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_NIC_3_3 */
318 QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_NIC_4_0 */
319 QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_NIC_4_1 */
320 QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_NIC_4_2 */
321 QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_NIC_4_3 */
322 QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_NIC_5_0 */
323 QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_NIC_5_1 */
324 QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_NIC_5_2 */
325 QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_NIC_5_3 */
326 QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_NIC_6_0 */
327 QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_NIC_6_1 */
328 QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_NIC_6_2 */
329 QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_NIC_6_3 */
330 QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_NIC_7_0 */
331 QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_NIC_7_1 */
332 QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_NIC_7_2 */
333 QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_NIC_7_3 */
334 QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_NIC_8_0 */
335 QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_NIC_8_1 */
336 QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_NIC_8_2 */
337 QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_NIC_8_3 */
338 QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_NIC_9_0 */
339 QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_NIC_9_1 */
340 QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_NIC_9_2 */
341 QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_NIC_9_3 */
Oded Gabbayac0ae6a2020-05-11 10:29:27 +0300342};
343
Oded Gabbayfcc6a4e2020-05-17 08:20:35 +0300344struct ecc_info_extract_params {
345 u64 block_address;
346 u32 num_memories;
347 bool derr;
348 bool disable_clock_gating;
349};
350
Oded Gabbayac0ae6a2020-05-11 10:29:27 +0300351static int gaudi_mmu_update_asid_hop0_addr(struct hl_device *hdev, u32 asid,
352 u64 phys_addr);
353static int gaudi_send_job_on_qman0(struct hl_device *hdev,
354 struct hl_cs_job *job);
355static int gaudi_memset_device_memory(struct hl_device *hdev, u64 addr,
356 u32 size, u64 val);
357static int gaudi_run_tpc_kernel(struct hl_device *hdev, u64 tpc_kernel,
358 u32 tpc_id);
359static int gaudi_mmu_clear_pgt_range(struct hl_device *hdev);
Oded Gabbay2f553422020-08-15 16:28:10 +0300360static int gaudi_cpucp_info_get(struct hl_device *hdev);
Oded Gabbayac0ae6a2020-05-11 10:29:27 +0300361static void gaudi_disable_clock_gating(struct hl_device *hdev);
362static void gaudi_mmu_prepare(struct hl_device *hdev, u32 asid);
Ofir Bitton5de406c2020-09-10 10:56:26 +0300363static u32 gaudi_gen_signal_cb(struct hl_device *hdev, void *data, u16 sob_id,
Alon Mizrahi72ab9ca52020-12-02 19:55:30 +0200364 u32 size, bool eb);
Ofir Bitton5de406c2020-09-10 10:56:26 +0300365static u32 gaudi_gen_wait_cb(struct hl_device *hdev,
366 struct hl_gen_wait_properties *prop);
367
368static inline enum hl_collective_mode
369get_collective_mode(struct hl_device *hdev, u32 queue_id)
370{
371 if (gaudi_queue_type[queue_id] == QUEUE_TYPE_EXT)
372 return HL_COLLECTIVE_MASTER;
373
374 if (queue_id >= GAUDI_QUEUE_ID_DMA_5_0 &&
375 queue_id <= GAUDI_QUEUE_ID_DMA_5_3)
376 return HL_COLLECTIVE_SLAVE;
377
378 if (queue_id >= GAUDI_QUEUE_ID_TPC_7_0 &&
379 queue_id <= GAUDI_QUEUE_ID_TPC_7_3)
380 return HL_COLLECTIVE_SLAVE;
381
382 if (queue_id >= GAUDI_QUEUE_ID_NIC_0_0 &&
383 queue_id <= GAUDI_QUEUE_ID_NIC_9_3)
384 return HL_COLLECTIVE_SLAVE;
385
386 return HL_COLLECTIVE_NOT_SUPPORTED;
387}
Oded Gabbayac0ae6a2020-05-11 10:29:27 +0300388
389static int gaudi_get_fixed_properties(struct hl_device *hdev)
390{
391 struct asic_fixed_properties *prop = &hdev->asic_prop;
Ofir Bitton843839b2020-07-19 11:08:09 +0300392 u32 num_sync_stream_queues = 0;
Oded Gabbayac0ae6a2020-05-11 10:29:27 +0300393 int i;
394
Ofir Bitton3abc99b2020-06-23 14:50:39 +0300395 prop->max_queues = GAUDI_QUEUE_ID_SIZE;
396 prop->hw_queues_props = kcalloc(prop->max_queues,
397 sizeof(struct hw_queue_properties),
398 GFP_KERNEL);
Oded Gabbayac0ae6a2020-05-11 10:29:27 +0300399
Ofir Bitton3abc99b2020-06-23 14:50:39 +0300400 if (!prop->hw_queues_props)
401 return -ENOMEM;
402
403 for (i = 0 ; i < prop->max_queues ; i++) {
Oded Gabbayac0ae6a2020-05-11 10:29:27 +0300404 if (gaudi_queue_type[i] == QUEUE_TYPE_EXT) {
405 prop->hw_queues_props[i].type = QUEUE_TYPE_EXT;
406 prop->hw_queues_props[i].driver_only = 0;
Ofir Bitton21e7a342020-05-14 18:25:47 +0300407 prop->hw_queues_props[i].supports_sync_stream = 1;
Tal Cohen4bb1f2f2020-06-03 09:25:27 +0300408 prop->hw_queues_props[i].cb_alloc_flags =
409 CB_ALLOC_KERNEL;
Ofir Bitton843839b2020-07-19 11:08:09 +0300410 num_sync_stream_queues++;
Oded Gabbayac0ae6a2020-05-11 10:29:27 +0300411 } else if (gaudi_queue_type[i] == QUEUE_TYPE_CPU) {
412 prop->hw_queues_props[i].type = QUEUE_TYPE_CPU;
413 prop->hw_queues_props[i].driver_only = 1;
Ofir Bitton21e7a342020-05-14 18:25:47 +0300414 prop->hw_queues_props[i].supports_sync_stream = 0;
Tal Cohen4bb1f2f2020-06-03 09:25:27 +0300415 prop->hw_queues_props[i].cb_alloc_flags =
416 CB_ALLOC_KERNEL;
Oded Gabbayac0ae6a2020-05-11 10:29:27 +0300417 } else if (gaudi_queue_type[i] == QUEUE_TYPE_INT) {
418 prop->hw_queues_props[i].type = QUEUE_TYPE_INT;
419 prop->hw_queues_props[i].driver_only = 0;
Tal Cohen4bb1f2f2020-06-03 09:25:27 +0300420 prop->hw_queues_props[i].supports_sync_stream = 0;
421 prop->hw_queues_props[i].cb_alloc_flags =
422 CB_ALLOC_USER;
Ofir Bitton5de406c2020-09-10 10:56:26 +0300423
Oded Gabbayac0ae6a2020-05-11 10:29:27 +0300424 }
Ofir Bitton5de406c2020-09-10 10:56:26 +0300425 prop->hw_queues_props[i].collective_mode =
426 get_collective_mode(hdev, i);
Oded Gabbayac0ae6a2020-05-11 10:29:27 +0300427 }
428
Oded Gabbayac0ae6a2020-05-11 10:29:27 +0300429 prop->completion_queues_count = NUMBER_OF_CMPLT_QUEUES;
Ofir Bitton5de406c2020-09-10 10:56:26 +0300430 prop->collective_first_sob = 0;
431 prop->collective_first_mon = 0;
432
433 /* 2 SOBs per internal queue stream are reserved for collective */
434 prop->sync_stream_first_sob =
435 ALIGN(NUMBER_OF_SOBS_IN_GRP, HL_MAX_SOBS_PER_MONITOR)
436 * QMAN_STREAMS * HL_RSVD_SOBS;
437
438 /* 1 monitor per internal queue stream are reserved for collective
439 * 2 monitors per external queue stream are reserved for collective
440 */
441 prop->sync_stream_first_mon =
442 (NUMBER_OF_COLLECTIVE_QUEUES * QMAN_STREAMS) +
443 (NUMBER_OF_EXT_HW_QUEUES * 2);
444
Oded Gabbayac0ae6a2020-05-11 10:29:27 +0300445 prop->dram_base_address = DRAM_PHYS_BASE;
446 prop->dram_size = GAUDI_HBM_SIZE_32GB;
447 prop->dram_end_address = prop->dram_base_address +
448 prop->dram_size;
449 prop->dram_user_base_address = DRAM_BASE_ADDR_USER;
450
451 prop->sram_base_address = SRAM_BASE_ADDR;
452 prop->sram_size = SRAM_SIZE;
453 prop->sram_end_address = prop->sram_base_address +
454 prop->sram_size;
455 prop->sram_user_base_address = prop->sram_base_address +
456 SRAM_USER_BASE_OFFSET;
457
458 prop->mmu_pgt_addr = MMU_PAGE_TABLES_ADDR;
459 if (hdev->pldm)
460 prop->mmu_pgt_size = 0x800000; /* 8MB */
461 else
462 prop->mmu_pgt_size = MMU_PAGE_TABLES_SIZE;
463 prop->mmu_pte_size = HL_PTE_SIZE;
464 prop->mmu_hop_table_size = HOP_TABLE_SIZE;
465 prop->mmu_hop0_tables_total_size = HOP0_TABLES_TOTAL_SIZE;
466 prop->dram_page_size = PAGE_SIZE_2MB;
Oded Gabbay7f070c92020-11-09 09:48:31 +0200467 prop->dram_supports_virtual_memory = false;
Oded Gabbayac0ae6a2020-05-11 10:29:27 +0300468
469 prop->pmmu.hop0_shift = HOP0_SHIFT;
470 prop->pmmu.hop1_shift = HOP1_SHIFT;
471 prop->pmmu.hop2_shift = HOP2_SHIFT;
472 prop->pmmu.hop3_shift = HOP3_SHIFT;
473 prop->pmmu.hop4_shift = HOP4_SHIFT;
474 prop->pmmu.hop0_mask = HOP0_MASK;
475 prop->pmmu.hop1_mask = HOP1_MASK;
476 prop->pmmu.hop2_mask = HOP2_MASK;
477 prop->pmmu.hop3_mask = HOP3_MASK;
478 prop->pmmu.hop4_mask = HOP4_MASK;
479 prop->pmmu.start_addr = VA_HOST_SPACE_START;
480 prop->pmmu.end_addr =
481 (VA_HOST_SPACE_START + VA_HOST_SPACE_SIZE / 2) - 1;
482 prop->pmmu.page_size = PAGE_SIZE_4KB;
Moti Haimovski7edf3412020-08-23 13:23:13 +0300483 prop->pmmu.num_hops = MMU_ARCH_5_HOPS;
Oded Gabbayac0ae6a2020-05-11 10:29:27 +0300484
485 /* PMMU and HPMMU are the same except of page size */
486 memcpy(&prop->pmmu_huge, &prop->pmmu, sizeof(prop->pmmu));
487 prop->pmmu_huge.page_size = PAGE_SIZE_2MB;
488
489 /* shifts and masks are the same in PMMU and DMMU */
490 memcpy(&prop->dmmu, &prop->pmmu, sizeof(prop->pmmu));
491 prop->dmmu.start_addr = (VA_HOST_SPACE_START + VA_HOST_SPACE_SIZE / 2);
492 prop->dmmu.end_addr = VA_HOST_SPACE_END;
493 prop->dmmu.page_size = PAGE_SIZE_2MB;
494
495 prop->cfg_size = CFG_SIZE;
496 prop->max_asid = MAX_ASID;
497 prop->num_of_events = GAUDI_EVENT_SIZE;
498 prop->tpc_enabled_mask = TPC_ENABLED_MASK;
499
Oded Gabbay58361aa2020-08-08 23:34:47 +0300500 prop->max_power_default = MAX_POWER_DEFAULT_PCI;
Oded Gabbayac0ae6a2020-05-11 10:29:27 +0300501
502 prop->cb_pool_cb_cnt = GAUDI_CB_POOL_CB_CNT;
503 prop->cb_pool_cb_size = GAUDI_CB_POOL_CB_SIZE;
504
505 prop->pcie_dbi_base_address = mmPCIE_DBI_BASE;
506 prop->pcie_aux_dbi_reg_addr = CFG_BASE + mmPCIE_AUX_DBI;
507
Oded Gabbay2f553422020-08-15 16:28:10 +0300508 strncpy(prop->cpucp_info.card_name, GAUDI_DEFAULT_CARD_NAME,
Oded Gabbayac0ae6a2020-05-11 10:29:27 +0300509 CARD_NAME_MAX_LEN);
510
Ofir Bittonc16d45f2020-06-02 12:28:27 +0300511 prop->max_pending_cs = GAUDI_MAX_PENDING_CS;
512
Ofir Bitton843839b2020-07-19 11:08:09 +0300513 prop->first_available_user_sob[HL_GAUDI_WS_DCORE] =
Ofir Bitton3cf74b32020-09-10 09:17:50 +0300514 prop->sync_stream_first_sob +
515 (num_sync_stream_queues * HL_RSVD_SOBS);
Ofir Bitton843839b2020-07-19 11:08:09 +0300516 prop->first_available_user_mon[HL_GAUDI_WS_DCORE] =
Ofir Bitton3cf74b32020-09-10 09:17:50 +0300517 prop->sync_stream_first_mon +
518 (num_sync_stream_queues * HL_RSVD_MONS);
Ofir Bitton843839b2020-07-19 11:08:09 +0300519
Ofir Bitton323b7262020-10-04 09:09:19 +0300520 /* disable fw security for now, set it in a later stage */
521 prop->fw_security_disabled = true;
522 prop->fw_security_status_valid = false;
Ofir Bittond611b9f2020-11-08 13:10:09 +0200523 prop->hard_reset_done_by_fw = false;
Ofir Bitton323b7262020-10-04 09:09:19 +0300524
Oded Gabbayac0ae6a2020-05-11 10:29:27 +0300525 return 0;
526}
527
528static int gaudi_pci_bars_map(struct hl_device *hdev)
529{
530 static const char * const name[] = {"SRAM", "CFG", "HBM"};
531 bool is_wc[3] = {false, false, true};
532 int rc;
533
534 rc = hl_pci_bars_map(hdev, name, is_wc);
535 if (rc)
536 return rc;
537
538 hdev->rmmio = hdev->pcie_bar[CFG_BAR_ID] +
539 (CFG_BASE - SPI_FLASH_BASE_ADDR);
540
541 return 0;
542}
543
544static u64 gaudi_set_hbm_bar_base(struct hl_device *hdev, u64 addr)
545{
546 struct gaudi_device *gaudi = hdev->asic_specific;
Ofir Bittonf4cbfd22020-06-15 17:45:12 +0300547 struct hl_inbound_pci_region pci_region;
Oded Gabbayac0ae6a2020-05-11 10:29:27 +0300548 u64 old_addr = addr;
549 int rc;
550
551 if ((gaudi) && (gaudi->hbm_bar_cur_addr == addr))
552 return old_addr;
553
554 /* Inbound Region 2 - Bar 4 - Point to HBM */
Ofir Bittonf4cbfd22020-06-15 17:45:12 +0300555 pci_region.mode = PCI_BAR_MATCH_MODE;
556 pci_region.bar = HBM_BAR_ID;
557 pci_region.addr = addr;
558 rc = hl_pci_set_inbound_region(hdev, 2, &pci_region);
Oded Gabbayac0ae6a2020-05-11 10:29:27 +0300559 if (rc)
560 return U64_MAX;
561
562 if (gaudi) {
563 old_addr = gaudi->hbm_bar_cur_addr;
564 gaudi->hbm_bar_cur_addr = addr;
565 }
566
567 return old_addr;
568}
569
570static int gaudi_init_iatu(struct hl_device *hdev)
571{
Ofir Bittonf4cbfd22020-06-15 17:45:12 +0300572 struct hl_inbound_pci_region inbound_region;
573 struct hl_outbound_pci_region outbound_region;
574 int rc;
575
576 /* Inbound Region 0 - Bar 0 - Point to SRAM + CFG */
577 inbound_region.mode = PCI_BAR_MATCH_MODE;
578 inbound_region.bar = SRAM_BAR_ID;
579 inbound_region.addr = SRAM_BASE_ADDR;
580 rc = hl_pci_set_inbound_region(hdev, 0, &inbound_region);
581 if (rc)
582 goto done;
Oded Gabbayac0ae6a2020-05-11 10:29:27 +0300583
584 /* Inbound Region 1 - Bar 2 - Point to SPI FLASH */
Ofir Bittonf4cbfd22020-06-15 17:45:12 +0300585 inbound_region.mode = PCI_BAR_MATCH_MODE;
586 inbound_region.bar = CFG_BAR_ID;
587 inbound_region.addr = SPI_FLASH_BASE_ADDR;
588 rc = hl_pci_set_inbound_region(hdev, 1, &inbound_region);
Oded Gabbayac0ae6a2020-05-11 10:29:27 +0300589 if (rc)
Ofir Bittonf4cbfd22020-06-15 17:45:12 +0300590 goto done;
Oded Gabbayac0ae6a2020-05-11 10:29:27 +0300591
Ofir Bittonf4cbfd22020-06-15 17:45:12 +0300592 /* Inbound Region 2 - Bar 4 - Point to HBM */
593 inbound_region.mode = PCI_BAR_MATCH_MODE;
594 inbound_region.bar = HBM_BAR_ID;
595 inbound_region.addr = DRAM_PHYS_BASE;
596 rc = hl_pci_set_inbound_region(hdev, 2, &inbound_region);
597 if (rc)
598 goto done;
599
600 hdev->asic_funcs->set_dma_mask_from_fw(hdev);
601
602 /* Outbound Region 0 - Point to Host */
603 outbound_region.addr = HOST_PHYS_BASE;
604 outbound_region.size = HOST_PHYS_SIZE;
605 rc = hl_pci_set_outbound_region(hdev, &outbound_region);
606
607done:
608 return rc;
Oded Gabbayac0ae6a2020-05-11 10:29:27 +0300609}
610
Ofir Bittond1ddd902020-10-19 17:04:20 +0300611static enum hl_device_hw_state gaudi_get_hw_state(struct hl_device *hdev)
612{
613 return RREG32(mmHW_STATE);
614}
615
Oded Gabbayac0ae6a2020-05-11 10:29:27 +0300616static int gaudi_early_init(struct hl_device *hdev)
617{
618 struct asic_fixed_properties *prop = &hdev->asic_prop;
619 struct pci_dev *pdev = hdev->pdev;
620 int rc;
621
622 rc = gaudi_get_fixed_properties(hdev);
623 if (rc) {
624 dev_err(hdev->dev, "Failed to get fixed properties\n");
625 return rc;
626 }
627
628 /* Check BAR sizes */
629 if (pci_resource_len(pdev, SRAM_BAR_ID) != SRAM_BAR_SIZE) {
630 dev_err(hdev->dev,
631 "Not " HL_NAME "? BAR %d size %llu, expecting %llu\n",
632 SRAM_BAR_ID,
633 (unsigned long long) pci_resource_len(pdev,
634 SRAM_BAR_ID),
635 SRAM_BAR_SIZE);
Ofir Bitton3abc99b2020-06-23 14:50:39 +0300636 rc = -ENODEV;
637 goto free_queue_props;
Oded Gabbayac0ae6a2020-05-11 10:29:27 +0300638 }
639
640 if (pci_resource_len(pdev, CFG_BAR_ID) != CFG_BAR_SIZE) {
641 dev_err(hdev->dev,
642 "Not " HL_NAME "? BAR %d size %llu, expecting %llu\n",
643 CFG_BAR_ID,
644 (unsigned long long) pci_resource_len(pdev,
645 CFG_BAR_ID),
646 CFG_BAR_SIZE);
Ofir Bitton3abc99b2020-06-23 14:50:39 +0300647 rc = -ENODEV;
648 goto free_queue_props;
Oded Gabbayac0ae6a2020-05-11 10:29:27 +0300649 }
650
651 prop->dram_pci_bar_size = pci_resource_len(pdev, HBM_BAR_ID);
652
Ofir Bittond1ddd902020-10-19 17:04:20 +0300653 rc = hl_pci_init(hdev);
Oded Gabbayac0ae6a2020-05-11 10:29:27 +0300654 if (rc)
Ofir Bitton3abc99b2020-06-23 14:50:39 +0300655 goto free_queue_props;
Oded Gabbayac0ae6a2020-05-11 10:29:27 +0300656
Ofir Bittond1ddd902020-10-19 17:04:20 +0300657 /* Before continuing in the initialization, we need to read the preboot
658 * version to determine whether we run with a security-enabled firmware
659 */
660 rc = hl_fw_read_preboot_status(hdev, mmPSOC_GLOBAL_CONF_CPU_BOOT_STATUS,
661 mmCPU_BOOT_DEV_STS0, mmCPU_BOOT_ERR0,
662 GAUDI_BOOT_FIT_REQ_TIMEOUT_USEC);
663 if (rc) {
664 if (hdev->reset_on_preboot_fail)
665 hdev->asic_funcs->hw_fini(hdev, true);
666 goto pci_fini;
667 }
668
Ofir Bitton9c9013c2020-12-01 10:39:54 +0200669 if (gaudi_get_hw_state(hdev) == HL_DEVICE_HW_STATE_DIRTY) {
670 dev_info(hdev->dev,
671 "H/W state is dirty, must reset before initializing\n");
672 hdev->asic_funcs->hw_fini(hdev, true);
673 }
674
Oded Gabbayac0ae6a2020-05-11 10:29:27 +0300675 return 0;
Ofir Bitton3abc99b2020-06-23 14:50:39 +0300676
Ofir Bittond1ddd902020-10-19 17:04:20 +0300677pci_fini:
678 hl_pci_fini(hdev);
Ofir Bitton3abc99b2020-06-23 14:50:39 +0300679free_queue_props:
680 kfree(hdev->asic_prop.hw_queues_props);
681 return rc;
Oded Gabbayac0ae6a2020-05-11 10:29:27 +0300682}
683
684static int gaudi_early_fini(struct hl_device *hdev)
685{
Ofir Bitton3abc99b2020-06-23 14:50:39 +0300686 kfree(hdev->asic_prop.hw_queues_props);
Oded Gabbayac0ae6a2020-05-11 10:29:27 +0300687 hl_pci_fini(hdev);
688
689 return 0;
690}
691
692/**
693 * gaudi_fetch_psoc_frequency - Fetch PSOC frequency values
694 *
695 * @hdev: pointer to hl_device structure
696 *
697 */
Ofir Bitton1cbca892020-10-05 11:36:00 +0300698static int gaudi_fetch_psoc_frequency(struct hl_device *hdev)
Oded Gabbayac0ae6a2020-05-11 10:29:27 +0300699{
700 struct asic_fixed_properties *prop = &hdev->asic_prop;
Alon Mizrahi65854892020-11-19 16:34:19 +0200701 u32 nr = 0, nf = 0, od = 0, div_fctr = 0, pll_clk, div_sel;
702 u16 pll_freq_arr[HL_PLL_NUM_OUTPUTS], freq;
Ofir Bitton1cbca892020-10-05 11:36:00 +0300703 int rc;
704
Alon Mizrahi65854892020-11-19 16:34:19 +0200705 if (hdev->asic_prop.fw_security_disabled) {
706 /* Backward compatibility */
707 div_fctr = RREG32(mmPSOC_CPU_PLL_DIV_FACTOR_2);
708 div_sel = RREG32(mmPSOC_CPU_PLL_DIV_SEL_2);
709 nr = RREG32(mmPSOC_CPU_PLL_NR);
710 nf = RREG32(mmPSOC_CPU_PLL_NF);
711 od = RREG32(mmPSOC_CPU_PLL_OD);
Oded Gabbayac0ae6a2020-05-11 10:29:27 +0300712
Alon Mizrahi65854892020-11-19 16:34:19 +0200713 if (div_sel == DIV_SEL_REF_CLK ||
714 div_sel == DIV_SEL_DIVIDED_REF) {
715 if (div_sel == DIV_SEL_REF_CLK)
716 freq = PLL_REF_CLK;
717 else
718 freq = PLL_REF_CLK / (div_fctr + 1);
719 } else if (div_sel == DIV_SEL_PLL_CLK ||
720 div_sel == DIV_SEL_DIVIDED_PLL) {
721 pll_clk = PLL_REF_CLK * (nf + 1) /
722 ((nr + 1) * (od + 1));
723 if (div_sel == DIV_SEL_PLL_CLK)
724 freq = pll_clk;
725 else
726 freq = pll_clk / (div_fctr + 1);
727 } else {
728 dev_warn(hdev->dev,
729 "Received invalid div select value: %d",
730 div_sel);
731 freq = 0;
732 }
733 } else {
734 rc = hl_fw_cpucp_pll_info_get(hdev, CPU_PLL, pll_freq_arr);
735
736 if (rc)
737 return rc;
738
739 freq = pll_freq_arr[2];
740 }
741
742 prop->psoc_timestamp_frequency = freq;
743 prop->psoc_pci_pll_nr = nr;
744 prop->psoc_pci_pll_nf = nf;
745 prop->psoc_pci_pll_od = od;
746 prop->psoc_pci_pll_div_factor = div_fctr;
Ofir Bitton1cbca892020-10-05 11:36:00 +0300747
748 return 0;
Oded Gabbayac0ae6a2020-05-11 10:29:27 +0300749}
750
751static int _gaudi_init_tpc_mem(struct hl_device *hdev,
752 dma_addr_t tpc_kernel_src_addr, u32 tpc_kernel_size)
753{
754 struct asic_fixed_properties *prop = &hdev->asic_prop;
755 struct packet_lin_dma *init_tpc_mem_pkt;
756 struct hl_cs_job *job;
757 struct hl_cb *cb;
758 u64 dst_addr;
759 u32 cb_size, ctl;
760 u8 tpc_id;
761 int rc;
762
Ofir Bittona04b7cd2020-07-13 13:36:55 +0300763 cb = hl_cb_kernel_create(hdev, PAGE_SIZE, false);
Oded Gabbayac0ae6a2020-05-11 10:29:27 +0300764 if (!cb)
765 return -EFAULT;
766
Arnd Bergmann82948e62020-10-26 17:08:06 +0100767 init_tpc_mem_pkt = cb->kernel_address;
Oded Gabbayac0ae6a2020-05-11 10:29:27 +0300768 cb_size = sizeof(*init_tpc_mem_pkt);
769 memset(init_tpc_mem_pkt, 0, cb_size);
770
771 init_tpc_mem_pkt->tsize = cpu_to_le32(tpc_kernel_size);
772
Oded Gabbay65887292020-08-12 11:21:01 +0300773 ctl = FIELD_PREP(GAUDI_PKT_CTL_OPCODE_MASK, PACKET_LIN_DMA);
774 ctl |= FIELD_PREP(GAUDI_PKT_LIN_DMA_CTL_LIN_MASK, 1);
775 ctl |= FIELD_PREP(GAUDI_PKT_CTL_RB_MASK, 1);
776 ctl |= FIELD_PREP(GAUDI_PKT_CTL_MB_MASK, 1);
Oded Gabbayac0ae6a2020-05-11 10:29:27 +0300777
778 init_tpc_mem_pkt->ctl = cpu_to_le32(ctl);
779
780 init_tpc_mem_pkt->src_addr = cpu_to_le64(tpc_kernel_src_addr);
781 dst_addr = (prop->sram_user_base_address &
782 GAUDI_PKT_LIN_DMA_DST_ADDR_MASK) >>
783 GAUDI_PKT_LIN_DMA_DST_ADDR_SHIFT;
784 init_tpc_mem_pkt->dst_addr |= cpu_to_le64(dst_addr);
785
786 job = hl_cs_allocate_job(hdev, QUEUE_TYPE_EXT, true);
787 if (!job) {
788 dev_err(hdev->dev, "Failed to allocate a new job\n");
789 rc = -ENOMEM;
790 goto release_cb;
791 }
792
793 job->id = 0;
794 job->user_cb = cb;
Tomer Tayarf07486742020-08-02 22:51:31 +0300795 atomic_inc(&job->user_cb->cs_cnt);
Oded Gabbayac0ae6a2020-05-11 10:29:27 +0300796 job->user_cb_size = cb_size;
797 job->hw_queue_id = GAUDI_QUEUE_ID_DMA_0_0;
798 job->patched_cb = job->user_cb;
799 job->job_cb_size = job->user_cb_size + sizeof(struct packet_msg_prot);
800
801 hl_debugfs_add_job(hdev, job);
802
803 rc = gaudi_send_job_on_qman0(hdev, job);
804
805 if (rc)
806 goto free_job;
807
808 for (tpc_id = 0 ; tpc_id < TPC_NUMBER_OF_ENGINES ; tpc_id++) {
809 rc = gaudi_run_tpc_kernel(hdev, dst_addr, tpc_id);
810 if (rc)
811 break;
812 }
813
814free_job:
815 hl_userptr_delete_list(hdev, &job->userptr_list);
816 hl_debugfs_remove_job(hdev, job);
817 kfree(job);
Tomer Tayarf07486742020-08-02 22:51:31 +0300818 atomic_dec(&cb->cs_cnt);
Oded Gabbayac0ae6a2020-05-11 10:29:27 +0300819
820release_cb:
821 hl_cb_put(cb);
822 hl_cb_destroy(hdev, &hdev->kernel_cb_mgr, cb->id << PAGE_SHIFT);
823
824 return rc;
825}
826
827/*
828 * gaudi_init_tpc_mem() - Initialize TPC memories.
829 * @hdev: Pointer to hl_device structure.
830 *
831 * Copy TPC kernel fw from firmware file and run it to initialize TPC memories.
832 *
833 * Return: 0 for success, negative value for error.
834 */
835static int gaudi_init_tpc_mem(struct hl_device *hdev)
836{
837 const struct firmware *fw;
838 size_t fw_size;
839 void *cpu_addr;
840 dma_addr_t dma_handle;
841 int rc;
842
843 rc = request_firmware(&fw, GAUDI_TPC_FW_FILE, hdev->dev);
844 if (rc) {
845 dev_err(hdev->dev, "Firmware file %s is not found!\n",
846 GAUDI_TPC_FW_FILE);
847 goto out;
848 }
849
850 fw_size = fw->size;
851 cpu_addr = hdev->asic_funcs->asic_dma_alloc_coherent(hdev, fw_size,
852 &dma_handle, GFP_KERNEL | __GFP_ZERO);
853 if (!cpu_addr) {
854 dev_err(hdev->dev,
855 "Failed to allocate %zu of dma memory for TPC kernel\n",
856 fw_size);
857 rc = -ENOMEM;
858 goto out;
859 }
860
861 memcpy(cpu_addr, fw->data, fw_size);
862
863 rc = _gaudi_init_tpc_mem(hdev, dma_handle, fw_size);
864
865 hdev->asic_funcs->asic_dma_free_coherent(hdev, fw->size, cpu_addr,
866 dma_handle);
867
868out:
869 release_firmware(fw);
870 return rc;
871}
872
Ofir Bitton5de406c2020-09-10 10:56:26 +0300873static void gaudi_collective_map_sobs(struct hl_device *hdev, u32 stream)
Ofir Bitton5fe1c172020-09-10 10:10:55 +0300874{
Ofir Bitton5de406c2020-09-10 10:56:26 +0300875 struct gaudi_device *gaudi = hdev->asic_specific;
876 struct gaudi_collective_properties *prop = &gaudi->collective_props;
877 struct hl_hw_queue *q;
878 u32 i, sob_id, sob_group_id, queue_id;
Ofir Bitton5fe1c172020-09-10 10:10:55 +0300879
Ofir Bitton5de406c2020-09-10 10:56:26 +0300880 /* Iterate through SOB groups and assign a SOB for each slave queue */
881 sob_group_id =
882 stream * HL_RSVD_SOBS + prop->curr_sob_group_idx[stream];
883 sob_id = prop->hw_sob_group[sob_group_id].base_sob_id;
884
885 queue_id = GAUDI_QUEUE_ID_NIC_0_0 + stream;
886 for (i = 0 ; i < NIC_NUMBER_OF_ENGINES ; i++) {
887 q = &hdev->kernel_queues[queue_id + (4 * i)];
888 q->sync_stream_prop.collective_sob_id = sob_id + i;
889 }
890
891 /* Both DMA5 and TPC7 use the same resources since only a single
892 * engine need to participate in the reduction process
893 */
894 queue_id = GAUDI_QUEUE_ID_DMA_5_0 + stream;
895 q = &hdev->kernel_queues[queue_id];
896 q->sync_stream_prop.collective_sob_id =
897 sob_id + NIC_NUMBER_OF_ENGINES;
898
899 queue_id = GAUDI_QUEUE_ID_TPC_7_0 + stream;
900 q = &hdev->kernel_queues[queue_id];
901 q->sync_stream_prop.collective_sob_id =
902 sob_id + NIC_NUMBER_OF_ENGINES;
903}
904
905static void gaudi_sob_group_hw_reset(struct kref *ref)
906{
907 struct gaudi_hw_sob_group *hw_sob_group =
908 container_of(ref, struct gaudi_hw_sob_group, kref);
909 struct hl_device *hdev = hw_sob_group->hdev;
910 int i;
911
912 for (i = 0 ; i < NUMBER_OF_SOBS_IN_GRP ; i++)
913 WREG32(mmSYNC_MNGR_W_S_SYNC_MNGR_OBJS_SOB_OBJ_0 +
914 (hw_sob_group->base_sob_id + i) * 4, 0);
915
916 kref_init(&hw_sob_group->kref);
917}
918
919static void gaudi_sob_group_reset_error(struct kref *ref)
920{
921 struct gaudi_hw_sob_group *hw_sob_group =
922 container_of(ref, struct gaudi_hw_sob_group, kref);
923 struct hl_device *hdev = hw_sob_group->hdev;
924
925 dev_crit(hdev->dev,
926 "SOB release shouldn't be called here, base_sob_id: %d\n",
927 hw_sob_group->base_sob_id);
928}
929
930static int gaudi_collective_init(struct hl_device *hdev)
931{
932 u32 i, master_monitor_sobs, sob_id, reserved_sobs_per_group;
933 struct gaudi_collective_properties *prop;
934 struct gaudi_device *gaudi;
935
936 gaudi = hdev->asic_specific;
937 prop = &gaudi->collective_props;
938 sob_id = hdev->asic_prop.collective_first_sob;
939
940 /* First sob in group must be aligned to HL_MAX_SOBS_PER_MONITOR */
941 reserved_sobs_per_group =
942 ALIGN(NUMBER_OF_SOBS_IN_GRP, HL_MAX_SOBS_PER_MONITOR);
943
944 /* Init SOB groups */
945 for (i = 0 ; i < NUM_SOB_GROUPS; i++) {
946 prop->hw_sob_group[i].hdev = hdev;
947 prop->hw_sob_group[i].base_sob_id = sob_id;
948 sob_id += reserved_sobs_per_group;
949 gaudi_sob_group_hw_reset(&prop->hw_sob_group[i].kref);
950 }
951
952 for (i = 0 ; i < QMAN_STREAMS; i++) {
953 prop->next_sob_group_val[i] = 1;
954 prop->curr_sob_group_idx[i] = 0;
955 gaudi_collective_map_sobs(hdev, i);
956 }
957
958 prop->mstr_sob_mask[0] = 0;
959 master_monitor_sobs = HL_MAX_SOBS_PER_MONITOR;
960 for (i = 0 ; i < master_monitor_sobs ; i++)
961 if (gaudi->hw_cap_initialized & BIT(HW_CAP_NIC_SHIFT + i))
962 prop->mstr_sob_mask[0] |= BIT(i);
963
964 prop->mstr_sob_mask[1] = 0;
965 master_monitor_sobs =
966 NIC_NUMBER_OF_ENGINES - HL_MAX_SOBS_PER_MONITOR;
967 for (i = 0 ; i < master_monitor_sobs; i++) {
968 if (gaudi->hw_cap_initialized & BIT(HW_CAP_NIC_SHIFT + i))
969 prop->mstr_sob_mask[1] |= BIT(i);
970 }
971
972 /* Set collective engine bit */
973 prop->mstr_sob_mask[1] |= BIT(i);
974
975 return 0;
976}
977
978static void gaudi_reset_sob_group(struct hl_device *hdev, u16 sob_group)
979{
980 struct gaudi_device *gaudi = hdev->asic_specific;
981 struct gaudi_collective_properties *cprop = &gaudi->collective_props;
982
983 kref_put(&cprop->hw_sob_group[sob_group].kref,
984 gaudi_sob_group_hw_reset);
985}
986
987static void gaudi_collective_master_init_job(struct hl_device *hdev,
988 struct hl_cs_job *job, u32 stream, u32 sob_group_offset)
989{
990 u32 master_sob_base, master_monitor, queue_id, cb_size = 0;
991 struct gaudi_collective_properties *cprop;
992 struct hl_gen_wait_properties wait_prop;
993 struct hl_sync_stream_properties *prop;
994 struct gaudi_device *gaudi;
995
996 gaudi = hdev->asic_specific;
997 cprop = &gaudi->collective_props;
998 queue_id = job->hw_queue_id;
999 prop = &hdev->kernel_queues[queue_id].sync_stream_prop;
1000
1001 master_sob_base =
1002 cprop->hw_sob_group[sob_group_offset].base_sob_id;
1003 master_monitor = prop->collective_mstr_mon_id[0];
1004
1005 dev_dbg(hdev->dev,
1006 "Generate master wait CBs, sob %d (mask %#x), val:0x%x, mon %u, q %d\n",
1007 master_sob_base, cprop->mstr_sob_mask[0],
1008 cprop->next_sob_group_val[stream],
1009 master_monitor, queue_id);
1010
1011 wait_prop.data = (void *) job->patched_cb;
1012 wait_prop.sob_base = master_sob_base;
1013 wait_prop.sob_mask = cprop->mstr_sob_mask[0];
1014 wait_prop.sob_val = cprop->next_sob_group_val[stream];
1015 wait_prop.mon_id = master_monitor;
1016 wait_prop.q_idx = queue_id;
1017 wait_prop.size = cb_size;
1018 cb_size += gaudi_gen_wait_cb(hdev, &wait_prop);
1019
1020 master_sob_base += HL_MAX_SOBS_PER_MONITOR;
1021 master_monitor = prop->collective_mstr_mon_id[1];
1022
1023 dev_dbg(hdev->dev,
1024 "Generate master wait CBs, sob %d (mask %#x), val:0x%x, mon %u, q %d\n",
1025 master_sob_base, cprop->mstr_sob_mask[1],
1026 cprop->next_sob_group_val[stream],
1027 master_monitor, queue_id);
1028
1029 wait_prop.sob_base = master_sob_base;
1030 wait_prop.sob_mask = cprop->mstr_sob_mask[1];
1031 wait_prop.mon_id = master_monitor;
1032 wait_prop.size = cb_size;
1033 cb_size += gaudi_gen_wait_cb(hdev, &wait_prop);
1034}
1035
1036static void gaudi_collective_slave_init_job(struct hl_device *hdev,
1037 struct hl_cs_job *job, struct hl_cs_compl *cs_cmpl)
1038{
1039 struct hl_gen_wait_properties wait_prop;
1040 struct hl_sync_stream_properties *prop;
1041 u32 queue_id, cb_size = 0;
1042
1043 queue_id = job->hw_queue_id;
1044 prop = &hdev->kernel_queues[queue_id].sync_stream_prop;
1045
1046 /* Add to wait CBs using slave monitor */
1047 wait_prop.data = (void *) job->user_cb;
1048 wait_prop.sob_base = cs_cmpl->hw_sob->sob_id;
1049 wait_prop.sob_mask = 0x1;
1050 wait_prop.sob_val = cs_cmpl->sob_val;
1051 wait_prop.mon_id = prop->collective_slave_mon_id;
1052 wait_prop.q_idx = queue_id;
1053 wait_prop.size = cb_size;
1054
1055 dev_dbg(hdev->dev,
1056 "Generate slave wait CB, sob %d, val:0x%x, mon %d, q %d\n",
1057 cs_cmpl->hw_sob->sob_id, cs_cmpl->sob_val,
1058 prop->collective_slave_mon_id, queue_id);
1059
1060 cb_size += gaudi_gen_wait_cb(hdev, &wait_prop);
1061
1062 dev_dbg(hdev->dev,
1063 "generate signal CB, sob_id: %d, sob val: 1, q_idx: %d\n",
1064 prop->collective_sob_id, queue_id);
1065
1066 cb_size += gaudi_gen_signal_cb(hdev, job->user_cb,
Alon Mizrahi72ab9ca52020-12-02 19:55:30 +02001067 prop->collective_sob_id, cb_size, false);
Ofir Bitton5fe1c172020-09-10 10:10:55 +03001068}
1069
1070static void gaudi_collective_wait_init_cs(struct hl_cs *cs)
1071{
Ofir Bitton5de406c2020-09-10 10:56:26 +03001072 struct hl_cs_compl *signal_cs_cmpl =
1073 container_of(cs->signal_fence, struct hl_cs_compl, base_fence);
1074 struct hl_cs_compl *cs_cmpl =
1075 container_of(cs->fence, struct hl_cs_compl, base_fence);
1076 struct gaudi_collective_properties *cprop;
1077 u32 stream, queue_id, sob_group_offset;
1078 struct gaudi_device *gaudi;
1079 struct hl_device *hdev;
1080 struct hl_cs_job *job;
1081 struct hl_ctx *ctx;
Ofir Bitton5fe1c172020-09-10 10:10:55 +03001082
Ofir Bitton5de406c2020-09-10 10:56:26 +03001083 ctx = cs->ctx;
1084 hdev = ctx->hdev;
1085 gaudi = hdev->asic_specific;
1086 cprop = &gaudi->collective_props;
1087
1088 /* copy the SOB id and value of the signal CS */
1089 cs_cmpl->hw_sob = signal_cs_cmpl->hw_sob;
1090 cs_cmpl->sob_val = signal_cs_cmpl->sob_val;
1091
1092 /* Calculate the stream from collective master queue (1st job) */
1093 job = list_first_entry(&cs->job_list, struct hl_cs_job, cs_node);
1094 stream = job->hw_queue_id % 4;
1095 sob_group_offset =
1096 stream * HL_RSVD_SOBS + cprop->curr_sob_group_idx[stream];
1097
1098 list_for_each_entry(job, &cs->job_list, cs_node) {
1099 queue_id = job->hw_queue_id;
1100
1101 if (hdev->kernel_queues[queue_id].collective_mode ==
1102 HL_COLLECTIVE_MASTER)
1103 gaudi_collective_master_init_job(hdev, job, stream,
1104 sob_group_offset);
1105 else
1106 gaudi_collective_slave_init_job(hdev, job, cs_cmpl);
1107 }
1108
1109 cs_cmpl->sob_group = sob_group_offset;
1110
1111 /* Handle sob group kref and wraparound */
1112 kref_get(&cprop->hw_sob_group[sob_group_offset].kref);
1113 cprop->next_sob_group_val[stream]++;
1114
1115 if (cprop->next_sob_group_val[stream] == HL_MAX_SOB_VAL) {
1116 /*
1117 * Decrement as we reached the max value.
1118 * The release function won't be called here as we've
1119 * just incremented the refcount.
1120 */
1121 kref_put(&cprop->hw_sob_group[sob_group_offset].kref,
1122 gaudi_sob_group_reset_error);
1123 cprop->next_sob_group_val[stream] = 1;
1124 /* only two SOBs are currently in use */
1125 cprop->curr_sob_group_idx[stream] =
1126 (cprop->curr_sob_group_idx[stream] + 1) &
1127 (HL_RSVD_SOBS - 1);
1128
1129 gaudi_collective_map_sobs(hdev, stream);
1130
1131 dev_dbg(hdev->dev, "switched to SOB group %d, stream: %d\n",
1132 cprop->curr_sob_group_idx[stream], stream);
1133 }
1134
1135 /* Increment kref since all slave queues are now waiting on it */
1136 kref_get(&cs_cmpl->hw_sob->kref);
1137 /*
1138 * Must put the signal fence after the SOB refcnt increment so
1139 * the SOB refcnt won't turn 0 and reset the SOB before the
1140 * wait CS was submitted.
1141 */
1142 mb();
1143 hl_fence_put(cs->signal_fence);
1144 cs->signal_fence = NULL;
1145}
1146
1147static int gaudi_collective_wait_create_job(struct hl_device *hdev,
1148 struct hl_ctx *ctx, struct hl_cs *cs,
1149 enum hl_collective_mode mode, u32 queue_id, u32 wait_queue_id)
1150{
1151 struct hw_queue_properties *hw_queue_prop;
1152 struct hl_cs_counters_atomic *cntr;
1153 struct hl_cs_job *job;
1154 struct hl_cb *cb;
1155 u32 cb_size;
1156 bool patched_cb;
1157
1158 cntr = &hdev->aggregated_cs_counters;
1159
1160 if (mode == HL_COLLECTIVE_MASTER) {
1161 /* CB size of collective master queue contains
1162 * 4 msg short packets for monitor 1 configuration
1163 * 1 fence packet
1164 * 4 msg short packets for monitor 2 configuration
1165 * 1 fence packet
1166 * 2 msg prot packets for completion and MSI-X
1167 */
1168 cb_size = sizeof(struct packet_msg_short) * 8 +
1169 sizeof(struct packet_fence) * 2 +
1170 sizeof(struct packet_msg_prot) * 2;
1171 patched_cb = true;
1172 } else {
1173 /* CB size of collective slave queues contains
1174 * 4 msg short packets for monitor configuration
1175 * 1 fence packet
1176 * 1 additional msg short packet for sob signal
1177 */
1178 cb_size = sizeof(struct packet_msg_short) * 5 +
1179 sizeof(struct packet_fence);
1180 patched_cb = false;
1181 }
1182
1183 hw_queue_prop = &hdev->asic_prop.hw_queues_props[queue_id];
1184 job = hl_cs_allocate_job(hdev, hw_queue_prop->type, true);
1185 if (!job) {
farah kassabrie7536432020-10-12 14:30:26 +03001186 atomic64_inc(&ctx->cs_counters.out_of_mem_drop_cnt);
Ofir Bitton5de406c2020-09-10 10:56:26 +03001187 atomic64_inc(&cntr->out_of_mem_drop_cnt);
1188 dev_err(hdev->dev, "Failed to allocate a new job\n");
1189 return -ENOMEM;
1190 }
1191
1192 /* Allocate internal mapped CB for non patched CBs */
1193 cb = hl_cb_kernel_create(hdev, cb_size,
1194 hdev->mmu_enable && !patched_cb);
1195 if (!cb) {
farah kassabrie7536432020-10-12 14:30:26 +03001196 atomic64_inc(&ctx->cs_counters.out_of_mem_drop_cnt);
Ofir Bitton5de406c2020-09-10 10:56:26 +03001197 atomic64_inc(&cntr->out_of_mem_drop_cnt);
1198 kfree(job);
1199 return -EFAULT;
1200 }
1201
1202 job->id = 0;
1203 job->cs = cs;
1204 job->user_cb = cb;
Tomer Tayarf07486742020-08-02 22:51:31 +03001205 atomic_inc(&job->user_cb->cs_cnt);
Ofir Bitton5de406c2020-09-10 10:56:26 +03001206 job->user_cb_size = cb_size;
1207 job->hw_queue_id = queue_id;
1208
1209 /*
1210 * No need in parsing, user CB is the patched CB.
1211 * We call hl_cb_destroy() out of two reasons - we don't need
1212 * the CB in the CB idr anymore and to decrement its refcount as
1213 * it was incremented inside hl_cb_kernel_create().
1214 */
1215 if (patched_cb)
1216 job->patched_cb = job->user_cb;
1217 else
1218 job->patched_cb = NULL;
1219
1220 job->job_cb_size = job->user_cb_size;
1221 hl_cb_destroy(hdev, &hdev->kernel_cb_mgr, cb->id << PAGE_SHIFT);
1222
1223 /* increment refcount as for external queues we get completion */
1224 if (hw_queue_prop->type == QUEUE_TYPE_EXT)
1225 cs_get(cs);
1226
1227 cs->jobs_in_queue_cnt[job->hw_queue_id]++;
1228
1229 list_add_tail(&job->cs_node, &cs->job_list);
1230
1231 hl_debugfs_add_job(hdev, job);
1232
1233 return 0;
Ofir Bitton5fe1c172020-09-10 10:10:55 +03001234}
1235
1236static int gaudi_collective_wait_create_jobs(struct hl_device *hdev,
1237 struct hl_ctx *ctx, struct hl_cs *cs, u32 wait_queue_id,
1238 u32 collective_engine_id)
1239{
Ofir Bitton5de406c2020-09-10 10:56:26 +03001240 struct gaudi_device *gaudi = hdev->asic_specific;
1241 struct hw_queue_properties *hw_queue_prop;
1242 u32 queue_id, collective_queue, num_jobs;
1243 u32 stream, nic_queue, nic_idx = 0;
1244 bool skip;
1245 int i, rc;
1246
1247 /* Verify wait queue id is configured as master */
1248 hw_queue_prop = &hdev->asic_prop.hw_queues_props[wait_queue_id];
1249 if (!(hw_queue_prop->collective_mode == HL_COLLECTIVE_MASTER)) {
1250 dev_err(hdev->dev,
1251 "Queue %d is not configured as collective master\n",
1252 wait_queue_id);
1253 return -EINVAL;
1254 }
1255
1256 /* Verify engine id is supported */
1257 if (collective_engine_id != GAUDI_ENGINE_ID_DMA_5 &&
1258 collective_engine_id != GAUDI_ENGINE_ID_TPC_7) {
1259 dev_err(hdev->dev,
1260 "Collective wait does not support engine %u\n",
1261 collective_engine_id);
1262 return -EINVAL;
1263 }
1264
1265 stream = wait_queue_id % 4;
1266
1267 if (collective_engine_id == GAUDI_ENGINE_ID_DMA_5)
1268 collective_queue = GAUDI_QUEUE_ID_DMA_5_0 + stream;
Ofir Bitton5de406c2020-09-10 10:56:26 +03001269 else
Ofir Bitton71a984f2020-10-19 16:52:00 +03001270 collective_queue = GAUDI_QUEUE_ID_TPC_7_0 + stream;
Ofir Bitton5de406c2020-09-10 10:56:26 +03001271
1272 num_jobs = NUMBER_OF_SOBS_IN_GRP + 1;
1273 nic_queue = GAUDI_QUEUE_ID_NIC_0_0 + stream;
1274
1275 /* First job goes to the collective master queue, it will wait for
1276 * the collective slave queues to finish execution.
1277 * The synchronization is done using two monitors:
1278 * First monitor for NICs 0-7, second monitor for NICs 8-9 and the
1279 * reduction engine (DMA5/TPC7).
1280 *
1281 * Rest of the jobs goes to the collective slave queues which will
1282 * all wait for the user to signal sob 'cs_cmpl->sob_val'.
1283 */
1284 for (i = 0 ; i < num_jobs ; i++) {
1285 if (i == 0) {
1286 queue_id = wait_queue_id;
1287 rc = gaudi_collective_wait_create_job(hdev, ctx, cs,
1288 HL_COLLECTIVE_MASTER, queue_id, wait_queue_id);
1289 } else {
1290 if (nic_idx < NIC_NUMBER_OF_ENGINES) {
1291 if (gaudi->hw_cap_initialized &
1292 BIT(HW_CAP_NIC_SHIFT + nic_idx))
1293 skip = false;
1294 else
1295 skip = true;
1296
1297 queue_id = nic_queue;
1298 nic_queue += 4;
1299 nic_idx++;
1300
1301 if (skip)
1302 continue;
1303 } else {
1304 queue_id = collective_queue;
1305 }
1306
1307 rc = gaudi_collective_wait_create_job(hdev, ctx, cs,
1308 HL_COLLECTIVE_SLAVE, queue_id, wait_queue_id);
1309 }
1310
1311 if (rc)
1312 return rc;
1313 }
1314
1315 return rc;
Ofir Bitton5fe1c172020-09-10 10:10:55 +03001316}
1317
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03001318static int gaudi_late_init(struct hl_device *hdev)
1319{
1320 struct gaudi_device *gaudi = hdev->asic_specific;
1321 int rc;
1322
Oded Gabbay2f553422020-08-15 16:28:10 +03001323 rc = gaudi->cpucp_info_get(hdev);
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03001324 if (rc) {
Oded Gabbay2f553422020-08-15 16:28:10 +03001325 dev_err(hdev->dev, "Failed to get cpucp info\n");
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03001326 return rc;
1327 }
1328
Oded Gabbay3c681572020-11-02 21:10:39 +02001329 if ((hdev->card_type == cpucp_card_type_pci) &&
1330 (hdev->nic_ports_mask & 0x3)) {
1331 dev_info(hdev->dev,
1332 "PCI card detected, only 8 ports are enabled\n");
1333 hdev->nic_ports_mask &= ~0x3;
1334
1335 /* Stop and disable unused NIC QMANs */
1336 WREG32(mmNIC0_QM0_GLBL_CFG1, NIC0_QM0_GLBL_CFG1_PQF_STOP_MASK |
1337 NIC0_QM0_GLBL_CFG1_CQF_STOP_MASK |
1338 NIC0_QM0_GLBL_CFG1_CP_STOP_MASK);
1339
1340 WREG32(mmNIC0_QM1_GLBL_CFG1, NIC0_QM0_GLBL_CFG1_PQF_STOP_MASK |
1341 NIC0_QM0_GLBL_CFG1_CQF_STOP_MASK |
1342 NIC0_QM0_GLBL_CFG1_CP_STOP_MASK);
1343
1344 WREG32(mmNIC0_QM0_GLBL_CFG0, 0);
1345 WREG32(mmNIC0_QM1_GLBL_CFG0, 0);
1346
1347 gaudi->hw_cap_initialized &= ~(HW_CAP_NIC0 | HW_CAP_NIC1);
1348 }
1349
Oded Gabbay2f553422020-08-15 16:28:10 +03001350 rc = hl_fw_send_pci_access_msg(hdev, CPUCP_PACKET_ENABLE_PCI_ACCESS);
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03001351 if (rc) {
1352 dev_err(hdev->dev, "Failed to enable PCI access from CPU\n");
1353 return rc;
1354 }
1355
1356 WREG32(mmGIC_DISTRIBUTOR__5_GICD_SETSPI_NSR, GAUDI_EVENT_INTS_REGISTER);
1357
Ofir Bitton1cbca892020-10-05 11:36:00 +03001358 rc = gaudi_fetch_psoc_frequency(hdev);
1359 if (rc) {
1360 dev_err(hdev->dev, "Failed to fetch psoc frequency\n");
1361 goto disable_pci_access;
1362 }
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03001363
1364 rc = gaudi_mmu_clear_pgt_range(hdev);
1365 if (rc) {
1366 dev_err(hdev->dev, "Failed to clear MMU page tables range\n");
1367 goto disable_pci_access;
1368 }
1369
1370 rc = gaudi_init_tpc_mem(hdev);
1371 if (rc) {
1372 dev_err(hdev->dev, "Failed to initialize TPC memories\n");
1373 goto disable_pci_access;
1374 }
1375
Ofir Bitton5de406c2020-09-10 10:56:26 +03001376 rc = gaudi_collective_init(hdev);
1377 if (rc) {
1378 dev_err(hdev->dev, "Failed to init collective\n");
1379 goto disable_pci_access;
1380 }
1381
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03001382 return 0;
1383
1384disable_pci_access:
Oded Gabbay2f553422020-08-15 16:28:10 +03001385 hl_fw_send_pci_access_msg(hdev, CPUCP_PACKET_DISABLE_PCI_ACCESS);
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03001386
1387 return rc;
1388}
1389
1390static void gaudi_late_fini(struct hl_device *hdev)
1391{
1392 const struct hwmon_channel_info **channel_info_arr;
1393 int i = 0;
1394
1395 if (!hdev->hl_chip_info->info)
1396 return;
1397
1398 channel_info_arr = hdev->hl_chip_info->info;
1399
1400 while (channel_info_arr[i]) {
1401 kfree(channel_info_arr[i]->config);
1402 kfree(channel_info_arr[i]);
1403 i++;
1404 }
1405
1406 kfree(channel_info_arr);
1407
1408 hdev->hl_chip_info->info = NULL;
1409}
1410
1411static int gaudi_alloc_cpu_accessible_dma_mem(struct hl_device *hdev)
1412{
1413 dma_addr_t dma_addr_arr[GAUDI_ALLOC_CPU_MEM_RETRY_CNT] = {}, end_addr;
1414 void *virt_addr_arr[GAUDI_ALLOC_CPU_MEM_RETRY_CNT] = {};
1415 int i, j, rc = 0;
1416
1417 /*
1418 * The device CPU works with 40-bits addresses, while bit 39 must be set
1419 * to '1' when accessing the host.
1420 * Bits 49:39 of the full host address are saved for a later
1421 * configuration of the HW to perform extension to 50 bits.
1422 * Because there is a single HW register that holds the extension bits,
1423 * these bits must be identical in all allocated range.
1424 */
1425
1426 for (i = 0 ; i < GAUDI_ALLOC_CPU_MEM_RETRY_CNT ; i++) {
1427 virt_addr_arr[i] =
1428 hdev->asic_funcs->asic_dma_alloc_coherent(hdev,
1429 HL_CPU_ACCESSIBLE_MEM_SIZE,
1430 &dma_addr_arr[i],
1431 GFP_KERNEL | __GFP_ZERO);
1432 if (!virt_addr_arr[i]) {
1433 rc = -ENOMEM;
1434 goto free_dma_mem_arr;
1435 }
1436
1437 end_addr = dma_addr_arr[i] + HL_CPU_ACCESSIBLE_MEM_SIZE - 1;
1438 if (GAUDI_CPU_PCI_MSB_ADDR(dma_addr_arr[i]) ==
1439 GAUDI_CPU_PCI_MSB_ADDR(end_addr))
1440 break;
1441 }
1442
1443 if (i == GAUDI_ALLOC_CPU_MEM_RETRY_CNT) {
1444 dev_err(hdev->dev,
1445 "MSB of CPU accessible DMA memory are not identical in all range\n");
1446 rc = -EFAULT;
1447 goto free_dma_mem_arr;
1448 }
1449
1450 hdev->cpu_accessible_dma_mem = virt_addr_arr[i];
1451 hdev->cpu_accessible_dma_address = dma_addr_arr[i];
1452 hdev->cpu_pci_msb_addr =
1453 GAUDI_CPU_PCI_MSB_ADDR(hdev->cpu_accessible_dma_address);
1454
Ofir Bittonc692dec2020-10-04 17:34:37 +03001455 if (hdev->asic_prop.fw_security_disabled)
1456 GAUDI_PCI_TO_CPU_ADDR(hdev->cpu_accessible_dma_address);
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03001457
1458free_dma_mem_arr:
1459 for (j = 0 ; j < i ; j++)
1460 hdev->asic_funcs->asic_dma_free_coherent(hdev,
1461 HL_CPU_ACCESSIBLE_MEM_SIZE,
1462 virt_addr_arr[j],
1463 dma_addr_arr[j]);
1464
1465 return rc;
1466}
1467
1468static void gaudi_free_internal_qmans_pq_mem(struct hl_device *hdev)
1469{
1470 struct gaudi_device *gaudi = hdev->asic_specific;
1471 struct gaudi_internal_qman_info *q;
1472 u32 i;
1473
1474 for (i = 0 ; i < GAUDI_QUEUE_ID_SIZE ; i++) {
1475 q = &gaudi->internal_qmans[i];
1476 if (!q->pq_kernel_addr)
1477 continue;
1478 hdev->asic_funcs->asic_dma_free_coherent(hdev, q->pq_size,
1479 q->pq_kernel_addr,
1480 q->pq_dma_addr);
1481 }
1482}
1483
1484static int gaudi_alloc_internal_qmans_pq_mem(struct hl_device *hdev)
1485{
1486 struct gaudi_device *gaudi = hdev->asic_specific;
1487 struct gaudi_internal_qman_info *q;
1488 int rc, i;
1489
1490 for (i = 0 ; i < GAUDI_QUEUE_ID_SIZE ; i++) {
1491 if (gaudi_queue_type[i] != QUEUE_TYPE_INT)
1492 continue;
1493
1494 q = &gaudi->internal_qmans[i];
1495
1496 switch (i) {
Ofir Bitton0940cab2020-08-31 08:52:56 +03001497 case GAUDI_QUEUE_ID_DMA_2_0 ... GAUDI_QUEUE_ID_DMA_7_3:
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03001498 q->pq_size = HBM_DMA_QMAN_SIZE_IN_BYTES;
1499 break;
1500 case GAUDI_QUEUE_ID_MME_0_0 ... GAUDI_QUEUE_ID_MME_1_3:
1501 q->pq_size = MME_QMAN_SIZE_IN_BYTES;
1502 break;
1503 case GAUDI_QUEUE_ID_TPC_0_0 ... GAUDI_QUEUE_ID_TPC_7_3:
1504 q->pq_size = TPC_QMAN_SIZE_IN_BYTES;
1505 break;
Oded Gabbay3c681572020-11-02 21:10:39 +02001506 case GAUDI_QUEUE_ID_NIC_0_0 ... GAUDI_QUEUE_ID_NIC_9_3:
1507 q->pq_size = NIC_QMAN_SIZE_IN_BYTES;
1508 break;
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03001509 default:
1510 dev_err(hdev->dev, "Bad internal queue index %d", i);
1511 rc = -EINVAL;
1512 goto free_internal_qmans_pq_mem;
1513 }
1514
1515 q->pq_kernel_addr = hdev->asic_funcs->asic_dma_alloc_coherent(
1516 hdev, q->pq_size,
1517 &q->pq_dma_addr,
1518 GFP_KERNEL | __GFP_ZERO);
1519 if (!q->pq_kernel_addr) {
1520 rc = -ENOMEM;
1521 goto free_internal_qmans_pq_mem;
1522 }
1523 }
1524
1525 return 0;
1526
1527free_internal_qmans_pq_mem:
1528 gaudi_free_internal_qmans_pq_mem(hdev);
1529 return rc;
1530}
1531
1532static int gaudi_sw_init(struct hl_device *hdev)
1533{
1534 struct gaudi_device *gaudi;
Ofir Bittonebd8d122020-05-10 13:41:28 +03001535 u32 i, event_id = 0;
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03001536 int rc;
1537
1538 /* Allocate device structure */
1539 gaudi = kzalloc(sizeof(*gaudi), GFP_KERNEL);
1540 if (!gaudi)
1541 return -ENOMEM;
1542
Ofir Bittonebd8d122020-05-10 13:41:28 +03001543 for (i = 0 ; i < ARRAY_SIZE(gaudi_irq_map_table) ; i++) {
1544 if (gaudi_irq_map_table[i].valid) {
1545 if (event_id == GAUDI_EVENT_SIZE) {
1546 dev_err(hdev->dev,
1547 "Event array exceeds the limit of %u events\n",
1548 GAUDI_EVENT_SIZE);
1549 rc = -EINVAL;
1550 goto free_gaudi_device;
1551 }
1552
1553 gaudi->events[event_id++] =
1554 gaudi_irq_map_table[i].fc_id;
1555 }
1556 }
1557
Oded Gabbay2f553422020-08-15 16:28:10 +03001558 gaudi->cpucp_info_get = gaudi_cpucp_info_get;
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03001559
1560 gaudi->max_freq_value = GAUDI_MAX_CLK_FREQ;
1561
1562 hdev->asic_specific = gaudi;
1563
1564 /* Create DMA pool for small allocations */
1565 hdev->dma_pool = dma_pool_create(dev_name(hdev->dev),
1566 &hdev->pdev->dev, GAUDI_DMA_POOL_BLK_SIZE, 8, 0);
1567 if (!hdev->dma_pool) {
1568 dev_err(hdev->dev, "failed to create DMA pool\n");
1569 rc = -ENOMEM;
1570 goto free_gaudi_device;
1571 }
1572
1573 rc = gaudi_alloc_cpu_accessible_dma_mem(hdev);
1574 if (rc)
1575 goto free_dma_pool;
1576
1577 hdev->cpu_accessible_dma_pool = gen_pool_create(ilog2(32), -1);
1578 if (!hdev->cpu_accessible_dma_pool) {
1579 dev_err(hdev->dev,
1580 "Failed to create CPU accessible DMA pool\n");
1581 rc = -ENOMEM;
1582 goto free_cpu_dma_mem;
1583 }
1584
1585 rc = gen_pool_add(hdev->cpu_accessible_dma_pool,
1586 (uintptr_t) hdev->cpu_accessible_dma_mem,
1587 HL_CPU_ACCESSIBLE_MEM_SIZE, -1);
1588 if (rc) {
1589 dev_err(hdev->dev,
1590 "Failed to add memory to CPU accessible DMA pool\n");
1591 rc = -EFAULT;
1592 goto free_cpu_accessible_dma_pool;
1593 }
1594
1595 rc = gaudi_alloc_internal_qmans_pq_mem(hdev);
1596 if (rc)
1597 goto free_cpu_accessible_dma_pool;
1598
1599 spin_lock_init(&gaudi->hw_queues_lock);
1600 mutex_init(&gaudi->clk_gate_mutex);
1601
1602 hdev->supports_sync_stream = true;
1603 hdev->supports_coresight = true;
1604
1605 return 0;
1606
1607free_cpu_accessible_dma_pool:
1608 gen_pool_destroy(hdev->cpu_accessible_dma_pool);
1609free_cpu_dma_mem:
Ofir Bittonc692dec2020-10-04 17:34:37 +03001610 if (hdev->asic_prop.fw_security_disabled)
1611 GAUDI_CPU_TO_PCI_ADDR(hdev->cpu_accessible_dma_address,
1612 hdev->cpu_pci_msb_addr);
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03001613 hdev->asic_funcs->asic_dma_free_coherent(hdev,
1614 HL_CPU_ACCESSIBLE_MEM_SIZE,
1615 hdev->cpu_accessible_dma_mem,
1616 hdev->cpu_accessible_dma_address);
1617free_dma_pool:
1618 dma_pool_destroy(hdev->dma_pool);
1619free_gaudi_device:
1620 kfree(gaudi);
1621 return rc;
1622}
1623
1624static int gaudi_sw_fini(struct hl_device *hdev)
1625{
1626 struct gaudi_device *gaudi = hdev->asic_specific;
1627
1628 gaudi_free_internal_qmans_pq_mem(hdev);
1629
1630 gen_pool_destroy(hdev->cpu_accessible_dma_pool);
1631
Ofir Bittonc692dec2020-10-04 17:34:37 +03001632 if (hdev->asic_prop.fw_security_disabled)
1633 GAUDI_CPU_TO_PCI_ADDR(hdev->cpu_accessible_dma_address,
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03001634 hdev->cpu_pci_msb_addr);
Ofir Bittonc692dec2020-10-04 17:34:37 +03001635
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03001636 hdev->asic_funcs->asic_dma_free_coherent(hdev,
1637 HL_CPU_ACCESSIBLE_MEM_SIZE,
1638 hdev->cpu_accessible_dma_mem,
1639 hdev->cpu_accessible_dma_address);
1640
1641 dma_pool_destroy(hdev->dma_pool);
1642
1643 mutex_destroy(&gaudi->clk_gate_mutex);
1644
1645 kfree(gaudi);
1646
1647 return 0;
1648}
1649
1650static irqreturn_t gaudi_irq_handler_single(int irq, void *arg)
1651{
1652 struct hl_device *hdev = arg;
1653 int i;
1654
1655 if (hdev->disabled)
1656 return IRQ_HANDLED;
1657
1658 for (i = 0 ; i < hdev->asic_prop.completion_queues_count ; i++)
1659 hl_irq_handler_cq(irq, &hdev->completion_queue[i]);
1660
1661 hl_irq_handler_eq(irq, &hdev->event_queue);
1662
1663 return IRQ_HANDLED;
1664}
1665
1666/*
1667 * For backward compatibility, new MSI interrupts should be set after the
1668 * existing CPU and NIC interrupts.
1669 */
1670static int gaudi_pci_irq_vector(struct hl_device *hdev, unsigned int nr,
1671 bool cpu_eq)
1672{
1673 int msi_vec;
1674
1675 if ((nr != GAUDI_EVENT_QUEUE_MSI_IDX) && (cpu_eq))
1676 dev_crit(hdev->dev, "CPU EQ must use IRQ %d\n",
1677 GAUDI_EVENT_QUEUE_MSI_IDX);
1678
1679 msi_vec = ((nr < GAUDI_EVENT_QUEUE_MSI_IDX) || (cpu_eq)) ? nr :
1680 (nr + NIC_NUMBER_OF_ENGINES + 1);
1681
1682 return pci_irq_vector(hdev->pdev, msi_vec);
1683}
1684
1685static int gaudi_enable_msi_single(struct hl_device *hdev)
1686{
1687 int rc, irq;
1688
Oded Gabbay3b82c342020-11-27 18:10:20 +02001689 dev_dbg(hdev->dev, "Working in single MSI IRQ mode\n");
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03001690
1691 irq = gaudi_pci_irq_vector(hdev, 0, false);
1692 rc = request_irq(irq, gaudi_irq_handler_single, 0,
1693 "gaudi single msi", hdev);
1694 if (rc)
1695 dev_err(hdev->dev,
1696 "Failed to request single MSI IRQ\n");
1697
1698 return rc;
1699}
1700
1701static int gaudi_enable_msi_multi(struct hl_device *hdev)
1702{
1703 int cq_cnt = hdev->asic_prop.completion_queues_count;
1704 int rc, i, irq_cnt_init, irq;
1705
1706 for (i = 0, irq_cnt_init = 0 ; i < cq_cnt ; i++, irq_cnt_init++) {
1707 irq = gaudi_pci_irq_vector(hdev, i, false);
1708 rc = request_irq(irq, hl_irq_handler_cq, 0, gaudi_irq_name[i],
1709 &hdev->completion_queue[i]);
1710 if (rc) {
1711 dev_err(hdev->dev, "Failed to request IRQ %d", irq);
1712 goto free_irqs;
1713 }
1714 }
1715
1716 irq = gaudi_pci_irq_vector(hdev, GAUDI_EVENT_QUEUE_MSI_IDX, true);
1717 rc = request_irq(irq, hl_irq_handler_eq, 0, gaudi_irq_name[cq_cnt],
1718 &hdev->event_queue);
1719 if (rc) {
1720 dev_err(hdev->dev, "Failed to request IRQ %d", irq);
1721 goto free_irqs;
1722 }
1723
1724 return 0;
1725
1726free_irqs:
1727 for (i = 0 ; i < irq_cnt_init ; i++)
1728 free_irq(gaudi_pci_irq_vector(hdev, i, false),
1729 &hdev->completion_queue[i]);
1730 return rc;
1731}
1732
1733static int gaudi_enable_msi(struct hl_device *hdev)
1734{
1735 struct gaudi_device *gaudi = hdev->asic_specific;
1736 int rc;
1737
1738 if (gaudi->hw_cap_initialized & HW_CAP_MSI)
1739 return 0;
1740
1741 rc = pci_alloc_irq_vectors(hdev->pdev, 1, GAUDI_MSI_ENTRIES,
1742 PCI_IRQ_MSI);
1743 if (rc < 0) {
1744 dev_err(hdev->dev, "MSI: Failed to enable support %d\n", rc);
1745 return rc;
1746 }
1747
1748 if (rc < NUMBER_OF_INTERRUPTS) {
1749 gaudi->multi_msi_mode = false;
1750 rc = gaudi_enable_msi_single(hdev);
1751 } else {
1752 gaudi->multi_msi_mode = true;
1753 rc = gaudi_enable_msi_multi(hdev);
1754 }
1755
1756 if (rc)
1757 goto free_pci_irq_vectors;
1758
1759 gaudi->hw_cap_initialized |= HW_CAP_MSI;
1760
1761 return 0;
1762
1763free_pci_irq_vectors:
1764 pci_free_irq_vectors(hdev->pdev);
1765 return rc;
1766}
1767
1768static void gaudi_sync_irqs(struct hl_device *hdev)
1769{
1770 struct gaudi_device *gaudi = hdev->asic_specific;
1771 int i, cq_cnt = hdev->asic_prop.completion_queues_count;
1772
1773 if (!(gaudi->hw_cap_initialized & HW_CAP_MSI))
1774 return;
1775
1776 /* Wait for all pending IRQs to be finished */
1777 if (gaudi->multi_msi_mode) {
1778 for (i = 0 ; i < cq_cnt ; i++)
1779 synchronize_irq(gaudi_pci_irq_vector(hdev, i, false));
1780
1781 synchronize_irq(gaudi_pci_irq_vector(hdev,
1782 GAUDI_EVENT_QUEUE_MSI_IDX,
1783 true));
1784 } else {
1785 synchronize_irq(gaudi_pci_irq_vector(hdev, 0, false));
1786 }
1787}
1788
1789static void gaudi_disable_msi(struct hl_device *hdev)
1790{
1791 struct gaudi_device *gaudi = hdev->asic_specific;
1792 int i, irq, cq_cnt = hdev->asic_prop.completion_queues_count;
1793
1794 if (!(gaudi->hw_cap_initialized & HW_CAP_MSI))
1795 return;
1796
1797 gaudi_sync_irqs(hdev);
1798
1799 if (gaudi->multi_msi_mode) {
1800 irq = gaudi_pci_irq_vector(hdev, GAUDI_EVENT_QUEUE_MSI_IDX,
1801 true);
1802 free_irq(irq, &hdev->event_queue);
1803
1804 for (i = 0 ; i < cq_cnt ; i++) {
1805 irq = gaudi_pci_irq_vector(hdev, i, false);
1806 free_irq(irq, &hdev->completion_queue[i]);
1807 }
1808 } else {
1809 free_irq(gaudi_pci_irq_vector(hdev, 0, false), hdev);
1810 }
1811
1812 pci_free_irq_vectors(hdev->pdev);
1813
1814 gaudi->hw_cap_initialized &= ~HW_CAP_MSI;
1815}
1816
1817static void gaudi_init_scrambler_sram(struct hl_device *hdev)
1818{
1819 struct gaudi_device *gaudi = hdev->asic_specific;
1820
Ofir Bittonc692dec2020-10-04 17:34:37 +03001821 if (!hdev->asic_prop.fw_security_disabled)
1822 return;
1823
1824 if (hdev->asic_prop.fw_security_status_valid &&
1825 (hdev->asic_prop.fw_app_security_map &
1826 CPU_BOOT_DEV_STS0_SRAM_SCR_EN))
1827 return;
1828
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03001829 if (gaudi->hw_cap_initialized & HW_CAP_SRAM_SCRAMBLER)
1830 return;
1831
1832 if (!hdev->sram_scrambler_enable)
1833 return;
1834
1835 WREG32(mmNIF_RTR_CTRL_0_SCRAM_SRAM_EN,
1836 1 << IF_RTR_CTRL_SCRAM_SRAM_EN_VAL_SHIFT);
1837 WREG32(mmNIF_RTR_CTRL_1_SCRAM_SRAM_EN,
1838 1 << IF_RTR_CTRL_SCRAM_SRAM_EN_VAL_SHIFT);
1839 WREG32(mmNIF_RTR_CTRL_2_SCRAM_SRAM_EN,
1840 1 << IF_RTR_CTRL_SCRAM_SRAM_EN_VAL_SHIFT);
1841 WREG32(mmNIF_RTR_CTRL_3_SCRAM_SRAM_EN,
1842 1 << IF_RTR_CTRL_SCRAM_SRAM_EN_VAL_SHIFT);
1843 WREG32(mmNIF_RTR_CTRL_4_SCRAM_SRAM_EN,
1844 1 << IF_RTR_CTRL_SCRAM_SRAM_EN_VAL_SHIFT);
1845 WREG32(mmNIF_RTR_CTRL_5_SCRAM_SRAM_EN,
1846 1 << IF_RTR_CTRL_SCRAM_SRAM_EN_VAL_SHIFT);
1847 WREG32(mmNIF_RTR_CTRL_6_SCRAM_SRAM_EN,
1848 1 << IF_RTR_CTRL_SCRAM_SRAM_EN_VAL_SHIFT);
1849 WREG32(mmNIF_RTR_CTRL_7_SCRAM_SRAM_EN,
1850 1 << IF_RTR_CTRL_SCRAM_SRAM_EN_VAL_SHIFT);
1851
1852 WREG32(mmSIF_RTR_CTRL_0_SCRAM_SRAM_EN,
1853 1 << IF_RTR_CTRL_SCRAM_SRAM_EN_VAL_SHIFT);
1854 WREG32(mmSIF_RTR_CTRL_1_SCRAM_SRAM_EN,
1855 1 << IF_RTR_CTRL_SCRAM_SRAM_EN_VAL_SHIFT);
1856 WREG32(mmSIF_RTR_CTRL_2_SCRAM_SRAM_EN,
1857 1 << IF_RTR_CTRL_SCRAM_SRAM_EN_VAL_SHIFT);
1858 WREG32(mmSIF_RTR_CTRL_3_SCRAM_SRAM_EN,
1859 1 << IF_RTR_CTRL_SCRAM_SRAM_EN_VAL_SHIFT);
1860 WREG32(mmSIF_RTR_CTRL_4_SCRAM_SRAM_EN,
1861 1 << IF_RTR_CTRL_SCRAM_SRAM_EN_VAL_SHIFT);
1862 WREG32(mmSIF_RTR_CTRL_5_SCRAM_SRAM_EN,
1863 1 << IF_RTR_CTRL_SCRAM_SRAM_EN_VAL_SHIFT);
1864 WREG32(mmSIF_RTR_CTRL_6_SCRAM_SRAM_EN,
1865 1 << IF_RTR_CTRL_SCRAM_SRAM_EN_VAL_SHIFT);
1866 WREG32(mmSIF_RTR_CTRL_7_SCRAM_SRAM_EN,
1867 1 << IF_RTR_CTRL_SCRAM_SRAM_EN_VAL_SHIFT);
1868
1869 WREG32(mmDMA_IF_E_N_DOWN_CH0_SCRAM_SRAM_EN,
1870 1 << DMA_IF_DOWN_CHX_SCRAM_SRAM_EN_VAL_SHIFT);
1871 WREG32(mmDMA_IF_E_N_DOWN_CH1_SCRAM_SRAM_EN,
1872 1 << DMA_IF_DOWN_CHX_SCRAM_SRAM_EN_VAL_SHIFT);
1873 WREG32(mmDMA_IF_E_S_DOWN_CH0_SCRAM_SRAM_EN,
1874 1 << DMA_IF_DOWN_CHX_SCRAM_SRAM_EN_VAL_SHIFT);
1875 WREG32(mmDMA_IF_E_S_DOWN_CH1_SCRAM_SRAM_EN,
1876 1 << DMA_IF_DOWN_CHX_SCRAM_SRAM_EN_VAL_SHIFT);
1877 WREG32(mmDMA_IF_W_N_DOWN_CH0_SCRAM_SRAM_EN,
1878 1 << DMA_IF_DOWN_CHX_SCRAM_SRAM_EN_VAL_SHIFT);
1879 WREG32(mmDMA_IF_W_N_DOWN_CH1_SCRAM_SRAM_EN,
1880 1 << DMA_IF_DOWN_CHX_SCRAM_SRAM_EN_VAL_SHIFT);
1881 WREG32(mmDMA_IF_W_S_DOWN_CH0_SCRAM_SRAM_EN,
1882 1 << DMA_IF_DOWN_CHX_SCRAM_SRAM_EN_VAL_SHIFT);
1883 WREG32(mmDMA_IF_W_S_DOWN_CH1_SCRAM_SRAM_EN,
1884 1 << DMA_IF_DOWN_CHX_SCRAM_SRAM_EN_VAL_SHIFT);
1885
1886 gaudi->hw_cap_initialized |= HW_CAP_SRAM_SCRAMBLER;
1887}
1888
1889static void gaudi_init_scrambler_hbm(struct hl_device *hdev)
1890{
1891 struct gaudi_device *gaudi = hdev->asic_specific;
1892
Ofir Bittonc692dec2020-10-04 17:34:37 +03001893 if (!hdev->asic_prop.fw_security_disabled)
1894 return;
1895
1896 if (hdev->asic_prop.fw_security_status_valid &&
1897 (hdev->asic_prop.fw_boot_cpu_security_map &
1898 CPU_BOOT_DEV_STS0_DRAM_SCR_EN))
1899 return;
1900
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03001901 if (gaudi->hw_cap_initialized & HW_CAP_HBM_SCRAMBLER)
1902 return;
1903
1904 if (!hdev->dram_scrambler_enable)
1905 return;
1906
1907 WREG32(mmNIF_RTR_CTRL_0_SCRAM_HBM_EN,
1908 1 << IF_RTR_CTRL_SCRAM_HBM_EN_VAL_SHIFT);
1909 WREG32(mmNIF_RTR_CTRL_1_SCRAM_HBM_EN,
1910 1 << IF_RTR_CTRL_SCRAM_HBM_EN_VAL_SHIFT);
1911 WREG32(mmNIF_RTR_CTRL_2_SCRAM_HBM_EN,
1912 1 << IF_RTR_CTRL_SCRAM_HBM_EN_VAL_SHIFT);
1913 WREG32(mmNIF_RTR_CTRL_3_SCRAM_HBM_EN,
1914 1 << IF_RTR_CTRL_SCRAM_HBM_EN_VAL_SHIFT);
1915 WREG32(mmNIF_RTR_CTRL_4_SCRAM_HBM_EN,
1916 1 << IF_RTR_CTRL_SCRAM_HBM_EN_VAL_SHIFT);
1917 WREG32(mmNIF_RTR_CTRL_5_SCRAM_HBM_EN,
1918 1 << IF_RTR_CTRL_SCRAM_HBM_EN_VAL_SHIFT);
1919 WREG32(mmNIF_RTR_CTRL_6_SCRAM_HBM_EN,
1920 1 << IF_RTR_CTRL_SCRAM_HBM_EN_VAL_SHIFT);
1921 WREG32(mmNIF_RTR_CTRL_7_SCRAM_HBM_EN,
1922 1 << IF_RTR_CTRL_SCRAM_HBM_EN_VAL_SHIFT);
1923
1924 WREG32(mmSIF_RTR_CTRL_0_SCRAM_HBM_EN,
1925 1 << IF_RTR_CTRL_SCRAM_HBM_EN_VAL_SHIFT);
1926 WREG32(mmSIF_RTR_CTRL_1_SCRAM_HBM_EN,
1927 1 << IF_RTR_CTRL_SCRAM_HBM_EN_VAL_SHIFT);
1928 WREG32(mmSIF_RTR_CTRL_2_SCRAM_HBM_EN,
1929 1 << IF_RTR_CTRL_SCRAM_HBM_EN_VAL_SHIFT);
1930 WREG32(mmSIF_RTR_CTRL_3_SCRAM_HBM_EN,
1931 1 << IF_RTR_CTRL_SCRAM_HBM_EN_VAL_SHIFT);
1932 WREG32(mmSIF_RTR_CTRL_4_SCRAM_HBM_EN,
1933 1 << IF_RTR_CTRL_SCRAM_HBM_EN_VAL_SHIFT);
1934 WREG32(mmSIF_RTR_CTRL_5_SCRAM_HBM_EN,
1935 1 << IF_RTR_CTRL_SCRAM_HBM_EN_VAL_SHIFT);
1936 WREG32(mmSIF_RTR_CTRL_6_SCRAM_HBM_EN,
1937 1 << IF_RTR_CTRL_SCRAM_HBM_EN_VAL_SHIFT);
1938 WREG32(mmSIF_RTR_CTRL_7_SCRAM_HBM_EN,
1939 1 << IF_RTR_CTRL_SCRAM_HBM_EN_VAL_SHIFT);
1940
1941 WREG32(mmDMA_IF_E_N_DOWN_CH0_SCRAM_HBM_EN,
1942 1 << DMA_IF_DOWN_CHX_SCRAM_HBM_EN_VAL_SHIFT);
1943 WREG32(mmDMA_IF_E_N_DOWN_CH1_SCRAM_HBM_EN,
1944 1 << DMA_IF_DOWN_CHX_SCRAM_HBM_EN_VAL_SHIFT);
1945 WREG32(mmDMA_IF_E_S_DOWN_CH0_SCRAM_HBM_EN,
1946 1 << DMA_IF_DOWN_CHX_SCRAM_HBM_EN_VAL_SHIFT);
1947 WREG32(mmDMA_IF_E_S_DOWN_CH1_SCRAM_HBM_EN,
1948 1 << DMA_IF_DOWN_CHX_SCRAM_HBM_EN_VAL_SHIFT);
1949 WREG32(mmDMA_IF_W_N_DOWN_CH0_SCRAM_HBM_EN,
1950 1 << DMA_IF_DOWN_CHX_SCRAM_HBM_EN_VAL_SHIFT);
1951 WREG32(mmDMA_IF_W_N_DOWN_CH1_SCRAM_HBM_EN,
1952 1 << DMA_IF_DOWN_CHX_SCRAM_HBM_EN_VAL_SHIFT);
1953 WREG32(mmDMA_IF_W_S_DOWN_CH0_SCRAM_HBM_EN,
1954 1 << DMA_IF_DOWN_CHX_SCRAM_HBM_EN_VAL_SHIFT);
1955 WREG32(mmDMA_IF_W_S_DOWN_CH1_SCRAM_HBM_EN,
1956 1 << DMA_IF_DOWN_CHX_SCRAM_HBM_EN_VAL_SHIFT);
1957
1958 gaudi->hw_cap_initialized |= HW_CAP_HBM_SCRAMBLER;
1959}
1960
1961static void gaudi_init_e2e(struct hl_device *hdev)
1962{
Ofir Bittonc692dec2020-10-04 17:34:37 +03001963 if (!hdev->asic_prop.fw_security_disabled)
1964 return;
1965
1966 if (hdev->asic_prop.fw_security_status_valid &&
1967 (hdev->asic_prop.fw_boot_cpu_security_map &
1968 CPU_BOOT_DEV_STS0_E2E_CRED_EN))
1969 return;
1970
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03001971 WREG32(mmSIF_RTR_CTRL_0_E2E_HBM_WR_SIZE, 247 >> 3);
1972 WREG32(mmSIF_RTR_CTRL_0_E2E_HBM_RD_SIZE, 785 >> 3);
1973 WREG32(mmSIF_RTR_CTRL_0_E2E_PCI_WR_SIZE, 49);
1974 WREG32(mmSIF_RTR_CTRL_0_E2E_PCI_RD_SIZE, 101);
1975
1976 WREG32(mmSIF_RTR_CTRL_1_E2E_HBM_WR_SIZE, 275 >> 3);
1977 WREG32(mmSIF_RTR_CTRL_1_E2E_HBM_RD_SIZE, 614 >> 3);
1978 WREG32(mmSIF_RTR_CTRL_1_E2E_PCI_WR_SIZE, 1);
1979 WREG32(mmSIF_RTR_CTRL_1_E2E_PCI_RD_SIZE, 39);
1980
1981 WREG32(mmSIF_RTR_CTRL_2_E2E_HBM_WR_SIZE, 1);
1982 WREG32(mmSIF_RTR_CTRL_2_E2E_HBM_RD_SIZE, 1);
1983 WREG32(mmSIF_RTR_CTRL_2_E2E_PCI_WR_SIZE, 1);
1984 WREG32(mmSIF_RTR_CTRL_2_E2E_PCI_RD_SIZE, 32);
1985
1986 WREG32(mmSIF_RTR_CTRL_3_E2E_HBM_WR_SIZE, 176 >> 3);
1987 WREG32(mmSIF_RTR_CTRL_3_E2E_HBM_RD_SIZE, 32 >> 3);
1988 WREG32(mmSIF_RTR_CTRL_3_E2E_PCI_WR_SIZE, 19);
1989 WREG32(mmSIF_RTR_CTRL_3_E2E_PCI_RD_SIZE, 32);
1990
1991 WREG32(mmSIF_RTR_CTRL_4_E2E_HBM_WR_SIZE, 176 >> 3);
1992 WREG32(mmSIF_RTR_CTRL_4_E2E_HBM_RD_SIZE, 32 >> 3);
1993 WREG32(mmSIF_RTR_CTRL_4_E2E_PCI_WR_SIZE, 19);
1994 WREG32(mmSIF_RTR_CTRL_4_E2E_PCI_RD_SIZE, 32);
1995
1996 WREG32(mmSIF_RTR_CTRL_5_E2E_HBM_WR_SIZE, 1);
1997 WREG32(mmSIF_RTR_CTRL_5_E2E_HBM_RD_SIZE, 1);
1998 WREG32(mmSIF_RTR_CTRL_5_E2E_PCI_WR_SIZE, 1);
1999 WREG32(mmSIF_RTR_CTRL_5_E2E_PCI_RD_SIZE, 32);
2000
2001 WREG32(mmSIF_RTR_CTRL_6_E2E_HBM_WR_SIZE, 275 >> 3);
2002 WREG32(mmSIF_RTR_CTRL_6_E2E_HBM_RD_SIZE, 614 >> 3);
2003 WREG32(mmSIF_RTR_CTRL_6_E2E_PCI_WR_SIZE, 1);
2004 WREG32(mmSIF_RTR_CTRL_6_E2E_PCI_RD_SIZE, 39);
2005
2006 WREG32(mmSIF_RTR_CTRL_7_E2E_HBM_WR_SIZE, 297 >> 3);
2007 WREG32(mmSIF_RTR_CTRL_7_E2E_HBM_RD_SIZE, 908 >> 3);
2008 WREG32(mmSIF_RTR_CTRL_7_E2E_PCI_WR_SIZE, 19);
2009 WREG32(mmSIF_RTR_CTRL_7_E2E_PCI_RD_SIZE, 19);
2010
2011 WREG32(mmNIF_RTR_CTRL_0_E2E_HBM_WR_SIZE, 318 >> 3);
2012 WREG32(mmNIF_RTR_CTRL_0_E2E_HBM_RD_SIZE, 956 >> 3);
2013 WREG32(mmNIF_RTR_CTRL_0_E2E_PCI_WR_SIZE, 79);
2014 WREG32(mmNIF_RTR_CTRL_0_E2E_PCI_RD_SIZE, 163);
2015
2016 WREG32(mmNIF_RTR_CTRL_1_E2E_HBM_WR_SIZE, 275 >> 3);
2017 WREG32(mmNIF_RTR_CTRL_1_E2E_HBM_RD_SIZE, 614 >> 3);
2018 WREG32(mmNIF_RTR_CTRL_1_E2E_PCI_WR_SIZE, 1);
2019 WREG32(mmNIF_RTR_CTRL_1_E2E_PCI_RD_SIZE, 39);
2020
2021 WREG32(mmNIF_RTR_CTRL_2_E2E_HBM_WR_SIZE, 1);
2022 WREG32(mmNIF_RTR_CTRL_2_E2E_HBM_RD_SIZE, 1);
2023 WREG32(mmNIF_RTR_CTRL_2_E2E_PCI_WR_SIZE, 1);
2024 WREG32(mmNIF_RTR_CTRL_2_E2E_PCI_RD_SIZE, 32);
2025
2026 WREG32(mmNIF_RTR_CTRL_3_E2E_HBM_WR_SIZE, 176 >> 3);
2027 WREG32(mmNIF_RTR_CTRL_3_E2E_HBM_RD_SIZE, 32 >> 3);
2028 WREG32(mmNIF_RTR_CTRL_3_E2E_PCI_WR_SIZE, 19);
2029 WREG32(mmNIF_RTR_CTRL_3_E2E_PCI_RD_SIZE, 32);
2030
2031 WREG32(mmNIF_RTR_CTRL_4_E2E_HBM_WR_SIZE, 176 >> 3);
2032 WREG32(mmNIF_RTR_CTRL_4_E2E_HBM_RD_SIZE, 32 >> 3);
2033 WREG32(mmNIF_RTR_CTRL_4_E2E_PCI_WR_SIZE, 19);
2034 WREG32(mmNIF_RTR_CTRL_4_E2E_PCI_RD_SIZE, 32);
2035
2036 WREG32(mmNIF_RTR_CTRL_5_E2E_HBM_WR_SIZE, 1);
2037 WREG32(mmNIF_RTR_CTRL_5_E2E_HBM_RD_SIZE, 1);
2038 WREG32(mmNIF_RTR_CTRL_5_E2E_PCI_WR_SIZE, 1);
2039 WREG32(mmNIF_RTR_CTRL_5_E2E_PCI_RD_SIZE, 32);
2040
2041 WREG32(mmNIF_RTR_CTRL_6_E2E_HBM_WR_SIZE, 275 >> 3);
2042 WREG32(mmNIF_RTR_CTRL_6_E2E_HBM_RD_SIZE, 614 >> 3);
2043 WREG32(mmNIF_RTR_CTRL_6_E2E_PCI_WR_SIZE, 1);
2044 WREG32(mmNIF_RTR_CTRL_6_E2E_PCI_RD_SIZE, 39);
2045
2046 WREG32(mmNIF_RTR_CTRL_7_E2E_HBM_WR_SIZE, 318 >> 3);
2047 WREG32(mmNIF_RTR_CTRL_7_E2E_HBM_RD_SIZE, 956 >> 3);
2048 WREG32(mmNIF_RTR_CTRL_7_E2E_PCI_WR_SIZE, 79);
2049 WREG32(mmNIF_RTR_CTRL_7_E2E_PCI_RD_SIZE, 79);
2050
2051 WREG32(mmDMA_IF_E_N_DOWN_CH0_E2E_HBM_WR_SIZE, 344 >> 3);
2052 WREG32(mmDMA_IF_E_N_DOWN_CH0_E2E_HBM_RD_SIZE, 1000 >> 3);
2053 WREG32(mmDMA_IF_E_N_DOWN_CH0_E2E_PCI_WR_SIZE, 162);
2054 WREG32(mmDMA_IF_E_N_DOWN_CH0_E2E_PCI_RD_SIZE, 338);
2055
2056 WREG32(mmDMA_IF_E_N_DOWN_CH1_E2E_HBM_WR_SIZE, 344 >> 3);
2057 WREG32(mmDMA_IF_E_N_DOWN_CH1_E2E_HBM_RD_SIZE, 1000 >> 3);
2058 WREG32(mmDMA_IF_E_N_DOWN_CH1_E2E_PCI_WR_SIZE, 162);
2059 WREG32(mmDMA_IF_E_N_DOWN_CH1_E2E_PCI_RD_SIZE, 338);
2060
2061 WREG32(mmDMA_IF_E_S_DOWN_CH0_E2E_HBM_WR_SIZE, 344 >> 3);
2062 WREG32(mmDMA_IF_E_S_DOWN_CH0_E2E_HBM_RD_SIZE, 1000 >> 3);
2063 WREG32(mmDMA_IF_E_S_DOWN_CH0_E2E_PCI_WR_SIZE, 162);
2064 WREG32(mmDMA_IF_E_S_DOWN_CH0_E2E_PCI_RD_SIZE, 338);
2065
2066 WREG32(mmDMA_IF_E_S_DOWN_CH1_E2E_HBM_WR_SIZE, 344 >> 3);
2067 WREG32(mmDMA_IF_E_S_DOWN_CH1_E2E_HBM_RD_SIZE, 1000 >> 3);
2068 WREG32(mmDMA_IF_E_S_DOWN_CH1_E2E_PCI_WR_SIZE, 162);
2069 WREG32(mmDMA_IF_E_S_DOWN_CH1_E2E_PCI_RD_SIZE, 338);
2070
2071 WREG32(mmDMA_IF_W_N_DOWN_CH0_E2E_HBM_WR_SIZE, 344 >> 3);
2072 WREG32(mmDMA_IF_W_N_DOWN_CH0_E2E_HBM_RD_SIZE, 1000 >> 3);
2073 WREG32(mmDMA_IF_W_N_DOWN_CH0_E2E_PCI_WR_SIZE, 162);
2074 WREG32(mmDMA_IF_W_N_DOWN_CH0_E2E_PCI_RD_SIZE, 338);
2075
2076 WREG32(mmDMA_IF_W_N_DOWN_CH1_E2E_HBM_WR_SIZE, 344 >> 3);
2077 WREG32(mmDMA_IF_W_N_DOWN_CH1_E2E_HBM_RD_SIZE, 1000 >> 3);
2078 WREG32(mmDMA_IF_W_N_DOWN_CH1_E2E_PCI_WR_SIZE, 162);
2079 WREG32(mmDMA_IF_W_N_DOWN_CH1_E2E_PCI_RD_SIZE, 338);
2080
2081 WREG32(mmDMA_IF_W_S_DOWN_CH0_E2E_HBM_WR_SIZE, 344 >> 3);
2082 WREG32(mmDMA_IF_W_S_DOWN_CH0_E2E_HBM_RD_SIZE, 1000 >> 3);
2083 WREG32(mmDMA_IF_W_S_DOWN_CH0_E2E_PCI_WR_SIZE, 162);
2084 WREG32(mmDMA_IF_W_S_DOWN_CH0_E2E_PCI_RD_SIZE, 338);
2085
2086 WREG32(mmDMA_IF_W_S_DOWN_CH1_E2E_HBM_WR_SIZE, 344 >> 3);
2087 WREG32(mmDMA_IF_W_S_DOWN_CH1_E2E_HBM_RD_SIZE, 1000 >> 3);
2088 WREG32(mmDMA_IF_W_S_DOWN_CH1_E2E_PCI_WR_SIZE, 162);
2089 WREG32(mmDMA_IF_W_S_DOWN_CH1_E2E_PCI_RD_SIZE, 338);
2090
2091 if (!hdev->dram_scrambler_enable) {
2092 WREG32(mmSIF_RTR_CTRL_0_NL_HBM_SEL_0, 0x21);
2093 WREG32(mmSIF_RTR_CTRL_0_NL_HBM_SEL_1, 0x22);
2094 WREG32(mmSIF_RTR_CTRL_0_NL_HBM_OFFSET_18, 0x1F);
2095 WREG32(mmSIF_RTR_CTRL_0_NL_HBM_PC_SEL_3, 0x20);
2096
2097 WREG32(mmSIF_RTR_CTRL_1_NL_HBM_SEL_0, 0x21);
2098 WREG32(mmSIF_RTR_CTRL_1_NL_HBM_SEL_1, 0x22);
2099 WREG32(mmSIF_RTR_CTRL_1_NL_HBM_OFFSET_18, 0x1F);
2100 WREG32(mmSIF_RTR_CTRL_1_NL_HBM_PC_SEL_3, 0x20);
2101
2102 WREG32(mmSIF_RTR_CTRL_2_NL_HBM_SEL_0, 0x21);
2103 WREG32(mmSIF_RTR_CTRL_2_NL_HBM_SEL_1, 0x22);
2104 WREG32(mmSIF_RTR_CTRL_2_NL_HBM_OFFSET_18, 0x1F);
2105 WREG32(mmSIF_RTR_CTRL_2_NL_HBM_PC_SEL_3, 0x20);
2106
2107 WREG32(mmSIF_RTR_CTRL_3_NL_HBM_SEL_0, 0x21);
2108 WREG32(mmSIF_RTR_CTRL_3_NL_HBM_SEL_1, 0x22);
2109 WREG32(mmSIF_RTR_CTRL_3_NL_HBM_OFFSET_18, 0x1F);
2110 WREG32(mmSIF_RTR_CTRL_3_NL_HBM_PC_SEL_3, 0x20);
2111
2112 WREG32(mmSIF_RTR_CTRL_4_NL_HBM_SEL_0, 0x21);
2113 WREG32(mmSIF_RTR_CTRL_4_NL_HBM_SEL_1, 0x22);
2114 WREG32(mmSIF_RTR_CTRL_4_NL_HBM_OFFSET_18, 0x1F);
2115 WREG32(mmSIF_RTR_CTRL_4_NL_HBM_PC_SEL_3, 0x20);
2116
2117 WREG32(mmSIF_RTR_CTRL_5_NL_HBM_SEL_0, 0x21);
2118 WREG32(mmSIF_RTR_CTRL_5_NL_HBM_SEL_1, 0x22);
2119 WREG32(mmSIF_RTR_CTRL_5_NL_HBM_OFFSET_18, 0x1F);
2120 WREG32(mmSIF_RTR_CTRL_5_NL_HBM_PC_SEL_3, 0x20);
2121
2122 WREG32(mmSIF_RTR_CTRL_6_NL_HBM_SEL_0, 0x21);
2123 WREG32(mmSIF_RTR_CTRL_6_NL_HBM_SEL_1, 0x22);
2124 WREG32(mmSIF_RTR_CTRL_6_NL_HBM_OFFSET_18, 0x1F);
2125 WREG32(mmSIF_RTR_CTRL_6_NL_HBM_PC_SEL_3, 0x20);
2126
2127 WREG32(mmSIF_RTR_CTRL_7_NL_HBM_SEL_0, 0x21);
2128 WREG32(mmSIF_RTR_CTRL_7_NL_HBM_SEL_1, 0x22);
2129 WREG32(mmSIF_RTR_CTRL_7_NL_HBM_OFFSET_18, 0x1F);
2130 WREG32(mmSIF_RTR_CTRL_7_NL_HBM_PC_SEL_3, 0x20);
2131
2132 WREG32(mmNIF_RTR_CTRL_0_NL_HBM_SEL_0, 0x21);
2133 WREG32(mmNIF_RTR_CTRL_0_NL_HBM_SEL_1, 0x22);
2134 WREG32(mmNIF_RTR_CTRL_0_NL_HBM_OFFSET_18, 0x1F);
2135 WREG32(mmNIF_RTR_CTRL_0_NL_HBM_PC_SEL_3, 0x20);
2136
2137 WREG32(mmNIF_RTR_CTRL_1_NL_HBM_SEL_0, 0x21);
2138 WREG32(mmNIF_RTR_CTRL_1_NL_HBM_SEL_1, 0x22);
2139 WREG32(mmNIF_RTR_CTRL_1_NL_HBM_OFFSET_18, 0x1F);
2140 WREG32(mmNIF_RTR_CTRL_1_NL_HBM_PC_SEL_3, 0x20);
2141
2142 WREG32(mmNIF_RTR_CTRL_2_NL_HBM_SEL_0, 0x21);
2143 WREG32(mmNIF_RTR_CTRL_2_NL_HBM_SEL_1, 0x22);
2144 WREG32(mmNIF_RTR_CTRL_2_NL_HBM_OFFSET_18, 0x1F);
2145 WREG32(mmNIF_RTR_CTRL_2_NL_HBM_PC_SEL_3, 0x20);
2146
2147 WREG32(mmNIF_RTR_CTRL_3_NL_HBM_SEL_0, 0x21);
2148 WREG32(mmNIF_RTR_CTRL_3_NL_HBM_SEL_1, 0x22);
2149 WREG32(mmNIF_RTR_CTRL_3_NL_HBM_OFFSET_18, 0x1F);
2150 WREG32(mmNIF_RTR_CTRL_3_NL_HBM_PC_SEL_3, 0x20);
2151
2152 WREG32(mmNIF_RTR_CTRL_4_NL_HBM_SEL_0, 0x21);
2153 WREG32(mmNIF_RTR_CTRL_4_NL_HBM_SEL_1, 0x22);
2154 WREG32(mmNIF_RTR_CTRL_4_NL_HBM_OFFSET_18, 0x1F);
2155 WREG32(mmNIF_RTR_CTRL_4_NL_HBM_PC_SEL_3, 0x20);
2156
2157 WREG32(mmNIF_RTR_CTRL_5_NL_HBM_SEL_0, 0x21);
2158 WREG32(mmNIF_RTR_CTRL_5_NL_HBM_SEL_1, 0x22);
2159 WREG32(mmNIF_RTR_CTRL_5_NL_HBM_OFFSET_18, 0x1F);
2160 WREG32(mmNIF_RTR_CTRL_5_NL_HBM_PC_SEL_3, 0x20);
2161
2162 WREG32(mmNIF_RTR_CTRL_6_NL_HBM_SEL_0, 0x21);
2163 WREG32(mmNIF_RTR_CTRL_6_NL_HBM_SEL_1, 0x22);
2164 WREG32(mmNIF_RTR_CTRL_6_NL_HBM_OFFSET_18, 0x1F);
2165 WREG32(mmNIF_RTR_CTRL_6_NL_HBM_PC_SEL_3, 0x20);
2166
2167 WREG32(mmNIF_RTR_CTRL_7_NL_HBM_SEL_0, 0x21);
2168 WREG32(mmNIF_RTR_CTRL_7_NL_HBM_SEL_1, 0x22);
2169 WREG32(mmNIF_RTR_CTRL_7_NL_HBM_OFFSET_18, 0x1F);
2170 WREG32(mmNIF_RTR_CTRL_7_NL_HBM_PC_SEL_3, 0x20);
2171
2172 WREG32(mmDMA_IF_E_N_DOWN_CH0_NL_HBM_SEL_0, 0x21);
2173 WREG32(mmDMA_IF_E_N_DOWN_CH0_NL_HBM_SEL_1, 0x22);
2174 WREG32(mmDMA_IF_E_N_DOWN_CH0_NL_HBM_OFFSET_18, 0x1F);
2175 WREG32(mmDMA_IF_E_N_DOWN_CH0_NL_HBM_PC_SEL_3, 0x20);
2176
2177 WREG32(mmDMA_IF_E_N_DOWN_CH1_NL_HBM_SEL_0, 0x21);
2178 WREG32(mmDMA_IF_E_N_DOWN_CH1_NL_HBM_SEL_1, 0x22);
2179 WREG32(mmDMA_IF_E_N_DOWN_CH1_NL_HBM_OFFSET_18, 0x1F);
2180 WREG32(mmDMA_IF_E_N_DOWN_CH1_NL_HBM_PC_SEL_3, 0x20);
2181
2182 WREG32(mmDMA_IF_E_S_DOWN_CH0_NL_HBM_SEL_0, 0x21);
2183 WREG32(mmDMA_IF_E_S_DOWN_CH0_NL_HBM_SEL_1, 0x22);
2184 WREG32(mmDMA_IF_E_S_DOWN_CH0_NL_HBM_OFFSET_18, 0x1F);
2185 WREG32(mmDMA_IF_E_S_DOWN_CH0_NL_HBM_PC_SEL_3, 0x20);
2186
2187 WREG32(mmDMA_IF_E_S_DOWN_CH1_NL_HBM_SEL_0, 0x21);
2188 WREG32(mmDMA_IF_E_S_DOWN_CH1_NL_HBM_SEL_1, 0x22);
2189 WREG32(mmDMA_IF_E_S_DOWN_CH1_NL_HBM_OFFSET_18, 0x1F);
2190 WREG32(mmDMA_IF_E_S_DOWN_CH1_NL_HBM_PC_SEL_3, 0x20);
2191
2192 WREG32(mmDMA_IF_W_N_DOWN_CH0_NL_HBM_SEL_0, 0x21);
2193 WREG32(mmDMA_IF_W_N_DOWN_CH0_NL_HBM_SEL_1, 0x22);
2194 WREG32(mmDMA_IF_W_N_DOWN_CH0_NL_HBM_OFFSET_18, 0x1F);
2195 WREG32(mmDMA_IF_W_N_DOWN_CH0_NL_HBM_PC_SEL_3, 0x20);
2196
2197 WREG32(mmDMA_IF_W_N_DOWN_CH1_NL_HBM_SEL_0, 0x21);
2198 WREG32(mmDMA_IF_W_N_DOWN_CH1_NL_HBM_SEL_1, 0x22);
2199 WREG32(mmDMA_IF_W_N_DOWN_CH1_NL_HBM_OFFSET_18, 0x1F);
2200 WREG32(mmDMA_IF_W_N_DOWN_CH1_NL_HBM_PC_SEL_3, 0x20);
2201
2202 WREG32(mmDMA_IF_W_S_DOWN_CH0_NL_HBM_SEL_0, 0x21);
2203 WREG32(mmDMA_IF_W_S_DOWN_CH0_NL_HBM_SEL_1, 0x22);
2204 WREG32(mmDMA_IF_W_S_DOWN_CH0_NL_HBM_OFFSET_18, 0x1F);
2205 WREG32(mmDMA_IF_W_S_DOWN_CH0_NL_HBM_PC_SEL_3, 0x20);
2206
2207 WREG32(mmDMA_IF_W_S_DOWN_CH1_NL_HBM_SEL_0, 0x21);
2208 WREG32(mmDMA_IF_W_S_DOWN_CH1_NL_HBM_SEL_1, 0x22);
2209 WREG32(mmDMA_IF_W_S_DOWN_CH1_NL_HBM_OFFSET_18, 0x1F);
2210 WREG32(mmDMA_IF_W_S_DOWN_CH1_NL_HBM_PC_SEL_3, 0x20);
2211 }
2212
2213 WREG32(mmSIF_RTR_CTRL_0_E2E_HBM_EN,
2214 1 << IF_RTR_CTRL_E2E_HBM_EN_VAL_SHIFT);
2215 WREG32(mmSIF_RTR_CTRL_0_E2E_PCI_EN,
2216 1 << IF_RTR_CTRL_E2E_PCI_EN_VAL_SHIFT);
2217
2218 WREG32(mmSIF_RTR_CTRL_1_E2E_HBM_EN,
2219 1 << IF_RTR_CTRL_E2E_HBM_EN_VAL_SHIFT);
2220 WREG32(mmSIF_RTR_CTRL_1_E2E_PCI_EN,
2221 1 << IF_RTR_CTRL_E2E_PCI_EN_VAL_SHIFT);
2222
2223 WREG32(mmSIF_RTR_CTRL_2_E2E_HBM_EN,
2224 1 << IF_RTR_CTRL_E2E_HBM_EN_VAL_SHIFT);
2225 WREG32(mmSIF_RTR_CTRL_2_E2E_PCI_EN,
2226 1 << IF_RTR_CTRL_E2E_PCI_EN_VAL_SHIFT);
2227
2228 WREG32(mmSIF_RTR_CTRL_3_E2E_HBM_EN,
2229 1 << IF_RTR_CTRL_E2E_HBM_EN_VAL_SHIFT);
2230 WREG32(mmSIF_RTR_CTRL_3_E2E_PCI_EN,
2231 1 << IF_RTR_CTRL_E2E_PCI_EN_VAL_SHIFT);
2232
2233 WREG32(mmSIF_RTR_CTRL_4_E2E_HBM_EN,
2234 1 << IF_RTR_CTRL_E2E_HBM_EN_VAL_SHIFT);
2235 WREG32(mmSIF_RTR_CTRL_4_E2E_PCI_EN,
2236 1 << IF_RTR_CTRL_E2E_PCI_EN_VAL_SHIFT);
2237
2238 WREG32(mmSIF_RTR_CTRL_5_E2E_HBM_EN,
2239 1 << IF_RTR_CTRL_E2E_HBM_EN_VAL_SHIFT);
2240 WREG32(mmSIF_RTR_CTRL_5_E2E_PCI_EN,
2241 1 << IF_RTR_CTRL_E2E_PCI_EN_VAL_SHIFT);
2242
2243 WREG32(mmSIF_RTR_CTRL_6_E2E_HBM_EN,
2244 1 << IF_RTR_CTRL_E2E_HBM_EN_VAL_SHIFT);
2245 WREG32(mmSIF_RTR_CTRL_6_E2E_PCI_EN,
2246 1 << IF_RTR_CTRL_E2E_PCI_EN_VAL_SHIFT);
2247
2248 WREG32(mmSIF_RTR_CTRL_7_E2E_HBM_EN,
2249 1 << IF_RTR_CTRL_E2E_HBM_EN_VAL_SHIFT);
2250 WREG32(mmSIF_RTR_CTRL_7_E2E_PCI_EN,
2251 1 << IF_RTR_CTRL_E2E_PCI_EN_VAL_SHIFT);
2252
2253 WREG32(mmNIF_RTR_CTRL_0_E2E_HBM_EN,
2254 1 << IF_RTR_CTRL_E2E_HBM_EN_VAL_SHIFT);
2255 WREG32(mmNIF_RTR_CTRL_0_E2E_PCI_EN,
2256 1 << IF_RTR_CTRL_E2E_PCI_EN_VAL_SHIFT);
2257
2258 WREG32(mmNIF_RTR_CTRL_1_E2E_HBM_EN,
2259 1 << IF_RTR_CTRL_E2E_HBM_EN_VAL_SHIFT);
2260 WREG32(mmNIF_RTR_CTRL_1_E2E_PCI_EN,
2261 1 << IF_RTR_CTRL_E2E_PCI_EN_VAL_SHIFT);
2262
2263 WREG32(mmNIF_RTR_CTRL_2_E2E_HBM_EN,
2264 1 << IF_RTR_CTRL_E2E_HBM_EN_VAL_SHIFT);
2265 WREG32(mmNIF_RTR_CTRL_2_E2E_PCI_EN,
2266 1 << IF_RTR_CTRL_E2E_PCI_EN_VAL_SHIFT);
2267
2268 WREG32(mmNIF_RTR_CTRL_3_E2E_HBM_EN,
2269 1 << IF_RTR_CTRL_E2E_HBM_EN_VAL_SHIFT);
2270 WREG32(mmNIF_RTR_CTRL_3_E2E_PCI_EN,
2271 1 << IF_RTR_CTRL_E2E_PCI_EN_VAL_SHIFT);
2272
2273 WREG32(mmNIF_RTR_CTRL_4_E2E_HBM_EN,
2274 1 << IF_RTR_CTRL_E2E_HBM_EN_VAL_SHIFT);
2275 WREG32(mmNIF_RTR_CTRL_4_E2E_PCI_EN,
2276 1 << IF_RTR_CTRL_E2E_PCI_EN_VAL_SHIFT);
2277
2278 WREG32(mmNIF_RTR_CTRL_5_E2E_HBM_EN,
2279 1 << IF_RTR_CTRL_E2E_HBM_EN_VAL_SHIFT);
2280 WREG32(mmNIF_RTR_CTRL_5_E2E_PCI_EN,
2281 1 << IF_RTR_CTRL_E2E_PCI_EN_VAL_SHIFT);
2282
2283 WREG32(mmNIF_RTR_CTRL_6_E2E_HBM_EN,
2284 1 << IF_RTR_CTRL_E2E_HBM_EN_VAL_SHIFT);
2285 WREG32(mmNIF_RTR_CTRL_6_E2E_PCI_EN,
2286 1 << IF_RTR_CTRL_E2E_PCI_EN_VAL_SHIFT);
2287
2288 WREG32(mmNIF_RTR_CTRL_7_E2E_HBM_EN,
2289 1 << IF_RTR_CTRL_E2E_HBM_EN_VAL_SHIFT);
2290 WREG32(mmNIF_RTR_CTRL_7_E2E_PCI_EN,
2291 1 << IF_RTR_CTRL_E2E_PCI_EN_VAL_SHIFT);
2292
2293 WREG32(mmDMA_IF_E_N_DOWN_CH0_E2E_HBM_EN,
2294 1 << DMA_IF_DOWN_CHX_E2E_HBM_EN_VAL_SHIFT);
2295 WREG32(mmDMA_IF_E_N_DOWN_CH0_E2E_PCI_EN,
2296 1 << DMA_IF_DOWN_CHX_E2E_PCI_EN_VAL_SHIFT);
2297
2298 WREG32(mmDMA_IF_E_N_DOWN_CH1_E2E_HBM_EN,
2299 1 << DMA_IF_DOWN_CHX_E2E_HBM_EN_VAL_SHIFT);
2300 WREG32(mmDMA_IF_E_N_DOWN_CH1_E2E_PCI_EN,
2301 1 << DMA_IF_DOWN_CHX_E2E_PCI_EN_VAL_SHIFT);
2302
2303 WREG32(mmDMA_IF_E_S_DOWN_CH0_E2E_HBM_EN,
2304 1 << DMA_IF_DOWN_CHX_E2E_HBM_EN_VAL_SHIFT);
2305 WREG32(mmDMA_IF_E_S_DOWN_CH0_E2E_PCI_EN,
2306 1 << DMA_IF_DOWN_CHX_E2E_PCI_EN_VAL_SHIFT);
2307
2308 WREG32(mmDMA_IF_E_S_DOWN_CH1_E2E_HBM_EN,
2309 1 << DMA_IF_DOWN_CHX_E2E_HBM_EN_VAL_SHIFT);
2310 WREG32(mmDMA_IF_E_S_DOWN_CH1_E2E_PCI_EN,
2311 1 << DMA_IF_DOWN_CHX_E2E_PCI_EN_VAL_SHIFT);
2312
2313 WREG32(mmDMA_IF_W_N_DOWN_CH0_E2E_HBM_EN,
2314 1 << DMA_IF_DOWN_CHX_E2E_HBM_EN_VAL_SHIFT);
2315 WREG32(mmDMA_IF_W_N_DOWN_CH0_E2E_PCI_EN,
2316 1 << DMA_IF_DOWN_CHX_E2E_PCI_EN_VAL_SHIFT);
2317
2318 WREG32(mmDMA_IF_W_N_DOWN_CH1_E2E_HBM_EN,
2319 1 << DMA_IF_DOWN_CHX_E2E_HBM_EN_VAL_SHIFT);
2320 WREG32(mmDMA_IF_W_N_DOWN_CH1_E2E_PCI_EN,
2321 1 << DMA_IF_DOWN_CHX_E2E_PCI_EN_VAL_SHIFT);
2322
2323 WREG32(mmDMA_IF_W_S_DOWN_CH0_E2E_HBM_EN,
2324 1 << DMA_IF_DOWN_CHX_E2E_HBM_EN_VAL_SHIFT);
2325 WREG32(mmDMA_IF_W_S_DOWN_CH0_E2E_PCI_EN,
2326 1 << DMA_IF_DOWN_CHX_E2E_PCI_EN_VAL_SHIFT);
2327
2328 WREG32(mmDMA_IF_W_S_DOWN_CH1_E2E_HBM_EN,
2329 1 << DMA_IF_DOWN_CHX_E2E_HBM_EN_VAL_SHIFT);
2330 WREG32(mmDMA_IF_W_S_DOWN_CH1_E2E_PCI_EN,
2331 1 << DMA_IF_DOWN_CHX_E2E_PCI_EN_VAL_SHIFT);
2332}
2333
2334static void gaudi_init_hbm_cred(struct hl_device *hdev)
2335{
2336 uint32_t hbm0_wr, hbm1_wr, hbm0_rd, hbm1_rd;
2337
Ofir Bittonc692dec2020-10-04 17:34:37 +03002338 if (!hdev->asic_prop.fw_security_disabled)
2339 return;
2340
2341 if (hdev->asic_prop.fw_security_status_valid &&
2342 (hdev->asic_prop.fw_boot_cpu_security_map &
2343 CPU_BOOT_DEV_STS0_HBM_CRED_EN))
2344 return;
2345
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03002346 hbm0_wr = 0x33333333;
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03002347 hbm0_rd = 0x77777777;
Oded Gabbay0b168c82020-06-15 19:25:57 +03002348 hbm1_wr = 0x55555555;
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03002349 hbm1_rd = 0xDDDDDDDD;
2350
2351 WREG32(mmDMA_IF_E_N_HBM0_WR_CRED_CNT, hbm0_wr);
2352 WREG32(mmDMA_IF_E_N_HBM1_WR_CRED_CNT, hbm1_wr);
2353 WREG32(mmDMA_IF_E_N_HBM0_RD_CRED_CNT, hbm0_rd);
2354 WREG32(mmDMA_IF_E_N_HBM1_RD_CRED_CNT, hbm1_rd);
2355
2356 WREG32(mmDMA_IF_E_S_HBM0_WR_CRED_CNT, hbm0_wr);
2357 WREG32(mmDMA_IF_E_S_HBM1_WR_CRED_CNT, hbm1_wr);
2358 WREG32(mmDMA_IF_E_S_HBM0_RD_CRED_CNT, hbm0_rd);
2359 WREG32(mmDMA_IF_E_S_HBM1_RD_CRED_CNT, hbm1_rd);
2360
2361 WREG32(mmDMA_IF_W_N_HBM0_WR_CRED_CNT, hbm0_wr);
2362 WREG32(mmDMA_IF_W_N_HBM1_WR_CRED_CNT, hbm1_wr);
2363 WREG32(mmDMA_IF_W_N_HBM0_RD_CRED_CNT, hbm0_rd);
2364 WREG32(mmDMA_IF_W_N_HBM1_RD_CRED_CNT, hbm1_rd);
2365
2366 WREG32(mmDMA_IF_W_S_HBM0_WR_CRED_CNT, hbm0_wr);
2367 WREG32(mmDMA_IF_W_S_HBM1_WR_CRED_CNT, hbm1_wr);
2368 WREG32(mmDMA_IF_W_S_HBM0_RD_CRED_CNT, hbm0_rd);
2369 WREG32(mmDMA_IF_W_S_HBM1_RD_CRED_CNT, hbm1_rd);
2370
2371 WREG32(mmDMA_IF_E_N_HBM_CRED_EN_0,
2372 (1 << DMA_IF_HBM_CRED_EN_READ_CREDIT_EN_SHIFT) |
2373 (1 << DMA_IF_HBM_CRED_EN_WRITE_CREDIT_EN_SHIFT));
2374 WREG32(mmDMA_IF_E_S_HBM_CRED_EN_0,
2375 (1 << DMA_IF_HBM_CRED_EN_READ_CREDIT_EN_SHIFT) |
2376 (1 << DMA_IF_HBM_CRED_EN_WRITE_CREDIT_EN_SHIFT));
2377 WREG32(mmDMA_IF_W_N_HBM_CRED_EN_0,
2378 (1 << DMA_IF_HBM_CRED_EN_READ_CREDIT_EN_SHIFT) |
2379 (1 << DMA_IF_HBM_CRED_EN_WRITE_CREDIT_EN_SHIFT));
2380 WREG32(mmDMA_IF_W_S_HBM_CRED_EN_0,
2381 (1 << DMA_IF_HBM_CRED_EN_READ_CREDIT_EN_SHIFT) |
2382 (1 << DMA_IF_HBM_CRED_EN_WRITE_CREDIT_EN_SHIFT));
2383
2384 WREG32(mmDMA_IF_E_N_HBM_CRED_EN_1,
2385 (1 << DMA_IF_HBM_CRED_EN_READ_CREDIT_EN_SHIFT) |
2386 (1 << DMA_IF_HBM_CRED_EN_WRITE_CREDIT_EN_SHIFT));
2387 WREG32(mmDMA_IF_E_S_HBM_CRED_EN_1,
2388 (1 << DMA_IF_HBM_CRED_EN_READ_CREDIT_EN_SHIFT) |
2389 (1 << DMA_IF_HBM_CRED_EN_WRITE_CREDIT_EN_SHIFT));
2390 WREG32(mmDMA_IF_W_N_HBM_CRED_EN_1,
2391 (1 << DMA_IF_HBM_CRED_EN_READ_CREDIT_EN_SHIFT) |
2392 (1 << DMA_IF_HBM_CRED_EN_WRITE_CREDIT_EN_SHIFT));
2393 WREG32(mmDMA_IF_W_S_HBM_CRED_EN_1,
2394 (1 << DMA_IF_HBM_CRED_EN_READ_CREDIT_EN_SHIFT) |
2395 (1 << DMA_IF_HBM_CRED_EN_WRITE_CREDIT_EN_SHIFT));
2396}
2397
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03002398static void gaudi_init_golden_registers(struct hl_device *hdev)
2399{
2400 u32 tpc_offset;
2401 int tpc_id, i;
2402
2403 gaudi_init_e2e(hdev);
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03002404 gaudi_init_hbm_cred(hdev);
2405
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03002406 for (tpc_id = 0, tpc_offset = 0;
2407 tpc_id < TPC_NUMBER_OF_ENGINES;
2408 tpc_id++, tpc_offset += TPC_CFG_OFFSET) {
2409 /* Mask all arithmetic interrupts from TPC */
2410 WREG32(mmTPC0_CFG_TPC_INTR_MASK + tpc_offset, 0x8FFF);
2411 /* Set 16 cache lines */
2412 WREG32_FIELD(TPC0_CFG_MSS_CONFIG, tpc_offset,
2413 ICACHE_FETCH_LINE_NUM, 2);
2414 }
2415
2416 /* Make sure 1st 128 bytes in SRAM are 0 for Tensor DMA */
2417 for (i = 0 ; i < 128 ; i += 8)
2418 writeq(0, hdev->pcie_bar[SRAM_BAR_ID] + i);
2419
2420 WREG32(mmMME0_CTRL_EUS_ROLLUP_CNT_ADD, 3);
2421 WREG32(mmMME1_CTRL_EUS_ROLLUP_CNT_ADD, 3);
2422 WREG32(mmMME2_CTRL_EUS_ROLLUP_CNT_ADD, 3);
2423 WREG32(mmMME3_CTRL_EUS_ROLLUP_CNT_ADD, 3);
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03002424}
2425
2426static void gaudi_init_pci_dma_qman(struct hl_device *hdev, int dma_id,
2427 int qman_id, dma_addr_t qman_pq_addr)
2428{
2429 u32 mtr_base_en_lo, mtr_base_en_hi, mtr_base_ws_lo, mtr_base_ws_hi;
2430 u32 so_base_en_lo, so_base_en_hi, so_base_ws_lo, so_base_ws_hi;
2431 u32 q_off, dma_qm_offset;
2432 u32 dma_qm_err_cfg;
2433
2434 dma_qm_offset = dma_id * DMA_QMAN_OFFSET;
2435
2436 mtr_base_en_lo = lower_32_bits(CFG_BASE +
2437 mmSYNC_MNGR_E_N_SYNC_MNGR_OBJS_MON_PAY_ADDRL_0);
2438 mtr_base_en_hi = upper_32_bits(CFG_BASE +
2439 mmSYNC_MNGR_E_N_SYNC_MNGR_OBJS_MON_PAY_ADDRL_0);
2440 so_base_en_lo = lower_32_bits(CFG_BASE +
2441 mmSYNC_MNGR_E_N_SYNC_MNGR_OBJS_SOB_OBJ_0);
2442 so_base_en_hi = upper_32_bits(CFG_BASE +
2443 mmSYNC_MNGR_E_N_SYNC_MNGR_OBJS_SOB_OBJ_0);
2444 mtr_base_ws_lo = lower_32_bits(CFG_BASE +
2445 mmSYNC_MNGR_W_S_SYNC_MNGR_OBJS_MON_PAY_ADDRL_0);
2446 mtr_base_ws_hi = upper_32_bits(CFG_BASE +
2447 mmSYNC_MNGR_W_S_SYNC_MNGR_OBJS_MON_PAY_ADDRL_0);
2448 so_base_ws_lo = lower_32_bits(CFG_BASE +
2449 mmSYNC_MNGR_W_S_SYNC_MNGR_OBJS_SOB_OBJ_0);
2450 so_base_ws_hi = upper_32_bits(CFG_BASE +
2451 mmSYNC_MNGR_W_S_SYNC_MNGR_OBJS_SOB_OBJ_0);
2452
2453 q_off = dma_qm_offset + qman_id * 4;
2454
2455 WREG32(mmDMA0_QM_PQ_BASE_LO_0 + q_off, lower_32_bits(qman_pq_addr));
2456 WREG32(mmDMA0_QM_PQ_BASE_HI_0 + q_off, upper_32_bits(qman_pq_addr));
2457
2458 WREG32(mmDMA0_QM_PQ_SIZE_0 + q_off, ilog2(HL_QUEUE_LENGTH));
2459 WREG32(mmDMA0_QM_PQ_PI_0 + q_off, 0);
2460 WREG32(mmDMA0_QM_PQ_CI_0 + q_off, 0);
2461
Ofir Bitton25121d92020-09-24 08:22:58 +03002462 WREG32(mmDMA0_QM_CP_LDMA_TSIZE_OFFSET_0 + q_off, QMAN_LDMA_SIZE_OFFSET);
2463 WREG32(mmDMA0_QM_CP_LDMA_SRC_BASE_LO_OFFSET_0 + q_off,
2464 QMAN_LDMA_SRC_OFFSET);
2465 WREG32(mmDMA0_QM_CP_LDMA_DST_BASE_LO_OFFSET_0 + q_off,
2466 QMAN_LDMA_DST_OFFSET);
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03002467
2468 WREG32(mmDMA0_QM_CP_MSG_BASE0_ADDR_LO_0 + q_off, mtr_base_en_lo);
2469 WREG32(mmDMA0_QM_CP_MSG_BASE0_ADDR_HI_0 + q_off, mtr_base_en_hi);
2470 WREG32(mmDMA0_QM_CP_MSG_BASE1_ADDR_LO_0 + q_off, so_base_en_lo);
2471 WREG32(mmDMA0_QM_CP_MSG_BASE1_ADDR_HI_0 + q_off, so_base_en_hi);
2472 WREG32(mmDMA0_QM_CP_MSG_BASE2_ADDR_LO_0 + q_off, mtr_base_ws_lo);
2473 WREG32(mmDMA0_QM_CP_MSG_BASE2_ADDR_HI_0 + q_off, mtr_base_ws_hi);
2474 WREG32(mmDMA0_QM_CP_MSG_BASE3_ADDR_LO_0 + q_off, so_base_ws_lo);
2475 WREG32(mmDMA0_QM_CP_MSG_BASE3_ADDR_HI_0 + q_off, so_base_ws_hi);
2476
Omer Shpigelmance043262020-06-16 17:56:27 +03002477 WREG32(mmDMA0_QM_CP_BARRIER_CFG_0 + q_off, 0x100);
2478
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03002479 /* The following configuration is needed only once per QMAN */
2480 if (qman_id == 0) {
2481 /* Configure RAZWI IRQ */
2482 dma_qm_err_cfg = PCI_DMA_QMAN_GLBL_ERR_CFG_MSG_EN_MASK;
2483 if (hdev->stop_on_err) {
2484 dma_qm_err_cfg |=
2485 PCI_DMA_QMAN_GLBL_ERR_CFG_STOP_ON_ERR_EN_MASK;
2486 }
2487
2488 WREG32(mmDMA0_QM_GLBL_ERR_CFG + dma_qm_offset, dma_qm_err_cfg);
2489 WREG32(mmDMA0_QM_GLBL_ERR_ADDR_LO + dma_qm_offset,
2490 lower_32_bits(CFG_BASE +
2491 mmGIC_DISTRIBUTOR__5_GICD_SETSPI_NSR));
2492 WREG32(mmDMA0_QM_GLBL_ERR_ADDR_HI + dma_qm_offset,
2493 upper_32_bits(CFG_BASE +
2494 mmGIC_DISTRIBUTOR__5_GICD_SETSPI_NSR));
2495 WREG32(mmDMA0_QM_GLBL_ERR_WDATA + dma_qm_offset,
2496 gaudi_irq_map_table[GAUDI_EVENT_DMA0_QM].cpu_id +
2497 dma_id);
2498
2499 WREG32(mmDMA0_QM_ARB_ERR_MSG_EN + dma_qm_offset,
2500 QM_ARB_ERR_MSG_EN_MASK);
2501
2502 /* Increase ARB WDT to support streams architecture */
2503 WREG32(mmDMA0_QM_ARB_SLV_CHOISE_WDT + dma_qm_offset,
2504 GAUDI_ARB_WDT_TIMEOUT);
2505
2506 WREG32(mmDMA0_QM_GLBL_PROT + dma_qm_offset,
2507 QMAN_EXTERNAL_MAKE_TRUSTED);
2508
2509 WREG32(mmDMA0_QM_GLBL_CFG1 + dma_qm_offset, 0);
2510 }
2511}
2512
2513static void gaudi_init_dma_core(struct hl_device *hdev, int dma_id)
2514{
2515 u32 dma_offset = dma_id * DMA_CORE_OFFSET;
2516 u32 dma_err_cfg = 1 << DMA0_CORE_ERR_CFG_ERR_MSG_EN_SHIFT;
2517
2518 /* Set to maximum possible according to physical size */
2519 WREG32(mmDMA0_CORE_RD_MAX_OUTSTAND + dma_offset, 0);
2520 WREG32(mmDMA0_CORE_RD_MAX_SIZE + dma_offset, 0);
2521
Oded Gabbayd1f36332020-09-14 09:26:54 +03002522 /* WA for H/W bug H3-2116 */
2523 WREG32(mmDMA0_CORE_LBW_MAX_OUTSTAND + dma_offset, 15);
2524
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03002525 /* STOP_ON bit implies no completion to operation in case of RAZWI */
2526 if (hdev->stop_on_err)
2527 dma_err_cfg |= 1 << DMA0_CORE_ERR_CFG_STOP_ON_ERR_SHIFT;
2528
2529 WREG32(mmDMA0_CORE_ERR_CFG + dma_offset, dma_err_cfg);
2530 WREG32(mmDMA0_CORE_ERRMSG_ADDR_LO + dma_offset,
2531 lower_32_bits(CFG_BASE + mmGIC_DISTRIBUTOR__5_GICD_SETSPI_NSR));
2532 WREG32(mmDMA0_CORE_ERRMSG_ADDR_HI + dma_offset,
2533 upper_32_bits(CFG_BASE + mmGIC_DISTRIBUTOR__5_GICD_SETSPI_NSR));
2534 WREG32(mmDMA0_CORE_ERRMSG_WDATA + dma_offset,
2535 gaudi_irq_map_table[GAUDI_EVENT_DMA0_CORE].cpu_id + dma_id);
2536 WREG32(mmDMA0_CORE_PROT + dma_offset,
2537 1 << DMA0_CORE_PROT_ERR_VAL_SHIFT);
2538 /* If the channel is secured, it should be in MMU bypass mode */
2539 WREG32(mmDMA0_CORE_SECURE_PROPS + dma_offset,
2540 1 << DMA0_CORE_SECURE_PROPS_MMBP_SHIFT);
2541 WREG32(mmDMA0_CORE_CFG_0 + dma_offset, 1 << DMA0_CORE_CFG_0_EN_SHIFT);
2542}
2543
2544static void gaudi_enable_qman(struct hl_device *hdev, int dma_id,
2545 u32 enable_mask)
2546{
2547 u32 dma_qm_offset = dma_id * DMA_QMAN_OFFSET;
2548
2549 WREG32(mmDMA0_QM_GLBL_CFG0 + dma_qm_offset, enable_mask);
2550}
2551
2552static void gaudi_init_pci_dma_qmans(struct hl_device *hdev)
2553{
2554 struct gaudi_device *gaudi = hdev->asic_specific;
2555 struct hl_hw_queue *q;
2556 int i, j, dma_id, cpu_skip, nic_skip, cq_id = 0, q_idx, msi_vec = 0;
2557
2558 if (gaudi->hw_cap_initialized & HW_CAP_PCI_DMA)
2559 return;
2560
2561 for (i = 0 ; i < PCI_DMA_NUMBER_OF_CHNLS ; i++) {
2562 dma_id = gaudi_dma_assignment[i];
2563 /*
2564 * For queues after the CPU Q need to add 1 to get the correct
2565 * queue. In addition, need to add the CPU EQ and NIC IRQs in
2566 * order to get the correct MSI register.
2567 */
2568 if (dma_id > 1) {
2569 cpu_skip = 1;
2570 nic_skip = NIC_NUMBER_OF_ENGINES;
2571 } else {
2572 cpu_skip = 0;
2573 nic_skip = 0;
2574 }
2575
2576 for (j = 0 ; j < QMAN_STREAMS ; j++) {
2577 q_idx = 4 * dma_id + j + cpu_skip;
2578 q = &hdev->kernel_queues[q_idx];
2579 q->cq_id = cq_id++;
2580 q->msi_vec = nic_skip + cpu_skip + msi_vec++;
2581 gaudi_init_pci_dma_qman(hdev, dma_id, j,
2582 q->bus_address);
2583 }
2584
2585 gaudi_init_dma_core(hdev, dma_id);
2586
2587 gaudi_enable_qman(hdev, dma_id, PCI_DMA_QMAN_ENABLE);
2588 }
2589
2590 gaudi->hw_cap_initialized |= HW_CAP_PCI_DMA;
2591}
2592
2593static void gaudi_init_hbm_dma_qman(struct hl_device *hdev, int dma_id,
2594 int qman_id, u64 qman_base_addr)
2595{
Ofir Bitton5de406c2020-09-10 10:56:26 +03002596 u32 mtr_base_en_lo, mtr_base_en_hi, mtr_base_ws_lo, mtr_base_ws_hi;
2597 u32 so_base_en_lo, so_base_en_hi, so_base_ws_lo, so_base_ws_hi;
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03002598 u32 q_off, dma_qm_offset;
2599 u32 dma_qm_err_cfg;
2600
2601 dma_qm_offset = dma_id * DMA_QMAN_OFFSET;
2602
Ofir Bitton5de406c2020-09-10 10:56:26 +03002603 mtr_base_en_lo = lower_32_bits(CFG_BASE +
2604 mmSYNC_MNGR_E_N_SYNC_MNGR_OBJS_MON_PAY_ADDRL_0);
2605 mtr_base_en_hi = upper_32_bits(CFG_BASE +
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03002606 mmSYNC_MNGR_E_N_SYNC_MNGR_OBJS_MON_PAY_ADDRL_0);
Ofir Bitton5de406c2020-09-10 10:56:26 +03002607 so_base_en_lo = lower_32_bits(CFG_BASE +
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03002608 mmSYNC_MNGR_E_N_SYNC_MNGR_OBJS_SOB_OBJ_0);
Ofir Bitton5de406c2020-09-10 10:56:26 +03002609 so_base_en_hi = upper_32_bits(CFG_BASE +
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03002610 mmSYNC_MNGR_E_N_SYNC_MNGR_OBJS_SOB_OBJ_0);
Ofir Bitton5de406c2020-09-10 10:56:26 +03002611 mtr_base_ws_lo = lower_32_bits(CFG_BASE +
2612 mmSYNC_MNGR_W_S_SYNC_MNGR_OBJS_MON_PAY_ADDRL_0);
2613 mtr_base_ws_hi = upper_32_bits(CFG_BASE +
2614 mmSYNC_MNGR_W_S_SYNC_MNGR_OBJS_MON_PAY_ADDRL_0);
2615 so_base_ws_lo = lower_32_bits(CFG_BASE +
2616 mmSYNC_MNGR_W_S_SYNC_MNGR_OBJS_SOB_OBJ_0);
2617 so_base_ws_hi = upper_32_bits(CFG_BASE +
2618 mmSYNC_MNGR_W_S_SYNC_MNGR_OBJS_SOB_OBJ_0);
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03002619
2620 q_off = dma_qm_offset + qman_id * 4;
2621
2622 if (qman_id < 4) {
2623 WREG32(mmDMA0_QM_PQ_BASE_LO_0 + q_off,
2624 lower_32_bits(qman_base_addr));
2625 WREG32(mmDMA0_QM_PQ_BASE_HI_0 + q_off,
2626 upper_32_bits(qman_base_addr));
2627
2628 WREG32(mmDMA0_QM_PQ_SIZE_0 + q_off, ilog2(HBM_DMA_QMAN_LENGTH));
2629 WREG32(mmDMA0_QM_PQ_PI_0 + q_off, 0);
2630 WREG32(mmDMA0_QM_PQ_CI_0 + q_off, 0);
2631
Ofir Bitton25121d92020-09-24 08:22:58 +03002632 WREG32(mmDMA0_QM_CP_LDMA_TSIZE_OFFSET_0 + q_off,
2633 QMAN_CPDMA_SIZE_OFFSET);
2634 WREG32(mmDMA0_QM_CP_LDMA_SRC_BASE_LO_OFFSET_0 + q_off,
2635 QMAN_CPDMA_SRC_OFFSET);
2636 WREG32(mmDMA0_QM_CP_LDMA_DST_BASE_LO_OFFSET_0 + q_off,
2637 QMAN_CPDMA_DST_OFFSET);
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03002638 } else {
Ofir Bitton25121d92020-09-24 08:22:58 +03002639 WREG32(mmDMA0_QM_CP_LDMA_TSIZE_OFFSET_0 + q_off,
2640 QMAN_LDMA_SIZE_OFFSET);
2641 WREG32(mmDMA0_QM_CP_LDMA_SRC_BASE_LO_OFFSET_0 + q_off,
2642 QMAN_LDMA_SRC_OFFSET);
2643 WREG32(mmDMA0_QM_CP_LDMA_DST_BASE_LO_OFFSET_0 + q_off,
Oded Gabbay5b94d6e2020-09-25 20:14:15 +03002644 QMAN_LDMA_DST_OFFSET);
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03002645
2646 /* Configure RAZWI IRQ */
2647 dma_qm_err_cfg = HBM_DMA_QMAN_GLBL_ERR_CFG_MSG_EN_MASK;
2648 if (hdev->stop_on_err) {
2649 dma_qm_err_cfg |=
2650 HBM_DMA_QMAN_GLBL_ERR_CFG_STOP_ON_ERR_EN_MASK;
2651 }
2652 WREG32(mmDMA0_QM_GLBL_ERR_CFG + dma_qm_offset, dma_qm_err_cfg);
2653
2654 WREG32(mmDMA0_QM_GLBL_ERR_ADDR_LO + dma_qm_offset,
2655 lower_32_bits(CFG_BASE +
2656 mmGIC_DISTRIBUTOR__5_GICD_SETSPI_NSR));
2657 WREG32(mmDMA0_QM_GLBL_ERR_ADDR_HI + dma_qm_offset,
2658 upper_32_bits(CFG_BASE +
2659 mmGIC_DISTRIBUTOR__5_GICD_SETSPI_NSR));
2660 WREG32(mmDMA0_QM_GLBL_ERR_WDATA + dma_qm_offset,
2661 gaudi_irq_map_table[GAUDI_EVENT_DMA0_QM].cpu_id +
2662 dma_id);
2663
2664 WREG32(mmDMA0_QM_ARB_ERR_MSG_EN + dma_qm_offset,
2665 QM_ARB_ERR_MSG_EN_MASK);
2666
2667 /* Increase ARB WDT to support streams architecture */
2668 WREG32(mmDMA0_QM_ARB_SLV_CHOISE_WDT + dma_qm_offset,
2669 GAUDI_ARB_WDT_TIMEOUT);
2670
2671 WREG32(mmDMA0_QM_GLBL_CFG1 + dma_qm_offset, 0);
2672 WREG32(mmDMA0_QM_GLBL_PROT + dma_qm_offset,
2673 QMAN_INTERNAL_MAKE_TRUSTED);
2674 }
2675
Ofir Bitton5de406c2020-09-10 10:56:26 +03002676 WREG32(mmDMA0_QM_CP_MSG_BASE0_ADDR_LO_0 + q_off, mtr_base_en_lo);
2677 WREG32(mmDMA0_QM_CP_MSG_BASE0_ADDR_HI_0 + q_off, mtr_base_en_hi);
2678 WREG32(mmDMA0_QM_CP_MSG_BASE1_ADDR_LO_0 + q_off, so_base_en_lo);
2679 WREG32(mmDMA0_QM_CP_MSG_BASE1_ADDR_HI_0 + q_off, so_base_en_hi);
2680
2681 /* Configure DMA5 CP_MSG_BASE 2/3 for sync stream collective */
2682 if (gaudi_dma_assignment[dma_id] == GAUDI_ENGINE_ID_DMA_5) {
2683 WREG32(mmDMA0_QM_CP_MSG_BASE2_ADDR_LO_0 + q_off,
2684 mtr_base_ws_lo);
2685 WREG32(mmDMA0_QM_CP_MSG_BASE2_ADDR_HI_0 + q_off,
2686 mtr_base_ws_hi);
2687 WREG32(mmDMA0_QM_CP_MSG_BASE3_ADDR_LO_0 + q_off,
2688 so_base_ws_lo);
2689 WREG32(mmDMA0_QM_CP_MSG_BASE3_ADDR_HI_0 + q_off,
2690 so_base_ws_hi);
2691 }
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03002692}
2693
2694static void gaudi_init_hbm_dma_qmans(struct hl_device *hdev)
2695{
2696 struct gaudi_device *gaudi = hdev->asic_specific;
2697 struct gaudi_internal_qman_info *q;
2698 u64 qman_base_addr;
2699 int i, j, dma_id, internal_q_index;
2700
2701 if (gaudi->hw_cap_initialized & HW_CAP_HBM_DMA)
2702 return;
2703
2704 for (i = 0 ; i < HBM_DMA_NUMBER_OF_CHNLS ; i++) {
2705 dma_id = gaudi_dma_assignment[GAUDI_HBM_DMA_1 + i];
2706
2707 for (j = 0 ; j < QMAN_STREAMS ; j++) {
2708 /*
2709 * Add the CPU queue in order to get the correct queue
2710 * number as all internal queue are placed after it
2711 */
2712 internal_q_index = dma_id * QMAN_STREAMS + j + 1;
2713
2714 q = &gaudi->internal_qmans[internal_q_index];
2715 qman_base_addr = (u64) q->pq_dma_addr;
2716 gaudi_init_hbm_dma_qman(hdev, dma_id, j,
2717 qman_base_addr);
2718 }
2719
2720 /* Initializing lower CP for HBM DMA QMAN */
2721 gaudi_init_hbm_dma_qman(hdev, dma_id, 4, 0);
2722
2723 gaudi_init_dma_core(hdev, dma_id);
2724
2725 gaudi_enable_qman(hdev, dma_id, HBM_DMA_QMAN_ENABLE);
2726 }
2727
2728 gaudi->hw_cap_initialized |= HW_CAP_HBM_DMA;
2729}
2730
2731static void gaudi_init_mme_qman(struct hl_device *hdev, u32 mme_offset,
2732 int qman_id, u64 qman_base_addr)
2733{
2734 u32 mtr_base_lo, mtr_base_hi;
2735 u32 so_base_lo, so_base_hi;
2736 u32 q_off, mme_id;
2737 u32 mme_qm_err_cfg;
2738
2739 mtr_base_lo = lower_32_bits(CFG_BASE +
2740 mmSYNC_MNGR_E_N_SYNC_MNGR_OBJS_MON_PAY_ADDRL_0);
2741 mtr_base_hi = upper_32_bits(CFG_BASE +
2742 mmSYNC_MNGR_E_N_SYNC_MNGR_OBJS_MON_PAY_ADDRL_0);
2743 so_base_lo = lower_32_bits(CFG_BASE +
2744 mmSYNC_MNGR_E_N_SYNC_MNGR_OBJS_SOB_OBJ_0);
2745 so_base_hi = upper_32_bits(CFG_BASE +
2746 mmSYNC_MNGR_E_N_SYNC_MNGR_OBJS_SOB_OBJ_0);
2747
2748 q_off = mme_offset + qman_id * 4;
2749
2750 if (qman_id < 4) {
2751 WREG32(mmMME0_QM_PQ_BASE_LO_0 + q_off,
2752 lower_32_bits(qman_base_addr));
2753 WREG32(mmMME0_QM_PQ_BASE_HI_0 + q_off,
2754 upper_32_bits(qman_base_addr));
2755
2756 WREG32(mmMME0_QM_PQ_SIZE_0 + q_off, ilog2(MME_QMAN_LENGTH));
2757 WREG32(mmMME0_QM_PQ_PI_0 + q_off, 0);
2758 WREG32(mmMME0_QM_PQ_CI_0 + q_off, 0);
2759
Ofir Bitton25121d92020-09-24 08:22:58 +03002760 WREG32(mmMME0_QM_CP_LDMA_TSIZE_OFFSET_0 + q_off,
2761 QMAN_CPDMA_SIZE_OFFSET);
2762 WREG32(mmMME0_QM_CP_LDMA_SRC_BASE_LO_OFFSET_0 + q_off,
2763 QMAN_CPDMA_SRC_OFFSET);
2764 WREG32(mmMME0_QM_CP_LDMA_DST_BASE_LO_OFFSET_0 + q_off,
2765 QMAN_CPDMA_DST_OFFSET);
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03002766 } else {
Ofir Bitton25121d92020-09-24 08:22:58 +03002767 WREG32(mmMME0_QM_CP_LDMA_TSIZE_OFFSET_0 + q_off,
2768 QMAN_LDMA_SIZE_OFFSET);
2769 WREG32(mmMME0_QM_CP_LDMA_SRC_BASE_LO_OFFSET_0 + q_off,
2770 QMAN_LDMA_SRC_OFFSET);
2771 WREG32(mmMME0_QM_CP_LDMA_DST_BASE_LO_OFFSET_0 + q_off,
2772 QMAN_LDMA_DST_OFFSET);
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03002773
2774 /* Configure RAZWI IRQ */
2775 mme_id = mme_offset /
2776 (mmMME1_QM_GLBL_CFG0 - mmMME0_QM_GLBL_CFG0);
2777
2778 mme_qm_err_cfg = MME_QMAN_GLBL_ERR_CFG_MSG_EN_MASK;
2779 if (hdev->stop_on_err) {
2780 mme_qm_err_cfg |=
2781 MME_QMAN_GLBL_ERR_CFG_STOP_ON_ERR_EN_MASK;
2782 }
2783 WREG32(mmMME0_QM_GLBL_ERR_CFG + mme_offset, mme_qm_err_cfg);
2784 WREG32(mmMME0_QM_GLBL_ERR_ADDR_LO + mme_offset,
2785 lower_32_bits(CFG_BASE +
2786 mmGIC_DISTRIBUTOR__5_GICD_SETSPI_NSR));
2787 WREG32(mmMME0_QM_GLBL_ERR_ADDR_HI + mme_offset,
2788 upper_32_bits(CFG_BASE +
2789 mmGIC_DISTRIBUTOR__5_GICD_SETSPI_NSR));
2790 WREG32(mmMME0_QM_GLBL_ERR_WDATA + mme_offset,
2791 gaudi_irq_map_table[GAUDI_EVENT_MME0_QM].cpu_id +
2792 mme_id);
2793
2794 WREG32(mmMME0_QM_ARB_ERR_MSG_EN + mme_offset,
2795 QM_ARB_ERR_MSG_EN_MASK);
2796
2797 /* Increase ARB WDT to support streams architecture */
2798 WREG32(mmMME0_QM_ARB_SLV_CHOISE_WDT + mme_offset,
2799 GAUDI_ARB_WDT_TIMEOUT);
2800
2801 WREG32(mmMME0_QM_GLBL_CFG1 + mme_offset, 0);
2802 WREG32(mmMME0_QM_GLBL_PROT + mme_offset,
2803 QMAN_INTERNAL_MAKE_TRUSTED);
2804 }
2805
2806 WREG32(mmMME0_QM_CP_MSG_BASE0_ADDR_LO_0 + q_off, mtr_base_lo);
2807 WREG32(mmMME0_QM_CP_MSG_BASE0_ADDR_HI_0 + q_off, mtr_base_hi);
2808 WREG32(mmMME0_QM_CP_MSG_BASE1_ADDR_LO_0 + q_off, so_base_lo);
2809 WREG32(mmMME0_QM_CP_MSG_BASE1_ADDR_HI_0 + q_off, so_base_hi);
2810}
2811
2812static void gaudi_init_mme_qmans(struct hl_device *hdev)
2813{
2814 struct gaudi_device *gaudi = hdev->asic_specific;
2815 struct gaudi_internal_qman_info *q;
2816 u64 qman_base_addr;
2817 u32 mme_offset;
2818 int i, internal_q_index;
2819
2820 if (gaudi->hw_cap_initialized & HW_CAP_MME)
2821 return;
2822
2823 /*
2824 * map GAUDI_QUEUE_ID_MME_0_X to the N_W_MME (mmMME2_QM_BASE)
2825 * and GAUDI_QUEUE_ID_MME_1_X to the S_W_MME (mmMME0_QM_BASE)
2826 */
2827
2828 mme_offset = mmMME2_QM_GLBL_CFG0 - mmMME0_QM_GLBL_CFG0;
2829
2830 for (i = 0 ; i < MME_NUMBER_OF_QMANS ; i++) {
2831 internal_q_index = GAUDI_QUEUE_ID_MME_0_0 + i;
2832 q = &gaudi->internal_qmans[internal_q_index];
2833 qman_base_addr = (u64) q->pq_dma_addr;
2834 gaudi_init_mme_qman(hdev, mme_offset, (i & 0x3),
2835 qman_base_addr);
2836 if (i == 3)
2837 mme_offset = 0;
2838 }
2839
2840 /* Initializing lower CP for MME QMANs */
2841 mme_offset = mmMME2_QM_GLBL_CFG0 - mmMME0_QM_GLBL_CFG0;
2842 gaudi_init_mme_qman(hdev, mme_offset, 4, 0);
2843 gaudi_init_mme_qman(hdev, 0, 4, 0);
2844
2845 WREG32(mmMME2_QM_GLBL_CFG0, QMAN_MME_ENABLE);
2846 WREG32(mmMME0_QM_GLBL_CFG0, QMAN_MME_ENABLE);
2847
2848 gaudi->hw_cap_initialized |= HW_CAP_MME;
2849}
2850
2851static void gaudi_init_tpc_qman(struct hl_device *hdev, u32 tpc_offset,
2852 int qman_id, u64 qman_base_addr)
2853{
Ofir Bitton5de406c2020-09-10 10:56:26 +03002854 u32 mtr_base_en_lo, mtr_base_en_hi, mtr_base_ws_lo, mtr_base_ws_hi;
2855 u32 so_base_en_lo, so_base_en_hi, so_base_ws_lo, so_base_ws_hi;
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03002856 u32 q_off, tpc_id;
2857 u32 tpc_qm_err_cfg;
2858
Ofir Bitton5de406c2020-09-10 10:56:26 +03002859 mtr_base_en_lo = lower_32_bits(CFG_BASE +
2860 mmSYNC_MNGR_E_N_SYNC_MNGR_OBJS_MON_PAY_ADDRL_0);
2861 mtr_base_en_hi = upper_32_bits(CFG_BASE +
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03002862 mmSYNC_MNGR_E_N_SYNC_MNGR_OBJS_MON_PAY_ADDRL_0);
Ofir Bitton5de406c2020-09-10 10:56:26 +03002863 so_base_en_lo = lower_32_bits(CFG_BASE +
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03002864 mmSYNC_MNGR_E_N_SYNC_MNGR_OBJS_SOB_OBJ_0);
Ofir Bitton5de406c2020-09-10 10:56:26 +03002865 so_base_en_hi = upper_32_bits(CFG_BASE +
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03002866 mmSYNC_MNGR_E_N_SYNC_MNGR_OBJS_SOB_OBJ_0);
Ofir Bitton5de406c2020-09-10 10:56:26 +03002867 mtr_base_ws_lo = lower_32_bits(CFG_BASE +
2868 mmSYNC_MNGR_W_S_SYNC_MNGR_OBJS_MON_PAY_ADDRL_0);
2869 mtr_base_ws_hi = upper_32_bits(CFG_BASE +
2870 mmSYNC_MNGR_W_S_SYNC_MNGR_OBJS_MON_PAY_ADDRL_0);
2871 so_base_ws_lo = lower_32_bits(CFG_BASE +
2872 mmSYNC_MNGR_W_S_SYNC_MNGR_OBJS_SOB_OBJ_0);
2873 so_base_ws_hi = upper_32_bits(CFG_BASE +
2874 mmSYNC_MNGR_W_S_SYNC_MNGR_OBJS_SOB_OBJ_0);
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03002875
2876 q_off = tpc_offset + qman_id * 4;
2877
Ofir Bitton5de406c2020-09-10 10:56:26 +03002878 tpc_id = tpc_offset /
2879 (mmTPC1_QM_GLBL_CFG0 - mmTPC0_QM_GLBL_CFG0);
2880
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03002881 if (qman_id < 4) {
2882 WREG32(mmTPC0_QM_PQ_BASE_LO_0 + q_off,
2883 lower_32_bits(qman_base_addr));
2884 WREG32(mmTPC0_QM_PQ_BASE_HI_0 + q_off,
2885 upper_32_bits(qman_base_addr));
2886
2887 WREG32(mmTPC0_QM_PQ_SIZE_0 + q_off, ilog2(TPC_QMAN_LENGTH));
2888 WREG32(mmTPC0_QM_PQ_PI_0 + q_off, 0);
2889 WREG32(mmTPC0_QM_PQ_CI_0 + q_off, 0);
2890
Ofir Bitton25121d92020-09-24 08:22:58 +03002891 WREG32(mmTPC0_QM_CP_LDMA_TSIZE_OFFSET_0 + q_off,
2892 QMAN_CPDMA_SIZE_OFFSET);
2893 WREG32(mmTPC0_QM_CP_LDMA_SRC_BASE_LO_OFFSET_0 + q_off,
2894 QMAN_CPDMA_SRC_OFFSET);
2895 WREG32(mmTPC0_QM_CP_LDMA_DST_BASE_LO_OFFSET_0 + q_off,
2896 QMAN_CPDMA_DST_OFFSET);
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03002897 } else {
Ofir Bitton25121d92020-09-24 08:22:58 +03002898 WREG32(mmTPC0_QM_CP_LDMA_TSIZE_OFFSET_0 + q_off,
2899 QMAN_LDMA_SIZE_OFFSET);
2900 WREG32(mmTPC0_QM_CP_LDMA_SRC_BASE_LO_OFFSET_0 + q_off,
2901 QMAN_LDMA_SRC_OFFSET);
2902 WREG32(mmTPC0_QM_CP_LDMA_DST_BASE_LO_OFFSET_0 + q_off,
2903 QMAN_LDMA_DST_OFFSET);
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03002904
2905 /* Configure RAZWI IRQ */
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03002906 tpc_qm_err_cfg = TPC_QMAN_GLBL_ERR_CFG_MSG_EN_MASK;
2907 if (hdev->stop_on_err) {
2908 tpc_qm_err_cfg |=
2909 TPC_QMAN_GLBL_ERR_CFG_STOP_ON_ERR_EN_MASK;
2910 }
2911
2912 WREG32(mmTPC0_QM_GLBL_ERR_CFG + tpc_offset, tpc_qm_err_cfg);
2913 WREG32(mmTPC0_QM_GLBL_ERR_ADDR_LO + tpc_offset,
2914 lower_32_bits(CFG_BASE +
2915 mmGIC_DISTRIBUTOR__5_GICD_SETSPI_NSR));
2916 WREG32(mmTPC0_QM_GLBL_ERR_ADDR_HI + tpc_offset,
2917 upper_32_bits(CFG_BASE +
2918 mmGIC_DISTRIBUTOR__5_GICD_SETSPI_NSR));
2919 WREG32(mmTPC0_QM_GLBL_ERR_WDATA + tpc_offset,
2920 gaudi_irq_map_table[GAUDI_EVENT_TPC0_QM].cpu_id +
2921 tpc_id);
2922
2923 WREG32(mmTPC0_QM_ARB_ERR_MSG_EN + tpc_offset,
2924 QM_ARB_ERR_MSG_EN_MASK);
2925
2926 /* Increase ARB WDT to support streams architecture */
2927 WREG32(mmTPC0_QM_ARB_SLV_CHOISE_WDT + tpc_offset,
2928 GAUDI_ARB_WDT_TIMEOUT);
2929
2930 WREG32(mmTPC0_QM_GLBL_CFG1 + tpc_offset, 0);
2931 WREG32(mmTPC0_QM_GLBL_PROT + tpc_offset,
2932 QMAN_INTERNAL_MAKE_TRUSTED);
2933 }
2934
Ofir Bitton5de406c2020-09-10 10:56:26 +03002935 WREG32(mmTPC0_QM_CP_MSG_BASE0_ADDR_LO_0 + q_off, mtr_base_en_lo);
2936 WREG32(mmTPC0_QM_CP_MSG_BASE0_ADDR_HI_0 + q_off, mtr_base_en_hi);
2937 WREG32(mmTPC0_QM_CP_MSG_BASE1_ADDR_LO_0 + q_off, so_base_en_lo);
2938 WREG32(mmTPC0_QM_CP_MSG_BASE1_ADDR_HI_0 + q_off, so_base_en_hi);
2939
2940 /* Configure TPC7 CP_MSG_BASE 2/3 for sync stream collective */
2941 if (tpc_id == 6) {
2942 WREG32(mmTPC0_QM_CP_MSG_BASE2_ADDR_LO_0 + q_off,
2943 mtr_base_ws_lo);
2944 WREG32(mmTPC0_QM_CP_MSG_BASE2_ADDR_HI_0 + q_off,
2945 mtr_base_ws_hi);
2946 WREG32(mmTPC0_QM_CP_MSG_BASE3_ADDR_LO_0 + q_off,
2947 so_base_ws_lo);
2948 WREG32(mmTPC0_QM_CP_MSG_BASE3_ADDR_HI_0 + q_off,
2949 so_base_ws_hi);
2950 }
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03002951}
2952
2953static void gaudi_init_tpc_qmans(struct hl_device *hdev)
2954{
2955 struct gaudi_device *gaudi = hdev->asic_specific;
2956 struct gaudi_internal_qman_info *q;
2957 u64 qman_base_addr;
2958 u32 so_base_hi, tpc_offset = 0;
2959 u32 tpc_delta = mmTPC1_CFG_SM_BASE_ADDRESS_HIGH -
2960 mmTPC0_CFG_SM_BASE_ADDRESS_HIGH;
2961 int i, tpc_id, internal_q_index;
2962
2963 if (gaudi->hw_cap_initialized & HW_CAP_TPC_MASK)
2964 return;
2965
2966 so_base_hi = upper_32_bits(CFG_BASE +
2967 mmSYNC_MNGR_E_N_SYNC_MNGR_OBJS_SOB_OBJ_0);
2968
2969 for (tpc_id = 0 ; tpc_id < TPC_NUMBER_OF_ENGINES ; tpc_id++) {
2970 for (i = 0 ; i < QMAN_STREAMS ; i++) {
2971 internal_q_index = GAUDI_QUEUE_ID_TPC_0_0 +
2972 tpc_id * QMAN_STREAMS + i;
2973 q = &gaudi->internal_qmans[internal_q_index];
2974 qman_base_addr = (u64) q->pq_dma_addr;
2975 gaudi_init_tpc_qman(hdev, tpc_offset, i,
2976 qman_base_addr);
2977
2978 if (i == 3) {
2979 /* Initializing lower CP for TPC QMAN */
2980 gaudi_init_tpc_qman(hdev, tpc_offset, 4, 0);
2981
2982 /* Enable the QMAN and TPC channel */
2983 WREG32(mmTPC0_QM_GLBL_CFG0 + tpc_offset,
2984 QMAN_TPC_ENABLE);
2985 }
2986 }
2987
2988 WREG32(mmTPC0_CFG_SM_BASE_ADDRESS_HIGH + tpc_id * tpc_delta,
2989 so_base_hi);
2990
2991 tpc_offset += mmTPC1_QM_GLBL_CFG0 - mmTPC0_QM_GLBL_CFG0;
2992
Oded Gabbay65887292020-08-12 11:21:01 +03002993 gaudi->hw_cap_initialized |=
2994 FIELD_PREP(HW_CAP_TPC_MASK, 1 << tpc_id);
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03002995 }
2996}
2997
Oded Gabbay3c681572020-11-02 21:10:39 +02002998static void gaudi_init_nic_qman(struct hl_device *hdev, u32 nic_offset,
2999 int qman_id, u64 qman_base_addr, int nic_id)
3000{
Ofir Bitton5de406c2020-09-10 10:56:26 +03003001 u32 mtr_base_en_lo, mtr_base_en_hi, mtr_base_ws_lo, mtr_base_ws_hi;
3002 u32 so_base_en_lo, so_base_en_hi, so_base_ws_lo, so_base_ws_hi;
Oded Gabbay3c681572020-11-02 21:10:39 +02003003 u32 q_off;
3004 u32 nic_qm_err_cfg;
3005
Ofir Bitton5de406c2020-09-10 10:56:26 +03003006 mtr_base_en_lo = lower_32_bits(CFG_BASE +
3007 mmSYNC_MNGR_E_N_SYNC_MNGR_OBJS_MON_PAY_ADDRL_0);
3008 mtr_base_en_hi = upper_32_bits(CFG_BASE +
Oded Gabbay3c681572020-11-02 21:10:39 +02003009 mmSYNC_MNGR_E_N_SYNC_MNGR_OBJS_MON_PAY_ADDRL_0);
Ofir Bitton5de406c2020-09-10 10:56:26 +03003010 so_base_en_lo = lower_32_bits(CFG_BASE +
Oded Gabbay3c681572020-11-02 21:10:39 +02003011 mmSYNC_MNGR_E_N_SYNC_MNGR_OBJS_SOB_OBJ_0);
Ofir Bitton5de406c2020-09-10 10:56:26 +03003012 so_base_en_hi = upper_32_bits(CFG_BASE +
Oded Gabbay3c681572020-11-02 21:10:39 +02003013 mmSYNC_MNGR_E_N_SYNC_MNGR_OBJS_SOB_OBJ_0);
Ofir Bitton5de406c2020-09-10 10:56:26 +03003014 mtr_base_ws_lo = lower_32_bits(CFG_BASE +
3015 mmSYNC_MNGR_W_S_SYNC_MNGR_OBJS_MON_PAY_ADDRL_0);
3016 mtr_base_ws_hi = upper_32_bits(CFG_BASE +
3017 mmSYNC_MNGR_W_S_SYNC_MNGR_OBJS_MON_PAY_ADDRL_0);
3018 so_base_ws_lo = lower_32_bits(CFG_BASE +
3019 mmSYNC_MNGR_W_S_SYNC_MNGR_OBJS_SOB_OBJ_0);
3020 so_base_ws_hi = upper_32_bits(CFG_BASE +
3021 mmSYNC_MNGR_W_S_SYNC_MNGR_OBJS_SOB_OBJ_0);
Oded Gabbay3c681572020-11-02 21:10:39 +02003022
3023 q_off = nic_offset + qman_id * 4;
3024
3025 WREG32(mmNIC0_QM0_PQ_BASE_LO_0 + q_off, lower_32_bits(qman_base_addr));
3026 WREG32(mmNIC0_QM0_PQ_BASE_HI_0 + q_off, upper_32_bits(qman_base_addr));
3027
3028 WREG32(mmNIC0_QM0_PQ_SIZE_0 + q_off, ilog2(NIC_QMAN_LENGTH));
3029 WREG32(mmNIC0_QM0_PQ_PI_0 + q_off, 0);
3030 WREG32(mmNIC0_QM0_PQ_CI_0 + q_off, 0);
3031
Ofir Bitton5de406c2020-09-10 10:56:26 +03003032 WREG32(mmNIC0_QM0_CP_LDMA_TSIZE_OFFSET_0 + q_off,
3033 QMAN_LDMA_SIZE_OFFSET);
3034 WREG32(mmNIC0_QM0_CP_LDMA_SRC_BASE_LO_OFFSET_0 + q_off,
3035 QMAN_LDMA_SRC_OFFSET);
3036 WREG32(mmNIC0_QM0_CP_LDMA_DST_BASE_LO_OFFSET_0 + q_off,
3037 QMAN_LDMA_DST_OFFSET);
Oded Gabbay3c681572020-11-02 21:10:39 +02003038
Ofir Bitton5de406c2020-09-10 10:56:26 +03003039 WREG32(mmNIC0_QM0_CP_MSG_BASE0_ADDR_LO_0 + q_off, mtr_base_en_lo);
3040 WREG32(mmNIC0_QM0_CP_MSG_BASE0_ADDR_HI_0 + q_off, mtr_base_en_hi);
3041 WREG32(mmNIC0_QM0_CP_MSG_BASE1_ADDR_LO_0 + q_off, so_base_en_lo);
3042 WREG32(mmNIC0_QM0_CP_MSG_BASE1_ADDR_HI_0 + q_off, so_base_en_hi);
3043
3044 /* Configure NIC CP_MSG_BASE 2/3 for sync stream collective */
3045 WREG32(mmNIC0_QM0_CP_MSG_BASE2_ADDR_LO_0 + q_off, mtr_base_ws_lo);
3046 WREG32(mmNIC0_QM0_CP_MSG_BASE2_ADDR_HI_0 + q_off, mtr_base_ws_hi);
3047 WREG32(mmNIC0_QM0_CP_MSG_BASE3_ADDR_LO_0 + q_off, so_base_ws_lo);
3048 WREG32(mmNIC0_QM0_CP_MSG_BASE3_ADDR_HI_0 + q_off, so_base_ws_hi);
Oded Gabbay3c681572020-11-02 21:10:39 +02003049
3050 if (qman_id == 0) {
3051 /* Configure RAZWI IRQ */
3052 nic_qm_err_cfg = NIC_QMAN_GLBL_ERR_CFG_MSG_EN_MASK;
3053 if (hdev->stop_on_err) {
3054 nic_qm_err_cfg |=
3055 NIC_QMAN_GLBL_ERR_CFG_STOP_ON_ERR_EN_MASK;
3056 }
3057
3058 WREG32(mmNIC0_QM0_GLBL_ERR_CFG + nic_offset, nic_qm_err_cfg);
3059 WREG32(mmNIC0_QM0_GLBL_ERR_ADDR_LO + nic_offset,
3060 lower_32_bits(CFG_BASE +
3061 mmGIC_DISTRIBUTOR__5_GICD_SETSPI_NSR));
3062 WREG32(mmNIC0_QM0_GLBL_ERR_ADDR_HI + nic_offset,
3063 upper_32_bits(CFG_BASE +
3064 mmGIC_DISTRIBUTOR__5_GICD_SETSPI_NSR));
3065 WREG32(mmNIC0_QM0_GLBL_ERR_WDATA + nic_offset,
3066 gaudi_irq_map_table[GAUDI_EVENT_NIC0_QM0].cpu_id +
3067 nic_id);
3068
3069 WREG32(mmNIC0_QM0_ARB_ERR_MSG_EN + nic_offset,
3070 QM_ARB_ERR_MSG_EN_MASK);
3071
3072 /* Increase ARB WDT to support streams architecture */
3073 WREG32(mmNIC0_QM0_ARB_SLV_CHOISE_WDT + nic_offset,
3074 GAUDI_ARB_WDT_TIMEOUT);
3075
3076 WREG32(mmNIC0_QM0_GLBL_CFG1 + nic_offset, 0);
3077 WREG32(mmNIC0_QM0_GLBL_PROT + nic_offset,
3078 QMAN_INTERNAL_MAKE_TRUSTED);
3079 }
3080}
3081
3082static void gaudi_init_nic_qmans(struct hl_device *hdev)
3083{
3084 struct gaudi_device *gaudi = hdev->asic_specific;
3085 struct gaudi_internal_qman_info *q;
3086 u64 qman_base_addr;
3087 u32 nic_offset = 0;
3088 u32 nic_delta_between_qmans =
3089 mmNIC0_QM1_GLBL_CFG0 - mmNIC0_QM0_GLBL_CFG0;
3090 u32 nic_delta_between_nics =
3091 mmNIC1_QM0_GLBL_CFG0 - mmNIC0_QM0_GLBL_CFG0;
3092 int i, nic_id, internal_q_index;
3093
3094 if (!hdev->nic_ports_mask)
3095 return;
3096
3097 if (gaudi->hw_cap_initialized & HW_CAP_NIC_MASK)
3098 return;
3099
3100 dev_dbg(hdev->dev, "Initializing NIC QMANs\n");
3101
3102 for (nic_id = 0 ; nic_id < NIC_NUMBER_OF_ENGINES ; nic_id++) {
3103 if (!(hdev->nic_ports_mask & (1 << nic_id))) {
3104 nic_offset += nic_delta_between_qmans;
3105 if (nic_id & 1) {
3106 nic_offset -= (nic_delta_between_qmans * 2);
3107 nic_offset += nic_delta_between_nics;
3108 }
3109 continue;
3110 }
3111
3112 for (i = 0 ; i < QMAN_STREAMS ; i++) {
3113 internal_q_index = GAUDI_QUEUE_ID_NIC_0_0 +
3114 nic_id * QMAN_STREAMS + i;
3115 q = &gaudi->internal_qmans[internal_q_index];
3116 qman_base_addr = (u64) q->pq_dma_addr;
3117 gaudi_init_nic_qman(hdev, nic_offset, (i & 0x3),
3118 qman_base_addr, nic_id);
3119 }
3120
3121 /* Enable the QMAN */
3122 WREG32(mmNIC0_QM0_GLBL_CFG0 + nic_offset, NIC_QMAN_ENABLE);
3123
3124 nic_offset += nic_delta_between_qmans;
3125 if (nic_id & 1) {
3126 nic_offset -= (nic_delta_between_qmans * 2);
3127 nic_offset += nic_delta_between_nics;
3128 }
3129
3130 gaudi->hw_cap_initialized |= 1 << (HW_CAP_NIC_SHIFT + nic_id);
3131 }
3132}
3133
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03003134static void gaudi_disable_pci_dma_qmans(struct hl_device *hdev)
3135{
3136 struct gaudi_device *gaudi = hdev->asic_specific;
3137
3138 if (!(gaudi->hw_cap_initialized & HW_CAP_PCI_DMA))
3139 return;
3140
3141 WREG32(mmDMA0_QM_GLBL_CFG0, 0);
3142 WREG32(mmDMA1_QM_GLBL_CFG0, 0);
3143 WREG32(mmDMA5_QM_GLBL_CFG0, 0);
3144}
3145
3146static void gaudi_disable_hbm_dma_qmans(struct hl_device *hdev)
3147{
3148 struct gaudi_device *gaudi = hdev->asic_specific;
3149
3150 if (!(gaudi->hw_cap_initialized & HW_CAP_HBM_DMA))
3151 return;
3152
3153 WREG32(mmDMA2_QM_GLBL_CFG0, 0);
3154 WREG32(mmDMA3_QM_GLBL_CFG0, 0);
3155 WREG32(mmDMA4_QM_GLBL_CFG0, 0);
3156 WREG32(mmDMA6_QM_GLBL_CFG0, 0);
3157 WREG32(mmDMA7_QM_GLBL_CFG0, 0);
3158}
3159
3160static void gaudi_disable_mme_qmans(struct hl_device *hdev)
3161{
3162 struct gaudi_device *gaudi = hdev->asic_specific;
3163
3164 if (!(gaudi->hw_cap_initialized & HW_CAP_MME))
3165 return;
3166
3167 WREG32(mmMME2_QM_GLBL_CFG0, 0);
3168 WREG32(mmMME0_QM_GLBL_CFG0, 0);
3169}
3170
3171static void gaudi_disable_tpc_qmans(struct hl_device *hdev)
3172{
3173 struct gaudi_device *gaudi = hdev->asic_specific;
3174 u32 tpc_offset = 0;
3175 int tpc_id;
3176
3177 if (!(gaudi->hw_cap_initialized & HW_CAP_TPC_MASK))
3178 return;
3179
3180 for (tpc_id = 0 ; tpc_id < TPC_NUMBER_OF_ENGINES ; tpc_id++) {
3181 WREG32(mmTPC0_QM_GLBL_CFG0 + tpc_offset, 0);
3182 tpc_offset += mmTPC1_QM_GLBL_CFG0 - mmTPC0_QM_GLBL_CFG0;
3183 }
3184}
3185
Oded Gabbay3c681572020-11-02 21:10:39 +02003186static void gaudi_disable_nic_qmans(struct hl_device *hdev)
3187{
3188 struct gaudi_device *gaudi = hdev->asic_specific;
3189 u32 nic_mask, nic_offset = 0;
3190 u32 nic_delta_between_qmans =
3191 mmNIC0_QM1_GLBL_CFG0 - mmNIC0_QM0_GLBL_CFG0;
3192 u32 nic_delta_between_nics =
3193 mmNIC1_QM0_GLBL_CFG0 - mmNIC0_QM0_GLBL_CFG0;
3194 int nic_id;
3195
3196 for (nic_id = 0 ; nic_id < NIC_NUMBER_OF_ENGINES ; nic_id++) {
3197 nic_mask = 1 << (HW_CAP_NIC_SHIFT + nic_id);
3198
3199 if (gaudi->hw_cap_initialized & nic_mask)
3200 WREG32(mmNIC0_QM0_GLBL_CFG0 + nic_offset, 0);
3201
3202 nic_offset += nic_delta_between_qmans;
3203 if (nic_id & 1) {
3204 nic_offset -= (nic_delta_between_qmans * 2);
3205 nic_offset += nic_delta_between_nics;
3206 }
3207 }
3208}
3209
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03003210static void gaudi_stop_pci_dma_qmans(struct hl_device *hdev)
3211{
3212 struct gaudi_device *gaudi = hdev->asic_specific;
3213
3214 if (!(gaudi->hw_cap_initialized & HW_CAP_PCI_DMA))
3215 return;
3216
3217 /* Stop upper CPs of QMANs 0.0 to 1.3 and 5.0 to 5.3 */
3218 WREG32(mmDMA0_QM_GLBL_CFG1, 0xF << DMA0_QM_GLBL_CFG1_CP_STOP_SHIFT);
3219 WREG32(mmDMA1_QM_GLBL_CFG1, 0xF << DMA0_QM_GLBL_CFG1_CP_STOP_SHIFT);
3220 WREG32(mmDMA5_QM_GLBL_CFG1, 0xF << DMA0_QM_GLBL_CFG1_CP_STOP_SHIFT);
3221}
3222
3223static void gaudi_stop_hbm_dma_qmans(struct hl_device *hdev)
3224{
3225 struct gaudi_device *gaudi = hdev->asic_specific;
3226
3227 if (!(gaudi->hw_cap_initialized & HW_CAP_HBM_DMA))
3228 return;
3229
3230 /* Stop CPs of HBM DMA QMANs */
3231
3232 WREG32(mmDMA2_QM_GLBL_CFG1, 0x1F << DMA0_QM_GLBL_CFG1_CP_STOP_SHIFT);
3233 WREG32(mmDMA3_QM_GLBL_CFG1, 0x1F << DMA0_QM_GLBL_CFG1_CP_STOP_SHIFT);
3234 WREG32(mmDMA4_QM_GLBL_CFG1, 0x1F << DMA0_QM_GLBL_CFG1_CP_STOP_SHIFT);
3235 WREG32(mmDMA6_QM_GLBL_CFG1, 0x1F << DMA0_QM_GLBL_CFG1_CP_STOP_SHIFT);
3236 WREG32(mmDMA7_QM_GLBL_CFG1, 0x1F << DMA0_QM_GLBL_CFG1_CP_STOP_SHIFT);
3237}
3238
3239static void gaudi_stop_mme_qmans(struct hl_device *hdev)
3240{
3241 struct gaudi_device *gaudi = hdev->asic_specific;
3242
3243 if (!(gaudi->hw_cap_initialized & HW_CAP_MME))
3244 return;
3245
3246 /* Stop CPs of MME QMANs */
3247 WREG32(mmMME2_QM_GLBL_CFG1, 0x1F << MME0_QM_GLBL_CFG1_CP_STOP_SHIFT);
3248 WREG32(mmMME0_QM_GLBL_CFG1, 0x1F << MME0_QM_GLBL_CFG1_CP_STOP_SHIFT);
3249}
3250
3251static void gaudi_stop_tpc_qmans(struct hl_device *hdev)
3252{
3253 struct gaudi_device *gaudi = hdev->asic_specific;
3254
3255 if (!(gaudi->hw_cap_initialized & HW_CAP_TPC_MASK))
3256 return;
3257
3258 WREG32(mmTPC0_QM_GLBL_CFG1, 0x1F << TPC0_QM_GLBL_CFG1_CP_STOP_SHIFT);
3259 WREG32(mmTPC1_QM_GLBL_CFG1, 0x1F << TPC0_QM_GLBL_CFG1_CP_STOP_SHIFT);
3260 WREG32(mmTPC2_QM_GLBL_CFG1, 0x1F << TPC0_QM_GLBL_CFG1_CP_STOP_SHIFT);
3261 WREG32(mmTPC3_QM_GLBL_CFG1, 0x1F << TPC0_QM_GLBL_CFG1_CP_STOP_SHIFT);
3262 WREG32(mmTPC4_QM_GLBL_CFG1, 0x1F << TPC0_QM_GLBL_CFG1_CP_STOP_SHIFT);
3263 WREG32(mmTPC5_QM_GLBL_CFG1, 0x1F << TPC0_QM_GLBL_CFG1_CP_STOP_SHIFT);
3264 WREG32(mmTPC6_QM_GLBL_CFG1, 0x1F << TPC0_QM_GLBL_CFG1_CP_STOP_SHIFT);
3265 WREG32(mmTPC7_QM_GLBL_CFG1, 0x1F << TPC0_QM_GLBL_CFG1_CP_STOP_SHIFT);
3266}
3267
Oded Gabbay3c681572020-11-02 21:10:39 +02003268static void gaudi_stop_nic_qmans(struct hl_device *hdev)
3269{
3270 struct gaudi_device *gaudi = hdev->asic_specific;
3271
3272 /* Stop upper CPs of QMANs */
3273
3274 if (gaudi->hw_cap_initialized & HW_CAP_NIC0)
3275 WREG32(mmNIC0_QM0_GLBL_CFG1,
3276 NIC0_QM0_GLBL_CFG1_PQF_STOP_MASK |
3277 NIC0_QM0_GLBL_CFG1_CQF_STOP_MASK |
3278 NIC0_QM0_GLBL_CFG1_CP_STOP_MASK);
3279
3280 if (gaudi->hw_cap_initialized & HW_CAP_NIC1)
3281 WREG32(mmNIC0_QM1_GLBL_CFG1,
3282 NIC0_QM0_GLBL_CFG1_PQF_STOP_MASK |
3283 NIC0_QM0_GLBL_CFG1_CQF_STOP_MASK |
3284 NIC0_QM0_GLBL_CFG1_CP_STOP_MASK);
3285
3286 if (gaudi->hw_cap_initialized & HW_CAP_NIC2)
3287 WREG32(mmNIC1_QM0_GLBL_CFG1,
3288 NIC0_QM0_GLBL_CFG1_PQF_STOP_MASK |
3289 NIC0_QM0_GLBL_CFG1_CQF_STOP_MASK |
3290 NIC0_QM0_GLBL_CFG1_CP_STOP_MASK);
3291
3292 if (gaudi->hw_cap_initialized & HW_CAP_NIC3)
3293 WREG32(mmNIC1_QM1_GLBL_CFG1,
3294 NIC0_QM0_GLBL_CFG1_PQF_STOP_MASK |
3295 NIC0_QM0_GLBL_CFG1_CQF_STOP_MASK |
3296 NIC0_QM0_GLBL_CFG1_CP_STOP_MASK);
3297
3298 if (gaudi->hw_cap_initialized & HW_CAP_NIC4)
3299 WREG32(mmNIC2_QM0_GLBL_CFG1,
3300 NIC0_QM0_GLBL_CFG1_PQF_STOP_MASK |
3301 NIC0_QM0_GLBL_CFG1_CQF_STOP_MASK |
3302 NIC0_QM0_GLBL_CFG1_CP_STOP_MASK);
3303
3304 if (gaudi->hw_cap_initialized & HW_CAP_NIC5)
3305 WREG32(mmNIC2_QM1_GLBL_CFG1,
3306 NIC0_QM0_GLBL_CFG1_PQF_STOP_MASK |
3307 NIC0_QM0_GLBL_CFG1_CQF_STOP_MASK |
3308 NIC0_QM0_GLBL_CFG1_CP_STOP_MASK);
3309
3310 if (gaudi->hw_cap_initialized & HW_CAP_NIC6)
3311 WREG32(mmNIC3_QM0_GLBL_CFG1,
3312 NIC0_QM0_GLBL_CFG1_PQF_STOP_MASK |
3313 NIC0_QM0_GLBL_CFG1_CQF_STOP_MASK |
3314 NIC0_QM0_GLBL_CFG1_CP_STOP_MASK);
3315
3316 if (gaudi->hw_cap_initialized & HW_CAP_NIC7)
3317 WREG32(mmNIC3_QM1_GLBL_CFG1,
3318 NIC0_QM0_GLBL_CFG1_PQF_STOP_MASK |
3319 NIC0_QM0_GLBL_CFG1_CQF_STOP_MASK |
3320 NIC0_QM0_GLBL_CFG1_CP_STOP_MASK);
3321
3322 if (gaudi->hw_cap_initialized & HW_CAP_NIC8)
3323 WREG32(mmNIC4_QM0_GLBL_CFG1,
3324 NIC0_QM0_GLBL_CFG1_PQF_STOP_MASK |
3325 NIC0_QM0_GLBL_CFG1_CQF_STOP_MASK |
3326 NIC0_QM0_GLBL_CFG1_CP_STOP_MASK);
3327
3328 if (gaudi->hw_cap_initialized & HW_CAP_NIC9)
3329 WREG32(mmNIC4_QM1_GLBL_CFG1,
3330 NIC0_QM0_GLBL_CFG1_PQF_STOP_MASK |
3331 NIC0_QM0_GLBL_CFG1_CQF_STOP_MASK |
3332 NIC0_QM0_GLBL_CFG1_CP_STOP_MASK);
3333}
3334
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03003335static void gaudi_pci_dma_stall(struct hl_device *hdev)
3336{
3337 struct gaudi_device *gaudi = hdev->asic_specific;
3338
3339 if (!(gaudi->hw_cap_initialized & HW_CAP_PCI_DMA))
3340 return;
3341
3342 WREG32(mmDMA0_CORE_CFG_1, 1 << DMA0_CORE_CFG_1_HALT_SHIFT);
3343 WREG32(mmDMA1_CORE_CFG_1, 1 << DMA0_CORE_CFG_1_HALT_SHIFT);
3344 WREG32(mmDMA5_CORE_CFG_1, 1 << DMA0_CORE_CFG_1_HALT_SHIFT);
3345}
3346
3347static void gaudi_hbm_dma_stall(struct hl_device *hdev)
3348{
3349 struct gaudi_device *gaudi = hdev->asic_specific;
3350
3351 if (!(gaudi->hw_cap_initialized & HW_CAP_HBM_DMA))
3352 return;
3353
3354 WREG32(mmDMA2_CORE_CFG_1, 1 << DMA0_CORE_CFG_1_HALT_SHIFT);
3355 WREG32(mmDMA3_CORE_CFG_1, 1 << DMA0_CORE_CFG_1_HALT_SHIFT);
3356 WREG32(mmDMA4_CORE_CFG_1, 1 << DMA0_CORE_CFG_1_HALT_SHIFT);
3357 WREG32(mmDMA6_CORE_CFG_1, 1 << DMA0_CORE_CFG_1_HALT_SHIFT);
3358 WREG32(mmDMA7_CORE_CFG_1, 1 << DMA0_CORE_CFG_1_HALT_SHIFT);
3359}
3360
3361static void gaudi_mme_stall(struct hl_device *hdev)
3362{
3363 struct gaudi_device *gaudi = hdev->asic_specific;
3364
3365 if (!(gaudi->hw_cap_initialized & HW_CAP_MME))
3366 return;
3367
3368 /* WA for H3-1800 bug: do ACC and SBAB writes twice */
3369 WREG32(mmMME0_ACC_ACC_STALL, 1 << MME_ACC_ACC_STALL_R_SHIFT);
3370 WREG32(mmMME0_ACC_ACC_STALL, 1 << MME_ACC_ACC_STALL_R_SHIFT);
3371 WREG32(mmMME0_SBAB_SB_STALL, 1 << MME_SBAB_SB_STALL_R_SHIFT);
3372 WREG32(mmMME0_SBAB_SB_STALL, 1 << MME_SBAB_SB_STALL_R_SHIFT);
3373 WREG32(mmMME1_ACC_ACC_STALL, 1 << MME_ACC_ACC_STALL_R_SHIFT);
3374 WREG32(mmMME1_ACC_ACC_STALL, 1 << MME_ACC_ACC_STALL_R_SHIFT);
3375 WREG32(mmMME1_SBAB_SB_STALL, 1 << MME_SBAB_SB_STALL_R_SHIFT);
3376 WREG32(mmMME1_SBAB_SB_STALL, 1 << MME_SBAB_SB_STALL_R_SHIFT);
3377 WREG32(mmMME2_ACC_ACC_STALL, 1 << MME_ACC_ACC_STALL_R_SHIFT);
3378 WREG32(mmMME2_ACC_ACC_STALL, 1 << MME_ACC_ACC_STALL_R_SHIFT);
3379 WREG32(mmMME2_SBAB_SB_STALL, 1 << MME_SBAB_SB_STALL_R_SHIFT);
3380 WREG32(mmMME2_SBAB_SB_STALL, 1 << MME_SBAB_SB_STALL_R_SHIFT);
3381 WREG32(mmMME3_ACC_ACC_STALL, 1 << MME_ACC_ACC_STALL_R_SHIFT);
3382 WREG32(mmMME3_ACC_ACC_STALL, 1 << MME_ACC_ACC_STALL_R_SHIFT);
3383 WREG32(mmMME3_SBAB_SB_STALL, 1 << MME_SBAB_SB_STALL_R_SHIFT);
3384 WREG32(mmMME3_SBAB_SB_STALL, 1 << MME_SBAB_SB_STALL_R_SHIFT);
3385}
3386
3387static void gaudi_tpc_stall(struct hl_device *hdev)
3388{
3389 struct gaudi_device *gaudi = hdev->asic_specific;
3390
3391 if (!(gaudi->hw_cap_initialized & HW_CAP_TPC_MASK))
3392 return;
3393
3394 WREG32(mmTPC0_CFG_TPC_STALL, 1 << TPC0_CFG_TPC_STALL_V_SHIFT);
3395 WREG32(mmTPC1_CFG_TPC_STALL, 1 << TPC0_CFG_TPC_STALL_V_SHIFT);
3396 WREG32(mmTPC2_CFG_TPC_STALL, 1 << TPC0_CFG_TPC_STALL_V_SHIFT);
3397 WREG32(mmTPC3_CFG_TPC_STALL, 1 << TPC0_CFG_TPC_STALL_V_SHIFT);
3398 WREG32(mmTPC4_CFG_TPC_STALL, 1 << TPC0_CFG_TPC_STALL_V_SHIFT);
3399 WREG32(mmTPC5_CFG_TPC_STALL, 1 << TPC0_CFG_TPC_STALL_V_SHIFT);
3400 WREG32(mmTPC6_CFG_TPC_STALL, 1 << TPC0_CFG_TPC_STALL_V_SHIFT);
3401 WREG32(mmTPC7_CFG_TPC_STALL, 1 << TPC0_CFG_TPC_STALL_V_SHIFT);
3402}
3403
Oded Gabbaye38bfd32020-07-03 20:46:12 +03003404static void gaudi_set_clock_gating(struct hl_device *hdev)
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03003405{
3406 struct gaudi_device *gaudi = hdev->asic_specific;
3407 u32 qman_offset;
Ofir Bittonf44d23b2020-08-04 13:38:43 +03003408 bool enable;
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03003409 int i;
3410
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03003411 /* In case we are during debug session, don't enable the clock gate
3412 * as it may interfere
3413 */
3414 if (hdev->in_debug)
3415 return;
3416
Oded Gabbay0024c0942020-12-05 22:55:09 +02003417 if (!hdev->asic_prop.fw_security_disabled)
3418 return;
3419
Oded Gabbaye38bfd32020-07-03 20:46:12 +03003420 for (i = GAUDI_PCI_DMA_1, qman_offset = 0 ; i < GAUDI_HBM_DMA_1 ; i++) {
Ofir Bittonf44d23b2020-08-04 13:38:43 +03003421 enable = !!(hdev->clock_gating_mask &
3422 (BIT_ULL(gaudi_dma_assignment[i])));
Oded Gabbaye38bfd32020-07-03 20:46:12 +03003423
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03003424 qman_offset = gaudi_dma_assignment[i] * DMA_QMAN_OFFSET;
Ofir Bittonf44d23b2020-08-04 13:38:43 +03003425 WREG32(mmDMA0_QM_CGM_CFG1 + qman_offset,
3426 enable ? QMAN_CGM1_PWR_GATE_EN : 0);
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03003427 WREG32(mmDMA0_QM_CGM_CFG + qman_offset,
Ofir Bittonf44d23b2020-08-04 13:38:43 +03003428 enable ? QMAN_UPPER_CP_CGM_PWR_GATE_EN : 0);
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03003429 }
3430
Oded Gabbaye38bfd32020-07-03 20:46:12 +03003431 for (i = GAUDI_HBM_DMA_1 ; i < GAUDI_DMA_MAX ; i++) {
Ofir Bittonf44d23b2020-08-04 13:38:43 +03003432 enable = !!(hdev->clock_gating_mask &
3433 (BIT_ULL(gaudi_dma_assignment[i])));
Oded Gabbaye38bfd32020-07-03 20:46:12 +03003434
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03003435 qman_offset = gaudi_dma_assignment[i] * DMA_QMAN_OFFSET;
Ofir Bittonf44d23b2020-08-04 13:38:43 +03003436 WREG32(mmDMA0_QM_CGM_CFG1 + qman_offset,
3437 enable ? QMAN_CGM1_PWR_GATE_EN : 0);
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03003438 WREG32(mmDMA0_QM_CGM_CFG + qman_offset,
Ofir Bittonf44d23b2020-08-04 13:38:43 +03003439 enable ? QMAN_COMMON_CP_CGM_PWR_GATE_EN : 0);
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03003440 }
3441
Ofir Bittonf44d23b2020-08-04 13:38:43 +03003442 enable = !!(hdev->clock_gating_mask & (BIT_ULL(GAUDI_ENGINE_ID_MME_0)));
3443 WREG32(mmMME0_QM_CGM_CFG1, enable ? QMAN_CGM1_PWR_GATE_EN : 0);
3444 WREG32(mmMME0_QM_CGM_CFG, enable ? QMAN_COMMON_CP_CGM_PWR_GATE_EN : 0);
Oded Gabbaye38bfd32020-07-03 20:46:12 +03003445
Ofir Bittonf44d23b2020-08-04 13:38:43 +03003446 enable = !!(hdev->clock_gating_mask & (BIT_ULL(GAUDI_ENGINE_ID_MME_2)));
3447 WREG32(mmMME2_QM_CGM_CFG1, enable ? QMAN_CGM1_PWR_GATE_EN : 0);
3448 WREG32(mmMME2_QM_CGM_CFG, enable ? QMAN_COMMON_CP_CGM_PWR_GATE_EN : 0);
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03003449
3450 for (i = 0, qman_offset = 0 ; i < TPC_NUMBER_OF_ENGINES ; i++) {
Ofir Bittonf44d23b2020-08-04 13:38:43 +03003451 enable = !!(hdev->clock_gating_mask &
3452 (BIT_ULL(GAUDI_ENGINE_ID_TPC_0 + i)));
Oded Gabbaye38bfd32020-07-03 20:46:12 +03003453
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03003454 WREG32(mmTPC0_QM_CGM_CFG1 + qman_offset,
Ofir Bittonf44d23b2020-08-04 13:38:43 +03003455 enable ? QMAN_CGM1_PWR_GATE_EN : 0);
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03003456 WREG32(mmTPC0_QM_CGM_CFG + qman_offset,
Ofir Bittonf44d23b2020-08-04 13:38:43 +03003457 enable ? QMAN_COMMON_CP_CGM_PWR_GATE_EN : 0);
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03003458
3459 qman_offset += TPC_QMAN_OFFSET;
3460 }
3461
3462 gaudi->hw_cap_initialized |= HW_CAP_CLK_GATE;
3463}
3464
3465static void gaudi_disable_clock_gating(struct hl_device *hdev)
3466{
3467 struct gaudi_device *gaudi = hdev->asic_specific;
3468 u32 qman_offset;
3469 int i;
3470
Oded Gabbay0024c0942020-12-05 22:55:09 +02003471 if (!hdev->asic_prop.fw_security_disabled)
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03003472 return;
3473
3474 for (i = 0, qman_offset = 0 ; i < DMA_NUMBER_OF_CHANNELS ; i++) {
3475 WREG32(mmDMA0_QM_CGM_CFG + qman_offset, 0);
3476 WREG32(mmDMA0_QM_CGM_CFG1 + qman_offset, 0);
3477
3478 qman_offset += (mmDMA1_QM_CGM_CFG - mmDMA0_QM_CGM_CFG);
3479 }
3480
3481 WREG32(mmMME0_QM_CGM_CFG, 0);
3482 WREG32(mmMME0_QM_CGM_CFG1, 0);
3483 WREG32(mmMME2_QM_CGM_CFG, 0);
3484 WREG32(mmMME2_QM_CGM_CFG1, 0);
3485
3486 for (i = 0, qman_offset = 0 ; i < TPC_NUMBER_OF_ENGINES ; i++) {
3487 WREG32(mmTPC0_QM_CGM_CFG + qman_offset, 0);
3488 WREG32(mmTPC0_QM_CGM_CFG1 + qman_offset, 0);
3489
3490 qman_offset += (mmTPC1_QM_CGM_CFG - mmTPC0_QM_CGM_CFG);
3491 }
3492
3493 gaudi->hw_cap_initialized &= ~(HW_CAP_CLK_GATE);
3494}
3495
3496static void gaudi_enable_timestamp(struct hl_device *hdev)
3497{
3498 /* Disable the timestamp counter */
3499 WREG32(mmPSOC_TIMESTAMP_BASE - CFG_BASE, 0);
3500
3501 /* Zero the lower/upper parts of the 64-bit counter */
3502 WREG32(mmPSOC_TIMESTAMP_BASE - CFG_BASE + 0xC, 0);
3503 WREG32(mmPSOC_TIMESTAMP_BASE - CFG_BASE + 0x8, 0);
3504
3505 /* Enable the counter */
3506 WREG32(mmPSOC_TIMESTAMP_BASE - CFG_BASE, 1);
3507}
3508
3509static void gaudi_disable_timestamp(struct hl_device *hdev)
3510{
3511 /* Disable the timestamp counter */
3512 WREG32(mmPSOC_TIMESTAMP_BASE - CFG_BASE, 0);
3513}
3514
3515static void gaudi_halt_engines(struct hl_device *hdev, bool hard_reset)
3516{
Oded Gabbayc83c4172020-07-05 15:48:34 +03003517 u32 wait_timeout_ms;
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03003518
3519 dev_info(hdev->dev,
3520 "Halting compute engines and disabling interrupts\n");
3521
Oded Gabbayc83c4172020-07-05 15:48:34 +03003522 if (hdev->pldm)
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03003523 wait_timeout_ms = GAUDI_PLDM_RESET_WAIT_MSEC;
Oded Gabbayc83c4172020-07-05 15:48:34 +03003524 else
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03003525 wait_timeout_ms = GAUDI_RESET_WAIT_MSEC;
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03003526
Oded Gabbay3c681572020-11-02 21:10:39 +02003527 gaudi_stop_nic_qmans(hdev);
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03003528 gaudi_stop_mme_qmans(hdev);
3529 gaudi_stop_tpc_qmans(hdev);
3530 gaudi_stop_hbm_dma_qmans(hdev);
3531 gaudi_stop_pci_dma_qmans(hdev);
3532
Oded Gabbaye38bfd32020-07-03 20:46:12 +03003533 hdev->asic_funcs->disable_clock_gating(hdev);
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03003534
3535 msleep(wait_timeout_ms);
3536
3537 gaudi_pci_dma_stall(hdev);
3538 gaudi_hbm_dma_stall(hdev);
3539 gaudi_tpc_stall(hdev);
3540 gaudi_mme_stall(hdev);
3541
3542 msleep(wait_timeout_ms);
3543
Oded Gabbay3c681572020-11-02 21:10:39 +02003544 gaudi_disable_nic_qmans(hdev);
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03003545 gaudi_disable_mme_qmans(hdev);
3546 gaudi_disable_tpc_qmans(hdev);
3547 gaudi_disable_hbm_dma_qmans(hdev);
3548 gaudi_disable_pci_dma_qmans(hdev);
3549
3550 gaudi_disable_timestamp(hdev);
3551
Oded Gabbay12ae3132020-07-03 20:58:23 +03003552 gaudi_disable_msi(hdev);
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03003553}
3554
3555static int gaudi_mmu_init(struct hl_device *hdev)
3556{
3557 struct asic_fixed_properties *prop = &hdev->asic_prop;
3558 struct gaudi_device *gaudi = hdev->asic_specific;
3559 u64 hop0_addr;
3560 int rc, i;
3561
3562 if (!hdev->mmu_enable)
3563 return 0;
3564
3565 if (gaudi->hw_cap_initialized & HW_CAP_MMU)
3566 return 0;
3567
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03003568 for (i = 0 ; i < prop->max_asid ; i++) {
3569 hop0_addr = prop->mmu_pgt_addr +
3570 (i * prop->mmu_hop_table_size);
3571
3572 rc = gaudi_mmu_update_asid_hop0_addr(hdev, i, hop0_addr);
3573 if (rc) {
3574 dev_err(hdev->dev,
3575 "failed to set hop0 addr for asid %d\n", i);
3576 goto err;
3577 }
3578 }
3579
3580 /* init MMU cache manage page */
3581 WREG32(mmSTLB_CACHE_INV_BASE_39_8, MMU_CACHE_MNG_ADDR >> 8);
3582 WREG32(mmSTLB_CACHE_INV_BASE_49_40, MMU_CACHE_MNG_ADDR >> 40);
3583
Tomer Tayar644883e2020-07-19 11:00:03 +03003584 hdev->asic_funcs->mmu_invalidate_cache(hdev, true, 0);
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03003585
3586 WREG32(mmMMU_UP_MMU_ENABLE, 1);
3587 WREG32(mmMMU_UP_SPI_MASK, 0xF);
3588
3589 WREG32(mmSTLB_HOP_CONFIGURATION,
3590 hdev->mmu_huge_page_opt ? 0x30440 : 0x40440);
3591
Omer Shpigelmancfd41762020-06-03 13:03:35 +03003592 /*
3593 * The H/W expects the first PI after init to be 1. After wraparound
3594 * we'll write 0.
3595 */
3596 gaudi->mmu_cache_inv_pi = 1;
3597
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03003598 gaudi->hw_cap_initialized |= HW_CAP_MMU;
3599
3600 return 0;
3601
3602err:
3603 return rc;
3604}
3605
3606static int gaudi_load_firmware_to_device(struct hl_device *hdev)
3607{
3608 void __iomem *dst;
3609
3610 /* HBM scrambler must be initialized before pushing F/W to HBM */
3611 gaudi_init_scrambler_hbm(hdev);
3612
3613 dst = hdev->pcie_bar[HBM_BAR_ID] + LINUX_FW_OFFSET;
3614
Ofir Bitton9bb86b62020-10-20 10:45:37 +03003615 return hl_fw_load_fw_to_device(hdev, GAUDI_LINUX_FW_FILE, dst, 0, 0);
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03003616}
3617
3618static int gaudi_load_boot_fit_to_device(struct hl_device *hdev)
3619{
3620 void __iomem *dst;
3621
3622 dst = hdev->pcie_bar[SRAM_BAR_ID] + BOOT_FIT_SRAM_OFFSET;
3623
Ofir Bitton9bb86b62020-10-20 10:45:37 +03003624 return hl_fw_load_fw_to_device(hdev, GAUDI_BOOT_FIT_FILE, dst, 0, 0);
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03003625}
3626
farah kassabrieb10b892020-10-14 15:17:36 +03003627static int gaudi_read_device_fw_version(struct hl_device *hdev,
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03003628 enum hl_fw_component fwc)
3629{
3630 const char *name;
3631 u32 ver_off;
3632 char *dest;
3633
3634 switch (fwc) {
3635 case FW_COMP_UBOOT:
3636 ver_off = RREG32(mmUBOOT_VER_OFFSET);
3637 dest = hdev->asic_prop.uboot_ver;
3638 name = "U-Boot";
3639 break;
3640 case FW_COMP_PREBOOT:
3641 ver_off = RREG32(mmPREBOOT_VER_OFFSET);
3642 dest = hdev->asic_prop.preboot_ver;
3643 name = "Preboot";
3644 break;
3645 default:
3646 dev_warn(hdev->dev, "Undefined FW component: %d\n", fwc);
farah kassabrieb10b892020-10-14 15:17:36 +03003647 return -EIO;
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03003648 }
3649
3650 ver_off &= ~((u32)SRAM_BASE_ADDR);
3651
3652 if (ver_off < SRAM_SIZE - VERSION_MAX_LEN) {
3653 memcpy_fromio(dest, hdev->pcie_bar[SRAM_BAR_ID] + ver_off,
3654 VERSION_MAX_LEN);
3655 } else {
3656 dev_err(hdev->dev, "%s version offset (0x%x) is above SRAM\n",
3657 name, ver_off);
3658 strcpy(dest, "unavailable");
farah kassabrieb10b892020-10-14 15:17:36 +03003659 return -EIO;
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03003660 }
farah kassabrieb10b892020-10-14 15:17:36 +03003661
3662 return 0;
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03003663}
3664
3665static int gaudi_init_cpu(struct hl_device *hdev)
3666{
3667 struct gaudi_device *gaudi = hdev->asic_specific;
3668 int rc;
3669
3670 if (!hdev->cpu_enable)
3671 return 0;
3672
3673 if (gaudi->hw_cap_initialized & HW_CAP_CPU)
3674 return 0;
3675
3676 /*
3677 * The device CPU works with 40 bits addresses.
3678 * This register sets the extension to 50 bits.
3679 */
Ofir Bittonc692dec2020-10-04 17:34:37 +03003680 if (hdev->asic_prop.fw_security_disabled)
3681 WREG32(mmCPU_IF_CPU_MSB_ADDR, hdev->cpu_pci_msb_addr);
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03003682
3683 rc = hl_fw_init_cpu(hdev, mmPSOC_GLOBAL_CONF_CPU_BOOT_STATUS,
3684 mmPSOC_GLOBAL_CONF_KMD_MSG_TO_CPU,
3685 mmCPU_CMD_STATUS_TO_HOST,
Ofir Bitton323b7262020-10-04 09:09:19 +03003686 mmCPU_BOOT_DEV_STS0, mmCPU_BOOT_ERR0,
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03003687 !hdev->bmc_enable, GAUDI_CPU_TIMEOUT_USEC,
3688 GAUDI_BOOT_FIT_REQ_TIMEOUT_USEC);
3689
3690 if (rc)
3691 return rc;
3692
3693 gaudi->hw_cap_initialized |= HW_CAP_CPU;
3694
3695 return 0;
3696}
3697
3698static int gaudi_init_cpu_queues(struct hl_device *hdev, u32 cpu_timeout)
3699{
3700 struct gaudi_device *gaudi = hdev->asic_specific;
3701 struct hl_eq *eq;
3702 u32 status;
3703 struct hl_hw_queue *cpu_pq =
3704 &hdev->kernel_queues[GAUDI_QUEUE_ID_CPU_PQ];
3705 int err;
3706
3707 if (!hdev->cpu_queues_enable)
3708 return 0;
3709
3710 if (gaudi->hw_cap_initialized & HW_CAP_CPU_Q)
3711 return 0;
3712
3713 eq = &hdev->event_queue;
3714
3715 WREG32(mmCPU_IF_PQ_BASE_ADDR_LOW, lower_32_bits(cpu_pq->bus_address));
3716 WREG32(mmCPU_IF_PQ_BASE_ADDR_HIGH, upper_32_bits(cpu_pq->bus_address));
3717
3718 WREG32(mmCPU_IF_EQ_BASE_ADDR_LOW, lower_32_bits(eq->bus_address));
3719 WREG32(mmCPU_IF_EQ_BASE_ADDR_HIGH, upper_32_bits(eq->bus_address));
3720
3721 WREG32(mmCPU_IF_CQ_BASE_ADDR_LOW,
3722 lower_32_bits(hdev->cpu_accessible_dma_address));
3723 WREG32(mmCPU_IF_CQ_BASE_ADDR_HIGH,
3724 upper_32_bits(hdev->cpu_accessible_dma_address));
3725
3726 WREG32(mmCPU_IF_PQ_LENGTH, HL_QUEUE_SIZE_IN_BYTES);
3727 WREG32(mmCPU_IF_EQ_LENGTH, HL_EQ_SIZE_IN_BYTES);
3728 WREG32(mmCPU_IF_CQ_LENGTH, HL_CPU_ACCESSIBLE_MEM_SIZE);
3729
3730 /* Used for EQ CI */
3731 WREG32(mmCPU_IF_EQ_RD_OFFS, 0);
3732
3733 WREG32(mmCPU_IF_PF_PQ_PI, 0);
3734
3735 if (gaudi->multi_msi_mode)
3736 WREG32(mmCPU_IF_QUEUE_INIT, PQ_INIT_STATUS_READY_FOR_CP);
3737 else
3738 WREG32(mmCPU_IF_QUEUE_INIT,
3739 PQ_INIT_STATUS_READY_FOR_CP_SINGLE_MSI);
3740
3741 WREG32(mmGIC_DISTRIBUTOR__5_GICD_SETSPI_NSR, GAUDI_EVENT_PI_UPDATE);
3742
3743 err = hl_poll_timeout(
3744 hdev,
3745 mmCPU_IF_QUEUE_INIT,
3746 status,
3747 (status == PQ_INIT_STATUS_READY_FOR_HOST),
3748 1000,
3749 cpu_timeout);
3750
3751 if (err) {
3752 dev_err(hdev->dev,
Oded Gabbay6138bbe2020-09-04 20:18:16 +03003753 "Failed to communicate with Device CPU (CPU-CP timeout)\n");
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03003754 return -EIO;
3755 }
3756
3757 gaudi->hw_cap_initialized |= HW_CAP_CPU_Q;
3758 return 0;
3759}
3760
3761static void gaudi_pre_hw_init(struct hl_device *hdev)
3762{
3763 /* Perform read from the device to make sure device is up */
3764 RREG32(mmPCIE_DBI_DEVICE_ID_VENDOR_ID_REG);
3765
Ofir Bittonc692dec2020-10-04 17:34:37 +03003766 if (hdev->asic_prop.fw_security_disabled) {
3767 /* Set the access through PCI bars (Linux driver only) as
3768 * secured
3769 */
3770 WREG32(mmPCIE_WRAP_LBW_PROT_OVR,
3771 (PCIE_WRAP_LBW_PROT_OVR_RD_EN_MASK |
3772 PCIE_WRAP_LBW_PROT_OVR_WR_EN_MASK));
Oded Gabbay57799ce2020-09-13 15:51:28 +03003773
Ofir Bittonc692dec2020-10-04 17:34:37 +03003774 /* Perform read to flush the waiting writes to ensure
3775 * configuration was set in the device
3776 */
3777 RREG32(mmPCIE_WRAP_LBW_PROT_OVR);
3778 }
Oded Gabbay57799ce2020-09-13 15:51:28 +03003779
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03003780 /*
3781 * Let's mark in the H/W that we have reached this point. We check
3782 * this value in the reset_before_init function to understand whether
3783 * we need to reset the chip before doing H/W init. This register is
3784 * cleared by the H/W upon H/W reset
3785 */
3786 WREG32(mmHW_STATE, HL_DEVICE_HW_STATE_DIRTY);
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03003787}
3788
3789static int gaudi_hw_init(struct hl_device *hdev)
3790{
3791 int rc;
3792
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03003793 gaudi_pre_hw_init(hdev);
3794
3795 gaudi_init_pci_dma_qmans(hdev);
3796
3797 gaudi_init_hbm_dma_qmans(hdev);
3798
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03003799 rc = gaudi_init_cpu(hdev);
3800 if (rc) {
3801 dev_err(hdev->dev, "failed to initialize CPU\n");
3802 return rc;
3803 }
3804
Oded Gabbay0024c0942020-12-05 22:55:09 +02003805 /* In case the clock gating was enabled in preboot we need to disable
3806 * it here before touching the MME/TPC registers.
3807 * There is no need to take clk gating mutex because when this function
3808 * runs, no other relevant code can run
3809 */
3810 hdev->asic_funcs->disable_clock_gating(hdev);
3811
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03003812 /* SRAM scrambler must be initialized after CPU is running from HBM */
3813 gaudi_init_scrambler_sram(hdev);
3814
3815 /* This is here just in case we are working without CPU */
3816 gaudi_init_scrambler_hbm(hdev);
3817
3818 gaudi_init_golden_registers(hdev);
3819
3820 rc = gaudi_mmu_init(hdev);
3821 if (rc)
3822 return rc;
3823
Omer Shpigelman3a3a5bf12020-05-11 10:45:12 +03003824 gaudi_init_security(hdev);
3825
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03003826 gaudi_init_mme_qmans(hdev);
3827
3828 gaudi_init_tpc_qmans(hdev);
3829
Oded Gabbay3c681572020-11-02 21:10:39 +02003830 gaudi_init_nic_qmans(hdev);
3831
Oded Gabbaye38bfd32020-07-03 20:46:12 +03003832 hdev->asic_funcs->set_clock_gating(hdev);
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03003833
3834 gaudi_enable_timestamp(hdev);
3835
Oded Gabbay3c681572020-11-02 21:10:39 +02003836 /* MSI must be enabled before CPU queues and NIC are initialized */
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03003837 rc = gaudi_enable_msi(hdev);
3838 if (rc)
3839 goto disable_queues;
3840
3841 /* must be called after MSI was enabled */
3842 rc = gaudi_init_cpu_queues(hdev, GAUDI_CPU_TIMEOUT_USEC);
3843 if (rc) {
3844 dev_err(hdev->dev, "failed to initialize CPU H/W queues %d\n",
3845 rc);
3846 goto disable_msi;
3847 }
3848
3849 /* Perform read from the device to flush all configuration */
3850 RREG32(mmPCIE_DBI_DEVICE_ID_VENDOR_ID_REG);
3851
3852 return 0;
3853
3854disable_msi:
3855 gaudi_disable_msi(hdev);
3856disable_queues:
3857 gaudi_disable_mme_qmans(hdev);
3858 gaudi_disable_pci_dma_qmans(hdev);
3859
3860 return rc;
3861}
3862
3863static void gaudi_hw_fini(struct hl_device *hdev, bool hard_reset)
3864{
3865 struct gaudi_device *gaudi = hdev->asic_specific;
Igor Grinbergb726a2f2020-10-29 14:06:54 +02003866 u32 status, reset_timeout_ms, cpu_timeout_ms;
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03003867
Oded Gabbay12ae3132020-07-03 20:58:23 +03003868 if (!hard_reset) {
3869 dev_err(hdev->dev, "GAUDI doesn't support soft-reset\n");
3870 return;
3871 }
3872
Oded Gabbayc83c4172020-07-05 15:48:34 +03003873 if (hdev->pldm) {
Oded Gabbay12ae3132020-07-03 20:58:23 +03003874 reset_timeout_ms = GAUDI_PLDM_HRESET_TIMEOUT_MSEC;
Oded Gabbayc83c4172020-07-05 15:48:34 +03003875 cpu_timeout_ms = GAUDI_PLDM_RESET_WAIT_MSEC;
3876 } else {
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03003877 reset_timeout_ms = GAUDI_RESET_TIMEOUT_MSEC;
Oded Gabbayc83c4172020-07-05 15:48:34 +03003878 cpu_timeout_ms = GAUDI_CPU_RESET_WAIT_MSEC;
3879 }
3880
3881 /* Set device to handle FLR by H/W as we will put the device CPU to
3882 * halt mode
3883 */
Oded Gabbaya63c3fb2020-11-26 18:11:05 +02003884 if (hdev->asic_prop.fw_security_disabled &&
3885 !hdev->asic_prop.hard_reset_done_by_fw)
Ofir Bittonb90c8942020-11-08 12:59:04 +02003886 WREG32(mmPCIE_AUX_FLR_CTRL, (PCIE_AUX_FLR_CTRL_HW_CTRL_MASK |
Oded Gabbayc83c4172020-07-05 15:48:34 +03003887 PCIE_AUX_FLR_CTRL_INT_MASK_MASK));
3888
3889 /* I don't know what is the state of the CPU so make sure it is
3890 * stopped in any means necessary
3891 */
Ofir Bitton9c9013c2020-12-01 10:39:54 +02003892 if (hdev->asic_prop.hard_reset_done_by_fw)
3893 WREG32(mmPSOC_GLOBAL_CONF_KMD_MSG_TO_CPU, KMD_MSG_RST_DEV);
3894 else
3895 WREG32(mmPSOC_GLOBAL_CONF_KMD_MSG_TO_CPU, KMD_MSG_GOTO_WFE);
Ofir Bittonb90c8942020-11-08 12:59:04 +02003896
Oded Gabbayc83c4172020-07-05 15:48:34 +03003897 WREG32(mmGIC_DISTRIBUTOR__5_GICD_SETSPI_NSR, GAUDI_EVENT_HALT_MACHINE);
3898
Oded Gabbaya63c3fb2020-11-26 18:11:05 +02003899 if (hdev->asic_prop.fw_security_disabled &&
3900 !hdev->asic_prop.hard_reset_done_by_fw) {
3901
3902 /* Configure the reset registers. Must be done as early as
3903 * possible in case we fail during H/W initialization
3904 */
3905 WREG32(mmPSOC_GLOBAL_CONF_SOFT_RST_CFG_H,
3906 (CFG_RST_H_DMA_MASK |
3907 CFG_RST_H_MME_MASK |
3908 CFG_RST_H_SM_MASK |
3909 CFG_RST_H_TPC_7_MASK));
3910
3911 WREG32(mmPSOC_GLOBAL_CONF_SOFT_RST_CFG_L, CFG_RST_L_TPC_MASK);
3912
3913 WREG32(mmPSOC_GLOBAL_CONF_SW_ALL_RST_CFG_H,
3914 (CFG_RST_H_HBM_MASK |
3915 CFG_RST_H_TPC_7_MASK |
3916 CFG_RST_H_NIC_MASK |
3917 CFG_RST_H_SM_MASK |
3918 CFG_RST_H_DMA_MASK |
3919 CFG_RST_H_MME_MASK |
3920 CFG_RST_H_CPU_MASK |
3921 CFG_RST_H_MMU_MASK));
3922
3923 WREG32(mmPSOC_GLOBAL_CONF_SW_ALL_RST_CFG_L,
3924 (CFG_RST_L_IF_MASK |
3925 CFG_RST_L_PSOC_MASK |
3926 CFG_RST_L_TPC_MASK));
3927
Ofir Bittonb90c8942020-11-08 12:59:04 +02003928 msleep(cpu_timeout_ms);
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03003929
Ofir Bittonb90c8942020-11-08 12:59:04 +02003930 /* Tell ASIC not to re-initialize PCIe */
3931 WREG32(mmPREBOOT_PCIE_EN, LKD_HARD_RESET_MAGIC);
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03003932
Ofir Bittonb90c8942020-11-08 12:59:04 +02003933 /* Restart BTL/BLR upon hard-reset */
3934 if (hdev->asic_prop.fw_security_disabled)
3935 WREG32(mmPSOC_GLOBAL_CONF_BOOT_SEQ_RE_START, 1);
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03003936
Ofir Bittonb90c8942020-11-08 12:59:04 +02003937 WREG32(mmPSOC_GLOBAL_CONF_SW_ALL_RST,
Oded Gabbay12ae3132020-07-03 20:58:23 +03003938 1 << PSOC_GLOBAL_CONF_SW_ALL_RST_IND_SHIFT);
Ofir Bittonb90c8942020-11-08 12:59:04 +02003939
Oded Gabbay13d0ee12020-12-06 23:48:45 +02003940 dev_info(hdev->dev,
3941 "Issued HARD reset command, going to wait %dms\n",
3942 reset_timeout_ms);
3943 } else {
3944 dev_info(hdev->dev,
3945 "Firmware performs HARD reset, going to wait %dms\n",
3946 reset_timeout_ms);
3947 }
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03003948
3949 /*
3950 * After hard reset, we can't poll the BTM_FSM register because the PSOC
3951 * itself is in reset. Need to wait until the reset is deasserted
3952 */
3953 msleep(reset_timeout_ms);
3954
3955 status = RREG32(mmPSOC_GLOBAL_CONF_BTM_FSM);
3956 if (status & PSOC_GLOBAL_CONF_BTM_FSM_STATE_MASK)
3957 dev_err(hdev->dev,
3958 "Timeout while waiting for device to reset 0x%x\n",
3959 status);
3960
farah kassabrieb10b892020-10-14 15:17:36 +03003961 if (gaudi) {
3962 gaudi->hw_cap_initialized &= ~(HW_CAP_CPU | HW_CAP_CPU_Q |
3963 HW_CAP_HBM | HW_CAP_PCI_DMA |
3964 HW_CAP_MME | HW_CAP_TPC_MASK |
3965 HW_CAP_HBM_DMA | HW_CAP_PLL |
3966 HW_CAP_NIC_MASK | HW_CAP_MMU |
3967 HW_CAP_SRAM_SCRAMBLER |
3968 HW_CAP_HBM_SCRAMBLER |
3969 HW_CAP_CLK_GATE);
Oded Gabbaye38bfd32020-07-03 20:46:12 +03003970
farah kassabrieb10b892020-10-14 15:17:36 +03003971 memset(gaudi->events_stat, 0, sizeof(gaudi->events_stat));
3972 }
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03003973}
3974
3975static int gaudi_suspend(struct hl_device *hdev)
3976{
3977 int rc;
3978
Oded Gabbay2f553422020-08-15 16:28:10 +03003979 rc = hl_fw_send_pci_access_msg(hdev, CPUCP_PACKET_DISABLE_PCI_ACCESS);
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03003980 if (rc)
3981 dev_err(hdev->dev, "Failed to disable PCI access from CPU\n");
3982
3983 return rc;
3984}
3985
3986static int gaudi_resume(struct hl_device *hdev)
3987{
3988 return gaudi_init_iatu(hdev);
3989}
3990
3991static int gaudi_cb_mmap(struct hl_device *hdev, struct vm_area_struct *vma,
Hillf Danton0db57532020-08-23 07:32:42 +08003992 void *cpu_addr, dma_addr_t dma_addr, size_t size)
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03003993{
3994 int rc;
3995
3996 vma->vm_flags |= VM_IO | VM_PFNMAP | VM_DONTEXPAND | VM_DONTDUMP |
3997 VM_DONTCOPY | VM_NORESERVE;
3998
Hillf Danton0db57532020-08-23 07:32:42 +08003999 rc = dma_mmap_coherent(hdev->dev, vma, cpu_addr, dma_addr, size);
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03004000 if (rc)
Hillf Danton0db57532020-08-23 07:32:42 +08004001 dev_err(hdev->dev, "dma_mmap_coherent error %d", rc);
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03004002
4003 return rc;
4004}
4005
4006static void gaudi_ring_doorbell(struct hl_device *hdev, u32 hw_queue_id, u32 pi)
4007{
4008 struct gaudi_device *gaudi = hdev->asic_specific;
4009 u32 db_reg_offset, db_value, dma_qm_offset, q_off;
4010 int dma_id;
4011 bool invalid_queue = false;
4012
4013 switch (hw_queue_id) {
4014 case GAUDI_QUEUE_ID_DMA_0_0...GAUDI_QUEUE_ID_DMA_0_3:
4015 dma_id = gaudi_dma_assignment[GAUDI_PCI_DMA_1];
4016 dma_qm_offset = dma_id * DMA_QMAN_OFFSET;
4017 q_off = dma_qm_offset + (hw_queue_id & 0x3) * 4;
4018 db_reg_offset = mmDMA0_QM_PQ_PI_0 + q_off;
4019 break;
4020
4021 case GAUDI_QUEUE_ID_DMA_1_0...GAUDI_QUEUE_ID_DMA_1_3:
4022 dma_id = gaudi_dma_assignment[GAUDI_PCI_DMA_2];
4023 dma_qm_offset = dma_id * DMA_QMAN_OFFSET;
4024 q_off = dma_qm_offset + (hw_queue_id & 0x3) * 4;
4025 db_reg_offset = mmDMA0_QM_PQ_PI_0 + q_off;
4026 break;
4027
4028 case GAUDI_QUEUE_ID_DMA_2_0...GAUDI_QUEUE_ID_DMA_2_3:
4029 dma_id = gaudi_dma_assignment[GAUDI_HBM_DMA_1];
4030 dma_qm_offset = dma_id * DMA_QMAN_OFFSET;
4031 q_off = dma_qm_offset + ((hw_queue_id - 1) & 0x3) * 4;
4032 db_reg_offset = mmDMA0_QM_PQ_PI_0 + q_off;
4033 break;
4034
4035 case GAUDI_QUEUE_ID_DMA_3_0...GAUDI_QUEUE_ID_DMA_3_3:
4036 dma_id = gaudi_dma_assignment[GAUDI_HBM_DMA_2];
4037 dma_qm_offset = dma_id * DMA_QMAN_OFFSET;
4038 q_off = dma_qm_offset + ((hw_queue_id - 1) & 0x3) * 4;
4039 db_reg_offset = mmDMA0_QM_PQ_PI_0 + q_off;
4040 break;
4041
4042 case GAUDI_QUEUE_ID_DMA_4_0...GAUDI_QUEUE_ID_DMA_4_3:
4043 dma_id = gaudi_dma_assignment[GAUDI_HBM_DMA_3];
4044 dma_qm_offset = dma_id * DMA_QMAN_OFFSET;
4045 q_off = dma_qm_offset + ((hw_queue_id - 1) & 0x3) * 4;
4046 db_reg_offset = mmDMA0_QM_PQ_PI_0 + q_off;
4047 break;
4048
4049 case GAUDI_QUEUE_ID_DMA_5_0...GAUDI_QUEUE_ID_DMA_5_3:
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03004050 dma_id = gaudi_dma_assignment[GAUDI_HBM_DMA_4];
4051 dma_qm_offset = dma_id * DMA_QMAN_OFFSET;
4052 q_off = dma_qm_offset + ((hw_queue_id - 1) & 0x3) * 4;
4053 db_reg_offset = mmDMA0_QM_PQ_PI_0 + q_off;
4054 break;
4055
Ofir Bitton0940cab2020-08-31 08:52:56 +03004056 case GAUDI_QUEUE_ID_DMA_6_0...GAUDI_QUEUE_ID_DMA_6_3:
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03004057 dma_id = gaudi_dma_assignment[GAUDI_HBM_DMA_5];
4058 dma_qm_offset = dma_id * DMA_QMAN_OFFSET;
4059 q_off = dma_qm_offset + ((hw_queue_id - 1) & 0x3) * 4;
4060 db_reg_offset = mmDMA0_QM_PQ_PI_0 + q_off;
4061 break;
4062
Ofir Bitton0940cab2020-08-31 08:52:56 +03004063 case GAUDI_QUEUE_ID_DMA_7_0...GAUDI_QUEUE_ID_DMA_7_3:
4064 dma_id = gaudi_dma_assignment[GAUDI_HBM_DMA_6];
4065 dma_qm_offset = dma_id * DMA_QMAN_OFFSET;
4066 q_off = dma_qm_offset + ((hw_queue_id - 1) & 0x3) * 4;
4067 db_reg_offset = mmDMA0_QM_PQ_PI_0 + q_off;
4068 break;
4069
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03004070 case GAUDI_QUEUE_ID_CPU_PQ:
4071 if (gaudi->hw_cap_initialized & HW_CAP_CPU_Q)
4072 db_reg_offset = mmCPU_IF_PF_PQ_PI;
4073 else
4074 invalid_queue = true;
4075 break;
4076
4077 case GAUDI_QUEUE_ID_MME_0_0:
4078 db_reg_offset = mmMME2_QM_PQ_PI_0;
4079 break;
4080
4081 case GAUDI_QUEUE_ID_MME_0_1:
4082 db_reg_offset = mmMME2_QM_PQ_PI_1;
4083 break;
4084
4085 case GAUDI_QUEUE_ID_MME_0_2:
4086 db_reg_offset = mmMME2_QM_PQ_PI_2;
4087 break;
4088
4089 case GAUDI_QUEUE_ID_MME_0_3:
4090 db_reg_offset = mmMME2_QM_PQ_PI_3;
4091 break;
4092
4093 case GAUDI_QUEUE_ID_MME_1_0:
4094 db_reg_offset = mmMME0_QM_PQ_PI_0;
4095 break;
4096
4097 case GAUDI_QUEUE_ID_MME_1_1:
4098 db_reg_offset = mmMME0_QM_PQ_PI_1;
4099 break;
4100
4101 case GAUDI_QUEUE_ID_MME_1_2:
4102 db_reg_offset = mmMME0_QM_PQ_PI_2;
4103 break;
4104
4105 case GAUDI_QUEUE_ID_MME_1_3:
4106 db_reg_offset = mmMME0_QM_PQ_PI_3;
4107 break;
4108
4109 case GAUDI_QUEUE_ID_TPC_0_0:
4110 db_reg_offset = mmTPC0_QM_PQ_PI_0;
4111 break;
4112
4113 case GAUDI_QUEUE_ID_TPC_0_1:
4114 db_reg_offset = mmTPC0_QM_PQ_PI_1;
4115 break;
4116
4117 case GAUDI_QUEUE_ID_TPC_0_2:
4118 db_reg_offset = mmTPC0_QM_PQ_PI_2;
4119 break;
4120
4121 case GAUDI_QUEUE_ID_TPC_0_3:
4122 db_reg_offset = mmTPC0_QM_PQ_PI_3;
4123 break;
4124
4125 case GAUDI_QUEUE_ID_TPC_1_0:
4126 db_reg_offset = mmTPC1_QM_PQ_PI_0;
4127 break;
4128
4129 case GAUDI_QUEUE_ID_TPC_1_1:
4130 db_reg_offset = mmTPC1_QM_PQ_PI_1;
4131 break;
4132
4133 case GAUDI_QUEUE_ID_TPC_1_2:
4134 db_reg_offset = mmTPC1_QM_PQ_PI_2;
4135 break;
4136
4137 case GAUDI_QUEUE_ID_TPC_1_3:
4138 db_reg_offset = mmTPC1_QM_PQ_PI_3;
4139 break;
4140
4141 case GAUDI_QUEUE_ID_TPC_2_0:
4142 db_reg_offset = mmTPC2_QM_PQ_PI_0;
4143 break;
4144
4145 case GAUDI_QUEUE_ID_TPC_2_1:
4146 db_reg_offset = mmTPC2_QM_PQ_PI_1;
4147 break;
4148
4149 case GAUDI_QUEUE_ID_TPC_2_2:
4150 db_reg_offset = mmTPC2_QM_PQ_PI_2;
4151 break;
4152
4153 case GAUDI_QUEUE_ID_TPC_2_3:
4154 db_reg_offset = mmTPC2_QM_PQ_PI_3;
4155 break;
4156
4157 case GAUDI_QUEUE_ID_TPC_3_0:
4158 db_reg_offset = mmTPC3_QM_PQ_PI_0;
4159 break;
4160
4161 case GAUDI_QUEUE_ID_TPC_3_1:
4162 db_reg_offset = mmTPC3_QM_PQ_PI_1;
4163 break;
4164
4165 case GAUDI_QUEUE_ID_TPC_3_2:
4166 db_reg_offset = mmTPC3_QM_PQ_PI_2;
4167 break;
4168
4169 case GAUDI_QUEUE_ID_TPC_3_3:
4170 db_reg_offset = mmTPC3_QM_PQ_PI_3;
4171 break;
4172
4173 case GAUDI_QUEUE_ID_TPC_4_0:
4174 db_reg_offset = mmTPC4_QM_PQ_PI_0;
4175 break;
4176
4177 case GAUDI_QUEUE_ID_TPC_4_1:
4178 db_reg_offset = mmTPC4_QM_PQ_PI_1;
4179 break;
4180
4181 case GAUDI_QUEUE_ID_TPC_4_2:
4182 db_reg_offset = mmTPC4_QM_PQ_PI_2;
4183 break;
4184
4185 case GAUDI_QUEUE_ID_TPC_4_3:
4186 db_reg_offset = mmTPC4_QM_PQ_PI_3;
4187 break;
4188
4189 case GAUDI_QUEUE_ID_TPC_5_0:
4190 db_reg_offset = mmTPC5_QM_PQ_PI_0;
4191 break;
4192
4193 case GAUDI_QUEUE_ID_TPC_5_1:
4194 db_reg_offset = mmTPC5_QM_PQ_PI_1;
4195 break;
4196
4197 case GAUDI_QUEUE_ID_TPC_5_2:
4198 db_reg_offset = mmTPC5_QM_PQ_PI_2;
4199 break;
4200
4201 case GAUDI_QUEUE_ID_TPC_5_3:
4202 db_reg_offset = mmTPC5_QM_PQ_PI_3;
4203 break;
4204
4205 case GAUDI_QUEUE_ID_TPC_6_0:
4206 db_reg_offset = mmTPC6_QM_PQ_PI_0;
4207 break;
4208
4209 case GAUDI_QUEUE_ID_TPC_6_1:
4210 db_reg_offset = mmTPC6_QM_PQ_PI_1;
4211 break;
4212
4213 case GAUDI_QUEUE_ID_TPC_6_2:
4214 db_reg_offset = mmTPC6_QM_PQ_PI_2;
4215 break;
4216
4217 case GAUDI_QUEUE_ID_TPC_6_3:
4218 db_reg_offset = mmTPC6_QM_PQ_PI_3;
4219 break;
4220
4221 case GAUDI_QUEUE_ID_TPC_7_0:
4222 db_reg_offset = mmTPC7_QM_PQ_PI_0;
4223 break;
4224
4225 case GAUDI_QUEUE_ID_TPC_7_1:
4226 db_reg_offset = mmTPC7_QM_PQ_PI_1;
4227 break;
4228
4229 case GAUDI_QUEUE_ID_TPC_7_2:
4230 db_reg_offset = mmTPC7_QM_PQ_PI_2;
4231 break;
4232
4233 case GAUDI_QUEUE_ID_TPC_7_3:
4234 db_reg_offset = mmTPC7_QM_PQ_PI_3;
4235 break;
4236
Oded Gabbay3c681572020-11-02 21:10:39 +02004237 case GAUDI_QUEUE_ID_NIC_0_0:
4238 db_reg_offset = mmNIC0_QM0_PQ_PI_0;
4239 break;
4240
4241 case GAUDI_QUEUE_ID_NIC_0_1:
4242 db_reg_offset = mmNIC0_QM0_PQ_PI_1;
4243 break;
4244
4245 case GAUDI_QUEUE_ID_NIC_0_2:
4246 db_reg_offset = mmNIC0_QM0_PQ_PI_2;
4247 break;
4248
4249 case GAUDI_QUEUE_ID_NIC_0_3:
4250 db_reg_offset = mmNIC0_QM0_PQ_PI_3;
4251 break;
4252
4253 case GAUDI_QUEUE_ID_NIC_1_0:
4254 db_reg_offset = mmNIC0_QM1_PQ_PI_0;
4255 break;
4256
4257 case GAUDI_QUEUE_ID_NIC_1_1:
4258 db_reg_offset = mmNIC0_QM1_PQ_PI_1;
4259 break;
4260
4261 case GAUDI_QUEUE_ID_NIC_1_2:
4262 db_reg_offset = mmNIC0_QM1_PQ_PI_2;
4263 break;
4264
4265 case GAUDI_QUEUE_ID_NIC_1_3:
4266 db_reg_offset = mmNIC0_QM1_PQ_PI_3;
4267 break;
4268
4269 case GAUDI_QUEUE_ID_NIC_2_0:
4270 db_reg_offset = mmNIC1_QM0_PQ_PI_0;
4271 break;
4272
4273 case GAUDI_QUEUE_ID_NIC_2_1:
4274 db_reg_offset = mmNIC1_QM0_PQ_PI_1;
4275 break;
4276
4277 case GAUDI_QUEUE_ID_NIC_2_2:
4278 db_reg_offset = mmNIC1_QM0_PQ_PI_2;
4279 break;
4280
4281 case GAUDI_QUEUE_ID_NIC_2_3:
4282 db_reg_offset = mmNIC1_QM0_PQ_PI_3;
4283 break;
4284
4285 case GAUDI_QUEUE_ID_NIC_3_0:
4286 db_reg_offset = mmNIC1_QM1_PQ_PI_0;
4287 break;
4288
4289 case GAUDI_QUEUE_ID_NIC_3_1:
4290 db_reg_offset = mmNIC1_QM1_PQ_PI_1;
4291 break;
4292
4293 case GAUDI_QUEUE_ID_NIC_3_2:
4294 db_reg_offset = mmNIC1_QM1_PQ_PI_2;
4295 break;
4296
4297 case GAUDI_QUEUE_ID_NIC_3_3:
4298 db_reg_offset = mmNIC1_QM1_PQ_PI_3;
4299 break;
4300
4301 case GAUDI_QUEUE_ID_NIC_4_0:
4302 db_reg_offset = mmNIC2_QM0_PQ_PI_0;
4303 break;
4304
4305 case GAUDI_QUEUE_ID_NIC_4_1:
4306 db_reg_offset = mmNIC2_QM0_PQ_PI_1;
4307 break;
4308
4309 case GAUDI_QUEUE_ID_NIC_4_2:
4310 db_reg_offset = mmNIC2_QM0_PQ_PI_2;
4311 break;
4312
4313 case GAUDI_QUEUE_ID_NIC_4_3:
4314 db_reg_offset = mmNIC2_QM0_PQ_PI_3;
4315 break;
4316
4317 case GAUDI_QUEUE_ID_NIC_5_0:
4318 db_reg_offset = mmNIC2_QM1_PQ_PI_0;
4319 break;
4320
4321 case GAUDI_QUEUE_ID_NIC_5_1:
4322 db_reg_offset = mmNIC2_QM1_PQ_PI_1;
4323 break;
4324
4325 case GAUDI_QUEUE_ID_NIC_5_2:
4326 db_reg_offset = mmNIC2_QM1_PQ_PI_2;
4327 break;
4328
4329 case GAUDI_QUEUE_ID_NIC_5_3:
4330 db_reg_offset = mmNIC2_QM1_PQ_PI_3;
4331 break;
4332
4333 case GAUDI_QUEUE_ID_NIC_6_0:
4334 db_reg_offset = mmNIC3_QM0_PQ_PI_0;
4335 break;
4336
4337 case GAUDI_QUEUE_ID_NIC_6_1:
4338 db_reg_offset = mmNIC3_QM0_PQ_PI_1;
4339 break;
4340
4341 case GAUDI_QUEUE_ID_NIC_6_2:
4342 db_reg_offset = mmNIC3_QM0_PQ_PI_2;
4343 break;
4344
4345 case GAUDI_QUEUE_ID_NIC_6_3:
4346 db_reg_offset = mmNIC3_QM0_PQ_PI_3;
4347 break;
4348
4349 case GAUDI_QUEUE_ID_NIC_7_0:
4350 db_reg_offset = mmNIC3_QM1_PQ_PI_0;
4351 break;
4352
4353 case GAUDI_QUEUE_ID_NIC_7_1:
4354 db_reg_offset = mmNIC3_QM1_PQ_PI_1;
4355 break;
4356
4357 case GAUDI_QUEUE_ID_NIC_7_2:
4358 db_reg_offset = mmNIC3_QM1_PQ_PI_2;
4359 break;
4360
4361 case GAUDI_QUEUE_ID_NIC_7_3:
4362 db_reg_offset = mmNIC3_QM1_PQ_PI_3;
4363 break;
4364
4365 case GAUDI_QUEUE_ID_NIC_8_0:
4366 db_reg_offset = mmNIC4_QM0_PQ_PI_0;
4367 break;
4368
4369 case GAUDI_QUEUE_ID_NIC_8_1:
4370 db_reg_offset = mmNIC4_QM0_PQ_PI_1;
4371 break;
4372
4373 case GAUDI_QUEUE_ID_NIC_8_2:
4374 db_reg_offset = mmNIC4_QM0_PQ_PI_2;
4375 break;
4376
4377 case GAUDI_QUEUE_ID_NIC_8_3:
4378 db_reg_offset = mmNIC4_QM0_PQ_PI_3;
4379 break;
4380
4381 case GAUDI_QUEUE_ID_NIC_9_0:
4382 db_reg_offset = mmNIC4_QM1_PQ_PI_0;
4383 break;
4384
4385 case GAUDI_QUEUE_ID_NIC_9_1:
4386 db_reg_offset = mmNIC4_QM1_PQ_PI_1;
4387 break;
4388
4389 case GAUDI_QUEUE_ID_NIC_9_2:
4390 db_reg_offset = mmNIC4_QM1_PQ_PI_2;
4391 break;
4392
4393 case GAUDI_QUEUE_ID_NIC_9_3:
4394 db_reg_offset = mmNIC4_QM1_PQ_PI_3;
4395 break;
4396
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03004397 default:
4398 invalid_queue = true;
4399 }
4400
4401 if (invalid_queue) {
4402 /* Should never get here */
4403 dev_err(hdev->dev, "h/w queue %d is invalid. Can't set pi\n",
4404 hw_queue_id);
4405 return;
4406 }
4407
4408 db_value = pi;
4409
4410 /* ring the doorbell */
4411 WREG32(db_reg_offset, db_value);
4412
4413 if (hw_queue_id == GAUDI_QUEUE_ID_CPU_PQ)
4414 WREG32(mmGIC_DISTRIBUTOR__5_GICD_SETSPI_NSR,
4415 GAUDI_EVENT_PI_UPDATE);
4416}
4417
4418static void gaudi_pqe_write(struct hl_device *hdev, __le64 *pqe,
4419 struct hl_bd *bd)
4420{
4421 __le64 *pbd = (__le64 *) bd;
4422
4423 /* The QMANs are on the host memory so a simple copy suffice */
4424 pqe[0] = pbd[0];
4425 pqe[1] = pbd[1];
4426}
4427
4428static void *gaudi_dma_alloc_coherent(struct hl_device *hdev, size_t size,
4429 dma_addr_t *dma_handle, gfp_t flags)
4430{
4431 void *kernel_addr = dma_alloc_coherent(&hdev->pdev->dev, size,
4432 dma_handle, flags);
4433
4434 /* Shift to the device's base physical address of host memory */
4435 if (kernel_addr)
4436 *dma_handle += HOST_PHYS_BASE;
4437
4438 return kernel_addr;
4439}
4440
4441static void gaudi_dma_free_coherent(struct hl_device *hdev, size_t size,
4442 void *cpu_addr, dma_addr_t dma_handle)
4443{
4444 /* Cancel the device's base physical address of host memory */
4445 dma_addr_t fixed_dma_handle = dma_handle - HOST_PHYS_BASE;
4446
4447 dma_free_coherent(&hdev->pdev->dev, size, cpu_addr, fixed_dma_handle);
4448}
4449
farah kassabri03df1362020-05-06 11:17:38 +03004450static int gaudi_hbm_scrubbing(struct hl_device *hdev)
4451{
4452 struct asic_fixed_properties *prop = &hdev->asic_prop;
4453 u64 cur_addr = DRAM_BASE_ADDR_USER;
4454 u32 val;
4455 u32 chunk_size;
4456 int rc, dma_id;
4457
4458 while (cur_addr < prop->dram_end_address) {
4459 for (dma_id = 0 ; dma_id < DMA_NUMBER_OF_CHANNELS ; dma_id++) {
4460 u32 dma_offset = dma_id * DMA_CORE_OFFSET;
4461
4462 chunk_size =
4463 min((u64)SZ_2G, prop->dram_end_address - cur_addr);
4464
4465 dev_dbg(hdev->dev,
4466 "Doing HBM scrubbing for 0x%09llx - 0x%09llx\n",
4467 cur_addr, cur_addr + chunk_size);
4468
4469 WREG32(mmDMA0_CORE_SRC_BASE_LO + dma_offset, 0);
4470 WREG32(mmDMA0_CORE_SRC_BASE_HI + dma_offset, 0);
4471 WREG32(mmDMA0_CORE_DST_BASE_LO + dma_offset,
4472 lower_32_bits(cur_addr));
4473 WREG32(mmDMA0_CORE_DST_BASE_HI + dma_offset,
4474 upper_32_bits(cur_addr));
4475 WREG32(mmDMA0_CORE_DST_TSIZE_0 + dma_offset,
4476 chunk_size);
4477 WREG32(mmDMA0_CORE_COMMIT + dma_offset,
4478 ((1 << DMA0_CORE_COMMIT_LIN_SHIFT) |
4479 (1 << DMA0_CORE_COMMIT_MEM_SET_SHIFT)));
4480
4481 cur_addr += chunk_size;
4482
4483 if (cur_addr == prop->dram_end_address)
4484 break;
4485 }
4486
4487 for (dma_id = 0 ; dma_id < DMA_NUMBER_OF_CHANNELS ; dma_id++) {
4488 u32 dma_offset = dma_id * DMA_CORE_OFFSET;
4489
4490 rc = hl_poll_timeout(
4491 hdev,
4492 mmDMA0_CORE_STS0 + dma_offset,
4493 val,
4494 ((val & DMA0_CORE_STS0_BUSY_MASK) == 0),
4495 1000,
4496 HBM_SCRUBBING_TIMEOUT_US);
4497
4498 if (rc) {
4499 dev_err(hdev->dev,
4500 "DMA Timeout during HBM scrubbing of DMA #%d\n",
4501 dma_id);
4502 return -EIO;
4503 }
4504 }
4505 }
4506
4507 return 0;
4508}
4509
4510static int gaudi_scrub_device_mem(struct hl_device *hdev, u64 addr, u64 size)
4511{
4512 struct asic_fixed_properties *prop = &hdev->asic_prop;
4513 struct gaudi_device *gaudi = hdev->asic_specific;
4514 u64 idle_mask = 0;
4515 int rc = 0;
4516 u64 val = 0;
4517
4518 if (!hdev->memory_scrub)
4519 return 0;
4520
4521 if (!addr && !size) {
4522 /* Wait till device is idle */
4523 rc = hl_poll_timeout(
4524 hdev,
4525 mmDMA0_CORE_STS0/* dummy */,
4526 val/* dummy */,
4527 (hdev->asic_funcs->is_device_idle(hdev,
4528 &idle_mask, NULL)),
4529 1000,
4530 HBM_SCRUBBING_TIMEOUT_US);
4531 if (rc) {
4532 dev_err(hdev->dev, "waiting for idle timeout\n");
4533 return -EIO;
4534 }
4535
4536 /* Scrub SRAM */
4537 addr = prop->sram_user_base_address;
4538 size = hdev->pldm ? 0x10000 :
4539 (prop->sram_size - SRAM_USER_BASE_OFFSET);
4540 val = 0x7777777777777777ull;
4541
4542 rc = gaudi_memset_device_memory(hdev, addr, size, val);
4543 if (rc) {
4544 dev_err(hdev->dev,
4545 "Failed to clear SRAM in mem scrub all\n");
4546 return rc;
4547 }
4548
4549 mutex_lock(&gaudi->clk_gate_mutex);
4550 hdev->asic_funcs->disable_clock_gating(hdev);
4551
4552 /* Scrub HBM using all DMA channels in parallel */
4553 rc = gaudi_hbm_scrubbing(hdev);
4554 if (rc)
4555 dev_err(hdev->dev,
4556 "Failed to clear HBM in mem scrub all\n");
4557
4558 hdev->asic_funcs->set_clock_gating(hdev);
4559 mutex_unlock(&gaudi->clk_gate_mutex);
4560 }
4561
4562 return rc;
4563}
4564
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03004565static void *gaudi_get_int_queue_base(struct hl_device *hdev,
4566 u32 queue_id, dma_addr_t *dma_handle,
4567 u16 *queue_len)
4568{
4569 struct gaudi_device *gaudi = hdev->asic_specific;
4570 struct gaudi_internal_qman_info *q;
4571
4572 if (queue_id >= GAUDI_QUEUE_ID_SIZE ||
4573 gaudi_queue_type[queue_id] != QUEUE_TYPE_INT) {
4574 dev_err(hdev->dev, "Got invalid queue id %d\n", queue_id);
4575 return NULL;
4576 }
4577
4578 q = &gaudi->internal_qmans[queue_id];
4579 *dma_handle = q->pq_dma_addr;
4580 *queue_len = q->pq_size / QMAN_PQ_ENTRY_SIZE;
4581
4582 return q->pq_kernel_addr;
4583}
4584
4585static int gaudi_send_cpu_message(struct hl_device *hdev, u32 *msg,
Alon Mizrahi439bc472020-11-10 13:49:10 +02004586 u16 len, u32 timeout, u64 *result)
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03004587{
4588 struct gaudi_device *gaudi = hdev->asic_specific;
4589
4590 if (!(gaudi->hw_cap_initialized & HW_CAP_CPU_Q)) {
4591 if (result)
4592 *result = 0;
4593 return 0;
4594 }
4595
Oded Gabbay788cacf2020-07-07 17:30:13 +03004596 if (!timeout)
4597 timeout = GAUDI_MSG_TO_CPU_TIMEOUT_USEC;
4598
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03004599 return hl_fw_send_cpu_message(hdev, GAUDI_QUEUE_ID_CPU_PQ, msg, len,
4600 timeout, result);
4601}
4602
4603static int gaudi_test_queue(struct hl_device *hdev, u32 hw_queue_id)
4604{
4605 struct packet_msg_prot *fence_pkt;
4606 dma_addr_t pkt_dma_addr;
4607 u32 fence_val, tmp, timeout_usec;
4608 dma_addr_t fence_dma_addr;
4609 u32 *fence_ptr;
4610 int rc;
4611
4612 if (hdev->pldm)
4613 timeout_usec = GAUDI_PLDM_TEST_QUEUE_WAIT_USEC;
4614 else
4615 timeout_usec = GAUDI_TEST_QUEUE_WAIT_USEC;
4616
4617 fence_val = GAUDI_QMAN0_FENCE_VAL;
4618
4619 fence_ptr = hdev->asic_funcs->asic_dma_pool_zalloc(hdev, 4, GFP_KERNEL,
4620 &fence_dma_addr);
4621 if (!fence_ptr) {
4622 dev_err(hdev->dev,
Dotan Barakd6b045c2020-08-06 09:20:49 +03004623 "Failed to allocate memory for H/W queue %d testing\n",
4624 hw_queue_id);
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03004625 return -ENOMEM;
4626 }
4627
4628 *fence_ptr = 0;
4629
4630 fence_pkt = hdev->asic_funcs->asic_dma_pool_zalloc(hdev,
4631 sizeof(struct packet_msg_prot),
4632 GFP_KERNEL, &pkt_dma_addr);
4633 if (!fence_pkt) {
4634 dev_err(hdev->dev,
Dotan Barakd6b045c2020-08-06 09:20:49 +03004635 "Failed to allocate packet for H/W queue %d testing\n",
4636 hw_queue_id);
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03004637 rc = -ENOMEM;
4638 goto free_fence_ptr;
4639 }
4640
Oded Gabbay65887292020-08-12 11:21:01 +03004641 tmp = FIELD_PREP(GAUDI_PKT_CTL_OPCODE_MASK, PACKET_MSG_PROT);
4642 tmp |= FIELD_PREP(GAUDI_PKT_CTL_EB_MASK, 1);
4643 tmp |= FIELD_PREP(GAUDI_PKT_CTL_MB_MASK, 1);
4644
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03004645 fence_pkt->ctl = cpu_to_le32(tmp);
4646 fence_pkt->value = cpu_to_le32(fence_val);
4647 fence_pkt->addr = cpu_to_le64(fence_dma_addr);
4648
4649 rc = hl_hw_queue_send_cb_no_cmpl(hdev, hw_queue_id,
4650 sizeof(struct packet_msg_prot),
4651 pkt_dma_addr);
4652 if (rc) {
4653 dev_err(hdev->dev,
Dotan Barakd6b045c2020-08-06 09:20:49 +03004654 "Failed to send fence packet to H/W queue %d\n",
4655 hw_queue_id);
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03004656 goto free_pkt;
4657 }
4658
4659 rc = hl_poll_timeout_memory(hdev, fence_ptr, tmp, (tmp == fence_val),
4660 1000, timeout_usec, true);
4661
4662 hl_hw_queue_inc_ci_kernel(hdev, hw_queue_id);
4663
4664 if (rc == -ETIMEDOUT) {
4665 dev_err(hdev->dev,
4666 "H/W queue %d test failed (scratch(0x%08llX) == 0x%08X)\n",
4667 hw_queue_id, (unsigned long long) fence_dma_addr, tmp);
4668 rc = -EIO;
4669 }
4670
4671free_pkt:
4672 hdev->asic_funcs->asic_dma_pool_free(hdev, (void *) fence_pkt,
4673 pkt_dma_addr);
4674free_fence_ptr:
4675 hdev->asic_funcs->asic_dma_pool_free(hdev, (void *) fence_ptr,
4676 fence_dma_addr);
4677 return rc;
4678}
4679
4680static int gaudi_test_cpu_queue(struct hl_device *hdev)
4681{
4682 struct gaudi_device *gaudi = hdev->asic_specific;
4683
4684 /*
4685 * check capability here as send_cpu_message() won't update the result
4686 * value if no capability
4687 */
4688 if (!(gaudi->hw_cap_initialized & HW_CAP_CPU_Q))
4689 return 0;
4690
4691 return hl_fw_test_cpu_queue(hdev);
4692}
4693
4694static int gaudi_test_queues(struct hl_device *hdev)
4695{
4696 int i, rc, ret_val = 0;
4697
Ofir Bitton3abc99b2020-06-23 14:50:39 +03004698 for (i = 0 ; i < hdev->asic_prop.max_queues ; i++) {
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03004699 if (hdev->asic_prop.hw_queues_props[i].type == QUEUE_TYPE_EXT) {
4700 rc = gaudi_test_queue(hdev, i);
4701 if (rc)
4702 ret_val = -EINVAL;
4703 }
4704 }
4705
4706 rc = gaudi_test_cpu_queue(hdev);
4707 if (rc)
4708 ret_val = -EINVAL;
4709
4710 return ret_val;
4711}
4712
4713static void *gaudi_dma_pool_zalloc(struct hl_device *hdev, size_t size,
4714 gfp_t mem_flags, dma_addr_t *dma_handle)
4715{
4716 void *kernel_addr;
4717
4718 if (size > GAUDI_DMA_POOL_BLK_SIZE)
4719 return NULL;
4720
4721 kernel_addr = dma_pool_zalloc(hdev->dma_pool, mem_flags, dma_handle);
4722
4723 /* Shift to the device's base physical address of host memory */
4724 if (kernel_addr)
4725 *dma_handle += HOST_PHYS_BASE;
4726
4727 return kernel_addr;
4728}
4729
4730static void gaudi_dma_pool_free(struct hl_device *hdev, void *vaddr,
4731 dma_addr_t dma_addr)
4732{
4733 /* Cancel the device's base physical address of host memory */
4734 dma_addr_t fixed_dma_addr = dma_addr - HOST_PHYS_BASE;
4735
4736 dma_pool_free(hdev->dma_pool, vaddr, fixed_dma_addr);
4737}
4738
4739static void *gaudi_cpu_accessible_dma_pool_alloc(struct hl_device *hdev,
4740 size_t size, dma_addr_t *dma_handle)
4741{
4742 return hl_fw_cpu_accessible_dma_pool_alloc(hdev, size, dma_handle);
4743}
4744
4745static void gaudi_cpu_accessible_dma_pool_free(struct hl_device *hdev,
4746 size_t size, void *vaddr)
4747{
4748 hl_fw_cpu_accessible_dma_pool_free(hdev, size, vaddr);
4749}
4750
4751static int gaudi_dma_map_sg(struct hl_device *hdev, struct scatterlist *sgl,
4752 int nents, enum dma_data_direction dir)
4753{
4754 struct scatterlist *sg;
4755 int i;
4756
4757 if (!dma_map_sg(&hdev->pdev->dev, sgl, nents, dir))
4758 return -ENOMEM;
4759
4760 /* Shift to the device's base physical address of host memory */
4761 for_each_sg(sgl, sg, nents, i)
4762 sg->dma_address += HOST_PHYS_BASE;
4763
4764 return 0;
4765}
4766
4767static void gaudi_dma_unmap_sg(struct hl_device *hdev, struct scatterlist *sgl,
4768 int nents, enum dma_data_direction dir)
4769{
4770 struct scatterlist *sg;
4771 int i;
4772
4773 /* Cancel the device's base physical address of host memory */
4774 for_each_sg(sgl, sg, nents, i)
4775 sg->dma_address -= HOST_PHYS_BASE;
4776
4777 dma_unmap_sg(&hdev->pdev->dev, sgl, nents, dir);
4778}
4779
4780static u32 gaudi_get_dma_desc_list_size(struct hl_device *hdev,
4781 struct sg_table *sgt)
4782{
4783 struct scatterlist *sg, *sg_next_iter;
4784 u32 count, dma_desc_cnt;
4785 u64 len, len_next;
4786 dma_addr_t addr, addr_next;
4787
4788 dma_desc_cnt = 0;
4789
4790 for_each_sg(sgt->sgl, sg, sgt->nents, count) {
4791
4792 len = sg_dma_len(sg);
4793 addr = sg_dma_address(sg);
4794
4795 if (len == 0)
4796 break;
4797
4798 while ((count + 1) < sgt->nents) {
4799 sg_next_iter = sg_next(sg);
4800 len_next = sg_dma_len(sg_next_iter);
4801 addr_next = sg_dma_address(sg_next_iter);
4802
4803 if (len_next == 0)
4804 break;
4805
4806 if ((addr + len == addr_next) &&
4807 (len + len_next <= DMA_MAX_TRANSFER_SIZE)) {
4808 len += len_next;
4809 count++;
4810 sg = sg_next_iter;
4811 } else {
4812 break;
4813 }
4814 }
4815
4816 dma_desc_cnt++;
4817 }
4818
4819 return dma_desc_cnt * sizeof(struct packet_lin_dma);
4820}
4821
4822static int gaudi_pin_memory_before_cs(struct hl_device *hdev,
4823 struct hl_cs_parser *parser,
4824 struct packet_lin_dma *user_dma_pkt,
4825 u64 addr, enum dma_data_direction dir)
4826{
4827 struct hl_userptr *userptr;
4828 int rc;
4829
4830 if (hl_userptr_is_pinned(hdev, addr, le32_to_cpu(user_dma_pkt->tsize),
4831 parser->job_userptr_list, &userptr))
4832 goto already_pinned;
4833
4834 userptr = kzalloc(sizeof(*userptr), GFP_ATOMIC);
4835 if (!userptr)
4836 return -ENOMEM;
4837
4838 rc = hl_pin_host_memory(hdev, addr, le32_to_cpu(user_dma_pkt->tsize),
4839 userptr);
4840 if (rc)
4841 goto free_userptr;
4842
4843 list_add_tail(&userptr->job_node, parser->job_userptr_list);
4844
4845 rc = hdev->asic_funcs->asic_dma_map_sg(hdev, userptr->sgt->sgl,
4846 userptr->sgt->nents, dir);
4847 if (rc) {
4848 dev_err(hdev->dev, "failed to map sgt with DMA region\n");
4849 goto unpin_memory;
4850 }
4851
4852 userptr->dma_mapped = true;
4853 userptr->dir = dir;
4854
4855already_pinned:
4856 parser->patched_cb_size +=
4857 gaudi_get_dma_desc_list_size(hdev, userptr->sgt);
4858
4859 return 0;
4860
4861unpin_memory:
4862 hl_unpin_host_memory(hdev, userptr);
4863free_userptr:
4864 kfree(userptr);
4865 return rc;
4866}
4867
4868static int gaudi_validate_dma_pkt_host(struct hl_device *hdev,
4869 struct hl_cs_parser *parser,
4870 struct packet_lin_dma *user_dma_pkt,
4871 bool src_in_host)
4872{
4873 enum dma_data_direction dir;
4874 bool skip_host_mem_pin = false, user_memset;
4875 u64 addr;
4876 int rc = 0;
4877
4878 user_memset = (le32_to_cpu(user_dma_pkt->ctl) &
4879 GAUDI_PKT_LIN_DMA_CTL_MEMSET_MASK) >>
4880 GAUDI_PKT_LIN_DMA_CTL_MEMSET_SHIFT;
4881
4882 if (src_in_host) {
4883 if (user_memset)
4884 skip_host_mem_pin = true;
4885
4886 dev_dbg(hdev->dev, "DMA direction is HOST --> DEVICE\n");
4887 dir = DMA_TO_DEVICE;
4888 addr = le64_to_cpu(user_dma_pkt->src_addr);
4889 } else {
4890 dev_dbg(hdev->dev, "DMA direction is DEVICE --> HOST\n");
4891 dir = DMA_FROM_DEVICE;
4892 addr = (le64_to_cpu(user_dma_pkt->dst_addr) &
4893 GAUDI_PKT_LIN_DMA_DST_ADDR_MASK) >>
4894 GAUDI_PKT_LIN_DMA_DST_ADDR_SHIFT;
4895 }
4896
4897 if (skip_host_mem_pin)
4898 parser->patched_cb_size += sizeof(*user_dma_pkt);
4899 else
4900 rc = gaudi_pin_memory_before_cs(hdev, parser, user_dma_pkt,
4901 addr, dir);
4902
4903 return rc;
4904}
4905
4906static int gaudi_validate_dma_pkt_no_mmu(struct hl_device *hdev,
4907 struct hl_cs_parser *parser,
4908 struct packet_lin_dma *user_dma_pkt)
4909{
4910 bool src_in_host = false;
4911 u64 dst_addr = (le64_to_cpu(user_dma_pkt->dst_addr) &
4912 GAUDI_PKT_LIN_DMA_DST_ADDR_MASK) >>
4913 GAUDI_PKT_LIN_DMA_DST_ADDR_SHIFT;
4914
4915 dev_dbg(hdev->dev, "DMA packet details:\n");
4916 dev_dbg(hdev->dev, "source == 0x%llx\n",
4917 le64_to_cpu(user_dma_pkt->src_addr));
4918 dev_dbg(hdev->dev, "destination == 0x%llx\n", dst_addr);
4919 dev_dbg(hdev->dev, "size == %u\n", le32_to_cpu(user_dma_pkt->tsize));
4920
4921 /*
4922 * Special handling for DMA with size 0. Bypass all validations
4923 * because no transactions will be done except for WR_COMP, which
4924 * is not a security issue
4925 */
4926 if (!le32_to_cpu(user_dma_pkt->tsize)) {
4927 parser->patched_cb_size += sizeof(*user_dma_pkt);
4928 return 0;
4929 }
4930
4931 if (parser->hw_queue_id <= GAUDI_QUEUE_ID_DMA_0_3)
4932 src_in_host = true;
4933
4934 return gaudi_validate_dma_pkt_host(hdev, parser, user_dma_pkt,
4935 src_in_host);
4936}
4937
Oded Gabbay64536ab2020-05-27 12:38:16 +03004938static int gaudi_validate_load_and_exe_pkt(struct hl_device *hdev,
4939 struct hl_cs_parser *parser,
4940 struct packet_load_and_exe *user_pkt)
4941{
4942 u32 cfg;
4943
4944 cfg = le32_to_cpu(user_pkt->cfg);
4945
4946 if (cfg & GAUDI_PKT_LOAD_AND_EXE_CFG_DST_MASK) {
4947 dev_err(hdev->dev,
4948 "User not allowed to use Load and Execute\n");
4949 return -EPERM;
4950 }
4951
4952 parser->patched_cb_size += sizeof(struct packet_load_and_exe);
4953
4954 return 0;
4955}
4956
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03004957static int gaudi_validate_cb(struct hl_device *hdev,
4958 struct hl_cs_parser *parser, bool is_mmu)
4959{
4960 u32 cb_parsed_length = 0;
4961 int rc = 0;
4962
4963 parser->patched_cb_size = 0;
4964
4965 /* cb_user_size is more than 0 so loop will always be executed */
4966 while (cb_parsed_length < parser->user_cb_size) {
4967 enum packet_id pkt_id;
4968 u16 pkt_size;
4969 struct gaudi_packet *user_pkt;
4970
Arnd Bergmann82948e62020-10-26 17:08:06 +01004971 user_pkt = parser->user_cb->kernel_address + cb_parsed_length;
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03004972
4973 pkt_id = (enum packet_id) (
4974 (le64_to_cpu(user_pkt->header) &
4975 PACKET_HEADER_PACKET_ID_MASK) >>
4976 PACKET_HEADER_PACKET_ID_SHIFT);
4977
Ofir Bittonbc75be22020-07-30 14:56:38 +03004978 if (!validate_packet_id(pkt_id)) {
4979 dev_err(hdev->dev, "Invalid packet id %u\n", pkt_id);
4980 rc = -EINVAL;
4981 break;
4982 }
4983
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03004984 pkt_size = gaudi_packet_sizes[pkt_id];
4985 cb_parsed_length += pkt_size;
4986 if (cb_parsed_length > parser->user_cb_size) {
4987 dev_err(hdev->dev,
4988 "packet 0x%x is out of CB boundary\n", pkt_id);
4989 rc = -EINVAL;
4990 break;
4991 }
4992
4993 switch (pkt_id) {
4994 case PACKET_MSG_PROT:
4995 dev_err(hdev->dev,
4996 "User not allowed to use MSG_PROT\n");
4997 rc = -EPERM;
4998 break;
4999
5000 case PACKET_CP_DMA:
5001 dev_err(hdev->dev, "User not allowed to use CP_DMA\n");
5002 rc = -EPERM;
5003 break;
5004
5005 case PACKET_STOP:
5006 dev_err(hdev->dev, "User not allowed to use STOP\n");
5007 rc = -EPERM;
5008 break;
5009
Oded Gabbay2edc66e2020-07-03 19:28:54 +03005010 case PACKET_WREG_BULK:
5011 dev_err(hdev->dev,
5012 "User not allowed to use WREG_BULK\n");
5013 rc = -EPERM;
5014 break;
5015
Oded Gabbay64536ab2020-05-27 12:38:16 +03005016 case PACKET_LOAD_AND_EXE:
5017 rc = gaudi_validate_load_and_exe_pkt(hdev, parser,
5018 (struct packet_load_and_exe *) user_pkt);
5019 break;
5020
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03005021 case PACKET_LIN_DMA:
5022 parser->contains_dma_pkt = true;
5023 if (is_mmu)
5024 parser->patched_cb_size += pkt_size;
5025 else
5026 rc = gaudi_validate_dma_pkt_no_mmu(hdev, parser,
5027 (struct packet_lin_dma *) user_pkt);
5028 break;
5029
5030 case PACKET_WREG_32:
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03005031 case PACKET_MSG_LONG:
5032 case PACKET_MSG_SHORT:
5033 case PACKET_REPEAT:
5034 case PACKET_FENCE:
5035 case PACKET_NOP:
5036 case PACKET_ARB_POINT:
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03005037 parser->patched_cb_size += pkt_size;
5038 break;
5039
5040 default:
5041 dev_err(hdev->dev, "Invalid packet header 0x%x\n",
5042 pkt_id);
5043 rc = -EINVAL;
5044 break;
5045 }
5046
5047 if (rc)
5048 break;
5049 }
5050
5051 /*
5052 * The new CB should have space at the end for two MSG_PROT packets:
5053 * 1. A packet that will act as a completion packet
5054 * 2. A packet that will generate MSI-X interrupt
5055 */
5056 parser->patched_cb_size += sizeof(struct packet_msg_prot) * 2;
5057
5058 return rc;
5059}
5060
5061static int gaudi_patch_dma_packet(struct hl_device *hdev,
5062 struct hl_cs_parser *parser,
5063 struct packet_lin_dma *user_dma_pkt,
5064 struct packet_lin_dma *new_dma_pkt,
5065 u32 *new_dma_pkt_size)
5066{
5067 struct hl_userptr *userptr;
5068 struct scatterlist *sg, *sg_next_iter;
5069 u32 count, dma_desc_cnt, user_wrcomp_en_mask, ctl;
5070 u64 len, len_next;
5071 dma_addr_t dma_addr, dma_addr_next;
5072 u64 device_memory_addr, addr;
5073 enum dma_data_direction dir;
5074 struct sg_table *sgt;
5075 bool src_in_host = false;
5076 bool skip_host_mem_pin = false;
5077 bool user_memset;
5078
5079 ctl = le32_to_cpu(user_dma_pkt->ctl);
5080
5081 if (parser->hw_queue_id <= GAUDI_QUEUE_ID_DMA_0_3)
5082 src_in_host = true;
5083
5084 user_memset = (ctl & GAUDI_PKT_LIN_DMA_CTL_MEMSET_MASK) >>
5085 GAUDI_PKT_LIN_DMA_CTL_MEMSET_SHIFT;
5086
5087 if (src_in_host) {
5088 addr = le64_to_cpu(user_dma_pkt->src_addr);
5089 device_memory_addr = le64_to_cpu(user_dma_pkt->dst_addr);
5090 dir = DMA_TO_DEVICE;
5091 if (user_memset)
5092 skip_host_mem_pin = true;
5093 } else {
5094 addr = le64_to_cpu(user_dma_pkt->dst_addr);
5095 device_memory_addr = le64_to_cpu(user_dma_pkt->src_addr);
5096 dir = DMA_FROM_DEVICE;
5097 }
5098
5099 if ((!skip_host_mem_pin) &&
5100 (!hl_userptr_is_pinned(hdev, addr,
5101 le32_to_cpu(user_dma_pkt->tsize),
5102 parser->job_userptr_list, &userptr))) {
5103 dev_err(hdev->dev, "Userptr 0x%llx + 0x%x NOT mapped\n",
5104 addr, user_dma_pkt->tsize);
5105 return -EFAULT;
5106 }
5107
5108 if ((user_memset) && (dir == DMA_TO_DEVICE)) {
5109 memcpy(new_dma_pkt, user_dma_pkt, sizeof(*user_dma_pkt));
5110 *new_dma_pkt_size = sizeof(*user_dma_pkt);
5111 return 0;
5112 }
5113
5114 user_wrcomp_en_mask = ctl & GAUDI_PKT_LIN_DMA_CTL_WRCOMP_EN_MASK;
5115
5116 sgt = userptr->sgt;
5117 dma_desc_cnt = 0;
5118
5119 for_each_sg(sgt->sgl, sg, sgt->nents, count) {
5120 len = sg_dma_len(sg);
5121 dma_addr = sg_dma_address(sg);
5122
5123 if (len == 0)
5124 break;
5125
5126 while ((count + 1) < sgt->nents) {
5127 sg_next_iter = sg_next(sg);
5128 len_next = sg_dma_len(sg_next_iter);
5129 dma_addr_next = sg_dma_address(sg_next_iter);
5130
5131 if (len_next == 0)
5132 break;
5133
5134 if ((dma_addr + len == dma_addr_next) &&
5135 (len + len_next <= DMA_MAX_TRANSFER_SIZE)) {
5136 len += len_next;
5137 count++;
5138 sg = sg_next_iter;
5139 } else {
5140 break;
5141 }
5142 }
5143
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03005144 ctl = le32_to_cpu(user_dma_pkt->ctl);
5145 if (likely(dma_desc_cnt))
5146 ctl &= ~GAUDI_PKT_CTL_EB_MASK;
5147 ctl &= ~GAUDI_PKT_LIN_DMA_CTL_WRCOMP_EN_MASK;
5148 new_dma_pkt->ctl = cpu_to_le32(ctl);
5149 new_dma_pkt->tsize = cpu_to_le32(len);
5150
5151 if (dir == DMA_TO_DEVICE) {
5152 new_dma_pkt->src_addr = cpu_to_le64(dma_addr);
5153 new_dma_pkt->dst_addr = cpu_to_le64(device_memory_addr);
5154 } else {
5155 new_dma_pkt->src_addr = cpu_to_le64(device_memory_addr);
5156 new_dma_pkt->dst_addr = cpu_to_le64(dma_addr);
5157 }
5158
5159 if (!user_memset)
5160 device_memory_addr += len;
5161 dma_desc_cnt++;
5162 new_dma_pkt++;
5163 }
5164
5165 if (!dma_desc_cnt) {
5166 dev_err(hdev->dev,
5167 "Error of 0 SG entries when patching DMA packet\n");
5168 return -EFAULT;
5169 }
5170
5171 /* Fix the last dma packet - wrcomp must be as user set it */
5172 new_dma_pkt--;
5173 new_dma_pkt->ctl |= cpu_to_le32(user_wrcomp_en_mask);
5174
5175 *new_dma_pkt_size = dma_desc_cnt * sizeof(struct packet_lin_dma);
5176
5177 return 0;
5178}
5179
5180static int gaudi_patch_cb(struct hl_device *hdev,
5181 struct hl_cs_parser *parser)
5182{
5183 u32 cb_parsed_length = 0;
5184 u32 cb_patched_cur_length = 0;
5185 int rc = 0;
5186
5187 /* cb_user_size is more than 0 so loop will always be executed */
5188 while (cb_parsed_length < parser->user_cb_size) {
5189 enum packet_id pkt_id;
5190 u16 pkt_size;
5191 u32 new_pkt_size = 0;
5192 struct gaudi_packet *user_pkt, *kernel_pkt;
5193
Arnd Bergmann82948e62020-10-26 17:08:06 +01005194 user_pkt = parser->user_cb->kernel_address + cb_parsed_length;
5195 kernel_pkt = parser->patched_cb->kernel_address +
5196 cb_patched_cur_length;
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03005197
5198 pkt_id = (enum packet_id) (
5199 (le64_to_cpu(user_pkt->header) &
5200 PACKET_HEADER_PACKET_ID_MASK) >>
5201 PACKET_HEADER_PACKET_ID_SHIFT);
5202
Ofir Bittonbc75be22020-07-30 14:56:38 +03005203 if (!validate_packet_id(pkt_id)) {
5204 dev_err(hdev->dev, "Invalid packet id %u\n", pkt_id);
5205 rc = -EINVAL;
5206 break;
5207 }
5208
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03005209 pkt_size = gaudi_packet_sizes[pkt_id];
5210 cb_parsed_length += pkt_size;
5211 if (cb_parsed_length > parser->user_cb_size) {
5212 dev_err(hdev->dev,
5213 "packet 0x%x is out of CB boundary\n", pkt_id);
5214 rc = -EINVAL;
5215 break;
5216 }
5217
5218 switch (pkt_id) {
5219 case PACKET_LIN_DMA:
5220 rc = gaudi_patch_dma_packet(hdev, parser,
5221 (struct packet_lin_dma *) user_pkt,
5222 (struct packet_lin_dma *) kernel_pkt,
5223 &new_pkt_size);
5224 cb_patched_cur_length += new_pkt_size;
5225 break;
5226
5227 case PACKET_MSG_PROT:
5228 dev_err(hdev->dev,
5229 "User not allowed to use MSG_PROT\n");
5230 rc = -EPERM;
5231 break;
5232
5233 case PACKET_CP_DMA:
5234 dev_err(hdev->dev, "User not allowed to use CP_DMA\n");
5235 rc = -EPERM;
5236 break;
5237
5238 case PACKET_STOP:
5239 dev_err(hdev->dev, "User not allowed to use STOP\n");
5240 rc = -EPERM;
5241 break;
5242
5243 case PACKET_WREG_32:
5244 case PACKET_WREG_BULK:
5245 case PACKET_MSG_LONG:
5246 case PACKET_MSG_SHORT:
5247 case PACKET_REPEAT:
5248 case PACKET_FENCE:
5249 case PACKET_NOP:
5250 case PACKET_ARB_POINT:
5251 case PACKET_LOAD_AND_EXE:
5252 memcpy(kernel_pkt, user_pkt, pkt_size);
5253 cb_patched_cur_length += pkt_size;
5254 break;
5255
5256 default:
5257 dev_err(hdev->dev, "Invalid packet header 0x%x\n",
5258 pkt_id);
5259 rc = -EINVAL;
5260 break;
5261 }
5262
5263 if (rc)
5264 break;
5265 }
5266
5267 return rc;
5268}
5269
5270static int gaudi_parse_cb_mmu(struct hl_device *hdev,
5271 struct hl_cs_parser *parser)
5272{
5273 u64 patched_cb_handle;
5274 u32 patched_cb_size;
5275 struct hl_cb *user_cb;
5276 int rc;
5277
5278 /*
5279 * The new CB should have space at the end for two MSG_PROT pkt:
5280 * 1. A packet that will act as a completion packet
5281 * 2. A packet that will generate MSI interrupt
5282 */
5283 parser->patched_cb_size = parser->user_cb_size +
5284 sizeof(struct packet_msg_prot) * 2;
5285
Tomer Tayarfa8641a12020-09-07 17:36:41 +03005286 rc = hl_cb_create(hdev, &hdev->kernel_cb_mgr, hdev->kernel_ctx,
Tomer Tayaref6a0f62020-07-09 16:17:48 +03005287 parser->patched_cb_size, false, false,
Tomer Tayarfa8641a12020-09-07 17:36:41 +03005288 &patched_cb_handle);
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03005289
5290 if (rc) {
5291 dev_err(hdev->dev,
5292 "Failed to allocate patched CB for DMA CS %d\n",
5293 rc);
5294 return rc;
5295 }
5296
5297 patched_cb_handle >>= PAGE_SHIFT;
5298 parser->patched_cb = hl_cb_get(hdev, &hdev->kernel_cb_mgr,
5299 (u32) patched_cb_handle);
5300 /* hl_cb_get should never fail here so use kernel WARN */
5301 WARN(!parser->patched_cb, "DMA CB handle invalid 0x%x\n",
5302 (u32) patched_cb_handle);
5303 if (!parser->patched_cb) {
5304 rc = -EFAULT;
5305 goto out;
5306 }
5307
5308 /*
5309 * The check that parser->user_cb_size <= parser->user_cb->size was done
5310 * in validate_queue_index().
5311 */
Arnd Bergmann82948e62020-10-26 17:08:06 +01005312 memcpy(parser->patched_cb->kernel_address,
5313 parser->user_cb->kernel_address,
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03005314 parser->user_cb_size);
5315
5316 patched_cb_size = parser->patched_cb_size;
5317
5318 /* Validate patched CB instead of user CB */
5319 user_cb = parser->user_cb;
5320 parser->user_cb = parser->patched_cb;
5321 rc = gaudi_validate_cb(hdev, parser, true);
5322 parser->user_cb = user_cb;
5323
5324 if (rc) {
5325 hl_cb_put(parser->patched_cb);
5326 goto out;
5327 }
5328
5329 if (patched_cb_size != parser->patched_cb_size) {
5330 dev_err(hdev->dev, "user CB size mismatch\n");
5331 hl_cb_put(parser->patched_cb);
5332 rc = -EINVAL;
5333 goto out;
5334 }
5335
5336out:
5337 /*
5338 * Always call cb destroy here because we still have 1 reference
5339 * to it by calling cb_get earlier. After the job will be completed,
5340 * cb_put will release it, but here we want to remove it from the
5341 * idr
5342 */
5343 hl_cb_destroy(hdev, &hdev->kernel_cb_mgr,
5344 patched_cb_handle << PAGE_SHIFT);
5345
5346 return rc;
5347}
5348
5349static int gaudi_parse_cb_no_mmu(struct hl_device *hdev,
5350 struct hl_cs_parser *parser)
5351{
5352 u64 patched_cb_handle;
5353 int rc;
5354
5355 rc = gaudi_validate_cb(hdev, parser, false);
5356
5357 if (rc)
5358 goto free_userptr;
5359
Tomer Tayarfa8641a12020-09-07 17:36:41 +03005360 rc = hl_cb_create(hdev, &hdev->kernel_cb_mgr, hdev->kernel_ctx,
Tomer Tayaref6a0f62020-07-09 16:17:48 +03005361 parser->patched_cb_size, false, false,
Tomer Tayarfa8641a12020-09-07 17:36:41 +03005362 &patched_cb_handle);
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03005363 if (rc) {
5364 dev_err(hdev->dev,
5365 "Failed to allocate patched CB for DMA CS %d\n", rc);
5366 goto free_userptr;
5367 }
5368
5369 patched_cb_handle >>= PAGE_SHIFT;
5370 parser->patched_cb = hl_cb_get(hdev, &hdev->kernel_cb_mgr,
5371 (u32) patched_cb_handle);
5372 /* hl_cb_get should never fail here so use kernel WARN */
5373 WARN(!parser->patched_cb, "DMA CB handle invalid 0x%x\n",
5374 (u32) patched_cb_handle);
5375 if (!parser->patched_cb) {
5376 rc = -EFAULT;
5377 goto out;
5378 }
5379
5380 rc = gaudi_patch_cb(hdev, parser);
5381
5382 if (rc)
5383 hl_cb_put(parser->patched_cb);
5384
5385out:
5386 /*
5387 * Always call cb destroy here because we still have 1 reference
5388 * to it by calling cb_get earlier. After the job will be completed,
5389 * cb_put will release it, but here we want to remove it from the
5390 * idr
5391 */
5392 hl_cb_destroy(hdev, &hdev->kernel_cb_mgr,
5393 patched_cb_handle << PAGE_SHIFT);
5394
5395free_userptr:
5396 if (rc)
5397 hl_userptr_delete_list(hdev, parser->job_userptr_list);
5398 return rc;
5399}
5400
5401static int gaudi_parse_cb_no_ext_queue(struct hl_device *hdev,
5402 struct hl_cs_parser *parser)
5403{
5404 struct asic_fixed_properties *asic_prop = &hdev->asic_prop;
Oded Gabbay3c681572020-11-02 21:10:39 +02005405 struct gaudi_device *gaudi = hdev->asic_specific;
5406 u32 nic_mask_q_id = 1 << (HW_CAP_NIC_SHIFT +
5407 ((parser->hw_queue_id - GAUDI_QUEUE_ID_NIC_0_0) >> 2));
5408
5409 if ((parser->hw_queue_id >= GAUDI_QUEUE_ID_NIC_0_0) &&
5410 (parser->hw_queue_id <= GAUDI_QUEUE_ID_NIC_9_3) &&
5411 (!(gaudi->hw_cap_initialized & nic_mask_q_id))) {
5412 dev_err(hdev->dev, "h/w queue %d is disabled\n",
5413 parser->hw_queue_id);
5414 return -EINVAL;
5415 }
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03005416
5417 /* For internal queue jobs just check if CB address is valid */
5418 if (hl_mem_area_inside_range((u64) (uintptr_t) parser->user_cb,
5419 parser->user_cb_size,
5420 asic_prop->sram_user_base_address,
5421 asic_prop->sram_end_address))
5422 return 0;
5423
5424 if (hl_mem_area_inside_range((u64) (uintptr_t) parser->user_cb,
5425 parser->user_cb_size,
5426 asic_prop->dram_user_base_address,
5427 asic_prop->dram_end_address))
5428 return 0;
5429
5430 /* PMMU and HPMMU addresses are equal, check only one of them */
5431 if (hl_mem_area_inside_range((u64) (uintptr_t) parser->user_cb,
5432 parser->user_cb_size,
5433 asic_prop->pmmu.start_addr,
5434 asic_prop->pmmu.end_addr))
5435 return 0;
5436
5437 dev_err(hdev->dev,
5438 "CB address 0x%px + 0x%x for internal QMAN is not valid\n",
5439 parser->user_cb, parser->user_cb_size);
5440
5441 return -EFAULT;
5442}
5443
5444static int gaudi_cs_parser(struct hl_device *hdev, struct hl_cs_parser *parser)
5445{
5446 struct gaudi_device *gaudi = hdev->asic_specific;
5447
5448 if (parser->queue_type == QUEUE_TYPE_INT)
5449 return gaudi_parse_cb_no_ext_queue(hdev, parser);
5450
5451 if (gaudi->hw_cap_initialized & HW_CAP_MMU)
5452 return gaudi_parse_cb_mmu(hdev, parser);
5453 else
5454 return gaudi_parse_cb_no_mmu(hdev, parser);
5455}
5456
5457static void gaudi_add_end_of_cb_packets(struct hl_device *hdev,
Arnd Bergmann82948e62020-10-26 17:08:06 +01005458 void *kernel_address, u32 len,
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03005459 u64 cq_addr, u32 cq_val, u32 msi_vec,
5460 bool eb)
5461{
5462 struct gaudi_device *gaudi = hdev->asic_specific;
5463 struct packet_msg_prot *cq_pkt;
5464 u32 tmp;
5465
Arnd Bergmann82948e62020-10-26 17:08:06 +01005466 cq_pkt = kernel_address + len - (sizeof(struct packet_msg_prot) * 2);
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03005467
Oded Gabbay65887292020-08-12 11:21:01 +03005468 tmp = FIELD_PREP(GAUDI_PKT_CTL_OPCODE_MASK, PACKET_MSG_PROT);
5469 tmp |= FIELD_PREP(GAUDI_PKT_CTL_MB_MASK, 1);
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03005470
5471 if (eb)
Oded Gabbay65887292020-08-12 11:21:01 +03005472 tmp |= FIELD_PREP(GAUDI_PKT_CTL_EB_MASK, 1);
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03005473
5474 cq_pkt->ctl = cpu_to_le32(tmp);
5475 cq_pkt->value = cpu_to_le32(cq_val);
5476 cq_pkt->addr = cpu_to_le64(cq_addr);
5477
5478 cq_pkt++;
5479
Oded Gabbay65887292020-08-12 11:21:01 +03005480 tmp = FIELD_PREP(GAUDI_PKT_CTL_OPCODE_MASK, PACKET_MSG_PROT);
5481 tmp |= FIELD_PREP(GAUDI_PKT_CTL_MB_MASK, 1);
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03005482 cq_pkt->ctl = cpu_to_le32(tmp);
5483 cq_pkt->value = cpu_to_le32(1);
5484
5485 if (!gaudi->multi_msi_mode)
5486 msi_vec = 0;
5487
5488 cq_pkt->addr = cpu_to_le64(CFG_BASE + mmPCIE_MSI_INTR_0 + msi_vec * 4);
5489}
5490
5491static void gaudi_update_eq_ci(struct hl_device *hdev, u32 val)
5492{
5493 WREG32(mmCPU_IF_EQ_RD_OFFS, val);
5494}
5495
5496static int gaudi_memset_device_memory(struct hl_device *hdev, u64 addr,
5497 u32 size, u64 val)
5498{
5499 struct packet_lin_dma *lin_dma_pkt;
5500 struct hl_cs_job *job;
Moti Haimovskia9855a2d92020-06-24 19:40:57 +03005501 u32 cb_size, ctl, err_cause;
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03005502 struct hl_cb *cb;
5503 int rc;
5504
Ofir Bittona04b7cd2020-07-13 13:36:55 +03005505 cb = hl_cb_kernel_create(hdev, PAGE_SIZE, false);
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03005506 if (!cb)
5507 return -EFAULT;
5508
Arnd Bergmann82948e62020-10-26 17:08:06 +01005509 lin_dma_pkt = cb->kernel_address;
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03005510 memset(lin_dma_pkt, 0, sizeof(*lin_dma_pkt));
5511 cb_size = sizeof(*lin_dma_pkt);
5512
Oded Gabbay65887292020-08-12 11:21:01 +03005513 ctl = FIELD_PREP(GAUDI_PKT_CTL_OPCODE_MASK, PACKET_LIN_DMA);
5514 ctl |= FIELD_PREP(GAUDI_PKT_LIN_DMA_CTL_MEMSET_MASK, 1);
5515 ctl |= FIELD_PREP(GAUDI_PKT_LIN_DMA_CTL_LIN_MASK, 1);
5516 ctl |= FIELD_PREP(GAUDI_PKT_CTL_MB_MASK, 1);
5517 ctl |= FIELD_PREP(GAUDI_PKT_CTL_RB_MASK, 1);
5518
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03005519 lin_dma_pkt->ctl = cpu_to_le32(ctl);
5520 lin_dma_pkt->src_addr = cpu_to_le64(val);
5521 lin_dma_pkt->dst_addr |= cpu_to_le64(addr);
5522 lin_dma_pkt->tsize = cpu_to_le32(size);
5523
5524 job = hl_cs_allocate_job(hdev, QUEUE_TYPE_EXT, true);
5525 if (!job) {
5526 dev_err(hdev->dev, "Failed to allocate a new job\n");
5527 rc = -ENOMEM;
5528 goto release_cb;
5529 }
5530
Moti Haimovskia9855a2d92020-06-24 19:40:57 +03005531 /* Verify DMA is OK */
5532 err_cause = RREG32(mmDMA0_CORE_ERR_CAUSE);
5533 if (err_cause && !hdev->init_done) {
5534 dev_dbg(hdev->dev,
5535 "Clearing DMA0 engine from errors (cause 0x%x)\n",
5536 err_cause);
5537 WREG32(mmDMA0_CORE_ERR_CAUSE, err_cause);
5538 }
5539
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03005540 job->id = 0;
5541 job->user_cb = cb;
Tomer Tayarf07486742020-08-02 22:51:31 +03005542 atomic_inc(&job->user_cb->cs_cnt);
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03005543 job->user_cb_size = cb_size;
5544 job->hw_queue_id = GAUDI_QUEUE_ID_DMA_0_0;
5545 job->patched_cb = job->user_cb;
5546 job->job_cb_size = job->user_cb_size + sizeof(struct packet_msg_prot);
5547
5548 hl_debugfs_add_job(hdev, job);
5549
5550 rc = gaudi_send_job_on_qman0(hdev, job);
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03005551 hl_debugfs_remove_job(hdev, job);
5552 kfree(job);
Tomer Tayarf07486742020-08-02 22:51:31 +03005553 atomic_dec(&cb->cs_cnt);
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03005554
Moti Haimovskia9855a2d92020-06-24 19:40:57 +03005555 /* Verify DMA is OK */
5556 err_cause = RREG32(mmDMA0_CORE_ERR_CAUSE);
5557 if (err_cause) {
5558 dev_err(hdev->dev, "DMA Failed, cause 0x%x\n", err_cause);
5559 rc = -EIO;
5560 if (!hdev->init_done) {
5561 dev_dbg(hdev->dev,
5562 "Clearing DMA0 engine from errors (cause 0x%x)\n",
5563 err_cause);
5564 WREG32(mmDMA0_CORE_ERR_CAUSE, err_cause);
5565 }
5566 }
5567
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03005568release_cb:
5569 hl_cb_put(cb);
5570 hl_cb_destroy(hdev, &hdev->kernel_cb_mgr, cb->id << PAGE_SHIFT);
5571
5572 return rc;
5573}
5574
5575static void gaudi_restore_sm_registers(struct hl_device *hdev)
5576{
5577 int i;
5578
5579 for (i = 0 ; i < NUM_OF_SOB_IN_BLOCK << 2 ; i += 4) {
5580 WREG32(mmSYNC_MNGR_E_N_SYNC_MNGR_OBJS_SOB_OBJ_0 + i, 0);
5581 WREG32(mmSYNC_MNGR_E_S_SYNC_MNGR_OBJS_SOB_OBJ_0 + i, 0);
5582 WREG32(mmSYNC_MNGR_W_N_SYNC_MNGR_OBJS_SOB_OBJ_0 + i, 0);
5583 }
5584
5585 for (i = 0 ; i < NUM_OF_MONITORS_IN_BLOCK << 2 ; i += 4) {
5586 WREG32(mmSYNC_MNGR_E_N_SYNC_MNGR_OBJS_MON_STATUS_0 + i, 0);
5587 WREG32(mmSYNC_MNGR_E_S_SYNC_MNGR_OBJS_MON_STATUS_0 + i, 0);
5588 WREG32(mmSYNC_MNGR_W_N_SYNC_MNGR_OBJS_MON_STATUS_0 + i, 0);
5589 }
5590
5591 i = GAUDI_FIRST_AVAILABLE_W_S_SYNC_OBJECT * 4;
5592
5593 for (; i < NUM_OF_SOB_IN_BLOCK << 2 ; i += 4)
5594 WREG32(mmSYNC_MNGR_W_S_SYNC_MNGR_OBJS_SOB_OBJ_0 + i, 0);
5595
5596 i = GAUDI_FIRST_AVAILABLE_W_S_MONITOR * 4;
5597
5598 for (; i < NUM_OF_MONITORS_IN_BLOCK << 2 ; i += 4)
5599 WREG32(mmSYNC_MNGR_W_S_SYNC_MNGR_OBJS_MON_STATUS_0 + i, 0);
5600}
5601
5602static void gaudi_restore_dma_registers(struct hl_device *hdev)
5603{
5604 u32 sob_delta = mmSYNC_MNGR_E_N_SYNC_MNGR_OBJS_SOB_OBJ_1 -
5605 mmSYNC_MNGR_E_N_SYNC_MNGR_OBJS_SOB_OBJ_0;
5606 int i;
5607
5608 for (i = 0 ; i < DMA_NUMBER_OF_CHANNELS ; i++) {
5609 u64 sob_addr = CFG_BASE +
5610 mmSYNC_MNGR_E_N_SYNC_MNGR_OBJS_SOB_OBJ_0 +
5611 (i * sob_delta);
5612 u32 dma_offset = i * DMA_CORE_OFFSET;
5613
5614 WREG32(mmDMA0_CORE_WR_COMP_ADDR_LO + dma_offset,
5615 lower_32_bits(sob_addr));
5616 WREG32(mmDMA0_CORE_WR_COMP_ADDR_HI + dma_offset,
5617 upper_32_bits(sob_addr));
5618 WREG32(mmDMA0_CORE_WR_COMP_WDATA + dma_offset, 0x80000001);
5619
5620 /* For DMAs 2-7, need to restore WR_AWUSER_31_11 as it can be
5621 * modified by the user for SRAM reduction
5622 */
5623 if (i > 1)
5624 WREG32(mmDMA0_CORE_WR_AWUSER_31_11 + dma_offset,
5625 0x00000001);
5626 }
5627}
5628
5629static void gaudi_restore_qm_registers(struct hl_device *hdev)
5630{
5631 u32 qman_offset;
5632 int i;
5633
5634 for (i = 0 ; i < DMA_NUMBER_OF_CHANNELS ; i++) {
5635 qman_offset = i * DMA_QMAN_OFFSET;
5636 WREG32(mmDMA0_QM_ARB_CFG_0 + qman_offset, 0);
5637 }
5638
5639 for (i = 0 ; i < MME_NUMBER_OF_MASTER_ENGINES ; i++) {
5640 qman_offset = i * (mmMME2_QM_BASE - mmMME0_QM_BASE);
5641 WREG32(mmMME0_QM_ARB_CFG_0 + qman_offset, 0);
5642 }
5643
5644 for (i = 0 ; i < TPC_NUMBER_OF_ENGINES ; i++) {
5645 qman_offset = i * TPC_QMAN_OFFSET;
5646 WREG32(mmTPC0_QM_ARB_CFG_0 + qman_offset, 0);
5647 }
Oded Gabbay3c681572020-11-02 21:10:39 +02005648
5649 for (i = 0 ; i < NIC_NUMBER_OF_ENGINES ; i++) {
5650 qman_offset = (i >> 1) * NIC_MACRO_QMAN_OFFSET +
5651 (i & 0x1) * NIC_ENGINE_QMAN_OFFSET;
5652 WREG32(mmNIC0_QM0_ARB_CFG_0 + qman_offset, 0);
5653 }
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03005654}
5655
5656static void gaudi_restore_user_registers(struct hl_device *hdev)
5657{
5658 gaudi_restore_sm_registers(hdev);
5659 gaudi_restore_dma_registers(hdev);
5660 gaudi_restore_qm_registers(hdev);
5661}
5662
5663static int gaudi_context_switch(struct hl_device *hdev, u32 asid)
5664{
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03005665 gaudi_restore_user_registers(hdev);
5666
5667 return 0;
5668}
5669
5670static int gaudi_mmu_clear_pgt_range(struct hl_device *hdev)
5671{
5672 struct asic_fixed_properties *prop = &hdev->asic_prop;
5673 struct gaudi_device *gaudi = hdev->asic_specific;
5674 u64 addr = prop->mmu_pgt_addr;
5675 u32 size = prop->mmu_pgt_size + MMU_CACHE_MNG_SIZE;
5676
5677 if (!(gaudi->hw_cap_initialized & HW_CAP_MMU))
5678 return 0;
5679
5680 return gaudi_memset_device_memory(hdev, addr, size, 0);
5681}
5682
5683static void gaudi_restore_phase_topology(struct hl_device *hdev)
5684{
5685
5686}
5687
5688static int gaudi_debugfs_read32(struct hl_device *hdev, u64 addr, u32 *val)
5689{
5690 struct asic_fixed_properties *prop = &hdev->asic_prop;
5691 struct gaudi_device *gaudi = hdev->asic_specific;
5692 u64 hbm_bar_addr;
5693 int rc = 0;
5694
5695 if ((addr >= CFG_BASE) && (addr < CFG_BASE + CFG_SIZE)) {
Oded Gabbaye38bfd32020-07-03 20:46:12 +03005696
5697 if ((gaudi->hw_cap_initialized & HW_CAP_CLK_GATE) &&
5698 (hdev->clock_gating_mask &
5699 GAUDI_CLK_GATE_DEBUGFS_MASK)) {
5700
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03005701 dev_err_ratelimited(hdev->dev,
5702 "Can't read register - clock gating is enabled!\n");
5703 rc = -EFAULT;
5704 } else {
5705 *val = RREG32(addr - CFG_BASE);
5706 }
Oded Gabbaye38bfd32020-07-03 20:46:12 +03005707
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03005708 } else if ((addr >= SRAM_BASE_ADDR) &&
5709 (addr < SRAM_BASE_ADDR + SRAM_BAR_SIZE)) {
5710 *val = readl(hdev->pcie_bar[SRAM_BAR_ID] +
5711 (addr - SRAM_BASE_ADDR));
5712 } else if (addr < DRAM_PHYS_BASE + hdev->asic_prop.dram_size) {
5713 u64 bar_base_addr = DRAM_PHYS_BASE +
5714 (addr & ~(prop->dram_pci_bar_size - 0x1ull));
5715
5716 hbm_bar_addr = gaudi_set_hbm_bar_base(hdev, bar_base_addr);
5717 if (hbm_bar_addr != U64_MAX) {
5718 *val = readl(hdev->pcie_bar[HBM_BAR_ID] +
5719 (addr - bar_base_addr));
5720
5721 hbm_bar_addr = gaudi_set_hbm_bar_base(hdev,
5722 hbm_bar_addr);
5723 }
5724 if (hbm_bar_addr == U64_MAX)
5725 rc = -EIO;
5726 } else if (addr >= HOST_PHYS_BASE && !iommu_present(&pci_bus_type)) {
5727 *val = *(u32 *) phys_to_virt(addr - HOST_PHYS_BASE);
5728 } else {
5729 rc = -EFAULT;
5730 }
5731
5732 return rc;
5733}
5734
5735static int gaudi_debugfs_write32(struct hl_device *hdev, u64 addr, u32 val)
5736{
5737 struct asic_fixed_properties *prop = &hdev->asic_prop;
5738 struct gaudi_device *gaudi = hdev->asic_specific;
5739 u64 hbm_bar_addr;
5740 int rc = 0;
5741
5742 if ((addr >= CFG_BASE) && (addr < CFG_BASE + CFG_SIZE)) {
Oded Gabbaye38bfd32020-07-03 20:46:12 +03005743
5744 if ((gaudi->hw_cap_initialized & HW_CAP_CLK_GATE) &&
5745 (hdev->clock_gating_mask &
5746 GAUDI_CLK_GATE_DEBUGFS_MASK)) {
5747
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03005748 dev_err_ratelimited(hdev->dev,
5749 "Can't write register - clock gating is enabled!\n");
5750 rc = -EFAULT;
5751 } else {
5752 WREG32(addr - CFG_BASE, val);
5753 }
Oded Gabbaye38bfd32020-07-03 20:46:12 +03005754
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03005755 } else if ((addr >= SRAM_BASE_ADDR) &&
5756 (addr < SRAM_BASE_ADDR + SRAM_BAR_SIZE)) {
5757 writel(val, hdev->pcie_bar[SRAM_BAR_ID] +
5758 (addr - SRAM_BASE_ADDR));
5759 } else if (addr < DRAM_PHYS_BASE + hdev->asic_prop.dram_size) {
5760 u64 bar_base_addr = DRAM_PHYS_BASE +
5761 (addr & ~(prop->dram_pci_bar_size - 0x1ull));
5762
5763 hbm_bar_addr = gaudi_set_hbm_bar_base(hdev, bar_base_addr);
5764 if (hbm_bar_addr != U64_MAX) {
5765 writel(val, hdev->pcie_bar[HBM_BAR_ID] +
5766 (addr - bar_base_addr));
5767
5768 hbm_bar_addr = gaudi_set_hbm_bar_base(hdev,
5769 hbm_bar_addr);
5770 }
5771 if (hbm_bar_addr == U64_MAX)
5772 rc = -EIO;
5773 } else if (addr >= HOST_PHYS_BASE && !iommu_present(&pci_bus_type)) {
5774 *(u32 *) phys_to_virt(addr - HOST_PHYS_BASE) = val;
5775 } else {
5776 rc = -EFAULT;
5777 }
5778
5779 return rc;
5780}
5781
5782static int gaudi_debugfs_read64(struct hl_device *hdev, u64 addr, u64 *val)
5783{
5784 struct asic_fixed_properties *prop = &hdev->asic_prop;
5785 struct gaudi_device *gaudi = hdev->asic_specific;
5786 u64 hbm_bar_addr;
5787 int rc = 0;
5788
5789 if ((addr >= CFG_BASE) && (addr <= CFG_BASE + CFG_SIZE - sizeof(u64))) {
Oded Gabbaye38bfd32020-07-03 20:46:12 +03005790
5791 if ((gaudi->hw_cap_initialized & HW_CAP_CLK_GATE) &&
5792 (hdev->clock_gating_mask &
5793 GAUDI_CLK_GATE_DEBUGFS_MASK)) {
5794
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03005795 dev_err_ratelimited(hdev->dev,
5796 "Can't read register - clock gating is enabled!\n");
5797 rc = -EFAULT;
5798 } else {
5799 u32 val_l = RREG32(addr - CFG_BASE);
5800 u32 val_h = RREG32(addr + sizeof(u32) - CFG_BASE);
5801
5802 *val = (((u64) val_h) << 32) | val_l;
5803 }
Oded Gabbaye38bfd32020-07-03 20:46:12 +03005804
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03005805 } else if ((addr >= SRAM_BASE_ADDR) &&
5806 (addr <= SRAM_BASE_ADDR + SRAM_BAR_SIZE - sizeof(u64))) {
5807 *val = readq(hdev->pcie_bar[SRAM_BAR_ID] +
5808 (addr - SRAM_BASE_ADDR));
5809 } else if (addr <=
5810 DRAM_PHYS_BASE + hdev->asic_prop.dram_size - sizeof(u64)) {
5811 u64 bar_base_addr = DRAM_PHYS_BASE +
5812 (addr & ~(prop->dram_pci_bar_size - 0x1ull));
5813
5814 hbm_bar_addr = gaudi_set_hbm_bar_base(hdev, bar_base_addr);
5815 if (hbm_bar_addr != U64_MAX) {
5816 *val = readq(hdev->pcie_bar[HBM_BAR_ID] +
5817 (addr - bar_base_addr));
5818
5819 hbm_bar_addr = gaudi_set_hbm_bar_base(hdev,
5820 hbm_bar_addr);
5821 }
5822 if (hbm_bar_addr == U64_MAX)
5823 rc = -EIO;
5824 } else if (addr >= HOST_PHYS_BASE && !iommu_present(&pci_bus_type)) {
5825 *val = *(u64 *) phys_to_virt(addr - HOST_PHYS_BASE);
5826 } else {
5827 rc = -EFAULT;
5828 }
5829
5830 return rc;
5831}
5832
5833static int gaudi_debugfs_write64(struct hl_device *hdev, u64 addr, u64 val)
5834{
5835 struct asic_fixed_properties *prop = &hdev->asic_prop;
5836 struct gaudi_device *gaudi = hdev->asic_specific;
5837 u64 hbm_bar_addr;
5838 int rc = 0;
5839
5840 if ((addr >= CFG_BASE) && (addr <= CFG_BASE + CFG_SIZE - sizeof(u64))) {
Oded Gabbaye38bfd32020-07-03 20:46:12 +03005841
5842 if ((gaudi->hw_cap_initialized & HW_CAP_CLK_GATE) &&
5843 (hdev->clock_gating_mask &
5844 GAUDI_CLK_GATE_DEBUGFS_MASK)) {
5845
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03005846 dev_err_ratelimited(hdev->dev,
5847 "Can't write register - clock gating is enabled!\n");
5848 rc = -EFAULT;
5849 } else {
5850 WREG32(addr - CFG_BASE, lower_32_bits(val));
5851 WREG32(addr + sizeof(u32) - CFG_BASE,
5852 upper_32_bits(val));
5853 }
Oded Gabbaye38bfd32020-07-03 20:46:12 +03005854
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03005855 } else if ((addr >= SRAM_BASE_ADDR) &&
5856 (addr <= SRAM_BASE_ADDR + SRAM_BAR_SIZE - sizeof(u64))) {
5857 writeq(val, hdev->pcie_bar[SRAM_BAR_ID] +
5858 (addr - SRAM_BASE_ADDR));
5859 } else if (addr <=
5860 DRAM_PHYS_BASE + hdev->asic_prop.dram_size - sizeof(u64)) {
5861 u64 bar_base_addr = DRAM_PHYS_BASE +
5862 (addr & ~(prop->dram_pci_bar_size - 0x1ull));
5863
5864 hbm_bar_addr = gaudi_set_hbm_bar_base(hdev, bar_base_addr);
5865 if (hbm_bar_addr != U64_MAX) {
5866 writeq(val, hdev->pcie_bar[HBM_BAR_ID] +
5867 (addr - bar_base_addr));
5868
5869 hbm_bar_addr = gaudi_set_hbm_bar_base(hdev,
5870 hbm_bar_addr);
5871 }
5872 if (hbm_bar_addr == U64_MAX)
5873 rc = -EIO;
5874 } else if (addr >= HOST_PHYS_BASE && !iommu_present(&pci_bus_type)) {
5875 *(u64 *) phys_to_virt(addr - HOST_PHYS_BASE) = val;
5876 } else {
5877 rc = -EFAULT;
5878 }
5879
5880 return rc;
5881}
5882
5883static u64 gaudi_read_pte(struct hl_device *hdev, u64 addr)
5884{
5885 struct gaudi_device *gaudi = hdev->asic_specific;
5886
5887 if (hdev->hard_reset_pending)
5888 return U64_MAX;
5889
5890 return readq(hdev->pcie_bar[HBM_BAR_ID] +
5891 (addr - gaudi->hbm_bar_cur_addr));
5892}
5893
5894static void gaudi_write_pte(struct hl_device *hdev, u64 addr, u64 val)
5895{
5896 struct gaudi_device *gaudi = hdev->asic_specific;
5897
5898 if (hdev->hard_reset_pending)
5899 return;
5900
5901 writeq(val, hdev->pcie_bar[HBM_BAR_ID] +
5902 (addr - gaudi->hbm_bar_cur_addr));
5903}
5904
Ofir Bitton1137e1e2020-09-30 18:43:52 +03005905void gaudi_mmu_prepare_reg(struct hl_device *hdev, u64 reg, u32 asid)
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03005906{
5907 /* mask to zero the MMBP and ASID bits */
5908 WREG32_AND(reg, ~0x7FF);
5909 WREG32_OR(reg, asid);
5910}
5911
5912static void gaudi_mmu_prepare(struct hl_device *hdev, u32 asid)
5913{
5914 struct gaudi_device *gaudi = hdev->asic_specific;
5915
5916 if (!(gaudi->hw_cap_initialized & HW_CAP_MMU))
5917 return;
5918
5919 if (asid & ~DMA0_QM_GLBL_NON_SECURE_PROPS_0_ASID_MASK) {
5920 WARN(1, "asid %u is too big\n", asid);
5921 return;
5922 }
5923
5924 mutex_lock(&gaudi->clk_gate_mutex);
5925
5926 hdev->asic_funcs->disable_clock_gating(hdev);
5927
5928 gaudi_mmu_prepare_reg(hdev, mmDMA0_QM_GLBL_NON_SECURE_PROPS_0, asid);
5929 gaudi_mmu_prepare_reg(hdev, mmDMA0_QM_GLBL_NON_SECURE_PROPS_1, asid);
5930 gaudi_mmu_prepare_reg(hdev, mmDMA0_QM_GLBL_NON_SECURE_PROPS_2, asid);
5931 gaudi_mmu_prepare_reg(hdev, mmDMA0_QM_GLBL_NON_SECURE_PROPS_3, asid);
5932 gaudi_mmu_prepare_reg(hdev, mmDMA0_QM_GLBL_NON_SECURE_PROPS_4, asid);
5933
5934 gaudi_mmu_prepare_reg(hdev, mmDMA1_QM_GLBL_NON_SECURE_PROPS_0, asid);
5935 gaudi_mmu_prepare_reg(hdev, mmDMA1_QM_GLBL_NON_SECURE_PROPS_1, asid);
5936 gaudi_mmu_prepare_reg(hdev, mmDMA1_QM_GLBL_NON_SECURE_PROPS_2, asid);
5937 gaudi_mmu_prepare_reg(hdev, mmDMA1_QM_GLBL_NON_SECURE_PROPS_3, asid);
5938 gaudi_mmu_prepare_reg(hdev, mmDMA1_QM_GLBL_NON_SECURE_PROPS_4, asid);
5939
5940 gaudi_mmu_prepare_reg(hdev, mmDMA2_QM_GLBL_NON_SECURE_PROPS_0, asid);
5941 gaudi_mmu_prepare_reg(hdev, mmDMA2_QM_GLBL_NON_SECURE_PROPS_1, asid);
5942 gaudi_mmu_prepare_reg(hdev, mmDMA2_QM_GLBL_NON_SECURE_PROPS_2, asid);
5943 gaudi_mmu_prepare_reg(hdev, mmDMA2_QM_GLBL_NON_SECURE_PROPS_3, asid);
5944 gaudi_mmu_prepare_reg(hdev, mmDMA2_QM_GLBL_NON_SECURE_PROPS_4, asid);
5945
5946 gaudi_mmu_prepare_reg(hdev, mmDMA3_QM_GLBL_NON_SECURE_PROPS_0, asid);
5947 gaudi_mmu_prepare_reg(hdev, mmDMA3_QM_GLBL_NON_SECURE_PROPS_1, asid);
5948 gaudi_mmu_prepare_reg(hdev, mmDMA3_QM_GLBL_NON_SECURE_PROPS_2, asid);
5949 gaudi_mmu_prepare_reg(hdev, mmDMA3_QM_GLBL_NON_SECURE_PROPS_3, asid);
5950 gaudi_mmu_prepare_reg(hdev, mmDMA3_QM_GLBL_NON_SECURE_PROPS_4, asid);
5951
5952 gaudi_mmu_prepare_reg(hdev, mmDMA4_QM_GLBL_NON_SECURE_PROPS_0, asid);
5953 gaudi_mmu_prepare_reg(hdev, mmDMA4_QM_GLBL_NON_SECURE_PROPS_1, asid);
5954 gaudi_mmu_prepare_reg(hdev, mmDMA4_QM_GLBL_NON_SECURE_PROPS_2, asid);
5955 gaudi_mmu_prepare_reg(hdev, mmDMA4_QM_GLBL_NON_SECURE_PROPS_3, asid);
5956 gaudi_mmu_prepare_reg(hdev, mmDMA4_QM_GLBL_NON_SECURE_PROPS_4, asid);
5957
5958 gaudi_mmu_prepare_reg(hdev, mmDMA5_QM_GLBL_NON_SECURE_PROPS_0, asid);
5959 gaudi_mmu_prepare_reg(hdev, mmDMA5_QM_GLBL_NON_SECURE_PROPS_1, asid);
5960 gaudi_mmu_prepare_reg(hdev, mmDMA5_QM_GLBL_NON_SECURE_PROPS_2, asid);
5961 gaudi_mmu_prepare_reg(hdev, mmDMA5_QM_GLBL_NON_SECURE_PROPS_3, asid);
5962 gaudi_mmu_prepare_reg(hdev, mmDMA5_QM_GLBL_NON_SECURE_PROPS_4, asid);
5963
5964 gaudi_mmu_prepare_reg(hdev, mmDMA6_QM_GLBL_NON_SECURE_PROPS_0, asid);
5965 gaudi_mmu_prepare_reg(hdev, mmDMA6_QM_GLBL_NON_SECURE_PROPS_1, asid);
5966 gaudi_mmu_prepare_reg(hdev, mmDMA6_QM_GLBL_NON_SECURE_PROPS_2, asid);
5967 gaudi_mmu_prepare_reg(hdev, mmDMA6_QM_GLBL_NON_SECURE_PROPS_3, asid);
5968 gaudi_mmu_prepare_reg(hdev, mmDMA6_QM_GLBL_NON_SECURE_PROPS_4, asid);
5969
5970 gaudi_mmu_prepare_reg(hdev, mmDMA7_QM_GLBL_NON_SECURE_PROPS_0, asid);
5971 gaudi_mmu_prepare_reg(hdev, mmDMA7_QM_GLBL_NON_SECURE_PROPS_1, asid);
5972 gaudi_mmu_prepare_reg(hdev, mmDMA7_QM_GLBL_NON_SECURE_PROPS_2, asid);
5973 gaudi_mmu_prepare_reg(hdev, mmDMA7_QM_GLBL_NON_SECURE_PROPS_3, asid);
5974 gaudi_mmu_prepare_reg(hdev, mmDMA7_QM_GLBL_NON_SECURE_PROPS_4, asid);
5975
5976 gaudi_mmu_prepare_reg(hdev, mmDMA0_CORE_NON_SECURE_PROPS, asid);
5977 gaudi_mmu_prepare_reg(hdev, mmDMA1_CORE_NON_SECURE_PROPS, asid);
5978 gaudi_mmu_prepare_reg(hdev, mmDMA2_CORE_NON_SECURE_PROPS, asid);
5979 gaudi_mmu_prepare_reg(hdev, mmDMA3_CORE_NON_SECURE_PROPS, asid);
5980 gaudi_mmu_prepare_reg(hdev, mmDMA4_CORE_NON_SECURE_PROPS, asid);
5981 gaudi_mmu_prepare_reg(hdev, mmDMA5_CORE_NON_SECURE_PROPS, asid);
5982 gaudi_mmu_prepare_reg(hdev, mmDMA6_CORE_NON_SECURE_PROPS, asid);
5983 gaudi_mmu_prepare_reg(hdev, mmDMA7_CORE_NON_SECURE_PROPS, asid);
5984
5985 gaudi_mmu_prepare_reg(hdev, mmTPC0_QM_GLBL_NON_SECURE_PROPS_0, asid);
5986 gaudi_mmu_prepare_reg(hdev, mmTPC0_QM_GLBL_NON_SECURE_PROPS_1, asid);
5987 gaudi_mmu_prepare_reg(hdev, mmTPC0_QM_GLBL_NON_SECURE_PROPS_2, asid);
5988 gaudi_mmu_prepare_reg(hdev, mmTPC0_QM_GLBL_NON_SECURE_PROPS_3, asid);
5989 gaudi_mmu_prepare_reg(hdev, mmTPC0_QM_GLBL_NON_SECURE_PROPS_4, asid);
5990 gaudi_mmu_prepare_reg(hdev, mmTPC0_CFG_ARUSER_LO, asid);
5991 gaudi_mmu_prepare_reg(hdev, mmTPC0_CFG_AWUSER_LO, asid);
5992
5993 gaudi_mmu_prepare_reg(hdev, mmTPC1_QM_GLBL_NON_SECURE_PROPS_0, asid);
5994 gaudi_mmu_prepare_reg(hdev, mmTPC1_QM_GLBL_NON_SECURE_PROPS_1, asid);
5995 gaudi_mmu_prepare_reg(hdev, mmTPC1_QM_GLBL_NON_SECURE_PROPS_2, asid);
5996 gaudi_mmu_prepare_reg(hdev, mmTPC1_QM_GLBL_NON_SECURE_PROPS_3, asid);
5997 gaudi_mmu_prepare_reg(hdev, mmTPC1_QM_GLBL_NON_SECURE_PROPS_4, asid);
5998 gaudi_mmu_prepare_reg(hdev, mmTPC1_CFG_ARUSER_LO, asid);
5999 gaudi_mmu_prepare_reg(hdev, mmTPC1_CFG_AWUSER_LO, asid);
6000
6001 gaudi_mmu_prepare_reg(hdev, mmTPC2_QM_GLBL_NON_SECURE_PROPS_0, asid);
6002 gaudi_mmu_prepare_reg(hdev, mmTPC2_QM_GLBL_NON_SECURE_PROPS_1, asid);
6003 gaudi_mmu_prepare_reg(hdev, mmTPC2_QM_GLBL_NON_SECURE_PROPS_2, asid);
6004 gaudi_mmu_prepare_reg(hdev, mmTPC2_QM_GLBL_NON_SECURE_PROPS_3, asid);
6005 gaudi_mmu_prepare_reg(hdev, mmTPC2_QM_GLBL_NON_SECURE_PROPS_4, asid);
6006 gaudi_mmu_prepare_reg(hdev, mmTPC2_CFG_ARUSER_LO, asid);
6007 gaudi_mmu_prepare_reg(hdev, mmTPC2_CFG_AWUSER_LO, asid);
6008
6009 gaudi_mmu_prepare_reg(hdev, mmTPC3_QM_GLBL_NON_SECURE_PROPS_0, asid);
6010 gaudi_mmu_prepare_reg(hdev, mmTPC3_QM_GLBL_NON_SECURE_PROPS_1, asid);
6011 gaudi_mmu_prepare_reg(hdev, mmTPC3_QM_GLBL_NON_SECURE_PROPS_2, asid);
6012 gaudi_mmu_prepare_reg(hdev, mmTPC3_QM_GLBL_NON_SECURE_PROPS_3, asid);
6013 gaudi_mmu_prepare_reg(hdev, mmTPC3_QM_GLBL_NON_SECURE_PROPS_4, asid);
6014 gaudi_mmu_prepare_reg(hdev, mmTPC3_CFG_ARUSER_LO, asid);
6015 gaudi_mmu_prepare_reg(hdev, mmTPC3_CFG_AWUSER_LO, asid);
6016
6017 gaudi_mmu_prepare_reg(hdev, mmTPC4_QM_GLBL_NON_SECURE_PROPS_0, asid);
6018 gaudi_mmu_prepare_reg(hdev, mmTPC4_QM_GLBL_NON_SECURE_PROPS_1, asid);
6019 gaudi_mmu_prepare_reg(hdev, mmTPC4_QM_GLBL_NON_SECURE_PROPS_2, asid);
6020 gaudi_mmu_prepare_reg(hdev, mmTPC4_QM_GLBL_NON_SECURE_PROPS_3, asid);
6021 gaudi_mmu_prepare_reg(hdev, mmTPC4_QM_GLBL_NON_SECURE_PROPS_4, asid);
6022 gaudi_mmu_prepare_reg(hdev, mmTPC4_CFG_ARUSER_LO, asid);
6023 gaudi_mmu_prepare_reg(hdev, mmTPC4_CFG_AWUSER_LO, asid);
6024
6025 gaudi_mmu_prepare_reg(hdev, mmTPC5_QM_GLBL_NON_SECURE_PROPS_0, asid);
6026 gaudi_mmu_prepare_reg(hdev, mmTPC5_QM_GLBL_NON_SECURE_PROPS_1, asid);
6027 gaudi_mmu_prepare_reg(hdev, mmTPC5_QM_GLBL_NON_SECURE_PROPS_2, asid);
6028 gaudi_mmu_prepare_reg(hdev, mmTPC5_QM_GLBL_NON_SECURE_PROPS_3, asid);
6029 gaudi_mmu_prepare_reg(hdev, mmTPC5_QM_GLBL_NON_SECURE_PROPS_4, asid);
6030 gaudi_mmu_prepare_reg(hdev, mmTPC5_CFG_ARUSER_LO, asid);
6031 gaudi_mmu_prepare_reg(hdev, mmTPC5_CFG_AWUSER_LO, asid);
6032
6033 gaudi_mmu_prepare_reg(hdev, mmTPC6_QM_GLBL_NON_SECURE_PROPS_0, asid);
6034 gaudi_mmu_prepare_reg(hdev, mmTPC6_QM_GLBL_NON_SECURE_PROPS_1, asid);
6035 gaudi_mmu_prepare_reg(hdev, mmTPC6_QM_GLBL_NON_SECURE_PROPS_2, asid);
6036 gaudi_mmu_prepare_reg(hdev, mmTPC6_QM_GLBL_NON_SECURE_PROPS_3, asid);
6037 gaudi_mmu_prepare_reg(hdev, mmTPC6_QM_GLBL_NON_SECURE_PROPS_4, asid);
6038 gaudi_mmu_prepare_reg(hdev, mmTPC6_CFG_ARUSER_LO, asid);
6039 gaudi_mmu_prepare_reg(hdev, mmTPC6_CFG_AWUSER_LO, asid);
6040
6041 gaudi_mmu_prepare_reg(hdev, mmTPC7_QM_GLBL_NON_SECURE_PROPS_0, asid);
6042 gaudi_mmu_prepare_reg(hdev, mmTPC7_QM_GLBL_NON_SECURE_PROPS_1, asid);
6043 gaudi_mmu_prepare_reg(hdev, mmTPC7_QM_GLBL_NON_SECURE_PROPS_2, asid);
6044 gaudi_mmu_prepare_reg(hdev, mmTPC7_QM_GLBL_NON_SECURE_PROPS_3, asid);
6045 gaudi_mmu_prepare_reg(hdev, mmTPC7_QM_GLBL_NON_SECURE_PROPS_4, asid);
6046 gaudi_mmu_prepare_reg(hdev, mmTPC7_CFG_ARUSER_LO, asid);
6047 gaudi_mmu_prepare_reg(hdev, mmTPC7_CFG_AWUSER_LO, asid);
6048
6049 gaudi_mmu_prepare_reg(hdev, mmMME0_QM_GLBL_NON_SECURE_PROPS_0, asid);
6050 gaudi_mmu_prepare_reg(hdev, mmMME0_QM_GLBL_NON_SECURE_PROPS_1, asid);
6051 gaudi_mmu_prepare_reg(hdev, mmMME0_QM_GLBL_NON_SECURE_PROPS_2, asid);
6052 gaudi_mmu_prepare_reg(hdev, mmMME0_QM_GLBL_NON_SECURE_PROPS_3, asid);
6053 gaudi_mmu_prepare_reg(hdev, mmMME0_QM_GLBL_NON_SECURE_PROPS_4, asid);
6054 gaudi_mmu_prepare_reg(hdev, mmMME2_QM_GLBL_NON_SECURE_PROPS_0, asid);
6055 gaudi_mmu_prepare_reg(hdev, mmMME2_QM_GLBL_NON_SECURE_PROPS_1, asid);
6056 gaudi_mmu_prepare_reg(hdev, mmMME2_QM_GLBL_NON_SECURE_PROPS_2, asid);
6057 gaudi_mmu_prepare_reg(hdev, mmMME2_QM_GLBL_NON_SECURE_PROPS_3, asid);
6058 gaudi_mmu_prepare_reg(hdev, mmMME2_QM_GLBL_NON_SECURE_PROPS_4, asid);
6059
6060 gaudi_mmu_prepare_reg(hdev, mmMME0_SBAB_ARUSER0, asid);
6061 gaudi_mmu_prepare_reg(hdev, mmMME0_SBAB_ARUSER1, asid);
6062 gaudi_mmu_prepare_reg(hdev, mmMME1_SBAB_ARUSER0, asid);
6063 gaudi_mmu_prepare_reg(hdev, mmMME1_SBAB_ARUSER1, asid);
6064 gaudi_mmu_prepare_reg(hdev, mmMME2_SBAB_ARUSER0, asid);
6065 gaudi_mmu_prepare_reg(hdev, mmMME2_SBAB_ARUSER1, asid);
6066 gaudi_mmu_prepare_reg(hdev, mmMME3_SBAB_ARUSER0, asid);
6067 gaudi_mmu_prepare_reg(hdev, mmMME3_SBAB_ARUSER1, asid);
6068 gaudi_mmu_prepare_reg(hdev, mmMME0_ACC_WBC, asid);
6069 gaudi_mmu_prepare_reg(hdev, mmMME1_ACC_WBC, asid);
6070 gaudi_mmu_prepare_reg(hdev, mmMME2_ACC_WBC, asid);
6071 gaudi_mmu_prepare_reg(hdev, mmMME3_ACC_WBC, asid);
6072
Oded Gabbay3c681572020-11-02 21:10:39 +02006073 if (hdev->nic_ports_mask & GAUDI_NIC_MASK_NIC0) {
6074 gaudi_mmu_prepare_reg(hdev, mmNIC0_QM0_GLBL_NON_SECURE_PROPS_0,
6075 asid);
6076 gaudi_mmu_prepare_reg(hdev, mmNIC0_QM0_GLBL_NON_SECURE_PROPS_1,
6077 asid);
6078 gaudi_mmu_prepare_reg(hdev, mmNIC0_QM0_GLBL_NON_SECURE_PROPS_2,
6079 asid);
6080 gaudi_mmu_prepare_reg(hdev, mmNIC0_QM0_GLBL_NON_SECURE_PROPS_3,
6081 asid);
6082 gaudi_mmu_prepare_reg(hdev, mmNIC0_QM0_GLBL_NON_SECURE_PROPS_4,
6083 asid);
6084 }
6085
6086 if (hdev->nic_ports_mask & GAUDI_NIC_MASK_NIC1) {
6087 gaudi_mmu_prepare_reg(hdev, mmNIC0_QM1_GLBL_NON_SECURE_PROPS_0,
6088 asid);
6089 gaudi_mmu_prepare_reg(hdev, mmNIC0_QM1_GLBL_NON_SECURE_PROPS_1,
6090 asid);
6091 gaudi_mmu_prepare_reg(hdev, mmNIC0_QM1_GLBL_NON_SECURE_PROPS_2,
6092 asid);
6093 gaudi_mmu_prepare_reg(hdev, mmNIC0_QM1_GLBL_NON_SECURE_PROPS_3,
6094 asid);
6095 gaudi_mmu_prepare_reg(hdev, mmNIC0_QM1_GLBL_NON_SECURE_PROPS_4,
6096 asid);
6097 }
6098
6099 if (hdev->nic_ports_mask & GAUDI_NIC_MASK_NIC2) {
6100 gaudi_mmu_prepare_reg(hdev, mmNIC1_QM0_GLBL_NON_SECURE_PROPS_0,
6101 asid);
6102 gaudi_mmu_prepare_reg(hdev, mmNIC1_QM0_GLBL_NON_SECURE_PROPS_1,
6103 asid);
6104 gaudi_mmu_prepare_reg(hdev, mmNIC1_QM0_GLBL_NON_SECURE_PROPS_2,
6105 asid);
6106 gaudi_mmu_prepare_reg(hdev, mmNIC1_QM0_GLBL_NON_SECURE_PROPS_3,
6107 asid);
6108 gaudi_mmu_prepare_reg(hdev, mmNIC1_QM0_GLBL_NON_SECURE_PROPS_4,
6109 asid);
6110 }
6111
6112 if (hdev->nic_ports_mask & GAUDI_NIC_MASK_NIC3) {
6113 gaudi_mmu_prepare_reg(hdev, mmNIC1_QM1_GLBL_NON_SECURE_PROPS_0,
6114 asid);
6115 gaudi_mmu_prepare_reg(hdev, mmNIC1_QM1_GLBL_NON_SECURE_PROPS_1,
6116 asid);
6117 gaudi_mmu_prepare_reg(hdev, mmNIC1_QM1_GLBL_NON_SECURE_PROPS_2,
6118 asid);
6119 gaudi_mmu_prepare_reg(hdev, mmNIC1_QM1_GLBL_NON_SECURE_PROPS_3,
6120 asid);
6121 gaudi_mmu_prepare_reg(hdev, mmNIC1_QM1_GLBL_NON_SECURE_PROPS_4,
6122 asid);
6123 }
6124
6125 if (hdev->nic_ports_mask & GAUDI_NIC_MASK_NIC4) {
6126 gaudi_mmu_prepare_reg(hdev, mmNIC2_QM0_GLBL_NON_SECURE_PROPS_0,
6127 asid);
6128 gaudi_mmu_prepare_reg(hdev, mmNIC2_QM0_GLBL_NON_SECURE_PROPS_1,
6129 asid);
6130 gaudi_mmu_prepare_reg(hdev, mmNIC2_QM0_GLBL_NON_SECURE_PROPS_2,
6131 asid);
6132 gaudi_mmu_prepare_reg(hdev, mmNIC2_QM0_GLBL_NON_SECURE_PROPS_3,
6133 asid);
6134 gaudi_mmu_prepare_reg(hdev, mmNIC2_QM0_GLBL_NON_SECURE_PROPS_4,
6135 asid);
6136 }
6137
6138 if (hdev->nic_ports_mask & GAUDI_NIC_MASK_NIC5) {
6139 gaudi_mmu_prepare_reg(hdev, mmNIC2_QM1_GLBL_NON_SECURE_PROPS_0,
6140 asid);
6141 gaudi_mmu_prepare_reg(hdev, mmNIC2_QM1_GLBL_NON_SECURE_PROPS_1,
6142 asid);
6143 gaudi_mmu_prepare_reg(hdev, mmNIC2_QM1_GLBL_NON_SECURE_PROPS_2,
6144 asid);
6145 gaudi_mmu_prepare_reg(hdev, mmNIC2_QM1_GLBL_NON_SECURE_PROPS_3,
6146 asid);
6147 gaudi_mmu_prepare_reg(hdev, mmNIC2_QM1_GLBL_NON_SECURE_PROPS_4,
6148 asid);
6149 }
6150
6151 if (hdev->nic_ports_mask & GAUDI_NIC_MASK_NIC6) {
6152 gaudi_mmu_prepare_reg(hdev, mmNIC3_QM0_GLBL_NON_SECURE_PROPS_0,
6153 asid);
6154 gaudi_mmu_prepare_reg(hdev, mmNIC3_QM0_GLBL_NON_SECURE_PROPS_1,
6155 asid);
6156 gaudi_mmu_prepare_reg(hdev, mmNIC3_QM0_GLBL_NON_SECURE_PROPS_2,
6157 asid);
6158 gaudi_mmu_prepare_reg(hdev, mmNIC3_QM0_GLBL_NON_SECURE_PROPS_3,
6159 asid);
6160 gaudi_mmu_prepare_reg(hdev, mmNIC3_QM0_GLBL_NON_SECURE_PROPS_4,
6161 asid);
6162 }
6163
6164 if (hdev->nic_ports_mask & GAUDI_NIC_MASK_NIC7) {
6165 gaudi_mmu_prepare_reg(hdev, mmNIC3_QM1_GLBL_NON_SECURE_PROPS_0,
6166 asid);
6167 gaudi_mmu_prepare_reg(hdev, mmNIC3_QM1_GLBL_NON_SECURE_PROPS_1,
6168 asid);
6169 gaudi_mmu_prepare_reg(hdev, mmNIC3_QM1_GLBL_NON_SECURE_PROPS_2,
6170 asid);
6171 gaudi_mmu_prepare_reg(hdev, mmNIC3_QM1_GLBL_NON_SECURE_PROPS_3,
6172 asid);
6173 gaudi_mmu_prepare_reg(hdev, mmNIC3_QM1_GLBL_NON_SECURE_PROPS_4,
6174 asid);
6175 }
6176
6177 if (hdev->nic_ports_mask & GAUDI_NIC_MASK_NIC8) {
6178 gaudi_mmu_prepare_reg(hdev, mmNIC4_QM0_GLBL_NON_SECURE_PROPS_0,
6179 asid);
6180 gaudi_mmu_prepare_reg(hdev, mmNIC4_QM0_GLBL_NON_SECURE_PROPS_1,
6181 asid);
6182 gaudi_mmu_prepare_reg(hdev, mmNIC4_QM0_GLBL_NON_SECURE_PROPS_2,
6183 asid);
6184 gaudi_mmu_prepare_reg(hdev, mmNIC4_QM0_GLBL_NON_SECURE_PROPS_3,
6185 asid);
6186 gaudi_mmu_prepare_reg(hdev, mmNIC4_QM0_GLBL_NON_SECURE_PROPS_4,
6187 asid);
6188 }
6189
6190 if (hdev->nic_ports_mask & GAUDI_NIC_MASK_NIC9) {
6191 gaudi_mmu_prepare_reg(hdev, mmNIC4_QM1_GLBL_NON_SECURE_PROPS_0,
6192 asid);
6193 gaudi_mmu_prepare_reg(hdev, mmNIC4_QM1_GLBL_NON_SECURE_PROPS_1,
6194 asid);
6195 gaudi_mmu_prepare_reg(hdev, mmNIC4_QM1_GLBL_NON_SECURE_PROPS_2,
6196 asid);
6197 gaudi_mmu_prepare_reg(hdev, mmNIC4_QM1_GLBL_NON_SECURE_PROPS_3,
6198 asid);
6199 gaudi_mmu_prepare_reg(hdev, mmNIC4_QM1_GLBL_NON_SECURE_PROPS_4,
6200 asid);
6201 }
6202
Oded Gabbaye38bfd32020-07-03 20:46:12 +03006203 hdev->asic_funcs->set_clock_gating(hdev);
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03006204
6205 mutex_unlock(&gaudi->clk_gate_mutex);
6206}
6207
6208static int gaudi_send_job_on_qman0(struct hl_device *hdev,
6209 struct hl_cs_job *job)
6210{
6211 struct packet_msg_prot *fence_pkt;
6212 u32 *fence_ptr;
6213 dma_addr_t fence_dma_addr;
6214 struct hl_cb *cb;
6215 u32 tmp, timeout, dma_offset;
6216 int rc;
6217
6218 if (hdev->pldm)
6219 timeout = GAUDI_PLDM_QMAN0_TIMEOUT_USEC;
6220 else
6221 timeout = HL_DEVICE_TIMEOUT_USEC;
6222
6223 if (!hdev->asic_funcs->is_device_idle(hdev, NULL, NULL)) {
6224 dev_err_ratelimited(hdev->dev,
6225 "Can't send driver job on QMAN0 because the device is not idle\n");
6226 return -EBUSY;
6227 }
6228
6229 fence_ptr = hdev->asic_funcs->asic_dma_pool_zalloc(hdev, 4, GFP_KERNEL,
6230 &fence_dma_addr);
6231 if (!fence_ptr) {
6232 dev_err(hdev->dev,
6233 "Failed to allocate fence memory for QMAN0\n");
6234 return -ENOMEM;
6235 }
6236
6237 cb = job->patched_cb;
6238
Arnd Bergmann82948e62020-10-26 17:08:06 +01006239 fence_pkt = cb->kernel_address +
6240 job->job_cb_size - sizeof(struct packet_msg_prot);
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03006241
Oded Gabbay65887292020-08-12 11:21:01 +03006242 tmp = FIELD_PREP(GAUDI_PKT_CTL_OPCODE_MASK, PACKET_MSG_PROT);
6243 tmp |= FIELD_PREP(GAUDI_PKT_CTL_EB_MASK, 1);
6244 tmp |= FIELD_PREP(GAUDI_PKT_CTL_MB_MASK, 1);
6245
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03006246 fence_pkt->ctl = cpu_to_le32(tmp);
6247 fence_pkt->value = cpu_to_le32(GAUDI_QMAN0_FENCE_VAL);
6248 fence_pkt->addr = cpu_to_le64(fence_dma_addr);
6249
6250 dma_offset = gaudi_dma_assignment[GAUDI_PCI_DMA_1] * DMA_CORE_OFFSET;
6251
6252 WREG32_OR(mmDMA0_CORE_PROT + dma_offset, BIT(DMA0_CORE_PROT_VAL_SHIFT));
6253
6254 rc = hl_hw_queue_send_cb_no_cmpl(hdev, GAUDI_QUEUE_ID_DMA_0_0,
6255 job->job_cb_size, cb->bus_address);
6256 if (rc) {
6257 dev_err(hdev->dev, "Failed to send CB on QMAN0, %d\n", rc);
6258 goto free_fence_ptr;
6259 }
6260
6261 rc = hl_poll_timeout_memory(hdev, fence_ptr, tmp,
6262 (tmp == GAUDI_QMAN0_FENCE_VAL), 1000,
6263 timeout, true);
6264
6265 hl_hw_queue_inc_ci_kernel(hdev, GAUDI_QUEUE_ID_DMA_0_0);
6266
6267 if (rc == -ETIMEDOUT) {
6268 dev_err(hdev->dev, "QMAN0 Job timeout (0x%x)\n", tmp);
6269 goto free_fence_ptr;
6270 }
6271
6272free_fence_ptr:
6273 WREG32_AND(mmDMA0_CORE_PROT + dma_offset,
6274 ~BIT(DMA0_CORE_PROT_VAL_SHIFT));
6275
6276 hdev->asic_funcs->asic_dma_pool_free(hdev, (void *) fence_ptr,
6277 fence_dma_addr);
6278 return rc;
6279}
6280
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03006281static void gaudi_get_event_desc(u16 event_type, char *desc, size_t size)
6282{
Ofir Bittonebd8d122020-05-10 13:41:28 +03006283 if (event_type >= GAUDI_EVENT_SIZE)
6284 goto event_not_supported;
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03006285
Ofir Bittonebd8d122020-05-10 13:41:28 +03006286 if (!gaudi_irq_map_table[event_type].valid)
6287 goto event_not_supported;
6288
6289 snprintf(desc, size, gaudi_irq_map_table[event_type].name);
6290
6291 return;
6292
6293event_not_supported:
6294 snprintf(desc, size, "N/A");
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03006295}
6296
6297static const char *gaudi_get_razwi_initiator_dma_name(struct hl_device *hdev,
6298 u32 x_y, bool is_write)
6299{
6300 u32 dma_id[2], dma_offset, err_cause[2], mask, i;
6301
6302 mask = is_write ? DMA0_CORE_ERR_CAUSE_HBW_WR_ERR_MASK :
6303 DMA0_CORE_ERR_CAUSE_HBW_RD_ERR_MASK;
6304
6305 switch (x_y) {
6306 case RAZWI_INITIATOR_ID_X_Y_DMA_IF_W_S_0:
6307 case RAZWI_INITIATOR_ID_X_Y_DMA_IF_W_S_1:
6308 dma_id[0] = 0;
6309 dma_id[1] = 2;
6310 break;
6311 case RAZWI_INITIATOR_ID_X_Y_DMA_IF_E_S_0:
6312 case RAZWI_INITIATOR_ID_X_Y_DMA_IF_E_S_1:
6313 dma_id[0] = 1;
6314 dma_id[1] = 3;
6315 break;
6316 case RAZWI_INITIATOR_ID_X_Y_DMA_IF_W_N_0:
6317 case RAZWI_INITIATOR_ID_X_Y_DMA_IF_W_N_1:
6318 dma_id[0] = 4;
6319 dma_id[1] = 6;
6320 break;
6321 case RAZWI_INITIATOR_ID_X_Y_DMA_IF_E_N_0:
6322 case RAZWI_INITIATOR_ID_X_Y_DMA_IF_E_N_1:
6323 dma_id[0] = 5;
6324 dma_id[1] = 7;
6325 break;
6326 default:
6327 goto unknown_initiator;
6328 }
6329
6330 for (i = 0 ; i < 2 ; i++) {
6331 dma_offset = dma_id[i] * DMA_CORE_OFFSET;
6332 err_cause[i] = RREG32(mmDMA0_CORE_ERR_CAUSE + dma_offset);
6333 }
6334
6335 switch (x_y) {
6336 case RAZWI_INITIATOR_ID_X_Y_DMA_IF_W_S_0:
6337 case RAZWI_INITIATOR_ID_X_Y_DMA_IF_W_S_1:
6338 if ((err_cause[0] & mask) && !(err_cause[1] & mask))
6339 return "DMA0";
6340 else if (!(err_cause[0] & mask) && (err_cause[1] & mask))
6341 return "DMA2";
6342 else
6343 return "DMA0 or DMA2";
6344 case RAZWI_INITIATOR_ID_X_Y_DMA_IF_E_S_0:
6345 case RAZWI_INITIATOR_ID_X_Y_DMA_IF_E_S_1:
6346 if ((err_cause[0] & mask) && !(err_cause[1] & mask))
6347 return "DMA1";
6348 else if (!(err_cause[0] & mask) && (err_cause[1] & mask))
6349 return "DMA3";
6350 else
6351 return "DMA1 or DMA3";
6352 case RAZWI_INITIATOR_ID_X_Y_DMA_IF_W_N_0:
6353 case RAZWI_INITIATOR_ID_X_Y_DMA_IF_W_N_1:
6354 if ((err_cause[0] & mask) && !(err_cause[1] & mask))
6355 return "DMA4";
6356 else if (!(err_cause[0] & mask) && (err_cause[1] & mask))
6357 return "DMA6";
6358 else
6359 return "DMA4 or DMA6";
6360 case RAZWI_INITIATOR_ID_X_Y_DMA_IF_E_N_0:
6361 case RAZWI_INITIATOR_ID_X_Y_DMA_IF_E_N_1:
6362 if ((err_cause[0] & mask) && !(err_cause[1] & mask))
6363 return "DMA5";
6364 else if (!(err_cause[0] & mask) && (err_cause[1] & mask))
6365 return "DMA7";
6366 else
6367 return "DMA5 or DMA7";
6368 }
6369
6370unknown_initiator:
6371 return "unknown initiator";
6372}
6373
6374static const char *gaudi_get_razwi_initiator_name(struct hl_device *hdev,
6375 bool is_write)
6376{
6377 u32 val, x_y, axi_id;
6378
6379 val = is_write ? RREG32(mmMMU_UP_RAZWI_WRITE_ID) :
6380 RREG32(mmMMU_UP_RAZWI_READ_ID);
6381 x_y = val & ((RAZWI_INITIATOR_Y_MASK << RAZWI_INITIATOR_Y_SHIFT) |
6382 (RAZWI_INITIATOR_X_MASK << RAZWI_INITIATOR_X_SHIFT));
6383 axi_id = val & (RAZWI_INITIATOR_AXI_ID_MASK <<
6384 RAZWI_INITIATOR_AXI_ID_SHIFT);
6385
6386 switch (x_y) {
6387 case RAZWI_INITIATOR_ID_X_Y_TPC0_NIC0:
6388 if (axi_id == RAZWI_INITIATOR_ID_AXI_ID(AXI_ID_TPC))
6389 return "TPC0";
6390 if (axi_id == RAZWI_INITIATOR_ID_AXI_ID(AXI_ID_NIC))
6391 return "NIC0";
6392 break;
6393 case RAZWI_INITIATOR_ID_X_Y_TPC1:
6394 return "TPC1";
6395 case RAZWI_INITIATOR_ID_X_Y_MME0_0:
6396 case RAZWI_INITIATOR_ID_X_Y_MME0_1:
6397 return "MME0";
6398 case RAZWI_INITIATOR_ID_X_Y_MME1_0:
6399 case RAZWI_INITIATOR_ID_X_Y_MME1_1:
6400 return "MME1";
6401 case RAZWI_INITIATOR_ID_X_Y_TPC2:
6402 return "TPC2";
6403 case RAZWI_INITIATOR_ID_X_Y_TPC3_PCI_CPU_PSOC:
6404 if (axi_id == RAZWI_INITIATOR_ID_AXI_ID(AXI_ID_TPC))
6405 return "TPC3";
6406 if (axi_id == RAZWI_INITIATOR_ID_AXI_ID(AXI_ID_PCI))
6407 return "PCI";
6408 if (axi_id == RAZWI_INITIATOR_ID_AXI_ID(AXI_ID_CPU))
6409 return "CPU";
6410 if (axi_id == RAZWI_INITIATOR_ID_AXI_ID(AXI_ID_PSOC))
6411 return "PSOC";
6412 break;
6413 case RAZWI_INITIATOR_ID_X_Y_DMA_IF_W_S_0:
6414 case RAZWI_INITIATOR_ID_X_Y_DMA_IF_W_S_1:
6415 case RAZWI_INITIATOR_ID_X_Y_DMA_IF_E_S_0:
6416 case RAZWI_INITIATOR_ID_X_Y_DMA_IF_E_S_1:
6417 case RAZWI_INITIATOR_ID_X_Y_DMA_IF_W_N_0:
6418 case RAZWI_INITIATOR_ID_X_Y_DMA_IF_W_N_1:
6419 case RAZWI_INITIATOR_ID_X_Y_DMA_IF_E_N_0:
6420 case RAZWI_INITIATOR_ID_X_Y_DMA_IF_E_N_1:
6421 return gaudi_get_razwi_initiator_dma_name(hdev, x_y, is_write);
6422 case RAZWI_INITIATOR_ID_X_Y_TPC4_NIC1_NIC2:
6423 if (axi_id == RAZWI_INITIATOR_ID_AXI_ID(AXI_ID_TPC))
6424 return "TPC4";
6425 if (axi_id == RAZWI_INITIATOR_ID_AXI_ID(AXI_ID_NIC))
6426 return "NIC1";
6427 if (axi_id == RAZWI_INITIATOR_ID_AXI_ID(AXI_ID_NIC_FT))
6428 return "NIC2";
6429 break;
6430 case RAZWI_INITIATOR_ID_X_Y_TPC5:
6431 return "TPC5";
6432 case RAZWI_INITIATOR_ID_X_Y_MME2_0:
6433 case RAZWI_INITIATOR_ID_X_Y_MME2_1:
6434 return "MME2";
6435 case RAZWI_INITIATOR_ID_X_Y_MME3_0:
6436 case RAZWI_INITIATOR_ID_X_Y_MME3_1:
6437 return "MME3";
6438 case RAZWI_INITIATOR_ID_X_Y_TPC6:
6439 return "TPC6";
6440 case RAZWI_INITIATOR_ID_X_Y_TPC7_NIC4_NIC5:
6441 if (axi_id == RAZWI_INITIATOR_ID_AXI_ID(AXI_ID_TPC))
6442 return "TPC7";
6443 if (axi_id == RAZWI_INITIATOR_ID_AXI_ID(AXI_ID_NIC))
6444 return "NIC4";
6445 if (axi_id == RAZWI_INITIATOR_ID_AXI_ID(AXI_ID_NIC_FT))
6446 return "NIC5";
6447 break;
6448 default:
6449 break;
6450 }
6451
6452 dev_err(hdev->dev,
6453 "Unknown RAZWI initiator ID 0x%x [Y=%d, X=%d, AXI_ID=%d]\n",
6454 val,
6455 (val >> RAZWI_INITIATOR_Y_SHIFT) & RAZWI_INITIATOR_Y_MASK,
6456 (val >> RAZWI_INITIATOR_X_SHIFT) & RAZWI_INITIATOR_X_MASK,
6457 (val >> RAZWI_INITIATOR_AXI_ID_SHIFT) &
6458 RAZWI_INITIATOR_AXI_ID_MASK);
6459
6460 return "unknown initiator";
6461}
6462
6463static void gaudi_print_razwi_info(struct hl_device *hdev)
6464{
6465 if (RREG32(mmMMU_UP_RAZWI_WRITE_VLD)) {
6466 dev_err_ratelimited(hdev->dev,
6467 "RAZWI event caused by illegal write of %s\n",
6468 gaudi_get_razwi_initiator_name(hdev, true));
6469 WREG32(mmMMU_UP_RAZWI_WRITE_VLD, 0);
6470 }
6471
6472 if (RREG32(mmMMU_UP_RAZWI_READ_VLD)) {
6473 dev_err_ratelimited(hdev->dev,
6474 "RAZWI event caused by illegal read of %s\n",
6475 gaudi_get_razwi_initiator_name(hdev, false));
6476 WREG32(mmMMU_UP_RAZWI_READ_VLD, 0);
6477 }
6478}
6479
6480static void gaudi_print_mmu_error_info(struct hl_device *hdev)
6481{
6482 struct gaudi_device *gaudi = hdev->asic_specific;
6483 u64 addr;
6484 u32 val;
6485
6486 if (!(gaudi->hw_cap_initialized & HW_CAP_MMU))
6487 return;
6488
6489 val = RREG32(mmMMU_UP_PAGE_ERROR_CAPTURE);
6490 if (val & MMU_UP_PAGE_ERROR_CAPTURE_ENTRY_VALID_MASK) {
6491 addr = val & MMU_UP_PAGE_ERROR_CAPTURE_VA_49_32_MASK;
6492 addr <<= 32;
6493 addr |= RREG32(mmMMU_UP_PAGE_ERROR_CAPTURE_VA);
6494
6495 dev_err_ratelimited(hdev->dev, "MMU page fault on va 0x%llx\n",
6496 addr);
6497
6498 WREG32(mmMMU_UP_PAGE_ERROR_CAPTURE, 0);
6499 }
6500
6501 val = RREG32(mmMMU_UP_ACCESS_ERROR_CAPTURE);
6502 if (val & MMU_UP_ACCESS_ERROR_CAPTURE_ENTRY_VALID_MASK) {
6503 addr = val & MMU_UP_ACCESS_ERROR_CAPTURE_VA_49_32_MASK;
6504 addr <<= 32;
6505 addr |= RREG32(mmMMU_UP_ACCESS_ERROR_CAPTURE_VA);
6506
6507 dev_err_ratelimited(hdev->dev,
6508 "MMU access error on va 0x%llx\n", addr);
6509
6510 WREG32(mmMMU_UP_ACCESS_ERROR_CAPTURE, 0);
6511 }
6512}
6513
6514/*
6515 * +-------------------+------------------------------------------------------+
6516 * | Configuration Reg | Description |
6517 * | Address | |
6518 * +-------------------+------------------------------------------------------+
6519 * | 0xF30 - 0xF3F |ECC single error indication (1 bit per memory wrapper)|
6520 * | |0xF30 memory wrappers 31:0 (MSB to LSB) |
6521 * | |0xF34 memory wrappers 63:32 |
6522 * | |0xF38 memory wrappers 95:64 |
6523 * | |0xF3C memory wrappers 127:96 |
6524 * +-------------------+------------------------------------------------------+
6525 * | 0xF40 - 0xF4F |ECC double error indication (1 bit per memory wrapper)|
6526 * | |0xF40 memory wrappers 31:0 (MSB to LSB) |
6527 * | |0xF44 memory wrappers 63:32 |
6528 * | |0xF48 memory wrappers 95:64 |
6529 * | |0xF4C memory wrappers 127:96 |
6530 * +-------------------+------------------------------------------------------+
6531 */
Oded Gabbayfcc6a4e2020-05-17 08:20:35 +03006532static int gaudi_extract_ecc_info(struct hl_device *hdev,
6533 struct ecc_info_extract_params *params, u64 *ecc_address,
6534 u64 *ecc_syndrom, u8 *memory_wrapper_idx)
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03006535{
6536 struct gaudi_device *gaudi = hdev->asic_specific;
Oded Gabbayfcc6a4e2020-05-17 08:20:35 +03006537 u32 i, num_mem_regs, reg, err_bit;
6538 u64 err_addr, err_word = 0;
6539 int rc = 0;
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03006540
Oded Gabbayfcc6a4e2020-05-17 08:20:35 +03006541 num_mem_regs = params->num_memories / 32 +
6542 ((params->num_memories % 32) ? 1 : 0);
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03006543
Oded Gabbayfcc6a4e2020-05-17 08:20:35 +03006544 if (params->block_address >= CFG_BASE)
6545 params->block_address -= CFG_BASE;
6546
6547 if (params->derr)
6548 err_addr = params->block_address + GAUDI_ECC_DERR0_OFFSET;
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03006549 else
Oded Gabbayfcc6a4e2020-05-17 08:20:35 +03006550 err_addr = params->block_address + GAUDI_ECC_SERR0_OFFSET;
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03006551
Oded Gabbayfcc6a4e2020-05-17 08:20:35 +03006552 if (params->disable_clock_gating) {
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03006553 mutex_lock(&gaudi->clk_gate_mutex);
6554 hdev->asic_funcs->disable_clock_gating(hdev);
6555 }
6556
Oded Gabbayfcc6a4e2020-05-17 08:20:35 +03006557 /* Set invalid wrapper index */
6558 *memory_wrapper_idx = 0xFF;
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03006559
Oded Gabbayfcc6a4e2020-05-17 08:20:35 +03006560 /* Iterate through memory wrappers, a single bit must be set */
Dan Carpenterb0353542020-08-05 12:51:05 +03006561 for (i = 0 ; i < num_mem_regs ; i++) {
Oded Gabbayfcc6a4e2020-05-17 08:20:35 +03006562 err_addr += i * 4;
6563 err_word = RREG32(err_addr);
6564 if (err_word) {
6565 err_bit = __ffs(err_word);
6566 *memory_wrapper_idx = err_bit + (32 * i);
6567 break;
6568 }
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03006569 }
6570
Oded Gabbayfcc6a4e2020-05-17 08:20:35 +03006571 if (*memory_wrapper_idx == 0xFF) {
6572 dev_err(hdev->dev, "ECC error information cannot be found\n");
6573 rc = -EINVAL;
6574 goto enable_clk_gate;
6575 }
6576
6577 WREG32(params->block_address + GAUDI_ECC_MEM_SEL_OFFSET,
6578 *memory_wrapper_idx);
6579
6580 *ecc_address =
6581 RREG32(params->block_address + GAUDI_ECC_ADDRESS_OFFSET);
6582 *ecc_syndrom =
6583 RREG32(params->block_address + GAUDI_ECC_SYNDROME_OFFSET);
6584
6585 /* Clear error indication */
6586 reg = RREG32(params->block_address + GAUDI_ECC_MEM_INFO_CLR_OFFSET);
6587 if (params->derr)
6588 reg |= FIELD_PREP(GAUDI_ECC_MEM_INFO_CLR_DERR_MASK, 1);
6589 else
6590 reg |= FIELD_PREP(GAUDI_ECC_MEM_INFO_CLR_SERR_MASK, 1);
6591
6592 WREG32(params->block_address + GAUDI_ECC_MEM_INFO_CLR_OFFSET, reg);
6593
6594enable_clk_gate:
6595 if (params->disable_clock_gating) {
Oded Gabbaye38bfd32020-07-03 20:46:12 +03006596 hdev->asic_funcs->set_clock_gating(hdev);
Greg Kroah-Hartman65a9bde62020-07-27 11:49:37 +02006597
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03006598 mutex_unlock(&gaudi->clk_gate_mutex);
6599 }
Oded Gabbayfcc6a4e2020-05-17 08:20:35 +03006600
6601 return rc;
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03006602}
6603
6604static void gaudi_handle_qman_err_generic(struct hl_device *hdev,
6605 const char *qm_name,
6606 u64 glbl_sts_addr,
6607 u64 arb_err_addr)
6608{
6609 u32 i, j, glbl_sts_val, arb_err_val, glbl_sts_clr_val;
6610 char reg_desc[32];
6611
6612 /* Iterate through all stream GLBL_STS1 registers + Lower CP */
6613 for (i = 0 ; i < QMAN_STREAMS + 1 ; i++) {
6614 glbl_sts_clr_val = 0;
6615 glbl_sts_val = RREG32(glbl_sts_addr + 4 * i);
6616
6617 if (!glbl_sts_val)
6618 continue;
6619
6620 if (i == QMAN_STREAMS)
6621 snprintf(reg_desc, ARRAY_SIZE(reg_desc), "LowerCP");
6622 else
6623 snprintf(reg_desc, ARRAY_SIZE(reg_desc), "stream%u", i);
6624
6625 for (j = 0 ; j < GAUDI_NUM_OF_QM_ERR_CAUSE ; j++) {
6626 if (glbl_sts_val & BIT(j)) {
6627 dev_err_ratelimited(hdev->dev,
6628 "%s %s. err cause: %s\n",
6629 qm_name, reg_desc,
6630 gaudi_qman_error_cause[j]);
6631 glbl_sts_clr_val |= BIT(j);
6632 }
6633 }
6634
6635 /* Write 1 clear errors */
6636 WREG32(glbl_sts_addr + 4 * i, glbl_sts_clr_val);
6637 }
6638
6639 arb_err_val = RREG32(arb_err_addr);
6640
6641 if (!arb_err_val)
6642 return;
6643
6644 for (j = 0 ; j < GAUDI_NUM_OF_QM_ARB_ERR_CAUSE ; j++) {
6645 if (arb_err_val & BIT(j)) {
6646 dev_err_ratelimited(hdev->dev,
6647 "%s ARB_ERR. err cause: %s\n",
6648 qm_name,
6649 gaudi_qman_arb_error_cause[j]);
6650 }
6651 }
6652}
6653
Oded Gabbayfcc6a4e2020-05-17 08:20:35 +03006654static void gaudi_handle_ecc_event(struct hl_device *hdev, u16 event_type,
6655 struct hl_eq_ecc_data *ecc_data)
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03006656{
Oded Gabbayfcc6a4e2020-05-17 08:20:35 +03006657 struct ecc_info_extract_params params;
6658 u64 ecc_address = 0, ecc_syndrom = 0;
6659 u8 index, memory_wrapper_idx = 0;
6660 bool extract_info_from_fw;
6661 int rc;
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03006662
6663 switch (event_type) {
Oded Gabbayfcc6a4e2020-05-17 08:20:35 +03006664 case GAUDI_EVENT_PCIE_CORE_SERR ... GAUDI_EVENT_PCIE_PHY_DERR:
6665 case GAUDI_EVENT_DMA0_SERR_ECC ... GAUDI_EVENT_MMU_DERR:
6666 extract_info_from_fw = true;
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03006667 break;
6668 case GAUDI_EVENT_TPC0_SERR ... GAUDI_EVENT_TPC7_SERR:
6669 index = event_type - GAUDI_EVENT_TPC0_SERR;
Oded Gabbayfcc6a4e2020-05-17 08:20:35 +03006670 params.block_address = mmTPC0_CFG_BASE + index * TPC_CFG_OFFSET;
6671 params.num_memories = 90;
6672 params.derr = false;
6673 params.disable_clock_gating = true;
6674 extract_info_from_fw = false;
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03006675 break;
6676 case GAUDI_EVENT_TPC0_DERR ... GAUDI_EVENT_TPC7_DERR:
6677 index = event_type - GAUDI_EVENT_TPC0_DERR;
Oded Gabbayfcc6a4e2020-05-17 08:20:35 +03006678 params.block_address =
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03006679 mmTPC0_CFG_BASE + index * TPC_CFG_OFFSET;
Oded Gabbayfcc6a4e2020-05-17 08:20:35 +03006680 params.num_memories = 90;
6681 params.derr = true;
6682 params.disable_clock_gating = true;
6683 extract_info_from_fw = false;
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03006684 break;
6685 case GAUDI_EVENT_MME0_ACC_SERR:
6686 case GAUDI_EVENT_MME1_ACC_SERR:
6687 case GAUDI_EVENT_MME2_ACC_SERR:
6688 case GAUDI_EVENT_MME3_ACC_SERR:
6689 index = (event_type - GAUDI_EVENT_MME0_ACC_SERR) / 4;
Oded Gabbayfcc6a4e2020-05-17 08:20:35 +03006690 params.block_address = mmMME0_ACC_BASE + index * MME_ACC_OFFSET;
6691 params.num_memories = 128;
6692 params.derr = false;
6693 params.disable_clock_gating = true;
6694 extract_info_from_fw = false;
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03006695 break;
6696 case GAUDI_EVENT_MME0_ACC_DERR:
6697 case GAUDI_EVENT_MME1_ACC_DERR:
6698 case GAUDI_EVENT_MME2_ACC_DERR:
6699 case GAUDI_EVENT_MME3_ACC_DERR:
6700 index = (event_type - GAUDI_EVENT_MME0_ACC_DERR) / 4;
Oded Gabbayfcc6a4e2020-05-17 08:20:35 +03006701 params.block_address = mmMME0_ACC_BASE + index * MME_ACC_OFFSET;
6702 params.num_memories = 128;
6703 params.derr = true;
6704 params.disable_clock_gating = true;
6705 extract_info_from_fw = false;
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03006706 break;
6707 case GAUDI_EVENT_MME0_SBAB_SERR:
6708 case GAUDI_EVENT_MME1_SBAB_SERR:
6709 case GAUDI_EVENT_MME2_SBAB_SERR:
6710 case GAUDI_EVENT_MME3_SBAB_SERR:
6711 index = (event_type - GAUDI_EVENT_MME0_SBAB_SERR) / 4;
Oded Gabbayfcc6a4e2020-05-17 08:20:35 +03006712 params.block_address =
6713 mmMME0_SBAB_BASE + index * MME_ACC_OFFSET;
6714 params.num_memories = 33;
6715 params.derr = false;
6716 params.disable_clock_gating = true;
6717 extract_info_from_fw = false;
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03006718 break;
6719 case GAUDI_EVENT_MME0_SBAB_DERR:
6720 case GAUDI_EVENT_MME1_SBAB_DERR:
6721 case GAUDI_EVENT_MME2_SBAB_DERR:
6722 case GAUDI_EVENT_MME3_SBAB_DERR:
6723 index = (event_type - GAUDI_EVENT_MME0_SBAB_DERR) / 4;
Oded Gabbayfcc6a4e2020-05-17 08:20:35 +03006724 params.block_address =
6725 mmMME0_SBAB_BASE + index * MME_ACC_OFFSET;
6726 params.num_memories = 33;
6727 params.derr = true;
6728 params.disable_clock_gating = true;
Oded Gabbay652b4442020-11-21 14:35:35 +02006729 extract_info_from_fw = false;
6730 break;
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03006731 default:
6732 return;
6733 }
6734
Oded Gabbayfcc6a4e2020-05-17 08:20:35 +03006735 if (extract_info_from_fw) {
6736 ecc_address = le64_to_cpu(ecc_data->ecc_address);
6737 ecc_syndrom = le64_to_cpu(ecc_data->ecc_syndrom);
6738 memory_wrapper_idx = ecc_data->memory_wrapper_idx;
6739 } else {
6740 rc = gaudi_extract_ecc_info(hdev, &params, &ecc_address,
6741 &ecc_syndrom, &memory_wrapper_idx);
6742 if (rc)
6743 return;
6744 }
6745
6746 dev_err(hdev->dev,
6747 "ECC error detected. address: %#llx. Syndrom: %#llx. block id %u\n",
6748 ecc_address, ecc_syndrom, memory_wrapper_idx);
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03006749}
6750
6751static void gaudi_handle_qman_err(struct hl_device *hdev, u16 event_type)
6752{
6753 u64 glbl_sts_addr, arb_err_addr;
6754 u8 index;
6755 char desc[32];
6756
6757 switch (event_type) {
6758 case GAUDI_EVENT_TPC0_QM ... GAUDI_EVENT_TPC7_QM:
6759 index = event_type - GAUDI_EVENT_TPC0_QM;
6760 glbl_sts_addr =
6761 mmTPC0_QM_GLBL_STS1_0 + index * TPC_QMAN_OFFSET;
6762 arb_err_addr =
6763 mmTPC0_QM_ARB_ERR_CAUSE + index * TPC_QMAN_OFFSET;
6764 snprintf(desc, ARRAY_SIZE(desc), "%s%d", "TPC_QM", index);
6765 break;
6766 case GAUDI_EVENT_MME0_QM ... GAUDI_EVENT_MME2_QM:
6767 index = event_type - GAUDI_EVENT_MME0_QM;
6768 glbl_sts_addr =
6769 mmMME0_QM_GLBL_STS1_0 + index * MME_QMAN_OFFSET;
6770 arb_err_addr =
6771 mmMME0_QM_ARB_ERR_CAUSE + index * MME_QMAN_OFFSET;
6772 snprintf(desc, ARRAY_SIZE(desc), "%s%d", "MME_QM", index);
6773 break;
6774 case GAUDI_EVENT_DMA0_QM ... GAUDI_EVENT_DMA7_QM:
6775 index = event_type - GAUDI_EVENT_DMA0_QM;
6776 glbl_sts_addr =
6777 mmDMA0_QM_GLBL_STS1_0 + index * DMA_QMAN_OFFSET;
6778 arb_err_addr =
6779 mmDMA0_QM_ARB_ERR_CAUSE + index * DMA_QMAN_OFFSET;
6780 snprintf(desc, ARRAY_SIZE(desc), "%s%d", "DMA_QM", index);
6781 break;
Oded Gabbay3c681572020-11-02 21:10:39 +02006782 case GAUDI_EVENT_NIC0_QM0:
6783 glbl_sts_addr = mmNIC0_QM0_GLBL_STS1_0;
6784 arb_err_addr = mmNIC0_QM0_ARB_ERR_CAUSE;
6785 snprintf(desc, ARRAY_SIZE(desc), "NIC0_QM0");
6786 break;
6787 case GAUDI_EVENT_NIC0_QM1:
6788 glbl_sts_addr = mmNIC0_QM1_GLBL_STS1_0;
6789 arb_err_addr = mmNIC0_QM1_ARB_ERR_CAUSE;
6790 snprintf(desc, ARRAY_SIZE(desc), "NIC0_QM1");
6791 break;
6792 case GAUDI_EVENT_NIC1_QM0:
6793 glbl_sts_addr = mmNIC1_QM0_GLBL_STS1_0;
6794 arb_err_addr = mmNIC1_QM0_ARB_ERR_CAUSE;
6795 snprintf(desc, ARRAY_SIZE(desc), "NIC1_QM0");
6796 break;
6797 case GAUDI_EVENT_NIC1_QM1:
6798 glbl_sts_addr = mmNIC1_QM1_GLBL_STS1_0;
6799 arb_err_addr = mmNIC1_QM1_ARB_ERR_CAUSE;
6800 snprintf(desc, ARRAY_SIZE(desc), "NIC1_QM1");
6801 break;
6802 case GAUDI_EVENT_NIC2_QM0:
6803 glbl_sts_addr = mmNIC2_QM0_GLBL_STS1_0;
6804 arb_err_addr = mmNIC2_QM0_ARB_ERR_CAUSE;
6805 snprintf(desc, ARRAY_SIZE(desc), "NIC2_QM0");
6806 break;
6807 case GAUDI_EVENT_NIC2_QM1:
6808 glbl_sts_addr = mmNIC2_QM1_GLBL_STS1_0;
6809 arb_err_addr = mmNIC2_QM1_ARB_ERR_CAUSE;
6810 snprintf(desc, ARRAY_SIZE(desc), "NIC2_QM1");
6811 break;
6812 case GAUDI_EVENT_NIC3_QM0:
6813 glbl_sts_addr = mmNIC3_QM0_GLBL_STS1_0;
6814 arb_err_addr = mmNIC3_QM0_ARB_ERR_CAUSE;
6815 snprintf(desc, ARRAY_SIZE(desc), "NIC3_QM0");
6816 break;
6817 case GAUDI_EVENT_NIC3_QM1:
6818 glbl_sts_addr = mmNIC3_QM1_GLBL_STS1_0;
6819 arb_err_addr = mmNIC3_QM1_ARB_ERR_CAUSE;
6820 snprintf(desc, ARRAY_SIZE(desc), "NIC3_QM1");
6821 break;
6822 case GAUDI_EVENT_NIC4_QM0:
6823 glbl_sts_addr = mmNIC4_QM0_GLBL_STS1_0;
6824 arb_err_addr = mmNIC4_QM0_ARB_ERR_CAUSE;
6825 snprintf(desc, ARRAY_SIZE(desc), "NIC4_QM0");
6826 break;
6827 case GAUDI_EVENT_NIC4_QM1:
6828 glbl_sts_addr = mmNIC4_QM1_GLBL_STS1_0;
6829 arb_err_addr = mmNIC4_QM1_ARB_ERR_CAUSE;
6830 snprintf(desc, ARRAY_SIZE(desc), "NIC4_QM1");
6831 break;
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03006832 default:
6833 return;
6834 }
6835
6836 gaudi_handle_qman_err_generic(hdev, desc, glbl_sts_addr, arb_err_addr);
6837}
6838
6839static void gaudi_print_irq_info(struct hl_device *hdev, u16 event_type,
6840 bool razwi)
6841{
Ofir Bittonebd8d122020-05-10 13:41:28 +03006842 char desc[64] = "";
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03006843
6844 gaudi_get_event_desc(event_type, desc, sizeof(desc));
6845 dev_err_ratelimited(hdev->dev, "Received H/W interrupt %d [\"%s\"]\n",
6846 event_type, desc);
6847
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03006848 if (razwi) {
6849 gaudi_print_razwi_info(hdev);
6850 gaudi_print_mmu_error_info(hdev);
6851 }
6852}
6853
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03006854static int gaudi_soft_reset_late_init(struct hl_device *hdev)
6855{
Ofir Bittonebd8d122020-05-10 13:41:28 +03006856 struct gaudi_device *gaudi = hdev->asic_specific;
6857
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03006858 /* Unmask all IRQs since some could have been received
6859 * during the soft reset
6860 */
Ofir Bittonebd8d122020-05-10 13:41:28 +03006861 return hl_fw_unmask_irq_arr(hdev, gaudi->events, sizeof(gaudi->events));
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03006862}
6863
Ofir Bitton5a2998f2020-10-05 13:44:59 +03006864static int gaudi_hbm_read_interrupts(struct hl_device *hdev, int device,
6865 struct hl_eq_hbm_ecc_data *hbm_ecc_data)
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03006866{
Ofir Bitton5a2998f2020-10-05 13:44:59 +03006867 u32 base, val, val2, wr_par, rd_par, ca_par, derr, serr, type, ch;
6868 int err = 0;
6869
6870 if (!hdev->asic_prop.fw_security_disabled) {
6871 if (!hbm_ecc_data) {
6872 dev_err(hdev->dev, "No FW ECC data");
6873 return 0;
6874 }
6875
6876 wr_par = FIELD_GET(CPUCP_PKT_HBM_ECC_INFO_WR_PAR_MASK,
6877 le32_to_cpu(hbm_ecc_data->hbm_ecc_info));
6878 rd_par = FIELD_GET(CPUCP_PKT_HBM_ECC_INFO_RD_PAR_MASK,
6879 le32_to_cpu(hbm_ecc_data->hbm_ecc_info));
6880 ca_par = FIELD_GET(CPUCP_PKT_HBM_ECC_INFO_CA_PAR_MASK,
6881 le32_to_cpu(hbm_ecc_data->hbm_ecc_info));
6882 derr = FIELD_GET(CPUCP_PKT_HBM_ECC_INFO_DERR_MASK,
6883 le32_to_cpu(hbm_ecc_data->hbm_ecc_info));
6884 serr = FIELD_GET(CPUCP_PKT_HBM_ECC_INFO_SERR_MASK,
6885 le32_to_cpu(hbm_ecc_data->hbm_ecc_info));
6886 type = FIELD_GET(CPUCP_PKT_HBM_ECC_INFO_TYPE_MASK,
6887 le32_to_cpu(hbm_ecc_data->hbm_ecc_info));
6888 ch = FIELD_GET(CPUCP_PKT_HBM_ECC_INFO_HBM_CH_MASK,
6889 le32_to_cpu(hbm_ecc_data->hbm_ecc_info));
6890
6891 dev_err(hdev->dev,
Oded Gabbay64a9d5a2020-11-21 14:29:25 +02006892 "HBM%d pc%d ECC: TYPE=%d, WR_PAR=%d, RD_PAR=%d, CA_PAR=%d, SERR=%d, DERR=%d\n",
6893 device, ch, type, wr_par, rd_par, ca_par, serr, derr);
Ofir Bitton5a2998f2020-10-05 13:44:59 +03006894
6895 err = 1;
6896
6897 return 0;
6898 }
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03006899
6900 base = GAUDI_HBM_CFG_BASE + device * GAUDI_HBM_CFG_OFFSET;
6901 for (ch = 0 ; ch < GAUDI_HBM_CHANNELS ; ch++) {
6902 val = RREG32_MASK(base + ch * 0x1000 + 0x06C, 0x0000FFFF);
6903 val = (val & 0xFF) | ((val >> 8) & 0xFF);
6904 if (val) {
6905 err = 1;
6906 dev_err(hdev->dev,
6907 "HBM%d pc%d interrupts info: WR_PAR=%d, RD_PAR=%d, CA_PAR=%d, SERR=%d, DERR=%d\n",
6908 device, ch * 2, val & 0x1, (val >> 1) & 0x1,
6909 (val >> 2) & 0x1, (val >> 3) & 0x1,
6910 (val >> 4) & 0x1);
6911
6912 val2 = RREG32(base + ch * 0x1000 + 0x060);
6913 dev_err(hdev->dev,
Ofir Bitton5a2998f2020-10-05 13:44:59 +03006914 "HBM%d pc%d ECC info: 1ST_ERR_ADDR=0x%x, 1ST_ERR_TYPE=%d, SEC_CONT_CNT=%d, SEC_CNT=%d, DEC_CNT=%d\n",
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03006915 device, ch * 2,
6916 RREG32(base + ch * 0x1000 + 0x064),
6917 (val2 & 0x200) >> 9, (val2 & 0xFC00) >> 10,
6918 (val2 & 0xFF0000) >> 16,
6919 (val2 & 0xFF000000) >> 24);
6920 }
6921
6922 val = RREG32_MASK(base + ch * 0x1000 + 0x07C, 0x0000FFFF);
6923 val = (val & 0xFF) | ((val >> 8) & 0xFF);
6924 if (val) {
6925 err = 1;
6926 dev_err(hdev->dev,
6927 "HBM%d pc%d interrupts info: WR_PAR=%d, RD_PAR=%d, CA_PAR=%d, SERR=%d, DERR=%d\n",
6928 device, ch * 2 + 1, val & 0x1, (val >> 1) & 0x1,
6929 (val >> 2) & 0x1, (val >> 3) & 0x1,
6930 (val >> 4) & 0x1);
6931
6932 val2 = RREG32(base + ch * 0x1000 + 0x070);
6933 dev_err(hdev->dev,
Ofir Bitton5a2998f2020-10-05 13:44:59 +03006934 "HBM%d pc%d ECC info: 1ST_ERR_ADDR=0x%x, 1ST_ERR_TYPE=%d, SEC_CONT_CNT=%d, SEC_CNT=%d, DEC_CNT=%d\n",
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03006935 device, ch * 2 + 1,
6936 RREG32(base + ch * 0x1000 + 0x074),
6937 (val2 & 0x200) >> 9, (val2 & 0xFC00) >> 10,
6938 (val2 & 0xFF0000) >> 16,
6939 (val2 & 0xFF000000) >> 24);
6940 }
6941
6942 /* Clear interrupts */
6943 RMWREG32(base + (ch * 0x1000) + 0x060, 0x1C8, 0x1FF);
6944 RMWREG32(base + (ch * 0x1000) + 0x070, 0x1C8, 0x1FF);
6945 WREG32(base + (ch * 0x1000) + 0x06C, 0x1F1F);
6946 WREG32(base + (ch * 0x1000) + 0x07C, 0x1F1F);
6947 RMWREG32(base + (ch * 0x1000) + 0x060, 0x0, 0xF);
6948 RMWREG32(base + (ch * 0x1000) + 0x070, 0x0, 0xF);
6949 }
6950
6951 val = RREG32(base + 0x8F30);
6952 val2 = RREG32(base + 0x8F34);
6953 if (val | val2) {
6954 err = 1;
6955 dev_err(hdev->dev,
6956 "HBM %d MC SRAM SERR info: Reg 0x8F30=0x%x, Reg 0x8F34=0x%x\n",
6957 device, val, val2);
6958 }
6959 val = RREG32(base + 0x8F40);
6960 val2 = RREG32(base + 0x8F44);
6961 if (val | val2) {
6962 err = 1;
6963 dev_err(hdev->dev,
6964 "HBM %d MC SRAM DERR info: Reg 0x8F40=0x%x, Reg 0x8F44=0x%x\n",
6965 device, val, val2);
6966 }
6967
6968 return err;
6969}
6970
6971static int gaudi_hbm_event_to_dev(u16 hbm_event_type)
6972{
6973 switch (hbm_event_type) {
6974 case GAUDI_EVENT_HBM0_SPI_0:
6975 case GAUDI_EVENT_HBM0_SPI_1:
6976 return 0;
6977 case GAUDI_EVENT_HBM1_SPI_0:
6978 case GAUDI_EVENT_HBM1_SPI_1:
6979 return 1;
6980 case GAUDI_EVENT_HBM2_SPI_0:
6981 case GAUDI_EVENT_HBM2_SPI_1:
6982 return 2;
6983 case GAUDI_EVENT_HBM3_SPI_0:
6984 case GAUDI_EVENT_HBM3_SPI_1:
6985 return 3;
6986 default:
6987 break;
6988 }
6989
6990 /* Should never happen */
6991 return 0;
6992}
6993
6994static bool gaudi_tpc_read_interrupts(struct hl_device *hdev, u8 tpc_id,
6995 char *interrupt_name)
6996{
6997 struct gaudi_device *gaudi = hdev->asic_specific;
6998 u32 tpc_offset = tpc_id * TPC_CFG_OFFSET, tpc_interrupts_cause, i;
6999 bool soft_reset_required = false;
7000
7001 /* Accessing the TPC_INTR_CAUSE registers requires disabling the clock
Oded Gabbay6138bbe2020-09-04 20:18:16 +03007002 * gating, and thus cannot be done in CPU-CP and should be done instead
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03007003 * by the driver.
7004 */
7005
7006 mutex_lock(&gaudi->clk_gate_mutex);
7007
7008 hdev->asic_funcs->disable_clock_gating(hdev);
7009
7010 tpc_interrupts_cause = RREG32(mmTPC0_CFG_TPC_INTR_CAUSE + tpc_offset) &
7011 TPC0_CFG_TPC_INTR_CAUSE_CAUSE_MASK;
7012
7013 for (i = 0 ; i < GAUDI_NUM_OF_TPC_INTR_CAUSE ; i++)
7014 if (tpc_interrupts_cause & BIT(i)) {
7015 dev_err_ratelimited(hdev->dev,
7016 "TPC%d_%s interrupt cause: %s\n",
7017 tpc_id, interrupt_name,
7018 gaudi_tpc_interrupts_cause[i]);
7019 /* If this is QM error, we need to soft-reset */
7020 if (i == 15)
7021 soft_reset_required = true;
7022 }
7023
7024 /* Clear interrupts */
7025 WREG32(mmTPC0_CFG_TPC_INTR_CAUSE + tpc_offset, 0);
7026
Oded Gabbaye38bfd32020-07-03 20:46:12 +03007027 hdev->asic_funcs->set_clock_gating(hdev);
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03007028
7029 mutex_unlock(&gaudi->clk_gate_mutex);
7030
7031 return soft_reset_required;
7032}
7033
7034static int tpc_dec_event_to_tpc_id(u16 tpc_dec_event_type)
7035{
7036 return (tpc_dec_event_type - GAUDI_EVENT_TPC0_DEC) >> 1;
7037}
7038
7039static int tpc_krn_event_to_tpc_id(u16 tpc_dec_event_type)
7040{
7041 return (tpc_dec_event_type - GAUDI_EVENT_TPC0_KRN_ERR) / 6;
7042}
7043
7044static void gaudi_print_clk_change_info(struct hl_device *hdev,
7045 u16 event_type)
7046{
7047 switch (event_type) {
7048 case GAUDI_EVENT_FIX_POWER_ENV_S:
Ofir Bitton0a068ad2020-07-21 10:49:51 +03007049 hdev->clk_throttling_reason |= HL_CLK_THROTTLE_POWER;
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03007050 dev_info_ratelimited(hdev->dev,
7051 "Clock throttling due to power consumption\n");
7052 break;
7053
7054 case GAUDI_EVENT_FIX_POWER_ENV_E:
Ofir Bitton0a068ad2020-07-21 10:49:51 +03007055 hdev->clk_throttling_reason &= ~HL_CLK_THROTTLE_POWER;
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03007056 dev_info_ratelimited(hdev->dev,
7057 "Power envelop is safe, back to optimal clock\n");
7058 break;
7059
7060 case GAUDI_EVENT_FIX_THERMAL_ENV_S:
Ofir Bitton0a068ad2020-07-21 10:49:51 +03007061 hdev->clk_throttling_reason |= HL_CLK_THROTTLE_THERMAL;
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03007062 dev_info_ratelimited(hdev->dev,
7063 "Clock throttling due to overheating\n");
7064 break;
7065
7066 case GAUDI_EVENT_FIX_THERMAL_ENV_E:
Ofir Bitton0a068ad2020-07-21 10:49:51 +03007067 hdev->clk_throttling_reason &= ~HL_CLK_THROTTLE_THERMAL;
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03007068 dev_info_ratelimited(hdev->dev,
7069 "Thermal envelop is safe, back to optimal clock\n");
7070 break;
7071
7072 default:
7073 dev_err(hdev->dev, "Received invalid clock change event %d\n",
7074 event_type);
7075 break;
7076 }
7077}
7078
7079static void gaudi_handle_eqe(struct hl_device *hdev,
7080 struct hl_eq_entry *eq_entry)
7081{
7082 struct gaudi_device *gaudi = hdev->asic_specific;
7083 u32 ctl = le32_to_cpu(eq_entry->hdr.ctl);
7084 u16 event_type = ((ctl & EQ_CTL_EVENT_TYPE_MASK)
7085 >> EQ_CTL_EVENT_TYPE_SHIFT);
7086 u8 cause;
Oded Gabbay66446822020-05-18 16:48:01 +03007087 bool reset_required;
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03007088
7089 gaudi->events_stat[event_type]++;
7090 gaudi->events_stat_aggregate[event_type]++;
7091
7092 switch (event_type) {
7093 case GAUDI_EVENT_PCIE_CORE_DERR:
7094 case GAUDI_EVENT_PCIE_IF_DERR:
7095 case GAUDI_EVENT_PCIE_PHY_DERR:
7096 case GAUDI_EVENT_TPC0_DERR ... GAUDI_EVENT_TPC7_DERR:
7097 case GAUDI_EVENT_MME0_ACC_DERR:
7098 case GAUDI_EVENT_MME0_SBAB_DERR:
7099 case GAUDI_EVENT_MME1_ACC_DERR:
7100 case GAUDI_EVENT_MME1_SBAB_DERR:
7101 case GAUDI_EVENT_MME2_ACC_DERR:
7102 case GAUDI_EVENT_MME2_SBAB_DERR:
7103 case GAUDI_EVENT_MME3_ACC_DERR:
7104 case GAUDI_EVENT_MME3_SBAB_DERR:
7105 case GAUDI_EVENT_DMA0_DERR_ECC ... GAUDI_EVENT_DMA7_DERR_ECC:
7106 fallthrough;
7107 case GAUDI_EVENT_CPU_IF_ECC_DERR:
7108 case GAUDI_EVENT_PSOC_MEM_DERR:
7109 case GAUDI_EVENT_PSOC_CORESIGHT_DERR:
7110 case GAUDI_EVENT_SRAM0_DERR ... GAUDI_EVENT_SRAM28_DERR:
7111 case GAUDI_EVENT_DMA_IF0_DERR ... GAUDI_EVENT_DMA_IF3_DERR:
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03007112 case GAUDI_EVENT_HBM_0_DERR ... GAUDI_EVENT_HBM_3_DERR:
7113 case GAUDI_EVENT_MMU_DERR:
Oded Gabbayfcc6a4e2020-05-17 08:20:35 +03007114 gaudi_print_irq_info(hdev, event_type, true);
7115 gaudi_handle_ecc_event(hdev, event_type, &eq_entry->ecc_data);
7116 if (hdev->hard_reset_on_fw_events)
7117 hl_device_reset(hdev, true, false);
7118 break;
7119
7120 case GAUDI_EVENT_GIC500:
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03007121 case GAUDI_EVENT_AXI_ECC:
7122 case GAUDI_EVENT_L2_RAM_ECC:
7123 case GAUDI_EVENT_PLL0 ... GAUDI_EVENT_PLL17:
7124 gaudi_print_irq_info(hdev, event_type, false);
7125 if (hdev->hard_reset_on_fw_events)
7126 hl_device_reset(hdev, true, false);
7127 break;
7128
7129 case GAUDI_EVENT_HBM0_SPI_0:
7130 case GAUDI_EVENT_HBM1_SPI_0:
7131 case GAUDI_EVENT_HBM2_SPI_0:
7132 case GAUDI_EVENT_HBM3_SPI_0:
7133 gaudi_print_irq_info(hdev, event_type, false);
7134 gaudi_hbm_read_interrupts(hdev,
Ofir Bitton5a2998f2020-10-05 13:44:59 +03007135 gaudi_hbm_event_to_dev(event_type),
7136 &eq_entry->hbm_ecc_data);
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03007137 if (hdev->hard_reset_on_fw_events)
7138 hl_device_reset(hdev, true, false);
7139 break;
7140
7141 case GAUDI_EVENT_HBM0_SPI_1:
7142 case GAUDI_EVENT_HBM1_SPI_1:
7143 case GAUDI_EVENT_HBM2_SPI_1:
7144 case GAUDI_EVENT_HBM3_SPI_1:
7145 gaudi_print_irq_info(hdev, event_type, false);
7146 gaudi_hbm_read_interrupts(hdev,
Ofir Bitton5a2998f2020-10-05 13:44:59 +03007147 gaudi_hbm_event_to_dev(event_type),
7148 &eq_entry->hbm_ecc_data);
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03007149 break;
7150
7151 case GAUDI_EVENT_TPC0_DEC:
7152 case GAUDI_EVENT_TPC1_DEC:
7153 case GAUDI_EVENT_TPC2_DEC:
7154 case GAUDI_EVENT_TPC3_DEC:
7155 case GAUDI_EVENT_TPC4_DEC:
7156 case GAUDI_EVENT_TPC5_DEC:
7157 case GAUDI_EVENT_TPC6_DEC:
7158 case GAUDI_EVENT_TPC7_DEC:
7159 gaudi_print_irq_info(hdev, event_type, true);
Oded Gabbay66446822020-05-18 16:48:01 +03007160 reset_required = gaudi_tpc_read_interrupts(hdev,
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03007161 tpc_dec_event_to_tpc_id(event_type),
7162 "AXI_SLV_DEC_Error");
Oded Gabbay66446822020-05-18 16:48:01 +03007163 if (reset_required) {
7164 dev_err(hdev->dev, "hard reset required due to %s\n",
7165 gaudi_irq_map_table[event_type].name);
7166
7167 if (hdev->hard_reset_on_fw_events)
7168 hl_device_reset(hdev, true, false);
7169 } else {
7170 hl_fw_unmask_irq(hdev, event_type);
Omer Shpigelmand7985072020-05-17 23:01:22 +03007171 }
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03007172 break;
7173
7174 case GAUDI_EVENT_TPC0_KRN_ERR:
7175 case GAUDI_EVENT_TPC1_KRN_ERR:
7176 case GAUDI_EVENT_TPC2_KRN_ERR:
7177 case GAUDI_EVENT_TPC3_KRN_ERR:
7178 case GAUDI_EVENT_TPC4_KRN_ERR:
7179 case GAUDI_EVENT_TPC5_KRN_ERR:
7180 case GAUDI_EVENT_TPC6_KRN_ERR:
7181 case GAUDI_EVENT_TPC7_KRN_ERR:
7182 gaudi_print_irq_info(hdev, event_type, true);
Oded Gabbay66446822020-05-18 16:48:01 +03007183 reset_required = gaudi_tpc_read_interrupts(hdev,
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03007184 tpc_krn_event_to_tpc_id(event_type),
7185 "KRN_ERR");
Oded Gabbay66446822020-05-18 16:48:01 +03007186 if (reset_required) {
7187 dev_err(hdev->dev, "hard reset required due to %s\n",
7188 gaudi_irq_map_table[event_type].name);
7189
7190 if (hdev->hard_reset_on_fw_events)
7191 hl_device_reset(hdev, true, false);
7192 } else {
7193 hl_fw_unmask_irq(hdev, event_type);
Omer Shpigelmand7985072020-05-17 23:01:22 +03007194 }
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03007195 break;
7196
7197 case GAUDI_EVENT_PCIE_CORE_SERR:
7198 case GAUDI_EVENT_PCIE_IF_SERR:
7199 case GAUDI_EVENT_PCIE_PHY_SERR:
7200 case GAUDI_EVENT_TPC0_SERR ... GAUDI_EVENT_TPC7_SERR:
7201 case GAUDI_EVENT_MME0_ACC_SERR:
7202 case GAUDI_EVENT_MME0_SBAB_SERR:
7203 case GAUDI_EVENT_MME1_ACC_SERR:
7204 case GAUDI_EVENT_MME1_SBAB_SERR:
7205 case GAUDI_EVENT_MME2_ACC_SERR:
7206 case GAUDI_EVENT_MME2_SBAB_SERR:
7207 case GAUDI_EVENT_MME3_ACC_SERR:
7208 case GAUDI_EVENT_MME3_SBAB_SERR:
7209 case GAUDI_EVENT_DMA0_SERR_ECC ... GAUDI_EVENT_DMA7_SERR_ECC:
7210 case GAUDI_EVENT_CPU_IF_ECC_SERR:
7211 case GAUDI_EVENT_PSOC_MEM_SERR:
7212 case GAUDI_EVENT_PSOC_CORESIGHT_SERR:
7213 case GAUDI_EVENT_SRAM0_SERR ... GAUDI_EVENT_SRAM28_SERR:
7214 case GAUDI_EVENT_DMA_IF0_SERR ... GAUDI_EVENT_DMA_IF3_SERR:
7215 case GAUDI_EVENT_HBM_0_SERR ... GAUDI_EVENT_HBM_3_SERR:
7216 fallthrough;
7217 case GAUDI_EVENT_MMU_SERR:
Oded Gabbayfcc6a4e2020-05-17 08:20:35 +03007218 gaudi_print_irq_info(hdev, event_type, true);
7219 gaudi_handle_ecc_event(hdev, event_type, &eq_entry->ecc_data);
7220 hl_fw_unmask_irq(hdev, event_type);
7221 break;
7222
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03007223 case GAUDI_EVENT_PCIE_DEC:
7224 case GAUDI_EVENT_MME0_WBC_RSP:
7225 case GAUDI_EVENT_MME0_SBAB0_RSP:
7226 case GAUDI_EVENT_MME1_WBC_RSP:
7227 case GAUDI_EVENT_MME1_SBAB0_RSP:
7228 case GAUDI_EVENT_MME2_WBC_RSP:
7229 case GAUDI_EVENT_MME2_SBAB0_RSP:
7230 case GAUDI_EVENT_MME3_WBC_RSP:
7231 case GAUDI_EVENT_MME3_SBAB0_RSP:
7232 case GAUDI_EVENT_CPU_AXI_SPLITTER:
7233 case GAUDI_EVENT_PSOC_AXI_DEC:
7234 case GAUDI_EVENT_PSOC_PRSTN_FALL:
7235 case GAUDI_EVENT_MMU_PAGE_FAULT:
7236 case GAUDI_EVENT_MMU_WR_PERM:
7237 case GAUDI_EVENT_RAZWI_OR_ADC:
7238 case GAUDI_EVENT_TPC0_QM ... GAUDI_EVENT_TPC7_QM:
7239 case GAUDI_EVENT_MME0_QM ... GAUDI_EVENT_MME2_QM:
7240 case GAUDI_EVENT_DMA0_QM ... GAUDI_EVENT_DMA7_QM:
7241 fallthrough;
Oded Gabbay3c681572020-11-02 21:10:39 +02007242 case GAUDI_EVENT_NIC0_QM0:
7243 case GAUDI_EVENT_NIC0_QM1:
7244 case GAUDI_EVENT_NIC1_QM0:
7245 case GAUDI_EVENT_NIC1_QM1:
7246 case GAUDI_EVENT_NIC2_QM0:
7247 case GAUDI_EVENT_NIC2_QM1:
7248 case GAUDI_EVENT_NIC3_QM0:
7249 case GAUDI_EVENT_NIC3_QM1:
7250 case GAUDI_EVENT_NIC4_QM0:
7251 case GAUDI_EVENT_NIC4_QM1:
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03007252 case GAUDI_EVENT_DMA0_CORE ... GAUDI_EVENT_DMA7_CORE:
7253 gaudi_print_irq_info(hdev, event_type, true);
7254 gaudi_handle_qman_err(hdev, event_type);
Ofir Bittonebd8d122020-05-10 13:41:28 +03007255 hl_fw_unmask_irq(hdev, event_type);
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03007256 break;
7257
7258 case GAUDI_EVENT_RAZWI_OR_ADC_SW:
7259 gaudi_print_irq_info(hdev, event_type, true);
Oded Gabbay66446822020-05-18 16:48:01 +03007260 if (hdev->hard_reset_on_fw_events)
7261 hl_device_reset(hdev, true, false);
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03007262 break;
7263
7264 case GAUDI_EVENT_TPC0_BMON_SPMU:
7265 case GAUDI_EVENT_TPC1_BMON_SPMU:
7266 case GAUDI_EVENT_TPC2_BMON_SPMU:
7267 case GAUDI_EVENT_TPC3_BMON_SPMU:
7268 case GAUDI_EVENT_TPC4_BMON_SPMU:
7269 case GAUDI_EVENT_TPC5_BMON_SPMU:
7270 case GAUDI_EVENT_TPC6_BMON_SPMU:
7271 case GAUDI_EVENT_TPC7_BMON_SPMU:
7272 case GAUDI_EVENT_DMA_BM_CH0 ... GAUDI_EVENT_DMA_BM_CH7:
7273 gaudi_print_irq_info(hdev, event_type, false);
Ofir Bittonebd8d122020-05-10 13:41:28 +03007274 hl_fw_unmask_irq(hdev, event_type);
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03007275 break;
7276
7277 case GAUDI_EVENT_FIX_POWER_ENV_S ... GAUDI_EVENT_FIX_THERMAL_ENV_E:
7278 gaudi_print_clk_change_info(hdev, event_type);
Ofir Bittonebd8d122020-05-10 13:41:28 +03007279 hl_fw_unmask_irq(hdev, event_type);
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03007280 break;
7281
7282 case GAUDI_EVENT_PSOC_GPIO_U16_0:
7283 cause = le64_to_cpu(eq_entry->data[0]) & 0xFF;
7284 dev_err(hdev->dev,
7285 "Received high temp H/W interrupt %d (cause %d)\n",
7286 event_type, cause);
7287 break;
7288
7289 default:
7290 dev_err(hdev->dev, "Received invalid H/W interrupt %d\n",
7291 event_type);
7292 break;
7293 }
7294}
7295
7296static void *gaudi_get_events_stat(struct hl_device *hdev, bool aggregate,
7297 u32 *size)
7298{
7299 struct gaudi_device *gaudi = hdev->asic_specific;
7300
7301 if (aggregate) {
7302 *size = (u32) sizeof(gaudi->events_stat_aggregate);
7303 return gaudi->events_stat_aggregate;
7304 }
7305
7306 *size = (u32) sizeof(gaudi->events_stat);
7307 return gaudi->events_stat;
7308}
7309
Omer Shpigelman8ff5f4f2020-05-24 23:06:59 +03007310static int gaudi_mmu_invalidate_cache(struct hl_device *hdev, bool is_hard,
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03007311 u32 flags)
7312{
7313 struct gaudi_device *gaudi = hdev->asic_specific;
7314 u32 status, timeout_usec;
7315 int rc;
7316
7317 if (!(gaudi->hw_cap_initialized & HW_CAP_MMU) ||
7318 hdev->hard_reset_pending)
Omer Shpigelman8ff5f4f2020-05-24 23:06:59 +03007319 return 0;
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03007320
7321 if (hdev->pldm)
7322 timeout_usec = GAUDI_PLDM_MMU_TIMEOUT_USEC;
7323 else
7324 timeout_usec = MMU_CONFIG_TIMEOUT_USEC;
7325
Omer Shpigelman8ff5f4f2020-05-24 23:06:59 +03007326 mutex_lock(&hdev->mmu_cache_lock);
7327
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03007328 /* L0 & L1 invalidation */
Omer Shpigelmancfd41762020-06-03 13:03:35 +03007329 WREG32(mmSTLB_INV_PS, 3);
7330 WREG32(mmSTLB_CACHE_INV, gaudi->mmu_cache_inv_pi++);
Omer Shpigelman42d0b0b2020-05-17 17:35:39 +03007331 WREG32(mmSTLB_INV_PS, 2);
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03007332
7333 rc = hl_poll_timeout(
7334 hdev,
Omer Shpigelman42d0b0b2020-05-17 17:35:39 +03007335 mmSTLB_INV_PS,
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03007336 status,
7337 !status,
7338 1000,
7339 timeout_usec);
7340
Omer Shpigelman42d0b0b2020-05-17 17:35:39 +03007341 WREG32(mmSTLB_INV_SET, 0);
7342
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03007343 mutex_unlock(&hdev->mmu_cache_lock);
Omer Shpigelman8ff5f4f2020-05-24 23:06:59 +03007344
7345 if (rc) {
7346 dev_err_ratelimited(hdev->dev,
7347 "MMU cache invalidation timeout\n");
7348 hl_device_reset(hdev, true, false);
7349 }
7350
7351 return rc;
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03007352}
7353
Omer Shpigelman8ff5f4f2020-05-24 23:06:59 +03007354static int gaudi_mmu_invalidate_cache_range(struct hl_device *hdev,
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03007355 bool is_hard, u32 asid, u64 va, u64 size)
7356{
7357 struct gaudi_device *gaudi = hdev->asic_specific;
7358 u32 status, timeout_usec;
7359 u32 inv_data;
7360 u32 pi;
7361 int rc;
7362
7363 if (!(gaudi->hw_cap_initialized & HW_CAP_MMU) ||
7364 hdev->hard_reset_pending)
Omer Shpigelman8ff5f4f2020-05-24 23:06:59 +03007365 return 0;
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03007366
7367 mutex_lock(&hdev->mmu_cache_lock);
7368
7369 if (hdev->pldm)
7370 timeout_usec = GAUDI_PLDM_MMU_TIMEOUT_USEC;
7371 else
7372 timeout_usec = MMU_CONFIG_TIMEOUT_USEC;
7373
7374 /*
7375 * TODO: currently invalidate entire L0 & L1 as in regular hard
7376 * invalidation. Need to apply invalidation of specific cache
7377 * lines with mask of ASID & VA & size.
7378 * Note that L1 with be flushed entirely in any case.
7379 */
7380
7381 /* L0 & L1 invalidation */
7382 inv_data = RREG32(mmSTLB_CACHE_INV);
7383 /* PI is 8 bit */
7384 pi = ((inv_data & STLB_CACHE_INV_PRODUCER_INDEX_MASK) + 1) & 0xFF;
7385 WREG32(mmSTLB_CACHE_INV,
7386 (inv_data & STLB_CACHE_INV_INDEX_MASK_MASK) | pi);
7387
7388 rc = hl_poll_timeout(
7389 hdev,
7390 mmSTLB_INV_CONSUMER_INDEX,
7391 status,
7392 status == pi,
7393 1000,
7394 timeout_usec);
7395
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03007396 mutex_unlock(&hdev->mmu_cache_lock);
Omer Shpigelman8ff5f4f2020-05-24 23:06:59 +03007397
7398 if (rc) {
7399 dev_err_ratelimited(hdev->dev,
7400 "MMU cache invalidation timeout\n");
7401 hl_device_reset(hdev, true, false);
7402 }
7403
7404 return rc;
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03007405}
7406
7407static int gaudi_mmu_update_asid_hop0_addr(struct hl_device *hdev,
7408 u32 asid, u64 phys_addr)
7409{
7410 u32 status, timeout_usec;
7411 int rc;
7412
7413 if (hdev->pldm)
7414 timeout_usec = GAUDI_PLDM_MMU_TIMEOUT_USEC;
7415 else
7416 timeout_usec = MMU_CONFIG_TIMEOUT_USEC;
7417
7418 WREG32(MMU_ASID, asid);
7419 WREG32(MMU_HOP0_PA43_12, phys_addr >> MMU_HOP0_PA43_12_SHIFT);
7420 WREG32(MMU_HOP0_PA49_44, phys_addr >> MMU_HOP0_PA49_44_SHIFT);
7421 WREG32(MMU_BUSY, 0x80000000);
7422
7423 rc = hl_poll_timeout(
7424 hdev,
7425 MMU_BUSY,
7426 status,
7427 !(status & 0x80000000),
7428 1000,
7429 timeout_usec);
7430
7431 if (rc) {
7432 dev_err(hdev->dev,
7433 "Timeout during MMU hop0 config of asid %d\n", asid);
7434 return rc;
7435 }
7436
7437 return 0;
7438}
7439
7440static int gaudi_send_heartbeat(struct hl_device *hdev)
7441{
7442 struct gaudi_device *gaudi = hdev->asic_specific;
7443
7444 if (!(gaudi->hw_cap_initialized & HW_CAP_CPU_Q))
7445 return 0;
7446
7447 return hl_fw_send_heartbeat(hdev);
7448}
7449
Oded Gabbay2f553422020-08-15 16:28:10 +03007450static int gaudi_cpucp_info_get(struct hl_device *hdev)
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03007451{
7452 struct gaudi_device *gaudi = hdev->asic_specific;
7453 struct asic_fixed_properties *prop = &hdev->asic_prop;
7454 int rc;
7455
7456 if (!(gaudi->hw_cap_initialized & HW_CAP_CPU_Q))
7457 return 0;
7458
Alon Mizrahi41478642020-11-17 14:25:14 +02007459 rc = hl_fw_cpucp_info_get(hdev, mmCPU_BOOT_DEV_STS0);
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03007460 if (rc)
7461 return rc;
7462
Oded Gabbay2f553422020-08-15 16:28:10 +03007463 if (!strlen(prop->cpucp_info.card_name))
7464 strncpy(prop->cpucp_info.card_name, GAUDI_DEFAULT_CARD_NAME,
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03007465 CARD_NAME_MAX_LEN);
7466
Oded Gabbay2f553422020-08-15 16:28:10 +03007467 hdev->card_type = le32_to_cpu(hdev->asic_prop.cpucp_info.card_type);
Oded Gabbay58361aa2020-08-08 23:34:47 +03007468
Oded Gabbay2f553422020-08-15 16:28:10 +03007469 if (hdev->card_type == cpucp_card_type_pci)
Oded Gabbay58361aa2020-08-08 23:34:47 +03007470 prop->max_power_default = MAX_POWER_DEFAULT_PCI;
Oded Gabbay2f553422020-08-15 16:28:10 +03007471 else if (hdev->card_type == cpucp_card_type_pmc)
Oded Gabbay58361aa2020-08-08 23:34:47 +03007472 prop->max_power_default = MAX_POWER_DEFAULT_PMC;
7473
7474 hdev->max_power = prop->max_power_default;
7475
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03007476 return 0;
7477}
7478
farah kassabrid90416c2020-08-12 17:20:13 +03007479static bool gaudi_is_device_idle(struct hl_device *hdev, u64 *mask,
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03007480 struct seq_file *s)
7481{
7482 struct gaudi_device *gaudi = hdev->asic_specific;
7483 const char *fmt = "%-5d%-9s%#-14x%#-12x%#x\n";
7484 const char *mme_slave_fmt = "%-5d%-9s%-14s%-12s%#x\n";
Oded Gabbay3c681572020-11-02 21:10:39 +02007485 const char *nic_fmt = "%-5d%-9s%#-14x%#x\n";
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03007486 u32 qm_glbl_sts0, qm_cgm_sts, dma_core_sts0, tpc_cfg_sts, mme_arch_sts;
7487 bool is_idle = true, is_eng_idle, is_slave;
7488 u64 offset;
Oded Gabbay3c681572020-11-02 21:10:39 +02007489 int i, dma_id, port;
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03007490
7491 mutex_lock(&gaudi->clk_gate_mutex);
7492
7493 hdev->asic_funcs->disable_clock_gating(hdev);
7494
7495 if (s)
7496 seq_puts(s,
7497 "\nDMA is_idle QM_GLBL_STS0 QM_CGM_STS DMA_CORE_STS0\n"
7498 "--- ------- ------------ ---------- -------------\n");
7499
7500 for (i = 0 ; i < DMA_NUMBER_OF_CHNLS ; i++) {
7501 dma_id = gaudi_dma_assignment[i];
7502 offset = dma_id * DMA_QMAN_OFFSET;
7503
7504 qm_glbl_sts0 = RREG32(mmDMA0_QM_GLBL_STS0 + offset);
7505 qm_cgm_sts = RREG32(mmDMA0_QM_CGM_STS + offset);
7506 dma_core_sts0 = RREG32(mmDMA0_CORE_STS0 + offset);
7507 is_eng_idle = IS_QM_IDLE(qm_glbl_sts0, qm_cgm_sts) &&
7508 IS_DMA_IDLE(dma_core_sts0);
7509 is_idle &= is_eng_idle;
7510
7511 if (mask)
Oded Gabbayf7639462020-08-29 11:24:03 +03007512 *mask |= ((u64) !is_eng_idle) <<
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03007513 (GAUDI_ENGINE_ID_DMA_0 + dma_id);
7514 if (s)
7515 seq_printf(s, fmt, dma_id,
7516 is_eng_idle ? "Y" : "N", qm_glbl_sts0,
7517 qm_cgm_sts, dma_core_sts0);
7518 }
7519
7520 if (s)
7521 seq_puts(s,
7522 "\nTPC is_idle QM_GLBL_STS0 QM_CGM_STS CFG_STATUS\n"
7523 "--- ------- ------------ ---------- ----------\n");
7524
7525 for (i = 0 ; i < TPC_NUMBER_OF_ENGINES ; i++) {
7526 offset = i * TPC_QMAN_OFFSET;
7527 qm_glbl_sts0 = RREG32(mmTPC0_QM_GLBL_STS0 + offset);
7528 qm_cgm_sts = RREG32(mmTPC0_QM_CGM_STS + offset);
7529 tpc_cfg_sts = RREG32(mmTPC0_CFG_STATUS + offset);
7530 is_eng_idle = IS_QM_IDLE(qm_glbl_sts0, qm_cgm_sts) &&
7531 IS_TPC_IDLE(tpc_cfg_sts);
7532 is_idle &= is_eng_idle;
7533
7534 if (mask)
Oded Gabbayf7639462020-08-29 11:24:03 +03007535 *mask |= ((u64) !is_eng_idle) <<
7536 (GAUDI_ENGINE_ID_TPC_0 + i);
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03007537 if (s)
7538 seq_printf(s, fmt, i,
7539 is_eng_idle ? "Y" : "N",
7540 qm_glbl_sts0, qm_cgm_sts, tpc_cfg_sts);
7541 }
7542
7543 if (s)
7544 seq_puts(s,
7545 "\nMME is_idle QM_GLBL_STS0 QM_CGM_STS ARCH_STATUS\n"
7546 "--- ------- ------------ ---------- -----------\n");
7547
7548 for (i = 0 ; i < MME_NUMBER_OF_ENGINES ; i++) {
7549 offset = i * MME_QMAN_OFFSET;
7550 mme_arch_sts = RREG32(mmMME0_CTRL_ARCH_STATUS + offset);
7551 is_eng_idle = IS_MME_IDLE(mme_arch_sts);
7552
7553 /* MME 1 & 3 are slaves, no need to check their QMANs */
7554 is_slave = i % 2;
7555 if (!is_slave) {
7556 qm_glbl_sts0 = RREG32(mmMME0_QM_GLBL_STS0 + offset);
7557 qm_cgm_sts = RREG32(mmMME0_QM_CGM_STS + offset);
7558 is_eng_idle &= IS_QM_IDLE(qm_glbl_sts0, qm_cgm_sts);
7559 }
7560
7561 is_idle &= is_eng_idle;
7562
7563 if (mask)
Oded Gabbayf7639462020-08-29 11:24:03 +03007564 *mask |= ((u64) !is_eng_idle) <<
7565 (GAUDI_ENGINE_ID_MME_0 + i);
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03007566 if (s) {
7567 if (!is_slave)
7568 seq_printf(s, fmt, i,
7569 is_eng_idle ? "Y" : "N",
7570 qm_glbl_sts0, qm_cgm_sts, mme_arch_sts);
7571 else
7572 seq_printf(s, mme_slave_fmt, i,
7573 is_eng_idle ? "Y" : "N", "-",
7574 "-", mme_arch_sts);
7575 }
7576 }
7577
7578 if (s)
Oded Gabbay3c681572020-11-02 21:10:39 +02007579 seq_puts(s, "\nNIC is_idle QM_GLBL_STS0 QM_CGM_STS\n"
7580 "--- ------- ------------ ----------\n");
7581
7582 for (i = 0 ; i < (NIC_NUMBER_OF_ENGINES / 2) ; i++) {
7583 offset = i * NIC_MACRO_QMAN_OFFSET;
7584 port = 2 * i;
7585 if (hdev->nic_ports_mask & BIT(port)) {
7586 qm_glbl_sts0 = RREG32(mmNIC0_QM0_GLBL_STS0 + offset);
7587 qm_cgm_sts = RREG32(mmNIC0_QM0_CGM_STS + offset);
7588 is_eng_idle = IS_QM_IDLE(qm_glbl_sts0, qm_cgm_sts);
7589 is_idle &= is_eng_idle;
7590
7591 if (mask)
7592 *mask |= ((u64) !is_eng_idle) <<
7593 (GAUDI_ENGINE_ID_NIC_0 + port);
7594 if (s)
7595 seq_printf(s, nic_fmt, port,
7596 is_eng_idle ? "Y" : "N",
7597 qm_glbl_sts0, qm_cgm_sts);
7598 }
7599
7600 port = 2 * i + 1;
7601 if (hdev->nic_ports_mask & BIT(port)) {
7602 qm_glbl_sts0 = RREG32(mmNIC0_QM1_GLBL_STS0 + offset);
7603 qm_cgm_sts = RREG32(mmNIC0_QM1_CGM_STS + offset);
7604 is_eng_idle = IS_QM_IDLE(qm_glbl_sts0, qm_cgm_sts);
7605 is_idle &= is_eng_idle;
7606
7607 if (mask)
7608 *mask |= ((u64) !is_eng_idle) <<
7609 (GAUDI_ENGINE_ID_NIC_0 + port);
7610 if (s)
7611 seq_printf(s, nic_fmt, port,
7612 is_eng_idle ? "Y" : "N",
7613 qm_glbl_sts0, qm_cgm_sts);
7614 }
7615 }
7616
7617 if (s)
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03007618 seq_puts(s, "\n");
7619
Oded Gabbaye38bfd32020-07-03 20:46:12 +03007620 hdev->asic_funcs->set_clock_gating(hdev);
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03007621
7622 mutex_unlock(&gaudi->clk_gate_mutex);
7623
7624 return is_idle;
7625}
7626
7627static void gaudi_hw_queues_lock(struct hl_device *hdev)
7628 __acquires(&gaudi->hw_queues_lock)
7629{
7630 struct gaudi_device *gaudi = hdev->asic_specific;
7631
7632 spin_lock(&gaudi->hw_queues_lock);
7633}
7634
7635static void gaudi_hw_queues_unlock(struct hl_device *hdev)
7636 __releases(&gaudi->hw_queues_lock)
7637{
7638 struct gaudi_device *gaudi = hdev->asic_specific;
7639
7640 spin_unlock(&gaudi->hw_queues_lock);
7641}
7642
7643static u32 gaudi_get_pci_id(struct hl_device *hdev)
7644{
7645 return hdev->pdev->device;
7646}
7647
7648static int gaudi_get_eeprom_data(struct hl_device *hdev, void *data,
7649 size_t max_size)
7650{
7651 struct gaudi_device *gaudi = hdev->asic_specific;
7652
7653 if (!(gaudi->hw_cap_initialized & HW_CAP_CPU_Q))
7654 return 0;
7655
7656 return hl_fw_get_eeprom_data(hdev, data, max_size);
7657}
7658
7659/*
7660 * this function should be used only during initialization and/or after reset,
7661 * when there are no active users.
7662 */
7663static int gaudi_run_tpc_kernel(struct hl_device *hdev, u64 tpc_kernel,
7664 u32 tpc_id)
7665{
7666 struct gaudi_device *gaudi = hdev->asic_specific;
7667 u64 kernel_timeout;
7668 u32 status, offset;
7669 int rc;
7670
7671 offset = tpc_id * (mmTPC1_CFG_STATUS - mmTPC0_CFG_STATUS);
7672
7673 if (hdev->pldm)
7674 kernel_timeout = GAUDI_PLDM_TPC_KERNEL_WAIT_USEC;
7675 else
7676 kernel_timeout = HL_DEVICE_TIMEOUT_USEC;
7677
7678 mutex_lock(&gaudi->clk_gate_mutex);
7679
7680 hdev->asic_funcs->disable_clock_gating(hdev);
7681
7682 WREG32(mmTPC0_CFG_QM_KERNEL_BASE_ADDRESS_LOW + offset,
7683 lower_32_bits(tpc_kernel));
7684 WREG32(mmTPC0_CFG_QM_KERNEL_BASE_ADDRESS_HIGH + offset,
7685 upper_32_bits(tpc_kernel));
7686
7687 WREG32(mmTPC0_CFG_ICACHE_BASE_ADDERESS_LOW + offset,
7688 lower_32_bits(tpc_kernel));
7689 WREG32(mmTPC0_CFG_ICACHE_BASE_ADDERESS_HIGH + offset,
7690 upper_32_bits(tpc_kernel));
7691 /* set a valid LUT pointer, content is of no significance */
7692 WREG32(mmTPC0_CFG_LUT_FUNC256_BASE_ADDR_LO + offset,
7693 lower_32_bits(tpc_kernel));
7694 WREG32(mmTPC0_CFG_LUT_FUNC256_BASE_ADDR_HI + offset,
7695 upper_32_bits(tpc_kernel));
7696
7697 WREG32(mmTPC0_CFG_QM_SYNC_OBJECT_ADDR + offset,
7698 lower_32_bits(CFG_BASE +
7699 mmSYNC_MNGR_E_N_SYNC_MNGR_OBJS_SOB_OBJ_0));
7700
7701 WREG32(mmTPC0_CFG_TPC_CMD + offset,
7702 (1 << TPC0_CFG_TPC_CMD_ICACHE_INVALIDATE_SHIFT |
7703 1 << TPC0_CFG_TPC_CMD_ICACHE_PREFETCH_64KB_SHIFT));
7704 /* wait a bit for the engine to start executing */
7705 usleep_range(1000, 1500);
7706
7707 /* wait until engine has finished executing */
7708 rc = hl_poll_timeout(
7709 hdev,
7710 mmTPC0_CFG_STATUS + offset,
7711 status,
7712 (status & TPC0_CFG_STATUS_VECTOR_PIPE_EMPTY_MASK) ==
7713 TPC0_CFG_STATUS_VECTOR_PIPE_EMPTY_MASK,
7714 1000,
7715 kernel_timeout);
7716
7717 if (rc) {
7718 dev_err(hdev->dev,
7719 "Timeout while waiting for TPC%d icache prefetch\n",
7720 tpc_id);
Oded Gabbaye38bfd32020-07-03 20:46:12 +03007721 hdev->asic_funcs->set_clock_gating(hdev);
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03007722 mutex_unlock(&gaudi->clk_gate_mutex);
7723 return -EIO;
7724 }
7725
7726 WREG32(mmTPC0_CFG_TPC_EXECUTE + offset,
7727 1 << TPC0_CFG_TPC_EXECUTE_V_SHIFT);
7728
7729 /* wait a bit for the engine to start executing */
7730 usleep_range(1000, 1500);
7731
7732 /* wait until engine has finished executing */
7733 rc = hl_poll_timeout(
7734 hdev,
7735 mmTPC0_CFG_STATUS + offset,
7736 status,
7737 (status & TPC0_CFG_STATUS_VECTOR_PIPE_EMPTY_MASK) ==
7738 TPC0_CFG_STATUS_VECTOR_PIPE_EMPTY_MASK,
7739 1000,
7740 kernel_timeout);
7741
Oded Gabbay31ac1f12020-08-12 11:28:13 +03007742 if (rc) {
7743 dev_err(hdev->dev,
7744 "Timeout while waiting for TPC%d vector pipe\n",
7745 tpc_id);
7746 hdev->asic_funcs->set_clock_gating(hdev);
7747 mutex_unlock(&gaudi->clk_gate_mutex);
7748 return -EIO;
7749 }
7750
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03007751 rc = hl_poll_timeout(
7752 hdev,
7753 mmTPC0_CFG_WQ_INFLIGHT_CNTR + offset,
7754 status,
7755 (status == 0),
7756 1000,
7757 kernel_timeout);
7758
Oded Gabbaye38bfd32020-07-03 20:46:12 +03007759 hdev->asic_funcs->set_clock_gating(hdev);
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03007760 mutex_unlock(&gaudi->clk_gate_mutex);
7761
7762 if (rc) {
7763 dev_err(hdev->dev,
7764 "Timeout while waiting for TPC%d kernel to execute\n",
7765 tpc_id);
7766 return -EIO;
7767 }
7768
7769 return 0;
7770}
7771
Ofir Bitton5de406c2020-09-10 10:56:26 +03007772static int gaudi_internal_cb_pool_init(struct hl_device *hdev,
7773 struct hl_ctx *ctx)
7774{
7775 struct gaudi_device *gaudi = hdev->asic_specific;
Ofir Bitton5de406c2020-09-10 10:56:26 +03007776 int min_alloc_order, rc, collective_cb_size;
7777
7778 if (!(gaudi->hw_cap_initialized & HW_CAP_MMU))
7779 return 0;
7780
7781 hdev->internal_cb_pool_virt_addr =
7782 hdev->asic_funcs->asic_dma_alloc_coherent(hdev,
7783 HOST_SPACE_INTERNAL_CB_SZ,
7784 &hdev->internal_cb_pool_dma_addr,
7785 GFP_KERNEL | __GFP_ZERO);
7786
7787 if (!hdev->internal_cb_pool_virt_addr)
7788 return -ENOMEM;
7789
7790 collective_cb_size = sizeof(struct packet_msg_short) * 5 +
7791 sizeof(struct packet_fence);
7792 min_alloc_order = ilog2(collective_cb_size);
7793
7794 hdev->internal_cb_pool = gen_pool_create(min_alloc_order, -1);
7795 if (!hdev->internal_cb_pool) {
7796 dev_err(hdev->dev,
7797 "Failed to create internal CB pool\n");
7798 rc = -ENOMEM;
7799 goto free_internal_cb_pool;
7800 }
7801
7802 rc = gen_pool_add(hdev->internal_cb_pool,
7803 (uintptr_t) hdev->internal_cb_pool_virt_addr,
7804 HOST_SPACE_INTERNAL_CB_SZ, -1);
7805 if (rc) {
7806 dev_err(hdev->dev,
7807 "Failed to add memory to internal CB pool\n");
7808 rc = -EFAULT;
7809 goto destroy_internal_cb_pool;
7810 }
7811
Ofir Bittonbe91b912020-10-22 15:04:10 +03007812 hdev->internal_cb_va_base = hl_reserve_va_block(hdev, ctx,
Ofir Bitton412c41f2020-11-04 15:18:55 +02007813 HL_VA_RANGE_TYPE_HOST, HOST_SPACE_INTERNAL_CB_SZ,
7814 HL_MMU_VA_ALIGNMENT_NOT_NEEDED);
Ofir Bittonbe91b912020-10-22 15:04:10 +03007815
7816 if (!hdev->internal_cb_va_base)
7817 goto destroy_internal_cb_pool;
Ofir Bitton5de406c2020-09-10 10:56:26 +03007818
7819 mutex_lock(&ctx->mmu_lock);
Ofir Bitton5c054872020-10-22 15:13:10 +03007820 rc = hl_mmu_map_contiguous(ctx, hdev->internal_cb_va_base,
7821 hdev->internal_cb_pool_dma_addr,
7822 HOST_SPACE_INTERNAL_CB_SZ);
Ofir Bitton5de406c2020-09-10 10:56:26 +03007823
7824 hdev->asic_funcs->mmu_invalidate_cache(hdev, false, VM_TYPE_USERPTR);
Ofir Bitton5de406c2020-09-10 10:56:26 +03007825 mutex_unlock(&ctx->mmu_lock);
7826
Ofir Bitton5c054872020-10-22 15:13:10 +03007827 if (rc)
7828 goto unreserve_internal_cb_pool;
7829
Ofir Bitton5de406c2020-09-10 10:56:26 +03007830 return 0;
7831
Ofir Bitton5c054872020-10-22 15:13:10 +03007832unreserve_internal_cb_pool:
Ofir Bittonbe91b912020-10-22 15:04:10 +03007833 hl_unreserve_va_block(hdev, ctx, hdev->internal_cb_va_base,
7834 HOST_SPACE_INTERNAL_CB_SZ);
Ofir Bitton5de406c2020-09-10 10:56:26 +03007835destroy_internal_cb_pool:
7836 gen_pool_destroy(hdev->internal_cb_pool);
Ofir Bitton5de406c2020-09-10 10:56:26 +03007837free_internal_cb_pool:
7838 hdev->asic_funcs->asic_dma_free_coherent(hdev,
7839 HOST_SPACE_INTERNAL_CB_SZ,
7840 hdev->internal_cb_pool_virt_addr,
7841 hdev->internal_cb_pool_dma_addr);
7842
7843 return rc;
7844}
7845
7846static void gaudi_internal_cb_pool_fini(struct hl_device *hdev,
7847 struct hl_ctx *ctx)
7848{
7849 struct gaudi_device *gaudi = hdev->asic_specific;
Ofir Bitton5de406c2020-09-10 10:56:26 +03007850
7851 if (!(gaudi->hw_cap_initialized & HW_CAP_MMU))
7852 return;
7853
7854 mutex_lock(&ctx->mmu_lock);
Ofir Bitton5c054872020-10-22 15:13:10 +03007855 hl_mmu_unmap_contiguous(ctx, hdev->internal_cb_va_base,
7856 HOST_SPACE_INTERNAL_CB_SZ);
Ofir Bittonbe91b912020-10-22 15:04:10 +03007857 hl_unreserve_va_block(hdev, ctx, hdev->internal_cb_va_base,
7858 HOST_SPACE_INTERNAL_CB_SZ);
Ofir Bitton5de406c2020-09-10 10:56:26 +03007859 hdev->asic_funcs->mmu_invalidate_cache(hdev, true, VM_TYPE_USERPTR);
Ofir Bitton5de406c2020-09-10 10:56:26 +03007860 mutex_unlock(&ctx->mmu_lock);
7861
7862 gen_pool_destroy(hdev->internal_cb_pool);
7863
7864 hdev->asic_funcs->asic_dma_free_coherent(hdev,
7865 HOST_SPACE_INTERNAL_CB_SZ,
7866 hdev->internal_cb_pool_virt_addr,
7867 hdev->internal_cb_pool_dma_addr);
7868}
7869
kernel test robotbb34bf72020-07-29 08:03:13 +08007870static int gaudi_ctx_init(struct hl_ctx *ctx)
Ofir Bittona04b7cd2020-07-13 13:36:55 +03007871{
Ofir Bitton20b75252020-09-30 15:51:10 +03007872 gaudi_mmu_prepare(ctx->hdev, ctx->asid);
Ofir Bitton5de406c2020-09-10 10:56:26 +03007873 return gaudi_internal_cb_pool_init(ctx->hdev, ctx);
7874}
Ofir Bitton20b75252020-09-30 15:51:10 +03007875
kernel test robot293744d2020-11-19 12:25:43 +08007876static void gaudi_ctx_fini(struct hl_ctx *ctx)
Ofir Bitton5de406c2020-09-10 10:56:26 +03007877{
7878 struct hl_device *hdev = ctx->hdev;
7879
7880 /* Gaudi will NEVER support more then a single compute context.
7881 * Therefore, don't clear anything unless it is the compute context
7882 */
7883 if (hdev->compute_ctx != ctx)
7884 return;
7885
7886 gaudi_internal_cb_pool_fini(ctx->hdev, ctx);
Ofir Bittona04b7cd2020-07-13 13:36:55 +03007887}
7888
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03007889static u32 gaudi_get_queue_id_for_cq(struct hl_device *hdev, u32 cq_idx)
7890{
7891 return gaudi_cq_assignment[cq_idx];
7892}
7893
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03007894static u32 gaudi_get_signal_cb_size(struct hl_device *hdev)
7895{
7896 return sizeof(struct packet_msg_short) +
7897 sizeof(struct packet_msg_prot) * 2;
7898}
7899
7900static u32 gaudi_get_wait_cb_size(struct hl_device *hdev)
7901{
7902 return sizeof(struct packet_msg_short) * 4 +
7903 sizeof(struct packet_fence) +
7904 sizeof(struct packet_msg_prot) * 2;
7905}
7906
Ofir Bitton2992c1d2020-09-10 09:40:35 +03007907static u32 gaudi_gen_signal_cb(struct hl_device *hdev, void *data, u16 sob_id,
Alon Mizrahi72ab9ca52020-12-02 19:55:30 +02007908 u32 size, bool eb)
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03007909{
7910 struct hl_cb *cb = (struct hl_cb *) data;
7911 struct packet_msg_short *pkt;
Ofir Bitton2992c1d2020-09-10 09:40:35 +03007912 u32 value, ctl, pkt_size = sizeof(*pkt);
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03007913
Ofir Bitton2992c1d2020-09-10 09:40:35 +03007914 pkt = cb->kernel_address + size;
7915 memset(pkt, 0, pkt_size);
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03007916
Ofir Bitton6c07bab2020-06-01 10:38:46 +03007917 /* Inc by 1, Mode ADD */
7918 value = FIELD_PREP(GAUDI_PKT_SHORT_VAL_SOB_SYNC_VAL_MASK, 1);
7919 value |= FIELD_PREP(GAUDI_PKT_SHORT_VAL_SOB_MOD_MASK, 1);
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03007920
Ofir Bitton6c07bab2020-06-01 10:38:46 +03007921 ctl = FIELD_PREP(GAUDI_PKT_SHORT_CTL_ADDR_MASK, sob_id * 4);
7922 ctl |= FIELD_PREP(GAUDI_PKT_SHORT_CTL_OP_MASK, 0); /* write the value */
7923 ctl |= FIELD_PREP(GAUDI_PKT_SHORT_CTL_BASE_MASK, 3); /* W_S SOB base */
7924 ctl |= FIELD_PREP(GAUDI_PKT_SHORT_CTL_OPCODE_MASK, PACKET_MSG_SHORT);
Alon Mizrahi72ab9ca52020-12-02 19:55:30 +02007925 ctl |= FIELD_PREP(GAUDI_PKT_SHORT_CTL_EB_MASK, eb);
Ofir Bitton6c07bab2020-06-01 10:38:46 +03007926 ctl |= FIELD_PREP(GAUDI_PKT_SHORT_CTL_RB_MASK, 1);
7927 ctl |= FIELD_PREP(GAUDI_PKT_SHORT_CTL_MB_MASK, 1);
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03007928
7929 pkt->value = cpu_to_le32(value);
7930 pkt->ctl = cpu_to_le32(ctl);
Ofir Bitton2992c1d2020-09-10 09:40:35 +03007931
7932 return size + pkt_size;
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03007933}
7934
7935static u32 gaudi_add_mon_msg_short(struct packet_msg_short *pkt, u32 value,
7936 u16 addr)
7937{
7938 u32 ctl, pkt_size = sizeof(*pkt);
7939
7940 memset(pkt, 0, pkt_size);
7941
Ofir Bitton6c07bab2020-06-01 10:38:46 +03007942 ctl = FIELD_PREP(GAUDI_PKT_SHORT_CTL_ADDR_MASK, addr);
7943 ctl |= FIELD_PREP(GAUDI_PKT_SHORT_CTL_BASE_MASK, 2); /* W_S MON base */
7944 ctl |= FIELD_PREP(GAUDI_PKT_SHORT_CTL_OPCODE_MASK, PACKET_MSG_SHORT);
7945 ctl |= FIELD_PREP(GAUDI_PKT_SHORT_CTL_EB_MASK, 0);
7946 ctl |= FIELD_PREP(GAUDI_PKT_SHORT_CTL_RB_MASK, 1);
7947 ctl |= FIELD_PREP(GAUDI_PKT_SHORT_CTL_MB_MASK, 0); /* last pkt MB */
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03007948
7949 pkt->value = cpu_to_le32(value);
7950 pkt->ctl = cpu_to_le32(ctl);
7951
7952 return pkt_size;
7953}
7954
Ofir Bitton2992c1d2020-09-10 09:40:35 +03007955static u32 gaudi_add_arm_monitor_pkt(struct hl_device *hdev,
7956 struct packet_msg_short *pkt, u16 sob_base, u8 sob_mask,
7957 u16 sob_val, u16 mon_id)
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03007958{
Ofir Bitton2992c1d2020-09-10 09:40:35 +03007959 u64 monitor_base;
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03007960 u32 ctl, value, pkt_size = sizeof(*pkt);
Ofir Bitton2992c1d2020-09-10 09:40:35 +03007961 u16 msg_addr_offset;
7962 u8 mask;
7963
7964 if (hl_gen_sob_mask(sob_base, sob_mask, &mask)) {
7965 dev_err(hdev->dev,
7966 "sob_base %u (mask %#x) is not valid\n",
7967 sob_base, sob_mask);
7968 return 0;
7969 }
7970
7971 /*
7972 * monitor_base should be the content of the base0 address registers,
7973 * so it will be added to the msg short offsets
7974 */
7975 monitor_base = mmSYNC_MNGR_W_S_SYNC_MNGR_OBJS_MON_PAY_ADDRL_0;
7976
7977 msg_addr_offset =
7978 (mmSYNC_MNGR_W_S_SYNC_MNGR_OBJS_MON_ARM_0 + mon_id * 4) -
7979 monitor_base;
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03007980
7981 memset(pkt, 0, pkt_size);
7982
Ofir Bitton2992c1d2020-09-10 09:40:35 +03007983 /* Monitor config packet: bind the monitor to a sync object */
7984 value = FIELD_PREP(GAUDI_PKT_SHORT_VAL_MON_SYNC_GID_MASK, sob_base / 8);
Ofir Bitton6c07bab2020-06-01 10:38:46 +03007985 value |= FIELD_PREP(GAUDI_PKT_SHORT_VAL_MON_SYNC_VAL_MASK, sob_val);
7986 value |= FIELD_PREP(GAUDI_PKT_SHORT_VAL_MON_MODE_MASK,
7987 0); /* GREATER OR EQUAL*/
7988 value |= FIELD_PREP(GAUDI_PKT_SHORT_VAL_MON_MASK_MASK, mask);
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03007989
Ofir Bitton2992c1d2020-09-10 09:40:35 +03007990 ctl = FIELD_PREP(GAUDI_PKT_SHORT_CTL_ADDR_MASK, msg_addr_offset);
Ofir Bitton6c07bab2020-06-01 10:38:46 +03007991 ctl |= FIELD_PREP(GAUDI_PKT_SHORT_CTL_OP_MASK, 0); /* write the value */
7992 ctl |= FIELD_PREP(GAUDI_PKT_SHORT_CTL_BASE_MASK, 2); /* W_S MON base */
7993 ctl |= FIELD_PREP(GAUDI_PKT_SHORT_CTL_OPCODE_MASK, PACKET_MSG_SHORT);
7994 ctl |= FIELD_PREP(GAUDI_PKT_SHORT_CTL_EB_MASK, 0);
7995 ctl |= FIELD_PREP(GAUDI_PKT_SHORT_CTL_RB_MASK, 1);
7996 ctl |= FIELD_PREP(GAUDI_PKT_SHORT_CTL_MB_MASK, 1);
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03007997
7998 pkt->value = cpu_to_le32(value);
7999 pkt->ctl = cpu_to_le32(ctl);
8000
8001 return pkt_size;
8002}
8003
8004static u32 gaudi_add_fence_pkt(struct packet_fence *pkt)
8005{
8006 u32 ctl, cfg, pkt_size = sizeof(*pkt);
8007
8008 memset(pkt, 0, pkt_size);
8009
Ofir Bitton6c07bab2020-06-01 10:38:46 +03008010 cfg = FIELD_PREP(GAUDI_PKT_FENCE_CFG_DEC_VAL_MASK, 1);
8011 cfg |= FIELD_PREP(GAUDI_PKT_FENCE_CFG_TARGET_VAL_MASK, 1);
8012 cfg |= FIELD_PREP(GAUDI_PKT_FENCE_CFG_ID_MASK, 2);
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03008013
Ofir Bitton6c07bab2020-06-01 10:38:46 +03008014 ctl = FIELD_PREP(GAUDI_PKT_FENCE_CTL_OPCODE_MASK, PACKET_FENCE);
8015 ctl |= FIELD_PREP(GAUDI_PKT_SHORT_CTL_EB_MASK, 0);
8016 ctl |= FIELD_PREP(GAUDI_PKT_SHORT_CTL_RB_MASK, 1);
8017 ctl |= FIELD_PREP(GAUDI_PKT_SHORT_CTL_MB_MASK, 1);
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03008018
8019 pkt->cfg = cpu_to_le32(cfg);
8020 pkt->ctl = cpu_to_le32(ctl);
8021
8022 return pkt_size;
8023}
8024
Ofir Bitton2992c1d2020-09-10 09:40:35 +03008025static int gaudi_get_fence_addr(struct hl_device *hdev, u32 queue_id, u64 *addr)
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03008026{
Ofir Bitton5de406c2020-09-10 10:56:26 +03008027 u32 offset, nic_index;
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03008028
Ofir Bitton2992c1d2020-09-10 09:40:35 +03008029 switch (queue_id) {
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03008030 case GAUDI_QUEUE_ID_DMA_0_0:
Ofir Bitton2992c1d2020-09-10 09:40:35 +03008031 offset = mmDMA0_QM_CP_FENCE2_RDATA_0;
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03008032 break;
8033 case GAUDI_QUEUE_ID_DMA_0_1:
Ofir Bitton2992c1d2020-09-10 09:40:35 +03008034 offset = mmDMA0_QM_CP_FENCE2_RDATA_1;
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03008035 break;
8036 case GAUDI_QUEUE_ID_DMA_0_2:
Ofir Bitton2992c1d2020-09-10 09:40:35 +03008037 offset = mmDMA0_QM_CP_FENCE2_RDATA_2;
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03008038 break;
8039 case GAUDI_QUEUE_ID_DMA_0_3:
Ofir Bitton2992c1d2020-09-10 09:40:35 +03008040 offset = mmDMA0_QM_CP_FENCE2_RDATA_3;
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03008041 break;
8042 case GAUDI_QUEUE_ID_DMA_1_0:
Ofir Bitton2992c1d2020-09-10 09:40:35 +03008043 offset = mmDMA1_QM_CP_FENCE2_RDATA_0;
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03008044 break;
8045 case GAUDI_QUEUE_ID_DMA_1_1:
Ofir Bitton2992c1d2020-09-10 09:40:35 +03008046 offset = mmDMA1_QM_CP_FENCE2_RDATA_1;
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03008047 break;
8048 case GAUDI_QUEUE_ID_DMA_1_2:
Ofir Bitton2992c1d2020-09-10 09:40:35 +03008049 offset = mmDMA1_QM_CP_FENCE2_RDATA_2;
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03008050 break;
8051 case GAUDI_QUEUE_ID_DMA_1_3:
Ofir Bitton2992c1d2020-09-10 09:40:35 +03008052 offset = mmDMA1_QM_CP_FENCE2_RDATA_3;
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03008053 break;
8054 case GAUDI_QUEUE_ID_DMA_5_0:
Ofir Bitton2992c1d2020-09-10 09:40:35 +03008055 offset = mmDMA5_QM_CP_FENCE2_RDATA_0;
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03008056 break;
8057 case GAUDI_QUEUE_ID_DMA_5_1:
Ofir Bitton2992c1d2020-09-10 09:40:35 +03008058 offset = mmDMA5_QM_CP_FENCE2_RDATA_1;
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03008059 break;
8060 case GAUDI_QUEUE_ID_DMA_5_2:
Ofir Bitton2992c1d2020-09-10 09:40:35 +03008061 offset = mmDMA5_QM_CP_FENCE2_RDATA_2;
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03008062 break;
8063 case GAUDI_QUEUE_ID_DMA_5_3:
Ofir Bitton2992c1d2020-09-10 09:40:35 +03008064 offset = mmDMA5_QM_CP_FENCE2_RDATA_3;
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03008065 break;
Ofir Bitton5de406c2020-09-10 10:56:26 +03008066 case GAUDI_QUEUE_ID_TPC_7_0:
8067 offset = mmTPC7_QM_CP_FENCE2_RDATA_0;
8068 break;
8069 case GAUDI_QUEUE_ID_TPC_7_1:
8070 offset = mmTPC7_QM_CP_FENCE2_RDATA_1;
8071 break;
8072 case GAUDI_QUEUE_ID_TPC_7_2:
8073 offset = mmTPC7_QM_CP_FENCE2_RDATA_2;
8074 break;
8075 case GAUDI_QUEUE_ID_TPC_7_3:
8076 offset = mmTPC7_QM_CP_FENCE2_RDATA_3;
8077 break;
8078 case GAUDI_QUEUE_ID_NIC_0_0:
8079 case GAUDI_QUEUE_ID_NIC_1_0:
8080 case GAUDI_QUEUE_ID_NIC_2_0:
8081 case GAUDI_QUEUE_ID_NIC_3_0:
8082 case GAUDI_QUEUE_ID_NIC_4_0:
8083 case GAUDI_QUEUE_ID_NIC_5_0:
8084 case GAUDI_QUEUE_ID_NIC_6_0:
8085 case GAUDI_QUEUE_ID_NIC_7_0:
8086 case GAUDI_QUEUE_ID_NIC_8_0:
8087 case GAUDI_QUEUE_ID_NIC_9_0:
8088 nic_index = (queue_id - GAUDI_QUEUE_ID_NIC_0_0) >> 2;
8089 offset = mmNIC0_QM0_CP_FENCE2_RDATA_0 +
8090 (nic_index >> 1) * NIC_MACRO_QMAN_OFFSET +
8091 (nic_index & 0x1) * NIC_ENGINE_QMAN_OFFSET;
8092 break;
8093 case GAUDI_QUEUE_ID_NIC_0_1:
8094 case GAUDI_QUEUE_ID_NIC_1_1:
8095 case GAUDI_QUEUE_ID_NIC_2_1:
8096 case GAUDI_QUEUE_ID_NIC_3_1:
8097 case GAUDI_QUEUE_ID_NIC_4_1:
8098 case GAUDI_QUEUE_ID_NIC_5_1:
8099 case GAUDI_QUEUE_ID_NIC_6_1:
8100 case GAUDI_QUEUE_ID_NIC_7_1:
8101 case GAUDI_QUEUE_ID_NIC_8_1:
8102 case GAUDI_QUEUE_ID_NIC_9_1:
8103 nic_index = (queue_id - GAUDI_QUEUE_ID_NIC_0_1) >> 2;
8104 offset = mmNIC0_QM0_CP_FENCE2_RDATA_1 +
8105 (nic_index >> 1) * NIC_MACRO_QMAN_OFFSET +
8106 (nic_index & 0x1) * NIC_ENGINE_QMAN_OFFSET;
8107 break;
8108 case GAUDI_QUEUE_ID_NIC_0_2:
8109 case GAUDI_QUEUE_ID_NIC_1_2:
8110 case GAUDI_QUEUE_ID_NIC_2_2:
8111 case GAUDI_QUEUE_ID_NIC_3_2:
8112 case GAUDI_QUEUE_ID_NIC_4_2:
8113 case GAUDI_QUEUE_ID_NIC_5_2:
8114 case GAUDI_QUEUE_ID_NIC_6_2:
8115 case GAUDI_QUEUE_ID_NIC_7_2:
8116 case GAUDI_QUEUE_ID_NIC_8_2:
8117 case GAUDI_QUEUE_ID_NIC_9_2:
8118 nic_index = (queue_id - GAUDI_QUEUE_ID_NIC_0_2) >> 2;
8119 offset = mmNIC0_QM0_CP_FENCE2_RDATA_2 +
8120 (nic_index >> 1) * NIC_MACRO_QMAN_OFFSET +
8121 (nic_index & 0x1) * NIC_ENGINE_QMAN_OFFSET;
8122 break;
8123 case GAUDI_QUEUE_ID_NIC_0_3:
8124 case GAUDI_QUEUE_ID_NIC_1_3:
8125 case GAUDI_QUEUE_ID_NIC_2_3:
8126 case GAUDI_QUEUE_ID_NIC_3_3:
8127 case GAUDI_QUEUE_ID_NIC_4_3:
8128 case GAUDI_QUEUE_ID_NIC_5_3:
8129 case GAUDI_QUEUE_ID_NIC_6_3:
8130 case GAUDI_QUEUE_ID_NIC_7_3:
8131 case GAUDI_QUEUE_ID_NIC_8_3:
8132 case GAUDI_QUEUE_ID_NIC_9_3:
8133 nic_index = (queue_id - GAUDI_QUEUE_ID_NIC_0_3) >> 2;
8134 offset = mmNIC0_QM0_CP_FENCE2_RDATA_3 +
8135 (nic_index >> 1) * NIC_MACRO_QMAN_OFFSET +
8136 (nic_index & 0x1) * NIC_ENGINE_QMAN_OFFSET;
8137 break;
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03008138 default:
Ofir Bitton2992c1d2020-09-10 09:40:35 +03008139 return -EINVAL;
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03008140 }
8141
Ofir Bitton2992c1d2020-09-10 09:40:35 +03008142 *addr = CFG_BASE + offset;
8143
8144 return 0;
8145}
8146
8147static u32 gaudi_add_mon_pkts(void *buf, u16 mon_id, u64 fence_addr)
8148{
8149 u64 monitor_base;
8150 u32 size = 0;
8151 u16 msg_addr_offset;
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03008152
8153 /*
8154 * monitor_base should be the content of the base0 address registers,
8155 * so it will be added to the msg short offsets
8156 */
8157 monitor_base = mmSYNC_MNGR_W_S_SYNC_MNGR_OBJS_MON_PAY_ADDRL_0;
8158
8159 /* First monitor config packet: low address of the sync */
Ofir Bitton2992c1d2020-09-10 09:40:35 +03008160 msg_addr_offset =
8161 (mmSYNC_MNGR_W_S_SYNC_MNGR_OBJS_MON_PAY_ADDRL_0 + mon_id * 4) -
8162 monitor_base;
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03008163
8164 size += gaudi_add_mon_msg_short(buf + size, (u32) fence_addr,
8165 msg_addr_offset);
8166
8167 /* Second monitor config packet: high address of the sync */
Ofir Bitton2992c1d2020-09-10 09:40:35 +03008168 msg_addr_offset =
8169 (mmSYNC_MNGR_W_S_SYNC_MNGR_OBJS_MON_PAY_ADDRH_0 + mon_id * 4) -
8170 monitor_base;
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03008171
8172 size += gaudi_add_mon_msg_short(buf + size, (u32) (fence_addr >> 32),
8173 msg_addr_offset);
8174
8175 /*
8176 * Third monitor config packet: the payload, i.e. what to write when the
8177 * sync triggers
8178 */
Ofir Bitton2992c1d2020-09-10 09:40:35 +03008179 msg_addr_offset =
8180 (mmSYNC_MNGR_W_S_SYNC_MNGR_OBJS_MON_PAY_DATA_0 + mon_id * 4) -
8181 monitor_base;
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03008182
8183 size += gaudi_add_mon_msg_short(buf + size, 1, msg_addr_offset);
8184
Ofir Bitton2992c1d2020-09-10 09:40:35 +03008185 return size;
8186}
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03008187
Oded Gabbay3c681572020-11-02 21:10:39 +02008188static u32 gaudi_gen_wait_cb(struct hl_device *hdev,
8189 struct hl_gen_wait_properties *prop)
Ofir Bitton2992c1d2020-09-10 09:40:35 +03008190{
8191 struct hl_cb *cb = (struct hl_cb *) prop->data;
8192 void *buf = cb->kernel_address;
8193 u64 fence_addr = 0;
8194 u32 size = prop->size;
8195
8196 if (gaudi_get_fence_addr(hdev, prop->q_idx, &fence_addr)) {
8197 dev_crit(hdev->dev, "wrong queue id %d for wait packet\n",
8198 prop->q_idx);
8199 return 0;
8200 }
8201
8202 size += gaudi_add_mon_pkts(buf + size, prop->mon_id, fence_addr);
8203 size += gaudi_add_arm_monitor_pkt(hdev, buf + size, prop->sob_base,
8204 prop->sob_mask, prop->sob_val, prop->mon_id);
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03008205 size += gaudi_add_fence_pkt(buf + size);
Ofir Bitton2992c1d2020-09-10 09:40:35 +03008206
8207 return size;
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03008208}
8209
8210static void gaudi_reset_sob(struct hl_device *hdev, void *data)
8211{
8212 struct hl_hw_sob *hw_sob = (struct hl_hw_sob *) data;
8213
8214 dev_dbg(hdev->dev, "reset SOB, q_idx: %d, sob_id: %d\n", hw_sob->q_idx,
8215 hw_sob->sob_id);
8216
8217 WREG32(mmSYNC_MNGR_W_S_SYNC_MNGR_OBJS_SOB_OBJ_0 + hw_sob->sob_id * 4,
8218 0);
8219
8220 kref_init(&hw_sob->kref);
8221}
8222
8223static void gaudi_set_dma_mask_from_fw(struct hl_device *hdev)
8224{
8225 if (RREG32(mmPSOC_GLOBAL_CONF_NON_RST_FLOPS_0) ==
8226 HL_POWER9_HOST_MAGIC) {
8227 hdev->power9_64bit_dma_enable = 1;
8228 hdev->dma_mask = 64;
8229 } else {
8230 hdev->power9_64bit_dma_enable = 0;
8231 hdev->dma_mask = 48;
8232 }
8233}
8234
8235static u64 gaudi_get_device_time(struct hl_device *hdev)
8236{
8237 u64 device_time = ((u64) RREG32(mmPSOC_TIMESTAMP_CNTCVU)) << 32;
8238
8239 return device_time | RREG32(mmPSOC_TIMESTAMP_CNTCVL);
8240}
8241
8242static const struct hl_asic_funcs gaudi_funcs = {
8243 .early_init = gaudi_early_init,
8244 .early_fini = gaudi_early_fini,
8245 .late_init = gaudi_late_init,
8246 .late_fini = gaudi_late_fini,
8247 .sw_init = gaudi_sw_init,
8248 .sw_fini = gaudi_sw_fini,
8249 .hw_init = gaudi_hw_init,
8250 .hw_fini = gaudi_hw_fini,
8251 .halt_engines = gaudi_halt_engines,
8252 .suspend = gaudi_suspend,
8253 .resume = gaudi_resume,
8254 .cb_mmap = gaudi_cb_mmap,
8255 .ring_doorbell = gaudi_ring_doorbell,
8256 .pqe_write = gaudi_pqe_write,
8257 .asic_dma_alloc_coherent = gaudi_dma_alloc_coherent,
8258 .asic_dma_free_coherent = gaudi_dma_free_coherent,
farah kassabri03df1362020-05-06 11:17:38 +03008259 .scrub_device_mem = gaudi_scrub_device_mem,
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03008260 .get_int_queue_base = gaudi_get_int_queue_base,
8261 .test_queues = gaudi_test_queues,
8262 .asic_dma_pool_zalloc = gaudi_dma_pool_zalloc,
8263 .asic_dma_pool_free = gaudi_dma_pool_free,
8264 .cpu_accessible_dma_pool_alloc = gaudi_cpu_accessible_dma_pool_alloc,
8265 .cpu_accessible_dma_pool_free = gaudi_cpu_accessible_dma_pool_free,
8266 .hl_dma_unmap_sg = gaudi_dma_unmap_sg,
8267 .cs_parser = gaudi_cs_parser,
8268 .asic_dma_map_sg = gaudi_dma_map_sg,
8269 .get_dma_desc_list_size = gaudi_get_dma_desc_list_size,
8270 .add_end_of_cb_packets = gaudi_add_end_of_cb_packets,
8271 .update_eq_ci = gaudi_update_eq_ci,
8272 .context_switch = gaudi_context_switch,
8273 .restore_phase_topology = gaudi_restore_phase_topology,
8274 .debugfs_read32 = gaudi_debugfs_read32,
8275 .debugfs_write32 = gaudi_debugfs_write32,
8276 .debugfs_read64 = gaudi_debugfs_read64,
8277 .debugfs_write64 = gaudi_debugfs_write64,
Oded Gabbaybcaf4152020-05-11 10:41:37 +03008278 .add_device_attr = gaudi_add_device_attr,
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03008279 .handle_eqe = gaudi_handle_eqe,
Oded Gabbaybcaf4152020-05-11 10:41:37 +03008280 .set_pll_profile = gaudi_set_pll_profile,
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03008281 .get_events_stat = gaudi_get_events_stat,
8282 .read_pte = gaudi_read_pte,
8283 .write_pte = gaudi_write_pte,
8284 .mmu_invalidate_cache = gaudi_mmu_invalidate_cache,
8285 .mmu_invalidate_cache_range = gaudi_mmu_invalidate_cache_range,
8286 .send_heartbeat = gaudi_send_heartbeat,
Oded Gabbaye38bfd32020-07-03 20:46:12 +03008287 .set_clock_gating = gaudi_set_clock_gating,
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03008288 .disable_clock_gating = gaudi_disable_clock_gating,
Omer Shpigelman79fc7a92020-05-11 10:46:29 +03008289 .debug_coresight = gaudi_debug_coresight,
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03008290 .is_device_idle = gaudi_is_device_idle,
8291 .soft_reset_late_init = gaudi_soft_reset_late_init,
8292 .hw_queues_lock = gaudi_hw_queues_lock,
8293 .hw_queues_unlock = gaudi_hw_queues_unlock,
8294 .get_pci_id = gaudi_get_pci_id,
8295 .get_eeprom_data = gaudi_get_eeprom_data,
8296 .send_cpu_message = gaudi_send_cpu_message,
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03008297 .pci_bars_map = gaudi_pci_bars_map,
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03008298 .init_iatu = gaudi_init_iatu,
8299 .rreg = hl_rreg,
8300 .wreg = hl_wreg,
Omer Shpigelman79fc7a92020-05-11 10:46:29 +03008301 .halt_coresight = gaudi_halt_coresight,
Ofir Bittona04b7cd2020-07-13 13:36:55 +03008302 .ctx_init = gaudi_ctx_init,
Ofir Bitton5de406c2020-09-10 10:56:26 +03008303 .ctx_fini = gaudi_ctx_fini,
Oded Gabbaybcaf4152020-05-11 10:41:37 +03008304 .get_clk_rate = gaudi_get_clk_rate,
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03008305 .get_queue_id_for_cq = gaudi_get_queue_id_for_cq,
8306 .read_device_fw_version = gaudi_read_device_fw_version,
8307 .load_firmware_to_device = gaudi_load_firmware_to_device,
8308 .load_boot_fit_to_device = gaudi_load_boot_fit_to_device,
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03008309 .get_signal_cb_size = gaudi_get_signal_cb_size,
8310 .get_wait_cb_size = gaudi_get_wait_cb_size,
8311 .gen_signal_cb = gaudi_gen_signal_cb,
8312 .gen_wait_cb = gaudi_gen_wait_cb,
8313 .reset_sob = gaudi_reset_sob,
Ofir Bitton5fe1c172020-09-10 10:10:55 +03008314 .reset_sob_group = gaudi_reset_sob_group,
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03008315 .set_dma_mask_from_fw = gaudi_set_dma_mask_from_fw,
Ofir Bitton5fe1c172020-09-10 10:10:55 +03008316 .get_device_time = gaudi_get_device_time,
8317 .collective_wait_init_cs = gaudi_collective_wait_init_cs,
8318 .collective_wait_create_jobs = gaudi_collective_wait_create_jobs
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03008319};
8320
8321/**
8322 * gaudi_set_asic_funcs - set GAUDI function pointers
8323 *
Lee Jonesf7d227c2020-07-01 09:58:42 +01008324 * @hdev: pointer to hl_device structure
Oded Gabbayac0ae6a2020-05-11 10:29:27 +03008325 *
8326 */
8327void gaudi_set_asic_funcs(struct hl_device *hdev)
8328{
8329 hdev->asic_funcs = &gaudi_funcs;
8330}