2 * Copyright (c) 2012, 2013 Intel Corporation. All rights reserved.
3 * Copyright (c) 2006 - 2012 QLogic Corporation. All rights reserved.
4 * Copyright (c) 2005, 2006 PathScale, Inc. All rights reserved.
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:
12 * Redistribution and use in source and binary forms, with or
13 * without modification, are permitted provided that the following
16 * - Redistributions of source code must retain the above
17 * copyright notice, this list of conditions and the following
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.
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
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>
44 #include <linux/kthread.h>
45 #include <linux/completion.h>
46 #include <rdma/ib_pack.h>
47 #include <rdma/ib_user_verbs.h>
52 struct qib_verbs_txreq
;
54 #define QIB_MAX_RDMA_ATOMIC 16
55 #define QIB_GUIDS_PER_PORT 5
57 #define QPN_MAX (1 << 24)
58 #define QPNMAP_ENTRIES (QPN_MAX / PAGE_SIZE / BITS_PER_BYTE)
61 * Increment this value if any changes that break userspace ABI
62 * compatibility are made.
64 #define QIB_UVERBS_ABI_VERSION 2
67 * Define an ib_cq_notify value that is not valid so we know when CQ
68 * notifications are armed.
70 #define IB_CQ_NONE (IB_CQ_NEXT_COMP + 1)
72 #define IB_SEQ_NAK (3 << 29)
74 /* AETH NAK opcode values */
75 #define IB_RNR_NAK 0x20
76 #define IB_NAK_PSN_ERROR 0x60
77 #define IB_NAK_INVALID_REQUEST 0x61
78 #define IB_NAK_REMOTE_ACCESS_ERROR 0x62
79 #define IB_NAK_REMOTE_OPERATIONAL_ERROR 0x63
80 #define IB_NAK_INVALID_RD_REQUEST 0x64
82 /* Flags for checking QP state (see ib_qib_state_ops[]) */
83 #define QIB_POST_SEND_OK 0x01
84 #define QIB_POST_RECV_OK 0x02
85 #define QIB_PROCESS_RECV_OK 0x04
86 #define QIB_PROCESS_SEND_OK 0x08
87 #define QIB_PROCESS_NEXT_SEND_OK 0x10
88 #define QIB_FLUSH_SEND 0x20
89 #define QIB_FLUSH_RECV 0x40
90 #define QIB_PROCESS_OR_FLUSH_SEND \
91 (QIB_PROCESS_SEND_OK | QIB_FLUSH_SEND)
93 /* IB Performance Manager status values */
94 #define IB_PMA_SAMPLE_STATUS_DONE 0x00
95 #define IB_PMA_SAMPLE_STATUS_STARTED 0x01
96 #define IB_PMA_SAMPLE_STATUS_RUNNING 0x02
98 /* Mandatory IB performance counter select values. */
99 #define IB_PMA_PORT_XMIT_DATA cpu_to_be16(0x0001)
100 #define IB_PMA_PORT_RCV_DATA cpu_to_be16(0x0002)
101 #define IB_PMA_PORT_XMIT_PKTS cpu_to_be16(0x0003)
102 #define IB_PMA_PORT_RCV_PKTS cpu_to_be16(0x0004)
103 #define IB_PMA_PORT_XMIT_WAIT cpu_to_be16(0x0005)
105 #define QIB_VENDOR_IPG cpu_to_be16(0xFFA0)
107 #define IB_BTH_REQ_ACK (1 << 31)
108 #define IB_BTH_SOLICITED (1 << 23)
109 #define IB_BTH_MIG_REQ (1 << 22)
111 /* XXX Should be defined in ib_verbs.h enum ib_port_cap_flags */
112 #define IB_PORT_OTHER_LOCAL_CHANGES_SUP (1 << 26)
114 #define IB_GRH_VERSION 6
115 #define IB_GRH_VERSION_MASK 0xF
116 #define IB_GRH_VERSION_SHIFT 28
117 #define IB_GRH_TCLASS_MASK 0xFF
118 #define IB_GRH_TCLASS_SHIFT 20
119 #define IB_GRH_FLOW_MASK 0xFFFFF
120 #define IB_GRH_FLOW_SHIFT 0
121 #define IB_GRH_NEXT_HDR 0x1B
123 #define IB_DEFAULT_GID_PREFIX cpu_to_be64(0xfe80000000000000ULL)
125 /* Values for set/get portinfo VLCap OperationalVLs */
127 #define IB_VL_VL0_1 2
128 #define IB_VL_VL0_3 3
129 #define IB_VL_VL0_7 4
130 #define IB_VL_VL0_14 5
132 static inline int qib_num_vls(int vls
)
155 struct ib_atomic_eth
{
156 __be32 vaddr
[2]; /* unaligned so access as 2 32-bit words */
162 struct qib_other_headers
{
175 __be32 atomic_ack_eth
[2];
179 struct ib_atomic_eth atomic_eth
;
184 * Note that UD packets with a GRH header are 8+40+12+8 = 68 bytes
185 * long (72 w/ imm_data). Only the first 56 bytes of the IB header
186 * will be in the eager header buffer. The remaining 12 or 16 bytes
187 * are in the data buffer.
189 struct qib_ib_header
{
194 struct qib_other_headers oth
;
196 struct qib_other_headers oth
;
200 struct qib_pio_header
{
202 struct qib_ib_header hdr
;
206 * There is one struct qib_mcast for each multicast GID.
207 * All attached QPs are then stored as a list of
208 * struct qib_mcast_qp.
210 struct qib_mcast_qp
{
211 struct list_head list
;
216 struct rb_node rb_node
;
218 struct list_head qp_list
;
219 wait_queue_head_t wait
;
224 /* Protection domain */
227 int user
; /* non-zero if created from user space */
233 struct ib_ah_attr attr
;
238 * This structure is used by qib_mmap() to validate an offset
239 * when an mmap() request is made. The vm_area_struct then uses
240 * this as its vm_private_data.
242 struct qib_mmap_info
{
243 struct list_head pending_mmaps
;
244 struct ib_ucontext
*context
;
252 * This structure is used to contain the head pointer, tail pointer,
253 * and completion queue entries as a single memory allocation so
254 * it can be mmap'ed into user space.
257 u32 head
; /* index of next entry to fill */
258 u32 tail
; /* index of next ib_poll_cq() entry */
260 /* these are actually size ibcq.cqe + 1 */
261 struct ib_uverbs_wc uqueue
[0];
262 struct ib_wc kqueue
[0];
267 * The completion queue structure.
271 struct kthread_work comptask
;
272 struct qib_devdata
*dd
;
273 spinlock_t lock
; /* protect changes in this struct */
276 struct qib_cq_wc
*queue
;
277 struct qib_mmap_info
*ip
;
281 * A segment is a linear region of low physical memory.
282 * XXX Maybe we should use phys addr here and kmap()/kunmap().
283 * Used by the verbs layer.
290 /* The number of qib_segs that fit in a page. */
291 #define QIB_SEGSZ (PAGE_SIZE / sizeof(struct qib_seg))
293 struct qib_segarray
{
294 struct qib_seg segs
[QIB_SEGSZ
];
298 struct ib_pd
*pd
; /* shares refcnt of ibmr.pd */
299 u64 user_base
; /* User's address for this region */
300 u64 iova
; /* IB start address of this region */
303 u32 offset
; /* offset (bytes) to start of region */
305 u32 max_segs
; /* number of qib_segs in all the arrays */
306 u32 mapsz
; /* size of the map array */
307 u8 page_shift
; /* 0 - non unform/non powerof2 sizes */
308 u8 lkey_published
; /* in global table */
309 struct completion comp
; /* complete when refcount goes to zero */
310 struct rcu_head list
;
312 struct qib_segarray
*map
[0]; /* the segments */
316 * These keep track of the copy progress within a memory region.
317 * Used by the verbs layer.
320 struct qib_mregion
*mr
;
321 void *vaddr
; /* kernel virtual address of segment */
322 u32 sge_length
; /* length of the SGE */
323 u32 length
; /* remaining length of the segment */
324 u16 m
; /* current index: mr->map[m] */
325 u16 n
; /* current index: mr->map[m]->segs[n] */
331 struct ib_umem
*umem
;
332 struct qib_mregion mr
; /* must be last */
336 * Send work request queue entry.
337 * The size of the sg_list is determined when the QP is created and stored
342 struct ib_send_wr wr
; /* don't use wr.sg_list */
343 struct ib_ud_wr ud_wr
;
344 struct ib_fast_reg_wr fast_reg_wr
;
345 struct ib_rdma_wr rdma_wr
;
346 struct ib_atomic_wr atomic_wr
;
348 u32 psn
; /* first packet sequence number */
349 u32 lpsn
; /* last packet sequence number */
350 u32 ssn
; /* send sequence number */
351 u32 length
; /* total length of data in sg_list */
352 struct qib_sge sg_list
[0];
356 * Receive work request queue entry.
357 * The size of the sg_list is determined when the QP (or SRQ) is created
358 * and stored in qp->r_rq.max_sge (or srq->rq.max_sge).
363 struct ib_sge sg_list
[0];
367 * This structure is used to contain the head pointer, tail pointer,
368 * and receive work queue entries as a single memory allocation so
369 * it can be mmap'ed into user space.
370 * Note that the wq array elements are variable size so you can't
371 * just index into the array to get the N'th element;
372 * use get_rwqe_ptr() instead.
375 u32 head
; /* new work requests posted to the head */
376 u32 tail
; /* receives pull requests from here. */
377 struct qib_rwqe wq
[0];
382 u32 size
; /* size of RWQE array */
384 spinlock_t lock
/* protect changes in this struct */
385 ____cacheline_aligned_in_smp
;
391 struct qib_mmap_info
*ip
;
392 /* send signal when number of RWQEs < limit */
396 struct qib_sge_state
{
397 struct qib_sge
*sg_list
; /* next SGE to be used if any */
398 struct qib_sge sge
; /* progress state for the current SGE */
404 * This structure holds the information that the send tasklet needs
405 * to send a RDMA read response or atomic operation.
407 struct qib_ack_entry
{
413 struct qib_sge rdma_sge
;
419 * Variables prefixed with s_ are for the requester (sender).
420 * Variables prefixed with r_ are for the responder (receiver).
421 * Variables prefixed with ack_ are for responder replies.
423 * Common variables are protected by both r_rq.lock and s_lock in that order
424 * which only happens in modify_qp() or changing the QP 'state'.
428 /* read mostly fields above and below */
429 struct ib_ah_attr remote_ah_attr
;
430 struct ib_ah_attr alt_ah_attr
;
431 struct qib_qp __rcu
*next
; /* link list for QPN hash table */
432 struct qib_swqe
*s_wq
; /* send work queue */
433 struct qib_mmap_info
*ip
;
434 struct qib_ib_header
*s_hdr
; /* next packet header to send */
435 unsigned long timeout_jiffies
; /* computed from timeout */
437 enum ib_mtu path_mtu
;
439 u32 pmtu
; /* decoded from path_mtu */
440 u32 qkey
; /* QKEY for this QP (for UD or RD) */
441 u32 s_size
; /* send work queue size */
442 u32 s_rnr_timeout
; /* number of milliseconds for RNR timeout */
444 u8 state
; /* QP state */
446 u8 alt_timeout
; /* Alternate path timeout for this QP */
447 u8 timeout
; /* Timeout for this QP */
451 u8 s_pkey_index
; /* PKEY index to use */
452 u8 s_alt_pkey_index
; /* Alternate path PKEY index to use */
453 u8 r_max_rd_atomic
; /* max number of RDMA read/atomic to receive */
454 u8 s_max_rd_atomic
; /* max number of RDMA read/atomic to send */
455 u8 s_retry_cnt
; /* number of times to retry */
457 u8 r_min_rnr_timer
; /* retry timeout value for RNR NAKs */
458 u8 s_max_sge
; /* size of s_wq->sg_list */
461 /* start of read/write fields */
463 atomic_t refcount ____cacheline_aligned_in_smp
;
464 wait_queue_head_t wait
;
467 struct qib_ack_entry s_ack_queue
[QIB_MAX_RDMA_ATOMIC
+ 1]
468 ____cacheline_aligned_in_smp
;
469 struct qib_sge_state s_rdma_read_sge
;
471 spinlock_t r_lock ____cacheline_aligned_in_smp
; /* used for APM */
472 unsigned long r_aflags
;
473 u64 r_wr_id
; /* ID for current receive WQE */
474 u32 r_ack_psn
; /* PSN for next ACK or atomic ACK */
475 u32 r_len
; /* total length of r_sge */
476 u32 r_rcv_len
; /* receive data len processed */
477 u32 r_psn
; /* expected rcv packet sequence number */
478 u32 r_msn
; /* message sequence number */
480 u8 r_state
; /* opcode of last packet received */
482 u8 r_head_ack_queue
; /* index into s_ack_queue[] */
484 struct list_head rspwait
; /* link for waititing to respond */
486 struct qib_sge_state r_sge
; /* current receive data */
487 struct qib_rq r_rq
; /* receive work queue */
489 spinlock_t s_lock ____cacheline_aligned_in_smp
;
490 struct qib_sge_state
*s_cur_sge
;
492 struct qib_verbs_txreq
*s_tx
;
493 struct qib_swqe
*s_wqe
;
494 struct qib_sge_state s_sge
; /* current send request data */
495 struct qib_mregion
*s_rdma_mr
;
497 u32 s_cur_size
; /* size of send packet in bytes */
498 u32 s_len
; /* total length of s_sge */
499 u32 s_rdma_read_len
; /* total length of s_rdma_read_sge */
500 u32 s_next_psn
; /* PSN for next request */
501 u32 s_last_psn
; /* last response PSN processed */
502 u32 s_sending_psn
; /* lowest PSN that is being sent */
503 u32 s_sending_hpsn
; /* highest PSN that is being sent */
504 u32 s_psn
; /* current packet sequence number */
505 u32 s_ack_rdma_psn
; /* PSN for sending RDMA read responses */
506 u32 s_ack_psn
; /* PSN for acking sends and RDMA writes */
507 u32 s_head
; /* new entries added here */
508 u32 s_tail
; /* next entry to process */
509 u32 s_cur
; /* current work queue entry */
510 u32 s_acked
; /* last un-ACK'ed entry */
511 u32 s_last
; /* last completed entry */
512 u32 s_ssn
; /* SSN of tail entry */
513 u32 s_lsn
; /* limit sequence number (credit) */
514 u16 s_hdrwords
; /* size of s_hdr in 32 bit words */
516 u8 s_state
; /* opcode of last packet sent */
517 u8 s_ack_state
; /* opcode of packet to ACK */
518 u8 s_nak_state
; /* non-zero if NAK is pending */
519 u8 r_nak_state
; /* non-zero if NAK is pending */
520 u8 s_retry
; /* requester retry counter */
521 u8 s_rnr_retry
; /* requester RNR retry counter */
522 u8 s_num_rd_atomic
; /* number of RDMA read/atomic pending */
523 u8 s_tail_ack_queue
; /* index into s_ack_queue[] */
525 struct qib_sge_state s_ack_rdma_sge
;
526 struct timer_list s_timer
;
527 struct list_head iowait
; /* link for wait PIO buf */
529 struct work_struct s_work
;
531 wait_queue_head_t wait_dma
;
533 struct qib_sge r_sg_list
[0] /* verified SGEs */
534 ____cacheline_aligned_in_smp
;
538 * Atomic bit definitions for r_aflags.
540 #define QIB_R_WRID_VALID 0
541 #define QIB_R_REWIND_SGE 1
544 * Bit definitions for r_flags.
546 #define QIB_R_REUSE_SGE 0x01
547 #define QIB_R_RDMAR_SEQ 0x02
548 #define QIB_R_RSP_NAK 0x04
549 #define QIB_R_RSP_SEND 0x08
550 #define QIB_R_COMM_EST 0x10
553 * Bit definitions for s_flags.
555 * QIB_S_SIGNAL_REQ_WR - set if QP send WRs contain completion signaled
556 * QIB_S_BUSY - send tasklet is processing the QP
557 * QIB_S_TIMER - the RC retry timer is active
558 * QIB_S_ACK_PENDING - an ACK is waiting to be sent after RDMA read/atomics
559 * QIB_S_WAIT_FENCE - waiting for all prior RDMA read or atomic SWQEs
560 * before processing the next SWQE
561 * QIB_S_WAIT_RDMAR - waiting for a RDMA read or atomic SWQE to complete
562 * before processing the next SWQE
563 * QIB_S_WAIT_RNR - waiting for RNR timeout
564 * QIB_S_WAIT_SSN_CREDIT - waiting for RC credits to process next SWQE
565 * QIB_S_WAIT_DMA - waiting for send DMA queue to drain before generating
566 * next send completion entry not via send DMA
567 * QIB_S_WAIT_PIO - waiting for a send buffer to be available
568 * QIB_S_WAIT_TX - waiting for a struct qib_verbs_txreq to be available
569 * QIB_S_WAIT_DMA_DESC - waiting for DMA descriptors to be available
570 * QIB_S_WAIT_KMEM - waiting for kernel memory to be available
571 * QIB_S_WAIT_PSN - waiting for a packet to exit the send DMA queue
572 * QIB_S_WAIT_ACK - waiting for an ACK packet before sending more requests
573 * QIB_S_SEND_ONE - send one packet, request ACK, then wait for ACK
575 #define QIB_S_SIGNAL_REQ_WR 0x0001
576 #define QIB_S_BUSY 0x0002
577 #define QIB_S_TIMER 0x0004
578 #define QIB_S_RESP_PENDING 0x0008
579 #define QIB_S_ACK_PENDING 0x0010
580 #define QIB_S_WAIT_FENCE 0x0020
581 #define QIB_S_WAIT_RDMAR 0x0040
582 #define QIB_S_WAIT_RNR 0x0080
583 #define QIB_S_WAIT_SSN_CREDIT 0x0100
584 #define QIB_S_WAIT_DMA 0x0200
585 #define QIB_S_WAIT_PIO 0x0400
586 #define QIB_S_WAIT_TX 0x0800
587 #define QIB_S_WAIT_DMA_DESC 0x1000
588 #define QIB_S_WAIT_KMEM 0x2000
589 #define QIB_S_WAIT_PSN 0x4000
590 #define QIB_S_WAIT_ACK 0x8000
591 #define QIB_S_SEND_ONE 0x10000
592 #define QIB_S_UNLIMITED_CREDIT 0x20000
595 * Wait flags that would prevent any packet type from being sent.
597 #define QIB_S_ANY_WAIT_IO (QIB_S_WAIT_PIO | QIB_S_WAIT_TX | \
598 QIB_S_WAIT_DMA_DESC | QIB_S_WAIT_KMEM)
601 * Wait flags that would prevent send work requests from making progress.
603 #define QIB_S_ANY_WAIT_SEND (QIB_S_WAIT_FENCE | QIB_S_WAIT_RDMAR | \
604 QIB_S_WAIT_RNR | QIB_S_WAIT_SSN_CREDIT | QIB_S_WAIT_DMA | \
605 QIB_S_WAIT_PSN | QIB_S_WAIT_ACK)
607 #define QIB_S_ANY_WAIT (QIB_S_ANY_WAIT_IO | QIB_S_ANY_WAIT_SEND)
609 #define QIB_PSN_CREDIT 16
612 * Since struct qib_swqe is not a fixed size, we can't simply index into
613 * struct qib_qp.s_wq. This function does the array index computation.
615 static inline struct qib_swqe
*get_swqe_ptr(struct qib_qp
*qp
,
618 return (struct qib_swqe
*)((char *)qp
->s_wq
+
619 (sizeof(struct qib_swqe
) +
621 sizeof(struct qib_sge
)) * n
);
625 * Since struct qib_rwqe is not a fixed size, we can't simply index into
626 * struct qib_rwq.wq. This function does the array index computation.
628 static inline struct qib_rwqe
*get_rwqe_ptr(struct qib_rq
*rq
, unsigned n
)
630 return (struct qib_rwqe
*)
631 ((char *) rq
->wq
->wq
+
632 (sizeof(struct qib_rwqe
) +
633 rq
->max_sge
* sizeof(struct ib_sge
)) * n
);
637 * QPN-map pages start out as NULL, they get allocated upon
638 * first use and are never deallocated. This way,
639 * large bitmaps are not allocated unless large numbers of QPs are used.
645 struct qib_qpn_table
{
646 spinlock_t lock
; /* protect changes in this struct */
647 unsigned flags
; /* flags for QP0/1 allocated for each port */
648 u32 last
; /* last QP number allocated */
649 u32 nmaps
; /* size of the map table */
652 /* bit map of free QP numbers other than 0/1 */
653 struct qpn_map map
[QPNMAP_ENTRIES
];
656 #define MAX_LKEY_TABLE_BITS 23
658 struct qib_lkey_table
{
659 spinlock_t lock
; /* protect changes in this struct */
660 u32 next
; /* next unused index (speeds search) */
661 u32 gen
; /* generation count */
662 u32 max
; /* size of the table */
663 struct qib_mregion __rcu
**table
;
666 struct qib_opcode_stats
{
667 u64 n_packets
; /* number of packets */
668 u64 n_bytes
; /* total number of bytes */
671 struct qib_opcode_stats_perctx
{
672 struct qib_opcode_stats stats
[128];
675 struct qib_pma_counters
{
676 u64 n_unicast_xmit
; /* total unicast packets sent */
677 u64 n_unicast_rcv
; /* total unicast packets received */
678 u64 n_multicast_xmit
; /* total multicast packets sent */
679 u64 n_multicast_rcv
; /* total multicast packets received */
683 struct qib_qp __rcu
*qp0
;
684 struct qib_qp __rcu
*qp1
;
685 struct ib_mad_agent
*send_agent
; /* agent for SMI (traps) */
686 struct qib_ah
*sm_ah
;
687 struct qib_ah
*smi_ah
;
688 struct rb_root mcast_tree
;
689 spinlock_t lock
; /* protect changes in this struct */
691 /* non-zero when timer is set */
692 unsigned long mkey_lease_timeout
;
693 unsigned long trap_timeout
;
694 __be64 gid_prefix
; /* in network order */
696 __be64 guids
[QIB_GUIDS_PER_PORT
- 1]; /* writable GUIDs */
697 u64 tid
; /* TID for traps */
698 struct qib_pma_counters __percpu
*pmastats
;
699 u64 z_unicast_xmit
; /* starting count for PMA */
700 u64 z_unicast_rcv
; /* starting count for PMA */
701 u64 z_multicast_xmit
; /* starting count for PMA */
702 u64 z_multicast_rcv
; /* starting count for PMA */
703 u64 z_symbol_error_counter
; /* starting count for PMA */
704 u64 z_link_error_recovery_counter
; /* starting count for PMA */
705 u64 z_link_downed_counter
; /* starting count for PMA */
706 u64 z_port_rcv_errors
; /* starting count for PMA */
707 u64 z_port_rcv_remphys_errors
; /* starting count for PMA */
708 u64 z_port_xmit_discards
; /* starting count for PMA */
709 u64 z_port_xmit_data
; /* starting count for PMA */
710 u64 z_port_rcv_data
; /* starting count for PMA */
711 u64 z_port_xmit_packets
; /* starting count for PMA */
712 u64 z_port_rcv_packets
; /* starting count for PMA */
713 u32 z_local_link_integrity_errors
; /* starting count for PMA */
714 u32 z_excessive_buffer_overrun_errors
; /* starting count for PMA */
715 u32 z_vl15_dropped
; /* starting count for PMA */
719 u32 n_rc_delayed_comp
;
733 u32 pma_sample_start
;
734 u32 pma_sample_interval
;
735 __be16 pma_counter_select
[5];
740 u16 mkey_lease_period
;
753 struct ib_device ibdev
;
754 struct list_head pending_mmaps
;
755 spinlock_t mmap_offset_lock
; /* protect mmap_offset */
757 struct qib_mregion __rcu
*dma_mr
;
759 /* QP numbers are shared by all IB ports */
760 struct qib_qpn_table qpn_table
;
761 struct qib_lkey_table lk_table
;
762 struct list_head piowait
; /* list for wait PIO buf */
763 struct list_head dmawait
; /* list for wait DMA */
764 struct list_head txwait
; /* list for wait qib_verbs_txreq */
765 struct list_head memwait
; /* list for wait kernel memory */
766 struct list_head txreq_free
;
767 struct timer_list mem_timer
;
768 struct qib_qp __rcu
**qp_table
;
769 struct qib_pio_header
*pio_hdrs
;
770 dma_addr_t pio_hdrs_phys
;
771 /* list of QPs waiting for RNR timer */
772 spinlock_t pending_lock
; /* protect wait lists, PMA counters, etc. */
773 u32 qp_table_size
; /* size of the hash table */
774 u32 qp_rnd
; /* random bytes for hash */
780 u32 n_pds_allocated
; /* number of PDs allocated for device */
781 spinlock_t n_pds_lock
;
782 u32 n_ahs_allocated
; /* number of AHs allocated for device */
783 spinlock_t n_ahs_lock
;
784 u32 n_cqs_allocated
; /* number of CQs allocated for device */
785 spinlock_t n_cqs_lock
;
786 u32 n_qps_allocated
; /* number of QPs allocated for device */
787 spinlock_t n_qps_lock
;
788 u32 n_srqs_allocated
; /* number of SRQs allocated for device */
789 spinlock_t n_srqs_lock
;
790 u32 n_mcast_grps_allocated
; /* number of mcast groups allocated */
791 spinlock_t n_mcast_grps_lock
;
792 #ifdef CONFIG_DEBUG_FS
793 /* per HCA debugfs */
794 struct dentry
*qib_ibdev_dbg
;
798 struct qib_verbs_counters
{
799 u64 symbol_error_counter
;
800 u64 link_error_recovery_counter
;
801 u64 link_downed_counter
;
803 u64 port_rcv_remphys_errors
;
804 u64 port_xmit_discards
;
807 u64 port_xmit_packets
;
808 u64 port_rcv_packets
;
809 u32 local_link_integrity_errors
;
810 u32 excessive_buffer_overrun_errors
;
814 static inline struct qib_mr
*to_imr(struct ib_mr
*ibmr
)
816 return container_of(ibmr
, struct qib_mr
, ibmr
);
819 static inline struct qib_pd
*to_ipd(struct ib_pd
*ibpd
)
821 return container_of(ibpd
, struct qib_pd
, ibpd
);
824 static inline struct qib_ah
*to_iah(struct ib_ah
*ibah
)
826 return container_of(ibah
, struct qib_ah
, ibah
);
829 static inline struct qib_cq
*to_icq(struct ib_cq
*ibcq
)
831 return container_of(ibcq
, struct qib_cq
, ibcq
);
834 static inline struct qib_srq
*to_isrq(struct ib_srq
*ibsrq
)
836 return container_of(ibsrq
, struct qib_srq
, ibsrq
);
839 static inline struct qib_qp
*to_iqp(struct ib_qp
*ibqp
)
841 return container_of(ibqp
, struct qib_qp
, ibqp
);
844 static inline struct qib_ibdev
*to_idev(struct ib_device
*ibdev
)
846 return container_of(ibdev
, struct qib_ibdev
, ibdev
);
850 * Send if not busy or waiting for I/O and either
851 * a RC response is pending or we can process send work requests.
853 static inline int qib_send_ok(struct qib_qp
*qp
)
855 return !(qp
->s_flags
& (QIB_S_BUSY
| QIB_S_ANY_WAIT_IO
)) &&
856 (qp
->s_hdrwords
|| (qp
->s_flags
& QIB_S_RESP_PENDING
) ||
857 !(qp
->s_flags
& QIB_S_ANY_WAIT_SEND
));
861 * This must be called with s_lock held.
863 void qib_schedule_send(struct qib_qp
*qp
);
865 static inline int qib_pkey_ok(u16 pkey1
, u16 pkey2
)
867 u16 p1
= pkey1
& 0x7FFF;
868 u16 p2
= pkey2
& 0x7FFF;
871 * Low 15 bits must be non-zero and match, and
872 * one of the two must be a full member.
874 return p1
&& p1
== p2
&& ((__s16
)pkey1
< 0 || (__s16
)pkey2
< 0);
877 void qib_bad_pqkey(struct qib_ibport
*ibp
, __be16 trap_num
, u32 key
, u32 sl
,
878 u32 qp1
, u32 qp2
, __be16 lid1
, __be16 lid2
);
879 void qib_cap_mask_chg(struct qib_ibport
*ibp
);
880 void qib_sys_guid_chg(struct qib_ibport
*ibp
);
881 void qib_node_desc_chg(struct qib_ibport
*ibp
);
882 int qib_process_mad(struct ib_device
*ibdev
, int mad_flags
, u8 port_num
,
883 const struct ib_wc
*in_wc
, const struct ib_grh
*in_grh
,
884 const struct ib_mad_hdr
*in
, size_t in_mad_size
,
885 struct ib_mad_hdr
*out
, size_t *out_mad_size
,
886 u16
*out_mad_pkey_index
);
887 int qib_create_agents(struct qib_ibdev
*dev
);
888 void qib_free_agents(struct qib_ibdev
*dev
);
891 * Compare the lower 24 bits of the two values.
892 * Returns an integer <, ==, or > than zero.
894 static inline int qib_cmp24(u32 a
, u32 b
)
896 return (((int) a
) - ((int) b
)) << 8;
899 struct qib_mcast
*qib_mcast_find(struct qib_ibport
*ibp
, union ib_gid
*mgid
);
901 int qib_snapshot_counters(struct qib_pportdata
*ppd
, u64
*swords
,
902 u64
*rwords
, u64
*spkts
, u64
*rpkts
,
905 int qib_get_counters(struct qib_pportdata
*ppd
,
906 struct qib_verbs_counters
*cntrs
);
908 int qib_multicast_attach(struct ib_qp
*ibqp
, union ib_gid
*gid
, u16 lid
);
910 int qib_multicast_detach(struct ib_qp
*ibqp
, union ib_gid
*gid
, u16 lid
);
912 int qib_mcast_tree_empty(struct qib_ibport
*ibp
);
914 __be32
qib_compute_aeth(struct qib_qp
*qp
);
916 struct qib_qp
*qib_lookup_qpn(struct qib_ibport
*ibp
, u32 qpn
);
918 struct ib_qp
*qib_create_qp(struct ib_pd
*ibpd
,
919 struct ib_qp_init_attr
*init_attr
,
920 struct ib_udata
*udata
);
922 int qib_destroy_qp(struct ib_qp
*ibqp
);
924 int qib_error_qp(struct qib_qp
*qp
, enum ib_wc_status err
);
926 int qib_modify_qp(struct ib_qp
*ibqp
, struct ib_qp_attr
*attr
,
927 int attr_mask
, struct ib_udata
*udata
);
929 int qib_query_qp(struct ib_qp
*ibqp
, struct ib_qp_attr
*attr
,
930 int attr_mask
, struct ib_qp_init_attr
*init_attr
);
932 unsigned qib_free_all_qps(struct qib_devdata
*dd
);
934 void qib_init_qpn_table(struct qib_devdata
*dd
, struct qib_qpn_table
*qpt
);
936 void qib_free_qpn_table(struct qib_qpn_table
*qpt
);
938 #ifdef CONFIG_DEBUG_FS
942 struct qib_qp_iter
*qib_qp_iter_init(struct qib_ibdev
*dev
);
944 int qib_qp_iter_next(struct qib_qp_iter
*iter
);
946 void qib_qp_iter_print(struct seq_file
*s
, struct qib_qp_iter
*iter
);
950 void qib_get_credit(struct qib_qp
*qp
, u32 aeth
);
952 unsigned qib_pkt_delay(u32 plen
, u8 snd_mult
, u8 rcv_mult
);
954 void qib_verbs_sdma_desc_avail(struct qib_pportdata
*ppd
, unsigned avail
);
956 void qib_put_txreq(struct qib_verbs_txreq
*tx
);
958 int qib_verbs_send(struct qib_qp
*qp
, struct qib_ib_header
*hdr
,
959 u32 hdrwords
, struct qib_sge_state
*ss
, u32 len
);
961 void qib_copy_sge(struct qib_sge_state
*ss
, void *data
, u32 length
,
964 void qib_skip_sge(struct qib_sge_state
*ss
, u32 length
, int release
);
966 void qib_uc_rcv(struct qib_ibport
*ibp
, struct qib_ib_header
*hdr
,
967 int has_grh
, void *data
, u32 tlen
, struct qib_qp
*qp
);
969 void qib_rc_rcv(struct qib_ctxtdata
*rcd
, struct qib_ib_header
*hdr
,
970 int has_grh
, void *data
, u32 tlen
, struct qib_qp
*qp
);
972 int qib_check_ah(struct ib_device
*ibdev
, struct ib_ah_attr
*ah_attr
);
974 struct ib_ah
*qib_create_qp0_ah(struct qib_ibport
*ibp
, u16 dlid
);
976 void qib_rc_rnr_retry(unsigned long arg
);
978 void qib_rc_send_complete(struct qib_qp
*qp
, struct qib_ib_header
*hdr
);
980 void qib_rc_error(struct qib_qp
*qp
, enum ib_wc_status err
);
982 int qib_post_ud_send(struct qib_qp
*qp
, struct ib_send_wr
*wr
);
984 void qib_ud_rcv(struct qib_ibport
*ibp
, struct qib_ib_header
*hdr
,
985 int has_grh
, void *data
, u32 tlen
, struct qib_qp
*qp
);
987 int qib_alloc_lkey(struct qib_mregion
*mr
, int dma_region
);
989 void qib_free_lkey(struct qib_mregion
*mr
);
991 int qib_lkey_ok(struct qib_lkey_table
*rkt
, struct qib_pd
*pd
,
992 struct qib_sge
*isge
, struct ib_sge
*sge
, int acc
);
994 int qib_rkey_ok(struct qib_qp
*qp
, struct qib_sge
*sge
,
995 u32 len
, u64 vaddr
, u32 rkey
, int acc
);
997 int qib_post_srq_receive(struct ib_srq
*ibsrq
, struct ib_recv_wr
*wr
,
998 struct ib_recv_wr
**bad_wr
);
1000 struct ib_srq
*qib_create_srq(struct ib_pd
*ibpd
,
1001 struct ib_srq_init_attr
*srq_init_attr
,
1002 struct ib_udata
*udata
);
1004 int qib_modify_srq(struct ib_srq
*ibsrq
, struct ib_srq_attr
*attr
,
1005 enum ib_srq_attr_mask attr_mask
,
1006 struct ib_udata
*udata
);
1008 int qib_query_srq(struct ib_srq
*ibsrq
, struct ib_srq_attr
*attr
);
1010 int qib_destroy_srq(struct ib_srq
*ibsrq
);
1012 int qib_cq_init(struct qib_devdata
*dd
);
1014 void qib_cq_exit(struct qib_devdata
*dd
);
1016 void qib_cq_enter(struct qib_cq
*cq
, struct ib_wc
*entry
, int sig
);
1018 int qib_poll_cq(struct ib_cq
*ibcq
, int num_entries
, struct ib_wc
*entry
);
1020 struct ib_cq
*qib_create_cq(struct ib_device
*ibdev
,
1021 const struct ib_cq_init_attr
*attr
,
1022 struct ib_ucontext
*context
,
1023 struct ib_udata
*udata
);
1025 int qib_destroy_cq(struct ib_cq
*ibcq
);
1027 int qib_req_notify_cq(struct ib_cq
*ibcq
, enum ib_cq_notify_flags notify_flags
);
1029 int qib_resize_cq(struct ib_cq
*ibcq
, int cqe
, struct ib_udata
*udata
);
1031 struct ib_mr
*qib_get_dma_mr(struct ib_pd
*pd
, int acc
);
1033 struct ib_mr
*qib_reg_phys_mr(struct ib_pd
*pd
,
1034 struct ib_phys_buf
*buffer_list
,
1035 int num_phys_buf
, int acc
, u64
*iova_start
);
1037 struct ib_mr
*qib_reg_user_mr(struct ib_pd
*pd
, u64 start
, u64 length
,
1038 u64 virt_addr
, int mr_access_flags
,
1039 struct ib_udata
*udata
);
1041 int qib_dereg_mr(struct ib_mr
*ibmr
);
1043 struct ib_mr
*qib_alloc_mr(struct ib_pd
*pd
,
1044 enum ib_mr_type mr_type
,
1047 struct ib_fast_reg_page_list
*qib_alloc_fast_reg_page_list(
1048 struct ib_device
*ibdev
, int page_list_len
);
1050 void qib_free_fast_reg_page_list(struct ib_fast_reg_page_list
*pl
);
1052 int qib_fast_reg_mr(struct qib_qp
*qp
, struct ib_send_wr
*wr
);
1054 struct ib_fmr
*qib_alloc_fmr(struct ib_pd
*pd
, int mr_access_flags
,
1055 struct ib_fmr_attr
*fmr_attr
);
1057 int qib_map_phys_fmr(struct ib_fmr
*ibfmr
, u64
*page_list
,
1058 int list_len
, u64 iova
);
1060 int qib_unmap_fmr(struct list_head
*fmr_list
);
1062 int qib_dealloc_fmr(struct ib_fmr
*ibfmr
);
1064 static inline void qib_get_mr(struct qib_mregion
*mr
)
1066 atomic_inc(&mr
->refcount
);
1069 void mr_rcu_callback(struct rcu_head
*list
);
1071 static inline void qib_put_mr(struct qib_mregion
*mr
)
1073 if (unlikely(atomic_dec_and_test(&mr
->refcount
)))
1074 call_rcu(&mr
->list
, mr_rcu_callback
);
1077 static inline void qib_put_ss(struct qib_sge_state
*ss
)
1079 while (ss
->num_sge
) {
1080 qib_put_mr(ss
->sge
.mr
);
1082 ss
->sge
= *ss
->sg_list
++;
1087 void qib_release_mmap_info(struct kref
*ref
);
1089 struct qib_mmap_info
*qib_create_mmap_info(struct qib_ibdev
*dev
, u32 size
,
1090 struct ib_ucontext
*context
,
1093 void qib_update_mmap_info(struct qib_ibdev
*dev
, struct qib_mmap_info
*ip
,
1094 u32 size
, void *obj
);
1096 int qib_mmap(struct ib_ucontext
*context
, struct vm_area_struct
*vma
);
1098 int qib_get_rwqe(struct qib_qp
*qp
, int wr_id_only
);
1100 void qib_migrate_qp(struct qib_qp
*qp
);
1102 int qib_ruc_check_hdr(struct qib_ibport
*ibp
, struct qib_ib_header
*hdr
,
1103 int has_grh
, struct qib_qp
*qp
, u32 bth0
);
1105 u32
qib_make_grh(struct qib_ibport
*ibp
, struct ib_grh
*hdr
,
1106 struct ib_global_route
*grh
, u32 hwords
, u32 nwords
);
1108 void qib_make_ruc_header(struct qib_qp
*qp
, struct qib_other_headers
*ohdr
,
1109 u32 bth0
, u32 bth2
);
1111 void qib_do_send(struct work_struct
*work
);
1113 void qib_send_complete(struct qib_qp
*qp
, struct qib_swqe
*wqe
,
1114 enum ib_wc_status status
);
1116 void qib_send_rc_ack(struct qib_qp
*qp
);
1118 int qib_make_rc_req(struct qib_qp
*qp
);
1120 int qib_make_uc_req(struct qib_qp
*qp
);
1122 int qib_make_ud_req(struct qib_qp
*qp
);
1124 int qib_register_ib_device(struct qib_devdata
*);
1126 void qib_unregister_ib_device(struct qib_devdata
*);
1128 void qib_ib_rcv(struct qib_ctxtdata
*, void *, void *, u32
);
1130 void qib_ib_piobufavail(struct qib_devdata
*);
1132 unsigned qib_get_npkeys(struct qib_devdata
*);
1134 unsigned qib_get_pkey(struct qib_ibport
*, unsigned);
1136 extern const enum ib_wc_opcode ib_qib_wc_opcode
[];
1139 * Below HCA-independent IB PhysPortState values, returned
1140 * by the f_ibphys_portstate() routine.
1142 #define IB_PHYSPORTSTATE_SLEEP 1
1143 #define IB_PHYSPORTSTATE_POLL 2
1144 #define IB_PHYSPORTSTATE_DISABLED 3
1145 #define IB_PHYSPORTSTATE_CFG_TRAIN 4
1146 #define IB_PHYSPORTSTATE_LINKUP 5
1147 #define IB_PHYSPORTSTATE_LINK_ERR_RECOVER 6
1148 #define IB_PHYSPORTSTATE_CFG_DEBOUNCE 8
1149 #define IB_PHYSPORTSTATE_CFG_IDLE 0xB
1150 #define IB_PHYSPORTSTATE_RECOVERY_RETRAIN 0xC
1151 #define IB_PHYSPORTSTATE_RECOVERY_WAITRMT 0xE
1152 #define IB_PHYSPORTSTATE_RECOVERY_IDLE 0xF
1153 #define IB_PHYSPORTSTATE_CFG_ENH 0x10
1154 #define IB_PHYSPORTSTATE_CFG_WAIT_ENH 0x13
1156 extern const int ib_qib_state_ops
[];
1158 extern __be64 ib_qib_sys_image_guid
; /* in network order */
1160 extern unsigned int ib_qib_lkey_table_size
;
1162 extern unsigned int ib_qib_max_cqes
;
1164 extern unsigned int ib_qib_max_cqs
;
1166 extern unsigned int ib_qib_max_qp_wrs
;
1168 extern unsigned int ib_qib_max_qps
;
1170 extern unsigned int ib_qib_max_sges
;
1172 extern unsigned int ib_qib_max_mcast_grps
;
1174 extern unsigned int ib_qib_max_mcast_qp_attached
;
1176 extern unsigned int ib_qib_max_srqs
;
1178 extern unsigned int ib_qib_max_srq_sges
;
1180 extern unsigned int ib_qib_max_srq_wrs
;
1182 extern const u32 ib_qib_rnr_table
[];
1184 extern struct ib_dma_mapping_ops qib_dma_mapping_ops
;
1186 #endif /* QIB_VERBS_H */