1 /* 2 * Copyright (c) 2004, 2005 Intel Corporation. All rights reserved. 3 * Copyright (c) 2004 Topspin Corporation. All rights reserved. 4 * Copyright (c) 2004 Voltaire Corporation. All rights reserved. 5 * Copyright (c) 2005 Sun Microsystems, Inc. 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 * OpenIB.org 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 * $Id: ib_cm.h 2730 2005-06-28 16:43:03Z sean.hefty $ 36 */ 37 #if !defined(IB_CM_H) 38 #define IB_CM_H 39 40 #include <rdma/ib_mad.h> 41 #include <rdma/ib_sa.h> 42 43 enum ib_cm_state { 44 IB_CM_IDLE, 45 IB_CM_LISTEN, 46 IB_CM_REQ_SENT, 47 IB_CM_REQ_RCVD, 48 IB_CM_MRA_REQ_SENT, 49 IB_CM_MRA_REQ_RCVD, 50 IB_CM_REP_SENT, 51 IB_CM_REP_RCVD, 52 IB_CM_MRA_REP_SENT, 53 IB_CM_MRA_REP_RCVD, 54 IB_CM_ESTABLISHED, 55 IB_CM_DREQ_SENT, 56 IB_CM_DREQ_RCVD, 57 IB_CM_TIMEWAIT, 58 IB_CM_SIDR_REQ_SENT, 59 IB_CM_SIDR_REQ_RCVD 60 }; 61 62 enum ib_cm_lap_state { 63 IB_CM_LAP_IDLE, 64 IB_CM_LAP_SENT, 65 IB_CM_LAP_RCVD, 66 IB_CM_MRA_LAP_SENT, 67 IB_CM_MRA_LAP_RCVD, 68 }; 69 70 enum ib_cm_event_type { 71 IB_CM_REQ_ERROR, 72 IB_CM_REQ_RECEIVED, 73 IB_CM_REP_ERROR, 74 IB_CM_REP_RECEIVED, 75 IB_CM_RTU_RECEIVED, 76 IB_CM_USER_ESTABLISHED, 77 IB_CM_DREQ_ERROR, 78 IB_CM_DREQ_RECEIVED, 79 IB_CM_DREP_RECEIVED, 80 IB_CM_TIMEWAIT_EXIT, 81 IB_CM_MRA_RECEIVED, 82 IB_CM_REJ_RECEIVED, 83 IB_CM_LAP_ERROR, 84 IB_CM_LAP_RECEIVED, 85 IB_CM_APR_RECEIVED, 86 IB_CM_SIDR_REQ_ERROR, 87 IB_CM_SIDR_REQ_RECEIVED, 88 IB_CM_SIDR_REP_RECEIVED 89 }; 90 91 enum ib_cm_data_size { 92 IB_CM_REQ_PRIVATE_DATA_SIZE = 92, 93 IB_CM_MRA_PRIVATE_DATA_SIZE = 222, 94 IB_CM_REJ_PRIVATE_DATA_SIZE = 148, 95 IB_CM_REP_PRIVATE_DATA_SIZE = 196, 96 IB_CM_RTU_PRIVATE_DATA_SIZE = 224, 97 IB_CM_DREQ_PRIVATE_DATA_SIZE = 220, 98 IB_CM_DREP_PRIVATE_DATA_SIZE = 224, 99 IB_CM_REJ_ARI_LENGTH = 72, 100 IB_CM_LAP_PRIVATE_DATA_SIZE = 168, 101 IB_CM_APR_PRIVATE_DATA_SIZE = 148, 102 IB_CM_APR_INFO_LENGTH = 72, 103 IB_CM_SIDR_REQ_PRIVATE_DATA_SIZE = 216, 104 IB_CM_SIDR_REP_PRIVATE_DATA_SIZE = 136, 105 IB_CM_SIDR_REP_INFO_LENGTH = 72 106 }; 107 108 struct ib_cm_id; 109 110 struct ib_cm_req_event_param { 111 struct ib_cm_id *listen_id; 112 u8 port; 113 114 struct ib_sa_path_rec *primary_path; 115 struct ib_sa_path_rec *alternate_path; 116 117 __be64 remote_ca_guid; 118 u32 remote_qkey; 119 u32 remote_qpn; 120 enum ib_qp_type qp_type; 121 122 u32 starting_psn; 123 u8 responder_resources; 124 u8 initiator_depth; 125 unsigned int local_cm_response_timeout:5; 126 unsigned int flow_control:1; 127 unsigned int remote_cm_response_timeout:5; 128 unsigned int retry_count:3; 129 unsigned int rnr_retry_count:3; 130 unsigned int srq:1; 131 }; 132 133 struct ib_cm_rep_event_param { 134 __be64 remote_ca_guid; 135 u32 remote_qkey; 136 u32 remote_qpn; 137 u32 starting_psn; 138 u8 responder_resources; 139 u8 initiator_depth; 140 unsigned int target_ack_delay:5; 141 unsigned int failover_accepted:2; 142 unsigned int flow_control:1; 143 unsigned int rnr_retry_count:3; 144 unsigned int srq:1; 145 }; 146 147 enum ib_cm_rej_reason { 148 IB_CM_REJ_NO_QP = 1, 149 IB_CM_REJ_NO_EEC = 2, 150 IB_CM_REJ_NO_RESOURCES = 3, 151 IB_CM_REJ_TIMEOUT = 4, 152 IB_CM_REJ_UNSUPPORTED = 5, 153 IB_CM_REJ_INVALID_COMM_ID = 6, 154 IB_CM_REJ_INVALID_COMM_INSTANCE = 7, 155 IB_CM_REJ_INVALID_SERVICE_ID = 8, 156 IB_CM_REJ_INVALID_TRANSPORT_TYPE = 9, 157 IB_CM_REJ_STALE_CONN = 10, 158 IB_CM_REJ_RDC_NOT_EXIST = 11, 159 IB_CM_REJ_INVALID_GID = 12, 160 IB_CM_REJ_INVALID_LID = 13, 161 IB_CM_REJ_INVALID_SL = 14, 162 IB_CM_REJ_INVALID_TRAFFIC_CLASS = 15, 163 IB_CM_REJ_INVALID_HOP_LIMIT = 16, 164 IB_CM_REJ_INVALID_PACKET_RATE = 17, 165 IB_CM_REJ_INVALID_ALT_GID = 18, 166 IB_CM_REJ_INVALID_ALT_LID = 19, 167 IB_CM_REJ_INVALID_ALT_SL = 20, 168 IB_CM_REJ_INVALID_ALT_TRAFFIC_CLASS = 21, 169 IB_CM_REJ_INVALID_ALT_HOP_LIMIT = 22, 170 IB_CM_REJ_INVALID_ALT_PACKET_RATE = 23, 171 IB_CM_REJ_PORT_CM_REDIRECT = 24, 172 IB_CM_REJ_PORT_REDIRECT = 25, 173 IB_CM_REJ_INVALID_MTU = 26, 174 IB_CM_REJ_INSUFFICIENT_RESP_RESOURCES = 27, 175 IB_CM_REJ_CONSUMER_DEFINED = 28, 176 IB_CM_REJ_INVALID_RNR_RETRY = 29, 177 IB_CM_REJ_DUPLICATE_LOCAL_COMM_ID = 30, 178 IB_CM_REJ_INVALID_CLASS_VERSION = 31, 179 IB_CM_REJ_INVALID_FLOW_LABEL = 32, 180 IB_CM_REJ_INVALID_ALT_FLOW_LABEL = 33 181 }; 182 183 struct ib_cm_rej_event_param { 184 enum ib_cm_rej_reason reason; 185 void *ari; 186 u8 ari_length; 187 }; 188 189 struct ib_cm_mra_event_param { 190 u8 service_timeout; 191 }; 192 193 struct ib_cm_lap_event_param { 194 struct ib_sa_path_rec *alternate_path; 195 }; 196 197 enum ib_cm_apr_status { 198 IB_CM_APR_SUCCESS, 199 IB_CM_APR_INVALID_COMM_ID, 200 IB_CM_APR_UNSUPPORTED, 201 IB_CM_APR_REJECT, 202 IB_CM_APR_REDIRECT, 203 IB_CM_APR_IS_CURRENT, 204 IB_CM_APR_INVALID_QPN_EECN, 205 IB_CM_APR_INVALID_LID, 206 IB_CM_APR_INVALID_GID, 207 IB_CM_APR_INVALID_FLOW_LABEL, 208 IB_CM_APR_INVALID_TCLASS, 209 IB_CM_APR_INVALID_HOP_LIMIT, 210 IB_CM_APR_INVALID_PACKET_RATE, 211 IB_CM_APR_INVALID_SL 212 }; 213 214 struct ib_cm_apr_event_param { 215 enum ib_cm_apr_status ap_status; 216 void *apr_info; 217 u8 info_len; 218 }; 219 220 struct ib_cm_sidr_req_event_param { 221 struct ib_cm_id *listen_id; 222 u8 port; 223 u16 pkey; 224 }; 225 226 enum ib_cm_sidr_status { 227 IB_SIDR_SUCCESS, 228 IB_SIDR_UNSUPPORTED, 229 IB_SIDR_REJECT, 230 IB_SIDR_NO_QP, 231 IB_SIDR_REDIRECT, 232 IB_SIDR_UNSUPPORTED_VERSION 233 }; 234 235 struct ib_cm_sidr_rep_event_param { 236 enum ib_cm_sidr_status status; 237 u32 qkey; 238 u32 qpn; 239 void *info; 240 u8 info_len; 241 242 }; 243 244 struct ib_cm_event { 245 enum ib_cm_event_type event; 246 union { 247 struct ib_cm_req_event_param req_rcvd; 248 struct ib_cm_rep_event_param rep_rcvd; 249 /* No data for RTU received events. */ 250 struct ib_cm_rej_event_param rej_rcvd; 251 struct ib_cm_mra_event_param mra_rcvd; 252 struct ib_cm_lap_event_param lap_rcvd; 253 struct ib_cm_apr_event_param apr_rcvd; 254 /* No data for DREQ/DREP received events. */ 255 struct ib_cm_sidr_req_event_param sidr_req_rcvd; 256 struct ib_cm_sidr_rep_event_param sidr_rep_rcvd; 257 enum ib_wc_status send_status; 258 } param; 259 260 void *private_data; 261 }; 262 263 /** 264 * ib_cm_handler - User-defined callback to process communication events. 265 * @cm_id: Communication identifier associated with the reported event. 266 * @event: Information about the communication event. 267 * 268 * IB_CM_REQ_RECEIVED and IB_CM_SIDR_REQ_RECEIVED communication events 269 * generated as a result of listen requests result in the allocation of a 270 * new @cm_id. The new @cm_id is returned to the user through this callback. 271 * Clients are responsible for destroying the new @cm_id. For peer-to-peer 272 * IB_CM_REQ_RECEIVED and all other events, the returned @cm_id corresponds 273 * to a user's existing communication identifier. 274 * 275 * Users may not call ib_destroy_cm_id while in the context of this callback; 276 * however, returning a non-zero value instructs the communication manager to 277 * destroy the @cm_id after the callback completes. 278 */ 279 typedef int (*ib_cm_handler)(struct ib_cm_id *cm_id, 280 struct ib_cm_event *event); 281 282 struct ib_cm_id { 283 ib_cm_handler cm_handler; 284 void *context; 285 struct ib_device *device; 286 __be64 service_id; 287 __be64 service_mask; 288 enum ib_cm_state state; /* internal CM/debug use */ 289 enum ib_cm_lap_state lap_state; /* internal CM/debug use */ 290 __be32 local_id; 291 __be32 remote_id; 292 u32 remote_cm_qpn; /* 1 unless redirected */ 293 }; 294 295 /** 296 * ib_create_cm_id - Allocate a communication identifier. 297 * @device: Device associated with the cm_id. All related communication will 298 * be associated with the specified device. 299 * @cm_handler: Callback invoked to notify the user of CM events. 300 * @context: User specified context associated with the communication 301 * identifier. 302 * 303 * Communication identifiers are used to track connection states, service 304 * ID resolution requests, and listen requests. 305 */ 306 struct ib_cm_id *ib_create_cm_id(struct ib_device *device, 307 ib_cm_handler cm_handler, 308 void *context); 309 310 /** 311 * ib_destroy_cm_id - Destroy a connection identifier. 312 * @cm_id: Connection identifier to destroy. 313 * 314 * This call blocks until the connection identifier is destroyed. 315 */ 316 void ib_destroy_cm_id(struct ib_cm_id *cm_id); 317 318 #define IB_SERVICE_ID_AGN_MASK __constant_cpu_to_be64(0xFF00000000000000ULL) 319 #define IB_CM_ASSIGN_SERVICE_ID __constant_cpu_to_be64(0x0200000000000000ULL) 320 321 /** 322 * ib_cm_listen - Initiates listening on the specified service ID for 323 * connection and service ID resolution requests. 324 * @cm_id: Connection identifier associated with the listen request. 325 * @service_id: Service identifier matched against incoming connection 326 * and service ID resolution requests. The service ID should be specified 327 * network-byte order. If set to IB_CM_ASSIGN_SERVICE_ID, the CM will 328 * assign a service ID to the caller. 329 * @service_mask: Mask applied to service ID used to listen across a 330 * range of service IDs. If set to 0, the service ID is matched 331 * exactly. This parameter is ignored if %service_id is set to 332 * IB_CM_ASSIGN_SERVICE_ID. 333 */ 334 int ib_cm_listen(struct ib_cm_id *cm_id, 335 __be64 service_id, 336 __be64 service_mask); 337 338 struct ib_cm_req_param { 339 struct ib_sa_path_rec *primary_path; 340 struct ib_sa_path_rec *alternate_path; 341 __be64 service_id; 342 u32 qp_num; 343 enum ib_qp_type qp_type; 344 u32 starting_psn; 345 const void *private_data; 346 u8 private_data_len; 347 u8 peer_to_peer; 348 u8 responder_resources; 349 u8 initiator_depth; 350 u8 remote_cm_response_timeout; 351 u8 flow_control; 352 u8 local_cm_response_timeout; 353 u8 retry_count; 354 u8 rnr_retry_count; 355 u8 max_cm_retries; 356 u8 srq; 357 }; 358 359 /** 360 * ib_send_cm_req - Sends a connection request to the remote node. 361 * @cm_id: Connection identifier that will be associated with the 362 * connection request. 363 * @param: Connection request information needed to establish the 364 * connection. 365 */ 366 int ib_send_cm_req(struct ib_cm_id *cm_id, 367 struct ib_cm_req_param *param); 368 369 struct ib_cm_rep_param { 370 u32 qp_num; 371 u32 starting_psn; 372 const void *private_data; 373 u8 private_data_len; 374 u8 responder_resources; 375 u8 initiator_depth; 376 u8 target_ack_delay; 377 u8 failover_accepted; 378 u8 flow_control; 379 u8 rnr_retry_count; 380 u8 srq; 381 }; 382 383 /** 384 * ib_send_cm_rep - Sends a connection reply in response to a connection 385 * request. 386 * @cm_id: Connection identifier that will be associated with the 387 * connection request. 388 * @param: Connection reply information needed to establish the 389 * connection. 390 */ 391 int ib_send_cm_rep(struct ib_cm_id *cm_id, 392 struct ib_cm_rep_param *param); 393 394 /** 395 * ib_send_cm_rtu - Sends a connection ready to use message in response 396 * to a connection reply message. 397 * @cm_id: Connection identifier associated with the connection request. 398 * @private_data: Optional user-defined private data sent with the 399 * ready to use message. 400 * @private_data_len: Size of the private data buffer, in bytes. 401 */ 402 int ib_send_cm_rtu(struct ib_cm_id *cm_id, 403 const void *private_data, 404 u8 private_data_len); 405 406 /** 407 * ib_send_cm_dreq - Sends a disconnection request for an existing 408 * connection. 409 * @cm_id: Connection identifier associated with the connection being 410 * released. 411 * @private_data: Optional user-defined private data sent with the 412 * disconnection request message. 413 * @private_data_len: Size of the private data buffer, in bytes. 414 */ 415 int ib_send_cm_dreq(struct ib_cm_id *cm_id, 416 const void *private_data, 417 u8 private_data_len); 418 419 /** 420 * ib_send_cm_drep - Sends a disconnection reply to a disconnection request. 421 * @cm_id: Connection identifier associated with the connection being 422 * released. 423 * @private_data: Optional user-defined private data sent with the 424 * disconnection reply message. 425 * @private_data_len: Size of the private data buffer, in bytes. 426 * 427 * If the cm_id is in the correct state, the CM will transition the connection 428 * to the timewait state, even if an error occurs sending the DREP message. 429 */ 430 int ib_send_cm_drep(struct ib_cm_id *cm_id, 431 const void *private_data, 432 u8 private_data_len); 433 434 /** 435 * ib_cm_establish - Forces a connection state to established. 436 * @cm_id: Connection identifier to transition to established. 437 * 438 * This routine should be invoked by users who receive messages on a 439 * connected QP before an RTU has been received. 440 */ 441 int ib_cm_establish(struct ib_cm_id *cm_id); 442 443 /** 444 * ib_send_cm_rej - Sends a connection rejection message to the 445 * remote node. 446 * @cm_id: Connection identifier associated with the connection being 447 * rejected. 448 * @reason: Reason for the connection request rejection. 449 * @ari: Optional additional rejection information. 450 * @ari_length: Size of the additional rejection information, in bytes. 451 * @private_data: Optional user-defined private data sent with the 452 * rejection message. 453 * @private_data_len: Size of the private data buffer, in bytes. 454 */ 455 int ib_send_cm_rej(struct ib_cm_id *cm_id, 456 enum ib_cm_rej_reason reason, 457 void *ari, 458 u8 ari_length, 459 const void *private_data, 460 u8 private_data_len); 461 462 /** 463 * ib_send_cm_mra - Sends a message receipt acknowledgement to a connection 464 * message. 465 * @cm_id: Connection identifier associated with the connection message. 466 * @service_timeout: The maximum time required for the sender to reply to 467 * to the connection message. 468 * @private_data: Optional user-defined private data sent with the 469 * message receipt acknowledgement. 470 * @private_data_len: Size of the private data buffer, in bytes. 471 */ 472 int ib_send_cm_mra(struct ib_cm_id *cm_id, 473 u8 service_timeout, 474 const void *private_data, 475 u8 private_data_len); 476 477 /** 478 * ib_send_cm_lap - Sends a load alternate path request. 479 * @cm_id: Connection identifier associated with the load alternate path 480 * message. 481 * @alternate_path: A path record that identifies the alternate path to 482 * load. 483 * @private_data: Optional user-defined private data sent with the 484 * load alternate path message. 485 * @private_data_len: Size of the private data buffer, in bytes. 486 */ 487 int ib_send_cm_lap(struct ib_cm_id *cm_id, 488 struct ib_sa_path_rec *alternate_path, 489 const void *private_data, 490 u8 private_data_len); 491 492 /** 493 * ib_cm_init_qp_attr - Initializes the QP attributes for use in transitioning 494 * to a specified QP state. 495 * @cm_id: Communication identifier associated with the QP attributes to 496 * initialize. 497 * @qp_attr: On input, specifies the desired QP state. On output, the 498 * mandatory and desired optional attributes will be set in order to 499 * modify the QP to the specified state. 500 * @qp_attr_mask: The QP attribute mask that may be used to transition the 501 * QP to the specified state. 502 * 503 * Users must set the @qp_attr->qp_state to the desired QP state. This call 504 * will set all required attributes for the given transition, along with 505 * known optional attributes. Users may override the attributes returned from 506 * this call before calling ib_modify_qp. 507 */ 508 int ib_cm_init_qp_attr(struct ib_cm_id *cm_id, 509 struct ib_qp_attr *qp_attr, 510 int *qp_attr_mask); 511 512 /** 513 * ib_send_cm_apr - Sends an alternate path response message in response to 514 * a load alternate path request. 515 * @cm_id: Connection identifier associated with the alternate path response. 516 * @status: Reply status sent with the alternate path response. 517 * @info: Optional additional information sent with the alternate path 518 * response. 519 * @info_length: Size of the additional information, in bytes. 520 * @private_data: Optional user-defined private data sent with the 521 * alternate path response message. 522 * @private_data_len: Size of the private data buffer, in bytes. 523 */ 524 int ib_send_cm_apr(struct ib_cm_id *cm_id, 525 enum ib_cm_apr_status status, 526 void *info, 527 u8 info_length, 528 const void *private_data, 529 u8 private_data_len); 530 531 struct ib_cm_sidr_req_param { 532 struct ib_sa_path_rec *path; 533 __be64 service_id; 534 int timeout_ms; 535 const void *private_data; 536 u8 private_data_len; 537 u8 max_cm_retries; 538 u16 pkey; 539 }; 540 541 /** 542 * ib_send_cm_sidr_req - Sends a service ID resolution request to the 543 * remote node. 544 * @cm_id: Communication identifier that will be associated with the 545 * service ID resolution request. 546 * @param: Service ID resolution request information. 547 */ 548 int ib_send_cm_sidr_req(struct ib_cm_id *cm_id, 549 struct ib_cm_sidr_req_param *param); 550 551 struct ib_cm_sidr_rep_param { 552 u32 qp_num; 553 u32 qkey; 554 enum ib_cm_sidr_status status; 555 const void *info; 556 u8 info_length; 557 const void *private_data; 558 u8 private_data_len; 559 }; 560 561 /** 562 * ib_send_cm_sidr_rep - Sends a service ID resolution request to the 563 * remote node. 564 * @cm_id: Communication identifier associated with the received service ID 565 * resolution request. 566 * @param: Service ID resolution reply information. 567 */ 568 int ib_send_cm_sidr_rep(struct ib_cm_id *cm_id, 569 struct ib_cm_sidr_rep_param *param); 570 571 #endif /* IB_CM_H */ 572