xref: /dpdk/drivers/common/dpaax/caamflib/rta/seq_in_out_ptr_cmd.h (revision c0ded849131598760a25e96ff368d035838af0b3)
1*c0ded849SHemant Agrawal /* SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0)
2*c0ded849SHemant Agrawal  *
3*c0ded849SHemant Agrawal  * Copyright 2008-2016 Freescale Semiconductor Inc.
4*c0ded849SHemant Agrawal  * Copyright 2016,2019 NXP
5*c0ded849SHemant Agrawal  */
6*c0ded849SHemant Agrawal 
7*c0ded849SHemant Agrawal #ifndef __RTA_SEQ_IN_OUT_PTR_CMD_H__
8*c0ded849SHemant Agrawal #define __RTA_SEQ_IN_OUT_PTR_CMD_H__
9*c0ded849SHemant Agrawal 
10*c0ded849SHemant Agrawal extern enum rta_sec_era rta_sec_era;
11*c0ded849SHemant Agrawal 
12*c0ded849SHemant Agrawal /* Allowed SEQ IN PTR flags for each SEC Era. */
13*c0ded849SHemant Agrawal static const uint32_t seq_in_ptr_flags[] = {
14*c0ded849SHemant Agrawal 	RBS | INL | SGF | PRE | EXT | RTO,
15*c0ded849SHemant Agrawal 	RBS | INL | SGF | PRE | EXT | RTO | RJD,
16*c0ded849SHemant Agrawal 	RBS | INL | SGF | PRE | EXT | RTO | RJD,
17*c0ded849SHemant Agrawal 	RBS | INL | SGF | PRE | EXT | RTO | RJD,
18*c0ded849SHemant Agrawal 	RBS | INL | SGF | PRE | EXT | RTO | RJD | SOP,
19*c0ded849SHemant Agrawal 	RBS | INL | SGF | PRE | EXT | RTO | RJD | SOP,
20*c0ded849SHemant Agrawal 	RBS | INL | SGF | PRE | EXT | RTO | RJD | SOP,
21*c0ded849SHemant Agrawal 	RBS | INL | SGF | PRE | EXT | RTO | RJD | SOP,
22*c0ded849SHemant Agrawal 	RBS | INL | SGF | PRE | EXT | RTO | RJD | SOP,
23*c0ded849SHemant Agrawal 	RBS | INL | SGF | PRE | EXT | RTO | RJD | SOP
24*c0ded849SHemant Agrawal };
25*c0ded849SHemant Agrawal 
26*c0ded849SHemant Agrawal /* Allowed SEQ OUT PTR flags for each SEC Era. */
27*c0ded849SHemant Agrawal static const uint32_t seq_out_ptr_flags[] = {
28*c0ded849SHemant Agrawal 	SGF | PRE | EXT,
29*c0ded849SHemant Agrawal 	SGF | PRE | EXT | RTO,
30*c0ded849SHemant Agrawal 	SGF | PRE | EXT | RTO,
31*c0ded849SHemant Agrawal 	SGF | PRE | EXT | RTO,
32*c0ded849SHemant Agrawal 	SGF | PRE | EXT | RTO | RST | EWS,
33*c0ded849SHemant Agrawal 	SGF | PRE | EXT | RTO | RST | EWS,
34*c0ded849SHemant Agrawal 	SGF | PRE | EXT | RTO | RST | EWS,
35*c0ded849SHemant Agrawal 	SGF | PRE | EXT | RTO | RST | EWS,
36*c0ded849SHemant Agrawal 	SGF | PRE | EXT | RTO | RST | EWS,
37*c0ded849SHemant Agrawal 	SGF | PRE | EXT | RTO | RST | EWS
38*c0ded849SHemant Agrawal };
39*c0ded849SHemant Agrawal 
40*c0ded849SHemant Agrawal static inline int
rta_seq_in_ptr(struct program * program,uint64_t src,uint32_t length,uint32_t flags)41*c0ded849SHemant Agrawal rta_seq_in_ptr(struct program *program, uint64_t src,
42*c0ded849SHemant Agrawal 	       uint32_t length, uint32_t flags)
43*c0ded849SHemant Agrawal {
44*c0ded849SHemant Agrawal 	uint32_t opcode = CMD_SEQ_IN_PTR;
45*c0ded849SHemant Agrawal 	unsigned int start_pc = program->current_pc;
46*c0ded849SHemant Agrawal 	int ret = -EINVAL;
47*c0ded849SHemant Agrawal 
48*c0ded849SHemant Agrawal 	/* Parameters checking */
49*c0ded849SHemant Agrawal 	if ((flags & RTO) && (flags & PRE)) {
50*c0ded849SHemant Agrawal 		pr_err("SEQ IN PTR: Invalid usage of RTO and PRE flags\n");
51*c0ded849SHemant Agrawal 		goto err;
52*c0ded849SHemant Agrawal 	}
53*c0ded849SHemant Agrawal 	if (flags & ~seq_in_ptr_flags[rta_sec_era]) {
54*c0ded849SHemant Agrawal 		pr_err("SEQ IN PTR: Flag(s) not supported by SEC Era %d\n",
55*c0ded849SHemant Agrawal 		       USER_SEC_ERA(rta_sec_era));
56*c0ded849SHemant Agrawal 		goto err;
57*c0ded849SHemant Agrawal 	}
58*c0ded849SHemant Agrawal 	if ((flags & INL) && (flags & RJD)) {
59*c0ded849SHemant Agrawal 		pr_err("SEQ IN PTR: Invalid usage of INL and RJD flags\n");
60*c0ded849SHemant Agrawal 		goto err;
61*c0ded849SHemant Agrawal 	}
62*c0ded849SHemant Agrawal 	if ((src) && (flags & (SOP | RTO | PRE))) {
63*c0ded849SHemant Agrawal 		pr_err("SEQ IN PTR: Invalid usage of RTO or PRE flag\n");
64*c0ded849SHemant Agrawal 		goto err;
65*c0ded849SHemant Agrawal 	}
66*c0ded849SHemant Agrawal 	if ((flags & SOP) && (flags & (RBS | PRE | RTO | EXT))) {
67*c0ded849SHemant Agrawal 		pr_err("SEQ IN PTR: Invalid usage of SOP and (RBS or PRE or RTO or EXT) flags\n");
68*c0ded849SHemant Agrawal 		goto err;
69*c0ded849SHemant Agrawal 	}
70*c0ded849SHemant Agrawal 
71*c0ded849SHemant Agrawal 	/* write flag fields */
72*c0ded849SHemant Agrawal 	if (flags & RBS)
73*c0ded849SHemant Agrawal 		opcode |= SQIN_RBS;
74*c0ded849SHemant Agrawal 	if (flags & INL)
75*c0ded849SHemant Agrawal 		opcode |= SQIN_INL;
76*c0ded849SHemant Agrawal 	if (flags & SGF)
77*c0ded849SHemant Agrawal 		opcode |= SQIN_SGF;
78*c0ded849SHemant Agrawal 	if (flags & PRE)
79*c0ded849SHemant Agrawal 		opcode |= SQIN_PRE;
80*c0ded849SHemant Agrawal 	if (flags & RTO)
81*c0ded849SHemant Agrawal 		opcode |= SQIN_RTO;
82*c0ded849SHemant Agrawal 	if (flags & RJD)
83*c0ded849SHemant Agrawal 		opcode |= SQIN_RJD;
84*c0ded849SHemant Agrawal 	if (flags & SOP)
85*c0ded849SHemant Agrawal 		opcode |= SQIN_SOP;
86*c0ded849SHemant Agrawal 	if ((length >> 16) || (flags & EXT)) {
87*c0ded849SHemant Agrawal 		if (flags & SOP) {
88*c0ded849SHemant Agrawal 			pr_err("SEQ IN PTR: Invalid usage of SOP and EXT flags\n");
89*c0ded849SHemant Agrawal 			goto err;
90*c0ded849SHemant Agrawal 		}
91*c0ded849SHemant Agrawal 
92*c0ded849SHemant Agrawal 		opcode |= SQIN_EXT;
93*c0ded849SHemant Agrawal 	} else {
94*c0ded849SHemant Agrawal 		opcode |= length & SQIN_LEN_MASK;
95*c0ded849SHemant Agrawal 	}
96*c0ded849SHemant Agrawal 
97*c0ded849SHemant Agrawal 	__rta_out32(program, opcode);
98*c0ded849SHemant Agrawal 	program->current_instruction++;
99*c0ded849SHemant Agrawal 
100*c0ded849SHemant Agrawal 	/* write pointer or immediate data field */
101*c0ded849SHemant Agrawal 	if (!(opcode & (SQIN_PRE | SQIN_RTO | SQIN_SOP)))
102*c0ded849SHemant Agrawal 		__rta_out64(program, program->ps, src);
103*c0ded849SHemant Agrawal 
104*c0ded849SHemant Agrawal 	/* write extended length field */
105*c0ded849SHemant Agrawal 	if (opcode & SQIN_EXT)
106*c0ded849SHemant Agrawal 		__rta_out32(program, length);
107*c0ded849SHemant Agrawal 
108*c0ded849SHemant Agrawal 	return (int)start_pc;
109*c0ded849SHemant Agrawal 
110*c0ded849SHemant Agrawal  err:
111*c0ded849SHemant Agrawal 	program->first_error_pc = start_pc;
112*c0ded849SHemant Agrawal 	program->current_instruction++;
113*c0ded849SHemant Agrawal 	return ret;
114*c0ded849SHemant Agrawal }
115*c0ded849SHemant Agrawal 
116*c0ded849SHemant Agrawal static inline int
rta_seq_out_ptr(struct program * program,uint64_t dst,uint32_t length,uint32_t flags)117*c0ded849SHemant Agrawal rta_seq_out_ptr(struct program *program, uint64_t dst,
118*c0ded849SHemant Agrawal 		uint32_t length, uint32_t flags)
119*c0ded849SHemant Agrawal {
120*c0ded849SHemant Agrawal 	uint32_t opcode = CMD_SEQ_OUT_PTR;
121*c0ded849SHemant Agrawal 	unsigned int start_pc = program->current_pc;
122*c0ded849SHemant Agrawal 	int ret = -EINVAL;
123*c0ded849SHemant Agrawal 
124*c0ded849SHemant Agrawal 	/* Parameters checking */
125*c0ded849SHemant Agrawal 	if (flags & ~seq_out_ptr_flags[rta_sec_era]) {
126*c0ded849SHemant Agrawal 		pr_err("SEQ OUT PTR: Flag(s) not supported by SEC Era %d\n",
127*c0ded849SHemant Agrawal 		       USER_SEC_ERA(rta_sec_era));
128*c0ded849SHemant Agrawal 		goto err;
129*c0ded849SHemant Agrawal 	}
130*c0ded849SHemant Agrawal 	if ((flags & RTO) && (flags & PRE)) {
131*c0ded849SHemant Agrawal 		pr_err("SEQ OUT PTR: Invalid usage of RTO and PRE flags\n");
132*c0ded849SHemant Agrawal 		goto err;
133*c0ded849SHemant Agrawal 	}
134*c0ded849SHemant Agrawal 	if ((dst) && (flags & (RTO | PRE))) {
135*c0ded849SHemant Agrawal 		pr_err("SEQ OUT PTR: Invalid usage of RTO or PRE flag\n");
136*c0ded849SHemant Agrawal 		goto err;
137*c0ded849SHemant Agrawal 	}
138*c0ded849SHemant Agrawal 	if ((flags & RST) && !(flags & RTO)) {
139*c0ded849SHemant Agrawal 		pr_err("SEQ OUT PTR: RST flag must be used with RTO flag\n");
140*c0ded849SHemant Agrawal 		goto err;
141*c0ded849SHemant Agrawal 	}
142*c0ded849SHemant Agrawal 
143*c0ded849SHemant Agrawal 	/* write flag fields */
144*c0ded849SHemant Agrawal 	if (flags & SGF)
145*c0ded849SHemant Agrawal 		opcode |= SQOUT_SGF;
146*c0ded849SHemant Agrawal 	if (flags & PRE)
147*c0ded849SHemant Agrawal 		opcode |= SQOUT_PRE;
148*c0ded849SHemant Agrawal 	if (flags & RTO)
149*c0ded849SHemant Agrawal 		opcode |= SQOUT_RTO;
150*c0ded849SHemant Agrawal 	if (flags & RST)
151*c0ded849SHemant Agrawal 		opcode |= SQOUT_RST;
152*c0ded849SHemant Agrawal 	if (flags & EWS)
153*c0ded849SHemant Agrawal 		opcode |= SQOUT_EWS;
154*c0ded849SHemant Agrawal 	if ((length >> 16) || (flags & EXT))
155*c0ded849SHemant Agrawal 		opcode |= SQOUT_EXT;
156*c0ded849SHemant Agrawal 	else
157*c0ded849SHemant Agrawal 		opcode |= length & SQOUT_LEN_MASK;
158*c0ded849SHemant Agrawal 
159*c0ded849SHemant Agrawal 	__rta_out32(program, opcode);
160*c0ded849SHemant Agrawal 	program->current_instruction++;
161*c0ded849SHemant Agrawal 
162*c0ded849SHemant Agrawal 	/* write pointer or immediate data field */
163*c0ded849SHemant Agrawal 	if (!(opcode & (SQOUT_PRE | SQOUT_RTO)))
164*c0ded849SHemant Agrawal 		__rta_out64(program, program->ps, dst);
165*c0ded849SHemant Agrawal 
166*c0ded849SHemant Agrawal 	/* write extended length field */
167*c0ded849SHemant Agrawal 	if (opcode & SQOUT_EXT)
168*c0ded849SHemant Agrawal 		__rta_out32(program, length);
169*c0ded849SHemant Agrawal 
170*c0ded849SHemant Agrawal 	return (int)start_pc;
171*c0ded849SHemant Agrawal 
172*c0ded849SHemant Agrawal  err:
173*c0ded849SHemant Agrawal 	program->first_error_pc = start_pc;
174*c0ded849SHemant Agrawal 	program->current_instruction++;
175*c0ded849SHemant Agrawal 	return ret;
176*c0ded849SHemant Agrawal }
177*c0ded849SHemant Agrawal 
178*c0ded849SHemant Agrawal #endif /* __RTA_SEQ_IN_OUT_PTR_CMD_H__ */
179