diff mbox

[rdma-next,v4,5/8] IB/core: Add functions to convert 32 bit lids to 16 bits

Message ID 1502388268-20687-6-git-send-email-don.hiatt@intel.com (mailing list archive)
State Changes Requested
Headers show

Commit Message

Hiatt, Don Aug. 10, 2017, 6:04 p.m. UTC
Add two helper functions (ib_lid_cpu16(), ib_lid_be16()) to
convert 32 bit lids to 16 bits.

Signed-off-by: Don Hiatt <don.hiatt@intel.com>
Reviewed-by: Dennis Dalessandro <dennis.dalessandro@intel.com>
---
 include/rdma/ib_verbs.h | 12 ++++++++++++
 1 file changed, 12 insertions(+)

Comments

Leon Romanovsky Aug. 11, 2017, 11:03 a.m. UTC | #1
On Thu, Aug 10, 2017 at 02:04:25PM -0400, Don Hiatt wrote:
> Add two helper functions (ib_lid_cpu16(), ib_lid_be16()) to
> convert 32 bit lids to 16 bits.
>
> Signed-off-by: Don Hiatt <don.hiatt@intel.com>
> Reviewed-by: Dennis Dalessandro <dennis.dalessandro@intel.com>
> ---
>  include/rdma/ib_verbs.h | 12 ++++++++++++
>  1 file changed, 12 insertions(+)
>
> diff --git a/include/rdma/ib_verbs.h b/include/rdma/ib_verbs.h
> index a7d6990..3875ea5d 100644
> --- a/include/rdma/ib_verbs.h
> +++ b/include/rdma/ib_verbs.h
> @@ -3710,4 +3710,16 @@ static inline enum rdma_ah_attr_type rdma_ah_find_type(struct ib_device *dev,
>  	else
>  		return RDMA_AH_ATTR_TYPE_IB;
>  }
> +
> +/* Return lid in 16bit CPU encoding */
> +static inline u16 ib_lid_cpu16(u32 lid)
> +{
> +	return (u16)lid;
> +}
> +
> +/* Return lid in 16bit BE encoding */
> +static inline u16 ib_lid_be16(u32 lid)
> +{
> +	return cpu_to_be16((u16)lid);
> +}

Please add comments to these functions, with the description when and
why we are doing this conversion, and I think that it is worth to add
here WARN_ON_ONCE(lid && 0xFFFF0000) to catch possible bad flows.

>  #endif /* IB_VERBS_H */
> --
> 1.8.3.1
>
> --
> 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
diff mbox

Patch

diff --git a/include/rdma/ib_verbs.h b/include/rdma/ib_verbs.h
index a7d6990..3875ea5d 100644
--- a/include/rdma/ib_verbs.h
+++ b/include/rdma/ib_verbs.h
@@ -3710,4 +3710,16 @@  static inline enum rdma_ah_attr_type rdma_ah_find_type(struct ib_device *dev,
 	else
 		return RDMA_AH_ATTR_TYPE_IB;
 }
+
+/* Return lid in 16bit CPU encoding */
+static inline u16 ib_lid_cpu16(u32 lid)
+{
+	return (u16)lid;
+}
+
+/* Return lid in 16bit BE encoding */
+static inline u16 ib_lid_be16(u32 lid)
+{
+	return cpu_to_be16((u16)lid);
+}
 #endif /* IB_VERBS_H */