xref: /dpdk/drivers/net/dpaa2/mc/dpdmux.c (revision 591200ef6f32b56adc367ebe3647cc3dbe9362db)
1 /* SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0)
2  *
3  * Copyright 2013-2016 Freescale Semiconductor Inc.
4  * Copyright 2018-2023 NXP
5  *
6  */
7 #include <fsl_mc_sys.h>
8 #include <fsl_mc_cmd.h>
9 #include <fsl_dpdmux.h>
10 #include <fsl_dpdmux_cmd.h>
11 
12 /** @addtogroup dpdmux
13  * @{
14  */
15 
16 /**
17  * dpdmux_open() - Open a control session for the specified object
18  * @mc_io:	Pointer to MC portal's I/O object
19  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
20  * @dpdmux_id:		DPDMUX unique ID
21  * @token:		Returned token; use in subsequent API calls
22  *
23  * This function can be used to open a control session for an
24  * already created object; an object may have been declared in
25  * the DPL or by calling the dpdmux_create() function.
26  * This function returns a unique authentication token,
27  * associated with the specific object ID and the specific MC
28  * portal; this token must be used in all subsequent commands for
29  * this specific object.
30  *
31  * Return:	'0' on Success; Error code otherwise.
32  */
33 int dpdmux_open(struct fsl_mc_io *mc_io,
34 		uint32_t cmd_flags,
35 		int dpdmux_id,
36 		uint16_t *token)
37 {
38 	struct mc_command cmd = { 0 };
39 	struct dpdmux_cmd_open *cmd_params;
40 	int err;
41 
42 	/* prepare command */
43 	cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_OPEN,
44 					  cmd_flags,
45 					  0);
46 	cmd_params = (struct dpdmux_cmd_open *)cmd.params;
47 	cmd_params->dpdmux_id = cpu_to_le32(dpdmux_id);
48 
49 	/* send command to mc*/
50 	err = mc_send_command(mc_io, &cmd);
51 	if (err)
52 		return err;
53 
54 	/* retrieve response parameters */
55 	*token = mc_cmd_hdr_read_token(&cmd);
56 
57 	return 0;
58 }
59 
60 /**
61  * dpdmux_close() - Close the control session of the object
62  * @mc_io:	Pointer to MC portal's I/O object
63  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
64  * @token:		Token of DPDMUX object
65  *
66  * After this function is called, no further operations are
67  * allowed on the object without opening a new control session.
68  *
69  * Return:	'0' on Success; Error code otherwise.
70  */
71 int dpdmux_close(struct fsl_mc_io *mc_io,
72 		 uint32_t cmd_flags,
73 		 uint16_t token)
74 {
75 	struct mc_command cmd = { 0 };
76 
77 	/* prepare command */
78 	cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_CLOSE,
79 					  cmd_flags,
80 					  token);
81 
82 	/* send command to mc*/
83 	return mc_send_command(mc_io, &cmd);
84 }
85 
86 /**
87  * dpdmux_create() - Create the DPDMUX object
88  * @mc_io:	Pointer to MC portal's I/O object
89  * @dprc_token:	Parent container token; '0' for default container
90  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
91  * @cfg:	Configuration structure
92  * @obj_id: returned object id
93  *
94  * Create the DPDMUX object, allocate required resources and
95  * perform required initialization.
96  *
97  * The object can be created either by declaring it in the
98  * DPL file, or by calling this function.
99  *
100  * The function accepts an authentication token of a parent
101  * container that this object should be assigned to. The token
102  * can be '0' so the object will be assigned to the default container.
103  * The newly created object can be opened with the returned
104  * object id and using the container's associated tokens and MC portals.
105  *
106  * Return:	'0' on Success; Error code otherwise.
107  */
108 int dpdmux_create(struct fsl_mc_io *mc_io,
109 		  uint16_t dprc_token,
110 		  uint32_t cmd_flags,
111 		  const struct dpdmux_cfg	*cfg,
112 		  uint32_t *obj_id)
113 {
114 	struct mc_command cmd = { 0 };
115 	struct dpdmux_cmd_create *cmd_params;
116 	int err;
117 
118 	/* prepare command */
119 	cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_CREATE,
120 					  cmd_flags,
121 					  dprc_token);
122 	cmd_params = (struct dpdmux_cmd_create *)cmd.params;
123 	cmd_params->method = cfg->method;
124 	cmd_params->manip = cfg->manip;
125 	cmd_params->num_ifs = cpu_to_le16(cfg->num_ifs);
126 	cmd_params->default_if = cpu_to_le16(cfg->default_if);
127 	cmd_params->adv_max_dmat_entries =
128 			cpu_to_le16(cfg->adv.max_dmat_entries);
129 	cmd_params->adv_max_mc_groups = cpu_to_le16(cfg->adv.max_mc_groups);
130 	cmd_params->adv_max_vlan_ids = cpu_to_le16(cfg->adv.max_vlan_ids);
131 	cmd_params->mem_size = cpu_to_le16(cfg->adv.mem_size);
132 	cmd_params->options = cpu_to_le64(cfg->adv.options);
133 
134 	/* send command to mc*/
135 	err = mc_send_command(mc_io, &cmd);
136 	if (err)
137 		return err;
138 
139 	/* retrieve response parameters */
140 	*obj_id = mc_cmd_read_object_id(&cmd);
141 
142 	return 0;
143 }
144 
145 /**
146  * dpdmux_destroy() - Destroy the DPDMUX object and release all its resources.
147  * @mc_io:	Pointer to MC portal's I/O object
148  * @dprc_token: Parent container token; '0' for default container
149  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
150  * @object_id:	The object id; it must be a valid id within the container that
151  * created this object;
152  *
153  * The function accepts the authentication token of the parent container that
154  * created the object (not the one that currently owns the object). The object
155  * is searched within parent using the provided 'object_id'.
156  * All tokens to the object must be closed before calling destroy.
157  *
158  * Return:	'0' on Success; error code otherwise.
159  */
160 int dpdmux_destroy(struct fsl_mc_io *mc_io,
161 		   uint16_t dprc_token,
162 		   uint32_t cmd_flags,
163 		   uint32_t object_id)
164 {
165 	struct mc_command cmd = { 0 };
166 	struct dpdmux_cmd_destroy *cmd_params;
167 
168 	/* prepare command */
169 	cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_DESTROY,
170 					  cmd_flags,
171 					  dprc_token);
172 	cmd_params = (struct dpdmux_cmd_destroy *)cmd.params;
173 	cmd_params->dpdmux_id = cpu_to_le32(object_id);
174 
175 	/* send command to mc*/
176 	return mc_send_command(mc_io, &cmd);
177 }
178 
179 /**
180  * dpdmux_enable() - Enable DPDMUX functionality
181  * @mc_io:	Pointer to MC portal's I/O object
182  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
183  * @token:	Token of DPDMUX object
184  *
185  * Return:	'0' on Success; Error code otherwise.
186  */
187 int dpdmux_enable(struct fsl_mc_io *mc_io,
188 		  uint32_t cmd_flags,
189 		  uint16_t token)
190 {
191 	struct mc_command cmd = { 0 };
192 
193 	/* prepare command */
194 	cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_ENABLE,
195 					  cmd_flags,
196 					  token);
197 
198 	/* send command to mc*/
199 	return mc_send_command(mc_io, &cmd);
200 }
201 
202 /**
203  * dpdmux_disable() - Disable DPDMUX functionality
204  * @mc_io:	Pointer to MC portal's I/O object
205  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
206  * @token:	Token of DPDMUX object
207  *
208  * Return:	'0' on Success; Error code otherwise.
209  */
210 int dpdmux_disable(struct fsl_mc_io *mc_io,
211 		   uint32_t cmd_flags,
212 		   uint16_t token)
213 {
214 	struct mc_command cmd = { 0 };
215 
216 	/* prepare command */
217 	cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_DISABLE,
218 					  cmd_flags,
219 					  token);
220 
221 	/* send command to mc*/
222 	return mc_send_command(mc_io, &cmd);
223 }
224 
225 /**
226  * dpdmux_is_enabled() - Check if the DPDMUX is enabled.
227  * @mc_io:	Pointer to MC portal's I/O object
228  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
229  * @token:	Token of DPDMUX object
230  * @en:		Returns '1' if object is enabled; '0' otherwise
231  *
232  * Return:	'0' on Success; Error code otherwise.
233  */
234 int dpdmux_is_enabled(struct fsl_mc_io *mc_io,
235 		      uint32_t cmd_flags,
236 		      uint16_t token,
237 		      int *en)
238 {
239 	struct mc_command cmd = { 0 };
240 	struct dpdmux_rsp_is_enabled *rsp_params;
241 	int err;
242 
243 	/* prepare command */
244 	cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_IS_ENABLED,
245 					  cmd_flags,
246 					  token);
247 
248 	/* send command to mc*/
249 	err = mc_send_command(mc_io, &cmd);
250 	if (err)
251 		return err;
252 
253 	/* retrieve response parameters */
254 	rsp_params = (struct dpdmux_rsp_is_enabled *)cmd.params;
255 	*en = dpdmux_get_field(rsp_params->en, ENABLE);
256 
257 	return 0;
258 }
259 
260 /**
261  * dpdmux_reset() - Reset the DPDMUX, returns the object to initial state.
262  * @mc_io:	Pointer to MC portal's I/O object
263  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
264  * @token:	Token of DPDMUX object
265  *
266  * Return:	'0' on Success; Error code otherwise.
267  */
268 int dpdmux_reset(struct fsl_mc_io *mc_io,
269 		 uint32_t cmd_flags,
270 		 uint16_t token)
271 {
272 	struct mc_command cmd = { 0 };
273 
274 	/* prepare command */
275 	cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_RESET,
276 					  cmd_flags,
277 					  token);
278 
279 	/* send command to mc*/
280 	return mc_send_command(mc_io, &cmd);
281 }
282 
283 /**
284  * dpdmux_set_resetable() - Set overall resetable DPDMUX parameters.
285  * @mc_io:	Pointer to MC portal's I/O object
286  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
287  * @token:	Token of DPDMUX object
288  * @skip_reset_flags:	By default all are 0.
289  *			By setting 1 will deactivate the reset.
290  * The flags are:
291  *			DPDMUX_SKIP_MODIFY_DEFAULT_INTERFACE  0x01
292  *			DPDMUX_SKIP_UNICAST_RULES             0x02
293  *			DPDMUX_SKIP_MULTICAST_RULES           0x04
294  *			DPDMUX_SKIP_RESET_DEFAULT_INTERFACE   0x08
295  *
296  * For example, by default, through DPDMUX_RESET the default
297  * interface will be restored with the one from create.
298  * By setting DPDMUX_SKIP_MODIFY_DEFAULT_INTERFACE flag,
299  * through DPDMUX_RESET the default interface will not be modified after reset.
300  * By setting DPDMUX_SKIP_RESET_DEFAULT_INTERFACE flag,
301  * through DPDMUX_RESET the default interface will not be reset
302  * and will continue to be functional during reset procedure.
303  *
304  * Return:	'0' on Success; Error code otherwise.
305  */
306 int dpdmux_set_resetable(struct fsl_mc_io *mc_io,
307 				  uint32_t cmd_flags,
308 				  uint16_t token,
309 				  uint8_t skip_reset_flags)
310 {
311 	struct mc_command cmd = { 0 };
312 	struct dpdmux_cmd_set_skip_reset_flags *cmd_params;
313 
314 	/* prepare command */
315 	cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_SET_RESETABLE,
316 					  cmd_flags,
317 					  token);
318 	cmd_params = (struct dpdmux_cmd_set_skip_reset_flags *)cmd.params;
319 	dpdmux_set_field(cmd_params->skip_reset_flags,
320 			SKIP_RESET_FLAGS,
321 			skip_reset_flags);
322 
323 	/* send command to mc*/
324 	return mc_send_command(mc_io, &cmd);
325 }
326 
327 /**
328  * dpdmux_get_resetable() - Get overall resetable parameters.
329  * @mc_io:	Pointer to MC portal's I/O object
330  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
331  * @token:	Token of DPDMUX object
332  * @skip_reset_flags:	Get the reset flags.
333  *
334  * The flags are:
335  *			DPDMUX_SKIP_MODIFY_DEFAULT_INTERFACE  0x01
336  *			DPDMUX_SKIP_UNICAST_RULES             0x02
337  *			DPDMUX_SKIP_MULTICAST_RULES           0x04
338  *			DPDMUX_SKIP_RESET_DEFAULT_INTERFACE   0x08
339  *
340  * Return:	'0' on Success; Error code otherwise.
341  */
342 int dpdmux_get_resetable(struct fsl_mc_io *mc_io,
343 				  uint32_t cmd_flags,
344 				  uint16_t token,
345 				  uint8_t *skip_reset_flags)
346 {
347 	struct mc_command cmd = { 0 };
348 	struct dpdmux_rsp_get_skip_reset_flags *rsp_params;
349 	int err;
350 
351 	/* prepare command */
352 	cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_GET_RESETABLE,
353 					  cmd_flags,
354 					  token);
355 
356 	/* send command to mc*/
357 	err = mc_send_command(mc_io, &cmd);
358 	if (err)
359 		return err;
360 
361 	/* retrieve response parameters */
362 	rsp_params = (struct dpdmux_rsp_get_skip_reset_flags *)cmd.params;
363 	*skip_reset_flags = dpdmux_get_field(rsp_params->skip_reset_flags,
364 			SKIP_RESET_FLAGS);
365 
366 	return 0;
367 }
368 
369 /**
370  * dpdmux_get_attributes() - Retrieve DPDMUX attributes
371  * @mc_io:	Pointer to MC portal's I/O object
372  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
373  * @token:	Token of DPDMUX object
374  * @attr:	Returned object's attributes
375  *
376  * Return:	'0' on Success; Error code otherwise.
377  */
378 int dpdmux_get_attributes(struct fsl_mc_io *mc_io,
379 			  uint32_t cmd_flags,
380 			  uint16_t token,
381 			  struct dpdmux_attr *attr)
382 {
383 	struct mc_command cmd = { 0 };
384 	struct dpdmux_rsp_get_attr *rsp_params;
385 	int err;
386 
387 	/* prepare command */
388 	cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_GET_ATTR,
389 					  cmd_flags,
390 					  token);
391 
392 	/* send command to mc*/
393 	err = mc_send_command(mc_io, &cmd);
394 	if (err)
395 		return err;
396 
397 	/* retrieve response parameters */
398 	rsp_params = (struct dpdmux_rsp_get_attr *)cmd.params;
399 	attr->id = le32_to_cpu(rsp_params->id);
400 	attr->options = le64_to_cpu(rsp_params->options);
401 	attr->method = rsp_params->method;
402 	attr->manip = rsp_params->manip;
403 	attr->num_ifs = le16_to_cpu(rsp_params->num_ifs);
404 	attr->mem_size = le16_to_cpu(rsp_params->mem_size);
405 	attr->default_if = le16_to_cpu(rsp_params->default_if);
406 	attr->max_dmat_entries = le16_to_cpu(rsp_params->max_dmat_entries);
407 	attr->max_mc_groups = le16_to_cpu(rsp_params->max_mc_groups);
408 	attr->max_vlan_ids = le16_to_cpu(rsp_params->max_vlan_ids);
409 
410 	return 0;
411 }
412 
413 /**
414  * dpdmux_if_enable() - Enable Interface
415  * @mc_io:	Pointer to MC portal's I/O object
416  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
417  * @token:	Token of DPDMUX object
418  * @if_id:	Interface Identifier
419  *
420  * Return:	Completion status. '0' on Success; Error code otherwise.
421  */
422 int dpdmux_if_enable(struct fsl_mc_io *mc_io,
423 		     uint32_t cmd_flags,
424 		     uint16_t token,
425 		     uint16_t if_id)
426 {
427 	struct dpdmux_cmd_if *cmd_params;
428 	struct mc_command cmd = { 0 };
429 
430 	/* prepare command */
431 	cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_IF_ENABLE,
432 					  cmd_flags,
433 					  token);
434 	cmd_params = (struct dpdmux_cmd_if *)cmd.params;
435 	cmd_params->if_id = cpu_to_le16(if_id);
436 
437 	/* send command to mc*/
438 	return mc_send_command(mc_io, &cmd);
439 }
440 
441 /**
442  * dpdmux_if_disable() - Disable Interface
443  * @mc_io:	Pointer to MC portal's I/O object
444  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
445  * @token:	Token of DPDMUX object
446  * @if_id:	Interface Identifier
447  *
448  * Return:	Completion status. '0' on Success; Error code otherwise.
449  */
450 int dpdmux_if_disable(struct fsl_mc_io *mc_io,
451 		      uint32_t cmd_flags,
452 		      uint16_t token,
453 		      uint16_t if_id)
454 {
455 	struct dpdmux_cmd_if *cmd_params;
456 	struct mc_command cmd = { 0 };
457 
458 	/* prepare command */
459 	cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_IF_DISABLE,
460 					  cmd_flags,
461 					  token);
462 	cmd_params = (struct dpdmux_cmd_if *)cmd.params;
463 	cmd_params->if_id = cpu_to_le16(if_id);
464 
465 	/* send command to mc*/
466 	return mc_send_command(mc_io, &cmd);
467 }
468 
469 /**
470  * dpdmux_set_max_frame_length() - Set the maximum frame length in DPDMUX
471  * @mc_io:	Pointer to MC portal's I/O object
472  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
473  * @token:		Token of DPDMUX object
474  * @max_frame_length:	The required maximum frame length
475  *
476  * Update the maximum frame length on all DMUX interfaces.
477  * In case of VEPA, the maximum frame length on all dmux interfaces
478  * will be updated with the minimum value of the mfls of the connected
479  * dpnis and the actual value of dmux mfl.
480  *
481  * If dpdmux object is created using DPDMUX_OPT_AUTO_MAX_FRAME_LEN and maximum
482  * frame length is changed for a dpni connected to dpdmux interface the change
483  * is propagated through dpdmux interfaces and will overwrite the value set using
484  * this API.
485  *
486  * Return:	'0' on Success; Error code otherwise.
487  */
488 int dpdmux_set_max_frame_length(struct fsl_mc_io *mc_io,
489 				uint32_t cmd_flags,
490 				uint16_t token,
491 				uint16_t max_frame_length)
492 {
493 	struct mc_command cmd = { 0 };
494 	struct dpdmux_cmd_set_max_frame_length *cmd_params;
495 
496 	/* prepare command */
497 	cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_SET_MAX_FRAME_LENGTH,
498 					  cmd_flags,
499 					  token);
500 	cmd_params = (struct dpdmux_cmd_set_max_frame_length *)cmd.params;
501 	cmd_params->max_frame_length = cpu_to_le16(max_frame_length);
502 
503 	/* send command to mc*/
504 	return mc_send_command(mc_io, &cmd);
505 }
506 
507 /**
508  * dpdmux_get_max_frame_length() - Return the maximum frame length for DPDMUX
509  * interface
510  * @mc_io:	Pointer to MC portal's I/O object
511  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
512  * @token:		Token of DPDMUX object
513  * @if_id:		Interface id
514  * @max_frame_length:	maximum frame length
515  *
516  * When dpdmux object is in VEPA mode this function will ignore if_id parameter
517  * and will return maximum frame length for uplink interface (if_id==0).
518  *
519  * Return:	'0' on Success; Error code otherwise.
520  */
521 int dpdmux_get_max_frame_length(struct fsl_mc_io *mc_io,
522 				uint32_t cmd_flags,
523 				uint16_t token,
524 				uint16_t if_id,
525 				uint16_t *max_frame_length)
526 {
527 	struct mc_command cmd = { 0 };
528 	struct dpdmux_cmd_get_max_frame_len *cmd_params;
529 	struct dpdmux_rsp_get_max_frame_len *rsp_params;
530 	int err = 0;
531 
532 	/* prepare command */
533 	cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_GET_MAX_FRAME_LENGTH,
534 					  cmd_flags,
535 					  token);
536 	cmd_params = (struct dpdmux_cmd_get_max_frame_len *)cmd.params;
537 	cmd_params->if_id = cpu_to_le16(if_id);
538 
539 	err = mc_send_command(mc_io, &cmd);
540 	if (err)
541 		return err;
542 
543 	rsp_params = (struct dpdmux_rsp_get_max_frame_len *)cmd.params;
544 	*max_frame_length = le16_to_cpu(rsp_params->max_len);
545 
546 	/* send command to mc*/
547 	return err;
548 }
549 
550 /**
551  * dpdmux_ul_reset_counters() - Function resets the uplink counter
552  * @mc_io:	Pointer to MC portal's I/O object
553  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
554  * @token:	Token of DPDMUX object
555  *
556  * Return:	'0' on Success; Error code otherwise.
557  */
558 int dpdmux_ul_reset_counters(struct fsl_mc_io *mc_io,
559 			     uint32_t cmd_flags,
560 			     uint16_t token)
561 {
562 	struct mc_command cmd = { 0 };
563 
564 	/* prepare command */
565 	cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_UL_RESET_COUNTERS,
566 					  cmd_flags,
567 					  token);
568 
569 	/* send command to mc*/
570 	return mc_send_command(mc_io, &cmd);
571 }
572 
573 /**
574  * dpdmux_if_set_accepted_frames() - Set the accepted frame types
575  * @mc_io:	Pointer to MC portal's I/O object
576  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
577  * @token:	Token of DPDMUX object
578  * @if_id:	Interface ID (0 for uplink, or 1-num_ifs);
579  * @cfg:	Frame types configuration
580  *
581  * if 'DPDMUX_ADMIT_ONLY_VLAN_TAGGED' is set - untagged frames or
582  * priority-tagged frames are discarded.
583  * if 'DPDMUX_ADMIT_ONLY_UNTAGGED' is set - untagged frames or
584  * priority-tagged frames are accepted.
585  * if 'DPDMUX_ADMIT_ALL' is set (default mode) - all VLAN tagged,
586  * untagged and priority-tagged frame are accepted;
587  *
588  * Return:	'0' on Success; Error code otherwise.
589  */
590 int dpdmux_if_set_accepted_frames(struct fsl_mc_io *mc_io,
591 				  uint32_t cmd_flags,
592 				  uint16_t token,
593 				  uint16_t if_id,
594 				  const struct dpdmux_accepted_frames *cfg)
595 {
596 	struct mc_command cmd = { 0 };
597 	struct dpdmux_cmd_if_set_accepted_frames *cmd_params;
598 
599 	/* prepare command */
600 	cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_IF_SET_ACCEPTED_FRAMES,
601 					  cmd_flags,
602 					  token);
603 	cmd_params = (struct dpdmux_cmd_if_set_accepted_frames *)cmd.params;
604 	cmd_params->if_id = cpu_to_le16(if_id);
605 	dpdmux_set_field(cmd_params->frames_options,
606 			 ACCEPTED_FRAMES_TYPE,
607 			 cfg->type);
608 	dpdmux_set_field(cmd_params->frames_options,
609 			 UNACCEPTED_FRAMES_ACTION,
610 			 cfg->unaccept_act);
611 
612 	/* send command to mc*/
613 	return mc_send_command(mc_io, &cmd);
614 }
615 
616 /**
617  * dpdmux_if_get_attributes() - Obtain DPDMUX interface attributes
618  * @mc_io:	Pointer to MC portal's I/O object
619  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
620  * @token:	Token of DPDMUX object
621  * @if_id:	Interface ID (0 for uplink, or 1-num_ifs);
622  * @attr:	Interface attributes
623  *
624  * Return:	'0' on Success; Error code otherwise.
625  */
626 int dpdmux_if_get_attributes(struct fsl_mc_io *mc_io,
627 			     uint32_t cmd_flags,
628 			     uint16_t token,
629 			     uint16_t if_id,
630 			     struct dpdmux_if_attr *attr)
631 {
632 	struct mc_command cmd = { 0 };
633 	struct dpdmux_cmd_if *cmd_params;
634 	struct dpdmux_rsp_if_get_attr *rsp_params;
635 	int err;
636 
637 	/* prepare command */
638 	cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_IF_GET_ATTR,
639 					  cmd_flags,
640 					  token);
641 	cmd_params = (struct dpdmux_cmd_if *)cmd.params;
642 	cmd_params->if_id = cpu_to_le16(if_id);
643 
644 	/* send command to mc*/
645 	err = mc_send_command(mc_io, &cmd);
646 	if (err)
647 		return err;
648 
649 	/* retrieve response parameters */
650 	rsp_params = (struct dpdmux_rsp_if_get_attr *)cmd.params;
651 	attr->rate = le32_to_cpu(rsp_params->rate);
652 	attr->enabled = dpdmux_get_field(rsp_params->enabled, ENABLE);
653 	attr->is_default = dpdmux_get_field(rsp_params->enabled, IS_DEFAULT);
654 	attr->accept_frame_type = dpdmux_get_field(
655 				  rsp_params->accepted_frames_type,
656 				  ACCEPTED_FRAMES_TYPE);
657 
658 	return 0;
659 }
660 
661 /**
662  * dpdmux_if_remove_l2_rule() - Remove L2 rule from DPDMUX table
663  * @mc_io:	Pointer to MC portal's I/O object
664  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
665  * @token:	Token of DPDMUX object
666  * @if_id:	Destination interface ID
667  * @rule:	L2 rule
668  *
669  * Function removes a L2 rule from DPDMUX table
670  * or adds an interface to an existing multicast address
671  *
672  * Return:	'0' on Success; Error code otherwise.
673  */
674 int dpdmux_if_remove_l2_rule(struct fsl_mc_io *mc_io,
675 			     uint32_t cmd_flags,
676 			     uint16_t token,
677 			     uint16_t if_id,
678 			     const struct dpdmux_l2_rule *rule)
679 {
680 	struct mc_command cmd = { 0 };
681 	struct dpdmux_cmd_if_l2_rule *cmd_params;
682 
683 	/* prepare command */
684 	cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_IF_REMOVE_L2_RULE,
685 					  cmd_flags,
686 					  token);
687 	cmd_params = (struct dpdmux_cmd_if_l2_rule *)cmd.params;
688 	cmd_params->if_id = cpu_to_le16(if_id);
689 	cmd_params->vlan_id = cpu_to_le16(rule->vlan_id);
690 	cmd_params->mac_addr5 = rule->mac_addr[5];
691 	cmd_params->mac_addr4 = rule->mac_addr[4];
692 	cmd_params->mac_addr3 = rule->mac_addr[3];
693 	cmd_params->mac_addr2 = rule->mac_addr[2];
694 	cmd_params->mac_addr1 = rule->mac_addr[1];
695 	cmd_params->mac_addr0 = rule->mac_addr[0];
696 
697 	/* send command to mc*/
698 	return mc_send_command(mc_io, &cmd);
699 }
700 
701 /**
702  * dpdmux_if_add_l2_rule() - Add L2 rule into DPDMUX table
703  * @mc_io:	Pointer to MC portal's I/O object
704  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
705  * @token:	Token of DPDMUX object
706  * @if_id:	Destination interface ID
707  * @rule:	L2 rule
708  *
709  * Function adds a L2 rule into DPDMUX table
710  * or adds an interface to an existing multicast address
711  *
712  * Return:	'0' on Success; Error code otherwise.
713  */
714 int dpdmux_if_add_l2_rule(struct fsl_mc_io *mc_io,
715 			  uint32_t cmd_flags,
716 			  uint16_t token,
717 			  uint16_t if_id,
718 			  const struct dpdmux_l2_rule *rule)
719 {
720 	struct mc_command cmd = { 0 };
721 	struct dpdmux_cmd_if_l2_rule *cmd_params;
722 
723 	/* prepare command */
724 	cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_IF_ADD_L2_RULE,
725 					  cmd_flags,
726 					  token);
727 	cmd_params = (struct dpdmux_cmd_if_l2_rule *)cmd.params;
728 	cmd_params->if_id = cpu_to_le16(if_id);
729 	cmd_params->vlan_id = cpu_to_le16(rule->vlan_id);
730 	cmd_params->mac_addr5 = rule->mac_addr[5];
731 	cmd_params->mac_addr4 = rule->mac_addr[4];
732 	cmd_params->mac_addr3 = rule->mac_addr[3];
733 	cmd_params->mac_addr2 = rule->mac_addr[2];
734 	cmd_params->mac_addr1 = rule->mac_addr[1];
735 	cmd_params->mac_addr0 = rule->mac_addr[0];
736 
737 	/* send command to mc*/
738 	return mc_send_command(mc_io, &cmd);
739 }
740 
741 /**
742  * dpdmux_if_get_counter() - Functions obtains specific counter of an interface
743  * @mc_io: Pointer to MC portal's I/O object
744  * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
745  * @token: Token of DPDMUX object
746  * @if_id:  Interface Id
747  * @counter_type: counter type
748  * @counter: Returned specific counter information
749  *
750  * Return:	'0' on Success; Error code otherwise.
751  */
752 int dpdmux_if_get_counter(struct fsl_mc_io *mc_io,
753 			  uint32_t cmd_flags,
754 			  uint16_t token,
755 			  uint16_t if_id,
756 			  enum dpdmux_counter_type counter_type,
757 			  uint64_t *counter)
758 {
759 	struct mc_command cmd = { 0 };
760 	struct dpdmux_cmd_if_get_counter *cmd_params;
761 	struct dpdmux_rsp_if_get_counter *rsp_params;
762 	int err;
763 
764 	/* prepare command */
765 	cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_IF_GET_COUNTER,
766 					  cmd_flags,
767 					  token);
768 	cmd_params = (struct dpdmux_cmd_if_get_counter *)cmd.params;
769 	cmd_params->if_id = cpu_to_le16(if_id);
770 	cmd_params->counter_type = counter_type;
771 
772 	/* send command to mc*/
773 	err = mc_send_command(mc_io, &cmd);
774 	if (err)
775 		return err;
776 
777 	/* retrieve response parameters */
778 	rsp_params = (struct dpdmux_rsp_if_get_counter *)cmd.params;
779 	*counter = le64_to_cpu(rsp_params->counter);
780 
781 	return 0;
782 }
783 
784 /**
785  * dpdmux_if_set_link_cfg() - set the link configuration.
786  * @mc_io:	Pointer to MC portal's I/O object
787  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
788  * @token: Token of DPSW object
789  * @if_id: interface id
790  * @cfg: Link configuration
791  *
792  * Return:	'0' on Success; Error code otherwise.
793  */
794 int dpdmux_if_set_link_cfg(struct fsl_mc_io *mc_io,
795 			   uint32_t cmd_flags,
796 			   uint16_t token,
797 			   uint16_t if_id,
798 			   struct dpdmux_link_cfg *cfg)
799 {
800 	struct mc_command cmd = { 0 };
801 	struct dpdmux_cmd_if_set_link_cfg *cmd_params;
802 
803 	/* prepare command */
804 	cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_IF_SET_LINK_CFG,
805 					  cmd_flags,
806 					  token);
807 	cmd_params = (struct dpdmux_cmd_if_set_link_cfg *)cmd.params;
808 	cmd_params->if_id = cpu_to_le16(if_id);
809 	cmd_params->rate = cpu_to_le32(cfg->rate);
810 	cmd_params->options = cpu_to_le64(cfg->options);
811 	cmd_params->advertising = cpu_to_le64(cfg->advertising);
812 
813 	/* send command to mc*/
814 	return mc_send_command(mc_io, &cmd);
815 }
816 
817 /**
818  * dpdmux_if_get_link_state - Return the link state
819  * @mc_io:	Pointer to MC portal's I/O object
820  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
821  * @token: Token of DPSW object
822  * @if_id: interface id
823  * @state: link state
824  *
825  * @returns	'0' on Success; Error code otherwise.
826  */
827 int dpdmux_if_get_link_state(struct fsl_mc_io *mc_io,
828 			     uint32_t cmd_flags,
829 			     uint16_t token,
830 			     uint16_t if_id,
831 			     struct dpdmux_link_state *state)
832 {
833 	struct mc_command cmd = { 0 };
834 	struct dpdmux_cmd_if_get_link_state *cmd_params;
835 	struct dpdmux_rsp_if_get_link_state *rsp_params;
836 	int err;
837 
838 	/* prepare command */
839 	cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_IF_GET_LINK_STATE,
840 					  cmd_flags,
841 					  token);
842 	cmd_params = (struct dpdmux_cmd_if_get_link_state *)cmd.params;
843 	cmd_params->if_id = cpu_to_le16(if_id);
844 
845 	/* send command to mc*/
846 	err = mc_send_command(mc_io, &cmd);
847 	if (err)
848 		return err;
849 
850 	/* retrieve response parameters */
851 	rsp_params = (struct dpdmux_rsp_if_get_link_state *)cmd.params;
852 	state->rate = le32_to_cpu(rsp_params->rate);
853 	state->options = le64_to_cpu(rsp_params->options);
854 	state->up = dpdmux_get_field(rsp_params->up, UP);
855 	state->state_valid = dpdmux_get_field(rsp_params->up, STATE_VALID);
856 	state->supported = le64_to_cpu(rsp_params->supported);
857 	state->advertising = le64_to_cpu(rsp_params->advertising);
858 
859 	return 0;
860 }
861 
862 /**
863  * dpdmux_if_set_default - Set default interface
864  * @mc_io:	Pointer to MC portal's I/O object
865  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
866  * @token: Token of DPSW object
867  * @if_id: interface id
868  *
869  * @returns	'0' on Success; Error code otherwise.
870  */
871 int dpdmux_if_set_default(struct fsl_mc_io *mc_io,
872 		uint32_t cmd_flags,
873 		uint16_t token,
874 		uint16_t if_id)
875 {
876 	struct dpdmux_cmd_if *cmd_params;
877 	struct mc_command cmd = { 0 };
878 
879 	/* prepare command */
880 	cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_IF_SET_DEFAULT,
881 					  cmd_flags,
882 					  token);
883 	cmd_params = (struct dpdmux_cmd_if *)cmd.params;
884 	cmd_params->if_id = cpu_to_le16(if_id);
885 
886 	/* send command to mc*/
887 	return mc_send_command(mc_io, &cmd);
888 }
889 
890 /**
891  * dpdmux_if_get_default - Get default interface
892  * @mc_io:	Pointer to MC portal's I/O object
893  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
894  * @token: Token of DPSW object
895  * @if_id: interface id
896  *
897  * @returns	'0' on Success; Error code otherwise.
898  */
899 int dpdmux_if_get_default(struct fsl_mc_io *mc_io,
900 		uint32_t cmd_flags,
901 		uint16_t token,
902 		uint16_t *if_id)
903 {
904 	struct dpdmux_cmd_if *rsp_params;
905 	struct mc_command cmd = { 0 };
906 	int err;
907 
908 	/* prepare command */
909 	cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_IF_GET_DEFAULT,
910 					  cmd_flags,
911 					  token);
912 
913 	/* send command to mc*/
914 	err = mc_send_command(mc_io, &cmd);
915 	if (err)
916 		return err;
917 
918 	/* retrieve response parameters */
919 	rsp_params = (struct dpdmux_cmd_if *)cmd.params;
920 	*if_id = le16_to_cpu(rsp_params->if_id);
921 
922 	return 0;
923 }
924 
925 /**
926  * dpdmux_set_custom_key - Set a custom classification key.
927  *
928  * This API is only available for DPDMUX instance created with
929  * DPDMUX_METHOD_CUSTOM.  This API must be called before populating the
930  * classification table using dpdmux_add_custom_cls_entry.
931  *
932  * Calls to dpdmux_set_custom_key remove all existing classification entries
933  * that may have been added previously using dpdmux_add_custom_cls_entry.
934  *
935  * @mc_io:		Pointer to MC portal's I/O object
936  * @cmd_flags:		Command flags; one or more of 'MC_CMD_FLAG_'
937  * @token:		Token of DPSW object
938  * @if_id:		Interface id
939  * @key_cfg_iova:	DMA address of a configuration structure set up using
940  *			dpkg_prepare_key_cfg. Maximum key size is 24 bytes
941  *
942  * @returns	'0' on Success; Error code otherwise.
943  */
944 int dpdmux_set_custom_key(struct fsl_mc_io *mc_io,
945 			uint32_t cmd_flags,
946 			uint16_t token,
947 			uint64_t key_cfg_iova)
948 {
949 	struct dpdmux_set_custom_key *cmd_params;
950 	struct mc_command cmd = { 0 };
951 
952 	/* prepare command */
953 	cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_SET_CUSTOM_KEY,
954 					  cmd_flags,
955 					  token);
956 	cmd_params = (struct dpdmux_set_custom_key *)cmd.params;
957 	cmd_params->key_cfg_iova = cpu_to_le64(key_cfg_iova);
958 
959 	/* send command to mc*/
960 	return mc_send_command(mc_io, &cmd);
961 }
962 
963 /**
964  * dpdmux_add_custom_cls_entry - Adds a custom classification entry.
965  *
966  * This API is only available for DPDMUX instances created with
967  * DPDMUX_METHOD_CUSTOM.  Before calling this function a classification key
968  * composition rule must be set up using dpdmux_set_custom_key.
969  *
970  * @mc_io:	Pointer to MC portal's I/O object
971  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
972  * @token: Token of DPSW object
973  * @rule: Classification rule to insert.  Rules cannot be duplicated, if a
974  *	matching rule already exists, the action will be replaced.
975  * @action: Action to perform for matching traffic.
976  *
977  * @returns	'0' on Success; Error code otherwise.
978  */
979 int dpdmux_add_custom_cls_entry(struct fsl_mc_io *mc_io,
980 		uint32_t cmd_flags,
981 		uint16_t token,
982 		struct dpdmux_rule_cfg *rule,
983 		struct dpdmux_cls_action *action)
984 {
985 	struct dpdmux_cmd_add_custom_cls_entry *cmd_params;
986 	struct mc_command cmd = { 0 };
987 
988 	/* prepare command */
989 	cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_ADD_CUSTOM_CLS_ENTRY,
990 					  cmd_flags,
991 					  token);
992 
993 	cmd_params = (struct dpdmux_cmd_add_custom_cls_entry *)cmd.params;
994 	cmd_params->key_size = rule->key_size;
995 	cmd_params->entry_index = rule->entry_index;
996 	cmd_params->dest_if = cpu_to_le16(action->dest_if);
997 	cmd_params->key_iova = cpu_to_le64(rule->key_iova);
998 	cmd_params->mask_iova = cpu_to_le64(rule->mask_iova);
999 
1000 	/* send command to mc*/
1001 	return mc_send_command(mc_io, &cmd);
1002 }
1003 
1004 /**
1005  * dpdmux_remove_custom_cls_entry - Removes a custom classification entry.
1006  *
1007  * This API is only available for DPDMUX instances created with
1008  * DPDMUX_METHOD_CUSTOM.  The API can be used to remove classification
1009  * entries previously inserted using dpdmux_add_custom_cls_entry.
1010  *
1011  * @mc_io:	Pointer to MC portal's I/O object
1012  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
1013  * @token: Token of DPSW object
1014  * @rule: Classification rule to remove
1015  *
1016  * @returns	'0' on Success; Error code otherwise.
1017  */
1018 int dpdmux_remove_custom_cls_entry(struct fsl_mc_io *mc_io,
1019 		uint32_t cmd_flags,
1020 		uint16_t token,
1021 		struct dpdmux_rule_cfg *rule)
1022 {
1023 	struct dpdmux_cmd_remove_custom_cls_entry *cmd_params;
1024 	struct mc_command cmd = { 0 };
1025 
1026 	/* prepare command */
1027 	cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_REMOVE_CUSTOM_CLS_ENTRY,
1028 					  cmd_flags,
1029 					  token);
1030 	cmd_params = (struct dpdmux_cmd_remove_custom_cls_entry *)cmd.params;
1031 	cmd_params->key_size = rule->key_size;
1032 	cmd_params->key_iova = cpu_to_le64(rule->key_iova);
1033 	cmd_params->mask_iova = cpu_to_le64(rule->mask_iova);
1034 
1035 	/* send command to mc*/
1036 	return mc_send_command(mc_io, &cmd);
1037 }
1038 
1039 /**
1040  * dpdmux_get_api_version() - Get Data Path Demux API version
1041  * @mc_io:  Pointer to MC portal's I/O object
1042  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
1043  * @major_ver:	Major version of data path demux API
1044  * @minor_ver:	Minor version of data path demux API
1045  *
1046  * Return:  '0' on Success; Error code otherwise.
1047  */
1048 int dpdmux_get_api_version(struct fsl_mc_io *mc_io,
1049 			   uint32_t cmd_flags,
1050 			   uint16_t *major_ver,
1051 			   uint16_t *minor_ver)
1052 {
1053 	struct mc_command cmd = { 0 };
1054 	struct dpdmux_rsp_get_api_version *rsp_params;
1055 	int err;
1056 
1057 	cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_GET_API_VERSION,
1058 					cmd_flags,
1059 					0);
1060 
1061 	err = mc_send_command(mc_io, &cmd);
1062 	if (err)
1063 		return err;
1064 
1065 	rsp_params = (struct dpdmux_rsp_get_api_version *)cmd.params;
1066 	*major_ver = le16_to_cpu(rsp_params->major);
1067 	*minor_ver = le16_to_cpu(rsp_params->minor);
1068 
1069 	return 0;
1070 }
1071 
1072 /**
1073  * dpdmux_if_set_taildrop() - enable taildrop for egress interface queues.
1074  * @mc_io:	Pointer to MC portal's I/O object
1075  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
1076  * @token:	Token of DPDMUX object
1077  * @if_id:	Interface Identifier
1078  * @cfg: Taildrop configuration
1079  */
1080 int dpdmux_if_set_taildrop(struct fsl_mc_io *mc_io, uint32_t cmd_flags, uint16_t token,
1081 			      uint16_t if_id, struct dpdmux_taildrop_cfg *cfg)
1082 {
1083 	struct mc_command cmd = { 0 };
1084 	struct dpdmux_cmd_set_taildrop *cmd_params;
1085 
1086 	/* prepare command */
1087 	cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_IF_SET_TAILDROP,
1088 			cmd_flags,
1089 			token);
1090 	cmd_params = (struct dpdmux_cmd_set_taildrop *)cmd.params;
1091 	cmd_params->if_id		= cpu_to_le16(if_id);
1092 	cmd_params->units		= cfg->units;
1093 	cmd_params->threshold	= cpu_to_le32(cfg->threshold);
1094 	dpdmux_set_field(cmd_params->oal_en, ENABLE, (!!cfg->enable));
1095 
1096 	return mc_send_command(mc_io, &cmd);
1097 }
1098 
1099 /**
1100  * dpdmux_if_get_taildrop() - get current taildrop configuration.
1101  * @mc_io:	Pointer to MC portal's I/O object
1102  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
1103  * @token:	Token of DPDMUX object
1104  * @if_id:	Interface Identifier
1105  * @cfg: Taildrop configuration
1106  */
1107 int dpdmux_if_get_taildrop(struct fsl_mc_io *mc_io, uint32_t cmd_flags, uint16_t token,
1108 			      uint16_t if_id, struct dpdmux_taildrop_cfg *cfg)
1109 {
1110 	struct mc_command cmd = {0};
1111 	struct dpdmux_cmd_get_taildrop *cmd_params;
1112 	struct dpdmux_rsp_get_taildrop *rsp_params;
1113 	int err = 0;
1114 
1115 	/* prepare command */
1116 	cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_IF_GET_TAILDROP,
1117 			cmd_flags,
1118 			token);
1119 	cmd_params = (struct dpdmux_cmd_get_taildrop *)cmd.params;
1120 	cmd_params->if_id	= cpu_to_le16(if_id);
1121 
1122 	err = mc_send_command(mc_io, &cmd);
1123 	if (err)
1124 		return err;
1125 
1126 	/* retrieve response parameters */
1127 	rsp_params = (struct dpdmux_rsp_get_taildrop *)cmd.params;
1128 	cfg->threshold = le32_to_cpu(rsp_params->threshold);
1129 	cfg->units = rsp_params->units;
1130 	cfg->enable = dpdmux_get_field(rsp_params->oal_en, ENABLE);
1131 
1132 	return err;
1133 }
1134 
1135 /**
1136  * dpdmux_dump_table() - Dump the content of table_type table into memory.
1137  * @mc_io: Pointer to MC portal's I/O object
1138  * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1139  * @token: Token of DPSW object
1140  * @table_type: The type of the table to dump
1141  *	- DPDMUX_DMAT_TABLE
1142  *	- DPDMUX_MISS_TABLE
1143  *	- DPDMUX_PRUNE_TABLE
1144  * @table_index: The index of the table to dump in case of more than one table
1145  *	if table_type == DPDMUX_DMAT_TABLE
1146  *		- DPDMUX_HMAP_UNICAST
1147  *		- DPDMUX_HMAP_MULTICAST
1148  *	else 0
1149  * @iova_addr: The snapshot will be stored in this variable as an header of struct dump_table_header
1150  *             followed by an array of struct dump_table_entry
1151  * @iova_size: Memory size allocated for iova_addr
1152  * @num_entries: Number of entries written in iova_addr
1153  *
1154  * Return: Completion status. '0' on Success; Error code otherwise.
1155  *
1156  * The memory allocated at iova_addr must be zeroed before command execution.
1157  * If the table content exceeds the memory size provided the dump will be truncated.
1158  */
1159 int dpdmux_dump_table(struct fsl_mc_io *mc_io,
1160 			 uint32_t cmd_flags,
1161 			 uint16_t token,
1162 			 uint16_t table_type,
1163 			 uint16_t table_index,
1164 			 uint64_t iova_addr,
1165 			 uint32_t iova_size,
1166 			 uint16_t *num_entries)
1167 {
1168 	struct mc_command cmd = { 0 };
1169 	int err;
1170 	struct dpdmux_cmd_dump_table *cmd_params;
1171 	struct dpdmux_rsp_dump_table *rsp_params;
1172 
1173 	/* prepare command */
1174 	cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_DUMP_TABLE, cmd_flags, token);
1175 	cmd_params = (struct dpdmux_cmd_dump_table *)cmd.params;
1176 	cmd_params->table_type = cpu_to_le16(table_type);
1177 	cmd_params->table_index = cpu_to_le16(table_index);
1178 	cmd_params->iova_addr = cpu_to_le64(iova_addr);
1179 	cmd_params->iova_size = cpu_to_le32(iova_size);
1180 
1181 	/* send command to mc*/
1182 	err = mc_send_command(mc_io, &cmd);
1183 	if (err)
1184 		return err;
1185 
1186 	rsp_params = (struct dpdmux_rsp_dump_table *)cmd.params;
1187 	*num_entries = le16_to_cpu(rsp_params->num_entries);
1188 
1189 	return 0;
1190 }
1191 
1192 
1193 /**
1194  * dpdmux_if_set_errors_behavior() - Set errors behavior
1195  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
1196  * @token:	Token of DPSW object
1197  * @if_id:  Interface Identifier
1198  * @cfg:	Errors configuration
1199  *
1200  * Provides a set of frame errors that will be rejected or accepted by the
1201  * dpdmux interface. The frame with this errors will no longer be dropped by
1202  * the dpdmux interface. When frame has parsing error the distribution to
1203  * expected interface may fail. If the frame must be distributed using the
1204  * information from a header that was not parsed due errors the frame may
1205  * be discarded or end up on a default interface because needed data was not
1206  * parsed properly.
1207  * This function may be called numerous times with different error masks
1208  *
1209  * Return:	'0' on Success; Error code otherwise.
1210  */
1211 int dpdmux_if_set_errors_behavior(struct fsl_mc_io *mc_io, uint32_t cmd_flags,
1212 		uint16_t token, uint16_t if_id, struct dpdmux_error_cfg *cfg)
1213 {
1214 	struct mc_command cmd = { 0 };
1215 	struct dpdmux_cmd_set_errors_behavior *cmd_params;
1216 
1217 	/* prepare command */
1218 	cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_SET_ERRORS_BEHAVIOR,
1219 					cmd_flags,
1220 					token);
1221 	cmd_params = (struct dpdmux_cmd_set_errors_behavior *)cmd.params;
1222 	cmd_params->errors = cpu_to_le32(cfg->errors);
1223 	dpdmux_set_field(cmd_params->flags, ERROR_ACTION, cfg->error_action);
1224 	cmd_params->if_id = cpu_to_le16(if_id);
1225 
1226 	/* send command to mc*/
1227 	return mc_send_command(mc_io, &cmd);
1228 }
1229 
1230 /* Sets up a Soft Parser Profile on this DPDMUX
1231  * @mc_io:	Pointer to MC portal's I/O object
1232  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
1233  * @token:	Token of DPDMUX object
1234  * @sp_profile: Soft Parser Profile name (must a valid name for a defined profile)
1235  *			Maximum allowed length for this string is 8 characters long
1236  *			If this parameter is empty string (all zeros)
1237  *			then the Default SP Profile is set on this dpdmux
1238  * @type: one of the SP Profile types defined above: Ingress or Egress (or both using bitwise OR)
1239  */
1240 int dpdmux_set_sp_profile(struct fsl_mc_io *mc_io, uint32_t cmd_flags, uint16_t token,
1241 		uint8_t sp_profile[], uint8_t type)
1242 {
1243 	struct dpdmux_cmd_set_sp_profile *cmd_params;
1244 	struct mc_command cmd = { 0 };
1245 	int i;
1246 
1247 	/* prepare command */
1248 	cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_SET_SP_PROFILE,
1249 			cmd_flags, token);
1250 
1251 	cmd_params = (struct dpdmux_cmd_set_sp_profile *)cmd.params;
1252 	for (i = 0; i < MAX_SP_PROFILE_ID_SIZE && sp_profile[i]; i++)
1253 		cmd_params->sp_profile[i] = sp_profile[i];
1254 	cmd_params->type = type;
1255 
1256 	/* send command to MC */
1257 	return mc_send_command(mc_io, &cmd);
1258 }
1259 
1260 /* Enable/Disable Soft Parser on this DPDMUX interface
1261  * @mc_io:	Pointer to MC portal's I/O object
1262  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
1263  * @token:	Token of DPDMUX object
1264  * @if_id: interface id
1265  * @type: one of the SP Profile types defined above: Ingress or Egress (or both using bitwise OR)
1266  * @en: 1 to enable or 0 to disable
1267  */
1268 int dpdmux_sp_enable(struct fsl_mc_io *mc_io, uint32_t cmd_flags, uint16_t token,
1269 		uint16_t if_id, uint8_t type, uint8_t en)
1270 {
1271 	struct dpdmux_cmd_sp_enable *cmd_params;
1272 	struct mc_command cmd = { 0 };
1273 
1274 	/* prepare command */
1275 	cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_SP_ENABLE,
1276 			cmd_flags, token);
1277 
1278 	cmd_params = (struct dpdmux_cmd_sp_enable *)cmd.params;
1279 	cmd_params->if_id = if_id;
1280 	cmd_params->type = type;
1281 	cmd_params->en = en;
1282 
1283 	/* send command to MC */
1284 	return mc_send_command(mc_io, &cmd);
1285 }
1286