1 /*
2  * Copyright (c) 2004, 2005 Topspin Communications.  All rights reserved.
3  * Copyright (c) 2005, 2006, 2016 Cisco Systems, Inc.  All rights reserved.
4  * Copyright (c) 2005 PathScale, Inc.  All rights reserved.
5  * Copyright (c) 2013-2014 Intel Corporation. All rights reserved.
6  *
7  * This software is available to you under a choice of one of two
8  * licenses.  You may choose to be licensed under the terms of the GNU
9  * General Public License (GPL) Version 2, available from the file
10  * COPYING in the main directory of this source tree, or the
11  * BSD license below:
12  *
13  *     Redistribution and use in source and binary forms, with or
14  *     without modification, are permitted provided that the following
15  *     conditions are met:
16  *
17  *      - Redistributions of source code must retain the above
18  *        copyright notice, this list of conditions and the following
19  *        disclaimer.
20  *
21  *      - Redistributions in binary form must reproduce the above
22  *        copyright notice, this list of conditions and the following
23  *        disclaimer in the documentation and/or other materials
24  *        provided with the distribution.
25  *
26  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
27  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
29  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
30  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
31  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
32  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
33  * SOFTWARE.
34  */
35 
36 #ifndef FI_PROV_H
37 #define FI_PROV_H
38 
39 #include <rdma/fabric.h>
40 
41 #ifdef __cplusplus
42 extern "C" {
43 #endif
44 
45 /*
46  * Extension that dl-loaded providers should add to their .so filename
47  * (probably via libtool "-release" option). For example a provider
48  * driver named "foo" should build a plug-in named "libfoo-fi.so", and
49  * place it in $prefix/$libdir/libfabric/
50  */
51 #define FI_LIB_EXTENSION "fi"
52 #define FI_LIB_SUFFIX FI_LIB_EXTENSION ".so"
53 
54 /*
55  * Dynamically loaded providers must export the following entry point.
56  * This is invoked by the libfabric framework when the provider library
57  * is loaded.
58  */
59 #define FI_EXT_INI \
60 	__attribute__((visibility ("default"),EXTERNALLY_VISIBLE)) \
61 	struct fi_provider* fi_prov_ini(void)
62 
63 struct fi_provider {
64 	uint32_t version;
65 	uint32_t fi_version;
66 	struct fi_context context;
67 	const char *name;
68 	int	(*getinfo)(uint32_t version, const char *node, const char *service,
69 			uint64_t flags, const struct fi_info *hints,
70 			struct fi_info **info);
71 	int	(*fabric)(struct fi_fabric_attr *attr, struct fid_fabric **fabric,
72 			void *context);
73 	void	(*cleanup)(void);
74 };
75 
76 
77 /*
78  * Defines a configuration parameter for use with libfabric.
79  *
80  * This registers the configuration variable "foo" in the specified
81  * provider.
82  *
83  * The help string cannot be NULL or empty.
84  *
85  * The param_name and help_string parameters will be copied internally;
86  * they can be freed upon return from fi_param_define().
87  */
88 int fi_param_define(const struct fi_provider *provider, const char *param_name,
89 		    enum fi_param_type type, const char *help_string_fmt, ...);
90 
91 /*
92  * Get the value of a configuration variable.
93  *
94  * Currently, configuration parameter will only be read from the
95  * environment.  The environment variable names will be of the form
96  * upper_case(FI_<provider_name>_<param_name>).
97  *
98  * Someday this call could be expanded to also check config files.
99  *
100  * If the parameter was previously defined and the user set a value,
101  * FI_SUCCESS is returned and (*value) points to the retrieved
102  * value.
103  *
104  * If the parameter name was previously defined, but the user did
105  * not set a value, -FI_ENODATA is returned and the value of (*value)
106  * is unchanged.
107  *
108  * If the variable name was not previously defined via
109  * fi_param_define(), -FI_ENOENT will be returned and the value of
110  * (*value) is unchanged.
111  */
112 int fi_param_get(struct fi_provider *provider, const char *param_name,
113 		 void *value);
114 
115 static inline int
fi_param_get_str(struct fi_provider * provider,const char * param_name,char ** value)116 fi_param_get_str(struct fi_provider *provider, const char *param_name, char **value)
117 {
118 	return fi_param_get(provider, param_name, value);
119 }
120 
121 static inline int
fi_param_get_int(struct fi_provider * provider,const char * param_name,int * value)122 fi_param_get_int(struct fi_provider *provider, const char *param_name, int *value)
123 {
124 	return fi_param_get(provider, param_name, value);
125 }
126 
127 static inline int
fi_param_get_bool(struct fi_provider * provider,const char * param_name,int * value)128 fi_param_get_bool(struct fi_provider *provider, const char *param_name, int *value)
129 {
130 	return fi_param_get(provider, param_name, value);
131 }
132 
133 static inline int
fi_param_get_size_t(struct fi_provider * provider,const char * param_name,size_t * value)134 fi_param_get_size_t(struct fi_provider *provider, const char *param_name, size_t *value)
135 {
136 	return fi_param_get(provider, param_name, value);
137 }
138 
139 #ifdef __cplusplus
140 }
141 #endif
142 
143 #endif /* FI_PROV_H */
144