1 /* SPDX-License-Identifier: GPL-2.0 2 * 3 * Copyright 2017-2020 HabanaLabs, Ltd. 4 * All Rights Reserved. 5 * 6 */ 7 8 #ifndef GAUDI_PACKETS_H 9 #define GAUDI_PACKETS_H 10 11 #include <linux/types.h> 12 13 #define PACKET_HEADER_PACKET_ID_SHIFT 56 14 #define PACKET_HEADER_PACKET_ID_MASK 0x1F00000000000000ull 15 16 enum packet_id { 17 PACKET_WREG_32 = 0x1, 18 PACKET_WREG_BULK = 0x2, 19 PACKET_MSG_LONG = 0x3, 20 PACKET_MSG_SHORT = 0x4, 21 PACKET_CP_DMA = 0x5, 22 PACKET_REPEAT = 0x6, 23 PACKET_MSG_PROT = 0x7, 24 PACKET_FENCE = 0x8, 25 PACKET_LIN_DMA = 0x9, 26 PACKET_NOP = 0xA, 27 PACKET_STOP = 0xB, 28 PACKET_ARB_POINT = 0xC, 29 PACKET_WAIT = 0xD, 30 PACKET_LOAD_AND_EXE = 0xF, 31 MAX_PACKET_ID = (PACKET_HEADER_PACKET_ID_MASK >> 32 PACKET_HEADER_PACKET_ID_SHIFT) + 1 33 }; 34 35 #define GAUDI_PKT_CTL_OPCODE_SHIFT 24 36 #define GAUDI_PKT_CTL_OPCODE_MASK 0x1F000000 37 38 #define GAUDI_PKT_CTL_EB_SHIFT 29 39 #define GAUDI_PKT_CTL_EB_MASK 0x20000000 40 41 #define GAUDI_PKT_CTL_RB_SHIFT 30 42 #define GAUDI_PKT_CTL_RB_MASK 0x40000000 43 44 #define GAUDI_PKT_CTL_MB_SHIFT 31 45 #define GAUDI_PKT_CTL_MB_MASK 0x80000000 46 47 /* All packets have, at least, an 8-byte header, which contains 48 * the packet type. The kernel driver uses the packet header for packet 49 * validation and to perform any necessary required preparation before 50 * sending them off to the hardware. 51 */ 52 struct gaudi_packet { 53 __le64 header; 54 /* The rest of the packet data follows. Use the corresponding 55 * packet_XXX struct to deference the data, based on packet type 56 */ 57 u8 contents[0]; 58 }; 59 60 struct packet_nop { 61 __le32 reserved; 62 __le32 ctl; 63 }; 64 65 struct packet_stop { 66 __le32 reserved; 67 __le32 ctl; 68 }; 69 70 struct packet_wreg32 { 71 __le32 value; 72 __le32 ctl; 73 }; 74 75 struct packet_wreg_bulk { 76 __le32 size64; 77 __le32 ctl; 78 __le64 values[0]; /* data starts here */ 79 }; 80 81 struct packet_msg_long { 82 __le32 value; 83 __le32 ctl; 84 __le64 addr; 85 }; 86 87 #define GAUDI_PKT_SHORT_VAL_SOB_SYNC_VAL_SHIFT 0 88 #define GAUDI_PKT_SHORT_VAL_SOB_SYNC_VAL_MASK 0x00007FFF 89 90 #define GAUDI_PKT_SHORT_VAL_SOB_MOD_SHIFT 31 91 #define GAUDI_PKT_SHORT_VAL_SOB_MOD_MASK 0x80000000 92 93 #define GAUDI_PKT_SHORT_VAL_MON_SYNC_GID_SHIFT 0 94 #define GAUDI_PKT_SHORT_VAL_MON_SYNC_GID_MASK 0x000000FF 95 96 #define GAUDI_PKT_SHORT_VAL_MON_MASK_SHIFT 8 97 #define GAUDI_PKT_SHORT_VAL_MON_MASK_MASK 0x0000FF00 98 99 #define GAUDI_PKT_SHORT_VAL_MON_MODE_SHIFT 16 100 #define GAUDI_PKT_SHORT_VAL_MON_MODE_MASK 0x00010000 101 102 #define GAUDI_PKT_SHORT_VAL_MON_SYNC_VAL_SHIFT 17 103 #define GAUDI_PKT_SHORT_VAL_MON_SYNC_VAL_MASK 0xFFFE0000 104 105 #define GAUDI_PKT_SHORT_CTL_ADDR_SHIFT 0 106 #define GAUDI_PKT_SHORT_CTL_ADDR_MASK 0x0000FFFF 107 108 #define GAUDI_PKT_SHORT_CTL_OP_SHIFT 20 109 #define GAUDI_PKT_SHORT_CTL_OP_MASK 0x00300000 110 111 #define GAUDI_PKT_SHORT_CTL_BASE_SHIFT 22 112 #define GAUDI_PKT_SHORT_CTL_BASE_MASK 0x00C00000 113 114 #define GAUDI_PKT_SHORT_CTL_OPCODE_SHIFT 24 115 #define GAUDI_PKT_SHORT_CTL_OPCODE_MASK 0x1F000000 116 117 #define GAUDI_PKT_SHORT_CTL_EB_SHIFT 29 118 #define GAUDI_PKT_SHORT_CTL_EB_MASK 0x20000000 119 120 #define GAUDI_PKT_SHORT_CTL_RB_SHIFT 30 121 #define GAUDI_PKT_SHORT_CTL_RB_MASK 0x40000000 122 123 #define GAUDI_PKT_SHORT_CTL_MB_SHIFT 31 124 #define GAUDI_PKT_SHORT_CTL_MB_MASK 0x80000000 125 126 struct packet_msg_short { 127 __le32 value; 128 __le32 ctl; 129 }; 130 131 struct packet_msg_prot { 132 __le32 value; 133 __le32 ctl; 134 __le64 addr; 135 }; 136 137 #define GAUDI_PKT_FENCE_CFG_DEC_VAL_SHIFT 0 138 #define GAUDI_PKT_FENCE_CFG_DEC_VAL_MASK 0x0000000F 139 140 #define GAUDI_PKT_FENCE_CFG_TARGET_VAL_SHIFT 16 141 #define GAUDI_PKT_FENCE_CFG_TARGET_VAL_MASK 0x00FF0000 142 143 #define GAUDI_PKT_FENCE_CFG_ID_SHIFT 30 144 #define GAUDI_PKT_FENCE_CFG_ID_MASK 0xC0000000 145 146 #define GAUDI_PKT_FENCE_CTL_PRED_SHIFT 0 147 #define GAUDI_PKT_FENCE_CTL_PRED_MASK 0x0000001F 148 149 #define GAUDI_PKT_FENCE_CTL_OPCODE_SHIFT 24 150 #define GAUDI_PKT_FENCE_CTL_OPCODE_MASK 0x1F000000 151 152 #define GAUDI_PKT_FENCE_CTL_EB_SHIFT 29 153 #define GAUDI_PKT_FENCE_CTL_EB_MASK 0x20000000 154 155 #define GAUDI_PKT_FENCE_CTL_RB_SHIFT 30 156 #define GAUDI_PKT_FENCE_CTL_RB_MASK 0x40000000 157 158 #define GAUDI_PKT_FENCE_CTL_MB_SHIFT 31 159 #define GAUDI_PKT_FENCE_CTL_MB_MASK 0x80000000 160 161 struct packet_fence { 162 __le32 cfg; 163 __le32 ctl; 164 }; 165 166 #define GAUDI_PKT_LIN_DMA_CTL_WRCOMP_EN_SHIFT 0 167 #define GAUDI_PKT_LIN_DMA_CTL_WRCOMP_EN_MASK 0x00000001 168 169 #define GAUDI_PKT_LIN_DMA_CTL_LIN_SHIFT 3 170 #define GAUDI_PKT_LIN_DMA_CTL_LIN_MASK 0x00000008 171 172 #define GAUDI_PKT_LIN_DMA_CTL_MEMSET_SHIFT 4 173 #define GAUDI_PKT_LIN_DMA_CTL_MEMSET_MASK 0x00000010 174 175 #define GAUDI_PKT_LIN_DMA_DST_ADDR_SHIFT 0 176 #define GAUDI_PKT_LIN_DMA_DST_ADDR_MASK 0x00FFFFFFFFFFFFFFull 177 178 struct packet_lin_dma { 179 __le32 tsize; 180 __le32 ctl; 181 __le64 src_addr; 182 __le64 dst_addr; 183 }; 184 185 struct packet_arb_point { 186 __le32 cfg; 187 __le32 ctl; 188 }; 189 190 struct packet_repeat { 191 __le32 cfg; 192 __le32 ctl; 193 }; 194 195 struct packet_wait { 196 __le32 cfg; 197 __le32 ctl; 198 }; 199 200 #define GAUDI_PKT_LOAD_AND_EXE_CFG_DST_SHIFT 0 201 #define GAUDI_PKT_LOAD_AND_EXE_CFG_DST_MASK 0x00000001 202 203 struct packet_load_and_exe { 204 __le32 cfg; 205 __le32 ctl; 206 __le64 src_addr; 207 }; 208 209 struct packet_cp_dma { 210 __le32 tsize; 211 __le32 ctl; 212 __le64 src_addr; 213 }; 214 215 #endif /* GAUDI_PACKETS_H */ 216