@@ -74,7 +74,11 @@ static inline void unlock_dca_page_to_active(struct hns_dca_page_state *state,
((HNS_DCA_OWN_MASK & (id)) == (HNS_DCA_OWN_MASK & (s)->buf_id))
#define dca_page_is_allocated(s, id) \
- (dca_page_is_attached(s, id) && (s)->lock)
+ (dca_page_is_attached(s, id) && (s)->lock)
+
+/* all buf id bits must be matched */
+#define dca_page_is_active(s, id) ((HNS_DCA_ID_MASK & (id)) == \
+ (s)->buf_id && !(s)->lock && (s)->active)
#define dca_page_is_inactive(s) (!(s)->lock && !(s)->active)
@@ -870,6 +874,64 @@ static int attach_dca_mem(struct hns_roce_dev *hr_dev,
return 0;
}
+struct dca_page_query_active_attr {
+ u32 buf_id;
+ u32 curr_index;
+ u32 start_index;
+ u32 page_index;
+ u32 page_count;
+ u64 mem_key;
+};
+
+static int query_dca_active_pages_proc(struct dca_mem *mem, int index,
+ void *param)
+{
+ struct hns_dca_page_state *state = &mem->states[index];
+ struct dca_page_query_active_attr *attr = param;
+
+ if (!dca_page_is_active(state, attr->buf_id))
+ return 0;
+
+ if (attr->curr_index < attr->start_index) {
+ attr->curr_index++;
+ return 0;
+ } else if (attr->curr_index > attr->start_index) {
+ return DCA_MEM_STOP_ITERATE;
+ }
+
+ /* Search first page in DCA mem */
+ attr->page_index = index;
+ attr->mem_key = mem->key;
+ /* Search active pages in continuous addresses */
+ while (index < mem->page_count) {
+ state = &mem->states[index];
+ if (!dca_page_is_active(state, attr->buf_id))
+ break;
+
+ index++;
+ attr->page_count++;
+ }
+
+ return DCA_MEM_STOP_ITERATE;
+}
+
+static int query_dca_mem(struct hns_roce_qp *hr_qp, u32 page_index,
+ struct hns_dca_query_resp *resp)
+{
+ struct hns_roce_dca_ctx *ctx = hr_qp_to_dca_ctx(hr_qp);
+ struct dca_page_query_active_attr attr = {};
+
+ attr.buf_id = hr_qp->dca_cfg.buf_id;
+ attr.start_index = page_index;
+ travel_dca_pages(ctx, &attr, query_dca_active_pages_proc);
+
+ resp->mem_key = attr.mem_key;
+ resp->mem_ofs = attr.page_index << HNS_HW_PAGE_SHIFT;
+ resp->page_count = attr.page_count;
+
+ return attr.page_count ? 0 : -ENOMEM;
+}
+
struct dca_page_free_buf_attr {
u32 buf_id;
u32 max_pages;
@@ -1202,13 +1264,57 @@ DECLARE_UVERBS_NAMED_METHOD(
UVERBS_ATTR_PTR_IN(HNS_IB_ATTR_DCA_MEM_DETACH_SQ_INDEX,
UVERBS_ATTR_TYPE(u32), UA_MANDATORY));
+static int UVERBS_HANDLER(HNS_IB_METHOD_DCA_MEM_QUERY)(
+ struct uverbs_attr_bundle *attrs)
+{
+ struct hns_roce_qp *hr_qp = uverbs_attr_to_hr_qp(attrs);
+ struct hns_dca_query_resp resp = {};
+ u32 page_idx;
+ int ret;
+
+ if (!hr_qp)
+ return -EINVAL;
+
+ if (uverbs_copy_from(&page_idx, attrs,
+ HNS_IB_ATTR_DCA_MEM_QUERY_PAGE_INDEX))
+ return -EFAULT;
+
+ ret = query_dca_mem(hr_qp, page_idx, &resp);
+ if (ret)
+ return ret;
+
+ if (uverbs_copy_to(attrs, HNS_IB_ATTR_DCA_MEM_QUERY_OUT_KEY,
+ &resp.mem_key, sizeof(resp.mem_key)) ||
+ uverbs_copy_to(attrs, HNS_IB_ATTR_DCA_MEM_QUERY_OUT_OFFSET,
+ &resp.mem_ofs, sizeof(resp.mem_ofs)) ||
+ uverbs_copy_to(attrs, HNS_IB_ATTR_DCA_MEM_QUERY_OUT_PAGE_COUNT,
+ &resp.page_count, sizeof(resp.page_count)))
+ return -EFAULT;
+
+ return 0;
+}
+
+DECLARE_UVERBS_NAMED_METHOD(
+ HNS_IB_METHOD_DCA_MEM_QUERY,
+ UVERBS_ATTR_IDR(HNS_IB_ATTR_DCA_MEM_QUERY_HANDLE, UVERBS_OBJECT_QP,
+ UVERBS_ACCESS_READ, UA_MANDATORY),
+ UVERBS_ATTR_PTR_IN(HNS_IB_ATTR_DCA_MEM_QUERY_PAGE_INDEX,
+ UVERBS_ATTR_TYPE(u32), UA_MANDATORY),
+ UVERBS_ATTR_PTR_OUT(HNS_IB_ATTR_DCA_MEM_QUERY_OUT_KEY,
+ UVERBS_ATTR_TYPE(u64), UA_MANDATORY),
+ UVERBS_ATTR_PTR_OUT(HNS_IB_ATTR_DCA_MEM_QUERY_OUT_OFFSET,
+ UVERBS_ATTR_TYPE(u32), UA_MANDATORY),
+ UVERBS_ATTR_PTR_OUT(HNS_IB_ATTR_DCA_MEM_QUERY_OUT_PAGE_COUNT,
+ UVERBS_ATTR_TYPE(u32), UA_MANDATORY));
+
DECLARE_UVERBS_NAMED_OBJECT(HNS_IB_OBJECT_DCA_MEM,
UVERBS_TYPE_ALLOC_IDR(dca_cleanup),
&UVERBS_METHOD(HNS_IB_METHOD_DCA_MEM_REG),
&UVERBS_METHOD(HNS_IB_METHOD_DCA_MEM_DEREG),
&UVERBS_METHOD(HNS_IB_METHOD_DCA_MEM_SHRINK),
&UVERBS_METHOD(HNS_IB_METHOD_DCA_MEM_ATTACH),
- &UVERBS_METHOD(HNS_IB_METHOD_DCA_MEM_DETACH));
+ &UVERBS_METHOD(HNS_IB_METHOD_DCA_MEM_DETACH),
+ &UVERBS_METHOD(HNS_IB_METHOD_DCA_MEM_QUERY));
static bool dca_is_supported(struct ib_device *device)
{
@@ -50,6 +50,12 @@ struct hns_dca_detach_attr {
u32 sq_idx;
};
+struct hns_dca_query_resp {
+ u64 mem_key;
+ u32 mem_ofs;
+ u32 page_count;
+};
+
void hns_roce_register_udca(struct hns_roce_dev *hr_dev,
struct hns_roce_ucontext *uctx);
void hns_roce_unregister_udca(struct hns_roce_dev *hr_dev,
@@ -114,6 +114,7 @@ enum hns_ib_dca_mem_methods {
HNS_IB_METHOD_DCA_MEM_SHRINK,
HNS_IB_METHOD_DCA_MEM_ATTACH,
HNS_IB_METHOD_DCA_MEM_DETACH,
+ HNS_IB_METHOD_DCA_MEM_QUERY,
};
enum hns_ib_dca_mem_reg_attrs {
@@ -149,4 +150,13 @@ enum hns_ib_dca_mem_detach_attrs {
HNS_IB_ATTR_DCA_MEM_DETACH_HANDLE = (1U << UVERBS_ID_NS_SHIFT),
HNS_IB_ATTR_DCA_MEM_DETACH_SQ_INDEX,
};
+
+enum hns_ib_dca_mem_query_attrs {
+ HNS_IB_ATTR_DCA_MEM_QUERY_HANDLE = (1U << UVERBS_ID_NS_SHIFT),
+ HNS_IB_ATTR_DCA_MEM_QUERY_PAGE_INDEX,
+ HNS_IB_ATTR_DCA_MEM_QUERY_OUT_KEY,
+ HNS_IB_ATTR_DCA_MEM_QUERY_OUT_OFFSET,
+ HNS_IB_ATTR_DCA_MEM_QUERY_OUT_PAGE_COUNT,
+};
+
#endif /* HNS_ABI_USER_H */