@@ -1292,6 +1292,7 @@ void ib_set_device_ops(struct ib_device *dev, const struct ib_device_ops *ops)
SET_DEVICE_OP(dev_ops, get_vf_config);
SET_DEVICE_OP(dev_ops, get_vf_stats);
SET_DEVICE_OP(dev_ops, map_mr_sg);
+ SET_DEVICE_OP(dev_ops, map_mr_sg_pi);
SET_DEVICE_OP(dev_ops, map_phys_fmr);
SET_DEVICE_OP(dev_ops, mmap);
SET_DEVICE_OP(dev_ops, modify_ah);
@@ -2020,7 +2020,8 @@ struct ib_mr *ib_alloc_mr_integrity(struct ib_pd *pd,
{
struct ib_mr *mr;
- if (!pd->device->ops.alloc_mr_integrity)
+ if (!pd->device->ops.alloc_mr_integrity ||
+ !pd->device->ops.map_mr_sg_pi)
return ERR_PTR(-EOPNOTSUPP);
if (!max_num_meta_sg)
@@ -2402,6 +2403,35 @@ int ib_set_vf_guid(struct ib_device *device, int vf, u8 port, u64 guid,
}
EXPORT_SYMBOL(ib_set_vf_guid);
+/**
+ * ib_map_mr_sg_pi() - Map the dma mapped SG lists for PI (protection
+ * information) and set an appropriate memory region for registration.
+ * @mr: memory region
+ * @data_ib_sg: dma mapped scatterlist for data
+ * @meta_ib_sg: dma mapped scatterlist for metadata
+ * @page_size: page vector desired page size
+ *
+ * Constraints:
+ * - The MR must be allocated with type IB_MR_TYPE_INTEGRITY.
+ *
+ * Returns the number of sg elements that were mapped to the memory region.
+ *
+ * After this completes successfully, the memory region
+ * is ready for registration.
+ */
+int ib_map_mr_sg_pi(struct ib_mr *mr, struct ib_scatterlist *data_ib_sg,
+ struct ib_scatterlist *meta_ib_sg, unsigned int page_size)
+{
+ if (unlikely(!mr->device->ops.map_mr_sg_pi ||
+ WARN_ON_ONCE(mr->type != IB_MR_TYPE_INTEGRITY)))
+ return -EOPNOTSUPP;
+
+ mr->page_size = page_size;
+
+ return mr->device->ops.map_mr_sg_pi(mr, data_ib_sg, meta_ib_sg);
+}
+EXPORT_SYMBOL(ib_map_mr_sg_pi);
+
/**
* ib_map_mr_sg() - Map the largest prefix of a dma mapped SG list
* and set it the memory region.
@@ -2393,6 +2393,10 @@ struct ib_device_ops {
int (*read_counters)(struct ib_counters *counters,
struct ib_counters_read_attr *counters_read_attr,
struct uverbs_attr_bundle *attrs);
+ int (*map_mr_sg_pi)(struct ib_mr *mr,
+ struct ib_scatterlist *data_ib_sg,
+ struct ib_scatterlist *meta_ib_sg);
+
/**
* alloc_hw_stats - Allocate a struct rdma_hw_stats and fill in the
* driver initialized data. The struct is kfree()'ed by the sysfs
@@ -3874,6 +3878,8 @@ int ib_destroy_rwq_ind_table(struct ib_rwq_ind_table *wq_ind_table);
int ib_map_mr_sg(struct ib_mr *mr, struct ib_scatterlist *ib_sg,
unsigned int page_size);
+int ib_map_mr_sg_pi(struct ib_mr *mr, struct ib_scatterlist *data_ib_sg,
+ struct ib_scatterlist *meta_ib_sg, unsigned int page_size);
static inline int
ib_map_mr_sg_zbva(struct ib_mr *mr, struct ib_scatterlist *ib_sg,