All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net-next 0/3] mlxsw: spectrum: Implement loopback ethtool feature
@ 2019-05-05  6:48 Ido Schimmel
  2019-05-05  6:48 ` [PATCH net-next 1/3] mlxsw: reg: Add Port Physical Loopback Register Ido Schimmel
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Ido Schimmel @ 2019-05-05  6:48 UTC (permalink / raw)
  To: netdev; +Cc: davem, jiri, mlxsw, Ido Schimmel

From: Ido Schimmel <idosch@mellanox.com>

This patchset from Jiri allows users to enable loopback feature for
individual ports using ethtool. The loopback feature is useful for
testing purposes and will also be used by upcoming patchsets to enable
the monitoring of buffer drops.

Patch #1 adds the relevant device register.

Patch #2 Implements support in the driver.

Patch #3 adds a selftest.

Jiri Pirko (3):
  mlxsw: reg: Add Port Physical Loopback Register
  mlxsw: spectrum: Implement loopback ethtool feature
  selftests: Add loopback test

 drivers/net/ethernet/mellanox/mlxsw/reg.h     | 37 ++++++++
 .../net/ethernet/mellanox/mlxsw/spectrum.c    | 35 ++++++-
 .../selftests/net/forwarding/loopback.sh      | 94 +++++++++++++++++++
 3 files changed, 164 insertions(+), 2 deletions(-)
 create mode 100755 tools/testing/selftests/net/forwarding/loopback.sh

-- 
2.20.1


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

* [PATCH net-next 1/3] mlxsw: reg: Add Port Physical Loopback Register
  2019-05-05  6:48 [PATCH net-next 0/3] mlxsw: spectrum: Implement loopback ethtool feature Ido Schimmel
@ 2019-05-05  6:48 ` Ido Schimmel
  2019-05-05  6:48 ` [PATCH net-next 2/3] mlxsw: spectrum: Implement loopback ethtool feature Ido Schimmel
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Ido Schimmel @ 2019-05-05  6:48 UTC (permalink / raw)
  To: netdev; +Cc: davem, jiri, mlxsw, Ido Schimmel

From: Jiri Pirko <jiri@mellanox.com>

The PPLR register allows configuration of the port's loopback mode.

Signed-off-by: Jiri Pirko <jiri@mellanox.com>
Signed-off-by: Ido Schimmel <idosch@mellanox.com>
---
 drivers/net/ethernet/mellanox/mlxsw/reg.h | 37 +++++++++++++++++++++++
 1 file changed, 37 insertions(+)

diff --git a/drivers/net/ethernet/mellanox/mlxsw/reg.h b/drivers/net/ethernet/mellanox/mlxsw/reg.h
index e1ee7f4994db..e8002bfc1e8f 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/reg.h
+++ b/drivers/net/ethernet/mellanox/mlxsw/reg.h
@@ -5210,6 +5210,42 @@ static inline void mlxsw_reg_pspa_pack(char *payload, u8 swid, u8 local_port)
 	mlxsw_reg_pspa_sub_port_set(payload, 0);
 }
 
+/* PPLR - Port Physical Loopback Register
+ * --------------------------------------
+ * This register allows configuration of the port's loopback mode.
+ */
+#define MLXSW_REG_PPLR_ID 0x5018
+#define MLXSW_REG_PPLR_LEN 0x8
+
+MLXSW_REG_DEFINE(pplr, MLXSW_REG_PPLR_ID, MLXSW_REG_PPLR_LEN);
+
+/* reg_pplr_local_port
+ * Local port number.
+ * Access: Index
+ */
+MLXSW_ITEM32(reg, pplr, local_port, 0x00, 16, 8);
+
+/* Phy local loopback. When set the port's egress traffic is looped back
+ * to the receiver and the port transmitter is disabled.
+ */
+#define MLXSW_REG_PPLR_LB_TYPE_BIT_PHY_LOCAL BIT(1)
+
+/* reg_pplr_lb_en
+ * Loopback enable.
+ * Access: RW
+ */
+MLXSW_ITEM32(reg, pplr, lb_en, 0x04, 0, 8);
+
+static inline void mlxsw_reg_pplr_pack(char *payload, u8 local_port,
+				       bool phy_local)
+{
+	MLXSW_REG_ZERO(pplr, payload);
+	mlxsw_reg_pplr_local_port_set(payload, local_port);
+	mlxsw_reg_pplr_lb_en_set(payload,
+				 phy_local ?
+				 MLXSW_REG_PPLR_LB_TYPE_BIT_PHY_LOCAL : 0);
+}
+
 /* HTGT - Host Trap Group Table
  * ----------------------------
  * Configures the properties for forwarding to CPU.
@@ -9981,6 +10017,7 @@ static const struct mlxsw_reg_info *mlxsw_reg_infos[] = {
 	MLXSW_REG(pptb),
 	MLXSW_REG(pbmc),
 	MLXSW_REG(pspa),
+	MLXSW_REG(pplr),
 	MLXSW_REG(htgt),
 	MLXSW_REG(hpkt),
 	MLXSW_REG(rgcr),
-- 
2.20.1


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

* [PATCH net-next 2/3] mlxsw: spectrum: Implement loopback ethtool feature
  2019-05-05  6:48 [PATCH net-next 0/3] mlxsw: spectrum: Implement loopback ethtool feature Ido Schimmel
  2019-05-05  6:48 ` [PATCH net-next 1/3] mlxsw: reg: Add Port Physical Loopback Register Ido Schimmel
@ 2019-05-05  6:48 ` Ido Schimmel
  2019-05-05  6:48 ` [PATCH net-next 3/3] selftests: Add loopback test Ido Schimmel
  2019-05-06  4:57 ` [PATCH net-next 0/3] mlxsw: spectrum: Implement loopback ethtool feature David Miller
  3 siblings, 0 replies; 5+ messages in thread
From: Ido Schimmel @ 2019-05-05  6:48 UTC (permalink / raw)
  To: netdev; +Cc: davem, jiri, mlxsw, Ido Schimmel

From: Jiri Pirko <jiri@mellanox.com>

Allow user to enable loopback feature for individual ports using ethtool.

Signed-off-by: Jiri Pirko <jiri@mellanox.com>
Signed-off-by: Ido Schimmel <idosch@mellanox.com>
---
 .../net/ethernet/mellanox/mlxsw/spectrum.c    | 35 +++++++++++++++++--
 1 file changed, 33 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum.c
index a6c6d5ee9ead..cbb02e37ec41 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/spectrum.c
+++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum.c
@@ -1669,6 +1669,25 @@ static int mlxsw_sp_feature_hw_tc(struct net_device *dev, bool enable)
 	return 0;
 }
 
+static int mlxsw_sp_feature_loopback(struct net_device *dev, bool enable)
+{
+	struct mlxsw_sp_port *mlxsw_sp_port = netdev_priv(dev);
+	char pplr_pl[MLXSW_REG_PPLR_LEN];
+	int err;
+
+	if (netif_running(dev))
+		mlxsw_sp_port_admin_status_set(mlxsw_sp_port, false);
+
+	mlxsw_reg_pplr_pack(pplr_pl, mlxsw_sp_port->local_port, enable);
+	err = mlxsw_reg_write(mlxsw_sp_port->mlxsw_sp->core, MLXSW_REG(pplr),
+			      pplr_pl);
+
+	if (netif_running(dev))
+		mlxsw_sp_port_admin_status_set(mlxsw_sp_port, true);
+
+	return err;
+}
+
 typedef int (*mlxsw_sp_feature_handler)(struct net_device *dev, bool enable);
 
 static int mlxsw_sp_handle_feature(struct net_device *dev,
@@ -1700,8 +1719,20 @@ static int mlxsw_sp_handle_feature(struct net_device *dev,
 static int mlxsw_sp_set_features(struct net_device *dev,
 				 netdev_features_t features)
 {
-	return mlxsw_sp_handle_feature(dev, features, NETIF_F_HW_TC,
+	netdev_features_t oper_features = dev->features;
+	int err = 0;
+
+	err |= mlxsw_sp_handle_feature(dev, features, NETIF_F_HW_TC,
 				       mlxsw_sp_feature_hw_tc);
+	err |= mlxsw_sp_handle_feature(dev, features, NETIF_F_LOOPBACK,
+				       mlxsw_sp_feature_loopback);
+
+	if (err) {
+		dev->features = oper_features;
+		return -EINVAL;
+	}
+
+	return 0;
 }
 
 static struct devlink_port *
@@ -3452,7 +3483,7 @@ static int mlxsw_sp_port_create(struct mlxsw_sp *mlxsw_sp, u8 local_port,
 
 	dev->features |= NETIF_F_NETNS_LOCAL | NETIF_F_LLTX | NETIF_F_SG |
 			 NETIF_F_HW_VLAN_CTAG_FILTER | NETIF_F_HW_TC;
-	dev->hw_features |= NETIF_F_HW_TC;
+	dev->hw_features |= NETIF_F_HW_TC | NETIF_F_LOOPBACK;
 
 	dev->min_mtu = 0;
 	dev->max_mtu = ETH_MAX_MTU;
-- 
2.20.1


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

* [PATCH net-next 3/3] selftests: Add loopback test
  2019-05-05  6:48 [PATCH net-next 0/3] mlxsw: spectrum: Implement loopback ethtool feature Ido Schimmel
  2019-05-05  6:48 ` [PATCH net-next 1/3] mlxsw: reg: Add Port Physical Loopback Register Ido Schimmel
  2019-05-05  6:48 ` [PATCH net-next 2/3] mlxsw: spectrum: Implement loopback ethtool feature Ido Schimmel
@ 2019-05-05  6:48 ` Ido Schimmel
  2019-05-06  4:57 ` [PATCH net-next 0/3] mlxsw: spectrum: Implement loopback ethtool feature David Miller
  3 siblings, 0 replies; 5+ messages in thread
From: Ido Schimmel @ 2019-05-05  6:48 UTC (permalink / raw)
  To: netdev; +Cc: davem, jiri, mlxsw, Ido Schimmel

From: Jiri Pirko <jiri@mellanox.com>

Add selftest for loopback feature

Signed-off-by: Jiri Pirko <jiri@mellanox.com>
Signed-off-by: Ido Schimmel <idosch@mellanox.com>
---
 .../selftests/net/forwarding/loopback.sh      | 94 +++++++++++++++++++
 1 file changed, 94 insertions(+)
 create mode 100755 tools/testing/selftests/net/forwarding/loopback.sh

diff --git a/tools/testing/selftests/net/forwarding/loopback.sh b/tools/testing/selftests/net/forwarding/loopback.sh
new file mode 100755
index 000000000000..6e4626ae71b0
--- /dev/null
+++ b/tools/testing/selftests/net/forwarding/loopback.sh
@@ -0,0 +1,94 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+
+ALL_TESTS="loopback_test"
+NUM_NETIFS=2
+source tc_common.sh
+source lib.sh
+
+h1_create()
+{
+	simple_if_init $h1 192.0.2.1/24
+	tc qdisc add dev $h1 clsact
+}
+
+h1_destroy()
+{
+	tc qdisc del dev $h1 clsact
+	simple_if_fini $h1 192.0.2.1/24
+}
+
+h2_create()
+{
+	simple_if_init $h2
+}
+
+h2_destroy()
+{
+	simple_if_fini $h2
+}
+
+loopback_test()
+{
+	RET=0
+
+	tc filter add dev $h1 ingress protocol arp pref 1 handle 101 flower \
+		skip_hw arp_op reply arp_tip 192.0.2.1 action drop
+
+	$MZ $h1 -c 1 -t arp -q
+
+	tc_check_packets "dev $h1 ingress" 101 1
+	check_fail $? "Matched on a filter without loopback setup"
+
+	ethtool -K $h1 loopback on
+	check_err $? "Failed to enable loopback"
+
+	setup_wait_dev $h1
+
+	$MZ $h1 -c 1 -t arp -q
+
+	tc_check_packets "dev $h1 ingress" 101 1
+	check_err $? "Did not match on filter with loopback"
+
+	ethtool -K $h1 loopback off
+	check_err $? "Failed to disable loopback"
+
+	$MZ $h1 -c 1 -t arp -q
+
+	tc_check_packets "dev $h1 ingress" 101 2
+	check_fail $? "Matched on a filter after loopback was removed"
+
+	tc filter del dev $h1 ingress protocol arp pref 1 handle 101 flower
+
+	log_test "loopback"
+}
+
+setup_prepare()
+{
+	h1=${NETIFS[p1]}
+	h2=${NETIFS[p2]}
+
+	vrf_prepare
+
+	h1_create
+	h2_create
+}
+
+cleanup()
+{
+	pre_cleanup
+
+	h2_destroy
+	h1_destroy
+
+	vrf_cleanup
+}
+
+trap cleanup EXIT
+
+setup_prepare
+setup_wait
+
+tests_run
+
+exit $EXIT_STATUS
-- 
2.20.1


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

* Re: [PATCH net-next 0/3] mlxsw: spectrum: Implement loopback ethtool feature
  2019-05-05  6:48 [PATCH net-next 0/3] mlxsw: spectrum: Implement loopback ethtool feature Ido Schimmel
                   ` (2 preceding siblings ...)
  2019-05-05  6:48 ` [PATCH net-next 3/3] selftests: Add loopback test Ido Schimmel
@ 2019-05-06  4:57 ` David Miller
  3 siblings, 0 replies; 5+ messages in thread
From: David Miller @ 2019-05-06  4:57 UTC (permalink / raw)
  To: idosch; +Cc: netdev, jiri, mlxsw, idosch

From: Ido Schimmel <idosch@idosch.org>
Date: Sun,  5 May 2019 09:48:04 +0300

> From: Ido Schimmel <idosch@mellanox.com>
> 
> This patchset from Jiri allows users to enable loopback feature for
> individual ports using ethtool. The loopback feature is useful for
> testing purposes and will also be used by upcoming patchsets to enable
> the monitoring of buffer drops.
> 
> Patch #1 adds the relevant device register.
> 
> Patch #2 Implements support in the driver.
> 
> Patch #3 adds a selftest.

Series applied.

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

end of thread, other threads:[~2019-05-06  4:57 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-05  6:48 [PATCH net-next 0/3] mlxsw: spectrum: Implement loopback ethtool feature Ido Schimmel
2019-05-05  6:48 ` [PATCH net-next 1/3] mlxsw: reg: Add Port Physical Loopback Register Ido Schimmel
2019-05-05  6:48 ` [PATCH net-next 2/3] mlxsw: spectrum: Implement loopback ethtool feature Ido Schimmel
2019-05-05  6:48 ` [PATCH net-next 3/3] selftests: Add loopback test Ido Schimmel
2019-05-06  4:57 ` [PATCH net-next 0/3] mlxsw: spectrum: Implement loopback ethtool feature David Miller

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.