Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

at v5.12 1123 lines 34 kB view raw
1/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note 2 * 3 * Copyright 2016-2020 HabanaLabs, Ltd. 4 * All Rights Reserved. 5 * 6 */ 7 8#ifndef HABANALABS_H_ 9#define HABANALABS_H_ 10 11#include <linux/types.h> 12#include <linux/ioctl.h> 13 14/* 15 * Defines that are asic-specific but constitutes as ABI between kernel driver 16 * and userspace 17 */ 18#define GOYA_KMD_SRAM_RESERVED_SIZE_FROM_START 0x8000 /* 32KB */ 19#define GAUDI_DRIVER_SRAM_RESERVED_SIZE_FROM_START 0x80 /* 128 bytes */ 20 21/* 22 * 128 SOBs reserved for collective wait 23 * 16 SOBs reserved for sync stream 24 */ 25#define GAUDI_FIRST_AVAILABLE_W_S_SYNC_OBJECT 144 26 27/* 28 * 64 monitors reserved for collective wait 29 * 8 monitors reserved for sync stream 30 */ 31#define GAUDI_FIRST_AVAILABLE_W_S_MONITOR 72 32 33/* 34 * Goya queue Numbering 35 * 36 * The external queues (PCI DMA channels) MUST be before the internal queues 37 * and each group (PCI DMA channels and internal) must be contiguous inside 38 * itself but there can be a gap between the two groups (although not 39 * recommended) 40 */ 41 42enum goya_queue_id { 43 GOYA_QUEUE_ID_DMA_0 = 0, 44 GOYA_QUEUE_ID_DMA_1 = 1, 45 GOYA_QUEUE_ID_DMA_2 = 2, 46 GOYA_QUEUE_ID_DMA_3 = 3, 47 GOYA_QUEUE_ID_DMA_4 = 4, 48 GOYA_QUEUE_ID_CPU_PQ = 5, 49 GOYA_QUEUE_ID_MME = 6, /* Internal queues start here */ 50 GOYA_QUEUE_ID_TPC0 = 7, 51 GOYA_QUEUE_ID_TPC1 = 8, 52 GOYA_QUEUE_ID_TPC2 = 9, 53 GOYA_QUEUE_ID_TPC3 = 10, 54 GOYA_QUEUE_ID_TPC4 = 11, 55 GOYA_QUEUE_ID_TPC5 = 12, 56 GOYA_QUEUE_ID_TPC6 = 13, 57 GOYA_QUEUE_ID_TPC7 = 14, 58 GOYA_QUEUE_ID_SIZE 59}; 60 61/* 62 * Gaudi queue Numbering 63 * External queues (PCI DMA channels) are DMA_0_*, DMA_1_* and DMA_5_*. 64 * Except one CPU queue, all the rest are internal queues. 65 */ 66 67enum gaudi_queue_id { 68 GAUDI_QUEUE_ID_DMA_0_0 = 0, /* external */ 69 GAUDI_QUEUE_ID_DMA_0_1 = 1, /* external */ 70 GAUDI_QUEUE_ID_DMA_0_2 = 2, /* external */ 71 GAUDI_QUEUE_ID_DMA_0_3 = 3, /* external */ 72 GAUDI_QUEUE_ID_DMA_1_0 = 4, /* external */ 73 GAUDI_QUEUE_ID_DMA_1_1 = 5, /* external */ 74 GAUDI_QUEUE_ID_DMA_1_2 = 6, /* external */ 75 GAUDI_QUEUE_ID_DMA_1_3 = 7, /* external */ 76 GAUDI_QUEUE_ID_CPU_PQ = 8, /* CPU */ 77 GAUDI_QUEUE_ID_DMA_2_0 = 9, /* internal */ 78 GAUDI_QUEUE_ID_DMA_2_1 = 10, /* internal */ 79 GAUDI_QUEUE_ID_DMA_2_2 = 11, /* internal */ 80 GAUDI_QUEUE_ID_DMA_2_3 = 12, /* internal */ 81 GAUDI_QUEUE_ID_DMA_3_0 = 13, /* internal */ 82 GAUDI_QUEUE_ID_DMA_3_1 = 14, /* internal */ 83 GAUDI_QUEUE_ID_DMA_3_2 = 15, /* internal */ 84 GAUDI_QUEUE_ID_DMA_3_3 = 16, /* internal */ 85 GAUDI_QUEUE_ID_DMA_4_0 = 17, /* internal */ 86 GAUDI_QUEUE_ID_DMA_4_1 = 18, /* internal */ 87 GAUDI_QUEUE_ID_DMA_4_2 = 19, /* internal */ 88 GAUDI_QUEUE_ID_DMA_4_3 = 20, /* internal */ 89 GAUDI_QUEUE_ID_DMA_5_0 = 21, /* internal */ 90 GAUDI_QUEUE_ID_DMA_5_1 = 22, /* internal */ 91 GAUDI_QUEUE_ID_DMA_5_2 = 23, /* internal */ 92 GAUDI_QUEUE_ID_DMA_5_3 = 24, /* internal */ 93 GAUDI_QUEUE_ID_DMA_6_0 = 25, /* internal */ 94 GAUDI_QUEUE_ID_DMA_6_1 = 26, /* internal */ 95 GAUDI_QUEUE_ID_DMA_6_2 = 27, /* internal */ 96 GAUDI_QUEUE_ID_DMA_6_3 = 28, /* internal */ 97 GAUDI_QUEUE_ID_DMA_7_0 = 29, /* internal */ 98 GAUDI_QUEUE_ID_DMA_7_1 = 30, /* internal */ 99 GAUDI_QUEUE_ID_DMA_7_2 = 31, /* internal */ 100 GAUDI_QUEUE_ID_DMA_7_3 = 32, /* internal */ 101 GAUDI_QUEUE_ID_MME_0_0 = 33, /* internal */ 102 GAUDI_QUEUE_ID_MME_0_1 = 34, /* internal */ 103 GAUDI_QUEUE_ID_MME_0_2 = 35, /* internal */ 104 GAUDI_QUEUE_ID_MME_0_3 = 36, /* internal */ 105 GAUDI_QUEUE_ID_MME_1_0 = 37, /* internal */ 106 GAUDI_QUEUE_ID_MME_1_1 = 38, /* internal */ 107 GAUDI_QUEUE_ID_MME_1_2 = 39, /* internal */ 108 GAUDI_QUEUE_ID_MME_1_3 = 40, /* internal */ 109 GAUDI_QUEUE_ID_TPC_0_0 = 41, /* internal */ 110 GAUDI_QUEUE_ID_TPC_0_1 = 42, /* internal */ 111 GAUDI_QUEUE_ID_TPC_0_2 = 43, /* internal */ 112 GAUDI_QUEUE_ID_TPC_0_3 = 44, /* internal */ 113 GAUDI_QUEUE_ID_TPC_1_0 = 45, /* internal */ 114 GAUDI_QUEUE_ID_TPC_1_1 = 46, /* internal */ 115 GAUDI_QUEUE_ID_TPC_1_2 = 47, /* internal */ 116 GAUDI_QUEUE_ID_TPC_1_3 = 48, /* internal */ 117 GAUDI_QUEUE_ID_TPC_2_0 = 49, /* internal */ 118 GAUDI_QUEUE_ID_TPC_2_1 = 50, /* internal */ 119 GAUDI_QUEUE_ID_TPC_2_2 = 51, /* internal */ 120 GAUDI_QUEUE_ID_TPC_2_3 = 52, /* internal */ 121 GAUDI_QUEUE_ID_TPC_3_0 = 53, /* internal */ 122 GAUDI_QUEUE_ID_TPC_3_1 = 54, /* internal */ 123 GAUDI_QUEUE_ID_TPC_3_2 = 55, /* internal */ 124 GAUDI_QUEUE_ID_TPC_3_3 = 56, /* internal */ 125 GAUDI_QUEUE_ID_TPC_4_0 = 57, /* internal */ 126 GAUDI_QUEUE_ID_TPC_4_1 = 58, /* internal */ 127 GAUDI_QUEUE_ID_TPC_4_2 = 59, /* internal */ 128 GAUDI_QUEUE_ID_TPC_4_3 = 60, /* internal */ 129 GAUDI_QUEUE_ID_TPC_5_0 = 61, /* internal */ 130 GAUDI_QUEUE_ID_TPC_5_1 = 62, /* internal */ 131 GAUDI_QUEUE_ID_TPC_5_2 = 63, /* internal */ 132 GAUDI_QUEUE_ID_TPC_5_3 = 64, /* internal */ 133 GAUDI_QUEUE_ID_TPC_6_0 = 65, /* internal */ 134 GAUDI_QUEUE_ID_TPC_6_1 = 66, /* internal */ 135 GAUDI_QUEUE_ID_TPC_6_2 = 67, /* internal */ 136 GAUDI_QUEUE_ID_TPC_6_3 = 68, /* internal */ 137 GAUDI_QUEUE_ID_TPC_7_0 = 69, /* internal */ 138 GAUDI_QUEUE_ID_TPC_7_1 = 70, /* internal */ 139 GAUDI_QUEUE_ID_TPC_7_2 = 71, /* internal */ 140 GAUDI_QUEUE_ID_TPC_7_3 = 72, /* internal */ 141 GAUDI_QUEUE_ID_NIC_0_0 = 73, /* internal */ 142 GAUDI_QUEUE_ID_NIC_0_1 = 74, /* internal */ 143 GAUDI_QUEUE_ID_NIC_0_2 = 75, /* internal */ 144 GAUDI_QUEUE_ID_NIC_0_3 = 76, /* internal */ 145 GAUDI_QUEUE_ID_NIC_1_0 = 77, /* internal */ 146 GAUDI_QUEUE_ID_NIC_1_1 = 78, /* internal */ 147 GAUDI_QUEUE_ID_NIC_1_2 = 79, /* internal */ 148 GAUDI_QUEUE_ID_NIC_1_3 = 80, /* internal */ 149 GAUDI_QUEUE_ID_NIC_2_0 = 81, /* internal */ 150 GAUDI_QUEUE_ID_NIC_2_1 = 82, /* internal */ 151 GAUDI_QUEUE_ID_NIC_2_2 = 83, /* internal */ 152 GAUDI_QUEUE_ID_NIC_2_3 = 84, /* internal */ 153 GAUDI_QUEUE_ID_NIC_3_0 = 85, /* internal */ 154 GAUDI_QUEUE_ID_NIC_3_1 = 86, /* internal */ 155 GAUDI_QUEUE_ID_NIC_3_2 = 87, /* internal */ 156 GAUDI_QUEUE_ID_NIC_3_3 = 88, /* internal */ 157 GAUDI_QUEUE_ID_NIC_4_0 = 89, /* internal */ 158 GAUDI_QUEUE_ID_NIC_4_1 = 90, /* internal */ 159 GAUDI_QUEUE_ID_NIC_4_2 = 91, /* internal */ 160 GAUDI_QUEUE_ID_NIC_4_3 = 92, /* internal */ 161 GAUDI_QUEUE_ID_NIC_5_0 = 93, /* internal */ 162 GAUDI_QUEUE_ID_NIC_5_1 = 94, /* internal */ 163 GAUDI_QUEUE_ID_NIC_5_2 = 95, /* internal */ 164 GAUDI_QUEUE_ID_NIC_5_3 = 96, /* internal */ 165 GAUDI_QUEUE_ID_NIC_6_0 = 97, /* internal */ 166 GAUDI_QUEUE_ID_NIC_6_1 = 98, /* internal */ 167 GAUDI_QUEUE_ID_NIC_6_2 = 99, /* internal */ 168 GAUDI_QUEUE_ID_NIC_6_3 = 100, /* internal */ 169 GAUDI_QUEUE_ID_NIC_7_0 = 101, /* internal */ 170 GAUDI_QUEUE_ID_NIC_7_1 = 102, /* internal */ 171 GAUDI_QUEUE_ID_NIC_7_2 = 103, /* internal */ 172 GAUDI_QUEUE_ID_NIC_7_3 = 104, /* internal */ 173 GAUDI_QUEUE_ID_NIC_8_0 = 105, /* internal */ 174 GAUDI_QUEUE_ID_NIC_8_1 = 106, /* internal */ 175 GAUDI_QUEUE_ID_NIC_8_2 = 107, /* internal */ 176 GAUDI_QUEUE_ID_NIC_8_3 = 108, /* internal */ 177 GAUDI_QUEUE_ID_NIC_9_0 = 109, /* internal */ 178 GAUDI_QUEUE_ID_NIC_9_1 = 110, /* internal */ 179 GAUDI_QUEUE_ID_NIC_9_2 = 111, /* internal */ 180 GAUDI_QUEUE_ID_NIC_9_3 = 112, /* internal */ 181 GAUDI_QUEUE_ID_SIZE 182}; 183 184/* 185 * Engine Numbering 186 * 187 * Used in the "busy_engines_mask" field in `struct hl_info_hw_idle' 188 */ 189 190enum goya_engine_id { 191 GOYA_ENGINE_ID_DMA_0 = 0, 192 GOYA_ENGINE_ID_DMA_1, 193 GOYA_ENGINE_ID_DMA_2, 194 GOYA_ENGINE_ID_DMA_3, 195 GOYA_ENGINE_ID_DMA_4, 196 GOYA_ENGINE_ID_MME_0, 197 GOYA_ENGINE_ID_TPC_0, 198 GOYA_ENGINE_ID_TPC_1, 199 GOYA_ENGINE_ID_TPC_2, 200 GOYA_ENGINE_ID_TPC_3, 201 GOYA_ENGINE_ID_TPC_4, 202 GOYA_ENGINE_ID_TPC_5, 203 GOYA_ENGINE_ID_TPC_6, 204 GOYA_ENGINE_ID_TPC_7, 205 GOYA_ENGINE_ID_SIZE 206}; 207 208enum gaudi_engine_id { 209 GAUDI_ENGINE_ID_DMA_0 = 0, 210 GAUDI_ENGINE_ID_DMA_1, 211 GAUDI_ENGINE_ID_DMA_2, 212 GAUDI_ENGINE_ID_DMA_3, 213 GAUDI_ENGINE_ID_DMA_4, 214 GAUDI_ENGINE_ID_DMA_5, 215 GAUDI_ENGINE_ID_DMA_6, 216 GAUDI_ENGINE_ID_DMA_7, 217 GAUDI_ENGINE_ID_MME_0, 218 GAUDI_ENGINE_ID_MME_1, 219 GAUDI_ENGINE_ID_MME_2, 220 GAUDI_ENGINE_ID_MME_3, 221 GAUDI_ENGINE_ID_TPC_0, 222 GAUDI_ENGINE_ID_TPC_1, 223 GAUDI_ENGINE_ID_TPC_2, 224 GAUDI_ENGINE_ID_TPC_3, 225 GAUDI_ENGINE_ID_TPC_4, 226 GAUDI_ENGINE_ID_TPC_5, 227 GAUDI_ENGINE_ID_TPC_6, 228 GAUDI_ENGINE_ID_TPC_7, 229 GAUDI_ENGINE_ID_NIC_0, 230 GAUDI_ENGINE_ID_NIC_1, 231 GAUDI_ENGINE_ID_NIC_2, 232 GAUDI_ENGINE_ID_NIC_3, 233 GAUDI_ENGINE_ID_NIC_4, 234 GAUDI_ENGINE_ID_NIC_5, 235 GAUDI_ENGINE_ID_NIC_6, 236 GAUDI_ENGINE_ID_NIC_7, 237 GAUDI_ENGINE_ID_NIC_8, 238 GAUDI_ENGINE_ID_NIC_9, 239 GAUDI_ENGINE_ID_SIZE 240}; 241 242enum hl_device_status { 243 HL_DEVICE_STATUS_OPERATIONAL, 244 HL_DEVICE_STATUS_IN_RESET, 245 HL_DEVICE_STATUS_MALFUNCTION, 246 HL_DEVICE_STATUS_NEEDS_RESET 247}; 248 249/* Opcode for management ioctl 250 * 251 * HW_IP_INFO - Receive information about different IP blocks in the 252 * device. 253 * HL_INFO_HW_EVENTS - Receive an array describing how many times each event 254 * occurred since the last hard reset. 255 * HL_INFO_DRAM_USAGE - Retrieve the dram usage inside the device and of the 256 * specific context. This is relevant only for devices 257 * where the dram is managed by the kernel driver 258 * HL_INFO_HW_IDLE - Retrieve information about the idle status of each 259 * internal engine. 260 * HL_INFO_DEVICE_STATUS - Retrieve the device's status. This opcode doesn't 261 * require an open context. 262 * HL_INFO_DEVICE_UTILIZATION - Retrieve the total utilization of the device 263 * over the last period specified by the user. 264 * The period can be between 100ms to 1s, in 265 * resolution of 100ms. The return value is a 266 * percentage of the utilization rate. 267 * HL_INFO_HW_EVENTS_AGGREGATE - Receive an array describing how many times each 268 * event occurred since the driver was loaded. 269 * HL_INFO_CLK_RATE - Retrieve the current and maximum clock rate 270 * of the device in MHz. The maximum clock rate is 271 * configurable via sysfs parameter 272 * HL_INFO_RESET_COUNT - Retrieve the counts of the soft and hard reset 273 * operations performed on the device since the last 274 * time the driver was loaded. 275 * HL_INFO_TIME_SYNC - Retrieve the device's time alongside the host's time 276 * for synchronization. 277 * HL_INFO_CS_COUNTERS - Retrieve command submission counters 278 * HL_INFO_PCI_COUNTERS - Retrieve PCI counters 279 * HL_INFO_CLK_THROTTLE_REASON - Retrieve clock throttling reason 280 * HL_INFO_SYNC_MANAGER - Retrieve sync manager info per dcore 281 * HL_INFO_TOTAL_ENERGY - Retrieve total energy consumption 282 * HL_INFO_PLL_FREQUENCY - Retrieve PLL frequency 283 */ 284#define HL_INFO_HW_IP_INFO 0 285#define HL_INFO_HW_EVENTS 1 286#define HL_INFO_DRAM_USAGE 2 287#define HL_INFO_HW_IDLE 3 288#define HL_INFO_DEVICE_STATUS 4 289#define HL_INFO_DEVICE_UTILIZATION 6 290#define HL_INFO_HW_EVENTS_AGGREGATE 7 291#define HL_INFO_CLK_RATE 8 292#define HL_INFO_RESET_COUNT 9 293#define HL_INFO_TIME_SYNC 10 294#define HL_INFO_CS_COUNTERS 11 295#define HL_INFO_PCI_COUNTERS 12 296#define HL_INFO_CLK_THROTTLE_REASON 13 297#define HL_INFO_SYNC_MANAGER 14 298#define HL_INFO_TOTAL_ENERGY 15 299#define HL_INFO_PLL_FREQUENCY 16 300 301#define HL_INFO_VERSION_MAX_LEN 128 302#define HL_INFO_CARD_NAME_MAX_LEN 16 303 304struct hl_info_hw_ip_info { 305 __u64 sram_base_address; 306 __u64 dram_base_address; 307 __u64 dram_size; 308 __u32 sram_size; 309 __u32 num_of_events; 310 __u32 device_id; /* PCI Device ID */ 311 __u32 module_id; /* For mezzanine cards in servers (From OCP spec.) */ 312 __u32 reserved; 313 __u16 first_available_interrupt_id; 314 __u16 reserved2; 315 __u32 cpld_version; 316 __u32 psoc_pci_pll_nr; 317 __u32 psoc_pci_pll_nf; 318 __u32 psoc_pci_pll_od; 319 __u32 psoc_pci_pll_div_factor; 320 __u8 tpc_enabled_mask; 321 __u8 dram_enabled; 322 __u8 pad[2]; 323 __u8 cpucp_version[HL_INFO_VERSION_MAX_LEN]; 324 __u8 card_name[HL_INFO_CARD_NAME_MAX_LEN]; 325 __u64 reserved3; 326 __u64 dram_page_size; 327}; 328 329struct hl_info_dram_usage { 330 __u64 dram_free_mem; 331 __u64 ctx_dram_mem; 332}; 333 334#define HL_BUSY_ENGINES_MASK_EXT_SIZE 2 335 336struct hl_info_hw_idle { 337 __u32 is_idle; 338 /* 339 * Bitmask of busy engines. 340 * Bits definition is according to `enum <chip>_enging_id'. 341 */ 342 __u32 busy_engines_mask; 343 344 /* 345 * Extended Bitmask of busy engines. 346 * Bits definition is according to `enum <chip>_enging_id'. 347 */ 348 __u64 busy_engines_mask_ext[HL_BUSY_ENGINES_MASK_EXT_SIZE]; 349}; 350 351struct hl_info_device_status { 352 __u32 status; 353 __u32 pad; 354}; 355 356struct hl_info_device_utilization { 357 __u32 utilization; 358 __u32 pad; 359}; 360 361struct hl_info_clk_rate { 362 __u32 cur_clk_rate_mhz; 363 __u32 max_clk_rate_mhz; 364}; 365 366struct hl_info_reset_count { 367 __u32 hard_reset_cnt; 368 __u32 soft_reset_cnt; 369}; 370 371struct hl_info_time_sync { 372 __u64 device_time; 373 __u64 host_time; 374}; 375 376/** 377 * struct hl_info_pci_counters - pci counters 378 * @rx_throughput: PCI rx throughput KBps 379 * @tx_throughput: PCI tx throughput KBps 380 * @replay_cnt: PCI replay counter 381 */ 382struct hl_info_pci_counters { 383 __u64 rx_throughput; 384 __u64 tx_throughput; 385 __u64 replay_cnt; 386}; 387 388#define HL_CLK_THROTTLE_POWER 0x1 389#define HL_CLK_THROTTLE_THERMAL 0x2 390 391/** 392 * struct hl_info_clk_throttle - clock throttling reason 393 * @clk_throttling_reason: each bit represents a clk throttling reason 394 */ 395struct hl_info_clk_throttle { 396 __u32 clk_throttling_reason; 397}; 398 399/** 400 * struct hl_info_energy - device energy information 401 * @total_energy_consumption: total device energy consumption 402 */ 403struct hl_info_energy { 404 __u64 total_energy_consumption; 405}; 406 407#define HL_PLL_NUM_OUTPUTS 4 408 409struct hl_pll_frequency_info { 410 __u16 output[HL_PLL_NUM_OUTPUTS]; 411}; 412 413/** 414 * struct hl_info_sync_manager - sync manager information 415 * @first_available_sync_object: first available sob 416 * @first_available_monitor: first available monitor 417 * @first_available_cq: first available cq 418 */ 419struct hl_info_sync_manager { 420 __u32 first_available_sync_object; 421 __u32 first_available_monitor; 422 __u32 first_available_cq; 423 __u32 reserved; 424}; 425 426/** 427 * struct hl_info_cs_counters - command submission counters 428 * @total_out_of_mem_drop_cnt: total dropped due to memory allocation issue 429 * @ctx_out_of_mem_drop_cnt: context dropped due to memory allocation issue 430 * @total_parsing_drop_cnt: total dropped due to error in packet parsing 431 * @ctx_parsing_drop_cnt: context dropped due to error in packet parsing 432 * @total_queue_full_drop_cnt: total dropped due to queue full 433 * @ctx_queue_full_drop_cnt: context dropped due to queue full 434 * @total_device_in_reset_drop_cnt: total dropped due to device in reset 435 * @ctx_device_in_reset_drop_cnt: context dropped due to device in reset 436 * @total_max_cs_in_flight_drop_cnt: total dropped due to maximum CS in-flight 437 * @ctx_max_cs_in_flight_drop_cnt: context dropped due to maximum CS in-flight 438 * @total_validation_drop_cnt: total dropped due to validation error 439 * @ctx_validation_drop_cnt: context dropped due to validation error 440 */ 441struct hl_info_cs_counters { 442 __u64 total_out_of_mem_drop_cnt; 443 __u64 ctx_out_of_mem_drop_cnt; 444 __u64 total_parsing_drop_cnt; 445 __u64 ctx_parsing_drop_cnt; 446 __u64 total_queue_full_drop_cnt; 447 __u64 ctx_queue_full_drop_cnt; 448 __u64 total_device_in_reset_drop_cnt; 449 __u64 ctx_device_in_reset_drop_cnt; 450 __u64 total_max_cs_in_flight_drop_cnt; 451 __u64 ctx_max_cs_in_flight_drop_cnt; 452 __u64 total_validation_drop_cnt; 453 __u64 ctx_validation_drop_cnt; 454}; 455 456enum gaudi_dcores { 457 HL_GAUDI_WS_DCORE, 458 HL_GAUDI_WN_DCORE, 459 HL_GAUDI_EN_DCORE, 460 HL_GAUDI_ES_DCORE 461}; 462 463struct hl_info_args { 464 /* Location of relevant struct in userspace */ 465 __u64 return_pointer; 466 /* 467 * The size of the return value. Just like "size" in "snprintf", 468 * it limits how many bytes the kernel can write 469 * 470 * For hw_events array, the size should be 471 * hl_info_hw_ip_info.num_of_events * sizeof(__u32) 472 */ 473 __u32 return_size; 474 475 /* HL_INFO_* */ 476 __u32 op; 477 478 union { 479 /* Dcore id for which the information is relevant. 480 * For Gaudi refer to 'enum gaudi_dcores' 481 */ 482 __u32 dcore_id; 483 /* Context ID - Currently not in use */ 484 __u32 ctx_id; 485 /* Period value for utilization rate (100ms - 1000ms, in 100ms 486 * resolution. 487 */ 488 __u32 period_ms; 489 /* PLL frequency retrieval */ 490 __u32 pll_index; 491 }; 492 493 __u32 pad; 494}; 495 496/* Opcode to create a new command buffer */ 497#define HL_CB_OP_CREATE 0 498/* Opcode to destroy previously created command buffer */ 499#define HL_CB_OP_DESTROY 1 500/* Opcode to retrieve information about a command buffer */ 501#define HL_CB_OP_INFO 2 502 503/* 2MB minus 32 bytes for 2xMSG_PROT */ 504#define HL_MAX_CB_SIZE (0x200000 - 32) 505 506/* Indicates whether the command buffer should be mapped to the device's MMU */ 507#define HL_CB_FLAGS_MAP 0x1 508 509struct hl_cb_in { 510 /* Handle of CB or 0 if we want to create one */ 511 __u64 cb_handle; 512 /* HL_CB_OP_* */ 513 __u32 op; 514 /* Size of CB. Maximum size is HL_MAX_CB_SIZE. The minimum size that 515 * will be allocated, regardless of this parameter's value, is PAGE_SIZE 516 */ 517 __u32 cb_size; 518 /* Context ID - Currently not in use */ 519 __u32 ctx_id; 520 /* HL_CB_FLAGS_* */ 521 __u32 flags; 522}; 523 524struct hl_cb_out { 525 union { 526 /* Handle of CB */ 527 __u64 cb_handle; 528 529 /* Information about CB */ 530 struct { 531 /* Usage count of CB */ 532 __u32 usage_cnt; 533 __u32 pad; 534 }; 535 }; 536}; 537 538union hl_cb_args { 539 struct hl_cb_in in; 540 struct hl_cb_out out; 541}; 542 543/* HL_CS_CHUNK_FLAGS_ values 544 * 545 * HL_CS_CHUNK_FLAGS_USER_ALLOC_CB: 546 * Indicates if the CB was allocated and mapped by userspace. 547 * User allocated CB is a command buffer allocated by the user, via malloc 548 * (or similar). After allocating the CB, the user invokes “memory ioctl” 549 * to map the user memory into a device virtual address. The user provides 550 * this address via the cb_handle field. The interface provides the 551 * ability to create a large CBs, Which aren’t limited to 552 * “HL_MAX_CB_SIZE”. Therefore, it increases the PCI-DMA queues 553 * throughput. This CB allocation method also reduces the use of Linux 554 * DMA-able memory pool. Which are limited and used by other Linux 555 * sub-systems. 556 */ 557#define HL_CS_CHUNK_FLAGS_USER_ALLOC_CB 0x1 558 559/* 560 * This structure size must always be fixed to 64-bytes for backward 561 * compatibility 562 */ 563struct hl_cs_chunk { 564 union { 565 /* For external queue, this represents a Handle of CB on the 566 * Host. 567 * For internal queue in Goya, this represents an SRAM or 568 * a DRAM address of the internal CB. In Gaudi, this might also 569 * represent a mapped host address of the CB. 570 * 571 * A mapped host address is in the device address space, after 572 * a host address was mapped by the device MMU. 573 */ 574 __u64 cb_handle; 575 576 /* Relevant only when HL_CS_FLAGS_WAIT or 577 * HL_CS_FLAGS_COLLECTIVE_WAIT is set. 578 * This holds address of array of u64 values that contain 579 * signal CS sequence numbers. The wait described by this job 580 * will listen on all those signals (wait event per signal) 581 */ 582 __u64 signal_seq_arr; 583 }; 584 585 /* Index of queue to put the CB on */ 586 __u32 queue_index; 587 588 union { 589 /* 590 * Size of command buffer with valid packets 591 * Can be smaller then actual CB size 592 */ 593 __u32 cb_size; 594 595 /* Relevant only when HL_CS_FLAGS_WAIT or 596 * HL_CS_FLAGS_COLLECTIVE_WAIT is set. 597 * Number of entries in signal_seq_arr 598 */ 599 __u32 num_signal_seq_arr; 600 }; 601 602 /* HL_CS_CHUNK_FLAGS_* */ 603 __u32 cs_chunk_flags; 604 605 /* Relevant only when HL_CS_FLAGS_COLLECTIVE_WAIT is set. 606 * This holds the collective engine ID. The wait described by this job 607 * will sync with this engine and with all NICs before completion. 608 */ 609 __u32 collective_engine_id; 610 611 /* Align structure to 64 bytes */ 612 __u32 pad[10]; 613}; 614 615/* SIGNAL and WAIT/COLLECTIVE_WAIT flags are mutually exclusive */ 616#define HL_CS_FLAGS_FORCE_RESTORE 0x1 617#define HL_CS_FLAGS_SIGNAL 0x2 618#define HL_CS_FLAGS_WAIT 0x4 619#define HL_CS_FLAGS_COLLECTIVE_WAIT 0x8 620#define HL_CS_FLAGS_TIMESTAMP 0x20 621#define HL_CS_FLAGS_STAGED_SUBMISSION 0x40 622#define HL_CS_FLAGS_STAGED_SUBMISSION_FIRST 0x80 623#define HL_CS_FLAGS_STAGED_SUBMISSION_LAST 0x100 624 625#define HL_CS_STATUS_SUCCESS 0 626 627#define HL_MAX_JOBS_PER_CS 512 628 629struct hl_cs_in { 630 631 /* this holds address of array of hl_cs_chunk for restore phase */ 632 __u64 chunks_restore; 633 634 /* holds address of array of hl_cs_chunk for execution phase */ 635 __u64 chunks_execute; 636 637 union { 638 /* this holds address of array of hl_cs_chunk for store phase - 639 * Currently not in use 640 */ 641 __u64 chunks_store; 642 643 /* Sequence number of a staged submission CS 644 * valid only if HL_CS_FLAGS_STAGED_SUBMISSION is set 645 */ 646 __u64 seq; 647 }; 648 649 /* Number of chunks in restore phase array. Maximum number is 650 * HL_MAX_JOBS_PER_CS 651 */ 652 __u32 num_chunks_restore; 653 654 /* Number of chunks in execution array. Maximum number is 655 * HL_MAX_JOBS_PER_CS 656 */ 657 __u32 num_chunks_execute; 658 659 /* Number of chunks in restore phase array - Currently not in use */ 660 __u32 num_chunks_store; 661 662 /* HL_CS_FLAGS_* */ 663 __u32 cs_flags; 664 665 /* Context ID - Currently not in use */ 666 __u32 ctx_id; 667}; 668 669struct hl_cs_out { 670 /* 671 * seq holds the sequence number of the CS to pass to wait ioctl. All 672 * values are valid except for 0 and ULLONG_MAX 673 */ 674 __u64 seq; 675 /* HL_CS_STATUS_* */ 676 __u32 status; 677 __u32 pad; 678}; 679 680union hl_cs_args { 681 struct hl_cs_in in; 682 struct hl_cs_out out; 683}; 684 685struct hl_wait_cs_in { 686 /* Command submission sequence number */ 687 __u64 seq; 688 /* Absolute timeout to wait in microseconds */ 689 __u64 timeout_us; 690 /* Context ID - Currently not in use */ 691 __u32 ctx_id; 692 __u32 pad; 693}; 694 695#define HL_WAIT_CS_STATUS_COMPLETED 0 696#define HL_WAIT_CS_STATUS_BUSY 1 697#define HL_WAIT_CS_STATUS_TIMEDOUT 2 698#define HL_WAIT_CS_STATUS_ABORTED 3 699#define HL_WAIT_CS_STATUS_INTERRUPTED 4 700 701#define HL_WAIT_CS_STATUS_FLAG_GONE 0x1 702#define HL_WAIT_CS_STATUS_FLAG_TIMESTAMP_VLD 0x2 703 704struct hl_wait_cs_out { 705 /* HL_WAIT_CS_STATUS_* */ 706 __u32 status; 707 /* HL_WAIT_CS_STATUS_FLAG* */ 708 __u32 flags; 709 /* valid only if HL_WAIT_CS_STATUS_FLAG_TIMESTAMP_VLD is set */ 710 __s64 timestamp_nsec; 711}; 712 713union hl_wait_cs_args { 714 struct hl_wait_cs_in in; 715 struct hl_wait_cs_out out; 716}; 717 718/* Opcode to allocate device memory */ 719#define HL_MEM_OP_ALLOC 0 720/* Opcode to free previously allocated device memory */ 721#define HL_MEM_OP_FREE 1 722/* Opcode to map host and device memory */ 723#define HL_MEM_OP_MAP 2 724/* Opcode to unmap previously mapped host and device memory */ 725#define HL_MEM_OP_UNMAP 3 726/* Opcode to map a hw block */ 727#define HL_MEM_OP_MAP_BLOCK 4 728 729/* Memory flags */ 730#define HL_MEM_CONTIGUOUS 0x1 731#define HL_MEM_SHARED 0x2 732#define HL_MEM_USERPTR 0x4 733 734struct hl_mem_in { 735 union { 736 /* HL_MEM_OP_ALLOC- allocate device memory */ 737 struct { 738 /* Size to alloc */ 739 __u64 mem_size; 740 } alloc; 741 742 /* HL_MEM_OP_FREE - free device memory */ 743 struct { 744 /* Handle returned from HL_MEM_OP_ALLOC */ 745 __u64 handle; 746 } free; 747 748 /* HL_MEM_OP_MAP - map device memory */ 749 struct { 750 /* 751 * Requested virtual address of mapped memory. 752 * The driver will try to map the requested region to 753 * this hint address, as long as the address is valid 754 * and not already mapped. The user should check the 755 * returned address of the IOCTL to make sure he got 756 * the hint address. Passing 0 here means that the 757 * driver will choose the address itself. 758 */ 759 __u64 hint_addr; 760 /* Handle returned from HL_MEM_OP_ALLOC */ 761 __u64 handle; 762 } map_device; 763 764 /* HL_MEM_OP_MAP - map host memory */ 765 struct { 766 /* Address of allocated host memory */ 767 __u64 host_virt_addr; 768 /* 769 * Requested virtual address of mapped memory. 770 * The driver will try to map the requested region to 771 * this hint address, as long as the address is valid 772 * and not already mapped. The user should check the 773 * returned address of the IOCTL to make sure he got 774 * the hint address. Passing 0 here means that the 775 * driver will choose the address itself. 776 */ 777 __u64 hint_addr; 778 /* Size of allocated host memory */ 779 __u64 mem_size; 780 } map_host; 781 782 /* HL_MEM_OP_MAP_BLOCK - map a hw block */ 783 struct { 784 /* 785 * HW block address to map, a handle and size will be 786 * returned to the user and will be used to mmap the 787 * relevant block. Only addresses from configuration 788 * space are allowed. 789 */ 790 __u64 block_addr; 791 } map_block; 792 793 /* HL_MEM_OP_UNMAP - unmap host memory */ 794 struct { 795 /* Virtual address returned from HL_MEM_OP_MAP */ 796 __u64 device_virt_addr; 797 } unmap; 798 }; 799 800 /* HL_MEM_OP_* */ 801 __u32 op; 802 /* HL_MEM_* flags */ 803 __u32 flags; 804 /* Context ID - Currently not in use */ 805 __u32 ctx_id; 806 __u32 pad; 807}; 808 809struct hl_mem_out { 810 union { 811 /* 812 * Used for HL_MEM_OP_MAP as the virtual address that was 813 * assigned in the device VA space. 814 * A value of 0 means the requested operation failed. 815 */ 816 __u64 device_virt_addr; 817 818 /* 819 * Used in HL_MEM_OP_ALLOC 820 * This is the assigned handle for the allocated memory 821 */ 822 __u64 handle; 823 824 struct { 825 /* 826 * Used in HL_MEM_OP_MAP_BLOCK. 827 * This is the assigned handle for the mapped block 828 */ 829 __u64 block_handle; 830 831 /* 832 * Used in HL_MEM_OP_MAP_BLOCK 833 * This is the size of the mapped block 834 */ 835 __u32 block_size; 836 837 __u32 pad; 838 }; 839 }; 840}; 841 842union hl_mem_args { 843 struct hl_mem_in in; 844 struct hl_mem_out out; 845}; 846 847#define HL_DEBUG_MAX_AUX_VALUES 10 848 849struct hl_debug_params_etr { 850 /* Address in memory to allocate buffer */ 851 __u64 buffer_address; 852 853 /* Size of buffer to allocate */ 854 __u64 buffer_size; 855 856 /* Sink operation mode: SW fifo, HW fifo, Circular buffer */ 857 __u32 sink_mode; 858 __u32 pad; 859}; 860 861struct hl_debug_params_etf { 862 /* Address in memory to allocate buffer */ 863 __u64 buffer_address; 864 865 /* Size of buffer to allocate */ 866 __u64 buffer_size; 867 868 /* Sink operation mode: SW fifo, HW fifo, Circular buffer */ 869 __u32 sink_mode; 870 __u32 pad; 871}; 872 873struct hl_debug_params_stm { 874 /* Two bit masks for HW event and Stimulus Port */ 875 __u64 he_mask; 876 __u64 sp_mask; 877 878 /* Trace source ID */ 879 __u32 id; 880 881 /* Frequency for the timestamp register */ 882 __u32 frequency; 883}; 884 885struct hl_debug_params_bmon { 886 /* Two address ranges that the user can request to filter */ 887 __u64 start_addr0; 888 __u64 addr_mask0; 889 890 __u64 start_addr1; 891 __u64 addr_mask1; 892 893 /* Capture window configuration */ 894 __u32 bw_win; 895 __u32 win_capture; 896 897 /* Trace source ID */ 898 __u32 id; 899 __u32 pad; 900}; 901 902struct hl_debug_params_spmu { 903 /* Event types selection */ 904 __u64 event_types[HL_DEBUG_MAX_AUX_VALUES]; 905 906 /* Number of event types selection */ 907 __u32 event_types_num; 908 __u32 pad; 909}; 910 911/* Opcode for ETR component */ 912#define HL_DEBUG_OP_ETR 0 913/* Opcode for ETF component */ 914#define HL_DEBUG_OP_ETF 1 915/* Opcode for STM component */ 916#define HL_DEBUG_OP_STM 2 917/* Opcode for FUNNEL component */ 918#define HL_DEBUG_OP_FUNNEL 3 919/* Opcode for BMON component */ 920#define HL_DEBUG_OP_BMON 4 921/* Opcode for SPMU component */ 922#define HL_DEBUG_OP_SPMU 5 923/* Opcode for timestamp (deprecated) */ 924#define HL_DEBUG_OP_TIMESTAMP 6 925/* Opcode for setting the device into or out of debug mode. The enable 926 * variable should be 1 for enabling debug mode and 0 for disabling it 927 */ 928#define HL_DEBUG_OP_SET_MODE 7 929 930struct hl_debug_args { 931 /* 932 * Pointer to user input structure. 933 * This field is relevant to specific opcodes. 934 */ 935 __u64 input_ptr; 936 /* Pointer to user output structure */ 937 __u64 output_ptr; 938 /* Size of user input structure */ 939 __u32 input_size; 940 /* Size of user output structure */ 941 __u32 output_size; 942 /* HL_DEBUG_OP_* */ 943 __u32 op; 944 /* 945 * Register index in the component, taken from the debug_regs_index enum 946 * in the various ASIC header files 947 */ 948 __u32 reg_idx; 949 /* Enable/disable */ 950 __u32 enable; 951 /* Context ID - Currently not in use */ 952 __u32 ctx_id; 953}; 954 955/* 956 * Various information operations such as: 957 * - H/W IP information 958 * - Current dram usage 959 * 960 * The user calls this IOCTL with an opcode that describes the required 961 * information. The user should supply a pointer to a user-allocated memory 962 * chunk, which will be filled by the driver with the requested information. 963 * 964 * The user supplies the maximum amount of size to copy into the user's memory, 965 * in order to prevent data corruption in case of differences between the 966 * definitions of structures in kernel and userspace, e.g. in case of old 967 * userspace and new kernel driver 968 */ 969#define HL_IOCTL_INFO \ 970 _IOWR('H', 0x01, struct hl_info_args) 971 972/* 973 * Command Buffer 974 * - Request a Command Buffer 975 * - Destroy a Command Buffer 976 * 977 * The command buffers are memory blocks that reside in DMA-able address 978 * space and are physically contiguous so they can be accessed by the device 979 * directly. They are allocated using the coherent DMA API. 980 * 981 * When creating a new CB, the IOCTL returns a handle of it, and the user-space 982 * process needs to use that handle to mmap the buffer so it can access them. 983 * 984 * In some instances, the device must access the command buffer through the 985 * device's MMU, and thus its memory should be mapped. In these cases, user can 986 * indicate the driver that such a mapping is required. 987 * The resulting device virtual address will be used internally by the driver, 988 * and won't be returned to user. 989 * 990 */ 991#define HL_IOCTL_CB \ 992 _IOWR('H', 0x02, union hl_cb_args) 993 994/* 995 * Command Submission 996 * 997 * To submit work to the device, the user need to call this IOCTL with a set 998 * of JOBS. That set of JOBS constitutes a CS object. 999 * Each JOB will be enqueued on a specific queue, according to the user's input. 1000 * There can be more then one JOB per queue. 1001 * 1002 * The CS IOCTL will receive three sets of JOBS. One set is for "restore" phase, 1003 * a second set is for "execution" phase and a third set is for "store" phase. 1004 * The JOBS on the "restore" phase are enqueued only after context-switch 1005 * (or if its the first CS for this context). The user can also order the 1006 * driver to run the "restore" phase explicitly 1007 * 1008 * There are two types of queues - external and internal. External queues 1009 * are DMA queues which transfer data from/to the Host. All other queues are 1010 * internal. The driver will get completion notifications from the device only 1011 * on JOBS which are enqueued in the external queues. 1012 * 1013 * For jobs on external queues, the user needs to create command buffers 1014 * through the CB ioctl and give the CB's handle to the CS ioctl. For jobs on 1015 * internal queues, the user needs to prepare a "command buffer" with packets 1016 * on either the device SRAM/DRAM or the host, and give the device address of 1017 * that buffer to the CS ioctl. 1018 * 1019 * This IOCTL is asynchronous in regard to the actual execution of the CS. This 1020 * means it returns immediately after ALL the JOBS were enqueued on their 1021 * relevant queues. Therefore, the user mustn't assume the CS has been completed 1022 * or has even started to execute. 1023 * 1024 * Upon successful enqueue, the IOCTL returns a sequence number which the user 1025 * can use with the "Wait for CS" IOCTL to check whether the handle's CS 1026 * external JOBS have been completed. Note that if the CS has internal JOBS 1027 * which can execute AFTER the external JOBS have finished, the driver might 1028 * report that the CS has finished executing BEFORE the internal JOBS have 1029 * actually finished executing. 1030 * 1031 * Even though the sequence number increments per CS, the user can NOT 1032 * automatically assume that if CS with sequence number N finished, then CS 1033 * with sequence number N-1 also finished. The user can make this assumption if 1034 * and only if CS N and CS N-1 are exactly the same (same CBs for the same 1035 * queues). 1036 */ 1037#define HL_IOCTL_CS \ 1038 _IOWR('H', 0x03, union hl_cs_args) 1039 1040/* 1041 * Wait for Command Submission 1042 * 1043 * The user can call this IOCTL with a handle it received from the CS IOCTL 1044 * to wait until the handle's CS has finished executing. The user will wait 1045 * inside the kernel until the CS has finished or until the user-requested 1046 * timeout has expired. 1047 * 1048 * If the timeout value is 0, the driver won't sleep at all. It will check 1049 * the status of the CS and return immediately 1050 * 1051 * The return value of the IOCTL is a standard Linux error code. The possible 1052 * values are: 1053 * 1054 * EINTR - Kernel waiting has been interrupted, e.g. due to OS signal 1055 * that the user process received 1056 * ETIMEDOUT - The CS has caused a timeout on the device 1057 * EIO - The CS was aborted (usually because the device was reset) 1058 * ENODEV - The device wants to do hard-reset (so user need to close FD) 1059 * 1060 * The driver also returns a custom define inside the IOCTL which can be: 1061 * 1062 * HL_WAIT_CS_STATUS_COMPLETED - The CS has been completed successfully (0) 1063 * HL_WAIT_CS_STATUS_BUSY - The CS is still executing (0) 1064 * HL_WAIT_CS_STATUS_TIMEDOUT - The CS has caused a timeout on the device 1065 * (ETIMEDOUT) 1066 * HL_WAIT_CS_STATUS_ABORTED - The CS was aborted, usually because the 1067 * device was reset (EIO) 1068 * HL_WAIT_CS_STATUS_INTERRUPTED - Waiting for the CS was interrupted (EINTR) 1069 * 1070 */ 1071 1072#define HL_IOCTL_WAIT_CS \ 1073 _IOWR('H', 0x04, union hl_wait_cs_args) 1074 1075/* 1076 * Memory 1077 * - Map host memory to device MMU 1078 * - Unmap host memory from device MMU 1079 * 1080 * This IOCTL allows the user to map host memory to the device MMU 1081 * 1082 * For host memory, the IOCTL doesn't allocate memory. The user is supposed 1083 * to allocate the memory in user-space (malloc/new). The driver pins the 1084 * physical pages (up to the allowed limit by the OS), assigns a virtual 1085 * address in the device VA space and initializes the device MMU. 1086 * 1087 * There is an option for the user to specify the requested virtual address. 1088 * 1089 */ 1090#define HL_IOCTL_MEMORY \ 1091 _IOWR('H', 0x05, union hl_mem_args) 1092 1093/* 1094 * Debug 1095 * - Enable/disable the ETR/ETF/FUNNEL/STM/BMON/SPMU debug traces 1096 * 1097 * This IOCTL allows the user to get debug traces from the chip. 1098 * 1099 * Before the user can send configuration requests of the various 1100 * debug/profile engines, it needs to set the device into debug mode. 1101 * This is because the debug/profile infrastructure is shared component in the 1102 * device and we can't allow multiple users to access it at the same time. 1103 * 1104 * Once a user set the device into debug mode, the driver won't allow other 1105 * users to "work" with the device, i.e. open a FD. If there are multiple users 1106 * opened on the device, the driver won't allow any user to debug the device. 1107 * 1108 * For each configuration request, the user needs to provide the register index 1109 * and essential data such as buffer address and size. 1110 * 1111 * Once the user has finished using the debug/profile engines, he should 1112 * set the device into non-debug mode, i.e. disable debug mode. 1113 * 1114 * The driver can decide to "kick out" the user if he abuses this interface. 1115 * 1116 */ 1117#define HL_IOCTL_DEBUG \ 1118 _IOWR('H', 0x06, struct hl_debug_args) 1119 1120#define HL_COMMAND_START 0x01 1121#define HL_COMMAND_END 0x07 1122 1123#endif /* HABANALABS_H_ */