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
57387SRobert.Gordon@Sun.COM  * Common Development and Distribution License (the "License").
67387SRobert.Gordon@Sun.COM  * 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  */
210Sstevel@tonic-gate /*
228695SRajkumar.Sivaprakasam@Sun.COM  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
267387SRobert.Gordon@Sun.COM /*
277387SRobert.Gordon@Sun.COM  * Copyright (c) 2007, The Ohio State University. All rights reserved.
287387SRobert.Gordon@Sun.COM  *
297387SRobert.Gordon@Sun.COM  * Portions of this source code is developed by the team members of
307387SRobert.Gordon@Sun.COM  * The Ohio State University's Network-Based Computing Laboratory (NBCL),
317387SRobert.Gordon@Sun.COM  * headed by Professor Dhabaleswar K. (DK) Panda.
327387SRobert.Gordon@Sun.COM  *
337387SRobert.Gordon@Sun.COM  * Acknowledgements to contributions from developors:
347387SRobert.Gordon@Sun.COM  *   Ranjit Noronha: noronha@cse.ohio-state.edu
357387SRobert.Gordon@Sun.COM  *   Lei Chai      : chail@cse.ohio-state.edu
367387SRobert.Gordon@Sun.COM  *   Weikuan Yu    : yuw@cse.ohio-state.edu
377387SRobert.Gordon@Sun.COM  *
387387SRobert.Gordon@Sun.COM  */
397387SRobert.Gordon@Sun.COM 
400Sstevel@tonic-gate #ifndef	_RPC_RPC_RDMA_H
410Sstevel@tonic-gate #define	_RPC_RPC_RDMA_H
420Sstevel@tonic-gate 
430Sstevel@tonic-gate #include <rpc/rpc.h>
440Sstevel@tonic-gate #include <rpc/rpc_sztypes.h>
450Sstevel@tonic-gate #include <sys/sunddi.h>
460Sstevel@tonic-gate #include <sys/sunldi.h>
470Sstevel@tonic-gate 
480Sstevel@tonic-gate #ifdef __cplusplus
490Sstevel@tonic-gate extern "C" {
500Sstevel@tonic-gate #endif
510Sstevel@tonic-gate 
527387SRobert.Gordon@Sun.COM #define	RPCRDMA_VERS	1	/* Version of the RPC over RDMA protocol */
530Sstevel@tonic-gate #define	RDMATF_VERS	1	/* Version of the API used by RPC for RDMA */
540Sstevel@tonic-gate #define	RDMATF_VERS_1	1	/* Current version of RDMATF */
550Sstevel@tonic-gate 
560Sstevel@tonic-gate /*
570Sstevel@tonic-gate  * The size of an RPC call or reply message
580Sstevel@tonic-gate  */
597387SRobert.Gordon@Sun.COM #define	RPC_MSG_SZ	1024
607387SRobert.Gordon@Sun.COM 
617387SRobert.Gordon@Sun.COM /*
627387SRobert.Gordon@Sun.COM  * RDMA chunk size
637387SRobert.Gordon@Sun.COM  */
647387SRobert.Gordon@Sun.COM #define	RDMA_MINCHUNK	1024
650Sstevel@tonic-gate 
660Sstevel@tonic-gate /*
670Sstevel@tonic-gate  * Storage for a chunk list
680Sstevel@tonic-gate  */
690Sstevel@tonic-gate #define	RPC_CL_SZ  1024
700Sstevel@tonic-gate 
710Sstevel@tonic-gate /*
720Sstevel@tonic-gate  * Chunk size
730Sstevel@tonic-gate  */
740Sstevel@tonic-gate #define	MINCHUNK  1024
750Sstevel@tonic-gate 
760Sstevel@tonic-gate /*
770Sstevel@tonic-gate  * Size of receive buffer
780Sstevel@tonic-gate  */
790Sstevel@tonic-gate #define	RPC_BUF_SIZE	2048
800Sstevel@tonic-gate 
810Sstevel@tonic-gate #define	NOWAIT	0	/* don't wait for operation of complete */
820Sstevel@tonic-gate #define	WAIT	1	/* wait and ensure that operation is complete */
830Sstevel@tonic-gate 
840Sstevel@tonic-gate /*
850Sstevel@tonic-gate  * RDMA xdr buffer control and other control flags. Add new flags here,
860Sstevel@tonic-gate  * set them in private structure for xdr over RDMA in xdr_rdma.c
870Sstevel@tonic-gate  */
887387SRobert.Gordon@Sun.COM #define	XDR_RDMA_CHUNK			0x1
897387SRobert.Gordon@Sun.COM #define	XDR_RDMA_WLIST_REG		0x2
907387SRobert.Gordon@Sun.COM #define	XDR_RDMA_RLIST_REG		0x4
917387SRobert.Gordon@Sun.COM 
927387SRobert.Gordon@Sun.COM #define	LONG_REPLY_LEN	65536
937387SRobert.Gordon@Sun.COM #define	WCL_BUF_LEN	32768
947387SRobert.Gordon@Sun.COM #define	RCL_BUF_LEN	32768
957387SRobert.Gordon@Sun.COM 
967387SRobert.Gordon@Sun.COM 
977387SRobert.Gordon@Sun.COM #define	RDMA_BUFS_RQST	34	/* Num bufs requested by client */
987387SRobert.Gordon@Sun.COM #define	RDMA_BUFS_GRANT	32	/* Num bufs granted by server */
997387SRobert.Gordon@Sun.COM 
1007387SRobert.Gordon@Sun.COM struct xdr_ops *xdrrdma_xops(void);
1017387SRobert.Gordon@Sun.COM 
1027387SRobert.Gordon@Sun.COM /*
1037387SRobert.Gordon@Sun.COM  * Credit Control Structures.
1047387SRobert.Gordon@Sun.COM  */
1057387SRobert.Gordon@Sun.COM typedef enum rdma_cc_type {
1067387SRobert.Gordon@Sun.COM 	RDMA_CC_CLNT,	/* CONN is for a client */
1077387SRobert.Gordon@Sun.COM 	RDMA_CC_SRV	/* CONN is for a server */
1087387SRobert.Gordon@Sun.COM } rdma_cc_type_t;
1097387SRobert.Gordon@Sun.COM 
1107387SRobert.Gordon@Sun.COM /*
1117387SRobert.Gordon@Sun.COM  * Client side credit control data structure.
1127387SRobert.Gordon@Sun.COM  */
1137387SRobert.Gordon@Sun.COM typedef struct rdma_clnt_cred_ctrl {
1147387SRobert.Gordon@Sun.COM 	uint32_t	clnt_cc_granted_ops;
1157387SRobert.Gordon@Sun.COM 	uint32_t	clnt_cc_in_flight_ops;
1167387SRobert.Gordon@Sun.COM 	kcondvar_t	clnt_cc_cv;
1177387SRobert.Gordon@Sun.COM } rdma_clnt_cred_ctrl_t;
1187387SRobert.Gordon@Sun.COM 
1197387SRobert.Gordon@Sun.COM /*
1207387SRobert.Gordon@Sun.COM  * Server side credit control data structure.
1217387SRobert.Gordon@Sun.COM  */
1227387SRobert.Gordon@Sun.COM typedef struct rdma_srv_cred_ctrl {
1237387SRobert.Gordon@Sun.COM 	uint32_t	srv_cc_buffers_granted;
1247387SRobert.Gordon@Sun.COM 	uint32_t	srv_cc_cur_buffers_used;
1257387SRobert.Gordon@Sun.COM 	uint32_t	srv_cc_posted;
1267387SRobert.Gordon@Sun.COM 	uint32_t	srv_cc_max_buf_size;	/* to be determined by CCP */
1277387SRobert.Gordon@Sun.COM 	uint32_t	srv_cc_cur_buf_size;	/* to be determined by CCP */
1287387SRobert.Gordon@Sun.COM } rdma_srv_cred_ctrl_t;
1297387SRobert.Gordon@Sun.COM 
1307387SRobert.Gordon@Sun.COM typedef enum {
1317387SRobert.Gordon@Sun.COM     RPCCALL_WLIST,
1327387SRobert.Gordon@Sun.COM     RPCCALL_WCHUNK,
1337387SRobert.Gordon@Sun.COM     RPCCALL_NOWRITE
1347387SRobert.Gordon@Sun.COM }rpccall_write_t;
1357387SRobert.Gordon@Sun.COM 
1367387SRobert.Gordon@Sun.COM typedef enum {
137*9348SSiddheshwar.Mahesh@Sun.COM 	CLIST_REG_SOURCE = 1,
1387387SRobert.Gordon@Sun.COM 	CLIST_REG_DST
1397387SRobert.Gordon@Sun.COM } clist_dstsrc;
1400Sstevel@tonic-gate 
1410Sstevel@tonic-gate /*
1420Sstevel@tonic-gate  * Return codes from RDMA operations
1430Sstevel@tonic-gate  */
1440Sstevel@tonic-gate typedef enum {
1450Sstevel@tonic-gate 
1460Sstevel@tonic-gate 	RDMA_SUCCESS = 0,	/* successful operation */
1470Sstevel@tonic-gate 
1480Sstevel@tonic-gate 	RDMA_INVAL = 1,		/* invalid parameter */
1490Sstevel@tonic-gate 	RDMA_TIMEDOUT = 2,	/* operation timed out */
1500Sstevel@tonic-gate 	RDMA_INTR = 3,		/* operation interrupted */
1510Sstevel@tonic-gate 	RDMA_NORESOURCE = 4,	/* insufficient resource */
1520Sstevel@tonic-gate 	/*
1530Sstevel@tonic-gate 	 * connection errors
1540Sstevel@tonic-gate 	 */
1550Sstevel@tonic-gate 	RDMA_REJECT = 5,	/* connection req rejected */
1560Sstevel@tonic-gate 	RDMA_NOLISTENER = 6,	/* no listener on server */
1570Sstevel@tonic-gate 	RDMA_UNREACHABLE = 7,	/* host unreachable */
1580Sstevel@tonic-gate 	RDMA_CONNLOST = 8,	/* connection lost */
1590Sstevel@tonic-gate 
1600Sstevel@tonic-gate 	RDMA_XPRTFAILED = 9,	/* RDMA transport failed */
1610Sstevel@tonic-gate 	RDMA_PROTECTERR = 10,	/* memory protection error */
1620Sstevel@tonic-gate 	RDMA_OVERRUN = 11,	/* transport overrun */
1630Sstevel@tonic-gate 	RDMA_RECVQEMPTY = 12,	/* incoming pkt dropped, recv q empty */
1640Sstevel@tonic-gate 	RDMA_PROTFAILED = 13,	/* RDMA protocol failed */
1650Sstevel@tonic-gate 	RDMA_NOTSUPP = 14,	/* requested feature not supported */
1660Sstevel@tonic-gate 	RDMA_REMOTERR = 15,	/* error at remote end */
1670Sstevel@tonic-gate 	/*
1680Sstevel@tonic-gate 	 * RDMATF errors
1690Sstevel@tonic-gate 	 */
1700Sstevel@tonic-gate 	RDMA_BADVERS = 16,	/* mismatch RDMATF versions */
1710Sstevel@tonic-gate 	RDMA_REG_EXIST = 17,	/* RDMATF registration already exists */
1728695SRajkumar.Sivaprakasam@Sun.COM 	RDMA_HCA_ATTACH = 18,
1738695SRajkumar.Sivaprakasam@Sun.COM 	RDMA_HCA_DETACH = 19,
1740Sstevel@tonic-gate 
1750Sstevel@tonic-gate 	/*
1760Sstevel@tonic-gate 	 * fallback error
1770Sstevel@tonic-gate 	 */
1788695SRajkumar.Sivaprakasam@Sun.COM 	RDMA_FAILED = 20	/* generic error */
1790Sstevel@tonic-gate } rdma_stat;
1800Sstevel@tonic-gate 
1810Sstevel@tonic-gate /*
1820Sstevel@tonic-gate  * Memory region context. This is an RDMA provider generated
1830Sstevel@tonic-gate  * handle for a registered arbitrary size contiguous virtual
1840Sstevel@tonic-gate  * memory. The RDMA Interface Adapter needs this for local or
1850Sstevel@tonic-gate  * remote memory access.
1860Sstevel@tonic-gate  *
1870Sstevel@tonic-gate  * The mrc_rmr field holds the remote memory region context
1880Sstevel@tonic-gate  * which is sent over-the-wire to provide the remote host
1890Sstevel@tonic-gate  * with RDMA access to the memory region.
1900Sstevel@tonic-gate  */
1910Sstevel@tonic-gate struct mrc {
1920Sstevel@tonic-gate 	uint32_t	mrc_rmr;	/* Remote MR context, sent OTW */
1930Sstevel@tonic-gate 	union {
1940Sstevel@tonic-gate 		struct mr {
1950Sstevel@tonic-gate 			uint32_t	lmr; 	/* Local MR context */
1960Sstevel@tonic-gate 			uint64_t	linfo;	/* Local memory info */
1970Sstevel@tonic-gate 		} mr;
1980Sstevel@tonic-gate 	} lhdl;
1990Sstevel@tonic-gate };
2000Sstevel@tonic-gate 
2010Sstevel@tonic-gate #define	mrc_lmr		lhdl.mr.lmr
2020Sstevel@tonic-gate #define	mrc_linfo	lhdl.mr.linfo
2030Sstevel@tonic-gate 
2040Sstevel@tonic-gate /*
2057387SRobert.Gordon@Sun.COM  * Memory management for the RDMA buffers
2067387SRobert.Gordon@Sun.COM  */
2077387SRobert.Gordon@Sun.COM /*
2087387SRobert.Gordon@Sun.COM  * RDMA buffer types
2097387SRobert.Gordon@Sun.COM  */
2107387SRobert.Gordon@Sun.COM typedef enum {
2117387SRobert.Gordon@Sun.COM 	SEND_BUFFER,	/* buf for send msg */
2127387SRobert.Gordon@Sun.COM 	SEND_DESCRIPTOR, /* buf used for send msg descriptor in plugins only */
2137387SRobert.Gordon@Sun.COM 	RECV_BUFFER,	/* buf for recv msg */
2147387SRobert.Gordon@Sun.COM 	RECV_DESCRIPTOR, /* buf used for recv msg descriptor in plugins only */
2157387SRobert.Gordon@Sun.COM 	RDMA_LONG_BUFFER /* chunk buf used in RDMATF only and not in plugins */
2167387SRobert.Gordon@Sun.COM } rdma_btype;
2177387SRobert.Gordon@Sun.COM 
2187387SRobert.Gordon@Sun.COM /*
2197387SRobert.Gordon@Sun.COM  * RDMA buffer information
2207387SRobert.Gordon@Sun.COM  */
2217387SRobert.Gordon@Sun.COM typedef struct rdma_buf {
2227387SRobert.Gordon@Sun.COM 	rdma_btype	type;	/* buffer type */
2237387SRobert.Gordon@Sun.COM 	uint_t		len;	/* length of buffer */
2247387SRobert.Gordon@Sun.COM 	caddr_t		addr;	/* buffer address */
2257387SRobert.Gordon@Sun.COM 	struct mrc	handle;	/* buffer registration handle */
2267387SRobert.Gordon@Sun.COM 	caddr_t		rb_private;
2277387SRobert.Gordon@Sun.COM } rdma_buf_t;
2287387SRobert.Gordon@Sun.COM 
2297387SRobert.Gordon@Sun.COM 
2307387SRobert.Gordon@Sun.COM /*
2310Sstevel@tonic-gate  * The XDR offset value is used by the XDR
2320Sstevel@tonic-gate  * routine to identify the position in the
2330Sstevel@tonic-gate  * RPC message where the opaque object would
2340Sstevel@tonic-gate  * normally occur. Neither the data content
2350Sstevel@tonic-gate  * of the chunk, nor its size field are included
2360Sstevel@tonic-gate  * in the RPC message.  The XDR offset is calculated
2370Sstevel@tonic-gate  * as if the chunks were present.
2380Sstevel@tonic-gate  *
2390Sstevel@tonic-gate  * The remaining fields identify the chunk of data
2400Sstevel@tonic-gate  * on the sender.  The c_memhandle identifies a
2410Sstevel@tonic-gate  * registered RDMA memory region and the c_addr
2420Sstevel@tonic-gate  * and c_len fields identify the chunk within it.
2430Sstevel@tonic-gate  */
2440Sstevel@tonic-gate struct clist {
2450Sstevel@tonic-gate 	uint32		c_xdroff;	/* XDR offset */
2460Sstevel@tonic-gate 	uint32		c_len;		/* Length */
247*9348SSiddheshwar.Mahesh@Sun.COM 	clist_dstsrc	c_regtype;	/* type of registration */
2480Sstevel@tonic-gate 	struct mrc	c_smemhandle;	/* src memory handle */
2490Sstevel@tonic-gate 	uint64 		c_ssynchandle;	/* src sync handle */
2507387SRobert.Gordon@Sun.COM 	union {
2517387SRobert.Gordon@Sun.COM 		uint64		c_saddr;	/* src address */
2527387SRobert.Gordon@Sun.COM 		caddr_t 	c_saddr3;
2537387SRobert.Gordon@Sun.COM 	} w;
2540Sstevel@tonic-gate 	struct mrc	c_dmemhandle;	/* dst memory handle */
2550Sstevel@tonic-gate 	uint64		c_dsynchandle;	/* dst sync handle */
2567387SRobert.Gordon@Sun.COM 	union {
2577387SRobert.Gordon@Sun.COM 		uint64	c_daddr;	/* dst address */
2587387SRobert.Gordon@Sun.COM 		caddr_t	c_daddr3;
2597387SRobert.Gordon@Sun.COM 	} u;
2607387SRobert.Gordon@Sun.COM 	struct as	*c_adspc;	/* address space for saddr/daddr */
2617387SRobert.Gordon@Sun.COM 	rdma_buf_t	rb_longbuf;	/* used for long requests/replies */
2620Sstevel@tonic-gate 	struct clist	*c_next;	/* Next chunk */
2630Sstevel@tonic-gate };
2640Sstevel@tonic-gate 
2650Sstevel@tonic-gate typedef struct clist clist;
2660Sstevel@tonic-gate 
2677387SRobert.Gordon@Sun.COM /*
2687387SRobert.Gordon@Sun.COM  * max 4M wlist xfer size
2697387SRobert.Gordon@Sun.COM  * This is defined because the rfs3_tsize service requires
2707387SRobert.Gordon@Sun.COM  * svc_req struct (which we don't have that in krecv).
2717387SRobert.Gordon@Sun.COM  */
2727387SRobert.Gordon@Sun.COM #define	MAX_SVC_XFER_SIZE (4*1024*1024)
2737387SRobert.Gordon@Sun.COM 
2740Sstevel@tonic-gate enum rdma_proc {
2750Sstevel@tonic-gate 	RDMA_MSG	= 0,	/* chunk list and RPC msg follow */
2760Sstevel@tonic-gate 	RDMA_NOMSG	= 1,	/* only chunk list follows */
2770Sstevel@tonic-gate 	RDMA_MSGP	= 2,	/* chunk list and RPC msg with padding follow */
2780Sstevel@tonic-gate 	RDMA_DONE	= 3	/* signal completion of chunk transfer */
2790Sstevel@tonic-gate };
2800Sstevel@tonic-gate 
2810Sstevel@tonic-gate /*
2820Sstevel@tonic-gate  * Listener information for a service
2830Sstevel@tonic-gate  */
2840Sstevel@tonic-gate struct rdma_svc_data {
2850Sstevel@tonic-gate 	queue_t		q;	/* queue_t to place incoming pkts */
2860Sstevel@tonic-gate 	int		active;	/* If active, after registeration startup */
2870Sstevel@tonic-gate 	rdma_stat	err_code;	/* Error code from plugin layer */
2880Sstevel@tonic-gate 	int32_t		svcid;		/* RDMA based service identifier */
2890Sstevel@tonic-gate };
2900Sstevel@tonic-gate 
2910Sstevel@tonic-gate /*
2920Sstevel@tonic-gate  * Per RDMA plugin module information.
2930Sstevel@tonic-gate  * Will be populated by each plugin
2940Sstevel@tonic-gate  * module during its initialization.
2950Sstevel@tonic-gate  */
2960Sstevel@tonic-gate typedef struct rdma_mod {
2970Sstevel@tonic-gate 	char 		*rdma_api;		/* "kvipl", "ibtf", etc */
2980Sstevel@tonic-gate 	uint_t 		rdma_version;		/* RDMATF API version */
2990Sstevel@tonic-gate 	int		rdma_count;		/* # of devices */
3000Sstevel@tonic-gate 	struct rdmaops 	*rdma_ops;		/* rdma op vector for api */
3010Sstevel@tonic-gate } rdma_mod_t;
3020Sstevel@tonic-gate 
3030Sstevel@tonic-gate /*
3040Sstevel@tonic-gate  * Registry of RDMA plugins
3050Sstevel@tonic-gate  */
3060Sstevel@tonic-gate typedef struct rdma_registry {
3070Sstevel@tonic-gate 	rdma_mod_t	*r_mod;		/* plugin mod info */
3088695SRajkumar.Sivaprakasam@Sun.COM 	uint32_t	r_mod_state;
3090Sstevel@tonic-gate 	struct rdma_registry *r_next;	/* next registered RDMA plugin */
3100Sstevel@tonic-gate } rdma_registry_t;
3110Sstevel@tonic-gate 
3120Sstevel@tonic-gate /*
3138695SRajkumar.Sivaprakasam@Sun.COM  * RDMA MODULE state flags (r_mod_state).
3148695SRajkumar.Sivaprakasam@Sun.COM  */
3158695SRajkumar.Sivaprakasam@Sun.COM #define	RDMA_MOD_ACTIVE		1
3168695SRajkumar.Sivaprakasam@Sun.COM #define	RDMA_MOD_INACTIVE	0
3178695SRajkumar.Sivaprakasam@Sun.COM 
3188695SRajkumar.Sivaprakasam@Sun.COM /*
3190Sstevel@tonic-gate  * RDMA transport information
3200Sstevel@tonic-gate  */
3210Sstevel@tonic-gate typedef struct rdma_info {
3220Sstevel@tonic-gate 	uint_t	addrlen;	/* address length */
3230Sstevel@tonic-gate 	uint_t  mts;		/* max transfer size */
3240Sstevel@tonic-gate 	uint_t  mtu;		/* native mtu size of unlerlying network */
3250Sstevel@tonic-gate } rdma_info_t;
3260Sstevel@tonic-gate 
3277387SRobert.Gordon@Sun.COM typedef enum {
3287387SRobert.Gordon@Sun.COM 	C_IDLE		= 0x00000001,
3297387SRobert.Gordon@Sun.COM 	C_CONN_PEND	= 0x00000002,
3307387SRobert.Gordon@Sun.COM 	C_CONNECTED	= 0x00000004,
3317387SRobert.Gordon@Sun.COM 	C_ERROR_CONN	= 0x00000008,
3327387SRobert.Gordon@Sun.COM 	C_DISCONN_PEND	= 0x00000010,
3337387SRobert.Gordon@Sun.COM 	C_REMOTE_DOWN	= 0x00000020
3347387SRobert.Gordon@Sun.COM } conn_c_state;
3357387SRobert.Gordon@Sun.COM 
3360Sstevel@tonic-gate /*
3370Sstevel@tonic-gate  * RDMA Connection information
3380Sstevel@tonic-gate  */
3390Sstevel@tonic-gate typedef struct conn {
3400Sstevel@tonic-gate 	rdma_mod_t	*c_rdmamod;	/* RDMA transport info for conn */
3410Sstevel@tonic-gate 	struct netbuf	c_raddr;	/* remote address */
3420Sstevel@tonic-gate 	struct netbuf	c_laddr;	/* local address */
3430Sstevel@tonic-gate 	int		c_ref;		/* no. of clients of connection */
3440Sstevel@tonic-gate 	struct conn	*c_next;	/* next in list of connections */
3450Sstevel@tonic-gate 	struct conn	*c_prev;	/* prev in list of connections */
3460Sstevel@tonic-gate 	caddr_t		c_private;	/* transport specific stuff */
3477387SRobert.Gordon@Sun.COM 	conn_c_state	c_state;	/* state of connection */
3487387SRobert.Gordon@Sun.COM 	rdma_cc_type_t	c_cc_type;	/* client or server, for credit cntrl */
3497387SRobert.Gordon@Sun.COM 	union {
3507387SRobert.Gordon@Sun.COM 		rdma_clnt_cred_ctrl_t	c_clnt_cc;
3517387SRobert.Gordon@Sun.COM 		rdma_srv_cred_ctrl_t	c_srv_cc;
3527387SRobert.Gordon@Sun.COM 	} rdma_conn_cred_ctrl_u;
3530Sstevel@tonic-gate 	kmutex_t	c_lock;		/* protect c_state and c_ref fields */
3540Sstevel@tonic-gate 	kcondvar_t	c_cv;		/* to signal when pending is done */
3550Sstevel@tonic-gate } CONN;
3560Sstevel@tonic-gate 
3570Sstevel@tonic-gate 
3580Sstevel@tonic-gate /*
3590Sstevel@tonic-gate  * Data transferred from plugin interrupt to svc_queuereq()
3600Sstevel@tonic-gate  */
3617387SRobert.Gordon@Sun.COM typedef struct rdma_recv_data {
3620Sstevel@tonic-gate 	CONN		*conn;
3630Sstevel@tonic-gate 	int		status;
3640Sstevel@tonic-gate 	rdma_buf_t	rpcmsg;
3657387SRobert.Gordon@Sun.COM } rdma_recv_data_t;
3667387SRobert.Gordon@Sun.COM 
3677387SRobert.Gordon@Sun.COM /* structure used to pass information for READ over rdma write */
3687387SRobert.Gordon@Sun.COM typedef enum {
3697387SRobert.Gordon@Sun.COM 	RCI_WRITE_UIO_CHUNK = 1,
3707387SRobert.Gordon@Sun.COM 	RCI_WRITE_ADDR_CHUNK = 2,
3717387SRobert.Gordon@Sun.COM 	RCI_REPLY_CHUNK = 3
3727387SRobert.Gordon@Sun.COM } rci_type_t;
3737387SRobert.Gordon@Sun.COM 
3747387SRobert.Gordon@Sun.COM typedef struct {
3757387SRobert.Gordon@Sun.COM 	rci_type_t rci_type;
3767387SRobert.Gordon@Sun.COM 	union {
3777387SRobert.Gordon@Sun.COM 		struct uio *rci_uiop;
3787387SRobert.Gordon@Sun.COM 		caddr_t    rci_addr;
3797387SRobert.Gordon@Sun.COM 	} rci_a;
3807387SRobert.Gordon@Sun.COM 	uint32	rci_len;
3817387SRobert.Gordon@Sun.COM 	struct clist	**rci_clpp; /* point to write chunk list in readargs */
3827387SRobert.Gordon@Sun.COM } rdma_chunkinfo_t;
3837387SRobert.Gordon@Sun.COM 
3847387SRobert.Gordon@Sun.COM typedef struct {
3857387SRobert.Gordon@Sun.COM 	uint_t rcil_len;
3867387SRobert.Gordon@Sun.COM 	uint_t rcil_len_alt;
3877387SRobert.Gordon@Sun.COM } rdma_chunkinfo_lengths_t;
3887387SRobert.Gordon@Sun.COM 
3897387SRobert.Gordon@Sun.COM typedef struct {
3907387SRobert.Gordon@Sun.COM 	struct	clist	*rwci_wlist;
3917387SRobert.Gordon@Sun.COM 	CONN		*rwci_conn;
3927387SRobert.Gordon@Sun.COM } rdma_wlist_conn_info_t;
3930Sstevel@tonic-gate 
3940Sstevel@tonic-gate /*
3950Sstevel@tonic-gate  * Operations vector for RDMA transports.
3960Sstevel@tonic-gate  */
3970Sstevel@tonic-gate typedef struct rdmaops {
3980Sstevel@tonic-gate 	/* Network */
3990Sstevel@tonic-gate 	rdma_stat	(*rdma_reachable)(int addr_type, struct netbuf *,
4000Sstevel@tonic-gate 						void **handle);
4010Sstevel@tonic-gate 	/* Connection */
4020Sstevel@tonic-gate 	rdma_stat	(*rdma_get_conn)(struct netbuf *, int addr_type,
4030Sstevel@tonic-gate 						void *, CONN **);
4040Sstevel@tonic-gate 	rdma_stat	(*rdma_rel_conn)(CONN *);
4050Sstevel@tonic-gate 	/* Server side listner start and stop routines */
4060Sstevel@tonic-gate 	void		(*rdma_svc_listen)(struct rdma_svc_data *);
4070Sstevel@tonic-gate 	void		(*rdma_svc_stop)(struct rdma_svc_data *);
4080Sstevel@tonic-gate 	/* Memory */
4097387SRobert.Gordon@Sun.COM 	rdma_stat	(*rdma_regmem)(CONN *, caddr_t, caddr_t,
4107387SRobert.Gordon@Sun.COM 			    uint_t, struct mrc *);
4110Sstevel@tonic-gate 	rdma_stat	(*rdma_deregmem)(CONN *, caddr_t, struct mrc);
4127387SRobert.Gordon@Sun.COM 	rdma_stat	(*rdma_regmemsync)(CONN *, caddr_t, caddr_t, uint_t,
4137387SRobert.Gordon@Sun.COM 				struct mrc *, void **, void *);
4140Sstevel@tonic-gate 	rdma_stat	(*rdma_deregmemsync)(CONN *, caddr_t, struct mrc,
4157387SRobert.Gordon@Sun.COM 			    void *, void *);
4160Sstevel@tonic-gate 	rdma_stat	(*rdma_syncmem)(CONN *, void *, caddr_t, int, int);
4170Sstevel@tonic-gate 	/* Buffer */
4180Sstevel@tonic-gate 	rdma_stat	(*rdma_buf_alloc)(CONN *, rdma_buf_t *);
4190Sstevel@tonic-gate 	void		(*rdma_buf_free)(CONN *, rdma_buf_t *);
4200Sstevel@tonic-gate 	/* Transfer */
4210Sstevel@tonic-gate 	rdma_stat	(*rdma_send)(CONN *, clist *, uint32_t);
4220Sstevel@tonic-gate 	rdma_stat	(*rdma_send_resp)(CONN *, clist *, uint32_t);
4230Sstevel@tonic-gate 	rdma_stat	(*rdma_clnt_recvbuf)(CONN *, clist *, uint32_t);
4247387SRobert.Gordon@Sun.COM 	rdma_stat	(*rdma_clnt_recvbuf_remove)(CONN *, uint32_t);
4250Sstevel@tonic-gate 	rdma_stat	(*rdma_svc_recvbuf)(CONN *, clist *);
4260Sstevel@tonic-gate 	rdma_stat	(*rdma_recv)(CONN *, clist **, uint32_t);
4270Sstevel@tonic-gate 	/* RDMA */
4280Sstevel@tonic-gate 	rdma_stat	(*rdma_read)(CONN *, clist *, int);
4290Sstevel@tonic-gate 	rdma_stat	(*rdma_write)(CONN *, clist *, int);
4300Sstevel@tonic-gate 	/* INFO */
4310Sstevel@tonic-gate 	rdma_stat	(*rdma_getinfo)(rdma_info_t *info);
4320Sstevel@tonic-gate } rdmaops_t;
4330Sstevel@tonic-gate 
4348695SRajkumar.Sivaprakasam@Sun.COM typedef struct rdma_svc_wait {
4358695SRajkumar.Sivaprakasam@Sun.COM 	kmutex_t svc_lock;
4368695SRajkumar.Sivaprakasam@Sun.COM 	kcondvar_t svc_cv;
4378695SRajkumar.Sivaprakasam@Sun.COM 	rdma_stat svc_stat;
4388695SRajkumar.Sivaprakasam@Sun.COM } rdma_svc_wait_t;
4398695SRajkumar.Sivaprakasam@Sun.COM 
4408695SRajkumar.Sivaprakasam@Sun.COM extern rdma_svc_wait_t rdma_wait;
4418695SRajkumar.Sivaprakasam@Sun.COM 
4420Sstevel@tonic-gate /*
4430Sstevel@tonic-gate  * RDMA operations.
4440Sstevel@tonic-gate  */
4450Sstevel@tonic-gate #define	RDMA_REACHABLE(rdma_ops, addr_type, addr, handle)	\
4460Sstevel@tonic-gate 	(*(rdma_ops)->rdma_reachable)(addr_type, addr, handle)
4470Sstevel@tonic-gate 
4480Sstevel@tonic-gate #define	RDMA_GET_CONN(rdma_ops, addr, addr_type, handle, conn)	\
4490Sstevel@tonic-gate 	(*(rdma_ops)->rdma_get_conn)(addr, addr_type, handle, conn)
4500Sstevel@tonic-gate 
4510Sstevel@tonic-gate #define	RDMA_REL_CONN(conn)	\
4520Sstevel@tonic-gate 	(*(conn)->c_rdmamod->rdma_ops->rdma_rel_conn)(conn)
4530Sstevel@tonic-gate 
4547387SRobert.Gordon@Sun.COM #define	RDMA_REGMEM(conn, adsp, buff, len, handle)	\
4557387SRobert.Gordon@Sun.COM 	(*(conn)->c_rdmamod->rdma_ops->rdma_regmem)(conn, adsp,	\
4567387SRobert.Gordon@Sun.COM 		buff, len, handle)
4570Sstevel@tonic-gate 
4580Sstevel@tonic-gate #define	RDMA_DEREGMEM(conn, buff, handle)	\
4590Sstevel@tonic-gate 	(*(conn)->c_rdmamod->rdma_ops->rdma_deregmem)(conn, buff, handle)
4600Sstevel@tonic-gate 
4617387SRobert.Gordon@Sun.COM #define	RDMA_REGMEMSYNC(conn, adsp, buff, len, handle, synchandle, lrc)	\
4627387SRobert.Gordon@Sun.COM 	(*(conn)->c_rdmamod->rdma_ops->rdma_regmemsync)(conn, adsp, buff, \
4637387SRobert.Gordon@Sun.COM 	len, handle, synchandle, lrc)
4640Sstevel@tonic-gate 
4657387SRobert.Gordon@Sun.COM #define	RDMA_DEREGMEMSYNC(conn, buff, handle, synchandle, lrc)	\
4667387SRobert.Gordon@Sun.COM 	(*(conn)->c_rdmamod->rdma_ops->rdma_deregmemsync)(conn, buff,	\
4677387SRobert.Gordon@Sun.COM 	handle, synchandle, lrc)
4680Sstevel@tonic-gate 
4690Sstevel@tonic-gate #define	RDMA_SYNCMEM(conn, handle, buff, len, direction)	\
4700Sstevel@tonic-gate 	(*(conn)->c_rdmamod->rdma_ops->rdma_syncmem)(conn, handle, \
4710Sstevel@tonic-gate 	    buff, len, direction)
4720Sstevel@tonic-gate 
4730Sstevel@tonic-gate #define	RDMA_BUF_ALLOC(conn, rbuf)	\
4740Sstevel@tonic-gate 	(*(conn)->c_rdmamod->rdma_ops->rdma_buf_alloc)(conn, rbuf)
4750Sstevel@tonic-gate 
4760Sstevel@tonic-gate #define	RDMA_BUF_FREE(conn, rbuf)	\
4770Sstevel@tonic-gate 	(*(conn)->c_rdmamod->rdma_ops->rdma_buf_free)(conn, rbuf)
4780Sstevel@tonic-gate 
4790Sstevel@tonic-gate #define	RDMA_SEND(conn, sendlist, xid)	\
4800Sstevel@tonic-gate 	(*(conn)->c_rdmamod->rdma_ops->rdma_send)(conn, sendlist, xid)
4810Sstevel@tonic-gate 
4820Sstevel@tonic-gate #define	RDMA_SEND_RESP(conn, sendlist, xid)	\
4830Sstevel@tonic-gate 	(*(conn)->c_rdmamod->rdma_ops->rdma_send_resp)(conn, sendlist, xid)
4840Sstevel@tonic-gate 
4850Sstevel@tonic-gate #define	RDMA_CLNT_RECVBUF(conn, cl, xid)	\
4860Sstevel@tonic-gate 	(*(conn)->c_rdmamod->rdma_ops->rdma_clnt_recvbuf)(conn, cl, xid)
4870Sstevel@tonic-gate 
4887387SRobert.Gordon@Sun.COM #define	RDMA_CLNT_RECVBUF_REMOVE(conn, xid)	\
4897387SRobert.Gordon@Sun.COM 	(*(conn)->c_rdmamod->rdma_ops->rdma_clnt_recvbuf_remove)(conn, xid)
4907387SRobert.Gordon@Sun.COM 
4910Sstevel@tonic-gate #define	RDMA_SVC_RECVBUF(conn, cl)	\
4920Sstevel@tonic-gate 	(*(conn)->c_rdmamod->rdma_ops->rdma_svc_recvbuf)(conn, cl)
4930Sstevel@tonic-gate 
4940Sstevel@tonic-gate #define	RDMA_RECV(conn, recvlist, xid)	\
4950Sstevel@tonic-gate 	(*(conn)->c_rdmamod->rdma_ops->rdma_recv)(conn, recvlist, xid)
4960Sstevel@tonic-gate 
4970Sstevel@tonic-gate #define	RDMA_READ(conn, cl, wait)	\
4980Sstevel@tonic-gate 	(*(conn)->c_rdmamod->rdma_ops->rdma_read)(conn, cl, wait)
4990Sstevel@tonic-gate 
5000Sstevel@tonic-gate #define	RDMA_WRITE(conn, cl, wait)	\
5010Sstevel@tonic-gate 	(*(conn)->c_rdmamod->rdma_ops->rdma_write)(conn, cl, wait)
5020Sstevel@tonic-gate 
5030Sstevel@tonic-gate #define	RDMA_GETINFO(rdma_mod, info)	\
5040Sstevel@tonic-gate 	(*(rdma_mod)->rdma_ops->rdma_getinfo)(info)
5050Sstevel@tonic-gate 
5060Sstevel@tonic-gate #ifdef _KERNEL
5070Sstevel@tonic-gate extern rdma_registry_t	*rdma_mod_head;
5080Sstevel@tonic-gate extern krwlock_t rdma_lock;		/* protects rdma_mod_head list */
5090Sstevel@tonic-gate extern int rdma_modloaded;		/* flag for loading RDMA plugins */
5100Sstevel@tonic-gate extern int rdma_dev_available;		/* rdma device is loaded or not */
5110Sstevel@tonic-gate extern kmutex_t rdma_modload_lock;	/* protects rdma_modloaded flag */
5120Sstevel@tonic-gate extern uint_t rdma_minchunk;
5130Sstevel@tonic-gate extern ldi_ident_t rpcmod_li; 		/* needed by layed driver framework */
5140Sstevel@tonic-gate 
5150Sstevel@tonic-gate /*
5160Sstevel@tonic-gate  * General RDMA routines
5170Sstevel@tonic-gate  */
5187387SRobert.Gordon@Sun.COM extern struct clist *clist_alloc(void);
5197387SRobert.Gordon@Sun.COM extern void clist_add(struct clist **, uint32_t, int,
5207387SRobert.Gordon@Sun.COM 	struct mrc *, caddr_t, struct mrc *, caddr_t);
5217387SRobert.Gordon@Sun.COM extern void clist_free(struct clist *);
522*9348SSiddheshwar.Mahesh@Sun.COM extern uint32_t clist_len(struct clist *);
523*9348SSiddheshwar.Mahesh@Sun.COM extern void clist_zero_len(struct clist *);
5247387SRobert.Gordon@Sun.COM extern rdma_stat clist_register(CONN *conn, struct clist *cl, clist_dstsrc);
525*9348SSiddheshwar.Mahesh@Sun.COM extern rdma_stat clist_deregister(CONN *conn, struct clist *cl);
5267387SRobert.Gordon@Sun.COM extern rdma_stat clist_syncmem(CONN *conn, struct clist *cl, clist_dstsrc);
5277387SRobert.Gordon@Sun.COM extern rdma_stat rdma_clnt_postrecv(CONN *conn, uint32_t xid);
5287387SRobert.Gordon@Sun.COM extern rdma_stat rdma_clnt_postrecv_remove(CONN *conn, uint32_t xid);
5297387SRobert.Gordon@Sun.COM extern rdma_stat rdma_svc_postrecv(CONN *conn);
5300Sstevel@tonic-gate extern rdma_stat rdma_register_mod(rdma_mod_t *mod);
5310Sstevel@tonic-gate extern rdma_stat rdma_unregister_mod(rdma_mod_t *mod);
5327387SRobert.Gordon@Sun.COM extern rdma_stat rdma_buf_alloc(CONN *, rdma_buf_t *);
5337387SRobert.Gordon@Sun.COM extern void rdma_buf_free(CONN *, rdma_buf_t *);
5340Sstevel@tonic-gate extern int rdma_modload();
5357387SRobert.Gordon@Sun.COM extern bool_t   rdma_get_wchunk(struct svc_req *, iovec_t *, struct clist *);
5368695SRajkumar.Sivaprakasam@Sun.COM extern rdma_stat rdma_kwait(void);
537*9348SSiddheshwar.Mahesh@Sun.COM extern int rdma_setup_read_chunks(struct clist *, uint32_t, int *);
5380Sstevel@tonic-gate 
5390Sstevel@tonic-gate /*
5400Sstevel@tonic-gate  * RDMA XDR
5410Sstevel@tonic-gate  */
5420Sstevel@tonic-gate extern void xdrrdma_create(XDR *, caddr_t, uint_t, int, struct clist *,
5430Sstevel@tonic-gate 	enum xdr_op, CONN *);
5440Sstevel@tonic-gate extern void xdrrdma_destroy(XDR *);
5457387SRobert.Gordon@Sun.COM 
5460Sstevel@tonic-gate extern uint_t xdrrdma_getpos(XDR *);
5470Sstevel@tonic-gate extern bool_t xdrrdma_setpos(XDR *, uint_t);
5480Sstevel@tonic-gate extern bool_t xdr_clist(XDR *, clist *);
5490Sstevel@tonic-gate extern bool_t xdr_do_clist(XDR *, clist **);
5500Sstevel@tonic-gate extern uint_t xdr_getbufsize(XDR *);
5517387SRobert.Gordon@Sun.COM extern unsigned int xdrrdma_sizeof(xdrproc_t, void *, int, uint_t *, uint_t *);
5527387SRobert.Gordon@Sun.COM extern unsigned int xdrrdma_authsize(AUTH *, struct cred *, int);
5537387SRobert.Gordon@Sun.COM 
5547387SRobert.Gordon@Sun.COM extern void xdrrdma_store_wlist(XDR *, struct clist *);
5557387SRobert.Gordon@Sun.COM extern struct clist *xdrrdma_wclist(XDR *);
5567387SRobert.Gordon@Sun.COM extern bool_t xdr_decode_reply_wchunk(XDR *, struct clist **);
5577387SRobert.Gordon@Sun.COM extern bool_t xdr_decode_wlist(XDR *xdrs, struct clist **, bool_t *);
5587387SRobert.Gordon@Sun.COM extern bool_t xdr_decode_wlist_svc(XDR *xdrs, struct clist **, bool_t *,
5597387SRobert.Gordon@Sun.COM 	uint32_t *, CONN *);
5607387SRobert.Gordon@Sun.COM extern bool_t xdr_encode_rlist_svc(XDR *, clist *);
5617387SRobert.Gordon@Sun.COM extern bool_t xdr_encode_wlist(XDR *, clist *);
5627387SRobert.Gordon@Sun.COM extern bool_t xdr_encode_reply_wchunk(XDR *, struct clist *,
5637387SRobert.Gordon@Sun.COM 		uint32_t seg_array_len);
5647387SRobert.Gordon@Sun.COM bool_t xdrrdma_getrdmablk(XDR *, struct clist **, uint_t *,
5657387SRobert.Gordon@Sun.COM 	CONN **conn, const uint_t);
566*9348SSiddheshwar.Mahesh@Sun.COM bool_t xdrrdma_read_from_client(struct clist *, CONN **, uint_t);
567*9348SSiddheshwar.Mahesh@Sun.COM bool_t xdrrdma_send_read_data(XDR *, uint_t, struct clist *);
5687387SRobert.Gordon@Sun.COM bool_t xdrrdma_free_clist(CONN *, struct clist *);
5690Sstevel@tonic-gate #endif /* _KERNEL */
5700Sstevel@tonic-gate 
5710Sstevel@tonic-gate #ifdef __cplusplus
5720Sstevel@tonic-gate }
5730Sstevel@tonic-gate #endif
5740Sstevel@tonic-gate 
5750Sstevel@tonic-gate #endif	/* _RPC_RPC_RDMA_H */
576