net/mlx5: Lag, add support to create/destroy/modify port selection
authorMaor Gottlieb <maorg@nvidia.com>
Thu, 15 Jul 2021 07:13:52 +0000 (10:13 +0300)
committerSaeed Mahameed <saeedm@nvidia.com>
Tue, 19 Oct 2021 03:18:09 +0000 (20:18 -0700)
Add create function, build the steering tables, TTC and definers
according to the LAG hash type.

The destroy function, destroys all the steering components.

The modify functions is used when the bond mapping changes and it
iterates over all the rules in the definers and modifies them to steer
the packet to the relevant active ports.

Signed-off-by: Maor Gottlieb <maorg@nvidia.com>
Reviewed-by: Mark Bloch <mbloch@nvidia.com>
Signed-off-by: Saeed Mahameed <saeedm@nvidia.com>
drivers/net/ethernet/mellanox/mlx5/core/Makefile
drivers/net/ethernet/mellanox/mlx5/core/lag/port_sel.c
drivers/net/ethernet/mellanox/mlx5/core/lag/port_sel.h

index fb123e2..bdb271b 100644 (file)
@@ -37,7 +37,7 @@ mlx5_core-$(CONFIG_MLX5_EN_ARFS)     += en_arfs.o
 mlx5_core-$(CONFIG_MLX5_EN_RXNFC)    += en_fs_ethtool.o
 mlx5_core-$(CONFIG_MLX5_CORE_EN_DCB) += en_dcbnl.o en/port_buffer.o
 mlx5_core-$(CONFIG_PCI_HYPERV_INTERFACE) += en/hv_vhca_stats.o
-mlx5_core-$(CONFIG_MLX5_ESWITCH)     += lag/mp.o lib/geneve.o lib/port_tun.o \
+mlx5_core-$(CONFIG_MLX5_ESWITCH)     += lag/mp.o lag/port_sel.o lib/geneve.o lib/port_tun.o \
                                        en_rep.o en/rep/bond.o en/mod_hdr.o \
                                        en/mapping.o
 mlx5_core-$(CONFIG_MLX5_CLS_ACT)     += en_tc.o en/rep/tc.o en/rep/neigh.o \
index a855b9e..adc836b 100644 (file)
@@ -511,3 +511,101 @@ static int mlx5_lag_create_inner_ttc_table(struct mlx5_lag *ldev)
 
        return 0;
 }
+
+int mlx5_lag_port_sel_create(struct mlx5_lag *ldev,
+                            enum netdev_lag_hash hash_type, u8 port1, u8 port2)
+{
+       struct mlx5_lag_port_sel *port_sel = &ldev->port_sel;
+       int err;
+
+       set_tt_map(port_sel, hash_type);
+       err = mlx5_lag_create_definers(ldev, hash_type, port1, port2);
+       if (err)
+               return err;
+
+       if (port_sel->tunnel) {
+               err = mlx5_lag_create_inner_ttc_table(ldev);
+               if (err)
+                       goto destroy_definers;
+       }
+
+       err = mlx5_lag_create_ttc_table(ldev);
+       if (err)
+               goto destroy_inner;
+
+       return 0;
+
+destroy_inner:
+       if (port_sel->tunnel)
+               mlx5_destroy_ttc_table(port_sel->inner.ttc);
+destroy_definers:
+       mlx5_lag_destroy_definers(ldev);
+       return err;
+}
+
+static int
+mlx5_lag_modify_definers_destinations(struct mlx5_lag *ldev,
+                                     struct mlx5_lag_definer **definers,
+                                     u8 port1, u8 port2)
+{
+       struct mlx5_lag_port_sel *port_sel = &ldev->port_sel;
+       struct mlx5_flow_destination dest = {};
+       int err;
+       int tt;
+
+       dest.type = MLX5_FLOW_DESTINATION_TYPE_UPLINK;
+       dest.vport.flags |= MLX5_FLOW_DEST_VPORT_VHCA_ID;
+
+       for_each_set_bit(tt, port_sel->tt_map, MLX5_NUM_TT) {
+               struct mlx5_flow_handle **rules = definers[tt]->rules;
+
+               if (ldev->v2p_map[MLX5_LAG_P1] != port1) {
+                       dest.vport.vhca_id =
+                               MLX5_CAP_GEN(ldev->pf[port1 - 1].dev, vhca_id);
+                       err = mlx5_modify_rule_destination(rules[MLX5_LAG_P1],
+                                                          &dest, NULL);
+                       if (err)
+                               return err;
+               }
+
+               if (ldev->v2p_map[MLX5_LAG_P2] != port2) {
+                       dest.vport.vhca_id =
+                               MLX5_CAP_GEN(ldev->pf[port2 - 1].dev, vhca_id);
+                       err = mlx5_modify_rule_destination(rules[MLX5_LAG_P2],
+                                                          &dest, NULL);
+                       if (err)
+                               return err;
+               }
+       }
+
+       return 0;
+}
+
+int mlx5_lag_port_sel_modify(struct mlx5_lag *ldev, u8 port1, u8 port2)
+{
+       struct mlx5_lag_port_sel *port_sel = &ldev->port_sel;
+       int err;
+
+       err = mlx5_lag_modify_definers_destinations(ldev,
+                                                   port_sel->outer.definers,
+                                                   port1, port2);
+       if (err)
+               return err;
+
+       if (!port_sel->tunnel)
+               return 0;
+
+       return mlx5_lag_modify_definers_destinations(ldev,
+                                                    port_sel->inner.definers,
+                                                    port1, port2);
+}
+
+void mlx5_lag_port_sel_destroy(struct mlx5_lag *ldev)
+{
+       struct mlx5_lag_port_sel *port_sel = &ldev->port_sel;
+
+       mlx5_destroy_ttc_table(port_sel->outer.ttc);
+       if (port_sel->tunnel)
+               mlx5_destroy_ttc_table(port_sel->inner.ttc);
+       mlx5_lag_destroy_definers(ldev);
+}
index 045dcee..6d15b28 100644 (file)
@@ -25,4 +25,28 @@ struct mlx5_lag_port_sel {
        struct mlx5_lag_ttc inner;
 };
 
+#ifdef CONFIG_MLX5_ESWITCH
+
+int mlx5_lag_port_sel_modify(struct mlx5_lag *ldev, u8 port1, u8 port2);
+void mlx5_lag_port_sel_destroy(struct mlx5_lag *ldev);
+int mlx5_lag_port_sel_create(struct mlx5_lag *ldev,
+                            enum netdev_lag_hash hash_type, u8 port1,
+                            u8 port2);
+
+#else /* CONFIG_MLX5_ESWITCH */
+static inline int mlx5_lag_port_sel_create(struct mlx5_lag *ldev,
+                                          enum netdev_lag_hash hash_type,
+                                          u8 port1, u8 port2)
+{
+       return 0;
+}
+
+static inline int mlx5_lag_port_sel_modify(struct mlx5_lag *ldev, u8 port1,
+                                          u8 port2)
+{
+       return 0;
+}
+
+static inline void mlx5_lag_port_sel_destroy(struct mlx5_lag *ldev) {}
+#endif /* CONFIG_MLX5_ESWITCH */
 #endif /* __MLX5_LAG_FS_H__ */