17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*03494a98SBill Taylor  * Common Development and Distribution License (the "License").
6*03494a98SBill Taylor  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22*03494a98SBill Taylor  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #ifndef _SYS_IB_MGT_IBMF_IBMF_IMPL_H
277c478bd9Sstevel@tonic-gate #define	_SYS_IB_MGT_IBMF_IBMF_IMPL_H
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate /*
317c478bd9Sstevel@tonic-gate  * This file contains the IBMF implementation dependent structures and defines.
327c478bd9Sstevel@tonic-gate  */
337c478bd9Sstevel@tonic-gate 
347c478bd9Sstevel@tonic-gate #ifdef __cplusplus
357c478bd9Sstevel@tonic-gate extern "C" {
367c478bd9Sstevel@tonic-gate #endif
377c478bd9Sstevel@tonic-gate 
387c478bd9Sstevel@tonic-gate #include <sys/types.h>
397c478bd9Sstevel@tonic-gate #include <sys/conf.h>
407c478bd9Sstevel@tonic-gate #include <sys/modctl.h>
417c478bd9Sstevel@tonic-gate #include <sys/kmem.h>
427c478bd9Sstevel@tonic-gate #include <sys/ksynch.h>
437c478bd9Sstevel@tonic-gate #include <sys/taskq.h>
447c478bd9Sstevel@tonic-gate #include <sys/sunddi.h>
457c478bd9Sstevel@tonic-gate #include <sys/disp.h>
467c478bd9Sstevel@tonic-gate #include <sys/ib/ibtl/ibvti.h>
477c478bd9Sstevel@tonic-gate #include <sys/ib/mgt/ibmf/ibmf.h>
487c478bd9Sstevel@tonic-gate #include <sys/ib/mgt/ibmf/ibmf_rmpp.h>
497c478bd9Sstevel@tonic-gate #include <sys/ib/mgt/ibmf/ibmf_kstat.h>
507c478bd9Sstevel@tonic-gate #include <sys/ib/mgt/ibmf/ibmf_trace.h>
517c478bd9Sstevel@tonic-gate 
527c478bd9Sstevel@tonic-gate #define	IBMF_MEM_PER_WQE		(IBMF_MAD_SIZE + sizeof (ib_grh_t))
537c478bd9Sstevel@tonic-gate #define	IBMF_MAX_SQ_WRE			64
547c478bd9Sstevel@tonic-gate #define	IBMF_MAX_RQ_WRE			64
557c478bd9Sstevel@tonic-gate #define	IBMF_MAX_POSTED_RQ_PER_QP	512
567c478bd9Sstevel@tonic-gate #define	IBMF_MAX_POSTED_SQ_PER_QP	512
577c478bd9Sstevel@tonic-gate #define	IBMF_MAX_SQ_WR_SGL_ELEMENTS	1
587c478bd9Sstevel@tonic-gate #define	IBMF_MAX_RQ_WR_SGL_ELEMENTS	1
597c478bd9Sstevel@tonic-gate #define	IBMF_MGMT_Q_KEY			0x80010000
607c478bd9Sstevel@tonic-gate #define	IBMF_P_KEY_DEF_FULL		0xFFFF
617c478bd9Sstevel@tonic-gate #define	IBMF_P_KEY_DEF_LIMITED		0x7FFF
627c478bd9Sstevel@tonic-gate #define	IBMF_P_KEY_BASE_MASK		0x7FFF
637c478bd9Sstevel@tonic-gate #define	IBMF_PKEY_MEMBERSHIP_MASK	0x8000
647c478bd9Sstevel@tonic-gate 
657c478bd9Sstevel@tonic-gate #define	IBMF_TASKQ_1THREAD		1
667c478bd9Sstevel@tonic-gate #define	IBMF_TASKQ_NTHREADS		128
677c478bd9Sstevel@tonic-gate 
687c478bd9Sstevel@tonic-gate /*
697c478bd9Sstevel@tonic-gate  * Work request ID format used for receive requests.
707c478bd9Sstevel@tonic-gate  *
717c478bd9Sstevel@tonic-gate  *  bit 0 set to 1
727c478bd9Sstevel@tonic-gate  */
737c478bd9Sstevel@tonic-gate #define	IBMF_RCV_CQE			0x1
747c478bd9Sstevel@tonic-gate 
757c478bd9Sstevel@tonic-gate /*
767c478bd9Sstevel@tonic-gate  * Convenience macro used in the RMPP protocol to obtain R_Method field
777c478bd9Sstevel@tonic-gate  * of MAD header with Response bit flipped.
787c478bd9Sstevel@tonic-gate  */
797c478bd9Sstevel@tonic-gate #define	IBMF_FLIP_RESP_BIT(r_method)					\
807c478bd9Sstevel@tonic-gate 	(((r_method & 0x80) ^ 0x80) | (r_method & 0x7F))
817c478bd9Sstevel@tonic-gate 
827c478bd9Sstevel@tonic-gate /* Work Request ID macros */
837c478bd9Sstevel@tonic-gate #define	IBMF_IS_RECV_WR_ID(id)				\
847c478bd9Sstevel@tonic-gate 	(((uint64_t)(id) & IBMF_RCV_CQE) ? B_TRUE : B_FALSE)
857c478bd9Sstevel@tonic-gate #define	IBMF_IS_SEND_WR_ID(id)				\
867c478bd9Sstevel@tonic-gate 	(!(IBMF_IS_RECV_WR_ID((id))))
877c478bd9Sstevel@tonic-gate 
887c478bd9Sstevel@tonic-gate /* Decrement IBMF message reference count */
897c478bd9Sstevel@tonic-gate #define	IBMF_MSG_DECR_REFCNT(msg)			{	\
907c478bd9Sstevel@tonic-gate 	ASSERT(MUTEX_HELD(&(msg)->im_mutex));			\
917c478bd9Sstevel@tonic-gate 	(msg)->im_ref_count--;					\
927c478bd9Sstevel@tonic-gate }
937c478bd9Sstevel@tonic-gate 
947c478bd9Sstevel@tonic-gate /* Increment IBMF message reference count */
957c478bd9Sstevel@tonic-gate #define	IBMF_MSG_INCR_REFCNT(msg)				\
967c478bd9Sstevel@tonic-gate 	(msg)->im_ref_count++;
977c478bd9Sstevel@tonic-gate 
987c478bd9Sstevel@tonic-gate /* Callback setup/cleanup macros */
997c478bd9Sstevel@tonic-gate #define	IBMF_RECV_CB_SETUP(clp)				{	\
1007c478bd9Sstevel@tonic-gate 	ASSERT(MUTEX_HELD(&(clp)->ic_mutex));			\
1017c478bd9Sstevel@tonic-gate 	(clp)->ic_flags |= IBMF_CLIENT_RECV_CB_ACTIVE;		\
1027c478bd9Sstevel@tonic-gate 	(clp)->ic_recvs_active++;				\
1037c478bd9Sstevel@tonic-gate 	mutex_enter(&(clp)->ic_kstat_mutex);			\
1047c478bd9Sstevel@tonic-gate 	IBMF_ADD32_KSTATS((clp), recvs_active, 1);		\
1057c478bd9Sstevel@tonic-gate 	mutex_exit(&(clp)->ic_kstat_mutex);			\
1067c478bd9Sstevel@tonic-gate }
1077c478bd9Sstevel@tonic-gate 
1087c478bd9Sstevel@tonic-gate #define	IBMF_RECV_CB_CLEANUP(clp)			{		\
1097c478bd9Sstevel@tonic-gate 	ASSERT(MUTEX_HELD(&(clp)->ic_mutex));				\
1107c478bd9Sstevel@tonic-gate 	(clp)->ic_recvs_active--;					\
1117c478bd9Sstevel@tonic-gate 	mutex_enter(&(clp)->ic_kstat_mutex);				\
1127c478bd9Sstevel@tonic-gate 	IBMF_SUB32_KSTATS((clp), recvs_active, 1);			\
1137c478bd9Sstevel@tonic-gate 	mutex_exit(&(clp)->ic_kstat_mutex);				\
1147c478bd9Sstevel@tonic-gate 	if ((clp)->ic_recvs_active == 0)				\
1157c478bd9Sstevel@tonic-gate 		(clp)->ic_flags &= ~IBMF_CLIENT_RECV_CB_ACTIVE;		\
1167c478bd9Sstevel@tonic-gate 	if ((((clp)->ic_flags & IBMF_CLIENT_RECV_CB_ACTIVE) == 0) &&	\
1177c478bd9Sstevel@tonic-gate 	    (((clp)->ic_flags & IBMF_CLIENT_TEAR_DOWN_CB) != 0))	\
1187c478bd9Sstevel@tonic-gate 		cv_signal(&(clp)->ic_recv_cb_teardown_cv);		\
1197c478bd9Sstevel@tonic-gate }
1207c478bd9Sstevel@tonic-gate 
1217c478bd9Sstevel@tonic-gate #define	IBMF_ALT_RECV_CB_SETUP(altqp)			{		\
1227c478bd9Sstevel@tonic-gate 	ASSERT(MUTEX_HELD(&(altqp)->isq_mutex));			\
1237c478bd9Sstevel@tonic-gate 	(altqp)->isq_flags |= IBMF_CLIENT_RECV_CB_ACTIVE;		\
1247c478bd9Sstevel@tonic-gate 	(altqp)->isq_recvs_active++;					\
1257c478bd9Sstevel@tonic-gate 	mutex_enter(&(altqp)->isq_client_hdl->ic_kstat_mutex);		\
1267c478bd9Sstevel@tonic-gate 	IBMF_ADD32_KSTATS((altqp)->isq_client_hdl, recvs_active, 1);	\
1277c478bd9Sstevel@tonic-gate 	mutex_exit(&(altqp)->isq_client_hdl->ic_kstat_mutex);		\
1287c478bd9Sstevel@tonic-gate }
1297c478bd9Sstevel@tonic-gate 
1307c478bd9Sstevel@tonic-gate #define	IBMF_ALT_RECV_CB_CLEANUP(altqp)			{		\
1317c478bd9Sstevel@tonic-gate 	ASSERT(MUTEX_HELD(&(altqp)->isq_mutex));			\
1327c478bd9Sstevel@tonic-gate 	(altqp)->isq_recvs_active--;					\
1337c478bd9Sstevel@tonic-gate 	mutex_enter(&(altqp)->isq_client_hdl->ic_kstat_mutex);		\
1347c478bd9Sstevel@tonic-gate 	IBMF_SUB32_KSTATS((altqp)->isq_client_hdl, recvs_active, 1);	\
1357c478bd9Sstevel@tonic-gate 	mutex_exit(&(altqp)->isq_client_hdl->ic_kstat_mutex);		\
1367c478bd9Sstevel@tonic-gate 	if ((altqp)->isq_recvs_active == 0)				\
1377c478bd9Sstevel@tonic-gate 		(altqp)->isq_flags &= ~IBMF_CLIENT_RECV_CB_ACTIVE;	\
1387c478bd9Sstevel@tonic-gate 	if ((((altqp)->isq_flags & IBMF_CLIENT_RECV_CB_ACTIVE) == 0) &&	\
1397c478bd9Sstevel@tonic-gate 	    (((altqp)->isq_flags & IBMF_CLIENT_TEAR_DOWN_CB) != 0))	\
1407c478bd9Sstevel@tonic-gate 		cv_signal(&(altqp)->isq_recv_cb_teardown_cv);		\
1417c478bd9Sstevel@tonic-gate }
1427c478bd9Sstevel@tonic-gate 
1437c478bd9Sstevel@tonic-gate /* warlock annotations for ibmf.h and ibmf_msg.h structures */
1447c478bd9Sstevel@tonic-gate _NOTE(READ_ONLY_DATA(_ibmf_msg::im_msgbufs_send.im_bufs_cl_data
1457c478bd9Sstevel@tonic-gate 	_ibmf_msg::im_msgbufs_send.im_bufs_cl_data_len
1467c478bd9Sstevel@tonic-gate 	_ibmf_msg::im_msgbufs_send.im_bufs_cl_hdr
1477c478bd9Sstevel@tonic-gate 	_ibmf_msg::im_msgbufs_send.im_bufs_cl_hdr_len
1487c478bd9Sstevel@tonic-gate 	_ibmf_msg::im_msgbufs_send.im_bufs_mad_hdr
1497c478bd9Sstevel@tonic-gate 	_ib_mad_hdr_t))
1507c478bd9Sstevel@tonic-gate 
1517c478bd9Sstevel@tonic-gate /*
1527c478bd9Sstevel@tonic-gate  * WQE pool management contexts
1537c478bd9Sstevel@tonic-gate  */
1547c478bd9Sstevel@tonic-gate typedef struct _ibmf_wqe_mgt {
1557c478bd9Sstevel@tonic-gate 	struct _ibmf_wqe_mgt	*wqe_mgt_next; /* next wqe management entry */
1567c478bd9Sstevel@tonic-gate 	void			*wqes_kmem;	/* kmem allocated for WQEs */
1577c478bd9Sstevel@tonic-gate 	uint64_t		wqes_kmem_sz; /* sizeof WQE kmem allocated */
1587c478bd9Sstevel@tonic-gate 	ib_vaddr_t		wqes_ib_mem;	/* Registered memory */
1597c478bd9Sstevel@tonic-gate 	ibt_lkey_t		wqes_ib_lkey;	/* Lkey that goes with it */
1607c478bd9Sstevel@tonic-gate 	ibt_mr_hdl_t		wqes_ib_mem_hdl; /* IB mem handle */
1617c478bd9Sstevel@tonic-gate 	kmutex_t		wqes_mutex;	/* WQE mgt context mutex */
1627c478bd9Sstevel@tonic-gate } ibmf_wqe_mgt_t;
1637c478bd9Sstevel@tonic-gate _NOTE(MUTEX_PROTECTS_DATA(ibmf_wqe_mgt_t::wqes_mutex,
1647c478bd9Sstevel@tonic-gate     ibmf_wqe_mgt_t::wqes_kmem
1657c478bd9Sstevel@tonic-gate     ibmf_wqe_mgt_t::wqes_kmem_sz
1667c478bd9Sstevel@tonic-gate     ibmf_wqe_mgt_t::wqes_ib_mem
1677c478bd9Sstevel@tonic-gate     ibmf_wqe_mgt_t::wqes_ib_lkey
1687c478bd9Sstevel@tonic-gate     ibmf_wqe_mgt_t::wqes_ib_mem_hdl))
1697c478bd9Sstevel@tonic-gate 
1707c478bd9Sstevel@tonic-gate /*
1717c478bd9Sstevel@tonic-gate  * structure used to keep track of qp handles
1727c478bd9Sstevel@tonic-gate  */
1737c478bd9Sstevel@tonic-gate typedef struct _ibmf_qp_t {
1747c478bd9Sstevel@tonic-gate 	struct _ibmf_qp_t	*iq_next;	/* next in the list */
1757c478bd9Sstevel@tonic-gate 	ibt_qp_hdl_t		iq_qp_handle;	/* qp handle from IB xport */
1767c478bd9Sstevel@tonic-gate 	int			iq_port_num;	/* port num for this qp */
1777c478bd9Sstevel@tonic-gate 	int			iq_qp_num;	/* qp num */
1787c478bd9Sstevel@tonic-gate 	int			iq_qp_ref;	/* no. of clients using this */
1797c478bd9Sstevel@tonic-gate 	uint_t			iq_flags;	/* for implementing state m/c */
1807c478bd9Sstevel@tonic-gate 	uint_t			iq_rwqes_posted; /* posted receive wqes */
1817c478bd9Sstevel@tonic-gate 	kmutex_t		iq_mutex;	/* mutex for some fields */
1827c478bd9Sstevel@tonic-gate } ibmf_qp_t;
1837c478bd9Sstevel@tonic-gate _NOTE(READ_ONLY_DATA(ibmf_qp_t::iq_port_num ibmf_qp_t::iq_qp_handle))
1847c478bd9Sstevel@tonic-gate _NOTE(MUTEX_PROTECTS_DATA(ibmf_qp_t::iq_mutex,
1857c478bd9Sstevel@tonic-gate     ibmf_qp_t::iq_rwqes_posted))
1867c478bd9Sstevel@tonic-gate 
1877c478bd9Sstevel@tonic-gate /* defines for iq_flags */
1887c478bd9Sstevel@tonic-gate #define	IBMF_QP_FLAGS_INVALID				0x0001
1897c478bd9Sstevel@tonic-gate #define	IBMF_QP_FLAGS_INITING				0x0002
1907c478bd9Sstevel@tonic-gate #define	IBMF_QP_FLAGS_INITED				0x0004
1917c478bd9Sstevel@tonic-gate #define	IBMF_QP_FLAGS_UNINITING				0x0008
1927c478bd9Sstevel@tonic-gate 
1937c478bd9Sstevel@tonic-gate /*
1947c478bd9Sstevel@tonic-gate  * structure used to keep track of qp handles for qps other than
1957c478bd9Sstevel@tonic-gate  * the special qps
1967c478bd9Sstevel@tonic-gate  */
1977c478bd9Sstevel@tonic-gate typedef struct _ibmf_alt_qp_t {
1987c478bd9Sstevel@tonic-gate 	struct _ibmf_alt_qp_t	*isq_next;	/* next qp ctx on list */
1997c478bd9Sstevel@tonic-gate 	ibt_qp_hdl_t		isq_qp_handle;	/* qp handle from IB xport */
2007c478bd9Sstevel@tonic-gate 	ibt_chan_sizes_t	isq_qp_sizes;	/* qp sizes returned by alloc */
2017c478bd9Sstevel@tonic-gate 	struct _ibmf_client	*isq_client_hdl; /* associated client handle */
2027c478bd9Sstevel@tonic-gate 	ibmf_msg_cb_t		isq_recv_cb;	/* recv callback for this qp */
2037c478bd9Sstevel@tonic-gate 	void			*isq_recv_cb_arg; /* arg for recv cb */
2047c478bd9Sstevel@tonic-gate 	kcondvar_t		isq_recv_cb_teardown_cv; /* wait on teardown */
2057c478bd9Sstevel@tonic-gate 	kmutex_t		isq_mutex;		/* qp context mutex */
2067c478bd9Sstevel@tonic-gate 	int			isq_flags;	/* to keep track of state */
2077c478bd9Sstevel@tonic-gate 	int			isq_sends_active; /* outstanding sends */
2087c478bd9Sstevel@tonic-gate 	int			isq_recvs_active; /* outstanding recvs */
2097c478bd9Sstevel@tonic-gate 	ib_qpn_t		isq_qpn;	/* qp number */
2107c478bd9Sstevel@tonic-gate 	ib_pkey_t		isq_pkey;	/* qp's partition key */
2117c478bd9Sstevel@tonic-gate 	ib_qkey_t		isq_qkey;	/* qp's queue keye */
2127c478bd9Sstevel@tonic-gate 	int			isq_port_num;	/* port num for this qp */
2137c478bd9Sstevel@tonic-gate 	boolean_t		isq_supports_rmpp; /* qp supports rmpp */
2147c478bd9Sstevel@tonic-gate 	kcondvar_t		isq_sqd_cv; 	/* wait on SQD event */
2157c478bd9Sstevel@tonic-gate 	int			isq_wqes_alloced; /* wqes allocated for QP */
2167c478bd9Sstevel@tonic-gate 	kcondvar_t		isq_wqes_cv; 	/* wait on wqes destruction */
2177c478bd9Sstevel@tonic-gate 	uint_t			isq_rwqes_posted; /* posted receive wqes */
2187c478bd9Sstevel@tonic-gate 
2197c478bd9Sstevel@tonic-gate 	/* Manage Send/Receive WQEs for Special QPs */
2207c478bd9Sstevel@tonic-gate 	struct kmem_cache	*isq_send_wqes_cache; /* Send WQE cache */
2217c478bd9Sstevel@tonic-gate 	struct kmem_cache	*isq_recv_wqes_cache; /* Receive WQE cache */
2227c478bd9Sstevel@tonic-gate 	vmem_t			*isq_wqe_ib_vmem; /* IB virtual address arena */
2237c478bd9Sstevel@tonic-gate 	kmutex_t		isq_wqe_mutex;	/* WQE management list mutex */
2247c478bd9Sstevel@tonic-gate 	ibmf_wqe_mgt_t		*isq_wqe_mgt_list; /* WQE management list */
2257c478bd9Sstevel@tonic-gate } ibmf_alt_qp_t;
2267c478bd9Sstevel@tonic-gate _NOTE(MUTEX_PROTECTS_DATA(ibmf_alt_qp_t::isq_mutex,
2277c478bd9Sstevel@tonic-gate     ibmf_alt_qp_t::isq_sends_active
2287c478bd9Sstevel@tonic-gate     ibmf_alt_qp_t::isq_recvs_active
2297c478bd9Sstevel@tonic-gate     ibmf_alt_qp_t::isq_pkey
2307c478bd9Sstevel@tonic-gate     ibmf_alt_qp_t::isq_qkey
2317c478bd9Sstevel@tonic-gate     ibmf_alt_qp_t::isq_recv_cb
2327c478bd9Sstevel@tonic-gate     ibmf_alt_qp_t::isq_recv_cb_arg
2337c478bd9Sstevel@tonic-gate     ibmf_alt_qp_t::isq_flags
2347c478bd9Sstevel@tonic-gate     ibmf_alt_qp_t::isq_rwqes_posted))
2357c478bd9Sstevel@tonic-gate _NOTE(MUTEX_PROTECTS_DATA(ibmf_alt_qp_t::isq_wqe_mutex,
2367c478bd9Sstevel@tonic-gate     ibmf_alt_qp_t::isq_wqe_mgt_list))
2377c478bd9Sstevel@tonic-gate _NOTE(READ_ONLY_DATA(ibmf_alt_qp_t::isq_port_num))
2387c478bd9Sstevel@tonic-gate 
2397c478bd9Sstevel@tonic-gate #define	IBMF_MSG_FLAGS_QUEUED		0x00001000	/* in the ib xport */
2407c478bd9Sstevel@tonic-gate #define	IBMF_MSG_FLAGS_DONE		0x00002000	/* xport done */
2417c478bd9Sstevel@tonic-gate #define	IBMF_MSG_FLAGS_BLOCKING		0x00004000	/* sync command */
2427c478bd9Sstevel@tonic-gate 
2437c478bd9Sstevel@tonic-gate /*
2447c478bd9Sstevel@tonic-gate  * This structure is used to keep track of IBT returned ibt_ud_dest_t
2457c478bd9Sstevel@tonic-gate  * structures.
2467c478bd9Sstevel@tonic-gate  */
2477c478bd9Sstevel@tonic-gate typedef struct ibmf_ud_dest_s {
2487c478bd9Sstevel@tonic-gate 	ibt_ud_dest_t		ud_dest;
2497c478bd9Sstevel@tonic-gate 	struct ibmf_ud_dest_s	*ud_next;
2507c478bd9Sstevel@tonic-gate } ibmf_ud_dest_t;
2517c478bd9Sstevel@tonic-gate 
2527c478bd9Sstevel@tonic-gate /*
2537c478bd9Sstevel@tonic-gate  * ibmf_msg_impl definition
2547c478bd9Sstevel@tonic-gate  *	The IBMF client initializes various members of the msg while sending
2557c478bd9Sstevel@tonic-gate  *	the message. IBMF fills in the various members of the msg when a message
2567c478bd9Sstevel@tonic-gate  *	is received.
2577c478bd9Sstevel@tonic-gate  */
2587c478bd9Sstevel@tonic-gate typedef struct _ibmf_msg_impl {
2597c478bd9Sstevel@tonic-gate 	ibmf_addr_info_t	im_local_addr;	/* local addressing info */
2607c478bd9Sstevel@tonic-gate 	ibmf_global_addr_info_t	im_global_addr;	/* global addressing info */
2617c478bd9Sstevel@tonic-gate 	int32_t			im_msg_status;	/* completion status */
2627c478bd9Sstevel@tonic-gate 	uint32_t		im_msg_flags;	/* flags */
2637c478bd9Sstevel@tonic-gate 	size_t			im_msg_sz_limit; /* max. message size */
2647c478bd9Sstevel@tonic-gate 	ibmf_msg_bufs_t		im_msgbufs_send; /* input data to ibmf */
2657c478bd9Sstevel@tonic-gate 	ibmf_msg_bufs_t		im_msgbufs_recv; /* output data from ibmf */
2667c478bd9Sstevel@tonic-gate 	struct _ibmf_msg_impl	*im_msg_next;	/* next message on the list */
2677c478bd9Sstevel@tonic-gate 	struct _ibmf_msg_impl	*im_msg_prev;	/* prev message on the list */
2687c478bd9Sstevel@tonic-gate 	void			*im_client;	/* client that allocd the pkt */
2697c478bd9Sstevel@tonic-gate 	ibmf_qp_handle_t	im_qp_hdl;	/* qp handle */
2707c478bd9Sstevel@tonic-gate 	ibt_ud_dest_t		*im_ud_dest;	/* ptr to the pkt's ud_dest */
2717c478bd9Sstevel@tonic-gate 	ibmf_ud_dest_t		*im_ibmf_ud_dest; /* ptr to the pkt's ud_dest */
2727c478bd9Sstevel@tonic-gate 	ibmf_msg_cb_t		im_trans_cb;	/* transaction completion cb */
2737c478bd9Sstevel@tonic-gate 	void			*im_trans_cb_arg; /* arg for completion cb */
2747c478bd9Sstevel@tonic-gate 	uint64_t		im_tid;		/* transaction ID */
2757c478bd9Sstevel@tonic-gate 	uint8_t			im_mgt_class; 	/* management class */
2767c478bd9Sstevel@tonic-gate 	kmutex_t		im_mutex;	/* protects trans context */
2777c478bd9Sstevel@tonic-gate 	uint32_t		im_state;	/* message state */
2787c478bd9Sstevel@tonic-gate 	uint32_t		im_transp_op_flags; /* transaction operation */
2797c478bd9Sstevel@tonic-gate 	uint32_t		im_flags;	/* message flags */
2807c478bd9Sstevel@tonic-gate 	uint32_t		im_trans_state_flags;	/* state flags */
2817c478bd9Sstevel@tonic-gate 	kcondvar_t		im_trans_cv;	/* wait for op completion */
2827c478bd9Sstevel@tonic-gate 	ibmf_rmpp_ctx_t		im_rmpp_ctx; 	/* RMPP context */
2837c478bd9Sstevel@tonic-gate 	ibmf_retrans_t		im_retrans;	/* retransmission info */
2847c478bd9Sstevel@tonic-gate 	timeout_id_t		im_rp_timeout_id; /* response timeout ID */
2857c478bd9Sstevel@tonic-gate 	timeout_id_t		im_tr_timeout_id; /* transaction timeout ID */
2867c478bd9Sstevel@tonic-gate 	timeout_id_t		im_rp_unset_timeout_id; /* id for untimeout() */
2877c478bd9Sstevel@tonic-gate 	timeout_id_t		im_tr_unset_timeout_id; /* id for untimeout() */
2887c478bd9Sstevel@tonic-gate 	int			im_ref_count;	/* reference count */
2897c478bd9Sstevel@tonic-gate 	boolean_t		im_unsolicited; /* msg was unsolicited recv */
2907c478bd9Sstevel@tonic-gate 	int			im_pending_send_compls; /* send completions */
2917c478bd9Sstevel@tonic-gate } ibmf_msg_impl_t;
2927c478bd9Sstevel@tonic-gate _NOTE(READ_ONLY_DATA(ibmf_msg_impl_t::im_trans_cb
2937c478bd9Sstevel@tonic-gate     ibmf_msg_impl_t::im_trans_cb_arg
2947c478bd9Sstevel@tonic-gate     ibmf_msg_impl_t::im_transp_op_flags
2957c478bd9Sstevel@tonic-gate     ibmf_msg_impl_t::im_local_addr
2967c478bd9Sstevel@tonic-gate     ibmf_msg_impl_t::im_unsolicited
2977c478bd9Sstevel@tonic-gate     ibmf_msg_impl_t::im_client))
2987c478bd9Sstevel@tonic-gate _NOTE(MUTEX_PROTECTS_DATA(ibmf_msg_impl_t::im_mutex,
2997c478bd9Sstevel@tonic-gate     ibmf_msg_impl_t::im_flags
3007c478bd9Sstevel@tonic-gate     ibmf_msg_impl_t::im_trans_state_flags
3017c478bd9Sstevel@tonic-gate     ibmf_msg_impl_t::im_msgbufs_recv
3027c478bd9Sstevel@tonic-gate     ibmf_msg_impl_t::im_msg_status
3037c478bd9Sstevel@tonic-gate     ibmf_msg_impl_t::im_rmpp_ctx))
3047c478bd9Sstevel@tonic-gate 
3057c478bd9Sstevel@tonic-gate /* im_flags */
3067c478bd9Sstevel@tonic-gate #define	IBMF_MSG_FLAGS_SEQUENCED	0x1
3077c478bd9Sstevel@tonic-gate #define	IBMF_MSG_FLAGS_SEND_RMPP	0x2
3087c478bd9Sstevel@tonic-gate #define	IBMF_MSG_FLAGS_RECV_RMPP	0x4
3097c478bd9Sstevel@tonic-gate #define	IBMF_MSG_FLAGS_NOT_RMPP		0x8
3107c478bd9Sstevel@tonic-gate #define	IBMF_MSG_FLAGS_BUSY		0x10
3117c478bd9Sstevel@tonic-gate #define	IBMF_MSG_FLAGS_FREE		0x20
3127c478bd9Sstevel@tonic-gate #define	IBMF_MSG_FLAGS_ON_LIST		0x40
3137c478bd9Sstevel@tonic-gate #define	IBMF_MSG_FLAGS_SET_TERMINATION	0x80
3147c478bd9Sstevel@tonic-gate #define	IBMF_MSG_FLAGS_TERMINATION	0x100
3157c478bd9Sstevel@tonic-gate 
3167c478bd9Sstevel@tonic-gate /* retransmission parameter defaults for im_retrans field */
3177c478bd9Sstevel@tonic-gate #define	IBMF_RETRANS_DEF_RTV		4000000		/* 4 seconds */
3187c478bd9Sstevel@tonic-gate #define	IBMF_RETRANS_DEF_RTTV		100000		/* 100 milliseconds */
3197c478bd9Sstevel@tonic-gate #define	IBMF_RETRANS_DEF_TRANS_TO	40000000	/* 40 seconds */
3207c478bd9Sstevel@tonic-gate #define	IBMF_RETRANS_DEF_RETRIES	0
3217c478bd9Sstevel@tonic-gate 
3227c478bd9Sstevel@tonic-gate /*
3237c478bd9Sstevel@tonic-gate  * Transaction state flags (im_trans_state_flags) definitions
3247c478bd9Sstevel@tonic-gate  * Don't use 0x0 as a flag value since clients OR and AND the flags
3257c478bd9Sstevel@tonic-gate  */
3267c478bd9Sstevel@tonic-gate #define	IBMF_TRANS_STATE_FLAG_UNINIT		0x1
3277c478bd9Sstevel@tonic-gate #define	IBMF_TRANS_STATE_FLAG_INIT		0x2
3287c478bd9Sstevel@tonic-gate #define	IBMF_TRANS_STATE_FLAG_WAIT		0x4
3297c478bd9Sstevel@tonic-gate #define	IBMF_TRANS_STATE_FLAG_DONE		0x8
3307c478bd9Sstevel@tonic-gate #define	IBMF_TRANS_STATE_FLAG_SIGNALED		0x10
3317c478bd9Sstevel@tonic-gate #define	IBMF_TRANS_STATE_FLAG_TIMEOUT		0x20
3327c478bd9Sstevel@tonic-gate #define	IBMF_TRANS_STATE_FLAG_RECV_ACTIVE	0x40
3337c478bd9Sstevel@tonic-gate #define	IBMF_TRANS_STATE_FLAG_RECV_DONE		0x80
3347c478bd9Sstevel@tonic-gate #define	IBMF_TRANS_STATE_FLAG_SEND_DONE		0x100
3357c478bd9Sstevel@tonic-gate 
3367c478bd9Sstevel@tonic-gate /* Timer types */
3377c478bd9Sstevel@tonic-gate typedef	enum _ibmf_timer_t {
3387c478bd9Sstevel@tonic-gate 	IBMF_RESP_TIMER			= 1,
3397c478bd9Sstevel@tonic-gate 	IBMF_TRANS_TIMER		= 2
3407c478bd9Sstevel@tonic-gate } ibmf_timer_t;
3417c478bd9Sstevel@tonic-gate 
3427c478bd9Sstevel@tonic-gate /*
3437c478bd9Sstevel@tonic-gate  * structure to hold specific client info taken from ibmf_register_info_t
3447c478bd9Sstevel@tonic-gate  * since we can register for more than one client at a time, but each specific
3457c478bd9Sstevel@tonic-gate  * ibmf_client_t only holds one client itself.
3467c478bd9Sstevel@tonic-gate  */
3477c478bd9Sstevel@tonic-gate typedef struct _ibmf_client_info {
3487c478bd9Sstevel@tonic-gate 	ib_guid_t		ci_guid;
3497c478bd9Sstevel@tonic-gate 	uint_t			port_num;
3507c478bd9Sstevel@tonic-gate 	ibmf_client_type_t	client_class;
3517c478bd9Sstevel@tonic-gate } ibmf_client_info_t;
3527c478bd9Sstevel@tonic-gate 
3537c478bd9Sstevel@tonic-gate /*
3547c478bd9Sstevel@tonic-gate  * Defines for the client type (agent/manager/agent+manager)
3557c478bd9Sstevel@tonic-gate  * Bits 16-19 of the client_class specify the client type.
3567c478bd9Sstevel@tonic-gate  */
3577c478bd9Sstevel@tonic-gate #define	IBMF_AGENT_ID			0x00010000
3587c478bd9Sstevel@tonic-gate #define	IBMF_MANAGER_ID			0x00020000
3597c478bd9Sstevel@tonic-gate #define	IBMF_AGENT_MANAGER_ID		0x00030000
3607c478bd9Sstevel@tonic-gate 
3617c478bd9Sstevel@tonic-gate /*
3627c478bd9Sstevel@tonic-gate  * structure used to keep track of clients
3637c478bd9Sstevel@tonic-gate  */
3647c478bd9Sstevel@tonic-gate typedef struct _ibmf_client {
3657c478bd9Sstevel@tonic-gate 	void			*ic_client_sig;	/* set for valid handles */
3667c478bd9Sstevel@tonic-gate 	struct _ibmf_ci		*ic_myci;	/* pointer to CI */
3677c478bd9Sstevel@tonic-gate 	struct _ibmf_client	*ic_next;	/* next client on list */
3687c478bd9Sstevel@tonic-gate 	struct _ibmf_client	*ic_prev;	/* previous client on list */
3697c478bd9Sstevel@tonic-gate 
3707c478bd9Sstevel@tonic-gate 	taskq_t			*ic_send_taskq;	/* taskq for send cb */
3717c478bd9Sstevel@tonic-gate 	taskq_t			*ic_recv_taskq;	/* taskq for receive cb */
3727c478bd9Sstevel@tonic-gate 	uint_t			ic_init_state_class; /* taskq initialization */
3737c478bd9Sstevel@tonic-gate 
3747c478bd9Sstevel@tonic-gate 	ibmf_msg_impl_t		*ic_msg_list; /* protected by ic_mutex */
3757c478bd9Sstevel@tonic-gate 	ibmf_msg_impl_t		*ic_msg_last; /* last message on list */
3767c478bd9Sstevel@tonic-gate 	ibmf_msg_impl_t		*ic_term_msg_list; /* termination loop mesgs */
3777c478bd9Sstevel@tonic-gate 	ibmf_msg_impl_t		*ic_term_msg_last; /* last message on list */
3787c478bd9Sstevel@tonic-gate 	kmutex_t		ic_msg_mutex; /* protect the message list */
3797c478bd9Sstevel@tonic-gate 
3807c478bd9Sstevel@tonic-gate 	/* IBTL asynchronous event callback (eg. HCA offline) */
3817c478bd9Sstevel@tonic-gate 	ibmf_async_event_cb_t	ic_async_cb; /* async/unsolicited handling */
3827c478bd9Sstevel@tonic-gate 	void			*ic_async_cb_arg; /* args for async cb */
3837c478bd9Sstevel@tonic-gate 
3847c478bd9Sstevel@tonic-gate 	/* Asynchronous/Unsolicited message handler */
3857c478bd9Sstevel@tonic-gate 	ibmf_msg_cb_t		ic_recv_cb;
3867c478bd9Sstevel@tonic-gate 	void			*ic_recv_cb_arg;
3877c478bd9Sstevel@tonic-gate 	kcondvar_t		ic_recv_cb_teardown_cv; /* wait on teardown */
3887c478bd9Sstevel@tonic-gate 
3897c478bd9Sstevel@tonic-gate 	ibmf_client_info_t	ic_client_info; /* client registration info */
3907c478bd9Sstevel@tonic-gate 	ibmf_qp_t		*ic_qp;		/* special qp context */
3917c478bd9Sstevel@tonic-gate 	ibt_hca_hdl_t		ic_ci_handle;	/* == ic_myci->ic_ci_handle */
3927c478bd9Sstevel@tonic-gate 	kmutex_t		ic_mutex;	/* prot the client struct */
3937c478bd9Sstevel@tonic-gate 	int			ic_flags;	/* to keep track of state */
3947c478bd9Sstevel@tonic-gate 	int			ic_reg_flags;	/* flags specified during */
3957c478bd9Sstevel@tonic-gate 						/* registration */
3967c478bd9Sstevel@tonic-gate 
3977c478bd9Sstevel@tonic-gate 	/* Statistics */
3987c478bd9Sstevel@tonic-gate 	int			ic_msgs_alloced; /* no. msgs alloced by/for */
3997c478bd9Sstevel@tonic-gate 	int			ic_msgs_active; /* no. msgs active */
4007c478bd9Sstevel@tonic-gate 	int			ic_trans_active; /* outstanding transacts  */
4017c478bd9Sstevel@tonic-gate 	int			ic_sends_active; /* outstanding sends */
4027c478bd9Sstevel@tonic-gate 	int			ic_recvs_active; /* outstanding recvs */
4037c478bd9Sstevel@tonic-gate 
4047c478bd9Sstevel@tonic-gate 	ib_lid_t		ic_base_lid;	/* used to calculate pathbits */
4057c478bd9Sstevel@tonic-gate 	kmutex_t		ic_kstat_mutex;	/* protect the kstat */
4067c478bd9Sstevel@tonic-gate 	struct kstat		*ic_kstatp;	/* kstats for client */
4077c478bd9Sstevel@tonic-gate } ibmf_client_t;
4087c478bd9Sstevel@tonic-gate _NOTE(READ_ONLY_DATA(ibmf_client_t::ic_ci_handle
4097c478bd9Sstevel@tonic-gate     ibmf_client_t::ic_client_info
4107c478bd9Sstevel@tonic-gate     ibmf_client_t::ic_client_sig))
4117c478bd9Sstevel@tonic-gate _NOTE(MUTEX_PROTECTS_DATA(ibmf_client_t::ic_msg_mutex,
4127c478bd9Sstevel@tonic-gate     ibmf_client_t::ic_msg_list
4137c478bd9Sstevel@tonic-gate     ibmf_client_t::ic_msg_last
4147c478bd9Sstevel@tonic-gate     ibmf_client_t::ic_term_msg_list
4157c478bd9Sstevel@tonic-gate     ibmf_client_t::ic_term_msg_last))
4167c478bd9Sstevel@tonic-gate _NOTE(MUTEX_PROTECTS_DATA(ibmf_client_t::ic_mutex,
4177c478bd9Sstevel@tonic-gate     ibmf_client_t::ic_msgs_alloced
4187c478bd9Sstevel@tonic-gate     ibmf_client_t::ic_flags
4197c478bd9Sstevel@tonic-gate     ibmf_client_t::ic_recv_cb
4207c478bd9Sstevel@tonic-gate     ibmf_client_t::ic_recv_cb_arg))
4217c478bd9Sstevel@tonic-gate _NOTE(MUTEX_PROTECTS_DATA(ibmf_client_t::ic_kstat_mutex,
4227c478bd9Sstevel@tonic-gate     ibmf_client_t::ic_kstatp))
4237c478bd9Sstevel@tonic-gate 
4247c478bd9Sstevel@tonic-gate #define	IBMF_CLIENT_RECV_CB_ACTIVE		0x00000001 /* rcv CB active */
4257c478bd9Sstevel@tonic-gate #define	IBMF_CLIENT_SEND_CB_ACTIVE		0x00000010 /* send CB active */
4267c478bd9Sstevel@tonic-gate #define	IBMF_CLIENT_TEAR_DOWN_CB		0x00000100 /* client wants to */
4277c478bd9Sstevel@tonic-gate 							    /* remove recv_cb */
4287c478bd9Sstevel@tonic-gate 
4297c478bd9Sstevel@tonic-gate /* IBMF_MAD_ONLY is used by the alternate QP context only (isq_flags) */
4307c478bd9Sstevel@tonic-gate #define	IBMF_MAD_ONLY				0x00002000
4317c478bd9Sstevel@tonic-gate #define	IBMF_RAW_ONLY				0x00004000
4327c478bd9Sstevel@tonic-gate 
4337c478bd9Sstevel@tonic-gate #define	IBMF_REG_MSG_LIST	0
4347c478bd9Sstevel@tonic-gate #define	IBMF_TERM_MSG_LIST	1
4357c478bd9Sstevel@tonic-gate 
4367c478bd9Sstevel@tonic-gate /*
4377c478bd9Sstevel@tonic-gate  * Send WQE context
4387c478bd9Sstevel@tonic-gate  */
4397c478bd9Sstevel@tonic-gate typedef struct _ibmf_send_wqe {
4407c478bd9Sstevel@tonic-gate 	struct _ibmf_send_wqe	*send_wqe_next;
4417c478bd9Sstevel@tonic-gate 	ibt_send_wr_t		send_wr;	/* IBT send work request */
4427c478bd9Sstevel@tonic-gate 	ibmf_client_t		*send_client;	/* client that sent this */
4437c478bd9Sstevel@tonic-gate 	void			*send_mem;	/* memory used in send */
4447c478bd9Sstevel@tonic-gate 	ib_vaddr_t		send_sg_mem;	/* registered memory */
4457c478bd9Sstevel@tonic-gate 	ibt_lkey_t		send_sg_lkey;	/* Lkey that goes with it */
4467c478bd9Sstevel@tonic-gate 	ibt_mr_hdl_t		send_mem_hdl;	/* == ci_send_mr_handle in ci */
4477c478bd9Sstevel@tonic-gate 	uint_t			send_wqe_flags;
4487c478bd9Sstevel@tonic-gate 	uchar_t			send_port_num;	/* port this is posted to */
4497c478bd9Sstevel@tonic-gate 	ibt_qp_hdl_t		send_qp_handle;	/* qp handle for this wqe */
4507c478bd9Sstevel@tonic-gate 	ibmf_qp_handle_t	send_ibmf_qp_handle; /* ibmf qp handle */
4517c478bd9Sstevel@tonic-gate 	ibmf_msg_impl_t		*send_msg;	/* message context */
4527c478bd9Sstevel@tonic-gate 	uint32_t		send_status;	/* completion status */
4537c478bd9Sstevel@tonic-gate 	uint32_t		send_rmpp_segment; /* rmpp segment */
4547c478bd9Sstevel@tonic-gate } ibmf_send_wqe_t;
4557c478bd9Sstevel@tonic-gate 
4567c478bd9Sstevel@tonic-gate /*
4577c478bd9Sstevel@tonic-gate  * Receive WQE context
4587c478bd9Sstevel@tonic-gate  */
4597c478bd9Sstevel@tonic-gate typedef struct _ibmf_recv_wqe {
4607c478bd9Sstevel@tonic-gate 	struct _ibmf_recv_wqe	*recv_wqe_next;
4617c478bd9Sstevel@tonic-gate 	ibt_recv_wr_t		recv_wr;
4627c478bd9Sstevel@tonic-gate 	ibmf_client_t		*recv_client;	/* client that received this */
4637c478bd9Sstevel@tonic-gate 	void			*recv_mem;	/* memory used in WQEs */
4647c478bd9Sstevel@tonic-gate 	ibmf_qp_t		*recv_qpp;	/* qp this is posted */
4657c478bd9Sstevel@tonic-gate 	ibt_wc_t		recv_wc;	/* corresponding  cqe */
4667c478bd9Sstevel@tonic-gate 	ib_vaddr_t		recv_sg_mem;	/* registered mem */
4677c478bd9Sstevel@tonic-gate 	ibt_lkey_t		recv_sg_lkey;	/* Lkey that goes with it */
4687c478bd9Sstevel@tonic-gate 	ibt_mr_hdl_t		recv_mem_hdl;	/* == ci_recv_mr_handle in ci */
4697c478bd9Sstevel@tonic-gate 	uint_t			recv_wqe_flags;
4707c478bd9Sstevel@tonic-gate 	uchar_t			recv_port_num;	/* port this is posted to */
4717c478bd9Sstevel@tonic-gate 	ibt_qp_hdl_t		recv_qp_handle;	/* ibt qp handle for this wqe */
4727c478bd9Sstevel@tonic-gate 	ibmf_qp_handle_t	recv_ibmf_qp_handle; /* ibmf qp handle */
4737c478bd9Sstevel@tonic-gate 	ibmf_msg_impl_t		*recv_msg;	/* message context */
4747c478bd9Sstevel@tonic-gate } ibmf_recv_wqe_t;
4757c478bd9Sstevel@tonic-gate 
4767c478bd9Sstevel@tonic-gate #define	IBMF_RECV_WQE_FREE		0x00000001	/* WQE is free */
4777c478bd9Sstevel@tonic-gate 
4787c478bd9Sstevel@tonic-gate /*
4797c478bd9Sstevel@tonic-gate  * Struct that keeps track of the underlying IB channel interface. There
4807c478bd9Sstevel@tonic-gate  * is one per CI. Each clients on a given ci gets a reference to the CI.
4817c478bd9Sstevel@tonic-gate  * References are tracked used ci_ref field; when ci_ref drops to 0, the
4827c478bd9Sstevel@tonic-gate  * structure can be freed.
4837c478bd9Sstevel@tonic-gate  */
4847c478bd9Sstevel@tonic-gate typedef struct _ibmf_ci {
4857c478bd9Sstevel@tonic-gate 	struct _ibmf_ci		*ci_next;
4867c478bd9Sstevel@tonic-gate 	kmutex_t		ci_mutex;	/* protects the CI struct */
4877c478bd9Sstevel@tonic-gate 	ibmf_client_t		*ci_clients;	/* list of clients;head */
4887c478bd9Sstevel@tonic-gate 	ibmf_client_t		*ci_clients_last; /* tail */
4897c478bd9Sstevel@tonic-gate 	kmutex_t		ci_clients_mutex; /* protect the client list */
4907c478bd9Sstevel@tonic-gate 	ib_guid_t		ci_node_guid;	/* node GUID */
4917c478bd9Sstevel@tonic-gate 	ibt_hca_hdl_t		ci_ci_handle;	/* HCA handle */
4927c478bd9Sstevel@tonic-gate 	ibt_pd_hdl_t		ci_pd;		/* protection domain */
4937c478bd9Sstevel@tonic-gate 	ibmf_qp_t		*ci_qp_list;	/* sp. QP list for all ports */
4947c478bd9Sstevel@tonic-gate 	ibmf_qp_t		*ci_qp_list_tail;
4957c478bd9Sstevel@tonic-gate 	kcondvar_t		ci_qp_cv;	/* wait for QP valid state */
4967c478bd9Sstevel@tonic-gate 	ibt_cq_hdl_t		ci_cq_handle;	/* CQ handle for sp. QPs */
4977c478bd9Sstevel@tonic-gate 	ibt_cq_hdl_t		ci_alt_cq_handle; /* CQ handle for alt. QPs */
4987c478bd9Sstevel@tonic-gate 	ibmf_alt_qp_t		*ci_alt_qp_list; /* alternate QP list */
4997c478bd9Sstevel@tonic-gate 
5007c478bd9Sstevel@tonic-gate 	/* UD destination resources */
5017c478bd9Sstevel@tonic-gate 	uint32_t		ci_ud_dest_list_count; /* resources in pool */
5027c478bd9Sstevel@tonic-gate 	kmutex_t		ci_ud_dest_list_mutex; /* UD dest list mutex */
5037c478bd9Sstevel@tonic-gate 	ibmf_ud_dest_t		*ci_ud_dest_list_head; /* start of list */
5047c478bd9Sstevel@tonic-gate 
5057c478bd9Sstevel@tonic-gate 	/* Send/Receive WQEs for Special QPs */
5067c478bd9Sstevel@tonic-gate 	struct kmem_cache	*ci_send_wqes_cache; /* Send WQE cache */
5077c478bd9Sstevel@tonic-gate 	struct kmem_cache	*ci_recv_wqes_cache; /* Receive WQE cache */
5087c478bd9Sstevel@tonic-gate 	vmem_t			*ci_wqe_ib_vmem; /* IB virtual address arena */
5097c478bd9Sstevel@tonic-gate 	kmutex_t		ci_wqe_mutex;	/* WQE management list mutex */
5107c478bd9Sstevel@tonic-gate 	ibmf_wqe_mgt_t		*ci_wqe_mgt_list; /* WQE management list */
5117c478bd9Sstevel@tonic-gate 
5127c478bd9Sstevel@tonic-gate 	uint_t			ci_nports;	/* num ports on the CI */
5137c478bd9Sstevel@tonic-gate 	uint32_t		ci_vendor_id:24; /* HCA vendor ID */
5147c478bd9Sstevel@tonic-gate 	uint16_t		ci_device_id;	/* HCA device ID */
5157c478bd9Sstevel@tonic-gate 	uint_t			ci_ref;		/* reference count */
5167c478bd9Sstevel@tonic-gate 	uint16_t		ci_state;	/* CI context state */
5177c478bd9Sstevel@tonic-gate 	uint16_t		ci_state_flags;	/* CI context state flags */
5187c478bd9Sstevel@tonic-gate 	kcondvar_t		ci_state_cv;	/* wait on a state change */
5197c478bd9Sstevel@tonic-gate 	uint_t			ci_init_state;	/* used in cleanup */
5207c478bd9Sstevel@tonic-gate 
5217c478bd9Sstevel@tonic-gate 	/* free QP synchronization with WQE completion processing */
5227c478bd9Sstevel@tonic-gate 	int			ci_wqes_alloced; /* wqes alloced for sp QPs */
5237c478bd9Sstevel@tonic-gate 	kcondvar_t		ci_wqes_cv; 	/* wait on wqes destruction */
5247c478bd9Sstevel@tonic-gate 
5257c478bd9Sstevel@tonic-gate 	/* port kstats */
5267c478bd9Sstevel@tonic-gate 	struct kstat		*ci_port_kstatp;	/* kstats for client */
5277c478bd9Sstevel@tonic-gate } ibmf_ci_t;
5287c478bd9Sstevel@tonic-gate _NOTE(MUTEX_PROTECTS_DATA(ibmf_ci_t::ci_ud_dest_list_mutex,
5297c478bd9Sstevel@tonic-gate     ibmf_ci_t::ci_ud_dest_list_count
5307c478bd9Sstevel@tonic-gate     ibmf_ci_t::ci_ud_dest_list_head))
5317c478bd9Sstevel@tonic-gate _NOTE(MUTEX_PROTECTS_DATA(ibmf_ci_t::ci_mutex,
5327c478bd9Sstevel@tonic-gate     ibmf_ci_t::ci_state
5337c478bd9Sstevel@tonic-gate     ibmf_ci_t::ci_port_kstatp))
5347c478bd9Sstevel@tonic-gate _NOTE(MUTEX_PROTECTS_DATA(ibmf_ci_t::ci_clients_mutex,
5357c478bd9Sstevel@tonic-gate     ibmf_ci_t::ci_clients
5367c478bd9Sstevel@tonic-gate     ibmf_ci_t::ci_clients_last))
5377c478bd9Sstevel@tonic-gate _NOTE(MUTEX_PROTECTS_DATA(ibmf_ci_t::ci_mutex,
5387c478bd9Sstevel@tonic-gate     ibmf_qp_t::iq_next
5397c478bd9Sstevel@tonic-gate     ibmf_qp_t::iq_flags))
5407c478bd9Sstevel@tonic-gate _NOTE(MUTEX_PROTECTS_DATA(ibmf_ci_t::ci_wqe_mutex,
5417c478bd9Sstevel@tonic-gate     ibmf_ci_t::ci_wqe_mgt_list))
5427c478bd9Sstevel@tonic-gate _NOTE(READ_ONLY_DATA(ibmf_ci_t::ci_cq_handle))
5437c478bd9Sstevel@tonic-gate 
5447c478bd9Sstevel@tonic-gate #define	IBMF_CI_BLOCKED_ON_SEND_WQE		0x00000001 /* blockers on wqe */
5457c478bd9Sstevel@tonic-gate 
5467c478bd9Sstevel@tonic-gate /* defines for ci_init_state */
5477c478bd9Sstevel@tonic-gate #define	IBMF_CI_INIT_HCA_INITED				0x0001
5487c478bd9Sstevel@tonic-gate #define	IBMF_CI_INIT_MUTEX_CV_INITED			0x0002
5497c478bd9Sstevel@tonic-gate #define	IBMF_CI_INIT_SEND_TASKQ_DONE			0x0004
5507c478bd9Sstevel@tonic-gate #define	IBMF_CI_INIT_RECV_TASKQ_DONE			0x0008
5517c478bd9Sstevel@tonic-gate #define	IBMF_CI_INIT_CQ_INITED				0x0010
5527c478bd9Sstevel@tonic-gate #define	IBMF_CI_INIT_WQES_ALLOCED			0x0020
5537c478bd9Sstevel@tonic-gate #define	IBMF_CI_INIT_HCA_LINKED				0x0040
5547c478bd9Sstevel@tonic-gate #define	IBMF_CI_INIT_QP_LIST_INITED			0x0080
5557c478bd9Sstevel@tonic-gate 
5567c478bd9Sstevel@tonic-gate /* defines for ci_state */
5577c478bd9Sstevel@tonic-gate #define	IBMF_CI_STATE_PRESENT				0x0001
5587c478bd9Sstevel@tonic-gate #define	IBMF_CI_STATE_INITED				0x0002
5597c478bd9Sstevel@tonic-gate #define	IBMF_CI_STATE_GONE				0x0003
5607c478bd9Sstevel@tonic-gate 
5617c478bd9Sstevel@tonic-gate /* defines for ci_state_flags */
5627c478bd9Sstevel@tonic-gate #define	IBMF_CI_STATE_INIT_WAIT				0x0001
5637c478bd9Sstevel@tonic-gate #define	IBMF_CI_STATE_UNINIT_WAIT			0x0002
5647c478bd9Sstevel@tonic-gate #define	IBMF_CI_STATE_VALIDATE_WAIT			0x0004
5657c478bd9Sstevel@tonic-gate 
5667c478bd9Sstevel@tonic-gate #define	IBMF_CI_STATE_INVALIDATING			0x0100
5677c478bd9Sstevel@tonic-gate #define	IBMF_CI_STATE_VALIDATING			0x0200
5687c478bd9Sstevel@tonic-gate #define	IBMF_CI_STATE_UNINITING				0x0400
5697c478bd9Sstevel@tonic-gate #define	IBMF_CI_STATE_INITING				0x0800
5707c478bd9Sstevel@tonic-gate 
5717c478bd9Sstevel@tonic-gate /*
5727c478bd9Sstevel@tonic-gate  * for keeping track of ibmf state
5737c478bd9Sstevel@tonic-gate  */
5747c478bd9Sstevel@tonic-gate typedef struct _ibmf_state {
5757c478bd9Sstevel@tonic-gate 	struct _ibmf_ci		*ibmf_ci_list;
5767c478bd9Sstevel@tonic-gate 	struct _ibmf_ci		*ibmf_ci_list_tail;
5777c478bd9Sstevel@tonic-gate 	ibt_clnt_hdl_t		ibmf_ibt_handle;
5787c478bd9Sstevel@tonic-gate 	ibt_cq_handler_t	ibmf_cq_handler;
5797c478bd9Sstevel@tonic-gate 	kmutex_t		ibmf_mutex;
5807c478bd9Sstevel@tonic-gate 	ibt_clnt_modinfo_t	ibmf_ibt_modinfo;
5817c478bd9Sstevel@tonic-gate 	taskq_t			*ibmf_taskq;	/* taskq for MAD processing */
5827c478bd9Sstevel@tonic-gate 						/* for classes not registered */
5837c478bd9Sstevel@tonic-gate } ibmf_state_t;
5847c478bd9Sstevel@tonic-gate _NOTE(MUTEX_PROTECTS_DATA(ibmf_state_t::ibmf_mutex,
5857c478bd9Sstevel@tonic-gate     ibmf_ci_t::ci_next))
5867c478bd9Sstevel@tonic-gate 
5877c478bd9Sstevel@tonic-gate /* UD Destination resource cache definitions */
5887c478bd9Sstevel@tonic-gate /*
5897c478bd9Sstevel@tonic-gate  * It is preferred that the difference between the hi and lo water
5907c478bd9Sstevel@tonic-gate  * marks be only a few ud_dest resources. The intent is that a
5917c478bd9Sstevel@tonic-gate  * thread that needs to run ibmf_i_populate_ud_dest_list() does not
5927c478bd9Sstevel@tonic-gate  * spend too much time in this ud_dest resource population process
5937c478bd9Sstevel@tonic-gate  * before it returns to its caller. A benefit of a higher lo water
5947c478bd9Sstevel@tonic-gate  * mark is that the larger available pool of resources supports high
5957c478bd9Sstevel@tonic-gate  * stress scenarios better.
5967c478bd9Sstevel@tonic-gate  */
5977c478bd9Sstevel@tonic-gate #define	IBMF_UD_DEST_HI_WATER_MARK	512
5987c478bd9Sstevel@tonic-gate #define	IBMF_UD_DEST_LO_WATER_MARK	500
5997c478bd9Sstevel@tonic-gate 
6007c478bd9Sstevel@tonic-gate /*
6017c478bd9Sstevel@tonic-gate  * Prototypes
6027c478bd9Sstevel@tonic-gate  */
6037c478bd9Sstevel@tonic-gate /* ci related functions */
6047c478bd9Sstevel@tonic-gate int ibmf_i_validate_ci_guid_and_port(ib_guid_t hca_guid, uint8_t port_num);
6057c478bd9Sstevel@tonic-gate int ibmf_i_get_ci(ibmf_register_info_t *client_infop, ibmf_ci_t **cipp);
6067c478bd9Sstevel@tonic-gate void ibmf_i_release_ci(ibmf_ci_t *cip);
6077c478bd9Sstevel@tonic-gate 
6087c478bd9Sstevel@tonic-gate /* client related functions */
6097c478bd9Sstevel@tonic-gate int ibmf_i_validate_classes_and_port(ibmf_ci_t *ibmf_cip,
6107c478bd9Sstevel@tonic-gate     ibmf_register_info_t *client_infop);
6117c478bd9Sstevel@tonic-gate int ibmf_i_validate_class_mask(ibmf_register_info_t *client_infop);
6127c478bd9Sstevel@tonic-gate int ibmf_i_alloc_client(ibmf_register_info_t *client_infop, uint_t flags,
6137c478bd9Sstevel@tonic-gate     ibmf_client_t **clientpp);
6147c478bd9Sstevel@tonic-gate void ibmf_i_add_client(ibmf_ci_t *ibmf_ci, ibmf_client_t *ibmf_clientp);
6157c478bd9Sstevel@tonic-gate 
6167c478bd9Sstevel@tonic-gate void ibmf_i_free_client(ibmf_client_t *clientp);
6177c478bd9Sstevel@tonic-gate void ibmf_i_delete_client(ibmf_ci_t *ibmf_ci, ibmf_client_t *ibmf_clientp);
6187c478bd9Sstevel@tonic-gate int ibmf_i_lookup_client_by_mgmt_class(ibmf_ci_t *ibmf_cip, int port_num,
6197c478bd9Sstevel@tonic-gate     ibmf_client_type_t class, ibmf_client_t **clientpp);
6207c478bd9Sstevel@tonic-gate 
6217c478bd9Sstevel@tonic-gate /* qp related functions */
6227c478bd9Sstevel@tonic-gate int ibmf_i_get_qp(ibmf_ci_t *ibmf_cip, uint_t port_num,
6237c478bd9Sstevel@tonic-gate     ibmf_client_type_t class, ibmf_qp_t **qppp);
6247c478bd9Sstevel@tonic-gate void ibmf_i_release_qp(ibmf_ci_t *ibmf_cip, ibmf_qp_t **qpp);
6257c478bd9Sstevel@tonic-gate int ibmf_i_alloc_qp(ibmf_client_t *clientp, ib_pkey_t p_key,
6267c478bd9Sstevel@tonic-gate     ib_qkey_t q_key, uint_t flags, ibmf_qp_handle_t *ibmf_qp_handlep);
6277c478bd9Sstevel@tonic-gate int ibmf_i_free_qp(ibmf_qp_handle_t ibmf_qp_handle, uint_t flags);
6287c478bd9Sstevel@tonic-gate int ibmf_i_query_qp(ibmf_qp_handle_t ibmf_qp_handle, uint_t flags,
6297c478bd9Sstevel@tonic-gate     uint_t *qp_nump, ib_pkey_t *p_keyp, ib_qkey_t *q_keyp, uint8_t *portnump);
6307c478bd9Sstevel@tonic-gate int ibmf_i_modify_qp(ibmf_qp_handle_t ibmf_qp_handle, ib_pkey_t p_key,
6317c478bd9Sstevel@tonic-gate     ib_qkey_t q_key, uint_t flags);
6327c478bd9Sstevel@tonic-gate int ibmf_i_get_pkeyix(ibt_hca_hdl_t hca_handle, ib_pkey_t pkey,
6337c478bd9Sstevel@tonic-gate     uint8_t port, ib_pkey_t *pkeyixp);
6347c478bd9Sstevel@tonic-gate int ibmf_i_pkey_ix_to_key(ibmf_ci_t *cip, uint_t port_num, uint_t pkey_ix,
6357c478bd9Sstevel@tonic-gate     ib_pkey_t *pkeyp);
6367c478bd9Sstevel@tonic-gate 
6377c478bd9Sstevel@tonic-gate /* pkt related functions */
6387c478bd9Sstevel@tonic-gate int ibmf_i_issue_pkt(ibmf_client_t *clientp, ibmf_msg_impl_t *msgp,
6397c478bd9Sstevel@tonic-gate     ibmf_qp_handle_t ibmf_qp_handle, ibmf_send_wqe_t *send_wqep);
6407c478bd9Sstevel@tonic-gate int ibmf_i_alloc_ud_dest(ibmf_client_t *clientp,
6417c478bd9Sstevel@tonic-gate     ibmf_msg_impl_t *msgimplp, ibt_ud_dest_hdl_t *ud_dest_p, boolean_t block);
6427c478bd9Sstevel@tonic-gate void ibmf_i_free_ud_dest(ibmf_client_t *clientp,
6437c478bd9Sstevel@tonic-gate     ibmf_msg_impl_t *msgimplp);
6447c478bd9Sstevel@tonic-gate void ibmf_i_init_ud_dest(ibmf_ci_t *cip);
6457c478bd9Sstevel@tonic-gate void ibmf_i_fini_ud_dest(ibmf_ci_t *cip);
6467c478bd9Sstevel@tonic-gate ibmf_ud_dest_t *ibmf_i_get_ud_dest(ibmf_ci_t *cip);
6477c478bd9Sstevel@tonic-gate void ibmf_i_put_ud_dest(ibmf_ci_t *cip, ibmf_ud_dest_t *ud_dest);
6487c478bd9Sstevel@tonic-gate void ibmf_i_pop_ud_dest_thread(void *argp);
6497c478bd9Sstevel@tonic-gate void ibmf_i_clean_ud_dest_list(ibmf_ci_t *cip, boolean_t all);
6507c478bd9Sstevel@tonic-gate int ibmf_i_alloc_send_resources(ibmf_ci_t *cip, ibmf_msg_impl_t *msgp,
6517c478bd9Sstevel@tonic-gate     boolean_t block, ibmf_send_wqe_t **swqepp);
6527c478bd9Sstevel@tonic-gate void ibmf_i_free_send_resources(ibmf_ci_t *cip, ibmf_msg_impl_t *msgimplp,
6537c478bd9Sstevel@tonic-gate     ibmf_send_wqe_t *swqep);
6547c478bd9Sstevel@tonic-gate int ibmf_i_post_recv_buffer(ibmf_ci_t *cip, ibmf_qp_t *qpp, boolean_t block,
6557c478bd9Sstevel@tonic-gate     ibmf_qp_handle_t ibmf_qp_handle);
6567c478bd9Sstevel@tonic-gate int ibmf_i_is_ibmf_handle_valid(ibmf_handle_t ibmf_handle);
6577c478bd9Sstevel@tonic-gate int ibmf_i_is_qp_handle_valid(ibmf_handle_t ibmf_handle,
6587c478bd9Sstevel@tonic-gate     ibmf_qp_handle_t ibmf_qp_handle);
6597c478bd9Sstevel@tonic-gate int ibmf_i_check_for_loopback(ibmf_msg_impl_t *msgimplp, ibmf_msg_cb_t msgp,
6607c478bd9Sstevel@tonic-gate     void *msg_cb_args, ibmf_retrans_t *retrans, boolean_t *loopback);
6617c478bd9Sstevel@tonic-gate int ibmf_i_ibt_to_ibmf_status(ibt_status_t ibt_status);
6627c478bd9Sstevel@tonic-gate int ibmf_i_ibt_wc_to_ibmf_status(ibt_wc_status_t ibt_wc_status);
6637c478bd9Sstevel@tonic-gate int ibmf_i_send_pkt(ibmf_client_t *clientp, ibmf_qp_handle_t ibmf_qp_handle,
6647c478bd9Sstevel@tonic-gate     ibmf_msg_impl_t *msgimplp, int block);
6657c478bd9Sstevel@tonic-gate int ibmf_i_send_single_pkt(ibmf_client_t *clientp,
6667c478bd9Sstevel@tonic-gate     ibmf_qp_handle_t ibmf_qp_handle, ibmf_msg_impl_t *msgimplp, int block);
6677c478bd9Sstevel@tonic-gate 
6687c478bd9Sstevel@tonic-gate /* WQE related functions */
6697c478bd9Sstevel@tonic-gate int ibmf_i_init_wqes(ibmf_ci_t *cip);
6707c478bd9Sstevel@tonic-gate void ibmf_i_fini_wqes(ibmf_ci_t *cip);
6717c478bd9Sstevel@tonic-gate void ibmf_i_init_send_wqe(ibmf_client_t *clientp,
6727c478bd9Sstevel@tonic-gate     ibmf_msg_impl_t *msgimplp, ibt_wr_ds_t *sglp, ibmf_send_wqe_t *wqep,
6737c478bd9Sstevel@tonic-gate     ibt_ud_dest_hdl_t ud_dest, ibt_qp_hdl_t ibt_qp_handle,
6747c478bd9Sstevel@tonic-gate     ibmf_qp_handle_t ibmf_qp_handle);
6757c478bd9Sstevel@tonic-gate void ibmf_i_init_recv_wqe(ibmf_qp_t *qpp, ibt_wr_ds_t *sglp,
6767c478bd9Sstevel@tonic-gate     ibmf_recv_wqe_t *wqep, ibt_qp_hdl_t ibt_qp_handle,
6777c478bd9Sstevel@tonic-gate     ibmf_qp_handle_t ibmf_qp_handle);
6787c478bd9Sstevel@tonic-gate void ibmf_i_mad_completions(ibt_cq_hdl_t cq_handle, void *arg);
6797c478bd9Sstevel@tonic-gate #ifdef DEBUG
6807c478bd9Sstevel@tonic-gate void ibmf_i_dump_wcp(ibmf_ci_t *cip, ibt_wc_t *wcp, ibmf_recv_wqe_t *recv_wqep);
6817c478bd9Sstevel@tonic-gate #endif
6827c478bd9Sstevel@tonic-gate 
6837c478bd9Sstevel@tonic-gate void ibmf_ibt_async_handler(void *clnt_private, ibt_hca_hdl_t hca_hdl,
6847c478bd9Sstevel@tonic-gate     ibt_async_code_t code, ibt_async_event_t *event);
6857c478bd9Sstevel@tonic-gate 
6867c478bd9Sstevel@tonic-gate /* msg related functions */
6877c478bd9Sstevel@tonic-gate void ibmf_i_init_msg(ibmf_msg_impl_t *msgimplp, ibmf_msg_cb_t trans_cb,
6887c478bd9Sstevel@tonic-gate     void *trans_cb_arg, ibmf_retrans_t *retrans, boolean_t block);
6897c478bd9Sstevel@tonic-gate void ibmf_i_client_add_msg(ibmf_client_t *clientp, ibmf_msg_impl_t *msgimplp);
6907c478bd9Sstevel@tonic-gate void ibmf_i_client_rem_msg(ibmf_client_t *clientp, ibmf_msg_impl_t *msgimplp,
6917c478bd9Sstevel@tonic-gate     uint_t *refcnt);
6927c478bd9Sstevel@tonic-gate int ibmf_i_alloc_msg(ibmf_client_t *clientp, ibmf_msg_impl_t **msgp,
6937c478bd9Sstevel@tonic-gate     int km_flags);
6947c478bd9Sstevel@tonic-gate void ibmf_i_free_msg(ibmf_msg_impl_t *msgimplp);
6957c478bd9Sstevel@tonic-gate int ibmf_i_msg_transport(ibmf_client_t *clientp,
6967c478bd9Sstevel@tonic-gate     ibmf_qp_handle_t ibmf_qp_handle, ibmf_msg_impl_t *msgimplp, int blocking);
6977c478bd9Sstevel@tonic-gate void ibmf_i_decrement_ref_count(ibmf_msg_impl_t *msgimplp);
6987c478bd9Sstevel@tonic-gate void ibmf_i_handle_send_completion(ibmf_ci_t *cip, ibt_wc_t *wcp);
6997c478bd9Sstevel@tonic-gate void ibmf_i_handle_recv_completion(ibmf_ci_t *cip, ibt_wc_t *wcp);
7007c478bd9Sstevel@tonic-gate int ibmf_setup_recvbuf_on_error(ibmf_msg_impl_t *msgimplp, uchar_t *mad);
7017c478bd9Sstevel@tonic-gate 
7027c478bd9Sstevel@tonic-gate /* transaction related functions */
7037c478bd9Sstevel@tonic-gate void ibmf_i_terminate_transaction(ibmf_client_t *clientp,
7047c478bd9Sstevel@tonic-gate     ibmf_msg_impl_t *msgimplp, uint32_t status);
7057c478bd9Sstevel@tonic-gate void ibmf_i_notify_client(ibmf_msg_impl_t *msgimplp);
7067c478bd9Sstevel@tonic-gate void ibmf_i_notify_sequence(ibmf_client_t *clientp, ibmf_msg_impl_t *msgimplp,
7077c478bd9Sstevel@tonic-gate     int msg_flags);
7087c478bd9Sstevel@tonic-gate 
7097c478bd9Sstevel@tonic-gate /* timer related functions */
7107c478bd9Sstevel@tonic-gate void ibmf_i_set_timer(void (*func)(void *), ibmf_msg_impl_t *msgimplp,
7117c478bd9Sstevel@tonic-gate     ibmf_timer_t type);
7127c478bd9Sstevel@tonic-gate void ibmf_i_unset_timer(ibmf_msg_impl_t *msgimplp, ibmf_timer_t type);
7137c478bd9Sstevel@tonic-gate void ibmf_i_recv_timeout(void *argp);
7147c478bd9Sstevel@tonic-gate void ibmf_i_send_timeout(void *argp);
7157c478bd9Sstevel@tonic-gate void ibmf_i_err_terminate_timeout(void *msgp);
7167c478bd9Sstevel@tonic-gate 
7177c478bd9Sstevel@tonic-gate /* rmpp related functions */
7187c478bd9Sstevel@tonic-gate boolean_t ibmf_i_find_msg_client(ibmf_client_t *cl, ibmf_msg_impl_t *msgimplp,
7197c478bd9Sstevel@tonic-gate     boolean_t inc_refcnt);
7207c478bd9Sstevel@tonic-gate boolean_t ibmf_i_is_rmpp(ibmf_client_t *clientp,
7217c478bd9Sstevel@tonic-gate     ibmf_qp_handle_t ibmf_qp_handle);
7227c478bd9Sstevel@tonic-gate void ibmf_i_mgt_class_to_hdr_sz_off(uint32_t mgt_class, uint32_t *szp,
7237c478bd9Sstevel@tonic-gate     uint32_t *offp);
7247c478bd9Sstevel@tonic-gate ibmf_msg_impl_t *ibmf_i_find_msg(ibmf_client_t *clientp, uint64_t tid,
7257c478bd9Sstevel@tonic-gate     uint8_t mgt_class, uint8_t r_method, ib_lid_t lid, ib_gid_t *gid,
7267c478bd9Sstevel@tonic-gate     boolean_t gid_pr, ibmf_rmpp_hdr_t *rmpp_hdr, boolean_t msg_list);
7277c478bd9Sstevel@tonic-gate #ifdef NOTDEF
7287c478bd9Sstevel@tonic-gate ibmf_msg_impl_t *ibmf_i_find_term_msg(ibmf_client_t *clientp, uint64_t tid,
7297c478bd9Sstevel@tonic-gate     uint8_t mgt_class, ib_lid_t lid, ib_gid_t *gid, boolean_t gid_pr,
7307c478bd9Sstevel@tonic-gate     ibmf_rmpp_hdr_t *rmpp_hd);
7317c478bd9Sstevel@tonic-gate #endif
7327c478bd9Sstevel@tonic-gate void ibmf_i_handle_rmpp(ibmf_client_t *clientp, ibmf_qp_handle_t qp_hdl,
7337c478bd9Sstevel@tonic-gate     ibmf_msg_impl_t *msgimpl, uchar_t *madp);
7347c478bd9Sstevel@tonic-gate int ibmf_i_send_rmpp(ibmf_msg_impl_t *msgimplp, uint8_t rmpp_type,
7357c478bd9Sstevel@tonic-gate     uint8_t rmpp_status, uint32_t segno, uint32_t nwl, int block);
7367c478bd9Sstevel@tonic-gate int ibmf_i_send_rmpp_pkts(ibmf_client_t *clientp,
7377c478bd9Sstevel@tonic-gate     ibmf_qp_handle_t ibmf_qp_handle, ibmf_msg_impl_t *msgimplp, boolean_t isDS,
7387c478bd9Sstevel@tonic-gate     int block);
7397c478bd9Sstevel@tonic-gate void ibmf_i_send_rmpp_window(ibmf_msg_impl_t *msgimplp, int block);
7407c478bd9Sstevel@tonic-gate int ibmf_setup_term_ctx(ibmf_client_t *clientp, ibmf_msg_impl_t *regmsgimplp);
7417c478bd9Sstevel@tonic-gate 
7427c478bd9Sstevel@tonic-gate /* Alternate QP WQE cache functions */
7437c478bd9Sstevel@tonic-gate int ibmf_altqp_send_wqe_cache_constructor(void *buf, void *cdrarg,
7447c478bd9Sstevel@tonic-gate     int kmflags);
7457c478bd9Sstevel@tonic-gate void ibmf_altqp_send_wqe_cache_destructor(void *buf, void *cdrarg);
7467c478bd9Sstevel@tonic-gate int ibmf_altqp_recv_wqe_cache_constructor(void *buf, void *cdrarg,
7477c478bd9Sstevel@tonic-gate     int kmflags);
7487c478bd9Sstevel@tonic-gate void ibmf_altqp_recv_wqe_cache_destructor(void *buf, void *cdrarg);
7497c478bd9Sstevel@tonic-gate int ibmf_i_init_altqp_wqes(ibmf_alt_qp_t *qp_ctx);
7507c478bd9Sstevel@tonic-gate void ibmf_i_fini_altqp_wqes(ibmf_alt_qp_t *qp_ctx);
7517c478bd9Sstevel@tonic-gate int ibmf_i_extend_wqe_cache(ibmf_ci_t *cip, ibmf_qp_handle_t ibmf_qp_handle,
7527c478bd9Sstevel@tonic-gate     boolean_t block);
7537c478bd9Sstevel@tonic-gate 
7547c478bd9Sstevel@tonic-gate /* Receive callback functions */
7557c478bd9Sstevel@tonic-gate void ibmf_i_recv_cb_setup(ibmf_client_t *clientp);
7567c478bd9Sstevel@tonic-gate void ibmf_i_recv_cb_cleanup(ibmf_client_t *clientp);
7577c478bd9Sstevel@tonic-gate void ibmf_i_alt_recv_cb_setup(ibmf_alt_qp_t *qpp);
7587c478bd9Sstevel@tonic-gate void ibmf_i_alt_recv_cb_cleanup(ibmf_alt_qp_t *qpp);
7597c478bd9Sstevel@tonic-gate 
7607c478bd9Sstevel@tonic-gate /* UD Dest population thread */
7617c478bd9Sstevel@tonic-gate int ibmf_ud_dest_tq_disp(ibmf_ci_t *cip);
7627c478bd9Sstevel@tonic-gate 
7637c478bd9Sstevel@tonic-gate #ifdef __cplusplus
7647c478bd9Sstevel@tonic-gate }
7657c478bd9Sstevel@tonic-gate #endif
7667c478bd9Sstevel@tonic-gate 
7677c478bd9Sstevel@tonic-gate #endif /* _SYS_IB_MGT_IBMF_IBMF_IMPL_H */
768