public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Codrin Ciubotariu <codrin.ciubotariu@freescale.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 06/10] drivers/net/vsc9953: Add commands to enable/disable HW learning
Date: Thu, 11 Jun 2015 18:10:16 +0300	[thread overview]
Message-ID: <1434035420-1663-8-git-send-email-codrin.ciubotariu@freescale.com> (raw)
In-Reply-To: <1434035420-1663-1-git-send-email-codrin.ciubotariu@freescale.com>

The command:
ethsw [port <port_no>] learning { [help] | show | auto | disable }

can be used to enable/disable HW learning on a port.

Signed-off-by: Johnson Leung <johnson.leung@freescale.com>
Signed-off-by: Codrin Ciubotariu <codrin.ciubotariu@freescale.com>
Change-Id: Id05691c342d9a9b253e591d9c64a8e13225c5e56
---
 drivers/net/vsc9953.c | 188 ++++++++++++++++++++++++++++++++++++++++++++++++++
 include/vsc9953.h     |   6 ++
 2 files changed, 194 insertions(+)

diff --git a/drivers/net/vsc9953.c b/drivers/net/vsc9953.c
index 62ab0eb..1936c4a 100644
--- a/drivers/net/vsc9953.c
+++ b/drivers/net/vsc9953.c
@@ -672,6 +672,73 @@ static void vsc9953_port_config_show(int port_no)
 	printf("%8s\n", duplex == DUPLEX_FULL ? "full" : "half");
 }
 
+enum port_learn_mode {
+	PORT_LEARN_NONE,
+	PORT_LEARN_AUTO
+};
+
+/* Set learning configuration for a VSC9953 port */
+static void vsc9953_port_learn_mode_set(int port_no, enum port_learn_mode mode)
+{
+	struct vsc9953_analyzer		*l2ana_reg;
+
+	/* Administrative down */
+	if (!vsc9953_l2sw.port[port_no].enabled) {
+		printf("Port %d is administrative down\n", port_no);
+		return;
+	}
+
+	l2ana_reg = (struct vsc9953_analyzer *)(VSC9953_OFFSET +
+			VSC9953_ANA_OFFSET);
+
+	switch (mode) {
+	case PORT_LEARN_NONE:
+		clrbits_le32(&l2ana_reg->port[port_no].port_cfg,
+			     CONFIG_VSC9953_PORT_CFG_LEARN_DROP |
+			     CONFIG_VSC9953_PORT_CFG_LEARN_CPU |
+			     CONFIG_VSC9953_PORT_CFG_LEARN_AUTO |
+			     CONFIG_VSC9953_PORT_CFG_LEARN_ENA);
+		break;
+	case PORT_LEARN_AUTO:
+		clrsetbits_le32(&l2ana_reg->port[port_no].port_cfg,
+				CONFIG_VSC9953_PORT_CFG_LEARN_DROP |
+				CONFIG_VSC9953_PORT_CFG_LEARN_CPU,
+				CONFIG_VSC9953_PORT_CFG_LEARN_ENA |
+				CONFIG_VSC9953_PORT_CFG_LEARN_AUTO);
+		break;
+	default:
+		printf("Unknown learn mode for port %d\n", port_no);
+	}
+}
+
+/* Get learning configuration for a VSC9953 port */
+static int vsc9953_port_learn_mode_get(int port_no, enum port_learn_mode *mode)
+{
+	u32				val;
+	struct vsc9953_analyzer		*l2ana_reg;
+
+	/* Administrative down */
+	if (!vsc9953_l2sw.port[port_no].enabled) {
+		printf("Port %d is administrative down\n", port_no);
+		return -1;
+	}
+
+	l2ana_reg = (struct vsc9953_analyzer *)(VSC9953_OFFSET +
+			VSC9953_ANA_OFFSET);
+
+	/* For now we only support HW learning (auto) and no learning */
+	val = in_le32(&l2ana_reg->port[port_no].port_cfg);
+	if ((val & (CONFIG_VSC9953_PORT_CFG_LEARN_ENA |
+		   CONFIG_VSC9953_PORT_CFG_LEARN_AUTO)) ==
+	    (CONFIG_VSC9953_PORT_CFG_LEARN_ENA |
+	     CONFIG_VSC9953_PORT_CFG_LEARN_AUTO))
+		*mode = PORT_LEARN_AUTO;
+	else
+		*mode = PORT_LEARN_NONE;
+
+	return 0;
+}
+
 /* Show VSC9953 ports' statistics */
 static void vsc9953_port_statistics_show(int port_no)
 {
@@ -895,6 +962,8 @@ enum keyword_id {
 	id_disable,
 	id_statistics,
 	id_clear,
+	id_learning,
+	id_auto,
 	id_count,	/* keep last */
 };
 
@@ -1002,6 +1071,84 @@ static int vsc9953_port_stats_clear_key_func(struct command_def *parsed_cmd)
 	return 0;
 }
 
+#define VSC9953_LEARN_HELP "ethsw [port <port_no>] learning " \
+"{ [help] | show | auto | disable } " \
+"- enable/disable/show learning configuration on a port"
+
+static int vsc9953_learn_help_key_func(struct command_def *parsed_cmd)
+{
+	printf(VSC9953_LEARN_HELP"\n");
+
+	return 0;
+}
+
+static int vsc9953_learn_show_key_func(struct command_def *parsed_cmd)
+{
+	int				i;
+	enum port_learn_mode		mode;
+
+	if (parsed_cmd->port != VSC9953_CMD_PORT_ALL) {
+		if (vsc9953_port_learn_mode_get(parsed_cmd->port, &mode))
+			return -1;
+		printf("%7s %11s\n", "Port", "Learn mode");
+		switch (mode) {
+		case PORT_LEARN_NONE:
+			printf("%7d %11s\n", parsed_cmd->port, "disable");
+			break;
+		case PORT_LEARN_AUTO:
+			printf("%7d %11s\n", parsed_cmd->port, "auto");
+			break;
+		default:
+			printf("%7d %11s\n", parsed_cmd->port, "-");
+		}
+	} else {
+		printf("%7s %11s\n", "Port", "Learn mode");
+		for (i = 0; i < VSC9953_MAX_PORTS; i++) {
+			if (vsc9953_port_learn_mode_get(i, &mode))
+				continue;
+			switch (mode) {
+			case PORT_LEARN_NONE:
+				printf("%7d %11s\n", i, "disable");
+				break;
+			case PORT_LEARN_AUTO:
+				printf("%7d %11s\n", i, "auto");
+				break;
+			default:
+				printf("%7d %11s\n", i, "-");
+			}
+		}
+	}
+
+	return 0;
+}
+
+static int vsc9953_learn_set_key_func(struct command_def *parsed_cmd)
+{
+	int				i;
+	enum port_learn_mode		mode;
+
+	/* Last keyword should tell us the learn mode */
+	if (parsed_cmd->cmd_to_keywords[parsed_cmd->cmd_keywords_nr - 1] ==
+			id_auto)
+		mode = PORT_LEARN_AUTO;
+	else if (parsed_cmd->cmd_to_keywords[parsed_cmd->cmd_keywords_nr - 1] ==
+			id_disable)
+		mode = PORT_LEARN_NONE;
+	else {
+		parsed_cmd->err = 1;
+		return -1;
+	}
+
+	if (parsed_cmd->port != VSC9953_CMD_PORT_ALL) {
+		vsc9953_port_learn_mode_set(parsed_cmd->port, mode);
+	} else {
+		for (i = 0; i < VSC9953_MAX_PORTS; i++)
+			vsc9953_port_learn_mode_set(i, mode);
+	}
+
+	return 0;
+}
+
 struct keywords_to_function {
 	enum keyword_id cmd_keyword[VSC9953_MAX_CMD_PARAMS];
 	int (*keyword_function)(struct command_def *parsed_cmd);
@@ -1044,6 +1191,40 @@ struct keywords_to_function {
 					id_key_end,
 			},
 			.keyword_function = &vsc9953_port_stats_clear_key_func,
+		}, {
+			.cmd_keyword = {
+					id_learning,
+					id_key_end,
+			},
+			.keyword_function = &vsc9953_learn_help_key_func,
+		}, {
+			.cmd_keyword = {
+					id_learning,
+					id_help,
+					id_key_end,
+			},
+			.keyword_function = &vsc9953_learn_help_key_func,
+		}, {
+			.cmd_keyword = {
+					id_learning,
+					id_show,
+					id_key_end,
+			},
+			.keyword_function = &vsc9953_learn_show_key_func,
+		}, {
+			.cmd_keyword = {
+					id_learning,
+					id_auto,
+					id_key_end,
+			},
+			.keyword_function = &vsc9953_learn_set_key_func,
+		}, {
+			.cmd_keyword = {
+					id_learning,
+					id_disable,
+					id_key_end,
+			},
+			.keyword_function = &vsc9953_learn_set_key_func,
 		},
 };
 
@@ -1095,6 +1276,12 @@ struct keyword_def {
 		}, {
 				.keyword_name = "clear",
 				.match = &keyword_match_gen,
+		}, {
+				.keyword_name = "learning",
+				.match = &keyword_match_gen,
+		}, {
+				.keyword_name = "auto",
+				.match = &keyword_match_gen,
 		},
 };
 
@@ -1273,6 +1460,7 @@ U_BOOT_CMD(ethsw, VSC9953_MAX_CMD_PARAMS, 0, do_ethsw,
 	   "vsc9953 l2 switch commands",
 	   VSC9953_PORT_CONF_HELP"\n"
 	   VSC9953_PORT_STATS_HELP"\n"
+	   VSC9953_LEARN_HELP"\n"
 );
 
 #endif /* CONFIG_VSC9953_CMD */
diff --git a/include/vsc9953.h b/include/vsc9953.h
index 482acac..59c85c3 100644
--- a/include/vsc9953.h
+++ b/include/vsc9953.h
@@ -112,6 +112,12 @@
 #define CONFIG_VSC9953_VLAN_CMD_WRITE	0x00000002
 #define CONFIG_VSC9953_VLAN_CMD_INIT	0x00000003
 
+/* Macros for vsc9953_ana_port.port_cfg register */
+#define CONFIG_VSC9953_PORT_CFG_LEARN_ENA	0x00000080
+#define CONFIG_VSC9953_PORT_CFG_LEARN_AUTO	0x00000100
+#define CONFIG_VSC9953_PORT_CFG_LEARN_CPU	0x00000200
+#define CONFIG_VSC9953_PORT_CFG_LEARN_DROP	0x00000400
+
 /* Macros for vsc9953_qsys_sys.switch_port_mode register */
 #define CONFIG_VSC9953_PORT_ENA		0x00002000
 
-- 
1.9.3

  parent reply	other threads:[~2015-06-11 15:10 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-11 15:10 [U-Boot] [PATCH 00/10] Add more commands for VSC9953 L2 Switch Codrin Ciubotariu
2015-06-11 15:10 ` [U-Boot] [PATCH] drivers/net/vsc9953: Add GPL-2.0+ SPDX-License-Identifier Codrin Ciubotariu
2015-06-11 15:10 ` [U-Boot] [PATCH 01/10] drivers/net/vsc9953: Cleanup patch Codrin Ciubotariu
2015-06-11 15:10 ` [U-Boot] [PATCH 02/10] drivers/net/vsc9953: Fix missing reserved register Codrin Ciubotariu
2015-06-11 15:10 ` [U-Boot] [PATCH 03/10] drivers/net/vsc9953: Add default configuration for VSC9953 L2 Switch Codrin Ciubotariu
2015-06-11 15:10 ` [U-Boot] [PATCH 04/10] drivers/net/vsc9953: Refractor the parser for VSC9953 commands Codrin Ciubotariu
2015-06-11 15:10 ` [U-Boot] [PATCH 05/10] drivers/net/vsc9953: Add command to show/clear port counters Codrin Ciubotariu
2015-06-11 15:10 ` Codrin Ciubotariu [this message]
2015-06-11 15:10 ` [U-Boot] [PATCH 07/10] drivers/net/vsc9953: Add commands to manipulate the FDB for VSC9953 Codrin Ciubotariu
2015-06-11 15:10 ` [U-Boot] [PATCH 08/10] drivers/net/vsc9953: Add VLAN commands " Codrin Ciubotariu
2015-06-11 15:10 ` [U-Boot] [PATCH 09/10] drivers/net/vsc9953: Add command for shared/private VLAN learning Codrin Ciubotariu
2015-06-11 15:10 ` [U-Boot] [PATCH 10/10] drivers/net/vsc9953: Add commands for VLAN ingress filtering Codrin Ciubotariu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1434035420-1663-8-git-send-email-codrin.ciubotariu@freescale.com \
    --to=codrin.ciubotariu@freescale.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox