xref: /dpdk/drivers/net/dpaa2/mc/dpdmux.c (revision b7b78a089c454d42eb654360eeecb1e2f15e6cd8)
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_ul_reset_counters() - Function resets the uplink counter
496  * @mc_io:	Pointer to MC portal's I/O object
497  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
498  * @token:	Token of DPDMUX object
499  *
500  * Return:	'0' on Success; Error code otherwise.
501  */
502 int dpdmux_ul_reset_counters(struct fsl_mc_io *mc_io,
503 			     uint32_t cmd_flags,
504 			     uint16_t token)
505 {
506 	struct mc_command cmd = { 0 };
507 
508 	/* prepare command */
509 	cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_UL_RESET_COUNTERS,
510 					  cmd_flags,
511 					  token);
512 
513 	/* send command to mc*/
514 	return mc_send_command(mc_io, &cmd);
515 }
516 
517 /**
518  * dpdmux_if_set_accepted_frames() - Set the accepted frame types
519  * @mc_io:	Pointer to MC portal's I/O object
520  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
521  * @token:	Token of DPDMUX object
522  * @if_id:	Interface ID (0 for uplink, or 1-num_ifs);
523  * @cfg:	Frame types configuration
524  *
525  * if 'DPDMUX_ADMIT_ONLY_VLAN_TAGGED' is set - untagged frames or
526  * priority-tagged frames are discarded.
527  * if 'DPDMUX_ADMIT_ONLY_UNTAGGED' is set - untagged frames or
528  * priority-tagged frames are accepted.
529  * if 'DPDMUX_ADMIT_ALL' is set (default mode) - all VLAN tagged,
530  * untagged and priority-tagged frame are accepted;
531  *
532  * Return:	'0' on Success; Error code otherwise.
533  */
534 int dpdmux_if_set_accepted_frames(struct fsl_mc_io *mc_io,
535 				  uint32_t cmd_flags,
536 				  uint16_t token,
537 				  uint16_t if_id,
538 				  const struct dpdmux_accepted_frames *cfg)
539 {
540 	struct mc_command cmd = { 0 };
541 	struct dpdmux_cmd_if_set_accepted_frames *cmd_params;
542 
543 	/* prepare command */
544 	cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_IF_SET_ACCEPTED_FRAMES,
545 					  cmd_flags,
546 					  token);
547 	cmd_params = (struct dpdmux_cmd_if_set_accepted_frames *)cmd.params;
548 	cmd_params->if_id = cpu_to_le16(if_id);
549 	dpdmux_set_field(cmd_params->frames_options,
550 			 ACCEPTED_FRAMES_TYPE,
551 			 cfg->type);
552 	dpdmux_set_field(cmd_params->frames_options,
553 			 UNACCEPTED_FRAMES_ACTION,
554 			 cfg->unaccept_act);
555 
556 	/* send command to mc*/
557 	return mc_send_command(mc_io, &cmd);
558 }
559 
560 /**
561  * dpdmux_if_get_attributes() - Obtain DPDMUX interface attributes
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  * @attr:	Interface attributes
567  *
568  * Return:	'0' on Success; Error code otherwise.
569  */
570 int dpdmux_if_get_attributes(struct fsl_mc_io *mc_io,
571 			     uint32_t cmd_flags,
572 			     uint16_t token,
573 			     uint16_t if_id,
574 			     struct dpdmux_if_attr *attr)
575 {
576 	struct mc_command cmd = { 0 };
577 	struct dpdmux_cmd_if *cmd_params;
578 	struct dpdmux_rsp_if_get_attr *rsp_params;
579 	int err;
580 
581 	/* prepare command */
582 	cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_IF_GET_ATTR,
583 					  cmd_flags,
584 					  token);
585 	cmd_params = (struct dpdmux_cmd_if *)cmd.params;
586 	cmd_params->if_id = cpu_to_le16(if_id);
587 
588 	/* send command to mc*/
589 	err = mc_send_command(mc_io, &cmd);
590 	if (err)
591 		return err;
592 
593 	/* retrieve response parameters */
594 	rsp_params = (struct dpdmux_rsp_if_get_attr *)cmd.params;
595 	attr->rate = le32_to_cpu(rsp_params->rate);
596 	attr->enabled = dpdmux_get_field(rsp_params->enabled, ENABLE);
597 	attr->is_default = dpdmux_get_field(rsp_params->enabled, IS_DEFAULT);
598 	attr->accept_frame_type = dpdmux_get_field(
599 				  rsp_params->accepted_frames_type,
600 				  ACCEPTED_FRAMES_TYPE);
601 
602 	return 0;
603 }
604 
605 /**
606  * dpdmux_if_remove_l2_rule() - Remove L2 rule from DPDMUX table
607  * @mc_io:	Pointer to MC portal's I/O object
608  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
609  * @token:	Token of DPDMUX object
610  * @if_id:	Destination interface ID
611  * @rule:	L2 rule
612  *
613  * Function removes a L2 rule from DPDMUX table
614  * or adds an interface to an existing multicast address
615  *
616  * Return:	'0' on Success; Error code otherwise.
617  */
618 int dpdmux_if_remove_l2_rule(struct fsl_mc_io *mc_io,
619 			     uint32_t cmd_flags,
620 			     uint16_t token,
621 			     uint16_t if_id,
622 			     const struct dpdmux_l2_rule *rule)
623 {
624 	struct mc_command cmd = { 0 };
625 	struct dpdmux_cmd_if_l2_rule *cmd_params;
626 
627 	/* prepare command */
628 	cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_IF_REMOVE_L2_RULE,
629 					  cmd_flags,
630 					  token);
631 	cmd_params = (struct dpdmux_cmd_if_l2_rule *)cmd.params;
632 	cmd_params->if_id = cpu_to_le16(if_id);
633 	cmd_params->vlan_id = cpu_to_le16(rule->vlan_id);
634 	cmd_params->mac_addr5 = rule->mac_addr[5];
635 	cmd_params->mac_addr4 = rule->mac_addr[4];
636 	cmd_params->mac_addr3 = rule->mac_addr[3];
637 	cmd_params->mac_addr2 = rule->mac_addr[2];
638 	cmd_params->mac_addr1 = rule->mac_addr[1];
639 	cmd_params->mac_addr0 = rule->mac_addr[0];
640 
641 	/* send command to mc*/
642 	return mc_send_command(mc_io, &cmd);
643 }
644 
645 /**
646  * dpdmux_if_add_l2_rule() - Add L2 rule into DPDMUX table
647  * @mc_io:	Pointer to MC portal's I/O object
648  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
649  * @token:	Token of DPDMUX object
650  * @if_id:	Destination interface ID
651  * @rule:	L2 rule
652  *
653  * Function adds a L2 rule into DPDMUX table
654  * or adds an interface to an existing multicast address
655  *
656  * Return:	'0' on Success; Error code otherwise.
657  */
658 int dpdmux_if_add_l2_rule(struct fsl_mc_io *mc_io,
659 			  uint32_t cmd_flags,
660 			  uint16_t token,
661 			  uint16_t if_id,
662 			  const struct dpdmux_l2_rule *rule)
663 {
664 	struct mc_command cmd = { 0 };
665 	struct dpdmux_cmd_if_l2_rule *cmd_params;
666 
667 	/* prepare command */
668 	cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_IF_ADD_L2_RULE,
669 					  cmd_flags,
670 					  token);
671 	cmd_params = (struct dpdmux_cmd_if_l2_rule *)cmd.params;
672 	cmd_params->if_id = cpu_to_le16(if_id);
673 	cmd_params->vlan_id = cpu_to_le16(rule->vlan_id);
674 	cmd_params->mac_addr5 = rule->mac_addr[5];
675 	cmd_params->mac_addr4 = rule->mac_addr[4];
676 	cmd_params->mac_addr3 = rule->mac_addr[3];
677 	cmd_params->mac_addr2 = rule->mac_addr[2];
678 	cmd_params->mac_addr1 = rule->mac_addr[1];
679 	cmd_params->mac_addr0 = rule->mac_addr[0];
680 
681 	/* send command to mc*/
682 	return mc_send_command(mc_io, &cmd);
683 }
684 
685 /**
686  * dpdmux_if_get_counter() - Functions obtains specific counter of an interface
687  * @mc_io: Pointer to MC portal's I/O object
688  * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
689  * @token: Token of DPDMUX object
690  * @if_id:  Interface Id
691  * @counter_type: counter type
692  * @counter: Returned specific counter information
693  *
694  * Return:	'0' on Success; Error code otherwise.
695  */
696 int dpdmux_if_get_counter(struct fsl_mc_io *mc_io,
697 			  uint32_t cmd_flags,
698 			  uint16_t token,
699 			  uint16_t if_id,
700 			  enum dpdmux_counter_type counter_type,
701 			  uint64_t *counter)
702 {
703 	struct mc_command cmd = { 0 };
704 	struct dpdmux_cmd_if_get_counter *cmd_params;
705 	struct dpdmux_rsp_if_get_counter *rsp_params;
706 	int err;
707 
708 	/* prepare command */
709 	cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_IF_GET_COUNTER,
710 					  cmd_flags,
711 					  token);
712 	cmd_params = (struct dpdmux_cmd_if_get_counter *)cmd.params;
713 	cmd_params->if_id = cpu_to_le16(if_id);
714 	cmd_params->counter_type = counter_type;
715 
716 	/* send command to mc*/
717 	err = mc_send_command(mc_io, &cmd);
718 	if (err)
719 		return err;
720 
721 	/* retrieve response parameters */
722 	rsp_params = (struct dpdmux_rsp_if_get_counter *)cmd.params;
723 	*counter = le64_to_cpu(rsp_params->counter);
724 
725 	return 0;
726 }
727 
728 /**
729  * dpdmux_if_set_link_cfg() - set the link configuration.
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 DPSW object
733  * @if_id: interface id
734  * @cfg: Link configuration
735  *
736  * Return:	'0' on Success; Error code otherwise.
737  */
738 int dpdmux_if_set_link_cfg(struct fsl_mc_io *mc_io,
739 			   uint32_t cmd_flags,
740 			   uint16_t token,
741 			   uint16_t if_id,
742 			   struct dpdmux_link_cfg *cfg)
743 {
744 	struct mc_command cmd = { 0 };
745 	struct dpdmux_cmd_if_set_link_cfg *cmd_params;
746 
747 	/* prepare command */
748 	cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_IF_SET_LINK_CFG,
749 					  cmd_flags,
750 					  token);
751 	cmd_params = (struct dpdmux_cmd_if_set_link_cfg *)cmd.params;
752 	cmd_params->if_id = cpu_to_le16(if_id);
753 	cmd_params->rate = cpu_to_le32(cfg->rate);
754 	cmd_params->options = cpu_to_le64(cfg->options);
755 	cmd_params->advertising = cpu_to_le64(cfg->advertising);
756 
757 	/* send command to mc*/
758 	return mc_send_command(mc_io, &cmd);
759 }
760 
761 /**
762  * dpdmux_if_get_link_state - Return the link state
763  * @mc_io:	Pointer to MC portal's I/O object
764  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
765  * @token: Token of DPSW object
766  * @if_id: interface id
767  * @state: link state
768  *
769  * @returns	'0' on Success; Error code otherwise.
770  */
771 int dpdmux_if_get_link_state(struct fsl_mc_io *mc_io,
772 			     uint32_t cmd_flags,
773 			     uint16_t token,
774 			     uint16_t if_id,
775 			     struct dpdmux_link_state *state)
776 {
777 	struct mc_command cmd = { 0 };
778 	struct dpdmux_cmd_if_get_link_state *cmd_params;
779 	struct dpdmux_rsp_if_get_link_state *rsp_params;
780 	int err;
781 
782 	/* prepare command */
783 	cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_IF_GET_LINK_STATE,
784 					  cmd_flags,
785 					  token);
786 	cmd_params = (struct dpdmux_cmd_if_get_link_state *)cmd.params;
787 	cmd_params->if_id = cpu_to_le16(if_id);
788 
789 	/* send command to mc*/
790 	err = mc_send_command(mc_io, &cmd);
791 	if (err)
792 		return err;
793 
794 	/* retrieve response parameters */
795 	rsp_params = (struct dpdmux_rsp_if_get_link_state *)cmd.params;
796 	state->rate = le32_to_cpu(rsp_params->rate);
797 	state->options = le64_to_cpu(rsp_params->options);
798 	state->up = dpdmux_get_field(rsp_params->up, UP);
799 	state->state_valid = dpdmux_get_field(rsp_params->up, STATE_VALID);
800 	state->supported = le64_to_cpu(rsp_params->supported);
801 	state->advertising = le64_to_cpu(rsp_params->advertising);
802 
803 	return 0;
804 }
805 
806 /**
807  * dpdmux_if_set_default - Set default interface
808  * @mc_io:	Pointer to MC portal's I/O object
809  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
810  * @token: Token of DPSW object
811  * @if_id: interface id
812  *
813  * @returns	'0' on Success; Error code otherwise.
814  */
815 int dpdmux_if_set_default(struct fsl_mc_io *mc_io,
816 		uint32_t cmd_flags,
817 		uint16_t token,
818 		uint16_t if_id)
819 {
820 	struct dpdmux_cmd_if *cmd_params;
821 	struct mc_command cmd = { 0 };
822 
823 	/* prepare command */
824 	cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_IF_SET_DEFAULT,
825 					  cmd_flags,
826 					  token);
827 	cmd_params = (struct dpdmux_cmd_if *)cmd.params;
828 	cmd_params->if_id = cpu_to_le16(if_id);
829 
830 	/* send command to mc*/
831 	return mc_send_command(mc_io, &cmd);
832 }
833 
834 /**
835  * dpdmux_if_get_default - Get default interface
836  * @mc_io:	Pointer to MC portal's I/O object
837  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
838  * @token: Token of DPSW object
839  * @if_id: interface id
840  *
841  * @returns	'0' on Success; Error code otherwise.
842  */
843 int dpdmux_if_get_default(struct fsl_mc_io *mc_io,
844 		uint32_t cmd_flags,
845 		uint16_t token,
846 		uint16_t *if_id)
847 {
848 	struct dpdmux_cmd_if *rsp_params;
849 	struct mc_command cmd = { 0 };
850 	int err;
851 
852 	/* prepare command */
853 	cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_IF_GET_DEFAULT,
854 					  cmd_flags,
855 					  token);
856 
857 	/* send command to mc*/
858 	err = mc_send_command(mc_io, &cmd);
859 	if (err)
860 		return err;
861 
862 	/* retrieve response parameters */
863 	rsp_params = (struct dpdmux_cmd_if *)cmd.params;
864 	*if_id = le16_to_cpu(rsp_params->if_id);
865 
866 	return 0;
867 }
868 
869 /**
870  * dpdmux_set_custom_key - Set a custom classification key.
871  *
872  * This API is only available for DPDMUX instance created with
873  * DPDMUX_METHOD_CUSTOM.  This API must be called before populating the
874  * classification table using dpdmux_add_custom_cls_entry.
875  *
876  * Calls to dpdmux_set_custom_key remove all existing classification entries
877  * that may have been added previously using dpdmux_add_custom_cls_entry.
878  *
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  * @key_cfg_iova:	DMA address of a configuration structure set up using
884  *			dpkg_prepare_key_cfg. Maximum key size is 24 bytes
885  *
886  * @returns	'0' on Success; Error code otherwise.
887  */
888 int dpdmux_set_custom_key(struct fsl_mc_io *mc_io,
889 			uint32_t cmd_flags,
890 			uint16_t token,
891 			uint64_t key_cfg_iova)
892 {
893 	struct dpdmux_set_custom_key *cmd_params;
894 	struct mc_command cmd = { 0 };
895 
896 	/* prepare command */
897 	cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_SET_CUSTOM_KEY,
898 					  cmd_flags,
899 					  token);
900 	cmd_params = (struct dpdmux_set_custom_key *)cmd.params;
901 	cmd_params->key_cfg_iova = cpu_to_le64(key_cfg_iova);
902 
903 	/* send command to mc*/
904 	return mc_send_command(mc_io, &cmd);
905 }
906 
907 /**
908  * dpdmux_add_custom_cls_entry - Adds a custom classification entry.
909  *
910  * This API is only available for DPDMUX instances created with
911  * DPDMUX_METHOD_CUSTOM.  Before calling this function a classification key
912  * composition rule must be set up using dpdmux_set_custom_key.
913  *
914  * @mc_io:	Pointer to MC portal's I/O object
915  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
916  * @token: Token of DPSW object
917  * @rule: Classification rule to insert.  Rules cannot be duplicated, if a
918  *	matching rule already exists, the action will be replaced.
919  * @action: Action to perform for matching traffic.
920  *
921  * @returns	'0' on Success; Error code otherwise.
922  */
923 int dpdmux_add_custom_cls_entry(struct fsl_mc_io *mc_io,
924 		uint32_t cmd_flags,
925 		uint16_t token,
926 		struct dpdmux_rule_cfg *rule,
927 		struct dpdmux_cls_action *action)
928 {
929 	struct dpdmux_cmd_add_custom_cls_entry *cmd_params;
930 	struct mc_command cmd = { 0 };
931 
932 	/* prepare command */
933 	cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_ADD_CUSTOM_CLS_ENTRY,
934 					  cmd_flags,
935 					  token);
936 
937 	cmd_params = (struct dpdmux_cmd_add_custom_cls_entry *)cmd.params;
938 	cmd_params->key_size = rule->key_size;
939 	cmd_params->entry_index = rule->entry_index;
940 	cmd_params->dest_if = cpu_to_le16(action->dest_if);
941 	cmd_params->key_iova = cpu_to_le64(rule->key_iova);
942 	cmd_params->mask_iova = cpu_to_le64(rule->mask_iova);
943 
944 	/* send command to mc*/
945 	return mc_send_command(mc_io, &cmd);
946 }
947 
948 /**
949  * dpdmux_remove_custom_cls_entry - Removes a custom classification entry.
950  *
951  * This API is only available for DPDMUX instances created with
952  * DPDMUX_METHOD_CUSTOM.  The API can be used to remove classification
953  * entries previously inserted using dpdmux_add_custom_cls_entry.
954  *
955  * @mc_io:	Pointer to MC portal's I/O object
956  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
957  * @token: Token of DPSW object
958  * @rule: Classification rule to remove
959  *
960  * @returns	'0' on Success; Error code otherwise.
961  */
962 int dpdmux_remove_custom_cls_entry(struct fsl_mc_io *mc_io,
963 		uint32_t cmd_flags,
964 		uint16_t token,
965 		struct dpdmux_rule_cfg *rule)
966 {
967 	struct dpdmux_cmd_remove_custom_cls_entry *cmd_params;
968 	struct mc_command cmd = { 0 };
969 
970 	/* prepare command */
971 	cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_REMOVE_CUSTOM_CLS_ENTRY,
972 					  cmd_flags,
973 					  token);
974 	cmd_params = (struct dpdmux_cmd_remove_custom_cls_entry *)cmd.params;
975 	cmd_params->key_size = rule->key_size;
976 	cmd_params->key_iova = cpu_to_le64(rule->key_iova);
977 	cmd_params->mask_iova = cpu_to_le64(rule->mask_iova);
978 
979 	/* send command to mc*/
980 	return mc_send_command(mc_io, &cmd);
981 }
982 
983 /**
984  * dpdmux_get_api_version() - Get Data Path Demux API version
985  * @mc_io:  Pointer to MC portal's I/O object
986  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
987  * @major_ver:	Major version of data path demux API
988  * @minor_ver:	Minor version of data path demux API
989  *
990  * Return:  '0' on Success; Error code otherwise.
991  */
992 int dpdmux_get_api_version(struct fsl_mc_io *mc_io,
993 			   uint32_t cmd_flags,
994 			   uint16_t *major_ver,
995 			   uint16_t *minor_ver)
996 {
997 	struct mc_command cmd = { 0 };
998 	struct dpdmux_rsp_get_api_version *rsp_params;
999 	int err;
1000 
1001 	cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_GET_API_VERSION,
1002 					cmd_flags,
1003 					0);
1004 
1005 	err = mc_send_command(mc_io, &cmd);
1006 	if (err)
1007 		return err;
1008 
1009 	rsp_params = (struct dpdmux_rsp_get_api_version *)cmd.params;
1010 	*major_ver = le16_to_cpu(rsp_params->major);
1011 	*minor_ver = le16_to_cpu(rsp_params->minor);
1012 
1013 	return 0;
1014 }
1015 
1016 /**
1017  * dpdmux_if_set_errors_behavior() - Set errors behavior
1018  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
1019  * @token:	Token of DPSW object
1020  * @if_id:  Interface Identifier
1021  * @cfg:	Errors configuration
1022  *
1023  * Provides a set of frame errors that will be rejected or accepted by the
1024  * dpdmux interface. The frame with this errors will no longer be dropped by
1025  * the dpdmux interface. When frame has parsing error the distribution to
1026  * expected interface may fail. If the frame must be distributed using the
1027  * information from a header that was not parsed due errors the frame may
1028  * be discarded or end up on a default interface because needed data was not
1029  * parsed properly.
1030  * This function may be called numerous times with different error masks
1031  *
1032  * Return:	'0' on Success; Error code otherwise.
1033  */
1034 int dpdmux_if_set_errors_behavior(struct fsl_mc_io *mc_io, uint32_t cmd_flags,
1035 		uint16_t token, uint16_t if_id, struct dpdmux_error_cfg *cfg)
1036 {
1037 	struct mc_command cmd = { 0 };
1038 	struct dpdmux_cmd_set_errors_behavior *cmd_params;
1039 
1040 	/* prepare command */
1041 	cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_SET_ERRORS_BEHAVIOR,
1042 					cmd_flags,
1043 					token);
1044 	cmd_params = (struct dpdmux_cmd_set_errors_behavior *)cmd.params;
1045 	cmd_params->errors = cpu_to_le32(cfg->errors);
1046 	dpdmux_set_field(cmd_params->flags, ERROR_ACTION, cfg->error_action);
1047 	cmd_params->if_id = cpu_to_le16(if_id);
1048 
1049 	/* send command to mc*/
1050 	return mc_send_command(mc_io, &cmd);
1051 }
1052