xref: /linux/drivers/accel/habanalabs/include/goya/goya_packets.h (revision 34dc1baba215b826e454b8d19e4f24adbeb7d00d)
1 /* SPDX-License-Identifier: GPL-2.0
2  *
3  * Copyright 2017-2018 HabanaLabs, Ltd.
4  * All Rights Reserved.
5  *
6  */
7 
8 #ifndef GOYA_PACKETS_H
9 #define GOYA_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_MSG_PROT = 0x7,
23 	PACKET_FENCE = 0x8,
24 	PACKET_LIN_DMA = 0x9,
25 	PACKET_NOP = 0xA,
26 	PACKET_STOP = 0xB,
27 	MAX_PACKET_ID = (PACKET_HEADER_PACKET_ID_MASK >>
28 				PACKET_HEADER_PACKET_ID_SHIFT) + 1
29 };
30 
31 #define GOYA_PKT_CTL_OPCODE_SHIFT	24
32 #define GOYA_PKT_CTL_OPCODE_MASK	0x1F000000
33 
34 #define GOYA_PKT_CTL_EB_SHIFT		29
35 #define GOYA_PKT_CTL_EB_MASK		0x20000000
36 
37 #define GOYA_PKT_CTL_RB_SHIFT		30
38 #define GOYA_PKT_CTL_RB_MASK		0x40000000
39 
40 #define GOYA_PKT_CTL_MB_SHIFT		31
41 #define GOYA_PKT_CTL_MB_MASK		0x80000000
42 
43 /* All packets have, at least, an 8-byte header, which contains
44  * the packet type. The kernel driver uses the packet header for packet
45  * validation and to perform any necessary required preparation before
46  * sending them off to the hardware.
47  */
48 struct goya_packet {
49 	__le64 header;
50 	/* The rest of the packet data follows. Use the corresponding
51 	 * packet_XXX struct to deference the data, based on packet type
52 	 */
53 	u8 contents[];
54 };
55 
56 struct packet_nop {
57 	__le32 reserved;
58 	__le32 ctl;
59 };
60 
61 struct packet_stop {
62 	__le32 reserved;
63 	__le32 ctl;
64 };
65 
66 #define GOYA_PKT_WREG32_CTL_REG_OFFSET_SHIFT	0
67 #define GOYA_PKT_WREG32_CTL_REG_OFFSET_MASK	0x0000FFFF
68 
69 struct packet_wreg32 {
70 	__le32 value;
71 	__le32 ctl;
72 };
73 
74 struct packet_wreg_bulk {
75 	__le32 size64;
76 	__le32 ctl;
77 	__le64 values[]; /* data starts here */
78 };
79 
80 struct packet_msg_long {
81 	__le32 value;
82 	__le32 ctl;
83 	__le64 addr;
84 };
85 
86 struct packet_msg_short {
87 	__le32 value;
88 	__le32 ctl;
89 };
90 
91 struct packet_msg_prot {
92 	__le32 value;
93 	__le32 ctl;
94 	__le64 addr;
95 };
96 
97 struct packet_fence {
98 	__le32 cfg;
99 	__le32 ctl;
100 };
101 
102 #define GOYA_PKT_LIN_DMA_CTL_WO_SHIFT		0
103 #define GOYA_PKT_LIN_DMA_CTL_WO_MASK		0x00000001
104 
105 #define GOYA_PKT_LIN_DMA_CTL_RDCOMP_SHIFT	1
106 #define GOYA_PKT_LIN_DMA_CTL_RDCOMP_MASK	0x00000002
107 
108 #define GOYA_PKT_LIN_DMA_CTL_WRCOMP_SHIFT	2
109 #define GOYA_PKT_LIN_DMA_CTL_WRCOMP_MASK	0x00000004
110 
111 #define GOYA_PKT_LIN_DMA_CTL_MEMSET_SHIFT	6
112 #define GOYA_PKT_LIN_DMA_CTL_MEMSET_MASK	0x00000040
113 
114 #define GOYA_PKT_LIN_DMA_CTL_DMA_DIR_SHIFT	20
115 #define GOYA_PKT_LIN_DMA_CTL_DMA_DIR_MASK	0x00700000
116 
117 struct packet_lin_dma {
118 	__le32 tsize;
119 	__le32 ctl;
120 	__le64 src_addr;
121 	__le64 dst_addr;
122 };
123 
124 struct packet_cp_dma {
125 	__le32 tsize;
126 	__le32 ctl;
127 	__le64 src_addr;
128 };
129 
130 #endif /* GOYA_PACKETS_H */
131