1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License, Version 1.0 only 6 * (the "License"). You may not use this file except in compliance 7 * with the License. 8 * 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 * or http://www.opensolaris.org/os/licensing. 11 * See the License for the specific language governing permissions 12 * and limitations under the License. 13 * 14 * When distributing Covered Code, include this CDDL HEADER in each 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 * If applicable, add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END 21 */ 22 /* 23 * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 */ 26 27 #ifndef _SYS_IB_MGT_IBCM_IBCM_IMPL_H 28 #define _SYS_IB_MGT_IBCM_IBCM_IMPL_H 29 30 #pragma ident "%Z%%M% %I% %E% SMI" 31 32 /* 33 * ibcm_impl.h 34 * 35 * This file contains all of the internal data structures and 36 * definitions for IBCM. 37 * 38 * The general state transition processing of CM is achieved by the 39 * following callgraph: 40 * 41 * CM INIT : Register for hca attach and detach callbacks, and other asyncs 42 * 43 * On new HCA attach: Register with IBMF on all ports of upcoming HCA 44 * Specify CM callback and callback "per HCA arg" 45 * Register with SA, allocate AVL trees etc. 46 * 47 * IBMF Callback 48 * Validate combination of method and attribute Id in the generic MAD hdr 49 * -> Call CM Connection state transition function based on attribute ID 50 * Create/lookup/delete CM state structure and save it into avl tree 51 * Handle duplicate messages and MRA to adjust timers etc. 52 * Handle stale connections 53 * Allocate reply MADs 54 * -> Call CM QP/EEC state transition function based on CM message 55 * Change QP/EEC state (to enable recvQ posting by client) 56 * Call Client/Server handler callback function 57 * Modify QP/EEC attributes 58 * Optionally fill up some fields of response MAD 59 * Post reply MADs 60 * Store reply MADs and reply MAD address, if necessary 61 * Initialize timeouts for the message 62 * Change CM state 63 * Deallocate reply MADs 64 * 65 * NOTES: 66 * o There are *NO* explicit CM allocation and deallocation routines for 67 * CM MADs and state data structures 68 * o CM timeouts are scheduled using timeout(9f), and cancelled using 69 * untimeout(9f) 70 * o svc_id allocation scheme 71 * A new counter for svcid is maintained in ibcm_hca_info_t 72 * which is used to allocate svcid. The svcids are incremented 73 * sequentially and allocated (with wrap around on overflow) with 74 * these considerations: 75 * The WellKnown service id's and locally allocated svcid's 76 * could be maintained in separate lists, thus allowing the 77 * lists to be kept apart and sorted easily. 78 * The insertions are done at the end of the list 79 * o reqid allocation scheme 80 * The list is a sorted one (as reqid's are allocated sequentially). 81 * If there is a code required for wrap around, it would search for 82 * a reqid from the head of the list. 83 * The insertions are always done at the end of the lists 84 * o XXX svc_id allocation scheme and req_id allocation scheme will 85 * be revisited. 86 */ 87 88 #include <sys/sysmacros.h> 89 #include <sys/systm.h> 90 #include <sys/kmem.h> 91 #include <sys/modctl.h> 92 #include <sys/avl.h> 93 #include <sys/taskq.h> 94 #include <sys/vmem.h> 95 #include <sys/note.h> 96 #include <sys/t_lock.h> 97 98 #include <sys/ib/ibtl/ibvti.h> 99 #include <sys/ib/ibtl/impl/ibtl_cm.h> 100 #include <sys/ib/ibtl/impl/ibtl_util.h> 101 #include <sys/ib/mgt/ibmf/ibmf.h> 102 #include <sys/ib/mgt/ibcm/ibcm_trace.h> 103 104 #ifdef __cplusplus 105 extern "C" { 106 #endif 107 108 _NOTE(SCHEME_PROTECTS_DATA("Private", sa_service_record_s)) 109 _NOTE(SCHEME_PROTECTS_DATA("Exclusive access to ibmf msg buf based on state", 110 ib_mad_hdr_t)) 111 _NOTE(SCHEME_PROTECTS_DATA("Exclusive access to ibmf msg buf based on state", 112 _ibmf_msg)) 113 114 /* 115 * Defines for all CM state machine states, as defined in 116 * section 12.9.7. IBCM_REJ_SENT is a state not defined in 117 * the spec and is added for implementation purposes. 118 */ 119 typedef enum ibcm_conn_state_e { 120 /* Initial states */ 121 IBCM_STATE_IDLE = 0, 122 IBCM_STATE_LISTEN, 123 124 /* States during connection establishment */ 125 IBCM_STATE_REQ_SENT, 126 IBCM_STATE_REQ_RCVD, 127 IBCM_STATE_REP_SENT, 128 IBCM_STATE_REP_RCVD, 129 IBCM_STATE_REP_WAIT, 130 IBCM_STATE_MRA_SENT, 131 IBCM_STATE_MRA_REP_SENT, 132 IBCM_STATE_MRA_REP_RCVD, 133 134 /* States during connection establishment failures */ 135 IBCM_STATE_TIMED_OUT, 136 IBCM_STATE_ABORTED, 137 IBCM_STATE_REJ_SENT, 138 139 /* Established state */ 140 IBCM_STATE_TRANSIENT_ESTABLISHED, 141 IBCM_STATE_ESTABLISHED, 142 143 /* States during connection teardown */ 144 IBCM_STATE_TRANSIENT_DREQ_SENT, 145 IBCM_STATE_DREQ_SENT, 146 IBCM_STATE_DREQ_RCVD, 147 IBCM_STATE_DREP_RCVD, 148 IBCM_STATE_TIMEWAIT, 149 150 /* states for UD side of things */ 151 IBCM_STATE_SIDR_REQ_SENT, 152 IBCM_STATE_SIDR_REQ_RCVD, 153 IBCM_STATE_SIDR_REP_SENT, 154 IBCM_STATE_SIDR_REP_RCVD, 155 156 /* states common to RC and UD, during state resource deletion */ 157 IBCM_STATE_DELETE 158 } ibcm_conn_state_t; 159 160 /* Defines the AP states for LAP/APR */ 161 typedef enum ibcm_ap_state_e { 162 IBCM_AP_STATE_IDLE = 0x0, 163 IBCM_AP_STATE_LAP_SENT, 164 IBCM_AP_STATE_LAP_RCVD, 165 IBCM_AP_STATE_APR_RCVD, 166 IBCM_AP_STATE_MRA_LAP_RCVD, 167 IBCM_AP_STATE_MRA_LAP_SENT, 168 IBCM_AP_STATE_TIMED_OUT 169 } ibcm_ap_state_t; 170 171 /* 172 * Defines for the CM event types/MAD attribute IDs 173 */ 174 typedef enum ibcm_event_type_e { 175 IBCM_INCOMING_REQ = 0x0, 176 IBCM_INCOMING_MRA = 0x1, 177 IBCM_INCOMING_REJ = 0x2, 178 IBCM_INCOMING_REP = 0x3, 179 IBCM_INCOMING_RTU = 0x4, 180 IBCM_INCOMING_DREQ = 0x5, 181 IBCM_INCOMING_DREP = 0x6, 182 IBCM_INCOMING_SIDR_REQ = 0x7, 183 IBCM_INCOMING_SIDR_REP = 0x8, 184 IBCM_INCOMING_LAP = 0x9, 185 IBCM_INCOMING_APR = 0xA, 186 IBCM_OUTGOING_REQ = 0xB, /* REQ Sent on active CM side */ 187 IBCM_INCOMING_REQ_STALE = 0xC, /* lookup by remote HCA and */ 188 /* remote comid */ 189 IBCM_INCOMING_REP_STALE = 0xD, /* lookup by passive HCA and QPN */ 190 IBCM_INCOMING_REJ_RCOMID = 0xE /* lookup by remote com id */ 191 } ibcm_event_type_t; 192 193 /* 194 * IBMF calls back into CM on only the first 11 events defined in 195 * ibcm_event_type_t. CM has pre-defined functions for these 11 events 196 * 197 */ 198 #define IBCM_MAX_EVENTS 11 199 200 /* 201 * CM message attribute IDs begin at this "base ID". The first 11 event types 202 * in ibcm_event_type_t are CM protocol messages that are posted to IBMF by 203 * adding the "base_id" to the respective event type value. By subtracting 204 * the "base_id" in IBMF callback in CM MAD, the message type is gotten back 205 */ 206 #define IBCM_ATTR_BASE_ID 0x10 207 208 #define IBCM_MAX_RETRY_CNT 15 209 #define IBCM_ATTRID_FIELD_SIZE 4 210 #define IBCM_TRANID_PRIV_FIELD_SIZE 28 211 212 #define IBCM_RNR_RETRY_CNT_MASK 0x7 /* 3 bits */ 213 #define IBCM_MAX_RNR_RETRY_CNT 7 214 215 #define IBCM_INITIAL_COMID 1 216 #define IBCM_INITIAL_REQID 1 217 #define IBCM_INITIAL_SID 1 218 219 /* 220 * Maximum number of com ids / req ids that can be active at any given time 221 * MUST ENSURE THAT (INITIAL ID + MAX IDS -1), for any of the IDs does not 222 * exceed the max 32 bit 223 */ 224 225 /* An hca can have max of 2^24 -2 RC connections */ 226 #define IBCM_MAX_COMIDS (0x01000000 - 2) 227 #define IBCM_MAX_REQIDS 0xFFFFFFFF 228 #define IBCM_MAX_LOCAL_SIDS 0xFFFFFFFF 229 230 typedef uint32_t ib_com_id_t; /* CM Communication ID */ 231 232 /* 233 * Defines the CM Mode of operation for a connection 234 */ 235 typedef enum ibcm_mode_e { 236 IBCM_ACTIVE_MODE = 1, /* Active side CM */ 237 IBCM_PASSIVE_MODE = 2 /* Passive side CM */ 238 } ibcm_mode_t; 239 240 241 /* different IBCM return values */ 242 typedef enum ibcm_status_e { 243 IBCM_SUCCESS = 0, /* good status */ 244 IBCM_LOOKUP_EXISTS, /* statep lookup found existing entry */ 245 IBCM_LOOKUP_NEW, /* lookup created new statep entry */ 246 IBCM_LOOKUP_FAIL, /* lookup found no statep entry */ 247 IBCM_SEND_REJ, /* CM QP state change sent REJ msg */ 248 IBCM_SEND_REP, /* CM QP state change sent REP msg */ 249 IBCM_SEND_RTU, /* CM QP state change sent RTU msg */ 250 IBCM_SEND_APR, /* CM to send APR MAD as response */ 251 IBCM_SEND_SIDR_REP, /* client's UD handler returned this */ 252 IBCM_DEFER, /* client's handler returned this */ 253 IBCM_FAILURE /* generic IBCM failure */ 254 } ibcm_status_t; 255 256 /* 257 * Struct definition for addressing information that CM maintains for 258 * each of the incoming MADs 259 */ 260 typedef struct ibcm_mad_addr { 261 ibmf_global_addr_info_t grh_hdr; /* GRH related fields of MAD */ 262 ibmf_addr_info_t rcvd_addr; /* Outgoing/Incoming MAD addr */ 263 ibmf_handle_t ibmf_hdl; /* IBMF handle */ 264 boolean_t grh_exists; /* TRUE if grh exists */ 265 uint8_t port_num; 266 struct ibcm_qp_list_s *cm_qp_entry; /* IBMF hdl on which MAD rcvd */ 267 /* or on which MAD shall be */ 268 /* sent out */ 269 } ibcm_mad_addr_t; 270 271 _NOTE(READ_ONLY_DATA(ibcm_mad_addr)) 272 273 #define IBCM_MAD_SIZE 0x100 /* size of MAD */ 274 #define IBCM_MAD_HDR_SIZE sizeof (ib_mad_hdr_t) /* size of MAD HDR */ 275 #define IBCM_MSG_SIZE IBCM_MAD_SIZE-IBCM_MAD_HDR_SIZE 276 277 typedef enum ibcm_abort_flag_e { 278 IBCM_ABORT_INIT = 0, /* no abort flag is set */ 279 IBCM_ABORT_CLIENT = 1, /* client requested connection abort */ 280 IBCM_ABORT_REJ = 2 /* REJ received with timeout reason */ 281 } ibcm_abort_flag_t; 282 283 typedef enum ibcm_isync_e { 284 IBCM_BLOCK = 0, /* Block cm operation */ 285 IBCM_UNBLOCK = 1, /* Unblock cm operation */ 286 IBCM_FAIL = 2 /* fail cm operation */ 287 } ibcm_isync_t; 288 289 /* 290 * Define a connection state structure, used by the IBTF CM 291 * to maintain state about connected QPs. 292 * 293 * mode : CM connection mode active/passive 294 * state : CM connection state 295 * ap_state : CM AP Internal state to manage LAP/APR state machine 296 * state_mutex : lock for this structure 297 * channel : Channel associated with this RC state structure 298 * ref_cnt : Number of active threads that may reference this 299 * state structure 300 * svcid : Service ID 301 * cm_handler : Client handler callback address 302 * stored_reply_addr : Address for replying using the stored mad 303 * hcap : A pointer to the HCA's entry 304 * stored_msg : Stores the response REP/REJ/RTU MAD 305 * mra_msg : Stores the response MRA MAD 306 * dreq_msg : Stores the DREQ MAD 307 * drep_msg : Stores the DREP MAD 308 * lapr_msg : Stores the LAP/APR MAD 309 * detect duplicate LAP messages 310 * local_comid : Local communication id 311 * local_hca_guid : Local HCA GUID 312 * local_qpn : Local QPN 313 * 314 * remote_comid : Remote communication id 315 * remote_hca_guid : Remote HCA GUID 316 * remote_qpn : Remote QPN 317 * 318 * timerid : Timer id for the timeout either for re-sending the 319 * stored mad or deleting the stored mad 320 * Ex: A REJ/RTU response for an incoming REP 321 * A REP response to an incoming REQ 322 * An outgoing REQ on active connection side 323 * timer_value : Time for any of the above timers in HZ 324 * pkt_life_time : pkt life time from source to destination 325 * remote_ack_delay : Remote hca's ack delay in clock_t 326 * rc_alt_pkt_lt : Life time for new ALT path specified in LAP 327 * stale_clock : clock used to detect stale vs duplicate REQs 328 * timer_stored_state : state of connection for timeout() validation 329 * timer_stored_ap_state: CM ap_state for timeout validation 330 * remaining_retry_count: Remaining count for retries ie., posting stored MADs 331 * max_cm_retries : Max retry count for sending a REQ/REP/DREQ 332 * delete_mra_msg : Set to TRUE for deletion, if MRA re-send in progress 333 * resend_mad : B_TRUE, if REQ/REP/RTU/REJ MAD re-send is in progress 334 * resend_mra_mad : B_TRUE, if a MRA mad re-sens is in progress 335 * cep_retry_cnt : Retry count for CEP. 336 * stale : B_TRUE, if connection has become stale 337 * blocking_done : B_TRUE, if cv_signal been issued to block_client_cv 338 * clnt_hdl : Clnt_hdl passed in ibt_open_channel 339 * return_data : RC return args, valid for blocking 340 * ibt_open_channel 341 * drep_priv_data; : The pointer to client specified outgoing private 342 * data, from close channel API call 343 * drep_priv_data_len : The length of DREP private data that client would 344 * like to be returned from close channel API call 345 * delete_state_data : B_TRUE, if CM decides to delete state data, but 346 * there is some thread that could access state data 347 * 348 * avl_active_link : For inserting this state-data into active AVL tree 349 * avl_passive_link : For inserting this state-data into passive AVL tree 350 * Note : All timer values that are of type "clock_t" below are in usecs 351 */ 352 typedef struct ibcm_state_data_s { 353 /* for AVL tree */ 354 avl_node_t avl_active_link; 355 avl_node_t avl_passive_link; 356 avl_node_t avl_passive_comid_link; 357 358 /* remote stuff */ 359 ib_guid_t remote_hca_guid; 360 ib_com_id_t remote_comid; 361 ib_qpn_t remote_qpn; 362 363 /* local stuff */ 364 ib_com_id_t local_comid; 365 ib_qpn_t local_qpn; 366 ib_guid_t local_hca_guid; 367 368 ibcm_mode_t mode; 369 ibcm_conn_state_t state; 370 ibcm_ap_state_t ap_state; 371 kmutex_t state_mutex; 372 ibt_channel_hdl_t channel; /* save a copy */ 373 374 /* ref_cnt so others cannot delete a statep that may be referenced */ 375 int ref_cnt; 376 377 ib_svc_id_t svcid; 378 ibt_cm_handler_t cm_handler; 379 380 ibcm_mad_addr_t stored_reply_addr; 381 382 struct ibcm_hca_info_s *hcap; 383 384 ibmf_msg_t *stored_msg; 385 ibmf_msg_t *mra_msg; 386 ibmf_msg_t *dreq_msg; 387 ibmf_msg_t *drep_msg; 388 ibmf_msg_t *lapr_msg; 389 390 void *defer_cm_msg; 391 392 /* timeout related stuff */ 393 timeout_id_t timerid; 394 clock_t timer_value; 395 clock_t pkt_life_time; 396 clock_t remote_ack_delay; 397 clock_t rc_alt_pkt_lt; 398 399 hrtime_t stale_clock; 400 401 ibcm_conn_state_t timer_stored_state; 402 ibcm_ap_state_t timer_stored_ap_state; 403 uint8_t remaining_retry_cnt; 404 uint8_t max_cm_retries; 405 406 /* some cep stuff, stored here temporarily during connection est */ 407 uint8_t cep_retry_cnt:3; 408 ibt_srate_t local_srate; 409 ibt_srate_t local_alt_srate; 410 ib_pkey_t pkey; 411 uint8_t prim_port; 412 uint8_t alt_port; 413 uint32_t starting_psn; 414 ib_path_bits_t prim_src_path_bits; 415 ib_path_bits_t alt_src_path_bits; 416 417 boolean_t delete_mra_msg; 418 boolean_t stale; 419 boolean_t delete_state_data; 420 421 boolean_t open_done; 422 boolean_t close_done; 423 boolean_t ap_done; 424 425 uint8_t send_mad_flags; 426 uint8_t close_flow; 427 ibcm_abort_flag_t abort_flag; 428 429 struct ibcm_state_data_s *timeout_next; 430 431 ibcm_conn_state_t timedout_state; 432 433 ibcm_isync_t cep_in_rts; 434 ibcm_isync_t clnt_proceed; 435 ibcm_isync_t close_nocb_state; 436 437 /* Clients' information */ 438 void *state_cm_private; 439 440 /* pointer to service info */ 441 struct ibcm_svc_info_s *state_svc_infop; 442 443 kcondvar_t block_client_cv; 444 kcondvar_t block_mad_cv; 445 446 /* Data for recycle function */ 447 struct ibcm_taskq_recycle_arg_s *recycle_arg; 448 449 /* Return data pointers in various cm api calls */ 450 ibt_rc_returns_t *open_return_data; 451 ibt_ap_returns_t *ap_return_data; 452 uint8_t *close_priv_data; 453 ibt_priv_data_len_t *close_priv_data_len; 454 uint8_t *close_ret_status; 455 456 struct ibcm_conn_trace_s *conn_trace; 457 458 } ibcm_state_data_t; 459 460 _NOTE(MUTEX_PROTECTS_DATA(ibcm_state_data_s::state_mutex, 461 ibcm_state_data_s::{state ref_cnt timer_stored_state timer_value 462 timer_stored_ap_state remaining_retry_cnt clnt_proceed cep_in_rts 463 close_nocb_state block_client_cv block_mad_cv timedout_state cm_handler 464 abort_flag mra_msg})) 465 466 _NOTE(READ_ONLY_DATA(ibcm_state_data_s::{mode channel svcid hcap 467 local_comid local_hca_guid local_qpn remote_comid remote_hca_guid 468 remote_qpn pkt_life_time remote_ack_delay rc_alt_pkt_lt stored_reply_addr 469 stale_clock max_cm_retries cep_retry_cnt local_srate local_alt_srate pkey 470 prim_port alt_port starting_psn state_svc_infop avl_active_link 471 avl_passive_link avl_passive_comid_link defer_cm_msg recycle_arg 472 conn_trace})) 473 474 _NOTE(SCHEME_PROTECTS_DATA("Serailized access by block_client_cv", 475 ibcm_state_data_s::{open_return_data ap_return_data close_priv_data 476 close_priv_data_len close_ret_status})) 477 478 _NOTE(DATA_READABLE_WITHOUT_LOCK(ibcm_state_data_s::{timedout_state 479 cm_handler mra_msg abort_flag})) 480 481 /* 482 * Definitions for send mad flags. Respective bits in send_mad_flags or 483 * ud_send_mad_flags are set to 1, during MAD transmission, and reset in 484 * ibmf send completion callback or on completion of a blocking ibmf mad post. 485 */ 486 #define IBCM_REP_POST_BUSY 1 /* REP post in progress */ 487 #define IBCM_REJ_POST_BUSY 2 /* REJ post in progress */ 488 #define IBCM_RTU_POST_BUSY 4 /* RTU post in progress */ 489 #define IBCM_MRA_POST_BUSY 8 /* MRA post in progress */ 490 #define IBCM_DREP_POST_BUSY 16 /* DREQ post in progress */ 491 #define IBCM_SREP_POST_BUSY 32 /* SIDR REP post in progress */ 492 493 /* MADs that are retransmitted only because of a timeout */ 494 #define IBCM_REQ_POST_BUSY 64 /* REQ post in progress */ 495 496 497 /* Incr/Decr ref_cnt by 1 */ 498 #define IBCM_REF_CNT_INCR(s) (s->ref_cnt++) 499 #define IBCM_REF_CNT_DECR(s) \ 500 if ((--(s->ref_cnt) == 0) && (s->delete_state_data == B_TRUE)) { \ 501 ibcm_add_tlist(s);\ 502 } \ 503 ASSERT(s->ref_cnt >= 0); 504 505 /* 506 * This macro checks if ch_qp/ch_eec handles are both not set for a channel 507 */ 508 #define IBCM_INVALID_CHANNEL(chan) (chan == NULL) 509 510 /* 511 * The next macros are used to get/set the statep from the QP 512 * handles, using the CM private data. These call into IBTL. 513 * The WAIT and RELEASE macros deal with related issues that 514 * require use of the same lock within IBTL. 515 */ 516 #define IBCM_GET_CHAN_PRIVATE(ch, s) \ 517 if ((ch) != NULL) { \ 518 s = ibtl_cm_get_chan_private(ch); \ 519 } else \ 520 s = NULL; 521 522 #define IBCM_SET_CHAN_PRIVATE(ch, s) \ 523 if ((ch) != NULL) { \ 524 ibtl_cm_set_chan_private(ch, (void *)(s)); \ 525 } 526 527 #define IBCM_RELEASE_CHAN_PRIVATE(ch) \ 528 if ((ch) != NULL) { \ 529 ibtl_cm_release_chan_private(ch); \ 530 } 531 532 #define IBCM_WAIT_CHAN_PRIVATE(ch) \ 533 ibtl_cm_wait_chan_private(ch); 534 535 /* In future, if we intend to change it to realtime_timeout, it's easy */ 536 #define IBCM_TIMEOUT(arg1, arg2) timeout(ibcm_timeout_cb, arg1,\ 537 drv_usectohz(arg2)) 538 #define IBCM_UD_TIMEOUT(arg1, arg2) timeout(ibcm_sidr_timeout_cb, arg1,\ 539 drv_usectohz(arg2)) 540 541 /* 542 * Structures & defines for SIDR 543 */ 544 545 /* 546 * Define a connection state structure, used for SIDR REQ and REP 547 * (ibcm_ud_state_data_t - struct for SIDR connection) 548 * 549 * ud_state: CM connection state (See ibcm_conn_state_t) 550 * ud_req_id: Request ID 551 * ud_svcid: Service ID 552 * ud_state_mutex: CM connection state 553 * 554 * ud_max_cm_retries: Max retry count for sending a SIDR REQ 555 * ud_ref_cnt: State ref count for not deleting accidentally 556 * ud_remaining_retry_count: Remaining count for retries ie., posting 557 * stored MADs 558 * ud_cm_handler: Server's handler callback address 559 * 560 * ud_nextp: CM link for IBTF list 561 * ud_hcap: A pointer to the HCA's entry 562 * 563 * ud_timerid: Timer id for the timeout either for re-sending the 564 * stored mad or deleting the stored mad 565 * Ex: A SIDR REP response for an incoming SIDR REQ 566 * An outgoing SIDR REQ on active connection side 567 * ud_timer_value: Time for any of the above timers in HZ 568 * ud_pkt_life_time: pkt life time from source to destination 569 * ud_stored_reply_addr: Address for replying using the stored mad 570 * 571 * ud_sidr_req_lid: SIDR REQ sender's port LID 572 * ud_sidr_req_gid: SIDR REQ sender's port GID 573 * ud_grh_exists: TRUE if GRH exists in the incoming SIDR REQ 574 * 575 * ud_passive_qpn: QPN allocated by server for a SIDR REQ 576 * ud_passive_qpn_qkey: QPN's QKEY allocated by server 577 * 578 * ud_block_client_cv: CV condition variable on which ibt_ud_get_dqpn() waits, 579 * if called in blocking mode. 580 * ud_return_data: UD return args, valid for blocking ibt_ud_get_dqpn 581 * ud_timer_stored_state: State stored for timeout handling 582 * ud_blocking_done : Tells if cv_wait is needed or not. To handle the 583 * case where a cv_signal is received prior to its 584 * cv_wait(). 585 * Note : All timer values that are of type "clock_t" below are in usec 586 */ 587 typedef struct ibcm_ud_state_data_s { 588 kmutex_t ud_state_mutex; 589 ibcm_conn_state_t ud_state; 590 ibcm_mode_t ud_mode; 591 592 int ud_ref_cnt; 593 594 uint32_t ud_req_id; 595 ib_svc_id_t ud_svc_id; 596 597 uint8_t ud_max_cm_retries; 598 uint8_t ud_remaining_retry_cnt; 599 ibt_cm_ud_handler_t ud_cm_handler; 600 601 struct ibcm_ud_state_data_s *ud_nextp; 602 struct ibcm_hca_info_s *ud_hcap; 603 604 /* timeout related stuff */ 605 timeout_id_t ud_timerid; 606 clock_t ud_timer_value; 607 clock_t ud_pkt_life_time; 608 ibcm_mad_addr_t ud_stored_reply_addr; 609 ibmf_msg_t *ud_stored_msg; 610 611 612 /* SIDR REQ side related */ 613 ib_lid_t ud_sidr_req_lid; 614 ib_gid_t ud_sidr_req_gid; 615 boolean_t ud_grh_exists; 616 617 /* Stored values on server/SIDR REP side for re-transmits */ 618 ib_qpn_t ud_passive_qpn; 619 ib_qkey_t ud_passive_qp_qkey; 620 621 /* Clients' information */ 622 void *ud_state_cm_private; 623 624 struct ibcm_ud_state_data_s *ud_timeout_next; 625 boolean_t ud_delete_state_data; 626 boolean_t ud_blocking_done; 627 628 uint8_t ud_send_mad_flags; 629 630 ibcm_isync_t ud_clnt_proceed; 631 632 /* The following fields are not used by server side connection */ 633 kcondvar_t ud_block_client_cv; 634 ibt_ud_returns_t *ud_return_data; 635 ibcm_conn_state_t ud_timer_stored_state; 636 } ibcm_ud_state_data_t; 637 638 _NOTE(MUTEX_PROTECTS_DATA(ibcm_ud_state_data_s::ud_state_mutex, 639 ibcm_ud_state_data_s::{ud_state ud_ref_cnt ud_timerid 640 ud_delete_state_data ud_blocking_done ud_send_mad_flags ud_clnt_proceed 641 ud_timer_stored_state ud_send_mad_flags ud_clnt_proceed 642 ud_block_client_cv ud_timer_value ud_remaining_retry_cnt})) 643 644 _NOTE(READ_ONLY_DATA(ibcm_ud_state_data_s::{ud_mode ud_req_id ud_svc_id 645 ud_max_cm_retries ud_pkt_life_time ud_stored_reply_addr ud_stored_msg 646 ud_sidr_req_lid ud_sidr_req_gid ud_grh_exists ud_passive_qpn 647 ud_passive_qp_qkey ud_state_cm_private ud_stored_reply_addr ud_stored_msg})) 648 649 _NOTE(SCHEME_PROTECTS_DATA("Serailized access by ud_block_client_cv", 650 ibcm_ud_state_data_s::{ud_return_data})) 651 652 _NOTE(DATA_READABLE_WITHOUT_LOCK(ibcm_ud_state_data_s::{ud_cm_handler})) 653 654 /* 655 * Structure used to specify the SIDR search parameters 656 */ 657 typedef struct ibcm_sidr_srch_s { 658 ib_lid_t srch_lid; 659 ib_gid_t srch_gid; 660 boolean_t srch_grh_exists; 661 uint32_t srch_req_id; 662 ibcm_mode_t srch_mode; 663 } ibcm_sidr_srch_t; 664 665 _NOTE(READ_ONLY_DATA(ibcm_sidr_srch_s)) 666 667 /* 668 * Incr/Decr ud_ref_cnt by 1 669 */ 670 #define IBCM_UD_REF_CNT_INCR(s) ((s)->ud_ref_cnt++) 671 #define IBCM_UD_REF_CNT_DECR(s) \ 672 if ((--(s->ud_ref_cnt) == 0) && (s->ud_delete_state_data == B_TRUE)) { \ 673 ibcm_add_ud_tlist(s);\ 674 } \ 675 ASSERT(s->ud_ref_cnt >= 0); 676 677 /* 678 * Structure to store the Service Registration and Service Bind entries. 679 * 680 * Well known service id's are unique on a given HCA, but can be registered 681 * only at some GID's. Hence can be multiple GID's per Service ID. For each 682 * such GID and PKEY combination registered, there will be an ibcm_svc_info_t 683 * entry in the CM global service list. 684 * 685 * Annex A of the spec constrains that there shall be one service provider per 686 * service id, which implies same svc_rc_handler for all such entries 687 * There can be multiple transport types (svc_tran_type) per Service ID. For 688 * each such transport type, there will be an ibcm_svc_info_t entry in the 689 * CM global service list and cm handler can be different 690 * 691 * For locally allocated service id's (maintained by OS), there can be only 692 * one GID, where the service can be registered 693 * 694 * svc_id: Service ID 695 * svc_num_sids: Number (Range) of service-ids supported 696 * svc_flags: Service flags specified at registration time 697 * svc_link: Global AVL tree of ibcm_svc_info_t structs 698 * svc_rc_handler: Server handler for RC (only one is valid at a time) 699 * svc_ud_handler: Server handler for UD (only one is valid at a time) 700 * svc_ref_cnt: Reference count 701 * svc_to_delete: If 1, then the entry is marked to be deleted 702 * 703 * sbind_gid: GID 704 * sbind_pkey: P_Key 705 * sbind_lease: Service Lease 706 * sbind_name: Service Name 707 */ 708 typedef struct ibcm_svc_info_s { 709 avl_node_t svc_link; 710 struct ibcm_svc_bind_s *svc_bind_list; 711 ibt_cm_handler_t svc_rc_handler; 712 ibt_cm_ud_handler_t svc_ud_handler; 713 int svc_ref_cnt; 714 int svc_to_delete; 715 ib_svc_id_t svc_id; 716 int svc_num_sids; 717 ibt_service_flags_t svc_flags; 718 } ibcm_svc_info_t; 719 720 typedef struct ibcm_svc_bind_s { 721 struct ibcm_svc_bind_s *sbind_link; 722 void *sbind_cm_private; 723 ib_gid_t sbind_gid; 724 ib_guid_t sbind_hcaguid; 725 uint64_t sbind_key[2]; 726 /* sbind_data is assumed to be 8-byte aligned */ 727 uint8_t sbind_data[IB_SVC_DATA_LEN]; /* ServiceData */ 728 uint32_t sbind_lease; 729 ib_pkey_t sbind_pkey; 730 uint8_t sbind_port; 731 uint8_t sbind_rewrite_state; 732 char sbind_name[IB_SVC_NAME_LEN]; 733 } ibcm_svc_bind_t; 734 735 /* 736 * Service records may be lost by the SM/SA (reboot, change in who 737 * is the master, etc.). When any of the above occurs, a PORT_UP 738 * async event is supposed to occur, at which point we mark all of 739 * our service record information as stale (REWRITE_NEEDED), and 740 * subsequently make the necessary sa_update calls to get the 741 * SM/SA in sync with all the service records we previously wrote. 742 * 743 * Values for sbind_rewrite_state follow. This field is protected by 744 * ibcm_svc_info_lock. ibt_unbind_service has to wait until a service 745 * binding is either idle or needed, sleeping on ibcm_svc_info_cv if 746 * busy (rewrite in progress). 747 */ 748 #define IBCM_REWRITE_IDLE 0 749 #define IBCM_REWRITE_NEEDED 1 750 #define IBCM_REWRITE_BUSY 2 751 752 typedef struct ibcm_port_up_s { 753 ib_guid_t pup_hca_guid; 754 uint8_t pup_port; 755 } ibcm_port_up_t; 756 757 /* arg is a pointer to ibcm_port_up_t */ 758 extern void ibcm_service_record_rewrite_task(void *); 759 760 #define IBCM_SVC_INCR(svcinfop) (svcinfop)->svc_ref_cnt++ 761 #define IBCM_SVC_DECR(svcinfop) \ 762 if (--((svcinfop)->svc_ref_cnt) == 0 && \ 763 (svcinfop)->svc_to_delete) \ 764 cv_broadcast(&ibcm_svc_info_cv); \ 765 ASSERT(svcinfop->svc_ref_cnt >= 0); 766 767 _NOTE(READ_ONLY_DATA(ibcm_svc_info_s::{svc_rc_handler svc_ud_handler svc_id 768 svc_num_sids svc_flags})) 769 770 _NOTE(READ_ONLY_DATA(ibcm_svc_bind_s::{sbind_cm_private sbind_gid sbind_hcaguid 771 sbind_key sbind_data sbind_lease sbind_pkey sbind_port sbind_name})) 772 773 /* for avl tree search */ 774 typedef struct ibcm_svc_lookup_s { 775 ib_svc_id_t sid; 776 int num_sids; 777 } ibcm_svc_lookup_t; 778 779 typedef struct ibcm_ar_ref_s { 780 struct ibcm_ar_ref_s *ar_ref_link; 781 ibt_clnt_hdl_t ar_ibt_hdl; 782 } ibcm_ar_ref_t; 783 784 typedef struct ibcm_ar_s { 785 ibt_ar_t ar; 786 int ar_flags; /* 1 = INITING, 2 = FAILED */ 787 int ar_waiters; /* # of waiters */ 788 kcondvar_t ar_cv; 789 uint8_t ar_port; 790 uint8_t ar_rewrite_state; /* see sbind_rewrite_state */ 791 ibcm_ar_ref_t *ar_ibt_hdl_list; 792 struct ibcm_ar_s *ar_link; 793 sa_service_record_t *ar_srv_recp; 794 ibmf_saa_handle_t ar_saa_handle; 795 struct ibcm_hca_info_s *ar_hcap; 796 } ibcm_ar_t; 797 798 /* ar_flags */ 799 #define IBCM_AR_SUCCESS 0 800 #define IBCM_AR_FAILED 1 801 #define IBCM_AR_INITING 2 802 803 804 /* 805 * These flags are used for adding (if an entry does not exist) or 806 * for just looking one up 807 */ 808 typedef enum ibcm_lookup_flag_e { 809 IBCM_FLAG_LOOKUP = 0, /* just lookup */ 810 IBCM_FLAG_ADD = 1, /* just add */ 811 IBCM_FLAG_LOOKUP_AND_ADD = 2 /* lookup first. add if */ 812 /* lookup failed */ 813 } ibcm_lookup_flag_t; 814 815 typedef enum ibcm_finit_state_e { 816 IBCM_FINIT_INIT, /* CM's init is not yet completed */ 817 IBCM_FINIT_IDLE, /* CM not in either init or fini */ 818 IBCM_FINIT_BUSY, /* CM busy either in init or fini */ 819 IBCM_FINIT_FAIL, /* Init failed */ 820 IBCM_FINIT_SUCCESS /* Fini has succeeded */ 821 } ibcm_finit_state_t; 822 823 /* 824 * Identifies HCA's state. Used in the definition of ibcm_hca_info_t 825 * If HCA is in ACTIVE state only does CM allow any MAD processing. 826 */ 827 typedef enum ibcm_hca_state_e { 828 IBCM_HCA_INIT, 829 IBCM_HCA_ACTIVE, 830 IBCM_HCA_NOT_ACTIVE 831 } ibcm_hca_state_t; 832 833 /* QP information per pkey, stored in port information */ 834 typedef struct ibcm_qp_list_s { 835 ib_pkey_t qp_pkey; 836 ibmf_qp_handle_t qp_cm; 837 uint32_t qp_ref_cnt; 838 struct ibcm_port_info_s *qp_port; 839 struct ibcm_qp_list_s *qp_next; 840 } ibcm_qp_list_t; 841 842 _NOTE(READ_ONLY_DATA(ibcm_qp_list_s::{qp_pkey qp_cm qp_port qp_next})) 843 _NOTE(DATA_READABLE_WITHOUT_LOCK(ibcm_qp_list_s)) 844 845 /* 846 * port information per HCA 847 * port_ibmf_hdl - contains IBMF handle for that port if valid 848 * otherwise is NULL 849 * port_ibmf_saa_hdl - contains SA Access handle for that port if valid 850 * otherwise is NULL 851 */ 852 typedef struct ibcm_port_info_s { 853 ibmf_handle_t port_ibmf_hdl; 854 ibmf_saa_handle_t port_ibmf_saa_hdl; 855 ib_gid_t port_sgid0; 856 uint8_t port_event_status; 857 uint8_t port_saa_open_in_progress; 858 uint8_t port_num; 859 ibmf_register_info_t port_ibmf_reg; 860 ibmf_impl_caps_t port_ibmf_caps; 861 ibcm_qp_list_t port_qp1; 862 ibcm_qp_list_t *port_qplist; 863 struct ibcm_hca_info_s *port_hcap; 864 } ibcm_port_info_t; 865 866 _NOTE(READ_ONLY_DATA(ibcm_port_info_s::{port_num port_ibmf_caps port_qp1 867 port_hcap})) 868 869 /* Value to indicate to exit the timeout list processing thread */ 870 #define IBCM_TIMEOUT_THREAD_EXIT 01 871 872 /* 873 * IBCM code relies on AVL routines already in kernel for faster lookups. 874 * AVL was chosen over mod hashing mechanism based on the its internal 875 * limitations in the kernel (no support for over 100,000 keys). 876 * 877 * IBCM uses two AVL trees on the passive side and one on active side per HCA. 878 * The two trees are need on the passive side because the tree lookup criteria 879 * changes based on the type of message being processed. On passive side it is 880 * based on remote_qpn and remote_hca_guid for only incoming REQ message and for 881 * for all other messages the search criteria is based upon remote_comid. 882 * On active side the lookup criteria remains static based upon local_comid. 883 * 884 * AVL tree insertions are done by grabbing the writer lock (hca_state_rwlock) 885 * and lookups are done by grabbing the reader lock. 886 */ 887 888 /* 889 * CM's per HCA data structure. 890 * 891 * One such entry is added/removed on hca attach/detach notifications to CM 892 * respectively. 893 * 894 * Comids are used for all connections. Req ids are used for SIDR REQ and 895 * SIDR REP messages. These are simple counters that wrap around INT_MAX. 896 * NOTE: The starting value for comid, per HCA, is 2. 897 * 898 * hca_state: HCA's current state (ibcm_hca_state_t) - whether 899 * IBT_HCA_ACTIVE, IBT_HCA_NOT_ACTIVE, 900 * hca_guid: Active HCA guid 901 * hca_caps: HCA capability mask 902 * hca_ack_delay: HCA ack delay 903 * hca_max_rdma_rd Max RDMA in Reads 904 * hca_max_rdma_dpt Max RDMA out Reads 905 * hca_active_tree: This tree is used for lookups on Active/Passive side 906 * CM based on communication id ONLY. 907 * hca_passive_tree: This tree is used to lookup/create ibcm_state_data_t on 908 * Passive Side CM based on remote_qpn and remote_hca_guid. 909 * hca_passive_comid_tree: 910 * This tree is used to lookup/create ibcm_state_data_t on 911 * Passive Side CM based on remote_comid and 912 * remote_hca_guid. 913 * hca_state_rwlock: reader/writer Lock for the hca entry 914 * for hca_active_tree 915 * for hca_passive_tree 916 * for hca_next_comid 917 * hca_sidr_list: List for UD side 918 * hca_sidr_list_lock: List lock for UD side 919 * for hca_sidr_list 920 * for hca_next_reqid 921 * hca_next_reqid: Next active ReqId 922 * hca_next_comid: Next active ComID 923 * hca_next: Pointer to the next HCA 924 * hca_svc_cnt: A count of services registered on this hca 925 * hca_acc_cnt: A count of active references to this ibcm_hca_info_t 926 * hca_res_cnt: A count of client's active resources on this hca 927 * hca_num_ports: Number of ports that this HCA has 928 * hca_port_info: Per port information (IBMA/SA access handles etc.) 929 * 930 * Note : The global mutex ibcm_global_hca_mutex declared in CM is used for 931 * accesses to the following fields : 932 * hca_acc_cnt, hca_res_cnt, hca_svc_cnt, hca_state 933 */ 934 typedef struct ibcm_hca_info_s { 935 ibcm_hca_state_t hca_state; /* Is HCA attached? */ 936 ib_guid_t hca_guid; /* HCA's guid value */ 937 ibt_hca_flags_t hca_caps; /* HCA capabilities */ 938 ib_time_t hca_ack_delay; /* HCA ack delay */ 939 uint8_t hca_max_rdma_in_qp; /* Max RDMA in Reads */ 940 uint8_t hca_max_rdma_out_qp; /* Max RDMA out Reads */ 941 vmem_t *hca_comid_arena; /* arena for com ids */ 942 vmem_t *hca_reqid_arena; /* arena for req ids */ 943 avl_tree_t hca_active_tree; /* active node tree */ 944 avl_tree_t hca_passive_tree; /* passive node tree */ 945 avl_tree_t hca_passive_comid_tree; /* passive comid tree */ 946 krwlock_t hca_state_rwlock; /* per HCA lock */ 947 ibcm_ud_state_data_t *hca_sidr_list; /* SIDR state list */ 948 krwlock_t hca_sidr_list_lock; 949 950 struct ibcm_hca_info_s *hca_next; /* Next HCA entry */ 951 952 int hca_svc_cnt; /* # of */ 953 /* services allocated */ 954 int hca_acc_cnt; /* active references */ 955 int hca_res_cnt; /* total resources */ 956 uint8_t hca_num_ports; /* #ports on this HCA */ 957 ibcm_port_info_t hca_port_info[1]; /* Per portinfo array */ 958 } ibcm_hca_info_t; 959 960 _NOTE(RWLOCK_PROTECTS_DATA(ibcm_hca_info_s::hca_state_rwlock, 961 ibcm_hca_info_s::{hca_active_tree hca_passive_tree hca_passive_comid_tree})) 962 963 _NOTE(SCHEME_PROTECTS_DATA("hca_sidr_list_lock protects hca_sidr_list", 964 ibcm_hca_info_s::{hca_sidr_list})) 965 966 _NOTE(READ_ONLY_DATA(ibcm_hca_info_s::{hca_guid hca_caps hca_ack_delay 967 hca_max_rdma_in_qp hca_max_rdma_out_qp hca_comid_arena hca_reqid_arena 968 hca_passive_tree hca_active_tree hca_passive_comid_tree hca_num_ports })) 969 970 971 /* 972 * called to ensure that HCA is in "attached" state and is willing to 973 * process connections etc. 974 */ 975 #define IBCM_ACCESS_HCA_OK(s) ((s)->hca_state == IBCM_HCA_ACTIVE) 976 977 /* 978 * Passive AVL tree lookup info (for hca_passive_tree) 979 * CM needs this structure as passive tree lookups are based on 980 * QPN and HCA GUID. 981 */ 982 typedef struct ibcm_passive_node_info_s { 983 ib_qpn_t info_qpn; 984 ib_guid_t info_hca_guid; 985 } ibcm_passive_node_info_t; 986 987 /* 988 * Passive Com ID AVL tree lookup info (for hca_passive_comid_tree) 989 * CM needs this structure as passive comid tree lookups are based on 990 * Remote Com ID and Remote HCA GUID. 991 */ 992 typedef struct ibcm_passive_comid_node_info_s { 993 ib_com_id_t info_comid; 994 ib_guid_t info_hca_guid; 995 } ibcm_passive_comid_node_info_t; 996 997 /* CM proceed task args structure definition */ 998 typedef struct ibcm_proceed_targs_s { 999 ibt_cm_event_type_t event; 1000 ibt_cm_status_t status; 1001 union tst_t { 1002 struct rc_s { 1003 ibcm_state_data_t *statep; 1004 ibt_cm_proceed_reply_t rc_cm_event_data; 1005 } rc; 1006 struct ud_s { 1007 ibcm_ud_state_data_t *ud_statep; 1008 ib_qpn_t ud_qpn; 1009 ib_qkey_t ud_qkey; 1010 ibt_redirect_info_t ud_redirect_info; 1011 } ud; 1012 } tst; 1013 ibt_priv_data_len_t priv_data_len; 1014 /* keep priv_data as the last field */ 1015 uint8_t priv_data[IBT_MAX_PRIV_DATA_SZ]; 1016 } ibcm_proceed_targs_t; 1017 1018 _NOTE(READ_ONLY_DATA(ibcm_proceed_targs_s)) 1019 1020 1021 /* 1022 * function prototypes for AVL tree compares 1023 */ 1024 int ibcm_active_node_compare(const void *, const void *); 1025 int ibcm_passive_node_compare(const void *, const void *); 1026 int ibcm_passive_comid_node_compare(const void *, const void *); 1027 1028 /* 1029 * function prototypes to allocate IBMF/SA_ACCESS handles 1030 */ 1031 ibt_status_t ibcm_hca_reinit_port(ibcm_hca_info_t *hca_p, 1032 uint8_t port_index); 1033 1034 /* function prototypes to Manage CM's IBMF QP's */ 1035 1036 ibcm_qp_list_t *ibcm_find_qp(ibcm_hca_info_t *hcap, int port_no, 1037 ib_pkey_t pkey); 1038 1039 void ibcm_release_qp(ibcm_qp_list_t *cm_qp_entry); 1040 1041 ibcm_status_t ibcm_free_qp(ibcm_qp_list_t *cm_qp_entry); 1042 1043 ibcm_status_t ibcm_free_allqps(ibcm_hca_info_t *hcap, int port_no); 1044 1045 /* 1046 * function prototypes to allocate and free outgoing CM messages 1047 */ 1048 ibt_status_t 1049 ibcm_alloc_out_msg(ibmf_handle_t ibmf_handle, ibmf_msg_t **ibmf_msgpp, 1050 uint8_t method); 1051 ibcm_status_t 1052 ibcm_free_out_msg(ibmf_handle_t ibmf_handle, ibmf_msg_t **ibmf_msgpp); 1053 1054 /* 1055 * Definition for CM state transition processing function 1056 */ 1057 typedef void (*ibcm_state_handler_t)(ibcm_hca_info_t *hcap, 1058 uint8_t *cm_input_mad, ibcm_mad_addr_t *cm_mad_addr); 1059 1060 /* 1061 * CM REQ Message structure 1062 * 1063 * Request for communication. 1064 * 1065 * Things of interest are:- 1066 * ib_qpn_t cannot be used - it is typecast to uint32_t but is 24 bits 1067 * ib_eecn_t cannot be used - it is typecast to uint32_t but is 24 bits 1068 * 1069 * (See Table 85 REQ Message Contents - chapter 12 in IB Spec v1.0a) 1070 * 1071 */ 1072 typedef struct ibcm_req_msg_s { 1073 ib_com_id_t req_local_comm_id; /* Local communication id */ 1074 /* 32 bits */ 1075 uint32_t req_rsvd1; /* Reserved1 - 32 bits */ 1076 ib_svc_id_t req_svc_id; /* Service Id - 64 bits */ 1077 ib_guid_t req_local_ca_guid; /* Local CA GUID - 64 bits */ 1078 uint32_t req_rsvd1p; /* Reserved1+ - 32 bits */ 1079 ib_qkey_t req_local_qkey; /* Local Q_KEY - 32 bits */ 1080 uint32_t req_local_qpn_plus; /* QPN_24 RESP_RSRC_8 */ 1081 /* local side QPN - 24 bits */ 1082 /* Offered responder */ 1083 /* resources - 8 bits */ 1084 uint32_t req_local_eec_no_plus; /* LOCAL_EECN_24 INIT_DEPTH_8 */ 1085 /* Local side EECN - 24 bits */ 1086 /* Offered initiator */ 1087 /* depth - 8 bits */ 1088 uint32_t req_remote_eecn_plus; /* REM_EECN_24 TO_5 TT_2 EE_1 */ 1089 /* Remote side EECN - 24 bits */ 1090 /* Remote CM timeout - 5 bits */ 1091 /* Transport srvtype - 2 bits */ 1092 /* End-to-End flow - 1 bit */ 1093 uint32_t req_starting_psn_plus; /* START_PSN_24 TO_5 RETRY_3 */ 1094 /* Starting PSN - 24 bits */ 1095 /* Local CM timeout - 5 bits */ 1096 /* Retry count - 3 bits */ 1097 ib_pkey_t req_part_key; /* Partition key - 16 bits */ 1098 uint8_t req_mtu_plus; /* PATH_MTU_4 RDC_1 RNR_3 */ 1099 /* Path Pkt MTU - 4 bits */ 1100 /* Does RDC exist? - 1 bits */ 1101 /* RNR retry count - 3 bits */ 1102 uint8_t req_max_cm_retries_plus; /* MAX_CM_RET_4 SRQ_1 RSV_3 */ 1103 /* Max CM retries - 4 bits */ 1104 /* SRQ Exists - 1 bit */ 1105 /* Reserved2 - 3 bits */ 1106 ib_lid_t req_primary_l_port_lid; /* Primary local port LID */ 1107 ib_lid_t req_primary_r_port_lid; /* Primary Remote port LID */ 1108 ib_gid_t req_primary_l_port_gid; /* Primary local port GID */ 1109 ib_gid_t req_primary_r_port_gid; /* Primary remote port GID */ 1110 uint32_t req_primary_flow_label_plus; /* FLOW_20 RSV_4 SRATE_6 */ 1111 /* Prim. flow label - 20 bits */ 1112 /* Reserved3 - 6 bits */ 1113 /* Primary rate - 6 bits */ 1114 uint8_t req_primary_traffic_class; 1115 /* Primary Traffic class */ 1116 uint8_t req_primary_hop_limit; /* Prim Hop Limit */ 1117 uint8_t req_primary_sl_plus; /* PRIMARY_SL_4 LOCAL_1 RSV_3 */ 1118 /* Primary SL - 4 bits */ 1119 /* Prim. subnet local - 1 bit */ 1120 /* Reserved4 - 3 bits */ 1121 uint8_t req_primary_localtime_plus; /* LOCAL_TO_5 RSV_3 */ 1122 /* Primary local */ 1123 /* timeout - 5 bits */ 1124 /* Reserved5 - 3 bits */ 1125 ib_lid_t req_alt_l_port_lid; /* Alt local port LID */ 1126 ib_lid_t req_alt_r_port_lid; /* Alt Remote port LID */ 1127 /* Note: req_alt_l_port_gid/req_alt_r_port_gid are not 8-byte aligned */ 1128 uint8_t req_alt_l_port_gid[16]; /* Alt local port GID */ 1129 uint8_t req_alt_r_port_gid[16]; /* Alt remote port GID */ 1130 uint32_t req_alt_flow_label_plus; /* ALT_FLOW_20 RSV_6 ARATE_6 */ 1131 /* Alt flow label - 20 bits */ 1132 /* Reserved6 - 6 bits */ 1133 /* Alternate rate - 6 bits */ 1134 uint8_t req_alt_traffic_class; /* Alt traffic class */ 1135 uint8_t req_alt_hop_limit; /* Alt hop limit */ 1136 uint8_t req_alt_sl_plus; /* ALT_SL_4 A_LOCAL_1 RSV_3 */ 1137 /* Alternate SL - 4 bits */ 1138 /* Alt subnet local - 1 bit */ 1139 /* Reserved7 - 3 bits */ 1140 uint8_t req_alt_localtime_plus; /* ALT_LOCAL_ACK_TO_5 RSV_3 */ 1141 /* Alt Local ACK */ 1142 /* timeout - 5 bits */ 1143 /* Reserved8 - 3 bits */ 1144 uint8_t req_private_data[IBT_REQ_PRIV_DATA_SZ]; 1145 /* Private data */ 1146 } ibcm_req_msg_t; 1147 1148 1149 /* 1150 * The following set of defines are short-cuts to CEP_PATH or GRH info 1151 */ 1152 #define IBCM_PRIM_CEP_PATH(s) (s)->oc_path->pi_prim_cep_path 1153 #define IBCM_PRIM_ADDS_VECT(s) (s)->oc_path->pi_prim_cep_path.cep_adds_vect 1154 1155 #define IBCM_ALT_CEP_PATH(s) (s)->oc_path->pi_alt_cep_path 1156 #define IBCM_ALT_ADDS_VECT(s) (s)->oc_path->pi_alt_cep_path.cep_adds_vect 1157 1158 #define IBCM_UD_CEP_PATH(s) (s)->us_path_info->ai_cep_path 1159 #define IBCM_UD_ADDS_VECT(s) (s)->us_path_info->ai_cep_path.cep_adds_vect 1160 1161 /* 1162 * The following set of defines are short-cuts to ibt_cm_event_t 1163 */ 1164 #define IBCM_EVT_REQ(e) (e).cm_event.req 1165 #define IBCM_EVT_REP(e) (e).cm_event.rep 1166 1167 /* 1168 * The following set of defines are short-cuts to qp_attrs or qp_info 1169 */ 1170 #define IBCM_QP_RC(q) (q).qp_info.qp_transport.rc 1171 #define IBCM_QP_UD(q) (q).qp_info.qp_transport.ud 1172 #define IBCM_QP_UC(q) (q).qp_info.qp_transport.uc 1173 1174 #define IBCM_QPINFO(q) (q).qp_transport 1175 #define IBCM_QPINFO_RC(q) (q).qp_transport.rc 1176 #define IBCM_QPINFO_RC_PATH(q) (q).qp_transport.rc.rc_path 1177 #define IBCM_QPINFO_UC(q) (q).qp_transport.uc 1178 #define IBCM_QPINFO_UC_PATH(q) (q).qp_transport.uc.uc_path 1179 #define IBCM_QPINFO_UD(q) (q).qp_transport.ud 1180 1181 1182 /* The following set of defines are short-cuts to RC and SIDR MAD HDRs */ 1183 1184 #define IBCM_OUT_MADP(msgp) (msgp->im_msgbufs_send.im_bufs_mad_hdr) 1185 #define IBCM_OUT_HDRP(msgp) ((ib_mad_hdr_t *)IBCM_OUT_MADP(msgp)) 1186 #define IBCM_OUT_MSGP(msgp) (msgp->im_msgbufs_send.im_bufs_cl_data) 1187 1188 #define IBCM_IN_MADP(msgp) (msgp->im_msgbufs_recv.im_bufs_mad_hdr) 1189 #define IBCM_IN_HDRP(msgp) ((ib_mad_hdr_t *)IBCM_IN_MADP(msgp)) 1190 #define IBCM_IN_MSGP(msgp) (msgp->im_msgbufs_recv.im_bufs_cl_data) 1191 1192 #define IBCM_REJ_PRIV(msgp) &(((ibcm_rej_msg_t *) \ 1193 IBCM_OUT_MSGP(statep->stored_msg))->rej_private_data[0]) 1194 /* 1195 * CM MRA Message structure 1196 * 1197 * Message Receipt Acknowledgement (MRA). 1198 * 1199 * NOTE: IB hosts and targets are required to be able to receive and 1200 * act upon an MRA, but the ability to send an MRA is optional. 1201 */ 1202 typedef struct ibcm_mra_msg_s { 1203 ib_com_id_t mra_local_comm_id; /* Local communication id */ 1204 ib_com_id_t mra_remote_comm_id; /* Remote communication id */ 1205 uint8_t mra_message_type_plus; /* Message Type - 2 bits */ 1206 /* Reserved1 - 6 bits */ 1207 uint8_t mra_service_timeout_plus; /* SVC_TO_5 RSV_3 */ 1208 /* Service timeout - 5 bits */ 1209 /* Reserved2 - 3 bits */ 1210 uint8_t mra_private_data[IBT_MRA_PRIV_DATA_SZ]; 1211 /* Private data */ 1212 } ibcm_mra_msg_t; 1213 1214 /* 1215 * CM REJ Message structure 1216 * REJ indicates that the sender will not continue through the communication 1217 * establishment sequence and the reason why it will not. 1218 * 1219 * NOTE: See ibt_cm_reason_t in common/sys/ib/ib_cm.h for complete list 1220 * of rejection reasons supported. 1221 */ 1222 typedef struct ibcm_rej_msg_s { 1223 ib_com_id_t rej_local_comm_id; /* Local communication id */ 1224 ib_com_id_t rej_remote_comm_id; /* Remote communication id */ 1225 uint8_t rej_msg_type_plus; /* REJ_MSG_TYPE_2 RSV_6 */ 1226 /* Msg being REJed - 2 bits */ 1227 /* Reserved1 - 6 bits */ 1228 uint8_t rej_reject_info_len_plus; /* REJ_INFO_LEN_7 RSV_1 */ 1229 /* Rej. Info Length - 7 bits */ 1230 /* Reserved2 - 1 bit */ 1231 uint16_t rej_rejection_reason; /* Reject err code - 16 bits */ 1232 uint8_t rej_addl_rej_info[IBT_CM_ADDL_REJ_LEN]; 1233 /* Additional Reject Info */ 1234 uint8_t rej_private_data[IBT_REJ_PRIV_DATA_SZ]; 1235 /* Private data */ 1236 } ibcm_rej_msg_t; 1237 1238 /* 1239 * CM REP Message structure 1240 * 1241 * REP is returned in response to REQ, indicating that the respondent 1242 * accepts the Service-ID, proposed primary port, and any parameters 1243 * specified in the PrivateData of the REQ. 1244 */ 1245 typedef struct ibcm_rep_msg_s { 1246 ib_com_id_t rep_local_comm_id; /* Local communication id */ 1247 ib_com_id_t rep_remote_comm_id; /* Remote communication id */ 1248 ib_qkey_t rep_local_qkey; /* Local Q_KEY */ 1249 uint32_t rep_local_qpn_plus; /* LOCAL_QPN_24 RSV_8 */ 1250 /* Local side QPN - 24 bits */ 1251 /* Reserved1 - 8 bits */ 1252 uint32_t rep_local_eecn_plus; /* LOCAL_EECN_24 RSV_8 */ 1253 /* Local side EECN - 24 bits */ 1254 /* Reserved2 - 8 bits */ 1255 uint32_t rep_starting_psn_plus; /* STARTING_PSN_24 RSV_8 */ 1256 /* Starting PSN - 24 bits */ 1257 /* Reserved3 - 8 bits */ 1258 uint8_t rep_resp_resources; /* Responder resources 8 bits */ 1259 uint8_t rep_initiator_depth; /* Initiator depth - 8 bits */ 1260 uint8_t rep_target_delay_plus; /* TGT_ACK_DLY_5 FAIL_2 EE_1 */ 1261 /* Target ACK delay - 5 bits */ 1262 /* Failover accepted - 2 bits */ 1263 /* End-to-End flow control - */ 1264 /* 1 bit */ 1265 uint8_t rep_rnr_retry_cnt_plus; /* RNR_COUNT_3 SRQ_1 RSV_4 */ 1266 /* RNR retry count - 3 bits */ 1267 /* SRQ Exists - 1 bit */ 1268 /* Reserved4 - 4 bits */ 1269 uint8_t rep_local_ca_guid[8]; /* Local CA GUID - 64 bits */ 1270 uint8_t rep_private_data[IBT_REP_PRIV_DATA_SZ]; 1271 /* Private data */ 1272 } ibcm_rep_msg_t; 1273 1274 1275 /* 1276 * CM RTU Message structure 1277 * 1278 * RTU indicates that the connection is established, and that the 1279 * recipient may begin transmitting. 1280 */ 1281 typedef struct ibcm_rtu_msg_s { 1282 ib_com_id_t rtu_local_comm_id; /* Local communication id */ 1283 ib_com_id_t rtu_remote_comm_id; /* Remote communication id */ 1284 uint8_t rtu_private_data[IBT_RTU_PRIV_DATA_SZ]; 1285 /* Private data */ 1286 } ibcm_rtu_msg_t; 1287 1288 1289 /* 1290 * CM DREQ Message structure 1291 * 1292 * DREQ is sent to initiate the connection release sequence. 1293 */ 1294 typedef struct ibcm_dreq_msg_s { 1295 ib_com_id_t dreq_local_comm_id; /* Local communication id */ 1296 ib_com_id_t dreq_remote_comm_id; /* Remote communication id */ 1297 uint32_t dreq_remote_qpn_eecn_plus; /* REM_EECN_24 RSV_8 */ 1298 /* Remote QPN/EECN - 24 bits */ 1299 /* reserved - 8 bits */ 1300 uint8_t dreq_private_data[IBT_DREQ_PRIV_DATA_SZ]; 1301 /* Private data */ 1302 } ibcm_dreq_msg_t; 1303 1304 1305 /* 1306 * CM DREP Message structure 1307 * 1308 * DREP is sent in response to DREQ, and signifies that the sender has 1309 * received DREQ. 1310 */ 1311 typedef struct ibcm_drep_msg_s { 1312 ib_com_id_t drep_local_comm_id; /* Local communication id */ 1313 ib_com_id_t drep_remote_comm_id; /* Remote communication id */ 1314 uint8_t drep_private_data[IBT_DREP_PRIV_DATA_SZ]; 1315 /* Private Data */ 1316 } ibcm_drep_msg_t; 1317 1318 1319 /* 1320 * CM LAP Message structure 1321 * 1322 * NOTE: LAP and APR messages are optional. These are needed if CM 1323 * accepts REQ messages and agrees to perform Automatic Path Migration. 1324 * 1325 * This message is used to change the alternate path information for a 1326 * specific connection. 1327 */ 1328 typedef struct ibcm_lap_msg_s { 1329 ib_com_id_t lap_local_comm_id; /* Local communication id */ 1330 ib_com_id_t lap_remote_comm_id; /* Remote communication id */ 1331 uint32_t lap_rsvd1; /* Reserved - 32 bits */ 1332 uint32_t lap_remote_qpn_eecn_plus; /* REM_EECN_24 TO_5 RSV_3 */ 1333 /* Remote QPN/EECN - 24 bits */ 1334 /* Remote CM response */ 1335 /* timeout - 5 bits */ 1336 /* Reserved1 - 3 bits */ 1337 uint32_t lap_rsvd2; /* Reserved2 - 32 bits */ 1338 ib_lid_t lap_alt_l_port_lid; /* Alt local port LID */ 1339 ib_lid_t lap_alt_r_port_lid; /* Alt Remote port LID */ 1340 ib_gid_t lap_alt_l_port_gid; /* Alt local port GID */ 1341 ib_gid_t lap_alt_r_port_gid; /* Alt remote port GID */ 1342 uint32_t lap_alt_flow_label_plus; /* ALT_FLOW_20 RSV_4 TCL_8 */ 1343 /* Alt flow label - 20 bits */ 1344 /* Reserved3 - 4 bits */ 1345 /* Alt traffic class - 8 bits */ 1346 uint8_t lap_alt_hop_limit; /* Alt hop limit */ 1347 uint8_t lap_alt_srate_plus; /* Reserved4 - 2 bits */ 1348 /* Alt. static rate - 6 bits */ 1349 uint8_t lap_alt_sl_plus; /* ALT_SL_4 A_LOCAL_1 RSV_3 */ 1350 /* Alternate SL - 4 bits */ 1351 /* Alt subnet local - 1 bit */ 1352 /* Reserved5 - 3 bits */ 1353 uint8_t lap_alt_local_acktime_plus; /* ALT_TO_5 RSV_3 */ 1354 /* Alt Local ACK */ 1355 /* timeout - 5 bits */ 1356 /* Reserved6 - 3 bits */ 1357 uint8_t lap_private_data[IBT_LAP_PRIV_DATA_SZ]; 1358 /* Private data */ 1359 } ibcm_lap_msg_t; 1360 1361 1362 /* 1363 * CM APR Message structure 1364 * 1365 * APR is sent in response to a LAP request. MRA may be sent to allow 1366 * processing of the LAP. 1367 */ 1368 typedef struct ibcm_apr_msg_s { 1369 ib_com_id_t apr_local_comm_id; /* Local communication id */ 1370 ib_com_id_t apr_remote_comm_id; /* Remote communication id */ 1371 uint8_t apr_addl_info_len; /* Add'l Info Len - 8 bits */ 1372 uint8_t apr_ap_status; /* AP status - 8 bits */ 1373 uint16_t apr_rsvd1; /* Reserved1 - 16 bits */ 1374 uint8_t apr_addl_info[IBT_CM_APR_ADDL_LEN]; 1375 /* Additional Information */ 1376 uint8_t apr_private_data[IBT_APR_PRIV_DATA_SZ]; 1377 /* Private data */ 1378 } ibcm_apr_msg_t; 1379 1380 1381 /* 1382 * CM SIDR_REQ Message structure 1383 * 1384 * NOTE: SIDR_REQ and SIDR_REP messages are conditionally required. 1385 * These are needed if non-management services are provided on the Channel 1386 * Adapter other than fixed QPNs. Management services include those 1387 * provided thru Subnet Manager Packets or thru General Management Packets. 1388 * 1389 * SIDR_REQ requests that the recipient return the information necessary 1390 * to communicate via UD messages with the entity specified by 1391 * SIDR_REQ:ServiceID 1392 */ 1393 typedef struct ibcm_sidr_req_msg_s { 1394 uint32_t sidr_req_request_id; /* Request id */ 1395 ib_pkey_t sidr_req_pkey; /* P_Key */ 1396 uint8_t sidr_req_reserved[2]; /* Reserved */ 1397 ib_svc_id_t sidr_req_service_id; /* Service Id */ 1398 uint8_t sidr_req_private_data[IBT_SIDR_REQ_PRIV_DATA_SZ]; 1399 /* Private Data */ 1400 } ibcm_sidr_req_msg_t; 1401 1402 1403 /* 1404 * CM SIDR_REP Message structure 1405 * 1406 * SIDR_REP returns the information necessary to communicate via UD 1407 * messages with the entity specified by SIDR_REQ:ServiceID 1408 */ 1409 typedef struct ibcm_sidr_rep_msg_s { 1410 uint32_t sidr_rep_request_id; /* Request id */ 1411 uint8_t sidr_rep_rep_status; /* Status */ 1412 uint8_t sidr_rep_add_info_len; /* Length of Add Info */ 1413 uint8_t sidr_rep_reserved1[2]; /* Reserved */ 1414 uint32_t sidr_rep_qpn_plus; /* QPN_24 RSV_8 */ 1415 /* since the 64-bit SID is not aligned, treat it as a byte array */ 1416 uint8_t sidr_rep_service_id[8]; /* Service Id */ 1417 ib_qkey_t sidr_rep_qkey; /* Q_KEY */ 1418 uint8_t sidr_rep_class_port_info[IBT_CM_SIDR_CP_LEN]; 1419 /* Class Port Info */ 1420 /* aka., add'l info */ 1421 uint8_t sidr_rep_private_data[IBT_SIDR_REP_PRIV_DATA_SZ]; 1422 /* Private data */ 1423 } ibcm_sidr_rep_msg_t; 1424 1425 typedef struct ibcm_classportinfo_msg_s { 1426 uint8_t BaseVersion; /* ver. of MAD base format */ 1427 uint8_t ClassVersion; /* ver. of MAD class format */ 1428 uint16_t CapabilityMask; /* capabilities of this class */ 1429 uint32_t RespTimeValue_plus; /* reserved : 27 bits */ 1430 /* resptime value : 5 bits */ 1431 uint64_t RedirectGID_hi; /* dest gid of redirect msgs */ 1432 uint64_t RedirectGID_lo; /* dest gid of redirect msgs */ 1433 uint32_t RedirectTC_plus; /* traffic class: 8 bits */ 1434 /* SL: 4 bits */ 1435 /* Flow label: 20 bits */ 1436 ib_lid_t RedirectLID; /* dlid for class services */ 1437 ib_pkey_t RedirectP_Key; /* p_key for class services */ 1438 uint32_t RedirectQP_plus; /* Reserved: 8 bits */ 1439 /* QPN: 24 bits */ 1440 ib_qkey_t RedirectQ_Key; /* q_key for class services */ 1441 uint64_t TrapGID_hi; /* dest gid of trap msgs */ 1442 uint64_t TrapGID_lo; /* dest gid of trap msgs */ 1443 uint32_t TrapTC_plus; /* Trap traffic class, etc., */ 1444 ib_lid_t TrapLID; /* dlid for traps */ 1445 ib_pkey_t TrapP_Key; /* p_key for traps */ 1446 uint32_t TrapHL_plus; /* Trap hop limit,etc., */ 1447 ib_qkey_t TrapQ_Key; /* q_key for traps */ 1448 } ibcm_classportinfo_msg_t; 1449 1450 /* All msgs are readonly on receiving side */ 1451 _NOTE(READ_ONLY_DATA(ibcm_req_msg_s)) 1452 _NOTE(READ_ONLY_DATA(ibcm_rep_msg_s)) 1453 _NOTE(READ_ONLY_DATA(ibcm_mra_msg_s)) 1454 _NOTE(READ_ONLY_DATA(ibcm_rej_msg_s)) 1455 _NOTE(READ_ONLY_DATA(ibcm_lap_msg_s)) 1456 _NOTE(READ_ONLY_DATA(ibcm_apr_msg_s)) 1457 _NOTE(READ_ONLY_DATA(ibcm_sidr_req_msg_s)) 1458 _NOTE(READ_ONLY_DATA(ibcm_sidr_rep_msg_s)) 1459 _NOTE(READ_ONLY_DATA(ibcm_rtu_msg_s)) 1460 _NOTE(READ_ONLY_DATA(ibcm_dreq_msg_s)) 1461 _NOTE(READ_ONLY_DATA(ibcm_drep_msg_s)) 1462 _NOTE(READ_ONLY_DATA(ibcm_classportinfo_msg_s)) 1463 1464 /* Prototype definitions for CM implementation functions */ 1465 1466 /* 1467 * The callback from IBMF to CM. This routines calls one of the CM 1468 * state processing functions depending upon mesg/attribute id 1469 * 1470 * ibmf_handle : IBMF handle on which CM MAD was received 1471 * pktp : MAD packet 1472 * args : IBMF receive mad callback arg 1473 */ 1474 void ibcm_recv_cb(ibmf_handle_t ibmf_handle, ibmf_msg_t *msgp, void *args); 1475 1476 /* 1477 * Prototypes for CM state transition handling functions 1478 */ 1479 1480 /* 1481 * The following are the CM state processing functions called on an 1482 * incoming REQ/REP/RTU/MRA/REJ/DREQ/DREP on active/passive sides 1483 * (Also handled are SIDR_REP and SIDR_REQ) 1484 * The brief description of these functions 1485 * Search based on CM message fields in CM's HCA entry. 1486 * Create/Delete state structures based on incoming message 1487 * Handle duplicate messages and state transitions 1488 * Set and Cancel timeouts 1489 * Handle stale connections 1490 * Change CM connection state 1491 * Call CM CEP state transition functions to update CEP state 1492 * and set CEP attributes 1493 * 1494 * INPUTS: 1495 * hcap: - IBMF callback argument 1496 * cm_input_mad: - ibmf message pointer of incoming MAD 1497 * cm_mad_addr - CM MAD address 1498 * 1499 * The state transition processing is specified in different functions based 1500 * on incoming message type rather than as one function because, the CM 1501 * processing is different for each of them. 1502 * 1503 * A global call table is initialized with these function addresses 1504 * (is defined in ibcm_impl.c), and invoked from ibcm_recv_cb 1505 * (IBMF's recv callback to CM) based on mesg/attribute id. 1506 */ 1507 void ibcm_process_req_msg(ibcm_hca_info_t *hcap, uint8_t *cm_input_mad, 1508 ibcm_mad_addr_t *cm_mad_addr); 1509 void ibcm_process_rep_msg(ibcm_hca_info_t *hcap, uint8_t *cm_input_mad, 1510 ibcm_mad_addr_t *cm_mad_addr); 1511 void ibcm_process_rtu_msg(ibcm_hca_info_t *hcap, uint8_t *cm_input_mad, 1512 ibcm_mad_addr_t *cm_mad_addr); 1513 void ibcm_process_dreq_msg(ibcm_hca_info_t *hcap, uint8_t *cm_input_mad, 1514 ibcm_mad_addr_t *cm_mad_addr); 1515 void ibcm_process_drep_msg(ibcm_hca_info_t *hcap, uint8_t *cm_input_mad, 1516 ibcm_mad_addr_t *cm_mad_addr); 1517 void ibcm_process_rej_msg(ibcm_hca_info_t *hcap, uint8_t *cm_input_mad, 1518 ibcm_mad_addr_t *cm_mad_addr); 1519 void ibcm_process_mra_msg(ibcm_hca_info_t *hcap, uint8_t *cm_input_mad, 1520 ibcm_mad_addr_t *cm_mad_addr); 1521 void ibcm_process_apr_msg(ibcm_hca_info_t *hcap, uint8_t *cm_input_mad, 1522 ibcm_mad_addr_t *cm_mad_addr); 1523 void ibcm_process_lap_msg(ibcm_hca_info_t *hcap, uint8_t *cm_input_mad, 1524 ibcm_mad_addr_t *cm_mad_addr); 1525 void ibcm_process_sidr_req_msg(ibcm_hca_info_t *hcap, 1526 uint8_t *cm_input_mad, ibcm_mad_addr_t *cm_mad_addr); 1527 void ibcm_process_sidr_rep_msg(ibcm_hca_info_t *hcap, 1528 uint8_t *cm_input_mad, ibcm_mad_addr_t *cm_mad_addr); 1529 1530 typedef enum ibcm_proceed_error_e { 1531 IBCM_PROCEED_INVALID_NONE = 0, 1532 IBCM_PROCEED_INVALID_EVENT, 1533 IBCM_PROCEED_INVALID_EVENT_STATE, 1534 IBCM_PROCEED_INVALID_PRIV_SZ, 1535 IBCM_PROCEED_INVALID_LAP 1536 } ibcm_proceed_error_t; 1537 1538 /* Encapsulates the information that client returns back from CM callback */ 1539 typedef struct ibcm_clnt_reply_info_s { 1540 ibt_cm_proceed_reply_t *reply_event; 1541 void *priv_data; 1542 ibt_priv_data_len_t priv_data_len; 1543 } ibcm_clnt_reply_info_t; 1544 1545 /* Encapsulates the information that UD client returns back from CM callback */ 1546 typedef struct ibcm_ud_clnt_reply_info_s { 1547 ib_qpn_t ud_qpn; 1548 ib_qkey_t ud_qkey; 1549 ibt_redirect_info_t *redirect_infop; 1550 void *priv_data; 1551 ibt_priv_data_len_t priv_data_len; 1552 } ibcm_ud_clnt_reply_info_t; 1553 1554 /* 1555 * Prototypes for CM CEP state transition handling functions. These are 1556 * called from CM connection state transition handling functions. 1557 * 1558 * The brief description of these functions : 1559 * Validate CEP related attributes in the messages 1560 * Change CEP state 1561 * Set CEP attributes (modify CEP) 1562 * Call client/server callback handlers 1563 * Fill up the response MADs 1564 * 1565 * The arguments are : 1566 * statep: Connection state structure 1567 * cm_req/rep/rtu/rej msg : Received CM message 1568 * cm_output_mad : The response CM MAD with some of the fields filled in 1569 * The cm output mad is allocated by CM state transition 1570 * functions and has generic MAD header 1571 * Certain fields like com id, etc., are filled by CM 1572 * connection state transition functions that are above 1573 */ 1574 1575 /* QP state transition function called for an incoming REQ on passive side */ 1576 ibcm_status_t ibcm_cep_state_req(ibcm_state_data_t *statep, 1577 ibcm_req_msg_t *cm_req_msg, ibt_cm_reason_t *reason, 1578 uint8_t *arej_info_len); 1579 1580 /* Processes QP state machine based on return values from cm handler */ 1581 ibcm_status_t ibcm_process_cep_req_cm_hdlr(ibcm_state_data_t *statep, 1582 ibt_cm_status_t cb_status, 1583 ibcm_clnt_reply_info_t *clnt_info, 1584 ibt_cm_reason_t *reject_reason, uint8_t *arej_len, 1585 ibcm_req_msg_t *cm_req_msgp); 1586 1587 /* Processes CM state machine based on return values from ibcm_cep_state_req */ 1588 void ibcm_handle_cep_req_response(ibcm_state_data_t *statep, 1589 ibcm_status_t response, ibt_cm_reason_t reject_reason, 1590 uint8_t arej_info_len); 1591 1592 /* QP state transition function called for an incoming REP on active side */ 1593 ibcm_status_t ibcm_cep_state_rep(ibcm_state_data_t *statep, 1594 ibcm_rep_msg_t *cm_rep_msg, ibt_cm_reason_t *reason, 1595 uint8_t *arej_info_len); 1596 1597 /* Processes QP state machine based on return values from cm handler */ 1598 ibcm_status_t ibcm_process_cep_rep_cm_hdlr(ibcm_state_data_t *statep, 1599 ibt_cm_status_t cb_status, 1600 ibcm_clnt_reply_info_t *clnt_info, 1601 ibt_cm_reason_t *reject_reason, uint8_t *arej_len, 1602 ibcm_rep_msg_t *cm_rep_msgp); 1603 1604 /* Processes CM state machine based on return values from ibcm_cep_state_rep */ 1605 void ibcm_handle_cep_rep_response(ibcm_state_data_t *statep, 1606 ibcm_status_t response, ibt_cm_reason_t reject_reason, 1607 uint8_t arej_info_len, ibcm_rep_msg_t *rep_msgp); 1608 1609 /* QP state transition function called for an incoming RTU on passive side */ 1610 void ibcm_cep_state_rtu(ibcm_state_data_t *statep, 1611 ibcm_rtu_msg_t *cm_rtu_msg); 1612 1613 /* QP state transition func called for an incoming REJ on active/passive side */ 1614 void ibcm_cep_state_rej(ibcm_state_data_t *statep, 1615 ibcm_rej_msg_t *cm_rej_msg, ibcm_conn_state_t rej_state); 1616 1617 /* QP state transition func for an incoming REJ on active side in est state */ 1618 void ibcm_cep_state_rej_est(ibcm_state_data_t *statep); 1619 1620 /* 1621 * QP state transition function called for an outgoing RTU on active side, 1622 * after setting CEP to RTS state active/passive side 1623 */ 1624 void ibcm_cep_send_rtu(ibcm_state_data_t *statep); 1625 1626 1627 /* QP state transition function called for an incoming LAP */ 1628 ibcm_status_t ibcm_cep_state_lap(ibcm_state_data_t *statep, 1629 ibcm_lap_msg_t *lap_msg, ibcm_apr_msg_t *apr_msg); 1630 1631 /* Processes QP state machine based on return value from cm handler for LAP */ 1632 void ibcm_process_cep_lap_cm_hdlr(ibcm_state_data_t *statep, 1633 ibt_cm_status_t cb_status, 1634 ibcm_clnt_reply_info_t *clnt_info, 1635 ibcm_lap_msg_t *lap_msg, ibcm_apr_msg_t *apr_msg); 1636 1637 void ibcm_post_apr_mad(ibcm_state_data_t *statep); 1638 1639 void ibcm_cep_state_apr(ibcm_state_data_t *statep, 1640 ibcm_lap_msg_t *lap_msg, ibcm_apr_msg_t *apr_msg); 1641 1642 /* Processes CM state machine based on return value from cm handler */ 1643 void ibcm_handle_cep_dreq_response(ibcm_state_data_t *statep, 1644 void *priv_data, ibt_priv_data_len_t priv_data_len); 1645 1646 /* Processes CM UD state machine based on return values from cm handler */ 1647 void ibcm_process_sidr_req_cm_hdlr(ibcm_ud_state_data_t *ud_statep, 1648 ibt_cm_status_t cb_status, 1649 ibcm_ud_clnt_reply_info_t *ud_clnt_info, 1650 ibt_sidr_status_t *sidr_status, 1651 ibcm_sidr_rep_msg_t *sidr_repp); 1652 1653 void ibcm_proceed_via_taskq(void *targs); 1654 void ibcm_ud_proceed_via_taskq(void *targs); 1655 1656 /* 1657 * Builds the reply MAD address based on "incoming mad addr" that is 1658 * supplied to it as an arg. 1659 * Swaps the source and destination lids in ibmf_addr_info_t 1660 * Swaps the source and destination gids in ib_grh_t 1661 * 1662 * INPUTS: 1663 * incoming_cm_mad_addr - Address information in the incoming MAD 1664 * reply_cm_mad_addr - Derived address for the reply MAD 1665 * The reply MAD address is derived based 1666 * address information of incoming CM MAD 1667 */ 1668 void ibcm_build_reply_mad_addr(ibcm_mad_addr_t *incoming_cm_mad_addr, 1669 ibcm_mad_addr_t *reply_cm_mad_addr); 1670 1671 /* Posts RC CM MAD using IBMF */ 1672 void ibcm_post_rc_mad(ibcm_state_data_t *statep, ibmf_msg_t *msgp, 1673 ibmf_msg_cb_t post_cb, void *args); 1674 1675 /* Posts UD CM MAD using IBMF */ 1676 void ibcm_post_ud_mad(ibcm_ud_state_data_t *ud_statep, ibmf_msg_t *msgp, 1677 ibmf_msg_cb_t ud_post_cb, void *args); 1678 1679 /* Posts CM MAD using IBMF */ 1680 ibt_status_t ibcm_post_mad(ibmf_msg_t *msgp, ibcm_mad_addr_t *cm_mad_addr, 1681 ibmf_msg_cb_t post_cb, void *args); 1682 1683 /* Post REJ MAD */ 1684 void ibcm_post_rej_mad(ibcm_state_data_t *statep, ibt_cm_reason_t reason, 1685 int who, void *addl_rej_info, uint8_t arej_info_len); 1686 1687 /* Post REP MAD */ 1688 void ibcm_post_rep_mad(ibcm_state_data_t *statep); 1689 1690 /* Post RTU MAD */ 1691 ibcm_status_t ibcm_post_rtu_mad(ibcm_state_data_t *statep); 1692 1693 /* Post DREQ MAD */ 1694 void ibcm_post_dreq_mad(void *statep); 1695 1696 /* Post LAP MAD */ 1697 void ibcm_post_lap_mad(ibcm_state_data_t *statep); 1698 1699 1700 /* 1701 * Posts CM SIDR MAD using IBMF in blocking mode 1702 * 1703 * INPUTS: 1704 * ud_statep: UD statep which is posting the mad 1705 * cm_mad_addr: Address information for the MAD to be posted 1706 * status: SIDR status 1707 */ 1708 void ibcm_post_sidr_rep_mad(ibcm_ud_state_data_t *ud_statep, 1709 ibt_sidr_status_t status); 1710 1711 /* prototypes to resend RC mad and UD MAD */ 1712 void ibcm_resend_rep_mad(ibcm_state_data_t *statep); 1713 void ibcm_resend_rtu_mad(ibcm_state_data_t *statep); 1714 void ibcm_resend_rej_mad(ibcm_state_data_t *statep); 1715 void ibcm_resend_mra_mad(ibcm_state_data_t *statep); 1716 void ibcm_resend_srep_mad(ibcm_ud_state_data_t *statep); 1717 1718 1719 /* Helper function used in connection abort processing */ 1720 void ibcm_process_abort(ibcm_state_data_t *statep); 1721 1722 /* 1723 * Prototypes for CM functions that lookup for a connection state structure 1724 */ 1725 1726 /* 1727 * ibcm_lookup_msg: 1728 * 1729 * Retrieves an existing state structure or creates a new one if none found. 1730 * This function is used during passive side of connection establishment for 1731 * INCOMING REQ/REJ/RTU/MRA 1732 * This function is used during active side of connection establishment for 1733 * INCOMING REP/REJ/MRA 1734 * This function is used during active side of connection establishment for 1735 * an outgoing REQ. 1736 * 1737 * NOTE: IBCM_LOOKP_FAIL is only returned if a new entry wasn't created and 1738 * a match wasn't found. 1739 * 1740 * Arguments are:- 1741 * ibcm_event_type_t - what type of message 1742 * incoming REQ, REP, REJ, MRA, RTU, DREQ, DREP 1743 * local_comid - ONLY *NOT* valid for incoming REQ. 1744 * needed for others 1745 * remote_qpn - Remote CM's QP number 1746 * remote_hca_guid - ONLY VALID FOR incoming REQ. 1747 * Ignored for others 1748 * hcap - HCA entry table pointer 1749 * statep - "return"ed state pointer 1750 * 1751 * Return Values: 1752 * IBCM_LOOKUP_NEW - new statep allocated 1753 * IBCM_LOOKUP_EXISTS - found an existing entry 1754 * IBCM_LOOKUP_FAIL - failed to find an entry 1755 * IBCM_MEMORY_FAILURE - failed to get memory 1756 * iff flags != IBT_CHAN_BLOCKING 1757 */ 1758 ibcm_status_t ibcm_lookup_msg(ibcm_event_type_t event_type, 1759 ib_com_id_t local_comid, ib_qpn_t remote_qpn, 1760 ib_guid_t remote_hca_guid, ibcm_hca_info_t *hcap, 1761 ibcm_state_data_t **statep); 1762 1763 1764 /* 1765 * Routines for CM SIDR state structure list manipulation 1766 * Wherever possible, the list routines of ibtl are used 1767 * for list manipulation 1768 */ 1769 1770 /* 1771 * Finds an entry based on lid, gid and grh exists fields 1772 * lid: LID of incoming SIDR REQ 1773 * gid: GID of incoming SIDR REQ 1774 * grh_exists: TRUE if GRH exists in the incoming SIDR REQ 1775 * hcap: CM State HCA entry ptr to search for SIDR state structure 1776 * statep: Returns a valid state structure, if one exists based 1777 * on lid, gid and grh_exists fields 1778 * flag: whether to just look OR to look and add if it doesn't exist. 1779 */ 1780 ibcm_status_t ibcm_find_sidr_entry(ibcm_sidr_srch_t *srch_param, 1781 ibcm_hca_info_t *hcap, 1782 ibcm_ud_state_data_t **statep, 1783 ibcm_lookup_flag_t flag); 1784 1785 ibcm_ud_state_data_t *ibcm_add_sidr_entry(ibcm_sidr_srch_t *srch_param, 1786 ibcm_hca_info_t *hcap); 1787 1788 /* 1789 * Deletes a given state structure, from both hca state and passive trees 1790 * If ref cnt is zero, deallocates all buffers and memory of state data 1791 */ 1792 void ibcm_delete_state_data(ibcm_state_data_t *statep); 1793 1794 /* 1795 * Deallocates all the buffers and memory of state data. 1796 * This function must be called, only when ref_cnt is zero. 1797 */ 1798 void ibcm_dealloc_state_data(ibcm_state_data_t *statep); 1799 1800 /* 1801 * Deletes a given UD state structure, from SIDR list. 1802 * The routine acquires and releases the SIDR list lock. 1803 */ 1804 void ibcm_delete_ud_state_data(ibcm_ud_state_data_t *statep); 1805 void ibcm_dealloc_ud_state_data(ibcm_ud_state_data_t *statep); 1806 1807 /* 1808 * Service ID entry create and lookup functions 1809 */ 1810 1811 /* 1812 * Adds/looks-up an ibcm_svc_info_t entry in the CM's global table. 1813 * This global table is defined in ibcm_impl.c. 1814 * 1815 * svc_info_list_lock must be held for RW_READER by caller of 1816 * ibcm_find_svc_entry(). 1817 * 1818 * Arguments are:- 1819 * sid - service id 1820 * num_sids - Number (Range) of service-ids 1821 * 1822 * Return values: 1823 * Pointer to ibcm_svc_info_t on success, otherwise NULL. 1824 */ 1825 int ibcm_svc_compare(const void *p1, const void *p2); 1826 ibcm_svc_info_t *ibcm_create_svc_entry(ib_svc_id_t sid, int num_sids); 1827 ibcm_svc_info_t *ibcm_find_svc_entry(ib_svc_id_t sid); 1828 1829 /* 1830 * The following are the function prototypes for various id initialization, 1831 * allocation, free and destroy operations. The cm id allocations are based 1832 * on vmem operations 1833 * The service id's are maintained globally per host 1834 * The com id and req id's are maintained per hca 1835 * To maintain compatibility with intel, service ids are allocated on a 32 bit 1836 * range, though spec has 64 bit range for service id's 1837 */ 1838 ibcm_status_t ibcm_init_ids(); 1839 void ibcm_fini_ids(); 1840 1841 ibcm_status_t ibcm_init_hca_ids(ibcm_hca_info_t *hcap); 1842 void ibcm_fini_hca_ids(ibcm_hca_info_t *hcap); 1843 1844 ibcm_status_t ibcm_alloc_comid(ibcm_hca_info_t *hcap, ib_com_id_t *comid); 1845 void ibcm_free_comid(ibcm_hca_info_t *hcap, ib_com_id_t comid); 1846 1847 ibcm_status_t ibcm_alloc_reqid(ibcm_hca_info_t *hcap, uint32_t *reqid); 1848 void ibcm_free_reqid(ibcm_hca_info_t *hcap, uint32_t reqid); 1849 1850 ib_svc_id_t ibcm_alloc_local_sids(int num_sids); 1851 void ibcm_free_local_sids(ib_svc_id_t service_id, int num_sids); 1852 1853 uint64_t ibcm_generate_tranid(uint8_t event, uint32_t id, 1854 uint32_t cm_tran_priv); 1855 1856 void ibcm_decode_tranid(uint64_t tran_id, uint32_t *cm_tran_priv); 1857 1858 ibcm_status_t ibcm_ar_init(void); 1859 ibcm_status_t ibcm_ar_fini(void); 1860 1861 /* 1862 * These functions are called to do timeout processing from CM connection 1863 * state transitions. (Also for SIDR REQ and SIDR REP processing) 1864 * 1865 * Brief description : 1866 * If retry count is below max retry value, then post the stored response 1867 * MAD using IBMF in blocking mode, adjusts remaining retry counters. 1868 * If retry counter reaches max value, then retry failure handling is 1869 * done here 1870 * 1871 * CM will ensure that the state data structure of the associated 1872 * timeout is valid when this timeout function is called. 1873 * (See timer_stored_state in ibcm_state_data_t and 1874 * ud_timer_stored_state in ibcm_ud_state_data_t) 1875 */ 1876 void ibcm_timeout_cb(void *arg); 1877 void ibcm_sidr_timeout_cb(void *arg); 1878 1879 /* 1880 * function prototypes for IBMF send completion callbacks on non-blocking 1881 * MAD posts 1882 */ 1883 void ibcm_post_req_complete(ibmf_handle_t ibmf_handle, ibmf_msg_t *msgp, 1884 void *args); 1885 void ibcm_post_rep_wait_complete(ibmf_handle_t ibmf_handle, ibmf_msg_t *msgp, 1886 void *args); /* MRA Rcvd on active side */ 1887 void ibcm_post_rep_complete(ibmf_handle_t ibmf_handle, ibmf_msg_t *msgp, 1888 void *args); 1889 void ibcm_resend_post_rep_complete(ibmf_handle_t ibmf_handle, 1890 ibmf_msg_t *msgp, void *args); 1891 void ibcm_post_mra_rep_complete(ibmf_handle_t ibmf_handle, ibmf_msg_t *msgp, 1892 void *args); /* MRA Rcvd on passive side */ 1893 void ibcm_post_rej_complete(ibmf_handle_t ibmf_handle, ibmf_msg_t *msgp, 1894 void *args); 1895 void ibcm_post_dreq_complete(ibmf_handle_t ibmf_handle, ibmf_msg_t *msgp, 1896 void *args); 1897 void ibcm_post_drep_complete(ibmf_handle_t ibmf_handle, ibmf_msg_t *msgp, 1898 void *args); 1899 void ibcm_post_lap_complete(ibmf_handle_t ibmf_handle, ibmf_msg_t *msgp, 1900 void *args); 1901 void ibcm_post_apr_complete(ibmf_handle_t ibmf_handle, ibmf_msg_t *msgp, 1902 void *args); 1903 void ibcm_post_stored_apr_complete(ibmf_handle_t ibmf_handle, 1904 ibmf_msg_t *msgp, void *args); 1905 void ibcm_post_mra_lap_complete(ibmf_handle_t ibmf_handle, ibmf_msg_t *msgp, 1906 void *args); /* MRA Rcvd for LAP on active side */ 1907 void ibcm_post_mra_complete(ibmf_handle_t ibmf_handle, ibmf_msg_t *msgp, 1908 void *args); /* for MRA sender */ 1909 void ibcm_post_rtu_complete(ibmf_handle_t ibmf_handle, ibmf_msg_t *msgp, 1910 void *args); 1911 1912 void ibcm_post_sidr_req_complete(ibmf_handle_t ibmf_handle, 1913 ibmf_msg_t *msgp, void *args); 1914 1915 /* 1916 * ibcm_find_hca_entry: 1917 * Given a HCA's GUID find out ibcm_hca_info_t entry for that HCA 1918 * This entry can be then used to access AVL tree/SIDR list etc. 1919 * 1920 * NOTE: This entry is not removed from the "ibcm_hca_listp". 1921 * And this function is called with ibcm_hca_list_mutex mutex held. 1922 * 1923 * INPUTS: 1924 * hca_guid - HCA's guid 1925 * 1926 * RETURN VALUE: 1927 * hcap - if a match is found, else NULL 1928 */ 1929 ibcm_hca_info_t *ibcm_find_hca_entry(ib_guid_t hca_guid); 1930 ibcm_hca_info_t *ibcm_find_hcap_entry(ib_guid_t hca_guid); 1931 void ibcm_delete_hca_entry(ibcm_hca_info_t *hcap); 1932 1933 /* Routines that manage the hca's temporary access count */ 1934 ibcm_status_t ibcm_inc_hca_acc_cnt(ibcm_hca_info_t *hca); 1935 void ibcm_dec_hca_acc_cnt(ibcm_hca_info_t *hca); 1936 1937 /* Routines that manage the hca's resource count */ 1938 void ibcm_inc_hca_res_cnt(ibcm_hca_info_t *hca); 1939 void ibcm_dec_hca_res_cnt(ibcm_hca_info_t *hca); 1940 1941 /* Routines that manage the hca's service count */ 1942 void ibcm_inc_hca_svc_cnt(ibcm_hca_info_t *hca); 1943 void ibcm_dec_hca_svc_cnt(ibcm_hca_info_t *hca); 1944 1945 /* Routine to fetch the saa_handle */ 1946 ibmf_saa_handle_t ibcm_get_saa_handle(ibcm_hca_info_t *hcap, uint8_t port); 1947 1948 /* Allow some flow control of RC connection initiations */ 1949 void ibcm_rc_flow_control_enter(void); 1950 void ibcm_rc_flow_control_exit(void); 1951 void ibcm_rc_flow_control_stall(void); 1952 void ibcm_close_flow_control_enter(void); 1953 void ibcm_close_flow_control_exit(void); 1954 1955 /* Allow some flow control of SA requests */ 1956 void ibcm_sa_access_enter(void); 1957 void ibcm_sa_access_exit(void); 1958 1959 /* 1960 * ibcm_cep_to_error_state: 1961 * Helper function to transition a CEP to ERROR state 1962 * 1963 * NOTE: This function checks if ch_qp is valid or ch_eec and calls 1964 * into IBTL to transition the CEP. 1965 * 1966 * INPUTS: 1967 * statep - Connection state pointer 1968 * 1969 * RETURN VALUE: 1970 * IBT_SUCCESS - if CEP transition succeeded; else error 1971 */ 1972 ibt_status_t ibcm_cep_to_error_state(ibcm_state_data_t *statep); 1973 1974 /* 1975 * Processes the pending stateps in a linked list. The operations are to 1976 * invoke a cm handler or delete statep 1977 * When the above operations are required on statep from a timeout handler, 1978 * they are linked for later processing by an independent thread 1979 */ 1980 void ibcm_process_tlist(); 1981 /* Links RC stateps to an RC timeout processing list */ 1982 void ibcm_add_tlist(ibcm_state_data_t *statep); 1983 1984 /* Links SIDR/UD stateps to an SIDR/UD timeout processing list */ 1985 void ibcm_add_ud_tlist(ibcm_ud_state_data_t *ud_statep); 1986 1987 /* 1988 * This call either aborts a pending or completes a in-progress LAP/APR 1989 * operation 1990 */ 1991 void ibcm_sync_lapr_idle(ibcm_state_data_t *statep); 1992 1993 void ibcm_process_rc_recycle(void *recycle_arg); 1994 1995 /* 1996 * Helper function to handle endianess in case of Service Data. 1997 * Used by ibt_bind_service() and ibt_get_paths(). 1998 */ 1999 void ibcm_swizzle_from_srv(ibt_srv_data_t *sb_data, uint8_t *service_bytes); 2000 void ibcm_swizzle_to_srv(uint8_t *service_bytes, ibt_srv_data_t *sb_data); 2001 2002 /* Misc ibcm global variables */ 2003 extern char cmlog[]; 2004 extern ibt_clnt_hdl_t ibcm_ibt_handle; 2005 extern taskq_t *ibcm_taskq; 2006 extern ibcm_state_handler_t ibcm_sm_funcs_tbl[]; 2007 extern uint8_t ibcm_timeout_list_flags; 2008 extern ibcm_classportinfo_msg_t ibcm_clpinfo; 2009 2010 /* Global lists */ 2011 extern avl_tree_t ibcm_svc_avl_tree; /* global service id tree */ 2012 extern ibcm_state_data_t *ibcm_timeout_list_hdr, *ibcm_timeout_list_tail; 2013 extern ibcm_ud_state_data_t *ibcm_ud_timeout_list_hdr, 2014 *ibcm_ud_timeout_list_tail; 2015 /* Default global retry counts */ 2016 extern uint32_t ibcm_max_retries; 2017 extern uint32_t ibcm_max_sa_retries; 2018 extern int ibcm_sa_timeout_delay; /* in ticks */ 2019 2020 /* Various default global timers */ 2021 extern ibt_rnr_nak_time_t ibcm_default_rnr_nak_time; 2022 2023 extern clock_t ibcm_local_processing_time; /* usecs */ 2024 extern clock_t ibcm_remote_response_time; 2025 extern ib_time_t ibcm_max_sidr_rep_proctime; 2026 extern ib_time_t ibcm_max_sidr_rep_store_time; 2027 extern uint32_t ibcm_adj_btime; 2028 extern uint32_t ibcm_sw_delay; 2029 2030 extern ib_time_t ibcm_max_ib_pkt_lt; 2031 extern ib_time_t ibcm_max_ib_mad_pkt_lt; 2032 2033 /* Global locks */ 2034 extern kmutex_t ibcm_svc_info_lock; 2035 extern kmutex_t ibcm_global_hca_lock; 2036 extern kmutex_t ibcm_qp_list_lock; 2037 extern kmutex_t ibcm_timeout_list_lock; 2038 extern kmutex_t ibcm_recv_mutex; 2039 2040 /* Global cond variables */ 2041 extern kcondvar_t ibcm_global_hca_cv; 2042 extern kcondvar_t ibcm_svc_info_cv; 2043 extern kcondvar_t ibcm_timeout_list_cv; 2044 extern kcondvar_t ibcm_timeout_thread_done_cv; 2045 2046 _NOTE(LOCK_ORDER(ibcm_state_data_s::state_mutex ibcm_timeout_list_lock)) 2047 _NOTE(LOCK_ORDER(ibcm_ud_state_data_s::ud_state_mutex ibcm_timeout_list_lock)) 2048 _NOTE(LOCK_ORDER(ibcm_hca_info_s::hca_state_rwlock 2049 ibcm_state_data_s::state_mutex)) 2050 _NOTE(LOCK_ORDER(ibcm_hca_info_s::hca_sidr_list_lock 2051 ibcm_ud_state_data_s::ud_state_mutex)) 2052 2053 _NOTE(READ_ONLY_DATA(ibcm_local_processing_time ibcm_remote_response_time 2054 ibcm_max_sidr_rep_proctime ibcm_max_sidr_rep_store_time ibcm_adj_btime 2055 ibcm_sw_delay ibcm_max_retries ibcm_max_sa_retries)) 2056 2057 /* 2058 * miscellaneous defines for retries, times etc. 2059 */ 2060 #define IBCM_MAX_RETRIES 7 /* Max CM retries for a msg */ 2061 #define IBCM_LOCAL_RESPONSE_TIME 250000 /* Local CM processing time */ 2062 /* in usecs */ 2063 #define IBCM_REMOTE_RESPONSE_TIME 250000 /* Remote CM response time */ 2064 /* in usecs */ 2065 #define IBCM_MAX_SIDR_PROCESS_TIME 16 /* Time to process SIDR REP */ 2066 #define IBCM_MAX_SIDR_PKT_LIFE_TIME 9 /* Approx pkt lt for UD srver */ 2067 2068 #define IBCM_MAX_IB_PKT_LT 18 /* 1 second */ 2069 #define IBCM_MAX_IB_MAD_PKT_LT 18 /* 1 second */ 2070 2071 #define IBCM_MAX_SA_RETRIES 0 /* Max CM retry for SA update */ 2072 2073 /* versions for CM MADs */ 2074 #define IBCM_MAD_BASE_VERSION 1 2075 #define IBCM_MAD_CLASS_VERSION 2 2076 2077 /* for Class_Port_Info stuff - see section 16.7.3.1 in Vol1 IB Spec */ 2078 #define IBCM_CPINFO_CAP_RC 0x0200 /* RC is supported */ 2079 #define IBCM_CPINFO_CAP_RD 0x0400 /* RD is supported */ 2080 #define IBCM_CPINFO_CAP_RAW 0x0800 /* Raw Datagrams supported */ 2081 #define IBCM_CPINFO_CAP_UC 0x1000 /* UC supported */ 2082 #define IBCM_CPINFO_CAP_SIDR 0x2000 /* SIDR supported */ 2083 2084 /* 2085 * for debug purposes 2086 */ 2087 #ifdef DEBUG 2088 extern int ibcm_test_mode; 2089 2090 void ibcm_query_qp(ibmf_handle_t ibmf_hdl, ibmf_qp_handle_t ibmf_qp); 2091 void ibcm_dump_raw_message(uchar_t *); 2092 void ibcm_dump_srvrec(sa_service_record_t *); 2093 void ibcm_dump_pathrec(sa_path_record_t *); 2094 void ibcm_dump_noderec(sa_node_record_t *); 2095 2096 void ibcm_query_classport_info(ibt_channel_hdl_t channel); 2097 2098 #define IBCM_DUMP_RAW_MSG ibcm_dump_raw_message 2099 #define IBCM_DUMP_SERVICE_REC ibcm_dump_srvrec 2100 #define IBCM_DUMP_PATH_REC ibcm_dump_pathrec 2101 #define IBCM_DUMP_NODE_REC ibcm_dump_noderec 2102 #else 2103 #define IBCM_DUMP_RAW_MSG 0 && 2104 #define IBCM_DUMP_SERVICE_REC 0 && 2105 #define IBCM_DUMP_PATH_REC 0 && 2106 #define IBCM_DUMP_NODE_REC 0 && 2107 #endif 2108 2109 ibt_status_t ibcm_ibmf_analyze_error(int ibmf_status); 2110 2111 ibt_status_t ibcm_contact_sa_access(ibmf_saa_handle_t saa_handle, 2112 ibmf_saa_access_args_t *access_args, size_t *length, void **results_p); 2113 2114 #ifdef __cplusplus 2115 } 2116 #endif 2117 2118 2119 #endif /* _SYS_IB_MGT_IBCM_IBCM_IMPL_H */ 2120