130e7468fSPeter Dunlap /*
230e7468fSPeter Dunlap  * CDDL HEADER START
330e7468fSPeter Dunlap  *
430e7468fSPeter Dunlap  * The contents of this file are subject to the terms of the
530e7468fSPeter Dunlap  * Common Development and Distribution License (the "License").
630e7468fSPeter Dunlap  * You may not use this file except in compliance with the License.
730e7468fSPeter Dunlap  *
830e7468fSPeter Dunlap  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
930e7468fSPeter Dunlap  * or http://www.opensolaris.org/os/licensing.
1030e7468fSPeter Dunlap  * See the License for the specific language governing permissions
1130e7468fSPeter Dunlap  * and limitations under the License.
1230e7468fSPeter Dunlap  *
1330e7468fSPeter Dunlap  * When distributing Covered Code, include this CDDL HEADER in each
1430e7468fSPeter Dunlap  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
1530e7468fSPeter Dunlap  * If applicable, add the following below this CDDL HEADER, with the
1630e7468fSPeter Dunlap  * fields enclosed by brackets "[]" replaced with your own identifying
1730e7468fSPeter Dunlap  * information: Portions Copyright [yyyy] [name of copyright owner]
1830e7468fSPeter Dunlap  *
1930e7468fSPeter Dunlap  * CDDL HEADER END
2030e7468fSPeter Dunlap  */
2130e7468fSPeter Dunlap /*
2230e7468fSPeter Dunlap  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
2330e7468fSPeter Dunlap  * Use is subject to license terms.
2430e7468fSPeter Dunlap  */
2530e7468fSPeter Dunlap 
2630e7468fSPeter Dunlap #ifndef _ISER_IB_H
2730e7468fSPeter Dunlap #define	_ISER_IB_H
2830e7468fSPeter Dunlap 
2930e7468fSPeter Dunlap #ifdef	__cplusplus
3030e7468fSPeter Dunlap extern "C" {
3130e7468fSPeter Dunlap #endif
3230e7468fSPeter Dunlap 
3330e7468fSPeter Dunlap #include <sys/types.h>
3430e7468fSPeter Dunlap #include <sys/socket.h>
3530e7468fSPeter Dunlap #include <netinet/in.h>
3630e7468fSPeter Dunlap #include <sys/ib/ibtl/ibti.h>
3730e7468fSPeter Dunlap #include <sys/iscsi_protocol.h>
3830e7468fSPeter Dunlap 
3930e7468fSPeter Dunlap /*
4030e7468fSPeter Dunlap  * iser_ib.h
4130e7468fSPeter Dunlap  *	Definitions and macros related to iSER InfiniBand transport,
4230e7468fSPeter Dunlap  * 	and the use of the Solaris IBTI (InfiniBand Transport Interface).
4330e7468fSPeter Dunlap  */
4430e7468fSPeter Dunlap 
4530e7468fSPeter Dunlap struct iser_state_s;
4630e7468fSPeter Dunlap 
4730e7468fSPeter Dunlap extern struct iser_state_s	*iser_state;
4830e7468fSPeter Dunlap extern ddi_taskq_t	*iser_taskq;
4930e7468fSPeter Dunlap 
5030e7468fSPeter Dunlap /*
5130e7468fSPeter Dunlap  * iser_hca_s holds all the information about the Infinband HCAs in use.
5230e7468fSPeter Dunlap  */
5330e7468fSPeter Dunlap typedef struct iser_hca_s {
5430e7468fSPeter Dunlap 	list_node_t		hca_node;
5530e7468fSPeter Dunlap 	boolean_t		hca_failed;
5630e7468fSPeter Dunlap 	ibt_clnt_hdl_t		hca_clnt_hdl;
5730e7468fSPeter Dunlap 	ibt_hca_hdl_t		hca_hdl;
5830e7468fSPeter Dunlap 	ibt_hca_attr_t		hca_attr;
5930e7468fSPeter Dunlap 	ibt_pd_hdl_t		hca_pdhdl;
6030e7468fSPeter Dunlap 	ib_guid_t		hca_guid;
6130e7468fSPeter Dunlap 	uint_t			hca_num_ports;
6230e7468fSPeter Dunlap 	ibt_hca_portinfo_t	*hca_port_info;
6330e7468fSPeter Dunlap 	uint_t			hca_port_info_sz;
6430e7468fSPeter Dunlap 
6530e7468fSPeter Dunlap 	/* Per PD (per HCA) message and data buffer caches */
6630e7468fSPeter Dunlap 	struct iser_vmem_mr_pool_s *hca_msg_pool; /* Use iser_msg_cache */
6730e7468fSPeter Dunlap 	kmem_cache_t		*iser_msg_cache;
6830e7468fSPeter Dunlap 	struct iser_vmem_mr_pool_s *hca_buf_pool; /* Use iser_buf_cache */
6930e7468fSPeter Dunlap 	kmem_cache_t		*iser_buf_cache;
7030e7468fSPeter Dunlap } iser_hca_t;
7130e7468fSPeter Dunlap 
7230e7468fSPeter Dunlap /* RQ low water mark percentage */
7330e7468fSPeter Dunlap #define	ISER_IB_RQ_LWM_PCT	80
7430e7468fSPeter Dunlap 
7530e7468fSPeter Dunlap /* Maximum number of WRs to post on the RQ at a time */
7630e7468fSPeter Dunlap #define	ISER_IB_RQ_POST_MAX	64
7730e7468fSPeter Dunlap 
7830e7468fSPeter Dunlap /* Maximum number of SCQ WCs to poll at a time */
7930e7468fSPeter Dunlap #define	ISER_IB_SCQ_POLL_MAX	8
8030e7468fSPeter Dunlap 
8130e7468fSPeter Dunlap /*
8230e7468fSPeter Dunlap  * iser_qp_t encodes data related to a Queue Pair (QP) in use by
8330e7468fSPeter Dunlap  * iSER. Each QP consists of two Work Queues (WQs), one Send Queue
8430e7468fSPeter Dunlap  * (SQ) and on Receive Queue (RQ). Most of the data in the QP
8530e7468fSPeter Dunlap  * handle relates to monitoring the posted depth of the RQ.
8630e7468fSPeter Dunlap  *
8730e7468fSPeter Dunlap  * Note that we are explicitly using slightly less than a power-of-2
8830e7468fSPeter Dunlap  * number for our queue sizes.  The HCA driver will round up for us,
8930e7468fSPeter Dunlap  * and this affords us some headroom.
9030e7468fSPeter Dunlap  */
9130e7468fSPeter Dunlap #ifdef _LP64
9230e7468fSPeter Dunlap #define	ISER_IB_RECVQ_SIZE	400
9330e7468fSPeter Dunlap #else
9430e7468fSPeter Dunlap /* Memory is very limited on 32-bit kernels */
9530e7468fSPeter Dunlap #define	ISER_IB_RECVQ_SIZE	100
9630e7468fSPeter Dunlap #endif
9730e7468fSPeter Dunlap #define	ISER_IB_SENDQ_SIZE	2000
9830e7468fSPeter Dunlap #define	ISER_IB_SGLIST_SIZE	1
9930e7468fSPeter Dunlap 
10030e7468fSPeter Dunlap #define	ISER_IB_DEFAULT_IRD	2
10130e7468fSPeter Dunlap #define	ISER_IB_DEFAULT_ORD	4
10230e7468fSPeter Dunlap 
10330e7468fSPeter Dunlap typedef struct iser_qp_s {
10430e7468fSPeter Dunlap 	kmutex_t	qp_lock;
10530e7468fSPeter Dunlap 	uint_t		sq_size;
10630e7468fSPeter Dunlap 	uint_t		rq_size;
10730e7468fSPeter Dunlap 	uint32_t	rq_depth;
10830e7468fSPeter Dunlap 	uint32_t	rq_level;
10930e7468fSPeter Dunlap 	uint32_t	rq_min_post_level;
11030e7468fSPeter Dunlap 	uint32_t	rq_lwm;
11130e7468fSPeter Dunlap 	boolean_t	rq_taskqpending;
11230e7468fSPeter Dunlap } iser_qp_t;
11330e7468fSPeter Dunlap 
11430e7468fSPeter Dunlap /*
11530e7468fSPeter Dunlap  * iSER RC channel information
11630e7468fSPeter Dunlap  */
11730e7468fSPeter Dunlap typedef struct iser_chan_s {
118*92adbba7SPeter Cudhea - Sun Microsystems - Burlington, MA United States 	kmutex_t		ic_chan_lock;
11930e7468fSPeter Dunlap 
12030e7468fSPeter Dunlap 	/* IBT channel handle */
12130e7468fSPeter Dunlap 	ibt_channel_hdl_t	ic_chanhdl;
12230e7468fSPeter Dunlap 
12330e7468fSPeter Dunlap 	/* local and remote IP addresses and port numbers */
12430e7468fSPeter Dunlap 	ibt_ip_addr_t		ic_localip;
12530e7468fSPeter Dunlap 	ibt_ip_addr_t		ic_remoteip;
12630e7468fSPeter Dunlap 	in_port_t		ic_lport;
12730e7468fSPeter Dunlap 	in_port_t		ic_rport;
12830e7468fSPeter Dunlap 
12930e7468fSPeter Dunlap 	/*
13030e7468fSPeter Dunlap 	 * The local HCA GUID, the service ID, Destination GID, Source GID
13130e7468fSPeter Dunlap 	 * the primary hca port on which the channel is connected is
13230e7468fSPeter Dunlap 	 * stored in ic_ibt_path
13330e7468fSPeter Dunlap 	 */
13430e7468fSPeter Dunlap 	ibt_path_info_t		ic_ibt_path;
13530e7468fSPeter Dunlap 
13630e7468fSPeter Dunlap 	/*
13730e7468fSPeter Dunlap 	 * Information related to the HCA handle and the queues.
13830e7468fSPeter Dunlap 	 */
13930e7468fSPeter Dunlap 	iser_hca_t		*ic_hca;
14030e7468fSPeter Dunlap 	ibt_cq_hdl_t		ic_sendcq;
14130e7468fSPeter Dunlap 	ibt_cq_hdl_t		ic_recvcq;
14230e7468fSPeter Dunlap 	uint_t			ic_sendcq_sz;
14330e7468fSPeter Dunlap 	uint_t			ic_recvcq_sz;
14430e7468fSPeter Dunlap 	iser_qp_t		ic_qp;
14530e7468fSPeter Dunlap 
14630e7468fSPeter Dunlap 	/* Used to track the number of WRs posted on the SQ */
14730e7468fSPeter Dunlap 	kmutex_t		ic_sq_post_lock;
14830e7468fSPeter Dunlap 	uint_t			ic_sq_post_count;
14930e7468fSPeter Dunlap 	uint_t			ic_sq_max_post_count;
15030e7468fSPeter Dunlap 
15130e7468fSPeter Dunlap 	/*
15230e7468fSPeter Dunlap 	 * To help identify the channel end point and some connection
15330e7468fSPeter Dunlap 	 * specifics, maintain a pointer to the connection on which
15430e7468fSPeter Dunlap 	 * this channel originated
15530e7468fSPeter Dunlap 	 */
15630e7468fSPeter Dunlap 	struct iser_conn_s	*ic_conn;
15730e7468fSPeter Dunlap } iser_chan_t;
15830e7468fSPeter Dunlap 
15930e7468fSPeter Dunlap int iser_ib_init(void);
16030e7468fSPeter Dunlap 
16130e7468fSPeter Dunlap int iser_ib_fini(void);
16230e7468fSPeter Dunlap 
16330e7468fSPeter Dunlap int iser_ib_register_service(idm_svc_t *idm_svc);
16430e7468fSPeter Dunlap 
16530e7468fSPeter Dunlap int iser_ib_bind_service(idm_svc_t *idm_svc);
16630e7468fSPeter Dunlap 
16730e7468fSPeter Dunlap void iser_ib_unbind_service(idm_svc_t *idm_svc);
16830e7468fSPeter Dunlap 
16930e7468fSPeter Dunlap void iser_ib_deregister_service(idm_svc_t *idm_svc);
17030e7468fSPeter Dunlap 
17130e7468fSPeter Dunlap void iser_ib_conv_sockaddr2ibtaddr(idm_sockaddr_t *saddr,
17230e7468fSPeter Dunlap     ibt_ip_addr_t *ibt_addr);
17330e7468fSPeter Dunlap 
17430e7468fSPeter Dunlap void iser_ib_conv_ibtaddr2sockaddr(struct sockaddr_storage *ss,
17530e7468fSPeter Dunlap     ibt_ip_addr_t *ibt_addr, in_port_t port);
17630e7468fSPeter Dunlap 
17730e7468fSPeter Dunlap int iser_ib_get_paths(
17830e7468fSPeter Dunlap     ibt_ip_addr_t *local_ip, ibt_ip_addr_t *remote_ip, ibt_path_info_t *path,
17930e7468fSPeter Dunlap     ibt_path_ip_src_t *path_src_ip);
18030e7468fSPeter Dunlap 
1811d73e59fSPriya Krishnan iser_chan_t *iser_ib_alloc_channel_pathlookup(
1821d73e59fSPriya Krishnan     ibt_ip_addr_t *local_ip, ibt_ip_addr_t *remote_ip);
1831d73e59fSPriya Krishnan 
1841d73e59fSPriya Krishnan iser_chan_t *iser_ib_alloc_channel_nopathlookup(
1851d73e59fSPriya Krishnan     ib_guid_t hca_guid, uint8_t hca_port);
1861d73e59fSPriya Krishnan 
1871d73e59fSPriya Krishnan iser_chan_t *iser_ib_alloc_rc_channel(iser_hca_t *hca, uint8_t hca_port);
18830e7468fSPeter Dunlap 
18930e7468fSPeter Dunlap int iser_ib_open_rc_channel(iser_chan_t *chan);
19030e7468fSPeter Dunlap 
19130e7468fSPeter Dunlap void iser_ib_close_rc_channel(iser_chan_t *chan);
19230e7468fSPeter Dunlap 
19330e7468fSPeter Dunlap void iser_ib_free_rc_channel(iser_chan_t *chan);
19430e7468fSPeter Dunlap 
195cf8c0ebaSPeter Dunlap int iser_ib_post_recv_async(ibt_channel_hdl_t chanhdl);
196cf8c0ebaSPeter Dunlap 
197cf8c0ebaSPeter Dunlap void iser_ib_post_recv(ibt_channel_hdl_t chanhdl);
19830e7468fSPeter Dunlap 
19930e7468fSPeter Dunlap void iser_ib_recvcq_handler(ibt_cq_hdl_t cq_hdl, void *arg);
20030e7468fSPeter Dunlap 
20130e7468fSPeter Dunlap void iser_ib_sendcq_handler(ibt_cq_hdl_t cq_hdl, void *arg);
20230e7468fSPeter Dunlap 
20330e7468fSPeter Dunlap void iser_ib_async_handler(void *clntp, ibt_hca_hdl_t hdl,
20430e7468fSPeter Dunlap     ibt_async_code_t code, ibt_async_event_t *event);
20530e7468fSPeter Dunlap 
20630e7468fSPeter Dunlap #ifdef	__cplusplus
20730e7468fSPeter Dunlap }
20830e7468fSPeter Dunlap #endif
20930e7468fSPeter Dunlap 
21030e7468fSPeter Dunlap #endif /* _ISER_IB_H */
211