xref: /titanic_44/usr/src/uts/common/rpc/rpc_rdma.h (revision 0a4b08109ed53cd50c90d18c62198d62eec19da0)
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
50a701b1eSRobert Gordon  * Common Development and Distribution License (the "License").
60a701b1eSRobert Gordon  * 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*0a4b0810SKaren Rochford  * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
237c478bd9Sstevel@tonic-gate  */
247c478bd9Sstevel@tonic-gate 
250a701b1eSRobert Gordon /*
260a701b1eSRobert Gordon  * Copyright (c) 2007, The Ohio State University. All rights reserved.
270a701b1eSRobert Gordon  *
280a701b1eSRobert Gordon  * Portions of this source code is developed by the team members of
290a701b1eSRobert Gordon  * The Ohio State University's Network-Based Computing Laboratory (NBCL),
300a701b1eSRobert Gordon  * headed by Professor Dhabaleswar K. (DK) Panda.
310a701b1eSRobert Gordon  *
320a701b1eSRobert Gordon  * Acknowledgements to contributions from developors:
330a701b1eSRobert Gordon  *   Ranjit Noronha: noronha@cse.ohio-state.edu
340a701b1eSRobert Gordon  *   Lei Chai      : chail@cse.ohio-state.edu
350a701b1eSRobert Gordon  *   Weikuan Yu    : yuw@cse.ohio-state.edu
360a701b1eSRobert Gordon  *
370a701b1eSRobert Gordon  */
380a701b1eSRobert Gordon 
397c478bd9Sstevel@tonic-gate #ifndef	_RPC_RPC_RDMA_H
407c478bd9Sstevel@tonic-gate #define	_RPC_RPC_RDMA_H
417c478bd9Sstevel@tonic-gate 
427c478bd9Sstevel@tonic-gate #include <rpc/rpc.h>
437c478bd9Sstevel@tonic-gate #include <rpc/rpc_sztypes.h>
447c478bd9Sstevel@tonic-gate #include <sys/sunddi.h>
457c478bd9Sstevel@tonic-gate #include <sys/sunldi.h>
467c478bd9Sstevel@tonic-gate 
477c478bd9Sstevel@tonic-gate #ifdef __cplusplus
487c478bd9Sstevel@tonic-gate extern "C" {
497c478bd9Sstevel@tonic-gate #endif
507c478bd9Sstevel@tonic-gate 
510a701b1eSRobert Gordon #define	RPCRDMA_VERS	1	/* Version of the RPC over RDMA protocol */
527c478bd9Sstevel@tonic-gate #define	RDMATF_VERS	1	/* Version of the API used by RPC for RDMA */
537c478bd9Sstevel@tonic-gate #define	RDMATF_VERS_1	1	/* Current version of RDMATF */
547c478bd9Sstevel@tonic-gate 
557c478bd9Sstevel@tonic-gate /*
567c478bd9Sstevel@tonic-gate  * The size of an RPC call or reply message
577c478bd9Sstevel@tonic-gate  */
587c478bd9Sstevel@tonic-gate #define	RPC_MSG_SZ	1024
597c478bd9Sstevel@tonic-gate 
607c478bd9Sstevel@tonic-gate /*
610a701b1eSRobert Gordon  * RDMA chunk size
620a701b1eSRobert Gordon  */
630a701b1eSRobert Gordon #define	RDMA_MINCHUNK	1024
640a701b1eSRobert Gordon 
650a701b1eSRobert Gordon /*
667c478bd9Sstevel@tonic-gate  * Storage for a chunk list
677c478bd9Sstevel@tonic-gate  */
687c478bd9Sstevel@tonic-gate #define	RPC_CL_SZ  1024
697c478bd9Sstevel@tonic-gate 
707c478bd9Sstevel@tonic-gate /*
717c478bd9Sstevel@tonic-gate  * Chunk size
727c478bd9Sstevel@tonic-gate  */
737c478bd9Sstevel@tonic-gate #define	MINCHUNK  1024
747c478bd9Sstevel@tonic-gate 
757c478bd9Sstevel@tonic-gate /*
767c478bd9Sstevel@tonic-gate  * Size of receive buffer
777c478bd9Sstevel@tonic-gate  */
787c478bd9Sstevel@tonic-gate #define	RPC_BUF_SIZE	2048
797c478bd9Sstevel@tonic-gate 
807c478bd9Sstevel@tonic-gate #define	NOWAIT	0	/* don't wait for operation of complete */
817c478bd9Sstevel@tonic-gate #define	WAIT	1	/* wait and ensure that operation is complete */
827c478bd9Sstevel@tonic-gate 
837c478bd9Sstevel@tonic-gate /*
847c478bd9Sstevel@tonic-gate  * RDMA xdr buffer control and other control flags. Add new flags here,
857c478bd9Sstevel@tonic-gate  * set them in private structure for xdr over RDMA in xdr_rdma.c
867c478bd9Sstevel@tonic-gate  */
870a701b1eSRobert Gordon #define	XDR_RDMA_CHUNK			0x1
880a701b1eSRobert Gordon #define	XDR_RDMA_WLIST_REG		0x2
890a701b1eSRobert Gordon #define	XDR_RDMA_RLIST_REG		0x4
900a701b1eSRobert Gordon 
910a701b1eSRobert Gordon #define	LONG_REPLY_LEN	65536
920a701b1eSRobert Gordon #define	WCL_BUF_LEN	32768
930a701b1eSRobert Gordon #define	RCL_BUF_LEN	32768
940a701b1eSRobert Gordon 
950a701b1eSRobert Gordon 
960a701b1eSRobert Gordon #define	RDMA_BUFS_RQST	34	/* Num bufs requested by client */
970a701b1eSRobert Gordon #define	RDMA_BUFS_GRANT	32	/* Num bufs granted by server */
980a701b1eSRobert Gordon 
990a701b1eSRobert Gordon struct xdr_ops *xdrrdma_xops(void);
1000a701b1eSRobert Gordon 
1010a701b1eSRobert Gordon /*
1020a701b1eSRobert Gordon  * Credit Control Structures.
1030a701b1eSRobert Gordon  */
1040a701b1eSRobert Gordon typedef enum rdma_cc_type {
1050a701b1eSRobert Gordon 	RDMA_CC_CLNT,	/* CONN is for a client */
1060a701b1eSRobert Gordon 	RDMA_CC_SRV	/* CONN is for a server */
1070a701b1eSRobert Gordon } rdma_cc_type_t;
1080a701b1eSRobert Gordon 
1090a701b1eSRobert Gordon /*
1100a701b1eSRobert Gordon  * Client side credit control data structure.
1110a701b1eSRobert Gordon  */
1120a701b1eSRobert Gordon typedef struct rdma_clnt_cred_ctrl {
1130a701b1eSRobert Gordon 	uint32_t	clnt_cc_granted_ops;
1140a701b1eSRobert Gordon 	uint32_t	clnt_cc_in_flight_ops;
1150a701b1eSRobert Gordon 	kcondvar_t	clnt_cc_cv;
1160a701b1eSRobert Gordon } rdma_clnt_cred_ctrl_t;
1170a701b1eSRobert Gordon 
1180a701b1eSRobert Gordon /*
1190a701b1eSRobert Gordon  * Server side credit control data structure.
1200a701b1eSRobert Gordon  */
1210a701b1eSRobert Gordon typedef struct rdma_srv_cred_ctrl {
1220a701b1eSRobert Gordon 	uint32_t	srv_cc_buffers_granted;
1230a701b1eSRobert Gordon 	uint32_t	srv_cc_cur_buffers_used;
1240a701b1eSRobert Gordon 	uint32_t	srv_cc_posted;
1250a701b1eSRobert Gordon 	uint32_t	srv_cc_max_buf_size;	/* to be determined by CCP */
1260a701b1eSRobert Gordon 	uint32_t	srv_cc_cur_buf_size;	/* to be determined by CCP */
1270a701b1eSRobert Gordon } rdma_srv_cred_ctrl_t;
1280a701b1eSRobert Gordon 
1290a701b1eSRobert Gordon typedef enum {
1300a701b1eSRobert Gordon     RPCCALL_WLIST,
1310a701b1eSRobert Gordon     RPCCALL_WCHUNK,
1320a701b1eSRobert Gordon     RPCCALL_NOWRITE
1330a701b1eSRobert Gordon }rpccall_write_t;
1340a701b1eSRobert Gordon 
1350a701b1eSRobert Gordon typedef enum {
136f837ee4aSSiddheshwar Mahesh 	CLIST_REG_SOURCE = 1,
1370a701b1eSRobert Gordon 	CLIST_REG_DST
1380a701b1eSRobert Gordon } clist_dstsrc;
1397c478bd9Sstevel@tonic-gate 
1407c478bd9Sstevel@tonic-gate /*
1417c478bd9Sstevel@tonic-gate  * Return codes from RDMA operations
1427c478bd9Sstevel@tonic-gate  */
1437c478bd9Sstevel@tonic-gate typedef enum {
1447c478bd9Sstevel@tonic-gate 
1457c478bd9Sstevel@tonic-gate 	RDMA_SUCCESS = 0,	/* successful operation */
1467c478bd9Sstevel@tonic-gate 
1477c478bd9Sstevel@tonic-gate 	RDMA_INVAL = 1,		/* invalid parameter */
1487c478bd9Sstevel@tonic-gate 	RDMA_TIMEDOUT = 2,	/* operation timed out */
1497c478bd9Sstevel@tonic-gate 	RDMA_INTR = 3,		/* operation interrupted */
1507c478bd9Sstevel@tonic-gate 	RDMA_NORESOURCE = 4,	/* insufficient resource */
1517c478bd9Sstevel@tonic-gate 	/*
1527c478bd9Sstevel@tonic-gate 	 * connection errors
1537c478bd9Sstevel@tonic-gate 	 */
1547c478bd9Sstevel@tonic-gate 	RDMA_REJECT = 5,	/* connection req rejected */
1557c478bd9Sstevel@tonic-gate 	RDMA_NOLISTENER = 6,	/* no listener on server */
1567c478bd9Sstevel@tonic-gate 	RDMA_UNREACHABLE = 7,	/* host unreachable */
1577c478bd9Sstevel@tonic-gate 	RDMA_CONNLOST = 8,	/* connection lost */
1587c478bd9Sstevel@tonic-gate 
1597c478bd9Sstevel@tonic-gate 	RDMA_XPRTFAILED = 9,	/* RDMA transport failed */
1607c478bd9Sstevel@tonic-gate 	RDMA_PROTECTERR = 10,	/* memory protection error */
1617c478bd9Sstevel@tonic-gate 	RDMA_OVERRUN = 11,	/* transport overrun */
1627c478bd9Sstevel@tonic-gate 	RDMA_RECVQEMPTY = 12,	/* incoming pkt dropped, recv q empty */
1637c478bd9Sstevel@tonic-gate 	RDMA_PROTFAILED = 13,	/* RDMA protocol failed */
1647c478bd9Sstevel@tonic-gate 	RDMA_NOTSUPP = 14,	/* requested feature not supported */
1657c478bd9Sstevel@tonic-gate 	RDMA_REMOTERR = 15,	/* error at remote end */
1667c478bd9Sstevel@tonic-gate 	/*
1677c478bd9Sstevel@tonic-gate 	 * RDMATF errors
1687c478bd9Sstevel@tonic-gate 	 */
1697c478bd9Sstevel@tonic-gate 	RDMA_BADVERS = 16,	/* mismatch RDMATF versions */
1707c478bd9Sstevel@tonic-gate 	RDMA_REG_EXIST = 17,	/* RDMATF registration already exists */
17151f34d4bSRajkumar Sivaprakasam 	RDMA_HCA_ATTACH = 18,
17251f34d4bSRajkumar Sivaprakasam 	RDMA_HCA_DETACH = 19,
1737c478bd9Sstevel@tonic-gate 
1747c478bd9Sstevel@tonic-gate 	/*
1757c478bd9Sstevel@tonic-gate 	 * fallback error
1767c478bd9Sstevel@tonic-gate 	 */
17751f34d4bSRajkumar Sivaprakasam 	RDMA_FAILED = 20	/* generic error */
1787c478bd9Sstevel@tonic-gate } rdma_stat;
1797c478bd9Sstevel@tonic-gate 
1807c478bd9Sstevel@tonic-gate /*
1817c478bd9Sstevel@tonic-gate  * Memory region context. This is an RDMA provider generated
1827c478bd9Sstevel@tonic-gate  * handle for a registered arbitrary size contiguous virtual
1837c478bd9Sstevel@tonic-gate  * memory. The RDMA Interface Adapter needs this for local or
1847c478bd9Sstevel@tonic-gate  * remote memory access.
1857c478bd9Sstevel@tonic-gate  *
1867c478bd9Sstevel@tonic-gate  * The mrc_rmr field holds the remote memory region context
1877c478bd9Sstevel@tonic-gate  * which is sent over-the-wire to provide the remote host
1887c478bd9Sstevel@tonic-gate  * with RDMA access to the memory region.
1897c478bd9Sstevel@tonic-gate  */
1907c478bd9Sstevel@tonic-gate struct mrc {
1917c478bd9Sstevel@tonic-gate 	uint32_t	mrc_rmr;	/* Remote MR context, sent OTW */
1927c478bd9Sstevel@tonic-gate 	union {
1937c478bd9Sstevel@tonic-gate 		struct mr {
1947c478bd9Sstevel@tonic-gate 			uint32_t	lmr; 	/* Local MR context */
1957c478bd9Sstevel@tonic-gate 			uint64_t	linfo;	/* Local memory info */
1967c478bd9Sstevel@tonic-gate 		} mr;
1977c478bd9Sstevel@tonic-gate 	} lhdl;
1987c478bd9Sstevel@tonic-gate };
1997c478bd9Sstevel@tonic-gate 
2007c478bd9Sstevel@tonic-gate #define	mrc_lmr		lhdl.mr.lmr
2017c478bd9Sstevel@tonic-gate #define	mrc_linfo	lhdl.mr.linfo
2027c478bd9Sstevel@tonic-gate 
2037c478bd9Sstevel@tonic-gate /*
2040a701b1eSRobert Gordon  * Memory management for the RDMA buffers
2050a701b1eSRobert Gordon  */
2060a701b1eSRobert Gordon /*
2070a701b1eSRobert Gordon  * RDMA buffer types
2080a701b1eSRobert Gordon  */
2090a701b1eSRobert Gordon typedef enum {
2100a701b1eSRobert Gordon 	SEND_BUFFER,	/* buf for send msg */
2110a701b1eSRobert Gordon 	SEND_DESCRIPTOR, /* buf used for send msg descriptor in plugins only */
2120a701b1eSRobert Gordon 	RECV_BUFFER,	/* buf for recv msg */
2130a701b1eSRobert Gordon 	RECV_DESCRIPTOR, /* buf used for recv msg descriptor in plugins only */
2140a701b1eSRobert Gordon 	RDMA_LONG_BUFFER /* chunk buf used in RDMATF only and not in plugins */
2150a701b1eSRobert Gordon } rdma_btype;
2160a701b1eSRobert Gordon 
2170a701b1eSRobert Gordon /*
2180a701b1eSRobert Gordon  * RDMA buffer information
2190a701b1eSRobert Gordon  */
2200a701b1eSRobert Gordon typedef struct rdma_buf {
2210a701b1eSRobert Gordon 	rdma_btype	type;	/* buffer type */
2220a701b1eSRobert Gordon 	uint_t		len;	/* length of buffer */
2230a701b1eSRobert Gordon 	caddr_t		addr;	/* buffer address */
2240a701b1eSRobert Gordon 	struct mrc	handle;	/* buffer registration handle */
2250a701b1eSRobert Gordon 	caddr_t		rb_private;
2260a701b1eSRobert Gordon } rdma_buf_t;
2270a701b1eSRobert Gordon 
2280a701b1eSRobert Gordon 
2290a701b1eSRobert Gordon /*
2307c478bd9Sstevel@tonic-gate  * The XDR offset value is used by the XDR
2317c478bd9Sstevel@tonic-gate  * routine to identify the position in the
2327c478bd9Sstevel@tonic-gate  * RPC message where the opaque object would
2337c478bd9Sstevel@tonic-gate  * normally occur. Neither the data content
2347c478bd9Sstevel@tonic-gate  * of the chunk, nor its size field are included
2357c478bd9Sstevel@tonic-gate  * in the RPC message.  The XDR offset is calculated
2367c478bd9Sstevel@tonic-gate  * as if the chunks were present.
2377c478bd9Sstevel@tonic-gate  *
2387c478bd9Sstevel@tonic-gate  * The remaining fields identify the chunk of data
2397c478bd9Sstevel@tonic-gate  * on the sender.  The c_memhandle identifies a
2407c478bd9Sstevel@tonic-gate  * registered RDMA memory region and the c_addr
2417c478bd9Sstevel@tonic-gate  * and c_len fields identify the chunk within it.
2427c478bd9Sstevel@tonic-gate  */
2437c478bd9Sstevel@tonic-gate struct clist {
2447c478bd9Sstevel@tonic-gate 	uint32		c_xdroff;	/* XDR offset */
2457c478bd9Sstevel@tonic-gate 	uint32		c_len;		/* Length */
246f837ee4aSSiddheshwar Mahesh 	clist_dstsrc	c_regtype;	/* type of registration */
2477c478bd9Sstevel@tonic-gate 	struct mrc	c_smemhandle;	/* src memory handle */
2487c478bd9Sstevel@tonic-gate 	uint64 		c_ssynchandle;	/* src sync handle */
2490a701b1eSRobert Gordon 	union {
2507c478bd9Sstevel@tonic-gate 		uint64		c_saddr;	/* src address */
2510a701b1eSRobert Gordon 		caddr_t 	c_saddr3;
2520a701b1eSRobert Gordon 	} w;
2537c478bd9Sstevel@tonic-gate 	struct mrc	c_dmemhandle;	/* dst memory handle */
2547c478bd9Sstevel@tonic-gate 	uint64		c_dsynchandle;	/* dst sync handle */
2550a701b1eSRobert Gordon 	union {
2567c478bd9Sstevel@tonic-gate 		uint64	c_daddr;	/* dst address */
2570a701b1eSRobert Gordon 		caddr_t	c_daddr3;
2580a701b1eSRobert Gordon 	} u;
2590a701b1eSRobert Gordon 	struct as	*c_adspc;	/* address space for saddr/daddr */
2600a701b1eSRobert Gordon 	rdma_buf_t	rb_longbuf;	/* used for long requests/replies */
2617c478bd9Sstevel@tonic-gate 	struct clist	*c_next;	/* Next chunk */
2627c478bd9Sstevel@tonic-gate };
2637c478bd9Sstevel@tonic-gate 
2647c478bd9Sstevel@tonic-gate typedef struct clist clist;
2657c478bd9Sstevel@tonic-gate 
2660a701b1eSRobert Gordon /*
2670a701b1eSRobert Gordon  * max 4M wlist xfer size
2680a701b1eSRobert Gordon  * This is defined because the rfs3_tsize service requires
2690a701b1eSRobert Gordon  * svc_req struct (which we don't have that in krecv).
2700a701b1eSRobert Gordon  */
2710a701b1eSRobert Gordon #define	MAX_SVC_XFER_SIZE (4*1024*1024)
2720a701b1eSRobert Gordon 
2737c478bd9Sstevel@tonic-gate enum rdma_proc {
2747c478bd9Sstevel@tonic-gate 	RDMA_MSG	= 0,	/* chunk list and RPC msg follow */
2757c478bd9Sstevel@tonic-gate 	RDMA_NOMSG	= 1,	/* only chunk list follows */
2767c478bd9Sstevel@tonic-gate 	RDMA_MSGP	= 2,	/* chunk list and RPC msg with padding follow */
2777c478bd9Sstevel@tonic-gate 	RDMA_DONE	= 3	/* signal completion of chunk transfer */
2787c478bd9Sstevel@tonic-gate };
2797c478bd9Sstevel@tonic-gate 
2807c478bd9Sstevel@tonic-gate /*
2817c478bd9Sstevel@tonic-gate  * Listener information for a service
2827c478bd9Sstevel@tonic-gate  */
2837c478bd9Sstevel@tonic-gate struct rdma_svc_data {
2847c478bd9Sstevel@tonic-gate 	queue_t		q;	/* queue_t to place incoming pkts */
2857c478bd9Sstevel@tonic-gate 	int		active;	/* If active, after registeration startup */
2867c478bd9Sstevel@tonic-gate 	rdma_stat	err_code;	/* Error code from plugin layer */
2877c478bd9Sstevel@tonic-gate 	int32_t		svcid;		/* RDMA based service identifier */
2887c478bd9Sstevel@tonic-gate };
2897c478bd9Sstevel@tonic-gate 
2907c478bd9Sstevel@tonic-gate /*
2917c478bd9Sstevel@tonic-gate  * Per RDMA plugin module information.
2927c478bd9Sstevel@tonic-gate  * Will be populated by each plugin
2937c478bd9Sstevel@tonic-gate  * module during its initialization.
2947c478bd9Sstevel@tonic-gate  */
2957c478bd9Sstevel@tonic-gate typedef struct rdma_mod {
2967c478bd9Sstevel@tonic-gate 	char 		*rdma_api;		/* "kvipl", "ibtf", etc */
2977c478bd9Sstevel@tonic-gate 	uint_t 		rdma_version;		/* RDMATF API version */
2987c478bd9Sstevel@tonic-gate 	int		rdma_count;		/* # of devices */
2997c478bd9Sstevel@tonic-gate 	struct rdmaops 	*rdma_ops;		/* rdma op vector for api */
3007c478bd9Sstevel@tonic-gate } rdma_mod_t;
3017c478bd9Sstevel@tonic-gate 
3027c478bd9Sstevel@tonic-gate /*
3037c478bd9Sstevel@tonic-gate  * Registry of RDMA plugins
3047c478bd9Sstevel@tonic-gate  */
3057c478bd9Sstevel@tonic-gate typedef struct rdma_registry {
3067c478bd9Sstevel@tonic-gate 	rdma_mod_t	*r_mod;		/* plugin mod info */
30751f34d4bSRajkumar Sivaprakasam 	uint32_t	r_mod_state;
3087c478bd9Sstevel@tonic-gate 	struct rdma_registry *r_next;	/* next registered RDMA plugin */
3097c478bd9Sstevel@tonic-gate } rdma_registry_t;
3107c478bd9Sstevel@tonic-gate 
3117c478bd9Sstevel@tonic-gate /*
31251f34d4bSRajkumar Sivaprakasam  * RDMA MODULE state flags (r_mod_state).
31351f34d4bSRajkumar Sivaprakasam  */
31451f34d4bSRajkumar Sivaprakasam #define	RDMA_MOD_ACTIVE		1
31551f34d4bSRajkumar Sivaprakasam #define	RDMA_MOD_INACTIVE	0
31651f34d4bSRajkumar Sivaprakasam 
31751f34d4bSRajkumar Sivaprakasam /*
3187c478bd9Sstevel@tonic-gate  * RDMA transport information
3197c478bd9Sstevel@tonic-gate  */
3207c478bd9Sstevel@tonic-gate typedef struct rdma_info {
3217c478bd9Sstevel@tonic-gate 	uint_t	addrlen;	/* address length */
3227c478bd9Sstevel@tonic-gate 	uint_t  mts;		/* max transfer size */
3237c478bd9Sstevel@tonic-gate 	uint_t  mtu;		/* native mtu size of unlerlying network */
3247c478bd9Sstevel@tonic-gate } rdma_info_t;
3257c478bd9Sstevel@tonic-gate 
3260a701b1eSRobert Gordon typedef enum {
3270a701b1eSRobert Gordon 	C_IDLE		= 0x00000001,
3280a701b1eSRobert Gordon 	C_CONN_PEND	= 0x00000002,
3290a701b1eSRobert Gordon 	C_CONNECTED	= 0x00000004,
3300a701b1eSRobert Gordon 	C_ERROR_CONN	= 0x00000008,
3310a701b1eSRobert Gordon 	C_DISCONN_PEND	= 0x00000010,
3320a701b1eSRobert Gordon 	C_REMOTE_DOWN	= 0x00000020
3330a701b1eSRobert Gordon } conn_c_state;
3340a701b1eSRobert Gordon 
335065714dcSSiddheshwar Mahesh /* c_flags */
336065714dcSSiddheshwar Mahesh #define	C_CLOSE_NOTNEEDED	0x00000001	/* just free the channel */
337065714dcSSiddheshwar Mahesh #define	C_CLOSE_PENDING		0x00000002	/* a close in progress */
338065714dcSSiddheshwar Mahesh 
3397c478bd9Sstevel@tonic-gate /*
3407c478bd9Sstevel@tonic-gate  * RDMA Connection information
3417c478bd9Sstevel@tonic-gate  */
3427c478bd9Sstevel@tonic-gate typedef struct conn {
3437c478bd9Sstevel@tonic-gate 	rdma_mod_t	*c_rdmamod;	/* RDMA transport info for conn */
3447523bef8SSiddheshwar Mahesh 	char 		*c_netid;	/* tcp or tcp6 token */
3457c478bd9Sstevel@tonic-gate 	struct netbuf	c_raddr;	/* remote address */
3467c478bd9Sstevel@tonic-gate 	struct netbuf	c_laddr;	/* local address */
347*0a4b0810SKaren Rochford 	struct netbuf	c_addrmask;	/* Address Mask */
3487c478bd9Sstevel@tonic-gate 	int		c_ref;		/* no. of clients of connection */
3497c478bd9Sstevel@tonic-gate 	struct conn	*c_next;	/* next in list of connections */
3507c478bd9Sstevel@tonic-gate 	struct conn	*c_prev;	/* prev in list of connections */
3517c478bd9Sstevel@tonic-gate 	caddr_t		c_private;	/* transport specific stuff */
3520a701b1eSRobert Gordon 	conn_c_state	c_state;	/* state of connection */
353065714dcSSiddheshwar Mahesh 	int		c_flags;	/* flags for connection management */
3540a701b1eSRobert Gordon 	rdma_cc_type_t	c_cc_type;	/* client or server, for credit cntrl */
3550a701b1eSRobert Gordon 	union {
3560a701b1eSRobert Gordon 		rdma_clnt_cred_ctrl_t	c_clnt_cc;
3570a701b1eSRobert Gordon 		rdma_srv_cred_ctrl_t	c_srv_cc;
3580a701b1eSRobert Gordon 	} rdma_conn_cred_ctrl_u;
3597c478bd9Sstevel@tonic-gate 	kmutex_t	c_lock;		/* protect c_state and c_ref fields */
3607c478bd9Sstevel@tonic-gate 	kcondvar_t	c_cv;		/* to signal when pending is done */
361065714dcSSiddheshwar Mahesh 	timeout_id_t	c_timeout;	/* timeout id for untimeout() */
362065714dcSSiddheshwar Mahesh 	time_t		c_last_used;	/* last time any activity on the conn */
3637c478bd9Sstevel@tonic-gate } CONN;
3647c478bd9Sstevel@tonic-gate 
3657c478bd9Sstevel@tonic-gate 
3667c478bd9Sstevel@tonic-gate /*
3677c478bd9Sstevel@tonic-gate  * Data transferred from plugin interrupt to svc_queuereq()
3687c478bd9Sstevel@tonic-gate  */
3690a701b1eSRobert Gordon typedef struct rdma_recv_data {
3707c478bd9Sstevel@tonic-gate 	CONN		*conn;
3717c478bd9Sstevel@tonic-gate 	int		status;
3727c478bd9Sstevel@tonic-gate 	rdma_buf_t	rpcmsg;
3730a701b1eSRobert Gordon } rdma_recv_data_t;
3740a701b1eSRobert Gordon 
3750a701b1eSRobert Gordon /* structure used to pass information for READ over rdma write */
3760a701b1eSRobert Gordon typedef enum {
3770a701b1eSRobert Gordon 	RCI_WRITE_UIO_CHUNK = 1,
3780a701b1eSRobert Gordon 	RCI_WRITE_ADDR_CHUNK = 2,
3790a701b1eSRobert Gordon 	RCI_REPLY_CHUNK = 3
3800a701b1eSRobert Gordon } rci_type_t;
3810a701b1eSRobert Gordon 
3820a701b1eSRobert Gordon typedef struct {
3830a701b1eSRobert Gordon 	rci_type_t rci_type;
3840a701b1eSRobert Gordon 	union {
3850a701b1eSRobert Gordon 		struct uio *rci_uiop;
3860a701b1eSRobert Gordon 		caddr_t    rci_addr;
3870a701b1eSRobert Gordon 	} rci_a;
3880a701b1eSRobert Gordon 	uint32	rci_len;
3890a701b1eSRobert Gordon 	struct clist	**rci_clpp; /* point to write chunk list in readargs */
3900a701b1eSRobert Gordon } rdma_chunkinfo_t;
3910a701b1eSRobert Gordon 
3920a701b1eSRobert Gordon typedef struct {
3930a701b1eSRobert Gordon 	uint_t rcil_len;
3940a701b1eSRobert Gordon 	uint_t rcil_len_alt;
3950a701b1eSRobert Gordon } rdma_chunkinfo_lengths_t;
3960a701b1eSRobert Gordon 
3970a701b1eSRobert Gordon typedef struct {
3980a701b1eSRobert Gordon 	struct	clist	*rwci_wlist;
3990a701b1eSRobert Gordon 	CONN		*rwci_conn;
4000a701b1eSRobert Gordon } rdma_wlist_conn_info_t;
4017c478bd9Sstevel@tonic-gate 
4027c478bd9Sstevel@tonic-gate /*
4037c478bd9Sstevel@tonic-gate  * Operations vector for RDMA transports.
4047c478bd9Sstevel@tonic-gate  */
4057c478bd9Sstevel@tonic-gate typedef struct rdmaops {
4067c478bd9Sstevel@tonic-gate 	/* Network */
4077c478bd9Sstevel@tonic-gate 	rdma_stat	(*rdma_reachable)(int addr_type, struct netbuf *,
4087c478bd9Sstevel@tonic-gate 						void **handle);
4097c478bd9Sstevel@tonic-gate 	/* Connection */
4107f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States 	rdma_stat	(*rdma_get_conn)(struct netbuf *, struct netbuf *,
4117f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States 					int addr_type, void *, CONN **);
4127c478bd9Sstevel@tonic-gate 	rdma_stat	(*rdma_rel_conn)(CONN *);
4137c478bd9Sstevel@tonic-gate 	/* Server side listner start and stop routines */
4147c478bd9Sstevel@tonic-gate 	void		(*rdma_svc_listen)(struct rdma_svc_data *);
4157c478bd9Sstevel@tonic-gate 	void		(*rdma_svc_stop)(struct rdma_svc_data *);
4167c478bd9Sstevel@tonic-gate 	/* Memory */
4170a701b1eSRobert Gordon 	rdma_stat	(*rdma_regmem)(CONN *, caddr_t, caddr_t,
4180a701b1eSRobert Gordon 			    uint_t, struct mrc *);
4197c478bd9Sstevel@tonic-gate 	rdma_stat	(*rdma_deregmem)(CONN *, caddr_t, struct mrc);
4200a701b1eSRobert Gordon 	rdma_stat	(*rdma_regmemsync)(CONN *, caddr_t, caddr_t, uint_t,
4210a701b1eSRobert Gordon 				struct mrc *, void **, void *);
4227c478bd9Sstevel@tonic-gate 	rdma_stat	(*rdma_deregmemsync)(CONN *, caddr_t, struct mrc,
4230a701b1eSRobert Gordon 			    void *, void *);
4247c478bd9Sstevel@tonic-gate 	rdma_stat	(*rdma_syncmem)(CONN *, void *, caddr_t, int, int);
4257c478bd9Sstevel@tonic-gate 	/* Buffer */
4267c478bd9Sstevel@tonic-gate 	rdma_stat	(*rdma_buf_alloc)(CONN *, rdma_buf_t *);
4277c478bd9Sstevel@tonic-gate 	void		(*rdma_buf_free)(CONN *, rdma_buf_t *);
4287c478bd9Sstevel@tonic-gate 	/* Transfer */
4297c478bd9Sstevel@tonic-gate 	rdma_stat	(*rdma_send)(CONN *, clist *, uint32_t);
4307c478bd9Sstevel@tonic-gate 	rdma_stat	(*rdma_send_resp)(CONN *, clist *, uint32_t);
4317c478bd9Sstevel@tonic-gate 	rdma_stat	(*rdma_clnt_recvbuf)(CONN *, clist *, uint32_t);
4320a701b1eSRobert Gordon 	rdma_stat	(*rdma_clnt_recvbuf_remove)(CONN *, uint32_t);
4337c478bd9Sstevel@tonic-gate 	rdma_stat	(*rdma_svc_recvbuf)(CONN *, clist *);
4347c478bd9Sstevel@tonic-gate 	rdma_stat	(*rdma_recv)(CONN *, clist **, uint32_t);
4357c478bd9Sstevel@tonic-gate 	/* RDMA */
4367c478bd9Sstevel@tonic-gate 	rdma_stat	(*rdma_read)(CONN *, clist *, int);
4377c478bd9Sstevel@tonic-gate 	rdma_stat	(*rdma_write)(CONN *, clist *, int);
4387c478bd9Sstevel@tonic-gate 	/* INFO */
4397c478bd9Sstevel@tonic-gate 	rdma_stat	(*rdma_getinfo)(rdma_info_t *info);
4407c478bd9Sstevel@tonic-gate } rdmaops_t;
4417c478bd9Sstevel@tonic-gate 
44251f34d4bSRajkumar Sivaprakasam typedef struct rdma_svc_wait {
44351f34d4bSRajkumar Sivaprakasam 	kmutex_t svc_lock;
44451f34d4bSRajkumar Sivaprakasam 	kcondvar_t svc_cv;
44551f34d4bSRajkumar Sivaprakasam 	rdma_stat svc_stat;
44651f34d4bSRajkumar Sivaprakasam } rdma_svc_wait_t;
44751f34d4bSRajkumar Sivaprakasam 
44851f34d4bSRajkumar Sivaprakasam extern rdma_svc_wait_t rdma_wait;
44951f34d4bSRajkumar Sivaprakasam 
4507c478bd9Sstevel@tonic-gate /*
4517c478bd9Sstevel@tonic-gate  * RDMA operations.
4527c478bd9Sstevel@tonic-gate  */
4537c478bd9Sstevel@tonic-gate #define	RDMA_REACHABLE(rdma_ops, addr_type, addr, handle)	\
4547c478bd9Sstevel@tonic-gate 	(*(rdma_ops)->rdma_reachable)(addr_type, addr, handle)
4557c478bd9Sstevel@tonic-gate 
4567f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States #define	RDMA_GET_CONN(rdma_ops, saddr, daddr, addr_type, handle, conn)	\
4577f379ad1SFaramarz Jalalian - Sun Microsystems - Irvine United States 	(*(rdma_ops)->rdma_get_conn)(saddr, daddr, addr_type, handle, conn)
4587c478bd9Sstevel@tonic-gate 
4597c478bd9Sstevel@tonic-gate #define	RDMA_REL_CONN(conn)	\
4607c478bd9Sstevel@tonic-gate 	(*(conn)->c_rdmamod->rdma_ops->rdma_rel_conn)(conn)
4617c478bd9Sstevel@tonic-gate 
4620a701b1eSRobert Gordon #define	RDMA_REGMEM(conn, adsp, buff, len, handle)	\
4630a701b1eSRobert Gordon 	(*(conn)->c_rdmamod->rdma_ops->rdma_regmem)(conn, adsp,	\
4640a701b1eSRobert Gordon 		buff, len, handle)
4657c478bd9Sstevel@tonic-gate 
4667c478bd9Sstevel@tonic-gate #define	RDMA_DEREGMEM(conn, buff, handle)	\
4677c478bd9Sstevel@tonic-gate 	(*(conn)->c_rdmamod->rdma_ops->rdma_deregmem)(conn, buff, handle)
4687c478bd9Sstevel@tonic-gate 
4690a701b1eSRobert Gordon #define	RDMA_REGMEMSYNC(conn, adsp, buff, len, handle, synchandle, lrc)	\
4700a701b1eSRobert Gordon 	(*(conn)->c_rdmamod->rdma_ops->rdma_regmemsync)(conn, adsp, buff, \
4710a701b1eSRobert Gordon 	len, handle, synchandle, lrc)
4727c478bd9Sstevel@tonic-gate 
4730a701b1eSRobert Gordon #define	RDMA_DEREGMEMSYNC(conn, buff, handle, synchandle, lrc)	\
4747c478bd9Sstevel@tonic-gate 	(*(conn)->c_rdmamod->rdma_ops->rdma_deregmemsync)(conn, buff,	\
4750a701b1eSRobert Gordon 	handle, synchandle, lrc)
4767c478bd9Sstevel@tonic-gate 
4777c478bd9Sstevel@tonic-gate #define	RDMA_SYNCMEM(conn, handle, buff, len, direction)	\
4787c478bd9Sstevel@tonic-gate 	(*(conn)->c_rdmamod->rdma_ops->rdma_syncmem)(conn, handle, \
4797c478bd9Sstevel@tonic-gate 	    buff, len, direction)
4807c478bd9Sstevel@tonic-gate 
4817c478bd9Sstevel@tonic-gate #define	RDMA_BUF_ALLOC(conn, rbuf)	\
4827c478bd9Sstevel@tonic-gate 	(*(conn)->c_rdmamod->rdma_ops->rdma_buf_alloc)(conn, rbuf)
4837c478bd9Sstevel@tonic-gate 
4847c478bd9Sstevel@tonic-gate #define	RDMA_BUF_FREE(conn, rbuf)	\
4857c478bd9Sstevel@tonic-gate 	(*(conn)->c_rdmamod->rdma_ops->rdma_buf_free)(conn, rbuf)
4867c478bd9Sstevel@tonic-gate 
4877c478bd9Sstevel@tonic-gate #define	RDMA_SEND(conn, sendlist, xid)	\
4887c478bd9Sstevel@tonic-gate 	(*(conn)->c_rdmamod->rdma_ops->rdma_send)(conn, sendlist, xid)
4897c478bd9Sstevel@tonic-gate 
4907c478bd9Sstevel@tonic-gate #define	RDMA_SEND_RESP(conn, sendlist, xid)	\
4917c478bd9Sstevel@tonic-gate 	(*(conn)->c_rdmamod->rdma_ops->rdma_send_resp)(conn, sendlist, xid)
4927c478bd9Sstevel@tonic-gate 
4937c478bd9Sstevel@tonic-gate #define	RDMA_CLNT_RECVBUF(conn, cl, xid)	\
4947c478bd9Sstevel@tonic-gate 	(*(conn)->c_rdmamod->rdma_ops->rdma_clnt_recvbuf)(conn, cl, xid)
4957c478bd9Sstevel@tonic-gate 
4960a701b1eSRobert Gordon #define	RDMA_CLNT_RECVBUF_REMOVE(conn, xid)	\
4970a701b1eSRobert Gordon 	(*(conn)->c_rdmamod->rdma_ops->rdma_clnt_recvbuf_remove)(conn, xid)
4980a701b1eSRobert Gordon 
4997c478bd9Sstevel@tonic-gate #define	RDMA_SVC_RECVBUF(conn, cl)	\
5007c478bd9Sstevel@tonic-gate 	(*(conn)->c_rdmamod->rdma_ops->rdma_svc_recvbuf)(conn, cl)
5017c478bd9Sstevel@tonic-gate 
5027c478bd9Sstevel@tonic-gate #define	RDMA_RECV(conn, recvlist, xid)	\
5037c478bd9Sstevel@tonic-gate 	(*(conn)->c_rdmamod->rdma_ops->rdma_recv)(conn, recvlist, xid)
5047c478bd9Sstevel@tonic-gate 
5057c478bd9Sstevel@tonic-gate #define	RDMA_READ(conn, cl, wait)	\
5067c478bd9Sstevel@tonic-gate 	(*(conn)->c_rdmamod->rdma_ops->rdma_read)(conn, cl, wait)
5077c478bd9Sstevel@tonic-gate 
5087c478bd9Sstevel@tonic-gate #define	RDMA_WRITE(conn, cl, wait)	\
5097c478bd9Sstevel@tonic-gate 	(*(conn)->c_rdmamod->rdma_ops->rdma_write)(conn, cl, wait)
5107c478bd9Sstevel@tonic-gate 
5117c478bd9Sstevel@tonic-gate #define	RDMA_GETINFO(rdma_mod, info)	\
5127c478bd9Sstevel@tonic-gate 	(*(rdma_mod)->rdma_ops->rdma_getinfo)(info)
5137c478bd9Sstevel@tonic-gate 
5147c478bd9Sstevel@tonic-gate #ifdef _KERNEL
5157c478bd9Sstevel@tonic-gate extern rdma_registry_t	*rdma_mod_head;
5167c478bd9Sstevel@tonic-gate extern krwlock_t rdma_lock;		/* protects rdma_mod_head list */
5177c478bd9Sstevel@tonic-gate extern int rdma_modloaded;		/* flag for loading RDMA plugins */
5187c478bd9Sstevel@tonic-gate extern int rdma_dev_available;		/* rdma device is loaded or not */
5197c478bd9Sstevel@tonic-gate extern kmutex_t rdma_modload_lock;	/* protects rdma_modloaded flag */
5207c478bd9Sstevel@tonic-gate extern uint_t rdma_minchunk;
5217c478bd9Sstevel@tonic-gate extern ldi_ident_t rpcmod_li; 		/* needed by layed driver framework */
5227c478bd9Sstevel@tonic-gate 
5237c478bd9Sstevel@tonic-gate /*
5247c478bd9Sstevel@tonic-gate  * General RDMA routines
5257c478bd9Sstevel@tonic-gate  */
5260a701b1eSRobert Gordon extern struct clist *clist_alloc(void);
5270a701b1eSRobert Gordon extern void clist_add(struct clist **, uint32_t, int,
5280a701b1eSRobert Gordon 	struct mrc *, caddr_t, struct mrc *, caddr_t);
5290a701b1eSRobert Gordon extern void clist_free(struct clist *);
530f837ee4aSSiddheshwar Mahesh extern uint32_t clist_len(struct clist *);
531f837ee4aSSiddheshwar Mahesh extern void clist_zero_len(struct clist *);
5320a701b1eSRobert Gordon extern rdma_stat clist_register(CONN *conn, struct clist *cl, clist_dstsrc);
533f837ee4aSSiddheshwar Mahesh extern rdma_stat clist_deregister(CONN *conn, struct clist *cl);
5340a701b1eSRobert Gordon extern rdma_stat clist_syncmem(CONN *conn, struct clist *cl, clist_dstsrc);
5350a701b1eSRobert Gordon extern rdma_stat rdma_clnt_postrecv(CONN *conn, uint32_t xid);
5360a701b1eSRobert Gordon extern rdma_stat rdma_clnt_postrecv_remove(CONN *conn, uint32_t xid);
5370a701b1eSRobert Gordon extern rdma_stat rdma_svc_postrecv(CONN *conn);
5387c478bd9Sstevel@tonic-gate extern rdma_stat rdma_register_mod(rdma_mod_t *mod);
5397c478bd9Sstevel@tonic-gate extern rdma_stat rdma_unregister_mod(rdma_mod_t *mod);
5400a701b1eSRobert Gordon extern rdma_stat rdma_buf_alloc(CONN *, rdma_buf_t *);
5410a701b1eSRobert Gordon extern void rdma_buf_free(CONN *, rdma_buf_t *);
5427c478bd9Sstevel@tonic-gate extern int rdma_modload();
5430a701b1eSRobert Gordon extern bool_t   rdma_get_wchunk(struct svc_req *, iovec_t *, struct clist *);
54451f34d4bSRajkumar Sivaprakasam extern rdma_stat rdma_kwait(void);
545f837ee4aSSiddheshwar Mahesh extern int rdma_setup_read_chunks(struct clist *, uint32_t, int *);
5467c478bd9Sstevel@tonic-gate 
5477c478bd9Sstevel@tonic-gate /*
5487c478bd9Sstevel@tonic-gate  * RDMA XDR
5497c478bd9Sstevel@tonic-gate  */
5507c478bd9Sstevel@tonic-gate extern void xdrrdma_create(XDR *, caddr_t, uint_t, int, struct clist *,
5517c478bd9Sstevel@tonic-gate 	enum xdr_op, CONN *);
5527c478bd9Sstevel@tonic-gate extern void xdrrdma_destroy(XDR *);
5530a701b1eSRobert Gordon 
5547c478bd9Sstevel@tonic-gate extern uint_t xdrrdma_getpos(XDR *);
5557c478bd9Sstevel@tonic-gate extern bool_t xdrrdma_setpos(XDR *, uint_t);
5567c478bd9Sstevel@tonic-gate extern bool_t xdr_clist(XDR *, clist *);
5577c478bd9Sstevel@tonic-gate extern bool_t xdr_do_clist(XDR *, clist **);
5587c478bd9Sstevel@tonic-gate extern uint_t xdr_getbufsize(XDR *);
5590a701b1eSRobert Gordon extern unsigned int xdrrdma_sizeof(xdrproc_t, void *, int, uint_t *, uint_t *);
5600a701b1eSRobert Gordon extern unsigned int xdrrdma_authsize(AUTH *, struct cred *, int);
5610a701b1eSRobert Gordon 
5620a701b1eSRobert Gordon extern void xdrrdma_store_wlist(XDR *, struct clist *);
5630a701b1eSRobert Gordon extern struct clist *xdrrdma_wclist(XDR *);
5640a701b1eSRobert Gordon extern bool_t xdr_decode_reply_wchunk(XDR *, struct clist **);
5650a701b1eSRobert Gordon extern bool_t xdr_decode_wlist(XDR *xdrs, struct clist **, bool_t *);
5660a701b1eSRobert Gordon extern bool_t xdr_decode_wlist_svc(XDR *xdrs, struct clist **, bool_t *,
5670a701b1eSRobert Gordon 	uint32_t *, CONN *);
5680a701b1eSRobert Gordon extern bool_t xdr_encode_rlist_svc(XDR *, clist *);
5690a701b1eSRobert Gordon extern bool_t xdr_encode_wlist(XDR *, clist *);
5700a701b1eSRobert Gordon extern bool_t xdr_encode_reply_wchunk(XDR *, struct clist *,
5710a701b1eSRobert Gordon 		uint32_t seg_array_len);
5720a701b1eSRobert Gordon bool_t xdrrdma_getrdmablk(XDR *, struct clist **, uint_t *,
5730a701b1eSRobert Gordon 	CONN **conn, const uint_t);
574f837ee4aSSiddheshwar Mahesh bool_t xdrrdma_read_from_client(struct clist *, CONN **, uint_t);
575f837ee4aSSiddheshwar Mahesh bool_t xdrrdma_send_read_data(XDR *, uint_t, struct clist *);
5760a701b1eSRobert Gordon bool_t xdrrdma_free_clist(CONN *, struct clist *);
5777c478bd9Sstevel@tonic-gate #endif /* _KERNEL */
5787c478bd9Sstevel@tonic-gate 
5797c478bd9Sstevel@tonic-gate #ifdef __cplusplus
5807c478bd9Sstevel@tonic-gate }
5817c478bd9Sstevel@tonic-gate #endif
5827c478bd9Sstevel@tonic-gate 
5837c478bd9Sstevel@tonic-gate #endif	/* _RPC_RPC_RDMA_H */
584