Skip to contentSkip to conversation

mlx5 updates 2021-11-16

GIT PULL Applied Saeed Mahameed 2 participants 17 messages Nov 17, 2021

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

From: Saeed Mahameed <[email protected]>

Hi Dave, Hi Jakub,

This series provides mlx5 misc updates.

For more information please see tag log below.

Please pull and let me know if there is any problem.

Thanks,
Saeed.

The following changes since commit b9241f54138ca5af4d3c5ca6db56be83d7491508:

net: document SMII and correct phylink's new validation mechanism (2021-11-16 19:22:30 -0800)

are available in the Git repository at:

git://git.kernel.org/pub/scm/linux/kernel/git/saeed/linux.git tags/mlx5-updates-2021-11-16

for you to fetch changes up to 85c5f7c9200e5ce89f0c188d0c24ab4e731b6a51:

net/mlx5: E-switch, Create QoS on demand (2021-11-16 20:31:52 -0800)

----------------------------------------------------------------
mlx5-updates-2021-11-16

Updates for mlx5 driver:

1) Support ethtool cq mode
2) Static allocation of mod header object for the common case
3) TC support for when local and remote VTEPs are in the same
4) Create E-Switch QoS objects on demand to save on resources
5) Minor code improvements

----------------------------------------------------------------
Aya Levin (1):
net/mlx5: Avoid printing health buffer when firmware is unavailable

Chris Mi (1):
net/mlx5e: Specify out ifindex when looking up decap route

Dmytro Linkin (2):
net/mlx5: E-switch, Enable vport QoS on demand net/mlx5: E-switch, Create QoS on demand

Parav Pandit (3):
net/mlx5: E-switch, Remove vport enabled check net/mlx5: E-switch, Reuse mlx5_eswitch_set_vport_mac net/mlx5: E-switch, move offloads mode callbacks to offloads file

Paul Blakey (2):
net/mlx5e: Refactor mod header management API net/mlx5: CT: Allow static allocation of mod headers

Roi Dayan (3):
net/mlx5e: TC, Destroy nic flow counter if exists net/mlx5e: TC, Move kfree() calls after destroying all resources net/mlx5e: TC, Move comment about mod header flag to correct place

Saeed Mahameed (2):
net/mlx5e: Support ethtool cq mode net/mlx5: Fix format-security build warnings

Yihao Han (1):
net/mlx5: TC, using swap() instead of tmp variable

 drivers/net/ethernet/mellanox/mlx5/core/en.h       |   7 +-
 .../net/ethernet/mellanox/mlx5/core/en/mod_hdr.c   |  58 ++++++
 .../net/ethernet/mellanox/mlx5/core/en/mod_hdr.h   |  26 +++
 .../net/ethernet/mellanox/mlx5/core/en/tc/sample.c |   5 +-
 drivers/net/ethernet/mellanox/mlx5/core/en/tc_ct.c |  39 ++--
 .../net/ethernet/mellanox/mlx5/core/en/tc_tun.c    |  23 +--
 .../net/ethernet/mellanox/mlx5/core/en/tc_tun.h    |   3 +-
 .../ethernet/mellanox/mlx5/core/en/tc_tun_encap.c  |   4 +-
 .../net/ethernet/mellanox/mlx5/core/en_ethtool.c   |  49 ++++-
 drivers/net/ethernet/mellanox/mlx5/core/en_rep.c   |   4 +-
 drivers/net/ethernet/mellanox/mlx5/core/en_stats.c |   2 +-
 drivers/net/ethernet/mellanox/mlx5/core/en_tc.c    | 110 +++--------
 drivers/net/ethernet/mellanox/mlx5/core/en_tc.h    |   5 -
 .../ethernet/mellanox/mlx5/core/esw/indir_table.c  |   5 +-
 .../net/ethernet/mellanox/mlx5/core/esw/legacy.c   |   4 +-
 drivers/net/ethernet/mellanox/mlx5/core/esw/qos.c  | 220 ++++++++++++++-------
 drivers/net/ethernet/mellanox/mlx5/core/esw/qos.h  |  14 +-
 drivers/net/ethernet/mellanox/mlx5/core/eswitch.c  |  94 +--------
 drivers/net/ethernet/mellanox/mlx5/core/eswitch.h  |  11 +-
 .../ethernet/mellanox/mlx5/core/eswitch_offloads.c |  59 ++++++
 drivers/net/ethernet/mellanox/mlx5/core/health.c   |   5 +
 .../ethernet/mellanox/mlx5/core/ipoib/ethtool.c    |   4 +-
 drivers/net/ethernet/mellanox/mlx5/core/pci_irq.c  |   2 +-
 23 files changed, 432 insertions(+), 321 deletions(-)
#1 lore raw

PATCH 1/15 net/mlx5e: Support ethtool cq mode

From: Saeed Mahameed <[email protected]>

Add support for ethtool coalesce cq mode set and get.

---
 drivers/net/ethernet/mellanox/mlx5/core/en.h  |  7 ++-
 .../ethernet/mellanox/mlx5/core/en_ethtool.c  | 49 ++++++++++++++++---
 .../net/ethernet/mellanox/mlx5/core/en_rep.c  |  4 +-
 .../mellanox/mlx5/core/ipoib/ethtool.c        |  4 +-
 4 files changed, 52 insertions(+), 12 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en.h +5 -2
index f0ac6b0d9653..48b12ee44b8d 100644
@@ -1148,9 +1148,12 @@ void mlx5e_ethtool_get_channels(struct mlx5e_priv *priv,
 int mlx5e_ethtool_set_channels(struct mlx5e_priv *priv,
 			       struct ethtool_channels *ch);
 int mlx5e_ethtool_get_coalesce(struct mlx5e_priv *priv,
-			       struct ethtool_coalesce *coal);
+			       struct ethtool_coalesce *coal,
+			       struct kernel_ethtool_coalesce *kernel_coal);
 int mlx5e_ethtool_set_coalesce(struct mlx5e_priv *priv,
-			       struct ethtool_coalesce *coal);
+			       struct ethtool_coalesce *coal,
+			       struct kernel_ethtool_coalesce *kernel_coal,
+			       struct netlink_ext_ack *extack);
 int mlx5e_ethtool_get_link_ksettings(struct mlx5e_priv *priv,
 				     struct ethtool_link_ksettings *link_ksettings);
 int mlx5e_ethtool_set_link_ksettings(struct mlx5e_priv *priv,
drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c +43 -6

105 lines not on this page · raw message

drivers/net/ethernet/mellanox/mlx5/core/en_rep.c +2 -2
index e58a9ec42553..8c81aeba07db 100644
@@ -258,7 +258,7 @@ static int mlx5e_rep_get_coalesce(struct net_device *netdev,
 {
 	struct mlx5e_priv *priv = netdev_priv(netdev);
 
-	return mlx5e_ethtool_get_coalesce(priv, coal);
+	return mlx5e_ethtool_get_coalesce(priv, coal, kernel_coal);
 }
 
 static int mlx5e_rep_set_coalesce(struct net_device *netdev,
@@ -268,7 +268,7 @@ static int mlx5e_rep_set_coalesce(struct net_device *netdev,
 {
 	struct mlx5e_priv *priv = netdev_priv(netdev);
 
-	return mlx5e_ethtool_set_coalesce(priv, coal);
+	return mlx5e_ethtool_set_coalesce(priv, coal, kernel_coal, extack);
 }
 
 static u32 mlx5e_rep_get_rxfh_key_size(struct net_device *netdev)
drivers/net/ethernet/mellanox/mlx5/core/ipoib/ethtool.c +2 -2
index 962d41418ce7..f23e33ac9c6b 100644
@@ -105,7 +105,7 @@ static int mlx5i_set_coalesce(struct net_device *netdev,
 {
 	struct mlx5e_priv *priv = mlx5i_epriv(netdev);
 
-	return mlx5e_ethtool_set_coalesce(priv, coal);
+	return mlx5e_ethtool_set_coalesce(priv, coal, kernel_coal, extack);
 }
 
 static int mlx5i_get_coalesce(struct net_device *netdev,
@@ -115,7 +115,7 @@ static int mlx5i_get_coalesce(struct net_device *netdev,
 {
 	struct mlx5e_priv *priv = mlx5i_epriv(netdev);
 
-	return mlx5e_ethtool_get_coalesce(priv, coal);
+	return mlx5e_ethtool_get_coalesce(priv, coal, kernel_coal);
 }
 
 static int mlx5i_get_ts_info(struct net_device *netdev,
Signature · 1 line
2.31.1
#3 lore raw

PATCH 2/15 net/mlx5: Fix format-security build warnings

In reply to Saeed Mahameed

From: Saeed Mahameed <[email protected]>

Treat the string as an argument to avoid this.

drivers/net/ethernet/mellanox/mlx5/core/pci_irq.c:482:5:
error: format string is not a string literal (potentially insecure)

                         name);
                         ^~~~
drivers/net/ethernet/mellanox/mlx5/core/en_stats.c:2079:4:
error: format string is not a string literal (potentially insecure)
                        ptp_ch_stats_desc[i].format);
                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~
---
 drivers/net/ethernet/mellanox/mlx5/core/en_stats.c | 2 +-
 drivers/net/ethernet/mellanox/mlx5/core/pci_irq.c  | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en_stats.c +1 -1
index 2a9bfc3ffa2e..3c91a11e27ad 100644
@@ -2076,7 +2076,7 @@ static MLX5E_DECLARE_STATS_GRP_OP_FILL_STRS(ptp)
 
 	for (i = 0; i < NUM_PTP_CH_STATS; i++)
 		sprintf(data + (idx++) * ETH_GSTRING_LEN,
-			ptp_ch_stats_desc[i].format);
+			"%s", ptp_ch_stats_desc[i].format);
 
 	if (priv->tx_ptp_opened) {
 		for (tc = 0; tc < priv->max_opened_tc; tc++)
drivers/net/ethernet/mellanox/mlx5/core/pci_irq.c +1 -1
index 830444f927d4..19bf2b66707d 100644
@@ -479,7 +479,7 @@ irq_pool_alloc(struct mlx5_core_dev *dev, int start, int size, char *name,
 	pool->xa_num_irqs.max = start + size - 1;
 	if (name)
 		snprintf(pool->name, MLX5_MAX_IRQ_NAME - MLX5_MAX_IRQ_IDX_CHARS,
-			 name);
+			 "%s", name);
 	pool->min_threshold = min_threshold * MLX5_EQ_REFS_PER_IRQ;
 	pool->max_threshold = max_threshold * MLX5_EQ_REFS_PER_IRQ;
 	mlx5_core_dbg(dev, "pool->name = %s, pool->size = %d, pool->start = %d",
Signature · 1 line
2.31.1
#5 lore raw

PATCH 4/15 net/mlx5e: Refactor mod header management API

In reply to Saeed Mahameed

From: Paul Blakey <[email protected]>

For all mod hdr related functions to reside in a single self contained component (mod_hdr.c), refactor alloc() and add get_id() so that user won't rely on internal implementation, and move both to mod_hdr component.

Rename the prefix to mlx5e_mod_hdr_* as other mod hdr functions.

---
 .../ethernet/mellanox/mlx5/core/en/mod_hdr.c  | 47 ++++++++++
 .../ethernet/mellanox/mlx5/core/en/mod_hdr.h  | 13 +++
 .../mellanox/mlx5/core/en/tc/sample.c         |  5 +-
 .../ethernet/mellanox/mlx5/core/en/tc_ct.c    | 25 ++----
 .../net/ethernet/mellanox/mlx5/core/en_tc.c   | 90 ++++---------------
 .../net/ethernet/mellanox/mlx5/core/en_tc.h   |  5 --
 .../mellanox/mlx5/core/esw/indir_table.c      |  5 +-
 7 files changed, 90 insertions(+), 100 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en/mod_hdr.c +47 -0
index 7edde4d536fd..19d05fb4aab2 100644
@@ -155,3 +155,50 @@ struct mlx5_modify_hdr *mlx5e_mod_hdr_get(struct mlx5e_mod_hdr_handle *mh)
 	return mh->modify_hdr;
 }
 
+char *
+mlx5e_mod_hdr_alloc(struct mlx5_core_dev *mdev, int namespace,
+		    struct mlx5e_tc_mod_hdr_acts *mod_hdr_acts)
+{
+	int new_num_actions, max_hw_actions;
+	size_t new_sz, old_sz;
+	void *ret;
+
+	if (mod_hdr_acts->num_actions < mod_hdr_acts->max_actions)
+		goto out;
+
+	max_hw_actions = mlx5e_mod_hdr_max_actions(mdev, namespace);
+	new_num_actions = min(max_hw_actions,
+			      mod_hdr_acts->actions ?
+			      mod_hdr_acts->max_actions * 2 : 1);
+	if (mod_hdr_acts->max_actions == new_num_actions)
+		return ERR_PTR(-ENOSPC);
+
+	new_sz = MLX5_MH_ACT_SZ * new_num_actions;
+	old_sz = mod_hdr_acts->max_actions * MLX5_MH_ACT_SZ;
+
+	ret = krealloc(mod_hdr_acts->actions, new_sz, GFP_KERNEL);
+	if (!ret)
+		return ERR_PTR(-ENOMEM);
+
+	memset(ret + old_sz, 0, new_sz - old_sz);
+	mod_hdr_acts->actions = ret;
+	mod_hdr_acts->max_actions = new_num_actions;
+
+out:
+	return mod_hdr_acts->actions + (mod_hdr_acts->num_actions * MLX5_MH_ACT_SZ);
+}
+
+void
+mlx5e_mod_hdr_dealloc(struct mlx5e_tc_mod_hdr_acts *mod_hdr_acts)
+{
+	kfree(mod_hdr_acts->actions);
+	mod_hdr_acts->actions = NULL;
+	mod_hdr_acts->num_actions = 0;
+	mod_hdr_acts->max_actions = 0;
+}
+
+char *
+mlx5e_mod_hdr_get_item(struct mlx5e_tc_mod_hdr_acts *mod_hdr_acts, int pos)
+{
+	return mod_hdr_acts->actions + (pos * MLX5_MH_ACT_SZ);
+}
drivers/net/ethernet/mellanox/mlx5/core/en/mod_hdr.h +13 -0
index 33b23d8f9182..b8cd1a7a31be 100644
@@ -15,6 +15,11 @@ struct mlx5e_tc_mod_hdr_acts {
 	void *actions;
 };
 
+char *mlx5e_mod_hdr_alloc(struct mlx5_core_dev *mdev, int namespace,
+			  struct mlx5e_tc_mod_hdr_acts *mod_hdr_acts);
+void mlx5e_mod_hdr_dealloc(struct mlx5e_tc_mod_hdr_acts *mod_hdr_acts);
+char *mlx5e_mod_hdr_get_item(struct mlx5e_tc_mod_hdr_acts *mod_hdr_acts, int pos);
+
 struct mlx5e_mod_hdr_handle *
 mlx5e_mod_hdr_attach(struct mlx5_core_dev *mdev,
 		     struct mod_hdr_tbl *tbl,
@@ -28,4 +33,12 @@ struct mlx5_modify_hdr *mlx5e_mod_hdr_get(struct mlx5e_mod_hdr_handle *mh);
 void mlx5e_mod_hdr_tbl_init(struct mod_hdr_tbl *tbl);
 void mlx5e_mod_hdr_tbl_destroy(struct mod_hdr_tbl *tbl);
 
+static inline int mlx5e_mod_hdr_max_actions(struct mlx5_core_dev *mdev, int namespace)
+{
+	if (namespace == MLX5_FLOW_NAMESPACE_FDB) /* FDB offloading */
+		return MLX5_CAP_ESW_FLOWTABLE_FDB(mdev, max_modify_header_actions);
+	else /* namespace is MLX5_FLOW_NAMESPACE_KERNEL - NIC offloading */
+		return MLX5_CAP_FLOWTABLE_NIC_RX(mdev, max_modify_header_actions);
+}
+
 #endif /* __MLX5E_EN_MOD_HDR_H__ */
drivers/net/ethernet/mellanox/mlx5/core/en/tc/sample.c +3 -2
index df6888c4793c..ff4b4f8a5a9d 100644
@@ -5,6 +5,7 @@
 #include <net/psample.h>
 #include "en/mapping.h"
 #include "en/tc/post_act.h"
+#include "en/mod_hdr.h"
 #include "sample.h"
 #include "eswitch.h"
 #include "en_tc.h"
@@ -255,12 +256,12 @@ sample_modify_hdr_get(struct mlx5_core_dev *mdev, u32 obj_id,
 		goto err_modify_hdr;
 	}
 
-	dealloc_mod_hdr_actions(&mod_acts);
+	mlx5e_mod_hdr_dealloc(&mod_acts);
 	return modify_hdr;
 
 err_modify_hdr:
 err_post_act:
-	dealloc_mod_hdr_actions(&mod_acts);
+	mlx5e_mod_hdr_dealloc(&mod_acts);
 err_set_regc0:
 	return ERR_PTR(err);
 }
drivers/net/ethernet/mellanox/mlx5/core/en/tc_ct.c +9 -16
index c1c6e74c79c4..89065fac7590 100644
@@ -609,22 +609,15 @@ mlx5_tc_ct_entry_create_nat(struct mlx5_tc_ct_priv *ct_priv,
 	struct flow_action *flow_action = &flow_rule->action;
 	struct mlx5_core_dev *mdev = ct_priv->dev;
 	struct flow_action_entry *act;
-	size_t action_size;
 	char *modact;
 	int err, i;
 
-	action_size = MLX5_UN_SZ_BYTES(set_add_copy_action_in_auto);
-
 	flow_action_for_each(i, act, flow_action) {
 		switch (act->id) {
 		case FLOW_ACTION_MANGLE: {
-			err = alloc_mod_hdr_actions(mdev, ct_priv->ns_type,
-						    mod_acts);
-			if (err)
-				return err;
-
-			modact = mod_acts->actions +
-				 mod_acts->num_actions * action_size;
+			modact = mlx5e_mod_hdr_alloc(mdev, ct_priv->ns_type, mod_acts);
+			if (IS_ERR(modact))
+				return PTR_ERR(modact);
 
 			err = mlx5_tc_ct_parse_mangle_to_mod_act(act, modact);
 			if (err)
@@ -706,11 +699,11 @@ mlx5_tc_ct_entry_create_mod_hdr(struct mlx5_tc_ct_priv *ct_priv,
 		attr->modify_hdr = mlx5e_mod_hdr_get(*mh);
 	}
 
-	dealloc_mod_hdr_actions(&mod_acts);
+	mlx5e_mod_hdr_dealloc(&mod_acts);
 	return 0;
 
 err_mapping:
-	dealloc_mod_hdr_actions(&mod_acts);
+	mlx5e_mod_hdr_dealloc(&mod_acts);
 	mlx5_put_label_mapping(ct_priv, attr->ct_attr.ct_labels_id);
 	return err;
 }
@@ -1445,7 +1438,7 @@ static int tc_ct_pre_ct_add_rules(struct mlx5_ct_ft *ct_ft,
 	}
 	pre_ct->miss_rule = rule;
 
-	dealloc_mod_hdr_actions(&pre_mod_acts);
+	mlx5e_mod_hdr_dealloc(&pre_mod_acts);
 	kvfree(spec);
 	return 0;
 
@@ -1454,7 +1447,7 @@ static int tc_ct_pre_ct_add_rules(struct mlx5_ct_ft *ct_ft,
 err_flow_rule:
 	mlx5_modify_header_dealloc(dev, pre_ct->modify_hdr);
 err_mapping:
-	dealloc_mod_hdr_actions(&pre_mod_acts);
+	mlx5e_mod_hdr_dealloc(&pre_mod_acts);
 	kvfree(spec);
 	return err;
 }
@@ -1850,14 +1843,14 @@ __mlx5_tc_ct_flow_offload(struct mlx5_tc_ct_priv *ct_priv,
 	}
 
 	attr->ct_attr.ct_flow = ct_flow;
-	dealloc_mod_hdr_actions(&pre_mod_acts);
+	mlx5e_mod_hdr_dealloc(&pre_mod_acts);
 
 	return ct_flow->pre_ct_rule;
 
 err_insert_orig:
 	mlx5_modify_header_dealloc(priv->mdev, pre_ct_attr->modify_hdr);
 err_mapping:
-	dealloc_mod_hdr_actions(&pre_mod_acts);
+	mlx5e_mod_hdr_dealloc(&pre_mod_acts);
 	mlx5_chains_put_chain_mapping(ct_priv->chains, ct_flow->chain_mapping);
 err_get_chain:
 	kfree(ct_flow->pre_ct_attr);
drivers/net/ethernet/mellanox/mlx5/core/en_tc.c +15 -75

179 lines not on this page · raw message

drivers/net/ethernet/mellanox/mlx5/core/en_tc.h +0 -5
index fdb222793027..eb042f0f5a41 100644
@@ -247,11 +247,6 @@ int mlx5e_tc_add_flow_mod_hdr(struct mlx5e_priv *priv,
 			      struct mlx5e_tc_flow_parse_attr *parse_attr,
 			      struct mlx5e_tc_flow *flow);
 
-int alloc_mod_hdr_actions(struct mlx5_core_dev *mdev,
-			  int namespace,
-			  struct mlx5e_tc_mod_hdr_acts *mod_hdr_acts);
-void dealloc_mod_hdr_actions(struct mlx5e_tc_mod_hdr_acts *mod_hdr_acts);
-
 struct mlx5e_tc_flow;
 u32 mlx5e_tc_get_flow_tun_id(struct mlx5e_tc_flow *flow);
 
drivers/net/ethernet/mellanox/mlx5/core/esw/indir_table.c +3 -2
index 425c91814b34..c275fe028b6d 100644
@@ -14,6 +14,7 @@
 #include "fs_core.h"
 #include "esw/indir_table.h"
 #include "lib/fs_chains.h"
+#include "en/mod_hdr.h"
 
 #define MLX5_ESW_INDIR_TABLE_SIZE 128
 #define MLX5_ESW_INDIR_TABLE_RECIRC_IDX_MAX (MLX5_ESW_INDIR_TABLE_SIZE - 2)
@@ -226,7 +227,7 @@ static int mlx5_esw_indir_table_rule_get(struct mlx5_eswitch *esw,
 		goto err_handle;
 	}
 
-	dealloc_mod_hdr_actions(&mod_acts);
+	mlx5e_mod_hdr_dealloc(&mod_acts);
 	rule->handle = handle;
 	rule->vni = esw_attr->rx_tun_attr->vni;
 	rule->mh = flow_act.modify_hdr;
@@ -243,7 +244,7 @@ static int mlx5_esw_indir_table_rule_get(struct mlx5_eswitch *esw,
 	mlx5_modify_header_dealloc(esw->dev, flow_act.modify_hdr);
 err_mod_hdr_alloc:
 err_mod_hdr_regc1:
-	dealloc_mod_hdr_actions(&mod_acts);
+	mlx5e_mod_hdr_dealloc(&mod_acts);
 err_mod_hdr_regc0:
 err_ethertype:
 	kfree(rule);
Signature · 1 line
2.31.1
#4 lore raw

PATCH 3/15 net/mlx5: Avoid printing health buffer when firmware is unavailable

In reply to Saeed Mahameed

From: Aya Levin <[email protected]>

Use firmware version field as an indication to health buffer's sanity. When firmware version is 0xFFFFFFFF, deduce that firmware is unavailable and avoid printing the health buffer to dmesg as it doesn't provide debug info.

---
 drivers/net/ethernet/mellanox/mlx5/core/health.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/net/ethernet/mellanox/mlx5/core/health.c +5 -0
index 64f1abc4dc36..75121bc1eaa5 100644
@@ -420,6 +420,11 @@ static void print_health_info(struct mlx5_core_dev *dev)
 	if (!ioread8(&h->synd))
 		return;
 
+	if (ioread32be(&h->fw_ver) == 0xFFFFFFFF) {
+		mlx5_log(dev, LOGLEVEL_ERR, "PCI slot is unavailable\n");
+		return;
+	}
+
 	rfr_severity = ioread8(&h->rfr_severity);
 	severity  = mlx5_health_get_severity(rfr_severity);
 	mlx5_log(dev, severity, "Health issue observed, %s, severity(%d) %s:\n",
Signature · 1 line
2.31.1
#6 lore raw

PATCH 5/15 net/mlx5: CT: Allow static allocation of mod headers

In reply to Saeed Mahameed

From: Paul Blakey <[email protected]>

As each CT rule uses at least 4 modify header actions, each rule causes at least 3 reallocations by the mod header actions api.

Allow initial static allocation of the mod acts array, and use it for CT rules. If the static allocation is exceeded go back to dynamic allocation.

---
 .../ethernet/mellanox/mlx5/core/en/mod_hdr.c    | 17 ++++++++++++++---
 .../ethernet/mellanox/mlx5/core/en/mod_hdr.h    | 13 +++++++++++++
 .../net/ethernet/mellanox/mlx5/core/en/tc_ct.c  |  9 ++++++++-
 3 files changed, 35 insertions(+), 4 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en/mod_hdr.c +14 -3
index 19d05fb4aab2..17325c5d6516 100644
@@ -176,11 +176,20 @@ mlx5e_mod_hdr_alloc(struct mlx5_core_dev *mdev, int namespace,
 	new_sz = MLX5_MH_ACT_SZ * new_num_actions;
 	old_sz = mod_hdr_acts->max_actions * MLX5_MH_ACT_SZ;
 
-	ret = krealloc(mod_hdr_acts->actions, new_sz, GFP_KERNEL);
+	if (mod_hdr_acts->is_static) {
+		ret = kzalloc(new_sz, GFP_KERNEL);
+		if (ret) {
+			memcpy(ret, mod_hdr_acts->actions, old_sz);
+			mod_hdr_acts->is_static = false;
+		}
+	} else {
+		ret = krealloc(mod_hdr_acts->actions, new_sz, GFP_KERNEL);
+		if (ret)
+			memset(ret + old_sz, 0, new_sz - old_sz);
+	}
 	if (!ret)
 		return ERR_PTR(-ENOMEM);
 
-	memset(ret + old_sz, 0, new_sz - old_sz);
 	mod_hdr_acts->actions = ret;
 	mod_hdr_acts->max_actions = new_num_actions;
 
@@ -191,7 +200,9 @@ mlx5e_mod_hdr_alloc(struct mlx5_core_dev *mdev, int namespace,
 void
 mlx5e_mod_hdr_dealloc(struct mlx5e_tc_mod_hdr_acts *mod_hdr_acts)
 {
-	kfree(mod_hdr_acts->actions);
+	if (!mod_hdr_acts->is_static)
+		kfree(mod_hdr_acts->actions);
+
 	mod_hdr_acts->actions = NULL;
 	mod_hdr_acts->num_actions = 0;
 	mod_hdr_acts->max_actions = 0;
drivers/net/ethernet/mellanox/mlx5/core/en/mod_hdr.h +13 -0
index b8cd1a7a31be..b8dac418d0a5 100644
@@ -7,14 +7,27 @@
 #include <linux/hashtable.h>
 #include <linux/mlx5/fs.h>
 
+#define MLX5_MH_ACT_SZ MLX5_UN_SZ_BYTES(set_add_copy_action_in_auto)
+
 struct mlx5e_mod_hdr_handle;
 
 struct mlx5e_tc_mod_hdr_acts {
 	int num_actions;
 	int max_actions;
+	bool is_static;
 	void *actions;
 };
 
+#define DECLARE_MOD_HDR_ACTS_ACTIONS(name, len) \
+	u8 name[len][MLX5_MH_ACT_SZ] = {}
+
+#define DECLARE_MOD_HDR_ACTS(name, acts_arr) \
+	struct mlx5e_tc_mod_hdr_acts name = { \
+		.max_actions = ARRAY_SIZE(acts_arr), \
+		.is_static = true, \
+		.actions = acts_arr, \
+	}
+
 char *mlx5e_mod_hdr_alloc(struct mlx5_core_dev *mdev, int namespace,
 			  struct mlx5e_tc_mod_hdr_acts *mod_hdr_acts);
 void mlx5e_mod_hdr_dealloc(struct mlx5e_tc_mod_hdr_acts *mod_hdr_acts);
drivers/net/ethernet/mellanox/mlx5/core/en/tc_ct.c +8 -1
index 89065fac7590..f89a4c7a4f71 100644
@@ -36,6 +36,12 @@
 #define MLX5_CT_LABELS_BITS (mlx5e_tc_attr_to_reg_mappings[LABELS_TO_REG].mlen)
 #define MLX5_CT_LABELS_MASK GENMASK(MLX5_CT_LABELS_BITS - 1, 0)
 
+/* Statically allocate modify actions for
+ * ipv6 and port nat (5) + tuple fields (4) + nic mode zone restore (1) = 10.
+ * This will be increased dynamically if needed (for the ipv6 snat + dnat).
+ */
+#define MLX5_CT_MIN_MOD_ACTS 10
+
 #define ct_dbg(fmt, args...)\
 	netdev_dbg(ct_priv->netdev, "ct_debug: " fmt "\n", ##args)
 
@@ -645,7 +651,8 @@ mlx5_tc_ct_entry_create_mod_hdr(struct mlx5_tc_ct_priv *ct_priv,
 				struct mlx5e_mod_hdr_handle **mh,
 				u8 zone_restore_id, bool nat)
 {
-	struct mlx5e_tc_mod_hdr_acts mod_acts = {};
+	DECLARE_MOD_HDR_ACTS_ACTIONS(actions_arr, MLX5_CT_MIN_MOD_ACTS);
+	DECLARE_MOD_HDR_ACTS(mod_acts, actions_arr);
 	struct flow_action_entry *meta;
 	u16 ct_state = 0;
 	int err;
Signature · 1 line
2.31.1
#7 lore raw

PATCH 6/15 net/mlx5: TC, using swap() instead of tmp variable

In reply to Saeed Mahameed

From: Yihao Han <[email protected]>

swap() was used instead of the tmp variable to swap values

---
 drivers/net/ethernet/mellanox/mlx5/core/en/tc_ct.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en/tc_ct.c +1 -4
index f89a4c7a4f71..9a31f45a9d9b 100644
@@ -907,12 +907,9 @@ mlx5_tc_ct_shared_counter_get(struct mlx5_tc_ct_priv *ct_priv,
 	struct mlx5_ct_tuple rev_tuple = entry->tuple;
 	struct mlx5_ct_counter *shared_counter;
 	struct mlx5_ct_entry *rev_entry;
-	__be16 tmp_port;
 
 	/* get the reversed tuple */
-	tmp_port = rev_tuple.port.src;
-	rev_tuple.port.src = rev_tuple.port.dst;
-	rev_tuple.port.dst = tmp_port;
+	swap(rev_tuple.port.src, rev_tuple.port.dst);
 
 	if (rev_tuple.addr_type == FLOW_DISSECTOR_KEY_IPV4_ADDRS) {
 		__be32 tmp_addr = rev_tuple.ip.src_v4;
Signature · 1 line
2.31.1
#8 lore raw

PATCH 7/15 net/mlx5e: TC, Destroy nic flow counter if exists

In reply to Saeed Mahameed

From: Roi Dayan <[email protected]>

Counter is only added if counter flag exists.
So check the counter fag exists for deleting the counter. This is the same as in add/del fdb flow.

---
 drivers/net/ethernet/mellanox/mlx5/core/en_tc.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/ethernet/mellanox/mlx5/core/en_tc.c +2 -1
index e620100eabe0..3e542b030fc1 100644
@@ -1133,7 +1133,8 @@ static void mlx5e_tc_del_nic_flow(struct mlx5e_priv *priv,
 	if (attr->action & MLX5_FLOW_CONTEXT_ACTION_MOD_HDR)
 		mlx5e_detach_mod_hdr(priv, flow);
 
-	mlx5_fc_destroy(priv->mdev, attr->counter);
+	if (attr->action & MLX5_FLOW_CONTEXT_ACTION_COUNT)
+		mlx5_fc_destroy(priv->mdev, attr->counter);
 
 	if (flow_flag_test(flow, HAIRPIN))
 		mlx5e_hairpin_flow_del(priv, flow);
Signature · 1 line
2.31.1
#9 lore raw

PATCH 8/15 net/mlx5e: TC, Move kfree() calls after destroying all resources

In reply to Saeed Mahameed

From: Roi Dayan <[email protected]>

When deleting fdb/nic flow rules first release all resources and then call the kfree() calls instead of sparse them around the function.

---
 drivers/net/ethernet/mellanox/mlx5/core/en_tc.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en_tc.c +4 -5
index 3e542b030fc1..aa4da8d1e252 100644
@@ -1128,8 +1128,6 @@ static void mlx5e_tc_del_nic_flow(struct mlx5e_priv *priv,
 	}
 	mutex_unlock(&priv->fs.tc.t_lock);
 
-	kvfree(attr->parse_attr);
-
 	if (attr->action & MLX5_FLOW_CONTEXT_ACTION_MOD_HDR)
 		mlx5e_detach_mod_hdr(priv, flow);
 
@@ -1139,6 +1137,7 @@ static void mlx5e_tc_del_nic_flow(struct mlx5e_priv *priv,
 	if (flow_flag_test(flow, HAIRPIN))
 		mlx5e_hairpin_flow_del(priv, flow);
 
+	kvfree(attr->parse_attr);
 	kfree(flow->attr);
 }
 
@@ -1626,9 +1625,6 @@ static void mlx5e_tc_del_fdb_flow(struct mlx5e_priv *priv,
 		else
 			mlx5e_detach_mod_hdr(priv, flow);
 	}
-	kfree(attr->sample_attr);
-	kvfree(attr->parse_attr);
-	kvfree(attr->esw_attr->rx_tun_attr);
 
 	if (attr->action & MLX5_FLOW_CONTEXT_ACTION_COUNT)
 		mlx5_fc_destroy(esw_attr->counter_dev, attr->counter);
@@ -1642,6 +1638,9 @@ static void mlx5e_tc_del_fdb_flow(struct mlx5e_priv *priv,
 	if (flow_flag_test(flow, L3_TO_L2_DECAP))
 		mlx5e_detach_decap(priv, flow);
 
+	kfree(attr->sample_attr);
+	kvfree(attr->esw_attr->rx_tun_attr);
+	kvfree(attr->parse_attr);
 	kfree(flow->attr);
 }
 
Signature · 1 line
2.31.1
#10 lore raw

PATCH 9/15 net/mlx5e: TC, Move comment about mod header flag to correct place

In reply to Saeed Mahameed

From: Roi Dayan <[email protected]>

Move the comment to the correct place where the driver actually removes the flag and not in the check that maybe pedit actions exists.

---
 drivers/net/ethernet/mellanox/mlx5/core/en_tc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/mellanox/mlx5/core/en_tc.c +1 -1
index aa4da8d1e252..686bb2e08e9e 100644
@@ -3424,10 +3424,10 @@ actions_prepare_mod_hdr_actions(struct mlx5e_priv *priv,
 	if (err)
 		return err;
 
-	/* In case all pedit actions are skipped, remove the MOD_HDR flag. */
 	if (parse_attr->mod_hdr_acts.num_actions > 0)
 		return 0;
 
+	/* In case all pedit actions are skipped, remove the MOD_HDR flag. */
 	attr->action &= ~MLX5_FLOW_CONTEXT_ACTION_MOD_HDR;
 	mlx5e_mod_hdr_dealloc(&parse_attr->mod_hdr_acts);
 
Signature · 1 line
2.31.1
#11 lore raw

PATCH 10/15 net/mlx5e: Specify out ifindex when looking up decap route

In reply to Saeed Mahameed

From: Chris Mi <[email protected]>

There is a use case that the local and remote VTEPs are in the same host. Currently, the out ifindex is not specified when looking up the decap route for offloads. So in this case, a local route is returned and the route dev is lo.

Actual tunnel interface can be created with a parameter "dev" [1], which specifies the physical device to use for tunnel endpoint communication. Pass this parameter to driver when looking up decap route for offloads. So that a unicast route will be returned.

[1] ip link add name vxlan1 type vxlan id 100 dev enp4s0f0 remote 1.1.1.1 dstport 4789

---
 .../ethernet/mellanox/mlx5/core/en/tc_tun.c   | 23 ++++++++++---------
 .../ethernet/mellanox/mlx5/core/en/tc_tun.h   |  3 ++-
 .../mellanox/mlx5/core/en/tc_tun_encap.c      |  4 ++--
 3 files changed, 16 insertions(+), 14 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun.c +12 -11
index a5e450973225..33815246fead 100644
@@ -103,7 +103,7 @@ static int get_route_and_out_devs(struct mlx5e_priv *priv,
 }
 
 static int mlx5e_route_lookup_ipv4_get(struct mlx5e_priv *priv,
-				       struct net_device *mirred_dev,
+				       struct net_device *dev,
 				       struct mlx5e_tc_tun_route_attr *attr)
 {
 	struct net_device *route_dev;
@@ -122,13 +122,13 @@ static int mlx5e_route_lookup_ipv4_get(struct mlx5e_priv *priv,
 		uplink_dev = mlx5_eswitch_uplink_get_proto_dev(esw, REP_ETH);
 		attr->fl.fl4.flowi4_oif = uplink_dev->ifindex;
 	} else {
-		struct mlx5e_tc_tunnel *tunnel = mlx5e_get_tc_tun(mirred_dev);
+		struct mlx5e_tc_tunnel *tunnel = mlx5e_get_tc_tun(dev);
 
 		if (tunnel && tunnel->get_remote_ifindex)
-			attr->fl.fl4.flowi4_oif = tunnel->get_remote_ifindex(mirred_dev);
+			attr->fl.fl4.flowi4_oif = tunnel->get_remote_ifindex(dev);
 	}
 
-	rt = ip_route_output_key(dev_net(mirred_dev), &attr->fl.fl4);
+	rt = ip_route_output_key(dev_net(dev), &attr->fl.fl4);
 	if (IS_ERR(rt))
 		return PTR_ERR(rt);
 
@@ -440,10 +440,10 @@ int mlx5e_tc_tun_update_header_ipv4(struct mlx5e_priv *priv,
 
 #if IS_ENABLED(CONFIG_INET) && IS_ENABLED(CONFIG_IPV6)
 static int mlx5e_route_lookup_ipv6_get(struct mlx5e_priv *priv,
-				       struct net_device *mirred_dev,
+				       struct net_device *dev,
 				       struct mlx5e_tc_tun_route_attr *attr)
 {
-	struct mlx5e_tc_tunnel *tunnel = mlx5e_get_tc_tun(mirred_dev);
+	struct mlx5e_tc_tunnel *tunnel = mlx5e_get_tc_tun(dev);
 	struct net_device *route_dev;
 	struct net_device *out_dev;
 	struct dst_entry *dst;
@@ -451,8 +451,8 @@ static int mlx5e_route_lookup_ipv6_get(struct mlx5e_priv *priv,
 	int ret;
 
 	if (tunnel && tunnel->get_remote_ifindex)
-		attr->fl.fl6.flowi6_oif = tunnel->get_remote_ifindex(mirred_dev);
-	dst = ipv6_stub->ipv6_dst_lookup_flow(dev_net(mirred_dev), NULL, &attr->fl.fl6,
+		attr->fl.fl6.flowi6_oif = tunnel->get_remote_ifindex(dev);
+	dst = ipv6_stub->ipv6_dst_lookup_flow(dev_net(dev), NULL, &attr->fl.fl6,
 					      NULL);
 	if (IS_ERR(dst))
 		return PTR_ERR(dst);
@@ -708,7 +708,8 @@ int mlx5e_tc_tun_update_header_ipv6(struct mlx5e_priv *priv,
 
 int mlx5e_tc_tun_route_lookup(struct mlx5e_priv *priv,
 			      struct mlx5_flow_spec *spec,
-			      struct mlx5_flow_attr *flow_attr)
+			      struct mlx5_flow_attr *flow_attr,
+			      struct net_device *filter_dev)
 {
 	struct mlx5_esw_flow_attr *esw_attr = flow_attr->esw_attr;
 	struct mlx5e_tc_int_port *int_port;
@@ -720,14 +721,14 @@ int mlx5e_tc_tun_route_lookup(struct mlx5e_priv *priv,
 		/* Addresses are swapped for decap */
 		attr.fl.fl4.saddr = esw_attr->rx_tun_attr->dst_ip.v4;
 		attr.fl.fl4.daddr = esw_attr->rx_tun_attr->src_ip.v4;
-		err = mlx5e_route_lookup_ipv4_get(priv, priv->netdev, &attr);
+		err = mlx5e_route_lookup_ipv4_get(priv, filter_dev, &attr);
 	}
 #if IS_ENABLED(CONFIG_INET) && IS_ENABLED(CONFIG_IPV6)
 	else if (flow_attr->tun_ip_version == 6) {
 		/* Addresses are swapped for decap */
 		attr.fl.fl6.saddr = esw_attr->rx_tun_attr->dst_ip.v6;
 		attr.fl.fl6.daddr = esw_attr->rx_tun_attr->src_ip.v6;
-		err = mlx5e_route_lookup_ipv6_get(priv, priv->netdev, &attr);
+		err = mlx5e_route_lookup_ipv6_get(priv, filter_dev, &attr);
 	}
 #endif
 	else
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun.h +2 -1
index aa092eaeaec3..b38f693bbb52 100644
@@ -94,7 +94,8 @@ mlx5e_tc_tun_update_header_ipv6(struct mlx5e_priv *priv,
 #endif
 int mlx5e_tc_tun_route_lookup(struct mlx5e_priv *priv,
 			      struct mlx5_flow_spec *spec,
-			      struct mlx5_flow_attr *attr);
+			      struct mlx5_flow_attr *attr,
+			      struct net_device *filter_dev);
 
 bool mlx5e_tc_tun_device_to_offload(struct mlx5e_priv *priv,
 				    struct net_device *netdev);
drivers/net/ethernet/mellanox/mlx5/core/en/tc_tun_encap.c +2 -2
index 660cca73c36c..de16bbc08679 100644
@@ -1153,7 +1153,7 @@ int mlx5e_attach_decap_route(struct mlx5e_priv *priv,
 
 	tbl_time_before = mlx5e_route_tbl_get_last_update(priv);
 	tbl_time_after = tbl_time_before;
-	err = mlx5e_tc_tun_route_lookup(priv, &parse_attr->spec, attr);
+	err = mlx5e_tc_tun_route_lookup(priv, &parse_attr->spec, attr, parse_attr->filter_dev);
 	if (err || !esw_attr->rx_tun_attr->decap_vport)
 		goto out;
 
@@ -1474,7 +1474,7 @@ static void mlx5e_reoffload_decap(struct mlx5e_priv *priv,
 
 		parse_attr = attr->parse_attr;
 		spec = &parse_attr->spec;
-		err = mlx5e_tc_tun_route_lookup(priv, spec, attr);
+		err = mlx5e_tc_tun_route_lookup(priv, spec, attr, parse_attr->filter_dev);
 		if (err) {
 			mlx5_core_warn(priv->mdev, "Failed to lookup route for flow, %d\n",
 				       err);
Signature · 1 line
2.31.1
#12 lore raw

PATCH 11/15 net/mlx5: E-switch, Remove vport enabled check

In reply to Saeed Mahameed

From: Parav Pandit <[email protected]>

An eswitch vport of the devlink port is always enabled before a devlink port is registered. And a eswitch vport is always disabled after a devlink port is unregistered.
Hence avoid the vport enabled check in the devlink callback routine. Such check is only applicable in the legacy SR-IOV callbacks.

---
 .../net/ethernet/mellanox/mlx5/core/eswitch.c   | 17 +++++------------
 1 file changed, 5 insertions(+), 12 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/eswitch.c +5 -12
index ec136b499204..b039f8b07d31 100644
@@ -1704,7 +1704,6 @@ int mlx5_devlink_port_function_hw_addr_get(struct devlink_port *port,
 {
 	struct mlx5_eswitch *esw;
 	struct mlx5_vport *vport;
-	int err = -EOPNOTSUPP;
 	u16 vport_num;
 
 	esw = mlx5_devlink_eswitch_get(port->devlink);
@@ -1722,13 +1721,10 @@ int mlx5_devlink_port_function_hw_addr_get(struct devlink_port *port,
 	}
 
 	mutex_lock(&esw->state_lock);
-	if (vport->enabled) {
-		ether_addr_copy(hw_addr, vport->info.mac);
-		*hw_addr_len = ETH_ALEN;
-		err = 0;
-	}
+	ether_addr_copy(hw_addr, vport->info.mac);
+	*hw_addr_len = ETH_ALEN;
 	mutex_unlock(&esw->state_lock);
-	return err;
+	return 0;
 }
 
 int mlx5_devlink_port_function_hw_addr_set(struct devlink_port *port,
@@ -1737,8 +1733,8 @@ int mlx5_devlink_port_function_hw_addr_set(struct devlink_port *port,
 {
 	struct mlx5_eswitch *esw;
 	struct mlx5_vport *vport;
-	int err = -EOPNOTSUPP;
 	u16 vport_num;
+	int err;
 
 	esw = mlx5_devlink_eswitch_get(port->devlink);
 	if (IS_ERR(esw)) {
@@ -1758,10 +1754,7 @@ int mlx5_devlink_port_function_hw_addr_set(struct devlink_port *port,
 	}
 
 	mutex_lock(&esw->state_lock);
-	if (vport->enabled)
-		err = mlx5_esw_set_vport_mac_locked(esw, vport, hw_addr);
-	else
-		NL_SET_ERR_MSG_MOD(extack, "Eswitch vport is disabled");
+	err = mlx5_esw_set_vport_mac_locked(esw, vport, hw_addr);
 	mutex_unlock(&esw->state_lock);
 	return err;
 }
Signature · 1 line
2.31.1
#13 lore raw

PATCH 12/15 net/mlx5: E-switch, Reuse mlx5_eswitch_set_vport_mac

In reply to Saeed Mahameed

From: Parav Pandit <[email protected]>

mlx5_eswitch_set_vport_mac() routine already does necessary checks which are duplicated in implementation of mlx5_devlink_port_function_hw_addr_set().

Hence, reuse mlx5_eswitch_set_vport_mac() and cut down the code.

---
 drivers/net/ethernet/mellanox/mlx5/core/eswitch.c | 12 +-----------
 1 file changed, 1 insertion(+), 11 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/eswitch.c +1 -11
index b039f8b07d31..c0526fc27ad6 100644
@@ -1732,9 +1732,7 @@ int mlx5_devlink_port_function_hw_addr_set(struct devlink_port *port,
 					   struct netlink_ext_ack *extack)
 {
 	struct mlx5_eswitch *esw;
-	struct mlx5_vport *vport;
 	u16 vport_num;
-	int err;
 
 	esw = mlx5_devlink_eswitch_get(port->devlink);
 	if (IS_ERR(esw)) {
@@ -1747,16 +1745,8 @@ int mlx5_devlink_port_function_hw_addr_set(struct devlink_port *port,
 		NL_SET_ERR_MSG_MOD(extack, "Port doesn't support set hw_addr");
 		return -EINVAL;
 	}
-	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);
-	err = mlx5_esw_set_vport_mac_locked(esw, vport, hw_addr);
-	mutex_unlock(&esw->state_lock);
-	return err;
+	return mlx5_eswitch_set_vport_mac(esw, vport_num, hw_addr);
 }
 
 int mlx5_eswitch_set_vport_state(struct mlx5_eswitch *esw,
Signature · 1 line
2.31.1
#14 lore raw

PATCH 13/15 net/mlx5: E-switch, move offloads mode callbacks to offloads file

In reply to Saeed Mahameed

From: Parav Pandit <[email protected]>

eswitch.c is mainly for common code between legacy and offloads mode. MAC address get and set via devlink is applicable only in offloads mode.

Hence, move it to eswitch_offloads.c file.

---
 .../net/ethernet/mellanox/mlx5/core/eswitch.c | 59 -------------------
 .../mellanox/mlx5/core/eswitch_offloads.c     | 59 +++++++++++++++++++
 2 files changed, 59 insertions(+), 59 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/eswitch.c +0 -59
index c0526fc27ad6..ec5b1641d40c 100644
@@ -1690,65 +1690,6 @@ bool mlx5_esw_is_sf_vport(struct mlx5_eswitch *esw, u16 vport_num)
 	return mlx5_esw_check_port_type(esw, vport_num, MLX5_ESW_VPT_SF);
 }
 
-static bool
-is_port_function_supported(struct mlx5_eswitch *esw, u16 vport_num)
-{
-	return vport_num == MLX5_VPORT_PF ||
-	       mlx5_eswitch_is_vf_vport(esw, vport_num) ||
-	       mlx5_esw_is_sf_vport(esw, vport_num);
-}
-
-int mlx5_devlink_port_function_hw_addr_get(struct devlink_port *port,
-					   u8 *hw_addr, int *hw_addr_len,
-					   struct netlink_ext_ack *extack)
-{
-	struct mlx5_eswitch *esw;
-	struct mlx5_vport *vport;
-	u16 vport_num;
-
-	esw = mlx5_devlink_eswitch_get(port->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);
-	ether_addr_copy(hw_addr, vport->info.mac);
-	*hw_addr_len = ETH_ALEN;
-	mutex_unlock(&esw->state_lock);
-	return 0;
-}
-
-int mlx5_devlink_port_function_hw_addr_set(struct devlink_port *port,
-					   const u8 *hw_addr, int hw_addr_len,
-					   struct netlink_ext_ack *extack)
-{
-	struct mlx5_eswitch *esw;
-	u16 vport_num;
-
-	esw = mlx5_devlink_eswitch_get(port->devlink);
-	if (IS_ERR(esw)) {
-		NL_SET_ERR_MSG_MOD(extack, "Eswitch doesn't support set hw_addr");
-		return PTR_ERR(esw);
-	}
-
-	vport_num = mlx5_esw_devlink_port_index_to_vport_num(port->index);
-	if (!is_port_function_supported(esw, vport_num)) {
-		NL_SET_ERR_MSG_MOD(extack, "Port doesn't support set hw_addr");
-		return -EINVAL;
-	}
-
-	return mlx5_eswitch_set_vport_mac(esw, vport_num, hw_addr);
-}
-
 int mlx5_eswitch_set_vport_state(struct mlx5_eswitch *esw,
 				 u16 vport, int link_state)
 {
drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c +59 -0

62 lines not on this page · raw message

Signature · 1 line
2.31.1
#15 lore raw

PATCH 14/15 net/mlx5: E-switch, Enable vport QoS on demand

In reply to Saeed Mahameed

From: Dmytro Linkin <[email protected]>

Vports' QoS is not commonly used but consume SW/HW resources, which becomes an issue on BlueField SoC systems.
Don't enable QoS on vports by default on eswitch mode change and enable when it's going to be used by one of the top level users:
- configuring TC matchall filter with police action;
- setting rate with legacy NDO API;
- calling devlink ops->rate_leaf_*() callbacks.

Disable vport QoS on vport cleanup.

---
 .../ethernet/mellanox/mlx5/core/esw/legacy.c  |  4 +-
 .../net/ethernet/mellanox/mlx5/core/esw/qos.c | 82 +++++++++++++------
 .../net/ethernet/mellanox/mlx5/core/esw/qos.h | 12 +--
 .../net/ethernet/mellanox/mlx5/core/eswitch.c |  9 +-
 4 files changed, 64 insertions(+), 43 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/esw/legacy.c +1 -3
index df277a6cddc0..2b52f7c09152 100644
@@ -522,9 +522,7 @@ int mlx5_eswitch_set_vport_rate(struct mlx5_eswitch *esw, u16 vport,
 		return PTR_ERR(evport);
 
 	mutex_lock(&esw->state_lock);
-	err = mlx5_esw_qos_set_vport_min_rate(esw, evport, min_rate, NULL);
-	if (!err)
-		err = mlx5_esw_qos_set_vport_max_rate(esw, evport, max_rate, NULL);
+	err = mlx5_esw_qos_set_vport_rate(esw, evport, max_rate, min_rate);
 	mutex_unlock(&esw->state_lock);
 	return err;
 }
drivers/net/ethernet/mellanox/mlx5/core/esw/qos.c +57 -25

144 lines not on this page · raw message

drivers/net/ethernet/mellanox/mlx5/core/esw/qos.h +2 -10
index 28451abe2d2f..91b66c1b9881 100644
@@ -6,18 +6,10 @@
 
 #ifdef CONFIG_MLX5_ESWITCH
 
-int mlx5_esw_qos_set_vport_min_rate(struct mlx5_eswitch *esw,
-				    struct mlx5_vport *evport,
-				    u32 min_rate,
-				    struct netlink_ext_ack *extack);
-int mlx5_esw_qos_set_vport_max_rate(struct mlx5_eswitch *esw,
-				    struct mlx5_vport *evport,
-				    u32 max_rate,
-				    struct netlink_ext_ack *extack);
+int mlx5_esw_qos_set_vport_rate(struct mlx5_eswitch *esw, struct mlx5_vport *evport,
+				u32 max_rate, u32 min_rate);
 void mlx5_esw_qos_create(struct mlx5_eswitch *esw);
 void mlx5_esw_qos_destroy(struct mlx5_eswitch *esw);
-int mlx5_esw_qos_vport_enable(struct mlx5_eswitch *esw, struct mlx5_vport *vport,
-			      u32 max_rate, u32 bw_share);
 void mlx5_esw_qos_vport_disable(struct mlx5_eswitch *esw, struct mlx5_vport *vport);
 
 int mlx5_esw_devlink_rate_leaf_tx_share_set(struct devlink_rate *rate_leaf, void *priv,
drivers/net/ethernet/mellanox/mlx5/core/eswitch.c +4 -5
index ec5b1641d40c..2d188f462028 100644
@@ -781,9 +781,6 @@ static int esw_vport_setup(struct mlx5_eswitch *esw, struct mlx5_vport *vport)
 	if (err)
 		return err;
 
-	/* Attach vport to the eswitch rate limiter */
-	mlx5_esw_qos_vport_enable(esw, vport, vport->qos.max_rate, vport->qos.bw_share);
-
 	if (mlx5_esw_is_manager_vport(esw, vport_num))
 		return 0;
 
@@ -1746,8 +1743,10 @@ int mlx5_eswitch_get_vport_config(struct mlx5_eswitch *esw,
 	ivi->qos = evport->info.qos;
 	ivi->spoofchk = evport->info.spoofchk;
 	ivi->trusted = evport->info.trusted;
-	ivi->min_tx_rate = evport->qos.min_rate;
-	ivi->max_tx_rate = evport->qos.max_rate;
+	if (evport->qos.enabled) {
+		ivi->min_tx_rate = evport->qos.min_rate;
+		ivi->max_tx_rate = evport->qos.max_rate;
+	}
 	mutex_unlock(&esw->state_lock);
 
 	return 0;
Signature · 1 line
2.31.1
#16 lore raw

PATCH 15/15 net/mlx5: E-switch, Create QoS on demand

In reply to Saeed Mahameed

From: Dmytro Linkin <[email protected]>

Don't create eswitch QoS (root TSAR) on switch mode change. Create it on first child TSAR object creation - vport or rate group. Keep track root TSAR references and release root TSAR with last object deletion. No need to check for QoS is enabled when installing tc matchall filter. Remove related helper function due to no users of it.

---
 .../net/ethernet/mellanox/mlx5/core/en_tc.c   |   6 -
 .../net/ethernet/mellanox/mlx5/core/esw/qos.c | 152 ++++++++++++------
 .../net/ethernet/mellanox/mlx5/core/esw/qos.h |   2 -
 .../net/ethernet/mellanox/mlx5/core/eswitch.c |   9 +-
 .../net/ethernet/mellanox/mlx5/core/eswitch.h |  11 +-
 5 files changed, 111 insertions(+), 69 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en_tc.c +0 -6
index 686bb2e08e9e..55e384abd364 100644
@@ -4948,14 +4948,8 @@ static int scan_tc_matchall_fdb_actions(struct mlx5e_priv *priv,
 int mlx5e_tc_configure_matchall(struct mlx5e_priv *priv,
 				struct tc_cls_matchall_offload *ma)
 {
-	struct mlx5_eswitch *esw = priv->mdev->priv.eswitch;
 	struct netlink_ext_ack *extack = ma->common.extack;
 
-	if (!mlx5_esw_qos_enabled(esw)) {
-		NL_SET_ERR_MSG_MOD(extack, "QoS is not supported on this device");
-		return -EOPNOTSUPP;
-	}
-
 	if (ma->common.prio != 1) {
 		NL_SET_ERR_MSG_MOD(extack, "only priority 1 is supported");
 		return -EINVAL;
drivers/net/ethernet/mellanox/mlx5/core/esw/qos.c +101 -51

277 lines not on this page · raw message

drivers/net/ethernet/mellanox/mlx5/core/esw/qos.h +0 -2
index 91b66c1b9881..0141e9d52037 100644
@@ -8,8 +8,6 @@
 
 int mlx5_esw_qos_set_vport_rate(struct mlx5_eswitch *esw, struct mlx5_vport *evport,
 				u32 max_rate, u32 min_rate);
-void mlx5_esw_qos_create(struct mlx5_eswitch *esw);
-void mlx5_esw_qos_destroy(struct mlx5_eswitch *esw);
 void mlx5_esw_qos_vport_disable(struct mlx5_eswitch *esw, struct mlx5_vport *vport);
 
 int mlx5_esw_devlink_rate_leaf_tx_share_set(struct devlink_rate *rate_leaf, void *priv,
drivers/net/ethernet/mellanox/mlx5/core/eswitch.c +5 -4
index 2d188f462028..46532dd42b43 100644
@@ -1257,8 +1257,6 @@ int mlx5_eswitch_enable_locked(struct mlx5_eswitch *esw, int mode, int num_vfs)
 
 	mlx5_eswitch_update_num_of_vfs(esw, num_vfs);
 
-	mlx5_esw_qos_create(esw);
-
 	esw->mode = mode;
 
 	if (mode == MLX5_ESWITCH_LEGACY) {
@@ -1287,7 +1285,6 @@ int mlx5_eswitch_enable_locked(struct mlx5_eswitch *esw, int mode, int num_vfs)
 	if (mode == MLX5_ESWITCH_OFFLOADS)
 		mlx5_rescan_drivers(esw->dev);
 
-	mlx5_esw_qos_destroy(esw);
 	mlx5_esw_acls_ns_cleanup(esw);
 	return err;
 }
@@ -1327,6 +1324,7 @@ int mlx5_eswitch_enable(struct mlx5_eswitch *esw, int num_vfs)
 
 void mlx5_eswitch_disable_locked(struct mlx5_eswitch *esw, bool clear_vf)
 {
+	struct devlink *devlink = priv_to_devlink(esw->dev);
 	int old_mode;
 
 	lockdep_assert_held_write(&esw->mode_lock);
@@ -1356,7 +1354,8 @@ void mlx5_eswitch_disable_locked(struct mlx5_eswitch *esw, bool clear_vf)
 	if (old_mode == MLX5_ESWITCH_OFFLOADS)
 		mlx5_rescan_drivers(esw->dev);
 
-	mlx5_esw_qos_destroy(esw);
+	devlink_rate_nodes_destroy(devlink);
+
 	mlx5_esw_acls_ns_cleanup(esw);
 
 	if (clear_vf)
@@ -1565,6 +1564,7 @@ int mlx5_eswitch_init(struct mlx5_core_dev *dev)
 	lockdep_register_key(&esw->mode_lock_key);
 	init_rwsem(&esw->mode_lock);
 	lockdep_set_class(&esw->mode_lock, &esw->mode_lock_key);
+	refcount_set(&esw->qos.refcnt, 0);
 
 	esw->enabled_vports = 0;
 	esw->mode = MLX5_ESWITCH_NONE;
@@ -1598,6 +1598,7 @@ void mlx5_eswitch_cleanup(struct mlx5_eswitch *esw)
 
 	esw->dev->priv.eswitch = NULL;
 	destroy_workqueue(esw->work_queue);
+	WARN_ON(refcount_read(&esw->qos.refcnt));
 	lockdep_unregister_key(&esw->mode_lock_key);
 	mutex_destroy(&esw->state_lock);
 	WARN_ON(!xa_empty(&esw->offloads.vhca_map));
drivers/net/ethernet/mellanox/mlx5/core/eswitch.h +5 -6
index 42f8ee2e5d9f..513f741d16c7 100644
@@ -308,10 +308,14 @@ struct mlx5_eswitch {
 	atomic64_t user_count;
 
 	struct {
-		bool            enabled;
 		u32             root_tsar_ix;
 		struct mlx5_esw_rate_group *group0;
 		struct list_head groups; /* Protected by esw->state_lock */
+
+		/* Protected by esw->state_lock.
+		 * Initially 0, meaning no QoS users and QoS is disabled.
+		 */
+		refcount_t refcnt;
 	} qos;
 
 	struct mlx5_esw_bridge_offloads *br_offloads;
@@ -516,11 +520,6 @@ int mlx5_eswitch_del_vlan_action(struct mlx5_eswitch *esw,
 int __mlx5_eswitch_set_vport_vlan(struct mlx5_eswitch *esw,
 				  u16 vport, u16 vlan, u8 qos, u8 set_flags);
 
-static inline bool mlx5_esw_qos_enabled(struct mlx5_eswitch *esw)
-{
-	return esw->qos.enabled;
-}
-
 static inline bool mlx5_eswitch_vlan_actions_supported(struct mlx5_core_dev *dev,
 						       u8 vlan_depth)
 {
Signature · 1 line
2.31.1
#2 lore raw

Re: [net-next v0 01/15] net/mlx5e: Support ethtool cq mode

In reply to Saeed Mahameed
This series was applied to netdev/net-next.git (master) by Saeed Mahameed <[email protected]>:

Hello:

This series was applied to netdev/net-next.git (master) by Saeed Mahameed <[email protected]>:

Quoted 8 lines · On Tue, 16 Nov 2021 20:33:43 -0800 you wrote:

From: Saeed Mahameed <[email protected]>

Add support for ethtool coalesce cq mode set and get.

[...]

Here is the summary with links:
- [net-next,v0,01/15] net/mlx5e: Support ethtool cq mode

    https://git.kernel.org/netdev/net-next/c/bc541621f8ba
  - [net-next,v0,02/15] net/mlx5: Fix format-security build warnings
    https://git.kernel.org/netdev/net-next/c/aef0f8c67d75
  - [net-next,v0,03/15] net/mlx5: Avoid printing health buffer when firmware is unavailable
    https://git.kernel.org/netdev/net-next/c/f28a14c1dcb0
  - [net-next,v0,04/15] net/mlx5e: Refactor mod header management API
    https://git.kernel.org/netdev/net-next/c/2c0e5cf5206e
  - [net-next,v0,05/15] net/mlx5: CT: Allow static allocation of mod headers
    https://git.kernel.org/netdev/net-next/c/1cfd3490f278
  - [net-next,v0,06/15] net/mlx5: TC, using swap() instead of tmp variable
    https://git.kernel.org/netdev/net-next/c/0164a9bd9d63
  - [net-next,v0,07/15] net/mlx5e: TC, Destroy nic flow counter if exists
    https://git.kernel.org/netdev/net-next/c/972fe492e847
  - [net-next,v0,08/15] net/mlx5e: TC, Move kfree() calls after destroying all resources
    https://git.kernel.org/netdev/net-next/c/88d974860412
  - [net-next,v0,09/15] net/mlx5e: TC, Move comment about mod header flag to correct place
    https://git.kernel.org/netdev/net-next/c/fc3a879aea35
  - [net-next,v0,10/15] net/mlx5e: Specify out ifindex when looking up decap route
    https://git.kernel.org/netdev/net-next/c/819c319c8c91
  - [net-next,v0,11/15] net/mlx5: E-switch, Remove vport enabled check
    https://git.kernel.org/netdev/net-next/c/fcf8ec54b047
  - [net-next,v0,12/15] net/mlx5: E-switch, Reuse mlx5_eswitch_set_vport_mac
    https://git.kernel.org/netdev/net-next/c/b22fd4381d15
  - [net-next,v0,13/15] net/mlx5: E-switch, move offloads mode callbacks to offloads file
    https://git.kernel.org/netdev/net-next/c/e9d491a64755
  - [net-next,v0,14/15] net/mlx5: E-switch, Enable vport QoS on demand
    https://git.kernel.org/netdev/net-next/c/d7df09f5e7b4
  - [net-next,v0,15/15] net/mlx5: E-switch, Create QoS on demand
    https://git.kernel.org/netdev/net-next/c/85c5f7c9200e

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html