18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0
28c2ecf20Sopenharmony_ci *
38c2ecf20Sopenharmony_ci * Copyright 2017-2020 HabanaLabs, Ltd.
48c2ecf20Sopenharmony_ci * All Rights Reserved.
58c2ecf20Sopenharmony_ci *
68c2ecf20Sopenharmony_ci */
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_ci#ifndef GAUDI_PACKETS_H
98c2ecf20Sopenharmony_ci#define GAUDI_PACKETS_H
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci#include <linux/types.h>
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_ci#define PACKET_HEADER_PACKET_ID_SHIFT		56
148c2ecf20Sopenharmony_ci#define PACKET_HEADER_PACKET_ID_MASK		0x1F00000000000000ull
158c2ecf20Sopenharmony_ci
168c2ecf20Sopenharmony_cienum packet_id {
178c2ecf20Sopenharmony_ci	PACKET_WREG_32 = 0x1,
188c2ecf20Sopenharmony_ci	PACKET_WREG_BULK = 0x2,
198c2ecf20Sopenharmony_ci	PACKET_MSG_LONG = 0x3,
208c2ecf20Sopenharmony_ci	PACKET_MSG_SHORT = 0x4,
218c2ecf20Sopenharmony_ci	PACKET_CP_DMA = 0x5,
228c2ecf20Sopenharmony_ci	PACKET_REPEAT = 0x6,
238c2ecf20Sopenharmony_ci	PACKET_MSG_PROT = 0x7,
248c2ecf20Sopenharmony_ci	PACKET_FENCE = 0x8,
258c2ecf20Sopenharmony_ci	PACKET_LIN_DMA = 0x9,
268c2ecf20Sopenharmony_ci	PACKET_NOP = 0xA,
278c2ecf20Sopenharmony_ci	PACKET_STOP = 0xB,
288c2ecf20Sopenharmony_ci	PACKET_ARB_POINT = 0xC,
298c2ecf20Sopenharmony_ci	PACKET_WAIT = 0xD,
308c2ecf20Sopenharmony_ci	PACKET_LOAD_AND_EXE = 0xF,
318c2ecf20Sopenharmony_ci	MAX_PACKET_ID = (PACKET_HEADER_PACKET_ID_MASK >>
328c2ecf20Sopenharmony_ci				PACKET_HEADER_PACKET_ID_SHIFT) + 1
338c2ecf20Sopenharmony_ci};
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_ci#define GAUDI_PKT_CTL_OPCODE_SHIFT	24
368c2ecf20Sopenharmony_ci#define GAUDI_PKT_CTL_OPCODE_MASK	0x1F000000
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ci#define GAUDI_PKT_CTL_EB_SHIFT		29
398c2ecf20Sopenharmony_ci#define GAUDI_PKT_CTL_EB_MASK		0x20000000
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_ci#define GAUDI_PKT_CTL_RB_SHIFT		30
428c2ecf20Sopenharmony_ci#define GAUDI_PKT_CTL_RB_MASK		0x40000000
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_ci#define GAUDI_PKT_CTL_MB_SHIFT		31
458c2ecf20Sopenharmony_ci#define GAUDI_PKT_CTL_MB_MASK		0x80000000
468c2ecf20Sopenharmony_ci
478c2ecf20Sopenharmony_ci/* All packets have, at least, an 8-byte header, which contains
488c2ecf20Sopenharmony_ci * the packet type. The kernel driver uses the packet header for packet
498c2ecf20Sopenharmony_ci * validation and to perform any necessary required preparation before
508c2ecf20Sopenharmony_ci * sending them off to the hardware.
518c2ecf20Sopenharmony_ci */
528c2ecf20Sopenharmony_cistruct gaudi_packet {
538c2ecf20Sopenharmony_ci	__le64 header;
548c2ecf20Sopenharmony_ci	/* The rest of the packet data follows. Use the corresponding
558c2ecf20Sopenharmony_ci	 * packet_XXX struct to deference the data, based on packet type
568c2ecf20Sopenharmony_ci	 */
578c2ecf20Sopenharmony_ci	u8 contents[0];
588c2ecf20Sopenharmony_ci};
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_cistruct packet_nop {
618c2ecf20Sopenharmony_ci	__le32 reserved;
628c2ecf20Sopenharmony_ci	__le32 ctl;
638c2ecf20Sopenharmony_ci};
648c2ecf20Sopenharmony_ci
658c2ecf20Sopenharmony_cistruct packet_stop {
668c2ecf20Sopenharmony_ci	__le32 reserved;
678c2ecf20Sopenharmony_ci	__le32 ctl;
688c2ecf20Sopenharmony_ci};
698c2ecf20Sopenharmony_ci
708c2ecf20Sopenharmony_cistruct packet_wreg32 {
718c2ecf20Sopenharmony_ci	__le32 value;
728c2ecf20Sopenharmony_ci	__le32 ctl;
738c2ecf20Sopenharmony_ci};
748c2ecf20Sopenharmony_ci
758c2ecf20Sopenharmony_cistruct packet_wreg_bulk {
768c2ecf20Sopenharmony_ci	__le32 size64;
778c2ecf20Sopenharmony_ci	__le32 ctl;
788c2ecf20Sopenharmony_ci	__le64 values[0]; /* data starts here */
798c2ecf20Sopenharmony_ci};
808c2ecf20Sopenharmony_ci
818c2ecf20Sopenharmony_cistruct packet_msg_long {
828c2ecf20Sopenharmony_ci	__le32 value;
838c2ecf20Sopenharmony_ci	__le32 ctl;
848c2ecf20Sopenharmony_ci	__le64 addr;
858c2ecf20Sopenharmony_ci};
868c2ecf20Sopenharmony_ci
878c2ecf20Sopenharmony_ci#define GAUDI_PKT_SHORT_VAL_SOB_SYNC_VAL_SHIFT	0
888c2ecf20Sopenharmony_ci#define GAUDI_PKT_SHORT_VAL_SOB_SYNC_VAL_MASK	0x00007FFF
898c2ecf20Sopenharmony_ci
908c2ecf20Sopenharmony_ci#define GAUDI_PKT_SHORT_VAL_SOB_MOD_SHIFT	31
918c2ecf20Sopenharmony_ci#define GAUDI_PKT_SHORT_VAL_SOB_MOD_MASK	0x80000000
928c2ecf20Sopenharmony_ci
938c2ecf20Sopenharmony_ci#define GAUDI_PKT_SHORT_VAL_MON_SYNC_GID_SHIFT	0
948c2ecf20Sopenharmony_ci#define GAUDI_PKT_SHORT_VAL_MON_SYNC_GID_MASK	0x000000FF
958c2ecf20Sopenharmony_ci
968c2ecf20Sopenharmony_ci#define GAUDI_PKT_SHORT_VAL_MON_MASK_SHIFT	8
978c2ecf20Sopenharmony_ci#define GAUDI_PKT_SHORT_VAL_MON_MASK_MASK	0x0000FF00
988c2ecf20Sopenharmony_ci
998c2ecf20Sopenharmony_ci#define GAUDI_PKT_SHORT_VAL_MON_MODE_SHIFT	16
1008c2ecf20Sopenharmony_ci#define GAUDI_PKT_SHORT_VAL_MON_MODE_MASK	0x00010000
1018c2ecf20Sopenharmony_ci
1028c2ecf20Sopenharmony_ci#define GAUDI_PKT_SHORT_VAL_MON_SYNC_VAL_SHIFT	17
1038c2ecf20Sopenharmony_ci#define GAUDI_PKT_SHORT_VAL_MON_SYNC_VAL_MASK	0xFFFE0000
1048c2ecf20Sopenharmony_ci
1058c2ecf20Sopenharmony_ci#define GAUDI_PKT_SHORT_CTL_ADDR_SHIFT		0
1068c2ecf20Sopenharmony_ci#define GAUDI_PKT_SHORT_CTL_ADDR_MASK		0x0000FFFF
1078c2ecf20Sopenharmony_ci
1088c2ecf20Sopenharmony_ci#define GAUDI_PKT_SHORT_CTL_OP_SHIFT		20
1098c2ecf20Sopenharmony_ci#define GAUDI_PKT_SHORT_CTL_OP_MASK		0x00300000
1108c2ecf20Sopenharmony_ci
1118c2ecf20Sopenharmony_ci#define GAUDI_PKT_SHORT_CTL_BASE_SHIFT		22
1128c2ecf20Sopenharmony_ci#define GAUDI_PKT_SHORT_CTL_BASE_MASK		0x00C00000
1138c2ecf20Sopenharmony_ci
1148c2ecf20Sopenharmony_ci#define GAUDI_PKT_SHORT_CTL_OPCODE_SHIFT	24
1158c2ecf20Sopenharmony_ci#define GAUDI_PKT_SHORT_CTL_OPCODE_MASK		0x1F000000
1168c2ecf20Sopenharmony_ci
1178c2ecf20Sopenharmony_ci#define GAUDI_PKT_SHORT_CTL_EB_SHIFT		29
1188c2ecf20Sopenharmony_ci#define GAUDI_PKT_SHORT_CTL_EB_MASK		0x20000000
1198c2ecf20Sopenharmony_ci
1208c2ecf20Sopenharmony_ci#define GAUDI_PKT_SHORT_CTL_RB_SHIFT		30
1218c2ecf20Sopenharmony_ci#define GAUDI_PKT_SHORT_CTL_RB_MASK		0x40000000
1228c2ecf20Sopenharmony_ci
1238c2ecf20Sopenharmony_ci#define GAUDI_PKT_SHORT_CTL_MB_SHIFT		31
1248c2ecf20Sopenharmony_ci#define GAUDI_PKT_SHORT_CTL_MB_MASK		0x80000000
1258c2ecf20Sopenharmony_ci
1268c2ecf20Sopenharmony_cistruct packet_msg_short {
1278c2ecf20Sopenharmony_ci	__le32 value;
1288c2ecf20Sopenharmony_ci	__le32 ctl;
1298c2ecf20Sopenharmony_ci};
1308c2ecf20Sopenharmony_ci
1318c2ecf20Sopenharmony_cistruct packet_msg_prot {
1328c2ecf20Sopenharmony_ci	__le32 value;
1338c2ecf20Sopenharmony_ci	__le32 ctl;
1348c2ecf20Sopenharmony_ci	__le64 addr;
1358c2ecf20Sopenharmony_ci};
1368c2ecf20Sopenharmony_ci
1378c2ecf20Sopenharmony_ci#define GAUDI_PKT_FENCE_CFG_DEC_VAL_SHIFT	0
1388c2ecf20Sopenharmony_ci#define GAUDI_PKT_FENCE_CFG_DEC_VAL_MASK	0x0000000F
1398c2ecf20Sopenharmony_ci
1408c2ecf20Sopenharmony_ci#define GAUDI_PKT_FENCE_CFG_TARGET_VAL_SHIFT	16
1418c2ecf20Sopenharmony_ci#define GAUDI_PKT_FENCE_CFG_TARGET_VAL_MASK	0x00FF0000
1428c2ecf20Sopenharmony_ci
1438c2ecf20Sopenharmony_ci#define GAUDI_PKT_FENCE_CFG_ID_SHIFT		30
1448c2ecf20Sopenharmony_ci#define GAUDI_PKT_FENCE_CFG_ID_MASK		0xC0000000
1458c2ecf20Sopenharmony_ci
1468c2ecf20Sopenharmony_ci#define GAUDI_PKT_FENCE_CTL_PRED_SHIFT		0
1478c2ecf20Sopenharmony_ci#define GAUDI_PKT_FENCE_CTL_PRED_MASK		0x0000001F
1488c2ecf20Sopenharmony_ci
1498c2ecf20Sopenharmony_ci#define GAUDI_PKT_FENCE_CTL_OPCODE_SHIFT	24
1508c2ecf20Sopenharmony_ci#define GAUDI_PKT_FENCE_CTL_OPCODE_MASK		0x1F000000
1518c2ecf20Sopenharmony_ci
1528c2ecf20Sopenharmony_ci#define GAUDI_PKT_FENCE_CTL_EB_SHIFT		29
1538c2ecf20Sopenharmony_ci#define GAUDI_PKT_FENCE_CTL_EB_MASK		0x20000000
1548c2ecf20Sopenharmony_ci
1558c2ecf20Sopenharmony_ci#define GAUDI_PKT_FENCE_CTL_RB_SHIFT		30
1568c2ecf20Sopenharmony_ci#define GAUDI_PKT_FENCE_CTL_RB_MASK		0x40000000
1578c2ecf20Sopenharmony_ci
1588c2ecf20Sopenharmony_ci#define GAUDI_PKT_FENCE_CTL_MB_SHIFT		31
1598c2ecf20Sopenharmony_ci#define GAUDI_PKT_FENCE_CTL_MB_MASK		0x80000000
1608c2ecf20Sopenharmony_ci
1618c2ecf20Sopenharmony_cistruct packet_fence {
1628c2ecf20Sopenharmony_ci	__le32 cfg;
1638c2ecf20Sopenharmony_ci	__le32 ctl;
1648c2ecf20Sopenharmony_ci};
1658c2ecf20Sopenharmony_ci
1668c2ecf20Sopenharmony_ci#define GAUDI_PKT_LIN_DMA_CTL_WRCOMP_EN_SHIFT	0
1678c2ecf20Sopenharmony_ci#define GAUDI_PKT_LIN_DMA_CTL_WRCOMP_EN_MASK	0x00000001
1688c2ecf20Sopenharmony_ci
1698c2ecf20Sopenharmony_ci#define GAUDI_PKT_LIN_DMA_CTL_LIN_SHIFT		3
1708c2ecf20Sopenharmony_ci#define GAUDI_PKT_LIN_DMA_CTL_LIN_MASK		0x00000008
1718c2ecf20Sopenharmony_ci
1728c2ecf20Sopenharmony_ci#define GAUDI_PKT_LIN_DMA_CTL_MEMSET_SHIFT	4
1738c2ecf20Sopenharmony_ci#define GAUDI_PKT_LIN_DMA_CTL_MEMSET_MASK	0x00000010
1748c2ecf20Sopenharmony_ci
1758c2ecf20Sopenharmony_ci#define GAUDI_PKT_LIN_DMA_DST_ADDR_SHIFT	0
1768c2ecf20Sopenharmony_ci#define GAUDI_PKT_LIN_DMA_DST_ADDR_MASK		0x00FFFFFFFFFFFFFFull
1778c2ecf20Sopenharmony_ci
1788c2ecf20Sopenharmony_cistruct packet_lin_dma {
1798c2ecf20Sopenharmony_ci	__le32 tsize;
1808c2ecf20Sopenharmony_ci	__le32 ctl;
1818c2ecf20Sopenharmony_ci	__le64 src_addr;
1828c2ecf20Sopenharmony_ci	__le64 dst_addr;
1838c2ecf20Sopenharmony_ci};
1848c2ecf20Sopenharmony_ci
1858c2ecf20Sopenharmony_cistruct packet_arb_point {
1868c2ecf20Sopenharmony_ci	__le32 cfg;
1878c2ecf20Sopenharmony_ci	__le32 ctl;
1888c2ecf20Sopenharmony_ci};
1898c2ecf20Sopenharmony_ci
1908c2ecf20Sopenharmony_cistruct packet_repeat {
1918c2ecf20Sopenharmony_ci	__le32 cfg;
1928c2ecf20Sopenharmony_ci	__le32 ctl;
1938c2ecf20Sopenharmony_ci};
1948c2ecf20Sopenharmony_ci
1958c2ecf20Sopenharmony_cistruct packet_wait {
1968c2ecf20Sopenharmony_ci	__le32 cfg;
1978c2ecf20Sopenharmony_ci	__le32 ctl;
1988c2ecf20Sopenharmony_ci};
1998c2ecf20Sopenharmony_ci
2008c2ecf20Sopenharmony_ci#define GAUDI_PKT_LOAD_AND_EXE_CFG_DST_SHIFT	0
2018c2ecf20Sopenharmony_ci#define GAUDI_PKT_LOAD_AND_EXE_CFG_DST_MASK	0x00000001
2028c2ecf20Sopenharmony_ci
2038c2ecf20Sopenharmony_cistruct packet_load_and_exe {
2048c2ecf20Sopenharmony_ci	__le32 cfg;
2058c2ecf20Sopenharmony_ci	__le32 ctl;
2068c2ecf20Sopenharmony_ci	__le64 src_addr;
2078c2ecf20Sopenharmony_ci};
2088c2ecf20Sopenharmony_ci
2098c2ecf20Sopenharmony_cistruct packet_cp_dma {
2108c2ecf20Sopenharmony_ci	__le32 tsize;
2118c2ecf20Sopenharmony_ci	__le32 ctl;
2128c2ecf20Sopenharmony_ci	__le64 src_addr;
2138c2ecf20Sopenharmony_ci};
2148c2ecf20Sopenharmony_ci
2158c2ecf20Sopenharmony_ci#endif /* GAUDI_PACKETS_H */
216