1f48298d3SIoana Ciornei // SPDX-License-Identifier: GPL-2.0
2f48298d3SIoana Ciornei /*
3f48298d3SIoana Ciornei  * Copyright 2014-2016 Freescale Semiconductor Inc.
4f48298d3SIoana Ciornei  * Copyright 2017-2021 NXP
5f48298d3SIoana Ciornei  *
6f48298d3SIoana Ciornei  */
7f48298d3SIoana Ciornei 
8f48298d3SIoana Ciornei #include <linux/fsl/mc.h>
9f48298d3SIoana Ciornei #include "dpsw.h"
10f48298d3SIoana Ciornei #include "dpsw-cmd.h"
11f48298d3SIoana Ciornei 
build_if_id_bitmap(__le64 * bmap,const u16 * id,const u16 num_ifs)125ac2d254SIoana Ciornei static void build_if_id_bitmap(__le64 *bmap, const u16 *id, const u16 num_ifs)
13f48298d3SIoana Ciornei {
14f48298d3SIoana Ciornei 	int i;
15f48298d3SIoana Ciornei 
16f48298d3SIoana Ciornei 	for (i = 0; (i < num_ifs) && (i < DPSW_MAX_IF); i++) {
17f48298d3SIoana Ciornei 		if (id[i] < DPSW_MAX_IF)
18f48298d3SIoana Ciornei 			bmap[id[i] / 64] |= cpu_to_le64(BIT_MASK(id[i] % 64));
19f48298d3SIoana Ciornei 	}
20f48298d3SIoana Ciornei }
21f48298d3SIoana Ciornei 
22f48298d3SIoana Ciornei /**
23f48298d3SIoana Ciornei  * dpsw_open() - Open a control session for the specified object
24f48298d3SIoana Ciornei  * @mc_io:	Pointer to MC portal's I/O object
25f48298d3SIoana Ciornei  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
26f48298d3SIoana Ciornei  * @dpsw_id:	DPSW unique ID
27f48298d3SIoana Ciornei  * @token:	Returned token; use in subsequent API calls
28f48298d3SIoana Ciornei  *
29f48298d3SIoana Ciornei  * This function can be used to open a control session for an
30f48298d3SIoana Ciornei  * already created object; an object may have been declared in
31f48298d3SIoana Ciornei  * the DPL or by calling the dpsw_create() function.
32f48298d3SIoana Ciornei  * This function returns a unique authentication token,
33f48298d3SIoana Ciornei  * associated with the specific object ID and the specific MC
34f48298d3SIoana Ciornei  * portal; this token must be used in all subsequent commands for
35f48298d3SIoana Ciornei  * this specific object
36f48298d3SIoana Ciornei  *
37f48298d3SIoana Ciornei  * Return:	'0' on Success; Error code otherwise.
38f48298d3SIoana Ciornei  */
dpsw_open(struct fsl_mc_io * mc_io,u32 cmd_flags,int dpsw_id,u16 * token)395ac2d254SIoana Ciornei int dpsw_open(struct fsl_mc_io *mc_io, u32 cmd_flags, int dpsw_id, u16 *token)
40f48298d3SIoana Ciornei {
41f48298d3SIoana Ciornei 	struct fsl_mc_command cmd = { 0 };
42f48298d3SIoana Ciornei 	struct dpsw_cmd_open *cmd_params;
43f48298d3SIoana Ciornei 	int err;
44f48298d3SIoana Ciornei 
45f48298d3SIoana Ciornei 	/* prepare command */
46f48298d3SIoana Ciornei 	cmd.header = mc_encode_cmd_header(DPSW_CMDID_OPEN,
47f48298d3SIoana Ciornei 					  cmd_flags,
48f48298d3SIoana Ciornei 					  0);
49f48298d3SIoana Ciornei 	cmd_params = (struct dpsw_cmd_open *)cmd.params;
50f48298d3SIoana Ciornei 	cmd_params->dpsw_id = cpu_to_le32(dpsw_id);
51f48298d3SIoana Ciornei 
52f48298d3SIoana Ciornei 	/* send command to mc*/
53f48298d3SIoana Ciornei 	err = mc_send_command(mc_io, &cmd);
54f48298d3SIoana Ciornei 	if (err)
55f48298d3SIoana Ciornei 		return err;
56f48298d3SIoana Ciornei 
57f48298d3SIoana Ciornei 	/* retrieve response parameters */
58f48298d3SIoana Ciornei 	*token = mc_cmd_hdr_read_token(&cmd);
59f48298d3SIoana Ciornei 
60f48298d3SIoana Ciornei 	return 0;
61f48298d3SIoana Ciornei }
62f48298d3SIoana Ciornei 
63f48298d3SIoana Ciornei /**
64f48298d3SIoana Ciornei  * dpsw_close() - Close the control session of the object
65f48298d3SIoana Ciornei  * @mc_io:	Pointer to MC portal's I/O object
66f48298d3SIoana Ciornei  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
67f48298d3SIoana Ciornei  * @token:	Token of DPSW object
68f48298d3SIoana Ciornei  *
69f48298d3SIoana Ciornei  * After this function is called, no further operations are
70f48298d3SIoana Ciornei  * allowed on the object without opening a new control session.
71f48298d3SIoana Ciornei  *
72f48298d3SIoana Ciornei  * Return:	'0' on Success; Error code otherwise.
73f48298d3SIoana Ciornei  */
dpsw_close(struct fsl_mc_io * mc_io,u32 cmd_flags,u16 token)745ac2d254SIoana Ciornei int dpsw_close(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token)
75f48298d3SIoana Ciornei {
76f48298d3SIoana Ciornei 	struct fsl_mc_command cmd = { 0 };
77f48298d3SIoana Ciornei 
78f48298d3SIoana Ciornei 	/* prepare command */
79f48298d3SIoana Ciornei 	cmd.header = mc_encode_cmd_header(DPSW_CMDID_CLOSE,
80f48298d3SIoana Ciornei 					  cmd_flags,
81f48298d3SIoana Ciornei 					  token);
82f48298d3SIoana Ciornei 
83f48298d3SIoana Ciornei 	/* send command to mc*/
84f48298d3SIoana Ciornei 	return mc_send_command(mc_io, &cmd);
85f48298d3SIoana Ciornei }
86f48298d3SIoana Ciornei 
87f48298d3SIoana Ciornei /**
88f48298d3SIoana Ciornei  * dpsw_enable() - Enable DPSW functionality
89f48298d3SIoana Ciornei  * @mc_io:	Pointer to MC portal's I/O object
90f48298d3SIoana Ciornei  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
91f48298d3SIoana Ciornei  * @token:	Token of DPSW object
92f48298d3SIoana Ciornei  *
93f48298d3SIoana Ciornei  * Return:	Completion status. '0' on Success; Error code otherwise.
94f48298d3SIoana Ciornei  */
dpsw_enable(struct fsl_mc_io * mc_io,u32 cmd_flags,u16 token)955ac2d254SIoana Ciornei int dpsw_enable(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token)
96f48298d3SIoana Ciornei {
97f48298d3SIoana Ciornei 	struct fsl_mc_command cmd = { 0 };
98f48298d3SIoana Ciornei 
99f48298d3SIoana Ciornei 	/* prepare command */
100f48298d3SIoana Ciornei 	cmd.header = mc_encode_cmd_header(DPSW_CMDID_ENABLE,
101f48298d3SIoana Ciornei 					  cmd_flags,
102f48298d3SIoana Ciornei 					  token);
103f48298d3SIoana Ciornei 
104f48298d3SIoana Ciornei 	/* send command to mc*/
105f48298d3SIoana Ciornei 	return mc_send_command(mc_io, &cmd);
106f48298d3SIoana Ciornei }
107f48298d3SIoana Ciornei 
108f48298d3SIoana Ciornei /**
109f48298d3SIoana Ciornei  * dpsw_disable() - Disable DPSW functionality
110f48298d3SIoana Ciornei  * @mc_io:	Pointer to MC portal's I/O object
111f48298d3SIoana Ciornei  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
112f48298d3SIoana Ciornei  * @token:	Token of DPSW object
113f48298d3SIoana Ciornei  *
114f48298d3SIoana Ciornei  * Return:	Completion status. '0' on Success; Error code otherwise.
115f48298d3SIoana Ciornei  */
dpsw_disable(struct fsl_mc_io * mc_io,u32 cmd_flags,u16 token)1165ac2d254SIoana Ciornei int dpsw_disable(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token)
117f48298d3SIoana Ciornei {
118f48298d3SIoana Ciornei 	struct fsl_mc_command cmd = { 0 };
119f48298d3SIoana Ciornei 
120f48298d3SIoana Ciornei 	/* prepare command */
121f48298d3SIoana Ciornei 	cmd.header = mc_encode_cmd_header(DPSW_CMDID_DISABLE,
122f48298d3SIoana Ciornei 					  cmd_flags,
123f48298d3SIoana Ciornei 					  token);
124f48298d3SIoana Ciornei 
125f48298d3SIoana Ciornei 	/* send command to mc*/
126f48298d3SIoana Ciornei 	return mc_send_command(mc_io, &cmd);
127f48298d3SIoana Ciornei }
128f48298d3SIoana Ciornei 
129f48298d3SIoana Ciornei /**
130f48298d3SIoana Ciornei  * dpsw_reset() - Reset the DPSW, returns the object to initial state.
131f48298d3SIoana Ciornei  * @mc_io:	Pointer to MC portal's I/O object
132f48298d3SIoana Ciornei  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
133f48298d3SIoana Ciornei  * @token:	Token of DPSW object
134f48298d3SIoana Ciornei  *
135f48298d3SIoana Ciornei  * Return:	'0' on Success; Error code otherwise.
136f48298d3SIoana Ciornei  */
dpsw_reset(struct fsl_mc_io * mc_io,u32 cmd_flags,u16 token)1375ac2d254SIoana Ciornei int dpsw_reset(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token)
138f48298d3SIoana Ciornei {
139f48298d3SIoana Ciornei 	struct fsl_mc_command cmd = { 0 };
140f48298d3SIoana Ciornei 
141f48298d3SIoana Ciornei 	/* prepare command */
142f48298d3SIoana Ciornei 	cmd.header = mc_encode_cmd_header(DPSW_CMDID_RESET,
143f48298d3SIoana Ciornei 					  cmd_flags,
144f48298d3SIoana Ciornei 					  token);
145f48298d3SIoana Ciornei 
146f48298d3SIoana Ciornei 	/* send command to mc*/
147f48298d3SIoana Ciornei 	return mc_send_command(mc_io, &cmd);
148f48298d3SIoana Ciornei }
149f48298d3SIoana Ciornei 
150f48298d3SIoana Ciornei /**
151f48298d3SIoana Ciornei  * dpsw_set_irq_enable() - Set overall interrupt state.
152f48298d3SIoana Ciornei  * @mc_io:	Pointer to MC portal's I/O object
153f48298d3SIoana Ciornei  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
154f48298d3SIoana Ciornei  * @token:	Token of DPCI object
155f48298d3SIoana Ciornei  * @irq_index:	The interrupt index to configure
156f48298d3SIoana Ciornei  * @en:		Interrupt state - enable = 1, disable = 0
157f48298d3SIoana Ciornei  *
158f48298d3SIoana Ciornei  * Allows GPP software to control when interrupts are generated.
159f48298d3SIoana Ciornei  * Each interrupt can have up to 32 causes.  The enable/disable control's the
160f48298d3SIoana Ciornei  * overall interrupt state. if the interrupt is disabled no causes will cause
161f48298d3SIoana Ciornei  * an interrupt
162f48298d3SIoana Ciornei  *
163f48298d3SIoana Ciornei  * Return:	'0' on Success; Error code otherwise.
164f48298d3SIoana Ciornei  */
dpsw_set_irq_enable(struct fsl_mc_io * mc_io,u32 cmd_flags,u16 token,u8 irq_index,u8 en)1655ac2d254SIoana Ciornei int dpsw_set_irq_enable(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
1665ac2d254SIoana Ciornei 			u8 irq_index, u8 en)
167f48298d3SIoana Ciornei {
168f48298d3SIoana Ciornei 	struct fsl_mc_command cmd = { 0 };
169f48298d3SIoana Ciornei 	struct dpsw_cmd_set_irq_enable *cmd_params;
170f48298d3SIoana Ciornei 
171f48298d3SIoana Ciornei 	/* prepare command */
172f48298d3SIoana Ciornei 	cmd.header = mc_encode_cmd_header(DPSW_CMDID_SET_IRQ_ENABLE,
173f48298d3SIoana Ciornei 					  cmd_flags,
174f48298d3SIoana Ciornei 					  token);
175f48298d3SIoana Ciornei 	cmd_params = (struct dpsw_cmd_set_irq_enable *)cmd.params;
176f48298d3SIoana Ciornei 	dpsw_set_field(cmd_params->enable_state, ENABLE, en);
177f48298d3SIoana Ciornei 	cmd_params->irq_index = irq_index;
178f48298d3SIoana Ciornei 
179f48298d3SIoana Ciornei 	/* send command to mc*/
180f48298d3SIoana Ciornei 	return mc_send_command(mc_io, &cmd);
181f48298d3SIoana Ciornei }
182f48298d3SIoana Ciornei 
183f48298d3SIoana Ciornei /**
184f48298d3SIoana Ciornei  * dpsw_set_irq_mask() - Set interrupt mask.
185f48298d3SIoana Ciornei  * @mc_io:	Pointer to MC portal's I/O object
186f48298d3SIoana Ciornei  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
187f48298d3SIoana Ciornei  * @token:	Token of DPCI object
188f48298d3SIoana Ciornei  * @irq_index:	The interrupt index to configure
189f48298d3SIoana Ciornei  * @mask:	Event mask to trigger interrupt;
190f48298d3SIoana Ciornei  *		each bit:
191f48298d3SIoana Ciornei  *			0 = ignore event
192f48298d3SIoana Ciornei  *			1 = consider event for asserting IRQ
193f48298d3SIoana Ciornei  *
194f48298d3SIoana Ciornei  * Every interrupt can have up to 32 causes and the interrupt model supports
195f48298d3SIoana Ciornei  * masking/unmasking each cause independently
196f48298d3SIoana Ciornei  *
197f48298d3SIoana Ciornei  * Return:	'0' on Success; Error code otherwise.
198f48298d3SIoana Ciornei  */
dpsw_set_irq_mask(struct fsl_mc_io * mc_io,u32 cmd_flags,u16 token,u8 irq_index,u32 mask)1995ac2d254SIoana Ciornei int dpsw_set_irq_mask(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
2005ac2d254SIoana Ciornei 		      u8 irq_index, u32 mask)
201f48298d3SIoana Ciornei {
202f48298d3SIoana Ciornei 	struct fsl_mc_command cmd = { 0 };
203f48298d3SIoana Ciornei 	struct dpsw_cmd_set_irq_mask *cmd_params;
204f48298d3SIoana Ciornei 
205f48298d3SIoana Ciornei 	/* prepare command */
206f48298d3SIoana Ciornei 	cmd.header = mc_encode_cmd_header(DPSW_CMDID_SET_IRQ_MASK,
207f48298d3SIoana Ciornei 					  cmd_flags,
208f48298d3SIoana Ciornei 					  token);
209f48298d3SIoana Ciornei 	cmd_params = (struct dpsw_cmd_set_irq_mask *)cmd.params;
210f48298d3SIoana Ciornei 	cmd_params->mask = cpu_to_le32(mask);
211f48298d3SIoana Ciornei 	cmd_params->irq_index = irq_index;
212f48298d3SIoana Ciornei 
213f48298d3SIoana Ciornei 	/* send command to mc*/
214f48298d3SIoana Ciornei 	return mc_send_command(mc_io, &cmd);
215f48298d3SIoana Ciornei }
216f48298d3SIoana Ciornei 
217f48298d3SIoana Ciornei /**
218f48298d3SIoana Ciornei  * dpsw_get_irq_status() - Get the current status of any pending interrupts
219f48298d3SIoana Ciornei  * @mc_io:	Pointer to MC portal's I/O object
220f48298d3SIoana Ciornei  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
221f48298d3SIoana Ciornei  * @token:	Token of DPSW object
222f48298d3SIoana Ciornei  * @irq_index:	The interrupt index to configure
223f48298d3SIoana Ciornei  * @status:	Returned interrupts status - one bit per cause:
224f48298d3SIoana Ciornei  *			0 = no interrupt pending
225f48298d3SIoana Ciornei  *			1 = interrupt pending
226f48298d3SIoana Ciornei  *
227f48298d3SIoana Ciornei  * Return:	'0' on Success; Error code otherwise.
228f48298d3SIoana Ciornei  */
dpsw_get_irq_status(struct fsl_mc_io * mc_io,u32 cmd_flags,u16 token,u8 irq_index,u32 * status)2295ac2d254SIoana Ciornei int dpsw_get_irq_status(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
2305ac2d254SIoana Ciornei 			u8 irq_index, u32 *status)
231f48298d3SIoana Ciornei {
232f48298d3SIoana Ciornei 	struct fsl_mc_command cmd = { 0 };
233f48298d3SIoana Ciornei 	struct dpsw_cmd_get_irq_status *cmd_params;
234f48298d3SIoana Ciornei 	struct dpsw_rsp_get_irq_status *rsp_params;
235f48298d3SIoana Ciornei 	int err;
236f48298d3SIoana Ciornei 
237f48298d3SIoana Ciornei 	/* prepare command */
238f48298d3SIoana Ciornei 	cmd.header = mc_encode_cmd_header(DPSW_CMDID_GET_IRQ_STATUS,
239f48298d3SIoana Ciornei 					  cmd_flags,
240f48298d3SIoana Ciornei 					  token);
241f48298d3SIoana Ciornei 	cmd_params = (struct dpsw_cmd_get_irq_status *)cmd.params;
242f48298d3SIoana Ciornei 	cmd_params->status = cpu_to_le32(*status);
243f48298d3SIoana Ciornei 	cmd_params->irq_index = irq_index;
244f48298d3SIoana Ciornei 
245f48298d3SIoana Ciornei 	/* send command to mc*/
246f48298d3SIoana Ciornei 	err = mc_send_command(mc_io, &cmd);
247f48298d3SIoana Ciornei 	if (err)
248f48298d3SIoana Ciornei 		return err;
249f48298d3SIoana Ciornei 
250f48298d3SIoana Ciornei 	/* retrieve response parameters */
251f48298d3SIoana Ciornei 	rsp_params = (struct dpsw_rsp_get_irq_status *)cmd.params;
252f48298d3SIoana Ciornei 	*status = le32_to_cpu(rsp_params->status);
253f48298d3SIoana Ciornei 
254f48298d3SIoana Ciornei 	return 0;
255f48298d3SIoana Ciornei }
256f48298d3SIoana Ciornei 
257f48298d3SIoana Ciornei /**
258f48298d3SIoana Ciornei  * dpsw_clear_irq_status() - Clear a pending interrupt's status
259f48298d3SIoana Ciornei  * @mc_io:	Pointer to MC portal's I/O object
260f48298d3SIoana Ciornei  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
261f48298d3SIoana Ciornei  * @token:	Token of DPCI object
262f48298d3SIoana Ciornei  * @irq_index:	The interrupt index to configure
263f48298d3SIoana Ciornei  * @status:	bits to clear (W1C) - one bit per cause:
264f48298d3SIoana Ciornei  *			0 = don't change
265f48298d3SIoana Ciornei  *			1 = clear status bit
266f48298d3SIoana Ciornei  *
267f48298d3SIoana Ciornei  * Return:	'0' on Success; Error code otherwise.
268f48298d3SIoana Ciornei  */
dpsw_clear_irq_status(struct fsl_mc_io * mc_io,u32 cmd_flags,u16 token,u8 irq_index,u32 status)2695ac2d254SIoana Ciornei int dpsw_clear_irq_status(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
2705ac2d254SIoana Ciornei 			  u8 irq_index, u32 status)
271f48298d3SIoana Ciornei {
272f48298d3SIoana Ciornei 	struct fsl_mc_command cmd = { 0 };
273f48298d3SIoana Ciornei 	struct dpsw_cmd_clear_irq_status *cmd_params;
274f48298d3SIoana Ciornei 
275f48298d3SIoana Ciornei 	/* prepare command */
276f48298d3SIoana Ciornei 	cmd.header = mc_encode_cmd_header(DPSW_CMDID_CLEAR_IRQ_STATUS,
277f48298d3SIoana Ciornei 					  cmd_flags,
278f48298d3SIoana Ciornei 					  token);
279f48298d3SIoana Ciornei 	cmd_params = (struct dpsw_cmd_clear_irq_status *)cmd.params;
280f48298d3SIoana Ciornei 	cmd_params->status = cpu_to_le32(status);
281f48298d3SIoana Ciornei 	cmd_params->irq_index = irq_index;
282f48298d3SIoana Ciornei 
283f48298d3SIoana Ciornei 	/* send command to mc*/
284f48298d3SIoana Ciornei 	return mc_send_command(mc_io, &cmd);
285f48298d3SIoana Ciornei }
286f48298d3SIoana Ciornei 
287f48298d3SIoana Ciornei /**
288f48298d3SIoana Ciornei  * dpsw_get_attributes() - Retrieve DPSW attributes
289f48298d3SIoana Ciornei  * @mc_io:	Pointer to MC portal's I/O object
290f48298d3SIoana Ciornei  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
291f48298d3SIoana Ciornei  * @token:	Token of DPSW object
292f48298d3SIoana Ciornei  * @attr:	Returned DPSW attributes
293f48298d3SIoana Ciornei  *
294f48298d3SIoana Ciornei  * Return:	Completion status. '0' on Success; Error code otherwise.
295f48298d3SIoana Ciornei  */
dpsw_get_attributes(struct fsl_mc_io * mc_io,u32 cmd_flags,u16 token,struct dpsw_attr * attr)2965ac2d254SIoana Ciornei int dpsw_get_attributes(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
297f48298d3SIoana Ciornei 			struct dpsw_attr *attr)
298f48298d3SIoana Ciornei {
299f48298d3SIoana Ciornei 	struct fsl_mc_command cmd = { 0 };
300f48298d3SIoana Ciornei 	struct dpsw_rsp_get_attr *rsp_params;
301f48298d3SIoana Ciornei 	int err;
302f48298d3SIoana Ciornei 
303f48298d3SIoana Ciornei 	/* prepare command */
304f48298d3SIoana Ciornei 	cmd.header = mc_encode_cmd_header(DPSW_CMDID_GET_ATTR,
305f48298d3SIoana Ciornei 					  cmd_flags,
306f48298d3SIoana Ciornei 					  token);
307f48298d3SIoana Ciornei 
308f48298d3SIoana Ciornei 	/* send command to mc*/
309f48298d3SIoana Ciornei 	err = mc_send_command(mc_io, &cmd);
310f48298d3SIoana Ciornei 	if (err)
311f48298d3SIoana Ciornei 		return err;
312f48298d3SIoana Ciornei 
313f48298d3SIoana Ciornei 	/* retrieve response parameters */
314f48298d3SIoana Ciornei 	rsp_params = (struct dpsw_rsp_get_attr *)cmd.params;
315f48298d3SIoana Ciornei 	attr->num_ifs = le16_to_cpu(rsp_params->num_ifs);
316f48298d3SIoana Ciornei 	attr->max_fdbs = rsp_params->max_fdbs;
317f48298d3SIoana Ciornei 	attr->num_fdbs = rsp_params->num_fdbs;
318f48298d3SIoana Ciornei 	attr->max_vlans = le16_to_cpu(rsp_params->max_vlans);
319f48298d3SIoana Ciornei 	attr->num_vlans = le16_to_cpu(rsp_params->num_vlans);
320f48298d3SIoana Ciornei 	attr->max_fdb_entries = le16_to_cpu(rsp_params->max_fdb_entries);
321f48298d3SIoana Ciornei 	attr->fdb_aging_time = le16_to_cpu(rsp_params->fdb_aging_time);
322f48298d3SIoana Ciornei 	attr->id = le32_to_cpu(rsp_params->dpsw_id);
323f48298d3SIoana Ciornei 	attr->mem_size = le16_to_cpu(rsp_params->mem_size);
324f48298d3SIoana Ciornei 	attr->max_fdb_mc_groups = le16_to_cpu(rsp_params->max_fdb_mc_groups);
325f48298d3SIoana Ciornei 	attr->max_meters_per_if = rsp_params->max_meters_per_if;
326f48298d3SIoana Ciornei 	attr->options = le64_to_cpu(rsp_params->options);
327f48298d3SIoana Ciornei 	attr->component_type = dpsw_get_field(rsp_params->component_type, COMPONENT_TYPE);
328f48298d3SIoana Ciornei 	attr->flooding_cfg = dpsw_get_field(rsp_params->repl_cfg, FLOODING_CFG);
329f48298d3SIoana Ciornei 	attr->broadcast_cfg = dpsw_get_field(rsp_params->repl_cfg, BROADCAST_CFG);
330f48298d3SIoana Ciornei 	return 0;
331f48298d3SIoana Ciornei }
332f48298d3SIoana Ciornei 
333f48298d3SIoana Ciornei /**
334f48298d3SIoana Ciornei  * dpsw_if_set_link_cfg() - Set the link configuration.
335f48298d3SIoana Ciornei  * @mc_io:	Pointer to MC portal's I/O object
336f48298d3SIoana Ciornei  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
337f48298d3SIoana Ciornei  * @token:	Token of DPSW object
338f48298d3SIoana Ciornei  * @if_id:	Interface id
339f48298d3SIoana Ciornei  * @cfg:	Link configuration
340f48298d3SIoana Ciornei  *
341f48298d3SIoana Ciornei  * Return:	'0' on Success; Error code otherwise.
342f48298d3SIoana Ciornei  */
dpsw_if_set_link_cfg(struct fsl_mc_io * mc_io,u32 cmd_flags,u16 token,u16 if_id,struct dpsw_link_cfg * cfg)3435ac2d254SIoana Ciornei int dpsw_if_set_link_cfg(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token, u16 if_id,
344f48298d3SIoana Ciornei 			 struct dpsw_link_cfg *cfg)
345f48298d3SIoana Ciornei {
346f48298d3SIoana Ciornei 	struct fsl_mc_command cmd = { 0 };
347f48298d3SIoana Ciornei 	struct dpsw_cmd_if_set_link_cfg *cmd_params;
348f48298d3SIoana Ciornei 
349f48298d3SIoana Ciornei 	/* prepare command */
350f48298d3SIoana Ciornei 	cmd.header = mc_encode_cmd_header(DPSW_CMDID_IF_SET_LINK_CFG,
351f48298d3SIoana Ciornei 					  cmd_flags,
352f48298d3SIoana Ciornei 					  token);
353f48298d3SIoana Ciornei 	cmd_params = (struct dpsw_cmd_if_set_link_cfg *)cmd.params;
354f48298d3SIoana Ciornei 	cmd_params->if_id = cpu_to_le16(if_id);
355f48298d3SIoana Ciornei 	cmd_params->rate = cpu_to_le32(cfg->rate);
356f48298d3SIoana Ciornei 	cmd_params->options = cpu_to_le64(cfg->options);
357f48298d3SIoana Ciornei 
358f48298d3SIoana Ciornei 	/* send command to mc*/
359f48298d3SIoana Ciornei 	return mc_send_command(mc_io, &cmd);
360f48298d3SIoana Ciornei }
361f48298d3SIoana Ciornei 
362f48298d3SIoana Ciornei /**
363f48298d3SIoana Ciornei  * dpsw_if_get_link_state - Return the link state
364f48298d3SIoana Ciornei  * @mc_io:	Pointer to MC portal's I/O object
365f48298d3SIoana Ciornei  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
366f48298d3SIoana Ciornei  * @token:	Token of DPSW object
367f48298d3SIoana Ciornei  * @if_id:	Interface id
368f48298d3SIoana Ciornei  * @state:	Link state	1 - linkup, 0 - link down or disconnected
369f48298d3SIoana Ciornei  *
370cba04456SIoana Ciornei  * Return:	'0' on Success; Error code otherwise.
371f48298d3SIoana Ciornei  */
dpsw_if_get_link_state(struct fsl_mc_io * mc_io,u32 cmd_flags,u16 token,u16 if_id,struct dpsw_link_state * state)3725ac2d254SIoana Ciornei int dpsw_if_get_link_state(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
3735ac2d254SIoana Ciornei 			   u16 if_id, struct dpsw_link_state *state)
374f48298d3SIoana Ciornei {
375f48298d3SIoana Ciornei 	struct fsl_mc_command cmd = { 0 };
376f48298d3SIoana Ciornei 	struct dpsw_cmd_if_get_link_state *cmd_params;
377f48298d3SIoana Ciornei 	struct dpsw_rsp_if_get_link_state *rsp_params;
378f48298d3SIoana Ciornei 	int err;
379f48298d3SIoana Ciornei 
380f48298d3SIoana Ciornei 	/* prepare command */
381f48298d3SIoana Ciornei 	cmd.header = mc_encode_cmd_header(DPSW_CMDID_IF_GET_LINK_STATE,
382f48298d3SIoana Ciornei 					  cmd_flags,
383f48298d3SIoana Ciornei 					  token);
384f48298d3SIoana Ciornei 	cmd_params = (struct dpsw_cmd_if_get_link_state *)cmd.params;
385f48298d3SIoana Ciornei 	cmd_params->if_id = cpu_to_le16(if_id);
386f48298d3SIoana Ciornei 
387f48298d3SIoana Ciornei 	/* send command to mc*/
388f48298d3SIoana Ciornei 	err = mc_send_command(mc_io, &cmd);
389f48298d3SIoana Ciornei 	if (err)
390f48298d3SIoana Ciornei 		return err;
391f48298d3SIoana Ciornei 
392f48298d3SIoana Ciornei 	/* retrieve response parameters */
393f48298d3SIoana Ciornei 	rsp_params = (struct dpsw_rsp_if_get_link_state *)cmd.params;
394f48298d3SIoana Ciornei 	state->rate = le32_to_cpu(rsp_params->rate);
395f48298d3SIoana Ciornei 	state->options = le64_to_cpu(rsp_params->options);
396f48298d3SIoana Ciornei 	state->up = dpsw_get_field(rsp_params->up, UP);
397f48298d3SIoana Ciornei 
398f48298d3SIoana Ciornei 	return 0;
399f48298d3SIoana Ciornei }
400f48298d3SIoana Ciornei 
401f48298d3SIoana Ciornei /**
402f48298d3SIoana Ciornei  * dpsw_if_set_tci() - Set default VLAN Tag Control Information (TCI)
403f48298d3SIoana Ciornei  * @mc_io:	Pointer to MC portal's I/O object
404f48298d3SIoana Ciornei  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
405f48298d3SIoana Ciornei  * @token:	Token of DPSW object
406f48298d3SIoana Ciornei  * @if_id:	Interface Identifier
407f48298d3SIoana Ciornei  * @cfg:	Tag Control Information Configuration
408f48298d3SIoana Ciornei  *
409f48298d3SIoana Ciornei  * Return:	Completion status. '0' on Success; Error code otherwise.
410f48298d3SIoana Ciornei  */
dpsw_if_set_tci(struct fsl_mc_io * mc_io,u32 cmd_flags,u16 token,u16 if_id,const struct dpsw_tci_cfg * cfg)4115ac2d254SIoana Ciornei int dpsw_if_set_tci(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token, u16 if_id,
412f48298d3SIoana Ciornei 		    const struct dpsw_tci_cfg *cfg)
413f48298d3SIoana Ciornei {
414f48298d3SIoana Ciornei 	struct fsl_mc_command cmd = { 0 };
415f48298d3SIoana Ciornei 	struct dpsw_cmd_if_set_tci *cmd_params;
416f48298d3SIoana Ciornei 	u16 tmp_conf = 0;
417f48298d3SIoana Ciornei 
418f48298d3SIoana Ciornei 	/* prepare command */
419f48298d3SIoana Ciornei 	cmd.header = mc_encode_cmd_header(DPSW_CMDID_IF_SET_TCI,
420f48298d3SIoana Ciornei 					  cmd_flags,
421f48298d3SIoana Ciornei 					  token);
422f48298d3SIoana Ciornei 	cmd_params = (struct dpsw_cmd_if_set_tci *)cmd.params;
423f48298d3SIoana Ciornei 	cmd_params->if_id = cpu_to_le16(if_id);
424f48298d3SIoana Ciornei 	dpsw_set_field(tmp_conf, VLAN_ID, cfg->vlan_id);
425f48298d3SIoana Ciornei 	dpsw_set_field(tmp_conf, DEI, cfg->dei);
426f48298d3SIoana Ciornei 	dpsw_set_field(tmp_conf, PCP, cfg->pcp);
427f48298d3SIoana Ciornei 	cmd_params->conf = cpu_to_le16(tmp_conf);
428f48298d3SIoana Ciornei 
429f48298d3SIoana Ciornei 	/* send command to mc*/
430f48298d3SIoana Ciornei 	return mc_send_command(mc_io, &cmd);
431f48298d3SIoana Ciornei }
432f48298d3SIoana Ciornei 
433f48298d3SIoana Ciornei /**
434f48298d3SIoana Ciornei  * dpsw_if_get_tci() - Get default VLAN Tag Control Information (TCI)
435f48298d3SIoana Ciornei  * @mc_io:	Pointer to MC portal's I/O object
436f48298d3SIoana Ciornei  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
437f48298d3SIoana Ciornei  * @token:	Token of DPSW object
438f48298d3SIoana Ciornei  * @if_id:	Interface Identifier
439f48298d3SIoana Ciornei  * @cfg:	Tag Control Information Configuration
440f48298d3SIoana Ciornei  *
441f48298d3SIoana Ciornei  * Return:	Completion status. '0' on Success; Error code otherwise.
442f48298d3SIoana Ciornei  */
dpsw_if_get_tci(struct fsl_mc_io * mc_io,u32 cmd_flags,u16 token,u16 if_id,struct dpsw_tci_cfg * cfg)4435ac2d254SIoana Ciornei int dpsw_if_get_tci(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token, u16 if_id,
444f48298d3SIoana Ciornei 		    struct dpsw_tci_cfg *cfg)
445f48298d3SIoana Ciornei {
446f48298d3SIoana Ciornei 	struct fsl_mc_command cmd = { 0 };
447f48298d3SIoana Ciornei 	struct dpsw_cmd_if_get_tci *cmd_params;
448f48298d3SIoana Ciornei 	struct dpsw_rsp_if_get_tci *rsp_params;
449f48298d3SIoana Ciornei 	int err;
450f48298d3SIoana Ciornei 
451f48298d3SIoana Ciornei 	/* prepare command */
452f48298d3SIoana Ciornei 	cmd.header = mc_encode_cmd_header(DPSW_CMDID_IF_GET_TCI,
453f48298d3SIoana Ciornei 					  cmd_flags,
454f48298d3SIoana Ciornei 					  token);
455f48298d3SIoana Ciornei 	cmd_params = (struct dpsw_cmd_if_get_tci *)cmd.params;
456f48298d3SIoana Ciornei 	cmd_params->if_id = cpu_to_le16(if_id);
457f48298d3SIoana Ciornei 
458f48298d3SIoana Ciornei 	/* send command to mc*/
459f48298d3SIoana Ciornei 	err = mc_send_command(mc_io, &cmd);
460f48298d3SIoana Ciornei 	if (err)
461f48298d3SIoana Ciornei 		return err;
462f48298d3SIoana Ciornei 
463f48298d3SIoana Ciornei 	/* retrieve response parameters */
464f48298d3SIoana Ciornei 	rsp_params = (struct dpsw_rsp_if_get_tci *)cmd.params;
465f48298d3SIoana Ciornei 	cfg->pcp = rsp_params->pcp;
466f48298d3SIoana Ciornei 	cfg->dei = rsp_params->dei;
467f48298d3SIoana Ciornei 	cfg->vlan_id = le16_to_cpu(rsp_params->vlan_id);
468f48298d3SIoana Ciornei 
469f48298d3SIoana Ciornei 	return 0;
470f48298d3SIoana Ciornei }
471f48298d3SIoana Ciornei 
472f48298d3SIoana Ciornei /**
473f48298d3SIoana Ciornei  * dpsw_if_set_stp() - Function sets Spanning Tree Protocol (STP) state.
474f48298d3SIoana Ciornei  * @mc_io:	Pointer to MC portal's I/O object
475f48298d3SIoana Ciornei  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
476f48298d3SIoana Ciornei  * @token:	Token of DPSW object
477f48298d3SIoana Ciornei  * @if_id:	Interface Identifier
478f48298d3SIoana Ciornei  * @cfg:	STP State configuration parameters
479f48298d3SIoana Ciornei  *
480f48298d3SIoana Ciornei  * The following STP states are supported -
481f48298d3SIoana Ciornei  * blocking, listening, learning, forwarding and disabled.
482f48298d3SIoana Ciornei  *
483f48298d3SIoana Ciornei  * Return:	Completion status. '0' on Success; Error code otherwise.
484f48298d3SIoana Ciornei  */
dpsw_if_set_stp(struct fsl_mc_io * mc_io,u32 cmd_flags,u16 token,u16 if_id,const struct dpsw_stp_cfg * cfg)4855ac2d254SIoana Ciornei int dpsw_if_set_stp(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token, u16 if_id,
486f48298d3SIoana Ciornei 		    const struct dpsw_stp_cfg *cfg)
487f48298d3SIoana Ciornei {
488f48298d3SIoana Ciornei 	struct fsl_mc_command cmd = { 0 };
489f48298d3SIoana Ciornei 	struct dpsw_cmd_if_set_stp *cmd_params;
490f48298d3SIoana Ciornei 
491f48298d3SIoana Ciornei 	/* prepare command */
492f48298d3SIoana Ciornei 	cmd.header = mc_encode_cmd_header(DPSW_CMDID_IF_SET_STP,
493f48298d3SIoana Ciornei 					  cmd_flags,
494f48298d3SIoana Ciornei 					  token);
495f48298d3SIoana Ciornei 	cmd_params = (struct dpsw_cmd_if_set_stp *)cmd.params;
496f48298d3SIoana Ciornei 	cmd_params->if_id = cpu_to_le16(if_id);
497f48298d3SIoana Ciornei 	cmd_params->vlan_id = cpu_to_le16(cfg->vlan_id);
498f48298d3SIoana Ciornei 	dpsw_set_field(cmd_params->state, STATE, cfg->state);
499f48298d3SIoana Ciornei 
500f48298d3SIoana Ciornei 	/* send command to mc*/
501f48298d3SIoana Ciornei 	return mc_send_command(mc_io, &cmd);
502f48298d3SIoana Ciornei }
503f48298d3SIoana Ciornei 
504f48298d3SIoana Ciornei /**
505f48298d3SIoana Ciornei  * dpsw_if_get_counter() - Get specific counter of particular interface
506f48298d3SIoana Ciornei  * @mc_io:	Pointer to MC portal's I/O object
507f48298d3SIoana Ciornei  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
508f48298d3SIoana Ciornei  * @token:	Token of DPSW object
509f48298d3SIoana Ciornei  * @if_id:	Interface Identifier
510f48298d3SIoana Ciornei  * @type:	Counter type
511f48298d3SIoana Ciornei  * @counter:	return value
512f48298d3SIoana Ciornei  *
513f48298d3SIoana Ciornei  * Return:	Completion status. '0' on Success; Error code otherwise.
514f48298d3SIoana Ciornei  */
dpsw_if_get_counter(struct fsl_mc_io * mc_io,u32 cmd_flags,u16 token,u16 if_id,enum dpsw_counter type,u64 * counter)5155ac2d254SIoana Ciornei int dpsw_if_get_counter(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
5165ac2d254SIoana Ciornei 			u16 if_id, enum dpsw_counter type, u64 *counter)
517f48298d3SIoana Ciornei {
518f48298d3SIoana Ciornei 	struct fsl_mc_command cmd = { 0 };
519f48298d3SIoana Ciornei 	struct dpsw_cmd_if_get_counter *cmd_params;
520f48298d3SIoana Ciornei 	struct dpsw_rsp_if_get_counter *rsp_params;
521f48298d3SIoana Ciornei 	int err;
522f48298d3SIoana Ciornei 
523f48298d3SIoana Ciornei 	/* prepare command */
524f48298d3SIoana Ciornei 	cmd.header = mc_encode_cmd_header(DPSW_CMDID_IF_GET_COUNTER,
525f48298d3SIoana Ciornei 					  cmd_flags,
526f48298d3SIoana Ciornei 					  token);
527f48298d3SIoana Ciornei 	cmd_params = (struct dpsw_cmd_if_get_counter *)cmd.params;
528f48298d3SIoana Ciornei 	cmd_params->if_id = cpu_to_le16(if_id);
529f48298d3SIoana Ciornei 	dpsw_set_field(cmd_params->type, COUNTER_TYPE, type);
530f48298d3SIoana Ciornei 
531f48298d3SIoana Ciornei 	/* send command to mc*/
532f48298d3SIoana Ciornei 	err = mc_send_command(mc_io, &cmd);
533f48298d3SIoana Ciornei 	if (err)
534f48298d3SIoana Ciornei 		return err;
535f48298d3SIoana Ciornei 
536f48298d3SIoana Ciornei 	/* retrieve response parameters */
537f48298d3SIoana Ciornei 	rsp_params = (struct dpsw_rsp_if_get_counter *)cmd.params;
538f48298d3SIoana Ciornei 	*counter = le64_to_cpu(rsp_params->counter);
539f48298d3SIoana Ciornei 
540f48298d3SIoana Ciornei 	return 0;
541f48298d3SIoana Ciornei }
542f48298d3SIoana Ciornei 
543f48298d3SIoana Ciornei /**
544f48298d3SIoana Ciornei  * dpsw_if_enable() - Enable Interface
545f48298d3SIoana Ciornei  * @mc_io:	Pointer to MC portal's I/O object
546f48298d3SIoana Ciornei  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
547f48298d3SIoana Ciornei  * @token:	Token of DPSW object
548f48298d3SIoana Ciornei  * @if_id:	Interface Identifier
549f48298d3SIoana Ciornei  *
550f48298d3SIoana Ciornei  * Return:	Completion status. '0' on Success; Error code otherwise.
551f48298d3SIoana Ciornei  */
dpsw_if_enable(struct fsl_mc_io * mc_io,u32 cmd_flags,u16 token,u16 if_id)5525ac2d254SIoana Ciornei int dpsw_if_enable(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token, u16 if_id)
553f48298d3SIoana Ciornei {
554f48298d3SIoana Ciornei 	struct fsl_mc_command cmd = { 0 };
555f48298d3SIoana Ciornei 	struct dpsw_cmd_if *cmd_params;
556f48298d3SIoana Ciornei 
557f48298d3SIoana Ciornei 	/* prepare command */
558f48298d3SIoana Ciornei 	cmd.header = mc_encode_cmd_header(DPSW_CMDID_IF_ENABLE,
559f48298d3SIoana Ciornei 					  cmd_flags,
560f48298d3SIoana Ciornei 					  token);
561f48298d3SIoana Ciornei 	cmd_params = (struct dpsw_cmd_if *)cmd.params;
562f48298d3SIoana Ciornei 	cmd_params->if_id = cpu_to_le16(if_id);
563f48298d3SIoana Ciornei 
564f48298d3SIoana Ciornei 	/* send command to mc*/
565f48298d3SIoana Ciornei 	return mc_send_command(mc_io, &cmd);
566f48298d3SIoana Ciornei }
567f48298d3SIoana Ciornei 
568f48298d3SIoana Ciornei /**
569f48298d3SIoana Ciornei  * dpsw_if_disable() - Disable Interface
570f48298d3SIoana Ciornei  * @mc_io:	Pointer to MC portal's I/O object
571f48298d3SIoana Ciornei  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
572f48298d3SIoana Ciornei  * @token:	Token of DPSW object
573f48298d3SIoana Ciornei  * @if_id:	Interface Identifier
574f48298d3SIoana Ciornei  *
575f48298d3SIoana Ciornei  * Return:	Completion status. '0' on Success; Error code otherwise.
576f48298d3SIoana Ciornei  */
dpsw_if_disable(struct fsl_mc_io * mc_io,u32 cmd_flags,u16 token,u16 if_id)5775ac2d254SIoana Ciornei int dpsw_if_disable(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token, u16 if_id)
578f48298d3SIoana Ciornei {
579f48298d3SIoana Ciornei 	struct fsl_mc_command cmd = { 0 };
580f48298d3SIoana Ciornei 	struct dpsw_cmd_if *cmd_params;
581f48298d3SIoana Ciornei 
582f48298d3SIoana Ciornei 	/* prepare command */
583f48298d3SIoana Ciornei 	cmd.header = mc_encode_cmd_header(DPSW_CMDID_IF_DISABLE,
584f48298d3SIoana Ciornei 					  cmd_flags,
585f48298d3SIoana Ciornei 					  token);
586f48298d3SIoana Ciornei 	cmd_params = (struct dpsw_cmd_if *)cmd.params;
587f48298d3SIoana Ciornei 	cmd_params->if_id = cpu_to_le16(if_id);
588f48298d3SIoana Ciornei 
589f48298d3SIoana Ciornei 	/* send command to mc*/
590f48298d3SIoana Ciornei 	return mc_send_command(mc_io, &cmd);
591f48298d3SIoana Ciornei }
592f48298d3SIoana Ciornei 
593f48298d3SIoana Ciornei /**
594f48298d3SIoana Ciornei  * dpsw_if_get_attributes() - Function obtains attributes of interface
595f48298d3SIoana Ciornei  * @mc_io:	Pointer to MC portal's I/O object
596f48298d3SIoana Ciornei  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
597f48298d3SIoana Ciornei  * @token:	Token of DPSW object
598f48298d3SIoana Ciornei  * @if_id:	Interface Identifier
599f48298d3SIoana Ciornei  * @attr:	Returned interface attributes
600f48298d3SIoana Ciornei  *
601f48298d3SIoana Ciornei  * Return:	Completion status. '0' on Success; Error code otherwise.
602f48298d3SIoana Ciornei  */
dpsw_if_get_attributes(struct fsl_mc_io * mc_io,u32 cmd_flags,u16 token,u16 if_id,struct dpsw_if_attr * attr)603f48298d3SIoana Ciornei int dpsw_if_get_attributes(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
604f48298d3SIoana Ciornei 			   u16 if_id, struct dpsw_if_attr *attr)
605f48298d3SIoana Ciornei {
606f48298d3SIoana Ciornei 	struct dpsw_rsp_if_get_attr *rsp_params;
607f48298d3SIoana Ciornei 	struct fsl_mc_command cmd = { 0 };
608f48298d3SIoana Ciornei 	struct dpsw_cmd_if *cmd_params;
609f48298d3SIoana Ciornei 	int err;
610f48298d3SIoana Ciornei 
611f48298d3SIoana Ciornei 	cmd.header = mc_encode_cmd_header(DPSW_CMDID_IF_GET_ATTR, cmd_flags,
612f48298d3SIoana Ciornei 					  token);
613f48298d3SIoana Ciornei 	cmd_params = (struct dpsw_cmd_if *)cmd.params;
614f48298d3SIoana Ciornei 	cmd_params->if_id = cpu_to_le16(if_id);
615f48298d3SIoana Ciornei 
616f48298d3SIoana Ciornei 	err = mc_send_command(mc_io, &cmd);
617f48298d3SIoana Ciornei 	if (err)
618f48298d3SIoana Ciornei 		return err;
619f48298d3SIoana Ciornei 
620f48298d3SIoana Ciornei 	rsp_params = (struct dpsw_rsp_if_get_attr *)cmd.params;
621f48298d3SIoana Ciornei 	attr->num_tcs = rsp_params->num_tcs;
622f48298d3SIoana Ciornei 	attr->rate = le32_to_cpu(rsp_params->rate);
623f48298d3SIoana Ciornei 	attr->options = le32_to_cpu(rsp_params->options);
624f48298d3SIoana Ciornei 	attr->qdid = le16_to_cpu(rsp_params->qdid);
625f48298d3SIoana Ciornei 	attr->enabled = dpsw_get_field(rsp_params->conf, ENABLED);
626f48298d3SIoana Ciornei 	attr->accept_all_vlan = dpsw_get_field(rsp_params->conf,
627f48298d3SIoana Ciornei 					       ACCEPT_ALL_VLAN);
628f48298d3SIoana Ciornei 	attr->admit_untagged = dpsw_get_field(rsp_params->conf,
629f48298d3SIoana Ciornei 					      ADMIT_UNTAGGED);
630f48298d3SIoana Ciornei 
631f48298d3SIoana Ciornei 	return 0;
632f48298d3SIoana Ciornei }
633f48298d3SIoana Ciornei 
634f48298d3SIoana Ciornei /**
635f48298d3SIoana Ciornei  * dpsw_if_set_max_frame_length() - Set Maximum Receive frame length.
636f48298d3SIoana Ciornei  * @mc_io:		Pointer to MC portal's I/O object
637f48298d3SIoana Ciornei  * @cmd_flags:		Command flags; one or more of 'MC_CMD_FLAG_'
638f48298d3SIoana Ciornei  * @token:		Token of DPSW object
639f48298d3SIoana Ciornei  * @if_id:		Interface Identifier
640f48298d3SIoana Ciornei  * @frame_length:	Maximum Frame Length
641f48298d3SIoana Ciornei  *
642f48298d3SIoana Ciornei  * Return:	Completion status. '0' on Success; Error code otherwise.
643f48298d3SIoana Ciornei  */
dpsw_if_set_max_frame_length(struct fsl_mc_io * mc_io,u32 cmd_flags,u16 token,u16 if_id,u16 frame_length)6445ac2d254SIoana Ciornei int dpsw_if_set_max_frame_length(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
6455ac2d254SIoana Ciornei 				 u16 if_id, u16 frame_length)
646f48298d3SIoana Ciornei {
647f48298d3SIoana Ciornei 	struct fsl_mc_command cmd = { 0 };
648f48298d3SIoana Ciornei 	struct dpsw_cmd_if_set_max_frame_length *cmd_params;
649f48298d3SIoana Ciornei 
650f48298d3SIoana Ciornei 	/* prepare command */
651f48298d3SIoana Ciornei 	cmd.header = mc_encode_cmd_header(DPSW_CMDID_IF_SET_MAX_FRAME_LENGTH,
652f48298d3SIoana Ciornei 					  cmd_flags,
653f48298d3SIoana Ciornei 					  token);
654f48298d3SIoana Ciornei 	cmd_params = (struct dpsw_cmd_if_set_max_frame_length *)cmd.params;
655f48298d3SIoana Ciornei 	cmd_params->if_id = cpu_to_le16(if_id);
656f48298d3SIoana Ciornei 	cmd_params->frame_length = cpu_to_le16(frame_length);
657f48298d3SIoana Ciornei 
658f48298d3SIoana Ciornei 	/* send command to mc*/
659f48298d3SIoana Ciornei 	return mc_send_command(mc_io, &cmd);
660f48298d3SIoana Ciornei }
661f48298d3SIoana Ciornei 
662f48298d3SIoana Ciornei /**
663f48298d3SIoana Ciornei  * dpsw_vlan_add() - Adding new VLAN to DPSW.
664f48298d3SIoana Ciornei  * @mc_io:	Pointer to MC portal's I/O object
665f48298d3SIoana Ciornei  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
666f48298d3SIoana Ciornei  * @token:	Token of DPSW object
667f48298d3SIoana Ciornei  * @vlan_id:	VLAN Identifier
668f48298d3SIoana Ciornei  * @cfg:	VLAN configuration
669f48298d3SIoana Ciornei  *
670f48298d3SIoana Ciornei  * Only VLAN ID and FDB ID are required parameters here.
671f48298d3SIoana Ciornei  * 12 bit VLAN ID is defined in IEEE802.1Q.
672f48298d3SIoana Ciornei  * Adding a duplicate VLAN ID is not allowed.
673f48298d3SIoana Ciornei  * FDB ID can be shared across multiple VLANs. Shared learning
674f48298d3SIoana Ciornei  * is obtained by calling dpsw_vlan_add for multiple VLAN IDs
675f48298d3SIoana Ciornei  * with same fdb_id
676f48298d3SIoana Ciornei  *
677f48298d3SIoana Ciornei  * Return:	Completion status. '0' on Success; Error code otherwise.
678f48298d3SIoana Ciornei  */
dpsw_vlan_add(struct fsl_mc_io * mc_io,u32 cmd_flags,u16 token,u16 vlan_id,const struct dpsw_vlan_cfg * cfg)6795ac2d254SIoana Ciornei int dpsw_vlan_add(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
6805ac2d254SIoana Ciornei 		  u16 vlan_id, const struct dpsw_vlan_cfg *cfg)
681f48298d3SIoana Ciornei {
682f48298d3SIoana Ciornei 	struct fsl_mc_command cmd = { 0 };
683f48298d3SIoana Ciornei 	struct dpsw_vlan_add *cmd_params;
684f48298d3SIoana Ciornei 
685f48298d3SIoana Ciornei 	/* prepare command */
686f48298d3SIoana Ciornei 	cmd.header = mc_encode_cmd_header(DPSW_CMDID_VLAN_ADD,
687f48298d3SIoana Ciornei 					  cmd_flags,
688f48298d3SIoana Ciornei 					  token);
689f48298d3SIoana Ciornei 	cmd_params = (struct dpsw_vlan_add *)cmd.params;
690f48298d3SIoana Ciornei 	cmd_params->fdb_id = cpu_to_le16(cfg->fdb_id);
691f48298d3SIoana Ciornei 	cmd_params->vlan_id = cpu_to_le16(vlan_id);
692f48298d3SIoana Ciornei 
693f48298d3SIoana Ciornei 	/* send command to mc*/
694f48298d3SIoana Ciornei 	return mc_send_command(mc_io, &cmd);
695f48298d3SIoana Ciornei }
696f48298d3SIoana Ciornei 
697f48298d3SIoana Ciornei /**
698f48298d3SIoana Ciornei  * dpsw_vlan_add_if() - Adding a set of interfaces to an existing VLAN.
699f48298d3SIoana Ciornei  * @mc_io:	Pointer to MC portal's I/O object
700f48298d3SIoana Ciornei  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
701f48298d3SIoana Ciornei  * @token:	Token of DPSW object
702f48298d3SIoana Ciornei  * @vlan_id:	VLAN Identifier
703f48298d3SIoana Ciornei  * @cfg:	Set of interfaces to add
704f48298d3SIoana Ciornei  *
705f48298d3SIoana Ciornei  * It adds only interfaces not belonging to this VLAN yet,
706f48298d3SIoana Ciornei  * otherwise an error is generated and an entire command is
707f48298d3SIoana Ciornei  * ignored. This function can be called numerous times always
708f48298d3SIoana Ciornei  * providing required interfaces delta.
709f48298d3SIoana Ciornei  *
710f48298d3SIoana Ciornei  * Return:	Completion status. '0' on Success; Error code otherwise.
711f48298d3SIoana Ciornei  */
dpsw_vlan_add_if(struct fsl_mc_io * mc_io,u32 cmd_flags,u16 token,u16 vlan_id,const struct dpsw_vlan_if_cfg * cfg)7125ac2d254SIoana Ciornei int dpsw_vlan_add_if(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
7135ac2d254SIoana Ciornei 		     u16 vlan_id, const struct dpsw_vlan_if_cfg *cfg)
714f48298d3SIoana Ciornei {
7152b7e3f7dSIoana Ciornei 	struct dpsw_cmd_vlan_add_if *cmd_params;
716f48298d3SIoana Ciornei 	struct fsl_mc_command cmd = { 0 };
717f48298d3SIoana Ciornei 
718f48298d3SIoana Ciornei 	/* prepare command */
719f48298d3SIoana Ciornei 	cmd.header = mc_encode_cmd_header(DPSW_CMDID_VLAN_ADD_IF,
720f48298d3SIoana Ciornei 					  cmd_flags,
721f48298d3SIoana Ciornei 					  token);
7222b7e3f7dSIoana Ciornei 	cmd_params = (struct dpsw_cmd_vlan_add_if *)cmd.params;
723f48298d3SIoana Ciornei 	cmd_params->vlan_id = cpu_to_le16(vlan_id);
7242b7e3f7dSIoana Ciornei 	cmd_params->options = cpu_to_le16(cfg->options);
7252b7e3f7dSIoana Ciornei 	cmd_params->fdb_id = cpu_to_le16(cfg->fdb_id);
7262b7e3f7dSIoana Ciornei 	build_if_id_bitmap(&cmd_params->if_id, cfg->if_id, cfg->num_ifs);
727f48298d3SIoana Ciornei 
728f48298d3SIoana Ciornei 	/* send command to mc*/
729f48298d3SIoana Ciornei 	return mc_send_command(mc_io, &cmd);
730f48298d3SIoana Ciornei }
731f48298d3SIoana Ciornei 
732f48298d3SIoana Ciornei /**
733f48298d3SIoana Ciornei  * dpsw_vlan_add_if_untagged() - Defining a set of interfaces that should be
734f48298d3SIoana Ciornei  *				transmitted as untagged.
735f48298d3SIoana Ciornei  * @mc_io:	Pointer to MC portal's I/O object
736f48298d3SIoana Ciornei  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
737f48298d3SIoana Ciornei  * @token:	Token of DPSW object
738f48298d3SIoana Ciornei  * @vlan_id:	VLAN Identifier
739f48298d3SIoana Ciornei  * @cfg:	Set of interfaces that should be transmitted as untagged
740f48298d3SIoana Ciornei  *
741f48298d3SIoana Ciornei  * These interfaces should already belong to this VLAN.
742f48298d3SIoana Ciornei  * By default all interfaces are transmitted as tagged.
743f48298d3SIoana Ciornei  * Providing un-existing interface or untagged interface that is
744f48298d3SIoana Ciornei  * configured untagged already generates an error and the entire
745f48298d3SIoana Ciornei  * command is ignored.
746f48298d3SIoana Ciornei  *
747f48298d3SIoana Ciornei  * Return:	Completion status. '0' on Success; Error code otherwise.
748f48298d3SIoana Ciornei  */
dpsw_vlan_add_if_untagged(struct fsl_mc_io * mc_io,u32 cmd_flags,u16 token,u16 vlan_id,const struct dpsw_vlan_if_cfg * cfg)7495ac2d254SIoana Ciornei int dpsw_vlan_add_if_untagged(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
7505ac2d254SIoana Ciornei 			      u16 vlan_id, const struct dpsw_vlan_if_cfg *cfg)
751f48298d3SIoana Ciornei {
752f48298d3SIoana Ciornei 	struct fsl_mc_command cmd = { 0 };
753f48298d3SIoana Ciornei 	struct dpsw_cmd_vlan_manage_if *cmd_params;
754f48298d3SIoana Ciornei 
755f48298d3SIoana Ciornei 	/* prepare command */
756f48298d3SIoana Ciornei 	cmd.header = mc_encode_cmd_header(DPSW_CMDID_VLAN_ADD_IF_UNTAGGED,
757f48298d3SIoana Ciornei 					  cmd_flags,
758f48298d3SIoana Ciornei 					  token);
759f48298d3SIoana Ciornei 	cmd_params = (struct dpsw_cmd_vlan_manage_if *)cmd.params;
760f48298d3SIoana Ciornei 	cmd_params->vlan_id = cpu_to_le16(vlan_id);
7612b7e3f7dSIoana Ciornei 	build_if_id_bitmap(&cmd_params->if_id, cfg->if_id, cfg->num_ifs);
762f48298d3SIoana Ciornei 
763f48298d3SIoana Ciornei 	/* send command to mc*/
764f48298d3SIoana Ciornei 	return mc_send_command(mc_io, &cmd);
765f48298d3SIoana Ciornei }
766f48298d3SIoana Ciornei 
767f48298d3SIoana Ciornei /**
768f48298d3SIoana Ciornei  * dpsw_vlan_remove_if() - Remove interfaces from an existing VLAN.
769f48298d3SIoana Ciornei  * @mc_io:	Pointer to MC portal's I/O object
770f48298d3SIoana Ciornei  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
771f48298d3SIoana Ciornei  * @token:	Token of DPSW object
772f48298d3SIoana Ciornei  * @vlan_id:	VLAN Identifier
773f48298d3SIoana Ciornei  * @cfg:	Set of interfaces that should be removed
774f48298d3SIoana Ciornei  *
775f48298d3SIoana Ciornei  * Interfaces must belong to this VLAN, otherwise an error
776f48298d3SIoana Ciornei  * is returned and an the command is ignored
777f48298d3SIoana Ciornei  *
778f48298d3SIoana Ciornei  * Return:	Completion status. '0' on Success; Error code otherwise.
779f48298d3SIoana Ciornei  */
dpsw_vlan_remove_if(struct fsl_mc_io * mc_io,u32 cmd_flags,u16 token,u16 vlan_id,const struct dpsw_vlan_if_cfg * cfg)7805ac2d254SIoana Ciornei int dpsw_vlan_remove_if(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
7815ac2d254SIoana Ciornei 			u16 vlan_id, const struct dpsw_vlan_if_cfg *cfg)
782f48298d3SIoana Ciornei {
783f48298d3SIoana Ciornei 	struct fsl_mc_command cmd = { 0 };
784f48298d3SIoana Ciornei 	struct dpsw_cmd_vlan_manage_if *cmd_params;
785f48298d3SIoana Ciornei 
786f48298d3SIoana Ciornei 	/* prepare command */
787f48298d3SIoana Ciornei 	cmd.header = mc_encode_cmd_header(DPSW_CMDID_VLAN_REMOVE_IF,
788f48298d3SIoana Ciornei 					  cmd_flags,
789f48298d3SIoana Ciornei 					  token);
790f48298d3SIoana Ciornei 	cmd_params = (struct dpsw_cmd_vlan_manage_if *)cmd.params;
791f48298d3SIoana Ciornei 	cmd_params->vlan_id = cpu_to_le16(vlan_id);
7922b7e3f7dSIoana Ciornei 	build_if_id_bitmap(&cmd_params->if_id, cfg->if_id, cfg->num_ifs);
793f48298d3SIoana Ciornei 
794f48298d3SIoana Ciornei 	/* send command to mc*/
795f48298d3SIoana Ciornei 	return mc_send_command(mc_io, &cmd);
796f48298d3SIoana Ciornei }
797f48298d3SIoana Ciornei 
798f48298d3SIoana Ciornei /**
799f48298d3SIoana Ciornei  * dpsw_vlan_remove_if_untagged() - Define a set of interfaces that should be
800f48298d3SIoana Ciornei  *		converted from transmitted as untagged to transmit as tagged.
801f48298d3SIoana Ciornei  * @mc_io:	Pointer to MC portal's I/O object
802f48298d3SIoana Ciornei  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
803f48298d3SIoana Ciornei  * @token:	Token of DPSW object
804f48298d3SIoana Ciornei  * @vlan_id:	VLAN Identifier
805f48298d3SIoana Ciornei  * @cfg:	Set of interfaces that should be removed
806f48298d3SIoana Ciornei  *
807f48298d3SIoana Ciornei  * Interfaces provided by API have to belong to this VLAN and
808f48298d3SIoana Ciornei  * configured untagged, otherwise an error is returned and the
809f48298d3SIoana Ciornei  * command is ignored
810f48298d3SIoana Ciornei  *
811f48298d3SIoana Ciornei  * Return:	Completion status. '0' on Success; Error code otherwise.
812f48298d3SIoana Ciornei  */
dpsw_vlan_remove_if_untagged(struct fsl_mc_io * mc_io,u32 cmd_flags,u16 token,u16 vlan_id,const struct dpsw_vlan_if_cfg * cfg)8135ac2d254SIoana Ciornei int dpsw_vlan_remove_if_untagged(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
8145ac2d254SIoana Ciornei 				 u16 vlan_id, const struct dpsw_vlan_if_cfg *cfg)
815f48298d3SIoana Ciornei {
816f48298d3SIoana Ciornei 	struct fsl_mc_command cmd = { 0 };
817f48298d3SIoana Ciornei 	struct dpsw_cmd_vlan_manage_if *cmd_params;
818f48298d3SIoana Ciornei 
819f48298d3SIoana Ciornei 	/* prepare command */
820f48298d3SIoana Ciornei 	cmd.header = mc_encode_cmd_header(DPSW_CMDID_VLAN_REMOVE_IF_UNTAGGED,
821f48298d3SIoana Ciornei 					  cmd_flags,
822f48298d3SIoana Ciornei 					  token);
823f48298d3SIoana Ciornei 	cmd_params = (struct dpsw_cmd_vlan_manage_if *)cmd.params;
824f48298d3SIoana Ciornei 	cmd_params->vlan_id = cpu_to_le16(vlan_id);
8252b7e3f7dSIoana Ciornei 	build_if_id_bitmap(&cmd_params->if_id, cfg->if_id, cfg->num_ifs);
826f48298d3SIoana Ciornei 
827f48298d3SIoana Ciornei 	/* send command to mc*/
828f48298d3SIoana Ciornei 	return mc_send_command(mc_io, &cmd);
829f48298d3SIoana Ciornei }
830f48298d3SIoana Ciornei 
831f48298d3SIoana Ciornei /**
832f48298d3SIoana Ciornei  * dpsw_vlan_remove() - Remove an entire VLAN
833f48298d3SIoana Ciornei  * @mc_io:	Pointer to MC portal's I/O object
834f48298d3SIoana Ciornei  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
835f48298d3SIoana Ciornei  * @token:	Token of DPSW object
836f48298d3SIoana Ciornei  * @vlan_id:	VLAN Identifier
837f48298d3SIoana Ciornei  *
838f48298d3SIoana Ciornei  * Return:	Completion status. '0' on Success; Error code otherwise.
839f48298d3SIoana Ciornei  */
dpsw_vlan_remove(struct fsl_mc_io * mc_io,u32 cmd_flags,u16 token,u16 vlan_id)8405ac2d254SIoana Ciornei int dpsw_vlan_remove(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
841f48298d3SIoana Ciornei 		     u16 vlan_id)
842f48298d3SIoana Ciornei {
843f48298d3SIoana Ciornei 	struct fsl_mc_command cmd = { 0 };
844f48298d3SIoana Ciornei 	struct dpsw_cmd_vlan_remove *cmd_params;
845f48298d3SIoana Ciornei 
846f48298d3SIoana Ciornei 	/* prepare command */
847f48298d3SIoana Ciornei 	cmd.header = mc_encode_cmd_header(DPSW_CMDID_VLAN_REMOVE,
848f48298d3SIoana Ciornei 					  cmd_flags,
849f48298d3SIoana Ciornei 					  token);
850f48298d3SIoana Ciornei 	cmd_params = (struct dpsw_cmd_vlan_remove *)cmd.params;
851f48298d3SIoana Ciornei 	cmd_params->vlan_id = cpu_to_le16(vlan_id);
852f48298d3SIoana Ciornei 
853f48298d3SIoana Ciornei 	/* send command to mc*/
854f48298d3SIoana Ciornei 	return mc_send_command(mc_io, &cmd);
855f48298d3SIoana Ciornei }
856f48298d3SIoana Ciornei 
857f48298d3SIoana Ciornei /**
858f48298d3SIoana Ciornei  * dpsw_fdb_add() - Add FDB to switch and Returns handle to FDB table for
859f48298d3SIoana Ciornei  *		the reference
860f48298d3SIoana Ciornei  * @mc_io:	Pointer to MC portal's I/O object
861f48298d3SIoana Ciornei  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
862f48298d3SIoana Ciornei  * @token:	Token of DPSW object
863f48298d3SIoana Ciornei  * @fdb_id:	Returned Forwarding Database Identifier
864f48298d3SIoana Ciornei  * @cfg:	FDB Configuration
865f48298d3SIoana Ciornei  *
866f48298d3SIoana Ciornei  * Return:	Completion status. '0' on Success; Error code otherwise.
867f48298d3SIoana Ciornei  */
dpsw_fdb_add(struct fsl_mc_io * mc_io,u32 cmd_flags,u16 token,u16 * fdb_id,const struct dpsw_fdb_cfg * cfg)868f48298d3SIoana Ciornei int dpsw_fdb_add(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token, u16 *fdb_id,
869f48298d3SIoana Ciornei 		 const struct dpsw_fdb_cfg *cfg)
870f48298d3SIoana Ciornei {
871f48298d3SIoana Ciornei 	struct dpsw_cmd_fdb_add *cmd_params;
872f48298d3SIoana Ciornei 	struct dpsw_rsp_fdb_add *rsp_params;
873f48298d3SIoana Ciornei 	struct fsl_mc_command cmd = { 0 };
874f48298d3SIoana Ciornei 	int err;
875f48298d3SIoana Ciornei 
876f48298d3SIoana Ciornei 	cmd.header = mc_encode_cmd_header(DPSW_CMDID_FDB_ADD,
877f48298d3SIoana Ciornei 					  cmd_flags,
878f48298d3SIoana Ciornei 					  token);
879f48298d3SIoana Ciornei 	cmd_params = (struct dpsw_cmd_fdb_add *)cmd.params;
880f48298d3SIoana Ciornei 	cmd_params->fdb_ageing_time = cpu_to_le16(cfg->fdb_ageing_time);
881f48298d3SIoana Ciornei 	cmd_params->num_fdb_entries = cpu_to_le16(cfg->num_fdb_entries);
882f48298d3SIoana Ciornei 
883f48298d3SIoana Ciornei 	err = mc_send_command(mc_io, &cmd);
884f48298d3SIoana Ciornei 	if (err)
885f48298d3SIoana Ciornei 		return err;
886f48298d3SIoana Ciornei 
887f48298d3SIoana Ciornei 	rsp_params = (struct dpsw_rsp_fdb_add *)cmd.params;
888f48298d3SIoana Ciornei 	*fdb_id = le16_to_cpu(rsp_params->fdb_id);
889f48298d3SIoana Ciornei 
890f48298d3SIoana Ciornei 	return 0;
891f48298d3SIoana Ciornei }
892f48298d3SIoana Ciornei 
893f48298d3SIoana Ciornei /**
894f48298d3SIoana Ciornei  * dpsw_fdb_remove() - Remove FDB from switch
895f48298d3SIoana Ciornei  * @mc_io:	Pointer to MC portal's I/O object
896f48298d3SIoana Ciornei  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
897f48298d3SIoana Ciornei  * @token:	Token of DPSW object
898f48298d3SIoana Ciornei  * @fdb_id:	Forwarding Database Identifier
899f48298d3SIoana Ciornei  *
900f48298d3SIoana Ciornei  * Return:	Completion status. '0' on Success; Error code otherwise.
901f48298d3SIoana Ciornei  */
dpsw_fdb_remove(struct fsl_mc_io * mc_io,u32 cmd_flags,u16 token,u16 fdb_id)902f48298d3SIoana Ciornei int dpsw_fdb_remove(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token, u16 fdb_id)
903f48298d3SIoana Ciornei {
904f48298d3SIoana Ciornei 	struct dpsw_cmd_fdb_remove *cmd_params;
905f48298d3SIoana Ciornei 	struct fsl_mc_command cmd = { 0 };
906f48298d3SIoana Ciornei 
907f48298d3SIoana Ciornei 	/* prepare command */
908f48298d3SIoana Ciornei 	cmd.header = mc_encode_cmd_header(DPSW_CMDID_FDB_REMOVE,
909f48298d3SIoana Ciornei 					  cmd_flags,
910f48298d3SIoana Ciornei 					  token);
911f48298d3SIoana Ciornei 	cmd_params = (struct dpsw_cmd_fdb_remove *)cmd.params;
912f48298d3SIoana Ciornei 	cmd_params->fdb_id = cpu_to_le16(fdb_id);
913f48298d3SIoana Ciornei 
914f48298d3SIoana Ciornei 	return mc_send_command(mc_io, &cmd);
915f48298d3SIoana Ciornei }
916f48298d3SIoana Ciornei 
917f48298d3SIoana Ciornei /**
918f48298d3SIoana Ciornei  * dpsw_fdb_add_unicast() - Function adds an unicast entry into MAC lookup table
919f48298d3SIoana Ciornei  * @mc_io:	Pointer to MC portal's I/O object
920f48298d3SIoana Ciornei  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
921f48298d3SIoana Ciornei  * @token:	Token of DPSW object
922f48298d3SIoana Ciornei  * @fdb_id:	Forwarding Database Identifier
923f48298d3SIoana Ciornei  * @cfg:	Unicast entry configuration
924f48298d3SIoana Ciornei  *
925f48298d3SIoana Ciornei  * Return:	Completion status. '0' on Success; Error code otherwise.
926f48298d3SIoana Ciornei  */
dpsw_fdb_add_unicast(struct fsl_mc_io * mc_io,u32 cmd_flags,u16 token,u16 fdb_id,const struct dpsw_fdb_unicast_cfg * cfg)9275ac2d254SIoana Ciornei int dpsw_fdb_add_unicast(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
9285ac2d254SIoana Ciornei 			 u16 fdb_id, const struct dpsw_fdb_unicast_cfg *cfg)
929f48298d3SIoana Ciornei {
930f48298d3SIoana Ciornei 	struct fsl_mc_command cmd = { 0 };
931f48298d3SIoana Ciornei 	struct dpsw_cmd_fdb_unicast_op *cmd_params;
932f48298d3SIoana Ciornei 	int i;
933f48298d3SIoana Ciornei 
934f48298d3SIoana Ciornei 	/* prepare command */
935f48298d3SIoana Ciornei 	cmd.header = mc_encode_cmd_header(DPSW_CMDID_FDB_ADD_UNICAST,
936f48298d3SIoana Ciornei 					  cmd_flags,
937f48298d3SIoana Ciornei 					  token);
938f48298d3SIoana Ciornei 	cmd_params = (struct dpsw_cmd_fdb_unicast_op *)cmd.params;
939f48298d3SIoana Ciornei 	cmd_params->fdb_id = cpu_to_le16(fdb_id);
940f48298d3SIoana Ciornei 	cmd_params->if_egress = cpu_to_le16(cfg->if_egress);
941f48298d3SIoana Ciornei 	for (i = 0; i < 6; i++)
942f48298d3SIoana Ciornei 		cmd_params->mac_addr[i] = cfg->mac_addr[5 - i];
943f48298d3SIoana Ciornei 	dpsw_set_field(cmd_params->type, ENTRY_TYPE, cfg->type);
944f48298d3SIoana Ciornei 
945f48298d3SIoana Ciornei 	/* send command to mc*/
946f48298d3SIoana Ciornei 	return mc_send_command(mc_io, &cmd);
947f48298d3SIoana Ciornei }
948f48298d3SIoana Ciornei 
949f48298d3SIoana Ciornei /**
950f48298d3SIoana Ciornei  * dpsw_fdb_dump() - Dump the content of FDB table into memory.
951f48298d3SIoana Ciornei  * @mc_io:	Pointer to MC portal's I/O object
952f48298d3SIoana Ciornei  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
953f48298d3SIoana Ciornei  * @token:	Token of DPSW object
954f48298d3SIoana Ciornei  * @fdb_id:	Forwarding Database Identifier
955f48298d3SIoana Ciornei  * @iova_addr:	Data will be stored here as an array of struct fdb_dump_entry
956f48298d3SIoana Ciornei  * @iova_size:	Memory size allocated at iova_addr
957f48298d3SIoana Ciornei  * @num_entries:Number of entries written at iova_addr
958f48298d3SIoana Ciornei  *
959f48298d3SIoana Ciornei  * Return:	Completion status. '0' on Success; Error code otherwise.
960f48298d3SIoana Ciornei  *
961f48298d3SIoana Ciornei  * The memory allocated at iova_addr must be initialized with zero before
962f48298d3SIoana Ciornei  * command execution. If the FDB table does not fit into memory MC will stop
963f48298d3SIoana Ciornei  * after the memory is filled up.
964f48298d3SIoana Ciornei  * The struct fdb_dump_entry array must be parsed until the end of memory
965f48298d3SIoana Ciornei  * area or until an entry with mac_addr set to zero is found.
966f48298d3SIoana Ciornei  */
dpsw_fdb_dump(struct fsl_mc_io * mc_io,u32 cmd_flags,u16 token,u16 fdb_id,u64 iova_addr,u32 iova_size,u16 * num_entries)9675ac2d254SIoana Ciornei int dpsw_fdb_dump(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token, u16 fdb_id,
9685ac2d254SIoana Ciornei 		  u64 iova_addr, u32 iova_size, u16 *num_entries)
969f48298d3SIoana Ciornei {
970f48298d3SIoana Ciornei 	struct dpsw_cmd_fdb_dump *cmd_params;
971f48298d3SIoana Ciornei 	struct dpsw_rsp_fdb_dump *rsp_params;
972f48298d3SIoana Ciornei 	struct fsl_mc_command cmd = { 0 };
973f48298d3SIoana Ciornei 	int err;
974f48298d3SIoana Ciornei 
975f48298d3SIoana Ciornei 	/* prepare command */
976f48298d3SIoana Ciornei 	cmd.header = mc_encode_cmd_header(DPSW_CMDID_FDB_DUMP,
977f48298d3SIoana Ciornei 					  cmd_flags,
978f48298d3SIoana Ciornei 					  token);
979f48298d3SIoana Ciornei 	cmd_params = (struct dpsw_cmd_fdb_dump *)cmd.params;
980f48298d3SIoana Ciornei 	cmd_params->fdb_id = cpu_to_le16(fdb_id);
981f48298d3SIoana Ciornei 	cmd_params->iova_addr = cpu_to_le64(iova_addr);
982f48298d3SIoana Ciornei 	cmd_params->iova_size = cpu_to_le32(iova_size);
983f48298d3SIoana Ciornei 
984f48298d3SIoana Ciornei 	/* send command to mc */
985f48298d3SIoana Ciornei 	err = mc_send_command(mc_io, &cmd);
986f48298d3SIoana Ciornei 	if (err)
987f48298d3SIoana Ciornei 		return err;
988f48298d3SIoana Ciornei 
989f48298d3SIoana Ciornei 	rsp_params = (struct dpsw_rsp_fdb_dump *)cmd.params;
990f48298d3SIoana Ciornei 	*num_entries = le16_to_cpu(rsp_params->num_entries);
991f48298d3SIoana Ciornei 
992f48298d3SIoana Ciornei 	return 0;
993f48298d3SIoana Ciornei }
994f48298d3SIoana Ciornei 
995f48298d3SIoana Ciornei /**
996f48298d3SIoana Ciornei  * dpsw_fdb_remove_unicast() - removes an entry from MAC lookup table
997f48298d3SIoana Ciornei  * @mc_io:	Pointer to MC portal's I/O object
998f48298d3SIoana Ciornei  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
999f48298d3SIoana Ciornei  * @token:	Token of DPSW object
1000f48298d3SIoana Ciornei  * @fdb_id:	Forwarding Database Identifier
1001f48298d3SIoana Ciornei  * @cfg:	Unicast entry configuration
1002f48298d3SIoana Ciornei  *
1003f48298d3SIoana Ciornei  * Return:	Completion status. '0' on Success; Error code otherwise.
1004f48298d3SIoana Ciornei  */
dpsw_fdb_remove_unicast(struct fsl_mc_io * mc_io,u32 cmd_flags,u16 token,u16 fdb_id,const struct dpsw_fdb_unicast_cfg * cfg)10055ac2d254SIoana Ciornei int dpsw_fdb_remove_unicast(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
10065ac2d254SIoana Ciornei 			    u16 fdb_id, const struct dpsw_fdb_unicast_cfg *cfg)
1007f48298d3SIoana Ciornei {
1008f48298d3SIoana Ciornei 	struct fsl_mc_command cmd = { 0 };
1009f48298d3SIoana Ciornei 	struct dpsw_cmd_fdb_unicast_op *cmd_params;
1010f48298d3SIoana Ciornei 	int i;
1011f48298d3SIoana Ciornei 
1012f48298d3SIoana Ciornei 	/* prepare command */
1013f48298d3SIoana Ciornei 	cmd.header = mc_encode_cmd_header(DPSW_CMDID_FDB_REMOVE_UNICAST,
1014f48298d3SIoana Ciornei 					  cmd_flags,
1015f48298d3SIoana Ciornei 					  token);
1016f48298d3SIoana Ciornei 	cmd_params = (struct dpsw_cmd_fdb_unicast_op *)cmd.params;
1017f48298d3SIoana Ciornei 	cmd_params->fdb_id = cpu_to_le16(fdb_id);
1018f48298d3SIoana Ciornei 	for (i = 0; i < 6; i++)
1019f48298d3SIoana Ciornei 		cmd_params->mac_addr[i] = cfg->mac_addr[5 - i];
1020f48298d3SIoana Ciornei 	cmd_params->if_egress = cpu_to_le16(cfg->if_egress);
1021f48298d3SIoana Ciornei 	dpsw_set_field(cmd_params->type, ENTRY_TYPE, cfg->type);
1022f48298d3SIoana Ciornei 
1023f48298d3SIoana Ciornei 	/* send command to mc*/
1024f48298d3SIoana Ciornei 	return mc_send_command(mc_io, &cmd);
1025f48298d3SIoana Ciornei }
1026f48298d3SIoana Ciornei 
1027f48298d3SIoana Ciornei /**
1028f48298d3SIoana Ciornei  * dpsw_fdb_add_multicast() - Add a set of egress interfaces to multi-cast group
1029f48298d3SIoana Ciornei  * @mc_io:	Pointer to MC portal's I/O object
1030f48298d3SIoana Ciornei  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
1031f48298d3SIoana Ciornei  * @token:	Token of DPSW object
1032f48298d3SIoana Ciornei  * @fdb_id:	Forwarding Database Identifier
1033f48298d3SIoana Ciornei  * @cfg:	Multicast entry configuration
1034f48298d3SIoana Ciornei  *
1035f48298d3SIoana Ciornei  * If group doesn't exist, it will be created.
1036f48298d3SIoana Ciornei  * It adds only interfaces not belonging to this multicast group
1037f48298d3SIoana Ciornei  * yet, otherwise error will be generated and the command is
1038f48298d3SIoana Ciornei  * ignored.
1039f48298d3SIoana Ciornei  * This function may be called numerous times always providing
1040f48298d3SIoana Ciornei  * required interfaces delta.
1041f48298d3SIoana Ciornei  *
1042f48298d3SIoana Ciornei  * Return:	Completion status. '0' on Success; Error code otherwise.
1043f48298d3SIoana Ciornei  */
dpsw_fdb_add_multicast(struct fsl_mc_io * mc_io,u32 cmd_flags,u16 token,u16 fdb_id,const struct dpsw_fdb_multicast_cfg * cfg)10445ac2d254SIoana Ciornei int dpsw_fdb_add_multicast(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
10455ac2d254SIoana Ciornei 			   u16 fdb_id, const struct dpsw_fdb_multicast_cfg *cfg)
1046f48298d3SIoana Ciornei {
1047f48298d3SIoana Ciornei 	struct fsl_mc_command cmd = { 0 };
1048f48298d3SIoana Ciornei 	struct dpsw_cmd_fdb_multicast_op *cmd_params;
1049f48298d3SIoana Ciornei 	int i;
1050f48298d3SIoana Ciornei 
1051f48298d3SIoana Ciornei 	/* prepare command */
1052f48298d3SIoana Ciornei 	cmd.header = mc_encode_cmd_header(DPSW_CMDID_FDB_ADD_MULTICAST,
1053f48298d3SIoana Ciornei 					  cmd_flags,
1054f48298d3SIoana Ciornei 					  token);
1055f48298d3SIoana Ciornei 	cmd_params = (struct dpsw_cmd_fdb_multicast_op *)cmd.params;
1056f48298d3SIoana Ciornei 	cmd_params->fdb_id = cpu_to_le16(fdb_id);
1057f48298d3SIoana Ciornei 	cmd_params->num_ifs = cpu_to_le16(cfg->num_ifs);
1058f48298d3SIoana Ciornei 	dpsw_set_field(cmd_params->type, ENTRY_TYPE, cfg->type);
10592b7e3f7dSIoana Ciornei 	build_if_id_bitmap(&cmd_params->if_id, cfg->if_id, cfg->num_ifs);
1060f48298d3SIoana Ciornei 	for (i = 0; i < 6; i++)
1061f48298d3SIoana Ciornei 		cmd_params->mac_addr[i] = cfg->mac_addr[5 - i];
1062f48298d3SIoana Ciornei 
1063f48298d3SIoana Ciornei 	/* send command to mc*/
1064f48298d3SIoana Ciornei 	return mc_send_command(mc_io, &cmd);
1065f48298d3SIoana Ciornei }
1066f48298d3SIoana Ciornei 
1067f48298d3SIoana Ciornei /**
1068f48298d3SIoana Ciornei  * dpsw_fdb_remove_multicast() - Removing interfaces from an existing multicast
1069f48298d3SIoana Ciornei  *				group.
1070f48298d3SIoana Ciornei  * @mc_io:	Pointer to MC portal's I/O object
1071f48298d3SIoana Ciornei  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
1072f48298d3SIoana Ciornei  * @token:	Token of DPSW object
1073f48298d3SIoana Ciornei  * @fdb_id:	Forwarding Database Identifier
1074f48298d3SIoana Ciornei  * @cfg:	Multicast entry configuration
1075f48298d3SIoana Ciornei  *
1076f48298d3SIoana Ciornei  * Interfaces provided by this API have to exist in the group,
1077f48298d3SIoana Ciornei  * otherwise an error will be returned and an entire command
1078f48298d3SIoana Ciornei  * ignored. If there is no interface left in the group,
1079f48298d3SIoana Ciornei  * an entire group is deleted
1080f48298d3SIoana Ciornei  *
1081f48298d3SIoana Ciornei  * Return:	Completion status. '0' on Success; Error code otherwise.
1082f48298d3SIoana Ciornei  */
dpsw_fdb_remove_multicast(struct fsl_mc_io * mc_io,u32 cmd_flags,u16 token,u16 fdb_id,const struct dpsw_fdb_multicast_cfg * cfg)10835ac2d254SIoana Ciornei int dpsw_fdb_remove_multicast(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
10845ac2d254SIoana Ciornei 			      u16 fdb_id, const struct dpsw_fdb_multicast_cfg *cfg)
1085f48298d3SIoana Ciornei {
1086f48298d3SIoana Ciornei 	struct fsl_mc_command cmd = { 0 };
1087f48298d3SIoana Ciornei 	struct dpsw_cmd_fdb_multicast_op *cmd_params;
1088f48298d3SIoana Ciornei 	int i;
1089f48298d3SIoana Ciornei 
1090f48298d3SIoana Ciornei 	/* prepare command */
1091f48298d3SIoana Ciornei 	cmd.header = mc_encode_cmd_header(DPSW_CMDID_FDB_REMOVE_MULTICAST,
1092f48298d3SIoana Ciornei 					  cmd_flags,
1093f48298d3SIoana Ciornei 					  token);
1094f48298d3SIoana Ciornei 	cmd_params = (struct dpsw_cmd_fdb_multicast_op *)cmd.params;
1095f48298d3SIoana Ciornei 	cmd_params->fdb_id = cpu_to_le16(fdb_id);
1096f48298d3SIoana Ciornei 	cmd_params->num_ifs = cpu_to_le16(cfg->num_ifs);
1097f48298d3SIoana Ciornei 	dpsw_set_field(cmd_params->type, ENTRY_TYPE, cfg->type);
10982b7e3f7dSIoana Ciornei 	build_if_id_bitmap(&cmd_params->if_id, cfg->if_id, cfg->num_ifs);
1099f48298d3SIoana Ciornei 	for (i = 0; i < 6; i++)
1100f48298d3SIoana Ciornei 		cmd_params->mac_addr[i] = cfg->mac_addr[5 - i];
1101f48298d3SIoana Ciornei 
1102f48298d3SIoana Ciornei 	/* send command to mc*/
1103f48298d3SIoana Ciornei 	return mc_send_command(mc_io, &cmd);
1104f48298d3SIoana Ciornei }
1105f48298d3SIoana Ciornei 
1106f48298d3SIoana Ciornei /**
1107f48298d3SIoana Ciornei  * dpsw_ctrl_if_get_attributes() - Obtain control interface attributes
1108f48298d3SIoana Ciornei  * @mc_io:	Pointer to MC portal's I/O object
1109f48298d3SIoana Ciornei  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
1110f48298d3SIoana Ciornei  * @token:	Token of DPSW object
1111f48298d3SIoana Ciornei  * @attr:	Returned control interface attributes
1112f48298d3SIoana Ciornei  *
1113f48298d3SIoana Ciornei  * Return:	'0' on Success; Error code otherwise.
1114f48298d3SIoana Ciornei  */
dpsw_ctrl_if_get_attributes(struct fsl_mc_io * mc_io,u32 cmd_flags,u16 token,struct dpsw_ctrl_if_attr * attr)1115f48298d3SIoana Ciornei int dpsw_ctrl_if_get_attributes(struct fsl_mc_io *mc_io, u32 cmd_flags,
1116f48298d3SIoana Ciornei 				u16 token, struct dpsw_ctrl_if_attr *attr)
1117f48298d3SIoana Ciornei {
1118f48298d3SIoana Ciornei 	struct dpsw_rsp_ctrl_if_get_attr *rsp_params;
1119f48298d3SIoana Ciornei 	struct fsl_mc_command cmd = { 0 };
1120f48298d3SIoana Ciornei 	int err;
1121f48298d3SIoana Ciornei 
1122f48298d3SIoana Ciornei 	cmd.header = mc_encode_cmd_header(DPSW_CMDID_CTRL_IF_GET_ATTR,
1123f48298d3SIoana Ciornei 					  cmd_flags, token);
1124f48298d3SIoana Ciornei 
1125f48298d3SIoana Ciornei 	err = mc_send_command(mc_io, &cmd);
1126f48298d3SIoana Ciornei 	if (err)
1127f48298d3SIoana Ciornei 		return err;
1128f48298d3SIoana Ciornei 
1129f48298d3SIoana Ciornei 	rsp_params = (struct dpsw_rsp_ctrl_if_get_attr *)cmd.params;
1130f48298d3SIoana Ciornei 	attr->rx_fqid = le32_to_cpu(rsp_params->rx_fqid);
1131f48298d3SIoana Ciornei 	attr->rx_err_fqid = le32_to_cpu(rsp_params->rx_err_fqid);
1132f48298d3SIoana Ciornei 	attr->tx_err_conf_fqid = le32_to_cpu(rsp_params->tx_err_conf_fqid);
1133f48298d3SIoana Ciornei 
1134f48298d3SIoana Ciornei 	return 0;
1135f48298d3SIoana Ciornei }
1136f48298d3SIoana Ciornei 
1137f48298d3SIoana Ciornei /**
1138f48298d3SIoana Ciornei  * dpsw_ctrl_if_set_pools() - Set control interface buffer pools
1139f48298d3SIoana Ciornei  * @mc_io:	Pointer to MC portal's I/O object
1140f48298d3SIoana Ciornei  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
1141f48298d3SIoana Ciornei  * @token:	Token of DPSW object
1142f48298d3SIoana Ciornei  * @cfg:	Buffer pools configuration
1143f48298d3SIoana Ciornei  *
1144f48298d3SIoana Ciornei  * Return:	'0' on Success; Error code otherwise.
1145f48298d3SIoana Ciornei  */
dpsw_ctrl_if_set_pools(struct fsl_mc_io * mc_io,u32 cmd_flags,u16 token,const struct dpsw_ctrl_if_pools_cfg * cfg)1146f48298d3SIoana Ciornei int dpsw_ctrl_if_set_pools(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
1147f48298d3SIoana Ciornei 			   const struct dpsw_ctrl_if_pools_cfg *cfg)
1148f48298d3SIoana Ciornei {
1149f48298d3SIoana Ciornei 	struct dpsw_cmd_ctrl_if_set_pools *cmd_params;
1150f48298d3SIoana Ciornei 	struct fsl_mc_command cmd = { 0 };
1151f48298d3SIoana Ciornei 	int i;
1152f48298d3SIoana Ciornei 
1153f48298d3SIoana Ciornei 	cmd.header = mc_encode_cmd_header(DPSW_CMDID_CTRL_IF_SET_POOLS,
1154f48298d3SIoana Ciornei 					  cmd_flags, token);
1155f48298d3SIoana Ciornei 	cmd_params = (struct dpsw_cmd_ctrl_if_set_pools *)cmd.params;
1156f48298d3SIoana Ciornei 	cmd_params->num_dpbp = cfg->num_dpbp;
1157f48298d3SIoana Ciornei 	for (i = 0; i < DPSW_MAX_DPBP; i++) {
1158f48298d3SIoana Ciornei 		cmd_params->dpbp_id[i] = cpu_to_le32(cfg->pools[i].dpbp_id);
1159f48298d3SIoana Ciornei 		cmd_params->buffer_size[i] =
1160f48298d3SIoana Ciornei 			cpu_to_le16(cfg->pools[i].buffer_size);
1161f48298d3SIoana Ciornei 		cmd_params->backup_pool_mask |=
1162f48298d3SIoana Ciornei 			DPSW_BACKUP_POOL(cfg->pools[i].backup_pool, i);
1163f48298d3SIoana Ciornei 	}
1164f48298d3SIoana Ciornei 
1165f48298d3SIoana Ciornei 	return mc_send_command(mc_io, &cmd);
1166f48298d3SIoana Ciornei }
1167f48298d3SIoana Ciornei 
1168f48298d3SIoana Ciornei /**
1169f48298d3SIoana Ciornei  * dpsw_ctrl_if_set_queue() - Set Rx queue configuration
1170f48298d3SIoana Ciornei  * @mc_io:	Pointer to MC portal's I/O object
1171f48298d3SIoana Ciornei  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
1172f48298d3SIoana Ciornei  * @token:	Token of dpsw object
1173f48298d3SIoana Ciornei  * @qtype:	dpsw_queue_type of the targeted queue
1174f48298d3SIoana Ciornei  * @cfg:	Rx queue configuration
1175f48298d3SIoana Ciornei  *
1176f48298d3SIoana Ciornei  * Return:	'0' on Success; Error code otherwise.
1177f48298d3SIoana Ciornei  */
dpsw_ctrl_if_set_queue(struct fsl_mc_io * mc_io,u32 cmd_flags,u16 token,enum dpsw_queue_type qtype,const struct dpsw_ctrl_if_queue_cfg * cfg)1178f48298d3SIoana Ciornei int dpsw_ctrl_if_set_queue(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
1179f48298d3SIoana Ciornei 			   enum dpsw_queue_type qtype,
1180f48298d3SIoana Ciornei 			   const struct dpsw_ctrl_if_queue_cfg *cfg)
1181f48298d3SIoana Ciornei {
1182f48298d3SIoana Ciornei 	struct dpsw_cmd_ctrl_if_set_queue *cmd_params;
1183f48298d3SIoana Ciornei 	struct fsl_mc_command cmd = { 0 };
1184f48298d3SIoana Ciornei 
1185f48298d3SIoana Ciornei 	cmd.header = mc_encode_cmd_header(DPSW_CMDID_CTRL_IF_SET_QUEUE,
1186f48298d3SIoana Ciornei 					  cmd_flags,
1187f48298d3SIoana Ciornei 					  token);
1188f48298d3SIoana Ciornei 	cmd_params = (struct dpsw_cmd_ctrl_if_set_queue *)cmd.params;
1189f48298d3SIoana Ciornei 	cmd_params->dest_id = cpu_to_le32(cfg->dest_cfg.dest_id);
1190f48298d3SIoana Ciornei 	cmd_params->dest_priority = cfg->dest_cfg.priority;
1191f48298d3SIoana Ciornei 	cmd_params->qtype = qtype;
1192f48298d3SIoana Ciornei 	cmd_params->user_ctx = cpu_to_le64(cfg->user_ctx);
1193f48298d3SIoana Ciornei 	cmd_params->options = cpu_to_le32(cfg->options);
1194f48298d3SIoana Ciornei 	dpsw_set_field(cmd_params->dest_type,
1195f48298d3SIoana Ciornei 		       DEST_TYPE,
1196f48298d3SIoana Ciornei 		       cfg->dest_cfg.dest_type);
1197f48298d3SIoana Ciornei 
1198f48298d3SIoana Ciornei 	return mc_send_command(mc_io, &cmd);
1199f48298d3SIoana Ciornei }
1200f48298d3SIoana Ciornei 
1201f48298d3SIoana Ciornei /**
1202f48298d3SIoana Ciornei  * dpsw_get_api_version() - Get Data Path Switch API version
1203f48298d3SIoana Ciornei  * @mc_io:	Pointer to MC portal's I/O object
1204f48298d3SIoana Ciornei  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
1205f48298d3SIoana Ciornei  * @major_ver:	Major version of data path switch API
1206f48298d3SIoana Ciornei  * @minor_ver:	Minor version of data path switch API
1207f48298d3SIoana Ciornei  *
1208f48298d3SIoana Ciornei  * Return:  '0' on Success; Error code otherwise.
1209f48298d3SIoana Ciornei  */
dpsw_get_api_version(struct fsl_mc_io * mc_io,u32 cmd_flags,u16 * major_ver,u16 * minor_ver)12105ac2d254SIoana Ciornei int dpsw_get_api_version(struct fsl_mc_io *mc_io, u32 cmd_flags,
12115ac2d254SIoana Ciornei 			 u16 *major_ver, u16 *minor_ver)
1212f48298d3SIoana Ciornei {
1213f48298d3SIoana Ciornei 	struct fsl_mc_command cmd = { 0 };
1214f48298d3SIoana Ciornei 	struct dpsw_rsp_get_api_version *rsp_params;
1215f48298d3SIoana Ciornei 	int err;
1216f48298d3SIoana Ciornei 
1217f48298d3SIoana Ciornei 	cmd.header = mc_encode_cmd_header(DPSW_CMDID_GET_API_VERSION,
1218f48298d3SIoana Ciornei 					  cmd_flags,
1219f48298d3SIoana Ciornei 					  0);
1220f48298d3SIoana Ciornei 
1221f48298d3SIoana Ciornei 	err = mc_send_command(mc_io, &cmd);
1222f48298d3SIoana Ciornei 	if (err)
1223f48298d3SIoana Ciornei 		return err;
1224f48298d3SIoana Ciornei 
1225f48298d3SIoana Ciornei 	rsp_params = (struct dpsw_rsp_get_api_version *)cmd.params;
1226f48298d3SIoana Ciornei 	*major_ver = le16_to_cpu(rsp_params->version_major);
1227f48298d3SIoana Ciornei 	*minor_ver = le16_to_cpu(rsp_params->version_minor);
1228f48298d3SIoana Ciornei 
1229f48298d3SIoana Ciornei 	return 0;
1230f48298d3SIoana Ciornei }
1231f48298d3SIoana Ciornei 
1232f48298d3SIoana Ciornei /**
123305b36360SIoana Ciornei  * dpsw_if_get_port_mac_addr() - Retrieve MAC address associated to the physical port
1234f48298d3SIoana Ciornei  * @mc_io:	Pointer to MC portal's I/O object
1235f48298d3SIoana Ciornei  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
1236f48298d3SIoana Ciornei  * @token:	Token of DPSW object
1237f48298d3SIoana Ciornei  * @if_id:	Interface Identifier
1238f48298d3SIoana Ciornei  * @mac_addr:	MAC address of the physical port, if any, otherwise 0
1239f48298d3SIoana Ciornei  *
1240f48298d3SIoana Ciornei  * Return:	Completion status. '0' on Success; Error code otherwise.
1241f48298d3SIoana Ciornei  */
dpsw_if_get_port_mac_addr(struct fsl_mc_io * mc_io,u32 cmd_flags,u16 token,u16 if_id,u8 mac_addr[6])1242f48298d3SIoana Ciornei int dpsw_if_get_port_mac_addr(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
1243f48298d3SIoana Ciornei 			      u16 if_id, u8 mac_addr[6])
1244f48298d3SIoana Ciornei {
1245f48298d3SIoana Ciornei 	struct dpsw_rsp_if_get_mac_addr *rsp_params;
1246f48298d3SIoana Ciornei 	struct fsl_mc_command cmd = { 0 };
1247f48298d3SIoana Ciornei 	struct dpsw_cmd_if *cmd_params;
1248f48298d3SIoana Ciornei 	int err, i;
1249f48298d3SIoana Ciornei 
1250f48298d3SIoana Ciornei 	/* prepare command */
1251f48298d3SIoana Ciornei 	cmd.header = mc_encode_cmd_header(DPSW_CMDID_IF_GET_PORT_MAC_ADDR,
1252f48298d3SIoana Ciornei 					  cmd_flags,
1253f48298d3SIoana Ciornei 					  token);
1254f48298d3SIoana Ciornei 	cmd_params = (struct dpsw_cmd_if *)cmd.params;
1255f48298d3SIoana Ciornei 	cmd_params->if_id = cpu_to_le16(if_id);
1256f48298d3SIoana Ciornei 
1257f48298d3SIoana Ciornei 	/* send command to mc*/
1258f48298d3SIoana Ciornei 	err = mc_send_command(mc_io, &cmd);
1259f48298d3SIoana Ciornei 	if (err)
1260f48298d3SIoana Ciornei 		return err;
1261f48298d3SIoana Ciornei 
1262f48298d3SIoana Ciornei 	/* retrieve response parameters */
1263f48298d3SIoana Ciornei 	rsp_params = (struct dpsw_rsp_if_get_mac_addr *)cmd.params;
1264f48298d3SIoana Ciornei 	for (i = 0; i < 6; i++)
1265f48298d3SIoana Ciornei 		mac_addr[5 - i] = rsp_params->mac_addr[i];
1266f48298d3SIoana Ciornei 
1267f48298d3SIoana Ciornei 	return 0;
1268f48298d3SIoana Ciornei }
1269f48298d3SIoana Ciornei 
1270f48298d3SIoana Ciornei /**
1271f48298d3SIoana Ciornei  * dpsw_ctrl_if_enable() - Enable control interface
1272f48298d3SIoana Ciornei  * @mc_io:	Pointer to MC portal's I/O object
1273f48298d3SIoana Ciornei  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
1274f48298d3SIoana Ciornei  * @token:	Token of DPSW object
1275f48298d3SIoana Ciornei  *
1276f48298d3SIoana Ciornei  * Return:	'0' on Success; Error code otherwise.
1277f48298d3SIoana Ciornei  */
dpsw_ctrl_if_enable(struct fsl_mc_io * mc_io,u32 cmd_flags,u16 token)1278f48298d3SIoana Ciornei int dpsw_ctrl_if_enable(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token)
1279f48298d3SIoana Ciornei {
1280f48298d3SIoana Ciornei 	struct fsl_mc_command cmd = { 0 };
1281f48298d3SIoana Ciornei 
1282f48298d3SIoana Ciornei 	cmd.header = mc_encode_cmd_header(DPSW_CMDID_CTRL_IF_ENABLE, cmd_flags,
1283f48298d3SIoana Ciornei 					  token);
1284f48298d3SIoana Ciornei 
1285f48298d3SIoana Ciornei 	return mc_send_command(mc_io, &cmd);
1286f48298d3SIoana Ciornei }
1287f48298d3SIoana Ciornei 
1288f48298d3SIoana Ciornei /**
1289f48298d3SIoana Ciornei  * dpsw_ctrl_if_disable() - Function disables control interface
1290f48298d3SIoana Ciornei  * @mc_io:	Pointer to MC portal's I/O object
1291f48298d3SIoana Ciornei  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
1292f48298d3SIoana Ciornei  * @token:	Token of DPSW object
1293f48298d3SIoana Ciornei  *
1294f48298d3SIoana Ciornei  * Return:	'0' on Success; Error code otherwise.
1295f48298d3SIoana Ciornei  */
dpsw_ctrl_if_disable(struct fsl_mc_io * mc_io,u32 cmd_flags,u16 token)1296f48298d3SIoana Ciornei int dpsw_ctrl_if_disable(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token)
1297f48298d3SIoana Ciornei {
1298f48298d3SIoana Ciornei 	struct fsl_mc_command cmd = { 0 };
1299f48298d3SIoana Ciornei 
1300f48298d3SIoana Ciornei 	cmd.header = mc_encode_cmd_header(DPSW_CMDID_CTRL_IF_DISABLE,
1301f48298d3SIoana Ciornei 					  cmd_flags,
1302f48298d3SIoana Ciornei 					  token);
1303f48298d3SIoana Ciornei 
1304f48298d3SIoana Ciornei 	return mc_send_command(mc_io, &cmd);
1305f48298d3SIoana Ciornei }
1306f48298d3SIoana Ciornei 
1307f48298d3SIoana Ciornei /**
1308f48298d3SIoana Ciornei  * dpsw_set_egress_flood() - Set egress parameters associated with an FDB ID
1309f48298d3SIoana Ciornei  * @mc_io:	Pointer to MC portal's I/O object
1310f48298d3SIoana Ciornei  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
1311f48298d3SIoana Ciornei  * @token:	Token of DPSW object
1312f48298d3SIoana Ciornei  * @cfg:	Egress flooding configuration
1313f48298d3SIoana Ciornei  *
1314f48298d3SIoana Ciornei  * Return:	'0' on Success; Error code otherwise.
1315f48298d3SIoana Ciornei  */
dpsw_set_egress_flood(struct fsl_mc_io * mc_io,u32 cmd_flags,u16 token,const struct dpsw_egress_flood_cfg * cfg)1316f48298d3SIoana Ciornei int dpsw_set_egress_flood(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
1317f48298d3SIoana Ciornei 			  const struct dpsw_egress_flood_cfg *cfg)
1318f48298d3SIoana Ciornei {
1319f48298d3SIoana Ciornei 	struct dpsw_cmd_set_egress_flood *cmd_params;
1320f48298d3SIoana Ciornei 	struct fsl_mc_command cmd = { 0 };
1321f48298d3SIoana Ciornei 
1322f48298d3SIoana Ciornei 	cmd.header = mc_encode_cmd_header(DPSW_CMDID_SET_EGRESS_FLOOD, cmd_flags, token);
1323f48298d3SIoana Ciornei 	cmd_params = (struct dpsw_cmd_set_egress_flood *)cmd.params;
1324f48298d3SIoana Ciornei 	cmd_params->fdb_id = cpu_to_le16(cfg->fdb_id);
1325f48298d3SIoana Ciornei 	cmd_params->flood_type = cfg->flood_type;
1326f48298d3SIoana Ciornei 	build_if_id_bitmap(&cmd_params->if_id, cfg->if_id, cfg->num_ifs);
1327f48298d3SIoana Ciornei 
1328f48298d3SIoana Ciornei 	return mc_send_command(mc_io, &cmd);
1329f48298d3SIoana Ciornei }
13301e7cbabfSIoana Ciornei 
13311e7cbabfSIoana Ciornei /**
13321e7cbabfSIoana Ciornei  * dpsw_if_set_learning_mode() - Configure the learning mode on an interface.
13331e7cbabfSIoana Ciornei  * If this API is used, it will take precedence over the FDB configuration.
13341e7cbabfSIoana Ciornei  * @mc_io:	Pointer to MC portal's I/O object
13351e7cbabfSIoana Ciornei  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
13361e7cbabfSIoana Ciornei  * @token:	Token of DPSW object
13371e7cbabfSIoana Ciornei  * @if_id:	InterfaceID
13381e7cbabfSIoana Ciornei  * @mode:	Learning mode
13391e7cbabfSIoana Ciornei  *
13401e7cbabfSIoana Ciornei  * Return:	Completion status. '0' on Success; Error code otherwise.
13411e7cbabfSIoana Ciornei  */
dpsw_if_set_learning_mode(struct fsl_mc_io * mc_io,u32 cmd_flags,u16 token,u16 if_id,enum dpsw_learning_mode mode)13421e7cbabfSIoana Ciornei int dpsw_if_set_learning_mode(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
13431e7cbabfSIoana Ciornei 			      u16 if_id, enum dpsw_learning_mode mode)
13441e7cbabfSIoana Ciornei {
13451e7cbabfSIoana Ciornei 	struct dpsw_cmd_if_set_learning_mode *cmd_params;
13461e7cbabfSIoana Ciornei 	struct fsl_mc_command cmd = { 0 };
13471e7cbabfSIoana Ciornei 
13481e7cbabfSIoana Ciornei 	cmd.header = mc_encode_cmd_header(DPSW_CMDID_IF_SET_LEARNING_MODE,
13491e7cbabfSIoana Ciornei 					  cmd_flags,
13501e7cbabfSIoana Ciornei 					  token);
13511e7cbabfSIoana Ciornei 	cmd_params = (struct dpsw_cmd_if_set_learning_mode *)cmd.params;
13521e7cbabfSIoana Ciornei 	cmd_params->if_id = cpu_to_le16(if_id);
13531e7cbabfSIoana Ciornei 	dpsw_set_field(cmd_params->mode, LEARNING_MODE, mode);
13541e7cbabfSIoana Ciornei 
13551e7cbabfSIoana Ciornei 	return mc_send_command(mc_io, &cmd);
13561e7cbabfSIoana Ciornei }
135790f07102SIoana Ciornei 
135890f07102SIoana Ciornei /**
135990f07102SIoana Ciornei  * dpsw_acl_add() - Create an ACL table
136090f07102SIoana Ciornei  * @mc_io:	Pointer to MC portal's I/O object
136190f07102SIoana Ciornei  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
136290f07102SIoana Ciornei  * @token:	Token of DPSW object
136390f07102SIoana Ciornei  * @acl_id:	Returned ACL ID, for future references
136490f07102SIoana Ciornei  * @cfg:	ACL configuration
136590f07102SIoana Ciornei  *
136690f07102SIoana Ciornei  * Create Access Control List table. Multiple ACLs can be created and
136790f07102SIoana Ciornei  * co-exist in L2 switch
136890f07102SIoana Ciornei  *
136990f07102SIoana Ciornei  * Return:	'0' on Success; Error code otherwise.
137090f07102SIoana Ciornei  */
dpsw_acl_add(struct fsl_mc_io * mc_io,u32 cmd_flags,u16 token,u16 * acl_id,const struct dpsw_acl_cfg * cfg)137190f07102SIoana Ciornei int dpsw_acl_add(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token, u16 *acl_id,
137290f07102SIoana Ciornei 		 const struct dpsw_acl_cfg *cfg)
137390f07102SIoana Ciornei {
137490f07102SIoana Ciornei 	struct dpsw_cmd_acl_add *cmd_params;
137590f07102SIoana Ciornei 	struct dpsw_rsp_acl_add *rsp_params;
137690f07102SIoana Ciornei 	struct fsl_mc_command cmd = { 0 };
137790f07102SIoana Ciornei 	int err;
137890f07102SIoana Ciornei 
137990f07102SIoana Ciornei 	cmd.header = mc_encode_cmd_header(DPSW_CMDID_ACL_ADD, cmd_flags, token);
138090f07102SIoana Ciornei 	cmd_params = (struct dpsw_cmd_acl_add *)cmd.params;
138190f07102SIoana Ciornei 	cmd_params->max_entries = cpu_to_le16(cfg->max_entries);
138290f07102SIoana Ciornei 
138390f07102SIoana Ciornei 	err = mc_send_command(mc_io, &cmd);
138490f07102SIoana Ciornei 	if (err)
138590f07102SIoana Ciornei 		return err;
138690f07102SIoana Ciornei 
138790f07102SIoana Ciornei 	rsp_params = (struct dpsw_rsp_acl_add *)cmd.params;
138890f07102SIoana Ciornei 	*acl_id = le16_to_cpu(rsp_params->acl_id);
138990f07102SIoana Ciornei 
139090f07102SIoana Ciornei 	return 0;
139190f07102SIoana Ciornei }
139290f07102SIoana Ciornei 
139390f07102SIoana Ciornei /**
139490f07102SIoana Ciornei  * dpsw_acl_remove() - Remove an ACL table from L2 switch.
139590f07102SIoana Ciornei  * @mc_io:	Pointer to MC portal's I/O object
139690f07102SIoana Ciornei  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
139790f07102SIoana Ciornei  * @token:	Token of DPSW object
139890f07102SIoana Ciornei  * @acl_id:	ACL ID
139990f07102SIoana Ciornei  *
140090f07102SIoana Ciornei  * Return:	'0' on Success; Error code otherwise.
140190f07102SIoana Ciornei  */
dpsw_acl_remove(struct fsl_mc_io * mc_io,u32 cmd_flags,u16 token,u16 acl_id)140290f07102SIoana Ciornei int dpsw_acl_remove(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
140390f07102SIoana Ciornei 		    u16 acl_id)
140490f07102SIoana Ciornei {
140590f07102SIoana Ciornei 	struct dpsw_cmd_acl_remove *cmd_params;
140690f07102SIoana Ciornei 	struct fsl_mc_command cmd = { 0 };
140790f07102SIoana Ciornei 
140890f07102SIoana Ciornei 	cmd.header = mc_encode_cmd_header(DPSW_CMDID_ACL_REMOVE, cmd_flags,
140990f07102SIoana Ciornei 					  token);
141090f07102SIoana Ciornei 	cmd_params = (struct dpsw_cmd_acl_remove *)cmd.params;
141190f07102SIoana Ciornei 	cmd_params->acl_id = cpu_to_le16(acl_id);
141290f07102SIoana Ciornei 
141390f07102SIoana Ciornei 	return mc_send_command(mc_io, &cmd);
141490f07102SIoana Ciornei }
141590f07102SIoana Ciornei 
141690f07102SIoana Ciornei /**
141790f07102SIoana Ciornei  * dpsw_acl_add_if() - Associate interface/interfaces with an ACL table.
141890f07102SIoana Ciornei  * @mc_io:	Pointer to MC portal's I/O object
141990f07102SIoana Ciornei  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
142090f07102SIoana Ciornei  * @token:	Token of DPSW object
142190f07102SIoana Ciornei  * @acl_id:	ACL ID
142290f07102SIoana Ciornei  * @cfg:	Interfaces list
142390f07102SIoana Ciornei  *
142490f07102SIoana Ciornei  * Return:	'0' on Success; Error code otherwise.
142590f07102SIoana Ciornei  */
dpsw_acl_add_if(struct fsl_mc_io * mc_io,u32 cmd_flags,u16 token,u16 acl_id,const struct dpsw_acl_if_cfg * cfg)142690f07102SIoana Ciornei int dpsw_acl_add_if(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
142790f07102SIoana Ciornei 		    u16 acl_id, const struct dpsw_acl_if_cfg *cfg)
142890f07102SIoana Ciornei {
142990f07102SIoana Ciornei 	struct dpsw_cmd_acl_if *cmd_params;
143090f07102SIoana Ciornei 	struct fsl_mc_command cmd = { 0 };
143190f07102SIoana Ciornei 
143290f07102SIoana Ciornei 	cmd.header = mc_encode_cmd_header(DPSW_CMDID_ACL_ADD_IF, cmd_flags,
143390f07102SIoana Ciornei 					  token);
143490f07102SIoana Ciornei 	cmd_params = (struct dpsw_cmd_acl_if *)cmd.params;
143590f07102SIoana Ciornei 	cmd_params->acl_id = cpu_to_le16(acl_id);
143690f07102SIoana Ciornei 	cmd_params->num_ifs = cpu_to_le16(cfg->num_ifs);
143790f07102SIoana Ciornei 	build_if_id_bitmap(&cmd_params->if_id, cfg->if_id, cfg->num_ifs);
143890f07102SIoana Ciornei 
143990f07102SIoana Ciornei 	return mc_send_command(mc_io, &cmd);
144090f07102SIoana Ciornei }
144190f07102SIoana Ciornei 
144290f07102SIoana Ciornei /**
144390f07102SIoana Ciornei  * dpsw_acl_remove_if() - De-associate interface/interfaces from an ACL table
144490f07102SIoana Ciornei  * @mc_io:	Pointer to MC portal's I/O object
144590f07102SIoana Ciornei  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
144690f07102SIoana Ciornei  * @token:	Token of DPSW object
144790f07102SIoana Ciornei  * @acl_id:	ACL ID
144890f07102SIoana Ciornei  * @cfg:	Interfaces list
144990f07102SIoana Ciornei  *
145090f07102SIoana Ciornei  * Return:	'0' on Success; Error code otherwise.
145190f07102SIoana Ciornei  */
dpsw_acl_remove_if(struct fsl_mc_io * mc_io,u32 cmd_flags,u16 token,u16 acl_id,const struct dpsw_acl_if_cfg * cfg)145290f07102SIoana Ciornei int dpsw_acl_remove_if(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
145390f07102SIoana Ciornei 		       u16 acl_id, const struct dpsw_acl_if_cfg *cfg)
145490f07102SIoana Ciornei {
145590f07102SIoana Ciornei 	struct dpsw_cmd_acl_if *cmd_params;
145690f07102SIoana Ciornei 	struct fsl_mc_command cmd = { 0 };
145790f07102SIoana Ciornei 
145890f07102SIoana Ciornei 	/* prepare command */
145990f07102SIoana Ciornei 	cmd.header = mc_encode_cmd_header(DPSW_CMDID_ACL_REMOVE_IF, cmd_flags,
146090f07102SIoana Ciornei 					  token);
146190f07102SIoana Ciornei 	cmd_params = (struct dpsw_cmd_acl_if *)cmd.params;
146290f07102SIoana Ciornei 	cmd_params->acl_id = cpu_to_le16(acl_id);
146390f07102SIoana Ciornei 	cmd_params->num_ifs = cpu_to_le16(cfg->num_ifs);
146490f07102SIoana Ciornei 	build_if_id_bitmap(&cmd_params->if_id, cfg->if_id, cfg->num_ifs);
146590f07102SIoana Ciornei 
146690f07102SIoana Ciornei 	/* send command to mc*/
146790f07102SIoana Ciornei 	return mc_send_command(mc_io, &cmd);
146890f07102SIoana Ciornei }
14691a64ed12SIoana Ciornei 
14701a64ed12SIoana Ciornei /**
14711a64ed12SIoana Ciornei  * dpsw_acl_prepare_entry_cfg() - Setup an ACL entry
14721a64ed12SIoana Ciornei  * @key:		Key
14731a64ed12SIoana Ciornei  * @entry_cfg_buf:	Zeroed 256 bytes of memory before mapping it to DMA
14741a64ed12SIoana Ciornei  *
14751a64ed12SIoana Ciornei  * This function has to be called before adding or removing acl_entry
14761a64ed12SIoana Ciornei  *
14771a64ed12SIoana Ciornei  */
dpsw_acl_prepare_entry_cfg(const struct dpsw_acl_key * key,u8 * entry_cfg_buf)14781a64ed12SIoana Ciornei void dpsw_acl_prepare_entry_cfg(const struct dpsw_acl_key *key,
14791a64ed12SIoana Ciornei 				u8 *entry_cfg_buf)
14801a64ed12SIoana Ciornei {
14811a64ed12SIoana Ciornei 	struct dpsw_prep_acl_entry *ext_params;
14821a64ed12SIoana Ciornei 	int i;
14831a64ed12SIoana Ciornei 
14841a64ed12SIoana Ciornei 	ext_params = (struct dpsw_prep_acl_entry *)entry_cfg_buf;
14851a64ed12SIoana Ciornei 
14861a64ed12SIoana Ciornei 	for (i = 0; i < 6; i++) {
14871a64ed12SIoana Ciornei 		ext_params->match_l2_dest_mac[i] = key->match.l2_dest_mac[5 - i];
14881a64ed12SIoana Ciornei 		ext_params->match_l2_source_mac[i] = key->match.l2_source_mac[5 - i];
14891a64ed12SIoana Ciornei 		ext_params->mask_l2_dest_mac[i] = key->mask.l2_dest_mac[5 - i];
14901a64ed12SIoana Ciornei 		ext_params->mask_l2_source_mac[i] = key->mask.l2_source_mac[5 - i];
14911a64ed12SIoana Ciornei 	}
14921a64ed12SIoana Ciornei 
14931a64ed12SIoana Ciornei 	ext_params->match_l2_tpid = cpu_to_le16(key->match.l2_tpid);
14941a64ed12SIoana Ciornei 	ext_params->match_l2_vlan_id = cpu_to_le16(key->match.l2_vlan_id);
14951a64ed12SIoana Ciornei 	ext_params->match_l3_dest_ip = cpu_to_le32(key->match.l3_dest_ip);
14961a64ed12SIoana Ciornei 	ext_params->match_l3_source_ip = cpu_to_le32(key->match.l3_source_ip);
14971a64ed12SIoana Ciornei 	ext_params->match_l4_dest_port = cpu_to_le16(key->match.l4_dest_port);
14981a64ed12SIoana Ciornei 	ext_params->match_l4_source_port = cpu_to_le16(key->match.l4_source_port);
14991a64ed12SIoana Ciornei 	ext_params->match_l2_ether_type = cpu_to_le16(key->match.l2_ether_type);
15001a64ed12SIoana Ciornei 	ext_params->match_l2_pcp_dei = key->match.l2_pcp_dei;
15011a64ed12SIoana Ciornei 	ext_params->match_l3_dscp = key->match.l3_dscp;
15021a64ed12SIoana Ciornei 
15031a64ed12SIoana Ciornei 	ext_params->mask_l2_tpid = cpu_to_le16(key->mask.l2_tpid);
15041a64ed12SIoana Ciornei 	ext_params->mask_l2_vlan_id = cpu_to_le16(key->mask.l2_vlan_id);
15051a64ed12SIoana Ciornei 	ext_params->mask_l3_dest_ip = cpu_to_le32(key->mask.l3_dest_ip);
15061a64ed12SIoana Ciornei 	ext_params->mask_l3_source_ip = cpu_to_le32(key->mask.l3_source_ip);
15071a64ed12SIoana Ciornei 	ext_params->mask_l4_dest_port = cpu_to_le16(key->mask.l4_dest_port);
15081a64ed12SIoana Ciornei 	ext_params->mask_l4_source_port = cpu_to_le16(key->mask.l4_source_port);
15091a64ed12SIoana Ciornei 	ext_params->mask_l2_ether_type = cpu_to_le16(key->mask.l2_ether_type);
15101a64ed12SIoana Ciornei 	ext_params->mask_l2_pcp_dei = key->mask.l2_pcp_dei;
15111a64ed12SIoana Ciornei 	ext_params->mask_l3_dscp = key->mask.l3_dscp;
15121a64ed12SIoana Ciornei 	ext_params->match_l3_protocol = key->match.l3_protocol;
15131a64ed12SIoana Ciornei 	ext_params->mask_l3_protocol = key->mask.l3_protocol;
15141a64ed12SIoana Ciornei }
15151a64ed12SIoana Ciornei 
15161a64ed12SIoana Ciornei /**
15171a64ed12SIoana Ciornei  * dpsw_acl_add_entry() - Add a rule to the ACL table.
15181a64ed12SIoana Ciornei  * @mc_io:	Pointer to MC portal's I/O object
15191a64ed12SIoana Ciornei  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
15201a64ed12SIoana Ciornei  * @token:	Token of DPSW object
15211a64ed12SIoana Ciornei  * @acl_id:	ACL ID
15221a64ed12SIoana Ciornei  * @cfg:	Entry configuration
15231a64ed12SIoana Ciornei  *
15241a64ed12SIoana Ciornei  * warning: This function has to be called after dpsw_acl_prepare_entry_cfg()
15251a64ed12SIoana Ciornei  *
15261a64ed12SIoana Ciornei  * Return:	'0' on Success; Error code otherwise.
15271a64ed12SIoana Ciornei  */
dpsw_acl_add_entry(struct fsl_mc_io * mc_io,u32 cmd_flags,u16 token,u16 acl_id,const struct dpsw_acl_entry_cfg * cfg)15281a64ed12SIoana Ciornei int dpsw_acl_add_entry(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
15291a64ed12SIoana Ciornei 		       u16 acl_id, const struct dpsw_acl_entry_cfg *cfg)
15301a64ed12SIoana Ciornei {
15311a64ed12SIoana Ciornei 	struct dpsw_cmd_acl_entry *cmd_params;
15321a64ed12SIoana Ciornei 	struct fsl_mc_command cmd = { 0 };
15331a64ed12SIoana Ciornei 
15341a64ed12SIoana Ciornei 	cmd.header = mc_encode_cmd_header(DPSW_CMDID_ACL_ADD_ENTRY, cmd_flags,
15351a64ed12SIoana Ciornei 					  token);
15361a64ed12SIoana Ciornei 	cmd_params = (struct dpsw_cmd_acl_entry *)cmd.params;
15371a64ed12SIoana Ciornei 	cmd_params->acl_id = cpu_to_le16(acl_id);
15381a64ed12SIoana Ciornei 	cmd_params->result_if_id = cpu_to_le16(cfg->result.if_id);
15391a64ed12SIoana Ciornei 	cmd_params->precedence = cpu_to_le32(cfg->precedence);
15401a64ed12SIoana Ciornei 	cmd_params->key_iova = cpu_to_le64(cfg->key_iova);
15411a64ed12SIoana Ciornei 	dpsw_set_field(cmd_params->result_action,
15421a64ed12SIoana Ciornei 		       RESULT_ACTION,
15431a64ed12SIoana Ciornei 		       cfg->result.action);
15441a64ed12SIoana Ciornei 
15451a64ed12SIoana Ciornei 	return mc_send_command(mc_io, &cmd);
15461a64ed12SIoana Ciornei }
15471110318dSIoana Ciornei 
15481110318dSIoana Ciornei /**
15491110318dSIoana Ciornei  * dpsw_acl_remove_entry() - Removes an entry from ACL.
15501110318dSIoana Ciornei  * @mc_io:	Pointer to MC portal's I/O object
15511110318dSIoana Ciornei  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
15521110318dSIoana Ciornei  * @token:	Token of DPSW object
15531110318dSIoana Ciornei  * @acl_id:	ACL ID
15541110318dSIoana Ciornei  * @cfg:	Entry configuration
15551110318dSIoana Ciornei  *
15561110318dSIoana Ciornei  * warning: This function has to be called after dpsw_acl_set_entry_cfg()
15571110318dSIoana Ciornei  *
15581110318dSIoana Ciornei  * Return:	'0' on Success; Error code otherwise.
15591110318dSIoana Ciornei  */
dpsw_acl_remove_entry(struct fsl_mc_io * mc_io,u32 cmd_flags,u16 token,u16 acl_id,const struct dpsw_acl_entry_cfg * cfg)15601110318dSIoana Ciornei int dpsw_acl_remove_entry(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
15611110318dSIoana Ciornei 			  u16 acl_id, const struct dpsw_acl_entry_cfg *cfg)
15621110318dSIoana Ciornei {
15631110318dSIoana Ciornei 	struct dpsw_cmd_acl_entry *cmd_params;
15641110318dSIoana Ciornei 	struct fsl_mc_command cmd = { 0 };
15651110318dSIoana Ciornei 
15661110318dSIoana Ciornei 	/* prepare command */
15671110318dSIoana Ciornei 	cmd.header = mc_encode_cmd_header(DPSW_CMDID_ACL_REMOVE_ENTRY,
15681110318dSIoana Ciornei 					  cmd_flags,
15691110318dSIoana Ciornei 					  token);
15701110318dSIoana Ciornei 	cmd_params = (struct dpsw_cmd_acl_entry *)cmd.params;
15711110318dSIoana Ciornei 	cmd_params->acl_id = cpu_to_le16(acl_id);
15721110318dSIoana Ciornei 	cmd_params->result_if_id = cpu_to_le16(cfg->result.if_id);
15731110318dSIoana Ciornei 	cmd_params->precedence = cpu_to_le32(cfg->precedence);
15741110318dSIoana Ciornei 	cmd_params->key_iova = cpu_to_le64(cfg->key_iova);
15751110318dSIoana Ciornei 	dpsw_set_field(cmd_params->result_action,
15761110318dSIoana Ciornei 		       RESULT_ACTION,
15771110318dSIoana Ciornei 		       cfg->result.action);
15781110318dSIoana Ciornei 
15791110318dSIoana Ciornei 	/* send command to mc*/
15801110318dSIoana Ciornei 	return mc_send_command(mc_io, &cmd);
15811110318dSIoana Ciornei }
1582*cbc2a889SIoana Ciornei 
1583*cbc2a889SIoana Ciornei /**
1584*cbc2a889SIoana Ciornei  * dpsw_set_reflection_if() - Set target interface for traffic mirrored
1585*cbc2a889SIoana Ciornei  * @mc_io:	Pointer to MC portal's I/O object
1586*cbc2a889SIoana Ciornei  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
1587*cbc2a889SIoana Ciornei  * @token:	Token of DPSW object
1588*cbc2a889SIoana Ciornei  * @if_id:	Interface Id
1589*cbc2a889SIoana Ciornei  *
1590*cbc2a889SIoana Ciornei  * Only one mirroring destination is allowed per switch
1591*cbc2a889SIoana Ciornei  *
1592*cbc2a889SIoana Ciornei  * Return:	Completion status. '0' on Success; Error code otherwise.
1593*cbc2a889SIoana Ciornei  */
dpsw_set_reflection_if(struct fsl_mc_io * mc_io,u32 cmd_flags,u16 token,u16 if_id)1594*cbc2a889SIoana Ciornei int dpsw_set_reflection_if(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
1595*cbc2a889SIoana Ciornei 			   u16 if_id)
1596*cbc2a889SIoana Ciornei {
1597*cbc2a889SIoana Ciornei 	struct dpsw_cmd_set_reflection_if *cmd_params;
1598*cbc2a889SIoana Ciornei 	struct fsl_mc_command cmd = { 0 };
1599*cbc2a889SIoana Ciornei 
1600*cbc2a889SIoana Ciornei 	cmd.header = mc_encode_cmd_header(DPSW_CMDID_SET_REFLECTION_IF,
1601*cbc2a889SIoana Ciornei 					  cmd_flags,
1602*cbc2a889SIoana Ciornei 					  token);
1603*cbc2a889SIoana Ciornei 	cmd_params = (struct dpsw_cmd_set_reflection_if *)cmd.params;
1604*cbc2a889SIoana Ciornei 	cmd_params->if_id = cpu_to_le16(if_id);
1605*cbc2a889SIoana Ciornei 
1606*cbc2a889SIoana Ciornei 	return mc_send_command(mc_io, &cmd);
1607*cbc2a889SIoana Ciornei }
1608*cbc2a889SIoana Ciornei 
1609*cbc2a889SIoana Ciornei /**
1610*cbc2a889SIoana Ciornei  * dpsw_if_add_reflection() - Setup mirroring rule
1611*cbc2a889SIoana Ciornei  * @mc_io:	Pointer to MC portal's I/O object
1612*cbc2a889SIoana Ciornei  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
1613*cbc2a889SIoana Ciornei  * @token:	Token of DPSW object
1614*cbc2a889SIoana Ciornei  * @if_id:	Interface Identifier
1615*cbc2a889SIoana Ciornei  * @cfg:	Reflection configuration
1616*cbc2a889SIoana Ciornei  *
1617*cbc2a889SIoana Ciornei  * Return:	Completion status. '0' on Success; Error code otherwise.
1618*cbc2a889SIoana Ciornei  */
dpsw_if_add_reflection(struct fsl_mc_io * mc_io,u32 cmd_flags,u16 token,u16 if_id,const struct dpsw_reflection_cfg * cfg)1619*cbc2a889SIoana Ciornei int dpsw_if_add_reflection(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
1620*cbc2a889SIoana Ciornei 			   u16 if_id, const struct dpsw_reflection_cfg *cfg)
1621*cbc2a889SIoana Ciornei {
1622*cbc2a889SIoana Ciornei 	struct dpsw_cmd_if_reflection *cmd_params;
1623*cbc2a889SIoana Ciornei 	struct fsl_mc_command cmd = { 0 };
1624*cbc2a889SIoana Ciornei 
1625*cbc2a889SIoana Ciornei 	cmd.header = mc_encode_cmd_header(DPSW_CMDID_IF_ADD_REFLECTION,
1626*cbc2a889SIoana Ciornei 					  cmd_flags,
1627*cbc2a889SIoana Ciornei 					  token);
1628*cbc2a889SIoana Ciornei 	cmd_params = (struct dpsw_cmd_if_reflection *)cmd.params;
1629*cbc2a889SIoana Ciornei 	cmd_params->if_id = cpu_to_le16(if_id);
1630*cbc2a889SIoana Ciornei 	cmd_params->vlan_id = cpu_to_le16(cfg->vlan_id);
1631*cbc2a889SIoana Ciornei 	dpsw_set_field(cmd_params->filter, FILTER, cfg->filter);
1632*cbc2a889SIoana Ciornei 
1633*cbc2a889SIoana Ciornei 	return mc_send_command(mc_io, &cmd);
1634*cbc2a889SIoana Ciornei }
1635*cbc2a889SIoana Ciornei 
1636*cbc2a889SIoana Ciornei /**
1637*cbc2a889SIoana Ciornei  * dpsw_if_remove_reflection() - Remove mirroring rule
1638*cbc2a889SIoana Ciornei  * @mc_io:	Pointer to MC portal's I/O object
1639*cbc2a889SIoana Ciornei  * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
1640*cbc2a889SIoana Ciornei  * @token:	Token of DPSW object
1641*cbc2a889SIoana Ciornei  * @if_id:	Interface Identifier
1642*cbc2a889SIoana Ciornei  * @cfg:	Reflection configuration
1643*cbc2a889SIoana Ciornei  *
1644*cbc2a889SIoana Ciornei  * Return:	Completion status. '0' on Success; Error code otherwise.
1645*cbc2a889SIoana Ciornei  */
dpsw_if_remove_reflection(struct fsl_mc_io * mc_io,u32 cmd_flags,u16 token,u16 if_id,const struct dpsw_reflection_cfg * cfg)1646*cbc2a889SIoana Ciornei int dpsw_if_remove_reflection(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
1647*cbc2a889SIoana Ciornei 			      u16 if_id, const struct dpsw_reflection_cfg *cfg)
1648*cbc2a889SIoana Ciornei {
1649*cbc2a889SIoana Ciornei 	struct dpsw_cmd_if_reflection *cmd_params;
1650*cbc2a889SIoana Ciornei 	struct fsl_mc_command cmd = { 0 };
1651*cbc2a889SIoana Ciornei 
1652*cbc2a889SIoana Ciornei 	cmd.header = mc_encode_cmd_header(DPSW_CMDID_IF_REMOVE_REFLECTION,
1653*cbc2a889SIoana Ciornei 					  cmd_flags,
1654*cbc2a889SIoana Ciornei 					  token);
1655*cbc2a889SIoana Ciornei 	cmd_params = (struct dpsw_cmd_if_reflection *)cmd.params;
1656*cbc2a889SIoana Ciornei 	cmd_params->if_id = cpu_to_le16(if_id);
1657*cbc2a889SIoana Ciornei 	cmd_params->vlan_id = cpu_to_le16(cfg->vlan_id);
1658*cbc2a889SIoana Ciornei 	dpsw_set_field(cmd_params->filter, FILTER, cfg->filter);
1659*cbc2a889SIoana Ciornei 
1660*cbc2a889SIoana Ciornei 	return mc_send_command(mc_io, &cmd);
1661*cbc2a889SIoana Ciornei }
1662