1f931551bSRalph Campbell /*
21dd173b0SMike Marciniszyn  * Copyright (c) 2012, 2013 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>
4485caafe3SMike Marciniszyn #include <linux/kthread.h>
456a82649fSMike Marciniszyn #include <linux/completion.h>
46f931551bSRalph Campbell #include <rdma/ib_pack.h>
47f931551bSRalph Campbell #include <rdma/ib_user_verbs.h>
482dc05ab5SDennis Dalessandro #include <rdma/rdma_vt.h>
494bb88e5fSHarish Chegondi #include <rdma/rdmavt_cq.h>
50f931551bSRalph Campbell 
51f931551bSRalph Campbell struct qib_ctxtdata;
52f931551bSRalph Campbell struct qib_pportdata;
53f931551bSRalph Campbell struct qib_devdata;
54f931551bSRalph Campbell struct qib_verbs_txreq;
55f931551bSRalph Campbell 
56f931551bSRalph Campbell #define QIB_MAX_RDMA_ATOMIC     16
57f931551bSRalph Campbell #define QIB_GUIDS_PER_PORT	5
5870696ea7SHarish Chegondi #define QIB_PSN_SHIFT		8
59f931551bSRalph Campbell 
60f931551bSRalph Campbell /*
61f931551bSRalph Campbell  * Increment this value if any changes that break userspace ABI
62f931551bSRalph Campbell  * compatibility are made.
63f931551bSRalph Campbell  */
64f931551bSRalph Campbell #define QIB_UVERBS_ABI_VERSION       2
65f931551bSRalph Campbell 
66f931551bSRalph Campbell #define IB_SEQ_NAK	(3 << 29)
67f931551bSRalph Campbell 
68f931551bSRalph Campbell /* AETH NAK opcode values */
69f931551bSRalph Campbell #define IB_RNR_NAK                      0x20
70f931551bSRalph Campbell #define IB_NAK_PSN_ERROR                0x60
71f931551bSRalph Campbell #define IB_NAK_INVALID_REQUEST          0x61
72f931551bSRalph Campbell #define IB_NAK_REMOTE_ACCESS_ERROR      0x62
73f931551bSRalph Campbell #define IB_NAK_REMOTE_OPERATIONAL_ERROR 0x63
74f931551bSRalph Campbell #define IB_NAK_INVALID_RD_REQUEST       0x64
75f931551bSRalph Campbell 
76f931551bSRalph Campbell /* IB Performance Manager status values */
77f931551bSRalph Campbell #define IB_PMA_SAMPLE_STATUS_DONE       0x00
78f931551bSRalph Campbell #define IB_PMA_SAMPLE_STATUS_STARTED    0x01
79f931551bSRalph Campbell #define IB_PMA_SAMPLE_STATUS_RUNNING    0x02
80f931551bSRalph Campbell 
81f931551bSRalph Campbell /* Mandatory IB performance counter select values. */
82f931551bSRalph Campbell #define IB_PMA_PORT_XMIT_DATA   cpu_to_be16(0x0001)
83f931551bSRalph Campbell #define IB_PMA_PORT_RCV_DATA    cpu_to_be16(0x0002)
84f931551bSRalph Campbell #define IB_PMA_PORT_XMIT_PKTS   cpu_to_be16(0x0003)
85f931551bSRalph Campbell #define IB_PMA_PORT_RCV_PKTS    cpu_to_be16(0x0004)
86f931551bSRalph Campbell #define IB_PMA_PORT_XMIT_WAIT   cpu_to_be16(0x0005)
87f931551bSRalph Campbell 
88f931551bSRalph Campbell #define QIB_VENDOR_IPG		cpu_to_be16(0xFFA0)
89f931551bSRalph Campbell 
90f931551bSRalph Campbell #define IB_BTH_REQ_ACK		(1 << 31)
91f931551bSRalph Campbell #define IB_BTH_SOLICITED	(1 << 23)
92f931551bSRalph Campbell #define IB_BTH_MIG_REQ		(1 << 22)
93f931551bSRalph Campbell 
94f931551bSRalph Campbell /* XXX Should be defined in ib_verbs.h enum ib_port_cap_flags */
95f931551bSRalph Campbell #define IB_PORT_OTHER_LOCAL_CHANGES_SUP (1 << 26)
96f931551bSRalph Campbell 
97f931551bSRalph Campbell #define IB_GRH_VERSION		6
98f931551bSRalph Campbell #define IB_GRH_VERSION_MASK	0xF
99f931551bSRalph Campbell #define IB_GRH_VERSION_SHIFT	28
100f931551bSRalph Campbell #define IB_GRH_TCLASS_MASK	0xFF
101f931551bSRalph Campbell #define IB_GRH_TCLASS_SHIFT	20
102f931551bSRalph Campbell #define IB_GRH_FLOW_MASK	0xFFFFF
103f931551bSRalph Campbell #define IB_GRH_FLOW_SHIFT	0
104f931551bSRalph Campbell #define IB_GRH_NEXT_HDR		0x1B
105f931551bSRalph Campbell 
106f931551bSRalph Campbell #define IB_DEFAULT_GID_PREFIX	cpu_to_be64(0xfe80000000000000ULL)
107f931551bSRalph Campbell 
108f931551bSRalph Campbell /* Values for set/get portinfo VLCap OperationalVLs */
109f931551bSRalph Campbell #define IB_VL_VL0       1
110f931551bSRalph Campbell #define IB_VL_VL0_1     2
111f931551bSRalph Campbell #define IB_VL_VL0_3     3
112f931551bSRalph Campbell #define IB_VL_VL0_7     4
113f931551bSRalph Campbell #define IB_VL_VL0_14    5
114f931551bSRalph Campbell 
115f931551bSRalph Campbell static inline int qib_num_vls(int vls)
116f931551bSRalph Campbell {
117f931551bSRalph Campbell 	switch (vls) {
118f931551bSRalph Campbell 	default:
119f931551bSRalph Campbell 	case IB_VL_VL0:
120f931551bSRalph Campbell 		return 1;
121f931551bSRalph Campbell 	case IB_VL_VL0_1:
122f931551bSRalph Campbell 		return 2;
123f931551bSRalph Campbell 	case IB_VL_VL0_3:
124f931551bSRalph Campbell 		return 4;
125f931551bSRalph Campbell 	case IB_VL_VL0_7:
126f931551bSRalph Campbell 		return 8;
127f931551bSRalph Campbell 	case IB_VL_VL0_14:
128f931551bSRalph Campbell 		return 15;
129f931551bSRalph Campbell 	}
130f931551bSRalph Campbell }
131f931551bSRalph Campbell 
132f931551bSRalph Campbell struct ib_reth {
133f931551bSRalph Campbell 	__be64 vaddr;
134f931551bSRalph Campbell 	__be32 rkey;
135f931551bSRalph Campbell 	__be32 length;
13678a58864SMike Marciniszyn } __packed;
137f931551bSRalph Campbell 
138f931551bSRalph Campbell struct ib_atomic_eth {
139f931551bSRalph Campbell 	__be32 vaddr[2];        /* unaligned so access as 2 32-bit words */
140f931551bSRalph Campbell 	__be32 rkey;
141f931551bSRalph Campbell 	__be64 swap_data;
142f931551bSRalph Campbell 	__be64 compare_data;
14378a58864SMike Marciniszyn } __packed;
144f931551bSRalph Campbell 
145f931551bSRalph Campbell struct qib_other_headers {
146f931551bSRalph Campbell 	__be32 bth[3];
147f931551bSRalph Campbell 	union {
148f931551bSRalph Campbell 		struct {
149f931551bSRalph Campbell 			__be32 deth[2];
150f931551bSRalph Campbell 			__be32 imm_data;
151f931551bSRalph Campbell 		} ud;
152f931551bSRalph Campbell 		struct {
153f931551bSRalph Campbell 			struct ib_reth reth;
154f931551bSRalph Campbell 			__be32 imm_data;
155f931551bSRalph Campbell 		} rc;
156f931551bSRalph Campbell 		struct {
157f931551bSRalph Campbell 			__be32 aeth;
158f931551bSRalph Campbell 			__be32 atomic_ack_eth[2];
159f931551bSRalph Campbell 		} at;
160f931551bSRalph Campbell 		__be32 imm_data;
161f931551bSRalph Campbell 		__be32 aeth;
162f931551bSRalph Campbell 		struct ib_atomic_eth atomic_eth;
163f931551bSRalph Campbell 	} u;
16478a58864SMike Marciniszyn } __packed;
165f931551bSRalph Campbell 
166f931551bSRalph Campbell /*
167f931551bSRalph Campbell  * Note that UD packets with a GRH header are 8+40+12+8 = 68 bytes
168f931551bSRalph Campbell  * long (72 w/ imm_data).  Only the first 56 bytes of the IB header
169f931551bSRalph Campbell  * will be in the eager header buffer.  The remaining 12 or 16 bytes
170f931551bSRalph Campbell  * are in the data buffer.
171f931551bSRalph Campbell  */
172f931551bSRalph Campbell struct qib_ib_header {
173f931551bSRalph Campbell 	__be16 lrh[4];
174f931551bSRalph Campbell 	union {
175f931551bSRalph Campbell 		struct {
176f931551bSRalph Campbell 			struct ib_grh grh;
177f931551bSRalph Campbell 			struct qib_other_headers oth;
178f931551bSRalph Campbell 		} l;
179f931551bSRalph Campbell 		struct qib_other_headers oth;
180f931551bSRalph Campbell 	} u;
18178a58864SMike Marciniszyn } __packed;
182f931551bSRalph Campbell 
183f931551bSRalph Campbell struct qib_pio_header {
184f931551bSRalph Campbell 	__le32 pbc[2];
185f931551bSRalph Campbell 	struct qib_ib_header hdr;
18678a58864SMike Marciniszyn } __packed;
187f931551bSRalph Campbell 
188f931551bSRalph Campbell /*
189ffc26907SDennis Dalessandro  * qib specific data structure that will be hidden from rvt after the queue pair
190ffc26907SDennis Dalessandro  * is made common.
191ffc26907SDennis Dalessandro  */
192ffc26907SDennis Dalessandro struct qib_qp_priv {
193ffc26907SDennis Dalessandro 	struct qib_ib_header *s_hdr;    /* next packet header to send */
194ffc26907SDennis Dalessandro 	struct list_head iowait;        /* link for wait PIO buf */
195ffc26907SDennis Dalessandro 	atomic_t s_dma_busy;
196ffc26907SDennis Dalessandro 	struct qib_verbs_txreq *s_tx;
197ffc26907SDennis Dalessandro 	struct work_struct s_work;
198ffc26907SDennis Dalessandro 	wait_queue_head_t wait_dma;
1997c2e11feSDennis Dalessandro 	struct rvt_qp *owner;
200f931551bSRalph Campbell };
201f931551bSRalph Campbell 
202f931551bSRalph Campbell #define QIB_PSN_CREDIT  16
203f931551bSRalph Campbell 
204f931551bSRalph Campbell struct qib_opcode_stats {
205f931551bSRalph Campbell 	u64 n_packets;          /* number of packets */
206f931551bSRalph Campbell 	u64 n_bytes;            /* total number of bytes */
207f931551bSRalph Campbell };
208f931551bSRalph Campbell 
209ddb88765SMike Marciniszyn struct qib_opcode_stats_perctx {
210ddb88765SMike Marciniszyn 	struct qib_opcode_stats stats[128];
211ddb88765SMike Marciniszyn };
212ddb88765SMike Marciniszyn 
2137d7632adSMike Marciniszyn struct qib_pma_counters {
2147d7632adSMike Marciniszyn 	u64 n_unicast_xmit;     /* total unicast packets sent */
2157d7632adSMike Marciniszyn 	u64 n_unicast_rcv;      /* total unicast packets received */
2167d7632adSMike Marciniszyn 	u64 n_multicast_xmit;   /* total multicast packets sent */
2177d7632adSMike Marciniszyn 	u64 n_multicast_rcv;    /* total multicast packets received */
2187d7632adSMike Marciniszyn };
2197d7632adSMike Marciniszyn 
220f931551bSRalph Campbell struct qib_ibport {
221f24a6d48SHarish Chegondi 	struct rvt_ibport rvp;
222f931551bSRalph Campbell 	__be64 guids[QIB_GUIDS_PER_PORT	- 1];	/* writable GUIDs */
2237d7632adSMike Marciniszyn 	struct qib_pma_counters __percpu *pmastats;
2247d7632adSMike Marciniszyn 	u64 z_unicast_xmit;     /* starting count for PMA */
2257d7632adSMike Marciniszyn 	u64 z_unicast_rcv;      /* starting count for PMA */
2267d7632adSMike Marciniszyn 	u64 z_multicast_xmit;   /* starting count for PMA */
2277d7632adSMike Marciniszyn 	u64 z_multicast_rcv;    /* starting count for PMA */
228f931551bSRalph Campbell 	u64 z_symbol_error_counter;             /* starting count for PMA */
229f931551bSRalph Campbell 	u64 z_link_error_recovery_counter;      /* starting count for PMA */
230f931551bSRalph Campbell 	u64 z_link_downed_counter;              /* starting count for PMA */
231f931551bSRalph Campbell 	u64 z_port_rcv_errors;                  /* starting count for PMA */
232f931551bSRalph Campbell 	u64 z_port_rcv_remphys_errors;          /* starting count for PMA */
233f931551bSRalph Campbell 	u64 z_port_xmit_discards;               /* starting count for PMA */
234f931551bSRalph Campbell 	u64 z_port_xmit_data;                   /* starting count for PMA */
235f931551bSRalph Campbell 	u64 z_port_rcv_data;                    /* starting count for PMA */
236f931551bSRalph Campbell 	u64 z_port_xmit_packets;                /* starting count for PMA */
237f931551bSRalph Campbell 	u64 z_port_rcv_packets;                 /* starting count for PMA */
238f931551bSRalph Campbell 	u32 z_local_link_integrity_errors;      /* starting count for PMA */
239f931551bSRalph Campbell 	u32 z_excessive_buffer_overrun_errors;  /* starting count for PMA */
240f931551bSRalph Campbell 	u32 z_vl15_dropped;                     /* starting count for PMA */
241f931551bSRalph Campbell 	u8 sl_to_vl[16];
242f931551bSRalph Campbell };
243f931551bSRalph Campbell 
244f931551bSRalph Campbell struct qib_ibdev {
2452dc05ab5SDennis Dalessandro 	struct rvt_dev_info rdi;
246f931551bSRalph Campbell 
247f931551bSRalph Campbell 	struct list_head piowait;       /* list for wait PIO buf */
248f931551bSRalph Campbell 	struct list_head dmawait;	/* list for wait DMA */
249f931551bSRalph Campbell 	struct list_head txwait;        /* list for wait qib_verbs_txreq */
250f931551bSRalph Campbell 	struct list_head memwait;       /* list for wait kernel memory */
251f931551bSRalph Campbell 	struct list_head txreq_free;
252f931551bSRalph Campbell 	struct timer_list mem_timer;
253f931551bSRalph Campbell 	struct qib_pio_header *pio_hdrs;
254f931551bSRalph Campbell 	dma_addr_t pio_hdrs_phys;
255af061a64SMike Marciniszyn 	u32 qp_rnd; /* random bytes for hash */
256f931551bSRalph Campbell 
257f931551bSRalph Campbell 	u32 n_piowait;
258f931551bSRalph Campbell 	u32 n_txwait;
259f931551bSRalph Campbell 
260ddb88765SMike Marciniszyn #ifdef CONFIG_DEBUG_FS
261ddb88765SMike Marciniszyn 	/* per HCA debugfs */
262ddb88765SMike Marciniszyn 	struct dentry *qib_ibdev_dbg;
263ddb88765SMike Marciniszyn #endif
264f931551bSRalph Campbell };
265f931551bSRalph Campbell 
266f931551bSRalph Campbell struct qib_verbs_counters {
267f931551bSRalph Campbell 	u64 symbol_error_counter;
268f931551bSRalph Campbell 	u64 link_error_recovery_counter;
269f931551bSRalph Campbell 	u64 link_downed_counter;
270f931551bSRalph Campbell 	u64 port_rcv_errors;
271f931551bSRalph Campbell 	u64 port_rcv_remphys_errors;
272f931551bSRalph Campbell 	u64 port_xmit_discards;
273f931551bSRalph Campbell 	u64 port_xmit_data;
274f931551bSRalph Campbell 	u64 port_rcv_data;
275f931551bSRalph Campbell 	u64 port_xmit_packets;
276f931551bSRalph Campbell 	u64 port_rcv_packets;
277f931551bSRalph Campbell 	u32 local_link_integrity_errors;
278f931551bSRalph Campbell 	u32 excessive_buffer_overrun_errors;
279f931551bSRalph Campbell 	u32 vl15_dropped;
280f931551bSRalph Campbell };
281f931551bSRalph Campbell 
282f931551bSRalph Campbell static inline struct qib_ibdev *to_idev(struct ib_device *ibdev)
283f931551bSRalph Campbell {
2842dc05ab5SDennis Dalessandro 	struct rvt_dev_info *rdi;
2852dc05ab5SDennis Dalessandro 
2862dc05ab5SDennis Dalessandro 	rdi = container_of(ibdev, struct rvt_dev_info, ibdev);
2872dc05ab5SDennis Dalessandro 	return container_of(rdi, struct qib_ibdev, rdi);
288f931551bSRalph Campbell }
289f931551bSRalph Campbell 
290f931551bSRalph Campbell /*
291f931551bSRalph Campbell  * Send if not busy or waiting for I/O and either
292f931551bSRalph Campbell  * a RC response is pending or we can process send work requests.
293f931551bSRalph Campbell  */
2947c2e11feSDennis Dalessandro static inline int qib_send_ok(struct rvt_qp *qp)
295f931551bSRalph Campbell {
29601ba79d4SHarish Chegondi 	return !(qp->s_flags & (RVT_S_BUSY | RVT_S_ANY_WAIT_IO)) &&
29701ba79d4SHarish Chegondi 		(qp->s_hdrwords || (qp->s_flags & RVT_S_RESP_PENDING) ||
29801ba79d4SHarish Chegondi 		 !(qp->s_flags & RVT_S_ANY_WAIT_SEND));
299f931551bSRalph Campbell }
300f931551bSRalph Campbell 
301f931551bSRalph Campbell /*
302f931551bSRalph Campbell  * This must be called with s_lock held.
303f931551bSRalph Campbell  */
3047c2e11feSDennis Dalessandro void qib_schedule_send(struct rvt_qp *qp);
305f931551bSRalph Campbell 
306f931551bSRalph Campbell static inline int qib_pkey_ok(u16 pkey1, u16 pkey2)
307f931551bSRalph Campbell {
308f931551bSRalph Campbell 	u16 p1 = pkey1 & 0x7FFF;
309f931551bSRalph Campbell 	u16 p2 = pkey2 & 0x7FFF;
310f931551bSRalph Campbell 
311f931551bSRalph Campbell 	/*
312f931551bSRalph Campbell 	 * Low 15 bits must be non-zero and match, and
313f931551bSRalph Campbell 	 * one of the two must be a full member.
314f931551bSRalph Campbell 	 */
315f931551bSRalph Campbell 	return p1 && p1 == p2 && ((__s16)pkey1 < 0 || (__s16)pkey2 < 0);
316f931551bSRalph Campbell }
317f931551bSRalph Campbell 
318f931551bSRalph Campbell void qib_bad_pqkey(struct qib_ibport *ibp, __be16 trap_num, u32 key, u32 sl,
319f931551bSRalph Campbell 		   u32 qp1, u32 qp2, __be16 lid1, __be16 lid2);
320f931551bSRalph Campbell void qib_cap_mask_chg(struct qib_ibport *ibp);
321f931551bSRalph Campbell void qib_sys_guid_chg(struct qib_ibport *ibp);
322f931551bSRalph Campbell void qib_node_desc_chg(struct qib_ibport *ibp);
323f931551bSRalph Campbell int qib_process_mad(struct ib_device *ibdev, int mad_flags, u8 port_num,
324a97e2d86SIra Weiny 		    const struct ib_wc *in_wc, const struct ib_grh *in_grh,
3254cd7c947SIra Weiny 		    const struct ib_mad_hdr *in, size_t in_mad_size,
3264cd7c947SIra Weiny 		    struct ib_mad_hdr *out, size_t *out_mad_size,
3274cd7c947SIra Weiny 		    u16 *out_mad_pkey_index);
3285196aa96SDennis Dalessandro void qib_notify_create_mad_agent(struct rvt_dev_info *rdi, int port_idx);
3295196aa96SDennis Dalessandro void qib_notify_free_mad_agent(struct rvt_dev_info *rdi, int port_idx);
330f931551bSRalph Campbell 
331f931551bSRalph Campbell /*
332f931551bSRalph Campbell  * Compare the lower 24 bits of the two values.
333f931551bSRalph Campbell  * Returns an integer <, ==, or > than zero.
334f931551bSRalph Campbell  */
335f931551bSRalph Campbell static inline int qib_cmp24(u32 a, u32 b)
336f931551bSRalph Campbell {
337f931551bSRalph Campbell 	return (((int) a) - ((int) b)) << 8;
338f931551bSRalph Campbell }
339f931551bSRalph Campbell 
340f931551bSRalph Campbell int qib_snapshot_counters(struct qib_pportdata *ppd, u64 *swords,
341f931551bSRalph Campbell 			  u64 *rwords, u64 *spkts, u64 *rpkts,
342f931551bSRalph Campbell 			  u64 *xmit_wait);
343f931551bSRalph Campbell 
344f931551bSRalph Campbell int qib_get_counters(struct qib_pportdata *ppd,
345f931551bSRalph Campbell 		     struct qib_verbs_counters *cntrs);
346f931551bSRalph Campbell 
3477c2e11feSDennis Dalessandro __be32 qib_compute_aeth(struct rvt_qp *qp);
348f931551bSRalph Campbell 
349f931551bSRalph Campbell int qib_destroy_qp(struct ib_qp *ibqp);
350f931551bSRalph Campbell 
35147c7ea6dSHarish Chegondi /*
35247c7ea6dSHarish Chegondi  * Functions provided by qib driver for rdmavt to use
35347c7ea6dSHarish Chegondi  */
35447c7ea6dSHarish Chegondi unsigned qib_free_all_qps(struct rvt_dev_info *rdi);
35547c7ea6dSHarish Chegondi void *qp_priv_alloc(struct rvt_dev_info *rdi, struct rvt_qp *qp, gfp_t gfp);
35647c7ea6dSHarish Chegondi void qp_priv_free(struct rvt_dev_info *rdi, struct rvt_qp *qp);
35747c7ea6dSHarish Chegondi void notify_qp_reset(struct rvt_qp *qp);
35847c7ea6dSHarish Chegondi int alloc_qpn(struct rvt_dev_info *rdi, struct rvt_qpn_table *qpt,
35947c7ea6dSHarish Chegondi 	      enum ib_qp_type type, u8 port, gfp_t gfp);
360f931551bSRalph Campbell 
3611dd173b0SMike Marciniszyn #ifdef CONFIG_DEBUG_FS
3621dd173b0SMike Marciniszyn 
3631dd173b0SMike Marciniszyn struct qib_qp_iter;
3641dd173b0SMike Marciniszyn 
3651dd173b0SMike Marciniszyn struct qib_qp_iter *qib_qp_iter_init(struct qib_ibdev *dev);
3661dd173b0SMike Marciniszyn 
3671dd173b0SMike Marciniszyn int qib_qp_iter_next(struct qib_qp_iter *iter);
3681dd173b0SMike Marciniszyn 
3691dd173b0SMike Marciniszyn void qib_qp_iter_print(struct seq_file *s, struct qib_qp_iter *iter);
3701dd173b0SMike Marciniszyn 
3711dd173b0SMike Marciniszyn #endif
3721dd173b0SMike Marciniszyn 
3737c2e11feSDennis Dalessandro void qib_get_credit(struct rvt_qp *qp, u32 aeth);
374f931551bSRalph Campbell 
375f931551bSRalph Campbell unsigned qib_pkt_delay(u32 plen, u8 snd_mult, u8 rcv_mult);
376f931551bSRalph Campbell 
377f931551bSRalph Campbell void qib_verbs_sdma_desc_avail(struct qib_pportdata *ppd, unsigned avail);
378f931551bSRalph Campbell 
379f931551bSRalph Campbell void qib_put_txreq(struct qib_verbs_txreq *tx);
380f931551bSRalph Campbell 
3817c2e11feSDennis Dalessandro int qib_verbs_send(struct rvt_qp *qp, struct qib_ib_header *hdr,
3827c2e11feSDennis Dalessandro 		   u32 hdrwords, struct rvt_sge_state *ss, u32 len);
383f931551bSRalph Campbell 
3847c2e11feSDennis Dalessandro void qib_copy_sge(struct rvt_sge_state *ss, void *data, u32 length,
385f931551bSRalph Campbell 		  int release);
386f931551bSRalph Campbell 
3877c2e11feSDennis Dalessandro void qib_skip_sge(struct rvt_sge_state *ss, u32 length, int release);
388f931551bSRalph Campbell 
389f931551bSRalph Campbell void qib_uc_rcv(struct qib_ibport *ibp, struct qib_ib_header *hdr,
3907c2e11feSDennis Dalessandro 		int has_grh, void *data, u32 tlen, struct rvt_qp *qp);
391f931551bSRalph Campbell 
392f931551bSRalph Campbell void qib_rc_rcv(struct qib_ctxtdata *rcd, struct qib_ib_header *hdr,
3937c2e11feSDennis Dalessandro 		int has_grh, void *data, u32 tlen, struct rvt_qp *qp);
394f931551bSRalph Campbell 
395f931551bSRalph Campbell int qib_check_ah(struct ib_device *ibdev, struct ib_ah_attr *ah_attr);
396f931551bSRalph Campbell 
3971fb9fed6SMike Marciniszyn struct ib_ah *qib_create_qp0_ah(struct qib_ibport *ibp, u16 dlid);
3981fb9fed6SMike Marciniszyn 
399f931551bSRalph Campbell void qib_rc_rnr_retry(unsigned long arg);
400f931551bSRalph Campbell 
4017c2e11feSDennis Dalessandro void qib_rc_send_complete(struct rvt_qp *qp, struct qib_ib_header *hdr);
402f931551bSRalph Campbell 
4037c2e11feSDennis Dalessandro void qib_rc_error(struct rvt_qp *qp, enum ib_wc_status err);
404f931551bSRalph Campbell 
4057c2e11feSDennis Dalessandro int qib_post_ud_send(struct rvt_qp *qp, struct ib_send_wr *wr);
406f931551bSRalph Campbell 
407f931551bSRalph Campbell void qib_ud_rcv(struct qib_ibport *ibp, struct qib_ib_header *hdr,
4087c2e11feSDennis Dalessandro 		int has_grh, void *data, u32 tlen, struct rvt_qp *qp);
409f931551bSRalph Campbell 
4108aac4cc3SMike Marciniszyn void mr_rcu_callback(struct rcu_head *list);
4118aac4cc3SMike Marciniszyn 
4127c2e11feSDennis Dalessandro int qib_get_rwqe(struct rvt_qp *qp, int wr_id_only);
413f931551bSRalph Campbell 
4147c2e11feSDennis Dalessandro void qib_migrate_qp(struct rvt_qp *qp);
415f931551bSRalph Campbell 
416f931551bSRalph Campbell int qib_ruc_check_hdr(struct qib_ibport *ibp, struct qib_ib_header *hdr,
4177c2e11feSDennis Dalessandro 		      int has_grh, struct rvt_qp *qp, u32 bth0);
418f931551bSRalph Campbell 
419f931551bSRalph Campbell u32 qib_make_grh(struct qib_ibport *ibp, struct ib_grh *hdr,
420f931551bSRalph Campbell 		 struct ib_global_route *grh, u32 hwords, u32 nwords);
421f931551bSRalph Campbell 
4227c2e11feSDennis Dalessandro void qib_make_ruc_header(struct rvt_qp *qp, struct qib_other_headers *ohdr,
423f931551bSRalph Campbell 			 u32 bth0, u32 bth2);
424f931551bSRalph Campbell 
425db3ef0ebSHarish Chegondi void _qib_do_send(struct work_struct *work);
426db3ef0ebSHarish Chegondi 
427db3ef0ebSHarish Chegondi void qib_do_send(struct rvt_qp *qp);
428f931551bSRalph Campbell 
4297c2e11feSDennis Dalessandro void qib_send_complete(struct rvt_qp *qp, struct rvt_swqe *wqe,
430f931551bSRalph Campbell 		       enum ib_wc_status status);
431f931551bSRalph Campbell 
4327c2e11feSDennis Dalessandro void qib_send_rc_ack(struct rvt_qp *qp);
433f931551bSRalph Campbell 
4347c2e11feSDennis Dalessandro int qib_make_rc_req(struct rvt_qp *qp);
435f931551bSRalph Campbell 
4367c2e11feSDennis Dalessandro int qib_make_uc_req(struct rvt_qp *qp);
437f931551bSRalph Campbell 
4387c2e11feSDennis Dalessandro int qib_make_ud_req(struct rvt_qp *qp);
439f931551bSRalph Campbell 
440f931551bSRalph Campbell int qib_register_ib_device(struct qib_devdata *);
441f931551bSRalph Campbell 
442f931551bSRalph Campbell void qib_unregister_ib_device(struct qib_devdata *);
443f931551bSRalph Campbell 
444f931551bSRalph Campbell void qib_ib_rcv(struct qib_ctxtdata *, void *, void *, u32);
445f931551bSRalph Campbell 
446f931551bSRalph Campbell void qib_ib_piobufavail(struct qib_devdata *);
447f931551bSRalph Campbell 
448f931551bSRalph Campbell unsigned qib_get_npkeys(struct qib_devdata *);
449f931551bSRalph Campbell 
450f931551bSRalph Campbell unsigned qib_get_pkey(struct qib_ibport *, unsigned);
451f931551bSRalph Campbell 
452f931551bSRalph Campbell extern const enum ib_wc_opcode ib_qib_wc_opcode[];
453f931551bSRalph Campbell 
454f931551bSRalph Campbell /*
455f931551bSRalph Campbell  * Below  HCA-independent IB PhysPortState values, returned
456f931551bSRalph Campbell  * by the f_ibphys_portstate() routine.
457f931551bSRalph Campbell  */
458f931551bSRalph Campbell #define IB_PHYSPORTSTATE_SLEEP 1
459f931551bSRalph Campbell #define IB_PHYSPORTSTATE_POLL 2
460f931551bSRalph Campbell #define IB_PHYSPORTSTATE_DISABLED 3
461f931551bSRalph Campbell #define IB_PHYSPORTSTATE_CFG_TRAIN 4
462f931551bSRalph Campbell #define IB_PHYSPORTSTATE_LINKUP 5
463f931551bSRalph Campbell #define IB_PHYSPORTSTATE_LINK_ERR_RECOVER 6
464f931551bSRalph Campbell #define IB_PHYSPORTSTATE_CFG_DEBOUNCE 8
465f931551bSRalph Campbell #define IB_PHYSPORTSTATE_CFG_IDLE 0xB
466f931551bSRalph Campbell #define IB_PHYSPORTSTATE_RECOVERY_RETRAIN 0xC
467f931551bSRalph Campbell #define IB_PHYSPORTSTATE_RECOVERY_WAITRMT 0xE
468f931551bSRalph Campbell #define IB_PHYSPORTSTATE_RECOVERY_IDLE 0xF
469f931551bSRalph Campbell #define IB_PHYSPORTSTATE_CFG_ENH 0x10
470f931551bSRalph Campbell #define IB_PHYSPORTSTATE_CFG_WAIT_ENH 0x13
471f931551bSRalph Campbell 
472db3ef0ebSHarish Chegondi extern const int ib_rvt_state_ops[];
473f931551bSRalph Campbell 
474f931551bSRalph Campbell extern __be64 ib_qib_sys_image_guid;    /* in network order */
475f931551bSRalph Campbell 
4767c2e11feSDennis Dalessandro extern unsigned int ib_rvt_lkey_table_size;
477f931551bSRalph Campbell 
478f931551bSRalph Campbell extern unsigned int ib_qib_max_cqes;
479f931551bSRalph Campbell 
480f931551bSRalph Campbell extern unsigned int ib_qib_max_cqs;
481f931551bSRalph Campbell 
482f931551bSRalph Campbell extern unsigned int ib_qib_max_qp_wrs;
483f931551bSRalph Campbell 
484f931551bSRalph Campbell extern unsigned int ib_qib_max_qps;
485f931551bSRalph Campbell 
486f931551bSRalph Campbell extern unsigned int ib_qib_max_sges;
487f931551bSRalph Campbell 
488f931551bSRalph Campbell extern unsigned int ib_qib_max_mcast_grps;
489f931551bSRalph Campbell 
490f931551bSRalph Campbell extern unsigned int ib_qib_max_mcast_qp_attached;
491f931551bSRalph Campbell 
492f931551bSRalph Campbell extern unsigned int ib_qib_max_srqs;
493f931551bSRalph Campbell 
494f931551bSRalph Campbell extern unsigned int ib_qib_max_srq_sges;
495f931551bSRalph Campbell 
496f931551bSRalph Campbell extern unsigned int ib_qib_max_srq_wrs;
497f931551bSRalph Campbell 
498f931551bSRalph Campbell extern const u32 ib_qib_rnr_table[];
499f931551bSRalph Campbell 
500f931551bSRalph Campbell #endif                          /* QIB_VERBS_H */
501