xref: /freebsd/sys/ofed/include/rdma/rdma_vt.h (revision 95ee2897e98f5d444f26ed2334cc7c439f9c16c6)
1478d3005SHans Petter Selasky #ifndef DEF_RDMA_VT_H
2478d3005SHans Petter Selasky #define DEF_RDMA_VT_H
3478d3005SHans Petter Selasky 
4*09938b21SHans Petter Selasky /*-
5*09938b21SHans Petter Selasky  * SPDX-License-Identifier: BSD-2-Clause OR GPL-2.0
6*09938b21SHans Petter Selasky  *
7478d3005SHans Petter Selasky  * Copyright(c) 2016 Intel Corporation.
8478d3005SHans Petter Selasky  *
9478d3005SHans Petter Selasky  * This file is provided under a dual BSD/GPLv2 license.  When using or
10478d3005SHans Petter Selasky  * redistributing this file, you may do so under either license.
11478d3005SHans Petter Selasky  *
12478d3005SHans Petter Selasky  * GPL LICENSE SUMMARY
13478d3005SHans Petter Selasky  *
14478d3005SHans Petter Selasky  * This program is free software; you can redistribute it and/or modify
15478d3005SHans Petter Selasky  * it under the terms of version 2 of the GNU General Public License as
16478d3005SHans Petter Selasky  * published by the Free Software Foundation.
17478d3005SHans Petter Selasky  *
18478d3005SHans Petter Selasky  * This program is distributed in the hope that it will be useful, but
19478d3005SHans Petter Selasky  * WITHOUT ANY WARRANTY; without even the implied warranty of
20478d3005SHans Petter Selasky  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
21478d3005SHans Petter Selasky  * General Public License for more details.
22478d3005SHans Petter Selasky  *
23478d3005SHans Petter Selasky  * BSD LICENSE
24478d3005SHans Petter Selasky  *
25478d3005SHans Petter Selasky  * Redistribution and use in source and binary forms, with or without
26478d3005SHans Petter Selasky  * modification, are permitted provided that the following conditions
27478d3005SHans Petter Selasky  * are met:
28478d3005SHans Petter Selasky  *
29478d3005SHans Petter Selasky  *  - Redistributions of source code must retain the above copyright
30478d3005SHans Petter Selasky  *    notice, this list of conditions and the following disclaimer.
31478d3005SHans Petter Selasky  *  - Redistributions in binary form must reproduce the above copyright
32478d3005SHans Petter Selasky  *    notice, this list of conditions and the following disclaimer in
33478d3005SHans Petter Selasky  *    the documentation and/or other materials provided with the
34478d3005SHans Petter Selasky  *    distribution.
35478d3005SHans Petter Selasky  *  - Neither the name of Intel Corporation nor the names of its
36478d3005SHans Petter Selasky  *    contributors may be used to endorse or promote products derived
37478d3005SHans Petter Selasky  *    from this software without specific prior written permission.
38478d3005SHans Petter Selasky  *
39478d3005SHans Petter Selasky  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
40478d3005SHans Petter Selasky  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
41478d3005SHans Petter Selasky  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
42478d3005SHans Petter Selasky  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
43478d3005SHans Petter Selasky  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44478d3005SHans Petter Selasky  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
45478d3005SHans Petter Selasky  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
46478d3005SHans Petter Selasky  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
47478d3005SHans Petter Selasky  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
48478d3005SHans Petter Selasky  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
49478d3005SHans Petter Selasky  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
50478d3005SHans Petter Selasky  */
51478d3005SHans Petter Selasky 
52478d3005SHans Petter Selasky /*
53478d3005SHans Petter Selasky  * Structure that low level drivers will populate in order to register with the
54478d3005SHans Petter Selasky  * rdmavt layer.
55478d3005SHans Petter Selasky  */
56478d3005SHans Petter Selasky 
57478d3005SHans Petter Selasky #include <linux/spinlock.h>
58478d3005SHans Petter Selasky #include <linux/list.h>
59478d3005SHans Petter Selasky #include <linux/hash.h>
60478d3005SHans Petter Selasky #include <rdma/ib_verbs.h>
61478d3005SHans Petter Selasky #include <rdma/rdmavt_mr.h>
62478d3005SHans Petter Selasky #include <rdma/rdmavt_qp.h>
63478d3005SHans Petter Selasky 
64478d3005SHans Petter Selasky #define RVT_MAX_PKEY_VALUES 16
65478d3005SHans Petter Selasky 
66478d3005SHans Petter Selasky struct rvt_ibport {
67478d3005SHans Petter Selasky 	struct rvt_qp __rcu *qp[2];
68478d3005SHans Petter Selasky 	struct ib_mad_agent *send_agent;	/* agent for SMI (traps) */
69478d3005SHans Petter Selasky 	struct rb_root mcast_tree;
70478d3005SHans Petter Selasky 	spinlock_t lock;		/* protect changes in this struct */
71478d3005SHans Petter Selasky 
72478d3005SHans Petter Selasky 	/* non-zero when timer is set */
73478d3005SHans Petter Selasky 	unsigned long mkey_lease_timeout;
74478d3005SHans Petter Selasky 	unsigned long trap_timeout;
75478d3005SHans Petter Selasky 	__be64 gid_prefix;      /* in network order */
76478d3005SHans Petter Selasky 	__be64 mkey;
77478d3005SHans Petter Selasky 	u64 tid;
78478d3005SHans Petter Selasky 	u32 port_cap_flags;
79478d3005SHans Petter Selasky 	u32 pma_sample_start;
80478d3005SHans Petter Selasky 	u32 pma_sample_interval;
81478d3005SHans Petter Selasky 	__be16 pma_counter_select[5];
82478d3005SHans Petter Selasky 	u16 pma_tag;
83478d3005SHans Petter Selasky 	u16 mkey_lease_period;
84478d3005SHans Petter Selasky 	u16 sm_lid;
85478d3005SHans Petter Selasky 	u8 sm_sl;
86478d3005SHans Petter Selasky 	u8 mkeyprot;
87478d3005SHans Petter Selasky 	u8 subnet_timeout;
88478d3005SHans Petter Selasky 	u8 vl_high_limit;
89478d3005SHans Petter Selasky 
90478d3005SHans Petter Selasky 	/*
91478d3005SHans Petter Selasky 	 * Driver is expected to keep these up to date. These
92478d3005SHans Petter Selasky 	 * counters are informational only and not required to be
93478d3005SHans Petter Selasky 	 * completely accurate.
94478d3005SHans Petter Selasky 	 */
95478d3005SHans Petter Selasky 	u64 n_rc_resends;
96478d3005SHans Petter Selasky 	u64 n_seq_naks;
97478d3005SHans Petter Selasky 	u64 n_rdma_seq;
98478d3005SHans Petter Selasky 	u64 n_rnr_naks;
99478d3005SHans Petter Selasky 	u64 n_other_naks;
100478d3005SHans Petter Selasky 	u64 n_loop_pkts;
101478d3005SHans Petter Selasky 	u64 n_pkt_drops;
102478d3005SHans Petter Selasky 	u64 n_vl15_dropped;
103478d3005SHans Petter Selasky 	u64 n_rc_timeouts;
104478d3005SHans Petter Selasky 	u64 n_dmawait;
105478d3005SHans Petter Selasky 	u64 n_unaligned;
106478d3005SHans Petter Selasky 	u64 n_rc_dupreq;
107478d3005SHans Petter Selasky 	u64 n_rc_seqnak;
108478d3005SHans Petter Selasky 	u16 pkey_violations;
109478d3005SHans Petter Selasky 	u16 qkey_violations;
110478d3005SHans Petter Selasky 	u16 mkey_violations;
111478d3005SHans Petter Selasky 
112478d3005SHans Petter Selasky 	/* Hot-path per CPU counters to avoid cacheline trading to update */
113478d3005SHans Petter Selasky 	u64 z_rc_acks;
114478d3005SHans Petter Selasky 	u64 z_rc_qacks;
115478d3005SHans Petter Selasky 	u64 z_rc_delayed_comp;
116478d3005SHans Petter Selasky 	u64 __percpu *rc_acks;
117478d3005SHans Petter Selasky 	u64 __percpu *rc_qacks;
118478d3005SHans Petter Selasky 	u64 __percpu *rc_delayed_comp;
119478d3005SHans Petter Selasky 
120478d3005SHans Petter Selasky 	void *priv; /* driver private data */
121478d3005SHans Petter Selasky 
122478d3005SHans Petter Selasky 	/*
123478d3005SHans Petter Selasky 	 * The pkey table is allocated and maintained by the driver. Drivers
124478d3005SHans Petter Selasky 	 * need to have access to this before registering with rdmav. However
125478d3005SHans Petter Selasky 	 * rdmavt will need access to it so drivers need to proviee this during
126478d3005SHans Petter Selasky 	 * the attach port API call.
127478d3005SHans Petter Selasky 	 */
128478d3005SHans Petter Selasky 	u16 *pkey_table;
129478d3005SHans Petter Selasky 
130478d3005SHans Petter Selasky 	struct rvt_ah *sm_ah;
131478d3005SHans Petter Selasky };
132478d3005SHans Petter Selasky 
133478d3005SHans Petter Selasky #define RVT_CQN_MAX 16 /* maximum length of cq name */
134478d3005SHans Petter Selasky 
135478d3005SHans Petter Selasky /*
136478d3005SHans Petter Selasky  * Things that are driver specific, module parameters in hfi1 and qib
137478d3005SHans Petter Selasky  */
138478d3005SHans Petter Selasky struct rvt_driver_params {
139478d3005SHans Petter Selasky 	struct ib_device_attr props;
140478d3005SHans Petter Selasky 
141478d3005SHans Petter Selasky 	/*
142478d3005SHans Petter Selasky 	 * Anything driver specific that is not covered by props
143478d3005SHans Petter Selasky 	 * For instance special module parameters. Goes here.
144478d3005SHans Petter Selasky 	 */
145478d3005SHans Petter Selasky 	unsigned int lkey_table_size;
146478d3005SHans Petter Selasky 	unsigned int qp_table_size;
147478d3005SHans Petter Selasky 	int qpn_start;
148478d3005SHans Petter Selasky 	int qpn_inc;
149478d3005SHans Petter Selasky 	int qpn_res_start;
150478d3005SHans Petter Selasky 	int qpn_res_end;
151478d3005SHans Petter Selasky 	int nports;
152478d3005SHans Petter Selasky 	int npkeys;
153478d3005SHans Petter Selasky 	char cq_name[RVT_CQN_MAX];
154478d3005SHans Petter Selasky 	int node;
155478d3005SHans Petter Selasky 	int psn_mask;
156478d3005SHans Petter Selasky 	int psn_shift;
157478d3005SHans Petter Selasky 	int psn_modify_mask;
158478d3005SHans Petter Selasky 	u32 core_cap_flags;
159478d3005SHans Petter Selasky 	u32 max_mad_size;
160478d3005SHans Petter Selasky 	u8 qos_shift;
161478d3005SHans Petter Selasky 	u8 max_rdma_atomic;
162478d3005SHans Petter Selasky 	u8 reserved_operations;
163478d3005SHans Petter Selasky };
164478d3005SHans Petter Selasky 
165478d3005SHans Petter Selasky /* Protection domain */
166478d3005SHans Petter Selasky struct rvt_pd {
167478d3005SHans Petter Selasky 	struct ib_pd ibpd;
168478d3005SHans Petter Selasky 	int user;               /* non-zero if created from user space */
169478d3005SHans Petter Selasky };
170478d3005SHans Petter Selasky 
171478d3005SHans Petter Selasky /* Address handle */
172478d3005SHans Petter Selasky struct rvt_ah {
173478d3005SHans Petter Selasky 	struct ib_ah ibah;
174478d3005SHans Petter Selasky 	struct ib_ah_attr attr;
175478d3005SHans Petter Selasky 	atomic_t refcount;
176478d3005SHans Petter Selasky 	u8 vl;
177478d3005SHans Petter Selasky 	u8 log_pmtu;
178478d3005SHans Petter Selasky };
179478d3005SHans Petter Selasky 
180478d3005SHans Petter Selasky struct rvt_dev_info;
181478d3005SHans Petter Selasky struct rvt_swqe;
182478d3005SHans Petter Selasky struct rvt_driver_provided {
183478d3005SHans Petter Selasky 	/*
184478d3005SHans Petter Selasky 	 * Which functions are required depends on which verbs rdmavt is
185478d3005SHans Petter Selasky 	 * providing and which verbs the driver is overriding. See
186478d3005SHans Petter Selasky 	 * check_support() for details.
187478d3005SHans Petter Selasky 	 */
188478d3005SHans Petter Selasky 
189478d3005SHans Petter Selasky 	/* Passed to ib core registration. Callback to create syfs files */
190478d3005SHans Petter Selasky 	int (*port_callback)(struct ib_device *, u8, struct kobject *);
191478d3005SHans Petter Selasky 
192478d3005SHans Petter Selasky 	/*
193478d3005SHans Petter Selasky 	 * Returns a string to represent the device for which is being
194478d3005SHans Petter Selasky 	 * registered. This is primarily used for error and debug messages on
195478d3005SHans Petter Selasky 	 * the console.
196478d3005SHans Petter Selasky 	 */
197478d3005SHans Petter Selasky 	const char * (*get_card_name)(struct rvt_dev_info *rdi);
198478d3005SHans Petter Selasky 
199478d3005SHans Petter Selasky 	/*
200478d3005SHans Petter Selasky 	 * Returns a pointer to the undelying hardware's PCI device. This is
201478d3005SHans Petter Selasky 	 * used to display information as to what hardware is being referenced
202478d3005SHans Petter Selasky 	 * in an output message
203478d3005SHans Petter Selasky 	 */
204478d3005SHans Petter Selasky 	struct pci_dev * (*get_pci_dev)(struct rvt_dev_info *rdi);
205478d3005SHans Petter Selasky 
206478d3005SHans Petter Selasky 	/*
207478d3005SHans Petter Selasky 	 * Allocate a private queue pair data structure for driver specific
208478d3005SHans Petter Selasky 	 * information which is opaque to rdmavt.  Errors are returned via
209478d3005SHans Petter Selasky 	 * ERR_PTR(err).  The driver is free to return NULL or a valid
210478d3005SHans Petter Selasky 	 * pointer.
211478d3005SHans Petter Selasky 	 */
212478d3005SHans Petter Selasky 	void * (*qp_priv_alloc)(struct rvt_dev_info *rdi, struct rvt_qp *qp,
213478d3005SHans Petter Selasky 				gfp_t gfp);
214478d3005SHans Petter Selasky 
215478d3005SHans Petter Selasky 	/*
216478d3005SHans Petter Selasky 	 * Free the driver's private qp structure.
217478d3005SHans Petter Selasky 	 */
218478d3005SHans Petter Selasky 	void (*qp_priv_free)(struct rvt_dev_info *rdi, struct rvt_qp *qp);
219478d3005SHans Petter Selasky 
220478d3005SHans Petter Selasky 	/*
221478d3005SHans Petter Selasky 	 * Inform the driver the particular qp in quesiton has been reset so
222478d3005SHans Petter Selasky 	 * that it can clean up anything it needs to.
223478d3005SHans Petter Selasky 	 */
224478d3005SHans Petter Selasky 	void (*notify_qp_reset)(struct rvt_qp *qp);
225478d3005SHans Petter Selasky 
226478d3005SHans Petter Selasky 	/*
227478d3005SHans Petter Selasky 	 * Give the driver a notice that there is send work to do. It is up to
228478d3005SHans Petter Selasky 	 * the driver to generally push the packets out, this just queues the
229478d3005SHans Petter Selasky 	 * work with the driver. There are two variants here. The no_lock
230478d3005SHans Petter Selasky 	 * version requires the s_lock not to be held. The other assumes the
231478d3005SHans Petter Selasky 	 * s_lock is held.
232478d3005SHans Petter Selasky 	 */
233478d3005SHans Petter Selasky 	void (*schedule_send)(struct rvt_qp *qp);
234478d3005SHans Petter Selasky 	void (*schedule_send_no_lock)(struct rvt_qp *qp);
235478d3005SHans Petter Selasky 
236478d3005SHans Petter Selasky 	/*
237478d3005SHans Petter Selasky 	 * Sometimes rdmavt needs to kick the driver's send progress. That is
238478d3005SHans Petter Selasky 	 * done by this call back.
239478d3005SHans Petter Selasky 	 */
240478d3005SHans Petter Selasky 	void (*do_send)(struct rvt_qp *qp);
241478d3005SHans Petter Selasky 
242478d3005SHans Petter Selasky 	/*
243478d3005SHans Petter Selasky 	 * Get a path mtu from the driver based on qp attributes.
244478d3005SHans Petter Selasky 	 */
245478d3005SHans Petter Selasky 	int (*get_pmtu_from_attr)(struct rvt_dev_info *rdi, struct rvt_qp *qp,
246478d3005SHans Petter Selasky 				  struct ib_qp_attr *attr);
247478d3005SHans Petter Selasky 
248478d3005SHans Petter Selasky 	/*
249478d3005SHans Petter Selasky 	 * Notify driver that it needs to flush any outstanding IO requests that
250478d3005SHans Petter Selasky 	 * are waiting on a qp.
251478d3005SHans Petter Selasky 	 */
252478d3005SHans Petter Selasky 	void (*flush_qp_waiters)(struct rvt_qp *qp);
253478d3005SHans Petter Selasky 
254478d3005SHans Petter Selasky 	/*
255478d3005SHans Petter Selasky 	 * Notify driver to stop its queue of sending packets. Nothing else
256478d3005SHans Petter Selasky 	 * should be posted to the queue pair after this has been called.
257478d3005SHans Petter Selasky 	 */
258478d3005SHans Petter Selasky 	void (*stop_send_queue)(struct rvt_qp *qp);
259478d3005SHans Petter Selasky 
260478d3005SHans Petter Selasky 	/*
261478d3005SHans Petter Selasky 	 * Have the drivr drain any in progress operations
262478d3005SHans Petter Selasky 	 */
263478d3005SHans Petter Selasky 	void (*quiesce_qp)(struct rvt_qp *qp);
264478d3005SHans Petter Selasky 
265478d3005SHans Petter Selasky 	/*
266478d3005SHans Petter Selasky 	 * Inform the driver a qp has went to error state.
267478d3005SHans Petter Selasky 	 */
268478d3005SHans Petter Selasky 	void (*notify_error_qp)(struct rvt_qp *qp);
269478d3005SHans Petter Selasky 
270478d3005SHans Petter Selasky 	/*
271478d3005SHans Petter Selasky 	 * Get an MTU for a qp.
272478d3005SHans Petter Selasky 	 */
273478d3005SHans Petter Selasky 	u32 (*mtu_from_qp)(struct rvt_dev_info *rdi, struct rvt_qp *qp,
274478d3005SHans Petter Selasky 			   u32 pmtu);
275478d3005SHans Petter Selasky 	/*
276478d3005SHans Petter Selasky 	 * Convert an mtu to a path mtu
277478d3005SHans Petter Selasky 	 */
278478d3005SHans Petter Selasky 	int (*mtu_to_path_mtu)(u32 mtu);
279478d3005SHans Petter Selasky 
280478d3005SHans Petter Selasky 	/*
281478d3005SHans Petter Selasky 	 * Get the guid of a port in big endian byte order
282478d3005SHans Petter Selasky 	 */
283478d3005SHans Petter Selasky 	int (*get_guid_be)(struct rvt_dev_info *rdi, struct rvt_ibport *rvp,
284478d3005SHans Petter Selasky 			   int guid_index, __be64 *guid);
285478d3005SHans Petter Selasky 
286478d3005SHans Petter Selasky 	/*
287478d3005SHans Petter Selasky 	 * Query driver for the state of the port.
288478d3005SHans Petter Selasky 	 */
289478d3005SHans Petter Selasky 	int (*query_port_state)(struct rvt_dev_info *rdi, u8 port_num,
290478d3005SHans Petter Selasky 				struct ib_port_attr *props);
291478d3005SHans Petter Selasky 
292478d3005SHans Petter Selasky 	/*
293478d3005SHans Petter Selasky 	 * Tell driver to shutdown a port
294478d3005SHans Petter Selasky 	 */
295478d3005SHans Petter Selasky 	int (*shut_down_port)(struct rvt_dev_info *rdi, u8 port_num);
296478d3005SHans Petter Selasky 
297478d3005SHans Petter Selasky 	/* Tell driver to send a trap for changed  port capabilities */
298478d3005SHans Petter Selasky 	void (*cap_mask_chg)(struct rvt_dev_info *rdi, u8 port_num);
299478d3005SHans Petter Selasky 
300478d3005SHans Petter Selasky 	/*
301478d3005SHans Petter Selasky 	 * The following functions can be safely ignored completely. Any use of
302478d3005SHans Petter Selasky 	 * these is checked for NULL before blindly calling. Rdmavt should also
303478d3005SHans Petter Selasky 	 * be functional if drivers omit these.
304478d3005SHans Petter Selasky 	 */
305478d3005SHans Petter Selasky 
306478d3005SHans Petter Selasky 	/* Called to inform the driver that all qps should now be freed. */
307478d3005SHans Petter Selasky 	unsigned (*free_all_qps)(struct rvt_dev_info *rdi);
308478d3005SHans Petter Selasky 
309478d3005SHans Petter Selasky 	/* Driver specific AH validation */
310478d3005SHans Petter Selasky 	int (*check_ah)(struct ib_device *, struct ib_ah_attr *);
311478d3005SHans Petter Selasky 
312478d3005SHans Petter Selasky 	/* Inform the driver a new AH has been created */
313478d3005SHans Petter Selasky 	void (*notify_new_ah)(struct ib_device *, struct ib_ah_attr *,
314478d3005SHans Petter Selasky 			      struct rvt_ah *);
315478d3005SHans Petter Selasky 
316478d3005SHans Petter Selasky 	/* Let the driver pick the next queue pair number*/
317478d3005SHans Petter Selasky 	int (*alloc_qpn)(struct rvt_dev_info *rdi, struct rvt_qpn_table *qpt,
318478d3005SHans Petter Selasky 			 enum ib_qp_type type, u8 port_num, gfp_t gfp);
319478d3005SHans Petter Selasky 
320478d3005SHans Petter Selasky 	/* Determine if its safe or allowed to modify the qp */
321478d3005SHans Petter Selasky 	int (*check_modify_qp)(struct rvt_qp *qp, struct ib_qp_attr *attr,
322478d3005SHans Petter Selasky 			       int attr_mask, struct ib_udata *udata);
323478d3005SHans Petter Selasky 
324478d3005SHans Petter Selasky 	/* Driver specific QP modification/notification-of */
325478d3005SHans Petter Selasky 	void (*modify_qp)(struct rvt_qp *qp, struct ib_qp_attr *attr,
326478d3005SHans Petter Selasky 			  int attr_mask, struct ib_udata *udata);
327478d3005SHans Petter Selasky 
328478d3005SHans Petter Selasky 	/* Driver specific work request checking */
329478d3005SHans Petter Selasky 	int (*check_send_wqe)(struct rvt_qp *qp, struct rvt_swqe *wqe);
330478d3005SHans Petter Selasky 
331478d3005SHans Petter Selasky 	/* Notify driver a mad agent has been created */
332478d3005SHans Petter Selasky 	void (*notify_create_mad_agent)(struct rvt_dev_info *rdi, int port_idx);
333478d3005SHans Petter Selasky 
334478d3005SHans Petter Selasky 	/* Notify driver a mad agent has been removed */
335478d3005SHans Petter Selasky 	void (*notify_free_mad_agent)(struct rvt_dev_info *rdi, int port_idx);
336478d3005SHans Petter Selasky 
337478d3005SHans Petter Selasky };
338478d3005SHans Petter Selasky 
339478d3005SHans Petter Selasky struct rvt_dev_info {
340478d3005SHans Petter Selasky 	struct ib_device ibdev; /* Keep this first. Nothing above here */
341478d3005SHans Petter Selasky 
342478d3005SHans Petter Selasky 	/*
343478d3005SHans Petter Selasky 	 * Prior to calling for registration the driver will be responsible for
344478d3005SHans Petter Selasky 	 * allocating space for this structure.
345478d3005SHans Petter Selasky 	 *
346478d3005SHans Petter Selasky 	 * The driver will also be responsible for filling in certain members of
347478d3005SHans Petter Selasky 	 * dparms.props. The driver needs to fill in dparms exactly as it would
348478d3005SHans Petter Selasky 	 * want values reported to a ULP. This will be returned to the caller
349478d3005SHans Petter Selasky 	 * in rdmavt's device. The driver should also therefore refrain from
350478d3005SHans Petter Selasky 	 * modifying this directly after registration with rdmavt.
351478d3005SHans Petter Selasky 	 */
352478d3005SHans Petter Selasky 
353478d3005SHans Petter Selasky 	/* Driver specific properties */
354478d3005SHans Petter Selasky 	struct rvt_driver_params dparms;
355478d3005SHans Petter Selasky 
356478d3005SHans Petter Selasky 	/* post send table */
357478d3005SHans Petter Selasky 	const struct rvt_operation_params *post_parms;
358478d3005SHans Petter Selasky 
359478d3005SHans Petter Selasky 	struct rvt_mregion __rcu *dma_mr;
360478d3005SHans Petter Selasky 	struct rvt_lkey_table lkey_table;
361478d3005SHans Petter Selasky 
362478d3005SHans Petter Selasky 	/* Driver specific helper functions */
363478d3005SHans Petter Selasky 	struct rvt_driver_provided driver_f;
364478d3005SHans Petter Selasky 
365478d3005SHans Petter Selasky 	/* Internal use */
366478d3005SHans Petter Selasky 	int n_pds_allocated;
367478d3005SHans Petter Selasky 	spinlock_t n_pds_lock; /* Protect pd allocated count */
368478d3005SHans Petter Selasky 
369478d3005SHans Petter Selasky 	int n_ahs_allocated;
370478d3005SHans Petter Selasky 	spinlock_t n_ahs_lock; /* Protect ah allocated count */
371478d3005SHans Petter Selasky 
372478d3005SHans Petter Selasky 	u32 n_srqs_allocated;
373478d3005SHans Petter Selasky 	spinlock_t n_srqs_lock; /* Protect srqs allocated count */
374478d3005SHans Petter Selasky 
375478d3005SHans Petter Selasky 	int flags;
376478d3005SHans Petter Selasky 	struct rvt_ibport **ports;
377478d3005SHans Petter Selasky 
378478d3005SHans Petter Selasky 	/* QP */
379478d3005SHans Petter Selasky 	struct rvt_qp_ibdev *qp_dev;
380478d3005SHans Petter Selasky 	u32 n_qps_allocated;    /* number of QPs allocated for device */
381478d3005SHans Petter Selasky 	u32 n_rc_qps;		/* number of RC QPs allocated for device */
382478d3005SHans Petter Selasky 	u32 busy_jiffies;	/* timeout scaling based on RC QP count */
383478d3005SHans Petter Selasky 	spinlock_t n_qps_lock;	/* protect qps, rc qps and busy jiffy counts */
384478d3005SHans Petter Selasky 
385478d3005SHans Petter Selasky 	/* memory maps */
386478d3005SHans Petter Selasky 	struct list_head pending_mmaps;
387478d3005SHans Petter Selasky 	spinlock_t mmap_offset_lock; /* protect mmap_offset */
388478d3005SHans Petter Selasky 	u32 mmap_offset;
389478d3005SHans Petter Selasky 	spinlock_t pending_lock; /* protect pending mmap list */
390478d3005SHans Petter Selasky 
391478d3005SHans Petter Selasky 	/* CQ */
392478d3005SHans Petter Selasky 	struct kthread_worker *worker; /* per device cq worker */
393478d3005SHans Petter Selasky 	u32 n_cqs_allocated;    /* number of CQs allocated for device */
394478d3005SHans Petter Selasky 	spinlock_t n_cqs_lock; /* protect count of in use cqs */
395478d3005SHans Petter Selasky 
396478d3005SHans Petter Selasky 	/* Multicast */
397478d3005SHans Petter Selasky 	u32 n_mcast_grps_allocated; /* number of mcast groups allocated */
398478d3005SHans Petter Selasky 	spinlock_t n_mcast_grps_lock;
399478d3005SHans Petter Selasky 
400478d3005SHans Petter Selasky };
401478d3005SHans Petter Selasky 
ibpd_to_rvtpd(struct ib_pd * ibpd)402478d3005SHans Petter Selasky static inline struct rvt_pd *ibpd_to_rvtpd(struct ib_pd *ibpd)
403478d3005SHans Petter Selasky {
404478d3005SHans Petter Selasky 	return container_of(ibpd, struct rvt_pd, ibpd);
405478d3005SHans Petter Selasky }
406478d3005SHans Petter Selasky 
ibah_to_rvtah(struct ib_ah * ibah)407478d3005SHans Petter Selasky static inline struct rvt_ah *ibah_to_rvtah(struct ib_ah *ibah)
408478d3005SHans Petter Selasky {
409478d3005SHans Petter Selasky 	return container_of(ibah, struct rvt_ah, ibah);
410478d3005SHans Petter Selasky }
411478d3005SHans Petter Selasky 
ib_to_rvt(struct ib_device * ibdev)412478d3005SHans Petter Selasky static inline struct rvt_dev_info *ib_to_rvt(struct ib_device *ibdev)
413478d3005SHans Petter Selasky {
414478d3005SHans Petter Selasky 	return  container_of(ibdev, struct rvt_dev_info, ibdev);
415478d3005SHans Petter Selasky }
416478d3005SHans Petter Selasky 
ibsrq_to_rvtsrq(struct ib_srq * ibsrq)417478d3005SHans Petter Selasky static inline struct rvt_srq *ibsrq_to_rvtsrq(struct ib_srq *ibsrq)
418478d3005SHans Petter Selasky {
419478d3005SHans Petter Selasky 	return container_of(ibsrq, struct rvt_srq, ibsrq);
420478d3005SHans Petter Selasky }
421478d3005SHans Petter Selasky 
ibqp_to_rvtqp(struct ib_qp * ibqp)422478d3005SHans Petter Selasky static inline struct rvt_qp *ibqp_to_rvtqp(struct ib_qp *ibqp)
423478d3005SHans Petter Selasky {
424478d3005SHans Petter Selasky 	return container_of(ibqp, struct rvt_qp, ibqp);
425478d3005SHans Petter Selasky }
426478d3005SHans Petter Selasky 
rvt_get_npkeys(struct rvt_dev_info * rdi)427478d3005SHans Petter Selasky static inline unsigned rvt_get_npkeys(struct rvt_dev_info *rdi)
428478d3005SHans Petter Selasky {
429478d3005SHans Petter Selasky 	/*
430478d3005SHans Petter Selasky 	 * All ports have same number of pkeys.
431478d3005SHans Petter Selasky 	 */
432478d3005SHans Petter Selasky 	return rdi->dparms.npkeys;
433478d3005SHans Petter Selasky }
434478d3005SHans Petter Selasky 
435478d3005SHans Petter Selasky /*
436478d3005SHans Petter Selasky  * Return the max atomic suitable for determining
437478d3005SHans Petter Selasky  * the size of the ack ring buffer in a QP.
438478d3005SHans Petter Selasky  */
rvt_max_atomic(struct rvt_dev_info * rdi)439478d3005SHans Petter Selasky static inline unsigned int rvt_max_atomic(struct rvt_dev_info *rdi)
440478d3005SHans Petter Selasky {
441478d3005SHans Petter Selasky 	return rdi->dparms.max_rdma_atomic + 1;
442478d3005SHans Petter Selasky }
443478d3005SHans Petter Selasky 
444478d3005SHans Petter Selasky /*
445478d3005SHans Petter Selasky  * Return the indexed PKEY from the port PKEY table.
446478d3005SHans Petter Selasky  */
rvt_get_pkey(struct rvt_dev_info * rdi,int port_index,unsigned index)447478d3005SHans Petter Selasky static inline u16 rvt_get_pkey(struct rvt_dev_info *rdi,
448478d3005SHans Petter Selasky 			       int port_index,
449478d3005SHans Petter Selasky 			       unsigned index)
450478d3005SHans Petter Selasky {
451478d3005SHans Petter Selasky 	if (index >= rvt_get_npkeys(rdi))
452478d3005SHans Petter Selasky 		return 0;
453478d3005SHans Petter Selasky 	else
454478d3005SHans Petter Selasky 		return rdi->ports[port_index]->pkey_table[index];
455478d3005SHans Petter Selasky }
456478d3005SHans Petter Selasky 
457478d3005SHans Petter Selasky /**
458478d3005SHans Petter Selasky  * rvt_lookup_qpn - return the QP with the given QPN
459478d3005SHans Petter Selasky  * @ibp: the ibport
460478d3005SHans Petter Selasky  * @qpn: the QP number to look up
461478d3005SHans Petter Selasky  *
462478d3005SHans Petter Selasky  * The caller must hold the rcu_read_lock(), and keep the lock until
463478d3005SHans Petter Selasky  * the returned qp is no longer in use.
464478d3005SHans Petter Selasky  */
465478d3005SHans Petter Selasky /* TODO: Remove this and put in rdmavt/qp.h when no longer needed by drivers */
rvt_lookup_qpn(struct rvt_dev_info * rdi,struct rvt_ibport * rvp,u32 qpn)466478d3005SHans Petter Selasky static inline struct rvt_qp *rvt_lookup_qpn(struct rvt_dev_info *rdi,
467478d3005SHans Petter Selasky 					    struct rvt_ibport *rvp,
468478d3005SHans Petter Selasky 					    u32 qpn) __must_hold(RCU)
469478d3005SHans Petter Selasky {
470478d3005SHans Petter Selasky 	struct rvt_qp *qp = NULL;
471478d3005SHans Petter Selasky 
472478d3005SHans Petter Selasky 	if (unlikely(qpn <= 1)) {
473478d3005SHans Petter Selasky 		qp = rcu_dereference(rvp->qp[qpn]);
474478d3005SHans Petter Selasky 	} else {
475478d3005SHans Petter Selasky 		u32 n = hash_32(qpn, rdi->qp_dev->qp_table_bits);
476478d3005SHans Petter Selasky 
477478d3005SHans Petter Selasky 		for (qp = rcu_dereference(rdi->qp_dev->qp_table[n]); qp;
478478d3005SHans Petter Selasky 			qp = rcu_dereference(qp->next))
479478d3005SHans Petter Selasky 			if (qp->ibqp.qp_num == qpn)
480478d3005SHans Petter Selasky 				break;
481478d3005SHans Petter Selasky 	}
482478d3005SHans Petter Selasky 	return qp;
483478d3005SHans Petter Selasky }
484478d3005SHans Petter Selasky 
485478d3005SHans Petter Selasky struct rvt_dev_info *rvt_alloc_device(size_t size, int nports);
486478d3005SHans Petter Selasky void rvt_dealloc_device(struct rvt_dev_info *rdi);
487478d3005SHans Petter Selasky int rvt_register_device(struct rvt_dev_info *rvd);
488478d3005SHans Petter Selasky void rvt_unregister_device(struct rvt_dev_info *rvd);
489478d3005SHans Petter Selasky int rvt_check_ah(struct ib_device *ibdev, struct ib_ah_attr *ah_attr);
490478d3005SHans Petter Selasky int rvt_init_port(struct rvt_dev_info *rdi, struct rvt_ibport *port,
491478d3005SHans Petter Selasky 		  int port_index, u16 *pkey_table);
492478d3005SHans Petter Selasky int rvt_fast_reg_mr(struct rvt_qp *qp, struct ib_mr *ibmr, u32 key,
493478d3005SHans Petter Selasky 		    int access);
494478d3005SHans Petter Selasky int rvt_invalidate_rkey(struct rvt_qp *qp, u32 rkey);
495478d3005SHans Petter Selasky int rvt_rkey_ok(struct rvt_qp *qp, struct rvt_sge *sge,
496478d3005SHans Petter Selasky 		u32 len, u64 vaddr, u32 rkey, int acc);
497478d3005SHans Petter Selasky int rvt_lkey_ok(struct rvt_lkey_table *rkt, struct rvt_pd *pd,
498478d3005SHans Petter Selasky 		struct rvt_sge *isge, struct ib_sge *sge, int acc);
499478d3005SHans Petter Selasky struct rvt_mcast *rvt_mcast_find(struct rvt_ibport *ibp, union ib_gid *mgid);
500478d3005SHans Petter Selasky 
501478d3005SHans Petter Selasky #endif          /* DEF_RDMA_VT_H */
502