[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20190301183510.9028-4-jakub.kicinski@netronome.com>
Date: Fri, 1 Mar 2019 10:35:10 -0800
From: Jakub Kicinski <jakub.kicinski@...ronome.com>
To: jiri@...nulli.us
Cc: netdev@...r.kernel.org, oss-drivers@...ronome.com,
Jakub Kicinski <jakub.kicinski@...ronome.com>
Subject: [RFC iproute2-next 3/3] devlink: add support for PCIe device peers
Print peer netdev information.
$ devlink port
pci/0000:82:00.0/0: type eth netdev p4p1 flavour physical
pci/0000:82:00.0/10000: type eth netdev eth1 flavour pci_pf pf 0 peer_netdev enp130s0
$ devlink -jp port
{
"port": {
"pci/0000:82:00.0/0": {
"type": "eth",
"netdev": "p4p1",
"flavour": "physical"
},
"pci/0000:82:00.0/10000": {
"type": "eth",
"netdev": "eth1",
"flavour": "pci_pf",
"pf": 0,
"peer": {
"netdev": "enp130s0"
}
}
}
}
Signed-off-by: Jakub Kicinski <jakub.kicinski@...ronome.com>
---
devlink/devlink.c | 34 ++++++++++++++++++++++++++++++++++
1 file changed, 34 insertions(+)
diff --git a/devlink/devlink.c b/devlink/devlink.c
index c130305b94ff..e4b66aa28f71 100644
--- a/devlink/devlink.c
+++ b/devlink/devlink.c
@@ -417,6 +417,8 @@ static const enum mnl_attr_data_type devlink_policy[DEVLINK_ATTR_MAX + 1] = {
[DEVLINK_ATTR_PORT_PCI_PF_NUMBER] = MNL_TYPE_U32,
[DEVLINK_ATTR_PORT_PCI_VF_NUMBER] = MNL_TYPE_U32,
[DEVLINK_ATTR_PORT_PCI_SUBPORT] = MNL_TYPE_U32,
+ [DEVLINK_ATTR_PORT_PEER_NETDEV_NAME] = MNL_TYPE_STRING,
+ [DEVLINK_ATTR_PORT_PEER_IBDEV_NAME] = MNL_TYPE_STRING,
};
static int attr_cb(const struct nlattr *attr, void *data)
@@ -2783,6 +2785,36 @@ static const char *port_flavour_name(uint16_t flavour)
}
}
+static void pr_out_port_peer(struct dl *dl, struct nlattr *peer)
+{
+ struct nlattr *tb[DEVLINK_ATTR_MAX + 1] = {};
+ const char *netdev = NULL, *ibdev = NULL;
+
+ mnl_attr_parse_nested(peer, attr_cb, tb);
+
+ if (tb[DEVLINK_ATTR_PORT_PEER_NETDEV_NAME])
+ netdev = mnl_attr_get_str(tb[DEVLINK_ATTR_PORT_PEER_NETDEV_NAME]);
+ if (tb[DEVLINK_ATTR_PORT_PEER_IBDEV_NAME])
+ ibdev = mnl_attr_get_str(tb[DEVLINK_ATTR_PORT_PEER_IBDEV_NAME]);
+
+ if (dl->jw) {
+ jsonw_name(dl->jw, "peer");
+ jsonw_start_object(dl->jw);
+
+ if (netdev)
+ pr_out_str(dl, "netdev", netdev);
+ if (ibdev)
+ pr_out_str(dl, "ibdev", ibdev);
+
+ jsonw_end_object(dl->jw);
+ } else {
+ if (netdev)
+ pr_out_str(dl, "peer_netdev", netdev);
+ if (ibdev)
+ pr_out_str(dl, "peer_ibdev", ibdev);
+ }
+}
+
static void pr_out_port(struct dl *dl, struct nlattr **tb)
{
struct nlattr *pt_attr = tb[DEVLINK_ATTR_PORT_TYPE];
@@ -2825,6 +2857,8 @@ static void pr_out_port(struct dl *dl, struct nlattr **tb)
if (tb[DEVLINK_ATTR_PORT_PCI_SUBPORT])
pr_out_uint(dl, "subport",
mnl_attr_get_u32(tb[DEVLINK_ATTR_PORT_PCI_SUBPORT]));
+ if (tb[DEVLINK_ATTR_PORT_PEER])
+ pr_out_port_peer(dl, tb[DEVLINK_ATTR_PORT_PEER]);
pr_out_port_handle_end(dl);
}
--
2.19.2
Powered by blists - more mailing lists