diff mbox

[v3,rdma-next,4/5] RDMA/NLDEV: helper functions to add provider attributes

Message ID 357679afe9921eb7e0ba3fe879e7558d11080a0e.1522433107.git.swise@opengridcomputing.com (mailing list archive)
State Changes Requested
Delegated to: Jason Gunthorpe
Headers show

Commit Message

Steve Wise March 30, 2018, 6:03 p.m. UTC
These help rdma providers to fill out the provider entries.

Signed-off-by: Steve Wise <swise@opengridcomputing.com>
---
 drivers/infiniband/core/nldev.c | 67 +++++++++++++++++++++++++++++++++++++++++
 include/rdma/restrack.h         | 13 ++++++++
 2 files changed, 80 insertions(+)

Comments

Jason Gunthorpe April 20, 2018, 6:15 p.m. UTC | #1
On Fri, Mar 30, 2018 at 11:03:42AM -0700, Steve Wise wrote:
> These help rdma providers to fill out the provider entries.
> 
> Signed-off-by: Steve Wise <swise@opengridcomputing.com>
>  drivers/infiniband/core/nldev.c | 67 +++++++++++++++++++++++++++++++++++++++++
>  include/rdma/restrack.h         | 13 ++++++++
>  2 files changed, 80 insertions(+)
> 
> diff --git a/drivers/infiniband/core/nldev.c b/drivers/infiniband/core/nldev.c
> index 0610313..a11fd16 100644
> +++ b/drivers/infiniband/core/nldev.c
> @@ -128,6 +128,73 @@ static int provider_fill_port_info(struct sk_buff *msg,
>  		device->res.fill_port_info(msg, device, port) : 0;
>  }
>  
> +static int put_provider_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_PROVIDER_STRING, name))
> +		return -EMSGSIZE;
> +	if (print_type != RDMA_NLDEV_PRINT_TYPE_UNSPEC &&
> +	    nla_put_u8(msg, RDMA_NLDEV_ATTR_PROVIDER_PRINT_TYPE, print_type))
> +		return -EMSGSIZE;
> +
> +	return 0;
> +}
> +
> +static int _rdma_nl_put_provider_u32(struct sk_buff *msg, const char *name,
> +				     enum rdma_nldev_print_type print_type,
> +				     u32 value)
> +{
> +	if (put_provider_name_print_type(msg, name, print_type))
> +		return -EMSGSIZE;
> +	if (nla_put_u32(msg, RDMA_NLDEV_ATTR_PROVIDER_U32, value))
> +		return -EMSGSIZE;
> +
> +	return 0;
> +}
> +
> +static int _rdma_nl_put_provider_u64(struct sk_buff *msg, const char *name,
> +				     enum rdma_nldev_print_type print_type,
> +				     u64 value)
> +{
> +	if (put_provider_name_print_type(msg, name, print_type))
> +		return -EMSGSIZE;
> +	if (nla_put_u64_64bit(msg, RDMA_NLDEV_ATTR_PROVIDER_U64, value,
> +			      RDMA_NLDEV_ATTR_PAD))
> +		return -EMSGSIZE;
> +
> +	return 0;
> +}
> +
> +int rdma_nl_put_provider_u32(struct sk_buff *msg, const char *name, u32 value)
> +{
> +	return _rdma_nl_put_provider_u32(msg, name,
> +					 RDMA_NLDEV_PRINT_TYPE_UNSPEC, value);
> +}
> +EXPORT_SYMBOL(rdma_nl_put_provider_u32);

I wonder if this should be EXPORT_SYMBOL_GPL ?

Jason
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Steve Wise April 20, 2018, 6:24 p.m. UTC | #2
> 
> On Fri, Mar 30, 2018 at 11:03:42AM -0700, Steve Wise wrote:
> > These help rdma providers to fill out the provider entries.
> >
> > Signed-off-by: Steve Wise <swise@opengridcomputing.com>
> >  drivers/infiniband/core/nldev.c | 67
> +++++++++++++++++++++++++++++++++++++++++
> >  include/rdma/restrack.h         | 13 ++++++++
> >  2 files changed, 80 insertions(+)
> >
> > diff --git a/drivers/infiniband/core/nldev.c
> b/drivers/infiniband/core/nldev.c
> > index 0610313..a11fd16 100644
> > +++ b/drivers/infiniband/core/nldev.c
> > @@ -128,6 +128,73 @@ static int provider_fill_port_info(struct sk_buff
> *msg,
> >  		device->res.fill_port_info(msg, device, port) : 0;
> >  }
> >
> > +static int put_provider_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_PROVIDER_STRING,
> name))
> > +		return -EMSGSIZE;
> > +	if (print_type != RDMA_NLDEV_PRINT_TYPE_UNSPEC &&
> > +	    nla_put_u8(msg, RDMA_NLDEV_ATTR_PROVIDER_PRINT_TYPE,
> print_type))
> > +		return -EMSGSIZE;
> > +
> > +	return 0;
> > +}
> > +
> > +static int _rdma_nl_put_provider_u32(struct sk_buff *msg, const char
> *name,
> > +				     enum rdma_nldev_print_type print_type,
> > +				     u32 value)
> > +{
> > +	if (put_provider_name_print_type(msg, name, print_type))
> > +		return -EMSGSIZE;
> > +	if (nla_put_u32(msg, RDMA_NLDEV_ATTR_PROVIDER_U32, value))
> > +		return -EMSGSIZE;
> > +
> > +	return 0;
> > +}
> > +
> > +static int _rdma_nl_put_provider_u64(struct sk_buff *msg, const char
> *name,
> > +				     enum rdma_nldev_print_type print_type,
> > +				     u64 value)
> > +{
> > +	if (put_provider_name_print_type(msg, name, print_type))
> > +		return -EMSGSIZE;
> > +	if (nla_put_u64_64bit(msg, RDMA_NLDEV_ATTR_PROVIDER_U64,
> value,
> > +			      RDMA_NLDEV_ATTR_PAD))
> > +		return -EMSGSIZE;
> > +
> > +	return 0;
> > +}
> > +
> > +int rdma_nl_put_provider_u32(struct sk_buff *msg, const char *name,
> u32 value)
> > +{
> > +	return _rdma_nl_put_provider_u32(msg, name,
> > +					 RDMA_NLDEV_PRINT_TYPE_UNSPEC,
> value);
> > +}
> > +EXPORT_SYMBOL(rdma_nl_put_provider_u32);
> 
> I wonder if this should be EXPORT_SYMBOL_GPL ?
> 
> Jason

I have no clue.  The ib_core module is dual bsd/gpl.   Whatever you think...



--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Leon Romanovsky April 22, 2018, 11:51 a.m. UTC | #3
On Fri, Apr 20, 2018 at 01:24:59PM -0500, Steve Wise wrote:
> >
> > On Fri, Mar 30, 2018 at 11:03:42AM -0700, Steve Wise wrote:
> > > These help rdma providers to fill out the provider entries.
> > >
> > > Signed-off-by: Steve Wise <swise@opengridcomputing.com>
> > >  drivers/infiniband/core/nldev.c | 67
> > +++++++++++++++++++++++++++++++++++++++++
> > >  include/rdma/restrack.h         | 13 ++++++++
> > >  2 files changed, 80 insertions(+)
> > >
> > > diff --git a/drivers/infiniband/core/nldev.c
> > b/drivers/infiniband/core/nldev.c
> > > index 0610313..a11fd16 100644
> > > +++ b/drivers/infiniband/core/nldev.c
> > > @@ -128,6 +128,73 @@ static int provider_fill_port_info(struct sk_buff
> > *msg,
> > >  		device->res.fill_port_info(msg, device, port) : 0;
> > >  }
> > >
> > > +static int put_provider_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_PROVIDER_STRING,
> > name))
> > > +		return -EMSGSIZE;
> > > +	if (print_type != RDMA_NLDEV_PRINT_TYPE_UNSPEC &&
> > > +	    nla_put_u8(msg, RDMA_NLDEV_ATTR_PROVIDER_PRINT_TYPE,
> > print_type))
> > > +		return -EMSGSIZE;
> > > +
> > > +	return 0;
> > > +}
> > > +
> > > +static int _rdma_nl_put_provider_u32(struct sk_buff *msg, const char
> > *name,
> > > +				     enum rdma_nldev_print_type print_type,
> > > +				     u32 value)
> > > +{
> > > +	if (put_provider_name_print_type(msg, name, print_type))
> > > +		return -EMSGSIZE;
> > > +	if (nla_put_u32(msg, RDMA_NLDEV_ATTR_PROVIDER_U32, value))
> > > +		return -EMSGSIZE;
> > > +
> > > +	return 0;
> > > +}
> > > +
> > > +static int _rdma_nl_put_provider_u64(struct sk_buff *msg, const char
> > *name,
> > > +				     enum rdma_nldev_print_type print_type,
> > > +				     u64 value)
> > > +{
> > > +	if (put_provider_name_print_type(msg, name, print_type))
> > > +		return -EMSGSIZE;
> > > +	if (nla_put_u64_64bit(msg, RDMA_NLDEV_ATTR_PROVIDER_U64,
> > value,
> > > +			      RDMA_NLDEV_ATTR_PAD))
> > > +		return -EMSGSIZE;
> > > +
> > > +	return 0;
> > > +}
> > > +
> > > +int rdma_nl_put_provider_u32(struct sk_buff *msg, const char *name,
> > u32 value)
> > > +{
> > > +	return _rdma_nl_put_provider_u32(msg, name,
> > > +					 RDMA_NLDEV_PRINT_TYPE_UNSPEC,
> > value);
> > > +}
> > > +EXPORT_SYMBOL(rdma_nl_put_provider_u32);
> >
> > I wonder if this should be EXPORT_SYMBOL_GPL ?
> >
> > Jason
>
> I have no clue.  The ib_core module is dual bsd/gpl.   Whatever you think...

I would like to see it EXPORT_SYMBOL() and not EXPORT_SYMBOL_GPL().

Thanks

>
>
>
diff mbox

Patch

diff --git a/drivers/infiniband/core/nldev.c b/drivers/infiniband/core/nldev.c
index 0610313..a11fd16 100644
--- a/drivers/infiniband/core/nldev.c
+++ b/drivers/infiniband/core/nldev.c
@@ -128,6 +128,73 @@  static int provider_fill_port_info(struct sk_buff *msg,
 		device->res.fill_port_info(msg, device, port) : 0;
 }
 
+static int put_provider_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_PROVIDER_STRING, name))
+		return -EMSGSIZE;
+	if (print_type != RDMA_NLDEV_PRINT_TYPE_UNSPEC &&
+	    nla_put_u8(msg, RDMA_NLDEV_ATTR_PROVIDER_PRINT_TYPE, print_type))
+		return -EMSGSIZE;
+
+	return 0;
+}
+
+static int _rdma_nl_put_provider_u32(struct sk_buff *msg, const char *name,
+				     enum rdma_nldev_print_type print_type,
+				     u32 value)
+{
+	if (put_provider_name_print_type(msg, name, print_type))
+		return -EMSGSIZE;
+	if (nla_put_u32(msg, RDMA_NLDEV_ATTR_PROVIDER_U32, value))
+		return -EMSGSIZE;
+
+	return 0;
+}
+
+static int _rdma_nl_put_provider_u64(struct sk_buff *msg, const char *name,
+				     enum rdma_nldev_print_type print_type,
+				     u64 value)
+{
+	if (put_provider_name_print_type(msg, name, print_type))
+		return -EMSGSIZE;
+	if (nla_put_u64_64bit(msg, RDMA_NLDEV_ATTR_PROVIDER_U64, value,
+			      RDMA_NLDEV_ATTR_PAD))
+		return -EMSGSIZE;
+
+	return 0;
+}
+
+int rdma_nl_put_provider_u32(struct sk_buff *msg, const char *name, u32 value)
+{
+	return _rdma_nl_put_provider_u32(msg, name,
+					 RDMA_NLDEV_PRINT_TYPE_UNSPEC, value);
+}
+EXPORT_SYMBOL(rdma_nl_put_provider_u32);
+
+int rdma_nl_put_provider_u32_hex(struct sk_buff *msg, const char *name,
+				 u32 value)
+{
+	return _rdma_nl_put_provider_u32(msg, name, RDMA_NLDEV_PRINT_TYPE_HEX,
+					 value);
+}
+EXPORT_SYMBOL(rdma_nl_put_provider_u32_hex);
+
+int rdma_nl_put_provider_u64(struct sk_buff *msg, const char *name, u64 value)
+{
+	return _rdma_nl_put_provider_u64(msg, name,
+					 RDMA_NLDEV_PRINT_TYPE_UNSPEC, value);
+}
+EXPORT_SYMBOL(rdma_nl_put_provider_u64);
+
+int rdma_nl_put_provider_u64_hex(struct sk_buff *msg, const char *name,
+				 u64 value)
+{
+	return _rdma_nl_put_provider_u64(msg, name, RDMA_NLDEV_PRINT_TYPE_HEX,
+					 value);
+}
+EXPORT_SYMBOL(rdma_nl_put_provider_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))
diff --git a/include/rdma/restrack.h b/include/rdma/restrack.h
index 525f885..10cca0e 100644
--- a/include/rdma/restrack.h
+++ b/include/rdma/restrack.h
@@ -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
@@ -197,4 +198,16 @@  static inline void rdma_restrack_set_task(struct rdma_restrack_entry *res,
 	res->task = task;
 }
 
+/*
+ * Helper functions for rdma providers when filling out
+ * nldev provider attributes.
+ */
+int rdma_nl_put_provider_u32(struct sk_buff *msg, const char *name,
+			     u32 value);
+int rdma_nl_put_provider_u32_hex(struct sk_buff *msg, const char *name,
+				 u32 value);
+int rdma_nl_put_provider_u64(struct sk_buff *msg, const char *name,
+			     u64 value);
+int rdma_nl_put_provider_u64_hex(struct sk_buff *msg, const char *name,
+				 u64 value);
 #endif /* _RDMA_RESTRACK_H_ */