netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [patch net-next v2 00/12] expose devlink instances relationships
@ 2023-09-13  7:12 Jiri Pirko
  2023-09-13  7:12 ` [patch net-next v2 01/12] devlink: move linecard struct into linecard.c Jiri Pirko
                   ` (13 more replies)
  0 siblings, 14 replies; 15+ messages in thread
From: Jiri Pirko @ 2023-09-13  7:12 UTC (permalink / raw)
  To: netdev
  Cc: kuba, pabeni, davem, edumazet, idosch, petrm, jacob.e.keller,
	moshe, shayd, saeedm, horms

From: Jiri Pirko <jiri@nvidia.com>

Currently, the user can instantiate new SF using "devlink port add"
command. That creates an E-switch representor devlink port.

When user activates this SF, there is an auxiliary device created and
probed for it which leads to SF devlink instance creation.

There is 1:1 relationship between E-switch representor devlink port and
the SF auxiliary device devlink instance.

Also, for example in mlx5, one devlink instance is created for
PCI device and one is created for an auxiliary device that represents
the uplink port. The relation between these is invisible to the user.

Patches #1-#3 and #5 are small preparations.

Patch #4 adds netnsid attribute for nested devlink if that in a
different namespace.

Patch #5 is the main one in this set, introduces the relationship
tracking infrastructure later on used to track SFs, linecards and
devlink instance relationships with nested devlink instances.

Expose the relation to the user by introducing new netlink attribute
DEVLINK_PORT_FN_ATTR_DEVLINK which contains the devlink instance related
to devlink port function. This is done by patch #8.
Patch #9 implements this in mlx5 driver.

Patch #10 converts the linecard nested devlink handling to the newly
introduced rel infrastructure.

Patch #11 benefits from the rel infra and introduces possiblitily to
have relation between devlink instances.
Patch #12 implements this in mlx5 driver.

Examples:
$ devlink dev
pci/0000:08:00.0: nested_devlink auxiliary/mlx5_core.eth.0
pci/0000:08:00.1: nested_devlink auxiliary/mlx5_core.eth.1
auxiliary/mlx5_core.eth.1
auxiliary/mlx5_core.eth.0

$ devlink port add pci/0000:08:00.0 flavour pcisf pfnum 0 sfnum 106
pci/0000:08:00.0/32768: type eth netdev eth4 flavour pcisf controller 0 pfnum 0 sfnum 106 splittable false
  function:
    hw_addr 00:00:00:00:00:00 state inactive opstate detached roce enable
$ devlink port function set pci/0000:08:00.0/32768 state active
$ devlink port show pci/0000:08:00.0/32768
pci/0000:08:00.0/32768: type eth netdev eth4 flavour pcisf controller 0 pfnum 0 sfnum 106 splittable false
  function:
    hw_addr 00:00:00:00:00:00 state active opstate attached roce enable nested_devlink auxiliary/mlx5_core.sf.2

# devlink dev reload auxiliary/mlx5_core.sf.2 netns ns1
$ devlink port show pci/0000:08:00.0/32768
pci/0000:08:00.0/32768: type eth netdev eth4 flavour pcisf controller 0 pfnum 0 sfnum 106 splittable false
  function:
    hw_addr 00:00:00:00:00:00 state active opstate attached roce enable nested_devlink auxiliary/mlx5_core.sf.2 nested_devlink_netns ns1

Jiri Pirko (12):
  devlink: move linecard struct into linecard.c
  net/mlx5: Disable eswitch as the first thing in mlx5_unload()
  net/mlx5: Lift reload limitation when SFs are present
  devlink: put netnsid to nested handle
  devlink: move devlink_nl_put_nested_handle() into netlink.c
  devlink: extend devlink_nl_put_nested_handle() with attrtype arg
  devlink: introduce object and nested devlink relationship infra
  devlink: expose peer SF devlink instance
  net/mlx5: SF, Implement peer devlink set for SF representor devlink
    port
  devlink: convert linecard nested devlink to new rel infrastructure
  devlink: introduce possibility to expose info about nested devlinks
  net/mlx5e: Set en auxiliary devlink instance as nested

 .../net/ethernet/mellanox/mlx5/core/devlink.c |  11 -
 .../ethernet/mellanox/mlx5/core/en/devlink.c  |   8 +
 .../net/ethernet/mellanox/mlx5/core/main.c    |   2 +-
 .../ethernet/mellanox/mlx5/core/sf/dev/dev.h  |   6 +
 .../mellanox/mlx5/core/sf/dev/driver.c        |  26 +++
 .../ethernet/mellanox/mlx5/core/sf/devlink.c  |  34 +++
 .../mellanox/mlxsw/core_linecard_dev.c        |   9 +-
 include/linux/mlx5/device.h                   |   1 +
 include/net/devlink.h                         |   9 +-
 include/uapi/linux/devlink.h                  |   1 +
 net/devlink/core.c                            | 217 ++++++++++++++++++
 net/devlink/dev.c                             |  50 ++++
 net/devlink/devl_internal.h                   |  34 +--
 net/devlink/linecard.c                        |  80 ++++---
 net/devlink/netlink.c                         |  26 +++
 net/devlink/port.c                            |  55 ++++-
 16 files changed, 509 insertions(+), 60 deletions(-)

-- 
2.41.0


^ permalink raw reply	[flat|nested] 15+ messages in thread

* [patch net-next v2 01/12] devlink: move linecard struct into linecard.c
  2023-09-13  7:12 [patch net-next v2 00/12] expose devlink instances relationships Jiri Pirko
@ 2023-09-13  7:12 ` Jiri Pirko
  2023-09-13  7:12 ` [patch net-next v2 02/12] net/mlx5: Disable eswitch as the first thing in mlx5_unload() Jiri Pirko
                   ` (12 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: Jiri Pirko @ 2023-09-13  7:12 UTC (permalink / raw)
  To: netdev
  Cc: kuba, pabeni, davem, edumazet, idosch, petrm, jacob.e.keller,
	moshe, shayd, saeedm, horms

From: Jiri Pirko <jiri@nvidia.com>

Instead of exposing linecard struct, expose a simple helper to get the
linecard index, which is all is needed outside linecard.c. Move the
linecard struct to linecard.c and keep it private similar to the rest of
the devlink objects.

Signed-off-by: Jiri Pirko <jiri@nvidia.com>
---
v1->v2:
- new patch
---
 net/devlink/devl_internal.h | 14 +-------------
 net/devlink/linecard.c      | 19 +++++++++++++++++++
 net/devlink/port.c          |  4 ++--
 3 files changed, 22 insertions(+), 15 deletions(-)

diff --git a/net/devlink/devl_internal.h b/net/devlink/devl_internal.h
index f6b5fea2e13c..1b05c2c09e27 100644
--- a/net/devlink/devl_internal.h
+++ b/net/devlink/devl_internal.h
@@ -206,19 +206,7 @@ int devlink_rate_nodes_check(struct devlink *devlink, u16 mode,
 			     struct netlink_ext_ack *extack);
 
 /* Linecards */
-struct devlink_linecard {
-	struct list_head list;
-	struct devlink *devlink;
-	unsigned int index;
-	const struct devlink_linecard_ops *ops;
-	void *priv;
-	enum devlink_linecard_state state;
-	struct mutex state_lock; /* Protects state */
-	const char *type;
-	struct devlink_linecard_type *types;
-	unsigned int types_count;
-	struct devlink *nested_devlink;
-};
+unsigned int devlink_linecard_index(struct devlink_linecard *linecard);
 
 /* Devlink nl cmds */
 int devlink_nl_cmd_reload(struct sk_buff *skb, struct genl_info *info);
diff --git a/net/devlink/linecard.c b/net/devlink/linecard.c
index 85c32c314b0f..a0210ba56f2d 100644
--- a/net/devlink/linecard.c
+++ b/net/devlink/linecard.c
@@ -6,6 +6,25 @@
 
 #include "devl_internal.h"
 
+struct devlink_linecard {
+	struct list_head list;
+	struct devlink *devlink;
+	unsigned int index;
+	const struct devlink_linecard_ops *ops;
+	void *priv;
+	enum devlink_linecard_state state;
+	struct mutex state_lock; /* Protects state */
+	const char *type;
+	struct devlink_linecard_type *types;
+	unsigned int types_count;
+	struct devlink *nested_devlink;
+};
+
+unsigned int devlink_linecard_index(struct devlink_linecard *linecard)
+{
+	return linecard->index;
+}
+
 static struct devlink_linecard *
 devlink_linecard_get_by_index(struct devlink *devlink,
 			      unsigned int linecard_index)
diff --git a/net/devlink/port.c b/net/devlink/port.c
index 4763b42885fb..7b300a322ed9 100644
--- a/net/devlink/port.c
+++ b/net/devlink/port.c
@@ -483,7 +483,7 @@ static int devlink_nl_port_fill(struct sk_buff *msg,
 		goto nla_put_failure;
 	if (devlink_port->linecard &&
 	    nla_put_u32(msg, DEVLINK_ATTR_LINECARD_INDEX,
-			devlink_port->linecard->index))
+			devlink_linecard_index(devlink_port->linecard)))
 		goto nla_put_failure;
 
 	genlmsg_end(msg, hdr);
@@ -1420,7 +1420,7 @@ static int __devlink_port_phys_port_name_get(struct devlink_port *devlink_port,
 	case DEVLINK_PORT_FLAVOUR_PHYSICAL:
 		if (devlink_port->linecard)
 			n = snprintf(name, len, "l%u",
-				     devlink_port->linecard->index);
+				     devlink_linecard_index(devlink_port->linecard));
 		if (n < len)
 			n += snprintf(name + n, len - n, "p%u",
 				      attrs->phys.port_number);
-- 
2.41.0


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [patch net-next v2 02/12] net/mlx5: Disable eswitch as the first thing in mlx5_unload()
  2023-09-13  7:12 [patch net-next v2 00/12] expose devlink instances relationships Jiri Pirko
  2023-09-13  7:12 ` [patch net-next v2 01/12] devlink: move linecard struct into linecard.c Jiri Pirko
@ 2023-09-13  7:12 ` Jiri Pirko
  2023-09-13  7:12 ` [patch net-next v2 03/12] net/mlx5: Lift reload limitation when SFs are present Jiri Pirko
                   ` (11 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: Jiri Pirko @ 2023-09-13  7:12 UTC (permalink / raw)
  To: netdev
  Cc: kuba, pabeni, davem, edumazet, idosch, petrm, jacob.e.keller,
	moshe, shayd, saeedm, horms

From: Jiri Pirko <jiri@nvidia.com>

The eswitch disable call does removal of all representors. Do that
before clearing the SF device table and maintain the same flow as during
SF devlink port removal, where the representor is removed before
the actual SF is removed.

Signed-off-by: Jiri Pirko <jiri@nvidia.com>
---
v1->v2:
- fixed a typo in patch description
---
 drivers/net/ethernet/mellanox/mlx5/core/main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/main.c b/drivers/net/ethernet/mellanox/mlx5/core/main.c
index 15561965d2af..d17c9c31b165 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/main.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/main.c
@@ -1405,9 +1405,9 @@ static int mlx5_load(struct mlx5_core_dev *dev)
 
 static void mlx5_unload(struct mlx5_core_dev *dev)
 {
+	mlx5_eswitch_disable(dev->priv.eswitch);
 	mlx5_devlink_traps_unregister(priv_to_devlink(dev));
 	mlx5_sf_dev_table_destroy(dev);
-	mlx5_eswitch_disable(dev->priv.eswitch);
 	mlx5_sriov_detach(dev);
 	mlx5_lag_remove_mdev(dev);
 	mlx5_ec_cleanup(dev);
-- 
2.41.0


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [patch net-next v2 03/12] net/mlx5: Lift reload limitation when SFs are present
  2023-09-13  7:12 [patch net-next v2 00/12] expose devlink instances relationships Jiri Pirko
  2023-09-13  7:12 ` [patch net-next v2 01/12] devlink: move linecard struct into linecard.c Jiri Pirko
  2023-09-13  7:12 ` [patch net-next v2 02/12] net/mlx5: Disable eswitch as the first thing in mlx5_unload() Jiri Pirko
@ 2023-09-13  7:12 ` Jiri Pirko
  2023-09-13  7:12 ` [patch net-next v2 04/12] devlink: put netnsid to nested handle Jiri Pirko
                   ` (10 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: Jiri Pirko @ 2023-09-13  7:12 UTC (permalink / raw)
  To: netdev
  Cc: kuba, pabeni, davem, edumazet, idosch, petrm, jacob.e.keller,
	moshe, shayd, saeedm, horms

From: Jiri Pirko <jiri@nvidia.com>

Historically, the shared devlink_mutex prevented devlink instances from
being registered/unregistered during another devlink instance reload
operation. However, devlink_muxex is gone for some time now, this
limitation is no longer needed. Lift it.

Signed-off-by: Jiri Pirko <jiri@nvidia.com>
---
 drivers/net/ethernet/mellanox/mlx5/core/devlink.c | 11 -----------
 1 file changed, 11 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/devlink.c b/drivers/net/ethernet/mellanox/mlx5/core/devlink.c
index af8460bb257b..3e064234f6fe 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/devlink.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/devlink.c
@@ -138,7 +138,6 @@ static int mlx5_devlink_reload_down(struct devlink *devlink, bool netns_change,
 {
 	struct mlx5_core_dev *dev = devlink_priv(devlink);
 	struct pci_dev *pdev = dev->pdev;
-	bool sf_dev_allocated;
 	int ret = 0;
 
 	if (mlx5_dev_is_lightweight(dev)) {
@@ -148,16 +147,6 @@ static int mlx5_devlink_reload_down(struct devlink *devlink, bool netns_change,
 		return 0;
 	}
 
-	sf_dev_allocated = mlx5_sf_dev_allocated(dev);
-	if (sf_dev_allocated) {
-		/* Reload results in deleting SF device which further results in
-		 * unregistering devlink instance while holding devlink_mutext.
-		 * Hence, do not support reload.
-		 */
-		NL_SET_ERR_MSG_MOD(extack, "reload is unsupported when SFs are allocated");
-		return -EOPNOTSUPP;
-	}
-
 	if (mlx5_lag_is_active(dev)) {
 		NL_SET_ERR_MSG_MOD(extack, "reload is unsupported in Lag mode");
 		return -EOPNOTSUPP;
-- 
2.41.0


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [patch net-next v2 04/12] devlink: put netnsid to nested handle
  2023-09-13  7:12 [patch net-next v2 00/12] expose devlink instances relationships Jiri Pirko
                   ` (2 preceding siblings ...)
  2023-09-13  7:12 ` [patch net-next v2 03/12] net/mlx5: Lift reload limitation when SFs are present Jiri Pirko
@ 2023-09-13  7:12 ` Jiri Pirko
  2023-09-13  7:12 ` [patch net-next v2 05/12] devlink: move devlink_nl_put_nested_handle() into netlink.c Jiri Pirko
                   ` (9 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: Jiri Pirko @ 2023-09-13  7:12 UTC (permalink / raw)
  To: netdev
  Cc: kuba, pabeni, davem, edumazet, idosch, petrm, jacob.e.keller,
	moshe, shayd, saeedm, horms

From: Jiri Pirko <jiri@nvidia.com>

If netns of devlink instance and nested devlink instance differs,
put netnsid attr to indicate that.

Signed-off-by: Jiri Pirko <jiri@nvidia.com>
---
v1->v2:
- new patch
---
 net/devlink/linecard.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/net/devlink/linecard.c b/net/devlink/linecard.c
index a0210ba56f2d..f95abdc93c66 100644
--- a/net/devlink/linecard.c
+++ b/net/devlink/linecard.c
@@ -65,7 +65,8 @@ devlink_linecard_get_from_info(struct devlink *devlink, struct genl_info *info)
 	return devlink_linecard_get_from_attrs(devlink, info->attrs);
 }
 
-static int devlink_nl_put_nested_handle(struct sk_buff *msg, struct devlink *devlink)
+static int devlink_nl_put_nested_handle(struct sk_buff *msg, struct net *net,
+					struct devlink *devlink)
 {
 	struct nlattr *nested_attr;
 
@@ -74,6 +75,13 @@ static int devlink_nl_put_nested_handle(struct sk_buff *msg, struct devlink *dev
 		return -EMSGSIZE;
 	if (devlink_nl_put_handle(msg, devlink))
 		goto nla_put_failure;
+	if (!net_eq(net, devlink_net(devlink))) {
+		int id = peernet2id_alloc(net, devlink_net(devlink),
+					  GFP_KERNEL);
+
+		if (nla_put_s32(msg, DEVLINK_ATTR_NETNS_ID, id))
+			return -EMSGSIZE;
+	}
 
 	nla_nest_end(msg, nested_attr);
 	return 0;
@@ -131,7 +139,8 @@ static int devlink_nl_linecard_fill(struct sk_buff *msg,
 	}
 
 	if (linecard->nested_devlink &&
-	    devlink_nl_put_nested_handle(msg, linecard->nested_devlink))
+	    devlink_nl_put_nested_handle(msg, devlink_net(devlink),
+					 linecard->nested_devlink))
 		goto nla_put_failure;
 
 	genlmsg_end(msg, hdr);
-- 
2.41.0


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [patch net-next v2 05/12] devlink: move devlink_nl_put_nested_handle() into netlink.c
  2023-09-13  7:12 [patch net-next v2 00/12] expose devlink instances relationships Jiri Pirko
                   ` (3 preceding siblings ...)
  2023-09-13  7:12 ` [patch net-next v2 04/12] devlink: put netnsid to nested handle Jiri Pirko
@ 2023-09-13  7:12 ` Jiri Pirko
  2023-09-13  7:12 ` [patch net-next v2 06/12] devlink: extend devlink_nl_put_nested_handle() with attrtype arg Jiri Pirko
                   ` (8 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: Jiri Pirko @ 2023-09-13  7:12 UTC (permalink / raw)
  To: netdev
  Cc: kuba, pabeni, davem, edumazet, idosch, petrm, jacob.e.keller,
	moshe, shayd, saeedm, horms

From: Jiri Pirko <jiri@nvidia.com>

As the next patch is going to call this helper out of the linecard.c,
move to netlink.c.

Signed-off-by: Jiri Pirko <jiri@nvidia.com>
---
 net/devlink/devl_internal.h |  2 ++
 net/devlink/linecard.c      | 26 --------------------------
 net/devlink/netlink.c       | 26 ++++++++++++++++++++++++++
 3 files changed, 28 insertions(+), 26 deletions(-)

diff --git a/net/devlink/devl_internal.h b/net/devlink/devl_internal.h
index 1b05c2c09e27..fbf00de1accf 100644
--- a/net/devlink/devl_internal.h
+++ b/net/devlink/devl_internal.h
@@ -145,6 +145,8 @@ devlink_nl_put_handle(struct sk_buff *msg, struct devlink *devlink)
 	return 0;
 }
 
+int devlink_nl_put_nested_handle(struct sk_buff *msg, struct net *net,
+				 struct devlink *devlink);
 int devlink_nl_msg_reply_and_new(struct sk_buff **msg, struct genl_info *info);
 
 /* Notify */
diff --git a/net/devlink/linecard.c b/net/devlink/linecard.c
index f95abdc93c66..688e89daee6a 100644
--- a/net/devlink/linecard.c
+++ b/net/devlink/linecard.c
@@ -65,32 +65,6 @@ devlink_linecard_get_from_info(struct devlink *devlink, struct genl_info *info)
 	return devlink_linecard_get_from_attrs(devlink, info->attrs);
 }
 
-static int devlink_nl_put_nested_handle(struct sk_buff *msg, struct net *net,
-					struct devlink *devlink)
-{
-	struct nlattr *nested_attr;
-
-	nested_attr = nla_nest_start(msg, DEVLINK_ATTR_NESTED_DEVLINK);
-	if (!nested_attr)
-		return -EMSGSIZE;
-	if (devlink_nl_put_handle(msg, devlink))
-		goto nla_put_failure;
-	if (!net_eq(net, devlink_net(devlink))) {
-		int id = peernet2id_alloc(net, devlink_net(devlink),
-					  GFP_KERNEL);
-
-		if (nla_put_s32(msg, DEVLINK_ATTR_NETNS_ID, id))
-			return -EMSGSIZE;
-	}
-
-	nla_nest_end(msg, nested_attr);
-	return 0;
-
-nla_put_failure:
-	nla_nest_cancel(msg, nested_attr);
-	return -EMSGSIZE;
-}
-
 struct devlink_linecard_type {
 	const char *type;
 	const void *priv;
diff --git a/net/devlink/netlink.c b/net/devlink/netlink.c
index fc3e7c029a3b..48b5cfc2842f 100644
--- a/net/devlink/netlink.c
+++ b/net/devlink/netlink.c
@@ -82,6 +82,32 @@ static const struct nla_policy devlink_nl_policy[DEVLINK_ATTR_MAX + 1] = {
 	[DEVLINK_ATTR_REGION_DIRECT] = { .type = NLA_FLAG },
 };
 
+int devlink_nl_put_nested_handle(struct sk_buff *msg, struct net *net,
+				 struct devlink *devlink)
+{
+	struct nlattr *nested_attr;
+
+	nested_attr = nla_nest_start(msg, DEVLINK_ATTR_NESTED_DEVLINK);
+	if (!nested_attr)
+		return -EMSGSIZE;
+	if (devlink_nl_put_handle(msg, devlink))
+		goto nla_put_failure;
+	if (!net_eq(net, devlink_net(devlink))) {
+		int id = peernet2id_alloc(net, devlink_net(devlink),
+					  GFP_KERNEL);
+
+		if (nla_put_s32(msg, DEVLINK_ATTR_NETNS_ID, id))
+			return -EMSGSIZE;
+	}
+
+	nla_nest_end(msg, nested_attr);
+	return 0;
+
+nla_put_failure:
+	nla_nest_cancel(msg, nested_attr);
+	return -EMSGSIZE;
+}
+
 int devlink_nl_msg_reply_and_new(struct sk_buff **msg, struct genl_info *info)
 {
 	int err;
-- 
2.41.0


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [patch net-next v2 06/12] devlink: extend devlink_nl_put_nested_handle() with attrtype arg
  2023-09-13  7:12 [patch net-next v2 00/12] expose devlink instances relationships Jiri Pirko
                   ` (4 preceding siblings ...)
  2023-09-13  7:12 ` [patch net-next v2 05/12] devlink: move devlink_nl_put_nested_handle() into netlink.c Jiri Pirko
@ 2023-09-13  7:12 ` Jiri Pirko
  2023-09-13  7:12 ` [patch net-next v2 07/12] devlink: introduce object and nested devlink relationship infra Jiri Pirko
                   ` (7 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: Jiri Pirko @ 2023-09-13  7:12 UTC (permalink / raw)
  To: netdev
  Cc: kuba, pabeni, davem, edumazet, idosch, petrm, jacob.e.keller,
	moshe, shayd, saeedm, horms

From: Jiri Pirko <jiri@nvidia.com>

As the next patch is going to call this helper with need to fill another
type of nested attribute, pass it over function arg.

Signed-off-by: Jiri Pirko <jiri@nvidia.com>
---
v1->v2:
- new patch
---
 net/devlink/devl_internal.h | 2 +-
 net/devlink/linecard.c      | 3 ++-
 net/devlink/netlink.c       | 4 ++--
 3 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/net/devlink/devl_internal.h b/net/devlink/devl_internal.h
index fbf00de1accf..53449dbd6545 100644
--- a/net/devlink/devl_internal.h
+++ b/net/devlink/devl_internal.h
@@ -146,7 +146,7 @@ devlink_nl_put_handle(struct sk_buff *msg, struct devlink *devlink)
 }
 
 int devlink_nl_put_nested_handle(struct sk_buff *msg, struct net *net,
-				 struct devlink *devlink);
+				 struct devlink *devlink, int attrtype);
 int devlink_nl_msg_reply_and_new(struct sk_buff **msg, struct genl_info *info);
 
 /* Notify */
diff --git a/net/devlink/linecard.c b/net/devlink/linecard.c
index 688e89daee6a..36170f466878 100644
--- a/net/devlink/linecard.c
+++ b/net/devlink/linecard.c
@@ -114,7 +114,8 @@ static int devlink_nl_linecard_fill(struct sk_buff *msg,
 
 	if (linecard->nested_devlink &&
 	    devlink_nl_put_nested_handle(msg, devlink_net(devlink),
-					 linecard->nested_devlink))
+					 linecard->nested_devlink,
+					 DEVLINK_ATTR_NESTED_DEVLINK))
 		goto nla_put_failure;
 
 	genlmsg_end(msg, hdr);
diff --git a/net/devlink/netlink.c b/net/devlink/netlink.c
index 48b5cfc2842f..499304d9de49 100644
--- a/net/devlink/netlink.c
+++ b/net/devlink/netlink.c
@@ -83,11 +83,11 @@ static const struct nla_policy devlink_nl_policy[DEVLINK_ATTR_MAX + 1] = {
 };
 
 int devlink_nl_put_nested_handle(struct sk_buff *msg, struct net *net,
-				 struct devlink *devlink)
+				 struct devlink *devlink, int attrtype)
 {
 	struct nlattr *nested_attr;
 
-	nested_attr = nla_nest_start(msg, DEVLINK_ATTR_NESTED_DEVLINK);
+	nested_attr = nla_nest_start(msg, attrtype);
 	if (!nested_attr)
 		return -EMSGSIZE;
 	if (devlink_nl_put_handle(msg, devlink))
-- 
2.41.0


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [patch net-next v2 07/12] devlink: introduce object and nested devlink relationship infra
  2023-09-13  7:12 [patch net-next v2 00/12] expose devlink instances relationships Jiri Pirko
                   ` (5 preceding siblings ...)
  2023-09-13  7:12 ` [patch net-next v2 06/12] devlink: extend devlink_nl_put_nested_handle() with attrtype arg Jiri Pirko
@ 2023-09-13  7:12 ` Jiri Pirko
  2023-09-13  7:12 ` [patch net-next v2 08/12] devlink: expose peer SF devlink instance Jiri Pirko
                   ` (6 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: Jiri Pirko @ 2023-09-13  7:12 UTC (permalink / raw)
  To: netdev
  Cc: kuba, pabeni, davem, edumazet, idosch, petrm, jacob.e.keller,
	moshe, shayd, saeedm, horms

From: Jiri Pirko <jiri@nvidia.com>

It is a bit tricky to maintain relationship between devlink objects and
nested devlink instances due to following aspects:

1) Locking. It is necessary to lock the devlink instance that contains
   the object first, only after that to lock the nested instance.
2) Lifetimes. Objects (e.g devlink port) may be removed before
   the nested devlink instance.
3) Notifications. If nested instance changes (e.g. gets
   registered/unregistered) the nested-in object needs to send
   appropriate notifications.

Resolve this by introducing an xarray that holds 1:1 relationships
between devlink object and related nested devlink instance.
Use that xarray index to get the object/nested devlink instance on
the other side.

Provide necessary helpers:
devlink_rel_nested_in_add/clear() to add and clear the relationship.
devlink_rel_nested_in_notify() to call the nested-in object to send
	notifications during nested instance register/unregister/netns
	change.
devlink_rel_devlink_handle_put() to be used by nested-in object fill
	function to fill the nested handle.

Signed-off-by: Jiri Pirko <jiri@nvidia.com>
---
v1->v2:
- new patch
---
 net/devlink/core.c          | 215 ++++++++++++++++++++++++++++++++++++
 net/devlink/dev.c           |   1 +
 net/devlink/devl_internal.h |  17 +++
 3 files changed, 233 insertions(+)

diff --git a/net/devlink/core.c b/net/devlink/core.c
index 6cec4afb01fb..2a98ff9a2f6b 100644
--- a/net/devlink/core.c
+++ b/net/devlink/core.c
@@ -16,6 +16,219 @@ EXPORT_TRACEPOINT_SYMBOL_GPL(devlink_trap_report);
 
 DEFINE_XARRAY_FLAGS(devlinks, XA_FLAGS_ALLOC);
 
+static struct devlink *devlinks_xa_get(unsigned long index)
+{
+	struct devlink *devlink;
+
+	rcu_read_lock();
+	devlink = xa_find(&devlinks, &index, index, DEVLINK_REGISTERED);
+	if (!devlink || !devlink_try_get(devlink))
+		devlink = NULL;
+	rcu_read_unlock();
+	return devlink;
+}
+
+/* devlink_rels xarray contains 1:1 relationships between
+ * devlink object and related nested devlink instance.
+ * The xarray index is used to get the nested object from
+ * the nested-in object code.
+ */
+static DEFINE_XARRAY_FLAGS(devlink_rels, XA_FLAGS_ALLOC1);
+
+#define DEVLINK_REL_IN_USE XA_MARK_0
+
+struct devlink_rel {
+	u32 index;
+	refcount_t refcount;
+	u32 devlink_index;
+	struct {
+		u32 devlink_index;
+		u32 obj_index;
+		devlink_rel_notify_cb_t *notify_cb;
+		devlink_rel_cleanup_cb_t *cleanup_cb;
+		struct work_struct notify_work;
+	} nested_in;
+};
+
+static void devlink_rel_free(struct devlink_rel *rel)
+{
+	xa_erase(&devlink_rels, rel->index);
+	kfree(rel);
+}
+
+static void __devlink_rel_get(struct devlink_rel *rel)
+{
+	refcount_inc(&rel->refcount);
+}
+
+static void __devlink_rel_put(struct devlink_rel *rel)
+{
+	if (refcount_dec_and_test(&rel->refcount))
+		devlink_rel_free(rel);
+}
+
+static void devlink_rel_nested_in_notify_work(struct work_struct *work)
+{
+	struct devlink_rel *rel = container_of(work, struct devlink_rel,
+					       nested_in.notify_work);
+	struct devlink *devlink;
+
+	devlink = devlinks_xa_get(rel->nested_in.devlink_index);
+	if (!devlink)
+		goto rel_put;
+	if (!devl_trylock(devlink)) {
+		devlink_put(devlink);
+		goto reschedule_work;
+	}
+	if (!devl_is_registered(devlink)) {
+		devl_unlock(devlink);
+		devlink_put(devlink);
+		goto rel_put;
+	}
+	if (!xa_get_mark(&devlink_rels, rel->index, DEVLINK_REL_IN_USE))
+		rel->nested_in.cleanup_cb(devlink, rel->nested_in.obj_index, rel->index);
+	rel->nested_in.notify_cb(devlink, rel->nested_in.obj_index);
+	devl_unlock(devlink);
+	devlink_put(devlink);
+
+rel_put:
+	__devlink_rel_put(rel);
+	return;
+
+reschedule_work:
+	schedule_work(&rel->nested_in.notify_work);
+}
+
+static void devlink_rel_nested_in_notify_work_schedule(struct devlink_rel *rel)
+{
+	__devlink_rel_get(rel);
+	schedule_work(&rel->nested_in.notify_work);
+}
+
+static struct devlink_rel *devlink_rel_alloc(void)
+{
+	struct devlink_rel *rel;
+	static u32 next;
+	int err;
+
+	rel = kzalloc(sizeof(*rel), GFP_KERNEL);
+	if (!rel)
+		return ERR_PTR(-ENOMEM);
+
+	err = xa_alloc_cyclic(&devlink_rels, &rel->index, rel,
+			      xa_limit_32b, &next, GFP_KERNEL);
+	if (err) {
+		kfree(rel);
+		return ERR_PTR(err);
+	}
+
+	refcount_set(&rel->refcount, 1);
+	INIT_WORK(&rel->nested_in.notify_work,
+		  &devlink_rel_nested_in_notify_work);
+	return rel;
+}
+
+static void devlink_rel_put(struct devlink *devlink)
+{
+	struct devlink_rel *rel = devlink->rel;
+
+	if (!rel)
+		return;
+	xa_clear_mark(&devlink_rels, rel->index, DEVLINK_REL_IN_USE);
+	devlink_rel_nested_in_notify_work_schedule(rel);
+	__devlink_rel_put(rel);
+	devlink->rel = NULL;
+}
+
+void devlink_rel_nested_in_clear(u32 rel_index)
+{
+	xa_clear_mark(&devlink_rels, rel_index, DEVLINK_REL_IN_USE);
+}
+
+int devlink_rel_nested_in_add(u32 *rel_index, u32 devlink_index,
+			      u32 obj_index, devlink_rel_notify_cb_t *notify_cb,
+			      devlink_rel_cleanup_cb_t *cleanup_cb,
+			      struct devlink *devlink)
+{
+	struct devlink_rel *rel = devlink_rel_alloc();
+
+	ASSERT_DEVLINK_NOT_REGISTERED(devlink);
+
+	if (IS_ERR(rel))
+		return PTR_ERR(rel);
+
+	rel->devlink_index = devlink->index;
+	rel->nested_in.devlink_index = devlink_index;
+	rel->nested_in.obj_index = obj_index;
+	rel->nested_in.notify_cb = notify_cb;
+	rel->nested_in.cleanup_cb = cleanup_cb;
+	*rel_index = rel->index;
+	xa_set_mark(&devlink_rels, rel->index, DEVLINK_REL_IN_USE);
+	devlink->rel = rel;
+	return 0;
+}
+
+void devlink_rel_nested_in_notify(struct devlink *devlink)
+{
+	struct devlink_rel *rel = devlink->rel;
+
+	if (!rel)
+		return;
+	devlink_rel_nested_in_notify_work_schedule(rel);
+}
+
+static struct devlink_rel *devlink_rel_find(unsigned long rel_index)
+{
+	return xa_find(&devlink_rels, &rel_index, rel_index,
+		       DEVLINK_REL_IN_USE);
+}
+
+static struct devlink *devlink_rel_devlink_get_lock(u32 rel_index)
+{
+	struct devlink *devlink;
+	struct devlink_rel *rel;
+	u32 devlink_index;
+
+	if (!rel_index)
+		return NULL;
+	xa_lock(&devlink_rels);
+	rel = devlink_rel_find(rel_index);
+	if (rel)
+		devlink_index = rel->devlink_index;
+	xa_unlock(&devlink_rels);
+	if (!rel)
+		return NULL;
+	devlink = devlinks_xa_get(devlink_index);
+	if (!devlink)
+		return NULL;
+	devl_lock(devlink);
+	if (!devl_is_registered(devlink)) {
+		devl_unlock(devlink);
+		devlink_put(devlink);
+		return NULL;
+	}
+	return devlink;
+}
+
+int devlink_rel_devlink_handle_put(struct sk_buff *msg, struct devlink *devlink,
+				   u32 rel_index, int attrtype,
+				   bool *msg_updated)
+{
+	struct net *net = devlink_net(devlink);
+	struct devlink *rel_devlink;
+	int err;
+
+	rel_devlink = devlink_rel_devlink_get_lock(rel_index);
+	if (!rel_devlink)
+		return 0;
+	err = devlink_nl_put_nested_handle(msg, net, rel_devlink, attrtype);
+	devl_unlock(rel_devlink);
+	devlink_put(rel_devlink);
+	if (!err && msg_updated)
+		*msg_updated = true;
+	return err;
+}
+
 void *devlink_priv(struct devlink *devlink)
 {
 	return &devlink->priv;
@@ -142,6 +355,7 @@ int devl_register(struct devlink *devlink)
 
 	xa_set_mark(&devlinks, devlink->index, DEVLINK_REGISTERED);
 	devlink_notify_register(devlink);
+	devlink_rel_nested_in_notify(devlink);
 
 	return 0;
 }
@@ -166,6 +380,7 @@ void devl_unregister(struct devlink *devlink)
 
 	devlink_notify_unregister(devlink);
 	xa_clear_mark(&devlinks, devlink->index, DEVLINK_REGISTERED);
+	devlink_rel_put(devlink);
 }
 EXPORT_SYMBOL_GPL(devl_unregister);
 
diff --git a/net/devlink/dev.c b/net/devlink/dev.c
index bba4ace7d22b..3ae26d9088ab 100644
--- a/net/devlink/dev.c
+++ b/net/devlink/dev.c
@@ -372,6 +372,7 @@ static void devlink_reload_netns_change(struct devlink *devlink,
 	devlink_notify_unregister(devlink);
 	write_pnet(&devlink->_net, dest_net);
 	devlink_notify_register(devlink);
+	devlink_rel_nested_in_notify(devlink);
 }
 
 int devlink_reload(struct devlink *devlink, struct net *dest_net,
diff --git a/net/devlink/devl_internal.h b/net/devlink/devl_internal.h
index 53449dbd6545..4cb534aff44d 100644
--- a/net/devlink/devl_internal.h
+++ b/net/devlink/devl_internal.h
@@ -17,6 +17,8 @@
 
 #include "netlink_gen.h"
 
+struct devlink_rel;
+
 #define DEVLINK_REGISTERED XA_MARK_1
 
 #define DEVLINK_RELOAD_STATS_ARRAY_SIZE \
@@ -55,6 +57,7 @@ struct devlink {
 	u8 reload_failed:1;
 	refcount_t refcount;
 	struct rcu_work rwork;
+	struct devlink_rel *rel;
 	char priv[] __aligned(NETDEV_ALIGN);
 };
 
@@ -92,6 +95,20 @@ static inline bool devl_is_registered(struct devlink *devlink)
 	return xa_get_mark(&devlinks, devlink->index, DEVLINK_REGISTERED);
 }
 
+typedef void devlink_rel_notify_cb_t(struct devlink *devlink, u32 obj_index);
+typedef void devlink_rel_cleanup_cb_t(struct devlink *devlink, u32 obj_index,
+				      u32 rel_index);
+
+void devlink_rel_nested_in_clear(u32 rel_index);
+int devlink_rel_nested_in_add(u32 *rel_index, u32 devlink_index,
+			      u32 obj_index, devlink_rel_notify_cb_t *notify_cb,
+			      devlink_rel_cleanup_cb_t *cleanup_cb,
+			      struct devlink *devlink);
+void devlink_rel_nested_in_notify(struct devlink *devlink);
+int devlink_rel_devlink_handle_put(struct sk_buff *msg, struct devlink *devlink,
+				   u32 rel_index, int attrtype,
+				   bool *msg_updated);
+
 /* Netlink */
 #define DEVLINK_NL_FLAG_NEED_PORT		BIT(0)
 #define DEVLINK_NL_FLAG_NEED_DEVLINK_OR_PORT	BIT(1)
-- 
2.41.0


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [patch net-next v2 08/12] devlink: expose peer SF devlink instance
  2023-09-13  7:12 [patch net-next v2 00/12] expose devlink instances relationships Jiri Pirko
                   ` (6 preceding siblings ...)
  2023-09-13  7:12 ` [patch net-next v2 07/12] devlink: introduce object and nested devlink relationship infra Jiri Pirko
@ 2023-09-13  7:12 ` Jiri Pirko
  2023-09-13  7:12 ` [patch net-next v2 09/12] net/mlx5: SF, Implement peer devlink set for SF representor devlink port Jiri Pirko
                   ` (5 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: Jiri Pirko @ 2023-09-13  7:12 UTC (permalink / raw)
  To: netdev
  Cc: kuba, pabeni, davem, edumazet, idosch, petrm, jacob.e.keller,
	moshe, shayd, saeedm, horms

From: Jiri Pirko <jiri@nvidia.com>

Introduce a new helper devl_port_fn_devlink_set() to be used by driver
assigning a devlink instance to the peer devlink port function.

Expose this to user over new netlink attribute nested under port
function nest to expose devlink handle related to the port function.

This is particularly helpful for user to understand the relationship
between devlink instances created for SFs and the port functions
they belong to.

Note that caller of devlink_port_notify() needs to hold devlink
instance lock, put the assertion to devl_port_fn_devlink_set() to make
this requirement explicit. Also note the limitations that only allow to
make this assignment for registered objects.

Signed-off-by: Jiri Pirko <jiri@nvidia.com>
---
v1->v2:
- rebased on top of previous patch
- utilize newly added rel infra
- split devlink_nl_put_nested_handle() arg extension into separate patch
---
 include/net/devlink.h        |  3 +++
 include/uapi/linux/devlink.h |  1 +
 net/devlink/port.c           | 51 ++++++++++++++++++++++++++++++++++++
 3 files changed, 55 insertions(+)

diff --git a/include/net/devlink.h b/include/net/devlink.h
index 29fd1b4ee654..2655ab6101ec 100644
--- a/include/net/devlink.h
+++ b/include/net/devlink.h
@@ -150,6 +150,7 @@ struct devlink_port {
 
 	struct devlink_rate *devlink_rate;
 	struct devlink_linecard *linecard;
+	u32 rel_index;
 };
 
 struct devlink_port_new_attrs {
@@ -1697,6 +1698,8 @@ void devlink_port_attrs_pci_vf_set(struct devlink_port *devlink_port, u32 contro
 void devlink_port_attrs_pci_sf_set(struct devlink_port *devlink_port,
 				   u32 controller, u16 pf, u32 sf,
 				   bool external);
+int devl_port_fn_devlink_set(struct devlink_port *devlink_port,
+			     struct devlink *fn_devlink);
 struct devlink_rate *
 devl_rate_node_create(struct devlink *devlink, void *priv, char *node_name,
 		      struct devlink_rate *parent);
diff --git a/include/uapi/linux/devlink.h b/include/uapi/linux/devlink.h
index 03875e078be8..cd4b82458d1b 100644
--- a/include/uapi/linux/devlink.h
+++ b/include/uapi/linux/devlink.h
@@ -680,6 +680,7 @@ enum devlink_port_function_attr {
 	DEVLINK_PORT_FN_ATTR_STATE,	/* u8 */
 	DEVLINK_PORT_FN_ATTR_OPSTATE,	/* u8 */
 	DEVLINK_PORT_FN_ATTR_CAPS,	/* bitfield32 */
+	DEVLINK_PORT_FN_ATTR_DEVLINK,	/* nested */
 
 	__DEVLINK_PORT_FUNCTION_ATTR_MAX,
 	DEVLINK_PORT_FUNCTION_ATTR_MAX = __DEVLINK_PORT_FUNCTION_ATTR_MAX - 1
diff --git a/net/devlink/port.c b/net/devlink/port.c
index 7b300a322ed9..4e9003242448 100644
--- a/net/devlink/port.c
+++ b/net/devlink/port.c
@@ -428,6 +428,13 @@ devlink_nl_port_function_attrs_put(struct sk_buff *msg, struct devlink_port *por
 	if (err)
 		goto out;
 	err = devlink_port_fn_state_fill(port, msg, extack, &msg_updated);
+	if (err)
+		goto out;
+	err = devlink_rel_devlink_handle_put(msg, port->devlink,
+					     port->rel_index,
+					     DEVLINK_PORT_FN_ATTR_DEVLINK,
+					     &msg_updated);
+
 out:
 	if (err || !msg_updated)
 		nla_nest_cancel(msg, function_attr);
@@ -1392,6 +1399,50 @@ void devlink_port_attrs_pci_sf_set(struct devlink_port *devlink_port, u32 contro
 }
 EXPORT_SYMBOL_GPL(devlink_port_attrs_pci_sf_set);
 
+static void devlink_port_rel_notify_cb(struct devlink *devlink, u32 port_index)
+{
+	struct devlink_port *devlink_port;
+
+	devlink_port = devlink_port_get_by_index(devlink, port_index);
+	if (!devlink_port)
+		return;
+	devlink_port_notify(devlink_port, DEVLINK_CMD_PORT_NEW);
+}
+
+static void devlink_port_rel_cleanup_cb(struct devlink *devlink, u32 port_index,
+					u32 rel_index)
+{
+	struct devlink_port *devlink_port;
+
+	devlink_port = devlink_port_get_by_index(devlink, port_index);
+	if (devlink_port && devlink_port->rel_index == rel_index)
+		devlink_port->rel_index = 0;
+}
+
+/**
+ * devl_port_fn_devlink_set - Attach peer devlink
+ *			      instance to port function.
+ * @devlink_port: devlink port
+ * @fn_devlink: devlink instance to attach
+ */
+int devl_port_fn_devlink_set(struct devlink_port *devlink_port,
+			     struct devlink *fn_devlink)
+{
+	ASSERT_DEVLINK_PORT_REGISTERED(devlink_port);
+
+	if (WARN_ON(devlink_port->attrs.flavour != DEVLINK_PORT_FLAVOUR_PCI_SF ||
+		    devlink_port->attrs.pci_sf.external))
+		return -EINVAL;
+
+	return devlink_rel_nested_in_add(&devlink_port->rel_index,
+					 devlink_port->devlink->index,
+					 devlink_port->index,
+					 devlink_port_rel_notify_cb,
+					 devlink_port_rel_cleanup_cb,
+					 fn_devlink);
+}
+EXPORT_SYMBOL_GPL(devl_port_fn_devlink_set);
+
 /**
  *	devlink_port_linecard_set - Link port with a linecard
  *
-- 
2.41.0


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [patch net-next v2 09/12] net/mlx5: SF, Implement peer devlink set for SF representor devlink port
  2023-09-13  7:12 [patch net-next v2 00/12] expose devlink instances relationships Jiri Pirko
                   ` (7 preceding siblings ...)
  2023-09-13  7:12 ` [patch net-next v2 08/12] devlink: expose peer SF devlink instance Jiri Pirko
@ 2023-09-13  7:12 ` Jiri Pirko
  2023-09-13  7:12 ` [patch net-next v2 10/12] devlink: convert linecard nested devlink to new rel infrastructure Jiri Pirko
                   ` (4 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: Jiri Pirko @ 2023-09-13  7:12 UTC (permalink / raw)
  To: netdev
  Cc: kuba, pabeni, davem, edumazet, idosch, petrm, jacob.e.keller,
	moshe, shayd, saeedm, horms

From: Jiri Pirko <jiri@nvidia.com>

Benefit from the existence of internal mlx5 notifier and extend it by
event MLX5_DRIVER_EVENT_SF_PEER_DEVLINK. Use this event from SF
auxiliary device probe/remove functions to pass the registered SF
devlink instance to the SF representor.

Process the new event in SF representor code and call
devl_port_fn_devlink_set() to do the assignments. Implement this in work
to avoid possible deadlock when probe/remove function of SF may be
called with devlink instance lock held during devlink reload.

Signed-off-by: Jiri Pirko <jiri@nvidia.com>
---
v1->v2:
- rebased on top of net-next
- removed work code as devl_port_fn_devlink_set() could be called
  without instance lock
- propagate return code newly returned by devl_port_fn_devlink_set()
---
 .../ethernet/mellanox/mlx5/core/sf/dev/dev.h  |  6 ++++
 .../mellanox/mlx5/core/sf/dev/driver.c        | 26 ++++++++++++++
 .../ethernet/mellanox/mlx5/core/sf/devlink.c  | 34 +++++++++++++++++++
 include/linux/mlx5/device.h                   |  1 +
 4 files changed, 67 insertions(+)

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/sf/dev/dev.h b/drivers/net/ethernet/mellanox/mlx5/core/sf/dev/dev.h
index 2a66a427ef15..b99131e95e37 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/sf/dev/dev.h
+++ b/drivers/net/ethernet/mellanox/mlx5/core/sf/dev/dev.h
@@ -19,6 +19,12 @@ struct mlx5_sf_dev {
 	u16 fn_id;
 };
 
+struct mlx5_sf_peer_devlink_event_ctx {
+	u16 fn_id;
+	struct devlink *devlink;
+	int err;
+};
+
 void mlx5_sf_dev_table_create(struct mlx5_core_dev *dev);
 void mlx5_sf_dev_table_destroy(struct mlx5_core_dev *dev);
 
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/sf/dev/driver.c b/drivers/net/ethernet/mellanox/mlx5/core/sf/dev/driver.c
index 8fe82f1191bb..169c2c68ed5c 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/sf/dev/driver.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/sf/dev/driver.c
@@ -8,6 +8,20 @@
 #include "dev.h"
 #include "devlink.h"
 
+static int mlx5_core_peer_devlink_set(struct mlx5_sf_dev *sf_dev, struct devlink *devlink)
+{
+	struct mlx5_sf_peer_devlink_event_ctx event_ctx = {
+		.fn_id = sf_dev->fn_id,
+		.devlink = devlink,
+	};
+	int ret;
+
+	ret = mlx5_blocking_notifier_call_chain(sf_dev->parent_mdev,
+						MLX5_DRIVER_EVENT_SF_PEER_DEVLINK,
+						&event_ctx);
+	return ret == NOTIFY_OK ? event_ctx.err : 0;
+}
+
 static int mlx5_sf_dev_probe(struct auxiliary_device *adev, const struct auxiliary_device_id *id)
 {
 	struct mlx5_sf_dev *sf_dev = container_of(adev, struct mlx5_sf_dev, adev);
@@ -54,9 +68,21 @@ static int mlx5_sf_dev_probe(struct auxiliary_device *adev, const struct auxilia
 		mlx5_core_warn(mdev, "mlx5_init_one err=%d\n", err);
 		goto init_one_err;
 	}
+
+	err = mlx5_core_peer_devlink_set(sf_dev, devlink);
+	if (err) {
+		mlx5_core_warn(mdev, "mlx5_core_peer_devlink_set err=%d\n", err);
+		goto peer_devlink_set_err;
+	}
+
 	devlink_register(devlink);
 	return 0;
 
+peer_devlink_set_err:
+	if (mlx5_dev_is_lightweight(sf_dev->mdev))
+		mlx5_uninit_one_light(sf_dev->mdev);
+	else
+		mlx5_uninit_one(sf_dev->mdev);
 init_one_err:
 	iounmap(mdev->iseg);
 remap_err:
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/sf/devlink.c b/drivers/net/ethernet/mellanox/mlx5/core/sf/devlink.c
index e34a8f88c518..964a5b1876f3 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/sf/devlink.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/sf/devlink.c
@@ -28,6 +28,7 @@ struct mlx5_sf_table {
 	struct mutex sf_state_lock; /* Serializes sf state among user cmds & vhca event handler. */
 	struct notifier_block esw_nb;
 	struct notifier_block vhca_nb;
+	struct notifier_block mdev_nb;
 };
 
 static struct mlx5_sf *
@@ -511,6 +512,35 @@ static int mlx5_sf_esw_event(struct notifier_block *nb, unsigned long event, voi
 	return 0;
 }
 
+static int mlx5_sf_mdev_event(struct notifier_block *nb, unsigned long event, void *data)
+{
+	struct mlx5_sf_table *table = container_of(nb, struct mlx5_sf_table, mdev_nb);
+	struct mlx5_sf_peer_devlink_event_ctx *event_ctx = data;
+	int ret = NOTIFY_DONE;
+	struct mlx5_sf *sf;
+
+	if (event != MLX5_DRIVER_EVENT_SF_PEER_DEVLINK)
+		return NOTIFY_DONE;
+
+	table = mlx5_sf_table_try_get(table->dev);
+	if (!table)
+		return NOTIFY_DONE;
+
+	mutex_lock(&table->sf_state_lock);
+	sf = mlx5_sf_lookup_by_function_id(table, event_ctx->fn_id);
+	if (!sf)
+		goto out;
+
+	event_ctx->err = devl_port_fn_devlink_set(&sf->dl_port.dl_port,
+						  event_ctx->devlink);
+
+	ret = NOTIFY_OK;
+out:
+	mutex_unlock(&table->sf_state_lock);
+	mlx5_sf_table_put(table);
+	return ret;
+}
+
 static bool mlx5_sf_table_supported(const struct mlx5_core_dev *dev)
 {
 	return dev->priv.eswitch && MLX5_ESWITCH_MANAGER(dev) &&
@@ -544,6 +574,9 @@ int mlx5_sf_table_init(struct mlx5_core_dev *dev)
 	if (err)
 		goto vhca_err;
 
+	table->mdev_nb.notifier_call = mlx5_sf_mdev_event;
+	mlx5_blocking_notifier_register(dev, &table->mdev_nb);
+
 	return 0;
 
 vhca_err:
@@ -562,6 +595,7 @@ void mlx5_sf_table_cleanup(struct mlx5_core_dev *dev)
 	if (!table)
 		return;
 
+	mlx5_blocking_notifier_unregister(dev, &table->mdev_nb);
 	mlx5_vhca_event_notifier_unregister(table->dev, &table->vhca_nb);
 	mlx5_esw_event_notifier_unregister(dev->priv.eswitch, &table->esw_nb);
 	WARN_ON(refcount_read(&table->refcount));
diff --git a/include/linux/mlx5/device.h b/include/linux/mlx5/device.h
index 4d5be378fa8c..8fbe22de16ef 100644
--- a/include/linux/mlx5/device.h
+++ b/include/linux/mlx5/device.h
@@ -366,6 +366,7 @@ enum mlx5_driver_event {
 	MLX5_DRIVER_EVENT_UPLINK_NETDEV,
 	MLX5_DRIVER_EVENT_MACSEC_SA_ADDED,
 	MLX5_DRIVER_EVENT_MACSEC_SA_DELETED,
+	MLX5_DRIVER_EVENT_SF_PEER_DEVLINK,
 };
 
 enum {
-- 
2.41.0


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [patch net-next v2 10/12] devlink: convert linecard nested devlink to new rel infrastructure
  2023-09-13  7:12 [patch net-next v2 00/12] expose devlink instances relationships Jiri Pirko
                   ` (8 preceding siblings ...)
  2023-09-13  7:12 ` [patch net-next v2 09/12] net/mlx5: SF, Implement peer devlink set for SF representor devlink port Jiri Pirko
@ 2023-09-13  7:12 ` Jiri Pirko
  2023-09-13  7:12 ` [patch net-next v2 11/12] devlink: introduce possibility to expose info about nested devlinks Jiri Pirko
                   ` (3 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: Jiri Pirko @ 2023-09-13  7:12 UTC (permalink / raw)
  To: netdev
  Cc: kuba, pabeni, davem, edumazet, idosch, petrm, jacob.e.keller,
	moshe, shayd, saeedm, horms

From: Jiri Pirko <jiri@nvidia.com>

Benefit from the newly introduced rel infrastructure, treat the linecard
nested devlink instances in the same way as port function instances.
Convert the code to use the rel infrastructure.

Signed-off-by: Jiri Pirko <jiri@nvidia.com>
---
v1->v2:
- new patch
---
 .../mellanox/mlxsw/core_linecard_dev.c        |  9 ++--
 include/net/devlink.h                         |  4 +-
 net/devlink/linecard.c                        | 47 ++++++++++++++-----
 3 files changed, 42 insertions(+), 18 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlxsw/core_linecard_dev.c b/drivers/net/ethernet/mellanox/mlxsw/core_linecard_dev.c
index af37e650a8ad..e8d6fe35bf36 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/core_linecard_dev.c
+++ b/drivers/net/ethernet/mellanox/mlxsw/core_linecard_dev.c
@@ -132,6 +132,7 @@ static int mlxsw_linecard_bdev_probe(struct auxiliary_device *adev,
 	struct mlxsw_linecard *linecard = linecard_bdev->linecard;
 	struct mlxsw_linecard_dev *linecard_dev;
 	struct devlink *devlink;
+	int err;
 
 	devlink = devlink_alloc(&mlxsw_linecard_dev_devlink_ops,
 				sizeof(*linecard_dev), &adev->dev);
@@ -141,8 +142,12 @@ static int mlxsw_linecard_bdev_probe(struct auxiliary_device *adev,
 	linecard_dev->linecard = linecard_bdev->linecard;
 	linecard_bdev->linecard_dev = linecard_dev;
 
+	err = devlink_linecard_nested_dl_set(linecard->devlink_linecard, devlink);
+	if (err) {
+		devlink_free(devlink);
+		return err;
+	}
 	devlink_register(devlink);
-	devlink_linecard_nested_dl_set(linecard->devlink_linecard, devlink);
 	return 0;
 }
 
@@ -151,9 +156,7 @@ static void mlxsw_linecard_bdev_remove(struct auxiliary_device *adev)
 	struct mlxsw_linecard_bdev *linecard_bdev =
 			container_of(adev, struct mlxsw_linecard_bdev, adev);
 	struct devlink *devlink = priv_to_devlink(linecard_bdev->linecard_dev);
-	struct mlxsw_linecard *linecard = linecard_bdev->linecard;
 
-	devlink_linecard_nested_dl_set(linecard->devlink_linecard, NULL);
 	devlink_unregister(devlink);
 	devlink_free(devlink);
 }
diff --git a/include/net/devlink.h b/include/net/devlink.h
index 2655ab6101ec..0dfcd7d7fa18 100644
--- a/include/net/devlink.h
+++ b/include/net/devlink.h
@@ -1720,8 +1720,8 @@ void devlink_linecard_provision_clear(struct devlink_linecard *linecard);
 void devlink_linecard_provision_fail(struct devlink_linecard *linecard);
 void devlink_linecard_activate(struct devlink_linecard *linecard);
 void devlink_linecard_deactivate(struct devlink_linecard *linecard);
-void devlink_linecard_nested_dl_set(struct devlink_linecard *linecard,
-				    struct devlink *nested_devlink);
+int devlink_linecard_nested_dl_set(struct devlink_linecard *linecard,
+				   struct devlink *nested_devlink);
 int devl_sb_register(struct devlink *devlink, unsigned int sb_index,
 		     u32 size, u16 ingress_pools_count,
 		     u16 egress_pools_count, u16 ingress_tc_count,
diff --git a/net/devlink/linecard.c b/net/devlink/linecard.c
index 36170f466878..9ff1813f88c5 100644
--- a/net/devlink/linecard.c
+++ b/net/devlink/linecard.c
@@ -17,7 +17,7 @@ struct devlink_linecard {
 	const char *type;
 	struct devlink_linecard_type *types;
 	unsigned int types_count;
-	struct devlink *nested_devlink;
+	u32 rel_index;
 };
 
 unsigned int devlink_linecard_index(struct devlink_linecard *linecard)
@@ -112,10 +112,10 @@ static int devlink_nl_linecard_fill(struct sk_buff *msg,
 		nla_nest_end(msg, attr);
 	}
 
-	if (linecard->nested_devlink &&
-	    devlink_nl_put_nested_handle(msg, devlink_net(devlink),
-					 linecard->nested_devlink,
-					 DEVLINK_ATTR_NESTED_DEVLINK))
+	if (devlink_rel_devlink_handle_put(msg, devlink,
+					   linecard->rel_index,
+					   DEVLINK_ATTR_NESTED_DEVLINK,
+					   NULL))
 		goto nla_put_failure;
 
 	genlmsg_end(msg, hdr);
@@ -524,7 +524,6 @@ EXPORT_SYMBOL_GPL(devlink_linecard_provision_set);
 void devlink_linecard_provision_clear(struct devlink_linecard *linecard)
 {
 	mutex_lock(&linecard->state_lock);
-	WARN_ON(linecard->nested_devlink);
 	linecard->state = DEVLINK_LINECARD_STATE_UNPROVISIONED;
 	linecard->type = NULL;
 	devlink_linecard_notify(linecard, DEVLINK_CMD_LINECARD_NEW);
@@ -543,7 +542,6 @@ EXPORT_SYMBOL_GPL(devlink_linecard_provision_clear);
 void devlink_linecard_provision_fail(struct devlink_linecard *linecard)
 {
 	mutex_lock(&linecard->state_lock);
-	WARN_ON(linecard->nested_devlink);
 	linecard->state = DEVLINK_LINECARD_STATE_PROVISIONING_FAILED;
 	devlink_linecard_notify(linecard, DEVLINK_CMD_LINECARD_NEW);
 	mutex_unlock(&linecard->state_lock);
@@ -591,6 +589,27 @@ void devlink_linecard_deactivate(struct devlink_linecard *linecard)
 }
 EXPORT_SYMBOL_GPL(devlink_linecard_deactivate);
 
+static void devlink_linecard_rel_notify_cb(struct devlink *devlink,
+					   u32 linecard_index)
+{
+	struct devlink_linecard *linecard;
+
+	linecard = devlink_linecard_get_by_index(devlink, linecard_index);
+	if (!linecard)
+		return;
+	devlink_linecard_notify(linecard, DEVLINK_CMD_LINECARD_NEW);
+}
+
+static void devlink_linecard_rel_cleanup_cb(struct devlink *devlink,
+					    u32 linecard_index, u32 rel_index)
+{
+	struct devlink_linecard *linecard;
+
+	linecard = devlink_linecard_get_by_index(devlink, linecard_index);
+	if (linecard && linecard->rel_index == rel_index)
+		linecard->rel_index = 0;
+}
+
 /**
  *	devlink_linecard_nested_dl_set - Attach/detach nested devlink
  *					 instance to linecard.
@@ -598,12 +617,14 @@ EXPORT_SYMBOL_GPL(devlink_linecard_deactivate);
  *	@linecard: devlink linecard
  *	@nested_devlink: devlink instance to attach or NULL to detach
  */
-void devlink_linecard_nested_dl_set(struct devlink_linecard *linecard,
-				    struct devlink *nested_devlink)
+int devlink_linecard_nested_dl_set(struct devlink_linecard *linecard,
+				   struct devlink *nested_devlink)
 {
-	mutex_lock(&linecard->state_lock);
-	linecard->nested_devlink = nested_devlink;
-	devlink_linecard_notify(linecard, DEVLINK_CMD_LINECARD_NEW);
-	mutex_unlock(&linecard->state_lock);
+	return devlink_rel_nested_in_add(&linecard->rel_index,
+					 linecard->devlink->index,
+					 linecard->index,
+					 devlink_linecard_rel_notify_cb,
+					 devlink_linecard_rel_cleanup_cb,
+					 nested_devlink);
 }
 EXPORT_SYMBOL_GPL(devlink_linecard_nested_dl_set);
-- 
2.41.0


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [patch net-next v2 11/12] devlink: introduce possibility to expose info about nested devlinks
  2023-09-13  7:12 [patch net-next v2 00/12] expose devlink instances relationships Jiri Pirko
                   ` (9 preceding siblings ...)
  2023-09-13  7:12 ` [patch net-next v2 10/12] devlink: convert linecard nested devlink to new rel infrastructure Jiri Pirko
@ 2023-09-13  7:12 ` Jiri Pirko
  2023-09-13  7:12 ` [patch net-next v2 12/12] net/mlx5e: Set en auxiliary devlink instance as nested Jiri Pirko
                   ` (2 subsequent siblings)
  13 siblings, 0 replies; 15+ messages in thread
From: Jiri Pirko @ 2023-09-13  7:12 UTC (permalink / raw)
  To: netdev
  Cc: kuba, pabeni, davem, edumazet, idosch, petrm, jacob.e.keller,
	moshe, shayd, saeedm, horms

From: Jiri Pirko <jiri@nvidia.com>

In mlx5, there is a devlink instance created for PCI device. Also, one
separate devlink instance is created for auxiliary device that
represents the netdev of uplink port. This relation is currently
invisible to the devlink user.

Benefit from the rel infrastructure and allow for nested devlink
instance to set the relationship for the nested-in devlink instance.
Note that there may be many nested instances, therefore use xarray to
hold the list of rel_indexes for individual nested instances.

Signed-off-by: Jiri Pirko <jiri@nvidia.com>
---
v1->v2:
- new patch
---
 include/net/devlink.h       |  2 ++
 net/devlink/core.c          |  2 ++
 net/devlink/dev.c           | 49 +++++++++++++++++++++++++++++++++++++
 net/devlink/devl_internal.h |  1 +
 4 files changed, 54 insertions(+)

diff --git a/include/net/devlink.h b/include/net/devlink.h
index 0dfcd7d7fa18..fad8e36e3d98 100644
--- a/include/net/devlink.h
+++ b/include/net/devlink.h
@@ -1921,6 +1921,8 @@ devlink_health_reporter_state_update(struct devlink_health_reporter *reporter,
 void
 devlink_health_reporter_recovery_done(struct devlink_health_reporter *reporter);
 
+int devl_nested_devlink_set(struct devlink *devlink,
+			    struct devlink *nested_devlink);
 bool devlink_is_reload_failed(const struct devlink *devlink);
 void devlink_remote_reload_actions_performed(struct devlink *devlink,
 					     enum devlink_reload_limit limit,
diff --git a/net/devlink/core.c b/net/devlink/core.c
index 2a98ff9a2f6b..bcbbb952569f 100644
--- a/net/devlink/core.c
+++ b/net/devlink/core.c
@@ -430,6 +430,7 @@ struct devlink *devlink_alloc_ns(const struct devlink_ops *ops,
 	xa_init_flags(&devlink->ports, XA_FLAGS_ALLOC);
 	xa_init_flags(&devlink->params, XA_FLAGS_ALLOC);
 	xa_init_flags(&devlink->snapshot_ids, XA_FLAGS_ALLOC);
+	xa_init_flags(&devlink->nested_rels, XA_FLAGS_ALLOC);
 	write_pnet(&devlink->_net, net);
 	INIT_LIST_HEAD(&devlink->rate_list);
 	INIT_LIST_HEAD(&devlink->linecard_list);
@@ -476,6 +477,7 @@ void devlink_free(struct devlink *devlink)
 	WARN_ON(!list_empty(&devlink->linecard_list));
 	WARN_ON(!xa_empty(&devlink->ports));
 
+	xa_destroy(&devlink->nested_rels);
 	xa_destroy(&devlink->snapshot_ids);
 	xa_destroy(&devlink->params);
 	xa_destroy(&devlink->ports);
diff --git a/net/devlink/dev.c b/net/devlink/dev.c
index 3ae26d9088ab..dc8039ca2b38 100644
--- a/net/devlink/dev.c
+++ b/net/devlink/dev.c
@@ -138,6 +138,23 @@ devlink_reload_stats_put(struct sk_buff *msg, struct devlink *devlink, bool is_r
 	return -EMSGSIZE;
 }
 
+static int devlink_nl_nested_fill(struct sk_buff *msg, struct devlink *devlink)
+{
+	unsigned long rel_index;
+	void *unused;
+	int err;
+
+	xa_for_each(&devlink->nested_rels, rel_index, unused) {
+		err = devlink_rel_devlink_handle_put(msg, devlink,
+						     rel_index,
+						     DEVLINK_ATTR_NESTED_DEVLINK,
+						     NULL);
+		if (err)
+			return err;
+	}
+	return 0;
+}
+
 static int devlink_nl_fill(struct sk_buff *msg, struct devlink *devlink,
 			   enum devlink_command cmd, u32 portid,
 			   u32 seq, int flags)
@@ -164,6 +181,10 @@ static int devlink_nl_fill(struct sk_buff *msg, struct devlink *devlink,
 		goto dev_stats_nest_cancel;
 
 	nla_nest_end(msg, dev_stats);
+
+	if (devlink_nl_nested_fill(msg, devlink))
+		goto nla_put_failure;
+
 	genlmsg_end(msg, hdr);
 	return 0;
 
@@ -230,6 +251,34 @@ int devlink_nl_get_dumpit(struct sk_buff *msg, struct netlink_callback *cb)
 	return devlink_nl_dumpit(msg, cb, devlink_nl_get_dump_one);
 }
 
+static void devlink_rel_notify_cb(struct devlink *devlink, u32 obj_index)
+{
+	devlink_notify(devlink, DEVLINK_CMD_NEW);
+}
+
+static void devlink_rel_cleanup_cb(struct devlink *devlink, u32 obj_index,
+				   u32 rel_index)
+{
+	xa_erase(&devlink->nested_rels, rel_index);
+}
+
+int devl_nested_devlink_set(struct devlink *devlink,
+			    struct devlink *nested_devlink)
+{
+	u32 rel_index;
+	int err;
+
+	err = devlink_rel_nested_in_add(&rel_index, devlink->index, 0,
+					devlink_rel_notify_cb,
+					devlink_rel_cleanup_cb,
+					nested_devlink);
+	if (err)
+		return err;
+	return xa_insert(&devlink->nested_rels, rel_index,
+			 xa_mk_value(0), GFP_KERNEL);
+}
+EXPORT_SYMBOL_GPL(devl_nested_devlink_set);
+
 void devlink_notify_register(struct devlink *devlink)
 {
 	devlink_notify(devlink, DEVLINK_CMD_NEW);
diff --git a/net/devlink/devl_internal.h b/net/devlink/devl_internal.h
index 4cb534aff44d..741d1bf1bec8 100644
--- a/net/devlink/devl_internal.h
+++ b/net/devlink/devl_internal.h
@@ -58,6 +58,7 @@ struct devlink {
 	refcount_t refcount;
 	struct rcu_work rwork;
 	struct devlink_rel *rel;
+	struct xarray nested_rels;
 	char priv[] __aligned(NETDEV_ALIGN);
 };
 
-- 
2.41.0


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [patch net-next v2 12/12] net/mlx5e: Set en auxiliary devlink instance as nested
  2023-09-13  7:12 [patch net-next v2 00/12] expose devlink instances relationships Jiri Pirko
                   ` (10 preceding siblings ...)
  2023-09-13  7:12 ` [patch net-next v2 11/12] devlink: introduce possibility to expose info about nested devlinks Jiri Pirko
@ 2023-09-13  7:12 ` Jiri Pirko
  2023-09-14 13:57 ` [patch net-next v2 00/12] expose devlink instances relationships Simon Horman
  2023-09-17 13:30 ` patchwork-bot+netdevbpf
  13 siblings, 0 replies; 15+ messages in thread
From: Jiri Pirko @ 2023-09-13  7:12 UTC (permalink / raw)
  To: netdev
  Cc: kuba, pabeni, davem, edumazet, idosch, petrm, jacob.e.keller,
	moshe, shayd, saeedm, horms

From: Jiri Pirko <jiri@nvidia.com>

Benefit from the previous commit introducing exposure of devlink
instances relationship and set the nested instance for en auxiliary
device.

Signed-off-by: Jiri Pirko <jiri@nvidia.com>
---
v1->v2:
- new patch
---
 drivers/net/ethernet/mellanox/mlx5/core/en/devlink.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/devlink.c b/drivers/net/ethernet/mellanox/mlx5/core/en/devlink.c
index c6b6e290fd79..0b1ac6e5c890 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en/devlink.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en/devlink.c
@@ -12,11 +12,19 @@ struct mlx5e_dev *mlx5e_create_devlink(struct device *dev,
 {
 	struct mlx5e_dev *mlx5e_dev;
 	struct devlink *devlink;
+	int err;
 
 	devlink = devlink_alloc_ns(&mlx5e_devlink_ops, sizeof(*mlx5e_dev),
 				   devlink_net(priv_to_devlink(mdev)), dev);
 	if (!devlink)
 		return ERR_PTR(-ENOMEM);
+
+	err = devl_nested_devlink_set(priv_to_devlink(mdev), devlink);
+	if (err) {
+		devlink_free(devlink);
+		return ERR_PTR(err);
+	}
+
 	devlink_register(devlink);
 	return devlink_priv(devlink);
 }
-- 
2.41.0


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* Re: [patch net-next v2 00/12] expose devlink instances relationships
  2023-09-13  7:12 [patch net-next v2 00/12] expose devlink instances relationships Jiri Pirko
                   ` (11 preceding siblings ...)
  2023-09-13  7:12 ` [patch net-next v2 12/12] net/mlx5e: Set en auxiliary devlink instance as nested Jiri Pirko
@ 2023-09-14 13:57 ` Simon Horman
  2023-09-17 13:30 ` patchwork-bot+netdevbpf
  13 siblings, 0 replies; 15+ messages in thread
From: Simon Horman @ 2023-09-14 13:57 UTC (permalink / raw)
  To: Jiri Pirko
  Cc: netdev, kuba, pabeni, davem, edumazet, idosch, petrm,
	jacob.e.keller, moshe, shayd, saeedm

On Wed, Sep 13, 2023 at 09:12:31AM +0200, Jiri Pirko wrote:
> From: Jiri Pirko <jiri@nvidia.com>
> 
> Currently, the user can instantiate new SF using "devlink port add"
> command. That creates an E-switch representor devlink port.
> 
> When user activates this SF, there is an auxiliary device created and
> probed for it which leads to SF devlink instance creation.
> 
> There is 1:1 relationship between E-switch representor devlink port and
> the SF auxiliary device devlink instance.
> 
> Also, for example in mlx5, one devlink instance is created for
> PCI device and one is created for an auxiliary device that represents
> the uplink port. The relation between these is invisible to the user.
> 
> Patches #1-#3 and #5 are small preparations.
> 
> Patch #4 adds netnsid attribute for nested devlink if that in a
> different namespace.
> 
> Patch #5 is the main one in this set, introduces the relationship
> tracking infrastructure later on used to track SFs, linecards and
> devlink instance relationships with nested devlink instances.
> 
> Expose the relation to the user by introducing new netlink attribute
> DEVLINK_PORT_FN_ATTR_DEVLINK which contains the devlink instance related
> to devlink port function. This is done by patch #8.
> Patch #9 implements this in mlx5 driver.
> 
> Patch #10 converts the linecard nested devlink handling to the newly
> introduced rel infrastructure.
> 
> Patch #11 benefits from the rel infra and introduces possiblitily to
> have relation between devlink instances.
> Patch #12 implements this in mlx5 driver.
> 
> Examples:
> $ devlink dev
> pci/0000:08:00.0: nested_devlink auxiliary/mlx5_core.eth.0
> pci/0000:08:00.1: nested_devlink auxiliary/mlx5_core.eth.1
> auxiliary/mlx5_core.eth.1
> auxiliary/mlx5_core.eth.0
> 
> $ devlink port add pci/0000:08:00.0 flavour pcisf pfnum 0 sfnum 106
> pci/0000:08:00.0/32768: type eth netdev eth4 flavour pcisf controller 0 pfnum 0 sfnum 106 splittable false
>   function:
>     hw_addr 00:00:00:00:00:00 state inactive opstate detached roce enable
> $ devlink port function set pci/0000:08:00.0/32768 state active
> $ devlink port show pci/0000:08:00.0/32768
> pci/0000:08:00.0/32768: type eth netdev eth4 flavour pcisf controller 0 pfnum 0 sfnum 106 splittable false
>   function:
>     hw_addr 00:00:00:00:00:00 state active opstate attached roce enable nested_devlink auxiliary/mlx5_core.sf.2
> 
> # devlink dev reload auxiliary/mlx5_core.sf.2 netns ns1
> $ devlink port show pci/0000:08:00.0/32768
> pci/0000:08:00.0/32768: type eth netdev eth4 flavour pcisf controller 0 pfnum 0 sfnum 106 splittable false
>   function:
>     hw_addr 00:00:00:00:00:00 state active opstate attached roce enable nested_devlink auxiliary/mlx5_core.sf.2 nested_devlink_netns ns1
> 
> Jiri Pirko (12):
>   devlink: move linecard struct into linecard.c
>   net/mlx5: Disable eswitch as the first thing in mlx5_unload()
>   net/mlx5: Lift reload limitation when SFs are present
>   devlink: put netnsid to nested handle
>   devlink: move devlink_nl_put_nested_handle() into netlink.c
>   devlink: extend devlink_nl_put_nested_handle() with attrtype arg
>   devlink: introduce object and nested devlink relationship infra
>   devlink: expose peer SF devlink instance
>   net/mlx5: SF, Implement peer devlink set for SF representor devlink
>     port
>   devlink: convert linecard nested devlink to new rel infrastructure
>   devlink: introduce possibility to expose info about nested devlinks
>   net/mlx5e: Set en auxiliary devlink instance as nested

Reviewed-by: Simon Horman <horms@kernel.org>


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [patch net-next v2 00/12] expose devlink instances relationships
  2023-09-13  7:12 [patch net-next v2 00/12] expose devlink instances relationships Jiri Pirko
                   ` (12 preceding siblings ...)
  2023-09-14 13:57 ` [patch net-next v2 00/12] expose devlink instances relationships Simon Horman
@ 2023-09-17 13:30 ` patchwork-bot+netdevbpf
  13 siblings, 0 replies; 15+ messages in thread
From: patchwork-bot+netdevbpf @ 2023-09-17 13:30 UTC (permalink / raw)
  To: Jiri Pirko
  Cc: netdev, kuba, pabeni, davem, edumazet, idosch, petrm,
	jacob.e.keller, moshe, shayd, saeedm, horms

Hello:

This series was applied to netdev/net-next.git (main)
by David S. Miller <davem@davemloft.net>:

On Wed, 13 Sep 2023 09:12:31 +0200 you wrote:
> From: Jiri Pirko <jiri@nvidia.com>
> 
> Currently, the user can instantiate new SF using "devlink port add"
> command. That creates an E-switch representor devlink port.
> 
> When user activates this SF, there is an auxiliary device created and
> probed for it which leads to SF devlink instance creation.
> 
> [...]

Here is the summary with links:
  - [net-next,v2,01/12] devlink: move linecard struct into linecard.c
    https://git.kernel.org/netdev/net-next/c/d0b7e990f760
  - [net-next,v2,02/12] net/mlx5: Disable eswitch as the first thing in mlx5_unload()
    https://git.kernel.org/netdev/net-next/c/85b47dc40bbc
  - [net-next,v2,03/12] net/mlx5: Lift reload limitation when SFs are present
    https://git.kernel.org/netdev/net-next/c/602d61e307ac
  - [net-next,v2,04/12] devlink: put netnsid to nested handle
    https://git.kernel.org/netdev/net-next/c/ad99637ac92d
  - [net-next,v2,05/12] devlink: move devlink_nl_put_nested_handle() into netlink.c
    https://git.kernel.org/netdev/net-next/c/af1f1400af02
  - [net-next,v2,06/12] devlink: extend devlink_nl_put_nested_handle() with attrtype arg
    https://git.kernel.org/netdev/net-next/c/1c2197c47a93
  - [net-next,v2,07/12] devlink: introduce object and nested devlink relationship infra
    https://git.kernel.org/netdev/net-next/c/c137743bce02
  - [net-next,v2,08/12] devlink: expose peer SF devlink instance
    https://git.kernel.org/netdev/net-next/c/0b7a2721e36c
  - [net-next,v2,09/12] net/mlx5: SF, Implement peer devlink set for SF representor devlink port
    https://git.kernel.org/netdev/net-next/c/ac5f395685bd
  - [net-next,v2,10/12] devlink: convert linecard nested devlink to new rel infrastructure
    https://git.kernel.org/netdev/net-next/c/9473bc0119e7
  - [net-next,v2,11/12] devlink: introduce possibility to expose info about nested devlinks
    https://git.kernel.org/netdev/net-next/c/c5e1bf8a51cf
  - [net-next,v2,12/12] net/mlx5e: Set en auxiliary devlink instance as nested
    https://git.kernel.org/netdev/net-next/c/6c75258cc220

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2023-09-17 13:30 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-09-13  7:12 [patch net-next v2 00/12] expose devlink instances relationships Jiri Pirko
2023-09-13  7:12 ` [patch net-next v2 01/12] devlink: move linecard struct into linecard.c Jiri Pirko
2023-09-13  7:12 ` [patch net-next v2 02/12] net/mlx5: Disable eswitch as the first thing in mlx5_unload() Jiri Pirko
2023-09-13  7:12 ` [patch net-next v2 03/12] net/mlx5: Lift reload limitation when SFs are present Jiri Pirko
2023-09-13  7:12 ` [patch net-next v2 04/12] devlink: put netnsid to nested handle Jiri Pirko
2023-09-13  7:12 ` [patch net-next v2 05/12] devlink: move devlink_nl_put_nested_handle() into netlink.c Jiri Pirko
2023-09-13  7:12 ` [patch net-next v2 06/12] devlink: extend devlink_nl_put_nested_handle() with attrtype arg Jiri Pirko
2023-09-13  7:12 ` [patch net-next v2 07/12] devlink: introduce object and nested devlink relationship infra Jiri Pirko
2023-09-13  7:12 ` [patch net-next v2 08/12] devlink: expose peer SF devlink instance Jiri Pirko
2023-09-13  7:12 ` [patch net-next v2 09/12] net/mlx5: SF, Implement peer devlink set for SF representor devlink port Jiri Pirko
2023-09-13  7:12 ` [patch net-next v2 10/12] devlink: convert linecard nested devlink to new rel infrastructure Jiri Pirko
2023-09-13  7:12 ` [patch net-next v2 11/12] devlink: introduce possibility to expose info about nested devlinks Jiri Pirko
2023-09-13  7:12 ` [patch net-next v2 12/12] net/mlx5e: Set en auxiliary devlink instance as nested Jiri Pirko
2023-09-14 13:57 ` [patch net-next v2 00/12] expose devlink instances relationships Simon Horman
2023-09-17 13:30 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).