xref: /illumos-gate/usr/src/uts/common/sys/ib/clients/rdsv3/rdma.h (revision b1d7ec75953cd517f5b7c3d9cb427ff8ec5d7d07)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
23  */
24 
25 #ifndef _RDSV3_RDMA_H
26 #define	_RDSV3_RDMA_H
27 
28 #include <sys/rds.h>
29 #include <sys/uio.h>
30 
31 #include <sys/ib/clients/rdsv3/rdsv3.h>
32 
33 struct rdsv3_mr {
34 	/* for AVL tree */
35 	avl_node_t		r_rb_node;
36 	atomic_t		r_refcount;
37 	uint32_t		r_key;
38 
39 	/* A copy of the creation flags */
40 	unsigned int		r_use_once:1;
41 	unsigned int		r_invalidate:1;
42 	unsigned int		r_write:1;
43 
44 	/*
45 	 * This is for RDS_MR_DEAD.
46 	 * It would be nice & consistent to make this part of the above
47 	 * bit field here, but we need to use test_and_set_bit.
48 	 */
49 	unsigned long		r_state;
50 	/* back pointer to the socket that owns us */
51 	struct rdsv3_sock	*r_sock;
52 	struct rdsv3_transport	*r_trans;
53 	void			*r_trans_private;
54 };
55 
56 /* Flags for mr->r_state */
57 #define	RDSV3_MR_DEAD		0
58 
59 struct rdsv3_rdma_sg {
60 	ddi_umem_cookie_t umem_cookie;
61 	struct rdsv3_iovec iovec;
62 	ibt_send_wr_t	swr;
63 	ibt_mi_hdl_t	mihdl;
64 	ibt_hca_hdl_t	hca_hdl;
65 };
66 
67 struct rdsv3_rdma_op {
68 	uint32_t		r_key;
69 	uint64_t		r_remote_addr;
70 	unsigned int		r_write:1;
71 	unsigned int		r_fence:1;
72 	unsigned int		r_notify:1;
73 	unsigned int		r_recverr:1;
74 	unsigned int		r_mapped:1;
75 	struct rdsv3_notifier	*r_notifier;
76 	unsigned int		r_bytes;
77 	unsigned int		r_nents;
78 	unsigned int		r_count;
79 	struct rdsv3_scatterlist  *r_sg;
80 	struct rdsv3_rdma_sg	r_rdma_sg[1];
81 };
82 
83 static inline rdsv3_rdma_cookie_t
84 rdsv3_rdma_make_cookie(uint32_t r_key, uint32_t offset)
85 {
86 	return (r_key | (((uint64_t)offset) << 32));
87 }
88 
89 static inline uint32_t
90 rdsv3_rdma_cookie_key(rdsv3_rdma_cookie_t cookie)
91 {
92 	return ((uint32_t)cookie);
93 }
94 
95 static inline uint32_t
96 rdsv3_rdma_cookie_offset(rdsv3_rdma_cookie_t cookie)
97 {
98 	return (cookie >> 32);
99 }
100 
101 int rdsv3_get_mr(struct rdsv3_sock *rs, const void *optval, int optlen);
102 int rdsv3_get_mr_for_dest(struct rdsv3_sock *rs, const void *optval,
103     int optlen);
104 int rdsv3_free_mr(struct rdsv3_sock *rs, const void *optval, int optlen);
105 void rdsv3_rdma_drop_keys(struct rdsv3_sock *rs);
106 int rdsv3_cmsg_rdma_args(struct rdsv3_sock *rs, struct rdsv3_message *rm,
107     struct cmsghdr *cmsg);
108 int rdsv3_cmsg_rdma_dest(struct rdsv3_sock *rs, struct rdsv3_message *rm,
109     struct cmsghdr *cmsg);
110 int rdsv3_cmsg_rdma_map(struct rdsv3_sock *rs, struct rdsv3_message *rm,
111     struct cmsghdr *cmsg);
112 void rdsv3_rdma_free_op(struct rdsv3_rdma_op *ro);
113 void rdsv3_rdma_send_complete(struct rdsv3_message *rm, int);
114 
115 extern void __rdsv3_put_mr_final(struct rdsv3_mr *mr);
116 static inline void rdsv3_mr_put(struct rdsv3_mr *mr)
117 {
118 	if (atomic_dec_and_test(&mr->r_refcount))
119 		__rdsv3_put_mr_final(mr);
120 }
121 
122 #endif /* _RDSV3_RDMA_H */
123