1 /*
2  * Copyright (c) 2017-2018 Intel Corporation. All rights reserved.
3  *
4  * This software is available to you under a choice of one of two
5  * licenses.  You may choose to be licensed under the terms of the GNU
6  * General Public License (GPL) Version 2, available from the file
7  * COPYING in the main directory of this source tree, or the
8  * BSD license below:
9  *
10  *     Redistribution and use in source and binary forms, with or
11  *     without modification, are permitted provided that the following
12  *     conditions are met:
13  *
14  *      - Redistributions of source code must retain the above
15  *        copyright notice, this list of conditions and the following
16  *        disclaimer.
17  *
18  *      - Redistributions in binary form must reproduce the above
19  *        copyright notice, this list of conditions and the following
20  *        disclaimer in the documentation and/or other materials
21  *        provided with the distribution.
22  *
23  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30  * SOFTWARE.
31  */
32 
33 #include "rstream.h"
34 
35 
rstream_domain_close(fid_t fid)36 static int rstream_domain_close(fid_t fid)
37 {
38 	struct rstream_domain *rstream_domain =
39 		container_of(fid, struct rstream_domain,
40 		util_domain.domain_fid.fid);
41 	int ret;
42 
43 	ret = fi_close(&rstream_domain->msg_domain->fid);
44 	if (ret)
45 		return ret;
46 
47 	ret = ofi_domain_close(&rstream_domain->util_domain);
48 	if (ret)
49 		return ret;
50 
51 	free(rstream_domain);
52 
53 	return 0;
54 }
55 
56 static struct fi_ops_mr rstream_domain_mr_ops = {
57 	.size = sizeof(struct fi_ops_mr),
58 	.reg = fi_no_mr_reg,
59 	.regv = fi_no_mr_regv,
60 	.regattr = fi_no_mr_regattr,
61 };
62 
63 static struct fi_ops rstream_domain_fi_ops = {
64 	.size = sizeof(struct fi_ops),
65 	.close = rstream_domain_close,
66 	.bind = fi_no_bind,
67 	.control = fi_no_control,
68 	.ops_open = fi_no_ops_open,
69 };
70 
71 static struct fi_ops_domain rstream_domain_ops = {
72 	.size = sizeof(struct fi_ops_domain),
73 	.av_open = fi_no_av_open,
74 	.cq_open = fi_no_cq_open,
75 	.endpoint = rstream_ep_open,
76 	.scalable_ep = fi_no_scalable_ep,
77 	.cntr_open = fi_no_cntr_open,
78 	.poll_open = fi_no_poll_open,
79 	.stx_ctx = fi_no_stx_context,
80 	.srx_ctx = fi_no_srx_context,
81 	.query_atomic = fi_no_query_atomic,
82 	.query_collective = fi_no_query_collective,
83 };
84 
rstream_domain_open(struct fid_fabric * fabric,struct fi_info * info,struct fid_domain ** domain,void * context)85 int rstream_domain_open(struct fid_fabric *fabric, struct fi_info *info,
86 			   struct fid_domain **domain, void *context)
87 {
88 	struct rstream_domain *rstream_domain;
89 	struct rstream_fabric *rstream_fabric;
90 	int ret;
91 	struct fi_info *cinfo = NULL;
92 
93 	rstream_domain = calloc(1, sizeof(*rstream_domain));
94 	if (!rstream_domain)
95 		return -FI_ENOMEM;
96 
97 	rstream_fabric = container_of(fabric, struct rstream_fabric,
98 		util_fabric.fabric_fid);
99 
100 	ret = ofi_get_core_info(FI_VERSION(1, 8), NULL, NULL, 0,
101 		&rstream_util_prov, info, rstream_info_to_core, &cinfo);
102 	if (ret)
103 		goto err1;
104 
105 	ret = fi_domain(rstream_fabric->msg_fabric, cinfo,
106 		&rstream_domain->msg_domain, context);
107 	if (ret)
108 		goto err1;
109 
110 	ret = ofi_domain_init(fabric, info, &rstream_domain->util_domain,
111 		context);
112 	if (ret)
113 		goto err1;
114 
115 	*domain = &rstream_domain->util_domain.domain_fid;
116 	(*domain)->fid.ops = &rstream_domain_fi_ops;
117 	(*domain)->mr = &rstream_domain_mr_ops;
118 	(*domain)->ops = &rstream_domain_ops;
119 
120 	return 0;
121 err1:
122 	if (cinfo)
123 		fi_freeinfo(cinfo);
124 	free(rstream_domain);
125 	return ret;
126 }
127