xref: /dpdk/drivers/crypto/dpaa2_sec/mc/dpseci.c (revision 869fede8d6795ea2b1e528f79b93a363eeff3ad0)
1 /* Copyright 2013-2016 Freescale Semiconductor Inc.
2  * Copyright (c) 2016 NXP.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  * * Redistributions of source code must retain the above copyright
7  * notice, this list of conditions and the following disclaimer.
8  * * Redistributions in binary form must reproduce the above copyright
9  * notice, this list of conditions and the following disclaimer in the
10  * documentation and/or other materials provided with the distribution.
11  * * Neither the name of the above-listed copyright holders nor the
12  * names of any contributors may be used to endorse or promote products
13  * derived from this software without specific prior written permission.
14  *
15  *
16  * ALTERNATIVELY, this software may be distributed under the terms of the
17  * GNU General Public License ("GPL") as published by the Free Software
18  * Foundation, either version 2 of that License or (at your option) any
19  * later version.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
25  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31  * POSSIBILITY OF SUCH DAMAGE.
32  */
33 
34 #include <fsl_mc_sys.h>
35 #include <fsl_mc_cmd.h>
36 #include <fsl_dpseci.h>
37 #include <fsl_dpseci_cmd.h>
38 
39 int
40 dpseci_open(struct fsl_mc_io *mc_io,
41 	    uint32_t cmd_flags,
42 	    int dpseci_id,
43 	    uint16_t *token)
44 {
45 	struct mc_command cmd = { 0 };
46 	int err;
47 
48 	/* prepare command */
49 	cmd.header = mc_encode_cmd_header(DPSECI_CMDID_OPEN,
50 					  cmd_flags,
51 					  0);
52 	DPSECI_CMD_OPEN(cmd, dpseci_id);
53 
54 	/* send command to mc */
55 	err = mc_send_command(mc_io, &cmd);
56 	if (err)
57 		return err;
58 
59 	/* retrieve response parameters */
60 	*token = MC_CMD_HDR_READ_TOKEN(cmd.header);
61 
62 	return 0;
63 }
64 
65 int
66 dpseci_close(struct fsl_mc_io *mc_io,
67 	     uint32_t cmd_flags,
68 	     uint16_t token)
69 {
70 	struct mc_command cmd = { 0 };
71 
72 	/* prepare command */
73 	cmd.header = mc_encode_cmd_header(DPSECI_CMDID_CLOSE,
74 					  cmd_flags,
75 					  token);
76 
77 	/* send command to mc */
78 	return mc_send_command(mc_io, &cmd);
79 }
80 
81 int
82 dpseci_create(struct fsl_mc_io *mc_io,
83 	      uint16_t dprc_token,
84 	      uint32_t cmd_flags,
85 	      const struct dpseci_cfg *cfg,
86 	      uint32_t *obj_id)
87 {
88 	struct mc_command cmd = { 0 };
89 	int err;
90 
91 	/* prepare command */
92 	cmd.header = mc_encode_cmd_header(DPSECI_CMDID_CREATE,
93 					  cmd_flags,
94 					  dprc_token);
95 	DPSECI_CMD_CREATE(cmd, cfg);
96 
97 	/* send command to mc */
98 	err = mc_send_command(mc_io, &cmd);
99 	if (err)
100 		return err;
101 
102 	/* retrieve response parameters */
103 	CMD_CREATE_RSP_GET_OBJ_ID_PARAM0(cmd, *obj_id);
104 
105 	return 0;
106 }
107 
108 int
109 dpseci_destroy(struct fsl_mc_io	*mc_io,
110 	       uint16_t	dprc_token,
111 	       uint32_t	cmd_flags,
112 	       uint32_t	object_id)
113 {
114 	struct mc_command cmd = { 0 };
115 
116 	/* prepare command */
117 	cmd.header = mc_encode_cmd_header(DPSECI_CMDID_DESTROY,
118 					  cmd_flags,
119 					  dprc_token);
120 	/* set object id to destroy */
121 	CMD_DESTROY_SET_OBJ_ID_PARAM0(cmd, object_id);
122 	/* send command to mc */
123 	return mc_send_command(mc_io, &cmd);
124 }
125 
126 int
127 dpseci_enable(struct fsl_mc_io *mc_io,
128 	      uint32_t cmd_flags,
129 	      uint16_t token)
130 {
131 	struct mc_command cmd = { 0 };
132 
133 	/* prepare command */
134 	cmd.header = mc_encode_cmd_header(DPSECI_CMDID_ENABLE,
135 					  cmd_flags,
136 					  token);
137 
138 	/* send command to mc */
139 	return mc_send_command(mc_io, &cmd);
140 }
141 
142 int
143 dpseci_disable(struct fsl_mc_io *mc_io,
144 	       uint32_t cmd_flags,
145 	       uint16_t token)
146 {
147 	struct mc_command cmd = { 0 };
148 
149 	/* prepare command */
150 	cmd.header = mc_encode_cmd_header(DPSECI_CMDID_DISABLE,
151 					  cmd_flags,
152 					  token);
153 
154 	/* send command to mc */
155 	return mc_send_command(mc_io, &cmd);
156 }
157 
158 int
159 dpseci_is_enabled(struct fsl_mc_io *mc_io,
160 		  uint32_t cmd_flags,
161 		  uint16_t token,
162 		  int *en)
163 {
164 	struct mc_command cmd = { 0 };
165 	int err;
166 	/* prepare command */
167 	cmd.header = mc_encode_cmd_header(DPSECI_CMDID_IS_ENABLED,
168 					  cmd_flags,
169 					  token);
170 
171 	/* send command to mc */
172 	err = mc_send_command(mc_io, &cmd);
173 	if (err)
174 		return err;
175 
176 	/* retrieve response parameters */
177 	DPSECI_RSP_IS_ENABLED(cmd, *en);
178 
179 	return 0;
180 }
181 
182 int
183 dpseci_reset(struct fsl_mc_io *mc_io,
184 	     uint32_t cmd_flags,
185 	     uint16_t token)
186 {
187 	struct mc_command cmd = { 0 };
188 
189 	/* prepare command */
190 	cmd.header = mc_encode_cmd_header(DPSECI_CMDID_RESET,
191 					  cmd_flags,
192 					  token);
193 
194 	/* send command to mc */
195 	return mc_send_command(mc_io, &cmd);
196 }
197 
198 int
199 dpseci_get_irq(struct fsl_mc_io *mc_io,
200 	       uint32_t cmd_flags,
201 	       uint16_t token,
202 	       uint8_t irq_index,
203 	       int *type,
204 	       struct dpseci_irq_cfg *irq_cfg)
205 {
206 	struct mc_command cmd = { 0 };
207 	int err;
208 
209 	/* prepare command */
210 	cmd.header = mc_encode_cmd_header(DPSECI_CMDID_GET_IRQ,
211 					  cmd_flags,
212 					  token);
213 	DPSECI_CMD_GET_IRQ(cmd, irq_index);
214 
215 	/* send command to mc */
216 	err = mc_send_command(mc_io, &cmd);
217 	if (err)
218 		return err;
219 
220 	/* retrieve response parameters */
221 	DPSECI_RSP_GET_IRQ(cmd, *type, irq_cfg);
222 
223 	return 0;
224 }
225 
226 int
227 dpseci_set_irq(struct fsl_mc_io *mc_io,
228 	       uint32_t cmd_flags,
229 	       uint16_t token,
230 	       uint8_t irq_index,
231 	       struct dpseci_irq_cfg *irq_cfg)
232 {
233 	struct mc_command cmd = { 0 };
234 
235 	/* prepare command */
236 	cmd.header = mc_encode_cmd_header(DPSECI_CMDID_SET_IRQ,
237 					  cmd_flags,
238 					  token);
239 	DPSECI_CMD_SET_IRQ(cmd, irq_index, irq_cfg);
240 
241 	/* send command to mc */
242 	return mc_send_command(mc_io, &cmd);
243 }
244 
245 int
246 dpseci_get_irq_enable(struct fsl_mc_io *mc_io,
247 		      uint32_t cmd_flags,
248 		      uint16_t token,
249 		      uint8_t irq_index,
250 		      uint8_t *en)
251 {
252 	struct mc_command cmd = { 0 };
253 	int err;
254 
255 	/* prepare command */
256 	cmd.header = mc_encode_cmd_header(DPSECI_CMDID_GET_IRQ_ENABLE,
257 					  cmd_flags,
258 					  token);
259 	DPSECI_CMD_GET_IRQ_ENABLE(cmd, irq_index);
260 
261 	/* send command to mc */
262 	err = mc_send_command(mc_io, &cmd);
263 	if (err)
264 		return err;
265 
266 	/* retrieve response parameters */
267 	DPSECI_RSP_GET_IRQ_ENABLE(cmd, *en);
268 
269 	return 0;
270 }
271 
272 int
273 dpseci_set_irq_enable(struct fsl_mc_io *mc_io,
274 		      uint32_t cmd_flags,
275 		      uint16_t token,
276 		      uint8_t irq_index,
277 		      uint8_t en)
278 {
279 	struct mc_command cmd = { 0 };
280 
281 	/* prepare command */
282 	cmd.header = mc_encode_cmd_header(DPSECI_CMDID_SET_IRQ_ENABLE,
283 					  cmd_flags,
284 					  token);
285 	DPSECI_CMD_SET_IRQ_ENABLE(cmd, irq_index, en);
286 
287 	/* send command to mc */
288 	return mc_send_command(mc_io, &cmd);
289 }
290 
291 int
292 dpseci_get_irq_mask(struct fsl_mc_io *mc_io,
293 		    uint32_t cmd_flags,
294 		    uint16_t token,
295 		    uint8_t irq_index,
296 		    uint32_t *mask)
297 {
298 	struct mc_command cmd = { 0 };
299 	int err;
300 
301 	/* prepare command */
302 	cmd.header = mc_encode_cmd_header(DPSECI_CMDID_GET_IRQ_MASK,
303 					  cmd_flags,
304 					  token);
305 	DPSECI_CMD_GET_IRQ_MASK(cmd, irq_index);
306 
307 	/* send command to mc */
308 	err = mc_send_command(mc_io, &cmd);
309 	if (err)
310 		return err;
311 
312 	/* retrieve response parameters */
313 	DPSECI_RSP_GET_IRQ_MASK(cmd, *mask);
314 
315 	return 0;
316 }
317 
318 int
319 dpseci_set_irq_mask(struct fsl_mc_io *mc_io,
320 		    uint32_t cmd_flags,
321 		    uint16_t token,
322 		    uint8_t irq_index,
323 		    uint32_t mask)
324 {
325 	struct mc_command cmd = { 0 };
326 
327 	/* prepare command */
328 	cmd.header = mc_encode_cmd_header(DPSECI_CMDID_SET_IRQ_MASK,
329 					  cmd_flags,
330 					  token);
331 	DPSECI_CMD_SET_IRQ_MASK(cmd, irq_index, mask);
332 
333 	/* send command to mc */
334 	return mc_send_command(mc_io, &cmd);
335 }
336 
337 int
338 dpseci_get_irq_status(struct fsl_mc_io *mc_io,
339 		      uint32_t cmd_flags,
340 		      uint16_t token,
341 		      uint8_t irq_index,
342 		      uint32_t *status)
343 {
344 	struct mc_command cmd = { 0 };
345 	int err;
346 
347 	/* prepare command */
348 	cmd.header = mc_encode_cmd_header(DPSECI_CMDID_GET_IRQ_STATUS,
349 					  cmd_flags,
350 					  token);
351 	DPSECI_CMD_GET_IRQ_STATUS(cmd, irq_index, *status);
352 
353 	/* send command to mc */
354 	err = mc_send_command(mc_io, &cmd);
355 	if (err)
356 		return err;
357 
358 	/* retrieve response parameters */
359 	DPSECI_RSP_GET_IRQ_STATUS(cmd, *status);
360 
361 	return 0;
362 }
363 
364 int
365 dpseci_clear_irq_status(struct fsl_mc_io *mc_io,
366 			uint32_t cmd_flags,
367 			uint16_t token,
368 			uint8_t irq_index,
369 			uint32_t status)
370 {
371 	struct mc_command cmd = { 0 };
372 
373 	/* prepare command */
374 	cmd.header = mc_encode_cmd_header(DPSECI_CMDID_CLEAR_IRQ_STATUS,
375 					  cmd_flags,
376 					  token);
377 	DPSECI_CMD_CLEAR_IRQ_STATUS(cmd, irq_index, status);
378 
379 	/* send command to mc */
380 	return mc_send_command(mc_io, &cmd);
381 }
382 
383 int
384 dpseci_get_attributes(struct fsl_mc_io *mc_io,
385 		      uint32_t cmd_flags,
386 		      uint16_t token,
387 		      struct dpseci_attr *attr)
388 {
389 	struct mc_command cmd = { 0 };
390 	int err;
391 
392 	/* prepare command */
393 	cmd.header = mc_encode_cmd_header(DPSECI_CMDID_GET_ATTR,
394 					  cmd_flags,
395 					  token);
396 
397 	/* send command to mc */
398 	err = mc_send_command(mc_io, &cmd);
399 	if (err)
400 		return err;
401 
402 	/* retrieve response parameters */
403 	DPSECI_RSP_GET_ATTR(cmd, attr);
404 
405 	return 0;
406 }
407 
408 int
409 dpseci_set_rx_queue(struct fsl_mc_io *mc_io,
410 		    uint32_t cmd_flags,
411 		    uint16_t token,
412 		    uint8_t queue,
413 		    const struct dpseci_rx_queue_cfg *cfg)
414 {
415 	struct mc_command cmd = { 0 };
416 
417 	/* prepare command */
418 	cmd.header = mc_encode_cmd_header(DPSECI_CMDID_SET_RX_QUEUE,
419 					  cmd_flags,
420 					  token);
421 	DPSECI_CMD_SET_RX_QUEUE(cmd, queue, cfg);
422 
423 	/* send command to mc */
424 	return mc_send_command(mc_io, &cmd);
425 }
426 
427 int
428 dpseci_get_rx_queue(struct fsl_mc_io *mc_io,
429 		    uint32_t cmd_flags,
430 		    uint16_t token,
431 		    uint8_t queue,
432 		    struct dpseci_rx_queue_attr *attr)
433 {
434 	struct mc_command cmd = { 0 };
435 	int err;
436 
437 	/* prepare command */
438 	cmd.header = mc_encode_cmd_header(DPSECI_CMDID_GET_RX_QUEUE,
439 					  cmd_flags,
440 					  token);
441 	DPSECI_CMD_GET_RX_QUEUE(cmd, queue);
442 
443 	/* send command to mc */
444 	err = mc_send_command(mc_io, &cmd);
445 	if (err)
446 		return err;
447 
448 	/* retrieve response parameters */
449 	DPSECI_RSP_GET_RX_QUEUE(cmd, attr);
450 
451 	return 0;
452 }
453 
454 int
455 dpseci_get_tx_queue(struct fsl_mc_io *mc_io,
456 		    uint32_t cmd_flags,
457 		    uint16_t token,
458 		    uint8_t queue,
459 		    struct dpseci_tx_queue_attr *attr)
460 {
461 	struct mc_command cmd = { 0 };
462 	int err;
463 
464 	/* prepare command */
465 	cmd.header = mc_encode_cmd_header(DPSECI_CMDID_GET_TX_QUEUE,
466 					  cmd_flags,
467 					  token);
468 	DPSECI_CMD_GET_TX_QUEUE(cmd, queue);
469 
470 	/* send command to mc */
471 	err = mc_send_command(mc_io, &cmd);
472 	if (err)
473 		return err;
474 
475 	/* retrieve response parameters */
476 	DPSECI_RSP_GET_TX_QUEUE(cmd, attr);
477 
478 	return 0;
479 }
480 
481 int
482 dpseci_get_sec_attr(struct fsl_mc_io *mc_io,
483 		    uint32_t cmd_flags,
484 		    uint16_t token,
485 		    struct dpseci_sec_attr *attr)
486 {
487 	struct mc_command cmd = { 0 };
488 	int err;
489 
490 	/* prepare command */
491 	cmd.header = mc_encode_cmd_header(DPSECI_CMDID_GET_SEC_ATTR,
492 					  cmd_flags,
493 					  token);
494 
495 	/* send command to mc */
496 	err = mc_send_command(mc_io, &cmd);
497 	if (err)
498 		return err;
499 
500 	/* retrieve response parameters */
501 	DPSECI_RSP_GET_SEC_ATTR(cmd, attr);
502 
503 	return 0;
504 }
505 
506 int
507 dpseci_get_sec_counters(struct fsl_mc_io *mc_io,
508 			uint32_t cmd_flags,
509 			uint16_t token,
510 			struct dpseci_sec_counters *counters)
511 {
512 	struct mc_command cmd = { 0 };
513 	int err;
514 
515 	/* prepare command */
516 	cmd.header = mc_encode_cmd_header(DPSECI_CMDID_GET_SEC_COUNTERS,
517 					  cmd_flags,
518 					  token);
519 
520 	/* send command to mc */
521 	err = mc_send_command(mc_io, &cmd);
522 	if (err)
523 		return err;
524 
525 	/* retrieve response parameters */
526 	DPSECI_RSP_GET_SEC_COUNTERS(cmd, counters);
527 
528 	return 0;
529 }
530 
531 int
532 dpseci_get_api_version(struct fsl_mc_io *mc_io,
533 		       uint32_t cmd_flags,
534 		       uint16_t *major_ver,
535 		       uint16_t *minor_ver)
536 {
537 	struct mc_command cmd = { 0 };
538 	int err;
539 
540 	cmd.header = mc_encode_cmd_header(DPSECI_CMDID_GET_API_VERSION,
541 					cmd_flags,
542 					0);
543 
544 	err = mc_send_command(mc_io, &cmd);
545 	if (err)
546 		return err;
547 
548 	DPSECI_RSP_GET_API_VERSION(cmd, *major_ver, *minor_ver);
549 
550 	return 0;
551 }
552