RDMA/nldev: helper functions to add driver attributes
authorSteve Wise <swise@opengridcomputing.com>
Thu, 3 May 2018 15:41:42 +0000 (08:41 -0700)
committerDoug Ledford <dledford@redhat.com>
Thu, 3 May 2018 19:51:27 +0000 (15:51 -0400)
These help rdma drivers to fill out the driver entries.

Signed-off-by: Steve Wise <swise@opengridcomputing.com>
Signed-off-by: Doug Ledford <dledford@redhat.com>
drivers/infiniband/core/nldev.c
include/rdma/restrack.h

index 50efca482a6cabb6eaca748c3956385da1f98d9e..8674ca2d8f9184442cd7ea0260d85a771c881ad3 100644 (file)
@@ -109,6 +109,72 @@ static const struct nla_policy nldev_policy[RDMA_NLDEV_ATTR_MAX] = {
        [RDMA_NLDEV_ATTR_DRIVER_U64]            = { .type = NLA_U64 },
 };
 
+static int put_driver_name_print_type(struct sk_buff *msg, const char *name,
+                                     enum rdma_nldev_print_type print_type)
+{
+       if (nla_put_string(msg, RDMA_NLDEV_ATTR_DRIVER_STRING, name))
+               return -EMSGSIZE;
+       if (print_type != RDMA_NLDEV_PRINT_TYPE_UNSPEC &&
+           nla_put_u8(msg, RDMA_NLDEV_ATTR_DRIVER_PRINT_TYPE, print_type))
+               return -EMSGSIZE;
+
+       return 0;
+}
+
+static int _rdma_nl_put_driver_u32(struct sk_buff *msg, const char *name,
+                                  enum rdma_nldev_print_type print_type,
+                                  u32 value)
+{
+       if (put_driver_name_print_type(msg, name, print_type))
+               return -EMSGSIZE;
+       if (nla_put_u32(msg, RDMA_NLDEV_ATTR_DRIVER_U32, value))
+               return -EMSGSIZE;
+
+       return 0;
+}
+
+static int _rdma_nl_put_driver_u64(struct sk_buff *msg, const char *name,
+                                  enum rdma_nldev_print_type print_type,
+                                  u64 value)
+{
+       if (put_driver_name_print_type(msg, name, print_type))
+               return -EMSGSIZE;
+       if (nla_put_u64_64bit(msg, RDMA_NLDEV_ATTR_DRIVER_U64, value,
+                             RDMA_NLDEV_ATTR_PAD))
+               return -EMSGSIZE;
+
+       return 0;
+}
+
+int rdma_nl_put_driver_u32(struct sk_buff *msg, const char *name, u32 value)
+{
+       return _rdma_nl_put_driver_u32(msg, name, RDMA_NLDEV_PRINT_TYPE_UNSPEC,
+                                      value);
+}
+EXPORT_SYMBOL(rdma_nl_put_driver_u32);
+
+int rdma_nl_put_driver_u32_hex(struct sk_buff *msg, const char *name,
+                              u32 value)
+{
+       return _rdma_nl_put_driver_u32(msg, name, RDMA_NLDEV_PRINT_TYPE_HEX,
+                                      value);
+}
+EXPORT_SYMBOL(rdma_nl_put_driver_u32_hex);
+
+int rdma_nl_put_driver_u64(struct sk_buff *msg, const char *name, u64 value)
+{
+       return _rdma_nl_put_driver_u64(msg, name, RDMA_NLDEV_PRINT_TYPE_UNSPEC,
+                                      value);
+}
+EXPORT_SYMBOL(rdma_nl_put_driver_u64);
+
+int rdma_nl_put_driver_u64_hex(struct sk_buff *msg, const char *name, u64 value)
+{
+       return _rdma_nl_put_driver_u64(msg, name, RDMA_NLDEV_PRINT_TYPE_HEX,
+                                      value);
+}
+EXPORT_SYMBOL(rdma_nl_put_driver_u64_hex);
+
 static int fill_nldev_handle(struct sk_buff *msg, struct ib_device *device)
 {
        if (nla_put_u32(msg, RDMA_NLDEV_ATTR_DEV_INDEX, device->index))
index 14304e2496851102dcfb7c736b17dc854317940e..637968589922ca475fbe0220e0f37ea1e95df08d 100644 (file)
@@ -12,6 +12,7 @@
 #include <linux/kref.h>
 #include <linux/completion.h>
 #include <linux/sched/task.h>
+#include <uapi/rdma/rdma_netlink.h>
 
 /**
  * enum rdma_restrack_type - HW objects to track
@@ -183,4 +184,14 @@ static inline void rdma_restrack_set_task(struct rdma_restrack_entry *res,
        res->task = task;
 }
 
+/*
+ * Helper functions for rdma drivers when filling out
+ * nldev driver attributes.
+ */
+int rdma_nl_put_driver_u32(struct sk_buff *msg, const char *name, u32 value);
+int rdma_nl_put_driver_u32_hex(struct sk_buff *msg, const char *name,
+                              u32 value);
+int rdma_nl_put_driver_u64(struct sk_buff *msg, const char *name, u64 value);
+int rdma_nl_put_driver_u64_hex(struct sk_buff *msg, const char *name,
+                              u64 value);
 #endif /* _RDMA_RESTRACK_H_ */