Lines Matching refs:ctx

81 static struct ibv_cq *pp_cq(struct pingpong_context *ctx)
83 return use_ts ? ibv_cq_ex_to_cq(ctx->cq_s.cq_ex) :
84 ctx->cq_s.cq;
94 static int pp_connect_ctx(struct pingpong_context *ctx, int port, int my_psn,
120 if (ibv_modify_qp(ctx->qp, &attr,
138 if (ibv_modify_qp(ctx->qp, &attr,
224 static struct pingpong_dest *pp_server_exch_dest(struct pingpong_context *ctx,
299 if (pp_connect_ctx(ctx, ib_port, my_dest->psn, mtu, sl, rem_dest,
329 struct pingpong_context *ctx;
332 ctx = calloc(1, sizeof *ctx);
333 if (!ctx)
336 ctx->size = size;
337 ctx->send_flags = IBV_SEND_SIGNALED;
338 ctx->rx_depth = rx_depth;
340 ctx->buf = memalign(page_size, size);
341 if (!ctx->buf) {
346 /* FIXME memset(ctx->buf, 0, size); */
347 memset(ctx->buf, 0x7b, size);
349 ctx->context = ibv_open_device(ib_dev);
350 if (!ctx->context) {
357 ctx->channel = ibv_create_comp_channel(ctx->context);
358 if (!ctx->channel) {
363 ctx->channel = NULL;
365 ctx->pd = ibv_alloc_pd(ctx->context);
366 if (!ctx->pd) {
376 if (ibv_query_device_ex(ctx->context, NULL, &attrx)) {
395 ctx->completion_timestamp_mask = attrx.completion_timestamp_mask;
398 ctx->mr = ibv_reg_mr(ctx->pd, ctx->buf, size, access_flags);
400 if (!ctx->mr) {
409 .channel = ctx->channel,
414 ctx->cq_s.cq_ex = ibv_create_cq_ex(ctx->context, &attr_ex);
416 ctx->cq_s.cq = ibv_create_cq(ctx->context, rx_depth + 1, NULL,
417 ctx->channel, 0);
420 if (!pp_cq(ctx)) {
428 .send_cq = pp_cq(ctx),
429 .recv_cq = pp_cq(ctx),
439 ctx->qp = ibv_create_qp(ctx->pd, &init_attr);
440 if (!ctx->qp) {
445 ibv_query_qp(ctx->qp, &attr, IBV_QP_CAP, &init_attr);
447 ctx->send_flags |= IBV_SEND_INLINE;
459 if (ibv_modify_qp(ctx->qp, &attr,
469 return ctx;
472 ibv_destroy_qp(ctx->qp);
475 ibv_destroy_cq(pp_cq(ctx));
478 ibv_dereg_mr(ctx->mr);
481 ibv_dealloc_pd(ctx->pd);
484 if (ctx->channel)
485 ibv_destroy_comp_channel(ctx->channel);
488 ibv_close_device(ctx->context);
491 free(ctx->buf);
494 free(ctx);
499 static int pp_close_ctx(struct pingpong_context *ctx)
501 if (ibv_destroy_qp(ctx->qp)) {
506 if (ibv_destroy_cq(pp_cq(ctx))) {
511 if (ibv_dereg_mr(ctx->mr)) {
516 if (ibv_dealloc_pd(ctx->pd)) {
521 if (ctx->channel) {
522 if (ibv_destroy_comp_channel(ctx->channel)) {
528 if (ibv_close_device(ctx->context)) {
533 free(ctx->buf);
534 free(ctx);
539 static int pp_post_recv(struct pingpong_context *ctx, int n)
542 .addr = (uintptr_t) ctx->buf,
543 .length = ctx->size,
544 .lkey = ctx->mr->lkey
555 if (ibv_post_recv(ctx->qp, &wr, &bad_wr))
561 static int pp_post_send(struct pingpong_context *ctx)
564 .addr = (uintptr_t) ctx->buf,
565 .length = ctx->size,
566 .lkey = ctx->mr->lkey
573 .send_flags = ctx->send_flags,
577 return ibv_post_send(ctx->qp, &wr, &bad_wr);
589 static inline int parse_single_wc(struct pingpong_context *ctx, int *scnt,
609 *routs += pp_post_recv(ctx, ctx->rx_depth - *routs);
610 if (*routs < ctx->rx_depth) {
627 delta = ctx->completion_timestamp_mask - ts->comp_recv_prev_time +
650 ctx->pending &= ~(int)wr_id;
651 if (*scnt < iters && !ctx->pending) {
652 if (pp_post_send(ctx)) {
656 ctx->pending = PINGPONG_RECV_WRID |
688 struct pingpong_context *ctx;
844 ctx = pp_init_ctx(ib_dev, size, rx_depth, ib_port, use_event);
845 if (!ctx)
848 routs = pp_post_recv(ctx, ctx->rx_depth);
849 if (routs < ctx->rx_depth) {
855 if (ibv_req_notify_cq(pp_cq(ctx), 0)) {
861 if (pp_get_port_info(ctx->context, ib_port, &ctx->portinfo)) {
866 my_dest.lid = ctx->portinfo.lid;
867 if (ctx->portinfo.link_layer != IBV_LINK_LAYER_ETHERNET &&
874 if (ibv_query_gid(ctx->context, ib_port, gidx, &my_dest.gid)) {
881 my_dest.qpn = ctx->qp->qp_num;
891 rem_dest = pp_server_exch_dest(ctx, ib_port, mtu, port, sl,
902 if (pp_connect_ctx(ctx, ib_port, my_dest.psn, mtu, sl, rem_dest,
906 ctx->pending = PINGPONG_RECV_WRID;
909 if (pp_post_send(ctx)) {
913 ctx->pending |= PINGPONG_SEND_WRID;
929 if (ibv_get_cq_event(ctx->channel, &ev_cq, &ev_ctx)) {
936 if (ev_cq != pp_cq(ctx)) {
941 if (ibv_req_notify_cq(pp_cq(ctx), 0)) {
951 ret = ibv_start_poll(ctx->cq_s.cq_ex, &attr);
958 ret = parse_single_wc(ctx, &scnt, &rcnt, &routs,
960 ctx->cq_s.cq_ex->wr_id,
961 ctx->cq_s.cq_ex->status,
962 ibv_wc_read_completion_ts(ctx->cq_s.cq_ex),
965 ibv_end_poll(ctx->cq_s.cq_ex);
968 ret = ibv_next_poll(ctx->cq_s.cq_ex);
970 ret = parse_single_wc(ctx, &scnt, &rcnt, &routs,
972 ctx->cq_s.cq_ex->wr_id,
973 ctx->cq_s.cq_ex->status,
974 ibv_wc_read_completion_ts(ctx->cq_s.cq_ex),
976 ibv_end_poll(ctx->cq_s.cq_ex);
986 ne = ibv_poll_cq(pp_cq(ctx), 2, wc);
994 ret = parse_single_wc(ctx, &scnt, &rcnt, &routs,
1032 ibv_ack_cq_events(pp_cq(ctx), num_cq_events);
1034 if (pp_close_ctx(ctx))