
Hi Codrin,
On Tue, Jun 23, 2015 at 11:48 AM, Codrin Ciubotariu codrin.ciubotariu@freescale.com wrote:
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
Changes for v2: - removed Change-id field;
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;
Please use: + return CMD_RET_SUCCESS;
+}
+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;
Please use: + return CMD_RET_FAILURE;
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;
Please use: + return CMD_RET_SUCCESS;
+}
+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;
Please use: + return CMD_RET_USAGE;
}
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;
Please use: + return CMD_RET_SUCCESS;
+}
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
Drop "CONFIG_" from these.
/* Macros for vsc9953_qsys_sys.switch_port_mode register */ #define CONFIG_VSC9953_PORT_ENA 0x00002000
-- 1.9.3
U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot