xref: /OK3568_Linux_fs/kernel/drivers/infiniband/hw/hfi1/verbs.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  * Copyright(c) 2015 - 2018 Intel Corporation.
3*4882a593Smuzhiyun  *
4*4882a593Smuzhiyun  * This file is provided under a dual BSD/GPLv2 license.  When using or
5*4882a593Smuzhiyun  * redistributing this file, you may do so under either license.
6*4882a593Smuzhiyun  *
7*4882a593Smuzhiyun  * GPL LICENSE SUMMARY
8*4882a593Smuzhiyun  *
9*4882a593Smuzhiyun  * This program is free software; you can redistribute it and/or modify
10*4882a593Smuzhiyun  * it under the terms of version 2 of the GNU General Public License as
11*4882a593Smuzhiyun  * published by the Free Software Foundation.
12*4882a593Smuzhiyun  *
13*4882a593Smuzhiyun  * This program is distributed in the hope that it will be useful, but
14*4882a593Smuzhiyun  * WITHOUT ANY WARRANTY; without even the implied warranty of
15*4882a593Smuzhiyun  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16*4882a593Smuzhiyun  * General Public License for more details.
17*4882a593Smuzhiyun  *
18*4882a593Smuzhiyun  * BSD LICENSE
19*4882a593Smuzhiyun  *
20*4882a593Smuzhiyun  * Redistribution and use in source and binary forms, with or without
21*4882a593Smuzhiyun  * modification, are permitted provided that the following conditions
22*4882a593Smuzhiyun  * are met:
23*4882a593Smuzhiyun  *
24*4882a593Smuzhiyun  *  - Redistributions of source code must retain the above copyright
25*4882a593Smuzhiyun  *    notice, this list of conditions and the following disclaimer.
26*4882a593Smuzhiyun  *  - Redistributions in binary form must reproduce the above copyright
27*4882a593Smuzhiyun  *    notice, this list of conditions and the following disclaimer in
28*4882a593Smuzhiyun  *    the documentation and/or other materials provided with the
29*4882a593Smuzhiyun  *    distribution.
30*4882a593Smuzhiyun  *  - Neither the name of Intel Corporation nor the names of its
31*4882a593Smuzhiyun  *    contributors may be used to endorse or promote products derived
32*4882a593Smuzhiyun  *    from this software without specific prior written permission.
33*4882a593Smuzhiyun  *
34*4882a593Smuzhiyun  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
35*4882a593Smuzhiyun  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
36*4882a593Smuzhiyun  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
37*4882a593Smuzhiyun  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
38*4882a593Smuzhiyun  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
39*4882a593Smuzhiyun  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
40*4882a593Smuzhiyun  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
41*4882a593Smuzhiyun  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
42*4882a593Smuzhiyun  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
43*4882a593Smuzhiyun  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
44*4882a593Smuzhiyun  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
45*4882a593Smuzhiyun  *
46*4882a593Smuzhiyun  */
47*4882a593Smuzhiyun 
48*4882a593Smuzhiyun #ifndef HFI1_VERBS_H
49*4882a593Smuzhiyun #define HFI1_VERBS_H
50*4882a593Smuzhiyun 
51*4882a593Smuzhiyun #include <linux/types.h>
52*4882a593Smuzhiyun #include <linux/seqlock.h>
53*4882a593Smuzhiyun #include <linux/kernel.h>
54*4882a593Smuzhiyun #include <linux/interrupt.h>
55*4882a593Smuzhiyun #include <linux/kref.h>
56*4882a593Smuzhiyun #include <linux/workqueue.h>
57*4882a593Smuzhiyun #include <linux/kthread.h>
58*4882a593Smuzhiyun #include <linux/completion.h>
59*4882a593Smuzhiyun #include <linux/slab.h>
60*4882a593Smuzhiyun #include <rdma/ib_pack.h>
61*4882a593Smuzhiyun #include <rdma/ib_user_verbs.h>
62*4882a593Smuzhiyun #include <rdma/ib_mad.h>
63*4882a593Smuzhiyun #include <rdma/ib_hdrs.h>
64*4882a593Smuzhiyun #include <rdma/rdma_vt.h>
65*4882a593Smuzhiyun #include <rdma/rdmavt_qp.h>
66*4882a593Smuzhiyun #include <rdma/rdmavt_cq.h>
67*4882a593Smuzhiyun 
68*4882a593Smuzhiyun struct hfi1_ctxtdata;
69*4882a593Smuzhiyun struct hfi1_pportdata;
70*4882a593Smuzhiyun struct hfi1_devdata;
71*4882a593Smuzhiyun struct hfi1_packet;
72*4882a593Smuzhiyun 
73*4882a593Smuzhiyun #include "iowait.h"
74*4882a593Smuzhiyun #include "tid_rdma.h"
75*4882a593Smuzhiyun #include "opfn.h"
76*4882a593Smuzhiyun 
77*4882a593Smuzhiyun #define HFI1_MAX_RDMA_ATOMIC     16
78*4882a593Smuzhiyun 
79*4882a593Smuzhiyun /*
80*4882a593Smuzhiyun  * Increment this value if any changes that break userspace ABI
81*4882a593Smuzhiyun  * compatibility are made.
82*4882a593Smuzhiyun  */
83*4882a593Smuzhiyun #define HFI1_UVERBS_ABI_VERSION       2
84*4882a593Smuzhiyun 
85*4882a593Smuzhiyun /* IB Performance Manager status values */
86*4882a593Smuzhiyun #define IB_PMA_SAMPLE_STATUS_DONE       0x00
87*4882a593Smuzhiyun #define IB_PMA_SAMPLE_STATUS_STARTED    0x01
88*4882a593Smuzhiyun #define IB_PMA_SAMPLE_STATUS_RUNNING    0x02
89*4882a593Smuzhiyun 
90*4882a593Smuzhiyun /* Mandatory IB performance counter select values. */
91*4882a593Smuzhiyun #define IB_PMA_PORT_XMIT_DATA   cpu_to_be16(0x0001)
92*4882a593Smuzhiyun #define IB_PMA_PORT_RCV_DATA    cpu_to_be16(0x0002)
93*4882a593Smuzhiyun #define IB_PMA_PORT_XMIT_PKTS   cpu_to_be16(0x0003)
94*4882a593Smuzhiyun #define IB_PMA_PORT_RCV_PKTS    cpu_to_be16(0x0004)
95*4882a593Smuzhiyun #define IB_PMA_PORT_XMIT_WAIT   cpu_to_be16(0x0005)
96*4882a593Smuzhiyun 
97*4882a593Smuzhiyun #define HFI1_VENDOR_IPG		cpu_to_be16(0xFFA0)
98*4882a593Smuzhiyun 
99*4882a593Smuzhiyun #define IB_DEFAULT_GID_PREFIX	cpu_to_be64(0xfe80000000000000ULL)
100*4882a593Smuzhiyun #define OPA_BTH_MIG_REQ		BIT(31)
101*4882a593Smuzhiyun 
102*4882a593Smuzhiyun #define RC_OP(x) IB_OPCODE_RC_##x
103*4882a593Smuzhiyun #define UC_OP(x) IB_OPCODE_UC_##x
104*4882a593Smuzhiyun 
105*4882a593Smuzhiyun /* flags passed by hfi1_ib_rcv() */
106*4882a593Smuzhiyun enum {
107*4882a593Smuzhiyun 	HFI1_HAS_GRH = (1 << 0),
108*4882a593Smuzhiyun };
109*4882a593Smuzhiyun 
110*4882a593Smuzhiyun #define LRH_16B_BYTES (sizeof_field(struct hfi1_16b_header, lrh))
111*4882a593Smuzhiyun #define LRH_16B_DWORDS (LRH_16B_BYTES / sizeof(u32))
112*4882a593Smuzhiyun #define LRH_9B_BYTES (sizeof_field(struct ib_header, lrh))
113*4882a593Smuzhiyun #define LRH_9B_DWORDS (LRH_9B_BYTES / sizeof(u32))
114*4882a593Smuzhiyun 
115*4882a593Smuzhiyun /* 24Bits for qpn, upper 8Bits reserved */
116*4882a593Smuzhiyun struct opa_16b_mgmt {
117*4882a593Smuzhiyun 	__be32 dest_qpn;
118*4882a593Smuzhiyun 	__be32 src_qpn;
119*4882a593Smuzhiyun };
120*4882a593Smuzhiyun 
121*4882a593Smuzhiyun struct hfi1_16b_header {
122*4882a593Smuzhiyun 	u32 lrh[4];
123*4882a593Smuzhiyun 	union {
124*4882a593Smuzhiyun 		struct {
125*4882a593Smuzhiyun 			struct ib_grh grh;
126*4882a593Smuzhiyun 			struct ib_other_headers oth;
127*4882a593Smuzhiyun 		} l;
128*4882a593Smuzhiyun 		struct ib_other_headers oth;
129*4882a593Smuzhiyun 		struct opa_16b_mgmt mgmt;
130*4882a593Smuzhiyun 	} u;
131*4882a593Smuzhiyun } __packed;
132*4882a593Smuzhiyun 
133*4882a593Smuzhiyun struct hfi1_opa_header {
134*4882a593Smuzhiyun 	union {
135*4882a593Smuzhiyun 		struct ib_header ibh; /* 9B header */
136*4882a593Smuzhiyun 		struct hfi1_16b_header opah; /* 16B header */
137*4882a593Smuzhiyun 	};
138*4882a593Smuzhiyun 	u8 hdr_type; /* 9B or 16B */
139*4882a593Smuzhiyun } __packed;
140*4882a593Smuzhiyun 
141*4882a593Smuzhiyun struct hfi1_ahg_info {
142*4882a593Smuzhiyun 	u32 ahgdesc[2];
143*4882a593Smuzhiyun 	u16 tx_flags;
144*4882a593Smuzhiyun 	u8 ahgcount;
145*4882a593Smuzhiyun 	u8 ahgidx;
146*4882a593Smuzhiyun };
147*4882a593Smuzhiyun 
148*4882a593Smuzhiyun struct hfi1_sdma_header {
149*4882a593Smuzhiyun 	__le64 pbc;
150*4882a593Smuzhiyun 	struct hfi1_opa_header hdr;
151*4882a593Smuzhiyun } __packed;
152*4882a593Smuzhiyun 
153*4882a593Smuzhiyun /*
154*4882a593Smuzhiyun  * hfi1 specific data structures that will be hidden from rvt after the queue
155*4882a593Smuzhiyun  * pair is made common
156*4882a593Smuzhiyun  */
157*4882a593Smuzhiyun struct hfi1_qp_priv {
158*4882a593Smuzhiyun 	struct hfi1_ahg_info *s_ahg;              /* ahg info for next header */
159*4882a593Smuzhiyun 	struct sdma_engine *s_sde;                /* current sde */
160*4882a593Smuzhiyun 	struct send_context *s_sendcontext;       /* current sendcontext */
161*4882a593Smuzhiyun 	struct hfi1_ctxtdata *rcd;                /* QP's receive context */
162*4882a593Smuzhiyun 	struct page **pages;                      /* for TID page scan */
163*4882a593Smuzhiyun 	u32 tid_enqueue;                          /* saved when tid waited */
164*4882a593Smuzhiyun 	u8 s_sc;		                  /* SC[0..4] for next packet */
165*4882a593Smuzhiyun 	struct iowait s_iowait;
166*4882a593Smuzhiyun 	struct timer_list s_tid_timer;            /* for timing tid wait */
167*4882a593Smuzhiyun 	struct timer_list s_tid_retry_timer;      /* for timing tid ack */
168*4882a593Smuzhiyun 	struct list_head tid_wait;                /* for queueing tid space */
169*4882a593Smuzhiyun 	struct hfi1_opfn_data opfn;
170*4882a593Smuzhiyun 	struct tid_flow_state flow_state;
171*4882a593Smuzhiyun 	struct tid_rdma_qp_params tid_rdma;
172*4882a593Smuzhiyun 	struct rvt_qp *owner;
173*4882a593Smuzhiyun 	u16 s_running_pkt_size;
174*4882a593Smuzhiyun 	u8 hdr_type; /* 9B or 16B */
175*4882a593Smuzhiyun 	struct rvt_sge_state tid_ss;       /* SGE state pointer for 2nd leg */
176*4882a593Smuzhiyun 	atomic_t n_requests;               /* # of TID RDMA requests in the */
177*4882a593Smuzhiyun 					   /* queue */
178*4882a593Smuzhiyun 	atomic_t n_tid_requests;            /* # of sent TID RDMA requests */
179*4882a593Smuzhiyun 	unsigned long tid_timer_timeout_jiffies;
180*4882a593Smuzhiyun 	unsigned long tid_retry_timeout_jiffies;
181*4882a593Smuzhiyun 
182*4882a593Smuzhiyun 	/* variables for the TID RDMA SE state machine */
183*4882a593Smuzhiyun 	u8 s_state;
184*4882a593Smuzhiyun 	u8 s_retry;
185*4882a593Smuzhiyun 	u8 rnr_nak_state;       /* RNR NAK state */
186*4882a593Smuzhiyun 	u8 s_nak_state;
187*4882a593Smuzhiyun 	u32 s_nak_psn;
188*4882a593Smuzhiyun 	u32 s_flags;
189*4882a593Smuzhiyun 	u32 s_tid_cur;
190*4882a593Smuzhiyun 	u32 s_tid_head;
191*4882a593Smuzhiyun 	u32 s_tid_tail;
192*4882a593Smuzhiyun 	u32 r_tid_head;     /* Most recently added TID RDMA request */
193*4882a593Smuzhiyun 	u32 r_tid_tail;     /* the last completed TID RDMA request */
194*4882a593Smuzhiyun 	u32 r_tid_ack;      /* the TID RDMA request to be ACK'ed */
195*4882a593Smuzhiyun 	u32 r_tid_alloc;    /* Request for which we are allocating resources */
196*4882a593Smuzhiyun 	u32 pending_tid_w_segs; /* Num of pending tid write segments */
197*4882a593Smuzhiyun 	u32 pending_tid_w_resp; /* Num of pending tid write responses */
198*4882a593Smuzhiyun 	u32 alloc_w_segs;       /* Number of segments for which write */
199*4882a593Smuzhiyun 			       /* resources have been allocated for this QP */
200*4882a593Smuzhiyun 
201*4882a593Smuzhiyun 	/* For TID RDMA READ */
202*4882a593Smuzhiyun 	u32 tid_r_reqs;         /* Num of tid reads requested */
203*4882a593Smuzhiyun 	u32 tid_r_comp;         /* Num of tid reads completed */
204*4882a593Smuzhiyun 	u32 pending_tid_r_segs; /* Num of pending tid read segments */
205*4882a593Smuzhiyun 	u16 pkts_ps;            /* packets per segment */
206*4882a593Smuzhiyun 	u8 timeout_shift;       /* account for number of packets per segment */
207*4882a593Smuzhiyun 
208*4882a593Smuzhiyun 	u32 r_next_psn_kdeth;
209*4882a593Smuzhiyun 	u32 r_next_psn_kdeth_save;
210*4882a593Smuzhiyun 	u32 s_resync_psn;
211*4882a593Smuzhiyun 	u8 sync_pt;           /* Set when QP reaches sync point */
212*4882a593Smuzhiyun 	u8 resync;
213*4882a593Smuzhiyun };
214*4882a593Smuzhiyun 
215*4882a593Smuzhiyun #define HFI1_QP_WQE_INVALID   ((u32)-1)
216*4882a593Smuzhiyun 
217*4882a593Smuzhiyun struct hfi1_swqe_priv {
218*4882a593Smuzhiyun 	struct tid_rdma_request tid_req;
219*4882a593Smuzhiyun 	struct rvt_sge_state ss;  /* Used for TID RDMA READ Request */
220*4882a593Smuzhiyun };
221*4882a593Smuzhiyun 
222*4882a593Smuzhiyun struct hfi1_ack_priv {
223*4882a593Smuzhiyun 	struct rvt_sge_state ss;               /* used for TID WRITE RESP */
224*4882a593Smuzhiyun 	struct tid_rdma_request tid_req;
225*4882a593Smuzhiyun };
226*4882a593Smuzhiyun 
227*4882a593Smuzhiyun /*
228*4882a593Smuzhiyun  * This structure is used to hold commonly lookedup and computed values during
229*4882a593Smuzhiyun  * the send engine progress.
230*4882a593Smuzhiyun  */
231*4882a593Smuzhiyun struct iowait_work;
232*4882a593Smuzhiyun struct hfi1_pkt_state {
233*4882a593Smuzhiyun 	struct hfi1_ibdev *dev;
234*4882a593Smuzhiyun 	struct hfi1_ibport *ibp;
235*4882a593Smuzhiyun 	struct hfi1_pportdata *ppd;
236*4882a593Smuzhiyun 	struct verbs_txreq *s_txreq;
237*4882a593Smuzhiyun 	struct iowait_work *wait;
238*4882a593Smuzhiyun 	unsigned long flags;
239*4882a593Smuzhiyun 	unsigned long timeout;
240*4882a593Smuzhiyun 	unsigned long timeout_int;
241*4882a593Smuzhiyun 	int cpu;
242*4882a593Smuzhiyun 	u8 opcode;
243*4882a593Smuzhiyun 	bool in_thread;
244*4882a593Smuzhiyun 	bool pkts_sent;
245*4882a593Smuzhiyun };
246*4882a593Smuzhiyun 
247*4882a593Smuzhiyun #define HFI1_PSN_CREDIT  16
248*4882a593Smuzhiyun 
249*4882a593Smuzhiyun struct hfi1_opcode_stats {
250*4882a593Smuzhiyun 	u64 n_packets;          /* number of packets */
251*4882a593Smuzhiyun 	u64 n_bytes;            /* total number of bytes */
252*4882a593Smuzhiyun };
253*4882a593Smuzhiyun 
254*4882a593Smuzhiyun struct hfi1_opcode_stats_perctx {
255*4882a593Smuzhiyun 	struct hfi1_opcode_stats stats[256];
256*4882a593Smuzhiyun };
257*4882a593Smuzhiyun 
inc_opstats(u32 tlen,struct hfi1_opcode_stats * stats)258*4882a593Smuzhiyun static inline void inc_opstats(
259*4882a593Smuzhiyun 	u32 tlen,
260*4882a593Smuzhiyun 	struct hfi1_opcode_stats *stats)
261*4882a593Smuzhiyun {
262*4882a593Smuzhiyun #ifdef CONFIG_DEBUG_FS
263*4882a593Smuzhiyun 	stats->n_bytes += tlen;
264*4882a593Smuzhiyun 	stats->n_packets++;
265*4882a593Smuzhiyun #endif
266*4882a593Smuzhiyun }
267*4882a593Smuzhiyun 
268*4882a593Smuzhiyun struct hfi1_ibport {
269*4882a593Smuzhiyun 	struct rvt_qp __rcu *qp[2];
270*4882a593Smuzhiyun 	struct rvt_ibport rvp;
271*4882a593Smuzhiyun 
272*4882a593Smuzhiyun 	/* the first 16 entries are sl_to_vl for !OPA */
273*4882a593Smuzhiyun 	u8 sl_to_sc[32];
274*4882a593Smuzhiyun 	u8 sc_to_sl[32];
275*4882a593Smuzhiyun };
276*4882a593Smuzhiyun 
277*4882a593Smuzhiyun struct hfi1_ibdev {
278*4882a593Smuzhiyun 	struct rvt_dev_info rdi; /* Must be first */
279*4882a593Smuzhiyun 
280*4882a593Smuzhiyun 	/* QP numbers are shared by all IB ports */
281*4882a593Smuzhiyun 	/* protect txwait list */
282*4882a593Smuzhiyun 	seqlock_t txwait_lock ____cacheline_aligned_in_smp;
283*4882a593Smuzhiyun 	struct list_head txwait;        /* list for wait verbs_txreq */
284*4882a593Smuzhiyun 	struct list_head memwait;       /* list for wait kernel memory */
285*4882a593Smuzhiyun 	struct kmem_cache *verbs_txreq_cache;
286*4882a593Smuzhiyun 	u64 n_txwait;
287*4882a593Smuzhiyun 	u64 n_kmem_wait;
288*4882a593Smuzhiyun 	u64 n_tidwait;
289*4882a593Smuzhiyun 
290*4882a593Smuzhiyun 	/* protect iowait lists */
291*4882a593Smuzhiyun 	seqlock_t iowait_lock ____cacheline_aligned_in_smp;
292*4882a593Smuzhiyun 	u64 n_piowait;
293*4882a593Smuzhiyun 	u64 n_piodrain;
294*4882a593Smuzhiyun 	struct timer_list mem_timer;
295*4882a593Smuzhiyun 
296*4882a593Smuzhiyun #ifdef CONFIG_DEBUG_FS
297*4882a593Smuzhiyun 	/* per HFI debugfs */
298*4882a593Smuzhiyun 	struct dentry *hfi1_ibdev_dbg;
299*4882a593Smuzhiyun 	/* per HFI symlinks to above */
300*4882a593Smuzhiyun 	struct dentry *hfi1_ibdev_link;
301*4882a593Smuzhiyun #ifdef CONFIG_FAULT_INJECTION
302*4882a593Smuzhiyun 	struct fault *fault;
303*4882a593Smuzhiyun #endif
304*4882a593Smuzhiyun #endif
305*4882a593Smuzhiyun };
306*4882a593Smuzhiyun 
to_idev(struct ib_device * ibdev)307*4882a593Smuzhiyun static inline struct hfi1_ibdev *to_idev(struct ib_device *ibdev)
308*4882a593Smuzhiyun {
309*4882a593Smuzhiyun 	struct rvt_dev_info *rdi;
310*4882a593Smuzhiyun 
311*4882a593Smuzhiyun 	rdi = container_of(ibdev, struct rvt_dev_info, ibdev);
312*4882a593Smuzhiyun 	return container_of(rdi, struct hfi1_ibdev, rdi);
313*4882a593Smuzhiyun }
314*4882a593Smuzhiyun 
iowait_to_qp(struct iowait * s_iowait)315*4882a593Smuzhiyun static inline struct rvt_qp *iowait_to_qp(struct iowait *s_iowait)
316*4882a593Smuzhiyun {
317*4882a593Smuzhiyun 	struct hfi1_qp_priv *priv;
318*4882a593Smuzhiyun 
319*4882a593Smuzhiyun 	priv = container_of(s_iowait, struct hfi1_qp_priv, s_iowait);
320*4882a593Smuzhiyun 	return priv->owner;
321*4882a593Smuzhiyun }
322*4882a593Smuzhiyun 
323*4882a593Smuzhiyun /*
324*4882a593Smuzhiyun  * This must be called with s_lock held.
325*4882a593Smuzhiyun  */
326*4882a593Smuzhiyun void hfi1_bad_pkey(struct hfi1_ibport *ibp, u32 key, u32 sl,
327*4882a593Smuzhiyun 		   u32 qp1, u32 qp2, u32 lid1, u32 lid2);
328*4882a593Smuzhiyun void hfi1_cap_mask_chg(struct rvt_dev_info *rdi, u8 port_num);
329*4882a593Smuzhiyun void hfi1_sys_guid_chg(struct hfi1_ibport *ibp);
330*4882a593Smuzhiyun void hfi1_node_desc_chg(struct hfi1_ibport *ibp);
331*4882a593Smuzhiyun int hfi1_process_mad(struct ib_device *ibdev, int mad_flags, u8 port,
332*4882a593Smuzhiyun 		     const struct ib_wc *in_wc, const struct ib_grh *in_grh,
333*4882a593Smuzhiyun 		     const struct ib_mad *in_mad, struct ib_mad *out_mad,
334*4882a593Smuzhiyun 		     size_t *out_mad_size, u16 *out_mad_pkey_index);
335*4882a593Smuzhiyun 
336*4882a593Smuzhiyun /*
337*4882a593Smuzhiyun  * The PSN_MASK and PSN_SHIFT allow for
338*4882a593Smuzhiyun  * 1) comparing two PSNs
339*4882a593Smuzhiyun  * 2) returning the PSN with any upper bits masked
340*4882a593Smuzhiyun  * 3) returning the difference between to PSNs
341*4882a593Smuzhiyun  *
342*4882a593Smuzhiyun  * The number of significant bits in the PSN must
343*4882a593Smuzhiyun  * necessarily be at least one bit less than
344*4882a593Smuzhiyun  * the container holding the PSN.
345*4882a593Smuzhiyun  */
346*4882a593Smuzhiyun #define PSN_MASK 0x7FFFFFFF
347*4882a593Smuzhiyun #define PSN_SHIFT 1
348*4882a593Smuzhiyun #define PSN_MODIFY_MASK 0xFFFFFF
349*4882a593Smuzhiyun 
350*4882a593Smuzhiyun /*
351*4882a593Smuzhiyun  * Compare two PSNs
352*4882a593Smuzhiyun  * Returns an integer <, ==, or > than zero.
353*4882a593Smuzhiyun  */
cmp_psn(u32 a,u32 b)354*4882a593Smuzhiyun static inline int cmp_psn(u32 a, u32 b)
355*4882a593Smuzhiyun {
356*4882a593Smuzhiyun 	return (((int)a) - ((int)b)) << PSN_SHIFT;
357*4882a593Smuzhiyun }
358*4882a593Smuzhiyun 
359*4882a593Smuzhiyun /*
360*4882a593Smuzhiyun  * Return masked PSN
361*4882a593Smuzhiyun  */
mask_psn(u32 a)362*4882a593Smuzhiyun static inline u32 mask_psn(u32 a)
363*4882a593Smuzhiyun {
364*4882a593Smuzhiyun 	return a & PSN_MASK;
365*4882a593Smuzhiyun }
366*4882a593Smuzhiyun 
367*4882a593Smuzhiyun /*
368*4882a593Smuzhiyun  * Return delta between two PSNs
369*4882a593Smuzhiyun  */
delta_psn(u32 a,u32 b)370*4882a593Smuzhiyun static inline u32 delta_psn(u32 a, u32 b)
371*4882a593Smuzhiyun {
372*4882a593Smuzhiyun 	return (((int)a - (int)b) << PSN_SHIFT) >> PSN_SHIFT;
373*4882a593Smuzhiyun }
374*4882a593Smuzhiyun 
wqe_to_tid_req(struct rvt_swqe * wqe)375*4882a593Smuzhiyun static inline struct tid_rdma_request *wqe_to_tid_req(struct rvt_swqe *wqe)
376*4882a593Smuzhiyun {
377*4882a593Smuzhiyun 	return &((struct hfi1_swqe_priv *)wqe->priv)->tid_req;
378*4882a593Smuzhiyun }
379*4882a593Smuzhiyun 
ack_to_tid_req(struct rvt_ack_entry * e)380*4882a593Smuzhiyun static inline struct tid_rdma_request *ack_to_tid_req(struct rvt_ack_entry *e)
381*4882a593Smuzhiyun {
382*4882a593Smuzhiyun 	return &((struct hfi1_ack_priv *)e->priv)->tid_req;
383*4882a593Smuzhiyun }
384*4882a593Smuzhiyun 
385*4882a593Smuzhiyun /*
386*4882a593Smuzhiyun  * Look through all the active flows for a TID RDMA request and find
387*4882a593Smuzhiyun  * the one (if it exists) that contains the specified PSN.
388*4882a593Smuzhiyun  */
__full_flow_psn(struct flow_state * state,u32 psn)389*4882a593Smuzhiyun static inline u32 __full_flow_psn(struct flow_state *state, u32 psn)
390*4882a593Smuzhiyun {
391*4882a593Smuzhiyun 	return mask_psn((state->generation << HFI1_KDETH_BTH_SEQ_SHIFT) |
392*4882a593Smuzhiyun 			(psn & HFI1_KDETH_BTH_SEQ_MASK));
393*4882a593Smuzhiyun }
394*4882a593Smuzhiyun 
full_flow_psn(struct tid_rdma_flow * flow,u32 psn)395*4882a593Smuzhiyun static inline u32 full_flow_psn(struct tid_rdma_flow *flow, u32 psn)
396*4882a593Smuzhiyun {
397*4882a593Smuzhiyun 	return __full_flow_psn(&flow->flow_state, psn);
398*4882a593Smuzhiyun }
399*4882a593Smuzhiyun 
400*4882a593Smuzhiyun struct verbs_txreq;
401*4882a593Smuzhiyun void hfi1_put_txreq(struct verbs_txreq *tx);
402*4882a593Smuzhiyun 
403*4882a593Smuzhiyun int hfi1_verbs_send(struct rvt_qp *qp, struct hfi1_pkt_state *ps);
404*4882a593Smuzhiyun 
405*4882a593Smuzhiyun void hfi1_cnp_rcv(struct hfi1_packet *packet);
406*4882a593Smuzhiyun 
407*4882a593Smuzhiyun void hfi1_uc_rcv(struct hfi1_packet *packet);
408*4882a593Smuzhiyun 
409*4882a593Smuzhiyun void hfi1_rc_rcv(struct hfi1_packet *packet);
410*4882a593Smuzhiyun 
411*4882a593Smuzhiyun void hfi1_rc_hdrerr(
412*4882a593Smuzhiyun 	struct hfi1_ctxtdata *rcd,
413*4882a593Smuzhiyun 	struct hfi1_packet *packet,
414*4882a593Smuzhiyun 	struct rvt_qp *qp);
415*4882a593Smuzhiyun 
416*4882a593Smuzhiyun u8 ah_to_sc(struct ib_device *ibdev, struct rdma_ah_attr *ah_attr);
417*4882a593Smuzhiyun 
418*4882a593Smuzhiyun void hfi1_rc_verbs_aborted(struct rvt_qp *qp, struct hfi1_opa_header *opah);
419*4882a593Smuzhiyun void hfi1_rc_send_complete(struct rvt_qp *qp, struct hfi1_opa_header *opah);
420*4882a593Smuzhiyun 
421*4882a593Smuzhiyun void hfi1_ud_rcv(struct hfi1_packet *packet);
422*4882a593Smuzhiyun 
423*4882a593Smuzhiyun int hfi1_lookup_pkey_idx(struct hfi1_ibport *ibp, u16 pkey);
424*4882a593Smuzhiyun 
425*4882a593Smuzhiyun void hfi1_migrate_qp(struct rvt_qp *qp);
426*4882a593Smuzhiyun 
427*4882a593Smuzhiyun int hfi1_check_modify_qp(struct rvt_qp *qp, struct ib_qp_attr *attr,
428*4882a593Smuzhiyun 			 int attr_mask, struct ib_udata *udata);
429*4882a593Smuzhiyun 
430*4882a593Smuzhiyun void hfi1_modify_qp(struct rvt_qp *qp, struct ib_qp_attr *attr,
431*4882a593Smuzhiyun 		    int attr_mask, struct ib_udata *udata);
432*4882a593Smuzhiyun void hfi1_restart_rc(struct rvt_qp *qp, u32 psn, int wait);
433*4882a593Smuzhiyun int hfi1_setup_wqe(struct rvt_qp *qp, struct rvt_swqe *wqe,
434*4882a593Smuzhiyun 		   bool *call_send);
435*4882a593Smuzhiyun 
436*4882a593Smuzhiyun extern const u32 rc_only_opcode;
437*4882a593Smuzhiyun extern const u32 uc_only_opcode;
438*4882a593Smuzhiyun 
439*4882a593Smuzhiyun int hfi1_ruc_check_hdr(struct hfi1_ibport *ibp, struct hfi1_packet *packet);
440*4882a593Smuzhiyun 
441*4882a593Smuzhiyun u32 hfi1_make_grh(struct hfi1_ibport *ibp, struct ib_grh *hdr,
442*4882a593Smuzhiyun 		  const struct ib_global_route *grh, u32 hwords, u32 nwords);
443*4882a593Smuzhiyun 
444*4882a593Smuzhiyun void hfi1_make_ruc_header(struct rvt_qp *qp, struct ib_other_headers *ohdr,
445*4882a593Smuzhiyun 			  u32 bth0, u32 bth1, u32 bth2, int middle,
446*4882a593Smuzhiyun 			  struct hfi1_pkt_state *ps);
447*4882a593Smuzhiyun 
448*4882a593Smuzhiyun bool hfi1_schedule_send_yield(struct rvt_qp *qp, struct hfi1_pkt_state *ps,
449*4882a593Smuzhiyun 			      bool tid);
450*4882a593Smuzhiyun 
451*4882a593Smuzhiyun void _hfi1_do_send(struct work_struct *work);
452*4882a593Smuzhiyun 
453*4882a593Smuzhiyun void hfi1_do_send_from_rvt(struct rvt_qp *qp);
454*4882a593Smuzhiyun 
455*4882a593Smuzhiyun void hfi1_do_send(struct rvt_qp *qp, bool in_thread);
456*4882a593Smuzhiyun 
457*4882a593Smuzhiyun void hfi1_send_rc_ack(struct hfi1_packet *packet, bool is_fecn);
458*4882a593Smuzhiyun 
459*4882a593Smuzhiyun int hfi1_make_rc_req(struct rvt_qp *qp, struct hfi1_pkt_state *ps);
460*4882a593Smuzhiyun 
461*4882a593Smuzhiyun int hfi1_make_uc_req(struct rvt_qp *qp, struct hfi1_pkt_state *ps);
462*4882a593Smuzhiyun 
463*4882a593Smuzhiyun int hfi1_make_ud_req(struct rvt_qp *qp, struct hfi1_pkt_state *ps);
464*4882a593Smuzhiyun 
465*4882a593Smuzhiyun int hfi1_register_ib_device(struct hfi1_devdata *);
466*4882a593Smuzhiyun 
467*4882a593Smuzhiyun void hfi1_unregister_ib_device(struct hfi1_devdata *);
468*4882a593Smuzhiyun 
469*4882a593Smuzhiyun void hfi1_kdeth_eager_rcv(struct hfi1_packet *packet);
470*4882a593Smuzhiyun 
471*4882a593Smuzhiyun void hfi1_kdeth_expected_rcv(struct hfi1_packet *packet);
472*4882a593Smuzhiyun 
473*4882a593Smuzhiyun void hfi1_ib_rcv(struct hfi1_packet *packet);
474*4882a593Smuzhiyun 
475*4882a593Smuzhiyun void hfi1_16B_rcv(struct hfi1_packet *packet);
476*4882a593Smuzhiyun 
477*4882a593Smuzhiyun unsigned hfi1_get_npkeys(struct hfi1_devdata *);
478*4882a593Smuzhiyun 
479*4882a593Smuzhiyun int hfi1_verbs_send_dma(struct rvt_qp *qp, struct hfi1_pkt_state *ps,
480*4882a593Smuzhiyun 			u64 pbc);
481*4882a593Smuzhiyun 
482*4882a593Smuzhiyun int hfi1_verbs_send_pio(struct rvt_qp *qp, struct hfi1_pkt_state *ps,
483*4882a593Smuzhiyun 			u64 pbc);
484*4882a593Smuzhiyun 
opa_bth_is_migration(struct ib_other_headers * ohdr)485*4882a593Smuzhiyun static inline bool opa_bth_is_migration(struct ib_other_headers *ohdr)
486*4882a593Smuzhiyun {
487*4882a593Smuzhiyun 	return ohdr->bth[1] & cpu_to_be32(OPA_BTH_MIG_REQ);
488*4882a593Smuzhiyun }
489*4882a593Smuzhiyun 
490*4882a593Smuzhiyun void hfi1_wait_kmem(struct rvt_qp *qp);
491*4882a593Smuzhiyun 
hfi1_trdma_send_complete(struct rvt_qp * qp,struct rvt_swqe * wqe,enum ib_wc_status status)492*4882a593Smuzhiyun static inline void hfi1_trdma_send_complete(struct rvt_qp *qp,
493*4882a593Smuzhiyun 					    struct rvt_swqe *wqe,
494*4882a593Smuzhiyun 					    enum ib_wc_status status)
495*4882a593Smuzhiyun {
496*4882a593Smuzhiyun 	trdma_clean_swqe(qp, wqe);
497*4882a593Smuzhiyun 	rvt_send_complete(qp, wqe, status);
498*4882a593Smuzhiyun }
499*4882a593Smuzhiyun 
500*4882a593Smuzhiyun extern const enum ib_wc_opcode ib_hfi1_wc_opcode[];
501*4882a593Smuzhiyun 
502*4882a593Smuzhiyun extern const u8 hdr_len_by_opcode[];
503*4882a593Smuzhiyun 
504*4882a593Smuzhiyun extern const int ib_rvt_state_ops[];
505*4882a593Smuzhiyun 
506*4882a593Smuzhiyun extern __be64 ib_hfi1_sys_image_guid;    /* in network order */
507*4882a593Smuzhiyun 
508*4882a593Smuzhiyun extern unsigned int hfi1_max_cqes;
509*4882a593Smuzhiyun 
510*4882a593Smuzhiyun extern unsigned int hfi1_max_cqs;
511*4882a593Smuzhiyun 
512*4882a593Smuzhiyun extern unsigned int hfi1_max_qp_wrs;
513*4882a593Smuzhiyun 
514*4882a593Smuzhiyun extern unsigned int hfi1_max_qps;
515*4882a593Smuzhiyun 
516*4882a593Smuzhiyun extern unsigned int hfi1_max_sges;
517*4882a593Smuzhiyun 
518*4882a593Smuzhiyun extern unsigned int hfi1_max_mcast_grps;
519*4882a593Smuzhiyun 
520*4882a593Smuzhiyun extern unsigned int hfi1_max_mcast_qp_attached;
521*4882a593Smuzhiyun 
522*4882a593Smuzhiyun extern unsigned int hfi1_max_srqs;
523*4882a593Smuzhiyun 
524*4882a593Smuzhiyun extern unsigned int hfi1_max_srq_sges;
525*4882a593Smuzhiyun 
526*4882a593Smuzhiyun extern unsigned int hfi1_max_srq_wrs;
527*4882a593Smuzhiyun 
528*4882a593Smuzhiyun extern unsigned short piothreshold;
529*4882a593Smuzhiyun 
530*4882a593Smuzhiyun extern const u32 ib_hfi1_rnr_table[];
531*4882a593Smuzhiyun 
532*4882a593Smuzhiyun #endif                          /* HFI1_VERBS_H */
533