1 // SPDX-License-Identifier: GPL-2.0
4 * Copyright 2016-2019 HabanaLabs, Ltd.
9 #include "include/hw_ip/mmu/mmu_general.h"
10 #include "include/hw_ip/mmu/mmu_v1_0.h"
11 #include "include/goya/asic_reg/goya_masks.h"
12 #include "include/goya/goya_reg_map.h"
14 #include <linux/pci.h>
15 #include <linux/genalloc.h>
16 #include <linux/hwmon.h>
17 #include <linux/io-64-nonatomic-lo-hi.h>
18 #include <linux/iommu.h>
19 #include <linux/seq_file.h>
22 * GOYA security scheme:
24 * 1. Host is protected by:
25 * - Range registers (When MMU is enabled, DMA RR does NOT protect host)
28 * 2. DRAM is protected by:
29 * - Range registers (protect the first 512MB)
30 * - MMU (isolation between users)
32 * 3. Configuration is protected by:
36 * When MMU is disabled:
38 * QMAN DMA: PQ, CQ, CP, DMA are secured.
39 * PQ, CB and the data are on the host.
42 * PQ, CQ and CP are not secured.
43 * PQ, CB and the data are on the SRAM/DRAM.
45 * Since QMAN DMA is secured, the driver is parsing the DMA CB:
46 * - checks DMA pointer
47 * - WREG, MSG_PROT are not allowed.
48 * - MSG_LONG/SHORT are allowed.
50 * A read/write transaction by the QMAN to a protected area will succeed if
51 * and only if the QMAN's CP is secured and MSG_PROT is used
54 * When MMU is enabled:
56 * QMAN DMA: PQ, CQ and CP are secured.
57 * MMU is set to bypass on the Secure props register of the QMAN.
58 * The reasons we don't enable MMU for PQ, CQ and CP are:
59 * - PQ entry is in kernel address space and the driver doesn't map it.
60 * - CP writes to MSIX register and to kernel address space (completion
63 * DMA is not secured but because CP is secured, the driver still needs to parse
64 * the CB, but doesn't need to check the DMA addresses.
66 * For QMAN DMA 0, DMA is also secured because only the driver uses this DMA and
67 * the driver doesn't map memory in MMU.
69 * QMAN TPC/MME: PQ, CQ and CP aren't secured (no change from MMU disabled mode)
71 * DMA RR does NOT protect host because DMA is not secured
75 #define GOYA_UBOOT_FW_FILE "habanalabs/goya/goya-u-boot.bin"
76 #define GOYA_LINUX_FW_FILE "habanalabs/goya/goya-fit.itb"
78 #define GOYA_MMU_REGS_NUM 63
80 #define GOYA_DMA_POOL_BLK_SIZE 0x100 /* 256 bytes */
82 #define GOYA_RESET_TIMEOUT_MSEC 500 /* 500ms */
83 #define GOYA_PLDM_RESET_TIMEOUT_MSEC 20000 /* 20s */
84 #define GOYA_RESET_WAIT_MSEC 1 /* 1ms */
85 #define GOYA_CPU_RESET_WAIT_MSEC 100 /* 100ms */
86 #define GOYA_PLDM_RESET_WAIT_MSEC 1000 /* 1s */
87 #define GOYA_TEST_QUEUE_WAIT_USEC 100000 /* 100ms */
88 #define GOYA_PLDM_MMU_TIMEOUT_USEC (MMU_CONFIG_TIMEOUT_USEC * 100)
89 #define GOYA_PLDM_QMAN0_TIMEOUT_USEC (HL_DEVICE_TIMEOUT_USEC * 30)
91 #define GOYA_QMAN0_FENCE_VAL 0xD169B243
93 #define GOYA_MAX_STRING_LEN 20
95 #define GOYA_CB_POOL_CB_CNT 512
96 #define GOYA_CB_POOL_CB_SIZE 0x20000 /* 128KB */
98 #define IS_QM_IDLE(engine, qm_glbl_sts0) \
99 (((qm_glbl_sts0) & engine##_QM_IDLE_MASK) == engine##_QM_IDLE_MASK)
100 #define IS_DMA_QM_IDLE(qm_glbl_sts0) IS_QM_IDLE(DMA, qm_glbl_sts0)
101 #define IS_TPC_QM_IDLE(qm_glbl_sts0) IS_QM_IDLE(TPC, qm_glbl_sts0)
102 #define IS_MME_QM_IDLE(qm_glbl_sts0) IS_QM_IDLE(MME, qm_glbl_sts0)
104 #define IS_CMDQ_IDLE(engine, cmdq_glbl_sts0) \
105 (((cmdq_glbl_sts0) & engine##_CMDQ_IDLE_MASK) == \
106 engine##_CMDQ_IDLE_MASK)
107 #define IS_TPC_CMDQ_IDLE(cmdq_glbl_sts0) \
108 IS_CMDQ_IDLE(TPC, cmdq_glbl_sts0)
109 #define IS_MME_CMDQ_IDLE(cmdq_glbl_sts0) \
110 IS_CMDQ_IDLE(MME, cmdq_glbl_sts0)
112 #define IS_DMA_IDLE(dma_core_sts0) \
113 !((dma_core_sts0) & DMA_CH_0_STS0_DMA_BUSY_MASK)
115 #define IS_TPC_IDLE(tpc_cfg_sts) \
116 (((tpc_cfg_sts) & TPC_CFG_IDLE_MASK) == TPC_CFG_IDLE_MASK)
118 #define IS_MME_IDLE(mme_arch_sts) \
119 (((mme_arch_sts) & MME_ARCH_IDLE_MASK) == MME_ARCH_IDLE_MASK)
122 static const char goya_irq_name
[GOYA_MSIX_ENTRIES
][GOYA_MAX_STRING_LEN
] = {
123 "goya cq 0", "goya cq 1", "goya cq 2", "goya cq 3",
124 "goya cq 4", "goya cpu eq"
127 static u16 goya_packet_sizes
[MAX_PACKET_ID
] = {
128 [PACKET_WREG_32
] = sizeof(struct packet_wreg32
),
129 [PACKET_WREG_BULK
] = sizeof(struct packet_wreg_bulk
),
130 [PACKET_MSG_LONG
] = sizeof(struct packet_msg_long
),
131 [PACKET_MSG_SHORT
] = sizeof(struct packet_msg_short
),
132 [PACKET_CP_DMA
] = sizeof(struct packet_cp_dma
),
133 [PACKET_MSG_PROT
] = sizeof(struct packet_msg_prot
),
134 [PACKET_FENCE
] = sizeof(struct packet_fence
),
135 [PACKET_LIN_DMA
] = sizeof(struct packet_lin_dma
),
136 [PACKET_NOP
] = sizeof(struct packet_nop
),
137 [PACKET_STOP
] = sizeof(struct packet_stop
)
140 static u64 goya_mmu_regs
[GOYA_MMU_REGS_NUM
] = {
141 mmDMA_QM_0_GLBL_NON_SECURE_PROPS
,
142 mmDMA_QM_1_GLBL_NON_SECURE_PROPS
,
143 mmDMA_QM_2_GLBL_NON_SECURE_PROPS
,
144 mmDMA_QM_3_GLBL_NON_SECURE_PROPS
,
145 mmDMA_QM_4_GLBL_NON_SECURE_PROPS
,
146 mmTPC0_QM_GLBL_SECURE_PROPS
,
147 mmTPC0_QM_GLBL_NON_SECURE_PROPS
,
148 mmTPC0_CMDQ_GLBL_SECURE_PROPS
,
149 mmTPC0_CMDQ_GLBL_NON_SECURE_PROPS
,
152 mmTPC1_QM_GLBL_SECURE_PROPS
,
153 mmTPC1_QM_GLBL_NON_SECURE_PROPS
,
154 mmTPC1_CMDQ_GLBL_SECURE_PROPS
,
155 mmTPC1_CMDQ_GLBL_NON_SECURE_PROPS
,
158 mmTPC2_QM_GLBL_SECURE_PROPS
,
159 mmTPC2_QM_GLBL_NON_SECURE_PROPS
,
160 mmTPC2_CMDQ_GLBL_SECURE_PROPS
,
161 mmTPC2_CMDQ_GLBL_NON_SECURE_PROPS
,
164 mmTPC3_QM_GLBL_SECURE_PROPS
,
165 mmTPC3_QM_GLBL_NON_SECURE_PROPS
,
166 mmTPC3_CMDQ_GLBL_SECURE_PROPS
,
167 mmTPC3_CMDQ_GLBL_NON_SECURE_PROPS
,
170 mmTPC4_QM_GLBL_SECURE_PROPS
,
171 mmTPC4_QM_GLBL_NON_SECURE_PROPS
,
172 mmTPC4_CMDQ_GLBL_SECURE_PROPS
,
173 mmTPC4_CMDQ_GLBL_NON_SECURE_PROPS
,
176 mmTPC5_QM_GLBL_SECURE_PROPS
,
177 mmTPC5_QM_GLBL_NON_SECURE_PROPS
,
178 mmTPC5_CMDQ_GLBL_SECURE_PROPS
,
179 mmTPC5_CMDQ_GLBL_NON_SECURE_PROPS
,
182 mmTPC6_QM_GLBL_SECURE_PROPS
,
183 mmTPC6_QM_GLBL_NON_SECURE_PROPS
,
184 mmTPC6_CMDQ_GLBL_SECURE_PROPS
,
185 mmTPC6_CMDQ_GLBL_NON_SECURE_PROPS
,
188 mmTPC7_QM_GLBL_SECURE_PROPS
,
189 mmTPC7_QM_GLBL_NON_SECURE_PROPS
,
190 mmTPC7_CMDQ_GLBL_SECURE_PROPS
,
191 mmTPC7_CMDQ_GLBL_NON_SECURE_PROPS
,
194 mmMME_QM_GLBL_SECURE_PROPS
,
195 mmMME_QM_GLBL_NON_SECURE_PROPS
,
196 mmMME_CMDQ_GLBL_SECURE_PROPS
,
197 mmMME_CMDQ_GLBL_NON_SECURE_PROPS
,
198 mmMME_SBA_CONTROL_DATA
,
199 mmMME_SBB_CONTROL_DATA
,
200 mmMME_SBC_CONTROL_DATA
,
201 mmMME_WBC_CONTROL_DATA
,
202 mmPCIE_WRAP_PSOC_ARUSER
,
203 mmPCIE_WRAP_PSOC_AWUSER
206 static u32 goya_all_events
[] = {
207 GOYA_ASYNC_EVENT_ID_PCIE_IF
,
208 GOYA_ASYNC_EVENT_ID_TPC0_ECC
,
209 GOYA_ASYNC_EVENT_ID_TPC1_ECC
,
210 GOYA_ASYNC_EVENT_ID_TPC2_ECC
,
211 GOYA_ASYNC_EVENT_ID_TPC3_ECC
,
212 GOYA_ASYNC_EVENT_ID_TPC4_ECC
,
213 GOYA_ASYNC_EVENT_ID_TPC5_ECC
,
214 GOYA_ASYNC_EVENT_ID_TPC6_ECC
,
215 GOYA_ASYNC_EVENT_ID_TPC7_ECC
,
216 GOYA_ASYNC_EVENT_ID_MME_ECC
,
217 GOYA_ASYNC_EVENT_ID_MME_ECC_EXT
,
218 GOYA_ASYNC_EVENT_ID_MMU_ECC
,
219 GOYA_ASYNC_EVENT_ID_DMA_MACRO
,
220 GOYA_ASYNC_EVENT_ID_DMA_ECC
,
221 GOYA_ASYNC_EVENT_ID_CPU_IF_ECC
,
222 GOYA_ASYNC_EVENT_ID_PSOC_MEM
,
223 GOYA_ASYNC_EVENT_ID_PSOC_CORESIGHT
,
224 GOYA_ASYNC_EVENT_ID_SRAM0
,
225 GOYA_ASYNC_EVENT_ID_SRAM1
,
226 GOYA_ASYNC_EVENT_ID_SRAM2
,
227 GOYA_ASYNC_EVENT_ID_SRAM3
,
228 GOYA_ASYNC_EVENT_ID_SRAM4
,
229 GOYA_ASYNC_EVENT_ID_SRAM5
,
230 GOYA_ASYNC_EVENT_ID_SRAM6
,
231 GOYA_ASYNC_EVENT_ID_SRAM7
,
232 GOYA_ASYNC_EVENT_ID_SRAM8
,
233 GOYA_ASYNC_EVENT_ID_SRAM9
,
234 GOYA_ASYNC_EVENT_ID_SRAM10
,
235 GOYA_ASYNC_EVENT_ID_SRAM11
,
236 GOYA_ASYNC_EVENT_ID_SRAM12
,
237 GOYA_ASYNC_EVENT_ID_SRAM13
,
238 GOYA_ASYNC_EVENT_ID_SRAM14
,
239 GOYA_ASYNC_EVENT_ID_SRAM15
,
240 GOYA_ASYNC_EVENT_ID_SRAM16
,
241 GOYA_ASYNC_EVENT_ID_SRAM17
,
242 GOYA_ASYNC_EVENT_ID_SRAM18
,
243 GOYA_ASYNC_EVENT_ID_SRAM19
,
244 GOYA_ASYNC_EVENT_ID_SRAM20
,
245 GOYA_ASYNC_EVENT_ID_SRAM21
,
246 GOYA_ASYNC_EVENT_ID_SRAM22
,
247 GOYA_ASYNC_EVENT_ID_SRAM23
,
248 GOYA_ASYNC_EVENT_ID_SRAM24
,
249 GOYA_ASYNC_EVENT_ID_SRAM25
,
250 GOYA_ASYNC_EVENT_ID_SRAM26
,
251 GOYA_ASYNC_EVENT_ID_SRAM27
,
252 GOYA_ASYNC_EVENT_ID_SRAM28
,
253 GOYA_ASYNC_EVENT_ID_SRAM29
,
254 GOYA_ASYNC_EVENT_ID_GIC500
,
255 GOYA_ASYNC_EVENT_ID_PLL0
,
256 GOYA_ASYNC_EVENT_ID_PLL1
,
257 GOYA_ASYNC_EVENT_ID_PLL3
,
258 GOYA_ASYNC_EVENT_ID_PLL4
,
259 GOYA_ASYNC_EVENT_ID_PLL5
,
260 GOYA_ASYNC_EVENT_ID_PLL6
,
261 GOYA_ASYNC_EVENT_ID_AXI_ECC
,
262 GOYA_ASYNC_EVENT_ID_L2_RAM_ECC
,
263 GOYA_ASYNC_EVENT_ID_PSOC_GPIO_05_SW_RESET
,
264 GOYA_ASYNC_EVENT_ID_PSOC_GPIO_10_VRHOT_ICRIT
,
265 GOYA_ASYNC_EVENT_ID_PCIE_DEC
,
266 GOYA_ASYNC_EVENT_ID_TPC0_DEC
,
267 GOYA_ASYNC_EVENT_ID_TPC1_DEC
,
268 GOYA_ASYNC_EVENT_ID_TPC2_DEC
,
269 GOYA_ASYNC_EVENT_ID_TPC3_DEC
,
270 GOYA_ASYNC_EVENT_ID_TPC4_DEC
,
271 GOYA_ASYNC_EVENT_ID_TPC5_DEC
,
272 GOYA_ASYNC_EVENT_ID_TPC6_DEC
,
273 GOYA_ASYNC_EVENT_ID_TPC7_DEC
,
274 GOYA_ASYNC_EVENT_ID_MME_WACS
,
275 GOYA_ASYNC_EVENT_ID_MME_WACSD
,
276 GOYA_ASYNC_EVENT_ID_CPU_AXI_SPLITTER
,
277 GOYA_ASYNC_EVENT_ID_PSOC_AXI_DEC
,
278 GOYA_ASYNC_EVENT_ID_PSOC
,
279 GOYA_ASYNC_EVENT_ID_TPC0_KRN_ERR
,
280 GOYA_ASYNC_EVENT_ID_TPC1_KRN_ERR
,
281 GOYA_ASYNC_EVENT_ID_TPC2_KRN_ERR
,
282 GOYA_ASYNC_EVENT_ID_TPC3_KRN_ERR
,
283 GOYA_ASYNC_EVENT_ID_TPC4_KRN_ERR
,
284 GOYA_ASYNC_EVENT_ID_TPC5_KRN_ERR
,
285 GOYA_ASYNC_EVENT_ID_TPC6_KRN_ERR
,
286 GOYA_ASYNC_EVENT_ID_TPC7_KRN_ERR
,
287 GOYA_ASYNC_EVENT_ID_TPC0_CMDQ
,
288 GOYA_ASYNC_EVENT_ID_TPC1_CMDQ
,
289 GOYA_ASYNC_EVENT_ID_TPC2_CMDQ
,
290 GOYA_ASYNC_EVENT_ID_TPC3_CMDQ
,
291 GOYA_ASYNC_EVENT_ID_TPC4_CMDQ
,
292 GOYA_ASYNC_EVENT_ID_TPC5_CMDQ
,
293 GOYA_ASYNC_EVENT_ID_TPC6_CMDQ
,
294 GOYA_ASYNC_EVENT_ID_TPC7_CMDQ
,
295 GOYA_ASYNC_EVENT_ID_TPC0_QM
,
296 GOYA_ASYNC_EVENT_ID_TPC1_QM
,
297 GOYA_ASYNC_EVENT_ID_TPC2_QM
,
298 GOYA_ASYNC_EVENT_ID_TPC3_QM
,
299 GOYA_ASYNC_EVENT_ID_TPC4_QM
,
300 GOYA_ASYNC_EVENT_ID_TPC5_QM
,
301 GOYA_ASYNC_EVENT_ID_TPC6_QM
,
302 GOYA_ASYNC_EVENT_ID_TPC7_QM
,
303 GOYA_ASYNC_EVENT_ID_MME_QM
,
304 GOYA_ASYNC_EVENT_ID_MME_CMDQ
,
305 GOYA_ASYNC_EVENT_ID_DMA0_QM
,
306 GOYA_ASYNC_EVENT_ID_DMA1_QM
,
307 GOYA_ASYNC_EVENT_ID_DMA2_QM
,
308 GOYA_ASYNC_EVENT_ID_DMA3_QM
,
309 GOYA_ASYNC_EVENT_ID_DMA4_QM
,
310 GOYA_ASYNC_EVENT_ID_DMA0_CH
,
311 GOYA_ASYNC_EVENT_ID_DMA1_CH
,
312 GOYA_ASYNC_EVENT_ID_DMA2_CH
,
313 GOYA_ASYNC_EVENT_ID_DMA3_CH
,
314 GOYA_ASYNC_EVENT_ID_DMA4_CH
,
315 GOYA_ASYNC_EVENT_ID_TPC0_BMON_SPMU
,
316 GOYA_ASYNC_EVENT_ID_TPC1_BMON_SPMU
,
317 GOYA_ASYNC_EVENT_ID_TPC2_BMON_SPMU
,
318 GOYA_ASYNC_EVENT_ID_TPC3_BMON_SPMU
,
319 GOYA_ASYNC_EVENT_ID_TPC4_BMON_SPMU
,
320 GOYA_ASYNC_EVENT_ID_TPC5_BMON_SPMU
,
321 GOYA_ASYNC_EVENT_ID_TPC6_BMON_SPMU
,
322 GOYA_ASYNC_EVENT_ID_TPC7_BMON_SPMU
,
323 GOYA_ASYNC_EVENT_ID_DMA_BM_CH0
,
324 GOYA_ASYNC_EVENT_ID_DMA_BM_CH1
,
325 GOYA_ASYNC_EVENT_ID_DMA_BM_CH2
,
326 GOYA_ASYNC_EVENT_ID_DMA_BM_CH3
,
327 GOYA_ASYNC_EVENT_ID_DMA_BM_CH4
330 static int goya_mmu_clear_pgt_range(struct hl_device
*hdev
);
331 static int goya_mmu_set_dram_default_page(struct hl_device
*hdev
);
332 static int goya_mmu_add_mappings_for_device_cpu(struct hl_device
*hdev
);
333 static void goya_mmu_prepare(struct hl_device
*hdev
, u32 asid
);
335 void goya_get_fixed_properties(struct hl_device
*hdev
)
337 struct asic_fixed_properties
*prop
= &hdev
->asic_prop
;
340 for (i
= 0 ; i
< NUMBER_OF_EXT_HW_QUEUES
; i
++) {
341 prop
->hw_queues_props
[i
].type
= QUEUE_TYPE_EXT
;
342 prop
->hw_queues_props
[i
].driver_only
= 0;
343 prop
->hw_queues_props
[i
].requires_kernel_cb
= 1;
346 for (; i
< NUMBER_OF_EXT_HW_QUEUES
+ NUMBER_OF_CPU_HW_QUEUES
; i
++) {
347 prop
->hw_queues_props
[i
].type
= QUEUE_TYPE_CPU
;
348 prop
->hw_queues_props
[i
].driver_only
= 1;
349 prop
->hw_queues_props
[i
].requires_kernel_cb
= 0;
352 for (; i
< NUMBER_OF_EXT_HW_QUEUES
+ NUMBER_OF_CPU_HW_QUEUES
+
353 NUMBER_OF_INT_HW_QUEUES
; i
++) {
354 prop
->hw_queues_props
[i
].type
= QUEUE_TYPE_INT
;
355 prop
->hw_queues_props
[i
].driver_only
= 0;
356 prop
->hw_queues_props
[i
].requires_kernel_cb
= 0;
359 for (; i
< HL_MAX_QUEUES
; i
++)
360 prop
->hw_queues_props
[i
].type
= QUEUE_TYPE_NA
;
362 prop
->completion_queues_count
= NUMBER_OF_CMPLT_QUEUES
;
364 prop
->dram_base_address
= DRAM_PHYS_BASE
;
365 prop
->dram_size
= DRAM_PHYS_DEFAULT_SIZE
;
366 prop
->dram_end_address
= prop
->dram_base_address
+ prop
->dram_size
;
367 prop
->dram_user_base_address
= DRAM_BASE_ADDR_USER
;
369 prop
->sram_base_address
= SRAM_BASE_ADDR
;
370 prop
->sram_size
= SRAM_SIZE
;
371 prop
->sram_end_address
= prop
->sram_base_address
+ prop
->sram_size
;
372 prop
->sram_user_base_address
= prop
->sram_base_address
+
373 SRAM_USER_BASE_OFFSET
;
375 prop
->mmu_pgt_addr
= MMU_PAGE_TABLES_ADDR
;
376 prop
->mmu_dram_default_page_addr
= MMU_DRAM_DEFAULT_PAGE_ADDR
;
378 prop
->mmu_pgt_size
= 0x800000; /* 8MB */
380 prop
->mmu_pgt_size
= MMU_PAGE_TABLES_SIZE
;
381 prop
->mmu_pte_size
= HL_PTE_SIZE
;
382 prop
->mmu_hop_table_size
= HOP_TABLE_SIZE
;
383 prop
->mmu_hop0_tables_total_size
= HOP0_TABLES_TOTAL_SIZE
;
384 prop
->dram_page_size
= PAGE_SIZE_2MB
;
386 prop
->dmmu
.hop0_shift
= HOP0_SHIFT
;
387 prop
->dmmu
.hop1_shift
= HOP1_SHIFT
;
388 prop
->dmmu
.hop2_shift
= HOP2_SHIFT
;
389 prop
->dmmu
.hop3_shift
= HOP3_SHIFT
;
390 prop
->dmmu
.hop4_shift
= HOP4_SHIFT
;
391 prop
->dmmu
.hop0_mask
= HOP0_MASK
;
392 prop
->dmmu
.hop1_mask
= HOP1_MASK
;
393 prop
->dmmu
.hop2_mask
= HOP2_MASK
;
394 prop
->dmmu
.hop3_mask
= HOP3_MASK
;
395 prop
->dmmu
.hop4_mask
= HOP4_MASK
;
396 prop
->dmmu
.huge_page_size
= PAGE_SIZE_2MB
;
398 /* No difference between PMMU and DMMU except of page size */
399 memcpy(&prop
->pmmu
, &prop
->dmmu
, sizeof(prop
->dmmu
));
400 prop
->dmmu
.page_size
= PAGE_SIZE_2MB
;
401 prop
->pmmu
.page_size
= PAGE_SIZE_4KB
;
403 prop
->va_space_host_start_address
= VA_HOST_SPACE_START
;
404 prop
->va_space_host_end_address
= VA_HOST_SPACE_END
;
405 prop
->va_space_dram_start_address
= VA_DDR_SPACE_START
;
406 prop
->va_space_dram_end_address
= VA_DDR_SPACE_END
;
407 prop
->dram_size_for_default_page_mapping
=
408 prop
->va_space_dram_end_address
;
409 prop
->cfg_size
= CFG_SIZE
;
410 prop
->max_asid
= MAX_ASID
;
411 prop
->num_of_events
= GOYA_ASYNC_EVENT_ID_SIZE
;
412 prop
->high_pll
= PLL_HIGH_DEFAULT
;
413 prop
->cb_pool_cb_cnt
= GOYA_CB_POOL_CB_CNT
;
414 prop
->cb_pool_cb_size
= GOYA_CB_POOL_CB_SIZE
;
415 prop
->max_power_default
= MAX_POWER_DEFAULT
;
416 prop
->tpc_enabled_mask
= TPC_ENABLED_MASK
;
417 prop
->pcie_dbi_base_address
= mmPCIE_DBI_BASE
;
418 prop
->pcie_aux_dbi_reg_addr
= CFG_BASE
+ mmPCIE_AUX_DBI
;
420 strncpy(prop
->armcp_info
.card_name
, GOYA_DEFAULT_CARD_NAME
,
425 * goya_pci_bars_map - Map PCI BARS of Goya device
427 * @hdev: pointer to hl_device structure
429 * Request PCI regions and map them to kernel virtual addresses.
430 * Returns 0 on success
433 static int goya_pci_bars_map(struct hl_device
*hdev
)
435 static const char * const name
[] = {"SRAM_CFG", "MSIX", "DDR"};
436 bool is_wc
[3] = {false, false, true};
439 rc
= hl_pci_bars_map(hdev
, name
, is_wc
);
443 hdev
->rmmio
= hdev
->pcie_bar
[SRAM_CFG_BAR_ID
] +
444 (CFG_BASE
- SRAM_BASE_ADDR
);
449 static u64
goya_set_ddr_bar_base(struct hl_device
*hdev
, u64 addr
)
451 struct goya_device
*goya
= hdev
->asic_specific
;
455 if ((goya
) && (goya
->ddr_bar_cur_addr
== addr
))
458 /* Inbound Region 1 - Bar 4 - Point to DDR */
459 rc
= hl_pci_set_dram_bar_base(hdev
, 1, 4, addr
);
464 old_addr
= goya
->ddr_bar_cur_addr
;
465 goya
->ddr_bar_cur_addr
= addr
;
472 * goya_init_iatu - Initialize the iATU unit inside the PCI controller
474 * @hdev: pointer to hl_device structure
476 * This is needed in case the firmware doesn't initialize the iATU
479 static int goya_init_iatu(struct hl_device
*hdev
)
481 return hl_pci_init_iatu(hdev
, SRAM_BASE_ADDR
, DRAM_PHYS_BASE
,
482 HOST_PHYS_BASE
, HOST_PHYS_SIZE
);
486 * goya_early_init - GOYA early initialization code
488 * @hdev: pointer to hl_device structure
492 * PCI controller initialization
496 static int goya_early_init(struct hl_device
*hdev
)
498 struct asic_fixed_properties
*prop
= &hdev
->asic_prop
;
499 struct pci_dev
*pdev
= hdev
->pdev
;
503 goya_get_fixed_properties(hdev
);
505 /* Check BAR sizes */
506 if (pci_resource_len(pdev
, SRAM_CFG_BAR_ID
) != CFG_BAR_SIZE
) {
508 "Not " HL_NAME
"? BAR %d size %llu, expecting %llu\n",
510 (unsigned long long) pci_resource_len(pdev
,
516 if (pci_resource_len(pdev
, MSIX_BAR_ID
) != MSIX_BAR_SIZE
) {
518 "Not " HL_NAME
"? BAR %d size %llu, expecting %llu\n",
520 (unsigned long long) pci_resource_len(pdev
,
526 prop
->dram_pci_bar_size
= pci_resource_len(pdev
, DDR_BAR_ID
);
528 rc
= hl_pci_init(hdev
, 48);
533 val
= RREG32(mmPSOC_GLOBAL_CONF_BOOT_STRAP_PINS
);
534 if (val
& PSOC_GLOBAL_CONF_BOOT_STRAP_PINS_SRIOV_EN_MASK
)
536 "PCI strap is not configured correctly, PCI bus errors may occur\n");
543 * goya_early_fini - GOYA early finalization code
545 * @hdev: pointer to hl_device structure
550 static int goya_early_fini(struct hl_device
*hdev
)
557 static void goya_mmu_prepare_reg(struct hl_device
*hdev
, u64 reg
, u32 asid
)
559 /* mask to zero the MMBP and ASID bits */
560 WREG32_AND(reg
, ~0x7FF);
561 WREG32_OR(reg
, asid
);
564 static void goya_qman0_set_security(struct hl_device
*hdev
, bool secure
)
566 struct goya_device
*goya
= hdev
->asic_specific
;
568 if (!(goya
->hw_cap_initialized
& HW_CAP_MMU
))
572 WREG32(mmDMA_QM_0_GLBL_PROT
, QMAN_DMA_FULLY_TRUSTED
);
574 WREG32(mmDMA_QM_0_GLBL_PROT
, QMAN_DMA_PARTLY_TRUSTED
);
576 RREG32(mmDMA_QM_0_GLBL_PROT
);
580 * goya_fetch_psoc_frequency - Fetch PSOC frequency values
582 * @hdev: pointer to hl_device structure
585 static void goya_fetch_psoc_frequency(struct hl_device
*hdev
)
587 struct asic_fixed_properties
*prop
= &hdev
->asic_prop
;
589 prop
->psoc_pci_pll_nr
= RREG32(mmPSOC_PCI_PLL_NR
);
590 prop
->psoc_pci_pll_nf
= RREG32(mmPSOC_PCI_PLL_NF
);
591 prop
->psoc_pci_pll_od
= RREG32(mmPSOC_PCI_PLL_OD
);
592 prop
->psoc_pci_pll_div_factor
= RREG32(mmPSOC_PCI_PLL_DIV_FACTOR_1
);
595 int goya_late_init(struct hl_device
*hdev
)
597 struct asic_fixed_properties
*prop
= &hdev
->asic_prop
;
600 goya_fetch_psoc_frequency(hdev
);
602 rc
= goya_mmu_clear_pgt_range(hdev
);
605 "Failed to clear MMU page tables range %d\n", rc
);
609 rc
= goya_mmu_set_dram_default_page(hdev
);
611 dev_err(hdev
->dev
, "Failed to set DRAM default page %d\n", rc
);
615 rc
= goya_mmu_add_mappings_for_device_cpu(hdev
);
619 rc
= goya_init_cpu_queues(hdev
);
623 rc
= goya_test_cpu_queue(hdev
);
627 rc
= goya_armcp_info_get(hdev
);
629 dev_err(hdev
->dev
, "Failed to get armcp info %d\n", rc
);
633 /* Now that we have the DRAM size in ASIC prop, we need to check
634 * its size and configure the DMA_IF DDR wrap protection (which is in
635 * the MMU block) accordingly. The value is the log2 of the DRAM size
637 WREG32(mmMMU_LOG2_DDR_SIZE
, ilog2(prop
->dram_size
));
639 rc
= hl_fw_send_pci_access_msg(hdev
, ARMCP_PACKET_ENABLE_PCI_ACCESS
);
642 "Failed to enable PCI access from CPU %d\n", rc
);
646 WREG32(mmGIC_DISTRIBUTOR__5_GICD_SETSPI_NSR
,
647 GOYA_ASYNC_EVENT_ID_INTS_REGISTER
);
653 * goya_late_fini - GOYA late tear-down code
655 * @hdev: pointer to hl_device structure
657 * Free sensors allocated structures
659 void goya_late_fini(struct hl_device
*hdev
)
661 const struct hwmon_channel_info
**channel_info_arr
;
664 if (!hdev
->hl_chip_info
->info
)
667 channel_info_arr
= hdev
->hl_chip_info
->info
;
669 while (channel_info_arr
[i
]) {
670 kfree(channel_info_arr
[i
]->config
);
671 kfree(channel_info_arr
[i
]);
675 kfree(channel_info_arr
);
677 hdev
->hl_chip_info
->info
= NULL
;
681 * goya_sw_init - Goya software initialization code
683 * @hdev: pointer to hl_device structure
686 static int goya_sw_init(struct hl_device
*hdev
)
688 struct goya_device
*goya
;
691 /* Allocate device structure */
692 goya
= kzalloc(sizeof(*goya
), GFP_KERNEL
);
696 /* according to goya_init_iatu */
697 goya
->ddr_bar_cur_addr
= DRAM_PHYS_BASE
;
699 goya
->mme_clk
= GOYA_PLL_FREQ_LOW
;
700 goya
->tpc_clk
= GOYA_PLL_FREQ_LOW
;
701 goya
->ic_clk
= GOYA_PLL_FREQ_LOW
;
703 hdev
->asic_specific
= goya
;
705 /* Create DMA pool for small allocations */
706 hdev
->dma_pool
= dma_pool_create(dev_name(hdev
->dev
),
707 &hdev
->pdev
->dev
, GOYA_DMA_POOL_BLK_SIZE
, 8, 0);
708 if (!hdev
->dma_pool
) {
709 dev_err(hdev
->dev
, "failed to create DMA pool\n");
711 goto free_goya_device
;
714 hdev
->cpu_accessible_dma_mem
=
715 hdev
->asic_funcs
->asic_dma_alloc_coherent(hdev
,
716 HL_CPU_ACCESSIBLE_MEM_SIZE
,
717 &hdev
->cpu_accessible_dma_address
,
718 GFP_KERNEL
| __GFP_ZERO
);
720 if (!hdev
->cpu_accessible_dma_mem
) {
725 dev_dbg(hdev
->dev
, "cpu accessible memory at bus address %pad\n",
726 &hdev
->cpu_accessible_dma_address
);
728 hdev
->cpu_accessible_dma_pool
= gen_pool_create(ilog2(32), -1);
729 if (!hdev
->cpu_accessible_dma_pool
) {
731 "Failed to create CPU accessible DMA pool\n");
733 goto free_cpu_dma_mem
;
736 rc
= gen_pool_add(hdev
->cpu_accessible_dma_pool
,
737 (uintptr_t) hdev
->cpu_accessible_dma_mem
,
738 HL_CPU_ACCESSIBLE_MEM_SIZE
, -1);
741 "Failed to add memory to CPU accessible DMA pool\n");
743 goto free_cpu_accessible_dma_pool
;
746 spin_lock_init(&goya
->hw_queues_lock
);
750 free_cpu_accessible_dma_pool
:
751 gen_pool_destroy(hdev
->cpu_accessible_dma_pool
);
753 hdev
->asic_funcs
->asic_dma_free_coherent(hdev
,
754 HL_CPU_ACCESSIBLE_MEM_SIZE
,
755 hdev
->cpu_accessible_dma_mem
,
756 hdev
->cpu_accessible_dma_address
);
758 dma_pool_destroy(hdev
->dma_pool
);
766 * goya_sw_fini - Goya software tear-down code
768 * @hdev: pointer to hl_device structure
771 static int goya_sw_fini(struct hl_device
*hdev
)
773 struct goya_device
*goya
= hdev
->asic_specific
;
775 gen_pool_destroy(hdev
->cpu_accessible_dma_pool
);
777 hdev
->asic_funcs
->asic_dma_free_coherent(hdev
,
778 HL_CPU_ACCESSIBLE_MEM_SIZE
,
779 hdev
->cpu_accessible_dma_mem
,
780 hdev
->cpu_accessible_dma_address
);
782 dma_pool_destroy(hdev
->dma_pool
);
789 static void goya_init_dma_qman(struct hl_device
*hdev
, int dma_id
,
790 dma_addr_t bus_address
)
792 struct goya_device
*goya
= hdev
->asic_specific
;
793 u32 mtr_base_lo
, mtr_base_hi
;
794 u32 so_base_lo
, so_base_hi
;
795 u32 gic_base_lo
, gic_base_hi
;
796 u32 reg_off
= dma_id
* (mmDMA_QM_1_PQ_PI
- mmDMA_QM_0_PQ_PI
);
798 mtr_base_lo
= lower_32_bits(CFG_BASE
+ mmSYNC_MNGR_MON_PAY_ADDRL_0
);
799 mtr_base_hi
= upper_32_bits(CFG_BASE
+ mmSYNC_MNGR_MON_PAY_ADDRL_0
);
800 so_base_lo
= lower_32_bits(CFG_BASE
+ mmSYNC_MNGR_SOB_OBJ_0
);
801 so_base_hi
= upper_32_bits(CFG_BASE
+ mmSYNC_MNGR_SOB_OBJ_0
);
804 lower_32_bits(CFG_BASE
+ mmGIC_DISTRIBUTOR__5_GICD_SETSPI_NSR
);
806 upper_32_bits(CFG_BASE
+ mmGIC_DISTRIBUTOR__5_GICD_SETSPI_NSR
);
808 WREG32(mmDMA_QM_0_PQ_BASE_LO
+ reg_off
, lower_32_bits(bus_address
));
809 WREG32(mmDMA_QM_0_PQ_BASE_HI
+ reg_off
, upper_32_bits(bus_address
));
811 WREG32(mmDMA_QM_0_PQ_SIZE
+ reg_off
, ilog2(HL_QUEUE_LENGTH
));
812 WREG32(mmDMA_QM_0_PQ_PI
+ reg_off
, 0);
813 WREG32(mmDMA_QM_0_PQ_CI
+ reg_off
, 0);
815 WREG32(mmDMA_QM_0_CP_MSG_BASE0_ADDR_LO
+ reg_off
, mtr_base_lo
);
816 WREG32(mmDMA_QM_0_CP_MSG_BASE0_ADDR_HI
+ reg_off
, mtr_base_hi
);
817 WREG32(mmDMA_QM_0_CP_MSG_BASE1_ADDR_LO
+ reg_off
, so_base_lo
);
818 WREG32(mmDMA_QM_0_CP_MSG_BASE1_ADDR_HI
+ reg_off
, so_base_hi
);
819 WREG32(mmDMA_QM_0_GLBL_ERR_ADDR_LO
+ reg_off
, gic_base_lo
);
820 WREG32(mmDMA_QM_0_GLBL_ERR_ADDR_HI
+ reg_off
, gic_base_hi
);
821 WREG32(mmDMA_QM_0_GLBL_ERR_WDATA
+ reg_off
,
822 GOYA_ASYNC_EVENT_ID_DMA0_QM
+ dma_id
);
824 /* PQ has buffer of 2 cache lines, while CQ has 8 lines */
825 WREG32(mmDMA_QM_0_PQ_CFG1
+ reg_off
, 0x00020002);
826 WREG32(mmDMA_QM_0_CQ_CFG1
+ reg_off
, 0x00080008);
828 if (goya
->hw_cap_initialized
& HW_CAP_MMU
)
829 WREG32(mmDMA_QM_0_GLBL_PROT
+ reg_off
, QMAN_DMA_PARTLY_TRUSTED
);
831 WREG32(mmDMA_QM_0_GLBL_PROT
+ reg_off
, QMAN_DMA_FULLY_TRUSTED
);
833 WREG32(mmDMA_QM_0_GLBL_ERR_CFG
+ reg_off
, QMAN_DMA_ERR_MSG_EN
);
834 WREG32(mmDMA_QM_0_GLBL_CFG0
+ reg_off
, QMAN_DMA_ENABLE
);
837 static void goya_init_dma_ch(struct hl_device
*hdev
, int dma_id
)
839 u32 gic_base_lo
, gic_base_hi
;
841 u32 reg_off
= dma_id
* (mmDMA_CH_1_CFG1
- mmDMA_CH_0_CFG1
);
844 lower_32_bits(CFG_BASE
+ mmGIC_DISTRIBUTOR__5_GICD_SETSPI_NSR
);
846 upper_32_bits(CFG_BASE
+ mmGIC_DISTRIBUTOR__5_GICD_SETSPI_NSR
);
848 WREG32(mmDMA_CH_0_ERRMSG_ADDR_LO
+ reg_off
, gic_base_lo
);
849 WREG32(mmDMA_CH_0_ERRMSG_ADDR_HI
+ reg_off
, gic_base_hi
);
850 WREG32(mmDMA_CH_0_ERRMSG_WDATA
+ reg_off
,
851 GOYA_ASYNC_EVENT_ID_DMA0_CH
+ dma_id
);
854 sob_addr
= CFG_BASE
+ mmSYNC_MNGR_SOB_OBJ_1000
+
857 sob_addr
= CFG_BASE
+ mmSYNC_MNGR_SOB_OBJ_1007
;
859 WREG32(mmDMA_CH_0_WR_COMP_ADDR_HI
+ reg_off
, upper_32_bits(sob_addr
));
860 WREG32(mmDMA_CH_0_WR_COMP_WDATA
+ reg_off
, 0x80000001);
864 * goya_init_dma_qmans - Initialize QMAN DMA registers
866 * @hdev: pointer to hl_device structure
868 * Initialize the H/W registers of the QMAN DMA channels
871 void goya_init_dma_qmans(struct hl_device
*hdev
)
873 struct goya_device
*goya
= hdev
->asic_specific
;
874 struct hl_hw_queue
*q
;
877 if (goya
->hw_cap_initialized
& HW_CAP_DMA
)
880 q
= &hdev
->kernel_queues
[0];
882 for (i
= 0 ; i
< NUMBER_OF_EXT_HW_QUEUES
; i
++, q
++) {
883 goya_init_dma_qman(hdev
, i
, q
->bus_address
);
884 goya_init_dma_ch(hdev
, i
);
887 goya
->hw_cap_initialized
|= HW_CAP_DMA
;
891 * goya_disable_external_queues - Disable external queues
893 * @hdev: pointer to hl_device structure
896 static void goya_disable_external_queues(struct hl_device
*hdev
)
898 WREG32(mmDMA_QM_0_GLBL_CFG0
, 0);
899 WREG32(mmDMA_QM_1_GLBL_CFG0
, 0);
900 WREG32(mmDMA_QM_2_GLBL_CFG0
, 0);
901 WREG32(mmDMA_QM_3_GLBL_CFG0
, 0);
902 WREG32(mmDMA_QM_4_GLBL_CFG0
, 0);
905 static int goya_stop_queue(struct hl_device
*hdev
, u32 cfg_reg
,
906 u32 cp_sts_reg
, u32 glbl_sts0_reg
)
911 /* use the values of TPC0 as they are all the same*/
913 WREG32(cfg_reg
, 1 << TPC0_QM_GLBL_CFG1_CP_STOP_SHIFT
);
915 status
= RREG32(cp_sts_reg
);
916 if (status
& TPC0_QM_CP_STS_FENCE_IN_PROGRESS_MASK
) {
917 rc
= hl_poll_timeout(
921 !(status
& TPC0_QM_CP_STS_FENCE_IN_PROGRESS_MASK
),
923 QMAN_FENCE_TIMEOUT_USEC
);
925 /* if QMAN is stuck in fence no need to check for stop */
930 rc
= hl_poll_timeout(
934 (status
& TPC0_QM_GLBL_STS0_CP_IS_STOP_MASK
),
936 QMAN_STOP_TIMEOUT_USEC
);
940 "Timeout while waiting for QMAN to stop\n");
948 * goya_stop_external_queues - Stop external queues
950 * @hdev: pointer to hl_device structure
952 * Returns 0 on success
955 static int goya_stop_external_queues(struct hl_device
*hdev
)
959 rc
= goya_stop_queue(hdev
,
960 mmDMA_QM_0_GLBL_CFG1
,
962 mmDMA_QM_0_GLBL_STS0
);
965 dev_err(hdev
->dev
, "failed to stop DMA QMAN 0\n");
969 rc
= goya_stop_queue(hdev
,
970 mmDMA_QM_1_GLBL_CFG1
,
972 mmDMA_QM_1_GLBL_STS0
);
975 dev_err(hdev
->dev
, "failed to stop DMA QMAN 1\n");
979 rc
= goya_stop_queue(hdev
,
980 mmDMA_QM_2_GLBL_CFG1
,
982 mmDMA_QM_2_GLBL_STS0
);
985 dev_err(hdev
->dev
, "failed to stop DMA QMAN 2\n");
989 rc
= goya_stop_queue(hdev
,
990 mmDMA_QM_3_GLBL_CFG1
,
992 mmDMA_QM_3_GLBL_STS0
);
995 dev_err(hdev
->dev
, "failed to stop DMA QMAN 3\n");
999 rc
= goya_stop_queue(hdev
,
1000 mmDMA_QM_4_GLBL_CFG1
,
1002 mmDMA_QM_4_GLBL_STS0
);
1005 dev_err(hdev
->dev
, "failed to stop DMA QMAN 4\n");
1013 * goya_init_cpu_queues - Initialize PQ/CQ/EQ of CPU
1015 * @hdev: pointer to hl_device structure
1017 * Returns 0 on success
1020 int goya_init_cpu_queues(struct hl_device
*hdev
)
1022 struct goya_device
*goya
= hdev
->asic_specific
;
1025 struct hl_hw_queue
*cpu_pq
= &hdev
->kernel_queues
[GOYA_QUEUE_ID_CPU_PQ
];
1028 if (!hdev
->cpu_queues_enable
)
1031 if (goya
->hw_cap_initialized
& HW_CAP_CPU_Q
)
1034 eq
= &hdev
->event_queue
;
1036 WREG32(mmCPU_PQ_BASE_ADDR_LOW
, lower_32_bits(cpu_pq
->bus_address
));
1037 WREG32(mmCPU_PQ_BASE_ADDR_HIGH
, upper_32_bits(cpu_pq
->bus_address
));
1039 WREG32(mmCPU_EQ_BASE_ADDR_LOW
, lower_32_bits(eq
->bus_address
));
1040 WREG32(mmCPU_EQ_BASE_ADDR_HIGH
, upper_32_bits(eq
->bus_address
));
1042 WREG32(mmCPU_CQ_BASE_ADDR_LOW
,
1043 lower_32_bits(VA_CPU_ACCESSIBLE_MEM_ADDR
));
1044 WREG32(mmCPU_CQ_BASE_ADDR_HIGH
,
1045 upper_32_bits(VA_CPU_ACCESSIBLE_MEM_ADDR
));
1047 WREG32(mmCPU_PQ_LENGTH
, HL_QUEUE_SIZE_IN_BYTES
);
1048 WREG32(mmCPU_EQ_LENGTH
, HL_EQ_SIZE_IN_BYTES
);
1049 WREG32(mmCPU_CQ_LENGTH
, HL_CPU_ACCESSIBLE_MEM_SIZE
);
1051 /* Used for EQ CI */
1052 WREG32(mmCPU_EQ_CI
, 0);
1054 WREG32(mmCPU_IF_PF_PQ_PI
, 0);
1056 WREG32(mmCPU_PQ_INIT_STATUS
, PQ_INIT_STATUS_READY_FOR_CP
);
1058 WREG32(mmGIC_DISTRIBUTOR__5_GICD_SETSPI_NSR
,
1059 GOYA_ASYNC_EVENT_ID_PI_UPDATE
);
1061 err
= hl_poll_timeout(
1063 mmCPU_PQ_INIT_STATUS
,
1065 (status
== PQ_INIT_STATUS_READY_FOR_HOST
),
1067 GOYA_CPU_TIMEOUT_USEC
);
1071 "Failed to setup communication with device CPU\n");
1075 goya
->hw_cap_initialized
|= HW_CAP_CPU_Q
;
1079 static void goya_set_pll_refclk(struct hl_device
*hdev
)
1081 WREG32(mmCPU_PLL_DIV_SEL_0
, 0x0);
1082 WREG32(mmCPU_PLL_DIV_SEL_1
, 0x0);
1083 WREG32(mmCPU_PLL_DIV_SEL_2
, 0x0);
1084 WREG32(mmCPU_PLL_DIV_SEL_3
, 0x0);
1086 WREG32(mmIC_PLL_DIV_SEL_0
, 0x0);
1087 WREG32(mmIC_PLL_DIV_SEL_1
, 0x0);
1088 WREG32(mmIC_PLL_DIV_SEL_2
, 0x0);
1089 WREG32(mmIC_PLL_DIV_SEL_3
, 0x0);
1091 WREG32(mmMC_PLL_DIV_SEL_0
, 0x0);
1092 WREG32(mmMC_PLL_DIV_SEL_1
, 0x0);
1093 WREG32(mmMC_PLL_DIV_SEL_2
, 0x0);
1094 WREG32(mmMC_PLL_DIV_SEL_3
, 0x0);
1096 WREG32(mmPSOC_MME_PLL_DIV_SEL_0
, 0x0);
1097 WREG32(mmPSOC_MME_PLL_DIV_SEL_1
, 0x0);
1098 WREG32(mmPSOC_MME_PLL_DIV_SEL_2
, 0x0);
1099 WREG32(mmPSOC_MME_PLL_DIV_SEL_3
, 0x0);
1101 WREG32(mmPSOC_PCI_PLL_DIV_SEL_0
, 0x0);
1102 WREG32(mmPSOC_PCI_PLL_DIV_SEL_1
, 0x0);
1103 WREG32(mmPSOC_PCI_PLL_DIV_SEL_2
, 0x0);
1104 WREG32(mmPSOC_PCI_PLL_DIV_SEL_3
, 0x0);
1106 WREG32(mmPSOC_EMMC_PLL_DIV_SEL_0
, 0x0);
1107 WREG32(mmPSOC_EMMC_PLL_DIV_SEL_1
, 0x0);
1108 WREG32(mmPSOC_EMMC_PLL_DIV_SEL_2
, 0x0);
1109 WREG32(mmPSOC_EMMC_PLL_DIV_SEL_3
, 0x0);
1111 WREG32(mmTPC_PLL_DIV_SEL_0
, 0x0);
1112 WREG32(mmTPC_PLL_DIV_SEL_1
, 0x0);
1113 WREG32(mmTPC_PLL_DIV_SEL_2
, 0x0);
1114 WREG32(mmTPC_PLL_DIV_SEL_3
, 0x0);
1117 static void goya_disable_clk_rlx(struct hl_device
*hdev
)
1119 WREG32(mmPSOC_MME_PLL_CLK_RLX_0
, 0x100010);
1120 WREG32(mmIC_PLL_CLK_RLX_0
, 0x100010);
1123 static void _goya_tpc_mbist_workaround(struct hl_device
*hdev
, u8 tpc_id
)
1125 u64 tpc_eml_address
;
1126 u32 val
, tpc_offset
, tpc_eml_offset
, tpc_slm_offset
;
1129 tpc_offset
= tpc_id
* 0x40000;
1130 tpc_eml_offset
= tpc_id
* 0x200000;
1131 tpc_eml_address
= (mmTPC0_EML_CFG_BASE
+ tpc_eml_offset
- CFG_BASE
);
1132 tpc_slm_offset
= tpc_eml_address
+ 0x100000;
1135 * Workaround for Bug H2 #2443 :
1136 * "TPC SB is not initialized on chip reset"
1139 val
= RREG32(mmTPC0_CFG_FUNC_MBIST_CNTRL
+ tpc_offset
);
1140 if (val
& TPC0_CFG_FUNC_MBIST_CNTRL_MBIST_ACTIVE_MASK
)
1141 dev_warn(hdev
->dev
, "TPC%d MBIST ACTIVE is not cleared\n",
1144 WREG32(mmTPC0_CFG_FUNC_MBIST_PAT
+ tpc_offset
, val
& 0xFFFFF000);
1146 WREG32(mmTPC0_CFG_FUNC_MBIST_MEM_0
+ tpc_offset
, 0x37FF);
1147 WREG32(mmTPC0_CFG_FUNC_MBIST_MEM_1
+ tpc_offset
, 0x303F);
1148 WREG32(mmTPC0_CFG_FUNC_MBIST_MEM_2
+ tpc_offset
, 0x71FF);
1149 WREG32(mmTPC0_CFG_FUNC_MBIST_MEM_3
+ tpc_offset
, 0x71FF);
1150 WREG32(mmTPC0_CFG_FUNC_MBIST_MEM_4
+ tpc_offset
, 0x70FF);
1151 WREG32(mmTPC0_CFG_FUNC_MBIST_MEM_5
+ tpc_offset
, 0x70FF);
1152 WREG32(mmTPC0_CFG_FUNC_MBIST_MEM_6
+ tpc_offset
, 0x70FF);
1153 WREG32(mmTPC0_CFG_FUNC_MBIST_MEM_7
+ tpc_offset
, 0x70FF);
1154 WREG32(mmTPC0_CFG_FUNC_MBIST_MEM_8
+ tpc_offset
, 0x70FF);
1155 WREG32(mmTPC0_CFG_FUNC_MBIST_MEM_9
+ tpc_offset
, 0x70FF);
1157 WREG32_OR(mmTPC0_CFG_FUNC_MBIST_CNTRL
+ tpc_offset
,
1158 1 << TPC0_CFG_FUNC_MBIST_CNTRL_MBIST_START_SHIFT
);
1160 err
= hl_poll_timeout(
1162 mmTPC0_CFG_FUNC_MBIST_CNTRL
+ tpc_offset
,
1164 (val
& TPC0_CFG_FUNC_MBIST_CNTRL_MBIST_DONE_MASK
),
1166 HL_DEVICE_TIMEOUT_USEC
);
1170 "Timeout while waiting for TPC%d MBIST DONE\n", tpc_id
);
1172 WREG32_OR(mmTPC0_EML_CFG_DBG_CNT
+ tpc_eml_offset
,
1173 1 << TPC0_EML_CFG_DBG_CNT_CORE_RST_SHIFT
);
1175 msleep(GOYA_RESET_WAIT_MSEC
);
1177 WREG32_AND(mmTPC0_EML_CFG_DBG_CNT
+ tpc_eml_offset
,
1178 ~(1 << TPC0_EML_CFG_DBG_CNT_CORE_RST_SHIFT
));
1180 msleep(GOYA_RESET_WAIT_MSEC
);
1182 for (slm_index
= 0 ; slm_index
< 256 ; slm_index
++)
1183 WREG32(tpc_slm_offset
+ (slm_index
<< 2), 0);
1185 val
= RREG32(tpc_slm_offset
);
1188 static void goya_tpc_mbist_workaround(struct hl_device
*hdev
)
1190 struct goya_device
*goya
= hdev
->asic_specific
;
1196 if (goya
->hw_cap_initialized
& HW_CAP_TPC_MBIST
)
1199 /* Workaround for H2 #2443 */
1201 for (i
= 0 ; i
< TPC_MAX_NUM
; i
++)
1202 _goya_tpc_mbist_workaround(hdev
, i
);
1204 goya
->hw_cap_initialized
|= HW_CAP_TPC_MBIST
;
1208 * goya_init_golden_registers - Initialize golden registers
1210 * @hdev: pointer to hl_device structure
1212 * Initialize the H/W registers of the device
1215 static void goya_init_golden_registers(struct hl_device
*hdev
)
1217 struct goya_device
*goya
= hdev
->asic_specific
;
1218 u32 polynom
[10], tpc_intr_mask
, offset
;
1221 if (goya
->hw_cap_initialized
& HW_CAP_GOLDEN
)
1224 polynom
[0] = 0x00020080;
1225 polynom
[1] = 0x00401000;
1226 polynom
[2] = 0x00200800;
1227 polynom
[3] = 0x00002000;
1228 polynom
[4] = 0x00080200;
1229 polynom
[5] = 0x00040100;
1230 polynom
[6] = 0x00100400;
1231 polynom
[7] = 0x00004000;
1232 polynom
[8] = 0x00010000;
1233 polynom
[9] = 0x00008000;
1235 /* Mask all arithmetic interrupts from TPC */
1236 tpc_intr_mask
= 0x7FFF;
1238 for (i
= 0, offset
= 0 ; i
< 6 ; i
++, offset
+= 0x20000) {
1239 WREG32(mmSRAM_Y0_X0_RTR_HBW_RD_RQ_L_ARB
+ offset
, 0x302);
1240 WREG32(mmSRAM_Y0_X1_RTR_HBW_RD_RQ_L_ARB
+ offset
, 0x302);
1241 WREG32(mmSRAM_Y0_X2_RTR_HBW_RD_RQ_L_ARB
+ offset
, 0x302);
1242 WREG32(mmSRAM_Y0_X3_RTR_HBW_RD_RQ_L_ARB
+ offset
, 0x302);
1243 WREG32(mmSRAM_Y0_X4_RTR_HBW_RD_RQ_L_ARB
+ offset
, 0x302);
1245 WREG32(mmSRAM_Y0_X0_RTR_HBW_DATA_L_ARB
+ offset
, 0x204);
1246 WREG32(mmSRAM_Y0_X1_RTR_HBW_DATA_L_ARB
+ offset
, 0x204);
1247 WREG32(mmSRAM_Y0_X2_RTR_HBW_DATA_L_ARB
+ offset
, 0x204);
1248 WREG32(mmSRAM_Y0_X3_RTR_HBW_DATA_L_ARB
+ offset
, 0x204);
1249 WREG32(mmSRAM_Y0_X4_RTR_HBW_DATA_L_ARB
+ offset
, 0x204);
1252 WREG32(mmSRAM_Y0_X0_RTR_HBW_DATA_E_ARB
+ offset
, 0x206);
1253 WREG32(mmSRAM_Y0_X1_RTR_HBW_DATA_E_ARB
+ offset
, 0x206);
1254 WREG32(mmSRAM_Y0_X2_RTR_HBW_DATA_E_ARB
+ offset
, 0x206);
1255 WREG32(mmSRAM_Y0_X3_RTR_HBW_DATA_E_ARB
+ offset
, 0x207);
1256 WREG32(mmSRAM_Y0_X4_RTR_HBW_DATA_E_ARB
+ offset
, 0x207);
1258 WREG32(mmSRAM_Y0_X0_RTR_HBW_DATA_W_ARB
+ offset
, 0x207);
1259 WREG32(mmSRAM_Y0_X1_RTR_HBW_DATA_W_ARB
+ offset
, 0x207);
1260 WREG32(mmSRAM_Y0_X2_RTR_HBW_DATA_W_ARB
+ offset
, 0x206);
1261 WREG32(mmSRAM_Y0_X3_RTR_HBW_DATA_W_ARB
+ offset
, 0x206);
1262 WREG32(mmSRAM_Y0_X4_RTR_HBW_DATA_W_ARB
+ offset
, 0x206);
1264 WREG32(mmSRAM_Y0_X0_RTR_HBW_WR_RS_E_ARB
+ offset
, 0x101);
1265 WREG32(mmSRAM_Y0_X1_RTR_HBW_WR_RS_E_ARB
+ offset
, 0x102);
1266 WREG32(mmSRAM_Y0_X2_RTR_HBW_WR_RS_E_ARB
+ offset
, 0x103);
1267 WREG32(mmSRAM_Y0_X3_RTR_HBW_WR_RS_E_ARB
+ offset
, 0x104);
1268 WREG32(mmSRAM_Y0_X4_RTR_HBW_WR_RS_E_ARB
+ offset
, 0x105);
1270 WREG32(mmSRAM_Y0_X0_RTR_HBW_WR_RS_W_ARB
+ offset
, 0x105);
1271 WREG32(mmSRAM_Y0_X1_RTR_HBW_WR_RS_W_ARB
+ offset
, 0x104);
1272 WREG32(mmSRAM_Y0_X2_RTR_HBW_WR_RS_W_ARB
+ offset
, 0x103);
1273 WREG32(mmSRAM_Y0_X3_RTR_HBW_WR_RS_W_ARB
+ offset
, 0x102);
1274 WREG32(mmSRAM_Y0_X4_RTR_HBW_WR_RS_W_ARB
+ offset
, 0x101);
1277 WREG32(mmMME_STORE_MAX_CREDIT
, 0x21);
1278 WREG32(mmMME_AGU
, 0x0f0f0f10);
1279 WREG32(mmMME_SEI_MASK
, ~0x0);
1281 WREG32(mmMME6_RTR_HBW_RD_RQ_N_ARB
, 0x01010101);
1282 WREG32(mmMME5_RTR_HBW_RD_RQ_N_ARB
, 0x01040101);
1283 WREG32(mmMME4_RTR_HBW_RD_RQ_N_ARB
, 0x01030101);
1284 WREG32(mmMME3_RTR_HBW_RD_RQ_N_ARB
, 0x01020101);
1285 WREG32(mmMME2_RTR_HBW_RD_RQ_N_ARB
, 0x01010101);
1286 WREG32(mmMME1_RTR_HBW_RD_RQ_N_ARB
, 0x07010701);
1287 WREG32(mmMME6_RTR_HBW_RD_RQ_S_ARB
, 0x04010401);
1288 WREG32(mmMME5_RTR_HBW_RD_RQ_S_ARB
, 0x04050401);
1289 WREG32(mmMME4_RTR_HBW_RD_RQ_S_ARB
, 0x03070301);
1290 WREG32(mmMME3_RTR_HBW_RD_RQ_S_ARB
, 0x01030101);
1291 WREG32(mmMME2_RTR_HBW_RD_RQ_S_ARB
, 0x01040101);
1292 WREG32(mmMME1_RTR_HBW_RD_RQ_S_ARB
, 0x01050105);
1293 WREG32(mmMME6_RTR_HBW_RD_RQ_W_ARB
, 0x01010501);
1294 WREG32(mmMME5_RTR_HBW_RD_RQ_W_ARB
, 0x01010501);
1295 WREG32(mmMME4_RTR_HBW_RD_RQ_W_ARB
, 0x01040301);
1296 WREG32(mmMME3_RTR_HBW_RD_RQ_W_ARB
, 0x01030401);
1297 WREG32(mmMME2_RTR_HBW_RD_RQ_W_ARB
, 0x01040101);
1298 WREG32(mmMME1_RTR_HBW_RD_RQ_W_ARB
, 0x01050101);
1299 WREG32(mmMME6_RTR_HBW_WR_RQ_N_ARB
, 0x02020202);
1300 WREG32(mmMME5_RTR_HBW_WR_RQ_N_ARB
, 0x01070101);
1301 WREG32(mmMME4_RTR_HBW_WR_RQ_N_ARB
, 0x02020201);
1302 WREG32(mmMME3_RTR_HBW_WR_RQ_N_ARB
, 0x07020701);
1303 WREG32(mmMME2_RTR_HBW_WR_RQ_N_ARB
, 0x01020101);
1304 WREG32(mmMME1_RTR_HBW_WR_RQ_S_ARB
, 0x01010101);
1305 WREG32(mmMME6_RTR_HBW_WR_RQ_S_ARB
, 0x01070101);
1306 WREG32(mmMME5_RTR_HBW_WR_RQ_S_ARB
, 0x01070101);
1307 WREG32(mmMME4_RTR_HBW_WR_RQ_S_ARB
, 0x07020701);
1308 WREG32(mmMME3_RTR_HBW_WR_RQ_S_ARB
, 0x02020201);
1309 WREG32(mmMME2_RTR_HBW_WR_RQ_S_ARB
, 0x01070101);
1310 WREG32(mmMME1_RTR_HBW_WR_RQ_S_ARB
, 0x01020102);
1311 WREG32(mmMME6_RTR_HBW_WR_RQ_W_ARB
, 0x01020701);
1312 WREG32(mmMME5_RTR_HBW_WR_RQ_W_ARB
, 0x01020701);
1313 WREG32(mmMME4_RTR_HBW_WR_RQ_W_ARB
, 0x07020707);
1314 WREG32(mmMME3_RTR_HBW_WR_RQ_W_ARB
, 0x01020201);
1315 WREG32(mmMME2_RTR_HBW_WR_RQ_W_ARB
, 0x01070201);
1316 WREG32(mmMME1_RTR_HBW_WR_RQ_W_ARB
, 0x01070201);
1317 WREG32(mmMME6_RTR_HBW_RD_RS_N_ARB
, 0x01070102);
1318 WREG32(mmMME5_RTR_HBW_RD_RS_N_ARB
, 0x01070102);
1319 WREG32(mmMME4_RTR_HBW_RD_RS_N_ARB
, 0x01060102);
1320 WREG32(mmMME3_RTR_HBW_RD_RS_N_ARB
, 0x01040102);
1321 WREG32(mmMME2_RTR_HBW_RD_RS_N_ARB
, 0x01020102);
1322 WREG32(mmMME1_RTR_HBW_RD_RS_N_ARB
, 0x01020107);
1323 WREG32(mmMME6_RTR_HBW_RD_RS_S_ARB
, 0x01020106);
1324 WREG32(mmMME5_RTR_HBW_RD_RS_S_ARB
, 0x01020102);
1325 WREG32(mmMME4_RTR_HBW_RD_RS_S_ARB
, 0x01040102);
1326 WREG32(mmMME3_RTR_HBW_RD_RS_S_ARB
, 0x01060102);
1327 WREG32(mmMME2_RTR_HBW_RD_RS_S_ARB
, 0x01070102);
1328 WREG32(mmMME1_RTR_HBW_RD_RS_S_ARB
, 0x01070102);
1329 WREG32(mmMME6_RTR_HBW_RD_RS_E_ARB
, 0x01020702);
1330 WREG32(mmMME5_RTR_HBW_RD_RS_E_ARB
, 0x01020702);
1331 WREG32(mmMME4_RTR_HBW_RD_RS_E_ARB
, 0x01040602);
1332 WREG32(mmMME3_RTR_HBW_RD_RS_E_ARB
, 0x01060402);
1333 WREG32(mmMME2_RTR_HBW_RD_RS_E_ARB
, 0x01070202);
1334 WREG32(mmMME1_RTR_HBW_RD_RS_E_ARB
, 0x01070102);
1335 WREG32(mmMME6_RTR_HBW_RD_RS_W_ARB
, 0x01060401);
1336 WREG32(mmMME5_RTR_HBW_RD_RS_W_ARB
, 0x01060401);
1337 WREG32(mmMME4_RTR_HBW_RD_RS_W_ARB
, 0x01060401);
1338 WREG32(mmMME3_RTR_HBW_RD_RS_W_ARB
, 0x01060401);
1339 WREG32(mmMME2_RTR_HBW_RD_RS_W_ARB
, 0x01060401);
1340 WREG32(mmMME1_RTR_HBW_RD_RS_W_ARB
, 0x01060401);
1341 WREG32(mmMME6_RTR_HBW_WR_RS_N_ARB
, 0x01050101);
1342 WREG32(mmMME5_RTR_HBW_WR_RS_N_ARB
, 0x01040101);
1343 WREG32(mmMME4_RTR_HBW_WR_RS_N_ARB
, 0x01030101);
1344 WREG32(mmMME3_RTR_HBW_WR_RS_N_ARB
, 0x01020101);
1345 WREG32(mmMME2_RTR_HBW_WR_RS_N_ARB
, 0x01010101);
1346 WREG32(mmMME1_RTR_HBW_WR_RS_N_ARB
, 0x01010107);
1347 WREG32(mmMME6_RTR_HBW_WR_RS_S_ARB
, 0x01010107);
1348 WREG32(mmMME5_RTR_HBW_WR_RS_S_ARB
, 0x01010101);
1349 WREG32(mmMME4_RTR_HBW_WR_RS_S_ARB
, 0x01020101);
1350 WREG32(mmMME3_RTR_HBW_WR_RS_S_ARB
, 0x01030101);
1351 WREG32(mmMME2_RTR_HBW_WR_RS_S_ARB
, 0x01040101);
1352 WREG32(mmMME1_RTR_HBW_WR_RS_S_ARB
, 0x01050101);
1353 WREG32(mmMME6_RTR_HBW_WR_RS_E_ARB
, 0x01010501);
1354 WREG32(mmMME5_RTR_HBW_WR_RS_E_ARB
, 0x01010501);
1355 WREG32(mmMME4_RTR_HBW_WR_RS_E_ARB
, 0x01040301);
1356 WREG32(mmMME3_RTR_HBW_WR_RS_E_ARB
, 0x01030401);
1357 WREG32(mmMME2_RTR_HBW_WR_RS_E_ARB
, 0x01040101);
1358 WREG32(mmMME1_RTR_HBW_WR_RS_E_ARB
, 0x01050101);
1359 WREG32(mmMME6_RTR_HBW_WR_RS_W_ARB
, 0x01010101);
1360 WREG32(mmMME5_RTR_HBW_WR_RS_W_ARB
, 0x01010101);
1361 WREG32(mmMME4_RTR_HBW_WR_RS_W_ARB
, 0x01010101);
1362 WREG32(mmMME3_RTR_HBW_WR_RS_W_ARB
, 0x01010101);
1363 WREG32(mmMME2_RTR_HBW_WR_RS_W_ARB
, 0x01010101);
1364 WREG32(mmMME1_RTR_HBW_WR_RS_W_ARB
, 0x01010101);
1366 WREG32(mmTPC1_RTR_HBW_RD_RQ_N_ARB
, 0x01010101);
1367 WREG32(mmTPC1_RTR_HBW_RD_RQ_S_ARB
, 0x01010101);
1368 WREG32(mmTPC1_RTR_HBW_RD_RQ_E_ARB
, 0x01060101);
1369 WREG32(mmTPC1_RTR_HBW_WR_RQ_N_ARB
, 0x02020102);
1370 WREG32(mmTPC1_RTR_HBW_WR_RQ_S_ARB
, 0x01010101);
1371 WREG32(mmTPC1_RTR_HBW_WR_RQ_E_ARB
, 0x02070202);
1372 WREG32(mmTPC1_RTR_HBW_RD_RS_N_ARB
, 0x01020201);
1373 WREG32(mmTPC1_RTR_HBW_RD_RS_S_ARB
, 0x01070201);
1374 WREG32(mmTPC1_RTR_HBW_RD_RS_W_ARB
, 0x01070202);
1375 WREG32(mmTPC1_RTR_HBW_WR_RS_N_ARB
, 0x01010101);
1376 WREG32(mmTPC1_RTR_HBW_WR_RS_S_ARB
, 0x01050101);
1377 WREG32(mmTPC1_RTR_HBW_WR_RS_W_ARB
, 0x01050101);
1379 WREG32(mmTPC2_RTR_HBW_RD_RQ_N_ARB
, 0x01020101);
1380 WREG32(mmTPC2_RTR_HBW_RD_RQ_S_ARB
, 0x01050101);
1381 WREG32(mmTPC2_RTR_HBW_RD_RQ_E_ARB
, 0x01010201);
1382 WREG32(mmTPC2_RTR_HBW_WR_RQ_N_ARB
, 0x02040102);
1383 WREG32(mmTPC2_RTR_HBW_WR_RQ_S_ARB
, 0x01050101);
1384 WREG32(mmTPC2_RTR_HBW_WR_RQ_E_ARB
, 0x02060202);
1385 WREG32(mmTPC2_RTR_HBW_RD_RS_N_ARB
, 0x01020201);
1386 WREG32(mmTPC2_RTR_HBW_RD_RS_S_ARB
, 0x01070201);
1387 WREG32(mmTPC2_RTR_HBW_RD_RS_W_ARB
, 0x01070202);
1388 WREG32(mmTPC2_RTR_HBW_WR_RS_N_ARB
, 0x01010101);
1389 WREG32(mmTPC2_RTR_HBW_WR_RS_S_ARB
, 0x01040101);
1390 WREG32(mmTPC2_RTR_HBW_WR_RS_W_ARB
, 0x01040101);
1392 WREG32(mmTPC3_RTR_HBW_RD_RQ_N_ARB
, 0x01030101);
1393 WREG32(mmTPC3_RTR_HBW_RD_RQ_S_ARB
, 0x01040101);
1394 WREG32(mmTPC3_RTR_HBW_RD_RQ_E_ARB
, 0x01040301);
1395 WREG32(mmTPC3_RTR_HBW_WR_RQ_N_ARB
, 0x02060102);
1396 WREG32(mmTPC3_RTR_HBW_WR_RQ_S_ARB
, 0x01040101);
1397 WREG32(mmTPC3_RTR_HBW_WR_RQ_E_ARB
, 0x01040301);
1398 WREG32(mmTPC3_RTR_HBW_RD_RS_N_ARB
, 0x01040201);
1399 WREG32(mmTPC3_RTR_HBW_RD_RS_S_ARB
, 0x01060201);
1400 WREG32(mmTPC3_RTR_HBW_RD_RS_W_ARB
, 0x01060402);
1401 WREG32(mmTPC3_RTR_HBW_WR_RS_N_ARB
, 0x01020101);
1402 WREG32(mmTPC3_RTR_HBW_WR_RS_S_ARB
, 0x01030101);
1403 WREG32(mmTPC3_RTR_HBW_WR_RS_W_ARB
, 0x01030401);
1405 WREG32(mmTPC4_RTR_HBW_RD_RQ_N_ARB
, 0x01040101);
1406 WREG32(mmTPC4_RTR_HBW_RD_RQ_S_ARB
, 0x01030101);
1407 WREG32(mmTPC4_RTR_HBW_RD_RQ_E_ARB
, 0x01030401);
1408 WREG32(mmTPC4_RTR_HBW_WR_RQ_N_ARB
, 0x02070102);
1409 WREG32(mmTPC4_RTR_HBW_WR_RQ_S_ARB
, 0x01030101);
1410 WREG32(mmTPC4_RTR_HBW_WR_RQ_E_ARB
, 0x02060702);
1411 WREG32(mmTPC4_RTR_HBW_RD_RS_N_ARB
, 0x01060201);
1412 WREG32(mmTPC4_RTR_HBW_RD_RS_S_ARB
, 0x01040201);
1413 WREG32(mmTPC4_RTR_HBW_RD_RS_W_ARB
, 0x01040602);
1414 WREG32(mmTPC4_RTR_HBW_WR_RS_N_ARB
, 0x01030101);
1415 WREG32(mmTPC4_RTR_HBW_WR_RS_S_ARB
, 0x01020101);
1416 WREG32(mmTPC4_RTR_HBW_WR_RS_W_ARB
, 0x01040301);
1418 WREG32(mmTPC5_RTR_HBW_RD_RQ_N_ARB
, 0x01050101);
1419 WREG32(mmTPC5_RTR_HBW_RD_RQ_S_ARB
, 0x01020101);
1420 WREG32(mmTPC5_RTR_HBW_RD_RQ_E_ARB
, 0x01200501);
1421 WREG32(mmTPC5_RTR_HBW_WR_RQ_N_ARB
, 0x02070102);
1422 WREG32(mmTPC5_RTR_HBW_WR_RQ_S_ARB
, 0x01020101);
1423 WREG32(mmTPC5_RTR_HBW_WR_RQ_E_ARB
, 0x02020602);
1424 WREG32(mmTPC5_RTR_HBW_RD_RS_N_ARB
, 0x01070201);
1425 WREG32(mmTPC5_RTR_HBW_RD_RS_S_ARB
, 0x01020201);
1426 WREG32(mmTPC5_RTR_HBW_RD_RS_W_ARB
, 0x01020702);
1427 WREG32(mmTPC5_RTR_HBW_WR_RS_N_ARB
, 0x01040101);
1428 WREG32(mmTPC5_RTR_HBW_WR_RS_S_ARB
, 0x01010101);
1429 WREG32(mmTPC5_RTR_HBW_WR_RS_W_ARB
, 0x01010501);
1431 WREG32(mmTPC6_RTR_HBW_RD_RQ_N_ARB
, 0x01010101);
1432 WREG32(mmTPC6_RTR_HBW_RD_RQ_S_ARB
, 0x01010101);
1433 WREG32(mmTPC6_RTR_HBW_RD_RQ_E_ARB
, 0x01010601);
1434 WREG32(mmTPC6_RTR_HBW_WR_RQ_N_ARB
, 0x01010101);
1435 WREG32(mmTPC6_RTR_HBW_WR_RQ_S_ARB
, 0x01010101);
1436 WREG32(mmTPC6_RTR_HBW_WR_RQ_E_ARB
, 0x02020702);
1437 WREG32(mmTPC6_RTR_HBW_RD_RS_N_ARB
, 0x01010101);
1438 WREG32(mmTPC6_RTR_HBW_RD_RS_S_ARB
, 0x01010101);
1439 WREG32(mmTPC6_RTR_HBW_RD_RS_W_ARB
, 0x01020702);
1440 WREG32(mmTPC6_RTR_HBW_WR_RS_N_ARB
, 0x01050101);
1441 WREG32(mmTPC6_RTR_HBW_WR_RS_S_ARB
, 0x01010101);
1442 WREG32(mmTPC6_RTR_HBW_WR_RS_W_ARB
, 0x01010501);
1444 for (i
= 0, offset
= 0 ; i
< 10 ; i
++, offset
+= 4) {
1445 WREG32(mmMME1_RTR_SPLIT_COEF_0
+ offset
, polynom
[i
] >> 7);
1446 WREG32(mmMME2_RTR_SPLIT_COEF_0
+ offset
, polynom
[i
] >> 7);
1447 WREG32(mmMME3_RTR_SPLIT_COEF_0
+ offset
, polynom
[i
] >> 7);
1448 WREG32(mmMME4_RTR_SPLIT_COEF_0
+ offset
, polynom
[i
] >> 7);
1449 WREG32(mmMME5_RTR_SPLIT_COEF_0
+ offset
, polynom
[i
] >> 7);
1450 WREG32(mmMME6_RTR_SPLIT_COEF_0
+ offset
, polynom
[i
] >> 7);
1452 WREG32(mmTPC0_NRTR_SPLIT_COEF_0
+ offset
, polynom
[i
] >> 7);
1453 WREG32(mmTPC1_RTR_SPLIT_COEF_0
+ offset
, polynom
[i
] >> 7);
1454 WREG32(mmTPC2_RTR_SPLIT_COEF_0
+ offset
, polynom
[i
] >> 7);
1455 WREG32(mmTPC3_RTR_SPLIT_COEF_0
+ offset
, polynom
[i
] >> 7);
1456 WREG32(mmTPC4_RTR_SPLIT_COEF_0
+ offset
, polynom
[i
] >> 7);
1457 WREG32(mmTPC5_RTR_SPLIT_COEF_0
+ offset
, polynom
[i
] >> 7);
1458 WREG32(mmTPC6_RTR_SPLIT_COEF_0
+ offset
, polynom
[i
] >> 7);
1459 WREG32(mmTPC7_NRTR_SPLIT_COEF_0
+ offset
, polynom
[i
] >> 7);
1461 WREG32(mmPCI_NRTR_SPLIT_COEF_0
+ offset
, polynom
[i
] >> 7);
1462 WREG32(mmDMA_NRTR_SPLIT_COEF_0
+ offset
, polynom
[i
] >> 7);
1465 for (i
= 0, offset
= 0 ; i
< 6 ; i
++, offset
+= 0x40000) {
1466 WREG32(mmMME1_RTR_SCRAMB_EN
+ offset
,
1467 1 << MME1_RTR_SCRAMB_EN_VAL_SHIFT
);
1468 WREG32(mmMME1_RTR_NON_LIN_SCRAMB
+ offset
,
1469 1 << MME1_RTR_NON_LIN_SCRAMB_EN_SHIFT
);
1472 for (i
= 0, offset
= 0 ; i
< 8 ; i
++, offset
+= 0x40000) {
1474 * Workaround for Bug H2 #2441 :
1475 * "ST.NOP set trace event illegal opcode"
1477 WREG32(mmTPC0_CFG_TPC_INTR_MASK
+ offset
, tpc_intr_mask
);
1479 WREG32(mmTPC0_NRTR_SCRAMB_EN
+ offset
,
1480 1 << TPC0_NRTR_SCRAMB_EN_VAL_SHIFT
);
1481 WREG32(mmTPC0_NRTR_NON_LIN_SCRAMB
+ offset
,
1482 1 << TPC0_NRTR_NON_LIN_SCRAMB_EN_SHIFT
);
1484 WREG32_FIELD(TPC0_CFG_MSS_CONFIG
, offset
,
1485 ICACHE_FETCH_LINE_NUM
, 2);
1488 WREG32(mmDMA_NRTR_SCRAMB_EN
, 1 << DMA_NRTR_SCRAMB_EN_VAL_SHIFT
);
1489 WREG32(mmDMA_NRTR_NON_LIN_SCRAMB
,
1490 1 << DMA_NRTR_NON_LIN_SCRAMB_EN_SHIFT
);
1492 WREG32(mmPCI_NRTR_SCRAMB_EN
, 1 << PCI_NRTR_SCRAMB_EN_VAL_SHIFT
);
1493 WREG32(mmPCI_NRTR_NON_LIN_SCRAMB
,
1494 1 << PCI_NRTR_NON_LIN_SCRAMB_EN_SHIFT
);
1497 * Workaround for H2 #HW-23 bug
1498 * Set DMA max outstanding read requests to 240 on DMA CH 1.
1499 * This limitation is still large enough to not affect Gen4 bandwidth.
1500 * We need to only limit that DMA channel because the user can only read
1501 * from Host using DMA CH 1
1503 WREG32(mmDMA_CH_1_CFG0
, 0x0fff00F0);
1505 WREG32(mmTPC_PLL_CLK_RLX_0
, 0x200020);
1507 goya
->hw_cap_initialized
|= HW_CAP_GOLDEN
;
1510 static void goya_init_mme_qman(struct hl_device
*hdev
)
1512 u32 mtr_base_lo
, mtr_base_hi
;
1513 u32 so_base_lo
, so_base_hi
;
1514 u32 gic_base_lo
, gic_base_hi
;
1517 mtr_base_lo
= lower_32_bits(CFG_BASE
+ mmSYNC_MNGR_MON_PAY_ADDRL_0
);
1518 mtr_base_hi
= upper_32_bits(CFG_BASE
+ mmSYNC_MNGR_MON_PAY_ADDRL_0
);
1519 so_base_lo
= lower_32_bits(CFG_BASE
+ mmSYNC_MNGR_SOB_OBJ_0
);
1520 so_base_hi
= upper_32_bits(CFG_BASE
+ mmSYNC_MNGR_SOB_OBJ_0
);
1523 lower_32_bits(CFG_BASE
+ mmGIC_DISTRIBUTOR__5_GICD_SETSPI_NSR
);
1525 upper_32_bits(CFG_BASE
+ mmGIC_DISTRIBUTOR__5_GICD_SETSPI_NSR
);
1527 qman_base_addr
= hdev
->asic_prop
.sram_base_address
+
1528 MME_QMAN_BASE_OFFSET
;
1530 WREG32(mmMME_QM_PQ_BASE_LO
, lower_32_bits(qman_base_addr
));
1531 WREG32(mmMME_QM_PQ_BASE_HI
, upper_32_bits(qman_base_addr
));
1532 WREG32(mmMME_QM_PQ_SIZE
, ilog2(MME_QMAN_LENGTH
));
1533 WREG32(mmMME_QM_PQ_PI
, 0);
1534 WREG32(mmMME_QM_PQ_CI
, 0);
1535 WREG32(mmMME_QM_CP_LDMA_SRC_BASE_LO_OFFSET
, 0x10C0);
1536 WREG32(mmMME_QM_CP_LDMA_SRC_BASE_HI_OFFSET
, 0x10C4);
1537 WREG32(mmMME_QM_CP_LDMA_TSIZE_OFFSET
, 0x10C8);
1538 WREG32(mmMME_QM_CP_LDMA_COMMIT_OFFSET
, 0x10CC);
1540 WREG32(mmMME_QM_CP_MSG_BASE0_ADDR_LO
, mtr_base_lo
);
1541 WREG32(mmMME_QM_CP_MSG_BASE0_ADDR_HI
, mtr_base_hi
);
1542 WREG32(mmMME_QM_CP_MSG_BASE1_ADDR_LO
, so_base_lo
);
1543 WREG32(mmMME_QM_CP_MSG_BASE1_ADDR_HI
, so_base_hi
);
1545 /* QMAN CQ has 8 cache lines */
1546 WREG32(mmMME_QM_CQ_CFG1
, 0x00080008);
1548 WREG32(mmMME_QM_GLBL_ERR_ADDR_LO
, gic_base_lo
);
1549 WREG32(mmMME_QM_GLBL_ERR_ADDR_HI
, gic_base_hi
);
1551 WREG32(mmMME_QM_GLBL_ERR_WDATA
, GOYA_ASYNC_EVENT_ID_MME_QM
);
1553 WREG32(mmMME_QM_GLBL_ERR_CFG
, QMAN_MME_ERR_MSG_EN
);
1555 WREG32(mmMME_QM_GLBL_PROT
, QMAN_MME_ERR_PROT
);
1557 WREG32(mmMME_QM_GLBL_CFG0
, QMAN_MME_ENABLE
);
1560 static void goya_init_mme_cmdq(struct hl_device
*hdev
)
1562 u32 mtr_base_lo
, mtr_base_hi
;
1563 u32 so_base_lo
, so_base_hi
;
1564 u32 gic_base_lo
, gic_base_hi
;
1566 mtr_base_lo
= lower_32_bits(CFG_BASE
+ mmSYNC_MNGR_MON_PAY_ADDRL_0
);
1567 mtr_base_hi
= upper_32_bits(CFG_BASE
+ mmSYNC_MNGR_MON_PAY_ADDRL_0
);
1568 so_base_lo
= lower_32_bits(CFG_BASE
+ mmSYNC_MNGR_SOB_OBJ_0
);
1569 so_base_hi
= upper_32_bits(CFG_BASE
+ mmSYNC_MNGR_SOB_OBJ_0
);
1572 lower_32_bits(CFG_BASE
+ mmGIC_DISTRIBUTOR__5_GICD_SETSPI_NSR
);
1574 upper_32_bits(CFG_BASE
+ mmGIC_DISTRIBUTOR__5_GICD_SETSPI_NSR
);
1576 WREG32(mmMME_CMDQ_CP_MSG_BASE0_ADDR_LO
, mtr_base_lo
);
1577 WREG32(mmMME_CMDQ_CP_MSG_BASE0_ADDR_HI
, mtr_base_hi
);
1578 WREG32(mmMME_CMDQ_CP_MSG_BASE1_ADDR_LO
, so_base_lo
);
1579 WREG32(mmMME_CMDQ_CP_MSG_BASE1_ADDR_HI
, so_base_hi
);
1581 /* CMDQ CQ has 20 cache lines */
1582 WREG32(mmMME_CMDQ_CQ_CFG1
, 0x00140014);
1584 WREG32(mmMME_CMDQ_GLBL_ERR_ADDR_LO
, gic_base_lo
);
1585 WREG32(mmMME_CMDQ_GLBL_ERR_ADDR_HI
, gic_base_hi
);
1587 WREG32(mmMME_CMDQ_GLBL_ERR_WDATA
, GOYA_ASYNC_EVENT_ID_MME_CMDQ
);
1589 WREG32(mmMME_CMDQ_GLBL_ERR_CFG
, CMDQ_MME_ERR_MSG_EN
);
1591 WREG32(mmMME_CMDQ_GLBL_PROT
, CMDQ_MME_ERR_PROT
);
1593 WREG32(mmMME_CMDQ_GLBL_CFG0
, CMDQ_MME_ENABLE
);
1596 void goya_init_mme_qmans(struct hl_device
*hdev
)
1598 struct goya_device
*goya
= hdev
->asic_specific
;
1599 u32 so_base_lo
, so_base_hi
;
1601 if (goya
->hw_cap_initialized
& HW_CAP_MME
)
1604 so_base_lo
= lower_32_bits(CFG_BASE
+ mmSYNC_MNGR_SOB_OBJ_0
);
1605 so_base_hi
= upper_32_bits(CFG_BASE
+ mmSYNC_MNGR_SOB_OBJ_0
);
1607 WREG32(mmMME_SM_BASE_ADDRESS_LOW
, so_base_lo
);
1608 WREG32(mmMME_SM_BASE_ADDRESS_HIGH
, so_base_hi
);
1610 goya_init_mme_qman(hdev
);
1611 goya_init_mme_cmdq(hdev
);
1613 goya
->hw_cap_initialized
|= HW_CAP_MME
;
1616 static void goya_init_tpc_qman(struct hl_device
*hdev
, u32 base_off
, int tpc_id
)
1618 u32 mtr_base_lo
, mtr_base_hi
;
1619 u32 so_base_lo
, so_base_hi
;
1620 u32 gic_base_lo
, gic_base_hi
;
1622 u32 reg_off
= tpc_id
* (mmTPC1_QM_PQ_PI
- mmTPC0_QM_PQ_PI
);
1624 mtr_base_lo
= lower_32_bits(CFG_BASE
+ mmSYNC_MNGR_MON_PAY_ADDRL_0
);
1625 mtr_base_hi
= upper_32_bits(CFG_BASE
+ mmSYNC_MNGR_MON_PAY_ADDRL_0
);
1626 so_base_lo
= lower_32_bits(CFG_BASE
+ mmSYNC_MNGR_SOB_OBJ_0
);
1627 so_base_hi
= upper_32_bits(CFG_BASE
+ mmSYNC_MNGR_SOB_OBJ_0
);
1630 lower_32_bits(CFG_BASE
+ mmGIC_DISTRIBUTOR__5_GICD_SETSPI_NSR
);
1632 upper_32_bits(CFG_BASE
+ mmGIC_DISTRIBUTOR__5_GICD_SETSPI_NSR
);
1634 qman_base_addr
= hdev
->asic_prop
.sram_base_address
+ base_off
;
1636 WREG32(mmTPC0_QM_PQ_BASE_LO
+ reg_off
, lower_32_bits(qman_base_addr
));
1637 WREG32(mmTPC0_QM_PQ_BASE_HI
+ reg_off
, upper_32_bits(qman_base_addr
));
1638 WREG32(mmTPC0_QM_PQ_SIZE
+ reg_off
, ilog2(TPC_QMAN_LENGTH
));
1639 WREG32(mmTPC0_QM_PQ_PI
+ reg_off
, 0);
1640 WREG32(mmTPC0_QM_PQ_CI
+ reg_off
, 0);
1641 WREG32(mmTPC0_QM_CP_LDMA_SRC_BASE_LO_OFFSET
+ reg_off
, 0x10C0);
1642 WREG32(mmTPC0_QM_CP_LDMA_SRC_BASE_HI_OFFSET
+ reg_off
, 0x10C4);
1643 WREG32(mmTPC0_QM_CP_LDMA_TSIZE_OFFSET
+ reg_off
, 0x10C8);
1644 WREG32(mmTPC0_QM_CP_LDMA_COMMIT_OFFSET
+ reg_off
, 0x10CC);
1646 WREG32(mmTPC0_QM_CP_MSG_BASE0_ADDR_LO
+ reg_off
, mtr_base_lo
);
1647 WREG32(mmTPC0_QM_CP_MSG_BASE0_ADDR_HI
+ reg_off
, mtr_base_hi
);
1648 WREG32(mmTPC0_QM_CP_MSG_BASE1_ADDR_LO
+ reg_off
, so_base_lo
);
1649 WREG32(mmTPC0_QM_CP_MSG_BASE1_ADDR_HI
+ reg_off
, so_base_hi
);
1651 WREG32(mmTPC0_QM_CQ_CFG1
+ reg_off
, 0x00080008);
1653 WREG32(mmTPC0_QM_GLBL_ERR_ADDR_LO
+ reg_off
, gic_base_lo
);
1654 WREG32(mmTPC0_QM_GLBL_ERR_ADDR_HI
+ reg_off
, gic_base_hi
);
1656 WREG32(mmTPC0_QM_GLBL_ERR_WDATA
+ reg_off
,
1657 GOYA_ASYNC_EVENT_ID_TPC0_QM
+ tpc_id
);
1659 WREG32(mmTPC0_QM_GLBL_ERR_CFG
+ reg_off
, QMAN_TPC_ERR_MSG_EN
);
1661 WREG32(mmTPC0_QM_GLBL_PROT
+ reg_off
, QMAN_TPC_ERR_PROT
);
1663 WREG32(mmTPC0_QM_GLBL_CFG0
+ reg_off
, QMAN_TPC_ENABLE
);
1666 static void goya_init_tpc_cmdq(struct hl_device
*hdev
, int tpc_id
)
1668 u32 mtr_base_lo
, mtr_base_hi
;
1669 u32 so_base_lo
, so_base_hi
;
1670 u32 gic_base_lo
, gic_base_hi
;
1671 u32 reg_off
= tpc_id
* (mmTPC1_CMDQ_CQ_CFG1
- mmTPC0_CMDQ_CQ_CFG1
);
1673 mtr_base_lo
= lower_32_bits(CFG_BASE
+ mmSYNC_MNGR_MON_PAY_ADDRL_0
);
1674 mtr_base_hi
= upper_32_bits(CFG_BASE
+ mmSYNC_MNGR_MON_PAY_ADDRL_0
);
1675 so_base_lo
= lower_32_bits(CFG_BASE
+ mmSYNC_MNGR_SOB_OBJ_0
);
1676 so_base_hi
= upper_32_bits(CFG_BASE
+ mmSYNC_MNGR_SOB_OBJ_0
);
1679 lower_32_bits(CFG_BASE
+ mmGIC_DISTRIBUTOR__5_GICD_SETSPI_NSR
);
1681 upper_32_bits(CFG_BASE
+ mmGIC_DISTRIBUTOR__5_GICD_SETSPI_NSR
);
1683 WREG32(mmTPC0_CMDQ_CP_MSG_BASE0_ADDR_LO
+ reg_off
, mtr_base_lo
);
1684 WREG32(mmTPC0_CMDQ_CP_MSG_BASE0_ADDR_HI
+ reg_off
, mtr_base_hi
);
1685 WREG32(mmTPC0_CMDQ_CP_MSG_BASE1_ADDR_LO
+ reg_off
, so_base_lo
);
1686 WREG32(mmTPC0_CMDQ_CP_MSG_BASE1_ADDR_HI
+ reg_off
, so_base_hi
);
1688 WREG32(mmTPC0_CMDQ_CQ_CFG1
+ reg_off
, 0x00140014);
1690 WREG32(mmTPC0_CMDQ_GLBL_ERR_ADDR_LO
+ reg_off
, gic_base_lo
);
1691 WREG32(mmTPC0_CMDQ_GLBL_ERR_ADDR_HI
+ reg_off
, gic_base_hi
);
1693 WREG32(mmTPC0_CMDQ_GLBL_ERR_WDATA
+ reg_off
,
1694 GOYA_ASYNC_EVENT_ID_TPC0_CMDQ
+ tpc_id
);
1696 WREG32(mmTPC0_CMDQ_GLBL_ERR_CFG
+ reg_off
, CMDQ_TPC_ERR_MSG_EN
);
1698 WREG32(mmTPC0_CMDQ_GLBL_PROT
+ reg_off
, CMDQ_TPC_ERR_PROT
);
1700 WREG32(mmTPC0_CMDQ_GLBL_CFG0
+ reg_off
, CMDQ_TPC_ENABLE
);
1703 void goya_init_tpc_qmans(struct hl_device
*hdev
)
1705 struct goya_device
*goya
= hdev
->asic_specific
;
1706 u32 so_base_lo
, so_base_hi
;
1707 u32 cfg_off
= mmTPC1_CFG_SM_BASE_ADDRESS_LOW
-
1708 mmTPC0_CFG_SM_BASE_ADDRESS_LOW
;
1711 if (goya
->hw_cap_initialized
& HW_CAP_TPC
)
1714 so_base_lo
= lower_32_bits(CFG_BASE
+ mmSYNC_MNGR_SOB_OBJ_0
);
1715 so_base_hi
= upper_32_bits(CFG_BASE
+ mmSYNC_MNGR_SOB_OBJ_0
);
1717 for (i
= 0 ; i
< TPC_MAX_NUM
; i
++) {
1718 WREG32(mmTPC0_CFG_SM_BASE_ADDRESS_LOW
+ i
* cfg_off
,
1720 WREG32(mmTPC0_CFG_SM_BASE_ADDRESS_HIGH
+ i
* cfg_off
,
1724 goya_init_tpc_qman(hdev
, TPC0_QMAN_BASE_OFFSET
, 0);
1725 goya_init_tpc_qman(hdev
, TPC1_QMAN_BASE_OFFSET
, 1);
1726 goya_init_tpc_qman(hdev
, TPC2_QMAN_BASE_OFFSET
, 2);
1727 goya_init_tpc_qman(hdev
, TPC3_QMAN_BASE_OFFSET
, 3);
1728 goya_init_tpc_qman(hdev
, TPC4_QMAN_BASE_OFFSET
, 4);
1729 goya_init_tpc_qman(hdev
, TPC5_QMAN_BASE_OFFSET
, 5);
1730 goya_init_tpc_qman(hdev
, TPC6_QMAN_BASE_OFFSET
, 6);
1731 goya_init_tpc_qman(hdev
, TPC7_QMAN_BASE_OFFSET
, 7);
1733 for (i
= 0 ; i
< TPC_MAX_NUM
; i
++)
1734 goya_init_tpc_cmdq(hdev
, i
);
1736 goya
->hw_cap_initialized
|= HW_CAP_TPC
;
1740 * goya_disable_internal_queues - Disable internal queues
1742 * @hdev: pointer to hl_device structure
1745 static void goya_disable_internal_queues(struct hl_device
*hdev
)
1747 WREG32(mmMME_QM_GLBL_CFG0
, 0);
1748 WREG32(mmMME_CMDQ_GLBL_CFG0
, 0);
1750 WREG32(mmTPC0_QM_GLBL_CFG0
, 0);
1751 WREG32(mmTPC0_CMDQ_GLBL_CFG0
, 0);
1753 WREG32(mmTPC1_QM_GLBL_CFG0
, 0);
1754 WREG32(mmTPC1_CMDQ_GLBL_CFG0
, 0);
1756 WREG32(mmTPC2_QM_GLBL_CFG0
, 0);
1757 WREG32(mmTPC2_CMDQ_GLBL_CFG0
, 0);
1759 WREG32(mmTPC3_QM_GLBL_CFG0
, 0);
1760 WREG32(mmTPC3_CMDQ_GLBL_CFG0
, 0);
1762 WREG32(mmTPC4_QM_GLBL_CFG0
, 0);
1763 WREG32(mmTPC4_CMDQ_GLBL_CFG0
, 0);
1765 WREG32(mmTPC5_QM_GLBL_CFG0
, 0);
1766 WREG32(mmTPC5_CMDQ_GLBL_CFG0
, 0);
1768 WREG32(mmTPC6_QM_GLBL_CFG0
, 0);
1769 WREG32(mmTPC6_CMDQ_GLBL_CFG0
, 0);
1771 WREG32(mmTPC7_QM_GLBL_CFG0
, 0);
1772 WREG32(mmTPC7_CMDQ_GLBL_CFG0
, 0);
1776 * goya_stop_internal_queues - Stop internal queues
1778 * @hdev: pointer to hl_device structure
1780 * Returns 0 on success
1783 static int goya_stop_internal_queues(struct hl_device
*hdev
)
1788 * Each queue (QMAN) is a separate H/W logic. That means that each
1789 * QMAN can be stopped independently and failure to stop one does NOT
1790 * mandate we should not try to stop other QMANs
1793 rc
= goya_stop_queue(hdev
,
1796 mmMME_QM_GLBL_STS0
);
1799 dev_err(hdev
->dev
, "failed to stop MME QMAN\n");
1803 rc
= goya_stop_queue(hdev
,
1804 mmMME_CMDQ_GLBL_CFG1
,
1806 mmMME_CMDQ_GLBL_STS0
);
1809 dev_err(hdev
->dev
, "failed to stop MME CMDQ\n");
1813 rc
= goya_stop_queue(hdev
,
1814 mmTPC0_QM_GLBL_CFG1
,
1816 mmTPC0_QM_GLBL_STS0
);
1819 dev_err(hdev
->dev
, "failed to stop TPC 0 QMAN\n");
1823 rc
= goya_stop_queue(hdev
,
1824 mmTPC0_CMDQ_GLBL_CFG1
,
1826 mmTPC0_CMDQ_GLBL_STS0
);
1829 dev_err(hdev
->dev
, "failed to stop TPC 0 CMDQ\n");
1833 rc
= goya_stop_queue(hdev
,
1834 mmTPC1_QM_GLBL_CFG1
,
1836 mmTPC1_QM_GLBL_STS0
);
1839 dev_err(hdev
->dev
, "failed to stop TPC 1 QMAN\n");
1843 rc
= goya_stop_queue(hdev
,
1844 mmTPC1_CMDQ_GLBL_CFG1
,
1846 mmTPC1_CMDQ_GLBL_STS0
);
1849 dev_err(hdev
->dev
, "failed to stop TPC 1 CMDQ\n");
1853 rc
= goya_stop_queue(hdev
,
1854 mmTPC2_QM_GLBL_CFG1
,
1856 mmTPC2_QM_GLBL_STS0
);
1859 dev_err(hdev
->dev
, "failed to stop TPC 2 QMAN\n");
1863 rc
= goya_stop_queue(hdev
,
1864 mmTPC2_CMDQ_GLBL_CFG1
,
1866 mmTPC2_CMDQ_GLBL_STS0
);
1869 dev_err(hdev
->dev
, "failed to stop TPC 2 CMDQ\n");
1873 rc
= goya_stop_queue(hdev
,
1874 mmTPC3_QM_GLBL_CFG1
,
1876 mmTPC3_QM_GLBL_STS0
);
1879 dev_err(hdev
->dev
, "failed to stop TPC 3 QMAN\n");
1883 rc
= goya_stop_queue(hdev
,
1884 mmTPC3_CMDQ_GLBL_CFG1
,
1886 mmTPC3_CMDQ_GLBL_STS0
);
1889 dev_err(hdev
->dev
, "failed to stop TPC 3 CMDQ\n");
1893 rc
= goya_stop_queue(hdev
,
1894 mmTPC4_QM_GLBL_CFG1
,
1896 mmTPC4_QM_GLBL_STS0
);
1899 dev_err(hdev
->dev
, "failed to stop TPC 4 QMAN\n");
1903 rc
= goya_stop_queue(hdev
,
1904 mmTPC4_CMDQ_GLBL_CFG1
,
1906 mmTPC4_CMDQ_GLBL_STS0
);
1909 dev_err(hdev
->dev
, "failed to stop TPC 4 CMDQ\n");
1913 rc
= goya_stop_queue(hdev
,
1914 mmTPC5_QM_GLBL_CFG1
,
1916 mmTPC5_QM_GLBL_STS0
);
1919 dev_err(hdev
->dev
, "failed to stop TPC 5 QMAN\n");
1923 rc
= goya_stop_queue(hdev
,
1924 mmTPC5_CMDQ_GLBL_CFG1
,
1926 mmTPC5_CMDQ_GLBL_STS0
);
1929 dev_err(hdev
->dev
, "failed to stop TPC 5 CMDQ\n");
1933 rc
= goya_stop_queue(hdev
,
1934 mmTPC6_QM_GLBL_CFG1
,
1936 mmTPC6_QM_GLBL_STS0
);
1939 dev_err(hdev
->dev
, "failed to stop TPC 6 QMAN\n");
1943 rc
= goya_stop_queue(hdev
,
1944 mmTPC6_CMDQ_GLBL_CFG1
,
1946 mmTPC6_CMDQ_GLBL_STS0
);
1949 dev_err(hdev
->dev
, "failed to stop TPC 6 CMDQ\n");
1953 rc
= goya_stop_queue(hdev
,
1954 mmTPC7_QM_GLBL_CFG1
,
1956 mmTPC7_QM_GLBL_STS0
);
1959 dev_err(hdev
->dev
, "failed to stop TPC 7 QMAN\n");
1963 rc
= goya_stop_queue(hdev
,
1964 mmTPC7_CMDQ_GLBL_CFG1
,
1966 mmTPC7_CMDQ_GLBL_STS0
);
1969 dev_err(hdev
->dev
, "failed to stop TPC 7 CMDQ\n");
1976 static void goya_dma_stall(struct hl_device
*hdev
)
1978 WREG32(mmDMA_QM_0_GLBL_CFG1
, 1 << DMA_QM_0_GLBL_CFG1_DMA_STOP_SHIFT
);
1979 WREG32(mmDMA_QM_1_GLBL_CFG1
, 1 << DMA_QM_1_GLBL_CFG1_DMA_STOP_SHIFT
);
1980 WREG32(mmDMA_QM_2_GLBL_CFG1
, 1 << DMA_QM_2_GLBL_CFG1_DMA_STOP_SHIFT
);
1981 WREG32(mmDMA_QM_3_GLBL_CFG1
, 1 << DMA_QM_3_GLBL_CFG1_DMA_STOP_SHIFT
);
1982 WREG32(mmDMA_QM_4_GLBL_CFG1
, 1 << DMA_QM_4_GLBL_CFG1_DMA_STOP_SHIFT
);
1985 static void goya_tpc_stall(struct hl_device
*hdev
)
1987 WREG32(mmTPC0_CFG_TPC_STALL
, 1 << TPC0_CFG_TPC_STALL_V_SHIFT
);
1988 WREG32(mmTPC1_CFG_TPC_STALL
, 1 << TPC1_CFG_TPC_STALL_V_SHIFT
);
1989 WREG32(mmTPC2_CFG_TPC_STALL
, 1 << TPC2_CFG_TPC_STALL_V_SHIFT
);
1990 WREG32(mmTPC3_CFG_TPC_STALL
, 1 << TPC3_CFG_TPC_STALL_V_SHIFT
);
1991 WREG32(mmTPC4_CFG_TPC_STALL
, 1 << TPC4_CFG_TPC_STALL_V_SHIFT
);
1992 WREG32(mmTPC5_CFG_TPC_STALL
, 1 << TPC5_CFG_TPC_STALL_V_SHIFT
);
1993 WREG32(mmTPC6_CFG_TPC_STALL
, 1 << TPC6_CFG_TPC_STALL_V_SHIFT
);
1994 WREG32(mmTPC7_CFG_TPC_STALL
, 1 << TPC7_CFG_TPC_STALL_V_SHIFT
);
1997 static void goya_mme_stall(struct hl_device
*hdev
)
1999 WREG32(mmMME_STALL
, 0xFFFFFFFF);
2002 static int goya_enable_msix(struct hl_device
*hdev
)
2004 struct goya_device
*goya
= hdev
->asic_specific
;
2005 int cq_cnt
= hdev
->asic_prop
.completion_queues_count
;
2006 int rc
, i
, irq_cnt_init
, irq
;
2008 if (goya
->hw_cap_initialized
& HW_CAP_MSIX
)
2011 rc
= pci_alloc_irq_vectors(hdev
->pdev
, GOYA_MSIX_ENTRIES
,
2012 GOYA_MSIX_ENTRIES
, PCI_IRQ_MSIX
);
2015 "MSI-X: Failed to enable support -- %d/%d\n",
2016 GOYA_MSIX_ENTRIES
, rc
);
2020 for (i
= 0, irq_cnt_init
= 0 ; i
< cq_cnt
; i
++, irq_cnt_init
++) {
2021 irq
= pci_irq_vector(hdev
->pdev
, i
);
2022 rc
= request_irq(irq
, hl_irq_handler_cq
, 0, goya_irq_name
[i
],
2023 &hdev
->completion_queue
[i
]);
2025 dev_err(hdev
->dev
, "Failed to request IRQ %d", irq
);
2030 irq
= pci_irq_vector(hdev
->pdev
, GOYA_EVENT_QUEUE_MSIX_IDX
);
2032 rc
= request_irq(irq
, hl_irq_handler_eq
, 0,
2033 goya_irq_name
[GOYA_EVENT_QUEUE_MSIX_IDX
],
2034 &hdev
->event_queue
);
2036 dev_err(hdev
->dev
, "Failed to request IRQ %d", irq
);
2040 goya
->hw_cap_initialized
|= HW_CAP_MSIX
;
2044 for (i
= 0 ; i
< irq_cnt_init
; i
++)
2045 free_irq(pci_irq_vector(hdev
->pdev
, i
),
2046 &hdev
->completion_queue
[i
]);
2048 pci_free_irq_vectors(hdev
->pdev
);
2052 static void goya_sync_irqs(struct hl_device
*hdev
)
2054 struct goya_device
*goya
= hdev
->asic_specific
;
2057 if (!(goya
->hw_cap_initialized
& HW_CAP_MSIX
))
2060 /* Wait for all pending IRQs to be finished */
2061 for (i
= 0 ; i
< hdev
->asic_prop
.completion_queues_count
; i
++)
2062 synchronize_irq(pci_irq_vector(hdev
->pdev
, i
));
2064 synchronize_irq(pci_irq_vector(hdev
->pdev
, GOYA_EVENT_QUEUE_MSIX_IDX
));
2067 static void goya_disable_msix(struct hl_device
*hdev
)
2069 struct goya_device
*goya
= hdev
->asic_specific
;
2072 if (!(goya
->hw_cap_initialized
& HW_CAP_MSIX
))
2075 goya_sync_irqs(hdev
);
2077 irq
= pci_irq_vector(hdev
->pdev
, GOYA_EVENT_QUEUE_MSIX_IDX
);
2078 free_irq(irq
, &hdev
->event_queue
);
2080 for (i
= 0 ; i
< hdev
->asic_prop
.completion_queues_count
; i
++) {
2081 irq
= pci_irq_vector(hdev
->pdev
, i
);
2082 free_irq(irq
, &hdev
->completion_queue
[i
]);
2085 pci_free_irq_vectors(hdev
->pdev
);
2087 goya
->hw_cap_initialized
&= ~HW_CAP_MSIX
;
2090 static void goya_enable_timestamp(struct hl_device
*hdev
)
2092 /* Disable the timestamp counter */
2093 WREG32(mmPSOC_TIMESTAMP_BASE
- CFG_BASE
, 0);
2095 /* Zero the lower/upper parts of the 64-bit counter */
2096 WREG32(mmPSOC_TIMESTAMP_BASE
- CFG_BASE
+ 0xC, 0);
2097 WREG32(mmPSOC_TIMESTAMP_BASE
- CFG_BASE
+ 0x8, 0);
2099 /* Enable the counter */
2100 WREG32(mmPSOC_TIMESTAMP_BASE
- CFG_BASE
, 1);
2103 static void goya_disable_timestamp(struct hl_device
*hdev
)
2105 /* Disable the timestamp counter */
2106 WREG32(mmPSOC_TIMESTAMP_BASE
- CFG_BASE
, 0);
2109 static void goya_halt_engines(struct hl_device
*hdev
, bool hard_reset
)
2111 u32 wait_timeout_ms
, cpu_timeout_ms
;
2114 "Halting compute engines and disabling interrupts\n");
2117 wait_timeout_ms
= GOYA_PLDM_RESET_WAIT_MSEC
;
2118 cpu_timeout_ms
= GOYA_PLDM_RESET_WAIT_MSEC
;
2120 wait_timeout_ms
= GOYA_RESET_WAIT_MSEC
;
2121 cpu_timeout_ms
= GOYA_CPU_RESET_WAIT_MSEC
;
2126 * I don't know what is the state of the CPU so make sure it is
2127 * stopped in any means necessary
2129 WREG32(mmPSOC_GLOBAL_CONF_UBOOT_MAGIC
, KMD_MSG_GOTO_WFE
);
2130 WREG32(mmGIC_DISTRIBUTOR__5_GICD_SETSPI_NSR
,
2131 GOYA_ASYNC_EVENT_ID_HALT_MACHINE
);
2132 msleep(cpu_timeout_ms
);
2135 goya_stop_external_queues(hdev
);
2136 goya_stop_internal_queues(hdev
);
2138 msleep(wait_timeout_ms
);
2140 goya_dma_stall(hdev
);
2141 goya_tpc_stall(hdev
);
2142 goya_mme_stall(hdev
);
2144 msleep(wait_timeout_ms
);
2146 goya_disable_external_queues(hdev
);
2147 goya_disable_internal_queues(hdev
);
2149 goya_disable_timestamp(hdev
);
2152 goya_disable_msix(hdev
);
2153 goya_mmu_remove_device_cpu_mappings(hdev
);
2155 goya_sync_irqs(hdev
);
2160 * goya_push_uboot_to_device() - Push u-boot FW code to device.
2161 * @hdev: Pointer to hl_device structure.
2163 * Copy u-boot fw code from firmware file to SRAM BAR.
2165 * Return: 0 on success, non-zero for failure.
2167 static int goya_push_uboot_to_device(struct hl_device
*hdev
)
2171 dst
= hdev
->pcie_bar
[SRAM_CFG_BAR_ID
] + UBOOT_FW_OFFSET
;
2173 return hl_fw_push_fw_to_device(hdev
, GOYA_UBOOT_FW_FILE
, dst
);
2177 * goya_push_linux_to_device() - Push LINUX FW code to device.
2178 * @hdev: Pointer to hl_device structure.
2180 * Copy LINUX fw code from firmware file to HBM BAR.
2182 * Return: 0 on success, non-zero for failure.
2184 static int goya_push_linux_to_device(struct hl_device
*hdev
)
2188 dst
= hdev
->pcie_bar
[DDR_BAR_ID
] + LINUX_FW_OFFSET
;
2190 return hl_fw_push_fw_to_device(hdev
, GOYA_LINUX_FW_FILE
, dst
);
2193 static int goya_pldm_init_cpu(struct hl_device
*hdev
)
2198 /* Must initialize SRAM scrambler before pushing u-boot to SRAM */
2199 goya_init_golden_registers(hdev
);
2201 /* Put ARM cores into reset */
2202 WREG32(mmCPU_CA53_CFG_ARM_RST_CONTROL
, CPU_RESET_ASSERT
);
2203 RREG32(mmCPU_CA53_CFG_ARM_RST_CONTROL
);
2205 /* Reset the CA53 MACRO */
2206 unit_rst_val
= RREG32(mmPSOC_GLOBAL_CONF_UNIT_RST_N
);
2207 WREG32(mmPSOC_GLOBAL_CONF_UNIT_RST_N
, CA53_RESET
);
2208 RREG32(mmPSOC_GLOBAL_CONF_UNIT_RST_N
);
2209 WREG32(mmPSOC_GLOBAL_CONF_UNIT_RST_N
, unit_rst_val
);
2210 RREG32(mmPSOC_GLOBAL_CONF_UNIT_RST_N
);
2212 rc
= goya_push_uboot_to_device(hdev
);
2216 rc
= goya_push_linux_to_device(hdev
);
2220 WREG32(mmPSOC_GLOBAL_CONF_UBOOT_MAGIC
, KMD_MSG_FIT_RDY
);
2221 WREG32(mmPSOC_GLOBAL_CONF_WARM_REBOOT
, CPU_BOOT_STATUS_NA
);
2223 WREG32(mmCPU_CA53_CFG_RST_ADDR_LSB_0
,
2224 lower_32_bits(SRAM_BASE_ADDR
+ UBOOT_FW_OFFSET
));
2225 WREG32(mmCPU_CA53_CFG_RST_ADDR_MSB_0
,
2226 upper_32_bits(SRAM_BASE_ADDR
+ UBOOT_FW_OFFSET
));
2228 /* Release ARM core 0 from reset */
2229 WREG32(mmCPU_CA53_CFG_ARM_RST_CONTROL
,
2230 CPU_RESET_CORE0_DEASSERT
);
2231 RREG32(mmCPU_CA53_CFG_ARM_RST_CONTROL
);
2237 * FW component passes an offset from SRAM_BASE_ADDR in SCRATCHPAD_xx.
2238 * The version string should be located by that offset.
2240 static void goya_read_device_fw_version(struct hl_device
*hdev
,
2241 enum goya_fw_component fwc
)
2249 ver_off
= RREG32(mmUBOOT_VER_OFFSET
);
2250 dest
= hdev
->asic_prop
.uboot_ver
;
2253 case FW_COMP_PREBOOT
:
2254 ver_off
= RREG32(mmPREBOOT_VER_OFFSET
);
2255 dest
= hdev
->asic_prop
.preboot_ver
;
2259 dev_warn(hdev
->dev
, "Undefined FW component: %d\n", fwc
);
2263 ver_off
&= ~((u32
)SRAM_BASE_ADDR
);
2265 if (ver_off
< SRAM_SIZE
- VERSION_MAX_LEN
) {
2266 memcpy_fromio(dest
, hdev
->pcie_bar
[SRAM_CFG_BAR_ID
] + ver_off
,
2269 dev_err(hdev
->dev
, "%s version offset (0x%x) is above SRAM\n",
2271 strcpy(dest
, "unavailable");
2275 static int goya_init_cpu(struct hl_device
*hdev
, u32 cpu_timeout
)
2277 struct goya_device
*goya
= hdev
->asic_specific
;
2281 if (!hdev
->cpu_enable
)
2284 if (goya
->hw_cap_initialized
& HW_CAP_CPU
)
2288 * Before pushing u-boot/linux to device, need to set the ddr bar to
2289 * base address of dram
2291 if (goya_set_ddr_bar_base(hdev
, DRAM_PHYS_BASE
) == U64_MAX
) {
2293 "failed to map DDR bar to DRAM base address\n");
2298 rc
= goya_pldm_init_cpu(hdev
);
2305 /* Make sure CPU boot-loader is running */
2306 rc
= hl_poll_timeout(
2308 mmPSOC_GLOBAL_CONF_WARM_REBOOT
,
2310 (status
== CPU_BOOT_STATUS_DRAM_RDY
) ||
2311 (status
== CPU_BOOT_STATUS_SRAM_AVAIL
),
2315 /* Read U-Boot version now in case we will later fail */
2316 goya_read_device_fw_version(hdev
, FW_COMP_UBOOT
);
2317 goya_read_device_fw_version(hdev
, FW_COMP_PREBOOT
);
2320 dev_err(hdev
->dev
, "Error in ARM u-boot!");
2322 case CPU_BOOT_STATUS_NA
:
2324 "ARM status %d - BTL did NOT run\n", status
);
2326 case CPU_BOOT_STATUS_IN_WFE
:
2328 "ARM status %d - Inside WFE loop\n", status
);
2330 case CPU_BOOT_STATUS_IN_BTL
:
2332 "ARM status %d - Stuck in BTL\n", status
);
2334 case CPU_BOOT_STATUS_IN_PREBOOT
:
2336 "ARM status %d - Stuck in Preboot\n", status
);
2338 case CPU_BOOT_STATUS_IN_SPL
:
2340 "ARM status %d - Stuck in SPL\n", status
);
2342 case CPU_BOOT_STATUS_IN_UBOOT
:
2344 "ARM status %d - Stuck in u-boot\n", status
);
2346 case CPU_BOOT_STATUS_DRAM_INIT_FAIL
:
2348 "ARM status %d - DDR initialization failed\n",
2351 case CPU_BOOT_STATUS_UBOOT_NOT_READY
:
2353 "ARM status %d - u-boot stopped by user\n",
2356 case CPU_BOOT_STATUS_TS_INIT_FAIL
:
2358 "ARM status %d - Thermal Sensor initialization failed\n",
2363 "ARM status %d - Invalid status code\n",
2370 if (!hdev
->fw_loading
) {
2371 dev_info(hdev
->dev
, "Skip loading FW\n");
2375 if (status
== CPU_BOOT_STATUS_SRAM_AVAIL
)
2378 rc
= goya_push_linux_to_device(hdev
);
2382 WREG32(mmPSOC_GLOBAL_CONF_UBOOT_MAGIC
, KMD_MSG_FIT_RDY
);
2384 rc
= hl_poll_timeout(
2386 mmPSOC_GLOBAL_CONF_WARM_REBOOT
,
2388 (status
== CPU_BOOT_STATUS_SRAM_AVAIL
),
2393 if (status
== CPU_BOOT_STATUS_FIT_CORRUPTED
)
2395 "ARM u-boot reports FIT image is corrupted\n");
2398 "ARM Linux failed to load, %d\n", status
);
2399 WREG32(mmPSOC_GLOBAL_CONF_UBOOT_MAGIC
, KMD_MSG_NA
);
2403 dev_info(hdev
->dev
, "Successfully loaded firmware to device\n");
2406 goya
->hw_cap_initialized
|= HW_CAP_CPU
;
2411 static int goya_mmu_update_asid_hop0_addr(struct hl_device
*hdev
, u32 asid
,
2414 u32 status
, timeout_usec
;
2418 timeout_usec
= GOYA_PLDM_MMU_TIMEOUT_USEC
;
2420 timeout_usec
= MMU_CONFIG_TIMEOUT_USEC
;
2422 WREG32(MMU_HOP0_PA43_12
, phys_addr
>> MMU_HOP0_PA43_12_SHIFT
);
2423 WREG32(MMU_HOP0_PA49_44
, phys_addr
>> MMU_HOP0_PA49_44_SHIFT
);
2424 WREG32(MMU_ASID_BUSY
, 0x80000000 | asid
);
2426 rc
= hl_poll_timeout(
2430 !(status
& 0x80000000),
2436 "Timeout during MMU hop0 config of asid %d\n", asid
);
2443 int goya_mmu_init(struct hl_device
*hdev
)
2445 struct asic_fixed_properties
*prop
= &hdev
->asic_prop
;
2446 struct goya_device
*goya
= hdev
->asic_specific
;
2450 if (!hdev
->mmu_enable
)
2453 if (goya
->hw_cap_initialized
& HW_CAP_MMU
)
2456 hdev
->dram_supports_virtual_memory
= true;
2457 hdev
->dram_default_page_mapping
= true;
2459 for (i
= 0 ; i
< prop
->max_asid
; i
++) {
2460 hop0_addr
= prop
->mmu_pgt_addr
+
2461 (i
* prop
->mmu_hop_table_size
);
2463 rc
= goya_mmu_update_asid_hop0_addr(hdev
, i
, hop0_addr
);
2466 "failed to set hop0 addr for asid %d\n", i
);
2471 goya
->hw_cap_initialized
|= HW_CAP_MMU
;
2473 /* init MMU cache manage page */
2474 WREG32(mmSTLB_CACHE_INV_BASE_39_8
,
2475 lower_32_bits(MMU_CACHE_MNG_ADDR
>> 8));
2476 WREG32(mmSTLB_CACHE_INV_BASE_49_40
, MMU_CACHE_MNG_ADDR
>> 40);
2478 /* Remove follower feature due to performance bug */
2479 WREG32_AND(mmSTLB_STLB_FEATURE_EN
,
2480 (~STLB_STLB_FEATURE_EN_FOLLOWER_EN_MASK
));
2482 hdev
->asic_funcs
->mmu_invalidate_cache(hdev
, true,
2483 VM_TYPE_USERPTR
| VM_TYPE_PHYS_PACK
);
2485 WREG32(mmMMU_MMU_ENABLE
, 1);
2486 WREG32(mmMMU_SPI_MASK
, 0xF);
2495 * goya_hw_init - Goya hardware initialization code
2497 * @hdev: pointer to hl_device structure
2499 * Returns 0 on success
2502 static int goya_hw_init(struct hl_device
*hdev
)
2504 struct asic_fixed_properties
*prop
= &hdev
->asic_prop
;
2507 dev_info(hdev
->dev
, "Starting initialization of H/W\n");
2509 /* Perform read from the device to make sure device is up */
2510 RREG32(mmPCIE_DBI_DEVICE_ID_VENDOR_ID_REG
);
2513 * Let's mark in the H/W that we have reached this point. We check
2514 * this value in the reset_before_init function to understand whether
2515 * we need to reset the chip before doing H/W init. This register is
2516 * cleared by the H/W upon H/W reset
2518 WREG32(mmHW_STATE
, HL_DEVICE_HW_STATE_DIRTY
);
2520 rc
= goya_init_cpu(hdev
, GOYA_CPU_TIMEOUT_USEC
);
2522 dev_err(hdev
->dev
, "failed to initialize CPU\n");
2526 goya_tpc_mbist_workaround(hdev
);
2528 goya_init_golden_registers(hdev
);
2531 * After CPU initialization is finished, change DDR bar mapping inside
2532 * iATU to point to the start address of the MMU page tables
2534 if (goya_set_ddr_bar_base(hdev
, DRAM_PHYS_BASE
+
2535 (MMU_PAGE_TABLES_ADDR
&
2536 ~(prop
->dram_pci_bar_size
- 0x1ull
))) == U64_MAX
) {
2538 "failed to map DDR bar to MMU page tables\n");
2542 rc
= goya_mmu_init(hdev
);
2546 goya_init_security(hdev
);
2548 goya_init_dma_qmans(hdev
);
2550 goya_init_mme_qmans(hdev
);
2552 goya_init_tpc_qmans(hdev
);
2554 goya_enable_timestamp(hdev
);
2556 /* MSI-X must be enabled before CPU queues are initialized */
2557 rc
= goya_enable_msix(hdev
);
2559 goto disable_queues
;
2561 /* Perform read from the device to flush all MSI-X configuration */
2562 RREG32(mmPCIE_DBI_DEVICE_ID_VENDOR_ID_REG
);
2567 goya_disable_internal_queues(hdev
);
2568 goya_disable_external_queues(hdev
);
2574 * goya_hw_fini - Goya hardware tear-down code
2576 * @hdev: pointer to hl_device structure
2577 * @hard_reset: should we do hard reset to all engines or just reset the
2578 * compute/dma engines
2580 static void goya_hw_fini(struct hl_device
*hdev
, bool hard_reset
)
2582 struct goya_device
*goya
= hdev
->asic_specific
;
2583 u32 reset_timeout_ms
, status
;
2586 reset_timeout_ms
= GOYA_PLDM_RESET_TIMEOUT_MSEC
;
2588 reset_timeout_ms
= GOYA_RESET_TIMEOUT_MSEC
;
2591 goya_set_ddr_bar_base(hdev
, DRAM_PHYS_BASE
);
2592 goya_disable_clk_rlx(hdev
);
2593 goya_set_pll_refclk(hdev
);
2595 WREG32(mmPSOC_GLOBAL_CONF_SW_ALL_RST_CFG
, RESET_ALL
);
2597 "Issued HARD reset command, going to wait %dms\n",
2600 WREG32(mmPSOC_GLOBAL_CONF_SW_ALL_RST_CFG
, DMA_MME_TPC_RESET
);
2602 "Issued SOFT reset command, going to wait %dms\n",
2607 * After hard reset, we can't poll the BTM_FSM register because the PSOC
2608 * itself is in reset. In either reset we need to wait until the reset
2611 msleep(reset_timeout_ms
);
2613 status
= RREG32(mmPSOC_GLOBAL_CONF_BTM_FSM
);
2614 if (status
& PSOC_GLOBAL_CONF_BTM_FSM_STATE_MASK
)
2616 "Timeout while waiting for device to reset 0x%x\n",
2620 goya
->hw_cap_initialized
&= ~(HW_CAP_DMA
| HW_CAP_MME
|
2621 HW_CAP_GOLDEN
| HW_CAP_TPC
);
2622 WREG32(mmGIC_DISTRIBUTOR__5_GICD_SETSPI_NSR
,
2623 GOYA_ASYNC_EVENT_ID_SOFT_RESET
);
2627 /* Chicken bit to re-initiate boot sequencer flow */
2628 WREG32(mmPSOC_GLOBAL_CONF_BOOT_SEQ_RE_START
,
2629 1 << PSOC_GLOBAL_CONF_BOOT_SEQ_RE_START_IND_SHIFT
);
2630 /* Move boot manager FSM to pre boot sequencer init state */
2631 WREG32(mmPSOC_GLOBAL_CONF_SW_BTM_FSM
,
2632 0xA << PSOC_GLOBAL_CONF_SW_BTM_FSM_CTRL_SHIFT
);
2634 goya
->hw_cap_initialized
&= ~(HW_CAP_CPU
| HW_CAP_CPU_Q
|
2635 HW_CAP_DDR_0
| HW_CAP_DDR_1
|
2636 HW_CAP_DMA
| HW_CAP_MME
|
2637 HW_CAP_MMU
| HW_CAP_TPC_MBIST
|
2638 HW_CAP_GOLDEN
| HW_CAP_TPC
);
2639 memset(goya
->events_stat
, 0, sizeof(goya
->events_stat
));
2643 /* In case we are running inside VM and the VM is
2644 * shutting down, we need to make sure CPU boot-loader
2645 * is running before we can continue the VM shutdown.
2646 * That is because the VM will send an FLR signal that
2650 "Going to wait up to %ds for CPU boot loader\n",
2651 GOYA_CPU_TIMEOUT_USEC
/ 1000 / 1000);
2653 rc
= hl_poll_timeout(
2655 mmPSOC_GLOBAL_CONF_WARM_REBOOT
,
2657 (status
== CPU_BOOT_STATUS_DRAM_RDY
),
2659 GOYA_CPU_TIMEOUT_USEC
);
2662 "failed to wait for CPU boot loader\n");
2666 int goya_suspend(struct hl_device
*hdev
)
2670 rc
= hl_fw_send_pci_access_msg(hdev
, ARMCP_PACKET_DISABLE_PCI_ACCESS
);
2672 dev_err(hdev
->dev
, "Failed to disable PCI access from CPU\n");
2677 int goya_resume(struct hl_device
*hdev
)
2679 return goya_init_iatu(hdev
);
2682 static int goya_cb_mmap(struct hl_device
*hdev
, struct vm_area_struct
*vma
,
2683 u64 kaddress
, phys_addr_t paddress
, u32 size
)
2687 vma
->vm_flags
|= VM_IO
| VM_PFNMAP
| VM_DONTEXPAND
| VM_DONTDUMP
|
2688 VM_DONTCOPY
| VM_NORESERVE
;
2690 rc
= remap_pfn_range(vma
, vma
->vm_start
, paddress
>> PAGE_SHIFT
,
2691 size
, vma
->vm_page_prot
);
2693 dev_err(hdev
->dev
, "remap_pfn_range error %d", rc
);
2698 void goya_ring_doorbell(struct hl_device
*hdev
, u32 hw_queue_id
, u32 pi
)
2700 u32 db_reg_offset
, db_value
;
2702 switch (hw_queue_id
) {
2703 case GOYA_QUEUE_ID_DMA_0
:
2704 db_reg_offset
= mmDMA_QM_0_PQ_PI
;
2707 case GOYA_QUEUE_ID_DMA_1
:
2708 db_reg_offset
= mmDMA_QM_1_PQ_PI
;
2711 case GOYA_QUEUE_ID_DMA_2
:
2712 db_reg_offset
= mmDMA_QM_2_PQ_PI
;
2715 case GOYA_QUEUE_ID_DMA_3
:
2716 db_reg_offset
= mmDMA_QM_3_PQ_PI
;
2719 case GOYA_QUEUE_ID_DMA_4
:
2720 db_reg_offset
= mmDMA_QM_4_PQ_PI
;
2723 case GOYA_QUEUE_ID_CPU_PQ
:
2724 db_reg_offset
= mmCPU_IF_PF_PQ_PI
;
2727 case GOYA_QUEUE_ID_MME
:
2728 db_reg_offset
= mmMME_QM_PQ_PI
;
2731 case GOYA_QUEUE_ID_TPC0
:
2732 db_reg_offset
= mmTPC0_QM_PQ_PI
;
2735 case GOYA_QUEUE_ID_TPC1
:
2736 db_reg_offset
= mmTPC1_QM_PQ_PI
;
2739 case GOYA_QUEUE_ID_TPC2
:
2740 db_reg_offset
= mmTPC2_QM_PQ_PI
;
2743 case GOYA_QUEUE_ID_TPC3
:
2744 db_reg_offset
= mmTPC3_QM_PQ_PI
;
2747 case GOYA_QUEUE_ID_TPC4
:
2748 db_reg_offset
= mmTPC4_QM_PQ_PI
;
2751 case GOYA_QUEUE_ID_TPC5
:
2752 db_reg_offset
= mmTPC5_QM_PQ_PI
;
2755 case GOYA_QUEUE_ID_TPC6
:
2756 db_reg_offset
= mmTPC6_QM_PQ_PI
;
2759 case GOYA_QUEUE_ID_TPC7
:
2760 db_reg_offset
= mmTPC7_QM_PQ_PI
;
2764 /* Should never get here */
2765 dev_err(hdev
->dev
, "H/W queue %d is invalid. Can't set pi\n",
2772 /* ring the doorbell */
2773 WREG32(db_reg_offset
, db_value
);
2775 if (hw_queue_id
== GOYA_QUEUE_ID_CPU_PQ
)
2776 WREG32(mmGIC_DISTRIBUTOR__5_GICD_SETSPI_NSR
,
2777 GOYA_ASYNC_EVENT_ID_PI_UPDATE
);
2780 void goya_pqe_write(struct hl_device
*hdev
, __le64
*pqe
, struct hl_bd
*bd
)
2782 /* The QMANs are on the SRAM so need to copy to IO space */
2783 memcpy_toio((void __iomem
*) pqe
, bd
, sizeof(struct hl_bd
));
2786 static void *goya_dma_alloc_coherent(struct hl_device
*hdev
, size_t size
,
2787 dma_addr_t
*dma_handle
, gfp_t flags
)
2789 void *kernel_addr
= dma_alloc_coherent(&hdev
->pdev
->dev
, size
,
2792 /* Shift to the device's base physical address of host memory */
2794 *dma_handle
+= HOST_PHYS_BASE
;
2799 static void goya_dma_free_coherent(struct hl_device
*hdev
, size_t size
,
2800 void *cpu_addr
, dma_addr_t dma_handle
)
2802 /* Cancel the device's base physical address of host memory */
2803 dma_addr_t fixed_dma_handle
= dma_handle
- HOST_PHYS_BASE
;
2805 dma_free_coherent(&hdev
->pdev
->dev
, size
, cpu_addr
, fixed_dma_handle
);
2808 void *goya_get_int_queue_base(struct hl_device
*hdev
, u32 queue_id
,
2809 dma_addr_t
*dma_handle
, u16
*queue_len
)
2814 *dma_handle
= hdev
->asic_prop
.sram_base_address
;
2816 base
= (void *) hdev
->pcie_bar
[SRAM_CFG_BAR_ID
];
2819 case GOYA_QUEUE_ID_MME
:
2820 offset
= MME_QMAN_BASE_OFFSET
;
2821 *queue_len
= MME_QMAN_LENGTH
;
2823 case GOYA_QUEUE_ID_TPC0
:
2824 offset
= TPC0_QMAN_BASE_OFFSET
;
2825 *queue_len
= TPC_QMAN_LENGTH
;
2827 case GOYA_QUEUE_ID_TPC1
:
2828 offset
= TPC1_QMAN_BASE_OFFSET
;
2829 *queue_len
= TPC_QMAN_LENGTH
;
2831 case GOYA_QUEUE_ID_TPC2
:
2832 offset
= TPC2_QMAN_BASE_OFFSET
;
2833 *queue_len
= TPC_QMAN_LENGTH
;
2835 case GOYA_QUEUE_ID_TPC3
:
2836 offset
= TPC3_QMAN_BASE_OFFSET
;
2837 *queue_len
= TPC_QMAN_LENGTH
;
2839 case GOYA_QUEUE_ID_TPC4
:
2840 offset
= TPC4_QMAN_BASE_OFFSET
;
2841 *queue_len
= TPC_QMAN_LENGTH
;
2843 case GOYA_QUEUE_ID_TPC5
:
2844 offset
= TPC5_QMAN_BASE_OFFSET
;
2845 *queue_len
= TPC_QMAN_LENGTH
;
2847 case GOYA_QUEUE_ID_TPC6
:
2848 offset
= TPC6_QMAN_BASE_OFFSET
;
2849 *queue_len
= TPC_QMAN_LENGTH
;
2851 case GOYA_QUEUE_ID_TPC7
:
2852 offset
= TPC7_QMAN_BASE_OFFSET
;
2853 *queue_len
= TPC_QMAN_LENGTH
;
2856 dev_err(hdev
->dev
, "Got invalid queue id %d\n", queue_id
);
2861 *dma_handle
+= offset
;
2866 static int goya_send_job_on_qman0(struct hl_device
*hdev
, struct hl_cs_job
*job
)
2868 struct packet_msg_prot
*fence_pkt
;
2870 dma_addr_t fence_dma_addr
;
2876 timeout
= GOYA_PLDM_QMAN0_TIMEOUT_USEC
;
2878 timeout
= HL_DEVICE_TIMEOUT_USEC
;
2880 if (!hdev
->asic_funcs
->is_device_idle(hdev
, NULL
, NULL
)) {
2881 dev_err_ratelimited(hdev
->dev
,
2882 "Can't send driver job on QMAN0 because the device is not idle\n");
2886 fence_ptr
= hdev
->asic_funcs
->asic_dma_pool_zalloc(hdev
, 4, GFP_KERNEL
,
2890 "Failed to allocate fence memory for QMAN0\n");
2894 goya_qman0_set_security(hdev
, true);
2896 cb
= job
->patched_cb
;
2898 fence_pkt
= (struct packet_msg_prot
*) (uintptr_t) (cb
->kernel_address
+
2899 job
->job_cb_size
- sizeof(struct packet_msg_prot
));
2901 tmp
= (PACKET_MSG_PROT
<< GOYA_PKT_CTL_OPCODE_SHIFT
) |
2902 (1 << GOYA_PKT_CTL_EB_SHIFT
) |
2903 (1 << GOYA_PKT_CTL_MB_SHIFT
);
2904 fence_pkt
->ctl
= cpu_to_le32(tmp
);
2905 fence_pkt
->value
= cpu_to_le32(GOYA_QMAN0_FENCE_VAL
);
2906 fence_pkt
->addr
= cpu_to_le64(fence_dma_addr
);
2908 rc
= hl_hw_queue_send_cb_no_cmpl(hdev
, GOYA_QUEUE_ID_DMA_0
,
2909 job
->job_cb_size
, cb
->bus_address
);
2911 dev_err(hdev
->dev
, "Failed to send CB on QMAN0, %d\n", rc
);
2912 goto free_fence_ptr
;
2915 rc
= hl_poll_timeout_memory(hdev
, fence_ptr
, tmp
,
2916 (tmp
== GOYA_QMAN0_FENCE_VAL
), 1000,
2919 hl_hw_queue_inc_ci_kernel(hdev
, GOYA_QUEUE_ID_DMA_0
);
2921 if (rc
== -ETIMEDOUT
) {
2922 dev_err(hdev
->dev
, "QMAN0 Job timeout (0x%x)\n", tmp
);
2923 goto free_fence_ptr
;
2927 hdev
->asic_funcs
->asic_dma_pool_free(hdev
, (void *) fence_ptr
,
2930 goya_qman0_set_security(hdev
, false);
2935 int goya_send_cpu_message(struct hl_device
*hdev
, u32
*msg
, u16 len
,
2936 u32 timeout
, long *result
)
2938 struct goya_device
*goya
= hdev
->asic_specific
;
2940 if (!(goya
->hw_cap_initialized
& HW_CAP_CPU_Q
)) {
2946 return hl_fw_send_cpu_message(hdev
, GOYA_QUEUE_ID_CPU_PQ
, msg
, len
,
2950 int goya_test_queue(struct hl_device
*hdev
, u32 hw_queue_id
)
2952 struct packet_msg_prot
*fence_pkt
;
2953 dma_addr_t pkt_dma_addr
;
2955 dma_addr_t fence_dma_addr
;
2959 fence_val
= GOYA_QMAN0_FENCE_VAL
;
2961 fence_ptr
= hdev
->asic_funcs
->asic_dma_pool_zalloc(hdev
, 4, GFP_KERNEL
,
2965 "Failed to allocate memory for queue testing\n");
2971 fence_pkt
= hdev
->asic_funcs
->asic_dma_pool_zalloc(hdev
,
2972 sizeof(struct packet_msg_prot
),
2973 GFP_KERNEL
, &pkt_dma_addr
);
2976 "Failed to allocate packet for queue testing\n");
2978 goto free_fence_ptr
;
2981 tmp
= (PACKET_MSG_PROT
<< GOYA_PKT_CTL_OPCODE_SHIFT
) |
2982 (1 << GOYA_PKT_CTL_EB_SHIFT
) |
2983 (1 << GOYA_PKT_CTL_MB_SHIFT
);
2984 fence_pkt
->ctl
= cpu_to_le32(tmp
);
2985 fence_pkt
->value
= cpu_to_le32(fence_val
);
2986 fence_pkt
->addr
= cpu_to_le64(fence_dma_addr
);
2988 rc
= hl_hw_queue_send_cb_no_cmpl(hdev
, hw_queue_id
,
2989 sizeof(struct packet_msg_prot
),
2993 "Failed to send fence packet\n");
2997 rc
= hl_poll_timeout_memory(hdev
, fence_ptr
, tmp
, (tmp
== fence_val
),
2998 1000, GOYA_TEST_QUEUE_WAIT_USEC
, true);
3000 hl_hw_queue_inc_ci_kernel(hdev
, hw_queue_id
);
3002 if (rc
== -ETIMEDOUT
) {
3004 "H/W queue %d test failed (scratch(0x%08llX) == 0x%08X)\n",
3005 hw_queue_id
, (unsigned long long) fence_dma_addr
, tmp
);
3010 hdev
->asic_funcs
->asic_dma_pool_free(hdev
, (void *) fence_pkt
,
3013 hdev
->asic_funcs
->asic_dma_pool_free(hdev
, (void *) fence_ptr
,
3018 int goya_test_cpu_queue(struct hl_device
*hdev
)
3020 struct goya_device
*goya
= hdev
->asic_specific
;
3023 * check capability here as send_cpu_message() won't update the result
3024 * value if no capability
3026 if (!(goya
->hw_cap_initialized
& HW_CAP_CPU_Q
))
3029 return hl_fw_test_cpu_queue(hdev
);
3032 int goya_test_queues(struct hl_device
*hdev
)
3034 int i
, rc
, ret_val
= 0;
3036 for (i
= 0 ; i
< NUMBER_OF_EXT_HW_QUEUES
; i
++) {
3037 rc
= goya_test_queue(hdev
, i
);
3045 static void *goya_dma_pool_zalloc(struct hl_device
*hdev
, size_t size
,
3046 gfp_t mem_flags
, dma_addr_t
*dma_handle
)
3050 if (size
> GOYA_DMA_POOL_BLK_SIZE
)
3053 kernel_addr
= dma_pool_zalloc(hdev
->dma_pool
, mem_flags
, dma_handle
);
3055 /* Shift to the device's base physical address of host memory */
3057 *dma_handle
+= HOST_PHYS_BASE
;
3062 static void goya_dma_pool_free(struct hl_device
*hdev
, void *vaddr
,
3063 dma_addr_t dma_addr
)
3065 /* Cancel the device's base physical address of host memory */
3066 dma_addr_t fixed_dma_addr
= dma_addr
- HOST_PHYS_BASE
;
3068 dma_pool_free(hdev
->dma_pool
, vaddr
, fixed_dma_addr
);
3071 void *goya_cpu_accessible_dma_pool_alloc(struct hl_device
*hdev
, size_t size
,
3072 dma_addr_t
*dma_handle
)
3076 vaddr
= hl_fw_cpu_accessible_dma_pool_alloc(hdev
, size
, dma_handle
);
3077 *dma_handle
= (*dma_handle
) - hdev
->cpu_accessible_dma_address
+
3078 VA_CPU_ACCESSIBLE_MEM_ADDR
;
3083 void goya_cpu_accessible_dma_pool_free(struct hl_device
*hdev
, size_t size
,
3086 hl_fw_cpu_accessible_dma_pool_free(hdev
, size
, vaddr
);
3089 static int goya_dma_map_sg(struct hl_device
*hdev
, struct scatterlist
*sgl
,
3090 int nents
, enum dma_data_direction dir
)
3092 struct scatterlist
*sg
;
3095 if (!dma_map_sg(&hdev
->pdev
->dev
, sgl
, nents
, dir
))
3098 /* Shift to the device's base physical address of host memory */
3099 for_each_sg(sgl
, sg
, nents
, i
)
3100 sg
->dma_address
+= HOST_PHYS_BASE
;
3105 static void goya_dma_unmap_sg(struct hl_device
*hdev
, struct scatterlist
*sgl
,
3106 int nents
, enum dma_data_direction dir
)
3108 struct scatterlist
*sg
;
3111 /* Cancel the device's base physical address of host memory */
3112 for_each_sg(sgl
, sg
, nents
, i
)
3113 sg
->dma_address
-= HOST_PHYS_BASE
;
3115 dma_unmap_sg(&hdev
->pdev
->dev
, sgl
, nents
, dir
);
3118 u32
goya_get_dma_desc_list_size(struct hl_device
*hdev
, struct sg_table
*sgt
)
3120 struct scatterlist
*sg
, *sg_next_iter
;
3121 u32 count
, dma_desc_cnt
;
3123 dma_addr_t addr
, addr_next
;
3127 for_each_sg(sgt
->sgl
, sg
, sgt
->nents
, count
) {
3129 len
= sg_dma_len(sg
);
3130 addr
= sg_dma_address(sg
);
3135 while ((count
+ 1) < sgt
->nents
) {
3136 sg_next_iter
= sg_next(sg
);
3137 len_next
= sg_dma_len(sg_next_iter
);
3138 addr_next
= sg_dma_address(sg_next_iter
);
3143 if ((addr
+ len
== addr_next
) &&
3144 (len
+ len_next
<= DMA_MAX_TRANSFER_SIZE
)) {
3156 return dma_desc_cnt
* sizeof(struct packet_lin_dma
);
3159 static int goya_pin_memory_before_cs(struct hl_device
*hdev
,
3160 struct hl_cs_parser
*parser
,
3161 struct packet_lin_dma
*user_dma_pkt
,
3162 u64 addr
, enum dma_data_direction dir
)
3164 struct hl_userptr
*userptr
;
3167 if (hl_userptr_is_pinned(hdev
, addr
, le32_to_cpu(user_dma_pkt
->tsize
),
3168 parser
->job_userptr_list
, &userptr
))
3169 goto already_pinned
;
3171 userptr
= kzalloc(sizeof(*userptr
), GFP_ATOMIC
);
3175 rc
= hl_pin_host_memory(hdev
, addr
, le32_to_cpu(user_dma_pkt
->tsize
),
3180 list_add_tail(&userptr
->job_node
, parser
->job_userptr_list
);
3182 rc
= hdev
->asic_funcs
->asic_dma_map_sg(hdev
, userptr
->sgt
->sgl
,
3183 userptr
->sgt
->nents
, dir
);
3185 dev_err(hdev
->dev
, "failed to map sgt with DMA region\n");
3189 userptr
->dma_mapped
= true;
3193 parser
->patched_cb_size
+=
3194 goya_get_dma_desc_list_size(hdev
, userptr
->sgt
);
3199 hl_unpin_host_memory(hdev
, userptr
);
3205 static int goya_validate_dma_pkt_host(struct hl_device
*hdev
,
3206 struct hl_cs_parser
*parser
,
3207 struct packet_lin_dma
*user_dma_pkt
)
3209 u64 device_memory_addr
, addr
;
3210 enum dma_data_direction dir
;
3211 enum goya_dma_direction user_dir
;
3212 bool sram_addr
= true;
3213 bool skip_host_mem_pin
= false;
3218 ctl
= le32_to_cpu(user_dma_pkt
->ctl
);
3220 user_dir
= (ctl
& GOYA_PKT_LIN_DMA_CTL_DMA_DIR_MASK
) >>
3221 GOYA_PKT_LIN_DMA_CTL_DMA_DIR_SHIFT
;
3223 user_memset
= (ctl
& GOYA_PKT_LIN_DMA_CTL_MEMSET_MASK
) >>
3224 GOYA_PKT_LIN_DMA_CTL_MEMSET_SHIFT
;
3227 case DMA_HOST_TO_DRAM
:
3228 dev_dbg(hdev
->dev
, "DMA direction is HOST --> DRAM\n");
3229 dir
= DMA_TO_DEVICE
;
3231 addr
= le64_to_cpu(user_dma_pkt
->src_addr
);
3232 device_memory_addr
= le64_to_cpu(user_dma_pkt
->dst_addr
);
3234 skip_host_mem_pin
= true;
3237 case DMA_DRAM_TO_HOST
:
3238 dev_dbg(hdev
->dev
, "DMA direction is DRAM --> HOST\n");
3239 dir
= DMA_FROM_DEVICE
;
3241 addr
= le64_to_cpu(user_dma_pkt
->dst_addr
);
3242 device_memory_addr
= le64_to_cpu(user_dma_pkt
->src_addr
);
3245 case DMA_HOST_TO_SRAM
:
3246 dev_dbg(hdev
->dev
, "DMA direction is HOST --> SRAM\n");
3247 dir
= DMA_TO_DEVICE
;
3248 addr
= le64_to_cpu(user_dma_pkt
->src_addr
);
3249 device_memory_addr
= le64_to_cpu(user_dma_pkt
->dst_addr
);
3251 skip_host_mem_pin
= true;
3254 case DMA_SRAM_TO_HOST
:
3255 dev_dbg(hdev
->dev
, "DMA direction is SRAM --> HOST\n");
3256 dir
= DMA_FROM_DEVICE
;
3257 addr
= le64_to_cpu(user_dma_pkt
->dst_addr
);
3258 device_memory_addr
= le64_to_cpu(user_dma_pkt
->src_addr
);
3261 dev_err(hdev
->dev
, "DMA direction is undefined\n");
3266 if (!hl_mem_area_inside_range(device_memory_addr
,
3267 le32_to_cpu(user_dma_pkt
->tsize
),
3268 hdev
->asic_prop
.sram_user_base_address
,
3269 hdev
->asic_prop
.sram_end_address
)) {
3272 "SRAM address 0x%llx + 0x%x is invalid\n",
3274 user_dma_pkt
->tsize
);
3278 if (!hl_mem_area_inside_range(device_memory_addr
,
3279 le32_to_cpu(user_dma_pkt
->tsize
),
3280 hdev
->asic_prop
.dram_user_base_address
,
3281 hdev
->asic_prop
.dram_end_address
)) {
3284 "DRAM address 0x%llx + 0x%x is invalid\n",
3286 user_dma_pkt
->tsize
);
3291 if (skip_host_mem_pin
)
3292 parser
->patched_cb_size
+= sizeof(*user_dma_pkt
);
3294 if ((dir
== DMA_TO_DEVICE
) &&
3295 (parser
->hw_queue_id
> GOYA_QUEUE_ID_DMA_1
)) {
3297 "Can't DMA from host on queue other then 1\n");
3301 rc
= goya_pin_memory_before_cs(hdev
, parser
, user_dma_pkt
,
3308 static int goya_validate_dma_pkt_no_host(struct hl_device
*hdev
,
3309 struct hl_cs_parser
*parser
,
3310 struct packet_lin_dma
*user_dma_pkt
)
3312 u64 sram_memory_addr
, dram_memory_addr
;
3313 enum goya_dma_direction user_dir
;
3316 ctl
= le32_to_cpu(user_dma_pkt
->ctl
);
3317 user_dir
= (ctl
& GOYA_PKT_LIN_DMA_CTL_DMA_DIR_MASK
) >>
3318 GOYA_PKT_LIN_DMA_CTL_DMA_DIR_SHIFT
;
3320 if (user_dir
== DMA_DRAM_TO_SRAM
) {
3321 dev_dbg(hdev
->dev
, "DMA direction is DRAM --> SRAM\n");
3322 dram_memory_addr
= le64_to_cpu(user_dma_pkt
->src_addr
);
3323 sram_memory_addr
= le64_to_cpu(user_dma_pkt
->dst_addr
);
3325 dev_dbg(hdev
->dev
, "DMA direction is SRAM --> DRAM\n");
3326 sram_memory_addr
= le64_to_cpu(user_dma_pkt
->src_addr
);
3327 dram_memory_addr
= le64_to_cpu(user_dma_pkt
->dst_addr
);
3330 if (!hl_mem_area_inside_range(sram_memory_addr
,
3331 le32_to_cpu(user_dma_pkt
->tsize
),
3332 hdev
->asic_prop
.sram_user_base_address
,
3333 hdev
->asic_prop
.sram_end_address
)) {
3334 dev_err(hdev
->dev
, "SRAM address 0x%llx + 0x%x is invalid\n",
3335 sram_memory_addr
, user_dma_pkt
->tsize
);
3339 if (!hl_mem_area_inside_range(dram_memory_addr
,
3340 le32_to_cpu(user_dma_pkt
->tsize
),
3341 hdev
->asic_prop
.dram_user_base_address
,
3342 hdev
->asic_prop
.dram_end_address
)) {
3343 dev_err(hdev
->dev
, "DRAM address 0x%llx + 0x%x is invalid\n",
3344 dram_memory_addr
, user_dma_pkt
->tsize
);
3348 parser
->patched_cb_size
+= sizeof(*user_dma_pkt
);
3353 static int goya_validate_dma_pkt_no_mmu(struct hl_device
*hdev
,
3354 struct hl_cs_parser
*parser
,
3355 struct packet_lin_dma
*user_dma_pkt
)
3357 enum goya_dma_direction user_dir
;
3361 dev_dbg(hdev
->dev
, "DMA packet details:\n");
3362 dev_dbg(hdev
->dev
, "source == 0x%llx\n",
3363 le64_to_cpu(user_dma_pkt
->src_addr
));
3364 dev_dbg(hdev
->dev
, "destination == 0x%llx\n",
3365 le64_to_cpu(user_dma_pkt
->dst_addr
));
3366 dev_dbg(hdev
->dev
, "size == %u\n", le32_to_cpu(user_dma_pkt
->tsize
));
3368 ctl
= le32_to_cpu(user_dma_pkt
->ctl
);
3369 user_dir
= (ctl
& GOYA_PKT_LIN_DMA_CTL_DMA_DIR_MASK
) >>
3370 GOYA_PKT_LIN_DMA_CTL_DMA_DIR_SHIFT
;
3373 * Special handling for DMA with size 0. The H/W has a bug where
3374 * this can cause the QMAN DMA to get stuck, so block it here.
3376 if (user_dma_pkt
->tsize
== 0) {
3378 "Got DMA with size 0, might reset the device\n");
3382 if ((user_dir
== DMA_DRAM_TO_SRAM
) || (user_dir
== DMA_SRAM_TO_DRAM
))
3383 rc
= goya_validate_dma_pkt_no_host(hdev
, parser
, user_dma_pkt
);
3385 rc
= goya_validate_dma_pkt_host(hdev
, parser
, user_dma_pkt
);
3390 static int goya_validate_dma_pkt_mmu(struct hl_device
*hdev
,
3391 struct hl_cs_parser
*parser
,
3392 struct packet_lin_dma
*user_dma_pkt
)
3394 dev_dbg(hdev
->dev
, "DMA packet details:\n");
3395 dev_dbg(hdev
->dev
, "source == 0x%llx\n",
3396 le64_to_cpu(user_dma_pkt
->src_addr
));
3397 dev_dbg(hdev
->dev
, "destination == 0x%llx\n",
3398 le64_to_cpu(user_dma_pkt
->dst_addr
));
3399 dev_dbg(hdev
->dev
, "size == %u\n", le32_to_cpu(user_dma_pkt
->tsize
));
3403 * We can't allow user to read from Host using QMANs other than 1.
3405 if (parser
->hw_queue_id
!= GOYA_QUEUE_ID_DMA_1
&&
3406 hl_mem_area_inside_range(le64_to_cpu(user_dma_pkt
->src_addr
),
3407 le32_to_cpu(user_dma_pkt
->tsize
),
3408 hdev
->asic_prop
.va_space_host_start_address
,
3409 hdev
->asic_prop
.va_space_host_end_address
)) {
3411 "Can't DMA from host on queue other then 1\n");
3415 if (user_dma_pkt
->tsize
== 0) {
3417 "Got DMA with size 0, might reset the device\n");
3421 parser
->patched_cb_size
+= sizeof(*user_dma_pkt
);
3426 static int goya_validate_wreg32(struct hl_device
*hdev
,
3427 struct hl_cs_parser
*parser
,
3428 struct packet_wreg32
*wreg_pkt
)
3430 struct goya_device
*goya
= hdev
->asic_specific
;
3431 u32 sob_start_addr
, sob_end_addr
;
3434 reg_offset
= le32_to_cpu(wreg_pkt
->ctl
) &
3435 GOYA_PKT_WREG32_CTL_REG_OFFSET_MASK
;
3437 dev_dbg(hdev
->dev
, "WREG32 packet details:\n");
3438 dev_dbg(hdev
->dev
, "reg_offset == 0x%x\n", reg_offset
);
3439 dev_dbg(hdev
->dev
, "value == 0x%x\n",
3440 le32_to_cpu(wreg_pkt
->value
));
3442 if (reg_offset
!= (mmDMA_CH_0_WR_COMP_ADDR_LO
& 0x1FFF)) {
3443 dev_err(hdev
->dev
, "WREG32 packet with illegal address 0x%x\n",
3449 * With MMU, DMA channels are not secured, so it doesn't matter where
3450 * the WR COMP will be written to because it will go out with
3451 * non-secured property
3453 if (goya
->hw_cap_initialized
& HW_CAP_MMU
)
3456 sob_start_addr
= lower_32_bits(CFG_BASE
+ mmSYNC_MNGR_SOB_OBJ_0
);
3457 sob_end_addr
= lower_32_bits(CFG_BASE
+ mmSYNC_MNGR_SOB_OBJ_1023
);
3459 if ((le32_to_cpu(wreg_pkt
->value
) < sob_start_addr
) ||
3460 (le32_to_cpu(wreg_pkt
->value
) > sob_end_addr
)) {
3462 dev_err(hdev
->dev
, "WREG32 packet with illegal value 0x%x\n",
3470 static int goya_validate_cb(struct hl_device
*hdev
,
3471 struct hl_cs_parser
*parser
, bool is_mmu
)
3473 u32 cb_parsed_length
= 0;
3476 parser
->patched_cb_size
= 0;
3478 /* cb_user_size is more than 0 so loop will always be executed */
3479 while (cb_parsed_length
< parser
->user_cb_size
) {
3480 enum packet_id pkt_id
;
3482 struct goya_packet
*user_pkt
;
3484 user_pkt
= (struct goya_packet
*) (uintptr_t)
3485 (parser
->user_cb
->kernel_address
+ cb_parsed_length
);
3487 pkt_id
= (enum packet_id
) (
3488 (le64_to_cpu(user_pkt
->header
) &
3489 PACKET_HEADER_PACKET_ID_MASK
) >>
3490 PACKET_HEADER_PACKET_ID_SHIFT
);
3492 pkt_size
= goya_packet_sizes
[pkt_id
];
3493 cb_parsed_length
+= pkt_size
;
3494 if (cb_parsed_length
> parser
->user_cb_size
) {
3496 "packet 0x%x is out of CB boundary\n", pkt_id
);
3502 case PACKET_WREG_32
:
3504 * Although it is validated after copy in patch_cb(),
3505 * need to validate here as well because patch_cb() is
3506 * not called in MMU path while this function is called
3508 rc
= goya_validate_wreg32(hdev
,
3509 parser
, (struct packet_wreg32
*) user_pkt
);
3512 case PACKET_WREG_BULK
:
3514 "User not allowed to use WREG_BULK\n");
3518 case PACKET_MSG_PROT
:
3520 "User not allowed to use MSG_PROT\n");
3525 dev_err(hdev
->dev
, "User not allowed to use CP_DMA\n");
3530 dev_err(hdev
->dev
, "User not allowed to use STOP\n");
3534 case PACKET_LIN_DMA
:
3536 rc
= goya_validate_dma_pkt_mmu(hdev
, parser
,
3537 (struct packet_lin_dma
*) user_pkt
);
3539 rc
= goya_validate_dma_pkt_no_mmu(hdev
, parser
,
3540 (struct packet_lin_dma
*) user_pkt
);
3543 case PACKET_MSG_LONG
:
3544 case PACKET_MSG_SHORT
:
3547 parser
->patched_cb_size
+= pkt_size
;
3551 dev_err(hdev
->dev
, "Invalid packet header 0x%x\n",
3562 * The new CB should have space at the end for two MSG_PROT packets:
3563 * 1. A packet that will act as a completion packet
3564 * 2. A packet that will generate MSI-X interrupt
3566 parser
->patched_cb_size
+= sizeof(struct packet_msg_prot
) * 2;
3571 static int goya_patch_dma_packet(struct hl_device
*hdev
,
3572 struct hl_cs_parser
*parser
,
3573 struct packet_lin_dma
*user_dma_pkt
,
3574 struct packet_lin_dma
*new_dma_pkt
,
3575 u32
*new_dma_pkt_size
)
3577 struct hl_userptr
*userptr
;
3578 struct scatterlist
*sg
, *sg_next_iter
;
3579 u32 count
, dma_desc_cnt
;
3581 dma_addr_t dma_addr
, dma_addr_next
;
3582 enum goya_dma_direction user_dir
;
3583 u64 device_memory_addr
, addr
;
3584 enum dma_data_direction dir
;
3585 struct sg_table
*sgt
;
3586 bool skip_host_mem_pin
= false;
3588 u32 user_rdcomp_mask
, user_wrcomp_mask
, ctl
;
3590 ctl
= le32_to_cpu(user_dma_pkt
->ctl
);
3592 user_dir
= (ctl
& GOYA_PKT_LIN_DMA_CTL_DMA_DIR_MASK
) >>
3593 GOYA_PKT_LIN_DMA_CTL_DMA_DIR_SHIFT
;
3595 user_memset
= (ctl
& GOYA_PKT_LIN_DMA_CTL_MEMSET_MASK
) >>
3596 GOYA_PKT_LIN_DMA_CTL_MEMSET_SHIFT
;
3598 if ((user_dir
== DMA_DRAM_TO_SRAM
) || (user_dir
== DMA_SRAM_TO_DRAM
) ||
3599 (user_dma_pkt
->tsize
== 0)) {
3600 memcpy(new_dma_pkt
, user_dma_pkt
, sizeof(*new_dma_pkt
));
3601 *new_dma_pkt_size
= sizeof(*new_dma_pkt
);
3605 if ((user_dir
== DMA_HOST_TO_DRAM
) || (user_dir
== DMA_HOST_TO_SRAM
)) {
3606 addr
= le64_to_cpu(user_dma_pkt
->src_addr
);
3607 device_memory_addr
= le64_to_cpu(user_dma_pkt
->dst_addr
);
3608 dir
= DMA_TO_DEVICE
;
3610 skip_host_mem_pin
= true;
3612 addr
= le64_to_cpu(user_dma_pkt
->dst_addr
);
3613 device_memory_addr
= le64_to_cpu(user_dma_pkt
->src_addr
);
3614 dir
= DMA_FROM_DEVICE
;
3617 if ((!skip_host_mem_pin
) &&
3618 (hl_userptr_is_pinned(hdev
, addr
,
3619 le32_to_cpu(user_dma_pkt
->tsize
),
3620 parser
->job_userptr_list
, &userptr
) == false)) {
3621 dev_err(hdev
->dev
, "Userptr 0x%llx + 0x%x NOT mapped\n",
3622 addr
, user_dma_pkt
->tsize
);
3626 if ((user_memset
) && (dir
== DMA_TO_DEVICE
)) {
3627 memcpy(new_dma_pkt
, user_dma_pkt
, sizeof(*user_dma_pkt
));
3628 *new_dma_pkt_size
= sizeof(*user_dma_pkt
);
3632 user_rdcomp_mask
= ctl
& GOYA_PKT_LIN_DMA_CTL_RDCOMP_MASK
;
3634 user_wrcomp_mask
= ctl
& GOYA_PKT_LIN_DMA_CTL_WRCOMP_MASK
;
3639 for_each_sg(sgt
->sgl
, sg
, sgt
->nents
, count
) {
3640 len
= sg_dma_len(sg
);
3641 dma_addr
= sg_dma_address(sg
);
3646 while ((count
+ 1) < sgt
->nents
) {
3647 sg_next_iter
= sg_next(sg
);
3648 len_next
= sg_dma_len(sg_next_iter
);
3649 dma_addr_next
= sg_dma_address(sg_next_iter
);
3654 if ((dma_addr
+ len
== dma_addr_next
) &&
3655 (len
+ len_next
<= DMA_MAX_TRANSFER_SIZE
)) {
3664 ctl
= le32_to_cpu(user_dma_pkt
->ctl
);
3665 if (likely(dma_desc_cnt
))
3666 ctl
&= ~GOYA_PKT_CTL_EB_MASK
;
3667 ctl
&= ~(GOYA_PKT_LIN_DMA_CTL_RDCOMP_MASK
|
3668 GOYA_PKT_LIN_DMA_CTL_WRCOMP_MASK
);
3669 new_dma_pkt
->ctl
= cpu_to_le32(ctl
);
3670 new_dma_pkt
->tsize
= cpu_to_le32((u32
) len
);
3672 if (dir
== DMA_TO_DEVICE
) {
3673 new_dma_pkt
->src_addr
= cpu_to_le64(dma_addr
);
3674 new_dma_pkt
->dst_addr
= cpu_to_le64(device_memory_addr
);
3676 new_dma_pkt
->src_addr
= cpu_to_le64(device_memory_addr
);
3677 new_dma_pkt
->dst_addr
= cpu_to_le64(dma_addr
);
3681 device_memory_addr
+= len
;
3686 if (!dma_desc_cnt
) {
3688 "Error of 0 SG entries when patching DMA packet\n");
3692 /* Fix the last dma packet - rdcomp/wrcomp must be as user set them */
3694 new_dma_pkt
->ctl
|= cpu_to_le32(user_rdcomp_mask
| user_wrcomp_mask
);
3696 *new_dma_pkt_size
= dma_desc_cnt
* sizeof(struct packet_lin_dma
);
3701 static int goya_patch_cb(struct hl_device
*hdev
,
3702 struct hl_cs_parser
*parser
)
3704 u32 cb_parsed_length
= 0;
3705 u32 cb_patched_cur_length
= 0;
3708 /* cb_user_size is more than 0 so loop will always be executed */
3709 while (cb_parsed_length
< parser
->user_cb_size
) {
3710 enum packet_id pkt_id
;
3712 u32 new_pkt_size
= 0;
3713 struct goya_packet
*user_pkt
, *kernel_pkt
;
3715 user_pkt
= (struct goya_packet
*) (uintptr_t)
3716 (parser
->user_cb
->kernel_address
+ cb_parsed_length
);
3717 kernel_pkt
= (struct goya_packet
*) (uintptr_t)
3718 (parser
->patched_cb
->kernel_address
+
3719 cb_patched_cur_length
);
3721 pkt_id
= (enum packet_id
) (
3722 (le64_to_cpu(user_pkt
->header
) &
3723 PACKET_HEADER_PACKET_ID_MASK
) >>
3724 PACKET_HEADER_PACKET_ID_SHIFT
);
3726 pkt_size
= goya_packet_sizes
[pkt_id
];
3727 cb_parsed_length
+= pkt_size
;
3728 if (cb_parsed_length
> parser
->user_cb_size
) {
3730 "packet 0x%x is out of CB boundary\n", pkt_id
);
3736 case PACKET_LIN_DMA
:
3737 rc
= goya_patch_dma_packet(hdev
, parser
,
3738 (struct packet_lin_dma
*) user_pkt
,
3739 (struct packet_lin_dma
*) kernel_pkt
,
3741 cb_patched_cur_length
+= new_pkt_size
;
3744 case PACKET_WREG_32
:
3745 memcpy(kernel_pkt
, user_pkt
, pkt_size
);
3746 cb_patched_cur_length
+= pkt_size
;
3747 rc
= goya_validate_wreg32(hdev
, parser
,
3748 (struct packet_wreg32
*) kernel_pkt
);
3751 case PACKET_WREG_BULK
:
3753 "User not allowed to use WREG_BULK\n");
3757 case PACKET_MSG_PROT
:
3759 "User not allowed to use MSG_PROT\n");
3764 dev_err(hdev
->dev
, "User not allowed to use CP_DMA\n");
3769 dev_err(hdev
->dev
, "User not allowed to use STOP\n");
3773 case PACKET_MSG_LONG
:
3774 case PACKET_MSG_SHORT
:
3777 memcpy(kernel_pkt
, user_pkt
, pkt_size
);
3778 cb_patched_cur_length
+= pkt_size
;
3782 dev_err(hdev
->dev
, "Invalid packet header 0x%x\n",
3795 static int goya_parse_cb_mmu(struct hl_device
*hdev
,
3796 struct hl_cs_parser
*parser
)
3798 u64 patched_cb_handle
;
3799 u32 patched_cb_size
;
3800 struct hl_cb
*user_cb
;
3804 * The new CB should have space at the end for two MSG_PROT pkt:
3805 * 1. A packet that will act as a completion packet
3806 * 2. A packet that will generate MSI-X interrupt
3808 parser
->patched_cb_size
= parser
->user_cb_size
+
3809 sizeof(struct packet_msg_prot
) * 2;
3811 rc
= hl_cb_create(hdev
, &hdev
->kernel_cb_mgr
,
3812 parser
->patched_cb_size
,
3813 &patched_cb_handle
, HL_KERNEL_ASID_ID
);
3817 "Failed to allocate patched CB for DMA CS %d\n",
3822 patched_cb_handle
>>= PAGE_SHIFT
;
3823 parser
->patched_cb
= hl_cb_get(hdev
, &hdev
->kernel_cb_mgr
,
3824 (u32
) patched_cb_handle
);
3825 /* hl_cb_get should never fail here so use kernel WARN */
3826 WARN(!parser
->patched_cb
, "DMA CB handle invalid 0x%x\n",
3827 (u32
) patched_cb_handle
);
3828 if (!parser
->patched_cb
) {
3834 * The check that parser->user_cb_size <= parser->user_cb->size was done
3835 * in validate_queue_index().
3837 memcpy((void *) (uintptr_t) parser
->patched_cb
->kernel_address
,
3838 (void *) (uintptr_t) parser
->user_cb
->kernel_address
,
3839 parser
->user_cb_size
);
3841 patched_cb_size
= parser
->patched_cb_size
;
3843 /* validate patched CB instead of user CB */
3844 user_cb
= parser
->user_cb
;
3845 parser
->user_cb
= parser
->patched_cb
;
3846 rc
= goya_validate_cb(hdev
, parser
, true);
3847 parser
->user_cb
= user_cb
;
3850 hl_cb_put(parser
->patched_cb
);
3854 if (patched_cb_size
!= parser
->patched_cb_size
) {
3855 dev_err(hdev
->dev
, "user CB size mismatch\n");
3856 hl_cb_put(parser
->patched_cb
);
3863 * Always call cb destroy here because we still have 1 reference
3864 * to it by calling cb_get earlier. After the job will be completed,
3865 * cb_put will release it, but here we want to remove it from the
3868 hl_cb_destroy(hdev
, &hdev
->kernel_cb_mgr
,
3869 patched_cb_handle
<< PAGE_SHIFT
);
3874 static int goya_parse_cb_no_mmu(struct hl_device
*hdev
,
3875 struct hl_cs_parser
*parser
)
3877 u64 patched_cb_handle
;
3880 rc
= goya_validate_cb(hdev
, parser
, false);
3885 rc
= hl_cb_create(hdev
, &hdev
->kernel_cb_mgr
,
3886 parser
->patched_cb_size
,
3887 &patched_cb_handle
, HL_KERNEL_ASID_ID
);
3890 "Failed to allocate patched CB for DMA CS %d\n", rc
);
3894 patched_cb_handle
>>= PAGE_SHIFT
;
3895 parser
->patched_cb
= hl_cb_get(hdev
, &hdev
->kernel_cb_mgr
,
3896 (u32
) patched_cb_handle
);
3897 /* hl_cb_get should never fail here so use kernel WARN */
3898 WARN(!parser
->patched_cb
, "DMA CB handle invalid 0x%x\n",
3899 (u32
) patched_cb_handle
);
3900 if (!parser
->patched_cb
) {
3905 rc
= goya_patch_cb(hdev
, parser
);
3908 hl_cb_put(parser
->patched_cb
);
3912 * Always call cb destroy here because we still have 1 reference
3913 * to it by calling cb_get earlier. After the job will be completed,
3914 * cb_put will release it, but here we want to remove it from the
3917 hl_cb_destroy(hdev
, &hdev
->kernel_cb_mgr
,
3918 patched_cb_handle
<< PAGE_SHIFT
);
3922 hl_userptr_delete_list(hdev
, parser
->job_userptr_list
);
3926 static int goya_parse_cb_no_ext_queue(struct hl_device
*hdev
,
3927 struct hl_cs_parser
*parser
)
3929 struct asic_fixed_properties
*asic_prop
= &hdev
->asic_prop
;
3930 struct goya_device
*goya
= hdev
->asic_specific
;
3932 if (goya
->hw_cap_initialized
& HW_CAP_MMU
)
3935 /* For internal queue jobs, just check if CB address is valid */
3936 if (hl_mem_area_inside_range(
3937 (u64
) (uintptr_t) parser
->user_cb
,
3938 parser
->user_cb_size
,
3939 asic_prop
->sram_user_base_address
,
3940 asic_prop
->sram_end_address
))
3943 if (hl_mem_area_inside_range(
3944 (u64
) (uintptr_t) parser
->user_cb
,
3945 parser
->user_cb_size
,
3946 asic_prop
->dram_user_base_address
,
3947 asic_prop
->dram_end_address
))
3951 "Internal CB address 0x%px + 0x%x is not in SRAM nor in DRAM\n",
3952 parser
->user_cb
, parser
->user_cb_size
);
3957 int goya_cs_parser(struct hl_device
*hdev
, struct hl_cs_parser
*parser
)
3959 struct goya_device
*goya
= hdev
->asic_specific
;
3961 if (parser
->queue_type
== QUEUE_TYPE_INT
)
3962 return goya_parse_cb_no_ext_queue(hdev
, parser
);
3964 if (goya
->hw_cap_initialized
& HW_CAP_MMU
)
3965 return goya_parse_cb_mmu(hdev
, parser
);
3967 return goya_parse_cb_no_mmu(hdev
, parser
);
3970 void goya_add_end_of_cb_packets(struct hl_device
*hdev
, u64 kernel_address
,
3971 u32 len
, u64 cq_addr
, u32 cq_val
, u32 msix_vec
)
3973 struct packet_msg_prot
*cq_pkt
;
3976 cq_pkt
= (struct packet_msg_prot
*) (uintptr_t)
3977 (kernel_address
+ len
- (sizeof(struct packet_msg_prot
) * 2));
3979 tmp
= (PACKET_MSG_PROT
<< GOYA_PKT_CTL_OPCODE_SHIFT
) |
3980 (1 << GOYA_PKT_CTL_EB_SHIFT
) |
3981 (1 << GOYA_PKT_CTL_MB_SHIFT
);
3982 cq_pkt
->ctl
= cpu_to_le32(tmp
);
3983 cq_pkt
->value
= cpu_to_le32(cq_val
);
3984 cq_pkt
->addr
= cpu_to_le64(cq_addr
);
3988 tmp
= (PACKET_MSG_PROT
<< GOYA_PKT_CTL_OPCODE_SHIFT
) |
3989 (1 << GOYA_PKT_CTL_MB_SHIFT
);
3990 cq_pkt
->ctl
= cpu_to_le32(tmp
);
3991 cq_pkt
->value
= cpu_to_le32(msix_vec
& 0x7FF);
3992 cq_pkt
->addr
= cpu_to_le64(CFG_BASE
+ mmPCIE_DBI_MSIX_DOORBELL_OFF
);
3995 void goya_update_eq_ci(struct hl_device
*hdev
, u32 val
)
3997 WREG32(mmCPU_EQ_CI
, val
);
4000 void goya_restore_phase_topology(struct hl_device
*hdev
)
4005 static void goya_clear_sm_regs(struct hl_device
*hdev
)
4007 int i
, num_of_sob_in_longs
, num_of_mon_in_longs
;
4009 num_of_sob_in_longs
=
4010 ((mmSYNC_MNGR_SOB_OBJ_1023
- mmSYNC_MNGR_SOB_OBJ_0
) + 4);
4012 num_of_mon_in_longs
=
4013 ((mmSYNC_MNGR_MON_STATUS_255
- mmSYNC_MNGR_MON_STATUS_0
) + 4);
4015 for (i
= 0 ; i
< num_of_sob_in_longs
; i
+= 4)
4016 WREG32(mmSYNC_MNGR_SOB_OBJ_0
+ i
, 0);
4018 for (i
= 0 ; i
< num_of_mon_in_longs
; i
+= 4)
4019 WREG32(mmSYNC_MNGR_MON_STATUS_0
+ i
, 0);
4021 /* Flush all WREG to prevent race */
4022 i
= RREG32(mmSYNC_MNGR_SOB_OBJ_0
);
4026 * goya_debugfs_read32 - read a 32bit value from a given device or a host mapped
4029 * @hdev: pointer to hl_device structure
4030 * @addr: device or host mapped address
4031 * @val: returned value
4033 * In case of DDR address that is not mapped into the default aperture that
4034 * the DDR bar exposes, the function will configure the iATU so that the DDR
4035 * bar will be positioned at a base address that allows reading from the
4036 * required address. Configuring the iATU during normal operation can
4037 * lead to undefined behavior and therefore, should be done with extreme care
4040 static int goya_debugfs_read32(struct hl_device
*hdev
, u64 addr
, u32
*val
)
4042 struct asic_fixed_properties
*prop
= &hdev
->asic_prop
;
4046 if ((addr
>= CFG_BASE
) && (addr
< CFG_BASE
+ CFG_SIZE
)) {
4047 *val
= RREG32(addr
- CFG_BASE
);
4049 } else if ((addr
>= SRAM_BASE_ADDR
) &&
4050 (addr
< SRAM_BASE_ADDR
+ SRAM_SIZE
)) {
4052 *val
= readl(hdev
->pcie_bar
[SRAM_CFG_BAR_ID
] +
4053 (addr
- SRAM_BASE_ADDR
));
4055 } else if ((addr
>= DRAM_PHYS_BASE
) &&
4056 (addr
< DRAM_PHYS_BASE
+ hdev
->asic_prop
.dram_size
)) {
4058 u64 bar_base_addr
= DRAM_PHYS_BASE
+
4059 (addr
& ~(prop
->dram_pci_bar_size
- 0x1ull
));
4061 ddr_bar_addr
= goya_set_ddr_bar_base(hdev
, bar_base_addr
);
4062 if (ddr_bar_addr
!= U64_MAX
) {
4063 *val
= readl(hdev
->pcie_bar
[DDR_BAR_ID
] +
4064 (addr
- bar_base_addr
));
4066 ddr_bar_addr
= goya_set_ddr_bar_base(hdev
,
4069 if (ddr_bar_addr
== U64_MAX
)
4072 } else if (addr
>= HOST_PHYS_BASE
&& !iommu_present(&pci_bus_type
)) {
4073 *val
= *(u32
*) phys_to_virt(addr
- HOST_PHYS_BASE
);
4083 * goya_debugfs_write32 - write a 32bit value to a given device or a host mapped
4086 * @hdev: pointer to hl_device structure
4087 * @addr: device or host mapped address
4088 * @val: returned value
4090 * In case of DDR address that is not mapped into the default aperture that
4091 * the DDR bar exposes, the function will configure the iATU so that the DDR
4092 * bar will be positioned at a base address that allows writing to the
4093 * required address. Configuring the iATU during normal operation can
4094 * lead to undefined behavior and therefore, should be done with extreme care
4097 static int goya_debugfs_write32(struct hl_device
*hdev
, u64 addr
, u32 val
)
4099 struct asic_fixed_properties
*prop
= &hdev
->asic_prop
;
4103 if ((addr
>= CFG_BASE
) && (addr
< CFG_BASE
+ CFG_SIZE
)) {
4104 WREG32(addr
- CFG_BASE
, val
);
4106 } else if ((addr
>= SRAM_BASE_ADDR
) &&
4107 (addr
< SRAM_BASE_ADDR
+ SRAM_SIZE
)) {
4109 writel(val
, hdev
->pcie_bar
[SRAM_CFG_BAR_ID
] +
4110 (addr
- SRAM_BASE_ADDR
));
4112 } else if ((addr
>= DRAM_PHYS_BASE
) &&
4113 (addr
< DRAM_PHYS_BASE
+ hdev
->asic_prop
.dram_size
)) {
4115 u64 bar_base_addr
= DRAM_PHYS_BASE
+
4116 (addr
& ~(prop
->dram_pci_bar_size
- 0x1ull
));
4118 ddr_bar_addr
= goya_set_ddr_bar_base(hdev
, bar_base_addr
);
4119 if (ddr_bar_addr
!= U64_MAX
) {
4120 writel(val
, hdev
->pcie_bar
[DDR_BAR_ID
] +
4121 (addr
- bar_base_addr
));
4123 ddr_bar_addr
= goya_set_ddr_bar_base(hdev
,
4126 if (ddr_bar_addr
== U64_MAX
)
4129 } else if (addr
>= HOST_PHYS_BASE
&& !iommu_present(&pci_bus_type
)) {
4130 *(u32
*) phys_to_virt(addr
- HOST_PHYS_BASE
) = val
;
4139 static u64
goya_read_pte(struct hl_device
*hdev
, u64 addr
)
4141 struct goya_device
*goya
= hdev
->asic_specific
;
4143 if (hdev
->hard_reset_pending
)
4146 return readq(hdev
->pcie_bar
[DDR_BAR_ID
] +
4147 (addr
- goya
->ddr_bar_cur_addr
));
4150 static void goya_write_pte(struct hl_device
*hdev
, u64 addr
, u64 val
)
4152 struct goya_device
*goya
= hdev
->asic_specific
;
4154 if (hdev
->hard_reset_pending
)
4157 writeq(val
, hdev
->pcie_bar
[DDR_BAR_ID
] +
4158 (addr
- goya
->ddr_bar_cur_addr
));
4161 static const char *_goya_get_event_desc(u16 event_type
)
4163 switch (event_type
) {
4164 case GOYA_ASYNC_EVENT_ID_PCIE_IF
:
4166 case GOYA_ASYNC_EVENT_ID_TPC0_ECC
:
4167 case GOYA_ASYNC_EVENT_ID_TPC1_ECC
:
4168 case GOYA_ASYNC_EVENT_ID_TPC2_ECC
:
4169 case GOYA_ASYNC_EVENT_ID_TPC3_ECC
:
4170 case GOYA_ASYNC_EVENT_ID_TPC4_ECC
:
4171 case GOYA_ASYNC_EVENT_ID_TPC5_ECC
:
4172 case GOYA_ASYNC_EVENT_ID_TPC6_ECC
:
4173 case GOYA_ASYNC_EVENT_ID_TPC7_ECC
:
4175 case GOYA_ASYNC_EVENT_ID_MME_ECC
:
4177 case GOYA_ASYNC_EVENT_ID_MME_ECC_EXT
:
4178 return "MME_ecc_ext";
4179 case GOYA_ASYNC_EVENT_ID_MMU_ECC
:
4181 case GOYA_ASYNC_EVENT_ID_DMA_MACRO
:
4183 case GOYA_ASYNC_EVENT_ID_DMA_ECC
:
4185 case GOYA_ASYNC_EVENT_ID_CPU_IF_ECC
:
4186 return "CPU_if_ecc";
4187 case GOYA_ASYNC_EVENT_ID_PSOC_MEM
:
4189 case GOYA_ASYNC_EVENT_ID_PSOC_CORESIGHT
:
4190 return "PSOC_coresight";
4191 case GOYA_ASYNC_EVENT_ID_SRAM0
... GOYA_ASYNC_EVENT_ID_SRAM29
:
4193 case GOYA_ASYNC_EVENT_ID_GIC500
:
4195 case GOYA_ASYNC_EVENT_ID_PLL0
... GOYA_ASYNC_EVENT_ID_PLL6
:
4197 case GOYA_ASYNC_EVENT_ID_AXI_ECC
:
4199 case GOYA_ASYNC_EVENT_ID_L2_RAM_ECC
:
4200 return "L2_ram_ecc";
4201 case GOYA_ASYNC_EVENT_ID_PSOC_GPIO_05_SW_RESET
:
4202 return "PSOC_gpio_05_sw_reset";
4203 case GOYA_ASYNC_EVENT_ID_PSOC_GPIO_10_VRHOT_ICRIT
:
4204 return "PSOC_gpio_10_vrhot_icrit";
4205 case GOYA_ASYNC_EVENT_ID_PCIE_DEC
:
4207 case GOYA_ASYNC_EVENT_ID_TPC0_DEC
:
4208 case GOYA_ASYNC_EVENT_ID_TPC1_DEC
:
4209 case GOYA_ASYNC_EVENT_ID_TPC2_DEC
:
4210 case GOYA_ASYNC_EVENT_ID_TPC3_DEC
:
4211 case GOYA_ASYNC_EVENT_ID_TPC4_DEC
:
4212 case GOYA_ASYNC_EVENT_ID_TPC5_DEC
:
4213 case GOYA_ASYNC_EVENT_ID_TPC6_DEC
:
4214 case GOYA_ASYNC_EVENT_ID_TPC7_DEC
:
4216 case GOYA_ASYNC_EVENT_ID_MME_WACS
:
4218 case GOYA_ASYNC_EVENT_ID_MME_WACSD
:
4220 case GOYA_ASYNC_EVENT_ID_CPU_AXI_SPLITTER
:
4221 return "CPU_axi_splitter";
4222 case GOYA_ASYNC_EVENT_ID_PSOC_AXI_DEC
:
4223 return "PSOC_axi_dec";
4224 case GOYA_ASYNC_EVENT_ID_PSOC
:
4226 case GOYA_ASYNC_EVENT_ID_TPC0_KRN_ERR
:
4227 case GOYA_ASYNC_EVENT_ID_TPC1_KRN_ERR
:
4228 case GOYA_ASYNC_EVENT_ID_TPC2_KRN_ERR
:
4229 case GOYA_ASYNC_EVENT_ID_TPC3_KRN_ERR
:
4230 case GOYA_ASYNC_EVENT_ID_TPC4_KRN_ERR
:
4231 case GOYA_ASYNC_EVENT_ID_TPC5_KRN_ERR
:
4232 case GOYA_ASYNC_EVENT_ID_TPC6_KRN_ERR
:
4233 case GOYA_ASYNC_EVENT_ID_TPC7_KRN_ERR
:
4234 return "TPC%d_krn_err";
4235 case GOYA_ASYNC_EVENT_ID_TPC0_CMDQ
... GOYA_ASYNC_EVENT_ID_TPC7_CMDQ
:
4237 case GOYA_ASYNC_EVENT_ID_TPC0_QM
... GOYA_ASYNC_EVENT_ID_TPC7_QM
:
4239 case GOYA_ASYNC_EVENT_ID_MME_QM
:
4241 case GOYA_ASYNC_EVENT_ID_MME_CMDQ
:
4243 case GOYA_ASYNC_EVENT_ID_DMA0_QM
... GOYA_ASYNC_EVENT_ID_DMA4_QM
:
4245 case GOYA_ASYNC_EVENT_ID_DMA0_CH
... GOYA_ASYNC_EVENT_ID_DMA4_CH
:
4247 case GOYA_ASYNC_EVENT_ID_TPC0_BMON_SPMU
:
4248 case GOYA_ASYNC_EVENT_ID_TPC1_BMON_SPMU
:
4249 case GOYA_ASYNC_EVENT_ID_TPC2_BMON_SPMU
:
4250 case GOYA_ASYNC_EVENT_ID_TPC3_BMON_SPMU
:
4251 case GOYA_ASYNC_EVENT_ID_TPC4_BMON_SPMU
:
4252 case GOYA_ASYNC_EVENT_ID_TPC5_BMON_SPMU
:
4253 case GOYA_ASYNC_EVENT_ID_TPC6_BMON_SPMU
:
4254 case GOYA_ASYNC_EVENT_ID_TPC7_BMON_SPMU
:
4255 return "TPC%d_bmon_spmu";
4256 case GOYA_ASYNC_EVENT_ID_DMA_BM_CH0
... GOYA_ASYNC_EVENT_ID_DMA_BM_CH4
:
4257 return "DMA_bm_ch%d";
4263 static void goya_get_event_desc(u16 event_type
, char *desc
, size_t size
)
4267 switch (event_type
) {
4268 case GOYA_ASYNC_EVENT_ID_TPC0_ECC
:
4269 case GOYA_ASYNC_EVENT_ID_TPC1_ECC
:
4270 case GOYA_ASYNC_EVENT_ID_TPC2_ECC
:
4271 case GOYA_ASYNC_EVENT_ID_TPC3_ECC
:
4272 case GOYA_ASYNC_EVENT_ID_TPC4_ECC
:
4273 case GOYA_ASYNC_EVENT_ID_TPC5_ECC
:
4274 case GOYA_ASYNC_EVENT_ID_TPC6_ECC
:
4275 case GOYA_ASYNC_EVENT_ID_TPC7_ECC
:
4276 index
= (event_type
- GOYA_ASYNC_EVENT_ID_TPC0_ECC
) / 3;
4277 snprintf(desc
, size
, _goya_get_event_desc(event_type
), index
);
4279 case GOYA_ASYNC_EVENT_ID_SRAM0
... GOYA_ASYNC_EVENT_ID_SRAM29
:
4280 index
= event_type
- GOYA_ASYNC_EVENT_ID_SRAM0
;
4281 snprintf(desc
, size
, _goya_get_event_desc(event_type
), index
);
4283 case GOYA_ASYNC_EVENT_ID_PLL0
... GOYA_ASYNC_EVENT_ID_PLL6
:
4284 index
= event_type
- GOYA_ASYNC_EVENT_ID_PLL0
;
4285 snprintf(desc
, size
, _goya_get_event_desc(event_type
), index
);
4287 case GOYA_ASYNC_EVENT_ID_TPC0_DEC
:
4288 case GOYA_ASYNC_EVENT_ID_TPC1_DEC
:
4289 case GOYA_ASYNC_EVENT_ID_TPC2_DEC
:
4290 case GOYA_ASYNC_EVENT_ID_TPC3_DEC
:
4291 case GOYA_ASYNC_EVENT_ID_TPC4_DEC
:
4292 case GOYA_ASYNC_EVENT_ID_TPC5_DEC
:
4293 case GOYA_ASYNC_EVENT_ID_TPC6_DEC
:
4294 case GOYA_ASYNC_EVENT_ID_TPC7_DEC
:
4295 index
= (event_type
- GOYA_ASYNC_EVENT_ID_TPC0_DEC
) / 3;
4296 snprintf(desc
, size
, _goya_get_event_desc(event_type
), index
);
4298 case GOYA_ASYNC_EVENT_ID_TPC0_KRN_ERR
:
4299 case GOYA_ASYNC_EVENT_ID_TPC1_KRN_ERR
:
4300 case GOYA_ASYNC_EVENT_ID_TPC2_KRN_ERR
:
4301 case GOYA_ASYNC_EVENT_ID_TPC3_KRN_ERR
:
4302 case GOYA_ASYNC_EVENT_ID_TPC4_KRN_ERR
:
4303 case GOYA_ASYNC_EVENT_ID_TPC5_KRN_ERR
:
4304 case GOYA_ASYNC_EVENT_ID_TPC6_KRN_ERR
:
4305 case GOYA_ASYNC_EVENT_ID_TPC7_KRN_ERR
:
4306 index
= (event_type
- GOYA_ASYNC_EVENT_ID_TPC0_KRN_ERR
) / 10;
4307 snprintf(desc
, size
, _goya_get_event_desc(event_type
), index
);
4309 case GOYA_ASYNC_EVENT_ID_TPC0_CMDQ
... GOYA_ASYNC_EVENT_ID_TPC7_CMDQ
:
4310 index
= event_type
- GOYA_ASYNC_EVENT_ID_TPC0_CMDQ
;
4311 snprintf(desc
, size
, _goya_get_event_desc(event_type
), index
);
4313 case GOYA_ASYNC_EVENT_ID_TPC0_QM
... GOYA_ASYNC_EVENT_ID_TPC7_QM
:
4314 index
= event_type
- GOYA_ASYNC_EVENT_ID_TPC0_QM
;
4315 snprintf(desc
, size
, _goya_get_event_desc(event_type
), index
);
4317 case GOYA_ASYNC_EVENT_ID_DMA0_QM
... GOYA_ASYNC_EVENT_ID_DMA4_QM
:
4318 index
= event_type
- GOYA_ASYNC_EVENT_ID_DMA0_QM
;
4319 snprintf(desc
, size
, _goya_get_event_desc(event_type
), index
);
4321 case GOYA_ASYNC_EVENT_ID_DMA0_CH
... GOYA_ASYNC_EVENT_ID_DMA4_CH
:
4322 index
= event_type
- GOYA_ASYNC_EVENT_ID_DMA0_CH
;
4323 snprintf(desc
, size
, _goya_get_event_desc(event_type
), index
);
4325 case GOYA_ASYNC_EVENT_ID_TPC0_BMON_SPMU
:
4326 case GOYA_ASYNC_EVENT_ID_TPC1_BMON_SPMU
:
4327 case GOYA_ASYNC_EVENT_ID_TPC2_BMON_SPMU
:
4328 case GOYA_ASYNC_EVENT_ID_TPC3_BMON_SPMU
:
4329 case GOYA_ASYNC_EVENT_ID_TPC4_BMON_SPMU
:
4330 case GOYA_ASYNC_EVENT_ID_TPC5_BMON_SPMU
:
4331 case GOYA_ASYNC_EVENT_ID_TPC6_BMON_SPMU
:
4332 case GOYA_ASYNC_EVENT_ID_TPC7_BMON_SPMU
:
4333 index
= (event_type
- GOYA_ASYNC_EVENT_ID_TPC0_BMON_SPMU
) / 10;
4334 snprintf(desc
, size
, _goya_get_event_desc(event_type
), index
);
4336 case GOYA_ASYNC_EVENT_ID_DMA_BM_CH0
... GOYA_ASYNC_EVENT_ID_DMA_BM_CH4
:
4337 index
= event_type
- GOYA_ASYNC_EVENT_ID_DMA_BM_CH0
;
4338 snprintf(desc
, size
, _goya_get_event_desc(event_type
), index
);
4341 snprintf(desc
, size
, _goya_get_event_desc(event_type
));
4346 static void goya_print_razwi_info(struct hl_device
*hdev
)
4348 if (RREG32(mmDMA_MACRO_RAZWI_LBW_WT_VLD
)) {
4349 dev_err(hdev
->dev
, "Illegal write to LBW\n");
4350 WREG32(mmDMA_MACRO_RAZWI_LBW_WT_VLD
, 0);
4353 if (RREG32(mmDMA_MACRO_RAZWI_LBW_RD_VLD
)) {
4354 dev_err(hdev
->dev
, "Illegal read from LBW\n");
4355 WREG32(mmDMA_MACRO_RAZWI_LBW_RD_VLD
, 0);
4358 if (RREG32(mmDMA_MACRO_RAZWI_HBW_WT_VLD
)) {
4359 dev_err(hdev
->dev
, "Illegal write to HBW\n");
4360 WREG32(mmDMA_MACRO_RAZWI_HBW_WT_VLD
, 0);
4363 if (RREG32(mmDMA_MACRO_RAZWI_HBW_RD_VLD
)) {
4364 dev_err(hdev
->dev
, "Illegal read from HBW\n");
4365 WREG32(mmDMA_MACRO_RAZWI_HBW_RD_VLD
, 0);
4369 static void goya_print_mmu_error_info(struct hl_device
*hdev
)
4371 struct goya_device
*goya
= hdev
->asic_specific
;
4375 if (!(goya
->hw_cap_initialized
& HW_CAP_MMU
))
4378 val
= RREG32(mmMMU_PAGE_ERROR_CAPTURE
);
4379 if (val
& MMU_PAGE_ERROR_CAPTURE_ENTRY_VALID_MASK
) {
4380 addr
= val
& MMU_PAGE_ERROR_CAPTURE_VA_49_32_MASK
;
4382 addr
|= RREG32(mmMMU_PAGE_ERROR_CAPTURE_VA
);
4384 dev_err(hdev
->dev
, "MMU page fault on va 0x%llx\n", addr
);
4386 WREG32(mmMMU_PAGE_ERROR_CAPTURE
, 0);
4390 static void goya_print_irq_info(struct hl_device
*hdev
, u16 event_type
,
4395 goya_get_event_desc(event_type
, desc
, sizeof(desc
));
4396 dev_err(hdev
->dev
, "Received H/W interrupt %d [\"%s\"]\n",
4400 goya_print_razwi_info(hdev
);
4401 goya_print_mmu_error_info(hdev
);
4405 static int goya_unmask_irq_arr(struct hl_device
*hdev
, u32
*irq_arr
,
4406 size_t irq_arr_size
)
4408 struct armcp_unmask_irq_arr_packet
*pkt
;
4409 size_t total_pkt_size
;
4412 int irq_num_entries
, irq_arr_index
;
4413 __le32
*goya_irq_arr
;
4415 total_pkt_size
= sizeof(struct armcp_unmask_irq_arr_packet
) +
4418 /* data should be aligned to 8 bytes in order to ArmCP to copy it */
4419 total_pkt_size
= (total_pkt_size
+ 0x7) & ~0x7;
4421 /* total_pkt_size is casted to u16 later on */
4422 if (total_pkt_size
> USHRT_MAX
) {
4423 dev_err(hdev
->dev
, "too many elements in IRQ array\n");
4427 pkt
= kzalloc(total_pkt_size
, GFP_KERNEL
);
4431 irq_num_entries
= irq_arr_size
/ sizeof(irq_arr
[0]);
4432 pkt
->length
= cpu_to_le32(irq_num_entries
);
4434 /* We must perform any necessary endianness conversation on the irq
4435 * array being passed to the goya hardware
4437 for (irq_arr_index
= 0, goya_irq_arr
= (__le32
*) &pkt
->irqs
;
4438 irq_arr_index
< irq_num_entries
; irq_arr_index
++)
4439 goya_irq_arr
[irq_arr_index
] =
4440 cpu_to_le32(irq_arr
[irq_arr_index
]);
4442 pkt
->armcp_pkt
.ctl
= cpu_to_le32(ARMCP_PACKET_UNMASK_RAZWI_IRQ_ARRAY
<<
4443 ARMCP_PKT_CTL_OPCODE_SHIFT
);
4445 rc
= goya_send_cpu_message(hdev
, (u32
*) pkt
, total_pkt_size
,
4446 HL_DEVICE_TIMEOUT_USEC
, &result
);
4449 dev_err(hdev
->dev
, "failed to unmask IRQ array\n");
4456 static int goya_soft_reset_late_init(struct hl_device
*hdev
)
4459 * Unmask all IRQs since some could have been received
4460 * during the soft reset
4462 return goya_unmask_irq_arr(hdev
, goya_all_events
,
4463 sizeof(goya_all_events
));
4466 static int goya_unmask_irq(struct hl_device
*hdev
, u16 event_type
)
4468 struct armcp_packet pkt
;
4472 memset(&pkt
, 0, sizeof(pkt
));
4474 pkt
.ctl
= cpu_to_le32(ARMCP_PACKET_UNMASK_RAZWI_IRQ
<<
4475 ARMCP_PKT_CTL_OPCODE_SHIFT
);
4476 pkt
.value
= cpu_to_le64(event_type
);
4478 rc
= goya_send_cpu_message(hdev
, (u32
*) &pkt
, sizeof(pkt
),
4479 HL_DEVICE_TIMEOUT_USEC
, &result
);
4482 dev_err(hdev
->dev
, "failed to unmask RAZWI IRQ %d", event_type
);
4487 void goya_handle_eqe(struct hl_device
*hdev
, struct hl_eq_entry
*eq_entry
)
4489 u32 ctl
= le32_to_cpu(eq_entry
->hdr
.ctl
);
4490 u16 event_type
= ((ctl
& EQ_CTL_EVENT_TYPE_MASK
)
4491 >> EQ_CTL_EVENT_TYPE_SHIFT
);
4492 struct goya_device
*goya
= hdev
->asic_specific
;
4494 goya
->events_stat
[event_type
]++;
4495 goya
->events_stat_aggregate
[event_type
]++;
4497 switch (event_type
) {
4498 case GOYA_ASYNC_EVENT_ID_PCIE_IF
:
4499 case GOYA_ASYNC_EVENT_ID_TPC0_ECC
:
4500 case GOYA_ASYNC_EVENT_ID_TPC1_ECC
:
4501 case GOYA_ASYNC_EVENT_ID_TPC2_ECC
:
4502 case GOYA_ASYNC_EVENT_ID_TPC3_ECC
:
4503 case GOYA_ASYNC_EVENT_ID_TPC4_ECC
:
4504 case GOYA_ASYNC_EVENT_ID_TPC5_ECC
:
4505 case GOYA_ASYNC_EVENT_ID_TPC6_ECC
:
4506 case GOYA_ASYNC_EVENT_ID_TPC7_ECC
:
4507 case GOYA_ASYNC_EVENT_ID_MME_ECC
:
4508 case GOYA_ASYNC_EVENT_ID_MME_ECC_EXT
:
4509 case GOYA_ASYNC_EVENT_ID_MMU_ECC
:
4510 case GOYA_ASYNC_EVENT_ID_DMA_MACRO
:
4511 case GOYA_ASYNC_EVENT_ID_DMA_ECC
:
4512 case GOYA_ASYNC_EVENT_ID_CPU_IF_ECC
:
4513 case GOYA_ASYNC_EVENT_ID_PSOC_MEM
:
4514 case GOYA_ASYNC_EVENT_ID_PSOC_CORESIGHT
:
4515 case GOYA_ASYNC_EVENT_ID_SRAM0
... GOYA_ASYNC_EVENT_ID_SRAM29
:
4516 case GOYA_ASYNC_EVENT_ID_GIC500
:
4517 case GOYA_ASYNC_EVENT_ID_PLL0
... GOYA_ASYNC_EVENT_ID_PLL6
:
4518 case GOYA_ASYNC_EVENT_ID_AXI_ECC
:
4519 case GOYA_ASYNC_EVENT_ID_L2_RAM_ECC
:
4520 case GOYA_ASYNC_EVENT_ID_PSOC_GPIO_05_SW_RESET
:
4521 goya_print_irq_info(hdev
, event_type
, false);
4522 hl_device_reset(hdev
, true, false);
4525 case GOYA_ASYNC_EVENT_ID_PCIE_DEC
:
4526 case GOYA_ASYNC_EVENT_ID_TPC0_DEC
:
4527 case GOYA_ASYNC_EVENT_ID_TPC1_DEC
:
4528 case GOYA_ASYNC_EVENT_ID_TPC2_DEC
:
4529 case GOYA_ASYNC_EVENT_ID_TPC3_DEC
:
4530 case GOYA_ASYNC_EVENT_ID_TPC4_DEC
:
4531 case GOYA_ASYNC_EVENT_ID_TPC5_DEC
:
4532 case GOYA_ASYNC_EVENT_ID_TPC6_DEC
:
4533 case GOYA_ASYNC_EVENT_ID_TPC7_DEC
:
4534 case GOYA_ASYNC_EVENT_ID_MME_WACS
:
4535 case GOYA_ASYNC_EVENT_ID_MME_WACSD
:
4536 case GOYA_ASYNC_EVENT_ID_CPU_AXI_SPLITTER
:
4537 case GOYA_ASYNC_EVENT_ID_PSOC_AXI_DEC
:
4538 case GOYA_ASYNC_EVENT_ID_PSOC
:
4539 case GOYA_ASYNC_EVENT_ID_TPC0_KRN_ERR
:
4540 case GOYA_ASYNC_EVENT_ID_TPC1_KRN_ERR
:
4541 case GOYA_ASYNC_EVENT_ID_TPC2_KRN_ERR
:
4542 case GOYA_ASYNC_EVENT_ID_TPC3_KRN_ERR
:
4543 case GOYA_ASYNC_EVENT_ID_TPC4_KRN_ERR
:
4544 case GOYA_ASYNC_EVENT_ID_TPC5_KRN_ERR
:
4545 case GOYA_ASYNC_EVENT_ID_TPC6_KRN_ERR
:
4546 case GOYA_ASYNC_EVENT_ID_TPC7_KRN_ERR
:
4547 case GOYA_ASYNC_EVENT_ID_TPC0_CMDQ
... GOYA_ASYNC_EVENT_ID_TPC7_QM
:
4548 case GOYA_ASYNC_EVENT_ID_MME_QM
:
4549 case GOYA_ASYNC_EVENT_ID_MME_CMDQ
:
4550 case GOYA_ASYNC_EVENT_ID_DMA0_QM
... GOYA_ASYNC_EVENT_ID_DMA4_QM
:
4551 case GOYA_ASYNC_EVENT_ID_DMA0_CH
... GOYA_ASYNC_EVENT_ID_DMA4_CH
:
4552 goya_print_irq_info(hdev
, event_type
, true);
4553 goya_unmask_irq(hdev
, event_type
);
4556 case GOYA_ASYNC_EVENT_ID_PSOC_GPIO_10_VRHOT_ICRIT
:
4557 case GOYA_ASYNC_EVENT_ID_TPC0_BMON_SPMU
:
4558 case GOYA_ASYNC_EVENT_ID_TPC1_BMON_SPMU
:
4559 case GOYA_ASYNC_EVENT_ID_TPC2_BMON_SPMU
:
4560 case GOYA_ASYNC_EVENT_ID_TPC3_BMON_SPMU
:
4561 case GOYA_ASYNC_EVENT_ID_TPC4_BMON_SPMU
:
4562 case GOYA_ASYNC_EVENT_ID_TPC5_BMON_SPMU
:
4563 case GOYA_ASYNC_EVENT_ID_TPC6_BMON_SPMU
:
4564 case GOYA_ASYNC_EVENT_ID_TPC7_BMON_SPMU
:
4565 case GOYA_ASYNC_EVENT_ID_DMA_BM_CH0
... GOYA_ASYNC_EVENT_ID_DMA_BM_CH4
:
4566 goya_print_irq_info(hdev
, event_type
, false);
4567 goya_unmask_irq(hdev
, event_type
);
4571 dev_err(hdev
->dev
, "Received invalid H/W interrupt %d\n",
4577 void *goya_get_events_stat(struct hl_device
*hdev
, bool aggregate
, u32
*size
)
4579 struct goya_device
*goya
= hdev
->asic_specific
;
4582 *size
= (u32
) sizeof(goya
->events_stat_aggregate
);
4583 return goya
->events_stat_aggregate
;
4586 *size
= (u32
) sizeof(goya
->events_stat
);
4587 return goya
->events_stat
;
4590 static int goya_memset_device_memory(struct hl_device
*hdev
, u64 addr
, u64 size
,
4591 u64 val
, bool is_dram
)
4593 struct packet_lin_dma
*lin_dma_pkt
;
4594 struct hl_cs_job
*job
;
4597 int rc
, lin_dma_pkts_cnt
;
4599 lin_dma_pkts_cnt
= DIV_ROUND_UP_ULL(size
, SZ_2G
);
4600 cb_size
= lin_dma_pkts_cnt
* sizeof(struct packet_lin_dma
) +
4601 sizeof(struct packet_msg_prot
);
4602 cb
= hl_cb_kernel_create(hdev
, cb_size
);
4606 lin_dma_pkt
= (struct packet_lin_dma
*) (uintptr_t) cb
->kernel_address
;
4609 memset(lin_dma_pkt
, 0, sizeof(*lin_dma_pkt
));
4611 ctl
= ((PACKET_LIN_DMA
<< GOYA_PKT_CTL_OPCODE_SHIFT
) |
4612 (1 << GOYA_PKT_LIN_DMA_CTL_MEMSET_SHIFT
) |
4613 (1 << GOYA_PKT_LIN_DMA_CTL_WO_SHIFT
) |
4614 (1 << GOYA_PKT_CTL_RB_SHIFT
) |
4615 (1 << GOYA_PKT_CTL_MB_SHIFT
));
4616 ctl
|= (is_dram
? DMA_HOST_TO_DRAM
: DMA_HOST_TO_SRAM
) <<
4617 GOYA_PKT_LIN_DMA_CTL_DMA_DIR_SHIFT
;
4618 lin_dma_pkt
->ctl
= cpu_to_le32(ctl
);
4620 lin_dma_pkt
->src_addr
= cpu_to_le64(val
);
4621 lin_dma_pkt
->dst_addr
= cpu_to_le64(addr
);
4622 if (lin_dma_pkts_cnt
> 1)
4623 lin_dma_pkt
->tsize
= cpu_to_le32(SZ_2G
);
4625 lin_dma_pkt
->tsize
= cpu_to_le32(size
);
4630 } while (--lin_dma_pkts_cnt
);
4632 job
= hl_cs_allocate_job(hdev
, QUEUE_TYPE_EXT
, true);
4634 dev_err(hdev
->dev
, "Failed to allocate a new job\n");
4641 job
->user_cb
->cs_cnt
++;
4642 job
->user_cb_size
= cb_size
;
4643 job
->hw_queue_id
= GOYA_QUEUE_ID_DMA_0
;
4644 job
->patched_cb
= job
->user_cb
;
4645 job
->job_cb_size
= job
->user_cb_size
;
4647 hl_debugfs_add_job(hdev
, job
);
4649 rc
= goya_send_job_on_qman0(hdev
, job
);
4651 hl_cb_put(job
->patched_cb
);
4653 hl_debugfs_remove_job(hdev
, job
);
4659 hl_cb_destroy(hdev
, &hdev
->kernel_cb_mgr
, cb
->id
<< PAGE_SHIFT
);
4664 int goya_context_switch(struct hl_device
*hdev
, u32 asid
)
4666 struct asic_fixed_properties
*prop
= &hdev
->asic_prop
;
4667 u64 addr
= prop
->sram_base_address
, sob_addr
;
4668 u32 size
= hdev
->pldm
? 0x10000 : prop
->sram_size
;
4669 u64 val
= 0x7777777777777777ull
;
4671 u32 channel_off
= mmDMA_CH_1_WR_COMP_ADDR_LO
-
4672 mmDMA_CH_0_WR_COMP_ADDR_LO
;
4674 rc
= goya_memset_device_memory(hdev
, addr
, size
, val
, false);
4676 dev_err(hdev
->dev
, "Failed to clear SRAM in context switch\n");
4680 /* we need to reset registers that the user is allowed to change */
4681 sob_addr
= CFG_BASE
+ mmSYNC_MNGR_SOB_OBJ_1007
;
4682 WREG32(mmDMA_CH_0_WR_COMP_ADDR_LO
, lower_32_bits(sob_addr
));
4684 for (dma_id
= 1 ; dma_id
< NUMBER_OF_EXT_HW_QUEUES
; dma_id
++) {
4685 sob_addr
= CFG_BASE
+ mmSYNC_MNGR_SOB_OBJ_1000
+
4687 WREG32(mmDMA_CH_0_WR_COMP_ADDR_LO
+ channel_off
* dma_id
,
4688 lower_32_bits(sob_addr
));
4691 WREG32(mmTPC_PLL_CLK_RLX_0
, 0x200020);
4693 goya_mmu_prepare(hdev
, asid
);
4695 goya_clear_sm_regs(hdev
);
4700 static int goya_mmu_clear_pgt_range(struct hl_device
*hdev
)
4702 struct asic_fixed_properties
*prop
= &hdev
->asic_prop
;
4703 struct goya_device
*goya
= hdev
->asic_specific
;
4704 u64 addr
= prop
->mmu_pgt_addr
;
4705 u32 size
= prop
->mmu_pgt_size
+ MMU_DRAM_DEFAULT_PAGE_SIZE
+
4708 if (!(goya
->hw_cap_initialized
& HW_CAP_MMU
))
4711 return goya_memset_device_memory(hdev
, addr
, size
, 0, true);
4714 static int goya_mmu_set_dram_default_page(struct hl_device
*hdev
)
4716 struct goya_device
*goya
= hdev
->asic_specific
;
4717 u64 addr
= hdev
->asic_prop
.mmu_dram_default_page_addr
;
4718 u32 size
= MMU_DRAM_DEFAULT_PAGE_SIZE
;
4719 u64 val
= 0x9999999999999999ull
;
4721 if (!(goya
->hw_cap_initialized
& HW_CAP_MMU
))
4724 return goya_memset_device_memory(hdev
, addr
, size
, val
, true);
4727 static int goya_mmu_add_mappings_for_device_cpu(struct hl_device
*hdev
)
4729 struct asic_fixed_properties
*prop
= &hdev
->asic_prop
;
4730 struct goya_device
*goya
= hdev
->asic_specific
;
4734 if (!(goya
->hw_cap_initialized
& HW_CAP_MMU
))
4737 for (off
= 0 ; off
< CPU_FW_IMAGE_SIZE
; off
+= PAGE_SIZE_2MB
) {
4738 rc
= hl_mmu_map(hdev
->kernel_ctx
, prop
->dram_base_address
+ off
,
4739 prop
->dram_base_address
+ off
, PAGE_SIZE_2MB
);
4741 dev_err(hdev
->dev
, "Map failed for address 0x%llx\n",
4742 prop
->dram_base_address
+ off
);
4747 if (!(hdev
->cpu_accessible_dma_address
& (PAGE_SIZE_2MB
- 1))) {
4748 rc
= hl_mmu_map(hdev
->kernel_ctx
, VA_CPU_ACCESSIBLE_MEM_ADDR
,
4749 hdev
->cpu_accessible_dma_address
, PAGE_SIZE_2MB
);
4753 "Map failed for CPU accessible memory\n");
4754 off
-= PAGE_SIZE_2MB
;
4758 for (cpu_off
= 0 ; cpu_off
< SZ_2M
; cpu_off
+= PAGE_SIZE_4KB
) {
4759 rc
= hl_mmu_map(hdev
->kernel_ctx
,
4760 VA_CPU_ACCESSIBLE_MEM_ADDR
+ cpu_off
,
4761 hdev
->cpu_accessible_dma_address
+ cpu_off
,
4765 "Map failed for CPU accessible memory\n");
4766 cpu_off
-= PAGE_SIZE_4KB
;
4772 goya_mmu_prepare_reg(hdev
, mmCPU_IF_ARUSER_OVR
, HL_KERNEL_ASID_ID
);
4773 goya_mmu_prepare_reg(hdev
, mmCPU_IF_AWUSER_OVR
, HL_KERNEL_ASID_ID
);
4774 WREG32(mmCPU_IF_ARUSER_OVR_EN
, 0x7FF);
4775 WREG32(mmCPU_IF_AWUSER_OVR_EN
, 0x7FF);
4777 /* Make sure configuration is flushed to device */
4778 RREG32(mmCPU_IF_AWUSER_OVR_EN
);
4780 goya
->device_cpu_mmu_mappings_done
= true;
4785 for (; cpu_off
>= 0 ; cpu_off
-= PAGE_SIZE_4KB
)
4786 if (hl_mmu_unmap(hdev
->kernel_ctx
,
4787 VA_CPU_ACCESSIBLE_MEM_ADDR
+ cpu_off
,
4789 dev_warn_ratelimited(hdev
->dev
,
4790 "failed to unmap address 0x%llx\n",
4791 VA_CPU_ACCESSIBLE_MEM_ADDR
+ cpu_off
);
4793 for (; off
>= 0 ; off
-= PAGE_SIZE_2MB
)
4794 if (hl_mmu_unmap(hdev
->kernel_ctx
,
4795 prop
->dram_base_address
+ off
, PAGE_SIZE_2MB
))
4796 dev_warn_ratelimited(hdev
->dev
,
4797 "failed to unmap address 0x%llx\n",
4798 prop
->dram_base_address
+ off
);
4803 void goya_mmu_remove_device_cpu_mappings(struct hl_device
*hdev
)
4805 struct asic_fixed_properties
*prop
= &hdev
->asic_prop
;
4806 struct goya_device
*goya
= hdev
->asic_specific
;
4809 if (!(goya
->hw_cap_initialized
& HW_CAP_MMU
))
4812 if (!goya
->device_cpu_mmu_mappings_done
)
4815 WREG32(mmCPU_IF_ARUSER_OVR_EN
, 0);
4816 WREG32(mmCPU_IF_AWUSER_OVR_EN
, 0);
4818 if (!(hdev
->cpu_accessible_dma_address
& (PAGE_SIZE_2MB
- 1))) {
4819 if (hl_mmu_unmap(hdev
->kernel_ctx
, VA_CPU_ACCESSIBLE_MEM_ADDR
,
4822 "Failed to unmap CPU accessible memory\n");
4824 for (cpu_off
= 0 ; cpu_off
< SZ_2M
; cpu_off
+= PAGE_SIZE_4KB
)
4825 if (hl_mmu_unmap(hdev
->kernel_ctx
,
4826 VA_CPU_ACCESSIBLE_MEM_ADDR
+ cpu_off
,
4828 dev_warn_ratelimited(hdev
->dev
,
4829 "failed to unmap address 0x%llx\n",
4830 VA_CPU_ACCESSIBLE_MEM_ADDR
+ cpu_off
);
4833 for (off
= 0 ; off
< CPU_FW_IMAGE_SIZE
; off
+= PAGE_SIZE_2MB
)
4834 if (hl_mmu_unmap(hdev
->kernel_ctx
,
4835 prop
->dram_base_address
+ off
, PAGE_SIZE_2MB
))
4836 dev_warn_ratelimited(hdev
->dev
,
4837 "Failed to unmap address 0x%llx\n",
4838 prop
->dram_base_address
+ off
);
4840 goya
->device_cpu_mmu_mappings_done
= false;
4843 static void goya_mmu_prepare(struct hl_device
*hdev
, u32 asid
)
4845 struct goya_device
*goya
= hdev
->asic_specific
;
4848 if (!(goya
->hw_cap_initialized
& HW_CAP_MMU
))
4851 if (asid
& ~MME_QM_GLBL_SECURE_PROPS_ASID_MASK
) {
4852 WARN(1, "asid %u is too big\n", asid
);
4856 /* zero the MMBP and ASID bits and then set the ASID */
4857 for (i
= 0 ; i
< GOYA_MMU_REGS_NUM
; i
++)
4858 goya_mmu_prepare_reg(hdev
, goya_mmu_regs
[i
], asid
);
4861 static void goya_mmu_invalidate_cache(struct hl_device
*hdev
, bool is_hard
,
4864 struct goya_device
*goya
= hdev
->asic_specific
;
4865 u32 status
, timeout_usec
;
4868 if (!(goya
->hw_cap_initialized
& HW_CAP_MMU
) ||
4869 hdev
->hard_reset_pending
)
4872 /* no need in L1 only invalidation in Goya */
4877 timeout_usec
= GOYA_PLDM_MMU_TIMEOUT_USEC
;
4879 timeout_usec
= MMU_CONFIG_TIMEOUT_USEC
;
4881 mutex_lock(&hdev
->mmu_cache_lock
);
4883 /* L0 & L1 invalidation */
4884 WREG32(mmSTLB_INV_ALL_START
, 1);
4886 rc
= hl_poll_timeout(
4888 mmSTLB_INV_ALL_START
,
4894 mutex_unlock(&hdev
->mmu_cache_lock
);
4897 dev_notice_ratelimited(hdev
->dev
,
4898 "Timeout when waiting for MMU cache invalidation\n");
4901 static void goya_mmu_invalidate_cache_range(struct hl_device
*hdev
,
4902 bool is_hard
, u32 asid
, u64 va
, u64 size
)
4904 struct goya_device
*goya
= hdev
->asic_specific
;
4905 u32 status
, timeout_usec
, inv_data
, pi
;
4908 if (!(goya
->hw_cap_initialized
& HW_CAP_MMU
) ||
4909 hdev
->hard_reset_pending
)
4912 /* no need in L1 only invalidation in Goya */
4917 timeout_usec
= GOYA_PLDM_MMU_TIMEOUT_USEC
;
4919 timeout_usec
= MMU_CONFIG_TIMEOUT_USEC
;
4921 mutex_lock(&hdev
->mmu_cache_lock
);
4924 * TODO: currently invalidate entire L0 & L1 as in regular hard
4925 * invalidation. Need to apply invalidation of specific cache lines with
4926 * mask of ASID & VA & size.
4927 * Note that L1 with be flushed entirely in any case.
4930 /* L0 & L1 invalidation */
4931 inv_data
= RREG32(mmSTLB_CACHE_INV
);
4933 pi
= ((inv_data
& STLB_CACHE_INV_PRODUCER_INDEX_MASK
) + 1) & 0xFF;
4934 WREG32(mmSTLB_CACHE_INV
,
4935 (inv_data
& STLB_CACHE_INV_INDEX_MASK_MASK
) | pi
);
4937 rc
= hl_poll_timeout(
4939 mmSTLB_INV_CONSUMER_INDEX
,
4945 mutex_unlock(&hdev
->mmu_cache_lock
);
4948 dev_notice_ratelimited(hdev
->dev
,
4949 "Timeout when waiting for MMU cache invalidation\n");
4952 int goya_send_heartbeat(struct hl_device
*hdev
)
4954 struct goya_device
*goya
= hdev
->asic_specific
;
4956 if (!(goya
->hw_cap_initialized
& HW_CAP_CPU_Q
))
4959 return hl_fw_send_heartbeat(hdev
);
4962 int goya_armcp_info_get(struct hl_device
*hdev
)
4964 struct goya_device
*goya
= hdev
->asic_specific
;
4965 struct asic_fixed_properties
*prop
= &hdev
->asic_prop
;
4969 if (!(goya
->hw_cap_initialized
& HW_CAP_CPU_Q
))
4972 rc
= hl_fw_armcp_info_get(hdev
);
4976 dram_size
= le64_to_cpu(prop
->armcp_info
.dram_size
);
4978 if ((!is_power_of_2(dram_size
)) ||
4979 (dram_size
< DRAM_PHYS_DEFAULT_SIZE
)) {
4981 "F/W reported invalid DRAM size %llu. Trying to use default size\n",
4983 dram_size
= DRAM_PHYS_DEFAULT_SIZE
;
4986 prop
->dram_size
= dram_size
;
4987 prop
->dram_end_address
= prop
->dram_base_address
+ dram_size
;
4990 if (!strlen(prop
->armcp_info
.card_name
))
4991 strncpy(prop
->armcp_info
.card_name
, GOYA_DEFAULT_CARD_NAME
,
4997 static bool goya_is_device_idle(struct hl_device
*hdev
, u32
*mask
,
5000 const char *fmt
= "%-5d%-9s%#-14x%#-16x%#x\n";
5001 const char *dma_fmt
= "%-5d%-9s%#-14x%#x\n";
5002 u32 qm_glbl_sts0
, cmdq_glbl_sts0
, dma_core_sts0
, tpc_cfg_sts
,
5004 bool is_idle
= true, is_eng_idle
;
5009 seq_puts(s
, "\nDMA is_idle QM_GLBL_STS0 DMA_CORE_STS0\n"
5010 "--- ------- ------------ -------------\n");
5012 offset
= mmDMA_QM_1_GLBL_STS0
- mmDMA_QM_0_GLBL_STS0
;
5014 for (i
= 0 ; i
< DMA_MAX_NUM
; i
++) {
5015 qm_glbl_sts0
= RREG32(mmDMA_QM_0_GLBL_STS0
+ i
* offset
);
5016 dma_core_sts0
= RREG32(mmDMA_CH_0_STS0
+ i
* offset
);
5017 is_eng_idle
= IS_DMA_QM_IDLE(qm_glbl_sts0
) &&
5018 IS_DMA_IDLE(dma_core_sts0
);
5019 is_idle
&= is_eng_idle
;
5022 *mask
|= !is_eng_idle
<< (GOYA_ENGINE_ID_DMA_0
+ i
);
5024 seq_printf(s
, dma_fmt
, i
, is_eng_idle
? "Y" : "N",
5025 qm_glbl_sts0
, dma_core_sts0
);
5030 "\nTPC is_idle QM_GLBL_STS0 CMDQ_GLBL_STS0 CFG_STATUS\n"
5031 "--- ------- ------------ -------------- ----------\n");
5033 offset
= mmTPC1_QM_GLBL_STS0
- mmTPC0_QM_GLBL_STS0
;
5035 for (i
= 0 ; i
< TPC_MAX_NUM
; i
++) {
5036 qm_glbl_sts0
= RREG32(mmTPC0_QM_GLBL_STS0
+ i
* offset
);
5037 cmdq_glbl_sts0
= RREG32(mmTPC0_CMDQ_GLBL_STS0
+ i
* offset
);
5038 tpc_cfg_sts
= RREG32(mmTPC0_CFG_STATUS
+ i
* offset
);
5039 is_eng_idle
= IS_TPC_QM_IDLE(qm_glbl_sts0
) &&
5040 IS_TPC_CMDQ_IDLE(cmdq_glbl_sts0
) &&
5041 IS_TPC_IDLE(tpc_cfg_sts
);
5042 is_idle
&= is_eng_idle
;
5045 *mask
|= !is_eng_idle
<< (GOYA_ENGINE_ID_TPC_0
+ i
);
5047 seq_printf(s
, fmt
, i
, is_eng_idle
? "Y" : "N",
5048 qm_glbl_sts0
, cmdq_glbl_sts0
, tpc_cfg_sts
);
5053 "\nMME is_idle QM_GLBL_STS0 CMDQ_GLBL_STS0 ARCH_STATUS\n"
5054 "--- ------- ------------ -------------- -----------\n");
5056 qm_glbl_sts0
= RREG32(mmMME_QM_GLBL_STS0
);
5057 cmdq_glbl_sts0
= RREG32(mmMME_CMDQ_GLBL_STS0
);
5058 mme_arch_sts
= RREG32(mmMME_ARCH_STATUS
);
5059 is_eng_idle
= IS_MME_QM_IDLE(qm_glbl_sts0
) &&
5060 IS_MME_CMDQ_IDLE(cmdq_glbl_sts0
) &&
5061 IS_MME_IDLE(mme_arch_sts
);
5062 is_idle
&= is_eng_idle
;
5065 *mask
|= !is_eng_idle
<< GOYA_ENGINE_ID_MME_0
;
5067 seq_printf(s
, fmt
, 0, is_eng_idle
? "Y" : "N", qm_glbl_sts0
,
5068 cmdq_glbl_sts0
, mme_arch_sts
);
5075 static void goya_hw_queues_lock(struct hl_device
*hdev
)
5077 struct goya_device
*goya
= hdev
->asic_specific
;
5079 spin_lock(&goya
->hw_queues_lock
);
5082 static void goya_hw_queues_unlock(struct hl_device
*hdev
)
5084 struct goya_device
*goya
= hdev
->asic_specific
;
5086 spin_unlock(&goya
->hw_queues_lock
);
5089 static u32
goya_get_pci_id(struct hl_device
*hdev
)
5091 return hdev
->pdev
->device
;
5094 static int goya_get_eeprom_data(struct hl_device
*hdev
, void *data
,
5097 struct goya_device
*goya
= hdev
->asic_specific
;
5099 if (!(goya
->hw_cap_initialized
& HW_CAP_CPU_Q
))
5102 return hl_fw_get_eeprom_data(hdev
, data
, max_size
);
5105 static enum hl_device_hw_state
goya_get_hw_state(struct hl_device
*hdev
)
5107 return RREG32(mmHW_STATE
);
5110 static const struct hl_asic_funcs goya_funcs
= {
5111 .early_init
= goya_early_init
,
5112 .early_fini
= goya_early_fini
,
5113 .late_init
= goya_late_init
,
5114 .late_fini
= goya_late_fini
,
5115 .sw_init
= goya_sw_init
,
5116 .sw_fini
= goya_sw_fini
,
5117 .hw_init
= goya_hw_init
,
5118 .hw_fini
= goya_hw_fini
,
5119 .halt_engines
= goya_halt_engines
,
5120 .suspend
= goya_suspend
,
5121 .resume
= goya_resume
,
5122 .cb_mmap
= goya_cb_mmap
,
5123 .ring_doorbell
= goya_ring_doorbell
,
5124 .pqe_write
= goya_pqe_write
,
5125 .asic_dma_alloc_coherent
= goya_dma_alloc_coherent
,
5126 .asic_dma_free_coherent
= goya_dma_free_coherent
,
5127 .get_int_queue_base
= goya_get_int_queue_base
,
5128 .test_queues
= goya_test_queues
,
5129 .asic_dma_pool_zalloc
= goya_dma_pool_zalloc
,
5130 .asic_dma_pool_free
= goya_dma_pool_free
,
5131 .cpu_accessible_dma_pool_alloc
= goya_cpu_accessible_dma_pool_alloc
,
5132 .cpu_accessible_dma_pool_free
= goya_cpu_accessible_dma_pool_free
,
5133 .hl_dma_unmap_sg
= goya_dma_unmap_sg
,
5134 .cs_parser
= goya_cs_parser
,
5135 .asic_dma_map_sg
= goya_dma_map_sg
,
5136 .get_dma_desc_list_size
= goya_get_dma_desc_list_size
,
5137 .add_end_of_cb_packets
= goya_add_end_of_cb_packets
,
5138 .update_eq_ci
= goya_update_eq_ci
,
5139 .context_switch
= goya_context_switch
,
5140 .restore_phase_topology
= goya_restore_phase_topology
,
5141 .debugfs_read32
= goya_debugfs_read32
,
5142 .debugfs_write32
= goya_debugfs_write32
,
5143 .add_device_attr
= goya_add_device_attr
,
5144 .handle_eqe
= goya_handle_eqe
,
5145 .set_pll_profile
= goya_set_pll_profile
,
5146 .get_events_stat
= goya_get_events_stat
,
5147 .read_pte
= goya_read_pte
,
5148 .write_pte
= goya_write_pte
,
5149 .mmu_invalidate_cache
= goya_mmu_invalidate_cache
,
5150 .mmu_invalidate_cache_range
= goya_mmu_invalidate_cache_range
,
5151 .send_heartbeat
= goya_send_heartbeat
,
5152 .debug_coresight
= goya_debug_coresight
,
5153 .is_device_idle
= goya_is_device_idle
,
5154 .soft_reset_late_init
= goya_soft_reset_late_init
,
5155 .hw_queues_lock
= goya_hw_queues_lock
,
5156 .hw_queues_unlock
= goya_hw_queues_unlock
,
5157 .get_pci_id
= goya_get_pci_id
,
5158 .get_eeprom_data
= goya_get_eeprom_data
,
5159 .send_cpu_message
= goya_send_cpu_message
,
5160 .get_hw_state
= goya_get_hw_state
,
5161 .pci_bars_map
= goya_pci_bars_map
,
5162 .set_dram_bar_base
= goya_set_ddr_bar_base
,
5163 .init_iatu
= goya_init_iatu
,
5166 .halt_coresight
= goya_halt_coresight
,
5167 .get_clk_rate
= goya_get_clk_rate
5171 * goya_set_asic_funcs - set Goya function pointers
5173 * @*hdev: pointer to hl_device structure
5176 void goya_set_asic_funcs(struct hl_device
*hdev
)
5178 hdev
->asic_funcs
= &goya_funcs
;