2 * Copyright (c) 2006, 2007, 2008, 2009, 2010 QLogic Corporation.
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/completion.h>
45 #include <rdma/ib_pack.h>
46 #include <rdma/ib_user_verbs.h>
51 struct qib_verbs_txreq
;
53 #define QIB_MAX_RDMA_ATOMIC 16
54 #define QIB_GUIDS_PER_PORT 5
56 #define QPN_MAX (1 << 24)
57 #define QPNMAP_ENTRIES (QPN_MAX / PAGE_SIZE / BITS_PER_BYTE)
60 * Increment this value if any changes that break userspace ABI
61 * compatibility are made.
63 #define QIB_UVERBS_ABI_VERSION 2
66 * Define an ib_cq_notify value that is not valid so we know when CQ
67 * notifications are armed.
69 #define IB_CQ_NONE (IB_CQ_NEXT_COMP + 1)
71 #define IB_SEQ_NAK (3 << 29)
73 /* AETH NAK opcode values */
74 #define IB_RNR_NAK 0x20
75 #define IB_NAK_PSN_ERROR 0x60
76 #define IB_NAK_INVALID_REQUEST 0x61
77 #define IB_NAK_REMOTE_ACCESS_ERROR 0x62
78 #define IB_NAK_REMOTE_OPERATIONAL_ERROR 0x63
79 #define IB_NAK_INVALID_RD_REQUEST 0x64
81 /* Flags for checking QP state (see ib_qib_state_ops[]) */
82 #define QIB_POST_SEND_OK 0x01
83 #define QIB_POST_RECV_OK 0x02
84 #define QIB_PROCESS_RECV_OK 0x04
85 #define QIB_PROCESS_SEND_OK 0x08
86 #define QIB_PROCESS_NEXT_SEND_OK 0x10
87 #define QIB_FLUSH_SEND 0x20
88 #define QIB_FLUSH_RECV 0x40
89 #define QIB_PROCESS_OR_FLUSH_SEND \
90 (QIB_PROCESS_SEND_OK | QIB_FLUSH_SEND)
92 /* IB Performance Manager status values */
93 #define IB_PMA_SAMPLE_STATUS_DONE 0x00
94 #define IB_PMA_SAMPLE_STATUS_STARTED 0x01
95 #define IB_PMA_SAMPLE_STATUS_RUNNING 0x02
97 /* Mandatory IB performance counter select values. */
98 #define IB_PMA_PORT_XMIT_DATA cpu_to_be16(0x0001)
99 #define IB_PMA_PORT_RCV_DATA cpu_to_be16(0x0002)
100 #define IB_PMA_PORT_XMIT_PKTS cpu_to_be16(0x0003)
101 #define IB_PMA_PORT_RCV_PKTS cpu_to_be16(0x0004)
102 #define IB_PMA_PORT_XMIT_WAIT cpu_to_be16(0x0005)
104 #define QIB_VENDOR_IPG cpu_to_be16(0xFFA0)
106 #define IB_BTH_REQ_ACK (1 << 31)
107 #define IB_BTH_SOLICITED (1 << 23)
108 #define IB_BTH_MIG_REQ (1 << 22)
110 /* XXX Should be defined in ib_verbs.h enum ib_port_cap_flags */
111 #define IB_PORT_OTHER_LOCAL_CHANGES_SUP (1 << 26)
113 #define IB_GRH_VERSION 6
114 #define IB_GRH_VERSION_MASK 0xF
115 #define IB_GRH_VERSION_SHIFT 28
116 #define IB_GRH_TCLASS_MASK 0xFF
117 #define IB_GRH_TCLASS_SHIFT 20
118 #define IB_GRH_FLOW_MASK 0xFFFFF
119 #define IB_GRH_FLOW_SHIFT 0
120 #define IB_GRH_NEXT_HDR 0x1B
122 #define IB_DEFAULT_GID_PREFIX cpu_to_be64(0xfe80000000000000ULL)
124 /* Values for set/get portinfo VLCap OperationalVLs */
126 #define IB_VL_VL0_1 2
127 #define IB_VL_VL0_3 3
128 #define IB_VL_VL0_7 4
129 #define IB_VL_VL0_14 5
131 static inline int qib_num_vls(int vls
)
152 } __attribute__ ((packed
));
154 struct ib_atomic_eth
{
155 __be32 vaddr
[2]; /* unaligned so access as 2 32-bit words */
159 } __attribute__ ((packed
));
161 struct qib_other_headers
{
174 __be32 atomic_ack_eth
[2];
178 struct ib_atomic_eth atomic_eth
;
180 } __attribute__ ((packed
));
183 * Note that UD packets with a GRH header are 8+40+12+8 = 68 bytes
184 * long (72 w/ imm_data). Only the first 56 bytes of the IB header
185 * will be in the eager header buffer. The remaining 12 or 16 bytes
186 * are in the data buffer.
188 struct qib_ib_header
{
193 struct qib_other_headers oth
;
195 struct qib_other_headers oth
;
197 } __attribute__ ((packed
));
199 struct qib_pio_header
{
201 struct qib_ib_header hdr
;
202 } __attribute__ ((packed
));
205 * There is one struct qib_mcast for each multicast GID.
206 * All attached QPs are then stored as a list of
207 * struct qib_mcast_qp.
209 struct qib_mcast_qp
{
210 struct list_head list
;
215 struct rb_node rb_node
;
217 struct list_head qp_list
;
218 wait_queue_head_t wait
;
223 /* Protection domain */
226 int user
; /* non-zero if created from user space */
232 struct ib_ah_attr attr
;
237 * This structure is used by qib_mmap() to validate an offset
238 * when an mmap() request is made. The vm_area_struct then uses
239 * this as its vm_private_data.
241 struct qib_mmap_info
{
242 struct list_head pending_mmaps
;
243 struct ib_ucontext
*context
;
251 * This structure is used to contain the head pointer, tail pointer,
252 * and completion queue entries as a single memory allocation so
253 * it can be mmap'ed into user space.
256 u32 head
; /* index of next entry to fill */
257 u32 tail
; /* index of next ib_poll_cq() entry */
259 /* these are actually size ibcq.cqe + 1 */
260 struct ib_uverbs_wc uqueue
[0];
261 struct ib_wc kqueue
[0];
266 * The completion queue structure.
270 struct work_struct comptask
;
271 spinlock_t lock
; /* protect changes in this struct */
274 struct qib_cq_wc
*queue
;
275 struct qib_mmap_info
*ip
;
279 * A segment is a linear region of low physical memory.
280 * XXX Maybe we should use phys addr here and kmap()/kunmap().
281 * Used by the verbs layer.
288 /* The number of qib_segs that fit in a page. */
289 #define QIB_SEGSZ (PAGE_SIZE / sizeof(struct qib_seg))
291 struct qib_segarray
{
292 struct qib_seg segs
[QIB_SEGSZ
];
296 struct ib_pd
*pd
; /* shares refcnt of ibmr.pd */
297 u64 user_base
; /* User's address for this region */
298 u64 iova
; /* IB start address of this region */
301 u32 offset
; /* offset (bytes) to start of region */
303 u32 max_segs
; /* number of qib_segs in all the arrays */
304 u32 mapsz
; /* size of the map array */
305 u8 page_shift
; /* 0 - non unform/non powerof2 sizes */
306 u8 lkey_published
; /* in global table */
307 struct completion comp
; /* complete when refcount goes to zero */
309 struct qib_segarray
*map
[0]; /* the segments */
313 * These keep track of the copy progress within a memory region.
314 * Used by the verbs layer.
317 struct qib_mregion
*mr
;
318 void *vaddr
; /* kernel virtual address of segment */
319 u32 sge_length
; /* length of the SGE */
320 u32 length
; /* remaining length of the segment */
321 u16 m
; /* current index: mr->map[m] */
322 u16 n
; /* current index: mr->map[m]->segs[n] */
328 struct ib_umem
*umem
;
329 struct qib_mregion mr
; /* must be last */
333 * Send work request queue entry.
334 * The size of the sg_list is determined when the QP is created and stored
338 struct ib_send_wr wr
; /* don't use wr.sg_list */
339 u32 psn
; /* first packet sequence number */
340 u32 lpsn
; /* last packet sequence number */
341 u32 ssn
; /* send sequence number */
342 u32 length
; /* total length of data in sg_list */
343 struct qib_sge sg_list
[0];
347 * Receive work request queue entry.
348 * The size of the sg_list is determined when the QP (or SRQ) is created
349 * and stored in qp->r_rq.max_sge (or srq->rq.max_sge).
354 struct ib_sge sg_list
[0];
358 * This structure is used to contain the head pointer, tail pointer,
359 * and receive work queue entries as a single memory allocation so
360 * it can be mmap'ed into user space.
361 * Note that the wq array elements are variable size so you can't
362 * just index into the array to get the N'th element;
363 * use get_rwqe_ptr() instead.
366 u32 head
; /* new work requests posted to the head */
367 u32 tail
; /* receives pull requests from here. */
368 struct qib_rwqe wq
[0];
373 u32 size
; /* size of RWQE array */
375 spinlock_t lock
/* protect changes in this struct */
376 ____cacheline_aligned_in_smp
;
382 struct qib_mmap_info
*ip
;
383 /* send signal when number of RWQEs < limit */
387 struct qib_sge_state
{
388 struct qib_sge
*sg_list
; /* next SGE to be used if any */
389 struct qib_sge sge
; /* progress state for the current SGE */
395 * This structure holds the information that the send tasklet needs
396 * to send a RDMA read response or atomic operation.
398 struct qib_ack_entry
{
404 struct qib_sge rdma_sge
;
410 * Variables prefixed with s_ are for the requester (sender).
411 * Variables prefixed with r_ are for the responder (receiver).
412 * Variables prefixed with ack_ are for responder replies.
414 * Common variables are protected by both r_rq.lock and s_lock in that order
415 * which only happens in modify_qp() or changing the QP 'state'.
419 /* read mostly fields above and below */
420 struct ib_ah_attr remote_ah_attr
;
421 struct ib_ah_attr alt_ah_attr
;
422 struct qib_qp
*next
; /* link list for QPN hash table */
423 struct qib_swqe
*s_wq
; /* send work queue */
424 struct qib_mmap_info
*ip
;
425 struct qib_ib_header
*s_hdr
; /* next packet header to send */
426 unsigned long timeout_jiffies
; /* computed from timeout */
428 enum ib_mtu path_mtu
;
430 u32 pmtu
; /* decoded from path_mtu */
431 u32 qkey
; /* QKEY for this QP (for UD or RD) */
432 u32 s_size
; /* send work queue size */
433 u32 s_rnr_timeout
; /* number of milliseconds for RNR timeout */
435 u8 state
; /* QP state */
437 u8 alt_timeout
; /* Alternate path timeout for this QP */
438 u8 timeout
; /* Timeout for this QP */
442 u8 s_pkey_index
; /* PKEY index to use */
443 u8 s_alt_pkey_index
; /* Alternate path PKEY index to use */
444 u8 r_max_rd_atomic
; /* max number of RDMA read/atomic to receive */
445 u8 s_max_rd_atomic
; /* max number of RDMA read/atomic to send */
446 u8 s_retry_cnt
; /* number of times to retry */
448 u8 r_min_rnr_timer
; /* retry timeout value for RNR NAKs */
449 u8 s_max_sge
; /* size of s_wq->sg_list */
452 /* start of read/write fields */
454 atomic_t refcount ____cacheline_aligned_in_smp
;
455 wait_queue_head_t wait
;
458 struct qib_ack_entry s_ack_queue
[QIB_MAX_RDMA_ATOMIC
+ 1]
459 ____cacheline_aligned_in_smp
;
460 struct qib_sge_state s_rdma_read_sge
;
462 spinlock_t r_lock ____cacheline_aligned_in_smp
; /* used for APM */
463 unsigned long r_aflags
;
464 u64 r_wr_id
; /* ID for current receive WQE */
465 u32 r_ack_psn
; /* PSN for next ACK or atomic ACK */
466 u32 r_len
; /* total length of r_sge */
467 u32 r_rcv_len
; /* receive data len processed */
468 u32 r_psn
; /* expected rcv packet sequence number */
469 u32 r_msn
; /* message sequence number */
471 u8 r_state
; /* opcode of last packet received */
473 u8 r_head_ack_queue
; /* index into s_ack_queue[] */
475 struct list_head rspwait
; /* link for waititing to respond */
477 struct qib_sge_state r_sge
; /* current receive data */
478 struct qib_rq r_rq
; /* receive work queue */
480 spinlock_t s_lock ____cacheline_aligned_in_smp
;
481 struct qib_sge_state
*s_cur_sge
;
483 struct qib_verbs_txreq
*s_tx
;
484 struct qib_swqe
*s_wqe
;
485 struct qib_sge_state s_sge
; /* current send request data */
486 struct qib_mregion
*s_rdma_mr
;
488 u32 s_cur_size
; /* size of send packet in bytes */
489 u32 s_len
; /* total length of s_sge */
490 u32 s_rdma_read_len
; /* total length of s_rdma_read_sge */
491 u32 s_next_psn
; /* PSN for next request */
492 u32 s_last_psn
; /* last response PSN processed */
493 u32 s_sending_psn
; /* lowest PSN that is being sent */
494 u32 s_sending_hpsn
; /* highest PSN that is being sent */
495 u32 s_psn
; /* current packet sequence number */
496 u32 s_ack_rdma_psn
; /* PSN for sending RDMA read responses */
497 u32 s_ack_psn
; /* PSN for acking sends and RDMA writes */
498 u32 s_head
; /* new entries added here */
499 u32 s_tail
; /* next entry to process */
500 u32 s_cur
; /* current work queue entry */
501 u32 s_acked
; /* last un-ACK'ed entry */
502 u32 s_last
; /* last completed entry */
503 u32 s_ssn
; /* SSN of tail entry */
504 u32 s_lsn
; /* limit sequence number (credit) */
505 u16 s_hdrwords
; /* size of s_hdr in 32 bit words */
507 u8 s_state
; /* opcode of last packet sent */
508 u8 s_ack_state
; /* opcode of packet to ACK */
509 u8 s_nak_state
; /* non-zero if NAK is pending */
510 u8 r_nak_state
; /* non-zero if NAK is pending */
511 u8 s_retry
; /* requester retry counter */
512 u8 s_rnr_retry
; /* requester RNR retry counter */
513 u8 s_num_rd_atomic
; /* number of RDMA read/atomic pending */
514 u8 s_tail_ack_queue
; /* index into s_ack_queue[] */
516 struct qib_sge_state s_ack_rdma_sge
;
517 struct timer_list s_timer
;
518 struct list_head iowait
; /* link for wait PIO buf */
520 struct work_struct s_work
;
522 wait_queue_head_t wait_dma
;
524 struct qib_sge r_sg_list
[0] /* verified SGEs */
525 ____cacheline_aligned_in_smp
;
529 * Atomic bit definitions for r_aflags.
531 #define QIB_R_WRID_VALID 0
532 #define QIB_R_REWIND_SGE 1
535 * Bit definitions for r_flags.
537 #define QIB_R_REUSE_SGE 0x01
538 #define QIB_R_RDMAR_SEQ 0x02
539 #define QIB_R_RSP_NAK 0x04
540 #define QIB_R_RSP_SEND 0x08
541 #define QIB_R_COMM_EST 0x10
544 * Bit definitions for s_flags.
546 * QIB_S_SIGNAL_REQ_WR - set if QP send WRs contain completion signaled
547 * QIB_S_BUSY - send tasklet is processing the QP
548 * QIB_S_TIMER - the RC retry timer is active
549 * QIB_S_ACK_PENDING - an ACK is waiting to be sent after RDMA read/atomics
550 * QIB_S_WAIT_FENCE - waiting for all prior RDMA read or atomic SWQEs
551 * before processing the next SWQE
552 * QIB_S_WAIT_RDMAR - waiting for a RDMA read or atomic SWQE to complete
553 * before processing the next SWQE
554 * QIB_S_WAIT_RNR - waiting for RNR timeout
555 * QIB_S_WAIT_SSN_CREDIT - waiting for RC credits to process next SWQE
556 * QIB_S_WAIT_DMA - waiting for send DMA queue to drain before generating
557 * next send completion entry not via send DMA
558 * QIB_S_WAIT_PIO - waiting for a send buffer to be available
559 * QIB_S_WAIT_TX - waiting for a struct qib_verbs_txreq to be available
560 * QIB_S_WAIT_DMA_DESC - waiting for DMA descriptors to be available
561 * QIB_S_WAIT_KMEM - waiting for kernel memory to be available
562 * QIB_S_WAIT_PSN - waiting for a packet to exit the send DMA queue
563 * QIB_S_WAIT_ACK - waiting for an ACK packet before sending more requests
564 * QIB_S_SEND_ONE - send one packet, request ACK, then wait for ACK
566 #define QIB_S_SIGNAL_REQ_WR 0x0001
567 #define QIB_S_BUSY 0x0002
568 #define QIB_S_TIMER 0x0004
569 #define QIB_S_RESP_PENDING 0x0008
570 #define QIB_S_ACK_PENDING 0x0010
571 #define QIB_S_WAIT_FENCE 0x0020
572 #define QIB_S_WAIT_RDMAR 0x0040
573 #define QIB_S_WAIT_RNR 0x0080
574 #define QIB_S_WAIT_SSN_CREDIT 0x0100
575 #define QIB_S_WAIT_DMA 0x0200
576 #define QIB_S_WAIT_PIO 0x0400
577 #define QIB_S_WAIT_TX 0x0800
578 #define QIB_S_WAIT_DMA_DESC 0x1000
579 #define QIB_S_WAIT_KMEM 0x2000
580 #define QIB_S_WAIT_PSN 0x4000
581 #define QIB_S_WAIT_ACK 0x8000
582 #define QIB_S_SEND_ONE 0x10000
583 #define QIB_S_UNLIMITED_CREDIT 0x20000
586 * Wait flags that would prevent any packet type from being sent.
588 #define QIB_S_ANY_WAIT_IO (QIB_S_WAIT_PIO | QIB_S_WAIT_TX | \
589 QIB_S_WAIT_DMA_DESC | QIB_S_WAIT_KMEM)
592 * Wait flags that would prevent send work requests from making progress.
594 #define QIB_S_ANY_WAIT_SEND (QIB_S_WAIT_FENCE | QIB_S_WAIT_RDMAR | \
595 QIB_S_WAIT_RNR | QIB_S_WAIT_SSN_CREDIT | QIB_S_WAIT_DMA | \
596 QIB_S_WAIT_PSN | QIB_S_WAIT_ACK)
598 #define QIB_S_ANY_WAIT (QIB_S_ANY_WAIT_IO | QIB_S_ANY_WAIT_SEND)
600 #define QIB_PSN_CREDIT 16
603 * Since struct qib_swqe is not a fixed size, we can't simply index into
604 * struct qib_qp.s_wq. This function does the array index computation.
606 static inline struct qib_swqe
*get_swqe_ptr(struct qib_qp
*qp
,
609 return (struct qib_swqe
*)((char *)qp
->s_wq
+
610 (sizeof(struct qib_swqe
) +
612 sizeof(struct qib_sge
)) * n
);
616 * Since struct qib_rwqe is not a fixed size, we can't simply index into
617 * struct qib_rwq.wq. This function does the array index computation.
619 static inline struct qib_rwqe
*get_rwqe_ptr(struct qib_rq
*rq
, unsigned n
)
621 return (struct qib_rwqe
*)
622 ((char *) rq
->wq
->wq
+
623 (sizeof(struct qib_rwqe
) +
624 rq
->max_sge
* sizeof(struct ib_sge
)) * n
);
628 * QPN-map pages start out as NULL, they get allocated upon
629 * first use and are never deallocated. This way,
630 * large bitmaps are not allocated unless large numbers of QPs are used.
636 struct qib_qpn_table
{
637 spinlock_t lock
; /* protect changes in this struct */
638 unsigned flags
; /* flags for QP0/1 allocated for each port */
639 u32 last
; /* last QP number allocated */
640 u32 nmaps
; /* size of the map table */
643 /* bit map of free QP numbers other than 0/1 */
644 struct qpn_map map
[QPNMAP_ENTRIES
];
647 struct qib_lkey_table
{
648 spinlock_t lock
; /* protect changes in this struct */
649 u32 next
; /* next unused index (speeds search) */
650 u32 gen
; /* generation count */
651 u32 max
; /* size of the table */
652 struct qib_mregion
**table
;
655 struct qib_opcode_stats
{
656 u64 n_packets
; /* number of packets */
657 u64 n_bytes
; /* total number of bytes */
663 struct ib_mad_agent
*send_agent
; /* agent for SMI (traps) */
664 struct qib_ah
*sm_ah
;
665 struct qib_ah
*smi_ah
;
666 struct rb_root mcast_tree
;
667 spinlock_t lock
; /* protect changes in this struct */
669 /* non-zero when timer is set */
670 unsigned long mkey_lease_timeout
;
671 unsigned long trap_timeout
;
672 __be64 gid_prefix
; /* in network order */
674 __be64 guids
[QIB_GUIDS_PER_PORT
- 1]; /* writable GUIDs */
675 u64 tid
; /* TID for traps */
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 */
680 u64 z_symbol_error_counter
; /* starting count for PMA */
681 u64 z_link_error_recovery_counter
; /* starting count for PMA */
682 u64 z_link_downed_counter
; /* starting count for PMA */
683 u64 z_port_rcv_errors
; /* starting count for PMA */
684 u64 z_port_rcv_remphys_errors
; /* starting count for PMA */
685 u64 z_port_xmit_discards
; /* starting count for PMA */
686 u64 z_port_xmit_data
; /* starting count for PMA */
687 u64 z_port_rcv_data
; /* starting count for PMA */
688 u64 z_port_xmit_packets
; /* starting count for PMA */
689 u64 z_port_rcv_packets
; /* starting count for PMA */
690 u32 z_local_link_integrity_errors
; /* starting count for PMA */
691 u32 z_excessive_buffer_overrun_errors
; /* starting count for PMA */
692 u32 z_vl15_dropped
; /* starting count for PMA */
696 u32 n_rc_delayed_comp
;
710 u32 pma_sample_start
;
711 u32 pma_sample_interval
;
712 __be16 pma_counter_select
[5];
717 u16 mkey_lease_period
;
726 struct qib_opcode_stats opstats
[128];
730 struct ib_device ibdev
;
731 struct list_head pending_mmaps
;
732 spinlock_t mmap_offset_lock
; /* protect mmap_offset */
734 struct qib_mregion
*dma_mr
;
736 /* QP numbers are shared by all IB ports */
737 struct qib_qpn_table qpn_table
;
738 struct qib_lkey_table lk_table
;
739 struct list_head piowait
; /* list for wait PIO buf */
740 struct list_head dmawait
; /* list for wait DMA */
741 struct list_head txwait
; /* list for wait qib_verbs_txreq */
742 struct list_head memwait
; /* list for wait kernel memory */
743 struct list_head txreq_free
;
744 struct timer_list mem_timer
;
745 struct qib_qp
**qp_table
;
746 struct qib_pio_header
*pio_hdrs
;
747 dma_addr_t pio_hdrs_phys
;
748 /* list of QPs waiting for RNR timer */
749 spinlock_t pending_lock
; /* protect wait lists, PMA counters, etc. */
750 u32 qp_table_size
; /* size of the hash table */
751 u32 qp_rnd
; /* random bytes for hash */
757 u32 n_pds_allocated
; /* number of PDs allocated for device */
758 spinlock_t n_pds_lock
;
759 u32 n_ahs_allocated
; /* number of AHs allocated for device */
760 spinlock_t n_ahs_lock
;
761 u32 n_cqs_allocated
; /* number of CQs allocated for device */
762 spinlock_t n_cqs_lock
;
763 u32 n_qps_allocated
; /* number of QPs allocated for device */
764 spinlock_t n_qps_lock
;
765 u32 n_srqs_allocated
; /* number of SRQs allocated for device */
766 spinlock_t n_srqs_lock
;
767 u32 n_mcast_grps_allocated
; /* number of mcast groups allocated */
768 spinlock_t n_mcast_grps_lock
;
771 struct qib_verbs_counters
{
772 u64 symbol_error_counter
;
773 u64 link_error_recovery_counter
;
774 u64 link_downed_counter
;
776 u64 port_rcv_remphys_errors
;
777 u64 port_xmit_discards
;
780 u64 port_xmit_packets
;
781 u64 port_rcv_packets
;
782 u32 local_link_integrity_errors
;
783 u32 excessive_buffer_overrun_errors
;
787 static inline struct qib_mr
*to_imr(struct ib_mr
*ibmr
)
789 return container_of(ibmr
, struct qib_mr
, ibmr
);
792 static inline struct qib_pd
*to_ipd(struct ib_pd
*ibpd
)
794 return container_of(ibpd
, struct qib_pd
, ibpd
);
797 static inline struct qib_ah
*to_iah(struct ib_ah
*ibah
)
799 return container_of(ibah
, struct qib_ah
, ibah
);
802 static inline struct qib_cq
*to_icq(struct ib_cq
*ibcq
)
804 return container_of(ibcq
, struct qib_cq
, ibcq
);
807 static inline struct qib_srq
*to_isrq(struct ib_srq
*ibsrq
)
809 return container_of(ibsrq
, struct qib_srq
, ibsrq
);
812 static inline struct qib_qp
*to_iqp(struct ib_qp
*ibqp
)
814 return container_of(ibqp
, struct qib_qp
, ibqp
);
817 static inline struct qib_ibdev
*to_idev(struct ib_device
*ibdev
)
819 return container_of(ibdev
, struct qib_ibdev
, ibdev
);
823 * Send if not busy or waiting for I/O and either
824 * a RC response is pending or we can process send work requests.
826 static inline int qib_send_ok(struct qib_qp
*qp
)
828 return !(qp
->s_flags
& (QIB_S_BUSY
| QIB_S_ANY_WAIT_IO
)) &&
829 (qp
->s_hdrwords
|| (qp
->s_flags
& QIB_S_RESP_PENDING
) ||
830 !(qp
->s_flags
& QIB_S_ANY_WAIT_SEND
));
833 extern struct workqueue_struct
*qib_cq_wq
;
836 * This must be called with s_lock held.
838 static inline void qib_schedule_send(struct qib_qp
*qp
)
841 queue_work(ib_wq
, &qp
->s_work
);
844 static inline int qib_pkey_ok(u16 pkey1
, u16 pkey2
)
846 u16 p1
= pkey1
& 0x7FFF;
847 u16 p2
= pkey2
& 0x7FFF;
850 * Low 15 bits must be non-zero and match, and
851 * one of the two must be a full member.
853 return p1
&& p1
== p2
&& ((__s16
)pkey1
< 0 || (__s16
)pkey2
< 0);
856 void qib_bad_pqkey(struct qib_ibport
*ibp
, __be16 trap_num
, u32 key
, u32 sl
,
857 u32 qp1
, u32 qp2
, __be16 lid1
, __be16 lid2
);
858 void qib_cap_mask_chg(struct qib_ibport
*ibp
);
859 void qib_sys_guid_chg(struct qib_ibport
*ibp
);
860 void qib_node_desc_chg(struct qib_ibport
*ibp
);
861 int qib_process_mad(struct ib_device
*ibdev
, int mad_flags
, u8 port_num
,
862 struct ib_wc
*in_wc
, struct ib_grh
*in_grh
,
863 struct ib_mad
*in_mad
, struct ib_mad
*out_mad
);
864 int qib_create_agents(struct qib_ibdev
*dev
);
865 void qib_free_agents(struct qib_ibdev
*dev
);
868 * Compare the lower 24 bits of the two values.
869 * Returns an integer <, ==, or > than zero.
871 static inline int qib_cmp24(u32 a
, u32 b
)
873 return (((int) a
) - ((int) b
)) << 8;
876 struct qib_mcast
*qib_mcast_find(struct qib_ibport
*ibp
, union ib_gid
*mgid
);
878 int qib_snapshot_counters(struct qib_pportdata
*ppd
, u64
*swords
,
879 u64
*rwords
, u64
*spkts
, u64
*rpkts
,
882 int qib_get_counters(struct qib_pportdata
*ppd
,
883 struct qib_verbs_counters
*cntrs
);
885 int qib_multicast_attach(struct ib_qp
*ibqp
, union ib_gid
*gid
, u16 lid
);
887 int qib_multicast_detach(struct ib_qp
*ibqp
, union ib_gid
*gid
, u16 lid
);
889 int qib_mcast_tree_empty(struct qib_ibport
*ibp
);
891 __be32
qib_compute_aeth(struct qib_qp
*qp
);
893 struct qib_qp
*qib_lookup_qpn(struct qib_ibport
*ibp
, u32 qpn
);
895 struct ib_qp
*qib_create_qp(struct ib_pd
*ibpd
,
896 struct ib_qp_init_attr
*init_attr
,
897 struct ib_udata
*udata
);
899 int qib_destroy_qp(struct ib_qp
*ibqp
);
901 int qib_error_qp(struct qib_qp
*qp
, enum ib_wc_status err
);
903 int qib_modify_qp(struct ib_qp
*ibqp
, struct ib_qp_attr
*attr
,
904 int attr_mask
, struct ib_udata
*udata
);
906 int qib_query_qp(struct ib_qp
*ibqp
, struct ib_qp_attr
*attr
,
907 int attr_mask
, struct ib_qp_init_attr
*init_attr
);
909 unsigned qib_free_all_qps(struct qib_devdata
*dd
);
911 void qib_init_qpn_table(struct qib_devdata
*dd
, struct qib_qpn_table
*qpt
);
913 void qib_free_qpn_table(struct qib_qpn_table
*qpt
);
915 void qib_get_credit(struct qib_qp
*qp
, u32 aeth
);
917 unsigned qib_pkt_delay(u32 plen
, u8 snd_mult
, u8 rcv_mult
);
919 void qib_verbs_sdma_desc_avail(struct qib_pportdata
*ppd
, unsigned avail
);
921 void qib_put_txreq(struct qib_verbs_txreq
*tx
);
923 int qib_verbs_send(struct qib_qp
*qp
, struct qib_ib_header
*hdr
,
924 u32 hdrwords
, struct qib_sge_state
*ss
, u32 len
);
926 void qib_copy_sge(struct qib_sge_state
*ss
, void *data
, u32 length
,
929 void qib_skip_sge(struct qib_sge_state
*ss
, u32 length
, int release
);
931 void qib_uc_rcv(struct qib_ibport
*ibp
, struct qib_ib_header
*hdr
,
932 int has_grh
, void *data
, u32 tlen
, struct qib_qp
*qp
);
934 void qib_rc_rcv(struct qib_ctxtdata
*rcd
, struct qib_ib_header
*hdr
,
935 int has_grh
, void *data
, u32 tlen
, struct qib_qp
*qp
);
937 int qib_check_ah(struct ib_device
*ibdev
, struct ib_ah_attr
*ah_attr
);
939 void qib_rc_rnr_retry(unsigned long arg
);
941 void qib_rc_send_complete(struct qib_qp
*qp
, struct qib_ib_header
*hdr
);
943 void qib_rc_error(struct qib_qp
*qp
, enum ib_wc_status err
);
945 int qib_post_ud_send(struct qib_qp
*qp
, struct ib_send_wr
*wr
);
947 void qib_ud_rcv(struct qib_ibport
*ibp
, struct qib_ib_header
*hdr
,
948 int has_grh
, void *data
, u32 tlen
, struct qib_qp
*qp
);
950 int qib_alloc_lkey(struct qib_mregion
*mr
, int dma_region
);
952 void qib_free_lkey(struct qib_mregion
*mr
);
954 int qib_lkey_ok(struct qib_lkey_table
*rkt
, struct qib_pd
*pd
,
955 struct qib_sge
*isge
, struct ib_sge
*sge
, int acc
);
957 int qib_rkey_ok(struct qib_qp
*qp
, struct qib_sge
*sge
,
958 u32 len
, u64 vaddr
, u32 rkey
, int acc
);
960 int qib_post_srq_receive(struct ib_srq
*ibsrq
, struct ib_recv_wr
*wr
,
961 struct ib_recv_wr
**bad_wr
);
963 struct ib_srq
*qib_create_srq(struct ib_pd
*ibpd
,
964 struct ib_srq_init_attr
*srq_init_attr
,
965 struct ib_udata
*udata
);
967 int qib_modify_srq(struct ib_srq
*ibsrq
, struct ib_srq_attr
*attr
,
968 enum ib_srq_attr_mask attr_mask
,
969 struct ib_udata
*udata
);
971 int qib_query_srq(struct ib_srq
*ibsrq
, struct ib_srq_attr
*attr
);
973 int qib_destroy_srq(struct ib_srq
*ibsrq
);
975 void qib_cq_enter(struct qib_cq
*cq
, struct ib_wc
*entry
, int sig
);
977 int qib_poll_cq(struct ib_cq
*ibcq
, int num_entries
, struct ib_wc
*entry
);
979 struct ib_cq
*qib_create_cq(struct ib_device
*ibdev
, int entries
,
980 int comp_vector
, struct ib_ucontext
*context
,
981 struct ib_udata
*udata
);
983 int qib_destroy_cq(struct ib_cq
*ibcq
);
985 int qib_req_notify_cq(struct ib_cq
*ibcq
, enum ib_cq_notify_flags notify_flags
);
987 int qib_resize_cq(struct ib_cq
*ibcq
, int cqe
, struct ib_udata
*udata
);
989 struct ib_mr
*qib_get_dma_mr(struct ib_pd
*pd
, int acc
);
991 struct ib_mr
*qib_reg_phys_mr(struct ib_pd
*pd
,
992 struct ib_phys_buf
*buffer_list
,
993 int num_phys_buf
, int acc
, u64
*iova_start
);
995 struct ib_mr
*qib_reg_user_mr(struct ib_pd
*pd
, u64 start
, u64 length
,
996 u64 virt_addr
, int mr_access_flags
,
997 struct ib_udata
*udata
);
999 int qib_dereg_mr(struct ib_mr
*ibmr
);
1001 struct ib_mr
*qib_alloc_fast_reg_mr(struct ib_pd
*pd
, int max_page_list_len
);
1003 struct ib_fast_reg_page_list
*qib_alloc_fast_reg_page_list(
1004 struct ib_device
*ibdev
, int page_list_len
);
1006 void qib_free_fast_reg_page_list(struct ib_fast_reg_page_list
*pl
);
1008 int qib_fast_reg_mr(struct qib_qp
*qp
, struct ib_send_wr
*wr
);
1010 struct ib_fmr
*qib_alloc_fmr(struct ib_pd
*pd
, int mr_access_flags
,
1011 struct ib_fmr_attr
*fmr_attr
);
1013 int qib_map_phys_fmr(struct ib_fmr
*ibfmr
, u64
*page_list
,
1014 int list_len
, u64 iova
);
1016 int qib_unmap_fmr(struct list_head
*fmr_list
);
1018 int qib_dealloc_fmr(struct ib_fmr
*ibfmr
);
1020 static inline void qib_get_mr(struct qib_mregion
*mr
)
1022 atomic_inc(&mr
->refcount
);
1025 static inline void qib_put_mr(struct qib_mregion
*mr
)
1027 if (unlikely(atomic_dec_and_test(&mr
->refcount
)))
1028 complete(&mr
->comp
);
1031 static inline void qib_put_ss(struct qib_sge_state
*ss
)
1033 while (ss
->num_sge
) {
1034 qib_put_mr(ss
->sge
.mr
);
1036 ss
->sge
= *ss
->sg_list
++;
1041 void qib_release_mmap_info(struct kref
*ref
);
1043 struct qib_mmap_info
*qib_create_mmap_info(struct qib_ibdev
*dev
, u32 size
,
1044 struct ib_ucontext
*context
,
1047 void qib_update_mmap_info(struct qib_ibdev
*dev
, struct qib_mmap_info
*ip
,
1048 u32 size
, void *obj
);
1050 int qib_mmap(struct ib_ucontext
*context
, struct vm_area_struct
*vma
);
1052 int qib_get_rwqe(struct qib_qp
*qp
, int wr_id_only
);
1054 void qib_migrate_qp(struct qib_qp
*qp
);
1056 int qib_ruc_check_hdr(struct qib_ibport
*ibp
, struct qib_ib_header
*hdr
,
1057 int has_grh
, struct qib_qp
*qp
, u32 bth0
);
1059 u32
qib_make_grh(struct qib_ibport
*ibp
, struct ib_grh
*hdr
,
1060 struct ib_global_route
*grh
, u32 hwords
, u32 nwords
);
1062 void qib_make_ruc_header(struct qib_qp
*qp
, struct qib_other_headers
*ohdr
,
1063 u32 bth0
, u32 bth2
);
1065 void qib_do_send(struct work_struct
*work
);
1067 void qib_send_complete(struct qib_qp
*qp
, struct qib_swqe
*wqe
,
1068 enum ib_wc_status status
);
1070 void qib_send_rc_ack(struct qib_qp
*qp
);
1072 int qib_make_rc_req(struct qib_qp
*qp
);
1074 int qib_make_uc_req(struct qib_qp
*qp
);
1076 int qib_make_ud_req(struct qib_qp
*qp
);
1078 int qib_register_ib_device(struct qib_devdata
*);
1080 void qib_unregister_ib_device(struct qib_devdata
*);
1082 void qib_ib_rcv(struct qib_ctxtdata
*, void *, void *, u32
);
1084 void qib_ib_piobufavail(struct qib_devdata
*);
1086 unsigned qib_get_npkeys(struct qib_devdata
*);
1088 unsigned qib_get_pkey(struct qib_ibport
*, unsigned);
1090 extern const enum ib_wc_opcode ib_qib_wc_opcode
[];
1093 * Below HCA-independent IB PhysPortState values, returned
1094 * by the f_ibphys_portstate() routine.
1096 #define IB_PHYSPORTSTATE_SLEEP 1
1097 #define IB_PHYSPORTSTATE_POLL 2
1098 #define IB_PHYSPORTSTATE_DISABLED 3
1099 #define IB_PHYSPORTSTATE_CFG_TRAIN 4
1100 #define IB_PHYSPORTSTATE_LINKUP 5
1101 #define IB_PHYSPORTSTATE_LINK_ERR_RECOVER 6
1102 #define IB_PHYSPORTSTATE_CFG_DEBOUNCE 8
1103 #define IB_PHYSPORTSTATE_CFG_IDLE 0xB
1104 #define IB_PHYSPORTSTATE_RECOVERY_RETRAIN 0xC
1105 #define IB_PHYSPORTSTATE_RECOVERY_WAITRMT 0xE
1106 #define IB_PHYSPORTSTATE_RECOVERY_IDLE 0xF
1107 #define IB_PHYSPORTSTATE_CFG_ENH 0x10
1108 #define IB_PHYSPORTSTATE_CFG_WAIT_ENH 0x13
1110 extern const int ib_qib_state_ops
[];
1112 extern __be64 ib_qib_sys_image_guid
; /* in network order */
1114 extern unsigned int ib_qib_lkey_table_size
;
1116 extern unsigned int ib_qib_max_cqes
;
1118 extern unsigned int ib_qib_max_cqs
;
1120 extern unsigned int ib_qib_max_qp_wrs
;
1122 extern unsigned int ib_qib_max_qps
;
1124 extern unsigned int ib_qib_max_sges
;
1126 extern unsigned int ib_qib_max_mcast_grps
;
1128 extern unsigned int ib_qib_max_mcast_qp_attached
;
1130 extern unsigned int ib_qib_max_srqs
;
1132 extern unsigned int ib_qib_max_srq_sges
;
1134 extern unsigned int ib_qib_max_srq_wrs
;
1136 extern const u32 ib_qib_rnr_table
[];
1138 extern struct ib_dma_mapping_ops qib_dma_mapping_ops
;
1140 #endif /* QIB_VERBS_H */