@@ -175,6 +175,9 @@ int efadv_query_device(struct ibv_context *ibvctx,
175175
176176 if (EFA_DEV_CAP (ctx , UNSOLICITED_WRITE_RECV ))
177177 attr -> device_caps |= EFADV_DEVICE_ATTR_CAPS_UNSOLICITED_WRITE_RECV ;
178+
179+ if (EFA_DEV_CAP (ctx , CQ_WITH_EXT_MEM ))
180+ attr -> device_caps |= EFADV_DEVICE_ATTR_CAPS_CQ_WITH_EXT_MEM_DMABUF ;
178181 }
179182
180183 if (vext_field_avail (typeof (* attr ), max_rdma_size , inlen )) {
@@ -879,9 +882,9 @@ static void efa_cq_fill_pfns(struct efa_cq *cq,
879882 if (attr -> wc_flags & IBV_WC_EX_WITH_DLID_PATH_BITS )
880883 ibvcqx -> read_dlid_path_bits = efa_wc_read_dlid_path_bits ;
881884
882- if (efa_attr && ( efa_attr -> wc_flags & EFADV_WC_EX_WITH_SGID ) )
885+ if (efa_attr -> wc_flags & EFADV_WC_EX_WITH_SGID )
883886 cq -> dv_cq .wc_read_sgid = efa_wc_read_sgid ;
884- if (efa_attr && ( efa_attr -> wc_flags & EFADV_WC_EX_WITH_IS_UNSOLICITED ) )
887+ if (efa_attr -> wc_flags & EFADV_WC_EX_WITH_IS_UNSOLICITED )
885888 cq -> dv_cq .wc_is_unsolicited = efa_wc_is_unsolicited ;
886889}
887890
@@ -900,9 +903,11 @@ static struct ibv_cq_ex *create_cq(struct ibv_context *ibvctx,
900903 struct efadv_cq_init_attr * efa_attr )
901904{
902905 struct efa_context * ctx = to_efa_context (ibvctx );
906+ struct verbs_create_cq_prov_attr prov_attr = {};
903907 uint16_t cqe_size = ctx -> ex_cqe_size ;
904908 struct efa_create_cq_resp resp = {};
905909 struct efa_create_cq cmd = {};
910+ uint32_t cmd_flags = 0 ;
906911 uint16_t num_sub_cqs ;
907912 struct efa_cq * cq ;
908913 int sub_buf_size ;
@@ -930,42 +935,58 @@ static struct ibv_cq_ex *create_cq(struct ibv_context *ibvctx,
930935 if (!cq )
931936 return NULL ;
932937
933- if (efa_attr && ( efa_attr -> wc_flags & EFADV_WC_EX_WITH_SGID ) )
938+ if (efa_attr -> wc_flags & EFADV_WC_EX_WITH_SGID )
934939 cmd .flags |= EFA_CREATE_CQ_WITH_SGID ;
935940
936941 num_sub_cqs = ctx -> sub_cqs_per_cq ;
937942 cmd .num_sub_cqs = num_sub_cqs ;
938943 cmd .cq_entry_size = cqe_size ;
944+
945+ if (efa_attr -> flags & EFADV_CQ_INIT_FLAGS_EXT_MEM_DMABUF ) {
946+ prov_attr .buffer .length = efa_attr -> ext_mem_dmabuf .length ;
947+ prov_attr .buffer .dmabuf .offset = efa_attr -> ext_mem_dmabuf .offset ;
948+ prov_attr .buffer .dmabuf .fd = efa_attr -> ext_mem_dmabuf .fd ;
949+ cmd_flags = CREATE_CQ_CMD_FLAGS_WITH_MEM_DMABUF ;
950+ }
951+
939952 if (attr -> channel )
940953 cmd .flags |= EFA_CREATE_CQ_WITH_COMPLETION_CHANNEL ;
941954
942955 attr -> cqe = roundup_pow_of_two (attr -> cqe );
943- err = ibv_cmd_create_cq_ex (ibvctx , attr , NULL , & cq -> verbs_cq ,
956+ err = ibv_cmd_create_cq_ex (ibvctx , attr , & prov_attr , & cq -> verbs_cq ,
944957 & cmd .ibv_cmd , sizeof (cmd ),
945- & resp .ibv_resp , sizeof (resp ), 0 );
958+ & resp .ibv_resp , sizeof (resp ), cmd_flags );
946959 if (err ) {
947960 errno = err ;
948961 goto err_free_cq ;
949962 }
950963
951964 sub_cq_size = cq -> verbs_cq .cq .cqe ;
952965 cq -> cqn = resp .cq_idx ;
953- cq -> buf_size = resp .q_mmap_size ;
954966 cq -> num_sub_cqs = num_sub_cqs ;
955967 cq -> cqe_size = cqe_size ;
956968 cq -> dev = ibvctx -> device ;
957969
958- cq -> buf = mmap (NULL , cq -> buf_size , PROT_READ , MAP_SHARED ,
959- ibvctx -> cmd_fd , resp .q_mmap_key );
960- if (cq -> buf == MAP_FAILED )
961- goto err_destroy_cq ;
970+ if (efa_attr -> flags & EFADV_CQ_INIT_FLAGS_EXT_MEM_DMABUF ) {
971+ cq -> buf_size = efa_attr -> ext_mem_dmabuf .length ;
972+ cq -> buf = efa_attr -> ext_mem_dmabuf .buffer ;
973+ } else {
974+ cq -> buf_size = resp .q_mmap_size ;
975+ cq -> buf = mmap (NULL , cq -> buf_size , PROT_READ , MAP_SHARED , ibvctx -> cmd_fd ,
976+ resp .q_mmap_key );
977+ if (cq -> buf == MAP_FAILED )
978+ goto err_destroy_cq ;
979+
980+ cq -> buf_mmaped = true;
981+ }
962982
963- buf = cq -> buf ;
964- sub_buf_size = cq -> cqe_size * sub_cq_size ;
965- for (i = 0 ; i < num_sub_cqs ; i ++ ) {
966- efa_sub_cq_initialize (& cq -> sub_cq_arr [i ], buf , sub_cq_size ,
967- cq -> cqe_size );
968- buf += sub_buf_size ;
983+ if (cq -> buf ) {
984+ buf = cq -> buf ;
985+ sub_buf_size = cq -> cqe_size * sub_cq_size ;
986+ for (i = 0 ; i < num_sub_cqs ; i ++ ) {
987+ efa_sub_cq_initialize (& cq -> sub_cq_arr [i ], buf , sub_cq_size , cq -> cqe_size );
988+ buf += sub_buf_size ;
989+ }
969990 }
970991
971992 if (resp .comp_mask & EFA_CREATE_CQ_RESP_DB_OFF ) {
@@ -984,7 +1005,8 @@ static struct ibv_cq_ex *create_cq(struct ibv_context *ibvctx,
9841005 return & cq -> verbs_cq .cq_ex ;
9851006
9861007err_unmap_cq :
987- munmap (cq -> buf , cq -> buf_size );
1008+ if (cq -> buf_mmaped )
1009+ munmap (cq -> buf , cq -> buf_size );
9881010err_destroy_cq :
9891011 ibv_cmd_destroy_cq (& cq -> verbs_cq .cq );
9901012err_free_cq :
@@ -996,29 +1018,33 @@ static struct ibv_cq_ex *create_cq(struct ibv_context *ibvctx,
9961018struct ibv_cq * efa_create_cq (struct ibv_context * ibvctx , int ncqe ,
9971019 struct ibv_comp_channel * channel , int vec )
9981020{
1021+ struct efadv_cq_init_attr efa_attr = {};
9991022 struct ibv_cq_init_attr_ex attr_ex = {
10001023 .cqe = ncqe ,
10011024 .channel = channel ,
10021025 .comp_vector = vec
10031026 };
10041027 struct ibv_cq_ex * ibvcqx ;
10051028
1006- ibvcqx = create_cq (ibvctx , & attr_ex , NULL );
1029+ ibvcqx = create_cq (ibvctx , & attr_ex , & efa_attr );
10071030
10081031 return ibvcqx ? ibv_cq_ex_to_cq (ibvcqx ) : NULL ;
10091032}
10101033
10111034struct ibv_cq_ex * efa_create_cq_ex (struct ibv_context * ibvctx ,
10121035 struct ibv_cq_init_attr_ex * attr_ex )
10131036{
1014- return create_cq (ibvctx , attr_ex , NULL );
1037+ struct efadv_cq_init_attr efa_attr = {};
1038+
1039+ return create_cq (ibvctx , attr_ex , & efa_attr );
10151040}
10161041
10171042struct ibv_cq_ex * efadv_create_cq (struct ibv_context * ibvctx ,
10181043 struct ibv_cq_init_attr_ex * attr_ex ,
10191044 struct efadv_cq_init_attr * efa_attr ,
10201045 uint32_t inlen )
10211046{
1047+ struct efadv_cq_init_attr local_efa_attr = {};
10221048 uint64_t supp_wc_flags = 0 ;
10231049 struct efa_context * ctx ;
10241050
@@ -1048,7 +1074,8 @@ struct ibv_cq_ex *efadv_create_cq(struct ibv_context *ibvctx,
10481074 return NULL ;
10491075 }
10501076
1051- return create_cq (ibvctx , attr_ex , efa_attr );
1077+ memcpy (& local_efa_attr , efa_attr , min_t (uint32_t , inlen , sizeof (local_efa_attr )));
1078+ return create_cq (ibvctx , attr_ex , & local_efa_attr );
10521079}
10531080
10541081struct efadv_cq * efadv_cq_from_ibv_cq_ex (struct ibv_cq_ex * ibvcqx )
@@ -1071,7 +1098,8 @@ int efa_destroy_cq(struct ibv_cq *ibvcq)
10711098 }
10721099
10731100 munmap (cq -> db_mmap_addr , to_efa_dev (cq -> dev )-> pg_sz );
1074- munmap (cq -> buf , cq -> buf_size );
1101+ if (cq -> buf_mmaped )
1102+ munmap (cq -> buf , cq -> buf_size );
10751103
10761104 pthread_spin_destroy (& cq -> lock );
10771105
0 commit comments