1 /** 2 * Copyright (C) Mellanox Technologies Ltd. 2001-2019. ALL RIGHTS RESERVED. 3 * 4 * See file LICENSE for terms. 5 */ 6 7 8 #ifndef UCT_COMPONENT_H_ 9 #define UCT_COMPONENT_H_ 10 11 #include <uct/api/uct.h> 12 #include <ucs/config/parser.h> 13 #include <ucs/datastruct/list.h> 14 15 16 /* Forward declaration */ 17 typedef struct uct_component uct_component_t; 18 19 20 /** 21 * Keeps information about allocated configuration structure, to be used when 22 * releasing the options. 23 */ 24 typedef struct uct_config_bundle { 25 ucs_config_field_t *table; 26 const char *table_prefix; 27 char data[]; 28 } uct_config_bundle_t; 29 30 31 /** 32 * Component method to query component memory domain resources. 33 * 34 * @param [in] component Query memory domain resources for this 35 * component. 36 * @param [out] resources_p Filled with a pointer to an array of 37 * memory domain resources, which should be 38 * released with ucs_free(). 39 * @param [out] num_resources_p Filled with the number of memory domain 40 * resource entries in the array. 41 * 42 * @return UCS_OK on success or error code in case of failure. 43 */ 44 typedef ucs_status_t (*uct_component_query_md_resources_func_t)( 45 uct_component_t *component, uct_md_resource_desc_t **resources_p, 46 unsigned *num_resources_p); 47 48 49 /** 50 * Component method to open a memory domain. 51 * 52 * @param [in] component Open memory domain resources on this 53 * component. 54 * @param [in] md_name Name of the memory domain to open, as 55 * returned by 56 * @ref uct_component_query_resources_func_t 57 * @param [in] config Memory domain configuration. 58 * @param [out] md_p Handle to the opened memory domain. 59 * 60 * @return UCS_OK on success or error code in case of failure. 61 */ 62 typedef ucs_status_t (*uct_component_md_open_func_t)( 63 uct_component_t *component, const char *md_name, 64 const uct_md_config_t *config, uct_md_h *md_p); 65 66 67 /** 68 * Component method to open a client/server connection manager. 69 * 70 * @param [in] component Open a connection manager on this 71 * component. 72 * @param [in] worker Open the connection manager on this worker. 73 * @param [in] config Connection manager configuration. 74 * @param [out] cm_p Filled with a handle to the connection manager. 75 * 76 * @return UCS_OK on success or error code in case of failure. 77 */ 78 typedef ucs_status_t (*uct_component_cm_open_func_t)( 79 uct_component_t *component, uct_worker_h worker, 80 const uct_cm_config_t *config, uct_cm_h *cm_p); 81 82 83 /** 84 * Component method to unpack a remote key buffer into a remote key object. 85 * 86 * @param [in] component Unpack the remote key buffer on this 87 * component. 88 * @param [in] rkey_buffer Remote key buffer to unpack. 89 * @param [in] config Memory domain configuration. 90 * @param [out] rkey_p Filled with a pointer to the unpacked 91 * remote key. 92 * @param [out] handle_p Filled with an additional handle which 93 * is used to release the remote key, but 94 * is not required for remote memory 95 * access operations. 96 * 97 * @return UCS_OK on success or error code in case of failure. 98 */ 99 typedef ucs_status_t (*uct_component_rkey_unpack_func_t)( 100 uct_component_t *component, const void *rkey_buffer, 101 uct_rkey_t *rkey_p, void **handle_p); 102 103 104 /** 105 * Component method to obtain a locally accessible pointer to a remote key. 106 * 107 * @param [in] component Get remote key memory pointer on this 108 * component. 109 * @param [in] rkey Obtain the pointer for this remote key. 110 * @param [in] handle Remote key handle, as returned from 111 * @ref uct_component_rkey_unpack_func_t. 112 * @param [in] remote_addr Remote address to obtain the pointer for. 113 * @param [out] local_addr_p Filled with the local access pointer. 114 * 115 * @return UCS_OK on success or error code in case of failure. 116 */ 117 typedef ucs_status_t (*uct_component_rkey_ptr_func_t)( 118 uct_component_t *component, uct_rkey_t rkey, void *handle, 119 uint64_t remote_addr, void **local_addr_p); 120 121 122 /** 123 * Component method to release an unpacked remote key. 124 * 125 * @param [in] component Release the remote key of this 126 * component. 127 * @param [in] rkey Release this remote key. 128 * @param [in] handle Remote key handle, as returned from 129 * @ref uct_component_rkey_unpack_func_t. 130 * 131 * @return UCS_OK on success or error code in case of failure. 132 */ 133 typedef ucs_status_t (*uct_component_rkey_release_func_t)( 134 uct_component_t *component, uct_rkey_t rkey, void *handle); 135 136 137 /** 138 * Defines a UCT component 139 */ 140 struct uct_component { 141 const char name[UCT_COMPONENT_NAME_MAX]; /**< Component name */ 142 uct_component_query_md_resources_func_t query_md_resources; /**< Query memory domain resources method */ 143 uct_component_md_open_func_t md_open; /**< Memory domain open method */ 144 uct_component_cm_open_func_t cm_open; /**< Connection manager open method */ 145 uct_component_rkey_unpack_func_t rkey_unpack; /**< Remote key unpack method */ 146 uct_component_rkey_ptr_func_t rkey_ptr; /**< Remote key access pointer method */ 147 uct_component_rkey_release_func_t rkey_release; /**< Remote key release method */ 148 ucs_config_global_list_entry_t md_config; /**< MD configuration entry */ 149 ucs_config_global_list_entry_t cm_config; /**< CM configuration entry */ 150 ucs_list_link_t tl_list; /**< List of transports */ 151 ucs_list_link_t list; /**< Entry in global list of components */ 152 uint64_t flags; /**< Flags as defined by 153 UCT_COMPONENT_FLAG_xx */ 154 }; 155 156 157 /** 158 * Register a component for usage, so it will be returned from 159 * @ref uct_query_components. 160 * 161 * @param [in] _component Pointer to a global component structure to register. 162 */ 163 #define UCT_COMPONENT_REGISTER(_component) \ 164 extern ucs_list_link_t uct_components_list; \ 165 UCS_STATIC_INIT { \ 166 ucs_list_add_tail(&uct_components_list, &(_component)->list); \ 167 } \ 168 UCS_CONFIG_REGISTER_TABLE_ENTRY(&(_component)->md_config); \ 169 UCS_CONFIG_REGISTER_TABLE_ENTRY(&(_component)->cm_config); \ 170 171 172 /** 173 * Helper macro to initialize component's transport list head. 174 */ 175 #define UCT_COMPONENT_TL_LIST_INITIALIZER(_component) \ 176 UCS_LIST_INITIALIZER(&(_component)->tl_list, &(_component)->tl_list) 177 178 179 ucs_status_t uct_config_read(uct_config_bundle_t **bundle, 180 ucs_config_field_t *config_table, 181 size_t config_size, const char *env_prefix, 182 const char *cfg_prefix); 183 184 #endif 185