xref: /dpdk/drivers/net/dpaa2/mc/dpdmux.c (revision 591200ef6f32b56adc367ebe3647cc3dbe9362db)
10817d41fSNipun Gupta /* SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0)
20817d41fSNipun Gupta  *
30817d41fSNipun Gupta  * Copyright 2013-2016 Freescale Semiconductor Inc.
4*591200efSGagandeep Singh  * Copyright 2018-2023 NXP
50817d41fSNipun Gupta  *
60817d41fSNipun Gupta  */
70817d41fSNipun Gupta #include <fsl_mc_sys.h>
80817d41fSNipun Gupta #include <fsl_mc_cmd.h>
90817d41fSNipun Gupta #include <fsl_dpdmux.h>
100817d41fSNipun Gupta #include <fsl_dpdmux_cmd.h>
110817d41fSNipun Gupta 
120817d41fSNipun Gupta /** @addtogroup dpdmux
130817d41fSNipun Gupta  * @{
140817d41fSNipun Gupta  */
150817d41fSNipun Gupta 
160817d41fSNipun Gupta /**
170817d41fSNipun Gupta  * dpdmux_open() - Open a control session for the specified object
180817d41fSNipun Gupta  * @mc_io:	Pointer to MC portal's I/O object
190817d41fSNipun Gupta  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
200817d41fSNipun Gupta  * @dpdmux_id:		DPDMUX unique ID
210817d41fSNipun Gupta  * @token:		Returned token; use in subsequent API calls
220817d41fSNipun Gupta  *
230817d41fSNipun Gupta  * This function can be used to open a control session for an
240817d41fSNipun Gupta  * already created object; an object may have been declared in
250817d41fSNipun Gupta  * the DPL or by calling the dpdmux_create() function.
260817d41fSNipun Gupta  * This function returns a unique authentication token,
270817d41fSNipun Gupta  * associated with the specific object ID and the specific MC
280817d41fSNipun Gupta  * portal; this token must be used in all subsequent commands for
290817d41fSNipun Gupta  * this specific object.
300817d41fSNipun Gupta  *
310817d41fSNipun Gupta  * Return:	'0' on Success; Error code otherwise.
320817d41fSNipun Gupta  */
330817d41fSNipun Gupta int dpdmux_open(struct fsl_mc_io *mc_io,
340817d41fSNipun Gupta 		uint32_t cmd_flags,
350817d41fSNipun Gupta 		int dpdmux_id,
360817d41fSNipun Gupta 		uint16_t *token)
370817d41fSNipun Gupta {
380817d41fSNipun Gupta 	struct mc_command cmd = { 0 };
390817d41fSNipun Gupta 	struct dpdmux_cmd_open *cmd_params;
400817d41fSNipun Gupta 	int err;
410817d41fSNipun Gupta 
420817d41fSNipun Gupta 	/* prepare command */
430817d41fSNipun Gupta 	cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_OPEN,
440817d41fSNipun Gupta 					  cmd_flags,
450817d41fSNipun Gupta 					  0);
460817d41fSNipun Gupta 	cmd_params = (struct dpdmux_cmd_open *)cmd.params;
470817d41fSNipun Gupta 	cmd_params->dpdmux_id = cpu_to_le32(dpdmux_id);
480817d41fSNipun Gupta 
490817d41fSNipun Gupta 	/* send command to mc*/
500817d41fSNipun Gupta 	err = mc_send_command(mc_io, &cmd);
510817d41fSNipun Gupta 	if (err)
520817d41fSNipun Gupta 		return err;
530817d41fSNipun Gupta 
540817d41fSNipun Gupta 	/* retrieve response parameters */
550817d41fSNipun Gupta 	*token = mc_cmd_hdr_read_token(&cmd);
560817d41fSNipun Gupta 
570817d41fSNipun Gupta 	return 0;
580817d41fSNipun Gupta }
590817d41fSNipun Gupta 
600817d41fSNipun Gupta /**
610817d41fSNipun Gupta  * dpdmux_close() - Close the control session of the object
620817d41fSNipun Gupta  * @mc_io:	Pointer to MC portal's I/O object
630817d41fSNipun Gupta  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
640817d41fSNipun Gupta  * @token:		Token of DPDMUX object
650817d41fSNipun Gupta  *
660817d41fSNipun Gupta  * After this function is called, no further operations are
670817d41fSNipun Gupta  * allowed on the object without opening a new control session.
680817d41fSNipun Gupta  *
690817d41fSNipun Gupta  * Return:	'0' on Success; Error code otherwise.
700817d41fSNipun Gupta  */
710817d41fSNipun Gupta int dpdmux_close(struct fsl_mc_io *mc_io,
720817d41fSNipun Gupta 		 uint32_t cmd_flags,
730817d41fSNipun Gupta 		 uint16_t token)
740817d41fSNipun Gupta {
750817d41fSNipun Gupta 	struct mc_command cmd = { 0 };
760817d41fSNipun Gupta 
770817d41fSNipun Gupta 	/* prepare command */
780817d41fSNipun Gupta 	cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_CLOSE,
790817d41fSNipun Gupta 					  cmd_flags,
800817d41fSNipun Gupta 					  token);
810817d41fSNipun Gupta 
820817d41fSNipun Gupta 	/* send command to mc*/
830817d41fSNipun Gupta 	return mc_send_command(mc_io, &cmd);
840817d41fSNipun Gupta }
850817d41fSNipun Gupta 
860817d41fSNipun Gupta /**
870817d41fSNipun Gupta  * dpdmux_create() - Create the DPDMUX object
880817d41fSNipun Gupta  * @mc_io:	Pointer to MC portal's I/O object
890817d41fSNipun Gupta  * @dprc_token:	Parent container token; '0' for default container
900817d41fSNipun Gupta  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
910817d41fSNipun Gupta  * @cfg:	Configuration structure
920817d41fSNipun Gupta  * @obj_id: returned object id
930817d41fSNipun Gupta  *
940817d41fSNipun Gupta  * Create the DPDMUX object, allocate required resources and
950817d41fSNipun Gupta  * perform required initialization.
960817d41fSNipun Gupta  *
970817d41fSNipun Gupta  * The object can be created either by declaring it in the
980817d41fSNipun Gupta  * DPL file, or by calling this function.
990817d41fSNipun Gupta  *
1000817d41fSNipun Gupta  * The function accepts an authentication token of a parent
1010817d41fSNipun Gupta  * container that this object should be assigned to. The token
1020817d41fSNipun Gupta  * can be '0' so the object will be assigned to the default container.
1030817d41fSNipun Gupta  * The newly created object can be opened with the returned
1040817d41fSNipun Gupta  * object id and using the container's associated tokens and MC portals.
1050817d41fSNipun Gupta  *
1060817d41fSNipun Gupta  * Return:	'0' on Success; Error code otherwise.
1070817d41fSNipun Gupta  */
1080817d41fSNipun Gupta int dpdmux_create(struct fsl_mc_io *mc_io,
1090817d41fSNipun Gupta 		  uint16_t dprc_token,
1100817d41fSNipun Gupta 		  uint32_t cmd_flags,
1110817d41fSNipun Gupta 		  const struct dpdmux_cfg	*cfg,
1120817d41fSNipun Gupta 		  uint32_t *obj_id)
1130817d41fSNipun Gupta {
1140817d41fSNipun Gupta 	struct mc_command cmd = { 0 };
1150817d41fSNipun Gupta 	struct dpdmux_cmd_create *cmd_params;
1160817d41fSNipun Gupta 	int err;
1170817d41fSNipun Gupta 
1180817d41fSNipun Gupta 	/* prepare command */
1190817d41fSNipun Gupta 	cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_CREATE,
1200817d41fSNipun Gupta 					  cmd_flags,
1210817d41fSNipun Gupta 					  dprc_token);
1220817d41fSNipun Gupta 	cmd_params = (struct dpdmux_cmd_create *)cmd.params;
1230817d41fSNipun Gupta 	cmd_params->method = cfg->method;
1240817d41fSNipun Gupta 	cmd_params->manip = cfg->manip;
1250817d41fSNipun Gupta 	cmd_params->num_ifs = cpu_to_le16(cfg->num_ifs);
126914450baSApeksha Gupta 	cmd_params->default_if = cpu_to_le16(cfg->default_if);
1270817d41fSNipun Gupta 	cmd_params->adv_max_dmat_entries =
1280817d41fSNipun Gupta 			cpu_to_le16(cfg->adv.max_dmat_entries);
1290817d41fSNipun Gupta 	cmd_params->adv_max_mc_groups = cpu_to_le16(cfg->adv.max_mc_groups);
1300817d41fSNipun Gupta 	cmd_params->adv_max_vlan_ids = cpu_to_le16(cfg->adv.max_vlan_ids);
131914450baSApeksha Gupta 	cmd_params->mem_size = cpu_to_le16(cfg->adv.mem_size);
1320817d41fSNipun Gupta 	cmd_params->options = cpu_to_le64(cfg->adv.options);
1330817d41fSNipun Gupta 
1340817d41fSNipun Gupta 	/* send command to mc*/
1350817d41fSNipun Gupta 	err = mc_send_command(mc_io, &cmd);
1360817d41fSNipun Gupta 	if (err)
1370817d41fSNipun Gupta 		return err;
1380817d41fSNipun Gupta 
1390817d41fSNipun Gupta 	/* retrieve response parameters */
1400817d41fSNipun Gupta 	*obj_id = mc_cmd_read_object_id(&cmd);
1410817d41fSNipun Gupta 
1420817d41fSNipun Gupta 	return 0;
1430817d41fSNipun Gupta }
1440817d41fSNipun Gupta 
1450817d41fSNipun Gupta /**
1460817d41fSNipun Gupta  * dpdmux_destroy() - Destroy the DPDMUX object and release all its resources.
1470817d41fSNipun Gupta  * @mc_io:	Pointer to MC portal's I/O object
1480817d41fSNipun Gupta  * @dprc_token: Parent container token; '0' for default container
1490817d41fSNipun Gupta  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
1500817d41fSNipun Gupta  * @object_id:	The object id; it must be a valid id within the container that
1510817d41fSNipun Gupta  * created this object;
1520817d41fSNipun Gupta  *
1530817d41fSNipun Gupta  * The function accepts the authentication token of the parent container that
1540817d41fSNipun Gupta  * created the object (not the one that currently owns the object). The object
1550817d41fSNipun Gupta  * is searched within parent using the provided 'object_id'.
1560817d41fSNipun Gupta  * All tokens to the object must be closed before calling destroy.
1570817d41fSNipun Gupta  *
1580817d41fSNipun Gupta  * Return:	'0' on Success; error code otherwise.
1590817d41fSNipun Gupta  */
1600817d41fSNipun Gupta int dpdmux_destroy(struct fsl_mc_io *mc_io,
1610817d41fSNipun Gupta 		   uint16_t dprc_token,
1620817d41fSNipun Gupta 		   uint32_t cmd_flags,
1630817d41fSNipun Gupta 		   uint32_t object_id)
1640817d41fSNipun Gupta {
1650817d41fSNipun Gupta 	struct mc_command cmd = { 0 };
1660817d41fSNipun Gupta 	struct dpdmux_cmd_destroy *cmd_params;
1670817d41fSNipun Gupta 
1680817d41fSNipun Gupta 	/* prepare command */
1690817d41fSNipun Gupta 	cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_DESTROY,
1700817d41fSNipun Gupta 					  cmd_flags,
1710817d41fSNipun Gupta 					  dprc_token);
1720817d41fSNipun Gupta 	cmd_params = (struct dpdmux_cmd_destroy *)cmd.params;
1730817d41fSNipun Gupta 	cmd_params->dpdmux_id = cpu_to_le32(object_id);
1740817d41fSNipun Gupta 
1750817d41fSNipun Gupta 	/* send command to mc*/
1760817d41fSNipun Gupta 	return mc_send_command(mc_io, &cmd);
1770817d41fSNipun Gupta }
1780817d41fSNipun Gupta 
1790817d41fSNipun Gupta /**
1800817d41fSNipun Gupta  * dpdmux_enable() - Enable DPDMUX functionality
1810817d41fSNipun Gupta  * @mc_io:	Pointer to MC portal's I/O object
1820817d41fSNipun Gupta  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
1830817d41fSNipun Gupta  * @token:	Token of DPDMUX object
1840817d41fSNipun Gupta  *
1850817d41fSNipun Gupta  * Return:	'0' on Success; Error code otherwise.
1860817d41fSNipun Gupta  */
1870817d41fSNipun Gupta int dpdmux_enable(struct fsl_mc_io *mc_io,
1880817d41fSNipun Gupta 		  uint32_t cmd_flags,
1890817d41fSNipun Gupta 		  uint16_t token)
1900817d41fSNipun Gupta {
1910817d41fSNipun Gupta 	struct mc_command cmd = { 0 };
1920817d41fSNipun Gupta 
1930817d41fSNipun Gupta 	/* prepare command */
1940817d41fSNipun Gupta 	cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_ENABLE,
1950817d41fSNipun Gupta 					  cmd_flags,
1960817d41fSNipun Gupta 					  token);
1970817d41fSNipun Gupta 
1980817d41fSNipun Gupta 	/* send command to mc*/
1990817d41fSNipun Gupta 	return mc_send_command(mc_io, &cmd);
2000817d41fSNipun Gupta }
2010817d41fSNipun Gupta 
2020817d41fSNipun Gupta /**
2030817d41fSNipun Gupta  * dpdmux_disable() - Disable DPDMUX functionality
2040817d41fSNipun Gupta  * @mc_io:	Pointer to MC portal's I/O object
2050817d41fSNipun Gupta  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
2060817d41fSNipun Gupta  * @token:	Token of DPDMUX object
2070817d41fSNipun Gupta  *
2080817d41fSNipun Gupta  * Return:	'0' on Success; Error code otherwise.
2090817d41fSNipun Gupta  */
2100817d41fSNipun Gupta int dpdmux_disable(struct fsl_mc_io *mc_io,
2110817d41fSNipun Gupta 		   uint32_t cmd_flags,
2120817d41fSNipun Gupta 		   uint16_t token)
2130817d41fSNipun Gupta {
2140817d41fSNipun Gupta 	struct mc_command cmd = { 0 };
2150817d41fSNipun Gupta 
2160817d41fSNipun Gupta 	/* prepare command */
2170817d41fSNipun Gupta 	cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_DISABLE,
2180817d41fSNipun Gupta 					  cmd_flags,
2190817d41fSNipun Gupta 					  token);
2200817d41fSNipun Gupta 
2210817d41fSNipun Gupta 	/* send command to mc*/
2220817d41fSNipun Gupta 	return mc_send_command(mc_io, &cmd);
2230817d41fSNipun Gupta }
2240817d41fSNipun Gupta 
2250817d41fSNipun Gupta /**
2260817d41fSNipun Gupta  * dpdmux_is_enabled() - Check if the DPDMUX is enabled.
2270817d41fSNipun Gupta  * @mc_io:	Pointer to MC portal's I/O object
2280817d41fSNipun Gupta  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
2290817d41fSNipun Gupta  * @token:	Token of DPDMUX object
2300817d41fSNipun Gupta  * @en:		Returns '1' if object is enabled; '0' otherwise
2310817d41fSNipun Gupta  *
2320817d41fSNipun Gupta  * Return:	'0' on Success; Error code otherwise.
2330817d41fSNipun Gupta  */
2340817d41fSNipun Gupta int dpdmux_is_enabled(struct fsl_mc_io *mc_io,
2350817d41fSNipun Gupta 		      uint32_t cmd_flags,
2360817d41fSNipun Gupta 		      uint16_t token,
2370817d41fSNipun Gupta 		      int *en)
2380817d41fSNipun Gupta {
2390817d41fSNipun Gupta 	struct mc_command cmd = { 0 };
2400817d41fSNipun Gupta 	struct dpdmux_rsp_is_enabled *rsp_params;
2410817d41fSNipun Gupta 	int err;
2420817d41fSNipun Gupta 
2430817d41fSNipun Gupta 	/* prepare command */
2440817d41fSNipun Gupta 	cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_IS_ENABLED,
2450817d41fSNipun Gupta 					  cmd_flags,
2460817d41fSNipun Gupta 					  token);
2470817d41fSNipun Gupta 
2480817d41fSNipun Gupta 	/* send command to mc*/
2490817d41fSNipun Gupta 	err = mc_send_command(mc_io, &cmd);
2500817d41fSNipun Gupta 	if (err)
2510817d41fSNipun Gupta 		return err;
2520817d41fSNipun Gupta 
2530817d41fSNipun Gupta 	/* retrieve response parameters */
2540817d41fSNipun Gupta 	rsp_params = (struct dpdmux_rsp_is_enabled *)cmd.params;
2550817d41fSNipun Gupta 	*en = dpdmux_get_field(rsp_params->en, ENABLE);
2560817d41fSNipun Gupta 
2570817d41fSNipun Gupta 	return 0;
2580817d41fSNipun Gupta }
2590817d41fSNipun Gupta 
2600817d41fSNipun Gupta /**
2610817d41fSNipun Gupta  * dpdmux_reset() - Reset the DPDMUX, returns the object to initial state.
2620817d41fSNipun Gupta  * @mc_io:	Pointer to MC portal's I/O object
2630817d41fSNipun Gupta  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
2640817d41fSNipun Gupta  * @token:	Token of DPDMUX object
2650817d41fSNipun Gupta  *
2660817d41fSNipun Gupta  * Return:	'0' on Success; Error code otherwise.
2670817d41fSNipun Gupta  */
2680817d41fSNipun Gupta int dpdmux_reset(struct fsl_mc_io *mc_io,
2690817d41fSNipun Gupta 		 uint32_t cmd_flags,
2700817d41fSNipun Gupta 		 uint16_t token)
2710817d41fSNipun Gupta {
2720817d41fSNipun Gupta 	struct mc_command cmd = { 0 };
2730817d41fSNipun Gupta 
2740817d41fSNipun Gupta 	/* prepare command */
2750817d41fSNipun Gupta 	cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_RESET,
2760817d41fSNipun Gupta 					  cmd_flags,
2770817d41fSNipun Gupta 					  token);
2780817d41fSNipun Gupta 
2790817d41fSNipun Gupta 	/* send command to mc*/
2800817d41fSNipun Gupta 	return mc_send_command(mc_io, &cmd);
2810817d41fSNipun Gupta }
2820817d41fSNipun Gupta 
2830817d41fSNipun Gupta /**
284914450baSApeksha Gupta  * dpdmux_set_resetable() - Set overall resetable DPDMUX parameters.
285914450baSApeksha Gupta  * @mc_io:	Pointer to MC portal's I/O object
286914450baSApeksha Gupta  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
287914450baSApeksha Gupta  * @token:	Token of DPDMUX object
288914450baSApeksha Gupta  * @skip_reset_flags:	By default all are 0.
289914450baSApeksha Gupta  *			By setting 1 will deactivate the reset.
290914450baSApeksha Gupta  * The flags are:
291*591200efSGagandeep Singh  *			DPDMUX_SKIP_MODIFY_DEFAULT_INTERFACE  0x01
292914450baSApeksha Gupta  *			DPDMUX_SKIP_UNICAST_RULES             0x02
293914450baSApeksha Gupta  *			DPDMUX_SKIP_MULTICAST_RULES           0x04
294*591200efSGagandeep Singh  *			DPDMUX_SKIP_RESET_DEFAULT_INTERFACE   0x08
295914450baSApeksha Gupta  *
296914450baSApeksha Gupta  * For example, by default, through DPDMUX_RESET the default
297914450baSApeksha Gupta  * interface will be restored with the one from create.
298*591200efSGagandeep Singh  * By setting DPDMUX_SKIP_MODIFY_DEFAULT_INTERFACE flag,
299*591200efSGagandeep Singh  * through DPDMUX_RESET the default interface will not be modified after reset.
300*591200efSGagandeep Singh  * By setting DPDMUX_SKIP_RESET_DEFAULT_INTERFACE flag,
301*591200efSGagandeep Singh  * through DPDMUX_RESET the default interface will not be reset
302*591200efSGagandeep Singh  * and will continue to be functional during reset procedure.
303914450baSApeksha Gupta  *
304914450baSApeksha Gupta  * Return:	'0' on Success; Error code otherwise.
305914450baSApeksha Gupta  */
306914450baSApeksha Gupta int dpdmux_set_resetable(struct fsl_mc_io *mc_io,
307914450baSApeksha Gupta 				  uint32_t cmd_flags,
308914450baSApeksha Gupta 				  uint16_t token,
309914450baSApeksha Gupta 				  uint8_t skip_reset_flags)
310914450baSApeksha Gupta {
311914450baSApeksha Gupta 	struct mc_command cmd = { 0 };
312914450baSApeksha Gupta 	struct dpdmux_cmd_set_skip_reset_flags *cmd_params;
313914450baSApeksha Gupta 
314914450baSApeksha Gupta 	/* prepare command */
315914450baSApeksha Gupta 	cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_SET_RESETABLE,
316914450baSApeksha Gupta 					  cmd_flags,
317914450baSApeksha Gupta 					  token);
318914450baSApeksha Gupta 	cmd_params = (struct dpdmux_cmd_set_skip_reset_flags *)cmd.params;
319914450baSApeksha Gupta 	dpdmux_set_field(cmd_params->skip_reset_flags,
320914450baSApeksha Gupta 			SKIP_RESET_FLAGS,
321914450baSApeksha Gupta 			skip_reset_flags);
322914450baSApeksha Gupta 
323914450baSApeksha Gupta 	/* send command to mc*/
324914450baSApeksha Gupta 	return mc_send_command(mc_io, &cmd);
325914450baSApeksha Gupta }
326914450baSApeksha Gupta 
327914450baSApeksha Gupta /**
328914450baSApeksha Gupta  * dpdmux_get_resetable() - Get overall resetable parameters.
329914450baSApeksha Gupta  * @mc_io:	Pointer to MC portal's I/O object
330914450baSApeksha Gupta  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
331914450baSApeksha Gupta  * @token:	Token of DPDMUX object
332914450baSApeksha Gupta  * @skip_reset_flags:	Get the reset flags.
333914450baSApeksha Gupta  *
334914450baSApeksha Gupta  * The flags are:
335*591200efSGagandeep Singh  *			DPDMUX_SKIP_MODIFY_DEFAULT_INTERFACE  0x01
336914450baSApeksha Gupta  *			DPDMUX_SKIP_UNICAST_RULES             0x02
337914450baSApeksha Gupta  *			DPDMUX_SKIP_MULTICAST_RULES           0x04
338*591200efSGagandeep Singh  *			DPDMUX_SKIP_RESET_DEFAULT_INTERFACE   0x08
339914450baSApeksha Gupta  *
340914450baSApeksha Gupta  * Return:	'0' on Success; Error code otherwise.
341914450baSApeksha Gupta  */
342914450baSApeksha Gupta int dpdmux_get_resetable(struct fsl_mc_io *mc_io,
343914450baSApeksha Gupta 				  uint32_t cmd_flags,
344914450baSApeksha Gupta 				  uint16_t token,
345914450baSApeksha Gupta 				  uint8_t *skip_reset_flags)
346914450baSApeksha Gupta {
347914450baSApeksha Gupta 	struct mc_command cmd = { 0 };
348914450baSApeksha Gupta 	struct dpdmux_rsp_get_skip_reset_flags *rsp_params;
349914450baSApeksha Gupta 	int err;
350914450baSApeksha Gupta 
351914450baSApeksha Gupta 	/* prepare command */
352914450baSApeksha Gupta 	cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_GET_RESETABLE,
353914450baSApeksha Gupta 					  cmd_flags,
354914450baSApeksha Gupta 					  token);
355914450baSApeksha Gupta 
356914450baSApeksha Gupta 	/* send command to mc*/
357914450baSApeksha Gupta 	err = mc_send_command(mc_io, &cmd);
358914450baSApeksha Gupta 	if (err)
359914450baSApeksha Gupta 		return err;
360914450baSApeksha Gupta 
361914450baSApeksha Gupta 	/* retrieve response parameters */
362914450baSApeksha Gupta 	rsp_params = (struct dpdmux_rsp_get_skip_reset_flags *)cmd.params;
363914450baSApeksha Gupta 	*skip_reset_flags = dpdmux_get_field(rsp_params->skip_reset_flags,
364914450baSApeksha Gupta 			SKIP_RESET_FLAGS);
365914450baSApeksha Gupta 
366914450baSApeksha Gupta 	return 0;
367914450baSApeksha Gupta }
368914450baSApeksha Gupta 
369914450baSApeksha Gupta /**
3700817d41fSNipun Gupta  * dpdmux_get_attributes() - Retrieve DPDMUX attributes
3710817d41fSNipun Gupta  * @mc_io:	Pointer to MC portal's I/O object
3720817d41fSNipun Gupta  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
3730817d41fSNipun Gupta  * @token:	Token of DPDMUX object
3740817d41fSNipun Gupta  * @attr:	Returned object's attributes
3750817d41fSNipun Gupta  *
3760817d41fSNipun Gupta  * Return:	'0' on Success; Error code otherwise.
3770817d41fSNipun Gupta  */
3780817d41fSNipun Gupta int dpdmux_get_attributes(struct fsl_mc_io *mc_io,
3790817d41fSNipun Gupta 			  uint32_t cmd_flags,
3800817d41fSNipun Gupta 			  uint16_t token,
3810817d41fSNipun Gupta 			  struct dpdmux_attr *attr)
3820817d41fSNipun Gupta {
3830817d41fSNipun Gupta 	struct mc_command cmd = { 0 };
3840817d41fSNipun Gupta 	struct dpdmux_rsp_get_attr *rsp_params;
3850817d41fSNipun Gupta 	int err;
3860817d41fSNipun Gupta 
3870817d41fSNipun Gupta 	/* prepare command */
3880817d41fSNipun Gupta 	cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_GET_ATTR,
3890817d41fSNipun Gupta 					  cmd_flags,
3900817d41fSNipun Gupta 					  token);
3910817d41fSNipun Gupta 
3920817d41fSNipun Gupta 	/* send command to mc*/
3930817d41fSNipun Gupta 	err = mc_send_command(mc_io, &cmd);
3940817d41fSNipun Gupta 	if (err)
3950817d41fSNipun Gupta 		return err;
3960817d41fSNipun Gupta 
3970817d41fSNipun Gupta 	/* retrieve response parameters */
3980817d41fSNipun Gupta 	rsp_params = (struct dpdmux_rsp_get_attr *)cmd.params;
3990817d41fSNipun Gupta 	attr->id = le32_to_cpu(rsp_params->id);
4000817d41fSNipun Gupta 	attr->options = le64_to_cpu(rsp_params->options);
4010817d41fSNipun Gupta 	attr->method = rsp_params->method;
4020817d41fSNipun Gupta 	attr->manip = rsp_params->manip;
4030817d41fSNipun Gupta 	attr->num_ifs = le16_to_cpu(rsp_params->num_ifs);
4040817d41fSNipun Gupta 	attr->mem_size = le16_to_cpu(rsp_params->mem_size);
405914450baSApeksha Gupta 	attr->default_if = le16_to_cpu(rsp_params->default_if);
406f48cd6c6SNipun Gupta 	attr->max_dmat_entries = le16_to_cpu(rsp_params->max_dmat_entries);
407f48cd6c6SNipun Gupta 	attr->max_mc_groups = le16_to_cpu(rsp_params->max_mc_groups);
408f48cd6c6SNipun Gupta 	attr->max_vlan_ids = le16_to_cpu(rsp_params->max_vlan_ids);
4090817d41fSNipun Gupta 
4100817d41fSNipun Gupta 	return 0;
4110817d41fSNipun Gupta }
4120817d41fSNipun Gupta 
4130817d41fSNipun Gupta /**
4140817d41fSNipun Gupta  * dpdmux_if_enable() - Enable Interface
4150817d41fSNipun Gupta  * @mc_io:	Pointer to MC portal's I/O object
4160817d41fSNipun Gupta  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
4170817d41fSNipun Gupta  * @token:	Token of DPDMUX object
4180817d41fSNipun Gupta  * @if_id:	Interface Identifier
4190817d41fSNipun Gupta  *
4200817d41fSNipun Gupta  * Return:	Completion status. '0' on Success; Error code otherwise.
4210817d41fSNipun Gupta  */
4220817d41fSNipun Gupta int dpdmux_if_enable(struct fsl_mc_io *mc_io,
4230817d41fSNipun Gupta 		     uint32_t cmd_flags,
4240817d41fSNipun Gupta 		     uint16_t token,
4250817d41fSNipun Gupta 		     uint16_t if_id)
4260817d41fSNipun Gupta {
4270817d41fSNipun Gupta 	struct dpdmux_cmd_if *cmd_params;
4280817d41fSNipun Gupta 	struct mc_command cmd = { 0 };
4290817d41fSNipun Gupta 
4300817d41fSNipun Gupta 	/* prepare command */
4310817d41fSNipun Gupta 	cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_IF_ENABLE,
4320817d41fSNipun Gupta 					  cmd_flags,
4330817d41fSNipun Gupta 					  token);
4340817d41fSNipun Gupta 	cmd_params = (struct dpdmux_cmd_if *)cmd.params;
4350817d41fSNipun Gupta 	cmd_params->if_id = cpu_to_le16(if_id);
4360817d41fSNipun Gupta 
4370817d41fSNipun Gupta 	/* send command to mc*/
4380817d41fSNipun Gupta 	return mc_send_command(mc_io, &cmd);
4390817d41fSNipun Gupta }
4400817d41fSNipun Gupta 
4410817d41fSNipun Gupta /**
4420817d41fSNipun Gupta  * dpdmux_if_disable() - Disable Interface
4430817d41fSNipun Gupta  * @mc_io:	Pointer to MC portal's I/O object
4440817d41fSNipun Gupta  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
4450817d41fSNipun Gupta  * @token:	Token of DPDMUX object
4460817d41fSNipun Gupta  * @if_id:	Interface Identifier
4470817d41fSNipun Gupta  *
4480817d41fSNipun Gupta  * Return:	Completion status. '0' on Success; Error code otherwise.
4490817d41fSNipun Gupta  */
4500817d41fSNipun Gupta int dpdmux_if_disable(struct fsl_mc_io *mc_io,
4510817d41fSNipun Gupta 		      uint32_t cmd_flags,
4520817d41fSNipun Gupta 		      uint16_t token,
4530817d41fSNipun Gupta 		      uint16_t if_id)
4540817d41fSNipun Gupta {
4550817d41fSNipun Gupta 	struct dpdmux_cmd_if *cmd_params;
4560817d41fSNipun Gupta 	struct mc_command cmd = { 0 };
4570817d41fSNipun Gupta 
4580817d41fSNipun Gupta 	/* prepare command */
4590817d41fSNipun Gupta 	cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_IF_DISABLE,
4600817d41fSNipun Gupta 					  cmd_flags,
4610817d41fSNipun Gupta 					  token);
4620817d41fSNipun Gupta 	cmd_params = (struct dpdmux_cmd_if *)cmd.params;
4630817d41fSNipun Gupta 	cmd_params->if_id = cpu_to_le16(if_id);
4640817d41fSNipun Gupta 
4650817d41fSNipun Gupta 	/* send command to mc*/
4660817d41fSNipun Gupta 	return mc_send_command(mc_io, &cmd);
4670817d41fSNipun Gupta }
4680817d41fSNipun Gupta 
4690817d41fSNipun Gupta /**
4700817d41fSNipun Gupta  * dpdmux_set_max_frame_length() - Set the maximum frame length in DPDMUX
4710817d41fSNipun Gupta  * @mc_io:	Pointer to MC portal's I/O object
4720817d41fSNipun Gupta  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
4730817d41fSNipun Gupta  * @token:		Token of DPDMUX object
4740817d41fSNipun Gupta  * @max_frame_length:	The required maximum frame length
4750817d41fSNipun Gupta  *
4760817d41fSNipun Gupta  * Update the maximum frame length on all DMUX interfaces.
4770817d41fSNipun Gupta  * In case of VEPA, the maximum frame length on all dmux interfaces
4780817d41fSNipun Gupta  * will be updated with the minimum value of the mfls of the connected
4790817d41fSNipun Gupta  * dpnis and the actual value of dmux mfl.
4800817d41fSNipun Gupta  *
481f48cd6c6SNipun Gupta  * If dpdmux object is created using DPDMUX_OPT_AUTO_MAX_FRAME_LEN and maximum
482f48cd6c6SNipun Gupta  * frame length is changed for a dpni connected to dpdmux interface the change
483f48cd6c6SNipun Gupta  * is propagated through dpdmux interfaces and will overwrite the value set using
484f48cd6c6SNipun Gupta  * this API.
485f48cd6c6SNipun Gupta  *
4860817d41fSNipun Gupta  * Return:	'0' on Success; Error code otherwise.
4870817d41fSNipun Gupta  */
4880817d41fSNipun Gupta int dpdmux_set_max_frame_length(struct fsl_mc_io *mc_io,
4890817d41fSNipun Gupta 				uint32_t cmd_flags,
4900817d41fSNipun Gupta 				uint16_t token,
4910817d41fSNipun Gupta 				uint16_t max_frame_length)
4920817d41fSNipun Gupta {
4930817d41fSNipun Gupta 	struct mc_command cmd = { 0 };
4940817d41fSNipun Gupta 	struct dpdmux_cmd_set_max_frame_length *cmd_params;
4950817d41fSNipun Gupta 
4960817d41fSNipun Gupta 	/* prepare command */
4970817d41fSNipun Gupta 	cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_SET_MAX_FRAME_LENGTH,
4980817d41fSNipun Gupta 					  cmd_flags,
4990817d41fSNipun Gupta 					  token);
5000817d41fSNipun Gupta 	cmd_params = (struct dpdmux_cmd_set_max_frame_length *)cmd.params;
5010817d41fSNipun Gupta 	cmd_params->max_frame_length = cpu_to_le16(max_frame_length);
5020817d41fSNipun Gupta 
5030817d41fSNipun Gupta 	/* send command to mc*/
5040817d41fSNipun Gupta 	return mc_send_command(mc_io, &cmd);
5050817d41fSNipun Gupta }
5060817d41fSNipun Gupta 
5070817d41fSNipun Gupta /**
5082cb2abf3SHemant Agrawal  * dpdmux_get_max_frame_length() - Return the maximum frame length for DPDMUX
5092cb2abf3SHemant Agrawal  * interface
5102cb2abf3SHemant Agrawal  * @mc_io:	Pointer to MC portal's I/O object
5112cb2abf3SHemant Agrawal  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
5122cb2abf3SHemant Agrawal  * @token:		Token of DPDMUX object
5132cb2abf3SHemant Agrawal  * @if_id:		Interface id
5142cb2abf3SHemant Agrawal  * @max_frame_length:	maximum frame length
5152cb2abf3SHemant Agrawal  *
5162cb2abf3SHemant Agrawal  * When dpdmux object is in VEPA mode this function will ignore if_id parameter
5172cb2abf3SHemant Agrawal  * and will return maximum frame length for uplink interface (if_id==0).
5182cb2abf3SHemant Agrawal  *
5192cb2abf3SHemant Agrawal  * Return:	'0' on Success; Error code otherwise.
5202cb2abf3SHemant Agrawal  */
5212cb2abf3SHemant Agrawal int dpdmux_get_max_frame_length(struct fsl_mc_io *mc_io,
5222cb2abf3SHemant Agrawal 				uint32_t cmd_flags,
5232cb2abf3SHemant Agrawal 				uint16_t token,
5242cb2abf3SHemant Agrawal 				uint16_t if_id,
5252cb2abf3SHemant Agrawal 				uint16_t *max_frame_length)
5262cb2abf3SHemant Agrawal {
5272cb2abf3SHemant Agrawal 	struct mc_command cmd = { 0 };
5282cb2abf3SHemant Agrawal 	struct dpdmux_cmd_get_max_frame_len *cmd_params;
5292cb2abf3SHemant Agrawal 	struct dpdmux_rsp_get_max_frame_len *rsp_params;
5302cb2abf3SHemant Agrawal 	int err = 0;
5312cb2abf3SHemant Agrawal 
5322cb2abf3SHemant Agrawal 	/* prepare command */
5332cb2abf3SHemant Agrawal 	cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_GET_MAX_FRAME_LENGTH,
5342cb2abf3SHemant Agrawal 					  cmd_flags,
5352cb2abf3SHemant Agrawal 					  token);
5362cb2abf3SHemant Agrawal 	cmd_params = (struct dpdmux_cmd_get_max_frame_len *)cmd.params;
5372cb2abf3SHemant Agrawal 	cmd_params->if_id = cpu_to_le16(if_id);
5382cb2abf3SHemant Agrawal 
5392cb2abf3SHemant Agrawal 	err = mc_send_command(mc_io, &cmd);
5402cb2abf3SHemant Agrawal 	if (err)
5412cb2abf3SHemant Agrawal 		return err;
5422cb2abf3SHemant Agrawal 
5432cb2abf3SHemant Agrawal 	rsp_params = (struct dpdmux_rsp_get_max_frame_len *)cmd.params;
5442cb2abf3SHemant Agrawal 	*max_frame_length = le16_to_cpu(rsp_params->max_len);
5452cb2abf3SHemant Agrawal 
5462cb2abf3SHemant Agrawal 	/* send command to mc*/
5472cb2abf3SHemant Agrawal 	return err;
5482cb2abf3SHemant Agrawal }
5492cb2abf3SHemant Agrawal 
5502cb2abf3SHemant Agrawal /**
5510817d41fSNipun Gupta  * dpdmux_ul_reset_counters() - Function resets the uplink counter
5520817d41fSNipun Gupta  * @mc_io:	Pointer to MC portal's I/O object
5530817d41fSNipun Gupta  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
5540817d41fSNipun Gupta  * @token:	Token of DPDMUX object
5550817d41fSNipun Gupta  *
5560817d41fSNipun Gupta  * Return:	'0' on Success; Error code otherwise.
5570817d41fSNipun Gupta  */
5580817d41fSNipun Gupta int dpdmux_ul_reset_counters(struct fsl_mc_io *mc_io,
5590817d41fSNipun Gupta 			     uint32_t cmd_flags,
5600817d41fSNipun Gupta 			     uint16_t token)
5610817d41fSNipun Gupta {
5620817d41fSNipun Gupta 	struct mc_command cmd = { 0 };
5630817d41fSNipun Gupta 
5640817d41fSNipun Gupta 	/* prepare command */
5650817d41fSNipun Gupta 	cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_UL_RESET_COUNTERS,
5660817d41fSNipun Gupta 					  cmd_flags,
5670817d41fSNipun Gupta 					  token);
5680817d41fSNipun Gupta 
5690817d41fSNipun Gupta 	/* send command to mc*/
5700817d41fSNipun Gupta 	return mc_send_command(mc_io, &cmd);
5710817d41fSNipun Gupta }
5720817d41fSNipun Gupta 
5730817d41fSNipun Gupta /**
5740817d41fSNipun Gupta  * dpdmux_if_set_accepted_frames() - Set the accepted frame types
5750817d41fSNipun Gupta  * @mc_io:	Pointer to MC portal's I/O object
5760817d41fSNipun Gupta  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
5770817d41fSNipun Gupta  * @token:	Token of DPDMUX object
5780817d41fSNipun Gupta  * @if_id:	Interface ID (0 for uplink, or 1-num_ifs);
5790817d41fSNipun Gupta  * @cfg:	Frame types configuration
5800817d41fSNipun Gupta  *
5810817d41fSNipun Gupta  * if 'DPDMUX_ADMIT_ONLY_VLAN_TAGGED' is set - untagged frames or
5820817d41fSNipun Gupta  * priority-tagged frames are discarded.
5830817d41fSNipun Gupta  * if 'DPDMUX_ADMIT_ONLY_UNTAGGED' is set - untagged frames or
5840817d41fSNipun Gupta  * priority-tagged frames are accepted.
5850817d41fSNipun Gupta  * if 'DPDMUX_ADMIT_ALL' is set (default mode) - all VLAN tagged,
5860817d41fSNipun Gupta  * untagged and priority-tagged frame are accepted;
5870817d41fSNipun Gupta  *
5880817d41fSNipun Gupta  * Return:	'0' on Success; Error code otherwise.
5890817d41fSNipun Gupta  */
5900817d41fSNipun Gupta int dpdmux_if_set_accepted_frames(struct fsl_mc_io *mc_io,
5910817d41fSNipun Gupta 				  uint32_t cmd_flags,
5920817d41fSNipun Gupta 				  uint16_t token,
5930817d41fSNipun Gupta 				  uint16_t if_id,
5940817d41fSNipun Gupta 				  const struct dpdmux_accepted_frames *cfg)
5950817d41fSNipun Gupta {
5960817d41fSNipun Gupta 	struct mc_command cmd = { 0 };
5970817d41fSNipun Gupta 	struct dpdmux_cmd_if_set_accepted_frames *cmd_params;
5980817d41fSNipun Gupta 
5990817d41fSNipun Gupta 	/* prepare command */
6000817d41fSNipun Gupta 	cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_IF_SET_ACCEPTED_FRAMES,
6010817d41fSNipun Gupta 					  cmd_flags,
6020817d41fSNipun Gupta 					  token);
6030817d41fSNipun Gupta 	cmd_params = (struct dpdmux_cmd_if_set_accepted_frames *)cmd.params;
6040817d41fSNipun Gupta 	cmd_params->if_id = cpu_to_le16(if_id);
6050817d41fSNipun Gupta 	dpdmux_set_field(cmd_params->frames_options,
6060817d41fSNipun Gupta 			 ACCEPTED_FRAMES_TYPE,
6070817d41fSNipun Gupta 			 cfg->type);
6080817d41fSNipun Gupta 	dpdmux_set_field(cmd_params->frames_options,
6090817d41fSNipun Gupta 			 UNACCEPTED_FRAMES_ACTION,
6100817d41fSNipun Gupta 			 cfg->unaccept_act);
6110817d41fSNipun Gupta 
6120817d41fSNipun Gupta 	/* send command to mc*/
6130817d41fSNipun Gupta 	return mc_send_command(mc_io, &cmd);
6140817d41fSNipun Gupta }
6150817d41fSNipun Gupta 
6160817d41fSNipun Gupta /**
6170817d41fSNipun Gupta  * dpdmux_if_get_attributes() - Obtain DPDMUX interface attributes
6180817d41fSNipun Gupta  * @mc_io:	Pointer to MC portal's I/O object
6190817d41fSNipun Gupta  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
6200817d41fSNipun Gupta  * @token:	Token of DPDMUX object
6210817d41fSNipun Gupta  * @if_id:	Interface ID (0 for uplink, or 1-num_ifs);
6220817d41fSNipun Gupta  * @attr:	Interface attributes
6230817d41fSNipun Gupta  *
6240817d41fSNipun Gupta  * Return:	'0' on Success; Error code otherwise.
6250817d41fSNipun Gupta  */
6260817d41fSNipun Gupta int dpdmux_if_get_attributes(struct fsl_mc_io *mc_io,
6270817d41fSNipun Gupta 			     uint32_t cmd_flags,
6280817d41fSNipun Gupta 			     uint16_t token,
6290817d41fSNipun Gupta 			     uint16_t if_id,
6300817d41fSNipun Gupta 			     struct dpdmux_if_attr *attr)
6310817d41fSNipun Gupta {
6320817d41fSNipun Gupta 	struct mc_command cmd = { 0 };
6330817d41fSNipun Gupta 	struct dpdmux_cmd_if *cmd_params;
6340817d41fSNipun Gupta 	struct dpdmux_rsp_if_get_attr *rsp_params;
6350817d41fSNipun Gupta 	int err;
6360817d41fSNipun Gupta 
6370817d41fSNipun Gupta 	/* prepare command */
6380817d41fSNipun Gupta 	cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_IF_GET_ATTR,
6390817d41fSNipun Gupta 					  cmd_flags,
6400817d41fSNipun Gupta 					  token);
6410817d41fSNipun Gupta 	cmd_params = (struct dpdmux_cmd_if *)cmd.params;
6420817d41fSNipun Gupta 	cmd_params->if_id = cpu_to_le16(if_id);
6430817d41fSNipun Gupta 
6440817d41fSNipun Gupta 	/* send command to mc*/
6450817d41fSNipun Gupta 	err = mc_send_command(mc_io, &cmd);
6460817d41fSNipun Gupta 	if (err)
6470817d41fSNipun Gupta 		return err;
6480817d41fSNipun Gupta 
6490817d41fSNipun Gupta 	/* retrieve response parameters */
6500817d41fSNipun Gupta 	rsp_params = (struct dpdmux_rsp_if_get_attr *)cmd.params;
6510817d41fSNipun Gupta 	attr->rate = le32_to_cpu(rsp_params->rate);
6520817d41fSNipun Gupta 	attr->enabled = dpdmux_get_field(rsp_params->enabled, ENABLE);
6530817d41fSNipun Gupta 	attr->is_default = dpdmux_get_field(rsp_params->enabled, IS_DEFAULT);
6540817d41fSNipun Gupta 	attr->accept_frame_type = dpdmux_get_field(
6550817d41fSNipun Gupta 				  rsp_params->accepted_frames_type,
6560817d41fSNipun Gupta 				  ACCEPTED_FRAMES_TYPE);
6570817d41fSNipun Gupta 
6580817d41fSNipun Gupta 	return 0;
6590817d41fSNipun Gupta }
6600817d41fSNipun Gupta 
6610817d41fSNipun Gupta /**
6620817d41fSNipun Gupta  * dpdmux_if_remove_l2_rule() - Remove L2 rule from DPDMUX table
6630817d41fSNipun Gupta  * @mc_io:	Pointer to MC portal's I/O object
6640817d41fSNipun Gupta  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
6650817d41fSNipun Gupta  * @token:	Token of DPDMUX object
6660817d41fSNipun Gupta  * @if_id:	Destination interface ID
6670817d41fSNipun Gupta  * @rule:	L2 rule
6680817d41fSNipun Gupta  *
6690817d41fSNipun Gupta  * Function removes a L2 rule from DPDMUX table
6700817d41fSNipun Gupta  * or adds an interface to an existing multicast address
6710817d41fSNipun Gupta  *
6720817d41fSNipun Gupta  * Return:	'0' on Success; Error code otherwise.
6730817d41fSNipun Gupta  */
6740817d41fSNipun Gupta int dpdmux_if_remove_l2_rule(struct fsl_mc_io *mc_io,
6750817d41fSNipun Gupta 			     uint32_t cmd_flags,
6760817d41fSNipun Gupta 			     uint16_t token,
6770817d41fSNipun Gupta 			     uint16_t if_id,
6780817d41fSNipun Gupta 			     const struct dpdmux_l2_rule *rule)
6790817d41fSNipun Gupta {
6800817d41fSNipun Gupta 	struct mc_command cmd = { 0 };
6810817d41fSNipun Gupta 	struct dpdmux_cmd_if_l2_rule *cmd_params;
6820817d41fSNipun Gupta 
6830817d41fSNipun Gupta 	/* prepare command */
6840817d41fSNipun Gupta 	cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_IF_REMOVE_L2_RULE,
6850817d41fSNipun Gupta 					  cmd_flags,
6860817d41fSNipun Gupta 					  token);
6870817d41fSNipun Gupta 	cmd_params = (struct dpdmux_cmd_if_l2_rule *)cmd.params;
6880817d41fSNipun Gupta 	cmd_params->if_id = cpu_to_le16(if_id);
6890817d41fSNipun Gupta 	cmd_params->vlan_id = cpu_to_le16(rule->vlan_id);
6900817d41fSNipun Gupta 	cmd_params->mac_addr5 = rule->mac_addr[5];
6910817d41fSNipun Gupta 	cmd_params->mac_addr4 = rule->mac_addr[4];
6920817d41fSNipun Gupta 	cmd_params->mac_addr3 = rule->mac_addr[3];
6930817d41fSNipun Gupta 	cmd_params->mac_addr2 = rule->mac_addr[2];
6940817d41fSNipun Gupta 	cmd_params->mac_addr1 = rule->mac_addr[1];
6950817d41fSNipun Gupta 	cmd_params->mac_addr0 = rule->mac_addr[0];
6960817d41fSNipun Gupta 
6970817d41fSNipun Gupta 	/* send command to mc*/
6980817d41fSNipun Gupta 	return mc_send_command(mc_io, &cmd);
6990817d41fSNipun Gupta }
7000817d41fSNipun Gupta 
7010817d41fSNipun Gupta /**
7020817d41fSNipun Gupta  * dpdmux_if_add_l2_rule() - Add L2 rule into DPDMUX table
7030817d41fSNipun Gupta  * @mc_io:	Pointer to MC portal's I/O object
7040817d41fSNipun Gupta  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
7050817d41fSNipun Gupta  * @token:	Token of DPDMUX object
7060817d41fSNipun Gupta  * @if_id:	Destination interface ID
7070817d41fSNipun Gupta  * @rule:	L2 rule
7080817d41fSNipun Gupta  *
7090817d41fSNipun Gupta  * Function adds a L2 rule into DPDMUX table
7100817d41fSNipun Gupta  * or adds an interface to an existing multicast address
7110817d41fSNipun Gupta  *
7120817d41fSNipun Gupta  * Return:	'0' on Success; Error code otherwise.
7130817d41fSNipun Gupta  */
7140817d41fSNipun Gupta int dpdmux_if_add_l2_rule(struct fsl_mc_io *mc_io,
7150817d41fSNipun Gupta 			  uint32_t cmd_flags,
7160817d41fSNipun Gupta 			  uint16_t token,
7170817d41fSNipun Gupta 			  uint16_t if_id,
7180817d41fSNipun Gupta 			  const struct dpdmux_l2_rule *rule)
7190817d41fSNipun Gupta {
7200817d41fSNipun Gupta 	struct mc_command cmd = { 0 };
7210817d41fSNipun Gupta 	struct dpdmux_cmd_if_l2_rule *cmd_params;
7220817d41fSNipun Gupta 
7230817d41fSNipun Gupta 	/* prepare command */
7240817d41fSNipun Gupta 	cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_IF_ADD_L2_RULE,
7250817d41fSNipun Gupta 					  cmd_flags,
7260817d41fSNipun Gupta 					  token);
7270817d41fSNipun Gupta 	cmd_params = (struct dpdmux_cmd_if_l2_rule *)cmd.params;
7280817d41fSNipun Gupta 	cmd_params->if_id = cpu_to_le16(if_id);
7290817d41fSNipun Gupta 	cmd_params->vlan_id = cpu_to_le16(rule->vlan_id);
7300817d41fSNipun Gupta 	cmd_params->mac_addr5 = rule->mac_addr[5];
7310817d41fSNipun Gupta 	cmd_params->mac_addr4 = rule->mac_addr[4];
7320817d41fSNipun Gupta 	cmd_params->mac_addr3 = rule->mac_addr[3];
7330817d41fSNipun Gupta 	cmd_params->mac_addr2 = rule->mac_addr[2];
7340817d41fSNipun Gupta 	cmd_params->mac_addr1 = rule->mac_addr[1];
7350817d41fSNipun Gupta 	cmd_params->mac_addr0 = rule->mac_addr[0];
7360817d41fSNipun Gupta 
7370817d41fSNipun Gupta 	/* send command to mc*/
7380817d41fSNipun Gupta 	return mc_send_command(mc_io, &cmd);
7390817d41fSNipun Gupta }
7400817d41fSNipun Gupta 
7410817d41fSNipun Gupta /**
7420817d41fSNipun Gupta  * dpdmux_if_get_counter() - Functions obtains specific counter of an interface
7430817d41fSNipun Gupta  * @mc_io: Pointer to MC portal's I/O object
7440817d41fSNipun Gupta  * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
7450817d41fSNipun Gupta  * @token: Token of DPDMUX object
7460817d41fSNipun Gupta  * @if_id:  Interface Id
7470817d41fSNipun Gupta  * @counter_type: counter type
7480817d41fSNipun Gupta  * @counter: Returned specific counter information
7490817d41fSNipun Gupta  *
7500817d41fSNipun Gupta  * Return:	'0' on Success; Error code otherwise.
7510817d41fSNipun Gupta  */
7520817d41fSNipun Gupta int dpdmux_if_get_counter(struct fsl_mc_io *mc_io,
7530817d41fSNipun Gupta 			  uint32_t cmd_flags,
7540817d41fSNipun Gupta 			  uint16_t token,
7550817d41fSNipun Gupta 			  uint16_t if_id,
7560817d41fSNipun Gupta 			  enum dpdmux_counter_type counter_type,
7570817d41fSNipun Gupta 			  uint64_t *counter)
7580817d41fSNipun Gupta {
7590817d41fSNipun Gupta 	struct mc_command cmd = { 0 };
7600817d41fSNipun Gupta 	struct dpdmux_cmd_if_get_counter *cmd_params;
7610817d41fSNipun Gupta 	struct dpdmux_rsp_if_get_counter *rsp_params;
7620817d41fSNipun Gupta 	int err;
7630817d41fSNipun Gupta 
7640817d41fSNipun Gupta 	/* prepare command */
7650817d41fSNipun Gupta 	cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_IF_GET_COUNTER,
7660817d41fSNipun Gupta 					  cmd_flags,
7670817d41fSNipun Gupta 					  token);
7680817d41fSNipun Gupta 	cmd_params = (struct dpdmux_cmd_if_get_counter *)cmd.params;
7690817d41fSNipun Gupta 	cmd_params->if_id = cpu_to_le16(if_id);
7700817d41fSNipun Gupta 	cmd_params->counter_type = counter_type;
7710817d41fSNipun Gupta 
7720817d41fSNipun Gupta 	/* send command to mc*/
7730817d41fSNipun Gupta 	err = mc_send_command(mc_io, &cmd);
7740817d41fSNipun Gupta 	if (err)
7750817d41fSNipun Gupta 		return err;
7760817d41fSNipun Gupta 
7770817d41fSNipun Gupta 	/* retrieve response parameters */
7780817d41fSNipun Gupta 	rsp_params = (struct dpdmux_rsp_if_get_counter *)cmd.params;
7790817d41fSNipun Gupta 	*counter = le64_to_cpu(rsp_params->counter);
7800817d41fSNipun Gupta 
7810817d41fSNipun Gupta 	return 0;
7820817d41fSNipun Gupta }
7830817d41fSNipun Gupta 
7840817d41fSNipun Gupta /**
7850817d41fSNipun Gupta  * dpdmux_if_set_link_cfg() - set the link configuration.
7860817d41fSNipun Gupta  * @mc_io:	Pointer to MC portal's I/O object
7870817d41fSNipun Gupta  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
7880817d41fSNipun Gupta  * @token: Token of DPSW object
7890817d41fSNipun Gupta  * @if_id: interface id
7900817d41fSNipun Gupta  * @cfg: Link configuration
7910817d41fSNipun Gupta  *
7920817d41fSNipun Gupta  * Return:	'0' on Success; Error code otherwise.
7930817d41fSNipun Gupta  */
7940817d41fSNipun Gupta int dpdmux_if_set_link_cfg(struct fsl_mc_io *mc_io,
7950817d41fSNipun Gupta 			   uint32_t cmd_flags,
7960817d41fSNipun Gupta 			   uint16_t token,
7970817d41fSNipun Gupta 			   uint16_t if_id,
7980817d41fSNipun Gupta 			   struct dpdmux_link_cfg *cfg)
7990817d41fSNipun Gupta {
8000817d41fSNipun Gupta 	struct mc_command cmd = { 0 };
8010817d41fSNipun Gupta 	struct dpdmux_cmd_if_set_link_cfg *cmd_params;
8020817d41fSNipun Gupta 
8030817d41fSNipun Gupta 	/* prepare command */
8040817d41fSNipun Gupta 	cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_IF_SET_LINK_CFG,
8050817d41fSNipun Gupta 					  cmd_flags,
8060817d41fSNipun Gupta 					  token);
8070817d41fSNipun Gupta 	cmd_params = (struct dpdmux_cmd_if_set_link_cfg *)cmd.params;
8080817d41fSNipun Gupta 	cmd_params->if_id = cpu_to_le16(if_id);
8090817d41fSNipun Gupta 	cmd_params->rate = cpu_to_le32(cfg->rate);
8100817d41fSNipun Gupta 	cmd_params->options = cpu_to_le64(cfg->options);
8110817d41fSNipun Gupta 	cmd_params->advertising = cpu_to_le64(cfg->advertising);
8120817d41fSNipun Gupta 
8130817d41fSNipun Gupta 	/* send command to mc*/
8140817d41fSNipun Gupta 	return mc_send_command(mc_io, &cmd);
8150817d41fSNipun Gupta }
8160817d41fSNipun Gupta 
8170817d41fSNipun Gupta /**
8180817d41fSNipun Gupta  * dpdmux_if_get_link_state - Return the link state
8190817d41fSNipun Gupta  * @mc_io:	Pointer to MC portal's I/O object
8200817d41fSNipun Gupta  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
8210817d41fSNipun Gupta  * @token: Token of DPSW object
8220817d41fSNipun Gupta  * @if_id: interface id
8230817d41fSNipun Gupta  * @state: link state
8240817d41fSNipun Gupta  *
8250817d41fSNipun Gupta  * @returns	'0' on Success; Error code otherwise.
8260817d41fSNipun Gupta  */
8270817d41fSNipun Gupta int dpdmux_if_get_link_state(struct fsl_mc_io *mc_io,
8280817d41fSNipun Gupta 			     uint32_t cmd_flags,
8290817d41fSNipun Gupta 			     uint16_t token,
8300817d41fSNipun Gupta 			     uint16_t if_id,
8310817d41fSNipun Gupta 			     struct dpdmux_link_state *state)
8320817d41fSNipun Gupta {
8330817d41fSNipun Gupta 	struct mc_command cmd = { 0 };
8340817d41fSNipun Gupta 	struct dpdmux_cmd_if_get_link_state *cmd_params;
8350817d41fSNipun Gupta 	struct dpdmux_rsp_if_get_link_state *rsp_params;
8360817d41fSNipun Gupta 	int err;
8370817d41fSNipun Gupta 
8380817d41fSNipun Gupta 	/* prepare command */
8390817d41fSNipun Gupta 	cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_IF_GET_LINK_STATE,
8400817d41fSNipun Gupta 					  cmd_flags,
8410817d41fSNipun Gupta 					  token);
8420817d41fSNipun Gupta 	cmd_params = (struct dpdmux_cmd_if_get_link_state *)cmd.params;
8430817d41fSNipun Gupta 	cmd_params->if_id = cpu_to_le16(if_id);
8440817d41fSNipun Gupta 
8450817d41fSNipun Gupta 	/* send command to mc*/
8460817d41fSNipun Gupta 	err = mc_send_command(mc_io, &cmd);
8470817d41fSNipun Gupta 	if (err)
8480817d41fSNipun Gupta 		return err;
8490817d41fSNipun Gupta 
8500817d41fSNipun Gupta 	/* retrieve response parameters */
8510817d41fSNipun Gupta 	rsp_params = (struct dpdmux_rsp_if_get_link_state *)cmd.params;
8520817d41fSNipun Gupta 	state->rate = le32_to_cpu(rsp_params->rate);
8530817d41fSNipun Gupta 	state->options = le64_to_cpu(rsp_params->options);
8540817d41fSNipun Gupta 	state->up = dpdmux_get_field(rsp_params->up, UP);
8550817d41fSNipun Gupta 	state->state_valid = dpdmux_get_field(rsp_params->up, STATE_VALID);
8560817d41fSNipun Gupta 	state->supported = le64_to_cpu(rsp_params->supported);
8570817d41fSNipun Gupta 	state->advertising = le64_to_cpu(rsp_params->advertising);
8580817d41fSNipun Gupta 
8590817d41fSNipun Gupta 	return 0;
8600817d41fSNipun Gupta }
8610817d41fSNipun Gupta 
8620817d41fSNipun Gupta /**
8630817d41fSNipun Gupta  * dpdmux_if_set_default - Set default interface
8640817d41fSNipun Gupta  * @mc_io:	Pointer to MC portal's I/O object
8650817d41fSNipun Gupta  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
8660817d41fSNipun Gupta  * @token: Token of DPSW object
8670817d41fSNipun Gupta  * @if_id: interface id
8680817d41fSNipun Gupta  *
8690817d41fSNipun Gupta  * @returns	'0' on Success; Error code otherwise.
8700817d41fSNipun Gupta  */
8710817d41fSNipun Gupta int dpdmux_if_set_default(struct fsl_mc_io *mc_io,
8720817d41fSNipun Gupta 		uint32_t cmd_flags,
8730817d41fSNipun Gupta 		uint16_t token,
8740817d41fSNipun Gupta 		uint16_t if_id)
8750817d41fSNipun Gupta {
8760817d41fSNipun Gupta 	struct dpdmux_cmd_if *cmd_params;
8770817d41fSNipun Gupta 	struct mc_command cmd = { 0 };
8780817d41fSNipun Gupta 
8790817d41fSNipun Gupta 	/* prepare command */
8800817d41fSNipun Gupta 	cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_IF_SET_DEFAULT,
8810817d41fSNipun Gupta 					  cmd_flags,
8820817d41fSNipun Gupta 					  token);
8830817d41fSNipun Gupta 	cmd_params = (struct dpdmux_cmd_if *)cmd.params;
8840817d41fSNipun Gupta 	cmd_params->if_id = cpu_to_le16(if_id);
8850817d41fSNipun Gupta 
8860817d41fSNipun Gupta 	/* send command to mc*/
8870817d41fSNipun Gupta 	return mc_send_command(mc_io, &cmd);
8880817d41fSNipun Gupta }
8890817d41fSNipun Gupta 
8900817d41fSNipun Gupta /**
8910817d41fSNipun Gupta  * dpdmux_if_get_default - Get default interface
8920817d41fSNipun Gupta  * @mc_io:	Pointer to MC portal's I/O object
8930817d41fSNipun Gupta  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
8940817d41fSNipun Gupta  * @token: Token of DPSW object
8950817d41fSNipun Gupta  * @if_id: interface id
8960817d41fSNipun Gupta  *
8970817d41fSNipun Gupta  * @returns	'0' on Success; Error code otherwise.
8980817d41fSNipun Gupta  */
8990817d41fSNipun Gupta int dpdmux_if_get_default(struct fsl_mc_io *mc_io,
9000817d41fSNipun Gupta 		uint32_t cmd_flags,
9010817d41fSNipun Gupta 		uint16_t token,
9020817d41fSNipun Gupta 		uint16_t *if_id)
9030817d41fSNipun Gupta {
9040817d41fSNipun Gupta 	struct dpdmux_cmd_if *rsp_params;
9050817d41fSNipun Gupta 	struct mc_command cmd = { 0 };
9060817d41fSNipun Gupta 	int err;
9070817d41fSNipun Gupta 
9080817d41fSNipun Gupta 	/* prepare command */
9090817d41fSNipun Gupta 	cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_IF_GET_DEFAULT,
9100817d41fSNipun Gupta 					  cmd_flags,
9110817d41fSNipun Gupta 					  token);
9120817d41fSNipun Gupta 
9130817d41fSNipun Gupta 	/* send command to mc*/
9140817d41fSNipun Gupta 	err = mc_send_command(mc_io, &cmd);
9150817d41fSNipun Gupta 	if (err)
9160817d41fSNipun Gupta 		return err;
9170817d41fSNipun Gupta 
9180817d41fSNipun Gupta 	/* retrieve response parameters */
9190817d41fSNipun Gupta 	rsp_params = (struct dpdmux_cmd_if *)cmd.params;
9200817d41fSNipun Gupta 	*if_id = le16_to_cpu(rsp_params->if_id);
9210817d41fSNipun Gupta 
9220817d41fSNipun Gupta 	return 0;
9230817d41fSNipun Gupta }
9240817d41fSNipun Gupta 
9250817d41fSNipun Gupta /**
9260817d41fSNipun Gupta  * dpdmux_set_custom_key - Set a custom classification key.
9270817d41fSNipun Gupta  *
9280817d41fSNipun Gupta  * This API is only available for DPDMUX instance created with
9290817d41fSNipun Gupta  * DPDMUX_METHOD_CUSTOM.  This API must be called before populating the
9300817d41fSNipun Gupta  * classification table using dpdmux_add_custom_cls_entry.
9310817d41fSNipun Gupta  *
9320817d41fSNipun Gupta  * Calls to dpdmux_set_custom_key remove all existing classification entries
9330817d41fSNipun Gupta  * that may have been added previously using dpdmux_add_custom_cls_entry.
9340817d41fSNipun Gupta  *
9350817d41fSNipun Gupta  * @mc_io:		Pointer to MC portal's I/O object
9360817d41fSNipun Gupta  * @cmd_flags:		Command flags; one or more of 'MC_CMD_FLAG_'
9370817d41fSNipun Gupta  * @token:		Token of DPSW object
9380817d41fSNipun Gupta  * @if_id:		Interface id
9390817d41fSNipun Gupta  * @key_cfg_iova:	DMA address of a configuration structure set up using
9400817d41fSNipun Gupta  *			dpkg_prepare_key_cfg. Maximum key size is 24 bytes
9410817d41fSNipun Gupta  *
9420817d41fSNipun Gupta  * @returns	'0' on Success; Error code otherwise.
9430817d41fSNipun Gupta  */
9440817d41fSNipun Gupta int dpdmux_set_custom_key(struct fsl_mc_io *mc_io,
9450817d41fSNipun Gupta 			uint32_t cmd_flags,
9460817d41fSNipun Gupta 			uint16_t token,
9470817d41fSNipun Gupta 			uint64_t key_cfg_iova)
9480817d41fSNipun Gupta {
9490817d41fSNipun Gupta 	struct dpdmux_set_custom_key *cmd_params;
9500817d41fSNipun Gupta 	struct mc_command cmd = { 0 };
9510817d41fSNipun Gupta 
9520817d41fSNipun Gupta 	/* prepare command */
9530817d41fSNipun Gupta 	cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_SET_CUSTOM_KEY,
9540817d41fSNipun Gupta 					  cmd_flags,
9550817d41fSNipun Gupta 					  token);
9560817d41fSNipun Gupta 	cmd_params = (struct dpdmux_set_custom_key *)cmd.params;
9570817d41fSNipun Gupta 	cmd_params->key_cfg_iova = cpu_to_le64(key_cfg_iova);
9580817d41fSNipun Gupta 
9590817d41fSNipun Gupta 	/* send command to mc*/
9600817d41fSNipun Gupta 	return mc_send_command(mc_io, &cmd);
9610817d41fSNipun Gupta }
9620817d41fSNipun Gupta 
9630817d41fSNipun Gupta /**
9640817d41fSNipun Gupta  * dpdmux_add_custom_cls_entry - Adds a custom classification entry.
9650817d41fSNipun Gupta  *
9660817d41fSNipun Gupta  * This API is only available for DPDMUX instances created with
9670817d41fSNipun Gupta  * DPDMUX_METHOD_CUSTOM.  Before calling this function a classification key
9680817d41fSNipun Gupta  * composition rule must be set up using dpdmux_set_custom_key.
9690817d41fSNipun Gupta  *
9700817d41fSNipun Gupta  * @mc_io:	Pointer to MC portal's I/O object
9710817d41fSNipun Gupta  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
9720817d41fSNipun Gupta  * @token: Token of DPSW object
9730817d41fSNipun Gupta  * @rule: Classification rule to insert.  Rules cannot be duplicated, if a
9740817d41fSNipun Gupta  *	matching rule already exists, the action will be replaced.
9750817d41fSNipun Gupta  * @action: Action to perform for matching traffic.
9760817d41fSNipun Gupta  *
9770817d41fSNipun Gupta  * @returns	'0' on Success; Error code otherwise.
9780817d41fSNipun Gupta  */
9790817d41fSNipun Gupta int dpdmux_add_custom_cls_entry(struct fsl_mc_io *mc_io,
9800817d41fSNipun Gupta 		uint32_t cmd_flags,
9810817d41fSNipun Gupta 		uint16_t token,
9820817d41fSNipun Gupta 		struct dpdmux_rule_cfg *rule,
9830817d41fSNipun Gupta 		struct dpdmux_cls_action *action)
9840817d41fSNipun Gupta {
9850817d41fSNipun Gupta 	struct dpdmux_cmd_add_custom_cls_entry *cmd_params;
9860817d41fSNipun Gupta 	struct mc_command cmd = { 0 };
9870817d41fSNipun Gupta 
9880817d41fSNipun Gupta 	/* prepare command */
9890817d41fSNipun Gupta 	cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_ADD_CUSTOM_CLS_ENTRY,
9900817d41fSNipun Gupta 					  cmd_flags,
9910817d41fSNipun Gupta 					  token);
9920817d41fSNipun Gupta 
9930817d41fSNipun Gupta 	cmd_params = (struct dpdmux_cmd_add_custom_cls_entry *)cmd.params;
9940817d41fSNipun Gupta 	cmd_params->key_size = rule->key_size;
995e5e9ef72SAkhil Goyal 	cmd_params->entry_index = rule->entry_index;
9960817d41fSNipun Gupta 	cmd_params->dest_if = cpu_to_le16(action->dest_if);
9970817d41fSNipun Gupta 	cmd_params->key_iova = cpu_to_le64(rule->key_iova);
9980817d41fSNipun Gupta 	cmd_params->mask_iova = cpu_to_le64(rule->mask_iova);
9990817d41fSNipun Gupta 
10000817d41fSNipun Gupta 	/* send command to mc*/
10010817d41fSNipun Gupta 	return mc_send_command(mc_io, &cmd);
10020817d41fSNipun Gupta }
10030817d41fSNipun Gupta 
10040817d41fSNipun Gupta /**
10050817d41fSNipun Gupta  * dpdmux_remove_custom_cls_entry - Removes a custom classification entry.
10060817d41fSNipun Gupta  *
10070817d41fSNipun Gupta  * This API is only available for DPDMUX instances created with
10080817d41fSNipun Gupta  * DPDMUX_METHOD_CUSTOM.  The API can be used to remove classification
10090817d41fSNipun Gupta  * entries previously inserted using dpdmux_add_custom_cls_entry.
10100817d41fSNipun Gupta  *
10110817d41fSNipun Gupta  * @mc_io:	Pointer to MC portal's I/O object
10120817d41fSNipun Gupta  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
10130817d41fSNipun Gupta  * @token: Token of DPSW object
10140817d41fSNipun Gupta  * @rule: Classification rule to remove
10150817d41fSNipun Gupta  *
10160817d41fSNipun Gupta  * @returns	'0' on Success; Error code otherwise.
10170817d41fSNipun Gupta  */
10180817d41fSNipun Gupta int dpdmux_remove_custom_cls_entry(struct fsl_mc_io *mc_io,
10190817d41fSNipun Gupta 		uint32_t cmd_flags,
10200817d41fSNipun Gupta 		uint16_t token,
10210817d41fSNipun Gupta 		struct dpdmux_rule_cfg *rule)
10220817d41fSNipun Gupta {
10230817d41fSNipun Gupta 	struct dpdmux_cmd_remove_custom_cls_entry *cmd_params;
10240817d41fSNipun Gupta 	struct mc_command cmd = { 0 };
10250817d41fSNipun Gupta 
10260817d41fSNipun Gupta 	/* prepare command */
10270817d41fSNipun Gupta 	cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_REMOVE_CUSTOM_CLS_ENTRY,
10280817d41fSNipun Gupta 					  cmd_flags,
10290817d41fSNipun Gupta 					  token);
10300817d41fSNipun Gupta 	cmd_params = (struct dpdmux_cmd_remove_custom_cls_entry *)cmd.params;
10310817d41fSNipun Gupta 	cmd_params->key_size = rule->key_size;
10320817d41fSNipun Gupta 	cmd_params->key_iova = cpu_to_le64(rule->key_iova);
10330817d41fSNipun Gupta 	cmd_params->mask_iova = cpu_to_le64(rule->mask_iova);
10340817d41fSNipun Gupta 
10350817d41fSNipun Gupta 	/* send command to mc*/
10360817d41fSNipun Gupta 	return mc_send_command(mc_io, &cmd);
10370817d41fSNipun Gupta }
10380817d41fSNipun Gupta 
10390817d41fSNipun Gupta /**
10400817d41fSNipun Gupta  * dpdmux_get_api_version() - Get Data Path Demux API version
10410817d41fSNipun Gupta  * @mc_io:  Pointer to MC portal's I/O object
10420817d41fSNipun Gupta  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
10430817d41fSNipun Gupta  * @major_ver:	Major version of data path demux API
10440817d41fSNipun Gupta  * @minor_ver:	Minor version of data path demux API
10450817d41fSNipun Gupta  *
10460817d41fSNipun Gupta  * Return:  '0' on Success; Error code otherwise.
10470817d41fSNipun Gupta  */
10480817d41fSNipun Gupta int dpdmux_get_api_version(struct fsl_mc_io *mc_io,
10490817d41fSNipun Gupta 			   uint32_t cmd_flags,
10500817d41fSNipun Gupta 			   uint16_t *major_ver,
10510817d41fSNipun Gupta 			   uint16_t *minor_ver)
10520817d41fSNipun Gupta {
10530817d41fSNipun Gupta 	struct mc_command cmd = { 0 };
10540817d41fSNipun Gupta 	struct dpdmux_rsp_get_api_version *rsp_params;
10550817d41fSNipun Gupta 	int err;
10560817d41fSNipun Gupta 
10570817d41fSNipun Gupta 	cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_GET_API_VERSION,
10580817d41fSNipun Gupta 					cmd_flags,
10590817d41fSNipun Gupta 					0);
10600817d41fSNipun Gupta 
10610817d41fSNipun Gupta 	err = mc_send_command(mc_io, &cmd);
10620817d41fSNipun Gupta 	if (err)
10630817d41fSNipun Gupta 		return err;
10640817d41fSNipun Gupta 
10650817d41fSNipun Gupta 	rsp_params = (struct dpdmux_rsp_get_api_version *)cmd.params;
10660817d41fSNipun Gupta 	*major_ver = le16_to_cpu(rsp_params->major);
10670817d41fSNipun Gupta 	*minor_ver = le16_to_cpu(rsp_params->minor);
10680817d41fSNipun Gupta 
10690817d41fSNipun Gupta 	return 0;
10700817d41fSNipun Gupta }
10713d43972bSHemant Agrawal 
10723d43972bSHemant Agrawal /**
1073*591200efSGagandeep Singh  * dpdmux_if_set_taildrop() - enable taildrop for egress interface queues.
1074*591200efSGagandeep Singh  * @mc_io:	Pointer to MC portal's I/O object
1075*591200efSGagandeep Singh  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
1076*591200efSGagandeep Singh  * @token:	Token of DPDMUX object
1077*591200efSGagandeep Singh  * @if_id:	Interface Identifier
1078*591200efSGagandeep Singh  * @cfg: Taildrop configuration
1079*591200efSGagandeep Singh  */
1080*591200efSGagandeep Singh int dpdmux_if_set_taildrop(struct fsl_mc_io *mc_io, uint32_t cmd_flags, uint16_t token,
1081*591200efSGagandeep Singh 			      uint16_t if_id, struct dpdmux_taildrop_cfg *cfg)
1082*591200efSGagandeep Singh {
1083*591200efSGagandeep Singh 	struct mc_command cmd = { 0 };
1084*591200efSGagandeep Singh 	struct dpdmux_cmd_set_taildrop *cmd_params;
1085*591200efSGagandeep Singh 
1086*591200efSGagandeep Singh 	/* prepare command */
1087*591200efSGagandeep Singh 	cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_IF_SET_TAILDROP,
1088*591200efSGagandeep Singh 			cmd_flags,
1089*591200efSGagandeep Singh 			token);
1090*591200efSGagandeep Singh 	cmd_params = (struct dpdmux_cmd_set_taildrop *)cmd.params;
1091*591200efSGagandeep Singh 	cmd_params->if_id		= cpu_to_le16(if_id);
1092*591200efSGagandeep Singh 	cmd_params->units		= cfg->units;
1093*591200efSGagandeep Singh 	cmd_params->threshold	= cpu_to_le32(cfg->threshold);
1094*591200efSGagandeep Singh 	dpdmux_set_field(cmd_params->oal_en, ENABLE, (!!cfg->enable));
1095*591200efSGagandeep Singh 
1096*591200efSGagandeep Singh 	return mc_send_command(mc_io, &cmd);
1097*591200efSGagandeep Singh }
1098*591200efSGagandeep Singh 
1099*591200efSGagandeep Singh /**
1100*591200efSGagandeep Singh  * dpdmux_if_get_taildrop() - get current taildrop configuration.
1101*591200efSGagandeep Singh  * @mc_io:	Pointer to MC portal's I/O object
1102*591200efSGagandeep Singh  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
1103*591200efSGagandeep Singh  * @token:	Token of DPDMUX object
1104*591200efSGagandeep Singh  * @if_id:	Interface Identifier
1105*591200efSGagandeep Singh  * @cfg: Taildrop configuration
1106*591200efSGagandeep Singh  */
1107*591200efSGagandeep Singh int dpdmux_if_get_taildrop(struct fsl_mc_io *mc_io, uint32_t cmd_flags, uint16_t token,
1108*591200efSGagandeep Singh 			      uint16_t if_id, struct dpdmux_taildrop_cfg *cfg)
1109*591200efSGagandeep Singh {
1110*591200efSGagandeep Singh 	struct mc_command cmd = {0};
1111*591200efSGagandeep Singh 	struct dpdmux_cmd_get_taildrop *cmd_params;
1112*591200efSGagandeep Singh 	struct dpdmux_rsp_get_taildrop *rsp_params;
1113*591200efSGagandeep Singh 	int err = 0;
1114*591200efSGagandeep Singh 
1115*591200efSGagandeep Singh 	/* prepare command */
1116*591200efSGagandeep Singh 	cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_IF_GET_TAILDROP,
1117*591200efSGagandeep Singh 			cmd_flags,
1118*591200efSGagandeep Singh 			token);
1119*591200efSGagandeep Singh 	cmd_params = (struct dpdmux_cmd_get_taildrop *)cmd.params;
1120*591200efSGagandeep Singh 	cmd_params->if_id	= cpu_to_le16(if_id);
1121*591200efSGagandeep Singh 
1122*591200efSGagandeep Singh 	err = mc_send_command(mc_io, &cmd);
1123*591200efSGagandeep Singh 	if (err)
1124*591200efSGagandeep Singh 		return err;
1125*591200efSGagandeep Singh 
1126*591200efSGagandeep Singh 	/* retrieve response parameters */
1127*591200efSGagandeep Singh 	rsp_params = (struct dpdmux_rsp_get_taildrop *)cmd.params;
1128*591200efSGagandeep Singh 	cfg->threshold = le32_to_cpu(rsp_params->threshold);
1129*591200efSGagandeep Singh 	cfg->units = rsp_params->units;
1130*591200efSGagandeep Singh 	cfg->enable = dpdmux_get_field(rsp_params->oal_en, ENABLE);
1131*591200efSGagandeep Singh 
1132*591200efSGagandeep Singh 	return err;
1133*591200efSGagandeep Singh }
1134*591200efSGagandeep Singh 
1135*591200efSGagandeep Singh /**
1136*591200efSGagandeep Singh  * dpdmux_dump_table() - Dump the content of table_type table into memory.
1137*591200efSGagandeep Singh  * @mc_io: Pointer to MC portal's I/O object
1138*591200efSGagandeep Singh  * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
1139*591200efSGagandeep Singh  * @token: Token of DPSW object
1140*591200efSGagandeep Singh  * @table_type: The type of the table to dump
1141*591200efSGagandeep Singh  *	- DPDMUX_DMAT_TABLE
1142*591200efSGagandeep Singh  *	- DPDMUX_MISS_TABLE
1143*591200efSGagandeep Singh  *	- DPDMUX_PRUNE_TABLE
1144*591200efSGagandeep Singh  * @table_index: The index of the table to dump in case of more than one table
1145*591200efSGagandeep Singh  *	if table_type == DPDMUX_DMAT_TABLE
1146*591200efSGagandeep Singh  *		- DPDMUX_HMAP_UNICAST
1147*591200efSGagandeep Singh  *		- DPDMUX_HMAP_MULTICAST
1148*591200efSGagandeep Singh  *	else 0
1149*591200efSGagandeep Singh  * @iova_addr: The snapshot will be stored in this variable as an header of struct dump_table_header
1150*591200efSGagandeep Singh  *             followed by an array of struct dump_table_entry
1151*591200efSGagandeep Singh  * @iova_size: Memory size allocated for iova_addr
1152*591200efSGagandeep Singh  * @num_entries: Number of entries written in iova_addr
1153*591200efSGagandeep Singh  *
1154*591200efSGagandeep Singh  * Return: Completion status. '0' on Success; Error code otherwise.
1155*591200efSGagandeep Singh  *
1156*591200efSGagandeep Singh  * The memory allocated at iova_addr must be zeroed before command execution.
1157*591200efSGagandeep Singh  * If the table content exceeds the memory size provided the dump will be truncated.
1158*591200efSGagandeep Singh  */
1159*591200efSGagandeep Singh int dpdmux_dump_table(struct fsl_mc_io *mc_io,
1160*591200efSGagandeep Singh 			 uint32_t cmd_flags,
1161*591200efSGagandeep Singh 			 uint16_t token,
1162*591200efSGagandeep Singh 			 uint16_t table_type,
1163*591200efSGagandeep Singh 			 uint16_t table_index,
1164*591200efSGagandeep Singh 			 uint64_t iova_addr,
1165*591200efSGagandeep Singh 			 uint32_t iova_size,
1166*591200efSGagandeep Singh 			 uint16_t *num_entries)
1167*591200efSGagandeep Singh {
1168*591200efSGagandeep Singh 	struct mc_command cmd = { 0 };
1169*591200efSGagandeep Singh 	int err;
1170*591200efSGagandeep Singh 	struct dpdmux_cmd_dump_table *cmd_params;
1171*591200efSGagandeep Singh 	struct dpdmux_rsp_dump_table *rsp_params;
1172*591200efSGagandeep Singh 
1173*591200efSGagandeep Singh 	/* prepare command */
1174*591200efSGagandeep Singh 	cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_DUMP_TABLE, cmd_flags, token);
1175*591200efSGagandeep Singh 	cmd_params = (struct dpdmux_cmd_dump_table *)cmd.params;
1176*591200efSGagandeep Singh 	cmd_params->table_type = cpu_to_le16(table_type);
1177*591200efSGagandeep Singh 	cmd_params->table_index = cpu_to_le16(table_index);
1178*591200efSGagandeep Singh 	cmd_params->iova_addr = cpu_to_le64(iova_addr);
1179*591200efSGagandeep Singh 	cmd_params->iova_size = cpu_to_le32(iova_size);
1180*591200efSGagandeep Singh 
1181*591200efSGagandeep Singh 	/* send command to mc*/
1182*591200efSGagandeep Singh 	err = mc_send_command(mc_io, &cmd);
1183*591200efSGagandeep Singh 	if (err)
1184*591200efSGagandeep Singh 		return err;
1185*591200efSGagandeep Singh 
1186*591200efSGagandeep Singh 	rsp_params = (struct dpdmux_rsp_dump_table *)cmd.params;
1187*591200efSGagandeep Singh 	*num_entries = le16_to_cpu(rsp_params->num_entries);
1188*591200efSGagandeep Singh 
1189*591200efSGagandeep Singh 	return 0;
1190*591200efSGagandeep Singh }
1191*591200efSGagandeep Singh 
1192*591200efSGagandeep Singh 
1193*591200efSGagandeep Singh /**
11943d43972bSHemant Agrawal  * dpdmux_if_set_errors_behavior() - Set errors behavior
11953d43972bSHemant Agrawal  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
11963d43972bSHemant Agrawal  * @token:	Token of DPSW object
11973d43972bSHemant Agrawal  * @if_id:  Interface Identifier
11983d43972bSHemant Agrawal  * @cfg:	Errors configuration
11993d43972bSHemant Agrawal  *
12003d43972bSHemant Agrawal  * Provides a set of frame errors that will be rejected or accepted by the
12013d43972bSHemant Agrawal  * dpdmux interface. The frame with this errors will no longer be dropped by
12023d43972bSHemant Agrawal  * the dpdmux interface. When frame has parsing error the distribution to
12033d43972bSHemant Agrawal  * expected interface may fail. If the frame must be distributed using the
12043d43972bSHemant Agrawal  * information from a header that was not parsed due errors the frame may
12053d43972bSHemant Agrawal  * be discarded or end up on a default interface because needed data was not
12063d43972bSHemant Agrawal  * parsed properly.
12073d43972bSHemant Agrawal  * This function may be called numerous times with different error masks
12083d43972bSHemant Agrawal  *
12093d43972bSHemant Agrawal  * Return:	'0' on Success; Error code otherwise.
12103d43972bSHemant Agrawal  */
12113d43972bSHemant Agrawal int dpdmux_if_set_errors_behavior(struct fsl_mc_io *mc_io, uint32_t cmd_flags,
12123d43972bSHemant Agrawal 		uint16_t token, uint16_t if_id, struct dpdmux_error_cfg *cfg)
12133d43972bSHemant Agrawal {
12143d43972bSHemant Agrawal 	struct mc_command cmd = { 0 };
12153d43972bSHemant Agrawal 	struct dpdmux_cmd_set_errors_behavior *cmd_params;
12163d43972bSHemant Agrawal 
12173d43972bSHemant Agrawal 	/* prepare command */
12183d43972bSHemant Agrawal 	cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_SET_ERRORS_BEHAVIOR,
12193d43972bSHemant Agrawal 					cmd_flags,
12203d43972bSHemant Agrawal 					token);
12213d43972bSHemant Agrawal 	cmd_params = (struct dpdmux_cmd_set_errors_behavior *)cmd.params;
12223d43972bSHemant Agrawal 	cmd_params->errors = cpu_to_le32(cfg->errors);
12233d43972bSHemant Agrawal 	dpdmux_set_field(cmd_params->flags, ERROR_ACTION, cfg->error_action);
12243d43972bSHemant Agrawal 	cmd_params->if_id = cpu_to_le16(if_id);
12253d43972bSHemant Agrawal 
12263d43972bSHemant Agrawal 	/* send command to mc*/
12273d43972bSHemant Agrawal 	return mc_send_command(mc_io, &cmd);
12283d43972bSHemant Agrawal }
1229*591200efSGagandeep Singh 
1230*591200efSGagandeep Singh /* Sets up a Soft Parser Profile on this DPDMUX
1231*591200efSGagandeep Singh  * @mc_io:	Pointer to MC portal's I/O object
1232*591200efSGagandeep Singh  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
1233*591200efSGagandeep Singh  * @token:	Token of DPDMUX object
1234*591200efSGagandeep Singh  * @sp_profile: Soft Parser Profile name (must a valid name for a defined profile)
1235*591200efSGagandeep Singh  *			Maximum allowed length for this string is 8 characters long
1236*591200efSGagandeep Singh  *			If this parameter is empty string (all zeros)
1237*591200efSGagandeep Singh  *			then the Default SP Profile is set on this dpdmux
1238*591200efSGagandeep Singh  * @type: one of the SP Profile types defined above: Ingress or Egress (or both using bitwise OR)
1239*591200efSGagandeep Singh  */
1240*591200efSGagandeep Singh int dpdmux_set_sp_profile(struct fsl_mc_io *mc_io, uint32_t cmd_flags, uint16_t token,
1241*591200efSGagandeep Singh 		uint8_t sp_profile[], uint8_t type)
1242*591200efSGagandeep Singh {
1243*591200efSGagandeep Singh 	struct dpdmux_cmd_set_sp_profile *cmd_params;
1244*591200efSGagandeep Singh 	struct mc_command cmd = { 0 };
1245*591200efSGagandeep Singh 	int i;
1246*591200efSGagandeep Singh 
1247*591200efSGagandeep Singh 	/* prepare command */
1248*591200efSGagandeep Singh 	cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_SET_SP_PROFILE,
1249*591200efSGagandeep Singh 			cmd_flags, token);
1250*591200efSGagandeep Singh 
1251*591200efSGagandeep Singh 	cmd_params = (struct dpdmux_cmd_set_sp_profile *)cmd.params;
1252*591200efSGagandeep Singh 	for (i = 0; i < MAX_SP_PROFILE_ID_SIZE && sp_profile[i]; i++)
1253*591200efSGagandeep Singh 		cmd_params->sp_profile[i] = sp_profile[i];
1254*591200efSGagandeep Singh 	cmd_params->type = type;
1255*591200efSGagandeep Singh 
1256*591200efSGagandeep Singh 	/* send command to MC */
1257*591200efSGagandeep Singh 	return mc_send_command(mc_io, &cmd);
1258*591200efSGagandeep Singh }
1259*591200efSGagandeep Singh 
1260*591200efSGagandeep Singh /* Enable/Disable Soft Parser on this DPDMUX interface
1261*591200efSGagandeep Singh  * @mc_io:	Pointer to MC portal's I/O object
1262*591200efSGagandeep Singh  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
1263*591200efSGagandeep Singh  * @token:	Token of DPDMUX object
1264*591200efSGagandeep Singh  * @if_id: interface id
1265*591200efSGagandeep Singh  * @type: one of the SP Profile types defined above: Ingress or Egress (or both using bitwise OR)
1266*591200efSGagandeep Singh  * @en: 1 to enable or 0 to disable
1267*591200efSGagandeep Singh  */
1268*591200efSGagandeep Singh int dpdmux_sp_enable(struct fsl_mc_io *mc_io, uint32_t cmd_flags, uint16_t token,
1269*591200efSGagandeep Singh 		uint16_t if_id, uint8_t type, uint8_t en)
1270*591200efSGagandeep Singh {
1271*591200efSGagandeep Singh 	struct dpdmux_cmd_sp_enable *cmd_params;
1272*591200efSGagandeep Singh 	struct mc_command cmd = { 0 };
1273*591200efSGagandeep Singh 
1274*591200efSGagandeep Singh 	/* prepare command */
1275*591200efSGagandeep Singh 	cmd.header = mc_encode_cmd_header(DPDMUX_CMDID_SP_ENABLE,
1276*591200efSGagandeep Singh 			cmd_flags, token);
1277*591200efSGagandeep Singh 
1278*591200efSGagandeep Singh 	cmd_params = (struct dpdmux_cmd_sp_enable *)cmd.params;
1279*591200efSGagandeep Singh 	cmd_params->if_id = if_id;
1280*591200efSGagandeep Singh 	cmd_params->type = type;
1281*591200efSGagandeep Singh 	cmd_params->en = en;
1282*591200efSGagandeep Singh 
1283*591200efSGagandeep Singh 	/* send command to MC */
1284*591200efSGagandeep Singh 	return mc_send_command(mc_io, &cmd);
1285*591200efSGagandeep Singh }
1286