gaudiP.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  1. /* SPDX-License-Identifier: GPL-2.0
  2. *
  3. * Copyright 2019-2022 HabanaLabs, Ltd.
  4. * All Rights Reserved.
  5. *
  6. */
  7. #ifndef GAUDIP_H_
  8. #define GAUDIP_H_
  9. #include <uapi/misc/habanalabs.h>
  10. #include "../common/habanalabs.h"
  11. #include "../include/common/hl_boot_if.h"
  12. #include "../include/gaudi/gaudi_packets.h"
  13. #include "../include/gaudi/gaudi.h"
  14. #include "../include/gaudi/gaudi_async_events.h"
  15. #include "../include/gaudi/gaudi_fw_if.h"
  16. #define NUMBER_OF_EXT_HW_QUEUES 8
  17. #define NUMBER_OF_CMPLT_QUEUES NUMBER_OF_EXT_HW_QUEUES
  18. #define NUMBER_OF_CPU_HW_QUEUES 1
  19. #define NUMBER_OF_INT_HW_QUEUES 100
  20. #define NUMBER_OF_HW_QUEUES (NUMBER_OF_EXT_HW_QUEUES + \
  21. NUMBER_OF_CPU_HW_QUEUES + \
  22. NUMBER_OF_INT_HW_QUEUES)
  23. /* 10 NIC QMANs, DMA5 QMAN, TPC7 QMAN */
  24. #define NUMBER_OF_COLLECTIVE_QUEUES 12
  25. #define NUMBER_OF_SOBS_IN_GRP 11
  26. /*
  27. * Number of MSI interrupts IDS:
  28. * Each completion queue has 1 ID
  29. * The event queue has 1 ID
  30. */
  31. #define NUMBER_OF_INTERRUPTS (NUMBER_OF_CMPLT_QUEUES + \
  32. NUMBER_OF_CPU_HW_QUEUES)
  33. #define GAUDI_STREAM_MASTER_ARR_SIZE 8
  34. #if (NUMBER_OF_INTERRUPTS > GAUDI_MSI_ENTRIES)
  35. #error "Number of MSI interrupts must be smaller or equal to GAUDI_MSI_ENTRIES"
  36. #endif
  37. #define CORESIGHT_TIMEOUT_USEC 100000 /* 100 ms */
  38. #define GAUDI_MAX_CLK_FREQ 2200000000ull /* 2200 MHz */
  39. #define MAX_POWER_DEFAULT_PCI 200000 /* 200W */
  40. #define MAX_POWER_DEFAULT_PMC 350000 /* 350W */
  41. #define DC_POWER_DEFAULT_PCI 60000 /* 60W */
  42. #define DC_POWER_DEFAULT_PMC 60000 /* 60W */
  43. #define DC_POWER_DEFAULT_PMC_SEC 97000 /* 97W */
  44. #define GAUDI_CPU_TIMEOUT_USEC 30000000 /* 30s */
  45. #define TPC_ENABLED_MASK 0xFF
  46. #define GAUDI_HBM_SIZE_32GB 0x800000000ull
  47. #define GAUDI_HBM_DEVICES 4
  48. #define GAUDI_HBM_CHANNELS 8
  49. #define GAUDI_HBM_CFG_BASE (mmHBM0_BASE - CFG_BASE)
  50. #define GAUDI_HBM_CFG_OFFSET (mmHBM1_BASE - mmHBM0_BASE)
  51. #define DMA_MAX_TRANSFER_SIZE U32_MAX
  52. #define GAUDI_DEFAULT_CARD_NAME "HL205"
  53. #define GAUDI_MAX_PENDING_CS SZ_16K
  54. #if !IS_MAX_PENDING_CS_VALID(GAUDI_MAX_PENDING_CS)
  55. #error "GAUDI_MAX_PENDING_CS must be power of 2 and greater than 1"
  56. #endif
  57. #define PCI_DMA_NUMBER_OF_CHNLS 2
  58. #define HBM_DMA_NUMBER_OF_CHNLS 6
  59. #define DMA_NUMBER_OF_CHNLS (PCI_DMA_NUMBER_OF_CHNLS + \
  60. HBM_DMA_NUMBER_OF_CHNLS)
  61. #define MME_NUMBER_OF_SLAVE_ENGINES 2
  62. #define MME_NUMBER_OF_ENGINES (MME_NUMBER_OF_MASTER_ENGINES + \
  63. MME_NUMBER_OF_SLAVE_ENGINES)
  64. #define MME_NUMBER_OF_QMANS (MME_NUMBER_OF_MASTER_ENGINES * \
  65. QMAN_STREAMS)
  66. #define QMAN_STREAMS 4
  67. #define PQ_FETCHER_CACHE_SIZE 8
  68. #define DMA_QMAN_OFFSET (mmDMA1_QM_BASE - mmDMA0_QM_BASE)
  69. #define TPC_QMAN_OFFSET (mmTPC1_QM_BASE - mmTPC0_QM_BASE)
  70. #define MME_QMAN_OFFSET (mmMME1_QM_BASE - mmMME0_QM_BASE)
  71. #define NIC_MACRO_QMAN_OFFSET (mmNIC1_QM0_BASE - mmNIC0_QM0_BASE)
  72. #define NIC_ENGINE_QMAN_OFFSET (mmNIC0_QM1_BASE - mmNIC0_QM0_BASE)
  73. #define TPC_CFG_OFFSET (mmTPC1_CFG_BASE - mmTPC0_CFG_BASE)
  74. #define DMA_CORE_OFFSET (mmDMA1_CORE_BASE - mmDMA0_CORE_BASE)
  75. #define QMAN_LDMA_SRC_OFFSET (mmDMA0_CORE_SRC_BASE_LO - mmDMA0_CORE_CFG_0)
  76. #define QMAN_LDMA_DST_OFFSET (mmDMA0_CORE_DST_BASE_LO - mmDMA0_CORE_CFG_0)
  77. #define QMAN_LDMA_SIZE_OFFSET (mmDMA0_CORE_DST_TSIZE_0 - mmDMA0_CORE_CFG_0)
  78. #define QMAN_CPDMA_SRC_OFFSET (mmDMA0_QM_CQ_PTR_LO_4 - mmDMA0_CORE_CFG_0)
  79. #define QMAN_CPDMA_DST_OFFSET (mmDMA0_CORE_DST_BASE_LO - mmDMA0_CORE_CFG_0)
  80. #define QMAN_CPDMA_SIZE_OFFSET (mmDMA0_QM_CQ_TSIZE_4 - mmDMA0_CORE_CFG_0)
  81. #define SIF_RTR_CTRL_OFFSET (mmSIF_RTR_CTRL_1_BASE - mmSIF_RTR_CTRL_0_BASE)
  82. #define NIF_RTR_CTRL_OFFSET (mmNIF_RTR_CTRL_1_BASE - mmNIF_RTR_CTRL_0_BASE)
  83. #define MME_ACC_OFFSET (mmMME1_ACC_BASE - mmMME0_ACC_BASE)
  84. #define SRAM_BANK_OFFSET (mmSRAM_Y0_X1_RTR_BASE - mmSRAM_Y0_X0_RTR_BASE)
  85. #define NUM_OF_SOB_IN_BLOCK \
  86. (((mmSYNC_MNGR_E_N_SYNC_MNGR_OBJS_SOB_OBJ_2047 - \
  87. mmSYNC_MNGR_E_N_SYNC_MNGR_OBJS_SOB_OBJ_0) + 4) >> 2)
  88. #define NUM_OF_MONITORS_IN_BLOCK \
  89. (((mmSYNC_MNGR_E_N_SYNC_MNGR_OBJS_MON_STATUS_511 - \
  90. mmSYNC_MNGR_E_N_SYNC_MNGR_OBJS_MON_STATUS_0) + 4) >> 2)
  91. #define MONITOR_MAX_SOBS 8
  92. /* DRAM Memory Map */
  93. #define CPU_FW_IMAGE_SIZE 0x10000000 /* 256MB */
  94. #define MMU_PAGE_TABLES_SIZE 0x0BF00000 /* 191MB */
  95. #define MMU_CACHE_MNG_SIZE 0x00100000 /* 1MB */
  96. #define RESERVED 0x04000000 /* 64MB */
  97. #define CPU_FW_IMAGE_ADDR DRAM_PHYS_BASE
  98. #define MMU_PAGE_TABLES_ADDR (CPU_FW_IMAGE_ADDR + CPU_FW_IMAGE_SIZE)
  99. #define MMU_CACHE_MNG_ADDR (MMU_PAGE_TABLES_ADDR + MMU_PAGE_TABLES_SIZE)
  100. #define DRAM_DRIVER_END_ADDR (MMU_CACHE_MNG_ADDR + MMU_CACHE_MNG_SIZE +\
  101. RESERVED)
  102. #define DRAM_BASE_ADDR_USER 0x20000000
  103. #if (DRAM_DRIVER_END_ADDR > DRAM_BASE_ADDR_USER)
  104. #error "Driver must reserve no more than 512MB"
  105. #endif
  106. /* Internal QMANs PQ sizes */
  107. #define MME_QMAN_LENGTH 1024
  108. #define MME_QMAN_SIZE_IN_BYTES (MME_QMAN_LENGTH * QMAN_PQ_ENTRY_SIZE)
  109. #define HBM_DMA_QMAN_LENGTH 4096
  110. #define HBM_DMA_QMAN_SIZE_IN_BYTES \
  111. (HBM_DMA_QMAN_LENGTH * QMAN_PQ_ENTRY_SIZE)
  112. #define TPC_QMAN_LENGTH 1024
  113. #define TPC_QMAN_SIZE_IN_BYTES (TPC_QMAN_LENGTH * QMAN_PQ_ENTRY_SIZE)
  114. #define NIC_QMAN_LENGTH 4096
  115. #define NIC_QMAN_SIZE_IN_BYTES (NIC_QMAN_LENGTH * QMAN_PQ_ENTRY_SIZE)
  116. #define SRAM_USER_BASE_OFFSET GAUDI_DRIVER_SRAM_RESERVED_SIZE_FROM_START
  117. /* Virtual address space */
  118. #define VA_HOST_SPACE_START 0x1000000000000ull /* 256TB */
  119. #define VA_HOST_SPACE_END 0x3FF8000000000ull /* 1PB - 512GB */
  120. #define VA_HOST_SPACE_SIZE (VA_HOST_SPACE_END - \
  121. VA_HOST_SPACE_START) /* 767TB */
  122. #define HOST_SPACE_INTERNAL_CB_SZ SZ_2M
  123. #define HW_CAP_PLL BIT(0)
  124. #define HW_CAP_HBM BIT(1)
  125. #define HW_CAP_MMU BIT(2)
  126. #define HW_CAP_MME BIT(3)
  127. #define HW_CAP_CPU BIT(4)
  128. #define HW_CAP_PCI_DMA BIT(5)
  129. #define HW_CAP_MSI BIT(6)
  130. #define HW_CAP_CPU_Q BIT(7)
  131. #define HW_CAP_HBM_DMA BIT(8)
  132. #define HW_CAP_SRAM_SCRAMBLER BIT(10)
  133. #define HW_CAP_HBM_SCRAMBLER BIT(11)
  134. #define HW_CAP_NIC0 BIT(14)
  135. #define HW_CAP_NIC1 BIT(15)
  136. #define HW_CAP_NIC2 BIT(16)
  137. #define HW_CAP_NIC3 BIT(17)
  138. #define HW_CAP_NIC4 BIT(18)
  139. #define HW_CAP_NIC5 BIT(19)
  140. #define HW_CAP_NIC6 BIT(20)
  141. #define HW_CAP_NIC7 BIT(21)
  142. #define HW_CAP_NIC8 BIT(22)
  143. #define HW_CAP_NIC9 BIT(23)
  144. #define HW_CAP_NIC_MASK GENMASK(23, 14)
  145. #define HW_CAP_NIC_SHIFT 14
  146. #define HW_CAP_TPC0 BIT(24)
  147. #define HW_CAP_TPC1 BIT(25)
  148. #define HW_CAP_TPC2 BIT(26)
  149. #define HW_CAP_TPC3 BIT(27)
  150. #define HW_CAP_TPC4 BIT(28)
  151. #define HW_CAP_TPC5 BIT(29)
  152. #define HW_CAP_TPC6 BIT(30)
  153. #define HW_CAP_TPC7 BIT(31)
  154. #define HW_CAP_TPC_MASK GENMASK(31, 24)
  155. #define HW_CAP_TPC_SHIFT 24
  156. #define NEXT_SYNC_OBJ_ADDR_INTERVAL \
  157. (mmSYNC_MNGR_W_N_SYNC_MNGR_OBJS_SOB_OBJ_0 - \
  158. mmSYNC_MNGR_E_N_SYNC_MNGR_OBJS_SOB_OBJ_0)
  159. #define NUM_OF_MME_ENGINES 2
  160. #define NUM_OF_MME_SUB_ENGINES 2
  161. #define NUM_OF_TPC_ENGINES 8
  162. #define NUM_OF_DMA_ENGINES 8
  163. #define NUM_OF_QUEUES 5
  164. #define NUM_OF_STREAMS 4
  165. #define NUM_OF_FENCES 4
  166. #define GAUDI_CPU_PCI_MSB_ADDR(addr) (((addr) & GENMASK_ULL(49, 39)) >> 39)
  167. #define GAUDI_PCI_TO_CPU_ADDR(addr) \
  168. do { \
  169. (addr) &= ~GENMASK_ULL(49, 39); \
  170. (addr) |= BIT_ULL(39); \
  171. } while (0)
  172. #define GAUDI_CPU_TO_PCI_ADDR(addr, extension) \
  173. do { \
  174. (addr) &= ~GENMASK_ULL(49, 39); \
  175. (addr) |= (u64) (extension) << 39; \
  176. } while (0)
  177. enum gaudi_dma_channels {
  178. GAUDI_PCI_DMA_1,
  179. GAUDI_PCI_DMA_2,
  180. GAUDI_HBM_DMA_1,
  181. GAUDI_HBM_DMA_2,
  182. GAUDI_HBM_DMA_3,
  183. GAUDI_HBM_DMA_4,
  184. GAUDI_HBM_DMA_5,
  185. GAUDI_HBM_DMA_6,
  186. GAUDI_DMA_MAX
  187. };
  188. enum gaudi_tpc_mask {
  189. GAUDI_TPC_MASK_TPC0 = 0x01,
  190. GAUDI_TPC_MASK_TPC1 = 0x02,
  191. GAUDI_TPC_MASK_TPC2 = 0x04,
  192. GAUDI_TPC_MASK_TPC3 = 0x08,
  193. GAUDI_TPC_MASK_TPC4 = 0x10,
  194. GAUDI_TPC_MASK_TPC5 = 0x20,
  195. GAUDI_TPC_MASK_TPC6 = 0x40,
  196. GAUDI_TPC_MASK_TPC7 = 0x80,
  197. GAUDI_TPC_MASK_ALL = 0xFF
  198. };
  199. enum gaudi_nic_mask {
  200. GAUDI_NIC_MASK_NIC0 = 0x01,
  201. GAUDI_NIC_MASK_NIC1 = 0x02,
  202. GAUDI_NIC_MASK_NIC2 = 0x04,
  203. GAUDI_NIC_MASK_NIC3 = 0x08,
  204. GAUDI_NIC_MASK_NIC4 = 0x10,
  205. GAUDI_NIC_MASK_NIC5 = 0x20,
  206. GAUDI_NIC_MASK_NIC6 = 0x40,
  207. GAUDI_NIC_MASK_NIC7 = 0x80,
  208. GAUDI_NIC_MASK_NIC8 = 0x100,
  209. GAUDI_NIC_MASK_NIC9 = 0x200,
  210. GAUDI_NIC_MASK_ALL = 0x3FF
  211. };
  212. /*
  213. * struct gaudi_hw_sob_group - H/W SOB group info.
  214. * @hdev: habanalabs device structure.
  215. * @kref: refcount of this SOB group. group will reset once refcount is zero.
  216. * @base_sob_id: base sob id of this SOB group.
  217. * @queue_id: id of the queue that waits on this sob group
  218. */
  219. struct gaudi_hw_sob_group {
  220. struct hl_device *hdev;
  221. struct kref kref;
  222. u32 base_sob_id;
  223. u32 queue_id;
  224. };
  225. #define NUM_SOB_GROUPS (HL_RSVD_SOBS * QMAN_STREAMS)
  226. /**
  227. * struct gaudi_collective_properties -
  228. * holds all SOB groups and queues info reserved for the collective
  229. * @hw_sob_group: H/W SOB groups.
  230. * @next_sob_group_val: the next value to use for the currently used SOB group.
  231. * @curr_sob_group_idx: the index of the currently used SOB group.
  232. * @mstr_sob_mask: pre-defined masks for collective master monitors
  233. */
  234. struct gaudi_collective_properties {
  235. struct gaudi_hw_sob_group hw_sob_group[NUM_SOB_GROUPS];
  236. u16 next_sob_group_val[QMAN_STREAMS];
  237. u8 curr_sob_group_idx[QMAN_STREAMS];
  238. u8 mstr_sob_mask[HL_COLLECTIVE_RSVD_MSTR_MONS];
  239. };
  240. /**
  241. * struct gaudi_internal_qman_info - Internal QMAN information.
  242. * @pq_kernel_addr: Kernel address of the PQ memory area in the host.
  243. * @pq_dma_addr: DMA address of the PQ memory area in the host.
  244. * @pq_size: Size of allocated host memory for PQ.
  245. */
  246. struct gaudi_internal_qman_info {
  247. void *pq_kernel_addr;
  248. dma_addr_t pq_dma_addr;
  249. size_t pq_size;
  250. };
  251. /**
  252. * struct gaudi_device - ASIC specific manage structure.
  253. * @cpucp_info_get: get information on device from CPU-CP
  254. * @hw_queues_lock: protects the H/W queues from concurrent access.
  255. * @internal_qmans: Internal QMANs information. The array size is larger than
  256. * the actual number of internal queues because they are not in
  257. * consecutive order.
  258. * @hbm_bar_cur_addr: current address of HBM PCI bar.
  259. * @events: array that holds all event id's
  260. * @events_stat: array that holds histogram of all received events.
  261. * @events_stat_aggregate: same as events_stat but doesn't get cleared on reset
  262. * @hw_cap_initialized: This field contains a bit per H/W engine. When that
  263. * engine is initialized, that bit is set by the driver to
  264. * signal we can use this engine in later code paths.
  265. * Each bit is cleared upon reset of its corresponding H/W
  266. * engine.
  267. * @multi_msi_mode: whether we are working in multi MSI single MSI mode.
  268. * Multi MSI is possible only with IOMMU enabled.
  269. * @mmu_cache_inv_pi: PI for MMU cache invalidation flow. The H/W expects an
  270. * 8-bit value so use u8.
  271. */
  272. struct gaudi_device {
  273. int (*cpucp_info_get)(struct hl_device *hdev);
  274. /* TODO: remove hw_queues_lock after moving to scheduler code */
  275. spinlock_t hw_queues_lock;
  276. struct gaudi_internal_qman_info internal_qmans[GAUDI_QUEUE_ID_SIZE];
  277. struct gaudi_collective_properties collective_props;
  278. u64 hbm_bar_cur_addr;
  279. u32 events[GAUDI_EVENT_SIZE];
  280. u32 events_stat[GAUDI_EVENT_SIZE];
  281. u32 events_stat_aggregate[GAUDI_EVENT_SIZE];
  282. u32 hw_cap_initialized;
  283. u8 multi_msi_mode;
  284. u8 mmu_cache_inv_pi;
  285. };
  286. void gaudi_init_security(struct hl_device *hdev);
  287. void gaudi_ack_protection_bits_errors(struct hl_device *hdev);
  288. int gaudi_debug_coresight(struct hl_device *hdev, struct hl_ctx *ctx, void *data);
  289. void gaudi_halt_coresight(struct hl_device *hdev, struct hl_ctx *ctx);
  290. void gaudi_mmu_prepare_reg(struct hl_device *hdev, u64 reg, u32 asid);
  291. #endif /* GAUDIP_H_ */