xref: /onnv-gate/usr/src/uts/common/sys/ib/clients/iser/iser_ib.h (revision 11078:97a14b54f53b)
19162SPeter.Dunlap@Sun.COM /*
29162SPeter.Dunlap@Sun.COM  * CDDL HEADER START
39162SPeter.Dunlap@Sun.COM  *
49162SPeter.Dunlap@Sun.COM  * The contents of this file are subject to the terms of the
59162SPeter.Dunlap@Sun.COM  * Common Development and Distribution License (the "License").
69162SPeter.Dunlap@Sun.COM  * You may not use this file except in compliance with the License.
79162SPeter.Dunlap@Sun.COM  *
89162SPeter.Dunlap@Sun.COM  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
99162SPeter.Dunlap@Sun.COM  * or http://www.opensolaris.org/os/licensing.
109162SPeter.Dunlap@Sun.COM  * See the License for the specific language governing permissions
119162SPeter.Dunlap@Sun.COM  * and limitations under the License.
129162SPeter.Dunlap@Sun.COM  *
139162SPeter.Dunlap@Sun.COM  * When distributing Covered Code, include this CDDL HEADER in each
149162SPeter.Dunlap@Sun.COM  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
159162SPeter.Dunlap@Sun.COM  * If applicable, add the following below this CDDL HEADER, with the
169162SPeter.Dunlap@Sun.COM  * fields enclosed by brackets "[]" replaced with your own identifying
179162SPeter.Dunlap@Sun.COM  * information: Portions Copyright [yyyy] [name of copyright owner]
189162SPeter.Dunlap@Sun.COM  *
199162SPeter.Dunlap@Sun.COM  * CDDL HEADER END
209162SPeter.Dunlap@Sun.COM  */
219162SPeter.Dunlap@Sun.COM /*
229162SPeter.Dunlap@Sun.COM  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
239162SPeter.Dunlap@Sun.COM  * Use is subject to license terms.
249162SPeter.Dunlap@Sun.COM  */
259162SPeter.Dunlap@Sun.COM 
269162SPeter.Dunlap@Sun.COM #ifndef _ISER_IB_H
279162SPeter.Dunlap@Sun.COM #define	_ISER_IB_H
289162SPeter.Dunlap@Sun.COM 
299162SPeter.Dunlap@Sun.COM #ifdef	__cplusplus
309162SPeter.Dunlap@Sun.COM extern "C" {
319162SPeter.Dunlap@Sun.COM #endif
329162SPeter.Dunlap@Sun.COM 
339162SPeter.Dunlap@Sun.COM #include <sys/types.h>
349162SPeter.Dunlap@Sun.COM #include <sys/socket.h>
359162SPeter.Dunlap@Sun.COM #include <netinet/in.h>
369162SPeter.Dunlap@Sun.COM #include <sys/ib/ibtl/ibti.h>
379162SPeter.Dunlap@Sun.COM #include <sys/iscsi_protocol.h>
389162SPeter.Dunlap@Sun.COM 
399162SPeter.Dunlap@Sun.COM /*
409162SPeter.Dunlap@Sun.COM  * iser_ib.h
419162SPeter.Dunlap@Sun.COM  *	Definitions and macros related to iSER InfiniBand transport,
429162SPeter.Dunlap@Sun.COM  * 	and the use of the Solaris IBTI (InfiniBand Transport Interface).
439162SPeter.Dunlap@Sun.COM  */
449162SPeter.Dunlap@Sun.COM 
459162SPeter.Dunlap@Sun.COM struct iser_state_s;
469162SPeter.Dunlap@Sun.COM 
479162SPeter.Dunlap@Sun.COM extern struct iser_state_s	*iser_state;
489162SPeter.Dunlap@Sun.COM extern ddi_taskq_t	*iser_taskq;
499162SPeter.Dunlap@Sun.COM 
509162SPeter.Dunlap@Sun.COM /*
519162SPeter.Dunlap@Sun.COM  * iser_hca_s holds all the information about the Infinband HCAs in use.
529162SPeter.Dunlap@Sun.COM  */
539162SPeter.Dunlap@Sun.COM typedef struct iser_hca_s {
549162SPeter.Dunlap@Sun.COM 	list_node_t		hca_node;
559162SPeter.Dunlap@Sun.COM 	boolean_t		hca_failed;
569162SPeter.Dunlap@Sun.COM 	ibt_clnt_hdl_t		hca_clnt_hdl;
579162SPeter.Dunlap@Sun.COM 	ibt_hca_hdl_t		hca_hdl;
589162SPeter.Dunlap@Sun.COM 	ibt_hca_attr_t		hca_attr;
599162SPeter.Dunlap@Sun.COM 	ibt_pd_hdl_t		hca_pdhdl;
609162SPeter.Dunlap@Sun.COM 	ib_guid_t		hca_guid;
619162SPeter.Dunlap@Sun.COM 	uint_t			hca_num_ports;
629162SPeter.Dunlap@Sun.COM 	ibt_hca_portinfo_t	*hca_port_info;
639162SPeter.Dunlap@Sun.COM 	uint_t			hca_port_info_sz;
649162SPeter.Dunlap@Sun.COM 
659162SPeter.Dunlap@Sun.COM 	/* Per PD (per HCA) message and data buffer caches */
669162SPeter.Dunlap@Sun.COM 	struct iser_vmem_mr_pool_s *hca_msg_pool; /* Use iser_msg_cache */
679162SPeter.Dunlap@Sun.COM 	kmem_cache_t		*iser_msg_cache;
689162SPeter.Dunlap@Sun.COM 	struct iser_vmem_mr_pool_s *hca_buf_pool; /* Use iser_buf_cache */
699162SPeter.Dunlap@Sun.COM 	kmem_cache_t		*iser_buf_cache;
709162SPeter.Dunlap@Sun.COM } iser_hca_t;
719162SPeter.Dunlap@Sun.COM 
729162SPeter.Dunlap@Sun.COM /* RQ low water mark percentage */
739162SPeter.Dunlap@Sun.COM #define	ISER_IB_RQ_LWM_PCT	80
749162SPeter.Dunlap@Sun.COM 
759162SPeter.Dunlap@Sun.COM /* Maximum number of WRs to post on the RQ at a time */
769162SPeter.Dunlap@Sun.COM #define	ISER_IB_RQ_POST_MAX	64
779162SPeter.Dunlap@Sun.COM 
789162SPeter.Dunlap@Sun.COM /* Maximum number of SCQ WCs to poll at a time */
799162SPeter.Dunlap@Sun.COM #define	ISER_IB_SCQ_POLL_MAX	8
809162SPeter.Dunlap@Sun.COM 
819162SPeter.Dunlap@Sun.COM /*
829162SPeter.Dunlap@Sun.COM  * iser_qp_t encodes data related to a Queue Pair (QP) in use by
839162SPeter.Dunlap@Sun.COM  * iSER. Each QP consists of two Work Queues (WQs), one Send Queue
849162SPeter.Dunlap@Sun.COM  * (SQ) and on Receive Queue (RQ). Most of the data in the QP
859162SPeter.Dunlap@Sun.COM  * handle relates to monitoring the posted depth of the RQ.
869162SPeter.Dunlap@Sun.COM  *
879162SPeter.Dunlap@Sun.COM  * Note that we are explicitly using slightly less than a power-of-2
889162SPeter.Dunlap@Sun.COM  * number for our queue sizes.  The HCA driver will round up for us,
899162SPeter.Dunlap@Sun.COM  * and this affords us some headroom.
909162SPeter.Dunlap@Sun.COM  */
919162SPeter.Dunlap@Sun.COM #ifdef _LP64
929162SPeter.Dunlap@Sun.COM #define	ISER_IB_RECVQ_SIZE	400
939162SPeter.Dunlap@Sun.COM #else
949162SPeter.Dunlap@Sun.COM /* Memory is very limited on 32-bit kernels */
959162SPeter.Dunlap@Sun.COM #define	ISER_IB_RECVQ_SIZE	100
969162SPeter.Dunlap@Sun.COM #endif
979162SPeter.Dunlap@Sun.COM #define	ISER_IB_SENDQ_SIZE	2000
989162SPeter.Dunlap@Sun.COM #define	ISER_IB_SGLIST_SIZE	1
999162SPeter.Dunlap@Sun.COM 
1009162SPeter.Dunlap@Sun.COM #define	ISER_IB_DEFAULT_IRD	2
1019162SPeter.Dunlap@Sun.COM #define	ISER_IB_DEFAULT_ORD	4
1029162SPeter.Dunlap@Sun.COM 
1039162SPeter.Dunlap@Sun.COM typedef struct iser_qp_s {
1049162SPeter.Dunlap@Sun.COM 	kmutex_t	qp_lock;
1059162SPeter.Dunlap@Sun.COM 	uint_t		sq_size;
1069162SPeter.Dunlap@Sun.COM 	uint_t		rq_size;
1079162SPeter.Dunlap@Sun.COM 	uint32_t	rq_depth;
1089162SPeter.Dunlap@Sun.COM 	uint32_t	rq_level;
1099162SPeter.Dunlap@Sun.COM 	uint32_t	rq_min_post_level;
1109162SPeter.Dunlap@Sun.COM 	uint32_t	rq_lwm;
1119162SPeter.Dunlap@Sun.COM 	boolean_t	rq_taskqpending;
1129162SPeter.Dunlap@Sun.COM } iser_qp_t;
1139162SPeter.Dunlap@Sun.COM 
1149162SPeter.Dunlap@Sun.COM /*
1159162SPeter.Dunlap@Sun.COM  * iSER RC channel information
1169162SPeter.Dunlap@Sun.COM  */
1179162SPeter.Dunlap@Sun.COM typedef struct iser_chan_s {
118*11078SPeter.Cudhea@Sun.COM 	kmutex_t		ic_chan_lock;
1199162SPeter.Dunlap@Sun.COM 
1209162SPeter.Dunlap@Sun.COM 	/* IBT channel handle */
1219162SPeter.Dunlap@Sun.COM 	ibt_channel_hdl_t	ic_chanhdl;
1229162SPeter.Dunlap@Sun.COM 
1239162SPeter.Dunlap@Sun.COM 	/* local and remote IP addresses and port numbers */
1249162SPeter.Dunlap@Sun.COM 	ibt_ip_addr_t		ic_localip;
1259162SPeter.Dunlap@Sun.COM 	ibt_ip_addr_t		ic_remoteip;
1269162SPeter.Dunlap@Sun.COM 	in_port_t		ic_lport;
1279162SPeter.Dunlap@Sun.COM 	in_port_t		ic_rport;
1289162SPeter.Dunlap@Sun.COM 
1299162SPeter.Dunlap@Sun.COM 	/*
1309162SPeter.Dunlap@Sun.COM 	 * The local HCA GUID, the service ID, Destination GID, Source GID
1319162SPeter.Dunlap@Sun.COM 	 * the primary hca port on which the channel is connected is
1329162SPeter.Dunlap@Sun.COM 	 * stored in ic_ibt_path
1339162SPeter.Dunlap@Sun.COM 	 */
1349162SPeter.Dunlap@Sun.COM 	ibt_path_info_t		ic_ibt_path;
1359162SPeter.Dunlap@Sun.COM 
1369162SPeter.Dunlap@Sun.COM 	/*
1379162SPeter.Dunlap@Sun.COM 	 * Information related to the HCA handle and the queues.
1389162SPeter.Dunlap@Sun.COM 	 */
1399162SPeter.Dunlap@Sun.COM 	iser_hca_t		*ic_hca;
1409162SPeter.Dunlap@Sun.COM 	ibt_cq_hdl_t		ic_sendcq;
1419162SPeter.Dunlap@Sun.COM 	ibt_cq_hdl_t		ic_recvcq;
1429162SPeter.Dunlap@Sun.COM 	uint_t			ic_sendcq_sz;
1439162SPeter.Dunlap@Sun.COM 	uint_t			ic_recvcq_sz;
1449162SPeter.Dunlap@Sun.COM 	iser_qp_t		ic_qp;
1459162SPeter.Dunlap@Sun.COM 
1469162SPeter.Dunlap@Sun.COM 	/* Used to track the number of WRs posted on the SQ */
1479162SPeter.Dunlap@Sun.COM 	kmutex_t		ic_sq_post_lock;
1489162SPeter.Dunlap@Sun.COM 	uint_t			ic_sq_post_count;
1499162SPeter.Dunlap@Sun.COM 	uint_t			ic_sq_max_post_count;
1509162SPeter.Dunlap@Sun.COM 
1519162SPeter.Dunlap@Sun.COM 	/*
1529162SPeter.Dunlap@Sun.COM 	 * To help identify the channel end point and some connection
1539162SPeter.Dunlap@Sun.COM 	 * specifics, maintain a pointer to the connection on which
1549162SPeter.Dunlap@Sun.COM 	 * this channel originated
1559162SPeter.Dunlap@Sun.COM 	 */
1569162SPeter.Dunlap@Sun.COM 	struct iser_conn_s	*ic_conn;
1579162SPeter.Dunlap@Sun.COM } iser_chan_t;
1589162SPeter.Dunlap@Sun.COM 
1599162SPeter.Dunlap@Sun.COM int iser_ib_init(void);
1609162SPeter.Dunlap@Sun.COM 
1619162SPeter.Dunlap@Sun.COM int iser_ib_fini(void);
1629162SPeter.Dunlap@Sun.COM 
1639162SPeter.Dunlap@Sun.COM int iser_ib_register_service(idm_svc_t *idm_svc);
1649162SPeter.Dunlap@Sun.COM 
1659162SPeter.Dunlap@Sun.COM int iser_ib_bind_service(idm_svc_t *idm_svc);
1669162SPeter.Dunlap@Sun.COM 
1679162SPeter.Dunlap@Sun.COM void iser_ib_unbind_service(idm_svc_t *idm_svc);
1689162SPeter.Dunlap@Sun.COM 
1699162SPeter.Dunlap@Sun.COM void iser_ib_deregister_service(idm_svc_t *idm_svc);
1709162SPeter.Dunlap@Sun.COM 
1719162SPeter.Dunlap@Sun.COM void iser_ib_conv_sockaddr2ibtaddr(idm_sockaddr_t *saddr,
1729162SPeter.Dunlap@Sun.COM     ibt_ip_addr_t *ibt_addr);
1739162SPeter.Dunlap@Sun.COM 
1749162SPeter.Dunlap@Sun.COM void iser_ib_conv_ibtaddr2sockaddr(struct sockaddr_storage *ss,
1759162SPeter.Dunlap@Sun.COM     ibt_ip_addr_t *ibt_addr, in_port_t port);
1769162SPeter.Dunlap@Sun.COM 
1779162SPeter.Dunlap@Sun.COM int iser_ib_get_paths(
1789162SPeter.Dunlap@Sun.COM     ibt_ip_addr_t *local_ip, ibt_ip_addr_t *remote_ip, ibt_path_info_t *path,
1799162SPeter.Dunlap@Sun.COM     ibt_path_ip_src_t *path_src_ip);
1809162SPeter.Dunlap@Sun.COM 
18110322SPriya.Krishnan@Sun.COM iser_chan_t *iser_ib_alloc_channel_pathlookup(
18210322SPriya.Krishnan@Sun.COM     ibt_ip_addr_t *local_ip, ibt_ip_addr_t *remote_ip);
18310322SPriya.Krishnan@Sun.COM 
18410322SPriya.Krishnan@Sun.COM iser_chan_t *iser_ib_alloc_channel_nopathlookup(
18510322SPriya.Krishnan@Sun.COM     ib_guid_t hca_guid, uint8_t hca_port);
18610322SPriya.Krishnan@Sun.COM 
18710322SPriya.Krishnan@Sun.COM iser_chan_t *iser_ib_alloc_rc_channel(iser_hca_t *hca, uint8_t hca_port);
1889162SPeter.Dunlap@Sun.COM 
1899162SPeter.Dunlap@Sun.COM int iser_ib_open_rc_channel(iser_chan_t *chan);
1909162SPeter.Dunlap@Sun.COM 
1919162SPeter.Dunlap@Sun.COM void iser_ib_close_rc_channel(iser_chan_t *chan);
1929162SPeter.Dunlap@Sun.COM 
1939162SPeter.Dunlap@Sun.COM void iser_ib_free_rc_channel(iser_chan_t *chan);
1949162SPeter.Dunlap@Sun.COM 
1959247SPeter.Dunlap@Sun.COM int iser_ib_post_recv_async(ibt_channel_hdl_t chanhdl);
1969247SPeter.Dunlap@Sun.COM 
1979247SPeter.Dunlap@Sun.COM void iser_ib_post_recv(ibt_channel_hdl_t chanhdl);
1989162SPeter.Dunlap@Sun.COM 
1999162SPeter.Dunlap@Sun.COM void iser_ib_recvcq_handler(ibt_cq_hdl_t cq_hdl, void *arg);
2009162SPeter.Dunlap@Sun.COM 
2019162SPeter.Dunlap@Sun.COM void iser_ib_sendcq_handler(ibt_cq_hdl_t cq_hdl, void *arg);
2029162SPeter.Dunlap@Sun.COM 
2039162SPeter.Dunlap@Sun.COM void iser_ib_async_handler(void *clntp, ibt_hca_hdl_t hdl,
2049162SPeter.Dunlap@Sun.COM     ibt_async_code_t code, ibt_async_event_t *event);
2059162SPeter.Dunlap@Sun.COM 
2069162SPeter.Dunlap@Sun.COM #ifdef	__cplusplus
2079162SPeter.Dunlap@Sun.COM }
2089162SPeter.Dunlap@Sun.COM #endif
2099162SPeter.Dunlap@Sun.COM 
2109162SPeter.Dunlap@Sun.COM #endif /* _ISER_IB_H */
211