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