All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net-next 0/3] devlink: Introduce PCI PF, VF ports and attributes
@ 2019-07-01 12:27 Parav Pandit
  2019-07-01 12:27 ` [PATCH net-next 1/3] devlink: Introduce PCI PF port flavour and port attribute Parav Pandit
                   ` (9 more replies)
  0 siblings, 10 replies; 71+ messages in thread
From: Parav Pandit @ 2019-07-01 12:27 UTC (permalink / raw)
  To: netdev; +Cc: jiri, saeedm, jakub.kicinski, Parav Pandit

This patchset carry forwards the work initiated in [1] and discussion
futher concluded at [2].

To improve visibility of representor netdevice, its association with
PF or VF, physical port, two new devlink port flavours are added as
PCI PF and PCI VF ports.

A sample eswitch view can be seen below, which will be futher extended to
mdev subdevices of a PCI function in future.

Patch-1,2 extends devlink port attributes and port flavour.
Patch-3 extends mlx5 driver to register devlink ports for PF, VF and
physical link.

                                +---+      +---+
                              vf|   |      |   | pf
                                +-+-+      +-+-+
physical link <---------+         |          |
                        |         |          |
                        |         |          |
                      +-+-+     +-+-+      +-+-+
                      | 1 |     | 2 |      | 3 |
                   +--+---+-----+---+------+---+--+
                   |  physical   vf         pf    |
                   |  port       port       port  |
                   |                              |
                   |             eswitch          |
                   |                              |
                   +------------------------------+

[1] https://www.spinics.net/lists/netdev/msg555797.html
[2] https://marc.info/?l=linux-netdev&m=155354609408485&w=2

Parav Pandit (3):
  devlink: Introduce PCI PF port flavour and port attribute
  devlink: Introduce PCI VF port flavour and port attribute
  net/mlx5e: Register devlink ports for physical link, PCI PF, VFs

 .../net/ethernet/mellanox/mlx5/core/en_rep.c  | 108 +++++++++++++-----
 .../net/ethernet/mellanox/mlx5/core/en_rep.h  |   1 +
 include/net/devlink.h                         |  22 ++++
 include/uapi/linux/devlink.h                  |  11 ++
 net/core/devlink.c                            | 107 ++++++++++++++---
 5 files changed, 204 insertions(+), 45 deletions(-)

-- 
2.19.2


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

* [PATCH net-next 1/3] devlink: Introduce PCI PF port flavour and port attribute
  2019-07-01 12:27 [PATCH net-next 0/3] devlink: Introduce PCI PF, VF ports and attributes Parav Pandit
@ 2019-07-01 12:27 ` Parav Pandit
  2019-07-01 23:26   ` Jakub Kicinski
  2019-07-01 12:27 ` [PATCH net-next 2/3] devlink: Introduce PCI VF " Parav Pandit
                   ` (8 subsequent siblings)
  9 siblings, 1 reply; 71+ messages in thread
From: Parav Pandit @ 2019-07-01 12:27 UTC (permalink / raw)
  To: netdev; +Cc: jiri, saeedm, jakub.kicinski, Parav Pandit

In an eswitch, PCI PF may have port which is normally represented
using a representor netdevice.
To have better visibility of eswitch port, its association with
PF, a representor netdevice and port number, introduce a PCI PF port
flavour and port attriute.

When devlink port flavour is PCI PF, fill up PCI PF attributes of the
port.

Extend port name creation using PCI PF number on best effort basis.
So that vendor drivers can skip defining their own scheme.

$ devlink port show
pci/0000:05:00.0/0: type eth netdev eth0 flavour pcipf pfnum 0

Acked-by: Jiri Pirko <jiri@mellanox.com>
Signed-off-by: Parav Pandit <parav@mellanox.com>
---
 include/net/devlink.h        | 11 ++++++
 include/uapi/linux/devlink.h |  5 +++
 net/core/devlink.c           | 71 +++++++++++++++++++++++++++++-------
 3 files changed, 73 insertions(+), 14 deletions(-)

diff --git a/include/net/devlink.h b/include/net/devlink.h
index 6625ea068d5e..8db9c0e83fb5 100644
--- a/include/net/devlink.h
+++ b/include/net/devlink.h
@@ -38,6 +38,10 @@ struct devlink {
 	char priv[0] __aligned(NETDEV_ALIGN);
 };
 
+struct devlink_port_pci_pf_attrs {
+	u16 pf;	/* Associated PCI PF for this port. */
+};
+
 struct devlink_port_attrs {
 	u8 set:1,
 	   split:1,
@@ -46,6 +50,9 @@ struct devlink_port_attrs {
 	u32 port_number; /* same value as "split group" */
 	u32 split_subport_number;
 	struct netdev_phys_item_id switch_id;
+	union {
+		struct devlink_port_pci_pf_attrs pci_pf;
+	};
 };
 
 struct devlink_port {
@@ -590,6 +597,10 @@ void devlink_port_attrs_set(struct devlink_port *devlink_port,
 			    u32 split_subport_number,
 			    const unsigned char *switch_id,
 			    unsigned char switch_id_len);
+void devlink_port_attrs_pci_pf_set(struct devlink_port *devlink_port,
+				   u32 port_number,
+				   const unsigned char *switch_id,
+				   unsigned char switch_id_len, u16 pf);
 int devlink_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/include/uapi/linux/devlink.h b/include/uapi/linux/devlink.h
index 5287b42c181f..f7323884c3fe 100644
--- a/include/uapi/linux/devlink.h
+++ b/include/uapi/linux/devlink.h
@@ -169,6 +169,10 @@ enum devlink_port_flavour {
 	DEVLINK_PORT_FLAVOUR_DSA, /* Distributed switch architecture
 				   * interconnect port.
 				   */
+	DEVLINK_PORT_FLAVOUR_PCI_PF, /* Represents eswitch port for
+				      * the PCI PF. It is an internal
+				      * port that faces the PCI PF.
+				      */
 };
 
 enum devlink_param_cmode {
@@ -337,6 +341,7 @@ enum devlink_attr {
 	DEVLINK_ATTR_FLASH_UPDATE_STATUS_DONE,	/* u64 */
 	DEVLINK_ATTR_FLASH_UPDATE_STATUS_TOTAL,	/* u64 */
 
+	DEVLINK_ATTR_PORT_PCI_PF_NUMBER,	/* u16 */
 	/* add new attributes above here, update the policy in devlink.c */
 
 	__DEVLINK_ATTR_MAX,
diff --git a/net/core/devlink.c b/net/core/devlink.c
index 89c533778135..001f9e2c96f0 100644
--- a/net/core/devlink.c
+++ b/net/core/devlink.c
@@ -517,6 +517,11 @@ static int devlink_nl_port_attrs_put(struct sk_buff *msg,
 		return -EMSGSIZE;
 	if (nla_put_u32(msg, DEVLINK_ATTR_PORT_NUMBER, attrs->port_number))
 		return -EMSGSIZE;
+	if (devlink_port->attrs.flavour == DEVLINK_PORT_FLAVOUR_PCI_PF) {
+		if (nla_put_u16(msg, DEVLINK_ATTR_PORT_PCI_PF_NUMBER,
+				attrs->pci_pf.pf))
+			return -EMSGSIZE;
+	}
 	if (!attrs->split)
 		return 0;
 	if (nla_put_u32(msg, DEVLINK_ATTR_PORT_SPLIT_GROUP, attrs->port_number))
@@ -5738,6 +5743,30 @@ void devlink_port_type_clear(struct devlink_port *devlink_port)
 }
 EXPORT_SYMBOL_GPL(devlink_port_type_clear);
 
+static void __devlink_port_attrs_set(struct devlink_port *devlink_port,
+				     enum devlink_port_flavour flavour,
+				     u32 port_number,
+				     const unsigned char *switch_id,
+				     unsigned char switch_id_len)
+{
+	struct devlink_port_attrs *attrs = &devlink_port->attrs;
+
+	if (WARN_ON(devlink_port->registered))
+		return;
+	attrs->set = true;
+	attrs->flavour = flavour;
+	attrs->port_number = port_number;
+	if (switch_id) {
+		attrs->switch_port = true;
+		if (WARN_ON(switch_id_len > MAX_PHYS_ITEM_ID_LEN))
+			switch_id_len = MAX_PHYS_ITEM_ID_LEN;
+		memcpy(attrs->switch_id.id, switch_id, switch_id_len);
+		attrs->switch_id.id_len = switch_id_len;
+	} else {
+		attrs->switch_port = false;
+	}
+}
+
 /**
  *	devlink_port_attrs_set - Set port attributes
  *
@@ -5761,25 +5790,36 @@ void devlink_port_attrs_set(struct devlink_port *devlink_port,
 {
 	struct devlink_port_attrs *attrs = &devlink_port->attrs;
 
-	if (WARN_ON(devlink_port->registered))
-		return;
-	attrs->set = true;
-	attrs->flavour = flavour;
-	attrs->port_number = port_number;
+	__devlink_port_attrs_set(devlink_port, flavour, port_number,
+				 switch_id, switch_id_len);
 	attrs->split = split;
 	attrs->split_subport_number = split_subport_number;
-	if (switch_id) {
-		attrs->switch_port = true;
-		if (WARN_ON(switch_id_len > MAX_PHYS_ITEM_ID_LEN))
-			switch_id_len = MAX_PHYS_ITEM_ID_LEN;
-		memcpy(attrs->switch_id.id, switch_id, switch_id_len);
-		attrs->switch_id.id_len = switch_id_len;
-	} else {
-		attrs->switch_port = false;
-	}
 }
 EXPORT_SYMBOL_GPL(devlink_port_attrs_set);
 
+/**
+ *	devlink_port_attrs_pci_pf_set - Set PCI PF port attributes
+ *
+ *	@devlink_port: devlink port
+ *	@port_number: number of the port that is facing a PF
+ *	@pf: associated PF for the devlink port instance
+ *	@switch_id: if the port is part of switch, this is buffer with ID,
+ *	            otwerwise this is NULL
+ *	@switch_id_len: length of the switch_id buffer
+ */
+void devlink_port_attrs_pci_pf_set(struct devlink_port *devlink_port,
+				   u32 port_number,
+				   const unsigned char *switch_id,
+				   unsigned char switch_id_len, u16 pf)
+{
+	struct devlink_port_attrs *attrs = &devlink_port->attrs;
+
+	__devlink_port_attrs_set(devlink_port, DEVLINK_PORT_FLAVOUR_PCI_PF,
+				 port_number, switch_id, switch_id_len);
+	attrs->pci_pf.pf = pf;
+}
+EXPORT_SYMBOL_GPL(devlink_port_attrs_pci_pf_set);
+
 static int __devlink_port_phys_port_name_get(struct devlink_port *devlink_port,
 					     char *name, size_t len)
 {
@@ -5804,6 +5844,9 @@ static int __devlink_port_phys_port_name_get(struct devlink_port *devlink_port,
 		 */
 		WARN_ON(1);
 		return -EINVAL;
+	case DEVLINK_PORT_FLAVOUR_PCI_PF:
+		n = snprintf(name, len, "pf%u", attrs->pci_pf.pf);
+		break;
 	}
 
 	if (n >= len)
-- 
2.19.2


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

* [PATCH net-next 2/3] devlink: Introduce PCI VF port flavour and port attribute
  2019-07-01 12:27 [PATCH net-next 0/3] devlink: Introduce PCI PF, VF ports and attributes Parav Pandit
  2019-07-01 12:27 ` [PATCH net-next 1/3] devlink: Introduce PCI PF port flavour and port attribute Parav Pandit
@ 2019-07-01 12:27 ` Parav Pandit
  2019-07-01 12:27 ` [PATCH net-next 3/3] net/mlx5e: Register devlink ports for physical link, PCI PF, VFs Parav Pandit
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 71+ messages in thread
From: Parav Pandit @ 2019-07-01 12:27 UTC (permalink / raw)
  To: netdev; +Cc: jiri, saeedm, jakub.kicinski, Parav Pandit

In an eswitch, PCI VF may have port which is normally represented using
a representor netdevice.
To have better visibility of eswitch port, its association with VF,
its representor netdevice and port number, introduce a PCI VF
port flavour.

When devlink port flavour is PCI VF, fill up PCI VF attributes of
the port.

Extend port name creation using PCI PF and VF number scheme on best
effort basis, so that vendor drivers can skip defining their own scheme.

$ devlink port show
pci/0000:05:00.0/0: type eth netdev eth0 flavour pcipf pfnum 0
pci/0000:05:00.0/1: type eth netdev eth1 flavour pcivf pfnum 0 vfnum 0
pci/0000:05:00.0/2: type eth netdev eth2 flavour pcivf pfnum 0 vfnum 1

Acked-by: Jiri Pirko <jiri@mellanox.com>
Signed-off-by: Parav Pandit <parav@mellanox.com>
---
 include/net/devlink.h        | 11 +++++++++++
 include/uapi/linux/devlink.h |  6 ++++++
 net/core/devlink.c           | 36 ++++++++++++++++++++++++++++++++++++
 3 files changed, 53 insertions(+)

diff --git a/include/net/devlink.h b/include/net/devlink.h
index 8db9c0e83fb5..dff7c7797f3e 100644
--- a/include/net/devlink.h
+++ b/include/net/devlink.h
@@ -42,6 +42,11 @@ struct devlink_port_pci_pf_attrs {
 	u16 pf;	/* Associated PCI PF for this port. */
 };
 
+struct devlink_port_pci_vf_attrs {
+	u16 pf;	/* Associated PCI PF for this port. */
+	u16 vf;	/* Associated PCI VF for of the PCI PF for this port. */
+};
+
 struct devlink_port_attrs {
 	u8 set:1,
 	   split:1,
@@ -52,6 +57,7 @@ struct devlink_port_attrs {
 	struct netdev_phys_item_id switch_id;
 	union {
 		struct devlink_port_pci_pf_attrs pci_pf;
+		struct devlink_port_pci_vf_attrs pci_vf;
 	};
 };
 
@@ -601,6 +607,11 @@ void devlink_port_attrs_pci_pf_set(struct devlink_port *devlink_port,
 				   u32 port_number,
 				   const unsigned char *switch_id,
 				   unsigned char switch_id_len, u16 pf);
+void devlink_port_attrs_pci_vf_set(struct devlink_port *devlink_port,
+				   u32 port_number,
+				   const unsigned char *switch_id,
+				   unsigned char switch_id_len,
+				   u16 pf, u16 vf);
 int devlink_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/include/uapi/linux/devlink.h b/include/uapi/linux/devlink.h
index f7323884c3fe..ffc993256527 100644
--- a/include/uapi/linux/devlink.h
+++ b/include/uapi/linux/devlink.h
@@ -173,6 +173,10 @@ enum devlink_port_flavour {
 				      * the PCI PF. It is an internal
 				      * port that faces the PCI PF.
 				      */
+	DEVLINK_PORT_FLAVOUR_PCI_VF, /* Represents eswitch port
+				      * for the PCI VF. It is an internal
+				      * port that faces the PCI VF.
+				      */
 };
 
 enum devlink_param_cmode {
@@ -342,6 +346,8 @@ enum devlink_attr {
 	DEVLINK_ATTR_FLASH_UPDATE_STATUS_TOTAL,	/* u64 */
 
 	DEVLINK_ATTR_PORT_PCI_PF_NUMBER,	/* u16 */
+	DEVLINK_ATTR_PORT_PCI_VF_NUMBER,	/* u16 */
+
 	/* add new attributes above here, update the policy in devlink.c */
 
 	__DEVLINK_ATTR_MAX,
diff --git a/net/core/devlink.c b/net/core/devlink.c
index 001f9e2c96f0..d62c4591351b 100644
--- a/net/core/devlink.c
+++ b/net/core/devlink.c
@@ -521,6 +521,12 @@ static int devlink_nl_port_attrs_put(struct sk_buff *msg,
 		if (nla_put_u16(msg, DEVLINK_ATTR_PORT_PCI_PF_NUMBER,
 				attrs->pci_pf.pf))
 			return -EMSGSIZE;
+	} else if (devlink_port->attrs.flavour == DEVLINK_PORT_FLAVOUR_PCI_VF) {
+		if (nla_put_u16(msg, DEVLINK_ATTR_PORT_PCI_PF_NUMBER,
+				attrs->pci_vf.pf) ||
+		    nla_put_u16(msg, DEVLINK_ATTR_PORT_PCI_VF_NUMBER,
+				attrs->pci_vf.vf))
+			return -EMSGSIZE;
 	}
 	if (!attrs->split)
 		return 0;
@@ -5820,6 +5826,32 @@ void devlink_port_attrs_pci_pf_set(struct devlink_port *devlink_port,
 }
 EXPORT_SYMBOL_GPL(devlink_port_attrs_pci_pf_set);
 
+/**
+ *	devlink_port_attrs_pci_vf_set - Set PCI VF port attributes
+ *
+ *	@devlink_port: devlink port
+ *	@port_number: number of the port that is facing a VF
+ *	@pf: associated PF for the devlink port instance
+ *	@vf: associated VF of a PF for the devlink port instance
+ *	@switch_id: if the port is part of switch, this is buffer with ID,
+ *	            otwerwise this is NULL
+ *	@switch_id_len: length of the switch_id buffer
+ */
+void devlink_port_attrs_pci_vf_set(struct devlink_port *devlink_port,
+				   u32 port_number,
+				   const unsigned char *switch_id,
+				   unsigned char switch_id_len,
+				   u16 pf, u16 vf)
+{
+	struct devlink_port_attrs *attrs = &devlink_port->attrs;
+
+	__devlink_port_attrs_set(devlink_port, DEVLINK_PORT_FLAVOUR_PCI_VF,
+				 port_number, switch_id, switch_id_len);
+	attrs->pci_vf.pf = pf;
+	attrs->pci_vf.vf = vf;
+}
+EXPORT_SYMBOL_GPL(devlink_port_attrs_pci_vf_set);
+
 static int __devlink_port_phys_port_name_get(struct devlink_port *devlink_port,
 					     char *name, size_t len)
 {
@@ -5847,6 +5879,10 @@ static int __devlink_port_phys_port_name_get(struct devlink_port *devlink_port,
 	case DEVLINK_PORT_FLAVOUR_PCI_PF:
 		n = snprintf(name, len, "pf%u", attrs->pci_pf.pf);
 		break;
+	case DEVLINK_PORT_FLAVOUR_PCI_VF:
+		n = snprintf(name, len, "pf%uvf%u",
+			     attrs->pci_vf.pf, attrs->pci_vf.vf);
+		break;
 	}
 
 	if (n >= len)
-- 
2.19.2


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

* [PATCH net-next 3/3] net/mlx5e: Register devlink ports for physical link, PCI PF, VFs
  2019-07-01 12:27 [PATCH net-next 0/3] devlink: Introduce PCI PF, VF ports and attributes Parav Pandit
  2019-07-01 12:27 ` [PATCH net-next 1/3] devlink: Introduce PCI PF port flavour and port attribute Parav Pandit
  2019-07-01 12:27 ` [PATCH net-next 2/3] devlink: Introduce PCI VF " Parav Pandit
@ 2019-07-01 12:27 ` Parav Pandit
  2019-07-01 18:27 ` [PATCH] devlink: Introduce PCI PF and VF port flavour and attribute Parav Pandit
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 71+ messages in thread
From: Parav Pandit @ 2019-07-01 12:27 UTC (permalink / raw)
  To: netdev; +Cc: jiri, saeedm, jakub.kicinski, Parav Pandit

Register devlink port of physical port, PCI PF and PCI VF flavour
for each PF, VF when a given devlink instance is in switchdev mode.

Implement ndo_get_devlink_port callback API to make use of registered
devlink ports.
This eliminates ndo_get_phys_port_name() and ndo_get_port_parent_id()
callbacks. Hence, remove them.

An example output with 2 VFs, without a PF and single uplink port is
below.

$ devlink port show
pci/0000:06:00.0/65535: type eth netdev ens2f0 flavour physical
pci/0000:05:00.0/1: type eth netdev eth1 flavour pcivf pfnum 0 vfnum 0
pci/0000:05:00.0/2: type eth netdev eth2 flavour pcivf pfnum 0 vfnum 1

Reviewed-by: Roi Dayan <roid@mellanox.com>
Acked-by: Jiri Pirko <jiri@mellanox.com>
Signed-off-by: Parav Pandit <parav@mellanox.com>
---
 .../net/ethernet/mellanox/mlx5/core/en_rep.c  | 108 +++++++++++++-----
 .../net/ethernet/mellanox/mlx5/core/en_rep.h  |   1 +
 2 files changed, 78 insertions(+), 31 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_rep.c b/drivers/net/ethernet/mellanox/mlx5/core/en_rep.c
index 330034fcdfc5..aa47be3c139f 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_rep.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_rep.c
@@ -37,6 +37,7 @@
 #include <net/act_api.h>
 #include <net/netevent.h>
 #include <net/arp.h>
+#include <net/devlink.h>
 
 #include "eswitch.h"
 #include "en.h"
@@ -1119,32 +1120,6 @@ static int mlx5e_rep_close(struct net_device *dev)
 	return ret;
 }
 
-static int mlx5e_rep_get_phys_port_name(struct net_device *dev,
-					char *buf, size_t len)
-{
-	struct mlx5e_priv *priv = netdev_priv(dev);
-	struct mlx5e_rep_priv *rpriv = priv->ppriv;
-	struct mlx5_eswitch_rep *rep = rpriv->rep;
-	unsigned int fn;
-	int ret;
-
-	fn = PCI_FUNC(priv->mdev->pdev->devfn);
-	if (fn >= MLX5_MAX_PORTS)
-		return -EOPNOTSUPP;
-
-	if (rep->vport == MLX5_VPORT_UPLINK)
-		ret = snprintf(buf, len, "p%d", fn);
-	else if (rep->vport == MLX5_VPORT_PF)
-		ret = snprintf(buf, len, "pf%d", fn);
-	else
-		ret = snprintf(buf, len, "pf%dvf%d", fn, rep->vport - 1);
-
-	if (ret >= len)
-		return -EOPNOTSUPP;
-
-	return 0;
-}
-
 static int
 mlx5e_rep_setup_tc_cls_flower(struct mlx5e_priv *priv,
 			      struct tc_cls_flower_offload *cls_flower, int flags)
@@ -1298,17 +1273,24 @@ static int mlx5e_uplink_rep_set_vf_vlan(struct net_device *dev, int vf, u16 vlan
 	return 0;
 }
 
+static struct devlink_port *mlx5e_get_devlink_port(struct net_device *dev)
+{
+	struct mlx5e_priv *priv = netdev_priv(dev);
+	struct mlx5e_rep_priv *rpriv = priv->ppriv;
+
+	return &rpriv->dl_port;
+}
+
 static const struct net_device_ops mlx5e_netdev_ops_rep = {
 	.ndo_open                = mlx5e_rep_open,
 	.ndo_stop                = mlx5e_rep_close,
 	.ndo_start_xmit          = mlx5e_xmit,
-	.ndo_get_phys_port_name  = mlx5e_rep_get_phys_port_name,
 	.ndo_setup_tc            = mlx5e_rep_setup_tc,
+	.ndo_get_devlink_port = mlx5e_get_devlink_port,
 	.ndo_get_stats64         = mlx5e_rep_get_stats,
 	.ndo_has_offload_stats	 = mlx5e_rep_has_offload_stats,
 	.ndo_get_offload_stats	 = mlx5e_rep_get_offload_stats,
 	.ndo_change_mtu          = mlx5e_rep_change_mtu,
-	.ndo_get_port_parent_id	 = mlx5e_rep_get_port_parent_id,
 };
 
 static const struct net_device_ops mlx5e_netdev_ops_uplink_rep = {
@@ -1316,8 +1298,8 @@ static const struct net_device_ops mlx5e_netdev_ops_uplink_rep = {
 	.ndo_stop                = mlx5e_close,
 	.ndo_start_xmit          = mlx5e_xmit,
 	.ndo_set_mac_address     = mlx5e_uplink_rep_set_mac,
-	.ndo_get_phys_port_name  = mlx5e_rep_get_phys_port_name,
 	.ndo_setup_tc            = mlx5e_rep_setup_tc,
+	.ndo_get_devlink_port = mlx5e_get_devlink_port,
 	.ndo_get_stats64         = mlx5e_get_stats,
 	.ndo_has_offload_stats	 = mlx5e_rep_has_offload_stats,
 	.ndo_get_offload_stats	 = mlx5e_rep_get_offload_stats,
@@ -1330,7 +1312,6 @@ static const struct net_device_ops mlx5e_netdev_ops_uplink_rep = {
 	.ndo_get_vf_config       = mlx5e_get_vf_config,
 	.ndo_get_vf_stats        = mlx5e_get_vf_stats,
 	.ndo_set_vf_vlan         = mlx5e_uplink_rep_set_vf_vlan,
-	.ndo_get_port_parent_id	 = mlx5e_rep_get_port_parent_id,
 	.ndo_set_features        = mlx5e_set_features,
 };
 
@@ -1731,6 +1712,55 @@ static const struct mlx5e_profile mlx5e_uplink_rep_profile = {
 	.max_tc			= MLX5E_MAX_NUM_TC,
 };
 
+static bool
+is_devlink_port_supported(const struct mlx5_core_dev *dev,
+			  const struct mlx5e_rep_priv *rpriv)
+{
+	return rpriv->rep->vport == MLX5_VPORT_UPLINK ||
+	       rpriv->rep->vport == MLX5_VPORT_PF ||
+	       mlx5_eswitch_is_vf_vport(dev->priv.eswitch, rpriv->rep->vport);
+}
+
+static int register_devlink_port(struct mlx5_core_dev *dev,
+				 struct mlx5e_rep_priv *rpriv)
+{
+	struct devlink *devlink = priv_to_devlink(dev);
+	struct mlx5_eswitch_rep *rep = rpriv->rep;
+	struct netdev_phys_item_id ppid = {};
+	int ret;
+
+	if (!is_devlink_port_supported(dev, rpriv))
+		return 0;
+
+	ret = mlx5e_rep_get_port_parent_id(rpriv->netdev, &ppid);
+	if (ret)
+		return ret;
+
+	if (rep->vport == MLX5_VPORT_UPLINK)
+		devlink_port_attrs_set(&rpriv->dl_port,
+				       DEVLINK_PORT_FLAVOUR_PHYSICAL,
+				       PCI_FUNC(dev->pdev->devfn), false, 0,
+				       &ppid.id[0], ppid.id_len);
+	else if (rep->vport == MLX5_VPORT_PF)
+		devlink_port_attrs_pci_pf_set(&rpriv->dl_port, rep->vport,
+					      &ppid.id[0], ppid.id_len,
+					      dev->pdev->devfn);
+	else if (mlx5_eswitch_is_vf_vport(dev->priv.eswitch, rpriv->rep->vport))
+		devlink_port_attrs_pci_vf_set(&rpriv->dl_port, rep->vport,
+					      &ppid.id[0], ppid.id_len,
+					      dev->pdev->devfn,
+					      rep->vport - 1);
+
+	return devlink_port_register(devlink, &rpriv->dl_port, rep->vport);
+}
+
+static void unregister_devlink_port(struct mlx5_core_dev *dev,
+				    struct mlx5e_rep_priv *rpriv)
+{
+	if (is_devlink_port_supported(dev, rpriv))
+		devlink_port_unregister(&rpriv->dl_port);
+}
+
 /* e-Switch vport representors */
 static int
 mlx5e_vport_rep_load(struct mlx5_core_dev *dev, struct mlx5_eswitch_rep *rep)
@@ -1782,15 +1812,27 @@ mlx5e_vport_rep_load(struct mlx5_core_dev *dev, struct mlx5_eswitch_rep *rep)
 		goto err_detach_netdev;
 	}
 
+	err = register_devlink_port(dev, rpriv);
+	if (err) {
+		esw_warn(dev, "Failed to register devlink port %d\n",
+			 rep->vport);
+		goto err_neigh_cleanup;
+	}
+
 	err = register_netdev(netdev);
 	if (err) {
 		pr_warn("Failed to register representor netdev for vport %d\n",
 			rep->vport);
-		goto err_neigh_cleanup;
+		goto err_devlink_cleanup;
 	}
 
+	if (is_devlink_port_supported(dev, rpriv))
+		devlink_port_type_eth_set(&rpriv->dl_port, netdev);
 	return 0;
 
+err_devlink_cleanup:
+	unregister_devlink_port(dev, rpriv);
+
 err_neigh_cleanup:
 	mlx5e_rep_neigh_cleanup(rpriv);
 
@@ -1813,9 +1855,13 @@ mlx5e_vport_rep_unload(struct mlx5_eswitch_rep *rep)
 	struct mlx5e_rep_priv *rpriv = mlx5e_rep_to_rep_priv(rep);
 	struct net_device *netdev = rpriv->netdev;
 	struct mlx5e_priv *priv = netdev_priv(netdev);
+	struct mlx5_core_dev *dev = priv->mdev;
 	void *ppriv = priv->ppriv;
 
+	if (is_devlink_port_supported(dev, rpriv))
+		devlink_port_type_clear(&rpriv->dl_port);
 	unregister_netdev(netdev);
+	unregister_devlink_port(dev, rpriv);
 	mlx5e_rep_neigh_cleanup(rpriv);
 	mlx5e_detach_netdev(priv);
 	if (rep->vport == MLX5_VPORT_UPLINK)
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_rep.h b/drivers/net/ethernet/mellanox/mlx5/core/en_rep.h
index d4585f3b8cb2..c56e6ee4350c 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_rep.h
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_rep.h
@@ -86,6 +86,7 @@ struct mlx5e_rep_priv {
 	struct mlx5_flow_handle *vport_rx_rule;
 	struct list_head       vport_sqs_list;
 	struct mlx5_rep_uplink_priv uplink_priv; /* valid for uplink rep */
+	struct devlink_port dl_port;
 };
 
 static inline
-- 
2.19.2


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

* [PATCH] devlink: Introduce PCI PF and VF port flavour and attribute
  2019-07-01 12:27 [PATCH net-next 0/3] devlink: Introduce PCI PF, VF ports and attributes Parav Pandit
                   ` (2 preceding siblings ...)
  2019-07-01 12:27 ` [PATCH net-next 3/3] net/mlx5e: Register devlink ports for physical link, PCI PF, VFs Parav Pandit
@ 2019-07-01 18:27 ` Parav Pandit
  2019-07-01 18:30 ` [RESEND PATCH iproute2 net-next] " Parav Pandit
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 71+ messages in thread
From: Parav Pandit @ 2019-07-01 18:27 UTC (permalink / raw)
  To: netdev; +Cc: saeedm, jakub.kicinski, jiri, Parav Pandit

Introduce PCI PF and VF port flavour and port attributes such as PF
number and VF number.

$ devlink port show
pci/0000:05:00.0/0: type eth netdev eth0 flavour pcipf pfnum 0
pci/0000:05:00.0/1: type eth netdev eth1 flavour pcivf pfnum 0 vfnum 0
pci/0000:05:00.0/2: type eth netdev eth2 flavour pcivf pfnum 0 vfnum 1

Acked-by: Jiri Pirko <jiri@mellanox.com>
Signed-off-by: Parav Pandit <parav@mellanox.com>
---
 devlink/devlink.c            | 23 +++++++++++++++++++++++
 include/uapi/linux/devlink.h | 11 +++++++++++
 2 files changed, 34 insertions(+)

diff --git a/devlink/devlink.c b/devlink/devlink.c
index 559f624e..15493426 100644
--- a/devlink/devlink.c
+++ b/devlink/devlink.c
@@ -2771,6 +2771,10 @@ static const char *port_flavour_name(uint16_t flavour)
 		return "cpu";
 	case DEVLINK_PORT_FLAVOUR_DSA:
 		return "dsa";
+	case DEVLINK_PORT_FLAVOUR_PCI_PF:
+		return "pcipf";
+	case DEVLINK_PORT_FLAVOUR_PCI_VF:
+		return "pcivf";
 	default:
 		return "<unknown flavour>";
 	}
@@ -2803,8 +2807,27 @@ static void pr_out_port(struct dl *dl, struct nlattr **tb)
 	if (tb[DEVLINK_ATTR_PORT_FLAVOUR]) {
 		uint16_t port_flavour =
 				mnl_attr_get_u16(tb[DEVLINK_ATTR_PORT_FLAVOUR]);
+		uint16_t pf_vf;
 
 		pr_out_str(dl, "flavour", port_flavour_name(port_flavour));
+		if (port_flavour == DEVLINK_PORT_FLAVOUR_PCI_PF) {
+			if (tb[DEVLINK_ATTR_PORT_PCI_PF_NUMBER]) {
+				pf_vf = mnl_attr_get_u16(
+					tb[DEVLINK_ATTR_PORT_PCI_PF_NUMBER]);
+				pr_out_uint(dl, "pfnum", pf_vf);
+			}
+		} else if (port_flavour == DEVLINK_PORT_FLAVOUR_PCI_VF) {
+			if (tb[DEVLINK_ATTR_PORT_PCI_PF_NUMBER]) {
+				pf_vf = mnl_attr_get_u16(
+					tb[DEVLINK_ATTR_PORT_PCI_PF_NUMBER]);
+				pr_out_uint(dl, "pfnum", pf_vf);
+			}
+			if (tb[DEVLINK_ATTR_PORT_PCI_VF_NUMBER]) {
+				pf_vf = mnl_attr_get_u16(
+					tb[DEVLINK_ATTR_PORT_PCI_VF_NUMBER]);
+				pr_out_uint(dl, "vfnum", pf_vf);
+			}
+		}
 	}
 	if (tb[DEVLINK_ATTR_PORT_SPLIT_GROUP])
 		pr_out_uint(dl, "split_group",
diff --git a/include/uapi/linux/devlink.h b/include/uapi/linux/devlink.h
index 6544824a..fc195cbd 100644
--- a/include/uapi/linux/devlink.h
+++ b/include/uapi/linux/devlink.h
@@ -169,6 +169,14 @@ enum devlink_port_flavour {
 	DEVLINK_PORT_FLAVOUR_DSA, /* Distributed switch architecture
 				   * interconnect port.
 				   */
+	DEVLINK_PORT_FLAVOUR_PCI_PF, /* Represents eswitch port for
+				      * the PCI PF. It is an internal
+				      * port that faces the PCI PF.
+				      */
+	DEVLINK_PORT_FLAVOUR_PCI_VF, /* Represents eswitch port
+				      * for the PCI VF. It is an internal
+				      * port that faces the PCI VF.
+				      */
 };
 
 enum devlink_param_cmode {
@@ -337,6 +345,9 @@ enum devlink_attr {
 	DEVLINK_ATTR_FLASH_UPDATE_STATUS_DONE,	/* u64 */
 	DEVLINK_ATTR_FLASH_UPDATE_STATUS_TOTAL,	/* u64 */
 
+	DEVLINK_ATTR_PORT_PCI_PF_NUMBER,	/* u16 */
+	DEVLINK_ATTR_PORT_PCI_VF_NUMBER,	/* u16 */
+
 	/* add new attributes above here, update the policy in devlink.c */
 
 	__DEVLINK_ATTR_MAX,
-- 
2.19.2


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

* [RESEND PATCH iproute2 net-next] devlink: Introduce PCI PF and VF port flavour and attribute
  2019-07-01 12:27 [PATCH net-next 0/3] devlink: Introduce PCI PF, VF ports and attributes Parav Pandit
                   ` (3 preceding siblings ...)
  2019-07-01 18:27 ` [PATCH] devlink: Introduce PCI PF and VF port flavour and attribute Parav Pandit
@ 2019-07-01 18:30 ` Parav Pandit
  2019-07-09 19:49   ` Parav Pandit
  2019-07-10 12:39   ` [PATCH net-next iproute2 v2 1/2] devlink: Update kernel header to commit Parav Pandit
  2019-07-05  7:37 ` [PATCH net-next v2 0/3] devlink: Introduce PCI PF, VF ports and attributes Parav Pandit
                   ` (4 subsequent siblings)
  9 siblings, 2 replies; 71+ messages in thread
From: Parav Pandit @ 2019-07-01 18:30 UTC (permalink / raw)
  To: netdev; +Cc: saeedm, jakub.kicinski, jiri, Parav Pandit

Introduce PCI PF and VF port flavour and port attributes such as PF
number and VF number.

$ devlink port show
pci/0000:05:00.0/0: type eth netdev eth0 flavour pcipf pfnum 0
pci/0000:05:00.0/1: type eth netdev eth1 flavour pcivf pfnum 0 vfnum 0
pci/0000:05:00.0/2: type eth netdev eth2 flavour pcivf pfnum 0 vfnum 1

Acked-by: Jiri Pirko <jiri@mellanox.com>
Signed-off-by: Parav Pandit <parav@mellanox.com>
---
 devlink/devlink.c            | 23 +++++++++++++++++++++++
 include/uapi/linux/devlink.h | 11 +++++++++++
 2 files changed, 34 insertions(+)

diff --git a/devlink/devlink.c b/devlink/devlink.c
index 559f624e..15493426 100644
--- a/devlink/devlink.c
+++ b/devlink/devlink.c
@@ -2771,6 +2771,10 @@ static const char *port_flavour_name(uint16_t flavour)
 		return "cpu";
 	case DEVLINK_PORT_FLAVOUR_DSA:
 		return "dsa";
+	case DEVLINK_PORT_FLAVOUR_PCI_PF:
+		return "pcipf";
+	case DEVLINK_PORT_FLAVOUR_PCI_VF:
+		return "pcivf";
 	default:
 		return "<unknown flavour>";
 	}
@@ -2803,8 +2807,27 @@ static void pr_out_port(struct dl *dl, struct nlattr **tb)
 	if (tb[DEVLINK_ATTR_PORT_FLAVOUR]) {
 		uint16_t port_flavour =
 				mnl_attr_get_u16(tb[DEVLINK_ATTR_PORT_FLAVOUR]);
+		uint16_t pf_vf;
 
 		pr_out_str(dl, "flavour", port_flavour_name(port_flavour));
+		if (port_flavour == DEVLINK_PORT_FLAVOUR_PCI_PF) {
+			if (tb[DEVLINK_ATTR_PORT_PCI_PF_NUMBER]) {
+				pf_vf = mnl_attr_get_u16(
+					tb[DEVLINK_ATTR_PORT_PCI_PF_NUMBER]);
+				pr_out_uint(dl, "pfnum", pf_vf);
+			}
+		} else if (port_flavour == DEVLINK_PORT_FLAVOUR_PCI_VF) {
+			if (tb[DEVLINK_ATTR_PORT_PCI_PF_NUMBER]) {
+				pf_vf = mnl_attr_get_u16(
+					tb[DEVLINK_ATTR_PORT_PCI_PF_NUMBER]);
+				pr_out_uint(dl, "pfnum", pf_vf);
+			}
+			if (tb[DEVLINK_ATTR_PORT_PCI_VF_NUMBER]) {
+				pf_vf = mnl_attr_get_u16(
+					tb[DEVLINK_ATTR_PORT_PCI_VF_NUMBER]);
+				pr_out_uint(dl, "vfnum", pf_vf);
+			}
+		}
 	}
 	if (tb[DEVLINK_ATTR_PORT_SPLIT_GROUP])
 		pr_out_uint(dl, "split_group",
diff --git a/include/uapi/linux/devlink.h b/include/uapi/linux/devlink.h
index 6544824a..fc195cbd 100644
--- a/include/uapi/linux/devlink.h
+++ b/include/uapi/linux/devlink.h
@@ -169,6 +169,14 @@ enum devlink_port_flavour {
 	DEVLINK_PORT_FLAVOUR_DSA, /* Distributed switch architecture
 				   * interconnect port.
 				   */
+	DEVLINK_PORT_FLAVOUR_PCI_PF, /* Represents eswitch port for
+				      * the PCI PF. It is an internal
+				      * port that faces the PCI PF.
+				      */
+	DEVLINK_PORT_FLAVOUR_PCI_VF, /* Represents eswitch port
+				      * for the PCI VF. It is an internal
+				      * port that faces the PCI VF.
+				      */
 };
 
 enum devlink_param_cmode {
@@ -337,6 +345,9 @@ enum devlink_attr {
 	DEVLINK_ATTR_FLASH_UPDATE_STATUS_DONE,	/* u64 */
 	DEVLINK_ATTR_FLASH_UPDATE_STATUS_TOTAL,	/* u64 */
 
+	DEVLINK_ATTR_PORT_PCI_PF_NUMBER,	/* u16 */
+	DEVLINK_ATTR_PORT_PCI_VF_NUMBER,	/* u16 */
+
 	/* add new attributes above here, update the policy in devlink.c */
 
 	__DEVLINK_ATTR_MAX,
-- 
2.19.2


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

* Re: [PATCH net-next 1/3] devlink: Introduce PCI PF port flavour and port attribute
  2019-07-01 12:27 ` [PATCH net-next 1/3] devlink: Introduce PCI PF port flavour and port attribute Parav Pandit
@ 2019-07-01 23:26   ` Jakub Kicinski
  2019-07-02  4:26     ` Parav Pandit
  0 siblings, 1 reply; 71+ messages in thread
From: Jakub Kicinski @ 2019-07-01 23:26 UTC (permalink / raw)
  To: jiri; +Cc: Parav Pandit, netdev, saeedm

On Mon,  1 Jul 2019 07:27:32 -0500, Parav Pandit wrote:
> In an eswitch, PCI PF may have port which is normally represented
> using a representor netdevice.
> To have better visibility of eswitch port, its association with
> PF, a representor netdevice and port number, introduce a PCI PF port
> flavour and port attriute.
> 
> When devlink port flavour is PCI PF, fill up PCI PF attributes of the
> port.
> 
> Extend port name creation using PCI PF number on best effort basis.
> So that vendor drivers can skip defining their own scheme.
> 
> $ devlink port show
> pci/0000:05:00.0/0: type eth netdev eth0 flavour pcipf pfnum 0
> 
> Acked-by: Jiri Pirko <jiri@mellanox.com>
> Signed-off-by: Parav Pandit <parav@mellanox.com>
> ---
>  include/net/devlink.h        | 11 ++++++
>  include/uapi/linux/devlink.h |  5 +++
>  net/core/devlink.c           | 71 +++++++++++++++++++++++++++++-------
>  3 files changed, 73 insertions(+), 14 deletions(-)
> 
> diff --git a/include/net/devlink.h b/include/net/devlink.h
> index 6625ea068d5e..8db9c0e83fb5 100644
> --- a/include/net/devlink.h
> +++ b/include/net/devlink.h
> @@ -38,6 +38,10 @@ struct devlink {
>  	char priv[0] __aligned(NETDEV_ALIGN);
>  };
>  
> +struct devlink_port_pci_pf_attrs {

Why the named structure?  Anonymous one should be just fine?

> +	u16 pf;	/* Associated PCI PF for this port. */
> +};
> +
>  struct devlink_port_attrs {
>  	u8 set:1,
>  	   split:1,
> @@ -46,6 +50,9 @@ struct devlink_port_attrs {
>  	u32 port_number; /* same value as "split group" */
>  	u32 split_subport_number;
>  	struct netdev_phys_item_id switch_id;
> +	union {
> +		struct devlink_port_pci_pf_attrs pci_pf;
> +	};
>  };
>  
>  struct devlink_port {
> @@ -590,6 +597,10 @@ void devlink_port_attrs_set(struct devlink_port *devlink_port,
>  			    u32 split_subport_number,
>  			    const unsigned char *switch_id,
>  			    unsigned char switch_id_len);
> +void devlink_port_attrs_pci_pf_set(struct devlink_port *devlink_port,
> +				   u32 port_number,
> +				   const unsigned char *switch_id,
> +				   unsigned char switch_id_len, u16 pf);
>  int devlink_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/include/uapi/linux/devlink.h b/include/uapi/linux/devlink.h
> index 5287b42c181f..f7323884c3fe 100644
> --- a/include/uapi/linux/devlink.h
> +++ b/include/uapi/linux/devlink.h
> @@ -169,6 +169,10 @@ enum devlink_port_flavour {
>  	DEVLINK_PORT_FLAVOUR_DSA, /* Distributed switch architecture
>  				   * interconnect port.
>  				   */
> +	DEVLINK_PORT_FLAVOUR_PCI_PF, /* Represents eswitch port for
> +				      * the PCI PF. It is an internal
> +				      * port that faces the PCI PF.
> +				      */
>  };
>  
>  enum devlink_param_cmode {
> @@ -337,6 +341,7 @@ enum devlink_attr {
>  	DEVLINK_ATTR_FLASH_UPDATE_STATUS_DONE,	/* u64 */
>  	DEVLINK_ATTR_FLASH_UPDATE_STATUS_TOTAL,	/* u64 */
>  
> +	DEVLINK_ATTR_PORT_PCI_PF_NUMBER,	/* u16 */
>  	/* add new attributes above here, update the policy in devlink.c */
>  
>  	__DEVLINK_ATTR_MAX,
> diff --git a/net/core/devlink.c b/net/core/devlink.c
> index 89c533778135..001f9e2c96f0 100644
> --- a/net/core/devlink.c
> +++ b/net/core/devlink.c
> @@ -517,6 +517,11 @@ static int devlink_nl_port_attrs_put(struct sk_buff *msg,
>  		return -EMSGSIZE;
>  	if (nla_put_u32(msg, DEVLINK_ATTR_PORT_NUMBER, attrs->port_number))
>  		return -EMSGSIZE;

Why would we report network port information for PF and VF port
flavours?

> +	if (devlink_port->attrs.flavour == DEVLINK_PORT_FLAVOUR_PCI_PF) {
> +		if (nla_put_u16(msg, DEVLINK_ATTR_PORT_PCI_PF_NUMBER,
> +				attrs->pci_pf.pf))
> +			return -EMSGSIZE;
> +	}
>  	if (!attrs->split)
>  		return 0;
>  	if (nla_put_u32(msg, DEVLINK_ATTR_PORT_SPLIT_GROUP, attrs->port_number))

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

* RE: [PATCH net-next 1/3] devlink: Introduce PCI PF port flavour and port attribute
  2019-07-01 23:26   ` Jakub Kicinski
@ 2019-07-02  4:26     ` Parav Pandit
  2019-07-02 17:47       ` Jakub Kicinski
  0 siblings, 1 reply; 71+ messages in thread
From: Parav Pandit @ 2019-07-02  4:26 UTC (permalink / raw)
  To: Jakub Kicinski, Jiri Pirko; +Cc: netdev, Saeed Mahameed

Hi Jakub,

> -----Original Message-----
> From: Jakub Kicinski <jakub.kicinski@netronome.com>
> Sent: Tuesday, July 2, 2019 4:57 AM
> To: Jiri Pirko <jiri@mellanox.com>
> Cc: Parav Pandit <parav@mellanox.com>; netdev@vger.kernel.org; Saeed
> Mahameed <saeedm@mellanox.com>
> Subject: Re: [PATCH net-next 1/3] devlink: Introduce PCI PF port flavour and
> port attribute
> 
> On Mon,  1 Jul 2019 07:27:32 -0500, Parav Pandit wrote:
> > In an eswitch, PCI PF may have port which is normally represented
> > using a representor netdevice.
> > To have better visibility of eswitch port, its association with PF, a
> > representor netdevice and port number, introduce a PCI PF port flavour
> > and port attriute.
> >
> > When devlink port flavour is PCI PF, fill up PCI PF attributes of the
> > port.
> >
> > Extend port name creation using PCI PF number on best effort basis.
> > So that vendor drivers can skip defining their own scheme.
> >
> > $ devlink port show
> > pci/0000:05:00.0/0: type eth netdev eth0 flavour pcipf pfnum 0
> >
> > Acked-by: Jiri Pirko <jiri@mellanox.com>
> > Signed-off-by: Parav Pandit <parav@mellanox.com>
> > ---
> >  include/net/devlink.h        | 11 ++++++
> >  include/uapi/linux/devlink.h |  5 +++
> >  net/core/devlink.c           | 71 +++++++++++++++++++++++++++++-------
> >  3 files changed, 73 insertions(+), 14 deletions(-)
> >
> > diff --git a/include/net/devlink.h b/include/net/devlink.h index
> > 6625ea068d5e..8db9c0e83fb5 100644
> > --- a/include/net/devlink.h
> > +++ b/include/net/devlink.h
> > @@ -38,6 +38,10 @@ struct devlink {
> >  	char priv[0] __aligned(NETDEV_ALIGN);  };
> >
> > +struct devlink_port_pci_pf_attrs {
> 
> Why the named structure?  Anonymous one should be just fine?
>
No specific reason for this patch. But named structure allows to extend it more easily with code readability.
Such as subsequently we want to add the peer_mac etc port attributes.
Named structure to store those attributes are helpful.
 
> > +	u16 pf;	/* Associated PCI PF for this port. */
> > +};
> > +
> >  struct devlink_port_attrs {
> >  	u8 set:1,
> >  	   split:1,
> > @@ -46,6 +50,9 @@ struct devlink_port_attrs {
> >  	u32 port_number; /* same value as "split group" */
> >  	u32 split_subport_number;
> >  	struct netdev_phys_item_id switch_id;
> > +	union {
> > +		struct devlink_port_pci_pf_attrs pci_pf;
> > +	};
> >  };
> >
> >  struct devlink_port {
> > @@ -590,6 +597,10 @@ void devlink_port_attrs_set(struct devlink_port
> *devlink_port,
> >  			    u32 split_subport_number,
> >  			    const unsigned char *switch_id,
> >  			    unsigned char switch_id_len);
> > +void devlink_port_attrs_pci_pf_set(struct devlink_port *devlink_port,
> > +				   u32 port_number,
> > +				   const unsigned char *switch_id,
> > +				   unsigned char switch_id_len, u16 pf);
> >  int devlink_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/include/uapi/linux/devlink.h b/include/uapi/linux/devlink.h index
> > 5287b42c181f..f7323884c3fe 100644
> > --- a/include/uapi/linux/devlink.h
> > +++ b/include/uapi/linux/devlink.h
> > @@ -169,6 +169,10 @@ enum devlink_port_flavour {
> >  	DEVLINK_PORT_FLAVOUR_DSA, /* Distributed switch architecture
> >  				   * interconnect port.
> >  				   */
> > +	DEVLINK_PORT_FLAVOUR_PCI_PF, /* Represents eswitch port for
> > +				      * the PCI PF. It is an internal
> > +				      * port that faces the PCI PF.
> > +				      */
> >  };
> >
> >  enum devlink_param_cmode {
> > @@ -337,6 +341,7 @@ enum devlink_attr {
> >  	DEVLINK_ATTR_FLASH_UPDATE_STATUS_DONE,	/* u64 */
> >  	DEVLINK_ATTR_FLASH_UPDATE_STATUS_TOTAL,	/* u64 */
> >
> > +	DEVLINK_ATTR_PORT_PCI_PF_NUMBER,	/* u16 */
> >  	/* add new attributes above here, update the policy in devlink.c */
> >
> >  	__DEVLINK_ATTR_MAX,
> > diff --git a/net/core/devlink.c b/net/core/devlink.c index
> > 89c533778135..001f9e2c96f0 100644
> > --- a/net/core/devlink.c
> > +++ b/net/core/devlink.c
> > @@ -517,6 +517,11 @@ static int devlink_nl_port_attrs_put(struct sk_buff
> *msg,
> >  		return -EMSGSIZE;
> >  	if (nla_put_u32(msg, DEVLINK_ATTR_PORT_NUMBER, attrs-
> >port_number))
> >  		return -EMSGSIZE;
> 
> Why would we report network port information for PF and VF port flavours?
I didn't see any immediate need to report, at the same time didn't find any reason to treat such port flavours differently than existing one.
It just gives a clear view of the device's eswitch.
Might find it useful during debugging while inspecting device internal tables..

> 
> > +	if (devlink_port->attrs.flavour == DEVLINK_PORT_FLAVOUR_PCI_PF) {
> > +		if (nla_put_u16(msg, DEVLINK_ATTR_PORT_PCI_PF_NUMBER,
> > +				attrs->pci_pf.pf))
> > +			return -EMSGSIZE;
> > +	}
> >  	if (!attrs->split)
> >  		return 0;
> >  	if (nla_put_u32(msg, DEVLINK_ATTR_PORT_SPLIT_GROUP,
> > attrs->port_number))

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

* Re: [PATCH net-next 1/3] devlink: Introduce PCI PF port flavour and port attribute
  2019-07-02  4:26     ` Parav Pandit
@ 2019-07-02 17:47       ` Jakub Kicinski
  2019-07-02 18:50         ` Parav Pandit
  0 siblings, 1 reply; 71+ messages in thread
From: Jakub Kicinski @ 2019-07-02 17:47 UTC (permalink / raw)
  To: Parav Pandit; +Cc: Jiri Pirko, netdev, Saeed Mahameed

On Tue, 2 Jul 2019 04:26:47 +0000, Parav Pandit wrote:
> > On Mon,  1 Jul 2019 07:27:32 -0500, Parav Pandit wrote:  
> > > In an eswitch, PCI PF may have port which is normally represented
> > > using a representor netdevice.
> > > To have better visibility of eswitch port, its association with PF, a
> > > representor netdevice and port number, introduce a PCI PF port flavour
> > > and port attriute.
> > >
> > > When devlink port flavour is PCI PF, fill up PCI PF attributes of the
> > > port.
> > >
> > > Extend port name creation using PCI PF number on best effort basis.
> > > So that vendor drivers can skip defining their own scheme.
> > >
> > > $ devlink port show
> > > pci/0000:05:00.0/0: type eth netdev eth0 flavour pcipf pfnum 0
> > >
> > > Acked-by: Jiri Pirko <jiri@mellanox.com>
> > > Signed-off-by: Parav Pandit <parav@mellanox.com>
> > > diff --git a/include/net/devlink.h b/include/net/devlink.h index
> > > 6625ea068d5e..8db9c0e83fb5 100644
> > > --- a/include/net/devlink.h
> > > +++ b/include/net/devlink.h
> > > @@ -38,6 +38,10 @@ struct devlink {
> > >  	char priv[0] __aligned(NETDEV_ALIGN);  };
> > >
> > > +struct devlink_port_pci_pf_attrs {  
> > 
> > Why the named structure?  Anonymous one should be just fine?
> >  
> No specific reason for this patch. But named structure allows to
> extend it more easily with code readability. 

I'd argue the readability - I hove to scroll up/look up the structure
just to see it has a single member.  But no big deal :)

> Such as subsequently we want to add the peer_mac etc port attributes.
> Named structure to store those attributes are helpful. 

It remains to be seen if peer attributes are flavour specific 🤔
I'd imagine most port types would have some form of a peer (other
than a network port, perhaps).  But perhaps different peer attributes.

> > > diff --git a/net/core/devlink.c b/net/core/devlink.c index
> > > 89c533778135..001f9e2c96f0 100644
> > > --- a/net/core/devlink.c
> > > +++ b/net/core/devlink.c
> > > @@ -517,6 +517,11 @@ static int devlink_nl_port_attrs_put(struct sk_buff *msg,  
> > >  		return -EMSGSIZE;
> > >  	if (nla_put_u32(msg, DEVLINK_ATTR_PORT_NUMBER, attrs->port_number))
> > >  		return -EMSGSIZE;  
> > 
> > Why would we report network port information for PF and VF port
> > flavours?  
>
> I didn't see any immediate need to report, at the same time didn't
> find any reason to treat such port flavours differently than existing
> one. It just gives a clear view of the device's eswitch. Might find
> it useful during debugging while inspecting device internal tables..

PFs and VFs ports are not tied to network ports in switchdev mode.
You have only one network port under a devlink instance AFAIR, anyway.

> > > +	if (devlink_port->attrs.flavour == DEVLINK_PORT_FLAVOUR_PCI_PF) {
> > > +		if (nla_put_u16(msg, DEVLINK_ATTR_PORT_PCI_PF_NUMBER,
> > > +				attrs->pci_pf.pf))
> > > +			return -EMSGSIZE;
> > > +	}
> > >  	if (!attrs->split)
> > >  		return 0;
> > >  	if (nla_put_u32(msg, DEVLINK_ATTR_PORT_SPLIT_GROUP, attrs->port_number))  

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

* RE: [PATCH net-next 1/3] devlink: Introduce PCI PF port flavour and port attribute
  2019-07-02 17:47       ` Jakub Kicinski
@ 2019-07-02 18:50         ` Parav Pandit
  2019-07-02 23:42           ` Jakub Kicinski
  0 siblings, 1 reply; 71+ messages in thread
From: Parav Pandit @ 2019-07-02 18:50 UTC (permalink / raw)
  To: Jakub Kicinski; +Cc: Jiri Pirko, netdev, Saeed Mahameed



> -----Original Message-----
> From: Jakub Kicinski <jakub.kicinski@netronome.com>
> Sent: Tuesday, July 2, 2019 11:17 PM
> To: Parav Pandit <parav@mellanox.com>
> Cc: Jiri Pirko <jiri@mellanox.com>; netdev@vger.kernel.org; Saeed
> Mahameed <saeedm@mellanox.com>
> Subject: Re: [PATCH net-next 1/3] devlink: Introduce PCI PF port flavour and
> port attribute
> 
> On Tue, 2 Jul 2019 04:26:47 +0000, Parav Pandit wrote:
> > > On Mon,  1 Jul 2019 07:27:32 -0500, Parav Pandit wrote:
> > > > In an eswitch, PCI PF may have port which is normally represented
> > > > using a representor netdevice.
> > > > To have better visibility of eswitch port, its association with
> > > > PF, a representor netdevice and port number, introduce a PCI PF
> > > > port flavour and port attriute.
> > > >
> > > > When devlink port flavour is PCI PF, fill up PCI PF attributes of
> > > > the port.
> > > >
> > > > Extend port name creation using PCI PF number on best effort basis.
> > > > So that vendor drivers can skip defining their own scheme.
> > > >
> > > > $ devlink port show
> > > > pci/0000:05:00.0/0: type eth netdev eth0 flavour pcipf pfnum 0
> > > >
> > > > Acked-by: Jiri Pirko <jiri@mellanox.com>
> > > > Signed-off-by: Parav Pandit <parav@mellanox.com> diff --git
> > > > a/include/net/devlink.h b/include/net/devlink.h index
> > > > 6625ea068d5e..8db9c0e83fb5 100644
> > > > --- a/include/net/devlink.h
> > > > +++ b/include/net/devlink.h
> > > > @@ -38,6 +38,10 @@ struct devlink {
> > > >  	char priv[0] __aligned(NETDEV_ALIGN);  };
> > > >
> > > > +struct devlink_port_pci_pf_attrs {
> > >
> > > Why the named structure?  Anonymous one should be just fine?
> > >
> > No specific reason for this patch. But named structure allows to
> > extend it more easily with code readability.
> 
> I'd argue the readability - I hove to scroll up/look up the structure just to see
> it has a single member.  But no big deal :)
> 
Ok. :-)

> > Such as subsequently we want to add the peer_mac etc port attributes.
> > Named structure to store those attributes are helpful.
> 
> It remains to be seen if peer attributes are flavour specific 🤔
> I'd imagine most port types would have some form of a peer (other than a
> network port, perhaps).  But perhaps different peer attributes.
>
Few attributes may be common and few will be port specific.
So as it evolves, data structure will evolve.
Common attribute I can think of is - mac address.
 
> > > > diff --git a/net/core/devlink.c b/net/core/devlink.c index
> > > > 89c533778135..001f9e2c96f0 100644
> > > > --- a/net/core/devlink.c
> > > > +++ b/net/core/devlink.c
> > > > @@ -517,6 +517,11 @@ static int devlink_nl_port_attrs_put(struct
> sk_buff *msg,
> > > >  		return -EMSGSIZE;
> > > >  	if (nla_put_u32(msg, DEVLINK_ATTR_PORT_NUMBER, attrs-
> >port_number))
> > > >  		return -EMSGSIZE;
> > >
> > > Why would we report network port information for PF and VF port
> > > flavours?
> >
> > I didn't see any immediate need to report, at the same time didn't
> > find any reason to treat such port flavours differently than existing
> > one. It just gives a clear view of the device's eswitch. Might find it
> > useful during debugging while inspecting device internal tables..
> 
> PFs and VFs ports are not tied to network ports in switchdev mode.
> You have only one network port under a devlink instance AFAIR, anyway.
> 
I am not sure what do you mean by network port.
Do you intent to see a physical port that connects to physical network?

As I described in the comment of the PF and VF flavour, it is an eswitch port.
I have shown the diagram also of the eswitch in the cover letter.
Port_number doesn't have to a physical port. Flavour describe what port type is and number says what is the eswitch port number.
Hope it clarifies.

> > > > +	if (devlink_port->attrs.flavour == DEVLINK_PORT_FLAVOUR_PCI_PF) {
> > > > +		if (nla_put_u16(msg, DEVLINK_ATTR_PORT_PCI_PF_NUMBER,
> > > > +				attrs->pci_pf.pf))
> > > > +			return -EMSGSIZE;
> > > > +	}
> > > >  	if (!attrs->split)
> > > >  		return 0;
> > > >  	if (nla_put_u32(msg, DEVLINK_ATTR_PORT_SPLIT_GROUP,
> > > > attrs->port_number))

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

* Re: [PATCH net-next 1/3] devlink: Introduce PCI PF port flavour and port attribute
  2019-07-02 18:50         ` Parav Pandit
@ 2019-07-02 23:42           ` Jakub Kicinski
  2019-07-03  2:08             ` Parav Pandit
  0 siblings, 1 reply; 71+ messages in thread
From: Jakub Kicinski @ 2019-07-02 23:42 UTC (permalink / raw)
  To: Parav Pandit; +Cc: Jiri Pirko, netdev, Saeed Mahameed

On Tue, 2 Jul 2019 18:50:31 +0000, Parav Pandit wrote:
> > > I didn't see any immediate need to report, at the same time didn't
> > > find any reason to treat such port flavours differently than existing
> > > one. It just gives a clear view of the device's eswitch. Might find it
> > > useful during debugging while inspecting device internal tables..  
> > 
> > PFs and VFs ports are not tied to network ports in switchdev mode.
> > You have only one network port under a devlink instance AFAIR, anyway.
> >   
> I am not sure what do you mean by network port.

DEVLINK_PORT_FLAVOUR_PHYSICAL

> Do you intent to see a physical port that connects to physical network?
> 
> As I described in the comment of the PF and VF flavour, it is an eswitch port.
> I have shown the diagram also of the eswitch in the cover letter.
> Port_number doesn't have to a physical port. Flavour describe what
> port type is and number says what is the eswitch port number.
> Hope it clarifies.

I understand what you're doing.  If you want to expose some device
specific eswitch port ID please add a new attribute for that.
The fact that that ID may match port_number for your device today 
is coincidental.  port_number, and split attributes should not be
exposed for PCI ports.

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

* RE: [PATCH net-next 1/3] devlink: Introduce PCI PF port flavour and port attribute
  2019-07-02 23:42           ` Jakub Kicinski
@ 2019-07-03  2:08             ` Parav Pandit
  2019-07-03  2:15               ` Jakub Kicinski
  0 siblings, 1 reply; 71+ messages in thread
From: Parav Pandit @ 2019-07-03  2:08 UTC (permalink / raw)
  To: Jakub Kicinski; +Cc: Jiri Pirko, netdev, Saeed Mahameed



> -----Original Message-----
> From: Jakub Kicinski <jakub.kicinski@netronome.com>
> Sent: Wednesday, July 3, 2019 5:13 AM
> To: Parav Pandit <parav@mellanox.com>
> Cc: Jiri Pirko <jiri@mellanox.com>; netdev@vger.kernel.org; Saeed
> Mahameed <saeedm@mellanox.com>
> Subject: Re: [PATCH net-next 1/3] devlink: Introduce PCI PF port flavour and
> port attribute
> 
> On Tue, 2 Jul 2019 18:50:31 +0000, Parav Pandit wrote:
> > > > I didn't see any immediate need to report, at the same time didn't
> > > > find any reason to treat such port flavours differently than
> > > > existing one. It just gives a clear view of the device's eswitch.
> > > > Might find it useful during debugging while inspecting device internal
> tables..
> > >
> > > PFs and VFs ports are not tied to network ports in switchdev mode.
> > > You have only one network port under a devlink instance AFAIR, anyway.
> > >
> > I am not sure what do you mean by network port.
> 
> DEVLINK_PORT_FLAVOUR_PHYSICAL
> 
> > Do you intent to see a physical port that connects to physical network?
> >
> > As I described in the comment of the PF and VF flavour, it is an eswitch
> port.
> > I have shown the diagram also of the eswitch in the cover letter.
> > Port_number doesn't have to a physical port. Flavour describe what
> > port type is and number says what is the eswitch port number.
> > Hope it clarifies.
> 
> I understand what you're doing.  
o.k.

> If you want to expose some device specific
> eswitch port ID please add a new attribute for that.
> The fact that that ID may match port_number for your device today is
> coincidental.  port_number, and split attributes should not be exposed for
> PCI ports.
So your concern is non mellanox hw has eswitch but there may not be a unique handle to identify a eswitch port?
Or that handle may be wider than 32-bit?
And instead of treating port_number as handle, there should be different attribute, is that the ask?

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

* Re: [PATCH net-next 1/3] devlink: Introduce PCI PF port flavour and port attribute
  2019-07-03  2:08             ` Parav Pandit
@ 2019-07-03  2:15               ` Jakub Kicinski
  2019-07-03  4:46                 ` Parav Pandit
  0 siblings, 1 reply; 71+ messages in thread
From: Jakub Kicinski @ 2019-07-03  2:15 UTC (permalink / raw)
  To: Parav Pandit; +Cc: Jiri Pirko, netdev, Saeed Mahameed

On Wed, 3 Jul 2019 02:08:39 +0000, Parav Pandit wrote:
> > If you want to expose some device specific
> > eswitch port ID please add a new attribute for that.
> > The fact that that ID may match port_number for your device today is
> > coincidental.  port_number, and split attributes should not be exposed for
> > PCI ports.
>
> So your concern is non mellanox hw has eswitch but there may not be a
> unique handle to identify a eswitch port?

That's not a concern, no.  Like any debug attribute it should be
optional.

> Or that handle may be wider than 32-bit?

64 bit would probably be better, yes, although that wasn't my initial
concern.

> And instead of treating port_number as handle, there should be
> different attribute, is that the ask?

Yes, the ask, as always, is to not abuse existing attributes to carry
tangentially related information.

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

* RE: [PATCH net-next 1/3] devlink: Introduce PCI PF port flavour and port attribute
  2019-07-03  2:15               ` Jakub Kicinski
@ 2019-07-03  4:46                 ` Parav Pandit
  2019-07-03 10:37                   ` Jiri Pirko
  0 siblings, 1 reply; 71+ messages in thread
From: Parav Pandit @ 2019-07-03  4:46 UTC (permalink / raw)
  To: Jakub Kicinski; +Cc: Jiri Pirko, netdev, Saeed Mahameed



> -----Original Message-----
> From: Jakub Kicinski <jakub.kicinski@netronome.com>
> Sent: Wednesday, July 3, 2019 7:46 AM
> To: Parav Pandit <parav@mellanox.com>
> Cc: Jiri Pirko <jiri@mellanox.com>; netdev@vger.kernel.org; Saeed
> Mahameed <saeedm@mellanox.com>
> Subject: Re: [PATCH net-next 1/3] devlink: Introduce PCI PF port flavour and
> port attribute
> 
> On Wed, 3 Jul 2019 02:08:39 +0000, Parav Pandit wrote:
> > > If you want to expose some device specific eswitch port ID please
> > > add a new attribute for that.
> > > The fact that that ID may match port_number for your device today is
> > > coincidental.  port_number, and split attributes should not be
> > > exposed for PCI ports.
> >
> > So your concern is non mellanox hw has eswitch but there may not be a
> > unique handle to identify a eswitch port?
> 
> That's not a concern, no.  Like any debug attribute it should be optional.
> 
> > Or that handle may be wider than 32-bit?
> 
> 64 bit would probably be better, yes, although that wasn't my initial
> concern.
> 
Why 32-bit is not enough?

> > And instead of treating port_number as handle, there should be
> > different attribute, is that the ask?
> 
> Yes, the ask, as always, is to not abuse existing attributes to carry
> tangentially related information.

Why it is tangential?
Devlink_port has got a port_number. Depending on flavour this port_number represents a port.
If it is floavour=PHYSICAL, its physical port number.
If it is eswitch pf/vf ports, it represents eswitch port.

Why you see it only as physical_port_number?

Jiri,
Do you see it this way too?


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

* Re: [PATCH net-next 1/3] devlink: Introduce PCI PF port flavour and port attribute
  2019-07-03  4:46                 ` Parav Pandit
@ 2019-07-03 10:37                   ` Jiri Pirko
  2019-07-03 13:49                     ` Parav Pandit
  2019-07-03 14:09                     ` Andrew Lunn
  0 siblings, 2 replies; 71+ messages in thread
From: Jiri Pirko @ 2019-07-03 10:37 UTC (permalink / raw)
  To: Parav Pandit
  Cc: Jakub Kicinski, Jiri Pirko, netdev, Saeed Mahameed,
	vivien.didelot, andrew, f.fainelli

Wed, Jul 03, 2019 at 06:46:13AM CEST, parav@mellanox.com wrote:
>
>
>> -----Original Message-----
>> From: Jakub Kicinski <jakub.kicinski@netronome.com>
>> Sent: Wednesday, July 3, 2019 7:46 AM
>> To: Parav Pandit <parav@mellanox.com>
>> Cc: Jiri Pirko <jiri@mellanox.com>; netdev@vger.kernel.org; Saeed
>> Mahameed <saeedm@mellanox.com>
>> Subject: Re: [PATCH net-next 1/3] devlink: Introduce PCI PF port flavour and
>> port attribute
>> 
>> On Wed, 3 Jul 2019 02:08:39 +0000, Parav Pandit wrote:
>> > > If you want to expose some device specific eswitch port ID please
>> > > add a new attribute for that.
>> > > The fact that that ID may match port_number for your device today is
>> > > coincidental.  port_number, and split attributes should not be
>> > > exposed for PCI ports.
>> >
>> > So your concern is non mellanox hw has eswitch but there may not be a
>> > unique handle to identify a eswitch port?
>> 
>> That's not a concern, no.  Like any debug attribute it should be optional.
>> 
>> > Or that handle may be wider than 32-bit?
>> 
>> 64 bit would probably be better, yes, although that wasn't my initial
>> concern.
>> 
>Why 32-bit is not enough?
>
>> > And instead of treating port_number as handle, there should be
>> > different attribute, is that the ask?
>> 
>> Yes, the ask, as always, is to not abuse existing attributes to carry
>> tangentially related information.
>
>Why it is tangential?
>Devlink_port has got a port_number. Depending on flavour this port_number represents a port.
>If it is floavour=PHYSICAL, its physical port number.
>If it is eswitch pf/vf ports, it represents eswitch port.
>
>Why you see it only as physical_port_number?

The original intention was like that. See the desc of
devlink_port_attrs_set():

 *      @port_number: number of the port that is facing user, for example
 *                    the front panel port number

For vf/pf representors, this is not applicable and should be indeed
avoided.

However, we expose it for DEVLINK_PORT_FLAVOUR_CPU and
DEVLINK_PORT_FLAVOUR_DSA. Not sure if it makes sense there either.
Ccing Florian, Andrew and Vivien.
What do you guys think?

Perhaps we should have:
	if (attrs->flavour == DEVLINK_PORT_FLAVOUR_PHYSICAL &&
	    nla_put_u32(msg, DEVLINK_ATTR_PORT_NUMBER, attrs->port_number))
                return -EMSGSIZE;
in devlink_nl_port_attrs_put()


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

* RE: [PATCH net-next 1/3] devlink: Introduce PCI PF port flavour and port attribute
  2019-07-03 10:37                   ` Jiri Pirko
@ 2019-07-03 13:49                     ` Parav Pandit
  2019-07-03 14:33                       ` Jiri Pirko
  2019-07-03 14:09                     ` Andrew Lunn
  1 sibling, 1 reply; 71+ messages in thread
From: Parav Pandit @ 2019-07-03 13:49 UTC (permalink / raw)
  To: Jiri Pirko
  Cc: Jakub Kicinski, Jiri Pirko, netdev, Saeed Mahameed,
	vivien.didelot, andrew, f.fainelli



> -----Original Message-----
> From: Jiri Pirko <jiri@resnulli.us>
> Sent: Wednesday, July 3, 2019 4:07 PM
> To: Parav Pandit <parav@mellanox.com>
> Cc: Jakub Kicinski <jakub.kicinski@netronome.com>; Jiri Pirko
> <jiri@mellanox.com>; netdev@vger.kernel.org; Saeed Mahameed
> <saeedm@mellanox.com>; vivien.didelot@gmail.com; andrew@lunn.ch;
> f.fainelli@gmail.com
> Subject: Re: [PATCH net-next 1/3] devlink: Introduce PCI PF port flavour and
> port attribute
> 
> Wed, Jul 03, 2019 at 06:46:13AM CEST, parav@mellanox.com wrote:
> >
> >
> >> -----Original Message-----
> >> From: Jakub Kicinski <jakub.kicinski@netronome.com>
> >> Sent: Wednesday, July 3, 2019 7:46 AM
> >> To: Parav Pandit <parav@mellanox.com>
> >> Cc: Jiri Pirko <jiri@mellanox.com>; netdev@vger.kernel.org; Saeed
> >> Mahameed <saeedm@mellanox.com>
> >> Subject: Re: [PATCH net-next 1/3] devlink: Introduce PCI PF port
> >> flavour and port attribute
> >>
> >> On Wed, 3 Jul 2019 02:08:39 +0000, Parav Pandit wrote:
> >> > > If you want to expose some device specific eswitch port ID please
> >> > > add a new attribute for that.
> >> > > The fact that that ID may match port_number for your device today
> >> > > is coincidental.  port_number, and split attributes should not be
> >> > > exposed for PCI ports.
> >> >
> >> > So your concern is non mellanox hw has eswitch but there may not be
> >> > a unique handle to identify a eswitch port?
> >>
> >> That's not a concern, no.  Like any debug attribute it should be optional.
> >>
> >> > Or that handle may be wider than 32-bit?
> >>
> >> 64 bit would probably be better, yes, although that wasn't my initial
> >> concern.
> >>
> >Why 32-bit is not enough?
> >
> >> > And instead of treating port_number as handle, there should be
> >> > different attribute, is that the ask?
> >>
> >> Yes, the ask, as always, is to not abuse existing attributes to carry
> >> tangentially related information.
> >
> >Why it is tangential?
> >Devlink_port has got a port_number. Depending on flavour this port_number
> represents a port.
> >If it is floavour=PHYSICAL, its physical port number.
> >If it is eswitch pf/vf ports, it represents eswitch port.
> >
> >Why you see it only as physical_port_number?
> 
> The original intention was like that. See the desc of
> devlink_port_attrs_set():
> 
>  *      @port_number: number of the port that is facing user, for example
>  *                    the front panel port number
> 
> For vf/pf representors, this is not applicable and should be indeed avoided.
> 
Physical port number is not applicable but this is useful information that completes the eswitch picture.
Because eswitch has this termination end point anyway.
Instead of inventing some new vendor specific field, I see value in using existing port_number field.
Will wait for others inputs.

> However, we expose it for DEVLINK_PORT_FLAVOUR_CPU and
> DEVLINK_PORT_FLAVOUR_DSA. Not sure if it makes sense there either.
> Ccing Florian, Andrew and Vivien.
> What do you guys think?
> 
> Perhaps we should have:
> 	if (attrs->flavour == DEVLINK_PORT_FLAVOUR_PHYSICAL &&
> 	    nla_put_u32(msg, DEVLINK_ATTR_PORT_NUMBER, attrs-
> >port_number))
>                 return -EMSGSIZE;
> in devlink_nl_port_attrs_put()


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

* Re: [PATCH net-next 1/3] devlink: Introduce PCI PF port flavour and port attribute
  2019-07-03 10:37                   ` Jiri Pirko
  2019-07-03 13:49                     ` Parav Pandit
@ 2019-07-03 14:09                     ` Andrew Lunn
  2019-07-03 14:34                       ` Jiri Pirko
  1 sibling, 1 reply; 71+ messages in thread
From: Andrew Lunn @ 2019-07-03 14:09 UTC (permalink / raw)
  To: Jiri Pirko
  Cc: Parav Pandit, Jakub Kicinski, Jiri Pirko, netdev, Saeed Mahameed,
	vivien.didelot, f.fainelli

> However, we expose it for DEVLINK_PORT_FLAVOUR_CPU and
> DEVLINK_PORT_FLAVOUR_DSA. Not sure if it makes sense there either.
> Ccing Florian, Andrew and Vivien.
> What do you guys think?

Hi Jiri

DSA and CPU ports are physical ports of the switch. And there can be
multiple DSA ports, and maybe sometime real soon now, multiple CPU
ports. So having a number associated with them is useful.

       Andrew

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

* Re: [PATCH net-next 1/3] devlink: Introduce PCI PF port flavour and port attribute
  2019-07-03 13:49                     ` Parav Pandit
@ 2019-07-03 14:33                       ` Jiri Pirko
  0 siblings, 0 replies; 71+ messages in thread
From: Jiri Pirko @ 2019-07-03 14:33 UTC (permalink / raw)
  To: Parav Pandit
  Cc: Jakub Kicinski, Jiri Pirko, netdev, Saeed Mahameed,
	vivien.didelot, andrew, f.fainelli

Wed, Jul 03, 2019 at 03:49:51PM CEST, parav@mellanox.com wrote:
>
>
>> -----Original Message-----
>> From: Jiri Pirko <jiri@resnulli.us>
>> Sent: Wednesday, July 3, 2019 4:07 PM
>> To: Parav Pandit <parav@mellanox.com>
>> Cc: Jakub Kicinski <jakub.kicinski@netronome.com>; Jiri Pirko
>> <jiri@mellanox.com>; netdev@vger.kernel.org; Saeed Mahameed
>> <saeedm@mellanox.com>; vivien.didelot@gmail.com; andrew@lunn.ch;
>> f.fainelli@gmail.com
>> Subject: Re: [PATCH net-next 1/3] devlink: Introduce PCI PF port flavour and
>> port attribute
>> 
>> Wed, Jul 03, 2019 at 06:46:13AM CEST, parav@mellanox.com wrote:
>> >
>> >
>> >> -----Original Message-----
>> >> From: Jakub Kicinski <jakub.kicinski@netronome.com>
>> >> Sent: Wednesday, July 3, 2019 7:46 AM
>> >> To: Parav Pandit <parav@mellanox.com>
>> >> Cc: Jiri Pirko <jiri@mellanox.com>; netdev@vger.kernel.org; Saeed
>> >> Mahameed <saeedm@mellanox.com>
>> >> Subject: Re: [PATCH net-next 1/3] devlink: Introduce PCI PF port
>> >> flavour and port attribute
>> >>
>> >> On Wed, 3 Jul 2019 02:08:39 +0000, Parav Pandit wrote:
>> >> > > If you want to expose some device specific eswitch port ID please
>> >> > > add a new attribute for that.
>> >> > > The fact that that ID may match port_number for your device today
>> >> > > is coincidental.  port_number, and split attributes should not be
>> >> > > exposed for PCI ports.
>> >> >
>> >> > So your concern is non mellanox hw has eswitch but there may not be
>> >> > a unique handle to identify a eswitch port?
>> >>
>> >> That's not a concern, no.  Like any debug attribute it should be optional.
>> >>
>> >> > Or that handle may be wider than 32-bit?
>> >>
>> >> 64 bit would probably be better, yes, although that wasn't my initial
>> >> concern.
>> >>
>> >Why 32-bit is not enough?
>> >
>> >> > And instead of treating port_number as handle, there should be
>> >> > different attribute, is that the ask?
>> >>
>> >> Yes, the ask, as always, is to not abuse existing attributes to carry
>> >> tangentially related information.
>> >
>> >Why it is tangential?
>> >Devlink_port has got a port_number. Depending on flavour this port_number
>> represents a port.
>> >If it is floavour=PHYSICAL, its physical port number.
>> >If it is eswitch pf/vf ports, it represents eswitch port.
>> >
>> >Why you see it only as physical_port_number?
>> 
>> The original intention was like that. See the desc of
>> devlink_port_attrs_set():
>> 
>>  *      @port_number: number of the port that is facing user, for example
>>  *                    the front panel port number
>> 
>> For vf/pf representors, this is not applicable and should be indeed avoided.
>> 
>Physical port number is not applicable but this is useful information that completes the eswitch picture.
>Because eswitch has this termination end point anyway.

Use port_index. That is up to the driver to put whatever value there.


>Instead of inventing some new vendor specific field, I see value in using existing port_number field.
>Will wait for others inputs.
>
>> However, we expose it for DEVLINK_PORT_FLAVOUR_CPU and
>> DEVLINK_PORT_FLAVOUR_DSA. Not sure if it makes sense there either.
>> Ccing Florian, Andrew and Vivien.
>> What do you guys think?
>> 
>> Perhaps we should have:
>> 	if (attrs->flavour == DEVLINK_PORT_FLAVOUR_PHYSICAL &&
>> 	    nla_put_u32(msg, DEVLINK_ATTR_PORT_NUMBER, attrs-
>> >port_number))
>>                 return -EMSGSIZE;
>> in devlink_nl_port_attrs_put()
>

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

* Re: [PATCH net-next 1/3] devlink: Introduce PCI PF port flavour and port attribute
  2019-07-03 14:09                     ` Andrew Lunn
@ 2019-07-03 14:34                       ` Jiri Pirko
  2019-07-03 16:13                         ` Parav Pandit
  0 siblings, 1 reply; 71+ messages in thread
From: Jiri Pirko @ 2019-07-03 14:34 UTC (permalink / raw)
  To: Andrew Lunn
  Cc: Parav Pandit, Jakub Kicinski, Jiri Pirko, netdev, Saeed Mahameed,
	vivien.didelot, f.fainelli

Wed, Jul 03, 2019 at 04:09:58PM CEST, andrew@lunn.ch wrote:
>> However, we expose it for DEVLINK_PORT_FLAVOUR_CPU and
>> DEVLINK_PORT_FLAVOUR_DSA. Not sure if it makes sense there either.
>> Ccing Florian, Andrew and Vivien.
>> What do you guys think?
>
>Hi Jiri
>
>DSA and CPU ports are physical ports of the switch. And there can be
>multiple DSA ports, and maybe sometime real soon now, multiple CPU
>ports. So having a number associated with them is useful.

Okay. Makes sense.

>
>       Andrew

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

* RE: [PATCH net-next 1/3] devlink: Introduce PCI PF port flavour and port attribute
  2019-07-03 14:34                       ` Jiri Pirko
@ 2019-07-03 16:13                         ` Parav Pandit
  2019-07-04  7:44                           ` Jiri Pirko
  0 siblings, 1 reply; 71+ messages in thread
From: Parav Pandit @ 2019-07-03 16:13 UTC (permalink / raw)
  To: Jiri Pirko, Andrew Lunn
  Cc: Jakub Kicinski, Jiri Pirko, netdev, Saeed Mahameed,
	vivien.didelot, f.fainelli



> -----Original Message-----
> From: Jiri Pirko <jiri@resnulli.us>
> Sent: Wednesday, July 3, 2019 8:05 PM
> To: Andrew Lunn <andrew@lunn.ch>
> Cc: Parav Pandit <parav@mellanox.com>; Jakub Kicinski
> <jakub.kicinski@netronome.com>; Jiri Pirko <jiri@mellanox.com>;
> netdev@vger.kernel.org; Saeed Mahameed <saeedm@mellanox.com>;
> vivien.didelot@gmail.com; f.fainelli@gmail.com
> Subject: Re: [PATCH net-next 1/3] devlink: Introduce PCI PF port flavour and
> port attribute
> 
> Wed, Jul 03, 2019 at 04:09:58PM CEST, andrew@lunn.ch wrote:
> >> However, we expose it for DEVLINK_PORT_FLAVOUR_CPU and
> >> DEVLINK_PORT_FLAVOUR_DSA. Not sure if it makes sense there either.
> >> Ccing Florian, Andrew and Vivien.
> >> What do you guys think?
> >
> >Hi Jiri
> >
> >DSA and CPU ports are physical ports of the switch. And there can be
> >multiple DSA ports, and maybe sometime real soon now, multiple CPU
> >ports. So having a number associated with them is useful.
> 
> Okay. Makes sense.
> 
Ok. I should probably update the comment section for port_number as its scope is expanded.
Should I revise the series with updated comment?

> >
> >       Andrew

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

* Re: [PATCH net-next 1/3] devlink: Introduce PCI PF port flavour and port attribute
  2019-07-03 16:13                         ` Parav Pandit
@ 2019-07-04  7:44                           ` Jiri Pirko
  0 siblings, 0 replies; 71+ messages in thread
From: Jiri Pirko @ 2019-07-04  7:44 UTC (permalink / raw)
  To: Parav Pandit
  Cc: Andrew Lunn, Jakub Kicinski, Jiri Pirko, netdev, Saeed Mahameed,
	vivien.didelot, f.fainelli

Wed, Jul 03, 2019 at 06:13:17PM CEST, parav@mellanox.com wrote:
>
>
>> -----Original Message-----
>> From: Jiri Pirko <jiri@resnulli.us>
>> Sent: Wednesday, July 3, 2019 8:05 PM
>> To: Andrew Lunn <andrew@lunn.ch>
>> Cc: Parav Pandit <parav@mellanox.com>; Jakub Kicinski
>> <jakub.kicinski@netronome.com>; Jiri Pirko <jiri@mellanox.com>;
>> netdev@vger.kernel.org; Saeed Mahameed <saeedm@mellanox.com>;
>> vivien.didelot@gmail.com; f.fainelli@gmail.com
>> Subject: Re: [PATCH net-next 1/3] devlink: Introduce PCI PF port flavour and
>> port attribute
>> 
>> Wed, Jul 03, 2019 at 04:09:58PM CEST, andrew@lunn.ch wrote:
>> >> However, we expose it for DEVLINK_PORT_FLAVOUR_CPU and
>> >> DEVLINK_PORT_FLAVOUR_DSA. Not sure if it makes sense there either.
>> >> Ccing Florian, Andrew and Vivien.
>> >> What do you guys think?
>> >
>> >Hi Jiri
>> >
>> >DSA and CPU ports are physical ports of the switch. And there can be
>> >multiple DSA ports, and maybe sometime real soon now, multiple CPU
>> >ports. So having a number associated with them is useful.
>> 
>> Okay. Makes sense.
>> 
>Ok. I should probably update the comment section for port_number as its scope is expanded.
>Should I revise the series with updated comment?

Please do. Also put a check to not fillup port_number attribute in case
of pf/vf flavour. Thanks!

>
>> >
>> >       Andrew

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

* [PATCH net-next v2 0/3] devlink: Introduce PCI PF, VF ports and attributes
  2019-07-01 12:27 [PATCH net-next 0/3] devlink: Introduce PCI PF, VF ports and attributes Parav Pandit
                   ` (4 preceding siblings ...)
  2019-07-01 18:30 ` [RESEND PATCH iproute2 net-next] " Parav Pandit
@ 2019-07-05  7:37 ` Parav Pandit
  2019-07-05  7:37   ` [PATCH net-next v2 1/3] devlink: Introduce PCI PF port flavour and port attribute Parav Pandit
                     ` (2 more replies)
  2019-07-06  6:16 ` [PATCH net-next v3 0/3] devlink: Introduce PCI PF, VF ports and attributes Parav Pandit
                   ` (3 subsequent siblings)
  9 siblings, 3 replies; 71+ messages in thread
From: Parav Pandit @ 2019-07-05  7:37 UTC (permalink / raw)
  To: netdev; +Cc: jiri, saeedm, jakub.kicinski, Parav Pandit

This patchset carry forwards the work initiated in [1] and discussion
futher concluded at [2].

To improve visibility of representor netdevice, its association with
PF or VF, physical port, two new devlink port flavours are added as
PCI PF and PCI VF ports.

A sample eswitch view can be seen below, which will be futher extended to
mdev subdevices of a PCI function in future.

Patch-1,2 extends devlink port attributes and port flavour.
Patch-3 extends mlx5 driver to register devlink ports for PF, VF and
physical link.

                                +---+      +---+
                              vf|   |      |   | pf
                                +-+-+      +-+-+
physical link <---------+         |          |
                        |         |          |
                        |         |          |
                      +-+-+     +-+-+      +-+-+
                      | 1 |     | 2 |      | 3 |
                   +--+---+-----+---+------+---+--+
                   |  physical   vf         pf    |
                   |  port       port       port  |
                   |                              |
                   |             eswitch          |
                   |                              |
                   +------------------------------+

[1] https://www.spinics.net/lists/netdev/msg555797.html
[2] https://marc.info/?l=linux-netdev&m=155354609408485&w=2

---
Changelog:
v1->v2:
 - Updated new APIs and mlx5 driver to drop port_number for PF, VF
   attributes
 - Updated port_number comment for its usage
 - Limited putting port_number to physical ports

Parav Pandit (3):
  devlink: Introduce PCI PF port flavour and port attribute
  devlink: Introduce PCI VF port flavour and port attribute
  net/mlx5e: Register devlink ports for physical link, PCI PF, VFs

 .../net/ethernet/mellanox/mlx5/core/en_rep.c  | 108 ++++++++++++-----
 .../net/ethernet/mellanox/mlx5/core/en_rep.h  |   1 +
 include/net/devlink.h                         |  25 +++-
 include/uapi/linux/devlink.h                  |  11 ++
 net/core/devlink.c                            | 114 +++++++++++++++---
 5 files changed, 212 insertions(+), 47 deletions(-)

-- 
2.19.2


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

* [PATCH net-next v2 1/3] devlink: Introduce PCI PF port flavour and port attribute
  2019-07-05  7:37 ` [PATCH net-next v2 0/3] devlink: Introduce PCI PF, VF ports and attributes Parav Pandit
@ 2019-07-05  7:37   ` Parav Pandit
  2019-07-05 19:17     ` Jakub Kicinski
  2019-07-05  7:37   ` [PATCH net-next v2 2/3] devlink: Introduce PCI VF " Parav Pandit
  2019-07-05  7:37   ` [PATCH net-next v2 3/3] net/mlx5e: Register devlink ports for physical link, PCI PF, VFs Parav Pandit
  2 siblings, 1 reply; 71+ messages in thread
From: Parav Pandit @ 2019-07-05  7:37 UTC (permalink / raw)
  To: netdev; +Cc: jiri, saeedm, jakub.kicinski, Parav Pandit

In an eswitch, PCI PF may have port which is normally represented
using a representor netdevice.
To have better visibility of eswitch port, its association with
PF and a representor netdevice, introduce a PCI PF port
flavour and port attriute.

When devlink port flavour is PCI PF, fill up PCI PF attributes of the
port.

Extend port name creation using PCI PF number on best effort basis.
So that vendor drivers can skip defining their own scheme.

$ devlink port show
pci/0000:05:00.0/0: type eth netdev eth0 flavour pcipf pfnum 0

Signed-off-by: Parav Pandit <parav@mellanox.com>

---
Changelog:
v1->v2:
 - Limited port_num attribute to physical ports
 - Updated PCI PF attribute set API to not have port_number
---
 include/net/devlink.h        | 15 ++++++-
 include/uapi/linux/devlink.h |  5 +++
 net/core/devlink.c           | 80 +++++++++++++++++++++++++++++-------
 3 files changed, 84 insertions(+), 16 deletions(-)

diff --git a/include/net/devlink.h b/include/net/devlink.h
index 6625ea068d5e..32badf7e0810 100644
--- a/include/net/devlink.h
+++ b/include/net/devlink.h
@@ -38,14 +38,24 @@ struct devlink {
 	char priv[0] __aligned(NETDEV_ALIGN);
 };
 
+struct devlink_port_pci_pf_attrs {
+	u16 pf;	/* Associated PCI PF for this port. */
+};
+
 struct devlink_port_attrs {
 	u8 set:1,
 	   split:1,
 	   switch_port:1;
 	enum devlink_port_flavour flavour;
-	u32 port_number; /* same value as "split group" */
+	u32 port_number; /* same value as "split group".
+			  * Valid only when a port is physical and visible
+			  * to the user for a given port flavour.
+			  */
 	u32 split_subport_number;
 	struct netdev_phys_item_id switch_id;
+	union {
+		struct devlink_port_pci_pf_attrs pci_pf;
+	};
 };
 
 struct devlink_port {
@@ -590,6 +600,9 @@ void devlink_port_attrs_set(struct devlink_port *devlink_port,
 			    u32 split_subport_number,
 			    const unsigned char *switch_id,
 			    unsigned char switch_id_len);
+void devlink_port_attrs_pci_pf_set(struct devlink_port *devlink_port,
+				   const unsigned char *switch_id,
+				   unsigned char switch_id_len, u16 pf);
 int devlink_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/include/uapi/linux/devlink.h b/include/uapi/linux/devlink.h
index 5287b42c181f..f7323884c3fe 100644
--- a/include/uapi/linux/devlink.h
+++ b/include/uapi/linux/devlink.h
@@ -169,6 +169,10 @@ enum devlink_port_flavour {
 	DEVLINK_PORT_FLAVOUR_DSA, /* Distributed switch architecture
 				   * interconnect port.
 				   */
+	DEVLINK_PORT_FLAVOUR_PCI_PF, /* Represents eswitch port for
+				      * the PCI PF. It is an internal
+				      * port that faces the PCI PF.
+				      */
 };
 
 enum devlink_param_cmode {
@@ -337,6 +341,7 @@ enum devlink_attr {
 	DEVLINK_ATTR_FLASH_UPDATE_STATUS_DONE,	/* u64 */
 	DEVLINK_ATTR_FLASH_UPDATE_STATUS_TOTAL,	/* u64 */
 
+	DEVLINK_ATTR_PORT_PCI_PF_NUMBER,	/* u16 */
 	/* add new attributes above here, update the policy in devlink.c */
 
 	__DEVLINK_ATTR_MAX,
diff --git a/net/core/devlink.c b/net/core/devlink.c
index 89c533778135..c9418f1ce025 100644
--- a/net/core/devlink.c
+++ b/net/core/devlink.c
@@ -506,6 +506,14 @@ static void devlink_notify(struct devlink *devlink, enum devlink_command cmd)
 				msg, 0, DEVLINK_MCGRP_CONFIG, GFP_KERNEL);
 }
 
+static bool
+is_devlink_phy_port_num_supported(const struct devlink_port *dl_port)
+{
+	return (dl_port->attrs.flavour == DEVLINK_PORT_FLAVOUR_PHYSICAL ||
+		dl_port->attrs.flavour == DEVLINK_PORT_FLAVOUR_CPU ||
+		dl_port->attrs.flavour == DEVLINK_PORT_FLAVOUR_DSA);
+}
+
 static int devlink_nl_port_attrs_put(struct sk_buff *msg,
 				     struct devlink_port *devlink_port)
 {
@@ -515,8 +523,14 @@ static int devlink_nl_port_attrs_put(struct sk_buff *msg,
 		return 0;
 	if (nla_put_u16(msg, DEVLINK_ATTR_PORT_FLAVOUR, attrs->flavour))
 		return -EMSGSIZE;
-	if (nla_put_u32(msg, DEVLINK_ATTR_PORT_NUMBER, attrs->port_number))
+	if (is_devlink_phy_port_num_supported(devlink_port) &&
+	    nla_put_u32(msg, DEVLINK_ATTR_PORT_NUMBER, attrs->port_number))
 		return -EMSGSIZE;
+	if (devlink_port->attrs.flavour == DEVLINK_PORT_FLAVOUR_PCI_PF) {
+		if (nla_put_u16(msg, DEVLINK_ATTR_PORT_PCI_PF_NUMBER,
+				attrs->pci_pf.pf))
+			return -EMSGSIZE;
+	}
 	if (!attrs->split)
 		return 0;
 	if (nla_put_u32(msg, DEVLINK_ATTR_PORT_SPLIT_GROUP, attrs->port_number))
@@ -5738,6 +5752,30 @@ void devlink_port_type_clear(struct devlink_port *devlink_port)
 }
 EXPORT_SYMBOL_GPL(devlink_port_type_clear);
 
+static void __devlink_port_attrs_set(struct devlink_port *devlink_port,
+				     enum devlink_port_flavour flavour,
+				     u32 port_number,
+				     const unsigned char *switch_id,
+				     unsigned char switch_id_len)
+{
+	struct devlink_port_attrs *attrs = &devlink_port->attrs;
+
+	if (WARN_ON(devlink_port->registered))
+		return;
+	attrs->set = true;
+	attrs->flavour = flavour;
+	attrs->port_number = port_number;
+	if (switch_id) {
+		attrs->switch_port = true;
+		if (WARN_ON(switch_id_len > MAX_PHYS_ITEM_ID_LEN))
+			switch_id_len = MAX_PHYS_ITEM_ID_LEN;
+		memcpy(attrs->switch_id.id, switch_id, switch_id_len);
+		attrs->switch_id.id_len = switch_id_len;
+	} else {
+		attrs->switch_port = false;
+	}
+}
+
 /**
  *	devlink_port_attrs_set - Set port attributes
  *
@@ -5761,25 +5799,34 @@ void devlink_port_attrs_set(struct devlink_port *devlink_port,
 {
 	struct devlink_port_attrs *attrs = &devlink_port->attrs;
 
-	if (WARN_ON(devlink_port->registered))
-		return;
-	attrs->set = true;
-	attrs->flavour = flavour;
-	attrs->port_number = port_number;
+	__devlink_port_attrs_set(devlink_port, flavour, port_number,
+				 switch_id, switch_id_len);
 	attrs->split = split;
 	attrs->split_subport_number = split_subport_number;
-	if (switch_id) {
-		attrs->switch_port = true;
-		if (WARN_ON(switch_id_len > MAX_PHYS_ITEM_ID_LEN))
-			switch_id_len = MAX_PHYS_ITEM_ID_LEN;
-		memcpy(attrs->switch_id.id, switch_id, switch_id_len);
-		attrs->switch_id.id_len = switch_id_len;
-	} else {
-		attrs->switch_port = false;
-	}
 }
 EXPORT_SYMBOL_GPL(devlink_port_attrs_set);
 
+/**
+ *	devlink_port_attrs_pci_pf_set - Set PCI PF port attributes
+ *
+ *	@devlink_port: devlink port
+ *	@pf: associated PF for the devlink port instance
+ *	@switch_id: if the port is part of switch, this is buffer with ID,
+ *	            otwerwise this is NULL
+ *	@switch_id_len: length of the switch_id buffer
+ */
+void devlink_port_attrs_pci_pf_set(struct devlink_port *devlink_port,
+				   const unsigned char *switch_id,
+				   unsigned char switch_id_len, u16 pf)
+{
+	struct devlink_port_attrs *attrs = &devlink_port->attrs;
+
+	__devlink_port_attrs_set(devlink_port, DEVLINK_PORT_FLAVOUR_PCI_PF,
+				 0, switch_id, switch_id_len);
+	attrs->pci_pf.pf = pf;
+}
+EXPORT_SYMBOL_GPL(devlink_port_attrs_pci_pf_set);
+
 static int __devlink_port_phys_port_name_get(struct devlink_port *devlink_port,
 					     char *name, size_t len)
 {
@@ -5804,6 +5851,9 @@ static int __devlink_port_phys_port_name_get(struct devlink_port *devlink_port,
 		 */
 		WARN_ON(1);
 		return -EINVAL;
+	case DEVLINK_PORT_FLAVOUR_PCI_PF:
+		n = snprintf(name, len, "pf%u", attrs->pci_pf.pf);
+		break;
 	}
 
 	if (n >= len)
-- 
2.19.2


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

* [PATCH net-next v2 2/3] devlink: Introduce PCI VF port flavour and port attribute
  2019-07-05  7:37 ` [PATCH net-next v2 0/3] devlink: Introduce PCI PF, VF ports and attributes Parav Pandit
  2019-07-05  7:37   ` [PATCH net-next v2 1/3] devlink: Introduce PCI PF port flavour and port attribute Parav Pandit
@ 2019-07-05  7:37   ` Parav Pandit
  2019-07-05  7:37   ` [PATCH net-next v2 3/3] net/mlx5e: Register devlink ports for physical link, PCI PF, VFs Parav Pandit
  2 siblings, 0 replies; 71+ messages in thread
From: Parav Pandit @ 2019-07-05  7:37 UTC (permalink / raw)
  To: netdev; +Cc: jiri, saeedm, jakub.kicinski, Parav Pandit

In an eswitch, PCI VF may have port which is normally represented using
a representor netdevice.
To have better visibility of eswitch port, its association with VF,
and its representor netdevice, introduce a PCI VF port flavour.

When devlink port flavour is PCI VF, fill up PCI VF attributes of
the port.

Extend port name creation using PCI PF and VF number scheme on best
effort basis, so that vendor drivers can skip defining their own scheme.

$ devlink port show
pci/0000:05:00.0/0: type eth netdev eth0 flavour pcipf pfnum 0
pci/0000:05:00.0/1: type eth netdev eth1 flavour pcivf pfnum 0 vfnum 0
pci/0000:05:00.0/2: type eth netdev eth2 flavour pcivf pfnum 0 vfnum 1

Signed-off-by: Parav Pandit <parav@mellanox.com>
---
Changelog:
v1->v2:
 - Updated PCI VF attribute set API to not have port_number
---
 include/net/devlink.h        | 10 ++++++++++
 include/uapi/linux/devlink.h |  6 ++++++
 net/core/devlink.c           | 34 ++++++++++++++++++++++++++++++++++
 3 files changed, 50 insertions(+)

diff --git a/include/net/devlink.h b/include/net/devlink.h
index 32badf7e0810..2b5cbc3f5a8b 100644
--- a/include/net/devlink.h
+++ b/include/net/devlink.h
@@ -42,6 +42,11 @@ struct devlink_port_pci_pf_attrs {
 	u16 pf;	/* Associated PCI PF for this port. */
 };
 
+struct devlink_port_pci_vf_attrs {
+	u16 pf;	/* Associated PCI PF for this port. */
+	u16 vf;	/* Associated PCI VF for of the PCI PF for this port. */
+};
+
 struct devlink_port_attrs {
 	u8 set:1,
 	   split:1,
@@ -55,6 +60,7 @@ struct devlink_port_attrs {
 	struct netdev_phys_item_id switch_id;
 	union {
 		struct devlink_port_pci_pf_attrs pci_pf;
+		struct devlink_port_pci_vf_attrs pci_vf;
 	};
 };
 
@@ -603,6 +609,10 @@ void devlink_port_attrs_set(struct devlink_port *devlink_port,
 void devlink_port_attrs_pci_pf_set(struct devlink_port *devlink_port,
 				   const unsigned char *switch_id,
 				   unsigned char switch_id_len, u16 pf);
+void devlink_port_attrs_pci_vf_set(struct devlink_port *devlink_port,
+				   const unsigned char *switch_id,
+				   unsigned char switch_id_len,
+				   u16 pf, u16 vf);
 int devlink_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/include/uapi/linux/devlink.h b/include/uapi/linux/devlink.h
index f7323884c3fe..ffc993256527 100644
--- a/include/uapi/linux/devlink.h
+++ b/include/uapi/linux/devlink.h
@@ -173,6 +173,10 @@ enum devlink_port_flavour {
 				      * the PCI PF. It is an internal
 				      * port that faces the PCI PF.
 				      */
+	DEVLINK_PORT_FLAVOUR_PCI_VF, /* Represents eswitch port
+				      * for the PCI VF. It is an internal
+				      * port that faces the PCI VF.
+				      */
 };
 
 enum devlink_param_cmode {
@@ -342,6 +346,8 @@ enum devlink_attr {
 	DEVLINK_ATTR_FLASH_UPDATE_STATUS_TOTAL,	/* u64 */
 
 	DEVLINK_ATTR_PORT_PCI_PF_NUMBER,	/* u16 */
+	DEVLINK_ATTR_PORT_PCI_VF_NUMBER,	/* u16 */
+
 	/* add new attributes above here, update the policy in devlink.c */
 
 	__DEVLINK_ATTR_MAX,
diff --git a/net/core/devlink.c b/net/core/devlink.c
index c9418f1ce025..033f13ecf89f 100644
--- a/net/core/devlink.c
+++ b/net/core/devlink.c
@@ -530,6 +530,12 @@ static int devlink_nl_port_attrs_put(struct sk_buff *msg,
 		if (nla_put_u16(msg, DEVLINK_ATTR_PORT_PCI_PF_NUMBER,
 				attrs->pci_pf.pf))
 			return -EMSGSIZE;
+	} else if (devlink_port->attrs.flavour == DEVLINK_PORT_FLAVOUR_PCI_VF) {
+		if (nla_put_u16(msg, DEVLINK_ATTR_PORT_PCI_PF_NUMBER,
+				attrs->pci_vf.pf) ||
+		    nla_put_u16(msg, DEVLINK_ATTR_PORT_PCI_VF_NUMBER,
+				attrs->pci_vf.vf))
+			return -EMSGSIZE;
 	}
 	if (!attrs->split)
 		return 0;
@@ -5827,6 +5833,30 @@ void devlink_port_attrs_pci_pf_set(struct devlink_port *devlink_port,
 }
 EXPORT_SYMBOL_GPL(devlink_port_attrs_pci_pf_set);
 
+/**
+ *	devlink_port_attrs_pci_vf_set - Set PCI VF port attributes
+ *
+ *	@devlink_port: devlink port
+ *	@pf: associated PF for the devlink port instance
+ *	@vf: associated VF of a PF for the devlink port instance
+ *	@switch_id: if the port is part of switch, this is buffer with ID,
+ *	            otwerwise this is NULL
+ *	@switch_id_len: length of the switch_id buffer
+ */
+void devlink_port_attrs_pci_vf_set(struct devlink_port *devlink_port,
+				   const unsigned char *switch_id,
+				   unsigned char switch_id_len,
+				   u16 pf, u16 vf)
+{
+	struct devlink_port_attrs *attrs = &devlink_port->attrs;
+
+	__devlink_port_attrs_set(devlink_port, DEVLINK_PORT_FLAVOUR_PCI_VF,
+				 0, switch_id, switch_id_len);
+	attrs->pci_vf.pf = pf;
+	attrs->pci_vf.vf = vf;
+}
+EXPORT_SYMBOL_GPL(devlink_port_attrs_pci_vf_set);
+
 static int __devlink_port_phys_port_name_get(struct devlink_port *devlink_port,
 					     char *name, size_t len)
 {
@@ -5854,6 +5884,10 @@ static int __devlink_port_phys_port_name_get(struct devlink_port *devlink_port,
 	case DEVLINK_PORT_FLAVOUR_PCI_PF:
 		n = snprintf(name, len, "pf%u", attrs->pci_pf.pf);
 		break;
+	case DEVLINK_PORT_FLAVOUR_PCI_VF:
+		n = snprintf(name, len, "pf%uvf%u",
+			     attrs->pci_vf.pf, attrs->pci_vf.vf);
+		break;
 	}
 
 	if (n >= len)
-- 
2.19.2


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

* [PATCH net-next v2 3/3] net/mlx5e: Register devlink ports for physical link, PCI PF, VFs
  2019-07-05  7:37 ` [PATCH net-next v2 0/3] devlink: Introduce PCI PF, VF ports and attributes Parav Pandit
  2019-07-05  7:37   ` [PATCH net-next v2 1/3] devlink: Introduce PCI PF port flavour and port attribute Parav Pandit
  2019-07-05  7:37   ` [PATCH net-next v2 2/3] devlink: Introduce PCI VF " Parav Pandit
@ 2019-07-05  7:37   ` Parav Pandit
  2 siblings, 0 replies; 71+ messages in thread
From: Parav Pandit @ 2019-07-05  7:37 UTC (permalink / raw)
  To: netdev; +Cc: jiri, saeedm, jakub.kicinski, Parav Pandit

Register devlink port of physical port, PCI PF and PCI VF flavour
for each PF, VF when a given devlink instance is in switchdev mode.

Implement ndo_get_devlink_port callback API to make use of registered
devlink ports.
This eliminates ndo_get_phys_port_name() and ndo_get_port_parent_id()
callbacks. Hence, remove them.

An example output with 2 VFs, without a PF and single uplink port is
below.

$devlink port show
pci/0000:06:00.0/65535: type eth netdev ens2f0 flavour physical
pci/0000:05:00.0/1: type eth netdev eth1 flavour pcivf pfnum 0 vfnum 0
pci/0000:05:00.0/2: type eth netdev eth2 flavour pcivf pfnum 0 vfnum 1

Reviewed-by: Roi Dayan <roid@mellanox.com>
Signed-off-by: Parav Pandit <parav@mellanox.com>
---
Changelog:
v1->v2:
 - Updated to use simpler API without port_number
---
 .../net/ethernet/mellanox/mlx5/core/en_rep.c  | 108 +++++++++++++-----
 .../net/ethernet/mellanox/mlx5/core/en_rep.h  |   1 +
 2 files changed, 78 insertions(+), 31 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_rep.c b/drivers/net/ethernet/mellanox/mlx5/core/en_rep.c
index 6a013a8c1150..ce50d8c9df03 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_rep.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_rep.c
@@ -37,6 +37,7 @@
 #include <net/act_api.h>
 #include <net/netevent.h>
 #include <net/arp.h>
+#include <net/devlink.h>
 
 #include "eswitch.h"
 #include "en.h"
@@ -1119,32 +1120,6 @@ static int mlx5e_rep_close(struct net_device *dev)
 	return ret;
 }
 
-static int mlx5e_rep_get_phys_port_name(struct net_device *dev,
-					char *buf, size_t len)
-{
-	struct mlx5e_priv *priv = netdev_priv(dev);
-	struct mlx5e_rep_priv *rpriv = priv->ppriv;
-	struct mlx5_eswitch_rep *rep = rpriv->rep;
-	unsigned int fn;
-	int ret;
-
-	fn = PCI_FUNC(priv->mdev->pdev->devfn);
-	if (fn >= MLX5_MAX_PORTS)
-		return -EOPNOTSUPP;
-
-	if (rep->vport == MLX5_VPORT_UPLINK)
-		ret = snprintf(buf, len, "p%d", fn);
-	else if (rep->vport == MLX5_VPORT_PF)
-		ret = snprintf(buf, len, "pf%d", fn);
-	else
-		ret = snprintf(buf, len, "pf%dvf%d", fn, rep->vport - 1);
-
-	if (ret >= len)
-		return -EOPNOTSUPP;
-
-	return 0;
-}
-
 static int
 mlx5e_rep_setup_tc_cls_flower(struct mlx5e_priv *priv,
 			      struct tc_cls_flower_offload *cls_flower, int flags)
@@ -1298,17 +1273,24 @@ static int mlx5e_uplink_rep_set_vf_vlan(struct net_device *dev, int vf, u16 vlan
 	return 0;
 }
 
+static struct devlink_port *mlx5e_get_devlink_port(struct net_device *dev)
+{
+	struct mlx5e_priv *priv = netdev_priv(dev);
+	struct mlx5e_rep_priv *rpriv = priv->ppriv;
+
+	return &rpriv->dl_port;
+}
+
 static const struct net_device_ops mlx5e_netdev_ops_rep = {
 	.ndo_open                = mlx5e_rep_open,
 	.ndo_stop                = mlx5e_rep_close,
 	.ndo_start_xmit          = mlx5e_xmit,
-	.ndo_get_phys_port_name  = mlx5e_rep_get_phys_port_name,
 	.ndo_setup_tc            = mlx5e_rep_setup_tc,
+	.ndo_get_devlink_port = mlx5e_get_devlink_port,
 	.ndo_get_stats64         = mlx5e_rep_get_stats,
 	.ndo_has_offload_stats	 = mlx5e_rep_has_offload_stats,
 	.ndo_get_offload_stats	 = mlx5e_rep_get_offload_stats,
 	.ndo_change_mtu          = mlx5e_rep_change_mtu,
-	.ndo_get_port_parent_id	 = mlx5e_rep_get_port_parent_id,
 };
 
 static const struct net_device_ops mlx5e_netdev_ops_uplink_rep = {
@@ -1316,8 +1298,8 @@ static const struct net_device_ops mlx5e_netdev_ops_uplink_rep = {
 	.ndo_stop                = mlx5e_close,
 	.ndo_start_xmit          = mlx5e_xmit,
 	.ndo_set_mac_address     = mlx5e_uplink_rep_set_mac,
-	.ndo_get_phys_port_name  = mlx5e_rep_get_phys_port_name,
 	.ndo_setup_tc            = mlx5e_rep_setup_tc,
+	.ndo_get_devlink_port = mlx5e_get_devlink_port,
 	.ndo_get_stats64         = mlx5e_get_stats,
 	.ndo_has_offload_stats	 = mlx5e_rep_has_offload_stats,
 	.ndo_get_offload_stats	 = mlx5e_rep_get_offload_stats,
@@ -1330,7 +1312,6 @@ static const struct net_device_ops mlx5e_netdev_ops_uplink_rep = {
 	.ndo_get_vf_config       = mlx5e_get_vf_config,
 	.ndo_get_vf_stats        = mlx5e_get_vf_stats,
 	.ndo_set_vf_vlan         = mlx5e_uplink_rep_set_vf_vlan,
-	.ndo_get_port_parent_id	 = mlx5e_rep_get_port_parent_id,
 	.ndo_set_features        = mlx5e_set_features,
 };
 
@@ -1731,6 +1712,55 @@ static const struct mlx5e_profile mlx5e_uplink_rep_profile = {
 	.max_tc			= MLX5E_MAX_NUM_TC,
 };
 
+static bool
+is_devlink_port_supported(const struct mlx5_core_dev *dev,
+			  const struct mlx5e_rep_priv *rpriv)
+{
+	return rpriv->rep->vport == MLX5_VPORT_UPLINK ||
+	       rpriv->rep->vport == MLX5_VPORT_PF ||
+	       mlx5_eswitch_is_vf_vport(dev->priv.eswitch, rpriv->rep->vport);
+}
+
+static int register_devlink_port(struct mlx5_core_dev *dev,
+				 struct mlx5e_rep_priv *rpriv)
+{
+	struct devlink *devlink = priv_to_devlink(dev);
+	struct mlx5_eswitch_rep *rep = rpriv->rep;
+	struct netdev_phys_item_id ppid = {};
+	int ret;
+
+	if (!is_devlink_port_supported(dev, rpriv))
+		return 0;
+
+	ret = mlx5e_rep_get_port_parent_id(rpriv->netdev, &ppid);
+	if (ret)
+		return ret;
+
+	if (rep->vport == MLX5_VPORT_UPLINK)
+		devlink_port_attrs_set(&rpriv->dl_port,
+				       DEVLINK_PORT_FLAVOUR_PHYSICAL,
+				       PCI_FUNC(dev->pdev->devfn), false, 0,
+				       &ppid.id[0], ppid.id_len);
+	else if (rep->vport == MLX5_VPORT_PF)
+		devlink_port_attrs_pci_pf_set(&rpriv->dl_port,
+					      &ppid.id[0], ppid.id_len,
+					      dev->pdev->devfn);
+	else if (mlx5_eswitch_is_vf_vport(dev->priv.eswitch, rpriv->rep->vport))
+		devlink_port_attrs_pci_vf_set(&rpriv->dl_port,
+					      &ppid.id[0], ppid.id_len,
+					      dev->pdev->devfn,
+					      rep->vport - 1);
+
+	return devlink_port_register(devlink, &rpriv->dl_port, rep->vport);
+}
+
+static void unregister_devlink_port(struct mlx5_core_dev *dev,
+				    struct mlx5e_rep_priv *rpriv)
+{
+	if (is_devlink_port_supported(dev, rpriv))
+		devlink_port_unregister(&rpriv->dl_port);
+}
+
 /* e-Switch vport representors */
 static int
 mlx5e_vport_rep_load(struct mlx5_core_dev *dev, struct mlx5_eswitch_rep *rep)
@@ -1782,15 +1812,27 @@ mlx5e_vport_rep_load(struct mlx5_core_dev *dev, struct mlx5_eswitch_rep *rep)
 		goto err_detach_netdev;
 	}
 
+	err = register_devlink_port(dev, rpriv);
+	if (err) {
+		esw_warn(dev, "Failed to register devlink port %d\n",
+			 rep->vport);
+		goto err_neigh_cleanup;
+	}
+
 	err = register_netdev(netdev);
 	if (err) {
 		pr_warn("Failed to register representor netdev for vport %d\n",
 			rep->vport);
-		goto err_neigh_cleanup;
+		goto err_devlink_cleanup;
 	}
 
+	if (is_devlink_port_supported(dev, rpriv))
+		devlink_port_type_eth_set(&rpriv->dl_port, netdev);
 	return 0;
 
+err_devlink_cleanup:
+	unregister_devlink_port(dev, rpriv);
+
 err_neigh_cleanup:
 	mlx5e_rep_neigh_cleanup(rpriv);
 
@@ -1813,9 +1855,13 @@ mlx5e_vport_rep_unload(struct mlx5_eswitch_rep *rep)
 	struct mlx5e_rep_priv *rpriv = mlx5e_rep_to_rep_priv(rep);
 	struct net_device *netdev = rpriv->netdev;
 	struct mlx5e_priv *priv = netdev_priv(netdev);
+	struct mlx5_core_dev *dev = priv->mdev;
 	void *ppriv = priv->ppriv;
 
+	if (is_devlink_port_supported(dev, rpriv))
+		devlink_port_type_clear(&rpriv->dl_port);
 	unregister_netdev(netdev);
+	unregister_devlink_port(dev, rpriv);
 	mlx5e_rep_neigh_cleanup(rpriv);
 	mlx5e_detach_netdev(priv);
 	if (rep->vport == MLX5_VPORT_UPLINK)
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_rep.h b/drivers/net/ethernet/mellanox/mlx5/core/en_rep.h
index d4585f3b8cb2..c56e6ee4350c 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_rep.h
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_rep.h
@@ -86,6 +86,7 @@ struct mlx5e_rep_priv {
 	struct mlx5_flow_handle *vport_rx_rule;
 	struct list_head       vport_sqs_list;
 	struct mlx5_rep_uplink_priv uplink_priv; /* valid for uplink rep */
+	struct devlink_port dl_port;
 };
 
 static inline
-- 
2.19.2


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

* Re: [PATCH net-next v2 1/3] devlink: Introduce PCI PF port flavour and port attribute
  2019-07-05  7:37   ` [PATCH net-next v2 1/3] devlink: Introduce PCI PF port flavour and port attribute Parav Pandit
@ 2019-07-05 19:17     ` Jakub Kicinski
  2019-07-06  6:12       ` Parav Pandit
  0 siblings, 1 reply; 71+ messages in thread
From: Jakub Kicinski @ 2019-07-05 19:17 UTC (permalink / raw)
  To: Parav Pandit; +Cc: netdev, jiri, saeedm

On Fri,  5 Jul 2019 02:37:09 -0500, Parav Pandit wrote:
> @@ -38,14 +38,24 @@ struct devlink {
>  	char priv[0] __aligned(NETDEV_ALIGN);
>  };
>  
> +struct devlink_port_pci_pf_attrs {
> +	u16 pf;	/* Associated PCI PF for this port. */
> +};
> +
>  struct devlink_port_attrs {
>  	u8 set:1,
>  	   split:1,
>  	   switch_port:1;
>  	enum devlink_port_flavour flavour;
> -	u32 port_number; /* same value as "split group" */
> +	u32 port_number; /* same value as "split group".
> +			  * Valid only when a port is physical and visible
> +			  * to the user for a given port flavour.
> +			  */

port_number can be in the per-flavour union below.

>  	u32 split_subport_number;

As can split_subport_number.

>  	struct netdev_phys_item_id switch_id;
> +	union {
> +		struct devlink_port_pci_pf_attrs pci_pf;
> +	};
>  };
>  
>  struct devlink_port {

> @@ -515,8 +523,14 @@ static int devlink_nl_port_attrs_put(struct sk_buff *msg,
>  		return 0;
>  	if (nla_put_u16(msg, DEVLINK_ATTR_PORT_FLAVOUR, attrs->flavour))
>  		return -EMSGSIZE;
> -	if (nla_put_u32(msg, DEVLINK_ATTR_PORT_NUMBER, attrs->port_number))
> +	if (is_devlink_phy_port_num_supported(devlink_port) &&
> +	    nla_put_u32(msg, DEVLINK_ATTR_PORT_NUMBER, attrs->port_number))
>  		return -EMSGSIZE;
> +	if (devlink_port->attrs.flavour == DEVLINK_PORT_FLAVOUR_PCI_PF) {
> +		if (nla_put_u16(msg, DEVLINK_ATTR_PORT_PCI_PF_NUMBER,
> +				attrs->pci_pf.pf))
> +			return -EMSGSIZE;
> +	}
>  	if (!attrs->split)
>  		return 0;
>  	if (nla_put_u32(msg, DEVLINK_ATTR_PORT_SPLIT_GROUP, attrs->port_number))

Split attributes as well, please:

On Tue, 2 Jul 2019 16:42:52 -0700, Jakub Kicinski wrote:
> port_number, and split attributes should not be exposed for PCI ports.

We have no clear semantics for those, yet, and the phys_port_name
implementation in this patch doesn't handle split PCI, so let's leave
them out for now.

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

* RE: [PATCH net-next v2 1/3] devlink: Introduce PCI PF port flavour and port attribute
  2019-07-05 19:17     ` Jakub Kicinski
@ 2019-07-06  6:12       ` Parav Pandit
  0 siblings, 0 replies; 71+ messages in thread
From: Parav Pandit @ 2019-07-06  6:12 UTC (permalink / raw)
  To: Jakub Kicinski; +Cc: netdev, Jiri Pirko, Saeed Mahameed



> -----Original Message-----
> From: Jakub Kicinski <jakub.kicinski@netronome.com>
> Sent: Saturday, July 6, 2019 12:47 AM
> To: Parav Pandit <parav@mellanox.com>
> Cc: netdev@vger.kernel.org; Jiri Pirko <jiri@mellanox.com>; Saeed Mahameed
> <saeedm@mellanox.com>
> Subject: Re: [PATCH net-next v2 1/3] devlink: Introduce PCI PF port flavour and
> port attribute
> 
> On Fri,  5 Jul 2019 02:37:09 -0500, Parav Pandit wrote:
> > @@ -38,14 +38,24 @@ struct devlink {
> >  	char priv[0] __aligned(NETDEV_ALIGN);  };
> >
> > +struct devlink_port_pci_pf_attrs {
> > +	u16 pf;	/* Associated PCI PF for this port. */
> > +};
> > +
> >  struct devlink_port_attrs {
> >  	u8 set:1,
> >  	   split:1,
> >  	   switch_port:1;
> >  	enum devlink_port_flavour flavour;
> > -	u32 port_number; /* same value as "split group" */
> > +	u32 port_number; /* same value as "split group".
> > +			  * Valid only when a port is physical and visible
> > +			  * to the user for a given port flavour.
> > +			  */
> 
> port_number can be in the per-flavour union below.
> 
Ack.
> >  	u32 split_subport_number;
> 
> As can split_subport_number.
> 
Ack.

> >  	struct netdev_phys_item_id switch_id;
> > +	union {
> > +		struct devlink_port_pci_pf_attrs pci_pf;
> > +	};
> >  };
> >
> >  struct devlink_port {
> 
> > @@ -515,8 +523,14 @@ static int devlink_nl_port_attrs_put(struct sk_buff
> *msg,
> >  		return 0;
> >  	if (nla_put_u16(msg, DEVLINK_ATTR_PORT_FLAVOUR, attrs->flavour))
> >  		return -EMSGSIZE;
> > -	if (nla_put_u32(msg, DEVLINK_ATTR_PORT_NUMBER, attrs-
> >port_number))
> > +	if (is_devlink_phy_port_num_supported(devlink_port) &&
> > +	    nla_put_u32(msg, DEVLINK_ATTR_PORT_NUMBER, attrs-
> >port_number))
> >  		return -EMSGSIZE;
> > +	if (devlink_port->attrs.flavour == DEVLINK_PORT_FLAVOUR_PCI_PF) {
> > +		if (nla_put_u16(msg, DEVLINK_ATTR_PORT_PCI_PF_NUMBER,
> > +				attrs->pci_pf.pf))
> > +			return -EMSGSIZE;
> > +	}
> >  	if (!attrs->split)
> >  		return 0;
> >  	if (nla_put_u32(msg, DEVLINK_ATTR_PORT_SPLIT_GROUP,
> > attrs->port_number))
> 
> Split attributes as well, please:
> 
Ack.
> On Tue, 2 Jul 2019 16:42:52 -0700, Jakub Kicinski wrote:
> > port_number, and split attributes should not be exposed for PCI ports.
> 
> We have no clear semantics for those, yet, and the phys_port_name
> implementation in this patch doesn't handle split PCI, so let's leave them out
> for now.
Ok. Sending v3.
Thanks for the review.

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

* [PATCH net-next v3 0/3] devlink: Introduce PCI PF, VF ports and attributes
  2019-07-01 12:27 [PATCH net-next 0/3] devlink: Introduce PCI PF, VF ports and attributes Parav Pandit
                   ` (5 preceding siblings ...)
  2019-07-05  7:37 ` [PATCH net-next v2 0/3] devlink: Introduce PCI PF, VF ports and attributes Parav Pandit
@ 2019-07-06  6:16 ` Parav Pandit
  2019-07-06  6:16   ` [PATCH net-next v3 1/3] devlink: Introduce PCI PF port flavour and port attribute Parav Pandit
                     ` (2 more replies)
  2019-07-06 18:23 ` [PATCH net-next v4 0/4] devlink: Introduce PCI PF, VF ports and attributes Parav Pandit
                   ` (2 subsequent siblings)
  9 siblings, 3 replies; 71+ messages in thread
From: Parav Pandit @ 2019-07-06  6:16 UTC (permalink / raw)
  To: netdev; +Cc: jiri, saeedm, jakub.kicinski, Parav Pandit

This patchset carry forwards the work initiated in [1] and discussion
futher concluded at [2].

To improve visibility of representor netdevice, its association with
PF or VF, physical port, two new devlink port flavours are added as
PCI PF and PCI VF ports.

A sample eswitch view can be seen below, which will be futher extended to
mdev subdevices of a PCI function in future.

Patch-1,2 extends devlink port attributes and port flavour.
Patch-3 extends mlx5 driver to register devlink ports for PF, VF and
physical link.

                                +---+      +---+
                              vf|   |      |   | pf
                                +-+-+      +-+-+
physical link <---------+         |          |
                        |         |          |
                        |         |          |
                      +-+-+     +-+-+      +-+-+
                      | 1 |     | 2 |      | 3 |
                   +--+---+-----+---+------+---+--+
                   |  physical   vf         pf    |
                   |  port       port       port  |
                   |                              |
                   |             eswitch          |
                   |                              |
                   +------------------------------+

[1] https://www.spinics.net/lists/netdev/msg555797.html
[2] https://marc.info/?l=linux-netdev&m=155354609408485&w=2

---
Changelog:
v2->v3:
 - Made port_number and split_port_number applicable only to
   physical port flavours.
v1->v2:
 - Updated new APIs and mlx5 driver to drop port_number for PF, VF
   attributes
 - Updated port_number comment for its usage
 - Limited putting port_number to physical ports


Parav Pandit (3):
  devlink: Introduce PCI PF port flavour and port attribute
  devlink: Introduce PCI VF port flavour and port attribute
  net/mlx5e: Register devlink ports for physical link, PCI PF, VFs

 .../net/ethernet/mellanox/mlx5/core/en_rep.c  | 108 ++++++++++-----
 .../net/ethernet/mellanox/mlx5/core/en_rep.h  |   1 +
 include/net/devlink.h                         |  31 ++++-
 include/uapi/linux/devlink.h                  |  11 ++
 net/core/devlink.c                            | 131 +++++++++++++++---
 5 files changed, 228 insertions(+), 54 deletions(-)

-- 
2.19.2


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

* [PATCH net-next v3 1/3] devlink: Introduce PCI PF port flavour and port attribute
  2019-07-06  6:16 ` [PATCH net-next v3 0/3] devlink: Introduce PCI PF, VF ports and attributes Parav Pandit
@ 2019-07-06  6:16   ` Parav Pandit
  2019-07-06  6:26     ` Jiri Pirko
  2019-07-06  6:16   ` [PATCH net-next v3 2/3] devlink: Introduce PCI VF " Parav Pandit
  2019-07-06  6:16   ` [PATCH net-next v3 3/3] net/mlx5e: Register devlink ports for physical link, PCI PF, VFs Parav Pandit
  2 siblings, 1 reply; 71+ messages in thread
From: Parav Pandit @ 2019-07-06  6:16 UTC (permalink / raw)
  To: netdev; +Cc: jiri, saeedm, jakub.kicinski, Parav Pandit

In an eswitch, PCI PF may have port which is normally represented
using a representor netdevice.
To have better visibility of eswitch port, its association with
PF and a representor netdevice, introduce a PCI PF port
flavour and port attriute.

When devlink port flavour is PCI PF, fill up PCI PF attributes of the
port.

Extend port name creation using PCI PF number on best effort basis.
So that vendor drivers can skip defining their own scheme.

$ devlink port show
pci/0000:05:00.0/0: type eth netdev eth0 flavour pcipf pfnum 0

Signed-off-by: Parav Pandit <parav@mellanox.com>

---
Changelog:
v2->v3:
 - Address comments from Jakub.
 - Made port_number and split_port_number applicable only to
   physical port flavours by having in union.
v1->v2:
 - Limited port_num attribute to physical ports
 - Updated PCI PF attribute set API to not have port_number
---
 include/net/devlink.h        | 21 +++++++-
 include/uapi/linux/devlink.h |  5 ++
 net/core/devlink.c           | 97 ++++++++++++++++++++++++++++--------
 3 files changed, 100 insertions(+), 23 deletions(-)

diff --git a/include/net/devlink.h b/include/net/devlink.h
index 6625ea068d5e..1455f60e4069 100644
--- a/include/net/devlink.h
+++ b/include/net/devlink.h
@@ -38,13 +38,27 @@ struct devlink {
 	char priv[0] __aligned(NETDEV_ALIGN);
 };
 
+struct devlink_port_phys_attrs {
+	u32 port_number; /* same value as "split group".
+			  * A physical port which is visible to the user
+			  * for a given port flavour.
+			  */
+	u32 split_subport_number;
+};
+
+struct devlink_port_pci_pf_attrs {
+	u16 pf;	/* Associated PCI PF for this port. */
+};
+
 struct devlink_port_attrs {
 	u8 set:1,
 	   split:1,
 	   switch_port:1;
 	enum devlink_port_flavour flavour;
-	u32 port_number; /* same value as "split group" */
-	u32 split_subport_number;
+	union {
+		struct devlink_port_phys_attrs phys_port;
+		struct devlink_port_pci_pf_attrs pci_pf;
+	};
 	struct netdev_phys_item_id switch_id;
 };
 
@@ -590,6 +604,9 @@ void devlink_port_attrs_set(struct devlink_port *devlink_port,
 			    u32 split_subport_number,
 			    const unsigned char *switch_id,
 			    unsigned char switch_id_len);
+void devlink_port_attrs_pci_pf_set(struct devlink_port *devlink_port,
+				   const unsigned char *switch_id,
+				   unsigned char switch_id_len, u16 pf);
 int devlink_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/include/uapi/linux/devlink.h b/include/uapi/linux/devlink.h
index 5287b42c181f..f7323884c3fe 100644
--- a/include/uapi/linux/devlink.h
+++ b/include/uapi/linux/devlink.h
@@ -169,6 +169,10 @@ enum devlink_port_flavour {
 	DEVLINK_PORT_FLAVOUR_DSA, /* Distributed switch architecture
 				   * interconnect port.
 				   */
+	DEVLINK_PORT_FLAVOUR_PCI_PF, /* Represents eswitch port for
+				      * the PCI PF. It is an internal
+				      * port that faces the PCI PF.
+				      */
 };
 
 enum devlink_param_cmode {
@@ -337,6 +341,7 @@ enum devlink_attr {
 	DEVLINK_ATTR_FLASH_UPDATE_STATUS_DONE,	/* u64 */
 	DEVLINK_ATTR_FLASH_UPDATE_STATUS_TOTAL,	/* u64 */
 
+	DEVLINK_ATTR_PORT_PCI_PF_NUMBER,	/* u16 */
 	/* add new attributes above here, update the policy in devlink.c */
 
 	__DEVLINK_ATTR_MAX,
diff --git a/net/core/devlink.c b/net/core/devlink.c
index 89c533778135..9aa36104b471 100644
--- a/net/core/devlink.c
+++ b/net/core/devlink.c
@@ -506,6 +506,14 @@ static void devlink_notify(struct devlink *devlink, enum devlink_command cmd)
 				msg, 0, DEVLINK_MCGRP_CONFIG, GFP_KERNEL);
 }
 
+static bool
+is_devlink_phy_port_num_supported(const struct devlink_port *dl_port)
+{
+	return (dl_port->attrs.flavour == DEVLINK_PORT_FLAVOUR_PHYSICAL ||
+		dl_port->attrs.flavour == DEVLINK_PORT_FLAVOUR_CPU ||
+		dl_port->attrs.flavour == DEVLINK_PORT_FLAVOUR_DSA);
+}
+
 static int devlink_nl_port_attrs_put(struct sk_buff *msg,
 				     struct devlink_port *devlink_port)
 {
@@ -515,14 +523,23 @@ static int devlink_nl_port_attrs_put(struct sk_buff *msg,
 		return 0;
 	if (nla_put_u16(msg, DEVLINK_ATTR_PORT_FLAVOUR, attrs->flavour))
 		return -EMSGSIZE;
-	if (nla_put_u32(msg, DEVLINK_ATTR_PORT_NUMBER, attrs->port_number))
+	if (devlink_port->attrs.flavour == DEVLINK_PORT_FLAVOUR_PCI_PF) {
+		if (nla_put_u16(msg, DEVLINK_ATTR_PORT_PCI_PF_NUMBER,
+				attrs->pci_pf.pf))
+			return -EMSGSIZE;
+	}
+	if (!is_devlink_phy_port_num_supported(devlink_port))
+		return 0;
+	if (nla_put_u32(msg, DEVLINK_ATTR_PORT_NUMBER,
+			attrs->phys_port.port_number))
 		return -EMSGSIZE;
 	if (!attrs->split)
 		return 0;
-	if (nla_put_u32(msg, DEVLINK_ATTR_PORT_SPLIT_GROUP, attrs->port_number))
+	if (nla_put_u32(msg, DEVLINK_ATTR_PORT_SPLIT_GROUP,
+			attrs->phys_port.port_number))
 		return -EMSGSIZE;
 	if (nla_put_u32(msg, DEVLINK_ATTR_PORT_SPLIT_SUBPORT_NUMBER,
-			attrs->split_subport_number))
+			attrs->phys_port.split_subport_number))
 		return -EMSGSIZE;
 	return 0;
 }
@@ -5738,6 +5755,30 @@ void devlink_port_type_clear(struct devlink_port *devlink_port)
 }
 EXPORT_SYMBOL_GPL(devlink_port_type_clear);
 
+static void __devlink_port_attrs_set(struct devlink_port *devlink_port,
+				     enum devlink_port_flavour flavour,
+				     u32 port_number,
+				     const unsigned char *switch_id,
+				     unsigned char switch_id_len)
+{
+	struct devlink_port_attrs *attrs = &devlink_port->attrs;
+
+	if (WARN_ON(devlink_port->registered))
+		return;
+	attrs->set = true;
+	attrs->flavour = flavour;
+	attrs->phys_port.port_number = port_number;
+	if (switch_id) {
+		attrs->switch_port = true;
+		if (WARN_ON(switch_id_len > MAX_PHYS_ITEM_ID_LEN))
+			switch_id_len = MAX_PHYS_ITEM_ID_LEN;
+		memcpy(attrs->switch_id.id, switch_id, switch_id_len);
+		attrs->switch_id.id_len = switch_id_len;
+	} else {
+		attrs->switch_port = false;
+	}
+}
+
 /**
  *	devlink_port_attrs_set - Set port attributes
  *
@@ -5761,25 +5802,34 @@ void devlink_port_attrs_set(struct devlink_port *devlink_port,
 {
 	struct devlink_port_attrs *attrs = &devlink_port->attrs;
 
-	if (WARN_ON(devlink_port->registered))
-		return;
-	attrs->set = true;
-	attrs->flavour = flavour;
-	attrs->port_number = port_number;
+	__devlink_port_attrs_set(devlink_port, flavour, port_number,
+				 switch_id, switch_id_len);
 	attrs->split = split;
-	attrs->split_subport_number = split_subport_number;
-	if (switch_id) {
-		attrs->switch_port = true;
-		if (WARN_ON(switch_id_len > MAX_PHYS_ITEM_ID_LEN))
-			switch_id_len = MAX_PHYS_ITEM_ID_LEN;
-		memcpy(attrs->switch_id.id, switch_id, switch_id_len);
-		attrs->switch_id.id_len = switch_id_len;
-	} else {
-		attrs->switch_port = false;
-	}
+	attrs->phys_port.split_subport_number = split_subport_number;
 }
 EXPORT_SYMBOL_GPL(devlink_port_attrs_set);
 
+/**
+ *	devlink_port_attrs_pci_pf_set - Set PCI PF port attributes
+ *
+ *	@devlink_port: devlink port
+ *	@pf: associated PF for the devlink port instance
+ *	@switch_id: if the port is part of switch, this is buffer with ID,
+ *	            otwerwise this is NULL
+ *	@switch_id_len: length of the switch_id buffer
+ */
+void devlink_port_attrs_pci_pf_set(struct devlink_port *devlink_port,
+				   const unsigned char *switch_id,
+				   unsigned char switch_id_len, u16 pf)
+{
+	struct devlink_port_attrs *attrs = &devlink_port->attrs;
+
+	__devlink_port_attrs_set(devlink_port, DEVLINK_PORT_FLAVOUR_PCI_PF,
+				 0, switch_id, switch_id_len);
+	attrs->pci_pf.pf = pf;
+}
+EXPORT_SYMBOL_GPL(devlink_port_attrs_pci_pf_set);
+
 static int __devlink_port_phys_port_name_get(struct devlink_port *devlink_port,
 					     char *name, size_t len)
 {
@@ -5792,10 +5842,12 @@ static int __devlink_port_phys_port_name_get(struct devlink_port *devlink_port,
 	switch (attrs->flavour) {
 	case DEVLINK_PORT_FLAVOUR_PHYSICAL:
 		if (!attrs->split)
-			n = snprintf(name, len, "p%u", attrs->port_number);
+			n = snprintf(name, len, "p%u",
+				     attrs->phys_port.port_number);
 		else
-			n = snprintf(name, len, "p%us%u", attrs->port_number,
-				     attrs->split_subport_number);
+			n = snprintf(name, len, "p%us%u",
+				     attrs->phys_port.port_number,
+				     attrs->phys_port.split_subport_number);
 		break;
 	case DEVLINK_PORT_FLAVOUR_CPU:
 	case DEVLINK_PORT_FLAVOUR_DSA:
@@ -5804,6 +5856,9 @@ static int __devlink_port_phys_port_name_get(struct devlink_port *devlink_port,
 		 */
 		WARN_ON(1);
 		return -EINVAL;
+	case DEVLINK_PORT_FLAVOUR_PCI_PF:
+		n = snprintf(name, len, "pf%u", attrs->pci_pf.pf);
+		break;
 	}
 
 	if (n >= len)
-- 
2.19.2


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

* [PATCH net-next v3 2/3] devlink: Introduce PCI VF port flavour and port attribute
  2019-07-06  6:16 ` [PATCH net-next v3 0/3] devlink: Introduce PCI PF, VF ports and attributes Parav Pandit
  2019-07-06  6:16   ` [PATCH net-next v3 1/3] devlink: Introduce PCI PF port flavour and port attribute Parav Pandit
@ 2019-07-06  6:16   ` Parav Pandit
  2019-07-06  6:16   ` [PATCH net-next v3 3/3] net/mlx5e: Register devlink ports for physical link, PCI PF, VFs Parav Pandit
  2 siblings, 0 replies; 71+ messages in thread
From: Parav Pandit @ 2019-07-06  6:16 UTC (permalink / raw)
  To: netdev; +Cc: jiri, saeedm, jakub.kicinski, Parav Pandit

In an eswitch, PCI VF may have port which is normally represented using
a representor netdevice.
To have better visibility of eswitch port, its association with VF,
and its representor netdevice, introduce a PCI VF port flavour.

When devlink port flavour is PCI VF, fill up PCI VF attributes of
the port.

Extend port name creation using PCI PF and VF number scheme on best
effort basis, so that vendor drivers can skip defining their own scheme.

$ devlink port show
pci/0000:05:00.0/0: type eth netdev eth0 flavour pcipf pfnum 0
pci/0000:05:00.0/1: type eth netdev eth1 flavour pcivf pfnum 0 vfnum 0
pci/0000:05:00.0/2: type eth netdev eth2 flavour pcivf pfnum 0 vfnum 1

Signed-off-by: Parav Pandit <parav@mellanox.com>
---
 include/net/devlink.h        | 10 ++++++++++
 include/uapi/linux/devlink.h |  6 ++++++
 net/core/devlink.c           | 34 ++++++++++++++++++++++++++++++++++
 3 files changed, 50 insertions(+)

diff --git a/include/net/devlink.h b/include/net/devlink.h
index 1455f60e4069..6c46d8300d6c 100644
--- a/include/net/devlink.h
+++ b/include/net/devlink.h
@@ -50,6 +50,11 @@ struct devlink_port_pci_pf_attrs {
 	u16 pf;	/* Associated PCI PF for this port. */
 };
 
+struct devlink_port_pci_vf_attrs {
+	u16 pf;	/* Associated PCI PF for this port. */
+	u16 vf;	/* Associated PCI VF for of the PCI PF for this port. */
+};
+
 struct devlink_port_attrs {
 	u8 set:1,
 	   split:1,
@@ -58,6 +63,7 @@ struct devlink_port_attrs {
 	union {
 		struct devlink_port_phys_attrs phys_port;
 		struct devlink_port_pci_pf_attrs pci_pf;
+		struct devlink_port_pci_vf_attrs pci_vf;
 	};
 	struct netdev_phys_item_id switch_id;
 };
@@ -607,6 +613,10 @@ void devlink_port_attrs_set(struct devlink_port *devlink_port,
 void devlink_port_attrs_pci_pf_set(struct devlink_port *devlink_port,
 				   const unsigned char *switch_id,
 				   unsigned char switch_id_len, u16 pf);
+void devlink_port_attrs_pci_vf_set(struct devlink_port *devlink_port,
+				   const unsigned char *switch_id,
+				   unsigned char switch_id_len,
+				   u16 pf, u16 vf);
 int devlink_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/include/uapi/linux/devlink.h b/include/uapi/linux/devlink.h
index f7323884c3fe..ffc993256527 100644
--- a/include/uapi/linux/devlink.h
+++ b/include/uapi/linux/devlink.h
@@ -173,6 +173,10 @@ enum devlink_port_flavour {
 				      * the PCI PF. It is an internal
 				      * port that faces the PCI PF.
 				      */
+	DEVLINK_PORT_FLAVOUR_PCI_VF, /* Represents eswitch port
+				      * for the PCI VF. It is an internal
+				      * port that faces the PCI VF.
+				      */
 };
 
 enum devlink_param_cmode {
@@ -342,6 +346,8 @@ enum devlink_attr {
 	DEVLINK_ATTR_FLASH_UPDATE_STATUS_TOTAL,	/* u64 */
 
 	DEVLINK_ATTR_PORT_PCI_PF_NUMBER,	/* u16 */
+	DEVLINK_ATTR_PORT_PCI_VF_NUMBER,	/* u16 */
+
 	/* add new attributes above here, update the policy in devlink.c */
 
 	__DEVLINK_ATTR_MAX,
diff --git a/net/core/devlink.c b/net/core/devlink.c
index 9aa36104b471..57d4722c3e73 100644
--- a/net/core/devlink.c
+++ b/net/core/devlink.c
@@ -527,6 +527,12 @@ static int devlink_nl_port_attrs_put(struct sk_buff *msg,
 		if (nla_put_u16(msg, DEVLINK_ATTR_PORT_PCI_PF_NUMBER,
 				attrs->pci_pf.pf))
 			return -EMSGSIZE;
+	} else if (devlink_port->attrs.flavour == DEVLINK_PORT_FLAVOUR_PCI_VF) {
+		if (nla_put_u16(msg, DEVLINK_ATTR_PORT_PCI_PF_NUMBER,
+				attrs->pci_vf.pf) ||
+		    nla_put_u16(msg, DEVLINK_ATTR_PORT_PCI_VF_NUMBER,
+				attrs->pci_vf.vf))
+			return -EMSGSIZE;
 	}
 	if (!is_devlink_phy_port_num_supported(devlink_port))
 		return 0;
@@ -5830,6 +5836,30 @@ void devlink_port_attrs_pci_pf_set(struct devlink_port *devlink_port,
 }
 EXPORT_SYMBOL_GPL(devlink_port_attrs_pci_pf_set);
 
+/**
+ *	devlink_port_attrs_pci_vf_set - Set PCI VF port attributes
+ *
+ *	@devlink_port: devlink port
+ *	@pf: associated PF for the devlink port instance
+ *	@vf: associated VF of a PF for the devlink port instance
+ *	@switch_id: if the port is part of switch, this is buffer with ID,
+ *	            otwerwise this is NULL
+ *	@switch_id_len: length of the switch_id buffer
+ */
+void devlink_port_attrs_pci_vf_set(struct devlink_port *devlink_port,
+				   const unsigned char *switch_id,
+				   unsigned char switch_id_len,
+				   u16 pf, u16 vf)
+{
+	struct devlink_port_attrs *attrs = &devlink_port->attrs;
+
+	__devlink_port_attrs_set(devlink_port, DEVLINK_PORT_FLAVOUR_PCI_VF,
+				 0, switch_id, switch_id_len);
+	attrs->pci_vf.pf = pf;
+	attrs->pci_vf.vf = vf;
+}
+EXPORT_SYMBOL_GPL(devlink_port_attrs_pci_vf_set);
+
 static int __devlink_port_phys_port_name_get(struct devlink_port *devlink_port,
 					     char *name, size_t len)
 {
@@ -5859,6 +5889,10 @@ static int __devlink_port_phys_port_name_get(struct devlink_port *devlink_port,
 	case DEVLINK_PORT_FLAVOUR_PCI_PF:
 		n = snprintf(name, len, "pf%u", attrs->pci_pf.pf);
 		break;
+	case DEVLINK_PORT_FLAVOUR_PCI_VF:
+		n = snprintf(name, len, "pf%uvf%u",
+			     attrs->pci_vf.pf, attrs->pci_vf.vf);
+		break;
 	}
 
 	if (n >= len)
-- 
2.19.2


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

* [PATCH net-next v3 3/3] net/mlx5e: Register devlink ports for physical link, PCI PF, VFs
  2019-07-06  6:16 ` [PATCH net-next v3 0/3] devlink: Introduce PCI PF, VF ports and attributes Parav Pandit
  2019-07-06  6:16   ` [PATCH net-next v3 1/3] devlink: Introduce PCI PF port flavour and port attribute Parav Pandit
  2019-07-06  6:16   ` [PATCH net-next v3 2/3] devlink: Introduce PCI VF " Parav Pandit
@ 2019-07-06  6:16   ` Parav Pandit
  2 siblings, 0 replies; 71+ messages in thread
From: Parav Pandit @ 2019-07-06  6:16 UTC (permalink / raw)
  To: netdev; +Cc: jiri, saeedm, jakub.kicinski, Parav Pandit

Register devlink port of physical port, PCI PF and PCI VF flavour
for each PF, VF when a given devlink instance is in switchdev mode.

Implement ndo_get_devlink_port callback API to make use of registered
devlink ports.
This eliminates ndo_get_phys_port_name() and ndo_get_port_parent_id()
callbacks. Hence, remove them.

An example output with 2 VFs, without a PF and single uplink port is
below.

$devlink port show
pci/0000:06:00.0/65535: type eth netdev ens2f0 flavour physical
pci/0000:05:00.0/1: type eth netdev eth1 flavour pcivf pfnum 0 vfnum 0
pci/0000:05:00.0/2: type eth netdev eth2 flavour pcivf pfnum 0 vfnum 1

Reviewed-by: Roi Dayan <roid@mellanox.com>
Signed-off-by: Parav Pandit <parav@mellanox.com>
---
 .../net/ethernet/mellanox/mlx5/core/en_rep.c  | 108 +++++++++++++-----
 .../net/ethernet/mellanox/mlx5/core/en_rep.h  |   1 +
 2 files changed, 78 insertions(+), 31 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_rep.c b/drivers/net/ethernet/mellanox/mlx5/core/en_rep.c
index 529f8e4b32c6..6810b9fa0705 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_rep.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_rep.c
@@ -37,6 +37,7 @@
 #include <net/act_api.h>
 #include <net/netevent.h>
 #include <net/arp.h>
+#include <net/devlink.h>
 
 #include "eswitch.h"
 #include "en.h"
@@ -1119,32 +1120,6 @@ static int mlx5e_rep_close(struct net_device *dev)
 	return ret;
 }
 
-static int mlx5e_rep_get_phys_port_name(struct net_device *dev,
-					char *buf, size_t len)
-{
-	struct mlx5e_priv *priv = netdev_priv(dev);
-	struct mlx5e_rep_priv *rpriv = priv->ppriv;
-	struct mlx5_eswitch_rep *rep = rpriv->rep;
-	unsigned int fn;
-	int ret;
-
-	fn = PCI_FUNC(priv->mdev->pdev->devfn);
-	if (fn >= MLX5_MAX_PORTS)
-		return -EOPNOTSUPP;
-
-	if (rep->vport == MLX5_VPORT_UPLINK)
-		ret = snprintf(buf, len, "p%d", fn);
-	else if (rep->vport == MLX5_VPORT_PF)
-		ret = snprintf(buf, len, "pf%d", fn);
-	else
-		ret = snprintf(buf, len, "pf%dvf%d", fn, rep->vport - 1);
-
-	if (ret >= len)
-		return -EOPNOTSUPP;
-
-	return 0;
-}
-
 static int
 mlx5e_rep_setup_tc_cls_flower(struct mlx5e_priv *priv,
 			      struct tc_cls_flower_offload *cls_flower, int flags)
@@ -1298,17 +1273,24 @@ static int mlx5e_uplink_rep_set_vf_vlan(struct net_device *dev, int vf, u16 vlan
 	return 0;
 }
 
+static struct devlink_port *mlx5e_get_devlink_port(struct net_device *dev)
+{
+	struct mlx5e_priv *priv = netdev_priv(dev);
+	struct mlx5e_rep_priv *rpriv = priv->ppriv;
+
+	return &rpriv->dl_port;
+}
+
 static const struct net_device_ops mlx5e_netdev_ops_rep = {
 	.ndo_open                = mlx5e_rep_open,
 	.ndo_stop                = mlx5e_rep_close,
 	.ndo_start_xmit          = mlx5e_xmit,
-	.ndo_get_phys_port_name  = mlx5e_rep_get_phys_port_name,
 	.ndo_setup_tc            = mlx5e_rep_setup_tc,
+	.ndo_get_devlink_port = mlx5e_get_devlink_port,
 	.ndo_get_stats64         = mlx5e_rep_get_stats,
 	.ndo_has_offload_stats	 = mlx5e_rep_has_offload_stats,
 	.ndo_get_offload_stats	 = mlx5e_rep_get_offload_stats,
 	.ndo_change_mtu          = mlx5e_rep_change_mtu,
-	.ndo_get_port_parent_id	 = mlx5e_rep_get_port_parent_id,
 };
 
 static const struct net_device_ops mlx5e_netdev_ops_uplink_rep = {
@@ -1316,8 +1298,8 @@ static const struct net_device_ops mlx5e_netdev_ops_uplink_rep = {
 	.ndo_stop                = mlx5e_close,
 	.ndo_start_xmit          = mlx5e_xmit,
 	.ndo_set_mac_address     = mlx5e_uplink_rep_set_mac,
-	.ndo_get_phys_port_name  = mlx5e_rep_get_phys_port_name,
 	.ndo_setup_tc            = mlx5e_rep_setup_tc,
+	.ndo_get_devlink_port = mlx5e_get_devlink_port,
 	.ndo_get_stats64         = mlx5e_get_stats,
 	.ndo_has_offload_stats	 = mlx5e_rep_has_offload_stats,
 	.ndo_get_offload_stats	 = mlx5e_rep_get_offload_stats,
@@ -1330,7 +1312,6 @@ static const struct net_device_ops mlx5e_netdev_ops_uplink_rep = {
 	.ndo_get_vf_config       = mlx5e_get_vf_config,
 	.ndo_get_vf_stats        = mlx5e_get_vf_stats,
 	.ndo_set_vf_vlan         = mlx5e_uplink_rep_set_vf_vlan,
-	.ndo_get_port_parent_id	 = mlx5e_rep_get_port_parent_id,
 	.ndo_set_features        = mlx5e_set_features,
 };
 
@@ -1731,6 +1712,55 @@ static const struct mlx5e_profile mlx5e_uplink_rep_profile = {
 	.max_tc			= MLX5E_MAX_NUM_TC,
 };
 
+static bool
+is_devlink_port_supported(const struct mlx5_core_dev *dev,
+			  const struct mlx5e_rep_priv *rpriv)
+{
+	return rpriv->rep->vport == MLX5_VPORT_UPLINK ||
+	       rpriv->rep->vport == MLX5_VPORT_PF ||
+	       mlx5_eswitch_is_vf_vport(dev->priv.eswitch, rpriv->rep->vport);
+}
+
+static int register_devlink_port(struct mlx5_core_dev *dev,
+				 struct mlx5e_rep_priv *rpriv)
+{
+	struct devlink *devlink = priv_to_devlink(dev);
+	struct mlx5_eswitch_rep *rep = rpriv->rep;
+	struct netdev_phys_item_id ppid = {};
+	int ret;
+
+	if (!is_devlink_port_supported(dev, rpriv))
+		return 0;
+
+	ret = mlx5e_rep_get_port_parent_id(rpriv->netdev, &ppid);
+	if (ret)
+		return ret;
+
+	if (rep->vport == MLX5_VPORT_UPLINK)
+		devlink_port_attrs_set(&rpriv->dl_port,
+				       DEVLINK_PORT_FLAVOUR_PHYSICAL,
+				       PCI_FUNC(dev->pdev->devfn), false, 0,
+				       &ppid.id[0], ppid.id_len);
+	else if (rep->vport == MLX5_VPORT_PF)
+		devlink_port_attrs_pci_pf_set(&rpriv->dl_port,
+					      &ppid.id[0], ppid.id_len,
+					      dev->pdev->devfn);
+	else if (mlx5_eswitch_is_vf_vport(dev->priv.eswitch, rpriv->rep->vport))
+		devlink_port_attrs_pci_vf_set(&rpriv->dl_port,
+					      &ppid.id[0], ppid.id_len,
+					      dev->pdev->devfn,
+					      rep->vport - 1);
+
+	return devlink_port_register(devlink, &rpriv->dl_port, rep->vport);
+}
+
+static void unregister_devlink_port(struct mlx5_core_dev *dev,
+				    struct mlx5e_rep_priv *rpriv)
+{
+	if (is_devlink_port_supported(dev, rpriv))
+		devlink_port_unregister(&rpriv->dl_port);
+}
+
 /* e-Switch vport representors */
 static int
 mlx5e_vport_rep_load(struct mlx5_core_dev *dev, struct mlx5_eswitch_rep *rep)
@@ -1782,15 +1812,27 @@ mlx5e_vport_rep_load(struct mlx5_core_dev *dev, struct mlx5_eswitch_rep *rep)
 		goto err_detach_netdev;
 	}
 
+	err = register_devlink_port(dev, rpriv);
+	if (err) {
+		esw_warn(dev, "Failed to register devlink port %d\n",
+			 rep->vport);
+		goto err_neigh_cleanup;
+	}
+
 	err = register_netdev(netdev);
 	if (err) {
 		pr_warn("Failed to register representor netdev for vport %d\n",
 			rep->vport);
-		goto err_neigh_cleanup;
+		goto err_devlink_cleanup;
 	}
 
+	if (is_devlink_port_supported(dev, rpriv))
+		devlink_port_type_eth_set(&rpriv->dl_port, netdev);
 	return 0;
 
+err_devlink_cleanup:
+	unregister_devlink_port(dev, rpriv);
+
 err_neigh_cleanup:
 	mlx5e_rep_neigh_cleanup(rpriv);
 
@@ -1813,9 +1855,13 @@ mlx5e_vport_rep_unload(struct mlx5_eswitch_rep *rep)
 	struct mlx5e_rep_priv *rpriv = mlx5e_rep_to_rep_priv(rep);
 	struct net_device *netdev = rpriv->netdev;
 	struct mlx5e_priv *priv = netdev_priv(netdev);
+	struct mlx5_core_dev *dev = priv->mdev;
 	void *ppriv = priv->ppriv;
 
+	if (is_devlink_port_supported(dev, rpriv))
+		devlink_port_type_clear(&rpriv->dl_port);
 	unregister_netdev(netdev);
+	unregister_devlink_port(dev, rpriv);
 	mlx5e_rep_neigh_cleanup(rpriv);
 	mlx5e_detach_netdev(priv);
 	if (rep->vport == MLX5_VPORT_UPLINK)
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_rep.h b/drivers/net/ethernet/mellanox/mlx5/core/en_rep.h
index d4585f3b8cb2..c56e6ee4350c 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_rep.h
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_rep.h
@@ -86,6 +86,7 @@ struct mlx5e_rep_priv {
 	struct mlx5_flow_handle *vport_rx_rule;
 	struct list_head       vport_sqs_list;
 	struct mlx5_rep_uplink_priv uplink_priv; /* valid for uplink rep */
+	struct devlink_port dl_port;
 };
 
 static inline
-- 
2.19.2


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

* Re: [PATCH net-next v3 1/3] devlink: Introduce PCI PF port flavour and port attribute
  2019-07-06  6:16   ` [PATCH net-next v3 1/3] devlink: Introduce PCI PF port flavour and port attribute Parav Pandit
@ 2019-07-06  6:26     ` Jiri Pirko
  2019-07-06 18:38       ` Parav Pandit
  0 siblings, 1 reply; 71+ messages in thread
From: Jiri Pirko @ 2019-07-06  6:26 UTC (permalink / raw)
  To: Parav Pandit; +Cc: netdev, jiri, saeedm, jakub.kicinski

Sat, Jul 06, 2019 at 08:16:24AM CEST, parav@mellanox.com wrote:
>In an eswitch, PCI PF may have port which is normally represented
>using a representor netdevice.
>To have better visibility of eswitch port, its association with
>PF and a representor netdevice, introduce a PCI PF port
>flavour and port attriute.
>
>When devlink port flavour is PCI PF, fill up PCI PF attributes of the
>port.
>
>Extend port name creation using PCI PF number on best effort basis.
>So that vendor drivers can skip defining their own scheme.
>
>$ devlink port show
>pci/0000:05:00.0/0: type eth netdev eth0 flavour pcipf pfnum 0
>
>Signed-off-by: Parav Pandit <parav@mellanox.com>
>
>---
>Changelog:
>v2->v3:
> - Address comments from Jakub.
> - Made port_number and split_port_number applicable only to
>   physical port flavours by having in union.
>v1->v2:
> - Limited port_num attribute to physical ports
> - Updated PCI PF attribute set API to not have port_number
>---
> include/net/devlink.h        | 21 +++++++-
> include/uapi/linux/devlink.h |  5 ++
> net/core/devlink.c           | 97 ++++++++++++++++++++++++++++--------
> 3 files changed, 100 insertions(+), 23 deletions(-)
>
>diff --git a/include/net/devlink.h b/include/net/devlink.h
>index 6625ea068d5e..1455f60e4069 100644
>--- a/include/net/devlink.h
>+++ b/include/net/devlink.h
>@@ -38,13 +38,27 @@ struct devlink {
> 	char priv[0] __aligned(NETDEV_ALIGN);
> };
> 
>+struct devlink_port_phys_attrs {
>+	u32 port_number; /* same value as "split group".

"Same" with capital letter.

>+			  * A physical port which is visible to the user
>+			  * for a given port flavour.
>+			  */
>+	u32 split_subport_number;
>+};
>+
>+struct devlink_port_pci_pf_attrs {
>+	u16 pf;	/* Associated PCI PF for this port. */
>+};
>+
> struct devlink_port_attrs {
> 	u8 set:1,
> 	   split:1,
> 	   switch_port:1;
> 	enum devlink_port_flavour flavour;
>-	u32 port_number; /* same value as "split group" */
>-	u32 split_subport_number;
>+	union {
>+		struct devlink_port_phys_attrs phys_port;
>+		struct devlink_port_pci_pf_attrs pci_pf;

Be consistent in naming: "phys", "pci_pf".


>+	};
> 	struct netdev_phys_item_id switch_id;
> };
> 
>@@ -590,6 +604,9 @@ void devlink_port_attrs_set(struct devlink_port *devlink_port,
> 			    u32 split_subport_number,
> 			    const unsigned char *switch_id,
> 			    unsigned char switch_id_len);
>+void devlink_port_attrs_pci_pf_set(struct devlink_port *devlink_port,
>+				   const unsigned char *switch_id,
>+				   unsigned char switch_id_len, u16 pf);
> int devlink_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/include/uapi/linux/devlink.h b/include/uapi/linux/devlink.h
>index 5287b42c181f..f7323884c3fe 100644
>--- a/include/uapi/linux/devlink.h
>+++ b/include/uapi/linux/devlink.h
>@@ -169,6 +169,10 @@ enum devlink_port_flavour {
> 	DEVLINK_PORT_FLAVOUR_DSA, /* Distributed switch architecture
> 				   * interconnect port.
> 				   */
>+	DEVLINK_PORT_FLAVOUR_PCI_PF, /* Represents eswitch port for
>+				      * the PCI PF. It is an internal
>+				      * port that faces the PCI PF.
>+				      */
> };
> 
> enum devlink_param_cmode {
>@@ -337,6 +341,7 @@ enum devlink_attr {
> 	DEVLINK_ATTR_FLASH_UPDATE_STATUS_DONE,	/* u64 */
> 	DEVLINK_ATTR_FLASH_UPDATE_STATUS_TOTAL,	/* u64 */
> 
>+	DEVLINK_ATTR_PORT_PCI_PF_NUMBER,	/* u16 */
> 	/* add new attributes above here, update the policy in devlink.c */
> 
> 	__DEVLINK_ATTR_MAX,
>diff --git a/net/core/devlink.c b/net/core/devlink.c
>index 89c533778135..9aa36104b471 100644
>--- a/net/core/devlink.c
>+++ b/net/core/devlink.c
>@@ -506,6 +506,14 @@ static void devlink_notify(struct devlink *devlink, enum devlink_command cmd)
> 				msg, 0, DEVLINK_MCGRP_CONFIG, GFP_KERNEL);
> }
> 
>+static bool
>+is_devlink_phy_port_num_supported(const struct devlink_port *dl_port)
>+{
>+	return (dl_port->attrs.flavour == DEVLINK_PORT_FLAVOUR_PHYSICAL ||
>+		dl_port->attrs.flavour == DEVLINK_PORT_FLAVOUR_CPU ||
>+		dl_port->attrs.flavour == DEVLINK_PORT_FLAVOUR_DSA);
>+}
>+
> static int devlink_nl_port_attrs_put(struct sk_buff *msg,
> 				     struct devlink_port *devlink_port)
> {
>@@ -515,14 +523,23 @@ static int devlink_nl_port_attrs_put(struct sk_buff *msg,
> 		return 0;
> 	if (nla_put_u16(msg, DEVLINK_ATTR_PORT_FLAVOUR, attrs->flavour))
> 		return -EMSGSIZE;
>-	if (nla_put_u32(msg, DEVLINK_ATTR_PORT_NUMBER, attrs->port_number))
>+	if (devlink_port->attrs.flavour == DEVLINK_PORT_FLAVOUR_PCI_PF) {
>+		if (nla_put_u16(msg, DEVLINK_ATTR_PORT_PCI_PF_NUMBER,
>+				attrs->pci_pf.pf))
>+			return -EMSGSIZE;
>+	}
>+	if (!is_devlink_phy_port_num_supported(devlink_port))

Please do the check here. No need for helper (the name with "is" and
"supported" is weird anyway.


>+		return 0;
>+	if (nla_put_u32(msg, DEVLINK_ATTR_PORT_NUMBER,
>+			attrs->phys_port.port_number))
> 		return -EMSGSIZE;
> 	if (!attrs->split)
> 		return 0;
>-	if (nla_put_u32(msg, DEVLINK_ATTR_PORT_SPLIT_GROUP, attrs->port_number))
>+	if (nla_put_u32(msg, DEVLINK_ATTR_PORT_SPLIT_GROUP,
>+			attrs->phys_port.port_number))

Better to split this into 2 patches. One pushing phys things into
separate struct, the second the rest.


> 		return -EMSGSIZE;
> 	if (nla_put_u32(msg, DEVLINK_ATTR_PORT_SPLIT_SUBPORT_NUMBER,
>-			attrs->split_subport_number))
>+			attrs->phys_port.split_subport_number))
> 		return -EMSGSIZE;
> 	return 0;
> }
>@@ -5738,6 +5755,30 @@ void devlink_port_type_clear(struct devlink_port *devlink_port)
> }
> EXPORT_SYMBOL_GPL(devlink_port_type_clear);
> 
>+static void __devlink_port_attrs_set(struct devlink_port *devlink_port,
>+				     enum devlink_port_flavour flavour,
>+				     u32 port_number,
>+				     const unsigned char *switch_id,
>+				     unsigned char switch_id_len)
>+{
>+	struct devlink_port_attrs *attrs = &devlink_port->attrs;
>+
>+	if (WARN_ON(devlink_port->registered))
>+		return;
>+	attrs->set = true;
>+	attrs->flavour = flavour;
>+	attrs->phys_port.port_number = port_number;
>+	if (switch_id) {
>+		attrs->switch_port = true;
>+		if (WARN_ON(switch_id_len > MAX_PHYS_ITEM_ID_LEN))
>+			switch_id_len = MAX_PHYS_ITEM_ID_LEN;
>+		memcpy(attrs->switch_id.id, switch_id, switch_id_len);
>+		attrs->switch_id.id_len = switch_id_len;
>+	} else {
>+		attrs->switch_port = false;
>+	}
>+}
>+
> /**
>  *	devlink_port_attrs_set - Set port attributes
>  *
>@@ -5761,25 +5802,34 @@ void devlink_port_attrs_set(struct devlink_port *devlink_port,
> {
> 	struct devlink_port_attrs *attrs = &devlink_port->attrs;
> 
>-	if (WARN_ON(devlink_port->registered))
>-		return;
>-	attrs->set = true;
>-	attrs->flavour = flavour;
>-	attrs->port_number = port_number;
>+	__devlink_port_attrs_set(devlink_port, flavour, port_number,
>+				 switch_id, switch_id_len);
> 	attrs->split = split;
>-	attrs->split_subport_number = split_subport_number;
>-	if (switch_id) {
>-		attrs->switch_port = true;
>-		if (WARN_ON(switch_id_len > MAX_PHYS_ITEM_ID_LEN))
>-			switch_id_len = MAX_PHYS_ITEM_ID_LEN;
>-		memcpy(attrs->switch_id.id, switch_id, switch_id_len);
>-		attrs->switch_id.id_len = switch_id_len;
>-	} else {
>-		attrs->switch_port = false;
>-	}
>+	attrs->phys_port.split_subport_number = split_subport_number;
> }
> EXPORT_SYMBOL_GPL(devlink_port_attrs_set);
> 
>+/**
>+ *	devlink_port_attrs_pci_pf_set - Set PCI PF port attributes
>+ *
>+ *	@devlink_port: devlink port
>+ *	@pf: associated PF for the devlink port instance
>+ *	@switch_id: if the port is part of switch, this is buffer with ID,
>+ *	            otwerwise this is NULL
>+ *	@switch_id_len: length of the switch_id buffer
>+ */
>+void devlink_port_attrs_pci_pf_set(struct devlink_port *devlink_port,
>+				   const unsigned char *switch_id,
>+				   unsigned char switch_id_len, u16 pf)
>+{
>+	struct devlink_port_attrs *attrs = &devlink_port->attrs;
>+
>+	__devlink_port_attrs_set(devlink_port, DEVLINK_PORT_FLAVOUR_PCI_PF,
>+				 0, switch_id, switch_id_len);

Please have this done differently. __devlink_port_attrs_set() sets
attrs->phys_port.port_number which does not make sense there.


>+	attrs->pci_pf.pf = pf;
>+}
>+EXPORT_SYMBOL_GPL(devlink_port_attrs_pci_pf_set);
>+
> static int __devlink_port_phys_port_name_get(struct devlink_port *devlink_port,
> 					     char *name, size_t len)
> {
>@@ -5792,10 +5842,12 @@ static int __devlink_port_phys_port_name_get(struct devlink_port *devlink_port,
> 	switch (attrs->flavour) {
> 	case DEVLINK_PORT_FLAVOUR_PHYSICAL:
> 		if (!attrs->split)
>-			n = snprintf(name, len, "p%u", attrs->port_number);
>+			n = snprintf(name, len, "p%u",
>+				     attrs->phys_port.port_number);
> 		else
>-			n = snprintf(name, len, "p%us%u", attrs->port_number,
>-				     attrs->split_subport_number);
>+			n = snprintf(name, len, "p%us%u",
>+				     attrs->phys_port.port_number,
>+				     attrs->phys_port.split_subport_number);
> 		break;
> 	case DEVLINK_PORT_FLAVOUR_CPU:
> 	case DEVLINK_PORT_FLAVOUR_DSA:
>@@ -5804,6 +5856,9 @@ static int __devlink_port_phys_port_name_get(struct devlink_port *devlink_port,
> 		 */
> 		WARN_ON(1);
> 		return -EINVAL;
>+	case DEVLINK_PORT_FLAVOUR_PCI_PF:
>+		n = snprintf(name, len, "pf%u", attrs->pci_pf.pf);
>+		break;
> 	}
> 
> 	if (n >= len)
>-- 
>2.19.2
>

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

* [PATCH net-next v4 0/4] devlink: Introduce PCI PF, VF ports and attributes
  2019-07-01 12:27 [PATCH net-next 0/3] devlink: Introduce PCI PF, VF ports and attributes Parav Pandit
                   ` (6 preceding siblings ...)
  2019-07-06  6:16 ` [PATCH net-next v3 0/3] devlink: Introduce PCI PF, VF ports and attributes Parav Pandit
@ 2019-07-06 18:23 ` Parav Pandit
  2019-07-06 18:23   ` [PATCH net-next v4 1/4] devlink: Refactor physical port attributes Parav Pandit
                     ` (3 more replies)
  2019-07-08  4:15 ` [PATCH net-next v5 0/5] devlink: Introduce PCI PF, VF ports and attributes Parav Pandit
  2019-07-09  4:17 ` [PATCH net-next v6 0/5] devlink: Introduce PCI PF, VF ports and attributes Parav Pandit
  9 siblings, 4 replies; 71+ messages in thread
From: Parav Pandit @ 2019-07-06 18:23 UTC (permalink / raw)
  To: netdev; +Cc: jiri, saeedm, jakub.kicinski, Parav Pandit

This patchset carry forwards the work initiated in [1] and discussion
futher concluded at [2].

To improve visibility of representor netdevice, its association with
PF or VF, physical port, two new devlink port flavours are added as
PCI PF and PCI VF ports.

A sample eswitch view can be seen below, which will be futher extended to
mdev subdevices of a PCI function in future.

Patch-1,2 extends devlink port attributes and port flavour.
Patch-3 extends mlx5 driver to register devlink ports for PF, VF and
physical link.

                                +---+      +---+
                              vf|   |      |   | pf
                                +-+-+      +-+-+
physical link <---------+         |          |
                        |         |          |
                        |         |          |
                      +-+-+     +-+-+      +-+-+
                      | 1 |     | 2 |      | 3 |
                   +--+---+-----+---+------+---+--+
                   |  physical   vf         pf    |
                   |  port       port       port  |
                   |                              |
                   |             eswitch          |
                   |                              |
                   +------------------------------+

[1] https://www.spinics.net/lists/netdev/msg555797.html
[2] https://marc.info/?l=linux-netdev&m=155354609408485&w=2

---
Changelog:
v3->v4:
 - Addressed comments from Jiri.
 - Split first patch to two patches.
 - Renamed phys_port to physical to be consistent with pci_pf.
 - Removed port_number from __devlink_port_attrs_set and moved
   assignment to caller function.
 - Used capital letter while moving old comment to new structure.
 - Removed helper function is_devlink_phy_port_num_supported().

v2->v3:
 - Made port_number and split_port_number applicable only to
   physical port flavours.
v1->v2:
 - Updated new APIs and mlx5 driver to drop port_number for PF, VF
   attributes
 - Updated port_number comment for its usage
 - Limited putting port_number to physical ports

Parav Pandit (4):
  devlink: Refactor physical port attributes
  devlink: Introduce PCI PF port flavour and port attribute
  devlink: Introduce PCI VF port flavour and port attribute
  net/mlx5e: Register devlink ports for physical link, PCI PF, VFs

 .../net/ethernet/mellanox/mlx5/core/en_rep.c  | 108 ++++++++++----
 .../net/ethernet/mellanox/mlx5/core/en_rep.h  |   1 +
 include/net/devlink.h                         |  31 +++-
 include/uapi/linux/devlink.h                  |  11 ++
 net/core/devlink.c                            | 135 +++++++++++++++---
 5 files changed, 233 insertions(+), 53 deletions(-)

-- 
2.19.2


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

* [PATCH net-next v4 1/4] devlink: Refactor physical port attributes
  2019-07-06 18:23 ` [PATCH net-next v4 0/4] devlink: Introduce PCI PF, VF ports and attributes Parav Pandit
@ 2019-07-06 18:23   ` Parav Pandit
  2019-07-07 19:47     ` Jiri Pirko
  2019-07-06 18:23   ` [PATCH net-next v4 2/4] devlink: Introduce PCI PF port flavour and port attribute Parav Pandit
                     ` (2 subsequent siblings)
  3 siblings, 1 reply; 71+ messages in thread
From: Parav Pandit @ 2019-07-06 18:23 UTC (permalink / raw)
  To: netdev; +Cc: jiri, saeedm, jakub.kicinski, Parav Pandit

To support additional devlink port flavours and to support few common
and few different port attributes, make following changes.

1. Move physical port attributes to a different structure
2. Return such attritubes in netlink response only for physical ports
(PHYSICAL, CPU and DSA)

Signed-off-by: Parav Pandit <parav@mellanox.com>
---
 include/net/devlink.h | 13 +++++++--
 net/core/devlink.c    | 63 +++++++++++++++++++++++++++++--------------
 2 files changed, 54 insertions(+), 22 deletions(-)

diff --git a/include/net/devlink.h b/include/net/devlink.h
index 6625ea068d5e..c79a1370867a 100644
--- a/include/net/devlink.h
+++ b/include/net/devlink.h
@@ -38,14 +38,23 @@ struct devlink {
 	char priv[0] __aligned(NETDEV_ALIGN);
 };
 
+struct devlink_port_phys_attrs {
+	u32 port_number; /* Same value as "split group".
+			  * A physical port which is visible to the user
+			  * for a given port flavour.
+			  */
+	u32 split_subport_number;
+};
+
 struct devlink_port_attrs {
 	u8 set:1,
 	   split:1,
 	   switch_port:1;
 	enum devlink_port_flavour flavour;
-	u32 port_number; /* same value as "split group" */
-	u32 split_subport_number;
 	struct netdev_phys_item_id switch_id;
+	union {
+		struct devlink_port_phys_attrs physical;
+	};
 };
 
 struct devlink_port {
diff --git a/net/core/devlink.c b/net/core/devlink.c
index 89c533778135..db6fa6bb9b33 100644
--- a/net/core/devlink.c
+++ b/net/core/devlink.c
@@ -515,14 +515,20 @@ static int devlink_nl_port_attrs_put(struct sk_buff *msg,
 		return 0;
 	if (nla_put_u16(msg, DEVLINK_ATTR_PORT_FLAVOUR, attrs->flavour))
 		return -EMSGSIZE;
-	if (nla_put_u32(msg, DEVLINK_ATTR_PORT_NUMBER, attrs->port_number))
+	if (devlink_port->attrs.flavour == DEVLINK_PORT_FLAVOUR_PHYSICAL ||
+	    devlink_port->attrs.flavour == DEVLINK_PORT_FLAVOUR_CPU ||
+	    devlink_port->attrs.flavour == DEVLINK_PORT_FLAVOUR_DSA)
+		return 0;
+	if (nla_put_u32(msg, DEVLINK_ATTR_PORT_NUMBER,
+			attrs->physical.port_number))
 		return -EMSGSIZE;
 	if (!attrs->split)
 		return 0;
-	if (nla_put_u32(msg, DEVLINK_ATTR_PORT_SPLIT_GROUP, attrs->port_number))
+	if (nla_put_u32(msg, DEVLINK_ATTR_PORT_SPLIT_GROUP,
+			attrs->physical.port_number))
 		return -EMSGSIZE;
 	if (nla_put_u32(msg, DEVLINK_ATTR_PORT_SPLIT_SUBPORT_NUMBER,
-			attrs->split_subport_number))
+			attrs->physical.split_subport_number))
 		return -EMSGSIZE;
 	return 0;
 }
@@ -5738,6 +5744,29 @@ void devlink_port_type_clear(struct devlink_port *devlink_port)
 }
 EXPORT_SYMBOL_GPL(devlink_port_type_clear);
 
+static int __devlink_port_attrs_set(struct devlink_port *devlink_port,
+				    enum devlink_port_flavour flavour,
+				    const unsigned char *switch_id,
+				    unsigned char switch_id_len)
+{
+	struct devlink_port_attrs *attrs = &devlink_port->attrs;
+
+	if (WARN_ON(devlink_port->registered))
+		return -EEXIST;
+	attrs->set = true;
+	attrs->flavour = flavour;
+	if (switch_id) {
+		attrs->switch_port = true;
+		if (WARN_ON(switch_id_len > MAX_PHYS_ITEM_ID_LEN))
+			switch_id_len = MAX_PHYS_ITEM_ID_LEN;
+		memcpy(attrs->switch_id.id, switch_id, switch_id_len);
+		attrs->switch_id.id_len = switch_id_len;
+	} else {
+		attrs->switch_port = false;
+	}
+	return 0;
+}
+
 /**
  *	devlink_port_attrs_set - Set port attributes
  *
@@ -5760,23 +5789,15 @@ void devlink_port_attrs_set(struct devlink_port *devlink_port,
 			    unsigned char switch_id_len)
 {
 	struct devlink_port_attrs *attrs = &devlink_port->attrs;
+	int ret;
 
-	if (WARN_ON(devlink_port->registered))
+	ret = __devlink_port_attrs_set(devlink_port, flavour,
+				       switch_id, switch_id_len);
+	if (ret)
 		return;
-	attrs->set = true;
-	attrs->flavour = flavour;
-	attrs->port_number = port_number;
 	attrs->split = split;
-	attrs->split_subport_number = split_subport_number;
-	if (switch_id) {
-		attrs->switch_port = true;
-		if (WARN_ON(switch_id_len > MAX_PHYS_ITEM_ID_LEN))
-			switch_id_len = MAX_PHYS_ITEM_ID_LEN;
-		memcpy(attrs->switch_id.id, switch_id, switch_id_len);
-		attrs->switch_id.id_len = switch_id_len;
-	} else {
-		attrs->switch_port = false;
-	}
+	attrs->physical.port_number = port_number;
+	attrs->physical.split_subport_number = split_subport_number;
 }
 EXPORT_SYMBOL_GPL(devlink_port_attrs_set);
 
@@ -5792,10 +5813,12 @@ static int __devlink_port_phys_port_name_get(struct devlink_port *devlink_port,
 	switch (attrs->flavour) {
 	case DEVLINK_PORT_FLAVOUR_PHYSICAL:
 		if (!attrs->split)
-			n = snprintf(name, len, "p%u", attrs->port_number);
+			n = snprintf(name, len, "p%u",
+				     attrs->physical.port_number);
 		else
-			n = snprintf(name, len, "p%us%u", attrs->port_number,
-				     attrs->split_subport_number);
+			n = snprintf(name, len, "p%us%u",
+				     attrs->physical.port_number,
+				     attrs->physical.split_subport_number);
 		break;
 	case DEVLINK_PORT_FLAVOUR_CPU:
 	case DEVLINK_PORT_FLAVOUR_DSA:
-- 
2.19.2


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

* [PATCH net-next v4 2/4] devlink: Introduce PCI PF port flavour and port attribute
  2019-07-06 18:23 ` [PATCH net-next v4 0/4] devlink: Introduce PCI PF, VF ports and attributes Parav Pandit
  2019-07-06 18:23   ` [PATCH net-next v4 1/4] devlink: Refactor physical port attributes Parav Pandit
@ 2019-07-06 18:23   ` Parav Pandit
  2019-07-07 19:50     ` Jiri Pirko
  2019-07-06 18:23   ` [PATCH net-next v4 3/4] devlink: Introduce PCI VF " Parav Pandit
  2019-07-06 18:23   ` [PATCH net-next v4 4/4] net/mlx5e: Register devlink ports for physical link, PCI PF, VFs Parav Pandit
  3 siblings, 1 reply; 71+ messages in thread
From: Parav Pandit @ 2019-07-06 18:23 UTC (permalink / raw)
  To: netdev; +Cc: jiri, saeedm, jakub.kicinski, Parav Pandit

In an eswitch, PCI PF may have port which is normally represented
using a representor netdevice.
To have better visibility of eswitch port, its association with
PF and a representor netdevice, introduce a PCI PF port
flavour and port attriute.

When devlink port flavour is PCI PF, fill up PCI PF attributes of the
port.

Extend port name creation using PCI PF number on best effort basis.
So that vendor drivers can skip defining their own scheme.

$ devlink port show
pci/0000:05:00.0/0: type eth netdev eth0 flavour pcipf pfnum 0

Signed-off-by: Parav Pandit <parav@mellanox.com>
---
Changelog:
v3->v4:
 - Addressed comments from Jiri.
 - Renamed phys_port to physical to be consistent with pci_pf.
 - Removed port_number from __devlink_port_attrs_set and moved
   assigment to caller function.
 - Used capital letter while moving old comment to new structure.
 - Removed helper function is_devlink_phy_port_num_supported().
v2->v3:
 - Address comments from Jakub.
 - Made port_number and split_port_number applicable only to
   physical port flavours by having in union.
v1->v2:
 - Limited port_num attribute to physical ports
 - Updated PCI PF attribute set API to not have port_number
---
 include/net/devlink.h        |  8 ++++++++
 include/uapi/linux/devlink.h |  5 +++++
 net/core/devlink.c           | 34 ++++++++++++++++++++++++++++++++++
 3 files changed, 47 insertions(+)

diff --git a/include/net/devlink.h b/include/net/devlink.h
index c79a1370867a..2a8eaaff3d4b 100644
--- a/include/net/devlink.h
+++ b/include/net/devlink.h
@@ -46,6 +46,10 @@ struct devlink_port_phys_attrs {
 	u32 split_subport_number;
 };
 
+struct devlink_port_pci_pf_attrs {
+	u16 pf;	/* Associated PCI PF for this port. */
+};
+
 struct devlink_port_attrs {
 	u8 set:1,
 	   split:1,
@@ -54,6 +58,7 @@ struct devlink_port_attrs {
 	struct netdev_phys_item_id switch_id;
 	union {
 		struct devlink_port_phys_attrs physical;
+		struct devlink_port_pci_pf_attrs pci_pf;
 	};
 };
 
@@ -599,6 +604,9 @@ void devlink_port_attrs_set(struct devlink_port *devlink_port,
 			    u32 split_subport_number,
 			    const unsigned char *switch_id,
 			    unsigned char switch_id_len);
+void devlink_port_attrs_pci_pf_set(struct devlink_port *devlink_port,
+				   const unsigned char *switch_id,
+				   unsigned char switch_id_len, u16 pf);
 int devlink_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/include/uapi/linux/devlink.h b/include/uapi/linux/devlink.h
index 5287b42c181f..f7323884c3fe 100644
--- a/include/uapi/linux/devlink.h
+++ b/include/uapi/linux/devlink.h
@@ -169,6 +169,10 @@ enum devlink_port_flavour {
 	DEVLINK_PORT_FLAVOUR_DSA, /* Distributed switch architecture
 				   * interconnect port.
 				   */
+	DEVLINK_PORT_FLAVOUR_PCI_PF, /* Represents eswitch port for
+				      * the PCI PF. It is an internal
+				      * port that faces the PCI PF.
+				      */
 };
 
 enum devlink_param_cmode {
@@ -337,6 +341,7 @@ enum devlink_attr {
 	DEVLINK_ATTR_FLASH_UPDATE_STATUS_DONE,	/* u64 */
 	DEVLINK_ATTR_FLASH_UPDATE_STATUS_TOTAL,	/* u64 */
 
+	DEVLINK_ATTR_PORT_PCI_PF_NUMBER,	/* u16 */
 	/* add new attributes above here, update the policy in devlink.c */
 
 	__DEVLINK_ATTR_MAX,
diff --git a/net/core/devlink.c b/net/core/devlink.c
index db6fa6bb9b33..3717eae8a502 100644
--- a/net/core/devlink.c
+++ b/net/core/devlink.c
@@ -515,6 +515,11 @@ static int devlink_nl_port_attrs_put(struct sk_buff *msg,
 		return 0;
 	if (nla_put_u16(msg, DEVLINK_ATTR_PORT_FLAVOUR, attrs->flavour))
 		return -EMSGSIZE;
+	if (devlink_port->attrs.flavour == DEVLINK_PORT_FLAVOUR_PCI_PF) {
+		if (nla_put_u16(msg, DEVLINK_ATTR_PORT_PCI_PF_NUMBER,
+				attrs->pci_pf.pf))
+			return -EMSGSIZE;
+	}
 	if (devlink_port->attrs.flavour == DEVLINK_PORT_FLAVOUR_PHYSICAL ||
 	    devlink_port->attrs.flavour == DEVLINK_PORT_FLAVOUR_CPU ||
 	    devlink_port->attrs.flavour == DEVLINK_PORT_FLAVOUR_DSA)
@@ -5801,6 +5806,32 @@ void devlink_port_attrs_set(struct devlink_port *devlink_port,
 }
 EXPORT_SYMBOL_GPL(devlink_port_attrs_set);
 
+/**
+ *	devlink_port_attrs_pci_pf_set - Set PCI PF port attributes
+ *
+ *	@devlink_port: devlink port
+ *	@pf: associated PF for the devlink port instance
+ *	@switch_id: if the port is part of switch, this is buffer with ID,
+ *	            otwerwise this is NULL
+ *	@switch_id_len: length of the switch_id buffer
+ */
+void devlink_port_attrs_pci_pf_set(struct devlink_port *devlink_port,
+				   const unsigned char *switch_id,
+				   unsigned char switch_id_len, u16 pf)
+{
+	struct devlink_port_attrs *attrs = &devlink_port->attrs;
+	int ret;
+
+	ret = __devlink_port_attrs_set(devlink_port,
+				       DEVLINK_PORT_FLAVOUR_PCI_PF,
+				       switch_id, switch_id_len);
+	if (ret)
+		return;
+
+	attrs->pci_pf.pf = pf;
+}
+EXPORT_SYMBOL_GPL(devlink_port_attrs_pci_pf_set);
+
 static int __devlink_port_phys_port_name_get(struct devlink_port *devlink_port,
 					     char *name, size_t len)
 {
@@ -5827,6 +5858,9 @@ static int __devlink_port_phys_port_name_get(struct devlink_port *devlink_port,
 		 */
 		WARN_ON(1);
 		return -EINVAL;
+	case DEVLINK_PORT_FLAVOUR_PCI_PF:
+		n = snprintf(name, len, "pf%u", attrs->pci_pf.pf);
+		break;
 	}
 
 	if (n >= len)
-- 
2.19.2


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

* [PATCH net-next v4 3/4] devlink: Introduce PCI VF port flavour and port attribute
  2019-07-06 18:23 ` [PATCH net-next v4 0/4] devlink: Introduce PCI PF, VF ports and attributes Parav Pandit
  2019-07-06 18:23   ` [PATCH net-next v4 1/4] devlink: Refactor physical port attributes Parav Pandit
  2019-07-06 18:23   ` [PATCH net-next v4 2/4] devlink: Introduce PCI PF port flavour and port attribute Parav Pandit
@ 2019-07-06 18:23   ` Parav Pandit
  2019-07-07 19:50     ` Jiri Pirko
  2019-07-06 18:23   ` [PATCH net-next v4 4/4] net/mlx5e: Register devlink ports for physical link, PCI PF, VFs Parav Pandit
  3 siblings, 1 reply; 71+ messages in thread
From: Parav Pandit @ 2019-07-06 18:23 UTC (permalink / raw)
  To: netdev; +Cc: jiri, saeedm, jakub.kicinski, Parav Pandit

In an eswitch, PCI VF may have port which is normally represented using
a representor netdevice.
To have better visibility of eswitch port, its association with VF,
and its representor netdevice, introduce a PCI VF port flavour.

When devlink port flavour is PCI VF, fill up PCI VF attributes of
the port.

Extend port name creation using PCI PF and VF number scheme on best
effort basis, so that vendor drivers can skip defining their own scheme.

$ devlink port show
pci/0000:05:00.0/0: type eth netdev eth0 flavour pcipf pfnum 0
pci/0000:05:00.0/1: type eth netdev eth1 flavour pcivf pfnum 0 vfnum 0
pci/0000:05:00.0/2: type eth netdev eth2 flavour pcivf pfnum 0 vfnum 1

Signed-off-by: Parav Pandit <parav@mellanox.com>
---
 include/net/devlink.h        | 10 ++++++++++
 include/uapi/linux/devlink.h |  6 ++++++
 net/core/devlink.c           | 38 ++++++++++++++++++++++++++++++++++++
 3 files changed, 54 insertions(+)

diff --git a/include/net/devlink.h b/include/net/devlink.h
index 2a8eaaff3d4b..a02f639ad519 100644
--- a/include/net/devlink.h
+++ b/include/net/devlink.h
@@ -50,6 +50,11 @@ struct devlink_port_pci_pf_attrs {
 	u16 pf;	/* Associated PCI PF for this port. */
 };
 
+struct devlink_port_pci_vf_attrs {
+	u16 pf;	/* Associated PCI PF for this port. */
+	u16 vf;	/* Associated PCI VF for of the PCI PF for this port. */
+};
+
 struct devlink_port_attrs {
 	u8 set:1,
 	   split:1,
@@ -59,6 +64,7 @@ struct devlink_port_attrs {
 	union {
 		struct devlink_port_phys_attrs physical;
 		struct devlink_port_pci_pf_attrs pci_pf;
+		struct devlink_port_pci_vf_attrs pci_vf;
 	};
 };
 
@@ -607,6 +613,10 @@ void devlink_port_attrs_set(struct devlink_port *devlink_port,
 void devlink_port_attrs_pci_pf_set(struct devlink_port *devlink_port,
 				   const unsigned char *switch_id,
 				   unsigned char switch_id_len, u16 pf);
+void devlink_port_attrs_pci_vf_set(struct devlink_port *devlink_port,
+				   const unsigned char *switch_id,
+				   unsigned char switch_id_len,
+				   u16 pf, u16 vf);
 int devlink_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/include/uapi/linux/devlink.h b/include/uapi/linux/devlink.h
index f7323884c3fe..ffc993256527 100644
--- a/include/uapi/linux/devlink.h
+++ b/include/uapi/linux/devlink.h
@@ -173,6 +173,10 @@ enum devlink_port_flavour {
 				      * the PCI PF. It is an internal
 				      * port that faces the PCI PF.
 				      */
+	DEVLINK_PORT_FLAVOUR_PCI_VF, /* Represents eswitch port
+				      * for the PCI VF. It is an internal
+				      * port that faces the PCI VF.
+				      */
 };
 
 enum devlink_param_cmode {
@@ -342,6 +346,8 @@ enum devlink_attr {
 	DEVLINK_ATTR_FLASH_UPDATE_STATUS_TOTAL,	/* u64 */
 
 	DEVLINK_ATTR_PORT_PCI_PF_NUMBER,	/* u16 */
+	DEVLINK_ATTR_PORT_PCI_VF_NUMBER,	/* u16 */
+
 	/* add new attributes above here, update the policy in devlink.c */
 
 	__DEVLINK_ATTR_MAX,
diff --git a/net/core/devlink.c b/net/core/devlink.c
index 3717eae8a502..5a1887c1b3c5 100644
--- a/net/core/devlink.c
+++ b/net/core/devlink.c
@@ -519,6 +519,12 @@ static int devlink_nl_port_attrs_put(struct sk_buff *msg,
 		if (nla_put_u16(msg, DEVLINK_ATTR_PORT_PCI_PF_NUMBER,
 				attrs->pci_pf.pf))
 			return -EMSGSIZE;
+	} else if (devlink_port->attrs.flavour == DEVLINK_PORT_FLAVOUR_PCI_VF) {
+		if (nla_put_u16(msg, DEVLINK_ATTR_PORT_PCI_PF_NUMBER,
+				attrs->pci_vf.pf) ||
+		    nla_put_u16(msg, DEVLINK_ATTR_PORT_PCI_VF_NUMBER,
+				attrs->pci_vf.vf))
+			return -EMSGSIZE;
 	}
 	if (devlink_port->attrs.flavour == DEVLINK_PORT_FLAVOUR_PHYSICAL ||
 	    devlink_port->attrs.flavour == DEVLINK_PORT_FLAVOUR_CPU ||
@@ -5832,6 +5838,34 @@ void devlink_port_attrs_pci_pf_set(struct devlink_port *devlink_port,
 }
 EXPORT_SYMBOL_GPL(devlink_port_attrs_pci_pf_set);
 
+/**
+ *	devlink_port_attrs_pci_vf_set - Set PCI VF port attributes
+ *
+ *	@devlink_port: devlink port
+ *	@pf: associated PF for the devlink port instance
+ *	@vf: associated VF of a PF for the devlink port instance
+ *	@switch_id: if the port is part of switch, this is buffer with ID,
+ *	            otwerwise this is NULL
+ *	@switch_id_len: length of the switch_id buffer
+ */
+void devlink_port_attrs_pci_vf_set(struct devlink_port *devlink_port,
+				   const unsigned char *switch_id,
+				   unsigned char switch_id_len,
+				   u16 pf, u16 vf)
+{
+	struct devlink_port_attrs *attrs = &devlink_port->attrs;
+	int ret;
+
+	ret = __devlink_port_attrs_set(devlink_port,
+				       DEVLINK_PORT_FLAVOUR_PCI_VF,
+				       switch_id, switch_id_len);
+	if (ret)
+		return;
+	attrs->pci_vf.pf = pf;
+	attrs->pci_vf.vf = vf;
+}
+EXPORT_SYMBOL_GPL(devlink_port_attrs_pci_vf_set);
+
 static int __devlink_port_phys_port_name_get(struct devlink_port *devlink_port,
 					     char *name, size_t len)
 {
@@ -5861,6 +5895,10 @@ static int __devlink_port_phys_port_name_get(struct devlink_port *devlink_port,
 	case DEVLINK_PORT_FLAVOUR_PCI_PF:
 		n = snprintf(name, len, "pf%u", attrs->pci_pf.pf);
 		break;
+	case DEVLINK_PORT_FLAVOUR_PCI_VF:
+		n = snprintf(name, len, "pf%uvf%u",
+			     attrs->pci_vf.pf, attrs->pci_vf.vf);
+		break;
 	}
 
 	if (n >= len)
-- 
2.19.2


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

* [PATCH net-next v4 4/4] net/mlx5e: Register devlink ports for physical link, PCI PF, VFs
  2019-07-06 18:23 ` [PATCH net-next v4 0/4] devlink: Introduce PCI PF, VF ports and attributes Parav Pandit
                     ` (2 preceding siblings ...)
  2019-07-06 18:23   ` [PATCH net-next v4 3/4] devlink: Introduce PCI VF " Parav Pandit
@ 2019-07-06 18:23   ` Parav Pandit
  2019-07-07 19:51     ` Jiri Pirko
  3 siblings, 1 reply; 71+ messages in thread
From: Parav Pandit @ 2019-07-06 18:23 UTC (permalink / raw)
  To: netdev; +Cc: jiri, saeedm, jakub.kicinski, Parav Pandit

Register devlink port of physical port, PCI PF and PCI VF flavour
for each PF, VF when a given devlink instance is in switchdev mode.

Implement ndo_get_devlink_port callback API to make use of registered
devlink ports.
This eliminates ndo_get_phys_port_name() and ndo_get_port_parent_id()
callbacks. Hence, remove them.

An example output with 2 VFs, without a PF and single uplink port is
below.

$devlink port show
pci/0000:06:00.0/65535: type eth netdev ens2f0 flavour physical
pci/0000:05:00.0/1: type eth netdev eth1 flavour pcivf pfnum 0 vfnum 0
pci/0000:05:00.0/2: type eth netdev eth2 flavour pcivf pfnum 0 vfnum 1

Reviewed-by: Roi Dayan <roid@mellanox.com>
Signed-off-by: Parav Pandit <parav@mellanox.com>
---
 .../net/ethernet/mellanox/mlx5/core/en_rep.c  | 108 +++++++++++++-----
 .../net/ethernet/mellanox/mlx5/core/en_rep.h  |   1 +
 2 files changed, 78 insertions(+), 31 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_rep.c b/drivers/net/ethernet/mellanox/mlx5/core/en_rep.c
index 529f8e4b32c6..6810b9fa0705 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_rep.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_rep.c
@@ -37,6 +37,7 @@
 #include <net/act_api.h>
 #include <net/netevent.h>
 #include <net/arp.h>
+#include <net/devlink.h>
 
 #include "eswitch.h"
 #include "en.h"
@@ -1119,32 +1120,6 @@ static int mlx5e_rep_close(struct net_device *dev)
 	return ret;
 }
 
-static int mlx5e_rep_get_phys_port_name(struct net_device *dev,
-					char *buf, size_t len)
-{
-	struct mlx5e_priv *priv = netdev_priv(dev);
-	struct mlx5e_rep_priv *rpriv = priv->ppriv;
-	struct mlx5_eswitch_rep *rep = rpriv->rep;
-	unsigned int fn;
-	int ret;
-
-	fn = PCI_FUNC(priv->mdev->pdev->devfn);
-	if (fn >= MLX5_MAX_PORTS)
-		return -EOPNOTSUPP;
-
-	if (rep->vport == MLX5_VPORT_UPLINK)
-		ret = snprintf(buf, len, "p%d", fn);
-	else if (rep->vport == MLX5_VPORT_PF)
-		ret = snprintf(buf, len, "pf%d", fn);
-	else
-		ret = snprintf(buf, len, "pf%dvf%d", fn, rep->vport - 1);
-
-	if (ret >= len)
-		return -EOPNOTSUPP;
-
-	return 0;
-}
-
 static int
 mlx5e_rep_setup_tc_cls_flower(struct mlx5e_priv *priv,
 			      struct tc_cls_flower_offload *cls_flower, int flags)
@@ -1298,17 +1273,24 @@ static int mlx5e_uplink_rep_set_vf_vlan(struct net_device *dev, int vf, u16 vlan
 	return 0;
 }
 
+static struct devlink_port *mlx5e_get_devlink_port(struct net_device *dev)
+{
+	struct mlx5e_priv *priv = netdev_priv(dev);
+	struct mlx5e_rep_priv *rpriv = priv->ppriv;
+
+	return &rpriv->dl_port;
+}
+
 static const struct net_device_ops mlx5e_netdev_ops_rep = {
 	.ndo_open                = mlx5e_rep_open,
 	.ndo_stop                = mlx5e_rep_close,
 	.ndo_start_xmit          = mlx5e_xmit,
-	.ndo_get_phys_port_name  = mlx5e_rep_get_phys_port_name,
 	.ndo_setup_tc            = mlx5e_rep_setup_tc,
+	.ndo_get_devlink_port = mlx5e_get_devlink_port,
 	.ndo_get_stats64         = mlx5e_rep_get_stats,
 	.ndo_has_offload_stats	 = mlx5e_rep_has_offload_stats,
 	.ndo_get_offload_stats	 = mlx5e_rep_get_offload_stats,
 	.ndo_change_mtu          = mlx5e_rep_change_mtu,
-	.ndo_get_port_parent_id	 = mlx5e_rep_get_port_parent_id,
 };
 
 static const struct net_device_ops mlx5e_netdev_ops_uplink_rep = {
@@ -1316,8 +1298,8 @@ static const struct net_device_ops mlx5e_netdev_ops_uplink_rep = {
 	.ndo_stop                = mlx5e_close,
 	.ndo_start_xmit          = mlx5e_xmit,
 	.ndo_set_mac_address     = mlx5e_uplink_rep_set_mac,
-	.ndo_get_phys_port_name  = mlx5e_rep_get_phys_port_name,
 	.ndo_setup_tc            = mlx5e_rep_setup_tc,
+	.ndo_get_devlink_port = mlx5e_get_devlink_port,
 	.ndo_get_stats64         = mlx5e_get_stats,
 	.ndo_has_offload_stats	 = mlx5e_rep_has_offload_stats,
 	.ndo_get_offload_stats	 = mlx5e_rep_get_offload_stats,
@@ -1330,7 +1312,6 @@ static const struct net_device_ops mlx5e_netdev_ops_uplink_rep = {
 	.ndo_get_vf_config       = mlx5e_get_vf_config,
 	.ndo_get_vf_stats        = mlx5e_get_vf_stats,
 	.ndo_set_vf_vlan         = mlx5e_uplink_rep_set_vf_vlan,
-	.ndo_get_port_parent_id	 = mlx5e_rep_get_port_parent_id,
 	.ndo_set_features        = mlx5e_set_features,
 };
 
@@ -1731,6 +1712,55 @@ static const struct mlx5e_profile mlx5e_uplink_rep_profile = {
 	.max_tc			= MLX5E_MAX_NUM_TC,
 };
 
+static bool
+is_devlink_port_supported(const struct mlx5_core_dev *dev,
+			  const struct mlx5e_rep_priv *rpriv)
+{
+	return rpriv->rep->vport == MLX5_VPORT_UPLINK ||
+	       rpriv->rep->vport == MLX5_VPORT_PF ||
+	       mlx5_eswitch_is_vf_vport(dev->priv.eswitch, rpriv->rep->vport);
+}
+
+static int register_devlink_port(struct mlx5_core_dev *dev,
+				 struct mlx5e_rep_priv *rpriv)
+{
+	struct devlink *devlink = priv_to_devlink(dev);
+	struct mlx5_eswitch_rep *rep = rpriv->rep;
+	struct netdev_phys_item_id ppid = {};
+	int ret;
+
+	if (!is_devlink_port_supported(dev, rpriv))
+		return 0;
+
+	ret = mlx5e_rep_get_port_parent_id(rpriv->netdev, &ppid);
+	if (ret)
+		return ret;
+
+	if (rep->vport == MLX5_VPORT_UPLINK)
+		devlink_port_attrs_set(&rpriv->dl_port,
+				       DEVLINK_PORT_FLAVOUR_PHYSICAL,
+				       PCI_FUNC(dev->pdev->devfn), false, 0,
+				       &ppid.id[0], ppid.id_len);
+	else if (rep->vport == MLX5_VPORT_PF)
+		devlink_port_attrs_pci_pf_set(&rpriv->dl_port,
+					      &ppid.id[0], ppid.id_len,
+					      dev->pdev->devfn);
+	else if (mlx5_eswitch_is_vf_vport(dev->priv.eswitch, rpriv->rep->vport))
+		devlink_port_attrs_pci_vf_set(&rpriv->dl_port,
+					      &ppid.id[0], ppid.id_len,
+					      dev->pdev->devfn,
+					      rep->vport - 1);
+
+	return devlink_port_register(devlink, &rpriv->dl_port, rep->vport);
+}
+
+static void unregister_devlink_port(struct mlx5_core_dev *dev,
+				    struct mlx5e_rep_priv *rpriv)
+{
+	if (is_devlink_port_supported(dev, rpriv))
+		devlink_port_unregister(&rpriv->dl_port);
+}
+
 /* e-Switch vport representors */
 static int
 mlx5e_vport_rep_load(struct mlx5_core_dev *dev, struct mlx5_eswitch_rep *rep)
@@ -1782,15 +1812,27 @@ mlx5e_vport_rep_load(struct mlx5_core_dev *dev, struct mlx5_eswitch_rep *rep)
 		goto err_detach_netdev;
 	}
 
+	err = register_devlink_port(dev, rpriv);
+	if (err) {
+		esw_warn(dev, "Failed to register devlink port %d\n",
+			 rep->vport);
+		goto err_neigh_cleanup;
+	}
+
 	err = register_netdev(netdev);
 	if (err) {
 		pr_warn("Failed to register representor netdev for vport %d\n",
 			rep->vport);
-		goto err_neigh_cleanup;
+		goto err_devlink_cleanup;
 	}
 
+	if (is_devlink_port_supported(dev, rpriv))
+		devlink_port_type_eth_set(&rpriv->dl_port, netdev);
 	return 0;
 
+err_devlink_cleanup:
+	unregister_devlink_port(dev, rpriv);
+
 err_neigh_cleanup:
 	mlx5e_rep_neigh_cleanup(rpriv);
 
@@ -1813,9 +1855,13 @@ mlx5e_vport_rep_unload(struct mlx5_eswitch_rep *rep)
 	struct mlx5e_rep_priv *rpriv = mlx5e_rep_to_rep_priv(rep);
 	struct net_device *netdev = rpriv->netdev;
 	struct mlx5e_priv *priv = netdev_priv(netdev);
+	struct mlx5_core_dev *dev = priv->mdev;
 	void *ppriv = priv->ppriv;
 
+	if (is_devlink_port_supported(dev, rpriv))
+		devlink_port_type_clear(&rpriv->dl_port);
 	unregister_netdev(netdev);
+	unregister_devlink_port(dev, rpriv);
 	mlx5e_rep_neigh_cleanup(rpriv);
 	mlx5e_detach_netdev(priv);
 	if (rep->vport == MLX5_VPORT_UPLINK)
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_rep.h b/drivers/net/ethernet/mellanox/mlx5/core/en_rep.h
index d4585f3b8cb2..c56e6ee4350c 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_rep.h
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_rep.h
@@ -86,6 +86,7 @@ struct mlx5e_rep_priv {
 	struct mlx5_flow_handle *vport_rx_rule;
 	struct list_head       vport_sqs_list;
 	struct mlx5_rep_uplink_priv uplink_priv; /* valid for uplink rep */
+	struct devlink_port dl_port;
 };
 
 static inline
-- 
2.19.2


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

* RE: [PATCH net-next v3 1/3] devlink: Introduce PCI PF port flavour and port attribute
  2019-07-06  6:26     ` Jiri Pirko
@ 2019-07-06 18:38       ` Parav Pandit
  0 siblings, 0 replies; 71+ messages in thread
From: Parav Pandit @ 2019-07-06 18:38 UTC (permalink / raw)
  To: Jiri Pirko; +Cc: netdev, Jiri Pirko, Saeed Mahameed, jakub.kicinski



> -----Original Message-----
> From: Jiri Pirko <jiri@resnulli.us>
> Sent: Saturday, July 6, 2019 11:56 AM
> To: Parav Pandit <parav@mellanox.com>
> Cc: netdev@vger.kernel.org; Jiri Pirko <jiri@mellanox.com>; Saeed Mahameed
> <saeedm@mellanox.com>; jakub.kicinski@netronome.com
> Subject: Re: [PATCH net-next v3 1/3] devlink: Introduce PCI PF port flavour and
> port attribute
> 
> Sat, Jul 06, 2019 at 08:16:24AM CEST, parav@mellanox.com wrote:
> >In an eswitch, PCI PF may have port which is normally represented using
> >a representor netdevice.
> >To have better visibility of eswitch port, its association with PF and
> >a representor netdevice, introduce a PCI PF port flavour and port
> >attriute.
> >
> >When devlink port flavour is PCI PF, fill up PCI PF attributes of the
> >port.
> >
> >Extend port name creation using PCI PF number on best effort basis.
> >So that vendor drivers can skip defining their own scheme.
> >
> >$ devlink port show
> >pci/0000:05:00.0/0: type eth netdev eth0 flavour pcipf pfnum 0
> >
> >Signed-off-by: Parav Pandit <parav@mellanox.com>
> >
> >---
> >Changelog:
> >v2->v3:
> > - Address comments from Jakub.
> > - Made port_number and split_port_number applicable only to
> >   physical port flavours by having in union.
> >v1->v2:
> > - Limited port_num attribute to physical ports
> > - Updated PCI PF attribute set API to not have port_number
> >---
> > include/net/devlink.h        | 21 +++++++-
> > include/uapi/linux/devlink.h |  5 ++
> > net/core/devlink.c           | 97 ++++++++++++++++++++++++++++--------
> > 3 files changed, 100 insertions(+), 23 deletions(-)
> >
> >diff --git a/include/net/devlink.h b/include/net/devlink.h index
> >6625ea068d5e..1455f60e4069 100644
> >--- a/include/net/devlink.h
> >+++ b/include/net/devlink.h
> >@@ -38,13 +38,27 @@ struct devlink {
> > 	char priv[0] __aligned(NETDEV_ALIGN);  };
> >
> >+struct devlink_port_phys_attrs {
> >+	u32 port_number; /* same value as "split group".
> 
> "Same" with capital letter.
> 
Done in v4.

> >+			  * A physical port which is visible to the user
> >+			  * for a given port flavour.
> >+			  */
> >+	u32 split_subport_number;
> >+};
> >+
> >+struct devlink_port_pci_pf_attrs {
> >+	u16 pf;	/* Associated PCI PF for this port. */
> >+};
> >+
> > struct devlink_port_attrs {
> > 	u8 set:1,
> > 	   split:1,
> > 	   switch_port:1;
> > 	enum devlink_port_flavour flavour;
> >-	u32 port_number; /* same value as "split group" */
> >-	u32 split_subport_number;
> >+	union {
> >+		struct devlink_port_phys_attrs phys_port;
> >+		struct devlink_port_pci_pf_attrs pci_pf;
> 
> Be consistent in naming: "phys", "pci_pf".
> 
Done in v4 as "physical".

> 
> >+	};
> > 	struct netdev_phys_item_id switch_id; };
> >
> >@@ -590,6 +604,9 @@ void devlink_port_attrs_set(struct devlink_port
> *devlink_port,
> > 			    u32 split_subport_number,
> > 			    const unsigned char *switch_id,
> > 			    unsigned char switch_id_len);
> >+void devlink_port_attrs_pci_pf_set(struct devlink_port *devlink_port,
> >+				   const unsigned char *switch_id,
> >+				   unsigned char switch_id_len, u16 pf);
> > int devlink_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/include/uapi/linux/devlink.h b/include/uapi/linux/devlink.h index
> >5287b42c181f..f7323884c3fe 100644
> >--- a/include/uapi/linux/devlink.h
> >+++ b/include/uapi/linux/devlink.h
> >@@ -169,6 +169,10 @@ enum devlink_port_flavour {
> > 	DEVLINK_PORT_FLAVOUR_DSA, /* Distributed switch architecture
> > 				   * interconnect port.
> > 				   */
> >+	DEVLINK_PORT_FLAVOUR_PCI_PF, /* Represents eswitch port for
> >+				      * the PCI PF. It is an internal
> >+				      * port that faces the PCI PF.
> >+				      */
> > };
> >
> > enum devlink_param_cmode {
> >@@ -337,6 +341,7 @@ enum devlink_attr {
> > 	DEVLINK_ATTR_FLASH_UPDATE_STATUS_DONE,	/* u64 */
> > 	DEVLINK_ATTR_FLASH_UPDATE_STATUS_TOTAL,	/* u64 */
> >
> >+	DEVLINK_ATTR_PORT_PCI_PF_NUMBER,	/* u16 */
> > 	/* add new attributes above here, update the policy in devlink.c */
> >
> > 	__DEVLINK_ATTR_MAX,
> >diff --git a/net/core/devlink.c b/net/core/devlink.c index
> >89c533778135..9aa36104b471 100644
> >--- a/net/core/devlink.c
> >+++ b/net/core/devlink.c
> >@@ -506,6 +506,14 @@ static void devlink_notify(struct devlink *devlink,
> enum devlink_command cmd)
> > 				msg, 0, DEVLINK_MCGRP_CONFIG,
> GFP_KERNEL);  }
> >
> >+static bool
> >+is_devlink_phy_port_num_supported(const struct devlink_port *dl_port)
> >+{
> >+	return (dl_port->attrs.flavour == DEVLINK_PORT_FLAVOUR_PHYSICAL
> ||
> >+		dl_port->attrs.flavour == DEVLINK_PORT_FLAVOUR_CPU ||
> >+		dl_port->attrs.flavour == DEVLINK_PORT_FLAVOUR_DSA); }
> >+
> > static int devlink_nl_port_attrs_put(struct sk_buff *msg,
> > 				     struct devlink_port *devlink_port)  { @@ -
> 515,14 +523,23 @@
> >static int devlink_nl_port_attrs_put(struct sk_buff *msg,
> > 		return 0;
> > 	if (nla_put_u16(msg, DEVLINK_ATTR_PORT_FLAVOUR, attrs->flavour))
> > 		return -EMSGSIZE;
> >-	if (nla_put_u32(msg, DEVLINK_ATTR_PORT_NUMBER, attrs-
> >port_number))
> >+	if (devlink_port->attrs.flavour == DEVLINK_PORT_FLAVOUR_PCI_PF) {
> >+		if (nla_put_u16(msg, DEVLINK_ATTR_PORT_PCI_PF_NUMBER,
> >+				attrs->pci_pf.pf))
> >+			return -EMSGSIZE;
> >+	}
> >+	if (!is_devlink_phy_port_num_supported(devlink_port))
> 
> Please do the check here. No need for helper (the name with "is" and
> "supported" is weird anyway.
> 
Done in v4.
> 
> >+		return 0;
> >+	if (nla_put_u32(msg, DEVLINK_ATTR_PORT_NUMBER,
> >+			attrs->phys_port.port_number))
> > 		return -EMSGSIZE;
> > 	if (!attrs->split)
> > 		return 0;
> >-	if (nla_put_u32(msg, DEVLINK_ATTR_PORT_SPLIT_GROUP, attrs-
> >port_number))
> >+	if (nla_put_u32(msg, DEVLINK_ATTR_PORT_SPLIT_GROUP,
> >+			attrs->phys_port.port_number))
> 
> Better to split this into 2 patches. One pushing phys things into separate struct,
> the second the rest.
> 
Done in v4.
> 
> > 		return -EMSGSIZE;
> > 	if (nla_put_u32(msg, DEVLINK_ATTR_PORT_SPLIT_SUBPORT_NUMBER,
> >-			attrs->split_subport_number))
> >+			attrs->phys_port.split_subport_number))
> > 		return -EMSGSIZE;
> > 	return 0;
> > }
> >@@ -5738,6 +5755,30 @@ void devlink_port_type_clear(struct devlink_port
> >*devlink_port)  }  EXPORT_SYMBOL_GPL(devlink_port_type_clear);
> >
> >+static void __devlink_port_attrs_set(struct devlink_port *devlink_port,
> >+				     enum devlink_port_flavour flavour,
> >+				     u32 port_number,
> >+				     const unsigned char *switch_id,
> >+				     unsigned char switch_id_len)
> >+{
> >+	struct devlink_port_attrs *attrs = &devlink_port->attrs;
> >+
> >+	if (WARN_ON(devlink_port->registered))
> >+		return;
> >+	attrs->set = true;
> >+	attrs->flavour = flavour;
> >+	attrs->phys_port.port_number = port_number;
> >+	if (switch_id) {
> >+		attrs->switch_port = true;
> >+		if (WARN_ON(switch_id_len > MAX_PHYS_ITEM_ID_LEN))
> >+			switch_id_len = MAX_PHYS_ITEM_ID_LEN;
> >+		memcpy(attrs->switch_id.id, switch_id, switch_id_len);
> >+		attrs->switch_id.id_len = switch_id_len;
> >+	} else {
> >+		attrs->switch_port = false;
> >+	}
> >+}
> >+
> > /**
> >  *	devlink_port_attrs_set - Set port attributes
> >  *
> >@@ -5761,25 +5802,34 @@ void devlink_port_attrs_set(struct devlink_port
> >*devlink_port,  {
> > 	struct devlink_port_attrs *attrs = &devlink_port->attrs;
> >
> >-	if (WARN_ON(devlink_port->registered))
> >-		return;
> >-	attrs->set = true;
> >-	attrs->flavour = flavour;
> >-	attrs->port_number = port_number;
> >+	__devlink_port_attrs_set(devlink_port, flavour, port_number,
> >+				 switch_id, switch_id_len);
> > 	attrs->split = split;
> >-	attrs->split_subport_number = split_subport_number;
> >-	if (switch_id) {
> >-		attrs->switch_port = true;
> >-		if (WARN_ON(switch_id_len > MAX_PHYS_ITEM_ID_LEN))
> >-			switch_id_len = MAX_PHYS_ITEM_ID_LEN;
> >-		memcpy(attrs->switch_id.id, switch_id, switch_id_len);
> >-		attrs->switch_id.id_len = switch_id_len;
> >-	} else {
> >-		attrs->switch_port = false;
> >-	}
> >+	attrs->phys_port.split_subport_number = split_subport_number;
> > }
> > EXPORT_SYMBOL_GPL(devlink_port_attrs_set);
> >
> >+/**
> >+ *	devlink_port_attrs_pci_pf_set - Set PCI PF port attributes
> >+ *
> >+ *	@devlink_port: devlink port
> >+ *	@pf: associated PF for the devlink port instance
> >+ *	@switch_id: if the port is part of switch, this is buffer with ID,
> >+ *	            otwerwise this is NULL
> >+ *	@switch_id_len: length of the switch_id buffer
> >+ */
> >+void devlink_port_attrs_pci_pf_set(struct devlink_port *devlink_port,
> >+				   const unsigned char *switch_id,
> >+				   unsigned char switch_id_len, u16 pf) {
> >+	struct devlink_port_attrs *attrs = &devlink_port->attrs;
> >+
> >+	__devlink_port_attrs_set(devlink_port,
> DEVLINK_PORT_FLAVOUR_PCI_PF,
> >+				 0, switch_id, switch_id_len);
> 
> Please have this done differently. __devlink_port_attrs_set() sets
> attrs->phys_port.port_number which does not make sense there.
> 
Changed in v4.

> 
> >+	attrs->pci_pf.pf = pf;
> >+}
> >+EXPORT_SYMBOL_GPL(devlink_port_attrs_pci_pf_set);
> >+
> > static int __devlink_port_phys_port_name_get(struct devlink_port
> *devlink_port,
> > 					     char *name, size_t len)
> > {
> >@@ -5792,10 +5842,12 @@ static int
> __devlink_port_phys_port_name_get(struct devlink_port *devlink_port,
> > 	switch (attrs->flavour) {
> > 	case DEVLINK_PORT_FLAVOUR_PHYSICAL:
> > 		if (!attrs->split)
> >-			n = snprintf(name, len, "p%u", attrs->port_number);
> >+			n = snprintf(name, len, "p%u",
> >+				     attrs->phys_port.port_number);
> > 		else
> >-			n = snprintf(name, len, "p%us%u", attrs->port_number,
> >-				     attrs->split_subport_number);
> >+			n = snprintf(name, len, "p%us%u",
> >+				     attrs->phys_port.port_number,
> >+				     attrs->phys_port.split_subport_number);
> > 		break;
> > 	case DEVLINK_PORT_FLAVOUR_CPU:
> > 	case DEVLINK_PORT_FLAVOUR_DSA:
> >@@ -5804,6 +5856,9 @@ static int
> __devlink_port_phys_port_name_get(struct devlink_port *devlink_port,
> > 		 */
> > 		WARN_ON(1);
> > 		return -EINVAL;
> >+	case DEVLINK_PORT_FLAVOUR_PCI_PF:
> >+		n = snprintf(name, len, "pf%u", attrs->pci_pf.pf);
> >+		break;
> > 	}
> >
> > 	if (n >= len)
> >--
> >2.19.2
> >

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

* Re: [PATCH net-next v4 1/4] devlink: Refactor physical port attributes
  2019-07-06 18:23   ` [PATCH net-next v4 1/4] devlink: Refactor physical port attributes Parav Pandit
@ 2019-07-07 19:47     ` Jiri Pirko
  2019-07-08  4:34       ` Parav Pandit
  0 siblings, 1 reply; 71+ messages in thread
From: Jiri Pirko @ 2019-07-07 19:47 UTC (permalink / raw)
  To: Parav Pandit; +Cc: netdev, jiri, saeedm, jakub.kicinski

Sat, Jul 06, 2019 at 08:23:47PM CEST, parav@mellanox.com wrote:
>To support additional devlink port flavours and to support few common
>and few different port attributes, make following changes.
>
>1. Move physical port attributes to a different structure
>2. Return such attritubes in netlink response only for physical ports
>(PHYSICAL, CPU and DSA)

2 changes, 2 patches please.


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

* Re: [PATCH net-next v4 2/4] devlink: Introduce PCI PF port flavour and port attribute
  2019-07-06 18:23   ` [PATCH net-next v4 2/4] devlink: Introduce PCI PF port flavour and port attribute Parav Pandit
@ 2019-07-07 19:50     ` Jiri Pirko
  0 siblings, 0 replies; 71+ messages in thread
From: Jiri Pirko @ 2019-07-07 19:50 UTC (permalink / raw)
  To: Parav Pandit; +Cc: netdev, jiri, saeedm, jakub.kicinski

Sat, Jul 06, 2019 at 08:23:48PM CEST, parav@mellanox.com wrote:
>In an eswitch, PCI PF may have port which is normally represented
>using a representor netdevice.
>To have better visibility of eswitch port, its association with
>PF and a representor netdevice, introduce a PCI PF port
>flavour and port attriute.
>
>When devlink port flavour is PCI PF, fill up PCI PF attributes of the
>port.
>
>Extend port name creation using PCI PF number on best effort basis.
>So that vendor drivers can skip defining their own scheme.
>
>$ devlink port show
>pci/0000:05:00.0/0: type eth netdev eth0 flavour pcipf pfnum 0
>
>Signed-off-by: Parav Pandit <parav@mellanox.com>

Acked-by: Jiri Pirko <jiri@mellanox.com>

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

* Re: [PATCH net-next v4 3/4] devlink: Introduce PCI VF port flavour and port attribute
  2019-07-06 18:23   ` [PATCH net-next v4 3/4] devlink: Introduce PCI VF " Parav Pandit
@ 2019-07-07 19:50     ` Jiri Pirko
  0 siblings, 0 replies; 71+ messages in thread
From: Jiri Pirko @ 2019-07-07 19:50 UTC (permalink / raw)
  To: Parav Pandit; +Cc: netdev, jiri, saeedm, jakub.kicinski

Sat, Jul 06, 2019 at 08:23:49PM CEST, parav@mellanox.com wrote:
>In an eswitch, PCI VF may have port which is normally represented using
>a representor netdevice.
>To have better visibility of eswitch port, its association with VF,
>and its representor netdevice, introduce a PCI VF port flavour.
>
>When devlink port flavour is PCI VF, fill up PCI VF attributes of
>the port.
>
>Extend port name creation using PCI PF and VF number scheme on best
>effort basis, so that vendor drivers can skip defining their own scheme.
>
>$ devlink port show
>pci/0000:05:00.0/0: type eth netdev eth0 flavour pcipf pfnum 0
>pci/0000:05:00.0/1: type eth netdev eth1 flavour pcivf pfnum 0 vfnum 0
>pci/0000:05:00.0/2: type eth netdev eth2 flavour pcivf pfnum 0 vfnum 1
>
>Signed-off-by: Parav Pandit <parav@mellanox.com>

Acked-by: Jiri Pirko <jiri@mellanox.com>

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

* Re: [PATCH net-next v4 4/4] net/mlx5e: Register devlink ports for physical link, PCI PF, VFs
  2019-07-06 18:23   ` [PATCH net-next v4 4/4] net/mlx5e: Register devlink ports for physical link, PCI PF, VFs Parav Pandit
@ 2019-07-07 19:51     ` Jiri Pirko
  0 siblings, 0 replies; 71+ messages in thread
From: Jiri Pirko @ 2019-07-07 19:51 UTC (permalink / raw)
  To: Parav Pandit; +Cc: netdev, jiri, saeedm, jakub.kicinski

Sat, Jul 06, 2019 at 08:23:50PM CEST, parav@mellanox.com wrote:
>Register devlink port of physical port, PCI PF and PCI VF flavour
>for each PF, VF when a given devlink instance is in switchdev mode.
>
>Implement ndo_get_devlink_port callback API to make use of registered
>devlink ports.
>This eliminates ndo_get_phys_port_name() and ndo_get_port_parent_id()
>callbacks. Hence, remove them.
>
>An example output with 2 VFs, without a PF and single uplink port is
>below.
>
>$devlink port show
>pci/0000:06:00.0/65535: type eth netdev ens2f0 flavour physical
>pci/0000:05:00.0/1: type eth netdev eth1 flavour pcivf pfnum 0 vfnum 0
>pci/0000:05:00.0/2: type eth netdev eth2 flavour pcivf pfnum 0 vfnum 1
>
>Reviewed-by: Roi Dayan <roid@mellanox.com>
>Signed-off-by: Parav Pandit <parav@mellanox.com>

Acked-by: Jiri Pirko <jiri@mellanox.com>

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

* [PATCH net-next v5 0/5] devlink: Introduce PCI PF, VF ports and attributes
  2019-07-01 12:27 [PATCH net-next 0/3] devlink: Introduce PCI PF, VF ports and attributes Parav Pandit
                   ` (7 preceding siblings ...)
  2019-07-06 18:23 ` [PATCH net-next v4 0/4] devlink: Introduce PCI PF, VF ports and attributes Parav Pandit
@ 2019-07-08  4:15 ` Parav Pandit
  2019-07-08  4:15   ` [PATCH net-next v5 1/5] devlink: Refactor physical port attributes Parav Pandit
                     ` (4 more replies)
  2019-07-09  4:17 ` [PATCH net-next v6 0/5] devlink: Introduce PCI PF, VF ports and attributes Parav Pandit
  9 siblings, 5 replies; 71+ messages in thread
From: Parav Pandit @ 2019-07-08  4:15 UTC (permalink / raw)
  To: netdev; +Cc: jiri, saeedm, jakub.kicinski, Parav Pandit

This patchset carry forwards the work initiated in [1] and discussion
futher concluded at [2].

To improve visibility of representor netdevice, its association with
PF or VF, physical port, two new devlink port flavours are added as
PCI PF and PCI VF ports.

A sample eswitch view can be seen below, which will be futher extended to
mdev subdevices of a PCI function in future.

Patch-1 moves physical port's attribute to new structure
Patch-2 enhances netlink response to consider port flavour
Patch-3,4 extends devlink port attributes and port flavour
Patch-5 extends mlx5 driver to register devlink ports for PF, VF and
physical link.

                                +---+      +---+
                              vf|   |      |   | pf
                                +-+-+      +-+-+
physical link <---------+         |          |
                        |         |          |
                        |         |          |
                      +-+-+     +-+-+      +-+-+
                      | 1 |     | 2 |      | 3 |
                   +--+---+-----+---+------+---+--+
                   |  physical   vf         pf    |
                   |  port       port       port  |
                   |                              |
                   |             eswitch          |
                   |                              |
                   +------------------------------+

[1] https://www.spinics.net/lists/netdev/msg555797.html
[2] https://marc.info/?l=linux-netdev&m=155354609408485&w=2

---
Changelog:
v4->v5:
 - Split first patch to two patches to handle netlink response in
   separate patch.
 - Corrected typo 'otwerwise' to 'otherwise' in patches 3 and 4.
v3->v4:
 - Addressed comments from Jiri.
 - Split first patch to two patches.
 - Renamed phys_port to physical to be consistent with pci_pf.
 - Removed port_number from __devlink_port_attrs_set and moved
   assignment to caller function.
 - Used capital letter while moving old comment to new structure.
 - Removed helper function is_devlink_phy_port_num_supported().
v2->v3:
 - Made port_number and split_port_number applicable only to
   physical port flavours.
v1->v2:
 - Updated new APIs and mlx5 driver to drop port_number for PF, VF
   attributes
 - Updated port_number comment for its usage
 - Limited putting port_number to physical ports


Parav Pandit (5):
  devlink: Refactor physical port attributes
  devlink: Return physical port fields only for applicable port flavours
  devlink: Introduce PCI PF port flavour and port attribute
  devlink: Introduce PCI VF port flavour and port attribute
  net/mlx5e: Register devlink ports for physical link, PCI PF, VFs

 .../net/ethernet/mellanox/mlx5/core/en_rep.c  | 108 ++++++++++----
 .../net/ethernet/mellanox/mlx5/core/en_rep.h  |   1 +
 include/net/devlink.h                         |  31 +++-
 include/uapi/linux/devlink.h                  |  11 ++
 net/core/devlink.c                            | 135 +++++++++++++++---
 5 files changed, 233 insertions(+), 53 deletions(-)

-- 
2.19.2


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

* [PATCH net-next v5 1/5] devlink: Refactor physical port attributes
  2019-07-08  4:15 ` [PATCH net-next v5 0/5] devlink: Introduce PCI PF, VF ports and attributes Parav Pandit
@ 2019-07-08  4:15   ` Parav Pandit
  2019-07-08 14:44     ` Jiri Pirko
  2019-07-08  4:15   ` [PATCH net-next v5 2/5] devlink: Return physical port fields only for applicable port flavours Parav Pandit
                     ` (3 subsequent siblings)
  4 siblings, 1 reply; 71+ messages in thread
From: Parav Pandit @ 2019-07-08  4:15 UTC (permalink / raw)
  To: netdev; +Cc: jiri, saeedm, jakub.kicinski, Parav Pandit

To support additional devlink port flavours and to support few common
and few different port attributes, move physical port attributes to a
different structure.

Signed-off-by: Parav Pandit <parav@mellanox.com>
---
Changelog:
v4->v5:
 - Addressed comments from Jiri.
 - Moved check for physical port flavours check to separate patch.
v3->v4:
 - Addressed comments from Jiri.
 - Renamed phys_port to physical to be consistent with pci_pf.
 - Removed port_number from __devlink_port_attrs_set and moved
   assigment to caller function.
 - Used capital letter while moving old comment to new structure.
 - Removed helper function is_devlink_phy_port_num_supported().
v2->v3:
 - Address comments from Jakub.
 - Made port_number and split_port_number applicable only to
   physical port flavours by having in union.
v1->v2:
 - Limited port_num attribute to physical ports
 - Updated PCI PF attribute set API to not have port_number
---
 include/net/devlink.h | 13 ++++++++--
 net/core/devlink.c    | 59 ++++++++++++++++++++++++++++---------------
 2 files changed, 50 insertions(+), 22 deletions(-)

diff --git a/include/net/devlink.h b/include/net/devlink.h
index 6625ea068d5e..c79a1370867a 100644
--- a/include/net/devlink.h
+++ b/include/net/devlink.h
@@ -38,14 +38,23 @@ struct devlink {
 	char priv[0] __aligned(NETDEV_ALIGN);
 };
 
+struct devlink_port_phys_attrs {
+	u32 port_number; /* Same value as "split group".
+			  * A physical port which is visible to the user
+			  * for a given port flavour.
+			  */
+	u32 split_subport_number;
+};
+
 struct devlink_port_attrs {
 	u8 set:1,
 	   split:1,
 	   switch_port:1;
 	enum devlink_port_flavour flavour;
-	u32 port_number; /* same value as "split group" */
-	u32 split_subport_number;
 	struct netdev_phys_item_id switch_id;
+	union {
+		struct devlink_port_phys_attrs physical;
+	};
 };
 
 struct devlink_port {
diff --git a/net/core/devlink.c b/net/core/devlink.c
index 89c533778135..abe50a8e25c6 100644
--- a/net/core/devlink.c
+++ b/net/core/devlink.c
@@ -515,14 +515,16 @@ static int devlink_nl_port_attrs_put(struct sk_buff *msg,
 		return 0;
 	if (nla_put_u16(msg, DEVLINK_ATTR_PORT_FLAVOUR, attrs->flavour))
 		return -EMSGSIZE;
-	if (nla_put_u32(msg, DEVLINK_ATTR_PORT_NUMBER, attrs->port_number))
+	if (nla_put_u32(msg, DEVLINK_ATTR_PORT_NUMBER,
+			attrs->physical.port_number))
 		return -EMSGSIZE;
 	if (!attrs->split)
 		return 0;
-	if (nla_put_u32(msg, DEVLINK_ATTR_PORT_SPLIT_GROUP, attrs->port_number))
+	if (nla_put_u32(msg, DEVLINK_ATTR_PORT_SPLIT_GROUP,
+			attrs->physical.port_number))
 		return -EMSGSIZE;
 	if (nla_put_u32(msg, DEVLINK_ATTR_PORT_SPLIT_SUBPORT_NUMBER,
-			attrs->split_subport_number))
+			attrs->physical.split_subport_number))
 		return -EMSGSIZE;
 	return 0;
 }
@@ -5738,6 +5740,29 @@ void devlink_port_type_clear(struct devlink_port *devlink_port)
 }
 EXPORT_SYMBOL_GPL(devlink_port_type_clear);
 
+static int __devlink_port_attrs_set(struct devlink_port *devlink_port,
+				    enum devlink_port_flavour flavour,
+				    const unsigned char *switch_id,
+				    unsigned char switch_id_len)
+{
+	struct devlink_port_attrs *attrs = &devlink_port->attrs;
+
+	if (WARN_ON(devlink_port->registered))
+		return -EEXIST;
+	attrs->set = true;
+	attrs->flavour = flavour;
+	if (switch_id) {
+		attrs->switch_port = true;
+		if (WARN_ON(switch_id_len > MAX_PHYS_ITEM_ID_LEN))
+			switch_id_len = MAX_PHYS_ITEM_ID_LEN;
+		memcpy(attrs->switch_id.id, switch_id, switch_id_len);
+		attrs->switch_id.id_len = switch_id_len;
+	} else {
+		attrs->switch_port = false;
+	}
+	return 0;
+}
+
 /**
  *	devlink_port_attrs_set - Set port attributes
  *
@@ -5760,23 +5785,15 @@ void devlink_port_attrs_set(struct devlink_port *devlink_port,
 			    unsigned char switch_id_len)
 {
 	struct devlink_port_attrs *attrs = &devlink_port->attrs;
+	int ret;
 
-	if (WARN_ON(devlink_port->registered))
+	ret = __devlink_port_attrs_set(devlink_port, flavour,
+				       switch_id, switch_id_len);
+	if (ret)
 		return;
-	attrs->set = true;
-	attrs->flavour = flavour;
-	attrs->port_number = port_number;
 	attrs->split = split;
-	attrs->split_subport_number = split_subport_number;
-	if (switch_id) {
-		attrs->switch_port = true;
-		if (WARN_ON(switch_id_len > MAX_PHYS_ITEM_ID_LEN))
-			switch_id_len = MAX_PHYS_ITEM_ID_LEN;
-		memcpy(attrs->switch_id.id, switch_id, switch_id_len);
-		attrs->switch_id.id_len = switch_id_len;
-	} else {
-		attrs->switch_port = false;
-	}
+	attrs->physical.port_number = port_number;
+	attrs->physical.split_subport_number = split_subport_number;
 }
 EXPORT_SYMBOL_GPL(devlink_port_attrs_set);
 
@@ -5792,10 +5809,12 @@ static int __devlink_port_phys_port_name_get(struct devlink_port *devlink_port,
 	switch (attrs->flavour) {
 	case DEVLINK_PORT_FLAVOUR_PHYSICAL:
 		if (!attrs->split)
-			n = snprintf(name, len, "p%u", attrs->port_number);
+			n = snprintf(name, len, "p%u",
+				     attrs->physical.port_number);
 		else
-			n = snprintf(name, len, "p%us%u", attrs->port_number,
-				     attrs->split_subport_number);
+			n = snprintf(name, len, "p%us%u",
+				     attrs->physical.port_number,
+				     attrs->physical.split_subport_number);
 		break;
 	case DEVLINK_PORT_FLAVOUR_CPU:
 	case DEVLINK_PORT_FLAVOUR_DSA:
-- 
2.19.2


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

* [PATCH net-next v5 2/5] devlink: Return physical port fields only for applicable port flavours
  2019-07-08  4:15 ` [PATCH net-next v5 0/5] devlink: Introduce PCI PF, VF ports and attributes Parav Pandit
  2019-07-08  4:15   ` [PATCH net-next v5 1/5] devlink: Refactor physical port attributes Parav Pandit
@ 2019-07-08  4:15   ` Parav Pandit
  2019-07-08 14:44     ` Jiri Pirko
  2019-07-08  4:15   ` [PATCH net-next v5 3/5] devlink: Introduce PCI PF port flavour and port attribute Parav Pandit
                     ` (2 subsequent siblings)
  4 siblings, 1 reply; 71+ messages in thread
From: Parav Pandit @ 2019-07-08  4:15 UTC (permalink / raw)
  To: netdev; +Cc: jiri, saeedm, jakub.kicinski, Parav Pandit

Physical port number and split group fields are applicable only to
physical port flavours such as PHYSICAL, CPU and DSA.
Hence limit returning those values in netlink response to such port
flavours.

Signed-off-by: Parav Pandit <parav@mellanox.com>
---
 net/core/devlink.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/net/core/devlink.c b/net/core/devlink.c
index abe50a8e25c6..3e5f8204c36f 100644
--- a/net/core/devlink.c
+++ b/net/core/devlink.c
@@ -515,6 +515,10 @@ static int devlink_nl_port_attrs_put(struct sk_buff *msg,
 		return 0;
 	if (nla_put_u16(msg, DEVLINK_ATTR_PORT_FLAVOUR, attrs->flavour))
 		return -EMSGSIZE;
+	if (devlink_port->attrs.flavour != DEVLINK_PORT_FLAVOUR_PHYSICAL &&
+	    devlink_port->attrs.flavour != DEVLINK_PORT_FLAVOUR_CPU &&
+	    devlink_port->attrs.flavour != DEVLINK_PORT_FLAVOUR_DSA)
+		return 0;
 	if (nla_put_u32(msg, DEVLINK_ATTR_PORT_NUMBER,
 			attrs->physical.port_number))
 		return -EMSGSIZE;
-- 
2.19.2


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

* [PATCH net-next v5 3/5] devlink: Introduce PCI PF port flavour and port attribute
  2019-07-08  4:15 ` [PATCH net-next v5 0/5] devlink: Introduce PCI PF, VF ports and attributes Parav Pandit
  2019-07-08  4:15   ` [PATCH net-next v5 1/5] devlink: Refactor physical port attributes Parav Pandit
  2019-07-08  4:15   ` [PATCH net-next v5 2/5] devlink: Return physical port fields only for applicable port flavours Parav Pandit
@ 2019-07-08  4:15   ` Parav Pandit
  2019-07-08 21:14     ` Jakub Kicinski
  2019-07-08  4:15   ` [PATCH net-next v5 4/5] devlink: Introduce PCI VF " Parav Pandit
  2019-07-08  4:15   ` [PATCH net-next v5 5/5] net/mlx5e: Register devlink ports for physical link, PCI PF, VFs Parav Pandit
  4 siblings, 1 reply; 71+ messages in thread
From: Parav Pandit @ 2019-07-08  4:15 UTC (permalink / raw)
  To: netdev; +Cc: jiri, saeedm, jakub.kicinski, Parav Pandit

In an eswitch, PCI PF may have port which is normally represented
using a representor netdevice.
To have better visibility of eswitch port, its association with
PF and a representor netdevice, introduce a PCI PF port
flavour and port attriute.

When devlink port flavour is PCI PF, fill up PCI PF attributes of the
port.

Extend port name creation using PCI PF number on best effort basis.
So that vendor drivers can skip defining their own scheme.

$ devlink port show
pci/0000:05:00.0/0: type eth netdev eth0 flavour pcipf pfnum 0

Acked-by: Jiri Pirko <jiri@mellanox.com>
Signed-off-by: Parav Pandit <parav@mellanox.com>
---
Changelog:
v4->v5:
 - Corrected typo 'otwerwise' to 'otherwise'
---
 include/net/devlink.h        |  8 ++++++++
 include/uapi/linux/devlink.h |  5 +++++
 net/core/devlink.c           | 34 ++++++++++++++++++++++++++++++++++
 3 files changed, 47 insertions(+)

diff --git a/include/net/devlink.h b/include/net/devlink.h
index c79a1370867a..2a8eaaff3d4b 100644
--- a/include/net/devlink.h
+++ b/include/net/devlink.h
@@ -46,6 +46,10 @@ struct devlink_port_phys_attrs {
 	u32 split_subport_number;
 };
 
+struct devlink_port_pci_pf_attrs {
+	u16 pf;	/* Associated PCI PF for this port. */
+};
+
 struct devlink_port_attrs {
 	u8 set:1,
 	   split:1,
@@ -54,6 +58,7 @@ struct devlink_port_attrs {
 	struct netdev_phys_item_id switch_id;
 	union {
 		struct devlink_port_phys_attrs physical;
+		struct devlink_port_pci_pf_attrs pci_pf;
 	};
 };
 
@@ -599,6 +604,9 @@ void devlink_port_attrs_set(struct devlink_port *devlink_port,
 			    u32 split_subport_number,
 			    const unsigned char *switch_id,
 			    unsigned char switch_id_len);
+void devlink_port_attrs_pci_pf_set(struct devlink_port *devlink_port,
+				   const unsigned char *switch_id,
+				   unsigned char switch_id_len, u16 pf);
 int devlink_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/include/uapi/linux/devlink.h b/include/uapi/linux/devlink.h
index 5287b42c181f..f7323884c3fe 100644
--- a/include/uapi/linux/devlink.h
+++ b/include/uapi/linux/devlink.h
@@ -169,6 +169,10 @@ enum devlink_port_flavour {
 	DEVLINK_PORT_FLAVOUR_DSA, /* Distributed switch architecture
 				   * interconnect port.
 				   */
+	DEVLINK_PORT_FLAVOUR_PCI_PF, /* Represents eswitch port for
+				      * the PCI PF. It is an internal
+				      * port that faces the PCI PF.
+				      */
 };
 
 enum devlink_param_cmode {
@@ -337,6 +341,7 @@ enum devlink_attr {
 	DEVLINK_ATTR_FLASH_UPDATE_STATUS_DONE,	/* u64 */
 	DEVLINK_ATTR_FLASH_UPDATE_STATUS_TOTAL,	/* u64 */
 
+	DEVLINK_ATTR_PORT_PCI_PF_NUMBER,	/* u16 */
 	/* add new attributes above here, update the policy in devlink.c */
 
 	__DEVLINK_ATTR_MAX,
diff --git a/net/core/devlink.c b/net/core/devlink.c
index 3e5f8204c36f..88b2cf207cb2 100644
--- a/net/core/devlink.c
+++ b/net/core/devlink.c
@@ -519,6 +519,11 @@ static int devlink_nl_port_attrs_put(struct sk_buff *msg,
 	    devlink_port->attrs.flavour != DEVLINK_PORT_FLAVOUR_CPU &&
 	    devlink_port->attrs.flavour != DEVLINK_PORT_FLAVOUR_DSA)
 		return 0;
+	if (devlink_port->attrs.flavour == DEVLINK_PORT_FLAVOUR_PCI_PF) {
+		if (nla_put_u16(msg, DEVLINK_ATTR_PORT_PCI_PF_NUMBER,
+				attrs->pci_pf.pf))
+			return -EMSGSIZE;
+	}
 	if (nla_put_u32(msg, DEVLINK_ATTR_PORT_NUMBER,
 			attrs->physical.port_number))
 		return -EMSGSIZE;
@@ -5801,6 +5806,32 @@ void devlink_port_attrs_set(struct devlink_port *devlink_port,
 }
 EXPORT_SYMBOL_GPL(devlink_port_attrs_set);
 
+/**
+ *	devlink_port_attrs_pci_pf_set - Set PCI PF port attributes
+ *
+ *	@devlink_port: devlink port
+ *	@pf: associated PF for the devlink port instance
+ *	@switch_id: if the port is part of switch, this is buffer with ID,
+ *	            otherwise this is NULL
+ *	@switch_id_len: length of the switch_id buffer
+ */
+void devlink_port_attrs_pci_pf_set(struct devlink_port *devlink_port,
+				   const unsigned char *switch_id,
+				   unsigned char switch_id_len, u16 pf)
+{
+	struct devlink_port_attrs *attrs = &devlink_port->attrs;
+	int ret;
+
+	ret = __devlink_port_attrs_set(devlink_port,
+				       DEVLINK_PORT_FLAVOUR_PCI_PF,
+				       switch_id, switch_id_len);
+	if (ret)
+		return;
+
+	attrs->pci_pf.pf = pf;
+}
+EXPORT_SYMBOL_GPL(devlink_port_attrs_pci_pf_set);
+
 static int __devlink_port_phys_port_name_get(struct devlink_port *devlink_port,
 					     char *name, size_t len)
 {
@@ -5827,6 +5858,9 @@ static int __devlink_port_phys_port_name_get(struct devlink_port *devlink_port,
 		 */
 		WARN_ON(1);
 		return -EINVAL;
+	case DEVLINK_PORT_FLAVOUR_PCI_PF:
+		n = snprintf(name, len, "pf%u", attrs->pci_pf.pf);
+		break;
 	}
 
 	if (n >= len)
-- 
2.19.2


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

* [PATCH net-next v5 4/5] devlink: Introduce PCI VF port flavour and port attribute
  2019-07-08  4:15 ` [PATCH net-next v5 0/5] devlink: Introduce PCI PF, VF ports and attributes Parav Pandit
                     ` (2 preceding siblings ...)
  2019-07-08  4:15   ` [PATCH net-next v5 3/5] devlink: Introduce PCI PF port flavour and port attribute Parav Pandit
@ 2019-07-08  4:15   ` Parav Pandit
  2019-07-08  4:15   ` [PATCH net-next v5 5/5] net/mlx5e: Register devlink ports for physical link, PCI PF, VFs Parav Pandit
  4 siblings, 0 replies; 71+ messages in thread
From: Parav Pandit @ 2019-07-08  4:15 UTC (permalink / raw)
  To: netdev; +Cc: jiri, saeedm, jakub.kicinski, Parav Pandit

In an eswitch, PCI VF may have port which is normally represented using
a representor netdevice.
To have better visibility of eswitch port, its association with VF,
and its representor netdevice, introduce a PCI VF port flavour.

When devlink port flavour is PCI VF, fill up PCI VF attributes of
the port.

Extend port name creation using PCI PF and VF number scheme on best
effort basis, so that vendor drivers can skip defining their own scheme.

$ devlink port show
pci/0000:05:00.0/0: type eth netdev eth0 flavour pcipf pfnum 0
pci/0000:05:00.0/1: type eth netdev eth1 flavour pcivf pfnum 0 vfnum 0
pci/0000:05:00.0/2: type eth netdev eth2 flavour pcivf pfnum 0 vfnum 1

Acked-by: Jiri Pirko <jiri@mellanox.com>
Signed-off-by: Parav Pandit <parav@mellanox.com>
---
Changelog:
v4->v5:
 - Corrected typo 'otwerwise' to 'otherwise'
---
 include/net/devlink.h        | 10 ++++++++++
 include/uapi/linux/devlink.h |  6 ++++++
 net/core/devlink.c           | 38 ++++++++++++++++++++++++++++++++++++
 3 files changed, 54 insertions(+)

diff --git a/include/net/devlink.h b/include/net/devlink.h
index 2a8eaaff3d4b..a02f639ad519 100644
--- a/include/net/devlink.h
+++ b/include/net/devlink.h
@@ -50,6 +50,11 @@ struct devlink_port_pci_pf_attrs {
 	u16 pf;	/* Associated PCI PF for this port. */
 };
 
+struct devlink_port_pci_vf_attrs {
+	u16 pf;	/* Associated PCI PF for this port. */
+	u16 vf;	/* Associated PCI VF for of the PCI PF for this port. */
+};
+
 struct devlink_port_attrs {
 	u8 set:1,
 	   split:1,
@@ -59,6 +64,7 @@ struct devlink_port_attrs {
 	union {
 		struct devlink_port_phys_attrs physical;
 		struct devlink_port_pci_pf_attrs pci_pf;
+		struct devlink_port_pci_vf_attrs pci_vf;
 	};
 };
 
@@ -607,6 +613,10 @@ void devlink_port_attrs_set(struct devlink_port *devlink_port,
 void devlink_port_attrs_pci_pf_set(struct devlink_port *devlink_port,
 				   const unsigned char *switch_id,
 				   unsigned char switch_id_len, u16 pf);
+void devlink_port_attrs_pci_vf_set(struct devlink_port *devlink_port,
+				   const unsigned char *switch_id,
+				   unsigned char switch_id_len,
+				   u16 pf, u16 vf);
 int devlink_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/include/uapi/linux/devlink.h b/include/uapi/linux/devlink.h
index f7323884c3fe..ffc993256527 100644
--- a/include/uapi/linux/devlink.h
+++ b/include/uapi/linux/devlink.h
@@ -173,6 +173,10 @@ enum devlink_port_flavour {
 				      * the PCI PF. It is an internal
 				      * port that faces the PCI PF.
 				      */
+	DEVLINK_PORT_FLAVOUR_PCI_VF, /* Represents eswitch port
+				      * for the PCI VF. It is an internal
+				      * port that faces the PCI VF.
+				      */
 };
 
 enum devlink_param_cmode {
@@ -342,6 +346,8 @@ enum devlink_attr {
 	DEVLINK_ATTR_FLASH_UPDATE_STATUS_TOTAL,	/* u64 */
 
 	DEVLINK_ATTR_PORT_PCI_PF_NUMBER,	/* u16 */
+	DEVLINK_ATTR_PORT_PCI_VF_NUMBER,	/* u16 */
+
 	/* add new attributes above here, update the policy in devlink.c */
 
 	__DEVLINK_ATTR_MAX,
diff --git a/net/core/devlink.c b/net/core/devlink.c
index 88b2cf207cb2..ec07dbab93c2 100644
--- a/net/core/devlink.c
+++ b/net/core/devlink.c
@@ -523,6 +523,12 @@ static int devlink_nl_port_attrs_put(struct sk_buff *msg,
 		if (nla_put_u16(msg, DEVLINK_ATTR_PORT_PCI_PF_NUMBER,
 				attrs->pci_pf.pf))
 			return -EMSGSIZE;
+	} else if (devlink_port->attrs.flavour == DEVLINK_PORT_FLAVOUR_PCI_VF) {
+		if (nla_put_u16(msg, DEVLINK_ATTR_PORT_PCI_PF_NUMBER,
+				attrs->pci_vf.pf) ||
+		    nla_put_u16(msg, DEVLINK_ATTR_PORT_PCI_VF_NUMBER,
+				attrs->pci_vf.vf))
+			return -EMSGSIZE;
 	}
 	if (nla_put_u32(msg, DEVLINK_ATTR_PORT_NUMBER,
 			attrs->physical.port_number))
@@ -5832,6 +5838,34 @@ void devlink_port_attrs_pci_pf_set(struct devlink_port *devlink_port,
 }
 EXPORT_SYMBOL_GPL(devlink_port_attrs_pci_pf_set);
 
+/**
+ *	devlink_port_attrs_pci_vf_set - Set PCI VF port attributes
+ *
+ *	@devlink_port: devlink port
+ *	@pf: associated PF for the devlink port instance
+ *	@vf: associated VF of a PF for the devlink port instance
+ *	@switch_id: if the port is part of switch, this is buffer with ID,
+ *	            otherwise this is NULL
+ *	@switch_id_len: length of the switch_id buffer
+ */
+void devlink_port_attrs_pci_vf_set(struct devlink_port *devlink_port,
+				   const unsigned char *switch_id,
+				   unsigned char switch_id_len,
+				   u16 pf, u16 vf)
+{
+	struct devlink_port_attrs *attrs = &devlink_port->attrs;
+	int ret;
+
+	ret = __devlink_port_attrs_set(devlink_port,
+				       DEVLINK_PORT_FLAVOUR_PCI_VF,
+				       switch_id, switch_id_len);
+	if (ret)
+		return;
+	attrs->pci_vf.pf = pf;
+	attrs->pci_vf.vf = vf;
+}
+EXPORT_SYMBOL_GPL(devlink_port_attrs_pci_vf_set);
+
 static int __devlink_port_phys_port_name_get(struct devlink_port *devlink_port,
 					     char *name, size_t len)
 {
@@ -5861,6 +5895,10 @@ static int __devlink_port_phys_port_name_get(struct devlink_port *devlink_port,
 	case DEVLINK_PORT_FLAVOUR_PCI_PF:
 		n = snprintf(name, len, "pf%u", attrs->pci_pf.pf);
 		break;
+	case DEVLINK_PORT_FLAVOUR_PCI_VF:
+		n = snprintf(name, len, "pf%uvf%u",
+			     attrs->pci_vf.pf, attrs->pci_vf.vf);
+		break;
 	}
 
 	if (n >= len)
-- 
2.19.2


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

* [PATCH net-next v5 5/5] net/mlx5e: Register devlink ports for physical link, PCI PF, VFs
  2019-07-08  4:15 ` [PATCH net-next v5 0/5] devlink: Introduce PCI PF, VF ports and attributes Parav Pandit
                     ` (3 preceding siblings ...)
  2019-07-08  4:15   ` [PATCH net-next v5 4/5] devlink: Introduce PCI VF " Parav Pandit
@ 2019-07-08  4:15   ` Parav Pandit
  4 siblings, 0 replies; 71+ messages in thread
From: Parav Pandit @ 2019-07-08  4:15 UTC (permalink / raw)
  To: netdev; +Cc: jiri, saeedm, jakub.kicinski, Parav Pandit

Register devlink port of physical port, PCI PF and PCI VF flavour
for each PF, VF when a given devlink instance is in switchdev mode.

Implement ndo_get_devlink_port callback API to make use of registered
devlink ports.
This eliminates ndo_get_phys_port_name() and ndo_get_port_parent_id()
callbacks. Hence, remove them.

An example output with 2 VFs, without a PF and single uplink port is
below.

$devlink port show
pci/0000:06:00.0/65535: type eth netdev ens2f0 flavour physical
pci/0000:05:00.0/1: type eth netdev eth1 flavour pcivf pfnum 0 vfnum 0
pci/0000:05:00.0/2: type eth netdev eth2 flavour pcivf pfnum 0 vfnum 1

Reviewed-by: Roi Dayan <roid@mellanox.com>
Acked-by: Jiri Pirko <jiri@mellanox.com>
Signed-off-by: Parav Pandit <parav@mellanox.com>
---
 .../net/ethernet/mellanox/mlx5/core/en_rep.c  | 108 +++++++++++++-----
 .../net/ethernet/mellanox/mlx5/core/en_rep.h  |   1 +
 2 files changed, 78 insertions(+), 31 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_rep.c b/drivers/net/ethernet/mellanox/mlx5/core/en_rep.c
index 529f8e4b32c6..6810b9fa0705 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_rep.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_rep.c
@@ -37,6 +37,7 @@
 #include <net/act_api.h>
 #include <net/netevent.h>
 #include <net/arp.h>
+#include <net/devlink.h>
 
 #include "eswitch.h"
 #include "en.h"
@@ -1119,32 +1120,6 @@ static int mlx5e_rep_close(struct net_device *dev)
 	return ret;
 }
 
-static int mlx5e_rep_get_phys_port_name(struct net_device *dev,
-					char *buf, size_t len)
-{
-	struct mlx5e_priv *priv = netdev_priv(dev);
-	struct mlx5e_rep_priv *rpriv = priv->ppriv;
-	struct mlx5_eswitch_rep *rep = rpriv->rep;
-	unsigned int fn;
-	int ret;
-
-	fn = PCI_FUNC(priv->mdev->pdev->devfn);
-	if (fn >= MLX5_MAX_PORTS)
-		return -EOPNOTSUPP;
-
-	if (rep->vport == MLX5_VPORT_UPLINK)
-		ret = snprintf(buf, len, "p%d", fn);
-	else if (rep->vport == MLX5_VPORT_PF)
-		ret = snprintf(buf, len, "pf%d", fn);
-	else
-		ret = snprintf(buf, len, "pf%dvf%d", fn, rep->vport - 1);
-
-	if (ret >= len)
-		return -EOPNOTSUPP;
-
-	return 0;
-}
-
 static int
 mlx5e_rep_setup_tc_cls_flower(struct mlx5e_priv *priv,
 			      struct tc_cls_flower_offload *cls_flower, int flags)
@@ -1298,17 +1273,24 @@ static int mlx5e_uplink_rep_set_vf_vlan(struct net_device *dev, int vf, u16 vlan
 	return 0;
 }
 
+static struct devlink_port *mlx5e_get_devlink_port(struct net_device *dev)
+{
+	struct mlx5e_priv *priv = netdev_priv(dev);
+	struct mlx5e_rep_priv *rpriv = priv->ppriv;
+
+	return &rpriv->dl_port;
+}
+
 static const struct net_device_ops mlx5e_netdev_ops_rep = {
 	.ndo_open                = mlx5e_rep_open,
 	.ndo_stop                = mlx5e_rep_close,
 	.ndo_start_xmit          = mlx5e_xmit,
-	.ndo_get_phys_port_name  = mlx5e_rep_get_phys_port_name,
 	.ndo_setup_tc            = mlx5e_rep_setup_tc,
+	.ndo_get_devlink_port = mlx5e_get_devlink_port,
 	.ndo_get_stats64         = mlx5e_rep_get_stats,
 	.ndo_has_offload_stats	 = mlx5e_rep_has_offload_stats,
 	.ndo_get_offload_stats	 = mlx5e_rep_get_offload_stats,
 	.ndo_change_mtu          = mlx5e_rep_change_mtu,
-	.ndo_get_port_parent_id	 = mlx5e_rep_get_port_parent_id,
 };
 
 static const struct net_device_ops mlx5e_netdev_ops_uplink_rep = {
@@ -1316,8 +1298,8 @@ static const struct net_device_ops mlx5e_netdev_ops_uplink_rep = {
 	.ndo_stop                = mlx5e_close,
 	.ndo_start_xmit          = mlx5e_xmit,
 	.ndo_set_mac_address     = mlx5e_uplink_rep_set_mac,
-	.ndo_get_phys_port_name  = mlx5e_rep_get_phys_port_name,
 	.ndo_setup_tc            = mlx5e_rep_setup_tc,
+	.ndo_get_devlink_port = mlx5e_get_devlink_port,
 	.ndo_get_stats64         = mlx5e_get_stats,
 	.ndo_has_offload_stats	 = mlx5e_rep_has_offload_stats,
 	.ndo_get_offload_stats	 = mlx5e_rep_get_offload_stats,
@@ -1330,7 +1312,6 @@ static const struct net_device_ops mlx5e_netdev_ops_uplink_rep = {
 	.ndo_get_vf_config       = mlx5e_get_vf_config,
 	.ndo_get_vf_stats        = mlx5e_get_vf_stats,
 	.ndo_set_vf_vlan         = mlx5e_uplink_rep_set_vf_vlan,
-	.ndo_get_port_parent_id	 = mlx5e_rep_get_port_parent_id,
 	.ndo_set_features        = mlx5e_set_features,
 };
 
@@ -1731,6 +1712,55 @@ static const struct mlx5e_profile mlx5e_uplink_rep_profile = {
 	.max_tc			= MLX5E_MAX_NUM_TC,
 };
 
+static bool
+is_devlink_port_supported(const struct mlx5_core_dev *dev,
+			  const struct mlx5e_rep_priv *rpriv)
+{
+	return rpriv->rep->vport == MLX5_VPORT_UPLINK ||
+	       rpriv->rep->vport == MLX5_VPORT_PF ||
+	       mlx5_eswitch_is_vf_vport(dev->priv.eswitch, rpriv->rep->vport);
+}
+
+static int register_devlink_port(struct mlx5_core_dev *dev,
+				 struct mlx5e_rep_priv *rpriv)
+{
+	struct devlink *devlink = priv_to_devlink(dev);
+	struct mlx5_eswitch_rep *rep = rpriv->rep;
+	struct netdev_phys_item_id ppid = {};
+	int ret;
+
+	if (!is_devlink_port_supported(dev, rpriv))
+		return 0;
+
+	ret = mlx5e_rep_get_port_parent_id(rpriv->netdev, &ppid);
+	if (ret)
+		return ret;
+
+	if (rep->vport == MLX5_VPORT_UPLINK)
+		devlink_port_attrs_set(&rpriv->dl_port,
+				       DEVLINK_PORT_FLAVOUR_PHYSICAL,
+				       PCI_FUNC(dev->pdev->devfn), false, 0,
+				       &ppid.id[0], ppid.id_len);
+	else if (rep->vport == MLX5_VPORT_PF)
+		devlink_port_attrs_pci_pf_set(&rpriv->dl_port,
+					      &ppid.id[0], ppid.id_len,
+					      dev->pdev->devfn);
+	else if (mlx5_eswitch_is_vf_vport(dev->priv.eswitch, rpriv->rep->vport))
+		devlink_port_attrs_pci_vf_set(&rpriv->dl_port,
+					      &ppid.id[0], ppid.id_len,
+					      dev->pdev->devfn,
+					      rep->vport - 1);
+
+	return devlink_port_register(devlink, &rpriv->dl_port, rep->vport);
+}
+
+static void unregister_devlink_port(struct mlx5_core_dev *dev,
+				    struct mlx5e_rep_priv *rpriv)
+{
+	if (is_devlink_port_supported(dev, rpriv))
+		devlink_port_unregister(&rpriv->dl_port);
+}
+
 /* e-Switch vport representors */
 static int
 mlx5e_vport_rep_load(struct mlx5_core_dev *dev, struct mlx5_eswitch_rep *rep)
@@ -1782,15 +1812,27 @@ mlx5e_vport_rep_load(struct mlx5_core_dev *dev, struct mlx5_eswitch_rep *rep)
 		goto err_detach_netdev;
 	}
 
+	err = register_devlink_port(dev, rpriv);
+	if (err) {
+		esw_warn(dev, "Failed to register devlink port %d\n",
+			 rep->vport);
+		goto err_neigh_cleanup;
+	}
+
 	err = register_netdev(netdev);
 	if (err) {
 		pr_warn("Failed to register representor netdev for vport %d\n",
 			rep->vport);
-		goto err_neigh_cleanup;
+		goto err_devlink_cleanup;
 	}
 
+	if (is_devlink_port_supported(dev, rpriv))
+		devlink_port_type_eth_set(&rpriv->dl_port, netdev);
 	return 0;
 
+err_devlink_cleanup:
+	unregister_devlink_port(dev, rpriv);
+
 err_neigh_cleanup:
 	mlx5e_rep_neigh_cleanup(rpriv);
 
@@ -1813,9 +1855,13 @@ mlx5e_vport_rep_unload(struct mlx5_eswitch_rep *rep)
 	struct mlx5e_rep_priv *rpriv = mlx5e_rep_to_rep_priv(rep);
 	struct net_device *netdev = rpriv->netdev;
 	struct mlx5e_priv *priv = netdev_priv(netdev);
+	struct mlx5_core_dev *dev = priv->mdev;
 	void *ppriv = priv->ppriv;
 
+	if (is_devlink_port_supported(dev, rpriv))
+		devlink_port_type_clear(&rpriv->dl_port);
 	unregister_netdev(netdev);
+	unregister_devlink_port(dev, rpriv);
 	mlx5e_rep_neigh_cleanup(rpriv);
 	mlx5e_detach_netdev(priv);
 	if (rep->vport == MLX5_VPORT_UPLINK)
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_rep.h b/drivers/net/ethernet/mellanox/mlx5/core/en_rep.h
index d4585f3b8cb2..c56e6ee4350c 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_rep.h
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_rep.h
@@ -86,6 +86,7 @@ struct mlx5e_rep_priv {
 	struct mlx5_flow_handle *vport_rx_rule;
 	struct list_head       vport_sqs_list;
 	struct mlx5_rep_uplink_priv uplink_priv; /* valid for uplink rep */
+	struct devlink_port dl_port;
 };
 
 static inline
-- 
2.19.2


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

* RE: [PATCH net-next v4 1/4] devlink: Refactor physical port attributes
  2019-07-07 19:47     ` Jiri Pirko
@ 2019-07-08  4:34       ` Parav Pandit
  0 siblings, 0 replies; 71+ messages in thread
From: Parav Pandit @ 2019-07-08  4:34 UTC (permalink / raw)
  To: Jiri Pirko; +Cc: netdev, Jiri Pirko, Saeed Mahameed, jakub.kicinski



> -----Original Message-----
> From: Jiri Pirko <jiri@resnulli.us>
> Sent: Monday, July 8, 2019 1:18 AM
> To: Parav Pandit <parav@mellanox.com>
> Cc: netdev@vger.kernel.org; Jiri Pirko <jiri@mellanox.com>; Saeed
> Mahameed <saeedm@mellanox.com>; jakub.kicinski@netronome.com
> Subject: Re: [PATCH net-next v4 1/4] devlink: Refactor physical port
> attributes
> 
> Sat, Jul 06, 2019 at 08:23:47PM CEST, parav@mellanox.com wrote:
> >To support additional devlink port flavours and to support few common
> >and few different port attributes, make following changes.
> >
> >1. Move physical port attributes to a different structure 2. Return
> >such attritubes in netlink response only for physical ports (PHYSICAL,
> >CPU and DSA)
> 
> 2 changes, 2 patches please.
Done in v5.

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

* Re: [PATCH net-next v5 1/5] devlink: Refactor physical port attributes
  2019-07-08  4:15   ` [PATCH net-next v5 1/5] devlink: Refactor physical port attributes Parav Pandit
@ 2019-07-08 14:44     ` Jiri Pirko
  0 siblings, 0 replies; 71+ messages in thread
From: Jiri Pirko @ 2019-07-08 14:44 UTC (permalink / raw)
  To: Parav Pandit; +Cc: netdev, jiri, saeedm, jakub.kicinski

Mon, Jul 08, 2019 at 06:15:45AM CEST, parav@mellanox.com wrote:
>To support additional devlink port flavours and to support few common
>and few different port attributes, move physical port attributes to a
>different structure.
>
>Signed-off-by: Parav Pandit <parav@mellanox.com>
>---
>Changelog:
>v4->v5:
> - Addressed comments from Jiri.
> - Moved check for physical port flavours check to separate patch.
>v3->v4:
> - Addressed comments from Jiri.
> - Renamed phys_port to physical to be consistent with pci_pf.
> - Removed port_number from __devlink_port_attrs_set and moved
>   assigment to caller function.
> - Used capital letter while moving old comment to new structure.
> - Removed helper function is_devlink_phy_port_num_supported().
>v2->v3:
> - Address comments from Jakub.
> - Made port_number and split_port_number applicable only to
>   physical port flavours by having in union.
>v1->v2:
> - Limited port_num attribute to physical ports
> - Updated PCI PF attribute set API to not have port_number
>---
> include/net/devlink.h | 13 ++++++++--
> net/core/devlink.c    | 59 ++++++++++++++++++++++++++++---------------
> 2 files changed, 50 insertions(+), 22 deletions(-)
>
>diff --git a/include/net/devlink.h b/include/net/devlink.h
>index 6625ea068d5e..c79a1370867a 100644
>--- a/include/net/devlink.h
>+++ b/include/net/devlink.h
>@@ -38,14 +38,23 @@ struct devlink {
> 	char priv[0] __aligned(NETDEV_ALIGN);
> };
> 
>+struct devlink_port_phys_attrs {
>+	u32 port_number; /* Same value as "split group".
>+			  * A physical port which is visible to the user
>+			  * for a given port flavour.
>+			  */
>+	u32 split_subport_number;
>+};
>+
> struct devlink_port_attrs {
> 	u8 set:1,
> 	   split:1,
> 	   switch_port:1;
> 	enum devlink_port_flavour flavour;
>-	u32 port_number; /* same value as "split group" */
>-	u32 split_subport_number;
> 	struct netdev_phys_item_id switch_id;
>+	union {
>+		struct devlink_port_phys_attrs physical;

You can shorten this to just "phys". Would be better.
With that
Acked-by: Jiri Pirko <jiri@mellanox.com>

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

* Re: [PATCH net-next v5 2/5] devlink: Return physical port fields only for applicable port flavours
  2019-07-08  4:15   ` [PATCH net-next v5 2/5] devlink: Return physical port fields only for applicable port flavours Parav Pandit
@ 2019-07-08 14:44     ` Jiri Pirko
  0 siblings, 0 replies; 71+ messages in thread
From: Jiri Pirko @ 2019-07-08 14:44 UTC (permalink / raw)
  To: Parav Pandit; +Cc: netdev, jiri, saeedm, jakub.kicinski

Mon, Jul 08, 2019 at 06:15:46AM CEST, parav@mellanox.com wrote:
>Physical port number and split group fields are applicable only to
>physical port flavours such as PHYSICAL, CPU and DSA.
>Hence limit returning those values in netlink response to such port
>flavours.
>
>Signed-off-by: Parav Pandit <parav@mellanox.com>

Acked-by: Jiri Pirko <jiri@mellanox.com>

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

* Re: [PATCH net-next v5 3/5] devlink: Introduce PCI PF port flavour and port attribute
  2019-07-08  4:15   ` [PATCH net-next v5 3/5] devlink: Introduce PCI PF port flavour and port attribute Parav Pandit
@ 2019-07-08 21:14     ` Jakub Kicinski
  2019-07-09  2:36       ` Parav Pandit
  0 siblings, 1 reply; 71+ messages in thread
From: Jakub Kicinski @ 2019-07-08 21:14 UTC (permalink / raw)
  To: Parav Pandit; +Cc: netdev, jiri, saeedm

On Sun,  7 Jul 2019 23:15:47 -0500, Parav Pandit wrote:
> diff --git a/net/core/devlink.c b/net/core/devlink.c
> index 3e5f8204c36f..88b2cf207cb2 100644
> --- a/net/core/devlink.c
> +++ b/net/core/devlink.c
> @@ -519,6 +519,11 @@ static int devlink_nl_port_attrs_put(struct sk_buff *msg,
>  	if (devlink_port->attrs.flavour != DEVLINK_PORT_FLAVOUR_PHYSICAL &&
>  	    devlink_port->attrs.flavour != DEVLINK_PORT_FLAVOUR_CPU &&
>  	    devlink_port->attrs.flavour != DEVLINK_PORT_FLAVOUR_DSA)
>  		return 0;
> +	if (devlink_port->attrs.flavour == DEVLINK_PORT_FLAVOUR_PCI_PF) {

Thanks for making the changes!  I'm not sure how this would work, tho.
We return early if flavour is not phys/cpu/dsa, so how can flavour be
pci here?..

> +		if (nla_put_u16(msg, DEVLINK_ATTR_PORT_PCI_PF_NUMBER,
> +				attrs->pci_pf.pf))
> +			return -EMSGSIZE;
> +	}
>  	if (nla_put_u32(msg, DEVLINK_ATTR_PORT_NUMBER,
>  			attrs->physical.port_number))
>  		return -EMSGSIZE;

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

* RE: [PATCH net-next v5 3/5] devlink: Introduce PCI PF port flavour and port attribute
  2019-07-08 21:14     ` Jakub Kicinski
@ 2019-07-09  2:36       ` Parav Pandit
  0 siblings, 0 replies; 71+ messages in thread
From: Parav Pandit @ 2019-07-09  2:36 UTC (permalink / raw)
  To: Jakub Kicinski; +Cc: netdev, Jiri Pirko, Saeed Mahameed



> -----Original Message-----
> From: Jakub Kicinski <jakub.kicinski@netronome.com>
> Sent: Tuesday, July 9, 2019 2:44 AM
> To: Parav Pandit <parav@mellanox.com>
> Cc: netdev@vger.kernel.org; Jiri Pirko <jiri@mellanox.com>; Saeed Mahameed
> <saeedm@mellanox.com>
> Subject: Re: [PATCH net-next v5 3/5] devlink: Introduce PCI PF port flavour and
> port attribute
> 
> On Sun,  7 Jul 2019 23:15:47 -0500, Parav Pandit wrote:
> > diff --git a/net/core/devlink.c b/net/core/devlink.c index
> > 3e5f8204c36f..88b2cf207cb2 100644
> > --- a/net/core/devlink.c
> > +++ b/net/core/devlink.c
> > @@ -519,6 +519,11 @@ static int devlink_nl_port_attrs_put(struct sk_buff
> *msg,
> >  	if (devlink_port->attrs.flavour != DEVLINK_PORT_FLAVOUR_PHYSICAL
> &&
> >  	    devlink_port->attrs.flavour != DEVLINK_PORT_FLAVOUR_CPU &&
> >  	    devlink_port->attrs.flavour != DEVLINK_PORT_FLAVOUR_DSA)
> >  		return 0;
> > +	if (devlink_port->attrs.flavour == DEVLINK_PORT_FLAVOUR_PCI_PF) {
> 
> Thanks for making the changes!  I'm not sure how this would work, tho.
> We return early if flavour is not phys/cpu/dsa, so how can flavour be pci here?..
> 
My bad. Hunk got applied at wrong place when I split the patch.
Correcting it along with physical to phys name change that Jiri suggested.

> > +		if (nla_put_u16(msg, DEVLINK_ATTR_PORT_PCI_PF_NUMBER,
> > +				attrs->pci_pf.pf))
> > +			return -EMSGSIZE;
> > +	}
> >  	if (nla_put_u32(msg, DEVLINK_ATTR_PORT_NUMBER,
> >  			attrs->physical.port_number))
> >  		return -EMSGSIZE;

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

* [PATCH net-next v6 0/5] devlink: Introduce PCI PF, VF ports and attributes
  2019-07-01 12:27 [PATCH net-next 0/3] devlink: Introduce PCI PF, VF ports and attributes Parav Pandit
                   ` (8 preceding siblings ...)
  2019-07-08  4:15 ` [PATCH net-next v5 0/5] devlink: Introduce PCI PF, VF ports and attributes Parav Pandit
@ 2019-07-09  4:17 ` Parav Pandit
  2019-07-09  4:17   ` [PATCH net-next v6 1/5] devlink: Refactor physical port attributes Parav Pandit
                     ` (5 more replies)
  9 siblings, 6 replies; 71+ messages in thread
From: Parav Pandit @ 2019-07-09  4:17 UTC (permalink / raw)
  To: netdev; +Cc: jiri, saeedm, jakub.kicinski, Parav Pandit

This patchset carry forwards the work initiated in [1] and discussion
futher concluded at [2].

To improve visibility of representor netdevice, its association with
PF or VF, physical port, two new devlink port flavours are added as
PCI PF and PCI VF ports.

A sample eswitch view can be seen below, which will be futher extended to
mdev subdevices of a PCI function in future.

Patch-1 moves physical port's attribute to new structure
Patch-2 enhances netlink response to consider port flavour
Patch-3,4 extends devlink port attributes and port flavour
Patch-5 extends mlx5 driver to register devlink ports for PF, VF and
physical link.

                                +---+      +---+
                              vf|   |      |   | pf
                                +-+-+      +-+-+
physical link <---------+         |          |
                        |         |          |
                        |         |          |
                      +-+-+     +-+-+      +-+-+
                      | 1 |     | 2 |      | 3 |
                   +--+---+-----+---+------+---+--+
                   |  physical   vf         pf    |
                   |  port       port       port  |
                   |                              |
                   |             eswitch          |
                   |                              |
                   +------------------------------+

[1] https://www.spinics.net/lists/netdev/msg555797.html
[2] https://marc.info/?l=linux-netdev&m=155354609408485&w=2

---
Changelog:
v5->v6:
 - Fixed port flavour check order for PCI PF vs other flavours in
   netlink response.
 - Changed 'physical' to 'phys'.
v4->v5:
 - Split first patch to two patches to handle netlink response in
   separate patch.
 - Corrected typo 'otwerwise' to 'otherwise' in patches 3 and 4.
v3->v4:
 - Addressed comments from Jiri.
 - Split first patch to two patches.
 - Renamed phys_port to physical to be consistent with pci_pf.
 - Removed port_number from __devlink_port_attrs_set and moved
   assignment to caller function.
 - Used capital letter while moving old comment to new structure.
 - Removed helper function is_devlink_phy_port_num_supported().
v2->v3:
 - Made port_number and split_port_number applicable only to
   physical port flavours.
v1->v2:
 - Updated new APIs and mlx5 driver to drop port_number for PF, VF
   attributes
 - Updated port_number comment for its usage
 - Limited putting port_number to physical ports

Parav Pandit (5):
  devlink: Refactor physical port attributes
  devlink: Return physical port fields only for applicable port flavours
  devlink: Introduce PCI PF port flavour and port attribute
  devlink: Introduce PCI VF port flavour and port attribute
  net/mlx5e: Register devlink ports for physical link, PCI PF, VFs

 .../net/ethernet/mellanox/mlx5/core/en_rep.c  | 108 ++++++++++----
 .../net/ethernet/mellanox/mlx5/core/en_rep.h  |   1 +
 include/net/devlink.h                         |  31 +++-
 include/uapi/linux/devlink.h                  |  11 ++
 net/core/devlink.c                            | 134 +++++++++++++++---
 5 files changed, 232 insertions(+), 53 deletions(-)

-- 
2.19.2


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

* [PATCH net-next v6 1/5] devlink: Refactor physical port attributes
  2019-07-09  4:17 ` [PATCH net-next v6 0/5] devlink: Introduce PCI PF, VF ports and attributes Parav Pandit
@ 2019-07-09  4:17   ` Parav Pandit
  2019-07-09  4:17   ` [PATCH net-next v6 2/5] devlink: Return physical port fields only for applicable port flavours Parav Pandit
                     ` (4 subsequent siblings)
  5 siblings, 0 replies; 71+ messages in thread
From: Parav Pandit @ 2019-07-09  4:17 UTC (permalink / raw)
  To: netdev; +Cc: jiri, saeedm, jakub.kicinski, Parav Pandit

To support additional devlink port flavours and to support few common
and few different port attributes, move physical port attributes to a
different structure.

Acked-by: Jiri Pirko <jiri@mellanox.com>
Signed-off-by: Parav Pandit <parav@mellanox.com>
---
Changelog:
v5->v6:
 - Addressed comment from Jiri.
 - Changed 'physical' to 'phys'.
v4->v5:
 - Addressed comments from Jiri.
 - Moved check for physical port flavours check to separate patch.
v3->v4:
 - Addressed comments from Jiri.
 - Renamed phys_port to physical to be consistent with pci_pf.
 - Removed port_number from __devlink_port_attrs_set and moved
   assigment to caller function.
 - Used capital letter while moving old comment to new structure.
 - Removed helper function is_devlink_phy_port_num_supported().
v2->v3:
 - Address comments from Jakub.
 - Made port_number and split_port_number applicable only to
   physical port flavours by having in union.
v1->v2:
 - Limited port_num attribute to physical ports
 - Updated PCI PF attribute set API to not have port_number
---
 include/net/devlink.h | 13 ++++++++--
 net/core/devlink.c    | 58 ++++++++++++++++++++++++++++---------------
 2 files changed, 49 insertions(+), 22 deletions(-)

diff --git a/include/net/devlink.h b/include/net/devlink.h
index 6625ea068d5e..4538c80fe293 100644
--- a/include/net/devlink.h
+++ b/include/net/devlink.h
@@ -38,14 +38,23 @@ struct devlink {
 	char priv[0] __aligned(NETDEV_ALIGN);
 };
 
+struct devlink_port_phys_attrs {
+	u32 port_number; /* Same value as "split group".
+			  * A physical port which is visible to the user
+			  * for a given port flavour.
+			  */
+	u32 split_subport_number;
+};
+
 struct devlink_port_attrs {
 	u8 set:1,
 	   split:1,
 	   switch_port:1;
 	enum devlink_port_flavour flavour;
-	u32 port_number; /* same value as "split group" */
-	u32 split_subport_number;
 	struct netdev_phys_item_id switch_id;
+	union {
+		struct devlink_port_phys_attrs phys;
+	};
 };
 
 struct devlink_port {
diff --git a/net/core/devlink.c b/net/core/devlink.c
index 89c533778135..eacaf37b5108 100644
--- a/net/core/devlink.c
+++ b/net/core/devlink.c
@@ -515,14 +515,16 @@ static int devlink_nl_port_attrs_put(struct sk_buff *msg,
 		return 0;
 	if (nla_put_u16(msg, DEVLINK_ATTR_PORT_FLAVOUR, attrs->flavour))
 		return -EMSGSIZE;
-	if (nla_put_u32(msg, DEVLINK_ATTR_PORT_NUMBER, attrs->port_number))
+	if (nla_put_u32(msg, DEVLINK_ATTR_PORT_NUMBER,
+			attrs->phys.port_number))
 		return -EMSGSIZE;
 	if (!attrs->split)
 		return 0;
-	if (nla_put_u32(msg, DEVLINK_ATTR_PORT_SPLIT_GROUP, attrs->port_number))
+	if (nla_put_u32(msg, DEVLINK_ATTR_PORT_SPLIT_GROUP,
+			attrs->phys.port_number))
 		return -EMSGSIZE;
 	if (nla_put_u32(msg, DEVLINK_ATTR_PORT_SPLIT_SUBPORT_NUMBER,
-			attrs->split_subport_number))
+			attrs->phys.split_subport_number))
 		return -EMSGSIZE;
 	return 0;
 }
@@ -5738,6 +5740,29 @@ void devlink_port_type_clear(struct devlink_port *devlink_port)
 }
 EXPORT_SYMBOL_GPL(devlink_port_type_clear);
 
+static int __devlink_port_attrs_set(struct devlink_port *devlink_port,
+				    enum devlink_port_flavour flavour,
+				    const unsigned char *switch_id,
+				    unsigned char switch_id_len)
+{
+	struct devlink_port_attrs *attrs = &devlink_port->attrs;
+
+	if (WARN_ON(devlink_port->registered))
+		return -EEXIST;
+	attrs->set = true;
+	attrs->flavour = flavour;
+	if (switch_id) {
+		attrs->switch_port = true;
+		if (WARN_ON(switch_id_len > MAX_PHYS_ITEM_ID_LEN))
+			switch_id_len = MAX_PHYS_ITEM_ID_LEN;
+		memcpy(attrs->switch_id.id, switch_id, switch_id_len);
+		attrs->switch_id.id_len = switch_id_len;
+	} else {
+		attrs->switch_port = false;
+	}
+	return 0;
+}
+
 /**
  *	devlink_port_attrs_set - Set port attributes
  *
@@ -5760,23 +5785,15 @@ void devlink_port_attrs_set(struct devlink_port *devlink_port,
 			    unsigned char switch_id_len)
 {
 	struct devlink_port_attrs *attrs = &devlink_port->attrs;
+	int ret;
 
-	if (WARN_ON(devlink_port->registered))
+	ret = __devlink_port_attrs_set(devlink_port, flavour,
+				       switch_id, switch_id_len);
+	if (ret)
 		return;
-	attrs->set = true;
-	attrs->flavour = flavour;
-	attrs->port_number = port_number;
 	attrs->split = split;
-	attrs->split_subport_number = split_subport_number;
-	if (switch_id) {
-		attrs->switch_port = true;
-		if (WARN_ON(switch_id_len > MAX_PHYS_ITEM_ID_LEN))
-			switch_id_len = MAX_PHYS_ITEM_ID_LEN;
-		memcpy(attrs->switch_id.id, switch_id, switch_id_len);
-		attrs->switch_id.id_len = switch_id_len;
-	} else {
-		attrs->switch_port = false;
-	}
+	attrs->phys.port_number = port_number;
+	attrs->phys.split_subport_number = split_subport_number;
 }
 EXPORT_SYMBOL_GPL(devlink_port_attrs_set);
 
@@ -5792,10 +5809,11 @@ static int __devlink_port_phys_port_name_get(struct devlink_port *devlink_port,
 	switch (attrs->flavour) {
 	case DEVLINK_PORT_FLAVOUR_PHYSICAL:
 		if (!attrs->split)
-			n = snprintf(name, len, "p%u", attrs->port_number);
+			n = snprintf(name, len, "p%u", attrs->phys.port_number);
 		else
-			n = snprintf(name, len, "p%us%u", attrs->port_number,
-				     attrs->split_subport_number);
+			n = snprintf(name, len, "p%us%u",
+				     attrs->phys.port_number,
+				     attrs->phys.split_subport_number);
 		break;
 	case DEVLINK_PORT_FLAVOUR_CPU:
 	case DEVLINK_PORT_FLAVOUR_DSA:
-- 
2.19.2


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

* [PATCH net-next v6 2/5] devlink: Return physical port fields only for applicable port flavours
  2019-07-09  4:17 ` [PATCH net-next v6 0/5] devlink: Introduce PCI PF, VF ports and attributes Parav Pandit
  2019-07-09  4:17   ` [PATCH net-next v6 1/5] devlink: Refactor physical port attributes Parav Pandit
@ 2019-07-09  4:17   ` Parav Pandit
  2019-07-09  4:17   ` [PATCH net-next v6 3/5] devlink: Introduce PCI PF port flavour and port attribute Parav Pandit
                     ` (3 subsequent siblings)
  5 siblings, 0 replies; 71+ messages in thread
From: Parav Pandit @ 2019-07-09  4:17 UTC (permalink / raw)
  To: netdev; +Cc: jiri, saeedm, jakub.kicinski, Parav Pandit

Physical port number and split group fields are applicable only to
physical port flavours such as PHYSICAL, CPU and DSA.
Hence limit returning those values in netlink response to such port
flavours.

Acked-by: Jiri Pirko <jiri@mellanox.com>
Signed-off-by: Parav Pandit <parav@mellanox.com>
---
 net/core/devlink.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/net/core/devlink.c b/net/core/devlink.c
index eacaf37b5108..a9c4e5d8a99c 100644
--- a/net/core/devlink.c
+++ b/net/core/devlink.c
@@ -515,6 +515,10 @@ static int devlink_nl_port_attrs_put(struct sk_buff *msg,
 		return 0;
 	if (nla_put_u16(msg, DEVLINK_ATTR_PORT_FLAVOUR, attrs->flavour))
 		return -EMSGSIZE;
+	if (devlink_port->attrs.flavour != DEVLINK_PORT_FLAVOUR_PHYSICAL &&
+	    devlink_port->attrs.flavour != DEVLINK_PORT_FLAVOUR_CPU &&
+	    devlink_port->attrs.flavour != DEVLINK_PORT_FLAVOUR_DSA)
+		return 0;
 	if (nla_put_u32(msg, DEVLINK_ATTR_PORT_NUMBER,
 			attrs->phys.port_number))
 		return -EMSGSIZE;
-- 
2.19.2


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

* [PATCH net-next v6 3/5] devlink: Introduce PCI PF port flavour and port attribute
  2019-07-09  4:17 ` [PATCH net-next v6 0/5] devlink: Introduce PCI PF, VF ports and attributes Parav Pandit
  2019-07-09  4:17   ` [PATCH net-next v6 1/5] devlink: Refactor physical port attributes Parav Pandit
  2019-07-09  4:17   ` [PATCH net-next v6 2/5] devlink: Return physical port fields only for applicable port flavours Parav Pandit
@ 2019-07-09  4:17   ` Parav Pandit
  2019-07-09  4:17   ` [PATCH net-next v6 4/5] devlink: Introduce PCI VF " Parav Pandit
                     ` (2 subsequent siblings)
  5 siblings, 0 replies; 71+ messages in thread
From: Parav Pandit @ 2019-07-09  4:17 UTC (permalink / raw)
  To: netdev; +Cc: jiri, saeedm, jakub.kicinski, Parav Pandit

In an eswitch, PCI PF may have port which is normally represented
using a representor netdevice.
To have better visibility of eswitch port, its association with
PF and a representor netdevice, introduce a PCI PF port
flavour and port attriute.

When devlink port flavour is PCI PF, fill up PCI PF attributes of the
port.

Extend port name creation using PCI PF number on best effort basis.
So that vendor drivers can skip defining their own scheme.

$ devlink port show
pci/0000:05:00.0/0: type eth netdev eth0 flavour pcipf pfnum 0

Acked-by: Jiri Pirko <jiri@mellanox.com>
Signed-off-by: Parav Pandit <parav@mellanox.com>
---
Changelog:
v5->v6:
 - Addressed comment from Jakub.
 - Fixed ordering issue with port flavour check for PCI PF.
v4->v5:
 - Corrected typo 'otwerwise' to 'otherwise'
---
 include/net/devlink.h        |  8 ++++++++
 include/uapi/linux/devlink.h |  5 +++++
 net/core/devlink.c           | 34 ++++++++++++++++++++++++++++++++++
 3 files changed, 47 insertions(+)

diff --git a/include/net/devlink.h b/include/net/devlink.h
index 4538c80fe293..97cef896e4d0 100644
--- a/include/net/devlink.h
+++ b/include/net/devlink.h
@@ -46,6 +46,10 @@ struct devlink_port_phys_attrs {
 	u32 split_subport_number;
 };
 
+struct devlink_port_pci_pf_attrs {
+	u16 pf;	/* Associated PCI PF for this port. */
+};
+
 struct devlink_port_attrs {
 	u8 set:1,
 	   split:1,
@@ -54,6 +58,7 @@ struct devlink_port_attrs {
 	struct netdev_phys_item_id switch_id;
 	union {
 		struct devlink_port_phys_attrs phys;
+		struct devlink_port_pci_pf_attrs pci_pf;
 	};
 };
 
@@ -599,6 +604,9 @@ void devlink_port_attrs_set(struct devlink_port *devlink_port,
 			    u32 split_subport_number,
 			    const unsigned char *switch_id,
 			    unsigned char switch_id_len);
+void devlink_port_attrs_pci_pf_set(struct devlink_port *devlink_port,
+				   const unsigned char *switch_id,
+				   unsigned char switch_id_len, u16 pf);
 int devlink_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/include/uapi/linux/devlink.h b/include/uapi/linux/devlink.h
index 5287b42c181f..f7323884c3fe 100644
--- a/include/uapi/linux/devlink.h
+++ b/include/uapi/linux/devlink.h
@@ -169,6 +169,10 @@ enum devlink_port_flavour {
 	DEVLINK_PORT_FLAVOUR_DSA, /* Distributed switch architecture
 				   * interconnect port.
 				   */
+	DEVLINK_PORT_FLAVOUR_PCI_PF, /* Represents eswitch port for
+				      * the PCI PF. It is an internal
+				      * port that faces the PCI PF.
+				      */
 };
 
 enum devlink_param_cmode {
@@ -337,6 +341,7 @@ enum devlink_attr {
 	DEVLINK_ATTR_FLASH_UPDATE_STATUS_DONE,	/* u64 */
 	DEVLINK_ATTR_FLASH_UPDATE_STATUS_TOTAL,	/* u64 */
 
+	DEVLINK_ATTR_PORT_PCI_PF_NUMBER,	/* u16 */
 	/* add new attributes above here, update the policy in devlink.c */
 
 	__DEVLINK_ATTR_MAX,
diff --git a/net/core/devlink.c b/net/core/devlink.c
index a9c4e5d8a99c..d362652a5cc7 100644
--- a/net/core/devlink.c
+++ b/net/core/devlink.c
@@ -515,6 +515,11 @@ static int devlink_nl_port_attrs_put(struct sk_buff *msg,
 		return 0;
 	if (nla_put_u16(msg, DEVLINK_ATTR_PORT_FLAVOUR, attrs->flavour))
 		return -EMSGSIZE;
+	if (devlink_port->attrs.flavour == DEVLINK_PORT_FLAVOUR_PCI_PF) {
+		if (nla_put_u16(msg, DEVLINK_ATTR_PORT_PCI_PF_NUMBER,
+				attrs->pci_pf.pf))
+			return -EMSGSIZE;
+	}
 	if (devlink_port->attrs.flavour != DEVLINK_PORT_FLAVOUR_PHYSICAL &&
 	    devlink_port->attrs.flavour != DEVLINK_PORT_FLAVOUR_CPU &&
 	    devlink_port->attrs.flavour != DEVLINK_PORT_FLAVOUR_DSA)
@@ -5801,6 +5806,32 @@ void devlink_port_attrs_set(struct devlink_port *devlink_port,
 }
 EXPORT_SYMBOL_GPL(devlink_port_attrs_set);
 
+/**
+ *	devlink_port_attrs_pci_pf_set - Set PCI PF port attributes
+ *
+ *	@devlink_port: devlink port
+ *	@pf: associated PF for the devlink port instance
+ *	@switch_id: if the port is part of switch, this is buffer with ID,
+ *	            otherwise this is NULL
+ *	@switch_id_len: length of the switch_id buffer
+ */
+void devlink_port_attrs_pci_pf_set(struct devlink_port *devlink_port,
+				   const unsigned char *switch_id,
+				   unsigned char switch_id_len, u16 pf)
+{
+	struct devlink_port_attrs *attrs = &devlink_port->attrs;
+	int ret;
+
+	ret = __devlink_port_attrs_set(devlink_port,
+				       DEVLINK_PORT_FLAVOUR_PCI_PF,
+				       switch_id, switch_id_len);
+	if (ret)
+		return;
+
+	attrs->pci_pf.pf = pf;
+}
+EXPORT_SYMBOL_GPL(devlink_port_attrs_pci_pf_set);
+
 static int __devlink_port_phys_port_name_get(struct devlink_port *devlink_port,
 					     char *name, size_t len)
 {
@@ -5826,6 +5857,9 @@ static int __devlink_port_phys_port_name_get(struct devlink_port *devlink_port,
 		 */
 		WARN_ON(1);
 		return -EINVAL;
+	case DEVLINK_PORT_FLAVOUR_PCI_PF:
+		n = snprintf(name, len, "pf%u", attrs->pci_pf.pf);
+		break;
 	}
 
 	if (n >= len)
-- 
2.19.2


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

* [PATCH net-next v6 4/5] devlink: Introduce PCI VF port flavour and port attribute
  2019-07-09  4:17 ` [PATCH net-next v6 0/5] devlink: Introduce PCI PF, VF ports and attributes Parav Pandit
                     ` (2 preceding siblings ...)
  2019-07-09  4:17   ` [PATCH net-next v6 3/5] devlink: Introduce PCI PF port flavour and port attribute Parav Pandit
@ 2019-07-09  4:17   ` Parav Pandit
  2019-07-09  4:17   ` [PATCH net-next v6 5/5] net/mlx5e: Register devlink ports for physical link, PCI PF, VFs Parav Pandit
  2019-07-09  5:40   ` [PATCH net-next v6 0/5] devlink: Introduce PCI PF, VF ports and attributes Jakub Kicinski
  5 siblings, 0 replies; 71+ messages in thread
From: Parav Pandit @ 2019-07-09  4:17 UTC (permalink / raw)
  To: netdev; +Cc: jiri, saeedm, jakub.kicinski, Parav Pandit

In an eswitch, PCI VF may have port which is normally represented using
a representor netdevice.
To have better visibility of eswitch port, its association with VF,
and its representor netdevice, introduce a PCI VF port flavour.

When devlink port flavour is PCI VF, fill up PCI VF attributes of
the port.

Extend port name creation using PCI PF and VF number scheme on best
effort basis, so that vendor drivers can skip defining their own scheme.

$ devlink port show
pci/0000:05:00.0/0: type eth netdev eth0 flavour pcipf pfnum 0
pci/0000:05:00.0/1: type eth netdev eth1 flavour pcivf pfnum 0 vfnum 0
pci/0000:05:00.0/2: type eth netdev eth2 flavour pcivf pfnum 0 vfnum 1

Acked-by: Jiri Pirko <jiri@mellanox.com>
Signed-off-by: Parav Pandit <parav@mellanox.com>
---
 include/net/devlink.h        | 10 ++++++++++
 include/uapi/linux/devlink.h |  6 ++++++
 net/core/devlink.c           | 38 ++++++++++++++++++++++++++++++++++++
 3 files changed, 54 insertions(+)

diff --git a/include/net/devlink.h b/include/net/devlink.h
index 97cef896e4d0..bc36f942a7d5 100644
--- a/include/net/devlink.h
+++ b/include/net/devlink.h
@@ -50,6 +50,11 @@ struct devlink_port_pci_pf_attrs {
 	u16 pf;	/* Associated PCI PF for this port. */
 };
 
+struct devlink_port_pci_vf_attrs {
+	u16 pf;	/* Associated PCI PF for this port. */
+	u16 vf;	/* Associated PCI VF for of the PCI PF for this port. */
+};
+
 struct devlink_port_attrs {
 	u8 set:1,
 	   split:1,
@@ -59,6 +64,7 @@ struct devlink_port_attrs {
 	union {
 		struct devlink_port_phys_attrs phys;
 		struct devlink_port_pci_pf_attrs pci_pf;
+		struct devlink_port_pci_vf_attrs pci_vf;
 	};
 };
 
@@ -607,6 +613,10 @@ void devlink_port_attrs_set(struct devlink_port *devlink_port,
 void devlink_port_attrs_pci_pf_set(struct devlink_port *devlink_port,
 				   const unsigned char *switch_id,
 				   unsigned char switch_id_len, u16 pf);
+void devlink_port_attrs_pci_vf_set(struct devlink_port *devlink_port,
+				   const unsigned char *switch_id,
+				   unsigned char switch_id_len,
+				   u16 pf, u16 vf);
 int devlink_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/include/uapi/linux/devlink.h b/include/uapi/linux/devlink.h
index f7323884c3fe..ffc993256527 100644
--- a/include/uapi/linux/devlink.h
+++ b/include/uapi/linux/devlink.h
@@ -173,6 +173,10 @@ enum devlink_port_flavour {
 				      * the PCI PF. It is an internal
 				      * port that faces the PCI PF.
 				      */
+	DEVLINK_PORT_FLAVOUR_PCI_VF, /* Represents eswitch port
+				      * for the PCI VF. It is an internal
+				      * port that faces the PCI VF.
+				      */
 };
 
 enum devlink_param_cmode {
@@ -342,6 +346,8 @@ enum devlink_attr {
 	DEVLINK_ATTR_FLASH_UPDATE_STATUS_TOTAL,	/* u64 */
 
 	DEVLINK_ATTR_PORT_PCI_PF_NUMBER,	/* u16 */
+	DEVLINK_ATTR_PORT_PCI_VF_NUMBER,	/* u16 */
+
 	/* add new attributes above here, update the policy in devlink.c */
 
 	__DEVLINK_ATTR_MAX,
diff --git a/net/core/devlink.c b/net/core/devlink.c
index d362652a5cc7..4f40aeace902 100644
--- a/net/core/devlink.c
+++ b/net/core/devlink.c
@@ -519,6 +519,12 @@ static int devlink_nl_port_attrs_put(struct sk_buff *msg,
 		if (nla_put_u16(msg, DEVLINK_ATTR_PORT_PCI_PF_NUMBER,
 				attrs->pci_pf.pf))
 			return -EMSGSIZE;
+	} else if (devlink_port->attrs.flavour == DEVLINK_PORT_FLAVOUR_PCI_VF) {
+		if (nla_put_u16(msg, DEVLINK_ATTR_PORT_PCI_PF_NUMBER,
+				attrs->pci_vf.pf) ||
+		    nla_put_u16(msg, DEVLINK_ATTR_PORT_PCI_VF_NUMBER,
+				attrs->pci_vf.vf))
+			return -EMSGSIZE;
 	}
 	if (devlink_port->attrs.flavour != DEVLINK_PORT_FLAVOUR_PHYSICAL &&
 	    devlink_port->attrs.flavour != DEVLINK_PORT_FLAVOUR_CPU &&
@@ -5832,6 +5838,34 @@ void devlink_port_attrs_pci_pf_set(struct devlink_port *devlink_port,
 }
 EXPORT_SYMBOL_GPL(devlink_port_attrs_pci_pf_set);
 
+/**
+ *	devlink_port_attrs_pci_vf_set - Set PCI VF port attributes
+ *
+ *	@devlink_port: devlink port
+ *	@pf: associated PF for the devlink port instance
+ *	@vf: associated VF of a PF for the devlink port instance
+ *	@switch_id: if the port is part of switch, this is buffer with ID,
+ *	            otherwise this is NULL
+ *	@switch_id_len: length of the switch_id buffer
+ */
+void devlink_port_attrs_pci_vf_set(struct devlink_port *devlink_port,
+				   const unsigned char *switch_id,
+				   unsigned char switch_id_len,
+				   u16 pf, u16 vf)
+{
+	struct devlink_port_attrs *attrs = &devlink_port->attrs;
+	int ret;
+
+	ret = __devlink_port_attrs_set(devlink_port,
+				       DEVLINK_PORT_FLAVOUR_PCI_VF,
+				       switch_id, switch_id_len);
+	if (ret)
+		return;
+	attrs->pci_vf.pf = pf;
+	attrs->pci_vf.vf = vf;
+}
+EXPORT_SYMBOL_GPL(devlink_port_attrs_pci_vf_set);
+
 static int __devlink_port_phys_port_name_get(struct devlink_port *devlink_port,
 					     char *name, size_t len)
 {
@@ -5860,6 +5894,10 @@ static int __devlink_port_phys_port_name_get(struct devlink_port *devlink_port,
 	case DEVLINK_PORT_FLAVOUR_PCI_PF:
 		n = snprintf(name, len, "pf%u", attrs->pci_pf.pf);
 		break;
+	case DEVLINK_PORT_FLAVOUR_PCI_VF:
+		n = snprintf(name, len, "pf%uvf%u",
+			     attrs->pci_vf.pf, attrs->pci_vf.vf);
+		break;
 	}
 
 	if (n >= len)
-- 
2.19.2


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

* [PATCH net-next v6 5/5] net/mlx5e: Register devlink ports for physical link, PCI PF, VFs
  2019-07-09  4:17 ` [PATCH net-next v6 0/5] devlink: Introduce PCI PF, VF ports and attributes Parav Pandit
                     ` (3 preceding siblings ...)
  2019-07-09  4:17   ` [PATCH net-next v6 4/5] devlink: Introduce PCI VF " Parav Pandit
@ 2019-07-09  4:17   ` Parav Pandit
  2019-07-09  5:40   ` [PATCH net-next v6 0/5] devlink: Introduce PCI PF, VF ports and attributes Jakub Kicinski
  5 siblings, 0 replies; 71+ messages in thread
From: Parav Pandit @ 2019-07-09  4:17 UTC (permalink / raw)
  To: netdev; +Cc: jiri, saeedm, jakub.kicinski, Parav Pandit

Register devlink port of physical port, PCI PF and PCI VF flavour
for each PF, VF when a given devlink instance is in switchdev mode.

Implement ndo_get_devlink_port callback API to make use of registered
devlink ports.
This eliminates ndo_get_phys_port_name() and ndo_get_port_parent_id()
callbacks. Hence, remove them.

An example output with 2 VFs, without a PF and single uplink port is
below.

$devlink port show
pci/0000:06:00.0/65535: type eth netdev ens2f0 flavour physical
pci/0000:05:00.0/1: type eth netdev eth1 flavour pcivf pfnum 0 vfnum 0
pci/0000:05:00.0/2: type eth netdev eth2 flavour pcivf pfnum 0 vfnum 1

Reviewed-by: Roi Dayan <roid@mellanox.com>
Acked-by: Jiri Pirko <jiri@mellanox.com>
Signed-off-by: Parav Pandit <parav@mellanox.com>
---
 .../net/ethernet/mellanox/mlx5/core/en_rep.c  | 108 +++++++++++++-----
 .../net/ethernet/mellanox/mlx5/core/en_rep.h  |   1 +
 2 files changed, 78 insertions(+), 31 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_rep.c b/drivers/net/ethernet/mellanox/mlx5/core/en_rep.c
index 529f8e4b32c6..6810b9fa0705 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_rep.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_rep.c
@@ -37,6 +37,7 @@
 #include <net/act_api.h>
 #include <net/netevent.h>
 #include <net/arp.h>
+#include <net/devlink.h>
 
 #include "eswitch.h"
 #include "en.h"
@@ -1119,32 +1120,6 @@ static int mlx5e_rep_close(struct net_device *dev)
 	return ret;
 }
 
-static int mlx5e_rep_get_phys_port_name(struct net_device *dev,
-					char *buf, size_t len)
-{
-	struct mlx5e_priv *priv = netdev_priv(dev);
-	struct mlx5e_rep_priv *rpriv = priv->ppriv;
-	struct mlx5_eswitch_rep *rep = rpriv->rep;
-	unsigned int fn;
-	int ret;
-
-	fn = PCI_FUNC(priv->mdev->pdev->devfn);
-	if (fn >= MLX5_MAX_PORTS)
-		return -EOPNOTSUPP;
-
-	if (rep->vport == MLX5_VPORT_UPLINK)
-		ret = snprintf(buf, len, "p%d", fn);
-	else if (rep->vport == MLX5_VPORT_PF)
-		ret = snprintf(buf, len, "pf%d", fn);
-	else
-		ret = snprintf(buf, len, "pf%dvf%d", fn, rep->vport - 1);
-
-	if (ret >= len)
-		return -EOPNOTSUPP;
-
-	return 0;
-}
-
 static int
 mlx5e_rep_setup_tc_cls_flower(struct mlx5e_priv *priv,
 			      struct tc_cls_flower_offload *cls_flower, int flags)
@@ -1298,17 +1273,24 @@ static int mlx5e_uplink_rep_set_vf_vlan(struct net_device *dev, int vf, u16 vlan
 	return 0;
 }
 
+static struct devlink_port *mlx5e_get_devlink_port(struct net_device *dev)
+{
+	struct mlx5e_priv *priv = netdev_priv(dev);
+	struct mlx5e_rep_priv *rpriv = priv->ppriv;
+
+	return &rpriv->dl_port;
+}
+
 static const struct net_device_ops mlx5e_netdev_ops_rep = {
 	.ndo_open                = mlx5e_rep_open,
 	.ndo_stop                = mlx5e_rep_close,
 	.ndo_start_xmit          = mlx5e_xmit,
-	.ndo_get_phys_port_name  = mlx5e_rep_get_phys_port_name,
 	.ndo_setup_tc            = mlx5e_rep_setup_tc,
+	.ndo_get_devlink_port = mlx5e_get_devlink_port,
 	.ndo_get_stats64         = mlx5e_rep_get_stats,
 	.ndo_has_offload_stats	 = mlx5e_rep_has_offload_stats,
 	.ndo_get_offload_stats	 = mlx5e_rep_get_offload_stats,
 	.ndo_change_mtu          = mlx5e_rep_change_mtu,
-	.ndo_get_port_parent_id	 = mlx5e_rep_get_port_parent_id,
 };
 
 static const struct net_device_ops mlx5e_netdev_ops_uplink_rep = {
@@ -1316,8 +1298,8 @@ static const struct net_device_ops mlx5e_netdev_ops_uplink_rep = {
 	.ndo_stop                = mlx5e_close,
 	.ndo_start_xmit          = mlx5e_xmit,
 	.ndo_set_mac_address     = mlx5e_uplink_rep_set_mac,
-	.ndo_get_phys_port_name  = mlx5e_rep_get_phys_port_name,
 	.ndo_setup_tc            = mlx5e_rep_setup_tc,
+	.ndo_get_devlink_port = mlx5e_get_devlink_port,
 	.ndo_get_stats64         = mlx5e_get_stats,
 	.ndo_has_offload_stats	 = mlx5e_rep_has_offload_stats,
 	.ndo_get_offload_stats	 = mlx5e_rep_get_offload_stats,
@@ -1330,7 +1312,6 @@ static const struct net_device_ops mlx5e_netdev_ops_uplink_rep = {
 	.ndo_get_vf_config       = mlx5e_get_vf_config,
 	.ndo_get_vf_stats        = mlx5e_get_vf_stats,
 	.ndo_set_vf_vlan         = mlx5e_uplink_rep_set_vf_vlan,
-	.ndo_get_port_parent_id	 = mlx5e_rep_get_port_parent_id,
 	.ndo_set_features        = mlx5e_set_features,
 };
 
@@ -1731,6 +1712,55 @@ static const struct mlx5e_profile mlx5e_uplink_rep_profile = {
 	.max_tc			= MLX5E_MAX_NUM_TC,
 };
 
+static bool
+is_devlink_port_supported(const struct mlx5_core_dev *dev,
+			  const struct mlx5e_rep_priv *rpriv)
+{
+	return rpriv->rep->vport == MLX5_VPORT_UPLINK ||
+	       rpriv->rep->vport == MLX5_VPORT_PF ||
+	       mlx5_eswitch_is_vf_vport(dev->priv.eswitch, rpriv->rep->vport);
+}
+
+static int register_devlink_port(struct mlx5_core_dev *dev,
+				 struct mlx5e_rep_priv *rpriv)
+{
+	struct devlink *devlink = priv_to_devlink(dev);
+	struct mlx5_eswitch_rep *rep = rpriv->rep;
+	struct netdev_phys_item_id ppid = {};
+	int ret;
+
+	if (!is_devlink_port_supported(dev, rpriv))
+		return 0;
+
+	ret = mlx5e_rep_get_port_parent_id(rpriv->netdev, &ppid);
+	if (ret)
+		return ret;
+
+	if (rep->vport == MLX5_VPORT_UPLINK)
+		devlink_port_attrs_set(&rpriv->dl_port,
+				       DEVLINK_PORT_FLAVOUR_PHYSICAL,
+				       PCI_FUNC(dev->pdev->devfn), false, 0,
+				       &ppid.id[0], ppid.id_len);
+	else if (rep->vport == MLX5_VPORT_PF)
+		devlink_port_attrs_pci_pf_set(&rpriv->dl_port,
+					      &ppid.id[0], ppid.id_len,
+					      dev->pdev->devfn);
+	else if (mlx5_eswitch_is_vf_vport(dev->priv.eswitch, rpriv->rep->vport))
+		devlink_port_attrs_pci_vf_set(&rpriv->dl_port,
+					      &ppid.id[0], ppid.id_len,
+					      dev->pdev->devfn,
+					      rep->vport - 1);
+
+	return devlink_port_register(devlink, &rpriv->dl_port, rep->vport);
+}
+
+static void unregister_devlink_port(struct mlx5_core_dev *dev,
+				    struct mlx5e_rep_priv *rpriv)
+{
+	if (is_devlink_port_supported(dev, rpriv))
+		devlink_port_unregister(&rpriv->dl_port);
+}
+
 /* e-Switch vport representors */
 static int
 mlx5e_vport_rep_load(struct mlx5_core_dev *dev, struct mlx5_eswitch_rep *rep)
@@ -1782,15 +1812,27 @@ mlx5e_vport_rep_load(struct mlx5_core_dev *dev, struct mlx5_eswitch_rep *rep)
 		goto err_detach_netdev;
 	}
 
+	err = register_devlink_port(dev, rpriv);
+	if (err) {
+		esw_warn(dev, "Failed to register devlink port %d\n",
+			 rep->vport);
+		goto err_neigh_cleanup;
+	}
+
 	err = register_netdev(netdev);
 	if (err) {
 		pr_warn("Failed to register representor netdev for vport %d\n",
 			rep->vport);
-		goto err_neigh_cleanup;
+		goto err_devlink_cleanup;
 	}
 
+	if (is_devlink_port_supported(dev, rpriv))
+		devlink_port_type_eth_set(&rpriv->dl_port, netdev);
 	return 0;
 
+err_devlink_cleanup:
+	unregister_devlink_port(dev, rpriv);
+
 err_neigh_cleanup:
 	mlx5e_rep_neigh_cleanup(rpriv);
 
@@ -1813,9 +1855,13 @@ mlx5e_vport_rep_unload(struct mlx5_eswitch_rep *rep)
 	struct mlx5e_rep_priv *rpriv = mlx5e_rep_to_rep_priv(rep);
 	struct net_device *netdev = rpriv->netdev;
 	struct mlx5e_priv *priv = netdev_priv(netdev);
+	struct mlx5_core_dev *dev = priv->mdev;
 	void *ppriv = priv->ppriv;
 
+	if (is_devlink_port_supported(dev, rpriv))
+		devlink_port_type_clear(&rpriv->dl_port);
 	unregister_netdev(netdev);
+	unregister_devlink_port(dev, rpriv);
 	mlx5e_rep_neigh_cleanup(rpriv);
 	mlx5e_detach_netdev(priv);
 	if (rep->vport == MLX5_VPORT_UPLINK)
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_rep.h b/drivers/net/ethernet/mellanox/mlx5/core/en_rep.h
index d4585f3b8cb2..c56e6ee4350c 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_rep.h
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_rep.h
@@ -86,6 +86,7 @@ struct mlx5e_rep_priv {
 	struct mlx5_flow_handle *vport_rx_rule;
 	struct list_head       vport_sqs_list;
 	struct mlx5_rep_uplink_priv uplink_priv; /* valid for uplink rep */
+	struct devlink_port dl_port;
 };
 
 static inline
-- 
2.19.2


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

* Re: [PATCH net-next v6 0/5] devlink: Introduce PCI PF, VF ports and attributes
  2019-07-09  4:17 ` [PATCH net-next v6 0/5] devlink: Introduce PCI PF, VF ports and attributes Parav Pandit
                     ` (4 preceding siblings ...)
  2019-07-09  4:17   ` [PATCH net-next v6 5/5] net/mlx5e: Register devlink ports for physical link, PCI PF, VFs Parav Pandit
@ 2019-07-09  5:40   ` Jakub Kicinski
  2019-07-09  6:17     ` Jiri Pirko
  2019-07-09  6:20     ` Parav Pandit
  5 siblings, 2 replies; 71+ messages in thread
From: Jakub Kicinski @ 2019-07-09  5:40 UTC (permalink / raw)
  To: Parav Pandit; +Cc: netdev, jiri, saeedm

On Mon,  8 Jul 2019 23:17:34 -0500, Parav Pandit wrote:
> This patchset carry forwards the work initiated in [1] and discussion
> futher concluded at [2].
> 
> To improve visibility of representor netdevice, its association with
> PF or VF, physical port, two new devlink port flavours are added as
> PCI PF and PCI VF ports.
> 
> A sample eswitch view can be seen below, which will be futher extended to
> mdev subdevices of a PCI function in future.
> 
> Patch-1 moves physical port's attribute to new structure
> Patch-2 enhances netlink response to consider port flavour
> Patch-3,4 extends devlink port attributes and port flavour
> Patch-5 extends mlx5 driver to register devlink ports for PF, VF and
> physical link.

The coding leaves something to be desired:

1) flavour handling in devlink_nl_port_attrs_put() really calls for a
   switch statement,
2) devlink_port_attrs_.*set() can take a pointer to flavour specific
   structure instead of attr structure for setting the parameters,
3) the "ret" variable there is unnecessary,
4) there is inconsistency in whether there is an empty line between
   if (ret) return; after __devlink_port_attrs_set() and attr setting,
5) /* Associated PCI VF for of the PCI PF for this port. */ doesn't
   read great;
6) mlx5 functions should preferably have an appropriate prefix - f.e.
   register_devlink_port() or is_devlink_port_supported().

But I'll leave it to Jiri and Dave to decide if its worth a respin :)
Functionally I think this is okay.

Reviewed-by: Jakub Kicinski <jakub.kicinski@netronome.com>

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

* Re: [PATCH net-next v6 0/5] devlink: Introduce PCI PF, VF ports and attributes
  2019-07-09  5:40   ` [PATCH net-next v6 0/5] devlink: Introduce PCI PF, VF ports and attributes Jakub Kicinski
@ 2019-07-09  6:17     ` Jiri Pirko
  2019-07-09 18:20       ` Jakub Kicinski
  2019-07-09  6:20     ` Parav Pandit
  1 sibling, 1 reply; 71+ messages in thread
From: Jiri Pirko @ 2019-07-09  6:17 UTC (permalink / raw)
  To: Jakub Kicinski; +Cc: Parav Pandit, netdev, jiri, saeedm

Tue, Jul 09, 2019 at 07:40:12AM CEST, jakub.kicinski@netronome.com wrote:
>On Mon,  8 Jul 2019 23:17:34 -0500, Parav Pandit wrote:
>> This patchset carry forwards the work initiated in [1] and discussion
>> futher concluded at [2].
>> 
>> To improve visibility of representor netdevice, its association with
>> PF or VF, physical port, two new devlink port flavours are added as
>> PCI PF and PCI VF ports.
>> 
>> A sample eswitch view can be seen below, which will be futher extended to
>> mdev subdevices of a PCI function in future.
>> 
>> Patch-1 moves physical port's attribute to new structure
>> Patch-2 enhances netlink response to consider port flavour
>> Patch-3,4 extends devlink port attributes and port flavour
>> Patch-5 extends mlx5 driver to register devlink ports for PF, VF and
>> physical link.
>
>The coding leaves something to be desired:
>
>1) flavour handling in devlink_nl_port_attrs_put() really calls for a
>   switch statement,
>2) devlink_port_attrs_.*set() can take a pointer to flavour specific
>   structure instead of attr structure for setting the parameters,
>3) the "ret" variable there is unnecessary,
>4) there is inconsistency in whether there is an empty line between
>   if (ret) return; after __devlink_port_attrs_set() and attr setting,
>5) /* Associated PCI VF for of the PCI PF for this port. */ doesn't
>   read great;
>6) mlx5 functions should preferably have an appropriate prefix - f.e.
>   register_devlink_port() or is_devlink_port_supported().
>
>But I'll leave it to Jiri and Dave to decide if its worth a respin :)
>Functionally I think this is okay.
>

I'm happy with the set as it is right now. Anyway, if you want your
concerns to be addresses, you should write them to the appropriate code.
This list is hard to follow.


>Reviewed-by: Jakub Kicinski <jakub.kicinski@netronome.com>

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

* RE: [PATCH net-next v6 0/5] devlink: Introduce PCI PF, VF ports and attributes
  2019-07-09  5:40   ` [PATCH net-next v6 0/5] devlink: Introduce PCI PF, VF ports and attributes Jakub Kicinski
  2019-07-09  6:17     ` Jiri Pirko
@ 2019-07-09  6:20     ` Parav Pandit
  1 sibling, 0 replies; 71+ messages in thread
From: Parav Pandit @ 2019-07-09  6:20 UTC (permalink / raw)
  To: Jakub Kicinski; +Cc: netdev, Jiri Pirko, Saeed Mahameed

Hi Jakub,

> -----Original Message-----
> From: Jakub Kicinski <jakub.kicinski@netronome.com>
> Sent: Tuesday, July 9, 2019 11:10 AM
> To: Parav Pandit <parav@mellanox.com>
> Cc: netdev@vger.kernel.org; Jiri Pirko <jiri@mellanox.com>; Saeed Mahameed
> <saeedm@mellanox.com>
> Subject: Re: [PATCH net-next v6 0/5] devlink: Introduce PCI PF, VF ports and
> attributes
> 
> On Mon,  8 Jul 2019 23:17:34 -0500, Parav Pandit wrote:
> > This patchset carry forwards the work initiated in [1] and discussion
> > futher concluded at [2].
> >
> > To improve visibility of representor netdevice, its association with
> > PF or VF, physical port, two new devlink port flavours are added as
> > PCI PF and PCI VF ports.
> >
> > A sample eswitch view can be seen below, which will be futher extended
> > to mdev subdevices of a PCI function in future.
> >
> > Patch-1 moves physical port's attribute to new structure
> > Patch-2 enhances netlink response to consider port flavour
> > Patch-3,4 extends devlink port attributes and port flavour
> > Patch-5 extends mlx5 driver to register devlink ports for PF, VF and
> > physical link.
> 
> The coding leaves something to be desired:
> 
> 1) flavour handling in devlink_nl_port_attrs_put() really calls for a
>    switch statement,
> 2) devlink_port_attrs_.*set() can take a pointer to flavour specific
>    structure instead of attr structure for setting the parameters,
> 3) the "ret" variable there is unnecessary,
> 4) there is inconsistency in whether there is an empty line between
>    if (ret) return; after __devlink_port_attrs_set() and attr setting,
> 5) /* Associated PCI VF for of the PCI PF for this port. */ doesn't
>    read great;
> 6) mlx5 functions should preferably have an appropriate prefix - f.e.
>    register_devlink_port() or is_devlink_port_supported().
> 
Those two static helper functions doesn't need mlx5_ prefix.
ndo ops are prefixed appropriately.

> But I'll leave it to Jiri and Dave to decide if its worth a respin :) Functionally I
> think this is okay.
> 
> Reviewed-by: Jakub Kicinski <jakub.kicinski@netronome.com>

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

* Re: [PATCH net-next v6 0/5] devlink: Introduce PCI PF, VF ports and attributes
  2019-07-09  6:17     ` Jiri Pirko
@ 2019-07-09 18:20       ` Jakub Kicinski
  2019-07-09 19:03         ` David Miller
  0 siblings, 1 reply; 71+ messages in thread
From: Jakub Kicinski @ 2019-07-09 18:20 UTC (permalink / raw)
  To: Jiri Pirko; +Cc: Parav Pandit, netdev, jiri, saeedm

On Tue, 9 Jul 2019 08:17:11 +0200, Jiri Pirko wrote:
> >But I'll leave it to Jiri and Dave to decide if its worth a respin :)
> >Functionally I think this is okay.
> 
> I'm happy with the set as it is right now. 

To be clear, I am happy enough as well. Hence the review tag.

> Anyway, if you want your concerns to be addresses, you should write
> them to the appropriate code. This list is hard to follow.

Sorry, I was trying to be concise.

> >Reviewed-by: Jakub Kicinski <jakub.kicinski@netronome.com>  

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

* Re: [PATCH net-next v6 0/5] devlink: Introduce PCI PF, VF ports and attributes
  2019-07-09 18:20       ` Jakub Kicinski
@ 2019-07-09 19:03         ` David Miller
  2019-07-09 19:21           ` Parav Pandit
  2019-07-10  6:41           ` Jiri Pirko
  0 siblings, 2 replies; 71+ messages in thread
From: David Miller @ 2019-07-09 19:03 UTC (permalink / raw)
  To: jakub.kicinski; +Cc: jiri, parav, netdev, jiri, saeedm

From: Jakub Kicinski <jakub.kicinski@netronome.com>
Date: Tue, 9 Jul 2019 11:20:58 -0700

> On Tue, 9 Jul 2019 08:17:11 +0200, Jiri Pirko wrote:
>> >But I'll leave it to Jiri and Dave to decide if its worth a respin :)
>> >Functionally I think this is okay.
>> 
>> I'm happy with the set as it is right now. 
> 
> To be clear, I am happy enough as well. Hence the review tag.

Series applied, thanks everyone.

>> Anyway, if you want your concerns to be addresses, you should write
>> them to the appropriate code. This list is hard to follow.
> 
> Sorry, I was trying to be concise.

Jiri et al., if Jakub put forth the time and effort to make the list
and give you feedback you can put forth the effort to go through the
list and address his feedback with follow-up patches.  You cannot
dictate how people give feedback to your changes, thank you.


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

* RE: [PATCH net-next v6 0/5] devlink: Introduce PCI PF, VF ports and attributes
  2019-07-09 19:03         ` David Miller
@ 2019-07-09 19:21           ` Parav Pandit
  2019-07-10  6:41           ` Jiri Pirko
  1 sibling, 0 replies; 71+ messages in thread
From: Parav Pandit @ 2019-07-09 19:21 UTC (permalink / raw)
  To: David Miller, jakub.kicinski; +Cc: jiri, netdev, Jiri Pirko, Saeed Mahameed

Hi Dave,

> -----Original Message-----
> From: David Miller <davem@davemloft.net>
> Sent: Wednesday, July 10, 2019 12:34 AM
> To: jakub.kicinski@netronome.com
> Cc: jiri@resnulli.us; Parav Pandit <parav@mellanox.com>;
> netdev@vger.kernel.org; Jiri Pirko <jiri@mellanox.com>; Saeed Mahameed
> <saeedm@mellanox.com>
> Subject: Re: [PATCH net-next v6 0/5] devlink: Introduce PCI PF, VF ports and
> attributes
> 
> From: Jakub Kicinski <jakub.kicinski@netronome.com>
> Date: Tue, 9 Jul 2019 11:20:58 -0700
> 
> > On Tue, 9 Jul 2019 08:17:11 +0200, Jiri Pirko wrote:
> >> >But I'll leave it to Jiri and Dave to decide if its worth a respin
> >> >:) Functionally I think this is okay.
> >>
> >> I'm happy with the set as it is right now.
> >
> > To be clear, I am happy enough as well. Hence the review tag.
> 
> Series applied, thanks everyone.
> 
> >> Anyway, if you want your concerns to be addresses, you should write
> >> them to the appropriate code. This list is hard to follow.
> >
> > Sorry, I was trying to be concise.
> 
> Jiri et al., if Jakub put forth the time and effort to make the list and give you
> feedback you can put forth the effort to go through the list and address his
> feedback with follow-up patches.  You cannot dictate how people give
> feedback to your changes, thank you.

I will be happy to write follow up patches.
mostly in kernel 5.4, I will be adding mdev (mediated device) port flavour as discussed in past.
I will possibly write up follow up patch or two before posting them or have it in that series, as it will extend this devlink code further.

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

* RE: [RESEND PATCH iproute2 net-next] devlink: Introduce PCI PF and VF port flavour and attribute
  2019-07-01 18:30 ` [RESEND PATCH iproute2 net-next] " Parav Pandit
@ 2019-07-09 19:49   ` Parav Pandit
  2019-07-10 12:39   ` [PATCH net-next iproute2 v2 1/2] devlink: Update kernel header to commit Parav Pandit
  1 sibling, 0 replies; 71+ messages in thread
From: Parav Pandit @ 2019-07-09 19:49 UTC (permalink / raw)
  To: Parav Pandit, netdev; +Cc: Saeed Mahameed, jakub.kicinski, Jiri Pirko



> -----Original Message-----
> From: netdev-owner@vger.kernel.org <netdev-owner@vger.kernel.org> On
> Behalf Of Parav Pandit
> Sent: Tuesday, July 2, 2019 12:00 AM
> To: netdev@vger.kernel.org
> Cc: Saeed Mahameed <saeedm@mellanox.com>;
> jakub.kicinski@netronome.com; Jiri Pirko <jiri@mellanox.com>; Parav Pandit
> <parav@mellanox.com>
> Subject: [RESEND PATCH iproute2 net-next] devlink: Introduce PCI PF and VF
> port flavour and attribute
> 
> Introduce PCI PF and VF port flavour and port attributes such as PF number
> and VF number.
> 
> $ devlink port show
> pci/0000:05:00.0/0: type eth netdev eth0 flavour pcipf pfnum 0
> pci/0000:05:00.0/1: type eth netdev eth1 flavour pcivf pfnum 0 vfnum 0
> pci/0000:05:00.0/2: type eth netdev eth2 flavour pcivf pfnum 0 vfnum 1
> 
> Acked-by: Jiri Pirko <jiri@mellanox.com>
> Signed-off-by: Parav Pandit <parav@mellanox.com>
> ---
>  devlink/devlink.c            | 23 +++++++++++++++++++++++
>  include/uapi/linux/devlink.h | 11 +++++++++++
>  2 files changed, 34 insertions(+)
>
I will resend this patch with updated kernel commit id for the uapi, possibly once unrelated patch [1] is merged, just to avoid merge conflict.

[1] https://patchwork.ozlabs.org/patch/1129927/


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

* Re: [PATCH net-next v6 0/5] devlink: Introduce PCI PF, VF ports and attributes
  2019-07-09 19:03         ` David Miller
  2019-07-09 19:21           ` Parav Pandit
@ 2019-07-10  6:41           ` Jiri Pirko
  1 sibling, 0 replies; 71+ messages in thread
From: Jiri Pirko @ 2019-07-10  6:41 UTC (permalink / raw)
  To: David Miller; +Cc: jakub.kicinski, parav, netdev, jiri, saeedm

Tue, Jul 09, 2019 at 09:03:36PM CEST, davem@davemloft.net wrote:
>From: Jakub Kicinski <jakub.kicinski@netronome.com>
>Date: Tue, 9 Jul 2019 11:20:58 -0700
>
>> On Tue, 9 Jul 2019 08:17:11 +0200, Jiri Pirko wrote:
>>> >But I'll leave it to Jiri and Dave to decide if its worth a respin :)
>>> >Functionally I think this is okay.
>>> 
>>> I'm happy with the set as it is right now. 
>> 
>> To be clear, I am happy enough as well. Hence the review tag.
>
>Series applied, thanks everyone.
>
>>> Anyway, if you want your concerns to be addresses, you should write
>>> them to the appropriate code. This list is hard to follow.
>> 
>> Sorry, I was trying to be concise.
>
>Jiri et al., if Jakub put forth the time and effort to make the list
>and give you feedback you can put forth the effort to go through the
>list and address his feedback with follow-up patches.  You cannot
>dictate how people give feedback to your changes, thank you.

I don't want to do such thing. I'm just saying it's much easier to
follow the comments when they are provided by the actual code. That's it.
It's the usual way.

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

* [PATCH net-next iproute2 v2 1/2] devlink: Update kernel header to commit
  2019-07-01 18:30 ` [RESEND PATCH iproute2 net-next] " Parav Pandit
  2019-07-09 19:49   ` Parav Pandit
@ 2019-07-10 12:39   ` Parav Pandit
  2019-07-10 12:39     ` [PATCH net-next iproute2 v2 2/2] devlink: Introduce PCI PF and VF port flavour and attribute Parav Pandit
  1 sibling, 1 reply; 71+ messages in thread
From: Parav Pandit @ 2019-07-10 12:39 UTC (permalink / raw)
  To: netdev; +Cc: stephen, dsahern, jiri, Parav Pandit

Update kernel header to commit:
e41b6bf3cdd4 ("devlink: Introduce PCI VF port flavour and port attribute")

Signed-off-by: Parav Pandit <parav@mellanox.com>
---
 include/uapi/linux/devlink.h | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/include/uapi/linux/devlink.h b/include/uapi/linux/devlink.h
index 6544824a..fc195cbd 100644
--- a/include/uapi/linux/devlink.h
+++ b/include/uapi/linux/devlink.h
@@ -169,6 +169,14 @@ enum devlink_port_flavour {
 	DEVLINK_PORT_FLAVOUR_DSA, /* Distributed switch architecture
 				   * interconnect port.
 				   */
+	DEVLINK_PORT_FLAVOUR_PCI_PF, /* Represents eswitch port for
+				      * the PCI PF. It is an internal
+				      * port that faces the PCI PF.
+				      */
+	DEVLINK_PORT_FLAVOUR_PCI_VF, /* Represents eswitch port
+				      * for the PCI VF. It is an internal
+				      * port that faces the PCI VF.
+				      */
 };
 
 enum devlink_param_cmode {
@@ -337,6 +345,9 @@ enum devlink_attr {
 	DEVLINK_ATTR_FLASH_UPDATE_STATUS_DONE,	/* u64 */
 	DEVLINK_ATTR_FLASH_UPDATE_STATUS_TOTAL,	/* u64 */
 
+	DEVLINK_ATTR_PORT_PCI_PF_NUMBER,	/* u16 */
+	DEVLINK_ATTR_PORT_PCI_VF_NUMBER,	/* u16 */
+
 	/* add new attributes above here, update the policy in devlink.c */
 
 	__DEVLINK_ATTR_MAX,
-- 
2.19.2


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

* [PATCH net-next iproute2 v2 2/2] devlink: Introduce PCI PF and VF port flavour and attribute
  2019-07-10 12:39   ` [PATCH net-next iproute2 v2 1/2] devlink: Update kernel header to commit Parav Pandit
@ 2019-07-10 12:39     ` Parav Pandit
  2019-07-10 13:57       ` Jiri Pirko
  2019-07-10 21:01       ` David Ahern
  0 siblings, 2 replies; 71+ messages in thread
From: Parav Pandit @ 2019-07-10 12:39 UTC (permalink / raw)
  To: netdev; +Cc: stephen, dsahern, jiri, Parav Pandit

Introduce PCI PF and VF port flavour and port attributes such as PF
number and VF number.

$ devlink port show
pci/0000:05:00.0/0: type eth netdev eth0 flavour pcipf pfnum 0
pci/0000:05:00.0/1: type eth netdev eth1 flavour pcivf pfnum 0 vfnum 0
pci/0000:05:00.0/2: type eth netdev eth2 flavour pcivf pfnum 0 vfnum 1

Signed-off-by: Parav Pandit <parav@mellanox.com>
---
Changelog:
v1->v2:
 - Instead of if-else using switch-case.
 - Split patch to two patches to have kernel header update in dedicated
   patch.
---
 devlink/devlink.c | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/devlink/devlink.c b/devlink/devlink.c
index ac8c0fb1..d8197ea3 100644
--- a/devlink/devlink.c
+++ b/devlink/devlink.c
@@ -2794,11 +2794,29 @@ static const char *port_flavour_name(uint16_t flavour)
 		return "cpu";
 	case DEVLINK_PORT_FLAVOUR_DSA:
 		return "dsa";
+	case DEVLINK_PORT_FLAVOUR_PCI_PF:
+		return "pcipf";
+	case DEVLINK_PORT_FLAVOUR_PCI_VF:
+		return "pcivf";
 	default:
 		return "<unknown flavour>";
 	}
 }
 
+static void pr_out_port_pfvf_num(struct dl *dl, struct nlattr **tb)
+{
+	uint16_t fn_num;
+
+	if (tb[DEVLINK_ATTR_PORT_PCI_PF_NUMBER]) {
+		fn_num = mnl_attr_get_u16(tb[DEVLINK_ATTR_PORT_PCI_PF_NUMBER]);
+		pr_out_uint(dl, "pfnum", fn_num);
+	}
+	if (tb[DEVLINK_ATTR_PORT_PCI_VF_NUMBER]) {
+		fn_num = mnl_attr_get_u16(tb[DEVLINK_ATTR_PORT_PCI_VF_NUMBER]);
+		pr_out_uint(dl, "vfnum", fn_num);
+	}
+}
+
 static void pr_out_port(struct dl *dl, struct nlattr **tb)
 {
 	struct nlattr *pt_attr = tb[DEVLINK_ATTR_PORT_TYPE];
@@ -2828,6 +2846,15 @@ static void pr_out_port(struct dl *dl, struct nlattr **tb)
 				mnl_attr_get_u16(tb[DEVLINK_ATTR_PORT_FLAVOUR]);
 
 		pr_out_str(dl, "flavour", port_flavour_name(port_flavour));
+
+		switch (port_flavour) {
+		case DEVLINK_PORT_FLAVOUR_PCI_PF:
+		case DEVLINK_PORT_FLAVOUR_PCI_VF:
+			pr_out_port_pfvf_num(dl, tb);
+			break;
+		default:
+			break;
+		}
 	}
 	if (tb[DEVLINK_ATTR_PORT_NUMBER]) {
 		uint32_t port_number;
-- 
2.19.2


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

* Re: [PATCH net-next iproute2 v2 2/2] devlink: Introduce PCI PF and VF port flavour and attribute
  2019-07-10 12:39     ` [PATCH net-next iproute2 v2 2/2] devlink: Introduce PCI PF and VF port flavour and attribute Parav Pandit
@ 2019-07-10 13:57       ` Jiri Pirko
  2019-07-10 21:01       ` David Ahern
  1 sibling, 0 replies; 71+ messages in thread
From: Jiri Pirko @ 2019-07-10 13:57 UTC (permalink / raw)
  To: Parav Pandit; +Cc: netdev, stephen, dsahern, jiri

Wed, Jul 10, 2019 at 02:39:52PM CEST, parav@mellanox.com wrote:
>Introduce PCI PF and VF port flavour and port attributes such as PF
>number and VF number.
>
>$ devlink port show
>pci/0000:05:00.0/0: type eth netdev eth0 flavour pcipf pfnum 0
>pci/0000:05:00.0/1: type eth netdev eth1 flavour pcivf pfnum 0 vfnum 0
>pci/0000:05:00.0/2: type eth netdev eth2 flavour pcivf pfnum 0 vfnum 1
>
>Signed-off-by: Parav Pandit <parav@mellanox.com>

Acked-by: Jiri Pirko <jiri@mellanox.com>

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

* Re: [PATCH net-next iproute2 v2 2/2] devlink: Introduce PCI PF and VF port flavour and attribute
  2019-07-10 12:39     ` [PATCH net-next iproute2 v2 2/2] devlink: Introduce PCI PF and VF port flavour and attribute Parav Pandit
  2019-07-10 13:57       ` Jiri Pirko
@ 2019-07-10 21:01       ` David Ahern
  1 sibling, 0 replies; 71+ messages in thread
From: David Ahern @ 2019-07-10 21:01 UTC (permalink / raw)
  To: Parav Pandit, netdev; +Cc: stephen, dsahern, jiri

On 7/10/19 6:39 AM, Parav Pandit wrote:
> Introduce PCI PF and VF port flavour and port attributes such as PF
> number and VF number.
> 
> $ devlink port show
> pci/0000:05:00.0/0: type eth netdev eth0 flavour pcipf pfnum 0
> pci/0000:05:00.0/1: type eth netdev eth1 flavour pcivf pfnum 0 vfnum 0
> pci/0000:05:00.0/2: type eth netdev eth2 flavour pcivf pfnum 0 vfnum 1
> 
> Signed-off-by: Parav Pandit <parav@mellanox.com>
> ---
> Changelog:
> v1->v2:
>  - Instead of if-else using switch-case.
>  - Split patch to two patches to have kernel header update in dedicated
>    patch.
> ---
>  devlink/devlink.c | 27 +++++++++++++++++++++++++++
>  1 file changed, 27 insertions(+)
> 

applied to iproute2-next. Thanks

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

end of thread, other threads:[~2019-07-10 21:01 UTC | newest]

Thread overview: 71+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-01 12:27 [PATCH net-next 0/3] devlink: Introduce PCI PF, VF ports and attributes Parav Pandit
2019-07-01 12:27 ` [PATCH net-next 1/3] devlink: Introduce PCI PF port flavour and port attribute Parav Pandit
2019-07-01 23:26   ` Jakub Kicinski
2019-07-02  4:26     ` Parav Pandit
2019-07-02 17:47       ` Jakub Kicinski
2019-07-02 18:50         ` Parav Pandit
2019-07-02 23:42           ` Jakub Kicinski
2019-07-03  2:08             ` Parav Pandit
2019-07-03  2:15               ` Jakub Kicinski
2019-07-03  4:46                 ` Parav Pandit
2019-07-03 10:37                   ` Jiri Pirko
2019-07-03 13:49                     ` Parav Pandit
2019-07-03 14:33                       ` Jiri Pirko
2019-07-03 14:09                     ` Andrew Lunn
2019-07-03 14:34                       ` Jiri Pirko
2019-07-03 16:13                         ` Parav Pandit
2019-07-04  7:44                           ` Jiri Pirko
2019-07-01 12:27 ` [PATCH net-next 2/3] devlink: Introduce PCI VF " Parav Pandit
2019-07-01 12:27 ` [PATCH net-next 3/3] net/mlx5e: Register devlink ports for physical link, PCI PF, VFs Parav Pandit
2019-07-01 18:27 ` [PATCH] devlink: Introduce PCI PF and VF port flavour and attribute Parav Pandit
2019-07-01 18:30 ` [RESEND PATCH iproute2 net-next] " Parav Pandit
2019-07-09 19:49   ` Parav Pandit
2019-07-10 12:39   ` [PATCH net-next iproute2 v2 1/2] devlink: Update kernel header to commit Parav Pandit
2019-07-10 12:39     ` [PATCH net-next iproute2 v2 2/2] devlink: Introduce PCI PF and VF port flavour and attribute Parav Pandit
2019-07-10 13:57       ` Jiri Pirko
2019-07-10 21:01       ` David Ahern
2019-07-05  7:37 ` [PATCH net-next v2 0/3] devlink: Introduce PCI PF, VF ports and attributes Parav Pandit
2019-07-05  7:37   ` [PATCH net-next v2 1/3] devlink: Introduce PCI PF port flavour and port attribute Parav Pandit
2019-07-05 19:17     ` Jakub Kicinski
2019-07-06  6:12       ` Parav Pandit
2019-07-05  7:37   ` [PATCH net-next v2 2/3] devlink: Introduce PCI VF " Parav Pandit
2019-07-05  7:37   ` [PATCH net-next v2 3/3] net/mlx5e: Register devlink ports for physical link, PCI PF, VFs Parav Pandit
2019-07-06  6:16 ` [PATCH net-next v3 0/3] devlink: Introduce PCI PF, VF ports and attributes Parav Pandit
2019-07-06  6:16   ` [PATCH net-next v3 1/3] devlink: Introduce PCI PF port flavour and port attribute Parav Pandit
2019-07-06  6:26     ` Jiri Pirko
2019-07-06 18:38       ` Parav Pandit
2019-07-06  6:16   ` [PATCH net-next v3 2/3] devlink: Introduce PCI VF " Parav Pandit
2019-07-06  6:16   ` [PATCH net-next v3 3/3] net/mlx5e: Register devlink ports for physical link, PCI PF, VFs Parav Pandit
2019-07-06 18:23 ` [PATCH net-next v4 0/4] devlink: Introduce PCI PF, VF ports and attributes Parav Pandit
2019-07-06 18:23   ` [PATCH net-next v4 1/4] devlink: Refactor physical port attributes Parav Pandit
2019-07-07 19:47     ` Jiri Pirko
2019-07-08  4:34       ` Parav Pandit
2019-07-06 18:23   ` [PATCH net-next v4 2/4] devlink: Introduce PCI PF port flavour and port attribute Parav Pandit
2019-07-07 19:50     ` Jiri Pirko
2019-07-06 18:23   ` [PATCH net-next v4 3/4] devlink: Introduce PCI VF " Parav Pandit
2019-07-07 19:50     ` Jiri Pirko
2019-07-06 18:23   ` [PATCH net-next v4 4/4] net/mlx5e: Register devlink ports for physical link, PCI PF, VFs Parav Pandit
2019-07-07 19:51     ` Jiri Pirko
2019-07-08  4:15 ` [PATCH net-next v5 0/5] devlink: Introduce PCI PF, VF ports and attributes Parav Pandit
2019-07-08  4:15   ` [PATCH net-next v5 1/5] devlink: Refactor physical port attributes Parav Pandit
2019-07-08 14:44     ` Jiri Pirko
2019-07-08  4:15   ` [PATCH net-next v5 2/5] devlink: Return physical port fields only for applicable port flavours Parav Pandit
2019-07-08 14:44     ` Jiri Pirko
2019-07-08  4:15   ` [PATCH net-next v5 3/5] devlink: Introduce PCI PF port flavour and port attribute Parav Pandit
2019-07-08 21:14     ` Jakub Kicinski
2019-07-09  2:36       ` Parav Pandit
2019-07-08  4:15   ` [PATCH net-next v5 4/5] devlink: Introduce PCI VF " Parav Pandit
2019-07-08  4:15   ` [PATCH net-next v5 5/5] net/mlx5e: Register devlink ports for physical link, PCI PF, VFs Parav Pandit
2019-07-09  4:17 ` [PATCH net-next v6 0/5] devlink: Introduce PCI PF, VF ports and attributes Parav Pandit
2019-07-09  4:17   ` [PATCH net-next v6 1/5] devlink: Refactor physical port attributes Parav Pandit
2019-07-09  4:17   ` [PATCH net-next v6 2/5] devlink: Return physical port fields only for applicable port flavours Parav Pandit
2019-07-09  4:17   ` [PATCH net-next v6 3/5] devlink: Introduce PCI PF port flavour and port attribute Parav Pandit
2019-07-09  4:17   ` [PATCH net-next v6 4/5] devlink: Introduce PCI VF " Parav Pandit
2019-07-09  4:17   ` [PATCH net-next v6 5/5] net/mlx5e: Register devlink ports for physical link, PCI PF, VFs Parav Pandit
2019-07-09  5:40   ` [PATCH net-next v6 0/5] devlink: Introduce PCI PF, VF ports and attributes Jakub Kicinski
2019-07-09  6:17     ` Jiri Pirko
2019-07-09 18:20       ` Jakub Kicinski
2019-07-09 19:03         ` David Miller
2019-07-09 19:21           ` Parav Pandit
2019-07-10  6:41           ` Jiri Pirko
2019-07-09  6:20     ` Parav Pandit

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.