net/mlx5: E-switch, Support querying port function mac address
authorParav Pandit <parav@mellanox.com>
Fri, 19 Jun 2020 03:32:53 +0000 (03:32 +0000)
committerDavid S. Miller <davem@davemloft.net>
Mon, 22 Jun 2020 22:29:19 +0000 (15:29 -0700)
Support querying mac address of the eswitch devlink port function.

Signed-off-by: Parav Pandit <parav@mellanox.com>
Reviewed-by: Roi Dayan <roid@mellanox.com>
Acked-by: Jiri Pirko <jiri@mellanox.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/mellanox/mlx5/core/devlink.c
drivers/net/ethernet/mellanox/mlx5/core/eswitch.c
drivers/net/ethernet/mellanox/mlx5/core/eswitch.h

index a99fe4b..3177d24 100644 (file)
@@ -113,6 +113,7 @@ static const struct devlink_ops mlx5_devlink_ops = {
        .eswitch_inline_mode_get = mlx5_devlink_eswitch_inline_mode_get,
        .eswitch_encap_mode_set = mlx5_devlink_eswitch_encap_mode_set,
        .eswitch_encap_mode_get = mlx5_devlink_eswitch_encap_mode_get,
+       .port_function_hw_addr_get = mlx5_devlink_port_function_hw_addr_get,
 #endif
        .flash_update = mlx5_devlink_flash_update,
        .info_get = mlx5_devlink_info_get,
index 9f04fd1..999e516 100644 (file)
@@ -1845,6 +1845,49 @@ unlock:
        return err;
 }
 
+static bool
+is_port_function_supported(const struct mlx5_eswitch *esw, u16 vport_num)
+{
+       return vport_num == MLX5_VPORT_PF ||
+              mlx5_eswitch_is_vf_vport(esw, vport_num);
+}
+
+int mlx5_devlink_port_function_hw_addr_get(struct devlink *devlink,
+                                          struct devlink_port *port,
+                                          u8 *hw_addr, int *hw_addr_len,
+                                          struct netlink_ext_ack *extack)
+{
+       struct mlx5_eswitch *esw;
+       struct mlx5_vport *vport;
+       int err = -EOPNOTSUPP;
+       u16 vport_num;
+
+       esw = mlx5_devlink_eswitch_get(devlink);
+       if (IS_ERR(esw))
+               return PTR_ERR(esw);
+
+       vport_num = mlx5_esw_devlink_port_index_to_vport_num(port->index);
+       if (!is_port_function_supported(esw, vport_num))
+               return -EOPNOTSUPP;
+
+       vport = mlx5_eswitch_get_vport(esw, vport_num);
+       if (IS_ERR(vport)) {
+               NL_SET_ERR_MSG_MOD(extack, "Invalid port");
+               return PTR_ERR(vport);
+       }
+
+       mutex_lock(&esw->state_lock);
+       if (vport->enabled) {
+               ether_addr_copy(hw_addr, vport->info.mac);
+               *hw_addr_len = ETH_ALEN;
+               err = 0;
+       } else {
+               NL_SET_ERR_MSG_MOD(extack, "Eswitch vport is disabled");
+       }
+       mutex_unlock(&esw->state_lock);
+       return err;
+}
+
 int mlx5_eswitch_set_vport_state(struct mlx5_eswitch *esw,
                                 u16 vport, int link_state)
 {
index 8f53718..19cd0af 100644 (file)
@@ -450,6 +450,11 @@ int mlx5_devlink_eswitch_encap_mode_set(struct devlink *devlink,
                                        struct netlink_ext_ack *extack);
 int mlx5_devlink_eswitch_encap_mode_get(struct devlink *devlink,
                                        enum devlink_eswitch_encap_mode *encap);
+int mlx5_devlink_port_function_hw_addr_get(struct devlink *devlink,
+                                          struct devlink_port *port,
+                                          u8 *hw_addr, int *hw_addr_len,
+                                          struct netlink_ext_ack *extack);
+
 void *mlx5_eswitch_get_uplink_priv(struct mlx5_eswitch *esw, u8 rep_type);
 
 int mlx5_eswitch_add_vlan_action(struct mlx5_eswitch *esw,
@@ -572,6 +577,12 @@ mlx5_esw_vport_to_devlink_port_index(const struct mlx5_core_dev *dev,
        return (MLX5_CAP_GEN(dev, vhca_id) << 16) | vport_num;
 }
 
+static inline u16
+mlx5_esw_devlink_port_index_to_vport_num(unsigned int dl_port_index)
+{
+       return dl_port_index & 0xffff;
+}
+
 /* TODO: This mlx5e_tc function shouldn't be called by eswitch */
 void mlx5e_tc_clean_fdb_peer_flows(struct mlx5_eswitch *esw);