blob: 36e4fb4c0df3d3609f3318d0015eca80bf0fa85a [file] [log] [blame]
Dennis Dalessandro01946212016-01-06 09:50:24 -08001#ifndef DEF_RDMA_VT_H
2#define DEF_RDMA_VT_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 * Structure that low level drivers will populate in order to register with the
53 * rdmavt layer.
54 */
55
Dennis Dalessandrof3d01bb2016-01-06 10:04:13 -080056#include <linux/spinlock.h>
57#include <linux/list.h>
Dennis Dalessandrob4e64392016-01-06 10:04:31 -080058#include <rdma/ib_verbs.h>
59#include <rdma/rdmavt_mr.h>
60#include <rdma/rdmavt_qp.h>
Kamal Heibf2f34212016-01-06 10:03:47 -080061
Dennis Dalessandro8afd32e2016-01-06 09:51:48 -080062/*
Dennis Dalessandro0b8a8aa2016-01-06 10:03:07 -080063 * For some of the IBTA objects there will likely be some
64 * initializations required. We need flags to determine whether it is OK
65 * for rdmavt to do this or not. This does not imply any functions of a
66 * partiuclar IBTA object are overridden.
67 */
68#define RVT_FLAG_MR_INIT_DRIVER BIT(1)
69#define RVT_FLAG_QP_INIT_DRIVER BIT(2)
70#define RVT_FLAG_CQ_INIT_DRIVER BIT(3)
71
Dennis Dalessandro38ce2c62016-01-06 10:05:12 -080072#define RVT_MAX_PKEY_VALUES 16
73
Dennis Dalessandrof3d01bb2016-01-06 10:04:13 -080074struct rvt_ibport {
75 struct rvt_qp __rcu *qp[2];
76 struct ib_mad_agent *send_agent; /* agent for SMI (traps) */
77 struct rb_root mcast_tree;
78 spinlock_t lock; /* protect changes in this struct */
79
80 /* non-zero when timer is set */
81 unsigned long mkey_lease_timeout;
82 unsigned long trap_timeout;
83 __be64 gid_prefix; /* in network order */
84 __be64 mkey;
85 u64 tid;
86 u32 port_cap_flags;
87 u32 pma_sample_start;
88 u32 pma_sample_interval;
89 __be16 pma_counter_select[5];
90 u16 pma_tag;
91 u16 mkey_lease_period;
92 u16 sm_lid;
93 u8 sm_sl;
94 u8 mkeyprot;
95 u8 subnet_timeout;
96 u8 vl_high_limit;
97
98 /*
99 * Driver is expected to keep these up to date. These
100 * counters are informational only and not required to be
101 * completely accurate.
102 */
103 u64 n_rc_resends;
104 u64 n_seq_naks;
105 u64 n_rdma_seq;
106 u64 n_rnr_naks;
107 u64 n_other_naks;
108 u64 n_loop_pkts;
109 u64 n_pkt_drops;
110 u64 n_vl15_dropped;
111 u64 n_rc_timeouts;
112 u64 n_dmawait;
113 u64 n_unaligned;
114 u64 n_rc_dupreq;
115 u64 n_rc_seqnak;
116 u16 pkey_violations;
117 u16 qkey_violations;
118 u16 mkey_violations;
119
120 /* Hot-path per CPU counters to avoid cacheline trading to update */
121 u64 z_rc_acks;
122 u64 z_rc_qacks;
123 u64 z_rc_delayed_comp;
124 u64 __percpu *rc_acks;
125 u64 __percpu *rc_qacks;
126 u64 __percpu *rc_delayed_comp;
127
128 void *priv; /* driver private data */
129
Dennis Dalessandro38ce2c62016-01-06 10:05:12 -0800130 /*
131 * The pkey table is allocated and maintained by the driver. Drivers
132 * need to have access to this before registering with rdmav. However
133 * rdmavt will need access to it so drivers need to proviee this during
134 * the attach port API call.
135 */
136 u16 *pkey_table;
137
Dennis Dalessandrof3d01bb2016-01-06 10:04:13 -0800138 /* TODO: Move sm_ah and smi_ah into here as well*/
139};
140
Dennis Dalessandro6f6387a2016-01-22 13:00:15 -0800141#define RVT_CQN_MAX 16 /* maximum length of cq name */
142
Dennis Dalessandroca889e82016-01-06 10:02:41 -0800143/*
Dennis Dalessandro8afd32e2016-01-06 09:51:48 -0800144 * Things that are driver specific, module parameters in hfi1 and qib
145 */
146struct rvt_driver_params {
Dennis Dalessandrob1070a72016-01-06 09:52:19 -0800147 /*
148 * driver required fields:
149 * node_guid
150 * phys_port_cnt
151 * dma_device
152 * owner
153 * driver optional fields (rvt will provide generic value if blank):
154 * name
155 * node_desc
156 * rvt fields, driver value ignored:
157 * uverbs_abi_ver
158 * node_type
159 * num_comp_vectors
160 * uverbs_cmd_mask
161 */
162 struct ib_device_attr props;
163
164 /*
165 * Drivers will need to support a number of notifications to rvt in
166 * accordance with certain events. This structure should contain a mask
167 * of the supported events. Such events that the rvt may need to know
168 * about include:
169 * port errors
170 * port active
171 * lid change
172 * sm change
173 * client reregister
174 * pkey change
175 *
176 * There may also be other events that the rvt layers needs to know
177 * about this is not an exhaustive list. Some events though rvt does not
178 * need to rely on the driver for such as completion queue error.
179 */
180 int rvt_signal_supported;
181
182 /*
183 * Anything driver specific that is not covered by props
184 * For instance special module parameters. Goes here.
185 */
Dennis Dalessandro7b1e2092016-01-06 10:03:31 -0800186 unsigned int lkey_table_size;
Dennis Dalessandro0acb0cc2016-01-06 10:04:46 -0800187 unsigned int qp_table_size;
188 int qpn_start;
189 int qpn_inc;
190 int qpn_res_start;
191 int qpn_res_end;
Dennis Dalessandrof3d01bb2016-01-06 10:04:13 -0800192 int nports;
Dennis Dalessandro38ce2c62016-01-06 10:05:12 -0800193 int npkeys;
Dennis Dalessandro0acb0cc2016-01-06 10:04:46 -0800194 u8 qos_shift;
Dennis Dalessandro6f6387a2016-01-22 13:00:15 -0800195 char cq_name[RVT_CQN_MAX];
196 int node;
Dennis Dalessandro8afd32e2016-01-06 09:51:48 -0800197};
198
199/* Protection domain */
200struct rvt_pd {
201 struct ib_pd ibpd;
202 int user; /* non-zero if created from user space */
203};
204
Kamal Heib119a8e72016-01-06 10:03:59 -0800205/* Address handle */
206struct rvt_ah {
207 struct ib_ah ibah;
208 struct ib_ah_attr attr;
209 atomic_t refcount;
Dennis Dalessandrob036db82016-01-06 10:04:23 -0800210 u8 vl;
211 u8 log_pmtu;
212};
213
214struct rvt_dev_info;
215struct rvt_driver_provided {
216 /*
217 * The work to create port files in /sys/class Infiniband is different
218 * depending on the driver. This should not be extracted away and
219 * instead drivers are responsible for setting the correct callback for
220 * this.
221 */
222
223 /* -------------------*/
224 /* Required functions */
225 /* -------------------*/
226 int (*port_callback)(struct ib_device *, u8, struct kobject *);
227 const char * (*get_card_name)(struct rvt_dev_info *rdi);
228 struct pci_dev * (*get_pci_dev)(struct rvt_dev_info *rdi);
Dennis Dalessandro515667f2016-01-22 12:50:17 -0800229 unsigned (*free_all_qps)(struct rvt_dev_info *rdi);
Mike Marciniszynd2b8d4d2016-01-22 12:50:43 -0800230 void * (*qp_priv_alloc)(struct rvt_dev_info *rdi, struct rvt_qp *qp,
231 gfp_t gfp);
Dennis Dalessandro515667f2016-01-22 12:50:17 -0800232 void (*qp_priv_free)(struct rvt_dev_info *rdi, struct rvt_qp *qp);
233 void (*notify_qp_reset)(struct rvt_qp *qp);
Dennis Dalessandrobfbac092016-01-22 13:00:22 -0800234 void (*schedule_send)(struct rvt_qp *qp);
235 void (*do_send)(struct rvt_qp *qp);
Dennis Dalessandrob036db82016-01-06 10:04:23 -0800236
237 /*--------------------*/
238 /* Optional functions */
239 /*--------------------*/
240 int (*check_ah)(struct ib_device *, struct ib_ah_attr *);
241 void (*notify_new_ah)(struct ib_device *, struct ib_ah_attr *,
242 struct rvt_ah *);
Dennis Dalessandro515667f2016-01-22 12:50:17 -0800243 int (*alloc_qpn)(struct rvt_dev_info *rdi, struct rvt_qpn_table *qpt,
Mike Marciniszynd2b8d4d2016-01-22 12:50:43 -0800244 enum ib_qp_type type, u8 port, gfp_t gfp);
Kamal Heib119a8e72016-01-06 10:03:59 -0800245};
246
Dennis Dalessandro01946212016-01-06 09:50:24 -0800247struct rvt_dev_info {
Dennis Dalessandro7b1e2092016-01-06 10:03:31 -0800248 struct ib_device ibdev; /* Keep this first. Nothing above here */
249
Dennis Dalessandrob1070a72016-01-06 09:52:19 -0800250 /*
251 * Prior to calling for registration the driver will be responsible for
252 * allocating space for this structure.
253 *
254 * The driver will also be responsible for filling in certain members of
Harish Chegondifeaeb6e2016-01-22 12:50:36 -0800255 * dparms.props. The driver needs to fill in dparms exactly as it would
256 * want values reported to a ULP. This will be returned to the caller
257 * in rdmavt's device. The driver should also therefore refrain from
258 * modifying this directly after registration with rdmavt.
Dennis Dalessandrob1070a72016-01-06 09:52:19 -0800259 */
Dennis Dalessandro8afd32e2016-01-06 09:51:48 -0800260
Dennis Dalessandrob1070a72016-01-06 09:52:19 -0800261 /* Driver specific properties */
Dennis Dalessandro8afd32e2016-01-06 09:51:48 -0800262 struct rvt_driver_params dparms;
Dennis Dalessandrob1070a72016-01-06 09:52:19 -0800263
Dennis Dalessandrob92a7562016-01-06 10:01:42 -0800264 struct rvt_mregion __rcu *dma_mr;
265 struct rvt_lkey_table lkey_table;
266
Dennis Dalessandroaec57782016-01-06 10:02:52 -0800267 /* Driver specific helper functions */
268 struct rvt_driver_provided driver_f;
Dennis Dalessandro01946212016-01-06 09:50:24 -0800269
Dennis Dalessandro8afd32e2016-01-06 09:51:48 -0800270 /* Internal use */
271 int n_pds_allocated;
272 spinlock_t n_pds_lock; /* Protect pd allocated count */
Dennis Dalessandro0b8a8aa2016-01-06 10:03:07 -0800273
Kamal Heib119a8e72016-01-06 10:03:59 -0800274 int n_ahs_allocated;
275 spinlock_t n_ahs_lock; /* Protect ah allocated count */
276
Dennis Dalessandro0b8a8aa2016-01-06 10:03:07 -0800277 int flags;
Dennis Dalessandrof3d01bb2016-01-06 10:04:13 -0800278 struct rvt_ibport **ports;
Dennis Dalessandro0acb0cc2016-01-06 10:04:46 -0800279
Dennis Dalessandro515667f2016-01-22 12:50:17 -0800280 /* QP */
Dennis Dalessandro0acb0cc2016-01-06 10:04:46 -0800281 struct rvt_qp_ibdev *qp_dev;
Dennis Dalessandro515667f2016-01-22 12:50:17 -0800282 u32 n_qps_allocated; /* number of QPs allocated for device */
283 spinlock_t n_qps_lock; /* keep track of number of qps */
Dennis Dalessandro822514d2016-01-06 10:04:57 -0800284
285 /* memory maps */
286 struct list_head pending_mmaps;
287 spinlock_t mmap_offset_lock; /* protect mmap_offset */
288 u32 mmap_offset;
289 spinlock_t pending_lock; /* protect pending mmap list */
Dennis Dalessandro6f6387a2016-01-22 13:00:15 -0800290
291 /* CQ */
292 struct kthread_worker *worker; /* per device cq worker */
293 u32 n_cqs_allocated; /* number of CQs allocated for device */
294 spinlock_t n_cqs_lock; /* protect count of in use cqs */
Dennis Dalessandro01946212016-01-06 09:50:24 -0800295};
296
Dennis Dalessandro8afd32e2016-01-06 09:51:48 -0800297static inline struct rvt_pd *ibpd_to_rvtpd(struct ib_pd *ibpd)
298{
299 return container_of(ibpd, struct rvt_pd, ibpd);
300}
301
Kamal Heib119a8e72016-01-06 10:03:59 -0800302static inline struct rvt_ah *ibah_to_rvtah(struct ib_ah *ibah)
303{
304 return container_of(ibah, struct rvt_ah, ibah);
305}
306
Dennis Dalessandro8afd32e2016-01-06 09:51:48 -0800307static inline struct rvt_dev_info *ib_to_rvt(struct ib_device *ibdev)
308{
309 return container_of(ibdev, struct rvt_dev_info, ibdev);
310}
311
Dennis Dalessandro70a1a352016-01-06 10:04:06 -0800312static inline struct rvt_srq *ibsrq_to_rvtsrq(struct ib_srq *ibsrq)
313{
314 return container_of(ibsrq, struct rvt_srq, ibsrq);
315}
316
Dennis Dalessandrobfbac092016-01-22 13:00:22 -0800317static inline struct rvt_qp *ibqp_to_rvtqp(struct ib_qp *ibqp)
318{
319 return container_of(ibqp, struct rvt_qp, ibqp);
320}
321
Dennis Dalessandro38ce2c62016-01-06 10:05:12 -0800322static inline unsigned rvt_get_npkeys(struct rvt_dev_info *rdi)
323{
324 /*
325 * All ports have same number of pkeys.
326 */
327 return rdi->dparms.npkeys;
328}
329
330/*
331 * Return the indexed PKEY from the port PKEY table.
332 */
333static inline u16 rvt_get_pkey(struct rvt_dev_info *rdi,
334 int port_index,
335 unsigned index)
336{
337 if (index >= rvt_get_npkeys(rdi))
338 return 0;
339 else
340 return rdi->ports[port_index]->pkey_table[index];
341}
342
Dennis Dalessandro01946212016-01-06 09:50:24 -0800343int rvt_register_device(struct rvt_dev_info *rvd);
344void rvt_unregister_device(struct rvt_dev_info *rvd);
Kamal Heib119a8e72016-01-06 10:03:59 -0800345int rvt_check_ah(struct ib_device *ibdev, struct ib_ah_attr *ah_attr);
Dennis Dalessandro38ce2c62016-01-06 10:05:12 -0800346int rvt_init_port(struct rvt_dev_info *rdi, struct rvt_ibport *port,
347 int portnum, u16 *pkey_table);
Dennis Dalessandro7b1e2092016-01-06 10:03:31 -0800348int rvt_rkey_ok(struct rvt_qp *qp, struct rvt_sge *sge,
349 u32 len, u64 vaddr, u32 rkey, int acc);
350int rvt_lkey_ok(struct rvt_lkey_table *rkt, struct rvt_pd *pd,
351 struct rvt_sge *isge, struct ib_sge *sge, int acc);
Dennis Dalessandro822514d2016-01-06 10:04:57 -0800352int rvt_mmap(struct ib_ucontext *context, struct vm_area_struct *vma);
353void rvt_release_mmap_info(struct kref *ref);
354struct rvt_mmap_info *rvt_create_mmap_info(struct rvt_dev_info *rdi,
355 u32 size,
356 struct ib_ucontext *context,
357 void *obj);
358void rvt_update_mmap_info(struct rvt_dev_info *rdi, struct rvt_mmap_info *ip,
359 u32 size, void *obj);
360
Dennis Dalessandro5a9cf6f2016-01-22 12:50:24 -0800361/* Temporary export */
362void rvt_reset_qp(struct rvt_dev_info *rdi, struct rvt_qp *qp,
363 enum ib_qp_type type);
Dennis Dalessandro01946212016-01-06 09:50:24 -0800364#endif /* DEF_RDMA_VT_H */