blob: d46925d921a32829626bd0e82e5933bf7ff99f73 [file] [log] [blame]
Oded Gabbay99b9d7b2019-02-16 00:39:13 +02001// SPDX-License-Identifier: GPL-2.0
2
3/*
4 * Copyright 2016-2019 HabanaLabs, Ltd.
5 * All Rights Reserved.
6 */
7
8#include "goyaP.h"
9#include "include/goya/asic_reg/goya_masks.h"
10
11#include <linux/pci.h>
Oded Gabbay99b9d7b2019-02-16 00:39:13 +020012#include <linux/genalloc.h>
Oded Gabbay839c4802019-02-16 00:39:16 +020013#include <linux/firmware.h>
Oded Gabbayd91389b2019-02-16 00:39:19 +020014#include <linux/hwmon.h>
Oded Gabbay839c4802019-02-16 00:39:16 +020015#include <linux/io-64-nonatomic-lo-hi.h>
16#include <linux/io-64-nonatomic-hi-lo.h>
Oded Gabbay99b9d7b2019-02-16 00:39:13 +020017
18/*
19 * GOYA security scheme:
20 *
21 * 1. Host is protected by:
22 * - Range registers (When MMU is enabled, DMA RR does NOT protect host)
23 * - MMU
24 *
25 * 2. DRAM is protected by:
26 * - Range registers (protect the first 512MB)
27 * - MMU (isolation between users)
28 *
29 * 3. Configuration is protected by:
30 * - Range registers
31 * - Protection bits
32 *
33 * When MMU is disabled:
34 *
35 * QMAN DMA: PQ, CQ, CP, DMA are secured.
36 * PQ, CB and the data are on the host.
37 *
38 * QMAN TPC/MME:
39 * PQ, CQ and CP are not secured.
40 * PQ, CB and the data are on the SRAM/DRAM.
41 *
42 * Since QMAN DMA is secured, KMD is parsing the DMA CB:
43 * - KMD checks DMA pointer
44 * - WREG, MSG_PROT are not allowed.
45 * - MSG_LONG/SHORT are allowed.
46 *
47 * A read/write transaction by the QMAN to a protected area will succeed if
48 * and only if the QMAN's CP is secured and MSG_PROT is used
49 *
50 *
51 * When MMU is enabled:
52 *
53 * QMAN DMA: PQ, CQ and CP are secured.
54 * MMU is set to bypass on the Secure props register of the QMAN.
55 * The reasons we don't enable MMU for PQ, CQ and CP are:
56 * - PQ entry is in kernel address space and KMD doesn't map it.
57 * - CP writes to MSIX register and to kernel address space (completion
58 * queue).
59 *
60 * DMA is not secured but because CP is secured, KMD still needs to parse the
61 * CB, but doesn't need to check the DMA addresses.
62 *
63 * For QMAN DMA 0, DMA is also secured because only KMD uses this DMA and KMD
64 * doesn't map memory in MMU.
65 *
66 * QMAN TPC/MME: PQ, CQ and CP aren't secured (no change from MMU disabled mode)
67 *
68 * DMA RR does NOT protect host because DMA is not secured
69 *
70 */
71
72#define GOYA_MMU_REGS_NUM 61
73
74#define GOYA_DMA_POOL_BLK_SIZE 0x100 /* 256 bytes */
75
76#define GOYA_RESET_TIMEOUT_MSEC 500 /* 500ms */
77#define GOYA_PLDM_RESET_TIMEOUT_MSEC 20000 /* 20s */
78#define GOYA_RESET_WAIT_MSEC 1 /* 1ms */
79#define GOYA_CPU_RESET_WAIT_MSEC 100 /* 100ms */
80#define GOYA_PLDM_RESET_WAIT_MSEC 1000 /* 1s */
81#define GOYA_CPU_TIMEOUT_USEC 10000000 /* 10s */
82#define GOYA_TEST_QUEUE_WAIT_USEC 100000 /* 100ms */
83
84#define GOYA_QMAN0_FENCE_VAL 0xD169B243
85
86#define GOYA_MAX_INITIATORS 20
87
Oded Gabbay1251f232019-02-16 00:39:18 +020088#define GOYA_MAX_STRING_LEN 20
89
Oded Gabbaybe5d9262019-02-16 00:39:15 +020090#define GOYA_CB_POOL_CB_CNT 512
91#define GOYA_CB_POOL_CB_SIZE 0x20000 /* 128KB */
92
Oded Gabbay1251f232019-02-16 00:39:18 +020093static const char goya_irq_name[GOYA_MSIX_ENTRIES][GOYA_MAX_STRING_LEN] = {
94 "goya cq 0", "goya cq 1", "goya cq 2", "goya cq 3",
95 "goya cq 4", "goya cpu eq"
96};
97
98static const char *goya_axi_name[GOYA_MAX_INITIATORS] = {
99 "MME0",
100 "MME1",
101 "MME2",
102 "MME3",
103 "MME4",
104 "MME5",
105 "TPC0",
106 "TPC1",
107 "TPC2",
108 "TPC3",
109 "TPC4",
110 "TPC5",
111 "TPC6",
112 "TPC7",
113 "PCI",
114 "DMA", /* HBW */
115 "DMA", /* LBW */
116 "PSOC",
117 "CPU",
118 "MMU"
119};
120
121#define GOYA_ASYC_EVENT_GROUP_NON_FATAL_SIZE 121
122
Oded Gabbayd91389b2019-02-16 00:39:19 +0200123static int goya_armcp_info_get(struct hl_device *hdev);
124
Oded Gabbay99b9d7b2019-02-16 00:39:13 +0200125static void goya_get_fixed_properties(struct hl_device *hdev)
126{
127 struct asic_fixed_properties *prop = &hdev->asic_prop;
Oded Gabbay9494a8d2019-02-16 00:39:17 +0200128 int i;
129
130 for (i = 0 ; i < NUMBER_OF_EXT_HW_QUEUES ; i++) {
131 prop->hw_queues_props[i].type = QUEUE_TYPE_EXT;
132 prop->hw_queues_props[i].kmd_only = 0;
133 }
134
135 for (; i < NUMBER_OF_EXT_HW_QUEUES + NUMBER_OF_CPU_HW_QUEUES ; i++) {
136 prop->hw_queues_props[i].type = QUEUE_TYPE_CPU;
137 prop->hw_queues_props[i].kmd_only = 1;
138 }
139
140 for (; i < NUMBER_OF_EXT_HW_QUEUES + NUMBER_OF_CPU_HW_QUEUES +
141 NUMBER_OF_INT_HW_QUEUES; i++) {
142 prop->hw_queues_props[i].type = QUEUE_TYPE_INT;
143 prop->hw_queues_props[i].kmd_only = 0;
144 }
145
146 for (; i < HL_MAX_QUEUES; i++)
147 prop->hw_queues_props[i].type = QUEUE_TYPE_NA;
Oded Gabbay99b9d7b2019-02-16 00:39:13 +0200148
149 prop->completion_queues_count = NUMBER_OF_CMPLT_QUEUES;
150
151 prop->dram_base_address = DRAM_PHYS_BASE;
152 prop->dram_size = DRAM_PHYS_DEFAULT_SIZE;
153 prop->dram_end_address = prop->dram_base_address + prop->dram_size;
154 prop->dram_user_base_address = DRAM_BASE_ADDR_USER;
155
156 prop->sram_base_address = SRAM_BASE_ADDR;
157 prop->sram_size = SRAM_SIZE;
158 prop->sram_end_address = prop->sram_base_address + prop->sram_size;
159 prop->sram_user_base_address = prop->sram_base_address +
160 SRAM_USER_BASE_OFFSET;
161
162 prop->host_phys_base_address = HOST_PHYS_BASE;
163 prop->va_space_host_start_address = VA_HOST_SPACE_START;
164 prop->va_space_host_end_address = VA_HOST_SPACE_END;
165 prop->va_space_dram_start_address = VA_DDR_SPACE_START;
166 prop->va_space_dram_end_address = VA_DDR_SPACE_END;
167 prop->cfg_size = CFG_SIZE;
168 prop->max_asid = MAX_ASID;
Oded Gabbay1251f232019-02-16 00:39:18 +0200169 prop->num_of_events = GOYA_ASYNC_EVENT_ID_SIZE;
Oded Gabbay839c4802019-02-16 00:39:16 +0200170 prop->cb_pool_cb_cnt = GOYA_CB_POOL_CB_CNT;
171 prop->cb_pool_cb_size = GOYA_CB_POOL_CB_SIZE;
Oded Gabbayd91389b2019-02-16 00:39:19 +0200172 prop->max_power_default = MAX_POWER_DEFAULT;
Oded Gabbay99b9d7b2019-02-16 00:39:13 +0200173 prop->tpc_enabled_mask = TPC_ENABLED_MASK;
174
175 prop->high_pll = PLL_HIGH_DEFAULT;
176}
177
Oded Gabbay9494a8d2019-02-16 00:39:17 +0200178int goya_send_pci_access_msg(struct hl_device *hdev, u32 opcode)
179{
180 struct armcp_packet pkt;
181
182 memset(&pkt, 0, sizeof(pkt));
183
184 pkt.ctl = opcode << ARMCP_PKT_CTL_OPCODE_SHIFT;
185
186 return hdev->asic_funcs->send_cpu_message(hdev, (u32 *) &pkt,
187 sizeof(pkt), HL_DEVICE_TIMEOUT_USEC, NULL);
188}
189
Oded Gabbay99b9d7b2019-02-16 00:39:13 +0200190/*
191 * goya_pci_bars_map - Map PCI BARS of Goya device
192 *
193 * @hdev: pointer to hl_device structure
194 *
195 * Request PCI regions and map them to kernel virtual addresses.
196 * Returns 0 on success
197 *
198 */
199int goya_pci_bars_map(struct hl_device *hdev)
200{
201 struct pci_dev *pdev = hdev->pdev;
202 int rc;
203
204 rc = pci_request_regions(pdev, HL_NAME);
205 if (rc) {
206 dev_err(hdev->dev, "Cannot obtain PCI resources\n");
207 return rc;
208 }
209
210 hdev->pcie_bar[SRAM_CFG_BAR_ID] =
211 pci_ioremap_bar(pdev, SRAM_CFG_BAR_ID);
212 if (!hdev->pcie_bar[SRAM_CFG_BAR_ID]) {
213 dev_err(hdev->dev, "pci_ioremap_bar failed for CFG\n");
214 rc = -ENODEV;
215 goto err_release_regions;
216 }
217
218 hdev->pcie_bar[MSIX_BAR_ID] = pci_ioremap_bar(pdev, MSIX_BAR_ID);
219 if (!hdev->pcie_bar[MSIX_BAR_ID]) {
220 dev_err(hdev->dev, "pci_ioremap_bar failed for MSIX\n");
221 rc = -ENODEV;
222 goto err_unmap_sram_cfg;
223 }
224
225 hdev->pcie_bar[DDR_BAR_ID] = pci_ioremap_wc_bar(pdev, DDR_BAR_ID);
226 if (!hdev->pcie_bar[DDR_BAR_ID]) {
227 dev_err(hdev->dev, "pci_ioremap_bar failed for DDR\n");
228 rc = -ENODEV;
229 goto err_unmap_msix;
230 }
231
232 hdev->rmmio = hdev->pcie_bar[SRAM_CFG_BAR_ID] +
233 (CFG_BASE - SRAM_BASE_ADDR);
234
235 return 0;
236
237err_unmap_msix:
238 iounmap(hdev->pcie_bar[MSIX_BAR_ID]);
239err_unmap_sram_cfg:
240 iounmap(hdev->pcie_bar[SRAM_CFG_BAR_ID]);
241err_release_regions:
242 pci_release_regions(pdev);
243
244 return rc;
245}
246
247/*
248 * goya_pci_bars_unmap - Unmap PCI BARS of Goya device
249 *
250 * @hdev: pointer to hl_device structure
251 *
252 * Release all PCI BARS and unmap their virtual addresses
253 *
254 */
255static void goya_pci_bars_unmap(struct hl_device *hdev)
256{
257 struct pci_dev *pdev = hdev->pdev;
258
259 iounmap(hdev->pcie_bar[DDR_BAR_ID]);
260 iounmap(hdev->pcie_bar[MSIX_BAR_ID]);
261 iounmap(hdev->pcie_bar[SRAM_CFG_BAR_ID]);
262 pci_release_regions(pdev);
263}
264
265/*
266 * goya_elbi_write - Write through the ELBI interface
267 *
268 * @hdev: pointer to hl_device structure
269 *
270 * return 0 on success, -1 on failure
271 *
272 */
273static int goya_elbi_write(struct hl_device *hdev, u64 addr, u32 data)
274{
275 struct pci_dev *pdev = hdev->pdev;
276 ktime_t timeout;
277 u32 val;
278
279 /* Clear previous status */
280 pci_write_config_dword(pdev, mmPCI_CONFIG_ELBI_STS, 0);
281
282 pci_write_config_dword(pdev, mmPCI_CONFIG_ELBI_ADDR, (u32) addr);
283 pci_write_config_dword(pdev, mmPCI_CONFIG_ELBI_DATA, data);
284 pci_write_config_dword(pdev, mmPCI_CONFIG_ELBI_CTRL,
285 PCI_CONFIG_ELBI_CTRL_WRITE);
286
287 timeout = ktime_add_ms(ktime_get(), 10);
288 for (;;) {
289 pci_read_config_dword(pdev, mmPCI_CONFIG_ELBI_STS, &val);
290 if (val & PCI_CONFIG_ELBI_STS_MASK)
291 break;
292 if (ktime_compare(ktime_get(), timeout) > 0) {
293 pci_read_config_dword(pdev, mmPCI_CONFIG_ELBI_STS,
294 &val);
295 break;
296 }
297 usleep_range(300, 500);
298 }
299
300 if ((val & PCI_CONFIG_ELBI_STS_MASK) == PCI_CONFIG_ELBI_STS_DONE)
301 return 0;
302
303 if (val & PCI_CONFIG_ELBI_STS_ERR) {
304 dev_err(hdev->dev, "Error writing to ELBI\n");
305 return -EIO;
306 }
307
308 if (!(val & PCI_CONFIG_ELBI_STS_MASK)) {
309 dev_err(hdev->dev, "ELBI write didn't finish in time\n");
310 return -EIO;
311 }
312
313 dev_err(hdev->dev, "ELBI write has undefined bits in status\n");
314 return -EIO;
315}
316
317/*
318 * goya_iatu_write - iatu write routine
319 *
320 * @hdev: pointer to hl_device structure
321 *
322 */
323static int goya_iatu_write(struct hl_device *hdev, u32 addr, u32 data)
324{
325 u32 dbi_offset;
326 int rc;
327
328 dbi_offset = addr & 0xFFF;
329
330 rc = goya_elbi_write(hdev, CFG_BASE + mmPCIE_AUX_DBI, 0x00300000);
331 rc |= goya_elbi_write(hdev, mmPCIE_DBI_BASE + dbi_offset, data);
332
333 if (rc)
334 return -EIO;
335
336 return 0;
337}
338
339void goya_reset_link_through_bridge(struct hl_device *hdev)
340{
341 struct pci_dev *pdev = hdev->pdev;
342 struct pci_dev *parent_port;
343 u16 val;
344
345 parent_port = pdev->bus->self;
346 pci_read_config_word(parent_port, PCI_BRIDGE_CONTROL, &val);
347 val |= PCI_BRIDGE_CTL_BUS_RESET;
348 pci_write_config_word(parent_port, PCI_BRIDGE_CONTROL, val);
349 ssleep(1);
350
351 val &= ~(PCI_BRIDGE_CTL_BUS_RESET);
352 pci_write_config_word(parent_port, PCI_BRIDGE_CONTROL, val);
353 ssleep(3);
354}
355
356/*
357 * goya_set_ddr_bar_base - set DDR bar to map specific device address
358 *
359 * @hdev: pointer to hl_device structure
360 * @addr: address in DDR. Must be aligned to DDR bar size
361 *
362 * This function configures the iATU so that the DDR bar will start at the
363 * specified addr.
364 *
365 */
366static int goya_set_ddr_bar_base(struct hl_device *hdev, u64 addr)
367{
368 struct goya_device *goya = hdev->asic_specific;
369 int rc;
370
371 if ((goya) && (goya->ddr_bar_cur_addr == addr))
372 return 0;
373
374 /* Inbound Region 1 - Bar 4 - Point to DDR */
375 rc = goya_iatu_write(hdev, 0x314, lower_32_bits(addr));
376 rc |= goya_iatu_write(hdev, 0x318, upper_32_bits(addr));
377 rc |= goya_iatu_write(hdev, 0x300, 0);
378 /* Enable + Bar match + match enable + Bar 4 */
379 rc |= goya_iatu_write(hdev, 0x304, 0xC0080400);
380
381 /* Return the DBI window to the default location */
382 rc |= goya_elbi_write(hdev, CFG_BASE + mmPCIE_AUX_DBI, 0);
383 rc |= goya_elbi_write(hdev, CFG_BASE + mmPCIE_AUX_DBI_32, 0);
384
385 if (rc) {
386 dev_err(hdev->dev, "failed to map DDR bar to 0x%08llx\n", addr);
387 return -EIO;
388 }
389
390 if (goya)
391 goya->ddr_bar_cur_addr = addr;
392
393 return 0;
394}
395
396/*
397 * goya_init_iatu - Initialize the iATU unit inside the PCI controller
398 *
399 * @hdev: pointer to hl_device structure
400 *
401 * This is needed in case the firmware doesn't initialize the iATU
402 *
403 */
404static int goya_init_iatu(struct hl_device *hdev)
405{
406 int rc;
407
408 /* Inbound Region 0 - Bar 0 - Point to SRAM_BASE_ADDR */
409 rc = goya_iatu_write(hdev, 0x114, lower_32_bits(SRAM_BASE_ADDR));
410 rc |= goya_iatu_write(hdev, 0x118, upper_32_bits(SRAM_BASE_ADDR));
411 rc |= goya_iatu_write(hdev, 0x100, 0);
412 /* Enable + Bar match + match enable */
413 rc |= goya_iatu_write(hdev, 0x104, 0xC0080000);
414
415 /* Inbound Region 1 - Bar 4 - Point to DDR */
416 rc |= goya_set_ddr_bar_base(hdev, DRAM_PHYS_BASE);
417
418 /* Outbound Region 0 - Point to Host */
419 rc |= goya_iatu_write(hdev, 0x008, lower_32_bits(HOST_PHYS_BASE));
420 rc |= goya_iatu_write(hdev, 0x00C, upper_32_bits(HOST_PHYS_BASE));
421 rc |= goya_iatu_write(hdev, 0x010,
422 lower_32_bits(HOST_PHYS_BASE + HOST_PHYS_SIZE - 1));
423 rc |= goya_iatu_write(hdev, 0x014, 0);
424 rc |= goya_iatu_write(hdev, 0x018, 0);
425 rc |= goya_iatu_write(hdev, 0x020,
426 upper_32_bits(HOST_PHYS_BASE + HOST_PHYS_SIZE - 1));
427 /* Increase region size */
428 rc |= goya_iatu_write(hdev, 0x000, 0x00002000);
429 /* Enable */
430 rc |= goya_iatu_write(hdev, 0x004, 0x80000000);
431
432 /* Return the DBI window to the default location */
433 rc |= goya_elbi_write(hdev, CFG_BASE + mmPCIE_AUX_DBI, 0);
434 rc |= goya_elbi_write(hdev, CFG_BASE + mmPCIE_AUX_DBI_32, 0);
435
436 if (rc)
437 return -EIO;
438
439 return 0;
440}
441
442/*
443 * goya_early_init - GOYA early initialization code
444 *
445 * @hdev: pointer to hl_device structure
446 *
447 * Verify PCI bars
448 * Set DMA masks
449 * PCI controller initialization
450 * Map PCI bars
451 *
452 */
453static int goya_early_init(struct hl_device *hdev)
454{
455 struct asic_fixed_properties *prop = &hdev->asic_prop;
456 struct pci_dev *pdev = hdev->pdev;
457 u32 val;
458 int rc;
459
460 goya_get_fixed_properties(hdev);
461
462 /* Check BAR sizes */
463 if (pci_resource_len(pdev, SRAM_CFG_BAR_ID) != CFG_BAR_SIZE) {
464 dev_err(hdev->dev,
465 "Not " HL_NAME "? BAR %d size %llu, expecting %llu\n",
466 SRAM_CFG_BAR_ID,
467 (unsigned long long) pci_resource_len(pdev,
468 SRAM_CFG_BAR_ID),
469 CFG_BAR_SIZE);
470 return -ENODEV;
471 }
472
473 if (pci_resource_len(pdev, MSIX_BAR_ID) != MSIX_BAR_SIZE) {
474 dev_err(hdev->dev,
475 "Not " HL_NAME "? BAR %d size %llu, expecting %llu\n",
476 MSIX_BAR_ID,
477 (unsigned long long) pci_resource_len(pdev,
478 MSIX_BAR_ID),
479 MSIX_BAR_SIZE);
480 return -ENODEV;
481 }
482
483 prop->dram_pci_bar_size = pci_resource_len(pdev, DDR_BAR_ID);
484
485 /* set DMA mask for GOYA */
486 rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(39));
487 if (rc) {
488 dev_warn(hdev->dev, "Unable to set pci dma mask to 39 bits\n");
489 rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
490 if (rc) {
491 dev_err(hdev->dev,
492 "Unable to set pci dma mask to 32 bits\n");
493 return rc;
494 }
495 }
496
497 rc = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(39));
498 if (rc) {
499 dev_warn(hdev->dev,
500 "Unable to set pci consistent dma mask to 39 bits\n");
501 rc = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
502 if (rc) {
503 dev_err(hdev->dev,
504 "Unable to set pci consistent dma mask to 32 bits\n");
505 return rc;
506 }
507 }
508
509 if (hdev->reset_pcilink)
510 goya_reset_link_through_bridge(hdev);
511
512 rc = pci_enable_device_mem(pdev);
513 if (rc) {
514 dev_err(hdev->dev, "can't enable PCI device\n");
515 return rc;
516 }
517
518 pci_set_master(pdev);
519
520 rc = goya_init_iatu(hdev);
521 if (rc) {
522 dev_err(hdev->dev, "Failed to initialize iATU\n");
523 goto disable_device;
524 }
525
526 rc = goya_pci_bars_map(hdev);
527 if (rc) {
528 dev_err(hdev->dev, "Failed to initialize PCI BARS\n");
529 goto disable_device;
530 }
531
Oded Gabbay839c4802019-02-16 00:39:16 +0200532 if (!hdev->pldm) {
533 val = RREG32(mmPSOC_GLOBAL_CONF_BOOT_STRAP_PINS);
534 if (val & PSOC_GLOBAL_CONF_BOOT_STRAP_PINS_SRIOV_EN_MASK)
535 dev_warn(hdev->dev,
536 "PCI strap is not configured correctly, PCI bus errors may occur\n");
537 }
Oded Gabbay99b9d7b2019-02-16 00:39:13 +0200538
539 return 0;
540
541disable_device:
542 pci_clear_master(pdev);
543 pci_disable_device(pdev);
544
545 return rc;
546}
547
548/*
549 * goya_early_fini - GOYA early finalization code
550 *
551 * @hdev: pointer to hl_device structure
552 *
553 * Unmap PCI bars
554 *
555 */
556int goya_early_fini(struct hl_device *hdev)
557{
558 goya_pci_bars_unmap(hdev);
559
560 pci_clear_master(hdev->pdev);
561 pci_disable_device(hdev->pdev);
562
563 return 0;
564}
565
566/*
Oded Gabbayd91389b2019-02-16 00:39:19 +0200567 * goya_fetch_psoc_frequency - Fetch PSOC frequency values
568 *
569 * @hdev: pointer to hl_device structure
570 *
571 */
572static void goya_fetch_psoc_frequency(struct hl_device *hdev)
573{
574 struct asic_fixed_properties *prop = &hdev->asic_prop;
575
576 prop->psoc_pci_pll_nr = RREG32(mmPSOC_PCI_PLL_NR);
577 prop->psoc_pci_pll_nf = RREG32(mmPSOC_PCI_PLL_NF);
578 prop->psoc_pci_pll_od = RREG32(mmPSOC_PCI_PLL_OD);
579 prop->psoc_pci_pll_div_factor = RREG32(mmPSOC_PCI_PLL_DIV_FACTOR_1);
580}
581
582/*
583 * goya_late_init - GOYA late initialization code
584 *
585 * @hdev: pointer to hl_device structure
586 *
587 * Get ArmCP info and send message to CPU to enable PCI access
588 */
589static int goya_late_init(struct hl_device *hdev)
590{
591 struct asic_fixed_properties *prop = &hdev->asic_prop;
592 struct goya_device *goya = hdev->asic_specific;
593 int rc;
594
595 rc = goya->armcp_info_get(hdev);
596 if (rc) {
597 dev_err(hdev->dev, "Failed to get armcp info\n");
598 return rc;
599 }
600
601 /* Now that we have the DRAM size in ASIC prop, we need to check
602 * its size and configure the DMA_IF DDR wrap protection (which is in
603 * the MMU block) accordingly. The value is the log2 of the DRAM size
604 */
605 WREG32(mmMMU_LOG2_DDR_SIZE, ilog2(prop->dram_size));
606
607 rc = goya_send_pci_access_msg(hdev, ARMCP_PACKET_ENABLE_PCI_ACCESS);
608 if (rc) {
609 dev_err(hdev->dev, "Failed to enable PCI access from CPU\n");
610 return rc;
611 }
612
613 WREG32(mmGIC_DISTRIBUTOR__5_GICD_SETSPI_NSR,
614 GOYA_ASYNC_EVENT_ID_INTS_REGISTER);
615
616 goya_fetch_psoc_frequency(hdev);
617
618 return 0;
619}
620
621/*
622 * goya_late_fini - GOYA late tear-down code
623 *
624 * @hdev: pointer to hl_device structure
625 *
626 * Free sensors allocated structures
627 */
628void goya_late_fini(struct hl_device *hdev)
629{
630 const struct hwmon_channel_info **channel_info_arr;
631 int i = 0;
632
633 if (!hdev->hl_chip_info->info)
634 return;
635
636 channel_info_arr = hdev->hl_chip_info->info;
637
638 while (channel_info_arr[i]) {
639 kfree(channel_info_arr[i]->config);
640 kfree(channel_info_arr[i]);
641 i++;
642 }
643
644 kfree(channel_info_arr);
645
646 hdev->hl_chip_info->info = NULL;
647}
648
649/*
Oded Gabbay99b9d7b2019-02-16 00:39:13 +0200650 * goya_sw_init - Goya software initialization code
651 *
652 * @hdev: pointer to hl_device structure
653 *
654 */
655static int goya_sw_init(struct hl_device *hdev)
656{
657 struct goya_device *goya;
658 int rc;
659
660 /* Allocate device structure */
661 goya = kzalloc(sizeof(*goya), GFP_KERNEL);
662 if (!goya)
663 return -ENOMEM;
664
Oded Gabbay9494a8d2019-02-16 00:39:17 +0200665 goya->test_cpu_queue = goya_test_cpu_queue;
Oded Gabbayd91389b2019-02-16 00:39:19 +0200666 goya->armcp_info_get = goya_armcp_info_get;
Oded Gabbay9494a8d2019-02-16 00:39:17 +0200667
Oded Gabbay99b9d7b2019-02-16 00:39:13 +0200668 /* according to goya_init_iatu */
669 goya->ddr_bar_cur_addr = DRAM_PHYS_BASE;
Oded Gabbayd91389b2019-02-16 00:39:19 +0200670
671 goya->mme_clk = GOYA_PLL_FREQ_LOW;
672 goya->tpc_clk = GOYA_PLL_FREQ_LOW;
673 goya->ic_clk = GOYA_PLL_FREQ_LOW;
674
Oded Gabbay99b9d7b2019-02-16 00:39:13 +0200675 hdev->asic_specific = goya;
676
677 /* Create DMA pool for small allocations */
678 hdev->dma_pool = dma_pool_create(dev_name(hdev->dev),
679 &hdev->pdev->dev, GOYA_DMA_POOL_BLK_SIZE, 8, 0);
680 if (!hdev->dma_pool) {
681 dev_err(hdev->dev, "failed to create DMA pool\n");
682 rc = -ENOMEM;
683 goto free_goya_device;
684 }
685
686 hdev->cpu_accessible_dma_mem =
687 hdev->asic_funcs->dma_alloc_coherent(hdev,
688 CPU_ACCESSIBLE_MEM_SIZE,
689 &hdev->cpu_accessible_dma_address,
690 GFP_KERNEL | __GFP_ZERO);
691
692 if (!hdev->cpu_accessible_dma_mem) {
693 dev_err(hdev->dev,
694 "failed to allocate %d of dma memory for CPU accessible memory space\n",
695 CPU_ACCESSIBLE_MEM_SIZE);
696 rc = -ENOMEM;
697 goto free_dma_pool;
698 }
699
700 hdev->cpu_accessible_dma_pool = gen_pool_create(CPU_PKT_SHIFT, -1);
701 if (!hdev->cpu_accessible_dma_pool) {
702 dev_err(hdev->dev,
703 "Failed to create CPU accessible DMA pool\n");
704 rc = -ENOMEM;
705 goto free_cpu_pq_dma_mem;
706 }
707
708 rc = gen_pool_add(hdev->cpu_accessible_dma_pool,
709 (uintptr_t) hdev->cpu_accessible_dma_mem,
710 CPU_ACCESSIBLE_MEM_SIZE, -1);
711 if (rc) {
712 dev_err(hdev->dev,
713 "Failed to add memory to CPU accessible DMA pool\n");
714 rc = -EFAULT;
715 goto free_cpu_pq_pool;
716 }
717
718 spin_lock_init(&goya->hw_queues_lock);
719
720 return 0;
721
722free_cpu_pq_pool:
723 gen_pool_destroy(hdev->cpu_accessible_dma_pool);
724free_cpu_pq_dma_mem:
725 hdev->asic_funcs->dma_free_coherent(hdev, CPU_ACCESSIBLE_MEM_SIZE,
726 hdev->cpu_accessible_dma_mem,
727 hdev->cpu_accessible_dma_address);
728free_dma_pool:
729 dma_pool_destroy(hdev->dma_pool);
730free_goya_device:
731 kfree(goya);
732
733 return rc;
734}
735
736/*
737 * goya_sw_fini - Goya software tear-down code
738 *
739 * @hdev: pointer to hl_device structure
740 *
741 */
742int goya_sw_fini(struct hl_device *hdev)
743{
744 struct goya_device *goya = hdev->asic_specific;
745
746 gen_pool_destroy(hdev->cpu_accessible_dma_pool);
747
748 hdev->asic_funcs->dma_free_coherent(hdev, CPU_ACCESSIBLE_MEM_SIZE,
749 hdev->cpu_accessible_dma_mem,
750 hdev->cpu_accessible_dma_address);
751
752 dma_pool_destroy(hdev->dma_pool);
753
754 kfree(goya);
755
756 return 0;
757}
758
Oded Gabbay9494a8d2019-02-16 00:39:17 +0200759static void goya_init_dma_qman(struct hl_device *hdev, int dma_id,
760 dma_addr_t bus_address)
761{
762 struct goya_device *goya = hdev->asic_specific;
763 u32 mtr_base_lo, mtr_base_hi;
764 u32 so_base_lo, so_base_hi;
765 u32 gic_base_lo, gic_base_hi;
766 u32 reg_off = dma_id * (mmDMA_QM_1_PQ_PI - mmDMA_QM_0_PQ_PI);
767
768 mtr_base_lo = lower_32_bits(CFG_BASE + mmSYNC_MNGR_MON_PAY_ADDRL_0);
769 mtr_base_hi = upper_32_bits(CFG_BASE + mmSYNC_MNGR_MON_PAY_ADDRL_0);
770 so_base_lo = lower_32_bits(CFG_BASE + mmSYNC_MNGR_SOB_OBJ_0);
771 so_base_hi = upper_32_bits(CFG_BASE + mmSYNC_MNGR_SOB_OBJ_0);
772
773 gic_base_lo =
774 lower_32_bits(CFG_BASE + mmGIC_DISTRIBUTOR__5_GICD_SETSPI_NSR);
775 gic_base_hi =
776 upper_32_bits(CFG_BASE + mmGIC_DISTRIBUTOR__5_GICD_SETSPI_NSR);
777
778 WREG32(mmDMA_QM_0_PQ_BASE_LO + reg_off, lower_32_bits(bus_address));
779 WREG32(mmDMA_QM_0_PQ_BASE_HI + reg_off, upper_32_bits(bus_address));
780
781 WREG32(mmDMA_QM_0_PQ_SIZE + reg_off, ilog2(HL_QUEUE_LENGTH));
782 WREG32(mmDMA_QM_0_PQ_PI + reg_off, 0);
783 WREG32(mmDMA_QM_0_PQ_CI + reg_off, 0);
784
785 WREG32(mmDMA_QM_0_CP_MSG_BASE0_ADDR_LO + reg_off, mtr_base_lo);
786 WREG32(mmDMA_QM_0_CP_MSG_BASE0_ADDR_HI + reg_off, mtr_base_hi);
787 WREG32(mmDMA_QM_0_CP_MSG_BASE1_ADDR_LO + reg_off, so_base_lo);
788 WREG32(mmDMA_QM_0_CP_MSG_BASE1_ADDR_HI + reg_off, so_base_hi);
789 WREG32(mmDMA_QM_0_GLBL_ERR_ADDR_LO + reg_off, gic_base_lo);
790 WREG32(mmDMA_QM_0_GLBL_ERR_ADDR_HI + reg_off, gic_base_hi);
791 WREG32(mmDMA_QM_0_GLBL_ERR_WDATA + reg_off,
792 GOYA_ASYNC_EVENT_ID_DMA0_QM + dma_id);
793
794 /* PQ has buffer of 2 cache lines, while CQ has 8 lines */
795 WREG32(mmDMA_QM_0_PQ_CFG1 + reg_off, 0x00020002);
796 WREG32(mmDMA_QM_0_CQ_CFG1 + reg_off, 0x00080008);
797
Oded Gabbay1251f232019-02-16 00:39:18 +0200798 if (goya->hw_cap_initialized & HW_CAP_MMU)
799 WREG32(mmDMA_QM_0_GLBL_PROT + reg_off, QMAN_DMA_PARTLY_TRUSTED);
Oded Gabbay9494a8d2019-02-16 00:39:17 +0200800 else
Oded Gabbay1251f232019-02-16 00:39:18 +0200801 WREG32(mmDMA_QM_0_GLBL_PROT + reg_off, QMAN_DMA_FULLY_TRUSTED);
Oded Gabbay9494a8d2019-02-16 00:39:17 +0200802
803 WREG32(mmDMA_QM_0_GLBL_ERR_CFG + reg_off, QMAN_DMA_ERR_MSG_EN);
804 WREG32(mmDMA_QM_0_GLBL_CFG0 + reg_off, QMAN_DMA_ENABLE);
805}
806
807static void goya_init_dma_ch(struct hl_device *hdev, int dma_id)
808{
809 u32 gic_base_lo, gic_base_hi;
810 u64 sob_addr;
811 u32 reg_off = dma_id * (mmDMA_CH_1_CFG1 - mmDMA_CH_0_CFG1);
812
813 gic_base_lo =
814 lower_32_bits(CFG_BASE + mmGIC_DISTRIBUTOR__5_GICD_SETSPI_NSR);
815 gic_base_hi =
816 upper_32_bits(CFG_BASE + mmGIC_DISTRIBUTOR__5_GICD_SETSPI_NSR);
817
818 WREG32(mmDMA_CH_0_ERRMSG_ADDR_LO + reg_off, gic_base_lo);
819 WREG32(mmDMA_CH_0_ERRMSG_ADDR_HI + reg_off, gic_base_hi);
820 WREG32(mmDMA_CH_0_ERRMSG_WDATA + reg_off,
821 GOYA_ASYNC_EVENT_ID_DMA0_CH + dma_id);
822
823 if (dma_id) {
824 sob_addr = CFG_BASE + mmSYNC_MNGR_SOB_OBJ_1000 +
825 (dma_id - 1) * 4;
826 WREG32(mmDMA_CH_0_WR_COMP_ADDR_LO + reg_off,
827 lower_32_bits(sob_addr));
828 WREG32(mmDMA_CH_0_WR_COMP_ADDR_HI + reg_off,
829 upper_32_bits(sob_addr));
830 WREG32(mmDMA_CH_0_WR_COMP_WDATA + reg_off, 0x80000001);
831 }
832}
833
834/*
835 * goya_init_dma_qmans - Initialize QMAN DMA registers
836 *
837 * @hdev: pointer to hl_device structure
838 *
839 * Initialize the H/W registers of the QMAN DMA channels
840 *
841 */
842static void goya_init_dma_qmans(struct hl_device *hdev)
843{
844 struct goya_device *goya = hdev->asic_specific;
845 struct hl_hw_queue *q;
846 dma_addr_t bus_address;
847 int i;
848
849 if (goya->hw_cap_initialized & HW_CAP_DMA)
850 return;
851
852 q = &hdev->kernel_queues[0];
853
854 for (i = 0 ; i < NUMBER_OF_EXT_HW_QUEUES ; i++, q++) {
855 bus_address = q->bus_address +
856 hdev->asic_prop.host_phys_base_address;
857
858 goya_init_dma_qman(hdev, i, bus_address);
859 goya_init_dma_ch(hdev, i);
860 }
861
862 goya->hw_cap_initialized |= HW_CAP_DMA;
863}
864
865/*
866 * goya_disable_external_queues - Disable external queues
867 *
868 * @hdev: pointer to hl_device structure
869 *
870 */
871static void goya_disable_external_queues(struct hl_device *hdev)
872{
873 WREG32(mmDMA_QM_0_GLBL_CFG0, 0);
874 WREG32(mmDMA_QM_1_GLBL_CFG0, 0);
875 WREG32(mmDMA_QM_2_GLBL_CFG0, 0);
876 WREG32(mmDMA_QM_3_GLBL_CFG0, 0);
877 WREG32(mmDMA_QM_4_GLBL_CFG0, 0);
878}
879
880static int goya_stop_queue(struct hl_device *hdev, u32 cfg_reg,
881 u32 cp_sts_reg, u32 glbl_sts0_reg)
882{
883 int rc;
884 u32 status;
885
886 /* use the values of TPC0 as they are all the same*/
887
888 WREG32(cfg_reg, 1 << TPC0_QM_GLBL_CFG1_CP_STOP_SHIFT);
889
890 status = RREG32(cp_sts_reg);
891 if (status & TPC0_QM_CP_STS_FENCE_IN_PROGRESS_MASK) {
892 rc = hl_poll_timeout(
893 hdev,
894 cp_sts_reg,
895 status,
896 !(status & TPC0_QM_CP_STS_FENCE_IN_PROGRESS_MASK),
897 1000,
898 QMAN_FENCE_TIMEOUT_USEC);
899
900 /* if QMAN is stuck in fence no need to check for stop */
901 if (rc)
902 return 0;
903 }
904
905 rc = hl_poll_timeout(
906 hdev,
907 glbl_sts0_reg,
908 status,
909 (status & TPC0_QM_GLBL_STS0_CP_IS_STOP_MASK),
910 1000,
911 QMAN_STOP_TIMEOUT_USEC);
912
913 if (rc) {
914 dev_err(hdev->dev,
915 "Timeout while waiting for QMAN to stop\n");
916 return -EINVAL;
917 }
918
919 return 0;
920}
921
922/*
923 * goya_stop_external_queues - Stop external queues
924 *
925 * @hdev: pointer to hl_device structure
926 *
927 * Returns 0 on success
928 *
929 */
930static int goya_stop_external_queues(struct hl_device *hdev)
931{
932 int rc, retval = 0;
933
934 rc = goya_stop_queue(hdev,
935 mmDMA_QM_0_GLBL_CFG1,
936 mmDMA_QM_0_CP_STS,
937 mmDMA_QM_0_GLBL_STS0);
938
939 if (rc) {
940 dev_err(hdev->dev, "failed to stop DMA QMAN 0\n");
941 retval = -EIO;
942 }
943
944 rc = goya_stop_queue(hdev,
945 mmDMA_QM_1_GLBL_CFG1,
946 mmDMA_QM_1_CP_STS,
947 mmDMA_QM_1_GLBL_STS0);
948
949 if (rc) {
950 dev_err(hdev->dev, "failed to stop DMA QMAN 1\n");
951 retval = -EIO;
952 }
953
954 rc = goya_stop_queue(hdev,
955 mmDMA_QM_2_GLBL_CFG1,
956 mmDMA_QM_2_CP_STS,
957 mmDMA_QM_2_GLBL_STS0);
958
959 if (rc) {
960 dev_err(hdev->dev, "failed to stop DMA QMAN 2\n");
961 retval = -EIO;
962 }
963
964 rc = goya_stop_queue(hdev,
965 mmDMA_QM_3_GLBL_CFG1,
966 mmDMA_QM_3_CP_STS,
967 mmDMA_QM_3_GLBL_STS0);
968
969 if (rc) {
970 dev_err(hdev->dev, "failed to stop DMA QMAN 3\n");
971 retval = -EIO;
972 }
973
974 rc = goya_stop_queue(hdev,
975 mmDMA_QM_4_GLBL_CFG1,
976 mmDMA_QM_4_CP_STS,
977 mmDMA_QM_4_GLBL_STS0);
978
979 if (rc) {
980 dev_err(hdev->dev, "failed to stop DMA QMAN 4\n");
981 retval = -EIO;
982 }
983
984 return retval;
985}
986
987static void goya_resume_external_queues(struct hl_device *hdev)
988{
989 WREG32(mmDMA_QM_0_GLBL_CFG1, 0);
990 WREG32(mmDMA_QM_1_GLBL_CFG1, 0);
991 WREG32(mmDMA_QM_2_GLBL_CFG1, 0);
992 WREG32(mmDMA_QM_3_GLBL_CFG1, 0);
993 WREG32(mmDMA_QM_4_GLBL_CFG1, 0);
994}
995
996/*
997 * goya_init_cpu_queues - Initialize PQ/CQ/EQ of CPU
998 *
999 * @hdev: pointer to hl_device structure
1000 *
1001 * Returns 0 on success
1002 *
1003 */
1004int goya_init_cpu_queues(struct hl_device *hdev)
1005{
1006 struct goya_device *goya = hdev->asic_specific;
Oded Gabbay1251f232019-02-16 00:39:18 +02001007 struct hl_eq *eq;
Oded Gabbay9494a8d2019-02-16 00:39:17 +02001008 dma_addr_t bus_address;
1009 u32 status;
1010 struct hl_hw_queue *cpu_pq = &hdev->kernel_queues[GOYA_QUEUE_ID_CPU_PQ];
1011 int err;
1012
1013 if (!hdev->cpu_queues_enable)
1014 return 0;
1015
1016 if (goya->hw_cap_initialized & HW_CAP_CPU_Q)
1017 return 0;
1018
Oded Gabbay1251f232019-02-16 00:39:18 +02001019 eq = &hdev->event_queue;
1020
Oded Gabbay9494a8d2019-02-16 00:39:17 +02001021 bus_address = cpu_pq->bus_address +
1022 hdev->asic_prop.host_phys_base_address;
1023 WREG32(mmPSOC_GLOBAL_CONF_SCRATCHPAD_0, lower_32_bits(bus_address));
1024 WREG32(mmPSOC_GLOBAL_CONF_SCRATCHPAD_1, upper_32_bits(bus_address));
1025
Oded Gabbay1251f232019-02-16 00:39:18 +02001026 bus_address = eq->bus_address + hdev->asic_prop.host_phys_base_address;
1027 WREG32(mmPSOC_GLOBAL_CONF_SCRATCHPAD_2, lower_32_bits(bus_address));
1028 WREG32(mmPSOC_GLOBAL_CONF_SCRATCHPAD_3, upper_32_bits(bus_address));
1029
Oded Gabbay9494a8d2019-02-16 00:39:17 +02001030 bus_address = hdev->cpu_accessible_dma_address +
1031 hdev->asic_prop.host_phys_base_address;
1032 WREG32(mmPSOC_GLOBAL_CONF_SCRATCHPAD_8, lower_32_bits(bus_address));
1033 WREG32(mmPSOC_GLOBAL_CONF_SCRATCHPAD_9, upper_32_bits(bus_address));
1034
1035 WREG32(mmPSOC_GLOBAL_CONF_SCRATCHPAD_5, HL_QUEUE_SIZE_IN_BYTES);
Oded Gabbay1251f232019-02-16 00:39:18 +02001036 WREG32(mmPSOC_GLOBAL_CONF_SCRATCHPAD_4, HL_EQ_SIZE_IN_BYTES);
Oded Gabbay9494a8d2019-02-16 00:39:17 +02001037 WREG32(mmPSOC_GLOBAL_CONF_SCRATCHPAD_10, CPU_ACCESSIBLE_MEM_SIZE);
1038
1039 /* Used for EQ CI */
1040 WREG32(mmPSOC_GLOBAL_CONF_SCRATCHPAD_6, 0);
1041
1042 WREG32(mmCPU_IF_PF_PQ_PI, 0);
1043
1044 WREG32(mmPSOC_GLOBAL_CONF_SCRATCHPAD_7, PQ_INIT_STATUS_READY_FOR_CP);
1045
1046 WREG32(mmGIC_DISTRIBUTOR__5_GICD_SETSPI_NSR,
1047 GOYA_ASYNC_EVENT_ID_PI_UPDATE);
1048
1049 err = hl_poll_timeout(
1050 hdev,
1051 mmPSOC_GLOBAL_CONF_SCRATCHPAD_7,
1052 status,
1053 (status == PQ_INIT_STATUS_READY_FOR_HOST),
1054 1000,
1055 GOYA_CPU_TIMEOUT_USEC);
1056
1057 if (err) {
1058 dev_err(hdev->dev,
1059 "Failed to communicate with ARM CPU (ArmCP timeout)\n");
1060 return -EIO;
1061 }
1062
1063 goya->hw_cap_initialized |= HW_CAP_CPU_Q;
1064 return 0;
1065}
1066
Oded Gabbay839c4802019-02-16 00:39:16 +02001067static void goya_set_pll_refclk(struct hl_device *hdev)
1068{
1069 WREG32(mmCPU_PLL_DIV_SEL_0, 0x0);
1070 WREG32(mmCPU_PLL_DIV_SEL_1, 0x0);
1071 WREG32(mmCPU_PLL_DIV_SEL_2, 0x0);
1072 WREG32(mmCPU_PLL_DIV_SEL_3, 0x0);
1073
1074 WREG32(mmIC_PLL_DIV_SEL_0, 0x0);
1075 WREG32(mmIC_PLL_DIV_SEL_1, 0x0);
1076 WREG32(mmIC_PLL_DIV_SEL_2, 0x0);
1077 WREG32(mmIC_PLL_DIV_SEL_3, 0x0);
1078
1079 WREG32(mmMC_PLL_DIV_SEL_0, 0x0);
1080 WREG32(mmMC_PLL_DIV_SEL_1, 0x0);
1081 WREG32(mmMC_PLL_DIV_SEL_2, 0x0);
1082 WREG32(mmMC_PLL_DIV_SEL_3, 0x0);
1083
1084 WREG32(mmPSOC_MME_PLL_DIV_SEL_0, 0x0);
1085 WREG32(mmPSOC_MME_PLL_DIV_SEL_1, 0x0);
1086 WREG32(mmPSOC_MME_PLL_DIV_SEL_2, 0x0);
1087 WREG32(mmPSOC_MME_PLL_DIV_SEL_3, 0x0);
1088
1089 WREG32(mmPSOC_PCI_PLL_DIV_SEL_0, 0x0);
1090 WREG32(mmPSOC_PCI_PLL_DIV_SEL_1, 0x0);
1091 WREG32(mmPSOC_PCI_PLL_DIV_SEL_2, 0x0);
1092 WREG32(mmPSOC_PCI_PLL_DIV_SEL_3, 0x0);
1093
1094 WREG32(mmPSOC_EMMC_PLL_DIV_SEL_0, 0x0);
1095 WREG32(mmPSOC_EMMC_PLL_DIV_SEL_1, 0x0);
1096 WREG32(mmPSOC_EMMC_PLL_DIV_SEL_2, 0x0);
1097 WREG32(mmPSOC_EMMC_PLL_DIV_SEL_3, 0x0);
1098
1099 WREG32(mmTPC_PLL_DIV_SEL_0, 0x0);
1100 WREG32(mmTPC_PLL_DIV_SEL_1, 0x0);
1101 WREG32(mmTPC_PLL_DIV_SEL_2, 0x0);
1102 WREG32(mmTPC_PLL_DIV_SEL_3, 0x0);
1103}
1104
1105static void goya_disable_clk_rlx(struct hl_device *hdev)
1106{
1107 WREG32(mmPSOC_MME_PLL_CLK_RLX_0, 0x100010);
1108 WREG32(mmIC_PLL_CLK_RLX_0, 0x100010);
1109}
1110
1111static void _goya_tpc_mbist_workaround(struct hl_device *hdev, u8 tpc_id)
1112{
1113 u64 tpc_eml_address;
1114 u32 val, tpc_offset, tpc_eml_offset, tpc_slm_offset;
1115 int err, slm_index;
1116
1117 tpc_offset = tpc_id * 0x40000;
1118 tpc_eml_offset = tpc_id * 0x200000;
1119 tpc_eml_address = (mmTPC0_EML_CFG_BASE + tpc_eml_offset - CFG_BASE);
1120 tpc_slm_offset = tpc_eml_address + 0x100000;
1121
1122 /*
1123 * Workaround for Bug H2 #2443 :
1124 * "TPC SB is not initialized on chip reset"
1125 */
1126
1127 val = RREG32(mmTPC0_CFG_FUNC_MBIST_CNTRL + tpc_offset);
1128 if (val & TPC0_CFG_FUNC_MBIST_CNTRL_MBIST_ACTIVE_MASK)
1129 dev_warn(hdev->dev, "TPC%d MBIST ACTIVE is not cleared\n",
1130 tpc_id);
1131
1132 WREG32(mmTPC0_CFG_FUNC_MBIST_PAT + tpc_offset, val & 0xFFFFF000);
1133
1134 WREG32(mmTPC0_CFG_FUNC_MBIST_MEM_0 + tpc_offset, 0x37FF);
1135 WREG32(mmTPC0_CFG_FUNC_MBIST_MEM_1 + tpc_offset, 0x303F);
1136 WREG32(mmTPC0_CFG_FUNC_MBIST_MEM_2 + tpc_offset, 0x71FF);
1137 WREG32(mmTPC0_CFG_FUNC_MBIST_MEM_3 + tpc_offset, 0x71FF);
1138 WREG32(mmTPC0_CFG_FUNC_MBIST_MEM_4 + tpc_offset, 0x70FF);
1139 WREG32(mmTPC0_CFG_FUNC_MBIST_MEM_5 + tpc_offset, 0x70FF);
1140 WREG32(mmTPC0_CFG_FUNC_MBIST_MEM_6 + tpc_offset, 0x70FF);
1141 WREG32(mmTPC0_CFG_FUNC_MBIST_MEM_7 + tpc_offset, 0x70FF);
1142 WREG32(mmTPC0_CFG_FUNC_MBIST_MEM_8 + tpc_offset, 0x70FF);
1143 WREG32(mmTPC0_CFG_FUNC_MBIST_MEM_9 + tpc_offset, 0x70FF);
1144
1145 WREG32_OR(mmTPC0_CFG_FUNC_MBIST_CNTRL + tpc_offset,
1146 1 << TPC0_CFG_FUNC_MBIST_CNTRL_MBIST_START_SHIFT);
1147
1148 err = hl_poll_timeout(
1149 hdev,
1150 mmTPC0_CFG_FUNC_MBIST_CNTRL + tpc_offset,
1151 val,
1152 (val & TPC0_CFG_FUNC_MBIST_CNTRL_MBIST_DONE_MASK),
1153 1000,
1154 HL_DEVICE_TIMEOUT_USEC);
1155
1156 if (err)
1157 dev_err(hdev->dev,
1158 "Timeout while waiting for TPC%d MBIST DONE\n", tpc_id);
1159
1160 WREG32_OR(mmTPC0_EML_CFG_DBG_CNT + tpc_eml_offset,
1161 1 << TPC0_EML_CFG_DBG_CNT_CORE_RST_SHIFT);
1162
1163 msleep(GOYA_RESET_WAIT_MSEC);
1164
1165 WREG32_AND(mmTPC0_EML_CFG_DBG_CNT + tpc_eml_offset,
1166 ~(1 << TPC0_EML_CFG_DBG_CNT_CORE_RST_SHIFT));
1167
1168 msleep(GOYA_RESET_WAIT_MSEC);
1169
1170 for (slm_index = 0 ; slm_index < 256 ; slm_index++)
1171 WREG32(tpc_slm_offset + (slm_index << 2), 0);
1172
1173 val = RREG32(tpc_slm_offset);
1174}
1175
1176static void goya_tpc_mbist_workaround(struct hl_device *hdev)
1177{
1178 struct goya_device *goya = hdev->asic_specific;
1179 int i;
1180
1181 if (hdev->pldm)
1182 return;
1183
1184 if (goya->hw_cap_initialized & HW_CAP_TPC_MBIST)
1185 return;
1186
1187 /* Workaround for H2 #2443 */
1188
1189 for (i = 0 ; i < TPC_MAX_NUM ; i++)
1190 _goya_tpc_mbist_workaround(hdev, i);
1191
1192 goya->hw_cap_initialized |= HW_CAP_TPC_MBIST;
1193}
1194
1195/*
1196 * goya_init_golden_registers - Initialize golden registers
1197 *
1198 * @hdev: pointer to hl_device structure
1199 *
1200 * Initialize the H/W registers of the device
1201 *
1202 */
1203static void goya_init_golden_registers(struct hl_device *hdev)
1204{
1205 struct goya_device *goya = hdev->asic_specific;
1206 u32 polynom[10], tpc_intr_mask, offset;
1207 int i;
1208
1209 if (goya->hw_cap_initialized & HW_CAP_GOLDEN)
1210 return;
1211
1212 polynom[0] = 0x00020080;
1213 polynom[1] = 0x00401000;
1214 polynom[2] = 0x00200800;
1215 polynom[3] = 0x00002000;
1216 polynom[4] = 0x00080200;
1217 polynom[5] = 0x00040100;
1218 polynom[6] = 0x00100400;
1219 polynom[7] = 0x00004000;
1220 polynom[8] = 0x00010000;
1221 polynom[9] = 0x00008000;
1222
1223 /* Mask all arithmetic interrupts from TPC */
1224 tpc_intr_mask = 0x7FFF;
1225
1226 for (i = 0, offset = 0 ; i < 6 ; i++, offset += 0x20000) {
1227 WREG32(mmSRAM_Y0_X0_RTR_HBW_RD_RQ_L_ARB + offset, 0x302);
1228 WREG32(mmSRAM_Y0_X1_RTR_HBW_RD_RQ_L_ARB + offset, 0x302);
1229 WREG32(mmSRAM_Y0_X2_RTR_HBW_RD_RQ_L_ARB + offset, 0x302);
1230 WREG32(mmSRAM_Y0_X3_RTR_HBW_RD_RQ_L_ARB + offset, 0x302);
1231 WREG32(mmSRAM_Y0_X4_RTR_HBW_RD_RQ_L_ARB + offset, 0x302);
1232
1233 WREG32(mmSRAM_Y0_X0_RTR_HBW_DATA_L_ARB + offset, 0x204);
1234 WREG32(mmSRAM_Y0_X1_RTR_HBW_DATA_L_ARB + offset, 0x204);
1235 WREG32(mmSRAM_Y0_X2_RTR_HBW_DATA_L_ARB + offset, 0x204);
1236 WREG32(mmSRAM_Y0_X3_RTR_HBW_DATA_L_ARB + offset, 0x204);
1237 WREG32(mmSRAM_Y0_X4_RTR_HBW_DATA_L_ARB + offset, 0x204);
1238
1239
1240 WREG32(mmSRAM_Y0_X0_RTR_HBW_DATA_E_ARB + offset, 0x206);
1241 WREG32(mmSRAM_Y0_X1_RTR_HBW_DATA_E_ARB + offset, 0x206);
1242 WREG32(mmSRAM_Y0_X2_RTR_HBW_DATA_E_ARB + offset, 0x206);
1243 WREG32(mmSRAM_Y0_X3_RTR_HBW_DATA_E_ARB + offset, 0x207);
1244 WREG32(mmSRAM_Y0_X4_RTR_HBW_DATA_E_ARB + offset, 0x207);
1245
1246 WREG32(mmSRAM_Y0_X0_RTR_HBW_DATA_W_ARB + offset, 0x207);
1247 WREG32(mmSRAM_Y0_X1_RTR_HBW_DATA_W_ARB + offset, 0x207);
1248 WREG32(mmSRAM_Y0_X2_RTR_HBW_DATA_W_ARB + offset, 0x206);
1249 WREG32(mmSRAM_Y0_X3_RTR_HBW_DATA_W_ARB + offset, 0x206);
1250 WREG32(mmSRAM_Y0_X4_RTR_HBW_DATA_W_ARB + offset, 0x206);
1251
1252 WREG32(mmSRAM_Y0_X0_RTR_HBW_WR_RS_E_ARB + offset, 0x101);
1253 WREG32(mmSRAM_Y0_X1_RTR_HBW_WR_RS_E_ARB + offset, 0x102);
1254 WREG32(mmSRAM_Y0_X2_RTR_HBW_WR_RS_E_ARB + offset, 0x103);
1255 WREG32(mmSRAM_Y0_X3_RTR_HBW_WR_RS_E_ARB + offset, 0x104);
1256 WREG32(mmSRAM_Y0_X4_RTR_HBW_WR_RS_E_ARB + offset, 0x105);
1257
1258 WREG32(mmSRAM_Y0_X0_RTR_HBW_WR_RS_W_ARB + offset, 0x105);
1259 WREG32(mmSRAM_Y0_X1_RTR_HBW_WR_RS_W_ARB + offset, 0x104);
1260 WREG32(mmSRAM_Y0_X2_RTR_HBW_WR_RS_W_ARB + offset, 0x103);
1261 WREG32(mmSRAM_Y0_X3_RTR_HBW_WR_RS_W_ARB + offset, 0x102);
1262 WREG32(mmSRAM_Y0_X4_RTR_HBW_WR_RS_W_ARB + offset, 0x101);
1263 }
1264
1265 WREG32(mmMME_STORE_MAX_CREDIT, 0x21);
1266 WREG32(mmMME_AGU, 0x0f0f0f10);
1267 WREG32(mmMME_SEI_MASK, ~0x0);
1268
1269 WREG32(mmMME6_RTR_HBW_RD_RQ_N_ARB, 0x01010101);
1270 WREG32(mmMME5_RTR_HBW_RD_RQ_N_ARB, 0x01040101);
1271 WREG32(mmMME4_RTR_HBW_RD_RQ_N_ARB, 0x01030101);
1272 WREG32(mmMME3_RTR_HBW_RD_RQ_N_ARB, 0x01020101);
1273 WREG32(mmMME2_RTR_HBW_RD_RQ_N_ARB, 0x01010101);
1274 WREG32(mmMME1_RTR_HBW_RD_RQ_N_ARB, 0x07010701);
1275 WREG32(mmMME6_RTR_HBW_RD_RQ_S_ARB, 0x04010401);
1276 WREG32(mmMME5_RTR_HBW_RD_RQ_S_ARB, 0x04050401);
1277 WREG32(mmMME4_RTR_HBW_RD_RQ_S_ARB, 0x03070301);
1278 WREG32(mmMME3_RTR_HBW_RD_RQ_S_ARB, 0x01030101);
1279 WREG32(mmMME2_RTR_HBW_RD_RQ_S_ARB, 0x01040101);
1280 WREG32(mmMME1_RTR_HBW_RD_RQ_S_ARB, 0x01050105);
1281 WREG32(mmMME6_RTR_HBW_RD_RQ_W_ARB, 0x01010501);
1282 WREG32(mmMME5_RTR_HBW_RD_RQ_W_ARB, 0x01010501);
1283 WREG32(mmMME4_RTR_HBW_RD_RQ_W_ARB, 0x01040301);
1284 WREG32(mmMME3_RTR_HBW_RD_RQ_W_ARB, 0x01030401);
1285 WREG32(mmMME2_RTR_HBW_RD_RQ_W_ARB, 0x01040101);
1286 WREG32(mmMME1_RTR_HBW_RD_RQ_W_ARB, 0x01050101);
1287 WREG32(mmMME6_RTR_HBW_WR_RQ_N_ARB, 0x02020202);
1288 WREG32(mmMME5_RTR_HBW_WR_RQ_N_ARB, 0x01070101);
1289 WREG32(mmMME4_RTR_HBW_WR_RQ_N_ARB, 0x02020201);
1290 WREG32(mmMME3_RTR_HBW_WR_RQ_N_ARB, 0x07020701);
1291 WREG32(mmMME2_RTR_HBW_WR_RQ_N_ARB, 0x01020101);
1292 WREG32(mmMME1_RTR_HBW_WR_RQ_S_ARB, 0x01010101);
1293 WREG32(mmMME6_RTR_HBW_WR_RQ_S_ARB, 0x01070101);
1294 WREG32(mmMME5_RTR_HBW_WR_RQ_S_ARB, 0x01070101);
1295 WREG32(mmMME4_RTR_HBW_WR_RQ_S_ARB, 0x07020701);
1296 WREG32(mmMME3_RTR_HBW_WR_RQ_S_ARB, 0x02020201);
1297 WREG32(mmMME2_RTR_HBW_WR_RQ_S_ARB, 0x01070101);
1298 WREG32(mmMME1_RTR_HBW_WR_RQ_S_ARB, 0x01020102);
1299 WREG32(mmMME6_RTR_HBW_WR_RQ_W_ARB, 0x01020701);
1300 WREG32(mmMME5_RTR_HBW_WR_RQ_W_ARB, 0x01020701);
1301 WREG32(mmMME4_RTR_HBW_WR_RQ_W_ARB, 0x07020707);
1302 WREG32(mmMME3_RTR_HBW_WR_RQ_W_ARB, 0x01020201);
1303 WREG32(mmMME2_RTR_HBW_WR_RQ_W_ARB, 0x01070201);
1304 WREG32(mmMME1_RTR_HBW_WR_RQ_W_ARB, 0x01070201);
1305 WREG32(mmMME6_RTR_HBW_RD_RS_N_ARB, 0x01070102);
1306 WREG32(mmMME5_RTR_HBW_RD_RS_N_ARB, 0x01070102);
1307 WREG32(mmMME4_RTR_HBW_RD_RS_N_ARB, 0x01060102);
1308 WREG32(mmMME3_RTR_HBW_RD_RS_N_ARB, 0x01040102);
1309 WREG32(mmMME2_RTR_HBW_RD_RS_N_ARB, 0x01020102);
1310 WREG32(mmMME1_RTR_HBW_RD_RS_N_ARB, 0x01020107);
1311 WREG32(mmMME6_RTR_HBW_RD_RS_S_ARB, 0x01020106);
1312 WREG32(mmMME5_RTR_HBW_RD_RS_S_ARB, 0x01020102);
1313 WREG32(mmMME4_RTR_HBW_RD_RS_S_ARB, 0x01040102);
1314 WREG32(mmMME3_RTR_HBW_RD_RS_S_ARB, 0x01060102);
1315 WREG32(mmMME2_RTR_HBW_RD_RS_S_ARB, 0x01070102);
1316 WREG32(mmMME1_RTR_HBW_RD_RS_S_ARB, 0x01070102);
1317 WREG32(mmMME6_RTR_HBW_RD_RS_E_ARB, 0x01020702);
1318 WREG32(mmMME5_RTR_HBW_RD_RS_E_ARB, 0x01020702);
1319 WREG32(mmMME4_RTR_HBW_RD_RS_E_ARB, 0x01040602);
1320 WREG32(mmMME3_RTR_HBW_RD_RS_E_ARB, 0x01060402);
1321 WREG32(mmMME2_RTR_HBW_RD_RS_E_ARB, 0x01070202);
1322 WREG32(mmMME1_RTR_HBW_RD_RS_E_ARB, 0x01070102);
1323 WREG32(mmMME6_RTR_HBW_RD_RS_W_ARB, 0x01060401);
1324 WREG32(mmMME5_RTR_HBW_RD_RS_W_ARB, 0x01060401);
1325 WREG32(mmMME4_RTR_HBW_RD_RS_W_ARB, 0x01060401);
1326 WREG32(mmMME3_RTR_HBW_RD_RS_W_ARB, 0x01060401);
1327 WREG32(mmMME2_RTR_HBW_RD_RS_W_ARB, 0x01060401);
1328 WREG32(mmMME1_RTR_HBW_RD_RS_W_ARB, 0x01060401);
1329 WREG32(mmMME6_RTR_HBW_WR_RS_N_ARB, 0x01050101);
1330 WREG32(mmMME5_RTR_HBW_WR_RS_N_ARB, 0x01040101);
1331 WREG32(mmMME4_RTR_HBW_WR_RS_N_ARB, 0x01030101);
1332 WREG32(mmMME3_RTR_HBW_WR_RS_N_ARB, 0x01020101);
1333 WREG32(mmMME2_RTR_HBW_WR_RS_N_ARB, 0x01010101);
1334 WREG32(mmMME1_RTR_HBW_WR_RS_N_ARB, 0x01010107);
1335 WREG32(mmMME6_RTR_HBW_WR_RS_S_ARB, 0x01010107);
1336 WREG32(mmMME5_RTR_HBW_WR_RS_S_ARB, 0x01010101);
1337 WREG32(mmMME4_RTR_HBW_WR_RS_S_ARB, 0x01020101);
1338 WREG32(mmMME3_RTR_HBW_WR_RS_S_ARB, 0x01030101);
1339 WREG32(mmMME2_RTR_HBW_WR_RS_S_ARB, 0x01040101);
1340 WREG32(mmMME1_RTR_HBW_WR_RS_S_ARB, 0x01050101);
1341 WREG32(mmMME6_RTR_HBW_WR_RS_E_ARB, 0x01010501);
1342 WREG32(mmMME5_RTR_HBW_WR_RS_E_ARB, 0x01010501);
1343 WREG32(mmMME4_RTR_HBW_WR_RS_E_ARB, 0x01040301);
1344 WREG32(mmMME3_RTR_HBW_WR_RS_E_ARB, 0x01030401);
1345 WREG32(mmMME2_RTR_HBW_WR_RS_E_ARB, 0x01040101);
1346 WREG32(mmMME1_RTR_HBW_WR_RS_E_ARB, 0x01050101);
1347 WREG32(mmMME6_RTR_HBW_WR_RS_W_ARB, 0x01010101);
1348 WREG32(mmMME5_RTR_HBW_WR_RS_W_ARB, 0x01010101);
1349 WREG32(mmMME4_RTR_HBW_WR_RS_W_ARB, 0x01010101);
1350 WREG32(mmMME3_RTR_HBW_WR_RS_W_ARB, 0x01010101);
1351 WREG32(mmMME2_RTR_HBW_WR_RS_W_ARB, 0x01010101);
1352 WREG32(mmMME1_RTR_HBW_WR_RS_W_ARB, 0x01010101);
1353
1354 WREG32(mmTPC1_RTR_HBW_RD_RQ_N_ARB, 0x01010101);
1355 WREG32(mmTPC1_RTR_HBW_RD_RQ_S_ARB, 0x01010101);
1356 WREG32(mmTPC1_RTR_HBW_RD_RQ_E_ARB, 0x01060101);
1357 WREG32(mmTPC1_RTR_HBW_WR_RQ_N_ARB, 0x02020102);
1358 WREG32(mmTPC1_RTR_HBW_WR_RQ_S_ARB, 0x01010101);
1359 WREG32(mmTPC1_RTR_HBW_WR_RQ_E_ARB, 0x02070202);
1360 WREG32(mmTPC1_RTR_HBW_RD_RS_N_ARB, 0x01020201);
1361 WREG32(mmTPC1_RTR_HBW_RD_RS_S_ARB, 0x01070201);
1362 WREG32(mmTPC1_RTR_HBW_RD_RS_W_ARB, 0x01070202);
1363 WREG32(mmTPC1_RTR_HBW_WR_RS_N_ARB, 0x01010101);
1364 WREG32(mmTPC1_RTR_HBW_WR_RS_S_ARB, 0x01050101);
1365 WREG32(mmTPC1_RTR_HBW_WR_RS_W_ARB, 0x01050101);
1366
1367 WREG32(mmTPC2_RTR_HBW_RD_RQ_N_ARB, 0x01020101);
1368 WREG32(mmTPC2_RTR_HBW_RD_RQ_S_ARB, 0x01050101);
1369 WREG32(mmTPC2_RTR_HBW_RD_RQ_E_ARB, 0x01010201);
1370 WREG32(mmTPC2_RTR_HBW_WR_RQ_N_ARB, 0x02040102);
1371 WREG32(mmTPC2_RTR_HBW_WR_RQ_S_ARB, 0x01050101);
1372 WREG32(mmTPC2_RTR_HBW_WR_RQ_E_ARB, 0x02060202);
1373 WREG32(mmTPC2_RTR_HBW_RD_RS_N_ARB, 0x01020201);
1374 WREG32(mmTPC2_RTR_HBW_RD_RS_S_ARB, 0x01070201);
1375 WREG32(mmTPC2_RTR_HBW_RD_RS_W_ARB, 0x01070202);
1376 WREG32(mmTPC2_RTR_HBW_WR_RS_N_ARB, 0x01010101);
1377 WREG32(mmTPC2_RTR_HBW_WR_RS_S_ARB, 0x01040101);
1378 WREG32(mmTPC2_RTR_HBW_WR_RS_W_ARB, 0x01040101);
1379
1380 WREG32(mmTPC3_RTR_HBW_RD_RQ_N_ARB, 0x01030101);
1381 WREG32(mmTPC3_RTR_HBW_RD_RQ_S_ARB, 0x01040101);
1382 WREG32(mmTPC3_RTR_HBW_RD_RQ_E_ARB, 0x01040301);
1383 WREG32(mmTPC3_RTR_HBW_WR_RQ_N_ARB, 0x02060102);
1384 WREG32(mmTPC3_RTR_HBW_WR_RQ_S_ARB, 0x01040101);
1385 WREG32(mmTPC3_RTR_HBW_WR_RQ_E_ARB, 0x01040301);
1386 WREG32(mmTPC3_RTR_HBW_RD_RS_N_ARB, 0x01040201);
1387 WREG32(mmTPC3_RTR_HBW_RD_RS_S_ARB, 0x01060201);
1388 WREG32(mmTPC3_RTR_HBW_RD_RS_W_ARB, 0x01060402);
1389 WREG32(mmTPC3_RTR_HBW_WR_RS_N_ARB, 0x01020101);
1390 WREG32(mmTPC3_RTR_HBW_WR_RS_S_ARB, 0x01030101);
1391 WREG32(mmTPC3_RTR_HBW_WR_RS_W_ARB, 0x01030401);
1392
1393 WREG32(mmTPC4_RTR_HBW_RD_RQ_N_ARB, 0x01040101);
1394 WREG32(mmTPC4_RTR_HBW_RD_RQ_S_ARB, 0x01030101);
1395 WREG32(mmTPC4_RTR_HBW_RD_RQ_E_ARB, 0x01030401);
1396 WREG32(mmTPC4_RTR_HBW_WR_RQ_N_ARB, 0x02070102);
1397 WREG32(mmTPC4_RTR_HBW_WR_RQ_S_ARB, 0x01030101);
1398 WREG32(mmTPC4_RTR_HBW_WR_RQ_E_ARB, 0x02060702);
1399 WREG32(mmTPC4_RTR_HBW_RD_RS_N_ARB, 0x01060201);
1400 WREG32(mmTPC4_RTR_HBW_RD_RS_S_ARB, 0x01040201);
1401 WREG32(mmTPC4_RTR_HBW_RD_RS_W_ARB, 0x01040602);
1402 WREG32(mmTPC4_RTR_HBW_WR_RS_N_ARB, 0x01030101);
1403 WREG32(mmTPC4_RTR_HBW_WR_RS_S_ARB, 0x01020101);
1404 WREG32(mmTPC4_RTR_HBW_WR_RS_W_ARB, 0x01040301);
1405
1406 WREG32(mmTPC5_RTR_HBW_RD_RQ_N_ARB, 0x01050101);
1407 WREG32(mmTPC5_RTR_HBW_RD_RQ_S_ARB, 0x01020101);
1408 WREG32(mmTPC5_RTR_HBW_RD_RQ_E_ARB, 0x01200501);
1409 WREG32(mmTPC5_RTR_HBW_WR_RQ_N_ARB, 0x02070102);
1410 WREG32(mmTPC5_RTR_HBW_WR_RQ_S_ARB, 0x01020101);
1411 WREG32(mmTPC5_RTR_HBW_WR_RQ_E_ARB, 0x02020602);
1412 WREG32(mmTPC5_RTR_HBW_RD_RS_N_ARB, 0x01070201);
1413 WREG32(mmTPC5_RTR_HBW_RD_RS_S_ARB, 0x01020201);
1414 WREG32(mmTPC5_RTR_HBW_RD_RS_W_ARB, 0x01020702);
1415 WREG32(mmTPC5_RTR_HBW_WR_RS_N_ARB, 0x01040101);
1416 WREG32(mmTPC5_RTR_HBW_WR_RS_S_ARB, 0x01010101);
1417 WREG32(mmTPC5_RTR_HBW_WR_RS_W_ARB, 0x01010501);
1418
1419 WREG32(mmTPC6_RTR_HBW_RD_RQ_N_ARB, 0x01010101);
1420 WREG32(mmTPC6_RTR_HBW_RD_RQ_S_ARB, 0x01010101);
1421 WREG32(mmTPC6_RTR_HBW_RD_RQ_E_ARB, 0x01010601);
1422 WREG32(mmTPC6_RTR_HBW_WR_RQ_N_ARB, 0x01010101);
1423 WREG32(mmTPC6_RTR_HBW_WR_RQ_S_ARB, 0x01010101);
1424 WREG32(mmTPC6_RTR_HBW_WR_RQ_E_ARB, 0x02020702);
1425 WREG32(mmTPC6_RTR_HBW_RD_RS_N_ARB, 0x01010101);
1426 WREG32(mmTPC6_RTR_HBW_RD_RS_S_ARB, 0x01010101);
1427 WREG32(mmTPC6_RTR_HBW_RD_RS_W_ARB, 0x01020702);
1428 WREG32(mmTPC6_RTR_HBW_WR_RS_N_ARB, 0x01050101);
1429 WREG32(mmTPC6_RTR_HBW_WR_RS_S_ARB, 0x01010101);
1430 WREG32(mmTPC6_RTR_HBW_WR_RS_W_ARB, 0x01010501);
1431
1432 for (i = 0, offset = 0 ; i < 10 ; i++, offset += 4) {
1433 WREG32(mmMME1_RTR_SPLIT_COEF_0 + offset, polynom[i] >> 7);
1434 WREG32(mmMME2_RTR_SPLIT_COEF_0 + offset, polynom[i] >> 7);
1435 WREG32(mmMME3_RTR_SPLIT_COEF_0 + offset, polynom[i] >> 7);
1436 WREG32(mmMME4_RTR_SPLIT_COEF_0 + offset, polynom[i] >> 7);
1437 WREG32(mmMME5_RTR_SPLIT_COEF_0 + offset, polynom[i] >> 7);
1438 WREG32(mmMME6_RTR_SPLIT_COEF_0 + offset, polynom[i] >> 7);
1439
1440 WREG32(mmTPC0_NRTR_SPLIT_COEF_0 + offset, polynom[i] >> 7);
1441 WREG32(mmTPC1_RTR_SPLIT_COEF_0 + offset, polynom[i] >> 7);
1442 WREG32(mmTPC2_RTR_SPLIT_COEF_0 + offset, polynom[i] >> 7);
1443 WREG32(mmTPC3_RTR_SPLIT_COEF_0 + offset, polynom[i] >> 7);
1444 WREG32(mmTPC4_RTR_SPLIT_COEF_0 + offset, polynom[i] >> 7);
1445 WREG32(mmTPC5_RTR_SPLIT_COEF_0 + offset, polynom[i] >> 7);
1446 WREG32(mmTPC6_RTR_SPLIT_COEF_0 + offset, polynom[i] >> 7);
1447 WREG32(mmTPC7_NRTR_SPLIT_COEF_0 + offset, polynom[i] >> 7);
1448
1449 WREG32(mmPCI_NRTR_SPLIT_COEF_0 + offset, polynom[i] >> 7);
1450 WREG32(mmDMA_NRTR_SPLIT_COEF_0 + offset, polynom[i] >> 7);
1451 }
1452
1453 for (i = 0, offset = 0 ; i < 6 ; i++, offset += 0x40000) {
1454 WREG32(mmMME1_RTR_SCRAMB_EN + offset,
1455 1 << MME1_RTR_SCRAMB_EN_VAL_SHIFT);
1456 WREG32(mmMME1_RTR_NON_LIN_SCRAMB + offset,
1457 1 << MME1_RTR_NON_LIN_SCRAMB_EN_SHIFT);
1458 }
1459
1460 for (i = 0, offset = 0 ; i < 8 ; i++, offset += 0x40000) {
1461 /*
1462 * Workaround for Bug H2 #2441 :
1463 * "ST.NOP set trace event illegal opcode"
1464 */
1465 WREG32(mmTPC0_CFG_TPC_INTR_MASK + offset, tpc_intr_mask);
1466
1467 WREG32(mmTPC0_NRTR_SCRAMB_EN + offset,
1468 1 << TPC0_NRTR_SCRAMB_EN_VAL_SHIFT);
1469 WREG32(mmTPC0_NRTR_NON_LIN_SCRAMB + offset,
1470 1 << TPC0_NRTR_NON_LIN_SCRAMB_EN_SHIFT);
1471 }
1472
1473 WREG32(mmDMA_NRTR_SCRAMB_EN, 1 << DMA_NRTR_SCRAMB_EN_VAL_SHIFT);
1474 WREG32(mmDMA_NRTR_NON_LIN_SCRAMB,
1475 1 << DMA_NRTR_NON_LIN_SCRAMB_EN_SHIFT);
1476
1477 WREG32(mmPCI_NRTR_SCRAMB_EN, 1 << PCI_NRTR_SCRAMB_EN_VAL_SHIFT);
1478 WREG32(mmPCI_NRTR_NON_LIN_SCRAMB,
1479 1 << PCI_NRTR_NON_LIN_SCRAMB_EN_SHIFT);
1480
1481 /*
1482 * Workaround for H2 #HW-23 bug
1483 * Set DMA max outstanding read requests to 240 on DMA CH 1. Set it
1484 * to 16 on KMD DMA
1485 * We need to limit only these DMAs because the user can only read
1486 * from Host using DMA CH 1
1487 */
1488 WREG32(mmDMA_CH_0_CFG0, 0x0fff0010);
1489 WREG32(mmDMA_CH_1_CFG0, 0x0fff00F0);
1490
1491 goya->hw_cap_initialized |= HW_CAP_GOLDEN;
1492}
1493
Oded Gabbay9494a8d2019-02-16 00:39:17 +02001494static void goya_init_mme_qman(struct hl_device *hdev)
1495{
1496 u32 mtr_base_lo, mtr_base_hi;
1497 u32 so_base_lo, so_base_hi;
1498 u32 gic_base_lo, gic_base_hi;
1499 u64 qman_base_addr;
1500
1501 mtr_base_lo = lower_32_bits(CFG_BASE + mmSYNC_MNGR_MON_PAY_ADDRL_0);
1502 mtr_base_hi = upper_32_bits(CFG_BASE + mmSYNC_MNGR_MON_PAY_ADDRL_0);
1503 so_base_lo = lower_32_bits(CFG_BASE + mmSYNC_MNGR_SOB_OBJ_0);
1504 so_base_hi = upper_32_bits(CFG_BASE + mmSYNC_MNGR_SOB_OBJ_0);
1505
1506 gic_base_lo =
1507 lower_32_bits(CFG_BASE + mmGIC_DISTRIBUTOR__5_GICD_SETSPI_NSR);
1508 gic_base_hi =
1509 upper_32_bits(CFG_BASE + mmGIC_DISTRIBUTOR__5_GICD_SETSPI_NSR);
1510
1511 qman_base_addr = hdev->asic_prop.sram_base_address +
1512 MME_QMAN_BASE_OFFSET;
1513
1514 WREG32(mmMME_QM_PQ_BASE_LO, lower_32_bits(qman_base_addr));
1515 WREG32(mmMME_QM_PQ_BASE_HI, upper_32_bits(qman_base_addr));
1516 WREG32(mmMME_QM_PQ_SIZE, ilog2(MME_QMAN_LENGTH));
1517 WREG32(mmMME_QM_PQ_PI, 0);
1518 WREG32(mmMME_QM_PQ_CI, 0);
1519 WREG32(mmMME_QM_CP_LDMA_SRC_BASE_LO_OFFSET, 0x10C0);
1520 WREG32(mmMME_QM_CP_LDMA_SRC_BASE_HI_OFFSET, 0x10C4);
1521 WREG32(mmMME_QM_CP_LDMA_TSIZE_OFFSET, 0x10C8);
1522 WREG32(mmMME_QM_CP_LDMA_COMMIT_OFFSET, 0x10CC);
1523
1524 WREG32(mmMME_QM_CP_MSG_BASE0_ADDR_LO, mtr_base_lo);
1525 WREG32(mmMME_QM_CP_MSG_BASE0_ADDR_HI, mtr_base_hi);
1526 WREG32(mmMME_QM_CP_MSG_BASE1_ADDR_LO, so_base_lo);
1527 WREG32(mmMME_QM_CP_MSG_BASE1_ADDR_HI, so_base_hi);
1528
1529 /* QMAN CQ has 8 cache lines */
1530 WREG32(mmMME_QM_CQ_CFG1, 0x00080008);
1531
1532 WREG32(mmMME_QM_GLBL_ERR_ADDR_LO, gic_base_lo);
1533 WREG32(mmMME_QM_GLBL_ERR_ADDR_HI, gic_base_hi);
1534
1535 WREG32(mmMME_QM_GLBL_ERR_WDATA, GOYA_ASYNC_EVENT_ID_MME_QM);
1536
1537 WREG32(mmMME_QM_GLBL_ERR_CFG, QMAN_MME_ERR_MSG_EN);
1538
1539 WREG32(mmMME_QM_GLBL_PROT, QMAN_MME_ERR_PROT);
1540
1541 WREG32(mmMME_QM_GLBL_CFG0, QMAN_MME_ENABLE);
1542}
1543
1544static void goya_init_mme_cmdq(struct hl_device *hdev)
1545{
1546 u32 mtr_base_lo, mtr_base_hi;
1547 u32 so_base_lo, so_base_hi;
1548 u32 gic_base_lo, gic_base_hi;
1549 u64 qman_base_addr;
1550
1551 mtr_base_lo = lower_32_bits(CFG_BASE + mmSYNC_MNGR_MON_PAY_ADDRL_0);
1552 mtr_base_hi = upper_32_bits(CFG_BASE + mmSYNC_MNGR_MON_PAY_ADDRL_0);
1553 so_base_lo = lower_32_bits(CFG_BASE + mmSYNC_MNGR_SOB_OBJ_0);
1554 so_base_hi = upper_32_bits(CFG_BASE + mmSYNC_MNGR_SOB_OBJ_0);
1555
1556 gic_base_lo =
1557 lower_32_bits(CFG_BASE + mmGIC_DISTRIBUTOR__5_GICD_SETSPI_NSR);
1558 gic_base_hi =
1559 upper_32_bits(CFG_BASE + mmGIC_DISTRIBUTOR__5_GICD_SETSPI_NSR);
1560
1561 qman_base_addr = hdev->asic_prop.sram_base_address +
1562 MME_QMAN_BASE_OFFSET;
1563
1564 WREG32(mmMME_CMDQ_CP_MSG_BASE0_ADDR_LO, mtr_base_lo);
1565 WREG32(mmMME_CMDQ_CP_MSG_BASE0_ADDR_HI, mtr_base_hi);
1566 WREG32(mmMME_CMDQ_CP_MSG_BASE1_ADDR_LO, so_base_lo);
1567 WREG32(mmMME_CMDQ_CP_MSG_BASE1_ADDR_HI, so_base_hi);
1568
1569 /* CMDQ CQ has 20 cache lines */
1570 WREG32(mmMME_CMDQ_CQ_CFG1, 0x00140014);
1571
1572 WREG32(mmMME_CMDQ_GLBL_ERR_ADDR_LO, gic_base_lo);
1573 WREG32(mmMME_CMDQ_GLBL_ERR_ADDR_HI, gic_base_hi);
1574
1575 WREG32(mmMME_CMDQ_GLBL_ERR_WDATA, GOYA_ASYNC_EVENT_ID_MME_CMDQ);
1576
1577 WREG32(mmMME_CMDQ_GLBL_ERR_CFG, CMDQ_MME_ERR_MSG_EN);
1578
1579 WREG32(mmMME_CMDQ_GLBL_PROT, CMDQ_MME_ERR_PROT);
1580
1581 WREG32(mmMME_CMDQ_GLBL_CFG0, CMDQ_MME_ENABLE);
1582}
1583
1584static void goya_init_mme_qmans(struct hl_device *hdev)
1585{
1586 struct goya_device *goya = hdev->asic_specific;
1587 u32 so_base_lo, so_base_hi;
1588
1589 if (goya->hw_cap_initialized & HW_CAP_MME)
1590 return;
1591
1592 so_base_lo = lower_32_bits(CFG_BASE + mmSYNC_MNGR_SOB_OBJ_0);
1593 so_base_hi = upper_32_bits(CFG_BASE + mmSYNC_MNGR_SOB_OBJ_0);
1594
1595 WREG32(mmMME_SM_BASE_ADDRESS_LOW, so_base_lo);
1596 WREG32(mmMME_SM_BASE_ADDRESS_HIGH, so_base_hi);
1597
1598 goya_init_mme_qman(hdev);
1599 goya_init_mme_cmdq(hdev);
1600
1601 goya->hw_cap_initialized |= HW_CAP_MME;
1602}
1603
1604static void goya_init_tpc_qman(struct hl_device *hdev, u32 base_off, int tpc_id)
1605{
1606 u32 mtr_base_lo, mtr_base_hi;
1607 u32 so_base_lo, so_base_hi;
1608 u32 gic_base_lo, gic_base_hi;
1609 u64 qman_base_addr;
1610 u32 reg_off = tpc_id * (mmTPC1_QM_PQ_PI - mmTPC0_QM_PQ_PI);
1611
1612 mtr_base_lo = lower_32_bits(CFG_BASE + mmSYNC_MNGR_MON_PAY_ADDRL_0);
1613 mtr_base_hi = upper_32_bits(CFG_BASE + mmSYNC_MNGR_MON_PAY_ADDRL_0);
1614 so_base_lo = lower_32_bits(CFG_BASE + mmSYNC_MNGR_SOB_OBJ_0);
1615 so_base_hi = upper_32_bits(CFG_BASE + mmSYNC_MNGR_SOB_OBJ_0);
1616
1617 gic_base_lo =
1618 lower_32_bits(CFG_BASE + mmGIC_DISTRIBUTOR__5_GICD_SETSPI_NSR);
1619 gic_base_hi =
1620 upper_32_bits(CFG_BASE + mmGIC_DISTRIBUTOR__5_GICD_SETSPI_NSR);
1621
1622 qman_base_addr = hdev->asic_prop.sram_base_address + base_off;
1623
1624 WREG32(mmTPC0_QM_PQ_BASE_LO + reg_off, lower_32_bits(qman_base_addr));
1625 WREG32(mmTPC0_QM_PQ_BASE_HI + reg_off, upper_32_bits(qman_base_addr));
1626 WREG32(mmTPC0_QM_PQ_SIZE + reg_off, ilog2(TPC_QMAN_LENGTH));
1627 WREG32(mmTPC0_QM_PQ_PI + reg_off, 0);
1628 WREG32(mmTPC0_QM_PQ_CI + reg_off, 0);
1629 WREG32(mmTPC0_QM_CP_LDMA_SRC_BASE_LO_OFFSET + reg_off, 0x10C0);
1630 WREG32(mmTPC0_QM_CP_LDMA_SRC_BASE_HI_OFFSET + reg_off, 0x10C4);
1631 WREG32(mmTPC0_QM_CP_LDMA_TSIZE_OFFSET + reg_off, 0x10C8);
1632 WREG32(mmTPC0_QM_CP_LDMA_COMMIT_OFFSET + reg_off, 0x10CC);
1633
1634 WREG32(mmTPC0_QM_CP_MSG_BASE0_ADDR_LO + reg_off, mtr_base_lo);
1635 WREG32(mmTPC0_QM_CP_MSG_BASE0_ADDR_HI + reg_off, mtr_base_hi);
1636 WREG32(mmTPC0_QM_CP_MSG_BASE1_ADDR_LO + reg_off, so_base_lo);
1637 WREG32(mmTPC0_QM_CP_MSG_BASE1_ADDR_HI + reg_off, so_base_hi);
1638
1639 WREG32(mmTPC0_QM_CQ_CFG1 + reg_off, 0x00080008);
1640
1641 WREG32(mmTPC0_QM_GLBL_ERR_ADDR_LO + reg_off, gic_base_lo);
1642 WREG32(mmTPC0_QM_GLBL_ERR_ADDR_HI + reg_off, gic_base_hi);
1643
1644 WREG32(mmTPC0_QM_GLBL_ERR_WDATA + reg_off,
1645 GOYA_ASYNC_EVENT_ID_TPC0_QM + tpc_id);
1646
1647 WREG32(mmTPC0_QM_GLBL_ERR_CFG + reg_off, QMAN_TPC_ERR_MSG_EN);
1648
1649 WREG32(mmTPC0_QM_GLBL_PROT + reg_off, QMAN_TPC_ERR_PROT);
1650
1651 WREG32(mmTPC0_QM_GLBL_CFG0 + reg_off, QMAN_TPC_ENABLE);
1652}
1653
1654static void goya_init_tpc_cmdq(struct hl_device *hdev, int tpc_id)
1655{
1656 u32 mtr_base_lo, mtr_base_hi;
1657 u32 so_base_lo, so_base_hi;
1658 u32 gic_base_lo, gic_base_hi;
1659 u32 reg_off = tpc_id * (mmTPC1_CMDQ_CQ_CFG1 - mmTPC0_CMDQ_CQ_CFG1);
1660
1661 mtr_base_lo = lower_32_bits(CFG_BASE + mmSYNC_MNGR_MON_PAY_ADDRL_0);
1662 mtr_base_hi = upper_32_bits(CFG_BASE + mmSYNC_MNGR_MON_PAY_ADDRL_0);
1663 so_base_lo = lower_32_bits(CFG_BASE + mmSYNC_MNGR_SOB_OBJ_0);
1664 so_base_hi = upper_32_bits(CFG_BASE + mmSYNC_MNGR_SOB_OBJ_0);
1665
1666 gic_base_lo =
1667 lower_32_bits(CFG_BASE + mmGIC_DISTRIBUTOR__5_GICD_SETSPI_NSR);
1668 gic_base_hi =
1669 upper_32_bits(CFG_BASE + mmGIC_DISTRIBUTOR__5_GICD_SETSPI_NSR);
1670
1671 WREG32(mmTPC0_CMDQ_CP_MSG_BASE0_ADDR_LO + reg_off, mtr_base_lo);
1672 WREG32(mmTPC0_CMDQ_CP_MSG_BASE0_ADDR_HI + reg_off, mtr_base_hi);
1673 WREG32(mmTPC0_CMDQ_CP_MSG_BASE1_ADDR_LO + reg_off, so_base_lo);
1674 WREG32(mmTPC0_CMDQ_CP_MSG_BASE1_ADDR_HI + reg_off, so_base_hi);
1675
1676 WREG32(mmTPC0_CMDQ_CQ_CFG1 + reg_off, 0x00140014);
1677
1678 WREG32(mmTPC0_CMDQ_GLBL_ERR_ADDR_LO + reg_off, gic_base_lo);
1679 WREG32(mmTPC0_CMDQ_GLBL_ERR_ADDR_HI + reg_off, gic_base_hi);
1680
1681 WREG32(mmTPC0_CMDQ_GLBL_ERR_WDATA + reg_off,
1682 GOYA_ASYNC_EVENT_ID_TPC0_CMDQ + tpc_id);
1683
1684 WREG32(mmTPC0_CMDQ_GLBL_ERR_CFG + reg_off, CMDQ_TPC_ERR_MSG_EN);
1685
1686 WREG32(mmTPC0_CMDQ_GLBL_PROT + reg_off, CMDQ_TPC_ERR_PROT);
1687
1688 WREG32(mmTPC0_CMDQ_GLBL_CFG0 + reg_off, CMDQ_TPC_ENABLE);
1689}
1690
1691static void goya_init_tpc_qmans(struct hl_device *hdev)
1692{
1693 struct goya_device *goya = hdev->asic_specific;
1694 u32 so_base_lo, so_base_hi;
1695 u32 cfg_off = mmTPC1_CFG_SM_BASE_ADDRESS_LOW -
1696 mmTPC0_CFG_SM_BASE_ADDRESS_LOW;
1697 int i;
1698
1699 if (goya->hw_cap_initialized & HW_CAP_TPC)
1700 return;
1701
1702 so_base_lo = lower_32_bits(CFG_BASE + mmSYNC_MNGR_SOB_OBJ_0);
1703 so_base_hi = upper_32_bits(CFG_BASE + mmSYNC_MNGR_SOB_OBJ_0);
1704
1705 for (i = 0 ; i < TPC_MAX_NUM ; i++) {
1706 WREG32(mmTPC0_CFG_SM_BASE_ADDRESS_LOW + i * cfg_off,
1707 so_base_lo);
1708 WREG32(mmTPC0_CFG_SM_BASE_ADDRESS_HIGH + i * cfg_off,
1709 so_base_hi);
1710 }
1711
1712 goya_init_tpc_qman(hdev, TPC0_QMAN_BASE_OFFSET, 0);
1713 goya_init_tpc_qman(hdev, TPC1_QMAN_BASE_OFFSET, 1);
1714 goya_init_tpc_qman(hdev, TPC2_QMAN_BASE_OFFSET, 2);
1715 goya_init_tpc_qman(hdev, TPC3_QMAN_BASE_OFFSET, 3);
1716 goya_init_tpc_qman(hdev, TPC4_QMAN_BASE_OFFSET, 4);
1717 goya_init_tpc_qman(hdev, TPC5_QMAN_BASE_OFFSET, 5);
1718 goya_init_tpc_qman(hdev, TPC6_QMAN_BASE_OFFSET, 6);
1719 goya_init_tpc_qman(hdev, TPC7_QMAN_BASE_OFFSET, 7);
1720
1721 for (i = 0 ; i < TPC_MAX_NUM ; i++)
1722 goya_init_tpc_cmdq(hdev, i);
1723
1724 goya->hw_cap_initialized |= HW_CAP_TPC;
1725}
1726
1727/*
1728 * goya_disable_internal_queues - Disable internal queues
1729 *
1730 * @hdev: pointer to hl_device structure
1731 *
1732 */
1733static void goya_disable_internal_queues(struct hl_device *hdev)
1734{
1735 WREG32(mmMME_QM_GLBL_CFG0, 0);
1736 WREG32(mmMME_CMDQ_GLBL_CFG0, 0);
1737
1738 WREG32(mmTPC0_QM_GLBL_CFG0, 0);
1739 WREG32(mmTPC0_CMDQ_GLBL_CFG0, 0);
1740
1741 WREG32(mmTPC1_QM_GLBL_CFG0, 0);
1742 WREG32(mmTPC1_CMDQ_GLBL_CFG0, 0);
1743
1744 WREG32(mmTPC2_QM_GLBL_CFG0, 0);
1745 WREG32(mmTPC2_CMDQ_GLBL_CFG0, 0);
1746
1747 WREG32(mmTPC3_QM_GLBL_CFG0, 0);
1748 WREG32(mmTPC3_CMDQ_GLBL_CFG0, 0);
1749
1750 WREG32(mmTPC4_QM_GLBL_CFG0, 0);
1751 WREG32(mmTPC4_CMDQ_GLBL_CFG0, 0);
1752
1753 WREG32(mmTPC5_QM_GLBL_CFG0, 0);
1754 WREG32(mmTPC5_CMDQ_GLBL_CFG0, 0);
1755
1756 WREG32(mmTPC6_QM_GLBL_CFG0, 0);
1757 WREG32(mmTPC6_CMDQ_GLBL_CFG0, 0);
1758
1759 WREG32(mmTPC7_QM_GLBL_CFG0, 0);
1760 WREG32(mmTPC7_CMDQ_GLBL_CFG0, 0);
1761}
1762
1763/*
1764 * goya_stop_internal_queues - Stop internal queues
1765 *
1766 * @hdev: pointer to hl_device structure
1767 *
1768 * Returns 0 on success
1769 *
1770 */
1771static int goya_stop_internal_queues(struct hl_device *hdev)
1772{
1773 int rc, retval = 0;
1774
1775 /*
1776 * Each queue (QMAN) is a separate H/W logic. That means that each
1777 * QMAN can be stopped independently and failure to stop one does NOT
1778 * mandate we should not try to stop other QMANs
1779 */
1780
1781 rc = goya_stop_queue(hdev,
1782 mmMME_QM_GLBL_CFG1,
1783 mmMME_QM_CP_STS,
1784 mmMME_QM_GLBL_STS0);
1785
1786 if (rc) {
1787 dev_err(hdev->dev, "failed to stop MME QMAN\n");
1788 retval = -EIO;
1789 }
1790
1791 rc = goya_stop_queue(hdev,
1792 mmMME_CMDQ_GLBL_CFG1,
1793 mmMME_CMDQ_CP_STS,
1794 mmMME_CMDQ_GLBL_STS0);
1795
1796 if (rc) {
1797 dev_err(hdev->dev, "failed to stop MME CMDQ\n");
1798 retval = -EIO;
1799 }
1800
1801 rc = goya_stop_queue(hdev,
1802 mmTPC0_QM_GLBL_CFG1,
1803 mmTPC0_QM_CP_STS,
1804 mmTPC0_QM_GLBL_STS0);
1805
1806 if (rc) {
1807 dev_err(hdev->dev, "failed to stop TPC 0 QMAN\n");
1808 retval = -EIO;
1809 }
1810
1811 rc = goya_stop_queue(hdev,
1812 mmTPC0_CMDQ_GLBL_CFG1,
1813 mmTPC0_CMDQ_CP_STS,
1814 mmTPC0_CMDQ_GLBL_STS0);
1815
1816 if (rc) {
1817 dev_err(hdev->dev, "failed to stop TPC 0 CMDQ\n");
1818 retval = -EIO;
1819 }
1820
1821 rc = goya_stop_queue(hdev,
1822 mmTPC1_QM_GLBL_CFG1,
1823 mmTPC1_QM_CP_STS,
1824 mmTPC1_QM_GLBL_STS0);
1825
1826 if (rc) {
1827 dev_err(hdev->dev, "failed to stop TPC 1 QMAN\n");
1828 retval = -EIO;
1829 }
1830
1831 rc = goya_stop_queue(hdev,
1832 mmTPC1_CMDQ_GLBL_CFG1,
1833 mmTPC1_CMDQ_CP_STS,
1834 mmTPC1_CMDQ_GLBL_STS0);
1835
1836 if (rc) {
1837 dev_err(hdev->dev, "failed to stop TPC 1 CMDQ\n");
1838 retval = -EIO;
1839 }
1840
1841 rc = goya_stop_queue(hdev,
1842 mmTPC2_QM_GLBL_CFG1,
1843 mmTPC2_QM_CP_STS,
1844 mmTPC2_QM_GLBL_STS0);
1845
1846 if (rc) {
1847 dev_err(hdev->dev, "failed to stop TPC 2 QMAN\n");
1848 retval = -EIO;
1849 }
1850
1851 rc = goya_stop_queue(hdev,
1852 mmTPC2_CMDQ_GLBL_CFG1,
1853 mmTPC2_CMDQ_CP_STS,
1854 mmTPC2_CMDQ_GLBL_STS0);
1855
1856 if (rc) {
1857 dev_err(hdev->dev, "failed to stop TPC 2 CMDQ\n");
1858 retval = -EIO;
1859 }
1860
1861 rc = goya_stop_queue(hdev,
1862 mmTPC3_QM_GLBL_CFG1,
1863 mmTPC3_QM_CP_STS,
1864 mmTPC3_QM_GLBL_STS0);
1865
1866 if (rc) {
1867 dev_err(hdev->dev, "failed to stop TPC 3 QMAN\n");
1868 retval = -EIO;
1869 }
1870
1871 rc = goya_stop_queue(hdev,
1872 mmTPC3_CMDQ_GLBL_CFG1,
1873 mmTPC3_CMDQ_CP_STS,
1874 mmTPC3_CMDQ_GLBL_STS0);
1875
1876 if (rc) {
1877 dev_err(hdev->dev, "failed to stop TPC 3 CMDQ\n");
1878 retval = -EIO;
1879 }
1880
1881 rc = goya_stop_queue(hdev,
1882 mmTPC4_QM_GLBL_CFG1,
1883 mmTPC4_QM_CP_STS,
1884 mmTPC4_QM_GLBL_STS0);
1885
1886 if (rc) {
1887 dev_err(hdev->dev, "failed to stop TPC 4 QMAN\n");
1888 retval = -EIO;
1889 }
1890
1891 rc = goya_stop_queue(hdev,
1892 mmTPC4_CMDQ_GLBL_CFG1,
1893 mmTPC4_CMDQ_CP_STS,
1894 mmTPC4_CMDQ_GLBL_STS0);
1895
1896 if (rc) {
1897 dev_err(hdev->dev, "failed to stop TPC 4 CMDQ\n");
1898 retval = -EIO;
1899 }
1900
1901 rc = goya_stop_queue(hdev,
1902 mmTPC5_QM_GLBL_CFG1,
1903 mmTPC5_QM_CP_STS,
1904 mmTPC5_QM_GLBL_STS0);
1905
1906 if (rc) {
1907 dev_err(hdev->dev, "failed to stop TPC 5 QMAN\n");
1908 retval = -EIO;
1909 }
1910
1911 rc = goya_stop_queue(hdev,
1912 mmTPC5_CMDQ_GLBL_CFG1,
1913 mmTPC5_CMDQ_CP_STS,
1914 mmTPC5_CMDQ_GLBL_STS0);
1915
1916 if (rc) {
1917 dev_err(hdev->dev, "failed to stop TPC 5 CMDQ\n");
1918 retval = -EIO;
1919 }
1920
1921 rc = goya_stop_queue(hdev,
1922 mmTPC6_QM_GLBL_CFG1,
1923 mmTPC6_QM_CP_STS,
1924 mmTPC6_QM_GLBL_STS0);
1925
1926 if (rc) {
1927 dev_err(hdev->dev, "failed to stop TPC 6 QMAN\n");
1928 retval = -EIO;
1929 }
1930
1931 rc = goya_stop_queue(hdev,
1932 mmTPC6_CMDQ_GLBL_CFG1,
1933 mmTPC6_CMDQ_CP_STS,
1934 mmTPC6_CMDQ_GLBL_STS0);
1935
1936 if (rc) {
1937 dev_err(hdev->dev, "failed to stop TPC 6 CMDQ\n");
1938 retval = -EIO;
1939 }
1940
1941 rc = goya_stop_queue(hdev,
1942 mmTPC7_QM_GLBL_CFG1,
1943 mmTPC7_QM_CP_STS,
1944 mmTPC7_QM_GLBL_STS0);
1945
1946 if (rc) {
1947 dev_err(hdev->dev, "failed to stop TPC 7 QMAN\n");
1948 retval = -EIO;
1949 }
1950
1951 rc = goya_stop_queue(hdev,
1952 mmTPC7_CMDQ_GLBL_CFG1,
1953 mmTPC7_CMDQ_CP_STS,
1954 mmTPC7_CMDQ_GLBL_STS0);
1955
1956 if (rc) {
1957 dev_err(hdev->dev, "failed to stop TPC 7 CMDQ\n");
1958 retval = -EIO;
1959 }
1960
1961 return retval;
1962}
1963
1964static void goya_resume_internal_queues(struct hl_device *hdev)
1965{
1966 WREG32(mmMME_QM_GLBL_CFG1, 0);
1967 WREG32(mmMME_CMDQ_GLBL_CFG1, 0);
1968
1969 WREG32(mmTPC0_QM_GLBL_CFG1, 0);
1970 WREG32(mmTPC0_CMDQ_GLBL_CFG1, 0);
1971
1972 WREG32(mmTPC1_QM_GLBL_CFG1, 0);
1973 WREG32(mmTPC1_CMDQ_GLBL_CFG1, 0);
1974
1975 WREG32(mmTPC2_QM_GLBL_CFG1, 0);
1976 WREG32(mmTPC2_CMDQ_GLBL_CFG1, 0);
1977
1978 WREG32(mmTPC3_QM_GLBL_CFG1, 0);
1979 WREG32(mmTPC3_CMDQ_GLBL_CFG1, 0);
1980
1981 WREG32(mmTPC4_QM_GLBL_CFG1, 0);
1982 WREG32(mmTPC4_CMDQ_GLBL_CFG1, 0);
1983
1984 WREG32(mmTPC5_QM_GLBL_CFG1, 0);
1985 WREG32(mmTPC5_CMDQ_GLBL_CFG1, 0);
1986
1987 WREG32(mmTPC6_QM_GLBL_CFG1, 0);
1988 WREG32(mmTPC6_CMDQ_GLBL_CFG1, 0);
1989
1990 WREG32(mmTPC7_QM_GLBL_CFG1, 0);
1991 WREG32(mmTPC7_CMDQ_GLBL_CFG1, 0);
1992}
1993
Oded Gabbay1251f232019-02-16 00:39:18 +02001994static void goya_dma_stall(struct hl_device *hdev)
1995{
1996 WREG32(mmDMA_QM_0_GLBL_CFG1, 1 << DMA_QM_0_GLBL_CFG1_DMA_STOP_SHIFT);
1997 WREG32(mmDMA_QM_1_GLBL_CFG1, 1 << DMA_QM_1_GLBL_CFG1_DMA_STOP_SHIFT);
1998 WREG32(mmDMA_QM_2_GLBL_CFG1, 1 << DMA_QM_2_GLBL_CFG1_DMA_STOP_SHIFT);
1999 WREG32(mmDMA_QM_3_GLBL_CFG1, 1 << DMA_QM_3_GLBL_CFG1_DMA_STOP_SHIFT);
2000 WREG32(mmDMA_QM_4_GLBL_CFG1, 1 << DMA_QM_4_GLBL_CFG1_DMA_STOP_SHIFT);
2001}
2002
2003static void goya_tpc_stall(struct hl_device *hdev)
2004{
2005 WREG32(mmTPC0_CFG_TPC_STALL, 1 << TPC0_CFG_TPC_STALL_V_SHIFT);
2006 WREG32(mmTPC1_CFG_TPC_STALL, 1 << TPC1_CFG_TPC_STALL_V_SHIFT);
2007 WREG32(mmTPC2_CFG_TPC_STALL, 1 << TPC2_CFG_TPC_STALL_V_SHIFT);
2008 WREG32(mmTPC3_CFG_TPC_STALL, 1 << TPC3_CFG_TPC_STALL_V_SHIFT);
2009 WREG32(mmTPC4_CFG_TPC_STALL, 1 << TPC4_CFG_TPC_STALL_V_SHIFT);
2010 WREG32(mmTPC5_CFG_TPC_STALL, 1 << TPC5_CFG_TPC_STALL_V_SHIFT);
2011 WREG32(mmTPC6_CFG_TPC_STALL, 1 << TPC6_CFG_TPC_STALL_V_SHIFT);
2012 WREG32(mmTPC7_CFG_TPC_STALL, 1 << TPC7_CFG_TPC_STALL_V_SHIFT);
2013}
2014
2015static void goya_mme_stall(struct hl_device *hdev)
2016{
2017 WREG32(mmMME_STALL, 0xFFFFFFFF);
2018}
2019
2020static int goya_enable_msix(struct hl_device *hdev)
2021{
2022 struct goya_device *goya = hdev->asic_specific;
2023 int cq_cnt = hdev->asic_prop.completion_queues_count;
2024 int rc, i, irq_cnt_init, irq;
2025
2026 if (goya->hw_cap_initialized & HW_CAP_MSIX)
2027 return 0;
2028
2029 rc = pci_alloc_irq_vectors(hdev->pdev, GOYA_MSIX_ENTRIES,
2030 GOYA_MSIX_ENTRIES, PCI_IRQ_MSIX);
2031 if (rc < 0) {
2032 dev_err(hdev->dev,
2033 "MSI-X: Failed to enable support -- %d/%d\n",
2034 GOYA_MSIX_ENTRIES, rc);
2035 return rc;
2036 }
2037
2038 for (i = 0, irq_cnt_init = 0 ; i < cq_cnt ; i++, irq_cnt_init++) {
2039 irq = pci_irq_vector(hdev->pdev, i);
2040 rc = request_irq(irq, hl_irq_handler_cq, 0, goya_irq_name[i],
2041 &hdev->completion_queue[i]);
2042 if (rc) {
2043 dev_err(hdev->dev, "Failed to request IRQ %d", irq);
2044 goto free_irqs;
2045 }
2046 }
2047
2048 irq = pci_irq_vector(hdev->pdev, EVENT_QUEUE_MSIX_IDX);
2049
2050 rc = request_irq(irq, hl_irq_handler_eq, 0,
2051 goya_irq_name[EVENT_QUEUE_MSIX_IDX],
2052 &hdev->event_queue);
2053 if (rc) {
2054 dev_err(hdev->dev, "Failed to request IRQ %d", irq);
2055 goto free_irqs;
2056 }
2057
2058 goya->hw_cap_initialized |= HW_CAP_MSIX;
2059 return 0;
2060
2061free_irqs:
2062 for (i = 0 ; i < irq_cnt_init ; i++)
2063 free_irq(pci_irq_vector(hdev->pdev, i),
2064 &hdev->completion_queue[i]);
2065
2066 pci_free_irq_vectors(hdev->pdev);
2067 return rc;
2068}
2069
2070static void goya_sync_irqs(struct hl_device *hdev)
2071{
2072 struct goya_device *goya = hdev->asic_specific;
2073 int i;
2074
2075 if (!(goya->hw_cap_initialized & HW_CAP_MSIX))
2076 return;
2077
2078 /* Wait for all pending IRQs to be finished */
2079 for (i = 0 ; i < hdev->asic_prop.completion_queues_count ; i++)
2080 synchronize_irq(pci_irq_vector(hdev->pdev, i));
2081
2082 synchronize_irq(pci_irq_vector(hdev->pdev, EVENT_QUEUE_MSIX_IDX));
2083}
2084
2085static void goya_disable_msix(struct hl_device *hdev)
2086{
2087 struct goya_device *goya = hdev->asic_specific;
2088 int i, irq;
2089
2090 if (!(goya->hw_cap_initialized & HW_CAP_MSIX))
2091 return;
2092
2093 goya_sync_irqs(hdev);
2094
2095 irq = pci_irq_vector(hdev->pdev, EVENT_QUEUE_MSIX_IDX);
2096 free_irq(irq, &hdev->event_queue);
2097
2098 for (i = 0 ; i < hdev->asic_prop.completion_queues_count ; i++) {
2099 irq = pci_irq_vector(hdev->pdev, i);
2100 free_irq(irq, &hdev->completion_queue[i]);
2101 }
2102
2103 pci_free_irq_vectors(hdev->pdev);
2104
2105 goya->hw_cap_initialized &= ~HW_CAP_MSIX;
2106}
2107
2108static void goya_halt_engines(struct hl_device *hdev, bool hard_reset)
2109{
2110 u32 wait_timeout_ms, cpu_timeout_ms;
2111
2112 dev_info(hdev->dev,
2113 "Halting compute engines and disabling interrupts\n");
2114
2115 if (hdev->pldm) {
2116 wait_timeout_ms = GOYA_PLDM_RESET_WAIT_MSEC;
2117 cpu_timeout_ms = GOYA_PLDM_RESET_WAIT_MSEC;
2118 } else {
2119 wait_timeout_ms = GOYA_RESET_WAIT_MSEC;
2120 cpu_timeout_ms = GOYA_CPU_RESET_WAIT_MSEC;
2121 }
2122
2123 if (hard_reset) {
2124 /*
2125 * I don't know what is the state of the CPU so make sure it is
2126 * stopped in any means necessary
2127 */
2128 WREG32(mmPSOC_GLOBAL_CONF_UBOOT_MAGIC, KMD_MSG_GOTO_WFE);
2129 WREG32(mmGIC_DISTRIBUTOR__5_GICD_SETSPI_NSR,
2130 GOYA_ASYNC_EVENT_ID_HALT_MACHINE);
2131 msleep(cpu_timeout_ms);
2132 }
2133
2134 goya_stop_external_queues(hdev);
2135 goya_stop_internal_queues(hdev);
2136
2137 msleep(wait_timeout_ms);
2138
2139 goya_dma_stall(hdev);
2140 goya_tpc_stall(hdev);
2141 goya_mme_stall(hdev);
2142
2143 msleep(wait_timeout_ms);
2144
2145 goya_disable_external_queues(hdev);
2146 goya_disable_internal_queues(hdev);
2147
2148 if (hard_reset)
2149 goya_disable_msix(hdev);
2150 else
2151 goya_sync_irqs(hdev);
2152}
Oded Gabbay839c4802019-02-16 00:39:16 +02002153
2154/*
2155 * goya_push_fw_to_device - Push FW code to device
2156 *
2157 * @hdev: pointer to hl_device structure
2158 *
2159 * Copy fw code from firmware file to device memory.
2160 * Returns 0 on success
2161 *
2162 */
2163static int goya_push_fw_to_device(struct hl_device *hdev, const char *fw_name,
2164 void __iomem *dst)
2165{
2166 const struct firmware *fw;
2167 const u64 *fw_data;
2168 size_t fw_size, i;
2169 int rc;
2170
2171 rc = request_firmware(&fw, fw_name, hdev->dev);
2172
2173 if (rc) {
2174 dev_err(hdev->dev, "Failed to request %s\n", fw_name);
2175 goto out;
2176 }
2177
2178 fw_size = fw->size;
2179 if ((fw_size % 4) != 0) {
2180 dev_err(hdev->dev, "illegal %s firmware size %zu\n",
2181 fw_name, fw_size);
2182 rc = -EINVAL;
2183 goto out;
2184 }
2185
2186 dev_dbg(hdev->dev, "%s firmware size == %zu\n", fw_name, fw_size);
2187
2188 fw_data = (const u64 *) fw->data;
2189
2190 if ((fw->size % 8) != 0)
2191 fw_size -= 8;
2192
2193 for (i = 0 ; i < fw_size ; i += 8, fw_data++, dst += 8) {
2194 if (!(i & (0x80000 - 1))) {
2195 dev_dbg(hdev->dev,
2196 "copied so far %zu out of %zu for %s firmware",
2197 i, fw_size, fw_name);
2198 usleep_range(20, 100);
2199 }
2200
2201 writeq(*fw_data, dst);
2202 }
2203
2204 if ((fw->size % 8) != 0)
2205 writel(*(const u32 *) fw_data, dst);
2206
2207out:
2208 release_firmware(fw);
2209 return rc;
2210}
2211
2212static int goya_pldm_init_cpu(struct hl_device *hdev)
2213{
2214 char fw_name[200];
2215 void __iomem *dst;
2216 u32 val, unit_rst_val;
2217 int rc;
2218
2219 /* Must initialize SRAM scrambler before pushing u-boot to SRAM */
2220 goya_init_golden_registers(hdev);
2221
2222 /* Put ARM cores into reset */
2223 WREG32(mmCPU_CA53_CFG_ARM_RST_CONTROL, CPU_RESET_ASSERT);
2224 val = RREG32(mmCPU_CA53_CFG_ARM_RST_CONTROL);
2225
2226 /* Reset the CA53 MACRO */
2227 unit_rst_val = RREG32(mmPSOC_GLOBAL_CONF_UNIT_RST_N);
2228 WREG32(mmPSOC_GLOBAL_CONF_UNIT_RST_N, CA53_RESET);
2229 val = RREG32(mmPSOC_GLOBAL_CONF_UNIT_RST_N);
2230 WREG32(mmPSOC_GLOBAL_CONF_UNIT_RST_N, unit_rst_val);
2231 val = RREG32(mmPSOC_GLOBAL_CONF_UNIT_RST_N);
2232
2233 snprintf(fw_name, sizeof(fw_name), "habanalabs/goya/goya-u-boot.bin");
2234 dst = hdev->pcie_bar[SRAM_CFG_BAR_ID] + UBOOT_FW_OFFSET;
2235 rc = goya_push_fw_to_device(hdev, fw_name, dst);
2236 if (rc)
2237 return rc;
2238
2239 snprintf(fw_name, sizeof(fw_name), "habanalabs/goya/goya-fit.itb");
2240 dst = hdev->pcie_bar[DDR_BAR_ID] + LINUX_FW_OFFSET;
2241 rc = goya_push_fw_to_device(hdev, fw_name, dst);
2242 if (rc)
2243 return rc;
2244
2245 WREG32(mmPSOC_GLOBAL_CONF_UBOOT_MAGIC, KMD_MSG_FIT_RDY);
2246 WREG32(mmPSOC_GLOBAL_CONF_WARM_REBOOT, CPU_BOOT_STATUS_NA);
2247
2248 WREG32(mmCPU_CA53_CFG_RST_ADDR_LSB_0,
2249 lower_32_bits(SRAM_BASE_ADDR + UBOOT_FW_OFFSET));
2250 WREG32(mmCPU_CA53_CFG_RST_ADDR_MSB_0,
2251 upper_32_bits(SRAM_BASE_ADDR + UBOOT_FW_OFFSET));
2252
2253 /* Release ARM core 0 from reset */
2254 WREG32(mmCPU_CA53_CFG_ARM_RST_CONTROL,
2255 CPU_RESET_CORE0_DEASSERT);
2256 val = RREG32(mmCPU_CA53_CFG_ARM_RST_CONTROL);
2257
2258 return 0;
2259}
2260
2261/*
2262 * FW component passes an offset from SRAM_BASE_ADDR in SCRATCHPAD_xx.
2263 * The version string should be located by that offset.
2264 */
2265static void goya_read_device_fw_version(struct hl_device *hdev,
2266 enum goya_fw_component fwc)
2267{
2268 const char *name;
2269 u32 ver_off;
2270 char *dest;
2271
2272 switch (fwc) {
2273 case FW_COMP_UBOOT:
2274 ver_off = RREG32(mmPSOC_GLOBAL_CONF_SCRATCHPAD_29);
2275 dest = hdev->asic_prop.uboot_ver;
2276 name = "U-Boot";
2277 break;
2278 case FW_COMP_PREBOOT:
2279 ver_off = RREG32(mmPSOC_GLOBAL_CONF_SCRATCHPAD_28);
2280 dest = hdev->asic_prop.preboot_ver;
2281 name = "Preboot";
2282 break;
2283 default:
2284 dev_warn(hdev->dev, "Undefined FW component: %d\n", fwc);
2285 return;
2286 }
2287
2288 ver_off &= ~((u32)SRAM_BASE_ADDR);
2289
2290 if (ver_off < SRAM_SIZE - VERSION_MAX_LEN) {
2291 memcpy_fromio(dest, hdev->pcie_bar[SRAM_CFG_BAR_ID] + ver_off,
2292 VERSION_MAX_LEN);
2293 } else {
2294 dev_err(hdev->dev, "%s version offset (0x%x) is above SRAM\n",
2295 name, ver_off);
2296 strcpy(dest, "unavailable");
2297 }
2298}
2299
2300static int goya_init_cpu(struct hl_device *hdev, u32 cpu_timeout)
2301{
2302 struct goya_device *goya = hdev->asic_specific;
2303 char fw_name[200];
2304 void __iomem *dst;
2305 u32 status;
2306 int rc;
2307
2308 if (!hdev->cpu_enable)
2309 return 0;
2310
2311 if (goya->hw_cap_initialized & HW_CAP_CPU)
2312 return 0;
2313
2314 /*
2315 * Before pushing u-boot/linux to device, need to set the ddr bar to
2316 * base address of dram
2317 */
2318 rc = goya_set_ddr_bar_base(hdev, DRAM_PHYS_BASE);
2319 if (rc) {
2320 dev_err(hdev->dev,
2321 "failed to map DDR bar to DRAM base address\n");
2322 return rc;
2323 }
2324
2325 if (hdev->pldm) {
2326 rc = goya_pldm_init_cpu(hdev);
2327 if (rc)
2328 return rc;
2329
2330 goto out;
2331 }
2332
2333 /* Make sure CPU boot-loader is running */
2334 rc = hl_poll_timeout(
2335 hdev,
2336 mmPSOC_GLOBAL_CONF_WARM_REBOOT,
2337 status,
2338 (status == CPU_BOOT_STATUS_DRAM_RDY) ||
2339 (status == CPU_BOOT_STATUS_SRAM_AVAIL),
2340 10000,
2341 cpu_timeout);
2342
2343 if (rc) {
2344 dev_err(hdev->dev, "Error in ARM u-boot!");
2345 switch (status) {
2346 case CPU_BOOT_STATUS_NA:
2347 dev_err(hdev->dev,
2348 "ARM status %d - BTL did NOT run\n", status);
2349 break;
2350 case CPU_BOOT_STATUS_IN_WFE:
2351 dev_err(hdev->dev,
2352 "ARM status %d - Inside WFE loop\n", status);
2353 break;
2354 case CPU_BOOT_STATUS_IN_BTL:
2355 dev_err(hdev->dev,
2356 "ARM status %d - Stuck in BTL\n", status);
2357 break;
2358 case CPU_BOOT_STATUS_IN_PREBOOT:
2359 dev_err(hdev->dev,
2360 "ARM status %d - Stuck in Preboot\n", status);
2361 break;
2362 case CPU_BOOT_STATUS_IN_SPL:
2363 dev_err(hdev->dev,
2364 "ARM status %d - Stuck in SPL\n", status);
2365 break;
2366 case CPU_BOOT_STATUS_IN_UBOOT:
2367 dev_err(hdev->dev,
2368 "ARM status %d - Stuck in u-boot\n", status);
2369 break;
2370 case CPU_BOOT_STATUS_DRAM_INIT_FAIL:
2371 dev_err(hdev->dev,
2372 "ARM status %d - DDR initialization failed\n",
2373 status);
2374 break;
2375 default:
2376 dev_err(hdev->dev,
2377 "ARM status %d - Invalid status code\n",
2378 status);
2379 break;
2380 }
2381 return -EIO;
2382 }
2383
2384 /* Read U-Boot version now in case we will later fail */
2385 goya_read_device_fw_version(hdev, FW_COMP_UBOOT);
2386 goya_read_device_fw_version(hdev, FW_COMP_PREBOOT);
2387
2388 if (status == CPU_BOOT_STATUS_SRAM_AVAIL)
2389 goto out;
2390
2391 if (!hdev->fw_loading) {
2392 dev_info(hdev->dev, "Skip loading FW\n");
2393 goto out;
2394 }
2395
2396 snprintf(fw_name, sizeof(fw_name), "habanalabs/goya/goya-fit.itb");
2397 dst = hdev->pcie_bar[DDR_BAR_ID] + LINUX_FW_OFFSET;
2398 rc = goya_push_fw_to_device(hdev, fw_name, dst);
2399 if (rc)
2400 return rc;
2401
2402 WREG32(mmPSOC_GLOBAL_CONF_UBOOT_MAGIC, KMD_MSG_FIT_RDY);
2403
2404 rc = hl_poll_timeout(
2405 hdev,
2406 mmPSOC_GLOBAL_CONF_WARM_REBOOT,
2407 status,
2408 (status == CPU_BOOT_STATUS_SRAM_AVAIL),
2409 10000,
2410 cpu_timeout);
2411
2412 if (rc) {
2413 if (status == CPU_BOOT_STATUS_FIT_CORRUPTED)
2414 dev_err(hdev->dev,
2415 "ARM u-boot reports FIT image is corrupted\n");
2416 else
2417 dev_err(hdev->dev,
2418 "ARM Linux failed to load, %d\n", status);
2419 WREG32(mmPSOC_GLOBAL_CONF_UBOOT_MAGIC, KMD_MSG_NA);
2420 return -EIO;
2421 }
2422
2423 dev_info(hdev->dev, "Successfully loaded firmware to device\n");
2424
2425out:
2426 goya->hw_cap_initialized |= HW_CAP_CPU;
2427
2428 return 0;
2429}
2430
2431/*
2432 * goya_hw_init - Goya hardware initialization code
2433 *
2434 * @hdev: pointer to hl_device structure
2435 *
2436 * Returns 0 on success
2437 *
2438 */
2439static int goya_hw_init(struct hl_device *hdev)
2440{
2441 struct asic_fixed_properties *prop = &hdev->asic_prop;
2442 u32 val;
2443 int rc;
2444
2445 dev_info(hdev->dev, "Starting initialization of H/W\n");
2446
2447 /* Perform read from the device to make sure device is up */
2448 val = RREG32(mmPCIE_DBI_DEVICE_ID_VENDOR_ID_REG);
2449
2450 rc = goya_init_cpu(hdev, GOYA_CPU_TIMEOUT_USEC);
2451 if (rc) {
2452 dev_err(hdev->dev, "failed to initialize CPU\n");
2453 return rc;
2454 }
2455
2456 goya_tpc_mbist_workaround(hdev);
2457
2458 goya_init_golden_registers(hdev);
2459
2460 /*
2461 * After CPU initialization is finished, change DDR bar mapping inside
2462 * iATU to point to the start address of the MMU page tables
2463 */
2464 rc = goya_set_ddr_bar_base(hdev, DRAM_PHYS_BASE +
2465 (MMU_PAGE_TABLES_ADDR & ~(prop->dram_pci_bar_size - 0x1ull)));
2466 if (rc) {
2467 dev_err(hdev->dev,
2468 "failed to map DDR bar to MMU page tables\n");
2469 return rc;
2470 }
2471
2472 goya_init_security(hdev);
2473
Oded Gabbay9494a8d2019-02-16 00:39:17 +02002474 goya_init_dma_qmans(hdev);
2475
2476 goya_init_mme_qmans(hdev);
2477
2478 goya_init_tpc_qmans(hdev);
2479
Oded Gabbay1251f232019-02-16 00:39:18 +02002480 /* MSI-X must be enabled before CPU queues are initialized */
2481 rc = goya_enable_msix(hdev);
2482 if (rc)
2483 goto disable_queues;
2484
Oded Gabbay9494a8d2019-02-16 00:39:17 +02002485 rc = goya_init_cpu_queues(hdev);
2486 if (rc) {
2487 dev_err(hdev->dev, "failed to initialize CPU H/W queues %d\n",
2488 rc);
Oded Gabbay1251f232019-02-16 00:39:18 +02002489 goto disable_msix;
Oded Gabbay9494a8d2019-02-16 00:39:17 +02002490 }
2491
Oded Gabbay839c4802019-02-16 00:39:16 +02002492 /* CPU initialization is finished, we can now move to 48 bit DMA mask */
2493 rc = pci_set_dma_mask(hdev->pdev, DMA_BIT_MASK(48));
2494 if (rc) {
2495 dev_warn(hdev->dev, "Unable to set pci dma mask to 48 bits\n");
2496 rc = pci_set_dma_mask(hdev->pdev, DMA_BIT_MASK(32));
2497 if (rc) {
2498 dev_err(hdev->dev,
2499 "Unable to set pci dma mask to 32 bits\n");
Oded Gabbay9494a8d2019-02-16 00:39:17 +02002500 goto disable_pci_access;
Oded Gabbay839c4802019-02-16 00:39:16 +02002501 }
2502 }
2503
2504 rc = pci_set_consistent_dma_mask(hdev->pdev, DMA_BIT_MASK(48));
2505 if (rc) {
2506 dev_warn(hdev->dev,
2507 "Unable to set pci consistent dma mask to 48 bits\n");
2508 rc = pci_set_consistent_dma_mask(hdev->pdev, DMA_BIT_MASK(32));
2509 if (rc) {
2510 dev_err(hdev->dev,
2511 "Unable to set pci consistent dma mask to 32 bits\n");
Oded Gabbay9494a8d2019-02-16 00:39:17 +02002512 goto disable_pci_access;
Oded Gabbay839c4802019-02-16 00:39:16 +02002513 }
2514 }
2515
2516 /* Perform read from the device to flush all MSI-X configuration */
2517 val = RREG32(mmPCIE_DBI_DEVICE_ID_VENDOR_ID_REG);
2518
2519 return 0;
Oded Gabbay9494a8d2019-02-16 00:39:17 +02002520
2521disable_pci_access:
2522 goya_send_pci_access_msg(hdev, ARMCP_PACKET_DISABLE_PCI_ACCESS);
Oded Gabbay1251f232019-02-16 00:39:18 +02002523disable_msix:
2524 goya_disable_msix(hdev);
Oded Gabbay9494a8d2019-02-16 00:39:17 +02002525disable_queues:
2526 goya_disable_internal_queues(hdev);
2527 goya_disable_external_queues(hdev);
2528
2529 return rc;
Oded Gabbay839c4802019-02-16 00:39:16 +02002530}
2531
2532/*
2533 * goya_hw_fini - Goya hardware tear-down code
2534 *
2535 * @hdev: pointer to hl_device structure
2536 * @hard_reset: should we do hard reset to all engines or just reset the
2537 * compute/dma engines
2538 */
2539static void goya_hw_fini(struct hl_device *hdev, bool hard_reset)
2540{
2541 struct goya_device *goya = hdev->asic_specific;
2542 u32 reset_timeout_ms, status;
2543
2544 if (hdev->pldm)
2545 reset_timeout_ms = GOYA_PLDM_RESET_TIMEOUT_MSEC;
2546 else
2547 reset_timeout_ms = GOYA_RESET_TIMEOUT_MSEC;
2548
2549 if (hard_reset) {
2550 goya_set_ddr_bar_base(hdev, DRAM_PHYS_BASE);
2551 goya_disable_clk_rlx(hdev);
2552 goya_set_pll_refclk(hdev);
2553
2554 WREG32(mmPSOC_GLOBAL_CONF_SW_ALL_RST_CFG, RESET_ALL);
2555 dev_info(hdev->dev,
2556 "Issued HARD reset command, going to wait %dms\n",
2557 reset_timeout_ms);
2558 } else {
2559 WREG32(mmPSOC_GLOBAL_CONF_SW_ALL_RST_CFG, DMA_MME_TPC_RESET);
2560 dev_info(hdev->dev,
2561 "Issued SOFT reset command, going to wait %dms\n",
2562 reset_timeout_ms);
2563 }
2564
2565 /*
2566 * After hard reset, we can't poll the BTM_FSM register because the PSOC
2567 * itself is in reset. In either reset we need to wait until the reset
2568 * is deasserted
2569 */
2570 msleep(reset_timeout_ms);
2571
2572 status = RREG32(mmPSOC_GLOBAL_CONF_BTM_FSM);
2573 if (status & PSOC_GLOBAL_CONF_BTM_FSM_STATE_MASK)
2574 dev_err(hdev->dev,
2575 "Timeout while waiting for device to reset 0x%x\n",
2576 status);
2577
2578 /* Chicken bit to re-initiate boot sequencer flow */
2579 WREG32(mmPSOC_GLOBAL_CONF_BOOT_SEQ_RE_START,
2580 1 << PSOC_GLOBAL_CONF_BOOT_SEQ_RE_START_IND_SHIFT);
2581 /* Move boot manager FSM to pre boot sequencer init state */
2582 WREG32(mmPSOC_GLOBAL_CONF_SW_BTM_FSM,
2583 0xA << PSOC_GLOBAL_CONF_SW_BTM_FSM_CTRL_SHIFT);
2584
2585 goya->hw_cap_initialized &= ~(HW_CAP_CPU | HW_CAP_CPU_Q |
2586 HW_CAP_DDR_0 | HW_CAP_DDR_1 |
2587 HW_CAP_DMA | HW_CAP_MME |
2588 HW_CAP_MMU | HW_CAP_TPC_MBIST |
2589 HW_CAP_GOLDEN | HW_CAP_TPC);
Oded Gabbay1251f232019-02-16 00:39:18 +02002590 memset(goya->events_stat, 0, sizeof(goya->events_stat));
Oded Gabbay839c4802019-02-16 00:39:16 +02002591
2592 if (!hdev->pldm) {
2593 int rc;
2594 /* In case we are running inside VM and the VM is
2595 * shutting down, we need to make sure CPU boot-loader
2596 * is running before we can continue the VM shutdown.
2597 * That is because the VM will send an FLR signal that
2598 * we must answer
2599 */
2600 dev_info(hdev->dev,
2601 "Going to wait up to %ds for CPU boot loader\n",
2602 GOYA_CPU_TIMEOUT_USEC / 1000 / 1000);
2603
2604 rc = hl_poll_timeout(
2605 hdev,
2606 mmPSOC_GLOBAL_CONF_WARM_REBOOT,
2607 status,
2608 (status == CPU_BOOT_STATUS_DRAM_RDY),
2609 10000,
2610 GOYA_CPU_TIMEOUT_USEC);
2611 if (rc)
2612 dev_err(hdev->dev,
2613 "failed to wait for CPU boot loader\n");
2614 }
2615}
2616
Oded Gabbay99b9d7b2019-02-16 00:39:13 +02002617int goya_suspend(struct hl_device *hdev)
2618{
Oded Gabbay9494a8d2019-02-16 00:39:17 +02002619 int rc;
2620
2621 rc = goya_stop_internal_queues(hdev);
2622
2623 if (rc) {
2624 dev_err(hdev->dev, "failed to stop internal queues\n");
2625 return rc;
2626 }
2627
2628 rc = goya_stop_external_queues(hdev);
2629
2630 if (rc) {
2631 dev_err(hdev->dev, "failed to stop external queues\n");
2632 return rc;
2633 }
2634
2635 rc = goya_send_pci_access_msg(hdev, ARMCP_PACKET_DISABLE_PCI_ACCESS);
2636 if (rc)
2637 dev_err(hdev->dev, "Failed to disable PCI access from CPU\n");
2638
2639 return rc;
Oded Gabbay99b9d7b2019-02-16 00:39:13 +02002640}
2641
2642int goya_resume(struct hl_device *hdev)
2643{
Oded Gabbay9494a8d2019-02-16 00:39:17 +02002644 int rc;
2645
2646 goya_resume_external_queues(hdev);
2647 goya_resume_internal_queues(hdev);
2648
2649 rc = goya_send_pci_access_msg(hdev, ARMCP_PACKET_ENABLE_PCI_ACCESS);
2650 if (rc)
2651 dev_err(hdev->dev, "Failed to enable PCI access from CPU\n");
2652 return rc;
Oded Gabbay99b9d7b2019-02-16 00:39:13 +02002653}
2654
Oded Gabbaybe5d9262019-02-16 00:39:15 +02002655int goya_mmap(struct hl_fpriv *hpriv, struct vm_area_struct *vma)
2656{
2657 return -EINVAL;
2658}
2659
2660int goya_cb_mmap(struct hl_device *hdev, struct vm_area_struct *vma,
2661 u64 kaddress, phys_addr_t paddress, u32 size)
2662{
2663 int rc;
2664
2665 vma->vm_flags |= VM_IO | VM_PFNMAP | VM_DONTEXPAND | VM_DONTDUMP |
2666 VM_DONTCOPY | VM_NORESERVE;
2667
2668 rc = remap_pfn_range(vma, vma->vm_start, paddress >> PAGE_SHIFT,
2669 size, vma->vm_page_prot);
2670 if (rc)
2671 dev_err(hdev->dev, "remap_pfn_range error %d", rc);
2672
2673 return rc;
2674}
2675
Oded Gabbay9494a8d2019-02-16 00:39:17 +02002676void goya_ring_doorbell(struct hl_device *hdev, u32 hw_queue_id, u32 pi)
2677{
2678 u32 db_reg_offset, db_value;
2679 bool invalid_queue = false;
2680
2681 switch (hw_queue_id) {
2682 case GOYA_QUEUE_ID_DMA_0:
2683 db_reg_offset = mmDMA_QM_0_PQ_PI;
2684 break;
2685
2686 case GOYA_QUEUE_ID_DMA_1:
2687 db_reg_offset = mmDMA_QM_1_PQ_PI;
2688 break;
2689
2690 case GOYA_QUEUE_ID_DMA_2:
2691 db_reg_offset = mmDMA_QM_2_PQ_PI;
2692 break;
2693
2694 case GOYA_QUEUE_ID_DMA_3:
2695 db_reg_offset = mmDMA_QM_3_PQ_PI;
2696 break;
2697
2698 case GOYA_QUEUE_ID_DMA_4:
2699 db_reg_offset = mmDMA_QM_4_PQ_PI;
2700 break;
2701
2702 case GOYA_QUEUE_ID_CPU_PQ:
2703 if (hdev->cpu_queues_enable)
2704 db_reg_offset = mmCPU_IF_PF_PQ_PI;
2705 else
2706 invalid_queue = true;
2707 break;
2708
2709 case GOYA_QUEUE_ID_MME:
2710 db_reg_offset = mmMME_QM_PQ_PI;
2711 break;
2712
2713 case GOYA_QUEUE_ID_TPC0:
2714 db_reg_offset = mmTPC0_QM_PQ_PI;
2715 break;
2716
2717 case GOYA_QUEUE_ID_TPC1:
2718 db_reg_offset = mmTPC1_QM_PQ_PI;
2719 break;
2720
2721 case GOYA_QUEUE_ID_TPC2:
2722 db_reg_offset = mmTPC2_QM_PQ_PI;
2723 break;
2724
2725 case GOYA_QUEUE_ID_TPC3:
2726 db_reg_offset = mmTPC3_QM_PQ_PI;
2727 break;
2728
2729 case GOYA_QUEUE_ID_TPC4:
2730 db_reg_offset = mmTPC4_QM_PQ_PI;
2731 break;
2732
2733 case GOYA_QUEUE_ID_TPC5:
2734 db_reg_offset = mmTPC5_QM_PQ_PI;
2735 break;
2736
2737 case GOYA_QUEUE_ID_TPC6:
2738 db_reg_offset = mmTPC6_QM_PQ_PI;
2739 break;
2740
2741 case GOYA_QUEUE_ID_TPC7:
2742 db_reg_offset = mmTPC7_QM_PQ_PI;
2743 break;
2744
2745 default:
2746 invalid_queue = true;
2747 }
2748
2749 if (invalid_queue) {
2750 /* Should never get here */
2751 dev_err(hdev->dev, "h/w queue %d is invalid. Can't set pi\n",
2752 hw_queue_id);
2753 return;
2754 }
2755
2756 db_value = pi;
2757
2758 /* ring the doorbell */
2759 WREG32(db_reg_offset, db_value);
2760
2761 if (hw_queue_id == GOYA_QUEUE_ID_CPU_PQ)
2762 WREG32(mmGIC_DISTRIBUTOR__5_GICD_SETSPI_NSR,
2763 GOYA_ASYNC_EVENT_ID_PI_UPDATE);
2764}
2765
2766void goya_flush_pq_write(struct hl_device *hdev, u64 *pq, u64 exp_val)
2767{
2768 /* Not needed in Goya */
2769}
2770
Oded Gabbay99b9d7b2019-02-16 00:39:13 +02002771void *goya_dma_alloc_coherent(struct hl_device *hdev, size_t size,
2772 dma_addr_t *dma_handle, gfp_t flags)
2773{
2774 return dma_alloc_coherent(&hdev->pdev->dev, size, dma_handle, flags);
2775}
2776
2777void goya_dma_free_coherent(struct hl_device *hdev, size_t size, void *cpu_addr,
2778 dma_addr_t dma_handle)
2779{
2780 dma_free_coherent(&hdev->pdev->dev, size, cpu_addr, dma_handle);
2781}
2782
Oded Gabbay9494a8d2019-02-16 00:39:17 +02002783void *goya_get_int_queue_base(struct hl_device *hdev, u32 queue_id,
2784 dma_addr_t *dma_handle, u16 *queue_len)
2785{
2786 void *base;
2787 u32 offset;
2788
2789 *dma_handle = hdev->asic_prop.sram_base_address;
2790
2791 base = hdev->pcie_bar[SRAM_CFG_BAR_ID];
2792
2793 switch (queue_id) {
2794 case GOYA_QUEUE_ID_MME:
2795 offset = MME_QMAN_BASE_OFFSET;
2796 *queue_len = MME_QMAN_LENGTH;
2797 break;
2798 case GOYA_QUEUE_ID_TPC0:
2799 offset = TPC0_QMAN_BASE_OFFSET;
2800 *queue_len = TPC_QMAN_LENGTH;
2801 break;
2802 case GOYA_QUEUE_ID_TPC1:
2803 offset = TPC1_QMAN_BASE_OFFSET;
2804 *queue_len = TPC_QMAN_LENGTH;
2805 break;
2806 case GOYA_QUEUE_ID_TPC2:
2807 offset = TPC2_QMAN_BASE_OFFSET;
2808 *queue_len = TPC_QMAN_LENGTH;
2809 break;
2810 case GOYA_QUEUE_ID_TPC3:
2811 offset = TPC3_QMAN_BASE_OFFSET;
2812 *queue_len = TPC_QMAN_LENGTH;
2813 break;
2814 case GOYA_QUEUE_ID_TPC4:
2815 offset = TPC4_QMAN_BASE_OFFSET;
2816 *queue_len = TPC_QMAN_LENGTH;
2817 break;
2818 case GOYA_QUEUE_ID_TPC5:
2819 offset = TPC5_QMAN_BASE_OFFSET;
2820 *queue_len = TPC_QMAN_LENGTH;
2821 break;
2822 case GOYA_QUEUE_ID_TPC6:
2823 offset = TPC6_QMAN_BASE_OFFSET;
2824 *queue_len = TPC_QMAN_LENGTH;
2825 break;
2826 case GOYA_QUEUE_ID_TPC7:
2827 offset = TPC7_QMAN_BASE_OFFSET;
2828 *queue_len = TPC_QMAN_LENGTH;
2829 break;
2830 default:
2831 dev_err(hdev->dev, "Got invalid queue id %d\n", queue_id);
2832 return NULL;
2833 }
2834
2835 base += offset;
2836 *dma_handle += offset;
2837
2838 return base;
2839}
2840
2841int goya_send_cpu_message(struct hl_device *hdev, u32 *msg, u16 len,
2842 u32 timeout, long *result)
2843{
2844 struct goya_device *goya = hdev->asic_specific;
2845 struct armcp_packet *pkt;
2846 dma_addr_t pkt_dma_addr;
2847 u32 tmp;
2848 int rc = 0;
2849
2850 if (!(goya->hw_cap_initialized & HW_CAP_CPU_Q)) {
2851 if (result)
2852 *result = 0;
2853 return 0;
2854 }
2855
2856 if (len > CPU_CB_SIZE) {
2857 dev_err(hdev->dev, "Invalid CPU message size of %d bytes\n",
2858 len);
2859 return -ENOMEM;
2860 }
2861
2862 pkt = hdev->asic_funcs->cpu_accessible_dma_pool_alloc(hdev, len,
2863 &pkt_dma_addr);
2864 if (!pkt) {
2865 dev_err(hdev->dev,
2866 "Failed to allocate DMA memory for packet to CPU\n");
2867 return -ENOMEM;
2868 }
2869
2870 memcpy(pkt, msg, len);
2871
2872 mutex_lock(&hdev->send_cpu_message_lock);
2873
2874 if (hdev->disabled)
2875 goto out;
2876
2877 rc = hl_hw_queue_send_cb_no_cmpl(hdev, GOYA_QUEUE_ID_CPU_PQ, len,
2878 pkt_dma_addr);
2879 if (rc) {
2880 dev_err(hdev->dev, "Failed to send CB on CPU PQ (%d)\n", rc);
2881 goto out;
2882 }
2883
2884 rc = hl_poll_timeout_memory(hdev, (u64) (uintptr_t) &pkt->fence,
2885 timeout, &tmp);
2886
2887 hl_hw_queue_inc_ci_kernel(hdev, GOYA_QUEUE_ID_CPU_PQ);
2888
2889 if (rc == -ETIMEDOUT) {
2890 dev_err(hdev->dev,
2891 "Timeout while waiting for CPU packet fence\n");
2892 goto out;
2893 }
2894
2895 if (tmp == ARMCP_PACKET_FENCE_VAL) {
2896 rc = (pkt->ctl & ARMCP_PKT_CTL_RC_MASK) >>
2897 ARMCP_PKT_CTL_RC_SHIFT;
2898 if (rc) {
2899 dev_err(hdev->dev,
2900 "F/W ERROR %d for CPU packet %d\n",
2901 rc, (pkt->ctl & ARMCP_PKT_CTL_OPCODE_MASK)
2902 >> ARMCP_PKT_CTL_OPCODE_SHIFT);
2903 rc = -EINVAL;
2904 } else if (result) {
2905 *result = pkt->result;
2906 }
2907 } else {
2908 dev_err(hdev->dev, "CPU packet wrong fence value\n");
2909 rc = -EINVAL;
2910 }
2911
2912out:
2913 mutex_unlock(&hdev->send_cpu_message_lock);
2914
2915 hdev->asic_funcs->cpu_accessible_dma_pool_free(hdev, len, pkt);
2916
2917 return rc;
2918}
2919
2920int goya_test_queue(struct hl_device *hdev, u32 hw_queue_id)
2921{
2922 struct packet_msg_prot *fence_pkt;
2923 dma_addr_t pkt_dma_addr;
2924 u32 fence_val, tmp;
2925 dma_addr_t fence_dma_addr;
2926 u32 *fence_ptr;
2927 int rc;
2928
2929 fence_val = GOYA_QMAN0_FENCE_VAL;
2930
2931 fence_ptr = hdev->asic_funcs->dma_pool_zalloc(hdev, 4, GFP_KERNEL,
2932 &fence_dma_addr);
2933 if (!fence_ptr) {
2934 dev_err(hdev->dev,
2935 "Failed to allocate memory for queue testing\n");
2936 return -ENOMEM;
2937 }
2938
2939 *fence_ptr = 0;
2940
2941 fence_pkt = hdev->asic_funcs->dma_pool_zalloc(hdev,
2942 sizeof(struct packet_msg_prot),
2943 GFP_KERNEL, &pkt_dma_addr);
2944 if (!fence_pkt) {
2945 dev_err(hdev->dev,
2946 "Failed to allocate packet for queue testing\n");
2947 rc = -ENOMEM;
2948 goto free_fence_ptr;
2949 }
2950
2951 fence_pkt->ctl = (PACKET_MSG_PROT << GOYA_PKT_CTL_OPCODE_SHIFT) |
2952 (1 << GOYA_PKT_CTL_EB_SHIFT) |
2953 (1 << GOYA_PKT_CTL_MB_SHIFT);
2954 fence_pkt->value = fence_val;
2955 fence_pkt->addr = fence_dma_addr +
2956 hdev->asic_prop.host_phys_base_address;
2957
2958 rc = hl_hw_queue_send_cb_no_cmpl(hdev, hw_queue_id,
2959 sizeof(struct packet_msg_prot),
2960 pkt_dma_addr);
2961 if (rc) {
2962 dev_err(hdev->dev,
2963 "Failed to send fence packet\n");
2964 goto free_pkt;
2965 }
2966
2967 rc = hl_poll_timeout_memory(hdev, (u64) (uintptr_t) fence_ptr,
2968 GOYA_TEST_QUEUE_WAIT_USEC, &tmp);
2969
2970 hl_hw_queue_inc_ci_kernel(hdev, hw_queue_id);
2971
2972 if ((!rc) && (tmp == fence_val)) {
2973 dev_info(hdev->dev,
2974 "queue test on H/W queue %d succeeded\n",
2975 hw_queue_id);
2976 } else {
2977 dev_err(hdev->dev,
2978 "H/W queue %d test failed (scratch(0x%08llX) == 0x%08X)\n",
2979 hw_queue_id, (unsigned long long) fence_dma_addr, tmp);
2980 rc = -EINVAL;
2981 }
2982
2983free_pkt:
2984 hdev->asic_funcs->dma_pool_free(hdev, (void *) fence_pkt,
2985 pkt_dma_addr);
2986free_fence_ptr:
2987 hdev->asic_funcs->dma_pool_free(hdev, (void *) fence_ptr,
2988 fence_dma_addr);
2989 return rc;
2990}
2991
2992int goya_test_cpu_queue(struct hl_device *hdev)
2993{
2994 struct armcp_packet test_pkt;
2995 long result;
2996 int rc;
2997
2998 /* cpu_queues_enable flag is always checked in send cpu message */
2999
3000 memset(&test_pkt, 0, sizeof(test_pkt));
3001
3002 test_pkt.ctl = ARMCP_PACKET_TEST << ARMCP_PKT_CTL_OPCODE_SHIFT;
3003 test_pkt.value = ARMCP_PACKET_FENCE_VAL;
3004
3005 rc = hdev->asic_funcs->send_cpu_message(hdev, (u32 *) &test_pkt,
3006 sizeof(test_pkt), HL_DEVICE_TIMEOUT_USEC, &result);
3007
3008 if (!rc)
3009 dev_info(hdev->dev, "queue test on CPU queue succeeded\n");
3010 else
3011 dev_err(hdev->dev, "CPU queue test failed (0x%08lX)\n", result);
3012
3013 return rc;
3014}
3015
3016static int goya_test_queues(struct hl_device *hdev)
3017{
3018 struct goya_device *goya = hdev->asic_specific;
3019 int i, rc, ret_val = 0;
3020
3021 for (i = 0 ; i < NUMBER_OF_EXT_HW_QUEUES ; i++) {
3022 rc = goya_test_queue(hdev, i);
3023 if (rc)
3024 ret_val = -EINVAL;
3025 }
3026
3027 if (hdev->cpu_queues_enable) {
3028 rc = goya->test_cpu_queue(hdev);
3029 if (rc)
3030 ret_val = -EINVAL;
3031 }
3032
3033 return ret_val;
3034}
3035
3036void *goya_dma_pool_zalloc(struct hl_device *hdev, size_t size, gfp_t mem_flags,
3037 dma_addr_t *dma_handle)
3038{
3039 if (size > GOYA_DMA_POOL_BLK_SIZE)
3040 return NULL;
3041
3042 return dma_pool_zalloc(hdev->dma_pool, mem_flags, dma_handle);
3043}
3044
3045void goya_dma_pool_free(struct hl_device *hdev, void *vaddr,
3046 dma_addr_t dma_addr)
3047{
3048 dma_pool_free(hdev->dma_pool, vaddr, dma_addr);
3049}
3050
3051void *goya_cpu_accessible_dma_pool_alloc(struct hl_device *hdev, size_t size,
3052 dma_addr_t *dma_handle)
3053{
3054 u64 kernel_addr;
3055
3056 /* roundup to CPU_PKT_SIZE */
3057 size = (size + (CPU_PKT_SIZE - 1)) & CPU_PKT_MASK;
3058
3059 kernel_addr = gen_pool_alloc(hdev->cpu_accessible_dma_pool, size);
3060
3061 *dma_handle = hdev->cpu_accessible_dma_address +
3062 (kernel_addr - (u64) (uintptr_t) hdev->cpu_accessible_dma_mem);
3063
3064 return (void *) (uintptr_t) kernel_addr;
3065}
3066
3067void goya_cpu_accessible_dma_pool_free(struct hl_device *hdev, size_t size,
3068 void *vaddr)
3069{
3070 /* roundup to CPU_PKT_SIZE */
3071 size = (size + (CPU_PKT_SIZE - 1)) & CPU_PKT_MASK;
3072
3073 gen_pool_free(hdev->cpu_accessible_dma_pool, (u64) (uintptr_t) vaddr,
3074 size);
3075}
3076
Oded Gabbay1251f232019-02-16 00:39:18 +02003077static void goya_update_eq_ci(struct hl_device *hdev, u32 val)
3078{
3079 WREG32(mmPSOC_GLOBAL_CONF_SCRATCHPAD_6, val);
3080}
3081
3082static void goya_get_axi_name(struct hl_device *hdev, u32 agent_id,
3083 u16 event_type, char *axi_name, int len)
3084{
3085 if (!strcmp(goya_axi_name[agent_id], "DMA"))
3086 if (event_type >= GOYA_ASYNC_EVENT_ID_DMA0_CH)
3087 snprintf(axi_name, len, "DMA %d",
3088 event_type - GOYA_ASYNC_EVENT_ID_DMA0_CH);
3089 else
3090 snprintf(axi_name, len, "DMA %d",
3091 event_type - GOYA_ASYNC_EVENT_ID_DMA0_QM);
3092 else
3093 snprintf(axi_name, len, "%s", goya_axi_name[agent_id]);
3094}
3095
3096static void goya_print_razwi_info(struct hl_device *hdev, u64 reg,
3097 bool is_hbw, bool is_read, u16 event_type)
3098{
3099 u32 val, agent_id;
3100 char axi_name[10] = {0};
3101
3102 val = RREG32(reg);
3103
3104 if (is_hbw)
3105 agent_id = (val & GOYA_IRQ_HBW_AGENT_ID_MASK) >>
3106 GOYA_IRQ_HBW_AGENT_ID_SHIFT;
3107 else
3108 agent_id = (val & GOYA_IRQ_LBW_AGENT_ID_MASK) >>
3109 GOYA_IRQ_LBW_AGENT_ID_SHIFT;
3110
3111 if (agent_id >= GOYA_MAX_INITIATORS) {
3112 dev_err(hdev->dev,
3113 "Illegal %s %s with wrong initiator id %d, H/W IRQ %d\n",
3114 is_read ? "read from" : "write to",
3115 is_hbw ? "HBW" : "LBW",
3116 agent_id,
3117 event_type);
3118 } else {
3119 goya_get_axi_name(hdev, agent_id, event_type, axi_name,
3120 sizeof(axi_name));
3121 dev_err(hdev->dev, "Illegal %s by %s %s %s, H/W IRQ %d\n",
3122 is_read ? "read" : "write",
3123 axi_name,
3124 is_read ? "from" : "to",
3125 is_hbw ? "HBW" : "LBW",
3126 event_type);
3127 }
3128}
3129
3130static void goya_print_irq_info(struct hl_device *hdev, u16 event_type)
3131{
3132 struct goya_device *goya = hdev->asic_specific;
3133 bool is_hbw = false, is_read = false, is_info = false;
3134
3135 if (RREG32(mmDMA_MACRO_RAZWI_LBW_WT_VLD)) {
3136 goya_print_razwi_info(hdev, mmDMA_MACRO_RAZWI_LBW_WT_ID, is_hbw,
3137 is_read, event_type);
3138 WREG32(mmDMA_MACRO_RAZWI_LBW_WT_VLD, 0);
3139 is_info = true;
3140 }
3141 if (RREG32(mmDMA_MACRO_RAZWI_LBW_RD_VLD)) {
3142 is_read = true;
3143 goya_print_razwi_info(hdev, mmDMA_MACRO_RAZWI_LBW_RD_ID, is_hbw,
3144 is_read, event_type);
3145 WREG32(mmDMA_MACRO_RAZWI_LBW_RD_VLD, 0);
3146 is_info = true;
3147 }
3148 if (RREG32(mmDMA_MACRO_RAZWI_HBW_WT_VLD)) {
3149 is_hbw = true;
3150 goya_print_razwi_info(hdev, mmDMA_MACRO_RAZWI_HBW_WT_ID, is_hbw,
3151 is_read, event_type);
3152 WREG32(mmDMA_MACRO_RAZWI_HBW_WT_VLD, 0);
3153 is_info = true;
3154 }
3155 if (RREG32(mmDMA_MACRO_RAZWI_HBW_RD_VLD)) {
3156 is_hbw = true;
3157 is_read = true;
3158 goya_print_razwi_info(hdev, mmDMA_MACRO_RAZWI_HBW_RD_ID, is_hbw,
3159 is_read, event_type);
3160 WREG32(mmDMA_MACRO_RAZWI_HBW_RD_VLD, 0);
3161 is_info = true;
3162 }
3163 if (!is_info) {
3164 dev_err(hdev->dev,
3165 "Received H/W interrupt %d, no additional info\n",
3166 event_type);
3167 return;
3168 }
3169
3170 if (goya->hw_cap_initialized & HW_CAP_MMU) {
3171 u32 val = RREG32(mmMMU_PAGE_ERROR_CAPTURE);
3172 u64 addr;
3173
3174 if (val & MMU_PAGE_ERROR_CAPTURE_ENTRY_VALID_MASK) {
3175 addr = val & MMU_PAGE_ERROR_CAPTURE_VA_49_32_MASK;
3176 addr <<= 32;
3177 addr |= RREG32(mmMMU_PAGE_ERROR_CAPTURE_VA);
3178
3179 dev_err(hdev->dev, "MMU page fault on va 0x%llx\n",
3180 addr);
3181
3182 WREG32(mmMMU_PAGE_ERROR_CAPTURE, 0);
3183 }
3184 }
3185}
3186
3187static int goya_unmask_irq(struct hl_device *hdev, u16 event_type)
3188{
3189 struct armcp_packet pkt;
3190 long result;
3191 int rc;
3192
3193 memset(&pkt, 0, sizeof(pkt));
3194
3195 pkt.ctl = ARMCP_PACKET_UNMASK_RAZWI_IRQ << ARMCP_PKT_CTL_OPCODE_SHIFT;
3196 pkt.value = event_type;
3197
3198 rc = hdev->asic_funcs->send_cpu_message(hdev, (u32 *) &pkt, sizeof(pkt),
3199 HL_DEVICE_TIMEOUT_USEC, &result);
3200
3201 if (rc)
3202 dev_err(hdev->dev, "failed to unmask RAZWI IRQ %d", event_type);
3203
3204 return rc;
3205}
3206
3207void goya_handle_eqe(struct hl_device *hdev, struct hl_eq_entry *eq_entry)
3208{
3209 u16 event_type = ((eq_entry->hdr.ctl & EQ_CTL_EVENT_TYPE_MASK)
3210 >> EQ_CTL_EVENT_TYPE_SHIFT);
3211 struct goya_device *goya = hdev->asic_specific;
3212
3213 goya->events_stat[event_type]++;
3214
3215 switch (event_type) {
3216 case GOYA_ASYNC_EVENT_ID_PCIE_IF:
3217 case GOYA_ASYNC_EVENT_ID_TPC0_ECC:
3218 case GOYA_ASYNC_EVENT_ID_TPC1_ECC:
3219 case GOYA_ASYNC_EVENT_ID_TPC2_ECC:
3220 case GOYA_ASYNC_EVENT_ID_TPC3_ECC:
3221 case GOYA_ASYNC_EVENT_ID_TPC4_ECC:
3222 case GOYA_ASYNC_EVENT_ID_TPC5_ECC:
3223 case GOYA_ASYNC_EVENT_ID_TPC6_ECC:
3224 case GOYA_ASYNC_EVENT_ID_TPC7_ECC:
3225 case GOYA_ASYNC_EVENT_ID_MME_ECC:
3226 case GOYA_ASYNC_EVENT_ID_MME_ECC_EXT:
3227 case GOYA_ASYNC_EVENT_ID_MMU_ECC:
3228 case GOYA_ASYNC_EVENT_ID_DMA_MACRO:
3229 case GOYA_ASYNC_EVENT_ID_DMA_ECC:
3230 case GOYA_ASYNC_EVENT_ID_CPU_IF_ECC:
3231 case GOYA_ASYNC_EVENT_ID_PSOC_MEM:
3232 case GOYA_ASYNC_EVENT_ID_PSOC_CORESIGHT:
3233 case GOYA_ASYNC_EVENT_ID_SRAM0 ... GOYA_ASYNC_EVENT_ID_SRAM29:
3234 case GOYA_ASYNC_EVENT_ID_GIC500:
3235 case GOYA_ASYNC_EVENT_ID_PLL0:
3236 case GOYA_ASYNC_EVENT_ID_PLL1:
3237 case GOYA_ASYNC_EVENT_ID_PLL3:
3238 case GOYA_ASYNC_EVENT_ID_PLL4:
3239 case GOYA_ASYNC_EVENT_ID_PLL5:
3240 case GOYA_ASYNC_EVENT_ID_PLL6:
3241 case GOYA_ASYNC_EVENT_ID_AXI_ECC:
3242 case GOYA_ASYNC_EVENT_ID_L2_RAM_ECC:
3243 case GOYA_ASYNC_EVENT_ID_PSOC_GPIO_05_SW_RESET:
3244 case GOYA_ASYNC_EVENT_ID_PSOC_GPIO_10_VRHOT_ICRIT:
3245 dev_err(hdev->dev,
3246 "Received H/W interrupt %d, reset the chip\n",
3247 event_type);
3248 break;
3249
3250 case GOYA_ASYNC_EVENT_ID_PCIE_DEC:
3251 case GOYA_ASYNC_EVENT_ID_TPC0_DEC:
3252 case GOYA_ASYNC_EVENT_ID_TPC1_DEC:
3253 case GOYA_ASYNC_EVENT_ID_TPC2_DEC:
3254 case GOYA_ASYNC_EVENT_ID_TPC3_DEC:
3255 case GOYA_ASYNC_EVENT_ID_TPC4_DEC:
3256 case GOYA_ASYNC_EVENT_ID_TPC5_DEC:
3257 case GOYA_ASYNC_EVENT_ID_TPC6_DEC:
3258 case GOYA_ASYNC_EVENT_ID_TPC7_DEC:
3259 case GOYA_ASYNC_EVENT_ID_MME_WACS:
3260 case GOYA_ASYNC_EVENT_ID_MME_WACSD:
3261 case GOYA_ASYNC_EVENT_ID_CPU_AXI_SPLITTER:
3262 case GOYA_ASYNC_EVENT_ID_PSOC_AXI_DEC:
3263 case GOYA_ASYNC_EVENT_ID_PSOC:
3264 case GOYA_ASYNC_EVENT_ID_TPC0_KRN_ERR:
3265 case GOYA_ASYNC_EVENT_ID_TPC1_KRN_ERR:
3266 case GOYA_ASYNC_EVENT_ID_TPC2_KRN_ERR:
3267 case GOYA_ASYNC_EVENT_ID_TPC3_KRN_ERR:
3268 case GOYA_ASYNC_EVENT_ID_TPC4_KRN_ERR:
3269 case GOYA_ASYNC_EVENT_ID_TPC5_KRN_ERR:
3270 case GOYA_ASYNC_EVENT_ID_TPC6_KRN_ERR:
3271 case GOYA_ASYNC_EVENT_ID_TPC7_KRN_ERR:
3272 case GOYA_ASYNC_EVENT_ID_TPC0_CMDQ ... GOYA_ASYNC_EVENT_ID_TPC7_QM:
3273 case GOYA_ASYNC_EVENT_ID_MME_QM:
3274 case GOYA_ASYNC_EVENT_ID_MME_CMDQ:
3275 case GOYA_ASYNC_EVENT_ID_DMA0_QM ... GOYA_ASYNC_EVENT_ID_DMA4_QM:
3276 case GOYA_ASYNC_EVENT_ID_DMA0_CH ... GOYA_ASYNC_EVENT_ID_DMA4_CH:
3277 goya_print_irq_info(hdev, event_type);
3278 goya_unmask_irq(hdev, event_type);
3279 break;
3280
3281 case GOYA_ASYNC_EVENT_ID_TPC0_BMON_SPMU:
3282 case GOYA_ASYNC_EVENT_ID_TPC1_BMON_SPMU:
3283 case GOYA_ASYNC_EVENT_ID_TPC2_BMON_SPMU:
3284 case GOYA_ASYNC_EVENT_ID_TPC3_BMON_SPMU:
3285 case GOYA_ASYNC_EVENT_ID_TPC4_BMON_SPMU:
3286 case GOYA_ASYNC_EVENT_ID_TPC5_BMON_SPMU:
3287 case GOYA_ASYNC_EVENT_ID_TPC6_BMON_SPMU:
3288 case GOYA_ASYNC_EVENT_ID_TPC7_BMON_SPMU:
3289 case GOYA_ASYNC_EVENT_ID_DMA_BM_CH0:
3290 case GOYA_ASYNC_EVENT_ID_DMA_BM_CH1:
3291 case GOYA_ASYNC_EVENT_ID_DMA_BM_CH2:
3292 case GOYA_ASYNC_EVENT_ID_DMA_BM_CH3:
3293 case GOYA_ASYNC_EVENT_ID_DMA_BM_CH4:
3294 dev_info(hdev->dev, "Received H/W interrupt %d\n", event_type);
3295 break;
3296
3297 default:
3298 dev_err(hdev->dev, "Received invalid H/W interrupt %d\n",
3299 event_type);
3300 break;
3301 }
3302}
3303
3304void *goya_get_events_stat(struct hl_device *hdev, u32 *size)
3305{
3306 struct goya_device *goya = hdev->asic_specific;
3307
3308 *size = (u32) sizeof(goya->events_stat);
3309
3310 return goya->events_stat;
3311}
3312
Oded Gabbayd91389b2019-02-16 00:39:19 +02003313static int goya_armcp_info_get(struct hl_device *hdev)
3314{
3315 struct goya_device *goya = hdev->asic_specific;
3316 struct asic_fixed_properties *prop = &hdev->asic_prop;
3317 struct armcp_packet pkt;
3318 void *armcp_info_cpu_addr;
3319 dma_addr_t armcp_info_dma_addr;
3320 u64 dram_size;
3321 long result;
3322 int rc;
3323
3324 if (!(goya->hw_cap_initialized & HW_CAP_CPU_Q))
3325 return 0;
3326
3327 armcp_info_cpu_addr =
3328 hdev->asic_funcs->cpu_accessible_dma_pool_alloc(hdev,
3329 sizeof(struct armcp_info), &armcp_info_dma_addr);
3330 if (!armcp_info_cpu_addr) {
3331 dev_err(hdev->dev,
3332 "Failed to allocate DMA memory for ArmCP info packet\n");
3333 return -ENOMEM;
3334 }
3335
3336 memset(armcp_info_cpu_addr, 0, sizeof(struct armcp_info));
3337
3338 memset(&pkt, 0, sizeof(pkt));
3339
3340 pkt.ctl = ARMCP_PACKET_INFO_GET << ARMCP_PKT_CTL_OPCODE_SHIFT;
3341 pkt.addr = armcp_info_dma_addr + prop->host_phys_base_address;
3342 pkt.data_max_size = sizeof(struct armcp_info);
3343
3344 rc = hdev->asic_funcs->send_cpu_message(hdev, (u32 *) &pkt, sizeof(pkt),
3345 GOYA_ARMCP_INFO_TIMEOUT, &result);
3346
3347 if (rc) {
3348 dev_err(hdev->dev,
3349 "Failed to send armcp info pkt, error %d\n", rc);
3350 goto out;
3351 }
3352
3353 memcpy(&prop->armcp_info, armcp_info_cpu_addr,
3354 sizeof(prop->armcp_info));
3355
3356 dram_size = prop->armcp_info.dram_size;
3357 if (dram_size) {
3358 if ((!is_power_of_2(dram_size)) ||
3359 (dram_size < DRAM_PHYS_DEFAULT_SIZE)) {
3360 dev_err(hdev->dev,
3361 "F/W reported invalid DRAM size %llu. Trying to use default size\n",
3362 dram_size);
3363 dram_size = DRAM_PHYS_DEFAULT_SIZE;
3364 }
3365
3366 prop->dram_size = dram_size;
3367 prop->dram_end_address = prop->dram_base_address + dram_size;
3368 }
3369
3370 rc = hl_build_hwmon_channel_info(hdev, prop->armcp_info.sensors);
3371 if (rc) {
3372 dev_err(hdev->dev,
3373 "Failed to build hwmon channel info, error %d\n", rc);
3374 rc = -EFAULT;
3375 goto out;
3376 }
3377
3378out:
3379 hdev->asic_funcs->cpu_accessible_dma_pool_free(hdev,
3380 sizeof(struct armcp_info), armcp_info_cpu_addr);
3381
3382 return rc;
3383}
3384
3385static void goya_init_clock_gating(struct hl_device *hdev)
3386{
3387
3388}
3389
3390static void goya_disable_clock_gating(struct hl_device *hdev)
3391{
3392
3393}
Oded Gabbay9494a8d2019-02-16 00:39:17 +02003394
3395static void goya_hw_queues_lock(struct hl_device *hdev)
3396{
3397 struct goya_device *goya = hdev->asic_specific;
3398
3399 spin_lock(&goya->hw_queues_lock);
3400}
3401
3402static void goya_hw_queues_unlock(struct hl_device *hdev)
3403{
3404 struct goya_device *goya = hdev->asic_specific;
3405
3406 spin_unlock(&goya->hw_queues_lock);
3407}
3408
Oded Gabbayd91389b2019-02-16 00:39:19 +02003409int goya_get_eeprom_data(struct hl_device *hdev, void *data, size_t max_size)
3410{
3411 struct goya_device *goya = hdev->asic_specific;
3412 struct asic_fixed_properties *prop = &hdev->asic_prop;
3413 struct armcp_packet pkt;
3414 void *eeprom_info_cpu_addr;
3415 dma_addr_t eeprom_info_dma_addr;
3416 long result;
3417 int rc;
3418
3419 if (!(goya->hw_cap_initialized & HW_CAP_CPU_Q))
3420 return 0;
3421
3422 eeprom_info_cpu_addr =
3423 hdev->asic_funcs->cpu_accessible_dma_pool_alloc(hdev,
3424 max_size, &eeprom_info_dma_addr);
3425 if (!eeprom_info_cpu_addr) {
3426 dev_err(hdev->dev,
3427 "Failed to allocate DMA memory for EEPROM info packet\n");
3428 return -ENOMEM;
3429 }
3430
3431 memset(eeprom_info_cpu_addr, 0, max_size);
3432
3433 memset(&pkt, 0, sizeof(pkt));
3434
3435 pkt.ctl = ARMCP_PACKET_EEPROM_DATA_GET << ARMCP_PKT_CTL_OPCODE_SHIFT;
3436 pkt.addr = eeprom_info_dma_addr + prop->host_phys_base_address;
3437 pkt.data_max_size = max_size;
3438
3439 rc = hdev->asic_funcs->send_cpu_message(hdev, (u32 *) &pkt, sizeof(pkt),
3440 GOYA_ARMCP_EEPROM_TIMEOUT, &result);
3441
3442 if (rc) {
3443 dev_err(hdev->dev,
3444 "Failed to send armcp EEPROM pkt, error %d\n", rc);
3445 goto out;
3446 }
3447
3448 /* result contains the actual size */
3449 memcpy(data, eeprom_info_cpu_addr, min((size_t)result, max_size));
3450
3451out:
3452 hdev->asic_funcs->cpu_accessible_dma_pool_free(hdev, max_size,
3453 eeprom_info_cpu_addr);
3454
3455 return rc;
3456}
3457
Oded Gabbay99b9d7b2019-02-16 00:39:13 +02003458static const struct hl_asic_funcs goya_funcs = {
3459 .early_init = goya_early_init,
3460 .early_fini = goya_early_fini,
Oded Gabbayd91389b2019-02-16 00:39:19 +02003461 .late_init = goya_late_init,
3462 .late_fini = goya_late_fini,
Oded Gabbay99b9d7b2019-02-16 00:39:13 +02003463 .sw_init = goya_sw_init,
3464 .sw_fini = goya_sw_fini,
Oded Gabbay839c4802019-02-16 00:39:16 +02003465 .hw_init = goya_hw_init,
3466 .hw_fini = goya_hw_fini,
Oded Gabbay1251f232019-02-16 00:39:18 +02003467 .halt_engines = goya_halt_engines,
Oded Gabbay99b9d7b2019-02-16 00:39:13 +02003468 .suspend = goya_suspend,
3469 .resume = goya_resume,
Oded Gabbaybe5d9262019-02-16 00:39:15 +02003470 .mmap = goya_mmap,
3471 .cb_mmap = goya_cb_mmap,
Oded Gabbay9494a8d2019-02-16 00:39:17 +02003472 .ring_doorbell = goya_ring_doorbell,
3473 .flush_pq_write = goya_flush_pq_write,
Oded Gabbay99b9d7b2019-02-16 00:39:13 +02003474 .dma_alloc_coherent = goya_dma_alloc_coherent,
3475 .dma_free_coherent = goya_dma_free_coherent,
Oded Gabbay9494a8d2019-02-16 00:39:17 +02003476 .get_int_queue_base = goya_get_int_queue_base,
3477 .test_queues = goya_test_queues,
3478 .dma_pool_zalloc = goya_dma_pool_zalloc,
3479 .dma_pool_free = goya_dma_pool_free,
3480 .cpu_accessible_dma_pool_alloc = goya_cpu_accessible_dma_pool_alloc,
3481 .cpu_accessible_dma_pool_free = goya_cpu_accessible_dma_pool_free,
Oded Gabbay1251f232019-02-16 00:39:18 +02003482 .update_eq_ci = goya_update_eq_ci,
Oded Gabbayd91389b2019-02-16 00:39:19 +02003483 .add_device_attr = goya_add_device_attr,
Oded Gabbay1251f232019-02-16 00:39:18 +02003484 .handle_eqe = goya_handle_eqe,
Oded Gabbayd91389b2019-02-16 00:39:19 +02003485 .set_pll_profile = goya_set_pll_profile,
Oded Gabbay1251f232019-02-16 00:39:18 +02003486 .get_events_stat = goya_get_events_stat,
Oded Gabbayd91389b2019-02-16 00:39:19 +02003487 .enable_clock_gating = goya_init_clock_gating,
3488 .disable_clock_gating = goya_disable_clock_gating,
Oded Gabbay9494a8d2019-02-16 00:39:17 +02003489 .hw_queues_lock = goya_hw_queues_lock,
3490 .hw_queues_unlock = goya_hw_queues_unlock,
Oded Gabbayd91389b2019-02-16 00:39:19 +02003491 .get_eeprom_data = goya_get_eeprom_data,
Oded Gabbay9494a8d2019-02-16 00:39:17 +02003492 .send_cpu_message = goya_send_cpu_message
Oded Gabbay99b9d7b2019-02-16 00:39:13 +02003493};
3494
3495/*
3496 * goya_set_asic_funcs - set Goya function pointers
3497 *
3498 * @*hdev: pointer to hl_device structure
3499 *
3500 */
3501void goya_set_asic_funcs(struct hl_device *hdev)
3502{
3503 hdev->asic_funcs = &goya_funcs;
3504}