The devlink interface was introduced [0] in the Linux 4.6 time
frame and has since gained traction among multiple hardware
vendors.
The devlink-port [1] and devlink-info[2] interfaces are
particularly useful for managing NICs connected to multiple
distinct CPUs such as SmartNICs.
In such a topology it would be useful to be able to offload
Open vSwitch and OVN onto the NIC SoC operating system and this
library will help with discovering and managing ports representing
resources made available on the host from the NIC SoC side.
The library will be consumed by upcoming proposed changes to OVN,
and I think it makes sense to maintain it together with the Open
vSwitch netlink library code. The proposed changes are also
referenced in specifications proposed to the OpenStack project [3][4].
0:
https://lore.kernel.org/netdev/1456504351-18871-1-git-send-email-j...@resnulli.us/
1:
https://github.com/torvalds/linux/blob/master/Documentation/networking/devlink/devlink-port.rst
2:
https://github.com/torvalds/linux/blob/master/Documentation/networking/devlink/devlink-info.rst
3: https://review.opendev.org/c/openstack/nova-specs/+/787458
4: https://review.opendev.org/c/openstack/neutron-specs/+/788821
Signed-off-by: Frode Nordahl
---
include/linux/automake.mk | 1 +
include/linux/devlink.h | 625 ++
include/openvswitch/types.h | 8 +
lib/automake.mk | 2 +
lib/netlink-devlink.c | 498
lib/netlink-devlink.h | 114 ++
lib/netlink.c | 16 +
lib/netlink.h | 5 +
lib/packets.h | 1 +
tests/.gitignore | 3 +
tests/automake.mk | 16 +
tests/system-devlink-info.at | 9 +
tests/system-devlink-port.at | 12 +
tests/system-devlink-testsuite.at | 45 +++
utilities/.gitignore | 1 +
utilities/automake.mk | 3 +
utilities/devlink.c | 245
17 files changed, 1604 insertions(+)
create mode 100644 include/linux/devlink.h
create mode 100644 lib/netlink-devlink.c
create mode 100644 lib/netlink-devlink.h
create mode 100644 tests/system-devlink-info.at
create mode 100644 tests/system-devlink-port.at
create mode 100644 tests/system-devlink-testsuite.at
create mode 100644 utilities/devlink.c
diff --git a/include/linux/automake.mk b/include/linux/automake.mk
index 8f063f482..8718f980d 100644
--- a/include/linux/automake.mk
+++ b/include/linux/automake.mk
@@ -1,4 +1,5 @@
noinst_HEADERS += \
+ include/linux/devlink.h \
include/linux/netlink.h \
include/linux/netfilter/nf_conntrack_sctp.h \
include/linux/pkt_cls.h \
diff --git a/include/linux/devlink.h b/include/linux/devlink.h
new file mode 100644
index 0..28ea92b62
--- /dev/null
+++ b/include/linux/devlink.h
@@ -0,0 +1,625 @@
+/*
+ * The kernel devlink interface has gained a number of additions in recent
+ * kernel versions. To allow Open vSwitch to consume these interfaces in its
+ * runtime environment regardless of what kernel version was available at build
+ * time, and also avoiding an elaborate set of autoconf macros to check for
+ * presence of individual pieces, we include the entire file here.
+ *
+ * Source:
+ *
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/plain/include/uapi/linux/devlink.h
@ a556dded9c23c51c82654f1ebe389cbc0bc22057 */
+#if !defined(__KERNEL__)
+#ifndef __UAPI_LINUX_DEVLINK_WRAPPER_H
+#define __UAPI_LINUX_DEVLINK_WRAPPER_H 1
+/* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */
+/*
+ * include/uapi/linux/devlink.h - Network physical device Netlink interface
+ * Copyright (c) 2016 Mellanox Technologies. All rights reserved.
+ * Copyright (c) 2016 Jiri Pirko
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+
+#ifndef _UAPI_LINUX_DEVLINK_H_
+#define _UAPI_LINUX_DEVLINK_H_
+
+#include
+
+#define DEVLINK_GENL_NAME "devlink"
+#define DEVLINK_GENL_VERSION 0x1
+#define DEVLINK_GENL_MCGRP_CONFIG_NAME "config"
+
+enum devlink_command {
+ /* don't change the order or add anything between, this is ABI! */
+ DEVLINK_CMD_UNSPEC,
+
+ DEVLINK_CMD_GET,/* can dump */
+ DEVLINK_CMD_SET,
+ DEVLINK_CMD_NEW,
+ DEVLINK_CMD_DEL,
+
+ DEVLINK_CMD_PORT_GET, /* can dump */
+ DEVLINK_CMD_PORT_SET,
+ DEVLINK_CMD_PORT_NEW,
+ DEVLINK_CMD_PORT_DEL,
+
+ DEVLINK_CMD_PORT_SPLIT,
+ DEVLINK_CMD_PORT_UNSPLIT,
+
+ DEVLINK_CMD_SB_GET, /* can dump */
+ DEVLINK_CMD_SB_SET,
+ DEVLINK_CMD_SB_NEW,
+ DEVLINK_CMD_SB_DEL,
+
+ DEVLINK_CMD_SB_POOL_GET,/* can dump */
+