1e65e175bSOded Gabbay // SPDX-License-Identifier: GPL-2.0
2e65e175bSOded Gabbay
3e65e175bSOded Gabbay /*
4e65e175bSOded Gabbay * Copyright 2016-2022 HabanaLabs, Ltd.
5e65e175bSOded Gabbay * All Rights Reserved.
6e65e175bSOded Gabbay */
7e65e175bSOded Gabbay
8e65e175bSOded Gabbay #include "gaudiP.h"
9e65e175bSOded Gabbay #include "../include/hw_ip/mmu/mmu_general.h"
10e65e175bSOded Gabbay #include "../include/hw_ip/mmu/mmu_v1_1.h"
11e65e175bSOded Gabbay #include "../include/gaudi/gaudi_masks.h"
12e65e175bSOded Gabbay #include "../include/gaudi/gaudi_fw_if.h"
13e65e175bSOded Gabbay #include "../include/gaudi/gaudi_reg_map.h"
14e65e175bSOded Gabbay #include "../include/gaudi/gaudi_async_ids_map_extended.h"
15e65e175bSOded Gabbay
16e65e175bSOded Gabbay #include <linux/module.h>
17e65e175bSOded Gabbay #include <linux/pci.h>
18e65e175bSOded Gabbay #include <linux/firmware.h>
19e65e175bSOded Gabbay #include <linux/hwmon.h>
20e65e175bSOded Gabbay #include <linux/iommu.h>
21e65e175bSOded Gabbay #include <linux/seq_file.h>
22e65e175bSOded Gabbay
23e65e175bSOded Gabbay /*
24e65e175bSOded Gabbay * Gaudi security scheme:
25e65e175bSOded Gabbay *
26e65e175bSOded Gabbay * 1. Host is protected by:
27e65e175bSOded Gabbay * - Range registers
28e65e175bSOded Gabbay * - MMU
29e65e175bSOded Gabbay *
30e65e175bSOded Gabbay * 2. DDR is protected by:
31e65e175bSOded Gabbay * - Range registers (protect the first 512MB)
32e65e175bSOded Gabbay *
33e65e175bSOded Gabbay * 3. Configuration is protected by:
34e65e175bSOded Gabbay * - Range registers
35e65e175bSOded Gabbay * - Protection bits
36e65e175bSOded Gabbay *
37e65e175bSOded Gabbay * MMU is always enabled.
38e65e175bSOded Gabbay *
39e65e175bSOded Gabbay * QMAN DMA channels 0,1 (PCI DMAN):
40e65e175bSOded Gabbay * - DMA is not secured.
41e65e175bSOded Gabbay * - PQ and CQ are secured.
42e65e175bSOded Gabbay * - CP is secured: The driver needs to parse CB but WREG should be allowed
43e65e175bSOded Gabbay * because of TDMA (tensor DMA). Hence, WREG is always not
44e65e175bSOded Gabbay * secured.
45e65e175bSOded Gabbay *
46e65e175bSOded Gabbay * When the driver needs to use DMA it will check that Gaudi is idle, set DMA
47e65e175bSOded Gabbay * channel 0 to be secured, execute the DMA and change it back to not secured.
48e65e175bSOded Gabbay * Currently, the driver doesn't use the DMA while there are compute jobs
49e65e175bSOded Gabbay * running.
50e65e175bSOded Gabbay *
51e65e175bSOded Gabbay * The current use cases for the driver to use the DMA are:
52e65e175bSOded Gabbay * - Clear SRAM on context switch (happens on context switch when device is
53e65e175bSOded Gabbay * idle)
54e65e175bSOded Gabbay * - MMU page tables area clear (happens on init)
55e65e175bSOded Gabbay *
56e65e175bSOded Gabbay * QMAN DMA 2-7, TPC, MME, NIC:
57e65e175bSOded Gabbay * PQ is secured and is located on the Host (HBM CON TPC3 bug)
58e65e175bSOded Gabbay * CQ, CP and the engine are not secured
59e65e175bSOded Gabbay *
60e65e175bSOded Gabbay */
61e65e175bSOded Gabbay
62e65e175bSOded Gabbay #define GAUDI_BOOT_FIT_FILE "habanalabs/gaudi/gaudi-boot-fit.itb"
63e65e175bSOded Gabbay #define GAUDI_LINUX_FW_FILE "habanalabs/gaudi/gaudi-fit.itb"
64e65e175bSOded Gabbay #define GAUDI_TPC_FW_FILE "habanalabs/gaudi/gaudi_tpc.bin"
65e65e175bSOded Gabbay
66e65e175bSOded Gabbay #define GAUDI_DMA_POOL_BLK_SIZE 0x100 /* 256 bytes */
67e65e175bSOded Gabbay
68e65e175bSOded Gabbay #define GAUDI_RESET_TIMEOUT_MSEC 2000 /* 2000ms */
69e65e175bSOded Gabbay #define GAUDI_RESET_WAIT_MSEC 1 /* 1ms */
70e65e175bSOded Gabbay #define GAUDI_CPU_RESET_WAIT_MSEC 200 /* 200ms */
71e65e175bSOded Gabbay #define GAUDI_TEST_QUEUE_WAIT_USEC 100000 /* 100ms */
72e65e175bSOded Gabbay
73e65e175bSOded Gabbay #define GAUDI_PLDM_RESET_WAIT_MSEC 1000 /* 1s */
74e65e175bSOded Gabbay #define GAUDI_PLDM_HRESET_TIMEOUT_MSEC 20000 /* 20s */
75e65e175bSOded Gabbay #define GAUDI_PLDM_TEST_QUEUE_WAIT_USEC 1000000 /* 1s */
76e65e175bSOded Gabbay #define GAUDI_PLDM_MMU_TIMEOUT_USEC (MMU_CONFIG_TIMEOUT_USEC * 100)
77e65e175bSOded Gabbay #define GAUDI_PLDM_QMAN0_TIMEOUT_USEC (HL_DEVICE_TIMEOUT_USEC * 30)
78e65e175bSOded Gabbay #define GAUDI_PLDM_TPC_KERNEL_WAIT_USEC (HL_DEVICE_TIMEOUT_USEC * 30)
79e65e175bSOded Gabbay #define GAUDI_BOOT_FIT_REQ_TIMEOUT_USEC 4000000 /* 4s */
80e65e175bSOded Gabbay #define GAUDI_MSG_TO_CPU_TIMEOUT_USEC 4000000 /* 4s */
81e65e175bSOded Gabbay #define GAUDI_WAIT_FOR_BL_TIMEOUT_USEC 15000000 /* 15s */
82e65e175bSOded Gabbay
83e65e175bSOded Gabbay #define GAUDI_QMAN0_FENCE_VAL 0x72E91AB9
84e65e175bSOded Gabbay
85e65e175bSOded Gabbay #define GAUDI_MAX_STRING_LEN 20
86e65e175bSOded Gabbay
87e65e175bSOded Gabbay #define GAUDI_CB_POOL_CB_CNT 512
88e65e175bSOded Gabbay #define GAUDI_CB_POOL_CB_SIZE 0x20000 /* 128KB */
89e65e175bSOded Gabbay
90e65e175bSOded Gabbay #define GAUDI_ALLOC_CPU_MEM_RETRY_CNT 3
91e65e175bSOded Gabbay
92e65e175bSOded Gabbay #define GAUDI_NUM_OF_TPC_INTR_CAUSE 20
93e65e175bSOded Gabbay
94e65e175bSOded Gabbay #define GAUDI_NUM_OF_QM_ERR_CAUSE 16
95e65e175bSOded Gabbay
96e65e175bSOded Gabbay #define GAUDI_NUM_OF_QM_ARB_ERR_CAUSE 3
97e65e175bSOded Gabbay
98e65e175bSOded Gabbay #define GAUDI_ARB_WDT_TIMEOUT 0xEE6b27FF /* 8 seconds */
99e65e175bSOded Gabbay
100e65e175bSOded Gabbay #define HBM_SCRUBBING_TIMEOUT_US 1000000 /* 1s */
101e65e175bSOded Gabbay
102e65e175bSOded Gabbay #define BIN_REG_STRING_SIZE sizeof("0b10101010101010101010101010101010")
103e65e175bSOded Gabbay
104e65e175bSOded Gabbay #define MONITOR_SOB_STRING_SIZE 256
105e65e175bSOded Gabbay
106e65e175bSOded Gabbay static u32 gaudi_stream_master[GAUDI_STREAM_MASTER_ARR_SIZE] = {
107e65e175bSOded Gabbay GAUDI_QUEUE_ID_DMA_0_0,
108e65e175bSOded Gabbay GAUDI_QUEUE_ID_DMA_0_1,
109e65e175bSOded Gabbay GAUDI_QUEUE_ID_DMA_0_2,
110e65e175bSOded Gabbay GAUDI_QUEUE_ID_DMA_0_3,
111e65e175bSOded Gabbay GAUDI_QUEUE_ID_DMA_1_0,
112e65e175bSOded Gabbay GAUDI_QUEUE_ID_DMA_1_1,
113e65e175bSOded Gabbay GAUDI_QUEUE_ID_DMA_1_2,
114e65e175bSOded Gabbay GAUDI_QUEUE_ID_DMA_1_3
115e65e175bSOded Gabbay };
116e65e175bSOded Gabbay
117e65e175bSOded Gabbay static const u8 gaudi_dma_assignment[GAUDI_DMA_MAX] = {
118e65e175bSOded Gabbay [GAUDI_PCI_DMA_1] = GAUDI_ENGINE_ID_DMA_0,
119e65e175bSOded Gabbay [GAUDI_PCI_DMA_2] = GAUDI_ENGINE_ID_DMA_1,
120e65e175bSOded Gabbay [GAUDI_HBM_DMA_1] = GAUDI_ENGINE_ID_DMA_2,
121e65e175bSOded Gabbay [GAUDI_HBM_DMA_2] = GAUDI_ENGINE_ID_DMA_3,
122e65e175bSOded Gabbay [GAUDI_HBM_DMA_3] = GAUDI_ENGINE_ID_DMA_4,
123e65e175bSOded Gabbay [GAUDI_HBM_DMA_4] = GAUDI_ENGINE_ID_DMA_5,
124e65e175bSOded Gabbay [GAUDI_HBM_DMA_5] = GAUDI_ENGINE_ID_DMA_6,
125e65e175bSOded Gabbay [GAUDI_HBM_DMA_6] = GAUDI_ENGINE_ID_DMA_7
126e65e175bSOded Gabbay };
127e65e175bSOded Gabbay
128e65e175bSOded Gabbay static const u8 gaudi_cq_assignment[NUMBER_OF_CMPLT_QUEUES] = {
129e65e175bSOded Gabbay [0] = GAUDI_QUEUE_ID_DMA_0_0,
130e65e175bSOded Gabbay [1] = GAUDI_QUEUE_ID_DMA_0_1,
131e65e175bSOded Gabbay [2] = GAUDI_QUEUE_ID_DMA_0_2,
132e65e175bSOded Gabbay [3] = GAUDI_QUEUE_ID_DMA_0_3,
133e65e175bSOded Gabbay [4] = GAUDI_QUEUE_ID_DMA_1_0,
134e65e175bSOded Gabbay [5] = GAUDI_QUEUE_ID_DMA_1_1,
135e65e175bSOded Gabbay [6] = GAUDI_QUEUE_ID_DMA_1_2,
136e65e175bSOded Gabbay [7] = GAUDI_QUEUE_ID_DMA_1_3,
137e65e175bSOded Gabbay };
138e65e175bSOded Gabbay
139e65e175bSOded Gabbay static const u16 gaudi_packet_sizes[MAX_PACKET_ID] = {
140e65e175bSOded Gabbay [PACKET_WREG_32] = sizeof(struct packet_wreg32),
141e65e175bSOded Gabbay [PACKET_WREG_BULK] = sizeof(struct packet_wreg_bulk),
142e65e175bSOded Gabbay [PACKET_MSG_LONG] = sizeof(struct packet_msg_long),
143e65e175bSOded Gabbay [PACKET_MSG_SHORT] = sizeof(struct packet_msg_short),
144e65e175bSOded Gabbay [PACKET_CP_DMA] = sizeof(struct packet_cp_dma),
145e65e175bSOded Gabbay [PACKET_REPEAT] = sizeof(struct packet_repeat),
146e65e175bSOded Gabbay [PACKET_MSG_PROT] = sizeof(struct packet_msg_prot),
147e65e175bSOded Gabbay [PACKET_FENCE] = sizeof(struct packet_fence),
148e65e175bSOded Gabbay [PACKET_LIN_DMA] = sizeof(struct packet_lin_dma),
149e65e175bSOded Gabbay [PACKET_NOP] = sizeof(struct packet_nop),
150e65e175bSOded Gabbay [PACKET_STOP] = sizeof(struct packet_stop),
151e65e175bSOded Gabbay [PACKET_ARB_POINT] = sizeof(struct packet_arb_point),
152e65e175bSOded Gabbay [PACKET_WAIT] = sizeof(struct packet_wait),
153e65e175bSOded Gabbay [PACKET_LOAD_AND_EXE] = sizeof(struct packet_load_and_exe)
154e65e175bSOded Gabbay };
155e65e175bSOded Gabbay
validate_packet_id(enum packet_id id)156e65e175bSOded Gabbay static inline bool validate_packet_id(enum packet_id id)
157e65e175bSOded Gabbay {
158e65e175bSOded Gabbay switch (id) {
159e65e175bSOded Gabbay case PACKET_WREG_32:
160e65e175bSOded Gabbay case PACKET_WREG_BULK:
161e65e175bSOded Gabbay case PACKET_MSG_LONG:
162e65e175bSOded Gabbay case PACKET_MSG_SHORT:
163e65e175bSOded Gabbay case PACKET_CP_DMA:
164e65e175bSOded Gabbay case PACKET_REPEAT:
165e65e175bSOded Gabbay case PACKET_MSG_PROT:
166e65e175bSOded Gabbay case PACKET_FENCE:
167e65e175bSOded Gabbay case PACKET_LIN_DMA:
168e65e175bSOded Gabbay case PACKET_NOP:
169e65e175bSOded Gabbay case PACKET_STOP:
170e65e175bSOded Gabbay case PACKET_ARB_POINT:
171e65e175bSOded Gabbay case PACKET_WAIT:
172e65e175bSOded Gabbay case PACKET_LOAD_AND_EXE:
173e65e175bSOded Gabbay return true;
174e65e175bSOded Gabbay default:
175e65e175bSOded Gabbay return false;
176e65e175bSOded Gabbay }
177e65e175bSOded Gabbay }
178e65e175bSOded Gabbay
179e65e175bSOded Gabbay static const char * const
180e65e175bSOded Gabbay gaudi_tpc_interrupts_cause[GAUDI_NUM_OF_TPC_INTR_CAUSE] = {
181e65e175bSOded Gabbay "tpc_address_exceed_slm",
182e65e175bSOded Gabbay "tpc_div_by_0",
183e65e175bSOded Gabbay "tpc_spu_mac_overflow",
184e65e175bSOded Gabbay "tpc_spu_addsub_overflow",
185e65e175bSOded Gabbay "tpc_spu_abs_overflow",
186e65e175bSOded Gabbay "tpc_spu_fp_dst_nan_inf",
187e65e175bSOded Gabbay "tpc_spu_fp_dst_denorm",
188e65e175bSOded Gabbay "tpc_vpu_mac_overflow",
189e65e175bSOded Gabbay "tpc_vpu_addsub_overflow",
190e65e175bSOded Gabbay "tpc_vpu_abs_overflow",
191e65e175bSOded Gabbay "tpc_vpu_fp_dst_nan_inf",
192e65e175bSOded Gabbay "tpc_vpu_fp_dst_denorm",
193e65e175bSOded Gabbay "tpc_assertions",
194e65e175bSOded Gabbay "tpc_illegal_instruction",
195e65e175bSOded Gabbay "tpc_pc_wrap_around",
196e65e175bSOded Gabbay "tpc_qm_sw_err",
197e65e175bSOded Gabbay "tpc_hbw_rresp_err",
198e65e175bSOded Gabbay "tpc_hbw_bresp_err",
199e65e175bSOded Gabbay "tpc_lbw_rresp_err",
200e65e175bSOded Gabbay "tpc_lbw_bresp_err"
201e65e175bSOded Gabbay };
202e65e175bSOded Gabbay
203e65e175bSOded Gabbay static const char * const
204e65e175bSOded Gabbay gaudi_qman_error_cause[GAUDI_NUM_OF_QM_ERR_CAUSE] = {
205e65e175bSOded Gabbay "PQ AXI HBW error",
206e65e175bSOded Gabbay "CQ AXI HBW error",
207e65e175bSOded Gabbay "CP AXI HBW error",
208e65e175bSOded Gabbay "CP error due to undefined OPCODE",
209e65e175bSOded Gabbay "CP encountered STOP OPCODE",
210e65e175bSOded Gabbay "CP AXI LBW error",
211e65e175bSOded Gabbay "CP WRREG32 or WRBULK returned error",
212e65e175bSOded Gabbay "N/A",
213e65e175bSOded Gabbay "FENCE 0 inc over max value and clipped",
214e65e175bSOded Gabbay "FENCE 1 inc over max value and clipped",
215e65e175bSOded Gabbay "FENCE 2 inc over max value and clipped",
216e65e175bSOded Gabbay "FENCE 3 inc over max value and clipped",
217e65e175bSOded Gabbay "FENCE 0 dec under min value and clipped",
218e65e175bSOded Gabbay "FENCE 1 dec under min value and clipped",
219e65e175bSOded Gabbay "FENCE 2 dec under min value and clipped",
220e65e175bSOded Gabbay "FENCE 3 dec under min value and clipped"
221e65e175bSOded Gabbay };
222e65e175bSOded Gabbay
223e65e175bSOded Gabbay static const char * const
224e65e175bSOded Gabbay gaudi_qman_arb_error_cause[GAUDI_NUM_OF_QM_ARB_ERR_CAUSE] = {
225e65e175bSOded Gabbay "Choice push while full error",
226e65e175bSOded Gabbay "Choice Q watchdog error",
227e65e175bSOded Gabbay "MSG AXI LBW returned with error"
228e65e175bSOded Gabbay };
229e65e175bSOded Gabbay
230e65e175bSOded Gabbay static enum hl_queue_type gaudi_queue_type[GAUDI_QUEUE_ID_SIZE] = {
231e65e175bSOded Gabbay QUEUE_TYPE_EXT, /* GAUDI_QUEUE_ID_DMA_0_0 */
232e65e175bSOded Gabbay QUEUE_TYPE_EXT, /* GAUDI_QUEUE_ID_DMA_0_1 */
233e65e175bSOded Gabbay QUEUE_TYPE_EXT, /* GAUDI_QUEUE_ID_DMA_0_2 */
234e65e175bSOded Gabbay QUEUE_TYPE_EXT, /* GAUDI_QUEUE_ID_DMA_0_3 */
235e65e175bSOded Gabbay QUEUE_TYPE_EXT, /* GAUDI_QUEUE_ID_DMA_1_0 */
236e65e175bSOded Gabbay QUEUE_TYPE_EXT, /* GAUDI_QUEUE_ID_DMA_1_1 */
237e65e175bSOded Gabbay QUEUE_TYPE_EXT, /* GAUDI_QUEUE_ID_DMA_1_2 */
238e65e175bSOded Gabbay QUEUE_TYPE_EXT, /* GAUDI_QUEUE_ID_DMA_1_3 */
239e65e175bSOded Gabbay QUEUE_TYPE_CPU, /* GAUDI_QUEUE_ID_CPU_PQ */
240e65e175bSOded Gabbay QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_DMA_2_0 */
241e65e175bSOded Gabbay QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_DMA_2_1 */
242e65e175bSOded Gabbay QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_DMA_2_2 */
243e65e175bSOded Gabbay QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_DMA_2_3 */
244e65e175bSOded Gabbay QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_DMA_3_0 */
245e65e175bSOded Gabbay QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_DMA_3_1 */
246e65e175bSOded Gabbay QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_DMA_3_2 */
247e65e175bSOded Gabbay QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_DMA_3_3 */
248e65e175bSOded Gabbay QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_DMA_4_0 */
249e65e175bSOded Gabbay QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_DMA_4_1 */
250e65e175bSOded Gabbay QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_DMA_4_2 */
251e65e175bSOded Gabbay QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_DMA_4_3 */
252e65e175bSOded Gabbay QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_DMA_5_0 */
253e65e175bSOded Gabbay QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_DMA_5_1 */
254e65e175bSOded Gabbay QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_DMA_5_2 */
255e65e175bSOded Gabbay QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_DMA_5_3 */
256e65e175bSOded Gabbay QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_DMA_6_0 */
257e65e175bSOded Gabbay QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_DMA_6_1 */
258e65e175bSOded Gabbay QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_DMA_6_2 */
259e65e175bSOded Gabbay QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_DMA_6_3 */
260e65e175bSOded Gabbay QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_DMA_7_0 */
261e65e175bSOded Gabbay QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_DMA_7_1 */
262e65e175bSOded Gabbay QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_DMA_7_2 */
263e65e175bSOded Gabbay QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_DMA_7_3 */
264e65e175bSOded Gabbay QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_MME_0_0 */
265e65e175bSOded Gabbay QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_MME_0_1 */
266e65e175bSOded Gabbay QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_MME_0_2 */
267e65e175bSOded Gabbay QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_MME_0_3 */
268e65e175bSOded Gabbay QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_MME_1_0 */
269e65e175bSOded Gabbay QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_MME_1_1 */
270e65e175bSOded Gabbay QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_MME_1_2 */
271e65e175bSOded Gabbay QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_MME_1_3 */
272e65e175bSOded Gabbay QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_TPC_0_0 */
273e65e175bSOded Gabbay QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_TPC_0_1 */
274e65e175bSOded Gabbay QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_TPC_0_2 */
275e65e175bSOded Gabbay QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_TPC_0_3 */
276e65e175bSOded Gabbay QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_TPC_1_0 */
277e65e175bSOded Gabbay QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_TPC_1_1 */
278e65e175bSOded Gabbay QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_TPC_1_2 */
279e65e175bSOded Gabbay QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_TPC_1_3 */
280e65e175bSOded Gabbay QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_TPC_2_0 */
281e65e175bSOded Gabbay QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_TPC_2_1 */
282e65e175bSOded Gabbay QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_TPC_2_2 */
283e65e175bSOded Gabbay QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_TPC_2_3 */
284e65e175bSOded Gabbay QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_TPC_3_0 */
285e65e175bSOded Gabbay QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_TPC_3_1 */
286e65e175bSOded Gabbay QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_TPC_3_2 */
287e65e175bSOded Gabbay QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_TPC_3_3 */
288e65e175bSOded Gabbay QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_TPC_4_0 */
289e65e175bSOded Gabbay QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_TPC_4_1 */
290e65e175bSOded Gabbay QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_TPC_4_2 */
291e65e175bSOded Gabbay QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_TPC_4_3 */
292e65e175bSOded Gabbay QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_TPC_5_0 */
293e65e175bSOded Gabbay QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_TPC_5_1 */
294e65e175bSOded Gabbay QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_TPC_5_2 */
295e65e175bSOded Gabbay QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_TPC_5_3 */
296e65e175bSOded Gabbay QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_TPC_6_0 */
297e65e175bSOded Gabbay QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_TPC_6_1 */
298e65e175bSOded Gabbay QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_TPC_6_2 */
299e65e175bSOded Gabbay QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_TPC_6_3 */
300e65e175bSOded Gabbay QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_TPC_7_0 */
301e65e175bSOded Gabbay QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_TPC_7_1 */
302e65e175bSOded Gabbay QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_TPC_7_2 */
303e65e175bSOded Gabbay QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_TPC_7_3 */
304e65e175bSOded Gabbay QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_NIC_0_0 */
305e65e175bSOded Gabbay QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_NIC_0_1 */
306e65e175bSOded Gabbay QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_NIC_0_2 */
307e65e175bSOded Gabbay QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_NIC_0_3 */
308e65e175bSOded Gabbay QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_NIC_1_0 */
309e65e175bSOded Gabbay QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_NIC_1_1 */
310e65e175bSOded Gabbay QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_NIC_1_2 */
311e65e175bSOded Gabbay QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_NIC_1_3 */
312e65e175bSOded Gabbay QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_NIC_2_0 */
313e65e175bSOded Gabbay QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_NIC_2_1 */
314e65e175bSOded Gabbay QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_NIC_2_2 */
315e65e175bSOded Gabbay QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_NIC_2_3 */
316e65e175bSOded Gabbay QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_NIC_3_0 */
317e65e175bSOded Gabbay QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_NIC_3_1 */
318e65e175bSOded Gabbay QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_NIC_3_2 */
319e65e175bSOded Gabbay QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_NIC_3_3 */
320e65e175bSOded Gabbay QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_NIC_4_0 */
321e65e175bSOded Gabbay QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_NIC_4_1 */
322e65e175bSOded Gabbay QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_NIC_4_2 */
323e65e175bSOded Gabbay QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_NIC_4_3 */
324e65e175bSOded Gabbay QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_NIC_5_0 */
325e65e175bSOded Gabbay QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_NIC_5_1 */
326e65e175bSOded Gabbay QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_NIC_5_2 */
327e65e175bSOded Gabbay QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_NIC_5_3 */
328e65e175bSOded Gabbay QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_NIC_6_0 */
329e65e175bSOded Gabbay QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_NIC_6_1 */
330e65e175bSOded Gabbay QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_NIC_6_2 */
331e65e175bSOded Gabbay QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_NIC_6_3 */
332e65e175bSOded Gabbay QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_NIC_7_0 */
333e65e175bSOded Gabbay QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_NIC_7_1 */
334e65e175bSOded Gabbay QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_NIC_7_2 */
335e65e175bSOded Gabbay QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_NIC_7_3 */
336e65e175bSOded Gabbay QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_NIC_8_0 */
337e65e175bSOded Gabbay QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_NIC_8_1 */
338e65e175bSOded Gabbay QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_NIC_8_2 */
339e65e175bSOded Gabbay QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_NIC_8_3 */
340e65e175bSOded Gabbay QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_NIC_9_0 */
341e65e175bSOded Gabbay QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_NIC_9_1 */
342e65e175bSOded Gabbay QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_NIC_9_2 */
343e65e175bSOded Gabbay QUEUE_TYPE_INT, /* GAUDI_QUEUE_ID_NIC_9_3 */
344e65e175bSOded Gabbay };
345e65e175bSOded Gabbay
346e65e175bSOded Gabbay static struct hl_hw_obj_name_entry gaudi_so_id_to_str[] = {
347e65e175bSOded Gabbay { .id = 0, .name = "SYNC_OBJ_DMA_DOWN_FEEDBACK" },
348e65e175bSOded Gabbay { .id = 1, .name = "SYNC_OBJ_DMA_UP_FEEDBACK" },
349e65e175bSOded Gabbay { .id = 2, .name = "SYNC_OBJ_DMA_STATIC_DRAM_SRAM_FEEDBACK" },
350e65e175bSOded Gabbay { .id = 3, .name = "SYNC_OBJ_DMA_SRAM_DRAM_FEEDBACK" },
351e65e175bSOded Gabbay { .id = 4, .name = "SYNC_OBJ_FIRST_COMPUTE_FINISH" },
352e65e175bSOded Gabbay { .id = 5, .name = "SYNC_OBJ_HOST_DRAM_DONE" },
353e65e175bSOded Gabbay { .id = 6, .name = "SYNC_OBJ_DBG_CTR_DEPRECATED" },
354e65e175bSOded Gabbay { .id = 7, .name = "SYNC_OBJ_DMA_ACTIVATIONS_DRAM_SRAM_FEEDBACK" },
355e65e175bSOded Gabbay { .id = 8, .name = "SYNC_OBJ_ENGINE_SEM_MME_0" },
356e65e175bSOded Gabbay { .id = 9, .name = "SYNC_OBJ_ENGINE_SEM_MME_1" },
357e65e175bSOded Gabbay { .id = 10, .name = "SYNC_OBJ_ENGINE_SEM_TPC_0" },
358e65e175bSOded Gabbay { .id = 11, .name = "SYNC_OBJ_ENGINE_SEM_TPC_1" },
359e65e175bSOded Gabbay { .id = 12, .name = "SYNC_OBJ_ENGINE_SEM_TPC_2" },
360e65e175bSOded Gabbay { .id = 13, .name = "SYNC_OBJ_ENGINE_SEM_TPC_3" },
361e65e175bSOded Gabbay { .id = 14, .name = "SYNC_OBJ_ENGINE_SEM_TPC_4" },
362e65e175bSOded Gabbay { .id = 15, .name = "SYNC_OBJ_ENGINE_SEM_TPC_5" },
363e65e175bSOded Gabbay { .id = 16, .name = "SYNC_OBJ_ENGINE_SEM_TPC_6" },
364e65e175bSOded Gabbay { .id = 17, .name = "SYNC_OBJ_ENGINE_SEM_TPC_7" },
365e65e175bSOded Gabbay { .id = 18, .name = "SYNC_OBJ_ENGINE_SEM_DMA_1" },
366e65e175bSOded Gabbay { .id = 19, .name = "SYNC_OBJ_ENGINE_SEM_DMA_2" },
367e65e175bSOded Gabbay { .id = 20, .name = "SYNC_OBJ_ENGINE_SEM_DMA_3" },
368e65e175bSOded Gabbay { .id = 21, .name = "SYNC_OBJ_ENGINE_SEM_DMA_4" },
369e65e175bSOded Gabbay { .id = 22, .name = "SYNC_OBJ_ENGINE_SEM_DMA_5" },
370e65e175bSOded Gabbay { .id = 23, .name = "SYNC_OBJ_ENGINE_SEM_DMA_6" },
371e65e175bSOded Gabbay { .id = 24, .name = "SYNC_OBJ_ENGINE_SEM_DMA_7" },
372e65e175bSOded Gabbay { .id = 25, .name = "SYNC_OBJ_DBG_CTR_0" },
373e65e175bSOded Gabbay { .id = 26, .name = "SYNC_OBJ_DBG_CTR_1" },
374e65e175bSOded Gabbay };
375e65e175bSOded Gabbay
376e65e175bSOded Gabbay static struct hl_hw_obj_name_entry gaudi_monitor_id_to_str[] = {
377e65e175bSOded Gabbay { .id = 200, .name = "MON_OBJ_DMA_DOWN_FEEDBACK_RESET" },
378e65e175bSOded Gabbay { .id = 201, .name = "MON_OBJ_DMA_UP_FEEDBACK_RESET" },
379e65e175bSOded Gabbay { .id = 203, .name = "MON_OBJ_DRAM_TO_SRAM_QUEUE_FENCE" },
380e65e175bSOded Gabbay { .id = 204, .name = "MON_OBJ_TPC_0_CLK_GATE" },
381e65e175bSOded Gabbay { .id = 205, .name = "MON_OBJ_TPC_1_CLK_GATE" },
382e65e175bSOded Gabbay { .id = 206, .name = "MON_OBJ_TPC_2_CLK_GATE" },
383e65e175bSOded Gabbay { .id = 207, .name = "MON_OBJ_TPC_3_CLK_GATE" },
384e65e175bSOded Gabbay { .id = 208, .name = "MON_OBJ_TPC_4_CLK_GATE" },
385e65e175bSOded Gabbay { .id = 209, .name = "MON_OBJ_TPC_5_CLK_GATE" },
386e65e175bSOded Gabbay { .id = 210, .name = "MON_OBJ_TPC_6_CLK_GATE" },
387e65e175bSOded Gabbay { .id = 211, .name = "MON_OBJ_TPC_7_CLK_GATE" },
388e65e175bSOded Gabbay };
389e65e175bSOded Gabbay
390e65e175bSOded Gabbay static s64 gaudi_state_dump_specs_props[] = {
391e65e175bSOded Gabbay [SP_SYNC_OBJ_BASE_ADDR] = mmSYNC_MNGR_E_N_SYNC_MNGR_OBJS_SOB_OBJ_0,
392e65e175bSOded Gabbay [SP_NEXT_SYNC_OBJ_ADDR] = NEXT_SYNC_OBJ_ADDR_INTERVAL,
393e65e175bSOded Gabbay [SP_SYNC_OBJ_AMOUNT] = NUM_OF_SOB_IN_BLOCK,
394e65e175bSOded Gabbay [SP_MON_OBJ_WR_ADDR_LOW] =
395e65e175bSOded Gabbay mmSYNC_MNGR_E_N_SYNC_MNGR_OBJS_MON_PAY_ADDRL_0,
396e65e175bSOded Gabbay [SP_MON_OBJ_WR_ADDR_HIGH] =
397e65e175bSOded Gabbay mmSYNC_MNGR_E_N_SYNC_MNGR_OBJS_MON_PAY_ADDRH_0,
398e65e175bSOded Gabbay [SP_MON_OBJ_WR_DATA] = mmSYNC_MNGR_E_N_SYNC_MNGR_OBJS_MON_PAY_DATA_0,
399e65e175bSOded Gabbay [SP_MON_OBJ_ARM_DATA] = mmSYNC_MNGR_E_N_SYNC_MNGR_OBJS_MON_ARM_0,
400e65e175bSOded Gabbay [SP_MON_OBJ_STATUS] = mmSYNC_MNGR_E_N_SYNC_MNGR_OBJS_MON_STATUS_0,
401e65e175bSOded Gabbay [SP_MONITORS_AMOUNT] = NUM_OF_MONITORS_IN_BLOCK,
402e65e175bSOded Gabbay [SP_TPC0_CMDQ] = mmTPC0_QM_GLBL_CFG0,
403e65e175bSOded Gabbay [SP_TPC0_CFG_SO] = mmTPC0_CFG_QM_SYNC_OBJECT_ADDR,
404e65e175bSOded Gabbay [SP_NEXT_TPC] = mmTPC1_QM_GLBL_CFG0 - mmTPC0_QM_GLBL_CFG0,
405e65e175bSOded Gabbay [SP_MME_CMDQ] = mmMME0_QM_GLBL_CFG0,
406e65e175bSOded Gabbay [SP_MME_CFG_SO] = mmMME0_CTRL_ARCH_DESC_SYNC_OBJECT_ADDR_LOW_LOCAL,
407e65e175bSOded Gabbay [SP_NEXT_MME] = mmMME2_QM_GLBL_CFG0 - mmMME0_QM_GLBL_CFG0,
408e65e175bSOded Gabbay [SP_DMA_CMDQ] = mmDMA0_QM_GLBL_CFG0,
409e65e175bSOded Gabbay [SP_DMA_CFG_SO] = mmDMA0_CORE_WR_COMP_ADDR_LO,
410e65e175bSOded Gabbay [SP_DMA_QUEUES_OFFSET] = mmDMA1_QM_GLBL_CFG0 - mmDMA0_QM_GLBL_CFG0,
411e65e175bSOded Gabbay [SP_NUM_OF_MME_ENGINES] = NUM_OF_MME_ENGINES,
412e65e175bSOded Gabbay [SP_SUB_MME_ENG_NUM] = NUM_OF_MME_SUB_ENGINES,
413e65e175bSOded Gabbay [SP_NUM_OF_DMA_ENGINES] = NUM_OF_DMA_ENGINES,
414e65e175bSOded Gabbay [SP_NUM_OF_TPC_ENGINES] = NUM_OF_TPC_ENGINES,
415e65e175bSOded Gabbay [SP_ENGINE_NUM_OF_QUEUES] = NUM_OF_QUEUES,
416e65e175bSOded Gabbay [SP_ENGINE_NUM_OF_STREAMS] = NUM_OF_STREAMS,
417e65e175bSOded Gabbay [SP_ENGINE_NUM_OF_FENCES] = NUM_OF_FENCES,
418e65e175bSOded Gabbay [SP_FENCE0_CNT_OFFSET] =
419e65e175bSOded Gabbay mmDMA0_QM_CP_FENCE0_CNT_0 - mmDMA0_QM_GLBL_CFG0,
420e65e175bSOded Gabbay [SP_FENCE0_RDATA_OFFSET] =
421e65e175bSOded Gabbay mmDMA0_QM_CP_FENCE0_RDATA_0 - mmDMA0_QM_GLBL_CFG0,
422e65e175bSOded Gabbay [SP_CP_STS_OFFSET] = mmDMA0_QM_CP_STS_0 - mmDMA0_QM_GLBL_CFG0,
423e65e175bSOded Gabbay [SP_NUM_CORES] = 1,
424e65e175bSOded Gabbay };
425e65e175bSOded Gabbay
426e65e175bSOded Gabbay static const int gaudi_queue_id_to_engine_id[] = {
427e65e175bSOded Gabbay [GAUDI_QUEUE_ID_DMA_0_0...GAUDI_QUEUE_ID_DMA_0_3] = GAUDI_ENGINE_ID_DMA_0,
428e65e175bSOded Gabbay [GAUDI_QUEUE_ID_DMA_1_0...GAUDI_QUEUE_ID_DMA_1_3] = GAUDI_ENGINE_ID_DMA_1,
429e65e175bSOded Gabbay [GAUDI_QUEUE_ID_CPU_PQ] = GAUDI_ENGINE_ID_SIZE,
430e65e175bSOded Gabbay [GAUDI_QUEUE_ID_DMA_2_0...GAUDI_QUEUE_ID_DMA_2_3] = GAUDI_ENGINE_ID_DMA_2,
431e65e175bSOded Gabbay [GAUDI_QUEUE_ID_DMA_3_0...GAUDI_QUEUE_ID_DMA_3_3] = GAUDI_ENGINE_ID_DMA_3,
432e65e175bSOded Gabbay [GAUDI_QUEUE_ID_DMA_4_0...GAUDI_QUEUE_ID_DMA_4_3] = GAUDI_ENGINE_ID_DMA_4,
433e65e175bSOded Gabbay [GAUDI_QUEUE_ID_DMA_5_0...GAUDI_QUEUE_ID_DMA_5_3] = GAUDI_ENGINE_ID_DMA_5,
434e65e175bSOded Gabbay [GAUDI_QUEUE_ID_DMA_6_0...GAUDI_QUEUE_ID_DMA_6_3] = GAUDI_ENGINE_ID_DMA_6,
435e65e175bSOded Gabbay [GAUDI_QUEUE_ID_DMA_7_0...GAUDI_QUEUE_ID_DMA_7_3] = GAUDI_ENGINE_ID_DMA_7,
436e65e175bSOded Gabbay [GAUDI_QUEUE_ID_MME_0_0...GAUDI_QUEUE_ID_MME_0_3] = GAUDI_ENGINE_ID_MME_0,
437e65e175bSOded Gabbay [GAUDI_QUEUE_ID_MME_1_0...GAUDI_QUEUE_ID_MME_1_3] = GAUDI_ENGINE_ID_MME_2,
438e65e175bSOded Gabbay [GAUDI_QUEUE_ID_TPC_0_0...GAUDI_QUEUE_ID_TPC_0_3] = GAUDI_ENGINE_ID_TPC_0,
439e65e175bSOded Gabbay [GAUDI_QUEUE_ID_TPC_1_0...GAUDI_QUEUE_ID_TPC_1_3] = GAUDI_ENGINE_ID_TPC_1,
440e65e175bSOded Gabbay [GAUDI_QUEUE_ID_TPC_2_0...GAUDI_QUEUE_ID_TPC_2_3] = GAUDI_ENGINE_ID_TPC_2,
441e65e175bSOded Gabbay [GAUDI_QUEUE_ID_TPC_3_0...GAUDI_QUEUE_ID_TPC_3_3] = GAUDI_ENGINE_ID_TPC_3,
442e65e175bSOded Gabbay [GAUDI_QUEUE_ID_TPC_4_0...GAUDI_QUEUE_ID_TPC_4_3] = GAUDI_ENGINE_ID_TPC_4,
443e65e175bSOded Gabbay [GAUDI_QUEUE_ID_TPC_5_0...GAUDI_QUEUE_ID_TPC_5_3] = GAUDI_ENGINE_ID_TPC_5,
444e65e175bSOded Gabbay [GAUDI_QUEUE_ID_TPC_6_0...GAUDI_QUEUE_ID_TPC_6_3] = GAUDI_ENGINE_ID_TPC_6,
445e65e175bSOded Gabbay [GAUDI_QUEUE_ID_TPC_7_0...GAUDI_QUEUE_ID_TPC_7_3] = GAUDI_ENGINE_ID_TPC_7,
446e65e175bSOded Gabbay [GAUDI_QUEUE_ID_NIC_0_0...GAUDI_QUEUE_ID_NIC_0_3] = GAUDI_ENGINE_ID_NIC_0,
447e65e175bSOded Gabbay [GAUDI_QUEUE_ID_NIC_1_0...GAUDI_QUEUE_ID_NIC_1_3] = GAUDI_ENGINE_ID_NIC_1,
448e65e175bSOded Gabbay [GAUDI_QUEUE_ID_NIC_2_0...GAUDI_QUEUE_ID_NIC_2_3] = GAUDI_ENGINE_ID_NIC_2,
449e65e175bSOded Gabbay [GAUDI_QUEUE_ID_NIC_3_0...GAUDI_QUEUE_ID_NIC_3_3] = GAUDI_ENGINE_ID_NIC_3,
450e65e175bSOded Gabbay [GAUDI_QUEUE_ID_NIC_4_0...GAUDI_QUEUE_ID_NIC_4_3] = GAUDI_ENGINE_ID_NIC_4,
451e65e175bSOded Gabbay [GAUDI_QUEUE_ID_NIC_5_0...GAUDI_QUEUE_ID_NIC_5_3] = GAUDI_ENGINE_ID_NIC_5,
452e65e175bSOded Gabbay [GAUDI_QUEUE_ID_NIC_6_0...GAUDI_QUEUE_ID_NIC_6_3] = GAUDI_ENGINE_ID_NIC_6,
453e65e175bSOded Gabbay [GAUDI_QUEUE_ID_NIC_7_0...GAUDI_QUEUE_ID_NIC_7_3] = GAUDI_ENGINE_ID_NIC_7,
454e65e175bSOded Gabbay [GAUDI_QUEUE_ID_NIC_8_0...GAUDI_QUEUE_ID_NIC_8_3] = GAUDI_ENGINE_ID_NIC_8,
455e65e175bSOded Gabbay [GAUDI_QUEUE_ID_NIC_9_0...GAUDI_QUEUE_ID_NIC_9_3] = GAUDI_ENGINE_ID_NIC_9,
456e65e175bSOded Gabbay };
457e65e175bSOded Gabbay
458e65e175bSOded Gabbay /* The order here is opposite to the order of the indexing in the h/w.
459e65e175bSOded Gabbay * i.e. SYNC_MGR_W_S is actually 0, SYNC_MGR_E_S is 1, etc.
460e65e175bSOded Gabbay */
461e65e175bSOded Gabbay static const char * const gaudi_sync_manager_names[] = {
462e65e175bSOded Gabbay "SYNC_MGR_E_N",
463e65e175bSOded Gabbay "SYNC_MGR_W_N",
464e65e175bSOded Gabbay "SYNC_MGR_E_S",
465e65e175bSOded Gabbay "SYNC_MGR_W_S",
466e65e175bSOded Gabbay NULL
467e65e175bSOded Gabbay };
468e65e175bSOded Gabbay
469e65e175bSOded Gabbay struct ecc_info_extract_params {
470e65e175bSOded Gabbay u64 block_address;
471e65e175bSOded Gabbay u32 num_memories;
472e65e175bSOded Gabbay bool derr;
473e65e175bSOded Gabbay };
474e65e175bSOded Gabbay
475e65e175bSOded Gabbay static int gaudi_mmu_update_asid_hop0_addr(struct hl_device *hdev, u32 asid,
476e65e175bSOded Gabbay u64 phys_addr);
477e65e175bSOded Gabbay static int gaudi_send_job_on_qman0(struct hl_device *hdev,
478e65e175bSOded Gabbay struct hl_cs_job *job);
479e65e175bSOded Gabbay static int gaudi_memset_device_memory(struct hl_device *hdev, u64 addr,
480e65e175bSOded Gabbay u32 size, u64 val);
481e65e175bSOded Gabbay static int gaudi_memset_registers(struct hl_device *hdev, u64 reg_base,
482e65e175bSOded Gabbay u32 num_regs, u32 val);
483e65e175bSOded Gabbay static int gaudi_run_tpc_kernel(struct hl_device *hdev, u64 tpc_kernel,
484e65e175bSOded Gabbay u32 tpc_id);
485e65e175bSOded Gabbay static int gaudi_mmu_clear_pgt_range(struct hl_device *hdev);
486e65e175bSOded Gabbay static int gaudi_cpucp_info_get(struct hl_device *hdev);
487e65e175bSOded Gabbay static void gaudi_disable_clock_gating(struct hl_device *hdev);
488e65e175bSOded Gabbay static void gaudi_mmu_prepare(struct hl_device *hdev, u32 asid);
489e65e175bSOded Gabbay static u32 gaudi_gen_signal_cb(struct hl_device *hdev, void *data, u16 sob_id,
490e65e175bSOded Gabbay u32 size, bool eb);
491e65e175bSOded Gabbay static u32 gaudi_gen_wait_cb(struct hl_device *hdev,
492e65e175bSOded Gabbay struct hl_gen_wait_properties *prop);
493e65e175bSOded Gabbay static inline enum hl_collective_mode
get_collective_mode(struct hl_device * hdev,u32 queue_id)494e65e175bSOded Gabbay get_collective_mode(struct hl_device *hdev, u32 queue_id)
495e65e175bSOded Gabbay {
496e65e175bSOded Gabbay if (gaudi_queue_type[queue_id] == QUEUE_TYPE_EXT)
497e65e175bSOded Gabbay return HL_COLLECTIVE_MASTER;
498e65e175bSOded Gabbay
499e65e175bSOded Gabbay if (queue_id >= GAUDI_QUEUE_ID_DMA_5_0 &&
500e65e175bSOded Gabbay queue_id <= GAUDI_QUEUE_ID_DMA_5_3)
501e65e175bSOded Gabbay return HL_COLLECTIVE_SLAVE;
502e65e175bSOded Gabbay
503e65e175bSOded Gabbay if (queue_id >= GAUDI_QUEUE_ID_TPC_7_0 &&
504e65e175bSOded Gabbay queue_id <= GAUDI_QUEUE_ID_TPC_7_3)
505e65e175bSOded Gabbay return HL_COLLECTIVE_SLAVE;
506e65e175bSOded Gabbay
507e65e175bSOded Gabbay if (queue_id >= GAUDI_QUEUE_ID_NIC_0_0 &&
508e65e175bSOded Gabbay queue_id <= GAUDI_QUEUE_ID_NIC_9_3)
509e65e175bSOded Gabbay return HL_COLLECTIVE_SLAVE;
510e65e175bSOded Gabbay
511e65e175bSOded Gabbay return HL_COLLECTIVE_NOT_SUPPORTED;
512e65e175bSOded Gabbay }
513e65e175bSOded Gabbay
set_default_power_values(struct hl_device * hdev)514e65e175bSOded Gabbay static inline void set_default_power_values(struct hl_device *hdev)
515e65e175bSOded Gabbay {
516e65e175bSOded Gabbay struct asic_fixed_properties *prop = &hdev->asic_prop;
517e65e175bSOded Gabbay
518e65e175bSOded Gabbay if (hdev->card_type == cpucp_card_type_pmc) {
519e65e175bSOded Gabbay prop->max_power_default = MAX_POWER_DEFAULT_PMC;
520e65e175bSOded Gabbay
521e65e175bSOded Gabbay if (prop->fw_security_enabled)
522e65e175bSOded Gabbay prop->dc_power_default = DC_POWER_DEFAULT_PMC_SEC;
523e65e175bSOded Gabbay else
524e65e175bSOded Gabbay prop->dc_power_default = DC_POWER_DEFAULT_PMC;
525e65e175bSOded Gabbay } else {
526e65e175bSOded Gabbay prop->max_power_default = MAX_POWER_DEFAULT_PCI;
527e65e175bSOded Gabbay prop->dc_power_default = DC_POWER_DEFAULT_PCI;
528e65e175bSOded Gabbay }
529e65e175bSOded Gabbay }
530e65e175bSOded Gabbay
gaudi_set_fixed_properties(struct hl_device * hdev)531e65e175bSOded Gabbay static int gaudi_set_fixed_properties(struct hl_device *hdev)
532e65e175bSOded Gabbay {
533e65e175bSOded Gabbay struct asic_fixed_properties *prop = &hdev->asic_prop;
534e65e175bSOded Gabbay u32 num_sync_stream_queues = 0;
535e65e175bSOded Gabbay int i;
536e65e175bSOded Gabbay
537e65e175bSOded Gabbay prop->max_queues = GAUDI_QUEUE_ID_SIZE;
538e65e175bSOded Gabbay prop->hw_queues_props = kcalloc(prop->max_queues,
539e65e175bSOded Gabbay sizeof(struct hw_queue_properties),
540e65e175bSOded Gabbay GFP_KERNEL);
541e65e175bSOded Gabbay
542e65e175bSOded Gabbay if (!prop->hw_queues_props)
543e65e175bSOded Gabbay return -ENOMEM;
544e65e175bSOded Gabbay
545e65e175bSOded Gabbay for (i = 0 ; i < prop->max_queues ; i++) {
546e65e175bSOded Gabbay if (gaudi_queue_type[i] == QUEUE_TYPE_EXT) {
547e65e175bSOded Gabbay prop->hw_queues_props[i].type = QUEUE_TYPE_EXT;
548e65e175bSOded Gabbay prop->hw_queues_props[i].driver_only = 0;
549e65e175bSOded Gabbay prop->hw_queues_props[i].supports_sync_stream = 1;
550e65e175bSOded Gabbay prop->hw_queues_props[i].cb_alloc_flags =
551e65e175bSOded Gabbay CB_ALLOC_KERNEL;
552e65e175bSOded Gabbay num_sync_stream_queues++;
553e65e175bSOded Gabbay } else if (gaudi_queue_type[i] == QUEUE_TYPE_CPU) {
554e65e175bSOded Gabbay prop->hw_queues_props[i].type = QUEUE_TYPE_CPU;
555e65e175bSOded Gabbay prop->hw_queues_props[i].driver_only = 1;
556e65e175bSOded Gabbay prop->hw_queues_props[i].supports_sync_stream = 0;
557e65e175bSOded Gabbay prop->hw_queues_props[i].cb_alloc_flags =
558e65e175bSOded Gabbay CB_ALLOC_KERNEL;
559e65e175bSOded Gabbay } else if (gaudi_queue_type[i] == QUEUE_TYPE_INT) {
560e65e175bSOded Gabbay prop->hw_queues_props[i].type = QUEUE_TYPE_INT;
561e65e175bSOded Gabbay prop->hw_queues_props[i].driver_only = 0;
562e65e175bSOded Gabbay prop->hw_queues_props[i].supports_sync_stream = 0;
563e65e175bSOded Gabbay prop->hw_queues_props[i].cb_alloc_flags =
564e65e175bSOded Gabbay CB_ALLOC_USER;
565e65e175bSOded Gabbay
566e65e175bSOded Gabbay }
567e65e175bSOded Gabbay prop->hw_queues_props[i].collective_mode =
568e65e175bSOded Gabbay get_collective_mode(hdev, i);
569e65e175bSOded Gabbay }
570e65e175bSOded Gabbay
571e65e175bSOded Gabbay prop->cache_line_size = DEVICE_CACHE_LINE_SIZE;
572e65e175bSOded Gabbay prop->cfg_base_address = CFG_BASE;
573e65e175bSOded Gabbay prop->device_dma_offset_for_host_access = HOST_PHYS_BASE;
574e65e175bSOded Gabbay prop->host_base_address = HOST_PHYS_BASE;
575e65e175bSOded Gabbay prop->host_end_address = prop->host_base_address + HOST_PHYS_SIZE;
576e65e175bSOded Gabbay prop->completion_queues_count = NUMBER_OF_CMPLT_QUEUES;
577e65e175bSOded Gabbay prop->completion_mode = HL_COMPLETION_MODE_JOB;
578e65e175bSOded Gabbay prop->collective_first_sob = 0;
579e65e175bSOded Gabbay prop->collective_first_mon = 0;
580e65e175bSOded Gabbay
581e65e175bSOded Gabbay /* 2 SOBs per internal queue stream are reserved for collective */
582e65e175bSOded Gabbay prop->sync_stream_first_sob =
583e65e175bSOded Gabbay ALIGN(NUMBER_OF_SOBS_IN_GRP, HL_MAX_SOBS_PER_MONITOR)
584e65e175bSOded Gabbay * QMAN_STREAMS * HL_RSVD_SOBS;
585e65e175bSOded Gabbay
586e65e175bSOded Gabbay /* 1 monitor per internal queue stream are reserved for collective
587e65e175bSOded Gabbay * 2 monitors per external queue stream are reserved for collective
588e65e175bSOded Gabbay */
589e65e175bSOded Gabbay prop->sync_stream_first_mon =
590e65e175bSOded Gabbay (NUMBER_OF_COLLECTIVE_QUEUES * QMAN_STREAMS) +
591e65e175bSOded Gabbay (NUMBER_OF_EXT_HW_QUEUES * 2);
592e65e175bSOded Gabbay
593e65e175bSOded Gabbay prop->dram_base_address = DRAM_PHYS_BASE;
594e65e175bSOded Gabbay prop->dram_size = GAUDI_HBM_SIZE_32GB;
595e65e175bSOded Gabbay prop->dram_end_address = prop->dram_base_address + prop->dram_size;
596e65e175bSOded Gabbay prop->dram_user_base_address = DRAM_BASE_ADDR_USER;
597e65e175bSOded Gabbay
598e65e175bSOded Gabbay prop->sram_base_address = SRAM_BASE_ADDR;
599e65e175bSOded Gabbay prop->sram_size = SRAM_SIZE;
600e65e175bSOded Gabbay prop->sram_end_address = prop->sram_base_address + prop->sram_size;
601e65e175bSOded Gabbay prop->sram_user_base_address =
602e65e175bSOded Gabbay prop->sram_base_address + SRAM_USER_BASE_OFFSET;
603e65e175bSOded Gabbay
604e65e175bSOded Gabbay prop->mmu_cache_mng_addr = MMU_CACHE_MNG_ADDR;
605e65e175bSOded Gabbay prop->mmu_cache_mng_size = MMU_CACHE_MNG_SIZE;
606e65e175bSOded Gabbay
607e65e175bSOded Gabbay prop->mmu_pgt_addr = MMU_PAGE_TABLES_ADDR;
608e65e175bSOded Gabbay if (hdev->pldm)
609e65e175bSOded Gabbay prop->mmu_pgt_size = 0x800000; /* 8MB */
610e65e175bSOded Gabbay else
611e65e175bSOded Gabbay prop->mmu_pgt_size = MMU_PAGE_TABLES_SIZE;
612e65e175bSOded Gabbay prop->mmu_pte_size = HL_PTE_SIZE;
613e65e175bSOded Gabbay prop->mmu_hop_table_size = HOP_TABLE_SIZE_512_PTE;
614e65e175bSOded Gabbay prop->mmu_hop0_tables_total_size = HOP0_512_PTE_TABLES_TOTAL_SIZE;
615e65e175bSOded Gabbay prop->dram_page_size = PAGE_SIZE_2MB;
616e65e175bSOded Gabbay prop->device_mem_alloc_default_page_size = prop->dram_page_size;
617e65e175bSOded Gabbay prop->dram_supports_virtual_memory = false;
618e65e175bSOded Gabbay
619e65e175bSOded Gabbay prop->pmmu.hop_shifts[MMU_HOP0] = MMU_V1_1_HOP0_SHIFT;
620e65e175bSOded Gabbay prop->pmmu.hop_shifts[MMU_HOP1] = MMU_V1_1_HOP1_SHIFT;
621e65e175bSOded Gabbay prop->pmmu.hop_shifts[MMU_HOP2] = MMU_V1_1_HOP2_SHIFT;
622e65e175bSOded Gabbay prop->pmmu.hop_shifts[MMU_HOP3] = MMU_V1_1_HOP3_SHIFT;
623e65e175bSOded Gabbay prop->pmmu.hop_shifts[MMU_HOP4] = MMU_V1_1_HOP4_SHIFT;
624e65e175bSOded Gabbay prop->pmmu.hop_masks[MMU_HOP0] = MMU_V1_1_HOP0_MASK;
625e65e175bSOded Gabbay prop->pmmu.hop_masks[MMU_HOP1] = MMU_V1_1_HOP1_MASK;
626e65e175bSOded Gabbay prop->pmmu.hop_masks[MMU_HOP2] = MMU_V1_1_HOP2_MASK;
627e65e175bSOded Gabbay prop->pmmu.hop_masks[MMU_HOP3] = MMU_V1_1_HOP3_MASK;
628e65e175bSOded Gabbay prop->pmmu.hop_masks[MMU_HOP4] = MMU_V1_1_HOP4_MASK;
629e65e175bSOded Gabbay prop->pmmu.start_addr = VA_HOST_SPACE_START;
630e65e175bSOded Gabbay prop->pmmu.end_addr =
631e65e175bSOded Gabbay (VA_HOST_SPACE_START + VA_HOST_SPACE_SIZE / 2) - 1;
632e65e175bSOded Gabbay prop->pmmu.page_size = PAGE_SIZE_4KB;
633e65e175bSOded Gabbay prop->pmmu.num_hops = MMU_ARCH_5_HOPS;
634e65e175bSOded Gabbay prop->pmmu.last_mask = LAST_MASK;
635e65e175bSOded Gabbay /* TODO: will be duplicated until implementing per-MMU props */
636e65e175bSOded Gabbay prop->pmmu.hop_table_size = prop->mmu_hop_table_size;
637e65e175bSOded Gabbay prop->pmmu.hop0_tables_total_size = prop->mmu_hop0_tables_total_size;
638e65e175bSOded Gabbay
639e65e175bSOded Gabbay /* PMMU and HPMMU are the same except of page size */
640e65e175bSOded Gabbay memcpy(&prop->pmmu_huge, &prop->pmmu, sizeof(prop->pmmu));
641e65e175bSOded Gabbay prop->pmmu_huge.page_size = PAGE_SIZE_2MB;
642e65e175bSOded Gabbay
643e65e175bSOded Gabbay /* shifts and masks are the same in PMMU and DMMU */
644e65e175bSOded Gabbay memcpy(&prop->dmmu, &prop->pmmu, sizeof(prop->pmmu));
645e65e175bSOded Gabbay prop->dmmu.start_addr = (VA_HOST_SPACE_START + VA_HOST_SPACE_SIZE / 2);
646e65e175bSOded Gabbay prop->dmmu.end_addr = VA_HOST_SPACE_END;
647e65e175bSOded Gabbay prop->dmmu.page_size = PAGE_SIZE_2MB;
648e65e175bSOded Gabbay
649e65e175bSOded Gabbay prop->cfg_size = CFG_SIZE;
650e65e175bSOded Gabbay prop->max_asid = MAX_ASID;
651e65e175bSOded Gabbay prop->num_of_events = GAUDI_EVENT_SIZE;
652e65e175bSOded Gabbay prop->max_num_of_engines = GAUDI_ENGINE_ID_SIZE;
653e65e175bSOded Gabbay prop->tpc_enabled_mask = TPC_ENABLED_MASK;
654e65e175bSOded Gabbay
655e65e175bSOded Gabbay set_default_power_values(hdev);
656e65e175bSOded Gabbay
657e65e175bSOded Gabbay prop->cb_pool_cb_cnt = GAUDI_CB_POOL_CB_CNT;
658e65e175bSOded Gabbay prop->cb_pool_cb_size = GAUDI_CB_POOL_CB_SIZE;
659f7f0085eSKoby Elbaz
660e65e175bSOded Gabbay prop->pcie_dbi_base_address = mmPCIE_DBI_BASE;
661e65e175bSOded Gabbay prop->pcie_aux_dbi_reg_addr = CFG_BASE + mmPCIE_AUX_DBI;
662e65e175bSOded Gabbay
663e65e175bSOded Gabbay strncpy(prop->cpucp_info.card_name, GAUDI_DEFAULT_CARD_NAME,
664e65e175bSOded Gabbay CARD_NAME_MAX_LEN);
665e65e175bSOded Gabbay
666e65e175bSOded Gabbay prop->max_pending_cs = GAUDI_MAX_PENDING_CS;
667e65e175bSOded Gabbay
668e65e175bSOded Gabbay prop->first_available_user_sob[HL_GAUDI_WS_DCORE] =
669e65e175bSOded Gabbay prop->sync_stream_first_sob +
670e65e175bSOded Gabbay (num_sync_stream_queues * HL_RSVD_SOBS);
671e65e175bSOded Gabbay prop->first_available_user_mon[HL_GAUDI_WS_DCORE] =
672e65e175bSOded Gabbay prop->sync_stream_first_mon +
673e65e175bSOded Gabbay (num_sync_stream_queues * HL_RSVD_MONS);
674e65e175bSOded Gabbay
675e65e175bSOded Gabbay prop->first_available_user_interrupt = USHRT_MAX;
676e65e175bSOded Gabbay prop->tpc_interrupt_id = USHRT_MAX;
677e65e175bSOded Gabbay
678e65e175bSOded Gabbay /* single msi */
679e65e175bSOded Gabbay prop->eq_interrupt_id = 0;
680e65e175bSOded Gabbay
681e65e175bSOded Gabbay for (i = 0 ; i < HL_MAX_DCORES ; i++)
682e65e175bSOded Gabbay prop->first_available_cq[i] = USHRT_MAX;
6834713ace3SOfir Bitton
684e65e175bSOded Gabbay prop->fw_cpu_boot_dev_sts0_valid = false;
685802f25b6STal Cohen prop->fw_cpu_boot_dev_sts1_valid = false;
686802f25b6STal Cohen prop->hard_reset_done_by_fw = false;
687802f25b6STal Cohen prop->gic_interrupts_enable = true;
688e65e175bSOded Gabbay
689e65e175bSOded Gabbay prop->server_type = HL_SERVER_TYPE_UNKNOWN;
690e65e175bSOded Gabbay
691e65e175bSOded Gabbay prop->clk_pll_index = HL_GAUDI_MME_PLL;
692e65e175bSOded Gabbay prop->max_freq_value = GAUDI_MAX_CLK_FREQ;
693e65e175bSOded Gabbay
694e65e175bSOded Gabbay prop->use_get_power_for_reset_history = true;
695e65e175bSOded Gabbay
696e65e175bSOded Gabbay prop->configurable_stop_on_err = true;
697e65e175bSOded Gabbay
698e65e175bSOded Gabbay prop->set_max_power_on_device_init = true;
699e65e175bSOded Gabbay
700e65e175bSOded Gabbay prop->dma_mask = 48;
701e65e175bSOded Gabbay
702e65e175bSOded Gabbay prop->hbw_flush_reg = mmPCIE_WRAP_RR_ELBI_RD_SEC_REG_CTRL;
703e65e175bSOded Gabbay
704e65e175bSOded Gabbay return 0;
705e65e175bSOded Gabbay }
706e65e175bSOded Gabbay
gaudi_pci_bars_map(struct hl_device * hdev)707e65e175bSOded Gabbay static int gaudi_pci_bars_map(struct hl_device *hdev)
708e65e175bSOded Gabbay {
70920faaeecSOhad Sharabi static const char * const name[] = {"SRAM", "CFG", "HBM"};
71020faaeecSOhad Sharabi bool is_wc[3] = {false, false, true};
711e65e175bSOded Gabbay int rc;
712e65e175bSOded Gabbay
713e65e175bSOded Gabbay rc = hl_pci_bars_map(hdev, name, is_wc);
714e65e175bSOded Gabbay if (rc)
715e65e175bSOded Gabbay return rc;
716e65e175bSOded Gabbay
717e65e175bSOded Gabbay hdev->rmmio = hdev->pcie_bar[CFG_BAR_ID] +
718e65e175bSOded Gabbay (CFG_BASE - SPI_FLASH_BASE_ADDR);
719e65e175bSOded Gabbay
720e65e175bSOded Gabbay return 0;
721e65e175bSOded Gabbay }
722e65e175bSOded Gabbay
gaudi_set_hbm_bar_base(struct hl_device * hdev,u64 addr)723e65e175bSOded Gabbay static u64 gaudi_set_hbm_bar_base(struct hl_device *hdev, u64 addr)
724e65e175bSOded Gabbay {
725e65e175bSOded Gabbay struct gaudi_device *gaudi = hdev->asic_specific;
726e65e175bSOded Gabbay struct hl_inbound_pci_region pci_region;
727e65e175bSOded Gabbay u64 old_addr = addr;
728e65e175bSOded Gabbay int rc;
729e65e175bSOded Gabbay
730e65e175bSOded Gabbay if ((gaudi) && (gaudi->hbm_bar_cur_addr == addr))
731e65e175bSOded Gabbay return old_addr;
732e65e175bSOded Gabbay
733e65e175bSOded Gabbay if (hdev->asic_prop.iatu_done_by_fw)
734e65e175bSOded Gabbay return U64_MAX;
735e65e175bSOded Gabbay
736e65e175bSOded Gabbay /* Inbound Region 2 - Bar 4 - Point to HBM */
737e65e175bSOded Gabbay pci_region.mode = PCI_BAR_MATCH_MODE;
738e65e175bSOded Gabbay pci_region.bar = HBM_BAR_ID;
739e65e175bSOded Gabbay pci_region.addr = addr;
740e65e175bSOded Gabbay rc = hl_pci_set_inbound_region(hdev, 2, &pci_region);
741e65e175bSOded Gabbay if (rc)
742e65e175bSOded Gabbay return U64_MAX;
743e65e175bSOded Gabbay
744e65e175bSOded Gabbay if (gaudi) {
745e65e175bSOded Gabbay old_addr = gaudi->hbm_bar_cur_addr;
746e65e175bSOded Gabbay gaudi->hbm_bar_cur_addr = addr;
747e65e175bSOded Gabbay }
748e65e175bSOded Gabbay
749e65e175bSOded Gabbay return old_addr;
750e65e175bSOded Gabbay }
751e65e175bSOded Gabbay
gaudi_init_iatu(struct hl_device * hdev)752e65e175bSOded Gabbay static int gaudi_init_iatu(struct hl_device *hdev)
753e65e175bSOded Gabbay {
754e65e175bSOded Gabbay struct hl_inbound_pci_region inbound_region;
755e65e175bSOded Gabbay struct hl_outbound_pci_region outbound_region;
756e65e175bSOded Gabbay int rc;
757e65e175bSOded Gabbay
758e65e175bSOded Gabbay if (hdev->asic_prop.iatu_done_by_fw)
759e65e175bSOded Gabbay return 0;
760e65e175bSOded Gabbay
761e65e175bSOded Gabbay /* Inbound Region 0 - Bar 0 - Point to SRAM + CFG */
762e65e175bSOded Gabbay inbound_region.mode = PCI_BAR_MATCH_MODE;
763e65e175bSOded Gabbay inbound_region.bar = SRAM_BAR_ID;
764e65e175bSOded Gabbay inbound_region.addr = SRAM_BASE_ADDR;
765e65e175bSOded Gabbay rc = hl_pci_set_inbound_region(hdev, 0, &inbound_region);
766e65e175bSOded Gabbay if (rc)
767e65e175bSOded Gabbay goto done;
768e65e175bSOded Gabbay
769e65e175bSOded Gabbay /* Inbound Region 1 - Bar 2 - Point to SPI FLASH */
770e65e175bSOded Gabbay inbound_region.mode = PCI_BAR_MATCH_MODE;
771e65e175bSOded Gabbay inbound_region.bar = CFG_BAR_ID;
772e65e175bSOded Gabbay inbound_region.addr = SPI_FLASH_BASE_ADDR;
773e65e175bSOded Gabbay rc = hl_pci_set_inbound_region(hdev, 1, &inbound_region);
774e65e175bSOded Gabbay if (rc)
775e65e175bSOded Gabbay goto done;
776e65e175bSOded Gabbay
777e65e175bSOded Gabbay /* Inbound Region 2 - Bar 4 - Point to HBM */
778e65e175bSOded Gabbay inbound_region.mode = PCI_BAR_MATCH_MODE;
779e65e175bSOded Gabbay inbound_region.bar = HBM_BAR_ID;
780e65e175bSOded Gabbay inbound_region.addr = DRAM_PHYS_BASE;
781e65e175bSOded Gabbay rc = hl_pci_set_inbound_region(hdev, 2, &inbound_region);
782e65e175bSOded Gabbay if (rc)
783e65e175bSOded Gabbay goto done;
784e65e175bSOded Gabbay
785e65e175bSOded Gabbay /* Outbound Region 0 - Point to Host */
786e65e175bSOded Gabbay outbound_region.addr = HOST_PHYS_BASE;
787e65e175bSOded Gabbay outbound_region.size = HOST_PHYS_SIZE;
788e65e175bSOded Gabbay rc = hl_pci_set_outbound_region(hdev, &outbound_region);
789e65e175bSOded Gabbay
790e65e175bSOded Gabbay done:
791e65e175bSOded Gabbay return rc;
792e65e175bSOded Gabbay }
793e65e175bSOded Gabbay
gaudi_get_hw_state(struct hl_device * hdev)794e65e175bSOded Gabbay static enum hl_device_hw_state gaudi_get_hw_state(struct hl_device *hdev)
795e65e175bSOded Gabbay {
796e65e175bSOded Gabbay return RREG32(mmHW_STATE);
797e65e175bSOded Gabbay }
798e65e175bSOded Gabbay
gaudi_early_init(struct hl_device * hdev)799e65e175bSOded Gabbay static int gaudi_early_init(struct hl_device *hdev)
800e65e175bSOded Gabbay {
801e65e175bSOded Gabbay struct asic_fixed_properties *prop = &hdev->asic_prop;
802e65e175bSOded Gabbay struct pci_dev *pdev = hdev->pdev;
803e65e175bSOded Gabbay resource_size_t pci_bar_size;
804e65e175bSOded Gabbay u32 fw_boot_status;
805e65e175bSOded Gabbay int rc;
806e65e175bSOded Gabbay
807e65e175bSOded Gabbay rc = gaudi_set_fixed_properties(hdev);
808e65e175bSOded Gabbay if (rc) {
809e65e175bSOded Gabbay dev_err(hdev->dev, "Failed setting fixed properties\n");
810e65e175bSOded Gabbay return rc;
811e65e175bSOded Gabbay }
812e65e175bSOded Gabbay
813e65e175bSOded Gabbay /* Check BAR sizes */
814e65e175bSOded Gabbay pci_bar_size = pci_resource_len(pdev, SRAM_BAR_ID);
815e65e175bSOded Gabbay
816e65e175bSOded Gabbay if (pci_bar_size != SRAM_BAR_SIZE) {
817e65e175bSOded Gabbay dev_err(hdev->dev, "Not " HL_NAME "? BAR %d size %pa, expecting %llu\n",
818e65e175bSOded Gabbay SRAM_BAR_ID, &pci_bar_size, SRAM_BAR_SIZE);
819e65e175bSOded Gabbay rc = -ENODEV;
820e65e175bSOded Gabbay goto free_queue_props;
821e65e175bSOded Gabbay }
822e65e175bSOded Gabbay
823e65e175bSOded Gabbay pci_bar_size = pci_resource_len(pdev, CFG_BAR_ID);
824e65e175bSOded Gabbay
825e65e175bSOded Gabbay if (pci_bar_size != CFG_BAR_SIZE) {
826e65e175bSOded Gabbay dev_err(hdev->dev, "Not " HL_NAME "? BAR %d size %pa, expecting %llu\n",
827e65e175bSOded Gabbay CFG_BAR_ID, &pci_bar_size, CFG_BAR_SIZE);
828e65e175bSOded Gabbay rc = -ENODEV;
829e65e175bSOded Gabbay goto free_queue_props;
830e65e175bSOded Gabbay }
831e65e175bSOded Gabbay
832e65e175bSOded Gabbay prop->dram_pci_bar_size = pci_resource_len(pdev, HBM_BAR_ID);
833e65e175bSOded Gabbay hdev->dram_pci_bar_start = pci_resource_start(pdev, HBM_BAR_ID);
834e65e175bSOded Gabbay
835e65e175bSOded Gabbay /* If FW security is enabled at this point it means no access to ELBI */
836e65e175bSOded Gabbay if (hdev->asic_prop.fw_security_enabled) {
837e65e175bSOded Gabbay hdev->asic_prop.iatu_done_by_fw = true;
838e65e175bSOded Gabbay
839e65e175bSOded Gabbay /*
840e65e175bSOded Gabbay * GIC-security-bit can ONLY be set by CPUCP, so in this stage
841e65e175bSOded Gabbay * decision can only be taken based on PCI ID security.
842e65e175bSOded Gabbay */
843e65e175bSOded Gabbay hdev->asic_prop.gic_interrupts_enable = false;
844e65e175bSOded Gabbay goto pci_init;
845e65e175bSOded Gabbay }
846e65e175bSOded Gabbay
847e65e175bSOded Gabbay rc = hl_pci_elbi_read(hdev, CFG_BASE + mmCPU_BOOT_DEV_STS0,
848e65e175bSOded Gabbay &fw_boot_status);
849e65e175bSOded Gabbay if (rc)
850e65e175bSOded Gabbay goto free_queue_props;
851e65e175bSOded Gabbay
852e65e175bSOded Gabbay /* Check whether FW is configuring iATU */
853e65e175bSOded Gabbay if ((fw_boot_status & CPU_BOOT_DEV_STS0_ENABLED) &&
854e65e175bSOded Gabbay (fw_boot_status & CPU_BOOT_DEV_STS0_FW_IATU_CONF_EN))
855e65e175bSOded Gabbay hdev->asic_prop.iatu_done_by_fw = true;
856e65e175bSOded Gabbay
857e65e175bSOded Gabbay pci_init:
858e65e175bSOded Gabbay rc = hl_pci_init(hdev);
859e65e175bSOded Gabbay if (rc)
860e65e175bSOded Gabbay goto free_queue_props;
861e65e175bSOded Gabbay
862e65e175bSOded Gabbay /* Before continuing in the initialization, we need to read the preboot
863e65e175bSOded Gabbay * version to determine whether we run with a security-enabled firmware
864e65e175bSOded Gabbay */
865e65e175bSOded Gabbay rc = hl_fw_read_preboot_status(hdev);
866e65e175bSOded Gabbay if (rc) {
867e65e175bSOded Gabbay if (hdev->reset_on_preboot_fail)
868e65e175bSOded Gabbay /* we are already on failure flow, so don't check if hw_fini fails. */
869e65e175bSOded Gabbay hdev->asic_funcs->hw_fini(hdev, true, false);
870e65e175bSOded Gabbay goto pci_fini;
871e65e175bSOded Gabbay }
872e65e175bSOded Gabbay
873e65e175bSOded Gabbay if (gaudi_get_hw_state(hdev) == HL_DEVICE_HW_STATE_DIRTY) {
874e65e175bSOded Gabbay dev_dbg(hdev->dev, "H/W state is dirty, must reset before initializing\n");
87586b74d84SDafna Hirschfeld rc = hdev->asic_funcs->hw_fini(hdev, true, false);
876e65e175bSOded Gabbay if (rc) {
877e65e175bSOded Gabbay dev_err(hdev->dev, "failed to reset HW in dirty state (%d)\n", rc);
878e65e175bSOded Gabbay goto pci_fini;
879e65e175bSOded Gabbay }
880e65e175bSOded Gabbay }
881e65e175bSOded Gabbay
88286b74d84SDafna Hirschfeld return 0;
88386b74d84SDafna Hirschfeld
88486b74d84SDafna Hirschfeld pci_fini:
88586b74d84SDafna Hirschfeld hl_pci_fini(hdev);
88686b74d84SDafna Hirschfeld free_queue_props:
887e65e175bSOded Gabbay kfree(hdev->asic_prop.hw_queues_props);
888e65e175bSOded Gabbay return rc;
889e65e175bSOded Gabbay }
890e65e175bSOded Gabbay
gaudi_early_fini(struct hl_device * hdev)891e65e175bSOded Gabbay static int gaudi_early_fini(struct hl_device *hdev)
892e65e175bSOded Gabbay {
893e65e175bSOded Gabbay kfree(hdev->asic_prop.hw_queues_props);
894e65e175bSOded Gabbay hl_pci_fini(hdev);
895e65e175bSOded Gabbay
896e65e175bSOded Gabbay return 0;
897e65e175bSOded Gabbay }
898e65e175bSOded Gabbay
899e65e175bSOded Gabbay /**
900e65e175bSOded Gabbay * gaudi_fetch_psoc_frequency - Fetch PSOC frequency values
901e65e175bSOded Gabbay *
902e65e175bSOded Gabbay * @hdev: pointer to hl_device structure
903e65e175bSOded Gabbay *
904e65e175bSOded Gabbay */
gaudi_fetch_psoc_frequency(struct hl_device * hdev)905e65e175bSOded Gabbay static int gaudi_fetch_psoc_frequency(struct hl_device *hdev)
906e65e175bSOded Gabbay {
907e65e175bSOded Gabbay u32 nr = 0, nf = 0, od = 0, div_fctr = 0, pll_clk, div_sel;
908e65e175bSOded Gabbay struct asic_fixed_properties *prop = &hdev->asic_prop;
909e65e175bSOded Gabbay u16 pll_freq_arr[HL_PLL_NUM_OUTPUTS], freq;
910e65e175bSOded Gabbay int rc;
911e65e175bSOded Gabbay
912e65e175bSOded Gabbay if ((hdev->fw_components & FW_TYPE_LINUX) &&
913e65e175bSOded Gabbay (prop->fw_app_cpu_boot_dev_sts0 & CPU_BOOT_DEV_STS0_PLL_INFO_EN)) {
914e65e175bSOded Gabbay struct gaudi_device *gaudi = hdev->asic_specific;
915e65e175bSOded Gabbay
916e65e175bSOded Gabbay if (!(gaudi->hw_cap_initialized & HW_CAP_CPU_Q))
917e65e175bSOded Gabbay return 0;
918e65e175bSOded Gabbay
919e65e175bSOded Gabbay rc = hl_fw_cpucp_pll_info_get(hdev, HL_GAUDI_CPU_PLL, pll_freq_arr);
920e65e175bSOded Gabbay
921e65e175bSOded Gabbay if (rc)
922e65e175bSOded Gabbay return rc;
923e65e175bSOded Gabbay
924e65e175bSOded Gabbay freq = pll_freq_arr[2];
925e65e175bSOded Gabbay } else {
926e65e175bSOded Gabbay /* Backward compatibility */
927e65e175bSOded Gabbay div_fctr = RREG32(mmPSOC_CPU_PLL_DIV_FACTOR_2);
928e65e175bSOded Gabbay div_sel = RREG32(mmPSOC_CPU_PLL_DIV_SEL_2);
929e65e175bSOded Gabbay nr = RREG32(mmPSOC_CPU_PLL_NR);
930e65e175bSOded Gabbay nf = RREG32(mmPSOC_CPU_PLL_NF);
931e65e175bSOded Gabbay od = RREG32(mmPSOC_CPU_PLL_OD);
932e65e175bSOded Gabbay
933e65e175bSOded Gabbay if (div_sel == DIV_SEL_REF_CLK ||
934e65e175bSOded Gabbay div_sel == DIV_SEL_DIVIDED_REF) {
935e65e175bSOded Gabbay if (div_sel == DIV_SEL_REF_CLK)
936e65e175bSOded Gabbay freq = PLL_REF_CLK;
937e65e175bSOded Gabbay else
938e65e175bSOded Gabbay freq = PLL_REF_CLK / (div_fctr + 1);
939e65e175bSOded Gabbay } else if (div_sel == DIV_SEL_PLL_CLK ||
940e65e175bSOded Gabbay div_sel == DIV_SEL_DIVIDED_PLL) {
941e65e175bSOded Gabbay pll_clk = PLL_REF_CLK * (nf + 1) /
942e65e175bSOded Gabbay ((nr + 1) * (od + 1));
943e65e175bSOded Gabbay if (div_sel == DIV_SEL_PLL_CLK)
944e65e175bSOded Gabbay freq = pll_clk;
945e65e175bSOded Gabbay else
946e65e175bSOded Gabbay freq = pll_clk / (div_fctr + 1);
947e65e175bSOded Gabbay } else {
948e65e175bSOded Gabbay dev_warn(hdev->dev, "Received invalid div select value: %#x", div_sel);
949e65e175bSOded Gabbay freq = 0;
950e65e175bSOded Gabbay }
951e65e175bSOded Gabbay }
952e65e175bSOded Gabbay
953e65e175bSOded Gabbay prop->psoc_timestamp_frequency = freq;
954e65e175bSOded Gabbay prop->psoc_pci_pll_nr = nr;
955e65e175bSOded Gabbay prop->psoc_pci_pll_nf = nf;
956e65e175bSOded Gabbay prop->psoc_pci_pll_od = od;
957e65e175bSOded Gabbay prop->psoc_pci_pll_div_factor = div_fctr;
958e65e175bSOded Gabbay
959e65e175bSOded Gabbay return 0;
960e65e175bSOded Gabbay }
961e65e175bSOded Gabbay
_gaudi_init_tpc_mem(struct hl_device * hdev,dma_addr_t tpc_kernel_src_addr,u32 tpc_kernel_size)962e65e175bSOded Gabbay static int _gaudi_init_tpc_mem(struct hl_device *hdev,
963e65e175bSOded Gabbay dma_addr_t tpc_kernel_src_addr, u32 tpc_kernel_size)
964e65e175bSOded Gabbay {
965e65e175bSOded Gabbay struct asic_fixed_properties *prop = &hdev->asic_prop;
966e65e175bSOded Gabbay struct packet_lin_dma *init_tpc_mem_pkt;
967e65e175bSOded Gabbay struct hl_cs_job *job;
968e65e175bSOded Gabbay struct hl_cb *cb;
969e65e175bSOded Gabbay u64 dst_addr;
970e65e175bSOded Gabbay u32 cb_size, ctl;
971e65e175bSOded Gabbay u8 tpc_id;
972e65e175bSOded Gabbay int rc;
973e65e175bSOded Gabbay
974e65e175bSOded Gabbay cb = hl_cb_kernel_create(hdev, PAGE_SIZE, false);
975e65e175bSOded Gabbay if (!cb)
976e65e175bSOded Gabbay return -EFAULT;
977e65e175bSOded Gabbay
978e65e175bSOded Gabbay init_tpc_mem_pkt = cb->kernel_address;
979e65e175bSOded Gabbay cb_size = sizeof(*init_tpc_mem_pkt);
980e65e175bSOded Gabbay memset(init_tpc_mem_pkt, 0, cb_size);
981e65e175bSOded Gabbay
982e65e175bSOded Gabbay init_tpc_mem_pkt->tsize = cpu_to_le32(tpc_kernel_size);
983e65e175bSOded Gabbay
984e65e175bSOded Gabbay ctl = FIELD_PREP(GAUDI_PKT_CTL_OPCODE_MASK, PACKET_LIN_DMA);
985e65e175bSOded Gabbay ctl |= FIELD_PREP(GAUDI_PKT_LIN_DMA_CTL_LIN_MASK, 1);
986e65e175bSOded Gabbay ctl |= FIELD_PREP(GAUDI_PKT_CTL_RB_MASK, 1);
987e65e175bSOded Gabbay ctl |= FIELD_PREP(GAUDI_PKT_CTL_MB_MASK, 1);
988e65e175bSOded Gabbay
989e65e175bSOded Gabbay init_tpc_mem_pkt->ctl = cpu_to_le32(ctl);
990e65e175bSOded Gabbay
991e65e175bSOded Gabbay init_tpc_mem_pkt->src_addr = cpu_to_le64(tpc_kernel_src_addr);
992e65e175bSOded Gabbay
993e65e175bSOded Gabbay /* TPC_CMD is configured with I$ prefetch enabled, so address should be aligned to 8KB */
994e65e175bSOded Gabbay dst_addr = FIELD_PREP(GAUDI_PKT_LIN_DMA_DST_ADDR_MASK,
995e65e175bSOded Gabbay round_up(prop->sram_user_base_address, SZ_8K));
996e65e175bSOded Gabbay init_tpc_mem_pkt->dst_addr |= cpu_to_le64(dst_addr);
997e65e175bSOded Gabbay
998e65e175bSOded Gabbay job = hl_cs_allocate_job(hdev, QUEUE_TYPE_EXT, true);
999e65e175bSOded Gabbay if (!job) {
1000e65e175bSOded Gabbay dev_err(hdev->dev, "Failed to allocate a new job\n");
1001e65e175bSOded Gabbay rc = -ENOMEM;
1002e65e175bSOded Gabbay goto release_cb;
1003e65e175bSOded Gabbay }
1004e65e175bSOded Gabbay
1005e65e175bSOded Gabbay job->id = 0;
1006e65e175bSOded Gabbay job->user_cb = cb;
1007e65e175bSOded Gabbay atomic_inc(&job->user_cb->cs_cnt);
1008e65e175bSOded Gabbay job->user_cb_size = cb_size;
1009e65e175bSOded Gabbay job->hw_queue_id = GAUDI_QUEUE_ID_DMA_0_0;
1010e65e175bSOded Gabbay job->patched_cb = job->user_cb;
1011e65e175bSOded Gabbay job->job_cb_size = job->user_cb_size + sizeof(struct packet_msg_prot);
1012e65e175bSOded Gabbay
1013e65e175bSOded Gabbay hl_debugfs_add_job(hdev, job);
1014e65e175bSOded Gabbay
1015e65e175bSOded Gabbay rc = gaudi_send_job_on_qman0(hdev, job);
1016e65e175bSOded Gabbay
1017e65e175bSOded Gabbay if (rc)
1018e65e175bSOded Gabbay goto free_job;
1019e65e175bSOded Gabbay
1020e65e175bSOded Gabbay for (tpc_id = 0 ; tpc_id < TPC_NUMBER_OF_ENGINES ; tpc_id++) {
1021e65e175bSOded Gabbay rc = gaudi_run_tpc_kernel(hdev, dst_addr, tpc_id);
1022e65e175bSOded Gabbay if (rc)
1023e65e175bSOded Gabbay break;
1024e65e175bSOded Gabbay }
1025e65e175bSOded Gabbay
1026e65e175bSOded Gabbay free_job:
1027e65e175bSOded Gabbay hl_userptr_delete_list(hdev, &job->userptr_list);
1028e65e175bSOded Gabbay hl_debugfs_remove_job(hdev, job);
1029e65e175bSOded Gabbay kfree(job);
1030e65e175bSOded Gabbay atomic_dec(&cb->cs_cnt);
1031e65e175bSOded Gabbay
1032e65e175bSOded Gabbay release_cb:
1033e65e175bSOded Gabbay hl_cb_put(cb);
1034e65e175bSOded Gabbay hl_cb_destroy(&hdev->kernel_mem_mgr, cb->buf->handle);
1035e65e175bSOded Gabbay
1036e65e175bSOded Gabbay return rc;
1037e65e175bSOded Gabbay }
1038e65e175bSOded Gabbay
1039e65e175bSOded Gabbay /*
1040e65e175bSOded Gabbay * gaudi_init_tpc_mem() - Initialize TPC memories.
1041e65e175bSOded Gabbay * @hdev: Pointer to hl_device structure.
1042e65e175bSOded Gabbay *
1043e65e175bSOded Gabbay * Copy TPC kernel fw from firmware file and run it to initialize TPC memories.
1044e65e175bSOded Gabbay *
1045e65e175bSOded Gabbay * Return: 0 for success, negative value for error.
1046e65e175bSOded Gabbay */
gaudi_init_tpc_mem(struct hl_device * hdev)1047e65e175bSOded Gabbay static int gaudi_init_tpc_mem(struct hl_device *hdev)
1048e65e175bSOded Gabbay {
1049e65e175bSOded Gabbay const struct firmware *fw;
1050e65e175bSOded Gabbay size_t fw_size;
1051e65e175bSOded Gabbay void *cpu_addr;
1052e65e175bSOded Gabbay dma_addr_t dma_handle;
1053e65e175bSOded Gabbay int rc, count = 5;
1054e65e175bSOded Gabbay
1055e65e175bSOded Gabbay again:
1056e65e175bSOded Gabbay rc = request_firmware(&fw, GAUDI_TPC_FW_FILE, hdev->dev);
1057e65e175bSOded Gabbay if (rc == -EINTR && count-- > 0) {
1058e65e175bSOded Gabbay msleep(50);
1059e65e175bSOded Gabbay goto again;
1060e65e175bSOded Gabbay }
1061e65e175bSOded Gabbay
1062e65e175bSOded Gabbay if (rc) {
1063e65e175bSOded Gabbay dev_err(hdev->dev, "Failed to load firmware file %s\n",
1064e65e175bSOded Gabbay GAUDI_TPC_FW_FILE);
1065e65e175bSOded Gabbay goto out;
1066e65e175bSOded Gabbay }
1067e65e175bSOded Gabbay
1068e65e175bSOded Gabbay fw_size = fw->size;
1069e65e175bSOded Gabbay cpu_addr = hl_asic_dma_alloc_coherent(hdev, fw_size, &dma_handle, GFP_KERNEL | __GFP_ZERO);
1070e65e175bSOded Gabbay if (!cpu_addr) {
1071e65e175bSOded Gabbay dev_err(hdev->dev,
1072e65e175bSOded Gabbay "Failed to allocate %zu of dma memory for TPC kernel\n",
1073e65e175bSOded Gabbay fw_size);
1074e65e175bSOded Gabbay rc = -ENOMEM;
1075e65e175bSOded Gabbay goto out;
1076e65e175bSOded Gabbay }
1077e65e175bSOded Gabbay
1078e65e175bSOded Gabbay memcpy(cpu_addr, fw->data, fw_size);
1079e65e175bSOded Gabbay
1080e65e175bSOded Gabbay rc = _gaudi_init_tpc_mem(hdev, dma_handle, fw_size);
1081e65e175bSOded Gabbay
1082e65e175bSOded Gabbay hl_asic_dma_free_coherent(hdev, fw->size, cpu_addr, dma_handle);
1083e65e175bSOded Gabbay
1084e65e175bSOded Gabbay out:
1085e65e175bSOded Gabbay release_firmware(fw);
1086e65e175bSOded Gabbay return rc;
1087e65e175bSOded Gabbay }
1088e65e175bSOded Gabbay
gaudi_collective_map_sobs(struct hl_device * hdev,u32 stream)1089e65e175bSOded Gabbay static void gaudi_collective_map_sobs(struct hl_device *hdev, u32 stream)
1090e65e175bSOded Gabbay {
1091e65e175bSOded Gabbay struct gaudi_device *gaudi = hdev->asic_specific;
1092e65e175bSOded Gabbay struct gaudi_collective_properties *prop = &gaudi->collective_props;
1093e65e175bSOded Gabbay struct hl_hw_queue *q;
1094e65e175bSOded Gabbay u32 i, sob_id, sob_group_id, queue_id;
1095e65e175bSOded Gabbay
1096e65e175bSOded Gabbay /* Iterate through SOB groups and assign a SOB for each slave queue */
1097e65e175bSOded Gabbay sob_group_id =
1098e65e175bSOded Gabbay stream * HL_RSVD_SOBS + prop->curr_sob_group_idx[stream];
1099e65e175bSOded Gabbay sob_id = prop->hw_sob_group[sob_group_id].base_sob_id;
1100e65e175bSOded Gabbay
1101e65e175bSOded Gabbay queue_id = GAUDI_QUEUE_ID_NIC_0_0 + stream;
1102e65e175bSOded Gabbay for (i = 0 ; i < NIC_NUMBER_OF_ENGINES ; i++) {
1103e65e175bSOded Gabbay q = &hdev->kernel_queues[queue_id + (4 * i)];
1104e65e175bSOded Gabbay q->sync_stream_prop.collective_sob_id = sob_id + i;
1105e65e175bSOded Gabbay }
1106e65e175bSOded Gabbay
1107e65e175bSOded Gabbay /* Both DMA5 and TPC7 use the same resources since only a single
1108e65e175bSOded Gabbay * engine need to participate in the reduction process
1109e65e175bSOded Gabbay */
1110e65e175bSOded Gabbay queue_id = GAUDI_QUEUE_ID_DMA_5_0 + stream;
1111e65e175bSOded Gabbay q = &hdev->kernel_queues[queue_id];
1112e65e175bSOded Gabbay q->sync_stream_prop.collective_sob_id =
1113e65e175bSOded Gabbay sob_id + NIC_NUMBER_OF_ENGINES;
1114e65e175bSOded Gabbay
1115e65e175bSOded Gabbay queue_id = GAUDI_QUEUE_ID_TPC_7_0 + stream;
1116e65e175bSOded Gabbay q = &hdev->kernel_queues[queue_id];
1117e65e175bSOded Gabbay q->sync_stream_prop.collective_sob_id =
1118e65e175bSOded Gabbay sob_id + NIC_NUMBER_OF_ENGINES;
1119e65e175bSOded Gabbay }
1120e65e175bSOded Gabbay
gaudi_sob_group_hw_reset(struct kref * ref)1121e65e175bSOded Gabbay static void gaudi_sob_group_hw_reset(struct kref *ref)
1122e65e175bSOded Gabbay {
1123e65e175bSOded Gabbay struct gaudi_hw_sob_group *hw_sob_group =
1124e65e175bSOded Gabbay container_of(ref, struct gaudi_hw_sob_group, kref);
1125e65e175bSOded Gabbay struct hl_device *hdev = hw_sob_group->hdev;
1126e65e175bSOded Gabbay int i;
1127e65e175bSOded Gabbay
1128e65e175bSOded Gabbay for (i = 0 ; i < NUMBER_OF_SOBS_IN_GRP ; i++)
1129e65e175bSOded Gabbay WREG32((mmSYNC_MNGR_W_S_SYNC_MNGR_OBJS_SOB_OBJ_0 +
1130e65e175bSOded Gabbay (hw_sob_group->base_sob_id * 4) + (i * 4)), 0);
1131e65e175bSOded Gabbay
1132e65e175bSOded Gabbay kref_init(&hw_sob_group->kref);
1133e65e175bSOded Gabbay }
1134e65e175bSOded Gabbay
gaudi_sob_group_reset_error(struct kref * ref)1135e65e175bSOded Gabbay static void gaudi_sob_group_reset_error(struct kref *ref)
1136e65e175bSOded Gabbay {
1137e65e175bSOded Gabbay struct gaudi_hw_sob_group *hw_sob_group =
1138e65e175bSOded Gabbay container_of(ref, struct gaudi_hw_sob_group, kref);
1139e65e175bSOded Gabbay struct hl_device *hdev = hw_sob_group->hdev;
1140e65e175bSOded Gabbay
1141e65e175bSOded Gabbay dev_crit(hdev->dev,
1142e65e175bSOded Gabbay "SOB release shouldn't be called here, base_sob_id: %d\n",
1143e65e175bSOded Gabbay hw_sob_group->base_sob_id);
1144e65e175bSOded Gabbay }
1145e65e175bSOded Gabbay
gaudi_collective_mstr_sob_mask_set(struct gaudi_device * gaudi)1146e65e175bSOded Gabbay static void gaudi_collective_mstr_sob_mask_set(struct gaudi_device *gaudi)
1147e65e175bSOded Gabbay {
1148e65e175bSOded Gabbay struct gaudi_collective_properties *prop;
1149e65e175bSOded Gabbay int i;
1150e65e175bSOded Gabbay
1151e65e175bSOded Gabbay prop = &gaudi->collective_props;
1152e65e175bSOded Gabbay
1153e65e175bSOded Gabbay memset(prop->mstr_sob_mask, 0, sizeof(prop->mstr_sob_mask));
1154e65e175bSOded Gabbay
1155e65e175bSOded Gabbay for (i = 0 ; i < NIC_NUMBER_OF_ENGINES ; i++)
1156e65e175bSOded Gabbay if (gaudi->hw_cap_initialized & BIT(HW_CAP_NIC_SHIFT + i))
1157e65e175bSOded Gabbay prop->mstr_sob_mask[i / HL_MAX_SOBS_PER_MONITOR] |=
1158e65e175bSOded Gabbay BIT(i % HL_MAX_SOBS_PER_MONITOR);
1159e65e175bSOded Gabbay /* Set collective engine bit */
1160e65e175bSOded Gabbay prop->mstr_sob_mask[i / HL_MAX_SOBS_PER_MONITOR] |=
1161e65e175bSOded Gabbay BIT(i % HL_MAX_SOBS_PER_MONITOR);
1162e65e175bSOded Gabbay }
1163e65e175bSOded Gabbay
gaudi_collective_init(struct hl_device * hdev)1164e65e175bSOded Gabbay static int gaudi_collective_init(struct hl_device *hdev)
1165e65e175bSOded Gabbay {
1166e65e175bSOded Gabbay u32 i, sob_id, reserved_sobs_per_group;
1167e65e175bSOded Gabbay struct gaudi_collective_properties *prop;
1168e65e175bSOded Gabbay struct gaudi_device *gaudi;
1169e65e175bSOded Gabbay
1170e65e175bSOded Gabbay gaudi = hdev->asic_specific;
1171e65e175bSOded Gabbay prop = &gaudi->collective_props;
1172e65e175bSOded Gabbay sob_id = hdev->asic_prop.collective_first_sob;
1173e65e175bSOded Gabbay
1174e65e175bSOded Gabbay /* First sob in group must be aligned to HL_MAX_SOBS_PER_MONITOR */
1175e65e175bSOded Gabbay reserved_sobs_per_group =
1176e65e175bSOded Gabbay ALIGN(NUMBER_OF_SOBS_IN_GRP, HL_MAX_SOBS_PER_MONITOR);
1177e65e175bSOded Gabbay
1178e65e175bSOded Gabbay /* Init SOB groups */
1179e65e175bSOded Gabbay for (i = 0 ; i < NUM_SOB_GROUPS; i++) {
1180e65e175bSOded Gabbay prop->hw_sob_group[i].hdev = hdev;
1181e65e175bSOded Gabbay prop->hw_sob_group[i].base_sob_id = sob_id;
1182e65e175bSOded Gabbay sob_id += reserved_sobs_per_group;
1183e65e175bSOded Gabbay gaudi_sob_group_hw_reset(&prop->hw_sob_group[i].kref);
1184e65e175bSOded Gabbay }
1185e65e175bSOded Gabbay
1186e65e175bSOded Gabbay for (i = 0 ; i < QMAN_STREAMS; i++) {
1187e65e175bSOded Gabbay prop->next_sob_group_val[i] = 1;
1188e65e175bSOded Gabbay prop->curr_sob_group_idx[i] = 0;
1189e65e175bSOded Gabbay gaudi_collective_map_sobs(hdev, i);
1190e65e175bSOded Gabbay }
1191e65e175bSOded Gabbay
1192e65e175bSOded Gabbay gaudi_collective_mstr_sob_mask_set(gaudi);
1193e65e175bSOded Gabbay
1194e65e175bSOded Gabbay return 0;
1195e65e175bSOded Gabbay }
1196e65e175bSOded Gabbay
gaudi_reset_sob_group(struct hl_device * hdev,u16 sob_group)1197e65e175bSOded Gabbay static void gaudi_reset_sob_group(struct hl_device *hdev, u16 sob_group)
1198e65e175bSOded Gabbay {
1199e65e175bSOded Gabbay struct gaudi_device *gaudi = hdev->asic_specific;
1200e65e175bSOded Gabbay struct gaudi_collective_properties *cprop = &gaudi->collective_props;
1201e65e175bSOded Gabbay
1202e65e175bSOded Gabbay kref_put(&cprop->hw_sob_group[sob_group].kref,
1203e65e175bSOded Gabbay gaudi_sob_group_hw_reset);
1204e65e175bSOded Gabbay }
1205e65e175bSOded Gabbay
gaudi_collective_master_init_job(struct hl_device * hdev,struct hl_cs_job * job,u32 stream,u32 sob_group_offset)1206e65e175bSOded Gabbay static void gaudi_collective_master_init_job(struct hl_device *hdev,
1207e65e175bSOded Gabbay struct hl_cs_job *job, u32 stream, u32 sob_group_offset)
1208e65e175bSOded Gabbay {
1209e65e175bSOded Gabbay u32 master_sob_base, master_monitor, queue_id, cb_size = 0;
1210e65e175bSOded Gabbay struct gaudi_collective_properties *cprop;
1211e65e175bSOded Gabbay struct hl_gen_wait_properties wait_prop;
1212e65e175bSOded Gabbay struct hl_sync_stream_properties *prop;
1213e65e175bSOded Gabbay struct gaudi_device *gaudi;
1214e65e175bSOded Gabbay
1215e65e175bSOded Gabbay gaudi = hdev->asic_specific;
1216e65e175bSOded Gabbay cprop = &gaudi->collective_props;
1217e65e175bSOded Gabbay queue_id = job->hw_queue_id;
1218e65e175bSOded Gabbay prop = &hdev->kernel_queues[queue_id].sync_stream_prop;
1219e65e175bSOded Gabbay
1220e65e175bSOded Gabbay master_sob_base =
1221e65e175bSOded Gabbay cprop->hw_sob_group[sob_group_offset].base_sob_id;
1222e65e175bSOded Gabbay master_monitor = prop->collective_mstr_mon_id[0];
1223e65e175bSOded Gabbay
1224e65e175bSOded Gabbay cprop->hw_sob_group[sob_group_offset].queue_id = queue_id;
1225e65e175bSOded Gabbay
1226e65e175bSOded Gabbay dev_dbg(hdev->dev,
1227e65e175bSOded Gabbay "Generate master wait CBs, sob %d (mask %#x), val:0x%x, mon %u, q %d\n",
1228e65e175bSOded Gabbay master_sob_base, cprop->mstr_sob_mask[0],
1229e65e175bSOded Gabbay cprop->next_sob_group_val[stream],
1230e65e175bSOded Gabbay master_monitor, queue_id);
1231e65e175bSOded Gabbay
1232e65e175bSOded Gabbay wait_prop.data = (void *) job->patched_cb;
1233e65e175bSOded Gabbay wait_prop.sob_base = master_sob_base;
1234e65e175bSOded Gabbay wait_prop.sob_mask = cprop->mstr_sob_mask[0];
1235e65e175bSOded Gabbay wait_prop.sob_val = cprop->next_sob_group_val[stream];
1236e65e175bSOded Gabbay wait_prop.mon_id = master_monitor;
1237e65e175bSOded Gabbay wait_prop.q_idx = queue_id;
1238e65e175bSOded Gabbay wait_prop.size = cb_size;
1239e65e175bSOded Gabbay cb_size += gaudi_gen_wait_cb(hdev, &wait_prop);
1240e65e175bSOded Gabbay
1241e65e175bSOded Gabbay master_sob_base += HL_MAX_SOBS_PER_MONITOR;
1242e65e175bSOded Gabbay master_monitor = prop->collective_mstr_mon_id[1];
1243e65e175bSOded Gabbay
1244e65e175bSOded Gabbay dev_dbg(hdev->dev,
1245e65e175bSOded Gabbay "Generate master wait CBs, sob %d (mask %#x), val:0x%x, mon %u, q %d\n",
1246e65e175bSOded Gabbay master_sob_base, cprop->mstr_sob_mask[1],
1247e65e175bSOded Gabbay cprop->next_sob_group_val[stream],
1248e65e175bSOded Gabbay master_monitor, queue_id);
1249e65e175bSOded Gabbay
1250e65e175bSOded Gabbay wait_prop.sob_base = master_sob_base;
1251e65e175bSOded Gabbay wait_prop.sob_mask = cprop->mstr_sob_mask[1];
1252e65e175bSOded Gabbay wait_prop.mon_id = master_monitor;
1253e65e175bSOded Gabbay wait_prop.size = cb_size;
1254e65e175bSOded Gabbay cb_size += gaudi_gen_wait_cb(hdev, &wait_prop);
1255e65e175bSOded Gabbay }
1256e65e175bSOded Gabbay
gaudi_collective_slave_init_job(struct hl_device * hdev,struct hl_cs_job * job,struct hl_cs_compl * cs_cmpl)1257e65e175bSOded Gabbay static void gaudi_collective_slave_init_job(struct hl_device *hdev,
1258e65e175bSOded Gabbay struct hl_cs_job *job, struct hl_cs_compl *cs_cmpl)
1259e65e175bSOded Gabbay {
1260e65e175bSOded Gabbay struct hl_gen_wait_properties wait_prop;
1261e65e175bSOded Gabbay struct hl_sync_stream_properties *prop;
1262e65e175bSOded Gabbay u32 queue_id, cb_size = 0;
1263e65e175bSOded Gabbay
1264e65e175bSOded Gabbay queue_id = job->hw_queue_id;
1265e65e175bSOded Gabbay prop = &hdev->kernel_queues[queue_id].sync_stream_prop;
1266e65e175bSOded Gabbay
1267e65e175bSOded Gabbay if (job->cs->encaps_signals) {
1268e65e175bSOded Gabbay /* use the encaps signal handle store earlier in the flow
1269e65e175bSOded Gabbay * and set the SOB information from the encaps
1270e65e175bSOded Gabbay * signals handle
1271e65e175bSOded Gabbay */
1272e65e175bSOded Gabbay hl_hw_queue_encaps_sig_set_sob_info(hdev, job->cs, job,
1273e65e175bSOded Gabbay cs_cmpl);
1274e65e175bSOded Gabbay
1275e65e175bSOded Gabbay dev_dbg(hdev->dev, "collective wait: Sequence %llu found, sob_id: %u, wait for sob_val: %u\n",
1276e65e175bSOded Gabbay job->cs->sequence,
1277e65e175bSOded Gabbay cs_cmpl->hw_sob->sob_id,
1278e65e175bSOded Gabbay cs_cmpl->sob_val);
1279e65e175bSOded Gabbay }
1280e65e175bSOded Gabbay
1281e65e175bSOded Gabbay /* Add to wait CBs using slave monitor */
1282e65e175bSOded Gabbay wait_prop.data = (void *) job->user_cb;
1283e65e175bSOded Gabbay wait_prop.sob_base = cs_cmpl->hw_sob->sob_id;
1284e65e175bSOded Gabbay wait_prop.sob_mask = 0x1;
1285e65e175bSOded Gabbay wait_prop.sob_val = cs_cmpl->sob_val;
1286e65e175bSOded Gabbay wait_prop.mon_id = prop->collective_slave_mon_id;
1287e65e175bSOded Gabbay wait_prop.q_idx = queue_id;
1288e65e175bSOded Gabbay wait_prop.size = cb_size;
1289e65e175bSOded Gabbay
1290e65e175bSOded Gabbay dev_dbg(hdev->dev,
1291e65e175bSOded Gabbay "Generate slave wait CB, sob %d, val:%x, mon %d, q %d\n",
1292e65e175bSOded Gabbay cs_cmpl->hw_sob->sob_id, cs_cmpl->sob_val,
1293e65e175bSOded Gabbay prop->collective_slave_mon_id, queue_id);
1294e65e175bSOded Gabbay
1295e65e175bSOded Gabbay cb_size += gaudi_gen_wait_cb(hdev, &wait_prop);
1296e65e175bSOded Gabbay
1297e65e175bSOded Gabbay dev_dbg(hdev->dev,
1298e65e175bSOded Gabbay "generate signal CB, sob_id: %d, sob val: 1, q_idx: %d\n",
1299e65e175bSOded Gabbay prop->collective_sob_id, queue_id);
1300e65e175bSOded Gabbay
1301e65e175bSOded Gabbay cb_size += gaudi_gen_signal_cb(hdev, job->user_cb,
1302e65e175bSOded Gabbay prop->collective_sob_id, cb_size, false);
1303e65e175bSOded Gabbay }
1304e65e175bSOded Gabbay
gaudi_collective_wait_init_cs(struct hl_cs * cs)1305e65e175bSOded Gabbay static int gaudi_collective_wait_init_cs(struct hl_cs *cs)
1306e65e175bSOded Gabbay {
1307e65e175bSOded Gabbay struct hl_cs_compl *signal_cs_cmpl =
1308e65e175bSOded Gabbay container_of(cs->signal_fence, struct hl_cs_compl, base_fence);
1309e65e175bSOded Gabbay struct hl_cs_compl *cs_cmpl =
1310e65e175bSOded Gabbay container_of(cs->fence, struct hl_cs_compl, base_fence);
1311e65e175bSOded Gabbay struct hl_cs_encaps_sig_handle *handle = cs->encaps_sig_hdl;
1312e65e175bSOded Gabbay struct gaudi_collective_properties *cprop;
1313e65e175bSOded Gabbay u32 stream, queue_id, sob_group_offset;
1314e65e175bSOded Gabbay struct gaudi_device *gaudi;
1315e65e175bSOded Gabbay struct hl_device *hdev;
1316e65e175bSOded Gabbay struct hl_cs_job *job;
1317e65e175bSOded Gabbay struct hl_ctx *ctx;
1318e65e175bSOded Gabbay
1319e65e175bSOded Gabbay ctx = cs->ctx;
1320e65e175bSOded Gabbay hdev = ctx->hdev;
1321e65e175bSOded Gabbay gaudi = hdev->asic_specific;
1322e65e175bSOded Gabbay cprop = &gaudi->collective_props;
1323e65e175bSOded Gabbay
1324e65e175bSOded Gabbay if (cs->encaps_signals) {
1325e65e175bSOded Gabbay cs_cmpl->hw_sob = handle->hw_sob;
1326e65e175bSOded Gabbay /* at this checkpoint we only need the hw_sob pointer
1327e65e175bSOded Gabbay * for the completion check before start going over the jobs
1328e65e175bSOded Gabbay * of the master/slaves, the sob_value will be taken later on
1329e65e175bSOded Gabbay * in gaudi_collective_slave_init_job depends on each
1330e65e175bSOded Gabbay * job wait offset value.
1331e65e175bSOded Gabbay */
1332e65e175bSOded Gabbay cs_cmpl->sob_val = 0;
1333e65e175bSOded Gabbay } else {
1334e65e175bSOded Gabbay /* copy the SOB id and value of the signal CS */
1335e65e175bSOded Gabbay cs_cmpl->hw_sob = signal_cs_cmpl->hw_sob;
1336e65e175bSOded Gabbay cs_cmpl->sob_val = signal_cs_cmpl->sob_val;
1337e65e175bSOded Gabbay }
1338e65e175bSOded Gabbay
1339e65e175bSOded Gabbay /* check again if the signal cs already completed.
1340e65e175bSOded Gabbay * if yes then don't send any wait cs since the hw_sob
1341e65e175bSOded Gabbay * could be in reset already. if signal is not completed
1342e65e175bSOded Gabbay * then get refcount to hw_sob to prevent resetting the sob
1343e65e175bSOded Gabbay * while wait cs is not submitted.
1344e65e175bSOded Gabbay * note that this check is protected by two locks,
1345e65e175bSOded Gabbay * hw queue lock and completion object lock,
1346e65e175bSOded Gabbay * and the same completion object lock also protects
1347e65e175bSOded Gabbay * the hw_sob reset handler function.
1348e65e175bSOded Gabbay * The hw_queue lock prevent out of sync of hw_sob
1349e65e175bSOded Gabbay * refcount value, changed by signal/wait flows.
1350e65e175bSOded Gabbay */
1351e65e175bSOded Gabbay spin_lock(&signal_cs_cmpl->lock);
1352e65e175bSOded Gabbay
1353e65e175bSOded Gabbay if (completion_done(&cs->signal_fence->completion)) {
1354e65e175bSOded Gabbay spin_unlock(&signal_cs_cmpl->lock);
1355e65e175bSOded Gabbay return -EINVAL;
1356e65e175bSOded Gabbay }
1357e65e175bSOded Gabbay /* Increment kref since all slave queues are now waiting on it */
1358e65e175bSOded Gabbay kref_get(&cs_cmpl->hw_sob->kref);
1359e65e175bSOded Gabbay
1360e65e175bSOded Gabbay spin_unlock(&signal_cs_cmpl->lock);
1361e65e175bSOded Gabbay
1362e65e175bSOded Gabbay /* Calculate the stream from collective master queue (1st job) */
1363e65e175bSOded Gabbay job = list_first_entry(&cs->job_list, struct hl_cs_job, cs_node);
1364e65e175bSOded Gabbay stream = job->hw_queue_id % 4;
1365e65e175bSOded Gabbay sob_group_offset =
1366e65e175bSOded Gabbay stream * HL_RSVD_SOBS + cprop->curr_sob_group_idx[stream];
1367e65e175bSOded Gabbay
1368e65e175bSOded Gabbay list_for_each_entry(job, &cs->job_list, cs_node) {
1369e65e175bSOded Gabbay queue_id = job->hw_queue_id;
1370e65e175bSOded Gabbay
1371e65e175bSOded Gabbay if (hdev->kernel_queues[queue_id].collective_mode ==
1372e65e175bSOded Gabbay HL_COLLECTIVE_MASTER)
1373e65e175bSOded Gabbay gaudi_collective_master_init_job(hdev, job, stream,
1374e65e175bSOded Gabbay sob_group_offset);
1375e65e175bSOded Gabbay else
1376e65e175bSOded Gabbay gaudi_collective_slave_init_job(hdev, job, cs_cmpl);
1377e65e175bSOded Gabbay }
1378e65e175bSOded Gabbay
1379e65e175bSOded Gabbay cs_cmpl->sob_group = sob_group_offset;
1380e65e175bSOded Gabbay
1381e65e175bSOded Gabbay /* Handle sob group kref and wraparound */
1382e65e175bSOded Gabbay kref_get(&cprop->hw_sob_group[sob_group_offset].kref);
1383e65e175bSOded Gabbay cprop->next_sob_group_val[stream]++;
1384e65e175bSOded Gabbay
1385e65e175bSOded Gabbay if (cprop->next_sob_group_val[stream] == HL_MAX_SOB_VAL) {
1386e65e175bSOded Gabbay /*
1387e65e175bSOded Gabbay * Decrement as we reached the max value.
1388e65e175bSOded Gabbay * The release function won't be called here as we've
1389e65e175bSOded Gabbay * just incremented the refcount.
1390e65e175bSOded Gabbay */
1391e65e175bSOded Gabbay kref_put(&cprop->hw_sob_group[sob_group_offset].kref,
1392e65e175bSOded Gabbay gaudi_sob_group_reset_error);
1393e65e175bSOded Gabbay cprop->next_sob_group_val[stream] = 1;
1394e65e175bSOded Gabbay /* only two SOBs are currently in use */
1395e65e175bSOded Gabbay cprop->curr_sob_group_idx[stream] =
1396e65e175bSOded Gabbay (cprop->curr_sob_group_idx[stream] + 1) &
1397e65e175bSOded Gabbay (HL_RSVD_SOBS - 1);
1398e65e175bSOded Gabbay
1399e65e175bSOded Gabbay gaudi_collective_map_sobs(hdev, stream);
1400e65e175bSOded Gabbay
1401e65e175bSOded Gabbay dev_dbg(hdev->dev, "switched to SOB group %d, stream: %d\n",
1402e65e175bSOded Gabbay cprop->curr_sob_group_idx[stream], stream);
1403e65e175bSOded Gabbay }
1404e65e175bSOded Gabbay
1405e65e175bSOded Gabbay mb();
1406e65e175bSOded Gabbay hl_fence_put(cs->signal_fence);
1407e65e175bSOded Gabbay cs->signal_fence = NULL;
1408e65e175bSOded Gabbay
1409e65e175bSOded Gabbay return 0;
1410e65e175bSOded Gabbay }
1411e65e175bSOded Gabbay
gaudi_get_patched_cb_extra_size(u32 user_cb_size)1412e65e175bSOded Gabbay static u32 gaudi_get_patched_cb_extra_size(u32 user_cb_size)
1413e65e175bSOded Gabbay {
1414e65e175bSOded Gabbay u32 cacheline_end, additional_commands;
1415e65e175bSOded Gabbay
1416e65e175bSOded Gabbay cacheline_end = round_up(user_cb_size, DEVICE_CACHE_LINE_SIZE);
1417e65e175bSOded Gabbay additional_commands = sizeof(struct packet_msg_prot) * 2;
1418e65e175bSOded Gabbay
1419e65e175bSOded Gabbay if (user_cb_size + additional_commands > cacheline_end)
1420e65e175bSOded Gabbay return cacheline_end - user_cb_size + additional_commands;
1421e65e175bSOded Gabbay else
1422e65e175bSOded Gabbay return additional_commands;
1423e65e175bSOded Gabbay }
1424e65e175bSOded Gabbay
gaudi_collective_wait_create_job(struct hl_device * hdev,struct hl_ctx * ctx,struct hl_cs * cs,enum hl_collective_mode mode,u32 queue_id,u32 wait_queue_id,u32 encaps_signal_offset)1425e65e175bSOded Gabbay static int gaudi_collective_wait_create_job(struct hl_device *hdev,
1426e65e175bSOded Gabbay struct hl_ctx *ctx, struct hl_cs *cs,
1427e65e175bSOded Gabbay enum hl_collective_mode mode, u32 queue_id, u32 wait_queue_id,
1428e65e175bSOded Gabbay u32 encaps_signal_offset)
1429e65e175bSOded Gabbay {
1430e65e175bSOded Gabbay struct hw_queue_properties *hw_queue_prop;
1431e65e175bSOded Gabbay struct hl_cs_counters_atomic *cntr;
1432e65e175bSOded Gabbay struct hl_cs_job *job;
1433e65e175bSOded Gabbay struct hl_cb *cb;
1434e65e175bSOded Gabbay u32 cb_size;
1435e65e175bSOded Gabbay bool patched_cb;
1436e65e175bSOded Gabbay
1437e65e175bSOded Gabbay cntr = &hdev->aggregated_cs_counters;
1438e65e175bSOded Gabbay
1439e65e175bSOded Gabbay if (mode == HL_COLLECTIVE_MASTER) {
1440e65e175bSOded Gabbay /* CB size of collective master queue contains
1441e65e175bSOded Gabbay * 4 msg short packets for monitor 1 configuration
1442e65e175bSOded Gabbay * 1 fence packet
1443e65e175bSOded Gabbay * 4 msg short packets for monitor 2 configuration
1444e65e175bSOded Gabbay * 1 fence packet
1445e65e175bSOded Gabbay * 2 msg prot packets for completion and MSI
1446e65e175bSOded Gabbay */
1447e65e175bSOded Gabbay cb_size = sizeof(struct packet_msg_short) * 8 +
1448e65e175bSOded Gabbay sizeof(struct packet_fence) * 2 +
1449e65e175bSOded Gabbay sizeof(struct packet_msg_prot) * 2;
1450e65e175bSOded Gabbay patched_cb = true;
1451e65e175bSOded Gabbay } else {
1452e65e175bSOded Gabbay /* CB size of collective slave queues contains
1453e65e175bSOded Gabbay * 4 msg short packets for monitor configuration
1454e65e175bSOded Gabbay * 1 fence packet
1455e65e175bSOded Gabbay * 1 additional msg short packet for sob signal
1456e65e175bSOded Gabbay */
1457e65e175bSOded Gabbay cb_size = sizeof(struct packet_msg_short) * 5 +
1458e65e175bSOded Gabbay sizeof(struct packet_fence);
1459e65e175bSOded Gabbay patched_cb = false;
1460e65e175bSOded Gabbay }
1461e65e175bSOded Gabbay
1462e65e175bSOded Gabbay hw_queue_prop = &hdev->asic_prop.hw_queues_props[queue_id];
1463e65e175bSOded Gabbay job = hl_cs_allocate_job(hdev, hw_queue_prop->type, true);
1464e65e175bSOded Gabbay if (!job) {
1465e65e175bSOded Gabbay atomic64_inc(&ctx->cs_counters.out_of_mem_drop_cnt);
1466e65e175bSOded Gabbay atomic64_inc(&cntr->out_of_mem_drop_cnt);
1467e65e175bSOded Gabbay dev_err(hdev->dev, "Failed to allocate a new job\n");
1468e65e175bSOded Gabbay return -ENOMEM;
1469e65e175bSOded Gabbay }
1470e65e175bSOded Gabbay
1471e65e175bSOded Gabbay /* Allocate internal mapped CB for non patched CBs */
1472e65e175bSOded Gabbay cb = hl_cb_kernel_create(hdev, cb_size, !patched_cb);
1473e65e175bSOded Gabbay if (!cb) {
1474e65e175bSOded Gabbay atomic64_inc(&ctx->cs_counters.out_of_mem_drop_cnt);
1475e65e175bSOded Gabbay atomic64_inc(&cntr->out_of_mem_drop_cnt);
1476e65e175bSOded Gabbay kfree(job);
1477e65e175bSOded Gabbay return -EFAULT;
1478e65e175bSOded Gabbay }
1479e65e175bSOded Gabbay
1480e65e175bSOded Gabbay job->id = 0;
1481e65e175bSOded Gabbay job->cs = cs;
1482e65e175bSOded Gabbay job->user_cb = cb;
1483e65e175bSOded Gabbay atomic_inc(&job->user_cb->cs_cnt);
1484e65e175bSOded Gabbay job->user_cb_size = cb_size;
1485e65e175bSOded Gabbay job->hw_queue_id = queue_id;
1486e65e175bSOded Gabbay
1487e65e175bSOded Gabbay /* since its guaranteed to have only one chunk in the collective wait
1488e65e175bSOded Gabbay * cs, we can use this chunk to set the encapsulated signal offset
1489e65e175bSOded Gabbay * in the jobs.
1490e65e175bSOded Gabbay */
1491e65e175bSOded Gabbay if (cs->encaps_signals)
1492e65e175bSOded Gabbay job->encaps_sig_wait_offset = encaps_signal_offset;
1493e65e175bSOded Gabbay
1494e65e175bSOded Gabbay /*
1495e65e175bSOded Gabbay * No need in parsing, user CB is the patched CB.
1496e65e175bSOded Gabbay * We call hl_cb_destroy() out of two reasons - we don't need
1497e65e175bSOded Gabbay * the CB in the CB idr anymore and to decrement its refcount as
1498e65e175bSOded Gabbay * it was incremented inside hl_cb_kernel_create().
1499e65e175bSOded Gabbay */
1500e65e175bSOded Gabbay if (patched_cb)
1501e65e175bSOded Gabbay job->patched_cb = job->user_cb;
1502e65e175bSOded Gabbay else
1503e65e175bSOded Gabbay job->patched_cb = NULL;
1504e65e175bSOded Gabbay
1505e65e175bSOded Gabbay job->job_cb_size = job->user_cb_size;
1506e65e175bSOded Gabbay hl_cb_destroy(&hdev->kernel_mem_mgr, cb->buf->handle);
1507e65e175bSOded Gabbay
1508e65e175bSOded Gabbay /* increment refcount as for external queues we get completion */
1509e65e175bSOded Gabbay if (hw_queue_prop->type == QUEUE_TYPE_EXT)
1510e65e175bSOded Gabbay cs_get(cs);
1511e65e175bSOded Gabbay
1512e65e175bSOded Gabbay cs->jobs_in_queue_cnt[job->hw_queue_id]++;
1513e65e175bSOded Gabbay
1514e65e175bSOded Gabbay list_add_tail(&job->cs_node, &cs->job_list);
1515e65e175bSOded Gabbay
1516e65e175bSOded Gabbay hl_debugfs_add_job(hdev, job);
1517e65e175bSOded Gabbay
1518e65e175bSOded Gabbay return 0;
1519e65e175bSOded Gabbay }
1520e65e175bSOded Gabbay
gaudi_collective_wait_create_jobs(struct hl_device * hdev,struct hl_ctx * ctx,struct hl_cs * cs,u32 wait_queue_id,u32 collective_engine_id,u32 encaps_signal_offset)1521e65e175bSOded Gabbay static int gaudi_collective_wait_create_jobs(struct hl_device *hdev,
1522e65e175bSOded Gabbay struct hl_ctx *ctx, struct hl_cs *cs,
1523e65e175bSOded Gabbay u32 wait_queue_id, u32 collective_engine_id,
1524e65e175bSOded Gabbay u32 encaps_signal_offset)
1525e65e175bSOded Gabbay {
1526e65e175bSOded Gabbay struct gaudi_device *gaudi = hdev->asic_specific;
1527e65e175bSOded Gabbay struct hw_queue_properties *hw_queue_prop;
1528e65e175bSOded Gabbay u32 queue_id, collective_queue, num_jobs;
1529e65e175bSOded Gabbay u32 stream, nic_queue, nic_idx = 0;
1530e65e175bSOded Gabbay bool skip;
1531e65e175bSOded Gabbay int i, rc = 0;
1532e65e175bSOded Gabbay
1533e65e175bSOded Gabbay /* Verify wait queue id is configured as master */
1534e65e175bSOded Gabbay hw_queue_prop = &hdev->asic_prop.hw_queues_props[wait_queue_id];
1535e65e175bSOded Gabbay if (!(hw_queue_prop->collective_mode == HL_COLLECTIVE_MASTER)) {
1536e65e175bSOded Gabbay dev_err(hdev->dev,
1537e65e175bSOded Gabbay "Queue %d is not configured as collective master\n",
1538e65e175bSOded Gabbay wait_queue_id);
1539e65e175bSOded Gabbay return -EINVAL;
1540e65e175bSOded Gabbay }
1541e65e175bSOded Gabbay
1542e65e175bSOded Gabbay /* Verify engine id is supported */
1543e65e175bSOded Gabbay if (collective_engine_id != GAUDI_ENGINE_ID_DMA_5 &&
1544e65e175bSOded Gabbay collective_engine_id != GAUDI_ENGINE_ID_TPC_7) {
1545e65e175bSOded Gabbay dev_err(hdev->dev,
1546e65e175bSOded Gabbay "Collective wait does not support engine %u\n",
1547e65e175bSOded Gabbay collective_engine_id);
1548e65e175bSOded Gabbay return -EINVAL;
1549e65e175bSOded Gabbay }
1550e65e175bSOded Gabbay
1551e65e175bSOded Gabbay stream = wait_queue_id % 4;
1552e65e175bSOded Gabbay
1553e65e175bSOded Gabbay if (collective_engine_id == GAUDI_ENGINE_ID_DMA_5)
1554e65e175bSOded Gabbay collective_queue = GAUDI_QUEUE_ID_DMA_5_0 + stream;
1555e65e175bSOded Gabbay else
1556e65e175bSOded Gabbay collective_queue = GAUDI_QUEUE_ID_TPC_7_0 + stream;
1557e65e175bSOded Gabbay
1558e65e175bSOded Gabbay num_jobs = NUMBER_OF_SOBS_IN_GRP + 1;
1559e65e175bSOded Gabbay nic_queue = GAUDI_QUEUE_ID_NIC_0_0 + stream;
1560e65e175bSOded Gabbay
1561e65e175bSOded Gabbay /* First job goes to the collective master queue, it will wait for
1562e65e175bSOded Gabbay * the collective slave queues to finish execution.
1563e65e175bSOded Gabbay * The synchronization is done using two monitors:
1564e65e175bSOded Gabbay * First monitor for NICs 0-7, second monitor for NICs 8-9 and the
1565e65e175bSOded Gabbay * reduction engine (DMA5/TPC7).
1566e65e175bSOded Gabbay *
1567e65e175bSOded Gabbay * Rest of the jobs goes to the collective slave queues which will
1568e65e175bSOded Gabbay * all wait for the user to signal sob 'cs_cmpl->sob_val'.
1569e65e175bSOded Gabbay */
1570e65e175bSOded Gabbay for (i = 0 ; i < num_jobs ; i++) {
1571e65e175bSOded Gabbay if (i == 0) {
1572e65e175bSOded Gabbay queue_id = wait_queue_id;
1573e65e175bSOded Gabbay rc = gaudi_collective_wait_create_job(hdev, ctx, cs,
1574e65e175bSOded Gabbay HL_COLLECTIVE_MASTER, queue_id,
1575e65e175bSOded Gabbay wait_queue_id, encaps_signal_offset);
1576e65e175bSOded Gabbay } else {
1577e65e175bSOded Gabbay if (nic_idx < NIC_NUMBER_OF_ENGINES) {
1578e65e175bSOded Gabbay if (gaudi->hw_cap_initialized &
1579e65e175bSOded Gabbay BIT(HW_CAP_NIC_SHIFT + nic_idx))
1580e65e175bSOded Gabbay skip = false;
1581e65e175bSOded Gabbay else
1582e65e175bSOded Gabbay skip = true;
1583e65e175bSOded Gabbay
1584e65e175bSOded Gabbay queue_id = nic_queue;
1585e65e175bSOded Gabbay nic_queue += 4;
1586e65e175bSOded Gabbay nic_idx++;
1587e65e175bSOded Gabbay
1588e65e175bSOded Gabbay if (skip)
1589e65e175bSOded Gabbay continue;
1590e65e175bSOded Gabbay } else {
1591e65e175bSOded Gabbay queue_id = collective_queue;
1592e65e175bSOded Gabbay }
1593e65e175bSOded Gabbay
1594e65e175bSOded Gabbay rc = gaudi_collective_wait_create_job(hdev, ctx, cs,
1595e65e175bSOded Gabbay HL_COLLECTIVE_SLAVE, queue_id,
1596e65e175bSOded Gabbay wait_queue_id, encaps_signal_offset);
1597e65e175bSOded Gabbay }
1598e65e175bSOded Gabbay
1599e65e175bSOded Gabbay if (rc)
1600e65e175bSOded Gabbay return rc;
1601e65e175bSOded Gabbay }
1602e65e175bSOded Gabbay
1603e65e175bSOded Gabbay return rc;
1604e65e175bSOded Gabbay }
1605e65e175bSOded Gabbay
gaudi_late_init(struct hl_device * hdev)1606e65e175bSOded Gabbay static int gaudi_late_init(struct hl_device *hdev)
1607e65e175bSOded Gabbay {
1608e65e175bSOded Gabbay struct gaudi_device *gaudi = hdev->asic_specific;
1609e65e175bSOded Gabbay int rc;
1610e65e175bSOded Gabbay
1611e65e175bSOded Gabbay rc = gaudi->cpucp_info_get(hdev);
1612e65e175bSOded Gabbay if (rc) {
1613e65e175bSOded Gabbay dev_err(hdev->dev, "Failed to get cpucp info\n");
1614e65e175bSOded Gabbay return rc;
1615e65e175bSOded Gabbay }
1616e65e175bSOded Gabbay
1617e65e175bSOded Gabbay if ((hdev->card_type == cpucp_card_type_pci) &&
1618e65e175bSOded Gabbay (hdev->nic_ports_mask & 0x3)) {
1619e65e175bSOded Gabbay dev_info(hdev->dev,
1620e65e175bSOded Gabbay "PCI card detected, only 8 ports are enabled\n");
1621e65e175bSOded Gabbay hdev->nic_ports_mask &= ~0x3;
1622e65e175bSOded Gabbay
1623e65e175bSOded Gabbay /* Stop and disable unused NIC QMANs */
1624e65e175bSOded Gabbay WREG32(mmNIC0_QM0_GLBL_CFG1, NIC0_QM0_GLBL_CFG1_PQF_STOP_MASK |
1625e65e175bSOded Gabbay NIC0_QM0_GLBL_CFG1_CQF_STOP_MASK |
1626e65e175bSOded Gabbay NIC0_QM0_GLBL_CFG1_CP_STOP_MASK);
1627e65e175bSOded Gabbay
1628e65e175bSOded Gabbay WREG32(mmNIC0_QM1_GLBL_CFG1, NIC0_QM0_GLBL_CFG1_PQF_STOP_MASK |
1629e65e175bSOded Gabbay NIC0_QM0_GLBL_CFG1_CQF_STOP_MASK |
1630e65e175bSOded Gabbay NIC0_QM0_GLBL_CFG1_CP_STOP_MASK);
1631e65e175bSOded Gabbay
1632e65e175bSOded Gabbay WREG32(mmNIC0_QM0_GLBL_CFG0, 0);
1633e65e175bSOded Gabbay WREG32(mmNIC0_QM1_GLBL_CFG0, 0);
1634e65e175bSOded Gabbay
1635e65e175bSOded Gabbay gaudi->hw_cap_initialized &= ~(HW_CAP_NIC0 | HW_CAP_NIC1);
1636e65e175bSOded Gabbay }
1637e65e175bSOded Gabbay
1638e65e175bSOded Gabbay rc = hl_fw_send_pci_access_msg(hdev, CPUCP_PACKET_ENABLE_PCI_ACCESS, 0x0);
1639e65e175bSOded Gabbay if (rc) {
1640e65e175bSOded Gabbay dev_err(hdev->dev, "Failed to enable PCI access from CPU\n");
1641e65e175bSOded Gabbay return rc;
1642e65e175bSOded Gabbay }
1643e65e175bSOded Gabbay
1644e65e175bSOded Gabbay /* Scrub both SRAM and DRAM */
1645e65e175bSOded Gabbay rc = hdev->asic_funcs->scrub_device_mem(hdev);
1646e65e175bSOded Gabbay if (rc)
1647e65e175bSOded Gabbay goto disable_pci_access;
1648e65e175bSOded Gabbay
1649e65e175bSOded Gabbay rc = gaudi_fetch_psoc_frequency(hdev);
1650e65e175bSOded Gabbay if (rc) {
1651e65e175bSOded Gabbay dev_err(hdev->dev, "Failed to fetch psoc frequency\n");
1652e65e175bSOded Gabbay goto disable_pci_access;
1653e65e175bSOded Gabbay }
1654e65e175bSOded Gabbay
1655e65e175bSOded Gabbay rc = gaudi_mmu_clear_pgt_range(hdev);
1656e65e175bSOded Gabbay if (rc) {
1657e65e175bSOded Gabbay dev_err(hdev->dev, "Failed to clear MMU page tables range\n");
1658e65e175bSOded Gabbay goto disable_pci_access;
1659e65e175bSOded Gabbay }
1660e65e175bSOded Gabbay
1661e65e175bSOded Gabbay rc = gaudi_init_tpc_mem(hdev);
1662e65e175bSOded Gabbay if (rc) {
1663e65e175bSOded Gabbay dev_err(hdev->dev, "Failed to initialize TPC memories\n");
1664e65e175bSOded Gabbay goto disable_pci_access;
1665e65e175bSOded Gabbay }
1666e65e175bSOded Gabbay
1667e65e175bSOded Gabbay rc = gaudi_collective_init(hdev);
1668e65e175bSOded Gabbay if (rc) {
1669e65e175bSOded Gabbay dev_err(hdev->dev, "Failed to init collective\n");
1670e65e175bSOded Gabbay goto disable_pci_access;
1671e65e175bSOded Gabbay }
1672e65e175bSOded Gabbay
1673e65e175bSOded Gabbay /* We only support a single ASID for the user, so for the sake of optimization, just
1674e65e175bSOded Gabbay * initialize the ASID one time during device initialization with the fixed value of 1
1675e65e175bSOded Gabbay */
1676e65e175bSOded Gabbay gaudi_mmu_prepare(hdev, 1);
1677e65e175bSOded Gabbay
1678e65e175bSOded Gabbay hl_fw_set_pll_profile(hdev);
1679e65e175bSOded Gabbay
1680e65e175bSOded Gabbay return 0;
1681e65e175bSOded Gabbay
1682e65e175bSOded Gabbay disable_pci_access:
1683e65e175bSOded Gabbay hl_fw_send_pci_access_msg(hdev, CPUCP_PACKET_DISABLE_PCI_ACCESS, 0x0);
1684e65e175bSOded Gabbay
1685e65e175bSOded Gabbay return rc;
1686e65e175bSOded Gabbay }
1687e65e175bSOded Gabbay
gaudi_late_fini(struct hl_device * hdev)1688e65e175bSOded Gabbay static void gaudi_late_fini(struct hl_device *hdev)
1689e65e175bSOded Gabbay {
1690e65e175bSOded Gabbay hl_hwmon_release_resources(hdev);
1691e65e175bSOded Gabbay }
1692e65e175bSOded Gabbay
gaudi_alloc_cpu_accessible_dma_mem(struct hl_device * hdev)1693e65e175bSOded Gabbay static int gaudi_alloc_cpu_accessible_dma_mem(struct hl_device *hdev)
1694e65e175bSOded Gabbay {
1695e65e175bSOded Gabbay dma_addr_t dma_addr_arr[GAUDI_ALLOC_CPU_MEM_RETRY_CNT] = {}, end_addr;
1696e65e175bSOded Gabbay void *virt_addr_arr[GAUDI_ALLOC_CPU_MEM_RETRY_CNT] = {};
1697e65e175bSOded Gabbay int i, j, rc = 0;
1698e65e175bSOded Gabbay
1699e65e175bSOded Gabbay /*
1700e65e175bSOded Gabbay * The device CPU works with 40-bits addresses, while bit 39 must be set
1701e65e175bSOded Gabbay * to '1' when accessing the host.
1702e65e175bSOded Gabbay * Bits 49:39 of the full host address are saved for a later
1703e65e175bSOded Gabbay * configuration of the HW to perform extension to 50 bits.
1704e65e175bSOded Gabbay * Because there is a single HW register that holds the extension bits,
1705e65e175bSOded Gabbay * these bits must be identical in all allocated range.
1706e65e175bSOded Gabbay */
1707e65e175bSOded Gabbay
1708e65e175bSOded Gabbay for (i = 0 ; i < GAUDI_ALLOC_CPU_MEM_RETRY_CNT ; i++) {
1709e65e175bSOded Gabbay virt_addr_arr[i] = hl_asic_dma_alloc_coherent(hdev, HL_CPU_ACCESSIBLE_MEM_SIZE,
1710e65e175bSOded Gabbay &dma_addr_arr[i],
1711e65e175bSOded Gabbay GFP_KERNEL | __GFP_ZERO);
1712e65e175bSOded Gabbay if (!virt_addr_arr[i]) {
1713e65e175bSOded Gabbay rc = -ENOMEM;
1714e65e175bSOded Gabbay goto free_dma_mem_arr;
1715e65e175bSOded Gabbay }
1716e65e175bSOded Gabbay
1717e65e175bSOded Gabbay end_addr = dma_addr_arr[i] + HL_CPU_ACCESSIBLE_MEM_SIZE - 1;
1718e65e175bSOded Gabbay if (GAUDI_CPU_PCI_MSB_ADDR(dma_addr_arr[i]) ==
1719e65e175bSOded Gabbay GAUDI_CPU_PCI_MSB_ADDR(end_addr))
1720e65e175bSOded Gabbay break;
1721e65e175bSOded Gabbay }
1722e65e175bSOded Gabbay
1723e65e175bSOded Gabbay if (i == GAUDI_ALLOC_CPU_MEM_RETRY_CNT) {
1724e65e175bSOded Gabbay dev_err(hdev->dev,
1725e65e175bSOded Gabbay "MSB of CPU accessible DMA memory are not identical in all range\n");
1726e65e175bSOded Gabbay rc = -EFAULT;
1727e65e175bSOded Gabbay goto free_dma_mem_arr;
1728e65e175bSOded Gabbay }
1729e65e175bSOded Gabbay
1730e65e175bSOded Gabbay hdev->cpu_accessible_dma_mem = virt_addr_arr[i];
1731e65e175bSOded Gabbay hdev->cpu_accessible_dma_address = dma_addr_arr[i];
1732e65e175bSOded Gabbay hdev->cpu_pci_msb_addr =
1733e65e175bSOded Gabbay GAUDI_CPU_PCI_MSB_ADDR(hdev->cpu_accessible_dma_address);
1734e65e175bSOded Gabbay
1735e65e175bSOded Gabbay if (!hdev->asic_prop.fw_security_enabled)
1736e65e175bSOded Gabbay GAUDI_PCI_TO_CPU_ADDR(hdev->cpu_accessible_dma_address);
1737e65e175bSOded Gabbay
1738e65e175bSOded Gabbay free_dma_mem_arr:
1739e65e175bSOded Gabbay for (j = 0 ; j < i ; j++)
1740e65e175bSOded Gabbay hl_asic_dma_free_coherent(hdev, HL_CPU_ACCESSIBLE_MEM_SIZE, virt_addr_arr[j],
1741e65e175bSOded Gabbay dma_addr_arr[j]);
1742e65e175bSOded Gabbay
1743e65e175bSOded Gabbay return rc;
1744e65e175bSOded Gabbay }
1745e65e175bSOded Gabbay
gaudi_free_internal_qmans_pq_mem(struct hl_device * hdev)1746e65e175bSOded Gabbay static void gaudi_free_internal_qmans_pq_mem(struct hl_device *hdev)
1747e65e175bSOded Gabbay {
1748e65e175bSOded Gabbay struct gaudi_device *gaudi = hdev->asic_specific;
1749e65e175bSOded Gabbay struct gaudi_internal_qman_info *q;
1750e65e175bSOded Gabbay u32 i;
1751e65e175bSOded Gabbay
1752e65e175bSOded Gabbay for (i = 0 ; i < GAUDI_QUEUE_ID_SIZE ; i++) {
1753e65e175bSOded Gabbay q = &gaudi->internal_qmans[i];
1754e65e175bSOded Gabbay if (!q->pq_kernel_addr)
1755e65e175bSOded Gabbay continue;
1756e65e175bSOded Gabbay hl_asic_dma_free_coherent(hdev, q->pq_size, q->pq_kernel_addr, q->pq_dma_addr);
1757e65e175bSOded Gabbay }
1758e65e175bSOded Gabbay }
1759e65e175bSOded Gabbay
gaudi_alloc_internal_qmans_pq_mem(struct hl_device * hdev)1760e65e175bSOded Gabbay static int gaudi_alloc_internal_qmans_pq_mem(struct hl_device *hdev)
1761e65e175bSOded Gabbay {
1762e65e175bSOded Gabbay struct gaudi_device *gaudi = hdev->asic_specific;
1763e65e175bSOded Gabbay struct gaudi_internal_qman_info *q;
1764e65e175bSOded Gabbay int rc, i;
1765e65e175bSOded Gabbay
1766e65e175bSOded Gabbay for (i = 0 ; i < GAUDI_QUEUE_ID_SIZE ; i++) {
1767e65e175bSOded Gabbay if (gaudi_queue_type[i] != QUEUE_TYPE_INT)
1768e65e175bSOded Gabbay continue;
1769e65e175bSOded Gabbay
1770e65e175bSOded Gabbay q = &gaudi->internal_qmans[i];
1771e65e175bSOded Gabbay
1772e65e175bSOded Gabbay switch (i) {
1773e65e175bSOded Gabbay case GAUDI_QUEUE_ID_DMA_2_0 ... GAUDI_QUEUE_ID_DMA_7_3:
1774e65e175bSOded Gabbay q->pq_size = HBM_DMA_QMAN_SIZE_IN_BYTES;
1775e65e175bSOded Gabbay break;
1776e65e175bSOded Gabbay case GAUDI_QUEUE_ID_MME_0_0 ... GAUDI_QUEUE_ID_MME_1_3:
1777e65e175bSOded Gabbay q->pq_size = MME_QMAN_SIZE_IN_BYTES;
1778e65e175bSOded Gabbay break;
1779e65e175bSOded Gabbay case GAUDI_QUEUE_ID_TPC_0_0 ... GAUDI_QUEUE_ID_TPC_7_3:
1780e65e175bSOded Gabbay q->pq_size = TPC_QMAN_SIZE_IN_BYTES;
1781e65e175bSOded Gabbay break;
1782e65e175bSOded Gabbay case GAUDI_QUEUE_ID_NIC_0_0 ... GAUDI_QUEUE_ID_NIC_9_3:
1783e65e175bSOded Gabbay q->pq_size = NIC_QMAN_SIZE_IN_BYTES;
1784e65e175bSOded Gabbay break;
1785e65e175bSOded Gabbay default:
1786e65e175bSOded Gabbay dev_err(hdev->dev, "Bad internal queue index %d", i);
1787e65e175bSOded Gabbay rc = -EINVAL;
1788e65e175bSOded Gabbay goto free_internal_qmans_pq_mem;
1789e65e175bSOded Gabbay }
1790e65e175bSOded Gabbay
1791e65e175bSOded Gabbay q->pq_kernel_addr = hl_asic_dma_alloc_coherent(hdev, q->pq_size, &q->pq_dma_addr,
1792e65e175bSOded Gabbay GFP_KERNEL | __GFP_ZERO);
1793e65e175bSOded Gabbay if (!q->pq_kernel_addr) {
1794e65e175bSOded Gabbay rc = -ENOMEM;
1795e65e175bSOded Gabbay goto free_internal_qmans_pq_mem;
1796e65e175bSOded Gabbay }
1797e65e175bSOded Gabbay }
1798e65e175bSOded Gabbay
1799e65e175bSOded Gabbay return 0;
1800e65e175bSOded Gabbay
1801e65e175bSOded Gabbay free_internal_qmans_pq_mem:
1802e65e175bSOded Gabbay gaudi_free_internal_qmans_pq_mem(hdev);
1803e65e175bSOded Gabbay return rc;
1804e65e175bSOded Gabbay }
1805e65e175bSOded Gabbay
gaudi_set_pci_memory_regions(struct hl_device * hdev)1806e65e175bSOded Gabbay static void gaudi_set_pci_memory_regions(struct hl_device *hdev)
1807e65e175bSOded Gabbay {
1808e65e175bSOded Gabbay struct asic_fixed_properties *prop = &hdev->asic_prop;
1809e65e175bSOded Gabbay struct pci_mem_region *region;
1810e65e175bSOded Gabbay
1811e65e175bSOded Gabbay /* CFG */
1812e65e175bSOded Gabbay region = &hdev->pci_mem_region[PCI_REGION_CFG];
1813e65e175bSOded Gabbay region->region_base = CFG_BASE;
1814e65e175bSOded Gabbay region->region_size = CFG_SIZE;
1815e65e175bSOded Gabbay region->offset_in_bar = CFG_BASE - SPI_FLASH_BASE_ADDR;
1816e65e175bSOded Gabbay region->bar_size = CFG_BAR_SIZE;
1817e65e175bSOded Gabbay region->bar_id = CFG_BAR_ID;
1818e65e175bSOded Gabbay region->used = 1;
1819e65e175bSOded Gabbay
1820e65e175bSOded Gabbay /* SRAM */
1821e65e175bSOded Gabbay region = &hdev->pci_mem_region[PCI_REGION_SRAM];
1822e65e175bSOded Gabbay region->region_base = SRAM_BASE_ADDR;
1823e65e175bSOded Gabbay region->region_size = SRAM_SIZE;
1824e65e175bSOded Gabbay region->offset_in_bar = 0;
1825e65e175bSOded Gabbay region->bar_size = SRAM_BAR_SIZE;
1826e65e175bSOded Gabbay region->bar_id = SRAM_BAR_ID;
1827e65e175bSOded Gabbay region->used = 1;
1828e65e175bSOded Gabbay
1829e65e175bSOded Gabbay /* DRAM */
1830e65e175bSOded Gabbay region = &hdev->pci_mem_region[PCI_REGION_DRAM];
1831e65e175bSOded Gabbay region->region_base = DRAM_PHYS_BASE;
1832e65e175bSOded Gabbay region->region_size = hdev->asic_prop.dram_size;
1833e65e175bSOded Gabbay region->offset_in_bar = 0;
1834e65e175bSOded Gabbay region->bar_size = prop->dram_pci_bar_size;
1835e65e175bSOded Gabbay region->bar_id = HBM_BAR_ID;
1836e65e175bSOded Gabbay region->used = 1;
1837e65e175bSOded Gabbay
1838e65e175bSOded Gabbay /* SP SRAM */
1839e65e175bSOded Gabbay region = &hdev->pci_mem_region[PCI_REGION_SP_SRAM];
1840e65e175bSOded Gabbay region->region_base = PSOC_SCRATCHPAD_ADDR;
1841e65e175bSOded Gabbay region->region_size = PSOC_SCRATCHPAD_SIZE;
1842e65e175bSOded Gabbay region->offset_in_bar = PSOC_SCRATCHPAD_ADDR - SPI_FLASH_BASE_ADDR;
1843e65e175bSOded Gabbay region->bar_size = CFG_BAR_SIZE;
1844e65e175bSOded Gabbay region->bar_id = CFG_BAR_ID;
1845e65e175bSOded Gabbay region->used = 1;
1846e65e175bSOded Gabbay }
1847e65e175bSOded Gabbay
gaudi_sw_init(struct hl_device * hdev)1848e65e175bSOded Gabbay static int gaudi_sw_init(struct hl_device *hdev)
1849e65e175bSOded Gabbay {
1850e65e175bSOded Gabbay struct gaudi_device *gaudi;
1851e65e175bSOded Gabbay u32 i, event_id = 0;
1852e65e175bSOded Gabbay int rc;
1853e65e175bSOded Gabbay
1854e65e175bSOded Gabbay /* Allocate device structure */
1855e65e175bSOded Gabbay gaudi = kzalloc(sizeof(*gaudi), GFP_KERNEL);
1856e65e175bSOded Gabbay if (!gaudi)
1857e65e175bSOded Gabbay return -ENOMEM;
1858e65e175bSOded Gabbay
1859e65e175bSOded Gabbay for (i = 0 ; i < ARRAY_SIZE(gaudi_irq_map_table) ; i++) {
1860e65e175bSOded Gabbay if (gaudi_irq_map_table[i].valid) {
1861e65e175bSOded Gabbay if (event_id == GAUDI_EVENT_SIZE) {
1862e65e175bSOded Gabbay dev_err(hdev->dev,
1863e65e175bSOded Gabbay "Event array exceeds the limit of %u events\n",
1864e65e175bSOded Gabbay GAUDI_EVENT_SIZE);
1865e65e175bSOded Gabbay rc = -EINVAL;
1866e65e175bSOded Gabbay goto free_gaudi_device;
1867e65e175bSOded Gabbay }
1868e65e175bSOded Gabbay
1869e65e175bSOded Gabbay gaudi->events[event_id++] =
1870e65e175bSOded Gabbay gaudi_irq_map_table[i].fc_id;
1871e65e175bSOded Gabbay }
1872e65e175bSOded Gabbay }
1873e65e175bSOded Gabbay
1874e65e175bSOded Gabbay gaudi->cpucp_info_get = gaudi_cpucp_info_get;
1875e65e175bSOded Gabbay
1876e65e175bSOded Gabbay hdev->asic_specific = gaudi;
1877e65e175bSOded Gabbay
1878e65e175bSOded Gabbay /* Create DMA pool for small allocations */
1879e65e175bSOded Gabbay hdev->dma_pool = dma_pool_create(dev_name(hdev->dev),
1880e65e175bSOded Gabbay &hdev->pdev->dev, GAUDI_DMA_POOL_BLK_SIZE, 8, 0);
1881e65e175bSOded Gabbay if (!hdev->dma_pool) {
1882e65e175bSOded Gabbay dev_err(hdev->dev, "failed to create DMA pool\n");
1883e65e175bSOded Gabbay rc = -ENOMEM;
1884e65e175bSOded Gabbay goto free_gaudi_device;
1885e65e175bSOded Gabbay }
1886e65e175bSOded Gabbay
1887e65e175bSOded Gabbay rc = gaudi_alloc_cpu_accessible_dma_mem(hdev);
1888e65e175bSOded Gabbay if (rc)
1889e65e175bSOded Gabbay goto free_dma_pool;
1890e65e175bSOded Gabbay
1891e65e175bSOded Gabbay hdev->cpu_accessible_dma_pool = gen_pool_create(ilog2(32), -1);
1892e65e175bSOded Gabbay if (!hdev->cpu_accessible_dma_pool) {
1893e65e175bSOded Gabbay dev_err(hdev->dev,
1894e65e175bSOded Gabbay "Failed to create CPU accessible DMA pool\n");
1895e65e175bSOded Gabbay rc = -ENOMEM;
1896e65e175bSOded Gabbay goto free_cpu_dma_mem;
1897e65e175bSOded Gabbay }
1898e65e175bSOded Gabbay
1899e65e175bSOded Gabbay rc = gen_pool_add(hdev->cpu_accessible_dma_pool,
1900e65e175bSOded Gabbay (uintptr_t) hdev->cpu_accessible_dma_mem,
1901e65e175bSOded Gabbay HL_CPU_ACCESSIBLE_MEM_SIZE, -1);
1902e65e175bSOded Gabbay if (rc) {
1903e65e175bSOded Gabbay dev_err(hdev->dev,
1904e65e175bSOded Gabbay "Failed to add memory to CPU accessible DMA pool\n");
1905e65e175bSOded Gabbay rc = -EFAULT;
1906e65e175bSOded Gabbay goto free_cpu_accessible_dma_pool;
1907e65e175bSOded Gabbay }
1908e65e175bSOded Gabbay
1909e65e175bSOded Gabbay rc = gaudi_alloc_internal_qmans_pq_mem(hdev);
1910e65e175bSOded Gabbay if (rc)
1911e65e175bSOded Gabbay goto free_cpu_accessible_dma_pool;
1912e65e175bSOded Gabbay
1913e65e175bSOded Gabbay spin_lock_init(&gaudi->hw_queues_lock);
1914e65e175bSOded Gabbay
1915e65e175bSOded Gabbay hdev->supports_sync_stream = true;
1916e65e175bSOded Gabbay hdev->supports_coresight = true;
1917e65e175bSOded Gabbay hdev->supports_staged_submission = true;
1918e65e175bSOded Gabbay hdev->supports_wait_for_multi_cs = true;
1919e65e175bSOded Gabbay
1920e65e175bSOded Gabbay hdev->asic_funcs->set_pci_memory_regions(hdev);
1921e65e175bSOded Gabbay hdev->stream_master_qid_arr =
1922e65e175bSOded Gabbay hdev->asic_funcs->get_stream_master_qid_arr();
1923e65e175bSOded Gabbay hdev->stream_master_qid_arr_size = GAUDI_STREAM_MASTER_ARR_SIZE;
1924e65e175bSOded Gabbay
1925e65e175bSOded Gabbay return 0;
1926e65e175bSOded Gabbay
1927e65e175bSOded Gabbay free_cpu_accessible_dma_pool:
1928e65e175bSOded Gabbay gen_pool_destroy(hdev->cpu_accessible_dma_pool);
1929e65e175bSOded Gabbay free_cpu_dma_mem:
1930e65e175bSOded Gabbay if (!hdev->asic_prop.fw_security_enabled)
1931e65e175bSOded Gabbay GAUDI_CPU_TO_PCI_ADDR(hdev->cpu_accessible_dma_address,
1932e65e175bSOded Gabbay hdev->cpu_pci_msb_addr);
1933e65e175bSOded Gabbay hl_asic_dma_free_coherent(hdev, HL_CPU_ACCESSIBLE_MEM_SIZE, hdev->cpu_accessible_dma_mem,
1934e65e175bSOded Gabbay hdev->cpu_accessible_dma_address);
1935e65e175bSOded Gabbay free_dma_pool:
1936e65e175bSOded Gabbay dma_pool_destroy(hdev->dma_pool);
1937e65e175bSOded Gabbay free_gaudi_device:
1938e65e175bSOded Gabbay kfree(gaudi);
1939e65e175bSOded Gabbay return rc;
1940e65e175bSOded Gabbay }
1941e65e175bSOded Gabbay
gaudi_sw_fini(struct hl_device * hdev)1942e65e175bSOded Gabbay static int gaudi_sw_fini(struct hl_device *hdev)
1943e65e175bSOded Gabbay {
1944e65e175bSOded Gabbay struct gaudi_device *gaudi = hdev->asic_specific;
1945e65e175bSOded Gabbay
1946e65e175bSOded Gabbay gaudi_free_internal_qmans_pq_mem(hdev);
1947e65e175bSOded Gabbay
1948e65e175bSOded Gabbay gen_pool_destroy(hdev->cpu_accessible_dma_pool);
1949e65e175bSOded Gabbay
1950e65e175bSOded Gabbay if (!hdev->asic_prop.fw_security_enabled)
1951e65e175bSOded Gabbay GAUDI_CPU_TO_PCI_ADDR(hdev->cpu_accessible_dma_address,
1952e65e175bSOded Gabbay hdev->cpu_pci_msb_addr);
1953e65e175bSOded Gabbay
1954e65e175bSOded Gabbay hl_asic_dma_free_coherent(hdev, HL_CPU_ACCESSIBLE_MEM_SIZE, hdev->cpu_accessible_dma_mem,
1955e65e175bSOded Gabbay hdev->cpu_accessible_dma_address);
1956e65e175bSOded Gabbay
1957e65e175bSOded Gabbay dma_pool_destroy(hdev->dma_pool);
1958e65e175bSOded Gabbay
1959e65e175bSOded Gabbay kfree(gaudi);
1960e65e175bSOded Gabbay
1961e65e175bSOded Gabbay return 0;
1962e65e175bSOded Gabbay }
1963e65e175bSOded Gabbay
gaudi_irq_handler_single(int irq,void * arg)1964e65e175bSOded Gabbay static irqreturn_t gaudi_irq_handler_single(int irq, void *arg)
1965e65e175bSOded Gabbay {
1966e65e175bSOded Gabbay struct hl_device *hdev = arg;
1967e65e175bSOded Gabbay int i;
1968e65e175bSOded Gabbay
1969e65e175bSOded Gabbay if (hdev->disabled)
1970e65e175bSOded Gabbay return IRQ_HANDLED;
1971e65e175bSOded Gabbay
1972e65e175bSOded Gabbay for (i = 0 ; i < hdev->asic_prop.completion_queues_count ; i++)
1973e65e175bSOded Gabbay hl_irq_handler_cq(irq, &hdev->completion_queue[i]);
1974e65e175bSOded Gabbay
1975e65e175bSOded Gabbay hl_irq_handler_eq(irq, &hdev->event_queue);
1976e65e175bSOded Gabbay
1977e65e175bSOded Gabbay return IRQ_HANDLED;
1978e65e175bSOded Gabbay }
1979e65e175bSOded Gabbay
1980e65e175bSOded Gabbay /*
1981e65e175bSOded Gabbay * For backward compatibility, new MSI interrupts should be set after the
1982e65e175bSOded Gabbay * existing CPU and NIC interrupts.
1983e65e175bSOded Gabbay */
gaudi_pci_irq_vector(struct hl_device * hdev,unsigned int nr,bool cpu_eq)1984e65e175bSOded Gabbay static int gaudi_pci_irq_vector(struct hl_device *hdev, unsigned int nr,
1985e65e175bSOded Gabbay bool cpu_eq)
1986e65e175bSOded Gabbay {
1987e65e175bSOded Gabbay int msi_vec;
1988e65e175bSOded Gabbay
1989e65e175bSOded Gabbay if ((nr != GAUDI_EVENT_QUEUE_MSI_IDX) && (cpu_eq))
1990e65e175bSOded Gabbay dev_crit(hdev->dev, "CPU EQ must use IRQ %d\n",
1991e65e175bSOded Gabbay GAUDI_EVENT_QUEUE_MSI_IDX);
1992e65e175bSOded Gabbay
1993e65e175bSOded Gabbay msi_vec = ((nr < GAUDI_EVENT_QUEUE_MSI_IDX) || (cpu_eq)) ? nr :
1994e65e175bSOded Gabbay (nr + NIC_NUMBER_OF_ENGINES + 1);
1995e65e175bSOded Gabbay
1996e65e175bSOded Gabbay return pci_irq_vector(hdev->pdev, msi_vec);
1997e65e175bSOded Gabbay }
1998e65e175bSOded Gabbay
gaudi_enable_msi_single(struct hl_device * hdev)1999e65e175bSOded Gabbay static int gaudi_enable_msi_single(struct hl_device *hdev)
2000e65e175bSOded Gabbay {
2001e65e175bSOded Gabbay int rc, irq;
2002e65e175bSOded Gabbay
2003e65e175bSOded Gabbay dev_dbg(hdev->dev, "Working in single MSI IRQ mode\n");
2004e65e175bSOded Gabbay
2005e65e175bSOded Gabbay irq = gaudi_pci_irq_vector(hdev, 0, false);
2006e65e175bSOded Gabbay rc = request_irq(irq, gaudi_irq_handler_single, 0,
2007e65e175bSOded Gabbay "gaudi single msi", hdev);
2008e65e175bSOded Gabbay if (rc)
2009e65e175bSOded Gabbay dev_err(hdev->dev,
2010e65e175bSOded Gabbay "Failed to request single MSI IRQ\n");
2011e65e175bSOded Gabbay
2012e65e175bSOded Gabbay return rc;
2013e65e175bSOded Gabbay }
2014e65e175bSOded Gabbay
gaudi_enable_msi(struct hl_device * hdev)2015e65e175bSOded Gabbay static int gaudi_enable_msi(struct hl_device *hdev)
2016e65e175bSOded Gabbay {
2017e65e175bSOded Gabbay struct gaudi_device *gaudi = hdev->asic_specific;
2018e65e175bSOded Gabbay int rc;
2019e65e175bSOded Gabbay
2020e65e175bSOded Gabbay if (gaudi->hw_cap_initialized & HW_CAP_MSI)
2021e65e175bSOded Gabbay return 0;
2022e65e175bSOded Gabbay
2023e65e175bSOded Gabbay rc = pci_alloc_irq_vectors(hdev->pdev, 1, 1, PCI_IRQ_MSI);
2024e65e175bSOded Gabbay if (rc < 0) {
2025e65e175bSOded Gabbay dev_err(hdev->dev, "MSI: Failed to enable support %d\n", rc);
2026e65e175bSOded Gabbay return rc;
2027e65e175bSOded Gabbay }
2028e65e175bSOded Gabbay
2029e65e175bSOded Gabbay rc = gaudi_enable_msi_single(hdev);
2030e65e175bSOded Gabbay if (rc)
2031e65e175bSOded Gabbay goto free_pci_irq_vectors;
2032e65e175bSOded Gabbay
2033e65e175bSOded Gabbay gaudi->hw_cap_initialized |= HW_CAP_MSI;
2034e65e175bSOded Gabbay
2035e65e175bSOded Gabbay return 0;
2036e65e175bSOded Gabbay
2037e65e175bSOded Gabbay free_pci_irq_vectors:
2038e65e175bSOded Gabbay pci_free_irq_vectors(hdev->pdev);
2039e65e175bSOded Gabbay return rc;
2040e65e175bSOded Gabbay }
2041e65e175bSOded Gabbay
gaudi_sync_irqs(struct hl_device * hdev)2042e65e175bSOded Gabbay static void gaudi_sync_irqs(struct hl_device *hdev)
2043e65e175bSOded Gabbay {
2044e65e175bSOded Gabbay struct gaudi_device *gaudi = hdev->asic_specific;
2045e65e175bSOded Gabbay
2046e65e175bSOded Gabbay if (!(gaudi->hw_cap_initialized & HW_CAP_MSI))
2047e65e175bSOded Gabbay return;
2048e65e175bSOded Gabbay
2049e65e175bSOded Gabbay /* Wait for all pending IRQs to be finished */
2050e65e175bSOded Gabbay synchronize_irq(gaudi_pci_irq_vector(hdev, 0, false));
2051e65e175bSOded Gabbay }
2052e65e175bSOded Gabbay
gaudi_disable_msi(struct hl_device * hdev)2053e65e175bSOded Gabbay static void gaudi_disable_msi(struct hl_device *hdev)
2054e65e175bSOded Gabbay {
2055e65e175bSOded Gabbay struct gaudi_device *gaudi = hdev->asic_specific;
2056e65e175bSOded Gabbay
2057e65e175bSOded Gabbay if (!(gaudi->hw_cap_initialized & HW_CAP_MSI))
2058e65e175bSOded Gabbay return;
2059e65e175bSOded Gabbay
2060e65e175bSOded Gabbay gaudi_sync_irqs(hdev);
2061e65e175bSOded Gabbay free_irq(gaudi_pci_irq_vector(hdev, 0, false), hdev);
2062e65e175bSOded Gabbay pci_free_irq_vectors(hdev->pdev);
2063e65e175bSOded Gabbay
2064e65e175bSOded Gabbay gaudi->hw_cap_initialized &= ~HW_CAP_MSI;
2065e65e175bSOded Gabbay }
2066e65e175bSOded Gabbay
gaudi_init_scrambler_sram(struct hl_device * hdev)2067e65e175bSOded Gabbay static void gaudi_init_scrambler_sram(struct hl_device *hdev)
2068e65e175bSOded Gabbay {
2069e65e175bSOded Gabbay struct gaudi_device *gaudi = hdev->asic_specific;
2070e65e175bSOded Gabbay
2071e65e175bSOded Gabbay if (hdev->asic_prop.fw_security_enabled)
2072e65e175bSOded Gabbay return;
2073e65e175bSOded Gabbay
2074e65e175bSOded Gabbay if (hdev->asic_prop.fw_app_cpu_boot_dev_sts0 &
2075e65e175bSOded Gabbay CPU_BOOT_DEV_STS0_SRAM_SCR_EN)
2076e65e175bSOded Gabbay return;
2077e65e175bSOded Gabbay
2078e65e175bSOded Gabbay if (gaudi->hw_cap_initialized & HW_CAP_SRAM_SCRAMBLER)
2079e65e175bSOded Gabbay return;
2080e65e175bSOded Gabbay
2081e65e175bSOded Gabbay WREG32(mmNIF_RTR_CTRL_0_SCRAM_SRAM_EN,
2082e65e175bSOded Gabbay 1 << IF_RTR_CTRL_SCRAM_SRAM_EN_VAL_SHIFT);
2083e65e175bSOded Gabbay WREG32(mmNIF_RTR_CTRL_1_SCRAM_SRAM_EN,
2084e65e175bSOded Gabbay 1 << IF_RTR_CTRL_SCRAM_SRAM_EN_VAL_SHIFT);
2085e65e175bSOded Gabbay WREG32(mmNIF_RTR_CTRL_2_SCRAM_SRAM_EN,
2086e65e175bSOded Gabbay 1 << IF_RTR_CTRL_SCRAM_SRAM_EN_VAL_SHIFT);
2087e65e175bSOded Gabbay WREG32(mmNIF_RTR_CTRL_3_SCRAM_SRAM_EN,
2088e65e175bSOded Gabbay 1 << IF_RTR_CTRL_SCRAM_SRAM_EN_VAL_SHIFT);
2089e65e175bSOded Gabbay WREG32(mmNIF_RTR_CTRL_4_SCRAM_SRAM_EN,
2090e65e175bSOded Gabbay 1 << IF_RTR_CTRL_SCRAM_SRAM_EN_VAL_SHIFT);
2091e65e175bSOded Gabbay WREG32(mmNIF_RTR_CTRL_5_SCRAM_SRAM_EN,
2092e65e175bSOded Gabbay 1 << IF_RTR_CTRL_SCRAM_SRAM_EN_VAL_SHIFT);
2093e65e175bSOded Gabbay WREG32(mmNIF_RTR_CTRL_6_SCRAM_SRAM_EN,
2094e65e175bSOded Gabbay 1 << IF_RTR_CTRL_SCRAM_SRAM_EN_VAL_SHIFT);
2095e65e175bSOded Gabbay WREG32(mmNIF_RTR_CTRL_7_SCRAM_SRAM_EN,
2096e65e175bSOded Gabbay 1 << IF_RTR_CTRL_SCRAM_SRAM_EN_VAL_SHIFT);
2097e65e175bSOded Gabbay
2098e65e175bSOded Gabbay WREG32(mmSIF_RTR_CTRL_0_SCRAM_SRAM_EN,
2099e65e175bSOded Gabbay 1 << IF_RTR_CTRL_SCRAM_SRAM_EN_VAL_SHIFT);
2100e65e175bSOded Gabbay WREG32(mmSIF_RTR_CTRL_1_SCRAM_SRAM_EN,
2101e65e175bSOded Gabbay 1 << IF_RTR_CTRL_SCRAM_SRAM_EN_VAL_SHIFT);
2102e65e175bSOded Gabbay WREG32(mmSIF_RTR_CTRL_2_SCRAM_SRAM_EN,
2103e65e175bSOded Gabbay 1 << IF_RTR_CTRL_SCRAM_SRAM_EN_VAL_SHIFT);
2104e65e175bSOded Gabbay WREG32(mmSIF_RTR_CTRL_3_SCRAM_SRAM_EN,
2105e65e175bSOded Gabbay 1 << IF_RTR_CTRL_SCRAM_SRAM_EN_VAL_SHIFT);
2106e65e175bSOded Gabbay WREG32(mmSIF_RTR_CTRL_4_SCRAM_SRAM_EN,
2107e65e175bSOded Gabbay 1 << IF_RTR_CTRL_SCRAM_SRAM_EN_VAL_SHIFT);
2108e65e175bSOded Gabbay WREG32(mmSIF_RTR_CTRL_5_SCRAM_SRAM_EN,
2109e65e175bSOded Gabbay 1 << IF_RTR_CTRL_SCRAM_SRAM_EN_VAL_SHIFT);
2110e65e175bSOded Gabbay WREG32(mmSIF_RTR_CTRL_6_SCRAM_SRAM_EN,
2111e65e175bSOded Gabbay 1 << IF_RTR_CTRL_SCRAM_SRAM_EN_VAL_SHIFT);
2112e65e175bSOded Gabbay WREG32(mmSIF_RTR_CTRL_7_SCRAM_SRAM_EN,
2113e65e175bSOded Gabbay 1 << IF_RTR_CTRL_SCRAM_SRAM_EN_VAL_SHIFT);
2114e65e175bSOded Gabbay
2115e65e175bSOded Gabbay WREG32(mmDMA_IF_E_N_DOWN_CH0_SCRAM_SRAM_EN,
2116e65e175bSOded Gabbay 1 << DMA_IF_DOWN_CHX_SCRAM_SRAM_EN_VAL_SHIFT);
2117e65e175bSOded Gabbay WREG32(mmDMA_IF_E_N_DOWN_CH1_SCRAM_SRAM_EN,
2118e65e175bSOded Gabbay 1 << DMA_IF_DOWN_CHX_SCRAM_SRAM_EN_VAL_SHIFT);
2119e65e175bSOded Gabbay WREG32(mmDMA_IF_E_S_DOWN_CH0_SCRAM_SRAM_EN,
2120e65e175bSOded Gabbay 1 << DMA_IF_DOWN_CHX_SCRAM_SRAM_EN_VAL_SHIFT);
2121e65e175bSOded Gabbay WREG32(mmDMA_IF_E_S_DOWN_CH1_SCRAM_SRAM_EN,
2122e65e175bSOded Gabbay 1 << DMA_IF_DOWN_CHX_SCRAM_SRAM_EN_VAL_SHIFT);
2123e65e175bSOded Gabbay WREG32(mmDMA_IF_W_N_DOWN_CH0_SCRAM_SRAM_EN,
2124e65e175bSOded Gabbay 1 << DMA_IF_DOWN_CHX_SCRAM_SRAM_EN_VAL_SHIFT);
2125e65e175bSOded Gabbay WREG32(mmDMA_IF_W_N_DOWN_CH1_SCRAM_SRAM_EN,
2126e65e175bSOded Gabbay 1 << DMA_IF_DOWN_CHX_SCRAM_SRAM_EN_VAL_SHIFT);
2127e65e175bSOded Gabbay WREG32(mmDMA_IF_W_S_DOWN_CH0_SCRAM_SRAM_EN,
2128e65e175bSOded Gabbay 1 << DMA_IF_DOWN_CHX_SCRAM_SRAM_EN_VAL_SHIFT);
2129e65e175bSOded Gabbay WREG32(mmDMA_IF_W_S_DOWN_CH1_SCRAM_SRAM_EN,
2130e65e175bSOded Gabbay 1 << DMA_IF_DOWN_CHX_SCRAM_SRAM_EN_VAL_SHIFT);
2131e65e175bSOded Gabbay
2132e65e175bSOded Gabbay gaudi->hw_cap_initialized |= HW_CAP_SRAM_SCRAMBLER;
2133e65e175bSOded Gabbay }
2134e65e175bSOded Gabbay
gaudi_init_scrambler_hbm(struct hl_device * hdev)2135e65e175bSOded Gabbay static void gaudi_init_scrambler_hbm(struct hl_device *hdev)
2136e65e175bSOded Gabbay {
2137e65e175bSOded Gabbay struct gaudi_device *gaudi = hdev->asic_specific;
2138e65e175bSOded Gabbay
2139e65e175bSOded Gabbay if (hdev->asic_prop.fw_security_enabled)
2140e65e175bSOded Gabbay return;
2141e65e175bSOded Gabbay
2142e65e175bSOded Gabbay if (hdev->asic_prop.fw_bootfit_cpu_boot_dev_sts0 &
2143e65e175bSOded Gabbay CPU_BOOT_DEV_STS0_DRAM_SCR_EN)
2144e65e175bSOded Gabbay return;
2145e65e175bSOded Gabbay
2146e65e175bSOded Gabbay if (gaudi->hw_cap_initialized & HW_CAP_HBM_SCRAMBLER)
2147e65e175bSOded Gabbay return;
2148e65e175bSOded Gabbay
2149e65e175bSOded Gabbay WREG32(mmNIF_RTR_CTRL_0_SCRAM_HBM_EN,
2150e65e175bSOded Gabbay 1 << IF_RTR_CTRL_SCRAM_HBM_EN_VAL_SHIFT);
2151e65e175bSOded Gabbay WREG32(mmNIF_RTR_CTRL_1_SCRAM_HBM_EN,
2152e65e175bSOded Gabbay 1 << IF_RTR_CTRL_SCRAM_HBM_EN_VAL_SHIFT);
2153e65e175bSOded Gabbay WREG32(mmNIF_RTR_CTRL_2_SCRAM_HBM_EN,
2154e65e175bSOded Gabbay 1 << IF_RTR_CTRL_SCRAM_HBM_EN_VAL_SHIFT);
2155e65e175bSOded Gabbay WREG32(mmNIF_RTR_CTRL_3_SCRAM_HBM_EN,
2156e65e175bSOded Gabbay 1 << IF_RTR_CTRL_SCRAM_HBM_EN_VAL_SHIFT);
2157e65e175bSOded Gabbay WREG32(mmNIF_RTR_CTRL_4_SCRAM_HBM_EN,
2158e65e175bSOded Gabbay 1 << IF_RTR_CTRL_SCRAM_HBM_EN_VAL_SHIFT);
2159e65e175bSOded Gabbay WREG32(mmNIF_RTR_CTRL_5_SCRAM_HBM_EN,
2160e65e175bSOded Gabbay 1 << IF_RTR_CTRL_SCRAM_HBM_EN_VAL_SHIFT);
2161e65e175bSOded Gabbay WREG32(mmNIF_RTR_CTRL_6_SCRAM_HBM_EN,
2162e65e175bSOded Gabbay 1 << IF_RTR_CTRL_SCRAM_HBM_EN_VAL_SHIFT);
2163e65e175bSOded Gabbay WREG32(mmNIF_RTR_CTRL_7_SCRAM_HBM_EN,
2164e65e175bSOded Gabbay 1 << IF_RTR_CTRL_SCRAM_HBM_EN_VAL_SHIFT);
2165e65e175bSOded Gabbay
2166e65e175bSOded Gabbay WREG32(mmSIF_RTR_CTRL_0_SCRAM_HBM_EN,
2167e65e175bSOded Gabbay 1 << IF_RTR_CTRL_SCRAM_HBM_EN_VAL_SHIFT);
2168e65e175bSOded Gabbay WREG32(mmSIF_RTR_CTRL_1_SCRAM_HBM_EN,
2169e65e175bSOded Gabbay 1 << IF_RTR_CTRL_SCRAM_HBM_EN_VAL_SHIFT);
2170e65e175bSOded Gabbay WREG32(mmSIF_RTR_CTRL_2_SCRAM_HBM_EN,
2171e65e175bSOded Gabbay 1 << IF_RTR_CTRL_SCRAM_HBM_EN_VAL_SHIFT);
2172e65e175bSOded Gabbay WREG32(mmSIF_RTR_CTRL_3_SCRAM_HBM_EN,
2173e65e175bSOded Gabbay 1 << IF_RTR_CTRL_SCRAM_HBM_EN_VAL_SHIFT);
2174e65e175bSOded Gabbay WREG32(mmSIF_RTR_CTRL_4_SCRAM_HBM_EN,
2175e65e175bSOded Gabbay 1 << IF_RTR_CTRL_SCRAM_HBM_EN_VAL_SHIFT);
2176e65e175bSOded Gabbay WREG32(mmSIF_RTR_CTRL_5_SCRAM_HBM_EN,
2177e65e175bSOded Gabbay 1 << IF_RTR_CTRL_SCRAM_HBM_EN_VAL_SHIFT);
2178e65e175bSOded Gabbay WREG32(mmSIF_RTR_CTRL_6_SCRAM_HBM_EN,
2179e65e175bSOded Gabbay 1 << IF_RTR_CTRL_SCRAM_HBM_EN_VAL_SHIFT);
2180e65e175bSOded Gabbay WREG32(mmSIF_RTR_CTRL_7_SCRAM_HBM_EN,
2181e65e175bSOded Gabbay 1 << IF_RTR_CTRL_SCRAM_HBM_EN_VAL_SHIFT);
2182e65e175bSOded Gabbay
2183e65e175bSOded Gabbay WREG32(mmDMA_IF_E_N_DOWN_CH0_SCRAM_HBM_EN,
2184e65e175bSOded Gabbay 1 << DMA_IF_DOWN_CHX_SCRAM_HBM_EN_VAL_SHIFT);
2185e65e175bSOded Gabbay WREG32(mmDMA_IF_E_N_DOWN_CH1_SCRAM_HBM_EN,
2186e65e175bSOded Gabbay 1 << DMA_IF_DOWN_CHX_SCRAM_HBM_EN_VAL_SHIFT);
2187e65e175bSOded Gabbay WREG32(mmDMA_IF_E_S_DOWN_CH0_SCRAM_HBM_EN,
2188e65e175bSOded Gabbay 1 << DMA_IF_DOWN_CHX_SCRAM_HBM_EN_VAL_SHIFT);
2189e65e175bSOded Gabbay WREG32(mmDMA_IF_E_S_DOWN_CH1_SCRAM_HBM_EN,
2190e65e175bSOded Gabbay 1 << DMA_IF_DOWN_CHX_SCRAM_HBM_EN_VAL_SHIFT);
2191e65e175bSOded Gabbay WREG32(mmDMA_IF_W_N_DOWN_CH0_SCRAM_HBM_EN,
2192e65e175bSOded Gabbay 1 << DMA_IF_DOWN_CHX_SCRAM_HBM_EN_VAL_SHIFT);
2193e65e175bSOded Gabbay WREG32(mmDMA_IF_W_N_DOWN_CH1_SCRAM_HBM_EN,
2194e65e175bSOded Gabbay 1 << DMA_IF_DOWN_CHX_SCRAM_HBM_EN_VAL_SHIFT);
2195e65e175bSOded Gabbay WREG32(mmDMA_IF_W_S_DOWN_CH0_SCRAM_HBM_EN,
2196e65e175bSOded Gabbay 1 << DMA_IF_DOWN_CHX_SCRAM_HBM_EN_VAL_SHIFT);
2197e65e175bSOded Gabbay WREG32(mmDMA_IF_W_S_DOWN_CH1_SCRAM_HBM_EN,
2198e65e175bSOded Gabbay 1 << DMA_IF_DOWN_CHX_SCRAM_HBM_EN_VAL_SHIFT);
2199e65e175bSOded Gabbay
2200e65e175bSOded Gabbay gaudi->hw_cap_initialized |= HW_CAP_HBM_SCRAMBLER;
2201e65e175bSOded Gabbay }
2202e65e175bSOded Gabbay
gaudi_init_e2e(struct hl_device * hdev)2203e65e175bSOded Gabbay static void gaudi_init_e2e(struct hl_device *hdev)
2204e65e175bSOded Gabbay {
2205e65e175bSOded Gabbay if (hdev->asic_prop.fw_security_enabled)
2206e65e175bSOded Gabbay return;
2207e65e175bSOded Gabbay
2208e65e175bSOded Gabbay if (hdev->asic_prop.fw_bootfit_cpu_boot_dev_sts0 &
2209e65e175bSOded Gabbay CPU_BOOT_DEV_STS0_E2E_CRED_EN)
2210e65e175bSOded Gabbay return;
2211e65e175bSOded Gabbay
2212e65e175bSOded Gabbay WREG32(mmSIF_RTR_CTRL_0_E2E_HBM_WR_SIZE, 247 >> 3);
2213e65e175bSOded Gabbay WREG32(mmSIF_RTR_CTRL_0_E2E_HBM_RD_SIZE, 785 >> 3);
2214e65e175bSOded Gabbay WREG32(mmSIF_RTR_CTRL_0_E2E_PCI_WR_SIZE, 49);
2215e65e175bSOded Gabbay WREG32(mmSIF_RTR_CTRL_0_E2E_PCI_RD_SIZE, 101);
2216e65e175bSOded Gabbay
2217e65e175bSOded Gabbay WREG32(mmSIF_RTR_CTRL_1_E2E_HBM_WR_SIZE, 275 >> 3);
2218e65e175bSOded Gabbay WREG32(mmSIF_RTR_CTRL_1_E2E_HBM_RD_SIZE, 614 >> 3);
2219e65e175bSOded Gabbay WREG32(mmSIF_RTR_CTRL_1_E2E_PCI_WR_SIZE, 1);
2220e65e175bSOded Gabbay WREG32(mmSIF_RTR_CTRL_1_E2E_PCI_RD_SIZE, 39);
2221e65e175bSOded Gabbay
2222e65e175bSOded Gabbay WREG32(mmSIF_RTR_CTRL_2_E2E_HBM_WR_SIZE, 1);
2223e65e175bSOded Gabbay WREG32(mmSIF_RTR_CTRL_2_E2E_HBM_RD_SIZE, 1);
2224e65e175bSOded Gabbay WREG32(mmSIF_RTR_CTRL_2_E2E_PCI_WR_SIZE, 1);
2225e65e175bSOded Gabbay WREG32(mmSIF_RTR_CTRL_2_E2E_PCI_RD_SIZE, 32);
2226e65e175bSOded Gabbay
2227e65e175bSOded Gabbay WREG32(mmSIF_RTR_CTRL_3_E2E_HBM_WR_SIZE, 176 >> 3);
2228e65e175bSOded Gabbay WREG32(mmSIF_RTR_CTRL_3_E2E_HBM_RD_SIZE, 32 >> 3);
2229e65e175bSOded Gabbay WREG32(mmSIF_RTR_CTRL_3_E2E_PCI_WR_SIZE, 19);
2230e65e175bSOded Gabbay WREG32(mmSIF_RTR_CTRL_3_E2E_PCI_RD_SIZE, 32);
2231e65e175bSOded Gabbay
2232e65e175bSOded Gabbay WREG32(mmSIF_RTR_CTRL_4_E2E_HBM_WR_SIZE, 176 >> 3);
2233e65e175bSOded Gabbay WREG32(mmSIF_RTR_CTRL_4_E2E_HBM_RD_SIZE, 32 >> 3);
2234e65e175bSOded Gabbay WREG32(mmSIF_RTR_CTRL_4_E2E_PCI_WR_SIZE, 19);
2235e65e175bSOded Gabbay WREG32(mmSIF_RTR_CTRL_4_E2E_PCI_RD_SIZE, 32);
2236e65e175bSOded Gabbay
2237e65e175bSOded Gabbay WREG32(mmSIF_RTR_CTRL_5_E2E_HBM_WR_SIZE, 1);
2238e65e175bSOded Gabbay WREG32(mmSIF_RTR_CTRL_5_E2E_HBM_RD_SIZE, 1);
2239e65e175bSOded Gabbay WREG32(mmSIF_RTR_CTRL_5_E2E_PCI_WR_SIZE, 1);
2240e65e175bSOded Gabbay WREG32(mmSIF_RTR_CTRL_5_E2E_PCI_RD_SIZE, 32);
2241e65e175bSOded Gabbay
2242e65e175bSOded Gabbay WREG32(mmSIF_RTR_CTRL_6_E2E_HBM_WR_SIZE, 275 >> 3);
2243e65e175bSOded Gabbay WREG32(mmSIF_RTR_CTRL_6_E2E_HBM_RD_SIZE, 614 >> 3);
2244e65e175bSOded Gabbay WREG32(mmSIF_RTR_CTRL_6_E2E_PCI_WR_SIZE, 1);
2245e65e175bSOded Gabbay WREG32(mmSIF_RTR_CTRL_6_E2E_PCI_RD_SIZE, 39);
2246e65e175bSOded Gabbay
2247e65e175bSOded Gabbay WREG32(mmSIF_RTR_CTRL_7_E2E_HBM_WR_SIZE, 297 >> 3);
2248e65e175bSOded Gabbay WREG32(mmSIF_RTR_CTRL_7_E2E_HBM_RD_SIZE, 908 >> 3);
2249e65e175bSOded Gabbay WREG32(mmSIF_RTR_CTRL_7_E2E_PCI_WR_SIZE, 19);
2250e65e175bSOded Gabbay WREG32(mmSIF_RTR_CTRL_7_E2E_PCI_RD_SIZE, 19);
2251e65e175bSOded Gabbay
2252e65e175bSOded Gabbay WREG32(mmNIF_RTR_CTRL_0_E2E_HBM_WR_SIZE, 318 >> 3);
2253e65e175bSOded Gabbay WREG32(mmNIF_RTR_CTRL_0_E2E_HBM_RD_SIZE, 956 >> 3);
2254e65e175bSOded Gabbay WREG32(mmNIF_RTR_CTRL_0_E2E_PCI_WR_SIZE, 79);
2255e65e175bSOded Gabbay WREG32(mmNIF_RTR_CTRL_0_E2E_PCI_RD_SIZE, 163);
2256e65e175bSOded Gabbay
2257e65e175bSOded Gabbay WREG32(mmNIF_RTR_CTRL_1_E2E_HBM_WR_SIZE, 275 >> 3);
2258e65e175bSOded Gabbay WREG32(mmNIF_RTR_CTRL_1_E2E_HBM_RD_SIZE, 614 >> 3);
2259e65e175bSOded Gabbay WREG32(mmNIF_RTR_CTRL_1_E2E_PCI_WR_SIZE, 1);
2260e65e175bSOded Gabbay WREG32(mmNIF_RTR_CTRL_1_E2E_PCI_RD_SIZE, 39);
2261e65e175bSOded Gabbay
2262e65e175bSOded Gabbay WREG32(mmNIF_RTR_CTRL_2_E2E_HBM_WR_SIZE, 1);
2263e65e175bSOded Gabbay WREG32(mmNIF_RTR_CTRL_2_E2E_HBM_RD_SIZE, 1);
2264e65e175bSOded Gabbay WREG32(mmNIF_RTR_CTRL_2_E2E_PCI_WR_SIZE, 1);
2265e65e175bSOded Gabbay WREG32(mmNIF_RTR_CTRL_2_E2E_PCI_RD_SIZE, 32);
2266e65e175bSOded Gabbay
2267e65e175bSOded Gabbay WREG32(mmNIF_RTR_CTRL_3_E2E_HBM_WR_SIZE, 176 >> 3);
2268e65e175bSOded Gabbay WREG32(mmNIF_RTR_CTRL_3_E2E_HBM_RD_SIZE, 32 >> 3);
2269e65e175bSOded Gabbay WREG32(mmNIF_RTR_CTRL_3_E2E_PCI_WR_SIZE, 19);
2270e65e175bSOded Gabbay WREG32(mmNIF_RTR_CTRL_3_E2E_PCI_RD_SIZE, 32);
2271e65e175bSOded Gabbay
2272e65e175bSOded Gabbay WREG32(mmNIF_RTR_CTRL_4_E2E_HBM_WR_SIZE, 176 >> 3);
2273e65e175bSOded Gabbay WREG32(mmNIF_RTR_CTRL_4_E2E_HBM_RD_SIZE, 32 >> 3);
2274e65e175bSOded Gabbay WREG32(mmNIF_RTR_CTRL_4_E2E_PCI_WR_SIZE, 19);
2275e65e175bSOded Gabbay WREG32(mmNIF_RTR_CTRL_4_E2E_PCI_RD_SIZE, 32);
2276e65e175bSOded Gabbay
2277e65e175bSOded Gabbay WREG32(mmNIF_RTR_CTRL_5_E2E_HBM_WR_SIZE, 1);
2278e65e175bSOded Gabbay WREG32(mmNIF_RTR_CTRL_5_E2E_HBM_RD_SIZE, 1);
2279e65e175bSOded Gabbay WREG32(mmNIF_RTR_CTRL_5_E2E_PCI_WR_SIZE, 1);
2280e65e175bSOded Gabbay WREG32(mmNIF_RTR_CTRL_5_E2E_PCI_RD_SIZE, 32);
2281e65e175bSOded Gabbay
2282e65e175bSOded Gabbay WREG32(mmNIF_RTR_CTRL_6_E2E_HBM_WR_SIZE, 275 >> 3);
2283e65e175bSOded Gabbay WREG32(mmNIF_RTR_CTRL_6_E2E_HBM_RD_SIZE, 614 >> 3);
2284e65e175bSOded Gabbay WREG32(mmNIF_RTR_CTRL_6_E2E_PCI_WR_SIZE, 1);
2285e65e175bSOded Gabbay WREG32(mmNIF_RTR_CTRL_6_E2E_PCI_RD_SIZE, 39);
2286e65e175bSOded Gabbay
2287e65e175bSOded Gabbay WREG32(mmNIF_RTR_CTRL_7_E2E_HBM_WR_SIZE, 318 >> 3);
2288e65e175bSOded Gabbay WREG32(mmNIF_RTR_CTRL_7_E2E_HBM_RD_SIZE, 956 >> 3);
2289e65e175bSOded Gabbay WREG32(mmNIF_RTR_CTRL_7_E2E_PCI_WR_SIZE, 79);
2290e65e175bSOded Gabbay WREG32(mmNIF_RTR_CTRL_7_E2E_PCI_RD_SIZE, 79);
2291e65e175bSOded Gabbay
2292e65e175bSOded Gabbay WREG32(mmDMA_IF_E_N_DOWN_CH0_E2E_HBM_WR_SIZE, 344 >> 3);
2293e65e175bSOded Gabbay WREG32(mmDMA_IF_E_N_DOWN_CH0_E2E_HBM_RD_SIZE, 1000 >> 3);
2294e65e175bSOded Gabbay WREG32(mmDMA_IF_E_N_DOWN_CH0_E2E_PCI_WR_SIZE, 162);
2295e65e175bSOded Gabbay WREG32(mmDMA_IF_E_N_DOWN_CH0_E2E_PCI_RD_SIZE, 338);
2296e65e175bSOded Gabbay
2297e65e175bSOded Gabbay WREG32(mmDMA_IF_E_N_DOWN_CH1_E2E_HBM_WR_SIZE, 344 >> 3);
2298e65e175bSOded Gabbay WREG32(mmDMA_IF_E_N_DOWN_CH1_E2E_HBM_RD_SIZE, 1000 >> 3);
2299e65e175bSOded Gabbay WREG32(mmDMA_IF_E_N_DOWN_CH1_E2E_PCI_WR_SIZE, 162);
2300e65e175bSOded Gabbay WREG32(mmDMA_IF_E_N_DOWN_CH1_E2E_PCI_RD_SIZE, 338);
2301e65e175bSOded Gabbay
2302e65e175bSOded Gabbay WREG32(mmDMA_IF_E_S_DOWN_CH0_E2E_HBM_WR_SIZE, 344 >> 3);
2303e65e175bSOded Gabbay WREG32(mmDMA_IF_E_S_DOWN_CH0_E2E_HBM_RD_SIZE, 1000 >> 3);
2304e65e175bSOded Gabbay WREG32(mmDMA_IF_E_S_DOWN_CH0_E2E_PCI_WR_SIZE, 162);
2305e65e175bSOded Gabbay WREG32(mmDMA_IF_E_S_DOWN_CH0_E2E_PCI_RD_SIZE, 338);
2306e65e175bSOded Gabbay
2307e65e175bSOded Gabbay WREG32(mmDMA_IF_E_S_DOWN_CH1_E2E_HBM_WR_SIZE, 344 >> 3);
2308e65e175bSOded Gabbay WREG32(mmDMA_IF_E_S_DOWN_CH1_E2E_HBM_RD_SIZE, 1000 >> 3);
2309e65e175bSOded Gabbay WREG32(mmDMA_IF_E_S_DOWN_CH1_E2E_PCI_WR_SIZE, 162);
2310e65e175bSOded Gabbay WREG32(mmDMA_IF_E_S_DOWN_CH1_E2E_PCI_RD_SIZE, 338);
2311e65e175bSOded Gabbay
2312e65e175bSOded Gabbay WREG32(mmDMA_IF_W_N_DOWN_CH0_E2E_HBM_WR_SIZE, 344 >> 3);
2313e65e175bSOded Gabbay WREG32(mmDMA_IF_W_N_DOWN_CH0_E2E_HBM_RD_SIZE, 1000 >> 3);
2314e65e175bSOded Gabbay WREG32(mmDMA_IF_W_N_DOWN_CH0_E2E_PCI_WR_SIZE, 162);
2315e65e175bSOded Gabbay WREG32(mmDMA_IF_W_N_DOWN_CH0_E2E_PCI_RD_SIZE, 338);
2316e65e175bSOded Gabbay
2317e65e175bSOded Gabbay WREG32(mmDMA_IF_W_N_DOWN_CH1_E2E_HBM_WR_SIZE, 344 >> 3);
2318e65e175bSOded Gabbay WREG32(mmDMA_IF_W_N_DOWN_CH1_E2E_HBM_RD_SIZE, 1000 >> 3);
2319e65e175bSOded Gabbay WREG32(mmDMA_IF_W_N_DOWN_CH1_E2E_PCI_WR_SIZE, 162);
2320e65e175bSOded Gabbay WREG32(mmDMA_IF_W_N_DOWN_CH1_E2E_PCI_RD_SIZE, 338);
2321e65e175bSOded Gabbay
2322e65e175bSOded Gabbay WREG32(mmDMA_IF_W_S_DOWN_CH0_E2E_HBM_WR_SIZE, 344 >> 3);
2323e65e175bSOded Gabbay WREG32(mmDMA_IF_W_S_DOWN_CH0_E2E_HBM_RD_SIZE, 1000 >> 3);
2324e65e175bSOded Gabbay WREG32(mmDMA_IF_W_S_DOWN_CH0_E2E_PCI_WR_SIZE, 162);
2325e65e175bSOded Gabbay WREG32(mmDMA_IF_W_S_DOWN_CH0_E2E_PCI_RD_SIZE, 338);
2326e65e175bSOded Gabbay
2327e65e175bSOded Gabbay WREG32(mmDMA_IF_W_S_DOWN_CH1_E2E_HBM_WR_SIZE, 344 >> 3);
2328e65e175bSOded Gabbay WREG32(mmDMA_IF_W_S_DOWN_CH1_E2E_HBM_RD_SIZE, 1000 >> 3);
2329e65e175bSOded Gabbay WREG32(mmDMA_IF_W_S_DOWN_CH1_E2E_PCI_WR_SIZE, 162);
2330e65e175bSOded Gabbay WREG32(mmDMA_IF_W_S_DOWN_CH1_E2E_PCI_RD_SIZE, 338);
2331e65e175bSOded Gabbay
2332e65e175bSOded Gabbay WREG32(mmSIF_RTR_CTRL_0_E2E_HBM_EN,
2333e65e175bSOded Gabbay 1 << IF_RTR_CTRL_E2E_HBM_EN_VAL_SHIFT);
2334e65e175bSOded Gabbay WREG32(mmSIF_RTR_CTRL_0_E2E_PCI_EN,
2335e65e175bSOded Gabbay 1 << IF_RTR_CTRL_E2E_PCI_EN_VAL_SHIFT);
2336e65e175bSOded Gabbay
2337e65e175bSOded Gabbay WREG32(mmSIF_RTR_CTRL_1_E2E_HBM_EN,
2338e65e175bSOded Gabbay 1 << IF_RTR_CTRL_E2E_HBM_EN_VAL_SHIFT);
2339e65e175bSOded Gabbay WREG32(mmSIF_RTR_CTRL_1_E2E_PCI_EN,
2340e65e175bSOded Gabbay 1 << IF_RTR_CTRL_E2E_PCI_EN_VAL_SHIFT);
2341e65e175bSOded Gabbay
2342e65e175bSOded Gabbay WREG32(mmSIF_RTR_CTRL_2_E2E_HBM_EN,
2343e65e175bSOded Gabbay 1 << IF_RTR_CTRL_E2E_HBM_EN_VAL_SHIFT);
2344e65e175bSOded Gabbay WREG32(mmSIF_RTR_CTRL_2_E2E_PCI_EN,
2345e65e175bSOded Gabbay 1 << IF_RTR_CTRL_E2E_PCI_EN_VAL_SHIFT);
2346e65e175bSOded Gabbay
2347e65e175bSOded Gabbay WREG32(mmSIF_RTR_CTRL_3_E2E_HBM_EN,
2348e65e175bSOded Gabbay 1 << IF_RTR_CTRL_E2E_HBM_EN_VAL_SHIFT);
2349e65e175bSOded Gabbay WREG32(mmSIF_RTR_CTRL_3_E2E_PCI_EN,
2350e65e175bSOded Gabbay 1 << IF_RTR_CTRL_E2E_PCI_EN_VAL_SHIFT);
2351e65e175bSOded Gabbay
2352e65e175bSOded Gabbay WREG32(mmSIF_RTR_CTRL_4_E2E_HBM_EN,
2353e65e175bSOded Gabbay 1 << IF_RTR_CTRL_E2E_HBM_EN_VAL_SHIFT);
2354e65e175bSOded Gabbay WREG32(mmSIF_RTR_CTRL_4_E2E_PCI_EN,
2355e65e175bSOded Gabbay 1 << IF_RTR_CTRL_E2E_PCI_EN_VAL_SHIFT);
2356e65e175bSOded Gabbay
2357e65e175bSOded Gabbay WREG32(mmSIF_RTR_CTRL_5_E2E_HBM_EN,
2358e65e175bSOded Gabbay 1 << IF_RTR_CTRL_E2E_HBM_EN_VAL_SHIFT);
2359e65e175bSOded Gabbay WREG32(mmSIF_RTR_CTRL_5_E2E_PCI_EN,
2360e65e175bSOded Gabbay 1 << IF_RTR_CTRL_E2E_PCI_EN_VAL_SHIFT);
2361e65e175bSOded Gabbay
2362e65e175bSOded Gabbay WREG32(mmSIF_RTR_CTRL_6_E2E_HBM_EN,
2363e65e175bSOded Gabbay 1 << IF_RTR_CTRL_E2E_HBM_EN_VAL_SHIFT);
2364e65e175bSOded Gabbay WREG32(mmSIF_RTR_CTRL_6_E2E_PCI_EN,
2365e65e175bSOded Gabbay 1 << IF_RTR_CTRL_E2E_PCI_EN_VAL_SHIFT);
2366e65e175bSOded Gabbay
2367e65e175bSOded Gabbay WREG32(mmSIF_RTR_CTRL_7_E2E_HBM_EN,
2368e65e175bSOded Gabbay 1 << IF_RTR_CTRL_E2E_HBM_EN_VAL_SHIFT);
2369e65e175bSOded Gabbay WREG32(mmSIF_RTR_CTRL_7_E2E_PCI_EN,
2370e65e175bSOded Gabbay 1 << IF_RTR_CTRL_E2E_PCI_EN_VAL_SHIFT);
2371e65e175bSOded Gabbay
2372e65e175bSOded Gabbay WREG32(mmNIF_RTR_CTRL_0_E2E_HBM_EN,
2373e65e175bSOded Gabbay 1 << IF_RTR_CTRL_E2E_HBM_EN_VAL_SHIFT);
2374e65e175bSOded Gabbay WREG32(mmNIF_RTR_CTRL_0_E2E_PCI_EN,
2375e65e175bSOded Gabbay 1 << IF_RTR_CTRL_E2E_PCI_EN_VAL_SHIFT);
2376e65e175bSOded Gabbay
2377e65e175bSOded Gabbay WREG32(mmNIF_RTR_CTRL_1_E2E_HBM_EN,
2378e65e175bSOded Gabbay 1 << IF_RTR_CTRL_E2E_HBM_EN_VAL_SHIFT);
2379e65e175bSOded Gabbay WREG32(mmNIF_RTR_CTRL_1_E2E_PCI_EN,
2380e65e175bSOded Gabbay 1 << IF_RTR_CTRL_E2E_PCI_EN_VAL_SHIFT);
2381e65e175bSOded Gabbay
2382e65e175bSOded Gabbay WREG32(mmNIF_RTR_CTRL_2_E2E_HBM_EN,
2383e65e175bSOded Gabbay 1 << IF_RTR_CTRL_E2E_HBM_EN_VAL_SHIFT);
2384e65e175bSOded Gabbay WREG32(mmNIF_RTR_CTRL_2_E2E_PCI_EN,
2385e65e175bSOded Gabbay 1 << IF_RTR_CTRL_E2E_PCI_EN_VAL_SHIFT);
2386e65e175bSOded Gabbay
2387e65e175bSOded Gabbay WREG32(mmNIF_RTR_CTRL_3_E2E_HBM_EN,
2388e65e175bSOded Gabbay 1 << IF_RTR_CTRL_E2E_HBM_EN_VAL_SHIFT);
2389e65e175bSOded Gabbay WREG32(mmNIF_RTR_CTRL_3_E2E_PCI_EN,
2390e65e175bSOded Gabbay 1 << IF_RTR_CTRL_E2E_PCI_EN_VAL_SHIFT);
2391e65e175bSOded Gabbay
2392e65e175bSOded Gabbay WREG32(mmNIF_RTR_CTRL_4_E2E_HBM_EN,
2393e65e175bSOded Gabbay 1 << IF_RTR_CTRL_E2E_HBM_EN_VAL_SHIFT);
2394e65e175bSOded Gabbay WREG32(mmNIF_RTR_CTRL_4_E2E_PCI_EN,
2395e65e175bSOded Gabbay 1 << IF_RTR_CTRL_E2E_PCI_EN_VAL_SHIFT);
2396e65e175bSOded Gabbay
2397e65e175bSOded Gabbay WREG32(mmNIF_RTR_CTRL_5_E2E_HBM_EN,
2398e65e175bSOded Gabbay 1 << IF_RTR_CTRL_E2E_HBM_EN_VAL_SHIFT);
2399e65e175bSOded Gabbay WREG32(mmNIF_RTR_CTRL_5_E2E_PCI_EN,
2400e65e175bSOded Gabbay 1 << IF_RTR_CTRL_E2E_PCI_EN_VAL_SHIFT);
2401e65e175bSOded Gabbay
2402e65e175bSOded Gabbay WREG32(mmNIF_RTR_CTRL_6_E2E_HBM_EN,
2403e65e175bSOded Gabbay 1 << IF_RTR_CTRL_E2E_HBM_EN_VAL_SHIFT);
2404e65e175bSOded Gabbay WREG32(mmNIF_RTR_CTRL_6_E2E_PCI_EN,
2405e65e175bSOded Gabbay 1 << IF_RTR_CTRL_E2E_PCI_EN_VAL_SHIFT);
2406e65e175bSOded Gabbay
2407e65e175bSOded Gabbay WREG32(mmNIF_RTR_CTRL_7_E2E_HBM_EN,
2408e65e175bSOded Gabbay 1 << IF_RTR_CTRL_E2E_HBM_EN_VAL_SHIFT);
2409e65e175bSOded Gabbay WREG32(mmNIF_RTR_CTRL_7_E2E_PCI_EN,
2410e65e175bSOded Gabbay 1 << IF_RTR_CTRL_E2E_PCI_EN_VAL_SHIFT);
2411e65e175bSOded Gabbay
2412e65e175bSOded Gabbay WREG32(mmDMA_IF_E_N_DOWN_CH0_E2E_HBM_EN,
2413e65e175bSOded Gabbay 1 << DMA_IF_DOWN_CHX_E2E_HBM_EN_VAL_SHIFT);
2414e65e175bSOded Gabbay WREG32(mmDMA_IF_E_N_DOWN_CH0_E2E_PCI_EN,
2415e65e175bSOded Gabbay 1 << DMA_IF_DOWN_CHX_E2E_PCI_EN_VAL_SHIFT);
2416e65e175bSOded Gabbay
2417e65e175bSOded Gabbay WREG32(mmDMA_IF_E_N_DOWN_CH1_E2E_HBM_EN,
2418e65e175bSOded Gabbay 1 << DMA_IF_DOWN_CHX_E2E_HBM_EN_VAL_SHIFT);
2419e65e175bSOded Gabbay WREG32(mmDMA_IF_E_N_DOWN_CH1_E2E_PCI_EN,
2420e65e175bSOded Gabbay 1 << DMA_IF_DOWN_CHX_E2E_PCI_EN_VAL_SHIFT);
2421e65e175bSOded Gabbay
2422e65e175bSOded Gabbay WREG32(mmDMA_IF_E_S_DOWN_CH0_E2E_HBM_EN,
2423e65e175bSOded Gabbay 1 << DMA_IF_DOWN_CHX_E2E_HBM_EN_VAL_SHIFT);
2424e65e175bSOded Gabbay WREG32(mmDMA_IF_E_S_DOWN_CH0_E2E_PCI_EN,
2425e65e175bSOded Gabbay 1 << DMA_IF_DOWN_CHX_E2E_PCI_EN_VAL_SHIFT);
2426e65e175bSOded Gabbay
2427e65e175bSOded Gabbay WREG32(mmDMA_IF_E_S_DOWN_CH1_E2E_HBM_EN,
2428e65e175bSOded Gabbay 1 << DMA_IF_DOWN_CHX_E2E_HBM_EN_VAL_SHIFT);
2429e65e175bSOded Gabbay WREG32(mmDMA_IF_E_S_DOWN_CH1_E2E_PCI_EN,
2430e65e175bSOded Gabbay 1 << DMA_IF_DOWN_CHX_E2E_PCI_EN_VAL_SHIFT);
2431e65e175bSOded Gabbay
2432e65e175bSOded Gabbay WREG32(mmDMA_IF_W_N_DOWN_CH0_E2E_HBM_EN,
2433e65e175bSOded Gabbay 1 << DMA_IF_DOWN_CHX_E2E_HBM_EN_VAL_SHIFT);
2434e65e175bSOded Gabbay WREG32(mmDMA_IF_W_N_DOWN_CH0_E2E_PCI_EN,
2435e65e175bSOded Gabbay 1 << DMA_IF_DOWN_CHX_E2E_PCI_EN_VAL_SHIFT);
2436e65e175bSOded Gabbay
2437e65e175bSOded Gabbay WREG32(mmDMA_IF_W_N_DOWN_CH1_E2E_HBM_EN,
2438e65e175bSOded Gabbay 1 << DMA_IF_DOWN_CHX_E2E_HBM_EN_VAL_SHIFT);
2439e65e175bSOded Gabbay WREG32(mmDMA_IF_W_N_DOWN_CH1_E2E_PCI_EN,
2440e65e175bSOded Gabbay 1 << DMA_IF_DOWN_CHX_E2E_PCI_EN_VAL_SHIFT);
2441e65e175bSOded Gabbay
2442e65e175bSOded Gabbay WREG32(mmDMA_IF_W_S_DOWN_CH0_E2E_HBM_EN,
2443e65e175bSOded Gabbay 1 << DMA_IF_DOWN_CHX_E2E_HBM_EN_VAL_SHIFT);
2444e65e175bSOded Gabbay WREG32(mmDMA_IF_W_S_DOWN_CH0_E2E_PCI_EN,
2445e65e175bSOded Gabbay 1 << DMA_IF_DOWN_CHX_E2E_PCI_EN_VAL_SHIFT);
2446e65e175bSOded Gabbay
2447e65e175bSOded Gabbay WREG32(mmDMA_IF_W_S_DOWN_CH1_E2E_HBM_EN,
2448e65e175bSOded Gabbay 1 << DMA_IF_DOWN_CHX_E2E_HBM_EN_VAL_SHIFT);
2449e65e175bSOded Gabbay WREG32(mmDMA_IF_W_S_DOWN_CH1_E2E_PCI_EN,
2450e65e175bSOded Gabbay 1 << DMA_IF_DOWN_CHX_E2E_PCI_EN_VAL_SHIFT);
2451e65e175bSOded Gabbay }
2452e65e175bSOded Gabbay
gaudi_init_hbm_cred(struct hl_device * hdev)2453e65e175bSOded Gabbay static void gaudi_init_hbm_cred(struct hl_device *hdev)
2454e65e175bSOded Gabbay {
2455e65e175bSOded Gabbay u32 hbm0_wr, hbm1_wr, hbm0_rd, hbm1_rd;
2456e65e175bSOded Gabbay
2457e65e175bSOded Gabbay if (hdev->asic_prop.fw_security_enabled)
2458e65e175bSOded Gabbay return;
2459e65e175bSOded Gabbay
2460e65e175bSOded Gabbay if (hdev->asic_prop.fw_bootfit_cpu_boot_dev_sts0 &
2461e65e175bSOded Gabbay CPU_BOOT_DEV_STS0_HBM_CRED_EN)
2462e65e175bSOded Gabbay return;
2463e65e175bSOded Gabbay
2464e65e175bSOded Gabbay hbm0_wr = 0x33333333;
2465e65e175bSOded Gabbay hbm0_rd = 0x77777777;
2466e65e175bSOded Gabbay hbm1_wr = 0x55555555;
2467e65e175bSOded Gabbay hbm1_rd = 0xDDDDDDDD;
2468e65e175bSOded Gabbay
2469e65e175bSOded Gabbay WREG32(mmDMA_IF_E_N_HBM0_WR_CRED_CNT, hbm0_wr);
2470e65e175bSOded Gabbay WREG32(mmDMA_IF_E_N_HBM1_WR_CRED_CNT, hbm1_wr);
2471e65e175bSOded Gabbay WREG32(mmDMA_IF_E_N_HBM0_RD_CRED_CNT, hbm0_rd);
2472e65e175bSOded Gabbay WREG32(mmDMA_IF_E_N_HBM1_RD_CRED_CNT, hbm1_rd);
2473e65e175bSOded Gabbay
2474e65e175bSOded Gabbay WREG32(mmDMA_IF_E_S_HBM0_WR_CRED_CNT, hbm0_wr);
2475e65e175bSOded Gabbay WREG32(mmDMA_IF_E_S_HBM1_WR_CRED_CNT, hbm1_wr);
2476e65e175bSOded Gabbay WREG32(mmDMA_IF_E_S_HBM0_RD_CRED_CNT, hbm0_rd);
2477e65e175bSOded Gabbay WREG32(mmDMA_IF_E_S_HBM1_RD_CRED_CNT, hbm1_rd);
2478e65e175bSOded Gabbay
2479e65e175bSOded Gabbay WREG32(mmDMA_IF_W_N_HBM0_WR_CRED_CNT, hbm0_wr);
2480e65e175bSOded Gabbay WREG32(mmDMA_IF_W_N_HBM1_WR_CRED_CNT, hbm1_wr);
2481e65e175bSOded Gabbay WREG32(mmDMA_IF_W_N_HBM0_RD_CRED_CNT, hbm0_rd);
2482e65e175bSOded Gabbay WREG32(mmDMA_IF_W_N_HBM1_RD_CRED_CNT, hbm1_rd);
2483e65e175bSOded Gabbay
2484e65e175bSOded Gabbay WREG32(mmDMA_IF_W_S_HBM0_WR_CRED_CNT, hbm0_wr);
2485e65e175bSOded Gabbay WREG32(mmDMA_IF_W_S_HBM1_WR_CRED_CNT, hbm1_wr);
2486e65e175bSOded Gabbay WREG32(mmDMA_IF_W_S_HBM0_RD_CRED_CNT, hbm0_rd);
2487e65e175bSOded Gabbay WREG32(mmDMA_IF_W_S_HBM1_RD_CRED_CNT, hbm1_rd);
2488e65e175bSOded Gabbay
2489e65e175bSOded Gabbay WREG32(mmDMA_IF_E_N_HBM_CRED_EN_0,
2490e65e175bSOded Gabbay (1 << DMA_IF_HBM_CRED_EN_READ_CREDIT_EN_SHIFT) |
2491e65e175bSOded Gabbay (1 << DMA_IF_HBM_CRED_EN_WRITE_CREDIT_EN_SHIFT));
2492e65e175bSOded Gabbay WREG32(mmDMA_IF_E_S_HBM_CRED_EN_0,
2493e65e175bSOded Gabbay (1 << DMA_IF_HBM_CRED_EN_READ_CREDIT_EN_SHIFT) |
2494e65e175bSOded Gabbay (1 << DMA_IF_HBM_CRED_EN_WRITE_CREDIT_EN_SHIFT));
2495e65e175bSOded Gabbay WREG32(mmDMA_IF_W_N_HBM_CRED_EN_0,
2496e65e175bSOded Gabbay (1 << DMA_IF_HBM_CRED_EN_READ_CREDIT_EN_SHIFT) |
2497e65e175bSOded Gabbay (1 << DMA_IF_HBM_CRED_EN_WRITE_CREDIT_EN_SHIFT));
2498e65e175bSOded Gabbay WREG32(mmDMA_IF_W_S_HBM_CRED_EN_0,
2499e65e175bSOded Gabbay (1 << DMA_IF_HBM_CRED_EN_READ_CREDIT_EN_SHIFT) |
2500e65e175bSOded Gabbay (1 << DMA_IF_HBM_CRED_EN_WRITE_CREDIT_EN_SHIFT));
2501e65e175bSOded Gabbay
2502e65e175bSOded Gabbay WREG32(mmDMA_IF_E_N_HBM_CRED_EN_1,
2503e65e175bSOded Gabbay (1 << DMA_IF_HBM_CRED_EN_READ_CREDIT_EN_SHIFT) |
2504e65e175bSOded Gabbay (1 << DMA_IF_HBM_CRED_EN_WRITE_CREDIT_EN_SHIFT));
2505e65e175bSOded Gabbay WREG32(mmDMA_IF_E_S_HBM_CRED_EN_1,
2506e65e175bSOded Gabbay (1 << DMA_IF_HBM_CRED_EN_READ_CREDIT_EN_SHIFT) |
2507e65e175bSOded Gabbay (1 << DMA_IF_HBM_CRED_EN_WRITE_CREDIT_EN_SHIFT));
2508e65e175bSOded Gabbay WREG32(mmDMA_IF_W_N_HBM_CRED_EN_1,
2509e65e175bSOded Gabbay (1 << DMA_IF_HBM_CRED_EN_READ_CREDIT_EN_SHIFT) |
2510e65e175bSOded Gabbay (1 << DMA_IF_HBM_CRED_EN_WRITE_CREDIT_EN_SHIFT));
2511e65e175bSOded Gabbay WREG32(mmDMA_IF_W_S_HBM_CRED_EN_1,
2512e65e175bSOded Gabbay (1 << DMA_IF_HBM_CRED_EN_READ_CREDIT_EN_SHIFT) |
2513e65e175bSOded Gabbay (1 << DMA_IF_HBM_CRED_EN_WRITE_CREDIT_EN_SHIFT));
2514e65e175bSOded Gabbay }
2515e65e175bSOded Gabbay
gaudi_init_golden_registers(struct hl_device * hdev)2516e65e175bSOded Gabbay static void gaudi_init_golden_registers(struct hl_device *hdev)
2517e65e175bSOded Gabbay {
2518e65e175bSOded Gabbay u32 tpc_offset;
2519e65e175bSOded Gabbay int tpc_id, i;
2520e65e175bSOded Gabbay
2521e65e175bSOded Gabbay gaudi_init_e2e(hdev);
2522e65e175bSOded Gabbay gaudi_init_hbm_cred(hdev);
2523e65e175bSOded Gabbay
2524e65e175bSOded Gabbay for (tpc_id = 0, tpc_offset = 0;
2525e65e175bSOded Gabbay tpc_id < TPC_NUMBER_OF_ENGINES;
2526e65e175bSOded Gabbay tpc_id++, tpc_offset += TPC_CFG_OFFSET) {
2527e65e175bSOded Gabbay /* Mask all arithmetic interrupts from TPC */
2528e65e175bSOded Gabbay WREG32(mmTPC0_CFG_TPC_INTR_MASK + tpc_offset, 0x8FFE);
2529e65e175bSOded Gabbay /* Set 16 cache lines */
2530e65e175bSOded Gabbay WREG32_FIELD(TPC0_CFG_MSS_CONFIG, tpc_offset,
2531e65e175bSOded Gabbay ICACHE_FETCH_LINE_NUM, 2);
2532e65e175bSOded Gabbay }
2533e65e175bSOded Gabbay
2534e65e175bSOded Gabbay /* Make sure 1st 128 bytes in SRAM are 0 for Tensor DMA */
2535e65e175bSOded Gabbay for (i = 0 ; i < 128 ; i += 8)
2536e65e175bSOded Gabbay writeq(0, hdev->pcie_bar[SRAM_BAR_ID] + i);
2537e65e175bSOded Gabbay
2538e65e175bSOded Gabbay WREG32(mmMME0_CTRL_EUS_ROLLUP_CNT_ADD, 3);
2539e65e175bSOded Gabbay WREG32(mmMME1_CTRL_EUS_ROLLUP_CNT_ADD, 3);
2540e65e175bSOded Gabbay WREG32(mmMME2_CTRL_EUS_ROLLUP_CNT_ADD, 3);
2541e65e175bSOded Gabbay WREG32(mmMME3_CTRL_EUS_ROLLUP_CNT_ADD, 3);
2542e65e175bSOded Gabbay }
2543e65e175bSOded Gabbay
gaudi_init_pci_dma_qman(struct hl_device * hdev,int dma_id,int qman_id,dma_addr_t qman_pq_addr)2544e65e175bSOded Gabbay static void gaudi_init_pci_dma_qman(struct hl_device *hdev, int dma_id,
2545e65e175bSOded Gabbay int qman_id, dma_addr_t qman_pq_addr)
2546e65e175bSOded Gabbay {
2547e65e175bSOded Gabbay struct cpu_dyn_regs *dyn_regs =
2548e65e175bSOded Gabbay &hdev->fw_loader.dynamic_loader.comm_desc.cpu_dyn_regs;
2549e65e175bSOded Gabbay u32 mtr_base_en_lo, mtr_base_en_hi, mtr_base_ws_lo, mtr_base_ws_hi;
2550e65e175bSOded Gabbay u32 so_base_en_lo, so_base_en_hi, so_base_ws_lo, so_base_ws_hi;
2551e65e175bSOded Gabbay u32 q_off, dma_qm_offset;
2552e65e175bSOded Gabbay u32 dma_qm_err_cfg, irq_handler_offset;
2553e65e175bSOded Gabbay
2554e65e175bSOded Gabbay dma_qm_offset = dma_id * DMA_QMAN_OFFSET;
2555e65e175bSOded Gabbay
2556e65e175bSOded Gabbay mtr_base_en_lo = lower_32_bits(CFG_BASE +
2557e65e175bSOded Gabbay mmSYNC_MNGR_E_N_SYNC_MNGR_OBJS_MON_PAY_ADDRL_0);
2558e65e175bSOded Gabbay mtr_base_en_hi = upper_32_bits(CFG_BASE +
2559e65e175bSOded Gabbay mmSYNC_MNGR_E_N_SYNC_MNGR_OBJS_MON_PAY_ADDRL_0);
2560e65e175bSOded Gabbay so_base_en_lo = lower_32_bits(CFG_BASE +
2561e65e175bSOded Gabbay mmSYNC_MNGR_E_N_SYNC_MNGR_OBJS_SOB_OBJ_0);
2562e65e175bSOded Gabbay so_base_en_hi = upper_32_bits(CFG_BASE +
2563e65e175bSOded Gabbay mmSYNC_MNGR_E_N_SYNC_MNGR_OBJS_SOB_OBJ_0);
2564e65e175bSOded Gabbay mtr_base_ws_lo = lower_32_bits(CFG_BASE +
2565e65e175bSOded Gabbay mmSYNC_MNGR_W_S_SYNC_MNGR_OBJS_MON_PAY_ADDRL_0);
2566e65e175bSOded Gabbay mtr_base_ws_hi = upper_32_bits(CFG_BASE +
2567e65e175bSOded Gabbay mmSYNC_MNGR_W_S_SYNC_MNGR_OBJS_MON_PAY_ADDRL_0);
2568e65e175bSOded Gabbay so_base_ws_lo = lower_32_bits(CFG_BASE +
2569e65e175bSOded Gabbay mmSYNC_MNGR_W_S_SYNC_MNGR_OBJS_SOB_OBJ_0);
2570e65e175bSOded Gabbay so_base_ws_hi = upper_32_bits(CFG_BASE +
2571e65e175bSOded Gabbay mmSYNC_MNGR_W_S_SYNC_MNGR_OBJS_SOB_OBJ_0);
2572e65e175bSOded Gabbay
2573e65e175bSOded Gabbay q_off = dma_qm_offset + qman_id * 4;
2574e65e175bSOded Gabbay
2575e65e175bSOded Gabbay WREG32(mmDMA0_QM_PQ_BASE_LO_0 + q_off, lower_32_bits(qman_pq_addr));
2576e65e175bSOded Gabbay WREG32(mmDMA0_QM_PQ_BASE_HI_0 + q_off, upper_32_bits(qman_pq_addr));
2577e65e175bSOded Gabbay
2578e65e175bSOded Gabbay WREG32(mmDMA0_QM_PQ_SIZE_0 + q_off, ilog2(HL_QUEUE_LENGTH));
2579e65e175bSOded Gabbay WREG32(mmDMA0_QM_PQ_PI_0 + q_off, 0);
2580e65e175bSOded Gabbay WREG32(mmDMA0_QM_PQ_CI_0 + q_off, 0);
2581e65e175bSOded Gabbay
2582e65e175bSOded Gabbay WREG32(mmDMA0_QM_CP_LDMA_TSIZE_OFFSET_0 + q_off, QMAN_LDMA_SIZE_OFFSET);
2583e65e175bSOded Gabbay WREG32(mmDMA0_QM_CP_LDMA_SRC_BASE_LO_OFFSET_0 + q_off,
2584e65e175bSOded Gabbay QMAN_LDMA_SRC_OFFSET);
2585e65e175bSOded Gabbay WREG32(mmDMA0_QM_CP_LDMA_DST_BASE_LO_OFFSET_0 + q_off,
2586e65e175bSOded Gabbay QMAN_LDMA_DST_OFFSET);
2587e65e175bSOded Gabbay
2588e65e175bSOded Gabbay WREG32(mmDMA0_QM_CP_MSG_BASE0_ADDR_LO_0 + q_off, mtr_base_en_lo);
2589e65e175bSOded Gabbay WREG32(mmDMA0_QM_CP_MSG_BASE0_ADDR_HI_0 + q_off, mtr_base_en_hi);
2590e65e175bSOded Gabbay WREG32(mmDMA0_QM_CP_MSG_BASE1_ADDR_LO_0 + q_off, so_base_en_lo);
2591e65e175bSOded Gabbay WREG32(mmDMA0_QM_CP_MSG_BASE1_ADDR_HI_0 + q_off, so_base_en_hi);
2592e65e175bSOded Gabbay WREG32(mmDMA0_QM_CP_MSG_BASE2_ADDR_LO_0 + q_off, mtr_base_ws_lo);
2593e65e175bSOded Gabbay WREG32(mmDMA0_QM_CP_MSG_BASE2_ADDR_HI_0 + q_off, mtr_base_ws_hi);
2594e65e175bSOded Gabbay WREG32(mmDMA0_QM_CP_MSG_BASE3_ADDR_LO_0 + q_off, so_base_ws_lo);
2595e65e175bSOded Gabbay WREG32(mmDMA0_QM_CP_MSG_BASE3_ADDR_HI_0 + q_off, so_base_ws_hi);
2596e65e175bSOded Gabbay
2597e65e175bSOded Gabbay WREG32(mmDMA0_QM_CP_BARRIER_CFG_0 + q_off, 0x100);
2598e65e175bSOded Gabbay
2599e65e175bSOded Gabbay /* The following configuration is needed only once per QMAN */
2600e65e175bSOded Gabbay if (qman_id == 0) {
2601e65e175bSOded Gabbay irq_handler_offset = hdev->asic_prop.gic_interrupts_enable ?
2602e65e175bSOded Gabbay mmGIC_DISTRIBUTOR__5_GICD_SETSPI_NSR :
2603e65e175bSOded Gabbay le32_to_cpu(dyn_regs->gic_dma_qm_irq_ctrl);
2604e65e175bSOded Gabbay
2605e65e175bSOded Gabbay /* Configure RAZWI IRQ */
2606e65e175bSOded Gabbay dma_qm_err_cfg = PCI_DMA_QMAN_GLBL_ERR_CFG_MSG_EN_MASK;
2607e65e175bSOded Gabbay if (hdev->stop_on_err)
2608e65e175bSOded Gabbay dma_qm_err_cfg |=
2609e65e175bSOded Gabbay PCI_DMA_QMAN_GLBL_ERR_CFG_STOP_ON_ERR_EN_MASK;
2610e65e175bSOded Gabbay
2611e65e175bSOded Gabbay WREG32(mmDMA0_QM_GLBL_ERR_CFG + dma_qm_offset, dma_qm_err_cfg);
2612e65e175bSOded Gabbay
2613e65e175bSOded Gabbay WREG32(mmDMA0_QM_GLBL_ERR_ADDR_LO + dma_qm_offset,
2614e65e175bSOded Gabbay lower_32_bits(CFG_BASE + irq_handler_offset));
2615e65e175bSOded Gabbay WREG32(mmDMA0_QM_GLBL_ERR_ADDR_HI + dma_qm_offset,
2616e65e175bSOded Gabbay upper_32_bits(CFG_BASE + irq_handler_offset));
2617e65e175bSOded Gabbay
2618e65e175bSOded Gabbay WREG32(mmDMA0_QM_GLBL_ERR_WDATA + dma_qm_offset,
2619e65e175bSOded Gabbay gaudi_irq_map_table[GAUDI_EVENT_DMA0_QM].cpu_id +
2620e65e175bSOded Gabbay dma_id);
2621e65e175bSOded Gabbay
2622e65e175bSOded Gabbay WREG32(mmDMA0_QM_ARB_ERR_MSG_EN + dma_qm_offset,
2623e65e175bSOded Gabbay QM_ARB_ERR_MSG_EN_MASK);
2624e65e175bSOded Gabbay
2625e65e175bSOded Gabbay /* Set timeout to maximum */
2626e65e175bSOded Gabbay WREG32(mmDMA0_QM_ARB_SLV_CHOISE_WDT + dma_qm_offset, GAUDI_ARB_WDT_TIMEOUT);
2627e65e175bSOded Gabbay
2628e65e175bSOded Gabbay WREG32(mmDMA0_QM_GLBL_PROT + dma_qm_offset,
2629e65e175bSOded Gabbay QMAN_EXTERNAL_MAKE_TRUSTED);
2630e65e175bSOded Gabbay
2631e65e175bSOded Gabbay WREG32(mmDMA0_QM_GLBL_CFG1 + dma_qm_offset, 0);
2632e65e175bSOded Gabbay }
2633e65e175bSOded Gabbay }
2634e65e175bSOded Gabbay
gaudi_init_dma_core(struct hl_device * hdev,int dma_id)2635e65e175bSOded Gabbay static void gaudi_init_dma_core(struct hl_device *hdev, int dma_id)
2636e65e175bSOded Gabbay {
2637e65e175bSOded Gabbay struct cpu_dyn_regs *dyn_regs =
2638e65e175bSOded Gabbay &hdev->fw_loader.dynamic_loader.comm_desc.cpu_dyn_regs;
2639e65e175bSOded Gabbay u32 dma_err_cfg = 1 << DMA0_CORE_ERR_CFG_ERR_MSG_EN_SHIFT;
2640e65e175bSOded Gabbay u32 dma_offset = dma_id * DMA_CORE_OFFSET;
2641e65e175bSOded Gabbay u32 irq_handler_offset;
2642e65e175bSOded Gabbay
2643e65e175bSOded Gabbay /* Set to maximum possible according to physical size */
2644e65e175bSOded Gabbay WREG32(mmDMA0_CORE_RD_MAX_OUTSTAND + dma_offset, 0);
2645e65e175bSOded Gabbay WREG32(mmDMA0_CORE_RD_MAX_SIZE + dma_offset, 0);
2646e65e175bSOded Gabbay
2647e65e175bSOded Gabbay /* WA for H/W bug H3-2116 */
2648e65e175bSOded Gabbay WREG32(mmDMA0_CORE_LBW_MAX_OUTSTAND + dma_offset, 15);
2649e65e175bSOded Gabbay
2650e65e175bSOded Gabbay /* STOP_ON bit implies no completion to operation in case of RAZWI */
2651e65e175bSOded Gabbay if (hdev->stop_on_err)
2652e65e175bSOded Gabbay dma_err_cfg |= 1 << DMA0_CORE_ERR_CFG_STOP_ON_ERR_SHIFT;
2653e65e175bSOded Gabbay
2654e65e175bSOded Gabbay WREG32(mmDMA0_CORE_ERR_CFG + dma_offset, dma_err_cfg);
2655e65e175bSOded Gabbay
2656e65e175bSOded Gabbay irq_handler_offset = hdev->asic_prop.gic_interrupts_enable ?
2657e65e175bSOded Gabbay mmGIC_DISTRIBUTOR__5_GICD_SETSPI_NSR :
2658e65e175bSOded Gabbay le32_to_cpu(dyn_regs->gic_dma_core_irq_ctrl);
2659e65e175bSOded Gabbay
2660e65e175bSOded Gabbay WREG32(mmDMA0_CORE_ERRMSG_ADDR_LO + dma_offset,
2661e65e175bSOded Gabbay lower_32_bits(CFG_BASE + irq_handler_offset));
2662e65e175bSOded Gabbay WREG32(mmDMA0_CORE_ERRMSG_ADDR_HI + dma_offset,
2663e65e175bSOded Gabbay upper_32_bits(CFG_BASE + irq_handler_offset));
2664e65e175bSOded Gabbay
2665e65e175bSOded Gabbay WREG32(mmDMA0_CORE_ERRMSG_WDATA + dma_offset,
2666e65e175bSOded Gabbay gaudi_irq_map_table[GAUDI_EVENT_DMA0_CORE].cpu_id + dma_id);
2667e65e175bSOded Gabbay WREG32(mmDMA0_CORE_PROT + dma_offset,
2668e65e175bSOded Gabbay 1 << DMA0_CORE_PROT_ERR_VAL_SHIFT);
2669e65e175bSOded Gabbay /* If the channel is secured, it should be in MMU bypass mode */
2670e65e175bSOded Gabbay WREG32(mmDMA0_CORE_SECURE_PROPS + dma_offset,
2671e65e175bSOded Gabbay 1 << DMA0_CORE_SECURE_PROPS_MMBP_SHIFT);
2672e65e175bSOded Gabbay WREG32(mmDMA0_CORE_CFG_0 + dma_offset, 1 << DMA0_CORE_CFG_0_EN_SHIFT);
2673e65e175bSOded Gabbay }
2674e65e175bSOded Gabbay
gaudi_enable_qman(struct hl_device * hdev,int dma_id,u32 enable_mask)2675e65e175bSOded Gabbay static void gaudi_enable_qman(struct hl_device *hdev, int dma_id,
2676e65e175bSOded Gabbay u32 enable_mask)
2677e65e175bSOded Gabbay {
2678e65e175bSOded Gabbay u32 dma_qm_offset = dma_id * DMA_QMAN_OFFSET;
2679e65e175bSOded Gabbay
2680e65e175bSOded Gabbay WREG32(mmDMA0_QM_GLBL_CFG0 + dma_qm_offset, enable_mask);
2681e65e175bSOded Gabbay }
2682e65e175bSOded Gabbay
gaudi_init_pci_dma_qmans(struct hl_device * hdev)2683e65e175bSOded Gabbay static void gaudi_init_pci_dma_qmans(struct hl_device *hdev)
2684e65e175bSOded Gabbay {
2685e65e175bSOded Gabbay struct gaudi_device *gaudi = hdev->asic_specific;
2686e65e175bSOded Gabbay struct hl_hw_queue *q;
2687e65e175bSOded Gabbay int i, j, dma_id, cpu_skip, nic_skip, cq_id = 0, q_idx, msi_vec = 0;
2688e65e175bSOded Gabbay
2689e65e175bSOded Gabbay if (gaudi->hw_cap_initialized & HW_CAP_PCI_DMA)
2690e65e175bSOded Gabbay return;
2691e65e175bSOded Gabbay
2692e65e175bSOded Gabbay for (i = 0 ; i < PCI_DMA_NUMBER_OF_CHNLS ; i++) {
2693e65e175bSOded Gabbay dma_id = gaudi_dma_assignment[i];
2694e65e175bSOded Gabbay /*
2695e65e175bSOded Gabbay * For queues after the CPU Q need to add 1 to get the correct
2696e65e175bSOded Gabbay * queue. In addition, need to add the CPU EQ and NIC IRQs in
2697e65e175bSOded Gabbay * order to get the correct MSI register.
2698e65e175bSOded Gabbay */
2699e65e175bSOded Gabbay if (dma_id > 1) {
2700e65e175bSOded Gabbay cpu_skip = 1;
2701e65e175bSOded Gabbay nic_skip = NIC_NUMBER_OF_ENGINES;
2702e65e175bSOded Gabbay } else {
2703e65e175bSOded Gabbay cpu_skip = 0;
2704e65e175bSOded Gabbay nic_skip = 0;
2705e65e175bSOded Gabbay }
2706e65e175bSOded Gabbay
2707e65e175bSOded Gabbay for (j = 0 ; j < QMAN_STREAMS ; j++) {
2708e65e175bSOded Gabbay q_idx = 4 * dma_id + j + cpu_skip;
2709e65e175bSOded Gabbay q = &hdev->kernel_queues[q_idx];
2710e65e175bSOded Gabbay q->cq_id = cq_id++;
2711e65e175bSOded Gabbay q->msi_vec = nic_skip + cpu_skip + msi_vec++;
2712e65e175bSOded Gabbay gaudi_init_pci_dma_qman(hdev, dma_id, j,
2713e65e175bSOded Gabbay q->bus_address);
2714e65e175bSOded Gabbay }
2715e65e175bSOded Gabbay
2716e65e175bSOded Gabbay gaudi_init_dma_core(hdev, dma_id);
2717e65e175bSOded Gabbay
2718e65e175bSOded Gabbay gaudi_enable_qman(hdev, dma_id, PCI_DMA_QMAN_ENABLE);
2719e65e175bSOded Gabbay }
2720e65e175bSOded Gabbay
2721e65e175bSOded Gabbay gaudi->hw_cap_initialized |= HW_CAP_PCI_DMA;
2722e65e175bSOded Gabbay }
2723e65e175bSOded Gabbay
gaudi_init_hbm_dma_qman(struct hl_device * hdev,int dma_id,int qman_id,u64 qman_base_addr)2724e65e175bSOded Gabbay static void gaudi_init_hbm_dma_qman(struct hl_device *hdev, int dma_id,
2725e65e175bSOded Gabbay int qman_id, u64 qman_base_addr)
2726e65e175bSOded Gabbay {
2727e65e175bSOded Gabbay struct cpu_dyn_regs *dyn_regs =
2728e65e175bSOded Gabbay &hdev->fw_loader.dynamic_loader.comm_desc.cpu_dyn_regs;
2729e65e175bSOded Gabbay u32 mtr_base_en_lo, mtr_base_en_hi, mtr_base_ws_lo, mtr_base_ws_hi;
2730e65e175bSOded Gabbay u32 so_base_en_lo, so_base_en_hi, so_base_ws_lo, so_base_ws_hi;
2731e65e175bSOded Gabbay u32 dma_qm_err_cfg, irq_handler_offset;
2732e65e175bSOded Gabbay u32 q_off, dma_qm_offset;
2733e65e175bSOded Gabbay
2734e65e175bSOded Gabbay dma_qm_offset = dma_id * DMA_QMAN_OFFSET;
2735e65e175bSOded Gabbay
2736e65e175bSOded Gabbay mtr_base_en_lo = lower_32_bits(CFG_BASE +
2737e65e175bSOded Gabbay mmSYNC_MNGR_E_N_SYNC_MNGR_OBJS_MON_PAY_ADDRL_0);
2738e65e175bSOded Gabbay mtr_base_en_hi = upper_32_bits(CFG_BASE +
2739e65e175bSOded Gabbay mmSYNC_MNGR_E_N_SYNC_MNGR_OBJS_MON_PAY_ADDRL_0);
2740e65e175bSOded Gabbay so_base_en_lo = lower_32_bits(CFG_BASE +
2741e65e175bSOded Gabbay mmSYNC_MNGR_E_N_SYNC_MNGR_OBJS_SOB_OBJ_0);
2742e65e175bSOded Gabbay so_base_en_hi = upper_32_bits(CFG_BASE +
2743e65e175bSOded Gabbay mmSYNC_MNGR_E_N_SYNC_MNGR_OBJS_SOB_OBJ_0);
2744e65e175bSOded Gabbay mtr_base_ws_lo = lower_32_bits(CFG_BASE +
2745e65e175bSOded Gabbay mmSYNC_MNGR_W_S_SYNC_MNGR_OBJS_MON_PAY_ADDRL_0);
2746e65e175bSOded Gabbay mtr_base_ws_hi = upper_32_bits(CFG_BASE +
2747e65e175bSOded Gabbay mmSYNC_MNGR_W_S_SYNC_MNGR_OBJS_MON_PAY_ADDRL_0);
2748e65e175bSOded Gabbay so_base_ws_lo = lower_32_bits(CFG_BASE +
2749e65e175bSOded Gabbay mmSYNC_MNGR_W_S_SYNC_MNGR_OBJS_SOB_OBJ_0);
2750e65e175bSOded Gabbay so_base_ws_hi = upper_32_bits(CFG_BASE +
2751e65e175bSOded Gabbay mmSYNC_MNGR_W_S_SYNC_MNGR_OBJS_SOB_OBJ_0);
2752e65e175bSOded Gabbay
2753e65e175bSOded Gabbay q_off = dma_qm_offset + qman_id * 4;
2754e65e175bSOded Gabbay
2755e65e175bSOded Gabbay if (qman_id < 4) {
2756e65e175bSOded Gabbay WREG32(mmDMA0_QM_PQ_BASE_LO_0 + q_off,
2757e65e175bSOded Gabbay lower_32_bits(qman_base_addr));
2758e65e175bSOded Gabbay WREG32(mmDMA0_QM_PQ_BASE_HI_0 + q_off,
2759e65e175bSOded Gabbay upper_32_bits(qman_base_addr));
2760e65e175bSOded Gabbay
2761e65e175bSOded Gabbay WREG32(mmDMA0_QM_PQ_SIZE_0 + q_off, ilog2(HBM_DMA_QMAN_LENGTH));
2762e65e175bSOded Gabbay WREG32(mmDMA0_QM_PQ_PI_0 + q_off, 0);
2763e65e175bSOded Gabbay WREG32(mmDMA0_QM_PQ_CI_0 + q_off, 0);
2764e65e175bSOded Gabbay
2765e65e175bSOded Gabbay WREG32(mmDMA0_QM_CP_LDMA_TSIZE_OFFSET_0 + q_off,
2766e65e175bSOded Gabbay QMAN_CPDMA_SIZE_OFFSET);
2767e65e175bSOded Gabbay WREG32(mmDMA0_QM_CP_LDMA_SRC_BASE_LO_OFFSET_0 + q_off,
2768e65e175bSOded Gabbay QMAN_CPDMA_SRC_OFFSET);
2769e65e175bSOded Gabbay WREG32(mmDMA0_QM_CP_LDMA_DST_BASE_LO_OFFSET_0 + q_off,
2770e65e175bSOded Gabbay QMAN_CPDMA_DST_OFFSET);
2771e65e175bSOded Gabbay } else {
2772e65e175bSOded Gabbay irq_handler_offset = hdev->asic_prop.gic_interrupts_enable ?
2773e65e175bSOded Gabbay mmGIC_DISTRIBUTOR__5_GICD_SETSPI_NSR :
2774e65e175bSOded Gabbay le32_to_cpu(dyn_regs->gic_dma_qm_irq_ctrl);
2775e65e175bSOded Gabbay
2776e65e175bSOded Gabbay WREG32(mmDMA0_QM_CP_LDMA_TSIZE_OFFSET_0 + q_off,
2777e65e175bSOded Gabbay QMAN_LDMA_SIZE_OFFSET);
2778e65e175bSOded Gabbay WREG32(mmDMA0_QM_CP_LDMA_SRC_BASE_LO_OFFSET_0 + q_off,
2779e65e175bSOded Gabbay QMAN_LDMA_SRC_OFFSET);
2780e65e175bSOded Gabbay WREG32(mmDMA0_QM_CP_LDMA_DST_BASE_LO_OFFSET_0 + q_off,
2781e65e175bSOded Gabbay QMAN_LDMA_DST_OFFSET);
2782e65e175bSOded Gabbay
2783e65e175bSOded Gabbay /* Configure RAZWI IRQ */
2784e65e175bSOded Gabbay dma_qm_err_cfg = HBM_DMA_QMAN_GLBL_ERR_CFG_MSG_EN_MASK;
2785e65e175bSOded Gabbay if (hdev->stop_on_err)
2786e65e175bSOded Gabbay dma_qm_err_cfg |=
2787e65e175bSOded Gabbay HBM_DMA_QMAN_GLBL_ERR_CFG_STOP_ON_ERR_EN_MASK;
2788e65e175bSOded Gabbay
2789e65e175bSOded Gabbay WREG32(mmDMA0_QM_GLBL_ERR_CFG + dma_qm_offset, dma_qm_err_cfg);
2790e65e175bSOded Gabbay
2791e65e175bSOded Gabbay WREG32(mmDMA0_QM_GLBL_ERR_ADDR_LO + dma_qm_offset,
2792e65e175bSOded Gabbay lower_32_bits(CFG_BASE + irq_handler_offset));
2793e65e175bSOded Gabbay WREG32(mmDMA0_QM_GLBL_ERR_ADDR_HI + dma_qm_offset,
2794e65e175bSOded Gabbay upper_32_bits(CFG_BASE + irq_handler_offset));
2795e65e175bSOded Gabbay
2796e65e175bSOded Gabbay WREG32(mmDMA0_QM_GLBL_ERR_WDATA + dma_qm_offset,
2797e65e175bSOded Gabbay gaudi_irq_map_table[GAUDI_EVENT_DMA0_QM].cpu_id +
2798e65e175bSOded Gabbay dma_id);
2799e65e175bSOded Gabbay
2800e65e175bSOded Gabbay WREG32(mmDMA0_QM_ARB_ERR_MSG_EN + dma_qm_offset,
2801e65e175bSOded Gabbay QM_ARB_ERR_MSG_EN_MASK);
2802e65e175bSOded Gabbay
2803e65e175bSOded Gabbay /* Set timeout to maximum */
2804e65e175bSOded Gabbay WREG32(mmDMA0_QM_ARB_SLV_CHOISE_WDT + dma_qm_offset, GAUDI_ARB_WDT_TIMEOUT);
2805e65e175bSOded Gabbay
2806e65e175bSOded Gabbay WREG32(mmDMA0_QM_GLBL_CFG1 + dma_qm_offset, 0);
2807e65e175bSOded Gabbay WREG32(mmDMA0_QM_GLBL_PROT + dma_qm_offset,
2808e65e175bSOded Gabbay QMAN_INTERNAL_MAKE_TRUSTED);
2809e65e175bSOded Gabbay }
2810e65e175bSOded Gabbay
2811e65e175bSOded Gabbay WREG32(mmDMA0_QM_CP_MSG_BASE0_ADDR_LO_0 + q_off, mtr_base_en_lo);
2812e65e175bSOded Gabbay WREG32(mmDMA0_QM_CP_MSG_BASE0_ADDR_HI_0 + q_off, mtr_base_en_hi);
2813e65e175bSOded Gabbay WREG32(mmDMA0_QM_CP_MSG_BASE1_ADDR_LO_0 + q_off, so_base_en_lo);
2814e65e175bSOded Gabbay WREG32(mmDMA0_QM_CP_MSG_BASE1_ADDR_HI_0 + q_off, so_base_en_hi);
2815e65e175bSOded Gabbay
2816e65e175bSOded Gabbay /* Configure DMA5 CP_MSG_BASE 2/3 for sync stream collective */
2817e65e175bSOded Gabbay if (gaudi_dma_assignment[dma_id] == GAUDI_ENGINE_ID_DMA_5) {
2818e65e175bSOded Gabbay WREG32(mmDMA0_QM_CP_MSG_BASE2_ADDR_LO_0 + q_off,
2819e65e175bSOded Gabbay mtr_base_ws_lo);
2820e65e175bSOded Gabbay WREG32(mmDMA0_QM_CP_MSG_BASE2_ADDR_HI_0 + q_off,
2821e65e175bSOded Gabbay mtr_base_ws_hi);
2822e65e175bSOded Gabbay WREG32(mmDMA0_QM_CP_MSG_BASE3_ADDR_LO_0 + q_off,
2823e65e175bSOded Gabbay so_base_ws_lo);
2824e65e175bSOded Gabbay WREG32(mmDMA0_QM_CP_MSG_BASE3_ADDR_HI_0 + q_off,
2825e65e175bSOded Gabbay so_base_ws_hi);
2826e65e175bSOded Gabbay }
2827e65e175bSOded Gabbay }
2828e65e175bSOded Gabbay
gaudi_init_hbm_dma_qmans(struct hl_device * hdev)2829e65e175bSOded Gabbay static void gaudi_init_hbm_dma_qmans(struct hl_device *hdev)
2830e65e175bSOded Gabbay {
2831e65e175bSOded Gabbay struct gaudi_device *gaudi = hdev->asic_specific;
2832e65e175bSOded Gabbay struct gaudi_internal_qman_info *q;
2833e65e175bSOded Gabbay u64 qman_base_addr;
2834e65e175bSOded Gabbay int i, j, dma_id, internal_q_index;
2835e65e175bSOded Gabbay
2836e65e175bSOded Gabbay if (gaudi->hw_cap_initialized & HW_CAP_HBM_DMA)
2837e65e175bSOded Gabbay return;
2838e65e175bSOded Gabbay
2839e65e175bSOded Gabbay for (i = 0 ; i < HBM_DMA_NUMBER_OF_CHNLS ; i++) {
2840e65e175bSOded Gabbay dma_id = gaudi_dma_assignment[GAUDI_HBM_DMA_1 + i];
2841e65e175bSOded Gabbay
2842e65e175bSOded Gabbay for (j = 0 ; j < QMAN_STREAMS ; j++) {
2843e65e175bSOded Gabbay /*
2844e65e175bSOded Gabbay * Add the CPU queue in order to get the correct queue
2845e65e175bSOded Gabbay * number as all internal queue are placed after it
2846e65e175bSOded Gabbay */
2847e65e175bSOded Gabbay internal_q_index = dma_id * QMAN_STREAMS + j + 1;
2848e65e175bSOded Gabbay
2849e65e175bSOded Gabbay q = &gaudi->internal_qmans[internal_q_index];
2850e65e175bSOded Gabbay qman_base_addr = (u64) q->pq_dma_addr;
2851e65e175bSOded Gabbay gaudi_init_hbm_dma_qman(hdev, dma_id, j,
2852e65e175bSOded Gabbay qman_base_addr);
2853e65e175bSOded Gabbay }
2854e65e175bSOded Gabbay
2855e65e175bSOded Gabbay /* Initializing lower CP for HBM DMA QMAN */
2856e65e175bSOded Gabbay gaudi_init_hbm_dma_qman(hdev, dma_id, 4, 0);
2857e65e175bSOded Gabbay
2858e65e175bSOded Gabbay gaudi_init_dma_core(hdev, dma_id);
2859e65e175bSOded Gabbay
2860e65e175bSOded Gabbay gaudi_enable_qman(hdev, dma_id, HBM_DMA_QMAN_ENABLE);
2861e65e175bSOded Gabbay }
2862e65e175bSOded Gabbay
2863e65e175bSOded Gabbay gaudi->hw_cap_initialized |= HW_CAP_HBM_DMA;
2864e65e175bSOded Gabbay }
2865e65e175bSOded Gabbay
gaudi_init_mme_qman(struct hl_device * hdev,u32 mme_offset,int qman_id,u64 qman_base_addr)2866e65e175bSOded Gabbay static void gaudi_init_mme_qman(struct hl_device *hdev, u32 mme_offset,
2867e65e175bSOded Gabbay int qman_id, u64 qman_base_addr)
2868e65e175bSOded Gabbay {
2869e65e175bSOded Gabbay struct cpu_dyn_regs *dyn_regs =
2870e65e175bSOded Gabbay &hdev->fw_loader.dynamic_loader.comm_desc.cpu_dyn_regs;
2871e65e175bSOded Gabbay u32 mtr_base_lo, mtr_base_hi;
2872e65e175bSOded Gabbay u32 so_base_lo, so_base_hi;
2873e65e175bSOded Gabbay u32 irq_handler_offset;
2874e65e175bSOded Gabbay u32 q_off, mme_id;
2875e65e175bSOded Gabbay u32 mme_qm_err_cfg;
2876e65e175bSOded Gabbay
2877e65e175bSOded Gabbay mtr_base_lo = lower_32_bits(CFG_BASE +
2878e65e175bSOded Gabbay mmSYNC_MNGR_E_N_SYNC_MNGR_OBJS_MON_PAY_ADDRL_0);
2879e65e175bSOded Gabbay mtr_base_hi = upper_32_bits(CFG_BASE +
2880e65e175bSOded Gabbay mmSYNC_MNGR_E_N_SYNC_MNGR_OBJS_MON_PAY_ADDRL_0);
2881e65e175bSOded Gabbay so_base_lo = lower_32_bits(CFG_BASE +
2882e65e175bSOded Gabbay mmSYNC_MNGR_E_N_SYNC_MNGR_OBJS_SOB_OBJ_0);
2883e65e175bSOded Gabbay so_base_hi = upper_32_bits(CFG_BASE +
2884e65e175bSOded Gabbay mmSYNC_MNGR_E_N_SYNC_MNGR_OBJS_SOB_OBJ_0);
2885e65e175bSOded Gabbay
2886e65e175bSOded Gabbay q_off = mme_offset + qman_id * 4;
2887e65e175bSOded Gabbay
2888e65e175bSOded Gabbay if (qman_id < 4) {
2889e65e175bSOded Gabbay WREG32(mmMME0_QM_PQ_BASE_LO_0 + q_off,
2890e65e175bSOded Gabbay lower_32_bits(qman_base_addr));
2891e65e175bSOded Gabbay WREG32(mmMME0_QM_PQ_BASE_HI_0 + q_off,
2892e65e175bSOded Gabbay upper_32_bits(qman_base_addr));
2893e65e175bSOded Gabbay
2894e65e175bSOded Gabbay WREG32(mmMME0_QM_PQ_SIZE_0 + q_off, ilog2(MME_QMAN_LENGTH));
2895e65e175bSOded Gabbay WREG32(mmMME0_QM_PQ_PI_0 + q_off, 0);
2896e65e175bSOded Gabbay WREG32(mmMME0_QM_PQ_CI_0 + q_off, 0);
2897e65e175bSOded Gabbay
2898e65e175bSOded Gabbay WREG32(mmMME0_QM_CP_LDMA_TSIZE_OFFSET_0 + q_off,
2899e65e175bSOded Gabbay QMAN_CPDMA_SIZE_OFFSET);
2900e65e175bSOded Gabbay WREG32(mmMME0_QM_CP_LDMA_SRC_BASE_LO_OFFSET_0 + q_off,
2901e65e175bSOded Gabbay QMAN_CPDMA_SRC_OFFSET);
2902e65e175bSOded Gabbay WREG32(mmMME0_QM_CP_LDMA_DST_BASE_LO_OFFSET_0 + q_off,
2903e65e175bSOded Gabbay QMAN_CPDMA_DST_OFFSET);
2904e65e175bSOded Gabbay } else {
2905e65e175bSOded Gabbay irq_handler_offset = hdev->asic_prop.gic_interrupts_enable ?
2906e65e175bSOded Gabbay mmGIC_DISTRIBUTOR__5_GICD_SETSPI_NSR :
2907e65e175bSOded Gabbay le32_to_cpu(dyn_regs->gic_mme_qm_irq_ctrl);
2908e65e175bSOded Gabbay
2909e65e175bSOded Gabbay WREG32(mmMME0_QM_CP_LDMA_TSIZE_OFFSET_0 + q_off,
2910e65e175bSOded Gabbay QMAN_LDMA_SIZE_OFFSET);
2911e65e175bSOded Gabbay WREG32(mmMME0_QM_CP_LDMA_SRC_BASE_LO_OFFSET_0 + q_off,
2912e65e175bSOded Gabbay QMAN_LDMA_SRC_OFFSET);
2913e65e175bSOded Gabbay WREG32(mmMME0_QM_CP_LDMA_DST_BASE_LO_OFFSET_0 + q_off,
2914e65e175bSOded Gabbay QMAN_LDMA_DST_OFFSET);
2915e65e175bSOded Gabbay
2916e65e175bSOded Gabbay /* Configure RAZWI IRQ */
2917e65e175bSOded Gabbay mme_id = mme_offset /
2918e65e175bSOded Gabbay (mmMME1_QM_GLBL_CFG0 - mmMME0_QM_GLBL_CFG0) / 2;
2919e65e175bSOded Gabbay
2920e65e175bSOded Gabbay mme_qm_err_cfg = MME_QMAN_GLBL_ERR_CFG_MSG_EN_MASK;
2921e65e175bSOded Gabbay if (hdev->stop_on_err)
2922e65e175bSOded Gabbay mme_qm_err_cfg |=
2923e65e175bSOded Gabbay MME_QMAN_GLBL_ERR_CFG_STOP_ON_ERR_EN_MASK;
2924e65e175bSOded Gabbay
2925e65e175bSOded Gabbay WREG32(mmMME0_QM_GLBL_ERR_CFG + mme_offset, mme_qm_err_cfg);
2926e65e175bSOded Gabbay
2927e65e175bSOded Gabbay WREG32(mmMME0_QM_GLBL_ERR_ADDR_LO + mme_offset,
2928e65e175bSOded Gabbay lower_32_bits(CFG_BASE + irq_handler_offset));
2929e65e175bSOded Gabbay WREG32(mmMME0_QM_GLBL_ERR_ADDR_HI + mme_offset,
2930e65e175bSOded Gabbay upper_32_bits(CFG_BASE + irq_handler_offset));
2931e65e175bSOded Gabbay
2932e65e175bSOded Gabbay WREG32(mmMME0_QM_GLBL_ERR_WDATA + mme_offset,
2933e65e175bSOded Gabbay gaudi_irq_map_table[GAUDI_EVENT_MME0_QM].cpu_id +
2934e65e175bSOded Gabbay mme_id);
2935e65e175bSOded Gabbay
2936e65e175bSOded Gabbay WREG32(mmMME0_QM_ARB_ERR_MSG_EN + mme_offset,
2937e65e175bSOded Gabbay QM_ARB_ERR_MSG_EN_MASK);
2938e65e175bSOded Gabbay
2939e65e175bSOded Gabbay /* Set timeout to maximum */
2940e65e175bSOded Gabbay WREG32(mmMME0_QM_ARB_SLV_CHOISE_WDT + mme_offset, GAUDI_ARB_WDT_TIMEOUT);
2941e65e175bSOded Gabbay
2942e65e175bSOded Gabbay WREG32(mmMME0_QM_GLBL_CFG1 + mme_offset, 0);
2943e65e175bSOded Gabbay WREG32(mmMME0_QM_GLBL_PROT + mme_offset,
2944e65e175bSOded Gabbay QMAN_INTERNAL_MAKE_TRUSTED);
2945e65e175bSOded Gabbay }
2946e65e175bSOded Gabbay
2947e65e175bSOded Gabbay WREG32(mmMME0_QM_CP_MSG_BASE0_ADDR_LO_0 + q_off, mtr_base_lo);
2948e65e175bSOded Gabbay WREG32(mmMME0_QM_CP_MSG_BASE0_ADDR_HI_0 + q_off, mtr_base_hi);
2949e65e175bSOded Gabbay WREG32(mmMME0_QM_CP_MSG_BASE1_ADDR_LO_0 + q_off, so_base_lo);
2950e65e175bSOded Gabbay WREG32(mmMME0_QM_CP_MSG_BASE1_ADDR_HI_0 + q_off, so_base_hi);
2951e65e175bSOded Gabbay }
2952e65e175bSOded Gabbay
gaudi_init_mme_qmans(struct hl_device * hdev)2953e65e175bSOded Gabbay static void gaudi_init_mme_qmans(struct hl_device *hdev)
2954e65e175bSOded Gabbay {
2955e65e175bSOded Gabbay struct gaudi_device *gaudi = hdev->asic_specific;
2956e65e175bSOded Gabbay struct gaudi_internal_qman_info *q;
2957e65e175bSOded Gabbay u64 qman_base_addr;
2958e65e175bSOded Gabbay u32 mme_offset;
2959e65e175bSOded Gabbay int i, internal_q_index;
2960e65e175bSOded Gabbay
2961e65e175bSOded Gabbay if (gaudi->hw_cap_initialized & HW_CAP_MME)
2962e65e175bSOded Gabbay return;
2963e65e175bSOded Gabbay
2964e65e175bSOded Gabbay /*
2965e65e175bSOded Gabbay * map GAUDI_QUEUE_ID_MME_0_X to the N_W_MME (mmMME2_QM_BASE)
2966e65e175bSOded Gabbay * and GAUDI_QUEUE_ID_MME_1_X to the S_W_MME (mmMME0_QM_BASE)
2967e65e175bSOded Gabbay */
2968e65e175bSOded Gabbay
2969e65e175bSOded Gabbay mme_offset = mmMME2_QM_GLBL_CFG0 - mmMME0_QM_GLBL_CFG0;
2970e65e175bSOded Gabbay
2971e65e175bSOded Gabbay for (i = 0 ; i < MME_NUMBER_OF_QMANS ; i++) {
2972e65e175bSOded Gabbay internal_q_index = GAUDI_QUEUE_ID_MME_0_0 + i;
2973e65e175bSOded Gabbay q = &gaudi->internal_qmans[internal_q_index];
2974e65e175bSOded Gabbay qman_base_addr = (u64) q->pq_dma_addr;
2975e65e175bSOded Gabbay gaudi_init_mme_qman(hdev, mme_offset, (i & 0x3),
2976e65e175bSOded Gabbay qman_base_addr);
2977e65e175bSOded Gabbay if (i == 3)
2978e65e175bSOded Gabbay mme_offset = 0;
2979e65e175bSOded Gabbay }
2980e65e175bSOded Gabbay
2981e65e175bSOded Gabbay /* Initializing lower CP for MME QMANs */
2982e65e175bSOded Gabbay mme_offset = mmMME2_QM_GLBL_CFG0 - mmMME0_QM_GLBL_CFG0;
2983e65e175bSOded Gabbay gaudi_init_mme_qman(hdev, mme_offset, 4, 0);
2984e65e175bSOded Gabbay gaudi_init_mme_qman(hdev, 0, 4, 0);
2985e65e175bSOded Gabbay
2986e65e175bSOded Gabbay WREG32(mmMME2_QM_GLBL_CFG0, QMAN_MME_ENABLE);
2987e65e175bSOded Gabbay WREG32(mmMME0_QM_GLBL_CFG0, QMAN_MME_ENABLE);
2988e65e175bSOded Gabbay
2989e65e175bSOded Gabbay gaudi->hw_cap_initialized |= HW_CAP_MME;
2990e65e175bSOded Gabbay }
2991e65e175bSOded Gabbay
gaudi_init_tpc_qman(struct hl_device * hdev,u32 tpc_offset,int qman_id,u64 qman_base_addr)2992e65e175bSOded Gabbay static void gaudi_init_tpc_qman(struct hl_device *hdev, u32 tpc_offset,
2993e65e175bSOded Gabbay int qman_id, u64 qman_base_addr)
2994e65e175bSOded Gabbay {
2995e65e175bSOded Gabbay struct cpu_dyn_regs *dyn_regs =
2996e65e175bSOded Gabbay &hdev->fw_loader.dynamic_loader.comm_desc.cpu_dyn_regs;
2997e65e175bSOded Gabbay u32 mtr_base_en_lo, mtr_base_en_hi, mtr_base_ws_lo, mtr_base_ws_hi;
2998e65e175bSOded Gabbay u32 so_base_en_lo, so_base_en_hi, so_base_ws_lo, so_base_ws_hi;
2999e65e175bSOded Gabbay u32 tpc_qm_err_cfg, irq_handler_offset;
3000e65e175bSOded Gabbay u32 q_off, tpc_id;
3001e65e175bSOded Gabbay
3002e65e175bSOded Gabbay mtr_base_en_lo = lower_32_bits(CFG_BASE +
3003e65e175bSOded Gabbay mmSYNC_MNGR_E_N_SYNC_MNGR_OBJS_MON_PAY_ADDRL_0);
3004e65e175bSOded Gabbay mtr_base_en_hi = upper_32_bits(CFG_BASE +
3005e65e175bSOded Gabbay mmSYNC_MNGR_E_N_SYNC_MNGR_OBJS_MON_PAY_ADDRL_0);
3006e65e175bSOded Gabbay so_base_en_lo = lower_32_bits(CFG_BASE +
3007e65e175bSOded Gabbay mmSYNC_MNGR_E_N_SYNC_MNGR_OBJS_SOB_OBJ_0);
3008e65e175bSOded Gabbay so_base_en_hi = upper_32_bits(CFG_BASE +
3009e65e175bSOded Gabbay mmSYNC_MNGR_E_N_SYNC_MNGR_OBJS_SOB_OBJ_0);
3010e65e175bSOded Gabbay mtr_base_ws_lo = lower_32_bits(CFG_BASE +
3011e65e175bSOded Gabbay mmSYNC_MNGR_W_S_SYNC_MNGR_OBJS_MON_PAY_ADDRL_0);
3012e65e175bSOded Gabbay mtr_base_ws_hi = upper_32_bits(CFG_BASE +
3013e65e175bSOded Gabbay mmSYNC_MNGR_W_S_SYNC_MNGR_OBJS_MON_PAY_ADDRL_0);
3014e65e175bSOded Gabbay so_base_ws_lo = lower_32_bits(CFG_BASE +
3015e65e175bSOded Gabbay mmSYNC_MNGR_W_S_SYNC_MNGR_OBJS_SOB_OBJ_0);
3016e65e175bSOded Gabbay so_base_ws_hi = upper_32_bits(CFG_BASE +
3017e65e175bSOded Gabbay mmSYNC_MNGR_W_S_SYNC_MNGR_OBJS_SOB_OBJ_0);
3018e65e175bSOded Gabbay
3019e65e175bSOded Gabbay q_off = tpc_offset + qman_id * 4;
3020e65e175bSOded Gabbay
3021e65e175bSOded Gabbay tpc_id = tpc_offset /
3022e65e175bSOded Gabbay (mmTPC1_QM_GLBL_CFG0 - mmTPC0_QM_GLBL_CFG0);
3023e65e175bSOded Gabbay
3024e65e175bSOded Gabbay if (qman_id < 4) {
3025e65e175bSOded Gabbay WREG32(mmTPC0_QM_PQ_BASE_LO_0 + q_off,
3026e65e175bSOded Gabbay lower_32_bits(qman_base_addr));
3027e65e175bSOded Gabbay WREG32(mmTPC0_QM_PQ_BASE_HI_0 + q_off,
3028e65e175bSOded Gabbay upper_32_bits(qman_base_addr));
3029e65e175bSOded Gabbay
3030e65e175bSOded Gabbay WREG32(mmTPC0_QM_PQ_SIZE_0 + q_off, ilog2(TPC_QMAN_LENGTH));
3031e65e175bSOded Gabbay WREG32(mmTPC0_QM_PQ_PI_0 + q_off, 0);
3032e65e175bSOded Gabbay WREG32(mmTPC0_QM_PQ_CI_0 + q_off, 0);
3033e65e175bSOded Gabbay
3034e65e175bSOded Gabbay WREG32(mmTPC0_QM_CP_LDMA_TSIZE_OFFSET_0 + q_off,
3035e65e175bSOded Gabbay QMAN_CPDMA_SIZE_OFFSET);
3036e65e175bSOded Gabbay WREG32(mmTPC0_QM_CP_LDMA_SRC_BASE_LO_OFFSET_0 + q_off,
3037e65e175bSOded Gabbay QMAN_CPDMA_SRC_OFFSET);
3038e65e175bSOded Gabbay WREG32(mmTPC0_QM_CP_LDMA_DST_BASE_LO_OFFSET_0 + q_off,
3039e65e175bSOded Gabbay QMAN_CPDMA_DST_OFFSET);
3040e65e175bSOded Gabbay } else {
3041e65e175bSOded Gabbay irq_handler_offset = hdev->asic_prop.gic_interrupts_enable ?
3042e65e175bSOded Gabbay mmGIC_DISTRIBUTOR__5_GICD_SETSPI_NSR :
3043e65e175bSOded Gabbay le32_to_cpu(dyn_regs->gic_tpc_qm_irq_ctrl);
3044e65e175bSOded Gabbay
3045e65e175bSOded Gabbay WREG32(mmTPC0_QM_CP_LDMA_TSIZE_OFFSET_0 + q_off,
3046e65e175bSOded Gabbay QMAN_LDMA_SIZE_OFFSET);
3047e65e175bSOded Gabbay WREG32(mmTPC0_QM_CP_LDMA_SRC_BASE_LO_OFFSET_0 + q_off,
3048e65e175bSOded Gabbay QMAN_LDMA_SRC_OFFSET);
3049e65e175bSOded Gabbay WREG32(mmTPC0_QM_CP_LDMA_DST_BASE_LO_OFFSET_0 + q_off,
3050e65e175bSOded Gabbay QMAN_LDMA_DST_OFFSET);
3051e65e175bSOded Gabbay
3052e65e175bSOded Gabbay /* Configure RAZWI IRQ */
3053e65e175bSOded Gabbay tpc_qm_err_cfg = TPC_QMAN_GLBL_ERR_CFG_MSG_EN_MASK;
3054e65e175bSOded Gabbay if (hdev->stop_on_err)
3055e65e175bSOded Gabbay tpc_qm_err_cfg |=
3056e65e175bSOded Gabbay TPC_QMAN_GLBL_ERR_CFG_STOP_ON_ERR_EN_MASK;
3057e65e175bSOded Gabbay
3058e65e175bSOded Gabbay WREG32(mmTPC0_QM_GLBL_ERR_CFG + tpc_offset, tpc_qm_err_cfg);
3059e65e175bSOded Gabbay
3060e65e175bSOded Gabbay WREG32(mmTPC0_QM_GLBL_ERR_ADDR_LO + tpc_offset,
3061e65e175bSOded Gabbay lower_32_bits(CFG_BASE + irq_handler_offset));
3062e65e175bSOded Gabbay WREG32(mmTPC0_QM_GLBL_ERR_ADDR_HI + tpc_offset,
3063e65e175bSOded Gabbay upper_32_bits(CFG_BASE + irq_handler_offset));
3064e65e175bSOded Gabbay
3065e65e175bSOded Gabbay WREG32(mmTPC0_QM_GLBL_ERR_WDATA + tpc_offset,
3066e65e175bSOded Gabbay gaudi_irq_map_table[GAUDI_EVENT_TPC0_QM].cpu_id +
3067e65e175bSOded Gabbay tpc_id);
3068e65e175bSOded Gabbay
3069e65e175bSOded Gabbay WREG32(mmTPC0_QM_ARB_ERR_MSG_EN + tpc_offset,
3070e65e175bSOded Gabbay QM_ARB_ERR_MSG_EN_MASK);
3071e65e175bSOded Gabbay
3072e65e175bSOded Gabbay /* Set timeout to maximum */
3073e65e175bSOded Gabbay WREG32(mmTPC0_QM_ARB_SLV_CHOISE_WDT + tpc_offset, GAUDI_ARB_WDT_TIMEOUT);
3074e65e175bSOded Gabbay
3075e65e175bSOded Gabbay WREG32(mmTPC0_QM_GLBL_CFG1 + tpc_offset, 0);
3076e65e175bSOded Gabbay WREG32(mmTPC0_QM_GLBL_PROT + tpc_offset,
3077e65e175bSOded Gabbay QMAN_INTERNAL_MAKE_TRUSTED);
3078e65e175bSOded Gabbay }
3079e65e175bSOded Gabbay
3080e65e175bSOded Gabbay WREG32(mmTPC0_QM_CP_MSG_BASE0_ADDR_LO_0 + q_off, mtr_base_en_lo);
3081e65e175bSOded Gabbay WREG32(mmTPC0_QM_CP_MSG_BASE0_ADDR_HI_0 + q_off, mtr_base_en_hi);
3082e65e175bSOded Gabbay WREG32(mmTPC0_QM_CP_MSG_BASE1_ADDR_LO_0 + q_off, so_base_en_lo);
3083e65e175bSOded Gabbay WREG32(mmTPC0_QM_CP_MSG_BASE1_ADDR_HI_0 + q_off, so_base_en_hi);
3084e65e175bSOded Gabbay
3085e65e175bSOded Gabbay /* Configure TPC7 CP_MSG_BASE 2/3 for sync stream collective */
3086e65e175bSOded Gabbay if (tpc_id == 6) {
3087e65e175bSOded Gabbay WREG32(mmTPC0_QM_CP_MSG_BASE2_ADDR_LO_0 + q_off,
3088e65e175bSOded Gabbay mtr_base_ws_lo);
3089e65e175bSOded Gabbay WREG32(mmTPC0_QM_CP_MSG_BASE2_ADDR_HI_0 + q_off,
3090e65e175bSOded Gabbay mtr_base_ws_hi);
3091e65e175bSOded Gabbay WREG32(mmTPC0_QM_CP_MSG_BASE3_ADDR_LO_0 + q_off,
3092e65e175bSOded Gabbay so_base_ws_lo);
3093e65e175bSOded Gabbay WREG32(mmTPC0_QM_CP_MSG_BASE3_ADDR_HI_0 + q_off,
3094e65e175bSOded Gabbay so_base_ws_hi);
3095e65e175bSOded Gabbay }
3096e65e175bSOded Gabbay }
3097e65e175bSOded Gabbay
gaudi_init_tpc_qmans(struct hl_device * hdev)3098e65e175bSOded Gabbay static void gaudi_init_tpc_qmans(struct hl_device *hdev)
3099e65e175bSOded Gabbay {
3100e65e175bSOded Gabbay struct gaudi_device *gaudi = hdev->asic_specific;
3101e65e175bSOded Gabbay struct gaudi_internal_qman_info *q;
3102e65e175bSOded Gabbay u64 qman_base_addr;
3103e65e175bSOded Gabbay u32 so_base_hi, tpc_offset = 0;
3104e65e175bSOded Gabbay u32 tpc_delta = mmTPC1_CFG_SM_BASE_ADDRESS_HIGH -
3105e65e175bSOded Gabbay mmTPC0_CFG_SM_BASE_ADDRESS_HIGH;
3106e65e175bSOded Gabbay int i, tpc_id, internal_q_index;
3107e65e175bSOded Gabbay
3108e65e175bSOded Gabbay if (gaudi->hw_cap_initialized & HW_CAP_TPC_MASK)
3109e65e175bSOded Gabbay return;
3110e65e175bSOded Gabbay
3111e65e175bSOded Gabbay so_base_hi = upper_32_bits(CFG_BASE +
3112e65e175bSOded Gabbay mmSYNC_MNGR_E_N_SYNC_MNGR_OBJS_SOB_OBJ_0);
3113e65e175bSOded Gabbay
3114e65e175bSOded Gabbay for (tpc_id = 0 ; tpc_id < TPC_NUMBER_OF_ENGINES ; tpc_id++) {
3115e65e175bSOded Gabbay for (i = 0 ; i < QMAN_STREAMS ; i++) {
3116e65e175bSOded Gabbay internal_q_index = GAUDI_QUEUE_ID_TPC_0_0 +
3117e65e175bSOded Gabbay tpc_id * QMAN_STREAMS + i;
3118e65e175bSOded Gabbay q = &gaudi->internal_qmans[internal_q_index];
3119e65e175bSOded Gabbay qman_base_addr = (u64) q->pq_dma_addr;
3120e65e175bSOded Gabbay gaudi_init_tpc_qman(hdev, tpc_offset, i,
3121e65e175bSOded Gabbay qman_base_addr);
3122e65e175bSOded Gabbay
3123e65e175bSOded Gabbay if (i == 3) {
3124e65e175bSOded Gabbay /* Initializing lower CP for TPC QMAN */
3125e65e175bSOded Gabbay gaudi_init_tpc_qman(hdev, tpc_offset, 4, 0);
3126e65e175bSOded Gabbay
3127e65e175bSOded Gabbay /* Enable the QMAN and TPC channel */
3128e65e175bSOded Gabbay WREG32(mmTPC0_QM_GLBL_CFG0 + tpc_offset,
3129e65e175bSOded Gabbay QMAN_TPC_ENABLE);
3130e65e175bSOded Gabbay }
3131e65e175bSOded Gabbay }
3132e65e175bSOded Gabbay
3133e65e175bSOded Gabbay WREG32(mmTPC0_CFG_SM_BASE_ADDRESS_HIGH + tpc_id * tpc_delta,
3134e65e175bSOded Gabbay so_base_hi);
3135e65e175bSOded Gabbay
3136e65e175bSOded Gabbay tpc_offset += mmTPC1_QM_GLBL_CFG0 - mmTPC0_QM_GLBL_CFG0;
3137e65e175bSOded Gabbay
3138e65e175bSOded Gabbay gaudi->hw_cap_initialized |=
3139e65e175bSOded Gabbay FIELD_PREP(HW_CAP_TPC_MASK, 1 << tpc_id);
3140e65e175bSOded Gabbay }
3141e65e175bSOded Gabbay }
3142e65e175bSOded Gabbay
gaudi_init_nic_qman(struct hl_device * hdev,u32 nic_offset,int qman_id,u64 qman_base_addr,int nic_id)3143e65e175bSOded Gabbay static void gaudi_init_nic_qman(struct hl_device *hdev, u32 nic_offset,
3144e65e175bSOded Gabbay int qman_id, u64 qman_base_addr, int nic_id)
3145e65e175bSOded Gabbay {
3146e65e175bSOded Gabbay struct cpu_dyn_regs *dyn_regs =
3147e65e175bSOded Gabbay &hdev->fw_loader.dynamic_loader.comm_desc.cpu_dyn_regs;
3148e65e175bSOded Gabbay u32 mtr_base_en_lo, mtr_base_en_hi, mtr_base_ws_lo, mtr_base_ws_hi;
3149e65e175bSOded Gabbay u32 so_base_en_lo, so_base_en_hi, so_base_ws_lo, so_base_ws_hi;
3150e65e175bSOded Gabbay u32 nic_qm_err_cfg, irq_handler_offset;
3151e65e175bSOded Gabbay u32 q_off;
3152e65e175bSOded Gabbay
3153e65e175bSOded Gabbay mtr_base_en_lo = lower_32_bits((CFG_BASE & U32_MAX) +
3154e65e175bSOded Gabbay mmSYNC_MNGR_E_N_SYNC_MNGR_OBJS_MON_PAY_ADDRL_0);
3155e65e175bSOded Gabbay mtr_base_en_hi = upper_32_bits(CFG_BASE +
3156e65e175bSOded Gabbay mmSYNC_MNGR_E_N_SYNC_MNGR_OBJS_MON_PAY_ADDRL_0);
3157e65e175bSOded Gabbay so_base_en_lo = lower_32_bits((CFG_BASE & U32_MAX) +
3158e65e175bSOded Gabbay mmSYNC_MNGR_E_N_SYNC_MNGR_OBJS_SOB_OBJ_0);
3159e65e175bSOded Gabbay so_base_en_hi = upper_32_bits(CFG_BASE +
3160e65e175bSOded Gabbay mmSYNC_MNGR_E_N_SYNC_MNGR_OBJS_SOB_OBJ_0);
3161e65e175bSOded Gabbay mtr_base_ws_lo = lower_32_bits((CFG_BASE & U32_MAX) +
3162e65e175bSOded Gabbay mmSYNC_MNGR_W_S_SYNC_MNGR_OBJS_MON_PAY_ADDRL_0);
3163e65e175bSOded Gabbay mtr_base_ws_hi = upper_32_bits(CFG_BASE +
3164e65e175bSOded Gabbay mmSYNC_MNGR_W_S_SYNC_MNGR_OBJS_MON_PAY_ADDRL_0);
3165e65e175bSOded Gabbay so_base_ws_lo = lower_32_bits((CFG_BASE & U32_MAX) +
3166e65e175bSOded Gabbay mmSYNC_MNGR_W_S_SYNC_MNGR_OBJS_SOB_OBJ_0);
3167e65e175bSOded Gabbay so_base_ws_hi = upper_32_bits(CFG_BASE +
3168e65e175bSOded Gabbay mmSYNC_MNGR_W_S_SYNC_MNGR_OBJS_SOB_OBJ_0);
3169e65e175bSOded Gabbay
3170e65e175bSOded Gabbay q_off = nic_offset + qman_id * 4;
3171e65e175bSOded Gabbay
3172e65e175bSOded Gabbay WREG32(mmNIC0_QM0_PQ_BASE_LO_0 + q_off, lower_32_bits(qman_base_addr));
3173e65e175bSOded Gabbay WREG32(mmNIC0_QM0_PQ_BASE_HI_0 + q_off, upper_32_bits(qman_base_addr));
3174e65e175bSOded Gabbay
3175e65e175bSOded Gabbay WREG32(mmNIC0_QM0_PQ_SIZE_0 + q_off, ilog2(NIC_QMAN_LENGTH));
3176e65e175bSOded Gabbay WREG32(mmNIC0_QM0_PQ_PI_0 + q_off, 0);
3177e65e175bSOded Gabbay WREG32(mmNIC0_QM0_PQ_CI_0 + q_off, 0);
3178e65e175bSOded Gabbay
3179e65e175bSOded Gabbay WREG32(mmNIC0_QM0_CP_LDMA_TSIZE_OFFSET_0 + q_off,
3180e65e175bSOded Gabbay QMAN_LDMA_SIZE_OFFSET);
3181e65e175bSOded Gabbay WREG32(mmNIC0_QM0_CP_LDMA_SRC_BASE_LO_OFFSET_0 + q_off,
3182e65e175bSOded Gabbay QMAN_LDMA_SRC_OFFSET);
3183e65e175bSOded Gabbay WREG32(mmNIC0_QM0_CP_LDMA_DST_BASE_LO_OFFSET_0 + q_off,
3184e65e175bSOded Gabbay QMAN_LDMA_DST_OFFSET);
3185e65e175bSOded Gabbay
3186e65e175bSOded Gabbay WREG32(mmNIC0_QM0_CP_MSG_BASE0_ADDR_LO_0 + q_off, mtr_base_en_lo);
3187e65e175bSOded Gabbay WREG32(mmNIC0_QM0_CP_MSG_BASE0_ADDR_HI_0 + q_off, mtr_base_en_hi);
3188e65e175bSOded Gabbay WREG32(mmNIC0_QM0_CP_MSG_BASE1_ADDR_LO_0 + q_off, so_base_en_lo);
3189e65e175bSOded Gabbay WREG32(mmNIC0_QM0_CP_MSG_BASE1_ADDR_HI_0 + q_off, so_base_en_hi);
3190e65e175bSOded Gabbay
3191e65e175bSOded Gabbay /* Configure NIC CP_MSG_BASE 2/3 for sync stream collective */
3192e65e175bSOded Gabbay WREG32(mmNIC0_QM0_CP_MSG_BASE2_ADDR_LO_0 + q_off, mtr_base_ws_lo);
3193e65e175bSOded Gabbay WREG32(mmNIC0_QM0_CP_MSG_BASE2_ADDR_HI_0 + q_off, mtr_base_ws_hi);
3194e65e175bSOded Gabbay WREG32(mmNIC0_QM0_CP_MSG_BASE3_ADDR_LO_0 + q_off, so_base_ws_lo);
3195e65e175bSOded Gabbay WREG32(mmNIC0_QM0_CP_MSG_BASE3_ADDR_HI_0 + q_off, so_base_ws_hi);
3196e65e175bSOded Gabbay
3197e65e175bSOded Gabbay if (qman_id == 0) {
3198e65e175bSOded Gabbay irq_handler_offset = hdev->asic_prop.gic_interrupts_enable ?
3199e65e175bSOded Gabbay mmGIC_DISTRIBUTOR__5_GICD_SETSPI_NSR :
3200e65e175bSOded Gabbay le32_to_cpu(dyn_regs->gic_nic_qm_irq_ctrl);
3201e65e175bSOded Gabbay
3202e65e175bSOded Gabbay /* Configure RAZWI IRQ */
3203e65e175bSOded Gabbay nic_qm_err_cfg = NIC_QMAN_GLBL_ERR_CFG_MSG_EN_MASK;
3204e65e175bSOded Gabbay if (hdev->stop_on_err)
3205e65e175bSOded Gabbay nic_qm_err_cfg |=
3206e65e175bSOded Gabbay NIC_QMAN_GLBL_ERR_CFG_STOP_ON_ERR_EN_MASK;
3207e65e175bSOded Gabbay
3208e65e175bSOded Gabbay WREG32(mmNIC0_QM0_GLBL_ERR_CFG + nic_offset, nic_qm_err_cfg);
3209e65e175bSOded Gabbay
3210e65e175bSOded Gabbay WREG32(mmNIC0_QM0_GLBL_ERR_ADDR_LO + nic_offset,
3211e65e175bSOded Gabbay lower_32_bits(CFG_BASE + irq_handler_offset));
3212e65e175bSOded Gabbay WREG32(mmNIC0_QM0_GLBL_ERR_ADDR_HI + nic_offset,
3213e65e175bSOded Gabbay upper_32_bits(CFG_BASE + irq_handler_offset));
3214e65e175bSOded Gabbay
3215e65e175bSOded Gabbay WREG32(mmNIC0_QM0_GLBL_ERR_WDATA + nic_offset,
3216e65e175bSOded Gabbay gaudi_irq_map_table[GAUDI_EVENT_NIC0_QM0].cpu_id +
3217e65e175bSOded Gabbay nic_id);
3218e65e175bSOded Gabbay
3219e65e175bSOded Gabbay WREG32(mmNIC0_QM0_ARB_ERR_MSG_EN + nic_offset,
3220e65e175bSOded Gabbay QM_ARB_ERR_MSG_EN_MASK);
3221e65e175bSOded Gabbay
3222e65e175bSOded Gabbay /* Set timeout to maximum */
3223e65e175bSOded Gabbay WREG32(mmNIC0_QM0_ARB_SLV_CHOISE_WDT + nic_offset, GAUDI_ARB_WDT_TIMEOUT);
3224e65e175bSOded Gabbay
3225e65e175bSOded Gabbay WREG32(mmNIC0_QM0_GLBL_CFG1 + nic_offset, 0);
3226e65e175bSOded Gabbay WREG32(mmNIC0_QM0_GLBL_PROT + nic_offset,
3227e65e175bSOded Gabbay QMAN_INTERNAL_MAKE_TRUSTED);
3228e65e175bSOded Gabbay }
3229e65e175bSOded Gabbay }
3230e65e175bSOded Gabbay
gaudi_init_nic_qmans(struct hl_device * hdev)3231e65e175bSOded Gabbay static void gaudi_init_nic_qmans(struct hl_device *hdev)
3232e65e175bSOded Gabbay {
3233e65e175bSOded Gabbay struct gaudi_device *gaudi = hdev->asic_specific;
3234e65e175bSOded Gabbay struct gaudi_internal_qman_info *q;
3235e65e175bSOded Gabbay u64 qman_base_addr;
3236e65e175bSOded Gabbay u32 nic_offset = 0;
3237e65e175bSOded Gabbay u32 nic_delta_between_qmans =
3238e65e175bSOded Gabbay mmNIC0_QM1_GLBL_CFG0 - mmNIC0_QM0_GLBL_CFG0;
3239e65e175bSOded Gabbay u32 nic_delta_between_nics =
3240e65e175bSOded Gabbay mmNIC1_QM0_GLBL_CFG0 - mmNIC0_QM0_GLBL_CFG0;
3241e65e175bSOded Gabbay int i, nic_id, internal_q_index;
3242e65e175bSOded Gabbay
3243e65e175bSOded Gabbay if (!hdev->nic_ports_mask)
3244e65e175bSOded Gabbay return;
3245e65e175bSOded Gabbay
3246e65e175bSOded Gabbay if (gaudi->hw_cap_initialized & HW_CAP_NIC_MASK)
3247e65e175bSOded Gabbay return;
3248e65e175bSOded Gabbay
3249e65e175bSOded Gabbay dev_dbg(hdev->dev, "Initializing NIC QMANs\n");
3250e65e175bSOded Gabbay
3251e65e175bSOded Gabbay for (nic_id = 0 ; nic_id < NIC_NUMBER_OF_ENGINES ; nic_id++) {
3252e65e175bSOded Gabbay if (!(hdev->nic_ports_mask & (1 << nic_id))) {
3253e65e175bSOded Gabbay nic_offset += nic_delta_between_qmans;
3254e65e175bSOded Gabbay if (nic_id & 1) {
3255e65e175bSOded Gabbay nic_offset -= (nic_delta_between_qmans * 2);
3256e65e175bSOded Gabbay nic_offset += nic_delta_between_nics;
3257e65e175bSOded Gabbay }
3258e65e175bSOded Gabbay continue;
3259e65e175bSOded Gabbay }
3260e65e175bSOded Gabbay
3261e65e175bSOded Gabbay for (i = 0 ; i < QMAN_STREAMS ; i++) {
3262e65e175bSOded Gabbay internal_q_index = GAUDI_QUEUE_ID_NIC_0_0 +
3263e65e175bSOded Gabbay nic_id * QMAN_STREAMS + i;
3264e65e175bSOded Gabbay q = &gaudi->internal_qmans[internal_q_index];
3265e65e175bSOded Gabbay qman_base_addr = (u64) q->pq_dma_addr;
3266e65e175bSOded Gabbay gaudi_init_nic_qman(hdev, nic_offset, (i & 0x3),
3267e65e175bSOded Gabbay qman_base_addr, nic_id);
3268e65e175bSOded Gabbay }
3269e65e175bSOded Gabbay
3270e65e175bSOded Gabbay /* Enable the QMAN */
3271e65e175bSOded Gabbay WREG32(mmNIC0_QM0_GLBL_CFG0 + nic_offset, NIC_QMAN_ENABLE);
3272e65e175bSOded Gabbay
3273e65e175bSOded Gabbay nic_offset += nic_delta_between_qmans;
3274e65e175bSOded Gabbay if (nic_id & 1) {
3275e65e175bSOded Gabbay nic_offset -= (nic_delta_between_qmans * 2);
3276e65e175bSOded Gabbay nic_offset += nic_delta_between_nics;
3277e65e175bSOded Gabbay }
3278e65e175bSOded Gabbay
3279e65e175bSOded Gabbay gaudi->hw_cap_initialized |= 1 << (HW_CAP_NIC_SHIFT + nic_id);
3280e65e175bSOded Gabbay }
3281e65e175bSOded Gabbay }
3282e65e175bSOded Gabbay
gaudi_disable_pci_dma_qmans(struct hl_device * hdev)3283e65e175bSOded Gabbay static void gaudi_disable_pci_dma_qmans(struct hl_device *hdev)
3284e65e175bSOded Gabbay {
3285e65e175bSOded Gabbay struct gaudi_device *gaudi = hdev->asic_specific;
3286e65e175bSOded Gabbay
3287e65e175bSOded Gabbay if (!(gaudi->hw_cap_initialized & HW_CAP_PCI_DMA))
3288e65e175bSOded Gabbay return;
3289e65e175bSOded Gabbay
3290e65e175bSOded Gabbay WREG32(mmDMA0_QM_GLBL_CFG0, 0);
3291e65e175bSOded Gabbay WREG32(mmDMA1_QM_GLBL_CFG0, 0);
3292e65e175bSOded Gabbay WREG32(mmDMA5_QM_GLBL_CFG0, 0);
3293e65e175bSOded Gabbay }
3294e65e175bSOded Gabbay
gaudi_disable_hbm_dma_qmans(struct hl_device * hdev)3295e65e175bSOded Gabbay static void gaudi_disable_hbm_dma_qmans(struct hl_device *hdev)
3296e65e175bSOded Gabbay {
3297e65e175bSOded Gabbay struct gaudi_device *gaudi = hdev->asic_specific;
3298e65e175bSOded Gabbay
3299e65e175bSOded Gabbay if (!(gaudi->hw_cap_initialized & HW_CAP_HBM_DMA))
3300e65e175bSOded Gabbay return;
3301e65e175bSOded Gabbay
3302e65e175bSOded Gabbay WREG32(mmDMA2_QM_GLBL_CFG0, 0);
3303e65e175bSOded Gabbay WREG32(mmDMA3_QM_GLBL_CFG0, 0);
3304e65e175bSOded Gabbay WREG32(mmDMA4_QM_GLBL_CFG0, 0);
3305e65e175bSOded Gabbay WREG32(mmDMA6_QM_GLBL_CFG0, 0);
3306e65e175bSOded Gabbay WREG32(mmDMA7_QM_GLBL_CFG0, 0);
3307e65e175bSOded Gabbay }
3308e65e175bSOded Gabbay
gaudi_disable_mme_qmans(struct hl_device * hdev)3309e65e175bSOded Gabbay static void gaudi_disable_mme_qmans(struct hl_device *hdev)
3310e65e175bSOded Gabbay {
3311e65e175bSOded Gabbay struct gaudi_device *gaudi = hdev->asic_specific;
3312e65e175bSOded Gabbay
3313e65e175bSOded Gabbay if (!(gaudi->hw_cap_initialized & HW_CAP_MME))
3314e65e175bSOded Gabbay return;
3315e65e175bSOded Gabbay
3316e65e175bSOded Gabbay WREG32(mmMME2_QM_GLBL_CFG0, 0);
3317e65e175bSOded Gabbay WREG32(mmMME0_QM_GLBL_CFG0, 0);
3318e65e175bSOded Gabbay }
3319e65e175bSOded Gabbay
gaudi_disable_tpc_qmans(struct hl_device * hdev)3320e65e175bSOded Gabbay static void gaudi_disable_tpc_qmans(struct hl_device *hdev)
3321e65e175bSOded Gabbay {
3322e65e175bSOded Gabbay struct gaudi_device *gaudi = hdev->asic_specific;
3323e65e175bSOded Gabbay u32 tpc_offset = 0;
3324e65e175bSOded Gabbay int tpc_id;
3325e65e175bSOded Gabbay
3326e65e175bSOded Gabbay if (!(gaudi->hw_cap_initialized & HW_CAP_TPC_MASK))
3327e65e175bSOded Gabbay return;
3328e65e175bSOded Gabbay
3329e65e175bSOded Gabbay for (tpc_id = 0 ; tpc_id < TPC_NUMBER_OF_ENGINES ; tpc_id++) {
3330e65e175bSOded Gabbay WREG32(mmTPC0_QM_GLBL_CFG0 + tpc_offset, 0);
3331e65e175bSOded Gabbay tpc_offset += mmTPC1_QM_GLBL_CFG0 - mmTPC0_QM_GLBL_CFG0;
3332e65e175bSOded Gabbay }
3333e65e175bSOded Gabbay }
3334e65e175bSOded Gabbay
gaudi_disable_nic_qmans(struct hl_device * hdev)3335e65e175bSOded Gabbay static void gaudi_disable_nic_qmans(struct hl_device *hdev)
3336e65e175bSOded Gabbay {
3337e65e175bSOded Gabbay struct gaudi_device *gaudi = hdev->asic_specific;
3338e65e175bSOded Gabbay u32 nic_mask, nic_offset = 0;
3339e65e175bSOded Gabbay u32 nic_delta_between_qmans =
3340e65e175bSOded Gabbay mmNIC0_QM1_GLBL_CFG0 - mmNIC0_QM0_GLBL_CFG0;
3341e65e175bSOded Gabbay u32 nic_delta_between_nics =
3342e65e175bSOded Gabbay mmNIC1_QM0_GLBL_CFG0 - mmNIC0_QM0_GLBL_CFG0;
3343e65e175bSOded Gabbay int nic_id;
3344e65e175bSOded Gabbay
3345e65e175bSOded Gabbay for (nic_id = 0 ; nic_id < NIC_NUMBER_OF_ENGINES ; nic_id++) {
3346e65e175bSOded Gabbay nic_mask = 1 << (HW_CAP_NIC_SHIFT + nic_id);
3347e65e175bSOded Gabbay
3348e65e175bSOded Gabbay if (gaudi->hw_cap_initialized & nic_mask)
3349e65e175bSOded Gabbay WREG32(mmNIC0_QM0_GLBL_CFG0 + nic_offset, 0);
3350e65e175bSOded Gabbay
3351e65e175bSOded Gabbay nic_offset += nic_delta_between_qmans;
3352e65e175bSOded Gabbay if (nic_id & 1) {
3353e65e175bSOded Gabbay nic_offset -= (nic_delta_between_qmans * 2);
3354e65e175bSOded Gabbay nic_offset += nic_delta_between_nics;
3355e65e175bSOded Gabbay }
3356e65e175bSOded Gabbay }
3357e65e175bSOded Gabbay }
3358e65e175bSOded Gabbay
gaudi_stop_pci_dma_qmans(struct hl_device * hdev)3359e65e175bSOded Gabbay static void gaudi_stop_pci_dma_qmans(struct hl_device *hdev)
3360e65e175bSOded Gabbay {
3361e65e175bSOded Gabbay struct gaudi_device *gaudi = hdev->asic_specific;
3362e65e175bSOded Gabbay
3363e65e175bSOded Gabbay if (!(gaudi->hw_cap_initialized & HW_CAP_PCI_DMA))
3364e65e175bSOded Gabbay return;
3365e65e175bSOded Gabbay
3366e65e175bSOded Gabbay /* Stop upper CPs of QMANs 0.0 to 1.3 and 5.0 to 5.3 */
3367e65e175bSOded Gabbay WREG32(mmDMA0_QM_GLBL_CFG1, 0xF << DMA0_QM_GLBL_CFG1_CP_STOP_SHIFT);
3368e65e175bSOded Gabbay WREG32(mmDMA1_QM_GLBL_CFG1, 0xF << DMA0_QM_GLBL_CFG1_CP_STOP_SHIFT);
3369e65e175bSOded Gabbay WREG32(mmDMA5_QM_GLBL_CFG1, 0xF << DMA0_QM_GLBL_CFG1_CP_STOP_SHIFT);
3370e65e175bSOded Gabbay }
3371e65e175bSOded Gabbay
gaudi_stop_hbm_dma_qmans(struct hl_device * hdev)3372e65e175bSOded Gabbay static void gaudi_stop_hbm_dma_qmans(struct hl_device *hdev)
3373e65e175bSOded Gabbay {
3374e65e175bSOded Gabbay struct gaudi_device *gaudi = hdev->asic_specific;
3375e65e175bSOded Gabbay
3376e65e175bSOded Gabbay if (!(gaudi->hw_cap_initialized & HW_CAP_HBM_DMA))
3377e65e175bSOded Gabbay return;
3378e65e175bSOded Gabbay
3379e65e175bSOded Gabbay /* Stop CPs of HBM DMA QMANs */
3380e65e175bSOded Gabbay
3381e65e175bSOded Gabbay WREG32(mmDMA2_QM_GLBL_CFG1, 0x1F << DMA0_QM_GLBL_CFG1_CP_STOP_SHIFT);
3382e65e175bSOded Gabbay WREG32(mmDMA3_QM_GLBL_CFG1, 0x1F << DMA0_QM_GLBL_CFG1_CP_STOP_SHIFT);
3383e65e175bSOded Gabbay WREG32(mmDMA4_QM_GLBL_CFG1, 0x1F << DMA0_QM_GLBL_CFG1_CP_STOP_SHIFT);
3384e65e175bSOded Gabbay WREG32(mmDMA6_QM_GLBL_CFG1, 0x1F << DMA0_QM_GLBL_CFG1_CP_STOP_SHIFT);
3385e65e175bSOded Gabbay WREG32(mmDMA7_QM_GLBL_CFG1, 0x1F << DMA0_QM_GLBL_CFG1_CP_STOP_SHIFT);
3386e65e175bSOded Gabbay }
3387e65e175bSOded Gabbay
gaudi_stop_mme_qmans(struct hl_device * hdev)3388e65e175bSOded Gabbay static void gaudi_stop_mme_qmans(struct hl_device *hdev)
3389e65e175bSOded Gabbay {
3390e65e175bSOded Gabbay struct gaudi_device *gaudi = hdev->asic_specific;
3391e65e175bSOded Gabbay
3392e65e175bSOded Gabbay if (!(gaudi->hw_cap_initialized & HW_CAP_MME))
3393e65e175bSOded Gabbay return;
3394e65e175bSOded Gabbay
3395e65e175bSOded Gabbay /* Stop CPs of MME QMANs */
3396e65e175bSOded Gabbay WREG32(mmMME2_QM_GLBL_CFG1, 0x1F << MME0_QM_GLBL_CFG1_CP_STOP_SHIFT);
3397e65e175bSOded Gabbay WREG32(mmMME0_QM_GLBL_CFG1, 0x1F << MME0_QM_GLBL_CFG1_CP_STOP_SHIFT);
3398e65e175bSOded Gabbay }
3399e65e175bSOded Gabbay
gaudi_stop_tpc_qmans(struct hl_device * hdev)3400e65e175bSOded Gabbay static void gaudi_stop_tpc_qmans(struct hl_device *hdev)
3401e65e175bSOded Gabbay {
3402e65e175bSOded Gabbay struct gaudi_device *gaudi = hdev->asic_specific;
3403e65e175bSOded Gabbay
3404e65e175bSOded Gabbay if (!(gaudi->hw_cap_initialized & HW_CAP_TPC_MASK))
3405e65e175bSOded Gabbay return;
3406e65e175bSOded Gabbay
3407e65e175bSOded Gabbay WREG32(mmTPC0_QM_GLBL_CFG1, 0x1F << TPC0_QM_GLBL_CFG1_CP_STOP_SHIFT);
3408e65e175bSOded Gabbay WREG32(mmTPC1_QM_GLBL_CFG1, 0x1F << TPC0_QM_GLBL_CFG1_CP_STOP_SHIFT);
3409e65e175bSOded Gabbay WREG32(mmTPC2_QM_GLBL_CFG1, 0x1F << TPC0_QM_GLBL_CFG1_CP_STOP_SHIFT);
3410e65e175bSOded Gabbay WREG32(mmTPC3_QM_GLBL_CFG1, 0x1F << TPC0_QM_GLBL_CFG1_CP_STOP_SHIFT);
3411e65e175bSOded Gabbay WREG32(mmTPC4_QM_GLBL_CFG1, 0x1F << TPC0_QM_GLBL_CFG1_CP_STOP_SHIFT);
3412e65e175bSOded Gabbay WREG32(mmTPC5_QM_GLBL_CFG1, 0x1F << TPC0_QM_GLBL_CFG1_CP_STOP_SHIFT);
3413e65e175bSOded Gabbay WREG32(mmTPC6_QM_GLBL_CFG1, 0x1F << TPC0_QM_GLBL_CFG1_CP_STOP_SHIFT);
3414e65e175bSOded Gabbay WREG32(mmTPC7_QM_GLBL_CFG1, 0x1F << TPC0_QM_GLBL_CFG1_CP_STOP_SHIFT);
3415e65e175bSOded Gabbay }
3416e65e175bSOded Gabbay
gaudi_stop_nic_qmans(struct hl_device * hdev)3417e65e175bSOded Gabbay static void gaudi_stop_nic_qmans(struct hl_device *hdev)
3418e65e175bSOded Gabbay {
3419e65e175bSOded Gabbay struct gaudi_device *gaudi = hdev->asic_specific;
3420e65e175bSOded Gabbay
3421e65e175bSOded Gabbay /* Stop upper CPs of QMANs */
3422e65e175bSOded Gabbay
3423e65e175bSOded Gabbay if (gaudi->hw_cap_initialized & HW_CAP_NIC0)
3424e65e175bSOded Gabbay WREG32(mmNIC0_QM0_GLBL_CFG1,
3425e65e175bSOded Gabbay NIC0_QM0_GLBL_CFG1_PQF_STOP_MASK |
3426e65e175bSOded Gabbay NIC0_QM0_GLBL_CFG1_CQF_STOP_MASK |
3427e65e175bSOded Gabbay NIC0_QM0_GLBL_CFG1_CP_STOP_MASK);
3428e65e175bSOded Gabbay
3429e65e175bSOded Gabbay if (gaudi->hw_cap_initialized & HW_CAP_NIC1)
3430e65e175bSOded Gabbay WREG32(mmNIC0_QM1_GLBL_CFG1,
3431e65e175bSOded Gabbay NIC0_QM0_GLBL_CFG1_PQF_STOP_MASK |
3432e65e175bSOded Gabbay NIC0_QM0_GLBL_CFG1_CQF_STOP_MASK |
3433e65e175bSOded Gabbay NIC0_QM0_GLBL_CFG1_CP_STOP_MASK);
3434e65e175bSOded Gabbay
3435e65e175bSOded Gabbay if (gaudi->hw_cap_initialized & HW_CAP_NIC2)
3436e65e175bSOded Gabbay WREG32(mmNIC1_QM0_GLBL_CFG1,
3437e65e175bSOded Gabbay NIC0_QM0_GLBL_CFG1_PQF_STOP_MASK |
3438e65e175bSOded Gabbay NIC0_QM0_GLBL_CFG1_CQF_STOP_MASK |
3439e65e175bSOded Gabbay NIC0_QM0_GLBL_CFG1_CP_STOP_MASK);
3440e65e175bSOded Gabbay
3441e65e175bSOded Gabbay if (gaudi->hw_cap_initialized & HW_CAP_NIC3)
3442e65e175bSOded Gabbay WREG32(mmNIC1_QM1_GLBL_CFG1,
3443e65e175bSOded Gabbay NIC0_QM0_GLBL_CFG1_PQF_STOP_MASK |
3444e65e175bSOded Gabbay NIC0_QM0_GLBL_CFG1_CQF_STOP_MASK |
3445e65e175bSOded Gabbay NIC0_QM0_GLBL_CFG1_CP_STOP_MASK);
3446e65e175bSOded Gabbay
3447e65e175bSOded Gabbay if (gaudi->hw_cap_initialized & HW_CAP_NIC4)
3448e65e175bSOded Gabbay WREG32(mmNIC2_QM0_GLBL_CFG1,
3449e65e175bSOded Gabbay NIC0_QM0_GLBL_CFG1_PQF_STOP_MASK |
3450e65e175bSOded Gabbay NIC0_QM0_GLBL_CFG1_CQF_STOP_MASK |
3451e65e175bSOded Gabbay NIC0_QM0_GLBL_CFG1_CP_STOP_MASK);
3452e65e175bSOded Gabbay
3453e65e175bSOded Gabbay if (gaudi->hw_cap_initialized & HW_CAP_NIC5)
3454e65e175bSOded Gabbay WREG32(mmNIC2_QM1_GLBL_CFG1,
3455e65e175bSOded Gabbay NIC0_QM0_GLBL_CFG1_PQF_STOP_MASK |
3456e65e175bSOded Gabbay NIC0_QM0_GLBL_CFG1_CQF_STOP_MASK |
3457e65e175bSOded Gabbay NIC0_QM0_GLBL_CFG1_CP_STOP_MASK);
3458e65e175bSOded Gabbay
3459e65e175bSOded Gabbay if (gaudi->hw_cap_initialized & HW_CAP_NIC6)
3460e65e175bSOded Gabbay WREG32(mmNIC3_QM0_GLBL_CFG1,
3461e65e175bSOded Gabbay NIC0_QM0_GLBL_CFG1_PQF_STOP_MASK |
3462e65e175bSOded Gabbay NIC0_QM0_GLBL_CFG1_CQF_STOP_MASK |
3463e65e175bSOded Gabbay NIC0_QM0_GLBL_CFG1_CP_STOP_MASK);
3464e65e175bSOded Gabbay
3465e65e175bSOded Gabbay if (gaudi->hw_cap_initialized & HW_CAP_NIC7)
3466e65e175bSOded Gabbay WREG32(mmNIC3_QM1_GLBL_CFG1,
3467e65e175bSOded Gabbay NIC0_QM0_GLBL_CFG1_PQF_STOP_MASK |
3468e65e175bSOded Gabbay NIC0_QM0_GLBL_CFG1_CQF_STOP_MASK |
3469e65e175bSOded Gabbay NIC0_QM0_GLBL_CFG1_CP_STOP_MASK);
3470e65e175bSOded Gabbay
3471e65e175bSOded Gabbay if (gaudi->hw_cap_initialized & HW_CAP_NIC8)
3472e65e175bSOded Gabbay WREG32(mmNIC4_QM0_GLBL_CFG1,
3473e65e175bSOded Gabbay NIC0_QM0_GLBL_CFG1_PQF_STOP_MASK |
3474e65e175bSOded Gabbay NIC0_QM0_GLBL_CFG1_CQF_STOP_MASK |
3475e65e175bSOded Gabbay NIC0_QM0_GLBL_CFG1_CP_STOP_MASK);
3476e65e175bSOded Gabbay
3477e65e175bSOded Gabbay if (gaudi->hw_cap_initialized & HW_CAP_NIC9)
3478e65e175bSOded Gabbay WREG32(mmNIC4_QM1_GLBL_CFG1,
3479e65e175bSOded Gabbay NIC0_QM0_GLBL_CFG1_PQF_STOP_MASK |
3480e65e175bSOded Gabbay NIC0_QM0_GLBL_CFG1_CQF_STOP_MASK |
3481e65e175bSOded Gabbay NIC0_QM0_GLBL_CFG1_CP_STOP_MASK);
3482e65e175bSOded Gabbay }
3483e65e175bSOded Gabbay
gaudi_pci_dma_stall(struct hl_device * hdev)3484e65e175bSOded Gabbay static void gaudi_pci_dma_stall(struct hl_device *hdev)
3485e65e175bSOded Gabbay {
3486e65e175bSOded Gabbay struct gaudi_device *gaudi = hdev->asic_specific;
3487e65e175bSOded Gabbay
3488e65e175bSOded Gabbay if (!(gaudi->hw_cap_initialized & HW_CAP_PCI_DMA))
3489e65e175bSOded Gabbay return;
3490e65e175bSOded Gabbay
3491e65e175bSOded Gabbay WREG32(mmDMA0_CORE_CFG_1, 1 << DMA0_CORE_CFG_1_HALT_SHIFT);
3492e65e175bSOded Gabbay WREG32(mmDMA1_CORE_CFG_1, 1 << DMA0_CORE_CFG_1_HALT_SHIFT);
3493e65e175bSOded Gabbay WREG32(mmDMA5_CORE_CFG_1, 1 << DMA0_CORE_CFG_1_HALT_SHIFT);
3494e65e175bSOded Gabbay }
3495e65e175bSOded Gabbay
gaudi_hbm_dma_stall(struct hl_device * hdev)3496e65e175bSOded Gabbay static void gaudi_hbm_dma_stall(struct hl_device *hdev)
3497e65e175bSOded Gabbay {
3498e65e175bSOded Gabbay struct gaudi_device *gaudi = hdev->asic_specific;
3499e65e175bSOded Gabbay
3500e65e175bSOded Gabbay if (!(gaudi->hw_cap_initialized & HW_CAP_HBM_DMA))
3501e65e175bSOded Gabbay return;
3502e65e175bSOded Gabbay
3503e65e175bSOded Gabbay WREG32(mmDMA2_CORE_CFG_1, 1 << DMA0_CORE_CFG_1_HALT_SHIFT);
3504e65e175bSOded Gabbay WREG32(mmDMA3_CORE_CFG_1, 1 << DMA0_CORE_CFG_1_HALT_SHIFT);
3505e65e175bSOded Gabbay WREG32(mmDMA4_CORE_CFG_1, 1 << DMA0_CORE_CFG_1_HALT_SHIFT);
3506e65e175bSOded Gabbay WREG32(mmDMA6_CORE_CFG_1, 1 << DMA0_CORE_CFG_1_HALT_SHIFT);
3507e65e175bSOded Gabbay WREG32(mmDMA7_CORE_CFG_1, 1 << DMA0_CORE_CFG_1_HALT_SHIFT);
3508e65e175bSOded Gabbay }
3509e65e175bSOded Gabbay
gaudi_mme_stall(struct hl_device * hdev)3510e65e175bSOded Gabbay static void gaudi_mme_stall(struct hl_device *hdev)
3511e65e175bSOded Gabbay {
3512e65e175bSOded Gabbay struct gaudi_device *gaudi = hdev->asic_specific;
3513e65e175bSOded Gabbay
3514e65e175bSOded Gabbay if (!(gaudi->hw_cap_initialized & HW_CAP_MME))
3515e65e175bSOded Gabbay return;
3516e65e175bSOded Gabbay
3517e65e175bSOded Gabbay /* WA for H3-1800 bug: do ACC and SBAB writes twice */
3518e65e175bSOded Gabbay WREG32(mmMME0_ACC_ACC_STALL, 1 << MME_ACC_ACC_STALL_R_SHIFT);
3519e65e175bSOded Gabbay WREG32(mmMME0_ACC_ACC_STALL, 1 << MME_ACC_ACC_STALL_R_SHIFT);
3520e65e175bSOded Gabbay WREG32(mmMME0_SBAB_SB_STALL, 1 << MME_SBAB_SB_STALL_R_SHIFT);
3521e65e175bSOded Gabbay WREG32(mmMME0_SBAB_SB_STALL, 1 << MME_SBAB_SB_STALL_R_SHIFT);
3522e65e175bSOded Gabbay WREG32(mmMME1_ACC_ACC_STALL, 1 << MME_ACC_ACC_STALL_R_SHIFT);
3523e65e175bSOded Gabbay WREG32(mmMME1_ACC_ACC_STALL, 1 << MME_ACC_ACC_STALL_R_SHIFT);
3524e65e175bSOded Gabbay WREG32(mmMME1_SBAB_SB_STALL, 1 << MME_SBAB_SB_STALL_R_SHIFT);
3525e65e175bSOded Gabbay WREG32(mmMME1_SBAB_SB_STALL, 1 << MME_SBAB_SB_STALL_R_SHIFT);
3526e65e175bSOded Gabbay WREG32(mmMME2_ACC_ACC_STALL, 1 << MME_ACC_ACC_STALL_R_SHIFT);
3527e65e175bSOded Gabbay WREG32(mmMME2_ACC_ACC_STALL, 1 << MME_ACC_ACC_STALL_R_SHIFT);
3528e65e175bSOded Gabbay WREG32(mmMME2_SBAB_SB_STALL, 1 << MME_SBAB_SB_STALL_R_SHIFT);
3529e65e175bSOded Gabbay WREG32(mmMME2_SBAB_SB_STALL, 1 << MME_SBAB_SB_STALL_R_SHIFT);
3530e65e175bSOded Gabbay WREG32(mmMME3_ACC_ACC_STALL, 1 << MME_ACC_ACC_STALL_R_SHIFT);
3531e65e175bSOded Gabbay WREG32(mmMME3_ACC_ACC_STALL, 1 << MME_ACC_ACC_STALL_R_SHIFT);
3532e65e175bSOded Gabbay WREG32(mmMME3_SBAB_SB_STALL, 1 << MME_SBAB_SB_STALL_R_SHIFT);
3533e65e175bSOded Gabbay WREG32(mmMME3_SBAB_SB_STALL, 1 << MME_SBAB_SB_STALL_R_SHIFT);
3534e65e175bSOded Gabbay }
3535e65e175bSOded Gabbay
gaudi_tpc_stall(struct hl_device * hdev)3536e65e175bSOded Gabbay static void gaudi_tpc_stall(struct hl_device *hdev)
3537e65e175bSOded Gabbay {
3538e65e175bSOded Gabbay struct gaudi_device *gaudi = hdev->asic_specific;
3539e65e175bSOded Gabbay
3540e65e175bSOded Gabbay if (!(gaudi->hw_cap_initialized & HW_CAP_TPC_MASK))
3541e65e175bSOded Gabbay return;
3542e65e175bSOded Gabbay
3543e65e175bSOded Gabbay WREG32(mmTPC0_CFG_TPC_STALL, 1 << TPC0_CFG_TPC_STALL_V_SHIFT);
3544e65e175bSOded Gabbay WREG32(mmTPC1_CFG_TPC_STALL, 1 << TPC0_CFG_TPC_STALL_V_SHIFT);
3545e65e175bSOded Gabbay WREG32(mmTPC2_CFG_TPC_STALL, 1 << TPC0_CFG_TPC_STALL_V_SHIFT);
3546e65e175bSOded Gabbay WREG32(mmTPC3_CFG_TPC_STALL, 1 << TPC0_CFG_TPC_STALL_V_SHIFT);
3547e65e175bSOded Gabbay WREG32(mmTPC4_CFG_TPC_STALL, 1 << TPC0_CFG_TPC_STALL_V_SHIFT);
3548e65e175bSOded Gabbay WREG32(mmTPC5_CFG_TPC_STALL, 1 << TPC0_CFG_TPC_STALL_V_SHIFT);
3549e65e175bSOded Gabbay WREG32(mmTPC6_CFG_TPC_STALL, 1 << TPC0_CFG_TPC_STALL_V_SHIFT);
3550e65e175bSOded Gabbay WREG32(mmTPC7_CFG_TPC_STALL, 1 << TPC0_CFG_TPC_STALL_V_SHIFT);
3551e65e175bSOded Gabbay }
3552e65e175bSOded Gabbay
gaudi_disable_clock_gating(struct hl_device * hdev)3553e65e175bSOded Gabbay static void gaudi_disable_clock_gating(struct hl_device *hdev)
3554e65e175bSOded Gabbay {
3555e65e175bSOded Gabbay u32 qman_offset;
3556e65e175bSOded Gabbay int i;
3557e65e175bSOded Gabbay
3558e65e175bSOded Gabbay if (hdev->asic_prop.fw_security_enabled)
3559e65e175bSOded Gabbay return;
3560e65e175bSOded Gabbay
3561e65e175bSOded Gabbay for (i = 0, qman_offset = 0 ; i < DMA_NUMBER_OF_CHANNELS ; i++) {
3562e65e175bSOded Gabbay WREG32(mmDMA0_QM_CGM_CFG + qman_offset, 0);
3563e65e175bSOded Gabbay WREG32(mmDMA0_QM_CGM_CFG1 + qman_offset, 0);
3564e65e175bSOded Gabbay
3565e65e175bSOded Gabbay qman_offset += (mmDMA1_QM_CGM_CFG - mmDMA0_QM_CGM_CFG);
3566e65e175bSOded Gabbay }
3567e65e175bSOded Gabbay
3568e65e175bSOded Gabbay WREG32(mmMME0_QM_CGM_CFG, 0);
3569e65e175bSOded Gabbay WREG32(mmMME0_QM_CGM_CFG1, 0);
3570e65e175bSOded Gabbay WREG32(mmMME2_QM_CGM_CFG, 0);
3571e65e175bSOded Gabbay WREG32(mmMME2_QM_CGM_CFG1, 0);
3572e65e175bSOded Gabbay
3573e65e175bSOded Gabbay for (i = 0, qman_offset = 0 ; i < TPC_NUMBER_OF_ENGINES ; i++) {
3574e65e175bSOded Gabbay WREG32(mmTPC0_QM_CGM_CFG + qman_offset, 0);
3575e65e175bSOded Gabbay WREG32(mmTPC0_QM_CGM_CFG1 + qman_offset, 0);
3576e65e175bSOded Gabbay
3577e65e175bSOded Gabbay qman_offset += (mmTPC1_QM_CGM_CFG - mmTPC0_QM_CGM_CFG);
3578e65e175bSOded Gabbay }
3579e65e175bSOded Gabbay }
3580e65e175bSOded Gabbay
gaudi_enable_timestamp(struct hl_device * hdev)3581e65e175bSOded Gabbay static void gaudi_enable_timestamp(struct hl_device *hdev)
3582e65e175bSOded Gabbay {
3583e65e175bSOded Gabbay /* Disable the timestamp counter */
3584e65e175bSOded Gabbay WREG32(mmPSOC_TIMESTAMP_BASE - CFG_BASE, 0);
3585e65e175bSOded Gabbay
3586e65e175bSOded Gabbay /* Zero the lower/upper parts of the 64-bit counter */
3587e65e175bSOded Gabbay WREG32(mmPSOC_TIMESTAMP_BASE - CFG_BASE + 0xC, 0);
3588e65e175bSOded Gabbay WREG32(mmPSOC_TIMESTAMP_BASE - CFG_BASE + 0x8, 0);
3589e65e175bSOded Gabbay
3590e65e175bSOded Gabbay /* Enable the counter */
3591e65e175bSOded Gabbay WREG32(mmPSOC_TIMESTAMP_BASE - CFG_BASE, 1);
3592e65e175bSOded Gabbay }
3593e65e175bSOded Gabbay
gaudi_disable_timestamp(struct hl_device * hdev)3594e65e175bSOded Gabbay static void gaudi_disable_timestamp(struct hl_device *hdev)
3595e65e175bSOded Gabbay {
3596e65e175bSOded Gabbay /* Disable the timestamp counter */
3597e65e175bSOded Gabbay WREG32(mmPSOC_TIMESTAMP_BASE - CFG_BASE, 0);
3598e65e175bSOded Gabbay }
3599e65e175bSOded Gabbay
gaudi_halt_engines(struct hl_device * hdev,bool hard_reset,bool fw_reset)3600e65e175bSOded Gabbay static void gaudi_halt_engines(struct hl_device *hdev, bool hard_reset, bool fw_reset)
3601e65e175bSOded Gabbay {
3602e65e175bSOded Gabbay u32 wait_timeout_ms;
3603e65e175bSOded Gabbay
3604e65e175bSOded Gabbay if (hdev->pldm)
3605e65e175bSOded Gabbay wait_timeout_ms = GAUDI_PLDM_RESET_WAIT_MSEC;
3606e65e175bSOded Gabbay else
3607e65e175bSOded Gabbay wait_timeout_ms = GAUDI_RESET_WAIT_MSEC;
3608e65e175bSOded Gabbay
3609e65e175bSOded Gabbay if (fw_reset)
3610e65e175bSOded Gabbay goto skip_engines;
3611e65e175bSOded Gabbay
3612e65e175bSOded Gabbay gaudi_stop_nic_qmans(hdev);
3613e65e175bSOded Gabbay gaudi_stop_mme_qmans(hdev);
3614e65e175bSOded Gabbay gaudi_stop_tpc_qmans(hdev);
3615e65e175bSOded Gabbay gaudi_stop_hbm_dma_qmans(hdev);
3616e65e175bSOded Gabbay gaudi_stop_pci_dma_qmans(hdev);
3617e65e175bSOded Gabbay
3618e65e175bSOded Gabbay msleep(wait_timeout_ms);
3619e65e175bSOded Gabbay
3620e65e175bSOded Gabbay gaudi_pci_dma_stall(hdev);
3621e65e175bSOded Gabbay gaudi_hbm_dma_stall(hdev);
3622e65e175bSOded Gabbay gaudi_tpc_stall(hdev);
3623e65e175bSOded Gabbay gaudi_mme_stall(hdev);
3624e65e175bSOded Gabbay
3625e65e175bSOded Gabbay msleep(wait_timeout_ms);
3626e65e175bSOded Gabbay
3627e65e175bSOded Gabbay gaudi_disable_nic_qmans(hdev);
3628e65e175bSOded Gabbay gaudi_disable_mme_qmans(hdev);
3629e65e175bSOded Gabbay gaudi_disable_tpc_qmans(hdev);
3630e65e175bSOded Gabbay gaudi_disable_hbm_dma_qmans(hdev);
3631e65e175bSOded Gabbay gaudi_disable_pci_dma_qmans(hdev);
3632e65e175bSOded Gabbay
3633e65e175bSOded Gabbay gaudi_disable_timestamp(hdev);
3634e65e175bSOded Gabbay
3635e65e175bSOded Gabbay skip_engines:
3636e65e175bSOded Gabbay gaudi_disable_msi(hdev);
3637e65e175bSOded Gabbay }
3638e65e175bSOded Gabbay
gaudi_mmu_init(struct hl_device * hdev)3639e65e175bSOded Gabbay static int gaudi_mmu_init(struct hl_device *hdev)
3640e65e175bSOded Gabbay {
3641e65e175bSOded Gabbay struct asic_fixed_properties *prop = &hdev->asic_prop;
3642e65e175bSOded Gabbay struct gaudi_device *gaudi = hdev->asic_specific;
3643e65e175bSOded Gabbay u64 hop0_addr;
3644e65e175bSOded Gabbay int rc, i;
3645e65e175bSOded Gabbay
3646e65e175bSOded Gabbay if (gaudi->hw_cap_initialized & HW_CAP_MMU)
3647e65e175bSOded Gabbay return 0;
3648e65e175bSOded Gabbay
3649e65e175bSOded Gabbay for (i = 0 ; i < prop->max_asid ; i++) {
3650e65e175bSOded Gabbay hop0_addr = prop->mmu_pgt_addr +
3651e65e175bSOded Gabbay (i * prop->mmu_hop_table_size);
3652e65e175bSOded Gabbay
3653e65e175bSOded Gabbay rc = gaudi_mmu_update_asid_hop0_addr(hdev, i, hop0_addr);
3654e65e175bSOded Gabbay if (rc) {
3655e65e175bSOded Gabbay dev_err(hdev->dev,
3656e65e175bSOded Gabbay "failed to set hop0 addr for asid %d\n", i);
3657e65e175bSOded Gabbay return rc;
3658e65e175bSOded Gabbay }
3659e65e175bSOded Gabbay }
3660e65e175bSOded Gabbay
3661e65e175bSOded Gabbay /* init MMU cache manage page */
3662e65e175bSOded Gabbay WREG32(mmSTLB_CACHE_INV_BASE_39_8, prop->mmu_cache_mng_addr >> 8);
3663e65e175bSOded Gabbay WREG32(mmSTLB_CACHE_INV_BASE_49_40, prop->mmu_cache_mng_addr >> 40);
3664e65e175bSOded Gabbay
3665e65e175bSOded Gabbay /* mem cache invalidation */
3666e65e175bSOded Gabbay WREG32(mmSTLB_MEM_CACHE_INVALIDATION, 1);
3667e65e175bSOded Gabbay
3668af5e675fSKoby Elbaz rc = hl_mmu_invalidate_cache(hdev, true, 0);
3669e65e175bSOded Gabbay if (rc)
3670e65e175bSOded Gabbay return rc;
3671e65e175bSOded Gabbay
3672e65e175bSOded Gabbay WREG32(mmMMU_UP_MMU_ENABLE, 1);
3673e65e175bSOded Gabbay WREG32(mmMMU_UP_SPI_MASK, 0xF);
3674e65e175bSOded Gabbay
3675e65e175bSOded Gabbay WREG32(mmSTLB_HOP_CONFIGURATION, 0x30440);
3676e65e175bSOded Gabbay
3677e65e175bSOded Gabbay /*
3678e65e175bSOded Gabbay * The H/W expects the first PI after init to be 1. After wraparound
3679af5e675fSKoby Elbaz * we'll write 0.
3680af5e675fSKoby Elbaz */
3681af5e675fSKoby Elbaz gaudi->mmu_cache_inv_pi = 1;
3682e65e175bSOded Gabbay
3683e65e175bSOded Gabbay gaudi->hw_cap_initialized |= HW_CAP_MMU;
3684e65e175bSOded Gabbay
3685e65e175bSOded Gabbay return 0;
3686e65e175bSOded Gabbay }
3687e65e175bSOded Gabbay
gaudi_load_firmware_to_device(struct hl_device * hdev)3688e65e175bSOded Gabbay static int gaudi_load_firmware_to_device(struct hl_device *hdev)
3689e65e175bSOded Gabbay {
3690e65e175bSOded Gabbay void __iomem *dst;
3691e65e175bSOded Gabbay
3692e65e175bSOded Gabbay dst = hdev->pcie_bar[HBM_BAR_ID] + LINUX_FW_OFFSET;
3693e65e175bSOded Gabbay
3694e65e175bSOded Gabbay return hl_fw_load_fw_to_device(hdev, GAUDI_LINUX_FW_FILE, dst, 0, 0);
3695e65e175bSOded Gabbay }
3696e65e175bSOded Gabbay
gaudi_load_boot_fit_to_device(struct hl_device * hdev)3697e65e175bSOded Gabbay static int gaudi_load_boot_fit_to_device(struct hl_device *hdev)
3698e65e175bSOded Gabbay {
3699e65e175bSOded Gabbay void __iomem *dst;
3700e65e175bSOded Gabbay
3701e65e175bSOded Gabbay dst = hdev->pcie_bar[SRAM_BAR_ID] + BOOT_FIT_SRAM_OFFSET;
3702e65e175bSOded Gabbay
3703e65e175bSOded Gabbay return hl_fw_load_fw_to_device(hdev, GAUDI_BOOT_FIT_FILE, dst, 0, 0);
3704e65e175bSOded Gabbay }
3705e65e175bSOded Gabbay
gaudi_init_dynamic_firmware_loader(struct hl_device * hdev)3706e65e175bSOded Gabbay static void gaudi_init_dynamic_firmware_loader(struct hl_device *hdev)
3707e65e175bSOded Gabbay {
3708e65e175bSOded Gabbay struct dynamic_fw_load_mgr *dynamic_loader;
3709e65e175bSOded Gabbay struct cpu_dyn_regs *dyn_regs;
3710e65e175bSOded Gabbay
3711e65e175bSOded Gabbay dynamic_loader = &hdev->fw_loader.dynamic_loader;
3712e65e175bSOded Gabbay
3713e65e175bSOded Gabbay /*
3714e65e175bSOded Gabbay * here we update initial values for few specific dynamic regs (as
3715e65e175bSOded Gabbay * before reading the first descriptor from FW those value has to be
3716e65e175bSOded Gabbay * hard-coded) in later stages of the protocol those values will be
3717e65e175bSOded Gabbay * updated automatically by reading the FW descriptor so data there
3718e65e175bSOded Gabbay * will always be up-to-date
3719e65e175bSOded Gabbay */
3720e65e175bSOded Gabbay dyn_regs = &dynamic_loader->comm_desc.cpu_dyn_regs;
3721e65e175bSOded Gabbay dyn_regs->kmd_msg_to_cpu =
3722e65e175bSOded Gabbay cpu_to_le32(mmPSOC_GLOBAL_CONF_KMD_MSG_TO_CPU);
3723e65e175bSOded Gabbay dyn_regs->cpu_cmd_status_to_host =
3724e65e175bSOded Gabbay cpu_to_le32(mmCPU_CMD_STATUS_TO_HOST);
3725e65e175bSOded Gabbay
3726e65e175bSOded Gabbay dynamic_loader->wait_for_bl_timeout = GAUDI_WAIT_FOR_BL_TIMEOUT_USEC;
3727e65e175bSOded Gabbay }
3728e65e175bSOded Gabbay
gaudi_init_static_firmware_loader(struct hl_device * hdev)3729e65e175bSOded Gabbay static void gaudi_init_static_firmware_loader(struct hl_device *hdev)
3730e65e175bSOded Gabbay {
3731e65e175bSOded Gabbay struct static_fw_load_mgr *static_loader;
3732e65e175bSOded Gabbay
3733e65e175bSOded Gabbay static_loader = &hdev->fw_loader.static_loader;
3734e65e175bSOded Gabbay
3735e65e175bSOded Gabbay static_loader->preboot_version_max_off = SRAM_SIZE - VERSION_MAX_LEN;
3736e65e175bSOded Gabbay static_loader->boot_fit_version_max_off = SRAM_SIZE - VERSION_MAX_LEN;
3737e65e175bSOded Gabbay static_loader->kmd_msg_to_cpu_reg = mmPSOC_GLOBAL_CONF_KMD_MSG_TO_CPU;
3738e65e175bSOded Gabbay static_loader->cpu_cmd_status_to_host_reg = mmCPU_CMD_STATUS_TO_HOST;
3739e65e175bSOded Gabbay static_loader->cpu_boot_status_reg = mmPSOC_GLOBAL_CONF_CPU_BOOT_STATUS;
3740e65e175bSOded Gabbay static_loader->cpu_boot_dev_status0_reg = mmCPU_BOOT_DEV_STS0;
3741e65e175bSOded Gabbay static_loader->cpu_boot_dev_status1_reg = mmCPU_BOOT_DEV_STS1;
3742e65e175bSOded Gabbay static_loader->boot_err0_reg = mmCPU_BOOT_ERR0;
3743e65e175bSOded Gabbay static_loader->boot_err1_reg = mmCPU_BOOT_ERR1;
3744e65e175bSOded Gabbay static_loader->preboot_version_offset_reg = mmPREBOOT_VER_OFFSET;
3745e65e175bSOded Gabbay static_loader->boot_fit_version_offset_reg = mmUBOOT_VER_OFFSET;
3746e65e175bSOded Gabbay static_loader->sram_offset_mask = ~(lower_32_bits(SRAM_BASE_ADDR));
3747e65e175bSOded Gabbay static_loader->cpu_reset_wait_msec = hdev->pldm ?
3748e65e175bSOded Gabbay GAUDI_PLDM_RESET_WAIT_MSEC :
3749e65e175bSOded Gabbay GAUDI_CPU_RESET_WAIT_MSEC;
3750e65e175bSOded Gabbay }
3751e65e175bSOded Gabbay
gaudi_init_firmware_preload_params(struct hl_device * hdev)3752e65e175bSOded Gabbay static void gaudi_init_firmware_preload_params(struct hl_device *hdev)
3753e65e175bSOded Gabbay {
3754e65e175bSOded Gabbay struct pre_fw_load_props *pre_fw_load = &hdev->fw_loader.pre_fw_load;
3755e65e175bSOded Gabbay
3756e65e175bSOded Gabbay pre_fw_load->cpu_boot_status_reg = mmPSOC_GLOBAL_CONF_CPU_BOOT_STATUS;
3757e65e175bSOded Gabbay pre_fw_load->sts_boot_dev_sts0_reg = mmCPU_BOOT_DEV_STS0;
3758e65e175bSOded Gabbay pre_fw_load->sts_boot_dev_sts1_reg = mmCPU_BOOT_DEV_STS1;
3759e65e175bSOded Gabbay pre_fw_load->boot_err0_reg = mmCPU_BOOT_ERR0;
3760e65e175bSOded Gabbay pre_fw_load->boot_err1_reg = mmCPU_BOOT_ERR1;
3761e65e175bSOded Gabbay pre_fw_load->wait_for_preboot_timeout = GAUDI_BOOT_FIT_REQ_TIMEOUT_USEC;
3762e65e175bSOded Gabbay }
3763e65e175bSOded Gabbay
gaudi_init_firmware_loader(struct hl_device * hdev)3764e65e175bSOded Gabbay static void gaudi_init_firmware_loader(struct hl_device *hdev)
3765e65e175bSOded Gabbay {
3766e65e175bSOded Gabbay struct asic_fixed_properties *prop = &hdev->asic_prop;
3767e65e175bSOded Gabbay struct fw_load_mgr *fw_loader = &hdev->fw_loader;
3768e65e175bSOded Gabbay
3769e65e175bSOded Gabbay /* fill common fields */
3770e65e175bSOded Gabbay fw_loader->fw_comp_loaded = FW_TYPE_NONE;
3771e65e175bSOded Gabbay fw_loader->boot_fit_img.image_name = GAUDI_BOOT_FIT_FILE;
3772e65e175bSOded Gabbay fw_loader->linux_img.image_name = GAUDI_LINUX_FW_FILE;
3773e65e175bSOded Gabbay fw_loader->cpu_timeout = GAUDI_CPU_TIMEOUT_USEC;
3774e65e175bSOded Gabbay fw_loader->boot_fit_timeout = GAUDI_BOOT_FIT_REQ_TIMEOUT_USEC;
3775e65e175bSOded Gabbay fw_loader->skip_bmc = !hdev->bmc_enable;
3776e65e175bSOded Gabbay fw_loader->sram_bar_id = SRAM_BAR_ID;
3777e65e175bSOded Gabbay fw_loader->dram_bar_id = HBM_BAR_ID;
3778e65e175bSOded Gabbay
3779e65e175bSOded Gabbay if (prop->dynamic_fw_load)
3780e65e175bSOded Gabbay gaudi_init_dynamic_firmware_loader(hdev);
3781e65e175bSOded Gabbay else
3782e65e175bSOded Gabbay gaudi_init_static_firmware_loader(hdev);
3783e65e175bSOded Gabbay }
3784e65e175bSOded Gabbay
gaudi_init_cpu(struct hl_device * hdev)3785e65e175bSOded Gabbay static int gaudi_init_cpu(struct hl_device *hdev)
3786e65e175bSOded Gabbay {
3787e65e175bSOded Gabbay struct gaudi_device *gaudi = hdev->asic_specific;
3788e65e175bSOded Gabbay int rc;
3789e65e175bSOded Gabbay
3790e65e175bSOded Gabbay if (!(hdev->fw_components & FW_TYPE_PREBOOT_CPU))
3791e65e175bSOded Gabbay return 0;
3792e65e175bSOded Gabbay
3793e65e175bSOded Gabbay if (gaudi->hw_cap_initialized & HW_CAP_CPU)
3794e65e175bSOded Gabbay return 0;
3795e65e175bSOded Gabbay
3796e65e175bSOded Gabbay /*
3797e65e175bSOded Gabbay * The device CPU works with 40 bits addresses.
3798e65e175bSOded Gabbay * This register sets the extension to 50 bits.
3799e65e175bSOded Gabbay */
3800e65e175bSOded Gabbay if (!hdev->asic_prop.fw_security_enabled)
3801e65e175bSOded Gabbay WREG32(mmCPU_IF_CPU_MSB_ADDR, hdev->cpu_pci_msb_addr);
3802e65e175bSOded Gabbay
3803e65e175bSOded Gabbay rc = hl_fw_init_cpu(hdev);
3804e65e175bSOded Gabbay
3805e65e175bSOded Gabbay if (rc)
3806e65e175bSOded Gabbay return rc;
3807e65e175bSOded Gabbay
3808e65e175bSOded Gabbay gaudi->hw_cap_initialized |= HW_CAP_CPU;
3809e65e175bSOded Gabbay
3810e65e175bSOded Gabbay return 0;
3811e65e175bSOded Gabbay }
3812e65e175bSOded Gabbay
gaudi_init_cpu_queues(struct hl_device * hdev,u32 cpu_timeout)3813e65e175bSOded Gabbay static int gaudi_init_cpu_queues(struct hl_device *hdev, u32 cpu_timeout)
3814e65e175bSOded Gabbay {
3815e65e175bSOded Gabbay struct cpu_dyn_regs *dyn_regs =
3816e65e175bSOded Gabbay &hdev->fw_loader.dynamic_loader.comm_desc.cpu_dyn_regs;
3817e65e175bSOded Gabbay struct asic_fixed_properties *prop = &hdev->asic_prop;
3818e65e175bSOded Gabbay struct gaudi_device *gaudi = hdev->asic_specific;
3819e65e175bSOded Gabbay u32 status, irq_handler_offset;
3820e65e175bSOded Gabbay struct hl_eq *eq;
3821e65e175bSOded Gabbay struct hl_hw_queue *cpu_pq =
3822e65e175bSOded Gabbay &hdev->kernel_queues[GAUDI_QUEUE_ID_CPU_PQ];
3823e65e175bSOded Gabbay int err;
3824e65e175bSOded Gabbay
3825e65e175bSOded Gabbay if (!hdev->cpu_queues_enable)
3826e65e175bSOded Gabbay return 0;
3827e65e175bSOded Gabbay
3828e65e175bSOded Gabbay if (gaudi->hw_cap_initialized & HW_CAP_CPU_Q)
3829e65e175bSOded Gabbay return 0;
3830e65e175bSOded Gabbay
3831e65e175bSOded Gabbay eq = &hdev->event_queue;
3832e65e175bSOded Gabbay
3833e65e175bSOded Gabbay WREG32(mmCPU_IF_PQ_BASE_ADDR_LOW, lower_32_bits(cpu_pq->bus_address));
3834e65e175bSOded Gabbay WREG32(mmCPU_IF_PQ_BASE_ADDR_HIGH, upper_32_bits(cpu_pq->bus_address));
3835e65e175bSOded Gabbay
3836e65e175bSOded Gabbay WREG32(mmCPU_IF_EQ_BASE_ADDR_LOW, lower_32_bits(eq->bus_address));
3837e65e175bSOded Gabbay WREG32(mmCPU_IF_EQ_BASE_ADDR_HIGH, upper_32_bits(eq->bus_address));
3838e65e175bSOded Gabbay
3839e65e175bSOded Gabbay WREG32(mmCPU_IF_CQ_BASE_ADDR_LOW,
3840e65e175bSOded Gabbay lower_32_bits(hdev->cpu_accessible_dma_address));
3841e65e175bSOded Gabbay WREG32(mmCPU_IF_CQ_BASE_ADDR_HIGH,
3842e65e175bSOded Gabbay upper_32_bits(hdev->cpu_accessible_dma_address));
3843e65e175bSOded Gabbay
3844e65e175bSOded Gabbay WREG32(mmCPU_IF_PQ_LENGTH, HL_QUEUE_SIZE_IN_BYTES);
3845e65e175bSOded Gabbay WREG32(mmCPU_IF_EQ_LENGTH, HL_EQ_SIZE_IN_BYTES);
3846e65e175bSOded Gabbay WREG32(mmCPU_IF_CQ_LENGTH, HL_CPU_ACCESSIBLE_MEM_SIZE);
3847e65e175bSOded Gabbay
3848e65e175bSOded Gabbay /* Used for EQ CI */
3849e65e175bSOded Gabbay WREG32(mmCPU_IF_EQ_RD_OFFS, 0);
3850e65e175bSOded Gabbay
3851e65e175bSOded Gabbay WREG32(mmCPU_IF_PF_PQ_PI, 0);
3852e65e175bSOded Gabbay
3853e65e175bSOded Gabbay WREG32(mmCPU_IF_QUEUE_INIT, PQ_INIT_STATUS_READY_FOR_CP_SINGLE_MSI);
3854e65e175bSOded Gabbay
3855e65e175bSOded Gabbay irq_handler_offset = prop->gic_interrupts_enable ?
3856e65e175bSOded Gabbay mmGIC_DISTRIBUTOR__5_GICD_SETSPI_NSR :
3857e65e175bSOded Gabbay le32_to_cpu(dyn_regs->gic_host_pi_upd_irq);
3858e65e175bSOded Gabbay
3859e65e175bSOded Gabbay WREG32(irq_handler_offset,
3860e65e175bSOded Gabbay gaudi_irq_map_table[GAUDI_EVENT_PI_UPDATE].cpu_id);
3861e65e175bSOded Gabbay
3862e65e175bSOded Gabbay err = hl_poll_timeout(
3863e65e175bSOded Gabbay hdev,
3864*b207e166SOfir Bitton mmCPU_IF_QUEUE_INIT,
3865e65e175bSOded Gabbay status,
3866e65e175bSOded Gabbay (status == PQ_INIT_STATUS_READY_FOR_HOST),
3867e65e175bSOded Gabbay 1000,
3868e65e175bSOded Gabbay cpu_timeout);
3869e65e175bSOded Gabbay
3870e65e175bSOded Gabbay if (err) {
3871e65e175bSOded Gabbay dev_err(hdev->dev,
3872e65e175bSOded Gabbay "Failed to communicate with Device CPU (CPU-CP timeout)\n");
3873e65e175bSOded Gabbay return -EIO;
3874e65e175bSOded Gabbay }
3875e65e175bSOded Gabbay
3876e65e175bSOded Gabbay /* update FW application security bits */
3877e65e175bSOded Gabbay if (prop->fw_cpu_boot_dev_sts0_valid)
3878e65e175bSOded Gabbay prop->fw_app_cpu_boot_dev_sts0 = RREG32(mmCPU_BOOT_DEV_STS0);
3879e65e175bSOded Gabbay if (prop->fw_cpu_boot_dev_sts1_valid)
3880e65e175bSOded Gabbay prop->fw_app_cpu_boot_dev_sts1 = RREG32(mmCPU_BOOT_DEV_STS1);
3881e65e175bSOded Gabbay
3882e65e175bSOded Gabbay gaudi->hw_cap_initialized |= HW_CAP_CPU_Q;
3883e65e175bSOded Gabbay return 0;
3884e65e175bSOded Gabbay }
3885e65e175bSOded Gabbay
gaudi_pre_hw_init(struct hl_device * hdev)3886e65e175bSOded Gabbay static void gaudi_pre_hw_init(struct hl_device *hdev)
3887e65e175bSOded Gabbay {
3888e65e175bSOded Gabbay /* Perform read from the device to make sure device is up */
3889e65e175bSOded Gabbay RREG32(mmHW_STATE);
3890e65e175bSOded Gabbay
3891e65e175bSOded Gabbay if (!hdev->asic_prop.fw_security_enabled) {
3892e65e175bSOded Gabbay /* Set the access through PCI bars (Linux driver only) as
3893e65e175bSOded Gabbay * secured
3894e65e175bSOded Gabbay */
3895e65e175bSOded Gabbay WREG32(mmPCIE_WRAP_LBW_PROT_OVR,
3896e65e175bSOded Gabbay (PCIE_WRAP_LBW_PROT_OVR_RD_EN_MASK |
3897e65e175bSOded Gabbay PCIE_WRAP_LBW_PROT_OVR_WR_EN_MASK));
3898e65e175bSOded Gabbay
3899e65e175bSOded Gabbay /* Perform read to flush the waiting writes to ensure
3900e65e175bSOded Gabbay * configuration was set in the device
3901e65e175bSOded Gabbay */
3902e65e175bSOded Gabbay RREG32(mmPCIE_WRAP_LBW_PROT_OVR);
3903e65e175bSOded Gabbay }
3904e65e175bSOded Gabbay
3905e65e175bSOded Gabbay /*
3906e65e175bSOded Gabbay * Let's mark in the H/W that we have reached this point. We check
3907e65e175bSOded Gabbay * this value in the reset_before_init function to understand whether
3908e65e175bSOded Gabbay * we need to reset the chip before doing H/W init. This register is
3909e65e175bSOded Gabbay * cleared by the H/W upon H/W reset
3910e65e175bSOded Gabbay */
3911e65e175bSOded Gabbay WREG32(mmHW_STATE, HL_DEVICE_HW_STATE_DIRTY);
3912e65e175bSOded Gabbay }
3913e65e175bSOded Gabbay
gaudi_hw_init(struct hl_device * hdev)3914e65e175bSOded Gabbay static int gaudi_hw_init(struct hl_device *hdev)
3915e65e175bSOded Gabbay {
3916e65e175bSOded Gabbay struct gaudi_device *gaudi = hdev->asic_specific;
3917e65e175bSOded Gabbay int rc;
3918e65e175bSOded Gabbay
3919e65e175bSOded Gabbay gaudi_pre_hw_init(hdev);
3920e65e175bSOded Gabbay
3921e65e175bSOded Gabbay /* If iATU is done by FW, the HBM bar ALWAYS points to DRAM_PHYS_BASE.
3922e65e175bSOded Gabbay * So we set it here and if anyone tries to move it later to
3923e65e175bSOded Gabbay * a different address, there will be an error
3924e65e175bSOded Gabbay */
3925e65e175bSOded Gabbay if (hdev->asic_prop.iatu_done_by_fw)
3926e65e175bSOded Gabbay gaudi->hbm_bar_cur_addr = DRAM_PHYS_BASE;
3927e65e175bSOded Gabbay
3928e65e175bSOded Gabbay /*
3929e65e175bSOded Gabbay * Before pushing u-boot/linux to device, need to set the hbm bar to
3930e65e175bSOded Gabbay * base address of dram
3931e65e175bSOded Gabbay */
3932e65e175bSOded Gabbay if (gaudi_set_hbm_bar_base(hdev, DRAM_PHYS_BASE) == U64_MAX) {
3933e65e175bSOded Gabbay dev_err(hdev->dev,
3934e65e175bSOded Gabbay "failed to map HBM bar to DRAM base address\n");
3935e65e175bSOded Gabbay return -EIO;
3936e65e175bSOded Gabbay }
3937e65e175bSOded Gabbay
3938e65e175bSOded Gabbay rc = gaudi_init_cpu(hdev);
3939e65e175bSOded Gabbay if (rc) {
3940e65e175bSOded Gabbay dev_err(hdev->dev, "failed to initialize CPU\n");
3941e65e175bSOded Gabbay return rc;
3942e65e175bSOded Gabbay }
3943e65e175bSOded Gabbay
3944e65e175bSOded Gabbay /* In case the clock gating was enabled in preboot we need to disable
3945e65e175bSOded Gabbay * it here before touching the MME/TPC registers.
3946e65e175bSOded Gabbay */
3947e65e175bSOded Gabbay gaudi_disable_clock_gating(hdev);
3948e65e175bSOded Gabbay
3949e65e175bSOded Gabbay /* SRAM scrambler must be initialized after CPU is running from HBM */
3950e65e175bSOded Gabbay gaudi_init_scrambler_sram(hdev);
3951e65e175bSOded Gabbay
3952e65e175bSOded Gabbay /* This is here just in case we are working without CPU */
3953e65e175bSOded Gabbay gaudi_init_scrambler_hbm(hdev);
3954e65e175bSOded Gabbay
3955e65e175bSOded Gabbay gaudi_init_golden_registers(hdev);
3956e65e175bSOded Gabbay
3957e65e175bSOded Gabbay rc = gaudi_mmu_init(hdev);
3958e65e175bSOded Gabbay if (rc)
3959e65e175bSOded Gabbay return rc;
3960e65e175bSOded Gabbay
3961e65e175bSOded Gabbay gaudi_init_security(hdev);
3962e65e175bSOded Gabbay
3963e65e175bSOded Gabbay gaudi_init_pci_dma_qmans(hdev);
3964e65e175bSOded Gabbay
3965e65e175bSOded Gabbay gaudi_init_hbm_dma_qmans(hdev);
3966e65e175bSOded Gabbay
3967e65e175bSOded Gabbay gaudi_init_mme_qmans(hdev);
3968e65e175bSOded Gabbay
3969e65e175bSOded Gabbay gaudi_init_tpc_qmans(hdev);
3970e65e175bSOded Gabbay
3971e65e175bSOded Gabbay gaudi_init_nic_qmans(hdev);
3972e65e175bSOded Gabbay
3973e65e175bSOded Gabbay gaudi_enable_timestamp(hdev);
3974e65e175bSOded Gabbay
3975e65e175bSOded Gabbay /* MSI must be enabled before CPU queues and NIC are initialized */
3976e65e175bSOded Gabbay rc = gaudi_enable_msi(hdev);
3977e65e175bSOded Gabbay if (rc)
3978e65e175bSOded Gabbay goto disable_queues;
3979e65e175bSOded Gabbay
3980e65e175bSOded Gabbay /* must be called after MSI was enabled */
3981e65e175bSOded Gabbay rc = gaudi_init_cpu_queues(hdev, GAUDI_CPU_TIMEOUT_USEC);
3982e65e175bSOded Gabbay if (rc) {
3983e65e175bSOded Gabbay dev_err(hdev->dev, "failed to initialize CPU H/W queues %d\n",
3984e65e175bSOded Gabbay rc);
3985e65e175bSOded Gabbay goto disable_msi;
3986e65e175bSOded Gabbay }
3987e65e175bSOded Gabbay
3988e65e175bSOded Gabbay /* Perform read from the device to flush all configuration */
3989e65e175bSOded Gabbay RREG32(mmHW_STATE);
3990e65e175bSOded Gabbay
3991e65e175bSOded Gabbay return 0;
3992e65e175bSOded Gabbay
3993e65e175bSOded Gabbay disable_msi:
3994e65e175bSOded Gabbay gaudi_disable_msi(hdev);
3995e65e175bSOded Gabbay disable_queues:
3996e65e175bSOded Gabbay gaudi_disable_mme_qmans(hdev);
3997e65e175bSOded Gabbay gaudi_disable_pci_dma_qmans(hdev);
3998e65e175bSOded Gabbay
3999e65e175bSOded Gabbay return rc;
4000e65e175bSOded Gabbay }
4001e65e175bSOded Gabbay
gaudi_hw_fini(struct hl_device * hdev,bool hard_reset,bool fw_reset)4002e65e175bSOded Gabbay static int gaudi_hw_fini(struct hl_device *hdev, bool hard_reset, bool fw_reset)
4003e65e175bSOded Gabbay {
4004e65e175bSOded Gabbay struct cpu_dyn_regs *dyn_regs =
4005e65e175bSOded Gabbay &hdev->fw_loader.dynamic_loader.comm_desc.cpu_dyn_regs;
4006e65e175bSOded Gabbay u32 status, reset_timeout_ms, cpu_timeout_ms, irq_handler_offset;
4007e65e175bSOded Gabbay struct gaudi_device *gaudi = hdev->asic_specific;
4008e65e175bSOded Gabbay bool driver_performs_reset;
4009e65e175bSOded Gabbay
4010e65e175bSOded Gabbay if (!hard_reset) {
4011e65e175bSOded Gabbay dev_err(hdev->dev, "GAUDI doesn't support soft-reset\n");
4012e65e175bSOded Gabbay return 0;
40135e09ae92SDafna Hirschfeld }
4014e65e175bSOded Gabbay
4015e65e175bSOded Gabbay if (hdev->pldm) {
4016e65e175bSOded Gabbay reset_timeout_ms = GAUDI_PLDM_HRESET_TIMEOUT_MSEC;
4017e65e175bSOded Gabbay cpu_timeout_ms = GAUDI_PLDM_RESET_WAIT_MSEC;
4018e65e175bSOded Gabbay } else {
4019e65e175bSOded Gabbay reset_timeout_ms = GAUDI_RESET_TIMEOUT_MSEC;
4020e65e175bSOded Gabbay cpu_timeout_ms = GAUDI_CPU_RESET_WAIT_MSEC;
4021e65e175bSOded Gabbay }
4022e65e175bSOded Gabbay
40235e09ae92SDafna Hirschfeld if (fw_reset) {
4024e65e175bSOded Gabbay dev_dbg(hdev->dev,
4025e65e175bSOded Gabbay "Firmware performs HARD reset, going to wait %dms\n",
4026e65e175bSOded Gabbay reset_timeout_ms);
4027e65e175bSOded Gabbay
4028e65e175bSOded Gabbay goto skip_reset;
4029e65e175bSOded Gabbay }
4030e65e175bSOded Gabbay
4031e65e175bSOded Gabbay driver_performs_reset = !!(!hdev->asic_prop.fw_security_enabled &&
4032e65e175bSOded Gabbay !hdev->asic_prop.hard_reset_done_by_fw);
4033e65e175bSOded Gabbay
4034e65e175bSOded Gabbay /* Set device to handle FLR by H/W as we will put the device CPU to
4035e65e175bSOded Gabbay * halt mode
4036e65e175bSOded Gabbay */
4037e65e175bSOded Gabbay if (driver_performs_reset)
4038e65e175bSOded Gabbay WREG32(mmPCIE_AUX_FLR_CTRL, (PCIE_AUX_FLR_CTRL_HW_CTRL_MASK |
4039e65e175bSOded Gabbay PCIE_AUX_FLR_CTRL_INT_MASK_MASK));
4040e65e175bSOded Gabbay
4041e65e175bSOded Gabbay /* If linux is loaded in the device CPU we need to communicate with it
4042e65e175bSOded Gabbay * via the GIC. Otherwise, we need to use COMMS or the MSG_TO_CPU
4043e65e175bSOded Gabbay * registers in case of old F/Ws
4044e65e175bSOded Gabbay */
4045e65e175bSOded Gabbay if (hdev->fw_loader.fw_comp_loaded & FW_TYPE_LINUX) {
4046e65e175bSOded Gabbay irq_handler_offset = hdev->asic_prop.gic_interrupts_enable ?
4047e65e175bSOded Gabbay mmGIC_DISTRIBUTOR__5_GICD_SETSPI_NSR :
4048e65e175bSOded Gabbay le32_to_cpu(dyn_regs->gic_host_halt_irq);
4049e65e175bSOded Gabbay
4050e65e175bSOded Gabbay WREG32(irq_handler_offset,
4051e65e175bSOded Gabbay gaudi_irq_map_table[GAUDI_EVENT_HALT_MACHINE].cpu_id);
4052e65e175bSOded Gabbay
4053e65e175bSOded Gabbay /* This is a hail-mary attempt to revive the card in the small chance that the
4054e65e175bSOded Gabbay * f/w has experienced a watchdog event, which caused it to return back to preboot.
4055e65e175bSOded Gabbay * In that case, triggering reset through GIC won't help. We need to trigger the
4056e65e175bSOded Gabbay * reset as if Linux wasn't loaded.
4057e65e175bSOded Gabbay *
4058e65e175bSOded Gabbay * We do it only if the reset cause was HB, because that would be the indication
4059e65e175bSOded Gabbay * of such an event.
4060e65e175bSOded Gabbay *
4061e65e175bSOded Gabbay * In case watchdog hasn't expired but we still got HB, then this won't do any
4062e65e175bSOded Gabbay * damage.
4063e65e175bSOded Gabbay */
4064e65e175bSOded Gabbay if (hdev->reset_info.curr_reset_cause == HL_RESET_CAUSE_HEARTBEAT) {
4065e65e175bSOded Gabbay if (hdev->asic_prop.hard_reset_done_by_fw)
4066e65e175bSOded Gabbay hl_fw_ask_hard_reset_without_linux(hdev);
4067e65e175bSOded Gabbay else
4068e65e175bSOded Gabbay hl_fw_ask_halt_machine_without_linux(hdev);
4069e65e175bSOded Gabbay }
4070e65e175bSOded Gabbay } else {
4071e65e175bSOded Gabbay if (hdev->asic_prop.hard_reset_done_by_fw)
4072e65e175bSOded Gabbay hl_fw_ask_hard_reset_without_linux(hdev);
4073e65e175bSOded Gabbay else
4074e65e175bSOded Gabbay hl_fw_ask_halt_machine_without_linux(hdev);
4075e65e175bSOded Gabbay }
4076e65e175bSOded Gabbay
4077e65e175bSOded Gabbay if (driver_performs_reset) {
4078e65e175bSOded Gabbay
4079e65e175bSOded Gabbay /* Configure the reset registers. Must be done as early as
4080e65e175bSOded Gabbay * possible in case we fail during H/W initialization
4081e65e175bSOded Gabbay */
4082e65e175bSOded Gabbay WREG32(mmPSOC_GLOBAL_CONF_SOFT_RST_CFG_H,
4083e65e175bSOded Gabbay (CFG_RST_H_DMA_MASK |
4084e65e175bSOded Gabbay CFG_RST_H_MME_MASK |
4085e65e175bSOded Gabbay CFG_RST_H_SM_MASK |
4086e65e175bSOded Gabbay CFG_RST_H_TPC_7_MASK));
4087e65e175bSOded Gabbay
4088e65e175bSOded Gabbay WREG32(mmPSOC_GLOBAL_CONF_SOFT_RST_CFG_L, CFG_RST_L_TPC_MASK);
4089e65e175bSOded Gabbay
4090e65e175bSOded Gabbay WREG32(mmPSOC_GLOBAL_CONF_SW_ALL_RST_CFG_H,
4091e65e175bSOded Gabbay (CFG_RST_H_HBM_MASK |
4092e65e175bSOded Gabbay CFG_RST_H_TPC_7_MASK |
4093e65e175bSOded Gabbay CFG_RST_H_NIC_MASK |
4094e65e175bSOded Gabbay CFG_RST_H_SM_MASK |
4095e65e175bSOded Gabbay CFG_RST_H_DMA_MASK |
4096e65e175bSOded Gabbay CFG_RST_H_MME_MASK |
4097e65e175bSOded Gabbay CFG_RST_H_CPU_MASK |
4098e65e175bSOded Gabbay CFG_RST_H_MMU_MASK));
4099e65e175bSOded Gabbay
4100e65e175bSOded Gabbay WREG32(mmPSOC_GLOBAL_CONF_SW_ALL_RST_CFG_L,
4101e65e175bSOded Gabbay (CFG_RST_L_IF_MASK |
4102e65e175bSOded Gabbay CFG_RST_L_PSOC_MASK |
4103e65e175bSOded Gabbay CFG_RST_L_TPC_MASK));
4104e65e175bSOded Gabbay
4105e65e175bSOded Gabbay msleep(cpu_timeout_ms);
4106e65e175bSOded Gabbay
4107e65e175bSOded Gabbay /* Tell ASIC not to re-initialize PCIe */
4108e65e175bSOded Gabbay WREG32(mmPREBOOT_PCIE_EN, LKD_HARD_RESET_MAGIC);
4109e65e175bSOded Gabbay
4110e65e175bSOded Gabbay /* Restart BTL/BLR upon hard-reset */
4111e65e175bSOded Gabbay WREG32(mmPSOC_GLOBAL_CONF_BOOT_SEQ_RE_START, 1);
4112e65e175bSOded Gabbay
4113e65e175bSOded Gabbay WREG32(mmPSOC_GLOBAL_CONF_SW_ALL_RST,
4114e65e175bSOded Gabbay 1 << PSOC_GLOBAL_CONF_SW_ALL_RST_IND_SHIFT);
4115e65e175bSOded Gabbay
4116e65e175bSOded Gabbay dev_dbg(hdev->dev,
4117e65e175bSOded Gabbay "Issued HARD reset command, going to wait %dms\n",
4118e65e175bSOded Gabbay reset_timeout_ms);
4119e65e175bSOded Gabbay } else {
4120e65e175bSOded Gabbay dev_dbg(hdev->dev,
4121e65e175bSOded Gabbay "Firmware performs HARD reset, going to wait %dms\n",
4122e65e175bSOded Gabbay reset_timeout_ms);
4123e65e175bSOded Gabbay }
4124e65e175bSOded Gabbay
4125e65e175bSOded Gabbay skip_reset:
4126e65e175bSOded Gabbay /*
4127e65e175bSOded Gabbay * After hard reset, we can't poll the BTM_FSM register because the PSOC
4128e65e175bSOded Gabbay * itself is in reset. Need to wait until the reset is deasserted
4129e65e175bSOded Gabbay */
4130e65e175bSOded Gabbay msleep(reset_timeout_ms);
4131e65e175bSOded Gabbay
4132e65e175bSOded Gabbay status = RREG32(mmPSOC_GLOBAL_CONF_BTM_FSM);
4133e65e175bSOded Gabbay if (status & PSOC_GLOBAL_CONF_BTM_FSM_STATE_MASK) {
4134e65e175bSOded Gabbay dev_err(hdev->dev, "Timeout while waiting for device to reset 0x%x\n", status);
4135e65e175bSOded Gabbay return -ETIMEDOUT;
4136e65e175bSOded Gabbay }
4137e65e175bSOded Gabbay
4138e65e175bSOded Gabbay if (gaudi) {
4139e65e175bSOded Gabbay gaudi->hw_cap_initialized &= ~(HW_CAP_CPU | HW_CAP_CPU_Q | HW_CAP_HBM |
4140e65e175bSOded Gabbay HW_CAP_PCI_DMA | HW_CAP_MME | HW_CAP_TPC_MASK |
4141e65e175bSOded Gabbay HW_CAP_HBM_DMA | HW_CAP_PLL | HW_CAP_NIC_MASK |
4142e65e175bSOded Gabbay HW_CAP_MMU | HW_CAP_SRAM_SCRAMBLER |
4143e65e175bSOded Gabbay HW_CAP_HBM_SCRAMBLER);
4144077a39faSDafna Hirschfeld
4145077a39faSDafna Hirschfeld memset(gaudi->events_stat, 0, sizeof(gaudi->events_stat));
4146077a39faSDafna Hirschfeld
4147077a39faSDafna Hirschfeld hdev->device_cpu_is_halted = false;
4148e65e175bSOded Gabbay }
4149e65e175bSOded Gabbay return 0;
4150e65e175bSOded Gabbay }
4151e65e175bSOded Gabbay
gaudi_suspend(struct hl_device * hdev)4152e65e175bSOded Gabbay static int gaudi_suspend(struct hl_device *hdev)
4153e65e175bSOded Gabbay {
4154e65e175bSOded Gabbay int rc;
4155e65e175bSOded Gabbay
4156e65e175bSOded Gabbay rc = hl_fw_send_pci_access_msg(hdev, CPUCP_PACKET_DISABLE_PCI_ACCESS, 0x0);
4157e65e175bSOded Gabbay if (rc)
4158e65e175bSOded Gabbay dev_err(hdev->dev, "Failed to disable PCI access from CPU\n");
4159e65e175bSOded Gabbay
41605e09ae92SDafna Hirschfeld return rc;
4161e65e175bSOded Gabbay }
4162e65e175bSOded Gabbay
gaudi_resume(struct hl_device * hdev)4163e65e175bSOded Gabbay static int gaudi_resume(struct hl_device *hdev)
4164e65e175bSOded Gabbay {
4165e65e175bSOded Gabbay return gaudi_init_iatu(hdev);
4166e65e175bSOded Gabbay }
4167e65e175bSOded Gabbay
gaudi_mmap(struct hl_device * hdev,struct vm_area_struct * vma,void * cpu_addr,dma_addr_t dma_addr,size_t size)4168e65e175bSOded Gabbay static int gaudi_mmap(struct hl_device *hdev, struct vm_area_struct *vma,
4169e65e175bSOded Gabbay void *cpu_addr, dma_addr_t dma_addr, size_t size)
4170e65e175bSOded Gabbay {
4171e65e175bSOded Gabbay int rc;
4172e65e175bSOded Gabbay
4173e65e175bSOded Gabbay vm_flags_set(vma, VM_IO | VM_PFNMAP | VM_DONTEXPAND | VM_DONTDUMP |
4174e65e175bSOded Gabbay VM_DONTCOPY | VM_NORESERVE);
4175e65e175bSOded Gabbay
4176e65e175bSOded Gabbay rc = dma_mmap_coherent(hdev->dev, vma, cpu_addr,
4177e65e175bSOded Gabbay (dma_addr - HOST_PHYS_BASE), size);
4178e65e175bSOded Gabbay if (rc)
4179e65e175bSOded Gabbay dev_err(hdev->dev, "dma_mmap_coherent error %d", rc);
4180e65e175bSOded Gabbay
4181e65e175bSOded Gabbay return rc;
4182e65e175bSOded Gabbay }
4183e65e175bSOded Gabbay
gaudi_ring_doorbell(struct hl_device * hdev,u32 hw_queue_id,u32 pi)41843822a7c4SLinus Torvalds static void gaudi_ring_doorbell(struct hl_device *hdev, u32 hw_queue_id, u32 pi)
41853822a7c4SLinus Torvalds {
4186e65e175bSOded Gabbay struct cpu_dyn_regs *dyn_regs =
4187e65e175bSOded Gabbay &hdev->fw_loader.dynamic_loader.comm_desc.cpu_dyn_regs;
4188e65e175bSOded Gabbay u32 db_reg_offset, db_value, dma_qm_offset, q_off, irq_handler_offset;
4189e65e175bSOded Gabbay struct gaudi_device *gaudi = hdev->asic_specific;
4190e65e175bSOded Gabbay bool invalid_queue = false;
4191e65e175bSOded Gabbay int dma_id;
4192e65e175bSOded Gabbay
4193e65e175bSOded Gabbay switch (hw_queue_id) {
4194e65e175bSOded Gabbay case GAUDI_QUEUE_ID_DMA_0_0...GAUDI_QUEUE_ID_DMA_0_3:
4195e65e175bSOded Gabbay dma_id = gaudi_dma_assignment[GAUDI_PCI_DMA_1];
4196e65e175bSOded Gabbay dma_qm_offset = dma_id * DMA_QMAN_OFFSET;
4197e65e175bSOded Gabbay q_off = dma_qm_offset + (hw_queue_id & 0x3) * 4;
4198e65e175bSOded Gabbay db_reg_offset = mmDMA0_QM_PQ_PI_0 + q_off;
4199e65e175bSOded Gabbay break;
4200e65e175bSOded Gabbay
4201e65e175bSOded Gabbay case GAUDI_QUEUE_ID_DMA_1_0...GAUDI_QUEUE_ID_DMA_1_3:
4202e65e175bSOded Gabbay dma_id = gaudi_dma_assignment[GAUDI_PCI_DMA_2];
4203e65e175bSOded Gabbay dma_qm_offset = dma_id * DMA_QMAN_OFFSET;
4204e65e175bSOded Gabbay q_off = dma_qm_offset + (hw_queue_id & 0x3) * 4;
4205e65e175bSOded Gabbay db_reg_offset = mmDMA0_QM_PQ_PI_0 + q_off;
4206e65e175bSOded Gabbay break;
4207e65e175bSOded Gabbay
4208e65e175bSOded Gabbay case GAUDI_QUEUE_ID_DMA_2_0...GAUDI_QUEUE_ID_DMA_2_3:
4209e65e175bSOded Gabbay dma_id = gaudi_dma_assignment[GAUDI_HBM_DMA_1];
4210e65e175bSOded Gabbay dma_qm_offset = dma_id * DMA_QMAN_OFFSET;
4211e65e175bSOded Gabbay q_off = dma_qm_offset + ((hw_queue_id - 1) & 0x3) * 4;
4212e65e175bSOded Gabbay db_reg_offset = mmDMA0_QM_PQ_PI_0 + q_off;
4213e65e175bSOded Gabbay break;
4214e65e175bSOded Gabbay
4215e65e175bSOded Gabbay case GAUDI_QUEUE_ID_DMA_3_0...GAUDI_QUEUE_ID_DMA_3_3:
4216e65e175bSOded Gabbay dma_id = gaudi_dma_assignment[GAUDI_HBM_DMA_2];
4217e65e175bSOded Gabbay dma_qm_offset = dma_id * DMA_QMAN_OFFSET;
4218e65e175bSOded Gabbay q_off = dma_qm_offset + ((hw_queue_id - 1) & 0x3) * 4;
4219e65e175bSOded Gabbay db_reg_offset = mmDMA0_QM_PQ_PI_0 + q_off;
4220e65e175bSOded Gabbay break;
4221e65e175bSOded Gabbay
4222e65e175bSOded Gabbay case GAUDI_QUEUE_ID_DMA_4_0...GAUDI_QUEUE_ID_DMA_4_3:
4223e65e175bSOded Gabbay dma_id = gaudi_dma_assignment[GAUDI_HBM_DMA_3];
4224e65e175bSOded Gabbay dma_qm_offset = dma_id * DMA_QMAN_OFFSET;
4225e65e175bSOded Gabbay q_off = dma_qm_offset + ((hw_queue_id - 1) & 0x3) * 4;
4226e65e175bSOded Gabbay db_reg_offset = mmDMA0_QM_PQ_PI_0 + q_off;
4227e65e175bSOded Gabbay break;
4228e65e175bSOded Gabbay
4229e65e175bSOded Gabbay case GAUDI_QUEUE_ID_DMA_5_0...GAUDI_QUEUE_ID_DMA_5_3:
4230e65e175bSOded Gabbay dma_id = gaudi_dma_assignment[GAUDI_HBM_DMA_4];
4231e65e175bSOded Gabbay dma_qm_offset = dma_id * DMA_QMAN_OFFSET;
4232e65e175bSOded Gabbay q_off = dma_qm_offset + ((hw_queue_id - 1) & 0x3) * 4;
4233e65e175bSOded Gabbay db_reg_offset = mmDMA0_QM_PQ_PI_0 + q_off;
4234e65e175bSOded Gabbay break;
4235e65e175bSOded Gabbay
4236e65e175bSOded Gabbay case GAUDI_QUEUE_ID_DMA_6_0...GAUDI_QUEUE_ID_DMA_6_3:
4237e65e175bSOded Gabbay dma_id = gaudi_dma_assignment[GAUDI_HBM_DMA_5];
4238e65e175bSOded Gabbay dma_qm_offset = dma_id * DMA_QMAN_OFFSET;
4239e65e175bSOded Gabbay q_off = dma_qm_offset + ((hw_queue_id - 1) & 0x3) * 4;
4240e65e175bSOded Gabbay db_reg_offset = mmDMA0_QM_PQ_PI_0 + q_off;
4241e65e175bSOded Gabbay break;
4242e65e175bSOded Gabbay
4243e65e175bSOded Gabbay case GAUDI_QUEUE_ID_DMA_7_0...GAUDI_QUEUE_ID_DMA_7_3:
4244e65e175bSOded Gabbay dma_id = gaudi_dma_assignment[GAUDI_HBM_DMA_6];
4245e65e175bSOded Gabbay dma_qm_offset = dma_id * DMA_QMAN_OFFSET;
4246e65e175bSOded Gabbay q_off = dma_qm_offset + ((hw_queue_id - 1) & 0x3) * 4;
4247e65e175bSOded Gabbay db_reg_offset = mmDMA0_QM_PQ_PI_0 + q_off;
4248e65e175bSOded Gabbay break;
4249e65e175bSOded Gabbay
4250e65e175bSOded Gabbay case GAUDI_QUEUE_ID_CPU_PQ:
4251e65e175bSOded Gabbay if (gaudi->hw_cap_initialized & HW_CAP_CPU_Q)
4252e65e175bSOded Gabbay db_reg_offset = mmCPU_IF_PF_PQ_PI;
4253e65e175bSOded Gabbay else
4254e65e175bSOded Gabbay invalid_queue = true;
4255e65e175bSOded Gabbay break;
4256e65e175bSOded Gabbay
4257e65e175bSOded Gabbay case GAUDI_QUEUE_ID_MME_0_0:
4258e65e175bSOded Gabbay db_reg_offset = mmMME2_QM_PQ_PI_0;
4259e65e175bSOded Gabbay break;
4260e65e175bSOded Gabbay
4261e65e175bSOded Gabbay case GAUDI_QUEUE_ID_MME_0_1:
4262e65e175bSOded Gabbay db_reg_offset = mmMME2_QM_PQ_PI_1;
4263e65e175bSOded Gabbay break;
4264e65e175bSOded Gabbay
4265e65e175bSOded Gabbay case GAUDI_QUEUE_ID_MME_0_2:
4266e65e175bSOded Gabbay db_reg_offset = mmMME2_QM_PQ_PI_2;
4267e65e175bSOded Gabbay break;
4268e65e175bSOded Gabbay
4269e65e175bSOded Gabbay case GAUDI_QUEUE_ID_MME_0_3:
4270e65e175bSOded Gabbay db_reg_offset = mmMME2_QM_PQ_PI_3;
4271e65e175bSOded Gabbay break;
4272e65e175bSOded Gabbay
4273e65e175bSOded Gabbay case GAUDI_QUEUE_ID_MME_1_0:
4274e65e175bSOded Gabbay db_reg_offset = mmMME0_QM_PQ_PI_0;
4275e65e175bSOded Gabbay break;
4276e65e175bSOded Gabbay
4277e65e175bSOded Gabbay case GAUDI_QUEUE_ID_MME_1_1:
4278e65e175bSOded Gabbay db_reg_offset = mmMME0_QM_PQ_PI_1;
4279e65e175bSOded Gabbay break;
4280e65e175bSOded Gabbay
4281e65e175bSOded Gabbay case GAUDI_QUEUE_ID_MME_1_2:
4282e65e175bSOded Gabbay db_reg_offset = mmMME0_QM_PQ_PI_2;
4283e65e175bSOded Gabbay break;
4284e65e175bSOded Gabbay
4285e65e175bSOded Gabbay case GAUDI_QUEUE_ID_MME_1_3:
4286e65e175bSOded Gabbay db_reg_offset = mmMME0_QM_PQ_PI_3;
4287e65e175bSOded Gabbay break;
4288e65e175bSOded Gabbay
4289e65e175bSOded Gabbay case GAUDI_QUEUE_ID_TPC_0_0:
4290e65e175bSOded Gabbay db_reg_offset = mmTPC0_QM_PQ_PI_0;
4291e65e175bSOded Gabbay break;
4292e65e175bSOded Gabbay
4293e65e175bSOded Gabbay case GAUDI_QUEUE_ID_TPC_0_1:
4294e65e175bSOded Gabbay db_reg_offset = mmTPC0_QM_PQ_PI_1;
4295e65e175bSOded Gabbay break;
4296e65e175bSOded Gabbay
4297e65e175bSOded Gabbay case GAUDI_QUEUE_ID_TPC_0_2:
4298e65e175bSOded Gabbay db_reg_offset = mmTPC0_QM_PQ_PI_2;
4299e65e175bSOded Gabbay break;
4300e65e175bSOded Gabbay
4301e65e175bSOded Gabbay case GAUDI_QUEUE_ID_TPC_0_3:
4302e65e175bSOded Gabbay db_reg_offset = mmTPC0_QM_PQ_PI_3;
4303e65e175bSOded Gabbay break;
4304e65e175bSOded Gabbay
4305e65e175bSOded Gabbay case GAUDI_QUEUE_ID_TPC_1_0:
4306e65e175bSOded Gabbay db_reg_offset = mmTPC1_QM_PQ_PI_0;
4307e65e175bSOded Gabbay break;
4308e65e175bSOded Gabbay
4309e65e175bSOded Gabbay case GAUDI_QUEUE_ID_TPC_1_1:
4310e65e175bSOded Gabbay db_reg_offset = mmTPC1_QM_PQ_PI_1;
4311e65e175bSOded Gabbay break;
4312e65e175bSOded Gabbay
4313e65e175bSOded Gabbay case GAUDI_QUEUE_ID_TPC_1_2:
4314e65e175bSOded Gabbay db_reg_offset = mmTPC1_QM_PQ_PI_2;
4315e65e175bSOded Gabbay break;
4316e65e175bSOded Gabbay
4317e65e175bSOded Gabbay case GAUDI_QUEUE_ID_TPC_1_3:
4318e65e175bSOded Gabbay db_reg_offset = mmTPC1_QM_PQ_PI_3;
4319e65e175bSOded Gabbay break;
4320e65e175bSOded Gabbay
4321e65e175bSOded Gabbay case GAUDI_QUEUE_ID_TPC_2_0:
4322e65e175bSOded Gabbay db_reg_offset = mmTPC2_QM_PQ_PI_0;
4323e65e175bSOded Gabbay break;
4324e65e175bSOded Gabbay
4325e65e175bSOded Gabbay case GAUDI_QUEUE_ID_TPC_2_1:
4326e65e175bSOded Gabbay db_reg_offset = mmTPC2_QM_PQ_PI_1;
4327e65e175bSOded Gabbay break;
4328e65e175bSOded Gabbay
4329e65e175bSOded Gabbay case GAUDI_QUEUE_ID_TPC_2_2:
4330e65e175bSOded Gabbay db_reg_offset = mmTPC2_QM_PQ_PI_2;
4331e65e175bSOded Gabbay break;
4332e65e175bSOded Gabbay
4333e65e175bSOded Gabbay case GAUDI_QUEUE_ID_TPC_2_3:
4334e65e175bSOded Gabbay db_reg_offset = mmTPC2_QM_PQ_PI_3;
4335e65e175bSOded Gabbay break;
4336e65e175bSOded Gabbay
4337e65e175bSOded Gabbay case GAUDI_QUEUE_ID_TPC_3_0:
4338e65e175bSOded Gabbay db_reg_offset = mmTPC3_QM_PQ_PI_0;
4339e65e175bSOded Gabbay break;
4340e65e175bSOded Gabbay
4341e65e175bSOded Gabbay case GAUDI_QUEUE_ID_TPC_3_1:
4342e65e175bSOded Gabbay db_reg_offset = mmTPC3_QM_PQ_PI_1;
4343e65e175bSOded Gabbay break;
4344e65e175bSOded Gabbay
4345e65e175bSOded Gabbay case GAUDI_QUEUE_ID_TPC_3_2:
4346e65e175bSOded Gabbay db_reg_offset = mmTPC3_QM_PQ_PI_2;
4347e65e175bSOded Gabbay break;
4348e65e175bSOded Gabbay
4349e65e175bSOded Gabbay case GAUDI_QUEUE_ID_TPC_3_3:
4350e65e175bSOded Gabbay db_reg_offset = mmTPC3_QM_PQ_PI_3;
4351e65e175bSOded Gabbay break;
4352e65e175bSOded Gabbay
4353e65e175bSOded Gabbay case GAUDI_QUEUE_ID_TPC_4_0:
4354e65e175bSOded Gabbay db_reg_offset = mmTPC4_QM_PQ_PI_0;
4355e65e175bSOded Gabbay break;
4356e65e175bSOded Gabbay
4357e65e175bSOded Gabbay case GAUDI_QUEUE_ID_TPC_4_1:
4358e65e175bSOded Gabbay db_reg_offset = mmTPC4_QM_PQ_PI_1;
4359e65e175bSOded Gabbay break;
4360e65e175bSOded Gabbay
4361e65e175bSOded Gabbay case GAUDI_QUEUE_ID_TPC_4_2:
4362e65e175bSOded Gabbay db_reg_offset = mmTPC4_QM_PQ_PI_2;
4363e65e175bSOded Gabbay break;
4364e65e175bSOded Gabbay
4365e65e175bSOded Gabbay case GAUDI_QUEUE_ID_TPC_4_3:
4366e65e175bSOded Gabbay db_reg_offset = mmTPC4_QM_PQ_PI_3;
4367e65e175bSOded Gabbay break;
4368e65e175bSOded Gabbay
4369e65e175bSOded Gabbay case GAUDI_QUEUE_ID_TPC_5_0:
4370e65e175bSOded Gabbay db_reg_offset = mmTPC5_QM_PQ_PI_0;
4371e65e175bSOded Gabbay break;
4372e65e175bSOded Gabbay
4373e65e175bSOded Gabbay case GAUDI_QUEUE_ID_TPC_5_1:
4374e65e175bSOded Gabbay db_reg_offset = mmTPC5_QM_PQ_PI_1;
4375e65e175bSOded Gabbay break;
4376e65e175bSOded Gabbay
4377e65e175bSOded Gabbay case GAUDI_QUEUE_ID_TPC_5_2:
4378e65e175bSOded Gabbay db_reg_offset = mmTPC5_QM_PQ_PI_2;
4379e65e175bSOded Gabbay break;
4380e65e175bSOded Gabbay
4381e65e175bSOded Gabbay case GAUDI_QUEUE_ID_TPC_5_3:
4382e65e175bSOded Gabbay db_reg_offset = mmTPC5_QM_PQ_PI_3;
4383e65e175bSOded Gabbay break;
4384e65e175bSOded Gabbay
4385e65e175bSOded Gabbay case GAUDI_QUEUE_ID_TPC_6_0:
4386e65e175bSOded Gabbay db_reg_offset = mmTPC6_QM_PQ_PI_0;
4387e65e175bSOded Gabbay break;
4388e65e175bSOded Gabbay
4389e65e175bSOded Gabbay case GAUDI_QUEUE_ID_TPC_6_1:
4390e65e175bSOded Gabbay db_reg_offset = mmTPC6_QM_PQ_PI_1;
4391e65e175bSOded Gabbay break;
4392e65e175bSOded Gabbay
4393e65e175bSOded Gabbay case GAUDI_QUEUE_ID_TPC_6_2:
4394e65e175bSOded Gabbay db_reg_offset = mmTPC6_QM_PQ_PI_2;
4395e65e175bSOded Gabbay break;
4396e65e175bSOded Gabbay
4397e65e175bSOded Gabbay case GAUDI_QUEUE_ID_TPC_6_3:
4398e65e175bSOded Gabbay db_reg_offset = mmTPC6_QM_PQ_PI_3;
4399e65e175bSOded Gabbay break;
4400e65e175bSOded Gabbay
4401e65e175bSOded Gabbay case GAUDI_QUEUE_ID_TPC_7_0:
4402e65e175bSOded Gabbay db_reg_offset = mmTPC7_QM_PQ_PI_0;
4403e65e175bSOded Gabbay break;
4404e65e175bSOded Gabbay
4405e65e175bSOded Gabbay case GAUDI_QUEUE_ID_TPC_7_1:
4406e65e175bSOded Gabbay db_reg_offset = mmTPC7_QM_PQ_PI_1;
4407e65e175bSOded Gabbay break;
4408e65e175bSOded Gabbay
4409e65e175bSOded Gabbay case GAUDI_QUEUE_ID_TPC_7_2:
4410e65e175bSOded Gabbay db_reg_offset = mmTPC7_QM_PQ_PI_2;
4411e65e175bSOded Gabbay break;
4412e65e175bSOded Gabbay
4413e65e175bSOded Gabbay case GAUDI_QUEUE_ID_TPC_7_3:
4414e65e175bSOded Gabbay db_reg_offset = mmTPC7_QM_PQ_PI_3;
4415e65e175bSOded Gabbay break;
4416e65e175bSOded Gabbay
4417e65e175bSOded Gabbay case GAUDI_QUEUE_ID_NIC_0_0...GAUDI_QUEUE_ID_NIC_0_3:
4418e65e175bSOded Gabbay if (!(gaudi->hw_cap_initialized & HW_CAP_NIC0))
4419e65e175bSOded Gabbay invalid_queue = true;
4420e65e175bSOded Gabbay
4421e65e175bSOded Gabbay q_off = ((hw_queue_id - 1) & 0x3) * 4;
4422e65e175bSOded Gabbay db_reg_offset = mmNIC0_QM0_PQ_PI_0 + q_off;
4423e65e175bSOded Gabbay break;
4424e65e175bSOded Gabbay
4425e65e175bSOded Gabbay case GAUDI_QUEUE_ID_NIC_1_0...GAUDI_QUEUE_ID_NIC_1_3:
4426e65e175bSOded Gabbay if (!(gaudi->hw_cap_initialized & HW_CAP_NIC1))
4427e65e175bSOded Gabbay invalid_queue = true;
4428e65e175bSOded Gabbay
4429e65e175bSOded Gabbay q_off = ((hw_queue_id - 1) & 0x3) * 4;
4430e65e175bSOded Gabbay db_reg_offset = mmNIC0_QM1_PQ_PI_0 + q_off;
4431e65e175bSOded Gabbay break;
4432e65e175bSOded Gabbay
4433e65e175bSOded Gabbay case GAUDI_QUEUE_ID_NIC_2_0...GAUDI_QUEUE_ID_NIC_2_3:
4434e65e175bSOded Gabbay if (!(gaudi->hw_cap_initialized & HW_CAP_NIC2))
4435e65e175bSOded Gabbay invalid_queue = true;
4436e65e175bSOded Gabbay
4437e65e175bSOded Gabbay q_off = ((hw_queue_id - 1) & 0x3) * 4;
4438e65e175bSOded Gabbay db_reg_offset = mmNIC1_QM0_PQ_PI_0 + q_off;
4439e65e175bSOded Gabbay break;
4440e65e175bSOded Gabbay
4441e65e175bSOded Gabbay case GAUDI_QUEUE_ID_NIC_3_0...GAUDI_QUEUE_ID_NIC_3_3:
4442e65e175bSOded Gabbay if (!(gaudi->hw_cap_initialized & HW_CAP_NIC3))
4443e65e175bSOded Gabbay invalid_queue = true;
4444e65e175bSOded Gabbay
4445e65e175bSOded Gabbay q_off = ((hw_queue_id - 1) & 0x3) * 4;
4446e65e175bSOded Gabbay db_reg_offset = mmNIC1_QM1_PQ_PI_0 + q_off;
4447e65e175bSOded Gabbay break;
4448e65e175bSOded Gabbay
4449e65e175bSOded Gabbay case GAUDI_QUEUE_ID_NIC_4_0...GAUDI_QUEUE_ID_NIC_4_3:
4450e65e175bSOded Gabbay if (!(gaudi->hw_cap_initialized & HW_CAP_NIC4))
4451e65e175bSOded Gabbay invalid_queue = true;
4452e65e175bSOded Gabbay
4453e65e175bSOded Gabbay q_off = ((hw_queue_id - 1) & 0x3) * 4;
4454e65e175bSOded Gabbay db_reg_offset = mmNIC2_QM0_PQ_PI_0 + q_off;
4455e65e175bSOded Gabbay break;
4456e65e175bSOded Gabbay
4457e65e175bSOded Gabbay case GAUDI_QUEUE_ID_NIC_5_0...GAUDI_QUEUE_ID_NIC_5_3:
4458e65e175bSOded Gabbay if (!(gaudi->hw_cap_initialized & HW_CAP_NIC5))
4459e65e175bSOded Gabbay invalid_queue = true;
4460e65e175bSOded Gabbay
4461e65e175bSOded Gabbay q_off = ((hw_queue_id - 1) & 0x3) * 4;
4462e65e175bSOded Gabbay db_reg_offset = mmNIC2_QM1_PQ_PI_0 + q_off;
4463e65e175bSOded Gabbay break;
4464e65e175bSOded Gabbay
4465e65e175bSOded Gabbay case GAUDI_QUEUE_ID_NIC_6_0...GAUDI_QUEUE_ID_NIC_6_3:
4466e65e175bSOded Gabbay if (!(gaudi->hw_cap_initialized & HW_CAP_NIC6))
4467e65e175bSOded Gabbay invalid_queue = true;
4468e65e175bSOded Gabbay
4469e65e175bSOded Gabbay q_off = ((hw_queue_id - 1) & 0x3) * 4;
4470e65e175bSOded Gabbay db_reg_offset = mmNIC3_QM0_PQ_PI_0 + q_off;
4471e65e175bSOded Gabbay break;
4472e65e175bSOded Gabbay
4473e65e175bSOded Gabbay case GAUDI_QUEUE_ID_NIC_7_0...GAUDI_QUEUE_ID_NIC_7_3:
4474e65e175bSOded Gabbay if (!(gaudi->hw_cap_initialized & HW_CAP_NIC7))
4475e65e175bSOded Gabbay invalid_queue = true;
4476e65e175bSOded Gabbay
4477e65e175bSOded Gabbay q_off = ((hw_queue_id - 1) & 0x3) * 4;
4478e65e175bSOded Gabbay db_reg_offset = mmNIC3_QM1_PQ_PI_0 + q_off;
4479e65e175bSOded Gabbay break;
4480e65e175bSOded Gabbay
4481e65e175bSOded Gabbay case GAUDI_QUEUE_ID_NIC_8_0...GAUDI_QUEUE_ID_NIC_8_3:
4482e65e175bSOded Gabbay if (!(gaudi->hw_cap_initialized & HW_CAP_NIC8))
4483e65e175bSOded Gabbay invalid_queue = true;
4484e65e175bSOded Gabbay
4485e65e175bSOded Gabbay q_off = ((hw_queue_id - 1) & 0x3) * 4;
4486e65e175bSOded Gabbay db_reg_offset = mmNIC4_QM0_PQ_PI_0 + q_off;
4487e65e175bSOded Gabbay break;
4488e65e175bSOded Gabbay
4489e65e175bSOded Gabbay case GAUDI_QUEUE_ID_NIC_9_0...GAUDI_QUEUE_ID_NIC_9_3:
4490e65e175bSOded Gabbay if (!(gaudi->hw_cap_initialized & HW_CAP_NIC9))
4491e65e175bSOded Gabbay invalid_queue = true;
4492e65e175bSOded Gabbay
4493e65e175bSOded Gabbay q_off = ((hw_queue_id - 1) & 0x3) * 4;
4494e65e175bSOded Gabbay db_reg_offset = mmNIC4_QM1_PQ_PI_0 + q_off;
4495e65e175bSOded Gabbay break;
4496e65e175bSOded Gabbay
4497e65e175bSOded Gabbay default:
4498e65e175bSOded Gabbay invalid_queue = true;
4499e65e175bSOded Gabbay }
4500e65e175bSOded Gabbay
4501e65e175bSOded Gabbay if (invalid_queue) {
4502e65e175bSOded Gabbay /* Should never get here */
4503e65e175bSOded Gabbay dev_err(hdev->dev, "h/w queue %d is invalid. Can't set pi\n",
4504e65e175bSOded Gabbay hw_queue_id);
4505e65e175bSOded Gabbay return;
4506e65e175bSOded Gabbay }
4507e65e175bSOded Gabbay
4508e65e175bSOded Gabbay db_value = pi;
4509e65e175bSOded Gabbay
4510e65e175bSOded Gabbay /* ring the doorbell */
4511e65e175bSOded Gabbay WREG32(db_reg_offset, db_value);
4512e65e175bSOded Gabbay
4513e65e175bSOded Gabbay if (hw_queue_id == GAUDI_QUEUE_ID_CPU_PQ) {
4514e65e175bSOded Gabbay /* make sure device CPU will read latest data from host */
4515e65e175bSOded Gabbay mb();
4516e65e175bSOded Gabbay
4517e65e175bSOded Gabbay irq_handler_offset = hdev->asic_prop.gic_interrupts_enable ?
4518e65e175bSOded Gabbay mmGIC_DISTRIBUTOR__5_GICD_SETSPI_NSR :
4519e65e175bSOded Gabbay le32_to_cpu(dyn_regs->gic_host_pi_upd_irq);
4520e65e175bSOded Gabbay
4521e65e175bSOded Gabbay WREG32(irq_handler_offset,
4522e65e175bSOded Gabbay gaudi_irq_map_table[GAUDI_EVENT_PI_UPDATE].cpu_id);
4523e65e175bSOded Gabbay }
4524e65e175bSOded Gabbay }
4525e65e175bSOded Gabbay
gaudi_pqe_write(struct hl_device * hdev,__le64 * pqe,struct hl_bd * bd)4526e65e175bSOded Gabbay static void gaudi_pqe_write(struct hl_device *hdev, __le64 *pqe,
4527e65e175bSOded Gabbay struct hl_bd *bd)
4528e65e175bSOded Gabbay {
4529e65e175bSOded Gabbay __le64 *pbd = (__le64 *) bd;
4530e65e175bSOded Gabbay
4531e65e175bSOded Gabbay /* The QMANs are on the host memory so a simple copy suffice */
4532e65e175bSOded Gabbay pqe[0] = pbd[0];
4533e65e175bSOded Gabbay pqe[1] = pbd[1];
4534e65e175bSOded Gabbay }
4535e65e175bSOded Gabbay
gaudi_dma_alloc_coherent(struct hl_device * hdev,size_t size,dma_addr_t * dma_handle,gfp_t flags)4536e65e175bSOded Gabbay static void *gaudi_dma_alloc_coherent(struct hl_device *hdev, size_t size,
4537e65e175bSOded Gabbay dma_addr_t *dma_handle, gfp_t flags)
4538e65e175bSOded Gabbay {
4539e65e175bSOded Gabbay void *kernel_addr = dma_alloc_coherent(&hdev->pdev->dev, size,
4540e65e175bSOded Gabbay dma_handle, flags);
4541e65e175bSOded Gabbay
4542e65e175bSOded Gabbay /* Shift to the device's base physical address of host memory */
4543e65e175bSOded Gabbay if (kernel_addr)
4544e65e175bSOded Gabbay *dma_handle += HOST_PHYS_BASE;
4545e65e175bSOded Gabbay
4546e65e175bSOded Gabbay return kernel_addr;
4547e65e175bSOded Gabbay }
4548e65e175bSOded Gabbay
gaudi_dma_free_coherent(struct hl_device * hdev,size_t size,void * cpu_addr,dma_addr_t dma_handle)4549e65e175bSOded Gabbay static void gaudi_dma_free_coherent(struct hl_device *hdev, size_t size,
4550e65e175bSOded Gabbay void *cpu_addr, dma_addr_t dma_handle)
4551e65e175bSOded Gabbay {
4552e65e175bSOded Gabbay /* Cancel the device's base physical address of host memory */
4553e65e175bSOded Gabbay dma_addr_t fixed_dma_handle = dma_handle - HOST_PHYS_BASE;
4554e65e175bSOded Gabbay
4555e65e175bSOded Gabbay dma_free_coherent(&hdev->pdev->dev, size, cpu_addr, fixed_dma_handle);
4556e65e175bSOded Gabbay }
4557e65e175bSOded Gabbay
gaudi_scrub_device_dram(struct hl_device * hdev,u64 val)4558e65e175bSOded Gabbay static int gaudi_scrub_device_dram(struct hl_device *hdev, u64 val)
4559e65e175bSOded Gabbay {
4560e65e175bSOded Gabbay struct asic_fixed_properties *prop = &hdev->asic_prop;
4561e65e175bSOded Gabbay u64 cur_addr = prop->dram_user_base_address;
4562e65e175bSOded Gabbay u32 chunk_size, busy;
4563e65e175bSOded Gabbay int rc, dma_id;
4564e65e175bSOded Gabbay
4565e65e175bSOded Gabbay while (cur_addr < prop->dram_end_address) {
4566e65e175bSOded Gabbay for (dma_id = 0 ; dma_id < DMA_NUMBER_OF_CHANNELS ; dma_id++) {
4567e65e175bSOded Gabbay u32 dma_offset = dma_id * DMA_CORE_OFFSET;
4568e65e175bSOded Gabbay
4569e65e175bSOded Gabbay chunk_size =
4570e65e175bSOded Gabbay min((u64)SZ_2G, prop->dram_end_address - cur_addr);
4571e65e175bSOded Gabbay
4572e65e175bSOded Gabbay dev_dbg(hdev->dev,
4573e65e175bSOded Gabbay "Doing HBM scrubbing for 0x%09llx - 0x%09llx\n",
4574e65e175bSOded Gabbay cur_addr, cur_addr + chunk_size);
4575e65e175bSOded Gabbay
4576e65e175bSOded Gabbay WREG32(mmDMA0_CORE_SRC_BASE_LO + dma_offset,
4577e65e175bSOded Gabbay lower_32_bits(val));
4578e65e175bSOded Gabbay WREG32(mmDMA0_CORE_SRC_BASE_HI + dma_offset,
4579e65e175bSOded Gabbay upper_32_bits(val));
4580e65e175bSOded Gabbay WREG32(mmDMA0_CORE_DST_BASE_LO + dma_offset,
4581e65e175bSOded Gabbay lower_32_bits(cur_addr));
4582e65e175bSOded Gabbay WREG32(mmDMA0_CORE_DST_BASE_HI + dma_offset,
4583e65e175bSOded Gabbay upper_32_bits(cur_addr));
4584e65e175bSOded Gabbay WREG32(mmDMA0_CORE_DST_TSIZE_0 + dma_offset,
4585e65e175bSOded Gabbay chunk_size);
4586e65e175bSOded Gabbay WREG32(mmDMA0_CORE_COMMIT + dma_offset,
4587e65e175bSOded Gabbay ((1 << DMA0_CORE_COMMIT_LIN_SHIFT) |
4588e65e175bSOded Gabbay (1 << DMA0_CORE_COMMIT_MEM_SET_SHIFT)));
4589e65e175bSOded Gabbay
4590e65e175bSOded Gabbay cur_addr += chunk_size;
4591e65e175bSOded Gabbay
4592e65e175bSOded Gabbay if (cur_addr == prop->dram_end_address)
4593e65e175bSOded Gabbay break;
4594e65e175bSOded Gabbay }
4595e65e175bSOded Gabbay
4596e65e175bSOded Gabbay for (dma_id = 0 ; dma_id < DMA_NUMBER_OF_CHANNELS ; dma_id++) {
4597e65e175bSOded Gabbay u32 dma_offset = dma_id * DMA_CORE_OFFSET;
4598e65e175bSOded Gabbay
4599e65e175bSOded Gabbay rc = hl_poll_timeout(
4600e65e175bSOded Gabbay hdev,
4601e65e175bSOded Gabbay mmDMA0_CORE_STS0 + dma_offset,
4602e65e175bSOded Gabbay busy,
4603e65e175bSOded Gabbay ((busy & DMA0_CORE_STS0_BUSY_MASK) == 0),
4604e65e175bSOded Gabbay 1000,
4605e65e175bSOded Gabbay HBM_SCRUBBING_TIMEOUT_US);
4606e65e175bSOded Gabbay
4607e65e175bSOded Gabbay if (rc) {
4608e65e175bSOded Gabbay dev_err(hdev->dev,
4609e65e175bSOded Gabbay "DMA Timeout during HBM scrubbing of DMA #%d\n",
4610e65e175bSOded Gabbay dma_id);
4611e65e175bSOded Gabbay return -EIO;
4612e65e175bSOded Gabbay }
4613e65e175bSOded Gabbay }
4614e65e175bSOded Gabbay }
4615e65e175bSOded Gabbay
4616e65e175bSOded Gabbay return 0;
4617e65e175bSOded Gabbay }
4618e65e175bSOded Gabbay
gaudi_scrub_device_mem(struct hl_device * hdev)4619e65e175bSOded Gabbay static int gaudi_scrub_device_mem(struct hl_device *hdev)
4620e65e175bSOded Gabbay {
4621e65e175bSOded Gabbay struct asic_fixed_properties *prop = &hdev->asic_prop;
4622e65e175bSOded Gabbay u64 wait_to_idle_time = hdev->pdev ? HBM_SCRUBBING_TIMEOUT_US :
4623e65e175bSOded Gabbay min_t(u64, HBM_SCRUBBING_TIMEOUT_US * 10, HL_SIM_MAX_TIMEOUT_US);
4624e65e175bSOded Gabbay u64 addr, size, val = hdev->memory_scrub_val;
4625e65e175bSOded Gabbay ktime_t timeout;
4626e65e175bSOded Gabbay int rc = 0;
4627e65e175bSOded Gabbay
4628e65e175bSOded Gabbay if (!hdev->memory_scrub)
4629e65e175bSOded Gabbay return 0;
4630e65e175bSOded Gabbay
4631e65e175bSOded Gabbay timeout = ktime_add_us(ktime_get(), wait_to_idle_time);
4632e65e175bSOded Gabbay while (!hdev->asic_funcs->is_device_idle(hdev, NULL, 0, NULL)) {
4633e65e175bSOded Gabbay if (ktime_compare(ktime_get(), timeout) > 0) {
4634e65e175bSOded Gabbay dev_err(hdev->dev, "waiting for idle timeout\n");
4635e65e175bSOded Gabbay return -ETIMEDOUT;
4636e65e175bSOded Gabbay }
4637e65e175bSOded Gabbay usleep_range((1000 >> 2) + 1, 1000);
4638e65e175bSOded Gabbay }
4639e65e175bSOded Gabbay
4640e65e175bSOded Gabbay /* Scrub SRAM */
4641e65e175bSOded Gabbay addr = prop->sram_user_base_address;
4642e65e175bSOded Gabbay size = hdev->pldm ? 0x10000 : prop->sram_size - SRAM_USER_BASE_OFFSET;
4643e65e175bSOded Gabbay
4644e65e175bSOded Gabbay dev_dbg(hdev->dev, "Scrubbing SRAM: 0x%09llx - 0x%09llx val: 0x%llx\n",
4645e65e175bSOded Gabbay addr, addr + size, val);
4646e65e175bSOded Gabbay rc = gaudi_memset_device_memory(hdev, addr, size, val);
4647e65e175bSOded Gabbay if (rc) {
4648e65e175bSOded Gabbay dev_err(hdev->dev, "Failed to clear SRAM (%d)\n", rc);
4649e65e175bSOded Gabbay return rc;
4650e65e175bSOded Gabbay }
4651e65e175bSOded Gabbay
4652e65e175bSOded Gabbay /* Scrub HBM using all DMA channels in parallel */
4653e65e175bSOded Gabbay rc = gaudi_scrub_device_dram(hdev, val);
4654e65e175bSOded Gabbay if (rc) {
4655e65e175bSOded Gabbay dev_err(hdev->dev, "Failed to clear HBM (%d)\n", rc);
4656e65e175bSOded Gabbay return rc;
4657e65e175bSOded Gabbay }
4658e65e175bSOded Gabbay
4659e65e175bSOded Gabbay return 0;
4660e65e175bSOded Gabbay }
4661e65e175bSOded Gabbay
gaudi_get_int_queue_base(struct hl_device * hdev,u32 queue_id,dma_addr_t * dma_handle,u16 * queue_len)4662e65e175bSOded Gabbay static void *gaudi_get_int_queue_base(struct hl_device *hdev,
4663e65e175bSOded Gabbay u32 queue_id, dma_addr_t *dma_handle,
4664e65e175bSOded Gabbay u16 *queue_len)
4665e65e175bSOded Gabbay {
4666e65e175bSOded Gabbay struct gaudi_device *gaudi = hdev->asic_specific;
4667e65e175bSOded Gabbay struct gaudi_internal_qman_info *q;
4668e65e175bSOded Gabbay
4669e65e175bSOded Gabbay if (queue_id >= GAUDI_QUEUE_ID_SIZE ||
4670e65e175bSOded Gabbay gaudi_queue_type[queue_id] != QUEUE_TYPE_INT) {
4671e65e175bSOded Gabbay dev_err(hdev->dev, "Got invalid queue id %d\n", queue_id);
4672e65e175bSOded Gabbay return NULL;
4673e65e175bSOded Gabbay }
4674e65e175bSOded Gabbay
4675e65e175bSOded Gabbay q = &gaudi->internal_qmans[queue_id];
4676e65e175bSOded Gabbay *dma_handle = q->pq_dma_addr;
4677e65e175bSOded Gabbay *queue_len = q->pq_size / QMAN_PQ_ENTRY_SIZE;
4678e65e175bSOded Gabbay
4679e65e175bSOded Gabbay return q->pq_kernel_addr;
4680e65e175bSOded Gabbay }
4681e65e175bSOded Gabbay
gaudi_send_cpu_message(struct hl_device * hdev,u32 * msg,u16 len,u32 timeout,u64 * result)4682e65e175bSOded Gabbay static int gaudi_send_cpu_message(struct hl_device *hdev, u32 *msg,
4683e65e175bSOded Gabbay u16 len, u32 timeout, u64 *result)
4684e65e175bSOded Gabbay {
4685e65e175bSOded Gabbay struct gaudi_device *gaudi = hdev->asic_specific;
4686e65e175bSOded Gabbay
4687e65e175bSOded Gabbay if (!(gaudi->hw_cap_initialized & HW_CAP_CPU_Q)) {
4688e65e175bSOded Gabbay if (result)
4689e65e175bSOded Gabbay *result = 0;
4690e65e175bSOded Gabbay return 0;
4691e65e175bSOded Gabbay }
4692e65e175bSOded Gabbay
4693e65e175bSOded Gabbay if (!timeout)
4694e65e175bSOded Gabbay timeout = GAUDI_MSG_TO_CPU_TIMEOUT_USEC;
4695e65e175bSOded Gabbay
4696e65e175bSOded Gabbay return hl_fw_send_cpu_message(hdev, GAUDI_QUEUE_ID_CPU_PQ, msg, len,
4697e65e175bSOded Gabbay timeout, result);
4698e65e175bSOded Gabbay }
4699e65e175bSOded Gabbay
gaudi_test_queue(struct hl_device * hdev,u32 hw_queue_id)4700e65e175bSOded Gabbay static int gaudi_test_queue(struct hl_device *hdev, u32 hw_queue_id)
4701e65e175bSOded Gabbay {
4702e65e175bSOded Gabbay struct packet_msg_prot *fence_pkt;
4703e65e175bSOded Gabbay dma_addr_t pkt_dma_addr;
4704e65e175bSOded Gabbay u32 fence_val, tmp, timeout_usec;
4705e65e175bSOded Gabbay dma_addr_t fence_dma_addr;
4706e65e175bSOded Gabbay u32 *fence_ptr;
4707e65e175bSOded Gabbay int rc;
4708e65e175bSOded Gabbay
4709e65e175bSOded Gabbay if (hdev->pldm)
4710e65e175bSOded Gabbay timeout_usec = GAUDI_PLDM_TEST_QUEUE_WAIT_USEC;
4711e65e175bSOded Gabbay else
4712e65e175bSOded Gabbay timeout_usec = GAUDI_TEST_QUEUE_WAIT_USEC;
4713e65e175bSOded Gabbay
4714e65e175bSOded Gabbay fence_val = GAUDI_QMAN0_FENCE_VAL;
4715e65e175bSOded Gabbay
4716e65e175bSOded Gabbay fence_ptr = hl_asic_dma_pool_zalloc(hdev, 4, GFP_KERNEL, &fence_dma_addr);
4717e65e175bSOded Gabbay if (!fence_ptr) {
4718e65e175bSOded Gabbay dev_err(hdev->dev,
4719e65e175bSOded Gabbay "Failed to allocate memory for H/W queue %d testing\n",
4720e65e175bSOded Gabbay hw_queue_id);
4721e65e175bSOded Gabbay return -ENOMEM;
4722e65e175bSOded Gabbay }
4723e65e175bSOded Gabbay
4724e65e175bSOded Gabbay *fence_ptr = 0;
4725e65e175bSOded Gabbay
4726e65e175bSOded Gabbay fence_pkt = hl_asic_dma_pool_zalloc(hdev, sizeof(struct packet_msg_prot), GFP_KERNEL,
4727e65e175bSOded Gabbay &pkt_dma_addr);
4728e65e175bSOded Gabbay if (!fence_pkt) {
4729e65e175bSOded Gabbay dev_err(hdev->dev,
4730e65e175bSOded Gabbay "Failed to allocate packet for H/W queue %d testing\n",
4731e65e175bSOded Gabbay hw_queue_id);
4732e65e175bSOded Gabbay rc = -ENOMEM;
4733e65e175bSOded Gabbay goto free_fence_ptr;
4734e65e175bSOded Gabbay }
4735e65e175bSOded Gabbay
4736e65e175bSOded Gabbay tmp = FIELD_PREP(GAUDI_PKT_CTL_OPCODE_MASK, PACKET_MSG_PROT);
4737e65e175bSOded Gabbay tmp |= FIELD_PREP(GAUDI_PKT_CTL_EB_MASK, 1);
4738e65e175bSOded Gabbay tmp |= FIELD_PREP(GAUDI_PKT_CTL_MB_MASK, 1);
4739e65e175bSOded Gabbay
4740e65e175bSOded Gabbay fence_pkt->ctl = cpu_to_le32(tmp);
4741e65e175bSOded Gabbay fence_pkt->value = cpu_to_le32(fence_val);
4742e65e175bSOded Gabbay fence_pkt->addr = cpu_to_le64(fence_dma_addr);
4743e65e175bSOded Gabbay
4744e65e175bSOded Gabbay rc = hl_hw_queue_send_cb_no_cmpl(hdev, hw_queue_id,
4745e65e175bSOded Gabbay sizeof(struct packet_msg_prot),
4746e65e175bSOded Gabbay pkt_dma_addr);
4747e65e175bSOded Gabbay if (rc) {
4748e65e175bSOded Gabbay dev_err(hdev->dev,
4749e65e175bSOded Gabbay "Failed to send fence packet to H/W queue %d\n",
4750e65e175bSOded Gabbay hw_queue_id);
4751e65e175bSOded Gabbay goto free_pkt;
4752e65e175bSOded Gabbay }
4753e65e175bSOded Gabbay
4754e65e175bSOded Gabbay rc = hl_poll_timeout_memory(hdev, fence_ptr, tmp, (tmp == fence_val),
4755e65e175bSOded Gabbay 1000, timeout_usec, true);
4756e65e175bSOded Gabbay
4757e65e175bSOded Gabbay hl_hw_queue_inc_ci_kernel(hdev, hw_queue_id);
4758e65e175bSOded Gabbay
4759e65e175bSOded Gabbay if (rc == -ETIMEDOUT) {
4760e65e175bSOded Gabbay dev_err(hdev->dev,
4761e65e175bSOded Gabbay "H/W queue %d test failed (scratch(0x%08llX) == 0x%08X)\n",
4762e65e175bSOded Gabbay hw_queue_id, (unsigned long long) fence_dma_addr, tmp);
4763e65e175bSOded Gabbay rc = -EIO;
4764e65e175bSOded Gabbay }
4765e65e175bSOded Gabbay
4766e65e175bSOded Gabbay free_pkt:
4767e65e175bSOded Gabbay hl_asic_dma_pool_free(hdev, (void *) fence_pkt, pkt_dma_addr);
4768e65e175bSOded Gabbay free_fence_ptr:
4769e65e175bSOded Gabbay hl_asic_dma_pool_free(hdev, (void *) fence_ptr, fence_dma_addr);
4770e65e175bSOded Gabbay return rc;
4771e65e175bSOded Gabbay }
4772e65e175bSOded Gabbay
gaudi_test_cpu_queue(struct hl_device * hdev)4773e65e175bSOded Gabbay static int gaudi_test_cpu_queue(struct hl_device *hdev)
4774e65e175bSOded Gabbay {
4775e65e175bSOded Gabbay struct gaudi_device *gaudi = hdev->asic_specific;
4776e65e175bSOded Gabbay
4777e65e175bSOded Gabbay /*
4778e65e175bSOded Gabbay * check capability here as send_cpu_message() won't update the result
4779e65e175bSOded Gabbay * value if no capability
4780e65e175bSOded Gabbay */
4781e65e175bSOded Gabbay if (!(gaudi->hw_cap_initialized & HW_CAP_CPU_Q))
4782e65e175bSOded Gabbay return 0;
4783e65e175bSOded Gabbay
4784e65e175bSOded Gabbay return hl_fw_test_cpu_queue(hdev);
4785e65e175bSOded Gabbay }
4786e65e175bSOded Gabbay
gaudi_test_queues(struct hl_device * hdev)4787e65e175bSOded Gabbay static int gaudi_test_queues(struct hl_device *hdev)
4788e65e175bSOded Gabbay {
4789e65e175bSOded Gabbay int i, rc, ret_val = 0;
4790e65e175bSOded Gabbay
4791e65e175bSOded Gabbay for (i = 0 ; i < hdev->asic_prop.max_queues ; i++) {
4792e65e175bSOded Gabbay if (hdev->asic_prop.hw_queues_props[i].type == QUEUE_TYPE_EXT) {
4793e65e175bSOded Gabbay rc = gaudi_test_queue(hdev, i);
4794e65e175bSOded Gabbay if (rc)
4795e65e175bSOded Gabbay ret_val = -EINVAL;
4796e65e175bSOded Gabbay }
4797e65e175bSOded Gabbay }
4798e65e175bSOded Gabbay
4799e65e175bSOded Gabbay rc = gaudi_test_cpu_queue(hdev);
4800e65e175bSOded Gabbay if (rc)
4801e65e175bSOded Gabbay ret_val = -EINVAL;
4802e65e175bSOded Gabbay
4803e65e175bSOded Gabbay return ret_val;
4804e65e175bSOded Gabbay }
4805e65e175bSOded Gabbay
gaudi_dma_pool_zalloc(struct hl_device * hdev,size_t size,gfp_t mem_flags,dma_addr_t * dma_handle)4806e65e175bSOded Gabbay static void *gaudi_dma_pool_zalloc(struct hl_device *hdev, size_t size,
4807e65e175bSOded Gabbay gfp_t mem_flags, dma_addr_t *dma_handle)
4808e65e175bSOded Gabbay {
4809e65e175bSOded Gabbay void *kernel_addr;
4810e65e175bSOded Gabbay
4811e65e175bSOded Gabbay if (size > GAUDI_DMA_POOL_BLK_SIZE)
4812e65e175bSOded Gabbay return NULL;
4813e65e175bSOded Gabbay
4814e65e175bSOded Gabbay kernel_addr = dma_pool_zalloc(hdev->dma_pool, mem_flags, dma_handle);
4815e65e175bSOded Gabbay
4816e65e175bSOded Gabbay /* Shift to the device's base physical address of host memory */
4817e65e175bSOded Gabbay if (kernel_addr)
4818e65e175bSOded Gabbay *dma_handle += HOST_PHYS_BASE;
4819e65e175bSOded Gabbay
4820e65e175bSOded Gabbay return kernel_addr;
4821e65e175bSOded Gabbay }
4822e65e175bSOded Gabbay
gaudi_dma_pool_free(struct hl_device * hdev,void * vaddr,dma_addr_t dma_addr)4823e65e175bSOded Gabbay static void gaudi_dma_pool_free(struct hl_device *hdev, void *vaddr,
4824e65e175bSOded Gabbay dma_addr_t dma_addr)
4825e65e175bSOded Gabbay {
4826e65e175bSOded Gabbay /* Cancel the device's base physical address of host memory */
4827e65e175bSOded Gabbay dma_addr_t fixed_dma_addr = dma_addr - HOST_PHYS_BASE;
4828e65e175bSOded Gabbay
4829e65e175bSOded Gabbay dma_pool_free(hdev->dma_pool, vaddr, fixed_dma_addr);
4830e65e175bSOded Gabbay }
4831e65e175bSOded Gabbay
gaudi_cpu_accessible_dma_pool_alloc(struct hl_device * hdev,size_t size,dma_addr_t * dma_handle)4832e65e175bSOded Gabbay static void *gaudi_cpu_accessible_dma_pool_alloc(struct hl_device *hdev,
4833e65e175bSOded Gabbay size_t size, dma_addr_t *dma_handle)
4834e65e175bSOded Gabbay {
4835e65e175bSOded Gabbay return hl_fw_cpu_accessible_dma_pool_alloc(hdev, size, dma_handle);
4836e65e175bSOded Gabbay }
4837e65e175bSOded Gabbay
gaudi_cpu_accessible_dma_pool_free(struct hl_device * hdev,size_t size,void * vaddr)4838e65e175bSOded Gabbay static void gaudi_cpu_accessible_dma_pool_free(struct hl_device *hdev,
4839e65e175bSOded Gabbay size_t size, void *vaddr)
4840e65e175bSOded Gabbay {
4841e65e175bSOded Gabbay hl_fw_cpu_accessible_dma_pool_free(hdev, size, vaddr);
4842e65e175bSOded Gabbay }
4843e65e175bSOded Gabbay
gaudi_get_dma_desc_list_size(struct hl_device * hdev,struct sg_table * sgt)4844e65e175bSOded Gabbay static u32 gaudi_get_dma_desc_list_size(struct hl_device *hdev, struct sg_table *sgt)
4845e65e175bSOded Gabbay {
4846e65e175bSOded Gabbay struct scatterlist *sg, *sg_next_iter;
4847e65e175bSOded Gabbay u32 count, dma_desc_cnt;
4848e65e175bSOded Gabbay u64 len, len_next;
4849e65e175bSOded Gabbay dma_addr_t addr, addr_next;
4850e65e175bSOded Gabbay
4851e65e175bSOded Gabbay dma_desc_cnt = 0;
4852e65e175bSOded Gabbay
4853e65e175bSOded Gabbay for_each_sgtable_dma_sg(sgt, sg, count) {
4854e65e175bSOded Gabbay len = sg_dma_len(sg);
4855e65e175bSOded Gabbay addr = sg_dma_address(sg);
4856e65e175bSOded Gabbay
4857e65e175bSOded Gabbay if (len == 0)
4858e65e175bSOded Gabbay break;
4859e65e175bSOded Gabbay
4860e65e175bSOded Gabbay while ((count + 1) < sgt->nents) {
4861e65e175bSOded Gabbay sg_next_iter = sg_next(sg);
4862e65e175bSOded Gabbay len_next = sg_dma_len(sg_next_iter);
4863e65e175bSOded Gabbay addr_next = sg_dma_address(sg_next_iter);
4864e65e175bSOded Gabbay
4865e65e175bSOded Gabbay if (len_next == 0)
4866e65e175bSOded Gabbay break;
4867e65e175bSOded Gabbay
4868e65e175bSOded Gabbay if ((addr + len == addr_next) &&
4869e65e175bSOded Gabbay (len + len_next <= DMA_MAX_TRANSFER_SIZE)) {
4870e65e175bSOded Gabbay len += len_next;
4871e65e175bSOded Gabbay count++;
4872e65e175bSOded Gabbay sg = sg_next_iter;
4873e65e175bSOded Gabbay } else {
4874e65e175bSOded Gabbay break;
4875e65e175bSOded Gabbay }
4876e65e175bSOded Gabbay }
4877e65e175bSOded Gabbay
4878e65e175bSOded Gabbay dma_desc_cnt++;
4879e65e175bSOded Gabbay }
4880e65e175bSOded Gabbay
4881e65e175bSOded Gabbay return dma_desc_cnt * sizeof(struct packet_lin_dma);
4882e65e175bSOded Gabbay }
4883e65e175bSOded Gabbay
gaudi_pin_memory_before_cs(struct hl_device * hdev,struct hl_cs_parser * parser,struct packet_lin_dma * user_dma_pkt,u64 addr,enum dma_data_direction dir)4884e65e175bSOded Gabbay static int gaudi_pin_memory_before_cs(struct hl_device *hdev,
4885e65e175bSOded Gabbay struct hl_cs_parser *parser,
4886e65e175bSOded Gabbay struct packet_lin_dma *user_dma_pkt,
4887e65e175bSOded Gabbay u64 addr, enum dma_data_direction dir)
4888e65e175bSOded Gabbay {
4889e65e175bSOded Gabbay struct hl_userptr *userptr;
4890e65e175bSOded Gabbay int rc;
4891e65e175bSOded Gabbay
4892e65e175bSOded Gabbay if (hl_userptr_is_pinned(hdev, addr, le32_to_cpu(user_dma_pkt->tsize),
4893e65e175bSOded Gabbay parser->job_userptr_list, &userptr))
4894e65e175bSOded Gabbay goto already_pinned;
4895e65e175bSOded Gabbay
4896e65e175bSOded Gabbay userptr = kzalloc(sizeof(*userptr), GFP_KERNEL);
4897e65e175bSOded Gabbay if (!userptr)
4898e65e175bSOded Gabbay return -ENOMEM;
4899e65e175bSOded Gabbay
4900e65e175bSOded Gabbay rc = hl_pin_host_memory(hdev, addr, le32_to_cpu(user_dma_pkt->tsize),
4901e65e175bSOded Gabbay userptr);
4902e65e175bSOded Gabbay if (rc)
4903e65e175bSOded Gabbay goto free_userptr;
4904e65e175bSOded Gabbay
4905e65e175bSOded Gabbay list_add_tail(&userptr->job_node, parser->job_userptr_list);
4906e65e175bSOded Gabbay
4907e65e175bSOded Gabbay rc = hdev->asic_funcs->asic_dma_map_sgtable(hdev, userptr->sgt, dir);
4908e65e175bSOded Gabbay if (rc) {
4909e65e175bSOded Gabbay dev_err(hdev->dev, "failed to map sgt with DMA region\n");
4910e65e175bSOded Gabbay goto unpin_memory;
4911e65e175bSOded Gabbay }
4912e65e175bSOded Gabbay
4913e65e175bSOded Gabbay userptr->dma_mapped = true;
4914e65e175bSOded Gabbay userptr->dir = dir;
4915e65e175bSOded Gabbay
4916e65e175bSOded Gabbay already_pinned:
4917e65e175bSOded Gabbay parser->patched_cb_size +=
4918e65e175bSOded Gabbay gaudi_get_dma_desc_list_size(hdev, userptr->sgt);
4919e65e175bSOded Gabbay
4920e65e175bSOded Gabbay return 0;
4921e65e175bSOded Gabbay
4922e65e175bSOded Gabbay unpin_memory:
4923e65e175bSOded Gabbay list_del(&userptr->job_node);
4924e65e175bSOded Gabbay hl_unpin_host_memory(hdev, userptr);
4925e65e175bSOded Gabbay free_userptr:
4926e65e175bSOded Gabbay kfree(userptr);
4927e65e175bSOded Gabbay return rc;
4928e65e175bSOded Gabbay }
4929e65e175bSOded Gabbay
gaudi_validate_dma_pkt_host(struct hl_device * hdev,struct hl_cs_parser * parser,struct packet_lin_dma * user_dma_pkt,bool src_in_host)4930e65e175bSOded Gabbay static int gaudi_validate_dma_pkt_host(struct hl_device *hdev,
4931e65e175bSOded Gabbay struct hl_cs_parser *parser,
4932e65e175bSOded Gabbay struct packet_lin_dma *user_dma_pkt,
4933e65e175bSOded Gabbay bool src_in_host)
4934e65e175bSOded Gabbay {
4935e65e175bSOded Gabbay enum dma_data_direction dir;
4936e65e175bSOded Gabbay bool skip_host_mem_pin = false, user_memset;
4937e65e175bSOded Gabbay u64 addr;
4938e65e175bSOded Gabbay int rc = 0;
4939e65e175bSOded Gabbay
4940e65e175bSOded Gabbay user_memset = (le32_to_cpu(user_dma_pkt->ctl) &
4941e65e175bSOded Gabbay GAUDI_PKT_LIN_DMA_CTL_MEMSET_MASK) >>
4942e65e175bSOded Gabbay GAUDI_PKT_LIN_DMA_CTL_MEMSET_SHIFT;
4943e65e175bSOded Gabbay
4944e65e175bSOded Gabbay if (src_in_host) {
4945e65e175bSOded Gabbay if (user_memset)
4946e65e175bSOded Gabbay skip_host_mem_pin = true;
4947e65e175bSOded Gabbay
4948e65e175bSOded Gabbay dev_dbg(hdev->dev, "DMA direction is HOST --> DEVICE\n");
4949e65e175bSOded Gabbay dir = DMA_TO_DEVICE;
4950e65e175bSOded Gabbay addr = le64_to_cpu(user_dma_pkt->src_addr);
4951e65e175bSOded Gabbay } else {
4952e65e175bSOded Gabbay dev_dbg(hdev->dev, "DMA direction is DEVICE --> HOST\n");
4953e65e175bSOded Gabbay dir = DMA_FROM_DEVICE;
4954e65e175bSOded Gabbay addr = (le64_to_cpu(user_dma_pkt->dst_addr) &
4955e65e175bSOded Gabbay GAUDI_PKT_LIN_DMA_DST_ADDR_MASK) >>
4956e65e175bSOded Gabbay GAUDI_PKT_LIN_DMA_DST_ADDR_SHIFT;
4957e65e175bSOded Gabbay }
4958e65e175bSOded Gabbay
4959e65e175bSOded Gabbay if (skip_host_mem_pin)
4960e65e175bSOded Gabbay parser->patched_cb_size += sizeof(*user_dma_pkt);
4961e65e175bSOded Gabbay else
4962e65e175bSOded Gabbay rc = gaudi_pin_memory_before_cs(hdev, parser, user_dma_pkt,
4963e65e175bSOded Gabbay addr, dir);
4964e65e175bSOded Gabbay
4965e65e175bSOded Gabbay return rc;
4966e65e175bSOded Gabbay }
4967e65e175bSOded Gabbay
gaudi_validate_dma_pkt_no_mmu(struct hl_device * hdev,struct hl_cs_parser * parser,struct packet_lin_dma * user_dma_pkt)4968e65e175bSOded Gabbay static int gaudi_validate_dma_pkt_no_mmu(struct hl_device *hdev,
4969e65e175bSOded Gabbay struct hl_cs_parser *parser,
4970e65e175bSOded Gabbay struct packet_lin_dma *user_dma_pkt)
4971e65e175bSOded Gabbay {
4972e65e175bSOded Gabbay bool src_in_host = false;
4973e65e175bSOded Gabbay u64 dst_addr = (le64_to_cpu(user_dma_pkt->dst_addr) &
4974e65e175bSOded Gabbay GAUDI_PKT_LIN_DMA_DST_ADDR_MASK) >>
4975e65e175bSOded Gabbay GAUDI_PKT_LIN_DMA_DST_ADDR_SHIFT;
4976e65e175bSOded Gabbay
4977e65e175bSOded Gabbay dev_dbg(hdev->dev, "DMA packet details:\n");
4978e65e175bSOded Gabbay dev_dbg(hdev->dev, "source == 0x%llx\n",
4979e65e175bSOded Gabbay le64_to_cpu(user_dma_pkt->src_addr));
4980e65e175bSOded Gabbay dev_dbg(hdev->dev, "destination == 0x%llx\n", dst_addr);
4981e65e175bSOded Gabbay dev_dbg(hdev->dev, "size == %u\n", le32_to_cpu(user_dma_pkt->tsize));
4982e65e175bSOded Gabbay
4983e65e175bSOded Gabbay /*
4984e65e175bSOded Gabbay * Special handling for DMA with size 0. Bypass all validations
4985e65e175bSOded Gabbay * because no transactions will be done except for WR_COMP, which
4986e65e175bSOded Gabbay * is not a security issue
4987e65e175bSOded Gabbay */
4988e65e175bSOded Gabbay if (!le32_to_cpu(user_dma_pkt->tsize)) {
4989e65e175bSOded Gabbay parser->patched_cb_size += sizeof(*user_dma_pkt);
4990e65e175bSOded Gabbay return 0;
4991e65e175bSOded Gabbay }
4992e65e175bSOded Gabbay
4993e65e175bSOded Gabbay if (parser->hw_queue_id <= GAUDI_QUEUE_ID_DMA_0_3)
4994e65e175bSOded Gabbay src_in_host = true;
4995e65e175bSOded Gabbay
4996e65e175bSOded Gabbay return gaudi_validate_dma_pkt_host(hdev, parser, user_dma_pkt,
4997e65e175bSOded Gabbay src_in_host);
4998e65e175bSOded Gabbay }
4999e65e175bSOded Gabbay
gaudi_validate_load_and_exe_pkt(struct hl_device * hdev,struct hl_cs_parser * parser,struct packet_load_and_exe * user_pkt)5000e65e175bSOded Gabbay static int gaudi_validate_load_and_exe_pkt(struct hl_device *hdev,
5001e65e175bSOded Gabbay struct hl_cs_parser *parser,
5002e65e175bSOded Gabbay struct packet_load_and_exe *user_pkt)
5003e65e175bSOded Gabbay {
5004e65e175bSOded Gabbay u32 cfg;
5005e65e175bSOded Gabbay
5006e65e175bSOded Gabbay cfg = le32_to_cpu(user_pkt->cfg);
5007e65e175bSOded Gabbay
5008e65e175bSOded Gabbay if (cfg & GAUDI_PKT_LOAD_AND_EXE_CFG_DST_MASK) {
5009e65e175bSOded Gabbay dev_err(hdev->dev,
5010e65e175bSOded Gabbay "User not allowed to use Load and Execute\n");
5011e65e175bSOded Gabbay return -EPERM;
5012e65e175bSOded Gabbay }
5013e65e175bSOded Gabbay
5014e65e175bSOded Gabbay parser->patched_cb_size += sizeof(struct packet_load_and_exe);
5015e65e175bSOded Gabbay
5016e65e175bSOded Gabbay return 0;
5017e65e175bSOded Gabbay }
5018e65e175bSOded Gabbay
gaudi_validate_cb(struct hl_device * hdev,struct hl_cs_parser * parser,bool is_mmu)5019e65e175bSOded Gabbay static int gaudi_validate_cb(struct hl_device *hdev,
5020e65e175bSOded Gabbay struct hl_cs_parser *parser, bool is_mmu)
5021e65e175bSOded Gabbay {
5022e65e175bSOded Gabbay u32 cb_parsed_length = 0;
5023e65e175bSOded Gabbay int rc = 0;
5024e65e175bSOded Gabbay
5025e65e175bSOded Gabbay parser->patched_cb_size = 0;
5026e65e175bSOded Gabbay
5027e65e175bSOded Gabbay /* cb_user_size is more than 0 so loop will always be executed */
5028e65e175bSOded Gabbay while (cb_parsed_length < parser->user_cb_size) {
5029e65e175bSOded Gabbay enum packet_id pkt_id;
5030e65e175bSOded Gabbay u16 pkt_size;
5031e65e175bSOded Gabbay struct gaudi_packet *user_pkt;
5032e65e175bSOded Gabbay
5033e65e175bSOded Gabbay user_pkt = parser->user_cb->kernel_address + cb_parsed_length;
5034e65e175bSOded Gabbay
5035e65e175bSOded Gabbay pkt_id = (enum packet_id) (
5036e65e175bSOded Gabbay (le64_to_cpu(user_pkt->header) &
5037e65e175bSOded Gabbay PACKET_HEADER_PACKET_ID_MASK) >>
5038e65e175bSOded Gabbay PACKET_HEADER_PACKET_ID_SHIFT);
5039e65e175bSOded Gabbay
5040e65e175bSOded Gabbay if (!validate_packet_id(pkt_id)) {
5041e65e175bSOded Gabbay dev_err(hdev->dev, "Invalid packet id %u\n", pkt_id);
5042e65e175bSOded Gabbay rc = -EINVAL;
5043e65e175bSOded Gabbay break;
5044e65e175bSOded Gabbay }
5045e65e175bSOded Gabbay
5046e65e175bSOded Gabbay pkt_size = gaudi_packet_sizes[pkt_id];
5047e65e175bSOded Gabbay cb_parsed_length += pkt_size;
5048e65e175bSOded Gabbay if (cb_parsed_length > parser->user_cb_size) {
5049e65e175bSOded Gabbay dev_err(hdev->dev,
5050e65e175bSOded Gabbay "packet 0x%x is out of CB boundary\n", pkt_id);
5051e65e175bSOded Gabbay rc = -EINVAL;
5052e65e175bSOded Gabbay break;
5053e65e175bSOded Gabbay }
5054e65e175bSOded Gabbay
5055e65e175bSOded Gabbay switch (pkt_id) {
5056e65e175bSOded Gabbay case PACKET_MSG_PROT:
5057e65e175bSOded Gabbay dev_err(hdev->dev,
5058e65e175bSOded Gabbay "User not allowed to use MSG_PROT\n");
5059e65e175bSOded Gabbay rc = -EPERM;
5060e65e175bSOded Gabbay break;
5061e65e175bSOded Gabbay
5062e65e175bSOded Gabbay case PACKET_CP_DMA:
5063e65e175bSOded Gabbay dev_err(hdev->dev, "User not allowed to use CP_DMA\n");
5064e65e175bSOded Gabbay rc = -EPERM;
5065e65e175bSOded Gabbay break;
5066e65e175bSOded Gabbay
5067e65e175bSOded Gabbay case PACKET_STOP:
5068e65e175bSOded Gabbay dev_err(hdev->dev, "User not allowed to use STOP\n");
5069e65e175bSOded Gabbay rc = -EPERM;
5070e65e175bSOded Gabbay break;
5071e65e175bSOded Gabbay
5072e65e175bSOded Gabbay case PACKET_WREG_BULK:
5073e65e175bSOded Gabbay dev_err(hdev->dev,
5074e65e175bSOded Gabbay "User not allowed to use WREG_BULK\n");
5075e65e175bSOded Gabbay rc = -EPERM;
5076e65e175bSOded Gabbay break;
5077e65e175bSOded Gabbay
5078e65e175bSOded Gabbay case PACKET_LOAD_AND_EXE:
5079e65e175bSOded Gabbay rc = gaudi_validate_load_and_exe_pkt(hdev, parser,
5080e65e175bSOded Gabbay (struct packet_load_and_exe *) user_pkt);
5081e65e175bSOded Gabbay break;
5082e65e175bSOded Gabbay
5083e65e175bSOded Gabbay case PACKET_LIN_DMA:
5084e65e175bSOded Gabbay parser->contains_dma_pkt = true;
5085e65e175bSOded Gabbay if (is_mmu)
5086e65e175bSOded Gabbay parser->patched_cb_size += pkt_size;
5087e65e175bSOded Gabbay else
5088e65e175bSOded Gabbay rc = gaudi_validate_dma_pkt_no_mmu(hdev, parser,
5089e65e175bSOded Gabbay (struct packet_lin_dma *) user_pkt);
5090e65e175bSOded Gabbay break;
5091e65e175bSOded Gabbay
5092e65e175bSOded Gabbay case PACKET_WREG_32:
5093e65e175bSOded Gabbay case PACKET_MSG_LONG:
5094e65e175bSOded Gabbay case PACKET_MSG_SHORT:
5095e65e175bSOded Gabbay case PACKET_REPEAT:
5096e65e175bSOded Gabbay case PACKET_FENCE:
5097e65e175bSOded Gabbay case PACKET_NOP:
5098e65e175bSOded Gabbay case PACKET_ARB_POINT:
5099e65e175bSOded Gabbay parser->patched_cb_size += pkt_size;
5100e65e175bSOded Gabbay break;
5101e65e175bSOded Gabbay
5102e65e175bSOded Gabbay default:
5103e65e175bSOded Gabbay dev_err(hdev->dev, "Invalid packet header 0x%x\n",
5104e65e175bSOded Gabbay pkt_id);
5105e65e175bSOded Gabbay rc = -EINVAL;
5106e65e175bSOded Gabbay break;
5107e65e175bSOded Gabbay }
5108e65e175bSOded Gabbay
5109e65e175bSOded Gabbay if (rc)
5110e65e175bSOded Gabbay break;
5111e65e175bSOded Gabbay }
5112e65e175bSOded Gabbay
5113e65e175bSOded Gabbay /*
5114e65e175bSOded Gabbay * The new CB should have space at the end for two MSG_PROT packets:
5115e65e175bSOded Gabbay * 1. Optional NOP padding for cacheline alignment
5116e65e175bSOded Gabbay * 2. A packet that will act as a completion packet
5117e65e175bSOded Gabbay * 3. A packet that will generate MSI interrupt
5118e65e175bSOded Gabbay */
5119e65e175bSOded Gabbay if (parser->completion)
5120e65e175bSOded Gabbay parser->patched_cb_size += gaudi_get_patched_cb_extra_size(
5121e65e175bSOded Gabbay parser->patched_cb_size);
5122e65e175bSOded Gabbay
5123e65e175bSOded Gabbay return rc;
5124e65e175bSOded Gabbay }
5125e65e175bSOded Gabbay
gaudi_patch_dma_packet(struct hl_device * hdev,struct hl_cs_parser * parser,struct packet_lin_dma * user_dma_pkt,struct packet_lin_dma * new_dma_pkt,u32 * new_dma_pkt_size)5126e65e175bSOded Gabbay static int gaudi_patch_dma_packet(struct hl_device *hdev,
5127e65e175bSOded Gabbay struct hl_cs_parser *parser,
5128e65e175bSOded Gabbay struct packet_lin_dma *user_dma_pkt,
5129e65e175bSOded Gabbay struct packet_lin_dma *new_dma_pkt,
5130e65e175bSOded Gabbay u32 *new_dma_pkt_size)
5131e65e175bSOded Gabbay {
5132e65e175bSOded Gabbay struct hl_userptr *userptr;
5133e65e175bSOded Gabbay struct scatterlist *sg, *sg_next_iter;
5134e65e175bSOded Gabbay u32 count, dma_desc_cnt, user_wrcomp_en_mask, ctl;
5135e65e175bSOded Gabbay u64 len, len_next;
5136e65e175bSOded Gabbay dma_addr_t dma_addr, dma_addr_next;
5137e65e175bSOded Gabbay u64 device_memory_addr, addr;
5138e65e175bSOded Gabbay enum dma_data_direction dir;
5139e65e175bSOded Gabbay struct sg_table *sgt;
5140e65e175bSOded Gabbay bool src_in_host = false;
5141e65e175bSOded Gabbay bool skip_host_mem_pin = false;
5142e65e175bSOded Gabbay bool user_memset;
5143e65e175bSOded Gabbay
5144e65e175bSOded Gabbay ctl = le32_to_cpu(user_dma_pkt->ctl);
5145e65e175bSOded Gabbay
5146e65e175bSOded Gabbay if (parser->hw_queue_id <= GAUDI_QUEUE_ID_DMA_0_3)
5147e65e175bSOded Gabbay src_in_host = true;
5148e65e175bSOded Gabbay
5149e65e175bSOded Gabbay user_memset = (ctl & GAUDI_PKT_LIN_DMA_CTL_MEMSET_MASK) >>
5150e65e175bSOded Gabbay GAUDI_PKT_LIN_DMA_CTL_MEMSET_SHIFT;
5151e65e175bSOded Gabbay
5152e65e175bSOded Gabbay if (src_in_host) {
5153e65e175bSOded Gabbay addr = le64_to_cpu(user_dma_pkt->src_addr);
5154e65e175bSOded Gabbay device_memory_addr = le64_to_cpu(user_dma_pkt->dst_addr);
5155e65e175bSOded Gabbay dir = DMA_TO_DEVICE;
5156e65e175bSOded Gabbay if (user_memset)
5157e65e175bSOded Gabbay skip_host_mem_pin = true;
5158e65e175bSOded Gabbay } else {
5159e65e175bSOded Gabbay addr = le64_to_cpu(user_dma_pkt->dst_addr);
5160e65e175bSOded Gabbay device_memory_addr = le64_to_cpu(user_dma_pkt->src_addr);
5161e65e175bSOded Gabbay dir = DMA_FROM_DEVICE;
5162e65e175bSOded Gabbay }
5163e65e175bSOded Gabbay
5164e65e175bSOded Gabbay if ((!skip_host_mem_pin) &&
5165e65e175bSOded Gabbay (!hl_userptr_is_pinned(hdev, addr,
5166e65e175bSOded Gabbay le32_to_cpu(user_dma_pkt->tsize),
5167e65e175bSOded Gabbay parser->job_userptr_list, &userptr))) {
5168e65e175bSOded Gabbay dev_err(hdev->dev, "Userptr 0x%llx + 0x%x NOT mapped\n",
5169e65e175bSOded Gabbay addr, user_dma_pkt->tsize);
5170e65e175bSOded Gabbay return -EFAULT;
5171e65e175bSOded Gabbay }
5172e65e175bSOded Gabbay
5173e65e175bSOded Gabbay if ((user_memset) && (dir == DMA_TO_DEVICE)) {
5174e65e175bSOded Gabbay memcpy(new_dma_pkt, user_dma_pkt, sizeof(*user_dma_pkt));
5175e65e175bSOded Gabbay *new_dma_pkt_size = sizeof(*user_dma_pkt);
5176e65e175bSOded Gabbay return 0;
5177e65e175bSOded Gabbay }
5178e65e175bSOded Gabbay
5179e65e175bSOded Gabbay user_wrcomp_en_mask = ctl & GAUDI_PKT_LIN_DMA_CTL_WRCOMP_EN_MASK;
5180e65e175bSOded Gabbay
5181e65e175bSOded Gabbay sgt = userptr->sgt;
5182e65e175bSOded Gabbay dma_desc_cnt = 0;
5183e65e175bSOded Gabbay
5184e65e175bSOded Gabbay for_each_sgtable_dma_sg(sgt, sg, count) {
5185e65e175bSOded Gabbay len = sg_dma_len(sg);
5186e65e175bSOded Gabbay dma_addr = sg_dma_address(sg);
5187e65e175bSOded Gabbay
5188e65e175bSOded Gabbay if (len == 0)
5189e65e175bSOded Gabbay break;
5190e65e175bSOded Gabbay
5191e65e175bSOded Gabbay while ((count + 1) < sgt->nents) {
5192e65e175bSOded Gabbay sg_next_iter = sg_next(sg);
5193e65e175bSOded Gabbay len_next = sg_dma_len(sg_next_iter);
5194e65e175bSOded Gabbay dma_addr_next = sg_dma_address(sg_next_iter);
5195e65e175bSOded Gabbay
5196e65e175bSOded Gabbay if (len_next == 0)
5197e65e175bSOded Gabbay break;
5198e65e175bSOded Gabbay
5199e65e175bSOded Gabbay if ((dma_addr + len == dma_addr_next) &&
5200e65e175bSOded Gabbay (len + len_next <= DMA_MAX_TRANSFER_SIZE)) {
5201e65e175bSOded Gabbay len += len_next;
5202e65e175bSOded Gabbay count++;
5203e65e175bSOded Gabbay sg = sg_next_iter;
5204e65e175bSOded Gabbay } else {
5205e65e175bSOded Gabbay break;
5206e65e175bSOded Gabbay }
5207e65e175bSOded Gabbay }
5208e65e175bSOded Gabbay
5209e65e175bSOded Gabbay ctl = le32_to_cpu(user_dma_pkt->ctl);
5210e65e175bSOded Gabbay if (likely(dma_desc_cnt))
5211e65e175bSOded Gabbay ctl &= ~GAUDI_PKT_CTL_EB_MASK;
5212e65e175bSOded Gabbay ctl &= ~GAUDI_PKT_LIN_DMA_CTL_WRCOMP_EN_MASK;
5213e65e175bSOded Gabbay new_dma_pkt->ctl = cpu_to_le32(ctl);
5214e65e175bSOded Gabbay new_dma_pkt->tsize = cpu_to_le32(len);
5215e65e175bSOded Gabbay
5216e65e175bSOded Gabbay if (dir == DMA_TO_DEVICE) {
5217e65e175bSOded Gabbay new_dma_pkt->src_addr = cpu_to_le64(dma_addr);
5218e65e175bSOded Gabbay new_dma_pkt->dst_addr = cpu_to_le64(device_memory_addr);
5219e65e175bSOded Gabbay } else {
5220e65e175bSOded Gabbay new_dma_pkt->src_addr = cpu_to_le64(device_memory_addr);
5221e65e175bSOded Gabbay new_dma_pkt->dst_addr = cpu_to_le64(dma_addr);
5222e65e175bSOded Gabbay }
5223e65e175bSOded Gabbay
5224e65e175bSOded Gabbay if (!user_memset)
5225e65e175bSOded Gabbay device_memory_addr += len;
5226e65e175bSOded Gabbay dma_desc_cnt++;
5227e65e175bSOded Gabbay new_dma_pkt++;
5228e65e175bSOded Gabbay }
5229e65e175bSOded Gabbay
5230e65e175bSOded Gabbay if (!dma_desc_cnt) {
5231e65e175bSOded Gabbay dev_err(hdev->dev,
5232e65e175bSOded Gabbay "Error of 0 SG entries when patching DMA packet\n");
5233e65e175bSOded Gabbay return -EFAULT;
5234e65e175bSOded Gabbay }
5235e65e175bSOded Gabbay
5236e65e175bSOded Gabbay /* Fix the last dma packet - wrcomp must be as user set it */
5237e65e175bSOded Gabbay new_dma_pkt--;
5238e65e175bSOded Gabbay new_dma_pkt->ctl |= cpu_to_le32(user_wrcomp_en_mask);
5239e65e175bSOded Gabbay
5240e65e175bSOded Gabbay *new_dma_pkt_size = dma_desc_cnt * sizeof(struct packet_lin_dma);
5241e65e175bSOded Gabbay
5242e65e175bSOded Gabbay return 0;
5243e65e175bSOded Gabbay }
5244e65e175bSOded Gabbay
gaudi_patch_cb(struct hl_device * hdev,struct hl_cs_parser * parser)5245e65e175bSOded Gabbay static int gaudi_patch_cb(struct hl_device *hdev,
5246e65e175bSOded Gabbay struct hl_cs_parser *parser)
5247e65e175bSOded Gabbay {
5248e65e175bSOded Gabbay u32 cb_parsed_length = 0;
5249e65e175bSOded Gabbay u32 cb_patched_cur_length = 0;
5250e65e175bSOded Gabbay int rc = 0;
5251e65e175bSOded Gabbay
5252e65e175bSOded Gabbay /* cb_user_size is more than 0 so loop will always be executed */
5253e65e175bSOded Gabbay while (cb_parsed_length < parser->user_cb_size) {
5254e65e175bSOded Gabbay enum packet_id pkt_id;
5255e65e175bSOded Gabbay u16 pkt_size;
5256e65e175bSOded Gabbay u32 new_pkt_size = 0;
5257e65e175bSOded Gabbay struct gaudi_packet *user_pkt, *kernel_pkt;
5258e65e175bSOded Gabbay
5259e65e175bSOded Gabbay user_pkt = parser->user_cb->kernel_address + cb_parsed_length;
5260e65e175bSOded Gabbay kernel_pkt = parser->patched_cb->kernel_address +
5261e65e175bSOded Gabbay cb_patched_cur_length;
5262e65e175bSOded Gabbay
5263e65e175bSOded Gabbay pkt_id = (enum packet_id) (
5264e65e175bSOded Gabbay (le64_to_cpu(user_pkt->header) &
5265e65e175bSOded Gabbay PACKET_HEADER_PACKET_ID_MASK) >>
5266e65e175bSOded Gabbay PACKET_HEADER_PACKET_ID_SHIFT);
5267e65e175bSOded Gabbay
5268e65e175bSOded Gabbay if (!validate_packet_id(pkt_id)) {
5269e65e175bSOded Gabbay dev_err(hdev->dev, "Invalid packet id %u\n", pkt_id);
5270e65e175bSOded Gabbay rc = -EINVAL;
5271e65e175bSOded Gabbay break;
5272e65e175bSOded Gabbay }
5273e65e175bSOded Gabbay
5274e65e175bSOded Gabbay pkt_size = gaudi_packet_sizes[pkt_id];
5275e65e175bSOded Gabbay cb_parsed_length += pkt_size;
5276e65e175bSOded Gabbay if (cb_parsed_length > parser->user_cb_size) {
5277e65e175bSOded Gabbay dev_err(hdev->dev,
5278e65e175bSOded Gabbay "packet 0x%x is out of CB boundary\n", pkt_id);
5279e65e175bSOded Gabbay rc = -EINVAL;
5280e65e175bSOded Gabbay break;
5281e65e175bSOded Gabbay }
5282e65e175bSOded Gabbay
5283e65e175bSOded Gabbay switch (pkt_id) {
5284e65e175bSOded Gabbay case PACKET_LIN_DMA:
5285e65e175bSOded Gabbay rc = gaudi_patch_dma_packet(hdev, parser,
5286e65e175bSOded Gabbay (struct packet_lin_dma *) user_pkt,
5287e65e175bSOded Gabbay (struct packet_lin_dma *) kernel_pkt,
5288e65e175bSOded Gabbay &new_pkt_size);
5289e65e175bSOded Gabbay cb_patched_cur_length += new_pkt_size;
5290e65e175bSOded Gabbay break;
5291e65e175bSOded Gabbay
5292e65e175bSOded Gabbay case PACKET_MSG_PROT:
5293e65e175bSOded Gabbay dev_err(hdev->dev,
5294e65e175bSOded Gabbay "User not allowed to use MSG_PROT\n");
5295e65e175bSOded Gabbay rc = -EPERM;
5296e65e175bSOded Gabbay break;
5297e65e175bSOded Gabbay
5298e65e175bSOded Gabbay case PACKET_CP_DMA:
5299e65e175bSOded Gabbay dev_err(hdev->dev, "User not allowed to use CP_DMA\n");
5300e65e175bSOded Gabbay rc = -EPERM;
5301e65e175bSOded Gabbay break;
5302e65e175bSOded Gabbay
5303e65e175bSOded Gabbay case PACKET_STOP:
5304e65e175bSOded Gabbay dev_err(hdev->dev, "User not allowed to use STOP\n");
5305e65e175bSOded Gabbay rc = -EPERM;
5306e65e175bSOded Gabbay break;
5307e65e175bSOded Gabbay
5308e65e175bSOded Gabbay case PACKET_WREG_32:
5309e65e175bSOded Gabbay case PACKET_WREG_BULK:
5310e65e175bSOded Gabbay case PACKET_MSG_LONG:
5311e65e175bSOded Gabbay case PACKET_MSG_SHORT:
5312e65e175bSOded Gabbay case PACKET_REPEAT:
5313e65e175bSOded Gabbay case PACKET_FENCE:
5314e65e175bSOded Gabbay case PACKET_NOP:
5315e65e175bSOded Gabbay case PACKET_ARB_POINT:
5316e65e175bSOded Gabbay case PACKET_LOAD_AND_EXE:
5317e65e175bSOded Gabbay memcpy(kernel_pkt, user_pkt, pkt_size);
5318e65e175bSOded Gabbay cb_patched_cur_length += pkt_size;
5319e65e175bSOded Gabbay break;
5320e65e175bSOded Gabbay
5321e65e175bSOded Gabbay default:
5322e65e175bSOded Gabbay dev_err(hdev->dev, "Invalid packet header 0x%x\n",
5323e65e175bSOded Gabbay pkt_id);
5324e65e175bSOded Gabbay rc = -EINVAL;
5325e65e175bSOded Gabbay break;
5326e65e175bSOded Gabbay }
5327e65e175bSOded Gabbay
5328e65e175bSOded Gabbay if (rc)
5329e65e175bSOded Gabbay break;
5330e65e175bSOded Gabbay }
5331e65e175bSOded Gabbay
5332e65e175bSOded Gabbay return rc;
5333e65e175bSOded Gabbay }
5334e65e175bSOded Gabbay
gaudi_parse_cb_mmu(struct hl_device * hdev,struct hl_cs_parser * parser)5335e65e175bSOded Gabbay static int gaudi_parse_cb_mmu(struct hl_device *hdev,
5336e65e175bSOded Gabbay struct hl_cs_parser *parser)
5337e65e175bSOded Gabbay {
5338e65e175bSOded Gabbay u64 handle;
5339e65e175bSOded Gabbay u32 patched_cb_size;
5340e65e175bSOded Gabbay struct hl_cb *user_cb;
5341e65e175bSOded Gabbay int rc;
5342e65e175bSOded Gabbay
5343e65e175bSOded Gabbay /*
5344e65e175bSOded Gabbay * The new CB should have space at the end for two MSG_PROT packets:
5345e65e175bSOded Gabbay * 1. Optional NOP padding for cacheline alignment
5346e65e175bSOded Gabbay * 2. A packet that will act as a completion packet
5347e65e175bSOded Gabbay * 3. A packet that will generate MSI interrupt
5348e65e175bSOded Gabbay */
5349e65e175bSOded Gabbay if (parser->completion)
5350e65e175bSOded Gabbay parser->patched_cb_size = parser->user_cb_size +
5351e65e175bSOded Gabbay gaudi_get_patched_cb_extra_size(parser->user_cb_size);
5352e65e175bSOded Gabbay else
5353e65e175bSOded Gabbay parser->patched_cb_size = parser->user_cb_size;
5354e65e175bSOded Gabbay
5355e65e175bSOded Gabbay rc = hl_cb_create(hdev, &hdev->kernel_mem_mgr, hdev->kernel_ctx,
5356e65e175bSOded Gabbay parser->patched_cb_size, false, false,
5357e65e175bSOded Gabbay &handle);
5358e65e175bSOded Gabbay
5359e65e175bSOded Gabbay if (rc) {
5360e65e175bSOded Gabbay dev_err(hdev->dev,
5361e65e175bSOded Gabbay "Failed to allocate patched CB for DMA CS %d\n",
5362e65e175bSOded Gabbay rc);
5363e65e175bSOded Gabbay return rc;
5364e65e175bSOded Gabbay }
5365e65e175bSOded Gabbay
5366e65e175bSOded Gabbay parser->patched_cb = hl_cb_get(&hdev->kernel_mem_mgr, handle);
5367e65e175bSOded Gabbay /* hl_cb_get should never fail */
5368e65e175bSOded Gabbay if (!parser->patched_cb) {
5369e65e175bSOded Gabbay dev_crit(hdev->dev, "DMA CB handle invalid 0x%llx\n", handle);
5370e65e175bSOded Gabbay rc = -EFAULT;
5371e65e175bSOded Gabbay goto out;
5372e65e175bSOded Gabbay }
5373e65e175bSOded Gabbay
5374e65e175bSOded Gabbay /*
5375e65e175bSOded Gabbay * We are protected from overflow because the check
5376e65e175bSOded Gabbay * "parser->user_cb_size <= parser->user_cb->size" was done in get_cb_from_cs_chunk()
5377e65e175bSOded Gabbay * in the common code. That check is done only if is_kernel_allocated_cb is true.
5378e65e175bSOded Gabbay *
5379e65e175bSOded Gabbay * There is no option to reach here without going through that check because:
5380e65e175bSOded Gabbay * 1. validate_queue_index() assigns true to is_kernel_allocated_cb for any submission to
5381e65e175bSOded Gabbay * an external queue.
5382e65e175bSOded Gabbay * 2. For Gaudi, we only parse CBs that were submitted to the external queues.
5383e65e175bSOded Gabbay */
5384e65e175bSOded Gabbay memcpy(parser->patched_cb->kernel_address,
5385e65e175bSOded Gabbay parser->user_cb->kernel_address,
5386e65e175bSOded Gabbay parser->user_cb_size);
5387e65e175bSOded Gabbay
5388e65e175bSOded Gabbay patched_cb_size = parser->patched_cb_size;
5389e65e175bSOded Gabbay
5390e65e175bSOded Gabbay /* Validate patched CB instead of user CB */
5391e65e175bSOded Gabbay user_cb = parser->user_cb;
5392e65e175bSOded Gabbay parser->user_cb = parser->patched_cb;
5393e65e175bSOded Gabbay rc = gaudi_validate_cb(hdev, parser, true);
5394e65e175bSOded Gabbay parser->user_cb = user_cb;
5395e65e175bSOded Gabbay
5396e65e175bSOded Gabbay if (rc) {
5397e65e175bSOded Gabbay hl_cb_put(parser->patched_cb);
5398e65e175bSOded Gabbay goto out;
5399e65e175bSOded Gabbay }
5400e65e175bSOded Gabbay
5401e65e175bSOded Gabbay if (patched_cb_size != parser->patched_cb_size) {
5402e65e175bSOded Gabbay dev_err(hdev->dev, "user CB size mismatch\n");
5403e65e175bSOded Gabbay hl_cb_put(parser->patched_cb);
5404e65e175bSOded Gabbay rc = -EINVAL;
5405e65e175bSOded Gabbay goto out;
5406e65e175bSOded Gabbay }
5407e65e175bSOded Gabbay
5408e65e175bSOded Gabbay out:
5409e65e175bSOded Gabbay /*
5410e65e175bSOded Gabbay * Always call cb destroy here because we still have 1 reference
5411e65e175bSOded Gabbay * to it by calling cb_get earlier. After the job will be completed,
5412e65e175bSOded Gabbay * cb_put will release it, but here we want to remove it from the
5413e65e175bSOded Gabbay * idr
5414e65e175bSOded Gabbay */
5415e65e175bSOded Gabbay hl_cb_destroy(&hdev->kernel_mem_mgr, handle);
5416e65e175bSOded Gabbay
5417e65e175bSOded Gabbay return rc;
5418e65e175bSOded Gabbay }
5419e65e175bSOded Gabbay
gaudi_parse_cb_no_mmu(struct hl_device * hdev,struct hl_cs_parser * parser)5420e65e175bSOded Gabbay static int gaudi_parse_cb_no_mmu(struct hl_device *hdev,
5421e65e175bSOded Gabbay struct hl_cs_parser *parser)
5422e65e175bSOded Gabbay {
5423e65e175bSOded Gabbay u64 handle;
5424e65e175bSOded Gabbay int rc;
5425e65e175bSOded Gabbay
5426e65e175bSOded Gabbay rc = gaudi_validate_cb(hdev, parser, false);
5427e65e175bSOded Gabbay
5428e65e175bSOded Gabbay if (rc)
5429e65e175bSOded Gabbay goto free_userptr;
5430e65e175bSOded Gabbay
5431e65e175bSOded Gabbay rc = hl_cb_create(hdev, &hdev->kernel_mem_mgr, hdev->kernel_ctx,
5432e65e175bSOded Gabbay parser->patched_cb_size, false, false,
5433e65e175bSOded Gabbay &handle);
5434e65e175bSOded Gabbay if (rc) {
5435e65e175bSOded Gabbay dev_err(hdev->dev,
5436e65e175bSOded Gabbay "Failed to allocate patched CB for DMA CS %d\n", rc);
5437e65e175bSOded Gabbay goto free_userptr;
5438e65e175bSOded Gabbay }
5439e65e175bSOded Gabbay
5440e65e175bSOded Gabbay parser->patched_cb = hl_cb_get(&hdev->kernel_mem_mgr, handle);
5441e65e175bSOded Gabbay /* hl_cb_get should never fail here */
5442e65e175bSOded Gabbay if (!parser->patched_cb) {
5443e65e175bSOded Gabbay dev_crit(hdev->dev, "DMA CB handle invalid 0x%llx\n", handle);
5444e65e175bSOded Gabbay rc = -EFAULT;
5445e65e175bSOded Gabbay goto out;
5446e65e175bSOded Gabbay }
5447e65e175bSOded Gabbay
5448e65e175bSOded Gabbay rc = gaudi_patch_cb(hdev, parser);
5449e65e175bSOded Gabbay
5450e65e175bSOded Gabbay if (rc)
5451e65e175bSOded Gabbay hl_cb_put(parser->patched_cb);
5452e65e175bSOded Gabbay
5453e65e175bSOded Gabbay out:
5454e65e175bSOded Gabbay /*
5455e65e175bSOded Gabbay * Always call cb destroy here because we still have 1 reference
5456e65e175bSOded Gabbay * to it by calling cb_get earlier. After the job will be completed,
5457e65e175bSOded Gabbay * cb_put will release it, but here we want to remove it from the
5458e65e175bSOded Gabbay * idr
5459e65e175bSOded Gabbay */
5460e65e175bSOded Gabbay hl_cb_destroy(&hdev->kernel_mem_mgr, handle);
5461e65e175bSOded Gabbay
5462e65e175bSOded Gabbay free_userptr:
5463e65e175bSOded Gabbay if (rc)
5464e65e175bSOded Gabbay hl_userptr_delete_list(hdev, parser->job_userptr_list);
5465e65e175bSOded Gabbay return rc;
5466e65e175bSOded Gabbay }
5467e65e175bSOded Gabbay
gaudi_parse_cb_no_ext_queue(struct hl_device * hdev,struct hl_cs_parser * parser)5468e65e175bSOded Gabbay static int gaudi_parse_cb_no_ext_queue(struct hl_device *hdev,
5469e65e175bSOded Gabbay struct hl_cs_parser *parser)
5470e65e175bSOded Gabbay {
5471e65e175bSOded Gabbay struct asic_fixed_properties *asic_prop = &hdev->asic_prop;
5472e65e175bSOded Gabbay struct gaudi_device *gaudi = hdev->asic_specific;
5473e65e175bSOded Gabbay u32 nic_queue_offset, nic_mask_q_id;
5474e65e175bSOded Gabbay
5475e65e175bSOded Gabbay if ((parser->hw_queue_id >= GAUDI_QUEUE_ID_NIC_0_0) &&
5476e65e175bSOded Gabbay (parser->hw_queue_id <= GAUDI_QUEUE_ID_NIC_9_3)) {
5477e65e175bSOded Gabbay nic_queue_offset = parser->hw_queue_id - GAUDI_QUEUE_ID_NIC_0_0;
5478e65e175bSOded Gabbay nic_mask_q_id = 1 << (HW_CAP_NIC_SHIFT + (nic_queue_offset >> 2));
5479e65e175bSOded Gabbay
5480e65e175bSOded Gabbay if (!(gaudi->hw_cap_initialized & nic_mask_q_id)) {
5481e65e175bSOded Gabbay dev_err(hdev->dev, "h/w queue %d is disabled\n", parser->hw_queue_id);
5482e65e175bSOded Gabbay return -EINVAL;
5483e65e175bSOded Gabbay }
5484e65e175bSOded Gabbay }
5485e65e175bSOded Gabbay
5486e65e175bSOded Gabbay /* For internal queue jobs just check if CB address is valid */
5487e65e175bSOded Gabbay if (hl_mem_area_inside_range((u64) (uintptr_t) parser->user_cb,
5488e65e175bSOded Gabbay parser->user_cb_size,
5489e65e175bSOded Gabbay asic_prop->sram_user_base_address,
5490e65e175bSOded Gabbay asic_prop->sram_end_address))
5491e65e175bSOded Gabbay return 0;
5492e65e175bSOded Gabbay
5493e65e175bSOded Gabbay if (hl_mem_area_inside_range((u64) (uintptr_t) parser->user_cb,
5494e65e175bSOded Gabbay parser->user_cb_size,
5495e65e175bSOded Gabbay asic_prop->dram_user_base_address,
5496e65e175bSOded Gabbay asic_prop->dram_end_address))
5497e65e175bSOded Gabbay return 0;
5498e65e175bSOded Gabbay
5499e65e175bSOded Gabbay /* PMMU and HPMMU addresses are equal, check only one of them */
5500e65e175bSOded Gabbay if (hl_mem_area_inside_range((u64) (uintptr_t) parser->user_cb,
5501e65e175bSOded Gabbay parser->user_cb_size,
5502e65e175bSOded Gabbay asic_prop->pmmu.start_addr,
5503e65e175bSOded Gabbay asic_prop->pmmu.end_addr))
5504e65e175bSOded Gabbay return 0;
5505e65e175bSOded Gabbay
5506e65e175bSOded Gabbay dev_err(hdev->dev,
5507e65e175bSOded Gabbay "CB address 0x%px + 0x%x for internal QMAN is not valid\n",
5508e65e175bSOded Gabbay parser->user_cb, parser->user_cb_size);
5509e65e175bSOded Gabbay
5510e65e175bSOded Gabbay return -EFAULT;
5511e65e175bSOded Gabbay }
5512e65e175bSOded Gabbay
gaudi_cs_parser(struct hl_device * hdev,struct hl_cs_parser * parser)5513e65e175bSOded Gabbay static int gaudi_cs_parser(struct hl_device *hdev, struct hl_cs_parser *parser)
5514e65e175bSOded Gabbay {
5515e65e175bSOded Gabbay struct gaudi_device *gaudi = hdev->asic_specific;
5516e65e175bSOded Gabbay
5517e65e175bSOded Gabbay if (parser->queue_type == QUEUE_TYPE_INT)
5518e65e175bSOded Gabbay return gaudi_parse_cb_no_ext_queue(hdev, parser);
5519e65e175bSOded Gabbay
5520e65e175bSOded Gabbay if (gaudi->hw_cap_initialized & HW_CAP_MMU)
5521e65e175bSOded Gabbay return gaudi_parse_cb_mmu(hdev, parser);
5522e65e175bSOded Gabbay else
5523e65e175bSOded Gabbay return gaudi_parse_cb_no_mmu(hdev, parser);
5524e65e175bSOded Gabbay }
5525e65e175bSOded Gabbay
gaudi_add_end_of_cb_packets(struct hl_device * hdev,void * kernel_address,u32 len,u32 original_len,u64 cq_addr,u32 cq_val,u32 msi_vec,bool eb)5526e65e175bSOded Gabbay static void gaudi_add_end_of_cb_packets(struct hl_device *hdev, void *kernel_address,
5527e65e175bSOded Gabbay u32 len, u32 original_len, u64 cq_addr, u32 cq_val,
5528e65e175bSOded Gabbay u32 msi_vec, bool eb)
5529e65e175bSOded Gabbay {
5530e65e175bSOded Gabbay struct packet_msg_prot *cq_pkt;
5531e65e175bSOded Gabbay struct packet_nop *cq_padding;
5532e65e175bSOded Gabbay u64 msi_addr;
5533e65e175bSOded Gabbay u32 tmp;
5534e65e175bSOded Gabbay
5535e65e175bSOded Gabbay cq_padding = kernel_address + original_len;
5536e65e175bSOded Gabbay cq_pkt = kernel_address + len - (sizeof(struct packet_msg_prot) * 2);
5537e65e175bSOded Gabbay
5538e65e175bSOded Gabbay while ((void *)cq_padding < (void *)cq_pkt) {
5539e65e175bSOded Gabbay cq_padding->ctl = cpu_to_le32(FIELD_PREP(GAUDI_PKT_CTL_OPCODE_MASK, PACKET_NOP));
5540e65e175bSOded Gabbay cq_padding++;
5541e65e175bSOded Gabbay }
5542e65e175bSOded Gabbay
5543e65e175bSOded Gabbay tmp = FIELD_PREP(GAUDI_PKT_CTL_OPCODE_MASK, PACKET_MSG_PROT);
5544e65e175bSOded Gabbay tmp |= FIELD_PREP(GAUDI_PKT_CTL_MB_MASK, 1);
5545e65e175bSOded Gabbay
5546e65e175bSOded Gabbay if (eb)
5547e65e175bSOded Gabbay tmp |= FIELD_PREP(GAUDI_PKT_CTL_EB_MASK, 1);
5548e65e175bSOded Gabbay
5549e65e175bSOded Gabbay cq_pkt->ctl = cpu_to_le32(tmp);
5550e65e175bSOded Gabbay cq_pkt->value = cpu_to_le32(cq_val);
5551e65e175bSOded Gabbay cq_pkt->addr = cpu_to_le64(cq_addr);
5552e65e175bSOded Gabbay
5553e65e175bSOded Gabbay cq_pkt++;
5554e65e175bSOded Gabbay
5555e65e175bSOded Gabbay tmp = FIELD_PREP(GAUDI_PKT_CTL_OPCODE_MASK, PACKET_MSG_PROT);
5556e65e175bSOded Gabbay tmp |= FIELD_PREP(GAUDI_PKT_CTL_MB_MASK, 1);
5557e65e175bSOded Gabbay cq_pkt->ctl = cpu_to_le32(tmp);
5558e65e175bSOded Gabbay cq_pkt->value = cpu_to_le32(1);
5559e65e175bSOded Gabbay msi_addr = hdev->pdev ? mmPCIE_CORE_MSI_REQ : mmPCIE_MSI_INTR_0 + msi_vec * 4;
5560e65e175bSOded Gabbay cq_pkt->addr = cpu_to_le64(CFG_BASE + msi_addr);
5561e65e175bSOded Gabbay }
5562e65e175bSOded Gabbay
gaudi_update_eq_ci(struct hl_device * hdev,u32 val)5563e65e175bSOded Gabbay static void gaudi_update_eq_ci(struct hl_device *hdev, u32 val)
5564e65e175bSOded Gabbay {
5565e65e175bSOded Gabbay WREG32(mmCPU_IF_EQ_RD_OFFS, val);
5566e65e175bSOded Gabbay }
5567e65e175bSOded Gabbay
gaudi_memset_device_memory(struct hl_device * hdev,u64 addr,u32 size,u64 val)5568e65e175bSOded Gabbay static int gaudi_memset_device_memory(struct hl_device *hdev, u64 addr,
5569e65e175bSOded Gabbay u32 size, u64 val)
5570*b207e166SOfir Bitton {
5571e65e175bSOded Gabbay struct packet_lin_dma *lin_dma_pkt;
5572e65e175bSOded Gabbay struct hl_cs_job *job;
5573e65e175bSOded Gabbay u32 cb_size, ctl, err_cause;
5574e65e175bSOded Gabbay struct hl_cb *cb;
5575e65e175bSOded Gabbay int rc;
5576e65e175bSOded Gabbay
5577e65e175bSOded Gabbay cb = hl_cb_kernel_create(hdev, PAGE_SIZE, false);
5578e65e175bSOded Gabbay if (!cb)
5579e65e175bSOded Gabbay return -EFAULT;
5580e65e175bSOded Gabbay
5581e65e175bSOded Gabbay lin_dma_pkt = cb->kernel_address;
5582e65e175bSOded Gabbay memset(lin_dma_pkt, 0, sizeof(*lin_dma_pkt));
5583e65e175bSOded Gabbay cb_size = sizeof(*lin_dma_pkt);
5584e65e175bSOded Gabbay
5585e65e175bSOded Gabbay ctl = FIELD_PREP(GAUDI_PKT_CTL_OPCODE_MASK, PACKET_LIN_DMA);
5586e65e175bSOded Gabbay ctl |= FIELD_PREP(GAUDI_PKT_LIN_DMA_CTL_MEMSET_MASK, 1);
5587e65e175bSOded Gabbay ctl |= FIELD_PREP(GAUDI_PKT_LIN_DMA_CTL_LIN_MASK, 1);
5588e65e175bSOded Gabbay ctl |= FIELD_PREP(GAUDI_PKT_CTL_MB_MASK, 1);
5589e65e175bSOded Gabbay ctl |= FIELD_PREP(GAUDI_PKT_CTL_RB_MASK, 1);
5590e65e175bSOded Gabbay
5591e65e175bSOded Gabbay lin_dma_pkt->ctl = cpu_to_le32(ctl);
5592e65e175bSOded Gabbay lin_dma_pkt->src_addr = cpu_to_le64(val);
5593e65e175bSOded Gabbay lin_dma_pkt->dst_addr |= cpu_to_le64(addr);
5594e65e175bSOded Gabbay lin_dma_pkt->tsize = cpu_to_le32(size);
5595e65e175bSOded Gabbay
5596e65e175bSOded Gabbay job = hl_cs_allocate_job(hdev, QUEUE_TYPE_EXT, true);
5597e65e175bSOded Gabbay if (!job) {
5598e65e175bSOded Gabbay dev_err(hdev->dev, "Failed to allocate a new job\n");
5599e65e175bSOded Gabbay rc = -ENOMEM;
5600e65e175bSOded Gabbay goto release_cb;
5601e65e175bSOded Gabbay }
5602e65e175bSOded Gabbay
5603e65e175bSOded Gabbay /* Verify DMA is OK */
5604e65e175bSOded Gabbay err_cause = RREG32(mmDMA0_CORE_ERR_CAUSE);
5605e65e175bSOded Gabbay if (err_cause && !hdev->init_done) {
5606e65e175bSOded Gabbay dev_dbg(hdev->dev,
5607e65e175bSOded Gabbay "Clearing DMA0 engine from errors (cause 0x%x)\n",
5608e65e175bSOded Gabbay err_cause);
5609e65e175bSOded Gabbay WREG32(mmDMA0_CORE_ERR_CAUSE, err_cause);
5610e65e175bSOded Gabbay }
5611e65e175bSOded Gabbay
5612e65e175bSOded Gabbay job->id = 0;
5613e65e175bSOded Gabbay job->user_cb = cb;
5614e65e175bSOded Gabbay atomic_inc(&job->user_cb->cs_cnt);
5615e65e175bSOded Gabbay job->user_cb_size = cb_size;
5616e65e175bSOded Gabbay job->hw_queue_id = GAUDI_QUEUE_ID_DMA_0_0;
5617e65e175bSOded Gabbay job->patched_cb = job->user_cb;
5618e65e175bSOded Gabbay job->job_cb_size = job->user_cb_size + sizeof(struct packet_msg_prot);
5619e65e175bSOded Gabbay
5620e65e175bSOded Gabbay hl_debugfs_add_job(hdev, job);
5621e65e175bSOded Gabbay
5622e65e175bSOded Gabbay rc = gaudi_send_job_on_qman0(hdev, job);
5623e65e175bSOded Gabbay hl_debugfs_remove_job(hdev, job);
5624e65e175bSOded Gabbay kfree(job);
5625e65e175bSOded Gabbay atomic_dec(&cb->cs_cnt);
5626e65e175bSOded Gabbay
5627e65e175bSOded Gabbay /* Verify DMA is OK */
5628e65e175bSOded Gabbay err_cause = RREG32(mmDMA0_CORE_ERR_CAUSE);
5629e65e175bSOded Gabbay if (err_cause) {
5630e65e175bSOded Gabbay dev_err(hdev->dev, "DMA Failed, cause 0x%x\n", err_cause);
5631e65e175bSOded Gabbay rc = -EIO;
5632e65e175bSOded Gabbay if (!hdev->init_done) {
5633e65e175bSOded Gabbay dev_dbg(hdev->dev,
5634e65e175bSOded Gabbay "Clearing DMA0 engine from errors (cause 0x%x)\n",
5635e65e175bSOded Gabbay err_cause);
5636e65e175bSOded Gabbay WREG32(mmDMA0_CORE_ERR_CAUSE, err_cause);
5637e65e175bSOded Gabbay }
5638e65e175bSOded Gabbay }
5639e65e175bSOded Gabbay
5640e65e175bSOded Gabbay release_cb:
5641e65e175bSOded Gabbay hl_cb_put(cb);
5642e65e175bSOded Gabbay hl_cb_destroy(&hdev->kernel_mem_mgr, cb->buf->handle);
5643e65e175bSOded Gabbay
5644e65e175bSOded Gabbay return rc;
5645e65e175bSOded Gabbay }
5646e65e175bSOded Gabbay
gaudi_memset_registers(struct hl_device * hdev,u64 reg_base,u32 num_regs,u32 val)5647e65e175bSOded Gabbay static int gaudi_memset_registers(struct hl_device *hdev, u64 reg_base,
5648e65e175bSOded Gabbay u32 num_regs, u32 val)
5649e65e175bSOded Gabbay {
5650e65e175bSOded Gabbay struct packet_msg_long *pkt;
5651e65e175bSOded Gabbay struct hl_cs_job *job;
5652e65e175bSOded Gabbay u32 cb_size, ctl;
5653e65e175bSOded Gabbay struct hl_cb *cb;
5654e65e175bSOded Gabbay int i, rc;
5655e65e175bSOded Gabbay
5656e65e175bSOded Gabbay cb_size = (sizeof(*pkt) * num_regs) + sizeof(struct packet_msg_prot);
5657e65e175bSOded Gabbay
5658e65e175bSOded Gabbay if (cb_size > SZ_2M) {
5659e65e175bSOded Gabbay dev_err(hdev->dev, "CB size must be smaller than %uMB", SZ_2M);
5660e65e175bSOded Gabbay return -ENOMEM;
5661e65e175bSOded Gabbay }
5662e65e175bSOded Gabbay
5663e65e175bSOded Gabbay cb = hl_cb_kernel_create(hdev, cb_size, false);
5664e65e175bSOded Gabbay if (!cb)
5665e65e175bSOded Gabbay return -EFAULT;
5666e65e175bSOded Gabbay
5667e65e175bSOded Gabbay pkt = cb->kernel_address;
5668e65e175bSOded Gabbay
5669e65e175bSOded Gabbay ctl = FIELD_PREP(GAUDI_PKT_LONG_CTL_OP_MASK, 0); /* write the value */
5670e65e175bSOded Gabbay ctl |= FIELD_PREP(GAUDI_PKT_CTL_OPCODE_MASK, PACKET_MSG_LONG);
5671e65e175bSOded Gabbay ctl |= FIELD_PREP(GAUDI_PKT_CTL_EB_MASK, 1);
5672e65e175bSOded Gabbay ctl |= FIELD_PREP(GAUDI_PKT_CTL_RB_MASK, 1);
5673e65e175bSOded Gabbay ctl |= FIELD_PREP(GAUDI_PKT_CTL_MB_MASK, 1);
5674e65e175bSOded Gabbay
5675e65e175bSOded Gabbay for (i = 0; i < num_regs ; i++, pkt++) {
5676e65e175bSOded Gabbay pkt->ctl = cpu_to_le32(ctl);
5677e65e175bSOded Gabbay pkt->value = cpu_to_le32(val);
5678e65e175bSOded Gabbay pkt->addr = cpu_to_le64(reg_base + (i * 4));
5679e65e175bSOded Gabbay }
5680e65e175bSOded Gabbay
5681e65e175bSOded Gabbay job = hl_cs_allocate_job(hdev, QUEUE_TYPE_EXT, true);
5682e65e175bSOded Gabbay if (!job) {
5683e65e175bSOded Gabbay dev_err(hdev->dev, "Failed to allocate a new job\n");
5684e65e175bSOded Gabbay rc = -ENOMEM;
5685e65e175bSOded Gabbay goto release_cb;
5686e65e175bSOded Gabbay }
5687e65e175bSOded Gabbay
5688e65e175bSOded Gabbay job->id = 0;
5689e65e175bSOded Gabbay job->user_cb = cb;
5690e65e175bSOded Gabbay atomic_inc(&job->user_cb->cs_cnt);
5691e65e175bSOded Gabbay job->user_cb_size = cb_size;
5692e65e175bSOded Gabbay job->hw_queue_id = GAUDI_QUEUE_ID_DMA_0_0;
5693e65e175bSOded Gabbay job->patched_cb = job->user_cb;
5694e65e175bSOded Gabbay job->job_cb_size = cb_size;
5695e65e175bSOded Gabbay
5696e65e175bSOded Gabbay hl_debugfs_add_job(hdev, job);
5697e65e175bSOded Gabbay
5698e65e175bSOded Gabbay rc = gaudi_send_job_on_qman0(hdev, job);
5699e65e175bSOded Gabbay hl_debugfs_remove_job(hdev, job);
5700e65e175bSOded Gabbay kfree(job);
5701e65e175bSOded Gabbay atomic_dec(&cb->cs_cnt);
5702e65e175bSOded Gabbay
5703e65e175bSOded Gabbay release_cb:
5704e65e175bSOded Gabbay hl_cb_put(cb);
5705e65e175bSOded Gabbay hl_cb_destroy(&hdev->kernel_mem_mgr, cb->buf->handle);
5706e65e175bSOded Gabbay
5707e65e175bSOded Gabbay return rc;
5708e65e175bSOded Gabbay }
5709e65e175bSOded Gabbay
gaudi_restore_sm_registers(struct hl_device * hdev)5710e65e175bSOded Gabbay static int gaudi_restore_sm_registers(struct hl_device *hdev)
5711e65e175bSOded Gabbay {
5712e65e175bSOded Gabbay u64 base_addr;
5713e65e175bSOded Gabbay u32 num_regs;
5714e65e175bSOded Gabbay int rc;
5715e65e175bSOded Gabbay
5716e65e175bSOded Gabbay base_addr = CFG_BASE + mmSYNC_MNGR_E_N_SYNC_MNGR_OBJS_SOB_OBJ_0;
5717e65e175bSOded Gabbay num_regs = NUM_OF_SOB_IN_BLOCK;
5718e65e175bSOded Gabbay rc = gaudi_memset_registers(hdev, base_addr, num_regs, 0);
5719e65e175bSOded Gabbay if (rc) {
5720e65e175bSOded Gabbay dev_err(hdev->dev, "failed resetting SM registers");
5721e65e175bSOded Gabbay return -ENOMEM;
5722e65e175bSOded Gabbay }
5723e65e175bSOded Gabbay
5724e65e175bSOded Gabbay base_addr = CFG_BASE + mmSYNC_MNGR_E_S_SYNC_MNGR_OBJS_SOB_OBJ_0;
5725e65e175bSOded Gabbay num_regs = NUM_OF_SOB_IN_BLOCK;
5726e65e175bSOded Gabbay rc = gaudi_memset_registers(hdev, base_addr, num_regs, 0);
5727e65e175bSOded Gabbay if (rc) {
5728e65e175bSOded Gabbay dev_err(hdev->dev, "failed resetting SM registers");
5729e65e175bSOded Gabbay return -ENOMEM;
5730e65e175bSOded Gabbay }
5731e65e175bSOded Gabbay
5732e65e175bSOded Gabbay base_addr = CFG_BASE + mmSYNC_MNGR_W_N_SYNC_MNGR_OBJS_SOB_OBJ_0;
5733e65e175bSOded Gabbay num_regs = NUM_OF_SOB_IN_BLOCK;
5734e65e175bSOded Gabbay rc = gaudi_memset_registers(hdev, base_addr, num_regs, 0);
5735e65e175bSOded Gabbay if (rc) {
5736e65e175bSOded Gabbay dev_err(hdev->dev, "failed resetting SM registers");
5737e65e175bSOded Gabbay return -ENOMEM;
5738e65e175bSOded Gabbay }
5739e65e175bSOded Gabbay
5740e65e175bSOded Gabbay base_addr = CFG_BASE + mmSYNC_MNGR_E_N_SYNC_MNGR_OBJS_MON_STATUS_0;
5741e65e175bSOded Gabbay num_regs = NUM_OF_MONITORS_IN_BLOCK;
5742e65e175bSOded Gabbay rc = gaudi_memset_registers(hdev, base_addr, num_regs, 0);
5743e65e175bSOded Gabbay if (rc) {
5744e65e175bSOded Gabbay dev_err(hdev->dev, "failed resetting SM registers");
5745e65e175bSOded Gabbay return -ENOMEM;
5746e65e175bSOded Gabbay }
5747e65e175bSOded Gabbay
5748e65e175bSOded Gabbay base_addr = CFG_BASE + mmSYNC_MNGR_E_S_SYNC_MNGR_OBJS_MON_STATUS_0;
5749e65e175bSOded Gabbay num_regs = NUM_OF_MONITORS_IN_BLOCK;
5750e65e175bSOded Gabbay rc = gaudi_memset_registers(hdev, base_addr, num_regs, 0);
5751e65e175bSOded Gabbay if (rc) {
5752e65e175bSOded Gabbay dev_err(hdev->dev, "failed resetting SM registers");
5753e65e175bSOded Gabbay return -ENOMEM;
5754e65e175bSOded Gabbay }
5755e65e175bSOded Gabbay
5756e65e175bSOded Gabbay base_addr = CFG_BASE + mmSYNC_MNGR_W_N_SYNC_MNGR_OBJS_MON_STATUS_0;
5757e65e175bSOded Gabbay num_regs = NUM_OF_MONITORS_IN_BLOCK;
5758e65e175bSOded Gabbay rc = gaudi_memset_registers(hdev, base_addr, num_regs, 0);
5759e65e175bSOded Gabbay if (rc) {
5760e65e175bSOded Gabbay dev_err(hdev->dev, "failed resetting SM registers");
5761e65e175bSOded Gabbay return -ENOMEM;
5762e65e175bSOded Gabbay }
5763e65e175bSOded Gabbay
5764e65e175bSOded Gabbay base_addr = CFG_BASE + mmSYNC_MNGR_W_S_SYNC_MNGR_OBJS_SOB_OBJ_0 +
5765e65e175bSOded Gabbay (GAUDI_FIRST_AVAILABLE_W_S_SYNC_OBJECT * 4);
5766e65e175bSOded Gabbay num_regs = NUM_OF_SOB_IN_BLOCK - GAUDI_FIRST_AVAILABLE_W_S_SYNC_OBJECT;
5767e65e175bSOded Gabbay rc = gaudi_memset_registers(hdev, base_addr, num_regs, 0);
5768e65e175bSOded Gabbay if (rc) {
5769e65e175bSOded Gabbay dev_err(hdev->dev, "failed resetting SM registers");
5770e65e175bSOded Gabbay return -ENOMEM;
5771e65e175bSOded Gabbay }
5772e65e175bSOded Gabbay
5773e65e175bSOded Gabbay base_addr = CFG_BASE + mmSYNC_MNGR_W_S_SYNC_MNGR_OBJS_MON_STATUS_0 +
5774e65e175bSOded Gabbay (GAUDI_FIRST_AVAILABLE_W_S_MONITOR * 4);
5775e65e175bSOded Gabbay num_regs = NUM_OF_MONITORS_IN_BLOCK - GAUDI_FIRST_AVAILABLE_W_S_MONITOR;
5776e65e175bSOded Gabbay rc = gaudi_memset_registers(hdev, base_addr, num_regs, 0);
5777e65e175bSOded Gabbay if (rc) {
5778e65e175bSOded Gabbay dev_err(hdev->dev, "failed resetting SM registers");
5779e65e175bSOded Gabbay return -ENOMEM;
5780e65e175bSOded Gabbay }
5781e65e175bSOded Gabbay
5782e65e175bSOded Gabbay return 0;
5783e65e175bSOded Gabbay }
5784e65e175bSOded Gabbay
gaudi_restore_dma_registers(struct hl_device * hdev)5785e65e175bSOded Gabbay static void gaudi_restore_dma_registers(struct hl_device *hdev)
5786e65e175bSOded Gabbay {
5787e65e175bSOded Gabbay u32 sob_delta = mmSYNC_MNGR_E_N_SYNC_MNGR_OBJS_SOB_OBJ_1 -
5788e65e175bSOded Gabbay mmSYNC_MNGR_E_N_SYNC_MNGR_OBJS_SOB_OBJ_0;
5789e65e175bSOded Gabbay int i;
5790e65e175bSOded Gabbay
5791e65e175bSOded Gabbay for (i = 0 ; i < DMA_NUMBER_OF_CHANNELS ; i++) {
5792e65e175bSOded Gabbay u64 sob_addr = CFG_BASE +
5793e65e175bSOded Gabbay mmSYNC_MNGR_E_N_SYNC_MNGR_OBJS_SOB_OBJ_0 +
5794e65e175bSOded Gabbay (i * sob_delta);
5795e65e175bSOded Gabbay u32 dma_offset = i * DMA_CORE_OFFSET;
5796e65e175bSOded Gabbay
5797e65e175bSOded Gabbay WREG32(mmDMA0_CORE_WR_COMP_ADDR_LO + dma_offset,
5798e65e175bSOded Gabbay lower_32_bits(sob_addr));
5799e65e175bSOded Gabbay WREG32(mmDMA0_CORE_WR_COMP_ADDR_HI + dma_offset,
5800e65e175bSOded Gabbay upper_32_bits(sob_addr));
5801e65e175bSOded Gabbay WREG32(mmDMA0_CORE_WR_COMP_WDATA + dma_offset, 0x80000001);
5802e65e175bSOded Gabbay
5803e65e175bSOded Gabbay /* For DMAs 2-7, need to restore WR_AWUSER_31_11 as it can be
5804e65e175bSOded Gabbay * modified by the user for SRAM reduction
5805e65e175bSOded Gabbay */
5806e65e175bSOded Gabbay if (i > 1)
5807e65e175bSOded Gabbay WREG32(mmDMA0_CORE_WR_AWUSER_31_11 + dma_offset,
5808e65e175bSOded Gabbay 0x00000001);
5809e65e175bSOded Gabbay }
5810e65e175bSOded Gabbay }
5811e65e175bSOded Gabbay
gaudi_restore_qm_registers(struct hl_device * hdev)5812e65e175bSOded Gabbay static void gaudi_restore_qm_registers(struct hl_device *hdev)
5813e65e175bSOded Gabbay {
5814e65e175bSOded Gabbay u32 qman_offset;
5815e65e175bSOded Gabbay int i;
5816e65e175bSOded Gabbay
5817e65e175bSOded Gabbay for (i = 0 ; i < DMA_NUMBER_OF_CHANNELS ; i++) {
5818e65e175bSOded Gabbay qman_offset = i * DMA_QMAN_OFFSET;
5819e65e175bSOded Gabbay WREG32(mmDMA0_QM_ARB_CFG_0 + qman_offset, 0);
5820e65e175bSOded Gabbay }
5821e65e175bSOded Gabbay
5822e65e175bSOded Gabbay for (i = 0 ; i < MME_NUMBER_OF_MASTER_ENGINES ; i++) {
5823e65e175bSOded Gabbay qman_offset = i * (mmMME2_QM_BASE - mmMME0_QM_BASE);
5824e65e175bSOded Gabbay WREG32(mmMME0_QM_ARB_CFG_0 + qman_offset, 0);
5825e65e175bSOded Gabbay }
5826e65e175bSOded Gabbay
5827e65e175bSOded Gabbay for (i = 0 ; i < TPC_NUMBER_OF_ENGINES ; i++) {
5828e65e175bSOded Gabbay qman_offset = i * TPC_QMAN_OFFSET;
5829e65e175bSOded Gabbay WREG32(mmTPC0_QM_ARB_CFG_0 + qman_offset, 0);
5830e65e175bSOded Gabbay }
5831e65e175bSOded Gabbay
5832e65e175bSOded Gabbay for (i = 0 ; i < NIC_NUMBER_OF_ENGINES ; i++) {
5833e65e175bSOded Gabbay qman_offset = (i >> 1) * NIC_MACRO_QMAN_OFFSET +
5834e65e175bSOded Gabbay (i & 0x1) * NIC_ENGINE_QMAN_OFFSET;
5835e65e175bSOded Gabbay WREG32(mmNIC0_QM0_ARB_CFG_0 + qman_offset, 0);
5836e65e175bSOded Gabbay }
5837e65e175bSOded Gabbay }
5838e65e175bSOded Gabbay
gaudi_restore_user_registers(struct hl_device * hdev)5839e65e175bSOded Gabbay static int gaudi_restore_user_registers(struct hl_device *hdev)
5840e65e175bSOded Gabbay {
5841e65e175bSOded Gabbay int rc;
5842e65e175bSOded Gabbay
5843e65e175bSOded Gabbay rc = gaudi_restore_sm_registers(hdev);
5844e65e175bSOded Gabbay if (rc)
5845e65e175bSOded Gabbay return rc;
5846e65e175bSOded Gabbay
5847e65e175bSOded Gabbay gaudi_restore_dma_registers(hdev);
5848e65e175bSOded Gabbay gaudi_restore_qm_registers(hdev);
5849e65e175bSOded Gabbay
5850e65e175bSOded Gabbay return 0;
5851e65e175bSOded Gabbay }
5852e65e175bSOded Gabbay
gaudi_context_switch(struct hl_device * hdev,u32 asid)5853e65e175bSOded Gabbay static int gaudi_context_switch(struct hl_device *hdev, u32 asid)
5854e65e175bSOded Gabbay {
5855e65e175bSOded Gabbay return 0;
5856e65e175bSOded Gabbay }
5857e65e175bSOded Gabbay
gaudi_mmu_clear_pgt_range(struct hl_device * hdev)5858e65e175bSOded Gabbay static int gaudi_mmu_clear_pgt_range(struct hl_device *hdev)
5859e65e175bSOded Gabbay {
5860e65e175bSOded Gabbay u32 size = hdev->asic_prop.mmu_pgt_size +
5861e65e175bSOded Gabbay hdev->asic_prop.mmu_cache_mng_size;
5862e65e175bSOded Gabbay struct gaudi_device *gaudi = hdev->asic_specific;
5863e65e175bSOded Gabbay u64 addr = hdev->asic_prop.mmu_pgt_addr;
5864e65e175bSOded Gabbay
5865e65e175bSOded Gabbay if (!(gaudi->hw_cap_initialized & HW_CAP_MMU))
5866e65e175bSOded Gabbay return 0;
5867e65e175bSOded Gabbay
5868e65e175bSOded Gabbay return gaudi_memset_device_memory(hdev, addr, size, 0);
5869e65e175bSOded Gabbay }
5870e65e175bSOded Gabbay
gaudi_restore_phase_topology(struct hl_device * hdev)5871e65e175bSOded Gabbay static void gaudi_restore_phase_topology(struct hl_device *hdev)
5872e65e175bSOded Gabbay {
5873e65e175bSOded Gabbay
5874e65e175bSOded Gabbay }
5875e65e175bSOded Gabbay
gaudi_dma_core_transfer(struct hl_device * hdev,int dma_id,u64 addr,u32 size_to_dma,dma_addr_t dma_addr)5876e65e175bSOded Gabbay static int gaudi_dma_core_transfer(struct hl_device *hdev, int dma_id, u64 addr,
5877e65e175bSOded Gabbay u32 size_to_dma, dma_addr_t dma_addr)
5878e65e175bSOded Gabbay {
5879e65e175bSOded Gabbay u32 err_cause, val;
5880e65e175bSOded Gabbay u64 dma_offset;
5881e65e175bSOded Gabbay int rc;
5882e65e175bSOded Gabbay
5883e65e175bSOded Gabbay dma_offset = dma_id * DMA_CORE_OFFSET;
5884e65e175bSOded Gabbay
5885e65e175bSOded Gabbay WREG32(mmDMA0_CORE_SRC_BASE_LO + dma_offset, lower_32_bits(addr));
5886e65e175bSOded Gabbay WREG32(mmDMA0_CORE_SRC_BASE_HI + dma_offset, upper_32_bits(addr));
5887e65e175bSOded Gabbay WREG32(mmDMA0_CORE_DST_BASE_LO + dma_offset, lower_32_bits(dma_addr));
5888e65e175bSOded Gabbay WREG32(mmDMA0_CORE_DST_BASE_HI + dma_offset, upper_32_bits(dma_addr));
5889e65e175bSOded Gabbay WREG32(mmDMA0_CORE_DST_TSIZE_0 + dma_offset, size_to_dma);
5890e65e175bSOded Gabbay WREG32(mmDMA0_CORE_COMMIT + dma_offset,
5891e65e175bSOded Gabbay (1 << DMA0_CORE_COMMIT_LIN_SHIFT));
5892e65e175bSOded Gabbay
5893e65e175bSOded Gabbay rc = hl_poll_timeout(
5894e65e175bSOded Gabbay hdev,
5895e65e175bSOded Gabbay mmDMA0_CORE_STS0 + dma_offset,
5896e65e175bSOded Gabbay val,
5897e65e175bSOded Gabbay ((val & DMA0_CORE_STS0_BUSY_MASK) == 0),
5898e65e175bSOded Gabbay 0,
5899e65e175bSOded Gabbay 1000000);
5900e65e175bSOded Gabbay
5901e65e175bSOded Gabbay if (rc) {
5902e65e175bSOded Gabbay dev_err(hdev->dev,
5903e65e175bSOded Gabbay "DMA %d timed-out during reading of 0x%llx\n",
5904e65e175bSOded Gabbay dma_id, addr);
5905e65e175bSOded Gabbay return -EIO;
5906e65e175bSOded Gabbay }
5907e65e175bSOded Gabbay
5908e65e175bSOded Gabbay /* Verify DMA is OK */
5909e65e175bSOded Gabbay err_cause = RREG32(mmDMA0_CORE_ERR_CAUSE + dma_offset);
5910e65e175bSOded Gabbay if (err_cause) {
5911e65e175bSOded Gabbay dev_err(hdev->dev, "DMA Failed, cause 0x%x\n", err_cause);
5912e65e175bSOded Gabbay dev_dbg(hdev->dev,
5913e65e175bSOded Gabbay "Clearing DMA0 engine from errors (cause 0x%x)\n",
5914e65e175bSOded Gabbay err_cause);
5915e65e175bSOded Gabbay WREG32(mmDMA0_CORE_ERR_CAUSE + dma_offset, err_cause);
5916e65e175bSOded Gabbay
5917e65e175bSOded Gabbay return -EIO;
5918e65e175bSOded Gabbay }
5919e65e175bSOded Gabbay
5920e65e175bSOded Gabbay return 0;
5921e65e175bSOded Gabbay }
5922e65e175bSOded Gabbay
gaudi_debugfs_read_dma(struct hl_device * hdev,u64 addr,u32 size,void * blob_addr)5923e65e175bSOded Gabbay static int gaudi_debugfs_read_dma(struct hl_device *hdev, u64 addr, u32 size,
5924e65e175bSOded Gabbay void *blob_addr)
5925e65e175bSOded Gabbay {
5926e65e175bSOded Gabbay u32 dma_core_sts0, err_cause, cfg1, size_left, pos, size_to_dma;
5927e65e175bSOded Gabbay u32 qm_glbl_sts0, qm_cgm_sts;
5928e65e175bSOded Gabbay u64 dma_offset, qm_offset;
5929e65e175bSOded Gabbay dma_addr_t dma_addr;
5930e65e175bSOded Gabbay void *kernel_addr;
5931e65e175bSOded Gabbay bool is_eng_idle;
5932e65e175bSOded Gabbay int rc = 0, dma_id;
5933e65e175bSOded Gabbay
5934e65e175bSOded Gabbay kernel_addr = hl_asic_dma_alloc_coherent(hdev, SZ_2M, &dma_addr, GFP_KERNEL | __GFP_ZERO);
5935e65e175bSOded Gabbay
5936e65e175bSOded Gabbay if (!kernel_addr)
5937e65e175bSOded Gabbay return -ENOMEM;
5938e65e175bSOded Gabbay
5939e65e175bSOded Gabbay hdev->asic_funcs->hw_queues_lock(hdev);
5940e65e175bSOded Gabbay
5941e65e175bSOded Gabbay dma_id = gaudi_dma_assignment[GAUDI_PCI_DMA_1];
5942e65e175bSOded Gabbay dma_offset = dma_id * DMA_CORE_OFFSET;
5943e65e175bSOded Gabbay qm_offset = dma_id * DMA_QMAN_OFFSET;
5944e65e175bSOded Gabbay dma_core_sts0 = RREG32(mmDMA0_CORE_STS0 + dma_offset);
5945e65e175bSOded Gabbay qm_glbl_sts0 = RREG32(mmDMA0_QM_GLBL_STS0 + qm_offset);
5946e65e175bSOded Gabbay qm_cgm_sts = RREG32(mmDMA0_QM_CGM_STS + qm_offset);
5947e65e175bSOded Gabbay is_eng_idle = IS_QM_IDLE(qm_glbl_sts0, qm_cgm_sts) &&
5948e65e175bSOded Gabbay IS_DMA_IDLE(dma_core_sts0);
5949e65e175bSOded Gabbay
5950e65e175bSOded Gabbay if (!is_eng_idle) {
5951e65e175bSOded Gabbay dma_id = gaudi_dma_assignment[GAUDI_PCI_DMA_2];
5952e65e175bSOded Gabbay dma_offset = dma_id * DMA_CORE_OFFSET;
5953e65e175bSOded Gabbay qm_offset = dma_id * DMA_QMAN_OFFSET;
5954e65e175bSOded Gabbay dma_core_sts0 = RREG32(mmDMA0_CORE_STS0 + dma_offset);
5955e65e175bSOded Gabbay qm_glbl_sts0 = RREG32(mmDMA0_QM_GLBL_STS0 + qm_offset);
5956e65e175bSOded Gabbay qm_cgm_sts = RREG32(mmDMA0_QM_CGM_STS + qm_offset);
5957e65e175bSOded Gabbay is_eng_idle = IS_QM_IDLE(qm_glbl_sts0, qm_cgm_sts) &&
5958e65e175bSOded Gabbay IS_DMA_IDLE(dma_core_sts0);
5959e65e175bSOded Gabbay
5960e65e175bSOded Gabbay if (!is_eng_idle) {
5961e65e175bSOded Gabbay dev_err_ratelimited(hdev->dev,
5962e65e175bSOded Gabbay "Can't read via DMA because it is BUSY\n");
5963e65e175bSOded Gabbay rc = -EAGAIN;
5964e65e175bSOded Gabbay goto out;
5965e65e175bSOded Gabbay }
5966e65e175bSOded Gabbay }
5967e65e175bSOded Gabbay
5968e65e175bSOded Gabbay cfg1 = RREG32(mmDMA0_QM_GLBL_CFG1 + qm_offset);
5969e65e175bSOded Gabbay WREG32(mmDMA0_QM_GLBL_CFG1 + qm_offset,
5970e65e175bSOded Gabbay 0xF << DMA0_QM_GLBL_CFG1_CP_STOP_SHIFT);
5971e65e175bSOded Gabbay
5972e65e175bSOded Gabbay /* TODO: remove this by mapping the DMA temporary buffer to the MMU
5973e65e175bSOded Gabbay * using the compute ctx ASID, if exists. If not, use the kernel ctx
5974e65e175bSOded Gabbay * ASID
5975e65e175bSOded Gabbay */
5976e65e175bSOded Gabbay WREG32_OR(mmDMA0_CORE_PROT + dma_offset, BIT(DMA0_CORE_PROT_VAL_SHIFT));
5977e65e175bSOded Gabbay
5978e65e175bSOded Gabbay /* Verify DMA is OK */
5979e65e175bSOded Gabbay err_cause = RREG32(mmDMA0_CORE_ERR_CAUSE + dma_offset);
5980e65e175bSOded Gabbay if (err_cause) {
5981e65e175bSOded Gabbay dev_dbg(hdev->dev,
5982e65e175bSOded Gabbay "Clearing DMA0 engine from errors (cause 0x%x)\n",
5983e65e175bSOded Gabbay err_cause);
5984e65e175bSOded Gabbay WREG32(mmDMA0_CORE_ERR_CAUSE + dma_offset, err_cause);
5985e65e175bSOded Gabbay }
5986e65e175bSOded Gabbay
5987e65e175bSOded Gabbay pos = 0;
5988e65e175bSOded Gabbay size_left = size;
5989e65e175bSOded Gabbay size_to_dma = SZ_2M;
5990e65e175bSOded Gabbay
5991e65e175bSOded Gabbay while (size_left > 0) {
5992e65e175bSOded Gabbay
5993e65e175bSOded Gabbay if (size_left < SZ_2M)
5994e65e175bSOded Gabbay size_to_dma = size_left;
5995e65e175bSOded Gabbay
5996e65e175bSOded Gabbay rc = gaudi_dma_core_transfer(hdev, dma_id, addr, size_to_dma,
5997e65e175bSOded Gabbay dma_addr);
5998e65e175bSOded Gabbay if (rc)
5999e65e175bSOded Gabbay break;
6000e65e175bSOded Gabbay
6001e65e175bSOded Gabbay memcpy(blob_addr + pos, kernel_addr, size_to_dma);
6002e65e175bSOded Gabbay
6003e65e175bSOded Gabbay if (size_left <= SZ_2M)
6004e65e175bSOded Gabbay break;
6005e65e175bSOded Gabbay
6006e65e175bSOded Gabbay pos += SZ_2M;
6007e65e175bSOded Gabbay addr += SZ_2M;
6008e65e175bSOded Gabbay size_left -= SZ_2M;
6009e65e175bSOded Gabbay }
6010e65e175bSOded Gabbay
6011e65e175bSOded Gabbay /* TODO: remove this by mapping the DMA temporary buffer to the MMU
6012e65e175bSOded Gabbay * using the compute ctx ASID, if exists. If not, use the kernel ctx
6013e65e175bSOded Gabbay * ASID
6014e65e175bSOded Gabbay */
6015e65e175bSOded Gabbay WREG32_AND(mmDMA0_CORE_PROT + dma_offset,
6016e65e175bSOded Gabbay ~BIT(DMA0_CORE_PROT_VAL_SHIFT));
6017e65e175bSOded Gabbay
6018e65e175bSOded Gabbay WREG32(mmDMA0_QM_GLBL_CFG1 + qm_offset, cfg1);
6019e65e175bSOded Gabbay
6020e65e175bSOded Gabbay out:
6021e65e175bSOded Gabbay hdev->asic_funcs->hw_queues_unlock(hdev);
6022e65e175bSOded Gabbay
6023e65e175bSOded Gabbay hl_asic_dma_free_coherent(hdev, SZ_2M, kernel_addr, dma_addr);
6024e65e175bSOded Gabbay
6025e65e175bSOded Gabbay return rc;
6026e65e175bSOded Gabbay }
6027e65e175bSOded Gabbay
gaudi_read_pte(struct hl_device * hdev,u64 addr)6028e65e175bSOded Gabbay static u64 gaudi_read_pte(struct hl_device *hdev, u64 addr)
6029e65e175bSOded Gabbay {
6030e65e175bSOded Gabbay struct gaudi_device *gaudi = hdev->asic_specific;
6031e65e175bSOded Gabbay
6032e65e175bSOded Gabbay if (hdev->reset_info.hard_reset_pending)
6033e65e175bSOded Gabbay return U64_MAX;
6034e65e175bSOded Gabbay
6035e65e175bSOded Gabbay return readq(hdev->pcie_bar[HBM_BAR_ID] +
6036e65e175bSOded Gabbay (addr - gaudi->hbm_bar_cur_addr));
6037e65e175bSOded Gabbay }
6038e65e175bSOded Gabbay
gaudi_write_pte(struct hl_device * hdev,u64 addr,u64 val)6039e65e175bSOded Gabbay static void gaudi_write_pte(struct hl_device *hdev, u64 addr, u64 val)
6040e65e175bSOded Gabbay {
6041e65e175bSOded Gabbay struct gaudi_device *gaudi = hdev->asic_specific;
6042e65e175bSOded Gabbay
6043e65e175bSOded Gabbay if (hdev->reset_info.hard_reset_pending)
6044e65e175bSOded Gabbay return;
6045e65e175bSOded Gabbay
6046e65e175bSOded Gabbay writeq(val, hdev->pcie_bar[HBM_BAR_ID] +
6047e65e175bSOded Gabbay (addr - gaudi->hbm_bar_cur_addr));
6048e65e175bSOded Gabbay }
6049e65e175bSOded Gabbay
gaudi_mmu_prepare_reg(struct hl_device * hdev,u64 reg,u32 asid)6050e65e175bSOded Gabbay void gaudi_mmu_prepare_reg(struct hl_device *hdev, u64 reg, u32 asid)
6051e65e175bSOded Gabbay {
6052e65e175bSOded Gabbay /* mask to zero the MMBP and ASID bits */
6053e65e175bSOded Gabbay WREG32_AND(reg, ~0x7FF);
6054e65e175bSOded Gabbay WREG32_OR(reg, asid);
6055e65e175bSOded Gabbay }
6056e65e175bSOded Gabbay
gaudi_mmu_prepare(struct hl_device * hdev,u32 asid)6057e65e175bSOded Gabbay static void gaudi_mmu_prepare(struct hl_device *hdev, u32 asid)
6058e65e175bSOded Gabbay {
6059e65e175bSOded Gabbay struct gaudi_device *gaudi = hdev->asic_specific;
6060e65e175bSOded Gabbay
6061e65e175bSOded Gabbay if (!(gaudi->hw_cap_initialized & HW_CAP_MMU))
6062e65e175bSOded Gabbay return;
6063e65e175bSOded Gabbay
6064e65e175bSOded Gabbay if (asid & ~DMA0_QM_GLBL_NON_SECURE_PROPS_0_ASID_MASK) {
6065e65e175bSOded Gabbay dev_crit(hdev->dev, "asid %u is too big\n", asid);
6066e65e175bSOded Gabbay return;
6067e65e175bSOded Gabbay }
6068e65e175bSOded Gabbay
6069e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmDMA0_QM_GLBL_NON_SECURE_PROPS_0, asid);
6070e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmDMA0_QM_GLBL_NON_SECURE_PROPS_1, asid);
6071e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmDMA0_QM_GLBL_NON_SECURE_PROPS_2, asid);
6072e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmDMA0_QM_GLBL_NON_SECURE_PROPS_3, asid);
6073e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmDMA0_QM_GLBL_NON_SECURE_PROPS_4, asid);
6074e65e175bSOded Gabbay
6075e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmDMA1_QM_GLBL_NON_SECURE_PROPS_0, asid);
6076e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmDMA1_QM_GLBL_NON_SECURE_PROPS_1, asid);
6077e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmDMA1_QM_GLBL_NON_SECURE_PROPS_2, asid);
6078e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmDMA1_QM_GLBL_NON_SECURE_PROPS_3, asid);
6079e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmDMA1_QM_GLBL_NON_SECURE_PROPS_4, asid);
6080e65e175bSOded Gabbay
6081e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmDMA2_QM_GLBL_NON_SECURE_PROPS_0, asid);
6082e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmDMA2_QM_GLBL_NON_SECURE_PROPS_1, asid);
6083e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmDMA2_QM_GLBL_NON_SECURE_PROPS_2, asid);
6084e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmDMA2_QM_GLBL_NON_SECURE_PROPS_3, asid);
6085e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmDMA2_QM_GLBL_NON_SECURE_PROPS_4, asid);
6086e65e175bSOded Gabbay
6087e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmDMA3_QM_GLBL_NON_SECURE_PROPS_0, asid);
6088e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmDMA3_QM_GLBL_NON_SECURE_PROPS_1, asid);
6089e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmDMA3_QM_GLBL_NON_SECURE_PROPS_2, asid);
6090e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmDMA3_QM_GLBL_NON_SECURE_PROPS_3, asid);
6091e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmDMA3_QM_GLBL_NON_SECURE_PROPS_4, asid);
6092e65e175bSOded Gabbay
6093e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmDMA4_QM_GLBL_NON_SECURE_PROPS_0, asid);
6094e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmDMA4_QM_GLBL_NON_SECURE_PROPS_1, asid);
6095e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmDMA4_QM_GLBL_NON_SECURE_PROPS_2, asid);
6096e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmDMA4_QM_GLBL_NON_SECURE_PROPS_3, asid);
6097e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmDMA4_QM_GLBL_NON_SECURE_PROPS_4, asid);
6098e65e175bSOded Gabbay
6099e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmDMA5_QM_GLBL_NON_SECURE_PROPS_0, asid);
6100e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmDMA5_QM_GLBL_NON_SECURE_PROPS_1, asid);
6101e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmDMA5_QM_GLBL_NON_SECURE_PROPS_2, asid);
6102e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmDMA5_QM_GLBL_NON_SECURE_PROPS_3, asid);
6103e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmDMA5_QM_GLBL_NON_SECURE_PROPS_4, asid);
6104e65e175bSOded Gabbay
6105e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmDMA6_QM_GLBL_NON_SECURE_PROPS_0, asid);
6106e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmDMA6_QM_GLBL_NON_SECURE_PROPS_1, asid);
6107e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmDMA6_QM_GLBL_NON_SECURE_PROPS_2, asid);
6108e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmDMA6_QM_GLBL_NON_SECURE_PROPS_3, asid);
6109e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmDMA6_QM_GLBL_NON_SECURE_PROPS_4, asid);
6110e65e175bSOded Gabbay
6111e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmDMA7_QM_GLBL_NON_SECURE_PROPS_0, asid);
6112e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmDMA7_QM_GLBL_NON_SECURE_PROPS_1, asid);
6113e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmDMA7_QM_GLBL_NON_SECURE_PROPS_2, asid);
6114e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmDMA7_QM_GLBL_NON_SECURE_PROPS_3, asid);
6115e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmDMA7_QM_GLBL_NON_SECURE_PROPS_4, asid);
6116e65e175bSOded Gabbay
6117e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmDMA0_CORE_NON_SECURE_PROPS, asid);
6118e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmDMA1_CORE_NON_SECURE_PROPS, asid);
6119e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmDMA2_CORE_NON_SECURE_PROPS, asid);
6120e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmDMA3_CORE_NON_SECURE_PROPS, asid);
6121e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmDMA4_CORE_NON_SECURE_PROPS, asid);
6122e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmDMA5_CORE_NON_SECURE_PROPS, asid);
6123e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmDMA6_CORE_NON_SECURE_PROPS, asid);
6124e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmDMA7_CORE_NON_SECURE_PROPS, asid);
6125e65e175bSOded Gabbay
6126e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmTPC0_QM_GLBL_NON_SECURE_PROPS_0, asid);
6127e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmTPC0_QM_GLBL_NON_SECURE_PROPS_1, asid);
6128e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmTPC0_QM_GLBL_NON_SECURE_PROPS_2, asid);
6129e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmTPC0_QM_GLBL_NON_SECURE_PROPS_3, asid);
6130e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmTPC0_QM_GLBL_NON_SECURE_PROPS_4, asid);
6131e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmTPC0_CFG_ARUSER_LO, asid);
6132e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmTPC0_CFG_AWUSER_LO, asid);
6133e65e175bSOded Gabbay
6134e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmTPC1_QM_GLBL_NON_SECURE_PROPS_0, asid);
6135e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmTPC1_QM_GLBL_NON_SECURE_PROPS_1, asid);
6136e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmTPC1_QM_GLBL_NON_SECURE_PROPS_2, asid);
6137e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmTPC1_QM_GLBL_NON_SECURE_PROPS_3, asid);
6138e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmTPC1_QM_GLBL_NON_SECURE_PROPS_4, asid);
6139e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmTPC1_CFG_ARUSER_LO, asid);
6140e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmTPC1_CFG_AWUSER_LO, asid);
6141e65e175bSOded Gabbay
6142e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmTPC2_QM_GLBL_NON_SECURE_PROPS_0, asid);
6143e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmTPC2_QM_GLBL_NON_SECURE_PROPS_1, asid);
6144e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmTPC2_QM_GLBL_NON_SECURE_PROPS_2, asid);
6145e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmTPC2_QM_GLBL_NON_SECURE_PROPS_3, asid);
6146e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmTPC2_QM_GLBL_NON_SECURE_PROPS_4, asid);
6147e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmTPC2_CFG_ARUSER_LO, asid);
6148e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmTPC2_CFG_AWUSER_LO, asid);
6149e65e175bSOded Gabbay
6150e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmTPC3_QM_GLBL_NON_SECURE_PROPS_0, asid);
6151e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmTPC3_QM_GLBL_NON_SECURE_PROPS_1, asid);
6152e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmTPC3_QM_GLBL_NON_SECURE_PROPS_2, asid);
6153e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmTPC3_QM_GLBL_NON_SECURE_PROPS_3, asid);
6154e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmTPC3_QM_GLBL_NON_SECURE_PROPS_4, asid);
6155e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmTPC3_CFG_ARUSER_LO, asid);
6156e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmTPC3_CFG_AWUSER_LO, asid);
6157e65e175bSOded Gabbay
6158e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmTPC4_QM_GLBL_NON_SECURE_PROPS_0, asid);
6159e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmTPC4_QM_GLBL_NON_SECURE_PROPS_1, asid);
6160e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmTPC4_QM_GLBL_NON_SECURE_PROPS_2, asid);
6161e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmTPC4_QM_GLBL_NON_SECURE_PROPS_3, asid);
6162e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmTPC4_QM_GLBL_NON_SECURE_PROPS_4, asid);
6163e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmTPC4_CFG_ARUSER_LO, asid);
6164e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmTPC4_CFG_AWUSER_LO, asid);
6165e65e175bSOded Gabbay
6166e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmTPC5_QM_GLBL_NON_SECURE_PROPS_0, asid);
6167e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmTPC5_QM_GLBL_NON_SECURE_PROPS_1, asid);
6168e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmTPC5_QM_GLBL_NON_SECURE_PROPS_2, asid);
6169e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmTPC5_QM_GLBL_NON_SECURE_PROPS_3, asid);
6170e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmTPC5_QM_GLBL_NON_SECURE_PROPS_4, asid);
6171e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmTPC5_CFG_ARUSER_LO, asid);
6172e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmTPC5_CFG_AWUSER_LO, asid);
6173e65e175bSOded Gabbay
6174e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmTPC6_QM_GLBL_NON_SECURE_PROPS_0, asid);
6175e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmTPC6_QM_GLBL_NON_SECURE_PROPS_1, asid);
6176e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmTPC6_QM_GLBL_NON_SECURE_PROPS_2, asid);
6177e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmTPC6_QM_GLBL_NON_SECURE_PROPS_3, asid);
6178e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmTPC6_QM_GLBL_NON_SECURE_PROPS_4, asid);
6179e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmTPC6_CFG_ARUSER_LO, asid);
6180e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmTPC6_CFG_AWUSER_LO, asid);
6181e65e175bSOded Gabbay
6182e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmTPC7_QM_GLBL_NON_SECURE_PROPS_0, asid);
6183e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmTPC7_QM_GLBL_NON_SECURE_PROPS_1, asid);
6184e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmTPC7_QM_GLBL_NON_SECURE_PROPS_2, asid);
6185e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmTPC7_QM_GLBL_NON_SECURE_PROPS_3, asid);
6186e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmTPC7_QM_GLBL_NON_SECURE_PROPS_4, asid);
6187e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmTPC7_CFG_ARUSER_LO, asid);
6188e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmTPC7_CFG_AWUSER_LO, asid);
6189e65e175bSOded Gabbay
6190e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmMME0_QM_GLBL_NON_SECURE_PROPS_0, asid);
6191e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmMME0_QM_GLBL_NON_SECURE_PROPS_1, asid);
6192e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmMME0_QM_GLBL_NON_SECURE_PROPS_2, asid);
6193e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmMME0_QM_GLBL_NON_SECURE_PROPS_3, asid);
6194e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmMME0_QM_GLBL_NON_SECURE_PROPS_4, asid);
6195e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmMME2_QM_GLBL_NON_SECURE_PROPS_0, asid);
6196e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmMME2_QM_GLBL_NON_SECURE_PROPS_1, asid);
6197e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmMME2_QM_GLBL_NON_SECURE_PROPS_2, asid);
6198e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmMME2_QM_GLBL_NON_SECURE_PROPS_3, asid);
6199e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmMME2_QM_GLBL_NON_SECURE_PROPS_4, asid);
6200e65e175bSOded Gabbay
6201e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmMME0_SBAB_ARUSER0, asid);
6202e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmMME0_SBAB_ARUSER1, asid);
6203e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmMME1_SBAB_ARUSER0, asid);
6204e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmMME1_SBAB_ARUSER1, asid);
6205e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmMME2_SBAB_ARUSER0, asid);
6206e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmMME2_SBAB_ARUSER1, asid);
6207e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmMME3_SBAB_ARUSER0, asid);
6208e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmMME3_SBAB_ARUSER1, asid);
6209e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmMME0_ACC_WBC, asid);
6210e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmMME1_ACC_WBC, asid);
6211e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmMME2_ACC_WBC, asid);
6212e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmMME3_ACC_WBC, asid);
6213e65e175bSOded Gabbay
6214e65e175bSOded Gabbay if (gaudi->hw_cap_initialized & HW_CAP_NIC0) {
6215e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmNIC0_QM0_GLBL_NON_SECURE_PROPS_0,
6216e65e175bSOded Gabbay asid);
6217e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmNIC0_QM0_GLBL_NON_SECURE_PROPS_1,
6218e65e175bSOded Gabbay asid);
6219e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmNIC0_QM0_GLBL_NON_SECURE_PROPS_2,
6220e65e175bSOded Gabbay asid);
6221e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmNIC0_QM0_GLBL_NON_SECURE_PROPS_3,
6222e65e175bSOded Gabbay asid);
6223e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmNIC0_QM0_GLBL_NON_SECURE_PROPS_4,
6224e65e175bSOded Gabbay asid);
6225e65e175bSOded Gabbay }
6226e65e175bSOded Gabbay
6227e65e175bSOded Gabbay if (gaudi->hw_cap_initialized & HW_CAP_NIC1) {
6228e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmNIC0_QM1_GLBL_NON_SECURE_PROPS_0,
6229e65e175bSOded Gabbay asid);
6230e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmNIC0_QM1_GLBL_NON_SECURE_PROPS_1,
6231e65e175bSOded Gabbay asid);
6232e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmNIC0_QM1_GLBL_NON_SECURE_PROPS_2,
6233e65e175bSOded Gabbay asid);
6234e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmNIC0_QM1_GLBL_NON_SECURE_PROPS_3,
6235e65e175bSOded Gabbay asid);
6236e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmNIC0_QM1_GLBL_NON_SECURE_PROPS_4,
6237e65e175bSOded Gabbay asid);
6238e65e175bSOded Gabbay }
6239e65e175bSOded Gabbay
6240e65e175bSOded Gabbay if (gaudi->hw_cap_initialized & HW_CAP_NIC2) {
6241e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmNIC1_QM0_GLBL_NON_SECURE_PROPS_0,
6242e65e175bSOded Gabbay asid);
6243e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmNIC1_QM0_GLBL_NON_SECURE_PROPS_1,
6244e65e175bSOded Gabbay asid);
6245e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmNIC1_QM0_GLBL_NON_SECURE_PROPS_2,
6246e65e175bSOded Gabbay asid);
6247e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmNIC1_QM0_GLBL_NON_SECURE_PROPS_3,
6248e65e175bSOded Gabbay asid);
6249e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmNIC1_QM0_GLBL_NON_SECURE_PROPS_4,
6250e65e175bSOded Gabbay asid);
6251e65e175bSOded Gabbay }
6252e65e175bSOded Gabbay
6253e65e175bSOded Gabbay if (gaudi->hw_cap_initialized & HW_CAP_NIC3) {
6254e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmNIC1_QM1_GLBL_NON_SECURE_PROPS_0,
6255e65e175bSOded Gabbay asid);
6256e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmNIC1_QM1_GLBL_NON_SECURE_PROPS_1,
6257e65e175bSOded Gabbay asid);
6258e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmNIC1_QM1_GLBL_NON_SECURE_PROPS_2,
6259e65e175bSOded Gabbay asid);
6260e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmNIC1_QM1_GLBL_NON_SECURE_PROPS_3,
6261e65e175bSOded Gabbay asid);
6262e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmNIC1_QM1_GLBL_NON_SECURE_PROPS_4,
6263e65e175bSOded Gabbay asid);
6264e65e175bSOded Gabbay }
6265e65e175bSOded Gabbay
6266e65e175bSOded Gabbay if (gaudi->hw_cap_initialized & HW_CAP_NIC4) {
6267e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmNIC2_QM0_GLBL_NON_SECURE_PROPS_0,
6268e65e175bSOded Gabbay asid);
6269e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmNIC2_QM0_GLBL_NON_SECURE_PROPS_1,
6270e65e175bSOded Gabbay asid);
6271e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmNIC2_QM0_GLBL_NON_SECURE_PROPS_2,
6272e65e175bSOded Gabbay asid);
6273e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmNIC2_QM0_GLBL_NON_SECURE_PROPS_3,
6274e65e175bSOded Gabbay asid);
6275e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmNIC2_QM0_GLBL_NON_SECURE_PROPS_4,
6276e65e175bSOded Gabbay asid);
6277e65e175bSOded Gabbay }
6278e65e175bSOded Gabbay
6279e65e175bSOded Gabbay if (gaudi->hw_cap_initialized & HW_CAP_NIC5) {
6280e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmNIC2_QM1_GLBL_NON_SECURE_PROPS_0,
6281e65e175bSOded Gabbay asid);
6282e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmNIC2_QM1_GLBL_NON_SECURE_PROPS_1,
6283e65e175bSOded Gabbay asid);
6284e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmNIC2_QM1_GLBL_NON_SECURE_PROPS_2,
6285e65e175bSOded Gabbay asid);
6286e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmNIC2_QM1_GLBL_NON_SECURE_PROPS_3,
6287e65e175bSOded Gabbay asid);
6288e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmNIC2_QM1_GLBL_NON_SECURE_PROPS_4,
6289e65e175bSOded Gabbay asid);
6290e65e175bSOded Gabbay }
6291e65e175bSOded Gabbay
6292e65e175bSOded Gabbay if (gaudi->hw_cap_initialized & HW_CAP_NIC6) {
6293e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmNIC3_QM0_GLBL_NON_SECURE_PROPS_0,
6294e65e175bSOded Gabbay asid);
6295e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmNIC3_QM0_GLBL_NON_SECURE_PROPS_1,
6296e65e175bSOded Gabbay asid);
6297e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmNIC3_QM0_GLBL_NON_SECURE_PROPS_2,
6298e65e175bSOded Gabbay asid);
6299e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmNIC3_QM0_GLBL_NON_SECURE_PROPS_3,
6300e65e175bSOded Gabbay asid);
6301e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmNIC3_QM0_GLBL_NON_SECURE_PROPS_4,
6302e65e175bSOded Gabbay asid);
6303e65e175bSOded Gabbay }
6304e65e175bSOded Gabbay
6305e65e175bSOded Gabbay if (gaudi->hw_cap_initialized & HW_CAP_NIC7) {
6306e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmNIC3_QM1_GLBL_NON_SECURE_PROPS_0,
6307e65e175bSOded Gabbay asid);
6308e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmNIC3_QM1_GLBL_NON_SECURE_PROPS_1,
6309e65e175bSOded Gabbay asid);
6310e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmNIC3_QM1_GLBL_NON_SECURE_PROPS_2,
6311e65e175bSOded Gabbay asid);
6312e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmNIC3_QM1_GLBL_NON_SECURE_PROPS_3,
6313e65e175bSOded Gabbay asid);
6314e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmNIC3_QM1_GLBL_NON_SECURE_PROPS_4,
6315e65e175bSOded Gabbay asid);
6316e65e175bSOded Gabbay }
6317e65e175bSOded Gabbay
6318e65e175bSOded Gabbay if (gaudi->hw_cap_initialized & HW_CAP_NIC8) {
6319e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmNIC4_QM0_GLBL_NON_SECURE_PROPS_0,
6320e65e175bSOded Gabbay asid);
6321e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmNIC4_QM0_GLBL_NON_SECURE_PROPS_1,
6322e65e175bSOded Gabbay asid);
6323e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmNIC4_QM0_GLBL_NON_SECURE_PROPS_2,
6324e65e175bSOded Gabbay asid);
6325e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmNIC4_QM0_GLBL_NON_SECURE_PROPS_3,
6326e65e175bSOded Gabbay asid);
6327e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmNIC4_QM0_GLBL_NON_SECURE_PROPS_4,
6328e65e175bSOded Gabbay asid);
6329e65e175bSOded Gabbay }
6330e65e175bSOded Gabbay
6331e65e175bSOded Gabbay if (gaudi->hw_cap_initialized & HW_CAP_NIC9) {
6332e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmNIC4_QM1_GLBL_NON_SECURE_PROPS_0,
6333e65e175bSOded Gabbay asid);
6334e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmNIC4_QM1_GLBL_NON_SECURE_PROPS_1,
6335e65e175bSOded Gabbay asid);
6336e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmNIC4_QM1_GLBL_NON_SECURE_PROPS_2,
6337e65e175bSOded Gabbay asid);
6338e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmNIC4_QM1_GLBL_NON_SECURE_PROPS_3,
6339e65e175bSOded Gabbay asid);
6340e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmNIC4_QM1_GLBL_NON_SECURE_PROPS_4,
6341e65e175bSOded Gabbay asid);
6342e65e175bSOded Gabbay }
6343e65e175bSOded Gabbay
6344e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmPSOC_GLOBAL_CONF_TRACE_ARUSER, asid);
6345e65e175bSOded Gabbay gaudi_mmu_prepare_reg(hdev, mmPSOC_GLOBAL_CONF_TRACE_AWUSER, asid);
6346e65e175bSOded Gabbay }
6347e65e175bSOded Gabbay
gaudi_send_job_on_qman0(struct hl_device * hdev,struct hl_cs_job * job)6348e65e175bSOded Gabbay static int gaudi_send_job_on_qman0(struct hl_device *hdev,
6349e65e175bSOded Gabbay struct hl_cs_job *job)
6350e65e175bSOded Gabbay {
6351e65e175bSOded Gabbay struct packet_msg_prot *fence_pkt;
6352e65e175bSOded Gabbay u32 *fence_ptr;
6353e65e175bSOded Gabbay dma_addr_t fence_dma_addr;
6354e65e175bSOded Gabbay struct hl_cb *cb;
6355e65e175bSOded Gabbay u32 tmp, timeout, dma_offset;
6356e65e175bSOded Gabbay int rc;
6357e65e175bSOded Gabbay
6358e65e175bSOded Gabbay if (hdev->pldm)
6359e65e175bSOded Gabbay timeout = GAUDI_PLDM_QMAN0_TIMEOUT_USEC;
6360e65e175bSOded Gabbay else
6361e65e175bSOded Gabbay timeout = HL_DEVICE_TIMEOUT_USEC;
6362e65e175bSOded Gabbay
6363e65e175bSOded Gabbay fence_ptr = hl_asic_dma_pool_zalloc(hdev, 4, GFP_KERNEL, &fence_dma_addr);
6364e65e175bSOded Gabbay if (!fence_ptr) {
6365e65e175bSOded Gabbay dev_err(hdev->dev,
6366e65e175bSOded Gabbay "Failed to allocate fence memory for QMAN0\n");
6367e65e175bSOded Gabbay return -ENOMEM;
6368e65e175bSOded Gabbay }
6369e65e175bSOded Gabbay
6370e65e175bSOded Gabbay cb = job->patched_cb;
6371e65e175bSOded Gabbay
6372e65e175bSOded Gabbay fence_pkt = cb->kernel_address +
6373e65e175bSOded Gabbay job->job_cb_size - sizeof(struct packet_msg_prot);
6374e65e175bSOded Gabbay
6375e65e175bSOded Gabbay tmp = FIELD_PREP(GAUDI_PKT_CTL_OPCODE_MASK, PACKET_MSG_PROT);
6376e65e175bSOded Gabbay tmp |= FIELD_PREP(GAUDI_PKT_CTL_EB_MASK, 1);
6377e65e175bSOded Gabbay tmp |= FIELD_PREP(GAUDI_PKT_CTL_MB_MASK, 1);
6378e65e175bSOded Gabbay
6379e65e175bSOded Gabbay fence_pkt->ctl = cpu_to_le32(tmp);
6380e65e175bSOded Gabbay fence_pkt->value = cpu_to_le32(GAUDI_QMAN0_FENCE_VAL);
6381e65e175bSOded Gabbay fence_pkt->addr = cpu_to_le64(fence_dma_addr);
6382e65e175bSOded Gabbay
6383e65e175bSOded Gabbay dma_offset = gaudi_dma_assignment[GAUDI_PCI_DMA_1] * DMA_CORE_OFFSET;
6384e65e175bSOded Gabbay
6385e65e175bSOded Gabbay WREG32(mmDMA0_CORE_PROT + dma_offset,
6386e65e175bSOded Gabbay BIT(DMA0_CORE_PROT_ERR_VAL_SHIFT) | BIT(DMA0_CORE_PROT_VAL_SHIFT));
6387e65e175bSOded Gabbay
6388e65e175bSOded Gabbay rc = hl_hw_queue_send_cb_no_cmpl(hdev, GAUDI_QUEUE_ID_DMA_0_0,
6389e65e175bSOded Gabbay job->job_cb_size, cb->bus_address);
6390e65e175bSOded Gabbay if (rc) {
6391e65e175bSOded Gabbay dev_err(hdev->dev, "Failed to send CB on QMAN0, %d\n", rc);
6392e65e175bSOded Gabbay goto free_fence_ptr;
6393e65e175bSOded Gabbay }
6394e65e175bSOded Gabbay
6395e65e175bSOded Gabbay rc = hl_poll_timeout_memory(hdev, fence_ptr, tmp,
6396e65e175bSOded Gabbay (tmp == GAUDI_QMAN0_FENCE_VAL), 1000,
6397e65e175bSOded Gabbay timeout, true);
6398e65e175bSOded Gabbay
6399e65e175bSOded Gabbay hl_hw_queue_inc_ci_kernel(hdev, GAUDI_QUEUE_ID_DMA_0_0);
6400e65e175bSOded Gabbay
6401e65e175bSOded Gabbay if (rc == -ETIMEDOUT) {
6402e65e175bSOded Gabbay dev_err(hdev->dev, "QMAN0 Job timeout (0x%x)\n", tmp);
6403e65e175bSOded Gabbay goto free_fence_ptr;
6404e65e175bSOded Gabbay }
6405e65e175bSOded Gabbay
6406e65e175bSOded Gabbay free_fence_ptr:
6407e65e175bSOded Gabbay WREG32(mmDMA0_CORE_PROT + dma_offset, BIT(DMA0_CORE_PROT_ERR_VAL_SHIFT));
6408e65e175bSOded Gabbay
6409e65e175bSOded Gabbay hl_asic_dma_pool_free(hdev, (void *) fence_ptr, fence_dma_addr);
6410e65e175bSOded Gabbay return rc;
6411e65e175bSOded Gabbay }
6412e65e175bSOded Gabbay
gaudi_get_event_desc(u16 event_type,char * desc,size_t size)6413e65e175bSOded Gabbay static void gaudi_get_event_desc(u16 event_type, char *desc, size_t size)
6414e65e175bSOded Gabbay {
6415e65e175bSOded Gabbay if (event_type >= GAUDI_EVENT_SIZE)
6416e65e175bSOded Gabbay goto event_not_supported;
6417e65e175bSOded Gabbay
6418e65e175bSOded Gabbay if (!gaudi_irq_map_table[event_type].valid)
6419e65e175bSOded Gabbay goto event_not_supported;
6420e65e175bSOded Gabbay
6421e65e175bSOded Gabbay snprintf(desc, size, gaudi_irq_map_table[event_type].name);
6422e65e175bSOded Gabbay
6423e65e175bSOded Gabbay return;
6424e65e175bSOded Gabbay
6425e65e175bSOded Gabbay event_not_supported:
6426e65e175bSOded Gabbay snprintf(desc, size, "N/A");
6427e65e175bSOded Gabbay }
6428e65e175bSOded Gabbay
gaudi_get_razwi_initiator_dma_name(struct hl_device * hdev,u32 x_y,bool is_write,u16 * engine_id_1,u16 * engine_id_2)6429e65e175bSOded Gabbay static const char *gaudi_get_razwi_initiator_dma_name(struct hl_device *hdev, u32 x_y,
6430e65e175bSOded Gabbay bool is_write, u16 *engine_id_1,
6431e65e175bSOded Gabbay u16 *engine_id_2)
6432e65e175bSOded Gabbay {
6433e65e175bSOded Gabbay u32 dma_id[2], dma_offset, err_cause[2], mask, i;
6434e65e175bSOded Gabbay
6435e65e175bSOded Gabbay mask = is_write ? DMA0_CORE_ERR_CAUSE_HBW_WR_ERR_MASK :
6436e65e175bSOded Gabbay DMA0_CORE_ERR_CAUSE_HBW_RD_ERR_MASK;
6437e65e175bSOded Gabbay
6438e65e175bSOded Gabbay switch (x_y) {
6439e65e175bSOded Gabbay case RAZWI_INITIATOR_ID_X_Y_DMA_IF_W_S_0:
6440e65e175bSOded Gabbay case RAZWI_INITIATOR_ID_X_Y_DMA_IF_W_S_1:
6441e65e175bSOded Gabbay dma_id[0] = 0;
6442e65e175bSOded Gabbay dma_id[1] = 2;
6443e65e175bSOded Gabbay break;
6444e65e175bSOded Gabbay case RAZWI_INITIATOR_ID_X_Y_DMA_IF_E_S_0:
6445e65e175bSOded Gabbay case RAZWI_INITIATOR_ID_X_Y_DMA_IF_E_S_1:
6446e65e175bSOded Gabbay dma_id[0] = 1;
6447e65e175bSOded Gabbay dma_id[1] = 3;
6448e65e175bSOded Gabbay break;
6449e65e175bSOded Gabbay case RAZWI_INITIATOR_ID_X_Y_DMA_IF_W_N_0:
6450e65e175bSOded Gabbay case RAZWI_INITIATOR_ID_X_Y_DMA_IF_W_N_1:
6451e65e175bSOded Gabbay dma_id[0] = 4;
6452e65e175bSOded Gabbay dma_id[1] = 6;
6453e65e175bSOded Gabbay break;
6454e65e175bSOded Gabbay case RAZWI_INITIATOR_ID_X_Y_DMA_IF_E_N_0:
6455e65e175bSOded Gabbay case RAZWI_INITIATOR_ID_X_Y_DMA_IF_E_N_1:
6456e65e175bSOded Gabbay dma_id[0] = 5;
6457e65e175bSOded Gabbay dma_id[1] = 7;
6458e65e175bSOded Gabbay break;
6459e65e175bSOded Gabbay default:
6460e65e175bSOded Gabbay goto unknown_initiator;
6461e65e175bSOded Gabbay }
6462e65e175bSOded Gabbay
6463e65e175bSOded Gabbay for (i = 0 ; i < 2 ; i++) {
6464e65e175bSOded Gabbay dma_offset = dma_id[i] * DMA_CORE_OFFSET;
6465e65e175bSOded Gabbay err_cause[i] = RREG32(mmDMA0_CORE_ERR_CAUSE + dma_offset);
6466e65e175bSOded Gabbay }
6467e65e175bSOded Gabbay
6468e65e175bSOded Gabbay switch (x_y) {
6469e65e175bSOded Gabbay case RAZWI_INITIATOR_ID_X_Y_DMA_IF_W_S_0:
6470e65e175bSOded Gabbay case RAZWI_INITIATOR_ID_X_Y_DMA_IF_W_S_1:
6471e65e175bSOded Gabbay if ((err_cause[0] & mask) && !(err_cause[1] & mask)) {
6472e65e175bSOded Gabbay *engine_id_1 = GAUDI_ENGINE_ID_DMA_0;
6473e65e175bSOded Gabbay return "DMA0";
6474e65e175bSOded Gabbay } else if (!(err_cause[0] & mask) && (err_cause[1] & mask)) {
6475e65e175bSOded Gabbay *engine_id_1 = GAUDI_ENGINE_ID_DMA_2;
6476e65e175bSOded Gabbay return "DMA2";
6477e65e175bSOded Gabbay } else {
6478e65e175bSOded Gabbay *engine_id_1 = GAUDI_ENGINE_ID_DMA_0;
6479e65e175bSOded Gabbay *engine_id_2 = GAUDI_ENGINE_ID_DMA_2;
6480e65e175bSOded Gabbay return "DMA0 or DMA2";
6481e65e175bSOded Gabbay }
6482e65e175bSOded Gabbay case RAZWI_INITIATOR_ID_X_Y_DMA_IF_E_S_0:
6483e65e175bSOded Gabbay case RAZWI_INITIATOR_ID_X_Y_DMA_IF_E_S_1:
6484e65e175bSOded Gabbay if ((err_cause[0] & mask) && !(err_cause[1] & mask)) {
6485e65e175bSOded Gabbay *engine_id_1 = GAUDI_ENGINE_ID_DMA_1;
6486e65e175bSOded Gabbay return "DMA1";
6487e65e175bSOded Gabbay } else if (!(err_cause[0] & mask) && (err_cause[1] & mask)) {
6488e65e175bSOded Gabbay *engine_id_1 = GAUDI_ENGINE_ID_DMA_3;
6489e65e175bSOded Gabbay return "DMA3";
6490e65e175bSOded Gabbay } else {
6491e65e175bSOded Gabbay *engine_id_1 = GAUDI_ENGINE_ID_DMA_1;
6492e65e175bSOded Gabbay *engine_id_2 = GAUDI_ENGINE_ID_DMA_3;
6493e65e175bSOded Gabbay return "DMA1 or DMA3";
6494e65e175bSOded Gabbay }
6495e65e175bSOded Gabbay case RAZWI_INITIATOR_ID_X_Y_DMA_IF_W_N_0:
6496e65e175bSOded Gabbay case RAZWI_INITIATOR_ID_X_Y_DMA_IF_W_N_1:
6497e65e175bSOded Gabbay if ((err_cause[0] & mask) && !(err_cause[1] & mask)) {
6498e65e175bSOded Gabbay *engine_id_1 = GAUDI_ENGINE_ID_DMA_4;
6499e65e175bSOded Gabbay return "DMA4";
6500e65e175bSOded Gabbay } else if (!(err_cause[0] & mask) && (err_cause[1] & mask)) {
6501e65e175bSOded Gabbay *engine_id_1 = GAUDI_ENGINE_ID_DMA_6;
6502e65e175bSOded Gabbay return "DMA6";
6503e65e175bSOded Gabbay } else {
6504e65e175bSOded Gabbay *engine_id_1 = GAUDI_ENGINE_ID_DMA_4;
6505e65e175bSOded Gabbay *engine_id_2 = GAUDI_ENGINE_ID_DMA_6;
6506e65e175bSOded Gabbay return "DMA4 or DMA6";
6507e65e175bSOded Gabbay }
6508e65e175bSOded Gabbay case RAZWI_INITIATOR_ID_X_Y_DMA_IF_E_N_0:
6509e65e175bSOded Gabbay case RAZWI_INITIATOR_ID_X_Y_DMA_IF_E_N_1:
6510e65e175bSOded Gabbay if ((err_cause[0] & mask) && !(err_cause[1] & mask)) {
6511e65e175bSOded Gabbay *engine_id_1 = GAUDI_ENGINE_ID_DMA_5;
6512e65e175bSOded Gabbay return "DMA5";
6513e65e175bSOded Gabbay } else if (!(err_cause[0] & mask) && (err_cause[1] & mask)) {
6514e65e175bSOded Gabbay *engine_id_1 = GAUDI_ENGINE_ID_DMA_7;
6515e65e175bSOded Gabbay return "DMA7";
6516e65e175bSOded Gabbay } else {
6517e65e175bSOded Gabbay *engine_id_1 = GAUDI_ENGINE_ID_DMA_5;
6518e65e175bSOded Gabbay *engine_id_2 = GAUDI_ENGINE_ID_DMA_7;
6519e65e175bSOded Gabbay return "DMA5 or DMA7";
6520e65e175bSOded Gabbay }
6521e65e175bSOded Gabbay }
6522e65e175bSOded Gabbay
6523e65e175bSOded Gabbay unknown_initiator:
6524e65e175bSOded Gabbay return "unknown initiator";
6525e65e175bSOded Gabbay }
6526e65e175bSOded Gabbay
gaudi_get_razwi_initiator_name(struct hl_device * hdev,bool is_write,u16 * engine_id_1,u16 * engine_id_2)6527e65e175bSOded Gabbay static const char *gaudi_get_razwi_initiator_name(struct hl_device *hdev, bool is_write,
6528e65e175bSOded Gabbay u16 *engine_id_1, u16 *engine_id_2)
6529e65e175bSOded Gabbay {
6530e65e175bSOded Gabbay u32 val, x_y, axi_id;
6531e65e175bSOded Gabbay
6532e65e175bSOded Gabbay val = is_write ? RREG32(mmMMU_UP_RAZWI_WRITE_ID) :
6533e65e175bSOded Gabbay RREG32(mmMMU_UP_RAZWI_READ_ID);
6534e65e175bSOded Gabbay x_y = val & ((RAZWI_INITIATOR_Y_MASK << RAZWI_INITIATOR_Y_SHIFT) |
6535e65e175bSOded Gabbay (RAZWI_INITIATOR_X_MASK << RAZWI_INITIATOR_X_SHIFT));
6536e65e175bSOded Gabbay axi_id = val & (RAZWI_INITIATOR_AXI_ID_MASK <<
6537e65e175bSOded Gabbay RAZWI_INITIATOR_AXI_ID_SHIFT);
6538e65e175bSOded Gabbay
6539e65e175bSOded Gabbay switch (x_y) {
6540e65e175bSOded Gabbay case RAZWI_INITIATOR_ID_X_Y_TPC0_NIC0:
6541e65e175bSOded Gabbay if (axi_id == RAZWI_INITIATOR_ID_AXI_ID(AXI_ID_TPC)) {
6542e65e175bSOded Gabbay *engine_id_1 = GAUDI_ENGINE_ID_TPC_0;
6543e65e175bSOded Gabbay return "TPC0";
6544e65e175bSOded Gabbay }
6545e65e175bSOded Gabbay if (axi_id == RAZWI_INITIATOR_ID_AXI_ID(AXI_ID_NIC)) {
6546e65e175bSOded Gabbay *engine_id_1 = GAUDI_ENGINE_ID_NIC_0;
6547e65e175bSOded Gabbay return "NIC0";
6548e65e175bSOded Gabbay }
6549e65e175bSOded Gabbay break;
6550e65e175bSOded Gabbay case RAZWI_INITIATOR_ID_X_Y_TPC1:
6551e65e175bSOded Gabbay *engine_id_1 = GAUDI_ENGINE_ID_TPC_1;
6552e65e175bSOded Gabbay return "TPC1";
6553e65e175bSOded Gabbay case RAZWI_INITIATOR_ID_X_Y_MME0_0:
6554e65e175bSOded Gabbay case RAZWI_INITIATOR_ID_X_Y_MME0_1:
6555e65e175bSOded Gabbay *engine_id_1 = GAUDI_ENGINE_ID_MME_0;
6556e65e175bSOded Gabbay return "MME0";
6557e65e175bSOded Gabbay case RAZWI_INITIATOR_ID_X_Y_MME1_0:
6558e65e175bSOded Gabbay case RAZWI_INITIATOR_ID_X_Y_MME1_1:
6559e65e175bSOded Gabbay *engine_id_1 = GAUDI_ENGINE_ID_MME_1;
6560e65e175bSOded Gabbay return "MME1";
6561e65e175bSOded Gabbay case RAZWI_INITIATOR_ID_X_Y_TPC2:
6562e65e175bSOded Gabbay *engine_id_1 = GAUDI_ENGINE_ID_TPC_2;
6563e65e175bSOded Gabbay return "TPC2";
6564e65e175bSOded Gabbay case RAZWI_INITIATOR_ID_X_Y_TPC3_PCI_CPU_PSOC:
6565e65e175bSOded Gabbay if (axi_id == RAZWI_INITIATOR_ID_AXI_ID(AXI_ID_TPC)) {
6566e65e175bSOded Gabbay *engine_id_1 = GAUDI_ENGINE_ID_TPC_3;
6567e65e175bSOded Gabbay return "TPC3";
6568e65e175bSOded Gabbay }
6569e65e175bSOded Gabbay /* PCI, CPU or PSOC does not have engine id*/
6570e65e175bSOded Gabbay if (axi_id == RAZWI_INITIATOR_ID_AXI_ID(AXI_ID_PCI))
6571e65e175bSOded Gabbay return "PCI";
6572e65e175bSOded Gabbay if (axi_id == RAZWI_INITIATOR_ID_AXI_ID(AXI_ID_CPU))
6573e65e175bSOded Gabbay return "CPU";
6574e65e175bSOded Gabbay if (axi_id == RAZWI_INITIATOR_ID_AXI_ID(AXI_ID_PSOC))
6575e65e175bSOded Gabbay return "PSOC";
6576e65e175bSOded Gabbay break;
6577e65e175bSOded Gabbay case RAZWI_INITIATOR_ID_X_Y_DMA_IF_W_S_0:
6578e65e175bSOded Gabbay case RAZWI_INITIATOR_ID_X_Y_DMA_IF_W_S_1:
6579e65e175bSOded Gabbay case RAZWI_INITIATOR_ID_X_Y_DMA_IF_E_S_0:
6580e65e175bSOded Gabbay case RAZWI_INITIATOR_ID_X_Y_DMA_IF_E_S_1:
6581e65e175bSOded Gabbay case RAZWI_INITIATOR_ID_X_Y_DMA_IF_W_N_0:
6582e65e175bSOded Gabbay case RAZWI_INITIATOR_ID_X_Y_DMA_IF_W_N_1:
6583e65e175bSOded Gabbay case RAZWI_INITIATOR_ID_X_Y_DMA_IF_E_N_0:
6584e65e175bSOded Gabbay case RAZWI_INITIATOR_ID_X_Y_DMA_IF_E_N_1:
6585e65e175bSOded Gabbay return gaudi_get_razwi_initiator_dma_name(hdev, x_y, is_write,
6586e65e175bSOded Gabbay engine_id_1, engine_id_2);
6587e65e175bSOded Gabbay case RAZWI_INITIATOR_ID_X_Y_TPC4_NIC1_NIC2:
6588e65e175bSOded Gabbay if (axi_id == RAZWI_INITIATOR_ID_AXI_ID(AXI_ID_TPC)) {
6589e65e175bSOded Gabbay *engine_id_1 = GAUDI_ENGINE_ID_TPC_4;
6590e65e175bSOded Gabbay return "TPC4";
6591e65e175bSOded Gabbay }
6592e65e175bSOded Gabbay if (axi_id == RAZWI_INITIATOR_ID_AXI_ID(AXI_ID_NIC)) {
6593e65e175bSOded Gabbay *engine_id_1 = GAUDI_ENGINE_ID_NIC_1;
6594e65e175bSOded Gabbay return "NIC1";
6595e65e175bSOded Gabbay }
6596e65e175bSOded Gabbay if (axi_id == RAZWI_INITIATOR_ID_AXI_ID(AXI_ID_NIC_FT)) {
6597e65e175bSOded Gabbay *engine_id_1 = GAUDI_ENGINE_ID_NIC_2;
6598e65e175bSOded Gabbay return "NIC2";
6599e65e175bSOded Gabbay }
6600e65e175bSOded Gabbay break;
6601e65e175bSOded Gabbay case RAZWI_INITIATOR_ID_X_Y_TPC5:
6602e65e175bSOded Gabbay *engine_id_1 = GAUDI_ENGINE_ID_TPC_5;
6603e65e175bSOded Gabbay return "TPC5";
6604e65e175bSOded Gabbay case RAZWI_INITIATOR_ID_X_Y_MME2_0:
6605e65e175bSOded Gabbay case RAZWI_INITIATOR_ID_X_Y_MME2_1:
6606e65e175bSOded Gabbay *engine_id_1 = GAUDI_ENGINE_ID_MME_2;
6607e65e175bSOded Gabbay return "MME2";
6608e65e175bSOded Gabbay case RAZWI_INITIATOR_ID_X_Y_MME3_0:
6609e65e175bSOded Gabbay case RAZWI_INITIATOR_ID_X_Y_MME3_1:
6610e65e175bSOded Gabbay *engine_id_1 = GAUDI_ENGINE_ID_MME_3;
6611e65e175bSOded Gabbay return "MME3";
6612e65e175bSOded Gabbay case RAZWI_INITIATOR_ID_X_Y_TPC6:
6613e65e175bSOded Gabbay *engine_id_1 = GAUDI_ENGINE_ID_TPC_6;
6614e65e175bSOded Gabbay return "TPC6";
6615e65e175bSOded Gabbay case RAZWI_INITIATOR_ID_X_Y_TPC7_NIC4_NIC5:
6616e65e175bSOded Gabbay if (axi_id == RAZWI_INITIATOR_ID_AXI_ID(AXI_ID_TPC)) {
6617e65e175bSOded Gabbay *engine_id_1 = GAUDI_ENGINE_ID_TPC_7;
6618e65e175bSOded Gabbay return "TPC7";
6619e65e175bSOded Gabbay }
6620e65e175bSOded Gabbay if (axi_id == RAZWI_INITIATOR_ID_AXI_ID(AXI_ID_NIC)) {
6621e65e175bSOded Gabbay *engine_id_1 = GAUDI_ENGINE_ID_NIC_4;
6622e65e175bSOded Gabbay return "NIC4";
6623e65e175bSOded Gabbay }
6624e65e175bSOded Gabbay if (axi_id == RAZWI_INITIATOR_ID_AXI_ID(AXI_ID_NIC_FT)) {
6625e65e175bSOded Gabbay *engine_id_1 = GAUDI_ENGINE_ID_NIC_5;
6626e65e175bSOded Gabbay return "NIC5";
6627e65e175bSOded Gabbay }
6628e65e175bSOded Gabbay break;
6629e65e175bSOded Gabbay default:
6630e65e175bSOded Gabbay break;
6631e65e175bSOded Gabbay }
6632e65e175bSOded Gabbay
6633e65e175bSOded Gabbay dev_err(hdev->dev,
6634e65e175bSOded Gabbay "Unknown RAZWI initiator ID 0x%x [Y=%d, X=%d, AXI_ID=%d]\n",
6635e65e175bSOded Gabbay val,
6636e65e175bSOded Gabbay (val >> RAZWI_INITIATOR_Y_SHIFT) & RAZWI_INITIATOR_Y_MASK,
6637e65e175bSOded Gabbay (val >> RAZWI_INITIATOR_X_SHIFT) & RAZWI_INITIATOR_X_MASK,
6638e65e175bSOded Gabbay (val >> RAZWI_INITIATOR_AXI_ID_SHIFT) &
6639e65e175bSOded Gabbay RAZWI_INITIATOR_AXI_ID_MASK);
6640e65e175bSOded Gabbay
6641e65e175bSOded Gabbay return "unknown initiator";
6642e65e175bSOded Gabbay }
6643e65e175bSOded Gabbay
gaudi_print_and_get_razwi_info(struct hl_device * hdev,u16 * engine_id_1,u16 * engine_id_2,bool * is_read,bool * is_write)6644e65e175bSOded Gabbay static void gaudi_print_and_get_razwi_info(struct hl_device *hdev, u16 *engine_id_1,
6645e65e175bSOded Gabbay u16 *engine_id_2, bool *is_read, bool *is_write)
6646e65e175bSOded Gabbay {
6647e65e175bSOded Gabbay
6648e65e175bSOded Gabbay if (RREG32(mmMMU_UP_RAZWI_WRITE_VLD)) {
6649e65e175bSOded Gabbay dev_err_ratelimited(hdev->dev,
6650e65e175bSOded Gabbay "RAZWI event caused by illegal write of %s\n",
6651e65e175bSOded Gabbay gaudi_get_razwi_initiator_name(hdev, true, engine_id_1, engine_id_2));
6652e65e175bSOded Gabbay WREG32(mmMMU_UP_RAZWI_WRITE_VLD, 0);
6653e65e175bSOded Gabbay *is_write = true;
6654e65e175bSOded Gabbay }
6655e65e175bSOded Gabbay
6656e65e175bSOded Gabbay if (RREG32(mmMMU_UP_RAZWI_READ_VLD)) {
6657e65e175bSOded Gabbay dev_err_ratelimited(hdev->dev,
6658e65e175bSOded Gabbay "RAZWI event caused by illegal read of %s\n",
6659e65e175bSOded Gabbay gaudi_get_razwi_initiator_name(hdev, false, engine_id_1, engine_id_2));
6660e65e175bSOded Gabbay WREG32(mmMMU_UP_RAZWI_READ_VLD, 0);
6661e65e175bSOded Gabbay *is_read = true;
6662e65e175bSOded Gabbay }
6663e65e175bSOded Gabbay }
6664e65e175bSOded Gabbay
gaudi_print_and_get_mmu_error_info(struct hl_device * hdev,u64 * addr,u64 * event_mask)6665e65e175bSOded Gabbay static void gaudi_print_and_get_mmu_error_info(struct hl_device *hdev, u64 *addr, u64 *event_mask)
6666e65e175bSOded Gabbay {
6667e65e175bSOded Gabbay struct gaudi_device *gaudi = hdev->asic_specific;
6668e65e175bSOded Gabbay u32 val;
6669e65e175bSOded Gabbay
6670e65e175bSOded Gabbay if (!(gaudi->hw_cap_initialized & HW_CAP_MMU))
6671e65e175bSOded Gabbay return;
6672e65e175bSOded Gabbay
6673e65e175bSOded Gabbay val = RREG32(mmMMU_UP_PAGE_ERROR_CAPTURE);
6674e65e175bSOded Gabbay if (val & MMU_UP_PAGE_ERROR_CAPTURE_ENTRY_VALID_MASK) {
6675e65e175bSOded Gabbay *addr = val & MMU_UP_PAGE_ERROR_CAPTURE_VA_49_32_MASK;
6676e65e175bSOded Gabbay *addr <<= 32;
6677e65e175bSOded Gabbay *addr |= RREG32(mmMMU_UP_PAGE_ERROR_CAPTURE_VA);
6678e65e175bSOded Gabbay
6679e65e175bSOded Gabbay dev_err_ratelimited(hdev->dev, "MMU page fault on va 0x%llx\n", *addr);
6680e65e175bSOded Gabbay hl_handle_page_fault(hdev, *addr, 0, true, event_mask);
6681e65e175bSOded Gabbay
6682e65e175bSOded Gabbay WREG32(mmMMU_UP_PAGE_ERROR_CAPTURE, 0);
6683e65e175bSOded Gabbay }
6684e65e175bSOded Gabbay
6685e65e175bSOded Gabbay val = RREG32(mmMMU_UP_ACCESS_ERROR_CAPTURE);
6686e65e175bSOded Gabbay if (val & MMU_UP_ACCESS_ERROR_CAPTURE_ENTRY_VALID_MASK) {
6687e65e175bSOded Gabbay *addr = val & MMU_UP_ACCESS_ERROR_CAPTURE_VA_49_32_MASK;
6688e65e175bSOded Gabbay *addr <<= 32;
6689e65e175bSOded Gabbay *addr |= RREG32(mmMMU_UP_ACCESS_ERROR_CAPTURE_VA);
6690e65e175bSOded Gabbay
6691e65e175bSOded Gabbay dev_err_ratelimited(hdev->dev, "MMU access error on va 0x%llx\n", *addr);
6692e65e175bSOded Gabbay
6693e65e175bSOded Gabbay WREG32(mmMMU_UP_ACCESS_ERROR_CAPTURE, 0);
6694e65e175bSOded Gabbay }
6695e65e175bSOded Gabbay }
6696e65e175bSOded Gabbay
6697e65e175bSOded Gabbay /*
6698e65e175bSOded Gabbay * +-------------------+------------------------------------------------------+
6699e65e175bSOded Gabbay * | Configuration Reg | Description |
6700e65e175bSOded Gabbay * | Address | |
6701e65e175bSOded Gabbay * +-------------------+------------------------------------------------------+
6702e65e175bSOded Gabbay * | 0xF30 - 0xF3F |ECC single error indication (1 bit per memory wrapper)|
6703e65e175bSOded Gabbay * | |0xF30 memory wrappers 31:0 (MSB to LSB) |
6704e65e175bSOded Gabbay * | |0xF34 memory wrappers 63:32 |
6705e65e175bSOded Gabbay * | |0xF38 memory wrappers 95:64 |
6706e65e175bSOded Gabbay * | |0xF3C memory wrappers 127:96 |
6707e65e175bSOded Gabbay * +-------------------+------------------------------------------------------+
6708e65e175bSOded Gabbay * | 0xF40 - 0xF4F |ECC double error indication (1 bit per memory wrapper)|
6709e65e175bSOded Gabbay * | |0xF40 memory wrappers 31:0 (MSB to LSB) |
6710e65e175bSOded Gabbay * | |0xF44 memory wrappers 63:32 |
6711e65e175bSOded Gabbay * | |0xF48 memory wrappers 95:64 |
6712e65e175bSOded Gabbay * | |0xF4C memory wrappers 127:96 |
6713e65e175bSOded Gabbay * +-------------------+------------------------------------------------------+
6714e65e175bSOded Gabbay */
gaudi_extract_ecc_info(struct hl_device * hdev,struct ecc_info_extract_params * params,u64 * ecc_address,u64 * ecc_syndrom,u8 * memory_wrapper_idx)6715e65e175bSOded Gabbay static int gaudi_extract_ecc_info(struct hl_device *hdev,
6716e65e175bSOded Gabbay struct ecc_info_extract_params *params, u64 *ecc_address,
6717e65e175bSOded Gabbay u64 *ecc_syndrom, u8 *memory_wrapper_idx)
6718e65e175bSOded Gabbay {
6719e65e175bSOded Gabbay u32 i, num_mem_regs, reg, err_bit;
6720e65e175bSOded Gabbay u64 err_addr, err_word = 0;
6721e65e175bSOded Gabbay
6722e65e175bSOded Gabbay num_mem_regs = params->num_memories / 32 +
6723e65e175bSOded Gabbay ((params->num_memories % 32) ? 1 : 0);
6724e65e175bSOded Gabbay
6725e65e175bSOded Gabbay if (params->block_address >= CFG_BASE)
6726e65e175bSOded Gabbay params->block_address -= CFG_BASE;
6727e65e175bSOded Gabbay
6728e65e175bSOded Gabbay if (params->derr)
6729e65e175bSOded Gabbay err_addr = params->block_address + GAUDI_ECC_DERR0_OFFSET;
6730e65e175bSOded Gabbay else
6731e65e175bSOded Gabbay err_addr = params->block_address + GAUDI_ECC_SERR0_OFFSET;
6732e65e175bSOded Gabbay
6733e65e175bSOded Gabbay /* Set invalid wrapper index */
6734e65e175bSOded Gabbay *memory_wrapper_idx = 0xFF;
6735e65e175bSOded Gabbay
6736e65e175bSOded Gabbay /* Iterate through memory wrappers, a single bit must be set */
6737e65e175bSOded Gabbay for (i = 0 ; i < num_mem_regs ; i++) {
6738e65e175bSOded Gabbay err_addr += i * 4;
6739e65e175bSOded Gabbay err_word = RREG32(err_addr);
6740e65e175bSOded Gabbay if (err_word) {
6741e65e175bSOded Gabbay err_bit = __ffs(err_word);
6742e65e175bSOded Gabbay *memory_wrapper_idx = err_bit + (32 * i);
6743e65e175bSOded Gabbay break;
6744e65e175bSOded Gabbay }
6745e65e175bSOded Gabbay }
6746e65e175bSOded Gabbay
6747e65e175bSOded Gabbay if (*memory_wrapper_idx == 0xFF) {
6748e65e175bSOded Gabbay dev_err(hdev->dev, "ECC error information cannot be found\n");
6749e65e175bSOded Gabbay return -EINVAL;
6750e65e175bSOded Gabbay }
6751e65e175bSOded Gabbay
6752e65e175bSOded Gabbay WREG32(params->block_address + GAUDI_ECC_MEM_SEL_OFFSET,
6753e65e175bSOded Gabbay *memory_wrapper_idx);
6754e65e175bSOded Gabbay
6755e65e175bSOded Gabbay *ecc_address =
6756e65e175bSOded Gabbay RREG32(params->block_address + GAUDI_ECC_ADDRESS_OFFSET);
6757e65e175bSOded Gabbay *ecc_syndrom =
6758e65e175bSOded Gabbay RREG32(params->block_address + GAUDI_ECC_SYNDROME_OFFSET);
6759e65e175bSOded Gabbay
6760e65e175bSOded Gabbay /* Clear error indication */
6761e65e175bSOded Gabbay reg = RREG32(params->block_address + GAUDI_ECC_MEM_INFO_CLR_OFFSET);
6762e65e175bSOded Gabbay if (params->derr)
6763e65e175bSOded Gabbay reg |= FIELD_PREP(GAUDI_ECC_MEM_INFO_CLR_DERR_MASK, 1);
6764e65e175bSOded Gabbay else
6765e65e175bSOded Gabbay reg |= FIELD_PREP(GAUDI_ECC_MEM_INFO_CLR_SERR_MASK, 1);
6766e65e175bSOded Gabbay
6767e65e175bSOded Gabbay WREG32(params->block_address + GAUDI_ECC_MEM_INFO_CLR_OFFSET, reg);
6768e65e175bSOded Gabbay
6769e65e175bSOded Gabbay return 0;
6770e65e175bSOded Gabbay }
6771e65e175bSOded Gabbay
6772e65e175bSOded Gabbay /*
6773e65e175bSOded Gabbay * gaudi_queue_idx_dec - decrement queue index (pi/ci) and handle wrap
6774e65e175bSOded Gabbay *
6775e65e175bSOded Gabbay * @idx: the current pi/ci value
6776e65e175bSOded Gabbay * @q_len: the queue length (power of 2)
6777e65e175bSOded Gabbay *
6778e65e175bSOded Gabbay * @return the cyclically decremented index
6779e65e175bSOded Gabbay */
gaudi_queue_idx_dec(u32 idx,u32 q_len)6780e65e175bSOded Gabbay static inline u32 gaudi_queue_idx_dec(u32 idx, u32 q_len)
6781e65e175bSOded Gabbay {
6782e65e175bSOded Gabbay u32 mask = q_len - 1;
6783e65e175bSOded Gabbay
6784e65e175bSOded Gabbay /*
6785e65e175bSOded Gabbay * modular decrement is equivalent to adding (queue_size -1)
6786e65e175bSOded Gabbay * later we take LSBs to make sure the value is in the
6787e65e175bSOded Gabbay * range [0, queue_len - 1]
6788e65e175bSOded Gabbay */
6789e65e175bSOded Gabbay return (idx + q_len - 1) & mask;
6790e65e175bSOded Gabbay }
6791e65e175bSOded Gabbay
6792e65e175bSOded Gabbay /**
6793e65e175bSOded Gabbay * gaudi_handle_sw_config_stream_data - print SW config stream data
6794e65e175bSOded Gabbay *
6795e65e175bSOded Gabbay * @hdev: pointer to the habanalabs device structure
6796e65e175bSOded Gabbay * @stream: the QMAN's stream
6797e65e175bSOded Gabbay * @qman_base: base address of QMAN registers block
6798e65e175bSOded Gabbay * @event_mask: mask of the last events occurred
6799e65e175bSOded Gabbay */
gaudi_handle_sw_config_stream_data(struct hl_device * hdev,u32 stream,u64 qman_base,u64 event_mask)6800e65e175bSOded Gabbay static void gaudi_handle_sw_config_stream_data(struct hl_device *hdev, u32 stream,
6801e65e175bSOded Gabbay u64 qman_base, u64 event_mask)
6802e65e175bSOded Gabbay {
6803e65e175bSOded Gabbay u64 cq_ptr_lo, cq_ptr_hi, cq_tsize, cq_ptr;
6804e65e175bSOded Gabbay u32 cq_ptr_lo_off, size;
6805e65e175bSOded Gabbay
6806e65e175bSOded Gabbay cq_ptr_lo_off = mmTPC0_QM_CQ_PTR_LO_1 - mmTPC0_QM_CQ_PTR_LO_0;
6807e65e175bSOded Gabbay
6808e65e175bSOded Gabbay cq_ptr_lo = qman_base + (mmTPC0_QM_CQ_PTR_LO_0 - mmTPC0_QM_BASE) +
6809e65e175bSOded Gabbay stream * cq_ptr_lo_off;
6810e65e175bSOded Gabbay cq_ptr_hi = cq_ptr_lo +
6811e65e175bSOded Gabbay (mmTPC0_QM_CQ_PTR_HI_0 - mmTPC0_QM_CQ_PTR_LO_0);
6812e65e175bSOded Gabbay cq_tsize = cq_ptr_lo +
6813e65e175bSOded Gabbay (mmTPC0_QM_CQ_TSIZE_0 - mmTPC0_QM_CQ_PTR_LO_0);
6814e65e175bSOded Gabbay
6815e65e175bSOded Gabbay cq_ptr = (((u64) RREG32(cq_ptr_hi)) << 32) | RREG32(cq_ptr_lo);
6816e65e175bSOded Gabbay size = RREG32(cq_tsize);
6817e65e175bSOded Gabbay dev_info(hdev->dev, "stop on err: stream: %u, addr: %#llx, size: %u\n",
6818e65e175bSOded Gabbay stream, cq_ptr, size);
6819e65e175bSOded Gabbay
6820e65e175bSOded Gabbay if (event_mask & HL_NOTIFIER_EVENT_UNDEFINED_OPCODE) {
6821e65e175bSOded Gabbay hdev->captured_err_info.undef_opcode.cq_addr = cq_ptr;
6822e65e175bSOded Gabbay hdev->captured_err_info.undef_opcode.cq_size = size;
6823e65e175bSOded Gabbay hdev->captured_err_info.undef_opcode.stream_id = stream;
6824e65e175bSOded Gabbay }
6825e65e175bSOded Gabbay }
6826e65e175bSOded Gabbay
6827e65e175bSOded Gabbay /**
6828e65e175bSOded Gabbay * gaudi_handle_last_pqes_on_err - print last PQEs on error
6829e65e175bSOded Gabbay *
6830e65e175bSOded Gabbay * @hdev: pointer to the habanalabs device structure
6831e65e175bSOded Gabbay * @qid_base: first QID of the QMAN (out of 4 streams)
6832e65e175bSOded Gabbay * @stream: the QMAN's stream
6833e65e175bSOded Gabbay * @qman_base: base address of QMAN registers block
6834e65e175bSOded Gabbay * @event_mask: mask of the last events occurred
6835e65e175bSOded Gabbay * @pr_sw_conf: if true print the SW config stream data (CQ PTR and SIZE)
6836e65e175bSOded Gabbay */
gaudi_handle_last_pqes_on_err(struct hl_device * hdev,u32 qid_base,u32 stream,u64 qman_base,u64 event_mask,bool pr_sw_conf)6837e65e175bSOded Gabbay static void gaudi_handle_last_pqes_on_err(struct hl_device *hdev, u32 qid_base,
6838e65e175bSOded Gabbay u32 stream, u64 qman_base,
6839e65e175bSOded Gabbay u64 event_mask,
6840e65e175bSOded Gabbay bool pr_sw_conf)
6841e65e175bSOded Gabbay {
6842e65e175bSOded Gabbay u32 ci, qm_ci_stream_off, queue_len;
6843e65e175bSOded Gabbay struct hl_hw_queue *q;
6844e65e175bSOded Gabbay u64 pq_ci, addr[PQ_FETCHER_CACHE_SIZE];
6845e65e175bSOded Gabbay int i;
6846e65e175bSOded Gabbay
6847e65e175bSOded Gabbay q = &hdev->kernel_queues[qid_base + stream];
6848e65e175bSOded Gabbay
6849e65e175bSOded Gabbay qm_ci_stream_off = mmTPC0_QM_PQ_CI_1 - mmTPC0_QM_PQ_CI_0;
6850e65e175bSOded Gabbay pq_ci = qman_base + (mmTPC0_QM_PQ_CI_0 - mmTPC0_QM_BASE) +
6851e65e175bSOded Gabbay stream * qm_ci_stream_off;
6852e65e175bSOded Gabbay
6853e65e175bSOded Gabbay queue_len = (q->queue_type == QUEUE_TYPE_INT) ?
6854e65e175bSOded Gabbay q->int_queue_len : HL_QUEUE_LENGTH;
6855e65e175bSOded Gabbay
6856e65e175bSOded Gabbay hdev->asic_funcs->hw_queues_lock(hdev);
6857e65e175bSOded Gabbay
6858e65e175bSOded Gabbay if (pr_sw_conf)
6859e65e175bSOded Gabbay gaudi_handle_sw_config_stream_data(hdev, stream, qman_base, event_mask);
6860e65e175bSOded Gabbay
6861e65e175bSOded Gabbay ci = RREG32(pq_ci);
6862e65e175bSOded Gabbay
6863e65e175bSOded Gabbay /* we should start printing form ci -1 */
6864e65e175bSOded Gabbay ci = gaudi_queue_idx_dec(ci, queue_len);
6865e65e175bSOded Gabbay memset(addr, 0, sizeof(addr));
6866e65e175bSOded Gabbay
6867e65e175bSOded Gabbay for (i = 0; i < PQ_FETCHER_CACHE_SIZE; i++) {
6868e65e175bSOded Gabbay struct hl_bd *bd;
6869e65e175bSOded Gabbay u32 len;
6870e65e175bSOded Gabbay
6871e65e175bSOded Gabbay bd = q->kernel_address;
6872e65e175bSOded Gabbay bd += ci;
6873e65e175bSOded Gabbay
6874e65e175bSOded Gabbay len = le32_to_cpu(bd->len);
6875e65e175bSOded Gabbay /* len 0 means uninitialized entry- break */
6876e65e175bSOded Gabbay if (!len)
6877e65e175bSOded Gabbay break;
6878e65e175bSOded Gabbay
6879e65e175bSOded Gabbay addr[i] = le64_to_cpu(bd->ptr);
6880e65e175bSOded Gabbay
6881e65e175bSOded Gabbay dev_info(hdev->dev, "stop on err PQE(stream %u): ci: %u, addr: %#llx, size: %u\n",
6882e65e175bSOded Gabbay stream, ci, addr[i], len);
6883e65e175bSOded Gabbay
6884e65e175bSOded Gabbay /* get previous ci, wrap if needed */
6885e65e175bSOded Gabbay ci = gaudi_queue_idx_dec(ci, queue_len);
6886e65e175bSOded Gabbay }
6887e65e175bSOded Gabbay
6888e65e175bSOded Gabbay if (event_mask & HL_NOTIFIER_EVENT_UNDEFINED_OPCODE) {
6889e65e175bSOded Gabbay struct undefined_opcode_info *undef_opcode = &hdev->captured_err_info.undef_opcode;
6890e65e175bSOded Gabbay u32 arr_idx = undef_opcode->cb_addr_streams_len;
6891e65e175bSOded Gabbay
6892e65e175bSOded Gabbay if (arr_idx == 0) {
6893e65e175bSOded Gabbay undef_opcode->timestamp = ktime_get();
6894e65e175bSOded Gabbay undef_opcode->engine_id = gaudi_queue_id_to_engine_id[qid_base];
6895e65e175bSOded Gabbay }
6896e65e175bSOded Gabbay
6897e65e175bSOded Gabbay memcpy(undef_opcode->cb_addr_streams[arr_idx], addr, sizeof(addr));
6898e65e175bSOded Gabbay undef_opcode->cb_addr_streams_len++;
6899e65e175bSOded Gabbay }
6900e65e175bSOded Gabbay
6901e65e175bSOded Gabbay hdev->asic_funcs->hw_queues_unlock(hdev);
6902e65e175bSOded Gabbay }
6903e65e175bSOded Gabbay
6904e65e175bSOded Gabbay /**
6905e65e175bSOded Gabbay * handle_qman_data_on_err - extract QMAN data on error
6906e65e175bSOded Gabbay *
6907e65e175bSOded Gabbay * @hdev: pointer to the habanalabs device structure
6908e65e175bSOded Gabbay * @qid_base: first QID of the QMAN (out of 4 streams)
6909e65e175bSOded Gabbay * @stream: the QMAN's stream
6910e65e175bSOded Gabbay * @qman_base: base address of QMAN registers block
6911e65e175bSOded Gabbay * @event_mask: mask of the last events occurred
6912e65e175bSOded Gabbay *
6913e65e175bSOded Gabbay * This function attempt to exatract as much data as possible on QMAN error.
6914e65e175bSOded Gabbay * On upper CP print the SW config stream data and last 8 PQEs.
6915e65e175bSOded Gabbay * On lower CP print SW config data and last PQEs of ALL 4 upper CPs
6916e65e175bSOded Gabbay */
handle_qman_data_on_err(struct hl_device * hdev,u32 qid_base,u32 stream,u64 qman_base,u64 event_mask)6917e65e175bSOded Gabbay static void handle_qman_data_on_err(struct hl_device *hdev, u32 qid_base,
6918e65e175bSOded Gabbay u32 stream, u64 qman_base, u64 event_mask)
6919e65e175bSOded Gabbay {
6920e65e175bSOded Gabbay u32 i;
6921e65e175bSOded Gabbay
6922e65e175bSOded Gabbay if (stream != QMAN_STREAMS) {
6923e65e175bSOded Gabbay gaudi_handle_last_pqes_on_err(hdev, qid_base, stream,
6924e65e175bSOded Gabbay qman_base, event_mask, true);
6925e65e175bSOded Gabbay return;
6926e65e175bSOded Gabbay }
6927e65e175bSOded Gabbay
6928e65e175bSOded Gabbay /* handle Lower-CP */
6929e65e175bSOded Gabbay gaudi_handle_sw_config_stream_data(hdev, stream, qman_base, event_mask);
6930e65e175bSOded Gabbay
6931e65e175bSOded Gabbay for (i = 0; i < QMAN_STREAMS; i++)
6932e65e175bSOded Gabbay gaudi_handle_last_pqes_on_err(hdev, qid_base, i,
6933e65e175bSOded Gabbay qman_base, event_mask, false);
6934e65e175bSOded Gabbay }
6935e65e175bSOded Gabbay
gaudi_handle_qman_err_generic(struct hl_device * hdev,const char * qm_name,u64 qman_base,u32 qid_base,u64 * event_mask)6936e65e175bSOded Gabbay static void gaudi_handle_qman_err_generic(struct hl_device *hdev,
6937e65e175bSOded Gabbay const char *qm_name,
6938e65e175bSOded Gabbay u64 qman_base,
6939e65e175bSOded Gabbay u32 qid_base,
6940e65e175bSOded Gabbay u64 *event_mask)
6941e65e175bSOded Gabbay {
6942e65e175bSOded Gabbay u32 i, j, glbl_sts_val, arb_err_val, glbl_sts_clr_val;
6943e65e175bSOded Gabbay u64 glbl_sts_addr, arb_err_addr;
6944e65e175bSOded Gabbay char reg_desc[32];
6945e65e175bSOded Gabbay
6946e65e175bSOded Gabbay glbl_sts_addr = qman_base + (mmTPC0_QM_GLBL_STS1_0 - mmTPC0_QM_BASE);
6947e65e175bSOded Gabbay arb_err_addr = qman_base + (mmTPC0_QM_ARB_ERR_CAUSE - mmTPC0_QM_BASE);
6948e65e175bSOded Gabbay
6949e65e175bSOded Gabbay /* Iterate through all stream GLBL_STS1 registers + Lower CP */
6950e65e175bSOded Gabbay for (i = 0 ; i < QMAN_STREAMS + 1 ; i++) {
6951e65e175bSOded Gabbay glbl_sts_clr_val = 0;
6952e65e175bSOded Gabbay glbl_sts_val = RREG32(glbl_sts_addr + 4 * i);
6953e65e175bSOded Gabbay
6954e65e175bSOded Gabbay if (!glbl_sts_val)
6955e65e175bSOded Gabbay continue;
6956e65e175bSOded Gabbay
6957e65e175bSOded Gabbay if (i == QMAN_STREAMS)
6958e65e175bSOded Gabbay snprintf(reg_desc, ARRAY_SIZE(reg_desc), "LowerCP");
6959e65e175bSOded Gabbay else
6960e65e175bSOded Gabbay snprintf(reg_desc, ARRAY_SIZE(reg_desc), "stream%u", i);
6961e65e175bSOded Gabbay
6962e65e175bSOded Gabbay for (j = 0 ; j < GAUDI_NUM_OF_QM_ERR_CAUSE ; j++) {
6963e65e175bSOded Gabbay if (glbl_sts_val & BIT(j)) {
6964e65e175bSOded Gabbay dev_err_ratelimited(hdev->dev,
6965e65e175bSOded Gabbay "%s %s. err cause: %s\n",
6966e65e175bSOded Gabbay qm_name, reg_desc,
6967e65e175bSOded Gabbay gaudi_qman_error_cause[j]);
6968e65e175bSOded Gabbay glbl_sts_clr_val |= BIT(j);
6969e65e175bSOded Gabbay }
6970e65e175bSOded Gabbay }
6971e65e175bSOded Gabbay /* check for undefined opcode */
6972e65e175bSOded Gabbay if (glbl_sts_val & TPC0_QM_GLBL_STS1_CP_UNDEF_CMD_ERR_MASK &&
6973e65e175bSOded Gabbay hdev->captured_err_info.undef_opcode.write_enable) {
6974e65e175bSOded Gabbay memset(&hdev->captured_err_info.undef_opcode, 0,
6975e65e175bSOded Gabbay sizeof(hdev->captured_err_info.undef_opcode));
6976e65e175bSOded Gabbay
6977e65e175bSOded Gabbay hdev->captured_err_info.undef_opcode.write_enable = false;
6978e65e175bSOded Gabbay *event_mask |= HL_NOTIFIER_EVENT_UNDEFINED_OPCODE;
6979e65e175bSOded Gabbay }
6980e65e175bSOded Gabbay
6981e65e175bSOded Gabbay /* Write 1 clear errors */
6982e65e175bSOded Gabbay if (!hdev->stop_on_err)
6983e65e175bSOded Gabbay WREG32(glbl_sts_addr + 4 * i, glbl_sts_clr_val);
6984e65e175bSOded Gabbay else
6985e65e175bSOded Gabbay handle_qman_data_on_err(hdev, qid_base, i, qman_base, *event_mask);
6986e65e175bSOded Gabbay }
6987e65e175bSOded Gabbay
6988e65e175bSOded Gabbay arb_err_val = RREG32(arb_err_addr);
6989e65e175bSOded Gabbay
6990e65e175bSOded Gabbay if (!arb_err_val)
6991e65e175bSOded Gabbay return;
6992e65e175bSOded Gabbay
6993e65e175bSOded Gabbay for (j = 0 ; j < GAUDI_NUM_OF_QM_ARB_ERR_CAUSE ; j++) {
6994e65e175bSOded Gabbay if (arb_err_val & BIT(j)) {
6995e65e175bSOded Gabbay dev_err_ratelimited(hdev->dev,
6996e65e175bSOded Gabbay "%s ARB_ERR. err cause: %s\n",
6997e65e175bSOded Gabbay qm_name,
6998e65e175bSOded Gabbay gaudi_qman_arb_error_cause[j]);
6999e65e175bSOded Gabbay }
7000e65e175bSOded Gabbay }
7001e65e175bSOded Gabbay }
7002e65e175bSOded Gabbay
gaudi_print_sm_sei_info(struct hl_device * hdev,u16 event_type,struct hl_eq_sm_sei_data * sei_data)7003e65e175bSOded Gabbay static void gaudi_print_sm_sei_info(struct hl_device *hdev, u16 event_type,
7004e65e175bSOded Gabbay struct hl_eq_sm_sei_data *sei_data)
7005e65e175bSOded Gabbay {
7006e65e175bSOded Gabbay u32 index = event_type - GAUDI_EVENT_DMA_IF_SEI_0;
7007e65e175bSOded Gabbay
7008e65e175bSOded Gabbay /* Flip the bits as the enum is ordered in the opposite way */
7009e65e175bSOded Gabbay index = (index ^ 0x3) & 0x3;
7010e65e175bSOded Gabbay
7011e65e175bSOded Gabbay switch (sei_data->sei_cause) {
7012e65e175bSOded Gabbay case SM_SEI_SO_OVERFLOW:
7013e65e175bSOded Gabbay dev_err_ratelimited(hdev->dev,
7014e65e175bSOded Gabbay "%s SEI Error: SOB Group %u overflow/underflow",
7015e65e175bSOded Gabbay gaudi_sync_manager_names[index],
7016e65e175bSOded Gabbay le32_to_cpu(sei_data->sei_log));
7017e65e175bSOded Gabbay break;
7018e65e175bSOded Gabbay case SM_SEI_LBW_4B_UNALIGNED:
7019e65e175bSOded Gabbay dev_err_ratelimited(hdev->dev,
7020e65e175bSOded Gabbay "%s SEI Error: Unaligned 4B LBW access, monitor agent address low - %#x",
7021e65e175bSOded Gabbay gaudi_sync_manager_names[index],
7022e65e175bSOded Gabbay le32_to_cpu(sei_data->sei_log));
7023e65e175bSOded Gabbay break;
7024e65e175bSOded Gabbay case SM_SEI_AXI_RESPONSE_ERR:
7025e65e175bSOded Gabbay dev_err_ratelimited(hdev->dev,
7026e65e175bSOded Gabbay "%s SEI Error: AXI ID %u response error",
7027e65e175bSOded Gabbay gaudi_sync_manager_names[index],
7028e65e175bSOded Gabbay le32_to_cpu(sei_data->sei_log));
7029e65e175bSOded Gabbay break;
7030e65e175bSOded Gabbay default:
7031e65e175bSOded Gabbay dev_err_ratelimited(hdev->dev, "Unknown SM SEI cause %u",
7032e65e175bSOded Gabbay le32_to_cpu(sei_data->sei_log));
7033e65e175bSOded Gabbay break;
7034e65e175bSOded Gabbay }
7035e65e175bSOded Gabbay }
7036e65e175bSOded Gabbay
gaudi_handle_ecc_event(struct hl_device * hdev,u16 event_type,struct hl_eq_ecc_data * ecc_data)7037e65e175bSOded Gabbay static void gaudi_handle_ecc_event(struct hl_device *hdev, u16 event_type,
7038e65e175bSOded Gabbay struct hl_eq_ecc_data *ecc_data)
7039e65e175bSOded Gabbay {
7040e65e175bSOded Gabbay struct ecc_info_extract_params params;
7041e65e175bSOded Gabbay u64 ecc_address = 0, ecc_syndrom = 0;
7042e65e175bSOded Gabbay u8 index, memory_wrapper_idx = 0;
7043e65e175bSOded Gabbay bool extract_info_from_fw;
7044e65e175bSOded Gabbay int rc;
7045e65e175bSOded Gabbay
7046e65e175bSOded Gabbay if (hdev->asic_prop.fw_security_enabled) {
7047e65e175bSOded Gabbay extract_info_from_fw = true;
7048e65e175bSOded Gabbay goto extract_ecc_info;
7049e65e175bSOded Gabbay }
7050e65e175bSOded Gabbay
7051e65e175bSOded Gabbay switch (event_type) {
7052e65e175bSOded Gabbay case GAUDI_EVENT_PCIE_CORE_SERR ... GAUDI_EVENT_PCIE_PHY_DERR:
7053e65e175bSOded Gabbay case GAUDI_EVENT_DMA0_SERR_ECC ... GAUDI_EVENT_MMU_DERR:
7054e65e175bSOded Gabbay extract_info_from_fw = true;
7055e65e175bSOded Gabbay break;
7056e65e175bSOded Gabbay case GAUDI_EVENT_TPC0_SERR ... GAUDI_EVENT_TPC7_SERR:
7057e65e175bSOded Gabbay index = event_type - GAUDI_EVENT_TPC0_SERR;
7058e65e175bSOded Gabbay params.block_address = mmTPC0_CFG_BASE + index * TPC_CFG_OFFSET;
7059e65e175bSOded Gabbay params.num_memories = 90;
7060e65e175bSOded Gabbay params.derr = false;
7061e65e175bSOded Gabbay extract_info_from_fw = false;
7062e65e175bSOded Gabbay break;
7063e65e175bSOded Gabbay case GAUDI_EVENT_TPC0_DERR ... GAUDI_EVENT_TPC7_DERR:
7064e65e175bSOded Gabbay index = event_type - GAUDI_EVENT_TPC0_DERR;
7065e65e175bSOded Gabbay params.block_address =
7066e65e175bSOded Gabbay mmTPC0_CFG_BASE + index * TPC_CFG_OFFSET;
7067e65e175bSOded Gabbay params.num_memories = 90;
7068e65e175bSOded Gabbay params.derr = true;
7069e65e175bSOded Gabbay extract_info_from_fw = false;
7070e65e175bSOded Gabbay break;
7071e65e175bSOded Gabbay case GAUDI_EVENT_MME0_ACC_SERR:
7072e65e175bSOded Gabbay case GAUDI_EVENT_MME1_ACC_SERR:
7073e65e175bSOded Gabbay case GAUDI_EVENT_MME2_ACC_SERR:
7074e65e175bSOded Gabbay case GAUDI_EVENT_MME3_ACC_SERR:
7075e65e175bSOded Gabbay index = (event_type - GAUDI_EVENT_MME0_ACC_SERR) / 4;
7076e65e175bSOded Gabbay params.block_address = mmMME0_ACC_BASE + index * MME_ACC_OFFSET;
7077e65e175bSOded Gabbay params.num_memories = 128;
7078e65e175bSOded Gabbay params.derr = false;
7079e65e175bSOded Gabbay extract_info_from_fw = false;
7080e65e175bSOded Gabbay break;
7081e65e175bSOded Gabbay case GAUDI_EVENT_MME0_ACC_DERR:
7082e65e175bSOded Gabbay case GAUDI_EVENT_MME1_ACC_DERR:
7083e65e175bSOded Gabbay case GAUDI_EVENT_MME2_ACC_DERR:
7084e65e175bSOded Gabbay case GAUDI_EVENT_MME3_ACC_DERR:
7085e65e175bSOded Gabbay index = (event_type - GAUDI_EVENT_MME0_ACC_DERR) / 4;
7086e65e175bSOded Gabbay params.block_address = mmMME0_ACC_BASE + index * MME_ACC_OFFSET;
7087e65e175bSOded Gabbay params.num_memories = 128;
7088e65e175bSOded Gabbay params.derr = true;
7089e65e175bSOded Gabbay extract_info_from_fw = false;
7090e65e175bSOded Gabbay break;
7091e65e175bSOded Gabbay case GAUDI_EVENT_MME0_SBAB_SERR:
7092e65e175bSOded Gabbay case GAUDI_EVENT_MME1_SBAB_SERR:
7093e65e175bSOded Gabbay case GAUDI_EVENT_MME2_SBAB_SERR:
7094e65e175bSOded Gabbay case GAUDI_EVENT_MME3_SBAB_SERR:
7095e65e175bSOded Gabbay index = (event_type - GAUDI_EVENT_MME0_SBAB_SERR) / 4;
7096e65e175bSOded Gabbay params.block_address =
7097e65e175bSOded Gabbay mmMME0_SBAB_BASE + index * MME_ACC_OFFSET;
7098e65e175bSOded Gabbay params.num_memories = 33;
7099e65e175bSOded Gabbay params.derr = false;
7100e65e175bSOded Gabbay extract_info_from_fw = false;
7101e65e175bSOded Gabbay break;
7102e65e175bSOded Gabbay case GAUDI_EVENT_MME0_SBAB_DERR:
7103e65e175bSOded Gabbay case GAUDI_EVENT_MME1_SBAB_DERR:
7104e65e175bSOded Gabbay case GAUDI_EVENT_MME2_SBAB_DERR:
7105e65e175bSOded Gabbay case GAUDI_EVENT_MME3_SBAB_DERR:
7106e65e175bSOded Gabbay index = (event_type - GAUDI_EVENT_MME0_SBAB_DERR) / 4;
7107e65e175bSOded Gabbay params.block_address =
7108e65e175bSOded Gabbay mmMME0_SBAB_BASE + index * MME_ACC_OFFSET;
7109e65e175bSOded Gabbay params.num_memories = 33;
7110e65e175bSOded Gabbay params.derr = true;
7111e65e175bSOded Gabbay extract_info_from_fw = false;
7112e65e175bSOded Gabbay break;
7113e65e175bSOded Gabbay default:
7114e65e175bSOded Gabbay return;
7115e65e175bSOded Gabbay }
7116e65e175bSOded Gabbay
7117e65e175bSOded Gabbay extract_ecc_info:
7118e65e175bSOded Gabbay if (extract_info_from_fw) {
7119e65e175bSOded Gabbay ecc_address = le64_to_cpu(ecc_data->ecc_address);
7120e65e175bSOded Gabbay ecc_syndrom = le64_to_cpu(ecc_data->ecc_syndrom);
7121e65e175bSOded Gabbay memory_wrapper_idx = ecc_data->memory_wrapper_idx;
7122e65e175bSOded Gabbay } else {
7123e65e175bSOded Gabbay rc = gaudi_extract_ecc_info(hdev, ¶ms, &ecc_address,
7124e65e175bSOded Gabbay &ecc_syndrom, &memory_wrapper_idx);
7125e65e175bSOded Gabbay if (rc)
7126e65e175bSOded Gabbay return;
7127e65e175bSOded Gabbay }
7128e65e175bSOded Gabbay
7129e65e175bSOded Gabbay dev_err(hdev->dev,
7130e65e175bSOded Gabbay "ECC error detected. address: %#llx. Syndrom: %#llx. block id %u\n",
7131e65e175bSOded Gabbay ecc_address, ecc_syndrom, memory_wrapper_idx);
7132e65e175bSOded Gabbay }
7133e65e175bSOded Gabbay
gaudi_handle_qman_err(struct hl_device * hdev,u16 event_type,u64 * event_mask)7134e65e175bSOded Gabbay static void gaudi_handle_qman_err(struct hl_device *hdev, u16 event_type, u64 *event_mask)
7135e65e175bSOded Gabbay {
7136e65e175bSOded Gabbay u64 qman_base;
7137e65e175bSOded Gabbay char desc[32];
7138e65e175bSOded Gabbay u32 qid_base;
7139e65e175bSOded Gabbay u8 index;
7140e65e175bSOded Gabbay
7141e65e175bSOded Gabbay switch (event_type) {
7142e65e175bSOded Gabbay case GAUDI_EVENT_TPC0_QM ... GAUDI_EVENT_TPC7_QM:
7143e65e175bSOded Gabbay index = event_type - GAUDI_EVENT_TPC0_QM;
7144e65e175bSOded Gabbay qid_base = GAUDI_QUEUE_ID_TPC_0_0 + index * QMAN_STREAMS;
7145e65e175bSOded Gabbay qman_base = mmTPC0_QM_BASE + index * TPC_QMAN_OFFSET;
7146e65e175bSOded Gabbay snprintf(desc, ARRAY_SIZE(desc), "%s%d", "TPC_QM", index);
7147e65e175bSOded Gabbay break;
7148e65e175bSOded Gabbay case GAUDI_EVENT_MME0_QM ... GAUDI_EVENT_MME2_QM:
7149e65e175bSOded Gabbay if (event_type == GAUDI_EVENT_MME0_QM) {
7150e65e175bSOded Gabbay index = 0;
7151e65e175bSOded Gabbay qid_base = GAUDI_QUEUE_ID_MME_0_0;
7152e65e175bSOded Gabbay } else { /* event_type == GAUDI_EVENT_MME2_QM */
7153e65e175bSOded Gabbay index = 2;
7154e65e175bSOded Gabbay qid_base = GAUDI_QUEUE_ID_MME_1_0;
7155e65e175bSOded Gabbay }
7156e65e175bSOded Gabbay qman_base = mmMME0_QM_BASE + index * MME_QMAN_OFFSET;
7157e65e175bSOded Gabbay snprintf(desc, ARRAY_SIZE(desc), "%s%d", "MME_QM", index);
7158e65e175bSOded Gabbay break;
7159e65e175bSOded Gabbay case GAUDI_EVENT_DMA0_QM ... GAUDI_EVENT_DMA7_QM:
7160e65e175bSOded Gabbay index = event_type - GAUDI_EVENT_DMA0_QM;
7161e65e175bSOded Gabbay qid_base = GAUDI_QUEUE_ID_DMA_0_0 + index * QMAN_STREAMS;
7162e65e175bSOded Gabbay /* skip GAUDI_QUEUE_ID_CPU_PQ if necessary */
7163e65e175bSOded Gabbay if (index > 1)
7164e65e175bSOded Gabbay qid_base++;
7165e65e175bSOded Gabbay qman_base = mmDMA0_QM_BASE + index * DMA_QMAN_OFFSET;
7166e65e175bSOded Gabbay snprintf(desc, ARRAY_SIZE(desc), "%s%d", "DMA_QM", index);
7167e65e175bSOded Gabbay break;
7168e65e175bSOded Gabbay case GAUDI_EVENT_NIC0_QM0:
7169e65e175bSOded Gabbay qid_base = GAUDI_QUEUE_ID_NIC_0_0;
7170e65e175bSOded Gabbay qman_base = mmNIC0_QM0_BASE;
7171e65e175bSOded Gabbay snprintf(desc, ARRAY_SIZE(desc), "NIC0_QM0");
7172e65e175bSOded Gabbay break;
7173e65e175bSOded Gabbay case GAUDI_EVENT_NIC0_QM1:
7174e65e175bSOded Gabbay qid_base = GAUDI_QUEUE_ID_NIC_1_0;
7175e65e175bSOded Gabbay qman_base = mmNIC0_QM1_BASE;
7176e65e175bSOded Gabbay snprintf(desc, ARRAY_SIZE(desc), "NIC0_QM1");
7177e65e175bSOded Gabbay break;
7178e65e175bSOded Gabbay case GAUDI_EVENT_NIC1_QM0:
7179e65e175bSOded Gabbay qid_base = GAUDI_QUEUE_ID_NIC_2_0;
7180e65e175bSOded Gabbay qman_base = mmNIC1_QM0_BASE;
7181e65e175bSOded Gabbay snprintf(desc, ARRAY_SIZE(desc), "NIC1_QM0");
7182e65e175bSOded Gabbay break;
7183e65e175bSOded Gabbay case GAUDI_EVENT_NIC1_QM1:
7184e65e175bSOded Gabbay qid_base = GAUDI_QUEUE_ID_NIC_3_0;
7185e65e175bSOded Gabbay qman_base = mmNIC1_QM1_BASE;
7186e65e175bSOded Gabbay snprintf(desc, ARRAY_SIZE(desc), "NIC1_QM1");
7187e65e175bSOded Gabbay break;
7188e65e175bSOded Gabbay case GAUDI_EVENT_NIC2_QM0:
7189e65e175bSOded Gabbay qid_base = GAUDI_QUEUE_ID_NIC_4_0;
7190e65e175bSOded Gabbay qman_base = mmNIC2_QM0_BASE;
7191e65e175bSOded Gabbay snprintf(desc, ARRAY_SIZE(desc), "NIC2_QM0");
7192e65e175bSOded Gabbay break;
7193e65e175bSOded Gabbay case GAUDI_EVENT_NIC2_QM1:
7194e65e175bSOded Gabbay qid_base = GAUDI_QUEUE_ID_NIC_5_0;
7195e65e175bSOded Gabbay qman_base = mmNIC2_QM1_BASE;
7196e65e175bSOded Gabbay snprintf(desc, ARRAY_SIZE(desc), "NIC2_QM1");
7197e65e175bSOded Gabbay break;
7198e65e175bSOded Gabbay case GAUDI_EVENT_NIC3_QM0:
7199e65e175bSOded Gabbay qid_base = GAUDI_QUEUE_ID_NIC_6_0;
7200e65e175bSOded Gabbay qman_base = mmNIC3_QM0_BASE;
7201e65e175bSOded Gabbay snprintf(desc, ARRAY_SIZE(desc), "NIC3_QM0");
7202e65e175bSOded Gabbay break;
7203e65e175bSOded Gabbay case GAUDI_EVENT_NIC3_QM1:
7204e65e175bSOded Gabbay qid_base = GAUDI_QUEUE_ID_NIC_7_0;
7205e65e175bSOded Gabbay qman_base = mmNIC3_QM1_BASE;
7206e65e175bSOded Gabbay snprintf(desc, ARRAY_SIZE(desc), "NIC3_QM1");
7207e65e175bSOded Gabbay break;
7208e65e175bSOded Gabbay case GAUDI_EVENT_NIC4_QM0:
7209e65e175bSOded Gabbay qid_base = GAUDI_QUEUE_ID_NIC_8_0;
7210e65e175bSOded Gabbay qman_base = mmNIC4_QM0_BASE;
7211e65e175bSOded Gabbay snprintf(desc, ARRAY_SIZE(desc), "NIC4_QM0");
7212e65e175bSOded Gabbay break;
7213e65e175bSOded Gabbay case GAUDI_EVENT_NIC4_QM1:
7214e65e175bSOded Gabbay qid_base = GAUDI_QUEUE_ID_NIC_9_0;
7215e65e175bSOded Gabbay qman_base = mmNIC4_QM1_BASE;
7216e65e175bSOded Gabbay snprintf(desc, ARRAY_SIZE(desc), "NIC4_QM1");
7217e65e175bSOded Gabbay break;
7218e65e175bSOded Gabbay default:
7219e65e175bSOded Gabbay return;
7220e65e175bSOded Gabbay }
7221e65e175bSOded Gabbay
7222e65e175bSOded Gabbay gaudi_handle_qman_err_generic(hdev, desc, qman_base, qid_base, event_mask);
7223e65e175bSOded Gabbay }
7224e65e175bSOded Gabbay
gaudi_print_irq_info(struct hl_device * hdev,u16 event_type,bool check_razwi,u64 * event_mask)7225e65e175bSOded Gabbay static void gaudi_print_irq_info(struct hl_device *hdev, u16 event_type,
7226e65e175bSOded Gabbay bool check_razwi, u64 *event_mask)
7227e65e175bSOded Gabbay {
7228e65e175bSOded Gabbay bool is_read = false, is_write = false;
7229e65e175bSOded Gabbay u16 engine_id[2], num_of_razwi_eng = 0;
7230e65e175bSOded Gabbay char desc[64] = "";
7231e65e175bSOded Gabbay u64 razwi_addr = 0;
7232e65e175bSOded Gabbay u8 razwi_flags = 0;
7233e65e175bSOded Gabbay
7234e65e175bSOded Gabbay /*
7235e65e175bSOded Gabbay * Init engine id by default as not valid and only if razwi initiated from engine with
7236e65e175bSOded Gabbay * engine id it will get valid value.
72374b9c2d36SKoby Elbaz */
7238e65e175bSOded Gabbay engine_id[0] = HL_RAZWI_NA_ENG_ID;
7239e65e175bSOded Gabbay engine_id[1] = HL_RAZWI_NA_ENG_ID;
7240e65e175bSOded Gabbay
7241e65e175bSOded Gabbay gaudi_get_event_desc(event_type, desc, sizeof(desc));
7242e65e175bSOded Gabbay dev_err_ratelimited(hdev->dev, "Received H/W interrupt %d [\"%s\"]\n",
7243e65e175bSOded Gabbay event_type, desc);
7244e65e175bSOded Gabbay
7245e65e175bSOded Gabbay if (check_razwi) {
7246e65e175bSOded Gabbay gaudi_print_and_get_razwi_info(hdev, &engine_id[0], &engine_id[1], &is_read,
7247e65e175bSOded Gabbay &is_write);
7248e65e175bSOded Gabbay gaudi_print_and_get_mmu_error_info(hdev, &razwi_addr, event_mask);
7249e65e175bSOded Gabbay
7250e65e175bSOded Gabbay if (is_read)
7251e65e175bSOded Gabbay razwi_flags |= HL_RAZWI_READ;
7252e65e175bSOded Gabbay if (is_write)
7253e65e175bSOded Gabbay razwi_flags |= HL_RAZWI_WRITE;
7254e65e175bSOded Gabbay
7255e65e175bSOded Gabbay if (engine_id[0] != HL_RAZWI_NA_ENG_ID) {
72564b9c2d36SKoby Elbaz if (engine_id[1] != HL_RAZWI_NA_ENG_ID)
7257e65e175bSOded Gabbay num_of_razwi_eng = 2;
7258e65e175bSOded Gabbay else
7259e65e175bSOded Gabbay num_of_razwi_eng = 1;
7260e65e175bSOded Gabbay }
7261e65e175bSOded Gabbay
7262e65e175bSOded Gabbay if (razwi_flags)
7263e65e175bSOded Gabbay hl_handle_razwi(hdev, razwi_addr, engine_id, num_of_razwi_eng,
7264e65e175bSOded Gabbay razwi_flags, event_mask);
7265e65e175bSOded Gabbay }
7266e65e175bSOded Gabbay }
7267e65e175bSOded Gabbay
gaudi_print_out_of_sync_info(struct hl_device * hdev,struct cpucp_pkt_sync_err * sync_err)7268e65e175bSOded Gabbay static void gaudi_print_out_of_sync_info(struct hl_device *hdev,
7269e65e175bSOded Gabbay struct cpucp_pkt_sync_err *sync_err)
7270e65e175bSOded Gabbay {
7271e65e175bSOded Gabbay struct hl_hw_queue *q = &hdev->kernel_queues[GAUDI_QUEUE_ID_CPU_PQ];
7272e65e175bSOded Gabbay
72734b9c2d36SKoby Elbaz dev_err(hdev->dev, "Out of sync with FW, FW: pi=%u, ci=%u, LKD: pi=%u, ci=%d\n",
72744b9c2d36SKoby Elbaz le32_to_cpu(sync_err->pi), le32_to_cpu(sync_err->ci), q->pi, atomic_read(&q->ci));
72754b9c2d36SKoby Elbaz }
7276e65e175bSOded Gabbay
gaudi_print_fw_alive_info(struct hl_device * hdev,struct hl_eq_fw_alive * fw_alive)7277e65e175bSOded Gabbay static void gaudi_print_fw_alive_info(struct hl_device *hdev,
7278e65e175bSOded Gabbay struct hl_eq_fw_alive *fw_alive)
7279e65e175bSOded Gabbay {
7280e65e175bSOded Gabbay dev_err(hdev->dev,
7281e65e175bSOded Gabbay "FW alive report: severity=%s, process_id=%u, thread_id=%u, uptime=%llu seconds\n",
7282e65e175bSOded Gabbay (fw_alive->severity == FW_ALIVE_SEVERITY_MINOR) ? "Minor" : "Critical",
7283e65e175bSOded Gabbay le32_to_cpu(fw_alive->process_id),
7284e65e175bSOded Gabbay le32_to_cpu(fw_alive->thread_id),
7285e65e175bSOded Gabbay le64_to_cpu(fw_alive->uptime_seconds));
7286e65e175bSOded Gabbay }
7287e65e175bSOded Gabbay
gaudi_print_nic_axi_irq_info(struct hl_device * hdev,u16 event_type,void * data)7288e65e175bSOded Gabbay static void gaudi_print_nic_axi_irq_info(struct hl_device *hdev, u16 event_type,
7289e65e175bSOded Gabbay void *data)
7290e65e175bSOded Gabbay {
7291e65e175bSOded Gabbay char desc[64] = "", *type;
7292e65e175bSOded Gabbay struct eq_nic_sei_event *eq_nic_sei = data;
7293e65e175bSOded Gabbay u16 nic_id = event_type - GAUDI_EVENT_NIC_SEI_0;
7294e65e175bSOded Gabbay
7295e65e175bSOded Gabbay switch (eq_nic_sei->axi_error_cause) {
7296e65e175bSOded Gabbay case RXB:
7297e65e175bSOded Gabbay type = "RXB";
7298e65e175bSOded Gabbay break;
7299e65e175bSOded Gabbay case RXE:
7300e65e175bSOded Gabbay type = "RXE";
7301e65e175bSOded Gabbay break;
7302e65e175bSOded Gabbay case TXS:
7303e65e175bSOded Gabbay type = "TXS";
7304e65e175bSOded Gabbay break;
7305e65e175bSOded Gabbay case TXE:
7306e65e175bSOded Gabbay type = "TXE";
7307e65e175bSOded Gabbay break;
7308e65e175bSOded Gabbay case QPC_RESP:
7309e65e175bSOded Gabbay type = "QPC_RESP";
7310e65e175bSOded Gabbay break;
7311e65e175bSOded Gabbay case NON_AXI_ERR:
7312e65e175bSOded Gabbay type = "NON_AXI_ERR";
7313e65e175bSOded Gabbay break;
7314e65e175bSOded Gabbay case TMR:
7315e65e175bSOded Gabbay type = "TMR";
7316e65e175bSOded Gabbay break;
7317e65e175bSOded Gabbay default:
7318e65e175bSOded Gabbay dev_err(hdev->dev, "unknown NIC AXI cause %d\n",
7319e65e175bSOded Gabbay eq_nic_sei->axi_error_cause);
7320e65e175bSOded Gabbay type = "N/A";
7321e65e175bSOded Gabbay break;
7322e65e175bSOded Gabbay }
7323e65e175bSOded Gabbay
7324e65e175bSOded Gabbay snprintf(desc, sizeof(desc), "NIC%d_%s%d", nic_id, type,
7325e65e175bSOded Gabbay eq_nic_sei->id);
7326e65e175bSOded Gabbay dev_err_ratelimited(hdev->dev, "Received H/W interrupt %d [\"%s\"]\n",
7327e65e175bSOded Gabbay event_type, desc);
7328e65e175bSOded Gabbay }
7329e65e175bSOded Gabbay
gaudi_compute_reset_late_init(struct hl_device * hdev)7330e65e175bSOded Gabbay static int gaudi_compute_reset_late_init(struct hl_device *hdev)
7331e65e175bSOded Gabbay {
7332e65e175bSOded Gabbay /* GAUDI doesn't support any reset except hard-reset */
7333e65e175bSOded Gabbay return -EPERM;
7334e65e175bSOded Gabbay }
7335e65e175bSOded Gabbay
gaudi_hbm_read_interrupts(struct hl_device * hdev,int device,struct hl_eq_hbm_ecc_data * hbm_ecc_data)7336e65e175bSOded Gabbay static int gaudi_hbm_read_interrupts(struct hl_device *hdev, int device,
7337e65e175bSOded Gabbay struct hl_eq_hbm_ecc_data *hbm_ecc_data)
7338e65e175bSOded Gabbay {
7339e65e175bSOded Gabbay u32 base, val, val2, wr_par, rd_par, ca_par, derr, serr, type, ch;
7340e65e175bSOded Gabbay int rc = 0;
7341e65e175bSOded Gabbay
7342e65e175bSOded Gabbay if (hdev->asic_prop.fw_app_cpu_boot_dev_sts0 &
7343e65e175bSOded Gabbay CPU_BOOT_DEV_STS0_HBM_ECC_EN) {
7344e65e175bSOded Gabbay if (!hbm_ecc_data) {
7345e65e175bSOded Gabbay dev_err(hdev->dev, "No FW ECC data");
7346e65e175bSOded Gabbay return 0;
7347e65e175bSOded Gabbay }
7348e65e175bSOded Gabbay
7349e65e175bSOded Gabbay wr_par = FIELD_GET(CPUCP_PKT_HBM_ECC_INFO_WR_PAR_MASK,
7350e65e175bSOded Gabbay le32_to_cpu(hbm_ecc_data->hbm_ecc_info));
7351e65e175bSOded Gabbay rd_par = FIELD_GET(CPUCP_PKT_HBM_ECC_INFO_RD_PAR_MASK,
7352e65e175bSOded Gabbay le32_to_cpu(hbm_ecc_data->hbm_ecc_info));
7353e65e175bSOded Gabbay ca_par = FIELD_GET(CPUCP_PKT_HBM_ECC_INFO_CA_PAR_MASK,
7354e65e175bSOded Gabbay le32_to_cpu(hbm_ecc_data->hbm_ecc_info));
7355e65e175bSOded Gabbay derr = FIELD_GET(CPUCP_PKT_HBM_ECC_INFO_DERR_MASK,
7356e65e175bSOded Gabbay le32_to_cpu(hbm_ecc_data->hbm_ecc_info));
7357e65e175bSOded Gabbay serr = FIELD_GET(CPUCP_PKT_HBM_ECC_INFO_SERR_MASK,
7358e65e175bSOded Gabbay le32_to_cpu(hbm_ecc_data->hbm_ecc_info));
7359e65e175bSOded Gabbay type = FIELD_GET(CPUCP_PKT_HBM_ECC_INFO_TYPE_MASK,
7360e65e175bSOded Gabbay le32_to_cpu(hbm_ecc_data->hbm_ecc_info));
7361e65e175bSOded Gabbay ch = FIELD_GET(CPUCP_PKT_HBM_ECC_INFO_HBM_CH_MASK,
7362e65e175bSOded Gabbay le32_to_cpu(hbm_ecc_data->hbm_ecc_info));
7363e65e175bSOded Gabbay
7364e65e175bSOded Gabbay dev_err(hdev->dev,
7365e65e175bSOded Gabbay "HBM%d pc%d interrupts info: WR_PAR=%d, RD_PAR=%d, CA_PAR=%d, SERR=%d, DERR=%d\n",
7366e65e175bSOded Gabbay device, ch, wr_par, rd_par, ca_par, serr, derr);
7367e65e175bSOded Gabbay dev_err(hdev->dev,
7368e65e175bSOded Gabbay "HBM%d pc%d ECC info: 1ST_ERR_ADDR=0x%x, 1ST_ERR_TYPE=%d, SEC_CONT_CNT=%u, SEC_CNT=%d, DEC_CNT=%d\n",
7369e65e175bSOded Gabbay device, ch, hbm_ecc_data->first_addr, type,
7370e65e175bSOded Gabbay hbm_ecc_data->sec_cont_cnt, hbm_ecc_data->sec_cnt,
7371e65e175bSOded Gabbay hbm_ecc_data->dec_cnt);
7372e65e175bSOded Gabbay return 0;
7373e65e175bSOded Gabbay }
7374e65e175bSOded Gabbay
7375e65e175bSOded Gabbay if (hdev->asic_prop.fw_security_enabled) {
7376e65e175bSOded Gabbay dev_info(hdev->dev, "Cannot access MC regs for ECC data while security is enabled\n");
7377e65e175bSOded Gabbay return 0;
7378e65e175bSOded Gabbay }
7379e65e175bSOded Gabbay
7380e65e175bSOded Gabbay base = GAUDI_HBM_CFG_BASE + device * GAUDI_HBM_CFG_OFFSET;
7381e65e175bSOded Gabbay for (ch = 0 ; ch < GAUDI_HBM_CHANNELS ; ch++) {
7382e65e175bSOded Gabbay val = RREG32_MASK(base + ch * 0x1000 + 0x06C, 0x0000FFFF);
7383e65e175bSOded Gabbay val = (val & 0xFF) | ((val >> 8) & 0xFF);
7384e65e175bSOded Gabbay if (val) {
7385e65e175bSOded Gabbay rc = -EIO;
7386e65e175bSOded Gabbay dev_err(hdev->dev,
7387e65e175bSOded Gabbay "HBM%d pc%d interrupts info: WR_PAR=%d, RD_PAR=%d, CA_PAR=%d, SERR=%d, DERR=%d\n",
7388e65e175bSOded Gabbay device, ch * 2, val & 0x1, (val >> 1) & 0x1,
7389e65e175bSOded Gabbay (val >> 2) & 0x1, (val >> 3) & 0x1,
7390e65e175bSOded Gabbay (val >> 4) & 0x1);
7391e65e175bSOded Gabbay
7392e65e175bSOded Gabbay val2 = RREG32(base + ch * 0x1000 + 0x060);
7393e65e175bSOded Gabbay dev_err(hdev->dev,
7394e65e175bSOded Gabbay "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",
7395e65e175bSOded Gabbay device, ch * 2,
7396e65e175bSOded Gabbay RREG32(base + ch * 0x1000 + 0x064),
7397e65e175bSOded Gabbay (val2 & 0x200) >> 9, (val2 & 0xFC00) >> 10,
7398e65e175bSOded Gabbay (val2 & 0xFF0000) >> 16,
7399e65e175bSOded Gabbay (val2 & 0xFF000000) >> 24);
7400e65e175bSOded Gabbay }
7401e65e175bSOded Gabbay
7402e65e175bSOded Gabbay val = RREG32_MASK(base + ch * 0x1000 + 0x07C, 0x0000FFFF);
7403e65e175bSOded Gabbay val = (val & 0xFF) | ((val >> 8) & 0xFF);
7404e65e175bSOded Gabbay if (val) {
7405e65e175bSOded Gabbay rc = -EIO;
7406e65e175bSOded Gabbay dev_err(hdev->dev,
7407e65e175bSOded Gabbay "HBM%d pc%d interrupts info: WR_PAR=%d, RD_PAR=%d, CA_PAR=%d, SERR=%d, DERR=%d\n",
7408e65e175bSOded Gabbay device, ch * 2 + 1, val & 0x1, (val >> 1) & 0x1,
7409e65e175bSOded Gabbay (val >> 2) & 0x1, (val >> 3) & 0x1,
7410e65e175bSOded Gabbay (val >> 4) & 0x1);
7411e65e175bSOded Gabbay
7412e65e175bSOded Gabbay val2 = RREG32(base + ch * 0x1000 + 0x070);
7413e65e175bSOded Gabbay dev_err(hdev->dev,
7414e65e175bSOded Gabbay "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",
7415e65e175bSOded Gabbay device, ch * 2 + 1,
7416e65e175bSOded Gabbay RREG32(base + ch * 0x1000 + 0x074),
7417e65e175bSOded Gabbay (val2 & 0x200) >> 9, (val2 & 0xFC00) >> 10,
7418e65e175bSOded Gabbay (val2 & 0xFF0000) >> 16,
7419e65e175bSOded Gabbay (val2 & 0xFF000000) >> 24);
7420e65e175bSOded Gabbay }
7421e65e175bSOded Gabbay
7422e65e175bSOded Gabbay /* Clear interrupts */
7423e65e175bSOded Gabbay RMWREG32(base + (ch * 0x1000) + 0x060, 0x1C8, 0x1FF);
7424e65e175bSOded Gabbay RMWREG32(base + (ch * 0x1000) + 0x070, 0x1C8, 0x1FF);
7425e65e175bSOded Gabbay WREG32(base + (ch * 0x1000) + 0x06C, 0x1F1F);
7426e65e175bSOded Gabbay WREG32(base + (ch * 0x1000) + 0x07C, 0x1F1F);
7427e65e175bSOded Gabbay RMWREG32(base + (ch * 0x1000) + 0x060, 0x0, 0xF);
7428e65e175bSOded Gabbay RMWREG32(base + (ch * 0x1000) + 0x070, 0x0, 0xF);
7429e65e175bSOded Gabbay }
7430e65e175bSOded Gabbay
7431e65e175bSOded Gabbay val = RREG32(base + 0x8F30);
7432e65e175bSOded Gabbay val2 = RREG32(base + 0x8F34);
7433e65e175bSOded Gabbay if (val | val2) {
7434e65e175bSOded Gabbay rc = -EIO;
7435e65e175bSOded Gabbay dev_err(hdev->dev,
7436e65e175bSOded Gabbay "HBM %d MC SRAM SERR info: Reg 0x8F30=0x%x, Reg 0x8F34=0x%x\n",
7437e65e175bSOded Gabbay device, val, val2);
7438e65e175bSOded Gabbay }
7439e65e175bSOded Gabbay val = RREG32(base + 0x8F40);
7440e65e175bSOded Gabbay val2 = RREG32(base + 0x8F44);
7441e65e175bSOded Gabbay if (val | val2) {
7442e65e175bSOded Gabbay rc = -EIO;
7443e65e175bSOded Gabbay dev_err(hdev->dev,
7444e65e175bSOded Gabbay "HBM %d MC SRAM DERR info: Reg 0x8F40=0x%x, Reg 0x8F44=0x%x\n",
7445e65e175bSOded Gabbay device, val, val2);
7446e65e175bSOded Gabbay }
7447e65e175bSOded Gabbay
7448e65e175bSOded Gabbay return rc;
7449e65e175bSOded Gabbay }
7450e65e175bSOded Gabbay
gaudi_hbm_event_to_dev(u16 hbm_event_type)7451e65e175bSOded Gabbay static int gaudi_hbm_event_to_dev(u16 hbm_event_type)
7452e65e175bSOded Gabbay {
7453e65e175bSOded Gabbay switch (hbm_event_type) {
7454e65e175bSOded Gabbay case GAUDI_EVENT_HBM0_SPI_0:
7455e65e175bSOded Gabbay case GAUDI_EVENT_HBM0_SPI_1:
7456e65e175bSOded Gabbay return 0;
7457e65e175bSOded Gabbay case GAUDI_EVENT_HBM1_SPI_0:
7458e65e175bSOded Gabbay case GAUDI_EVENT_HBM1_SPI_1:
7459e65e175bSOded Gabbay return 1;
7460e65e175bSOded Gabbay case GAUDI_EVENT_HBM2_SPI_0:
7461e65e175bSOded Gabbay case GAUDI_EVENT_HBM2_SPI_1:
7462e65e175bSOded Gabbay return 2;
7463e65e175bSOded Gabbay case GAUDI_EVENT_HBM3_SPI_0:
7464e65e175bSOded Gabbay case GAUDI_EVENT_HBM3_SPI_1:
7465e65e175bSOded Gabbay return 3;
7466e65e175bSOded Gabbay default:
7467e65e175bSOded Gabbay break;
7468e65e175bSOded Gabbay }
7469e65e175bSOded Gabbay
7470e65e175bSOded Gabbay /* Should never happen */
7471e65e175bSOded Gabbay return 0;
7472e65e175bSOded Gabbay }
7473e65e175bSOded Gabbay
gaudi_tpc_read_interrupts(struct hl_device * hdev,u8 tpc_id,char * interrupt_name)7474e65e175bSOded Gabbay static bool gaudi_tpc_read_interrupts(struct hl_device *hdev, u8 tpc_id,
7475e65e175bSOded Gabbay char *interrupt_name)
7476e65e175bSOded Gabbay {
7477e65e175bSOded Gabbay u32 tpc_offset = tpc_id * TPC_CFG_OFFSET, tpc_interrupts_cause, i;
7478e65e175bSOded Gabbay bool soft_reset_required = false;
7479e65e175bSOded Gabbay
7480e65e175bSOded Gabbay tpc_interrupts_cause = RREG32(mmTPC0_CFG_TPC_INTR_CAUSE + tpc_offset) &
7481e65e175bSOded Gabbay TPC0_CFG_TPC_INTR_CAUSE_CAUSE_MASK;
7482e65e175bSOded Gabbay
7483e65e175bSOded Gabbay for (i = 0 ; i < GAUDI_NUM_OF_TPC_INTR_CAUSE ; i++)
7484e65e175bSOded Gabbay if (tpc_interrupts_cause & BIT(i)) {
7485e65e175bSOded Gabbay dev_err_ratelimited(hdev->dev,
7486e65e175bSOded Gabbay "TPC%d_%s interrupt cause: %s\n",
7487e65e175bSOded Gabbay tpc_id, interrupt_name,
7488e65e175bSOded Gabbay gaudi_tpc_interrupts_cause[i]);
7489e65e175bSOded Gabbay /* If this is QM error, we need to soft-reset */
7490e65e175bSOded Gabbay if (i == 15)
7491e65e175bSOded Gabbay soft_reset_required = true;
7492e65e175bSOded Gabbay }
7493e65e175bSOded Gabbay
7494e65e175bSOded Gabbay /* Clear interrupts */
7495e65e175bSOded Gabbay WREG32(mmTPC0_CFG_TPC_INTR_CAUSE + tpc_offset, 0);
7496e65e175bSOded Gabbay
7497e65e175bSOded Gabbay return soft_reset_required;
7498e65e175bSOded Gabbay }
7499e65e175bSOded Gabbay
tpc_dec_event_to_tpc_id(u16 tpc_dec_event_type)7500e65e175bSOded Gabbay static int tpc_dec_event_to_tpc_id(u16 tpc_dec_event_type)
7501e65e175bSOded Gabbay {
7502e65e175bSOded Gabbay return (tpc_dec_event_type - GAUDI_EVENT_TPC0_DEC) >> 1;
7503e65e175bSOded Gabbay }
7504e65e175bSOded Gabbay
tpc_krn_event_to_tpc_id(u16 tpc_dec_event_type)7505e65e175bSOded Gabbay static int tpc_krn_event_to_tpc_id(u16 tpc_dec_event_type)
7506e65e175bSOded Gabbay {
7507e65e175bSOded Gabbay return (tpc_dec_event_type - GAUDI_EVENT_TPC0_KRN_ERR) / 6;
7508e65e175bSOded Gabbay }
7509e65e175bSOded Gabbay
gaudi_print_clk_change_info(struct hl_device * hdev,u16 event_type,u64 * event_mask)7510e65e175bSOded Gabbay static void gaudi_print_clk_change_info(struct hl_device *hdev, u16 event_type, u64 *event_mask)
7511e65e175bSOded Gabbay {
7512e65e175bSOded Gabbay ktime_t zero_time = ktime_set(0, 0);
7513e65e175bSOded Gabbay
7514e65e175bSOded Gabbay mutex_lock(&hdev->clk_throttling.lock);
7515e65e175bSOded Gabbay
7516e65e175bSOded Gabbay switch (event_type) {
7517e65e175bSOded Gabbay case GAUDI_EVENT_FIX_POWER_ENV_S:
7518e65e175bSOded Gabbay hdev->clk_throttling.current_reason |= HL_CLK_THROTTLE_POWER;
7519e65e175bSOded Gabbay hdev->clk_throttling.aggregated_reason |= HL_CLK_THROTTLE_POWER;
7520e65e175bSOded Gabbay hdev->clk_throttling.timestamp[HL_CLK_THROTTLE_TYPE_POWER].start = ktime_get();
7521e65e175bSOded Gabbay hdev->clk_throttling.timestamp[HL_CLK_THROTTLE_TYPE_POWER].end = zero_time;
7522e65e175bSOded Gabbay dev_info_ratelimited(hdev->dev,
7523e65e175bSOded Gabbay "Clock throttling due to power consumption\n");
7524e65e175bSOded Gabbay break;
7525e65e175bSOded Gabbay
7526e65e175bSOded Gabbay case GAUDI_EVENT_FIX_POWER_ENV_E:
7527e65e175bSOded Gabbay hdev->clk_throttling.current_reason &= ~HL_CLK_THROTTLE_POWER;
7528e65e175bSOded Gabbay hdev->clk_throttling.timestamp[HL_CLK_THROTTLE_TYPE_POWER].end = ktime_get();
7529e65e175bSOded Gabbay dev_info_ratelimited(hdev->dev,
7530e65e175bSOded Gabbay "Power envelop is safe, back to optimal clock\n");
7531e65e175bSOded Gabbay break;
7532e65e175bSOded Gabbay
7533e65e175bSOded Gabbay case GAUDI_EVENT_FIX_THERMAL_ENV_S:
7534e65e175bSOded Gabbay hdev->clk_throttling.current_reason |= HL_CLK_THROTTLE_THERMAL;
7535e65e175bSOded Gabbay hdev->clk_throttling.aggregated_reason |= HL_CLK_THROTTLE_THERMAL;
7536e65e175bSOded Gabbay hdev->clk_throttling.timestamp[HL_CLK_THROTTLE_TYPE_THERMAL].start = ktime_get();
7537e65e175bSOded Gabbay hdev->clk_throttling.timestamp[HL_CLK_THROTTLE_TYPE_THERMAL].end = zero_time;
7538e65e175bSOded Gabbay *event_mask |= HL_NOTIFIER_EVENT_USER_ENGINE_ERR;
7539e65e175bSOded Gabbay dev_info_ratelimited(hdev->dev,
7540e65e175bSOded Gabbay "Clock throttling due to overheating\n");
7541e65e175bSOded Gabbay break;
7542e65e175bSOded Gabbay
7543e65e175bSOded Gabbay case GAUDI_EVENT_FIX_THERMAL_ENV_E:
7544e65e175bSOded Gabbay hdev->clk_throttling.current_reason &= ~HL_CLK_THROTTLE_THERMAL;
7545e65e175bSOded Gabbay hdev->clk_throttling.timestamp[HL_CLK_THROTTLE_TYPE_THERMAL].end = ktime_get();
7546e65e175bSOded Gabbay *event_mask |= HL_NOTIFIER_EVENT_USER_ENGINE_ERR;
7547e65e175bSOded Gabbay dev_info_ratelimited(hdev->dev,
7548e65e175bSOded Gabbay "Thermal envelop is safe, back to optimal clock\n");
7549e65e175bSOded Gabbay break;
7550e65e175bSOded Gabbay
7551e65e175bSOded Gabbay default:
7552e65e175bSOded Gabbay dev_err(hdev->dev, "Received invalid clock change event %d\n",
7553e65e175bSOded Gabbay event_type);
7554e65e175bSOded Gabbay break;
7555e65e175bSOded Gabbay }
7556e65e175bSOded Gabbay
7557e65e175bSOded Gabbay mutex_unlock(&hdev->clk_throttling.lock);
7558e65e175bSOded Gabbay }
7559e65e175bSOded Gabbay
gaudi_handle_eqe(struct hl_device * hdev,struct hl_eq_entry * eq_entry)7560e65e175bSOded Gabbay static void gaudi_handle_eqe(struct hl_device *hdev, struct hl_eq_entry *eq_entry)
7561e65e175bSOded Gabbay {
7562e65e175bSOded Gabbay struct gaudi_device *gaudi = hdev->asic_specific;
7563e65e175bSOded Gabbay struct hl_info_fw_err_info fw_err_info;
7564e65e175bSOded Gabbay u64 data = le64_to_cpu(eq_entry->data[0]), event_mask = 0;
7565e65e175bSOded Gabbay u32 ctl = le32_to_cpu(eq_entry->hdr.ctl);
7566e65e175bSOded Gabbay u32 fw_fatal_err_flag = 0, flags = 0;
7567e65e175bSOded Gabbay u16 event_type = ((ctl & EQ_CTL_EVENT_TYPE_MASK)
7568e65e175bSOded Gabbay >> EQ_CTL_EVENT_TYPE_SHIFT);
7569e65e175bSOded Gabbay bool reset_required, reset_direct = false;
7570e65e175bSOded Gabbay u8 cause;
7571e65e175bSOded Gabbay int rc;
7572e65e175bSOded Gabbay
7573e65e175bSOded Gabbay if (event_type >= GAUDI_EVENT_SIZE) {
7574313e9f63SMoti Haimovski dev_err(hdev->dev, "Event type %u exceeds maximum of %u",
7575e65e175bSOded Gabbay event_type, GAUDI_EVENT_SIZE - 1);
7576e65e175bSOded Gabbay return;
7577e65e175bSOded Gabbay }
7578e65e175bSOded Gabbay
7579e65e175bSOded Gabbay gaudi->events_stat[event_type]++;
7580e65e175bSOded Gabbay gaudi->events_stat_aggregate[event_type]++;
7581e65e175bSOded Gabbay
7582e65e175bSOded Gabbay switch (event_type) {
7583e65e175bSOded Gabbay case GAUDI_EVENT_PCIE_CORE_DERR:
7584e65e175bSOded Gabbay case GAUDI_EVENT_PCIE_IF_DERR:
7585e65e175bSOded Gabbay case GAUDI_EVENT_PCIE_PHY_DERR:
7586e65e175bSOded Gabbay case GAUDI_EVENT_TPC0_DERR ... GAUDI_EVENT_TPC7_DERR:
7587e65e175bSOded Gabbay case GAUDI_EVENT_MME0_ACC_DERR:
7588e65e175bSOded Gabbay case GAUDI_EVENT_MME0_SBAB_DERR:
7589e65e175bSOded Gabbay case GAUDI_EVENT_MME1_ACC_DERR:
7590e65e175bSOded Gabbay case GAUDI_EVENT_MME1_SBAB_DERR:
7591e65e175bSOded Gabbay case GAUDI_EVENT_MME2_ACC_DERR:
7592e65e175bSOded Gabbay case GAUDI_EVENT_MME2_SBAB_DERR:
7593e65e175bSOded Gabbay case GAUDI_EVENT_MME3_ACC_DERR:
7594e65e175bSOded Gabbay case GAUDI_EVENT_MME3_SBAB_DERR:
7595e65e175bSOded Gabbay case GAUDI_EVENT_DMA0_DERR_ECC ... GAUDI_EVENT_DMA7_DERR_ECC:
7596e65e175bSOded Gabbay fallthrough;
7597e65e175bSOded Gabbay case GAUDI_EVENT_CPU_IF_ECC_DERR:
7598e65e175bSOded Gabbay case GAUDI_EVENT_PSOC_MEM_DERR:
7599e65e175bSOded Gabbay case GAUDI_EVENT_PSOC_CORESIGHT_DERR:
7600e65e175bSOded Gabbay case GAUDI_EVENT_SRAM0_DERR ... GAUDI_EVENT_SRAM28_DERR:
7601e65e175bSOded Gabbay case GAUDI_EVENT_NIC0_DERR ... GAUDI_EVENT_NIC4_DERR:
7602e65e175bSOded Gabbay case GAUDI_EVENT_DMA_IF0_DERR ... GAUDI_EVENT_DMA_IF3_DERR:
7603e65e175bSOded Gabbay case GAUDI_EVENT_HBM_0_DERR ... GAUDI_EVENT_HBM_3_DERR:
7604e65e175bSOded Gabbay case GAUDI_EVENT_MMU_DERR:
7605e65e175bSOded Gabbay case GAUDI_EVENT_NIC0_CS_DBG_DERR ... GAUDI_EVENT_NIC4_CS_DBG_DERR:
7606e65e175bSOded Gabbay gaudi_print_irq_info(hdev, event_type, true, &event_mask);
7607e65e175bSOded Gabbay gaudi_handle_ecc_event(hdev, event_type, &eq_entry->ecc_data);
7608e65e175bSOded Gabbay event_mask |= HL_NOTIFIER_EVENT_GENERAL_HW_ERR;
7609e65e175bSOded Gabbay fw_fatal_err_flag = HL_DRV_RESET_FW_FATAL_ERR;
7610e65e175bSOded Gabbay goto reset_device;
7611e65e175bSOded Gabbay
7612e65e175bSOded Gabbay case GAUDI_EVENT_GIC500:
7613e65e175bSOded Gabbay case GAUDI_EVENT_AXI_ECC:
7614e65e175bSOded Gabbay case GAUDI_EVENT_L2_RAM_ECC:
7615e65e175bSOded Gabbay case GAUDI_EVENT_PLL0 ... GAUDI_EVENT_PLL17:
7616e65e175bSOded Gabbay gaudi_print_irq_info(hdev, event_type, false, &event_mask);
7617e65e175bSOded Gabbay fw_fatal_err_flag = HL_DRV_RESET_FW_FATAL_ERR;
7618e65e175bSOded Gabbay event_mask |= HL_NOTIFIER_EVENT_GENERAL_HW_ERR;
7619e65e175bSOded Gabbay goto reset_device;
7620e65e175bSOded Gabbay
7621e65e175bSOded Gabbay case GAUDI_EVENT_HBM0_SPI_0:
7622e65e175bSOded Gabbay case GAUDI_EVENT_HBM1_SPI_0:
7623e65e175bSOded Gabbay case GAUDI_EVENT_HBM2_SPI_0:
7624e65e175bSOded Gabbay case GAUDI_EVENT_HBM3_SPI_0:
7625e65e175bSOded Gabbay gaudi_print_irq_info(hdev, event_type, false, &event_mask);
7626e65e175bSOded Gabbay gaudi_hbm_read_interrupts(hdev,
7627e65e175bSOded Gabbay gaudi_hbm_event_to_dev(event_type),
7628e65e175bSOded Gabbay &eq_entry->hbm_ecc_data);
7629e65e175bSOded Gabbay fw_fatal_err_flag = HL_DRV_RESET_FW_FATAL_ERR;
7630e65e175bSOded Gabbay event_mask |= HL_NOTIFIER_EVENT_GENERAL_HW_ERR;
7631e65e175bSOded Gabbay goto reset_device;
7632e65e175bSOded Gabbay
7633e65e175bSOded Gabbay case GAUDI_EVENT_HBM0_SPI_1:
7634e65e175bSOded Gabbay case GAUDI_EVENT_HBM1_SPI_1:
7635e65e175bSOded Gabbay case GAUDI_EVENT_HBM2_SPI_1:
7636e65e175bSOded Gabbay case GAUDI_EVENT_HBM3_SPI_1:
7637e65e175bSOded Gabbay gaudi_print_irq_info(hdev, event_type, false, &event_mask);
7638e65e175bSOded Gabbay gaudi_hbm_read_interrupts(hdev,
7639e65e175bSOded Gabbay gaudi_hbm_event_to_dev(event_type),
7640e65e175bSOded Gabbay &eq_entry->hbm_ecc_data);
7641e65e175bSOded Gabbay hl_fw_unmask_irq(hdev, event_type);
7642e65e175bSOded Gabbay event_mask |= HL_NOTIFIER_EVENT_GENERAL_HW_ERR;
7643e65e175bSOded Gabbay break;
7644e65e175bSOded Gabbay
7645e65e175bSOded Gabbay case GAUDI_EVENT_TPC0_DEC:
7646e65e175bSOded Gabbay case GAUDI_EVENT_TPC1_DEC:
7647e65e175bSOded Gabbay case GAUDI_EVENT_TPC2_DEC:
7648e65e175bSOded Gabbay case GAUDI_EVENT_TPC3_DEC:
7649e65e175bSOded Gabbay case GAUDI_EVENT_TPC4_DEC:
7650e65e175bSOded Gabbay case GAUDI_EVENT_TPC5_DEC:
7651e65e175bSOded Gabbay case GAUDI_EVENT_TPC6_DEC:
7652e65e175bSOded Gabbay case GAUDI_EVENT_TPC7_DEC:
7653e65e175bSOded Gabbay /* In TPC DEC event, notify on TPC assertion. While there isn't
7654e65e175bSOded Gabbay * a specific event for assertion yet, the FW generates TPC DEC event.
7655e65e175bSOded Gabbay * The SW upper layer will inspect an internal mapped area to indicate
7656e65e175bSOded Gabbay * if the event is a TPC Assertion or a "real" TPC DEC.
7657e65e175bSOded Gabbay */
7658e65e175bSOded Gabbay event_mask |= HL_NOTIFIER_EVENT_TPC_ASSERT;
7659e65e175bSOded Gabbay gaudi_print_irq_info(hdev, event_type, true, &event_mask);
7660e65e175bSOded Gabbay reset_required = gaudi_tpc_read_interrupts(hdev,
7661e65e175bSOded Gabbay tpc_dec_event_to_tpc_id(event_type),
7662e65e175bSOded Gabbay "AXI_SLV_DEC_Error");
7663e65e175bSOded Gabbay event_mask |= HL_NOTIFIER_EVENT_USER_ENGINE_ERR;
7664e65e175bSOded Gabbay if (reset_required) {
7665e65e175bSOded Gabbay dev_err(hdev->dev, "reset required due to %s\n",
7666e65e175bSOded Gabbay gaudi_irq_map_table[event_type].name);
7667e65e175bSOded Gabbay
7668e65e175bSOded Gabbay reset_direct = true;
7669e65e175bSOded Gabbay goto reset_device;
7670e65e175bSOded Gabbay } else {
7671e65e175bSOded Gabbay hl_fw_unmask_irq(hdev, event_type);
7672e65e175bSOded Gabbay event_mask |= HL_NOTIFIER_EVENT_DEVICE_RESET;
7673e65e175bSOded Gabbay }
7674e65e175bSOded Gabbay break;
7675e65e175bSOded Gabbay
7676e65e175bSOded Gabbay case GAUDI_EVENT_TPC0_KRN_ERR:
7677e65e175bSOded Gabbay case GAUDI_EVENT_TPC1_KRN_ERR:
7678e65e175bSOded Gabbay case GAUDI_EVENT_TPC2_KRN_ERR:
7679e65e175bSOded Gabbay case GAUDI_EVENT_TPC3_KRN_ERR:
7680e65e175bSOded Gabbay case GAUDI_EVENT_TPC4_KRN_ERR:
7681e65e175bSOded Gabbay case GAUDI_EVENT_TPC5_KRN_ERR:
7682e65e175bSOded Gabbay case GAUDI_EVENT_TPC6_KRN_ERR:
7683e65e175bSOded Gabbay case GAUDI_EVENT_TPC7_KRN_ERR:
7684e65e175bSOded Gabbay gaudi_print_irq_info(hdev, event_type, true, &event_mask);
7685e65e175bSOded Gabbay reset_required = gaudi_tpc_read_interrupts(hdev,
7686e65e175bSOded Gabbay tpc_krn_event_to_tpc_id(event_type),
7687e65e175bSOded Gabbay "KRN_ERR");
7688e65e175bSOded Gabbay event_mask |= HL_NOTIFIER_EVENT_USER_ENGINE_ERR;
7689e65e175bSOded Gabbay if (reset_required) {
7690e65e175bSOded Gabbay dev_err(hdev->dev, "reset required due to %s\n",
7691e65e175bSOded Gabbay gaudi_irq_map_table[event_type].name);
7692e65e175bSOded Gabbay
7693e65e175bSOded Gabbay reset_direct = true;
7694e65e175bSOded Gabbay goto reset_device;
7695e65e175bSOded Gabbay } else {
7696e65e175bSOded Gabbay hl_fw_unmask_irq(hdev, event_type);
7697e65e175bSOded Gabbay event_mask |= HL_NOTIFIER_EVENT_DEVICE_RESET;
7698e65e175bSOded Gabbay }
7699e65e175bSOded Gabbay break;
7700e65e175bSOded Gabbay
7701e65e175bSOded Gabbay case GAUDI_EVENT_PCIE_CORE_SERR:
7702e65e175bSOded Gabbay case GAUDI_EVENT_PCIE_IF_SERR:
7703e65e175bSOded Gabbay case GAUDI_EVENT_PCIE_PHY_SERR:
7704e65e175bSOded Gabbay case GAUDI_EVENT_TPC0_SERR ... GAUDI_EVENT_TPC7_SERR:
7705e65e175bSOded Gabbay case GAUDI_EVENT_MME0_ACC_SERR:
7706e65e175bSOded Gabbay case GAUDI_EVENT_MME0_SBAB_SERR:
7707e65e175bSOded Gabbay case GAUDI_EVENT_MME1_ACC_SERR:
7708e65e175bSOded Gabbay case GAUDI_EVENT_MME1_SBAB_SERR:
7709e65e175bSOded Gabbay case GAUDI_EVENT_MME2_ACC_SERR:
7710e65e175bSOded Gabbay case GAUDI_EVENT_MME2_SBAB_SERR:
7711e65e175bSOded Gabbay case GAUDI_EVENT_MME3_ACC_SERR:
7712e65e175bSOded Gabbay case GAUDI_EVENT_MME3_SBAB_SERR:
7713e65e175bSOded Gabbay case GAUDI_EVENT_DMA0_SERR_ECC ... GAUDI_EVENT_DMA7_SERR_ECC:
7714e65e175bSOded Gabbay case GAUDI_EVENT_CPU_IF_ECC_SERR:
7715e65e175bSOded Gabbay case GAUDI_EVENT_PSOC_MEM_SERR:
7716e65e175bSOded Gabbay case GAUDI_EVENT_PSOC_CORESIGHT_SERR:
7717e65e175bSOded Gabbay case GAUDI_EVENT_SRAM0_SERR ... GAUDI_EVENT_SRAM28_SERR:
7718e65e175bSOded Gabbay case GAUDI_EVENT_NIC0_SERR ... GAUDI_EVENT_NIC4_SERR:
7719e65e175bSOded Gabbay case GAUDI_EVENT_DMA_IF0_SERR ... GAUDI_EVENT_DMA_IF3_SERR:
7720e65e175bSOded Gabbay case GAUDI_EVENT_HBM_0_SERR ... GAUDI_EVENT_HBM_3_SERR:
7721e65e175bSOded Gabbay fallthrough;
7722e65e175bSOded Gabbay case GAUDI_EVENT_MMU_SERR:
7723e65e175bSOded Gabbay gaudi_print_irq_info(hdev, event_type, true, &event_mask);
7724e65e175bSOded Gabbay gaudi_handle_ecc_event(hdev, event_type, &eq_entry->ecc_data);
7725e65e175bSOded Gabbay hl_fw_unmask_irq(hdev, event_type);
7726e65e175bSOded Gabbay event_mask |= HL_NOTIFIER_EVENT_GENERAL_HW_ERR;
7727e65e175bSOded Gabbay break;
7728e65e175bSOded Gabbay
7729e65e175bSOded Gabbay case GAUDI_EVENT_PCIE_DEC:
7730e65e175bSOded Gabbay case GAUDI_EVENT_CPU_AXI_SPLITTER:
7731e65e175bSOded Gabbay case GAUDI_EVENT_PSOC_AXI_DEC:
7732e65e175bSOded Gabbay case GAUDI_EVENT_PSOC_PRSTN_FALL:
7733e65e175bSOded Gabbay gaudi_print_irq_info(hdev, event_type, true, &event_mask);
7734e65e175bSOded Gabbay hl_fw_unmask_irq(hdev, event_type);
7735e65e175bSOded Gabbay event_mask |= HL_NOTIFIER_EVENT_GENERAL_HW_ERR;
7736e65e175bSOded Gabbay break;
7737e65e175bSOded Gabbay
7738e65e175bSOded Gabbay case GAUDI_EVENT_MMU_PAGE_FAULT:
7739e65e175bSOded Gabbay case GAUDI_EVENT_MMU_WR_PERM:
7740e65e175bSOded Gabbay gaudi_print_irq_info(hdev, event_type, true, &event_mask);
7741e65e175bSOded Gabbay hl_fw_unmask_irq(hdev, event_type);
7742e65e175bSOded Gabbay event_mask |= HL_NOTIFIER_EVENT_USER_ENGINE_ERR;
7743e65e175bSOded Gabbay break;
7744e65e175bSOded Gabbay
7745e65e175bSOded Gabbay case GAUDI_EVENT_MME0_WBC_RSP:
7746e65e175bSOded Gabbay case GAUDI_EVENT_MME0_SBAB0_RSP:
7747e65e175bSOded Gabbay case GAUDI_EVENT_MME1_WBC_RSP:
7748e65e175bSOded Gabbay case GAUDI_EVENT_MME1_SBAB0_RSP:
7749e65e175bSOded Gabbay case GAUDI_EVENT_MME2_WBC_RSP:
7750e65e175bSOded Gabbay case GAUDI_EVENT_MME2_SBAB0_RSP:
7751e65e175bSOded Gabbay case GAUDI_EVENT_MME3_WBC_RSP:
7752e65e175bSOded Gabbay case GAUDI_EVENT_MME3_SBAB0_RSP:
7753e65e175bSOded Gabbay case GAUDI_EVENT_RAZWI_OR_ADC:
7754e65e175bSOded Gabbay case GAUDI_EVENT_MME0_QM ... GAUDI_EVENT_MME2_QM:
7755e65e175bSOded Gabbay case GAUDI_EVENT_DMA0_QM ... GAUDI_EVENT_DMA7_QM:
7756e65e175bSOded Gabbay fallthrough;
7757e65e175bSOded Gabbay case GAUDI_EVENT_NIC0_QM0:
7758e65e175bSOded Gabbay case GAUDI_EVENT_NIC0_QM1:
7759e65e175bSOded Gabbay case GAUDI_EVENT_NIC1_QM0:
7760e65e175bSOded Gabbay case GAUDI_EVENT_NIC1_QM1:
7761e65e175bSOded Gabbay case GAUDI_EVENT_NIC2_QM0:
7762e65e175bSOded Gabbay case GAUDI_EVENT_NIC2_QM1:
7763e65e175bSOded Gabbay case GAUDI_EVENT_NIC3_QM0:
7764e65e175bSOded Gabbay case GAUDI_EVENT_NIC3_QM1:
7765e65e175bSOded Gabbay case GAUDI_EVENT_NIC4_QM0:
7766e65e175bSOded Gabbay case GAUDI_EVENT_NIC4_QM1:
7767e65e175bSOded Gabbay case GAUDI_EVENT_DMA0_CORE ... GAUDI_EVENT_DMA7_CORE:
7768e65e175bSOded Gabbay case GAUDI_EVENT_TPC0_QM ... GAUDI_EVENT_TPC7_QM:
7769e65e175bSOded Gabbay gaudi_print_irq_info(hdev, event_type, true, &event_mask);
7770e65e175bSOded Gabbay gaudi_handle_qman_err(hdev, event_type, &event_mask);
7771e65e175bSOded Gabbay hl_fw_unmask_irq(hdev, event_type);
7772e65e175bSOded Gabbay event_mask |= (HL_NOTIFIER_EVENT_USER_ENGINE_ERR | HL_NOTIFIER_EVENT_DEVICE_RESET);
7773e65e175bSOded Gabbay break;
7774e65e175bSOded Gabbay
7775e65e175bSOded Gabbay case GAUDI_EVENT_RAZWI_OR_ADC_SW:
7776e65e175bSOded Gabbay gaudi_print_irq_info(hdev, event_type, true, &event_mask);
7777e65e175bSOded Gabbay event_mask |= HL_NOTIFIER_EVENT_USER_ENGINE_ERR;
7778e65e175bSOded Gabbay goto reset_device;
7779e65e175bSOded Gabbay
7780e65e175bSOded Gabbay case GAUDI_EVENT_TPC0_BMON_SPMU:
7781e65e175bSOded Gabbay case GAUDI_EVENT_TPC1_BMON_SPMU:
7782e65e175bSOded Gabbay case GAUDI_EVENT_TPC2_BMON_SPMU:
7783e65e175bSOded Gabbay case GAUDI_EVENT_TPC3_BMON_SPMU:
7784e65e175bSOded Gabbay case GAUDI_EVENT_TPC4_BMON_SPMU:
7785e65e175bSOded Gabbay case GAUDI_EVENT_TPC5_BMON_SPMU:
7786e65e175bSOded Gabbay case GAUDI_EVENT_TPC6_BMON_SPMU:
7787e65e175bSOded Gabbay case GAUDI_EVENT_TPC7_BMON_SPMU:
7788e65e175bSOded Gabbay case GAUDI_EVENT_DMA_BM_CH0 ... GAUDI_EVENT_DMA_BM_CH7:
7789e65e175bSOded Gabbay gaudi_print_irq_info(hdev, event_type, false, &event_mask);
7790e65e175bSOded Gabbay hl_fw_unmask_irq(hdev, event_type);
7791e65e175bSOded Gabbay event_mask |= HL_NOTIFIER_EVENT_USER_ENGINE_ERR;
7792e65e175bSOded Gabbay break;
7793e65e175bSOded Gabbay
7794e65e175bSOded Gabbay case GAUDI_EVENT_NIC_SEI_0 ... GAUDI_EVENT_NIC_SEI_4:
7795e65e175bSOded Gabbay gaudi_print_nic_axi_irq_info(hdev, event_type, &data);
7796e65e175bSOded Gabbay hl_fw_unmask_irq(hdev, event_type);
7797e65e175bSOded Gabbay event_mask |= HL_NOTIFIER_EVENT_USER_ENGINE_ERR;
7798e65e175bSOded Gabbay break;
7799e65e175bSOded Gabbay
7800e65e175bSOded Gabbay case GAUDI_EVENT_DMA_IF_SEI_0 ... GAUDI_EVENT_DMA_IF_SEI_3:
7801e65e175bSOded Gabbay gaudi_print_irq_info(hdev, event_type, false, &event_mask);
7802e65e175bSOded Gabbay gaudi_print_sm_sei_info(hdev, event_type,
7803e65e175bSOded Gabbay &eq_entry->sm_sei_data);
7804e65e175bSOded Gabbay rc = hl_state_dump(hdev);
7805e65e175bSOded Gabbay event_mask |= HL_NOTIFIER_EVENT_USER_ENGINE_ERR;
7806e65e175bSOded Gabbay if (rc)
7807e65e175bSOded Gabbay dev_err(hdev->dev,
7808e65e175bSOded Gabbay "Error during system state dump %d\n", rc);
7809e65e175bSOded Gabbay hl_fw_unmask_irq(hdev, event_type);
7810e65e175bSOded Gabbay break;
7811e65e175bSOded Gabbay
7812e65e175bSOded Gabbay case GAUDI_EVENT_STATUS_NIC0_ENG0 ... GAUDI_EVENT_STATUS_NIC4_ENG1:
7813e65e175bSOded Gabbay break;
7814e65e175bSOded Gabbay
7815e65e175bSOded Gabbay case GAUDI_EVENT_FIX_POWER_ENV_S ... GAUDI_EVENT_FIX_THERMAL_ENV_E:
7816e65e175bSOded Gabbay gaudi_print_clk_change_info(hdev, event_type, &event_mask);
7817e65e175bSOded Gabbay hl_fw_unmask_irq(hdev, event_type);
7818e65e175bSOded Gabbay break;
7819e65e175bSOded Gabbay
7820e65e175bSOded Gabbay case GAUDI_EVENT_PSOC_GPIO_U16_0:
7821e65e175bSOded Gabbay cause = le64_to_cpu(eq_entry->data[0]) & 0xFF;
7822e65e175bSOded Gabbay dev_err(hdev->dev,
7823e65e175bSOded Gabbay "Received high temp H/W interrupt %d (cause %d)\n",
7824e65e175bSOded Gabbay event_type, cause);
7825e65e175bSOded Gabbay event_mask |= HL_NOTIFIER_EVENT_USER_ENGINE_ERR;
7826e65e175bSOded Gabbay break;
7827e65e175bSOded Gabbay
7828e65e175bSOded Gabbay case GAUDI_EVENT_DEV_RESET_REQ:
7829e65e175bSOded Gabbay gaudi_print_irq_info(hdev, event_type, false, &event_mask);
7830e65e175bSOded Gabbay event_mask |= HL_NOTIFIER_EVENT_GENERAL_HW_ERR;
7831e65e175bSOded Gabbay goto reset_device;
7832e65e175bSOded Gabbay
7833e65e175bSOded Gabbay case GAUDI_EVENT_PKT_QUEUE_OUT_SYNC:
7834e65e175bSOded Gabbay gaudi_print_irq_info(hdev, event_type, false, &event_mask);
7835e65e175bSOded Gabbay gaudi_print_out_of_sync_info(hdev, &eq_entry->pkt_sync_err);
7836e65e175bSOded Gabbay event_mask |= HL_NOTIFIER_EVENT_GENERAL_HW_ERR;
7837e65e175bSOded Gabbay goto reset_device;
7838e65e175bSOded Gabbay
7839e65e175bSOded Gabbay case GAUDI_EVENT_FW_ALIVE_S:
7840e65e175bSOded Gabbay gaudi_print_irq_info(hdev, event_type, false, &event_mask);
7841e65e175bSOded Gabbay gaudi_print_fw_alive_info(hdev, &eq_entry->fw_alive);
7842e65e175bSOded Gabbay fw_err_info.err_type = HL_INFO_FW_REPORTED_ERR;
7843e65e175bSOded Gabbay fw_err_info.event_id = event_type;
7844e65e175bSOded Gabbay fw_err_info.event_mask = &event_mask;
7845e65e175bSOded Gabbay hl_handle_fw_err(hdev, &fw_err_info);
7846e65e175bSOded Gabbay goto reset_device;
7847e65e175bSOded Gabbay
7848e65e175bSOded Gabbay default:
7849e65e175bSOded Gabbay dev_err(hdev->dev, "Received invalid H/W interrupt %d\n",
7850e65e175bSOded Gabbay event_type);
7851e65e175bSOded Gabbay break;
7852e65e175bSOded Gabbay }
7853313e9f63SMoti Haimovski
7854313e9f63SMoti Haimovski if (event_mask)
7855313e9f63SMoti Haimovski hl_notifier_event_send_all(hdev, event_mask);
7856313e9f63SMoti Haimovski
7857e65e175bSOded Gabbay return;
7858e65e175bSOded Gabbay
7859e65e175bSOded Gabbay reset_device:
7860e65e175bSOded Gabbay reset_required = true;
7861e65e175bSOded Gabbay
7862e65e175bSOded Gabbay if (hdev->asic_prop.fw_security_enabled && !reset_direct) {
7863e65e175bSOded Gabbay flags = HL_DRV_RESET_HARD | HL_DRV_RESET_BYPASS_REQ_TO_FW | fw_fatal_err_flag;
7864e65e175bSOded Gabbay
7865e65e175bSOded Gabbay /* notify on device unavailable while the reset triggered by fw */
7866e65e175bSOded Gabbay event_mask |= (HL_NOTIFIER_EVENT_DEVICE_RESET |
7867e65e175bSOded Gabbay HL_NOTIFIER_EVENT_DEVICE_UNAVAILABLE);
7868e65e175bSOded Gabbay } else if (hdev->hard_reset_on_fw_events) {
7869e65e175bSOded Gabbay flags = HL_DRV_RESET_HARD | HL_DRV_RESET_DELAY | fw_fatal_err_flag;
7870e65e175bSOded Gabbay event_mask |= HL_NOTIFIER_EVENT_DEVICE_RESET;
7871e65e175bSOded Gabbay } else {
7872e65e175bSOded Gabbay reset_required = false;
7873e65e175bSOded Gabbay }
7874e65e175bSOded Gabbay
7875e65e175bSOded Gabbay if (reset_required) {
7876e65e175bSOded Gabbay /* escalate general hw errors to critical/fatal error */
7877e65e175bSOded Gabbay if (event_mask & HL_NOTIFIER_EVENT_GENERAL_HW_ERR)
7878e65e175bSOded Gabbay hl_handle_critical_hw_err(hdev, event_type, &event_mask);
7879e65e175bSOded Gabbay
7880e65e175bSOded Gabbay hl_device_cond_reset(hdev, flags, event_mask);
7881e65e175bSOded Gabbay } else {
7882e65e175bSOded Gabbay hl_fw_unmask_irq(hdev, event_type);
7883e65e175bSOded Gabbay /* Notification on occurred event needs to be sent although reset is not executed */
7884e65e175bSOded Gabbay if (event_mask)
7885e65e175bSOded Gabbay hl_notifier_event_send_all(hdev, event_mask);
7886e65e175bSOded Gabbay }
7887313e9f63SMoti Haimovski }
7888313e9f63SMoti Haimovski
gaudi_get_events_stat(struct hl_device * hdev,bool aggregate,u32 * size)7889313e9f63SMoti Haimovski static void *gaudi_get_events_stat(struct hl_device *hdev, bool aggregate, u32 *size)
7890313e9f63SMoti Haimovski {
7891e65e175bSOded Gabbay struct gaudi_device *gaudi = hdev->asic_specific;
7892e65e175bSOded Gabbay
7893e65e175bSOded Gabbay if (aggregate) {
7894e65e175bSOded Gabbay *size = (u32) sizeof(gaudi->events_stat_aggregate);
7895e65e175bSOded Gabbay return gaudi->events_stat_aggregate;
7896e65e175bSOded Gabbay }
7897e65e175bSOded Gabbay
7898e65e175bSOded Gabbay *size = (u32) sizeof(gaudi->events_stat);
7899e65e175bSOded Gabbay return gaudi->events_stat;
7900e65e175bSOded Gabbay }
7901e65e175bSOded Gabbay
gaudi_mmu_invalidate_cache(struct hl_device * hdev,bool is_hard,u32 flags)7902e65e175bSOded Gabbay static int gaudi_mmu_invalidate_cache(struct hl_device *hdev, bool is_hard, u32 flags)
7903e65e175bSOded Gabbay {
7904e65e175bSOded Gabbay struct gaudi_device *gaudi = hdev->asic_specific;
7905e65e175bSOded Gabbay u32 status, timeout_usec;
7906e65e175bSOded Gabbay int rc;
7907e65e175bSOded Gabbay
7908e65e175bSOded Gabbay if (!(gaudi->hw_cap_initialized & HW_CAP_MMU) ||
7909e65e175bSOded Gabbay hdev->reset_info.hard_reset_pending)
7910e65e175bSOded Gabbay return 0;
7911e65e175bSOded Gabbay
7912e65e175bSOded Gabbay if (hdev->pldm)
7913e65e175bSOded Gabbay timeout_usec = GAUDI_PLDM_MMU_TIMEOUT_USEC;
7914e65e175bSOded Gabbay else
7915e65e175bSOded Gabbay timeout_usec = MMU_CONFIG_TIMEOUT_USEC;
7916e65e175bSOded Gabbay
7917e65e175bSOded Gabbay /* L0 & L1 invalidation */
7918e65e175bSOded Gabbay WREG32(mmSTLB_INV_PS, 3);
7919e65e175bSOded Gabbay WREG32(mmSTLB_CACHE_INV, gaudi->mmu_cache_inv_pi++);
7920e65e175bSOded Gabbay WREG32(mmSTLB_INV_PS, 2);
7921e65e175bSOded Gabbay
7922e65e175bSOded Gabbay rc = hl_poll_timeout(
7923e65e175bSOded Gabbay hdev,
7924e65e175bSOded Gabbay mmSTLB_INV_PS,
7925e65e175bSOded Gabbay status,
7926e65e175bSOded Gabbay !status,
7927e65e175bSOded Gabbay 1000,
7928e65e175bSOded Gabbay timeout_usec);
7929e65e175bSOded Gabbay
7930e65e175bSOded Gabbay WREG32(mmSTLB_INV_SET, 0);
7931e65e175bSOded Gabbay
7932e65e175bSOded Gabbay return rc;
7933e65e175bSOded Gabbay }
7934e65e175bSOded Gabbay
gaudi_mmu_invalidate_cache_range(struct hl_device * hdev,bool is_hard,u32 flags,u32 asid,u64 va,u64 size)7935e65e175bSOded Gabbay static int gaudi_mmu_invalidate_cache_range(struct hl_device *hdev,
7936e65e175bSOded Gabbay bool is_hard, u32 flags,
7937e65e175bSOded Gabbay u32 asid, u64 va, u64 size)
7938e65e175bSOded Gabbay {
7939e65e175bSOded Gabbay /* Treat as invalidate all because there is no range invalidation
7940e65e175bSOded Gabbay * in Gaudi
7941e65e175bSOded Gabbay */
7942e65e175bSOded Gabbay return hdev->asic_funcs->mmu_invalidate_cache(hdev, is_hard, flags);
7943e65e175bSOded Gabbay }
7944e65e175bSOded Gabbay
gaudi_mmu_update_asid_hop0_addr(struct hl_device * hdev,u32 asid,u64 phys_addr)7945e65e175bSOded Gabbay static int gaudi_mmu_update_asid_hop0_addr(struct hl_device *hdev, u32 asid, u64 phys_addr)
7946e65e175bSOded Gabbay {
7947e65e175bSOded Gabbay u32 status, timeout_usec;
7948e65e175bSOded Gabbay int rc;
7949e65e175bSOded Gabbay
7950e65e175bSOded Gabbay if (hdev->pldm)
7951e65e175bSOded Gabbay timeout_usec = GAUDI_PLDM_MMU_TIMEOUT_USEC;
7952e65e175bSOded Gabbay else
7953e65e175bSOded Gabbay timeout_usec = MMU_CONFIG_TIMEOUT_USEC;
7954e65e175bSOded Gabbay
7955e65e175bSOded Gabbay WREG32(MMU_ASID, asid);
7956e65e175bSOded Gabbay WREG32(MMU_HOP0_PA43_12, phys_addr >> MMU_HOP0_PA43_12_SHIFT);
7957e65e175bSOded Gabbay WREG32(MMU_HOP0_PA49_44, phys_addr >> MMU_HOP0_PA49_44_SHIFT);
7958e65e175bSOded Gabbay WREG32(MMU_BUSY, 0x80000000);
7959e65e175bSOded Gabbay
7960e65e175bSOded Gabbay rc = hl_poll_timeout(
7961e65e175bSOded Gabbay hdev,
7962e65e175bSOded Gabbay MMU_BUSY,
7963e65e175bSOded Gabbay status,
7964e65e175bSOded Gabbay !(status & 0x80000000),
7965e65e175bSOded Gabbay 1000,
7966e65e175bSOded Gabbay timeout_usec);
7967e65e175bSOded Gabbay
7968e65e175bSOded Gabbay if (rc) {
7969e65e175bSOded Gabbay dev_err(hdev->dev,
7970e65e175bSOded Gabbay "Timeout during MMU hop0 config of asid %d\n", asid);
7971e65e175bSOded Gabbay return rc;
7972e65e175bSOded Gabbay }
7973e65e175bSOded Gabbay
7974e65e175bSOded Gabbay return 0;
7975e65e175bSOded Gabbay }
7976e65e175bSOded Gabbay
gaudi_send_heartbeat(struct hl_device * hdev)7977e65e175bSOded Gabbay static int gaudi_send_heartbeat(struct hl_device *hdev)
7978e65e175bSOded Gabbay {
7979e65e175bSOded Gabbay struct gaudi_device *gaudi = hdev->asic_specific;
7980e65e175bSOded Gabbay
7981e65e175bSOded Gabbay if (!(gaudi->hw_cap_initialized & HW_CAP_CPU_Q))
7982e65e175bSOded Gabbay return 0;
7983e65e175bSOded Gabbay
7984e65e175bSOded Gabbay return hl_fw_send_heartbeat(hdev);
7985e65e175bSOded Gabbay }
7986e65e175bSOded Gabbay
gaudi_cpucp_info_get(struct hl_device * hdev)7987e65e175bSOded Gabbay static int gaudi_cpucp_info_get(struct hl_device *hdev)
7988e65e175bSOded Gabbay {
7989e65e175bSOded Gabbay struct gaudi_device *gaudi = hdev->asic_specific;
7990e65e175bSOded Gabbay struct asic_fixed_properties *prop = &hdev->asic_prop;
7991e65e175bSOded Gabbay int rc;
7992e65e175bSOded Gabbay
7993e65e175bSOded Gabbay if (!(gaudi->hw_cap_initialized & HW_CAP_CPU_Q))
7994e65e175bSOded Gabbay return 0;
7995e65e175bSOded Gabbay
7996e65e175bSOded Gabbay rc = hl_fw_cpucp_handshake(hdev, mmCPU_BOOT_DEV_STS0,
7997e65e175bSOded Gabbay mmCPU_BOOT_DEV_STS1, mmCPU_BOOT_ERR0,
7998e65e175bSOded Gabbay mmCPU_BOOT_ERR1);
7999e65e175bSOded Gabbay if (rc)
8000e65e175bSOded Gabbay return rc;
8001e65e175bSOded Gabbay
8002e65e175bSOded Gabbay if (!strlen(prop->cpucp_info.card_name))
8003e65e175bSOded Gabbay strncpy(prop->cpucp_info.card_name, GAUDI_DEFAULT_CARD_NAME,
8004e65e175bSOded Gabbay CARD_NAME_MAX_LEN);
8005e65e175bSOded Gabbay
8006e65e175bSOded Gabbay hdev->card_type = le32_to_cpu(hdev->asic_prop.cpucp_info.card_type);
8007e65e175bSOded Gabbay
8008e65e175bSOded Gabbay set_default_power_values(hdev);
8009e65e175bSOded Gabbay
8010e65e175bSOded Gabbay return 0;
8011e65e175bSOded Gabbay }
8012e65e175bSOded Gabbay
gaudi_is_device_idle(struct hl_device * hdev,u64 * mask_arr,u8 mask_len,struct engines_data * e)8013e65e175bSOded Gabbay static bool gaudi_is_device_idle(struct hl_device *hdev, u64 *mask_arr, u8 mask_len,
8014e65e175bSOded Gabbay struct engines_data *e)
8015e65e175bSOded Gabbay {
8016e65e175bSOded Gabbay struct gaudi_device *gaudi = hdev->asic_specific;
8017e65e175bSOded Gabbay const char *fmt = "%-5d%-9s%#-14x%#-12x%#x\n";
8018e65e175bSOded Gabbay const char *mme_slave_fmt = "%-5d%-9s%-14s%-12s%#x\n";
8019e65e175bSOded Gabbay const char *nic_fmt = "%-5d%-9s%#-14x%#x\n";
8020e65e175bSOded Gabbay unsigned long *mask = (unsigned long *)mask_arr;
8021e65e175bSOded Gabbay u32 qm_glbl_sts0, qm_cgm_sts, dma_core_sts0, tpc_cfg_sts, mme_arch_sts;
8022e65e175bSOded Gabbay bool is_idle = true, is_eng_idle, is_slave;
8023e65e175bSOded Gabbay u64 offset;
8024e65e175bSOded Gabbay int i, dma_id, port;
8025e65e175bSOded Gabbay
8026e65e175bSOded Gabbay if (e)
8027e65e175bSOded Gabbay hl_engine_data_sprintf(e,
8028e65e175bSOded Gabbay "\nDMA is_idle QM_GLBL_STS0 QM_CGM_STS DMA_CORE_STS0\n"
8029e65e175bSOded Gabbay "--- ------- ------------ ---------- -------------\n");
8030e65e175bSOded Gabbay
8031e65e175bSOded Gabbay for (i = 0 ; i < DMA_NUMBER_OF_CHNLS ; i++) {
8032e65e175bSOded Gabbay dma_id = gaudi_dma_assignment[i];
8033e65e175bSOded Gabbay offset = dma_id * DMA_QMAN_OFFSET;
8034e65e175bSOded Gabbay
8035e65e175bSOded Gabbay qm_glbl_sts0 = RREG32(mmDMA0_QM_GLBL_STS0 + offset);
8036e65e175bSOded Gabbay qm_cgm_sts = RREG32(mmDMA0_QM_CGM_STS + offset);
8037e65e175bSOded Gabbay dma_core_sts0 = RREG32(mmDMA0_CORE_STS0 + offset);
8038e65e175bSOded Gabbay is_eng_idle = IS_QM_IDLE(qm_glbl_sts0, qm_cgm_sts) &&
8039e65e175bSOded Gabbay IS_DMA_IDLE(dma_core_sts0);
8040e65e175bSOded Gabbay is_idle &= is_eng_idle;
8041e65e175bSOded Gabbay
8042e65e175bSOded Gabbay if (mask && !is_eng_idle)
8043e65e175bSOded Gabbay set_bit(GAUDI_ENGINE_ID_DMA_0 + dma_id, mask);
8044e65e175bSOded Gabbay if (e)
8045e65e175bSOded Gabbay hl_engine_data_sprintf(e, fmt, dma_id,
8046e65e175bSOded Gabbay is_eng_idle ? "Y" : "N", qm_glbl_sts0,
8047e65e175bSOded Gabbay qm_cgm_sts, dma_core_sts0);
8048e65e175bSOded Gabbay }
8049e65e175bSOded Gabbay
8050e65e175bSOded Gabbay if (e)
8051e65e175bSOded Gabbay hl_engine_data_sprintf(e,
8052e65e175bSOded Gabbay "\nTPC is_idle QM_GLBL_STS0 QM_CGM_STS CFG_STATUS\n"
8053e65e175bSOded Gabbay "--- ------- ------------ ---------- ----------\n");
8054e65e175bSOded Gabbay
8055e65e175bSOded Gabbay for (i = 0 ; i < TPC_NUMBER_OF_ENGINES ; i++) {
8056e65e175bSOded Gabbay offset = i * TPC_QMAN_OFFSET;
8057e65e175bSOded Gabbay qm_glbl_sts0 = RREG32(mmTPC0_QM_GLBL_STS0 + offset);
8058e65e175bSOded Gabbay qm_cgm_sts = RREG32(mmTPC0_QM_CGM_STS + offset);
8059e65e175bSOded Gabbay tpc_cfg_sts = RREG32(mmTPC0_CFG_STATUS + offset);
8060e65e175bSOded Gabbay is_eng_idle = IS_QM_IDLE(qm_glbl_sts0, qm_cgm_sts) &&
8061e65e175bSOded Gabbay IS_TPC_IDLE(tpc_cfg_sts);
8062e65e175bSOded Gabbay is_idle &= is_eng_idle;
8063e65e175bSOded Gabbay
8064e65e175bSOded Gabbay if (mask && !is_eng_idle)
8065e65e175bSOded Gabbay set_bit(GAUDI_ENGINE_ID_TPC_0 + i, mask);
8066e65e175bSOded Gabbay if (e)
8067e65e175bSOded Gabbay hl_engine_data_sprintf(e, fmt, i,
8068e65e175bSOded Gabbay is_eng_idle ? "Y" : "N",
8069e65e175bSOded Gabbay qm_glbl_sts0, qm_cgm_sts, tpc_cfg_sts);
8070e65e175bSOded Gabbay }
8071e65e175bSOded Gabbay
8072e65e175bSOded Gabbay if (e)
8073e65e175bSOded Gabbay hl_engine_data_sprintf(e,
8074e65e175bSOded Gabbay "\nMME is_idle QM_GLBL_STS0 QM_CGM_STS ARCH_STATUS\n"
8075e65e175bSOded Gabbay "--- ------- ------------ ---------- -----------\n");
8076e65e175bSOded Gabbay
8077e65e175bSOded Gabbay for (i = 0 ; i < MME_NUMBER_OF_ENGINES ; i++) {
8078e65e175bSOded Gabbay offset = i * MME_QMAN_OFFSET;
8079e65e175bSOded Gabbay mme_arch_sts = RREG32(mmMME0_CTRL_ARCH_STATUS + offset);
8080e65e175bSOded Gabbay is_eng_idle = IS_MME_IDLE(mme_arch_sts);
8081e65e175bSOded Gabbay
8082e65e175bSOded Gabbay /* MME 1 & 3 are slaves, no need to check their QMANs */
8083e65e175bSOded Gabbay is_slave = i % 2;
8084e65e175bSOded Gabbay if (!is_slave) {
8085e65e175bSOded Gabbay qm_glbl_sts0 = RREG32(mmMME0_QM_GLBL_STS0 + offset);
8086e65e175bSOded Gabbay qm_cgm_sts = RREG32(mmMME0_QM_CGM_STS + offset);
8087e65e175bSOded Gabbay is_eng_idle &= IS_QM_IDLE(qm_glbl_sts0, qm_cgm_sts);
8088e65e175bSOded Gabbay }
8089e65e175bSOded Gabbay
8090e65e175bSOded Gabbay is_idle &= is_eng_idle;
8091e65e175bSOded Gabbay
8092e65e175bSOded Gabbay if (mask && !is_eng_idle)
8093e65e175bSOded Gabbay set_bit(GAUDI_ENGINE_ID_MME_0 + i, mask);
8094e65e175bSOded Gabbay if (e) {
8095e65e175bSOded Gabbay if (!is_slave)
8096e65e175bSOded Gabbay hl_engine_data_sprintf(e, fmt, i,
8097e65e175bSOded Gabbay is_eng_idle ? "Y" : "N",
8098e65e175bSOded Gabbay qm_glbl_sts0, qm_cgm_sts, mme_arch_sts);
8099e65e175bSOded Gabbay else
8100e65e175bSOded Gabbay hl_engine_data_sprintf(e, mme_slave_fmt, i,
8101e65e175bSOded Gabbay is_eng_idle ? "Y" : "N", "-",
8102e65e175bSOded Gabbay "-", mme_arch_sts);
8103e65e175bSOded Gabbay }
8104e65e175bSOded Gabbay }
8105e65e175bSOded Gabbay
8106e65e175bSOded Gabbay if (e)
8107e65e175bSOded Gabbay hl_engine_data_sprintf(e,
8108e65e175bSOded Gabbay "\nNIC is_idle QM_GLBL_STS0 QM_CGM_STS\n"
8109e65e175bSOded Gabbay "--- ------- ------------ ----------\n");
8110e65e175bSOded Gabbay
8111e65e175bSOded Gabbay for (i = 0 ; i < (NIC_NUMBER_OF_ENGINES / 2) ; i++) {
8112e65e175bSOded Gabbay offset = i * NIC_MACRO_QMAN_OFFSET;
8113e65e175bSOded Gabbay port = 2 * i;
8114e65e175bSOded Gabbay if (gaudi->hw_cap_initialized & BIT(HW_CAP_NIC_SHIFT + port)) {
8115e65e175bSOded Gabbay qm_glbl_sts0 = RREG32(mmNIC0_QM0_GLBL_STS0 + offset);
8116e65e175bSOded Gabbay qm_cgm_sts = RREG32(mmNIC0_QM0_CGM_STS + offset);
8117e65e175bSOded Gabbay is_eng_idle = IS_QM_IDLE(qm_glbl_sts0, qm_cgm_sts);
8118e65e175bSOded Gabbay is_idle &= is_eng_idle;
8119e65e175bSOded Gabbay
8120e65e175bSOded Gabbay if (mask && !is_eng_idle)
8121e65e175bSOded Gabbay set_bit(GAUDI_ENGINE_ID_NIC_0 + port, mask);
8122e65e175bSOded Gabbay if (e)
8123e65e175bSOded Gabbay hl_engine_data_sprintf(e, nic_fmt, port,
8124e65e175bSOded Gabbay is_eng_idle ? "Y" : "N",
8125e65e175bSOded Gabbay qm_glbl_sts0, qm_cgm_sts);
8126e65e175bSOded Gabbay }
8127e65e175bSOded Gabbay
8128e65e175bSOded Gabbay port = 2 * i + 1;
8129e65e175bSOded Gabbay if (gaudi->hw_cap_initialized & BIT(HW_CAP_NIC_SHIFT + port)) {
8130e65e175bSOded Gabbay qm_glbl_sts0 = RREG32(mmNIC0_QM1_GLBL_STS0 + offset);
8131e65e175bSOded Gabbay qm_cgm_sts = RREG32(mmNIC0_QM1_CGM_STS + offset);
8132e65e175bSOded Gabbay is_eng_idle = IS_QM_IDLE(qm_glbl_sts0, qm_cgm_sts);
8133e65e175bSOded Gabbay is_idle &= is_eng_idle;
8134e65e175bSOded Gabbay
8135e65e175bSOded Gabbay if (mask && !is_eng_idle)
8136e65e175bSOded Gabbay set_bit(GAUDI_ENGINE_ID_NIC_0 + port, mask);
8137e65e175bSOded Gabbay if (e)
8138e65e175bSOded Gabbay hl_engine_data_sprintf(e, nic_fmt, port,
8139e65e175bSOded Gabbay is_eng_idle ? "Y" : "N",
8140e65e175bSOded Gabbay qm_glbl_sts0, qm_cgm_sts);
8141e65e175bSOded Gabbay }
8142e65e175bSOded Gabbay }
8143e65e175bSOded Gabbay
8144e65e175bSOded Gabbay if (e)
8145e65e175bSOded Gabbay hl_engine_data_sprintf(e, "\n");
8146e65e175bSOded Gabbay
8147e65e175bSOded Gabbay return is_idle;
8148e65e175bSOded Gabbay }
8149e65e175bSOded Gabbay
gaudi_hw_queues_lock(struct hl_device * hdev)8150e65e175bSOded Gabbay static void gaudi_hw_queues_lock(struct hl_device *hdev)
8151e65e175bSOded Gabbay __acquires(&gaudi->hw_queues_lock)
8152e65e175bSOded Gabbay {
8153e65e175bSOded Gabbay struct gaudi_device *gaudi = hdev->asic_specific;
8154e65e175bSOded Gabbay
8155e65e175bSOded Gabbay spin_lock(&gaudi->hw_queues_lock);
8156e65e175bSOded Gabbay }
8157e65e175bSOded Gabbay
gaudi_hw_queues_unlock(struct hl_device * hdev)8158e65e175bSOded Gabbay static void gaudi_hw_queues_unlock(struct hl_device *hdev)
8159e65e175bSOded Gabbay __releases(&gaudi->hw_queues_lock)
8160e65e175bSOded Gabbay {
8161e65e175bSOded Gabbay struct gaudi_device *gaudi = hdev->asic_specific;
8162e65e175bSOded Gabbay
8163e65e175bSOded Gabbay spin_unlock(&gaudi->hw_queues_lock);
8164e65e175bSOded Gabbay }
8165e65e175bSOded Gabbay
gaudi_get_pci_id(struct hl_device * hdev)8166e65e175bSOded Gabbay static u32 gaudi_get_pci_id(struct hl_device *hdev)
8167e65e175bSOded Gabbay {
8168e65e175bSOded Gabbay return hdev->pdev->device;
8169e65e175bSOded Gabbay }
8170e65e175bSOded Gabbay
gaudi_get_eeprom_data(struct hl_device * hdev,void * data,size_t max_size)8171e65e175bSOded Gabbay static int gaudi_get_eeprom_data(struct hl_device *hdev, void *data,
8172e65e175bSOded Gabbay size_t max_size)
8173e65e175bSOded Gabbay {
8174e65e175bSOded Gabbay struct gaudi_device *gaudi = hdev->asic_specific;
8175e65e175bSOded Gabbay
8176e65e175bSOded Gabbay if (!(gaudi->hw_cap_initialized & HW_CAP_CPU_Q))
8177e65e175bSOded Gabbay return 0;
8178e65e175bSOded Gabbay
8179e65e175bSOded Gabbay return hl_fw_get_eeprom_data(hdev, data, max_size);
8180e65e175bSOded Gabbay }
8181e65e175bSOded Gabbay
gaudi_get_monitor_dump(struct hl_device * hdev,void * data)8182e65e175bSOded Gabbay static int gaudi_get_monitor_dump(struct hl_device *hdev, void *data)
8183e65e175bSOded Gabbay {
8184e65e175bSOded Gabbay struct gaudi_device *gaudi = hdev->asic_specific;
8185e65e175bSOded Gabbay
8186e65e175bSOded Gabbay if (!(gaudi->hw_cap_initialized & HW_CAP_CPU_Q))
8187e65e175bSOded Gabbay return 0;
8188e65e175bSOded Gabbay
8189e65e175bSOded Gabbay return hl_fw_get_monitor_dump(hdev, data);
8190e65e175bSOded Gabbay }
8191e65e175bSOded Gabbay
8192e65e175bSOded Gabbay /*
8193e65e175bSOded Gabbay * this function should be used only during initialization and/or after reset,
8194e65e175bSOded Gabbay * when there are no active users.
8195e65e175bSOded Gabbay */
gaudi_run_tpc_kernel(struct hl_device * hdev,u64 tpc_kernel,u32 tpc_id)8196e65e175bSOded Gabbay static int gaudi_run_tpc_kernel(struct hl_device *hdev, u64 tpc_kernel, u32 tpc_id)
8197e65e175bSOded Gabbay {
8198e65e175bSOded Gabbay u64 kernel_timeout;
8199e65e175bSOded Gabbay u32 status, offset;
8200e65e175bSOded Gabbay int rc;
8201e65e175bSOded Gabbay
8202e65e175bSOded Gabbay offset = tpc_id * (mmTPC1_CFG_STATUS - mmTPC0_CFG_STATUS);
8203e65e175bSOded Gabbay
8204e65e175bSOded Gabbay if (hdev->pldm)
8205e65e175bSOded Gabbay kernel_timeout = GAUDI_PLDM_TPC_KERNEL_WAIT_USEC;
8206e65e175bSOded Gabbay else
8207e65e175bSOded Gabbay kernel_timeout = HL_DEVICE_TIMEOUT_USEC;
8208e65e175bSOded Gabbay
8209e65e175bSOded Gabbay WREG32(mmTPC0_CFG_QM_KERNEL_BASE_ADDRESS_LOW + offset,
8210e65e175bSOded Gabbay lower_32_bits(tpc_kernel));
8211e65e175bSOded Gabbay WREG32(mmTPC0_CFG_QM_KERNEL_BASE_ADDRESS_HIGH + offset,
8212e65e175bSOded Gabbay upper_32_bits(tpc_kernel));
8213e65e175bSOded Gabbay
8214e65e175bSOded Gabbay WREG32(mmTPC0_CFG_ICACHE_BASE_ADDERESS_LOW + offset,
8215e65e175bSOded Gabbay lower_32_bits(tpc_kernel));
8216e65e175bSOded Gabbay WREG32(mmTPC0_CFG_ICACHE_BASE_ADDERESS_HIGH + offset,
8217e65e175bSOded Gabbay upper_32_bits(tpc_kernel));
8218e65e175bSOded Gabbay /* set a valid LUT pointer, content is of no significance */
8219e65e175bSOded Gabbay WREG32(mmTPC0_CFG_LUT_FUNC256_BASE_ADDR_LO + offset,
8220e65e175bSOded Gabbay lower_32_bits(tpc_kernel));
8221e65e175bSOded Gabbay WREG32(mmTPC0_CFG_LUT_FUNC256_BASE_ADDR_HI + offset,
8222e65e175bSOded Gabbay upper_32_bits(tpc_kernel));
8223e65e175bSOded Gabbay
8224e65e175bSOded Gabbay WREG32(mmTPC0_CFG_QM_SYNC_OBJECT_ADDR + offset,
8225e65e175bSOded Gabbay lower_32_bits(CFG_BASE +
8226e65e175bSOded Gabbay mmSYNC_MNGR_E_N_SYNC_MNGR_OBJS_SOB_OBJ_0));
8227e65e175bSOded Gabbay
8228e65e175bSOded Gabbay WREG32(mmTPC0_CFG_TPC_CMD + offset,
8229e65e175bSOded Gabbay (1 << TPC0_CFG_TPC_CMD_ICACHE_INVALIDATE_SHIFT |
8230e65e175bSOded Gabbay 1 << TPC0_CFG_TPC_CMD_ICACHE_PREFETCH_64KB_SHIFT));
8231e65e175bSOded Gabbay /* wait a bit for the engine to start executing */
8232e65e175bSOded Gabbay usleep_range(1000, 1500);
8233e65e175bSOded Gabbay
8234e65e175bSOded Gabbay /* wait until engine has finished executing */
8235e65e175bSOded Gabbay rc = hl_poll_timeout(
8236e65e175bSOded Gabbay hdev,
8237e65e175bSOded Gabbay mmTPC0_CFG_STATUS + offset,
8238e65e175bSOded Gabbay status,
8239e65e175bSOded Gabbay (status & TPC0_CFG_STATUS_VECTOR_PIPE_EMPTY_MASK) ==
8240e65e175bSOded Gabbay TPC0_CFG_STATUS_VECTOR_PIPE_EMPTY_MASK,
8241e65e175bSOded Gabbay 1000,
8242e65e175bSOded Gabbay kernel_timeout);
8243e65e175bSOded Gabbay
8244e65e175bSOded Gabbay if (rc) {
8245e65e175bSOded Gabbay dev_err(hdev->dev,
8246e65e175bSOded Gabbay "Timeout while waiting for TPC%d icache prefetch\n",
8247e65e175bSOded Gabbay tpc_id);
8248e65e175bSOded Gabbay return -EIO;
8249e65e175bSOded Gabbay }
8250e65e175bSOded Gabbay
8251e65e175bSOded Gabbay WREG32(mmTPC0_CFG_TPC_EXECUTE + offset,
8252e65e175bSOded Gabbay 1 << TPC0_CFG_TPC_EXECUTE_V_SHIFT);
8253e65e175bSOded Gabbay
8254e65e175bSOded Gabbay /* wait a bit for the engine to start executing */
8255e65e175bSOded Gabbay usleep_range(1000, 1500);
8256e65e175bSOded Gabbay
8257e65e175bSOded Gabbay /* wait until engine has finished executing */
8258e65e175bSOded Gabbay rc = hl_poll_timeout(
8259e65e175bSOded Gabbay hdev,
8260e65e175bSOded Gabbay mmTPC0_CFG_STATUS + offset,
8261e65e175bSOded Gabbay status,
8262e65e175bSOded Gabbay (status & TPC0_CFG_STATUS_VECTOR_PIPE_EMPTY_MASK) ==
8263e65e175bSOded Gabbay TPC0_CFG_STATUS_VECTOR_PIPE_EMPTY_MASK,
8264e65e175bSOded Gabbay 1000,
8265e65e175bSOded Gabbay kernel_timeout);
8266e65e175bSOded Gabbay
8267e65e175bSOded Gabbay if (rc) {
8268e65e175bSOded Gabbay dev_err(hdev->dev,
8269e65e175bSOded Gabbay "Timeout while waiting for TPC%d vector pipe\n",
8270e65e175bSOded Gabbay tpc_id);
8271e65e175bSOded Gabbay return -EIO;
8272e65e175bSOded Gabbay }
8273e65e175bSOded Gabbay
8274e65e175bSOded Gabbay rc = hl_poll_timeout(
8275e65e175bSOded Gabbay hdev,
8276e65e175bSOded Gabbay mmTPC0_CFG_WQ_INFLIGHT_CNTR + offset,
8277e65e175bSOded Gabbay status,
8278e65e175bSOded Gabbay (status == 0),
8279e65e175bSOded Gabbay 1000,
8280e65e175bSOded Gabbay kernel_timeout);
8281e65e175bSOded Gabbay
8282e65e175bSOded Gabbay if (rc) {
8283e65e175bSOded Gabbay dev_err(hdev->dev,
8284e65e175bSOded Gabbay "Timeout while waiting for TPC%d kernel to execute\n",
8285e65e175bSOded Gabbay tpc_id);
8286e65e175bSOded Gabbay return -EIO;
8287e65e175bSOded Gabbay }
8288e65e175bSOded Gabbay
8289e65e175bSOded Gabbay return 0;
8290e65e175bSOded Gabbay }
8291e65e175bSOded Gabbay
gaudi_internal_cb_pool_init(struct hl_device * hdev,struct hl_ctx * ctx)8292e65e175bSOded Gabbay static int gaudi_internal_cb_pool_init(struct hl_device *hdev,
8293e65e175bSOded Gabbay struct hl_ctx *ctx)
8294e65e175bSOded Gabbay {
8295e65e175bSOded Gabbay struct gaudi_device *gaudi = hdev->asic_specific;
8296e65e175bSOded Gabbay int min_alloc_order, rc, collective_cb_size;
8297e65e175bSOded Gabbay
8298e65e175bSOded Gabbay if (!(gaudi->hw_cap_initialized & HW_CAP_MMU))
8299e65e175bSOded Gabbay return 0;
8300e65e175bSOded Gabbay
8301e65e175bSOded Gabbay hdev->internal_cb_pool_virt_addr = hl_asic_dma_alloc_coherent(hdev,
8302e65e175bSOded Gabbay HOST_SPACE_INTERNAL_CB_SZ,
8303e65e175bSOded Gabbay &hdev->internal_cb_pool_dma_addr,
8304e65e175bSOded Gabbay GFP_KERNEL | __GFP_ZERO);
8305e65e175bSOded Gabbay
8306e65e175bSOded Gabbay if (!hdev->internal_cb_pool_virt_addr)
8307e65e175bSOded Gabbay return -ENOMEM;
8308e65e175bSOded Gabbay
8309e65e175bSOded Gabbay collective_cb_size = sizeof(struct packet_msg_short) * 5 +
8310e65e175bSOded Gabbay sizeof(struct packet_fence);
8311e65e175bSOded Gabbay min_alloc_order = ilog2(collective_cb_size);
8312e65e175bSOded Gabbay
8313e65e175bSOded Gabbay hdev->internal_cb_pool = gen_pool_create(min_alloc_order, -1);
8314e65e175bSOded Gabbay if (!hdev->internal_cb_pool) {
8315e65e175bSOded Gabbay dev_err(hdev->dev,
8316e65e175bSOded Gabbay "Failed to create internal CB pool\n");
8317e65e175bSOded Gabbay rc = -ENOMEM;
8318e65e175bSOded Gabbay goto free_internal_cb_pool;
8319e65e175bSOded Gabbay }
8320e65e175bSOded Gabbay
8321e65e175bSOded Gabbay rc = gen_pool_add(hdev->internal_cb_pool,
8322e65e175bSOded Gabbay (uintptr_t) hdev->internal_cb_pool_virt_addr,
8323e65e175bSOded Gabbay HOST_SPACE_INTERNAL_CB_SZ, -1);
8324e65e175bSOded Gabbay if (rc) {
8325e65e175bSOded Gabbay dev_err(hdev->dev,
8326e65e175bSOded Gabbay "Failed to add memory to internal CB pool\n");
8327e65e175bSOded Gabbay rc = -EFAULT;
8328e65e175bSOded Gabbay goto destroy_internal_cb_pool;
8329e65e175bSOded Gabbay }
8330e65e175bSOded Gabbay
8331e65e175bSOded Gabbay hdev->internal_cb_va_base = hl_reserve_va_block(hdev, ctx,
8332e65e175bSOded Gabbay HL_VA_RANGE_TYPE_HOST, HOST_SPACE_INTERNAL_CB_SZ,
8333e65e175bSOded Gabbay HL_MMU_VA_ALIGNMENT_NOT_NEEDED);
8334e65e175bSOded Gabbay
8335e65e175bSOded Gabbay if (!hdev->internal_cb_va_base) {
8336e65e175bSOded Gabbay rc = -ENOMEM;
8337e65e175bSOded Gabbay goto destroy_internal_cb_pool;
8338e65e175bSOded Gabbay }
8339e65e175bSOded Gabbay
8340e65e175bSOded Gabbay mutex_lock(&hdev->mmu_lock);
8341e65e175bSOded Gabbay
8342e65e175bSOded Gabbay rc = hl_mmu_map_contiguous(ctx, hdev->internal_cb_va_base,
8343e65e175bSOded Gabbay hdev->internal_cb_pool_dma_addr,
8344e65e175bSOded Gabbay HOST_SPACE_INTERNAL_CB_SZ);
8345e65e175bSOded Gabbay if (rc)
8346e65e175bSOded Gabbay goto unreserve_internal_cb_pool;
8347e65e175bSOded Gabbay
8348e65e175bSOded Gabbay rc = hl_mmu_invalidate_cache(hdev, false, MMU_OP_USERPTR);
8349e65e175bSOded Gabbay if (rc)
8350e65e175bSOded Gabbay goto unmap_internal_cb_pool;
8351e65e175bSOded Gabbay
8352af5e675fSKoby Elbaz mutex_unlock(&hdev->mmu_lock);
8353e65e175bSOded Gabbay
8354e65e175bSOded Gabbay return 0;
8355e65e175bSOded Gabbay
8356e65e175bSOded Gabbay unmap_internal_cb_pool:
8357e65e175bSOded Gabbay hl_mmu_unmap_contiguous(ctx, hdev->internal_cb_va_base,
8358e65e175bSOded Gabbay HOST_SPACE_INTERNAL_CB_SZ);
8359af5e675fSKoby Elbaz unreserve_internal_cb_pool:
8360af5e675fSKoby Elbaz mutex_unlock(&hdev->mmu_lock);
8361af5e675fSKoby Elbaz hl_unreserve_va_block(hdev, ctx, hdev->internal_cb_va_base,
8362af5e675fSKoby Elbaz HOST_SPACE_INTERNAL_CB_SZ);
8363af5e675fSKoby Elbaz destroy_internal_cb_pool:
8364af5e675fSKoby Elbaz gen_pool_destroy(hdev->internal_cb_pool);
8365e65e175bSOded Gabbay free_internal_cb_pool:
8366e65e175bSOded Gabbay hl_asic_dma_free_coherent(hdev, HOST_SPACE_INTERNAL_CB_SZ, hdev->internal_cb_pool_virt_addr,
8367af5e675fSKoby Elbaz hdev->internal_cb_pool_dma_addr);
8368af5e675fSKoby Elbaz
8369af5e675fSKoby Elbaz return rc;
8370e65e175bSOded Gabbay }
8371af5e675fSKoby Elbaz
gaudi_internal_cb_pool_fini(struct hl_device * hdev,struct hl_ctx * ctx)8372e65e175bSOded Gabbay static void gaudi_internal_cb_pool_fini(struct hl_device *hdev,
8373e65e175bSOded Gabbay struct hl_ctx *ctx)
8374e65e175bSOded Gabbay {
8375e65e175bSOded Gabbay struct gaudi_device *gaudi = hdev->asic_specific;
8376e65e175bSOded Gabbay
8377e65e175bSOded Gabbay if (!(gaudi->hw_cap_initialized & HW_CAP_MMU))
8378e65e175bSOded Gabbay return;
8379e65e175bSOded Gabbay
8380e65e175bSOded Gabbay mutex_lock(&hdev->mmu_lock);
8381e65e175bSOded Gabbay hl_mmu_unmap_contiguous(ctx, hdev->internal_cb_va_base,
8382e65e175bSOded Gabbay HOST_SPACE_INTERNAL_CB_SZ);
8383e65e175bSOded Gabbay hl_unreserve_va_block(hdev, ctx, hdev->internal_cb_va_base,
8384e65e175bSOded Gabbay HOST_SPACE_INTERNAL_CB_SZ);
8385e65e175bSOded Gabbay hl_mmu_invalidate_cache(hdev, true, MMU_OP_USERPTR);
8386e65e175bSOded Gabbay mutex_unlock(&hdev->mmu_lock);
8387e65e175bSOded Gabbay
8388e65e175bSOded Gabbay gen_pool_destroy(hdev->internal_cb_pool);
8389e65e175bSOded Gabbay
8390e65e175bSOded Gabbay hl_asic_dma_free_coherent(hdev, HOST_SPACE_INTERNAL_CB_SZ, hdev->internal_cb_pool_virt_addr,
8391e65e175bSOded Gabbay hdev->internal_cb_pool_dma_addr);
8392e65e175bSOded Gabbay }
8393e65e175bSOded Gabbay
gaudi_ctx_init(struct hl_ctx * ctx)8394e65e175bSOded Gabbay static int gaudi_ctx_init(struct hl_ctx *ctx)
8395e65e175bSOded Gabbay {
8396e65e175bSOded Gabbay int rc;
8397e65e175bSOded Gabbay
8398e65e175bSOded Gabbay if (ctx->asid == HL_KERNEL_ASID_ID)
8399e65e175bSOded Gabbay return 0;
8400e65e175bSOded Gabbay
8401e65e175bSOded Gabbay rc = gaudi_internal_cb_pool_init(ctx->hdev, ctx);
8402e65e175bSOded Gabbay if (rc)
8403e65e175bSOded Gabbay return rc;
8404e65e175bSOded Gabbay
8405e65e175bSOded Gabbay rc = gaudi_restore_user_registers(ctx->hdev);
8406e65e175bSOded Gabbay if (rc)
8407e65e175bSOded Gabbay gaudi_internal_cb_pool_fini(ctx->hdev, ctx);
8408e65e175bSOded Gabbay
8409e65e175bSOded Gabbay return rc;
8410e65e175bSOded Gabbay }
8411e65e175bSOded Gabbay
gaudi_ctx_fini(struct hl_ctx * ctx)8412e65e175bSOded Gabbay static void gaudi_ctx_fini(struct hl_ctx *ctx)
8413e65e175bSOded Gabbay {
8414e65e175bSOded Gabbay if (ctx->asid == HL_KERNEL_ASID_ID)
8415e65e175bSOded Gabbay return;
8416e65e175bSOded Gabbay
8417e65e175bSOded Gabbay gaudi_internal_cb_pool_fini(ctx->hdev, ctx);
8418e65e175bSOded Gabbay }
8419e65e175bSOded Gabbay
gaudi_pre_schedule_cs(struct hl_cs * cs)8420e65e175bSOded Gabbay static int gaudi_pre_schedule_cs(struct hl_cs *cs)
8421e65e175bSOded Gabbay {
8422e65e175bSOded Gabbay return 0;
8423e65e175bSOded Gabbay }
8424e65e175bSOded Gabbay
gaudi_get_queue_id_for_cq(struct hl_device * hdev,u32 cq_idx)8425e65e175bSOded Gabbay static u32 gaudi_get_queue_id_for_cq(struct hl_device *hdev, u32 cq_idx)
8426e65e175bSOded Gabbay {
8427e65e175bSOded Gabbay return gaudi_cq_assignment[cq_idx];
8428e65e175bSOded Gabbay }
8429e65e175bSOded Gabbay
gaudi_get_signal_cb_size(struct hl_device * hdev)8430e65e175bSOded Gabbay static u32 gaudi_get_signal_cb_size(struct hl_device *hdev)
8431e65e175bSOded Gabbay {
8432e65e175bSOded Gabbay return sizeof(struct packet_msg_short) +
8433e65e175bSOded Gabbay sizeof(struct packet_msg_prot) * 2;
8434e65e175bSOded Gabbay }
8435e65e175bSOded Gabbay
gaudi_get_wait_cb_size(struct hl_device * hdev)8436e65e175bSOded Gabbay static u32 gaudi_get_wait_cb_size(struct hl_device *hdev)
8437e65e175bSOded Gabbay {
8438e65e175bSOded Gabbay return sizeof(struct packet_msg_short) * 4 +
8439e65e175bSOded Gabbay sizeof(struct packet_fence) +
8440e65e175bSOded Gabbay sizeof(struct packet_msg_prot) * 2;
8441e65e175bSOded Gabbay }
8442e65e175bSOded Gabbay
gaudi_get_sob_addr(struct hl_device * hdev,u32 sob_id)8443e65e175bSOded Gabbay static u32 gaudi_get_sob_addr(struct hl_device *hdev, u32 sob_id)
8444e65e175bSOded Gabbay {
8445e65e175bSOded Gabbay return mmSYNC_MNGR_W_S_SYNC_MNGR_OBJS_SOB_OBJ_0 + (sob_id * 4);
8446e65e175bSOded Gabbay }
8447e65e175bSOded Gabbay
gaudi_gen_signal_cb(struct hl_device * hdev,void * data,u16 sob_id,u32 size,bool eb)8448e65e175bSOded Gabbay static u32 gaudi_gen_signal_cb(struct hl_device *hdev, void *data, u16 sob_id,
8449e65e175bSOded Gabbay u32 size, bool eb)
8450e65e175bSOded Gabbay {
8451e65e175bSOded Gabbay struct hl_cb *cb = (struct hl_cb *) data;
8452e65e175bSOded Gabbay struct packet_msg_short *pkt;
8453e65e175bSOded Gabbay u32 value, ctl, pkt_size = sizeof(*pkt);
8454e65e175bSOded Gabbay
8455e65e175bSOded Gabbay pkt = cb->kernel_address + size;
8456e65e175bSOded Gabbay memset(pkt, 0, pkt_size);
8457e65e175bSOded Gabbay
8458e65e175bSOded Gabbay /* Inc by 1, Mode ADD */
8459e65e175bSOded Gabbay value = FIELD_PREP(GAUDI_PKT_SHORT_VAL_SOB_SYNC_VAL_MASK, 1);
8460e65e175bSOded Gabbay value |= FIELD_PREP(GAUDI_PKT_SHORT_VAL_SOB_MOD_MASK, 1);
8461e65e175bSOded Gabbay
8462e65e175bSOded Gabbay ctl = FIELD_PREP(GAUDI_PKT_SHORT_CTL_ADDR_MASK, sob_id * 4);
8463e65e175bSOded Gabbay ctl |= FIELD_PREP(GAUDI_PKT_SHORT_CTL_OP_MASK, 0); /* write the value */
8464e65e175bSOded Gabbay ctl |= FIELD_PREP(GAUDI_PKT_SHORT_CTL_BASE_MASK, 3); /* W_S SOB base */
8465e65e175bSOded Gabbay ctl |= FIELD_PREP(GAUDI_PKT_CTL_OPCODE_MASK, PACKET_MSG_SHORT);
8466e65e175bSOded Gabbay ctl |= FIELD_PREP(GAUDI_PKT_CTL_EB_MASK, eb);
8467e65e175bSOded Gabbay ctl |= FIELD_PREP(GAUDI_PKT_CTL_RB_MASK, 1);
8468e65e175bSOded Gabbay ctl |= FIELD_PREP(GAUDI_PKT_CTL_MB_MASK, 1);
8469e65e175bSOded Gabbay
8470e65e175bSOded Gabbay pkt->value = cpu_to_le32(value);
8471e65e175bSOded Gabbay pkt->ctl = cpu_to_le32(ctl);
8472e65e175bSOded Gabbay
8473e65e175bSOded Gabbay return size + pkt_size;
8474e65e175bSOded Gabbay }
8475e65e175bSOded Gabbay
gaudi_add_mon_msg_short(struct packet_msg_short * pkt,u32 value,u16 addr)8476e65e175bSOded Gabbay static u32 gaudi_add_mon_msg_short(struct packet_msg_short *pkt, u32 value,
8477e65e175bSOded Gabbay u16 addr)
8478e65e175bSOded Gabbay {
8479e65e175bSOded Gabbay u32 ctl, pkt_size = sizeof(*pkt);
8480e65e175bSOded Gabbay
8481e65e175bSOded Gabbay memset(pkt, 0, pkt_size);
8482e65e175bSOded Gabbay
8483e65e175bSOded Gabbay ctl = FIELD_PREP(GAUDI_PKT_SHORT_CTL_ADDR_MASK, addr);
8484e65e175bSOded Gabbay ctl |= FIELD_PREP(GAUDI_PKT_SHORT_CTL_BASE_MASK, 2); /* W_S MON base */
8485e65e175bSOded Gabbay ctl |= FIELD_PREP(GAUDI_PKT_CTL_OPCODE_MASK, PACKET_MSG_SHORT);
8486e65e175bSOded Gabbay ctl |= FIELD_PREP(GAUDI_PKT_CTL_EB_MASK, 0);
8487e65e175bSOded Gabbay ctl |= FIELD_PREP(GAUDI_PKT_CTL_RB_MASK, 1);
8488e65e175bSOded Gabbay ctl |= FIELD_PREP(GAUDI_PKT_CTL_MB_MASK, 0); /* last pkt MB */
8489e65e175bSOded Gabbay
8490e65e175bSOded Gabbay pkt->value = cpu_to_le32(value);
8491e65e175bSOded Gabbay pkt->ctl = cpu_to_le32(ctl);
8492e65e175bSOded Gabbay
8493e65e175bSOded Gabbay return pkt_size;
8494e65e175bSOded Gabbay }
8495e65e175bSOded Gabbay
gaudi_add_arm_monitor_pkt(struct hl_device * hdev,struct packet_msg_short * pkt,u16 sob_base,u8 sob_mask,u16 sob_val,u16 mon_id)8496e65e175bSOded Gabbay static u32 gaudi_add_arm_monitor_pkt(struct hl_device *hdev,
8497e65e175bSOded Gabbay struct packet_msg_short *pkt, u16 sob_base, u8 sob_mask,
8498e65e175bSOded Gabbay u16 sob_val, u16 mon_id)
8499e65e175bSOded Gabbay {
8500e65e175bSOded Gabbay u64 monitor_base;
8501e65e175bSOded Gabbay u32 ctl, value, pkt_size = sizeof(*pkt);
8502e65e175bSOded Gabbay u16 msg_addr_offset;
8503e65e175bSOded Gabbay u8 mask;
8504e65e175bSOded Gabbay
8505e65e175bSOded Gabbay if (hl_gen_sob_mask(sob_base, sob_mask, &mask)) {
8506e65e175bSOded Gabbay dev_err(hdev->dev,
8507e65e175bSOded Gabbay "sob_base %u (mask %#x) is not valid\n",
8508e65e175bSOded Gabbay sob_base, sob_mask);
8509e65e175bSOded Gabbay return 0;
8510e65e175bSOded Gabbay }
8511e65e175bSOded Gabbay
8512e65e175bSOded Gabbay /*
8513e65e175bSOded Gabbay * monitor_base should be the content of the base0 address registers,
8514e65e175bSOded Gabbay * so it will be added to the msg short offsets
8515e65e175bSOded Gabbay */
8516e65e175bSOded Gabbay monitor_base = mmSYNC_MNGR_W_S_SYNC_MNGR_OBJS_MON_PAY_ADDRL_0;
8517e65e175bSOded Gabbay
8518e65e175bSOded Gabbay msg_addr_offset =
8519e65e175bSOded Gabbay (mmSYNC_MNGR_W_S_SYNC_MNGR_OBJS_MON_ARM_0 + mon_id * 4) -
8520e65e175bSOded Gabbay monitor_base;
8521e65e175bSOded Gabbay
8522e65e175bSOded Gabbay memset(pkt, 0, pkt_size);
8523e65e175bSOded Gabbay
8524e65e175bSOded Gabbay /* Monitor config packet: bind the monitor to a sync object */
8525e65e175bSOded Gabbay value = FIELD_PREP(GAUDI_PKT_SHORT_VAL_MON_SYNC_GID_MASK, sob_base / 8);
8526e65e175bSOded Gabbay value |= FIELD_PREP(GAUDI_PKT_SHORT_VAL_MON_SYNC_VAL_MASK, sob_val);
8527e65e175bSOded Gabbay value |= FIELD_PREP(GAUDI_PKT_SHORT_VAL_MON_MODE_MASK,
8528e65e175bSOded Gabbay 0); /* GREATER OR EQUAL*/
8529e65e175bSOded Gabbay value |= FIELD_PREP(GAUDI_PKT_SHORT_VAL_MON_MASK_MASK, mask);
8530e65e175bSOded Gabbay
8531e65e175bSOded Gabbay ctl = FIELD_PREP(GAUDI_PKT_SHORT_CTL_ADDR_MASK, msg_addr_offset);
8532e65e175bSOded Gabbay ctl |= FIELD_PREP(GAUDI_PKT_SHORT_CTL_OP_MASK, 0); /* write the value */
8533e65e175bSOded Gabbay ctl |= FIELD_PREP(GAUDI_PKT_SHORT_CTL_BASE_MASK, 2); /* W_S MON base */
8534e65e175bSOded Gabbay ctl |= FIELD_PREP(GAUDI_PKT_CTL_OPCODE_MASK, PACKET_MSG_SHORT);
8535e65e175bSOded Gabbay ctl |= FIELD_PREP(GAUDI_PKT_CTL_EB_MASK, 0);
8536e65e175bSOded Gabbay ctl |= FIELD_PREP(GAUDI_PKT_CTL_RB_MASK, 1);
8537e65e175bSOded Gabbay ctl |= FIELD_PREP(GAUDI_PKT_CTL_MB_MASK, 1);
8538e65e175bSOded Gabbay
8539e65e175bSOded Gabbay pkt->value = cpu_to_le32(value);
8540e65e175bSOded Gabbay pkt->ctl = cpu_to_le32(ctl);
8541e65e175bSOded Gabbay
8542e65e175bSOded Gabbay return pkt_size;
8543e65e175bSOded Gabbay }
8544e65e175bSOded Gabbay
gaudi_add_fence_pkt(struct packet_fence * pkt)8545e65e175bSOded Gabbay static u32 gaudi_add_fence_pkt(struct packet_fence *pkt)
8546e65e175bSOded Gabbay {
8547e65e175bSOded Gabbay u32 ctl, cfg, pkt_size = sizeof(*pkt);
8548e65e175bSOded Gabbay
8549e65e175bSOded Gabbay memset(pkt, 0, pkt_size);
8550e65e175bSOded Gabbay
8551e65e175bSOded Gabbay cfg = FIELD_PREP(GAUDI_PKT_FENCE_CFG_DEC_VAL_MASK, 1);
8552e65e175bSOded Gabbay cfg |= FIELD_PREP(GAUDI_PKT_FENCE_CFG_TARGET_VAL_MASK, 1);
8553e65e175bSOded Gabbay cfg |= FIELD_PREP(GAUDI_PKT_FENCE_CFG_ID_MASK, 2);
8554e65e175bSOded Gabbay
8555e65e175bSOded Gabbay ctl = FIELD_PREP(GAUDI_PKT_CTL_OPCODE_MASK, PACKET_FENCE);
8556e65e175bSOded Gabbay ctl |= FIELD_PREP(GAUDI_PKT_CTL_EB_MASK, 0);
8557e65e175bSOded Gabbay ctl |= FIELD_PREP(GAUDI_PKT_CTL_RB_MASK, 1);
8558e65e175bSOded Gabbay ctl |= FIELD_PREP(GAUDI_PKT_CTL_MB_MASK, 1);
8559e65e175bSOded Gabbay
8560e65e175bSOded Gabbay pkt->cfg = cpu_to_le32(cfg);
8561e65e175bSOded Gabbay pkt->ctl = cpu_to_le32(ctl);
8562e65e175bSOded Gabbay
8563e65e175bSOded Gabbay return pkt_size;
8564e65e175bSOded Gabbay }
8565e65e175bSOded Gabbay
gaudi_get_fence_addr(struct hl_device * hdev,u32 queue_id,u64 * addr)8566e65e175bSOded Gabbay static int gaudi_get_fence_addr(struct hl_device *hdev, u32 queue_id, u64 *addr)
8567e65e175bSOded Gabbay {
8568e65e175bSOded Gabbay u32 offset, nic_index;
8569e65e175bSOded Gabbay
8570e65e175bSOded Gabbay switch (queue_id) {
8571e65e175bSOded Gabbay case GAUDI_QUEUE_ID_DMA_0_0:
8572e65e175bSOded Gabbay offset = mmDMA0_QM_CP_FENCE2_RDATA_0;
8573e65e175bSOded Gabbay break;
8574e65e175bSOded Gabbay case GAUDI_QUEUE_ID_DMA_0_1:
8575e65e175bSOded Gabbay offset = mmDMA0_QM_CP_FENCE2_RDATA_1;
8576e65e175bSOded Gabbay break;
8577e65e175bSOded Gabbay case GAUDI_QUEUE_ID_DMA_0_2:
8578e65e175bSOded Gabbay offset = mmDMA0_QM_CP_FENCE2_RDATA_2;
8579e65e175bSOded Gabbay break;
8580e65e175bSOded Gabbay case GAUDI_QUEUE_ID_DMA_0_3:
8581e65e175bSOded Gabbay offset = mmDMA0_QM_CP_FENCE2_RDATA_3;
8582e65e175bSOded Gabbay break;
8583e65e175bSOded Gabbay case GAUDI_QUEUE_ID_DMA_1_0:
8584e65e175bSOded Gabbay offset = mmDMA1_QM_CP_FENCE2_RDATA_0;
8585e65e175bSOded Gabbay break;
8586e65e175bSOded Gabbay case GAUDI_QUEUE_ID_DMA_1_1:
8587e65e175bSOded Gabbay offset = mmDMA1_QM_CP_FENCE2_RDATA_1;
8588e65e175bSOded Gabbay break;
8589e65e175bSOded Gabbay case GAUDI_QUEUE_ID_DMA_1_2:
8590e65e175bSOded Gabbay offset = mmDMA1_QM_CP_FENCE2_RDATA_2;
8591e65e175bSOded Gabbay break;
8592e65e175bSOded Gabbay case GAUDI_QUEUE_ID_DMA_1_3:
8593e65e175bSOded Gabbay offset = mmDMA1_QM_CP_FENCE2_RDATA_3;
8594e65e175bSOded Gabbay break;
8595e65e175bSOded Gabbay case GAUDI_QUEUE_ID_DMA_5_0:
8596e65e175bSOded Gabbay offset = mmDMA5_QM_CP_FENCE2_RDATA_0;
8597e65e175bSOded Gabbay break;
8598e65e175bSOded Gabbay case GAUDI_QUEUE_ID_DMA_5_1:
8599e65e175bSOded Gabbay offset = mmDMA5_QM_CP_FENCE2_RDATA_1;
8600e65e175bSOded Gabbay break;
8601e65e175bSOded Gabbay case GAUDI_QUEUE_ID_DMA_5_2:
8602e65e175bSOded Gabbay offset = mmDMA5_QM_CP_FENCE2_RDATA_2;
8603e65e175bSOded Gabbay break;
8604e65e175bSOded Gabbay case GAUDI_QUEUE_ID_DMA_5_3:
8605e65e175bSOded Gabbay offset = mmDMA5_QM_CP_FENCE2_RDATA_3;
8606e65e175bSOded Gabbay break;
8607e65e175bSOded Gabbay case GAUDI_QUEUE_ID_TPC_7_0:
8608e65e175bSOded Gabbay offset = mmTPC7_QM_CP_FENCE2_RDATA_0;
8609e65e175bSOded Gabbay break;
8610e65e175bSOded Gabbay case GAUDI_QUEUE_ID_TPC_7_1:
8611e65e175bSOded Gabbay offset = mmTPC7_QM_CP_FENCE2_RDATA_1;
8612e65e175bSOded Gabbay break;
8613e65e175bSOded Gabbay case GAUDI_QUEUE_ID_TPC_7_2:
8614e65e175bSOded Gabbay offset = mmTPC7_QM_CP_FENCE2_RDATA_2;
8615e65e175bSOded Gabbay break;
8616e65e175bSOded Gabbay case GAUDI_QUEUE_ID_TPC_7_3:
8617e65e175bSOded Gabbay offset = mmTPC7_QM_CP_FENCE2_RDATA_3;
8618e65e175bSOded Gabbay break;
8619e65e175bSOded Gabbay case GAUDI_QUEUE_ID_NIC_0_0:
8620e65e175bSOded Gabbay case GAUDI_QUEUE_ID_NIC_1_0:
8621e65e175bSOded Gabbay case GAUDI_QUEUE_ID_NIC_2_0:
8622e65e175bSOded Gabbay case GAUDI_QUEUE_ID_NIC_3_0:
8623e65e175bSOded Gabbay case GAUDI_QUEUE_ID_NIC_4_0:
8624e65e175bSOded Gabbay case GAUDI_QUEUE_ID_NIC_5_0:
8625e65e175bSOded Gabbay case GAUDI_QUEUE_ID_NIC_6_0:
8626e65e175bSOded Gabbay case GAUDI_QUEUE_ID_NIC_7_0:
8627e65e175bSOded Gabbay case GAUDI_QUEUE_ID_NIC_8_0:
8628e65e175bSOded Gabbay case GAUDI_QUEUE_ID_NIC_9_0:
8629e65e175bSOded Gabbay nic_index = (queue_id - GAUDI_QUEUE_ID_NIC_0_0) >> 2;
8630e65e175bSOded Gabbay offset = mmNIC0_QM0_CP_FENCE2_RDATA_0 +
8631e65e175bSOded Gabbay (nic_index >> 1) * NIC_MACRO_QMAN_OFFSET +
8632e65e175bSOded Gabbay (nic_index & 0x1) * NIC_ENGINE_QMAN_OFFSET;
8633e65e175bSOded Gabbay break;
8634e65e175bSOded Gabbay case GAUDI_QUEUE_ID_NIC_0_1:
8635e65e175bSOded Gabbay case GAUDI_QUEUE_ID_NIC_1_1:
8636e65e175bSOded Gabbay case GAUDI_QUEUE_ID_NIC_2_1:
8637e65e175bSOded Gabbay case GAUDI_QUEUE_ID_NIC_3_1:
8638e65e175bSOded Gabbay case GAUDI_QUEUE_ID_NIC_4_1:
8639e65e175bSOded Gabbay case GAUDI_QUEUE_ID_NIC_5_1:
8640e65e175bSOded Gabbay case GAUDI_QUEUE_ID_NIC_6_1:
8641e65e175bSOded Gabbay case GAUDI_QUEUE_ID_NIC_7_1:
8642e65e175bSOded Gabbay case GAUDI_QUEUE_ID_NIC_8_1:
8643e65e175bSOded Gabbay case GAUDI_QUEUE_ID_NIC_9_1:
8644e65e175bSOded Gabbay nic_index = (queue_id - GAUDI_QUEUE_ID_NIC_0_1) >> 2;
8645e65e175bSOded Gabbay offset = mmNIC0_QM0_CP_FENCE2_RDATA_1 +
8646e65e175bSOded Gabbay (nic_index >> 1) * NIC_MACRO_QMAN_OFFSET +
8647e65e175bSOded Gabbay (nic_index & 0x1) * NIC_ENGINE_QMAN_OFFSET;
8648e65e175bSOded Gabbay break;
8649e65e175bSOded Gabbay case GAUDI_QUEUE_ID_NIC_0_2:
8650e65e175bSOded Gabbay case GAUDI_QUEUE_ID_NIC_1_2:
8651e65e175bSOded Gabbay case GAUDI_QUEUE_ID_NIC_2_2:
8652e65e175bSOded Gabbay case GAUDI_QUEUE_ID_NIC_3_2:
8653e65e175bSOded Gabbay case GAUDI_QUEUE_ID_NIC_4_2:
8654e65e175bSOded Gabbay case GAUDI_QUEUE_ID_NIC_5_2:
8655e65e175bSOded Gabbay case GAUDI_QUEUE_ID_NIC_6_2:
8656e65e175bSOded Gabbay case GAUDI_QUEUE_ID_NIC_7_2:
8657e65e175bSOded Gabbay case GAUDI_QUEUE_ID_NIC_8_2:
8658e65e175bSOded Gabbay case GAUDI_QUEUE_ID_NIC_9_2:
8659e65e175bSOded Gabbay nic_index = (queue_id - GAUDI_QUEUE_ID_NIC_0_2) >> 2;
8660e65e175bSOded Gabbay offset = mmNIC0_QM0_CP_FENCE2_RDATA_2 +
8661e65e175bSOded Gabbay (nic_index >> 1) * NIC_MACRO_QMAN_OFFSET +
8662e65e175bSOded Gabbay (nic_index & 0x1) * NIC_ENGINE_QMAN_OFFSET;
8663e65e175bSOded Gabbay break;
8664e65e175bSOded Gabbay case GAUDI_QUEUE_ID_NIC_0_3:
8665e65e175bSOded Gabbay case GAUDI_QUEUE_ID_NIC_1_3:
8666e65e175bSOded Gabbay case GAUDI_QUEUE_ID_NIC_2_3:
8667e65e175bSOded Gabbay case GAUDI_QUEUE_ID_NIC_3_3:
8668e65e175bSOded Gabbay case GAUDI_QUEUE_ID_NIC_4_3:
8669e65e175bSOded Gabbay case GAUDI_QUEUE_ID_NIC_5_3:
8670e65e175bSOded Gabbay case GAUDI_QUEUE_ID_NIC_6_3:
8671e65e175bSOded Gabbay case GAUDI_QUEUE_ID_NIC_7_3:
8672e65e175bSOded Gabbay case GAUDI_QUEUE_ID_NIC_8_3:
8673e65e175bSOded Gabbay case GAUDI_QUEUE_ID_NIC_9_3:
8674e65e175bSOded Gabbay nic_index = (queue_id - GAUDI_QUEUE_ID_NIC_0_3) >> 2;
8675e65e175bSOded Gabbay offset = mmNIC0_QM0_CP_FENCE2_RDATA_3 +
8676e65e175bSOded Gabbay (nic_index >> 1) * NIC_MACRO_QMAN_OFFSET +
8677e65e175bSOded Gabbay (nic_index & 0x1) * NIC_ENGINE_QMAN_OFFSET;
8678e65e175bSOded Gabbay break;
8679e65e175bSOded Gabbay default:
8680e65e175bSOded Gabbay return -EINVAL;
8681e65e175bSOded Gabbay }
8682e65e175bSOded Gabbay
8683e65e175bSOded Gabbay *addr = CFG_BASE + offset;
8684e65e175bSOded Gabbay
8685e65e175bSOded Gabbay return 0;
8686e65e175bSOded Gabbay }
8687e65e175bSOded Gabbay
gaudi_add_mon_pkts(void * buf,u16 mon_id,u64 fence_addr)8688e65e175bSOded Gabbay static u32 gaudi_add_mon_pkts(void *buf, u16 mon_id, u64 fence_addr)
8689e65e175bSOded Gabbay {
8690e65e175bSOded Gabbay u64 monitor_base;
8691e65e175bSOded Gabbay u32 size = 0;
8692e65e175bSOded Gabbay u16 msg_addr_offset;
8693e65e175bSOded Gabbay
8694e65e175bSOded Gabbay /*
8695e65e175bSOded Gabbay * monitor_base should be the content of the base0 address registers,
8696e65e175bSOded Gabbay * so it will be added to the msg short offsets
8697e65e175bSOded Gabbay */
8698e65e175bSOded Gabbay monitor_base = mmSYNC_MNGR_W_S_SYNC_MNGR_OBJS_MON_PAY_ADDRL_0;
8699e65e175bSOded Gabbay
8700e65e175bSOded Gabbay /* First monitor config packet: low address of the sync */
8701e65e175bSOded Gabbay msg_addr_offset =
8702e65e175bSOded Gabbay (mmSYNC_MNGR_W_S_SYNC_MNGR_OBJS_MON_PAY_ADDRL_0 + mon_id * 4) -
8703e65e175bSOded Gabbay monitor_base;
8704e65e175bSOded Gabbay
8705e65e175bSOded Gabbay size += gaudi_add_mon_msg_short(buf + size, (u32) fence_addr,
8706e65e175bSOded Gabbay msg_addr_offset);
8707e65e175bSOded Gabbay
8708e65e175bSOded Gabbay /* Second monitor config packet: high address of the sync */
8709e65e175bSOded Gabbay msg_addr_offset =
8710e65e175bSOded Gabbay (mmSYNC_MNGR_W_S_SYNC_MNGR_OBJS_MON_PAY_ADDRH_0 + mon_id * 4) -
8711e65e175bSOded Gabbay monitor_base;
8712e65e175bSOded Gabbay
8713e65e175bSOded Gabbay size += gaudi_add_mon_msg_short(buf + size, (u32) (fence_addr >> 32),
8714e65e175bSOded Gabbay msg_addr_offset);
8715e65e175bSOded Gabbay
8716e65e175bSOded Gabbay /*
8717e65e175bSOded Gabbay * Third monitor config packet: the payload, i.e. what to write when the
8718e65e175bSOded Gabbay * sync triggers
8719e65e175bSOded Gabbay */
8720e65e175bSOded Gabbay msg_addr_offset =
8721e65e175bSOded Gabbay (mmSYNC_MNGR_W_S_SYNC_MNGR_OBJS_MON_PAY_DATA_0 + mon_id * 4) -
8722e65e175bSOded Gabbay monitor_base;
8723e65e175bSOded Gabbay
8724e65e175bSOded Gabbay size += gaudi_add_mon_msg_short(buf + size, 1, msg_addr_offset);
8725e65e175bSOded Gabbay
8726e65e175bSOded Gabbay return size;
8727e65e175bSOded Gabbay }
8728e65e175bSOded Gabbay
gaudi_gen_wait_cb(struct hl_device * hdev,struct hl_gen_wait_properties * prop)8729e65e175bSOded Gabbay static u32 gaudi_gen_wait_cb(struct hl_device *hdev,
8730e65e175bSOded Gabbay struct hl_gen_wait_properties *prop)
8731e65e175bSOded Gabbay {
8732e65e175bSOded Gabbay struct hl_cb *cb = (struct hl_cb *) prop->data;
8733e65e175bSOded Gabbay void *buf = cb->kernel_address;
8734e65e175bSOded Gabbay u64 fence_addr = 0;
8735e65e175bSOded Gabbay u32 size = prop->size;
8736e65e175bSOded Gabbay
8737e65e175bSOded Gabbay if (gaudi_get_fence_addr(hdev, prop->q_idx, &fence_addr)) {
8738e65e175bSOded Gabbay dev_crit(hdev->dev, "wrong queue id %d for wait packet\n",
8739e65e175bSOded Gabbay prop->q_idx);
8740e65e175bSOded Gabbay return 0;
8741e65e175bSOded Gabbay }
8742e65e175bSOded Gabbay
8743e65e175bSOded Gabbay size += gaudi_add_mon_pkts(buf + size, prop->mon_id, fence_addr);
8744e65e175bSOded Gabbay size += gaudi_add_arm_monitor_pkt(hdev, buf + size, prop->sob_base,
8745e65e175bSOded Gabbay prop->sob_mask, prop->sob_val, prop->mon_id);
8746e65e175bSOded Gabbay size += gaudi_add_fence_pkt(buf + size);
8747e65e175bSOded Gabbay
8748e65e175bSOded Gabbay return size;
8749e65e175bSOded Gabbay }
8750e65e175bSOded Gabbay
gaudi_reset_sob(struct hl_device * hdev,void * data)8751e65e175bSOded Gabbay static void gaudi_reset_sob(struct hl_device *hdev, void *data)
8752e65e175bSOded Gabbay {
8753e65e175bSOded Gabbay struct hl_hw_sob *hw_sob = (struct hl_hw_sob *) data;
8754e65e175bSOded Gabbay
8755e65e175bSOded Gabbay dev_dbg(hdev->dev, "reset SOB, q_idx: %d, sob_id: %d\n", hw_sob->q_idx,
8756e65e175bSOded Gabbay hw_sob->sob_id);
8757e65e175bSOded Gabbay
8758e65e175bSOded Gabbay WREG32(mmSYNC_MNGR_W_S_SYNC_MNGR_OBJS_SOB_OBJ_0 +
8759e65e175bSOded Gabbay hw_sob->sob_id * 4, 0);
8760e65e175bSOded Gabbay
8761e65e175bSOded Gabbay kref_init(&hw_sob->kref);
8762e65e175bSOded Gabbay }
8763e65e175bSOded Gabbay
gaudi_get_device_time(struct hl_device * hdev)8764e65e175bSOded Gabbay static u64 gaudi_get_device_time(struct hl_device *hdev)
8765e65e175bSOded Gabbay {
8766e65e175bSOded Gabbay u64 device_time = ((u64) RREG32(mmPSOC_TIMESTAMP_CNTCVU)) << 32;
8767e65e175bSOded Gabbay
8768e65e175bSOded Gabbay return device_time | RREG32(mmPSOC_TIMESTAMP_CNTCVL);
8769e65e175bSOded Gabbay }
8770e65e175bSOded Gabbay
gaudi_get_hw_block_id(struct hl_device * hdev,u64 block_addr,u32 * block_size,u32 * block_id)8771e65e175bSOded Gabbay static int gaudi_get_hw_block_id(struct hl_device *hdev, u64 block_addr,
8772e65e175bSOded Gabbay u32 *block_size, u32 *block_id)
8773e65e175bSOded Gabbay {
8774e65e175bSOded Gabbay return -EPERM;
8775e65e175bSOded Gabbay }
8776e65e175bSOded Gabbay
gaudi_block_mmap(struct hl_device * hdev,struct vm_area_struct * vma,u32 block_id,u32 block_size)8777e65e175bSOded Gabbay static int gaudi_block_mmap(struct hl_device *hdev,
8778e65e175bSOded Gabbay struct vm_area_struct *vma,
8779e65e175bSOded Gabbay u32 block_id, u32 block_size)
8780e65e175bSOded Gabbay {
8781e65e175bSOded Gabbay return -EPERM;
8782e65e175bSOded Gabbay }
8783e65e175bSOded Gabbay
gaudi_enable_events_from_fw(struct hl_device * hdev)8784e65e175bSOded Gabbay static void gaudi_enable_events_from_fw(struct hl_device *hdev)
8785e65e175bSOded Gabbay {
8786e65e175bSOded Gabbay struct cpu_dyn_regs *dyn_regs =
8787e65e175bSOded Gabbay &hdev->fw_loader.dynamic_loader.comm_desc.cpu_dyn_regs;
8788e65e175bSOded Gabbay u32 irq_handler_offset = hdev->asic_prop.gic_interrupts_enable ?
8789e65e175bSOded Gabbay mmGIC_DISTRIBUTOR__5_GICD_SETSPI_NSR :
8790e65e175bSOded Gabbay le32_to_cpu(dyn_regs->gic_host_ints_irq);
8791e65e175bSOded Gabbay
8792e65e175bSOded Gabbay WREG32(irq_handler_offset,
8793e65e175bSOded Gabbay gaudi_irq_map_table[GAUDI_EVENT_INTS_REGISTER].cpu_id);
8794e65e175bSOded Gabbay }
8795e65e175bSOded Gabbay
gaudi_ack_mmu_page_fault_or_access_error(struct hl_device * hdev,u64 mmu_cap_mask)8796e65e175bSOded Gabbay static int gaudi_ack_mmu_page_fault_or_access_error(struct hl_device *hdev, u64 mmu_cap_mask)
8797e65e175bSOded Gabbay {
8798e65e175bSOded Gabbay return -EINVAL;
8799e65e175bSOded Gabbay }
8800e65e175bSOded Gabbay
gaudi_map_pll_idx_to_fw_idx(u32 pll_idx)8801e65e175bSOded Gabbay static int gaudi_map_pll_idx_to_fw_idx(u32 pll_idx)
8802e65e175bSOded Gabbay {
8803e65e175bSOded Gabbay switch (pll_idx) {
8804e65e175bSOded Gabbay case HL_GAUDI_CPU_PLL: return CPU_PLL;
8805e65e175bSOded Gabbay case HL_GAUDI_PCI_PLL: return PCI_PLL;
8806e65e175bSOded Gabbay case HL_GAUDI_NIC_PLL: return NIC_PLL;
8807e65e175bSOded Gabbay case HL_GAUDI_DMA_PLL: return DMA_PLL;
8808e65e175bSOded Gabbay case HL_GAUDI_MESH_PLL: return MESH_PLL;
8809e65e175bSOded Gabbay case HL_GAUDI_MME_PLL: return MME_PLL;
8810e65e175bSOded Gabbay case HL_GAUDI_TPC_PLL: return TPC_PLL;
8811e65e175bSOded Gabbay case HL_GAUDI_IF_PLL: return IF_PLL;
8812e65e175bSOded Gabbay case HL_GAUDI_SRAM_PLL: return SRAM_PLL;
8813e65e175bSOded Gabbay case HL_GAUDI_HBM_PLL: return HBM_PLL;
8814e65e175bSOded Gabbay default: return -EINVAL;
8815e65e175bSOded Gabbay }
8816e65e175bSOded Gabbay }
8817e65e175bSOded Gabbay
gaudi_add_sync_to_engine_map_entry(struct hl_sync_to_engine_map * map,u32 reg_value,enum hl_sync_engine_type engine_type,u32 engine_id)8818e65e175bSOded Gabbay static int gaudi_add_sync_to_engine_map_entry(
8819e65e175bSOded Gabbay struct hl_sync_to_engine_map *map, u32 reg_value,
8820e65e175bSOded Gabbay enum hl_sync_engine_type engine_type, u32 engine_id)
8821e65e175bSOded Gabbay {
8822e65e175bSOded Gabbay struct hl_sync_to_engine_map_entry *entry;
8823e65e175bSOded Gabbay
8824e65e175bSOded Gabbay /* Reg value represents a partial address of sync object,
8825e65e175bSOded Gabbay * it is used as unique identifier. For this we need to
8826e65e175bSOded Gabbay * clear the cutoff cfg base bits from the value.
8827e65e175bSOded Gabbay */
8828e65e175bSOded Gabbay if (reg_value == 0 || reg_value == 0xffffffff)
8829e65e175bSOded Gabbay return 0;
8830e65e175bSOded Gabbay reg_value -= lower_32_bits(CFG_BASE);
8831e65e175bSOded Gabbay
8832e65e175bSOded Gabbay /* create a new hash entry */
8833e65e175bSOded Gabbay entry = kzalloc(sizeof(*entry), GFP_KERNEL);
8834e65e175bSOded Gabbay if (!entry)
8835e65e175bSOded Gabbay return -ENOMEM;
8836e65e175bSOded Gabbay entry->engine_type = engine_type;
8837e65e175bSOded Gabbay entry->engine_id = engine_id;
8838e65e175bSOded Gabbay entry->sync_id = reg_value;
8839e65e175bSOded Gabbay hash_add(map->tb, &entry->node, reg_value);
8840e65e175bSOded Gabbay
8841e65e175bSOded Gabbay return 0;
8842e65e175bSOded Gabbay }
8843e65e175bSOded Gabbay
gaudi_gen_sync_to_engine_map(struct hl_device * hdev,struct hl_sync_to_engine_map * map)8844e65e175bSOded Gabbay static int gaudi_gen_sync_to_engine_map(struct hl_device *hdev,
8845e65e175bSOded Gabbay struct hl_sync_to_engine_map *map)
8846e65e175bSOded Gabbay {
8847e65e175bSOded Gabbay struct hl_state_dump_specs *sds = &hdev->state_dump_specs;
8848e65e175bSOded Gabbay int i, j, rc;
8849e65e175bSOded Gabbay u32 reg_value;
8850e65e175bSOded Gabbay
8851e65e175bSOded Gabbay /* Iterate over TPC engines */
8852e65e175bSOded Gabbay for (i = 0; i < sds->props[SP_NUM_OF_TPC_ENGINES]; ++i) {
8853e65e175bSOded Gabbay
8854e65e175bSOded Gabbay reg_value = RREG32(sds->props[SP_TPC0_CFG_SO] +
8855e65e175bSOded Gabbay sds->props[SP_NEXT_TPC] * i);
8856e65e175bSOded Gabbay
8857e65e175bSOded Gabbay rc = gaudi_add_sync_to_engine_map_entry(map, reg_value,
8858e65e175bSOded Gabbay ENGINE_TPC, i);
8859e65e175bSOded Gabbay if (rc)
8860e65e175bSOded Gabbay goto free_sync_to_engine_map;
8861e65e175bSOded Gabbay }
8862e65e175bSOded Gabbay
8863e65e175bSOded Gabbay /* Iterate over MME engines */
8864e65e175bSOded Gabbay for (i = 0; i < sds->props[SP_NUM_OF_MME_ENGINES]; ++i) {
8865e65e175bSOded Gabbay for (j = 0; j < sds->props[SP_SUB_MME_ENG_NUM]; ++j) {
8866e65e175bSOded Gabbay
8867e65e175bSOded Gabbay reg_value = RREG32(sds->props[SP_MME_CFG_SO] +
8868e65e175bSOded Gabbay sds->props[SP_NEXT_MME] * i +
8869e65e175bSOded Gabbay j * sizeof(u32));
8870e65e175bSOded Gabbay
8871e65e175bSOded Gabbay rc = gaudi_add_sync_to_engine_map_entry(
8872e65e175bSOded Gabbay map, reg_value, ENGINE_MME,
8873e65e175bSOded Gabbay i * sds->props[SP_SUB_MME_ENG_NUM] + j);
8874e65e175bSOded Gabbay if (rc)
8875e65e175bSOded Gabbay goto free_sync_to_engine_map;
8876e65e175bSOded Gabbay }
8877e65e175bSOded Gabbay }
8878e65e175bSOded Gabbay
8879e65e175bSOded Gabbay /* Iterate over DMA engines */
8880e65e175bSOded Gabbay for (i = 0; i < sds->props[SP_NUM_OF_DMA_ENGINES]; ++i) {
8881e65e175bSOded Gabbay reg_value = RREG32(sds->props[SP_DMA_CFG_SO] +
8882e65e175bSOded Gabbay sds->props[SP_DMA_QUEUES_OFFSET] * i);
8883e65e175bSOded Gabbay rc = gaudi_add_sync_to_engine_map_entry(map, reg_value,
8884e65e175bSOded Gabbay ENGINE_DMA, i);
8885e65e175bSOded Gabbay if (rc)
8886e65e175bSOded Gabbay goto free_sync_to_engine_map;
8887e65e175bSOded Gabbay }
8888e65e175bSOded Gabbay
8889e65e175bSOded Gabbay return 0;
8890e65e175bSOded Gabbay
8891e65e175bSOded Gabbay free_sync_to_engine_map:
8892e65e175bSOded Gabbay hl_state_dump_free_sync_to_engine_map(map);
8893e65e175bSOded Gabbay
8894e65e175bSOded Gabbay return rc;
8895e65e175bSOded Gabbay }
8896e65e175bSOded Gabbay
gaudi_monitor_valid(struct hl_mon_state_dump * mon)8897e65e175bSOded Gabbay static int gaudi_monitor_valid(struct hl_mon_state_dump *mon)
8898e65e175bSOded Gabbay {
8899e65e175bSOded Gabbay return FIELD_GET(
8900e65e175bSOded Gabbay SYNC_MNGR_W_S_SYNC_MNGR_OBJS_MON_STATUS_0_VALID_MASK,
8901e65e175bSOded Gabbay mon->status);
8902e65e175bSOded Gabbay }
8903e65e175bSOded Gabbay
gaudi_fill_sobs_from_mon(char * sobs,struct hl_mon_state_dump * mon)8904e65e175bSOded Gabbay static void gaudi_fill_sobs_from_mon(char *sobs, struct hl_mon_state_dump *mon)
8905e65e175bSOded Gabbay {
8906e65e175bSOded Gabbay const size_t max_write = 10;
8907e65e175bSOded Gabbay u32 gid, mask, sob;
8908e65e175bSOded Gabbay int i, offset;
8909e65e175bSOded Gabbay
8910e65e175bSOded Gabbay /* Sync object ID is calculated as follows:
8911e65e175bSOded Gabbay * (8 * group_id + cleared bits in mask)
8912e65e175bSOded Gabbay */
8913e65e175bSOded Gabbay gid = FIELD_GET(SYNC_MNGR_W_S_SYNC_MNGR_OBJS_MON_ARM_0_SID_MASK,
8914e65e175bSOded Gabbay mon->arm_data);
8915e65e175bSOded Gabbay mask = FIELD_GET(SYNC_MNGR_W_S_SYNC_MNGR_OBJS_MON_ARM_0_MASK_MASK,
8916e65e175bSOded Gabbay mon->arm_data);
8917e65e175bSOded Gabbay
8918e65e175bSOded Gabbay for (i = 0, offset = 0; mask && offset < MONITOR_SOB_STRING_SIZE -
8919e65e175bSOded Gabbay max_write; mask >>= 1, i++) {
8920e65e175bSOded Gabbay if (!(mask & 1)) {
8921e65e175bSOded Gabbay sob = gid * MONITOR_MAX_SOBS + i;
8922e65e175bSOded Gabbay
8923e65e175bSOded Gabbay if (offset > 0)
8924e65e175bSOded Gabbay offset += snprintf(sobs + offset, max_write,
8925e65e175bSOded Gabbay ", ");
8926e65e175bSOded Gabbay
8927e65e175bSOded Gabbay offset += snprintf(sobs + offset, max_write, "%u", sob);
8928e65e175bSOded Gabbay }
8929e65e175bSOded Gabbay }
8930e65e175bSOded Gabbay }
8931e65e175bSOded Gabbay
gaudi_print_single_monitor(char ** buf,size_t * size,size_t * offset,struct hl_device * hdev,struct hl_mon_state_dump * mon)8932e65e175bSOded Gabbay static int gaudi_print_single_monitor(char **buf, size_t *size, size_t *offset,
8933e65e175bSOded Gabbay struct hl_device *hdev,
8934e65e175bSOded Gabbay struct hl_mon_state_dump *mon)
8935e65e175bSOded Gabbay {
8936e65e175bSOded Gabbay const char *name;
8937e65e175bSOded Gabbay char scratch_buf1[BIN_REG_STRING_SIZE],
8938e65e175bSOded Gabbay scratch_buf2[BIN_REG_STRING_SIZE];
8939e65e175bSOded Gabbay char monitored_sobs[MONITOR_SOB_STRING_SIZE] = {0};
8940e65e175bSOded Gabbay
8941e65e175bSOded Gabbay name = hl_state_dump_get_monitor_name(hdev, mon);
8942e65e175bSOded Gabbay if (!name)
8943e65e175bSOded Gabbay name = "";
8944e65e175bSOded Gabbay
8945e65e175bSOded Gabbay gaudi_fill_sobs_from_mon(monitored_sobs, mon);
8946e65e175bSOded Gabbay
8947e65e175bSOded Gabbay return hl_snprintf_resize(
8948e65e175bSOded Gabbay buf, size, offset,
8949e65e175bSOded Gabbay "Mon id: %u%s, wait for group id: %u mask %s to reach val: %u and write %u to address 0x%llx. Pending: %s. Means sync objects [%s] are being monitored.",
8950e65e175bSOded Gabbay mon->id, name,
8951e65e175bSOded Gabbay FIELD_GET(SYNC_MNGR_W_S_SYNC_MNGR_OBJS_MON_ARM_0_SID_MASK,
8952e65e175bSOded Gabbay mon->arm_data),
8953e65e175bSOded Gabbay hl_format_as_binary(
8954e65e175bSOded Gabbay scratch_buf1, sizeof(scratch_buf1),
8955e65e175bSOded Gabbay FIELD_GET(
8956e65e175bSOded Gabbay SYNC_MNGR_W_S_SYNC_MNGR_OBJS_MON_ARM_0_MASK_MASK,
8957e65e175bSOded Gabbay mon->arm_data)),
8958e65e175bSOded Gabbay FIELD_GET(SYNC_MNGR_W_S_SYNC_MNGR_OBJS_MON_ARM_0_SOD_MASK,
8959e65e175bSOded Gabbay mon->arm_data),
8960e65e175bSOded Gabbay mon->wr_data,
8961e65e175bSOded Gabbay (((u64)mon->wr_addr_high) << 32) | mon->wr_addr_low,
8962e65e175bSOded Gabbay hl_format_as_binary(
8963e65e175bSOded Gabbay scratch_buf2, sizeof(scratch_buf2),
8964e65e175bSOded Gabbay FIELD_GET(
8965e65e175bSOded Gabbay SYNC_MNGR_W_S_SYNC_MNGR_OBJS_MON_STATUS_0_PENDING_MASK,
8966e65e175bSOded Gabbay mon->status)),
8967e65e175bSOded Gabbay monitored_sobs);
8968e65e175bSOded Gabbay }
8969e65e175bSOded Gabbay
8970e65e175bSOded Gabbay
gaudi_print_fences_single_engine(struct hl_device * hdev,u64 base_offset,u64 status_base_offset,enum hl_sync_engine_type engine_type,u32 engine_id,char ** buf,size_t * size,size_t * offset)8971e65e175bSOded Gabbay static int gaudi_print_fences_single_engine(
8972e65e175bSOded Gabbay struct hl_device *hdev, u64 base_offset, u64 status_base_offset,
8973e65e175bSOded Gabbay enum hl_sync_engine_type engine_type, u32 engine_id, char **buf,
8974e65e175bSOded Gabbay size_t *size, size_t *offset)
8975e65e175bSOded Gabbay {
8976e65e175bSOded Gabbay struct hl_state_dump_specs *sds = &hdev->state_dump_specs;
8977e65e175bSOded Gabbay int rc = -ENOMEM, i;
8978e65e175bSOded Gabbay u32 *statuses, *fences;
8979e65e175bSOded Gabbay
8980e65e175bSOded Gabbay statuses = kcalloc(sds->props[SP_ENGINE_NUM_OF_QUEUES],
8981e65e175bSOded Gabbay sizeof(*statuses), GFP_KERNEL);
8982e65e175bSOded Gabbay if (!statuses)
8983e65e175bSOded Gabbay goto out;
8984e65e175bSOded Gabbay
8985e65e175bSOded Gabbay fences = kcalloc(sds->props[SP_ENGINE_NUM_OF_FENCES] *
8986e65e175bSOded Gabbay sds->props[SP_ENGINE_NUM_OF_QUEUES],
8987e65e175bSOded Gabbay sizeof(*fences), GFP_KERNEL);
8988e65e175bSOded Gabbay if (!fences)
8989e65e175bSOded Gabbay goto free_status;
8990e65e175bSOded Gabbay
8991e65e175bSOded Gabbay for (i = 0; i < sds->props[SP_ENGINE_NUM_OF_FENCES]; ++i)
8992e65e175bSOded Gabbay statuses[i] = RREG32(status_base_offset + i * sizeof(u32));
8993e65e175bSOded Gabbay
8994e65e175bSOded Gabbay for (i = 0; i < sds->props[SP_ENGINE_NUM_OF_FENCES] *
8995e65e175bSOded Gabbay sds->props[SP_ENGINE_NUM_OF_QUEUES]; ++i)
8996e65e175bSOded Gabbay fences[i] = RREG32(base_offset + i * sizeof(u32));
8997e65e175bSOded Gabbay
8998e65e175bSOded Gabbay /* The actual print */
8999e65e175bSOded Gabbay for (i = 0; i < sds->props[SP_ENGINE_NUM_OF_QUEUES]; ++i) {
9000e65e175bSOded Gabbay u32 fence_id;
9001e65e175bSOded Gabbay u64 fence_cnt, fence_rdata;
9002e65e175bSOded Gabbay const char *engine_name;
9003e65e175bSOded Gabbay
9004e65e175bSOded Gabbay if (!FIELD_GET(TPC0_QM_CP_STS_0_FENCE_IN_PROGRESS_MASK,
9005e65e175bSOded Gabbay statuses[i]))
9006e65e175bSOded Gabbay continue;
9007e65e175bSOded Gabbay
9008e65e175bSOded Gabbay fence_id =
9009e65e175bSOded Gabbay FIELD_GET(TPC0_QM_CP_STS_0_FENCE_ID_MASK, statuses[i]);
9010e65e175bSOded Gabbay fence_cnt = base_offset + CFG_BASE +
9011e65e175bSOded Gabbay sizeof(u32) *
9012e65e175bSOded Gabbay (i + fence_id * sds->props[SP_ENGINE_NUM_OF_QUEUES]);
9013e65e175bSOded Gabbay fence_rdata = fence_cnt - sds->props[SP_FENCE0_CNT_OFFSET] +
9014e65e175bSOded Gabbay sds->props[SP_FENCE0_RDATA_OFFSET];
9015e65e175bSOded Gabbay engine_name = hl_sync_engine_to_string(engine_type);
9016e65e175bSOded Gabbay
9017e65e175bSOded Gabbay rc = hl_snprintf_resize(
9018e65e175bSOded Gabbay buf, size, offset,
9019e65e175bSOded Gabbay "%s%u, stream %u: fence id %u cnt = 0x%llx (%s%u_QM.CP_FENCE%u_CNT_%u) rdata = 0x%llx (%s%u_QM.CP_FENCE%u_RDATA_%u) value = %u, cp_status = %u\n",
9020e65e175bSOded Gabbay engine_name, engine_id,
9021e65e175bSOded Gabbay i, fence_id,
9022e65e175bSOded Gabbay fence_cnt, engine_name, engine_id, fence_id, i,
9023e65e175bSOded Gabbay fence_rdata, engine_name, engine_id, fence_id, i,
9024e65e175bSOded Gabbay fences[fence_id],
9025e65e175bSOded Gabbay statuses[i]);
9026e65e175bSOded Gabbay if (rc)
9027e65e175bSOded Gabbay goto free_fences;
9028e65e175bSOded Gabbay }
9029e65e175bSOded Gabbay
9030e65e175bSOded Gabbay rc = 0;
9031e65e175bSOded Gabbay
9032e65e175bSOded Gabbay free_fences:
9033e65e175bSOded Gabbay kfree(fences);
9034e65e175bSOded Gabbay free_status:
9035e65e175bSOded Gabbay kfree(statuses);
9036e65e175bSOded Gabbay out:
9037e65e175bSOded Gabbay return rc;
9038e65e175bSOded Gabbay }
9039e65e175bSOded Gabbay
9040e65e175bSOded Gabbay
9041e65e175bSOded Gabbay static struct hl_state_dump_specs_funcs gaudi_state_dump_funcs = {
9042e65e175bSOded Gabbay .monitor_valid = gaudi_monitor_valid,
9043e65e175bSOded Gabbay .print_single_monitor = gaudi_print_single_monitor,
9044e65e175bSOded Gabbay .gen_sync_to_engine_map = gaudi_gen_sync_to_engine_map,
9045e65e175bSOded Gabbay .print_fences_single_engine = gaudi_print_fences_single_engine,
9046e65e175bSOded Gabbay };
9047e65e175bSOded Gabbay
gaudi_state_dump_init(struct hl_device * hdev)9048e65e175bSOded Gabbay static void gaudi_state_dump_init(struct hl_device *hdev)
9049e65e175bSOded Gabbay {
9050e65e175bSOded Gabbay struct hl_state_dump_specs *sds = &hdev->state_dump_specs;
9051e65e175bSOded Gabbay int i;
9052e65e175bSOded Gabbay
9053e65e175bSOded Gabbay for (i = 0; i < ARRAY_SIZE(gaudi_so_id_to_str); ++i)
9054e65e175bSOded Gabbay hash_add(sds->so_id_to_str_tb,
9055e65e175bSOded Gabbay &gaudi_so_id_to_str[i].node,
9056e65e175bSOded Gabbay gaudi_so_id_to_str[i].id);
9057e65e175bSOded Gabbay
9058e65e175bSOded Gabbay for (i = 0; i < ARRAY_SIZE(gaudi_monitor_id_to_str); ++i)
9059e65e175bSOded Gabbay hash_add(sds->monitor_id_to_str_tb,
9060e65e175bSOded Gabbay &gaudi_monitor_id_to_str[i].node,
9061e65e175bSOded Gabbay gaudi_monitor_id_to_str[i].id);
9062e65e175bSOded Gabbay
9063e65e175bSOded Gabbay sds->props = gaudi_state_dump_specs_props;
9064e65e175bSOded Gabbay
9065e65e175bSOded Gabbay sds->sync_namager_names = gaudi_sync_manager_names;
9066e65e175bSOded Gabbay
9067e65e175bSOded Gabbay sds->funcs = gaudi_state_dump_funcs;
9068e65e175bSOded Gabbay }
9069e65e175bSOded Gabbay
gaudi_get_stream_master_qid_arr(void)9070e65e175bSOded Gabbay static u32 *gaudi_get_stream_master_qid_arr(void)
9071e65e175bSOded Gabbay {
9072e65e175bSOded Gabbay return gaudi_stream_master;
9073e65e175bSOded Gabbay }
9074e65e175bSOded Gabbay
gaudi_set_dram_properties(struct hl_device * hdev)9075e65e175bSOded Gabbay static int gaudi_set_dram_properties(struct hl_device *hdev)
9076e65e175bSOded Gabbay {
9077e65e175bSOded Gabbay return 0;
9078e65e175bSOded Gabbay }
9079e65e175bSOded Gabbay
gaudi_set_binning_masks(struct hl_device * hdev)9080e65e175bSOded Gabbay static int gaudi_set_binning_masks(struct hl_device *hdev)
9081e65e175bSOded Gabbay {
9082e65e175bSOded Gabbay return 0;
9083e65e175bSOded Gabbay }
9084e65e175bSOded Gabbay
gaudi_check_if_razwi_happened(struct hl_device * hdev)9085e65e175bSOded Gabbay static void gaudi_check_if_razwi_happened(struct hl_device *hdev)
9086e65e175bSOded Gabbay {
9087e65e175bSOded Gabbay }
9088e65e175bSOded Gabbay
infineon_ver_show(struct device * dev,struct device_attribute * attr,char * buf)9089e65e175bSOded Gabbay static ssize_t infineon_ver_show(struct device *dev, struct device_attribute *attr, char *buf)
9090e65e175bSOded Gabbay {
9091ab509d81SOhad Sharabi struct hl_device *hdev = dev_get_drvdata(dev);
9092ab509d81SOhad Sharabi struct cpucp_info *cpucp_info;
9093ab509d81SOhad Sharabi
9094ab509d81SOhad Sharabi cpucp_info = &hdev->asic_prop.cpucp_info;
9095ab509d81SOhad Sharabi
9096e65e175bSOded Gabbay return sprintf(buf, "%#04x\n", le32_to_cpu(cpucp_info->infineon_version));
9097e65e175bSOded Gabbay }
9098e65e175bSOded Gabbay
9099e65e175bSOded Gabbay static DEVICE_ATTR_RO(infineon_ver);
9100e65e175bSOded Gabbay
9101e65e175bSOded Gabbay static struct attribute *gaudi_vrm_dev_attrs[] = {
9102e65e175bSOded Gabbay &dev_attr_infineon_ver.attr,
9103e65e175bSOded Gabbay NULL,
9104e65e175bSOded Gabbay };
9105e65e175bSOded Gabbay
gaudi_add_device_attr(struct hl_device * hdev,struct attribute_group * dev_clk_attr_grp,struct attribute_group * dev_vrm_attr_grp)9106e65e175bSOded Gabbay static void gaudi_add_device_attr(struct hl_device *hdev, struct attribute_group *dev_clk_attr_grp,
9107e65e175bSOded Gabbay struct attribute_group *dev_vrm_attr_grp)
9108e65e175bSOded Gabbay {
9109e65e175bSOded Gabbay hl_sysfs_add_dev_clk_attr(hdev, dev_clk_attr_grp);
9110e65e175bSOded Gabbay dev_vrm_attr_grp->attrs = gaudi_vrm_dev_attrs;
9111e65e175bSOded Gabbay }
9112e65e175bSOded Gabbay
gaudi_send_device_activity(struct hl_device * hdev,bool open)9113e65e175bSOded Gabbay static int gaudi_send_device_activity(struct hl_device *hdev, bool open)
9114e65e175bSOded Gabbay {
9115e65e175bSOded Gabbay return 0;
9116e65e175bSOded Gabbay }
9117e65e175bSOded Gabbay
9118e65e175bSOded Gabbay static const struct hl_asic_funcs gaudi_funcs = {
9119e65e175bSOded Gabbay .early_init = gaudi_early_init,
9120e65e175bSOded Gabbay .early_fini = gaudi_early_fini,
9121e65e175bSOded Gabbay .late_init = gaudi_late_init,
9122e65e175bSOded Gabbay .late_fini = gaudi_late_fini,
9123e65e175bSOded Gabbay .sw_init = gaudi_sw_init,
9124e65e175bSOded Gabbay .sw_fini = gaudi_sw_fini,
9125e65e175bSOded Gabbay .hw_init = gaudi_hw_init,
9126e65e175bSOded Gabbay .hw_fini = gaudi_hw_fini,
9127e65e175bSOded Gabbay .halt_engines = gaudi_halt_engines,
9128e65e175bSOded Gabbay .suspend = gaudi_suspend,
9129e65e175bSOded Gabbay .resume = gaudi_resume,
9130e65e175bSOded Gabbay .mmap = gaudi_mmap,
9131e65e175bSOded Gabbay .ring_doorbell = gaudi_ring_doorbell,
9132e65e175bSOded Gabbay .pqe_write = gaudi_pqe_write,
9133e65e175bSOded Gabbay .asic_dma_alloc_coherent = gaudi_dma_alloc_coherent,
9134e65e175bSOded Gabbay .asic_dma_free_coherent = gaudi_dma_free_coherent,
9135e65e175bSOded Gabbay .scrub_device_mem = gaudi_scrub_device_mem,
9136e65e175bSOded Gabbay .scrub_device_dram = gaudi_scrub_device_dram,
9137e65e175bSOded Gabbay .get_int_queue_base = gaudi_get_int_queue_base,
9138e65e175bSOded Gabbay .test_queues = gaudi_test_queues,
9139e65e175bSOded Gabbay .asic_dma_pool_zalloc = gaudi_dma_pool_zalloc,
9140e65e175bSOded Gabbay .asic_dma_pool_free = gaudi_dma_pool_free,
9141e65e175bSOded Gabbay .cpu_accessible_dma_pool_alloc = gaudi_cpu_accessible_dma_pool_alloc,
9142e65e175bSOded Gabbay .cpu_accessible_dma_pool_free = gaudi_cpu_accessible_dma_pool_free,
9143e65e175bSOded Gabbay .hl_dma_unmap_sgtable = hl_dma_unmap_sgtable,
9144e65e175bSOded Gabbay .cs_parser = gaudi_cs_parser,
9145e65e175bSOded Gabbay .asic_dma_map_sgtable = hl_dma_map_sgtable,
9146e65e175bSOded Gabbay .add_end_of_cb_packets = gaudi_add_end_of_cb_packets,
9147e65e175bSOded Gabbay .update_eq_ci = gaudi_update_eq_ci,
9148e65e175bSOded Gabbay .context_switch = gaudi_context_switch,
9149e65e175bSOded Gabbay .restore_phase_topology = gaudi_restore_phase_topology,
9150e65e175bSOded Gabbay .debugfs_read_dma = gaudi_debugfs_read_dma,
9151e65e175bSOded Gabbay .add_device_attr = gaudi_add_device_attr,
9152e65e175bSOded Gabbay .handle_eqe = gaudi_handle_eqe,
9153e65e175bSOded Gabbay .get_events_stat = gaudi_get_events_stat,
9154e65e175bSOded Gabbay .read_pte = gaudi_read_pte,
9155e65e175bSOded Gabbay .write_pte = gaudi_write_pte,
9156e65e175bSOded Gabbay .mmu_invalidate_cache = gaudi_mmu_invalidate_cache,
9157e65e175bSOded Gabbay .mmu_invalidate_cache_range = gaudi_mmu_invalidate_cache_range,
9158e65e175bSOded Gabbay .mmu_prefetch_cache_range = NULL,
9159e65e175bSOded Gabbay .send_heartbeat = gaudi_send_heartbeat,
9160e65e175bSOded Gabbay .debug_coresight = gaudi_debug_coresight,
9161e65e175bSOded Gabbay .is_device_idle = gaudi_is_device_idle,
9162e65e175bSOded Gabbay .compute_reset_late_init = gaudi_compute_reset_late_init,
9163e65e175bSOded Gabbay .hw_queues_lock = gaudi_hw_queues_lock,
9164e65e175bSOded Gabbay .hw_queues_unlock = gaudi_hw_queues_unlock,
9165e65e175bSOded Gabbay .get_pci_id = gaudi_get_pci_id,
9166e65e175bSOded Gabbay .get_eeprom_data = gaudi_get_eeprom_data,
9167e65e175bSOded Gabbay .get_monitor_dump = gaudi_get_monitor_dump,
9168e65e175bSOded Gabbay .send_cpu_message = gaudi_send_cpu_message,
9169e65e175bSOded Gabbay .pci_bars_map = gaudi_pci_bars_map,
9170e65e175bSOded Gabbay .init_iatu = gaudi_init_iatu,
9171e65e175bSOded Gabbay .rreg = hl_rreg,
9172e65e175bSOded Gabbay .wreg = hl_wreg,
9173e65e175bSOded Gabbay .halt_coresight = gaudi_halt_coresight,
9174e65e175bSOded Gabbay .ctx_init = gaudi_ctx_init,
9175e65e175bSOded Gabbay .ctx_fini = gaudi_ctx_fini,
9176e65e175bSOded Gabbay .pre_schedule_cs = gaudi_pre_schedule_cs,
9177e65e175bSOded Gabbay .get_queue_id_for_cq = gaudi_get_queue_id_for_cq,
9178e65e175bSOded Gabbay .load_firmware_to_device = gaudi_load_firmware_to_device,
9179e65e175bSOded Gabbay .load_boot_fit_to_device = gaudi_load_boot_fit_to_device,
9180e65e175bSOded Gabbay .get_signal_cb_size = gaudi_get_signal_cb_size,
9181e65e175bSOded Gabbay .get_wait_cb_size = gaudi_get_wait_cb_size,
9182e65e175bSOded Gabbay .gen_signal_cb = gaudi_gen_signal_cb,
9183e65e175bSOded Gabbay .gen_wait_cb = gaudi_gen_wait_cb,
9184e65e175bSOded Gabbay .reset_sob = gaudi_reset_sob,
9185e65e175bSOded Gabbay .reset_sob_group = gaudi_reset_sob_group,
9186e65e175bSOded Gabbay .get_device_time = gaudi_get_device_time,
9187e65e175bSOded Gabbay .pb_print_security_errors = NULL,
9188e65e175bSOded Gabbay .collective_wait_init_cs = gaudi_collective_wait_init_cs,
9189e65e175bSOded Gabbay .collective_wait_create_jobs = gaudi_collective_wait_create_jobs,
9190e65e175bSOded Gabbay .get_dec_base_addr = NULL,
9191e65e175bSOded Gabbay .scramble_addr = hl_mmu_scramble_addr,
9192e65e175bSOded Gabbay .descramble_addr = hl_mmu_descramble_addr,
9193e65e175bSOded Gabbay .ack_protection_bits_errors = gaudi_ack_protection_bits_errors,
9194e65e175bSOded Gabbay .get_hw_block_id = gaudi_get_hw_block_id,
9195e65e175bSOded Gabbay .hw_block_mmap = gaudi_block_mmap,
9196e65e175bSOded Gabbay .enable_events_from_fw = gaudi_enable_events_from_fw,
9197e65e175bSOded Gabbay .ack_mmu_errors = gaudi_ack_mmu_page_fault_or_access_error,
9198e65e175bSOded Gabbay .map_pll_idx_to_fw_idx = gaudi_map_pll_idx_to_fw_idx,
9199e65e175bSOded Gabbay .init_firmware_preload_params = gaudi_init_firmware_preload_params,
9200e65e175bSOded Gabbay .init_firmware_loader = gaudi_init_firmware_loader,
9201e65e175bSOded Gabbay .init_cpu_scrambler_dram = gaudi_init_scrambler_hbm,
9202e65e175bSOded Gabbay .state_dump_init = gaudi_state_dump_init,
9203e65e175bSOded Gabbay .get_sob_addr = gaudi_get_sob_addr,
9204e65e175bSOded Gabbay .set_pci_memory_regions = gaudi_set_pci_memory_regions,
9205e65e175bSOded Gabbay .get_stream_master_qid_arr = gaudi_get_stream_master_qid_arr,
9206e65e175bSOded Gabbay .check_if_razwi_happened = gaudi_check_if_razwi_happened,
9207e65e175bSOded Gabbay .mmu_get_real_page_size = hl_mmu_get_real_page_size,
9208e65e175bSOded Gabbay .access_dev_mem = hl_access_dev_mem,
9209e65e175bSOded Gabbay .set_dram_bar_base = gaudi_set_hbm_bar_base,
9210e65e175bSOded Gabbay .send_device_activity = gaudi_send_device_activity,
9211e65e175bSOded Gabbay .set_dram_properties = gaudi_set_dram_properties,
9212e65e175bSOded Gabbay .set_binning_masks = gaudi_set_binning_masks,
9213e65e175bSOded Gabbay };
9214e65e175bSOded Gabbay
9215e65e175bSOded Gabbay /**
9216e65e175bSOded Gabbay * gaudi_set_asic_funcs - set GAUDI function pointers
9217e65e175bSOded Gabbay *
9218e65e175bSOded Gabbay * @hdev: pointer to hl_device structure
9219e65e175bSOded Gabbay *
9220e65e175bSOded Gabbay */
gaudi_set_asic_funcs(struct hl_device * hdev)9221e65e175bSOded Gabbay void gaudi_set_asic_funcs(struct hl_device *hdev)
9222e65e175bSOded Gabbay {
9223ab509d81SOhad Sharabi hdev->asic_funcs = &gaudi_funcs;
9224e65e175bSOded Gabbay }
9225e65e175bSOded Gabbay