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