blob: e10ab80db3b17958acedba42e54e50320cfbe9ce [file] [log] [blame]
Ralph Campbellf9315512010-05-23 21:44:54 -07001/*
Mike Marciniszyn1dd173b2013-06-15 17:07:14 -04002 * Copyright (c) 2012, 2013 Intel Corporation. All rights reserved.
Mike Marciniszyn1fb9fed2012-07-16 17:11:06 +00003 * Copyright (c) 2006 - 2012 QLogic Corporation. All rights reserved.
Ralph Campbellf9315512010-05-23 21:44:54 -07004 * Copyright (c) 2005, 2006 PathScale, Inc. All rights reserved.
5 *
6 * This software is available to you under a choice of one of two
7 * licenses. You may choose to be licensed under the terms of the GNU
8 * General Public License (GPL) Version 2, available from the file
9 * COPYING in the main directory of this source tree, or the
10 * OpenIB.org BSD license below:
11 *
12 * Redistribution and use in source and binary forms, with or
13 * without modification, are permitted provided that the following
14 * conditions are met:
15 *
16 * - Redistributions of source code must retain the above
17 * copyright notice, this list of conditions and the following
18 * disclaimer.
19 *
20 * - Redistributions in binary form must reproduce the above
21 * copyright notice, this list of conditions and the following
22 * disclaimer in the documentation and/or other materials
23 * provided with the distribution.
24 *
25 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
29 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
30 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
31 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32 * SOFTWARE.
33 */
34
35#ifndef QIB_VERBS_H
36#define QIB_VERBS_H
37
38#include <linux/types.h>
39#include <linux/spinlock.h>
40#include <linux/kernel.h>
41#include <linux/interrupt.h>
42#include <linux/kref.h>
43#include <linux/workqueue.h>
Mike Marciniszyn85caafe2013-06-04 15:05:37 -040044#include <linux/kthread.h>
Mike Marciniszyn6a826492012-06-27 18:33:12 -040045#include <linux/completion.h>
Ralph Campbellf9315512010-05-23 21:44:54 -070046#include <rdma/ib_pack.h>
47#include <rdma/ib_user_verbs.h>
Dennis Dalessandro2dc05ab2016-01-22 12:44:29 -080048#include <rdma/rdma_vt.h>
Ralph Campbellf9315512010-05-23 21:44:54 -070049
50struct qib_ctxtdata;
51struct qib_pportdata;
52struct qib_devdata;
53struct qib_verbs_txreq;
54
55#define QIB_MAX_RDMA_ATOMIC 16
56#define QIB_GUIDS_PER_PORT 5
57
Ralph Campbellf9315512010-05-23 21:44:54 -070058/*
59 * Increment this value if any changes that break userspace ABI
60 * compatibility are made.
61 */
62#define QIB_UVERBS_ABI_VERSION 2
63
64/*
65 * Define an ib_cq_notify value that is not valid so we know when CQ
66 * notifications are armed.
67 */
68#define IB_CQ_NONE (IB_CQ_NEXT_COMP + 1)
69
70#define IB_SEQ_NAK (3 << 29)
71
72/* AETH NAK opcode values */
73#define IB_RNR_NAK 0x20
74#define IB_NAK_PSN_ERROR 0x60
75#define IB_NAK_INVALID_REQUEST 0x61
76#define IB_NAK_REMOTE_ACCESS_ERROR 0x62
77#define IB_NAK_REMOTE_OPERATIONAL_ERROR 0x63
78#define IB_NAK_INVALID_RD_REQUEST 0x64
79
80/* Flags for checking QP state (see ib_qib_state_ops[]) */
81#define QIB_POST_SEND_OK 0x01
82#define QIB_POST_RECV_OK 0x02
83#define QIB_PROCESS_RECV_OK 0x04
84#define QIB_PROCESS_SEND_OK 0x08
85#define QIB_PROCESS_NEXT_SEND_OK 0x10
86#define QIB_FLUSH_SEND 0x20
87#define QIB_FLUSH_RECV 0x40
88#define QIB_PROCESS_OR_FLUSH_SEND \
89 (QIB_PROCESS_SEND_OK | QIB_FLUSH_SEND)
90
91/* IB Performance Manager status values */
92#define IB_PMA_SAMPLE_STATUS_DONE 0x00
93#define IB_PMA_SAMPLE_STATUS_STARTED 0x01
94#define IB_PMA_SAMPLE_STATUS_RUNNING 0x02
95
96/* Mandatory IB performance counter select values. */
97#define IB_PMA_PORT_XMIT_DATA cpu_to_be16(0x0001)
98#define IB_PMA_PORT_RCV_DATA cpu_to_be16(0x0002)
99#define IB_PMA_PORT_XMIT_PKTS cpu_to_be16(0x0003)
100#define IB_PMA_PORT_RCV_PKTS cpu_to_be16(0x0004)
101#define IB_PMA_PORT_XMIT_WAIT cpu_to_be16(0x0005)
102
103#define QIB_VENDOR_IPG cpu_to_be16(0xFFA0)
104
105#define IB_BTH_REQ_ACK (1 << 31)
106#define IB_BTH_SOLICITED (1 << 23)
107#define IB_BTH_MIG_REQ (1 << 22)
108
109/* XXX Should be defined in ib_verbs.h enum ib_port_cap_flags */
110#define IB_PORT_OTHER_LOCAL_CHANGES_SUP (1 << 26)
111
112#define IB_GRH_VERSION 6
113#define IB_GRH_VERSION_MASK 0xF
114#define IB_GRH_VERSION_SHIFT 28
115#define IB_GRH_TCLASS_MASK 0xFF
116#define IB_GRH_TCLASS_SHIFT 20
117#define IB_GRH_FLOW_MASK 0xFFFFF
118#define IB_GRH_FLOW_SHIFT 0
119#define IB_GRH_NEXT_HDR 0x1B
120
121#define IB_DEFAULT_GID_PREFIX cpu_to_be64(0xfe80000000000000ULL)
122
123/* Values for set/get portinfo VLCap OperationalVLs */
124#define IB_VL_VL0 1
125#define IB_VL_VL0_1 2
126#define IB_VL_VL0_3 3
127#define IB_VL_VL0_7 4
128#define IB_VL_VL0_14 5
129
130static inline int qib_num_vls(int vls)
131{
132 switch (vls) {
133 default:
134 case IB_VL_VL0:
135 return 1;
136 case IB_VL_VL0_1:
137 return 2;
138 case IB_VL_VL0_3:
139 return 4;
140 case IB_VL_VL0_7:
141 return 8;
142 case IB_VL_VL0_14:
143 return 15;
144 }
145}
146
147struct ib_reth {
148 __be64 vaddr;
149 __be32 rkey;
150 __be32 length;
Mike Marciniszyn78a58862013-10-24 11:40:37 -0400151} __packed;
Ralph Campbellf9315512010-05-23 21:44:54 -0700152
153struct ib_atomic_eth {
154 __be32 vaddr[2]; /* unaligned so access as 2 32-bit words */
155 __be32 rkey;
156 __be64 swap_data;
157 __be64 compare_data;
Mike Marciniszyn78a58862013-10-24 11:40:37 -0400158} __packed;
Ralph Campbellf9315512010-05-23 21:44:54 -0700159
160struct qib_other_headers {
161 __be32 bth[3];
162 union {
163 struct {
164 __be32 deth[2];
165 __be32 imm_data;
166 } ud;
167 struct {
168 struct ib_reth reth;
169 __be32 imm_data;
170 } rc;
171 struct {
172 __be32 aeth;
173 __be32 atomic_ack_eth[2];
174 } at;
175 __be32 imm_data;
176 __be32 aeth;
177 struct ib_atomic_eth atomic_eth;
178 } u;
Mike Marciniszyn78a58862013-10-24 11:40:37 -0400179} __packed;
Ralph Campbellf9315512010-05-23 21:44:54 -0700180
181/*
182 * Note that UD packets with a GRH header are 8+40+12+8 = 68 bytes
183 * long (72 w/ imm_data). Only the first 56 bytes of the IB header
184 * will be in the eager header buffer. The remaining 12 or 16 bytes
185 * are in the data buffer.
186 */
187struct qib_ib_header {
188 __be16 lrh[4];
189 union {
190 struct {
191 struct ib_grh grh;
192 struct qib_other_headers oth;
193 } l;
194 struct qib_other_headers oth;
195 } u;
Mike Marciniszyn78a58862013-10-24 11:40:37 -0400196} __packed;
Ralph Campbellf9315512010-05-23 21:44:54 -0700197
198struct qib_pio_header {
199 __le32 pbc[2];
200 struct qib_ib_header hdr;
Mike Marciniszyn78a58862013-10-24 11:40:37 -0400201} __packed;
Ralph Campbellf9315512010-05-23 21:44:54 -0700202
203/*
204 * There is one struct qib_mcast for each multicast GID.
205 * All attached QPs are then stored as a list of
206 * struct qib_mcast_qp.
207 */
208struct qib_mcast_qp {
209 struct list_head list;
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800210 struct rvt_qp *qp;
Ralph Campbellf9315512010-05-23 21:44:54 -0700211};
212
213struct qib_mcast {
214 struct rb_node rb_node;
215 union ib_gid mgid;
216 struct list_head qp_list;
217 wait_queue_head_t wait;
218 atomic_t refcount;
219 int n_attached;
220};
221
Ralph Campbellf9315512010-05-23 21:44:54 -0700222/*
Ralph Campbellf9315512010-05-23 21:44:54 -0700223 * This structure is used to contain the head pointer, tail pointer,
224 * and completion queue entries as a single memory allocation so
225 * it can be mmap'ed into user space.
226 */
227struct qib_cq_wc {
228 u32 head; /* index of next entry to fill */
229 u32 tail; /* index of next ib_poll_cq() entry */
230 union {
231 /* these are actually size ibcq.cqe + 1 */
232 struct ib_uverbs_wc uqueue[0];
233 struct ib_wc kqueue[0];
234 };
235};
236
237/*
238 * The completion queue structure.
239 */
240struct qib_cq {
241 struct ib_cq ibcq;
Mike Marciniszyn85caafe2013-06-04 15:05:37 -0400242 struct kthread_work comptask;
243 struct qib_devdata *dd;
Ralph Campbellf9315512010-05-23 21:44:54 -0700244 spinlock_t lock; /* protect changes in this struct */
245 u8 notify;
246 u8 triggered;
247 struct qib_cq_wc *queue;
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800248 struct rvt_mmap_info *ip;
Ralph Campbellf9315512010-05-23 21:44:54 -0700249};
250
Ralph Campbellf9315512010-05-23 21:44:54 -0700251/*
Dennis Dalessandroffc26902016-01-22 12:45:11 -0800252 * qib specific data structure that will be hidden from rvt after the queue pair
253 * is made common.
254 */
Dennis Dalessandroffc26902016-01-22 12:45:11 -0800255struct qib_qp_priv {
256 struct qib_ib_header *s_hdr; /* next packet header to send */
257 struct list_head iowait; /* link for wait PIO buf */
258 atomic_t s_dma_busy;
259 struct qib_verbs_txreq *s_tx;
260 struct work_struct s_work;
261 wait_queue_head_t wait_dma;
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800262 struct rvt_qp *owner;
Ralph Campbellf9315512010-05-23 21:44:54 -0700263};
264
265/*
266 * Atomic bit definitions for r_aflags.
267 */
268#define QIB_R_WRID_VALID 0
269#define QIB_R_REWIND_SGE 1
270
271/*
272 * Bit definitions for r_flags.
273 */
274#define QIB_R_REUSE_SGE 0x01
275#define QIB_R_RDMAR_SEQ 0x02
276#define QIB_R_RSP_NAK 0x04
277#define QIB_R_RSP_SEND 0x08
278#define QIB_R_COMM_EST 0x10
279
280/*
281 * Bit definitions for s_flags.
282 *
283 * QIB_S_SIGNAL_REQ_WR - set if QP send WRs contain completion signaled
284 * QIB_S_BUSY - send tasklet is processing the QP
285 * QIB_S_TIMER - the RC retry timer is active
286 * QIB_S_ACK_PENDING - an ACK is waiting to be sent after RDMA read/atomics
287 * QIB_S_WAIT_FENCE - waiting for all prior RDMA read or atomic SWQEs
288 * before processing the next SWQE
289 * QIB_S_WAIT_RDMAR - waiting for a RDMA read or atomic SWQE to complete
290 * before processing the next SWQE
291 * QIB_S_WAIT_RNR - waiting for RNR timeout
292 * QIB_S_WAIT_SSN_CREDIT - waiting for RC credits to process next SWQE
293 * QIB_S_WAIT_DMA - waiting for send DMA queue to drain before generating
294 * next send completion entry not via send DMA
295 * QIB_S_WAIT_PIO - waiting for a send buffer to be available
296 * QIB_S_WAIT_TX - waiting for a struct qib_verbs_txreq to be available
297 * QIB_S_WAIT_DMA_DESC - waiting for DMA descriptors to be available
298 * QIB_S_WAIT_KMEM - waiting for kernel memory to be available
299 * QIB_S_WAIT_PSN - waiting for a packet to exit the send DMA queue
300 * QIB_S_WAIT_ACK - waiting for an ACK packet before sending more requests
301 * QIB_S_SEND_ONE - send one packet, request ACK, then wait for ACK
302 */
303#define QIB_S_SIGNAL_REQ_WR 0x0001
304#define QIB_S_BUSY 0x0002
305#define QIB_S_TIMER 0x0004
306#define QIB_S_RESP_PENDING 0x0008
307#define QIB_S_ACK_PENDING 0x0010
308#define QIB_S_WAIT_FENCE 0x0020
309#define QIB_S_WAIT_RDMAR 0x0040
310#define QIB_S_WAIT_RNR 0x0080
311#define QIB_S_WAIT_SSN_CREDIT 0x0100
312#define QIB_S_WAIT_DMA 0x0200
313#define QIB_S_WAIT_PIO 0x0400
314#define QIB_S_WAIT_TX 0x0800
315#define QIB_S_WAIT_DMA_DESC 0x1000
316#define QIB_S_WAIT_KMEM 0x2000
317#define QIB_S_WAIT_PSN 0x4000
318#define QIB_S_WAIT_ACK 0x8000
319#define QIB_S_SEND_ONE 0x10000
320#define QIB_S_UNLIMITED_CREDIT 0x20000
321
322/*
323 * Wait flags that would prevent any packet type from being sent.
324 */
325#define QIB_S_ANY_WAIT_IO (QIB_S_WAIT_PIO | QIB_S_WAIT_TX | \
326 QIB_S_WAIT_DMA_DESC | QIB_S_WAIT_KMEM)
327
328/*
329 * Wait flags that would prevent send work requests from making progress.
330 */
331#define QIB_S_ANY_WAIT_SEND (QIB_S_WAIT_FENCE | QIB_S_WAIT_RDMAR | \
332 QIB_S_WAIT_RNR | QIB_S_WAIT_SSN_CREDIT | QIB_S_WAIT_DMA | \
333 QIB_S_WAIT_PSN | QIB_S_WAIT_ACK)
334
335#define QIB_S_ANY_WAIT (QIB_S_ANY_WAIT_IO | QIB_S_ANY_WAIT_SEND)
336
337#define QIB_PSN_CREDIT 16
338
339/*
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800340 * Since struct rvt_swqe is not a fixed size, we can't simply index into
341 * struct rvt_qp.s_wq. This function does the array index computation.
Ralph Campbellf9315512010-05-23 21:44:54 -0700342 */
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800343static inline struct rvt_swqe *get_swqe_ptr(struct rvt_qp *qp,
344 unsigned n)
Ralph Campbellf9315512010-05-23 21:44:54 -0700345{
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800346 return (struct rvt_swqe *)((char *)qp->s_wq +
347 (sizeof(struct rvt_swqe) +
Ralph Campbellf9315512010-05-23 21:44:54 -0700348 qp->s_max_sge *
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800349 sizeof(struct rvt_sge)) * n);
Ralph Campbellf9315512010-05-23 21:44:54 -0700350}
351
352/*
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800353 * Since struct rvt_rwqe is not a fixed size, we can't simply index into
354 * struct rvt_rwq.wq. This function does the array index computation.
Ralph Campbellf9315512010-05-23 21:44:54 -0700355 */
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800356static inline struct rvt_rwqe *get_rwqe_ptr(struct rvt_rq *rq, unsigned n)
Ralph Campbellf9315512010-05-23 21:44:54 -0700357{
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800358 return (struct rvt_rwqe *)
Ralph Campbellf9315512010-05-23 21:44:54 -0700359 ((char *) rq->wq->wq +
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800360 (sizeof(struct rvt_rwqe) +
Ralph Campbellf9315512010-05-23 21:44:54 -0700361 rq->max_sge * sizeof(struct ib_sge)) * n);
362}
363
Ralph Campbellf9315512010-05-23 21:44:54 -0700364struct qib_opcode_stats {
365 u64 n_packets; /* number of packets */
366 u64 n_bytes; /* total number of bytes */
367};
368
Mike Marciniszynddb88762013-06-15 17:07:03 -0400369struct qib_opcode_stats_perctx {
370 struct qib_opcode_stats stats[128];
371};
372
Mike Marciniszyn7d7632a2014-03-07 08:40:55 -0500373struct qib_pma_counters {
374 u64 n_unicast_xmit; /* total unicast packets sent */
375 u64 n_unicast_rcv; /* total unicast packets received */
376 u64 n_multicast_xmit; /* total multicast packets sent */
377 u64 n_multicast_rcv; /* total multicast packets received */
378};
379
Ralph Campbellf9315512010-05-23 21:44:54 -0700380struct qib_ibport {
Harish Chegondif24a6d42016-01-22 12:56:02 -0800381 struct rvt_ibport rvp;
Dennis Dalessandro96ab1ac2016-01-22 12:46:07 -0800382 struct rvt_ah *sm_ah;
383 struct rvt_ah *smi_ah;
Ralph Campbellf9315512010-05-23 21:44:54 -0700384 __be64 guids[QIB_GUIDS_PER_PORT - 1]; /* writable GUIDs */
Mike Marciniszyn7d7632a2014-03-07 08:40:55 -0500385 struct qib_pma_counters __percpu *pmastats;
386 u64 z_unicast_xmit; /* starting count for PMA */
387 u64 z_unicast_rcv; /* starting count for PMA */
388 u64 z_multicast_xmit; /* starting count for PMA */
389 u64 z_multicast_rcv; /* starting count for PMA */
Ralph Campbellf9315512010-05-23 21:44:54 -0700390 u64 z_symbol_error_counter; /* starting count for PMA */
391 u64 z_link_error_recovery_counter; /* starting count for PMA */
392 u64 z_link_downed_counter; /* starting count for PMA */
393 u64 z_port_rcv_errors; /* starting count for PMA */
394 u64 z_port_rcv_remphys_errors; /* starting count for PMA */
395 u64 z_port_xmit_discards; /* starting count for PMA */
396 u64 z_port_xmit_data; /* starting count for PMA */
397 u64 z_port_rcv_data; /* starting count for PMA */
398 u64 z_port_xmit_packets; /* starting count for PMA */
399 u64 z_port_rcv_packets; /* starting count for PMA */
400 u32 z_local_link_integrity_errors; /* starting count for PMA */
401 u32 z_excessive_buffer_overrun_errors; /* starting count for PMA */
402 u32 z_vl15_dropped; /* starting count for PMA */
Ralph Campbellf9315512010-05-23 21:44:54 -0700403 u8 sl_to_vl[16];
Ralph Campbellf9315512010-05-23 21:44:54 -0700404};
405
406struct qib_ibdev {
Dennis Dalessandro2dc05ab2016-01-22 12:44:29 -0800407 struct rvt_dev_info rdi;
Ralph Campbellf9315512010-05-23 21:44:54 -0700408
Ralph Campbellf9315512010-05-23 21:44:54 -0700409 struct list_head piowait; /* list for wait PIO buf */
410 struct list_head dmawait; /* list for wait DMA */
411 struct list_head txwait; /* list for wait qib_verbs_txreq */
412 struct list_head memwait; /* list for wait kernel memory */
413 struct list_head txreq_free;
414 struct timer_list mem_timer;
Ralph Campbellf9315512010-05-23 21:44:54 -0700415 struct qib_pio_header *pio_hdrs;
416 dma_addr_t pio_hdrs_phys;
Mike Marciniszynaf061a62011-09-23 13:16:44 -0400417 u32 qp_rnd; /* random bytes for hash */
Ralph Campbellf9315512010-05-23 21:44:54 -0700418
419 u32 n_piowait;
420 u32 n_txwait;
421
Ralph Campbellf9315512010-05-23 21:44:54 -0700422 u32 n_cqs_allocated; /* number of CQs allocated for device */
423 spinlock_t n_cqs_lock;
424 u32 n_qps_allocated; /* number of QPs allocated for device */
425 spinlock_t n_qps_lock;
426 u32 n_srqs_allocated; /* number of SRQs allocated for device */
427 spinlock_t n_srqs_lock;
428 u32 n_mcast_grps_allocated; /* number of mcast groups allocated */
429 spinlock_t n_mcast_grps_lock;
Mike Marciniszynddb88762013-06-15 17:07:03 -0400430#ifdef CONFIG_DEBUG_FS
431 /* per HCA debugfs */
432 struct dentry *qib_ibdev_dbg;
433#endif
Ralph Campbellf9315512010-05-23 21:44:54 -0700434};
435
436struct qib_verbs_counters {
437 u64 symbol_error_counter;
438 u64 link_error_recovery_counter;
439 u64 link_downed_counter;
440 u64 port_rcv_errors;
441 u64 port_rcv_remphys_errors;
442 u64 port_xmit_discards;
443 u64 port_xmit_data;
444 u64 port_rcv_data;
445 u64 port_xmit_packets;
446 u64 port_rcv_packets;
447 u32 local_link_integrity_errors;
448 u32 excessive_buffer_overrun_errors;
449 u32 vl15_dropped;
450};
451
Ralph Campbellf9315512010-05-23 21:44:54 -0700452static inline struct qib_cq *to_icq(struct ib_cq *ibcq)
453{
454 return container_of(ibcq, struct qib_cq, ibcq);
455}
456
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800457static inline struct rvt_qp *to_iqp(struct ib_qp *ibqp)
Ralph Campbellf9315512010-05-23 21:44:54 -0700458{
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800459 return container_of(ibqp, struct rvt_qp, ibqp);
Ralph Campbellf9315512010-05-23 21:44:54 -0700460}
461
462static inline struct qib_ibdev *to_idev(struct ib_device *ibdev)
463{
Dennis Dalessandro2dc05ab2016-01-22 12:44:29 -0800464 struct rvt_dev_info *rdi;
465
466 rdi = container_of(ibdev, struct rvt_dev_info, ibdev);
467 return container_of(rdi, struct qib_ibdev, rdi);
Ralph Campbellf9315512010-05-23 21:44:54 -0700468}
469
470/*
471 * Send if not busy or waiting for I/O and either
472 * a RC response is pending or we can process send work requests.
473 */
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800474static inline int qib_send_ok(struct rvt_qp *qp)
Ralph Campbellf9315512010-05-23 21:44:54 -0700475{
476 return !(qp->s_flags & (QIB_S_BUSY | QIB_S_ANY_WAIT_IO)) &&
477 (qp->s_hdrwords || (qp->s_flags & QIB_S_RESP_PENDING) ||
478 !(qp->s_flags & QIB_S_ANY_WAIT_SEND));
479}
480
Ralph Campbellf9315512010-05-23 21:44:54 -0700481/*
482 * This must be called with s_lock held.
483 */
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800484void qib_schedule_send(struct rvt_qp *qp);
Ralph Campbellf9315512010-05-23 21:44:54 -0700485
486static inline int qib_pkey_ok(u16 pkey1, u16 pkey2)
487{
488 u16 p1 = pkey1 & 0x7FFF;
489 u16 p2 = pkey2 & 0x7FFF;
490
491 /*
492 * Low 15 bits must be non-zero and match, and
493 * one of the two must be a full member.
494 */
495 return p1 && p1 == p2 && ((__s16)pkey1 < 0 || (__s16)pkey2 < 0);
496}
497
498void qib_bad_pqkey(struct qib_ibport *ibp, __be16 trap_num, u32 key, u32 sl,
499 u32 qp1, u32 qp2, __be16 lid1, __be16 lid2);
500void qib_cap_mask_chg(struct qib_ibport *ibp);
501void qib_sys_guid_chg(struct qib_ibport *ibp);
502void qib_node_desc_chg(struct qib_ibport *ibp);
503int qib_process_mad(struct ib_device *ibdev, int mad_flags, u8 port_num,
Ira Weinya97e2d82015-05-31 17:15:30 -0400504 const struct ib_wc *in_wc, const struct ib_grh *in_grh,
Ira Weiny4cd7c942015-06-06 14:38:31 -0400505 const struct ib_mad_hdr *in, size_t in_mad_size,
506 struct ib_mad_hdr *out, size_t *out_mad_size,
507 u16 *out_mad_pkey_index);
Ralph Campbellf9315512010-05-23 21:44:54 -0700508int qib_create_agents(struct qib_ibdev *dev);
509void qib_free_agents(struct qib_ibdev *dev);
510
511/*
512 * Compare the lower 24 bits of the two values.
513 * Returns an integer <, ==, or > than zero.
514 */
515static inline int qib_cmp24(u32 a, u32 b)
516{
517 return (((int) a) - ((int) b)) << 8;
518}
519
520struct qib_mcast *qib_mcast_find(struct qib_ibport *ibp, union ib_gid *mgid);
521
522int qib_snapshot_counters(struct qib_pportdata *ppd, u64 *swords,
523 u64 *rwords, u64 *spkts, u64 *rpkts,
524 u64 *xmit_wait);
525
526int qib_get_counters(struct qib_pportdata *ppd,
527 struct qib_verbs_counters *cntrs);
528
529int qib_multicast_attach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid);
530
531int qib_multicast_detach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid);
532
533int qib_mcast_tree_empty(struct qib_ibport *ibp);
534
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800535__be32 qib_compute_aeth(struct rvt_qp *qp);
Ralph Campbellf9315512010-05-23 21:44:54 -0700536
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800537struct rvt_qp *qib_lookup_qpn(struct qib_ibport *ibp, u32 qpn);
Ralph Campbellf9315512010-05-23 21:44:54 -0700538
539struct ib_qp *qib_create_qp(struct ib_pd *ibpd,
540 struct ib_qp_init_attr *init_attr,
541 struct ib_udata *udata);
542
543int qib_destroy_qp(struct ib_qp *ibqp);
544
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800545int qib_error_qp(struct rvt_qp *qp, enum ib_wc_status err);
Ralph Campbellf9315512010-05-23 21:44:54 -0700546
547int qib_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr,
548 int attr_mask, struct ib_udata *udata);
549
550int qib_query_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr,
551 int attr_mask, struct ib_qp_init_attr *init_attr);
552
553unsigned qib_free_all_qps(struct qib_devdata *dd);
554
Harish Chegondi898fa522016-01-22 12:56:27 -0800555void qib_init_qpn_table(struct qib_devdata *dd, struct rvt_qpn_table *qpt);
Ralph Campbellf9315512010-05-23 21:44:54 -0700556
Harish Chegondi898fa522016-01-22 12:56:27 -0800557void qib_free_qpn_table(struct rvt_qpn_table *qpt);
Ralph Campbellf9315512010-05-23 21:44:54 -0700558
Mike Marciniszyn1dd173b2013-06-15 17:07:14 -0400559#ifdef CONFIG_DEBUG_FS
560
561struct qib_qp_iter;
562
563struct qib_qp_iter *qib_qp_iter_init(struct qib_ibdev *dev);
564
565int qib_qp_iter_next(struct qib_qp_iter *iter);
566
567void qib_qp_iter_print(struct seq_file *s, struct qib_qp_iter *iter);
568
569#endif
570
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800571void qib_get_credit(struct rvt_qp *qp, u32 aeth);
Ralph Campbellf9315512010-05-23 21:44:54 -0700572
573unsigned qib_pkt_delay(u32 plen, u8 snd_mult, u8 rcv_mult);
574
575void qib_verbs_sdma_desc_avail(struct qib_pportdata *ppd, unsigned avail);
576
577void qib_put_txreq(struct qib_verbs_txreq *tx);
578
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800579int qib_verbs_send(struct rvt_qp *qp, struct qib_ib_header *hdr,
580 u32 hdrwords, struct rvt_sge_state *ss, u32 len);
Ralph Campbellf9315512010-05-23 21:44:54 -0700581
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800582void qib_copy_sge(struct rvt_sge_state *ss, void *data, u32 length,
Ralph Campbellf9315512010-05-23 21:44:54 -0700583 int release);
584
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800585void qib_skip_sge(struct rvt_sge_state *ss, u32 length, int release);
Ralph Campbellf9315512010-05-23 21:44:54 -0700586
587void qib_uc_rcv(struct qib_ibport *ibp, struct qib_ib_header *hdr,
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800588 int has_grh, void *data, u32 tlen, struct rvt_qp *qp);
Ralph Campbellf9315512010-05-23 21:44:54 -0700589
590void qib_rc_rcv(struct qib_ctxtdata *rcd, struct qib_ib_header *hdr,
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800591 int has_grh, void *data, u32 tlen, struct rvt_qp *qp);
Ralph Campbellf9315512010-05-23 21:44:54 -0700592
593int qib_check_ah(struct ib_device *ibdev, struct ib_ah_attr *ah_attr);
594
Mike Marciniszyn1fb9fed2012-07-16 17:11:06 +0000595struct ib_ah *qib_create_qp0_ah(struct qib_ibport *ibp, u16 dlid);
596
Ralph Campbellf9315512010-05-23 21:44:54 -0700597void qib_rc_rnr_retry(unsigned long arg);
598
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800599void qib_rc_send_complete(struct rvt_qp *qp, struct qib_ib_header *hdr);
Ralph Campbellf9315512010-05-23 21:44:54 -0700600
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800601void qib_rc_error(struct rvt_qp *qp, enum ib_wc_status err);
Ralph Campbellf9315512010-05-23 21:44:54 -0700602
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800603int qib_post_ud_send(struct rvt_qp *qp, struct ib_send_wr *wr);
Ralph Campbellf9315512010-05-23 21:44:54 -0700604
605void qib_ud_rcv(struct qib_ibport *ibp, struct qib_ib_header *hdr,
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800606 int has_grh, void *data, u32 tlen, struct rvt_qp *qp);
Ralph Campbellf9315512010-05-23 21:44:54 -0700607
608int qib_post_srq_receive(struct ib_srq *ibsrq, struct ib_recv_wr *wr,
609 struct ib_recv_wr **bad_wr);
610
611struct ib_srq *qib_create_srq(struct ib_pd *ibpd,
612 struct ib_srq_init_attr *srq_init_attr,
613 struct ib_udata *udata);
614
615int qib_modify_srq(struct ib_srq *ibsrq, struct ib_srq_attr *attr,
616 enum ib_srq_attr_mask attr_mask,
617 struct ib_udata *udata);
618
619int qib_query_srq(struct ib_srq *ibsrq, struct ib_srq_attr *attr);
620
621int qib_destroy_srq(struct ib_srq *ibsrq);
622
Mike Marciniszyn85caafe2013-06-04 15:05:37 -0400623int qib_cq_init(struct qib_devdata *dd);
624
625void qib_cq_exit(struct qib_devdata *dd);
626
Ralph Campbellf9315512010-05-23 21:44:54 -0700627void qib_cq_enter(struct qib_cq *cq, struct ib_wc *entry, int sig);
628
629int qib_poll_cq(struct ib_cq *ibcq, int num_entries, struct ib_wc *entry);
630
Matan Barakbcf4c1e2015-06-11 16:35:20 +0300631struct ib_cq *qib_create_cq(struct ib_device *ibdev,
632 const struct ib_cq_init_attr *attr,
633 struct ib_ucontext *context,
Ralph Campbellf9315512010-05-23 21:44:54 -0700634 struct ib_udata *udata);
635
636int qib_destroy_cq(struct ib_cq *ibcq);
637
638int qib_req_notify_cq(struct ib_cq *ibcq, enum ib_cq_notify_flags notify_flags);
639
640int qib_resize_cq(struct ib_cq *ibcq, int cqe, struct ib_udata *udata);
641
Mike Marciniszyn8aac4cc2012-06-27 18:33:19 -0400642void mr_rcu_callback(struct rcu_head *list);
643
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800644static inline void qib_put_ss(struct rvt_sge_state *ss)
Mike Marciniszyn6a826492012-06-27 18:33:12 -0400645{
646 while (ss->num_sge) {
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800647 rvt_put_mr(ss->sge.mr);
Mike Marciniszyn6a826492012-06-27 18:33:12 -0400648 if (--ss->num_sge)
649 ss->sge = *ss->sg_list++;
650 }
651}
652
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800653int qib_get_rwqe(struct rvt_qp *qp, int wr_id_only);
Ralph Campbellf9315512010-05-23 21:44:54 -0700654
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800655void qib_migrate_qp(struct rvt_qp *qp);
Ralph Campbellf9315512010-05-23 21:44:54 -0700656
657int qib_ruc_check_hdr(struct qib_ibport *ibp, struct qib_ib_header *hdr,
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800658 int has_grh, struct rvt_qp *qp, u32 bth0);
Ralph Campbellf9315512010-05-23 21:44:54 -0700659
660u32 qib_make_grh(struct qib_ibport *ibp, struct ib_grh *hdr,
661 struct ib_global_route *grh, u32 hwords, u32 nwords);
662
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800663void qib_make_ruc_header(struct rvt_qp *qp, struct qib_other_headers *ohdr,
Ralph Campbellf9315512010-05-23 21:44:54 -0700664 u32 bth0, u32 bth2);
665
666void qib_do_send(struct work_struct *work);
667
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800668void qib_send_complete(struct rvt_qp *qp, struct rvt_swqe *wqe,
Ralph Campbellf9315512010-05-23 21:44:54 -0700669 enum ib_wc_status status);
670
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800671void qib_send_rc_ack(struct rvt_qp *qp);
Ralph Campbellf9315512010-05-23 21:44:54 -0700672
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800673int qib_make_rc_req(struct rvt_qp *qp);
Ralph Campbellf9315512010-05-23 21:44:54 -0700674
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800675int qib_make_uc_req(struct rvt_qp *qp);
Ralph Campbellf9315512010-05-23 21:44:54 -0700676
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800677int qib_make_ud_req(struct rvt_qp *qp);
Ralph Campbellf9315512010-05-23 21:44:54 -0700678
679int qib_register_ib_device(struct qib_devdata *);
680
681void qib_unregister_ib_device(struct qib_devdata *);
682
683void qib_ib_rcv(struct qib_ctxtdata *, void *, void *, u32);
684
685void qib_ib_piobufavail(struct qib_devdata *);
686
687unsigned qib_get_npkeys(struct qib_devdata *);
688
689unsigned qib_get_pkey(struct qib_ibport *, unsigned);
690
691extern const enum ib_wc_opcode ib_qib_wc_opcode[];
692
693/*
694 * Below HCA-independent IB PhysPortState values, returned
695 * by the f_ibphys_portstate() routine.
696 */
697#define IB_PHYSPORTSTATE_SLEEP 1
698#define IB_PHYSPORTSTATE_POLL 2
699#define IB_PHYSPORTSTATE_DISABLED 3
700#define IB_PHYSPORTSTATE_CFG_TRAIN 4
701#define IB_PHYSPORTSTATE_LINKUP 5
702#define IB_PHYSPORTSTATE_LINK_ERR_RECOVER 6
703#define IB_PHYSPORTSTATE_CFG_DEBOUNCE 8
704#define IB_PHYSPORTSTATE_CFG_IDLE 0xB
705#define IB_PHYSPORTSTATE_RECOVERY_RETRAIN 0xC
706#define IB_PHYSPORTSTATE_RECOVERY_WAITRMT 0xE
707#define IB_PHYSPORTSTATE_RECOVERY_IDLE 0xF
708#define IB_PHYSPORTSTATE_CFG_ENH 0x10
709#define IB_PHYSPORTSTATE_CFG_WAIT_ENH 0x13
710
711extern const int ib_qib_state_ops[];
712
713extern __be64 ib_qib_sys_image_guid; /* in network order */
714
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800715extern unsigned int ib_rvt_lkey_table_size;
Ralph Campbellf9315512010-05-23 21:44:54 -0700716
717extern unsigned int ib_qib_max_cqes;
718
719extern unsigned int ib_qib_max_cqs;
720
721extern unsigned int ib_qib_max_qp_wrs;
722
723extern unsigned int ib_qib_max_qps;
724
725extern unsigned int ib_qib_max_sges;
726
727extern unsigned int ib_qib_max_mcast_grps;
728
729extern unsigned int ib_qib_max_mcast_qp_attached;
730
731extern unsigned int ib_qib_max_srqs;
732
733extern unsigned int ib_qib_max_srq_sges;
734
735extern unsigned int ib_qib_max_srq_wrs;
736
737extern const u32 ib_qib_rnr_table[];
738
Ralph Campbellf9315512010-05-23 21:44:54 -0700739#endif /* QIB_VERBS_H */