DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH 1/2] net/sfc: support loopback mode configuration
@ 2018-04-04 11:10 Andrew Rybchenko
  2018-04-04 11:10 ` [dpdk-dev] [PATCH 2/2] app/testpmd: add commands to set loopback mode Andrew Rybchenko
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Andrew Rybchenko @ 2018-04-04 11:10 UTC (permalink / raw)
  To: dev

All loopback modes are listed in efx_loopback_type_t.
Available loopback modes are listed per link speed in
the enc_loopback_types member of the efx_nic_cfg_t.

Signed-off-by: Andrew Rybchenko <arybchenko@solarflare.com>
Reviewed-by: Andy Moreton <amoreton@solarflare.com>
Reviewed-by: Ivan Malov <ivan.malov@oktetlabs.ru>
---
 doc/guides/nics/sfc_efx.rst |  4 ++--
 drivers/net/sfc/efsys.h     |  2 +-
 drivers/net/sfc/sfc.c       |  2 ++
 drivers/net/sfc/sfc_port.c  | 40 ++++++++++++++++++++++++++++++++++++++++
 4 files changed, 45 insertions(+), 3 deletions(-)

diff --git a/doc/guides/nics/sfc_efx.rst b/doc/guides/nics/sfc_efx.rst
index c170e36..abaed67 100644
--- a/doc/guides/nics/sfc_efx.rst
+++ b/doc/guides/nics/sfc_efx.rst
@@ -88,6 +88,8 @@ SFC EFX PMD has support for:
 
 - Flow API
 
+- Loopback
+
 
 Non-supported Features
 ----------------------
@@ -98,8 +100,6 @@ The features not yet supported include:
 
 - Priority-based flow control
 
-- Loopback
-
 - Configurable RX CRC stripping (always stripped)
 
 - Header split on receive
diff --git a/drivers/net/sfc/efsys.h b/drivers/net/sfc/efsys.h
index b3dae6e..52c5bd5 100644
--- a/drivers/net/sfc/efsys.h
+++ b/drivers/net/sfc/efsys.h
@@ -166,7 +166,7 @@ prefetch_read_once(const volatile void *addr)
 
 #define EFSYS_OPT_MAC_STATS 1
 
-#define EFSYS_OPT_LOOPBACK 0
+#define EFSYS_OPT_LOOPBACK 1
 
 #define EFSYS_OPT_MON_MCDI 0
 #define EFSYS_OPT_MON_STATS 0
diff --git a/drivers/net/sfc/sfc.c b/drivers/net/sfc/sfc.c
index e456bca..2eefe00 100644
--- a/drivers/net/sfc/sfc.c
+++ b/drivers/net/sfc/sfc.c
@@ -123,10 +123,12 @@ sfc_check_conf(struct sfc_adapter *sa)
 		rc = EINVAL;
 	}
 
+#if !EFSYS_OPT_LOOPBACK
 	if (conf->lpbk_mode != 0) {
 		sfc_err(sa, "Loopback not supported");
 		rc = EINVAL;
 	}
+#endif
 
 	if (conf->dcb_capability_en != 0) {
 		sfc_err(sa, "Priority-based flow control not supported");
diff --git a/drivers/net/sfc/sfc_port.c b/drivers/net/sfc/sfc_port.c
index fd267e1..5cc3ad7 100644
--- a/drivers/net/sfc/sfc_port.c
+++ b/drivers/net/sfc/sfc_port.c
@@ -121,6 +121,28 @@ sfc_port_init_dev_link(struct sfc_adapter *sa)
 	return 0;
 }
 
+#if EFSYS_OPT_LOOPBACK
+
+static efx_link_mode_t
+sfc_port_phy_caps_to_max_link_speed(uint32_t phy_caps)
+{
+	if (phy_caps & (1u << EFX_PHY_CAP_100000FDX))
+		return EFX_LINK_100000FDX;
+	if (phy_caps & (1u << EFX_PHY_CAP_50000FDX))
+		return EFX_LINK_50000FDX;
+	if (phy_caps & (1u << EFX_PHY_CAP_40000FDX))
+		return EFX_LINK_40000FDX;
+	if (phy_caps & (1u << EFX_PHY_CAP_25000FDX))
+		return EFX_LINK_25000FDX;
+	if (phy_caps & (1u << EFX_PHY_CAP_10000FDX))
+		return EFX_LINK_10000FDX;
+	if (phy_caps & (1u << EFX_PHY_CAP_1000FDX))
+		return EFX_LINK_1000FDX;
+	return EFX_LINK_UNKNOWN;
+}
+
+#endif
+
 int
 sfc_port_start(struct sfc_adapter *sa)
 {
@@ -143,6 +165,21 @@ sfc_port_start(struct sfc_adapter *sa)
 	if (rc != 0)
 		goto fail_port_init;
 
+#if EFSYS_OPT_LOOPBACK
+	if (sa->eth_dev->data->dev_conf.lpbk_mode != 0) {
+		efx_link_mode_t link_mode;
+
+		link_mode =
+			sfc_port_phy_caps_to_max_link_speed(port->phy_adv_cap);
+		sfc_log_init(sa, "set loopback link_mode=%u type=%u", link_mode,
+			     sa->eth_dev->data->dev_conf.lpbk_mode);
+		rc = efx_port_loopback_set(sa->nic, link_mode,
+			sa->eth_dev->data->dev_conf.lpbk_mode);
+		if (rc != 0)
+			goto fail_loopback_set;
+	}
+#endif
+
 	sfc_log_init(sa, "set flow control to %#x autoneg=%u",
 		     port->flow_ctrl, port->flow_ctrl_autoneg);
 	rc = efx_mac_fcntl_set(sa->nic, port->flow_ctrl,
@@ -268,6 +305,9 @@ sfc_port_start(struct sfc_adapter *sa)
 fail_mac_pdu_set:
 fail_phy_adv_cap_set:
 fail_mac_fcntl_set:
+#if EFSYS_OPT_LOOPBACK
+fail_loopback_set:
+#endif
 	efx_port_fini(sa->nic);
 
 fail_port_init:
-- 
2.7.4

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [dpdk-dev] [PATCH 2/2] app/testpmd: add commands to set loopback mode
  2018-04-04 11:10 [dpdk-dev] [PATCH 1/2] net/sfc: support loopback mode configuration Andrew Rybchenko
@ 2018-04-04 11:10 ` Andrew Rybchenko
  2018-04-06 12:09   ` Ferruh Yigit
  2018-04-06 12:09 ` [dpdk-dev] [PATCH 1/2] net/sfc: support loopback mode configuration Ferruh Yigit
  2018-04-09 11:58 ` [dpdk-dev] [PATCH v2 0/3] " Andrew Rybchenko
  2 siblings, 1 reply; 10+ messages in thread
From: Andrew Rybchenko @ 2018-04-04 11:10 UTC (permalink / raw)
  To: dev; +Cc: Wenzhuo Lu, Jingjing Wu

Signed-off-by: Andrew Rybchenko <arybchenko@solarflare.com>
Reviewed-by: Roman Zhukov <roman.zhukov@oktetlabs.ru>
Reviewed-by: Ivan Malov <ivan.malov@oktetlabs.ru>
---
 app/test-pmd/cmdline.c | 121 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 121 insertions(+)

diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c
index 40b31ad..92ef7e1 100644
--- a/app/test-pmd/cmdline.c
+++ b/app/test-pmd/cmdline.c
@@ -806,6 +806,9 @@ static void cmd_help_long_parsed(void *parsed_result,
 			" duplex (half|full|auto)\n"
 			"    Set speed and duplex for all ports or port_id\n\n"
 
+			"port config (port_id|all) loopback (mode)\n"
+			"    Set loopback mode for all ports or port_id\n\n"
+
 			"port config all (rxq|txq|rxd|txd) (value)\n"
 			"    Set number for rxq/txq/rxd/txd.\n\n"
 
@@ -1487,6 +1490,122 @@ cmdline_parse_inst_t cmd_config_speed_specific = {
 	},
 };
 
+/* *** configure loopback for all ports *** */
+struct cmd_config_loopback_all {
+	cmdline_fixed_string_t port;
+	cmdline_fixed_string_t keyword;
+	cmdline_fixed_string_t all;
+	cmdline_fixed_string_t item;
+	uint32_t mode;
+};
+
+static void
+cmd_config_loopback_all_parsed(void *parsed_result,
+			__attribute__((unused)) struct cmdline *cl,
+			__attribute__((unused)) void *data)
+{
+	struct cmd_config_loopback_all *res = parsed_result;
+	portid_t pid;
+
+	if (!all_ports_stopped()) {
+		printf("Please stop all ports first\n");
+		return;
+	}
+
+	RTE_ETH_FOREACH_DEV(pid) {
+		ports[pid].dev_conf.lpbk_mode = res->mode;
+	}
+
+	cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
+}
+
+cmdline_parse_token_string_t cmd_config_loopback_all_port =
+	TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, port, "port");
+cmdline_parse_token_string_t cmd_config_loopback_all_keyword =
+	TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, keyword,
+							"config");
+cmdline_parse_token_string_t cmd_config_loopback_all_all =
+	TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, all, "all");
+cmdline_parse_token_string_t cmd_config_loopback_all_item =
+	TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, item,
+							"loopback");
+cmdline_parse_token_num_t cmd_config_loopback_all_mode =
+	TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_all, mode, UINT32);
+
+cmdline_parse_inst_t cmd_config_loopback_all = {
+	.f = cmd_config_loopback_all_parsed,
+	.data = NULL,
+	.help_str = "port config all loopback <mode>",
+	.tokens = {
+		(void *)&cmd_config_loopback_all_port,
+		(void *)&cmd_config_loopback_all_keyword,
+		(void *)&cmd_config_loopback_all_all,
+		(void *)&cmd_config_loopback_all_item,
+		(void *)&cmd_config_loopback_all_mode,
+		NULL,
+	},
+};
+
+/* *** configure loopback for specific port *** */
+struct cmd_config_loopback_specific {
+	cmdline_fixed_string_t port;
+	cmdline_fixed_string_t keyword;
+	uint16_t port_id;
+	cmdline_fixed_string_t item;
+	uint32_t mode;
+};
+
+static void
+cmd_config_loopback_specific_parsed(void *parsed_result,
+				__attribute__((unused)) struct cmdline *cl,
+				__attribute__((unused)) void *data)
+{
+	struct cmd_config_loopback_specific *res = parsed_result;
+
+	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
+		return;
+
+	if (!port_is_stopped(res->port_id)) {
+		printf("Please stop port %u first\n", res->port_id);
+		return;
+	}
+
+	ports[res->port_id].dev_conf.lpbk_mode = res->mode;
+
+	cmd_reconfig_device_queue(res->port_id, 1, 1);
+}
+
+
+cmdline_parse_token_string_t cmd_config_loopback_specific_port =
+	TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, port,
+								"port");
+cmdline_parse_token_string_t cmd_config_loopback_specific_keyword =
+	TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, keyword,
+								"config");
+cmdline_parse_token_num_t cmd_config_loopback_specific_id =
+	TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, port_id,
+								UINT16);
+cmdline_parse_token_string_t cmd_config_loopback_specific_item =
+	TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, item,
+								"loopback");
+cmdline_parse_token_num_t cmd_config_loopback_specific_mode =
+	TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, mode,
+			      UINT32);
+
+cmdline_parse_inst_t cmd_config_loopback_specific = {
+	.f = cmd_config_loopback_specific_parsed,
+	.data = NULL,
+	.help_str = "port config <port_id> loopback <mode>",
+	.tokens = {
+		(void *)&cmd_config_loopback_specific_port,
+		(void *)&cmd_config_loopback_specific_keyword,
+		(void *)&cmd_config_loopback_specific_id,
+		(void *)&cmd_config_loopback_specific_item,
+		(void *)&cmd_config_loopback_specific_mode,
+		NULL,
+	},
+};
+
 /* *** configure txq/rxq, txd/rxd *** */
 struct cmd_config_rx_tx {
 	cmdline_fixed_string_t port;
@@ -16130,6 +16249,8 @@ cmdline_parse_ctx_t main_ctx[] = {
 	(cmdline_parse_inst_t *)&cmd_operate_detach_port,
 	(cmdline_parse_inst_t *)&cmd_config_speed_all,
 	(cmdline_parse_inst_t *)&cmd_config_speed_specific,
+	(cmdline_parse_inst_t *)&cmd_config_loopback_all,
+	(cmdline_parse_inst_t *)&cmd_config_loopback_specific,
 	(cmdline_parse_inst_t *)&cmd_config_rx_tx,
 	(cmdline_parse_inst_t *)&cmd_config_mtu,
 	(cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
-- 
2.7.4

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [dpdk-dev] [PATCH 1/2] net/sfc: support loopback mode configuration
  2018-04-04 11:10 [dpdk-dev] [PATCH 1/2] net/sfc: support loopback mode configuration Andrew Rybchenko
  2018-04-04 11:10 ` [dpdk-dev] [PATCH 2/2] app/testpmd: add commands to set loopback mode Andrew Rybchenko
@ 2018-04-06 12:09 ` Ferruh Yigit
  2018-04-09 12:01   ` Andrew Rybchenko
  2018-04-09 11:58 ` [dpdk-dev] [PATCH v2 0/3] " Andrew Rybchenko
  2 siblings, 1 reply; 10+ messages in thread
From: Ferruh Yigit @ 2018-04-06 12:09 UTC (permalink / raw)
  To: Andrew Rybchenko, dev

On 4/4/2018 12:10 PM, Andrew Rybchenko wrote:
> All loopback modes are listed in efx_loopback_type_t.
> Available loopback modes are listed per link speed in
> the enc_loopback_types member of the efx_nic_cfg_t.
> 
> Signed-off-by: Andrew Rybchenko <arybchenko@solarflare.com>
> Reviewed-by: Andy Moreton <amoreton@solarflare.com>
> Reviewed-by: Ivan Malov <ivan.malov@oktetlabs.ru>

Getting following build error with clang, can you please check?


.../dpdk/drivers/net/sfc/base/efx_port.c:122:6: error: comparison of constant 64
with expression of type 'efx_loopback_type_t' (aka 'enum efx_loopback_type_e')
is always true [-Werror,-Wtautological-constant-out-of-range-compare]
        if (EFX_TEST_QWORD_BIT(encp->enc_loopback_types[link_mode],
            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.../dpdk/drivers/net/sfc/base/efx_types.h:1590:28: note: expanded from macro
'EFX_TEST_QWORD_BIT'
#define EFX_TEST_QWORD_BIT      EFX_TEST_QWORD_BIT64
                                ^
.../dpdk/drivers/net/sfc/base/efx_types.h:1412:22: note: expanded from macro
'EFX_TEST_QWORD_BIT64'
                    __CPU_TO_LE_64(EFX_SHIFT64(_bit, FIX_LINT(0)))) != 0)
                    ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.../dpdk/drivers/net/sfc/base/efx_types.h:1290:32: note: expanded from macro
'EFX_SHIFT64'
        (((_bit) >= (_base) && (_bit) < (_base) + 64) ?                 \
                                      ^
.../dpdk/drivers/net/sfc/base/efx_types.h:269:50: note: expanded from macro
'__CPU_TO_LE_64'
#define __CPU_TO_LE_64(_x)      ((uint64_t)__NOSWAP64(_x))
                                           ~~~~~~~~~~~^~~
.../dpdk/drivers/net/sfc/base/efx_types.h:238:26: note: expanded from macro
'__NOSWAP64'
#define __NOSWAP64(_x)          (_x)
                                 ^~
1 error generated.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [dpdk-dev] [PATCH 2/2] app/testpmd: add commands to set loopback mode
  2018-04-04 11:10 ` [dpdk-dev] [PATCH 2/2] app/testpmd: add commands to set loopback mode Andrew Rybchenko
@ 2018-04-06 12:09   ` Ferruh Yigit
  0 siblings, 0 replies; 10+ messages in thread
From: Ferruh Yigit @ 2018-04-06 12:09 UTC (permalink / raw)
  To: Andrew Rybchenko, dev; +Cc: Wenzhuo Lu, Jingjing Wu

On 4/4/2018 12:10 PM, Andrew Rybchenko wrote:
> Signed-off-by: Andrew Rybchenko <arybchenko@solarflare.com>
> Reviewed-by: Roman Zhukov <roman.zhukov@oktetlabs.ru>
> Reviewed-by: Ivan Malov <ivan.malov@oktetlabs.ru
Reviewed-by: Ferruh Yigit <ferruh.yigit@intel.com>

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [dpdk-dev] [PATCH v2 0/3] net/sfc: support loopback mode configuration
  2018-04-04 11:10 [dpdk-dev] [PATCH 1/2] net/sfc: support loopback mode configuration Andrew Rybchenko
  2018-04-04 11:10 ` [dpdk-dev] [PATCH 2/2] app/testpmd: add commands to set loopback mode Andrew Rybchenko
  2018-04-06 12:09 ` [dpdk-dev] [PATCH 1/2] net/sfc: support loopback mode configuration Ferruh Yigit
@ 2018-04-09 11:58 ` Andrew Rybchenko
  2018-04-09 11:58   ` [dpdk-dev] [PATCH v2 1/3] net/sfc/base: fix comparison always true warning Andrew Rybchenko
                     ` (3 more replies)
  2 siblings, 4 replies; 10+ messages in thread
From: Andrew Rybchenko @ 2018-04-09 11:58 UTC (permalink / raw)
  To: dev; +Cc: Ferruh Yigit

v1 -> v2:
 - add patch to fix clang build error

Andrew Rybchenko (3):
  net/sfc/base: fix comparison always true warning
  net/sfc: support loopback mode configuration
  app/testpmd: add commands to set loopback mode

 app/test-pmd/cmdline.c          | 121 ++++++++++++++++++++++++++++++++++++++++
 doc/guides/nics/sfc_efx.rst     |   4 +-
 drivers/net/sfc/base/efx_port.c |   2 +-
 drivers/net/sfc/efsys.h         |   2 +-
 drivers/net/sfc/sfc.c           |   2 +
 drivers/net/sfc/sfc_port.c      |  40 +++++++++++++
 6 files changed, 167 insertions(+), 4 deletions(-)

-- 
2.7.4

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [dpdk-dev] [PATCH v2 1/3] net/sfc/base: fix comparison always true warning
  2018-04-09 11:58 ` [dpdk-dev] [PATCH v2 0/3] " Andrew Rybchenko
@ 2018-04-09 11:58   ` Andrew Rybchenko
  2018-04-09 11:58   ` [dpdk-dev] [PATCH v2 2/3] net/sfc: support loopback mode configuration Andrew Rybchenko
                     ` (2 subsequent siblings)
  3 siblings, 0 replies; 10+ messages in thread
From: Andrew Rybchenko @ 2018-04-09 11:58 UTC (permalink / raw)
  To: dev; +Cc: Ferruh Yigit, stable

Loopback type used as bit index has efx_loopback_type_t type
which is enum. clang complains that it is always true when it
is compared with qword (64 bit) bits number boundary.

Fixes: 9ee64bd404fc ("net/sfc/base: import loopback control")
Cc: stable@dpdk.org

Signed-off-by: Andrew Rybchenko <arybchenko@solarflare.com>
---
 drivers/net/sfc/base/efx_port.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/sfc/base/efx_port.c b/drivers/net/sfc/base/efx_port.c
index 261ac62..33a1a08 100644
--- a/drivers/net/sfc/base/efx_port.c
+++ b/drivers/net/sfc/base/efx_port.c
@@ -120,7 +120,7 @@ efx_port_loopback_set(
 	EFSYS_ASSERT(link_mode < EFX_LINK_NMODES);
 
 	if (EFX_TEST_QWORD_BIT(encp->enc_loopback_types[link_mode],
-		loopback_type) == 0) {
+		(int)loopback_type) == 0) {
 		rc = ENOTSUP;
 		goto fail1;
 	}
-- 
2.7.4

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [dpdk-dev] [PATCH v2 2/3] net/sfc: support loopback mode configuration
  2018-04-09 11:58 ` [dpdk-dev] [PATCH v2 0/3] " Andrew Rybchenko
  2018-04-09 11:58   ` [dpdk-dev] [PATCH v2 1/3] net/sfc/base: fix comparison always true warning Andrew Rybchenko
@ 2018-04-09 11:58   ` Andrew Rybchenko
  2018-04-09 11:58   ` [dpdk-dev] [PATCH v2 3/3] app/testpmd: add commands to set loopback mode Andrew Rybchenko
  2018-04-10 17:23   ` [dpdk-dev] [PATCH v2 0/3] net/sfc: support loopback mode configuration Ferruh Yigit
  3 siblings, 0 replies; 10+ messages in thread
From: Andrew Rybchenko @ 2018-04-09 11:58 UTC (permalink / raw)
  To: dev; +Cc: Ferruh Yigit

All loopback modes are listed in efx_loopback_type_t.
Available loopback modes are listed per link speed in
the enc_loopback_types member of the efx_nic_cfg_t.

Signed-off-by: Andrew Rybchenko <arybchenko@solarflare.com>
Reviewed-by: Andy Moreton <amoreton@solarflare.com>
Reviewed-by: Ivan Malov <ivan.malov@oktetlabs.ru>
---
 doc/guides/nics/sfc_efx.rst |  4 ++--
 drivers/net/sfc/efsys.h     |  2 +-
 drivers/net/sfc/sfc.c       |  2 ++
 drivers/net/sfc/sfc_port.c  | 40 ++++++++++++++++++++++++++++++++++++++++
 4 files changed, 45 insertions(+), 3 deletions(-)

diff --git a/doc/guides/nics/sfc_efx.rst b/doc/guides/nics/sfc_efx.rst
index c170e36..abaed67 100644
--- a/doc/guides/nics/sfc_efx.rst
+++ b/doc/guides/nics/sfc_efx.rst
@@ -88,6 +88,8 @@ SFC EFX PMD has support for:
 
 - Flow API
 
+- Loopback
+
 
 Non-supported Features
 ----------------------
@@ -98,8 +100,6 @@ The features not yet supported include:
 
 - Priority-based flow control
 
-- Loopback
-
 - Configurable RX CRC stripping (always stripped)
 
 - Header split on receive
diff --git a/drivers/net/sfc/efsys.h b/drivers/net/sfc/efsys.h
index 7eb2c3f..12f77dc 100644
--- a/drivers/net/sfc/efsys.h
+++ b/drivers/net/sfc/efsys.h
@@ -166,7 +166,7 @@ prefetch_read_once(const volatile void *addr)
 
 #define EFSYS_OPT_MAC_STATS 1
 
-#define EFSYS_OPT_LOOPBACK 0
+#define EFSYS_OPT_LOOPBACK 1
 
 #define EFSYS_OPT_MON_MCDI 0
 #define EFSYS_OPT_MON_STATS 0
diff --git a/drivers/net/sfc/sfc.c b/drivers/net/sfc/sfc.c
index 69abaff..716683b 100644
--- a/drivers/net/sfc/sfc.c
+++ b/drivers/net/sfc/sfc.c
@@ -123,10 +123,12 @@ sfc_check_conf(struct sfc_adapter *sa)
 		rc = EINVAL;
 	}
 
+#if !EFSYS_OPT_LOOPBACK
 	if (conf->lpbk_mode != 0) {
 		sfc_err(sa, "Loopback not supported");
 		rc = EINVAL;
 	}
+#endif
 
 	if (conf->dcb_capability_en != 0) {
 		sfc_err(sa, "Priority-based flow control not supported");
diff --git a/drivers/net/sfc/sfc_port.c b/drivers/net/sfc/sfc_port.c
index fd267e1..5cc3ad7 100644
--- a/drivers/net/sfc/sfc_port.c
+++ b/drivers/net/sfc/sfc_port.c
@@ -121,6 +121,28 @@ sfc_port_init_dev_link(struct sfc_adapter *sa)
 	return 0;
 }
 
+#if EFSYS_OPT_LOOPBACK
+
+static efx_link_mode_t
+sfc_port_phy_caps_to_max_link_speed(uint32_t phy_caps)
+{
+	if (phy_caps & (1u << EFX_PHY_CAP_100000FDX))
+		return EFX_LINK_100000FDX;
+	if (phy_caps & (1u << EFX_PHY_CAP_50000FDX))
+		return EFX_LINK_50000FDX;
+	if (phy_caps & (1u << EFX_PHY_CAP_40000FDX))
+		return EFX_LINK_40000FDX;
+	if (phy_caps & (1u << EFX_PHY_CAP_25000FDX))
+		return EFX_LINK_25000FDX;
+	if (phy_caps & (1u << EFX_PHY_CAP_10000FDX))
+		return EFX_LINK_10000FDX;
+	if (phy_caps & (1u << EFX_PHY_CAP_1000FDX))
+		return EFX_LINK_1000FDX;
+	return EFX_LINK_UNKNOWN;
+}
+
+#endif
+
 int
 sfc_port_start(struct sfc_adapter *sa)
 {
@@ -143,6 +165,21 @@ sfc_port_start(struct sfc_adapter *sa)
 	if (rc != 0)
 		goto fail_port_init;
 
+#if EFSYS_OPT_LOOPBACK
+	if (sa->eth_dev->data->dev_conf.lpbk_mode != 0) {
+		efx_link_mode_t link_mode;
+
+		link_mode =
+			sfc_port_phy_caps_to_max_link_speed(port->phy_adv_cap);
+		sfc_log_init(sa, "set loopback link_mode=%u type=%u", link_mode,
+			     sa->eth_dev->data->dev_conf.lpbk_mode);
+		rc = efx_port_loopback_set(sa->nic, link_mode,
+			sa->eth_dev->data->dev_conf.lpbk_mode);
+		if (rc != 0)
+			goto fail_loopback_set;
+	}
+#endif
+
 	sfc_log_init(sa, "set flow control to %#x autoneg=%u",
 		     port->flow_ctrl, port->flow_ctrl_autoneg);
 	rc = efx_mac_fcntl_set(sa->nic, port->flow_ctrl,
@@ -268,6 +305,9 @@ sfc_port_start(struct sfc_adapter *sa)
 fail_mac_pdu_set:
 fail_phy_adv_cap_set:
 fail_mac_fcntl_set:
+#if EFSYS_OPT_LOOPBACK
+fail_loopback_set:
+#endif
 	efx_port_fini(sa->nic);
 
 fail_port_init:
-- 
2.7.4

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [dpdk-dev] [PATCH v2 3/3] app/testpmd: add commands to set loopback mode
  2018-04-09 11:58 ` [dpdk-dev] [PATCH v2 0/3] " Andrew Rybchenko
  2018-04-09 11:58   ` [dpdk-dev] [PATCH v2 1/3] net/sfc/base: fix comparison always true warning Andrew Rybchenko
  2018-04-09 11:58   ` [dpdk-dev] [PATCH v2 2/3] net/sfc: support loopback mode configuration Andrew Rybchenko
@ 2018-04-09 11:58   ` Andrew Rybchenko
  2018-04-10 17:23   ` [dpdk-dev] [PATCH v2 0/3] net/sfc: support loopback mode configuration Ferruh Yigit
  3 siblings, 0 replies; 10+ messages in thread
From: Andrew Rybchenko @ 2018-04-09 11:58 UTC (permalink / raw)
  To: dev; +Cc: Ferruh Yigit

Signed-off-by: Andrew Rybchenko <arybchenko@solarflare.com>
Reviewed-by: Roman Zhukov <roman.zhukov@oktetlabs.ru>
Reviewed-by: Ivan Malov <ivan.malov@oktetlabs.ru>
Reviewed-by: Ferruh Yigit <ferruh.yigit@intel.com>
---
 app/test-pmd/cmdline.c | 121 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 121 insertions(+)

diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c
index 40b31ad..92ef7e1 100644
--- a/app/test-pmd/cmdline.c
+++ b/app/test-pmd/cmdline.c
@@ -806,6 +806,9 @@ static void cmd_help_long_parsed(void *parsed_result,
 			" duplex (half|full|auto)\n"
 			"    Set speed and duplex for all ports or port_id\n\n"
 
+			"port config (port_id|all) loopback (mode)\n"
+			"    Set loopback mode for all ports or port_id\n\n"
+
 			"port config all (rxq|txq|rxd|txd) (value)\n"
 			"    Set number for rxq/txq/rxd/txd.\n\n"
 
@@ -1487,6 +1490,122 @@ cmdline_parse_inst_t cmd_config_speed_specific = {
 	},
 };
 
+/* *** configure loopback for all ports *** */
+struct cmd_config_loopback_all {
+	cmdline_fixed_string_t port;
+	cmdline_fixed_string_t keyword;
+	cmdline_fixed_string_t all;
+	cmdline_fixed_string_t item;
+	uint32_t mode;
+};
+
+static void
+cmd_config_loopback_all_parsed(void *parsed_result,
+			__attribute__((unused)) struct cmdline *cl,
+			__attribute__((unused)) void *data)
+{
+	struct cmd_config_loopback_all *res = parsed_result;
+	portid_t pid;
+
+	if (!all_ports_stopped()) {
+		printf("Please stop all ports first\n");
+		return;
+	}
+
+	RTE_ETH_FOREACH_DEV(pid) {
+		ports[pid].dev_conf.lpbk_mode = res->mode;
+	}
+
+	cmd_reconfig_device_queue(RTE_PORT_ALL, 1, 1);
+}
+
+cmdline_parse_token_string_t cmd_config_loopback_all_port =
+	TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, port, "port");
+cmdline_parse_token_string_t cmd_config_loopback_all_keyword =
+	TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, keyword,
+							"config");
+cmdline_parse_token_string_t cmd_config_loopback_all_all =
+	TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, all, "all");
+cmdline_parse_token_string_t cmd_config_loopback_all_item =
+	TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_all, item,
+							"loopback");
+cmdline_parse_token_num_t cmd_config_loopback_all_mode =
+	TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_all, mode, UINT32);
+
+cmdline_parse_inst_t cmd_config_loopback_all = {
+	.f = cmd_config_loopback_all_parsed,
+	.data = NULL,
+	.help_str = "port config all loopback <mode>",
+	.tokens = {
+		(void *)&cmd_config_loopback_all_port,
+		(void *)&cmd_config_loopback_all_keyword,
+		(void *)&cmd_config_loopback_all_all,
+		(void *)&cmd_config_loopback_all_item,
+		(void *)&cmd_config_loopback_all_mode,
+		NULL,
+	},
+};
+
+/* *** configure loopback for specific port *** */
+struct cmd_config_loopback_specific {
+	cmdline_fixed_string_t port;
+	cmdline_fixed_string_t keyword;
+	uint16_t port_id;
+	cmdline_fixed_string_t item;
+	uint32_t mode;
+};
+
+static void
+cmd_config_loopback_specific_parsed(void *parsed_result,
+				__attribute__((unused)) struct cmdline *cl,
+				__attribute__((unused)) void *data)
+{
+	struct cmd_config_loopback_specific *res = parsed_result;
+
+	if (port_id_is_invalid(res->port_id, ENABLED_WARN))
+		return;
+
+	if (!port_is_stopped(res->port_id)) {
+		printf("Please stop port %u first\n", res->port_id);
+		return;
+	}
+
+	ports[res->port_id].dev_conf.lpbk_mode = res->mode;
+
+	cmd_reconfig_device_queue(res->port_id, 1, 1);
+}
+
+
+cmdline_parse_token_string_t cmd_config_loopback_specific_port =
+	TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, port,
+								"port");
+cmdline_parse_token_string_t cmd_config_loopback_specific_keyword =
+	TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, keyword,
+								"config");
+cmdline_parse_token_num_t cmd_config_loopback_specific_id =
+	TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, port_id,
+								UINT16);
+cmdline_parse_token_string_t cmd_config_loopback_specific_item =
+	TOKEN_STRING_INITIALIZER(struct cmd_config_loopback_specific, item,
+								"loopback");
+cmdline_parse_token_num_t cmd_config_loopback_specific_mode =
+	TOKEN_NUM_INITIALIZER(struct cmd_config_loopback_specific, mode,
+			      UINT32);
+
+cmdline_parse_inst_t cmd_config_loopback_specific = {
+	.f = cmd_config_loopback_specific_parsed,
+	.data = NULL,
+	.help_str = "port config <port_id> loopback <mode>",
+	.tokens = {
+		(void *)&cmd_config_loopback_specific_port,
+		(void *)&cmd_config_loopback_specific_keyword,
+		(void *)&cmd_config_loopback_specific_id,
+		(void *)&cmd_config_loopback_specific_item,
+		(void *)&cmd_config_loopback_specific_mode,
+		NULL,
+	},
+};
+
 /* *** configure txq/rxq, txd/rxd *** */
 struct cmd_config_rx_tx {
 	cmdline_fixed_string_t port;
@@ -16130,6 +16249,8 @@ cmdline_parse_ctx_t main_ctx[] = {
 	(cmdline_parse_inst_t *)&cmd_operate_detach_port,
 	(cmdline_parse_inst_t *)&cmd_config_speed_all,
 	(cmdline_parse_inst_t *)&cmd_config_speed_specific,
+	(cmdline_parse_inst_t *)&cmd_config_loopback_all,
+	(cmdline_parse_inst_t *)&cmd_config_loopback_specific,
 	(cmdline_parse_inst_t *)&cmd_config_rx_tx,
 	(cmdline_parse_inst_t *)&cmd_config_mtu,
 	(cmdline_parse_inst_t *)&cmd_config_max_pkt_len,
-- 
2.7.4

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [dpdk-dev] [PATCH 1/2] net/sfc: support loopback mode configuration
  2018-04-06 12:09 ` [dpdk-dev] [PATCH 1/2] net/sfc: support loopback mode configuration Ferruh Yigit
@ 2018-04-09 12:01   ` Andrew Rybchenko
  0 siblings, 0 replies; 10+ messages in thread
From: Andrew Rybchenko @ 2018-04-09 12:01 UTC (permalink / raw)
  To: Ferruh Yigit, dev

On 04/06/2018 03:09 PM, Ferruh Yigit wrote:
> On 4/4/2018 12:10 PM, Andrew Rybchenko wrote:
>> All loopback modes are listed in efx_loopback_type_t.
>> Available loopback modes are listed per link speed in
>> the enc_loopback_types member of the efx_nic_cfg_t.
>>
>> Signed-off-by: Andrew Rybchenko <arybchenko@solarflare.com>
>> Reviewed-by: Andy Moreton <amoreton@solarflare.com>
>> Reviewed-by: Ivan Malov <ivan.malov@oktetlabs.ru>
> Getting following build error with clang, can you please check?
>
>
> .../dpdk/drivers/net/sfc/base/efx_port.c:122:6: error: comparison of constant 64
> with expression of type 'efx_loopback_type_t' (aka 'enum efx_loopback_type_e')
> is always true [-Werror,-Wtautological-constant-out-of-range-compare]
>          if (EFX_TEST_QWORD_BIT(encp->enc_loopback_types[link_mode],
>              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> .../dpdk/drivers/net/sfc/base/efx_types.h:1590:28: note: expanded from macro
> 'EFX_TEST_QWORD_BIT'
> #define EFX_TEST_QWORD_BIT      EFX_TEST_QWORD_BIT64
>                                  ^
> .../dpdk/drivers/net/sfc/base/efx_types.h:1412:22: note: expanded from macro
> 'EFX_TEST_QWORD_BIT64'
>                      __CPU_TO_LE_64(EFX_SHIFT64(_bit, FIX_LINT(0)))) != 0)
>                      ~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> .../dpdk/drivers/net/sfc/base/efx_types.h:1290:32: note: expanded from macro
> 'EFX_SHIFT64'
>          (((_bit) >= (_base) && (_bit) < (_base) + 64) ?                 \
>                                        ^
> .../dpdk/drivers/net/sfc/base/efx_types.h:269:50: note: expanded from macro
> '__CPU_TO_LE_64'
> #define __CPU_TO_LE_64(_x)      ((uint64_t)__NOSWAP64(_x))
>                                             ~~~~~~~~~~~^~~
> .../dpdk/drivers/net/sfc/base/efx_types.h:238:26: note: expanded from macro
> '__NOSWAP64'
> #define __NOSWAP64(_x)          (_x)
>                                   ^~
> 1 error generated.

Thanks, I've added patch to fix the problem.

Andrew.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [dpdk-dev] [PATCH v2 0/3] net/sfc: support loopback mode configuration
  2018-04-09 11:58 ` [dpdk-dev] [PATCH v2 0/3] " Andrew Rybchenko
                     ` (2 preceding siblings ...)
  2018-04-09 11:58   ` [dpdk-dev] [PATCH v2 3/3] app/testpmd: add commands to set loopback mode Andrew Rybchenko
@ 2018-04-10 17:23   ` Ferruh Yigit
  3 siblings, 0 replies; 10+ messages in thread
From: Ferruh Yigit @ 2018-04-10 17:23 UTC (permalink / raw)
  To: Andrew Rybchenko, dev

On 4/9/2018 12:58 PM, Andrew Rybchenko wrote:
> v1 -> v2:
>  - add patch to fix clang build error
> 
> Andrew Rybchenko (3):
>   net/sfc/base: fix comparison always true warning
>   net/sfc: support loopback mode configuration
>   app/testpmd: add commands to set loopback mode

Series applied to dpdk-next-net/master, thanks.

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2018-04-10 17:23 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-04 11:10 [dpdk-dev] [PATCH 1/2] net/sfc: support loopback mode configuration Andrew Rybchenko
2018-04-04 11:10 ` [dpdk-dev] [PATCH 2/2] app/testpmd: add commands to set loopback mode Andrew Rybchenko
2018-04-06 12:09   ` Ferruh Yigit
2018-04-06 12:09 ` [dpdk-dev] [PATCH 1/2] net/sfc: support loopback mode configuration Ferruh Yigit
2018-04-09 12:01   ` Andrew Rybchenko
2018-04-09 11:58 ` [dpdk-dev] [PATCH v2 0/3] " Andrew Rybchenko
2018-04-09 11:58   ` [dpdk-dev] [PATCH v2 1/3] net/sfc/base: fix comparison always true warning Andrew Rybchenko
2018-04-09 11:58   ` [dpdk-dev] [PATCH v2 2/3] net/sfc: support loopback mode configuration Andrew Rybchenko
2018-04-09 11:58   ` [dpdk-dev] [PATCH v2 3/3] app/testpmd: add commands to set loopback mode Andrew Rybchenko
2018-04-10 17:23   ` [dpdk-dev] [PATCH v2 0/3] net/sfc: support loopback mode configuration Ferruh Yigit

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).