1f931551bSRalph Campbell /*
21fb9fed6SMike Marciniszyn  * Copyright (c) 2012 Intel Corporation.  All rights reserved.
31fb9fed6SMike Marciniszyn  * Copyright (c) 2006 - 2012 QLogic Corporation. All rights reserved.
4f931551bSRalph Campbell  * Copyright (c) 2005, 2006 PathScale, Inc. All rights reserved.
5f931551bSRalph Campbell  *
6f931551bSRalph Campbell  * This software is available to you under a choice of one of two
7f931551bSRalph Campbell  * licenses.  You may choose to be licensed under the terms of the GNU
8f931551bSRalph Campbell  * General Public License (GPL) Version 2, available from the file
9f931551bSRalph Campbell  * COPYING in the main directory of this source tree, or the
10f931551bSRalph Campbell  * OpenIB.org BSD license below:
11f931551bSRalph Campbell  *
12f931551bSRalph Campbell  *     Redistribution and use in source and binary forms, with or
13f931551bSRalph Campbell  *     without modification, are permitted provided that the following
14f931551bSRalph Campbell  *     conditions are met:
15f931551bSRalph Campbell  *
16f931551bSRalph Campbell  *      - Redistributions of source code must retain the above
17f931551bSRalph Campbell  *        copyright notice, this list of conditions and the following
18f931551bSRalph Campbell  *        disclaimer.
19f931551bSRalph Campbell  *
20f931551bSRalph Campbell  *      - Redistributions in binary form must reproduce the above
21f931551bSRalph Campbell  *        copyright notice, this list of conditions and the following
22f931551bSRalph Campbell  *        disclaimer in the documentation and/or other materials
23f931551bSRalph Campbell  *        provided with the distribution.
24f931551bSRalph Campbell  *
25f931551bSRalph Campbell  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26f931551bSRalph Campbell  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27f931551bSRalph Campbell  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28f931551bSRalph Campbell  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
29f931551bSRalph Campbell  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
30f931551bSRalph Campbell  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
31f931551bSRalph Campbell  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32f931551bSRalph Campbell  * SOFTWARE.
33f931551bSRalph Campbell  */
34f931551bSRalph Campbell 
35f931551bSRalph Campbell #ifndef QIB_VERBS_H
36f931551bSRalph Campbell #define QIB_VERBS_H
37f931551bSRalph Campbell 
38f931551bSRalph Campbell #include <linux/types.h>
39f931551bSRalph Campbell #include <linux/spinlock.h>
40f931551bSRalph Campbell #include <linux/kernel.h>
41f931551bSRalph Campbell #include <linux/interrupt.h>
42f931551bSRalph Campbell #include <linux/kref.h>
43f931551bSRalph Campbell #include <linux/workqueue.h>
446a82649fSMike Marciniszyn #include <linux/completion.h>
45f931551bSRalph Campbell #include <rdma/ib_pack.h>
46f931551bSRalph Campbell #include <rdma/ib_user_verbs.h>
47f931551bSRalph Campbell 
48f931551bSRalph Campbell struct qib_ctxtdata;
49f931551bSRalph Campbell struct qib_pportdata;
50f931551bSRalph Campbell struct qib_devdata;
51f931551bSRalph Campbell struct qib_verbs_txreq;
52f931551bSRalph Campbell 
53f931551bSRalph Campbell #define QIB_MAX_RDMA_ATOMIC     16
54f931551bSRalph Campbell #define QIB_GUIDS_PER_PORT	5
55f931551bSRalph Campbell 
56f931551bSRalph Campbell #define QPN_MAX                 (1 << 24)
57f931551bSRalph Campbell #define QPNMAP_ENTRIES          (QPN_MAX / PAGE_SIZE / BITS_PER_BYTE)
58f931551bSRalph Campbell 
59f931551bSRalph Campbell /*
60f931551bSRalph Campbell  * Increment this value if any changes that break userspace ABI
61f931551bSRalph Campbell  * compatibility are made.
62f931551bSRalph Campbell  */
63f931551bSRalph Campbell #define QIB_UVERBS_ABI_VERSION       2
64f931551bSRalph Campbell 
65f931551bSRalph Campbell /*
66f931551bSRalph Campbell  * Define an ib_cq_notify value that is not valid so we know when CQ
67f931551bSRalph Campbell  * notifications are armed.
68f931551bSRalph Campbell  */
69f931551bSRalph Campbell #define IB_CQ_NONE      (IB_CQ_NEXT_COMP + 1)
70f931551bSRalph Campbell 
71f931551bSRalph Campbell #define IB_SEQ_NAK	(3 << 29)
72f931551bSRalph Campbell 
73f931551bSRalph Campbell /* AETH NAK opcode values */
74f931551bSRalph Campbell #define IB_RNR_NAK                      0x20
75f931551bSRalph Campbell #define IB_NAK_PSN_ERROR                0x60
76f931551bSRalph Campbell #define IB_NAK_INVALID_REQUEST          0x61
77f931551bSRalph Campbell #define IB_NAK_REMOTE_ACCESS_ERROR      0x62
78f931551bSRalph Campbell #define IB_NAK_REMOTE_OPERATIONAL_ERROR 0x63
79f931551bSRalph Campbell #define IB_NAK_INVALID_RD_REQUEST       0x64
80f931551bSRalph Campbell 
81f931551bSRalph Campbell /* Flags for checking QP state (see ib_qib_state_ops[]) */
82f931551bSRalph Campbell #define QIB_POST_SEND_OK                0x01
83f931551bSRalph Campbell #define QIB_POST_RECV_OK                0x02
84f931551bSRalph Campbell #define QIB_PROCESS_RECV_OK             0x04
85f931551bSRalph Campbell #define QIB_PROCESS_SEND_OK             0x08
86f931551bSRalph Campbell #define QIB_PROCESS_NEXT_SEND_OK        0x10
87f931551bSRalph Campbell #define QIB_FLUSH_SEND			0x20
88f931551bSRalph Campbell #define QIB_FLUSH_RECV			0x40
89f931551bSRalph Campbell #define QIB_PROCESS_OR_FLUSH_SEND \
90f931551bSRalph Campbell 	(QIB_PROCESS_SEND_OK | QIB_FLUSH_SEND)
91f931551bSRalph Campbell 
92f931551bSRalph Campbell /* IB Performance Manager status values */
93f931551bSRalph Campbell #define IB_PMA_SAMPLE_STATUS_DONE       0x00
94f931551bSRalph Campbell #define IB_PMA_SAMPLE_STATUS_STARTED    0x01
95f931551bSRalph Campbell #define IB_PMA_SAMPLE_STATUS_RUNNING    0x02
96f931551bSRalph Campbell 
97f931551bSRalph Campbell /* Mandatory IB performance counter select values. */
98f931551bSRalph Campbell #define IB_PMA_PORT_XMIT_DATA   cpu_to_be16(0x0001)
99f931551bSRalph Campbell #define IB_PMA_PORT_RCV_DATA    cpu_to_be16(0x0002)
100f931551bSRalph Campbell #define IB_PMA_PORT_XMIT_PKTS   cpu_to_be16(0x0003)
101f931551bSRalph Campbell #define IB_PMA_PORT_RCV_PKTS    cpu_to_be16(0x0004)
102f931551bSRalph Campbell #define IB_PMA_PORT_XMIT_WAIT   cpu_to_be16(0x0005)
103f931551bSRalph Campbell 
104f931551bSRalph Campbell #define QIB_VENDOR_IPG		cpu_to_be16(0xFFA0)
105f931551bSRalph Campbell 
106f931551bSRalph Campbell #define IB_BTH_REQ_ACK		(1 << 31)
107f931551bSRalph Campbell #define IB_BTH_SOLICITED	(1 << 23)
108f931551bSRalph Campbell #define IB_BTH_MIG_REQ		(1 << 22)
109f931551bSRalph Campbell 
110f931551bSRalph Campbell /* XXX Should be defined in ib_verbs.h enum ib_port_cap_flags */
111f931551bSRalph Campbell #define IB_PORT_OTHER_LOCAL_CHANGES_SUP (1 << 26)
112f931551bSRalph Campbell 
113f931551bSRalph Campbell #define IB_GRH_VERSION		6
114f931551bSRalph Campbell #define IB_GRH_VERSION_MASK	0xF
115f931551bSRalph Campbell #define IB_GRH_VERSION_SHIFT	28
116f931551bSRalph Campbell #define IB_GRH_TCLASS_MASK	0xFF
117f931551bSRalph Campbell #define IB_GRH_TCLASS_SHIFT	20
118f931551bSRalph Campbell #define IB_GRH_FLOW_MASK	0xFFFFF
119f931551bSRalph Campbell #define IB_GRH_FLOW_SHIFT	0
120f931551bSRalph Campbell #define IB_GRH_NEXT_HDR		0x1B
121f931551bSRalph Campbell 
122f931551bSRalph Campbell #define IB_DEFAULT_GID_PREFIX	cpu_to_be64(0xfe80000000000000ULL)
123f931551bSRalph Campbell 
124f931551bSRalph Campbell /* Values for set/get portinfo VLCap OperationalVLs */
125f931551bSRalph Campbell #define IB_VL_VL0       1
126f931551bSRalph Campbell #define IB_VL_VL0_1     2
127f931551bSRalph Campbell #define IB_VL_VL0_3     3
128f931551bSRalph Campbell #define IB_VL_VL0_7     4
129f931551bSRalph Campbell #define IB_VL_VL0_14    5
130f931551bSRalph Campbell 
131f931551bSRalph Campbell static inline int qib_num_vls(int vls)
132f931551bSRalph Campbell {
133f931551bSRalph Campbell 	switch (vls) {
134f931551bSRalph Campbell 	default:
135f931551bSRalph Campbell 	case IB_VL_VL0:
136f931551bSRalph Campbell 		return 1;
137f931551bSRalph Campbell 	case IB_VL_VL0_1:
138f931551bSRalph Campbell 		return 2;
139f931551bSRalph Campbell 	case IB_VL_VL0_3:
140f931551bSRalph Campbell 		return 4;
141f931551bSRalph Campbell 	case IB_VL_VL0_7:
142f931551bSRalph Campbell 		return 8;
143f931551bSRalph Campbell 	case IB_VL_VL0_14:
144f931551bSRalph Campbell 		return 15;
145f931551bSRalph Campbell 	}
146f931551bSRalph Campbell }
147f931551bSRalph Campbell 
148f931551bSRalph Campbell struct ib_reth {
149f931551bSRalph Campbell 	__be64 vaddr;
150f931551bSRalph Campbell 	__be32 rkey;
151f931551bSRalph Campbell 	__be32 length;
152f931551bSRalph Campbell } __attribute__ ((packed));
153f931551bSRalph Campbell 
154f931551bSRalph Campbell struct ib_atomic_eth {
155f931551bSRalph Campbell 	__be32 vaddr[2];        /* unaligned so access as 2 32-bit words */
156f931551bSRalph Campbell 	__be32 rkey;
157f931551bSRalph Campbell 	__be64 swap_data;
158f931551bSRalph Campbell 	__be64 compare_data;
159f931551bSRalph Campbell } __attribute__ ((packed));
160f931551bSRalph Campbell 
161f931551bSRalph Campbell struct qib_other_headers {
162f931551bSRalph Campbell 	__be32 bth[3];
163f931551bSRalph Campbell 	union {
164f931551bSRalph Campbell 		struct {
165f931551bSRalph Campbell 			__be32 deth[2];
166f931551bSRalph Campbell 			__be32 imm_data;
167f931551bSRalph Campbell 		} ud;
168f931551bSRalph Campbell 		struct {
169f931551bSRalph Campbell 			struct ib_reth reth;
170f931551bSRalph Campbell 			__be32 imm_data;
171f931551bSRalph Campbell 		} rc;
172f931551bSRalph Campbell 		struct {
173f931551bSRalph Campbell 			__be32 aeth;
174f931551bSRalph Campbell 			__be32 atomic_ack_eth[2];
175f931551bSRalph Campbell 		} at;
176f931551bSRalph Campbell 		__be32 imm_data;
177f931551bSRalph Campbell 		__be32 aeth;
178f931551bSRalph Campbell 		struct ib_atomic_eth atomic_eth;
179f931551bSRalph Campbell 	} u;
180f931551bSRalph Campbell } __attribute__ ((packed));
181f931551bSRalph Campbell 
182f931551bSRalph Campbell /*
183f931551bSRalph Campbell  * Note that UD packets with a GRH header are 8+40+12+8 = 68 bytes
184f931551bSRalph Campbell  * long (72 w/ imm_data).  Only the first 56 bytes of the IB header
185f931551bSRalph Campbell  * will be in the eager header buffer.  The remaining 12 or 16 bytes
186f931551bSRalph Campbell  * are in the data buffer.
187f931551bSRalph Campbell  */
188f931551bSRalph Campbell struct qib_ib_header {
189f931551bSRalph Campbell 	__be16 lrh[4];
190f931551bSRalph Campbell 	union {
191f931551bSRalph Campbell 		struct {
192f931551bSRalph Campbell 			struct ib_grh grh;
193f931551bSRalph Campbell 			struct qib_other_headers oth;
194f931551bSRalph Campbell 		} l;
195f931551bSRalph Campbell 		struct qib_other_headers oth;
196f931551bSRalph Campbell 	} u;
197f931551bSRalph Campbell } __attribute__ ((packed));
198f931551bSRalph Campbell 
199f931551bSRalph Campbell struct qib_pio_header {
200f931551bSRalph Campbell 	__le32 pbc[2];
201f931551bSRalph Campbell 	struct qib_ib_header hdr;
202f931551bSRalph Campbell } __attribute__ ((packed));
203f931551bSRalph Campbell 
204f931551bSRalph Campbell /*
205f931551bSRalph Campbell  * There is one struct qib_mcast for each multicast GID.
206f931551bSRalph Campbell  * All attached QPs are then stored as a list of
207f931551bSRalph Campbell  * struct qib_mcast_qp.
208f931551bSRalph Campbell  */
209f931551bSRalph Campbell struct qib_mcast_qp {
210f931551bSRalph Campbell 	struct list_head list;
211f931551bSRalph Campbell 	struct qib_qp *qp;
212f931551bSRalph Campbell };
213f931551bSRalph Campbell 
214f931551bSRalph Campbell struct qib_mcast {
215f931551bSRalph Campbell 	struct rb_node rb_node;
216f931551bSRalph Campbell 	union ib_gid mgid;
217f931551bSRalph Campbell 	struct list_head qp_list;
218f931551bSRalph Campbell 	wait_queue_head_t wait;
219f931551bSRalph Campbell 	atomic_t refcount;
220f931551bSRalph Campbell 	int n_attached;
221f931551bSRalph Campbell };
222f931551bSRalph Campbell 
223f931551bSRalph Campbell /* Protection domain */
224f931551bSRalph Campbell struct qib_pd {
225f931551bSRalph Campbell 	struct ib_pd ibpd;
226f931551bSRalph Campbell 	int user;               /* non-zero if created from user space */
227f931551bSRalph Campbell };
228f931551bSRalph Campbell 
229f931551bSRalph Campbell /* Address Handle */
230f931551bSRalph Campbell struct qib_ah {
231f931551bSRalph Campbell 	struct ib_ah ibah;
232f931551bSRalph Campbell 	struct ib_ah_attr attr;
233f931551bSRalph Campbell 	atomic_t refcount;
234f931551bSRalph Campbell };
235f931551bSRalph Campbell 
236f931551bSRalph Campbell /*
237f931551bSRalph Campbell  * This structure is used by qib_mmap() to validate an offset
238f931551bSRalph Campbell  * when an mmap() request is made.  The vm_area_struct then uses
239f931551bSRalph Campbell  * this as its vm_private_data.
240f931551bSRalph Campbell  */
241f931551bSRalph Campbell struct qib_mmap_info {
242f931551bSRalph Campbell 	struct list_head pending_mmaps;
243f931551bSRalph Campbell 	struct ib_ucontext *context;
244f931551bSRalph Campbell 	void *obj;
245f931551bSRalph Campbell 	__u64 offset;
246f931551bSRalph Campbell 	struct kref ref;
247f931551bSRalph Campbell 	unsigned size;
248f931551bSRalph Campbell };
249f931551bSRalph Campbell 
250f931551bSRalph Campbell /*
251f931551bSRalph Campbell  * This structure is used to contain the head pointer, tail pointer,
252f931551bSRalph Campbell  * and completion queue entries as a single memory allocation so
253f931551bSRalph Campbell  * it can be mmap'ed into user space.
254f931551bSRalph Campbell  */
255f931551bSRalph Campbell struct qib_cq_wc {
256f931551bSRalph Campbell 	u32 head;               /* index of next entry to fill */
257f931551bSRalph Campbell 	u32 tail;               /* index of next ib_poll_cq() entry */
258f931551bSRalph Campbell 	union {
259f931551bSRalph Campbell 		/* these are actually size ibcq.cqe + 1 */
260f931551bSRalph Campbell 		struct ib_uverbs_wc uqueue[0];
261f931551bSRalph Campbell 		struct ib_wc kqueue[0];
262f931551bSRalph Campbell 	};
263f931551bSRalph Campbell };
264f931551bSRalph Campbell 
265f931551bSRalph Campbell /*
266f931551bSRalph Campbell  * The completion queue structure.
267f931551bSRalph Campbell  */
268f931551bSRalph Campbell struct qib_cq {
269f931551bSRalph Campbell 	struct ib_cq ibcq;
270f931551bSRalph Campbell 	struct work_struct comptask;
271f931551bSRalph Campbell 	spinlock_t lock; /* protect changes in this struct */
272f931551bSRalph Campbell 	u8 notify;
273f931551bSRalph Campbell 	u8 triggered;
274f931551bSRalph Campbell 	struct qib_cq_wc *queue;
275f931551bSRalph Campbell 	struct qib_mmap_info *ip;
276f931551bSRalph Campbell };
277f931551bSRalph Campbell 
278f931551bSRalph Campbell /*
279f931551bSRalph Campbell  * A segment is a linear region of low physical memory.
280f931551bSRalph Campbell  * XXX Maybe we should use phys addr here and kmap()/kunmap().
281f931551bSRalph Campbell  * Used by the verbs layer.
282f931551bSRalph Campbell  */
283f931551bSRalph Campbell struct qib_seg {
284f931551bSRalph Campbell 	void *vaddr;
285f931551bSRalph Campbell 	size_t length;
286f931551bSRalph Campbell };
287f931551bSRalph Campbell 
288f931551bSRalph Campbell /* The number of qib_segs that fit in a page. */
289f931551bSRalph Campbell #define QIB_SEGSZ     (PAGE_SIZE / sizeof(struct qib_seg))
290f931551bSRalph Campbell 
291f931551bSRalph Campbell struct qib_segarray {
292f931551bSRalph Campbell 	struct qib_seg segs[QIB_SEGSZ];
293f931551bSRalph Campbell };
294f931551bSRalph Campbell 
295f931551bSRalph Campbell struct qib_mregion {
296f931551bSRalph Campbell 	struct ib_pd *pd;       /* shares refcnt of ibmr.pd */
297f931551bSRalph Campbell 	u64 user_base;          /* User's address for this region */
298f931551bSRalph Campbell 	u64 iova;               /* IB start address of this region */
299f931551bSRalph Campbell 	size_t length;
300f931551bSRalph Campbell 	u32 lkey;
301f931551bSRalph Campbell 	u32 offset;             /* offset (bytes) to start of region */
302f931551bSRalph Campbell 	int access_flags;
303f931551bSRalph Campbell 	u32 max_segs;           /* number of qib_segs in all the arrays */
304f931551bSRalph Campbell 	u32 mapsz;              /* size of the map array */
3052a600f14SMike Marciniszyn 	u8  page_shift;         /* 0 - non unform/non powerof2 sizes */
3066a82649fSMike Marciniszyn 	u8  lkey_published;     /* in global table */
3076a82649fSMike Marciniszyn 	struct completion comp; /* complete when refcount goes to zero */
3088aac4cc3SMike Marciniszyn 	struct rcu_head list;
309f931551bSRalph Campbell 	atomic_t refcount;
310f931551bSRalph Campbell 	struct qib_segarray *map[0];    /* the segments */
311f931551bSRalph Campbell };
312f931551bSRalph Campbell 
313f931551bSRalph Campbell /*
314f931551bSRalph Campbell  * These keep track of the copy progress within a memory region.
315f931551bSRalph Campbell  * Used by the verbs layer.
316f931551bSRalph Campbell  */
317f931551bSRalph Campbell struct qib_sge {
318f931551bSRalph Campbell 	struct qib_mregion *mr;
319f931551bSRalph Campbell 	void *vaddr;            /* kernel virtual address of segment */
320f931551bSRalph Campbell 	u32 sge_length;         /* length of the SGE */
321f931551bSRalph Campbell 	u32 length;             /* remaining length of the segment */
322f931551bSRalph Campbell 	u16 m;                  /* current index: mr->map[m] */
323f931551bSRalph Campbell 	u16 n;                  /* current index: mr->map[m]->segs[n] */
324f931551bSRalph Campbell };
325f931551bSRalph Campbell 
326f931551bSRalph Campbell /* Memory region */
327f931551bSRalph Campbell struct qib_mr {
328f931551bSRalph Campbell 	struct ib_mr ibmr;
329f931551bSRalph Campbell 	struct ib_umem *umem;
330f931551bSRalph Campbell 	struct qib_mregion mr;  /* must be last */
331f931551bSRalph Campbell };
332f931551bSRalph Campbell 
333f931551bSRalph Campbell /*
334f931551bSRalph Campbell  * Send work request queue entry.
335f931551bSRalph Campbell  * The size of the sg_list is determined when the QP is created and stored
336f931551bSRalph Campbell  * in qp->s_max_sge.
337f931551bSRalph Campbell  */
338f931551bSRalph Campbell struct qib_swqe {
339f931551bSRalph Campbell 	struct ib_send_wr wr;   /* don't use wr.sg_list */
340f931551bSRalph Campbell 	u32 psn;                /* first packet sequence number */
341f931551bSRalph Campbell 	u32 lpsn;               /* last packet sequence number */
342f931551bSRalph Campbell 	u32 ssn;                /* send sequence number */
343f931551bSRalph Campbell 	u32 length;             /* total length of data in sg_list */
344f931551bSRalph Campbell 	struct qib_sge sg_list[0];
345f931551bSRalph Campbell };
346f931551bSRalph Campbell 
347f931551bSRalph Campbell /*
348f931551bSRalph Campbell  * Receive work request queue entry.
349f931551bSRalph Campbell  * The size of the sg_list is determined when the QP (or SRQ) is created
350f931551bSRalph Campbell  * and stored in qp->r_rq.max_sge (or srq->rq.max_sge).
351f931551bSRalph Campbell  */
352f931551bSRalph Campbell struct qib_rwqe {
353f931551bSRalph Campbell 	u64 wr_id;
354f931551bSRalph Campbell 	u8 num_sge;
355f931551bSRalph Campbell 	struct ib_sge sg_list[0];
356f931551bSRalph Campbell };
357f931551bSRalph Campbell 
358f931551bSRalph Campbell /*
359f931551bSRalph Campbell  * This structure is used to contain the head pointer, tail pointer,
360f931551bSRalph Campbell  * and receive work queue entries as a single memory allocation so
361f931551bSRalph Campbell  * it can be mmap'ed into user space.
362f931551bSRalph Campbell  * Note that the wq array elements are variable size so you can't
363f931551bSRalph Campbell  * just index into the array to get the N'th element;
364f931551bSRalph Campbell  * use get_rwqe_ptr() instead.
365f931551bSRalph Campbell  */
366f931551bSRalph Campbell struct qib_rwq {
367f931551bSRalph Campbell 	u32 head;               /* new work requests posted to the head */
368f931551bSRalph Campbell 	u32 tail;               /* receives pull requests from here. */
369f931551bSRalph Campbell 	struct qib_rwqe wq[0];
370f931551bSRalph Campbell };
371f931551bSRalph Campbell 
372f931551bSRalph Campbell struct qib_rq {
373f931551bSRalph Campbell 	struct qib_rwq *wq;
374f931551bSRalph Campbell 	u32 size;               /* size of RWQE array */
375f931551bSRalph Campbell 	u8 max_sge;
3761c94283dSMike Marciniszyn 	spinlock_t lock /* protect changes in this struct */
3771c94283dSMike Marciniszyn 		____cacheline_aligned_in_smp;
378f931551bSRalph Campbell };
379f931551bSRalph Campbell 
380f931551bSRalph Campbell struct qib_srq {
381f931551bSRalph Campbell 	struct ib_srq ibsrq;
382f931551bSRalph Campbell 	struct qib_rq rq;
383f931551bSRalph Campbell 	struct qib_mmap_info *ip;
384f931551bSRalph Campbell 	/* send signal when number of RWQEs < limit */
385f931551bSRalph Campbell 	u32 limit;
386f931551bSRalph Campbell };
387f931551bSRalph Campbell 
388f931551bSRalph Campbell struct qib_sge_state {
389f931551bSRalph Campbell 	struct qib_sge *sg_list;      /* next SGE to be used if any */
390f931551bSRalph Campbell 	struct qib_sge sge;   /* progress state for the current SGE */
391f931551bSRalph Campbell 	u32 total_len;
392f931551bSRalph Campbell 	u8 num_sge;
393f931551bSRalph Campbell };
394f931551bSRalph Campbell 
395f931551bSRalph Campbell /*
396f931551bSRalph Campbell  * This structure holds the information that the send tasklet needs
397f931551bSRalph Campbell  * to send a RDMA read response or atomic operation.
398f931551bSRalph Campbell  */
399f931551bSRalph Campbell struct qib_ack_entry {
400f931551bSRalph Campbell 	u8 opcode;
401f931551bSRalph Campbell 	u8 sent;
402f931551bSRalph Campbell 	u32 psn;
403f931551bSRalph Campbell 	u32 lpsn;
404f931551bSRalph Campbell 	union {
405f931551bSRalph Campbell 		struct qib_sge rdma_sge;
406f931551bSRalph Campbell 		u64 atomic_data;
407f931551bSRalph Campbell 	};
408f931551bSRalph Campbell };
409f931551bSRalph Campbell 
410f931551bSRalph Campbell /*
411f931551bSRalph Campbell  * Variables prefixed with s_ are for the requester (sender).
412f931551bSRalph Campbell  * Variables prefixed with r_ are for the responder (receiver).
413f931551bSRalph Campbell  * Variables prefixed with ack_ are for responder replies.
414f931551bSRalph Campbell  *
415f931551bSRalph Campbell  * Common variables are protected by both r_rq.lock and s_lock in that order
416f931551bSRalph Campbell  * which only happens in modify_qp() or changing the QP 'state'.
417f931551bSRalph Campbell  */
418f931551bSRalph Campbell struct qib_qp {
419f931551bSRalph Campbell 	struct ib_qp ibqp;
4201c94283dSMike Marciniszyn 	/* read mostly fields above and below */
421f931551bSRalph Campbell 	struct ib_ah_attr remote_ah_attr;
422f931551bSRalph Campbell 	struct ib_ah_attr alt_ah_attr;
4231fb9fed6SMike Marciniszyn 	struct qib_qp __rcu *next;            /* link list for QPN hash table */
4241c94283dSMike Marciniszyn 	struct qib_swqe *s_wq;  /* send work queue */
425f931551bSRalph Campbell 	struct qib_mmap_info *ip;
4261c94283dSMike Marciniszyn 	struct qib_ib_header *s_hdr;     /* next packet header to send */
4271c94283dSMike Marciniszyn 	unsigned long timeout_jiffies;  /* computed from timeout */
4281c94283dSMike Marciniszyn 
4291c94283dSMike Marciniszyn 	enum ib_mtu path_mtu;
4301c94283dSMike Marciniszyn 	u32 remote_qpn;
4311c94283dSMike Marciniszyn 	u32 pmtu;		/* decoded from path_mtu */
4321c94283dSMike Marciniszyn 	u32 qkey;               /* QKEY for this QP (for UD or RD) */
4331c94283dSMike Marciniszyn 	u32 s_size;             /* send work queue size */
4341c94283dSMike Marciniszyn 	u32 s_rnr_timeout;      /* number of milliseconds for RNR timeout */
4351c94283dSMike Marciniszyn 
4361c94283dSMike Marciniszyn 	u8 state;               /* QP state */
4371c94283dSMike Marciniszyn 	u8 qp_access_flags;
4381c94283dSMike Marciniszyn 	u8 alt_timeout;         /* Alternate path timeout for this QP */
4391c94283dSMike Marciniszyn 	u8 timeout;             /* Timeout for this QP */
4401c94283dSMike Marciniszyn 	u8 s_srate;
4411c94283dSMike Marciniszyn 	u8 s_mig_state;
4421c94283dSMike Marciniszyn 	u8 port_num;
4431c94283dSMike Marciniszyn 	u8 s_pkey_index;        /* PKEY index to use */
4441c94283dSMike Marciniszyn 	u8 s_alt_pkey_index;    /* Alternate path PKEY index to use */
4451c94283dSMike Marciniszyn 	u8 r_max_rd_atomic;     /* max number of RDMA read/atomic to receive */
4461c94283dSMike Marciniszyn 	u8 s_max_rd_atomic;     /* max number of RDMA read/atomic to send */
4471c94283dSMike Marciniszyn 	u8 s_retry_cnt;         /* number of times to retry */
4481c94283dSMike Marciniszyn 	u8 s_rnr_retry_cnt;
4491c94283dSMike Marciniszyn 	u8 r_min_rnr_timer;     /* retry timeout value for RNR NAKs */
4501c94283dSMike Marciniszyn 	u8 s_max_sge;           /* size of s_wq->sg_list */
4511c94283dSMike Marciniszyn 	u8 s_draining;
4521c94283dSMike Marciniszyn 
4531c94283dSMike Marciniszyn 	/* start of read/write fields */
4541c94283dSMike Marciniszyn 
4551c94283dSMike Marciniszyn 	atomic_t refcount ____cacheline_aligned_in_smp;
4561c94283dSMike Marciniszyn 	wait_queue_head_t wait;
4571c94283dSMike Marciniszyn 
4581c94283dSMike Marciniszyn 
4591c94283dSMike Marciniszyn 	struct qib_ack_entry s_ack_queue[QIB_MAX_RDMA_ATOMIC + 1]
4601c94283dSMike Marciniszyn 		____cacheline_aligned_in_smp;
461f931551bSRalph Campbell 	struct qib_sge_state s_rdma_read_sge;
4621c94283dSMike Marciniszyn 
4631c94283dSMike Marciniszyn 	spinlock_t r_lock ____cacheline_aligned_in_smp;      /* used for APM */
4641c94283dSMike Marciniszyn 	unsigned long r_aflags;
4651c94283dSMike Marciniszyn 	u64 r_wr_id;            /* ID for current receive WQE */
4661c94283dSMike Marciniszyn 	u32 r_ack_psn;          /* PSN for next ACK or atomic ACK */
4671c94283dSMike Marciniszyn 	u32 r_len;              /* total length of r_sge */
4681c94283dSMike Marciniszyn 	u32 r_rcv_len;          /* receive data len processed */
4691c94283dSMike Marciniszyn 	u32 r_psn;              /* expected rcv packet sequence number */
4701c94283dSMike Marciniszyn 	u32 r_msn;              /* message sequence number */
4711c94283dSMike Marciniszyn 
4721c94283dSMike Marciniszyn 	u8 r_state;             /* opcode of last packet received */
4731c94283dSMike Marciniszyn 	u8 r_flags;
4741c94283dSMike Marciniszyn 	u8 r_head_ack_queue;    /* index into s_ack_queue[] */
4751c94283dSMike Marciniszyn 
4761c94283dSMike Marciniszyn 	struct list_head rspwait;       /* link for waititing to respond */
4771c94283dSMike Marciniszyn 
478f931551bSRalph Campbell 	struct qib_sge_state r_sge;     /* current receive data */
4791c94283dSMike Marciniszyn 	struct qib_rq r_rq;             /* receive work queue */
4801c94283dSMike Marciniszyn 
4811c94283dSMike Marciniszyn 	spinlock_t s_lock ____cacheline_aligned_in_smp;
4821c94283dSMike Marciniszyn 	struct qib_sge_state *s_cur_sge;
483f931551bSRalph Campbell 	u32 s_flags;
4841c94283dSMike Marciniszyn 	struct qib_verbs_txreq *s_tx;
4851c94283dSMike Marciniszyn 	struct qib_swqe *s_wqe;
4861c94283dSMike Marciniszyn 	struct qib_sge_state s_sge;     /* current send request data */
4871c94283dSMike Marciniszyn 	struct qib_mregion *s_rdma_mr;
4881c94283dSMike Marciniszyn 	atomic_t s_dma_busy;
489f931551bSRalph Campbell 	u32 s_cur_size;         /* size of send packet in bytes */
490f931551bSRalph Campbell 	u32 s_len;              /* total length of s_sge */
491f931551bSRalph Campbell 	u32 s_rdma_read_len;    /* total length of s_rdma_read_sge */
492f931551bSRalph Campbell 	u32 s_next_psn;         /* PSN for next request */
493f931551bSRalph Campbell 	u32 s_last_psn;         /* last response PSN processed */
494f931551bSRalph Campbell 	u32 s_sending_psn;      /* lowest PSN that is being sent */
495f931551bSRalph Campbell 	u32 s_sending_hpsn;     /* highest PSN that is being sent */
496f931551bSRalph Campbell 	u32 s_psn;              /* current packet sequence number */
497f931551bSRalph Campbell 	u32 s_ack_rdma_psn;     /* PSN for sending RDMA read responses */
498f931551bSRalph Campbell 	u32 s_ack_psn;          /* PSN for acking sends and RDMA writes */
499f931551bSRalph Campbell 	u32 s_head;             /* new entries added here */
500f931551bSRalph Campbell 	u32 s_tail;             /* next entry to process */
501f931551bSRalph Campbell 	u32 s_cur;              /* current work queue entry */
502f931551bSRalph Campbell 	u32 s_acked;            /* last un-ACK'ed entry */
503f931551bSRalph Campbell 	u32 s_last;             /* last completed entry */
504f931551bSRalph Campbell 	u32 s_ssn;              /* SSN of tail entry */
505f931551bSRalph Campbell 	u32 s_lsn;              /* limit sequence number (credit) */
5061c94283dSMike Marciniszyn 	u16 s_hdrwords;         /* size of s_hdr in 32 bit words */
5071c94283dSMike Marciniszyn 	u16 s_rdma_ack_cnt;
5081c94283dSMike Marciniszyn 	u8 s_state;             /* opcode of last packet sent */
5091c94283dSMike Marciniszyn 	u8 s_ack_state;         /* opcode of packet to ACK */
5101c94283dSMike Marciniszyn 	u8 s_nak_state;         /* non-zero if NAK is pending */
5111c94283dSMike Marciniszyn 	u8 r_nak_state;         /* non-zero if NAK is pending */
5121c94283dSMike Marciniszyn 	u8 s_retry;             /* requester retry counter */
5131c94283dSMike Marciniszyn 	u8 s_rnr_retry;         /* requester RNR retry counter */
5141c94283dSMike Marciniszyn 	u8 s_num_rd_atomic;     /* number of RDMA read/atomic pending */
5151c94283dSMike Marciniszyn 	u8 s_tail_ack_queue;    /* index into s_ack_queue[] */
5161c94283dSMike Marciniszyn 
5171c94283dSMike Marciniszyn 	struct qib_sge_state s_ack_rdma_sge;
5181c94283dSMike Marciniszyn 	struct timer_list s_timer;
5191c94283dSMike Marciniszyn 	struct list_head iowait;        /* link for wait PIO buf */
5201c94283dSMike Marciniszyn 
5211c94283dSMike Marciniszyn 	struct work_struct s_work;
5221c94283dSMike Marciniszyn 
5231c94283dSMike Marciniszyn 	wait_queue_head_t wait_dma;
5241c94283dSMike Marciniszyn 
5251c94283dSMike Marciniszyn 	struct qib_sge r_sg_list[0] /* verified SGEs */
5261c94283dSMike Marciniszyn 		____cacheline_aligned_in_smp;
527f931551bSRalph Campbell };
528f931551bSRalph Campbell 
529f931551bSRalph Campbell /*
530f931551bSRalph Campbell  * Atomic bit definitions for r_aflags.
531f931551bSRalph Campbell  */
532f931551bSRalph Campbell #define QIB_R_WRID_VALID        0
533f931551bSRalph Campbell #define QIB_R_REWIND_SGE        1
534f931551bSRalph Campbell 
535f931551bSRalph Campbell /*
536f931551bSRalph Campbell  * Bit definitions for r_flags.
537f931551bSRalph Campbell  */
538f931551bSRalph Campbell #define QIB_R_REUSE_SGE 0x01
539f931551bSRalph Campbell #define QIB_R_RDMAR_SEQ 0x02
540f931551bSRalph Campbell #define QIB_R_RSP_NAK   0x04
541f931551bSRalph Campbell #define QIB_R_RSP_SEND  0x08
542f931551bSRalph Campbell #define QIB_R_COMM_EST  0x10
543f931551bSRalph Campbell 
544f931551bSRalph Campbell /*
545f931551bSRalph Campbell  * Bit definitions for s_flags.
546f931551bSRalph Campbell  *
547f931551bSRalph Campbell  * QIB_S_SIGNAL_REQ_WR - set if QP send WRs contain completion signaled
548f931551bSRalph Campbell  * QIB_S_BUSY - send tasklet is processing the QP
549f931551bSRalph Campbell  * QIB_S_TIMER - the RC retry timer is active
550f931551bSRalph Campbell  * QIB_S_ACK_PENDING - an ACK is waiting to be sent after RDMA read/atomics
551f931551bSRalph Campbell  * QIB_S_WAIT_FENCE - waiting for all prior RDMA read or atomic SWQEs
552f931551bSRalph Campbell  *                         before processing the next SWQE
553f931551bSRalph Campbell  * QIB_S_WAIT_RDMAR - waiting for a RDMA read or atomic SWQE to complete
554f931551bSRalph Campbell  *                         before processing the next SWQE
555f931551bSRalph Campbell  * QIB_S_WAIT_RNR - waiting for RNR timeout
556f931551bSRalph Campbell  * QIB_S_WAIT_SSN_CREDIT - waiting for RC credits to process next SWQE
557f931551bSRalph Campbell  * QIB_S_WAIT_DMA - waiting for send DMA queue to drain before generating
558f931551bSRalph Campbell  *                  next send completion entry not via send DMA
559f931551bSRalph Campbell  * QIB_S_WAIT_PIO - waiting for a send buffer to be available
560f931551bSRalph Campbell  * QIB_S_WAIT_TX - waiting for a struct qib_verbs_txreq to be available
561f931551bSRalph Campbell  * QIB_S_WAIT_DMA_DESC - waiting for DMA descriptors to be available
562f931551bSRalph Campbell  * QIB_S_WAIT_KMEM - waiting for kernel memory to be available
563f931551bSRalph Campbell  * QIB_S_WAIT_PSN - waiting for a packet to exit the send DMA queue
564f931551bSRalph Campbell  * QIB_S_WAIT_ACK - waiting for an ACK packet before sending more requests
565f931551bSRalph Campbell  * QIB_S_SEND_ONE - send one packet, request ACK, then wait for ACK
566f931551bSRalph Campbell  */
567f931551bSRalph Campbell #define QIB_S_SIGNAL_REQ_WR	0x0001
568f931551bSRalph Campbell #define QIB_S_BUSY		0x0002
569f931551bSRalph Campbell #define QIB_S_TIMER		0x0004
570f931551bSRalph Campbell #define QIB_S_RESP_PENDING	0x0008
571f931551bSRalph Campbell #define QIB_S_ACK_PENDING	0x0010
572f931551bSRalph Campbell #define QIB_S_WAIT_FENCE	0x0020
573f931551bSRalph Campbell #define QIB_S_WAIT_RDMAR	0x0040
574f931551bSRalph Campbell #define QIB_S_WAIT_RNR		0x0080
575f931551bSRalph Campbell #define QIB_S_WAIT_SSN_CREDIT	0x0100
576f931551bSRalph Campbell #define QIB_S_WAIT_DMA		0x0200
577f931551bSRalph Campbell #define QIB_S_WAIT_PIO		0x0400
578f931551bSRalph Campbell #define QIB_S_WAIT_TX		0x0800
579f931551bSRalph Campbell #define QIB_S_WAIT_DMA_DESC	0x1000
580f931551bSRalph Campbell #define QIB_S_WAIT_KMEM		0x2000
581f931551bSRalph Campbell #define QIB_S_WAIT_PSN		0x4000
582f931551bSRalph Campbell #define QIB_S_WAIT_ACK		0x8000
583f931551bSRalph Campbell #define QIB_S_SEND_ONE		0x10000
584f931551bSRalph Campbell #define QIB_S_UNLIMITED_CREDIT	0x20000
585f931551bSRalph Campbell 
586f931551bSRalph Campbell /*
587f931551bSRalph Campbell  * Wait flags that would prevent any packet type from being sent.
588f931551bSRalph Campbell  */
589f931551bSRalph Campbell #define QIB_S_ANY_WAIT_IO (QIB_S_WAIT_PIO | QIB_S_WAIT_TX | \
590f931551bSRalph Campbell 	QIB_S_WAIT_DMA_DESC | QIB_S_WAIT_KMEM)
591f931551bSRalph Campbell 
592f931551bSRalph Campbell /*
593f931551bSRalph Campbell  * Wait flags that would prevent send work requests from making progress.
594f931551bSRalph Campbell  */
595f931551bSRalph Campbell #define QIB_S_ANY_WAIT_SEND (QIB_S_WAIT_FENCE | QIB_S_WAIT_RDMAR | \
596f931551bSRalph Campbell 	QIB_S_WAIT_RNR | QIB_S_WAIT_SSN_CREDIT | QIB_S_WAIT_DMA | \
597f931551bSRalph Campbell 	QIB_S_WAIT_PSN | QIB_S_WAIT_ACK)
598f931551bSRalph Campbell 
599f931551bSRalph Campbell #define QIB_S_ANY_WAIT (QIB_S_ANY_WAIT_IO | QIB_S_ANY_WAIT_SEND)
600f931551bSRalph Campbell 
601f931551bSRalph Campbell #define QIB_PSN_CREDIT  16
602f931551bSRalph Campbell 
603f931551bSRalph Campbell /*
604f931551bSRalph Campbell  * Since struct qib_swqe is not a fixed size, we can't simply index into
605f931551bSRalph Campbell  * struct qib_qp.s_wq.  This function does the array index computation.
606f931551bSRalph Campbell  */
607f931551bSRalph Campbell static inline struct qib_swqe *get_swqe_ptr(struct qib_qp *qp,
608f931551bSRalph Campbell 					      unsigned n)
609f931551bSRalph Campbell {
610f931551bSRalph Campbell 	return (struct qib_swqe *)((char *)qp->s_wq +
611f931551bSRalph Campbell 				     (sizeof(struct qib_swqe) +
612f931551bSRalph Campbell 				      qp->s_max_sge *
613f931551bSRalph Campbell 				      sizeof(struct qib_sge)) * n);
614f931551bSRalph Campbell }
615f931551bSRalph Campbell 
616f931551bSRalph Campbell /*
617f931551bSRalph Campbell  * Since struct qib_rwqe is not a fixed size, we can't simply index into
618f931551bSRalph Campbell  * struct qib_rwq.wq.  This function does the array index computation.
619f931551bSRalph Campbell  */
620f931551bSRalph Campbell static inline struct qib_rwqe *get_rwqe_ptr(struct qib_rq *rq, unsigned n)
621f931551bSRalph Campbell {
622f931551bSRalph Campbell 	return (struct qib_rwqe *)
623f931551bSRalph Campbell 		((char *) rq->wq->wq +
624f931551bSRalph Campbell 		 (sizeof(struct qib_rwqe) +
625f931551bSRalph Campbell 		  rq->max_sge * sizeof(struct ib_sge)) * n);
626f931551bSRalph Campbell }
627f931551bSRalph Campbell 
628f931551bSRalph Campbell /*
629f931551bSRalph Campbell  * QPN-map pages start out as NULL, they get allocated upon
630f931551bSRalph Campbell  * first use and are never deallocated. This way,
631f931551bSRalph Campbell  * large bitmaps are not allocated unless large numbers of QPs are used.
632f931551bSRalph Campbell  */
633f931551bSRalph Campbell struct qpn_map {
634f931551bSRalph Campbell 	void *page;
635f931551bSRalph Campbell };
636f931551bSRalph Campbell 
637f931551bSRalph Campbell struct qib_qpn_table {
638f931551bSRalph Campbell 	spinlock_t lock; /* protect changes in this struct */
639f931551bSRalph Campbell 	unsigned flags;         /* flags for QP0/1 allocated for each port */
640f931551bSRalph Campbell 	u32 last;               /* last QP number allocated */
641f931551bSRalph Campbell 	u32 nmaps;              /* size of the map table */
642f931551bSRalph Campbell 	u16 limit;
643f931551bSRalph Campbell 	u16 mask;
644f931551bSRalph Campbell 	/* bit map of free QP numbers other than 0/1 */
645f931551bSRalph Campbell 	struct qpn_map map[QPNMAP_ENTRIES];
646f931551bSRalph Campbell };
647f931551bSRalph Campbell 
648f931551bSRalph Campbell struct qib_lkey_table {
649f931551bSRalph Campbell 	spinlock_t lock; /* protect changes in this struct */
650f931551bSRalph Campbell 	u32 next;               /* next unused index (speeds search) */
651f931551bSRalph Campbell 	u32 gen;                /* generation count */
652f931551bSRalph Campbell 	u32 max;                /* size of the table */
6537e230177SMike Marciniszyn 	struct qib_mregion __rcu **table;
654f931551bSRalph Campbell };
655f931551bSRalph Campbell 
656f931551bSRalph Campbell struct qib_opcode_stats {
657f931551bSRalph Campbell 	u64 n_packets;          /* number of packets */
658f931551bSRalph Campbell 	u64 n_bytes;            /* total number of bytes */
659f931551bSRalph Campbell };
660f931551bSRalph Campbell 
661f931551bSRalph Campbell struct qib_ibport {
6621fb9fed6SMike Marciniszyn 	struct qib_qp __rcu *qp0;
6631fb9fed6SMike Marciniszyn 	struct qib_qp __rcu *qp1;
664f931551bSRalph Campbell 	struct ib_mad_agent *send_agent;	/* agent for SMI (traps) */
665f931551bSRalph Campbell 	struct qib_ah *sm_ah;
666f931551bSRalph Campbell 	struct qib_ah *smi_ah;
667f931551bSRalph Campbell 	struct rb_root mcast_tree;
668f931551bSRalph Campbell 	spinlock_t lock;		/* protect changes in this struct */
669f931551bSRalph Campbell 
670f931551bSRalph Campbell 	/* non-zero when timer is set */
671f931551bSRalph Campbell 	unsigned long mkey_lease_timeout;
672f931551bSRalph Campbell 	unsigned long trap_timeout;
673f931551bSRalph Campbell 	__be64 gid_prefix;      /* in network order */
674f931551bSRalph Campbell 	__be64 mkey;
675f931551bSRalph Campbell 	__be64 guids[QIB_GUIDS_PER_PORT	- 1];	/* writable GUIDs */
676f931551bSRalph Campbell 	u64 tid;		/* TID for traps */
677f931551bSRalph Campbell 	u64 n_unicast_xmit;     /* total unicast packets sent */
678f931551bSRalph Campbell 	u64 n_unicast_rcv;      /* total unicast packets received */
679f931551bSRalph Campbell 	u64 n_multicast_xmit;   /* total multicast packets sent */
680f931551bSRalph Campbell 	u64 n_multicast_rcv;    /* total multicast packets received */
681f931551bSRalph Campbell 	u64 z_symbol_error_counter;             /* starting count for PMA */
682f931551bSRalph Campbell 	u64 z_link_error_recovery_counter;      /* starting count for PMA */
683f931551bSRalph Campbell 	u64 z_link_downed_counter;              /* starting count for PMA */
684f931551bSRalph Campbell 	u64 z_port_rcv_errors;                  /* starting count for PMA */
685f931551bSRalph Campbell 	u64 z_port_rcv_remphys_errors;          /* starting count for PMA */
686f931551bSRalph Campbell 	u64 z_port_xmit_discards;               /* starting count for PMA */
687f931551bSRalph Campbell 	u64 z_port_xmit_data;                   /* starting count for PMA */
688f931551bSRalph Campbell 	u64 z_port_rcv_data;                    /* starting count for PMA */
689f931551bSRalph Campbell 	u64 z_port_xmit_packets;                /* starting count for PMA */
690f931551bSRalph Campbell 	u64 z_port_rcv_packets;                 /* starting count for PMA */
691f931551bSRalph Campbell 	u32 z_local_link_integrity_errors;      /* starting count for PMA */
692f931551bSRalph Campbell 	u32 z_excessive_buffer_overrun_errors;  /* starting count for PMA */
693f931551bSRalph Campbell 	u32 z_vl15_dropped;                     /* starting count for PMA */
694f931551bSRalph Campbell 	u32 n_rc_resends;
695f931551bSRalph Campbell 	u32 n_rc_acks;
696f931551bSRalph Campbell 	u32 n_rc_qacks;
697f931551bSRalph Campbell 	u32 n_rc_delayed_comp;
698f931551bSRalph Campbell 	u32 n_seq_naks;
699f931551bSRalph Campbell 	u32 n_rdma_seq;
700f931551bSRalph Campbell 	u32 n_rnr_naks;
701f931551bSRalph Campbell 	u32 n_other_naks;
702f931551bSRalph Campbell 	u32 n_loop_pkts;
703f931551bSRalph Campbell 	u32 n_pkt_drops;
704f931551bSRalph Campbell 	u32 n_vl15_dropped;
705f931551bSRalph Campbell 	u32 n_rc_timeouts;
706f931551bSRalph Campbell 	u32 n_dmawait;
707f931551bSRalph Campbell 	u32 n_unaligned;
708f931551bSRalph Campbell 	u32 n_rc_dupreq;
709f931551bSRalph Campbell 	u32 n_rc_seqnak;
710f931551bSRalph Campbell 	u32 port_cap_flags;
711f931551bSRalph Campbell 	u32 pma_sample_start;
712f931551bSRalph Campbell 	u32 pma_sample_interval;
713f931551bSRalph Campbell 	__be16 pma_counter_select[5];
714f931551bSRalph Campbell 	u16 pma_tag;
715f931551bSRalph Campbell 	u16 pkey_violations;
716f931551bSRalph Campbell 	u16 qkey_violations;
717f931551bSRalph Campbell 	u16 mkey_violations;
718f931551bSRalph Campbell 	u16 mkey_lease_period;
719f931551bSRalph Campbell 	u16 sm_lid;
720f931551bSRalph Campbell 	u16 repress_traps;
721f931551bSRalph Campbell 	u8 sm_sl;
722f931551bSRalph Campbell 	u8 mkeyprot;
723f931551bSRalph Campbell 	u8 subnet_timeout;
724f931551bSRalph Campbell 	u8 vl_high_limit;
725f931551bSRalph Campbell 	u8 sl_to_vl[16];
726f931551bSRalph Campbell 
727f931551bSRalph Campbell 	struct qib_opcode_stats opstats[128];
728f931551bSRalph Campbell };
729f931551bSRalph Campbell 
730551ace12SMike Marciniszyn 
731f931551bSRalph Campbell struct qib_ibdev {
732f931551bSRalph Campbell 	struct ib_device ibdev;
733f931551bSRalph Campbell 	struct list_head pending_mmaps;
734f931551bSRalph Campbell 	spinlock_t mmap_offset_lock; /* protect mmap_offset */
735f931551bSRalph Campbell 	u32 mmap_offset;
7367e230177SMike Marciniszyn 	struct qib_mregion __rcu *dma_mr;
737f931551bSRalph Campbell 
738f931551bSRalph Campbell 	/* QP numbers are shared by all IB ports */
739f931551bSRalph Campbell 	struct qib_qpn_table qpn_table;
740f931551bSRalph Campbell 	struct qib_lkey_table lk_table;
741f931551bSRalph Campbell 	struct list_head piowait;       /* list for wait PIO buf */
742f931551bSRalph Campbell 	struct list_head dmawait;	/* list for wait DMA */
743f931551bSRalph Campbell 	struct list_head txwait;        /* list for wait qib_verbs_txreq */
744f931551bSRalph Campbell 	struct list_head memwait;       /* list for wait kernel memory */
745f931551bSRalph Campbell 	struct list_head txreq_free;
746f931551bSRalph Campbell 	struct timer_list mem_timer;
7471fb9fed6SMike Marciniszyn 	struct qib_qp __rcu **qp_table;
748f931551bSRalph Campbell 	struct qib_pio_header *pio_hdrs;
749f931551bSRalph Campbell 	dma_addr_t pio_hdrs_phys;
750f931551bSRalph Campbell 	/* list of QPs waiting for RNR timer */
751f931551bSRalph Campbell 	spinlock_t pending_lock; /* protect wait lists, PMA counters, etc. */
752af061a64SMike Marciniszyn 	u32 qp_table_size; /* size of the hash table */
753af061a64SMike Marciniszyn 	u32 qp_rnd; /* random bytes for hash */
754f931551bSRalph Campbell 	spinlock_t qpt_lock;
755f931551bSRalph Campbell 
756f931551bSRalph Campbell 	u32 n_piowait;
757f931551bSRalph Campbell 	u32 n_txwait;
758f931551bSRalph Campbell 
759f931551bSRalph Campbell 	u32 n_pds_allocated;    /* number of PDs allocated for device */
760f931551bSRalph Campbell 	spinlock_t n_pds_lock;
761f931551bSRalph Campbell 	u32 n_ahs_allocated;    /* number of AHs allocated for device */
762f931551bSRalph Campbell 	spinlock_t n_ahs_lock;
763f931551bSRalph Campbell 	u32 n_cqs_allocated;    /* number of CQs allocated for device */
764f931551bSRalph Campbell 	spinlock_t n_cqs_lock;
765f931551bSRalph Campbell 	u32 n_qps_allocated;    /* number of QPs allocated for device */
766f931551bSRalph Campbell 	spinlock_t n_qps_lock;
767f931551bSRalph Campbell 	u32 n_srqs_allocated;   /* number of SRQs allocated for device */
768f931551bSRalph Campbell 	spinlock_t n_srqs_lock;
769f931551bSRalph Campbell 	u32 n_mcast_grps_allocated; /* number of mcast groups allocated */
770f931551bSRalph Campbell 	spinlock_t n_mcast_grps_lock;
771f931551bSRalph Campbell };
772f931551bSRalph Campbell 
773f931551bSRalph Campbell struct qib_verbs_counters {
774f931551bSRalph Campbell 	u64 symbol_error_counter;
775f931551bSRalph Campbell 	u64 link_error_recovery_counter;
776f931551bSRalph Campbell 	u64 link_downed_counter;
777f931551bSRalph Campbell 	u64 port_rcv_errors;
778f931551bSRalph Campbell 	u64 port_rcv_remphys_errors;
779f931551bSRalph Campbell 	u64 port_xmit_discards;
780f931551bSRalph Campbell 	u64 port_xmit_data;
781f931551bSRalph Campbell 	u64 port_rcv_data;
782f931551bSRalph Campbell 	u64 port_xmit_packets;
783f931551bSRalph Campbell 	u64 port_rcv_packets;
784f931551bSRalph Campbell 	u32 local_link_integrity_errors;
785f931551bSRalph Campbell 	u32 excessive_buffer_overrun_errors;
786f931551bSRalph Campbell 	u32 vl15_dropped;
787f931551bSRalph Campbell };
788f931551bSRalph Campbell 
789f931551bSRalph Campbell static inline struct qib_mr *to_imr(struct ib_mr *ibmr)
790f931551bSRalph Campbell {
791f931551bSRalph Campbell 	return container_of(ibmr, struct qib_mr, ibmr);
792f931551bSRalph Campbell }
793f931551bSRalph Campbell 
794f931551bSRalph Campbell static inline struct qib_pd *to_ipd(struct ib_pd *ibpd)
795f931551bSRalph Campbell {
796f931551bSRalph Campbell 	return container_of(ibpd, struct qib_pd, ibpd);
797f931551bSRalph Campbell }
798f931551bSRalph Campbell 
799f931551bSRalph Campbell static inline struct qib_ah *to_iah(struct ib_ah *ibah)
800f931551bSRalph Campbell {
801f931551bSRalph Campbell 	return container_of(ibah, struct qib_ah, ibah);
802f931551bSRalph Campbell }
803f931551bSRalph Campbell 
804f931551bSRalph Campbell static inline struct qib_cq *to_icq(struct ib_cq *ibcq)
805f931551bSRalph Campbell {
806f931551bSRalph Campbell 	return container_of(ibcq, struct qib_cq, ibcq);
807f931551bSRalph Campbell }
808f931551bSRalph Campbell 
809f931551bSRalph Campbell static inline struct qib_srq *to_isrq(struct ib_srq *ibsrq)
810f931551bSRalph Campbell {
811f931551bSRalph Campbell 	return container_of(ibsrq, struct qib_srq, ibsrq);
812f931551bSRalph Campbell }
813f931551bSRalph Campbell 
814f931551bSRalph Campbell static inline struct qib_qp *to_iqp(struct ib_qp *ibqp)
815f931551bSRalph Campbell {
816f931551bSRalph Campbell 	return container_of(ibqp, struct qib_qp, ibqp);
817f931551bSRalph Campbell }
818f931551bSRalph Campbell 
819f931551bSRalph Campbell static inline struct qib_ibdev *to_idev(struct ib_device *ibdev)
820f931551bSRalph Campbell {
821f931551bSRalph Campbell 	return container_of(ibdev, struct qib_ibdev, ibdev);
822f931551bSRalph Campbell }
823f931551bSRalph Campbell 
824f931551bSRalph Campbell /*
825f931551bSRalph Campbell  * Send if not busy or waiting for I/O and either
826f931551bSRalph Campbell  * a RC response is pending or we can process send work requests.
827f931551bSRalph Campbell  */
828f931551bSRalph Campbell static inline int qib_send_ok(struct qib_qp *qp)
829f931551bSRalph Campbell {
830f931551bSRalph Campbell 	return !(qp->s_flags & (QIB_S_BUSY | QIB_S_ANY_WAIT_IO)) &&
831f931551bSRalph Campbell 		(qp->s_hdrwords || (qp->s_flags & QIB_S_RESP_PENDING) ||
832f931551bSRalph Campbell 		 !(qp->s_flags & QIB_S_ANY_WAIT_SEND));
833f931551bSRalph Campbell }
834f931551bSRalph Campbell 
835f931551bSRalph Campbell extern struct workqueue_struct *qib_cq_wq;
836f931551bSRalph Campbell 
837f931551bSRalph Campbell /*
838f931551bSRalph Campbell  * This must be called with s_lock held.
839f931551bSRalph Campbell  */
840551ace12SMike Marciniszyn void qib_schedule_send(struct qib_qp *qp);
841f931551bSRalph Campbell 
842f931551bSRalph Campbell static inline int qib_pkey_ok(u16 pkey1, u16 pkey2)
843f931551bSRalph Campbell {
844f931551bSRalph Campbell 	u16 p1 = pkey1 & 0x7FFF;
845f931551bSRalph Campbell 	u16 p2 = pkey2 & 0x7FFF;
846f931551bSRalph Campbell 
847f931551bSRalph Campbell 	/*
848f931551bSRalph Campbell 	 * Low 15 bits must be non-zero and match, and
849f931551bSRalph Campbell 	 * one of the two must be a full member.
850f931551bSRalph Campbell 	 */
851f931551bSRalph Campbell 	return p1 && p1 == p2 && ((__s16)pkey1 < 0 || (__s16)pkey2 < 0);
852f931551bSRalph Campbell }
853f931551bSRalph Campbell 
854f931551bSRalph Campbell void qib_bad_pqkey(struct qib_ibport *ibp, __be16 trap_num, u32 key, u32 sl,
855f931551bSRalph Campbell 		   u32 qp1, u32 qp2, __be16 lid1, __be16 lid2);
856f931551bSRalph Campbell void qib_cap_mask_chg(struct qib_ibport *ibp);
857f931551bSRalph Campbell void qib_sys_guid_chg(struct qib_ibport *ibp);
858f931551bSRalph Campbell void qib_node_desc_chg(struct qib_ibport *ibp);
859f931551bSRalph Campbell int qib_process_mad(struct ib_device *ibdev, int mad_flags, u8 port_num,
860f931551bSRalph Campbell 		    struct ib_wc *in_wc, struct ib_grh *in_grh,
861f931551bSRalph Campbell 		    struct ib_mad *in_mad, struct ib_mad *out_mad);
862f931551bSRalph Campbell int qib_create_agents(struct qib_ibdev *dev);
863f931551bSRalph Campbell void qib_free_agents(struct qib_ibdev *dev);
864f931551bSRalph Campbell 
865f931551bSRalph Campbell /*
866f931551bSRalph Campbell  * Compare the lower 24 bits of the two values.
867f931551bSRalph Campbell  * Returns an integer <, ==, or > than zero.
868f931551bSRalph Campbell  */
869f931551bSRalph Campbell static inline int qib_cmp24(u32 a, u32 b)
870f931551bSRalph Campbell {
871f931551bSRalph Campbell 	return (((int) a) - ((int) b)) << 8;
872f931551bSRalph Campbell }
873f931551bSRalph Campbell 
874f931551bSRalph Campbell struct qib_mcast *qib_mcast_find(struct qib_ibport *ibp, union ib_gid *mgid);
875f931551bSRalph Campbell 
876f931551bSRalph Campbell int qib_snapshot_counters(struct qib_pportdata *ppd, u64 *swords,
877f931551bSRalph Campbell 			  u64 *rwords, u64 *spkts, u64 *rpkts,
878f931551bSRalph Campbell 			  u64 *xmit_wait);
879f931551bSRalph Campbell 
880f931551bSRalph Campbell int qib_get_counters(struct qib_pportdata *ppd,
881f931551bSRalph Campbell 		     struct qib_verbs_counters *cntrs);
882f931551bSRalph Campbell 
883f931551bSRalph Campbell int qib_multicast_attach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid);
884f931551bSRalph Campbell 
885f931551bSRalph Campbell int qib_multicast_detach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid);
886f931551bSRalph Campbell 
887f931551bSRalph Campbell int qib_mcast_tree_empty(struct qib_ibport *ibp);
888f931551bSRalph Campbell 
889f931551bSRalph Campbell __be32 qib_compute_aeth(struct qib_qp *qp);
890f931551bSRalph Campbell 
891f931551bSRalph Campbell struct qib_qp *qib_lookup_qpn(struct qib_ibport *ibp, u32 qpn);
892f931551bSRalph Campbell 
893f931551bSRalph Campbell struct ib_qp *qib_create_qp(struct ib_pd *ibpd,
894f931551bSRalph Campbell 			    struct ib_qp_init_attr *init_attr,
895f931551bSRalph Campbell 			    struct ib_udata *udata);
896f931551bSRalph Campbell 
897f931551bSRalph Campbell int qib_destroy_qp(struct ib_qp *ibqp);
898f931551bSRalph Campbell 
899f931551bSRalph Campbell int qib_error_qp(struct qib_qp *qp, enum ib_wc_status err);
900f931551bSRalph Campbell 
901f931551bSRalph Campbell int qib_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr,
902f931551bSRalph Campbell 		  int attr_mask, struct ib_udata *udata);
903f931551bSRalph Campbell 
904f931551bSRalph Campbell int qib_query_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr,
905f931551bSRalph Campbell 		 int attr_mask, struct ib_qp_init_attr *init_attr);
906f931551bSRalph Campbell 
907f931551bSRalph Campbell unsigned qib_free_all_qps(struct qib_devdata *dd);
908f931551bSRalph Campbell 
909f931551bSRalph Campbell void qib_init_qpn_table(struct qib_devdata *dd, struct qib_qpn_table *qpt);
910f931551bSRalph Campbell 
911f931551bSRalph Campbell void qib_free_qpn_table(struct qib_qpn_table *qpt);
912f931551bSRalph Campbell 
913f931551bSRalph Campbell void qib_get_credit(struct qib_qp *qp, u32 aeth);
914f931551bSRalph Campbell 
915f931551bSRalph Campbell unsigned qib_pkt_delay(u32 plen, u8 snd_mult, u8 rcv_mult);
916f931551bSRalph Campbell 
917f931551bSRalph Campbell void qib_verbs_sdma_desc_avail(struct qib_pportdata *ppd, unsigned avail);
918f931551bSRalph Campbell 
919f931551bSRalph Campbell void qib_put_txreq(struct qib_verbs_txreq *tx);
920f931551bSRalph Campbell 
921f931551bSRalph Campbell int qib_verbs_send(struct qib_qp *qp, struct qib_ib_header *hdr,
922f931551bSRalph Campbell 		   u32 hdrwords, struct qib_sge_state *ss, u32 len);
923f931551bSRalph Campbell 
924f931551bSRalph Campbell void qib_copy_sge(struct qib_sge_state *ss, void *data, u32 length,
925f931551bSRalph Campbell 		  int release);
926f931551bSRalph Campbell 
927f931551bSRalph Campbell void qib_skip_sge(struct qib_sge_state *ss, u32 length, int release);
928f931551bSRalph Campbell 
929f931551bSRalph Campbell void qib_uc_rcv(struct qib_ibport *ibp, struct qib_ib_header *hdr,
930f931551bSRalph Campbell 		int has_grh, void *data, u32 tlen, struct qib_qp *qp);
931f931551bSRalph Campbell 
932f931551bSRalph Campbell void qib_rc_rcv(struct qib_ctxtdata *rcd, struct qib_ib_header *hdr,
933f931551bSRalph Campbell 		int has_grh, void *data, u32 tlen, struct qib_qp *qp);
934f931551bSRalph Campbell 
935f931551bSRalph Campbell int qib_check_ah(struct ib_device *ibdev, struct ib_ah_attr *ah_attr);
936f931551bSRalph Campbell 
9371fb9fed6SMike Marciniszyn struct ib_ah *qib_create_qp0_ah(struct qib_ibport *ibp, u16 dlid);
9381fb9fed6SMike Marciniszyn 
939f931551bSRalph Campbell void qib_rc_rnr_retry(unsigned long arg);
940f931551bSRalph Campbell 
941f931551bSRalph Campbell void qib_rc_send_complete(struct qib_qp *qp, struct qib_ib_header *hdr);
942f931551bSRalph Campbell 
943f931551bSRalph Campbell void qib_rc_error(struct qib_qp *qp, enum ib_wc_status err);
944f931551bSRalph Campbell 
945f931551bSRalph Campbell int qib_post_ud_send(struct qib_qp *qp, struct ib_send_wr *wr);
946f931551bSRalph Campbell 
947f931551bSRalph Campbell void qib_ud_rcv(struct qib_ibport *ibp, struct qib_ib_header *hdr,
948f931551bSRalph Campbell 		int has_grh, void *data, u32 tlen, struct qib_qp *qp);
949f931551bSRalph Campbell 
9506a82649fSMike Marciniszyn int qib_alloc_lkey(struct qib_mregion *mr, int dma_region);
951f931551bSRalph Campbell 
9526a82649fSMike Marciniszyn void qib_free_lkey(struct qib_mregion *mr);
953f931551bSRalph Campbell 
954f931551bSRalph Campbell int qib_lkey_ok(struct qib_lkey_table *rkt, struct qib_pd *pd,
955f931551bSRalph Campbell 		struct qib_sge *isge, struct ib_sge *sge, int acc);
956f931551bSRalph Campbell 
957f931551bSRalph Campbell int qib_rkey_ok(struct qib_qp *qp, struct qib_sge *sge,
958f931551bSRalph Campbell 		u32 len, u64 vaddr, u32 rkey, int acc);
959f931551bSRalph Campbell 
960f931551bSRalph Campbell int qib_post_srq_receive(struct ib_srq *ibsrq, struct ib_recv_wr *wr,
961f931551bSRalph Campbell 			 struct ib_recv_wr **bad_wr);
962f931551bSRalph Campbell 
963f931551bSRalph Campbell struct ib_srq *qib_create_srq(struct ib_pd *ibpd,
964f931551bSRalph Campbell 			      struct ib_srq_init_attr *srq_init_attr,
965f931551bSRalph Campbell 			      struct ib_udata *udata);
966f931551bSRalph Campbell 
967f931551bSRalph Campbell int qib_modify_srq(struct ib_srq *ibsrq, struct ib_srq_attr *attr,
968f931551bSRalph Campbell 		   enum ib_srq_attr_mask attr_mask,
969f931551bSRalph Campbell 		   struct ib_udata *udata);
970f931551bSRalph Campbell 
971f931551bSRalph Campbell int qib_query_srq(struct ib_srq *ibsrq, struct ib_srq_attr *attr);
972f931551bSRalph Campbell 
973f931551bSRalph Campbell int qib_destroy_srq(struct ib_srq *ibsrq);
974f931551bSRalph Campbell 
975f931551bSRalph Campbell void qib_cq_enter(struct qib_cq *cq, struct ib_wc *entry, int sig);
976f931551bSRalph Campbell 
977f931551bSRalph Campbell int qib_poll_cq(struct ib_cq *ibcq, int num_entries, struct ib_wc *entry);
978f931551bSRalph Campbell 
979f931551bSRalph Campbell struct ib_cq *qib_create_cq(struct ib_device *ibdev, int entries,
980f931551bSRalph Campbell 			    int comp_vector, struct ib_ucontext *context,
981f931551bSRalph Campbell 			    struct ib_udata *udata);
982f931551bSRalph Campbell 
983f931551bSRalph Campbell int qib_destroy_cq(struct ib_cq *ibcq);
984f931551bSRalph Campbell 
985f931551bSRalph Campbell int qib_req_notify_cq(struct ib_cq *ibcq, enum ib_cq_notify_flags notify_flags);
986f931551bSRalph Campbell 
987f931551bSRalph Campbell int qib_resize_cq(struct ib_cq *ibcq, int cqe, struct ib_udata *udata);
988f931551bSRalph Campbell 
989f931551bSRalph Campbell struct ib_mr *qib_get_dma_mr(struct ib_pd *pd, int acc);
990f931551bSRalph Campbell 
991f931551bSRalph Campbell struct ib_mr *qib_reg_phys_mr(struct ib_pd *pd,
992f931551bSRalph Campbell 			      struct ib_phys_buf *buffer_list,
993f931551bSRalph Campbell 			      int num_phys_buf, int acc, u64 *iova_start);
994f931551bSRalph Campbell 
995f931551bSRalph Campbell struct ib_mr *qib_reg_user_mr(struct ib_pd *pd, u64 start, u64 length,
996f931551bSRalph Campbell 			      u64 virt_addr, int mr_access_flags,
997f931551bSRalph Campbell 			      struct ib_udata *udata);
998f931551bSRalph Campbell 
999f931551bSRalph Campbell int qib_dereg_mr(struct ib_mr *ibmr);
1000f931551bSRalph Campbell 
1001f931551bSRalph Campbell struct ib_mr *qib_alloc_fast_reg_mr(struct ib_pd *pd, int max_page_list_len);
1002f931551bSRalph Campbell 
1003f931551bSRalph Campbell struct ib_fast_reg_page_list *qib_alloc_fast_reg_page_list(
1004f931551bSRalph Campbell 				struct ib_device *ibdev, int page_list_len);
1005f931551bSRalph Campbell 
1006f931551bSRalph Campbell void qib_free_fast_reg_page_list(struct ib_fast_reg_page_list *pl);
1007f931551bSRalph Campbell 
1008f931551bSRalph Campbell int qib_fast_reg_mr(struct qib_qp *qp, struct ib_send_wr *wr);
1009f931551bSRalph Campbell 
1010f931551bSRalph Campbell struct ib_fmr *qib_alloc_fmr(struct ib_pd *pd, int mr_access_flags,
1011f931551bSRalph Campbell 			     struct ib_fmr_attr *fmr_attr);
1012f931551bSRalph Campbell 
1013f931551bSRalph Campbell int qib_map_phys_fmr(struct ib_fmr *ibfmr, u64 *page_list,
1014f931551bSRalph Campbell 		     int list_len, u64 iova);
1015f931551bSRalph Campbell 
1016f931551bSRalph Campbell int qib_unmap_fmr(struct list_head *fmr_list);
1017f931551bSRalph Campbell 
1018f931551bSRalph Campbell int qib_dealloc_fmr(struct ib_fmr *ibfmr);
1019f931551bSRalph Campbell 
10206a82649fSMike Marciniszyn static inline void qib_get_mr(struct qib_mregion *mr)
10216a82649fSMike Marciniszyn {
10226a82649fSMike Marciniszyn 	atomic_inc(&mr->refcount);
10236a82649fSMike Marciniszyn }
10246a82649fSMike Marciniszyn 
10258aac4cc3SMike Marciniszyn void mr_rcu_callback(struct rcu_head *list);
10268aac4cc3SMike Marciniszyn 
10276a82649fSMike Marciniszyn static inline void qib_put_mr(struct qib_mregion *mr)
10286a82649fSMike Marciniszyn {
10296a82649fSMike Marciniszyn 	if (unlikely(atomic_dec_and_test(&mr->refcount)))
10308aac4cc3SMike Marciniszyn 		call_rcu(&mr->list, mr_rcu_callback);
10316a82649fSMike Marciniszyn }
10326a82649fSMike Marciniszyn 
10336a82649fSMike Marciniszyn static inline void qib_put_ss(struct qib_sge_state *ss)
10346a82649fSMike Marciniszyn {
10356a82649fSMike Marciniszyn 	while (ss->num_sge) {
10366a82649fSMike Marciniszyn 		qib_put_mr(ss->sge.mr);
10376a82649fSMike Marciniszyn 		if (--ss->num_sge)
10386a82649fSMike Marciniszyn 			ss->sge = *ss->sg_list++;
10396a82649fSMike Marciniszyn 	}
10406a82649fSMike Marciniszyn }
10416a82649fSMike Marciniszyn 
10426a82649fSMike Marciniszyn 
1043f931551bSRalph Campbell void qib_release_mmap_info(struct kref *ref);
1044f931551bSRalph Campbell 
1045f931551bSRalph Campbell struct qib_mmap_info *qib_create_mmap_info(struct qib_ibdev *dev, u32 size,
1046f931551bSRalph Campbell 					   struct ib_ucontext *context,
1047f931551bSRalph Campbell 					   void *obj);
1048f931551bSRalph Campbell 
1049f931551bSRalph Campbell void qib_update_mmap_info(struct qib_ibdev *dev, struct qib_mmap_info *ip,
1050f931551bSRalph Campbell 			  u32 size, void *obj);
1051f931551bSRalph Campbell 
1052f931551bSRalph Campbell int qib_mmap(struct ib_ucontext *context, struct vm_area_struct *vma);
1053f931551bSRalph Campbell 
1054f931551bSRalph Campbell int qib_get_rwqe(struct qib_qp *qp, int wr_id_only);
1055f931551bSRalph Campbell 
1056f931551bSRalph Campbell void qib_migrate_qp(struct qib_qp *qp);
1057f931551bSRalph Campbell 
1058f931551bSRalph Campbell int qib_ruc_check_hdr(struct qib_ibport *ibp, struct qib_ib_header *hdr,
1059f931551bSRalph Campbell 		      int has_grh, struct qib_qp *qp, u32 bth0);
1060f931551bSRalph Campbell 
1061f931551bSRalph Campbell u32 qib_make_grh(struct qib_ibport *ibp, struct ib_grh *hdr,
1062f931551bSRalph Campbell 		 struct ib_global_route *grh, u32 hwords, u32 nwords);
1063f931551bSRalph Campbell 
1064f931551bSRalph Campbell void qib_make_ruc_header(struct qib_qp *qp, struct qib_other_headers *ohdr,
1065f931551bSRalph Campbell 			 u32 bth0, u32 bth2);
1066f931551bSRalph Campbell 
1067f931551bSRalph Campbell void qib_do_send(struct work_struct *work);
1068f931551bSRalph Campbell 
1069f931551bSRalph Campbell void qib_send_complete(struct qib_qp *qp, struct qib_swqe *wqe,
1070f931551bSRalph Campbell 		       enum ib_wc_status status);
1071f931551bSRalph Campbell 
1072f931551bSRalph Campbell void qib_send_rc_ack(struct qib_qp *qp);
1073f931551bSRalph Campbell 
1074f931551bSRalph Campbell int qib_make_rc_req(struct qib_qp *qp);
1075f931551bSRalph Campbell 
1076f931551bSRalph Campbell int qib_make_uc_req(struct qib_qp *qp);
1077f931551bSRalph Campbell 
1078f931551bSRalph Campbell int qib_make_ud_req(struct qib_qp *qp);
1079f931551bSRalph Campbell 
1080f931551bSRalph Campbell int qib_register_ib_device(struct qib_devdata *);
1081f931551bSRalph Campbell 
1082f931551bSRalph Campbell void qib_unregister_ib_device(struct qib_devdata *);
1083f931551bSRalph Campbell 
1084f931551bSRalph Campbell void qib_ib_rcv(struct qib_ctxtdata *, void *, void *, u32);
1085f931551bSRalph Campbell 
1086f931551bSRalph Campbell void qib_ib_piobufavail(struct qib_devdata *);
1087f931551bSRalph Campbell 
1088f931551bSRalph Campbell unsigned qib_get_npkeys(struct qib_devdata *);
1089f931551bSRalph Campbell 
1090f931551bSRalph Campbell unsigned qib_get_pkey(struct qib_ibport *, unsigned);
1091f931551bSRalph Campbell 
1092f931551bSRalph Campbell extern const enum ib_wc_opcode ib_qib_wc_opcode[];
1093f931551bSRalph Campbell 
1094f931551bSRalph Campbell /*
1095f931551bSRalph Campbell  * Below  HCA-independent IB PhysPortState values, returned
1096f931551bSRalph Campbell  * by the f_ibphys_portstate() routine.
1097f931551bSRalph Campbell  */
1098f931551bSRalph Campbell #define IB_PHYSPORTSTATE_SLEEP 1
1099f931551bSRalph Campbell #define IB_PHYSPORTSTATE_POLL 2
1100f931551bSRalph Campbell #define IB_PHYSPORTSTATE_DISABLED 3
1101f931551bSRalph Campbell #define IB_PHYSPORTSTATE_CFG_TRAIN 4
1102f931551bSRalph Campbell #define IB_PHYSPORTSTATE_LINKUP 5
1103f931551bSRalph Campbell #define IB_PHYSPORTSTATE_LINK_ERR_RECOVER 6
1104f931551bSRalph Campbell #define IB_PHYSPORTSTATE_CFG_DEBOUNCE 8
1105f931551bSRalph Campbell #define IB_PHYSPORTSTATE_CFG_IDLE 0xB
1106f931551bSRalph Campbell #define IB_PHYSPORTSTATE_RECOVERY_RETRAIN 0xC
1107f931551bSRalph Campbell #define IB_PHYSPORTSTATE_RECOVERY_WAITRMT 0xE
1108f931551bSRalph Campbell #define IB_PHYSPORTSTATE_RECOVERY_IDLE 0xF
1109f931551bSRalph Campbell #define IB_PHYSPORTSTATE_CFG_ENH 0x10
1110f931551bSRalph Campbell #define IB_PHYSPORTSTATE_CFG_WAIT_ENH 0x13
1111f931551bSRalph Campbell 
1112f931551bSRalph Campbell extern const int ib_qib_state_ops[];
1113f931551bSRalph Campbell 
1114f931551bSRalph Campbell extern __be64 ib_qib_sys_image_guid;    /* in network order */
1115f931551bSRalph Campbell 
1116f931551bSRalph Campbell extern unsigned int ib_qib_lkey_table_size;
1117f931551bSRalph Campbell 
1118f931551bSRalph Campbell extern unsigned int ib_qib_max_cqes;
1119f931551bSRalph Campbell 
1120f931551bSRalph Campbell extern unsigned int ib_qib_max_cqs;
1121f931551bSRalph Campbell 
1122f931551bSRalph Campbell extern unsigned int ib_qib_max_qp_wrs;
1123f931551bSRalph Campbell 
1124f931551bSRalph Campbell extern unsigned int ib_qib_max_qps;
1125f931551bSRalph Campbell 
1126f931551bSRalph Campbell extern unsigned int ib_qib_max_sges;
1127f931551bSRalph Campbell 
1128f931551bSRalph Campbell extern unsigned int ib_qib_max_mcast_grps;
1129f931551bSRalph Campbell 
1130f931551bSRalph Campbell extern unsigned int ib_qib_max_mcast_qp_attached;
1131f931551bSRalph Campbell 
1132f931551bSRalph Campbell extern unsigned int ib_qib_max_srqs;
1133f931551bSRalph Campbell 
1134f931551bSRalph Campbell extern unsigned int ib_qib_max_srq_sges;
1135f931551bSRalph Campbell 
1136f931551bSRalph Campbell extern unsigned int ib_qib_max_srq_wrs;
1137f931551bSRalph Campbell 
1138f931551bSRalph Campbell extern const u32 ib_qib_rnr_table[];
1139f931551bSRalph Campbell 
1140f931551bSRalph Campbell extern struct ib_dma_mapping_ops qib_dma_mapping_ops;
1141f931551bSRalph Campbell 
1142f931551bSRalph Campbell #endif                          /* QIB_VERBS_H */
1143