Oded Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
| 2 | |
| 3 | /* |
| 4 | * Copyright 2016-2019 HabanaLabs, Ltd. |
| 5 | * All Rights Reserved. |
| 6 | */ |
| 7 | |
| 8 | #include "goyaP.h" |
Omer Shpigelman | 0feaf86 | 2019-02-16 00:39:22 +0200 | [diff] [blame] | 9 | #include "include/hw_ip/mmu/mmu_general.h" |
| 10 | #include "include/hw_ip/mmu/mmu_v1_0.h" |
Oded Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 11 | #include "include/goya/asic_reg/goya_masks.h" |
| 12 | |
| 13 | #include <linux/pci.h> |
Oded Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 14 | #include <linux/genalloc.h> |
Oded Gabbay | d91389b | 2019-02-16 00:39:19 +0200 | [diff] [blame] | 15 | #include <linux/hwmon.h> |
Oded Gabbay | 839c480 | 2019-02-16 00:39:16 +0200 | [diff] [blame] | 16 | #include <linux/io-64-nonatomic-lo-hi.h> |
Oded Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 17 | |
| 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 | |
Omer Shpigelman | 8ba2876 | 2019-04-01 22:23:02 +0300 | [diff] [blame] | 72 | #define GOYA_MMU_REGS_NUM 63 |
Oded Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 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 */ |
Oded Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 81 | #define GOYA_TEST_QUEUE_WAIT_USEC 100000 /* 100ms */ |
Omer Shpigelman | 0feaf86 | 2019-02-16 00:39:22 +0200 | [diff] [blame] | 82 | #define GOYA_PLDM_MMU_TIMEOUT_USEC (MMU_CONFIG_TIMEOUT_USEC * 100) |
Omer Shpigelman | 3dccd18 | 2019-02-28 10:46:16 +0200 | [diff] [blame] | 83 | #define GOYA_PLDM_QMAN0_TIMEOUT_USEC (HL_DEVICE_TIMEOUT_USEC * 30) |
Oded Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 84 | |
| 85 | #define GOYA_QMAN0_FENCE_VAL 0xD169B243 |
| 86 | |
Oded Gabbay | 1251f23 | 2019-02-16 00:39:18 +0200 | [diff] [blame] | 87 | #define GOYA_MAX_STRING_LEN 20 |
| 88 | |
Oded Gabbay | be5d926 | 2019-02-16 00:39:15 +0200 | [diff] [blame] | 89 | #define GOYA_CB_POOL_CB_CNT 512 |
| 90 | #define GOYA_CB_POOL_CB_SIZE 0x20000 /* 128KB */ |
| 91 | |
Oded Gabbay | 1251f23 | 2019-02-16 00:39:18 +0200 | [diff] [blame] | 92 | static const char goya_irq_name[GOYA_MSIX_ENTRIES][GOYA_MAX_STRING_LEN] = { |
| 93 | "goya cq 0", "goya cq 1", "goya cq 2", "goya cq 3", |
| 94 | "goya cq 4", "goya cpu eq" |
| 95 | }; |
| 96 | |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 97 | static u16 goya_packet_sizes[MAX_PACKET_ID] = { |
| 98 | [PACKET_WREG_32] = sizeof(struct packet_wreg32), |
| 99 | [PACKET_WREG_BULK] = sizeof(struct packet_wreg_bulk), |
| 100 | [PACKET_MSG_LONG] = sizeof(struct packet_msg_long), |
| 101 | [PACKET_MSG_SHORT] = sizeof(struct packet_msg_short), |
| 102 | [PACKET_CP_DMA] = sizeof(struct packet_cp_dma), |
| 103 | [PACKET_MSG_PROT] = sizeof(struct packet_msg_prot), |
| 104 | [PACKET_FENCE] = sizeof(struct packet_fence), |
| 105 | [PACKET_LIN_DMA] = sizeof(struct packet_lin_dma), |
| 106 | [PACKET_NOP] = sizeof(struct packet_nop), |
| 107 | [PACKET_STOP] = sizeof(struct packet_stop) |
| 108 | }; |
| 109 | |
Omer Shpigelman | 0feaf86 | 2019-02-16 00:39:22 +0200 | [diff] [blame] | 110 | static u64 goya_mmu_regs[GOYA_MMU_REGS_NUM] = { |
| 111 | mmDMA_QM_0_GLBL_NON_SECURE_PROPS, |
| 112 | mmDMA_QM_1_GLBL_NON_SECURE_PROPS, |
| 113 | mmDMA_QM_2_GLBL_NON_SECURE_PROPS, |
| 114 | mmDMA_QM_3_GLBL_NON_SECURE_PROPS, |
| 115 | mmDMA_QM_4_GLBL_NON_SECURE_PROPS, |
| 116 | mmTPC0_QM_GLBL_SECURE_PROPS, |
| 117 | mmTPC0_QM_GLBL_NON_SECURE_PROPS, |
| 118 | mmTPC0_CMDQ_GLBL_SECURE_PROPS, |
| 119 | mmTPC0_CMDQ_GLBL_NON_SECURE_PROPS, |
| 120 | mmTPC0_CFG_ARUSER, |
| 121 | mmTPC0_CFG_AWUSER, |
| 122 | mmTPC1_QM_GLBL_SECURE_PROPS, |
| 123 | mmTPC1_QM_GLBL_NON_SECURE_PROPS, |
| 124 | mmTPC1_CMDQ_GLBL_SECURE_PROPS, |
| 125 | mmTPC1_CMDQ_GLBL_NON_SECURE_PROPS, |
| 126 | mmTPC1_CFG_ARUSER, |
| 127 | mmTPC1_CFG_AWUSER, |
| 128 | mmTPC2_QM_GLBL_SECURE_PROPS, |
| 129 | mmTPC2_QM_GLBL_NON_SECURE_PROPS, |
| 130 | mmTPC2_CMDQ_GLBL_SECURE_PROPS, |
| 131 | mmTPC2_CMDQ_GLBL_NON_SECURE_PROPS, |
| 132 | mmTPC2_CFG_ARUSER, |
| 133 | mmTPC2_CFG_AWUSER, |
| 134 | mmTPC3_QM_GLBL_SECURE_PROPS, |
| 135 | mmTPC3_QM_GLBL_NON_SECURE_PROPS, |
| 136 | mmTPC3_CMDQ_GLBL_SECURE_PROPS, |
| 137 | mmTPC3_CMDQ_GLBL_NON_SECURE_PROPS, |
| 138 | mmTPC3_CFG_ARUSER, |
| 139 | mmTPC3_CFG_AWUSER, |
| 140 | mmTPC4_QM_GLBL_SECURE_PROPS, |
| 141 | mmTPC4_QM_GLBL_NON_SECURE_PROPS, |
| 142 | mmTPC4_CMDQ_GLBL_SECURE_PROPS, |
| 143 | mmTPC4_CMDQ_GLBL_NON_SECURE_PROPS, |
| 144 | mmTPC4_CFG_ARUSER, |
| 145 | mmTPC4_CFG_AWUSER, |
| 146 | mmTPC5_QM_GLBL_SECURE_PROPS, |
| 147 | mmTPC5_QM_GLBL_NON_SECURE_PROPS, |
| 148 | mmTPC5_CMDQ_GLBL_SECURE_PROPS, |
| 149 | mmTPC5_CMDQ_GLBL_NON_SECURE_PROPS, |
| 150 | mmTPC5_CFG_ARUSER, |
| 151 | mmTPC5_CFG_AWUSER, |
| 152 | mmTPC6_QM_GLBL_SECURE_PROPS, |
| 153 | mmTPC6_QM_GLBL_NON_SECURE_PROPS, |
| 154 | mmTPC6_CMDQ_GLBL_SECURE_PROPS, |
| 155 | mmTPC6_CMDQ_GLBL_NON_SECURE_PROPS, |
| 156 | mmTPC6_CFG_ARUSER, |
| 157 | mmTPC6_CFG_AWUSER, |
| 158 | mmTPC7_QM_GLBL_SECURE_PROPS, |
| 159 | mmTPC7_QM_GLBL_NON_SECURE_PROPS, |
| 160 | mmTPC7_CMDQ_GLBL_SECURE_PROPS, |
| 161 | mmTPC7_CMDQ_GLBL_NON_SECURE_PROPS, |
| 162 | mmTPC7_CFG_ARUSER, |
| 163 | mmTPC7_CFG_AWUSER, |
| 164 | mmMME_QM_GLBL_SECURE_PROPS, |
| 165 | mmMME_QM_GLBL_NON_SECURE_PROPS, |
| 166 | mmMME_CMDQ_GLBL_SECURE_PROPS, |
| 167 | mmMME_CMDQ_GLBL_NON_SECURE_PROPS, |
| 168 | mmMME_SBA_CONTROL_DATA, |
| 169 | mmMME_SBB_CONTROL_DATA, |
| 170 | mmMME_SBC_CONTROL_DATA, |
Omer Shpigelman | 8ba2876 | 2019-04-01 22:23:02 +0300 | [diff] [blame] | 171 | mmMME_WBC_CONTROL_DATA, |
| 172 | mmPCIE_WRAP_PSOC_ARUSER, |
| 173 | mmPCIE_WRAP_PSOC_AWUSER |
Omer Shpigelman | 0feaf86 | 2019-02-16 00:39:22 +0200 | [diff] [blame] | 174 | }; |
| 175 | |
Oded Gabbay | b24ca45 | 2019-02-24 15:50:53 +0200 | [diff] [blame] | 176 | static u32 goya_all_events[] = { |
Oded Gabbay | f8c8c7d | 2019-02-16 00:39:20 +0200 | [diff] [blame] | 177 | GOYA_ASYNC_EVENT_ID_PCIE_IF, |
| 178 | GOYA_ASYNC_EVENT_ID_TPC0_ECC, |
| 179 | GOYA_ASYNC_EVENT_ID_TPC1_ECC, |
| 180 | GOYA_ASYNC_EVENT_ID_TPC2_ECC, |
| 181 | GOYA_ASYNC_EVENT_ID_TPC3_ECC, |
| 182 | GOYA_ASYNC_EVENT_ID_TPC4_ECC, |
| 183 | GOYA_ASYNC_EVENT_ID_TPC5_ECC, |
| 184 | GOYA_ASYNC_EVENT_ID_TPC6_ECC, |
| 185 | GOYA_ASYNC_EVENT_ID_TPC7_ECC, |
| 186 | GOYA_ASYNC_EVENT_ID_MME_ECC, |
| 187 | GOYA_ASYNC_EVENT_ID_MME_ECC_EXT, |
| 188 | GOYA_ASYNC_EVENT_ID_MMU_ECC, |
| 189 | GOYA_ASYNC_EVENT_ID_DMA_MACRO, |
| 190 | GOYA_ASYNC_EVENT_ID_DMA_ECC, |
| 191 | GOYA_ASYNC_EVENT_ID_CPU_IF_ECC, |
| 192 | GOYA_ASYNC_EVENT_ID_PSOC_MEM, |
| 193 | GOYA_ASYNC_EVENT_ID_PSOC_CORESIGHT, |
| 194 | GOYA_ASYNC_EVENT_ID_SRAM0, |
| 195 | GOYA_ASYNC_EVENT_ID_SRAM1, |
| 196 | GOYA_ASYNC_EVENT_ID_SRAM2, |
| 197 | GOYA_ASYNC_EVENT_ID_SRAM3, |
| 198 | GOYA_ASYNC_EVENT_ID_SRAM4, |
| 199 | GOYA_ASYNC_EVENT_ID_SRAM5, |
| 200 | GOYA_ASYNC_EVENT_ID_SRAM6, |
| 201 | GOYA_ASYNC_EVENT_ID_SRAM7, |
| 202 | GOYA_ASYNC_EVENT_ID_SRAM8, |
| 203 | GOYA_ASYNC_EVENT_ID_SRAM9, |
| 204 | GOYA_ASYNC_EVENT_ID_SRAM10, |
| 205 | GOYA_ASYNC_EVENT_ID_SRAM11, |
| 206 | GOYA_ASYNC_EVENT_ID_SRAM12, |
| 207 | GOYA_ASYNC_EVENT_ID_SRAM13, |
| 208 | GOYA_ASYNC_EVENT_ID_SRAM14, |
| 209 | GOYA_ASYNC_EVENT_ID_SRAM15, |
| 210 | GOYA_ASYNC_EVENT_ID_SRAM16, |
| 211 | GOYA_ASYNC_EVENT_ID_SRAM17, |
| 212 | GOYA_ASYNC_EVENT_ID_SRAM18, |
| 213 | GOYA_ASYNC_EVENT_ID_SRAM19, |
| 214 | GOYA_ASYNC_EVENT_ID_SRAM20, |
| 215 | GOYA_ASYNC_EVENT_ID_SRAM21, |
| 216 | GOYA_ASYNC_EVENT_ID_SRAM22, |
| 217 | GOYA_ASYNC_EVENT_ID_SRAM23, |
| 218 | GOYA_ASYNC_EVENT_ID_SRAM24, |
| 219 | GOYA_ASYNC_EVENT_ID_SRAM25, |
| 220 | GOYA_ASYNC_EVENT_ID_SRAM26, |
| 221 | GOYA_ASYNC_EVENT_ID_SRAM27, |
| 222 | GOYA_ASYNC_EVENT_ID_SRAM28, |
| 223 | GOYA_ASYNC_EVENT_ID_SRAM29, |
| 224 | GOYA_ASYNC_EVENT_ID_GIC500, |
| 225 | GOYA_ASYNC_EVENT_ID_PLL0, |
| 226 | GOYA_ASYNC_EVENT_ID_PLL1, |
| 227 | GOYA_ASYNC_EVENT_ID_PLL3, |
| 228 | GOYA_ASYNC_EVENT_ID_PLL4, |
| 229 | GOYA_ASYNC_EVENT_ID_PLL5, |
| 230 | GOYA_ASYNC_EVENT_ID_PLL6, |
| 231 | GOYA_ASYNC_EVENT_ID_AXI_ECC, |
| 232 | GOYA_ASYNC_EVENT_ID_L2_RAM_ECC, |
| 233 | GOYA_ASYNC_EVENT_ID_PSOC_GPIO_05_SW_RESET, |
| 234 | GOYA_ASYNC_EVENT_ID_PSOC_GPIO_10_VRHOT_ICRIT, |
| 235 | GOYA_ASYNC_EVENT_ID_PCIE_DEC, |
| 236 | GOYA_ASYNC_EVENT_ID_TPC0_DEC, |
| 237 | GOYA_ASYNC_EVENT_ID_TPC1_DEC, |
| 238 | GOYA_ASYNC_EVENT_ID_TPC2_DEC, |
| 239 | GOYA_ASYNC_EVENT_ID_TPC3_DEC, |
| 240 | GOYA_ASYNC_EVENT_ID_TPC4_DEC, |
| 241 | GOYA_ASYNC_EVENT_ID_TPC5_DEC, |
| 242 | GOYA_ASYNC_EVENT_ID_TPC6_DEC, |
| 243 | GOYA_ASYNC_EVENT_ID_TPC7_DEC, |
| 244 | GOYA_ASYNC_EVENT_ID_MME_WACS, |
| 245 | GOYA_ASYNC_EVENT_ID_MME_WACSD, |
| 246 | GOYA_ASYNC_EVENT_ID_CPU_AXI_SPLITTER, |
| 247 | GOYA_ASYNC_EVENT_ID_PSOC_AXI_DEC, |
| 248 | GOYA_ASYNC_EVENT_ID_PSOC, |
| 249 | GOYA_ASYNC_EVENT_ID_TPC0_KRN_ERR, |
| 250 | GOYA_ASYNC_EVENT_ID_TPC1_KRN_ERR, |
| 251 | GOYA_ASYNC_EVENT_ID_TPC2_KRN_ERR, |
| 252 | GOYA_ASYNC_EVENT_ID_TPC3_KRN_ERR, |
| 253 | GOYA_ASYNC_EVENT_ID_TPC4_KRN_ERR, |
| 254 | GOYA_ASYNC_EVENT_ID_TPC5_KRN_ERR, |
| 255 | GOYA_ASYNC_EVENT_ID_TPC6_KRN_ERR, |
| 256 | GOYA_ASYNC_EVENT_ID_TPC7_KRN_ERR, |
| 257 | GOYA_ASYNC_EVENT_ID_TPC0_CMDQ, |
| 258 | GOYA_ASYNC_EVENT_ID_TPC1_CMDQ, |
| 259 | GOYA_ASYNC_EVENT_ID_TPC2_CMDQ, |
| 260 | GOYA_ASYNC_EVENT_ID_TPC3_CMDQ, |
| 261 | GOYA_ASYNC_EVENT_ID_TPC4_CMDQ, |
| 262 | GOYA_ASYNC_EVENT_ID_TPC5_CMDQ, |
| 263 | GOYA_ASYNC_EVENT_ID_TPC6_CMDQ, |
| 264 | GOYA_ASYNC_EVENT_ID_TPC7_CMDQ, |
| 265 | GOYA_ASYNC_EVENT_ID_TPC0_QM, |
| 266 | GOYA_ASYNC_EVENT_ID_TPC1_QM, |
| 267 | GOYA_ASYNC_EVENT_ID_TPC2_QM, |
| 268 | GOYA_ASYNC_EVENT_ID_TPC3_QM, |
| 269 | GOYA_ASYNC_EVENT_ID_TPC4_QM, |
| 270 | GOYA_ASYNC_EVENT_ID_TPC5_QM, |
| 271 | GOYA_ASYNC_EVENT_ID_TPC6_QM, |
| 272 | GOYA_ASYNC_EVENT_ID_TPC7_QM, |
| 273 | GOYA_ASYNC_EVENT_ID_MME_QM, |
| 274 | GOYA_ASYNC_EVENT_ID_MME_CMDQ, |
| 275 | GOYA_ASYNC_EVENT_ID_DMA0_QM, |
| 276 | GOYA_ASYNC_EVENT_ID_DMA1_QM, |
| 277 | GOYA_ASYNC_EVENT_ID_DMA2_QM, |
| 278 | GOYA_ASYNC_EVENT_ID_DMA3_QM, |
| 279 | GOYA_ASYNC_EVENT_ID_DMA4_QM, |
| 280 | GOYA_ASYNC_EVENT_ID_DMA0_CH, |
| 281 | GOYA_ASYNC_EVENT_ID_DMA1_CH, |
| 282 | GOYA_ASYNC_EVENT_ID_DMA2_CH, |
| 283 | GOYA_ASYNC_EVENT_ID_DMA3_CH, |
| 284 | GOYA_ASYNC_EVENT_ID_DMA4_CH, |
| 285 | GOYA_ASYNC_EVENT_ID_TPC0_BMON_SPMU, |
| 286 | GOYA_ASYNC_EVENT_ID_TPC1_BMON_SPMU, |
| 287 | GOYA_ASYNC_EVENT_ID_TPC2_BMON_SPMU, |
| 288 | GOYA_ASYNC_EVENT_ID_TPC3_BMON_SPMU, |
| 289 | GOYA_ASYNC_EVENT_ID_TPC4_BMON_SPMU, |
| 290 | GOYA_ASYNC_EVENT_ID_TPC5_BMON_SPMU, |
| 291 | GOYA_ASYNC_EVENT_ID_TPC6_BMON_SPMU, |
| 292 | GOYA_ASYNC_EVENT_ID_TPC7_BMON_SPMU, |
| 293 | GOYA_ASYNC_EVENT_ID_DMA_BM_CH0, |
| 294 | GOYA_ASYNC_EVENT_ID_DMA_BM_CH1, |
| 295 | GOYA_ASYNC_EVENT_ID_DMA_BM_CH2, |
| 296 | GOYA_ASYNC_EVENT_ID_DMA_BM_CH3, |
| 297 | GOYA_ASYNC_EVENT_ID_DMA_BM_CH4 |
| 298 | }; |
| 299 | |
Oded Gabbay | b2377e0 | 2019-04-22 11:49:06 +0300 | [diff] [blame] | 300 | void goya_get_fixed_properties(struct hl_device *hdev) |
Oded Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 301 | { |
| 302 | struct asic_fixed_properties *prop = &hdev->asic_prop; |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 303 | int i; |
| 304 | |
| 305 | for (i = 0 ; i < NUMBER_OF_EXT_HW_QUEUES ; i++) { |
| 306 | prop->hw_queues_props[i].type = QUEUE_TYPE_EXT; |
| 307 | prop->hw_queues_props[i].kmd_only = 0; |
| 308 | } |
| 309 | |
| 310 | for (; i < NUMBER_OF_EXT_HW_QUEUES + NUMBER_OF_CPU_HW_QUEUES ; i++) { |
| 311 | prop->hw_queues_props[i].type = QUEUE_TYPE_CPU; |
| 312 | prop->hw_queues_props[i].kmd_only = 1; |
| 313 | } |
| 314 | |
| 315 | for (; i < NUMBER_OF_EXT_HW_QUEUES + NUMBER_OF_CPU_HW_QUEUES + |
| 316 | NUMBER_OF_INT_HW_QUEUES; i++) { |
| 317 | prop->hw_queues_props[i].type = QUEUE_TYPE_INT; |
| 318 | prop->hw_queues_props[i].kmd_only = 0; |
| 319 | } |
| 320 | |
| 321 | for (; i < HL_MAX_QUEUES; i++) |
| 322 | prop->hw_queues_props[i].type = QUEUE_TYPE_NA; |
Oded Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 323 | |
| 324 | prop->completion_queues_count = NUMBER_OF_CMPLT_QUEUES; |
| 325 | |
| 326 | prop->dram_base_address = DRAM_PHYS_BASE; |
| 327 | prop->dram_size = DRAM_PHYS_DEFAULT_SIZE; |
| 328 | prop->dram_end_address = prop->dram_base_address + prop->dram_size; |
| 329 | prop->dram_user_base_address = DRAM_BASE_ADDR_USER; |
| 330 | |
| 331 | prop->sram_base_address = SRAM_BASE_ADDR; |
| 332 | prop->sram_size = SRAM_SIZE; |
| 333 | prop->sram_end_address = prop->sram_base_address + prop->sram_size; |
| 334 | prop->sram_user_base_address = prop->sram_base_address + |
| 335 | SRAM_USER_BASE_OFFSET; |
| 336 | |
Omer Shpigelman | 0feaf86 | 2019-02-16 00:39:22 +0200 | [diff] [blame] | 337 | prop->mmu_pgt_addr = MMU_PAGE_TABLES_ADDR; |
Omer Shpigelman | 27ca384c | 2019-02-28 10:46:11 +0200 | [diff] [blame] | 338 | prop->mmu_dram_default_page_addr = MMU_DRAM_DEFAULT_PAGE_ADDR; |
Omer Shpigelman | 0feaf86 | 2019-02-16 00:39:22 +0200 | [diff] [blame] | 339 | if (hdev->pldm) |
| 340 | prop->mmu_pgt_size = 0x800000; /* 8MB */ |
| 341 | else |
| 342 | prop->mmu_pgt_size = MMU_PAGE_TABLES_SIZE; |
| 343 | prop->mmu_pte_size = HL_PTE_SIZE; |
| 344 | prop->mmu_hop_table_size = HOP_TABLE_SIZE; |
| 345 | prop->mmu_hop0_tables_total_size = HOP0_TABLES_TOTAL_SIZE; |
| 346 | prop->dram_page_size = PAGE_SIZE_2MB; |
| 347 | |
Oded Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 348 | prop->va_space_host_start_address = VA_HOST_SPACE_START; |
| 349 | prop->va_space_host_end_address = VA_HOST_SPACE_END; |
| 350 | prop->va_space_dram_start_address = VA_DDR_SPACE_START; |
| 351 | prop->va_space_dram_end_address = VA_DDR_SPACE_END; |
Omer Shpigelman | 27ca384c | 2019-02-28 10:46:11 +0200 | [diff] [blame] | 352 | prop->dram_size_for_default_page_mapping = |
| 353 | prop->va_space_dram_end_address; |
Oded Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 354 | prop->cfg_size = CFG_SIZE; |
| 355 | prop->max_asid = MAX_ASID; |
Oded Gabbay | 1251f23 | 2019-02-16 00:39:18 +0200 | [diff] [blame] | 356 | prop->num_of_events = GOYA_ASYNC_EVENT_ID_SIZE; |
Tomer Tayar | b6f897d | 2019-03-05 16:48:42 +0200 | [diff] [blame] | 357 | prop->high_pll = PLL_HIGH_DEFAULT; |
Oded Gabbay | 839c480 | 2019-02-16 00:39:16 +0200 | [diff] [blame] | 358 | prop->cb_pool_cb_cnt = GOYA_CB_POOL_CB_CNT; |
| 359 | prop->cb_pool_cb_size = GOYA_CB_POOL_CB_SIZE; |
Oded Gabbay | d91389b | 2019-02-16 00:39:19 +0200 | [diff] [blame] | 360 | prop->max_power_default = MAX_POWER_DEFAULT; |
Oded Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 361 | prop->tpc_enabled_mask = TPC_ENABLED_MASK; |
Tomer Tayar | b6f897d | 2019-03-05 16:48:42 +0200 | [diff] [blame] | 362 | prop->pcie_dbi_base_address = mmPCIE_DBI_BASE; |
| 363 | prop->pcie_aux_dbi_reg_addr = CFG_BASE + mmPCIE_AUX_DBI; |
Oded Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 364 | } |
| 365 | |
| 366 | /* |
| 367 | * goya_pci_bars_map - Map PCI BARS of Goya device |
| 368 | * |
| 369 | * @hdev: pointer to hl_device structure |
| 370 | * |
| 371 | * Request PCI regions and map them to kernel virtual addresses. |
| 372 | * Returns 0 on success |
| 373 | * |
| 374 | */ |
Oded Gabbay | 5e6e023 | 2019-02-27 12:15:16 +0200 | [diff] [blame] | 375 | static int goya_pci_bars_map(struct hl_device *hdev) |
Oded Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 376 | { |
Tomer Tayar | b6f897d | 2019-03-05 16:48:42 +0200 | [diff] [blame] | 377 | static const char * const name[] = {"SRAM_CFG", "MSIX", "DDR"}; |
| 378 | bool is_wc[3] = {false, false, true}; |
Oded Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 379 | int rc; |
| 380 | |
Tomer Tayar | b6f897d | 2019-03-05 16:48:42 +0200 | [diff] [blame] | 381 | rc = hl_pci_bars_map(hdev, name, is_wc); |
| 382 | if (rc) |
Oded Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 383 | return rc; |
Oded Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 384 | |
| 385 | hdev->rmmio = hdev->pcie_bar[SRAM_CFG_BAR_ID] + |
Tomer Tayar | b6f897d | 2019-03-05 16:48:42 +0200 | [diff] [blame] | 386 | (CFG_BASE - SRAM_BASE_ADDR); |
Oded Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 387 | |
| 388 | return 0; |
Oded Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 389 | } |
| 390 | |
Oded Gabbay | a38693d | 2019-04-28 10:18:35 +0300 | [diff] [blame] | 391 | static u64 goya_set_ddr_bar_base(struct hl_device *hdev, u64 addr) |
Oded Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 392 | { |
| 393 | struct goya_device *goya = hdev->asic_specific; |
Oded Gabbay | a38693d | 2019-04-28 10:18:35 +0300 | [diff] [blame] | 394 | u64 old_addr = addr; |
Oded Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 395 | int rc; |
| 396 | |
| 397 | if ((goya) && (goya->ddr_bar_cur_addr == addr)) |
Oded Gabbay | a38693d | 2019-04-28 10:18:35 +0300 | [diff] [blame] | 398 | return old_addr; |
Oded Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 399 | |
| 400 | /* Inbound Region 1 - Bar 4 - Point to DDR */ |
Tomer Tayar | b6f897d | 2019-03-05 16:48:42 +0200 | [diff] [blame] | 401 | rc = hl_pci_set_dram_bar_base(hdev, 1, 4, addr); |
| 402 | if (rc) |
Oded Gabbay | a38693d | 2019-04-28 10:18:35 +0300 | [diff] [blame] | 403 | return U64_MAX; |
Oded Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 404 | |
Oded Gabbay | a38693d | 2019-04-28 10:18:35 +0300 | [diff] [blame] | 405 | if (goya) { |
| 406 | old_addr = goya->ddr_bar_cur_addr; |
Oded Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 407 | goya->ddr_bar_cur_addr = addr; |
Oded Gabbay | a38693d | 2019-04-28 10:18:35 +0300 | [diff] [blame] | 408 | } |
Oded Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 409 | |
Oded Gabbay | a38693d | 2019-04-28 10:18:35 +0300 | [diff] [blame] | 410 | return old_addr; |
Oded Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 411 | } |
| 412 | |
| 413 | /* |
| 414 | * goya_init_iatu - Initialize the iATU unit inside the PCI controller |
| 415 | * |
| 416 | * @hdev: pointer to hl_device structure |
| 417 | * |
| 418 | * This is needed in case the firmware doesn't initialize the iATU |
| 419 | * |
| 420 | */ |
| 421 | static int goya_init_iatu(struct hl_device *hdev) |
| 422 | { |
Tomer Tayar | b6f897d | 2019-03-05 16:48:42 +0200 | [diff] [blame] | 423 | return hl_pci_init_iatu(hdev, SRAM_BASE_ADDR, DRAM_PHYS_BASE, |
Tomer Tayar | 94cb669 | 2019-05-01 11:28:15 +0300 | [diff] [blame] | 424 | HOST_PHYS_BASE, HOST_PHYS_SIZE); |
Oded Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 425 | } |
| 426 | |
| 427 | /* |
| 428 | * goya_early_init - GOYA early initialization code |
| 429 | * |
| 430 | * @hdev: pointer to hl_device structure |
| 431 | * |
| 432 | * Verify PCI bars |
| 433 | * Set DMA masks |
| 434 | * PCI controller initialization |
| 435 | * Map PCI bars |
| 436 | * |
| 437 | */ |
| 438 | static int goya_early_init(struct hl_device *hdev) |
| 439 | { |
| 440 | struct asic_fixed_properties *prop = &hdev->asic_prop; |
| 441 | struct pci_dev *pdev = hdev->pdev; |
| 442 | u32 val; |
| 443 | int rc; |
| 444 | |
| 445 | goya_get_fixed_properties(hdev); |
| 446 | |
| 447 | /* Check BAR sizes */ |
| 448 | if (pci_resource_len(pdev, SRAM_CFG_BAR_ID) != CFG_BAR_SIZE) { |
| 449 | dev_err(hdev->dev, |
| 450 | "Not " HL_NAME "? BAR %d size %llu, expecting %llu\n", |
| 451 | SRAM_CFG_BAR_ID, |
| 452 | (unsigned long long) pci_resource_len(pdev, |
| 453 | SRAM_CFG_BAR_ID), |
| 454 | CFG_BAR_SIZE); |
| 455 | return -ENODEV; |
| 456 | } |
| 457 | |
| 458 | if (pci_resource_len(pdev, MSIX_BAR_ID) != MSIX_BAR_SIZE) { |
| 459 | dev_err(hdev->dev, |
| 460 | "Not " HL_NAME "? BAR %d size %llu, expecting %llu\n", |
| 461 | MSIX_BAR_ID, |
| 462 | (unsigned long long) pci_resource_len(pdev, |
| 463 | MSIX_BAR_ID), |
| 464 | MSIX_BAR_SIZE); |
| 465 | return -ENODEV; |
| 466 | } |
| 467 | |
| 468 | prop->dram_pci_bar_size = pci_resource_len(pdev, DDR_BAR_ID); |
| 469 | |
Oded Gabbay | d997387 | 2019-03-07 18:03:23 +0200 | [diff] [blame] | 470 | rc = hl_pci_init(hdev, 39); |
Tomer Tayar | b6f897d | 2019-03-05 16:48:42 +0200 | [diff] [blame] | 471 | if (rc) |
Oded Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 472 | return rc; |
Oded Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 473 | |
Oded Gabbay | 839c480 | 2019-02-16 00:39:16 +0200 | [diff] [blame] | 474 | if (!hdev->pldm) { |
| 475 | val = RREG32(mmPSOC_GLOBAL_CONF_BOOT_STRAP_PINS); |
| 476 | if (val & PSOC_GLOBAL_CONF_BOOT_STRAP_PINS_SRIOV_EN_MASK) |
| 477 | dev_warn(hdev->dev, |
| 478 | "PCI strap is not configured correctly, PCI bus errors may occur\n"); |
| 479 | } |
Oded Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 480 | |
| 481 | return 0; |
Oded Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 482 | } |
| 483 | |
| 484 | /* |
| 485 | * goya_early_fini - GOYA early finalization code |
| 486 | * |
| 487 | * @hdev: pointer to hl_device structure |
| 488 | * |
| 489 | * Unmap PCI bars |
| 490 | * |
| 491 | */ |
Oded Gabbay | 5e6e023 | 2019-02-27 12:15:16 +0200 | [diff] [blame] | 492 | static int goya_early_fini(struct hl_device *hdev) |
Oded Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 493 | { |
Tomer Tayar | b6f897d | 2019-03-05 16:48:42 +0200 | [diff] [blame] | 494 | hl_pci_fini(hdev); |
Oded Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 495 | |
| 496 | return 0; |
| 497 | } |
| 498 | |
Oded Gabbay | bedd144 | 2019-04-02 15:56:16 +0300 | [diff] [blame] | 499 | static void goya_mmu_prepare_reg(struct hl_device *hdev, u64 reg, u32 asid) |
| 500 | { |
| 501 | /* mask to zero the MMBP and ASID bits */ |
| 502 | WREG32_AND(reg, ~0x7FF); |
| 503 | WREG32_OR(reg, asid); |
| 504 | } |
| 505 | |
| 506 | static void goya_qman0_set_security(struct hl_device *hdev, bool secure) |
| 507 | { |
| 508 | struct goya_device *goya = hdev->asic_specific; |
| 509 | |
| 510 | if (!(goya->hw_cap_initialized & HW_CAP_MMU)) |
| 511 | return; |
| 512 | |
| 513 | if (secure) |
| 514 | WREG32(mmDMA_QM_0_GLBL_PROT, QMAN_DMA_FULLY_TRUSTED); |
| 515 | else |
| 516 | WREG32(mmDMA_QM_0_GLBL_PROT, QMAN_DMA_PARTLY_TRUSTED); |
| 517 | |
| 518 | RREG32(mmDMA_QM_0_GLBL_PROT); |
| 519 | } |
| 520 | |
Oded Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 521 | /* |
Oded Gabbay | d91389b | 2019-02-16 00:39:19 +0200 | [diff] [blame] | 522 | * goya_fetch_psoc_frequency - Fetch PSOC frequency values |
| 523 | * |
| 524 | * @hdev: pointer to hl_device structure |
| 525 | * |
| 526 | */ |
| 527 | static void goya_fetch_psoc_frequency(struct hl_device *hdev) |
| 528 | { |
| 529 | struct asic_fixed_properties *prop = &hdev->asic_prop; |
| 530 | |
| 531 | prop->psoc_pci_pll_nr = RREG32(mmPSOC_PCI_PLL_NR); |
| 532 | prop->psoc_pci_pll_nf = RREG32(mmPSOC_PCI_PLL_NF); |
| 533 | prop->psoc_pci_pll_od = RREG32(mmPSOC_PCI_PLL_OD); |
| 534 | prop->psoc_pci_pll_div_factor = RREG32(mmPSOC_PCI_PLL_DIV_FACTOR_1); |
| 535 | } |
| 536 | |
Oded Gabbay | b2377e0 | 2019-04-22 11:49:06 +0300 | [diff] [blame] | 537 | int goya_late_init(struct hl_device *hdev) |
Oded Gabbay | d91389b | 2019-02-16 00:39:19 +0200 | [diff] [blame] | 538 | { |
| 539 | struct asic_fixed_properties *prop = &hdev->asic_prop; |
Oded Gabbay | d91389b | 2019-02-16 00:39:19 +0200 | [diff] [blame] | 540 | int rc; |
| 541 | |
Tomer Tayar | 393e5b5 | 2019-03-06 14:30:26 +0200 | [diff] [blame] | 542 | rc = goya_armcp_info_get(hdev); |
Oded Gabbay | d91389b | 2019-02-16 00:39:19 +0200 | [diff] [blame] | 543 | if (rc) { |
| 544 | dev_err(hdev->dev, "Failed to get armcp info\n"); |
| 545 | return rc; |
| 546 | } |
| 547 | |
| 548 | /* Now that we have the DRAM size in ASIC prop, we need to check |
| 549 | * its size and configure the DMA_IF DDR wrap protection (which is in |
| 550 | * the MMU block) accordingly. The value is the log2 of the DRAM size |
| 551 | */ |
| 552 | WREG32(mmMMU_LOG2_DDR_SIZE, ilog2(prop->dram_size)); |
| 553 | |
Tomer Tayar | 3110c60 | 2019-03-04 10:22:09 +0200 | [diff] [blame] | 554 | rc = hl_fw_send_pci_access_msg(hdev, ARMCP_PACKET_ENABLE_PCI_ACCESS); |
Oded Gabbay | d91389b | 2019-02-16 00:39:19 +0200 | [diff] [blame] | 555 | if (rc) { |
| 556 | dev_err(hdev->dev, "Failed to enable PCI access from CPU\n"); |
| 557 | return rc; |
| 558 | } |
| 559 | |
| 560 | WREG32(mmGIC_DISTRIBUTOR__5_GICD_SETSPI_NSR, |
| 561 | GOYA_ASYNC_EVENT_ID_INTS_REGISTER); |
| 562 | |
| 563 | goya_fetch_psoc_frequency(hdev); |
| 564 | |
Omer Shpigelman | 0feaf86 | 2019-02-16 00:39:22 +0200 | [diff] [blame] | 565 | rc = goya_mmu_clear_pgt_range(hdev); |
| 566 | if (rc) { |
| 567 | dev_err(hdev->dev, "Failed to clear MMU page tables range\n"); |
| 568 | goto disable_pci_access; |
| 569 | } |
| 570 | |
Omer Shpigelman | 27ca384c | 2019-02-28 10:46:11 +0200 | [diff] [blame] | 571 | rc = goya_mmu_set_dram_default_page(hdev); |
| 572 | if (rc) { |
| 573 | dev_err(hdev->dev, "Failed to set DRAM default page\n"); |
| 574 | goto disable_pci_access; |
| 575 | } |
| 576 | |
Oded Gabbay | d91389b | 2019-02-16 00:39:19 +0200 | [diff] [blame] | 577 | return 0; |
Omer Shpigelman | 0feaf86 | 2019-02-16 00:39:22 +0200 | [diff] [blame] | 578 | |
| 579 | disable_pci_access: |
Tomer Tayar | 3110c60 | 2019-03-04 10:22:09 +0200 | [diff] [blame] | 580 | hl_fw_send_pci_access_msg(hdev, ARMCP_PACKET_DISABLE_PCI_ACCESS); |
Omer Shpigelman | 0feaf86 | 2019-02-16 00:39:22 +0200 | [diff] [blame] | 581 | |
| 582 | return rc; |
Oded Gabbay | d91389b | 2019-02-16 00:39:19 +0200 | [diff] [blame] | 583 | } |
| 584 | |
| 585 | /* |
| 586 | * goya_late_fini - GOYA late tear-down code |
| 587 | * |
| 588 | * @hdev: pointer to hl_device structure |
| 589 | * |
| 590 | * Free sensors allocated structures |
| 591 | */ |
| 592 | void goya_late_fini(struct hl_device *hdev) |
| 593 | { |
| 594 | const struct hwmon_channel_info **channel_info_arr; |
| 595 | int i = 0; |
| 596 | |
| 597 | if (!hdev->hl_chip_info->info) |
| 598 | return; |
| 599 | |
| 600 | channel_info_arr = hdev->hl_chip_info->info; |
| 601 | |
| 602 | while (channel_info_arr[i]) { |
| 603 | kfree(channel_info_arr[i]->config); |
| 604 | kfree(channel_info_arr[i]); |
| 605 | i++; |
| 606 | } |
| 607 | |
| 608 | kfree(channel_info_arr); |
| 609 | |
| 610 | hdev->hl_chip_info->info = NULL; |
| 611 | } |
| 612 | |
| 613 | /* |
Oded Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 614 | * goya_sw_init - Goya software initialization code |
| 615 | * |
| 616 | * @hdev: pointer to hl_device structure |
| 617 | * |
| 618 | */ |
| 619 | static int goya_sw_init(struct hl_device *hdev) |
| 620 | { |
| 621 | struct goya_device *goya; |
| 622 | int rc; |
| 623 | |
| 624 | /* Allocate device structure */ |
| 625 | goya = kzalloc(sizeof(*goya), GFP_KERNEL); |
| 626 | if (!goya) |
| 627 | return -ENOMEM; |
| 628 | |
| 629 | /* according to goya_init_iatu */ |
| 630 | goya->ddr_bar_cur_addr = DRAM_PHYS_BASE; |
Oded Gabbay | d91389b | 2019-02-16 00:39:19 +0200 | [diff] [blame] | 631 | |
| 632 | goya->mme_clk = GOYA_PLL_FREQ_LOW; |
| 633 | goya->tpc_clk = GOYA_PLL_FREQ_LOW; |
| 634 | goya->ic_clk = GOYA_PLL_FREQ_LOW; |
| 635 | |
Oded Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 636 | hdev->asic_specific = goya; |
| 637 | |
| 638 | /* Create DMA pool for small allocations */ |
| 639 | hdev->dma_pool = dma_pool_create(dev_name(hdev->dev), |
| 640 | &hdev->pdev->dev, GOYA_DMA_POOL_BLK_SIZE, 8, 0); |
| 641 | if (!hdev->dma_pool) { |
| 642 | dev_err(hdev->dev, "failed to create DMA pool\n"); |
| 643 | rc = -ENOMEM; |
| 644 | goto free_goya_device; |
| 645 | } |
| 646 | |
| 647 | hdev->cpu_accessible_dma_mem = |
Oded Gabbay | d9c3aa8 | 2019-05-01 11:47:04 +0300 | [diff] [blame] | 648 | hdev->asic_funcs->asic_dma_alloc_coherent(hdev, |
Tomer Tayar | 3110c60 | 2019-03-04 10:22:09 +0200 | [diff] [blame] | 649 | HL_CPU_ACCESSIBLE_MEM_SIZE, |
Oded Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 650 | &hdev->cpu_accessible_dma_address, |
| 651 | GFP_KERNEL | __GFP_ZERO); |
| 652 | |
| 653 | if (!hdev->cpu_accessible_dma_mem) { |
Oded Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 654 | rc = -ENOMEM; |
| 655 | goto free_dma_pool; |
| 656 | } |
| 657 | |
Tomer Tayar | 3110c60 | 2019-03-04 10:22:09 +0200 | [diff] [blame] | 658 | hdev->cpu_accessible_dma_pool = gen_pool_create(HL_CPU_PKT_SHIFT, -1); |
Oded Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 659 | if (!hdev->cpu_accessible_dma_pool) { |
| 660 | dev_err(hdev->dev, |
| 661 | "Failed to create CPU accessible DMA pool\n"); |
| 662 | rc = -ENOMEM; |
Tomer Tayar | 9f832fd | 2019-05-02 15:37:19 +0300 | [diff] [blame] | 663 | goto free_cpu_dma_mem; |
Oded Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 664 | } |
| 665 | |
| 666 | rc = gen_pool_add(hdev->cpu_accessible_dma_pool, |
| 667 | (uintptr_t) hdev->cpu_accessible_dma_mem, |
Tomer Tayar | 3110c60 | 2019-03-04 10:22:09 +0200 | [diff] [blame] | 668 | HL_CPU_ACCESSIBLE_MEM_SIZE, -1); |
Oded Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 669 | if (rc) { |
| 670 | dev_err(hdev->dev, |
| 671 | "Failed to add memory to CPU accessible DMA pool\n"); |
| 672 | rc = -EFAULT; |
Tomer Tayar | ba209e1 | 2019-05-02 11:33:12 +0300 | [diff] [blame] | 673 | goto free_cpu_accessible_dma_pool; |
Oded Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 674 | } |
| 675 | |
| 676 | spin_lock_init(&goya->hw_queues_lock); |
| 677 | |
| 678 | return 0; |
| 679 | |
Tomer Tayar | ba209e1 | 2019-05-02 11:33:12 +0300 | [diff] [blame] | 680 | free_cpu_accessible_dma_pool: |
Oded Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 681 | gen_pool_destroy(hdev->cpu_accessible_dma_pool); |
Tomer Tayar | 9f832fd | 2019-05-02 15:37:19 +0300 | [diff] [blame] | 682 | free_cpu_dma_mem: |
Oded Gabbay | d9c3aa8 | 2019-05-01 11:47:04 +0300 | [diff] [blame] | 683 | hdev->asic_funcs->asic_dma_free_coherent(hdev, |
| 684 | HL_CPU_ACCESSIBLE_MEM_SIZE, |
Oded Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 685 | hdev->cpu_accessible_dma_mem, |
| 686 | hdev->cpu_accessible_dma_address); |
| 687 | free_dma_pool: |
| 688 | dma_pool_destroy(hdev->dma_pool); |
| 689 | free_goya_device: |
| 690 | kfree(goya); |
| 691 | |
| 692 | return rc; |
| 693 | } |
| 694 | |
| 695 | /* |
| 696 | * goya_sw_fini - Goya software tear-down code |
| 697 | * |
| 698 | * @hdev: pointer to hl_device structure |
| 699 | * |
| 700 | */ |
Oded Gabbay | 5e6e023 | 2019-02-27 12:15:16 +0200 | [diff] [blame] | 701 | static int goya_sw_fini(struct hl_device *hdev) |
Oded Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 702 | { |
| 703 | struct goya_device *goya = hdev->asic_specific; |
| 704 | |
| 705 | gen_pool_destroy(hdev->cpu_accessible_dma_pool); |
| 706 | |
Oded Gabbay | d9c3aa8 | 2019-05-01 11:47:04 +0300 | [diff] [blame] | 707 | hdev->asic_funcs->asic_dma_free_coherent(hdev, |
| 708 | HL_CPU_ACCESSIBLE_MEM_SIZE, |
Oded Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 709 | hdev->cpu_accessible_dma_mem, |
| 710 | hdev->cpu_accessible_dma_address); |
| 711 | |
| 712 | dma_pool_destroy(hdev->dma_pool); |
| 713 | |
| 714 | kfree(goya); |
| 715 | |
| 716 | return 0; |
| 717 | } |
| 718 | |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 719 | static void goya_init_dma_qman(struct hl_device *hdev, int dma_id, |
| 720 | dma_addr_t bus_address) |
| 721 | { |
| 722 | struct goya_device *goya = hdev->asic_specific; |
| 723 | u32 mtr_base_lo, mtr_base_hi; |
| 724 | u32 so_base_lo, so_base_hi; |
| 725 | u32 gic_base_lo, gic_base_hi; |
| 726 | u32 reg_off = dma_id * (mmDMA_QM_1_PQ_PI - mmDMA_QM_0_PQ_PI); |
| 727 | |
| 728 | mtr_base_lo = lower_32_bits(CFG_BASE + mmSYNC_MNGR_MON_PAY_ADDRL_0); |
| 729 | mtr_base_hi = upper_32_bits(CFG_BASE + mmSYNC_MNGR_MON_PAY_ADDRL_0); |
| 730 | so_base_lo = lower_32_bits(CFG_BASE + mmSYNC_MNGR_SOB_OBJ_0); |
| 731 | so_base_hi = upper_32_bits(CFG_BASE + mmSYNC_MNGR_SOB_OBJ_0); |
| 732 | |
| 733 | gic_base_lo = |
| 734 | lower_32_bits(CFG_BASE + mmGIC_DISTRIBUTOR__5_GICD_SETSPI_NSR); |
| 735 | gic_base_hi = |
| 736 | upper_32_bits(CFG_BASE + mmGIC_DISTRIBUTOR__5_GICD_SETSPI_NSR); |
| 737 | |
| 738 | WREG32(mmDMA_QM_0_PQ_BASE_LO + reg_off, lower_32_bits(bus_address)); |
| 739 | WREG32(mmDMA_QM_0_PQ_BASE_HI + reg_off, upper_32_bits(bus_address)); |
| 740 | |
| 741 | WREG32(mmDMA_QM_0_PQ_SIZE + reg_off, ilog2(HL_QUEUE_LENGTH)); |
| 742 | WREG32(mmDMA_QM_0_PQ_PI + reg_off, 0); |
| 743 | WREG32(mmDMA_QM_0_PQ_CI + reg_off, 0); |
| 744 | |
| 745 | WREG32(mmDMA_QM_0_CP_MSG_BASE0_ADDR_LO + reg_off, mtr_base_lo); |
| 746 | WREG32(mmDMA_QM_0_CP_MSG_BASE0_ADDR_HI + reg_off, mtr_base_hi); |
| 747 | WREG32(mmDMA_QM_0_CP_MSG_BASE1_ADDR_LO + reg_off, so_base_lo); |
| 748 | WREG32(mmDMA_QM_0_CP_MSG_BASE1_ADDR_HI + reg_off, so_base_hi); |
| 749 | WREG32(mmDMA_QM_0_GLBL_ERR_ADDR_LO + reg_off, gic_base_lo); |
| 750 | WREG32(mmDMA_QM_0_GLBL_ERR_ADDR_HI + reg_off, gic_base_hi); |
| 751 | WREG32(mmDMA_QM_0_GLBL_ERR_WDATA + reg_off, |
| 752 | GOYA_ASYNC_EVENT_ID_DMA0_QM + dma_id); |
| 753 | |
| 754 | /* PQ has buffer of 2 cache lines, while CQ has 8 lines */ |
| 755 | WREG32(mmDMA_QM_0_PQ_CFG1 + reg_off, 0x00020002); |
| 756 | WREG32(mmDMA_QM_0_CQ_CFG1 + reg_off, 0x00080008); |
| 757 | |
Oded Gabbay | 1251f23 | 2019-02-16 00:39:18 +0200 | [diff] [blame] | 758 | if (goya->hw_cap_initialized & HW_CAP_MMU) |
| 759 | WREG32(mmDMA_QM_0_GLBL_PROT + reg_off, QMAN_DMA_PARTLY_TRUSTED); |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 760 | else |
Oded Gabbay | 1251f23 | 2019-02-16 00:39:18 +0200 | [diff] [blame] | 761 | WREG32(mmDMA_QM_0_GLBL_PROT + reg_off, QMAN_DMA_FULLY_TRUSTED); |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 762 | |
| 763 | WREG32(mmDMA_QM_0_GLBL_ERR_CFG + reg_off, QMAN_DMA_ERR_MSG_EN); |
| 764 | WREG32(mmDMA_QM_0_GLBL_CFG0 + reg_off, QMAN_DMA_ENABLE); |
| 765 | } |
| 766 | |
| 767 | static void goya_init_dma_ch(struct hl_device *hdev, int dma_id) |
| 768 | { |
| 769 | u32 gic_base_lo, gic_base_hi; |
| 770 | u64 sob_addr; |
| 771 | u32 reg_off = dma_id * (mmDMA_CH_1_CFG1 - mmDMA_CH_0_CFG1); |
| 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_CH_0_ERRMSG_ADDR_LO + reg_off, gic_base_lo); |
| 779 | WREG32(mmDMA_CH_0_ERRMSG_ADDR_HI + reg_off, gic_base_hi); |
| 780 | WREG32(mmDMA_CH_0_ERRMSG_WDATA + reg_off, |
| 781 | GOYA_ASYNC_EVENT_ID_DMA0_CH + dma_id); |
| 782 | |
Oded Gabbay | 887f7d3 | 2019-02-28 10:46:15 +0200 | [diff] [blame] | 783 | if (dma_id) |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 784 | sob_addr = CFG_BASE + mmSYNC_MNGR_SOB_OBJ_1000 + |
| 785 | (dma_id - 1) * 4; |
Oded Gabbay | 887f7d3 | 2019-02-28 10:46:15 +0200 | [diff] [blame] | 786 | else |
| 787 | sob_addr = CFG_BASE + mmSYNC_MNGR_SOB_OBJ_1007; |
| 788 | |
| 789 | WREG32(mmDMA_CH_0_WR_COMP_ADDR_LO + reg_off, lower_32_bits(sob_addr)); |
| 790 | WREG32(mmDMA_CH_0_WR_COMP_ADDR_HI + reg_off, upper_32_bits(sob_addr)); |
| 791 | WREG32(mmDMA_CH_0_WR_COMP_WDATA + reg_off, 0x80000001); |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 792 | } |
| 793 | |
| 794 | /* |
| 795 | * goya_init_dma_qmans - Initialize QMAN DMA registers |
| 796 | * |
| 797 | * @hdev: pointer to hl_device structure |
| 798 | * |
| 799 | * Initialize the H/W registers of the QMAN DMA channels |
| 800 | * |
| 801 | */ |
Oded Gabbay | b2377e0 | 2019-04-22 11:49:06 +0300 | [diff] [blame] | 802 | void goya_init_dma_qmans(struct hl_device *hdev) |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 803 | { |
| 804 | struct goya_device *goya = hdev->asic_specific; |
| 805 | struct hl_hw_queue *q; |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 806 | int i; |
| 807 | |
| 808 | if (goya->hw_cap_initialized & HW_CAP_DMA) |
| 809 | return; |
| 810 | |
| 811 | q = &hdev->kernel_queues[0]; |
| 812 | |
| 813 | for (i = 0 ; i < NUMBER_OF_EXT_HW_QUEUES ; i++, q++) { |
Tomer Tayar | 94cb669 | 2019-05-01 11:28:15 +0300 | [diff] [blame] | 814 | goya_init_dma_qman(hdev, i, q->bus_address); |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 815 | goya_init_dma_ch(hdev, i); |
| 816 | } |
| 817 | |
| 818 | goya->hw_cap_initialized |= HW_CAP_DMA; |
| 819 | } |
| 820 | |
| 821 | /* |
| 822 | * goya_disable_external_queues - Disable external queues |
| 823 | * |
| 824 | * @hdev: pointer to hl_device structure |
| 825 | * |
| 826 | */ |
| 827 | static void goya_disable_external_queues(struct hl_device *hdev) |
| 828 | { |
| 829 | WREG32(mmDMA_QM_0_GLBL_CFG0, 0); |
| 830 | WREG32(mmDMA_QM_1_GLBL_CFG0, 0); |
| 831 | WREG32(mmDMA_QM_2_GLBL_CFG0, 0); |
| 832 | WREG32(mmDMA_QM_3_GLBL_CFG0, 0); |
| 833 | WREG32(mmDMA_QM_4_GLBL_CFG0, 0); |
| 834 | } |
| 835 | |
| 836 | static int goya_stop_queue(struct hl_device *hdev, u32 cfg_reg, |
| 837 | u32 cp_sts_reg, u32 glbl_sts0_reg) |
| 838 | { |
| 839 | int rc; |
| 840 | u32 status; |
| 841 | |
| 842 | /* use the values of TPC0 as they are all the same*/ |
| 843 | |
| 844 | WREG32(cfg_reg, 1 << TPC0_QM_GLBL_CFG1_CP_STOP_SHIFT); |
| 845 | |
| 846 | status = RREG32(cp_sts_reg); |
| 847 | if (status & TPC0_QM_CP_STS_FENCE_IN_PROGRESS_MASK) { |
| 848 | rc = hl_poll_timeout( |
| 849 | hdev, |
| 850 | cp_sts_reg, |
| 851 | status, |
| 852 | !(status & TPC0_QM_CP_STS_FENCE_IN_PROGRESS_MASK), |
| 853 | 1000, |
| 854 | QMAN_FENCE_TIMEOUT_USEC); |
| 855 | |
| 856 | /* if QMAN is stuck in fence no need to check for stop */ |
| 857 | if (rc) |
| 858 | return 0; |
| 859 | } |
| 860 | |
| 861 | rc = hl_poll_timeout( |
| 862 | hdev, |
| 863 | glbl_sts0_reg, |
| 864 | status, |
| 865 | (status & TPC0_QM_GLBL_STS0_CP_IS_STOP_MASK), |
| 866 | 1000, |
| 867 | QMAN_STOP_TIMEOUT_USEC); |
| 868 | |
| 869 | if (rc) { |
| 870 | dev_err(hdev->dev, |
| 871 | "Timeout while waiting for QMAN to stop\n"); |
| 872 | return -EINVAL; |
| 873 | } |
| 874 | |
| 875 | return 0; |
| 876 | } |
| 877 | |
| 878 | /* |
| 879 | * goya_stop_external_queues - Stop external queues |
| 880 | * |
| 881 | * @hdev: pointer to hl_device structure |
| 882 | * |
| 883 | * Returns 0 on success |
| 884 | * |
| 885 | */ |
| 886 | static int goya_stop_external_queues(struct hl_device *hdev) |
| 887 | { |
| 888 | int rc, retval = 0; |
| 889 | |
| 890 | rc = goya_stop_queue(hdev, |
| 891 | mmDMA_QM_0_GLBL_CFG1, |
| 892 | mmDMA_QM_0_CP_STS, |
| 893 | mmDMA_QM_0_GLBL_STS0); |
| 894 | |
| 895 | if (rc) { |
| 896 | dev_err(hdev->dev, "failed to stop DMA QMAN 0\n"); |
| 897 | retval = -EIO; |
| 898 | } |
| 899 | |
| 900 | rc = goya_stop_queue(hdev, |
| 901 | mmDMA_QM_1_GLBL_CFG1, |
| 902 | mmDMA_QM_1_CP_STS, |
| 903 | mmDMA_QM_1_GLBL_STS0); |
| 904 | |
| 905 | if (rc) { |
| 906 | dev_err(hdev->dev, "failed to stop DMA QMAN 1\n"); |
| 907 | retval = -EIO; |
| 908 | } |
| 909 | |
| 910 | rc = goya_stop_queue(hdev, |
| 911 | mmDMA_QM_2_GLBL_CFG1, |
| 912 | mmDMA_QM_2_CP_STS, |
| 913 | mmDMA_QM_2_GLBL_STS0); |
| 914 | |
| 915 | if (rc) { |
| 916 | dev_err(hdev->dev, "failed to stop DMA QMAN 2\n"); |
| 917 | retval = -EIO; |
| 918 | } |
| 919 | |
| 920 | rc = goya_stop_queue(hdev, |
| 921 | mmDMA_QM_3_GLBL_CFG1, |
| 922 | mmDMA_QM_3_CP_STS, |
| 923 | mmDMA_QM_3_GLBL_STS0); |
| 924 | |
| 925 | if (rc) { |
| 926 | dev_err(hdev->dev, "failed to stop DMA QMAN 3\n"); |
| 927 | retval = -EIO; |
| 928 | } |
| 929 | |
| 930 | rc = goya_stop_queue(hdev, |
| 931 | mmDMA_QM_4_GLBL_CFG1, |
| 932 | mmDMA_QM_4_CP_STS, |
| 933 | mmDMA_QM_4_GLBL_STS0); |
| 934 | |
| 935 | if (rc) { |
| 936 | dev_err(hdev->dev, "failed to stop DMA QMAN 4\n"); |
| 937 | retval = -EIO; |
| 938 | } |
| 939 | |
| 940 | return retval; |
| 941 | } |
| 942 | |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 943 | /* |
| 944 | * goya_init_cpu_queues - Initialize PQ/CQ/EQ of CPU |
| 945 | * |
| 946 | * @hdev: pointer to hl_device structure |
| 947 | * |
| 948 | * Returns 0 on success |
| 949 | * |
| 950 | */ |
Oded Gabbay | b2377e0 | 2019-04-22 11:49:06 +0300 | [diff] [blame] | 951 | int goya_init_cpu_queues(struct hl_device *hdev) |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 952 | { |
| 953 | struct goya_device *goya = hdev->asic_specific; |
Oded Gabbay | 1251f23 | 2019-02-16 00:39:18 +0200 | [diff] [blame] | 954 | struct hl_eq *eq; |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 955 | u32 status; |
| 956 | struct hl_hw_queue *cpu_pq = &hdev->kernel_queues[GOYA_QUEUE_ID_CPU_PQ]; |
| 957 | int err; |
| 958 | |
| 959 | if (!hdev->cpu_queues_enable) |
| 960 | return 0; |
| 961 | |
| 962 | if (goya->hw_cap_initialized & HW_CAP_CPU_Q) |
| 963 | return 0; |
| 964 | |
Oded Gabbay | 1251f23 | 2019-02-16 00:39:18 +0200 | [diff] [blame] | 965 | eq = &hdev->event_queue; |
| 966 | |
Tomer Tayar | 94cb669 | 2019-05-01 11:28:15 +0300 | [diff] [blame] | 967 | WREG32(mmPSOC_GLOBAL_CONF_SCRATCHPAD_0, |
| 968 | lower_32_bits(cpu_pq->bus_address)); |
| 969 | WREG32(mmPSOC_GLOBAL_CONF_SCRATCHPAD_1, |
| 970 | upper_32_bits(cpu_pq->bus_address)); |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 971 | |
Tomer Tayar | 94cb669 | 2019-05-01 11:28:15 +0300 | [diff] [blame] | 972 | WREG32(mmPSOC_GLOBAL_CONF_SCRATCHPAD_2, lower_32_bits(eq->bus_address)); |
| 973 | WREG32(mmPSOC_GLOBAL_CONF_SCRATCHPAD_3, upper_32_bits(eq->bus_address)); |
Oded Gabbay | 1251f23 | 2019-02-16 00:39:18 +0200 | [diff] [blame] | 974 | |
Tomer Tayar | 94cb669 | 2019-05-01 11:28:15 +0300 | [diff] [blame] | 975 | WREG32(mmPSOC_GLOBAL_CONF_SCRATCHPAD_8, |
| 976 | lower_32_bits(hdev->cpu_accessible_dma_address)); |
| 977 | WREG32(mmPSOC_GLOBAL_CONF_SCRATCHPAD_9, |
| 978 | upper_32_bits(hdev->cpu_accessible_dma_address)); |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 979 | |
| 980 | WREG32(mmPSOC_GLOBAL_CONF_SCRATCHPAD_5, HL_QUEUE_SIZE_IN_BYTES); |
Oded Gabbay | 1251f23 | 2019-02-16 00:39:18 +0200 | [diff] [blame] | 981 | WREG32(mmPSOC_GLOBAL_CONF_SCRATCHPAD_4, HL_EQ_SIZE_IN_BYTES); |
Tomer Tayar | 3110c60 | 2019-03-04 10:22:09 +0200 | [diff] [blame] | 982 | WREG32(mmPSOC_GLOBAL_CONF_SCRATCHPAD_10, HL_CPU_ACCESSIBLE_MEM_SIZE); |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 983 | |
| 984 | /* Used for EQ CI */ |
| 985 | WREG32(mmPSOC_GLOBAL_CONF_SCRATCHPAD_6, 0); |
| 986 | |
| 987 | WREG32(mmCPU_IF_PF_PQ_PI, 0); |
| 988 | |
| 989 | WREG32(mmPSOC_GLOBAL_CONF_SCRATCHPAD_7, PQ_INIT_STATUS_READY_FOR_CP); |
| 990 | |
| 991 | WREG32(mmGIC_DISTRIBUTOR__5_GICD_SETSPI_NSR, |
| 992 | GOYA_ASYNC_EVENT_ID_PI_UPDATE); |
| 993 | |
| 994 | err = hl_poll_timeout( |
| 995 | hdev, |
| 996 | mmPSOC_GLOBAL_CONF_SCRATCHPAD_7, |
| 997 | status, |
| 998 | (status == PQ_INIT_STATUS_READY_FOR_HOST), |
| 999 | 1000, |
| 1000 | GOYA_CPU_TIMEOUT_USEC); |
| 1001 | |
| 1002 | if (err) { |
| 1003 | dev_err(hdev->dev, |
| 1004 | "Failed to communicate with ARM CPU (ArmCP timeout)\n"); |
| 1005 | return -EIO; |
| 1006 | } |
| 1007 | |
| 1008 | goya->hw_cap_initialized |= HW_CAP_CPU_Q; |
| 1009 | return 0; |
| 1010 | } |
| 1011 | |
Oded Gabbay | 839c480 | 2019-02-16 00:39:16 +0200 | [diff] [blame] | 1012 | static void goya_set_pll_refclk(struct hl_device *hdev) |
| 1013 | { |
| 1014 | WREG32(mmCPU_PLL_DIV_SEL_0, 0x0); |
| 1015 | WREG32(mmCPU_PLL_DIV_SEL_1, 0x0); |
| 1016 | WREG32(mmCPU_PLL_DIV_SEL_2, 0x0); |
| 1017 | WREG32(mmCPU_PLL_DIV_SEL_3, 0x0); |
| 1018 | |
| 1019 | WREG32(mmIC_PLL_DIV_SEL_0, 0x0); |
| 1020 | WREG32(mmIC_PLL_DIV_SEL_1, 0x0); |
| 1021 | WREG32(mmIC_PLL_DIV_SEL_2, 0x0); |
| 1022 | WREG32(mmIC_PLL_DIV_SEL_3, 0x0); |
| 1023 | |
| 1024 | WREG32(mmMC_PLL_DIV_SEL_0, 0x0); |
| 1025 | WREG32(mmMC_PLL_DIV_SEL_1, 0x0); |
| 1026 | WREG32(mmMC_PLL_DIV_SEL_2, 0x0); |
| 1027 | WREG32(mmMC_PLL_DIV_SEL_3, 0x0); |
| 1028 | |
| 1029 | WREG32(mmPSOC_MME_PLL_DIV_SEL_0, 0x0); |
| 1030 | WREG32(mmPSOC_MME_PLL_DIV_SEL_1, 0x0); |
| 1031 | WREG32(mmPSOC_MME_PLL_DIV_SEL_2, 0x0); |
| 1032 | WREG32(mmPSOC_MME_PLL_DIV_SEL_3, 0x0); |
| 1033 | |
| 1034 | WREG32(mmPSOC_PCI_PLL_DIV_SEL_0, 0x0); |
| 1035 | WREG32(mmPSOC_PCI_PLL_DIV_SEL_1, 0x0); |
| 1036 | WREG32(mmPSOC_PCI_PLL_DIV_SEL_2, 0x0); |
| 1037 | WREG32(mmPSOC_PCI_PLL_DIV_SEL_3, 0x0); |
| 1038 | |
| 1039 | WREG32(mmPSOC_EMMC_PLL_DIV_SEL_0, 0x0); |
| 1040 | WREG32(mmPSOC_EMMC_PLL_DIV_SEL_1, 0x0); |
| 1041 | WREG32(mmPSOC_EMMC_PLL_DIV_SEL_2, 0x0); |
| 1042 | WREG32(mmPSOC_EMMC_PLL_DIV_SEL_3, 0x0); |
| 1043 | |
| 1044 | WREG32(mmTPC_PLL_DIV_SEL_0, 0x0); |
| 1045 | WREG32(mmTPC_PLL_DIV_SEL_1, 0x0); |
| 1046 | WREG32(mmTPC_PLL_DIV_SEL_2, 0x0); |
| 1047 | WREG32(mmTPC_PLL_DIV_SEL_3, 0x0); |
| 1048 | } |
| 1049 | |
| 1050 | static void goya_disable_clk_rlx(struct hl_device *hdev) |
| 1051 | { |
| 1052 | WREG32(mmPSOC_MME_PLL_CLK_RLX_0, 0x100010); |
| 1053 | WREG32(mmIC_PLL_CLK_RLX_0, 0x100010); |
| 1054 | } |
| 1055 | |
| 1056 | static void _goya_tpc_mbist_workaround(struct hl_device *hdev, u8 tpc_id) |
| 1057 | { |
| 1058 | u64 tpc_eml_address; |
| 1059 | u32 val, tpc_offset, tpc_eml_offset, tpc_slm_offset; |
| 1060 | int err, slm_index; |
| 1061 | |
| 1062 | tpc_offset = tpc_id * 0x40000; |
| 1063 | tpc_eml_offset = tpc_id * 0x200000; |
| 1064 | tpc_eml_address = (mmTPC0_EML_CFG_BASE + tpc_eml_offset - CFG_BASE); |
| 1065 | tpc_slm_offset = tpc_eml_address + 0x100000; |
| 1066 | |
| 1067 | /* |
| 1068 | * Workaround for Bug H2 #2443 : |
| 1069 | * "TPC SB is not initialized on chip reset" |
| 1070 | */ |
| 1071 | |
| 1072 | val = RREG32(mmTPC0_CFG_FUNC_MBIST_CNTRL + tpc_offset); |
| 1073 | if (val & TPC0_CFG_FUNC_MBIST_CNTRL_MBIST_ACTIVE_MASK) |
| 1074 | dev_warn(hdev->dev, "TPC%d MBIST ACTIVE is not cleared\n", |
| 1075 | tpc_id); |
| 1076 | |
| 1077 | WREG32(mmTPC0_CFG_FUNC_MBIST_PAT + tpc_offset, val & 0xFFFFF000); |
| 1078 | |
| 1079 | WREG32(mmTPC0_CFG_FUNC_MBIST_MEM_0 + tpc_offset, 0x37FF); |
| 1080 | WREG32(mmTPC0_CFG_FUNC_MBIST_MEM_1 + tpc_offset, 0x303F); |
| 1081 | WREG32(mmTPC0_CFG_FUNC_MBIST_MEM_2 + tpc_offset, 0x71FF); |
| 1082 | WREG32(mmTPC0_CFG_FUNC_MBIST_MEM_3 + tpc_offset, 0x71FF); |
| 1083 | WREG32(mmTPC0_CFG_FUNC_MBIST_MEM_4 + tpc_offset, 0x70FF); |
| 1084 | WREG32(mmTPC0_CFG_FUNC_MBIST_MEM_5 + tpc_offset, 0x70FF); |
| 1085 | WREG32(mmTPC0_CFG_FUNC_MBIST_MEM_6 + tpc_offset, 0x70FF); |
| 1086 | WREG32(mmTPC0_CFG_FUNC_MBIST_MEM_7 + tpc_offset, 0x70FF); |
| 1087 | WREG32(mmTPC0_CFG_FUNC_MBIST_MEM_8 + tpc_offset, 0x70FF); |
| 1088 | WREG32(mmTPC0_CFG_FUNC_MBIST_MEM_9 + tpc_offset, 0x70FF); |
| 1089 | |
| 1090 | WREG32_OR(mmTPC0_CFG_FUNC_MBIST_CNTRL + tpc_offset, |
| 1091 | 1 << TPC0_CFG_FUNC_MBIST_CNTRL_MBIST_START_SHIFT); |
| 1092 | |
| 1093 | err = hl_poll_timeout( |
| 1094 | hdev, |
| 1095 | mmTPC0_CFG_FUNC_MBIST_CNTRL + tpc_offset, |
| 1096 | val, |
| 1097 | (val & TPC0_CFG_FUNC_MBIST_CNTRL_MBIST_DONE_MASK), |
| 1098 | 1000, |
| 1099 | HL_DEVICE_TIMEOUT_USEC); |
| 1100 | |
| 1101 | if (err) |
| 1102 | dev_err(hdev->dev, |
| 1103 | "Timeout while waiting for TPC%d MBIST DONE\n", tpc_id); |
| 1104 | |
| 1105 | WREG32_OR(mmTPC0_EML_CFG_DBG_CNT + tpc_eml_offset, |
| 1106 | 1 << TPC0_EML_CFG_DBG_CNT_CORE_RST_SHIFT); |
| 1107 | |
| 1108 | msleep(GOYA_RESET_WAIT_MSEC); |
| 1109 | |
| 1110 | WREG32_AND(mmTPC0_EML_CFG_DBG_CNT + tpc_eml_offset, |
| 1111 | ~(1 << TPC0_EML_CFG_DBG_CNT_CORE_RST_SHIFT)); |
| 1112 | |
| 1113 | msleep(GOYA_RESET_WAIT_MSEC); |
| 1114 | |
| 1115 | for (slm_index = 0 ; slm_index < 256 ; slm_index++) |
| 1116 | WREG32(tpc_slm_offset + (slm_index << 2), 0); |
| 1117 | |
| 1118 | val = RREG32(tpc_slm_offset); |
| 1119 | } |
| 1120 | |
| 1121 | static void goya_tpc_mbist_workaround(struct hl_device *hdev) |
| 1122 | { |
| 1123 | struct goya_device *goya = hdev->asic_specific; |
| 1124 | int i; |
| 1125 | |
| 1126 | if (hdev->pldm) |
| 1127 | return; |
| 1128 | |
| 1129 | if (goya->hw_cap_initialized & HW_CAP_TPC_MBIST) |
| 1130 | return; |
| 1131 | |
| 1132 | /* Workaround for H2 #2443 */ |
| 1133 | |
| 1134 | for (i = 0 ; i < TPC_MAX_NUM ; i++) |
| 1135 | _goya_tpc_mbist_workaround(hdev, i); |
| 1136 | |
| 1137 | goya->hw_cap_initialized |= HW_CAP_TPC_MBIST; |
| 1138 | } |
| 1139 | |
| 1140 | /* |
| 1141 | * goya_init_golden_registers - Initialize golden registers |
| 1142 | * |
| 1143 | * @hdev: pointer to hl_device structure |
| 1144 | * |
| 1145 | * Initialize the H/W registers of the device |
| 1146 | * |
| 1147 | */ |
| 1148 | static void goya_init_golden_registers(struct hl_device *hdev) |
| 1149 | { |
| 1150 | struct goya_device *goya = hdev->asic_specific; |
| 1151 | u32 polynom[10], tpc_intr_mask, offset; |
| 1152 | int i; |
| 1153 | |
| 1154 | if (goya->hw_cap_initialized & HW_CAP_GOLDEN) |
| 1155 | return; |
| 1156 | |
| 1157 | polynom[0] = 0x00020080; |
| 1158 | polynom[1] = 0x00401000; |
| 1159 | polynom[2] = 0x00200800; |
| 1160 | polynom[3] = 0x00002000; |
| 1161 | polynom[4] = 0x00080200; |
| 1162 | polynom[5] = 0x00040100; |
| 1163 | polynom[6] = 0x00100400; |
| 1164 | polynom[7] = 0x00004000; |
| 1165 | polynom[8] = 0x00010000; |
| 1166 | polynom[9] = 0x00008000; |
| 1167 | |
| 1168 | /* Mask all arithmetic interrupts from TPC */ |
| 1169 | tpc_intr_mask = 0x7FFF; |
| 1170 | |
| 1171 | for (i = 0, offset = 0 ; i < 6 ; i++, offset += 0x20000) { |
| 1172 | WREG32(mmSRAM_Y0_X0_RTR_HBW_RD_RQ_L_ARB + offset, 0x302); |
| 1173 | WREG32(mmSRAM_Y0_X1_RTR_HBW_RD_RQ_L_ARB + offset, 0x302); |
| 1174 | WREG32(mmSRAM_Y0_X2_RTR_HBW_RD_RQ_L_ARB + offset, 0x302); |
| 1175 | WREG32(mmSRAM_Y0_X3_RTR_HBW_RD_RQ_L_ARB + offset, 0x302); |
| 1176 | WREG32(mmSRAM_Y0_X4_RTR_HBW_RD_RQ_L_ARB + offset, 0x302); |
| 1177 | |
| 1178 | WREG32(mmSRAM_Y0_X0_RTR_HBW_DATA_L_ARB + offset, 0x204); |
| 1179 | WREG32(mmSRAM_Y0_X1_RTR_HBW_DATA_L_ARB + offset, 0x204); |
| 1180 | WREG32(mmSRAM_Y0_X2_RTR_HBW_DATA_L_ARB + offset, 0x204); |
| 1181 | WREG32(mmSRAM_Y0_X3_RTR_HBW_DATA_L_ARB + offset, 0x204); |
| 1182 | WREG32(mmSRAM_Y0_X4_RTR_HBW_DATA_L_ARB + offset, 0x204); |
| 1183 | |
| 1184 | |
| 1185 | WREG32(mmSRAM_Y0_X0_RTR_HBW_DATA_E_ARB + offset, 0x206); |
| 1186 | WREG32(mmSRAM_Y0_X1_RTR_HBW_DATA_E_ARB + offset, 0x206); |
| 1187 | WREG32(mmSRAM_Y0_X2_RTR_HBW_DATA_E_ARB + offset, 0x206); |
| 1188 | WREG32(mmSRAM_Y0_X3_RTR_HBW_DATA_E_ARB + offset, 0x207); |
| 1189 | WREG32(mmSRAM_Y0_X4_RTR_HBW_DATA_E_ARB + offset, 0x207); |
| 1190 | |
| 1191 | WREG32(mmSRAM_Y0_X0_RTR_HBW_DATA_W_ARB + offset, 0x207); |
| 1192 | WREG32(mmSRAM_Y0_X1_RTR_HBW_DATA_W_ARB + offset, 0x207); |
| 1193 | WREG32(mmSRAM_Y0_X2_RTR_HBW_DATA_W_ARB + offset, 0x206); |
| 1194 | WREG32(mmSRAM_Y0_X3_RTR_HBW_DATA_W_ARB + offset, 0x206); |
| 1195 | WREG32(mmSRAM_Y0_X4_RTR_HBW_DATA_W_ARB + offset, 0x206); |
| 1196 | |
| 1197 | WREG32(mmSRAM_Y0_X0_RTR_HBW_WR_RS_E_ARB + offset, 0x101); |
| 1198 | WREG32(mmSRAM_Y0_X1_RTR_HBW_WR_RS_E_ARB + offset, 0x102); |
| 1199 | WREG32(mmSRAM_Y0_X2_RTR_HBW_WR_RS_E_ARB + offset, 0x103); |
| 1200 | WREG32(mmSRAM_Y0_X3_RTR_HBW_WR_RS_E_ARB + offset, 0x104); |
| 1201 | WREG32(mmSRAM_Y0_X4_RTR_HBW_WR_RS_E_ARB + offset, 0x105); |
| 1202 | |
| 1203 | WREG32(mmSRAM_Y0_X0_RTR_HBW_WR_RS_W_ARB + offset, 0x105); |
| 1204 | WREG32(mmSRAM_Y0_X1_RTR_HBW_WR_RS_W_ARB + offset, 0x104); |
| 1205 | WREG32(mmSRAM_Y0_X2_RTR_HBW_WR_RS_W_ARB + offset, 0x103); |
| 1206 | WREG32(mmSRAM_Y0_X3_RTR_HBW_WR_RS_W_ARB + offset, 0x102); |
| 1207 | WREG32(mmSRAM_Y0_X4_RTR_HBW_WR_RS_W_ARB + offset, 0x101); |
| 1208 | } |
| 1209 | |
| 1210 | WREG32(mmMME_STORE_MAX_CREDIT, 0x21); |
| 1211 | WREG32(mmMME_AGU, 0x0f0f0f10); |
| 1212 | WREG32(mmMME_SEI_MASK, ~0x0); |
| 1213 | |
| 1214 | WREG32(mmMME6_RTR_HBW_RD_RQ_N_ARB, 0x01010101); |
| 1215 | WREG32(mmMME5_RTR_HBW_RD_RQ_N_ARB, 0x01040101); |
| 1216 | WREG32(mmMME4_RTR_HBW_RD_RQ_N_ARB, 0x01030101); |
| 1217 | WREG32(mmMME3_RTR_HBW_RD_RQ_N_ARB, 0x01020101); |
| 1218 | WREG32(mmMME2_RTR_HBW_RD_RQ_N_ARB, 0x01010101); |
| 1219 | WREG32(mmMME1_RTR_HBW_RD_RQ_N_ARB, 0x07010701); |
| 1220 | WREG32(mmMME6_RTR_HBW_RD_RQ_S_ARB, 0x04010401); |
| 1221 | WREG32(mmMME5_RTR_HBW_RD_RQ_S_ARB, 0x04050401); |
| 1222 | WREG32(mmMME4_RTR_HBW_RD_RQ_S_ARB, 0x03070301); |
| 1223 | WREG32(mmMME3_RTR_HBW_RD_RQ_S_ARB, 0x01030101); |
| 1224 | WREG32(mmMME2_RTR_HBW_RD_RQ_S_ARB, 0x01040101); |
| 1225 | WREG32(mmMME1_RTR_HBW_RD_RQ_S_ARB, 0x01050105); |
| 1226 | WREG32(mmMME6_RTR_HBW_RD_RQ_W_ARB, 0x01010501); |
| 1227 | WREG32(mmMME5_RTR_HBW_RD_RQ_W_ARB, 0x01010501); |
| 1228 | WREG32(mmMME4_RTR_HBW_RD_RQ_W_ARB, 0x01040301); |
| 1229 | WREG32(mmMME3_RTR_HBW_RD_RQ_W_ARB, 0x01030401); |
| 1230 | WREG32(mmMME2_RTR_HBW_RD_RQ_W_ARB, 0x01040101); |
| 1231 | WREG32(mmMME1_RTR_HBW_RD_RQ_W_ARB, 0x01050101); |
| 1232 | WREG32(mmMME6_RTR_HBW_WR_RQ_N_ARB, 0x02020202); |
| 1233 | WREG32(mmMME5_RTR_HBW_WR_RQ_N_ARB, 0x01070101); |
| 1234 | WREG32(mmMME4_RTR_HBW_WR_RQ_N_ARB, 0x02020201); |
| 1235 | WREG32(mmMME3_RTR_HBW_WR_RQ_N_ARB, 0x07020701); |
| 1236 | WREG32(mmMME2_RTR_HBW_WR_RQ_N_ARB, 0x01020101); |
| 1237 | WREG32(mmMME1_RTR_HBW_WR_RQ_S_ARB, 0x01010101); |
| 1238 | WREG32(mmMME6_RTR_HBW_WR_RQ_S_ARB, 0x01070101); |
| 1239 | WREG32(mmMME5_RTR_HBW_WR_RQ_S_ARB, 0x01070101); |
| 1240 | WREG32(mmMME4_RTR_HBW_WR_RQ_S_ARB, 0x07020701); |
| 1241 | WREG32(mmMME3_RTR_HBW_WR_RQ_S_ARB, 0x02020201); |
| 1242 | WREG32(mmMME2_RTR_HBW_WR_RQ_S_ARB, 0x01070101); |
| 1243 | WREG32(mmMME1_RTR_HBW_WR_RQ_S_ARB, 0x01020102); |
| 1244 | WREG32(mmMME6_RTR_HBW_WR_RQ_W_ARB, 0x01020701); |
| 1245 | WREG32(mmMME5_RTR_HBW_WR_RQ_W_ARB, 0x01020701); |
| 1246 | WREG32(mmMME4_RTR_HBW_WR_RQ_W_ARB, 0x07020707); |
| 1247 | WREG32(mmMME3_RTR_HBW_WR_RQ_W_ARB, 0x01020201); |
| 1248 | WREG32(mmMME2_RTR_HBW_WR_RQ_W_ARB, 0x01070201); |
| 1249 | WREG32(mmMME1_RTR_HBW_WR_RQ_W_ARB, 0x01070201); |
| 1250 | WREG32(mmMME6_RTR_HBW_RD_RS_N_ARB, 0x01070102); |
| 1251 | WREG32(mmMME5_RTR_HBW_RD_RS_N_ARB, 0x01070102); |
| 1252 | WREG32(mmMME4_RTR_HBW_RD_RS_N_ARB, 0x01060102); |
| 1253 | WREG32(mmMME3_RTR_HBW_RD_RS_N_ARB, 0x01040102); |
| 1254 | WREG32(mmMME2_RTR_HBW_RD_RS_N_ARB, 0x01020102); |
| 1255 | WREG32(mmMME1_RTR_HBW_RD_RS_N_ARB, 0x01020107); |
| 1256 | WREG32(mmMME6_RTR_HBW_RD_RS_S_ARB, 0x01020106); |
| 1257 | WREG32(mmMME5_RTR_HBW_RD_RS_S_ARB, 0x01020102); |
| 1258 | WREG32(mmMME4_RTR_HBW_RD_RS_S_ARB, 0x01040102); |
| 1259 | WREG32(mmMME3_RTR_HBW_RD_RS_S_ARB, 0x01060102); |
| 1260 | WREG32(mmMME2_RTR_HBW_RD_RS_S_ARB, 0x01070102); |
| 1261 | WREG32(mmMME1_RTR_HBW_RD_RS_S_ARB, 0x01070102); |
| 1262 | WREG32(mmMME6_RTR_HBW_RD_RS_E_ARB, 0x01020702); |
| 1263 | WREG32(mmMME5_RTR_HBW_RD_RS_E_ARB, 0x01020702); |
| 1264 | WREG32(mmMME4_RTR_HBW_RD_RS_E_ARB, 0x01040602); |
| 1265 | WREG32(mmMME3_RTR_HBW_RD_RS_E_ARB, 0x01060402); |
| 1266 | WREG32(mmMME2_RTR_HBW_RD_RS_E_ARB, 0x01070202); |
| 1267 | WREG32(mmMME1_RTR_HBW_RD_RS_E_ARB, 0x01070102); |
| 1268 | WREG32(mmMME6_RTR_HBW_RD_RS_W_ARB, 0x01060401); |
| 1269 | WREG32(mmMME5_RTR_HBW_RD_RS_W_ARB, 0x01060401); |
| 1270 | WREG32(mmMME4_RTR_HBW_RD_RS_W_ARB, 0x01060401); |
| 1271 | WREG32(mmMME3_RTR_HBW_RD_RS_W_ARB, 0x01060401); |
| 1272 | WREG32(mmMME2_RTR_HBW_RD_RS_W_ARB, 0x01060401); |
| 1273 | WREG32(mmMME1_RTR_HBW_RD_RS_W_ARB, 0x01060401); |
| 1274 | WREG32(mmMME6_RTR_HBW_WR_RS_N_ARB, 0x01050101); |
| 1275 | WREG32(mmMME5_RTR_HBW_WR_RS_N_ARB, 0x01040101); |
| 1276 | WREG32(mmMME4_RTR_HBW_WR_RS_N_ARB, 0x01030101); |
| 1277 | WREG32(mmMME3_RTR_HBW_WR_RS_N_ARB, 0x01020101); |
| 1278 | WREG32(mmMME2_RTR_HBW_WR_RS_N_ARB, 0x01010101); |
| 1279 | WREG32(mmMME1_RTR_HBW_WR_RS_N_ARB, 0x01010107); |
| 1280 | WREG32(mmMME6_RTR_HBW_WR_RS_S_ARB, 0x01010107); |
| 1281 | WREG32(mmMME5_RTR_HBW_WR_RS_S_ARB, 0x01010101); |
| 1282 | WREG32(mmMME4_RTR_HBW_WR_RS_S_ARB, 0x01020101); |
| 1283 | WREG32(mmMME3_RTR_HBW_WR_RS_S_ARB, 0x01030101); |
| 1284 | WREG32(mmMME2_RTR_HBW_WR_RS_S_ARB, 0x01040101); |
| 1285 | WREG32(mmMME1_RTR_HBW_WR_RS_S_ARB, 0x01050101); |
| 1286 | WREG32(mmMME6_RTR_HBW_WR_RS_E_ARB, 0x01010501); |
| 1287 | WREG32(mmMME5_RTR_HBW_WR_RS_E_ARB, 0x01010501); |
| 1288 | WREG32(mmMME4_RTR_HBW_WR_RS_E_ARB, 0x01040301); |
| 1289 | WREG32(mmMME3_RTR_HBW_WR_RS_E_ARB, 0x01030401); |
| 1290 | WREG32(mmMME2_RTR_HBW_WR_RS_E_ARB, 0x01040101); |
| 1291 | WREG32(mmMME1_RTR_HBW_WR_RS_E_ARB, 0x01050101); |
| 1292 | WREG32(mmMME6_RTR_HBW_WR_RS_W_ARB, 0x01010101); |
| 1293 | WREG32(mmMME5_RTR_HBW_WR_RS_W_ARB, 0x01010101); |
| 1294 | WREG32(mmMME4_RTR_HBW_WR_RS_W_ARB, 0x01010101); |
| 1295 | WREG32(mmMME3_RTR_HBW_WR_RS_W_ARB, 0x01010101); |
| 1296 | WREG32(mmMME2_RTR_HBW_WR_RS_W_ARB, 0x01010101); |
| 1297 | WREG32(mmMME1_RTR_HBW_WR_RS_W_ARB, 0x01010101); |
| 1298 | |
| 1299 | WREG32(mmTPC1_RTR_HBW_RD_RQ_N_ARB, 0x01010101); |
| 1300 | WREG32(mmTPC1_RTR_HBW_RD_RQ_S_ARB, 0x01010101); |
| 1301 | WREG32(mmTPC1_RTR_HBW_RD_RQ_E_ARB, 0x01060101); |
| 1302 | WREG32(mmTPC1_RTR_HBW_WR_RQ_N_ARB, 0x02020102); |
| 1303 | WREG32(mmTPC1_RTR_HBW_WR_RQ_S_ARB, 0x01010101); |
| 1304 | WREG32(mmTPC1_RTR_HBW_WR_RQ_E_ARB, 0x02070202); |
| 1305 | WREG32(mmTPC1_RTR_HBW_RD_RS_N_ARB, 0x01020201); |
| 1306 | WREG32(mmTPC1_RTR_HBW_RD_RS_S_ARB, 0x01070201); |
| 1307 | WREG32(mmTPC1_RTR_HBW_RD_RS_W_ARB, 0x01070202); |
| 1308 | WREG32(mmTPC1_RTR_HBW_WR_RS_N_ARB, 0x01010101); |
| 1309 | WREG32(mmTPC1_RTR_HBW_WR_RS_S_ARB, 0x01050101); |
| 1310 | WREG32(mmTPC1_RTR_HBW_WR_RS_W_ARB, 0x01050101); |
| 1311 | |
| 1312 | WREG32(mmTPC2_RTR_HBW_RD_RQ_N_ARB, 0x01020101); |
| 1313 | WREG32(mmTPC2_RTR_HBW_RD_RQ_S_ARB, 0x01050101); |
| 1314 | WREG32(mmTPC2_RTR_HBW_RD_RQ_E_ARB, 0x01010201); |
| 1315 | WREG32(mmTPC2_RTR_HBW_WR_RQ_N_ARB, 0x02040102); |
| 1316 | WREG32(mmTPC2_RTR_HBW_WR_RQ_S_ARB, 0x01050101); |
| 1317 | WREG32(mmTPC2_RTR_HBW_WR_RQ_E_ARB, 0x02060202); |
| 1318 | WREG32(mmTPC2_RTR_HBW_RD_RS_N_ARB, 0x01020201); |
| 1319 | WREG32(mmTPC2_RTR_HBW_RD_RS_S_ARB, 0x01070201); |
| 1320 | WREG32(mmTPC2_RTR_HBW_RD_RS_W_ARB, 0x01070202); |
| 1321 | WREG32(mmTPC2_RTR_HBW_WR_RS_N_ARB, 0x01010101); |
| 1322 | WREG32(mmTPC2_RTR_HBW_WR_RS_S_ARB, 0x01040101); |
| 1323 | WREG32(mmTPC2_RTR_HBW_WR_RS_W_ARB, 0x01040101); |
| 1324 | |
| 1325 | WREG32(mmTPC3_RTR_HBW_RD_RQ_N_ARB, 0x01030101); |
| 1326 | WREG32(mmTPC3_RTR_HBW_RD_RQ_S_ARB, 0x01040101); |
| 1327 | WREG32(mmTPC3_RTR_HBW_RD_RQ_E_ARB, 0x01040301); |
| 1328 | WREG32(mmTPC3_RTR_HBW_WR_RQ_N_ARB, 0x02060102); |
| 1329 | WREG32(mmTPC3_RTR_HBW_WR_RQ_S_ARB, 0x01040101); |
| 1330 | WREG32(mmTPC3_RTR_HBW_WR_RQ_E_ARB, 0x01040301); |
| 1331 | WREG32(mmTPC3_RTR_HBW_RD_RS_N_ARB, 0x01040201); |
| 1332 | WREG32(mmTPC3_RTR_HBW_RD_RS_S_ARB, 0x01060201); |
| 1333 | WREG32(mmTPC3_RTR_HBW_RD_RS_W_ARB, 0x01060402); |
| 1334 | WREG32(mmTPC3_RTR_HBW_WR_RS_N_ARB, 0x01020101); |
| 1335 | WREG32(mmTPC3_RTR_HBW_WR_RS_S_ARB, 0x01030101); |
| 1336 | WREG32(mmTPC3_RTR_HBW_WR_RS_W_ARB, 0x01030401); |
| 1337 | |
| 1338 | WREG32(mmTPC4_RTR_HBW_RD_RQ_N_ARB, 0x01040101); |
| 1339 | WREG32(mmTPC4_RTR_HBW_RD_RQ_S_ARB, 0x01030101); |
| 1340 | WREG32(mmTPC4_RTR_HBW_RD_RQ_E_ARB, 0x01030401); |
| 1341 | WREG32(mmTPC4_RTR_HBW_WR_RQ_N_ARB, 0x02070102); |
| 1342 | WREG32(mmTPC4_RTR_HBW_WR_RQ_S_ARB, 0x01030101); |
| 1343 | WREG32(mmTPC4_RTR_HBW_WR_RQ_E_ARB, 0x02060702); |
| 1344 | WREG32(mmTPC4_RTR_HBW_RD_RS_N_ARB, 0x01060201); |
| 1345 | WREG32(mmTPC4_RTR_HBW_RD_RS_S_ARB, 0x01040201); |
| 1346 | WREG32(mmTPC4_RTR_HBW_RD_RS_W_ARB, 0x01040602); |
| 1347 | WREG32(mmTPC4_RTR_HBW_WR_RS_N_ARB, 0x01030101); |
| 1348 | WREG32(mmTPC4_RTR_HBW_WR_RS_S_ARB, 0x01020101); |
| 1349 | WREG32(mmTPC4_RTR_HBW_WR_RS_W_ARB, 0x01040301); |
| 1350 | |
| 1351 | WREG32(mmTPC5_RTR_HBW_RD_RQ_N_ARB, 0x01050101); |
| 1352 | WREG32(mmTPC5_RTR_HBW_RD_RQ_S_ARB, 0x01020101); |
| 1353 | WREG32(mmTPC5_RTR_HBW_RD_RQ_E_ARB, 0x01200501); |
| 1354 | WREG32(mmTPC5_RTR_HBW_WR_RQ_N_ARB, 0x02070102); |
| 1355 | WREG32(mmTPC5_RTR_HBW_WR_RQ_S_ARB, 0x01020101); |
| 1356 | WREG32(mmTPC5_RTR_HBW_WR_RQ_E_ARB, 0x02020602); |
| 1357 | WREG32(mmTPC5_RTR_HBW_RD_RS_N_ARB, 0x01070201); |
| 1358 | WREG32(mmTPC5_RTR_HBW_RD_RS_S_ARB, 0x01020201); |
| 1359 | WREG32(mmTPC5_RTR_HBW_RD_RS_W_ARB, 0x01020702); |
| 1360 | WREG32(mmTPC5_RTR_HBW_WR_RS_N_ARB, 0x01040101); |
| 1361 | WREG32(mmTPC5_RTR_HBW_WR_RS_S_ARB, 0x01010101); |
| 1362 | WREG32(mmTPC5_RTR_HBW_WR_RS_W_ARB, 0x01010501); |
| 1363 | |
| 1364 | WREG32(mmTPC6_RTR_HBW_RD_RQ_N_ARB, 0x01010101); |
| 1365 | WREG32(mmTPC6_RTR_HBW_RD_RQ_S_ARB, 0x01010101); |
| 1366 | WREG32(mmTPC6_RTR_HBW_RD_RQ_E_ARB, 0x01010601); |
| 1367 | WREG32(mmTPC6_RTR_HBW_WR_RQ_N_ARB, 0x01010101); |
| 1368 | WREG32(mmTPC6_RTR_HBW_WR_RQ_S_ARB, 0x01010101); |
| 1369 | WREG32(mmTPC6_RTR_HBW_WR_RQ_E_ARB, 0x02020702); |
| 1370 | WREG32(mmTPC6_RTR_HBW_RD_RS_N_ARB, 0x01010101); |
| 1371 | WREG32(mmTPC6_RTR_HBW_RD_RS_S_ARB, 0x01010101); |
| 1372 | WREG32(mmTPC6_RTR_HBW_RD_RS_W_ARB, 0x01020702); |
| 1373 | WREG32(mmTPC6_RTR_HBW_WR_RS_N_ARB, 0x01050101); |
| 1374 | WREG32(mmTPC6_RTR_HBW_WR_RS_S_ARB, 0x01010101); |
| 1375 | WREG32(mmTPC6_RTR_HBW_WR_RS_W_ARB, 0x01010501); |
| 1376 | |
| 1377 | for (i = 0, offset = 0 ; i < 10 ; i++, offset += 4) { |
| 1378 | WREG32(mmMME1_RTR_SPLIT_COEF_0 + offset, polynom[i] >> 7); |
| 1379 | WREG32(mmMME2_RTR_SPLIT_COEF_0 + offset, polynom[i] >> 7); |
| 1380 | WREG32(mmMME3_RTR_SPLIT_COEF_0 + offset, polynom[i] >> 7); |
| 1381 | WREG32(mmMME4_RTR_SPLIT_COEF_0 + offset, polynom[i] >> 7); |
| 1382 | WREG32(mmMME5_RTR_SPLIT_COEF_0 + offset, polynom[i] >> 7); |
| 1383 | WREG32(mmMME6_RTR_SPLIT_COEF_0 + offset, polynom[i] >> 7); |
| 1384 | |
| 1385 | WREG32(mmTPC0_NRTR_SPLIT_COEF_0 + offset, polynom[i] >> 7); |
| 1386 | WREG32(mmTPC1_RTR_SPLIT_COEF_0 + offset, polynom[i] >> 7); |
| 1387 | WREG32(mmTPC2_RTR_SPLIT_COEF_0 + offset, polynom[i] >> 7); |
| 1388 | WREG32(mmTPC3_RTR_SPLIT_COEF_0 + offset, polynom[i] >> 7); |
| 1389 | WREG32(mmTPC4_RTR_SPLIT_COEF_0 + offset, polynom[i] >> 7); |
| 1390 | WREG32(mmTPC5_RTR_SPLIT_COEF_0 + offset, polynom[i] >> 7); |
| 1391 | WREG32(mmTPC6_RTR_SPLIT_COEF_0 + offset, polynom[i] >> 7); |
| 1392 | WREG32(mmTPC7_NRTR_SPLIT_COEF_0 + offset, polynom[i] >> 7); |
| 1393 | |
| 1394 | WREG32(mmPCI_NRTR_SPLIT_COEF_0 + offset, polynom[i] >> 7); |
| 1395 | WREG32(mmDMA_NRTR_SPLIT_COEF_0 + offset, polynom[i] >> 7); |
| 1396 | } |
| 1397 | |
| 1398 | for (i = 0, offset = 0 ; i < 6 ; i++, offset += 0x40000) { |
| 1399 | WREG32(mmMME1_RTR_SCRAMB_EN + offset, |
| 1400 | 1 << MME1_RTR_SCRAMB_EN_VAL_SHIFT); |
| 1401 | WREG32(mmMME1_RTR_NON_LIN_SCRAMB + offset, |
| 1402 | 1 << MME1_RTR_NON_LIN_SCRAMB_EN_SHIFT); |
| 1403 | } |
| 1404 | |
| 1405 | for (i = 0, offset = 0 ; i < 8 ; i++, offset += 0x40000) { |
| 1406 | /* |
| 1407 | * Workaround for Bug H2 #2441 : |
| 1408 | * "ST.NOP set trace event illegal opcode" |
| 1409 | */ |
| 1410 | WREG32(mmTPC0_CFG_TPC_INTR_MASK + offset, tpc_intr_mask); |
| 1411 | |
| 1412 | WREG32(mmTPC0_NRTR_SCRAMB_EN + offset, |
| 1413 | 1 << TPC0_NRTR_SCRAMB_EN_VAL_SHIFT); |
| 1414 | WREG32(mmTPC0_NRTR_NON_LIN_SCRAMB + offset, |
| 1415 | 1 << TPC0_NRTR_NON_LIN_SCRAMB_EN_SHIFT); |
| 1416 | } |
| 1417 | |
| 1418 | WREG32(mmDMA_NRTR_SCRAMB_EN, 1 << DMA_NRTR_SCRAMB_EN_VAL_SHIFT); |
| 1419 | WREG32(mmDMA_NRTR_NON_LIN_SCRAMB, |
| 1420 | 1 << DMA_NRTR_NON_LIN_SCRAMB_EN_SHIFT); |
| 1421 | |
| 1422 | WREG32(mmPCI_NRTR_SCRAMB_EN, 1 << PCI_NRTR_SCRAMB_EN_VAL_SHIFT); |
| 1423 | WREG32(mmPCI_NRTR_NON_LIN_SCRAMB, |
| 1424 | 1 << PCI_NRTR_NON_LIN_SCRAMB_EN_SHIFT); |
| 1425 | |
| 1426 | /* |
| 1427 | * Workaround for H2 #HW-23 bug |
Oded Gabbay | bfb57a9 | 2019-03-24 18:07:02 +0200 | [diff] [blame] | 1428 | * Set DMA max outstanding read requests to 240 on DMA CH 1. |
| 1429 | * This limitation is still large enough to not affect Gen4 bandwidth. |
| 1430 | * We need to only limit that DMA channel because the user can only read |
Oded Gabbay | 839c480 | 2019-02-16 00:39:16 +0200 | [diff] [blame] | 1431 | * from Host using DMA CH 1 |
| 1432 | */ |
Oded Gabbay | 839c480 | 2019-02-16 00:39:16 +0200 | [diff] [blame] | 1433 | WREG32(mmDMA_CH_1_CFG0, 0x0fff00F0); |
Omer Shpigelman | 8ba2876 | 2019-04-01 22:23:02 +0300 | [diff] [blame] | 1434 | |
Dalit Ben Zoor | a691a1e | 2019-03-20 16:13:23 +0200 | [diff] [blame] | 1435 | WREG32(mmTPC_PLL_CLK_RLX_0, 0x200020); |
Oded Gabbay | 839c480 | 2019-02-16 00:39:16 +0200 | [diff] [blame] | 1436 | |
| 1437 | goya->hw_cap_initialized |= HW_CAP_GOLDEN; |
| 1438 | } |
| 1439 | |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 1440 | static void goya_init_mme_qman(struct hl_device *hdev) |
| 1441 | { |
| 1442 | u32 mtr_base_lo, mtr_base_hi; |
| 1443 | u32 so_base_lo, so_base_hi; |
| 1444 | u32 gic_base_lo, gic_base_hi; |
| 1445 | u64 qman_base_addr; |
| 1446 | |
| 1447 | mtr_base_lo = lower_32_bits(CFG_BASE + mmSYNC_MNGR_MON_PAY_ADDRL_0); |
| 1448 | mtr_base_hi = upper_32_bits(CFG_BASE + mmSYNC_MNGR_MON_PAY_ADDRL_0); |
| 1449 | so_base_lo = lower_32_bits(CFG_BASE + mmSYNC_MNGR_SOB_OBJ_0); |
| 1450 | so_base_hi = upper_32_bits(CFG_BASE + mmSYNC_MNGR_SOB_OBJ_0); |
| 1451 | |
| 1452 | gic_base_lo = |
| 1453 | lower_32_bits(CFG_BASE + mmGIC_DISTRIBUTOR__5_GICD_SETSPI_NSR); |
| 1454 | gic_base_hi = |
| 1455 | upper_32_bits(CFG_BASE + mmGIC_DISTRIBUTOR__5_GICD_SETSPI_NSR); |
| 1456 | |
| 1457 | qman_base_addr = hdev->asic_prop.sram_base_address + |
| 1458 | MME_QMAN_BASE_OFFSET; |
| 1459 | |
| 1460 | WREG32(mmMME_QM_PQ_BASE_LO, lower_32_bits(qman_base_addr)); |
| 1461 | WREG32(mmMME_QM_PQ_BASE_HI, upper_32_bits(qman_base_addr)); |
| 1462 | WREG32(mmMME_QM_PQ_SIZE, ilog2(MME_QMAN_LENGTH)); |
| 1463 | WREG32(mmMME_QM_PQ_PI, 0); |
| 1464 | WREG32(mmMME_QM_PQ_CI, 0); |
| 1465 | WREG32(mmMME_QM_CP_LDMA_SRC_BASE_LO_OFFSET, 0x10C0); |
| 1466 | WREG32(mmMME_QM_CP_LDMA_SRC_BASE_HI_OFFSET, 0x10C4); |
| 1467 | WREG32(mmMME_QM_CP_LDMA_TSIZE_OFFSET, 0x10C8); |
| 1468 | WREG32(mmMME_QM_CP_LDMA_COMMIT_OFFSET, 0x10CC); |
| 1469 | |
| 1470 | WREG32(mmMME_QM_CP_MSG_BASE0_ADDR_LO, mtr_base_lo); |
| 1471 | WREG32(mmMME_QM_CP_MSG_BASE0_ADDR_HI, mtr_base_hi); |
| 1472 | WREG32(mmMME_QM_CP_MSG_BASE1_ADDR_LO, so_base_lo); |
| 1473 | WREG32(mmMME_QM_CP_MSG_BASE1_ADDR_HI, so_base_hi); |
| 1474 | |
| 1475 | /* QMAN CQ has 8 cache lines */ |
| 1476 | WREG32(mmMME_QM_CQ_CFG1, 0x00080008); |
| 1477 | |
| 1478 | WREG32(mmMME_QM_GLBL_ERR_ADDR_LO, gic_base_lo); |
| 1479 | WREG32(mmMME_QM_GLBL_ERR_ADDR_HI, gic_base_hi); |
| 1480 | |
| 1481 | WREG32(mmMME_QM_GLBL_ERR_WDATA, GOYA_ASYNC_EVENT_ID_MME_QM); |
| 1482 | |
| 1483 | WREG32(mmMME_QM_GLBL_ERR_CFG, QMAN_MME_ERR_MSG_EN); |
| 1484 | |
| 1485 | WREG32(mmMME_QM_GLBL_PROT, QMAN_MME_ERR_PROT); |
| 1486 | |
| 1487 | WREG32(mmMME_QM_GLBL_CFG0, QMAN_MME_ENABLE); |
| 1488 | } |
| 1489 | |
| 1490 | static void goya_init_mme_cmdq(struct hl_device *hdev) |
| 1491 | { |
| 1492 | u32 mtr_base_lo, mtr_base_hi; |
| 1493 | u32 so_base_lo, so_base_hi; |
| 1494 | u32 gic_base_lo, gic_base_hi; |
| 1495 | u64 qman_base_addr; |
| 1496 | |
| 1497 | mtr_base_lo = lower_32_bits(CFG_BASE + mmSYNC_MNGR_MON_PAY_ADDRL_0); |
| 1498 | mtr_base_hi = upper_32_bits(CFG_BASE + mmSYNC_MNGR_MON_PAY_ADDRL_0); |
| 1499 | so_base_lo = lower_32_bits(CFG_BASE + mmSYNC_MNGR_SOB_OBJ_0); |
| 1500 | so_base_hi = upper_32_bits(CFG_BASE + mmSYNC_MNGR_SOB_OBJ_0); |
| 1501 | |
| 1502 | gic_base_lo = |
| 1503 | lower_32_bits(CFG_BASE + mmGIC_DISTRIBUTOR__5_GICD_SETSPI_NSR); |
| 1504 | gic_base_hi = |
| 1505 | upper_32_bits(CFG_BASE + mmGIC_DISTRIBUTOR__5_GICD_SETSPI_NSR); |
| 1506 | |
| 1507 | qman_base_addr = hdev->asic_prop.sram_base_address + |
| 1508 | MME_QMAN_BASE_OFFSET; |
| 1509 | |
| 1510 | WREG32(mmMME_CMDQ_CP_MSG_BASE0_ADDR_LO, mtr_base_lo); |
| 1511 | WREG32(mmMME_CMDQ_CP_MSG_BASE0_ADDR_HI, mtr_base_hi); |
| 1512 | WREG32(mmMME_CMDQ_CP_MSG_BASE1_ADDR_LO, so_base_lo); |
| 1513 | WREG32(mmMME_CMDQ_CP_MSG_BASE1_ADDR_HI, so_base_hi); |
| 1514 | |
| 1515 | /* CMDQ CQ has 20 cache lines */ |
| 1516 | WREG32(mmMME_CMDQ_CQ_CFG1, 0x00140014); |
| 1517 | |
| 1518 | WREG32(mmMME_CMDQ_GLBL_ERR_ADDR_LO, gic_base_lo); |
| 1519 | WREG32(mmMME_CMDQ_GLBL_ERR_ADDR_HI, gic_base_hi); |
| 1520 | |
| 1521 | WREG32(mmMME_CMDQ_GLBL_ERR_WDATA, GOYA_ASYNC_EVENT_ID_MME_CMDQ); |
| 1522 | |
| 1523 | WREG32(mmMME_CMDQ_GLBL_ERR_CFG, CMDQ_MME_ERR_MSG_EN); |
| 1524 | |
| 1525 | WREG32(mmMME_CMDQ_GLBL_PROT, CMDQ_MME_ERR_PROT); |
| 1526 | |
| 1527 | WREG32(mmMME_CMDQ_GLBL_CFG0, CMDQ_MME_ENABLE); |
| 1528 | } |
| 1529 | |
Oded Gabbay | b2377e0 | 2019-04-22 11:49:06 +0300 | [diff] [blame] | 1530 | void goya_init_mme_qmans(struct hl_device *hdev) |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 1531 | { |
| 1532 | struct goya_device *goya = hdev->asic_specific; |
| 1533 | u32 so_base_lo, so_base_hi; |
| 1534 | |
| 1535 | if (goya->hw_cap_initialized & HW_CAP_MME) |
| 1536 | return; |
| 1537 | |
| 1538 | so_base_lo = lower_32_bits(CFG_BASE + mmSYNC_MNGR_SOB_OBJ_0); |
| 1539 | so_base_hi = upper_32_bits(CFG_BASE + mmSYNC_MNGR_SOB_OBJ_0); |
| 1540 | |
| 1541 | WREG32(mmMME_SM_BASE_ADDRESS_LOW, so_base_lo); |
| 1542 | WREG32(mmMME_SM_BASE_ADDRESS_HIGH, so_base_hi); |
| 1543 | |
| 1544 | goya_init_mme_qman(hdev); |
| 1545 | goya_init_mme_cmdq(hdev); |
| 1546 | |
| 1547 | goya->hw_cap_initialized |= HW_CAP_MME; |
| 1548 | } |
| 1549 | |
| 1550 | static void goya_init_tpc_qman(struct hl_device *hdev, u32 base_off, int tpc_id) |
| 1551 | { |
| 1552 | u32 mtr_base_lo, mtr_base_hi; |
| 1553 | u32 so_base_lo, so_base_hi; |
| 1554 | u32 gic_base_lo, gic_base_hi; |
| 1555 | u64 qman_base_addr; |
| 1556 | u32 reg_off = tpc_id * (mmTPC1_QM_PQ_PI - mmTPC0_QM_PQ_PI); |
| 1557 | |
| 1558 | mtr_base_lo = lower_32_bits(CFG_BASE + mmSYNC_MNGR_MON_PAY_ADDRL_0); |
| 1559 | mtr_base_hi = upper_32_bits(CFG_BASE + mmSYNC_MNGR_MON_PAY_ADDRL_0); |
| 1560 | so_base_lo = lower_32_bits(CFG_BASE + mmSYNC_MNGR_SOB_OBJ_0); |
| 1561 | so_base_hi = upper_32_bits(CFG_BASE + mmSYNC_MNGR_SOB_OBJ_0); |
| 1562 | |
| 1563 | gic_base_lo = |
| 1564 | lower_32_bits(CFG_BASE + mmGIC_DISTRIBUTOR__5_GICD_SETSPI_NSR); |
| 1565 | gic_base_hi = |
| 1566 | upper_32_bits(CFG_BASE + mmGIC_DISTRIBUTOR__5_GICD_SETSPI_NSR); |
| 1567 | |
| 1568 | qman_base_addr = hdev->asic_prop.sram_base_address + base_off; |
| 1569 | |
| 1570 | WREG32(mmTPC0_QM_PQ_BASE_LO + reg_off, lower_32_bits(qman_base_addr)); |
| 1571 | WREG32(mmTPC0_QM_PQ_BASE_HI + reg_off, upper_32_bits(qman_base_addr)); |
| 1572 | WREG32(mmTPC0_QM_PQ_SIZE + reg_off, ilog2(TPC_QMAN_LENGTH)); |
| 1573 | WREG32(mmTPC0_QM_PQ_PI + reg_off, 0); |
| 1574 | WREG32(mmTPC0_QM_PQ_CI + reg_off, 0); |
| 1575 | WREG32(mmTPC0_QM_CP_LDMA_SRC_BASE_LO_OFFSET + reg_off, 0x10C0); |
| 1576 | WREG32(mmTPC0_QM_CP_LDMA_SRC_BASE_HI_OFFSET + reg_off, 0x10C4); |
| 1577 | WREG32(mmTPC0_QM_CP_LDMA_TSIZE_OFFSET + reg_off, 0x10C8); |
| 1578 | WREG32(mmTPC0_QM_CP_LDMA_COMMIT_OFFSET + reg_off, 0x10CC); |
| 1579 | |
| 1580 | WREG32(mmTPC0_QM_CP_MSG_BASE0_ADDR_LO + reg_off, mtr_base_lo); |
| 1581 | WREG32(mmTPC0_QM_CP_MSG_BASE0_ADDR_HI + reg_off, mtr_base_hi); |
| 1582 | WREG32(mmTPC0_QM_CP_MSG_BASE1_ADDR_LO + reg_off, so_base_lo); |
| 1583 | WREG32(mmTPC0_QM_CP_MSG_BASE1_ADDR_HI + reg_off, so_base_hi); |
| 1584 | |
| 1585 | WREG32(mmTPC0_QM_CQ_CFG1 + reg_off, 0x00080008); |
| 1586 | |
| 1587 | WREG32(mmTPC0_QM_GLBL_ERR_ADDR_LO + reg_off, gic_base_lo); |
| 1588 | WREG32(mmTPC0_QM_GLBL_ERR_ADDR_HI + reg_off, gic_base_hi); |
| 1589 | |
| 1590 | WREG32(mmTPC0_QM_GLBL_ERR_WDATA + reg_off, |
| 1591 | GOYA_ASYNC_EVENT_ID_TPC0_QM + tpc_id); |
| 1592 | |
| 1593 | WREG32(mmTPC0_QM_GLBL_ERR_CFG + reg_off, QMAN_TPC_ERR_MSG_EN); |
| 1594 | |
| 1595 | WREG32(mmTPC0_QM_GLBL_PROT + reg_off, QMAN_TPC_ERR_PROT); |
| 1596 | |
| 1597 | WREG32(mmTPC0_QM_GLBL_CFG0 + reg_off, QMAN_TPC_ENABLE); |
| 1598 | } |
| 1599 | |
| 1600 | static void goya_init_tpc_cmdq(struct hl_device *hdev, int tpc_id) |
| 1601 | { |
| 1602 | u32 mtr_base_lo, mtr_base_hi; |
| 1603 | u32 so_base_lo, so_base_hi; |
| 1604 | u32 gic_base_lo, gic_base_hi; |
| 1605 | u32 reg_off = tpc_id * (mmTPC1_CMDQ_CQ_CFG1 - mmTPC0_CMDQ_CQ_CFG1); |
| 1606 | |
| 1607 | mtr_base_lo = lower_32_bits(CFG_BASE + mmSYNC_MNGR_MON_PAY_ADDRL_0); |
| 1608 | mtr_base_hi = upper_32_bits(CFG_BASE + mmSYNC_MNGR_MON_PAY_ADDRL_0); |
| 1609 | so_base_lo = lower_32_bits(CFG_BASE + mmSYNC_MNGR_SOB_OBJ_0); |
| 1610 | so_base_hi = upper_32_bits(CFG_BASE + mmSYNC_MNGR_SOB_OBJ_0); |
| 1611 | |
| 1612 | gic_base_lo = |
| 1613 | lower_32_bits(CFG_BASE + mmGIC_DISTRIBUTOR__5_GICD_SETSPI_NSR); |
| 1614 | gic_base_hi = |
| 1615 | upper_32_bits(CFG_BASE + mmGIC_DISTRIBUTOR__5_GICD_SETSPI_NSR); |
| 1616 | |
| 1617 | WREG32(mmTPC0_CMDQ_CP_MSG_BASE0_ADDR_LO + reg_off, mtr_base_lo); |
| 1618 | WREG32(mmTPC0_CMDQ_CP_MSG_BASE0_ADDR_HI + reg_off, mtr_base_hi); |
| 1619 | WREG32(mmTPC0_CMDQ_CP_MSG_BASE1_ADDR_LO + reg_off, so_base_lo); |
| 1620 | WREG32(mmTPC0_CMDQ_CP_MSG_BASE1_ADDR_HI + reg_off, so_base_hi); |
| 1621 | |
| 1622 | WREG32(mmTPC0_CMDQ_CQ_CFG1 + reg_off, 0x00140014); |
| 1623 | |
| 1624 | WREG32(mmTPC0_CMDQ_GLBL_ERR_ADDR_LO + reg_off, gic_base_lo); |
| 1625 | WREG32(mmTPC0_CMDQ_GLBL_ERR_ADDR_HI + reg_off, gic_base_hi); |
| 1626 | |
| 1627 | WREG32(mmTPC0_CMDQ_GLBL_ERR_WDATA + reg_off, |
| 1628 | GOYA_ASYNC_EVENT_ID_TPC0_CMDQ + tpc_id); |
| 1629 | |
| 1630 | WREG32(mmTPC0_CMDQ_GLBL_ERR_CFG + reg_off, CMDQ_TPC_ERR_MSG_EN); |
| 1631 | |
| 1632 | WREG32(mmTPC0_CMDQ_GLBL_PROT + reg_off, CMDQ_TPC_ERR_PROT); |
| 1633 | |
| 1634 | WREG32(mmTPC0_CMDQ_GLBL_CFG0 + reg_off, CMDQ_TPC_ENABLE); |
| 1635 | } |
| 1636 | |
Oded Gabbay | b2377e0 | 2019-04-22 11:49:06 +0300 | [diff] [blame] | 1637 | void goya_init_tpc_qmans(struct hl_device *hdev) |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 1638 | { |
| 1639 | struct goya_device *goya = hdev->asic_specific; |
| 1640 | u32 so_base_lo, so_base_hi; |
| 1641 | u32 cfg_off = mmTPC1_CFG_SM_BASE_ADDRESS_LOW - |
| 1642 | mmTPC0_CFG_SM_BASE_ADDRESS_LOW; |
| 1643 | int i; |
| 1644 | |
| 1645 | if (goya->hw_cap_initialized & HW_CAP_TPC) |
| 1646 | return; |
| 1647 | |
| 1648 | so_base_lo = lower_32_bits(CFG_BASE + mmSYNC_MNGR_SOB_OBJ_0); |
| 1649 | so_base_hi = upper_32_bits(CFG_BASE + mmSYNC_MNGR_SOB_OBJ_0); |
| 1650 | |
| 1651 | for (i = 0 ; i < TPC_MAX_NUM ; i++) { |
| 1652 | WREG32(mmTPC0_CFG_SM_BASE_ADDRESS_LOW + i * cfg_off, |
| 1653 | so_base_lo); |
| 1654 | WREG32(mmTPC0_CFG_SM_BASE_ADDRESS_HIGH + i * cfg_off, |
| 1655 | so_base_hi); |
| 1656 | } |
| 1657 | |
| 1658 | goya_init_tpc_qman(hdev, TPC0_QMAN_BASE_OFFSET, 0); |
| 1659 | goya_init_tpc_qman(hdev, TPC1_QMAN_BASE_OFFSET, 1); |
| 1660 | goya_init_tpc_qman(hdev, TPC2_QMAN_BASE_OFFSET, 2); |
| 1661 | goya_init_tpc_qman(hdev, TPC3_QMAN_BASE_OFFSET, 3); |
| 1662 | goya_init_tpc_qman(hdev, TPC4_QMAN_BASE_OFFSET, 4); |
| 1663 | goya_init_tpc_qman(hdev, TPC5_QMAN_BASE_OFFSET, 5); |
| 1664 | goya_init_tpc_qman(hdev, TPC6_QMAN_BASE_OFFSET, 6); |
| 1665 | goya_init_tpc_qman(hdev, TPC7_QMAN_BASE_OFFSET, 7); |
| 1666 | |
| 1667 | for (i = 0 ; i < TPC_MAX_NUM ; i++) |
| 1668 | goya_init_tpc_cmdq(hdev, i); |
| 1669 | |
| 1670 | goya->hw_cap_initialized |= HW_CAP_TPC; |
| 1671 | } |
| 1672 | |
| 1673 | /* |
| 1674 | * goya_disable_internal_queues - Disable internal queues |
| 1675 | * |
| 1676 | * @hdev: pointer to hl_device structure |
| 1677 | * |
| 1678 | */ |
| 1679 | static void goya_disable_internal_queues(struct hl_device *hdev) |
| 1680 | { |
| 1681 | WREG32(mmMME_QM_GLBL_CFG0, 0); |
| 1682 | WREG32(mmMME_CMDQ_GLBL_CFG0, 0); |
| 1683 | |
| 1684 | WREG32(mmTPC0_QM_GLBL_CFG0, 0); |
| 1685 | WREG32(mmTPC0_CMDQ_GLBL_CFG0, 0); |
| 1686 | |
| 1687 | WREG32(mmTPC1_QM_GLBL_CFG0, 0); |
| 1688 | WREG32(mmTPC1_CMDQ_GLBL_CFG0, 0); |
| 1689 | |
| 1690 | WREG32(mmTPC2_QM_GLBL_CFG0, 0); |
| 1691 | WREG32(mmTPC2_CMDQ_GLBL_CFG0, 0); |
| 1692 | |
| 1693 | WREG32(mmTPC3_QM_GLBL_CFG0, 0); |
| 1694 | WREG32(mmTPC3_CMDQ_GLBL_CFG0, 0); |
| 1695 | |
| 1696 | WREG32(mmTPC4_QM_GLBL_CFG0, 0); |
| 1697 | WREG32(mmTPC4_CMDQ_GLBL_CFG0, 0); |
| 1698 | |
| 1699 | WREG32(mmTPC5_QM_GLBL_CFG0, 0); |
| 1700 | WREG32(mmTPC5_CMDQ_GLBL_CFG0, 0); |
| 1701 | |
| 1702 | WREG32(mmTPC6_QM_GLBL_CFG0, 0); |
| 1703 | WREG32(mmTPC6_CMDQ_GLBL_CFG0, 0); |
| 1704 | |
| 1705 | WREG32(mmTPC7_QM_GLBL_CFG0, 0); |
| 1706 | WREG32(mmTPC7_CMDQ_GLBL_CFG0, 0); |
| 1707 | } |
| 1708 | |
| 1709 | /* |
| 1710 | * goya_stop_internal_queues - Stop internal queues |
| 1711 | * |
| 1712 | * @hdev: pointer to hl_device structure |
| 1713 | * |
| 1714 | * Returns 0 on success |
| 1715 | * |
| 1716 | */ |
| 1717 | static int goya_stop_internal_queues(struct hl_device *hdev) |
| 1718 | { |
| 1719 | int rc, retval = 0; |
| 1720 | |
| 1721 | /* |
| 1722 | * Each queue (QMAN) is a separate H/W logic. That means that each |
| 1723 | * QMAN can be stopped independently and failure to stop one does NOT |
| 1724 | * mandate we should not try to stop other QMANs |
| 1725 | */ |
| 1726 | |
| 1727 | rc = goya_stop_queue(hdev, |
| 1728 | mmMME_QM_GLBL_CFG1, |
| 1729 | mmMME_QM_CP_STS, |
| 1730 | mmMME_QM_GLBL_STS0); |
| 1731 | |
| 1732 | if (rc) { |
| 1733 | dev_err(hdev->dev, "failed to stop MME QMAN\n"); |
| 1734 | retval = -EIO; |
| 1735 | } |
| 1736 | |
| 1737 | rc = goya_stop_queue(hdev, |
| 1738 | mmMME_CMDQ_GLBL_CFG1, |
| 1739 | mmMME_CMDQ_CP_STS, |
| 1740 | mmMME_CMDQ_GLBL_STS0); |
| 1741 | |
| 1742 | if (rc) { |
| 1743 | dev_err(hdev->dev, "failed to stop MME CMDQ\n"); |
| 1744 | retval = -EIO; |
| 1745 | } |
| 1746 | |
| 1747 | rc = goya_stop_queue(hdev, |
| 1748 | mmTPC0_QM_GLBL_CFG1, |
| 1749 | mmTPC0_QM_CP_STS, |
| 1750 | mmTPC0_QM_GLBL_STS0); |
| 1751 | |
| 1752 | if (rc) { |
| 1753 | dev_err(hdev->dev, "failed to stop TPC 0 QMAN\n"); |
| 1754 | retval = -EIO; |
| 1755 | } |
| 1756 | |
| 1757 | rc = goya_stop_queue(hdev, |
| 1758 | mmTPC0_CMDQ_GLBL_CFG1, |
| 1759 | mmTPC0_CMDQ_CP_STS, |
| 1760 | mmTPC0_CMDQ_GLBL_STS0); |
| 1761 | |
| 1762 | if (rc) { |
| 1763 | dev_err(hdev->dev, "failed to stop TPC 0 CMDQ\n"); |
| 1764 | retval = -EIO; |
| 1765 | } |
| 1766 | |
| 1767 | rc = goya_stop_queue(hdev, |
| 1768 | mmTPC1_QM_GLBL_CFG1, |
| 1769 | mmTPC1_QM_CP_STS, |
| 1770 | mmTPC1_QM_GLBL_STS0); |
| 1771 | |
| 1772 | if (rc) { |
| 1773 | dev_err(hdev->dev, "failed to stop TPC 1 QMAN\n"); |
| 1774 | retval = -EIO; |
| 1775 | } |
| 1776 | |
| 1777 | rc = goya_stop_queue(hdev, |
| 1778 | mmTPC1_CMDQ_GLBL_CFG1, |
| 1779 | mmTPC1_CMDQ_CP_STS, |
| 1780 | mmTPC1_CMDQ_GLBL_STS0); |
| 1781 | |
| 1782 | if (rc) { |
| 1783 | dev_err(hdev->dev, "failed to stop TPC 1 CMDQ\n"); |
| 1784 | retval = -EIO; |
| 1785 | } |
| 1786 | |
| 1787 | rc = goya_stop_queue(hdev, |
| 1788 | mmTPC2_QM_GLBL_CFG1, |
| 1789 | mmTPC2_QM_CP_STS, |
| 1790 | mmTPC2_QM_GLBL_STS0); |
| 1791 | |
| 1792 | if (rc) { |
| 1793 | dev_err(hdev->dev, "failed to stop TPC 2 QMAN\n"); |
| 1794 | retval = -EIO; |
| 1795 | } |
| 1796 | |
| 1797 | rc = goya_stop_queue(hdev, |
| 1798 | mmTPC2_CMDQ_GLBL_CFG1, |
| 1799 | mmTPC2_CMDQ_CP_STS, |
| 1800 | mmTPC2_CMDQ_GLBL_STS0); |
| 1801 | |
| 1802 | if (rc) { |
| 1803 | dev_err(hdev->dev, "failed to stop TPC 2 CMDQ\n"); |
| 1804 | retval = -EIO; |
| 1805 | } |
| 1806 | |
| 1807 | rc = goya_stop_queue(hdev, |
| 1808 | mmTPC3_QM_GLBL_CFG1, |
| 1809 | mmTPC3_QM_CP_STS, |
| 1810 | mmTPC3_QM_GLBL_STS0); |
| 1811 | |
| 1812 | if (rc) { |
| 1813 | dev_err(hdev->dev, "failed to stop TPC 3 QMAN\n"); |
| 1814 | retval = -EIO; |
| 1815 | } |
| 1816 | |
| 1817 | rc = goya_stop_queue(hdev, |
| 1818 | mmTPC3_CMDQ_GLBL_CFG1, |
| 1819 | mmTPC3_CMDQ_CP_STS, |
| 1820 | mmTPC3_CMDQ_GLBL_STS0); |
| 1821 | |
| 1822 | if (rc) { |
| 1823 | dev_err(hdev->dev, "failed to stop TPC 3 CMDQ\n"); |
| 1824 | retval = -EIO; |
| 1825 | } |
| 1826 | |
| 1827 | rc = goya_stop_queue(hdev, |
| 1828 | mmTPC4_QM_GLBL_CFG1, |
| 1829 | mmTPC4_QM_CP_STS, |
| 1830 | mmTPC4_QM_GLBL_STS0); |
| 1831 | |
| 1832 | if (rc) { |
| 1833 | dev_err(hdev->dev, "failed to stop TPC 4 QMAN\n"); |
| 1834 | retval = -EIO; |
| 1835 | } |
| 1836 | |
| 1837 | rc = goya_stop_queue(hdev, |
| 1838 | mmTPC4_CMDQ_GLBL_CFG1, |
| 1839 | mmTPC4_CMDQ_CP_STS, |
| 1840 | mmTPC4_CMDQ_GLBL_STS0); |
| 1841 | |
| 1842 | if (rc) { |
| 1843 | dev_err(hdev->dev, "failed to stop TPC 4 CMDQ\n"); |
| 1844 | retval = -EIO; |
| 1845 | } |
| 1846 | |
| 1847 | rc = goya_stop_queue(hdev, |
| 1848 | mmTPC5_QM_GLBL_CFG1, |
| 1849 | mmTPC5_QM_CP_STS, |
| 1850 | mmTPC5_QM_GLBL_STS0); |
| 1851 | |
| 1852 | if (rc) { |
| 1853 | dev_err(hdev->dev, "failed to stop TPC 5 QMAN\n"); |
| 1854 | retval = -EIO; |
| 1855 | } |
| 1856 | |
| 1857 | rc = goya_stop_queue(hdev, |
| 1858 | mmTPC5_CMDQ_GLBL_CFG1, |
| 1859 | mmTPC5_CMDQ_CP_STS, |
| 1860 | mmTPC5_CMDQ_GLBL_STS0); |
| 1861 | |
| 1862 | if (rc) { |
| 1863 | dev_err(hdev->dev, "failed to stop TPC 5 CMDQ\n"); |
| 1864 | retval = -EIO; |
| 1865 | } |
| 1866 | |
| 1867 | rc = goya_stop_queue(hdev, |
| 1868 | mmTPC6_QM_GLBL_CFG1, |
| 1869 | mmTPC6_QM_CP_STS, |
| 1870 | mmTPC6_QM_GLBL_STS0); |
| 1871 | |
| 1872 | if (rc) { |
| 1873 | dev_err(hdev->dev, "failed to stop TPC 6 QMAN\n"); |
| 1874 | retval = -EIO; |
| 1875 | } |
| 1876 | |
| 1877 | rc = goya_stop_queue(hdev, |
| 1878 | mmTPC6_CMDQ_GLBL_CFG1, |
| 1879 | mmTPC6_CMDQ_CP_STS, |
| 1880 | mmTPC6_CMDQ_GLBL_STS0); |
| 1881 | |
| 1882 | if (rc) { |
| 1883 | dev_err(hdev->dev, "failed to stop TPC 6 CMDQ\n"); |
| 1884 | retval = -EIO; |
| 1885 | } |
| 1886 | |
| 1887 | rc = goya_stop_queue(hdev, |
| 1888 | mmTPC7_QM_GLBL_CFG1, |
| 1889 | mmTPC7_QM_CP_STS, |
| 1890 | mmTPC7_QM_GLBL_STS0); |
| 1891 | |
| 1892 | if (rc) { |
| 1893 | dev_err(hdev->dev, "failed to stop TPC 7 QMAN\n"); |
| 1894 | retval = -EIO; |
| 1895 | } |
| 1896 | |
| 1897 | rc = goya_stop_queue(hdev, |
| 1898 | mmTPC7_CMDQ_GLBL_CFG1, |
| 1899 | mmTPC7_CMDQ_CP_STS, |
| 1900 | mmTPC7_CMDQ_GLBL_STS0); |
| 1901 | |
| 1902 | if (rc) { |
| 1903 | dev_err(hdev->dev, "failed to stop TPC 7 CMDQ\n"); |
| 1904 | retval = -EIO; |
| 1905 | } |
| 1906 | |
| 1907 | return retval; |
| 1908 | } |
| 1909 | |
Oded Gabbay | 1251f23 | 2019-02-16 00:39:18 +0200 | [diff] [blame] | 1910 | static void goya_dma_stall(struct hl_device *hdev) |
| 1911 | { |
| 1912 | WREG32(mmDMA_QM_0_GLBL_CFG1, 1 << DMA_QM_0_GLBL_CFG1_DMA_STOP_SHIFT); |
| 1913 | WREG32(mmDMA_QM_1_GLBL_CFG1, 1 << DMA_QM_1_GLBL_CFG1_DMA_STOP_SHIFT); |
| 1914 | WREG32(mmDMA_QM_2_GLBL_CFG1, 1 << DMA_QM_2_GLBL_CFG1_DMA_STOP_SHIFT); |
| 1915 | WREG32(mmDMA_QM_3_GLBL_CFG1, 1 << DMA_QM_3_GLBL_CFG1_DMA_STOP_SHIFT); |
| 1916 | WREG32(mmDMA_QM_4_GLBL_CFG1, 1 << DMA_QM_4_GLBL_CFG1_DMA_STOP_SHIFT); |
| 1917 | } |
| 1918 | |
| 1919 | static void goya_tpc_stall(struct hl_device *hdev) |
| 1920 | { |
| 1921 | WREG32(mmTPC0_CFG_TPC_STALL, 1 << TPC0_CFG_TPC_STALL_V_SHIFT); |
| 1922 | WREG32(mmTPC1_CFG_TPC_STALL, 1 << TPC1_CFG_TPC_STALL_V_SHIFT); |
| 1923 | WREG32(mmTPC2_CFG_TPC_STALL, 1 << TPC2_CFG_TPC_STALL_V_SHIFT); |
| 1924 | WREG32(mmTPC3_CFG_TPC_STALL, 1 << TPC3_CFG_TPC_STALL_V_SHIFT); |
| 1925 | WREG32(mmTPC4_CFG_TPC_STALL, 1 << TPC4_CFG_TPC_STALL_V_SHIFT); |
| 1926 | WREG32(mmTPC5_CFG_TPC_STALL, 1 << TPC5_CFG_TPC_STALL_V_SHIFT); |
| 1927 | WREG32(mmTPC6_CFG_TPC_STALL, 1 << TPC6_CFG_TPC_STALL_V_SHIFT); |
| 1928 | WREG32(mmTPC7_CFG_TPC_STALL, 1 << TPC7_CFG_TPC_STALL_V_SHIFT); |
| 1929 | } |
| 1930 | |
| 1931 | static void goya_mme_stall(struct hl_device *hdev) |
| 1932 | { |
| 1933 | WREG32(mmMME_STALL, 0xFFFFFFFF); |
| 1934 | } |
| 1935 | |
| 1936 | static int goya_enable_msix(struct hl_device *hdev) |
| 1937 | { |
| 1938 | struct goya_device *goya = hdev->asic_specific; |
| 1939 | int cq_cnt = hdev->asic_prop.completion_queues_count; |
| 1940 | int rc, i, irq_cnt_init, irq; |
| 1941 | |
| 1942 | if (goya->hw_cap_initialized & HW_CAP_MSIX) |
| 1943 | return 0; |
| 1944 | |
| 1945 | rc = pci_alloc_irq_vectors(hdev->pdev, GOYA_MSIX_ENTRIES, |
| 1946 | GOYA_MSIX_ENTRIES, PCI_IRQ_MSIX); |
| 1947 | if (rc < 0) { |
| 1948 | dev_err(hdev->dev, |
| 1949 | "MSI-X: Failed to enable support -- %d/%d\n", |
| 1950 | GOYA_MSIX_ENTRIES, rc); |
| 1951 | return rc; |
| 1952 | } |
| 1953 | |
| 1954 | for (i = 0, irq_cnt_init = 0 ; i < cq_cnt ; i++, irq_cnt_init++) { |
| 1955 | irq = pci_irq_vector(hdev->pdev, i); |
| 1956 | rc = request_irq(irq, hl_irq_handler_cq, 0, goya_irq_name[i], |
| 1957 | &hdev->completion_queue[i]); |
| 1958 | if (rc) { |
| 1959 | dev_err(hdev->dev, "Failed to request IRQ %d", irq); |
| 1960 | goto free_irqs; |
| 1961 | } |
| 1962 | } |
| 1963 | |
Oded Gabbay | c535bfd | 2019-03-04 15:51:30 +0200 | [diff] [blame] | 1964 | irq = pci_irq_vector(hdev->pdev, GOYA_EVENT_QUEUE_MSIX_IDX); |
Oded Gabbay | 1251f23 | 2019-02-16 00:39:18 +0200 | [diff] [blame] | 1965 | |
| 1966 | rc = request_irq(irq, hl_irq_handler_eq, 0, |
Oded Gabbay | c535bfd | 2019-03-04 15:51:30 +0200 | [diff] [blame] | 1967 | goya_irq_name[GOYA_EVENT_QUEUE_MSIX_IDX], |
Oded Gabbay | 1251f23 | 2019-02-16 00:39:18 +0200 | [diff] [blame] | 1968 | &hdev->event_queue); |
| 1969 | if (rc) { |
| 1970 | dev_err(hdev->dev, "Failed to request IRQ %d", irq); |
| 1971 | goto free_irqs; |
| 1972 | } |
| 1973 | |
| 1974 | goya->hw_cap_initialized |= HW_CAP_MSIX; |
| 1975 | return 0; |
| 1976 | |
| 1977 | free_irqs: |
| 1978 | for (i = 0 ; i < irq_cnt_init ; i++) |
| 1979 | free_irq(pci_irq_vector(hdev->pdev, i), |
| 1980 | &hdev->completion_queue[i]); |
| 1981 | |
| 1982 | pci_free_irq_vectors(hdev->pdev); |
| 1983 | return rc; |
| 1984 | } |
| 1985 | |
| 1986 | static void goya_sync_irqs(struct hl_device *hdev) |
| 1987 | { |
| 1988 | struct goya_device *goya = hdev->asic_specific; |
| 1989 | int i; |
| 1990 | |
| 1991 | if (!(goya->hw_cap_initialized & HW_CAP_MSIX)) |
| 1992 | return; |
| 1993 | |
| 1994 | /* Wait for all pending IRQs to be finished */ |
| 1995 | for (i = 0 ; i < hdev->asic_prop.completion_queues_count ; i++) |
| 1996 | synchronize_irq(pci_irq_vector(hdev->pdev, i)); |
| 1997 | |
Oded Gabbay | c535bfd | 2019-03-04 15:51:30 +0200 | [diff] [blame] | 1998 | synchronize_irq(pci_irq_vector(hdev->pdev, GOYA_EVENT_QUEUE_MSIX_IDX)); |
Oded Gabbay | 1251f23 | 2019-02-16 00:39:18 +0200 | [diff] [blame] | 1999 | } |
| 2000 | |
| 2001 | static void goya_disable_msix(struct hl_device *hdev) |
| 2002 | { |
| 2003 | struct goya_device *goya = hdev->asic_specific; |
| 2004 | int i, irq; |
| 2005 | |
| 2006 | if (!(goya->hw_cap_initialized & HW_CAP_MSIX)) |
| 2007 | return; |
| 2008 | |
| 2009 | goya_sync_irqs(hdev); |
| 2010 | |
Oded Gabbay | c535bfd | 2019-03-04 15:51:30 +0200 | [diff] [blame] | 2011 | irq = pci_irq_vector(hdev->pdev, GOYA_EVENT_QUEUE_MSIX_IDX); |
Oded Gabbay | 1251f23 | 2019-02-16 00:39:18 +0200 | [diff] [blame] | 2012 | free_irq(irq, &hdev->event_queue); |
| 2013 | |
| 2014 | for (i = 0 ; i < hdev->asic_prop.completion_queues_count ; i++) { |
| 2015 | irq = pci_irq_vector(hdev->pdev, i); |
| 2016 | free_irq(irq, &hdev->completion_queue[i]); |
| 2017 | } |
| 2018 | |
| 2019 | pci_free_irq_vectors(hdev->pdev); |
| 2020 | |
| 2021 | goya->hw_cap_initialized &= ~HW_CAP_MSIX; |
| 2022 | } |
| 2023 | |
| 2024 | static void goya_halt_engines(struct hl_device *hdev, bool hard_reset) |
| 2025 | { |
| 2026 | u32 wait_timeout_ms, cpu_timeout_ms; |
| 2027 | |
| 2028 | dev_info(hdev->dev, |
| 2029 | "Halting compute engines and disabling interrupts\n"); |
| 2030 | |
| 2031 | if (hdev->pldm) { |
| 2032 | wait_timeout_ms = GOYA_PLDM_RESET_WAIT_MSEC; |
| 2033 | cpu_timeout_ms = GOYA_PLDM_RESET_WAIT_MSEC; |
| 2034 | } else { |
| 2035 | wait_timeout_ms = GOYA_RESET_WAIT_MSEC; |
| 2036 | cpu_timeout_ms = GOYA_CPU_RESET_WAIT_MSEC; |
| 2037 | } |
| 2038 | |
| 2039 | if (hard_reset) { |
| 2040 | /* |
| 2041 | * I don't know what is the state of the CPU so make sure it is |
| 2042 | * stopped in any means necessary |
| 2043 | */ |
| 2044 | WREG32(mmPSOC_GLOBAL_CONF_UBOOT_MAGIC, KMD_MSG_GOTO_WFE); |
| 2045 | WREG32(mmGIC_DISTRIBUTOR__5_GICD_SETSPI_NSR, |
| 2046 | GOYA_ASYNC_EVENT_ID_HALT_MACHINE); |
| 2047 | msleep(cpu_timeout_ms); |
| 2048 | } |
| 2049 | |
| 2050 | goya_stop_external_queues(hdev); |
| 2051 | goya_stop_internal_queues(hdev); |
| 2052 | |
| 2053 | msleep(wait_timeout_ms); |
| 2054 | |
| 2055 | goya_dma_stall(hdev); |
| 2056 | goya_tpc_stall(hdev); |
| 2057 | goya_mme_stall(hdev); |
| 2058 | |
| 2059 | msleep(wait_timeout_ms); |
| 2060 | |
| 2061 | goya_disable_external_queues(hdev); |
| 2062 | goya_disable_internal_queues(hdev); |
| 2063 | |
| 2064 | if (hard_reset) |
| 2065 | goya_disable_msix(hdev); |
| 2066 | else |
| 2067 | goya_sync_irqs(hdev); |
| 2068 | } |
Oded Gabbay | 839c480 | 2019-02-16 00:39:16 +0200 | [diff] [blame] | 2069 | |
| 2070 | /* |
Tomer Tayar | 3110c60 | 2019-03-04 10:22:09 +0200 | [diff] [blame] | 2071 | * goya_push_uboot_to_device() - Push u-boot FW code to device. |
| 2072 | * @hdev: Pointer to hl_device structure. |
Oded Gabbay | 839c480 | 2019-02-16 00:39:16 +0200 | [diff] [blame] | 2073 | * |
Tomer Tayar | 3110c60 | 2019-03-04 10:22:09 +0200 | [diff] [blame] | 2074 | * Copy u-boot fw code from firmware file to SRAM BAR. |
Oded Gabbay | 839c480 | 2019-02-16 00:39:16 +0200 | [diff] [blame] | 2075 | * |
Tomer Tayar | 3110c60 | 2019-03-04 10:22:09 +0200 | [diff] [blame] | 2076 | * Return: 0 on success, non-zero for failure. |
Oded Gabbay | 839c480 | 2019-02-16 00:39:16 +0200 | [diff] [blame] | 2077 | */ |
Tomer Tayar | 3110c60 | 2019-03-04 10:22:09 +0200 | [diff] [blame] | 2078 | static int goya_push_uboot_to_device(struct hl_device *hdev) |
Oded Gabbay | 839c480 | 2019-02-16 00:39:16 +0200 | [diff] [blame] | 2079 | { |
Tomer Tayar | 3110c60 | 2019-03-04 10:22:09 +0200 | [diff] [blame] | 2080 | char fw_name[200]; |
| 2081 | void __iomem *dst; |
Oded Gabbay | 839c480 | 2019-02-16 00:39:16 +0200 | [diff] [blame] | 2082 | |
Tomer Tayar | 3110c60 | 2019-03-04 10:22:09 +0200 | [diff] [blame] | 2083 | snprintf(fw_name, sizeof(fw_name), "habanalabs/goya/goya-u-boot.bin"); |
| 2084 | dst = hdev->pcie_bar[SRAM_CFG_BAR_ID] + UBOOT_FW_OFFSET; |
Oded Gabbay | 839c480 | 2019-02-16 00:39:16 +0200 | [diff] [blame] | 2085 | |
Tomer Tayar | 3110c60 | 2019-03-04 10:22:09 +0200 | [diff] [blame] | 2086 | return hl_fw_push_fw_to_device(hdev, fw_name, dst); |
| 2087 | } |
Oded Gabbay | 839c480 | 2019-02-16 00:39:16 +0200 | [diff] [blame] | 2088 | |
Tomer Tayar | 3110c60 | 2019-03-04 10:22:09 +0200 | [diff] [blame] | 2089 | /* |
| 2090 | * goya_push_linux_to_device() - Push LINUX FW code to device. |
| 2091 | * @hdev: Pointer to hl_device structure. |
| 2092 | * |
| 2093 | * Copy LINUX fw code from firmware file to HBM BAR. |
| 2094 | * |
| 2095 | * Return: 0 on success, non-zero for failure. |
| 2096 | */ |
| 2097 | static int goya_push_linux_to_device(struct hl_device *hdev) |
| 2098 | { |
| 2099 | char fw_name[200]; |
| 2100 | void __iomem *dst; |
Oded Gabbay | 839c480 | 2019-02-16 00:39:16 +0200 | [diff] [blame] | 2101 | |
Tomer Tayar | 3110c60 | 2019-03-04 10:22:09 +0200 | [diff] [blame] | 2102 | snprintf(fw_name, sizeof(fw_name), "habanalabs/goya/goya-fit.itb"); |
| 2103 | dst = hdev->pcie_bar[DDR_BAR_ID] + LINUX_FW_OFFSET; |
Oded Gabbay | 839c480 | 2019-02-16 00:39:16 +0200 | [diff] [blame] | 2104 | |
Tomer Tayar | 3110c60 | 2019-03-04 10:22:09 +0200 | [diff] [blame] | 2105 | return hl_fw_push_fw_to_device(hdev, fw_name, dst); |
Oded Gabbay | 839c480 | 2019-02-16 00:39:16 +0200 | [diff] [blame] | 2106 | } |
| 2107 | |
| 2108 | static int goya_pldm_init_cpu(struct hl_device *hdev) |
| 2109 | { |
Oded Gabbay | 839c480 | 2019-02-16 00:39:16 +0200 | [diff] [blame] | 2110 | u32 val, unit_rst_val; |
| 2111 | int rc; |
| 2112 | |
| 2113 | /* Must initialize SRAM scrambler before pushing u-boot to SRAM */ |
| 2114 | goya_init_golden_registers(hdev); |
| 2115 | |
| 2116 | /* Put ARM cores into reset */ |
| 2117 | WREG32(mmCPU_CA53_CFG_ARM_RST_CONTROL, CPU_RESET_ASSERT); |
| 2118 | val = RREG32(mmCPU_CA53_CFG_ARM_RST_CONTROL); |
| 2119 | |
| 2120 | /* Reset the CA53 MACRO */ |
| 2121 | unit_rst_val = RREG32(mmPSOC_GLOBAL_CONF_UNIT_RST_N); |
| 2122 | WREG32(mmPSOC_GLOBAL_CONF_UNIT_RST_N, CA53_RESET); |
| 2123 | val = RREG32(mmPSOC_GLOBAL_CONF_UNIT_RST_N); |
| 2124 | WREG32(mmPSOC_GLOBAL_CONF_UNIT_RST_N, unit_rst_val); |
| 2125 | val = RREG32(mmPSOC_GLOBAL_CONF_UNIT_RST_N); |
| 2126 | |
Tomer Tayar | 3110c60 | 2019-03-04 10:22:09 +0200 | [diff] [blame] | 2127 | rc = goya_push_uboot_to_device(hdev); |
Oded Gabbay | 839c480 | 2019-02-16 00:39:16 +0200 | [diff] [blame] | 2128 | if (rc) |
| 2129 | return rc; |
| 2130 | |
Tomer Tayar | 3110c60 | 2019-03-04 10:22:09 +0200 | [diff] [blame] | 2131 | rc = goya_push_linux_to_device(hdev); |
Oded Gabbay | 839c480 | 2019-02-16 00:39:16 +0200 | [diff] [blame] | 2132 | if (rc) |
| 2133 | return rc; |
| 2134 | |
| 2135 | WREG32(mmPSOC_GLOBAL_CONF_UBOOT_MAGIC, KMD_MSG_FIT_RDY); |
| 2136 | WREG32(mmPSOC_GLOBAL_CONF_WARM_REBOOT, CPU_BOOT_STATUS_NA); |
| 2137 | |
| 2138 | WREG32(mmCPU_CA53_CFG_RST_ADDR_LSB_0, |
| 2139 | lower_32_bits(SRAM_BASE_ADDR + UBOOT_FW_OFFSET)); |
| 2140 | WREG32(mmCPU_CA53_CFG_RST_ADDR_MSB_0, |
| 2141 | upper_32_bits(SRAM_BASE_ADDR + UBOOT_FW_OFFSET)); |
| 2142 | |
| 2143 | /* Release ARM core 0 from reset */ |
| 2144 | WREG32(mmCPU_CA53_CFG_ARM_RST_CONTROL, |
| 2145 | CPU_RESET_CORE0_DEASSERT); |
| 2146 | val = RREG32(mmCPU_CA53_CFG_ARM_RST_CONTROL); |
| 2147 | |
| 2148 | return 0; |
| 2149 | } |
| 2150 | |
| 2151 | /* |
| 2152 | * FW component passes an offset from SRAM_BASE_ADDR in SCRATCHPAD_xx. |
| 2153 | * The version string should be located by that offset. |
| 2154 | */ |
| 2155 | static void goya_read_device_fw_version(struct hl_device *hdev, |
| 2156 | enum goya_fw_component fwc) |
| 2157 | { |
| 2158 | const char *name; |
| 2159 | u32 ver_off; |
| 2160 | char *dest; |
| 2161 | |
| 2162 | switch (fwc) { |
| 2163 | case FW_COMP_UBOOT: |
| 2164 | ver_off = RREG32(mmPSOC_GLOBAL_CONF_SCRATCHPAD_29); |
| 2165 | dest = hdev->asic_prop.uboot_ver; |
| 2166 | name = "U-Boot"; |
| 2167 | break; |
| 2168 | case FW_COMP_PREBOOT: |
| 2169 | ver_off = RREG32(mmPSOC_GLOBAL_CONF_SCRATCHPAD_28); |
| 2170 | dest = hdev->asic_prop.preboot_ver; |
| 2171 | name = "Preboot"; |
| 2172 | break; |
| 2173 | default: |
| 2174 | dev_warn(hdev->dev, "Undefined FW component: %d\n", fwc); |
| 2175 | return; |
| 2176 | } |
| 2177 | |
| 2178 | ver_off &= ~((u32)SRAM_BASE_ADDR); |
| 2179 | |
| 2180 | if (ver_off < SRAM_SIZE - VERSION_MAX_LEN) { |
| 2181 | memcpy_fromio(dest, hdev->pcie_bar[SRAM_CFG_BAR_ID] + ver_off, |
| 2182 | VERSION_MAX_LEN); |
| 2183 | } else { |
| 2184 | dev_err(hdev->dev, "%s version offset (0x%x) is above SRAM\n", |
| 2185 | name, ver_off); |
| 2186 | strcpy(dest, "unavailable"); |
| 2187 | } |
| 2188 | } |
| 2189 | |
| 2190 | static int goya_init_cpu(struct hl_device *hdev, u32 cpu_timeout) |
| 2191 | { |
| 2192 | struct goya_device *goya = hdev->asic_specific; |
Oded Gabbay | 839c480 | 2019-02-16 00:39:16 +0200 | [diff] [blame] | 2193 | u32 status; |
| 2194 | int rc; |
| 2195 | |
| 2196 | if (!hdev->cpu_enable) |
| 2197 | return 0; |
| 2198 | |
| 2199 | if (goya->hw_cap_initialized & HW_CAP_CPU) |
| 2200 | return 0; |
| 2201 | |
| 2202 | /* |
| 2203 | * Before pushing u-boot/linux to device, need to set the ddr bar to |
| 2204 | * base address of dram |
| 2205 | */ |
Oded Gabbay | a38693d | 2019-04-28 10:18:35 +0300 | [diff] [blame] | 2206 | if (goya_set_ddr_bar_base(hdev, DRAM_PHYS_BASE) == U64_MAX) { |
Oded Gabbay | 839c480 | 2019-02-16 00:39:16 +0200 | [diff] [blame] | 2207 | dev_err(hdev->dev, |
| 2208 | "failed to map DDR bar to DRAM base address\n"); |
Oded Gabbay | a38693d | 2019-04-28 10:18:35 +0300 | [diff] [blame] | 2209 | return -EIO; |
Oded Gabbay | 839c480 | 2019-02-16 00:39:16 +0200 | [diff] [blame] | 2210 | } |
| 2211 | |
| 2212 | if (hdev->pldm) { |
| 2213 | rc = goya_pldm_init_cpu(hdev); |
| 2214 | if (rc) |
| 2215 | return rc; |
| 2216 | |
| 2217 | goto out; |
| 2218 | } |
| 2219 | |
| 2220 | /* Make sure CPU boot-loader is running */ |
| 2221 | rc = hl_poll_timeout( |
| 2222 | hdev, |
| 2223 | mmPSOC_GLOBAL_CONF_WARM_REBOOT, |
| 2224 | status, |
| 2225 | (status == CPU_BOOT_STATUS_DRAM_RDY) || |
| 2226 | (status == CPU_BOOT_STATUS_SRAM_AVAIL), |
| 2227 | 10000, |
| 2228 | cpu_timeout); |
| 2229 | |
| 2230 | if (rc) { |
| 2231 | dev_err(hdev->dev, "Error in ARM u-boot!"); |
| 2232 | switch (status) { |
| 2233 | case CPU_BOOT_STATUS_NA: |
| 2234 | dev_err(hdev->dev, |
| 2235 | "ARM status %d - BTL did NOT run\n", status); |
| 2236 | break; |
| 2237 | case CPU_BOOT_STATUS_IN_WFE: |
| 2238 | dev_err(hdev->dev, |
| 2239 | "ARM status %d - Inside WFE loop\n", status); |
| 2240 | break; |
| 2241 | case CPU_BOOT_STATUS_IN_BTL: |
| 2242 | dev_err(hdev->dev, |
| 2243 | "ARM status %d - Stuck in BTL\n", status); |
| 2244 | break; |
| 2245 | case CPU_BOOT_STATUS_IN_PREBOOT: |
| 2246 | dev_err(hdev->dev, |
| 2247 | "ARM status %d - Stuck in Preboot\n", status); |
| 2248 | break; |
| 2249 | case CPU_BOOT_STATUS_IN_SPL: |
| 2250 | dev_err(hdev->dev, |
| 2251 | "ARM status %d - Stuck in SPL\n", status); |
| 2252 | break; |
| 2253 | case CPU_BOOT_STATUS_IN_UBOOT: |
| 2254 | dev_err(hdev->dev, |
| 2255 | "ARM status %d - Stuck in u-boot\n", status); |
| 2256 | break; |
| 2257 | case CPU_BOOT_STATUS_DRAM_INIT_FAIL: |
| 2258 | dev_err(hdev->dev, |
| 2259 | "ARM status %d - DDR initialization failed\n", |
| 2260 | status); |
| 2261 | break; |
Igor Grinberg | 0ca3b1b | 2019-02-24 11:20:02 +0200 | [diff] [blame] | 2262 | case CPU_BOOT_STATUS_UBOOT_NOT_READY: |
| 2263 | dev_err(hdev->dev, |
| 2264 | "ARM status %d - u-boot stopped by user\n", |
| 2265 | status); |
| 2266 | break; |
Oded Gabbay | 839c480 | 2019-02-16 00:39:16 +0200 | [diff] [blame] | 2267 | default: |
| 2268 | dev_err(hdev->dev, |
| 2269 | "ARM status %d - Invalid status code\n", |
| 2270 | status); |
| 2271 | break; |
| 2272 | } |
| 2273 | return -EIO; |
| 2274 | } |
| 2275 | |
| 2276 | /* Read U-Boot version now in case we will later fail */ |
| 2277 | goya_read_device_fw_version(hdev, FW_COMP_UBOOT); |
| 2278 | goya_read_device_fw_version(hdev, FW_COMP_PREBOOT); |
| 2279 | |
| 2280 | if (status == CPU_BOOT_STATUS_SRAM_AVAIL) |
| 2281 | goto out; |
| 2282 | |
| 2283 | if (!hdev->fw_loading) { |
| 2284 | dev_info(hdev->dev, "Skip loading FW\n"); |
| 2285 | goto out; |
| 2286 | } |
| 2287 | |
Tomer Tayar | 3110c60 | 2019-03-04 10:22:09 +0200 | [diff] [blame] | 2288 | rc = goya_push_linux_to_device(hdev); |
Oded Gabbay | 839c480 | 2019-02-16 00:39:16 +0200 | [diff] [blame] | 2289 | if (rc) |
| 2290 | return rc; |
| 2291 | |
| 2292 | WREG32(mmPSOC_GLOBAL_CONF_UBOOT_MAGIC, KMD_MSG_FIT_RDY); |
| 2293 | |
| 2294 | rc = hl_poll_timeout( |
| 2295 | hdev, |
| 2296 | mmPSOC_GLOBAL_CONF_WARM_REBOOT, |
| 2297 | status, |
| 2298 | (status == CPU_BOOT_STATUS_SRAM_AVAIL), |
| 2299 | 10000, |
| 2300 | cpu_timeout); |
| 2301 | |
| 2302 | if (rc) { |
| 2303 | if (status == CPU_BOOT_STATUS_FIT_CORRUPTED) |
| 2304 | dev_err(hdev->dev, |
| 2305 | "ARM u-boot reports FIT image is corrupted\n"); |
| 2306 | else |
| 2307 | dev_err(hdev->dev, |
| 2308 | "ARM Linux failed to load, %d\n", status); |
| 2309 | WREG32(mmPSOC_GLOBAL_CONF_UBOOT_MAGIC, KMD_MSG_NA); |
| 2310 | return -EIO; |
| 2311 | } |
| 2312 | |
| 2313 | dev_info(hdev->dev, "Successfully loaded firmware to device\n"); |
| 2314 | |
| 2315 | out: |
| 2316 | goya->hw_cap_initialized |= HW_CAP_CPU; |
| 2317 | |
| 2318 | return 0; |
| 2319 | } |
| 2320 | |
Oded Gabbay | bedd144 | 2019-04-02 15:56:16 +0300 | [diff] [blame] | 2321 | static int goya_mmu_update_asid_hop0_addr(struct hl_device *hdev, u32 asid, |
| 2322 | u64 phys_addr) |
| 2323 | { |
| 2324 | u32 status, timeout_usec; |
| 2325 | int rc; |
| 2326 | |
| 2327 | if (hdev->pldm) |
| 2328 | timeout_usec = GOYA_PLDM_MMU_TIMEOUT_USEC; |
| 2329 | else |
| 2330 | timeout_usec = MMU_CONFIG_TIMEOUT_USEC; |
| 2331 | |
| 2332 | WREG32(MMU_HOP0_PA43_12, phys_addr >> MMU_HOP0_PA43_12_SHIFT); |
| 2333 | WREG32(MMU_HOP0_PA49_44, phys_addr >> MMU_HOP0_PA49_44_SHIFT); |
| 2334 | WREG32(MMU_ASID_BUSY, 0x80000000 | asid); |
| 2335 | |
| 2336 | rc = hl_poll_timeout( |
| 2337 | hdev, |
| 2338 | MMU_ASID_BUSY, |
| 2339 | status, |
| 2340 | !(status & 0x80000000), |
| 2341 | 1000, |
| 2342 | timeout_usec); |
| 2343 | |
| 2344 | if (rc) { |
| 2345 | dev_err(hdev->dev, |
| 2346 | "Timeout during MMU hop0 config of asid %d\n", asid); |
| 2347 | return rc; |
| 2348 | } |
| 2349 | |
| 2350 | return 0; |
| 2351 | } |
| 2352 | |
Oded Gabbay | b2377e0 | 2019-04-22 11:49:06 +0300 | [diff] [blame] | 2353 | int goya_mmu_init(struct hl_device *hdev) |
Omer Shpigelman | 0feaf86 | 2019-02-16 00:39:22 +0200 | [diff] [blame] | 2354 | { |
| 2355 | struct asic_fixed_properties *prop = &hdev->asic_prop; |
| 2356 | struct goya_device *goya = hdev->asic_specific; |
| 2357 | u64 hop0_addr; |
| 2358 | int rc, i; |
| 2359 | |
| 2360 | if (!hdev->mmu_enable) |
| 2361 | return 0; |
| 2362 | |
| 2363 | if (goya->hw_cap_initialized & HW_CAP_MMU) |
| 2364 | return 0; |
| 2365 | |
| 2366 | hdev->dram_supports_virtual_memory = true; |
Omer Shpigelman | 27ca384c | 2019-02-28 10:46:11 +0200 | [diff] [blame] | 2367 | hdev->dram_default_page_mapping = true; |
Omer Shpigelman | 0feaf86 | 2019-02-16 00:39:22 +0200 | [diff] [blame] | 2368 | |
| 2369 | for (i = 0 ; i < prop->max_asid ; i++) { |
| 2370 | hop0_addr = prop->mmu_pgt_addr + |
| 2371 | (i * prop->mmu_hop_table_size); |
| 2372 | |
| 2373 | rc = goya_mmu_update_asid_hop0_addr(hdev, i, hop0_addr); |
| 2374 | if (rc) { |
| 2375 | dev_err(hdev->dev, |
| 2376 | "failed to set hop0 addr for asid %d\n", i); |
| 2377 | goto err; |
| 2378 | } |
| 2379 | } |
| 2380 | |
| 2381 | goya->hw_cap_initialized |= HW_CAP_MMU; |
| 2382 | |
| 2383 | /* init MMU cache manage page */ |
Oded Gabbay | 1e7c1ec | 2019-02-28 10:46:13 +0200 | [diff] [blame] | 2384 | WREG32(mmSTLB_CACHE_INV_BASE_39_8, |
| 2385 | lower_32_bits(MMU_CACHE_MNG_ADDR >> 8)); |
| 2386 | WREG32(mmSTLB_CACHE_INV_BASE_49_40, MMU_CACHE_MNG_ADDR >> 40); |
Omer Shpigelman | 0feaf86 | 2019-02-16 00:39:22 +0200 | [diff] [blame] | 2387 | |
| 2388 | /* Remove follower feature due to performance bug */ |
| 2389 | WREG32_AND(mmSTLB_STLB_FEATURE_EN, |
| 2390 | (~STLB_STLB_FEATURE_EN_FOLLOWER_EN_MASK)); |
| 2391 | |
| 2392 | hdev->asic_funcs->mmu_invalidate_cache(hdev, true); |
| 2393 | |
| 2394 | WREG32(mmMMU_MMU_ENABLE, 1); |
| 2395 | WREG32(mmMMU_SPI_MASK, 0xF); |
| 2396 | |
| 2397 | return 0; |
| 2398 | |
| 2399 | err: |
| 2400 | return rc; |
| 2401 | } |
| 2402 | |
Oded Gabbay | 839c480 | 2019-02-16 00:39:16 +0200 | [diff] [blame] | 2403 | /* |
| 2404 | * goya_hw_init - Goya hardware initialization code |
| 2405 | * |
| 2406 | * @hdev: pointer to hl_device structure |
| 2407 | * |
| 2408 | * Returns 0 on success |
| 2409 | * |
| 2410 | */ |
| 2411 | static int goya_hw_init(struct hl_device *hdev) |
| 2412 | { |
| 2413 | struct asic_fixed_properties *prop = &hdev->asic_prop; |
| 2414 | u32 val; |
| 2415 | int rc; |
| 2416 | |
| 2417 | dev_info(hdev->dev, "Starting initialization of H/W\n"); |
| 2418 | |
| 2419 | /* Perform read from the device to make sure device is up */ |
| 2420 | val = RREG32(mmPCIE_DBI_DEVICE_ID_VENDOR_ID_REG); |
| 2421 | |
Oded Gabbay | f8c8c7d | 2019-02-16 00:39:20 +0200 | [diff] [blame] | 2422 | /* |
| 2423 | * Let's mark in the H/W that we have reached this point. We check |
| 2424 | * this value in the reset_before_init function to understand whether |
| 2425 | * we need to reset the chip before doing H/W init. This register is |
| 2426 | * cleared by the H/W upon H/W reset |
| 2427 | */ |
| 2428 | WREG32(mmPSOC_GLOBAL_CONF_APP_STATUS, HL_DEVICE_HW_STATE_DIRTY); |
| 2429 | |
Oded Gabbay | 839c480 | 2019-02-16 00:39:16 +0200 | [diff] [blame] | 2430 | rc = goya_init_cpu(hdev, GOYA_CPU_TIMEOUT_USEC); |
| 2431 | if (rc) { |
| 2432 | dev_err(hdev->dev, "failed to initialize CPU\n"); |
| 2433 | return rc; |
| 2434 | } |
| 2435 | |
| 2436 | goya_tpc_mbist_workaround(hdev); |
| 2437 | |
| 2438 | goya_init_golden_registers(hdev); |
| 2439 | |
| 2440 | /* |
| 2441 | * After CPU initialization is finished, change DDR bar mapping inside |
| 2442 | * iATU to point to the start address of the MMU page tables |
| 2443 | */ |
Oded Gabbay | a38693d | 2019-04-28 10:18:35 +0300 | [diff] [blame] | 2444 | if (goya_set_ddr_bar_base(hdev, DRAM_PHYS_BASE + |
| 2445 | (MMU_PAGE_TABLES_ADDR & |
| 2446 | ~(prop->dram_pci_bar_size - 0x1ull))) == U64_MAX) { |
Oded Gabbay | 839c480 | 2019-02-16 00:39:16 +0200 | [diff] [blame] | 2447 | dev_err(hdev->dev, |
| 2448 | "failed to map DDR bar to MMU page tables\n"); |
Oded Gabbay | a38693d | 2019-04-28 10:18:35 +0300 | [diff] [blame] | 2449 | return -EIO; |
Oded Gabbay | 839c480 | 2019-02-16 00:39:16 +0200 | [diff] [blame] | 2450 | } |
| 2451 | |
Omer Shpigelman | 0feaf86 | 2019-02-16 00:39:22 +0200 | [diff] [blame] | 2452 | rc = goya_mmu_init(hdev); |
| 2453 | if (rc) |
| 2454 | return rc; |
| 2455 | |
Oded Gabbay | 839c480 | 2019-02-16 00:39:16 +0200 | [diff] [blame] | 2456 | goya_init_security(hdev); |
| 2457 | |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 2458 | goya_init_dma_qmans(hdev); |
| 2459 | |
| 2460 | goya_init_mme_qmans(hdev); |
| 2461 | |
| 2462 | goya_init_tpc_qmans(hdev); |
| 2463 | |
Oded Gabbay | 1251f23 | 2019-02-16 00:39:18 +0200 | [diff] [blame] | 2464 | /* MSI-X must be enabled before CPU queues are initialized */ |
| 2465 | rc = goya_enable_msix(hdev); |
| 2466 | if (rc) |
| 2467 | goto disable_queues; |
| 2468 | |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 2469 | rc = goya_init_cpu_queues(hdev); |
| 2470 | if (rc) { |
| 2471 | dev_err(hdev->dev, "failed to initialize CPU H/W queues %d\n", |
| 2472 | rc); |
Oded Gabbay | 1251f23 | 2019-02-16 00:39:18 +0200 | [diff] [blame] | 2473 | goto disable_msix; |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 2474 | } |
| 2475 | |
Oded Gabbay | d997387 | 2019-03-07 18:03:23 +0200 | [diff] [blame] | 2476 | /* |
| 2477 | * Check if we managed to set the DMA mask to more then 32 bits. If so, |
| 2478 | * let's try to increase it again because in Goya we set the initial |
| 2479 | * dma mask to less then 39 bits so that the allocation of the memory |
| 2480 | * area for the device's cpu will be under 39 bits |
| 2481 | */ |
| 2482 | if (hdev->dma_mask > 32) { |
| 2483 | rc = hl_pci_set_dma_mask(hdev, 48); |
| 2484 | if (rc) |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 2485 | goto disable_pci_access; |
Oded Gabbay | 839c480 | 2019-02-16 00:39:16 +0200 | [diff] [blame] | 2486 | } |
| 2487 | |
| 2488 | /* Perform read from the device to flush all MSI-X configuration */ |
| 2489 | val = RREG32(mmPCIE_DBI_DEVICE_ID_VENDOR_ID_REG); |
| 2490 | |
| 2491 | return 0; |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 2492 | |
| 2493 | disable_pci_access: |
Tomer Tayar | 3110c60 | 2019-03-04 10:22:09 +0200 | [diff] [blame] | 2494 | hl_fw_send_pci_access_msg(hdev, ARMCP_PACKET_DISABLE_PCI_ACCESS); |
Oded Gabbay | 1251f23 | 2019-02-16 00:39:18 +0200 | [diff] [blame] | 2495 | disable_msix: |
| 2496 | goya_disable_msix(hdev); |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 2497 | disable_queues: |
| 2498 | goya_disable_internal_queues(hdev); |
| 2499 | goya_disable_external_queues(hdev); |
| 2500 | |
| 2501 | return rc; |
Oded Gabbay | 839c480 | 2019-02-16 00:39:16 +0200 | [diff] [blame] | 2502 | } |
| 2503 | |
| 2504 | /* |
| 2505 | * goya_hw_fini - Goya hardware tear-down code |
| 2506 | * |
| 2507 | * @hdev: pointer to hl_device structure |
| 2508 | * @hard_reset: should we do hard reset to all engines or just reset the |
| 2509 | * compute/dma engines |
| 2510 | */ |
| 2511 | static void goya_hw_fini(struct hl_device *hdev, bool hard_reset) |
| 2512 | { |
| 2513 | struct goya_device *goya = hdev->asic_specific; |
| 2514 | u32 reset_timeout_ms, status; |
| 2515 | |
| 2516 | if (hdev->pldm) |
| 2517 | reset_timeout_ms = GOYA_PLDM_RESET_TIMEOUT_MSEC; |
| 2518 | else |
| 2519 | reset_timeout_ms = GOYA_RESET_TIMEOUT_MSEC; |
| 2520 | |
| 2521 | if (hard_reset) { |
| 2522 | goya_set_ddr_bar_base(hdev, DRAM_PHYS_BASE); |
| 2523 | goya_disable_clk_rlx(hdev); |
| 2524 | goya_set_pll_refclk(hdev); |
| 2525 | |
| 2526 | WREG32(mmPSOC_GLOBAL_CONF_SW_ALL_RST_CFG, RESET_ALL); |
| 2527 | dev_info(hdev->dev, |
| 2528 | "Issued HARD reset command, going to wait %dms\n", |
| 2529 | reset_timeout_ms); |
| 2530 | } else { |
| 2531 | WREG32(mmPSOC_GLOBAL_CONF_SW_ALL_RST_CFG, DMA_MME_TPC_RESET); |
| 2532 | dev_info(hdev->dev, |
| 2533 | "Issued SOFT reset command, going to wait %dms\n", |
| 2534 | reset_timeout_ms); |
| 2535 | } |
| 2536 | |
| 2537 | /* |
| 2538 | * After hard reset, we can't poll the BTM_FSM register because the PSOC |
| 2539 | * itself is in reset. In either reset we need to wait until the reset |
| 2540 | * is deasserted |
| 2541 | */ |
| 2542 | msleep(reset_timeout_ms); |
| 2543 | |
| 2544 | status = RREG32(mmPSOC_GLOBAL_CONF_BTM_FSM); |
| 2545 | if (status & PSOC_GLOBAL_CONF_BTM_FSM_STATE_MASK) |
| 2546 | dev_err(hdev->dev, |
| 2547 | "Timeout while waiting for device to reset 0x%x\n", |
| 2548 | status); |
| 2549 | |
Oded Gabbay | f8c8c7d | 2019-02-16 00:39:20 +0200 | [diff] [blame] | 2550 | if (!hard_reset) { |
| 2551 | goya->hw_cap_initialized &= ~(HW_CAP_DMA | HW_CAP_MME | |
| 2552 | HW_CAP_GOLDEN | HW_CAP_TPC); |
| 2553 | WREG32(mmGIC_DISTRIBUTOR__5_GICD_SETSPI_NSR, |
| 2554 | GOYA_ASYNC_EVENT_ID_SOFT_RESET); |
| 2555 | return; |
| 2556 | } |
| 2557 | |
Oded Gabbay | 839c480 | 2019-02-16 00:39:16 +0200 | [diff] [blame] | 2558 | /* Chicken bit to re-initiate boot sequencer flow */ |
| 2559 | WREG32(mmPSOC_GLOBAL_CONF_BOOT_SEQ_RE_START, |
| 2560 | 1 << PSOC_GLOBAL_CONF_BOOT_SEQ_RE_START_IND_SHIFT); |
| 2561 | /* Move boot manager FSM to pre boot sequencer init state */ |
| 2562 | WREG32(mmPSOC_GLOBAL_CONF_SW_BTM_FSM, |
| 2563 | 0xA << PSOC_GLOBAL_CONF_SW_BTM_FSM_CTRL_SHIFT); |
| 2564 | |
| 2565 | goya->hw_cap_initialized &= ~(HW_CAP_CPU | HW_CAP_CPU_Q | |
| 2566 | HW_CAP_DDR_0 | HW_CAP_DDR_1 | |
| 2567 | HW_CAP_DMA | HW_CAP_MME | |
| 2568 | HW_CAP_MMU | HW_CAP_TPC_MBIST | |
| 2569 | HW_CAP_GOLDEN | HW_CAP_TPC); |
Oded Gabbay | 1251f23 | 2019-02-16 00:39:18 +0200 | [diff] [blame] | 2570 | memset(goya->events_stat, 0, sizeof(goya->events_stat)); |
Oded Gabbay | 839c480 | 2019-02-16 00:39:16 +0200 | [diff] [blame] | 2571 | |
| 2572 | if (!hdev->pldm) { |
| 2573 | int rc; |
| 2574 | /* In case we are running inside VM and the VM is |
| 2575 | * shutting down, we need to make sure CPU boot-loader |
| 2576 | * is running before we can continue the VM shutdown. |
| 2577 | * That is because the VM will send an FLR signal that |
| 2578 | * we must answer |
| 2579 | */ |
| 2580 | dev_info(hdev->dev, |
| 2581 | "Going to wait up to %ds for CPU boot loader\n", |
| 2582 | GOYA_CPU_TIMEOUT_USEC / 1000 / 1000); |
| 2583 | |
| 2584 | rc = hl_poll_timeout( |
| 2585 | hdev, |
| 2586 | mmPSOC_GLOBAL_CONF_WARM_REBOOT, |
| 2587 | status, |
| 2588 | (status == CPU_BOOT_STATUS_DRAM_RDY), |
| 2589 | 10000, |
| 2590 | GOYA_CPU_TIMEOUT_USEC); |
| 2591 | if (rc) |
| 2592 | dev_err(hdev->dev, |
| 2593 | "failed to wait for CPU boot loader\n"); |
| 2594 | } |
| 2595 | } |
| 2596 | |
Oded Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 2597 | int goya_suspend(struct hl_device *hdev) |
| 2598 | { |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 2599 | int rc; |
| 2600 | |
Tomer Tayar | 3110c60 | 2019-03-04 10:22:09 +0200 | [diff] [blame] | 2601 | rc = hl_fw_send_pci_access_msg(hdev, ARMCP_PACKET_DISABLE_PCI_ACCESS); |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 2602 | if (rc) |
| 2603 | dev_err(hdev->dev, "Failed to disable PCI access from CPU\n"); |
| 2604 | |
| 2605 | return rc; |
Oded Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 2606 | } |
| 2607 | |
| 2608 | int goya_resume(struct hl_device *hdev) |
| 2609 | { |
Oded Gabbay | 7cb5101 | 2019-03-03 22:29:20 +0200 | [diff] [blame] | 2610 | return goya_init_iatu(hdev); |
Oded Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 2611 | } |
| 2612 | |
Oded Gabbay | 5e6e023 | 2019-02-27 12:15:16 +0200 | [diff] [blame] | 2613 | static int goya_cb_mmap(struct hl_device *hdev, struct vm_area_struct *vma, |
Oded Gabbay | be5d926 | 2019-02-16 00:39:15 +0200 | [diff] [blame] | 2614 | u64 kaddress, phys_addr_t paddress, u32 size) |
| 2615 | { |
| 2616 | int rc; |
| 2617 | |
| 2618 | vma->vm_flags |= VM_IO | VM_PFNMAP | VM_DONTEXPAND | VM_DONTDUMP | |
| 2619 | VM_DONTCOPY | VM_NORESERVE; |
| 2620 | |
| 2621 | rc = remap_pfn_range(vma, vma->vm_start, paddress >> PAGE_SHIFT, |
| 2622 | size, vma->vm_page_prot); |
| 2623 | if (rc) |
| 2624 | dev_err(hdev->dev, "remap_pfn_range error %d", rc); |
| 2625 | |
| 2626 | return rc; |
| 2627 | } |
| 2628 | |
Oded Gabbay | b2377e0 | 2019-04-22 11:49:06 +0300 | [diff] [blame] | 2629 | void goya_ring_doorbell(struct hl_device *hdev, u32 hw_queue_id, u32 pi) |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 2630 | { |
| 2631 | u32 db_reg_offset, db_value; |
| 2632 | bool invalid_queue = false; |
| 2633 | |
| 2634 | switch (hw_queue_id) { |
| 2635 | case GOYA_QUEUE_ID_DMA_0: |
| 2636 | db_reg_offset = mmDMA_QM_0_PQ_PI; |
| 2637 | break; |
| 2638 | |
| 2639 | case GOYA_QUEUE_ID_DMA_1: |
| 2640 | db_reg_offset = mmDMA_QM_1_PQ_PI; |
| 2641 | break; |
| 2642 | |
| 2643 | case GOYA_QUEUE_ID_DMA_2: |
| 2644 | db_reg_offset = mmDMA_QM_2_PQ_PI; |
| 2645 | break; |
| 2646 | |
| 2647 | case GOYA_QUEUE_ID_DMA_3: |
| 2648 | db_reg_offset = mmDMA_QM_3_PQ_PI; |
| 2649 | break; |
| 2650 | |
| 2651 | case GOYA_QUEUE_ID_DMA_4: |
| 2652 | db_reg_offset = mmDMA_QM_4_PQ_PI; |
| 2653 | break; |
| 2654 | |
| 2655 | case GOYA_QUEUE_ID_CPU_PQ: |
| 2656 | if (hdev->cpu_queues_enable) |
| 2657 | db_reg_offset = mmCPU_IF_PF_PQ_PI; |
| 2658 | else |
| 2659 | invalid_queue = true; |
| 2660 | break; |
| 2661 | |
| 2662 | case GOYA_QUEUE_ID_MME: |
| 2663 | db_reg_offset = mmMME_QM_PQ_PI; |
| 2664 | break; |
| 2665 | |
| 2666 | case GOYA_QUEUE_ID_TPC0: |
| 2667 | db_reg_offset = mmTPC0_QM_PQ_PI; |
| 2668 | break; |
| 2669 | |
| 2670 | case GOYA_QUEUE_ID_TPC1: |
| 2671 | db_reg_offset = mmTPC1_QM_PQ_PI; |
| 2672 | break; |
| 2673 | |
| 2674 | case GOYA_QUEUE_ID_TPC2: |
| 2675 | db_reg_offset = mmTPC2_QM_PQ_PI; |
| 2676 | break; |
| 2677 | |
| 2678 | case GOYA_QUEUE_ID_TPC3: |
| 2679 | db_reg_offset = mmTPC3_QM_PQ_PI; |
| 2680 | break; |
| 2681 | |
| 2682 | case GOYA_QUEUE_ID_TPC4: |
| 2683 | db_reg_offset = mmTPC4_QM_PQ_PI; |
| 2684 | break; |
| 2685 | |
| 2686 | case GOYA_QUEUE_ID_TPC5: |
| 2687 | db_reg_offset = mmTPC5_QM_PQ_PI; |
| 2688 | break; |
| 2689 | |
| 2690 | case GOYA_QUEUE_ID_TPC6: |
| 2691 | db_reg_offset = mmTPC6_QM_PQ_PI; |
| 2692 | break; |
| 2693 | |
| 2694 | case GOYA_QUEUE_ID_TPC7: |
| 2695 | db_reg_offset = mmTPC7_QM_PQ_PI; |
| 2696 | break; |
| 2697 | |
| 2698 | default: |
| 2699 | invalid_queue = true; |
| 2700 | } |
| 2701 | |
| 2702 | if (invalid_queue) { |
| 2703 | /* Should never get here */ |
| 2704 | dev_err(hdev->dev, "h/w queue %d is invalid. Can't set pi\n", |
| 2705 | hw_queue_id); |
| 2706 | return; |
| 2707 | } |
| 2708 | |
| 2709 | db_value = pi; |
| 2710 | |
| 2711 | /* ring the doorbell */ |
| 2712 | WREG32(db_reg_offset, db_value); |
| 2713 | |
| 2714 | if (hw_queue_id == GOYA_QUEUE_ID_CPU_PQ) |
| 2715 | WREG32(mmGIC_DISTRIBUTOR__5_GICD_SETSPI_NSR, |
| 2716 | GOYA_ASYNC_EVENT_ID_PI_UPDATE); |
| 2717 | } |
| 2718 | |
| 2719 | void goya_flush_pq_write(struct hl_device *hdev, u64 *pq, u64 exp_val) |
| 2720 | { |
| 2721 | /* Not needed in Goya */ |
| 2722 | } |
| 2723 | |
Oded Gabbay | 5e6e023 | 2019-02-27 12:15:16 +0200 | [diff] [blame] | 2724 | static void *goya_dma_alloc_coherent(struct hl_device *hdev, size_t size, |
Oded Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 2725 | dma_addr_t *dma_handle, gfp_t flags) |
| 2726 | { |
Tomer Tayar | 94cb669 | 2019-05-01 11:28:15 +0300 | [diff] [blame] | 2727 | void *kernel_addr = dma_alloc_coherent(&hdev->pdev->dev, size, |
| 2728 | dma_handle, flags); |
| 2729 | |
| 2730 | /* Shift to the device's base physical address of host memory */ |
| 2731 | if (kernel_addr) |
| 2732 | *dma_handle += HOST_PHYS_BASE; |
| 2733 | |
| 2734 | return kernel_addr; |
Oded Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 2735 | } |
| 2736 | |
Oded Gabbay | 5e6e023 | 2019-02-27 12:15:16 +0200 | [diff] [blame] | 2737 | static void goya_dma_free_coherent(struct hl_device *hdev, size_t size, |
| 2738 | void *cpu_addr, dma_addr_t dma_handle) |
Oded Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 2739 | { |
Tomer Tayar | 94cb669 | 2019-05-01 11:28:15 +0300 | [diff] [blame] | 2740 | /* Cancel the device's base physical address of host memory */ |
| 2741 | dma_addr_t fixed_dma_handle = dma_handle - HOST_PHYS_BASE; |
| 2742 | |
| 2743 | dma_free_coherent(&hdev->pdev->dev, size, cpu_addr, fixed_dma_handle); |
Oded Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 2744 | } |
| 2745 | |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 2746 | void *goya_get_int_queue_base(struct hl_device *hdev, u32 queue_id, |
| 2747 | dma_addr_t *dma_handle, u16 *queue_len) |
| 2748 | { |
| 2749 | void *base; |
| 2750 | u32 offset; |
| 2751 | |
| 2752 | *dma_handle = hdev->asic_prop.sram_base_address; |
| 2753 | |
Oded Gabbay | 7c22278 | 2019-03-03 10:23:29 +0200 | [diff] [blame] | 2754 | base = (void *) hdev->pcie_bar[SRAM_CFG_BAR_ID]; |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 2755 | |
| 2756 | switch (queue_id) { |
| 2757 | case GOYA_QUEUE_ID_MME: |
| 2758 | offset = MME_QMAN_BASE_OFFSET; |
| 2759 | *queue_len = MME_QMAN_LENGTH; |
| 2760 | break; |
| 2761 | case GOYA_QUEUE_ID_TPC0: |
| 2762 | offset = TPC0_QMAN_BASE_OFFSET; |
| 2763 | *queue_len = TPC_QMAN_LENGTH; |
| 2764 | break; |
| 2765 | case GOYA_QUEUE_ID_TPC1: |
| 2766 | offset = TPC1_QMAN_BASE_OFFSET; |
| 2767 | *queue_len = TPC_QMAN_LENGTH; |
| 2768 | break; |
| 2769 | case GOYA_QUEUE_ID_TPC2: |
| 2770 | offset = TPC2_QMAN_BASE_OFFSET; |
| 2771 | *queue_len = TPC_QMAN_LENGTH; |
| 2772 | break; |
| 2773 | case GOYA_QUEUE_ID_TPC3: |
| 2774 | offset = TPC3_QMAN_BASE_OFFSET; |
| 2775 | *queue_len = TPC_QMAN_LENGTH; |
| 2776 | break; |
| 2777 | case GOYA_QUEUE_ID_TPC4: |
| 2778 | offset = TPC4_QMAN_BASE_OFFSET; |
| 2779 | *queue_len = TPC_QMAN_LENGTH; |
| 2780 | break; |
| 2781 | case GOYA_QUEUE_ID_TPC5: |
| 2782 | offset = TPC5_QMAN_BASE_OFFSET; |
| 2783 | *queue_len = TPC_QMAN_LENGTH; |
| 2784 | break; |
| 2785 | case GOYA_QUEUE_ID_TPC6: |
| 2786 | offset = TPC6_QMAN_BASE_OFFSET; |
| 2787 | *queue_len = TPC_QMAN_LENGTH; |
| 2788 | break; |
| 2789 | case GOYA_QUEUE_ID_TPC7: |
| 2790 | offset = TPC7_QMAN_BASE_OFFSET; |
| 2791 | *queue_len = TPC_QMAN_LENGTH; |
| 2792 | break; |
| 2793 | default: |
| 2794 | dev_err(hdev->dev, "Got invalid queue id %d\n", queue_id); |
| 2795 | return NULL; |
| 2796 | } |
| 2797 | |
| 2798 | base += offset; |
| 2799 | *dma_handle += offset; |
| 2800 | |
| 2801 | return base; |
| 2802 | } |
| 2803 | |
Oded Gabbay | 5e6e023 | 2019-02-27 12:15:16 +0200 | [diff] [blame] | 2804 | static int goya_send_job_on_qman0(struct hl_device *hdev, struct hl_cs_job *job) |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 2805 | { |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 2806 | struct packet_msg_prot *fence_pkt; |
| 2807 | u32 *fence_ptr; |
| 2808 | dma_addr_t fence_dma_addr; |
| 2809 | struct hl_cb *cb; |
Omer Shpigelman | 3dccd18 | 2019-02-28 10:46:16 +0200 | [diff] [blame] | 2810 | u32 tmp, timeout; |
Tomer Tayar | c811f7b | 2019-03-07 14:26:02 +0200 | [diff] [blame] | 2811 | char buf[16] = {}; |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 2812 | int rc; |
| 2813 | |
Omer Shpigelman | 3dccd18 | 2019-02-28 10:46:16 +0200 | [diff] [blame] | 2814 | if (hdev->pldm) |
| 2815 | timeout = GOYA_PLDM_QMAN0_TIMEOUT_USEC; |
| 2816 | else |
| 2817 | timeout = HL_DEVICE_TIMEOUT_USEC; |
| 2818 | |
Tomer Tayar | c811f7b | 2019-03-07 14:26:02 +0200 | [diff] [blame] | 2819 | if (!hdev->asic_funcs->is_device_idle(hdev, buf, sizeof(buf))) { |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 2820 | dev_err_ratelimited(hdev->dev, |
Tomer Tayar | c811f7b | 2019-03-07 14:26:02 +0200 | [diff] [blame] | 2821 | "Can't send KMD job on QMAN0 because %s is busy\n", |
| 2822 | buf); |
Oded Gabbay | af5f7ee | 2019-02-28 10:46:21 +0200 | [diff] [blame] | 2823 | return -EBUSY; |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 2824 | } |
| 2825 | |
Oded Gabbay | d9c3aa8 | 2019-05-01 11:47:04 +0300 | [diff] [blame] | 2826 | fence_ptr = hdev->asic_funcs->asic_dma_pool_zalloc(hdev, 4, GFP_KERNEL, |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 2827 | &fence_dma_addr); |
| 2828 | if (!fence_ptr) { |
| 2829 | dev_err(hdev->dev, |
| 2830 | "Failed to allocate fence memory for QMAN0\n"); |
| 2831 | return -ENOMEM; |
| 2832 | } |
| 2833 | |
| 2834 | *fence_ptr = 0; |
| 2835 | |
Oded Gabbay | b2377e0 | 2019-04-22 11:49:06 +0300 | [diff] [blame] | 2836 | goya_qman0_set_security(hdev, true); |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 2837 | |
| 2838 | /* |
| 2839 | * goya cs parser saves space for 2xpacket_msg_prot at end of CB. For |
| 2840 | * synchronized kernel jobs we only need space for 1 packet_msg_prot |
| 2841 | */ |
| 2842 | job->job_cb_size -= sizeof(struct packet_msg_prot); |
| 2843 | |
| 2844 | cb = job->patched_cb; |
| 2845 | |
| 2846 | fence_pkt = (struct packet_msg_prot *) (uintptr_t) (cb->kernel_address + |
| 2847 | job->job_cb_size - sizeof(struct packet_msg_prot)); |
| 2848 | |
Tomer Tayar | df697bc | 2019-02-28 10:46:22 +0200 | [diff] [blame] | 2849 | tmp = (PACKET_MSG_PROT << GOYA_PKT_CTL_OPCODE_SHIFT) | |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 2850 | (1 << GOYA_PKT_CTL_EB_SHIFT) | |
| 2851 | (1 << GOYA_PKT_CTL_MB_SHIFT); |
Tomer Tayar | df697bc | 2019-02-28 10:46:22 +0200 | [diff] [blame] | 2852 | fence_pkt->ctl = cpu_to_le32(tmp); |
| 2853 | fence_pkt->value = cpu_to_le32(GOYA_QMAN0_FENCE_VAL); |
Tomer Tayar | 94cb669 | 2019-05-01 11:28:15 +0300 | [diff] [blame] | 2854 | fence_pkt->addr = cpu_to_le64(fence_dma_addr); |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 2855 | |
| 2856 | rc = hl_hw_queue_send_cb_no_cmpl(hdev, GOYA_QUEUE_ID_DMA_0, |
| 2857 | job->job_cb_size, cb->bus_address); |
| 2858 | if (rc) { |
| 2859 | dev_err(hdev->dev, "Failed to send CB on QMAN0, %d\n", rc); |
| 2860 | goto free_fence_ptr; |
| 2861 | } |
| 2862 | |
Omer Shpigelman | 3dccd18 | 2019-02-28 10:46:16 +0200 | [diff] [blame] | 2863 | rc = hl_poll_timeout_memory(hdev, (u64) (uintptr_t) fence_ptr, timeout, |
| 2864 | &tmp); |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 2865 | |
| 2866 | hl_hw_queue_inc_ci_kernel(hdev, GOYA_QUEUE_ID_DMA_0); |
| 2867 | |
| 2868 | if ((rc) || (tmp != GOYA_QMAN0_FENCE_VAL)) { |
| 2869 | dev_err(hdev->dev, "QMAN0 Job hasn't finished in time\n"); |
| 2870 | rc = -ETIMEDOUT; |
| 2871 | } |
| 2872 | |
| 2873 | free_fence_ptr: |
Oded Gabbay | d9c3aa8 | 2019-05-01 11:47:04 +0300 | [diff] [blame] | 2874 | hdev->asic_funcs->asic_dma_pool_free(hdev, (void *) fence_ptr, |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 2875 | fence_dma_addr); |
| 2876 | |
Oded Gabbay | b2377e0 | 2019-04-22 11:49:06 +0300 | [diff] [blame] | 2877 | goya_qman0_set_security(hdev, false); |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 2878 | |
| 2879 | return rc; |
| 2880 | } |
| 2881 | |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 2882 | int goya_send_cpu_message(struct hl_device *hdev, u32 *msg, u16 len, |
| 2883 | u32 timeout, long *result) |
| 2884 | { |
| 2885 | struct goya_device *goya = hdev->asic_specific; |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 2886 | |
| 2887 | if (!(goya->hw_cap_initialized & HW_CAP_CPU_Q)) { |
| 2888 | if (result) |
| 2889 | *result = 0; |
| 2890 | return 0; |
| 2891 | } |
| 2892 | |
Tomer Tayar | 3110c60 | 2019-03-04 10:22:09 +0200 | [diff] [blame] | 2893 | return hl_fw_send_cpu_message(hdev, GOYA_QUEUE_ID_CPU_PQ, msg, len, |
| 2894 | timeout, result); |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 2895 | } |
| 2896 | |
| 2897 | int goya_test_queue(struct hl_device *hdev, u32 hw_queue_id) |
| 2898 | { |
| 2899 | struct packet_msg_prot *fence_pkt; |
| 2900 | dma_addr_t pkt_dma_addr; |
| 2901 | u32 fence_val, tmp; |
| 2902 | dma_addr_t fence_dma_addr; |
| 2903 | u32 *fence_ptr; |
| 2904 | int rc; |
| 2905 | |
| 2906 | fence_val = GOYA_QMAN0_FENCE_VAL; |
| 2907 | |
Oded Gabbay | d9c3aa8 | 2019-05-01 11:47:04 +0300 | [diff] [blame] | 2908 | fence_ptr = hdev->asic_funcs->asic_dma_pool_zalloc(hdev, 4, GFP_KERNEL, |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 2909 | &fence_dma_addr); |
| 2910 | if (!fence_ptr) { |
| 2911 | dev_err(hdev->dev, |
| 2912 | "Failed to allocate memory for queue testing\n"); |
| 2913 | return -ENOMEM; |
| 2914 | } |
| 2915 | |
| 2916 | *fence_ptr = 0; |
| 2917 | |
Oded Gabbay | d9c3aa8 | 2019-05-01 11:47:04 +0300 | [diff] [blame] | 2918 | fence_pkt = hdev->asic_funcs->asic_dma_pool_zalloc(hdev, |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 2919 | sizeof(struct packet_msg_prot), |
| 2920 | GFP_KERNEL, &pkt_dma_addr); |
| 2921 | if (!fence_pkt) { |
| 2922 | dev_err(hdev->dev, |
| 2923 | "Failed to allocate packet for queue testing\n"); |
| 2924 | rc = -ENOMEM; |
| 2925 | goto free_fence_ptr; |
| 2926 | } |
| 2927 | |
Tomer Tayar | df697bc | 2019-02-28 10:46:22 +0200 | [diff] [blame] | 2928 | tmp = (PACKET_MSG_PROT << GOYA_PKT_CTL_OPCODE_SHIFT) | |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 2929 | (1 << GOYA_PKT_CTL_EB_SHIFT) | |
| 2930 | (1 << GOYA_PKT_CTL_MB_SHIFT); |
Tomer Tayar | df697bc | 2019-02-28 10:46:22 +0200 | [diff] [blame] | 2931 | fence_pkt->ctl = cpu_to_le32(tmp); |
| 2932 | fence_pkt->value = cpu_to_le32(fence_val); |
Tomer Tayar | 94cb669 | 2019-05-01 11:28:15 +0300 | [diff] [blame] | 2933 | fence_pkt->addr = cpu_to_le64(fence_dma_addr); |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 2934 | |
| 2935 | rc = hl_hw_queue_send_cb_no_cmpl(hdev, hw_queue_id, |
| 2936 | sizeof(struct packet_msg_prot), |
| 2937 | pkt_dma_addr); |
| 2938 | if (rc) { |
| 2939 | dev_err(hdev->dev, |
| 2940 | "Failed to send fence packet\n"); |
| 2941 | goto free_pkt; |
| 2942 | } |
| 2943 | |
| 2944 | rc = hl_poll_timeout_memory(hdev, (u64) (uintptr_t) fence_ptr, |
| 2945 | GOYA_TEST_QUEUE_WAIT_USEC, &tmp); |
| 2946 | |
| 2947 | hl_hw_queue_inc_ci_kernel(hdev, hw_queue_id); |
| 2948 | |
| 2949 | if ((!rc) && (tmp == fence_val)) { |
| 2950 | dev_info(hdev->dev, |
| 2951 | "queue test on H/W queue %d succeeded\n", |
| 2952 | hw_queue_id); |
| 2953 | } else { |
| 2954 | dev_err(hdev->dev, |
| 2955 | "H/W queue %d test failed (scratch(0x%08llX) == 0x%08X)\n", |
| 2956 | hw_queue_id, (unsigned long long) fence_dma_addr, tmp); |
| 2957 | rc = -EINVAL; |
| 2958 | } |
| 2959 | |
| 2960 | free_pkt: |
Oded Gabbay | d9c3aa8 | 2019-05-01 11:47:04 +0300 | [diff] [blame] | 2961 | hdev->asic_funcs->asic_dma_pool_free(hdev, (void *) fence_pkt, |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 2962 | pkt_dma_addr); |
| 2963 | free_fence_ptr: |
Oded Gabbay | d9c3aa8 | 2019-05-01 11:47:04 +0300 | [diff] [blame] | 2964 | hdev->asic_funcs->asic_dma_pool_free(hdev, (void *) fence_ptr, |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 2965 | fence_dma_addr); |
| 2966 | return rc; |
| 2967 | } |
| 2968 | |
| 2969 | int goya_test_cpu_queue(struct hl_device *hdev) |
| 2970 | { |
Tomer Tayar | 3110c60 | 2019-03-04 10:22:09 +0200 | [diff] [blame] | 2971 | struct goya_device *goya = hdev->asic_specific; |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 2972 | |
Tomer Tayar | 3110c60 | 2019-03-04 10:22:09 +0200 | [diff] [blame] | 2973 | /* |
| 2974 | * check capability here as send_cpu_message() won't update the result |
| 2975 | * value if no capability |
| 2976 | */ |
| 2977 | if (!(goya->hw_cap_initialized & HW_CAP_CPU_Q)) |
| 2978 | return 0; |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 2979 | |
Tomer Tayar | 3110c60 | 2019-03-04 10:22:09 +0200 | [diff] [blame] | 2980 | return hl_fw_test_cpu_queue(hdev); |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 2981 | } |
| 2982 | |
Oded Gabbay | bedd144 | 2019-04-02 15:56:16 +0300 | [diff] [blame] | 2983 | int goya_test_queues(struct hl_device *hdev) |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 2984 | { |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 2985 | int i, rc, ret_val = 0; |
| 2986 | |
| 2987 | for (i = 0 ; i < NUMBER_OF_EXT_HW_QUEUES ; i++) { |
| 2988 | rc = goya_test_queue(hdev, i); |
| 2989 | if (rc) |
| 2990 | ret_val = -EINVAL; |
| 2991 | } |
| 2992 | |
| 2993 | if (hdev->cpu_queues_enable) { |
Tomer Tayar | 393e5b5 | 2019-03-06 14:30:26 +0200 | [diff] [blame] | 2994 | rc = goya_test_cpu_queue(hdev); |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 2995 | if (rc) |
| 2996 | ret_val = -EINVAL; |
| 2997 | } |
| 2998 | |
| 2999 | return ret_val; |
| 3000 | } |
| 3001 | |
Oded Gabbay | 5e6e023 | 2019-02-27 12:15:16 +0200 | [diff] [blame] | 3002 | static void *goya_dma_pool_zalloc(struct hl_device *hdev, size_t size, |
| 3003 | gfp_t mem_flags, dma_addr_t *dma_handle) |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 3004 | { |
Tomer Tayar | 94cb669 | 2019-05-01 11:28:15 +0300 | [diff] [blame] | 3005 | void *kernel_addr; |
| 3006 | |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 3007 | if (size > GOYA_DMA_POOL_BLK_SIZE) |
| 3008 | return NULL; |
| 3009 | |
Tomer Tayar | 94cb669 | 2019-05-01 11:28:15 +0300 | [diff] [blame] | 3010 | kernel_addr = dma_pool_zalloc(hdev->dma_pool, mem_flags, dma_handle); |
| 3011 | |
| 3012 | /* Shift to the device's base physical address of host memory */ |
| 3013 | if (kernel_addr) |
| 3014 | *dma_handle += HOST_PHYS_BASE; |
| 3015 | |
| 3016 | return kernel_addr; |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 3017 | } |
| 3018 | |
Oded Gabbay | 5e6e023 | 2019-02-27 12:15:16 +0200 | [diff] [blame] | 3019 | static void goya_dma_pool_free(struct hl_device *hdev, void *vaddr, |
| 3020 | dma_addr_t dma_addr) |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 3021 | { |
Tomer Tayar | 94cb669 | 2019-05-01 11:28:15 +0300 | [diff] [blame] | 3022 | /* Cancel the device's base physical address of host memory */ |
| 3023 | dma_addr_t fixed_dma_addr = dma_addr - HOST_PHYS_BASE; |
| 3024 | |
| 3025 | dma_pool_free(hdev->dma_pool, vaddr, fixed_dma_addr); |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 3026 | } |
| 3027 | |
Oded Gabbay | bedd144 | 2019-04-02 15:56:16 +0300 | [diff] [blame] | 3028 | void *goya_cpu_accessible_dma_pool_alloc(struct hl_device *hdev, size_t size, |
| 3029 | dma_addr_t *dma_handle) |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 3030 | { |
Tomer Tayar | 3110c60 | 2019-03-04 10:22:09 +0200 | [diff] [blame] | 3031 | return hl_fw_cpu_accessible_dma_pool_alloc(hdev, size, dma_handle); |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 3032 | } |
| 3033 | |
Oded Gabbay | bedd144 | 2019-04-02 15:56:16 +0300 | [diff] [blame] | 3034 | void goya_cpu_accessible_dma_pool_free(struct hl_device *hdev, size_t size, |
| 3035 | void *vaddr) |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 3036 | { |
Tomer Tayar | 3110c60 | 2019-03-04 10:22:09 +0200 | [diff] [blame] | 3037 | hl_fw_cpu_accessible_dma_pool_free(hdev, size, vaddr); |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 3038 | } |
| 3039 | |
Tomer Tayar | 94cb669 | 2019-05-01 11:28:15 +0300 | [diff] [blame] | 3040 | static int goya_dma_map_sg(struct hl_device *hdev, struct scatterlist *sgl, |
Oded Gabbay | 5e6e023 | 2019-02-27 12:15:16 +0200 | [diff] [blame] | 3041 | int nents, enum dma_data_direction dir) |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 3042 | { |
Tomer Tayar | 94cb669 | 2019-05-01 11:28:15 +0300 | [diff] [blame] | 3043 | struct scatterlist *sg; |
| 3044 | int i; |
| 3045 | |
| 3046 | if (!dma_map_sg(&hdev->pdev->dev, sgl, nents, dir)) |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 3047 | return -ENOMEM; |
| 3048 | |
Tomer Tayar | 94cb669 | 2019-05-01 11:28:15 +0300 | [diff] [blame] | 3049 | /* Shift to the device's base physical address of host memory */ |
| 3050 | for_each_sg(sgl, sg, nents, i) |
| 3051 | sg->dma_address += HOST_PHYS_BASE; |
| 3052 | |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 3053 | return 0; |
| 3054 | } |
| 3055 | |
Tomer Tayar | 94cb669 | 2019-05-01 11:28:15 +0300 | [diff] [blame] | 3056 | static void goya_dma_unmap_sg(struct hl_device *hdev, struct scatterlist *sgl, |
Oded Gabbay | 5e6e023 | 2019-02-27 12:15:16 +0200 | [diff] [blame] | 3057 | int nents, enum dma_data_direction dir) |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 3058 | { |
Tomer Tayar | 94cb669 | 2019-05-01 11:28:15 +0300 | [diff] [blame] | 3059 | struct scatterlist *sg; |
| 3060 | int i; |
| 3061 | |
| 3062 | /* Cancel the device's base physical address of host memory */ |
| 3063 | for_each_sg(sgl, sg, nents, i) |
| 3064 | sg->dma_address -= HOST_PHYS_BASE; |
| 3065 | |
| 3066 | dma_unmap_sg(&hdev->pdev->dev, sgl, nents, dir); |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 3067 | } |
| 3068 | |
Oded Gabbay | 5e6e023 | 2019-02-27 12:15:16 +0200 | [diff] [blame] | 3069 | u32 goya_get_dma_desc_list_size(struct hl_device *hdev, struct sg_table *sgt) |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 3070 | { |
| 3071 | struct scatterlist *sg, *sg_next_iter; |
Oded Gabbay | e99f1683 | 2019-02-24 11:55:26 +0200 | [diff] [blame] | 3072 | u32 count, dma_desc_cnt; |
| 3073 | u64 len, len_next; |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 3074 | dma_addr_t addr, addr_next; |
| 3075 | |
| 3076 | dma_desc_cnt = 0; |
| 3077 | |
| 3078 | for_each_sg(sgt->sgl, sg, sgt->nents, count) { |
| 3079 | |
| 3080 | len = sg_dma_len(sg); |
| 3081 | addr = sg_dma_address(sg); |
| 3082 | |
| 3083 | if (len == 0) |
| 3084 | break; |
| 3085 | |
| 3086 | while ((count + 1) < sgt->nents) { |
| 3087 | sg_next_iter = sg_next(sg); |
| 3088 | len_next = sg_dma_len(sg_next_iter); |
| 3089 | addr_next = sg_dma_address(sg_next_iter); |
| 3090 | |
| 3091 | if (len_next == 0) |
| 3092 | break; |
| 3093 | |
| 3094 | if ((addr + len == addr_next) && |
| 3095 | (len + len_next <= DMA_MAX_TRANSFER_SIZE)) { |
| 3096 | len += len_next; |
| 3097 | count++; |
| 3098 | sg = sg_next_iter; |
| 3099 | } else { |
| 3100 | break; |
| 3101 | } |
| 3102 | } |
| 3103 | |
| 3104 | dma_desc_cnt++; |
| 3105 | } |
| 3106 | |
| 3107 | return dma_desc_cnt * sizeof(struct packet_lin_dma); |
| 3108 | } |
| 3109 | |
| 3110 | static int goya_pin_memory_before_cs(struct hl_device *hdev, |
| 3111 | struct hl_cs_parser *parser, |
| 3112 | struct packet_lin_dma *user_dma_pkt, |
| 3113 | u64 addr, enum dma_data_direction dir) |
| 3114 | { |
| 3115 | struct hl_userptr *userptr; |
| 3116 | int rc; |
| 3117 | |
Tomer Tayar | df697bc | 2019-02-28 10:46:22 +0200 | [diff] [blame] | 3118 | if (hl_userptr_is_pinned(hdev, addr, le32_to_cpu(user_dma_pkt->tsize), |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 3119 | parser->job_userptr_list, &userptr)) |
| 3120 | goto already_pinned; |
| 3121 | |
| 3122 | userptr = kzalloc(sizeof(*userptr), GFP_ATOMIC); |
| 3123 | if (!userptr) |
| 3124 | return -ENOMEM; |
| 3125 | |
Tomer Tayar | df697bc | 2019-02-28 10:46:22 +0200 | [diff] [blame] | 3126 | rc = hl_pin_host_memory(hdev, addr, le32_to_cpu(user_dma_pkt->tsize), |
| 3127 | userptr); |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 3128 | if (rc) |
| 3129 | goto free_userptr; |
| 3130 | |
| 3131 | list_add_tail(&userptr->job_node, parser->job_userptr_list); |
| 3132 | |
| 3133 | rc = hdev->asic_funcs->asic_dma_map_sg(hdev, userptr->sgt->sgl, |
| 3134 | userptr->sgt->nents, dir); |
| 3135 | if (rc) { |
| 3136 | dev_err(hdev->dev, "failed to map sgt with DMA region\n"); |
| 3137 | goto unpin_memory; |
| 3138 | } |
| 3139 | |
| 3140 | userptr->dma_mapped = true; |
| 3141 | userptr->dir = dir; |
| 3142 | |
| 3143 | already_pinned: |
| 3144 | parser->patched_cb_size += |
| 3145 | goya_get_dma_desc_list_size(hdev, userptr->sgt); |
| 3146 | |
| 3147 | return 0; |
| 3148 | |
| 3149 | unpin_memory: |
| 3150 | hl_unpin_host_memory(hdev, userptr); |
| 3151 | free_userptr: |
| 3152 | kfree(userptr); |
| 3153 | return rc; |
| 3154 | } |
| 3155 | |
| 3156 | static int goya_validate_dma_pkt_host(struct hl_device *hdev, |
| 3157 | struct hl_cs_parser *parser, |
| 3158 | struct packet_lin_dma *user_dma_pkt) |
| 3159 | { |
| 3160 | u64 device_memory_addr, addr; |
| 3161 | enum dma_data_direction dir; |
| 3162 | enum goya_dma_direction user_dir; |
| 3163 | bool sram_addr = true; |
| 3164 | bool skip_host_mem_pin = false; |
| 3165 | bool user_memset; |
Tomer Tayar | df697bc | 2019-02-28 10:46:22 +0200 | [diff] [blame] | 3166 | u32 ctl; |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 3167 | int rc = 0; |
| 3168 | |
Tomer Tayar | df697bc | 2019-02-28 10:46:22 +0200 | [diff] [blame] | 3169 | ctl = le32_to_cpu(user_dma_pkt->ctl); |
| 3170 | |
| 3171 | user_dir = (ctl & GOYA_PKT_LIN_DMA_CTL_DMA_DIR_MASK) >> |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 3172 | GOYA_PKT_LIN_DMA_CTL_DMA_DIR_SHIFT; |
| 3173 | |
Tomer Tayar | df697bc | 2019-02-28 10:46:22 +0200 | [diff] [blame] | 3174 | user_memset = (ctl & GOYA_PKT_LIN_DMA_CTL_MEMSET_MASK) >> |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 3175 | GOYA_PKT_LIN_DMA_CTL_MEMSET_SHIFT; |
| 3176 | |
| 3177 | switch (user_dir) { |
| 3178 | case DMA_HOST_TO_DRAM: |
| 3179 | dev_dbg(hdev->dev, "DMA direction is HOST --> DRAM\n"); |
| 3180 | dir = DMA_TO_DEVICE; |
| 3181 | sram_addr = false; |
Tomer Tayar | df697bc | 2019-02-28 10:46:22 +0200 | [diff] [blame] | 3182 | addr = le64_to_cpu(user_dma_pkt->src_addr); |
| 3183 | device_memory_addr = le64_to_cpu(user_dma_pkt->dst_addr); |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 3184 | if (user_memset) |
| 3185 | skip_host_mem_pin = true; |
| 3186 | break; |
| 3187 | |
| 3188 | case DMA_DRAM_TO_HOST: |
| 3189 | dev_dbg(hdev->dev, "DMA direction is DRAM --> HOST\n"); |
| 3190 | dir = DMA_FROM_DEVICE; |
| 3191 | sram_addr = false; |
Tomer Tayar | df697bc | 2019-02-28 10:46:22 +0200 | [diff] [blame] | 3192 | addr = le64_to_cpu(user_dma_pkt->dst_addr); |
| 3193 | device_memory_addr = le64_to_cpu(user_dma_pkt->src_addr); |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 3194 | break; |
| 3195 | |
| 3196 | case DMA_HOST_TO_SRAM: |
| 3197 | dev_dbg(hdev->dev, "DMA direction is HOST --> SRAM\n"); |
| 3198 | dir = DMA_TO_DEVICE; |
Tomer Tayar | df697bc | 2019-02-28 10:46:22 +0200 | [diff] [blame] | 3199 | addr = le64_to_cpu(user_dma_pkt->src_addr); |
| 3200 | device_memory_addr = le64_to_cpu(user_dma_pkt->dst_addr); |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 3201 | if (user_memset) |
| 3202 | skip_host_mem_pin = true; |
| 3203 | break; |
| 3204 | |
| 3205 | case DMA_SRAM_TO_HOST: |
| 3206 | dev_dbg(hdev->dev, "DMA direction is SRAM --> HOST\n"); |
| 3207 | dir = DMA_FROM_DEVICE; |
Tomer Tayar | df697bc | 2019-02-28 10:46:22 +0200 | [diff] [blame] | 3208 | addr = le64_to_cpu(user_dma_pkt->dst_addr); |
| 3209 | device_memory_addr = le64_to_cpu(user_dma_pkt->src_addr); |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 3210 | break; |
| 3211 | default: |
| 3212 | dev_err(hdev->dev, "DMA direction is undefined\n"); |
| 3213 | return -EFAULT; |
| 3214 | } |
| 3215 | |
Dalit Ben Zoor | f0539fb | 2019-05-01 13:24:58 +0300 | [diff] [blame] | 3216 | if (sram_addr) { |
| 3217 | if (!hl_mem_area_inside_range(device_memory_addr, |
| 3218 | le32_to_cpu(user_dma_pkt->tsize), |
| 3219 | hdev->asic_prop.sram_user_base_address, |
| 3220 | hdev->asic_prop.sram_end_address)) { |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 3221 | |
Dalit Ben Zoor | f0539fb | 2019-05-01 13:24:58 +0300 | [diff] [blame] | 3222 | dev_err(hdev->dev, |
| 3223 | "SRAM address 0x%llx + 0x%x is invalid\n", |
| 3224 | device_memory_addr, |
| 3225 | user_dma_pkt->tsize); |
| 3226 | return -EFAULT; |
| 3227 | } |
| 3228 | } else { |
| 3229 | if (!hl_mem_area_inside_range(device_memory_addr, |
| 3230 | le32_to_cpu(user_dma_pkt->tsize), |
| 3231 | hdev->asic_prop.dram_user_base_address, |
| 3232 | hdev->asic_prop.dram_end_address)) { |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 3233 | |
Dalit Ben Zoor | f0539fb | 2019-05-01 13:24:58 +0300 | [diff] [blame] | 3234 | dev_err(hdev->dev, |
| 3235 | "DRAM address 0x%llx + 0x%x is invalid\n", |
| 3236 | device_memory_addr, |
| 3237 | user_dma_pkt->tsize); |
| 3238 | return -EFAULT; |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 3239 | } |
| 3240 | } |
| 3241 | |
| 3242 | if (skip_host_mem_pin) |
| 3243 | parser->patched_cb_size += sizeof(*user_dma_pkt); |
| 3244 | else { |
| 3245 | if ((dir == DMA_TO_DEVICE) && |
| 3246 | (parser->hw_queue_id > GOYA_QUEUE_ID_DMA_1)) { |
| 3247 | dev_err(hdev->dev, |
| 3248 | "Can't DMA from host on queue other then 1\n"); |
| 3249 | return -EFAULT; |
| 3250 | } |
| 3251 | |
| 3252 | rc = goya_pin_memory_before_cs(hdev, parser, user_dma_pkt, |
| 3253 | addr, dir); |
| 3254 | } |
| 3255 | |
| 3256 | return rc; |
| 3257 | } |
| 3258 | |
| 3259 | static int goya_validate_dma_pkt_no_host(struct hl_device *hdev, |
| 3260 | struct hl_cs_parser *parser, |
| 3261 | struct packet_lin_dma *user_dma_pkt) |
| 3262 | { |
| 3263 | u64 sram_memory_addr, dram_memory_addr; |
| 3264 | enum goya_dma_direction user_dir; |
Tomer Tayar | df697bc | 2019-02-28 10:46:22 +0200 | [diff] [blame] | 3265 | u32 ctl; |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 3266 | |
Tomer Tayar | df697bc | 2019-02-28 10:46:22 +0200 | [diff] [blame] | 3267 | ctl = le32_to_cpu(user_dma_pkt->ctl); |
| 3268 | user_dir = (ctl & GOYA_PKT_LIN_DMA_CTL_DMA_DIR_MASK) >> |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 3269 | GOYA_PKT_LIN_DMA_CTL_DMA_DIR_SHIFT; |
| 3270 | |
| 3271 | if (user_dir == DMA_DRAM_TO_SRAM) { |
| 3272 | dev_dbg(hdev->dev, "DMA direction is DRAM --> SRAM\n"); |
Tomer Tayar | df697bc | 2019-02-28 10:46:22 +0200 | [diff] [blame] | 3273 | dram_memory_addr = le64_to_cpu(user_dma_pkt->src_addr); |
| 3274 | sram_memory_addr = le64_to_cpu(user_dma_pkt->dst_addr); |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 3275 | } else { |
| 3276 | dev_dbg(hdev->dev, "DMA direction is SRAM --> DRAM\n"); |
Tomer Tayar | df697bc | 2019-02-28 10:46:22 +0200 | [diff] [blame] | 3277 | sram_memory_addr = le64_to_cpu(user_dma_pkt->src_addr); |
| 3278 | dram_memory_addr = le64_to_cpu(user_dma_pkt->dst_addr); |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 3279 | } |
| 3280 | |
Tomer Tayar | df697bc | 2019-02-28 10:46:22 +0200 | [diff] [blame] | 3281 | if (!hl_mem_area_inside_range(sram_memory_addr, |
| 3282 | le32_to_cpu(user_dma_pkt->tsize), |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 3283 | hdev->asic_prop.sram_user_base_address, |
| 3284 | hdev->asic_prop.sram_end_address)) { |
| 3285 | dev_err(hdev->dev, "SRAM address 0x%llx + 0x%x is invalid\n", |
| 3286 | sram_memory_addr, user_dma_pkt->tsize); |
| 3287 | return -EFAULT; |
| 3288 | } |
| 3289 | |
Tomer Tayar | df697bc | 2019-02-28 10:46:22 +0200 | [diff] [blame] | 3290 | if (!hl_mem_area_inside_range(dram_memory_addr, |
| 3291 | le32_to_cpu(user_dma_pkt->tsize), |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 3292 | hdev->asic_prop.dram_user_base_address, |
| 3293 | hdev->asic_prop.dram_end_address)) { |
| 3294 | dev_err(hdev->dev, "DRAM address 0x%llx + 0x%x is invalid\n", |
| 3295 | dram_memory_addr, user_dma_pkt->tsize); |
| 3296 | return -EFAULT; |
| 3297 | } |
| 3298 | |
| 3299 | parser->patched_cb_size += sizeof(*user_dma_pkt); |
| 3300 | |
| 3301 | return 0; |
| 3302 | } |
| 3303 | |
| 3304 | static int goya_validate_dma_pkt_no_mmu(struct hl_device *hdev, |
| 3305 | struct hl_cs_parser *parser, |
| 3306 | struct packet_lin_dma *user_dma_pkt) |
| 3307 | { |
| 3308 | enum goya_dma_direction user_dir; |
Tomer Tayar | df697bc | 2019-02-28 10:46:22 +0200 | [diff] [blame] | 3309 | u32 ctl; |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 3310 | int rc; |
| 3311 | |
| 3312 | dev_dbg(hdev->dev, "DMA packet details:\n"); |
| 3313 | dev_dbg(hdev->dev, "source == 0x%llx\n", user_dma_pkt->src_addr); |
| 3314 | dev_dbg(hdev->dev, "destination == 0x%llx\n", user_dma_pkt->dst_addr); |
| 3315 | dev_dbg(hdev->dev, "size == %u\n", user_dma_pkt->tsize); |
| 3316 | |
Tomer Tayar | df697bc | 2019-02-28 10:46:22 +0200 | [diff] [blame] | 3317 | ctl = le32_to_cpu(user_dma_pkt->ctl); |
| 3318 | user_dir = (ctl & GOYA_PKT_LIN_DMA_CTL_DMA_DIR_MASK) >> |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 3319 | GOYA_PKT_LIN_DMA_CTL_DMA_DIR_SHIFT; |
| 3320 | |
| 3321 | /* |
| 3322 | * Special handling for DMA with size 0. The H/W has a bug where |
| 3323 | * this can cause the QMAN DMA to get stuck, so block it here. |
| 3324 | */ |
| 3325 | if (user_dma_pkt->tsize == 0) { |
| 3326 | dev_err(hdev->dev, |
| 3327 | "Got DMA with size 0, might reset the device\n"); |
| 3328 | return -EINVAL; |
| 3329 | } |
| 3330 | |
| 3331 | if ((user_dir == DMA_DRAM_TO_SRAM) || (user_dir == DMA_SRAM_TO_DRAM)) |
| 3332 | rc = goya_validate_dma_pkt_no_host(hdev, parser, user_dma_pkt); |
| 3333 | else |
| 3334 | rc = goya_validate_dma_pkt_host(hdev, parser, user_dma_pkt); |
| 3335 | |
| 3336 | return rc; |
| 3337 | } |
| 3338 | |
| 3339 | static int goya_validate_dma_pkt_mmu(struct hl_device *hdev, |
| 3340 | struct hl_cs_parser *parser, |
| 3341 | struct packet_lin_dma *user_dma_pkt) |
| 3342 | { |
| 3343 | dev_dbg(hdev->dev, "DMA packet details:\n"); |
| 3344 | dev_dbg(hdev->dev, "source == 0x%llx\n", user_dma_pkt->src_addr); |
| 3345 | dev_dbg(hdev->dev, "destination == 0x%llx\n", user_dma_pkt->dst_addr); |
| 3346 | dev_dbg(hdev->dev, "size == %u\n", user_dma_pkt->tsize); |
| 3347 | |
| 3348 | /* |
| 3349 | * WA for HW-23. |
| 3350 | * We can't allow user to read from Host using QMANs other than 1. |
| 3351 | */ |
Oded Gabbay | bfb57a9 | 2019-03-24 18:07:02 +0200 | [diff] [blame] | 3352 | if (parser->hw_queue_id != GOYA_QUEUE_ID_DMA_1 && |
Tomer Tayar | df697bc | 2019-02-28 10:46:22 +0200 | [diff] [blame] | 3353 | hl_mem_area_inside_range(le64_to_cpu(user_dma_pkt->src_addr), |
| 3354 | le32_to_cpu(user_dma_pkt->tsize), |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 3355 | hdev->asic_prop.va_space_host_start_address, |
| 3356 | hdev->asic_prop.va_space_host_end_address)) { |
| 3357 | dev_err(hdev->dev, |
| 3358 | "Can't DMA from host on queue other then 1\n"); |
| 3359 | return -EFAULT; |
| 3360 | } |
| 3361 | |
| 3362 | if (user_dma_pkt->tsize == 0) { |
| 3363 | dev_err(hdev->dev, |
| 3364 | "Got DMA with size 0, might reset the device\n"); |
| 3365 | return -EINVAL; |
| 3366 | } |
| 3367 | |
| 3368 | parser->patched_cb_size += sizeof(*user_dma_pkt); |
| 3369 | |
| 3370 | return 0; |
| 3371 | } |
| 3372 | |
| 3373 | static int goya_validate_wreg32(struct hl_device *hdev, |
| 3374 | struct hl_cs_parser *parser, |
| 3375 | struct packet_wreg32 *wreg_pkt) |
| 3376 | { |
| 3377 | struct goya_device *goya = hdev->asic_specific; |
| 3378 | u32 sob_start_addr, sob_end_addr; |
| 3379 | u16 reg_offset; |
| 3380 | |
Tomer Tayar | df697bc | 2019-02-28 10:46:22 +0200 | [diff] [blame] | 3381 | reg_offset = le32_to_cpu(wreg_pkt->ctl) & |
| 3382 | GOYA_PKT_WREG32_CTL_REG_OFFSET_MASK; |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 3383 | |
| 3384 | dev_dbg(hdev->dev, "WREG32 packet details:\n"); |
| 3385 | dev_dbg(hdev->dev, "reg_offset == 0x%x\n", reg_offset); |
| 3386 | dev_dbg(hdev->dev, "value == 0x%x\n", wreg_pkt->value); |
| 3387 | |
Oded Gabbay | 6765fda | 2019-02-28 10:46:14 +0200 | [diff] [blame] | 3388 | if (reg_offset != (mmDMA_CH_0_WR_COMP_ADDR_LO & 0x1FFF)) { |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 3389 | dev_err(hdev->dev, "WREG32 packet with illegal address 0x%x\n", |
| 3390 | reg_offset); |
| 3391 | return -EPERM; |
| 3392 | } |
| 3393 | |
| 3394 | /* |
| 3395 | * With MMU, DMA channels are not secured, so it doesn't matter where |
| 3396 | * the WR COMP will be written to because it will go out with |
| 3397 | * non-secured property |
| 3398 | */ |
| 3399 | if (goya->hw_cap_initialized & HW_CAP_MMU) |
| 3400 | return 0; |
| 3401 | |
| 3402 | sob_start_addr = lower_32_bits(CFG_BASE + mmSYNC_MNGR_SOB_OBJ_0); |
| 3403 | sob_end_addr = lower_32_bits(CFG_BASE + mmSYNC_MNGR_SOB_OBJ_1023); |
| 3404 | |
Tomer Tayar | df697bc | 2019-02-28 10:46:22 +0200 | [diff] [blame] | 3405 | if ((le32_to_cpu(wreg_pkt->value) < sob_start_addr) || |
| 3406 | (le32_to_cpu(wreg_pkt->value) > sob_end_addr)) { |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 3407 | |
| 3408 | dev_err(hdev->dev, "WREG32 packet with illegal value 0x%x\n", |
| 3409 | wreg_pkt->value); |
| 3410 | return -EPERM; |
| 3411 | } |
| 3412 | |
| 3413 | return 0; |
| 3414 | } |
| 3415 | |
| 3416 | static int goya_validate_cb(struct hl_device *hdev, |
| 3417 | struct hl_cs_parser *parser, bool is_mmu) |
| 3418 | { |
| 3419 | u32 cb_parsed_length = 0; |
| 3420 | int rc = 0; |
| 3421 | |
| 3422 | parser->patched_cb_size = 0; |
| 3423 | |
| 3424 | /* cb_user_size is more than 0 so loop will always be executed */ |
| 3425 | while (cb_parsed_length < parser->user_cb_size) { |
| 3426 | enum packet_id pkt_id; |
| 3427 | u16 pkt_size; |
| 3428 | void *user_pkt; |
| 3429 | |
| 3430 | user_pkt = (void *) (uintptr_t) |
| 3431 | (parser->user_cb->kernel_address + cb_parsed_length); |
| 3432 | |
| 3433 | pkt_id = (enum packet_id) (((*(u64 *) user_pkt) & |
| 3434 | PACKET_HEADER_PACKET_ID_MASK) >> |
| 3435 | PACKET_HEADER_PACKET_ID_SHIFT); |
| 3436 | |
| 3437 | pkt_size = goya_packet_sizes[pkt_id]; |
| 3438 | cb_parsed_length += pkt_size; |
| 3439 | if (cb_parsed_length > parser->user_cb_size) { |
| 3440 | dev_err(hdev->dev, |
| 3441 | "packet 0x%x is out of CB boundary\n", pkt_id); |
| 3442 | rc = -EINVAL; |
| 3443 | break; |
| 3444 | } |
| 3445 | |
| 3446 | switch (pkt_id) { |
| 3447 | case PACKET_WREG_32: |
| 3448 | /* |
| 3449 | * Although it is validated after copy in patch_cb(), |
| 3450 | * need to validate here as well because patch_cb() is |
| 3451 | * not called in MMU path while this function is called |
| 3452 | */ |
| 3453 | rc = goya_validate_wreg32(hdev, parser, user_pkt); |
| 3454 | break; |
| 3455 | |
| 3456 | case PACKET_WREG_BULK: |
| 3457 | dev_err(hdev->dev, |
| 3458 | "User not allowed to use WREG_BULK\n"); |
| 3459 | rc = -EPERM; |
| 3460 | break; |
| 3461 | |
| 3462 | case PACKET_MSG_PROT: |
| 3463 | dev_err(hdev->dev, |
| 3464 | "User not allowed to use MSG_PROT\n"); |
| 3465 | rc = -EPERM; |
| 3466 | break; |
| 3467 | |
| 3468 | case PACKET_CP_DMA: |
| 3469 | dev_err(hdev->dev, "User not allowed to use CP_DMA\n"); |
| 3470 | rc = -EPERM; |
| 3471 | break; |
| 3472 | |
| 3473 | case PACKET_STOP: |
| 3474 | dev_err(hdev->dev, "User not allowed to use STOP\n"); |
| 3475 | rc = -EPERM; |
| 3476 | break; |
| 3477 | |
| 3478 | case PACKET_LIN_DMA: |
| 3479 | if (is_mmu) |
| 3480 | rc = goya_validate_dma_pkt_mmu(hdev, parser, |
| 3481 | user_pkt); |
| 3482 | else |
| 3483 | rc = goya_validate_dma_pkt_no_mmu(hdev, parser, |
| 3484 | user_pkt); |
| 3485 | break; |
| 3486 | |
| 3487 | case PACKET_MSG_LONG: |
| 3488 | case PACKET_MSG_SHORT: |
| 3489 | case PACKET_FENCE: |
| 3490 | case PACKET_NOP: |
| 3491 | parser->patched_cb_size += pkt_size; |
| 3492 | break; |
| 3493 | |
| 3494 | default: |
| 3495 | dev_err(hdev->dev, "Invalid packet header 0x%x\n", |
| 3496 | pkt_id); |
| 3497 | rc = -EINVAL; |
| 3498 | break; |
| 3499 | } |
| 3500 | |
| 3501 | if (rc) |
| 3502 | break; |
| 3503 | } |
| 3504 | |
| 3505 | /* |
| 3506 | * The new CB should have space at the end for two MSG_PROT packets: |
| 3507 | * 1. A packet that will act as a completion packet |
| 3508 | * 2. A packet that will generate MSI-X interrupt |
| 3509 | */ |
| 3510 | parser->patched_cb_size += sizeof(struct packet_msg_prot) * 2; |
| 3511 | |
| 3512 | return rc; |
| 3513 | } |
| 3514 | |
| 3515 | static int goya_patch_dma_packet(struct hl_device *hdev, |
| 3516 | struct hl_cs_parser *parser, |
| 3517 | struct packet_lin_dma *user_dma_pkt, |
| 3518 | struct packet_lin_dma *new_dma_pkt, |
| 3519 | u32 *new_dma_pkt_size) |
| 3520 | { |
| 3521 | struct hl_userptr *userptr; |
| 3522 | struct scatterlist *sg, *sg_next_iter; |
Oded Gabbay | e99f1683 | 2019-02-24 11:55:26 +0200 | [diff] [blame] | 3523 | u32 count, dma_desc_cnt; |
| 3524 | u64 len, len_next; |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 3525 | dma_addr_t dma_addr, dma_addr_next; |
| 3526 | enum goya_dma_direction user_dir; |
| 3527 | u64 device_memory_addr, addr; |
| 3528 | enum dma_data_direction dir; |
| 3529 | struct sg_table *sgt; |
| 3530 | bool skip_host_mem_pin = false; |
| 3531 | bool user_memset; |
Tomer Tayar | df697bc | 2019-02-28 10:46:22 +0200 | [diff] [blame] | 3532 | u32 user_rdcomp_mask, user_wrcomp_mask, ctl; |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 3533 | |
Tomer Tayar | df697bc | 2019-02-28 10:46:22 +0200 | [diff] [blame] | 3534 | ctl = le32_to_cpu(user_dma_pkt->ctl); |
| 3535 | |
| 3536 | user_dir = (ctl & GOYA_PKT_LIN_DMA_CTL_DMA_DIR_MASK) >> |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 3537 | GOYA_PKT_LIN_DMA_CTL_DMA_DIR_SHIFT; |
| 3538 | |
Tomer Tayar | df697bc | 2019-02-28 10:46:22 +0200 | [diff] [blame] | 3539 | user_memset = (ctl & GOYA_PKT_LIN_DMA_CTL_MEMSET_MASK) >> |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 3540 | GOYA_PKT_LIN_DMA_CTL_MEMSET_SHIFT; |
| 3541 | |
| 3542 | if ((user_dir == DMA_DRAM_TO_SRAM) || (user_dir == DMA_SRAM_TO_DRAM) || |
| 3543 | (user_dma_pkt->tsize == 0)) { |
| 3544 | memcpy(new_dma_pkt, user_dma_pkt, sizeof(*new_dma_pkt)); |
| 3545 | *new_dma_pkt_size = sizeof(*new_dma_pkt); |
| 3546 | return 0; |
| 3547 | } |
| 3548 | |
| 3549 | if ((user_dir == DMA_HOST_TO_DRAM) || (user_dir == DMA_HOST_TO_SRAM)) { |
Tomer Tayar | df697bc | 2019-02-28 10:46:22 +0200 | [diff] [blame] | 3550 | addr = le64_to_cpu(user_dma_pkt->src_addr); |
| 3551 | device_memory_addr = le64_to_cpu(user_dma_pkt->dst_addr); |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 3552 | dir = DMA_TO_DEVICE; |
| 3553 | if (user_memset) |
| 3554 | skip_host_mem_pin = true; |
| 3555 | } else { |
Tomer Tayar | df697bc | 2019-02-28 10:46:22 +0200 | [diff] [blame] | 3556 | addr = le64_to_cpu(user_dma_pkt->dst_addr); |
| 3557 | device_memory_addr = le64_to_cpu(user_dma_pkt->src_addr); |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 3558 | dir = DMA_FROM_DEVICE; |
| 3559 | } |
| 3560 | |
| 3561 | if ((!skip_host_mem_pin) && |
Tomer Tayar | df697bc | 2019-02-28 10:46:22 +0200 | [diff] [blame] | 3562 | (hl_userptr_is_pinned(hdev, addr, |
| 3563 | le32_to_cpu(user_dma_pkt->tsize), |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 3564 | parser->job_userptr_list, &userptr) == false)) { |
| 3565 | dev_err(hdev->dev, "Userptr 0x%llx + 0x%x NOT mapped\n", |
| 3566 | addr, user_dma_pkt->tsize); |
| 3567 | return -EFAULT; |
| 3568 | } |
| 3569 | |
| 3570 | if ((user_memset) && (dir == DMA_TO_DEVICE)) { |
| 3571 | memcpy(new_dma_pkt, user_dma_pkt, sizeof(*user_dma_pkt)); |
| 3572 | *new_dma_pkt_size = sizeof(*user_dma_pkt); |
| 3573 | return 0; |
| 3574 | } |
| 3575 | |
Tomer Tayar | df697bc | 2019-02-28 10:46:22 +0200 | [diff] [blame] | 3576 | user_rdcomp_mask = ctl & GOYA_PKT_LIN_DMA_CTL_RDCOMP_MASK; |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 3577 | |
Tomer Tayar | df697bc | 2019-02-28 10:46:22 +0200 | [diff] [blame] | 3578 | user_wrcomp_mask = ctl & GOYA_PKT_LIN_DMA_CTL_WRCOMP_MASK; |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 3579 | |
| 3580 | sgt = userptr->sgt; |
| 3581 | dma_desc_cnt = 0; |
| 3582 | |
| 3583 | for_each_sg(sgt->sgl, sg, sgt->nents, count) { |
| 3584 | len = sg_dma_len(sg); |
| 3585 | dma_addr = sg_dma_address(sg); |
| 3586 | |
| 3587 | if (len == 0) |
| 3588 | break; |
| 3589 | |
| 3590 | while ((count + 1) < sgt->nents) { |
| 3591 | sg_next_iter = sg_next(sg); |
| 3592 | len_next = sg_dma_len(sg_next_iter); |
| 3593 | dma_addr_next = sg_dma_address(sg_next_iter); |
| 3594 | |
| 3595 | if (len_next == 0) |
| 3596 | break; |
| 3597 | |
| 3598 | if ((dma_addr + len == dma_addr_next) && |
| 3599 | (len + len_next <= DMA_MAX_TRANSFER_SIZE)) { |
| 3600 | len += len_next; |
| 3601 | count++; |
| 3602 | sg = sg_next_iter; |
| 3603 | } else { |
| 3604 | break; |
| 3605 | } |
| 3606 | } |
| 3607 | |
Tomer Tayar | df697bc | 2019-02-28 10:46:22 +0200 | [diff] [blame] | 3608 | ctl = le32_to_cpu(user_dma_pkt->ctl); |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 3609 | if (likely(dma_desc_cnt)) |
Tomer Tayar | df697bc | 2019-02-28 10:46:22 +0200 | [diff] [blame] | 3610 | ctl &= ~GOYA_PKT_CTL_EB_MASK; |
| 3611 | ctl &= ~(GOYA_PKT_LIN_DMA_CTL_RDCOMP_MASK | |
| 3612 | GOYA_PKT_LIN_DMA_CTL_WRCOMP_MASK); |
| 3613 | new_dma_pkt->ctl = cpu_to_le32(ctl); |
| 3614 | new_dma_pkt->tsize = cpu_to_le32((u32) len); |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 3615 | |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 3616 | if (dir == DMA_TO_DEVICE) { |
Tomer Tayar | df697bc | 2019-02-28 10:46:22 +0200 | [diff] [blame] | 3617 | new_dma_pkt->src_addr = cpu_to_le64(dma_addr); |
| 3618 | new_dma_pkt->dst_addr = cpu_to_le64(device_memory_addr); |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 3619 | } else { |
Tomer Tayar | df697bc | 2019-02-28 10:46:22 +0200 | [diff] [blame] | 3620 | new_dma_pkt->src_addr = cpu_to_le64(device_memory_addr); |
| 3621 | new_dma_pkt->dst_addr = cpu_to_le64(dma_addr); |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 3622 | } |
| 3623 | |
| 3624 | if (!user_memset) |
| 3625 | device_memory_addr += len; |
| 3626 | dma_desc_cnt++; |
| 3627 | new_dma_pkt++; |
| 3628 | } |
| 3629 | |
| 3630 | if (!dma_desc_cnt) { |
| 3631 | dev_err(hdev->dev, |
| 3632 | "Error of 0 SG entries when patching DMA packet\n"); |
| 3633 | return -EFAULT; |
| 3634 | } |
| 3635 | |
| 3636 | /* Fix the last dma packet - rdcomp/wrcomp must be as user set them */ |
| 3637 | new_dma_pkt--; |
Tomer Tayar | df697bc | 2019-02-28 10:46:22 +0200 | [diff] [blame] | 3638 | new_dma_pkt->ctl |= cpu_to_le32(user_rdcomp_mask | user_wrcomp_mask); |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 3639 | |
| 3640 | *new_dma_pkt_size = dma_desc_cnt * sizeof(struct packet_lin_dma); |
| 3641 | |
| 3642 | return 0; |
| 3643 | } |
| 3644 | |
| 3645 | static int goya_patch_cb(struct hl_device *hdev, |
| 3646 | struct hl_cs_parser *parser) |
| 3647 | { |
| 3648 | u32 cb_parsed_length = 0; |
| 3649 | u32 cb_patched_cur_length = 0; |
| 3650 | int rc = 0; |
| 3651 | |
| 3652 | /* cb_user_size is more than 0 so loop will always be executed */ |
| 3653 | while (cb_parsed_length < parser->user_cb_size) { |
| 3654 | enum packet_id pkt_id; |
| 3655 | u16 pkt_size; |
| 3656 | u32 new_pkt_size = 0; |
| 3657 | void *user_pkt, *kernel_pkt; |
| 3658 | |
| 3659 | user_pkt = (void *) (uintptr_t) |
| 3660 | (parser->user_cb->kernel_address + cb_parsed_length); |
| 3661 | kernel_pkt = (void *) (uintptr_t) |
| 3662 | (parser->patched_cb->kernel_address + |
| 3663 | cb_patched_cur_length); |
| 3664 | |
| 3665 | pkt_id = (enum packet_id) (((*(u64 *) user_pkt) & |
| 3666 | PACKET_HEADER_PACKET_ID_MASK) >> |
| 3667 | PACKET_HEADER_PACKET_ID_SHIFT); |
| 3668 | |
| 3669 | pkt_size = goya_packet_sizes[pkt_id]; |
| 3670 | cb_parsed_length += pkt_size; |
| 3671 | if (cb_parsed_length > parser->user_cb_size) { |
| 3672 | dev_err(hdev->dev, |
| 3673 | "packet 0x%x is out of CB boundary\n", pkt_id); |
| 3674 | rc = -EINVAL; |
| 3675 | break; |
| 3676 | } |
| 3677 | |
| 3678 | switch (pkt_id) { |
| 3679 | case PACKET_LIN_DMA: |
| 3680 | rc = goya_patch_dma_packet(hdev, parser, user_pkt, |
| 3681 | kernel_pkt, &new_pkt_size); |
| 3682 | cb_patched_cur_length += new_pkt_size; |
| 3683 | break; |
| 3684 | |
| 3685 | case PACKET_WREG_32: |
| 3686 | memcpy(kernel_pkt, user_pkt, pkt_size); |
| 3687 | cb_patched_cur_length += pkt_size; |
| 3688 | rc = goya_validate_wreg32(hdev, parser, kernel_pkt); |
| 3689 | break; |
| 3690 | |
| 3691 | case PACKET_WREG_BULK: |
| 3692 | dev_err(hdev->dev, |
| 3693 | "User not allowed to use WREG_BULK\n"); |
| 3694 | rc = -EPERM; |
| 3695 | break; |
| 3696 | |
| 3697 | case PACKET_MSG_PROT: |
| 3698 | dev_err(hdev->dev, |
| 3699 | "User not allowed to use MSG_PROT\n"); |
| 3700 | rc = -EPERM; |
| 3701 | break; |
| 3702 | |
| 3703 | case PACKET_CP_DMA: |
| 3704 | dev_err(hdev->dev, "User not allowed to use CP_DMA\n"); |
| 3705 | rc = -EPERM; |
| 3706 | break; |
| 3707 | |
| 3708 | case PACKET_STOP: |
| 3709 | dev_err(hdev->dev, "User not allowed to use STOP\n"); |
| 3710 | rc = -EPERM; |
| 3711 | break; |
| 3712 | |
| 3713 | case PACKET_MSG_LONG: |
| 3714 | case PACKET_MSG_SHORT: |
| 3715 | case PACKET_FENCE: |
| 3716 | case PACKET_NOP: |
| 3717 | memcpy(kernel_pkt, user_pkt, pkt_size); |
| 3718 | cb_patched_cur_length += pkt_size; |
| 3719 | break; |
| 3720 | |
| 3721 | default: |
| 3722 | dev_err(hdev->dev, "Invalid packet header 0x%x\n", |
| 3723 | pkt_id); |
| 3724 | rc = -EINVAL; |
| 3725 | break; |
| 3726 | } |
| 3727 | |
| 3728 | if (rc) |
| 3729 | break; |
| 3730 | } |
| 3731 | |
| 3732 | return rc; |
| 3733 | } |
| 3734 | |
| 3735 | static int goya_parse_cb_mmu(struct hl_device *hdev, |
| 3736 | struct hl_cs_parser *parser) |
| 3737 | { |
| 3738 | u64 patched_cb_handle; |
| 3739 | u32 patched_cb_size; |
| 3740 | struct hl_cb *user_cb; |
| 3741 | int rc; |
| 3742 | |
| 3743 | /* |
| 3744 | * The new CB should have space at the end for two MSG_PROT pkt: |
| 3745 | * 1. A packet that will act as a completion packet |
| 3746 | * 2. A packet that will generate MSI-X interrupt |
| 3747 | */ |
| 3748 | parser->patched_cb_size = parser->user_cb_size + |
| 3749 | sizeof(struct packet_msg_prot) * 2; |
| 3750 | |
| 3751 | rc = hl_cb_create(hdev, &hdev->kernel_cb_mgr, |
| 3752 | parser->patched_cb_size, |
| 3753 | &patched_cb_handle, HL_KERNEL_ASID_ID); |
| 3754 | |
| 3755 | if (rc) { |
| 3756 | dev_err(hdev->dev, |
| 3757 | "Failed to allocate patched CB for DMA CS %d\n", |
| 3758 | rc); |
| 3759 | return rc; |
| 3760 | } |
| 3761 | |
| 3762 | patched_cb_handle >>= PAGE_SHIFT; |
| 3763 | parser->patched_cb = hl_cb_get(hdev, &hdev->kernel_cb_mgr, |
| 3764 | (u32) patched_cb_handle); |
| 3765 | /* hl_cb_get should never fail here so use kernel WARN */ |
| 3766 | WARN(!parser->patched_cb, "DMA CB handle invalid 0x%x\n", |
| 3767 | (u32) patched_cb_handle); |
| 3768 | if (!parser->patched_cb) { |
| 3769 | rc = -EFAULT; |
| 3770 | goto out; |
| 3771 | } |
| 3772 | |
| 3773 | /* |
| 3774 | * The check that parser->user_cb_size <= parser->user_cb->size was done |
| 3775 | * in validate_queue_index(). |
| 3776 | */ |
| 3777 | memcpy((void *) (uintptr_t) parser->patched_cb->kernel_address, |
| 3778 | (void *) (uintptr_t) parser->user_cb->kernel_address, |
| 3779 | parser->user_cb_size); |
| 3780 | |
| 3781 | patched_cb_size = parser->patched_cb_size; |
| 3782 | |
| 3783 | /* validate patched CB instead of user CB */ |
| 3784 | user_cb = parser->user_cb; |
| 3785 | parser->user_cb = parser->patched_cb; |
| 3786 | rc = goya_validate_cb(hdev, parser, true); |
| 3787 | parser->user_cb = user_cb; |
| 3788 | |
| 3789 | if (rc) { |
| 3790 | hl_cb_put(parser->patched_cb); |
| 3791 | goto out; |
| 3792 | } |
| 3793 | |
| 3794 | if (patched_cb_size != parser->patched_cb_size) { |
| 3795 | dev_err(hdev->dev, "user CB size mismatch\n"); |
| 3796 | hl_cb_put(parser->patched_cb); |
| 3797 | rc = -EINVAL; |
| 3798 | goto out; |
| 3799 | } |
| 3800 | |
| 3801 | out: |
| 3802 | /* |
| 3803 | * Always call cb destroy here because we still have 1 reference |
| 3804 | * to it by calling cb_get earlier. After the job will be completed, |
| 3805 | * cb_put will release it, but here we want to remove it from the |
| 3806 | * idr |
| 3807 | */ |
| 3808 | hl_cb_destroy(hdev, &hdev->kernel_cb_mgr, |
| 3809 | patched_cb_handle << PAGE_SHIFT); |
| 3810 | |
| 3811 | return rc; |
| 3812 | } |
| 3813 | |
Oded Gabbay | 5e6e023 | 2019-02-27 12:15:16 +0200 | [diff] [blame] | 3814 | static int goya_parse_cb_no_mmu(struct hl_device *hdev, |
| 3815 | struct hl_cs_parser *parser) |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 3816 | { |
| 3817 | u64 patched_cb_handle; |
| 3818 | int rc; |
| 3819 | |
| 3820 | rc = goya_validate_cb(hdev, parser, false); |
| 3821 | |
| 3822 | if (rc) |
| 3823 | goto free_userptr; |
| 3824 | |
| 3825 | rc = hl_cb_create(hdev, &hdev->kernel_cb_mgr, |
| 3826 | parser->patched_cb_size, |
| 3827 | &patched_cb_handle, HL_KERNEL_ASID_ID); |
| 3828 | if (rc) { |
| 3829 | dev_err(hdev->dev, |
| 3830 | "Failed to allocate patched CB for DMA CS %d\n", rc); |
| 3831 | goto free_userptr; |
| 3832 | } |
| 3833 | |
| 3834 | patched_cb_handle >>= PAGE_SHIFT; |
| 3835 | parser->patched_cb = hl_cb_get(hdev, &hdev->kernel_cb_mgr, |
| 3836 | (u32) patched_cb_handle); |
| 3837 | /* hl_cb_get should never fail here so use kernel WARN */ |
| 3838 | WARN(!parser->patched_cb, "DMA CB handle invalid 0x%x\n", |
| 3839 | (u32) patched_cb_handle); |
| 3840 | if (!parser->patched_cb) { |
| 3841 | rc = -EFAULT; |
| 3842 | goto out; |
| 3843 | } |
| 3844 | |
| 3845 | rc = goya_patch_cb(hdev, parser); |
| 3846 | |
| 3847 | if (rc) |
| 3848 | hl_cb_put(parser->patched_cb); |
| 3849 | |
| 3850 | out: |
| 3851 | /* |
| 3852 | * Always call cb destroy here because we still have 1 reference |
| 3853 | * to it by calling cb_get earlier. After the job will be completed, |
| 3854 | * cb_put will release it, but here we want to remove it from the |
| 3855 | * idr |
| 3856 | */ |
| 3857 | hl_cb_destroy(hdev, &hdev->kernel_cb_mgr, |
| 3858 | patched_cb_handle << PAGE_SHIFT); |
| 3859 | |
| 3860 | free_userptr: |
| 3861 | if (rc) |
| 3862 | hl_userptr_delete_list(hdev, parser->job_userptr_list); |
| 3863 | return rc; |
| 3864 | } |
| 3865 | |
Oded Gabbay | 883c245 | 2019-04-21 10:48:41 +0300 | [diff] [blame] | 3866 | static int goya_parse_cb_no_ext_queue(struct hl_device *hdev, |
Oded Gabbay | 5e6e023 | 2019-02-27 12:15:16 +0200 | [diff] [blame] | 3867 | struct hl_cs_parser *parser) |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 3868 | { |
| 3869 | struct asic_fixed_properties *asic_prop = &hdev->asic_prop; |
| 3870 | struct goya_device *goya = hdev->asic_specific; |
| 3871 | |
Oded Gabbay | 883c245 | 2019-04-21 10:48:41 +0300 | [diff] [blame] | 3872 | if (goya->hw_cap_initialized & HW_CAP_MMU) |
| 3873 | return 0; |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 3874 | |
Oded Gabbay | 883c245 | 2019-04-21 10:48:41 +0300 | [diff] [blame] | 3875 | /* For internal queue jobs, just check if CB address is valid */ |
| 3876 | if (hl_mem_area_inside_range( |
| 3877 | (u64) (uintptr_t) parser->user_cb, |
| 3878 | parser->user_cb_size, |
| 3879 | asic_prop->sram_user_base_address, |
| 3880 | asic_prop->sram_end_address)) |
| 3881 | return 0; |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 3882 | |
Oded Gabbay | 883c245 | 2019-04-21 10:48:41 +0300 | [diff] [blame] | 3883 | if (hl_mem_area_inside_range( |
| 3884 | (u64) (uintptr_t) parser->user_cb, |
| 3885 | parser->user_cb_size, |
| 3886 | asic_prop->dram_user_base_address, |
| 3887 | asic_prop->dram_end_address)) |
| 3888 | return 0; |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 3889 | |
Oded Gabbay | 883c245 | 2019-04-21 10:48:41 +0300 | [diff] [blame] | 3890 | dev_err(hdev->dev, |
| 3891 | "Internal CB address %px + 0x%x is not in SRAM nor in DRAM\n", |
| 3892 | parser->user_cb, parser->user_cb_size); |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 3893 | |
Oded Gabbay | 883c245 | 2019-04-21 10:48:41 +0300 | [diff] [blame] | 3894 | return -EFAULT; |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 3895 | } |
| 3896 | |
| 3897 | int goya_cs_parser(struct hl_device *hdev, struct hl_cs_parser *parser) |
| 3898 | { |
| 3899 | struct goya_device *goya = hdev->asic_specific; |
| 3900 | |
| 3901 | if (!parser->ext_queue) |
Oded Gabbay | 883c245 | 2019-04-21 10:48:41 +0300 | [diff] [blame] | 3902 | return goya_parse_cb_no_ext_queue(hdev, parser); |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 3903 | |
Dalit Ben Zoor | 5809e18 | 2019-05-01 13:16:18 +0300 | [diff] [blame] | 3904 | if (goya->hw_cap_initialized & HW_CAP_MMU) |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 3905 | return goya_parse_cb_mmu(hdev, parser); |
| 3906 | else |
| 3907 | return goya_parse_cb_no_mmu(hdev, parser); |
| 3908 | } |
| 3909 | |
| 3910 | void goya_add_end_of_cb_packets(u64 kernel_address, u32 len, u64 cq_addr, |
| 3911 | u32 cq_val, u32 msix_vec) |
| 3912 | { |
| 3913 | struct packet_msg_prot *cq_pkt; |
Tomer Tayar | df697bc | 2019-02-28 10:46:22 +0200 | [diff] [blame] | 3914 | u32 tmp; |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 3915 | |
| 3916 | cq_pkt = (struct packet_msg_prot *) (uintptr_t) |
| 3917 | (kernel_address + len - (sizeof(struct packet_msg_prot) * 2)); |
| 3918 | |
Tomer Tayar | df697bc | 2019-02-28 10:46:22 +0200 | [diff] [blame] | 3919 | tmp = (PACKET_MSG_PROT << GOYA_PKT_CTL_OPCODE_SHIFT) | |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 3920 | (1 << GOYA_PKT_CTL_EB_SHIFT) | |
| 3921 | (1 << GOYA_PKT_CTL_MB_SHIFT); |
Tomer Tayar | df697bc | 2019-02-28 10:46:22 +0200 | [diff] [blame] | 3922 | cq_pkt->ctl = cpu_to_le32(tmp); |
| 3923 | cq_pkt->value = cpu_to_le32(cq_val); |
| 3924 | cq_pkt->addr = cpu_to_le64(cq_addr); |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 3925 | |
| 3926 | cq_pkt++; |
| 3927 | |
Tomer Tayar | df697bc | 2019-02-28 10:46:22 +0200 | [diff] [blame] | 3928 | tmp = (PACKET_MSG_PROT << GOYA_PKT_CTL_OPCODE_SHIFT) | |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 3929 | (1 << GOYA_PKT_CTL_MB_SHIFT); |
Tomer Tayar | df697bc | 2019-02-28 10:46:22 +0200 | [diff] [blame] | 3930 | cq_pkt->ctl = cpu_to_le32(tmp); |
| 3931 | cq_pkt->value = cpu_to_le32(msix_vec & 0x7FF); |
| 3932 | cq_pkt->addr = cpu_to_le64(CFG_BASE + mmPCIE_DBI_MSIX_DOORBELL_OFF); |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 3933 | } |
| 3934 | |
Oded Gabbay | b2377e0 | 2019-04-22 11:49:06 +0300 | [diff] [blame] | 3935 | void goya_update_eq_ci(struct hl_device *hdev, u32 val) |
Oded Gabbay | 1251f23 | 2019-02-16 00:39:18 +0200 | [diff] [blame] | 3936 | { |
| 3937 | WREG32(mmPSOC_GLOBAL_CONF_SCRATCHPAD_6, val); |
| 3938 | } |
| 3939 | |
Oded Gabbay | b2377e0 | 2019-04-22 11:49:06 +0300 | [diff] [blame] | 3940 | void goya_restore_phase_topology(struct hl_device *hdev) |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 3941 | { |
| 3942 | int i, num_of_sob_in_longs, num_of_mon_in_longs; |
| 3943 | |
| 3944 | num_of_sob_in_longs = |
| 3945 | ((mmSYNC_MNGR_SOB_OBJ_1023 - mmSYNC_MNGR_SOB_OBJ_0) + 4); |
| 3946 | |
| 3947 | num_of_mon_in_longs = |
| 3948 | ((mmSYNC_MNGR_MON_STATUS_255 - mmSYNC_MNGR_MON_STATUS_0) + 4); |
| 3949 | |
| 3950 | for (i = 0 ; i < num_of_sob_in_longs ; i += 4) |
| 3951 | WREG32(mmSYNC_MNGR_SOB_OBJ_0 + i, 0); |
| 3952 | |
| 3953 | for (i = 0 ; i < num_of_mon_in_longs ; i += 4) |
| 3954 | WREG32(mmSYNC_MNGR_MON_STATUS_0 + i, 0); |
| 3955 | |
| 3956 | /* Flush all WREG to prevent race */ |
| 3957 | i = RREG32(mmSYNC_MNGR_SOB_OBJ_0); |
| 3958 | } |
| 3959 | |
Oded Gabbay | c216477 | 2019-02-16 00:39:24 +0200 | [diff] [blame] | 3960 | /* |
| 3961 | * goya_debugfs_read32 - read a 32bit value from a given device address |
| 3962 | * |
| 3963 | * @hdev: pointer to hl_device structure |
| 3964 | * @addr: address in device |
| 3965 | * @val: returned value |
| 3966 | * |
| 3967 | * In case of DDR address that is not mapped into the default aperture that |
| 3968 | * the DDR bar exposes, the function will configure the iATU so that the DDR |
| 3969 | * bar will be positioned at a base address that allows reading from the |
| 3970 | * required address. Configuring the iATU during normal operation can |
| 3971 | * lead to undefined behavior and therefore, should be done with extreme care |
| 3972 | * |
| 3973 | */ |
Oded Gabbay | 5e6e023 | 2019-02-27 12:15:16 +0200 | [diff] [blame] | 3974 | static int goya_debugfs_read32(struct hl_device *hdev, u64 addr, u32 *val) |
Oded Gabbay | c216477 | 2019-02-16 00:39:24 +0200 | [diff] [blame] | 3975 | { |
| 3976 | struct asic_fixed_properties *prop = &hdev->asic_prop; |
Oded Gabbay | a38693d | 2019-04-28 10:18:35 +0300 | [diff] [blame] | 3977 | u64 ddr_bar_addr; |
Oded Gabbay | c216477 | 2019-02-16 00:39:24 +0200 | [diff] [blame] | 3978 | int rc = 0; |
| 3979 | |
| 3980 | if ((addr >= CFG_BASE) && (addr < CFG_BASE + CFG_SIZE)) { |
| 3981 | *val = RREG32(addr - CFG_BASE); |
| 3982 | |
| 3983 | } else if ((addr >= SRAM_BASE_ADDR) && |
| 3984 | (addr < SRAM_BASE_ADDR + SRAM_SIZE)) { |
| 3985 | |
| 3986 | *val = readl(hdev->pcie_bar[SRAM_CFG_BAR_ID] + |
| 3987 | (addr - SRAM_BASE_ADDR)); |
| 3988 | |
| 3989 | } else if ((addr >= DRAM_PHYS_BASE) && |
| 3990 | (addr < DRAM_PHYS_BASE + hdev->asic_prop.dram_size)) { |
| 3991 | |
| 3992 | u64 bar_base_addr = DRAM_PHYS_BASE + |
| 3993 | (addr & ~(prop->dram_pci_bar_size - 0x1ull)); |
| 3994 | |
Oded Gabbay | a38693d | 2019-04-28 10:18:35 +0300 | [diff] [blame] | 3995 | ddr_bar_addr = goya_set_ddr_bar_base(hdev, bar_base_addr); |
| 3996 | if (ddr_bar_addr != U64_MAX) { |
Oded Gabbay | c216477 | 2019-02-16 00:39:24 +0200 | [diff] [blame] | 3997 | *val = readl(hdev->pcie_bar[DDR_BAR_ID] + |
| 3998 | (addr - bar_base_addr)); |
| 3999 | |
Oded Gabbay | a38693d | 2019-04-28 10:18:35 +0300 | [diff] [blame] | 4000 | ddr_bar_addr = goya_set_ddr_bar_base(hdev, |
| 4001 | ddr_bar_addr); |
Oded Gabbay | c216477 | 2019-02-16 00:39:24 +0200 | [diff] [blame] | 4002 | } |
Oded Gabbay | a38693d | 2019-04-28 10:18:35 +0300 | [diff] [blame] | 4003 | if (ddr_bar_addr == U64_MAX) |
| 4004 | rc = -EIO; |
Oded Gabbay | c216477 | 2019-02-16 00:39:24 +0200 | [diff] [blame] | 4005 | } else { |
| 4006 | rc = -EFAULT; |
| 4007 | } |
| 4008 | |
| 4009 | return rc; |
| 4010 | } |
| 4011 | |
| 4012 | /* |
| 4013 | * goya_debugfs_write32 - write a 32bit value to a given device address |
| 4014 | * |
| 4015 | * @hdev: pointer to hl_device structure |
| 4016 | * @addr: address in device |
| 4017 | * @val: returned value |
| 4018 | * |
| 4019 | * In case of DDR address that is not mapped into the default aperture that |
| 4020 | * the DDR bar exposes, the function will configure the iATU so that the DDR |
| 4021 | * bar will be positioned at a base address that allows writing to the |
| 4022 | * required address. Configuring the iATU during normal operation can |
| 4023 | * lead to undefined behavior and therefore, should be done with extreme care |
| 4024 | * |
| 4025 | */ |
Oded Gabbay | 5e6e023 | 2019-02-27 12:15:16 +0200 | [diff] [blame] | 4026 | static int goya_debugfs_write32(struct hl_device *hdev, u64 addr, u32 val) |
Oded Gabbay | c216477 | 2019-02-16 00:39:24 +0200 | [diff] [blame] | 4027 | { |
| 4028 | struct asic_fixed_properties *prop = &hdev->asic_prop; |
Oded Gabbay | a38693d | 2019-04-28 10:18:35 +0300 | [diff] [blame] | 4029 | u64 ddr_bar_addr; |
Oded Gabbay | c216477 | 2019-02-16 00:39:24 +0200 | [diff] [blame] | 4030 | int rc = 0; |
| 4031 | |
| 4032 | if ((addr >= CFG_BASE) && (addr < CFG_BASE + CFG_SIZE)) { |
| 4033 | WREG32(addr - CFG_BASE, val); |
| 4034 | |
| 4035 | } else if ((addr >= SRAM_BASE_ADDR) && |
| 4036 | (addr < SRAM_BASE_ADDR + SRAM_SIZE)) { |
| 4037 | |
| 4038 | writel(val, hdev->pcie_bar[SRAM_CFG_BAR_ID] + |
| 4039 | (addr - SRAM_BASE_ADDR)); |
| 4040 | |
| 4041 | } else if ((addr >= DRAM_PHYS_BASE) && |
| 4042 | (addr < DRAM_PHYS_BASE + hdev->asic_prop.dram_size)) { |
| 4043 | |
| 4044 | u64 bar_base_addr = DRAM_PHYS_BASE + |
| 4045 | (addr & ~(prop->dram_pci_bar_size - 0x1ull)); |
| 4046 | |
Oded Gabbay | a38693d | 2019-04-28 10:18:35 +0300 | [diff] [blame] | 4047 | ddr_bar_addr = goya_set_ddr_bar_base(hdev, bar_base_addr); |
| 4048 | if (ddr_bar_addr != U64_MAX) { |
Oded Gabbay | c216477 | 2019-02-16 00:39:24 +0200 | [diff] [blame] | 4049 | writel(val, hdev->pcie_bar[DDR_BAR_ID] + |
| 4050 | (addr - bar_base_addr)); |
| 4051 | |
Oded Gabbay | a38693d | 2019-04-28 10:18:35 +0300 | [diff] [blame] | 4052 | ddr_bar_addr = goya_set_ddr_bar_base(hdev, |
| 4053 | ddr_bar_addr); |
Oded Gabbay | c216477 | 2019-02-16 00:39:24 +0200 | [diff] [blame] | 4054 | } |
Oded Gabbay | a38693d | 2019-04-28 10:18:35 +0300 | [diff] [blame] | 4055 | if (ddr_bar_addr == U64_MAX) |
| 4056 | rc = -EIO; |
Oded Gabbay | c216477 | 2019-02-16 00:39:24 +0200 | [diff] [blame] | 4057 | } else { |
| 4058 | rc = -EFAULT; |
| 4059 | } |
| 4060 | |
| 4061 | return rc; |
| 4062 | } |
| 4063 | |
Omer Shpigelman | 0feaf86 | 2019-02-16 00:39:22 +0200 | [diff] [blame] | 4064 | static u64 goya_read_pte(struct hl_device *hdev, u64 addr) |
| 4065 | { |
| 4066 | struct goya_device *goya = hdev->asic_specific; |
| 4067 | |
Oded Gabbay | 9f201aba | 2019-04-06 15:33:38 +0300 | [diff] [blame] | 4068 | if (hdev->hard_reset_pending) |
| 4069 | return U64_MAX; |
| 4070 | |
Omer Shpigelman | 0feaf86 | 2019-02-16 00:39:22 +0200 | [diff] [blame] | 4071 | return readq(hdev->pcie_bar[DDR_BAR_ID] + |
| 4072 | (addr - goya->ddr_bar_cur_addr)); |
| 4073 | } |
| 4074 | |
| 4075 | static void goya_write_pte(struct hl_device *hdev, u64 addr, u64 val) |
| 4076 | { |
| 4077 | struct goya_device *goya = hdev->asic_specific; |
| 4078 | |
Oded Gabbay | 9f201aba | 2019-04-06 15:33:38 +0300 | [diff] [blame] | 4079 | if (hdev->hard_reset_pending) |
| 4080 | return; |
| 4081 | |
Omer Shpigelman | 0feaf86 | 2019-02-16 00:39:22 +0200 | [diff] [blame] | 4082 | writeq(val, hdev->pcie_bar[DDR_BAR_ID] + |
| 4083 | (addr - goya->ddr_bar_cur_addr)); |
| 4084 | } |
| 4085 | |
Tomer Tayar | 60b7dcc | 2019-02-28 10:46:10 +0200 | [diff] [blame] | 4086 | static const char *_goya_get_event_desc(u16 event_type) |
Oded Gabbay | 1251f23 | 2019-02-16 00:39:18 +0200 | [diff] [blame] | 4087 | { |
Tomer Tayar | 60b7dcc | 2019-02-28 10:46:10 +0200 | [diff] [blame] | 4088 | switch (event_type) { |
| 4089 | case GOYA_ASYNC_EVENT_ID_PCIE_DEC: |
| 4090 | return "PCIe_dec"; |
| 4091 | case GOYA_ASYNC_EVENT_ID_TPC0_DEC: |
| 4092 | case GOYA_ASYNC_EVENT_ID_TPC1_DEC: |
| 4093 | case GOYA_ASYNC_EVENT_ID_TPC2_DEC: |
| 4094 | case GOYA_ASYNC_EVENT_ID_TPC3_DEC: |
| 4095 | case GOYA_ASYNC_EVENT_ID_TPC4_DEC: |
| 4096 | case GOYA_ASYNC_EVENT_ID_TPC5_DEC: |
| 4097 | case GOYA_ASYNC_EVENT_ID_TPC6_DEC: |
| 4098 | case GOYA_ASYNC_EVENT_ID_TPC7_DEC: |
| 4099 | return "TPC%d_dec"; |
| 4100 | case GOYA_ASYNC_EVENT_ID_MME_WACS: |
| 4101 | return "MME_wacs"; |
| 4102 | case GOYA_ASYNC_EVENT_ID_MME_WACSD: |
| 4103 | return "MME_wacsd"; |
| 4104 | case GOYA_ASYNC_EVENT_ID_CPU_AXI_SPLITTER: |
| 4105 | return "CPU_axi_splitter"; |
| 4106 | case GOYA_ASYNC_EVENT_ID_PSOC_AXI_DEC: |
| 4107 | return "PSOC_axi_dec"; |
| 4108 | case GOYA_ASYNC_EVENT_ID_PSOC: |
| 4109 | return "PSOC"; |
| 4110 | case GOYA_ASYNC_EVENT_ID_TPC0_KRN_ERR: |
| 4111 | case GOYA_ASYNC_EVENT_ID_TPC1_KRN_ERR: |
| 4112 | case GOYA_ASYNC_EVENT_ID_TPC2_KRN_ERR: |
| 4113 | case GOYA_ASYNC_EVENT_ID_TPC3_KRN_ERR: |
| 4114 | case GOYA_ASYNC_EVENT_ID_TPC4_KRN_ERR: |
| 4115 | case GOYA_ASYNC_EVENT_ID_TPC5_KRN_ERR: |
| 4116 | case GOYA_ASYNC_EVENT_ID_TPC6_KRN_ERR: |
| 4117 | case GOYA_ASYNC_EVENT_ID_TPC7_KRN_ERR: |
| 4118 | return "TPC%d_krn_err"; |
| 4119 | case GOYA_ASYNC_EVENT_ID_TPC0_CMDQ ... GOYA_ASYNC_EVENT_ID_TPC7_CMDQ: |
| 4120 | return "TPC%d_cq"; |
| 4121 | case GOYA_ASYNC_EVENT_ID_TPC0_QM ... GOYA_ASYNC_EVENT_ID_TPC7_QM: |
| 4122 | return "TPC%d_qm"; |
| 4123 | case GOYA_ASYNC_EVENT_ID_MME_QM: |
| 4124 | return "MME_qm"; |
| 4125 | case GOYA_ASYNC_EVENT_ID_MME_CMDQ: |
| 4126 | return "MME_cq"; |
| 4127 | case GOYA_ASYNC_EVENT_ID_DMA0_QM ... GOYA_ASYNC_EVENT_ID_DMA4_QM: |
| 4128 | return "DMA%d_qm"; |
| 4129 | case GOYA_ASYNC_EVENT_ID_DMA0_CH ... GOYA_ASYNC_EVENT_ID_DMA4_CH: |
| 4130 | return "DMA%d_ch"; |
| 4131 | default: |
| 4132 | return "N/A"; |
| 4133 | } |
Oded Gabbay | 1251f23 | 2019-02-16 00:39:18 +0200 | [diff] [blame] | 4134 | } |
| 4135 | |
Tomer Tayar | 60b7dcc | 2019-02-28 10:46:10 +0200 | [diff] [blame] | 4136 | static void goya_get_event_desc(u16 event_type, char *desc, size_t size) |
Oded Gabbay | 1251f23 | 2019-02-16 00:39:18 +0200 | [diff] [blame] | 4137 | { |
Tomer Tayar | 60b7dcc | 2019-02-28 10:46:10 +0200 | [diff] [blame] | 4138 | u8 index; |
Oded Gabbay | 1251f23 | 2019-02-16 00:39:18 +0200 | [diff] [blame] | 4139 | |
Tomer Tayar | 60b7dcc | 2019-02-28 10:46:10 +0200 | [diff] [blame] | 4140 | switch (event_type) { |
| 4141 | case GOYA_ASYNC_EVENT_ID_TPC0_DEC: |
| 4142 | case GOYA_ASYNC_EVENT_ID_TPC1_DEC: |
| 4143 | case GOYA_ASYNC_EVENT_ID_TPC2_DEC: |
| 4144 | case GOYA_ASYNC_EVENT_ID_TPC3_DEC: |
| 4145 | case GOYA_ASYNC_EVENT_ID_TPC4_DEC: |
| 4146 | case GOYA_ASYNC_EVENT_ID_TPC5_DEC: |
| 4147 | case GOYA_ASYNC_EVENT_ID_TPC6_DEC: |
| 4148 | case GOYA_ASYNC_EVENT_ID_TPC7_DEC: |
| 4149 | index = (event_type - GOYA_ASYNC_EVENT_ID_TPC0_DEC) / 3; |
| 4150 | snprintf(desc, size, _goya_get_event_desc(event_type), index); |
| 4151 | break; |
| 4152 | case GOYA_ASYNC_EVENT_ID_TPC0_KRN_ERR: |
| 4153 | case GOYA_ASYNC_EVENT_ID_TPC1_KRN_ERR: |
| 4154 | case GOYA_ASYNC_EVENT_ID_TPC2_KRN_ERR: |
| 4155 | case GOYA_ASYNC_EVENT_ID_TPC3_KRN_ERR: |
| 4156 | case GOYA_ASYNC_EVENT_ID_TPC4_KRN_ERR: |
| 4157 | case GOYA_ASYNC_EVENT_ID_TPC5_KRN_ERR: |
| 4158 | case GOYA_ASYNC_EVENT_ID_TPC6_KRN_ERR: |
| 4159 | case GOYA_ASYNC_EVENT_ID_TPC7_KRN_ERR: |
| 4160 | index = (event_type - GOYA_ASYNC_EVENT_ID_TPC0_KRN_ERR) / 10; |
| 4161 | snprintf(desc, size, _goya_get_event_desc(event_type), index); |
| 4162 | break; |
| 4163 | case GOYA_ASYNC_EVENT_ID_TPC0_CMDQ ... GOYA_ASYNC_EVENT_ID_TPC7_CMDQ: |
| 4164 | index = event_type - GOYA_ASYNC_EVENT_ID_TPC0_CMDQ; |
| 4165 | snprintf(desc, size, _goya_get_event_desc(event_type), index); |
| 4166 | break; |
| 4167 | case GOYA_ASYNC_EVENT_ID_TPC0_QM ... GOYA_ASYNC_EVENT_ID_TPC7_QM: |
| 4168 | index = event_type - GOYA_ASYNC_EVENT_ID_TPC0_QM; |
| 4169 | snprintf(desc, size, _goya_get_event_desc(event_type), index); |
| 4170 | break; |
| 4171 | case GOYA_ASYNC_EVENT_ID_DMA0_QM ... GOYA_ASYNC_EVENT_ID_DMA4_QM: |
| 4172 | index = event_type - GOYA_ASYNC_EVENT_ID_DMA0_QM; |
| 4173 | snprintf(desc, size, _goya_get_event_desc(event_type), index); |
| 4174 | break; |
| 4175 | case GOYA_ASYNC_EVENT_ID_DMA0_CH ... GOYA_ASYNC_EVENT_ID_DMA4_CH: |
| 4176 | index = event_type - GOYA_ASYNC_EVENT_ID_DMA0_CH; |
| 4177 | snprintf(desc, size, _goya_get_event_desc(event_type), index); |
| 4178 | break; |
| 4179 | default: |
| 4180 | snprintf(desc, size, _goya_get_event_desc(event_type)); |
| 4181 | break; |
| 4182 | } |
| 4183 | } |
Oded Gabbay | 1251f23 | 2019-02-16 00:39:18 +0200 | [diff] [blame] | 4184 | |
Tomer Tayar | 60b7dcc | 2019-02-28 10:46:10 +0200 | [diff] [blame] | 4185 | static void goya_print_razwi_info(struct hl_device *hdev) |
| 4186 | { |
| 4187 | if (RREG32(mmDMA_MACRO_RAZWI_LBW_WT_VLD)) { |
| 4188 | dev_err(hdev->dev, "Illegal write to LBW\n"); |
| 4189 | WREG32(mmDMA_MACRO_RAZWI_LBW_WT_VLD, 0); |
| 4190 | } |
Oded Gabbay | 1251f23 | 2019-02-16 00:39:18 +0200 | [diff] [blame] | 4191 | |
Tomer Tayar | 60b7dcc | 2019-02-28 10:46:10 +0200 | [diff] [blame] | 4192 | if (RREG32(mmDMA_MACRO_RAZWI_LBW_RD_VLD)) { |
| 4193 | dev_err(hdev->dev, "Illegal read from LBW\n"); |
| 4194 | WREG32(mmDMA_MACRO_RAZWI_LBW_RD_VLD, 0); |
| 4195 | } |
| 4196 | |
| 4197 | if (RREG32(mmDMA_MACRO_RAZWI_HBW_WT_VLD)) { |
| 4198 | dev_err(hdev->dev, "Illegal write to HBW\n"); |
| 4199 | WREG32(mmDMA_MACRO_RAZWI_HBW_WT_VLD, 0); |
| 4200 | } |
| 4201 | |
| 4202 | if (RREG32(mmDMA_MACRO_RAZWI_HBW_RD_VLD)) { |
| 4203 | dev_err(hdev->dev, "Illegal read from HBW\n"); |
| 4204 | WREG32(mmDMA_MACRO_RAZWI_HBW_RD_VLD, 0); |
| 4205 | } |
| 4206 | } |
| 4207 | |
| 4208 | static void goya_print_mmu_error_info(struct hl_device *hdev) |
| 4209 | { |
| 4210 | struct goya_device *goya = hdev->asic_specific; |
| 4211 | u64 addr; |
| 4212 | u32 val; |
| 4213 | |
| 4214 | if (!(goya->hw_cap_initialized & HW_CAP_MMU)) |
| 4215 | return; |
| 4216 | |
| 4217 | val = RREG32(mmMMU_PAGE_ERROR_CAPTURE); |
| 4218 | if (val & MMU_PAGE_ERROR_CAPTURE_ENTRY_VALID_MASK) { |
| 4219 | addr = val & MMU_PAGE_ERROR_CAPTURE_VA_49_32_MASK; |
| 4220 | addr <<= 32; |
| 4221 | addr |= RREG32(mmMMU_PAGE_ERROR_CAPTURE_VA); |
| 4222 | |
| 4223 | dev_err(hdev->dev, "MMU page fault on va 0x%llx\n", addr); |
| 4224 | |
| 4225 | WREG32(mmMMU_PAGE_ERROR_CAPTURE, 0); |
Oded Gabbay | 1251f23 | 2019-02-16 00:39:18 +0200 | [diff] [blame] | 4226 | } |
| 4227 | } |
| 4228 | |
| 4229 | static void goya_print_irq_info(struct hl_device *hdev, u16 event_type) |
| 4230 | { |
Tomer Tayar | 60b7dcc | 2019-02-28 10:46:10 +0200 | [diff] [blame] | 4231 | char desc[20] = ""; |
Oded Gabbay | 1251f23 | 2019-02-16 00:39:18 +0200 | [diff] [blame] | 4232 | |
Tomer Tayar | 60b7dcc | 2019-02-28 10:46:10 +0200 | [diff] [blame] | 4233 | goya_get_event_desc(event_type, desc, sizeof(desc)); |
| 4234 | dev_err(hdev->dev, "Received H/W interrupt %d [\"%s\"]\n", |
| 4235 | event_type, desc); |
Oded Gabbay | 1251f23 | 2019-02-16 00:39:18 +0200 | [diff] [blame] | 4236 | |
Tomer Tayar | 60b7dcc | 2019-02-28 10:46:10 +0200 | [diff] [blame] | 4237 | goya_print_razwi_info(hdev); |
| 4238 | goya_print_mmu_error_info(hdev); |
Oded Gabbay | 1251f23 | 2019-02-16 00:39:18 +0200 | [diff] [blame] | 4239 | } |
| 4240 | |
Oded Gabbay | f8c8c7d | 2019-02-16 00:39:20 +0200 | [diff] [blame] | 4241 | static int goya_unmask_irq_arr(struct hl_device *hdev, u32 *irq_arr, |
| 4242 | size_t irq_arr_size) |
| 4243 | { |
| 4244 | struct armcp_unmask_irq_arr_packet *pkt; |
| 4245 | size_t total_pkt_size; |
| 4246 | long result; |
| 4247 | int rc; |
| 4248 | |
| 4249 | total_pkt_size = sizeof(struct armcp_unmask_irq_arr_packet) + |
| 4250 | irq_arr_size; |
| 4251 | |
| 4252 | /* data should be aligned to 8 bytes in order to ArmCP to copy it */ |
| 4253 | total_pkt_size = (total_pkt_size + 0x7) & ~0x7; |
| 4254 | |
| 4255 | /* total_pkt_size is casted to u16 later on */ |
| 4256 | if (total_pkt_size > USHRT_MAX) { |
| 4257 | dev_err(hdev->dev, "too many elements in IRQ array\n"); |
| 4258 | return -EINVAL; |
| 4259 | } |
| 4260 | |
| 4261 | pkt = kzalloc(total_pkt_size, GFP_KERNEL); |
| 4262 | if (!pkt) |
| 4263 | return -ENOMEM; |
| 4264 | |
Tomer Tayar | df697bc | 2019-02-28 10:46:22 +0200 | [diff] [blame] | 4265 | pkt->length = cpu_to_le32(irq_arr_size / sizeof(irq_arr[0])); |
Oded Gabbay | f8c8c7d | 2019-02-16 00:39:20 +0200 | [diff] [blame] | 4266 | memcpy(&pkt->irqs, irq_arr, irq_arr_size); |
| 4267 | |
Tomer Tayar | df697bc | 2019-02-28 10:46:22 +0200 | [diff] [blame] | 4268 | pkt->armcp_pkt.ctl = cpu_to_le32(ARMCP_PACKET_UNMASK_RAZWI_IRQ_ARRAY << |
| 4269 | ARMCP_PKT_CTL_OPCODE_SHIFT); |
Oded Gabbay | f8c8c7d | 2019-02-16 00:39:20 +0200 | [diff] [blame] | 4270 | |
Oded Gabbay | bedd144 | 2019-04-02 15:56:16 +0300 | [diff] [blame] | 4271 | rc = goya_send_cpu_message(hdev, (u32 *) pkt, total_pkt_size, |
| 4272 | HL_DEVICE_TIMEOUT_USEC, &result); |
Oded Gabbay | f8c8c7d | 2019-02-16 00:39:20 +0200 | [diff] [blame] | 4273 | |
| 4274 | if (rc) |
| 4275 | dev_err(hdev->dev, "failed to unmask IRQ array\n"); |
| 4276 | |
| 4277 | kfree(pkt); |
| 4278 | |
| 4279 | return rc; |
| 4280 | } |
| 4281 | |
| 4282 | static int goya_soft_reset_late_init(struct hl_device *hdev) |
| 4283 | { |
| 4284 | /* |
| 4285 | * Unmask all IRQs since some could have been received |
| 4286 | * during the soft reset |
| 4287 | */ |
Oded Gabbay | b24ca45 | 2019-02-24 15:50:53 +0200 | [diff] [blame] | 4288 | return goya_unmask_irq_arr(hdev, goya_all_events, |
| 4289 | sizeof(goya_all_events)); |
Oded Gabbay | f8c8c7d | 2019-02-16 00:39:20 +0200 | [diff] [blame] | 4290 | } |
| 4291 | |
Oded Gabbay | 1251f23 | 2019-02-16 00:39:18 +0200 | [diff] [blame] | 4292 | static int goya_unmask_irq(struct hl_device *hdev, u16 event_type) |
| 4293 | { |
| 4294 | struct armcp_packet pkt; |
| 4295 | long result; |
| 4296 | int rc; |
| 4297 | |
| 4298 | memset(&pkt, 0, sizeof(pkt)); |
| 4299 | |
Tomer Tayar | df697bc | 2019-02-28 10:46:22 +0200 | [diff] [blame] | 4300 | pkt.ctl = cpu_to_le32(ARMCP_PACKET_UNMASK_RAZWI_IRQ << |
| 4301 | ARMCP_PKT_CTL_OPCODE_SHIFT); |
| 4302 | pkt.value = cpu_to_le64(event_type); |
Oded Gabbay | 1251f23 | 2019-02-16 00:39:18 +0200 | [diff] [blame] | 4303 | |
Oded Gabbay | bedd144 | 2019-04-02 15:56:16 +0300 | [diff] [blame] | 4304 | rc = goya_send_cpu_message(hdev, (u32 *) &pkt, sizeof(pkt), |
Oded Gabbay | 1251f23 | 2019-02-16 00:39:18 +0200 | [diff] [blame] | 4305 | HL_DEVICE_TIMEOUT_USEC, &result); |
| 4306 | |
| 4307 | if (rc) |
| 4308 | dev_err(hdev->dev, "failed to unmask RAZWI IRQ %d", event_type); |
| 4309 | |
| 4310 | return rc; |
| 4311 | } |
| 4312 | |
| 4313 | void goya_handle_eqe(struct hl_device *hdev, struct hl_eq_entry *eq_entry) |
| 4314 | { |
Tomer Tayar | df697bc | 2019-02-28 10:46:22 +0200 | [diff] [blame] | 4315 | u32 ctl = le32_to_cpu(eq_entry->hdr.ctl); |
| 4316 | u16 event_type = ((ctl & EQ_CTL_EVENT_TYPE_MASK) |
| 4317 | >> EQ_CTL_EVENT_TYPE_SHIFT); |
Oded Gabbay | 1251f23 | 2019-02-16 00:39:18 +0200 | [diff] [blame] | 4318 | struct goya_device *goya = hdev->asic_specific; |
| 4319 | |
| 4320 | goya->events_stat[event_type]++; |
| 4321 | |
| 4322 | switch (event_type) { |
| 4323 | case GOYA_ASYNC_EVENT_ID_PCIE_IF: |
| 4324 | case GOYA_ASYNC_EVENT_ID_TPC0_ECC: |
| 4325 | case GOYA_ASYNC_EVENT_ID_TPC1_ECC: |
| 4326 | case GOYA_ASYNC_EVENT_ID_TPC2_ECC: |
| 4327 | case GOYA_ASYNC_EVENT_ID_TPC3_ECC: |
| 4328 | case GOYA_ASYNC_EVENT_ID_TPC4_ECC: |
| 4329 | case GOYA_ASYNC_EVENT_ID_TPC5_ECC: |
| 4330 | case GOYA_ASYNC_EVENT_ID_TPC6_ECC: |
| 4331 | case GOYA_ASYNC_EVENT_ID_TPC7_ECC: |
| 4332 | case GOYA_ASYNC_EVENT_ID_MME_ECC: |
| 4333 | case GOYA_ASYNC_EVENT_ID_MME_ECC_EXT: |
| 4334 | case GOYA_ASYNC_EVENT_ID_MMU_ECC: |
| 4335 | case GOYA_ASYNC_EVENT_ID_DMA_MACRO: |
| 4336 | case GOYA_ASYNC_EVENT_ID_DMA_ECC: |
| 4337 | case GOYA_ASYNC_EVENT_ID_CPU_IF_ECC: |
| 4338 | case GOYA_ASYNC_EVENT_ID_PSOC_MEM: |
| 4339 | case GOYA_ASYNC_EVENT_ID_PSOC_CORESIGHT: |
| 4340 | case GOYA_ASYNC_EVENT_ID_SRAM0 ... GOYA_ASYNC_EVENT_ID_SRAM29: |
| 4341 | case GOYA_ASYNC_EVENT_ID_GIC500: |
| 4342 | case GOYA_ASYNC_EVENT_ID_PLL0: |
| 4343 | case GOYA_ASYNC_EVENT_ID_PLL1: |
| 4344 | case GOYA_ASYNC_EVENT_ID_PLL3: |
| 4345 | case GOYA_ASYNC_EVENT_ID_PLL4: |
| 4346 | case GOYA_ASYNC_EVENT_ID_PLL5: |
| 4347 | case GOYA_ASYNC_EVENT_ID_PLL6: |
| 4348 | case GOYA_ASYNC_EVENT_ID_AXI_ECC: |
| 4349 | case GOYA_ASYNC_EVENT_ID_L2_RAM_ECC: |
| 4350 | case GOYA_ASYNC_EVENT_ID_PSOC_GPIO_05_SW_RESET: |
| 4351 | case GOYA_ASYNC_EVENT_ID_PSOC_GPIO_10_VRHOT_ICRIT: |
| 4352 | dev_err(hdev->dev, |
| 4353 | "Received H/W interrupt %d, reset the chip\n", |
| 4354 | event_type); |
Oded Gabbay | f8c8c7d | 2019-02-16 00:39:20 +0200 | [diff] [blame] | 4355 | hl_device_reset(hdev, true, false); |
Oded Gabbay | 1251f23 | 2019-02-16 00:39:18 +0200 | [diff] [blame] | 4356 | break; |
| 4357 | |
| 4358 | case GOYA_ASYNC_EVENT_ID_PCIE_DEC: |
| 4359 | case GOYA_ASYNC_EVENT_ID_TPC0_DEC: |
| 4360 | case GOYA_ASYNC_EVENT_ID_TPC1_DEC: |
| 4361 | case GOYA_ASYNC_EVENT_ID_TPC2_DEC: |
| 4362 | case GOYA_ASYNC_EVENT_ID_TPC3_DEC: |
| 4363 | case GOYA_ASYNC_EVENT_ID_TPC4_DEC: |
| 4364 | case GOYA_ASYNC_EVENT_ID_TPC5_DEC: |
| 4365 | case GOYA_ASYNC_EVENT_ID_TPC6_DEC: |
| 4366 | case GOYA_ASYNC_EVENT_ID_TPC7_DEC: |
| 4367 | case GOYA_ASYNC_EVENT_ID_MME_WACS: |
| 4368 | case GOYA_ASYNC_EVENT_ID_MME_WACSD: |
| 4369 | case GOYA_ASYNC_EVENT_ID_CPU_AXI_SPLITTER: |
| 4370 | case GOYA_ASYNC_EVENT_ID_PSOC_AXI_DEC: |
| 4371 | case GOYA_ASYNC_EVENT_ID_PSOC: |
| 4372 | case GOYA_ASYNC_EVENT_ID_TPC0_KRN_ERR: |
| 4373 | case GOYA_ASYNC_EVENT_ID_TPC1_KRN_ERR: |
| 4374 | case GOYA_ASYNC_EVENT_ID_TPC2_KRN_ERR: |
| 4375 | case GOYA_ASYNC_EVENT_ID_TPC3_KRN_ERR: |
| 4376 | case GOYA_ASYNC_EVENT_ID_TPC4_KRN_ERR: |
| 4377 | case GOYA_ASYNC_EVENT_ID_TPC5_KRN_ERR: |
| 4378 | case GOYA_ASYNC_EVENT_ID_TPC6_KRN_ERR: |
| 4379 | case GOYA_ASYNC_EVENT_ID_TPC7_KRN_ERR: |
| 4380 | case GOYA_ASYNC_EVENT_ID_TPC0_CMDQ ... GOYA_ASYNC_EVENT_ID_TPC7_QM: |
| 4381 | case GOYA_ASYNC_EVENT_ID_MME_QM: |
| 4382 | case GOYA_ASYNC_EVENT_ID_MME_CMDQ: |
| 4383 | case GOYA_ASYNC_EVENT_ID_DMA0_QM ... GOYA_ASYNC_EVENT_ID_DMA4_QM: |
| 4384 | case GOYA_ASYNC_EVENT_ID_DMA0_CH ... GOYA_ASYNC_EVENT_ID_DMA4_CH: |
| 4385 | goya_print_irq_info(hdev, event_type); |
| 4386 | goya_unmask_irq(hdev, event_type); |
| 4387 | break; |
| 4388 | |
| 4389 | case GOYA_ASYNC_EVENT_ID_TPC0_BMON_SPMU: |
| 4390 | case GOYA_ASYNC_EVENT_ID_TPC1_BMON_SPMU: |
| 4391 | case GOYA_ASYNC_EVENT_ID_TPC2_BMON_SPMU: |
| 4392 | case GOYA_ASYNC_EVENT_ID_TPC3_BMON_SPMU: |
| 4393 | case GOYA_ASYNC_EVENT_ID_TPC4_BMON_SPMU: |
| 4394 | case GOYA_ASYNC_EVENT_ID_TPC5_BMON_SPMU: |
| 4395 | case GOYA_ASYNC_EVENT_ID_TPC6_BMON_SPMU: |
| 4396 | case GOYA_ASYNC_EVENT_ID_TPC7_BMON_SPMU: |
| 4397 | case GOYA_ASYNC_EVENT_ID_DMA_BM_CH0: |
| 4398 | case GOYA_ASYNC_EVENT_ID_DMA_BM_CH1: |
| 4399 | case GOYA_ASYNC_EVENT_ID_DMA_BM_CH2: |
| 4400 | case GOYA_ASYNC_EVENT_ID_DMA_BM_CH3: |
| 4401 | case GOYA_ASYNC_EVENT_ID_DMA_BM_CH4: |
| 4402 | dev_info(hdev->dev, "Received H/W interrupt %d\n", event_type); |
| 4403 | break; |
| 4404 | |
| 4405 | default: |
| 4406 | dev_err(hdev->dev, "Received invalid H/W interrupt %d\n", |
| 4407 | event_type); |
| 4408 | break; |
| 4409 | } |
| 4410 | } |
| 4411 | |
| 4412 | void *goya_get_events_stat(struct hl_device *hdev, u32 *size) |
| 4413 | { |
| 4414 | struct goya_device *goya = hdev->asic_specific; |
| 4415 | |
| 4416 | *size = (u32) sizeof(goya->events_stat); |
| 4417 | |
| 4418 | return goya->events_stat; |
| 4419 | } |
| 4420 | |
Omer Shpigelman | 27ca384c | 2019-02-28 10:46:11 +0200 | [diff] [blame] | 4421 | static int goya_memset_device_memory(struct hl_device *hdev, u64 addr, u32 size, |
| 4422 | u64 val, bool is_dram) |
Omer Shpigelman | 0feaf86 | 2019-02-16 00:39:22 +0200 | [diff] [blame] | 4423 | { |
Omer Shpigelman | 27ca384c | 2019-02-28 10:46:11 +0200 | [diff] [blame] | 4424 | struct packet_lin_dma *lin_dma_pkt; |
Omer Shpigelman | 0feaf86 | 2019-02-16 00:39:22 +0200 | [diff] [blame] | 4425 | struct hl_cs_job *job; |
Tomer Tayar | df697bc | 2019-02-28 10:46:22 +0200 | [diff] [blame] | 4426 | u32 cb_size, ctl; |
Omer Shpigelman | 0feaf86 | 2019-02-16 00:39:22 +0200 | [diff] [blame] | 4427 | struct hl_cb *cb; |
| 4428 | int rc; |
| 4429 | |
Omer Shpigelman | 0feaf86 | 2019-02-16 00:39:22 +0200 | [diff] [blame] | 4430 | cb = hl_cb_kernel_create(hdev, PAGE_SIZE); |
| 4431 | if (!cb) |
| 4432 | return -EFAULT; |
| 4433 | |
Omer Shpigelman | 27ca384c | 2019-02-28 10:46:11 +0200 | [diff] [blame] | 4434 | lin_dma_pkt = (struct packet_lin_dma *) (uintptr_t) cb->kernel_address; |
Omer Shpigelman | 0feaf86 | 2019-02-16 00:39:22 +0200 | [diff] [blame] | 4435 | |
Omer Shpigelman | 27ca384c | 2019-02-28 10:46:11 +0200 | [diff] [blame] | 4436 | memset(lin_dma_pkt, 0, sizeof(*lin_dma_pkt)); |
| 4437 | cb_size = sizeof(*lin_dma_pkt); |
Omer Shpigelman | 0feaf86 | 2019-02-16 00:39:22 +0200 | [diff] [blame] | 4438 | |
Tomer Tayar | df697bc | 2019-02-28 10:46:22 +0200 | [diff] [blame] | 4439 | ctl = ((PACKET_LIN_DMA << GOYA_PKT_CTL_OPCODE_SHIFT) | |
| 4440 | (1 << GOYA_PKT_LIN_DMA_CTL_MEMSET_SHIFT) | |
| 4441 | (1 << GOYA_PKT_LIN_DMA_CTL_WO_SHIFT) | |
| 4442 | (1 << GOYA_PKT_CTL_RB_SHIFT) | |
| 4443 | (1 << GOYA_PKT_CTL_MB_SHIFT)); |
| 4444 | ctl |= (is_dram ? DMA_HOST_TO_DRAM : DMA_HOST_TO_SRAM) << |
| 4445 | GOYA_PKT_LIN_DMA_CTL_DMA_DIR_SHIFT; |
| 4446 | lin_dma_pkt->ctl = cpu_to_le32(ctl); |
Omer Shpigelman | 0feaf86 | 2019-02-16 00:39:22 +0200 | [diff] [blame] | 4447 | |
Tomer Tayar | df697bc | 2019-02-28 10:46:22 +0200 | [diff] [blame] | 4448 | lin_dma_pkt->src_addr = cpu_to_le64(val); |
| 4449 | lin_dma_pkt->dst_addr = cpu_to_le64(addr); |
| 4450 | lin_dma_pkt->tsize = cpu_to_le32(size); |
Omer Shpigelman | 0feaf86 | 2019-02-16 00:39:22 +0200 | [diff] [blame] | 4451 | |
| 4452 | job = hl_cs_allocate_job(hdev, true); |
| 4453 | if (!job) { |
| 4454 | dev_err(hdev->dev, "Failed to allocate a new job\n"); |
| 4455 | rc = -ENOMEM; |
| 4456 | goto release_cb; |
| 4457 | } |
| 4458 | |
| 4459 | job->id = 0; |
| 4460 | job->user_cb = cb; |
| 4461 | job->user_cb->cs_cnt++; |
| 4462 | job->user_cb_size = cb_size; |
| 4463 | job->hw_queue_id = GOYA_QUEUE_ID_DMA_0; |
Dalit Ben Zoor | 3706b47 | 2019-04-30 15:22:14 +0300 | [diff] [blame] | 4464 | job->patched_cb = job->user_cb; |
| 4465 | job->job_cb_size = job->user_cb_size + |
| 4466 | sizeof(struct packet_msg_prot) * 2; |
Omer Shpigelman | 0feaf86 | 2019-02-16 00:39:22 +0200 | [diff] [blame] | 4467 | |
Oded Gabbay | c216477 | 2019-02-16 00:39:24 +0200 | [diff] [blame] | 4468 | hl_debugfs_add_job(hdev, job); |
| 4469 | |
Omer Shpigelman | 0feaf86 | 2019-02-16 00:39:22 +0200 | [diff] [blame] | 4470 | rc = goya_send_job_on_qman0(hdev, job); |
| 4471 | |
Omer Shpigelman | 0feaf86 | 2019-02-16 00:39:22 +0200 | [diff] [blame] | 4472 | hl_cb_put(job->patched_cb); |
| 4473 | |
Oded Gabbay | c216477 | 2019-02-16 00:39:24 +0200 | [diff] [blame] | 4474 | hl_debugfs_remove_job(hdev, job); |
Omer Shpigelman | 0feaf86 | 2019-02-16 00:39:22 +0200 | [diff] [blame] | 4475 | kfree(job); |
| 4476 | cb->cs_cnt--; |
| 4477 | |
| 4478 | release_cb: |
| 4479 | hl_cb_put(cb); |
| 4480 | hl_cb_destroy(hdev, &hdev->kernel_cb_mgr, cb->id << PAGE_SHIFT); |
| 4481 | |
| 4482 | return rc; |
| 4483 | } |
| 4484 | |
Oded Gabbay | b2377e0 | 2019-04-22 11:49:06 +0300 | [diff] [blame] | 4485 | int goya_context_switch(struct hl_device *hdev, u32 asid) |
Omer Shpigelman | 27ca384c | 2019-02-28 10:46:11 +0200 | [diff] [blame] | 4486 | { |
| 4487 | struct asic_fixed_properties *prop = &hdev->asic_prop; |
| 4488 | u64 addr = prop->sram_base_address; |
| 4489 | u32 size = hdev->pldm ? 0x10000 : prop->sram_size; |
| 4490 | u64 val = 0x7777777777777777ull; |
| 4491 | int rc; |
| 4492 | |
| 4493 | rc = goya_memset_device_memory(hdev, addr, size, val, false); |
| 4494 | if (rc) { |
| 4495 | dev_err(hdev->dev, "Failed to clear SRAM in context switch\n"); |
| 4496 | return rc; |
| 4497 | } |
| 4498 | |
Dalit Ben Zoor | a691a1e | 2019-03-20 16:13:23 +0200 | [diff] [blame] | 4499 | WREG32(mmTPC_PLL_CLK_RLX_0, 0x200020); |
Omer Shpigelman | 27ca384c | 2019-02-28 10:46:11 +0200 | [diff] [blame] | 4500 | goya_mmu_prepare(hdev, asid); |
| 4501 | |
| 4502 | return 0; |
| 4503 | } |
| 4504 | |
Oded Gabbay | bedd144 | 2019-04-02 15:56:16 +0300 | [diff] [blame] | 4505 | int goya_mmu_clear_pgt_range(struct hl_device *hdev) |
Omer Shpigelman | 27ca384c | 2019-02-28 10:46:11 +0200 | [diff] [blame] | 4506 | { |
| 4507 | struct asic_fixed_properties *prop = &hdev->asic_prop; |
| 4508 | struct goya_device *goya = hdev->asic_specific; |
| 4509 | u64 addr = prop->mmu_pgt_addr; |
| 4510 | u32 size = prop->mmu_pgt_size + MMU_DRAM_DEFAULT_PAGE_SIZE + |
| 4511 | MMU_CACHE_MNG_SIZE; |
| 4512 | |
| 4513 | if (!(goya->hw_cap_initialized & HW_CAP_MMU)) |
| 4514 | return 0; |
| 4515 | |
| 4516 | return goya_memset_device_memory(hdev, addr, size, 0, true); |
| 4517 | } |
| 4518 | |
Oded Gabbay | bedd144 | 2019-04-02 15:56:16 +0300 | [diff] [blame] | 4519 | int goya_mmu_set_dram_default_page(struct hl_device *hdev) |
Omer Shpigelman | 27ca384c | 2019-02-28 10:46:11 +0200 | [diff] [blame] | 4520 | { |
| 4521 | struct goya_device *goya = hdev->asic_specific; |
| 4522 | u64 addr = hdev->asic_prop.mmu_dram_default_page_addr; |
| 4523 | u32 size = MMU_DRAM_DEFAULT_PAGE_SIZE; |
| 4524 | u64 val = 0x9999999999999999ull; |
| 4525 | |
| 4526 | if (!(goya->hw_cap_initialized & HW_CAP_MMU)) |
| 4527 | return 0; |
| 4528 | |
| 4529 | return goya_memset_device_memory(hdev, addr, size, val, true); |
| 4530 | } |
| 4531 | |
Oded Gabbay | bedd144 | 2019-04-02 15:56:16 +0300 | [diff] [blame] | 4532 | void goya_mmu_prepare(struct hl_device *hdev, u32 asid) |
Omer Shpigelman | 0feaf86 | 2019-02-16 00:39:22 +0200 | [diff] [blame] | 4533 | { |
| 4534 | struct goya_device *goya = hdev->asic_specific; |
| 4535 | int i; |
| 4536 | |
| 4537 | if (!(goya->hw_cap_initialized & HW_CAP_MMU)) |
| 4538 | return; |
| 4539 | |
| 4540 | if (asid & ~MME_QM_GLBL_SECURE_PROPS_ASID_MASK) { |
| 4541 | WARN(1, "asid %u is too big\n", asid); |
| 4542 | return; |
| 4543 | } |
| 4544 | |
| 4545 | /* zero the MMBP and ASID bits and then set the ASID */ |
Oded Gabbay | bedd144 | 2019-04-02 15:56:16 +0300 | [diff] [blame] | 4546 | for (i = 0 ; i < GOYA_MMU_REGS_NUM ; i++) |
Oded Gabbay | b2377e0 | 2019-04-22 11:49:06 +0300 | [diff] [blame] | 4547 | goya_mmu_prepare_reg(hdev, goya_mmu_regs[i], asid); |
Omer Shpigelman | 0feaf86 | 2019-02-16 00:39:22 +0200 | [diff] [blame] | 4548 | } |
| 4549 | |
| 4550 | static void goya_mmu_invalidate_cache(struct hl_device *hdev, bool is_hard) |
| 4551 | { |
| 4552 | struct goya_device *goya = hdev->asic_specific; |
| 4553 | u32 status, timeout_usec; |
| 4554 | int rc; |
| 4555 | |
| 4556 | if (!(goya->hw_cap_initialized & HW_CAP_MMU)) |
| 4557 | return; |
| 4558 | |
| 4559 | /* no need in L1 only invalidation in Goya */ |
| 4560 | if (!is_hard) |
| 4561 | return; |
| 4562 | |
| 4563 | if (hdev->pldm) |
| 4564 | timeout_usec = GOYA_PLDM_MMU_TIMEOUT_USEC; |
| 4565 | else |
| 4566 | timeout_usec = MMU_CONFIG_TIMEOUT_USEC; |
| 4567 | |
| 4568 | mutex_lock(&hdev->mmu_cache_lock); |
| 4569 | |
| 4570 | /* L0 & L1 invalidation */ |
| 4571 | WREG32(mmSTLB_INV_ALL_START, 1); |
| 4572 | |
| 4573 | rc = hl_poll_timeout( |
| 4574 | hdev, |
| 4575 | mmSTLB_INV_ALL_START, |
| 4576 | status, |
| 4577 | !status, |
| 4578 | 1000, |
| 4579 | timeout_usec); |
| 4580 | |
| 4581 | mutex_unlock(&hdev->mmu_cache_lock); |
| 4582 | |
| 4583 | if (rc) |
| 4584 | dev_notice_ratelimited(hdev->dev, |
| 4585 | "Timeout when waiting for MMU cache invalidation\n"); |
| 4586 | } |
| 4587 | |
| 4588 | static void goya_mmu_invalidate_cache_range(struct hl_device *hdev, |
| 4589 | bool is_hard, u32 asid, u64 va, u64 size) |
| 4590 | { |
| 4591 | struct goya_device *goya = hdev->asic_specific; |
| 4592 | u32 status, timeout_usec, inv_data, pi; |
| 4593 | int rc; |
| 4594 | |
| 4595 | if (!(goya->hw_cap_initialized & HW_CAP_MMU)) |
| 4596 | return; |
| 4597 | |
| 4598 | /* no need in L1 only invalidation in Goya */ |
| 4599 | if (!is_hard) |
| 4600 | return; |
| 4601 | |
| 4602 | if (hdev->pldm) |
| 4603 | timeout_usec = GOYA_PLDM_MMU_TIMEOUT_USEC; |
| 4604 | else |
| 4605 | timeout_usec = MMU_CONFIG_TIMEOUT_USEC; |
| 4606 | |
| 4607 | mutex_lock(&hdev->mmu_cache_lock); |
| 4608 | |
| 4609 | /* |
| 4610 | * TODO: currently invalidate entire L0 & L1 as in regular hard |
| 4611 | * invalidation. Need to apply invalidation of specific cache lines with |
| 4612 | * mask of ASID & VA & size. |
| 4613 | * Note that L1 with be flushed entirely in any case. |
| 4614 | */ |
| 4615 | |
| 4616 | /* L0 & L1 invalidation */ |
| 4617 | inv_data = RREG32(mmSTLB_CACHE_INV); |
| 4618 | /* PI is 8 bit */ |
| 4619 | pi = ((inv_data & STLB_CACHE_INV_PRODUCER_INDEX_MASK) + 1) & 0xFF; |
| 4620 | WREG32(mmSTLB_CACHE_INV, |
| 4621 | (inv_data & STLB_CACHE_INV_INDEX_MASK_MASK) | pi); |
| 4622 | |
| 4623 | rc = hl_poll_timeout( |
| 4624 | hdev, |
| 4625 | mmSTLB_INV_CONSUMER_INDEX, |
| 4626 | status, |
| 4627 | status == pi, |
| 4628 | 1000, |
| 4629 | timeout_usec); |
| 4630 | |
| 4631 | mutex_unlock(&hdev->mmu_cache_lock); |
| 4632 | |
| 4633 | if (rc) |
| 4634 | dev_notice_ratelimited(hdev->dev, |
| 4635 | "Timeout when waiting for MMU cache invalidation\n"); |
| 4636 | } |
| 4637 | |
Oded Gabbay | f8c8c7d | 2019-02-16 00:39:20 +0200 | [diff] [blame] | 4638 | int goya_send_heartbeat(struct hl_device *hdev) |
| 4639 | { |
| 4640 | struct goya_device *goya = hdev->asic_specific; |
Oded Gabbay | f8c8c7d | 2019-02-16 00:39:20 +0200 | [diff] [blame] | 4641 | |
| 4642 | if (!(goya->hw_cap_initialized & HW_CAP_CPU_Q)) |
| 4643 | return 0; |
| 4644 | |
Tomer Tayar | 3110c60 | 2019-03-04 10:22:09 +0200 | [diff] [blame] | 4645 | return hl_fw_send_heartbeat(hdev); |
Oded Gabbay | f8c8c7d | 2019-02-16 00:39:20 +0200 | [diff] [blame] | 4646 | } |
| 4647 | |
Tomer Tayar | 393e5b5 | 2019-03-06 14:30:26 +0200 | [diff] [blame] | 4648 | int goya_armcp_info_get(struct hl_device *hdev) |
Oded Gabbay | d91389b | 2019-02-16 00:39:19 +0200 | [diff] [blame] | 4649 | { |
| 4650 | struct goya_device *goya = hdev->asic_specific; |
| 4651 | struct asic_fixed_properties *prop = &hdev->asic_prop; |
Oded Gabbay | d91389b | 2019-02-16 00:39:19 +0200 | [diff] [blame] | 4652 | u64 dram_size; |
Oded Gabbay | d91389b | 2019-02-16 00:39:19 +0200 | [diff] [blame] | 4653 | int rc; |
| 4654 | |
| 4655 | if (!(goya->hw_cap_initialized & HW_CAP_CPU_Q)) |
| 4656 | return 0; |
| 4657 | |
Tomer Tayar | 3110c60 | 2019-03-04 10:22:09 +0200 | [diff] [blame] | 4658 | rc = hl_fw_armcp_info_get(hdev); |
| 4659 | if (rc) |
| 4660 | return rc; |
Oded Gabbay | d91389b | 2019-02-16 00:39:19 +0200 | [diff] [blame] | 4661 | |
Tomer Tayar | df697bc | 2019-02-28 10:46:22 +0200 | [diff] [blame] | 4662 | dram_size = le64_to_cpu(prop->armcp_info.dram_size); |
Oded Gabbay | d91389b | 2019-02-16 00:39:19 +0200 | [diff] [blame] | 4663 | if (dram_size) { |
| 4664 | if ((!is_power_of_2(dram_size)) || |
| 4665 | (dram_size < DRAM_PHYS_DEFAULT_SIZE)) { |
| 4666 | dev_err(hdev->dev, |
| 4667 | "F/W reported invalid DRAM size %llu. Trying to use default size\n", |
| 4668 | dram_size); |
| 4669 | dram_size = DRAM_PHYS_DEFAULT_SIZE; |
| 4670 | } |
| 4671 | |
| 4672 | prop->dram_size = dram_size; |
| 4673 | prop->dram_end_address = prop->dram_base_address + dram_size; |
| 4674 | } |
| 4675 | |
Tomer Tayar | 3110c60 | 2019-03-04 10:22:09 +0200 | [diff] [blame] | 4676 | return 0; |
Oded Gabbay | d91389b | 2019-02-16 00:39:19 +0200 | [diff] [blame] | 4677 | } |
| 4678 | |
Tomer Tayar | c811f7b | 2019-03-07 14:26:02 +0200 | [diff] [blame] | 4679 | static bool goya_is_device_idle(struct hl_device *hdev, char *buf, size_t size) |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 4680 | { |
| 4681 | u64 offset, dma_qm_reg, tpc_qm_reg, tpc_cmdq_reg, tpc_cfg_reg; |
| 4682 | int i; |
| 4683 | |
| 4684 | offset = mmDMA_QM_1_GLBL_STS0 - mmDMA_QM_0_GLBL_STS0; |
| 4685 | |
| 4686 | for (i = 0 ; i < DMA_MAX_NUM ; i++) { |
| 4687 | dma_qm_reg = mmDMA_QM_0_GLBL_STS0 + i * offset; |
| 4688 | |
| 4689 | if ((RREG32(dma_qm_reg) & DMA_QM_IDLE_MASK) != |
| 4690 | DMA_QM_IDLE_MASK) |
Tomer Tayar | c811f7b | 2019-03-07 14:26:02 +0200 | [diff] [blame] | 4691 | return HL_ENG_BUSY(buf, size, "DMA%d_QM", i); |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 4692 | } |
| 4693 | |
| 4694 | offset = mmTPC1_QM_GLBL_STS0 - mmTPC0_QM_GLBL_STS0; |
| 4695 | |
| 4696 | for (i = 0 ; i < TPC_MAX_NUM ; i++) { |
| 4697 | tpc_qm_reg = mmTPC0_QM_GLBL_STS0 + i * offset; |
| 4698 | tpc_cmdq_reg = mmTPC0_CMDQ_GLBL_STS0 + i * offset; |
| 4699 | tpc_cfg_reg = mmTPC0_CFG_STATUS + i * offset; |
| 4700 | |
| 4701 | if ((RREG32(tpc_qm_reg) & TPC_QM_IDLE_MASK) != |
| 4702 | TPC_QM_IDLE_MASK) |
Tomer Tayar | c811f7b | 2019-03-07 14:26:02 +0200 | [diff] [blame] | 4703 | return HL_ENG_BUSY(buf, size, "TPC%d_QM", i); |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 4704 | |
| 4705 | if ((RREG32(tpc_cmdq_reg) & TPC_CMDQ_IDLE_MASK) != |
| 4706 | TPC_CMDQ_IDLE_MASK) |
Tomer Tayar | c811f7b | 2019-03-07 14:26:02 +0200 | [diff] [blame] | 4707 | return HL_ENG_BUSY(buf, size, "TPC%d_CMDQ", i); |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 4708 | |
| 4709 | if ((RREG32(tpc_cfg_reg) & TPC_CFG_IDLE_MASK) != |
| 4710 | TPC_CFG_IDLE_MASK) |
Tomer Tayar | c811f7b | 2019-03-07 14:26:02 +0200 | [diff] [blame] | 4711 | return HL_ENG_BUSY(buf, size, "TPC%d_CFG", i); |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 4712 | } |
| 4713 | |
| 4714 | if ((RREG32(mmMME_QM_GLBL_STS0) & MME_QM_IDLE_MASK) != |
| 4715 | MME_QM_IDLE_MASK) |
Tomer Tayar | c811f7b | 2019-03-07 14:26:02 +0200 | [diff] [blame] | 4716 | return HL_ENG_BUSY(buf, size, "MME_QM"); |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 4717 | |
| 4718 | if ((RREG32(mmMME_CMDQ_GLBL_STS0) & MME_CMDQ_IDLE_MASK) != |
| 4719 | MME_CMDQ_IDLE_MASK) |
Tomer Tayar | c811f7b | 2019-03-07 14:26:02 +0200 | [diff] [blame] | 4720 | return HL_ENG_BUSY(buf, size, "MME_CMDQ"); |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 4721 | |
| 4722 | if ((RREG32(mmMME_ARCH_STATUS) & MME_ARCH_IDLE_MASK) != |
| 4723 | MME_ARCH_IDLE_MASK) |
Tomer Tayar | c811f7b | 2019-03-07 14:26:02 +0200 | [diff] [blame] | 4724 | return HL_ENG_BUSY(buf, size, "MME_ARCH"); |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 4725 | |
| 4726 | if (RREG32(mmMME_SHADOW_0_STATUS) & MME_SHADOW_IDLE_MASK) |
Tomer Tayar | c811f7b | 2019-03-07 14:26:02 +0200 | [diff] [blame] | 4727 | return HL_ENG_BUSY(buf, size, "MME"); |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 4728 | |
| 4729 | return true; |
| 4730 | } |
| 4731 | |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 4732 | static void goya_hw_queues_lock(struct hl_device *hdev) |
| 4733 | { |
| 4734 | struct goya_device *goya = hdev->asic_specific; |
| 4735 | |
| 4736 | spin_lock(&goya->hw_queues_lock); |
| 4737 | } |
| 4738 | |
| 4739 | static void goya_hw_queues_unlock(struct hl_device *hdev) |
| 4740 | { |
| 4741 | struct goya_device *goya = hdev->asic_specific; |
| 4742 | |
| 4743 | spin_unlock(&goya->hw_queues_lock); |
| 4744 | } |
| 4745 | |
Oded Gabbay | d8dd7b0 | 2019-02-16 00:39:23 +0200 | [diff] [blame] | 4746 | static u32 goya_get_pci_id(struct hl_device *hdev) |
| 4747 | { |
| 4748 | return hdev->pdev->device; |
| 4749 | } |
| 4750 | |
Oded Gabbay | 5e6e023 | 2019-02-27 12:15:16 +0200 | [diff] [blame] | 4751 | static int goya_get_eeprom_data(struct hl_device *hdev, void *data, |
| 4752 | size_t max_size) |
Oded Gabbay | d91389b | 2019-02-16 00:39:19 +0200 | [diff] [blame] | 4753 | { |
| 4754 | struct goya_device *goya = hdev->asic_specific; |
Oded Gabbay | d91389b | 2019-02-16 00:39:19 +0200 | [diff] [blame] | 4755 | |
| 4756 | if (!(goya->hw_cap_initialized & HW_CAP_CPU_Q)) |
| 4757 | return 0; |
| 4758 | |
Tomer Tayar | 3110c60 | 2019-03-04 10:22:09 +0200 | [diff] [blame] | 4759 | return hl_fw_get_eeprom_data(hdev, data, max_size); |
Oded Gabbay | d91389b | 2019-02-16 00:39:19 +0200 | [diff] [blame] | 4760 | } |
| 4761 | |
Oded Gabbay | f8c8c7d | 2019-02-16 00:39:20 +0200 | [diff] [blame] | 4762 | static enum hl_device_hw_state goya_get_hw_state(struct hl_device *hdev) |
| 4763 | { |
| 4764 | return RREG32(mmPSOC_GLOBAL_CONF_APP_STATUS); |
| 4765 | } |
| 4766 | |
Oded Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 4767 | static const struct hl_asic_funcs goya_funcs = { |
| 4768 | .early_init = goya_early_init, |
| 4769 | .early_fini = goya_early_fini, |
Oded Gabbay | d91389b | 2019-02-16 00:39:19 +0200 | [diff] [blame] | 4770 | .late_init = goya_late_init, |
| 4771 | .late_fini = goya_late_fini, |
Oded Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 4772 | .sw_init = goya_sw_init, |
| 4773 | .sw_fini = goya_sw_fini, |
Oded Gabbay | 839c480 | 2019-02-16 00:39:16 +0200 | [diff] [blame] | 4774 | .hw_init = goya_hw_init, |
| 4775 | .hw_fini = goya_hw_fini, |
Oded Gabbay | 1251f23 | 2019-02-16 00:39:18 +0200 | [diff] [blame] | 4776 | .halt_engines = goya_halt_engines, |
Oded Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 4777 | .suspend = goya_suspend, |
| 4778 | .resume = goya_resume, |
Oded Gabbay | be5d926 | 2019-02-16 00:39:15 +0200 | [diff] [blame] | 4779 | .cb_mmap = goya_cb_mmap, |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 4780 | .ring_doorbell = goya_ring_doorbell, |
| 4781 | .flush_pq_write = goya_flush_pq_write, |
Oded Gabbay | d9c3aa8 | 2019-05-01 11:47:04 +0300 | [diff] [blame] | 4782 | .asic_dma_alloc_coherent = goya_dma_alloc_coherent, |
| 4783 | .asic_dma_free_coherent = goya_dma_free_coherent, |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 4784 | .get_int_queue_base = goya_get_int_queue_base, |
| 4785 | .test_queues = goya_test_queues, |
Oded Gabbay | d9c3aa8 | 2019-05-01 11:47:04 +0300 | [diff] [blame] | 4786 | .asic_dma_pool_zalloc = goya_dma_pool_zalloc, |
| 4787 | .asic_dma_pool_free = goya_dma_pool_free, |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 4788 | .cpu_accessible_dma_pool_alloc = goya_cpu_accessible_dma_pool_alloc, |
| 4789 | .cpu_accessible_dma_pool_free = goya_cpu_accessible_dma_pool_free, |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 4790 | .hl_dma_unmap_sg = goya_dma_unmap_sg, |
| 4791 | .cs_parser = goya_cs_parser, |
| 4792 | .asic_dma_map_sg = goya_dma_map_sg, |
| 4793 | .get_dma_desc_list_size = goya_get_dma_desc_list_size, |
| 4794 | .add_end_of_cb_packets = goya_add_end_of_cb_packets, |
Oded Gabbay | 1251f23 | 2019-02-16 00:39:18 +0200 | [diff] [blame] | 4795 | .update_eq_ci = goya_update_eq_ci, |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 4796 | .context_switch = goya_context_switch, |
| 4797 | .restore_phase_topology = goya_restore_phase_topology, |
Oded Gabbay | c216477 | 2019-02-16 00:39:24 +0200 | [diff] [blame] | 4798 | .debugfs_read32 = goya_debugfs_read32, |
| 4799 | .debugfs_write32 = goya_debugfs_write32, |
Oded Gabbay | d91389b | 2019-02-16 00:39:19 +0200 | [diff] [blame] | 4800 | .add_device_attr = goya_add_device_attr, |
Oded Gabbay | 1251f23 | 2019-02-16 00:39:18 +0200 | [diff] [blame] | 4801 | .handle_eqe = goya_handle_eqe, |
Oded Gabbay | d91389b | 2019-02-16 00:39:19 +0200 | [diff] [blame] | 4802 | .set_pll_profile = goya_set_pll_profile, |
Oded Gabbay | 1251f23 | 2019-02-16 00:39:18 +0200 | [diff] [blame] | 4803 | .get_events_stat = goya_get_events_stat, |
Omer Shpigelman | 0feaf86 | 2019-02-16 00:39:22 +0200 | [diff] [blame] | 4804 | .read_pte = goya_read_pte, |
| 4805 | .write_pte = goya_write_pte, |
| 4806 | .mmu_invalidate_cache = goya_mmu_invalidate_cache, |
| 4807 | .mmu_invalidate_cache_range = goya_mmu_invalidate_cache_range, |
Oded Gabbay | f8c8c7d | 2019-02-16 00:39:20 +0200 | [diff] [blame] | 4808 | .send_heartbeat = goya_send_heartbeat, |
Omer Shpigelman | 315bc05 | 2019-04-01 22:31:22 +0300 | [diff] [blame] | 4809 | .debug_coresight = goya_debug_coresight, |
Oded Gabbay | eff6f4a | 2019-02-16 00:39:21 +0200 | [diff] [blame] | 4810 | .is_device_idle = goya_is_device_idle, |
Oded Gabbay | f8c8c7d | 2019-02-16 00:39:20 +0200 | [diff] [blame] | 4811 | .soft_reset_late_init = goya_soft_reset_late_init, |
Oded Gabbay | 9494a8d | 2019-02-16 00:39:17 +0200 | [diff] [blame] | 4812 | .hw_queues_lock = goya_hw_queues_lock, |
| 4813 | .hw_queues_unlock = goya_hw_queues_unlock, |
Oded Gabbay | d8dd7b0 | 2019-02-16 00:39:23 +0200 | [diff] [blame] | 4814 | .get_pci_id = goya_get_pci_id, |
Oded Gabbay | d91389b | 2019-02-16 00:39:19 +0200 | [diff] [blame] | 4815 | .get_eeprom_data = goya_get_eeprom_data, |
Oded Gabbay | f8c8c7d | 2019-02-16 00:39:20 +0200 | [diff] [blame] | 4816 | .send_cpu_message = goya_send_cpu_message, |
Tomer Tayar | b6f897d | 2019-03-05 16:48:42 +0200 | [diff] [blame] | 4817 | .get_hw_state = goya_get_hw_state, |
| 4818 | .pci_bars_map = goya_pci_bars_map, |
| 4819 | .set_dram_bar_base = goya_set_ddr_bar_base, |
Oded Gabbay | b2377e0 | 2019-04-22 11:49:06 +0300 | [diff] [blame] | 4820 | .init_iatu = goya_init_iatu, |
| 4821 | .rreg = hl_rreg, |
| 4822 | .wreg = hl_wreg |
Oded Gabbay | 99b9d7b | 2019-02-16 00:39:13 +0200 | [diff] [blame] | 4823 | }; |
| 4824 | |
| 4825 | /* |
| 4826 | * goya_set_asic_funcs - set Goya function pointers |
| 4827 | * |
| 4828 | * @*hdev: pointer to hl_device structure |
| 4829 | * |
| 4830 | */ |
| 4831 | void goya_set_asic_funcs(struct hl_device *hdev) |
| 4832 | { |
| 4833 | hdev->asic_funcs = &goya_funcs; |
| 4834 | } |