xref: /dpdk/drivers/net/dpaa2/mc/dpdmux.c (revision daa02b5cddbb8e11b31d41e2bf7bb1ae64dcae2f)
1 /* SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0)
2  *
3  * Copyright 2013-2016 Freescale Semiconductor Inc.
4  * Copyright 2018-2021 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_DEFAULT_INTERFACE  0x01
292  *			DPDMUX_SKIP_UNICAST_RULES      0x02
293  *			DPDMUX_SKIP_MULTICAST_RULES    0x04
294  *
295  * For example, by default, through DPDMUX_RESET the default
296  * interface will be restored with the one from create.
297  * By setting DPDMUX_SKIP_DEFAULT_INTERFACE flag,
298  * through DPDMUX_RESET the default interface will not be modified.
299  *
300  * Return:	'0' on Success; Error code otherwise.
301  */
302 int dpdmux_set_resetable(struct fsl_mc_io *mc_io,
303 				  uint32_t cmd_flags,
304 				  uint16_t token,
305 				  uint8_t skip_reset_flags)
306 {
307 	struct mc_command cmd = { 0 };
308 	struct dpdmux_cmd_set_skip_reset_flags *cmd_params;
309 
310 	/* prepare command */
311 	cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_SET_RESETABLE,
312 					  cmd_flags,
313 					  token);
314 	cmd_params = (struct dpdmux_cmd_set_skip_reset_flags *)cmd.params;
315 	dpdmux_set_field(cmd_params->skip_reset_flags,
316 			SKIP_RESET_FLAGS,
317 			skip_reset_flags);
318 
319 	/* send command to mc*/
320 	return mc_send_command(mc_io, &cmd);
321 }
322 
323 /**
324  * dpdmux_get_resetable() - Get overall resetable parameters.
325  * @mc_io:	Pointer to MC portal's I/O object
326  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
327  * @token:	Token of DPDMUX object
328  * @skip_reset_flags:	Get the reset flags.
329  *
330  *	The flags are:
331  *			DPDMUX_SKIP_DEFAULT_INTERFACE  0x01
332  *			DPDMUX_SKIP_UNICAST_RULES      0x02
333  *			DPDMUX_SKIP_MULTICAST_RULES    0x04
334  *
335  * Return:	'0' on Success; Error code otherwise.
336  */
337 int dpdmux_get_resetable(struct fsl_mc_io *mc_io,
338 				  uint32_t cmd_flags,
339 				  uint16_t token,
340 				  uint8_t *skip_reset_flags)
341 {
342 	struct mc_command cmd = { 0 };
343 	struct dpdmux_rsp_get_skip_reset_flags *rsp_params;
344 	int err;
345 
346 	/* prepare command */
347 	cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_GET_RESETABLE,
348 					  cmd_flags,
349 					  token);
350 
351 	/* send command to mc*/
352 	err = mc_send_command(mc_io, &cmd);
353 	if (err)
354 		return err;
355 
356 	/* retrieve response parameters */
357 	rsp_params = (struct dpdmux_rsp_get_skip_reset_flags *)cmd.params;
358 	*skip_reset_flags = dpdmux_get_field(rsp_params->skip_reset_flags,
359 			SKIP_RESET_FLAGS);
360 
361 	return 0;
362 }
363 
364 /**
365  * dpdmux_get_attributes() - Retrieve DPDMUX attributes
366  * @mc_io:	Pointer to MC portal's I/O object
367  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
368  * @token:	Token of DPDMUX object
369  * @attr:	Returned object's attributes
370  *
371  * Return:	'0' on Success; Error code otherwise.
372  */
373 int dpdmux_get_attributes(struct fsl_mc_io *mc_io,
374 			  uint32_t cmd_flags,
375 			  uint16_t token,
376 			  struct dpdmux_attr *attr)
377 {
378 	struct mc_command cmd = { 0 };
379 	struct dpdmux_rsp_get_attr *rsp_params;
380 	int err;
381 
382 	/* prepare command */
383 	cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_GET_ATTR,
384 					  cmd_flags,
385 					  token);
386 
387 	/* send command to mc*/
388 	err = mc_send_command(mc_io, &cmd);
389 	if (err)
390 		return err;
391 
392 	/* retrieve response parameters */
393 	rsp_params = (struct dpdmux_rsp_get_attr *)cmd.params;
394 	attr->id = le32_to_cpu(rsp_params->id);
395 	attr->options = le64_to_cpu(rsp_params->options);
396 	attr->method = rsp_params->method;
397 	attr->manip = rsp_params->manip;
398 	attr->num_ifs = le16_to_cpu(rsp_params->num_ifs);
399 	attr->mem_size = le16_to_cpu(rsp_params->mem_size);
400 	attr->default_if = le16_to_cpu(rsp_params->default_if);
401 
402 	return 0;
403 }
404 
405 /**
406  * dpdmux_if_enable() - Enable Interface
407  * @mc_io:	Pointer to MC portal's I/O object
408  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
409  * @token:	Token of DPDMUX object
410  * @if_id:	Interface Identifier
411  *
412  * Return:	Completion status. '0' on Success; Error code otherwise.
413  */
414 int dpdmux_if_enable(struct fsl_mc_io *mc_io,
415 		     uint32_t cmd_flags,
416 		     uint16_t token,
417 		     uint16_t if_id)
418 {
419 	struct dpdmux_cmd_if *cmd_params;
420 	struct mc_command cmd = { 0 };
421 
422 	/* prepare command */
423 	cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_IF_ENABLE,
424 					  cmd_flags,
425 					  token);
426 	cmd_params = (struct dpdmux_cmd_if *)cmd.params;
427 	cmd_params->if_id = cpu_to_le16(if_id);
428 
429 	/* send command to mc*/
430 	return mc_send_command(mc_io, &cmd);
431 }
432 
433 /**
434  * dpdmux_if_disable() - Disable Interface
435  * @mc_io:	Pointer to MC portal's I/O object
436  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
437  * @token:	Token of DPDMUX object
438  * @if_id:	Interface Identifier
439  *
440  * Return:	Completion status. '0' on Success; Error code otherwise.
441  */
442 int dpdmux_if_disable(struct fsl_mc_io *mc_io,
443 		      uint32_t cmd_flags,
444 		      uint16_t token,
445 		      uint16_t if_id)
446 {
447 	struct dpdmux_cmd_if *cmd_params;
448 	struct mc_command cmd = { 0 };
449 
450 	/* prepare command */
451 	cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_IF_DISABLE,
452 					  cmd_flags,
453 					  token);
454 	cmd_params = (struct dpdmux_cmd_if *)cmd.params;
455 	cmd_params->if_id = cpu_to_le16(if_id);
456 
457 	/* send command to mc*/
458 	return mc_send_command(mc_io, &cmd);
459 }
460 
461 /**
462  * dpdmux_set_max_frame_length() - Set the maximum frame length in DPDMUX
463  * @mc_io:	Pointer to MC portal's I/O object
464  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
465  * @token:		Token of DPDMUX object
466  * @max_frame_length:	The required maximum frame length
467  *
468  * Update the maximum frame length on all DMUX interfaces.
469  * In case of VEPA, the maximum frame length on all dmux interfaces
470  * will be updated with the minimum value of the mfls of the connected
471  * dpnis and the actual value of dmux mfl.
472  *
473  * Return:	'0' on Success; Error code otherwise.
474  */
475 int dpdmux_set_max_frame_length(struct fsl_mc_io *mc_io,
476 				uint32_t cmd_flags,
477 				uint16_t token,
478 				uint16_t max_frame_length)
479 {
480 	struct mc_command cmd = { 0 };
481 	struct dpdmux_cmd_set_max_frame_length *cmd_params;
482 
483 	/* prepare command */
484 	cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_SET_MAX_FRAME_LENGTH,
485 					  cmd_flags,
486 					  token);
487 	cmd_params = (struct dpdmux_cmd_set_max_frame_length *)cmd.params;
488 	cmd_params->max_frame_length = cpu_to_le16(max_frame_length);
489 
490 	/* send command to mc*/
491 	return mc_send_command(mc_io, &cmd);
492 }
493 
494 /**
495  * dpdmux_get_max_frame_length() - Return the maximum frame length for DPDMUX
496  * interface
497  * @mc_io:	Pointer to MC portal's I/O object
498  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
499  * @token:		Token of DPDMUX object
500  * @if_id:		Interface id
501  * @max_frame_length:	maximum frame length
502  *
503  * When dpdmux object is in VEPA mode this function will ignore if_id parameter
504  * and will return maximum frame length for uplink interface (if_id==0).
505  *
506  * Return:	'0' on Success; Error code otherwise.
507  */
508 int dpdmux_get_max_frame_length(struct fsl_mc_io *mc_io,
509 				uint32_t cmd_flags,
510 				uint16_t token,
511 				uint16_t if_id,
512 				uint16_t *max_frame_length)
513 {
514 	struct mc_command cmd = { 0 };
515 	struct dpdmux_cmd_get_max_frame_len *cmd_params;
516 	struct dpdmux_rsp_get_max_frame_len *rsp_params;
517 	int err = 0;
518 
519 	/* prepare command */
520 	cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_GET_MAX_FRAME_LENGTH,
521 					  cmd_flags,
522 					  token);
523 	cmd_params = (struct dpdmux_cmd_get_max_frame_len *)cmd.params;
524 	cmd_params->if_id = cpu_to_le16(if_id);
525 
526 	err = mc_send_command(mc_io, &cmd);
527 	if (err)
528 		return err;
529 
530 	rsp_params = (struct dpdmux_rsp_get_max_frame_len *)cmd.params;
531 	*max_frame_length = le16_to_cpu(rsp_params->max_len);
532 
533 	/* send command to mc*/
534 	return err;
535 }
536 
537 /**
538  * dpdmux_ul_reset_counters() - Function resets the uplink counter
539  * @mc_io:	Pointer to MC portal's I/O object
540  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
541  * @token:	Token of DPDMUX object
542  *
543  * Return:	'0' on Success; Error code otherwise.
544  */
545 int dpdmux_ul_reset_counters(struct fsl_mc_io *mc_io,
546 			     uint32_t cmd_flags,
547 			     uint16_t token)
548 {
549 	struct mc_command cmd = { 0 };
550 
551 	/* prepare command */
552 	cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_UL_RESET_COUNTERS,
553 					  cmd_flags,
554 					  token);
555 
556 	/* send command to mc*/
557 	return mc_send_command(mc_io, &cmd);
558 }
559 
560 /**
561  * dpdmux_if_set_accepted_frames() - Set the accepted frame types
562  * @mc_io:	Pointer to MC portal's I/O object
563  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
564  * @token:	Token of DPDMUX object
565  * @if_id:	Interface ID (0 for uplink, or 1-num_ifs);
566  * @cfg:	Frame types configuration
567  *
568  * if 'DPDMUX_ADMIT_ONLY_VLAN_TAGGED' is set - untagged frames or
569  * priority-tagged frames are discarded.
570  * if 'DPDMUX_ADMIT_ONLY_UNTAGGED' is set - untagged frames or
571  * priority-tagged frames are accepted.
572  * if 'DPDMUX_ADMIT_ALL' is set (default mode) - all VLAN tagged,
573  * untagged and priority-tagged frame are accepted;
574  *
575  * Return:	'0' on Success; Error code otherwise.
576  */
577 int dpdmux_if_set_accepted_frames(struct fsl_mc_io *mc_io,
578 				  uint32_t cmd_flags,
579 				  uint16_t token,
580 				  uint16_t if_id,
581 				  const struct dpdmux_accepted_frames *cfg)
582 {
583 	struct mc_command cmd = { 0 };
584 	struct dpdmux_cmd_if_set_accepted_frames *cmd_params;
585 
586 	/* prepare command */
587 	cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_IF_SET_ACCEPTED_FRAMES,
588 					  cmd_flags,
589 					  token);
590 	cmd_params = (struct dpdmux_cmd_if_set_accepted_frames *)cmd.params;
591 	cmd_params->if_id = cpu_to_le16(if_id);
592 	dpdmux_set_field(cmd_params->frames_options,
593 			 ACCEPTED_FRAMES_TYPE,
594 			 cfg->type);
595 	dpdmux_set_field(cmd_params->frames_options,
596 			 UNACCEPTED_FRAMES_ACTION,
597 			 cfg->unaccept_act);
598 
599 	/* send command to mc*/
600 	return mc_send_command(mc_io, &cmd);
601 }
602 
603 /**
604  * dpdmux_if_get_attributes() - Obtain DPDMUX interface attributes
605  * @mc_io:	Pointer to MC portal's I/O object
606  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
607  * @token:	Token of DPDMUX object
608  * @if_id:	Interface ID (0 for uplink, or 1-num_ifs);
609  * @attr:	Interface attributes
610  *
611  * Return:	'0' on Success; Error code otherwise.
612  */
613 int dpdmux_if_get_attributes(struct fsl_mc_io *mc_io,
614 			     uint32_t cmd_flags,
615 			     uint16_t token,
616 			     uint16_t if_id,
617 			     struct dpdmux_if_attr *attr)
618 {
619 	struct mc_command cmd = { 0 };
620 	struct dpdmux_cmd_if *cmd_params;
621 	struct dpdmux_rsp_if_get_attr *rsp_params;
622 	int err;
623 
624 	/* prepare command */
625 	cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_IF_GET_ATTR,
626 					  cmd_flags,
627 					  token);
628 	cmd_params = (struct dpdmux_cmd_if *)cmd.params;
629 	cmd_params->if_id = cpu_to_le16(if_id);
630 
631 	/* send command to mc*/
632 	err = mc_send_command(mc_io, &cmd);
633 	if (err)
634 		return err;
635 
636 	/* retrieve response parameters */
637 	rsp_params = (struct dpdmux_rsp_if_get_attr *)cmd.params;
638 	attr->rate = le32_to_cpu(rsp_params->rate);
639 	attr->enabled = dpdmux_get_field(rsp_params->enabled, ENABLE);
640 	attr->is_default = dpdmux_get_field(rsp_params->enabled, IS_DEFAULT);
641 	attr->accept_frame_type = dpdmux_get_field(
642 				  rsp_params->accepted_frames_type,
643 				  ACCEPTED_FRAMES_TYPE);
644 
645 	return 0;
646 }
647 
648 /**
649  * dpdmux_if_remove_l2_rule() - Remove L2 rule from DPDMUX table
650  * @mc_io:	Pointer to MC portal's I/O object
651  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
652  * @token:	Token of DPDMUX object
653  * @if_id:	Destination interface ID
654  * @rule:	L2 rule
655  *
656  * Function removes a L2 rule from DPDMUX table
657  * or adds an interface to an existing multicast address
658  *
659  * Return:	'0' on Success; Error code otherwise.
660  */
661 int dpdmux_if_remove_l2_rule(struct fsl_mc_io *mc_io,
662 			     uint32_t cmd_flags,
663 			     uint16_t token,
664 			     uint16_t if_id,
665 			     const struct dpdmux_l2_rule *rule)
666 {
667 	struct mc_command cmd = { 0 };
668 	struct dpdmux_cmd_if_l2_rule *cmd_params;
669 
670 	/* prepare command */
671 	cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_IF_REMOVE_L2_RULE,
672 					  cmd_flags,
673 					  token);
674 	cmd_params = (struct dpdmux_cmd_if_l2_rule *)cmd.params;
675 	cmd_params->if_id = cpu_to_le16(if_id);
676 	cmd_params->vlan_id = cpu_to_le16(rule->vlan_id);
677 	cmd_params->mac_addr5 = rule->mac_addr[5];
678 	cmd_params->mac_addr4 = rule->mac_addr[4];
679 	cmd_params->mac_addr3 = rule->mac_addr[3];
680 	cmd_params->mac_addr2 = rule->mac_addr[2];
681 	cmd_params->mac_addr1 = rule->mac_addr[1];
682 	cmd_params->mac_addr0 = rule->mac_addr[0];
683 
684 	/* send command to mc*/
685 	return mc_send_command(mc_io, &cmd);
686 }
687 
688 /**
689  * dpdmux_if_add_l2_rule() - Add L2 rule into DPDMUX table
690  * @mc_io:	Pointer to MC portal's I/O object
691  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
692  * @token:	Token of DPDMUX object
693  * @if_id:	Destination interface ID
694  * @rule:	L2 rule
695  *
696  * Function adds a L2 rule into DPDMUX table
697  * or adds an interface to an existing multicast address
698  *
699  * Return:	'0' on Success; Error code otherwise.
700  */
701 int dpdmux_if_add_l2_rule(struct fsl_mc_io *mc_io,
702 			  uint32_t cmd_flags,
703 			  uint16_t token,
704 			  uint16_t if_id,
705 			  const struct dpdmux_l2_rule *rule)
706 {
707 	struct mc_command cmd = { 0 };
708 	struct dpdmux_cmd_if_l2_rule *cmd_params;
709 
710 	/* prepare command */
711 	cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_IF_ADD_L2_RULE,
712 					  cmd_flags,
713 					  token);
714 	cmd_params = (struct dpdmux_cmd_if_l2_rule *)cmd.params;
715 	cmd_params->if_id = cpu_to_le16(if_id);
716 	cmd_params->vlan_id = cpu_to_le16(rule->vlan_id);
717 	cmd_params->mac_addr5 = rule->mac_addr[5];
718 	cmd_params->mac_addr4 = rule->mac_addr[4];
719 	cmd_params->mac_addr3 = rule->mac_addr[3];
720 	cmd_params->mac_addr2 = rule->mac_addr[2];
721 	cmd_params->mac_addr1 = rule->mac_addr[1];
722 	cmd_params->mac_addr0 = rule->mac_addr[0];
723 
724 	/* send command to mc*/
725 	return mc_send_command(mc_io, &cmd);
726 }
727 
728 /**
729  * dpdmux_if_get_counter() - Functions obtains specific counter of an interface
730  * @mc_io: Pointer to MC portal's I/O object
731  * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
732  * @token: Token of DPDMUX object
733  * @if_id:  Interface Id
734  * @counter_type: counter type
735  * @counter: Returned specific counter information
736  *
737  * Return:	'0' on Success; Error code otherwise.
738  */
739 int dpdmux_if_get_counter(struct fsl_mc_io *mc_io,
740 			  uint32_t cmd_flags,
741 			  uint16_t token,
742 			  uint16_t if_id,
743 			  enum dpdmux_counter_type counter_type,
744 			  uint64_t *counter)
745 {
746 	struct mc_command cmd = { 0 };
747 	struct dpdmux_cmd_if_get_counter *cmd_params;
748 	struct dpdmux_rsp_if_get_counter *rsp_params;
749 	int err;
750 
751 	/* prepare command */
752 	cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_IF_GET_COUNTER,
753 					  cmd_flags,
754 					  token);
755 	cmd_params = (struct dpdmux_cmd_if_get_counter *)cmd.params;
756 	cmd_params->if_id = cpu_to_le16(if_id);
757 	cmd_params->counter_type = counter_type;
758 
759 	/* send command to mc*/
760 	err = mc_send_command(mc_io, &cmd);
761 	if (err)
762 		return err;
763 
764 	/* retrieve response parameters */
765 	rsp_params = (struct dpdmux_rsp_if_get_counter *)cmd.params;
766 	*counter = le64_to_cpu(rsp_params->counter);
767 
768 	return 0;
769 }
770 
771 /**
772  * dpdmux_if_set_link_cfg() - set the link configuration.
773  * @mc_io:	Pointer to MC portal's I/O object
774  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
775  * @token: Token of DPSW object
776  * @if_id: interface id
777  * @cfg: Link configuration
778  *
779  * Return:	'0' on Success; Error code otherwise.
780  */
781 int dpdmux_if_set_link_cfg(struct fsl_mc_io *mc_io,
782 			   uint32_t cmd_flags,
783 			   uint16_t token,
784 			   uint16_t if_id,
785 			   struct dpdmux_link_cfg *cfg)
786 {
787 	struct mc_command cmd = { 0 };
788 	struct dpdmux_cmd_if_set_link_cfg *cmd_params;
789 
790 	/* prepare command */
791 	cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_IF_SET_LINK_CFG,
792 					  cmd_flags,
793 					  token);
794 	cmd_params = (struct dpdmux_cmd_if_set_link_cfg *)cmd.params;
795 	cmd_params->if_id = cpu_to_le16(if_id);
796 	cmd_params->rate = cpu_to_le32(cfg->rate);
797 	cmd_params->options = cpu_to_le64(cfg->options);
798 	cmd_params->advertising = cpu_to_le64(cfg->advertising);
799 
800 	/* send command to mc*/
801 	return mc_send_command(mc_io, &cmd);
802 }
803 
804 /**
805  * dpdmux_if_get_link_state - Return the link state
806  * @mc_io:	Pointer to MC portal's I/O object
807  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
808  * @token: Token of DPSW object
809  * @if_id: interface id
810  * @state: link state
811  *
812  * @returns	'0' on Success; Error code otherwise.
813  */
814 int dpdmux_if_get_link_state(struct fsl_mc_io *mc_io,
815 			     uint32_t cmd_flags,
816 			     uint16_t token,
817 			     uint16_t if_id,
818 			     struct dpdmux_link_state *state)
819 {
820 	struct mc_command cmd = { 0 };
821 	struct dpdmux_cmd_if_get_link_state *cmd_params;
822 	struct dpdmux_rsp_if_get_link_state *rsp_params;
823 	int err;
824 
825 	/* prepare command */
826 	cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_IF_GET_LINK_STATE,
827 					  cmd_flags,
828 					  token);
829 	cmd_params = (struct dpdmux_cmd_if_get_link_state *)cmd.params;
830 	cmd_params->if_id = cpu_to_le16(if_id);
831 
832 	/* send command to mc*/
833 	err = mc_send_command(mc_io, &cmd);
834 	if (err)
835 		return err;
836 
837 	/* retrieve response parameters */
838 	rsp_params = (struct dpdmux_rsp_if_get_link_state *)cmd.params;
839 	state->rate = le32_to_cpu(rsp_params->rate);
840 	state->options = le64_to_cpu(rsp_params->options);
841 	state->up = dpdmux_get_field(rsp_params->up, UP);
842 	state->state_valid = dpdmux_get_field(rsp_params->up, STATE_VALID);
843 	state->supported = le64_to_cpu(rsp_params->supported);
844 	state->advertising = le64_to_cpu(rsp_params->advertising);
845 
846 	return 0;
847 }
848 
849 /**
850  * dpdmux_if_set_default - Set default interface
851  * @mc_io:	Pointer to MC portal's I/O object
852  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
853  * @token: Token of DPSW object
854  * @if_id: interface id
855  *
856  * @returns	'0' on Success; Error code otherwise.
857  */
858 int dpdmux_if_set_default(struct fsl_mc_io *mc_io,
859 		uint32_t cmd_flags,
860 		uint16_t token,
861 		uint16_t if_id)
862 {
863 	struct dpdmux_cmd_if *cmd_params;
864 	struct mc_command cmd = { 0 };
865 
866 	/* prepare command */
867 	cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_IF_SET_DEFAULT,
868 					  cmd_flags,
869 					  token);
870 	cmd_params = (struct dpdmux_cmd_if *)cmd.params;
871 	cmd_params->if_id = cpu_to_le16(if_id);
872 
873 	/* send command to mc*/
874 	return mc_send_command(mc_io, &cmd);
875 }
876 
877 /**
878  * dpdmux_if_get_default - Get default interface
879  * @mc_io:	Pointer to MC portal's I/O object
880  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
881  * @token: Token of DPSW object
882  * @if_id: interface id
883  *
884  * @returns	'0' on Success; Error code otherwise.
885  */
886 int dpdmux_if_get_default(struct fsl_mc_io *mc_io,
887 		uint32_t cmd_flags,
888 		uint16_t token,
889 		uint16_t *if_id)
890 {
891 	struct dpdmux_cmd_if *rsp_params;
892 	struct mc_command cmd = { 0 };
893 	int err;
894 
895 	/* prepare command */
896 	cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_IF_GET_DEFAULT,
897 					  cmd_flags,
898 					  token);
899 
900 	/* send command to mc*/
901 	err = mc_send_command(mc_io, &cmd);
902 	if (err)
903 		return err;
904 
905 	/* retrieve response parameters */
906 	rsp_params = (struct dpdmux_cmd_if *)cmd.params;
907 	*if_id = le16_to_cpu(rsp_params->if_id);
908 
909 	return 0;
910 }
911 
912 /**
913  * dpdmux_set_custom_key - Set a custom classification key.
914  *
915  * This API is only available for DPDMUX instance created with
916  * DPDMUX_METHOD_CUSTOM.  This API must be called before populating the
917  * classification table using dpdmux_add_custom_cls_entry.
918  *
919  * Calls to dpdmux_set_custom_key remove all existing classification entries
920  * that may have been added previously using dpdmux_add_custom_cls_entry.
921  *
922  * @mc_io:		Pointer to MC portal's I/O object
923  * @cmd_flags:		Command flags; one or more of 'MC_CMD_FLAG_'
924  * @token:		Token of DPSW object
925  * @if_id:		Interface id
926  * @key_cfg_iova:	DMA address of a configuration structure set up using
927  *			dpkg_prepare_key_cfg. Maximum key size is 24 bytes
928  *
929  * @returns	'0' on Success; Error code otherwise.
930  */
931 int dpdmux_set_custom_key(struct fsl_mc_io *mc_io,
932 			uint32_t cmd_flags,
933 			uint16_t token,
934 			uint64_t key_cfg_iova)
935 {
936 	struct dpdmux_set_custom_key *cmd_params;
937 	struct mc_command cmd = { 0 };
938 
939 	/* prepare command */
940 	cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_SET_CUSTOM_KEY,
941 					  cmd_flags,
942 					  token);
943 	cmd_params = (struct dpdmux_set_custom_key *)cmd.params;
944 	cmd_params->key_cfg_iova = cpu_to_le64(key_cfg_iova);
945 
946 	/* send command to mc*/
947 	return mc_send_command(mc_io, &cmd);
948 }
949 
950 /**
951  * dpdmux_add_custom_cls_entry - Adds a custom classification entry.
952  *
953  * This API is only available for DPDMUX instances created with
954  * DPDMUX_METHOD_CUSTOM.  Before calling this function a classification key
955  * composition rule must be set up using dpdmux_set_custom_key.
956  *
957  * @mc_io:	Pointer to MC portal's I/O object
958  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
959  * @token: Token of DPSW object
960  * @rule: Classification rule to insert.  Rules cannot be duplicated, if a
961  *	matching rule already exists, the action will be replaced.
962  * @action: Action to perform for matching traffic.
963  *
964  * @returns	'0' on Success; Error code otherwise.
965  */
966 int dpdmux_add_custom_cls_entry(struct fsl_mc_io *mc_io,
967 		uint32_t cmd_flags,
968 		uint16_t token,
969 		struct dpdmux_rule_cfg *rule,
970 		struct dpdmux_cls_action *action)
971 {
972 	struct dpdmux_cmd_add_custom_cls_entry *cmd_params;
973 	struct mc_command cmd = { 0 };
974 
975 	/* prepare command */
976 	cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_ADD_CUSTOM_CLS_ENTRY,
977 					  cmd_flags,
978 					  token);
979 
980 	cmd_params = (struct dpdmux_cmd_add_custom_cls_entry *)cmd.params;
981 	cmd_params->key_size = rule->key_size;
982 	cmd_params->entry_index = rule->entry_index;
983 	cmd_params->dest_if = cpu_to_le16(action->dest_if);
984 	cmd_params->key_iova = cpu_to_le64(rule->key_iova);
985 	cmd_params->mask_iova = cpu_to_le64(rule->mask_iova);
986 
987 	/* send command to mc*/
988 	return mc_send_command(mc_io, &cmd);
989 }
990 
991 /**
992  * dpdmux_remove_custom_cls_entry - Removes a custom classification entry.
993  *
994  * This API is only available for DPDMUX instances created with
995  * DPDMUX_METHOD_CUSTOM.  The API can be used to remove classification
996  * entries previously inserted using dpdmux_add_custom_cls_entry.
997  *
998  * @mc_io:	Pointer to MC portal's I/O object
999  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
1000  * @token: Token of DPSW object
1001  * @rule: Classification rule to remove
1002  *
1003  * @returns	'0' on Success; Error code otherwise.
1004  */
1005 int dpdmux_remove_custom_cls_entry(struct fsl_mc_io *mc_io,
1006 		uint32_t cmd_flags,
1007 		uint16_t token,
1008 		struct dpdmux_rule_cfg *rule)
1009 {
1010 	struct dpdmux_cmd_remove_custom_cls_entry *cmd_params;
1011 	struct mc_command cmd = { 0 };
1012 
1013 	/* prepare command */
1014 	cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_REMOVE_CUSTOM_CLS_ENTRY,
1015 					  cmd_flags,
1016 					  token);
1017 	cmd_params = (struct dpdmux_cmd_remove_custom_cls_entry *)cmd.params;
1018 	cmd_params->key_size = rule->key_size;
1019 	cmd_params->key_iova = cpu_to_le64(rule->key_iova);
1020 	cmd_params->mask_iova = cpu_to_le64(rule->mask_iova);
1021 
1022 	/* send command to mc*/
1023 	return mc_send_command(mc_io, &cmd);
1024 }
1025 
1026 /**
1027  * dpdmux_get_api_version() - Get Data Path Demux API version
1028  * @mc_io:  Pointer to MC portal's I/O object
1029  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
1030  * @major_ver:	Major version of data path demux API
1031  * @minor_ver:	Minor version of data path demux API
1032  *
1033  * Return:  '0' on Success; Error code otherwise.
1034  */
1035 int dpdmux_get_api_version(struct fsl_mc_io *mc_io,
1036 			   uint32_t cmd_flags,
1037 			   uint16_t *major_ver,
1038 			   uint16_t *minor_ver)
1039 {
1040 	struct mc_command cmd = { 0 };
1041 	struct dpdmux_rsp_get_api_version *rsp_params;
1042 	int err;
1043 
1044 	cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_GET_API_VERSION,
1045 					cmd_flags,
1046 					0);
1047 
1048 	err = mc_send_command(mc_io, &cmd);
1049 	if (err)
1050 		return err;
1051 
1052 	rsp_params = (struct dpdmux_rsp_get_api_version *)cmd.params;
1053 	*major_ver = le16_to_cpu(rsp_params->major);
1054 	*minor_ver = le16_to_cpu(rsp_params->minor);
1055 
1056 	return 0;
1057 }
1058 
1059 /**
1060  * dpdmux_if_set_errors_behavior() - Set errors behavior
1061  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
1062  * @token:	Token of DPSW object
1063  * @if_id:  Interface Identifier
1064  * @cfg:	Errors configuration
1065  *
1066  * Provides a set of frame errors that will be rejected or accepted by the
1067  * dpdmux interface. The frame with this errors will no longer be dropped by
1068  * the dpdmux interface. When frame has parsing error the distribution to
1069  * expected interface may fail. If the frame must be distributed using the
1070  * information from a header that was not parsed due errors the frame may
1071  * be discarded or end up on a default interface because needed data was not
1072  * parsed properly.
1073  * This function may be called numerous times with different error masks
1074  *
1075  * Return:	'0' on Success; Error code otherwise.
1076  */
1077 int dpdmux_if_set_errors_behavior(struct fsl_mc_io *mc_io, uint32_t cmd_flags,
1078 		uint16_t token, uint16_t if_id, struct dpdmux_error_cfg *cfg)
1079 {
1080 	struct mc_command cmd = { 0 };
1081 	struct dpdmux_cmd_set_errors_behavior *cmd_params;
1082 
1083 	/* prepare command */
1084 	cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_SET_ERRORS_BEHAVIOR,
1085 					cmd_flags,
1086 					token);
1087 	cmd_params = (struct dpdmux_cmd_set_errors_behavior *)cmd.params;
1088 	cmd_params->errors = cpu_to_le32(cfg->errors);
1089 	dpdmux_set_field(cmd_params->flags, ERROR_ACTION, cfg->error_action);
1090 	cmd_params->if_id = cpu_to_le16(if_id);
1091 
1092 	/* send command to mc*/
1093 	return mc_send_command(mc_io, &cmd);
1094 }
1095