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