![]() |
|
|||
0001 /* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */ 0002 /* 0003 * Copyright (c) 2005 Voltaire Inc. All rights reserved. 0004 * Copyright (c) 2005 Intel Corporation. All rights reserved. 0005 */ 0006 0007 #ifndef RDMA_CM_H 0008 #define RDMA_CM_H 0009 0010 #include <linux/socket.h> 0011 #include <linux/in6.h> 0012 #include <rdma/ib_addr.h> 0013 #include <rdma/ib_sa.h> 0014 #include <uapi/rdma/rdma_user_cm.h> 0015 0016 /* 0017 * Upon receiving a device removal event, users must destroy the associated 0018 * RDMA identifier and release all resources allocated with the device. 0019 */ 0020 enum rdma_cm_event_type { 0021 RDMA_CM_EVENT_ADDR_RESOLVED, 0022 RDMA_CM_EVENT_ADDR_ERROR, 0023 RDMA_CM_EVENT_ROUTE_RESOLVED, 0024 RDMA_CM_EVENT_ROUTE_ERROR, 0025 RDMA_CM_EVENT_CONNECT_REQUEST, 0026 RDMA_CM_EVENT_CONNECT_RESPONSE, 0027 RDMA_CM_EVENT_CONNECT_ERROR, 0028 RDMA_CM_EVENT_UNREACHABLE, 0029 RDMA_CM_EVENT_REJECTED, 0030 RDMA_CM_EVENT_ESTABLISHED, 0031 RDMA_CM_EVENT_DISCONNECTED, 0032 RDMA_CM_EVENT_DEVICE_REMOVAL, 0033 RDMA_CM_EVENT_MULTICAST_JOIN, 0034 RDMA_CM_EVENT_MULTICAST_ERROR, 0035 RDMA_CM_EVENT_ADDR_CHANGE, 0036 RDMA_CM_EVENT_TIMEWAIT_EXIT 0037 }; 0038 0039 const char *__attribute_const__ rdma_event_msg(enum rdma_cm_event_type event); 0040 0041 #define RDMA_IB_IP_PS_MASK 0xFFFFFFFFFFFF0000ULL 0042 #define RDMA_IB_IP_PS_TCP 0x0000000001060000ULL 0043 #define RDMA_IB_IP_PS_UDP 0x0000000001110000ULL 0044 #define RDMA_IB_IP_PS_IB 0x00000000013F0000ULL 0045 0046 struct rdma_addr { 0047 struct sockaddr_storage src_addr; 0048 struct sockaddr_storage dst_addr; 0049 struct rdma_dev_addr dev_addr; 0050 }; 0051 0052 struct rdma_route { 0053 struct rdma_addr addr; 0054 struct sa_path_rec *path_rec; 0055 int num_paths; 0056 }; 0057 0058 struct rdma_conn_param { 0059 const void *private_data; 0060 u8 private_data_len; 0061 u8 responder_resources; 0062 u8 initiator_depth; 0063 u8 flow_control; 0064 u8 retry_count; /* ignored when accepting */ 0065 u8 rnr_retry_count; 0066 /* Fields below ignored if a QP is created on the rdma_cm_id. */ 0067 u8 srq; 0068 u32 qp_num; 0069 u32 qkey; 0070 }; 0071 0072 struct rdma_ud_param { 0073 const void *private_data; 0074 u8 private_data_len; 0075 struct rdma_ah_attr ah_attr; 0076 u32 qp_num; 0077 u32 qkey; 0078 }; 0079 0080 struct rdma_cm_event { 0081 enum rdma_cm_event_type event; 0082 int status; 0083 union { 0084 struct rdma_conn_param conn; 0085 struct rdma_ud_param ud; 0086 } param; 0087 struct rdma_ucm_ece ece; 0088 }; 0089 0090 struct rdma_cm_id; 0091 0092 /** 0093 * rdma_cm_event_handler - Callback used to report user events. 0094 * 0095 * Notes: Users may not call rdma_destroy_id from this callback to destroy 0096 * the passed in id, or a corresponding listen id. Returning a 0097 * non-zero value from the callback will destroy the passed in id. 0098 */ 0099 typedef int (*rdma_cm_event_handler)(struct rdma_cm_id *id, 0100 struct rdma_cm_event *event); 0101 0102 struct rdma_cm_id { 0103 struct ib_device *device; 0104 void *context; 0105 struct ib_qp *qp; 0106 rdma_cm_event_handler event_handler; 0107 struct rdma_route route; 0108 enum rdma_ucm_port_space ps; 0109 enum ib_qp_type qp_type; 0110 u32 port_num; 0111 struct work_struct net_work; 0112 }; 0113 0114 struct rdma_cm_id * 0115 __rdma_create_kernel_id(struct net *net, rdma_cm_event_handler event_handler, 0116 void *context, enum rdma_ucm_port_space ps, 0117 enum ib_qp_type qp_type, const char *caller); 0118 struct rdma_cm_id *rdma_create_user_id(rdma_cm_event_handler event_handler, 0119 void *context, 0120 enum rdma_ucm_port_space ps, 0121 enum ib_qp_type qp_type); 0122 0123 /** 0124 * rdma_create_id - Create an RDMA identifier. 0125 * 0126 * @net: The network namespace in which to create the new id. 0127 * @event_handler: User callback invoked to report events associated with the 0128 * returned rdma_id. 0129 * @context: User specified context associated with the id. 0130 * @ps: RDMA port space. 0131 * @qp_type: type of queue pair associated with the id. 0132 * 0133 * Returns a new rdma_cm_id. The id holds a reference on the network 0134 * namespace until it is destroyed. 0135 * 0136 * The event handler callback serializes on the id's mutex and is 0137 * allowed to sleep. 0138 */ 0139 #define rdma_create_id(net, event_handler, context, ps, qp_type) \ 0140 __rdma_create_kernel_id(net, event_handler, context, ps, qp_type, \ 0141 KBUILD_MODNAME) 0142 0143 /** 0144 * rdma_destroy_id - Destroys an RDMA identifier. 0145 * 0146 * @id: RDMA identifier. 0147 * 0148 * Note: calling this function has the effect of canceling in-flight 0149 * asynchronous operations associated with the id. 0150 */ 0151 void rdma_destroy_id(struct rdma_cm_id *id); 0152 0153 /** 0154 * rdma_bind_addr - Bind an RDMA identifier to a source address and 0155 * associated RDMA device, if needed. 0156 * 0157 * @id: RDMA identifier. 0158 * @addr: Local address information. Wildcard values are permitted. 0159 * 0160 * This associates a source address with the RDMA identifier before calling 0161 * rdma_listen. If a specific local address is given, the RDMA identifier will 0162 * be bound to a local RDMA device. 0163 */ 0164 int rdma_bind_addr(struct rdma_cm_id *id, struct sockaddr *addr); 0165 0166 /** 0167 * rdma_resolve_addr - Resolve destination and optional source addresses 0168 * from IP addresses to an RDMA address. If successful, the specified 0169 * rdma_cm_id will be bound to a local device. 0170 * 0171 * @id: RDMA identifier. 0172 * @src_addr: Source address information. This parameter may be NULL. 0173 * @dst_addr: Destination address information. 0174 * @timeout_ms: Time to wait for resolution to complete. 0175 */ 0176 int rdma_resolve_addr(struct rdma_cm_id *id, struct sockaddr *src_addr, 0177 const struct sockaddr *dst_addr, 0178 unsigned long timeout_ms); 0179 0180 /** 0181 * rdma_resolve_route - Resolve the RDMA address bound to the RDMA identifier 0182 * into route information needed to establish a connection. 0183 * 0184 * This is called on the client side of a connection. 0185 * Users must have first called rdma_resolve_addr to resolve a dst_addr 0186 * into an RDMA address before calling this routine. 0187 */ 0188 int rdma_resolve_route(struct rdma_cm_id *id, unsigned long timeout_ms); 0189 0190 /** 0191 * rdma_create_qp - Allocate a QP and associate it with the specified RDMA 0192 * identifier. 0193 * 0194 * QPs allocated to an rdma_cm_id will automatically be transitioned by the CMA 0195 * through their states. 0196 */ 0197 int rdma_create_qp(struct rdma_cm_id *id, struct ib_pd *pd, 0198 struct ib_qp_init_attr *qp_init_attr); 0199 0200 /** 0201 * rdma_destroy_qp - Deallocate the QP associated with the specified RDMA 0202 * identifier. 0203 * 0204 * Users must destroy any QP associated with an RDMA identifier before 0205 * destroying the RDMA ID. 0206 */ 0207 void rdma_destroy_qp(struct rdma_cm_id *id); 0208 0209 /** 0210 * rdma_init_qp_attr - Initializes the QP attributes for use in transitioning 0211 * to a specified QP state. 0212 * @id: Communication identifier associated with the QP attributes to 0213 * initialize. 0214 * @qp_attr: On input, specifies the desired QP state. On output, the 0215 * mandatory and desired optional attributes will be set in order to 0216 * modify the QP to the specified state. 0217 * @qp_attr_mask: The QP attribute mask that may be used to transition the 0218 * QP to the specified state. 0219 * 0220 * Users must set the @qp_attr->qp_state to the desired QP state. This call 0221 * will set all required attributes for the given transition, along with 0222 * known optional attributes. Users may override the attributes returned from 0223 * this call before calling ib_modify_qp. 0224 * 0225 * Users that wish to have their QP automatically transitioned through its 0226 * states can associate a QP with the rdma_cm_id by calling rdma_create_qp(). 0227 */ 0228 int rdma_init_qp_attr(struct rdma_cm_id *id, struct ib_qp_attr *qp_attr, 0229 int *qp_attr_mask); 0230 0231 int rdma_connect(struct rdma_cm_id *id, struct rdma_conn_param *conn_param); 0232 int rdma_connect_locked(struct rdma_cm_id *id, 0233 struct rdma_conn_param *conn_param); 0234 0235 int rdma_connect_ece(struct rdma_cm_id *id, struct rdma_conn_param *conn_param, 0236 struct rdma_ucm_ece *ece); 0237 0238 /** 0239 * rdma_listen - This function is called by the passive side to 0240 * listen for incoming connection requests. 0241 * 0242 * Users must have bound the rdma_cm_id to a local address by calling 0243 * rdma_bind_addr before calling this routine. 0244 */ 0245 int rdma_listen(struct rdma_cm_id *id, int backlog); 0246 0247 int rdma_accept(struct rdma_cm_id *id, struct rdma_conn_param *conn_param); 0248 0249 void rdma_lock_handler(struct rdma_cm_id *id); 0250 void rdma_unlock_handler(struct rdma_cm_id *id); 0251 int rdma_accept_ece(struct rdma_cm_id *id, struct rdma_conn_param *conn_param, 0252 struct rdma_ucm_ece *ece); 0253 0254 /** 0255 * rdma_notify - Notifies the RDMA CM of an asynchronous event that has 0256 * occurred on the connection. 0257 * @id: Connection identifier to transition to established. 0258 * @event: Asynchronous event. 0259 * 0260 * This routine should be invoked by users to notify the CM of relevant 0261 * communication events. Events that should be reported to the CM and 0262 * when to report them are: 0263 * 0264 * IB_EVENT_COMM_EST - Used when a message is received on a connected 0265 * QP before an RTU has been received. 0266 */ 0267 int rdma_notify(struct rdma_cm_id *id, enum ib_event_type event); 0268 0269 /** 0270 * rdma_reject - Called to reject a connection request or response. 0271 */ 0272 int rdma_reject(struct rdma_cm_id *id, const void *private_data, 0273 u8 private_data_len, u8 reason); 0274 0275 /** 0276 * rdma_disconnect - This function disconnects the associated QP and 0277 * transitions it into the error state. 0278 */ 0279 int rdma_disconnect(struct rdma_cm_id *id); 0280 0281 /** 0282 * rdma_join_multicast - Join the multicast group specified by the given 0283 * address. 0284 * @id: Communication identifier associated with the request. 0285 * @addr: Multicast address identifying the group to join. 0286 * @join_state: Multicast JoinState bitmap requested by port. 0287 * Bitmap is based on IB_SA_MCMEMBER_REC_JOIN_STATE bits. 0288 * @context: User-defined context associated with the join request, returned 0289 * to the user through the private_data pointer in multicast events. 0290 */ 0291 int rdma_join_multicast(struct rdma_cm_id *id, struct sockaddr *addr, 0292 u8 join_state, void *context); 0293 0294 /** 0295 * rdma_leave_multicast - Leave the multicast group specified by the given 0296 * address. 0297 */ 0298 void rdma_leave_multicast(struct rdma_cm_id *id, struct sockaddr *addr); 0299 0300 /** 0301 * rdma_set_service_type - Set the type of service associated with a 0302 * connection identifier. 0303 * @id: Communication identifier to associated with service type. 0304 * @tos: Type of service. 0305 * 0306 * The type of service is interpretted as a differentiated service 0307 * field (RFC 2474). The service type should be specified before 0308 * performing route resolution, as existing communication on the 0309 * connection identifier may be unaffected. The type of service 0310 * requested may not be supported by the network to all destinations. 0311 */ 0312 void rdma_set_service_type(struct rdma_cm_id *id, int tos); 0313 0314 /** 0315 * rdma_set_reuseaddr - Allow the reuse of local addresses when binding 0316 * the rdma_cm_id. 0317 * @id: Communication identifier to configure. 0318 * @reuse: Value indicating if the bound address is reusable. 0319 * 0320 * Reuse must be set before an address is bound to the id. 0321 */ 0322 int rdma_set_reuseaddr(struct rdma_cm_id *id, int reuse); 0323 0324 /** 0325 * rdma_set_afonly - Specify that listens are restricted to the 0326 * bound address family only. 0327 * @id: Communication identifer to configure. 0328 * @afonly: Value indicating if listens are restricted. 0329 * 0330 * Must be set before identifier is in the listening state. 0331 */ 0332 int rdma_set_afonly(struct rdma_cm_id *id, int afonly); 0333 0334 int rdma_set_ack_timeout(struct rdma_cm_id *id, u8 timeout); 0335 0336 int rdma_set_min_rnr_timer(struct rdma_cm_id *id, u8 min_rnr_timer); 0337 /** 0338 * rdma_get_service_id - Return the IB service ID for a specified address. 0339 * @id: Communication identifier associated with the address. 0340 * @addr: Address for the service ID. 0341 */ 0342 __be64 rdma_get_service_id(struct rdma_cm_id *id, struct sockaddr *addr); 0343 0344 /** 0345 * rdma_reject_msg - return a pointer to a reject message string. 0346 * @id: Communication identifier that received the REJECT event. 0347 * @reason: Value returned in the REJECT event status field. 0348 */ 0349 const char *__attribute_const__ rdma_reject_msg(struct rdma_cm_id *id, 0350 int reason); 0351 /** 0352 * rdma_consumer_reject_data - return the consumer reject private data and 0353 * length, if any. 0354 * @id: Communication identifier that received the REJECT event. 0355 * @ev: RDMA CM reject event. 0356 * @data_len: Pointer to the resulting length of the consumer data. 0357 */ 0358 const void *rdma_consumer_reject_data(struct rdma_cm_id *id, 0359 struct rdma_cm_event *ev, u8 *data_len); 0360 0361 /** 0362 * rdma_read_gids - Return the SGID and DGID used for establishing 0363 * connection. This can be used after rdma_resolve_addr() 0364 * on client side. This can be use on new connection 0365 * on server side. This is applicable to IB, RoCE, iWarp. 0366 * If cm_id is not bound yet to the RDMA device, it doesn't 0367 * copy and SGID or DGID to the given pointers. 0368 * @id: Communication identifier whose GIDs are queried. 0369 * @sgid: Pointer to SGID where SGID will be returned. It is optional. 0370 * @dgid: Pointer to DGID where DGID will be returned. It is optional. 0371 * Note: This API should not be used by any new ULPs or new code. 0372 * Instead, users interested in querying GIDs should refer to path record 0373 * of the rdma_cm_id to query the GIDs. 0374 * This API is provided for compatibility for existing users. 0375 */ 0376 0377 void rdma_read_gids(struct rdma_cm_id *cm_id, union ib_gid *sgid, 0378 union ib_gid *dgid); 0379 0380 struct iw_cm_id *rdma_iw_cm_id(struct rdma_cm_id *cm_id); 0381 struct rdma_cm_id *rdma_res_to_id(struct rdma_restrack_entry *res); 0382 0383 #endif /* RDMA_CM_H */
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.1.0 LXR engine. The LXR team |
![]() ![]() |