]>
Commit | Line | Data |
---|---|---|
b4e64397 DD |
1 | #ifndef DEF_RDMAVT_INCQP_H |
2 | #define DEF_RDMAVT_INCQP_H | |
3 | ||
4 | /* | |
5 | * Copyright(c) 2015 Intel Corporation. | |
6 | * | |
7 | * This file is provided under a dual BSD/GPLv2 license. When using or | |
8 | * redistributing this file, you may do so under either license. | |
9 | * | |
10 | * GPL LICENSE SUMMARY | |
11 | * | |
12 | * This program is free software; you can redistribute it and/or modify | |
13 | * it under the terms of version 2 of the GNU General Public License as | |
14 | * published by the Free Software Foundation. | |
15 | * | |
16 | * This program is distributed in the hope that it will be useful, but | |
17 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
19 | * General Public License for more details. | |
20 | * | |
21 | * BSD LICENSE | |
22 | * | |
23 | * Redistribution and use in source and binary forms, with or without | |
24 | * modification, are permitted provided that the following conditions | |
25 | * are met: | |
26 | * | |
27 | * - Redistributions of source code must retain the above copyright | |
28 | * notice, this list of conditions and the following disclaimer. | |
29 | * - Redistributions in binary form must reproduce the above copyright | |
30 | * notice, this list of conditions and the following disclaimer in | |
31 | * the documentation and/or other materials provided with the | |
32 | * distribution. | |
33 | * - Neither the name of Intel Corporation nor the names of its | |
34 | * contributors may be used to endorse or promote products derived | |
35 | * from this software without specific prior written permission. | |
36 | * | |
37 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
38 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
39 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
40 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
41 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
42 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
43 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
44 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
45 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
46 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
47 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
48 | * | |
49 | */ | |
50 | ||
51 | /* | |
52 | * Send work request queue entry. | |
53 | * The size of the sg_list is determined when the QP is created and stored | |
54 | * in qp->s_max_sge. | |
55 | */ | |
56 | struct rvt_swqe { | |
57 | union { | |
58 | struct ib_send_wr wr; /* don't use wr.sg_list */ | |
59 | struct ib_ud_wr ud_wr; | |
60 | struct ib_reg_wr reg_wr; | |
61 | struct ib_rdma_wr rdma_wr; | |
62 | struct ib_atomic_wr atomic_wr; | |
63 | }; | |
64 | u32 psn; /* first packet sequence number */ | |
65 | u32 lpsn; /* last packet sequence number */ | |
66 | u32 ssn; /* send sequence number */ | |
67 | u32 length; /* total length of data in sg_list */ | |
68 | struct rvt_sge sg_list[0]; | |
69 | }; | |
70 | ||
71 | /* | |
72 | * Receive work request queue entry. | |
73 | * The size of the sg_list is determined when the QP (or SRQ) is created | |
74 | * and stored in qp->r_rq.max_sge (or srq->rq.max_sge). | |
75 | */ | |
76 | struct rvt_rwqe { | |
77 | u64 wr_id; | |
78 | u8 num_sge; | |
79 | struct ib_sge sg_list[0]; | |
80 | }; | |
81 | ||
82 | /* | |
83 | * This structure is used to contain the head pointer, tail pointer, | |
84 | * and receive work queue entries as a single memory allocation so | |
85 | * it can be mmap'ed into user space. | |
86 | * Note that the wq array elements are variable size so you can't | |
87 | * just index into the array to get the N'th element; | |
88 | * use get_rwqe_ptr() instead. | |
89 | */ | |
90 | struct rvt_rwq { | |
91 | u32 head; /* new work requests posted to the head */ | |
92 | u32 tail; /* receives pull requests from here. */ | |
93 | struct rvt_rwqe wq[0]; | |
94 | }; | |
95 | ||
96 | struct rvt_rq { | |
97 | struct rvt_rwq *wq; | |
98 | u32 size; /* size of RWQE array */ | |
99 | u8 max_sge; | |
100 | /* protect changes in this struct */ | |
101 | spinlock_t lock ____cacheline_aligned_in_smp; | |
102 | }; | |
103 | ||
104 | /* | |
105 | * This structure is used by rvt_mmap() to validate an offset | |
106 | * when an mmap() request is made. The vm_area_struct then uses | |
107 | * this as its vm_private_data. | |
108 | */ | |
109 | struct rvt_mmap_info { | |
110 | struct list_head pending_mmaps; | |
111 | struct ib_ucontext *context; | |
112 | void *obj; | |
113 | __u64 offset; | |
114 | struct kref ref; | |
115 | unsigned size; | |
116 | }; | |
117 | ||
118 | #define RVT_MAX_RDMA_ATOMIC 16 | |
119 | ||
120 | /* | |
121 | * This structure holds the information that the send tasklet needs | |
122 | * to send a RDMA read response or atomic operation. | |
123 | */ | |
124 | struct rvt_ack_entry { | |
125 | u8 opcode; | |
126 | u8 sent; | |
127 | u32 psn; | |
128 | u32 lpsn; | |
129 | union { | |
130 | struct rvt_sge rdma_sge; | |
131 | u64 atomic_data; | |
132 | }; | |
133 | }; | |
134 | ||
135 | /* | |
136 | * Variables prefixed with s_ are for the requester (sender). | |
137 | * Variables prefixed with r_ are for the responder (receiver). | |
138 | * Variables prefixed with ack_ are for responder replies. | |
139 | * | |
140 | * Common variables are protected by both r_rq.lock and s_lock in that order | |
141 | * which only happens in modify_qp() or changing the QP 'state'. | |
142 | */ | |
143 | struct rvt_qp { | |
144 | struct ib_qp ibqp; | |
145 | void *priv; /* Driver private data */ | |
146 | /* read mostly fields above and below */ | |
147 | struct ib_ah_attr remote_ah_attr; | |
148 | struct ib_ah_attr alt_ah_attr; | |
149 | struct rvt_qp __rcu *next; /* link list for QPN hash table */ | |
150 | struct rvt_swqe *s_wq; /* send work queue */ | |
151 | struct rvt_mmap_info *ip; | |
152 | ||
153 | unsigned long timeout_jiffies; /* computed from timeout */ | |
154 | ||
155 | enum ib_mtu path_mtu; | |
156 | int srate_mbps; /* s_srate (below) converted to Mbit/s */ | |
157 | u32 remote_qpn; | |
158 | u32 pmtu; /* decoded from path_mtu */ | |
159 | u32 qkey; /* QKEY for this QP (for UD or RD) */ | |
160 | u32 s_size; /* send work queue size */ | |
161 | u32 s_rnr_timeout; /* number of milliseconds for RNR timeout */ | |
162 | u32 s_ahgpsn; /* set to the psn in the copy of the header */ | |
163 | ||
164 | u8 state; /* QP state */ | |
165 | u8 allowed_ops; /* high order bits of allowed opcodes */ | |
166 | u8 qp_access_flags; | |
167 | u8 alt_timeout; /* Alternate path timeout for this QP */ | |
168 | u8 timeout; /* Timeout for this QP */ | |
169 | u8 s_srate; | |
170 | u8 s_mig_state; | |
171 | u8 port_num; | |
172 | u8 s_pkey_index; /* PKEY index to use */ | |
173 | u8 s_alt_pkey_index; /* Alternate path PKEY index to use */ | |
174 | u8 r_max_rd_atomic; /* max number of RDMA read/atomic to receive */ | |
175 | u8 s_max_rd_atomic; /* max number of RDMA read/atomic to send */ | |
176 | u8 s_retry_cnt; /* number of times to retry */ | |
177 | u8 s_rnr_retry_cnt; | |
178 | u8 r_min_rnr_timer; /* retry timeout value for RNR NAKs */ | |
179 | u8 s_max_sge; /* size of s_wq->sg_list */ | |
180 | u8 s_draining; | |
181 | ||
182 | /* start of read/write fields */ | |
183 | atomic_t refcount ____cacheline_aligned_in_smp; | |
184 | wait_queue_head_t wait; | |
185 | ||
186 | struct rvt_ack_entry s_ack_queue[RVT_MAX_RDMA_ATOMIC + 1] | |
187 | ____cacheline_aligned_in_smp; | |
188 | struct rvt_sge_state s_rdma_read_sge; | |
189 | ||
190 | spinlock_t r_lock ____cacheline_aligned_in_smp; /* used for APM */ | |
191 | unsigned long r_aflags; | |
192 | u64 r_wr_id; /* ID for current receive WQE */ | |
193 | u32 r_ack_psn; /* PSN for next ACK or atomic ACK */ | |
194 | u32 r_len; /* total length of r_sge */ | |
195 | u32 r_rcv_len; /* receive data len processed */ | |
196 | u32 r_psn; /* expected rcv packet sequence number */ | |
197 | u32 r_msn; /* message sequence number */ | |
198 | ||
199 | u8 r_state; /* opcode of last packet received */ | |
200 | u8 r_flags; | |
201 | u8 r_head_ack_queue; /* index into s_ack_queue[] */ | |
202 | ||
203 | struct list_head rspwait; /* link for waiting to respond */ | |
204 | ||
205 | struct rvt_sge_state r_sge; /* current receive data */ | |
206 | struct rvt_rq r_rq; /* receive work queue */ | |
207 | ||
208 | spinlock_t s_lock ____cacheline_aligned_in_smp; | |
209 | struct rvt_sge_state *s_cur_sge; | |
210 | u32 s_flags; | |
211 | struct rvt_swqe *s_wqe; | |
212 | struct rvt_sge_state s_sge; /* current send request data */ | |
213 | struct rvt_mregion *s_rdma_mr; | |
214 | struct sdma_engine *s_sde; /* current sde */ | |
215 | u32 s_cur_size; /* size of send packet in bytes */ | |
216 | u32 s_len; /* total length of s_sge */ | |
217 | u32 s_rdma_read_len; /* total length of s_rdma_read_sge */ | |
218 | u32 s_next_psn; /* PSN for next request */ | |
219 | u32 s_last_psn; /* last response PSN processed */ | |
220 | u32 s_sending_psn; /* lowest PSN that is being sent */ | |
221 | u32 s_sending_hpsn; /* highest PSN that is being sent */ | |
222 | u32 s_psn; /* current packet sequence number */ | |
223 | u32 s_ack_rdma_psn; /* PSN for sending RDMA read responses */ | |
224 | u32 s_ack_psn; /* PSN for acking sends and RDMA writes */ | |
225 | u32 s_head; /* new entries added here */ | |
226 | u32 s_tail; /* next entry to process */ | |
227 | u32 s_cur; /* current work queue entry */ | |
228 | u32 s_acked; /* last un-ACK'ed entry */ | |
229 | u32 s_last; /* last completed entry */ | |
230 | u32 s_ssn; /* SSN of tail entry */ | |
231 | u32 s_lsn; /* limit sequence number (credit) */ | |
232 | u16 s_hdrwords; /* size of s_hdr in 32 bit words */ | |
233 | u16 s_rdma_ack_cnt; | |
234 | s8 s_ahgidx; | |
235 | u8 s_state; /* opcode of last packet sent */ | |
236 | u8 s_ack_state; /* opcode of packet to ACK */ | |
237 | u8 s_nak_state; /* non-zero if NAK is pending */ | |
238 | u8 r_nak_state; /* non-zero if NAK is pending */ | |
239 | u8 s_retry; /* requester retry counter */ | |
240 | u8 s_rnr_retry; /* requester RNR retry counter */ | |
241 | u8 s_num_rd_atomic; /* number of RDMA read/atomic pending */ | |
242 | u8 s_tail_ack_queue; /* index into s_ack_queue[] */ | |
243 | ||
244 | struct rvt_sge_state s_ack_rdma_sge; | |
245 | struct timer_list s_timer; | |
246 | ||
247 | /* | |
248 | * This sge list MUST be last. Do not add anything below here. | |
249 | */ | |
250 | struct rvt_sge r_sg_list[0] /* verified SGEs */ | |
251 | ____cacheline_aligned_in_smp; | |
252 | }; | |
253 | ||
254 | struct rvt_srq { | |
255 | struct ib_srq ibsrq; | |
256 | struct rvt_rq rq; | |
257 | struct rvt_mmap_info *ip; | |
258 | /* send signal when number of RWQEs < limit */ | |
259 | u32 limit; | |
260 | }; | |
261 | ||
0acb0cc7 DD |
262 | #define RVT_QPN_MAX BIT(24) |
263 | #define RVT_QPNMAP_ENTRIES (RVT_QPN_MAX / PAGE_SIZE / BITS_PER_BYTE) | |
264 | #define RVT_BITS_PER_PAGE (PAGE_SIZE * BITS_PER_BYTE) | |
265 | #define RVT_BITS_PER_PAGE_MASK (RVT_BITS_PER_PAGE - 1) | |
266 | ||
267 | /* | |
268 | * QPN-map pages start out as NULL, they get allocated upon | |
269 | * first use and are never deallocated. This way, | |
270 | * large bitmaps are not allocated unless large numbers of QPs are used. | |
271 | */ | |
272 | struct rvt_qpn_map { | |
273 | void *page; | |
274 | }; | |
275 | ||
276 | struct rvt_qpn_table { | |
277 | spinlock_t lock; /* protect changes to the qp table */ | |
278 | unsigned flags; /* flags for QP0/1 allocated for each port */ | |
279 | u32 last; /* last QP number allocated */ | |
280 | u32 nmaps; /* size of the map table */ | |
281 | u16 limit; | |
282 | u8 incr; | |
283 | /* bit map of free QP numbers other than 0/1 */ | |
284 | struct rvt_qpn_map map[RVT_QPNMAP_ENTRIES]; | |
285 | }; | |
286 | ||
287 | struct rvt_qp_ibdev { | |
288 | u32 qp_table_size; | |
289 | u32 qp_table_bits; | |
290 | struct rvt_qp __rcu **qp_table; | |
291 | spinlock_t qpt_lock; /* qptable lock */ | |
292 | struct rvt_qpn_table qpn_table; | |
293 | }; | |
294 | ||
b4e64397 | 295 | #endif /* DEF_RDMAVT_INCQP_H */ |