naccyde / rpms / iproute

Forked from rpms/iproute 9 months ago
Clone

Blame SOURCES/0017-vdpa-Allow-for-printing-negotiated-features-of-a-dev.patch

32391d
From fab19f1e5fe9ccf1d180874d5b0d86c99c7e16cb Mon Sep 17 00:00:00 2001
32391d
Message-Id: <fab19f1e5fe9ccf1d180874d5b0d86c99c7e16cb.1647872200.git.aclaudi@redhat.com>
32391d
In-Reply-To: <b30268eda844bdebbb8e5e4f5735e3b1bb666368.1647872200.git.aclaudi@redhat.com>
32391d
References: <b30268eda844bdebbb8e5e4f5735e3b1bb666368.1647872200.git.aclaudi@redhat.com>
32391d
From: Andrea Claudi <aclaudi@redhat.com>
32391d
Date: Mon, 21 Mar 2022 15:03:16 +0100
32391d
Subject: [PATCH] vdpa: Allow for printing negotiated features of a device
32391d
32391d
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2056827
32391d
Upstream Status: iproute2-next.git commit bd91c764
32391d
32391d
commit bd91c764718997adaa1d86eee5c585e67ca85356
32391d
Author: Eli Cohen <elic@nvidia.com>
32391d
Date:   Sun Mar 13 19:12:17 2022 +0200
32391d
32391d
    vdpa: Allow for printing negotiated features of a device
32391d
32391d
    When reading the configuration of a vdpa device, check if the
32391d
    VDPA_ATTR_DEV_NEGOTIATED_FEATURES is available. If it is, parse the
32391d
    feature bits and print a string representation of each of the feature
32391d
    bits.
32391d
32391d
    We keep the strings in two different arrays. One for net device related
32391d
    devices and one for generic feature bits.
32391d
32391d
    In this patch we parse only net device specific features. Support for
32391d
    other devices can be added later. If the device queried is not a net
32391d
    device, we print its bit number only.
32391d
32391d
    Examples:
32391d
    1. Standard presentation
32391d
    $ vdpa dev config show vdpa-a
32391d
    vdpa-a: mac 00:00:00:00:88:88 link up link_announce false max_vq_pairs 2 mtu 9000
32391d
      negotiated_features CSUM GUEST_CSUM MTU MAC HOST_TSO4 HOST_TSO6 STATUS \
32391d
    CTRL_VQ MQ CTRL_MAC_ADDR VERSION_1 ACCESS_PLATFORM
32391d
32391d
    2. json output
32391d
    $ vdpa -j dev config show vdpa-a
32391d
    {"config":{"vdpa-a":{"mac":"00:00:00:00:88:88","link":"up","link_announce":false,\
32391d
    "max_vq_pairs":2,"mtu":9000,"negotiated_features":["CSUM","GUEST_CSUM",\
32391d
    "MTU","MAC","HOST_TSO4","HOST_TSO6","STATUS","CTRL_VQ","MQ","CTRL_MAC_ADDR",\
32391d
    "VERSION_1","ACCESS_PLATFORM"]}}}
32391d
32391d
    3. Pretty json
32391d
    $ vdpa -jp dev config show vdpa-a
32391d
    {
32391d
        "config": {
32391d
            "vdpa-a": {
32391d
                "mac": "00:00:00:00:88:88",
32391d
                "link ": "up",
32391d
                "link_announce ": false,
32391d
                "max_vq_pairs": 2,
32391d
                "mtu": 9000,
32391d
                "negotiated_features": [
32391d
    "CSUM","GUEST_CSUM","MTU","MAC","HOST_TSO4","HOST_TSO6","STATUS","CTRL_VQ",\
32391d
    "MQ","CTRL_MAC_ADDR","VERSION_1","ACCESS_PLATFORM" ]
32391d
            }
32391d
        }
32391d
    }
32391d
32391d
    Reviewed-by: Si-Wei Liu<si-wei.liu@oracle.com>
32391d
    Acked-by: Jason Wang <jasowang@redhat.com>
32391d
    Signed-off-by: Eli Cohen <elic@nvidia.com>
32391d
    Signed-off-by: David Ahern <dsahern@kernel.org>
32391d
---
32391d
 vdpa/vdpa.c | 105 +++++++++++++++++++++++++++++++++++++++++++++++++++-
32391d
 1 file changed, 103 insertions(+), 2 deletions(-)
32391d
32391d
diff --git a/vdpa/vdpa.c b/vdpa/vdpa.c
32391d
index 4ccb5648..40078b1c 100644
32391d
--- a/vdpa/vdpa.c
32391d
+++ b/vdpa/vdpa.c
32391d
@@ -10,6 +10,8 @@
32391d
 #include <linux/virtio_net.h>
32391d
 #include <linux/netlink.h>
32391d
 #include <libmnl/libmnl.h>
32391d
+#include <linux/virtio_ring.h>
32391d
+#include <linux/virtio_config.h>
32391d
 #include "mnl_utils.h"
32391d
 #include <rt_names.h>
32391d
 
32391d
@@ -78,6 +80,7 @@ static const enum mnl_attr_data_type vdpa_policy[VDPA_ATTR_MAX + 1] = {
32391d
 	[VDPA_ATTR_DEV_VENDOR_ID] = MNL_TYPE_U32,
32391d
 	[VDPA_ATTR_DEV_MAX_VQS] = MNL_TYPE_U32,
32391d
 	[VDPA_ATTR_DEV_MAX_VQ_SIZE] = MNL_TYPE_U16,
32391d
+	[VDPA_ATTR_DEV_NEGOTIATED_FEATURES] = MNL_TYPE_U64,
32391d
 };
32391d
 
32391d
 static int attr_cb(const struct nlattr *attr, void *data)
32391d
@@ -385,6 +388,94 @@ static const char *parse_class(int num)
32391d
 	return class ? class : "< unknown class >";
32391d
 }
32391d
 
32391d
+static const char * const net_feature_strs[64] = {
32391d
+	[VIRTIO_NET_F_CSUM] = "CSUM",
32391d
+	[VIRTIO_NET_F_GUEST_CSUM] = "GUEST_CSUM",
32391d
+	[VIRTIO_NET_F_CTRL_GUEST_OFFLOADS] = "CTRL_GUEST_OFFLOADS",
32391d
+	[VIRTIO_NET_F_MTU] = "MTU",
32391d
+	[VIRTIO_NET_F_MAC] = "MAC",
32391d
+	[VIRTIO_NET_F_GUEST_TSO4] = "GUEST_TSO4",
32391d
+	[VIRTIO_NET_F_GUEST_TSO6] = "GUEST_TSO6",
32391d
+	[VIRTIO_NET_F_GUEST_ECN] = "GUEST_ECN",
32391d
+	[VIRTIO_NET_F_GUEST_UFO] = "GUEST_UFO",
32391d
+	[VIRTIO_NET_F_HOST_TSO4] = "HOST_TSO4",
32391d
+	[VIRTIO_NET_F_HOST_TSO6] = "HOST_TSO6",
32391d
+	[VIRTIO_NET_F_HOST_ECN] = "HOST_ECN",
32391d
+	[VIRTIO_NET_F_HOST_UFO] = "HOST_UFO",
32391d
+	[VIRTIO_NET_F_MRG_RXBUF] = "MRG_RXBUF",
32391d
+	[VIRTIO_NET_F_STATUS] = "STATUS",
32391d
+	[VIRTIO_NET_F_CTRL_VQ] = "CTRL_VQ",
32391d
+	[VIRTIO_NET_F_CTRL_RX] = "CTRL_RX",
32391d
+	[VIRTIO_NET_F_CTRL_VLAN] = "CTRL_VLAN",
32391d
+	[VIRTIO_NET_F_CTRL_RX_EXTRA] = "CTRL_RX_EXTRA",
32391d
+	[VIRTIO_NET_F_GUEST_ANNOUNCE] = "GUEST_ANNOUNCE",
32391d
+	[VIRTIO_NET_F_MQ] = "MQ",
32391d
+	[VIRTIO_F_NOTIFY_ON_EMPTY] = "NOTIFY_ON_EMPTY",
32391d
+	[VIRTIO_NET_F_CTRL_MAC_ADDR] = "CTRL_MAC_ADDR",
32391d
+	[VIRTIO_F_ANY_LAYOUT] = "ANY_LAYOUT",
32391d
+	[VIRTIO_NET_F_RSC_EXT] = "RSC_EXT",
32391d
+	[VIRTIO_NET_F_HASH_REPORT] = "HASH_REPORT",
32391d
+	[VIRTIO_NET_F_RSS] = "RSS",
32391d
+	[VIRTIO_NET_F_STANDBY] = "STANDBY",
32391d
+	[VIRTIO_NET_F_SPEED_DUPLEX] = "SPEED_DUPLEX",
32391d
+};
32391d
+
32391d
+#define VIRTIO_F_IN_ORDER 35
32391d
+#define VIRTIO_F_NOTIFICATION_DATA 38
32391d
+#define VDPA_EXT_FEATURES_SZ (VIRTIO_TRANSPORT_F_END - \
32391d
+			      VIRTIO_TRANSPORT_F_START + 1)
32391d
+
32391d
+static const char * const ext_feature_strs[VDPA_EXT_FEATURES_SZ] = {
32391d
+	[VIRTIO_RING_F_INDIRECT_DESC - VIRTIO_TRANSPORT_F_START] = "RING_INDIRECT_DESC",
32391d
+	[VIRTIO_RING_F_EVENT_IDX - VIRTIO_TRANSPORT_F_START] = "RING_EVENT_IDX",
32391d
+	[VIRTIO_F_VERSION_1 - VIRTIO_TRANSPORT_F_START] = "VERSION_1",
32391d
+	[VIRTIO_F_ACCESS_PLATFORM - VIRTIO_TRANSPORT_F_START] = "ACCESS_PLATFORM",
32391d
+	[VIRTIO_F_RING_PACKED - VIRTIO_TRANSPORT_F_START] = "RING_PACKED",
32391d
+	[VIRTIO_F_IN_ORDER - VIRTIO_TRANSPORT_F_START] = "IN_ORDER",
32391d
+	[VIRTIO_F_ORDER_PLATFORM - VIRTIO_TRANSPORT_F_START] = "ORDER_PLATFORM",
32391d
+	[VIRTIO_F_SR_IOV - VIRTIO_TRANSPORT_F_START] = "SR_IOV",
32391d
+	[VIRTIO_F_NOTIFICATION_DATA - VIRTIO_TRANSPORT_F_START] = "NOTIFICATION_DATA",
32391d
+};
32391d
+
32391d
+static const char * const *dev_to_feature_str[] = {
32391d
+	[VIRTIO_ID_NET] = net_feature_strs,
32391d
+};
32391d
+
32391d
+#define NUM_FEATURE_BITS 64
32391d
+
32391d
+static void print_features(struct vdpa *vdpa, uint64_t features, bool mgmtdevf,
32391d
+			   uint16_t dev_id)
32391d
+{
32391d
+	const char * const *feature_strs = NULL;
32391d
+	const char *s;
32391d
+	int i;
32391d
+
32391d
+	if (dev_id < ARRAY_SIZE(dev_to_feature_str))
32391d
+		feature_strs = dev_to_feature_str[dev_id];
32391d
+
32391d
+	if (mgmtdevf)
32391d
+		pr_out_array_start(vdpa, "dev_features");
32391d
+	else
32391d
+		pr_out_array_start(vdpa, "negotiated_features");
32391d
+
32391d
+	for (i = 0; i < NUM_FEATURE_BITS; i++) {
32391d
+		if (!(features & (1ULL << i)))
32391d
+			continue;
32391d
+
32391d
+		if (i < VIRTIO_TRANSPORT_F_START || i > VIRTIO_TRANSPORT_F_END)
32391d
+			s = feature_strs ? feature_strs[i] : NULL;
32391d
+		else
32391d
+			s = ext_feature_strs[i - VIRTIO_TRANSPORT_F_START];
32391d
+
32391d
+		if (!s)
32391d
+			print_uint(PRINT_ANY, NULL, " bit_%d", i);
32391d
+		else
32391d
+			print_string(PRINT_ANY, NULL, " %s", s);
32391d
+	}
32391d
+
32391d
+	pr_out_array_end(vdpa);
32391d
+}
32391d
+
32391d
 static void pr_out_mgmtdev_show(struct vdpa *vdpa, const struct nlmsghdr *nlh,
32391d
 				struct nlattr **tb)
32391d
 {
32391d
@@ -579,9 +670,10 @@ static int cmd_dev_del(struct vdpa *vdpa,  int argc, char **argv)
32391d
 	return mnlu_gen_socket_sndrcv(&vdpa->nlg, nlh, NULL, NULL);
32391d
 }
32391d
 
32391d
-static void pr_out_dev_net_config(struct nlattr **tb)
32391d
+static void pr_out_dev_net_config(struct vdpa *vdpa, struct nlattr **tb)
32391d
 {
32391d
 	SPRINT_BUF(macaddr);
32391d
+	uint64_t val_u64;
32391d
 	uint16_t val_u16;
32391d
 
32391d
 	if (tb[VDPA_ATTR_DEV_NET_CFG_MACADDR]) {
32391d
@@ -610,6 +702,15 @@ static void pr_out_dev_net_config(struct nlattr **tb)
32391d
 		val_u16 = mnl_attr_get_u16(tb[VDPA_ATTR_DEV_NET_CFG_MTU]);
32391d
 		print_uint(PRINT_ANY, "mtu", "mtu %d ", val_u16);
32391d
 	}
32391d
+	if (tb[VDPA_ATTR_DEV_NEGOTIATED_FEATURES]) {
32391d
+		uint16_t dev_id = 0;
32391d
+
32391d
+		if (tb[VDPA_ATTR_DEV_ID])
32391d
+			dev_id = mnl_attr_get_u32(tb[VDPA_ATTR_DEV_ID]);
32391d
+
32391d
+		val_u64 = mnl_attr_get_u64(tb[VDPA_ATTR_DEV_NEGOTIATED_FEATURES]);
32391d
+		print_features(vdpa, val_u64, false, dev_id);
32391d
+	}
32391d
 }
32391d
 
32391d
 static void pr_out_dev_config(struct vdpa *vdpa, struct nlattr **tb)
32391d
@@ -619,7 +720,7 @@ static void pr_out_dev_config(struct vdpa *vdpa, struct nlattr **tb)
32391d
 	pr_out_vdev_handle_start(vdpa, tb);
32391d
 	switch (device_id) {
32391d
 	case VIRTIO_ID_NET:
32391d
-		pr_out_dev_net_config(tb);
32391d
+		pr_out_dev_net_config(vdpa, tb);
32391d
 		break;
32391d
 	default:
32391d
 		break;
32391d
-- 
32391d
2.35.1
32391d