xref: /onnv-gate/usr/src/uts/common/sys/ib/clients/rdsv3/rdsv3.h (revision 12922:c58988eacbb2)
112198SEiji.Ota@Sun.COM /*
212763SGiri.Adari@Sun.COM  * This file contains definitions imported from the OFED rds header rds.h.
312763SGiri.Adari@Sun.COM  * Oracle elects to have and use the contents of rds.h under and
412763SGiri.Adari@Sun.COM  * governed by the OpenIB.org BSD license.
512198SEiji.Ota@Sun.COM  */
612763SGiri.Adari@Sun.COM 
712198SEiji.Ota@Sun.COM /*
812198SEiji.Ota@Sun.COM  * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
912198SEiji.Ota@Sun.COM  */
1012198SEiji.Ota@Sun.COM 
1112198SEiji.Ota@Sun.COM #ifndef _RDSV3_RDSV3_H
1212198SEiji.Ota@Sun.COM #define	_RDSV3_RDSV3_H
1312198SEiji.Ota@Sun.COM 
1412198SEiji.Ota@Sun.COM /*
1512198SEiji.Ota@Sun.COM  * The name of this file is rds.h in ofed.
1612198SEiji.Ota@Sun.COM  */
1712198SEiji.Ota@Sun.COM 
1812198SEiji.Ota@Sun.COM #ifdef __cplusplus
1912198SEiji.Ota@Sun.COM extern "C" {
2012198SEiji.Ota@Sun.COM #endif
2112198SEiji.Ota@Sun.COM 
2212198SEiji.Ota@Sun.COM #include <sys/sunndi.h>
2312198SEiji.Ota@Sun.COM #include <netinet/in.h>
2412198SEiji.Ota@Sun.COM #include <sys/synch.h>
2512198SEiji.Ota@Sun.COM #include <sys/stropts.h>
2612198SEiji.Ota@Sun.COM #include <sys/socket.h>
2712198SEiji.Ota@Sun.COM #include <sys/socketvar.h>
2812198SEiji.Ota@Sun.COM #include <inet/ip.h>
2912198SEiji.Ota@Sun.COM #include <sys/avl.h>
3012198SEiji.Ota@Sun.COM #include <sys/param.h>
3112676SEiji.Ota@Sun.COM #include <sys/time.h>
3212198SEiji.Ota@Sun.COM #include <sys/rds.h>
3312198SEiji.Ota@Sun.COM 
3412198SEiji.Ota@Sun.COM #include <sys/ib/ibtl/ibti.h>
3512198SEiji.Ota@Sun.COM #include <sys/ib/clients/of/rdma/ib_verbs.h>
3612198SEiji.Ota@Sun.COM #include <sys/ib/clients/of/rdma/ib_addr.h>
3712198SEiji.Ota@Sun.COM #include <sys/ib/clients/of/rdma/rdma_cm.h>
3812198SEiji.Ota@Sun.COM #include <sys/ib/clients/rdsv3/rdsv3_impl.h>
3912198SEiji.Ota@Sun.COM #include <sys/ib/clients/rdsv3/info.h>
4012198SEiji.Ota@Sun.COM 
41*12922SGiri.Adari@Sun.COM #include <sys/cpuvar.h>
42*12922SGiri.Adari@Sun.COM #include <sys/disp.h>
43*12922SGiri.Adari@Sun.COM 
4412198SEiji.Ota@Sun.COM #define	NIPQUAD(addr)					\
4512198SEiji.Ota@Sun.COM 	(unsigned char)((ntohl(addr) >> 24) & 0xFF),	\
4612198SEiji.Ota@Sun.COM 	(unsigned char)((ntohl(addr) >> 16) & 0xFF),	\
4712198SEiji.Ota@Sun.COM 	(unsigned char)((ntohl(addr) >>  8) & 0xFF),	\
4812198SEiji.Ota@Sun.COM 	(unsigned char)(ntohl(addr) & 0xFF)
4912198SEiji.Ota@Sun.COM 
5012198SEiji.Ota@Sun.COM /*
5112198SEiji.Ota@Sun.COM  * RDS Network protocol version
5212198SEiji.Ota@Sun.COM  */
5312198SEiji.Ota@Sun.COM #define	RDS_PROTOCOL_3_0	0x0300
5412198SEiji.Ota@Sun.COM #define	RDS_PROTOCOL_3_1	0x0301
5512198SEiji.Ota@Sun.COM #define	RDS_PROTOCOL_VERSION	RDS_PROTOCOL_3_1
5612198SEiji.Ota@Sun.COM #define	RDS_PROTOCOL_MAJOR(v)	((v) >> 8)
5712198SEiji.Ota@Sun.COM #define	RDS_PROTOCOL_MINOR(v)	((v) & 255)
5812198SEiji.Ota@Sun.COM #define	RDS_PROTOCOL(maj, min)	(((maj) << 8) | min)
5912198SEiji.Ota@Sun.COM 
6012198SEiji.Ota@Sun.COM /*
6112198SEiji.Ota@Sun.COM  * XXX randomly chosen, but at least seems to be unused:
6212198SEiji.Ota@Sun.COM  * #               18464-18768 Unassigned
6312198SEiji.Ota@Sun.COM  * We should do better.  We want a reserved port to discourage unpriv'ed
6412198SEiji.Ota@Sun.COM  * userspace from listening.
6512198SEiji.Ota@Sun.COM  *
6612198SEiji.Ota@Sun.COM  * port 18633 was the version that had ack frames on the wire.
6712198SEiji.Ota@Sun.COM  */
6812198SEiji.Ota@Sun.COM #define	RDSV3_PORT	18634
6912198SEiji.Ota@Sun.COM 
7012676SEiji.Ota@Sun.COM #define	RDSV3_REAPER_WAIT_SECS		(5*60)
7112676SEiji.Ota@Sun.COM #define	RDSV3_REAPER_WAIT_JIFFIES	SEC_TO_TICK(RDSV3_REAPER_WAIT_SECS)
7212676SEiji.Ota@Sun.COM 
7312198SEiji.Ota@Sun.COM static inline ulong_t
ceil(ulong_t x,ulong_t y)7412198SEiji.Ota@Sun.COM ceil(ulong_t x, ulong_t y)
7512198SEiji.Ota@Sun.COM {
7612198SEiji.Ota@Sun.COM 	return ((x + y - 1) / y);
7712198SEiji.Ota@Sun.COM }
7812198SEiji.Ota@Sun.COM 
7912198SEiji.Ota@Sun.COM #define	RDSV3_FRAG_SHIFT	12
8012198SEiji.Ota@Sun.COM #define	RDSV3_FRAG_SIZE	((unsigned int)(1 << RDSV3_FRAG_SHIFT))
8112198SEiji.Ota@Sun.COM 
8212198SEiji.Ota@Sun.COM #define	RDSV3_CONG_MAP_BYTES	(65536 / 8)
8312198SEiji.Ota@Sun.COM #define	RDSV3_CONG_MAP_LONGS	(RDSV3_CONG_MAP_BYTES / sizeof (unsigned long))
8412198SEiji.Ota@Sun.COM #define	RDSV3_CONG_MAP_PAGES	(RDSV3_CONG_MAP_BYTES / PAGE_SIZE)
8512198SEiji.Ota@Sun.COM #define	RDSV3_CONG_MAP_PAGE_BITS	(PAGE_SIZE * 8)
8612198SEiji.Ota@Sun.COM 
8712198SEiji.Ota@Sun.COM struct rdsv3_cong_map {
8812198SEiji.Ota@Sun.COM 	struct avl_node		m_rb_node;
8912198SEiji.Ota@Sun.COM 	uint32_be_t		m_addr;
9012198SEiji.Ota@Sun.COM 	rdsv3_wait_queue_t	m_waitq;
9112198SEiji.Ota@Sun.COM 	struct list		m_conn_list;
9212198SEiji.Ota@Sun.COM 	unsigned long		m_page_addrs[RDSV3_CONG_MAP_PAGES];
9312198SEiji.Ota@Sun.COM };
9412198SEiji.Ota@Sun.COM 
9512198SEiji.Ota@Sun.COM /*
9612198SEiji.Ota@Sun.COM  * This is how we will track the connection state:
9712198SEiji.Ota@Sun.COM  * A connection is always in one of the following
9812198SEiji.Ota@Sun.COM  * states. Updates to the state are atomic and imply
9912198SEiji.Ota@Sun.COM  * a memory barrier.
10012198SEiji.Ota@Sun.COM  */
10112198SEiji.Ota@Sun.COM enum {
10212198SEiji.Ota@Sun.COM 	RDSV3_CONN_DOWN = 0,
10312198SEiji.Ota@Sun.COM 	RDSV3_CONN_CONNECTING,
10412198SEiji.Ota@Sun.COM 	RDSV3_CONN_DISCONNECTING,
10512198SEiji.Ota@Sun.COM 	RDSV3_CONN_UP,
10612198SEiji.Ota@Sun.COM 	RDSV3_CONN_ERROR,
10712198SEiji.Ota@Sun.COM };
10812198SEiji.Ota@Sun.COM 
10912198SEiji.Ota@Sun.COM /* Bits for c_flags */
11012198SEiji.Ota@Sun.COM #define	RDSV3_LL_SEND_FULL	0
11112198SEiji.Ota@Sun.COM #define	RDSV3_RECONNECT_PENDING	1
11212198SEiji.Ota@Sun.COM 
11312198SEiji.Ota@Sun.COM struct rdsv3_connection {
11412198SEiji.Ota@Sun.COM 	struct avl_node		c_hash_node;
11512895SGiri.Adari@Sun.COM 	struct rdsv3_ip_bucket	*c_bucketp;
11612198SEiji.Ota@Sun.COM 	uint32_be_t		c_laddr;
11712198SEiji.Ota@Sun.COM 	uint32_be_t		c_faddr;
11812198SEiji.Ota@Sun.COM 	unsigned int		c_loopback:1;
11912198SEiji.Ota@Sun.COM 	struct rdsv3_connection	*c_passive;
12012198SEiji.Ota@Sun.COM 
12112198SEiji.Ota@Sun.COM 	struct rdsv3_cong_map	*c_lcong;
12212198SEiji.Ota@Sun.COM 	struct rdsv3_cong_map	*c_fcong;
12312198SEiji.Ota@Sun.COM 
12412198SEiji.Ota@Sun.COM 	struct mutex		c_send_lock;    /* protect send ring */
12512676SEiji.Ota@Sun.COM 	atomic_t		c_send_generation;
12612676SEiji.Ota@Sun.COM 	atomic_t		c_senders;
12712676SEiji.Ota@Sun.COM 
12812198SEiji.Ota@Sun.COM 	struct rdsv3_message	*c_xmit_rm;
12912198SEiji.Ota@Sun.COM 	unsigned long		c_xmit_sg;
13012198SEiji.Ota@Sun.COM 	unsigned int		c_xmit_hdr_off;
13112198SEiji.Ota@Sun.COM 	unsigned int		c_xmit_data_off;
13212198SEiji.Ota@Sun.COM 	unsigned int		c_xmit_rdma_sent;
13312198SEiji.Ota@Sun.COM 
13412198SEiji.Ota@Sun.COM 	kmutex_t		c_lock;		/* protect msg queues */
13512198SEiji.Ota@Sun.COM 	uint64_t		c_next_tx_seq;
13612198SEiji.Ota@Sun.COM 	struct list		c_send_queue;
13712198SEiji.Ota@Sun.COM 	struct list		c_retrans;
13812198SEiji.Ota@Sun.COM 
13912198SEiji.Ota@Sun.COM 	uint64_t		c_next_rx_seq;
14012198SEiji.Ota@Sun.COM 
14112198SEiji.Ota@Sun.COM 	struct rdsv3_transport	*c_trans;
14212198SEiji.Ota@Sun.COM 	void			*c_transport_data;
14312198SEiji.Ota@Sun.COM 
14412198SEiji.Ota@Sun.COM 	atomic_t		c_state;
14512198SEiji.Ota@Sun.COM 	unsigned long		c_flags;
14612198SEiji.Ota@Sun.COM 	unsigned long		c_reconnect_jiffies;
14712676SEiji.Ota@Sun.COM 	clock_t			c_last_connect_jiffies;
14812676SEiji.Ota@Sun.COM 
14912198SEiji.Ota@Sun.COM 	struct rdsv3_delayed_work_s	c_send_w;
15012198SEiji.Ota@Sun.COM 	struct rdsv3_delayed_work_s	c_recv_w;
15112198SEiji.Ota@Sun.COM 	struct rdsv3_delayed_work_s	c_conn_w;
15212676SEiji.Ota@Sun.COM 	struct rdsv3_delayed_work_s	c_reap_w;
15312198SEiji.Ota@Sun.COM 	struct rdsv3_work_s	c_down_w;
15412198SEiji.Ota@Sun.COM 	struct mutex		c_cm_lock;	/* protect conn state & cm */
15512198SEiji.Ota@Sun.COM 
15612198SEiji.Ota@Sun.COM 	struct list_node	c_map_item;
15712198SEiji.Ota@Sun.COM 	unsigned long		c_map_queued;
15812198SEiji.Ota@Sun.COM 	unsigned long		c_map_offset;
15912198SEiji.Ota@Sun.COM 	unsigned long		c_map_bytes;
16012198SEiji.Ota@Sun.COM 
16112198SEiji.Ota@Sun.COM 	unsigned int		c_unacked_packets;
16212198SEiji.Ota@Sun.COM 	unsigned int		c_unacked_bytes;
16312198SEiji.Ota@Sun.COM 
16412198SEiji.Ota@Sun.COM 	/* Protocol version */
16512198SEiji.Ota@Sun.COM 	unsigned int		c_version;
16612198SEiji.Ota@Sun.COM };
16712198SEiji.Ota@Sun.COM 
16812198SEiji.Ota@Sun.COM #define	RDSV3_FLAG_CONG_BITMAP		0x01
16912198SEiji.Ota@Sun.COM #define	RDSV3_FLAG_ACK_REQUIRED		0x02
17012198SEiji.Ota@Sun.COM #define	RDSV3_FLAG_RETRANSMITTED	0x04
17112414SEiji.Ota@Sun.COM #define	RDSV3_MAX_ADV_CREDIT		127
17212198SEiji.Ota@Sun.COM 
17312198SEiji.Ota@Sun.COM /*
17412198SEiji.Ota@Sun.COM  * Maximum space available for extension headers.
17512198SEiji.Ota@Sun.COM  */
17612198SEiji.Ota@Sun.COM #define	RDSV3_HEADER_EXT_SPACE    16
17712198SEiji.Ota@Sun.COM 
17812198SEiji.Ota@Sun.COM struct rdsv3_header {
17912198SEiji.Ota@Sun.COM 	uint64_be_t	h_sequence;
18012198SEiji.Ota@Sun.COM 	uint64_be_t	h_ack;
18112198SEiji.Ota@Sun.COM 	uint32_be_t	h_len;
18212198SEiji.Ota@Sun.COM 	uint16_be_t	h_sport;
18312198SEiji.Ota@Sun.COM 	uint16_be_t	h_dport;
18412198SEiji.Ota@Sun.COM 	uint8_t		h_flags;
18512198SEiji.Ota@Sun.COM 	uint8_t		h_credit;
18612198SEiji.Ota@Sun.COM 	uint8_t		h_padding[4];
18712198SEiji.Ota@Sun.COM 	uint16_be_t	h_csum;
18812198SEiji.Ota@Sun.COM 
18912198SEiji.Ota@Sun.COM 	uint8_t		h_exthdr[RDSV3_HEADER_EXT_SPACE];
19012198SEiji.Ota@Sun.COM };
19112198SEiji.Ota@Sun.COM 
19212198SEiji.Ota@Sun.COM /* Reserved - indicates end of extensions */
19312198SEiji.Ota@Sun.COM #define	RDSV3_EXTHDR_NONE		0
19412198SEiji.Ota@Sun.COM 
19512198SEiji.Ota@Sun.COM /*
19612198SEiji.Ota@Sun.COM  * This extension header is included in the very
19712198SEiji.Ota@Sun.COM  * first message that is sent on a new connection,
19812198SEiji.Ota@Sun.COM  * and identifies the protocol level. This will help
19912198SEiji.Ota@Sun.COM  * rolling updates if a future change requires breaking
20012198SEiji.Ota@Sun.COM  * the protocol.
20112198SEiji.Ota@Sun.COM  */
20212198SEiji.Ota@Sun.COM #define	RDSV3_EXTHDR_VERSION	1
20312198SEiji.Ota@Sun.COM struct rdsv3_ext_header_version {
20412198SEiji.Ota@Sun.COM 	uint32_be_t	h_version;
20512198SEiji.Ota@Sun.COM };
20612198SEiji.Ota@Sun.COM 
20712198SEiji.Ota@Sun.COM /*
20812198SEiji.Ota@Sun.COM  * This extension header is included in the RDS message
20912198SEiji.Ota@Sun.COM  * chasing an RDMA operation.
21012198SEiji.Ota@Sun.COM  */
21112198SEiji.Ota@Sun.COM #define	RDSV3_EXTHDR_RDMA		2
21212198SEiji.Ota@Sun.COM struct rdsv3_ext_header_rdma {
21312198SEiji.Ota@Sun.COM 	uint32_be_t	h_rdma_rkey;
21412198SEiji.Ota@Sun.COM };
21512198SEiji.Ota@Sun.COM 
21612198SEiji.Ota@Sun.COM /*
21712198SEiji.Ota@Sun.COM  * This extension header tells the peer about the
21812198SEiji.Ota@Sun.COM  * destination <R_Key,offset> of the requested RDMA
21912198SEiji.Ota@Sun.COM  * operation.
22012198SEiji.Ota@Sun.COM  */
22112198SEiji.Ota@Sun.COM #define	RDSV3_EXTHDR_RDMA_DEST    3
22212198SEiji.Ota@Sun.COM struct rdsv3_ext_header_rdma_dest {
22312198SEiji.Ota@Sun.COM 	uint32_be_t		h_rdma_rkey;
22412198SEiji.Ota@Sun.COM 	uint32_be_t		h_rdma_offset;
22512198SEiji.Ota@Sun.COM };
22612198SEiji.Ota@Sun.COM 
22712198SEiji.Ota@Sun.COM #define	__RDSV3_EXTHDR_MAX	16 /* for now */
22812198SEiji.Ota@Sun.COM 
22912198SEiji.Ota@Sun.COM struct rdsv3_incoming {
23012198SEiji.Ota@Sun.COM 	atomic_t		i_refcount;
23112198SEiji.Ota@Sun.COM 	struct list_node	i_item;
23212198SEiji.Ota@Sun.COM 	struct rdsv3_connection	*i_conn;
23312198SEiji.Ota@Sun.COM 	struct rdsv3_header	i_hdr;
23412198SEiji.Ota@Sun.COM 	unsigned long		i_rx_jiffies;
23512198SEiji.Ota@Sun.COM 	uint32_be_t		i_saddr;
23612198SEiji.Ota@Sun.COM 
23712863SEiji.Ota@Sun.COM 	rds_rdma_cookie_t	i_rdma_cookie;
23812198SEiji.Ota@Sun.COM };
23912198SEiji.Ota@Sun.COM 
24012198SEiji.Ota@Sun.COM /*
24112198SEiji.Ota@Sun.COM  * m_sock_item and m_conn_item are on lists that are serialized under
24212198SEiji.Ota@Sun.COM  * conn->c_lock.  m_sock_item has additional meaning in that once it is empty
24312198SEiji.Ota@Sun.COM  * the message will not be put back on the retransmit list after being sent.
24412198SEiji.Ota@Sun.COM  * messages that are canceled while being sent rely on this.
24512198SEiji.Ota@Sun.COM  *
24612198SEiji.Ota@Sun.COM  * m_inc is used by loopback so that it can pass an incoming message straight
24712198SEiji.Ota@Sun.COM  * back up into the rx path.  It embeds a wire header which is also used by
24812198SEiji.Ota@Sun.COM  * the send path, which is kind of awkward.
24912198SEiji.Ota@Sun.COM  *
25012198SEiji.Ota@Sun.COM  * m_sock_item indicates the message's presence on a socket's send or receive
25112198SEiji.Ota@Sun.COM  * queue.  m_rs will point to that socket.
25212198SEiji.Ota@Sun.COM  *
25312198SEiji.Ota@Sun.COM  * m_daddr is used by cancellation to prune messages to a given destination.
25412198SEiji.Ota@Sun.COM  *
25512198SEiji.Ota@Sun.COM  * The RDS_MSG_ON_SOCK and RDS_MSG_ON_CONN flags are used to avoid lock
25612198SEiji.Ota@Sun.COM  * nesting.  As paths iterate over messages on a sock, or conn, they must
25712198SEiji.Ota@Sun.COM  * also lock the conn, or sock, to remove the message from those lists too.
25812198SEiji.Ota@Sun.COM  * Testing the flag to determine if the message is still on the lists lets
25912198SEiji.Ota@Sun.COM  * us avoid testing the list_head directly.  That means each path can use
26012198SEiji.Ota@Sun.COM  * the message's list_head to keep it on a local list while juggling locks
26112198SEiji.Ota@Sun.COM  * without confusing the other path.
26212198SEiji.Ota@Sun.COM  *
26312198SEiji.Ota@Sun.COM  * m_ack_seq is an optional field set by transports who need a different
26412198SEiji.Ota@Sun.COM  * sequence number range to invalidate.  They can use this in a callback
26512198SEiji.Ota@Sun.COM  * that they pass to rdsv3_send_drop_acked() to see if each message has been
26612198SEiji.Ota@Sun.COM  * acked.  The HAS_ACK_SEQ flag can be used to detect messages which haven't
26712198SEiji.Ota@Sun.COM  * had ack_seq set yet.
26812198SEiji.Ota@Sun.COM  */
26912198SEiji.Ota@Sun.COM #define	RDSV3_MSG_ON_SOCK		1
27012198SEiji.Ota@Sun.COM #define	RDSV3_MSG_ON_CONN		2
27112198SEiji.Ota@Sun.COM #define	RDSV3_MSG_HAS_ACK_SEQ		3
27212198SEiji.Ota@Sun.COM #define	RDSV3_MSG_ACK_REQUIRED		4
27312198SEiji.Ota@Sun.COM #define	RDSV3_MSG_RETRANSMITTED		5
27412198SEiji.Ota@Sun.COM #define	RDSV3_MSG_MAPPED		6
27512198SEiji.Ota@Sun.COM #define	RDSV3_MSG_PAGEVEC		7
27612198SEiji.Ota@Sun.COM 
27712198SEiji.Ota@Sun.COM struct rdsv3_message {
27812198SEiji.Ota@Sun.COM 	atomic_t		m_refcount;
27912198SEiji.Ota@Sun.COM 	struct list_node	m_sock_item;
28012198SEiji.Ota@Sun.COM 	struct list_node	m_conn_item;
28112198SEiji.Ota@Sun.COM 	struct rdsv3_incoming	m_inc;
28212198SEiji.Ota@Sun.COM 	uint64_t		m_ack_seq;
28312198SEiji.Ota@Sun.COM 	uint32_be_t		m_daddr;
28412198SEiji.Ota@Sun.COM 	unsigned long		m_flags;
28512198SEiji.Ota@Sun.COM 
28612198SEiji.Ota@Sun.COM 	/*
28712198SEiji.Ota@Sun.COM 	 * Never access m_rs without holding m_rs_lock.
28812198SEiji.Ota@Sun.COM 	 * Lock nesting is
28912198SEiji.Ota@Sun.COM 	 *  rm->m_rs_lock
29012198SEiji.Ota@Sun.COM 	 *   -> rs->rs_lock
29112198SEiji.Ota@Sun.COM 	 */
29212198SEiji.Ota@Sun.COM 	kmutex_t		m_rs_lock;
29312676SEiji.Ota@Sun.COM 	rdsv3_wait_queue_t	m_flush_wait;
29412676SEiji.Ota@Sun.COM 
29512198SEiji.Ota@Sun.COM 	struct rdsv3_sock	*m_rs;
29612198SEiji.Ota@Sun.COM 	struct rdsv3_rdma_op	*m_rdma_op;
29712863SEiji.Ota@Sun.COM 	rds_rdma_cookie_t	m_rdma_cookie;
29812198SEiji.Ota@Sun.COM 	struct rdsv3_mr		*m_rdma_mr;
29912198SEiji.Ota@Sun.COM 	unsigned int		m_nents;
30012198SEiji.Ota@Sun.COM 	unsigned int		m_count;
30112198SEiji.Ota@Sun.COM 	struct rdsv3_scatterlist	m_sg[1];
30212198SEiji.Ota@Sun.COM };
30312198SEiji.Ota@Sun.COM 
30412198SEiji.Ota@Sun.COM /*
30512198SEiji.Ota@Sun.COM  * The RDS notifier is used (optionally) to tell the application about
30612198SEiji.Ota@Sun.COM  * completed RDMA operations. Rather than keeping the whole rds message
30712198SEiji.Ota@Sun.COM  * around on the queue, we allocate a small notifier that is put on the
30812198SEiji.Ota@Sun.COM  * socket's notifier_list. Notifications are delivered to the application
30912198SEiji.Ota@Sun.COM  * through control messages.
31012198SEiji.Ota@Sun.COM  */
31112198SEiji.Ota@Sun.COM struct rdsv3_notifier {
31212198SEiji.Ota@Sun.COM 	list_node_t	n_list;
31312198SEiji.Ota@Sun.COM 	uint64_t	n_user_token;
31412198SEiji.Ota@Sun.COM 	int		n_status;
31512198SEiji.Ota@Sun.COM };
31612198SEiji.Ota@Sun.COM 
31712198SEiji.Ota@Sun.COM /*
31812198SEiji.Ota@Sun.COM  * struct rdsv3_transport -  transport specific behavioural hooks
31912198SEiji.Ota@Sun.COM  *
32012198SEiji.Ota@Sun.COM  * @xmit: .xmit is called by rdsv3_send_xmit() to tell the transport to send
32112198SEiji.Ota@Sun.COM  *	  part of a message.  The caller serializes on the send_sem so this
32212198SEiji.Ota@Sun.COM  *	  doesn't need to be reentrant for a given conn.  The header must be
32312198SEiji.Ota@Sun.COM  *	  sent before the data payload.  .xmit must be prepared to send a
32412198SEiji.Ota@Sun.COM  *	  message with no data payload.  .xmit should return the number of
32512198SEiji.Ota@Sun.COM  *	  bytes that were sent down the connection, including header bytes.
32612198SEiji.Ota@Sun.COM  *	  Returning 0 tells the caller that it doesn't need to perform any
32712198SEiji.Ota@Sun.COM  *	  additional work now.  This is usually the case when the transport has
32812198SEiji.Ota@Sun.COM  *	  filled the sending queue for its connection and will handle
32912198SEiji.Ota@Sun.COM  *	  triggering the rds thread to continue the send when space becomes
33012198SEiji.Ota@Sun.COM  *	  available.  Returning -EAGAIN tells the caller to retry the send
33112198SEiji.Ota@Sun.COM  *	  immediately.  Returning -ENOMEM tells the caller to retry the send at
33212198SEiji.Ota@Sun.COM  *	  some point in the future.
33312198SEiji.Ota@Sun.COM  *
33412198SEiji.Ota@Sun.COM  * @conn_shutdown: conn_shutdown stops traffic on the given connection.  Once
33512198SEiji.Ota@Sun.COM  *		   it returns the connection can not call rdsv3_recv_incoming().
33612198SEiji.Ota@Sun.COM  *		   This will only be called once after conn_connect returns
33712198SEiji.Ota@Sun.COM  *		   non-zero success and will The caller serializes this with
33812198SEiji.Ota@Sun.COM  *		   the send and connecting paths (xmit_* and conn_*).  The
33912198SEiji.Ota@Sun.COM  *		   transport is responsible for other serialization, including
34012198SEiji.Ota@Sun.COM  *		   rdsv3_recv_incoming().  This is called in process context but
34112198SEiji.Ota@Sun.COM  *		   should try hard not to block.
34212198SEiji.Ota@Sun.COM  *
34312198SEiji.Ota@Sun.COM  * @xmit_cong_map: This asks the transport to send the local bitmap down the
34412198SEiji.Ota@Sun.COM  *		   given connection.  XXX get a better story about the bitmap
34512198SEiji.Ota@Sun.COM  *		   flag and header.
34612198SEiji.Ota@Sun.COM  */
34712198SEiji.Ota@Sun.COM 
34812414SEiji.Ota@Sun.COM #define	RDS_TRANS_IB    0
34912414SEiji.Ota@Sun.COM #define	RDS_TRANS_IWARP 1
35012414SEiji.Ota@Sun.COM #define	RDS_TRANS_TCP   2
35112414SEiji.Ota@Sun.COM #define	RDS_TRANS_COUNT 3
35212414SEiji.Ota@Sun.COM 
35312198SEiji.Ota@Sun.COM struct rdsv3_transport {
35412414SEiji.Ota@Sun.COM 	char			t_name[TRANSNAMSIZ];
35512198SEiji.Ota@Sun.COM 	struct list_node	t_item;
35612414SEiji.Ota@Sun.COM 	unsigned int		t_type;
35712198SEiji.Ota@Sun.COM 	unsigned int		t_prefer_loopback:1;
35812198SEiji.Ota@Sun.COM 
35912198SEiji.Ota@Sun.COM 	int (*laddr_check)(uint32_be_t addr);
36012198SEiji.Ota@Sun.COM 	int (*conn_alloc)(struct rdsv3_connection *conn, int gfp);
36112198SEiji.Ota@Sun.COM 	void (*conn_free)(void *data);
36212198SEiji.Ota@Sun.COM 	int (*conn_connect)(struct rdsv3_connection *conn);
36312198SEiji.Ota@Sun.COM 	void (*conn_shutdown)(struct rdsv3_connection *conn);
36412198SEiji.Ota@Sun.COM 	void (*xmit_prepare)(struct rdsv3_connection *conn);
36512198SEiji.Ota@Sun.COM 	void (*xmit_complete)(struct rdsv3_connection *conn);
36612198SEiji.Ota@Sun.COM 	int (*xmit)(struct rdsv3_connection *conn, struct rdsv3_message *rm,
36712198SEiji.Ota@Sun.COM 	    unsigned int hdr_off, unsigned int sg, unsigned int off);
36812198SEiji.Ota@Sun.COM 	int (*xmit_cong_map)(struct rdsv3_connection *conn,
36912198SEiji.Ota@Sun.COM 	    struct rdsv3_cong_map *map, unsigned long offset);
37012198SEiji.Ota@Sun.COM 	int (*xmit_rdma)(struct rdsv3_connection *conn,
37112198SEiji.Ota@Sun.COM 	    struct rdsv3_rdma_op *op);
37212198SEiji.Ota@Sun.COM 	int (*recv)(struct rdsv3_connection *conn);
37312198SEiji.Ota@Sun.COM 	int (*inc_copy_to_user)(struct rdsv3_incoming *inc, uio_t *uio,
37412198SEiji.Ota@Sun.COM 	    size_t size);
37512198SEiji.Ota@Sun.COM 	void (*inc_free)(struct rdsv3_incoming *inc);
37612198SEiji.Ota@Sun.COM 
37712198SEiji.Ota@Sun.COM 	int (*cm_handle_connect)(struct rdma_cm_id *cm_id,
37812198SEiji.Ota@Sun.COM 	    struct rdma_cm_event *event);
37912198SEiji.Ota@Sun.COM 	int (*cm_initiate_connect)(struct rdma_cm_id *cm_id);
38012198SEiji.Ota@Sun.COM 	void (*cm_connect_complete)(struct rdsv3_connection *conn,
38112198SEiji.Ota@Sun.COM 	    struct rdma_cm_event *event);
38212198SEiji.Ota@Sun.COM 
38312198SEiji.Ota@Sun.COM 	unsigned int (*stats_info_copy)(struct rdsv3_info_iterator *iter,
38412198SEiji.Ota@Sun.COM 	    unsigned int avail);
38512198SEiji.Ota@Sun.COM 	void (*exit)(void);
38612863SEiji.Ota@Sun.COM 	void *(*get_mr)(struct rds_iovec *sg, unsigned long nr_sg,
38712198SEiji.Ota@Sun.COM 	    struct rdsv3_sock *rs, uint32_t *key_ret);
38812198SEiji.Ota@Sun.COM 	void (*sync_mr)(void *trans_private, int direction);
38912198SEiji.Ota@Sun.COM 	void (*free_mr)(void *trans_private, int invalidate);
39012198SEiji.Ota@Sun.COM 	void (*flush_mrs)(void);
39112198SEiji.Ota@Sun.COM };
39212198SEiji.Ota@Sun.COM 
39312198SEiji.Ota@Sun.COM struct rdsv3_sock {
39412198SEiji.Ota@Sun.COM 	struct rsock		*rs_sk;
39512198SEiji.Ota@Sun.COM 	uint64_t		rs_user_addr;
39612198SEiji.Ota@Sun.COM 	uint64_t		rs_user_bytes;
39712198SEiji.Ota@Sun.COM 
39812198SEiji.Ota@Sun.COM 	/*
39912198SEiji.Ota@Sun.COM 	 * bound_addr used for both incoming and outgoing, no INADDR_ANY
40012198SEiji.Ota@Sun.COM 	 * support.
40112198SEiji.Ota@Sun.COM 	 */
40212198SEiji.Ota@Sun.COM 	struct avl_node		rs_bound_node;
40312198SEiji.Ota@Sun.COM 	uint32_be_t		rs_bound_addr;
40412198SEiji.Ota@Sun.COM 	uint32_be_t		rs_conn_addr;
40512198SEiji.Ota@Sun.COM 	uint16_be_t		rs_bound_port;
40612198SEiji.Ota@Sun.COM 	uint16_be_t		rs_conn_port;
40712198SEiji.Ota@Sun.COM 
40812198SEiji.Ota@Sun.COM 	/*
40912198SEiji.Ota@Sun.COM 	 * This is only used to communicate the transport between bind and
41012198SEiji.Ota@Sun.COM 	 * initiating connections. All other trans use is referenced through
41112198SEiji.Ota@Sun.COM 	 * the connection.
41212198SEiji.Ota@Sun.COM 	 */
41312198SEiji.Ota@Sun.COM 	struct rdsv3_transport	*rs_transport;
41412198SEiji.Ota@Sun.COM 
41512198SEiji.Ota@Sun.COM 	/*
41612198SEiji.Ota@Sun.COM 	 * rdsv3_sendmsg caches the conn it used the last time around.
41712198SEiji.Ota@Sun.COM 	 * This helps avoid costly lookups.
41812198SEiji.Ota@Sun.COM 	 */
41912198SEiji.Ota@Sun.COM 	struct rdsv3_connection	*rs_conn;
42012198SEiji.Ota@Sun.COM 	kmutex_t 		rs_conn_lock;
42112198SEiji.Ota@Sun.COM 
42212198SEiji.Ota@Sun.COM 	/* flag indicating we were congested or not */
42312198SEiji.Ota@Sun.COM 	int			rs_congested;
42412414SEiji.Ota@Sun.COM 	/* seen congestion (ENOBUFS) when sending? */
42512414SEiji.Ota@Sun.COM 	int			rs_seen_congestion;
42612676SEiji.Ota@Sun.COM 	kmutex_t 		rs_congested_lock;
42712676SEiji.Ota@Sun.COM 	kcondvar_t		rs_congested_cv;
42812198SEiji.Ota@Sun.COM 
42912198SEiji.Ota@Sun.COM 	/* rs_lock protects all these adjacent members before the newline */
43012198SEiji.Ota@Sun.COM 	kmutex_t		rs_lock;
43112198SEiji.Ota@Sun.COM 	struct list		rs_send_queue;
43212198SEiji.Ota@Sun.COM 	uint32_t		rs_snd_bytes;
43312198SEiji.Ota@Sun.COM 	int			rs_rcv_bytes;
43412198SEiji.Ota@Sun.COM 	/* currently used for failed RDMAs */
43512198SEiji.Ota@Sun.COM 	struct list		rs_notify_queue;
43612198SEiji.Ota@Sun.COM 
43712198SEiji.Ota@Sun.COM 	/*
43812198SEiji.Ota@Sun.COM 	 * Congestion wake_up. If rs_cong_monitor is set, we use cong_mask
43912198SEiji.Ota@Sun.COM 	 * to decide whether the application should be woken up.
44012198SEiji.Ota@Sun.COM 	 * If not set, we use rs_cong_track to find out whether a cong map
44112198SEiji.Ota@Sun.COM 	 * update arrived.
44212198SEiji.Ota@Sun.COM 	 */
44312198SEiji.Ota@Sun.COM 	uint64_t		rs_cong_mask;
44412198SEiji.Ota@Sun.COM 	uint64_t		rs_cong_notify;
44512198SEiji.Ota@Sun.COM 	struct list_node	rs_cong_list;
44612198SEiji.Ota@Sun.COM 	unsigned long		rs_cong_track;
44712198SEiji.Ota@Sun.COM 
44812198SEiji.Ota@Sun.COM 	/*
44912198SEiji.Ota@Sun.COM 	 * rs_recv_lock protects the receive queue, and is
45012198SEiji.Ota@Sun.COM 	 * used to serialize with rdsv3_release.
45112198SEiji.Ota@Sun.COM 	 */
45212198SEiji.Ota@Sun.COM 	krwlock_t		rs_recv_lock;
45312198SEiji.Ota@Sun.COM 	struct list		rs_recv_queue;
45412198SEiji.Ota@Sun.COM 
45512198SEiji.Ota@Sun.COM 	/* just for stats reporting */
45612198SEiji.Ota@Sun.COM 	struct list_node	rs_item;
45712198SEiji.Ota@Sun.COM 
45812198SEiji.Ota@Sun.COM 	/* these have their own lock */
45912198SEiji.Ota@Sun.COM 	kmutex_t		rs_rdma_lock;
46012198SEiji.Ota@Sun.COM 	struct avl_tree		rs_rdma_keys;
46112198SEiji.Ota@Sun.COM 
46212198SEiji.Ota@Sun.COM 	/* Socket options - in case there will be more */
46312198SEiji.Ota@Sun.COM 	unsigned char		rs_recverr,
46412198SEiji.Ota@Sun.COM 				rs_cong_monitor;
46512198SEiji.Ota@Sun.COM 
46612198SEiji.Ota@Sun.COM 	cred_t			*rs_cred;
46712198SEiji.Ota@Sun.COM 	zoneid_t		rs_zoneid;
46812198SEiji.Ota@Sun.COM };
46912198SEiji.Ota@Sun.COM 
47012228SEiji.Ota@Sun.COM static inline struct rdsv3_sock *
rdsv3_sk_to_rs(const struct rsock * sk)47112198SEiji.Ota@Sun.COM rdsv3_sk_to_rs(const struct rsock *sk)
47212198SEiji.Ota@Sun.COM {
47312198SEiji.Ota@Sun.COM 	return ((struct rdsv3_sock *)sk->sk_protinfo);
47412198SEiji.Ota@Sun.COM }
47512198SEiji.Ota@Sun.COM 
47612228SEiji.Ota@Sun.COM static inline struct rsock *
rdsv3_rs_to_sk(const struct rdsv3_sock * rs)47712198SEiji.Ota@Sun.COM rdsv3_rs_to_sk(const struct rdsv3_sock *rs)
47812198SEiji.Ota@Sun.COM {
47912198SEiji.Ota@Sun.COM 	return ((struct rsock *)rs->rs_sk);
48012198SEiji.Ota@Sun.COM }
48112198SEiji.Ota@Sun.COM 
48212198SEiji.Ota@Sun.COM /*
48312198SEiji.Ota@Sun.COM  * The stack assigns sk_sndbuf and sk_rcvbuf to twice the specified value
48412198SEiji.Ota@Sun.COM  * to account for overhead.  We don't account for overhead, we just apply
48512198SEiji.Ota@Sun.COM  * the number of payload bytes to the specified value.
48612198SEiji.Ota@Sun.COM  */
48712228SEiji.Ota@Sun.COM static inline int
rdsv3_sk_sndbuf(struct rdsv3_sock * rs)48812198SEiji.Ota@Sun.COM rdsv3_sk_sndbuf(struct rdsv3_sock *rs)
48912198SEiji.Ota@Sun.COM {
49012198SEiji.Ota@Sun.COM 	/* XXX */
49112198SEiji.Ota@Sun.COM 	return (rdsv3_rs_to_sk(rs)->sk_sndbuf);
49212198SEiji.Ota@Sun.COM }
49312198SEiji.Ota@Sun.COM 
49412228SEiji.Ota@Sun.COM static inline int
rdsv3_sk_rcvbuf(struct rdsv3_sock * rs)49512198SEiji.Ota@Sun.COM rdsv3_sk_rcvbuf(struct rdsv3_sock *rs)
49612198SEiji.Ota@Sun.COM {
49712198SEiji.Ota@Sun.COM 	/* XXX */
49812198SEiji.Ota@Sun.COM 	return (rdsv3_rs_to_sk(rs)->sk_rcvbuf);
49912198SEiji.Ota@Sun.COM }
50012198SEiji.Ota@Sun.COM 
50112198SEiji.Ota@Sun.COM struct rdsv3_statistics {
50212198SEiji.Ota@Sun.COM 	uint64_t	s_conn_reset;
50312198SEiji.Ota@Sun.COM 	uint64_t	s_recv_drop_bad_checksum;
50412198SEiji.Ota@Sun.COM 	uint64_t	s_recv_drop_old_seq;
50512198SEiji.Ota@Sun.COM 	uint64_t	s_recv_drop_no_sock;
50612198SEiji.Ota@Sun.COM 	uint64_t	s_recv_drop_dead_sock;
50712198SEiji.Ota@Sun.COM 	uint64_t	s_recv_deliver_raced;
50812198SEiji.Ota@Sun.COM 	uint64_t	s_recv_delivered;
50912198SEiji.Ota@Sun.COM 	uint64_t	s_recv_queued;
51012198SEiji.Ota@Sun.COM 	uint64_t	s_recv_immediate_retry;
51112198SEiji.Ota@Sun.COM 	uint64_t	s_recv_delayed_retry;
51212198SEiji.Ota@Sun.COM 	uint64_t	s_recv_ack_required;
51312198SEiji.Ota@Sun.COM 	uint64_t	s_recv_rdma_bytes;
51412198SEiji.Ota@Sun.COM 	uint64_t	s_recv_ping;
51512198SEiji.Ota@Sun.COM 	uint64_t	s_send_queue_empty;
51612198SEiji.Ota@Sun.COM 	uint64_t	s_send_queue_full;
51712198SEiji.Ota@Sun.COM 	uint64_t	s_send_sem_contention;
51812198SEiji.Ota@Sun.COM 	uint64_t	s_send_sem_queue_raced;
51912198SEiji.Ota@Sun.COM 	uint64_t	s_send_immediate_retry;
52012198SEiji.Ota@Sun.COM 	uint64_t	s_send_delayed_retry;
52112198SEiji.Ota@Sun.COM 	uint64_t	s_send_drop_acked;
52212198SEiji.Ota@Sun.COM 	uint64_t	s_send_ack_required;
52312198SEiji.Ota@Sun.COM 	uint64_t	s_send_queued;
52412198SEiji.Ota@Sun.COM 	uint64_t	s_send_rdma;
52512198SEiji.Ota@Sun.COM 	uint64_t	s_send_rdma_bytes;
52612198SEiji.Ota@Sun.COM 	uint64_t	s_send_pong;
52712198SEiji.Ota@Sun.COM 	uint64_t	s_page_remainder_hit;
52812198SEiji.Ota@Sun.COM 	uint64_t	s_page_remainder_miss;
52912198SEiji.Ota@Sun.COM 	uint64_t	s_copy_to_user;
53012198SEiji.Ota@Sun.COM 	uint64_t	s_copy_from_user;
53112198SEiji.Ota@Sun.COM 	uint64_t	s_cong_update_queued;
53212198SEiji.Ota@Sun.COM 	uint64_t	s_cong_update_received;
53312198SEiji.Ota@Sun.COM 	uint64_t	s_cong_send_error;
53412198SEiji.Ota@Sun.COM 	uint64_t	s_cong_send_blocked;
53512198SEiji.Ota@Sun.COM };
53612198SEiji.Ota@Sun.COM 
53712198SEiji.Ota@Sun.COM /* af_rds.c */
53812198SEiji.Ota@Sun.COM void rdsv3_sock_addref(struct rdsv3_sock *rs);
53912198SEiji.Ota@Sun.COM void rdsv3_sock_put(struct rdsv3_sock *rs);
54012198SEiji.Ota@Sun.COM void rdsv3_wake_sk_sleep(struct rdsv3_sock *rs);
54112198SEiji.Ota@Sun.COM void __rdsv3_wake_sk_sleep(struct rsock *sk);
54212198SEiji.Ota@Sun.COM 
54312198SEiji.Ota@Sun.COM /* bind.c */
54412198SEiji.Ota@Sun.COM int rdsv3_bind(sock_lower_handle_t proto_handle, struct sockaddr *sa,
54512198SEiji.Ota@Sun.COM     socklen_t len, cred_t *cr);
54612198SEiji.Ota@Sun.COM void rdsv3_remove_bound(struct rdsv3_sock *rs);
54712895SGiri.Adari@Sun.COM struct rdsv3_sock *rdsv3_find_bound(struct rdsv3_connection *conn,
54812895SGiri.Adari@Sun.COM     uint16_be_t port);
54912895SGiri.Adari@Sun.COM struct rdsv3_ip_bucket *rdsv3_find_ip_bucket(ipaddr_t, zoneid_t);
55012198SEiji.Ota@Sun.COM 
55112198SEiji.Ota@Sun.COM /* conn.c */
55212198SEiji.Ota@Sun.COM int rdsv3_conn_init(void);
55312198SEiji.Ota@Sun.COM void rdsv3_conn_exit(void);
55412198SEiji.Ota@Sun.COM struct rdsv3_connection *rdsv3_conn_create(uint32_be_t laddr, uint32_be_t faddr,
55512198SEiji.Ota@Sun.COM     struct rdsv3_transport *trans, int gfp);
55612198SEiji.Ota@Sun.COM struct rdsv3_connection *rdsv3_conn_create_outgoing(uint32_be_t laddr,
55712198SEiji.Ota@Sun.COM     uint32_be_t faddr,
55812198SEiji.Ota@Sun.COM     struct rdsv3_transport *trans, int gfp);
55912676SEiji.Ota@Sun.COM void rdsv3_conn_shutdown(struct rdsv3_connection *conn);
56012198SEiji.Ota@Sun.COM void rdsv3_conn_destroy(struct rdsv3_connection *conn);
56112198SEiji.Ota@Sun.COM void rdsv3_conn_reset(struct rdsv3_connection *conn);
56212198SEiji.Ota@Sun.COM void rdsv3_conn_drop(struct rdsv3_connection *conn);
56312198SEiji.Ota@Sun.COM void rdsv3_for_each_conn_info(struct rsock *sock, unsigned int len,
56412198SEiji.Ota@Sun.COM     struct rdsv3_info_iterator *iter,
56512198SEiji.Ota@Sun.COM     struct rdsv3_info_lengths *lens,
56612198SEiji.Ota@Sun.COM     int (*visitor)(struct rdsv3_connection *, void *),
56712198SEiji.Ota@Sun.COM     size_t item_len);
56812198SEiji.Ota@Sun.COM 
56912198SEiji.Ota@Sun.COM static inline int
rdsv3_conn_transition(struct rdsv3_connection * conn,int old,int new)57012198SEiji.Ota@Sun.COM rdsv3_conn_transition(struct rdsv3_connection *conn, int old, int new)
57112198SEiji.Ota@Sun.COM {
57212198SEiji.Ota@Sun.COM 	return (atomic_cmpxchg(&conn->c_state, old, new) == old);
57312198SEiji.Ota@Sun.COM }
57412198SEiji.Ota@Sun.COM 
57512228SEiji.Ota@Sun.COM static inline int
rdsv3_conn_state(struct rdsv3_connection * conn)57612198SEiji.Ota@Sun.COM rdsv3_conn_state(struct rdsv3_connection *conn)
57712198SEiji.Ota@Sun.COM {
57812198SEiji.Ota@Sun.COM 	return (atomic_get(&conn->c_state));
57912198SEiji.Ota@Sun.COM }
58012198SEiji.Ota@Sun.COM 
58112228SEiji.Ota@Sun.COM static inline int
rdsv3_conn_up(struct rdsv3_connection * conn)58212198SEiji.Ota@Sun.COM rdsv3_conn_up(struct rdsv3_connection *conn)
58312198SEiji.Ota@Sun.COM {
58412198SEiji.Ota@Sun.COM 	return (atomic_get(&conn->c_state) == RDSV3_CONN_UP);
58512198SEiji.Ota@Sun.COM }
58612198SEiji.Ota@Sun.COM 
58712228SEiji.Ota@Sun.COM static inline int
rdsv3_conn_connecting(struct rdsv3_connection * conn)58812198SEiji.Ota@Sun.COM rdsv3_conn_connecting(struct rdsv3_connection *conn)
58912198SEiji.Ota@Sun.COM {
59012198SEiji.Ota@Sun.COM 	return (atomic_get(&conn->c_state) == RDSV3_CONN_CONNECTING);
59112198SEiji.Ota@Sun.COM }
59212198SEiji.Ota@Sun.COM 
59312198SEiji.Ota@Sun.COM /* recv.c */
59412198SEiji.Ota@Sun.COM void rdsv3_inc_init(struct rdsv3_incoming *inc, struct rdsv3_connection *conn,
59512198SEiji.Ota@Sun.COM     uint32_be_t saddr);
59612198SEiji.Ota@Sun.COM void rdsv3_inc_addref(struct rdsv3_incoming *inc);
59712198SEiji.Ota@Sun.COM void rdsv3_inc_put(struct rdsv3_incoming *inc);
59812198SEiji.Ota@Sun.COM void rdsv3_recv_incoming(struct rdsv3_connection *conn, uint32_be_t saddr,
59912198SEiji.Ota@Sun.COM     uint32_be_t daddr,
60012198SEiji.Ota@Sun.COM     struct rdsv3_incoming *inc, int gfp);
60112198SEiji.Ota@Sun.COM int rdsv3_recvmsg(struct rdsv3_sock *rs, uio_t *uio,
60212198SEiji.Ota@Sun.COM     struct msghdr *msg, size_t size, int msg_flags);
60312198SEiji.Ota@Sun.COM void rdsv3_clear_recv_queue(struct rdsv3_sock *rs);
60412198SEiji.Ota@Sun.COM int rdsv3_notify_queue_get(struct rdsv3_sock *rs, struct msghdr *msg);
60512198SEiji.Ota@Sun.COM void rdsv3_inc_info_copy(struct rdsv3_incoming *inc,
60612198SEiji.Ota@Sun.COM     struct rdsv3_info_iterator *iter,
60712198SEiji.Ota@Sun.COM     uint32_be_t saddr, uint32_be_t daddr, int flip);
60812198SEiji.Ota@Sun.COM 
60912198SEiji.Ota@Sun.COM /* page.c */
61012198SEiji.Ota@Sun.COM int rdsv3_page_remainder_alloc(struct rdsv3_scatterlist *scat,
61112198SEiji.Ota@Sun.COM     unsigned long bytes, int gfp);
61212198SEiji.Ota@Sun.COM 
61312198SEiji.Ota@Sun.COM /* send.c */
61412198SEiji.Ota@Sun.COM int rdsv3_sendmsg(struct rdsv3_sock *rs, uio_t *uio, struct nmsghdr *msg,
61512198SEiji.Ota@Sun.COM     size_t payload_len);
61612198SEiji.Ota@Sun.COM void rdsv3_send_reset(struct rdsv3_connection *conn);
61712198SEiji.Ota@Sun.COM int rdsv3_send_xmit(struct rdsv3_connection *conn);
61812198SEiji.Ota@Sun.COM struct sockaddr_in;
61912198SEiji.Ota@Sun.COM void rdsv3_send_drop_to(struct rdsv3_sock *rs, struct sockaddr_in *dest);
62012198SEiji.Ota@Sun.COM typedef int (*is_acked_func)(struct rdsv3_message *rm, uint64_t ack);
62112198SEiji.Ota@Sun.COM void rdsv3_send_drop_acked(struct rdsv3_connection *conn, uint64_t ack,
62212198SEiji.Ota@Sun.COM     is_acked_func is_acked);
62312198SEiji.Ota@Sun.COM int rdsv3_send_acked_before(struct rdsv3_connection *conn, uint64_t seq);
62412198SEiji.Ota@Sun.COM void rdsv3_send_remove_from_sock(struct list *messages, int status);
62512198SEiji.Ota@Sun.COM int rdsv3_send_pong(struct rdsv3_connection *conn, uint16_be_t dport);
62612198SEiji.Ota@Sun.COM struct rdsv3_message *rdsv3_send_get_message(struct rdsv3_connection *,
62712198SEiji.Ota@Sun.COM     struct rdsv3_rdma_op *);
62812198SEiji.Ota@Sun.COM 
62912198SEiji.Ota@Sun.COM /* rdma.c */
63012198SEiji.Ota@Sun.COM void rdsv3_rdma_unuse(struct rdsv3_sock *rs, uint32_t r_key, int force);
63112198SEiji.Ota@Sun.COM 
63212198SEiji.Ota@Sun.COM /* cong.c */
63312198SEiji.Ota@Sun.COM void rdsv3_cong_init(void);
63412198SEiji.Ota@Sun.COM int rdsv3_cong_get_maps(struct rdsv3_connection *conn);
63512198SEiji.Ota@Sun.COM void rdsv3_cong_add_conn(struct rdsv3_connection *conn);
63612198SEiji.Ota@Sun.COM void rdsv3_cong_remove_conn(struct rdsv3_connection *conn);
63712198SEiji.Ota@Sun.COM void rdsv3_cong_set_bit(struct rdsv3_cong_map *map, uint16_be_t port);
63812198SEiji.Ota@Sun.COM void rdsv3_cong_clear_bit(struct rdsv3_cong_map *map, uint16_be_t port);
63912198SEiji.Ota@Sun.COM int rdsv3_cong_wait(struct rdsv3_cong_map *map, uint16_be_t port, int nonblock,
64012198SEiji.Ota@Sun.COM     struct rdsv3_sock *rs);
64112198SEiji.Ota@Sun.COM void rdsv3_cong_queue_updates(struct rdsv3_cong_map *map);
64212198SEiji.Ota@Sun.COM void rdsv3_cong_map_updated(struct rdsv3_cong_map *map, uint64_t);
64312198SEiji.Ota@Sun.COM int rdsv3_cong_updated_since(unsigned long *recent);
64412198SEiji.Ota@Sun.COM void rdsv3_cong_add_socket(struct rdsv3_sock *);
64512198SEiji.Ota@Sun.COM void rdsv3_cong_remove_socket(struct rdsv3_sock *);
64612198SEiji.Ota@Sun.COM void rdsv3_cong_exit(void);
64712198SEiji.Ota@Sun.COM struct rdsv3_message *rdsv3_cong_update_alloc(struct rdsv3_connection *conn);
64812198SEiji.Ota@Sun.COM 
64912198SEiji.Ota@Sun.COM /* stats.c */
650*12922SGiri.Adari@Sun.COM extern uint_t	nr_cpus;
651*12922SGiri.Adari@Sun.COM extern struct rdsv3_statistics	*rdsv3_stats;
652*12922SGiri.Adari@Sun.COM #define	rdsv3_per_cpu(var, cpu)  var[cpu]
653*12922SGiri.Adari@Sun.COM #define	rdsv3_stats_add_which(which, member, count) do {	\
654*12922SGiri.Adari@Sun.COM 	rdsv3_per_cpu(which, CPU->cpu_seqid).member += count;	\
65512198SEiji.Ota@Sun.COM } while (0)
656*12922SGiri.Adari@Sun.COM #define	rdsv3_stats_inc(member) \
657*12922SGiri.Adari@Sun.COM 	rdsv3_stats_add_which(rdsv3_stats, member, 1)
65812198SEiji.Ota@Sun.COM #define	rdsv3_stats_add(member, count)	\
65912198SEiji.Ota@Sun.COM 	rdsv3_stats_add_which(rdsv3_stats, member, count)
66012198SEiji.Ota@Sun.COM int rdsv3_stats_init(void);
66112198SEiji.Ota@Sun.COM void rdsv3_stats_exit(void);
66212198SEiji.Ota@Sun.COM void rdsv3_stats_info_copy(struct rdsv3_info_iterator *iter,
66312198SEiji.Ota@Sun.COM     uint64_t *values, char **names, size_t nr);
66412198SEiji.Ota@Sun.COM 
66512198SEiji.Ota@Sun.COM 
66612198SEiji.Ota@Sun.COM /* sysctl.c */
66712198SEiji.Ota@Sun.COM int rdsv3_sysctl_init(void);
66812198SEiji.Ota@Sun.COM void rdsv3_sysctl_exit(void);
66912198SEiji.Ota@Sun.COM extern unsigned long rdsv3_sysctl_sndbuf_min;
67012198SEiji.Ota@Sun.COM extern unsigned long rdsv3_sysctl_sndbuf_default;
67112198SEiji.Ota@Sun.COM extern unsigned long rdsv3_sysctl_sndbuf_max;
67212198SEiji.Ota@Sun.COM extern unsigned long rdsv3_sysctl_reconnect_min_jiffies;
67312198SEiji.Ota@Sun.COM extern unsigned long rdsv3_sysctl_reconnect_max_jiffies;
67412198SEiji.Ota@Sun.COM extern unsigned int  rdsv3_sysctl_max_unacked_packets;
67512198SEiji.Ota@Sun.COM extern unsigned int  rdsv3_sysctl_max_unacked_bytes;
67612198SEiji.Ota@Sun.COM extern unsigned int  rdsv3_sysctl_ping_enable;
67712198SEiji.Ota@Sun.COM extern unsigned long rdsv3_sysctl_trace_flags;
67812198SEiji.Ota@Sun.COM extern unsigned int  rdsv3_sysctl_trace_level;
67912198SEiji.Ota@Sun.COM 
68012198SEiji.Ota@Sun.COM /* threads.c */
68112198SEiji.Ota@Sun.COM int rdsv3_threads_init();
68212198SEiji.Ota@Sun.COM void rdsv3_threads_exit(void);
68312198SEiji.Ota@Sun.COM extern struct rdsv3_workqueue_struct_s *rdsv3_wq;
68412676SEiji.Ota@Sun.COM void rdsv3_queue_reconnect(struct rdsv3_connection *conn);
68512198SEiji.Ota@Sun.COM void rdsv3_connect_worker(struct rdsv3_work_s *);
68612198SEiji.Ota@Sun.COM void rdsv3_shutdown_worker(struct rdsv3_work_s *);
68712198SEiji.Ota@Sun.COM void rdsv3_send_worker(struct rdsv3_work_s *);
68812198SEiji.Ota@Sun.COM void rdsv3_recv_worker(struct rdsv3_work_s *);
68912676SEiji.Ota@Sun.COM void rdsv3_reaper_worker(struct rdsv3_work_s *);
69012198SEiji.Ota@Sun.COM void rdsv3_connect_complete(struct rdsv3_connection *conn);
69112198SEiji.Ota@Sun.COM 
69212198SEiji.Ota@Sun.COM /* transport.c */
69312198SEiji.Ota@Sun.COM int rdsv3_trans_register(struct rdsv3_transport *trans);
69412198SEiji.Ota@Sun.COM void rdsv3_trans_unregister(struct rdsv3_transport *trans);
69512198SEiji.Ota@Sun.COM struct rdsv3_transport *rdsv3_trans_get_preferred(uint32_be_t addr);
69612198SEiji.Ota@Sun.COM unsigned int rdsv3_trans_stats_info_copy(struct rdsv3_info_iterator *iter,
69712198SEiji.Ota@Sun.COM     unsigned int avail);
69812198SEiji.Ota@Sun.COM void rdsv3_trans_exit(void);
69912198SEiji.Ota@Sun.COM 
70012198SEiji.Ota@Sun.COM /* message.c */
70112198SEiji.Ota@Sun.COM struct rdsv3_message *rdsv3_message_alloc(unsigned int nents, int gfp);
70212198SEiji.Ota@Sun.COM struct rdsv3_message *rdsv3_message_copy_from_user(struct uio *uiop,
70312198SEiji.Ota@Sun.COM     size_t total_len);
70412198SEiji.Ota@Sun.COM struct rdsv3_message *rdsv3_message_map_pages(unsigned long *page_addrs,
70512198SEiji.Ota@Sun.COM     unsigned int total_len);
70612198SEiji.Ota@Sun.COM void rdsv3_message_populate_header(struct rdsv3_header *hdr, uint16_be_t sport,
70712198SEiji.Ota@Sun.COM     uint16_be_t dport, uint64_t seq);
70812198SEiji.Ota@Sun.COM int rdsv3_message_add_extension(struct rdsv3_header *hdr,
70912198SEiji.Ota@Sun.COM     unsigned int type, const void *data, unsigned int len);
71012198SEiji.Ota@Sun.COM int rdsv3_message_next_extension(struct rdsv3_header *hdr,
71112198SEiji.Ota@Sun.COM     unsigned int *pos, void *buf, unsigned int *buflen);
71212198SEiji.Ota@Sun.COM int rdsv3_message_add_version_extension(struct rdsv3_header *hdr,
71312198SEiji.Ota@Sun.COM     unsigned int version);
71412198SEiji.Ota@Sun.COM int rdsv3_message_get_version_extension(struct rdsv3_header *hdr,
71512198SEiji.Ota@Sun.COM     unsigned int *version);
71612198SEiji.Ota@Sun.COM int rdsv3_message_add_rdma_dest_extension(struct rdsv3_header *hdr,
71712198SEiji.Ota@Sun.COM     uint32_t r_key, uint32_t offset);
71812198SEiji.Ota@Sun.COM int rdsv3_message_inc_copy_to_user(struct rdsv3_incoming *inc,
71912198SEiji.Ota@Sun.COM     uio_t *uio, size_t size);
72012198SEiji.Ota@Sun.COM void rdsv3_message_inc_free(struct rdsv3_incoming *inc);
72112198SEiji.Ota@Sun.COM void rdsv3_message_addref(struct rdsv3_message *rm);
72212198SEiji.Ota@Sun.COM void rdsv3_message_put(struct rdsv3_message *rm);
72312198SEiji.Ota@Sun.COM void rdsv3_message_wait(struct rdsv3_message *rm);
72412198SEiji.Ota@Sun.COM void rdsv3_message_unmapped(struct rdsv3_message *rm);
72512198SEiji.Ota@Sun.COM 
72612228SEiji.Ota@Sun.COM static inline void
rdsv3_message_make_checksum(struct rdsv3_header * hdr)72712198SEiji.Ota@Sun.COM rdsv3_message_make_checksum(struct rdsv3_header *hdr)
72812198SEiji.Ota@Sun.COM {
72912198SEiji.Ota@Sun.COM 	hdr->h_csum = 0;
73012198SEiji.Ota@Sun.COM 	hdr->h_csum =
73112198SEiji.Ota@Sun.COM 	    rdsv3_ip_fast_csum((void *)hdr, sizeof (*hdr) >> 2);
73212198SEiji.Ota@Sun.COM }
73312198SEiji.Ota@Sun.COM 
73412228SEiji.Ota@Sun.COM static inline int
rdsv3_message_verify_checksum(const struct rdsv3_header * hdr)73512198SEiji.Ota@Sun.COM rdsv3_message_verify_checksum(const struct rdsv3_header *hdr)
73612198SEiji.Ota@Sun.COM {
73712198SEiji.Ota@Sun.COM 	return (!hdr->h_csum ||
73812198SEiji.Ota@Sun.COM 	    rdsv3_ip_fast_csum((void *)hdr, sizeof (*hdr) >> 2) == 0);
73912198SEiji.Ota@Sun.COM }
74012198SEiji.Ota@Sun.COM 
74112198SEiji.Ota@Sun.COM /* rdsv3_sc.c */
74212198SEiji.Ota@Sun.COM extern boolean_t rdsv3_if_lookup_by_name(char *if_name);
74312198SEiji.Ota@Sun.COM extern int rdsv3_sc_path_lookup(ipaddr_t *localip, ipaddr_t *remip);
74412198SEiji.Ota@Sun.COM extern ipaddr_t rdsv3_scaddr_to_ibaddr(ipaddr_t addr);
74512198SEiji.Ota@Sun.COM 
74612198SEiji.Ota@Sun.COM #ifdef	__cplusplus
74712198SEiji.Ota@Sun.COM }
74812198SEiji.Ota@Sun.COM #endif
74912198SEiji.Ota@Sun.COM 
75012198SEiji.Ota@Sun.COM #endif /* _RDSV3_RDSV3_H */
751