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