10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * The contents of this file are subject to the terms of the
53870Srm78299 * Common Development and Distribution License (the "License").
63870Srm78299 * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate *
80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate * See the License for the specific language governing permissions
110Sstevel@tonic-gate * and limitations under the License.
120Sstevel@tonic-gate *
130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate *
190Sstevel@tonic-gate * CDDL HEADER END
200Sstevel@tonic-gate */
21*12787SLida.Horn@Oracle.COM
220Sstevel@tonic-gate /*
23*12787SLida.Horn@Oracle.COM * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
240Sstevel@tonic-gate */
250Sstevel@tonic-gate
260Sstevel@tonic-gate /*
270Sstevel@tonic-gate * This file implements the Directed Route (DR) loopback support in IBMF.
280Sstevel@tonic-gate */
290Sstevel@tonic-gate
300Sstevel@tonic-gate #include <sys/ib/mgt/ibmf/ibmf_impl.h>
310Sstevel@tonic-gate #include <sys/ib/mgt/ib_mad.h>
320Sstevel@tonic-gate
33*12787SLida.Horn@Oracle.COM #define MELLANOX_VENDOR 0x15b3
34*12787SLida.Horn@Oracle.COM
350Sstevel@tonic-gate extern int ibmf_trace_level;
360Sstevel@tonic-gate
370Sstevel@tonic-gate static int ibmf_i_dr_loopback_filter(ibmf_client_t *clientp,
380Sstevel@tonic-gate ibmf_msg_impl_t *msgimplp, int blocking);
390Sstevel@tonic-gate static void ibmf_i_dr_loopback_term(ibmf_client_t *clientp,
400Sstevel@tonic-gate ibmf_msg_impl_t *msgimplp, int blocking);
410Sstevel@tonic-gate
420Sstevel@tonic-gate /*
430Sstevel@tonic-gate * ibmf_i_check_for_loopback():
440Sstevel@tonic-gate * Check for DR loopback traffic
450Sstevel@tonic-gate */
460Sstevel@tonic-gate int
ibmf_i_check_for_loopback(ibmf_msg_impl_t * msgimplp,ibmf_msg_cb_t msg_cb,void * msg_cb_args,ibmf_retrans_t * retrans,boolean_t * loopback)470Sstevel@tonic-gate ibmf_i_check_for_loopback(ibmf_msg_impl_t *msgimplp, ibmf_msg_cb_t msg_cb,
480Sstevel@tonic-gate void *msg_cb_args, ibmf_retrans_t *retrans, boolean_t *loopback)
490Sstevel@tonic-gate {
500Sstevel@tonic-gate sm_dr_mad_hdr_t *dr_hdr;
510Sstevel@tonic-gate boolean_t blocking;
520Sstevel@tonic-gate int status;
530Sstevel@tonic-gate ibmf_ci_t *cip = ((ibmf_client_t *)msgimplp->im_client)->ic_myci;
540Sstevel@tonic-gate
550Sstevel@tonic-gate IBMF_TRACE_1(IBMF_TNF_DEBUG, DPRINT_L4,
560Sstevel@tonic-gate ibmf_i_check_for_loopback_start, IBMF_TNF_TRACE, "",
570Sstevel@tonic-gate "ibmf_i_check_for_loopback() enter, msg = 0x%p\n",
580Sstevel@tonic-gate tnf_opaque, msg, msgimplp);
590Sstevel@tonic-gate
600Sstevel@tonic-gate *loopback = B_FALSE;
610Sstevel@tonic-gate dr_hdr = (sm_dr_mad_hdr_t *)msgimplp->im_msgbufs_send.im_bufs_mad_hdr;
620Sstevel@tonic-gate
630Sstevel@tonic-gate /*
640Sstevel@tonic-gate * Some HCAs do not handle directed route loopback MADs.
650Sstevel@tonic-gate * Such MADs are sent out on the wire instead of being looped back.
660Sstevel@tonic-gate * This behavior causes the SM to hang since the SM starts
670Sstevel@tonic-gate * its sweep with loopback DR MADs.
680Sstevel@tonic-gate * This ibmf workaround does the loopback without passing the MAD
690Sstevel@tonic-gate * into the transport layer.
70*12787SLida.Horn@Oracle.COM * We should really check a property of the hardware to determine
71*12787SLida.Horn@Oracle.COM * whether or not an IB HCA can "hear" itself rather than
72*12787SLida.Horn@Oracle.COM * checking for specific HCAs or vendor of HCAs.
730Sstevel@tonic-gate */
740Sstevel@tonic-gate if ((dr_hdr->MgmtClass == MAD_MGMT_CLASS_SUBN_DIRECT_ROUTE) &&
75*12787SLida.Horn@Oracle.COM (dr_hdr->HopCount == 0) && (cip->ci_vendor_id == MELLANOX_VENDOR)) {
760Sstevel@tonic-gate if (msg_cb == NULL) {
770Sstevel@tonic-gate blocking = B_TRUE;
780Sstevel@tonic-gate } else {
790Sstevel@tonic-gate blocking = B_FALSE;
800Sstevel@tonic-gate }
810Sstevel@tonic-gate
820Sstevel@tonic-gate ibmf_i_init_msg(msgimplp, msg_cb, msg_cb_args, retrans,
830Sstevel@tonic-gate blocking);
840Sstevel@tonic-gate
850Sstevel@tonic-gate status = ibmf_i_dr_loopback_filter(msgimplp->im_client,
860Sstevel@tonic-gate msgimplp, blocking);
870Sstevel@tonic-gate if (status != IBMF_SUCCESS) {
880Sstevel@tonic-gate IBMF_TRACE_1(IBMF_TNF_NODEBUG, DPRINT_L1,
890Sstevel@tonic-gate ibmf_i_check_for_loopback_err,
900Sstevel@tonic-gate "ibmf_i_check_for_loopback(): %s\n",
910Sstevel@tonic-gate IBMF_TNF_ERROR, "", tnf_string, msg,
920Sstevel@tonic-gate "Failure in DR loopback filter");
930Sstevel@tonic-gate IBMF_TRACE_0(IBMF_TNF_DEBUG, DPRINT_L4,
940Sstevel@tonic-gate ibmf_i_check_for_loopback_end, IBMF_TNF_TRACE, "",
950Sstevel@tonic-gate "ibmf_i_check_for_loopback() exit\n");
960Sstevel@tonic-gate return (status);
970Sstevel@tonic-gate }
980Sstevel@tonic-gate
990Sstevel@tonic-gate *loopback = B_TRUE;
1000Sstevel@tonic-gate }
1010Sstevel@tonic-gate
1020Sstevel@tonic-gate IBMF_TRACE_0(IBMF_TNF_DEBUG, DPRINT_L4, ibmf_i_check_for_loopback_end,
1030Sstevel@tonic-gate IBMF_TNF_TRACE, "", "ibmf_i_check_for_loopback() exit\n");
1040Sstevel@tonic-gate
1050Sstevel@tonic-gate return (IBMF_SUCCESS);
1060Sstevel@tonic-gate
1070Sstevel@tonic-gate }
1080Sstevel@tonic-gate
1090Sstevel@tonic-gate /*
1100Sstevel@tonic-gate * ibmf_i_dr_loopback_term():
1110Sstevel@tonic-gate * Perform termination processing of a DR loopback transaction
1120Sstevel@tonic-gate */
1130Sstevel@tonic-gate static void
ibmf_i_dr_loopback_term(ibmf_client_t * clientp,ibmf_msg_impl_t * msgimplp,int blocking)1140Sstevel@tonic-gate ibmf_i_dr_loopback_term(ibmf_client_t *clientp, ibmf_msg_impl_t *msgimplp,
1150Sstevel@tonic-gate int blocking)
1160Sstevel@tonic-gate {
1170Sstevel@tonic-gate uint_t refcnt;
1180Sstevel@tonic-gate
1190Sstevel@tonic-gate IBMF_TRACE_2(IBMF_TNF_DEBUG, DPRINT_L4,
1200Sstevel@tonic-gate ibmf_i_dr_loopback_term_start, IBMF_TNF_TRACE, "",
1210Sstevel@tonic-gate "ibmf_i_dr_loopback_term() enter, clientp = 0x%p, msg = 0x%p\n",
1220Sstevel@tonic-gate tnf_opaque, clientp, clientp, tnf_opaque, msg, msgimplp);
1230Sstevel@tonic-gate
1240Sstevel@tonic-gate mutex_enter(&msgimplp->im_mutex);
1250Sstevel@tonic-gate
1260Sstevel@tonic-gate if (blocking) {
1270Sstevel@tonic-gate /*
1280Sstevel@tonic-gate * For sequenced, and blocking transactions, we wait for
1290Sstevel@tonic-gate * the response. For non-sequenced, and blocking transactions,
1300Sstevel@tonic-gate * we are done since the send has completed (no send completion
1310Sstevel@tonic-gate * as when calling into IBTF).
1320Sstevel@tonic-gate */
1330Sstevel@tonic-gate if ((msgimplp->im_flags & IBMF_MSG_FLAGS_SEQUENCED) &&
1340Sstevel@tonic-gate ((msgimplp->im_trans_state_flags &
1350Sstevel@tonic-gate IBMF_TRANS_STATE_FLAG_SIGNALED) == 0)) {
1360Sstevel@tonic-gate
1370Sstevel@tonic-gate msgimplp->im_trans_state_flags |=
1380Sstevel@tonic-gate IBMF_TRANS_STATE_FLAG_WAIT;
1390Sstevel@tonic-gate
1400Sstevel@tonic-gate IBMF_TRACE_1(IBMF_TNF_DEBUG, DPRINT_L3,
1410Sstevel@tonic-gate ibmf_i_dr_loopback, IBMF_TNF_TRACE, "",
1420Sstevel@tonic-gate "ibmf_i_dr_loopback_term(): %s\n",
1430Sstevel@tonic-gate tnf_string, msg, "Blocking for completion");
1440Sstevel@tonic-gate
1450Sstevel@tonic-gate cv_wait(&msgimplp->im_trans_cv, &msgimplp->im_mutex);
1460Sstevel@tonic-gate
1470Sstevel@tonic-gate msgimplp->im_trans_state_flags &=
1480Sstevel@tonic-gate ~IBMF_TRANS_STATE_FLAG_WAIT;
1490Sstevel@tonic-gate
1500Sstevel@tonic-gate msgimplp->im_flags &= ~IBMF_MSG_FLAGS_BUSY;
1510Sstevel@tonic-gate
1520Sstevel@tonic-gate mutex_exit(&msgimplp->im_mutex);
1530Sstevel@tonic-gate
1540Sstevel@tonic-gate } else if ((msgimplp->im_flags &
1550Sstevel@tonic-gate IBMF_MSG_FLAGS_SEQUENCED) == 0) {
1560Sstevel@tonic-gate
1570Sstevel@tonic-gate msgimplp->im_trans_state_flags |=
1580Sstevel@tonic-gate IBMF_TRANS_STATE_FLAG_DONE;
1590Sstevel@tonic-gate msgimplp->im_flags &= ~IBMF_MSG_FLAGS_BUSY;
1600Sstevel@tonic-gate
1610Sstevel@tonic-gate mutex_exit(&msgimplp->im_mutex);
1620Sstevel@tonic-gate
1630Sstevel@tonic-gate ibmf_i_client_rem_msg(clientp, msgimplp, &refcnt);
1640Sstevel@tonic-gate } else {
1650Sstevel@tonic-gate
1660Sstevel@tonic-gate msgimplp->im_flags &= ~IBMF_MSG_FLAGS_BUSY;
1670Sstevel@tonic-gate mutex_exit(&msgimplp->im_mutex);
1680Sstevel@tonic-gate }
1690Sstevel@tonic-gate
1700Sstevel@tonic-gate } else if ((msgimplp->im_flags & IBMF_MSG_FLAGS_SEQUENCED) == 0) {
1710Sstevel@tonic-gate
1720Sstevel@tonic-gate IBMF_TRACE_1(IBMF_TNF_DEBUG, DPRINT_L3,
1730Sstevel@tonic-gate ibmf_i_dr_loopback, IBMF_TNF_TRACE, "",
1740Sstevel@tonic-gate "ibmf_i_dr_loopback_term(): %s\n",
1750Sstevel@tonic-gate tnf_string, msg, "Not sequenced, returning to caller");
1760Sstevel@tonic-gate msgimplp->im_trans_state_flags |= IBMF_TRANS_STATE_FLAG_DONE;
1770Sstevel@tonic-gate msgimplp->im_flags &= ~IBMF_MSG_FLAGS_BUSY;
1780Sstevel@tonic-gate mutex_exit(&msgimplp->im_mutex);
1790Sstevel@tonic-gate
1800Sstevel@tonic-gate ibmf_i_client_rem_msg(clientp, msgimplp, &refcnt);
1810Sstevel@tonic-gate
1820Sstevel@tonic-gate if (msgimplp->im_trans_cb) {
1830Sstevel@tonic-gate msgimplp->im_trans_cb((ibmf_handle_t)clientp,
1840Sstevel@tonic-gate (ibmf_msg_t *)msgimplp, msgimplp->im_trans_cb_arg);
1850Sstevel@tonic-gate }
1860Sstevel@tonic-gate } else {
1870Sstevel@tonic-gate
1880Sstevel@tonic-gate msgimplp->im_flags &= ~IBMF_MSG_FLAGS_BUSY;
1890Sstevel@tonic-gate mutex_exit(&msgimplp->im_mutex);
1900Sstevel@tonic-gate }
1910Sstevel@tonic-gate
1920Sstevel@tonic-gate IBMF_TRACE_0(IBMF_TNF_DEBUG, DPRINT_L4, ibmf_i_dr_loopback_term_end,
1930Sstevel@tonic-gate IBMF_TNF_TRACE, "", "ibmf_i_dr_loopback_term() exit\n");
1940Sstevel@tonic-gate
1950Sstevel@tonic-gate }
1960Sstevel@tonic-gate
1970Sstevel@tonic-gate /*
1980Sstevel@tonic-gate * ibmf_i_dr_loopback_filter():
1990Sstevel@tonic-gate * This function intercepts Directed Route MADs with zero hop count,
2000Sstevel@tonic-gate * or loopback DR MADs. If the MAD is outbound from the SM, the SMA's
2010Sstevel@tonic-gate * client handle is located, and the receive callback invoked.
2020Sstevel@tonic-gate * If the MAD is outbound from the SMA, the SM's client handle is located
2030Sstevel@tonic-gate * and the receive callback invoked.
2040Sstevel@tonic-gate *
2050Sstevel@tonic-gate * This filtering is needed for some HCAs where the SMA cannot handle DR
2060Sstevel@tonic-gate * MAD's that need to be treated as a loopback MAD. On these HCAs, we see
2070Sstevel@tonic-gate * the zero hopcount MAD being sent out on the wire which it should not.
2080Sstevel@tonic-gate */
2090Sstevel@tonic-gate static int
ibmf_i_dr_loopback_filter(ibmf_client_t * clientp,ibmf_msg_impl_t * msgimplp,int blocking)2100Sstevel@tonic-gate ibmf_i_dr_loopback_filter(ibmf_client_t *clientp, ibmf_msg_impl_t *msgimplp,
2110Sstevel@tonic-gate int blocking)
2120Sstevel@tonic-gate {
2130Sstevel@tonic-gate ibmf_client_t *rclientp;
2140Sstevel@tonic-gate sm_dr_mad_hdr_t *dr_hdr;
2150Sstevel@tonic-gate ibmf_msg_impl_t *rmsgimplp;
2160Sstevel@tonic-gate boolean_t rbuf_alloced;
2170Sstevel@tonic-gate int msg_trans_state_flags, msg_flags;
2180Sstevel@tonic-gate uint_t ref_cnt;
2190Sstevel@tonic-gate int ret;
2200Sstevel@tonic-gate
2210Sstevel@tonic-gate IBMF_TRACE_2(IBMF_TNF_DEBUG, DPRINT_L4,
2220Sstevel@tonic-gate ibmf_i_dr_loopback_filter_start, IBMF_TNF_TRACE, "",
2230Sstevel@tonic-gate "ibmf_i_dr_loopback_filter() enter, clientp = 0x%p, msg = 0x%p\n",
2240Sstevel@tonic-gate tnf_opaque, clientp, clientp, tnf_opaque, msg, msgimplp);
2250Sstevel@tonic-gate
2260Sstevel@tonic-gate dr_hdr = (sm_dr_mad_hdr_t *)msgimplp->im_msgbufs_send.im_bufs_mad_hdr;
2270Sstevel@tonic-gate
2280Sstevel@tonic-gate /* set transaction flag for a sequenced transaction */
2290Sstevel@tonic-gate if (msgimplp->im_transp_op_flags & IBMF_MSG_TRANS_FLAG_SEQ)
2300Sstevel@tonic-gate msgimplp->im_flags |= IBMF_MSG_FLAGS_SEQUENCED;
2310Sstevel@tonic-gate
2320Sstevel@tonic-gate /*
2330Sstevel@tonic-gate * If the DR SMP method is a Get or a Set, the target is the SMA, else,
2340Sstevel@tonic-gate * if the method is a GetResponse, the target is the SM. If the
2350Sstevel@tonic-gate * Attribute is SMInfo, the target is always the SM.
2360Sstevel@tonic-gate */
2370Sstevel@tonic-gate if ((((dr_hdr->R_Method == MAD_METHOD_GET) ||
2380Sstevel@tonic-gate (dr_hdr->R_Method == MAD_METHOD_SET)) &&
2390Sstevel@tonic-gate (dr_hdr->AttributeID != SM_SMINFO_ATTRID)) ||
2400Sstevel@tonic-gate (dr_hdr->R_Method == MAD_METHOD_TRAP_REPRESS)) {
2410Sstevel@tonic-gate
2420Sstevel@tonic-gate ret = ibmf_i_lookup_client_by_mgmt_class(clientp->ic_myci,
2430Sstevel@tonic-gate clientp->ic_client_info.port_num, SUBN_AGENT, &rclientp);
2440Sstevel@tonic-gate if (ret != IBMF_SUCCESS) {
2450Sstevel@tonic-gate IBMF_TRACE_1(IBMF_TNF_NODEBUG, DPRINT_L1,
2460Sstevel@tonic-gate ibmf_recv_pkt_cb_err, IBMF_TNF_TRACE, "",
2470Sstevel@tonic-gate "ibmf_i_dr_loopback_filter(): %s\n",
2480Sstevel@tonic-gate tnf_string, msg,
2490Sstevel@tonic-gate "Client for Mgt Class Subnet Agent not found");
2500Sstevel@tonic-gate IBMF_TRACE_0(IBMF_TNF_DEBUG, DPRINT_L4,
2510Sstevel@tonic-gate ibmf_i_dr_loopback_filter_end, IBMF_TNF_TRACE, "",
2520Sstevel@tonic-gate "ibmf_i_dr_loopback_filter() exit\n");
2530Sstevel@tonic-gate return (ret);
2540Sstevel@tonic-gate }
2550Sstevel@tonic-gate
2560Sstevel@tonic-gate } else if ((dr_hdr->R_Method == MAD_METHOD_GET_RESPONSE) ||
2570Sstevel@tonic-gate (dr_hdr->R_Method == MAD_METHOD_TRAP) ||
2580Sstevel@tonic-gate (dr_hdr->AttributeID == SM_SMINFO_ATTRID)) {
2590Sstevel@tonic-gate
2600Sstevel@tonic-gate ret = ibmf_i_lookup_client_by_mgmt_class(clientp->ic_myci,
2610Sstevel@tonic-gate clientp->ic_client_info.port_num, SUBN_MANAGER, &rclientp);
2620Sstevel@tonic-gate if (ret != IBMF_SUCCESS) {
2630Sstevel@tonic-gate IBMF_TRACE_1(IBMF_TNF_NODEBUG, DPRINT_L1,
2640Sstevel@tonic-gate ibmf_recv_pkt_cb_err, IBMF_TNF_TRACE, "",
2650Sstevel@tonic-gate "ibmf_i_dr_loopback_filter(): %s\n",
2660Sstevel@tonic-gate tnf_string, msg,
2670Sstevel@tonic-gate "Client for Mgt Class Subnet Manager not found")
2680Sstevel@tonic-gate IBMF_TRACE_0(IBMF_TNF_DEBUG, DPRINT_L4,
2690Sstevel@tonic-gate ibmf_i_dr_loopback_filter_end, IBMF_TNF_TRACE, "",
2700Sstevel@tonic-gate "ibmf_i_dr_loopback_filter() exit\n");
2710Sstevel@tonic-gate return (ret);
2720Sstevel@tonic-gate }
2730Sstevel@tonic-gate } else {
2740Sstevel@tonic-gate IBMF_TRACE_2(IBMF_TNF_NODEBUG, DPRINT_L1,
2750Sstevel@tonic-gate ibmf_recv_pkt_cb_err, IBMF_TNF_TRACE, "",
2760Sstevel@tonic-gate "ibmf_i_dr_loopback_filter(): %s, method = 0x%x\n",
2770Sstevel@tonic-gate tnf_string, msg, "Unexpected dr method",
2780Sstevel@tonic-gate tnf_opaque, method, dr_hdr->R_Method);
2790Sstevel@tonic-gate IBMF_TRACE_0(IBMF_TNF_DEBUG, DPRINT_L4,
2800Sstevel@tonic-gate ibmf_i_dr_loopback_filter_end, IBMF_TNF_TRACE, "",
2810Sstevel@tonic-gate "ibmf_i_dr_loopback_filter() exit\n");
2820Sstevel@tonic-gate
2830Sstevel@tonic-gate return (IBMF_FAILURE);
2840Sstevel@tonic-gate }
2850Sstevel@tonic-gate
2860Sstevel@tonic-gate /*
2870Sstevel@tonic-gate * Initialize the Transaction ID and Mgmt Class fields in the
2880Sstevel@tonic-gate * message context.
2890Sstevel@tonic-gate * NOTE: The IB MAD header in the incoming MAD is in wire (big-endian)
2900Sstevel@tonic-gate * format and needs to be converted to the host endian format where
2910Sstevel@tonic-gate * applicable (multi-byte fields)
2920Sstevel@tonic-gate */
2930Sstevel@tonic-gate msgimplp->im_tid = b2h64(dr_hdr->TransactionID);
2940Sstevel@tonic-gate msgimplp->im_mgt_class = dr_hdr->MgmtClass;
2950Sstevel@tonic-gate
2960Sstevel@tonic-gate /*
2970Sstevel@tonic-gate * Find the message context in the target client corresponding to the
2980Sstevel@tonic-gate * transaction ID and management class in the source message context
2990Sstevel@tonic-gate */
3000Sstevel@tonic-gate rmsgimplp = ibmf_i_find_msg(rclientp, msgimplp->im_tid,
3010Sstevel@tonic-gate dr_hdr->MgmtClass, dr_hdr->R_Method,
3020Sstevel@tonic-gate msgimplp->im_local_addr.ia_remote_lid, NULL, B_FALSE, NULL,
3030Sstevel@tonic-gate IBMF_REG_MSG_LIST);
3040Sstevel@tonic-gate
3050Sstevel@tonic-gate if (rmsgimplp != NULL) {
3060Sstevel@tonic-gate
3070Sstevel@tonic-gate mutex_enter(&rmsgimplp->im_mutex);
3080Sstevel@tonic-gate
3090Sstevel@tonic-gate /*
3100Sstevel@tonic-gate * If the message has been marked unitialized or done
3110Sstevel@tonic-gate * release the message mutex and return
3120Sstevel@tonic-gate */
3130Sstevel@tonic-gate if ((rmsgimplp->im_trans_state_flags &
3140Sstevel@tonic-gate IBMF_TRANS_STATE_FLAG_DONE) ||
3150Sstevel@tonic-gate (rmsgimplp->im_trans_state_flags &
3160Sstevel@tonic-gate IBMF_TRANS_STATE_FLAG_UNINIT)) {
3170Sstevel@tonic-gate IBMF_MSG_DECR_REFCNT(rmsgimplp);
3180Sstevel@tonic-gate msg_trans_state_flags = rmsgimplp->im_trans_state_flags;
3190Sstevel@tonic-gate msg_flags = rmsgimplp->im_flags;
3200Sstevel@tonic-gate ref_cnt = rmsgimplp->im_ref_count;
3210Sstevel@tonic-gate mutex_exit(&rmsgimplp->im_mutex);
3220Sstevel@tonic-gate /*
3230Sstevel@tonic-gate * This thread may notify the client only if the
3240Sstevel@tonic-gate * transaction is done, the message has been removed
3250Sstevel@tonic-gate * from the client's message list, and the message
3260Sstevel@tonic-gate * reference count is 0.
3270Sstevel@tonic-gate * If the transaction is done, and the message reference
3280Sstevel@tonic-gate * count = 0, there is still a possibility that a
3290Sstevel@tonic-gate * packet could arrive for the message and its reference
3300Sstevel@tonic-gate * count increased if the message is still on the list.
3310Sstevel@tonic-gate * If the message is still on the list, it will be
3320Sstevel@tonic-gate * removed by a call to ibmf_i_client_rem_msg() at
3330Sstevel@tonic-gate * the completion point of the transaction.
3340Sstevel@tonic-gate * So, the reference count should be checked after the
3350Sstevel@tonic-gate * message has been removed.
3360Sstevel@tonic-gate */
3370Sstevel@tonic-gate if ((msg_trans_state_flags &
3380Sstevel@tonic-gate IBMF_TRANS_STATE_FLAG_DONE) &&
3390Sstevel@tonic-gate !(msg_flags & IBMF_MSG_FLAGS_ON_LIST) &&
3400Sstevel@tonic-gate (ref_cnt == 0)) {
3410Sstevel@tonic-gate ibmf_i_notify_client(rmsgimplp);
3420Sstevel@tonic-gate }
3430Sstevel@tonic-gate IBMF_TRACE_2(IBMF_TNF_NODEBUG, DPRINT_L1,
3440Sstevel@tonic-gate ibmf_recv_pkt_cb_err, IBMF_TNF_TRACE, "",
3450Sstevel@tonic-gate "ibmf_i_dr_loopback_filter(): %s, msg = 0x%p\n",
3460Sstevel@tonic-gate tnf_string, msg,
3470Sstevel@tonic-gate "Message already marked for removal, dropping MAD",
3480Sstevel@tonic-gate tnf_opaque, msgimplp, msgimplp);
3490Sstevel@tonic-gate IBMF_TRACE_0(IBMF_TNF_DEBUG, DPRINT_L4,
3500Sstevel@tonic-gate ibmf_i_dr_loopback_filter_end, IBMF_TNF_TRACE, "",
3510Sstevel@tonic-gate "ibmf_i_dr_loopback_filter() exit\n");
3520Sstevel@tonic-gate return (IBMF_FAILURE);
3530Sstevel@tonic-gate }
3540Sstevel@tonic-gate } else {
3550Sstevel@tonic-gate
3560Sstevel@tonic-gate _NOTE(NOW_INVISIBLE_TO_OTHER_THREADS(*rmsgimplp))
3570Sstevel@tonic-gate
3580Sstevel@tonic-gate /* This is an unsolicited message */
3590Sstevel@tonic-gate
3600Sstevel@tonic-gate rmsgimplp = (ibmf_msg_impl_t *)kmem_zalloc(
3610Sstevel@tonic-gate sizeof (ibmf_msg_impl_t), KM_NOSLEEP);
3623870Srm78299 if (rmsgimplp == NULL) {
3630Sstevel@tonic-gate IBMF_TRACE_1(IBMF_TNF_NODEBUG, DPRINT_L1,
3640Sstevel@tonic-gate ibmf_recv_pkt_cb_err, IBMF_TNF_TRACE, "",
3650Sstevel@tonic-gate "ibmf_i_dr_loopback_filter(): %s\n",
3660Sstevel@tonic-gate tnf_string, msg, "Failed to alloc packet");
3670Sstevel@tonic-gate IBMF_TRACE_0(IBMF_TNF_DEBUG, DPRINT_L4,
3680Sstevel@tonic-gate ibmf_i_dr_loopback_filter_end, IBMF_TNF_TRACE, "",
3690Sstevel@tonic-gate "ibmf_i_dr_loopback_filter() exit\n");
3700Sstevel@tonic-gate return (IBMF_NO_RESOURCES);
3710Sstevel@tonic-gate }
3720Sstevel@tonic-gate
3730Sstevel@tonic-gate mutex_init(&rmsgimplp->im_mutex, NULL, MUTEX_DRIVER, NULL);
3740Sstevel@tonic-gate
3750Sstevel@tonic-gate rmsgimplp->im_client = rclientp;
3760Sstevel@tonic-gate rmsgimplp->im_qp_hdl = msgimplp->im_qp_hdl;
3770Sstevel@tonic-gate rmsgimplp->im_unsolicited = B_TRUE;
3780Sstevel@tonic-gate rmsgimplp->im_tid = b2h64(dr_hdr->TransactionID);
3790Sstevel@tonic-gate rmsgimplp->im_mgt_class = dr_hdr->MgmtClass;
3800Sstevel@tonic-gate
3810Sstevel@tonic-gate /* indicate the client callback is active */
3820Sstevel@tonic-gate if (rmsgimplp->im_qp_hdl == IBMF_QP_HANDLE_DEFAULT) {
3830Sstevel@tonic-gate mutex_enter(&rclientp->ic_mutex);
3840Sstevel@tonic-gate IBMF_RECV_CB_SETUP(rclientp);
3850Sstevel@tonic-gate mutex_exit(&rclientp->ic_mutex);
3860Sstevel@tonic-gate } else {
3870Sstevel@tonic-gate ibmf_alt_qp_t *qpp;
3880Sstevel@tonic-gate
3890Sstevel@tonic-gate qpp = (ibmf_alt_qp_t *)rmsgimplp->im_qp_hdl;
3900Sstevel@tonic-gate mutex_enter(&qpp->isq_mutex);
3910Sstevel@tonic-gate IBMF_ALT_RECV_CB_SETUP(qpp);
3920Sstevel@tonic-gate mutex_exit(&qpp->isq_mutex);
3930Sstevel@tonic-gate }
3940Sstevel@tonic-gate
3950Sstevel@tonic-gate /* Increment the message reference count */
3960Sstevel@tonic-gate IBMF_MSG_INCR_REFCNT(rmsgimplp);
3970Sstevel@tonic-gate rmsgimplp->im_trans_state_flags = IBMF_TRANS_STATE_FLAG_UNINIT;
3980Sstevel@tonic-gate
3990Sstevel@tonic-gate _NOTE(NOW_VISIBLE_TO_OTHER_THREADS(*rmsgimplp))
4000Sstevel@tonic-gate
4010Sstevel@tonic-gate /* add message to client's list; will acquire im_mutex */
4020Sstevel@tonic-gate ibmf_i_client_add_msg(rclientp, rmsgimplp);
4030Sstevel@tonic-gate
4040Sstevel@tonic-gate mutex_enter(&rmsgimplp->im_mutex);
4050Sstevel@tonic-gate
4060Sstevel@tonic-gate /* no one should have touched our state */
4070Sstevel@tonic-gate ASSERT(rmsgimplp->im_trans_state_flags ==
4080Sstevel@tonic-gate IBMF_TRANS_STATE_FLAG_UNINIT);
4090Sstevel@tonic-gate
4100Sstevel@tonic-gate /* transition out of uninit state */
4110Sstevel@tonic-gate rmsgimplp->im_trans_state_flags = IBMF_TRANS_STATE_FLAG_INIT;
4120Sstevel@tonic-gate }
4130Sstevel@tonic-gate
4140Sstevel@tonic-gate /* Allocate memory for the receive buffers */
4150Sstevel@tonic-gate if (rmsgimplp->im_msgbufs_recv.im_bufs_mad_hdr == NULL) {
4160Sstevel@tonic-gate rmsgimplp->im_msgbufs_recv.im_bufs_mad_hdr =
4170Sstevel@tonic-gate (ib_mad_hdr_t *)kmem_zalloc(IBMF_MAD_SIZE, KM_NOSLEEP);
4180Sstevel@tonic-gate if (rmsgimplp->im_msgbufs_recv.im_bufs_mad_hdr == NULL) {
4190Sstevel@tonic-gate IBMF_MSG_DECR_REFCNT(rmsgimplp);
4200Sstevel@tonic-gate mutex_exit(&rmsgimplp->im_mutex);
4210Sstevel@tonic-gate kmem_free(rmsgimplp, sizeof (ibmf_msg_impl_t));
4220Sstevel@tonic-gate IBMF_TRACE_1(IBMF_TNF_NODEBUG, DPRINT_L1,
4230Sstevel@tonic-gate ibmf_recv_pkt_cb_err, IBMF_TNF_TRACE, "",
4240Sstevel@tonic-gate "ibmf_i_dr_loopback_filter(): %s\n",
4250Sstevel@tonic-gate tnf_string, msg, "mem allocation failure");
4260Sstevel@tonic-gate IBMF_TRACE_0(IBMF_TNF_DEBUG, DPRINT_L4,
4270Sstevel@tonic-gate ibmf_i_dr_loopback_filter_end, IBMF_TNF_TRACE, "",
4280Sstevel@tonic-gate "ibmf_i_dr_loopback_filter() exit\n");
4290Sstevel@tonic-gate return (IBMF_NO_RESOURCES);
4300Sstevel@tonic-gate }
4310Sstevel@tonic-gate rbuf_alloced = B_TRUE;
4320Sstevel@tonic-gate }
4330Sstevel@tonic-gate
4340Sstevel@tonic-gate /* Copy the send buffers into the receive buffers */
4350Sstevel@tonic-gate
4360Sstevel@tonic-gate /* Copy the MAD header */
4370Sstevel@tonic-gate bcopy((void *)msgimplp->im_msgbufs_send.im_bufs_mad_hdr,
4380Sstevel@tonic-gate (void *)rmsgimplp->im_msgbufs_recv.im_bufs_mad_hdr,
4390Sstevel@tonic-gate sizeof (ib_mad_hdr_t));
4400Sstevel@tonic-gate
4410Sstevel@tonic-gate /*
4420Sstevel@tonic-gate * Copy the management class header
4430Sstevel@tonic-gate * For DR MADs, class header is of size 40 bytes and start
4440Sstevel@tonic-gate * right after the MAD header.
4450Sstevel@tonic-gate */
4460Sstevel@tonic-gate rmsgimplp->im_msgbufs_recv.im_bufs_cl_hdr =
4470Sstevel@tonic-gate (uchar_t *)rmsgimplp->im_msgbufs_recv.im_bufs_mad_hdr +
4480Sstevel@tonic-gate sizeof (ib_mad_hdr_t);
4490Sstevel@tonic-gate rmsgimplp->im_msgbufs_recv.im_bufs_cl_hdr_len =
4500Sstevel@tonic-gate msgimplp->im_msgbufs_send.im_bufs_cl_hdr_len;
4510Sstevel@tonic-gate bcopy((void *)msgimplp->im_msgbufs_send.im_bufs_cl_hdr,
4520Sstevel@tonic-gate (void *)rmsgimplp->im_msgbufs_recv.im_bufs_cl_hdr,
4530Sstevel@tonic-gate msgimplp->im_msgbufs_send.im_bufs_cl_hdr_len);
4540Sstevel@tonic-gate
4550Sstevel@tonic-gate /* Copy the management class data */
4560Sstevel@tonic-gate rmsgimplp->im_msgbufs_recv.im_bufs_cl_data =
4570Sstevel@tonic-gate (uchar_t *)rmsgimplp->im_msgbufs_recv.im_bufs_mad_hdr +
4580Sstevel@tonic-gate sizeof (ib_mad_hdr_t) +
4590Sstevel@tonic-gate rmsgimplp->im_msgbufs_recv.im_bufs_cl_hdr_len;
4600Sstevel@tonic-gate rmsgimplp->im_msgbufs_recv.im_bufs_cl_data_len =
4610Sstevel@tonic-gate msgimplp->im_msgbufs_send.im_bufs_cl_data_len;
4620Sstevel@tonic-gate bcopy((void *)msgimplp->im_msgbufs_send.im_bufs_cl_data,
4630Sstevel@tonic-gate (void *)rmsgimplp->im_msgbufs_recv.im_bufs_cl_data,
4640Sstevel@tonic-gate msgimplp->im_msgbufs_send.im_bufs_cl_data_len);
4650Sstevel@tonic-gate
4660Sstevel@tonic-gate /* Copy the global address information from the source message */
4670Sstevel@tonic-gate bcopy((void *)&msgimplp->im_global_addr,
4680Sstevel@tonic-gate (void *)&rmsgimplp->im_global_addr,
4690Sstevel@tonic-gate sizeof (ibmf_global_addr_info_t));
4700Sstevel@tonic-gate
4710Sstevel@tonic-gate /* Copy the local address information from the source message */
4720Sstevel@tonic-gate bcopy((void *)&msgimplp->im_local_addr,
4730Sstevel@tonic-gate (void *)&rmsgimplp->im_local_addr,
4740Sstevel@tonic-gate sizeof (ibmf_addr_info_t));
4750Sstevel@tonic-gate
4760Sstevel@tonic-gate /*
4770Sstevel@tonic-gate * Call the receive callback for the agent/manager the packet is
4780Sstevel@tonic-gate * destined for.
4790Sstevel@tonic-gate */
4800Sstevel@tonic-gate rmsgimplp->im_trans_state_flags |= IBMF_TRANS_STATE_FLAG_DONE;
4810Sstevel@tonic-gate
4820Sstevel@tonic-gate /*
4830Sstevel@tonic-gate * Decrement the message reference count
4840Sstevel@tonic-gate * This count was incremented either when the message was found
4850Sstevel@tonic-gate * on the client's message list (ibmf_i_find_msg()) or when
4860Sstevel@tonic-gate * a new message was created for unsolicited data
4870Sstevel@tonic-gate */
4880Sstevel@tonic-gate IBMF_MSG_DECR_REFCNT(rmsgimplp);
4890Sstevel@tonic-gate
4900Sstevel@tonic-gate mutex_exit(&rmsgimplp->im_mutex);
4910Sstevel@tonic-gate
4920Sstevel@tonic-gate if (rbuf_alloced) {
4930Sstevel@tonic-gate mutex_enter(&clientp->ic_kstat_mutex);
4940Sstevel@tonic-gate IBMF_ADD32_KSTATS(clientp, recv_bufs_alloced, 1);
4950Sstevel@tonic-gate mutex_exit(&clientp->ic_kstat_mutex);
4960Sstevel@tonic-gate }
4970Sstevel@tonic-gate
4980Sstevel@tonic-gate /* add the source message to the source client's list */
4990Sstevel@tonic-gate ibmf_i_client_add_msg(clientp, msgimplp);
5000Sstevel@tonic-gate
5010Sstevel@tonic-gate /* remove the destination message from the list */
5020Sstevel@tonic-gate ibmf_i_client_rem_msg(rclientp, rmsgimplp, &ref_cnt);
5030Sstevel@tonic-gate
5040Sstevel@tonic-gate /*
5050Sstevel@tonic-gate * Notify the client if the message reference count is zero.
5060Sstevel@tonic-gate * At this point, we know that the transaction is done and
5070Sstevel@tonic-gate * the message has been removed from the client's message list.
5080Sstevel@tonic-gate * So, we only need to make sure the reference count is zero
5090Sstevel@tonic-gate * before notifying the client.
5100Sstevel@tonic-gate */
5110Sstevel@tonic-gate if (ref_cnt == 0)
5120Sstevel@tonic-gate ibmf_i_notify_client(rmsgimplp);
5130Sstevel@tonic-gate
5140Sstevel@tonic-gate /* perform source client transaction termination processing */
5150Sstevel@tonic-gate ibmf_i_dr_loopback_term(clientp, msgimplp, blocking);
5160Sstevel@tonic-gate
5170Sstevel@tonic-gate IBMF_TRACE_1(IBMF_TNF_DEBUG, DPRINT_L4, ibmf_i_dr_loopback_filter_end,
5180Sstevel@tonic-gate IBMF_TNF_TRACE, "", "ibmf_i_dr_loopback_filter() exit, ret = %d\n",
5190Sstevel@tonic-gate tnf_uint, status, ret);
5200Sstevel@tonic-gate
5210Sstevel@tonic-gate return (IBMF_SUCCESS);
5220Sstevel@tonic-gate }
523