net/mlx5: Handle host PF vport mac/guid for ECPF
authorBodong Wang <bodong@mellanox.com>
Fri, 28 Jun 2019 22:36:13 +0000 (22:36 +0000)
committerSaeed Mahameed <saeedm@mellanox.com>
Mon, 1 Jul 2019 23:40:30 +0000 (16:40 -0700)
When ECPF is eswitch manager, it has the privilege to query and
configure the mac and node guid of host PF.

While vport number of host PF is 0, the vport command should be
issued with other_vport set in this case as the cmd is issued by
ECPF vport(0xfffe).

Add a specific function to query own vport mac. Low level functions
are used by vport manager to query/modify any vport mac and node guid.

Signed-off-by: Bodong Wang <bodong@mellanox.com>
Signed-off-by: Saeed Mahameed <saeedm@mellanox.com>
drivers/net/ethernet/mellanox/mlx5/core/en_dcbnl.c
drivers/net/ethernet/mellanox/mlx5/core/en_main.c
drivers/net/ethernet/mellanox/mlx5/core/en_rep.c
drivers/net/ethernet/mellanox/mlx5/core/eswitch.c
drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c
drivers/net/ethernet/mellanox/mlx5/core/fpga/conn.c
drivers/net/ethernet/mellanox/mlx5/core/rdma.c
drivers/net/ethernet/mellanox/mlx5/core/vport.c
include/linux/mlx5/vport.h

index 554672e..8dd31b5 100644 (file)
@@ -680,7 +680,7 @@ static void mlx5e_dcbnl_getpermhwaddr(struct net_device *netdev,
 
        memset(perm_addr, 0xff, MAX_ADDR_LEN);
 
-       mlx5_query_nic_vport_mac_address(priv->mdev, 0, perm_addr);
+       mlx5_query_mac_address(priv->mdev, perm_addr);
 }
 
 static void mlx5e_dcbnl_setpgtccfgtx(struct net_device *netdev,
index 457cc39..bc9150f 100644 (file)
@@ -4581,7 +4581,7 @@ static void mlx5e_set_netdev_dev_addr(struct net_device *netdev)
 {
        struct mlx5e_priv *priv = netdev_priv(netdev);
 
-       mlx5_query_nic_vport_mac_address(priv->mdev, 0, netdev->dev_addr);
+       mlx5_query_mac_address(priv->mdev, netdev->dev_addr);
        if (is_zero_ether_addr(netdev->dev_addr) &&
            !MLX5_CAP_GEN(priv->mdev, vport_group_manager)) {
                eth_hw_addr_random(netdev);
index 33f8f99..abe8540 100644 (file)
@@ -1394,7 +1394,7 @@ static void mlx5e_build_rep_netdev(struct net_device *netdev)
                SET_NETDEV_DEV(netdev, mdev->device);
                netdev->netdev_ops = &mlx5e_netdev_ops_uplink_rep;
                /* we want a persistent mac for the uplink rep */
-               mlx5_query_nic_vport_mac_address(mdev, 0, netdev->dev_addr);
+               mlx5_query_mac_address(mdev, netdev->dev_addr);
                netdev->ethtool_ops = &mlx5e_uplink_rep_ethtool_ops;
 #ifdef CONFIG_MLX5_CORE_EN_DCB
                if (MLX5_CAP_GEN(mdev, qos))
index 0c75219..a758755 100644 (file)
@@ -897,7 +897,7 @@ static void esw_vport_change_handle_locked(struct mlx5_vport *vport)
        struct mlx5_eswitch *esw = dev->priv.eswitch;
        u8 mac[ETH_ALEN];
 
-       mlx5_query_nic_vport_mac_address(dev, vport->vport, mac);
+       mlx5_query_nic_vport_mac_address(dev, vport->vport, true, mac);
        esw_debug(dev, "vport[%d] Context Changed: perm mac: %pM\n",
                  vport->vport, mac);
 
index 105c210..b253bdf 100644 (file)
@@ -1407,7 +1407,7 @@ int esw_offloads_init_reps(struct mlx5_eswitch *esw)
        if (!esw->offloads.vport_reps)
                return -ENOMEM;
 
-       mlx5_query_nic_vport_mac_address(dev, 0, hw_id);
+       mlx5_query_mac_address(dev, hw_id);
 
        mlx5_esw_for_all_reps(esw, vport_index, rep) {
                rep->vport = mlx5_eswitch_index_to_vport_num(esw, vport_index);
index ca2296a..d61d536 100644 (file)
@@ -867,7 +867,7 @@ struct mlx5_fpga_conn *mlx5_fpga_conn_create(struct mlx5_fpga_device *fdev,
        conn->cb_arg = attr->cb_arg;
 
        remote_mac = MLX5_ADDR_OF(fpga_qpc, conn->fpga_qpc, remote_mac_47_32);
-       err = mlx5_query_nic_vport_mac_address(fdev->mdev, 0, remote_mac);
+       err = mlx5_query_mac_address(fdev->mdev, remote_mac);
        if (err) {
                mlx5_fpga_err(fdev, "Failed to query local MAC: %d\n", err);
                ret = ERR_PTR(err);
index 401441a..17ce9dd 100644 (file)
@@ -126,7 +126,7 @@ static void mlx5_rdma_make_default_gid(struct mlx5_core_dev *dev, union ib_gid *
 {
        u8 hw_id[ETH_ALEN];
 
-       mlx5_query_nic_vport_mac_address(dev, 0, hw_id);
+       mlx5_query_mac_address(dev, hw_id);
        gid->global.subnet_prefix = cpu_to_be64(0xfe80000000000000LL);
        addrconf_addr_eui48(&gid->raw[8], hw_id);
 }
index 95cdc8c..670fa49 100644 (file)
@@ -155,11 +155,12 @@ int mlx5_modify_nic_vport_min_inline(struct mlx5_core_dev *mdev,
 }
 
 int mlx5_query_nic_vport_mac_address(struct mlx5_core_dev *mdev,
-                                    u16 vport, u8 *addr)
+                                    u16 vport, bool other, u8 *addr)
 {
-       u32 *out;
        int outlen = MLX5_ST_SZ_BYTES(query_nic_vport_context_out);
+       u32 in[MLX5_ST_SZ_DW(query_nic_vport_context_in)] = {};
        u8 *out_addr;
+       u32 *out;
        int err;
 
        out = kvzalloc(outlen, GFP_KERNEL);
@@ -169,7 +170,12 @@ int mlx5_query_nic_vport_mac_address(struct mlx5_core_dev *mdev,
        out_addr = MLX5_ADDR_OF(query_nic_vport_context_out, out,
                                nic_vport_context.permanent_address);
 
-       err = mlx5_query_nic_vport_context(mdev, vport, out, outlen);
+       MLX5_SET(query_nic_vport_context_in, in, opcode,
+                MLX5_CMD_OP_QUERY_NIC_VPORT_CONTEXT);
+       MLX5_SET(query_nic_vport_context_in, in, vport_number, vport);
+       MLX5_SET(query_nic_vport_context_in, in, other_vport, other);
+
+       err = mlx5_cmd_exec(mdev, in, sizeof(in), out, outlen);
        if (!err)
                ether_addr_copy(addr, &out_addr[2]);
 
@@ -178,6 +184,12 @@ int mlx5_query_nic_vport_mac_address(struct mlx5_core_dev *mdev,
 }
 EXPORT_SYMBOL_GPL(mlx5_query_nic_vport_mac_address);
 
+int mlx5_query_mac_address(struct mlx5_core_dev *mdev, u8 *addr)
+{
+       return mlx5_query_nic_vport_mac_address(mdev, 0, false, addr);
+}
+EXPORT_SYMBOL_GPL(mlx5_query_mac_address);
+
 int mlx5_modify_nic_vport_mac_address(struct mlx5_core_dev *mdev,
                                      u16 vport, u8 *addr)
 {
@@ -194,9 +206,7 @@ int mlx5_modify_nic_vport_mac_address(struct mlx5_core_dev *mdev,
        MLX5_SET(modify_nic_vport_context_in, in,
                 field_select.permanent_address, 1);
        MLX5_SET(modify_nic_vport_context_in, in, vport_number, vport);
-
-       if (vport)
-               MLX5_SET(modify_nic_vport_context_in, in, other_vport, 1);
+       MLX5_SET(modify_nic_vport_context_in, in, other_vport, 1);
 
        nic_vport_ctx = MLX5_ADDR_OF(modify_nic_vport_context_in,
                                     in, nic_vport_context);
@@ -291,9 +301,7 @@ int mlx5_query_nic_vport_mac_list(struct mlx5_core_dev *dev,
                 MLX5_CMD_OP_QUERY_NIC_VPORT_CONTEXT);
        MLX5_SET(query_nic_vport_context_in, in, allowed_list_type, list_type);
        MLX5_SET(query_nic_vport_context_in, in, vport_number, vport);
-
-       if (vport)
-               MLX5_SET(query_nic_vport_context_in, in, other_vport, 1);
+       MLX5_SET(query_nic_vport_context_in, in, other_vport, 1);
 
        err = mlx5_cmd_exec(dev, in, sizeof(in), out, out_sz);
        if (err)
@@ -483,7 +491,7 @@ int mlx5_modify_nic_vport_node_guid(struct mlx5_core_dev *mdev,
        MLX5_SET(modify_nic_vport_context_in, in,
                 field_select.node_guid, 1);
        MLX5_SET(modify_nic_vport_context_in, in, vport_number, vport);
-       MLX5_SET(modify_nic_vport_context_in, in, other_vport, !!vport);
+       MLX5_SET(modify_nic_vport_context_in, in, other_vport, 1);
 
        nic_vport_context = MLX5_ADDR_OF(modify_nic_vport_context_in,
                                         in, nic_vport_context);
index 3d1c6cd..c147acc 100644 (file)
@@ -69,7 +69,8 @@ u8 mlx5_query_vport_state(struct mlx5_core_dev *mdev, u8 opmod, u16 vport);
 int mlx5_modify_vport_admin_state(struct mlx5_core_dev *mdev, u8 opmod,
                                  u16 vport, u8 other_vport, u8 state);
 int mlx5_query_nic_vport_mac_address(struct mlx5_core_dev *mdev,
-                                    u16 vport, u8 *addr);
+                                    u16 vport, bool other, u8 *addr);
+int mlx5_query_mac_address(struct mlx5_core_dev *mdev, u8 *addr);
 int mlx5_query_nic_vport_min_inline(struct mlx5_core_dev *mdev,
                                    u16 vport, u8 *min_inline);
 void mlx5_query_min_inline(struct mlx5_core_dev *mdev, u8 *min_inline);