[U-Boot] [PATCH 10/10] drivers/net/vsc9953: Add commands for VLAN ingress filtering

Codrin Ciubotariu codrin.ciubotariu at freescale.com
Thu Jun 11 17:10:20 CEST 2015


The command:
ethsw [port <port_no>] ingress filtering
     { [help] | show | enable | disable }
  - enable/disable VLAN ingress filtering on port

can be used to enable/disable/show VLAN ingress filtering on a port.

Signed-off-by: Johnson Leung <johnson.leung at freescale.com>
Signed-off-by: Codrin Ciubotariu <codrin.ciubotariu at freescale.com>
Change-Id: I658ef613724e3e1dbf78babde985c4d11c4a2706
---
 drivers/net/vsc9953.c | 137 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 137 insertions(+)

diff --git a/drivers/net/vsc9953.c b/drivers/net/vsc9953.c
index 3129b03..d5520d9 100644
--- a/drivers/net/vsc9953.c
+++ b/drivers/net/vsc9953.c
@@ -1555,6 +1555,33 @@ static int vsc9953_vlan_learning_get(enum vlan_learning_mode *lrn_mode)
 	return 0;
 }
 
+/* Enable/disable VLAN ingress filtering on a VSC9953 port */
+static void vsc9953_port_ingress_filtering_set(int port_no, int enabled)
+{
+	struct vsc9953_analyzer		*l2ana_reg;
+
+	l2ana_reg = (struct vsc9953_analyzer *)(VSC9953_OFFSET +
+			VSC9953_ANA_OFFSET);
+
+	if (enabled)
+		setbits_le32(&l2ana_reg->ana.vlan_mask, 1 << port_no);
+	else
+		clrbits_le32(&l2ana_reg->ana.vlan_mask, 1 << port_no);
+}
+
+/* Show VLAN ingress filtering on a VSC9953 port */
+static void vsc9953_port_ingress_filtering_get(int port_no, int *enabled)
+{
+	u32				val;
+	struct vsc9953_analyzer		*l2ana_reg;
+
+	l2ana_reg = (struct vsc9953_analyzer *)(VSC9953_OFFSET +
+				VSC9953_ANA_OFFSET);
+
+	val = in_le32(&l2ana_reg->ana.vlan_mask);
+	*enabled = !!(val & (1 << port_no));
+}
+
 enum egress_vlan_tag {
 	EGR_TAG_CLASS = 0,
 	EGR_TAG_PVID,
@@ -1626,6 +1653,8 @@ enum keyword_id {
 	id_classified,
 	id_shared,
 	id_private,
+	id_ingress,
+	id_filtering,
 	id_count,	/* keep last */
 };
 
@@ -2031,6 +2060,68 @@ static int vsc9953_port_untag_set_key_func(struct command_def *parsed_cmd)
 	return 0;
 }
 
+#define VSC9953_PORT_INGR_FLTR_HELP "ethsw [port <port_no>] ingress filtering" \
+" { [help] | show | enable | disable } " \
+"- enable/disable VLAN ingress filtering on port"
+
+static int vsc9953_ingr_fltr_help_key_func(struct command_def *parsed_cmd)
+{
+	printf(VSC9953_PORT_INGR_FLTR_HELP"\n");
+
+	return 0;
+}
+
+static int vsc9953_ingr_fltr_show_key_func(struct command_def *parsed_cmd)
+{
+	int			i, enabled;
+
+	printf("%7s\t%18s\n", "Port", "Ingress filtering");
+	if (parsed_cmd->port != VSC9953_CMD_PORT_ALL) {
+		vsc9953_port_ingress_filtering_get(parsed_cmd->port, &enabled);
+		printf("%7d\t%18s\n", parsed_cmd->port, enabled ? "enable" :
+								  "disable");
+	} else {
+		for (i = 0; i < VSC9953_MAX_PORTS; i++) {
+			vsc9953_port_ingress_filtering_get(i, &enabled);
+			printf("%7d\t%18s\n", parsed_cmd->port, enabled ?
+								"enable" :
+								"disable");
+		}
+	}
+
+	return 0;
+}
+
+static int vsc9953_ingr_fltr_set_key_func(struct command_def *parsed_cmd)
+{
+	int				i, enable;
+
+	/* keywords for enabling/disabling ingress filtering
+	 * are the last in the array
+	 */
+	if (parsed_cmd->cmd_to_keywords[parsed_cmd->cmd_keywords_nr - 1] ==
+	    id_enable)
+		enable = 1;
+	else if (parsed_cmd->cmd_to_keywords[parsed_cmd->cmd_keywords_nr - 1] ==
+		 id_disable)
+		enable = 0;
+	else
+		return -1;
+
+	if (parsed_cmd->port != VSC9953_CMD_PORT_ALL) {
+		if (!VSC9953_PORT_CHECK(parsed_cmd->port)) {
+			printf("Invalid port number: %d\n", parsed_cmd->port);
+			return -1;
+		}
+		vsc9953_port_ingress_filtering_set(parsed_cmd->port, enable);
+	} else {
+		for (i = 0; i < VSC9953_MAX_PORTS; i++)
+			vsc9953_port_ingress_filtering_set(i, enable);
+	}
+
+	return 0;
+}
+
 #define VSC9953_EGR_VLAN_TAG_HELP "ethsw [port <port_no>] egress tag " \
 "{ [help] | show | pvid | classified } " \
 "- Configure VID source for egress tag. " \
@@ -2479,6 +2570,45 @@ struct keywords_to_function {
 					id_key_end,
 			},
 			.keyword_function = &vsc9953_vlan_learn_set_key_func,
+		}, {
+			.cmd_keyword = {
+					id_ingress,
+					id_filtering,
+					-1,
+			},
+			.keyword_function = &vsc9953_ingr_fltr_help_key_func,
+		}, {
+			.cmd_keyword = {
+					id_ingress,
+					id_filtering,
+					id_help,
+					-1,
+			},
+			.keyword_function = &vsc9953_ingr_fltr_help_key_func,
+		}, {
+			.cmd_keyword = {
+					id_ingress,
+					id_filtering,
+					id_show,
+					-1,
+			},
+			.keyword_function = &vsc9953_ingr_fltr_show_key_func,
+		}, {
+			.cmd_keyword = {
+					id_ingress,
+					id_filtering,
+					id_enable,
+					-1,
+			},
+			.keyword_function = &vsc9953_ingr_fltr_set_key_func,
+		}, {
+			.cmd_keyword = {
+					id_ingress,
+					id_filtering,
+					id_disable,
+					-1,
+			},
+			.keyword_function = &vsc9953_ingr_fltr_set_key_func,
 		},
 };
 
@@ -2601,6 +2731,12 @@ struct keyword_def {
 		}, {
 				.keyword_name = "private",
 				.match = &keyword_match_gen,
+		}, {
+				.keyword_name = "ingress",
+				.match = &keyword_match_gen,
+		}, {
+				.keyword_name = "filtering",
+				.match = &keyword_match_gen,
 		},
 };
 
@@ -2925,6 +3061,7 @@ U_BOOT_CMD(ethsw, VSC9953_MAX_CMD_PARAMS, 0, do_ethsw,
 	   VSC9953_PORT_UNTAG_HELP"\n"
 	   VSC9953_EGR_VLAN_TAG_HELP"\n"
 	   VSC9953_VLAN_FDB_HELP"\n"
+	   VSC9953_PORT_INGR_FLTR_HELP"\n"
 );
 
 #endif /* CONFIG_VSC9953_CMD */
-- 
1.9.3



More information about the U-Boot mailing list