net/mlx5: Align sriov/eswitch modules with the new load/unload flow.
[cascardo/linux.git] / drivers / net / ethernet / mellanox / mlx5 / core / eswitch.c
index f6d6677..015f1bf 100644 (file)
@@ -87,13 +87,9 @@ void esw_offloads_cleanup(struct mlx5_eswitch *esw, int nvports);
 static int arm_vport_context_events_cmd(struct mlx5_core_dev *dev, u16 vport,
                                        u32 events_mask)
 {
-       int in[MLX5_ST_SZ_DW(modify_nic_vport_context_in)];
-       int out[MLX5_ST_SZ_DW(modify_nic_vport_context_out)];
+       int in[MLX5_ST_SZ_DW(modify_nic_vport_context_in)]   = {0};
+       int out[MLX5_ST_SZ_DW(modify_nic_vport_context_out)] = {0};
        void *nic_vport_ctx;
-       int err;
-
-       memset(out, 0, sizeof(out));
-       memset(in, 0, sizeof(in));
 
        MLX5_SET(modify_nic_vport_context_in, in,
                 opcode, MLX5_CMD_OP_MODIFY_NIC_VPORT_CONTEXT);
@@ -116,45 +112,31 @@ static int arm_vport_context_events_cmd(struct mlx5_core_dev *dev, u16 vport,
                MLX5_SET(nic_vport_context, nic_vport_ctx,
                         event_on_promisc_change, 1);
 
-       err = mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out));
-       if (err)
-               goto ex;
-       err = mlx5_cmd_status_to_err_v2(out);
-       if (err)
-               goto ex;
-       return 0;
-ex:
-       return err;
+       return mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out));
 }
 
 /* E-Switch vport context HW commands */
 static int query_esw_vport_context_cmd(struct mlx5_core_dev *mdev, u32 vport,
                                       u32 *out, int outlen)
 {
-       u32 in[MLX5_ST_SZ_DW(query_esw_vport_context_in)];
-
-       memset(in, 0, sizeof(in));
+       u32 in[MLX5_ST_SZ_DW(query_esw_vport_context_in)] = {0};
 
        MLX5_SET(query_nic_vport_context_in, in, opcode,
                 MLX5_CMD_OP_QUERY_ESW_VPORT_CONTEXT);
-
        MLX5_SET(query_esw_vport_context_in, in, vport_number, vport);
        if (vport)
                MLX5_SET(query_esw_vport_context_in, in, other_vport, 1);
-
-       return mlx5_cmd_exec_check_status(mdev, in, sizeof(in), out, outlen);
+       return mlx5_cmd_exec(mdev, in, sizeof(in), out, outlen);
 }
 
 static int query_esw_vport_cvlan(struct mlx5_core_dev *dev, u32 vport,
                                 u16 *vlan, u8 *qos)
 {
-       u32 out[MLX5_ST_SZ_DW(query_esw_vport_context_out)];
+       u32 out[MLX5_ST_SZ_DW(query_esw_vport_context_out)] = {0};
        int err;
        bool cvlan_strip;
        bool cvlan_insert;
 
-       memset(out, 0, sizeof(out));
-
        *vlan = 0;
        *qos = 0;
 
@@ -188,27 +170,20 @@ out:
 static int modify_esw_vport_context_cmd(struct mlx5_core_dev *dev, u16 vport,
                                        void *in, int inlen)
 {
-       u32 out[MLX5_ST_SZ_DW(modify_esw_vport_context_out)];
-
-       memset(out, 0, sizeof(out));
+       u32 out[MLX5_ST_SZ_DW(modify_esw_vport_context_out)] = {0};
 
+       MLX5_SET(modify_esw_vport_context_in, in, opcode,
+                MLX5_CMD_OP_MODIFY_ESW_VPORT_CONTEXT);
        MLX5_SET(modify_esw_vport_context_in, in, vport_number, vport);
        if (vport)
                MLX5_SET(modify_esw_vport_context_in, in, other_vport, 1);
-
-       MLX5_SET(modify_esw_vport_context_in, in, opcode,
-                MLX5_CMD_OP_MODIFY_ESW_VPORT_CONTEXT);
-
-       return mlx5_cmd_exec_check_status(dev, in, inlen,
-                                         out, sizeof(out));
+       return mlx5_cmd_exec(dev, in, inlen, out, sizeof(out));
 }
 
 static int modify_esw_vport_cvlan(struct mlx5_core_dev *dev, u32 vport,
                                  u16 vlan, u8 qos, bool set)
 {
-       u32 in[MLX5_ST_SZ_DW(modify_esw_vport_context_in)];
-
-       memset(in, 0, sizeof(in));
+       u32 in[MLX5_ST_SZ_DW(modify_esw_vport_context_in)] = {0};
 
        if (!MLX5_CAP_ESW(dev, vport_cvlan_strip) ||
            !MLX5_CAP_ESW(dev, vport_cvlan_insert_if_not_exist))
@@ -216,7 +191,6 @@ static int modify_esw_vport_cvlan(struct mlx5_core_dev *dev, u32 vport,
 
        esw_debug(dev, "Set Vport[%d] VLAN %d qos %d set=%d\n",
                  vport, vlan, qos, set);
-
        if (set) {
                MLX5_SET(modify_esw_vport_context_in, in,
                         esw_vport_context.vport_cvlan_strip, 1);
@@ -241,13 +215,10 @@ static int modify_esw_vport_cvlan(struct mlx5_core_dev *dev, u32 vport,
 static int set_l2_table_entry_cmd(struct mlx5_core_dev *dev, u32 index,
                                  u8 *mac, u8 vlan_valid, u16 vlan)
 {
-       u32 in[MLX5_ST_SZ_DW(set_l2_table_entry_in)];
-       u32 out[MLX5_ST_SZ_DW(set_l2_table_entry_out)];
+       u32 in[MLX5_ST_SZ_DW(set_l2_table_entry_in)]   = {0};
+       u32 out[MLX5_ST_SZ_DW(set_l2_table_entry_out)] = {0};
        u8 *in_mac_addr;
 
-       memset(in, 0, sizeof(in));
-       memset(out, 0, sizeof(out));
-
        MLX5_SET(set_l2_table_entry_in, in, opcode,
                 MLX5_CMD_OP_SET_L2_TABLE_ENTRY);
        MLX5_SET(set_l2_table_entry_in, in, table_index, index);
@@ -257,23 +228,18 @@ static int set_l2_table_entry_cmd(struct mlx5_core_dev *dev, u32 index,
        in_mac_addr = MLX5_ADDR_OF(set_l2_table_entry_in, in, mac_address);
        ether_addr_copy(&in_mac_addr[2], mac);
 
-       return mlx5_cmd_exec_check_status(dev, in, sizeof(in),
-                                         out, sizeof(out));
+       return mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out));
 }
 
 static int del_l2_table_entry_cmd(struct mlx5_core_dev *dev, u32 index)
 {
-       u32 in[MLX5_ST_SZ_DW(delete_l2_table_entry_in)];
-       u32 out[MLX5_ST_SZ_DW(delete_l2_table_entry_out)];
-
-       memset(in, 0, sizeof(in));
-       memset(out, 0, sizeof(out));
+       u32 in[MLX5_ST_SZ_DW(delete_l2_table_entry_in)]   = {0};
+       u32 out[MLX5_ST_SZ_DW(delete_l2_table_entry_out)] = {0};
 
        MLX5_SET(delete_l2_table_entry_in, in, opcode,
                 MLX5_CMD_OP_DELETE_L2_TABLE_ENTRY);
        MLX5_SET(delete_l2_table_entry_in, in, table_index, index);
-       return mlx5_cmd_exec_check_status(dev, in, sizeof(in),
-                                         out, sizeof(out));
+       return mlx5_cmd_exec(dev, in, sizeof(in), out, sizeof(out));
 }
 
 static int alloc_l2_table_index(struct mlx5_l2_table *l2_table, u32 *ix)
@@ -340,7 +306,7 @@ __esw_fdb_set_vport_rule(struct mlx5_eswitch *esw, u32 vport, bool rx_rule,
 
        spec = mlx5_vzalloc(sizeof(*spec));
        if (!spec) {
-               pr_warn("FDB: Failed to alloc match parameters\n");
+               esw_warn(esw->dev, "FDB: Failed to alloc match parameters\n");
                return NULL;
        }
        dmac_v = MLX5_ADDR_OF(fte_match_param, spec->match_value,
@@ -374,8 +340,8 @@ __esw_fdb_set_vport_rule(struct mlx5_eswitch *esw, u32 vport, bool rx_rule,
                                   MLX5_FLOW_CONTEXT_ACTION_FWD_DEST,
                                   0, &dest);
        if (IS_ERR(flow_rule)) {
-               pr_warn(
-                       "FDB: Failed to add flow rule: dmac_v(%pM) dmac_c(%pM) -> vport(%d), err(%ld)\n",
+               esw_warn(esw->dev,
+                        "FDB: Failed to add flow rule: dmac_v(%pM) dmac_c(%pM) -> vport(%d), err(%ld)\n",
                         dmac_v, dmac_c, vport, PTR_ERR(flow_rule));
                flow_rule = NULL;
        }
@@ -1352,8 +1318,9 @@ static int esw_vport_ingress_config(struct mlx5_eswitch *esw,
                                   0, NULL);
        if (IS_ERR(vport->ingress.allow_rule)) {
                err = PTR_ERR(vport->ingress.allow_rule);
-               pr_warn("vport[%d] configure ingress allow rule, err(%d)\n",
-                       vport->vport, err);
+               esw_warn(esw->dev,
+                        "vport[%d] configure ingress allow rule, err(%d)\n",
+                        vport->vport, err);
                vport->ingress.allow_rule = NULL;
                goto out;
        }
@@ -1365,8 +1332,9 @@ static int esw_vport_ingress_config(struct mlx5_eswitch *esw,
                                   0, NULL);
        if (IS_ERR(vport->ingress.drop_rule)) {
                err = PTR_ERR(vport->ingress.drop_rule);
-               pr_warn("vport[%d] configure ingress drop rule, err(%d)\n",
-                       vport->vport, err);
+               esw_warn(esw->dev,
+                        "vport[%d] configure ingress drop rule, err(%d)\n",
+                        vport->vport, err);
                vport->ingress.drop_rule = NULL;
                goto out;
        }
@@ -1418,8 +1386,9 @@ static int esw_vport_egress_config(struct mlx5_eswitch *esw,
                                   0, NULL);
        if (IS_ERR(vport->egress.allowed_vlan)) {
                err = PTR_ERR(vport->egress.allowed_vlan);
-               pr_warn("vport[%d] configure egress allowed vlan rule failed, err(%d)\n",
-                       vport->vport, err);
+               esw_warn(esw->dev,
+                        "vport[%d] configure egress allowed vlan rule failed, err(%d)\n",
+                        vport->vport, err);
                vport->egress.allowed_vlan = NULL;
                goto out;
        }
@@ -1432,8 +1401,9 @@ static int esw_vport_egress_config(struct mlx5_eswitch *esw,
                                   0, NULL);
        if (IS_ERR(vport->egress.drop_rule)) {
                err = PTR_ERR(vport->egress.drop_rule);
-               pr_warn("vport[%d] configure egress drop rule failed, err(%d)\n",
-                       vport->vport, err);
+               esw_warn(esw->dev,
+                        "vport[%d] configure egress drop rule failed, err(%d)\n",
+                        vport->vport, err);
                vport->egress.drop_rule = NULL;
        }
 out:
@@ -1451,7 +1421,8 @@ static void esw_enable_vport(struct mlx5_eswitch *esw, int vport_num,
 
        esw_debug(esw->dev, "Enabling VPORT(%d)\n", vport_num);
 
-       if (vport_num) { /* Only VFs need ACLs for VST and spoofchk filtering */
+       /* Only VFs need ACLs for VST and spoofchk filtering */
+       if (vport_num && esw->mode == SRIOV_LEGACY) {
                esw_vport_ingress_config(esw, vport);
                esw_vport_egress_config(esw, vport);
        }
@@ -1502,7 +1473,7 @@ static void esw_disable_vport(struct mlx5_eswitch *esw, int vport_num)
         */
        esw_vport_change_handle_locked(vport);
        vport->enabled_events = 0;
-       if (vport_num) {
+       if (vport_num && esw->mode == SRIOV_LEGACY) {
                esw_vport_disable_egress_acl(esw, vport);
                esw_vport_disable_ingress_acl(esw, vport);
        }
@@ -1588,6 +1559,25 @@ void mlx5_eswitch_disable_sriov(struct mlx5_eswitch *esw)
        esw_enable_vport(esw, 0, UC_ADDR_CHANGE);
 }
 
+void mlx5_eswitch_attach(struct mlx5_eswitch *esw)
+{
+       if (!esw || !MLX5_CAP_GEN(esw->dev, vport_group_manager) ||
+           MLX5_CAP_GEN(esw->dev, port_type) != MLX5_CAP_PORT_TYPE_ETH)
+               return;
+
+       esw_enable_vport(esw, 0, UC_ADDR_CHANGE);
+       /* VF Vports will be enabled when SRIOV is enabled */
+}
+
+void mlx5_eswitch_detach(struct mlx5_eswitch *esw)
+{
+       if (!esw || !MLX5_CAP_GEN(esw->dev, vport_group_manager) ||
+           MLX5_CAP_GEN(esw->dev, port_type) != MLX5_CAP_PORT_TYPE_ETH)
+               return;
+
+       esw_disable_vport(esw, 0);
+}
+
 int mlx5_eswitch_init(struct mlx5_core_dev *dev)
 {
        int l2_table_size = 1 << MLX5_CAP_GEN(dev, log_max_l2_table);
@@ -1665,8 +1655,6 @@ int mlx5_eswitch_init(struct mlx5_core_dev *dev)
        esw->mode = SRIOV_NONE;
 
        dev->priv.eswitch = esw;
-       esw_enable_vport(esw, 0, UC_ADDR_CHANGE);
-       /* VF Vports will be enabled when SRIOV is enabled */
        return 0;
 abort:
        if (esw->work_queue)
@@ -1685,7 +1673,6 @@ void mlx5_eswitch_cleanup(struct mlx5_eswitch *esw)
                return;
 
        esw_info(esw->dev, "cleanup\n");
-       esw_disable_vport(esw, 0);
 
        esw->dev->priv.eswitch = NULL;
        destroy_workqueue(esw->work_queue);
@@ -1767,7 +1754,7 @@ int mlx5_eswitch_set_vport_mac(struct mlx5_eswitch *esw,
                               vport, err);
 
        mutex_lock(&esw->state_lock);
-       if (evport->enabled)
+       if (evport->enabled && esw->mode == SRIOV_LEGACY)
                err = esw_vport_ingress_config(esw, evport);
        mutex_unlock(&esw->state_lock);
        return err;
@@ -1839,7 +1826,7 @@ int mlx5_eswitch_set_vport_vlan(struct mlx5_eswitch *esw,
        mutex_lock(&esw->state_lock);
        evport->vlan = vlan;
        evport->qos = qos;
-       if (evport->enabled) {
+       if (evport->enabled && esw->mode == SRIOV_LEGACY) {
                err = esw_vport_ingress_config(esw, evport);
                if (err)
                        goto out;
@@ -1868,10 +1855,11 @@ int mlx5_eswitch_set_vport_spoofchk(struct mlx5_eswitch *esw,
        mutex_lock(&esw->state_lock);
        pschk = evport->spoofchk;
        evport->spoofchk = spoofchk;
-       if (evport->enabled)
+       if (evport->enabled && esw->mode == SRIOV_LEGACY) {
                err = esw_vport_ingress_config(esw, evport);
-       if (err)
-               evport->spoofchk = pschk;
+               if (err)
+                       evport->spoofchk = pschk;
+       }
        mutex_unlock(&esw->state_lock);
 
        return err;
@@ -1903,7 +1891,7 @@ int mlx5_eswitch_get_vport_stats(struct mlx5_eswitch *esw,
                                 struct ifla_vf_stats *vf_stats)
 {
        int outlen = MLX5_ST_SZ_BYTES(query_vport_counter_out);
-       u32 in[MLX5_ST_SZ_DW(query_vport_counter_in)];
+       u32 in[MLX5_ST_SZ_DW(query_vport_counter_in)] = {0};
        int err = 0;
        u32 *out;
 
@@ -1916,8 +1904,6 @@ int mlx5_eswitch_get_vport_stats(struct mlx5_eswitch *esw,
        if (!out)
                return -ENOMEM;
 
-       memset(in, 0, sizeof(in));
-
        MLX5_SET(query_vport_counter_in, in, opcode,
                 MLX5_CMD_OP_QUERY_VPORT_COUNTER);
        MLX5_SET(query_vport_counter_in, in, op_mod, 0);