Commit cbc2a889 authored by Ioana Ciornei's avatar Ioana Ciornei Committed by David S. Miller
Browse files

dpaa2-switch: add API for setting up mirroring



Add the necessary MC API for setting up and configuring the mirroring
feature on the DPSW DPAA2 object.

Signed-off-by: default avatarIoana Ciornei <ioana.ciornei@nxp.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 3fa5514a
Loading
Loading
Loading
Loading
+19 −0
Original line number Diff line number Diff line
@@ -39,11 +39,16 @@
#define DPSW_CMDID_GET_IRQ_STATUS           DPSW_CMD_ID(0x016)
#define DPSW_CMDID_CLEAR_IRQ_STATUS         DPSW_CMD_ID(0x017)

#define DPSW_CMDID_SET_REFLECTION_IF        DPSW_CMD_ID(0x022)

#define DPSW_CMDID_IF_SET_TCI               DPSW_CMD_ID(0x030)
#define DPSW_CMDID_IF_SET_STP               DPSW_CMD_ID(0x031)

#define DPSW_CMDID_IF_GET_COUNTER           DPSW_CMD_V2(0x034)

#define DPSW_CMDID_IF_ADD_REFLECTION        DPSW_CMD_ID(0x037)
#define DPSW_CMDID_IF_REMOVE_REFLECTION     DPSW_CMD_ID(0x038)

#define DPSW_CMDID_IF_ENABLE                DPSW_CMD_ID(0x03D)
#define DPSW_CMDID_IF_DISABLE               DPSW_CMD_ID(0x03E)

@@ -533,5 +538,19 @@ struct dpsw_cmd_acl_entry {
	__le64 pad2[4];
	__le64 key_iova;
};

struct dpsw_cmd_set_reflection_if {
	__le16 if_id;
};

#define DPSW_FILTER_SHIFT	0
#define DPSW_FILTER_SIZE	2

struct dpsw_cmd_if_reflection {
	__le16 if_id;
	__le16 vlan_id;
	/* only 2 bits from the LSB */
	u8 filter;
};
#pragma pack(pop)
#endif /* __FSL_DPSW_CMD_H */
+80 −0
Original line number Diff line number Diff line
@@ -1579,3 +1579,83 @@ int dpsw_acl_remove_entry(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
	/* send command to mc*/
	return mc_send_command(mc_io, &cmd);
}

/**
 * dpsw_set_reflection_if() - Set target interface for traffic mirrored
 * @mc_io:	Pointer to MC portal's I/O object
 * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
 * @token:	Token of DPSW object
 * @if_id:	Interface Id
 *
 * Only one mirroring destination is allowed per switch
 *
 * Return:	Completion status. '0' on Success; Error code otherwise.
 */
int dpsw_set_reflection_if(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
			   u16 if_id)
{
	struct dpsw_cmd_set_reflection_if *cmd_params;
	struct fsl_mc_command cmd = { 0 };

	cmd.header = mc_encode_cmd_header(DPSW_CMDID_SET_REFLECTION_IF,
					  cmd_flags,
					  token);
	cmd_params = (struct dpsw_cmd_set_reflection_if *)cmd.params;
	cmd_params->if_id = cpu_to_le16(if_id);

	return mc_send_command(mc_io, &cmd);
}

/**
 * dpsw_if_add_reflection() - Setup mirroring rule
 * @mc_io:	Pointer to MC portal's I/O object
 * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
 * @token:	Token of DPSW object
 * @if_id:	Interface Identifier
 * @cfg:	Reflection configuration
 *
 * Return:	Completion status. '0' on Success; Error code otherwise.
 */
int dpsw_if_add_reflection(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
			   u16 if_id, const struct dpsw_reflection_cfg *cfg)
{
	struct dpsw_cmd_if_reflection *cmd_params;
	struct fsl_mc_command cmd = { 0 };

	cmd.header = mc_encode_cmd_header(DPSW_CMDID_IF_ADD_REFLECTION,
					  cmd_flags,
					  token);
	cmd_params = (struct dpsw_cmd_if_reflection *)cmd.params;
	cmd_params->if_id = cpu_to_le16(if_id);
	cmd_params->vlan_id = cpu_to_le16(cfg->vlan_id);
	dpsw_set_field(cmd_params->filter, FILTER, cfg->filter);

	return mc_send_command(mc_io, &cmd);
}

/**
 * dpsw_if_remove_reflection() - Remove mirroring rule
 * @mc_io:	Pointer to MC portal's I/O object
 * @cmd_flags:	Command flags; one or more of 'MC_CMD_FLAG_'
 * @token:	Token of DPSW object
 * @if_id:	Interface Identifier
 * @cfg:	Reflection configuration
 *
 * Return:	Completion status. '0' on Success; Error code otherwise.
 */
int dpsw_if_remove_reflection(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
			      u16 if_id, const struct dpsw_reflection_cfg *cfg)
{
	struct dpsw_cmd_if_reflection *cmd_params;
	struct fsl_mc_command cmd = { 0 };

	cmd.header = mc_encode_cmd_header(DPSW_CMDID_IF_REMOVE_REFLECTION,
					  cmd_flags,
					  token);
	cmd_params = (struct dpsw_cmd_if_reflection *)cmd.params;
	cmd_params->if_id = cpu_to_le16(if_id);
	cmd_params->vlan_id = cpu_to_le16(cfg->vlan_id);
	dpsw_set_field(cmd_params->filter, FILTER, cfg->filter);

	return mc_send_command(mc_io, &cmd);
}
+31 −0
Original line number Diff line number Diff line
@@ -752,4 +752,35 @@ int dpsw_acl_add_entry(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,

int 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);

/**
 * enum dpsw_reflection_filter - Filter type for frames to be reflected
 * @DPSW_REFLECTION_FILTER_INGRESS_ALL: Reflect all frames
 * @DPSW_REFLECTION_FILTER_INGRESS_VLAN: Reflect only frames that belong to
 *	the particular VLAN defined by vid parameter
 *
 */
enum dpsw_reflection_filter {
	DPSW_REFLECTION_FILTER_INGRESS_ALL = 0,
	DPSW_REFLECTION_FILTER_INGRESS_VLAN = 1
};

/**
 * struct dpsw_reflection_cfg - Structure representing the mirroring config
 * @filter: Filter type for frames to be mirrored
 * @vlan_id: VLAN ID to mirror; valid only when the type is DPSW_INGRESS_VLAN
 */
struct dpsw_reflection_cfg {
	enum dpsw_reflection_filter filter;
	u16 vlan_id;
};

int dpsw_set_reflection_if(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
			   u16 if_id);

int dpsw_if_add_reflection(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
			   u16 if_id, const struct dpsw_reflection_cfg *cfg);

int dpsw_if_remove_reflection(struct fsl_mc_io *mc_io, u32 cmd_flags, u16 token,
			      u16 if_id, const struct dpsw_reflection_cfg *cfg);
#endif /* __FSL_DPSW_H */