blob: c7399ff90173050e16d4c84fbc5d77d54e5bcdd6 [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/* Address Handle */
226struct qib_ah {
227 struct ib_ah ibah;
228 struct ib_ah_attr attr;
229 atomic_t refcount;
230};
231
232/*
Ralph Campbellf9315512010-05-23 21:44:54 -0700233 * This structure is used to contain the head pointer, tail pointer,
234 * and completion queue entries as a single memory allocation so
235 * it can be mmap'ed into user space.
236 */
237struct qib_cq_wc {
238 u32 head; /* index of next entry to fill */
239 u32 tail; /* index of next ib_poll_cq() entry */
240 union {
241 /* these are actually size ibcq.cqe + 1 */
242 struct ib_uverbs_wc uqueue[0];
243 struct ib_wc kqueue[0];
244 };
245};
246
247/*
248 * The completion queue structure.
249 */
250struct qib_cq {
251 struct ib_cq ibcq;
Mike Marciniszyn85caafe2013-06-04 15:05:37 -0400252 struct kthread_work comptask;
253 struct qib_devdata *dd;
Ralph Campbellf9315512010-05-23 21:44:54 -0700254 spinlock_t lock; /* protect changes in this struct */
255 u8 notify;
256 u8 triggered;
257 struct qib_cq_wc *queue;
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800258 struct rvt_mmap_info *ip;
Ralph Campbellf9315512010-05-23 21:44:54 -0700259};
260
261struct qib_srq {
262 struct ib_srq ibsrq;
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800263 struct rvt_rq rq;
264 struct rvt_mmap_info *ip;
Ralph Campbellf9315512010-05-23 21:44:54 -0700265 /* send signal when number of RWQEs < limit */
266 u32 limit;
267};
268
Ralph Campbellf9315512010-05-23 21:44:54 -0700269/*
Dennis Dalessandroffc26902016-01-22 12:45:11 -0800270 * qib specific data structure that will be hidden from rvt after the queue pair
271 * is made common.
272 */
Dennis Dalessandroffc26902016-01-22 12:45:11 -0800273struct qib_qp_priv {
274 struct qib_ib_header *s_hdr; /* next packet header to send */
275 struct list_head iowait; /* link for wait PIO buf */
276 atomic_t s_dma_busy;
277 struct qib_verbs_txreq *s_tx;
278 struct work_struct s_work;
279 wait_queue_head_t wait_dma;
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800280 struct rvt_qp *owner;
Ralph Campbellf9315512010-05-23 21:44:54 -0700281};
282
283/*
284 * Atomic bit definitions for r_aflags.
285 */
286#define QIB_R_WRID_VALID 0
287#define QIB_R_REWIND_SGE 1
288
289/*
290 * Bit definitions for r_flags.
291 */
292#define QIB_R_REUSE_SGE 0x01
293#define QIB_R_RDMAR_SEQ 0x02
294#define QIB_R_RSP_NAK 0x04
295#define QIB_R_RSP_SEND 0x08
296#define QIB_R_COMM_EST 0x10
297
298/*
299 * Bit definitions for s_flags.
300 *
301 * QIB_S_SIGNAL_REQ_WR - set if QP send WRs contain completion signaled
302 * QIB_S_BUSY - send tasklet is processing the QP
303 * QIB_S_TIMER - the RC retry timer is active
304 * QIB_S_ACK_PENDING - an ACK is waiting to be sent after RDMA read/atomics
305 * QIB_S_WAIT_FENCE - waiting for all prior RDMA read or atomic SWQEs
306 * before processing the next SWQE
307 * QIB_S_WAIT_RDMAR - waiting for a RDMA read or atomic SWQE to complete
308 * before processing the next SWQE
309 * QIB_S_WAIT_RNR - waiting for RNR timeout
310 * QIB_S_WAIT_SSN_CREDIT - waiting for RC credits to process next SWQE
311 * QIB_S_WAIT_DMA - waiting for send DMA queue to drain before generating
312 * next send completion entry not via send DMA
313 * QIB_S_WAIT_PIO - waiting for a send buffer to be available
314 * QIB_S_WAIT_TX - waiting for a struct qib_verbs_txreq to be available
315 * QIB_S_WAIT_DMA_DESC - waiting for DMA descriptors to be available
316 * QIB_S_WAIT_KMEM - waiting for kernel memory to be available
317 * QIB_S_WAIT_PSN - waiting for a packet to exit the send DMA queue
318 * QIB_S_WAIT_ACK - waiting for an ACK packet before sending more requests
319 * QIB_S_SEND_ONE - send one packet, request ACK, then wait for ACK
320 */
321#define QIB_S_SIGNAL_REQ_WR 0x0001
322#define QIB_S_BUSY 0x0002
323#define QIB_S_TIMER 0x0004
324#define QIB_S_RESP_PENDING 0x0008
325#define QIB_S_ACK_PENDING 0x0010
326#define QIB_S_WAIT_FENCE 0x0020
327#define QIB_S_WAIT_RDMAR 0x0040
328#define QIB_S_WAIT_RNR 0x0080
329#define QIB_S_WAIT_SSN_CREDIT 0x0100
330#define QIB_S_WAIT_DMA 0x0200
331#define QIB_S_WAIT_PIO 0x0400
332#define QIB_S_WAIT_TX 0x0800
333#define QIB_S_WAIT_DMA_DESC 0x1000
334#define QIB_S_WAIT_KMEM 0x2000
335#define QIB_S_WAIT_PSN 0x4000
336#define QIB_S_WAIT_ACK 0x8000
337#define QIB_S_SEND_ONE 0x10000
338#define QIB_S_UNLIMITED_CREDIT 0x20000
339
340/*
341 * Wait flags that would prevent any packet type from being sent.
342 */
343#define QIB_S_ANY_WAIT_IO (QIB_S_WAIT_PIO | QIB_S_WAIT_TX | \
344 QIB_S_WAIT_DMA_DESC | QIB_S_WAIT_KMEM)
345
346/*
347 * Wait flags that would prevent send work requests from making progress.
348 */
349#define QIB_S_ANY_WAIT_SEND (QIB_S_WAIT_FENCE | QIB_S_WAIT_RDMAR | \
350 QIB_S_WAIT_RNR | QIB_S_WAIT_SSN_CREDIT | QIB_S_WAIT_DMA | \
351 QIB_S_WAIT_PSN | QIB_S_WAIT_ACK)
352
353#define QIB_S_ANY_WAIT (QIB_S_ANY_WAIT_IO | QIB_S_ANY_WAIT_SEND)
354
355#define QIB_PSN_CREDIT 16
356
357/*
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800358 * Since struct rvt_swqe is not a fixed size, we can't simply index into
359 * struct rvt_qp.s_wq. This function does the array index computation.
Ralph Campbellf9315512010-05-23 21:44:54 -0700360 */
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800361static inline struct rvt_swqe *get_swqe_ptr(struct rvt_qp *qp,
362 unsigned n)
Ralph Campbellf9315512010-05-23 21:44:54 -0700363{
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800364 return (struct rvt_swqe *)((char *)qp->s_wq +
365 (sizeof(struct rvt_swqe) +
Ralph Campbellf9315512010-05-23 21:44:54 -0700366 qp->s_max_sge *
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800367 sizeof(struct rvt_sge)) * n);
Ralph Campbellf9315512010-05-23 21:44:54 -0700368}
369
370/*
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800371 * Since struct rvt_rwqe is not a fixed size, we can't simply index into
372 * struct rvt_rwq.wq. This function does the array index computation.
Ralph Campbellf9315512010-05-23 21:44:54 -0700373 */
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800374static inline struct rvt_rwqe *get_rwqe_ptr(struct rvt_rq *rq, unsigned n)
Ralph Campbellf9315512010-05-23 21:44:54 -0700375{
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800376 return (struct rvt_rwqe *)
Ralph Campbellf9315512010-05-23 21:44:54 -0700377 ((char *) rq->wq->wq +
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800378 (sizeof(struct rvt_rwqe) +
Ralph Campbellf9315512010-05-23 21:44:54 -0700379 rq->max_sge * sizeof(struct ib_sge)) * n);
380}
381
382/*
383 * QPN-map pages start out as NULL, they get allocated upon
384 * first use and are never deallocated. This way,
385 * large bitmaps are not allocated unless large numbers of QPs are used.
386 */
387struct qpn_map {
388 void *page;
389};
390
391struct qib_qpn_table {
392 spinlock_t lock; /* protect changes in this struct */
393 unsigned flags; /* flags for QP0/1 allocated for each port */
394 u32 last; /* last QP number allocated */
395 u32 nmaps; /* size of the map table */
396 u16 limit;
397 u16 mask;
398 /* bit map of free QP numbers other than 0/1 */
399 struct qpn_map map[QPNMAP_ENTRIES];
400};
401
Ralph Campbellf9315512010-05-23 21:44:54 -0700402struct qib_opcode_stats {
403 u64 n_packets; /* number of packets */
404 u64 n_bytes; /* total number of bytes */
405};
406
Mike Marciniszynddb88762013-06-15 17:07:03 -0400407struct qib_opcode_stats_perctx {
408 struct qib_opcode_stats stats[128];
409};
410
Mike Marciniszyn7d7632a2014-03-07 08:40:55 -0500411struct qib_pma_counters {
412 u64 n_unicast_xmit; /* total unicast packets sent */
413 u64 n_unicast_rcv; /* total unicast packets received */
414 u64 n_multicast_xmit; /* total multicast packets sent */
415 u64 n_multicast_rcv; /* total multicast packets received */
416};
417
Ralph Campbellf9315512010-05-23 21:44:54 -0700418struct qib_ibport {
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800419 struct rvt_qp __rcu *qp0;
420 struct rvt_qp __rcu *qp1;
Ralph Campbellf9315512010-05-23 21:44:54 -0700421 struct ib_mad_agent *send_agent; /* agent for SMI (traps) */
422 struct qib_ah *sm_ah;
423 struct qib_ah *smi_ah;
424 struct rb_root mcast_tree;
425 spinlock_t lock; /* protect changes in this struct */
426
427 /* non-zero when timer is set */
428 unsigned long mkey_lease_timeout;
429 unsigned long trap_timeout;
430 __be64 gid_prefix; /* in network order */
431 __be64 mkey;
432 __be64 guids[QIB_GUIDS_PER_PORT - 1]; /* writable GUIDs */
433 u64 tid; /* TID for traps */
Mike Marciniszyn7d7632a2014-03-07 08:40:55 -0500434 struct qib_pma_counters __percpu *pmastats;
435 u64 z_unicast_xmit; /* starting count for PMA */
436 u64 z_unicast_rcv; /* starting count for PMA */
437 u64 z_multicast_xmit; /* starting count for PMA */
438 u64 z_multicast_rcv; /* starting count for PMA */
Ralph Campbellf9315512010-05-23 21:44:54 -0700439 u64 z_symbol_error_counter; /* starting count for PMA */
440 u64 z_link_error_recovery_counter; /* starting count for PMA */
441 u64 z_link_downed_counter; /* starting count for PMA */
442 u64 z_port_rcv_errors; /* starting count for PMA */
443 u64 z_port_rcv_remphys_errors; /* starting count for PMA */
444 u64 z_port_xmit_discards; /* starting count for PMA */
445 u64 z_port_xmit_data; /* starting count for PMA */
446 u64 z_port_rcv_data; /* starting count for PMA */
447 u64 z_port_xmit_packets; /* starting count for PMA */
448 u64 z_port_rcv_packets; /* starting count for PMA */
449 u32 z_local_link_integrity_errors; /* starting count for PMA */
450 u32 z_excessive_buffer_overrun_errors; /* starting count for PMA */
451 u32 z_vl15_dropped; /* starting count for PMA */
452 u32 n_rc_resends;
453 u32 n_rc_acks;
454 u32 n_rc_qacks;
455 u32 n_rc_delayed_comp;
456 u32 n_seq_naks;
457 u32 n_rdma_seq;
458 u32 n_rnr_naks;
459 u32 n_other_naks;
460 u32 n_loop_pkts;
461 u32 n_pkt_drops;
462 u32 n_vl15_dropped;
463 u32 n_rc_timeouts;
464 u32 n_dmawait;
465 u32 n_unaligned;
466 u32 n_rc_dupreq;
467 u32 n_rc_seqnak;
468 u32 port_cap_flags;
469 u32 pma_sample_start;
470 u32 pma_sample_interval;
471 __be16 pma_counter_select[5];
472 u16 pma_tag;
473 u16 pkey_violations;
474 u16 qkey_violations;
475 u16 mkey_violations;
476 u16 mkey_lease_period;
477 u16 sm_lid;
478 u16 repress_traps;
479 u8 sm_sl;
480 u8 mkeyprot;
481 u8 subnet_timeout;
482 u8 vl_high_limit;
483 u8 sl_to_vl[16];
484
Ralph Campbellf9315512010-05-23 21:44:54 -0700485};
486
Mike Marciniszyn551ace12012-07-19 13:03:56 +0000487
Ralph Campbellf9315512010-05-23 21:44:54 -0700488struct qib_ibdev {
Dennis Dalessandro2dc05ab2016-01-22 12:44:29 -0800489 struct rvt_dev_info rdi;
Ralph Campbellf9315512010-05-23 21:44:54 -0700490 struct list_head pending_mmaps;
491 spinlock_t mmap_offset_lock; /* protect mmap_offset */
492 u32 mmap_offset;
Ralph Campbellf9315512010-05-23 21:44:54 -0700493
494 /* QP numbers are shared by all IB ports */
495 struct qib_qpn_table qpn_table;
Ralph Campbellf9315512010-05-23 21:44:54 -0700496 struct list_head piowait; /* list for wait PIO buf */
497 struct list_head dmawait; /* list for wait DMA */
498 struct list_head txwait; /* list for wait qib_verbs_txreq */
499 struct list_head memwait; /* list for wait kernel memory */
500 struct list_head txreq_free;
501 struct timer_list mem_timer;
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800502 struct rvt_qp __rcu **qp_table;
Ralph Campbellf9315512010-05-23 21:44:54 -0700503 struct qib_pio_header *pio_hdrs;
504 dma_addr_t pio_hdrs_phys;
505 /* list of QPs waiting for RNR timer */
506 spinlock_t pending_lock; /* protect wait lists, PMA counters, etc. */
Mike Marciniszynaf061a62011-09-23 13:16:44 -0400507 u32 qp_table_size; /* size of the hash table */
508 u32 qp_rnd; /* random bytes for hash */
Ralph Campbellf9315512010-05-23 21:44:54 -0700509 spinlock_t qpt_lock;
510
511 u32 n_piowait;
512 u32 n_txwait;
513
514 u32 n_pds_allocated; /* number of PDs allocated for device */
515 spinlock_t n_pds_lock;
516 u32 n_ahs_allocated; /* number of AHs allocated for device */
517 spinlock_t n_ahs_lock;
518 u32 n_cqs_allocated; /* number of CQs allocated for device */
519 spinlock_t n_cqs_lock;
520 u32 n_qps_allocated; /* number of QPs allocated for device */
521 spinlock_t n_qps_lock;
522 u32 n_srqs_allocated; /* number of SRQs allocated for device */
523 spinlock_t n_srqs_lock;
524 u32 n_mcast_grps_allocated; /* number of mcast groups allocated */
525 spinlock_t n_mcast_grps_lock;
Mike Marciniszynddb88762013-06-15 17:07:03 -0400526#ifdef CONFIG_DEBUG_FS
527 /* per HCA debugfs */
528 struct dentry *qib_ibdev_dbg;
529#endif
Ralph Campbellf9315512010-05-23 21:44:54 -0700530};
531
532struct qib_verbs_counters {
533 u64 symbol_error_counter;
534 u64 link_error_recovery_counter;
535 u64 link_downed_counter;
536 u64 port_rcv_errors;
537 u64 port_rcv_remphys_errors;
538 u64 port_xmit_discards;
539 u64 port_xmit_data;
540 u64 port_rcv_data;
541 u64 port_xmit_packets;
542 u64 port_rcv_packets;
543 u32 local_link_integrity_errors;
544 u32 excessive_buffer_overrun_errors;
545 u32 vl15_dropped;
546};
547
Ralph Campbellf9315512010-05-23 21:44:54 -0700548static inline struct qib_ah *to_iah(struct ib_ah *ibah)
549{
550 return container_of(ibah, struct qib_ah, ibah);
551}
552
553static inline struct qib_cq *to_icq(struct ib_cq *ibcq)
554{
555 return container_of(ibcq, struct qib_cq, ibcq);
556}
557
558static inline struct qib_srq *to_isrq(struct ib_srq *ibsrq)
559{
560 return container_of(ibsrq, struct qib_srq, ibsrq);
561}
562
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800563static inline struct rvt_qp *to_iqp(struct ib_qp *ibqp)
Ralph Campbellf9315512010-05-23 21:44:54 -0700564{
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800565 return container_of(ibqp, struct rvt_qp, ibqp);
Ralph Campbellf9315512010-05-23 21:44:54 -0700566}
567
568static inline struct qib_ibdev *to_idev(struct ib_device *ibdev)
569{
Dennis Dalessandro2dc05ab2016-01-22 12:44:29 -0800570 struct rvt_dev_info *rdi;
571
572 rdi = container_of(ibdev, struct rvt_dev_info, ibdev);
573 return container_of(rdi, struct qib_ibdev, rdi);
Ralph Campbellf9315512010-05-23 21:44:54 -0700574}
575
576/*
577 * Send if not busy or waiting for I/O and either
578 * a RC response is pending or we can process send work requests.
579 */
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800580static inline int qib_send_ok(struct rvt_qp *qp)
Ralph Campbellf9315512010-05-23 21:44:54 -0700581{
582 return !(qp->s_flags & (QIB_S_BUSY | QIB_S_ANY_WAIT_IO)) &&
583 (qp->s_hdrwords || (qp->s_flags & QIB_S_RESP_PENDING) ||
584 !(qp->s_flags & QIB_S_ANY_WAIT_SEND));
585}
586
Ralph Campbellf9315512010-05-23 21:44:54 -0700587/*
588 * This must be called with s_lock held.
589 */
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800590void qib_schedule_send(struct rvt_qp *qp);
Ralph Campbellf9315512010-05-23 21:44:54 -0700591
592static inline int qib_pkey_ok(u16 pkey1, u16 pkey2)
593{
594 u16 p1 = pkey1 & 0x7FFF;
595 u16 p2 = pkey2 & 0x7FFF;
596
597 /*
598 * Low 15 bits must be non-zero and match, and
599 * one of the two must be a full member.
600 */
601 return p1 && p1 == p2 && ((__s16)pkey1 < 0 || (__s16)pkey2 < 0);
602}
603
604void qib_bad_pqkey(struct qib_ibport *ibp, __be16 trap_num, u32 key, u32 sl,
605 u32 qp1, u32 qp2, __be16 lid1, __be16 lid2);
606void qib_cap_mask_chg(struct qib_ibport *ibp);
607void qib_sys_guid_chg(struct qib_ibport *ibp);
608void qib_node_desc_chg(struct qib_ibport *ibp);
609int qib_process_mad(struct ib_device *ibdev, int mad_flags, u8 port_num,
Ira Weinya97e2d82015-05-31 17:15:30 -0400610 const struct ib_wc *in_wc, const struct ib_grh *in_grh,
Ira Weiny4cd7c942015-06-06 14:38:31 -0400611 const struct ib_mad_hdr *in, size_t in_mad_size,
612 struct ib_mad_hdr *out, size_t *out_mad_size,
613 u16 *out_mad_pkey_index);
Ralph Campbellf9315512010-05-23 21:44:54 -0700614int qib_create_agents(struct qib_ibdev *dev);
615void qib_free_agents(struct qib_ibdev *dev);
616
617/*
618 * Compare the lower 24 bits of the two values.
619 * Returns an integer <, ==, or > than zero.
620 */
621static inline int qib_cmp24(u32 a, u32 b)
622{
623 return (((int) a) - ((int) b)) << 8;
624}
625
626struct qib_mcast *qib_mcast_find(struct qib_ibport *ibp, union ib_gid *mgid);
627
628int qib_snapshot_counters(struct qib_pportdata *ppd, u64 *swords,
629 u64 *rwords, u64 *spkts, u64 *rpkts,
630 u64 *xmit_wait);
631
632int qib_get_counters(struct qib_pportdata *ppd,
633 struct qib_verbs_counters *cntrs);
634
635int qib_multicast_attach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid);
636
637int qib_multicast_detach(struct ib_qp *ibqp, union ib_gid *gid, u16 lid);
638
639int qib_mcast_tree_empty(struct qib_ibport *ibp);
640
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800641__be32 qib_compute_aeth(struct rvt_qp *qp);
Ralph Campbellf9315512010-05-23 21:44:54 -0700642
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800643struct rvt_qp *qib_lookup_qpn(struct qib_ibport *ibp, u32 qpn);
Ralph Campbellf9315512010-05-23 21:44:54 -0700644
645struct ib_qp *qib_create_qp(struct ib_pd *ibpd,
646 struct ib_qp_init_attr *init_attr,
647 struct ib_udata *udata);
648
649int qib_destroy_qp(struct ib_qp *ibqp);
650
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800651int qib_error_qp(struct rvt_qp *qp, enum ib_wc_status err);
Ralph Campbellf9315512010-05-23 21:44:54 -0700652
653int qib_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr,
654 int attr_mask, struct ib_udata *udata);
655
656int qib_query_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr,
657 int attr_mask, struct ib_qp_init_attr *init_attr);
658
659unsigned qib_free_all_qps(struct qib_devdata *dd);
660
661void qib_init_qpn_table(struct qib_devdata *dd, struct qib_qpn_table *qpt);
662
663void qib_free_qpn_table(struct qib_qpn_table *qpt);
664
Mike Marciniszyn1dd173b2013-06-15 17:07:14 -0400665#ifdef CONFIG_DEBUG_FS
666
667struct qib_qp_iter;
668
669struct qib_qp_iter *qib_qp_iter_init(struct qib_ibdev *dev);
670
671int qib_qp_iter_next(struct qib_qp_iter *iter);
672
673void qib_qp_iter_print(struct seq_file *s, struct qib_qp_iter *iter);
674
675#endif
676
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800677void qib_get_credit(struct rvt_qp *qp, u32 aeth);
Ralph Campbellf9315512010-05-23 21:44:54 -0700678
679unsigned qib_pkt_delay(u32 plen, u8 snd_mult, u8 rcv_mult);
680
681void qib_verbs_sdma_desc_avail(struct qib_pportdata *ppd, unsigned avail);
682
683void qib_put_txreq(struct qib_verbs_txreq *tx);
684
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800685int qib_verbs_send(struct rvt_qp *qp, struct qib_ib_header *hdr,
686 u32 hdrwords, struct rvt_sge_state *ss, u32 len);
Ralph Campbellf9315512010-05-23 21:44:54 -0700687
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800688void qib_copy_sge(struct rvt_sge_state *ss, void *data, u32 length,
Ralph Campbellf9315512010-05-23 21:44:54 -0700689 int release);
690
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800691void qib_skip_sge(struct rvt_sge_state *ss, u32 length, int release);
Ralph Campbellf9315512010-05-23 21:44:54 -0700692
693void qib_uc_rcv(struct qib_ibport *ibp, struct qib_ib_header *hdr,
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800694 int has_grh, void *data, u32 tlen, struct rvt_qp *qp);
Ralph Campbellf9315512010-05-23 21:44:54 -0700695
696void qib_rc_rcv(struct qib_ctxtdata *rcd, struct qib_ib_header *hdr,
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800697 int has_grh, void *data, u32 tlen, struct rvt_qp *qp);
Ralph Campbellf9315512010-05-23 21:44:54 -0700698
699int qib_check_ah(struct ib_device *ibdev, struct ib_ah_attr *ah_attr);
700
Mike Marciniszyn1fb9fed2012-07-16 17:11:06 +0000701struct ib_ah *qib_create_qp0_ah(struct qib_ibport *ibp, u16 dlid);
702
Ralph Campbellf9315512010-05-23 21:44:54 -0700703void qib_rc_rnr_retry(unsigned long arg);
704
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800705void qib_rc_send_complete(struct rvt_qp *qp, struct qib_ib_header *hdr);
Ralph Campbellf9315512010-05-23 21:44:54 -0700706
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800707void qib_rc_error(struct rvt_qp *qp, enum ib_wc_status err);
Ralph Campbellf9315512010-05-23 21:44:54 -0700708
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800709int qib_post_ud_send(struct rvt_qp *qp, struct ib_send_wr *wr);
Ralph Campbellf9315512010-05-23 21:44:54 -0700710
711void qib_ud_rcv(struct qib_ibport *ibp, struct qib_ib_header *hdr,
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800712 int has_grh, void *data, u32 tlen, struct rvt_qp *qp);
Ralph Campbellf9315512010-05-23 21:44:54 -0700713
714int qib_post_srq_receive(struct ib_srq *ibsrq, struct ib_recv_wr *wr,
715 struct ib_recv_wr **bad_wr);
716
717struct ib_srq *qib_create_srq(struct ib_pd *ibpd,
718 struct ib_srq_init_attr *srq_init_attr,
719 struct ib_udata *udata);
720
721int qib_modify_srq(struct ib_srq *ibsrq, struct ib_srq_attr *attr,
722 enum ib_srq_attr_mask attr_mask,
723 struct ib_udata *udata);
724
725int qib_query_srq(struct ib_srq *ibsrq, struct ib_srq_attr *attr);
726
727int qib_destroy_srq(struct ib_srq *ibsrq);
728
Mike Marciniszyn85caafe2013-06-04 15:05:37 -0400729int qib_cq_init(struct qib_devdata *dd);
730
731void qib_cq_exit(struct qib_devdata *dd);
732
Ralph Campbellf9315512010-05-23 21:44:54 -0700733void qib_cq_enter(struct qib_cq *cq, struct ib_wc *entry, int sig);
734
735int qib_poll_cq(struct ib_cq *ibcq, int num_entries, struct ib_wc *entry);
736
Matan Barakbcf4c1e2015-06-11 16:35:20 +0300737struct ib_cq *qib_create_cq(struct ib_device *ibdev,
738 const struct ib_cq_init_attr *attr,
739 struct ib_ucontext *context,
Ralph Campbellf9315512010-05-23 21:44:54 -0700740 struct ib_udata *udata);
741
742int qib_destroy_cq(struct ib_cq *ibcq);
743
744int qib_req_notify_cq(struct ib_cq *ibcq, enum ib_cq_notify_flags notify_flags);
745
746int qib_resize_cq(struct ib_cq *ibcq, int cqe, struct ib_udata *udata);
747
Mike Marciniszyn8aac4cc2012-06-27 18:33:19 -0400748void mr_rcu_callback(struct rcu_head *list);
749
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800750static inline void qib_put_ss(struct rvt_sge_state *ss)
Mike Marciniszyn6a826492012-06-27 18:33:12 -0400751{
752 while (ss->num_sge) {
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800753 rvt_put_mr(ss->sge.mr);
Mike Marciniszyn6a826492012-06-27 18:33:12 -0400754 if (--ss->num_sge)
755 ss->sge = *ss->sg_list++;
756 }
757}
758
Ralph Campbellf9315512010-05-23 21:44:54 -0700759void qib_release_mmap_info(struct kref *ref);
760
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800761struct rvt_mmap_info *qib_create_mmap_info(struct qib_ibdev *dev, u32 size,
Ralph Campbellf9315512010-05-23 21:44:54 -0700762 struct ib_ucontext *context,
763 void *obj);
764
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800765void qib_update_mmap_info(struct qib_ibdev *dev, struct rvt_mmap_info *ip,
Ralph Campbellf9315512010-05-23 21:44:54 -0700766 u32 size, void *obj);
767
768int qib_mmap(struct ib_ucontext *context, struct vm_area_struct *vma);
769
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800770int qib_get_rwqe(struct rvt_qp *qp, int wr_id_only);
Ralph Campbellf9315512010-05-23 21:44:54 -0700771
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800772void qib_migrate_qp(struct rvt_qp *qp);
Ralph Campbellf9315512010-05-23 21:44:54 -0700773
774int qib_ruc_check_hdr(struct qib_ibport *ibp, struct qib_ib_header *hdr,
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800775 int has_grh, struct rvt_qp *qp, u32 bth0);
Ralph Campbellf9315512010-05-23 21:44:54 -0700776
777u32 qib_make_grh(struct qib_ibport *ibp, struct ib_grh *hdr,
778 struct ib_global_route *grh, u32 hwords, u32 nwords);
779
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800780void qib_make_ruc_header(struct rvt_qp *qp, struct qib_other_headers *ohdr,
Ralph Campbellf9315512010-05-23 21:44:54 -0700781 u32 bth0, u32 bth2);
782
783void qib_do_send(struct work_struct *work);
784
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800785void qib_send_complete(struct rvt_qp *qp, struct rvt_swqe *wqe,
Ralph Campbellf9315512010-05-23 21:44:54 -0700786 enum ib_wc_status status);
787
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800788void qib_send_rc_ack(struct rvt_qp *qp);
Ralph Campbellf9315512010-05-23 21:44:54 -0700789
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800790int qib_make_rc_req(struct rvt_qp *qp);
Ralph Campbellf9315512010-05-23 21:44:54 -0700791
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800792int qib_make_uc_req(struct rvt_qp *qp);
Ralph Campbellf9315512010-05-23 21:44:54 -0700793
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800794int qib_make_ud_req(struct rvt_qp *qp);
Ralph Campbellf9315512010-05-23 21:44:54 -0700795
796int qib_register_ib_device(struct qib_devdata *);
797
798void qib_unregister_ib_device(struct qib_devdata *);
799
800void qib_ib_rcv(struct qib_ctxtdata *, void *, void *, u32);
801
802void qib_ib_piobufavail(struct qib_devdata *);
803
804unsigned qib_get_npkeys(struct qib_devdata *);
805
806unsigned qib_get_pkey(struct qib_ibport *, unsigned);
807
808extern const enum ib_wc_opcode ib_qib_wc_opcode[];
809
810/*
811 * Below HCA-independent IB PhysPortState values, returned
812 * by the f_ibphys_portstate() routine.
813 */
814#define IB_PHYSPORTSTATE_SLEEP 1
815#define IB_PHYSPORTSTATE_POLL 2
816#define IB_PHYSPORTSTATE_DISABLED 3
817#define IB_PHYSPORTSTATE_CFG_TRAIN 4
818#define IB_PHYSPORTSTATE_LINKUP 5
819#define IB_PHYSPORTSTATE_LINK_ERR_RECOVER 6
820#define IB_PHYSPORTSTATE_CFG_DEBOUNCE 8
821#define IB_PHYSPORTSTATE_CFG_IDLE 0xB
822#define IB_PHYSPORTSTATE_RECOVERY_RETRAIN 0xC
823#define IB_PHYSPORTSTATE_RECOVERY_WAITRMT 0xE
824#define IB_PHYSPORTSTATE_RECOVERY_IDLE 0xF
825#define IB_PHYSPORTSTATE_CFG_ENH 0x10
826#define IB_PHYSPORTSTATE_CFG_WAIT_ENH 0x13
827
828extern const int ib_qib_state_ops[];
829
830extern __be64 ib_qib_sys_image_guid; /* in network order */
831
Dennis Dalessandro7c2e11f2016-01-22 12:45:59 -0800832extern unsigned int ib_rvt_lkey_table_size;
Ralph Campbellf9315512010-05-23 21:44:54 -0700833
834extern unsigned int ib_qib_max_cqes;
835
836extern unsigned int ib_qib_max_cqs;
837
838extern unsigned int ib_qib_max_qp_wrs;
839
840extern unsigned int ib_qib_max_qps;
841
842extern unsigned int ib_qib_max_sges;
843
844extern unsigned int ib_qib_max_mcast_grps;
845
846extern unsigned int ib_qib_max_mcast_qp_attached;
847
848extern unsigned int ib_qib_max_srqs;
849
850extern unsigned int ib_qib_max_srq_sges;
851
852extern unsigned int ib_qib_max_srq_wrs;
853
854extern const u32 ib_qib_rnr_table[];
855
Ralph Campbellf9315512010-05-23 21:44:54 -0700856#endif /* QIB_VERBS_H */