[PATCH rdma-next v2 14/17] RDMA/restrack: Introduce range support for IDs

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Leon Romanovsky <leonro@xxxxxxxxxxxx>

The IDs are supposed to be generated in ranges with reserved slots for
HW management, (e.g. reserved_pd in mlx4 and hns), so provide extra
function to set supported range.

This function was names rdma_rt_* and not rdma_restrack_* to simplify
the usage and spread across drivers.

Signed-off-by: Leon Romanovsky <leonro@xxxxxxxxxxxx>
---
 drivers/infiniband/core/restrack.c | 35 +++++++++++++++++++++++++++++-
 include/rdma/restrack.h            |  2 ++
 2 files changed, 36 insertions(+), 1 deletion(-)

diff --git a/drivers/infiniband/core/restrack.c b/drivers/infiniband/core/restrack.c
index c9a0daf46499..5a8857cab822 100644
--- a/drivers/infiniband/core/restrack.c
+++ b/drivers/infiniband/core/restrack.c
@@ -13,6 +13,15 @@
 
 #include "cma_priv.h"
 
+/**
+ * FIXME: Replace with official xa_array_cyclic(), once it is merged
+ * http://git.infradead.org/users/willy/linux-dax.git/commit/8bcca93a53949d20877e82c2aaae0fd7c385b90d
+ */
+struct rt_xa_limit {
+	u32 min;
+	u32 max;
+};
+
 /**
  * struct rdma_restrack_root - main resource tracking management
  * entity, per-device
@@ -27,6 +36,10 @@ struct rdma_restrack_root {
 	 * @xa: Array of XArray structure to hold restrack entries.
 	 */
 	struct xarray xa;
+	/**
+	 * @range: Allocation ID range between min and max
+	 */
+	struct rt_xa_limit range;
 };
 
 /**
@@ -49,6 +62,7 @@ int rdma_restrack_init(struct ib_device *dev)
 	for (i = 0 ; i < RDMA_RESTRACK_MAX; i++) {
 		init_rwsem(&rt[i].rwsem);
 		xa_init_flags(&rt[i].xa, XA_FLAGS_ALLOC);
+		rt[i].range.max = U32_MAX;
 	}
 
 	return 0;
@@ -371,7 +385,7 @@ void rdma_restrack_del(struct rdma_restrack_entry *res)
 	 * this field set to NULL and it is set in _cma_attach_to_dev()
 	 * only.
 	 *
-	 * Becasue we don't want to add any conditions on call
+	 * Because we don't want to add any conditions on call
 	 * to rdma_restrack_del(), the check below protects from
 	 * NULL-dereference.
 	 */
@@ -399,3 +413,22 @@ void rdma_restrack_del(struct rdma_restrack_entry *res)
 	}
 }
 EXPORT_SYMBOL(rdma_restrack_del);
+
+/**
+ * rdma_rt_set_id_range() - initialize IDs range. Devices which are able
+ *                          to manage thos IDs in HW will leave max and reserved
+ *                          as zero.
+ * @dev: IB device to work
+ * @type: resource track type
+ * @reserved: number of entries to keep aside
+ * @max: maximal possible value
+ */
+void rdma_rt_set_id_range(struct ib_device *dev, enum rdma_restrack_type type,
+			  u32 reserved, u32 max)
+{
+	struct rdma_restrack_root *rt = dev->res;
+
+	rt[type].range.max = max;
+	rt[type].range.min = reserved;
+}
+EXPORT_SYMBOL(rdma_rt_set_id_range);
diff --git a/include/rdma/restrack.h b/include/rdma/restrack.h
index d66b0b052354..0706f51bb1f8 100644
--- a/include/rdma/restrack.h
+++ b/include/rdma/restrack.h
@@ -157,4 +157,6 @@ struct xarray *rdma_dev_to_xa(struct ib_device *dev,
 			      enum rdma_restrack_type type);
 void rdma_rt_read_lock(struct ib_device *dev, enum rdma_restrack_type type);
 void rdma_rt_read_unlock(struct ib_device *dev, enum rdma_restrack_type type);
+void rdma_rt_set_id_range(struct ib_device *dev, enum rdma_restrack_type type,
+			  u32 reserved, u32 max);
 #endif /* _RDMA_RESTRACK_H_ */
-- 
2.19.1




[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Photo]     [Yosemite News]     [Yosemite Photos]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux