blob: a9d7f0a8cd022dcbf9d2e516b12de650eac9aeb7 [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
58#define QPN_MAX (1 << 24)
59#define QPNMAP_ENTRIES (QPN_MAX / PAGE_SIZE / BITS_PER_BYTE)
60
61/*
62 * Increment this value if any changes that break userspace ABI
63 * compatibility are made.
64 */
65#define QIB_UVERBS_ABI_VERSION 2
66
67/*
68 * Define an ib_cq_notify value that is not valid so we know when CQ
69 * notifications are armed.
70 */
71#define IB_CQ_NONE (IB_CQ_NEXT_COMP + 1)
72
73#define IB_SEQ_NAK (3 << 29)
74
75/* AETH NAK opcode values */
76#define IB_RNR_NAK 0x20
77#define IB_NAK_PSN_ERROR 0x60
78#define IB_NAK_INVALID_REQUEST 0x61
79#define IB_NAK_REMOTE_ACCESS_ERROR 0x62
80#define IB_NAK_REMOTE_OPERATIONAL_ERROR 0x63
81#define IB_NAK_INVALID_RD_REQUEST 0x64
82
83/* Flags for checking QP state (see ib_qib_state_ops[]) */
84#define QIB_POST_SEND_OK 0x01
85#define QIB_POST_RECV_OK 0x02
86#define QIB_PROCESS_RECV_OK 0x04
87#define QIB_PROCESS_SEND_OK 0x08
88#define QIB_PROCESS_NEXT_SEND_OK 0x10
89#define QIB_FLUSH_SEND 0x20
90#define QIB_FLUSH_RECV 0x40
91#define QIB_PROCESS_OR_FLUSH_SEND \
92 (QIB_PROCESS_SEND_OK | QIB_FLUSH_SEND)
93
94/* IB Performance Manager status values */
95#define IB_PMA_SAMPLE_STATUS_DONE 0x00
96#define IB_PMA_SAMPLE_STATUS_STARTED 0x01
97#define IB_PMA_SAMPLE_STATUS_RUNNING 0x02
98
99/* Mandatory IB performance counter select values. */
100#define IB_PMA_PORT_XMIT_DATA cpu_to_be16(0x0001)
101#define IB_PMA_PORT_RCV_DATA cpu_to_be16(0x0002)
102#define IB_PMA_PORT_XMIT_PKTS cpu_to_be16(0x0003)
103#define IB_PMA_PORT_RCV_PKTS cpu_to_be16(0x0004)
104#define IB_PMA_PORT_XMIT_WAIT cpu_to_be16(0x0005)
105
106#define QIB_VENDOR_IPG cpu_to_be16(0xFFA0)
107
108#define IB_BTH_REQ_ACK (1 << 31)
109#define IB_BTH_SOLICITED (1 << 23)
110#define IB_BTH_MIG_REQ (1 << 22)
111
112/* XXX Should be defined in ib_verbs.h enum ib_port_cap_flags */
113#define IB_PORT_OTHER_LOCAL_CHANGES_SUP (1 << 26)
114
115#define IB_GRH_VERSION 6
116#define IB_GRH_VERSION_MASK 0xF
117#define IB_GRH_VERSION_SHIFT 28
118#define IB_GRH_TCLASS_MASK 0xFF
119#define IB_GRH_TCLASS_SHIFT 20
120#define IB_GRH_FLOW_MASK 0xFFFFF
121#define IB_GRH_FLOW_SHIFT 0
122#define IB_GRH_NEXT_HDR 0x1B
123
124#define IB_DEFAULT_GID_PREFIX cpu_to_be64(0xfe80000000000000ULL)
125
126/* Values for set/get portinfo VLCap OperationalVLs */
127#define IB_VL_VL0 1
128#define IB_VL_VL0_1 2
129#define IB_VL_VL0_3 3
130#define IB_VL_VL0_7 4
131#define IB_VL_VL0_14 5
132
133static inline int qib_num_vls(int vls)
134{
135 switch (vls) {
136 default:
137 case IB_VL_VL0:
138 return 1;
139 case IB_VL_VL0_1:
140 return 2;
141 case IB_VL_VL0_3:
142 return 4;
143 case IB_VL_VL0_7:
144 return 8;
145 case IB_VL_VL0_14:
146 return 15;
147 }
148}
149
150struct ib_reth {
151 __be64 vaddr;
152 __be32 rkey;
153 __be32 length;
Mike Marciniszyn78a58862013-10-24 11:40:37 -0400154} __packed;
Ralph Campbellf9315512010-05-23 21:44:54 -0700155
156struct ib_atomic_eth {
157 __be32 vaddr[2]; /* unaligned so access as 2 32-bit words */
158 __be32 rkey;
159 __be64 swap_data;
160 __be64 compare_data;
Mike Marciniszyn78a58862013-10-24 11:40:37 -0400161} __packed;
Ralph Campbellf9315512010-05-23 21:44:54 -0700162
163struct qib_other_headers {
164 __be32 bth[3];
165 union {
166 struct {
167 __be32 deth[2];
168 __be32 imm_data;
169 } ud;
170 struct {
171 struct ib_reth reth;
172 __be32 imm_data;
173 } rc;
174 struct {
175 __be32 aeth;
176 __be32 atomic_ack_eth[2];
177 } at;
178 __be32 imm_data;
179 __be32 aeth;
180 struct ib_atomic_eth atomic_eth;
181 } u;
Mike Marciniszyn78a58862013-10-24 11:40:37 -0400182} __packed;
Ralph Campbellf9315512010-05-23 21:44:54 -0700183
184/*
185 * Note that UD packets with a GRH header are 8+40+12+8 = 68 bytes
186 * long (72 w/ imm_data). Only the first 56 bytes of the IB header
187 * will be in the eager header buffer. The remaining 12 or 16 bytes
188 * are in the data buffer.
189 */
190struct qib_ib_header {
191 __be16 lrh[4];
192 union {
193 struct {
194 struct ib_grh grh;
195 struct qib_other_headers oth;
196 } l;
197 struct qib_other_headers oth;
198 } u;
Mike Marciniszyn78a58862013-10-24 11:40:37 -0400199} __packed;
Ralph Campbellf9315512010-05-23 21:44:54 -0700200
201struct qib_pio_header {
202 __le32 pbc[2];
203 struct qib_ib_header hdr;
Mike Marciniszyn78a58862013-10-24 11:40:37 -0400204} __packed;
Ralph Campbellf9315512010-05-23 21:44:54 -0700205
206/*
207 * There is one struct qib_mcast for each multicast GID.
208 * All attached QPs are then stored as a list of
209 * struct qib_mcast_qp.
210 */
211struct qib_mcast_qp {
212 struct list_head list;
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800213 struct rvt_qp *qp;
Ralph Campbellf9315512010-05-23 21:44:54 -0700214};
215
216struct qib_mcast {
217 struct rb_node rb_node;
218 union ib_gid mgid;
219 struct list_head qp_list;
220 wait_queue_head_t wait;
221 atomic_t refcount;
222 int n_attached;
223};
224
Ralph Campbellf9315512010-05-23 21:44:54 -0700225/*
Ralph Campbellf9315512010-05-23 21:44:54 -0700226 * This structure is used to contain the head pointer, tail pointer,
227 * and completion queue entries as a single memory allocation so
228 * it can be mmap'ed into user space.
229 */
230struct qib_cq_wc {
231 u32 head; /* index of next entry to fill */
232 u32 tail; /* index of next ib_poll_cq() entry */
233 union {
234 /* these are actually size ibcq.cqe + 1 */
235 struct ib_uverbs_wc uqueue[0];
236 struct ib_wc kqueue[0];
237 };
238};
239
240/*
241 * The completion queue structure.
242 */
243struct qib_cq {
244 struct ib_cq ibcq;
Mike Marciniszyn85caafe2013-06-04 15:05:37 -0400245 struct kthread_work comptask;
246 struct qib_devdata *dd;
Ralph Campbellf9315512010-05-23 21:44:54 -0700247 spinlock_t lock; /* protect changes in this struct */
248 u8 notify;
249 u8 triggered;
250 struct qib_cq_wc *queue;
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800251 struct rvt_mmap_info *ip;
Ralph Campbellf9315512010-05-23 21:44:54 -0700252};
253
254struct qib_srq {
255 struct ib_srq ibsrq;
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800256 struct rvt_rq rq;
257 struct rvt_mmap_info *ip;
Ralph Campbellf9315512010-05-23 21:44:54 -0700258 /* send signal when number of RWQEs < limit */
259 u32 limit;
260};
261
Ralph Campbellf9315512010-05-23 21:44:54 -0700262/*
Dennis Dalessandroffc26902016-01-22 12:45:11 -0800263 * qib specific data structure that will be hidden from rvt after the queue pair
264 * is made common.
265 */
Dennis Dalessandroffc26902016-01-22 12:45:11 -0800266struct qib_qp_priv {
267 struct qib_ib_header *s_hdr; /* next packet header to send */
268 struct list_head iowait; /* link for wait PIO buf */
269 atomic_t s_dma_busy;
270 struct qib_verbs_txreq *s_tx;
271 struct work_struct s_work;
272 wait_queue_head_t wait_dma;
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800273 struct rvt_qp *owner;
Ralph Campbellf9315512010-05-23 21:44:54 -0700274};
275
276/*
277 * Atomic bit definitions for r_aflags.
278 */
279#define QIB_R_WRID_VALID 0
280#define QIB_R_REWIND_SGE 1
281
282/*
283 * Bit definitions for r_flags.
284 */
285#define QIB_R_REUSE_SGE 0x01
286#define QIB_R_RDMAR_SEQ 0x02
287#define QIB_R_RSP_NAK 0x04
288#define QIB_R_RSP_SEND 0x08
289#define QIB_R_COMM_EST 0x10
290
291/*
292 * Bit definitions for s_flags.
293 *
294 * QIB_S_SIGNAL_REQ_WR - set if QP send WRs contain completion signaled
295 * QIB_S_BUSY - send tasklet is processing the QP
296 * QIB_S_TIMER - the RC retry timer is active
297 * QIB_S_ACK_PENDING - an ACK is waiting to be sent after RDMA read/atomics
298 * QIB_S_WAIT_FENCE - waiting for all prior RDMA read or atomic SWQEs
299 * before processing the next SWQE
300 * QIB_S_WAIT_RDMAR - waiting for a RDMA read or atomic SWQE to complete
301 * before processing the next SWQE
302 * QIB_S_WAIT_RNR - waiting for RNR timeout
303 * QIB_S_WAIT_SSN_CREDIT - waiting for RC credits to process next SWQE
304 * QIB_S_WAIT_DMA - waiting for send DMA queue to drain before generating
305 * next send completion entry not via send DMA
306 * QIB_S_WAIT_PIO - waiting for a send buffer to be available
307 * QIB_S_WAIT_TX - waiting for a struct qib_verbs_txreq to be available
308 * QIB_S_WAIT_DMA_DESC - waiting for DMA descriptors to be available
309 * QIB_S_WAIT_KMEM - waiting for kernel memory to be available
310 * QIB_S_WAIT_PSN - waiting for a packet to exit the send DMA queue
311 * QIB_S_WAIT_ACK - waiting for an ACK packet before sending more requests
312 * QIB_S_SEND_ONE - send one packet, request ACK, then wait for ACK
313 */
314#define QIB_S_SIGNAL_REQ_WR 0x0001
315#define QIB_S_BUSY 0x0002
316#define QIB_S_TIMER 0x0004
317#define QIB_S_RESP_PENDING 0x0008
318#define QIB_S_ACK_PENDING 0x0010
319#define QIB_S_WAIT_FENCE 0x0020
320#define QIB_S_WAIT_RDMAR 0x0040
321#define QIB_S_WAIT_RNR 0x0080
322#define QIB_S_WAIT_SSN_CREDIT 0x0100
323#define QIB_S_WAIT_DMA 0x0200
324#define QIB_S_WAIT_PIO 0x0400
325#define QIB_S_WAIT_TX 0x0800
326#define QIB_S_WAIT_DMA_DESC 0x1000
327#define QIB_S_WAIT_KMEM 0x2000
328#define QIB_S_WAIT_PSN 0x4000
329#define QIB_S_WAIT_ACK 0x8000
330#define QIB_S_SEND_ONE 0x10000
331#define QIB_S_UNLIMITED_CREDIT 0x20000
332
333/*
334 * Wait flags that would prevent any packet type from being sent.
335 */
336#define QIB_S_ANY_WAIT_IO (QIB_S_WAIT_PIO | QIB_S_WAIT_TX | \
337 QIB_S_WAIT_DMA_DESC | QIB_S_WAIT_KMEM)
338
339/*
340 * Wait flags that would prevent send work requests from making progress.
341 */
342#define QIB_S_ANY_WAIT_SEND (QIB_S_WAIT_FENCE | QIB_S_WAIT_RDMAR | \
343 QIB_S_WAIT_RNR | QIB_S_WAIT_SSN_CREDIT | QIB_S_WAIT_DMA | \
344 QIB_S_WAIT_PSN | QIB_S_WAIT_ACK)
345
346#define QIB_S_ANY_WAIT (QIB_S_ANY_WAIT_IO | QIB_S_ANY_WAIT_SEND)
347
348#define QIB_PSN_CREDIT 16
349
350/*
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800351 * Since struct rvt_swqe is not a fixed size, we can't simply index into
352 * struct rvt_qp.s_wq. This function does the array index computation.
Ralph Campbellf9315512010-05-23 21:44:54 -0700353 */
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800354static inline struct rvt_swqe *get_swqe_ptr(struct rvt_qp *qp,
355 unsigned n)
Ralph Campbellf9315512010-05-23 21:44:54 -0700356{
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800357 return (struct rvt_swqe *)((char *)qp->s_wq +
358 (sizeof(struct rvt_swqe) +
Ralph Campbellf9315512010-05-23 21:44:54 -0700359 qp->s_max_sge *
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800360 sizeof(struct rvt_sge)) * n);
Ralph Campbellf9315512010-05-23 21:44:54 -0700361}
362
363/*
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800364 * Since struct rvt_rwqe is not a fixed size, we can't simply index into
365 * struct rvt_rwq.wq. This function does the array index computation.
Ralph Campbellf9315512010-05-23 21:44:54 -0700366 */
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800367static inline struct rvt_rwqe *get_rwqe_ptr(struct rvt_rq *rq, unsigned n)
Ralph Campbellf9315512010-05-23 21:44:54 -0700368{
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800369 return (struct rvt_rwqe *)
Ralph Campbellf9315512010-05-23 21:44:54 -0700370 ((char *) rq->wq->wq +
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800371 (sizeof(struct rvt_rwqe) +
Ralph Campbellf9315512010-05-23 21:44:54 -0700372 rq->max_sge * sizeof(struct ib_sge)) * n);
373}
374
375/*
376 * QPN-map pages start out as NULL, they get allocated upon
377 * first use and are never deallocated. This way,
378 * large bitmaps are not allocated unless large numbers of QPs are used.
379 */
380struct qpn_map {
381 void *page;
382};
383
384struct qib_qpn_table {
385 spinlock_t lock; /* protect changes in this struct */
386 unsigned flags; /* flags for QP0/1 allocated for each port */
387 u32 last; /* last QP number allocated */
388 u32 nmaps; /* size of the map table */
389 u16 limit;
390 u16 mask;
391 /* bit map of free QP numbers other than 0/1 */
392 struct qpn_map map[QPNMAP_ENTRIES];
393};
394
Ralph Campbellf9315512010-05-23 21:44:54 -0700395struct qib_opcode_stats {
396 u64 n_packets; /* number of packets */
397 u64 n_bytes; /* total number of bytes */
398};
399
Mike Marciniszynddb88762013-06-15 17:07:03 -0400400struct qib_opcode_stats_perctx {
401 struct qib_opcode_stats stats[128];
402};
403
Mike Marciniszyn7d7632a2014-03-07 08:40:55 -0500404struct qib_pma_counters {
405 u64 n_unicast_xmit; /* total unicast packets sent */
406 u64 n_unicast_rcv; /* total unicast packets received */
407 u64 n_multicast_xmit; /* total multicast packets sent */
408 u64 n_multicast_rcv; /* total multicast packets received */
409};
410
Ralph Campbellf9315512010-05-23 21:44:54 -0700411struct qib_ibport {
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800412 struct rvt_qp __rcu *qp0;
413 struct rvt_qp __rcu *qp1;
Ralph Campbellf9315512010-05-23 21:44:54 -0700414 struct ib_mad_agent *send_agent; /* agent for SMI (traps) */
Dennis Dalessandro96ab1ac2016-01-22 12:46:07 -0800415 struct rvt_ah *sm_ah;
416 struct rvt_ah *smi_ah;
Ralph Campbellf9315512010-05-23 21:44:54 -0700417 struct rb_root mcast_tree;
418 spinlock_t lock; /* protect changes in this struct */
419
420 /* non-zero when timer is set */
421 unsigned long mkey_lease_timeout;
422 unsigned long trap_timeout;
423 __be64 gid_prefix; /* in network order */
424 __be64 mkey;
425 __be64 guids[QIB_GUIDS_PER_PORT - 1]; /* writable GUIDs */
426 u64 tid; /* TID for traps */
Mike Marciniszyn7d7632a2014-03-07 08:40:55 -0500427 struct qib_pma_counters __percpu *pmastats;
428 u64 z_unicast_xmit; /* starting count for PMA */
429 u64 z_unicast_rcv; /* starting count for PMA */
430 u64 z_multicast_xmit; /* starting count for PMA */
431 u64 z_multicast_rcv; /* starting count for PMA */
Ralph Campbellf9315512010-05-23 21:44:54 -0700432 u64 z_symbol_error_counter; /* starting count for PMA */
433 u64 z_link_error_recovery_counter; /* starting count for PMA */
434 u64 z_link_downed_counter; /* starting count for PMA */
435 u64 z_port_rcv_errors; /* starting count for PMA */
436 u64 z_port_rcv_remphys_errors; /* starting count for PMA */
437 u64 z_port_xmit_discards; /* starting count for PMA */
438 u64 z_port_xmit_data; /* starting count for PMA */
439 u64 z_port_rcv_data; /* starting count for PMA */
440 u64 z_port_xmit_packets; /* starting count for PMA */
441 u64 z_port_rcv_packets; /* starting count for PMA */
442 u32 z_local_link_integrity_errors; /* starting count for PMA */
443 u32 z_excessive_buffer_overrun_errors; /* starting count for PMA */
444 u32 z_vl15_dropped; /* starting count for PMA */
445 u32 n_rc_resends;
446 u32 n_rc_acks;
447 u32 n_rc_qacks;
448 u32 n_rc_delayed_comp;
449 u32 n_seq_naks;
450 u32 n_rdma_seq;
451 u32 n_rnr_naks;
452 u32 n_other_naks;
453 u32 n_loop_pkts;
454 u32 n_pkt_drops;
455 u32 n_vl15_dropped;
456 u32 n_rc_timeouts;
457 u32 n_dmawait;
458 u32 n_unaligned;
459 u32 n_rc_dupreq;
460 u32 n_rc_seqnak;
461 u32 port_cap_flags;
462 u32 pma_sample_start;
463 u32 pma_sample_interval;
464 __be16 pma_counter_select[5];
465 u16 pma_tag;
466 u16 pkey_violations;
467 u16 qkey_violations;
468 u16 mkey_violations;
469 u16 mkey_lease_period;
470 u16 sm_lid;
471 u16 repress_traps;
472 u8 sm_sl;
473 u8 mkeyprot;
474 u8 subnet_timeout;
475 u8 vl_high_limit;
476 u8 sl_to_vl[16];
477
Ralph Campbellf9315512010-05-23 21:44:54 -0700478};
479
Mike Marciniszyn551ace12012-07-19 13:03:56 +0000480
Ralph Campbellf9315512010-05-23 21:44:54 -0700481struct qib_ibdev {
Dennis Dalessandro2dc05ab2016-01-22 12:44:29 -0800482 struct rvt_dev_info rdi;
Ralph Campbellf9315512010-05-23 21:44:54 -0700483 struct list_head pending_mmaps;
484 spinlock_t mmap_offset_lock; /* protect mmap_offset */
485 u32 mmap_offset;
Ralph Campbellf9315512010-05-23 21:44:54 -0700486
487 /* QP numbers are shared by all IB ports */
488 struct qib_qpn_table qpn_table;
Ralph Campbellf9315512010-05-23 21:44:54 -0700489 struct list_head piowait; /* list for wait PIO buf */
490 struct list_head dmawait; /* list for wait DMA */
491 struct list_head txwait; /* list for wait qib_verbs_txreq */
492 struct list_head memwait; /* list for wait kernel memory */
493 struct list_head txreq_free;
494 struct timer_list mem_timer;
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800495 struct rvt_qp __rcu **qp_table;
Ralph Campbellf9315512010-05-23 21:44:54 -0700496 struct qib_pio_header *pio_hdrs;
497 dma_addr_t pio_hdrs_phys;
498 /* list of QPs waiting for RNR timer */
499 spinlock_t pending_lock; /* protect wait lists, PMA counters, etc. */
Mike Marciniszynaf061a62011-09-23 13:16:44 -0400500 u32 qp_table_size; /* size of the hash table */
501 u32 qp_rnd; /* random bytes for hash */
Ralph Campbellf9315512010-05-23 21:44:54 -0700502 spinlock_t qpt_lock;
503
504 u32 n_piowait;
505 u32 n_txwait;
506
Ralph Campbellf9315512010-05-23 21:44:54 -0700507 u32 n_cqs_allocated; /* number of CQs allocated for device */
508 spinlock_t n_cqs_lock;
509 u32 n_qps_allocated; /* number of QPs allocated for device */
510 spinlock_t n_qps_lock;
511 u32 n_srqs_allocated; /* number of SRQs allocated for device */
512 spinlock_t n_srqs_lock;
513 u32 n_mcast_grps_allocated; /* number of mcast groups allocated */
514 spinlock_t n_mcast_grps_lock;
Mike Marciniszynddb88762013-06-15 17:07:03 -0400515#ifdef CONFIG_DEBUG_FS
516 /* per HCA debugfs */
517 struct dentry *qib_ibdev_dbg;
518#endif
Ralph Campbellf9315512010-05-23 21:44:54 -0700519};
520
521struct qib_verbs_counters {
522 u64 symbol_error_counter;
523 u64 link_error_recovery_counter;
524 u64 link_downed_counter;
525 u64 port_rcv_errors;
526 u64 port_rcv_remphys_errors;
527 u64 port_xmit_discards;
528 u64 port_xmit_data;
529 u64 port_rcv_data;
530 u64 port_xmit_packets;
531 u64 port_rcv_packets;
532 u32 local_link_integrity_errors;
533 u32 excessive_buffer_overrun_errors;
534 u32 vl15_dropped;
535};
536
Ralph Campbellf9315512010-05-23 21:44:54 -0700537static inline struct qib_cq *to_icq(struct ib_cq *ibcq)
538{
539 return container_of(ibcq, struct qib_cq, ibcq);
540}
541
542static inline struct qib_srq *to_isrq(struct ib_srq *ibsrq)
543{
544 return container_of(ibsrq, struct qib_srq, ibsrq);
545}
546
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800547static inline struct rvt_qp *to_iqp(struct ib_qp *ibqp)
Ralph Campbellf9315512010-05-23 21:44:54 -0700548{
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800549 return container_of(ibqp, struct rvt_qp, ibqp);
Ralph Campbellf9315512010-05-23 21:44:54 -0700550}
551
552static inline struct qib_ibdev *to_idev(struct ib_device *ibdev)
553{
Dennis Dalessandro2dc05ab2016-01-22 12:44:29 -0800554 struct rvt_dev_info *rdi;
555
556 rdi = container_of(ibdev, struct rvt_dev_info, ibdev);
557 return container_of(rdi, struct qib_ibdev, rdi);
Ralph Campbellf9315512010-05-23 21:44:54 -0700558}
559
560/*
561 * Send if not busy or waiting for I/O and either
562 * a RC response is pending or we can process send work requests.
563 */
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800564static inline int qib_send_ok(struct rvt_qp *qp)
Ralph Campbellf9315512010-05-23 21:44:54 -0700565{
566 return !(qp->s_flags & (QIB_S_BUSY | QIB_S_ANY_WAIT_IO)) &&
567 (qp->s_hdrwords || (qp->s_flags & QIB_S_RESP_PENDING) ||
568 !(qp->s_flags & QIB_S_ANY_WAIT_SEND));
569}
570
Ralph Campbellf9315512010-05-23 21:44:54 -0700571/*
572 * This must be called with s_lock held.
573 */
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800574void qib_schedule_send(struct rvt_qp *qp);
Ralph Campbellf9315512010-05-23 21:44:54 -0700575
576static inline int qib_pkey_ok(u16 pkey1, u16 pkey2)
577{
578 u16 p1 = pkey1 & 0x7FFF;
579 u16 p2 = pkey2 & 0x7FFF;
580
581 /*
582 * Low 15 bits must be non-zero and match, and
583 * one of the two must be a full member.
584 */
585 return p1 && p1 == p2 && ((__s16)pkey1 < 0 || (__s16)pkey2 < 0);
586}
587
588void qib_bad_pqkey(struct qib_ibport *ibp, __be16 trap_num, u32 key, u32 sl,
589 u32 qp1, u32 qp2, __be16 lid1, __be16 lid2);
590void qib_cap_mask_chg(struct qib_ibport *ibp);
591void qib_sys_guid_chg(struct qib_ibport *ibp);
592void qib_node_desc_chg(struct qib_ibport *ibp);
593int qib_process_mad(struct ib_device *ibdev, int mad_flags, u8 port_num,
Ira Weinya97e2d82015-05-31 17:15:30 -0400594 const struct ib_wc *in_wc, const struct ib_grh *in_grh,
Ira Weiny4cd7c942015-06-06 14:38:31 -0400595 const struct ib_mad_hdr *in, size_t in_mad_size,
596 struct ib_mad_hdr *out, size_t *out_mad_size,
597 u16 *out_mad_pkey_index);
Ralph Campbellf9315512010-05-23 21:44:54 -0700598int qib_create_agents(struct qib_ibdev *dev);
599void qib_free_agents(struct qib_ibdev *dev);
600
601/*
602 * Compare the lower 24 bits of the two values.
603 * Returns an integer <, ==, or > than zero.
604 */
605static inline int qib_cmp24(u32 a, u32 b)
606{
607 return (((int) a) - ((int) b)) << 8;
608}
609
610struct qib_mcast *qib_mcast_find(struct qib_ibport *ibp, union ib_gid *mgid);
611
612int qib_snapshot_counters(struct qib_pportdata *ppd, u64 *swords,
613 u64 *rwords, u64 *spkts, u64 *rpkts,
614 u64 *xmit_wait);
615
616int qib_get_counters(struct qib_pportdata *ppd,
617 struct qib_verbs_counters *cntrs);
618
619int qib_multicast_attach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid);
620
621int qib_multicast_detach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid);
622
623int qib_mcast_tree_empty(struct qib_ibport *ibp);
624
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800625__be32 qib_compute_aeth(struct rvt_qp *qp);
Ralph Campbellf9315512010-05-23 21:44:54 -0700626
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800627struct rvt_qp *qib_lookup_qpn(struct qib_ibport *ibp, u32 qpn);
Ralph Campbellf9315512010-05-23 21:44:54 -0700628
629struct ib_qp *qib_create_qp(struct ib_pd *ibpd,
630 struct ib_qp_init_attr *init_attr,
631 struct ib_udata *udata);
632
633int qib_destroy_qp(struct ib_qp *ibqp);
634
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800635int qib_error_qp(struct rvt_qp *qp, enum ib_wc_status err);
Ralph Campbellf9315512010-05-23 21:44:54 -0700636
637int qib_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr,
638 int attr_mask, struct ib_udata *udata);
639
640int qib_query_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr,
641 int attr_mask, struct ib_qp_init_attr *init_attr);
642
643unsigned qib_free_all_qps(struct qib_devdata *dd);
644
645void qib_init_qpn_table(struct qib_devdata *dd, struct qib_qpn_table *qpt);
646
647void qib_free_qpn_table(struct qib_qpn_table *qpt);
648
Mike Marciniszyn1dd173b2013-06-15 17:07:14 -0400649#ifdef CONFIG_DEBUG_FS
650
651struct qib_qp_iter;
652
653struct qib_qp_iter *qib_qp_iter_init(struct qib_ibdev *dev);
654
655int qib_qp_iter_next(struct qib_qp_iter *iter);
656
657void qib_qp_iter_print(struct seq_file *s, struct qib_qp_iter *iter);
658
659#endif
660
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800661void qib_get_credit(struct rvt_qp *qp, u32 aeth);
Ralph Campbellf9315512010-05-23 21:44:54 -0700662
663unsigned qib_pkt_delay(u32 plen, u8 snd_mult, u8 rcv_mult);
664
665void qib_verbs_sdma_desc_avail(struct qib_pportdata *ppd, unsigned avail);
666
667void qib_put_txreq(struct qib_verbs_txreq *tx);
668
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800669int qib_verbs_send(struct rvt_qp *qp, struct qib_ib_header *hdr,
670 u32 hdrwords, struct rvt_sge_state *ss, u32 len);
Ralph Campbellf9315512010-05-23 21:44:54 -0700671
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800672void qib_copy_sge(struct rvt_sge_state *ss, void *data, u32 length,
Ralph Campbellf9315512010-05-23 21:44:54 -0700673 int release);
674
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800675void qib_skip_sge(struct rvt_sge_state *ss, u32 length, int release);
Ralph Campbellf9315512010-05-23 21:44:54 -0700676
677void qib_uc_rcv(struct qib_ibport *ibp, struct qib_ib_header *hdr,
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800678 int has_grh, void *data, u32 tlen, struct rvt_qp *qp);
Ralph Campbellf9315512010-05-23 21:44:54 -0700679
680void qib_rc_rcv(struct qib_ctxtdata *rcd, struct qib_ib_header *hdr,
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800681 int has_grh, void *data, u32 tlen, struct rvt_qp *qp);
Ralph Campbellf9315512010-05-23 21:44:54 -0700682
683int qib_check_ah(struct ib_device *ibdev, struct ib_ah_attr *ah_attr);
684
Mike Marciniszyn1fb9fed2012-07-16 17:11:06 +0000685struct ib_ah *qib_create_qp0_ah(struct qib_ibport *ibp, u16 dlid);
686
Ralph Campbellf9315512010-05-23 21:44:54 -0700687void qib_rc_rnr_retry(unsigned long arg);
688
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800689void qib_rc_send_complete(struct rvt_qp *qp, struct qib_ib_header *hdr);
Ralph Campbellf9315512010-05-23 21:44:54 -0700690
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800691void qib_rc_error(struct rvt_qp *qp, enum ib_wc_status err);
Ralph Campbellf9315512010-05-23 21:44:54 -0700692
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800693int qib_post_ud_send(struct rvt_qp *qp, struct ib_send_wr *wr);
Ralph Campbellf9315512010-05-23 21:44:54 -0700694
695void qib_ud_rcv(struct qib_ibport *ibp, struct qib_ib_header *hdr,
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800696 int has_grh, void *data, u32 tlen, struct rvt_qp *qp);
Ralph Campbellf9315512010-05-23 21:44:54 -0700697
698int qib_post_srq_receive(struct ib_srq *ibsrq, struct ib_recv_wr *wr,
699 struct ib_recv_wr **bad_wr);
700
701struct ib_srq *qib_create_srq(struct ib_pd *ibpd,
702 struct ib_srq_init_attr *srq_init_attr,
703 struct ib_udata *udata);
704
705int qib_modify_srq(struct ib_srq *ibsrq, struct ib_srq_attr *attr,
706 enum ib_srq_attr_mask attr_mask,
707 struct ib_udata *udata);
708
709int qib_query_srq(struct ib_srq *ibsrq, struct ib_srq_attr *attr);
710
711int qib_destroy_srq(struct ib_srq *ibsrq);
712
Mike Marciniszyn85caafe2013-06-04 15:05:37 -0400713int qib_cq_init(struct qib_devdata *dd);
714
715void qib_cq_exit(struct qib_devdata *dd);
716
Ralph Campbellf9315512010-05-23 21:44:54 -0700717void qib_cq_enter(struct qib_cq *cq, struct ib_wc *entry, int sig);
718
719int qib_poll_cq(struct ib_cq *ibcq, int num_entries, struct ib_wc *entry);
720
Matan Barakbcf4c1e2015-06-11 16:35:20 +0300721struct ib_cq *qib_create_cq(struct ib_device *ibdev,
722 const struct ib_cq_init_attr *attr,
723 struct ib_ucontext *context,
Ralph Campbellf9315512010-05-23 21:44:54 -0700724 struct ib_udata *udata);
725
726int qib_destroy_cq(struct ib_cq *ibcq);
727
728int qib_req_notify_cq(struct ib_cq *ibcq, enum ib_cq_notify_flags notify_flags);
729
730int qib_resize_cq(struct ib_cq *ibcq, int cqe, struct ib_udata *udata);
731
Mike Marciniszyn8aac4cc2012-06-27 18:33:19 -0400732void mr_rcu_callback(struct rcu_head *list);
733
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800734static inline void qib_put_ss(struct rvt_sge_state *ss)
Mike Marciniszyn6a826492012-06-27 18:33:12 -0400735{
736 while (ss->num_sge) {
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800737 rvt_put_mr(ss->sge.mr);
Mike Marciniszyn6a826492012-06-27 18:33:12 -0400738 if (--ss->num_sge)
739 ss->sge = *ss->sg_list++;
740 }
741}
742
Ralph Campbellf9315512010-05-23 21:44:54 -0700743void qib_release_mmap_info(struct kref *ref);
744
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800745struct rvt_mmap_info *qib_create_mmap_info(struct qib_ibdev *dev, u32 size,
Ralph Campbellf9315512010-05-23 21:44:54 -0700746 struct ib_ucontext *context,
747 void *obj);
748
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800749void qib_update_mmap_info(struct qib_ibdev *dev, struct rvt_mmap_info *ip,
Ralph Campbellf9315512010-05-23 21:44:54 -0700750 u32 size, void *obj);
751
752int qib_mmap(struct ib_ucontext *context, struct vm_area_struct *vma);
753
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800754int qib_get_rwqe(struct rvt_qp *qp, int wr_id_only);
Ralph Campbellf9315512010-05-23 21:44:54 -0700755
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800756void qib_migrate_qp(struct rvt_qp *qp);
Ralph Campbellf9315512010-05-23 21:44:54 -0700757
758int qib_ruc_check_hdr(struct qib_ibport *ibp, struct qib_ib_header *hdr,
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800759 int has_grh, struct rvt_qp *qp, u32 bth0);
Ralph Campbellf9315512010-05-23 21:44:54 -0700760
761u32 qib_make_grh(struct qib_ibport *ibp, struct ib_grh *hdr,
762 struct ib_global_route *grh, u32 hwords, u32 nwords);
763
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800764void qib_make_ruc_header(struct rvt_qp *qp, struct qib_other_headers *ohdr,
Ralph Campbellf9315512010-05-23 21:44:54 -0700765 u32 bth0, u32 bth2);
766
767void qib_do_send(struct work_struct *work);
768
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800769void qib_send_complete(struct rvt_qp *qp, struct rvt_swqe *wqe,
Ralph Campbellf9315512010-05-23 21:44:54 -0700770 enum ib_wc_status status);
771
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800772void qib_send_rc_ack(struct rvt_qp *qp);
Ralph Campbellf9315512010-05-23 21:44:54 -0700773
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800774int qib_make_rc_req(struct rvt_qp *qp);
Ralph Campbellf9315512010-05-23 21:44:54 -0700775
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800776int qib_make_uc_req(struct rvt_qp *qp);
Ralph Campbellf9315512010-05-23 21:44:54 -0700777
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800778int qib_make_ud_req(struct rvt_qp *qp);
Ralph Campbellf9315512010-05-23 21:44:54 -0700779
780int qib_register_ib_device(struct qib_devdata *);
781
782void qib_unregister_ib_device(struct qib_devdata *);
783
784void qib_ib_rcv(struct qib_ctxtdata *, void *, void *, u32);
785
786void qib_ib_piobufavail(struct qib_devdata *);
787
788unsigned qib_get_npkeys(struct qib_devdata *);
789
790unsigned qib_get_pkey(struct qib_ibport *, unsigned);
791
792extern const enum ib_wc_opcode ib_qib_wc_opcode[];
793
794/*
795 * Below HCA-independent IB PhysPortState values, returned
796 * by the f_ibphys_portstate() routine.
797 */
798#define IB_PHYSPORTSTATE_SLEEP 1
799#define IB_PHYSPORTSTATE_POLL 2
800#define IB_PHYSPORTSTATE_DISABLED 3
801#define IB_PHYSPORTSTATE_CFG_TRAIN 4
802#define IB_PHYSPORTSTATE_LINKUP 5
803#define IB_PHYSPORTSTATE_LINK_ERR_RECOVER 6
804#define IB_PHYSPORTSTATE_CFG_DEBOUNCE 8
805#define IB_PHYSPORTSTATE_CFG_IDLE 0xB
806#define IB_PHYSPORTSTATE_RECOVERY_RETRAIN 0xC
807#define IB_PHYSPORTSTATE_RECOVERY_WAITRMT 0xE
808#define IB_PHYSPORTSTATE_RECOVERY_IDLE 0xF
809#define IB_PHYSPORTSTATE_CFG_ENH 0x10
810#define IB_PHYSPORTSTATE_CFG_WAIT_ENH 0x13
811
812extern const int ib_qib_state_ops[];
813
814extern __be64 ib_qib_sys_image_guid; /* in network order */
815
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800816extern unsigned int ib_rvt_lkey_table_size;
Ralph Campbellf9315512010-05-23 21:44:54 -0700817
818extern unsigned int ib_qib_max_cqes;
819
820extern unsigned int ib_qib_max_cqs;
821
822extern unsigned int ib_qib_max_qp_wrs;
823
824extern unsigned int ib_qib_max_qps;
825
826extern unsigned int ib_qib_max_sges;
827
828extern unsigned int ib_qib_max_mcast_grps;
829
830extern unsigned int ib_qib_max_mcast_qp_attached;
831
832extern unsigned int ib_qib_max_srqs;
833
834extern unsigned int ib_qib_max_srq_sges;
835
836extern unsigned int ib_qib_max_srq_wrs;
837
838extern const u32 ib_qib_rnr_table[];
839
Ralph Campbellf9315512010-05-23 21:44:54 -0700840#endif /* QIB_VERBS_H */