devlink: Introduce external controller flag
authorParav Pandit <parav@nvidia.com>
Wed, 9 Sep 2020 04:50:36 +0000 (07:50 +0300)
committerDavid S. Miller <davem@davemloft.net>
Wed, 9 Sep 2020 21:19:55 +0000 (14:19 -0700)
A devlink eswitch port may represent PCI PF/VF ports of a controller.

A controller either located on same system or it can be an external
controller located in host where such NIC is plugged in.

Add the ability for driver to specify if a port is for external
controller.

Use such flag in the mlx5_core driver.

An example of an external controller having VF1 of PF0 belong to
controller 1.

$ devlink port show pci/0000:06:00.0/2
pci/0000:06:00.0/2: type eth netdev ens2f0pf0vf1 flavour pcivf pfnum 0 vfnum 1 external true splittable false
  function:
    hw_addr 00:00:00:00:00:00
$ devlink port show pci/0000:06:00.0/2 -jp
{
    "port": {
        "pci/0000:06:00.0/2": {
            "type": "eth",
            "netdev": "ens2f0pf0vf1",
            "flavour": "pcivf",
            "pfnum": 0,
            "vfnum": 1,
            "external": true,
            "splittable": false,
            "function": {
                "hw_addr": "00:00:00:00:00:00"
            }
        }
    }
}

Signed-off-by: Parav Pandit <parav@nvidia.com>
Reviewed-by: Jiri Pirko <jiri@nvidia.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/mellanox/mlx5/core/en_rep.c
include/net/devlink.h
include/uapi/linux/devlink.h
net/core/devlink.c

index e13e5d1b3eaed7220939385d15e4fff475d6aa22..5b3599caa007c5fcf7ac25102d41829f39a7fcf7 100644 (file)
@@ -1215,11 +1215,13 @@ static int register_devlink_port(struct mlx5_core_dev *dev,
        struct devlink_port_attrs attrs = {};
        struct netdev_phys_item_id ppid = {};
        unsigned int dl_port_index = 0;
+       bool external;
        u16 pfnum;
 
        if (!is_devlink_port_supported(dev, rpriv))
                return 0;
 
+       external = mlx5_core_is_ecpf_esw_manager(dev);
        mlx5e_rep_get_port_parent_id(rpriv->netdev, &ppid);
        dl_port_index = mlx5_esw_vport_to_devlink_port_index(dev, rep->vport);
        pfnum = PCI_FUNC(dev->pdev->devfn);
@@ -1232,12 +1234,12 @@ static int register_devlink_port(struct mlx5_core_dev *dev,
        } else if (rep->vport == MLX5_VPORT_PF) {
                memcpy(rpriv->dl_port.attrs.switch_id.id, &ppid.id[0], ppid.id_len);
                rpriv->dl_port.attrs.switch_id.id_len = ppid.id_len;
-               devlink_port_attrs_pci_pf_set(&rpriv->dl_port, pfnum);
+               devlink_port_attrs_pci_pf_set(&rpriv->dl_port, pfnum, external);
        } else if (mlx5_eswitch_is_vf_vport(dev->priv.eswitch, rpriv->rep->vport)) {
                memcpy(rpriv->dl_port.attrs.switch_id.id, &ppid.id[0], ppid.id_len);
                rpriv->dl_port.attrs.switch_id.id_len = ppid.id_len;
                devlink_port_attrs_pci_vf_set(&rpriv->dl_port,
-                                             pfnum, rep->vport - 1);
+                                             pfnum, rep->vport - 1, external);
        }
        return devlink_port_register(devlink, &rpriv->dl_port, dl_port_index);
 }
index efff9274d248cb0132399ab1b3d8f798007d4bd6..2dad8c9151f4bfda4ecc1e6ddcd49d1476c153f4 100644 (file)
@@ -60,19 +60,23 @@ struct devlink_port_phys_attrs {
 /**
  * struct devlink_port_pci_pf_attrs - devlink port's PCI PF attributes
  * @pf: Associated PCI PF number for this port.
+ * @external: when set, indicates if a port is for an external controller
  */
 struct devlink_port_pci_pf_attrs {
        u16 pf;
+       u8 external:1;
 };
 
 /**
  * struct devlink_port_pci_vf_attrs - devlink port's PCI VF attributes
  * @pf: Associated PCI PF number for this port.
  * @vf: Associated PCI VF for of the PCI PF for this port.
+ * @external: when set, indicates if a port is for an external controller
  */
 struct devlink_port_pci_vf_attrs {
        u16 pf;
        u16 vf;
+       u8 external:1;
 };
 
 /**
@@ -1215,9 +1219,9 @@ void devlink_port_type_ib_set(struct devlink_port *devlink_port,
 void devlink_port_type_clear(struct devlink_port *devlink_port);
 void devlink_port_attrs_set(struct devlink_port *devlink_port,
                            struct devlink_port_attrs *devlink_port_attrs);
-void devlink_port_attrs_pci_pf_set(struct devlink_port *devlink_port, u16 pf);
+void devlink_port_attrs_pci_pf_set(struct devlink_port *devlink_port, u16 pf, bool external);
 void devlink_port_attrs_pci_vf_set(struct devlink_port *devlink_port,
-                                  u16 pf, u16 vf);
+                                  u16 pf, u16 vf, bool external);
 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,
index cfef4245ea5aa79a3720a09474c55af08fa783af..40823ed7e05addcabd3027548870b9220e305e5b 100644 (file)
@@ -458,6 +458,7 @@ enum devlink_attr {
        DEVLINK_ATTR_PORT_LANES,                        /* u32 */
        DEVLINK_ATTR_PORT_SPLITTABLE,                   /* u8 */
 
+       DEVLINK_ATTR_PORT_EXTERNAL,             /* u8 */
        /* add new attributes above here, update the policy in devlink.c */
 
        __DEVLINK_ATTR_MAX,
index 49e911c19881567935255a32e5f5e1dc938d119a..6f5f85372721ad3cd06ac30538b7504b22b32c14 100644 (file)
@@ -526,6 +526,8 @@ 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;
+               if (nla_put_u8(msg, DEVLINK_ATTR_PORT_EXTERNAL, attrs->pci_pf.external))
+                       return -EMSGSIZE;
                break;
        case DEVLINK_PORT_FLAVOUR_PCI_VF:
                if (nla_put_u16(msg, DEVLINK_ATTR_PORT_PCI_PF_NUMBER,
@@ -533,6 +535,8 @@ static int devlink_nl_port_attrs_put(struct sk_buff *msg,
                    nla_put_u16(msg, DEVLINK_ATTR_PORT_PCI_VF_NUMBER,
                                attrs->pci_vf.vf))
                        return -EMSGSIZE;
+               if (nla_put_u8(msg, DEVLINK_ATTR_PORT_EXTERNAL, attrs->pci_vf.external))
+                       return -EMSGSIZE;
                break;
        case DEVLINK_PORT_FLAVOUR_PHYSICAL:
        case DEVLINK_PORT_FLAVOUR_CPU:
@@ -7716,8 +7720,9 @@ EXPORT_SYMBOL_GPL(devlink_port_attrs_set);
  *
  *     @devlink_port: devlink port
  *     @pf: associated PF for the devlink port instance
+ *     @external: indicates if the port is for an external controller
  */
-void devlink_port_attrs_pci_pf_set(struct devlink_port *devlink_port, u16 pf)
+void devlink_port_attrs_pci_pf_set(struct devlink_port *devlink_port, u16 pf, bool external)
 {
        struct devlink_port_attrs *attrs = &devlink_port->attrs;
        int ret;
@@ -7728,6 +7733,7 @@ void devlink_port_attrs_pci_pf_set(struct devlink_port *devlink_port, u16 pf)
                return;
 
        attrs->pci_pf.pf = pf;
+       attrs->pci_pf.external = external;
 }
 EXPORT_SYMBOL_GPL(devlink_port_attrs_pci_pf_set);
 
@@ -7737,9 +7743,10 @@ EXPORT_SYMBOL_GPL(devlink_port_attrs_pci_pf_set);
  *     @devlink_port: devlink port
  *     @pf: associated PF for the devlink port instance
  *     @vf: associated VF of a PF for the devlink port instance
+ *     @external: indicates if the port is for an external controller
  */
 void devlink_port_attrs_pci_vf_set(struct devlink_port *devlink_port,
-                                  u16 pf, u16 vf)
+                                  u16 pf, u16 vf, bool external)
 {
        struct devlink_port_attrs *attrs = &devlink_port->attrs;
        int ret;
@@ -7750,6 +7757,7 @@ void devlink_port_attrs_pci_vf_set(struct devlink_port *devlink_port,
                return;
        attrs->pci_vf.pf = pf;
        attrs->pci_vf.vf = vf;
+       attrs->pci_vf.external = external;
 }
 EXPORT_SYMBOL_GPL(devlink_port_attrs_pci_vf_set);