[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20191107160834.21087-12-parav@mellanox.com>
Date: Thu, 7 Nov 2019 10:08:27 -0600
From: Parav Pandit <parav@...lanox.com>
To: alex.williamson@...hat.com, davem@...emloft.net,
kvm@...r.kernel.org, netdev@...r.kernel.org
Cc: saeedm@...lanox.com, kwankhede@...dia.com, leon@...nel.org,
cohuck@...hat.com, jiri@...lanox.com, linux-rdma@...r.kernel.org,
Parav Pandit <parav@...lanox.com>
Subject: [PATCH net-next 12/19] devlink: Introduce mdev port flavour
Introduce a new mdev port flavour for mdev devices.
PF.
Prepare such port's phys_port_name using unique mdev alias.
An example output for eswitch ports with one physical port and
one mdev port:
$ devlink port show
pci/0000:06:00.0/65535: type eth netdev p0 flavour physical port 0
pci/0000:06:00.0/32768: type eth netdev p1b0348cf880a flavour mdev alias 1b0348cf880a
Signed-off-by: Parav Pandit <parav@...lanox.com>
---
include/net/devlink.h | 9 +++++++++
include/uapi/linux/devlink.h | 5 +++++
net/core/devlink.c | 32 ++++++++++++++++++++++++++++++++
3 files changed, 46 insertions(+)
diff --git a/include/net/devlink.h b/include/net/devlink.h
index 6bf3b9e0595a..fcffc7f7cff2 100644
--- a/include/net/devlink.h
+++ b/include/net/devlink.h
@@ -60,6 +60,10 @@ struct devlink_port_pci_vf_attrs {
u16 vf; /* Associated PCI VF for of the PCI PF for this port. */
};
+struct devlink_port_mdev_attrs {
+ const char *mdev_alias; /* Unique mdev alias used for this port. */
+};
+
struct devlink_port_attrs {
u8 set:1,
split:1,
@@ -70,6 +74,7 @@ struct devlink_port_attrs {
struct devlink_port_phys_attrs phys;
struct devlink_port_pci_pf_attrs pci_pf;
struct devlink_port_pci_vf_attrs pci_vf;
+ struct devlink_port_mdev_attrs mdev;
};
};
@@ -802,6 +807,10 @@ 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);
+void devlink_port_attrs_mdev_set(struct devlink_port *devlink_port,
+ const unsigned char *switch_id,
+ unsigned char switch_id_len,
+ const char *mdev_alias);
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 b558ea88b766..db803c0d0e9f 100644
--- a/include/uapi/linux/devlink.h
+++ b/include/uapi/linux/devlink.h
@@ -187,6 +187,10 @@ enum devlink_port_flavour {
* for the PCI VF. It is an internal
* port that faces the PCI VF.
*/
+ DEVLINK_PORT_FLAVOUR_MDEV, /* Represents eswitch port for the
+ * mdev device. It is an internal
+ * port that faces the mdev device.
+ */
};
enum devlink_param_cmode {
@@ -424,6 +428,7 @@ enum devlink_attr {
DEVLINK_ATTR_NETNS_FD, /* u32 */
DEVLINK_ATTR_NETNS_PID, /* u32 */
DEVLINK_ATTR_NETNS_ID, /* u32 */
+ DEVLINK_ATTR_PORT_MDEV_ALIAS, /* string */
/* add new attributes above here, update the policy in devlink.c */
diff --git a/net/core/devlink.c b/net/core/devlink.c
index 97e9a2246929..cb7b6ef5d520 100644
--- a/net/core/devlink.c
+++ b/net/core/devlink.c
@@ -542,6 +542,11 @@ static int devlink_nl_port_attrs_put(struct sk_buff *msg,
attrs->pci_vf.vf))
return -EMSGSIZE;
break;
+ case DEVLINK_PORT_FLAVOUR_MDEV:
+ if (nla_put_string(msg, DEVLINK_ATTR_PORT_MDEV_ALIAS,
+ attrs->mdev.mdev_alias))
+ return -EMSGSIZE;
+ break;
case DEVLINK_PORT_FLAVOUR_PHYSICAL:
case DEVLINK_PORT_FLAVOUR_CPU:
case DEVLINK_PORT_FLAVOUR_DSA:
@@ -6617,6 +6622,30 @@ void devlink_port_attrs_pci_vf_set(struct devlink_port *devlink_port,
}
EXPORT_SYMBOL_GPL(devlink_port_attrs_pci_vf_set);
+/**
+ * devlink_port_attrs_mdev_set - Set mdev port attributes
+ *
+ * @devlink_port: devlink port
+ * @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
+ * @mdev_alias: unique mdev alias for this port used to form phys_port_name
+ */
+void devlink_port_attrs_mdev_set(struct devlink_port *devlink_port,
+ const unsigned char *switch_id,
+ unsigned char switch_id_len,
+ const char *mdev_alias)
+{
+ struct devlink_port_attrs *attrs = &devlink_port->attrs;
+
+ if (__devlink_port_attrs_set(devlink_port,
+ DEVLINK_PORT_FLAVOUR_MDEV,
+ switch_id, switch_id_len))
+ return;
+ attrs->mdev.mdev_alias = mdev_alias;
+}
+EXPORT_SYMBOL_GPL(devlink_port_attrs_mdev_set);
+
static int __devlink_port_phys_port_name_get(struct devlink_port *devlink_port,
char *name, size_t len)
{
@@ -6649,6 +6678,9 @@ static int __devlink_port_phys_port_name_get(struct devlink_port *devlink_port,
n = snprintf(name, len, "pf%uvf%u",
attrs->pci_vf.pf, attrs->pci_vf.vf);
break;
+ case DEVLINK_PORT_FLAVOUR_MDEV:
+ n = snprintf(name, len, "p%s", attrs->mdev.mdev_alias);
+ break;
}
if (n >= len)
--
2.19.2
Powered by blists - more mailing lists