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