]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/commitdiff
mlxsw: spectrum: Implement loopback ethtool feature
authorJiri Pirko <jiri@mellanox.com>
Sun, 5 May 2019 06:48:06 +0000 (09:48 +0300)
committerDavid S. Miller <davem@davemloft.net>
Mon, 6 May 2019 04:56:57 +0000 (21:56 -0700)
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>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/mellanox/mlxsw/spectrum.c

index f594c6a913ec69993247115dafb9a2d9f15e74dd..dbb425717f5ed4971ecdfc4b01f3bdfef555aac6 100644 (file)
@@ -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;