xref: /dpdk/drivers/crypto/dpaa2_sec/mc/dpseci.c (revision 3e0ceb9f17fff027fc6c8f18de35e11719ffa61e)
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 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 #include <fsl_mc_sys.h>
41 #include <fsl_mc_cmd.h>
42 #include <fsl_dpseci.h>
43 #include <fsl_dpseci_cmd.h>
44 
45 /**
46  * dpseci_open() - Open a control session for the specified object
47  * @mc_io:	Pointer to MC portal's I/O object
48  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
49  * @dpseci_id:	DPSECI unique ID
50  * @token:	Returned token; use in subsequent API calls
51  *
52  * This function can be used to open a control session for an
53  * already created object; an object may have been declared in
54  * the DPL or by calling the dpseci_create() function.
55  * This function returns a unique authentication token,
56  * associated with the specific object ID and the specific MC
57  * portal; this token must be used in all subsequent commands for
58  * this specific object.
59  *
60  * Return:	'0' on Success; Error code otherwise.
61  */
62 int dpseci_open(struct fsl_mc_io *mc_io,
63 		uint32_t cmd_flags,
64 		int dpseci_id,
65 		uint16_t *token)
66 {
67 	struct dpseci_cmd_open *cmd_params;
68 	struct mc_command cmd = { 0 };
69 	int err;
70 
71 	/* prepare command */
72 	cmd.header = mc_encode_cmd_header(DPSECI_CMDID_OPEN,
73 					  cmd_flags,
74 					  0);
75 	cmd_params = (struct dpseci_cmd_open *)cmd.params;
76 	cmd_params->dpseci_id = cpu_to_le32(dpseci_id);
77 
78 	/* send command to mc*/
79 	err = mc_send_command(mc_io, &cmd);
80 	if (err)
81 		return err;
82 
83 	/* retrieve response parameters */
84 	*token = mc_cmd_hdr_read_token(&cmd);
85 
86 	return 0;
87 }
88 
89 /**
90  * dpseci_close() - Close the control session of the object
91  * @mc_io:	Pointer to MC portal's I/O object
92  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
93  * @token:	Token of DPSECI object
94  *
95  * After this function is called, no further operations are
96  * allowed on the object without opening a new control session.
97  *
98  * Return:	'0' on Success; Error code otherwise.
99  */
100 int dpseci_close(struct fsl_mc_io *mc_io,
101 		 uint32_t cmd_flags,
102 		 uint16_t token)
103 {
104 	struct mc_command cmd = { 0 };
105 
106 	/* prepare command */
107 	cmd.header = mc_encode_cmd_header(DPSECI_CMDID_CLOSE,
108 					  cmd_flags,
109 					  token);
110 
111 	/* send command to mc*/
112 	return mc_send_command(mc_io, &cmd);
113 }
114 
115 /**
116  * dpseci_create() - Create the DPSECI object
117  * @mc_io:	Pointer to MC portal's I/O object
118  * @dprc_token:	Parent container token; '0' for default container
119  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
120  * @cfg:	Configuration structure
121  * @obj_id:	Returned object id
122  *
123  * Create the DPSECI object, allocate required resources and
124  * perform required initialization.
125  *
126  * The object can be created either by declaring it in the
127  * DPL file, or by calling this function.
128  *
129  * The function accepts an authentication token of a parent
130  * container that this object should be assigned to. The token
131  * can be '0' so the object will be assigned to the default container.
132  * The newly created object can be opened with the returned
133  * object id and using the container's associated tokens and MC portals.
134  *
135  * Return:	'0' on Success; Error code otherwise.
136  */
137 int dpseci_create(struct fsl_mc_io *mc_io,
138 		  uint16_t dprc_token,
139 		  uint32_t cmd_flags,
140 		  const struct dpseci_cfg *cfg,
141 		  uint32_t *obj_id)
142 {
143 	struct dpseci_cmd_create *cmd_params;
144 	struct mc_command cmd = { 0 };
145 	int err, i;
146 
147 	/* prepare command */
148 	cmd.header = mc_encode_cmd_header(DPSECI_CMDID_CREATE,
149 					  cmd_flags,
150 					  dprc_token);
151 	cmd_params = (struct dpseci_cmd_create *)cmd.params;
152 	for (i = 0; i < DPSECI_PRIO_NUM; i++)
153 		cmd_params->priorities[i] = cfg->priorities[i];
154 	cmd_params->num_tx_queues = cfg->num_tx_queues;
155 	cmd_params->num_rx_queues = cfg->num_rx_queues;
156 	cmd_params->options = cfg->options;
157 
158 	/* send command to mc*/
159 	err = mc_send_command(mc_io, &cmd);
160 	if (err)
161 		return err;
162 
163 	/* retrieve response parameters */
164 	*obj_id = mc_cmd_read_object_id(&cmd);
165 
166 	return 0;
167 }
168 
169 /**
170  * dpseci_destroy() - Destroy the DPSECI object and release all its resources.
171  * @mc_io:	Pointer to MC portal's I/O object
172  * @dprc_token: Parent container token; '0' for default container
173  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
174  * @object_id:	The object id; it must be a valid id within the container that
175  * created this object;
176  *
177  * The function accepts the authentication token of the parent container that
178  * created the object (not the one that currently owns the object). The object
179  * is searched within parent using the provided 'object_id'.
180  * All tokens to the object must be closed before calling destroy.
181  *
182  * Return:	'0' on Success; error code otherwise.
183  */
184 int dpseci_destroy(struct fsl_mc_io *mc_io,
185 		   uint16_t dprc_token,
186 		   uint32_t cmd_flags,
187 		   uint32_t object_id)
188 {
189 	struct dpseci_cmd_destroy *cmd_params;
190 	struct mc_command cmd = { 0 };
191 
192 	/* prepare command */
193 	cmd.header = mc_encode_cmd_header(DPSECI_CMDID_DESTROY,
194 					  cmd_flags,
195 					  dprc_token);
196 	cmd_params = (struct dpseci_cmd_destroy *)cmd.params;
197 	cmd_params->dpseci_id = cpu_to_le32(object_id);
198 
199 	/* send command to mc*/
200 	return mc_send_command(mc_io, &cmd);
201 }
202 
203 /**
204  * dpseci_enable() - Enable the DPSECI, allow sending and receiving frames.
205  * @mc_io:	Pointer to MC portal's I/O object
206  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
207  * @token:	Token of DPSECI object
208  *
209  * Return:	'0' on Success; Error code otherwise.
210  */
211 int dpseci_enable(struct fsl_mc_io *mc_io,
212 		  uint32_t cmd_flags,
213 		  uint16_t token)
214 {
215 	struct mc_command cmd = { 0 };
216 
217 	/* prepare command */
218 	cmd.header = mc_encode_cmd_header(DPSECI_CMDID_ENABLE,
219 					  cmd_flags,
220 					  token);
221 
222 	/* send command to mc*/
223 	return mc_send_command(mc_io, &cmd);
224 }
225 
226 /**
227  * dpseci_disable() - Disable the DPSECI, stop sending and receiving frames.
228  * @mc_io:	Pointer to MC portal's I/O object
229  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
230  * @token:	Token of DPSECI object
231  *
232  * Return:	'0' on Success; Error code otherwise.
233  */
234 int dpseci_disable(struct fsl_mc_io *mc_io,
235 		   uint32_t cmd_flags,
236 		   uint16_t token)
237 {
238 	struct mc_command cmd = { 0 };
239 
240 	/* prepare command */
241 	cmd.header = mc_encode_cmd_header(DPSECI_CMDID_DISABLE,
242 					  cmd_flags,
243 					  token);
244 
245 	/* send command to mc*/
246 	return mc_send_command(mc_io, &cmd);
247 }
248 
249 /**
250  * dpseci_is_enabled() - Check if the DPSECI is enabled.
251  * @mc_io:	Pointer to MC portal's I/O object
252  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
253  * @token:	Token of DPSECI object
254  * @en:		Returns '1' if object is enabled; '0' otherwise
255  *
256  * Return:	'0' on Success; Error code otherwise.
257  */
258 int dpseci_is_enabled(struct fsl_mc_io *mc_io,
259 		      uint32_t cmd_flags,
260 		      uint16_t token,
261 		      int *en)
262 {
263 	struct dpseci_rsp_is_enabled *rsp_params;
264 	struct mc_command cmd = { 0 };
265 	int err;
266 
267 	/* prepare command */
268 	cmd.header = mc_encode_cmd_header(DPSECI_CMDID_IS_ENABLED,
269 					  cmd_flags,
270 					  token);
271 
272 	/* send command to mc*/
273 	err = mc_send_command(mc_io, &cmd);
274 	if (err)
275 		return err;
276 
277 	/* retrieve response parameters */
278 	rsp_params = (struct dpseci_rsp_is_enabled *)cmd.params;
279 	*en = dpseci_get_field(rsp_params->en, ENABLE);
280 
281 	return 0;
282 }
283 
284 /**
285  * dpseci_reset() - Reset the DPSECI, returns the object to initial state.
286  * @mc_io:	Pointer to MC portal's I/O object
287  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
288  * @token:	Token of DPSECI object
289  *
290  * Return:	'0' on Success; Error code otherwise.
291  */
292 int dpseci_reset(struct fsl_mc_io *mc_io,
293 		 uint32_t cmd_flags,
294 		 uint16_t token)
295 {
296 	struct mc_command cmd = { 0 };
297 
298 	/* prepare command */
299 	cmd.header = mc_encode_cmd_header(DPSECI_CMDID_RESET,
300 					  cmd_flags,
301 					  token);
302 
303 	/* send command to mc*/
304 	return mc_send_command(mc_io, &cmd);
305 }
306 
307 /**
308  * dpseci_get_attributes() - Retrieve DPSECI attributes.
309  * @mc_io:	Pointer to MC portal's I/O object
310  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
311  * @token:	Token of DPSECI object
312  * @attr:	Returned object's attributes
313  *
314  * Return:	'0' on Success; Error code otherwise.
315  */
316 int dpseci_get_attributes(struct fsl_mc_io *mc_io,
317 			  uint32_t cmd_flags,
318 			  uint16_t token,
319 			  struct dpseci_attr *attr)
320 {
321 	struct dpseci_rsp_get_attr *rsp_params;
322 	struct mc_command cmd = { 0 };
323 	int err;
324 
325 	/* prepare command */
326 	cmd.header = mc_encode_cmd_header(DPSECI_CMDID_GET_ATTR,
327 					  cmd_flags,
328 					  token);
329 
330 	/* send command to mc*/
331 	err = mc_send_command(mc_io, &cmd);
332 	if (err)
333 		return err;
334 
335 	/* retrieve response parameters */
336 	rsp_params = (struct dpseci_rsp_get_attr *)cmd.params;
337 	attr->id = le32_to_cpu(rsp_params->id);
338 	attr->options = rsp_params->options;
339 	attr->num_tx_queues = rsp_params->num_tx_queues;
340 	attr->num_rx_queues = rsp_params->num_rx_queues;
341 
342 	return 0;
343 }
344 
345 /**
346  * dpseci_set_rx_queue() - Set Rx queue configuration
347  * @mc_io:	Pointer to MC portal's I/O object
348  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
349  * @token:	Token of DPSECI object
350  * @queue:	Select the queue relative to number of
351  *		priorities configured at DPSECI creation; use
352  *		DPSECI_ALL_QUEUES to configure all Rx queues identically.
353  * @cfg:	Rx queue configuration
354  *
355  * Return:	'0' on Success; Error code otherwise.
356  */
357 int dpseci_set_rx_queue(struct fsl_mc_io *mc_io,
358 			uint32_t cmd_flags,
359 			uint16_t token,
360 			uint8_t queue,
361 			const struct dpseci_rx_queue_cfg *cfg)
362 {
363 	struct dpseci_cmd_set_rx_queue *cmd_params;
364 	struct mc_command cmd = { 0 };
365 
366 	/* prepare command */
367 	cmd.header = mc_encode_cmd_header(DPSECI_CMDID_SET_RX_QUEUE,
368 					  cmd_flags,
369 					  token);
370 	cmd_params = (struct dpseci_cmd_set_rx_queue *)cmd.params;
371 	cmd_params->dest_id = cpu_to_le32(cfg->dest_cfg.dest_id);
372 	cmd_params->dest_priority = cfg->dest_cfg.priority;
373 	cmd_params->queue = queue;
374 	cmd_params->user_ctx = cpu_to_le64(cfg->user_ctx);
375 	cmd_params->options = cpu_to_le32(cfg->options);
376 	dpseci_set_field(cmd_params->dest_type,
377 			 DEST_TYPE,
378 			 cfg->dest_cfg.dest_type);
379 	dpseci_set_field(cmd_params->order_preservation_en,
380 			 ORDER_PRESERVATION,
381 			 cfg->order_preservation_en);
382 
383 	/* send command to mc*/
384 	return mc_send_command(mc_io, &cmd);
385 }
386 
387 /**
388  * dpseci_get_rx_queue() - Retrieve Rx queue attributes.
389  * @mc_io:	Pointer to MC portal's I/O object
390  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
391  * @token:	Token of DPSECI object
392  * @queue:	Select the queue relative to number of
393  *				priorities configured at DPSECI creation
394  * @attr:	Returned Rx queue attributes
395  *
396  * Return:	'0' on Success; Error code otherwise.
397  */
398 int dpseci_get_rx_queue(struct fsl_mc_io *mc_io,
399 			uint32_t cmd_flags,
400 			uint16_t token,
401 			uint8_t queue,
402 			struct dpseci_rx_queue_attr *attr)
403 {
404 	struct dpseci_rsp_get_rx_queue *rsp_params;
405 	struct dpseci_cmd_get_queue *cmd_params;
406 	struct mc_command cmd = { 0 };
407 	int err;
408 
409 	/* prepare command */
410 	cmd.header = mc_encode_cmd_header(DPSECI_CMDID_GET_RX_QUEUE,
411 					  cmd_flags,
412 					  token);
413 	cmd_params = (struct dpseci_cmd_get_queue *)cmd.params;
414 	cmd_params->queue = queue;
415 
416 	/* send command to mc*/
417 	err = mc_send_command(mc_io, &cmd);
418 	if (err)
419 		return err;
420 
421 	/* retrieve response parameters */
422 	rsp_params = (struct dpseci_rsp_get_rx_queue *)cmd.params;
423 	attr->user_ctx = le64_to_cpu(rsp_params->user_ctx);
424 	attr->fqid = le32_to_cpu(rsp_params->fqid);
425 	attr->dest_cfg.dest_id = le32_to_cpu(rsp_params->dest_id);
426 	attr->dest_cfg.priority = rsp_params->dest_priority;
427 	attr->dest_cfg.dest_type =
428 		dpseci_get_field(rsp_params->dest_type,
429 				 DEST_TYPE);
430 	attr->order_preservation_en =
431 		dpseci_get_field(rsp_params->order_preservation_en,
432 				 ORDER_PRESERVATION);
433 
434 	return 0;
435 }
436 
437 /**
438  * dpseci_get_tx_queue() - Retrieve Tx queue attributes.
439  * @mc_io:	Pointer to MC portal's I/O object
440  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
441  * @token:	Token of DPSECI object
442  * @queue:	Select the queue relative to number of
443  *		priorities configured at DPSECI creation
444  * @attr:	Returned Tx queue attributes
445  *
446  * Return:	'0' on Success; Error code otherwise.
447  */
448 int dpseci_get_tx_queue(struct fsl_mc_io *mc_io,
449 			uint32_t cmd_flags,
450 			uint16_t token,
451 			uint8_t queue,
452 			struct dpseci_tx_queue_attr *attr)
453 {
454 	struct dpseci_rsp_get_tx_queue *rsp_params;
455 	struct dpseci_cmd_get_queue *cmd_params;
456 	struct mc_command cmd = { 0 };
457 	int err;
458 
459 	/* prepare command */
460 	cmd.header = mc_encode_cmd_header(DPSECI_CMDID_GET_TX_QUEUE,
461 					  cmd_flags,
462 					  token);
463 	cmd_params = (struct dpseci_cmd_get_queue *)cmd.params;
464 	cmd_params->queue = queue;
465 
466 	/* send command to mc*/
467 	err = mc_send_command(mc_io, &cmd);
468 	if (err)
469 		return err;
470 
471 	/* retrieve response parameters */
472 	rsp_params = (struct dpseci_rsp_get_tx_queue *)cmd.params;
473 	attr->fqid = le32_to_cpu(rsp_params->fqid);
474 	attr->priority = rsp_params->priority;
475 
476 	return 0;
477 }
478 
479 /**
480  * dpseci_get_sec_attr() - Retrieve SEC accelerator attributes.
481  * @mc_io:	Pointer to MC portal's I/O object
482  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
483  * @token:	Token of DPSECI object
484  * @attr:	Returned SEC attributes
485  *
486  * Return:	'0' on Success; Error code otherwise.
487  */
488 int dpseci_get_sec_attr(struct fsl_mc_io *mc_io,
489 			uint32_t cmd_flags,
490 			uint16_t token,
491 			struct dpseci_sec_attr *attr)
492 {
493 	struct dpseci_rsp_get_sec_attr *rsp_params;
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 	rsp_params = (struct dpseci_rsp_get_sec_attr *)cmd.params;
509 	attr->ip_id = le16_to_cpu(rsp_params->ip_id);
510 	attr->major_rev = rsp_params->major_rev;
511 	attr->minor_rev = rsp_params->minor_rev;
512 	attr->era = rsp_params->era;
513 	attr->deco_num = rsp_params->deco_num;
514 	attr->zuc_auth_acc_num = rsp_params->zuc_auth_acc_num;
515 	attr->zuc_enc_acc_num = rsp_params->zuc_enc_acc_num;
516 	attr->snow_f8_acc_num = rsp_params->snow_f8_acc_num;
517 	attr->snow_f9_acc_num = rsp_params->snow_f9_acc_num;
518 	attr->crc_acc_num = rsp_params->crc_acc_num;
519 	attr->pk_acc_num = rsp_params->pk_acc_num;
520 	attr->kasumi_acc_num = rsp_params->kasumi_acc_num;
521 	attr->rng_acc_num = rsp_params->rng_acc_num;
522 	attr->md_acc_num = rsp_params->md_acc_num;
523 	attr->arc4_acc_num = rsp_params->arc4_acc_num;
524 	attr->des_acc_num = rsp_params->des_acc_num;
525 	attr->aes_acc_num = rsp_params->aes_acc_num;
526 
527 	return 0;
528 }
529 
530 /**
531  * dpseci_get_sec_counters() - Retrieve SEC accelerator counters.
532  * @mc_io:	Pointer to MC portal's I/O object
533  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
534  * @token:	Token of DPSECI object
535  * @counters:	Returned SEC counters
536  *
537  * Return:	'0' on Success; Error code otherwise.
538  */
539 int dpseci_get_sec_counters(struct fsl_mc_io *mc_io,
540 			    uint32_t cmd_flags,
541 			    uint16_t token,
542 			    struct dpseci_sec_counters *counters)
543 {
544 	struct dpseci_rsp_get_sec_counters *rsp_params;
545 	struct mc_command cmd = { 0 };
546 	int err;
547 
548 	/* prepare command */
549 	cmd.header = mc_encode_cmd_header(DPSECI_CMDID_GET_SEC_COUNTERS,
550 					  cmd_flags,
551 					  token);
552 
553 	/* send command to mc*/
554 	err = mc_send_command(mc_io, &cmd);
555 	if (err)
556 		return err;
557 
558 	/* retrieve response parameters */
559 	rsp_params = (struct dpseci_rsp_get_sec_counters *)cmd.params;
560 	counters->dequeued_requests =
561 				le64_to_cpu(rsp_params->dequeued_requests);
562 	counters->ob_enc_requests = le64_to_cpu(rsp_params->ob_enc_requests);
563 	counters->ib_dec_requests = le64_to_cpu(rsp_params->ib_dec_requests);
564 	counters->ob_enc_bytes = le64_to_cpu(rsp_params->ob_enc_bytes);
565 	counters->ob_prot_bytes = le64_to_cpu(rsp_params->ob_prot_bytes);
566 	counters->ib_dec_bytes = le64_to_cpu(rsp_params->ib_dec_bytes);
567 	counters->ib_valid_bytes = le64_to_cpu(rsp_params->ib_valid_bytes);
568 
569 	return 0;
570 }
571 
572 /**
573  * dpseci_get_api_version() - Get Data Path SEC Interface API version
574  * @mc_io:  Pointer to MC portal's I/O object
575  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
576  * @major_ver:	Major version of data path sec API
577  * @minor_ver:	Minor version of data path sec API
578  *
579  * Return:  '0' on Success; Error code otherwise.
580  */
581 int dpseci_get_api_version(struct fsl_mc_io *mc_io,
582 			   uint32_t cmd_flags,
583 			   uint16_t *major_ver,
584 			   uint16_t *minor_ver)
585 {
586 	struct dpseci_rsp_get_api_version *rsp_params;
587 	struct mc_command cmd = { 0 };
588 	int err;
589 
590 	cmd.header = mc_encode_cmd_header(DPSECI_CMDID_GET_API_VERSION,
591 					cmd_flags,
592 					0);
593 
594 	err = mc_send_command(mc_io, &cmd);
595 	if (err)
596 		return err;
597 
598 	rsp_params = (struct dpseci_rsp_get_api_version *)cmd.params;
599 	*major_ver = le16_to_cpu(rsp_params->major);
600 	*minor_ver = le16_to_cpu(rsp_params->minor);
601 
602 	return 0;
603 }
604 
605 int dpseci_set_congestion_notification(
606 			struct fsl_mc_io *mc_io,
607 			uint32_t cmd_flags,
608 			uint16_t token,
609 			const struct dpseci_congestion_notification_cfg *cfg)
610 {
611 	struct dpseci_cmd_set_congestion_notification *cmd_params;
612 	struct mc_command cmd = { 0 };
613 
614 	/* prepare command */
615 	cmd.header = mc_encode_cmd_header(
616 			DPSECI_CMDID_SET_CONGESTION_NOTIFICATION,
617 			cmd_flags,
618 			token);
619 
620 	cmd_params =
621 		(struct dpseci_cmd_set_congestion_notification *)cmd.params;
622 	cmd_params->dest_id = cfg->dest_cfg.dest_id;
623 	cmd_params->dest_priority = cfg->dest_cfg.priority;
624 	cmd_params->message_ctx = cfg->message_ctx;
625 	cmd_params->message_iova = cfg->message_iova;
626 	cmd_params->notification_mode = cfg->notification_mode;
627 	cmd_params->threshold_entry = cfg->threshold_entry;
628 	cmd_params->threshold_exit = cfg->threshold_exit;
629 	dpseci_set_field(cmd_params->type_units,
630 			 DEST_TYPE,
631 			 cfg->dest_cfg.dest_type);
632 	dpseci_set_field(cmd_params->type_units,
633 			 CG_UNITS,
634 			 cfg->units);
635 
636 	/* send command to mc*/
637 	return mc_send_command(mc_io, &cmd);
638 }
639 
640 int dpseci_get_congestion_notification(
641 				struct fsl_mc_io *mc_io,
642 				uint32_t cmd_flags,
643 				uint16_t token,
644 				struct dpseci_congestion_notification_cfg *cfg)
645 {
646 	struct dpseci_cmd_set_congestion_notification *rsp_params;
647 	struct mc_command cmd = { 0 };
648 	int err;
649 
650 	/* prepare command */
651 	cmd.header = mc_encode_cmd_header(
652 			DPSECI_CMDID_GET_CONGESTION_NOTIFICATION,
653 			cmd_flags,
654 			token);
655 
656 	/* send command to mc*/
657 	err = mc_send_command(mc_io, &cmd);
658 	if (err)
659 		return err;
660 
661 	rsp_params =
662 		(struct dpseci_cmd_set_congestion_notification *)cmd.params;
663 
664 	cfg->dest_cfg.dest_id = le32_to_cpu(rsp_params->dest_id);
665 	cfg->dest_cfg.priority = rsp_params->dest_priority;
666 	cfg->notification_mode = le16_to_cpu(rsp_params->notification_mode);
667 	cfg->message_ctx = le64_to_cpu(rsp_params->message_ctx);
668 	cfg->message_iova = le64_to_cpu(rsp_params->message_iova);
669 	cfg->threshold_entry = le32_to_cpu(rsp_params->threshold_entry);
670 	cfg->threshold_exit = le32_to_cpu(rsp_params->threshold_exit);
671 	cfg->units = dpseci_get_field(rsp_params->type_units, CG_UNITS);
672 	cfg->dest_cfg.dest_type = dpseci_get_field(rsp_params->type_units,
673 						DEST_TYPE);
674 
675 	return 0;
676 }
677