Lines Matching refs:ctx

92 	struct ib_ucm_context *ctx;  member
127 struct ib_ucm_context *ctx; in ib_ucm_ctx_get() local
130 ctx = idr_find(&ctx_id_table, id); in ib_ucm_ctx_get()
131 if (!ctx) in ib_ucm_ctx_get()
132 ctx = ERR_PTR(-ENOENT); in ib_ucm_ctx_get()
133 else if (ctx->file != file) in ib_ucm_ctx_get()
134 ctx = ERR_PTR(-EINVAL); in ib_ucm_ctx_get()
136 atomic_inc(&ctx->ref); in ib_ucm_ctx_get()
139 return ctx; in ib_ucm_ctx_get()
142 static void ib_ucm_ctx_put(struct ib_ucm_context *ctx) in ib_ucm_ctx_put() argument
144 if (atomic_dec_and_test(&ctx->ref)) in ib_ucm_ctx_put()
145 complete(&ctx->comp); in ib_ucm_ctx_put()
153 static void ib_ucm_cleanup_events(struct ib_ucm_context *ctx) in ib_ucm_cleanup_events() argument
157 mutex_lock(&ctx->file->file_mutex); in ib_ucm_cleanup_events()
158 list_del(&ctx->file_list); in ib_ucm_cleanup_events()
159 while (!list_empty(&ctx->events)) { in ib_ucm_cleanup_events()
161 uevent = list_entry(ctx->events.next, in ib_ucm_cleanup_events()
165 mutex_unlock(&ctx->file->file_mutex); in ib_ucm_cleanup_events()
172 mutex_lock(&ctx->file->file_mutex); in ib_ucm_cleanup_events()
174 mutex_unlock(&ctx->file->file_mutex); in ib_ucm_cleanup_events()
179 struct ib_ucm_context *ctx; in ib_ucm_ctx_alloc() local
181 ctx = kzalloc(sizeof *ctx, GFP_KERNEL); in ib_ucm_ctx_alloc()
182 if (!ctx) in ib_ucm_ctx_alloc()
185 atomic_set(&ctx->ref, 1); in ib_ucm_ctx_alloc()
186 init_completion(&ctx->comp); in ib_ucm_ctx_alloc()
187 ctx->file = file; in ib_ucm_ctx_alloc()
188 INIT_LIST_HEAD(&ctx->events); in ib_ucm_ctx_alloc()
191 ctx->id = idr_alloc(&ctx_id_table, ctx, 0, 0, GFP_KERNEL); in ib_ucm_ctx_alloc()
193 if (ctx->id < 0) in ib_ucm_ctx_alloc()
196 list_add_tail(&ctx->file_list, &file->ctxs); in ib_ucm_ctx_alloc()
197 return ctx; in ib_ucm_ctx_alloc()
200 kfree(ctx); in ib_ucm_ctx_alloc()
352 struct ib_ucm_context *ctx; in ib_ucm_event_handler() local
355 ctx = cm_id->context; in ib_ucm_event_handler()
361 uevent->ctx = ctx; in ib_ucm_event_handler()
363 uevent->resp.uid = ctx->uid; in ib_ucm_event_handler()
364 uevent->resp.id = ctx->id; in ib_ucm_event_handler()
371 mutex_lock(&ctx->file->file_mutex); in ib_ucm_event_handler()
372 list_add_tail(&uevent->file_list, &ctx->file->events); in ib_ucm_event_handler()
373 list_add_tail(&uevent->ctx_list, &ctx->events); in ib_ucm_event_handler()
374 wake_up_interruptible(&ctx->file->poll_wait); in ib_ucm_event_handler()
375 mutex_unlock(&ctx->file->file_mutex); in ib_ucm_event_handler()
389 struct ib_ucm_context *ctx; in ib_ucm_event() local
417 ctx = ib_ucm_ctx_alloc(file); in ib_ucm_event()
418 if (!ctx) { in ib_ucm_event()
423 ctx->cm_id = uevent->cm_id; in ib_ucm_event()
424 ctx->cm_id->context = ctx; in ib_ucm_event()
425 uevent->resp.id = ctx->id; in ib_ucm_event()
460 uevent->ctx->events_reported++; in ib_ucm_event()
476 struct ib_ucm_context *ctx; in ib_ucm_create_id() local
486 ctx = ib_ucm_ctx_alloc(file); in ib_ucm_create_id()
488 if (!ctx) in ib_ucm_create_id()
491 ctx->uid = cmd.uid; in ib_ucm_create_id()
492 ctx->cm_id = ib_create_cm_id(file->device->ib_dev, in ib_ucm_create_id()
493 ib_ucm_event_handler, ctx); in ib_ucm_create_id()
494 if (IS_ERR(ctx->cm_id)) { in ib_ucm_create_id()
495 result = PTR_ERR(ctx->cm_id); in ib_ucm_create_id()
499 resp.id = ctx->id; in ib_ucm_create_id()
508 ib_destroy_cm_id(ctx->cm_id); in ib_ucm_create_id()
511 idr_remove(&ctx_id_table, ctx->id); in ib_ucm_create_id()
513 kfree(ctx); in ib_ucm_create_id()
523 struct ib_ucm_context *ctx; in ib_ucm_destroy_id() local
533 ctx = idr_find(&ctx_id_table, cmd.id); in ib_ucm_destroy_id()
534 if (!ctx) in ib_ucm_destroy_id()
535 ctx = ERR_PTR(-ENOENT); in ib_ucm_destroy_id()
536 else if (ctx->file != file) in ib_ucm_destroy_id()
537 ctx = ERR_PTR(-EINVAL); in ib_ucm_destroy_id()
539 idr_remove(&ctx_id_table, ctx->id); in ib_ucm_destroy_id()
542 if (IS_ERR(ctx)) in ib_ucm_destroy_id()
543 return PTR_ERR(ctx); in ib_ucm_destroy_id()
545 ib_ucm_ctx_put(ctx); in ib_ucm_destroy_id()
546 wait_for_completion(&ctx->comp); in ib_ucm_destroy_id()
549 ib_destroy_cm_id(ctx->cm_id); in ib_ucm_destroy_id()
551 ib_ucm_cleanup_events(ctx); in ib_ucm_destroy_id()
553 resp.events_reported = ctx->events_reported; in ib_ucm_destroy_id()
558 kfree(ctx); in ib_ucm_destroy_id()
568 struct ib_ucm_context *ctx; in ib_ucm_attr_id() local
577 ctx = ib_ucm_ctx_get(file, cmd.id); in ib_ucm_attr_id()
578 if (IS_ERR(ctx)) in ib_ucm_attr_id()
579 return PTR_ERR(ctx); in ib_ucm_attr_id()
581 resp.service_id = ctx->cm_id->service_id; in ib_ucm_attr_id()
582 resp.service_mask = ctx->cm_id->service_mask; in ib_ucm_attr_id()
583 resp.local_id = ctx->cm_id->local_id; in ib_ucm_attr_id()
584 resp.remote_id = ctx->cm_id->remote_id; in ib_ucm_attr_id()
590 ib_ucm_ctx_put(ctx); in ib_ucm_attr_id()
600 struct ib_ucm_context *ctx; in ib_ucm_init_qp_attr() local
610 ctx = ib_ucm_ctx_get(file, cmd.id); in ib_ucm_init_qp_attr()
611 if (IS_ERR(ctx)) in ib_ucm_init_qp_attr()
612 return PTR_ERR(ctx); in ib_ucm_init_qp_attr()
617 result = ib_cm_init_qp_attr(ctx->cm_id, &qp_attr, &resp.qp_attr_mask); in ib_ucm_init_qp_attr()
628 ib_ucm_ctx_put(ctx); in ib_ucm_init_qp_attr()
648 struct ib_ucm_context *ctx; in ib_ucm_listen() local
654 ctx = ib_ucm_ctx_get(file, cmd.id); in ib_ucm_listen()
655 if (IS_ERR(ctx)) in ib_ucm_listen()
656 return PTR_ERR(ctx); in ib_ucm_listen()
662 result = ib_cm_listen(ctx->cm_id, cmd.service_id, cmd.service_mask, in ib_ucm_listen()
665 ib_ucm_ctx_put(ctx); in ib_ucm_listen()
674 struct ib_ucm_context *ctx; in ib_ucm_notify() local
680 ctx = ib_ucm_ctx_get(file, cmd.id); in ib_ucm_notify()
681 if (IS_ERR(ctx)) in ib_ucm_notify()
682 return PTR_ERR(ctx); in ib_ucm_notify()
684 result = ib_cm_notify(ctx->cm_id, (enum ib_event_type) cmd.event); in ib_ucm_notify()
685 ib_ucm_ctx_put(ctx); in ib_ucm_notify()
737 struct ib_ucm_context *ctx; in ib_ucm_send_req() local
776 ctx = ib_ucm_ctx_get(file, cmd.id); in ib_ucm_send_req()
777 if (!IS_ERR(ctx)) { in ib_ucm_send_req()
778 result = ib_send_cm_req(ctx->cm_id, &param); in ib_ucm_send_req()
779 ib_ucm_ctx_put(ctx); in ib_ucm_send_req()
781 result = PTR_ERR(ctx); in ib_ucm_send_req()
795 struct ib_ucm_context *ctx; in ib_ucm_send_rep() local
818 ctx = ib_ucm_ctx_get(file, cmd.id); in ib_ucm_send_rep()
819 if (!IS_ERR(ctx)) { in ib_ucm_send_rep()
820 ctx->uid = cmd.uid; in ib_ucm_send_rep()
821 result = ib_send_cm_rep(ctx->cm_id, &param); in ib_ucm_send_rep()
822 ib_ucm_ctx_put(ctx); in ib_ucm_send_rep()
824 result = PTR_ERR(ctx); in ib_ucm_send_rep()
837 struct ib_ucm_context *ctx; in ib_ucm_send_private_data() local
848 ctx = ib_ucm_ctx_get(file, cmd.id); in ib_ucm_send_private_data()
849 if (!IS_ERR(ctx)) { in ib_ucm_send_private_data()
850 result = func(ctx->cm_id, private_data, cmd.len); in ib_ucm_send_private_data()
851 ib_ucm_ctx_put(ctx); in ib_ucm_send_private_data()
853 result = PTR_ERR(ctx); in ib_ucm_send_private_data()
889 struct ib_ucm_context *ctx; in ib_ucm_send_info() local
906 ctx = ib_ucm_ctx_get(file, cmd.id); in ib_ucm_send_info()
907 if (!IS_ERR(ctx)) { in ib_ucm_send_info()
908 result = func(ctx->cm_id, cmd.status, info, cmd.info_len, in ib_ucm_send_info()
910 ib_ucm_ctx_put(ctx); in ib_ucm_send_info()
912 result = PTR_ERR(ctx); in ib_ucm_send_info()
938 struct ib_ucm_context *ctx; in ib_ucm_send_mra() local
950 ctx = ib_ucm_ctx_get(file, cmd.id); in ib_ucm_send_mra()
951 if (!IS_ERR(ctx)) { in ib_ucm_send_mra()
952 result = ib_send_cm_mra(ctx->cm_id, cmd.timeout, data, cmd.len); in ib_ucm_send_mra()
953 ib_ucm_ctx_put(ctx); in ib_ucm_send_mra()
955 result = PTR_ERR(ctx); in ib_ucm_send_mra()
965 struct ib_ucm_context *ctx; in ib_ucm_send_lap() local
982 ctx = ib_ucm_ctx_get(file, cmd.id); in ib_ucm_send_lap()
983 if (!IS_ERR(ctx)) { in ib_ucm_send_lap()
984 result = ib_send_cm_lap(ctx->cm_id, path, data, cmd.len); in ib_ucm_send_lap()
985 ib_ucm_ctx_put(ctx); in ib_ucm_send_lap()
987 result = PTR_ERR(ctx); in ib_ucm_send_lap()
1000 struct ib_ucm_context *ctx; in ib_ucm_send_sidr_req() local
1023 ctx = ib_ucm_ctx_get(file, cmd.id); in ib_ucm_send_sidr_req()
1024 if (!IS_ERR(ctx)) { in ib_ucm_send_sidr_req()
1025 result = ib_send_cm_sidr_req(ctx->cm_id, &param); in ib_ucm_send_sidr_req()
1026 ib_ucm_ctx_put(ctx); in ib_ucm_send_sidr_req()
1028 result = PTR_ERR(ctx); in ib_ucm_send_sidr_req()
1042 struct ib_ucm_context *ctx; in ib_ucm_send_sidr_rep() local
1065 ctx = ib_ucm_ctx_get(file, cmd.id); in ib_ucm_send_sidr_rep()
1066 if (!IS_ERR(ctx)) { in ib_ucm_send_sidr_rep()
1067 result = ib_send_cm_sidr_rep(ctx->cm_id, &param); in ib_ucm_send_sidr_rep()
1068 ib_ucm_ctx_put(ctx); in ib_ucm_send_sidr_rep()
1070 result = PTR_ERR(ctx); in ib_ucm_send_sidr_rep()
1177 struct ib_ucm_context *ctx; in ib_ucm_close() local
1181 ctx = list_entry(file->ctxs.next, in ib_ucm_close()
1186 idr_remove(&ctx_id_table, ctx->id); in ib_ucm_close()
1189 ib_destroy_cm_id(ctx->cm_id); in ib_ucm_close()
1190 ib_ucm_cleanup_events(ctx); in ib_ucm_close()
1191 kfree(ctx); in ib_ucm_close()