rdsv3.h revision 12863:5783b6fe7ed5
1/*
2 * This file contains definitions imported from the OFED rds header rds.h.
3 * Oracle elects to have and use the contents of rds.h under and
4 * governed by the OpenIB.org BSD license.
5 */
6
7/*
8 * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
9 */
10
11#ifndef _RDSV3_RDSV3_H
12#define	_RDSV3_RDSV3_H
13
14/*
15 * The name of this file is rds.h in ofed.
16 */
17
18#ifdef __cplusplus
19extern "C" {
20#endif
21
22#include <sys/sunndi.h>
23#include <netinet/in.h>
24#include <sys/synch.h>
25#include <sys/stropts.h>
26#include <sys/socket.h>
27#include <sys/socketvar.h>
28#include <inet/ip.h>
29#include <sys/avl.h>
30#include <sys/param.h>
31#include <sys/time.h>
32#include <sys/rds.h>
33
34#include <sys/ib/ibtl/ibti.h>
35#include <sys/ib/clients/of/rdma/ib_verbs.h>
36#include <sys/ib/clients/of/rdma/ib_addr.h>
37#include <sys/ib/clients/of/rdma/rdma_cm.h>
38#include <sys/ib/clients/rdsv3/rdsv3_impl.h>
39#include <sys/ib/clients/rdsv3/info.h>
40
41#define	NIPQUAD(addr)					\
42	(unsigned char)((ntohl(addr) >> 24) & 0xFF),	\
43	(unsigned char)((ntohl(addr) >> 16) & 0xFF),	\
44	(unsigned char)((ntohl(addr) >>  8) & 0xFF),	\
45	(unsigned char)(ntohl(addr) & 0xFF)
46
47/*
48 * RDS Network protocol version
49 */
50#define	RDS_PROTOCOL_3_0	0x0300
51#define	RDS_PROTOCOL_3_1	0x0301
52#define	RDS_PROTOCOL_VERSION	RDS_PROTOCOL_3_1
53#define	RDS_PROTOCOL_MAJOR(v)	((v) >> 8)
54#define	RDS_PROTOCOL_MINOR(v)	((v) & 255)
55#define	RDS_PROTOCOL(maj, min)	(((maj) << 8) | min)
56
57/*
58 * XXX randomly chosen, but at least seems to be unused:
59 * #               18464-18768 Unassigned
60 * We should do better.  We want a reserved port to discourage unpriv'ed
61 * userspace from listening.
62 *
63 * port 18633 was the version that had ack frames on the wire.
64 */
65#define	RDSV3_PORT	18634
66
67#define	RDSV3_REAPER_WAIT_SECS		(5*60)
68#define	RDSV3_REAPER_WAIT_JIFFIES	SEC_TO_TICK(RDSV3_REAPER_WAIT_SECS)
69
70/*
71 * This is the sad making.  Some kernels have a bug in the per_cpu() api which
72 * makes DEFINE_PER_CPU trigger an oops on insmod because the per-cpu section
73 * in the module is not cacheline-aligned.  As much as we'd like to tell users
74 * with older kernels to stuff it, that's not reasonable.  We'll roll our own
75 * until this doesn't have to build against older kernels.
76 */
77#define	RDSV3_DEFINE_PER_CPU(type, var)  type var[NR_CPUS]
78#define	RDSV3_DECLARE_PER_CPU(type, var)  extern type var[NR_CPUS]
79#define	rdsv3_per_cpu(var, cpu)  var[cpu]
80
81static inline ulong_t
82ceil(ulong_t x, ulong_t y)
83{
84	return ((x + y - 1) / y);
85}
86
87#define	RDSV3_FRAG_SHIFT	12
88#define	RDSV3_FRAG_SIZE	((unsigned int)(1 << RDSV3_FRAG_SHIFT))
89
90#define	RDSV3_CONG_MAP_BYTES	(65536 / 8)
91#define	RDSV3_CONG_MAP_LONGS	(RDSV3_CONG_MAP_BYTES / sizeof (unsigned long))
92#define	RDSV3_CONG_MAP_PAGES	(RDSV3_CONG_MAP_BYTES / PAGE_SIZE)
93#define	RDSV3_CONG_MAP_PAGE_BITS	(PAGE_SIZE * 8)
94
95struct rdsv3_cong_map {
96	struct avl_node		m_rb_node;
97	uint32_be_t		m_addr;
98	rdsv3_wait_queue_t	m_waitq;
99	struct list		m_conn_list;
100	unsigned long		m_page_addrs[RDSV3_CONG_MAP_PAGES];
101};
102
103/*
104 * This is how we will track the connection state:
105 * A connection is always in one of the following
106 * states. Updates to the state are atomic and imply
107 * a memory barrier.
108 */
109enum {
110	RDSV3_CONN_DOWN = 0,
111	RDSV3_CONN_CONNECTING,
112	RDSV3_CONN_DISCONNECTING,
113	RDSV3_CONN_UP,
114	RDSV3_CONN_ERROR,
115};
116
117/* Bits for c_flags */
118#define	RDSV3_LL_SEND_FULL	0
119#define	RDSV3_RECONNECT_PENDING	1
120
121struct rdsv3_connection {
122	struct avl_node		c_hash_node;
123	uint32_be_t		c_laddr;
124	uint32_be_t		c_faddr;
125	unsigned int		c_loopback:1;
126	struct rdsv3_connection	*c_passive;
127
128	struct rdsv3_cong_map	*c_lcong;
129	struct rdsv3_cong_map	*c_fcong;
130
131	struct mutex		c_send_lock;    /* protect send ring */
132	atomic_t		c_send_generation;
133	atomic_t		c_senders;
134
135	struct rdsv3_message	*c_xmit_rm;
136	unsigned long		c_xmit_sg;
137	unsigned int		c_xmit_hdr_off;
138	unsigned int		c_xmit_data_off;
139	unsigned int		c_xmit_rdma_sent;
140
141	kmutex_t		c_lock;		/* protect msg queues */
142	uint64_t		c_next_tx_seq;
143	struct list		c_send_queue;
144	struct list		c_retrans;
145
146	uint64_t		c_next_rx_seq;
147
148	struct rdsv3_transport	*c_trans;
149	void			*c_transport_data;
150
151	atomic_t		c_state;
152	unsigned long		c_flags;
153	unsigned long		c_reconnect_jiffies;
154	clock_t			c_last_connect_jiffies;
155
156	struct rdsv3_delayed_work_s	c_send_w;
157	struct rdsv3_delayed_work_s	c_recv_w;
158	struct rdsv3_delayed_work_s	c_conn_w;
159	struct rdsv3_delayed_work_s	c_reap_w;
160	struct rdsv3_work_s	c_down_w;
161	struct mutex		c_cm_lock;	/* protect conn state & cm */
162
163	struct list_node	c_map_item;
164	unsigned long		c_map_queued;
165	unsigned long		c_map_offset;
166	unsigned long		c_map_bytes;
167
168	unsigned int		c_unacked_packets;
169	unsigned int		c_unacked_bytes;
170
171	/* Protocol version */
172	unsigned int		c_version;
173};
174
175#define	RDSV3_FLAG_CONG_BITMAP		0x01
176#define	RDSV3_FLAG_ACK_REQUIRED		0x02
177#define	RDSV3_FLAG_RETRANSMITTED	0x04
178#define	RDSV3_MAX_ADV_CREDIT		127
179
180/*
181 * Maximum space available for extension headers.
182 */
183#define	RDSV3_HEADER_EXT_SPACE    16
184
185struct rdsv3_header {
186	uint64_be_t	h_sequence;
187	uint64_be_t	h_ack;
188	uint32_be_t	h_len;
189	uint16_be_t	h_sport;
190	uint16_be_t	h_dport;
191	uint8_t		h_flags;
192	uint8_t		h_credit;
193	uint8_t		h_padding[4];
194	uint16_be_t	h_csum;
195
196	uint8_t		h_exthdr[RDSV3_HEADER_EXT_SPACE];
197};
198
199/* Reserved - indicates end of extensions */
200#define	RDSV3_EXTHDR_NONE		0
201
202/*
203 * This extension header is included in the very
204 * first message that is sent on a new connection,
205 * and identifies the protocol level. This will help
206 * rolling updates if a future change requires breaking
207 * the protocol.
208 */
209#define	RDSV3_EXTHDR_VERSION	1
210struct rdsv3_ext_header_version {
211	uint32_be_t	h_version;
212};
213
214/*
215 * This extension header is included in the RDS message
216 * chasing an RDMA operation.
217 */
218#define	RDSV3_EXTHDR_RDMA		2
219struct rdsv3_ext_header_rdma {
220	uint32_be_t	h_rdma_rkey;
221};
222
223/*
224 * This extension header tells the peer about the
225 * destination <R_Key,offset> of the requested RDMA
226 * operation.
227 */
228#define	RDSV3_EXTHDR_RDMA_DEST    3
229struct rdsv3_ext_header_rdma_dest {
230	uint32_be_t		h_rdma_rkey;
231	uint32_be_t		h_rdma_offset;
232};
233
234#define	__RDSV3_EXTHDR_MAX	16 /* for now */
235
236struct rdsv3_incoming {
237	atomic_t		i_refcount;
238	struct list_node	i_item;
239	struct rdsv3_connection	*i_conn;
240	struct rdsv3_header	i_hdr;
241	unsigned long		i_rx_jiffies;
242	uint32_be_t		i_saddr;
243
244	rds_rdma_cookie_t	i_rdma_cookie;
245};
246
247/*
248 * m_sock_item and m_conn_item are on lists that are serialized under
249 * conn->c_lock.  m_sock_item has additional meaning in that once it is empty
250 * the message will not be put back on the retransmit list after being sent.
251 * messages that are canceled while being sent rely on this.
252 *
253 * m_inc is used by loopback so that it can pass an incoming message straight
254 * back up into the rx path.  It embeds a wire header which is also used by
255 * the send path, which is kind of awkward.
256 *
257 * m_sock_item indicates the message's presence on a socket's send or receive
258 * queue.  m_rs will point to that socket.
259 *
260 * m_daddr is used by cancellation to prune messages to a given destination.
261 *
262 * The RDS_MSG_ON_SOCK and RDS_MSG_ON_CONN flags are used to avoid lock
263 * nesting.  As paths iterate over messages on a sock, or conn, they must
264 * also lock the conn, or sock, to remove the message from those lists too.
265 * Testing the flag to determine if the message is still on the lists lets
266 * us avoid testing the list_head directly.  That means each path can use
267 * the message's list_head to keep it on a local list while juggling locks
268 * without confusing the other path.
269 *
270 * m_ack_seq is an optional field set by transports who need a different
271 * sequence number range to invalidate.  They can use this in a callback
272 * that they pass to rdsv3_send_drop_acked() to see if each message has been
273 * acked.  The HAS_ACK_SEQ flag can be used to detect messages which haven't
274 * had ack_seq set yet.
275 */
276#define	RDSV3_MSG_ON_SOCK		1
277#define	RDSV3_MSG_ON_CONN		2
278#define	RDSV3_MSG_HAS_ACK_SEQ		3
279#define	RDSV3_MSG_ACK_REQUIRED		4
280#define	RDSV3_MSG_RETRANSMITTED		5
281#define	RDSV3_MSG_MAPPED		6
282#define	RDSV3_MSG_PAGEVEC		7
283
284struct rdsv3_message {
285	atomic_t		m_refcount;
286	struct list_node	m_sock_item;
287	struct list_node	m_conn_item;
288	struct rdsv3_incoming	m_inc;
289	uint64_t		m_ack_seq;
290	uint32_be_t		m_daddr;
291	unsigned long		m_flags;
292
293	/*
294	 * Never access m_rs without holding m_rs_lock.
295	 * Lock nesting is
296	 *  rm->m_rs_lock
297	 *   -> rs->rs_lock
298	 */
299	kmutex_t		m_rs_lock;
300	rdsv3_wait_queue_t	m_flush_wait;
301
302	struct rdsv3_sock	*m_rs;
303	struct rdsv3_rdma_op	*m_rdma_op;
304	rds_rdma_cookie_t	m_rdma_cookie;
305	struct rdsv3_mr		*m_rdma_mr;
306	unsigned int		m_nents;
307	unsigned int		m_count;
308	struct rdsv3_scatterlist	m_sg[1];
309};
310
311/*
312 * The RDS notifier is used (optionally) to tell the application about
313 * completed RDMA operations. Rather than keeping the whole rds message
314 * around on the queue, we allocate a small notifier that is put on the
315 * socket's notifier_list. Notifications are delivered to the application
316 * through control messages.
317 */
318struct rdsv3_notifier {
319	list_node_t	n_list;
320	uint64_t	n_user_token;
321	int		n_status;
322};
323
324/*
325 * struct rdsv3_transport -  transport specific behavioural hooks
326 *
327 * @xmit: .xmit is called by rdsv3_send_xmit() to tell the transport to send
328 *	  part of a message.  The caller serializes on the send_sem so this
329 *	  doesn't need to be reentrant for a given conn.  The header must be
330 *	  sent before the data payload.  .xmit must be prepared to send a
331 *	  message with no data payload.  .xmit should return the number of
332 *	  bytes that were sent down the connection, including header bytes.
333 *	  Returning 0 tells the caller that it doesn't need to perform any
334 *	  additional work now.  This is usually the case when the transport has
335 *	  filled the sending queue for its connection and will handle
336 *	  triggering the rds thread to continue the send when space becomes
337 *	  available.  Returning -EAGAIN tells the caller to retry the send
338 *	  immediately.  Returning -ENOMEM tells the caller to retry the send at
339 *	  some point in the future.
340 *
341 * @conn_shutdown: conn_shutdown stops traffic on the given connection.  Once
342 *		   it returns the connection can not call rdsv3_recv_incoming().
343 *		   This will only be called once after conn_connect returns
344 *		   non-zero success and will The caller serializes this with
345 *		   the send and connecting paths (xmit_* and conn_*).  The
346 *		   transport is responsible for other serialization, including
347 *		   rdsv3_recv_incoming().  This is called in process context but
348 *		   should try hard not to block.
349 *
350 * @xmit_cong_map: This asks the transport to send the local bitmap down the
351 *		   given connection.  XXX get a better story about the bitmap
352 *		   flag and header.
353 */
354
355#define	RDS_TRANS_IB    0
356#define	RDS_TRANS_IWARP 1
357#define	RDS_TRANS_TCP   2
358#define	RDS_TRANS_COUNT 3
359
360struct rdsv3_transport {
361	char			t_name[TRANSNAMSIZ];
362	struct list_node	t_item;
363	unsigned int		t_type;
364	unsigned int		t_prefer_loopback:1;
365
366	int (*laddr_check)(uint32_be_t addr);
367	int (*conn_alloc)(struct rdsv3_connection *conn, int gfp);
368	void (*conn_free)(void *data);
369	int (*conn_connect)(struct rdsv3_connection *conn);
370	void (*conn_shutdown)(struct rdsv3_connection *conn);
371	void (*xmit_prepare)(struct rdsv3_connection *conn);
372	void (*xmit_complete)(struct rdsv3_connection *conn);
373	int (*xmit)(struct rdsv3_connection *conn, struct rdsv3_message *rm,
374	    unsigned int hdr_off, unsigned int sg, unsigned int off);
375	int (*xmit_cong_map)(struct rdsv3_connection *conn,
376	    struct rdsv3_cong_map *map, unsigned long offset);
377	int (*xmit_rdma)(struct rdsv3_connection *conn,
378	    struct rdsv3_rdma_op *op);
379	int (*recv)(struct rdsv3_connection *conn);
380	int (*inc_copy_to_user)(struct rdsv3_incoming *inc, uio_t *uio,
381	    size_t size);
382	void (*inc_free)(struct rdsv3_incoming *inc);
383
384	int (*cm_handle_connect)(struct rdma_cm_id *cm_id,
385	    struct rdma_cm_event *event);
386	int (*cm_initiate_connect)(struct rdma_cm_id *cm_id);
387	void (*cm_connect_complete)(struct rdsv3_connection *conn,
388	    struct rdma_cm_event *event);
389
390	unsigned int (*stats_info_copy)(struct rdsv3_info_iterator *iter,
391	    unsigned int avail);
392	void (*exit)(void);
393	void *(*get_mr)(struct rds_iovec *sg, unsigned long nr_sg,
394	    struct rdsv3_sock *rs, uint32_t *key_ret);
395	void (*sync_mr)(void *trans_private, int direction);
396	void (*free_mr)(void *trans_private, int invalidate);
397	void (*flush_mrs)(void);
398};
399
400struct rdsv3_sock {
401	struct rsock		*rs_sk;
402	uint64_t		rs_user_addr;
403	uint64_t		rs_user_bytes;
404
405	/*
406	 * bound_addr used for both incoming and outgoing, no INADDR_ANY
407	 * support.
408	 */
409	struct avl_node		rs_bound_node;
410	uint32_be_t		rs_bound_addr;
411	uint32_be_t		rs_conn_addr;
412	uint16_be_t		rs_bound_port;
413	uint16_be_t		rs_conn_port;
414
415	/*
416	 * This is only used to communicate the transport between bind and
417	 * initiating connections. All other trans use is referenced through
418	 * the connection.
419	 */
420	struct rdsv3_transport	*rs_transport;
421
422	/*
423	 * rdsv3_sendmsg caches the conn it used the last time around.
424	 * This helps avoid costly lookups.
425	 */
426	struct rdsv3_connection	*rs_conn;
427	kmutex_t 		rs_conn_lock;
428
429	/* flag indicating we were congested or not */
430	int			rs_congested;
431	/* seen congestion (ENOBUFS) when sending? */
432	int			rs_seen_congestion;
433	kmutex_t 		rs_congested_lock;
434	kcondvar_t		rs_congested_cv;
435
436	/* rs_lock protects all these adjacent members before the newline */
437	kmutex_t		rs_lock;
438	struct list		rs_send_queue;
439	uint32_t		rs_snd_bytes;
440	int			rs_rcv_bytes;
441	/* currently used for failed RDMAs */
442	struct list		rs_notify_queue;
443
444	/*
445	 * Congestion wake_up. If rs_cong_monitor is set, we use cong_mask
446	 * to decide whether the application should be woken up.
447	 * If not set, we use rs_cong_track to find out whether a cong map
448	 * update arrived.
449	 */
450	uint64_t		rs_cong_mask;
451	uint64_t		rs_cong_notify;
452	struct list_node	rs_cong_list;
453	unsigned long		rs_cong_track;
454
455	/*
456	 * rs_recv_lock protects the receive queue, and is
457	 * used to serialize with rdsv3_release.
458	 */
459	krwlock_t		rs_recv_lock;
460	struct list		rs_recv_queue;
461
462	/* just for stats reporting */
463	struct list_node	rs_item;
464
465	/* these have their own lock */
466	kmutex_t		rs_rdma_lock;
467	struct avl_tree		rs_rdma_keys;
468
469	/* Socket options - in case there will be more */
470	unsigned char		rs_recverr,
471				rs_cong_monitor;
472
473	cred_t			*rs_cred;
474	zoneid_t		rs_zoneid;
475};
476
477static inline struct rdsv3_sock *
478rdsv3_sk_to_rs(const struct rsock *sk)
479{
480	return ((struct rdsv3_sock *)sk->sk_protinfo);
481}
482
483static inline struct rsock *
484rdsv3_rs_to_sk(const struct rdsv3_sock *rs)
485{
486	return ((struct rsock *)rs->rs_sk);
487}
488
489/*
490 * The stack assigns sk_sndbuf and sk_rcvbuf to twice the specified value
491 * to account for overhead.  We don't account for overhead, we just apply
492 * the number of payload bytes to the specified value.
493 */
494static inline int
495rdsv3_sk_sndbuf(struct rdsv3_sock *rs)
496{
497	/* XXX */
498	return (rdsv3_rs_to_sk(rs)->sk_sndbuf);
499}
500
501static inline int
502rdsv3_sk_rcvbuf(struct rdsv3_sock *rs)
503{
504	/* XXX */
505	return (rdsv3_rs_to_sk(rs)->sk_rcvbuf);
506}
507
508struct rdsv3_statistics {
509	uint64_t	s_conn_reset;
510	uint64_t	s_recv_drop_bad_checksum;
511	uint64_t	s_recv_drop_old_seq;
512	uint64_t	s_recv_drop_no_sock;
513	uint64_t	s_recv_drop_dead_sock;
514	uint64_t	s_recv_deliver_raced;
515	uint64_t	s_recv_delivered;
516	uint64_t	s_recv_queued;
517	uint64_t	s_recv_immediate_retry;
518	uint64_t	s_recv_delayed_retry;
519	uint64_t	s_recv_ack_required;
520	uint64_t	s_recv_rdma_bytes;
521	uint64_t	s_recv_ping;
522	uint64_t	s_send_queue_empty;
523	uint64_t	s_send_queue_full;
524	uint64_t	s_send_sem_contention;
525	uint64_t	s_send_sem_queue_raced;
526	uint64_t	s_send_immediate_retry;
527	uint64_t	s_send_delayed_retry;
528	uint64_t	s_send_drop_acked;
529	uint64_t	s_send_ack_required;
530	uint64_t	s_send_queued;
531	uint64_t	s_send_rdma;
532	uint64_t	s_send_rdma_bytes;
533	uint64_t	s_send_pong;
534	uint64_t	s_page_remainder_hit;
535	uint64_t	s_page_remainder_miss;
536	uint64_t	s_copy_to_user;
537	uint64_t	s_copy_from_user;
538	uint64_t	s_cong_update_queued;
539	uint64_t	s_cong_update_received;
540	uint64_t	s_cong_send_error;
541	uint64_t	s_cong_send_blocked;
542};
543
544/* af_rds.c */
545void rdsv3_sock_addref(struct rdsv3_sock *rs);
546void rdsv3_sock_put(struct rdsv3_sock *rs);
547void rdsv3_wake_sk_sleep(struct rdsv3_sock *rs);
548void __rdsv3_wake_sk_sleep(struct rsock *sk);
549
550/* bind.c */
551int rdsv3_bind(sock_lower_handle_t proto_handle, struct sockaddr *sa,
552    socklen_t len, cred_t *cr);
553void rdsv3_remove_bound(struct rdsv3_sock *rs);
554struct rdsv3_sock *rdsv3_find_bound(uint32_be_t addr, uint16_be_t port);
555
556/* conn.c */
557int rdsv3_conn_init(void);
558void rdsv3_conn_exit(void);
559struct rdsv3_connection *rdsv3_conn_create(uint32_be_t laddr, uint32_be_t faddr,
560    struct rdsv3_transport *trans, int gfp);
561struct rdsv3_connection *rdsv3_conn_create_outgoing(uint32_be_t laddr,
562    uint32_be_t faddr,
563    struct rdsv3_transport *trans, int gfp);
564void rdsv3_conn_shutdown(struct rdsv3_connection *conn);
565void rdsv3_conn_destroy(struct rdsv3_connection *conn);
566void rdsv3_conn_reset(struct rdsv3_connection *conn);
567void rdsv3_conn_drop(struct rdsv3_connection *conn);
568void rdsv3_for_each_conn_info(struct rsock *sock, unsigned int len,
569    struct rdsv3_info_iterator *iter,
570    struct rdsv3_info_lengths *lens,
571    int (*visitor)(struct rdsv3_connection *, void *),
572    size_t item_len);
573
574static inline int
575rdsv3_conn_transition(struct rdsv3_connection *conn, int old, int new)
576{
577	return (atomic_cmpxchg(&conn->c_state, old, new) == old);
578}
579
580static inline int
581rdsv3_conn_state(struct rdsv3_connection *conn)
582{
583	return (atomic_get(&conn->c_state));
584}
585
586static inline int
587rdsv3_conn_up(struct rdsv3_connection *conn)
588{
589	return (atomic_get(&conn->c_state) == RDSV3_CONN_UP);
590}
591
592static inline int
593rdsv3_conn_connecting(struct rdsv3_connection *conn)
594{
595	return (atomic_get(&conn->c_state) == RDSV3_CONN_CONNECTING);
596}
597
598/* recv.c */
599void rdsv3_inc_init(struct rdsv3_incoming *inc, struct rdsv3_connection *conn,
600    uint32_be_t saddr);
601void rdsv3_inc_addref(struct rdsv3_incoming *inc);
602void rdsv3_inc_put(struct rdsv3_incoming *inc);
603void rdsv3_recv_incoming(struct rdsv3_connection *conn, uint32_be_t saddr,
604    uint32_be_t daddr,
605    struct rdsv3_incoming *inc, int gfp);
606int rdsv3_recvmsg(struct rdsv3_sock *rs, uio_t *uio,
607    struct msghdr *msg, size_t size, int msg_flags);
608void rdsv3_clear_recv_queue(struct rdsv3_sock *rs);
609int rdsv3_notify_queue_get(struct rdsv3_sock *rs, struct msghdr *msg);
610void rdsv3_inc_info_copy(struct rdsv3_incoming *inc,
611    struct rdsv3_info_iterator *iter,
612    uint32_be_t saddr, uint32_be_t daddr, int flip);
613
614/* page.c */
615int rdsv3_page_remainder_alloc(struct rdsv3_scatterlist *scat,
616    unsigned long bytes, int gfp);
617
618/* send.c */
619int rdsv3_sendmsg(struct rdsv3_sock *rs, uio_t *uio, struct nmsghdr *msg,
620    size_t payload_len);
621void rdsv3_send_reset(struct rdsv3_connection *conn);
622int rdsv3_send_xmit(struct rdsv3_connection *conn);
623struct sockaddr_in;
624void rdsv3_send_drop_to(struct rdsv3_sock *rs, struct sockaddr_in *dest);
625typedef int (*is_acked_func)(struct rdsv3_message *rm, uint64_t ack);
626void rdsv3_send_drop_acked(struct rdsv3_connection *conn, uint64_t ack,
627    is_acked_func is_acked);
628int rdsv3_send_acked_before(struct rdsv3_connection *conn, uint64_t seq);
629void rdsv3_send_remove_from_sock(struct list *messages, int status);
630int rdsv3_send_pong(struct rdsv3_connection *conn, uint16_be_t dport);
631struct rdsv3_message *rdsv3_send_get_message(struct rdsv3_connection *,
632    struct rdsv3_rdma_op *);
633
634/* rdma.c */
635void rdsv3_rdma_unuse(struct rdsv3_sock *rs, uint32_t r_key, int force);
636
637/* cong.c */
638void rdsv3_cong_init(void);
639int rdsv3_cong_get_maps(struct rdsv3_connection *conn);
640void rdsv3_cong_add_conn(struct rdsv3_connection *conn);
641void rdsv3_cong_remove_conn(struct rdsv3_connection *conn);
642void rdsv3_cong_set_bit(struct rdsv3_cong_map *map, uint16_be_t port);
643void rdsv3_cong_clear_bit(struct rdsv3_cong_map *map, uint16_be_t port);
644int rdsv3_cong_wait(struct rdsv3_cong_map *map, uint16_be_t port, int nonblock,
645    struct rdsv3_sock *rs);
646void rdsv3_cong_queue_updates(struct rdsv3_cong_map *map);
647void rdsv3_cong_map_updated(struct rdsv3_cong_map *map, uint64_t);
648int rdsv3_cong_updated_since(unsigned long *recent);
649void rdsv3_cong_add_socket(struct rdsv3_sock *);
650void rdsv3_cong_remove_socket(struct rdsv3_sock *);
651void rdsv3_cong_exit(void);
652struct rdsv3_message *rdsv3_cong_update_alloc(struct rdsv3_connection *conn);
653
654/* stats.c */
655RDSV3_DECLARE_PER_CPU(struct rdsv3_statistics, rdsv3_stats);
656#define	rdsv3_stats_inc_which(which, member) do {		\
657	rdsv3_per_cpu(which, get_cpu()).member++;		\
658	put_cpu();						\
659} while (0)
660#define	rdsv3_stats_inc(member) rdsv3_stats_inc_which(rdsv3_stats, member)
661#define	rdsv3_stats_add_which(which, member, count) do {	\
662	rdsv3_per_cpu(which, get_cpu()).member += count;	\
663	put_cpu();						\
664} while (0)
665#define	rdsv3_stats_add(member, count)	\
666	rdsv3_stats_add_which(rdsv3_stats, member, count)
667int rdsv3_stats_init(void);
668void rdsv3_stats_exit(void);
669void rdsv3_stats_info_copy(struct rdsv3_info_iterator *iter,
670    uint64_t *values, char **names, size_t nr);
671
672
673/* sysctl.c */
674int rdsv3_sysctl_init(void);
675void rdsv3_sysctl_exit(void);
676extern unsigned long rdsv3_sysctl_sndbuf_min;
677extern unsigned long rdsv3_sysctl_sndbuf_default;
678extern unsigned long rdsv3_sysctl_sndbuf_max;
679extern unsigned long rdsv3_sysctl_reconnect_min_jiffies;
680extern unsigned long rdsv3_sysctl_reconnect_max_jiffies;
681extern unsigned int  rdsv3_sysctl_max_unacked_packets;
682extern unsigned int  rdsv3_sysctl_max_unacked_bytes;
683extern unsigned int  rdsv3_sysctl_ping_enable;
684extern unsigned long rdsv3_sysctl_trace_flags;
685extern unsigned int  rdsv3_sysctl_trace_level;
686
687/* threads.c */
688int rdsv3_threads_init();
689void rdsv3_threads_exit(void);
690extern struct rdsv3_workqueue_struct_s *rdsv3_wq;
691void rdsv3_queue_reconnect(struct rdsv3_connection *conn);
692void rdsv3_connect_worker(struct rdsv3_work_s *);
693void rdsv3_shutdown_worker(struct rdsv3_work_s *);
694void rdsv3_send_worker(struct rdsv3_work_s *);
695void rdsv3_recv_worker(struct rdsv3_work_s *);
696void rdsv3_reaper_worker(struct rdsv3_work_s *);
697void rdsv3_connect_complete(struct rdsv3_connection *conn);
698
699/* transport.c */
700int rdsv3_trans_register(struct rdsv3_transport *trans);
701void rdsv3_trans_unregister(struct rdsv3_transport *trans);
702struct rdsv3_transport *rdsv3_trans_get_preferred(uint32_be_t addr);
703unsigned int rdsv3_trans_stats_info_copy(struct rdsv3_info_iterator *iter,
704    unsigned int avail);
705void rdsv3_trans_exit(void);
706
707/* message.c */
708struct rdsv3_message *rdsv3_message_alloc(unsigned int nents, int gfp);
709struct rdsv3_message *rdsv3_message_copy_from_user(struct uio *uiop,
710    size_t total_len);
711struct rdsv3_message *rdsv3_message_map_pages(unsigned long *page_addrs,
712    unsigned int total_len);
713void rdsv3_message_populate_header(struct rdsv3_header *hdr, uint16_be_t sport,
714    uint16_be_t dport, uint64_t seq);
715int rdsv3_message_add_extension(struct rdsv3_header *hdr,
716    unsigned int type, const void *data, unsigned int len);
717int rdsv3_message_next_extension(struct rdsv3_header *hdr,
718    unsigned int *pos, void *buf, unsigned int *buflen);
719int rdsv3_message_add_version_extension(struct rdsv3_header *hdr,
720    unsigned int version);
721int rdsv3_message_get_version_extension(struct rdsv3_header *hdr,
722    unsigned int *version);
723int rdsv3_message_add_rdma_dest_extension(struct rdsv3_header *hdr,
724    uint32_t r_key, uint32_t offset);
725int rdsv3_message_inc_copy_to_user(struct rdsv3_incoming *inc,
726    uio_t *uio, size_t size);
727void rdsv3_message_inc_free(struct rdsv3_incoming *inc);
728void rdsv3_message_addref(struct rdsv3_message *rm);
729void rdsv3_message_put(struct rdsv3_message *rm);
730void rdsv3_message_wait(struct rdsv3_message *rm);
731void rdsv3_message_unmapped(struct rdsv3_message *rm);
732
733static inline void
734rdsv3_message_make_checksum(struct rdsv3_header *hdr)
735{
736	hdr->h_csum = 0;
737	hdr->h_csum =
738	    rdsv3_ip_fast_csum((void *)hdr, sizeof (*hdr) >> 2);
739}
740
741static inline int
742rdsv3_message_verify_checksum(const struct rdsv3_header *hdr)
743{
744	return (!hdr->h_csum ||
745	    rdsv3_ip_fast_csum((void *)hdr, sizeof (*hdr) >> 2) == 0);
746}
747
748/* rdsv3_sc.c */
749extern boolean_t rdsv3_if_lookup_by_name(char *if_name);
750extern int rdsv3_sc_path_lookup(ipaddr_t *localip, ipaddr_t *remip);
751extern ipaddr_t rdsv3_scaddr_to_ibaddr(ipaddr_t addr);
752
753#ifdef	__cplusplus
754}
755#endif
756
757#endif /* _RDSV3_RDSV3_H */
758