3 * This file is provided under a dual BSD/GPLv2 license. When using or
4 * redistributing this file, you may do so under either license.
8 * Copyright(c) 2015 Intel Corporation.
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of version 2 of the GNU General Public License as
12 * published by the Free Software Foundation.
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
21 * Copyright(c) 2015 Intel Corporation.
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
27 * - Redistributions of source code must retain the above copyright
28 * notice, this list of conditions and the following disclaimer.
29 * - Redistributions in binary form must reproduce the above copyright
30 * notice, this list of conditions and the following disclaimer in
31 * the documentation and/or other materials provided with the
33 * - Neither the name of Intel Corporation nor the names of its
34 * contributors may be used to endorse or promote products derived
35 * from this software without specific prior written permission.
37 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
38 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
39 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
40 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
41 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
42 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
43 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
44 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
45 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
46 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
47 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
54 #include <linux/types.h>
55 #include <linux/seqlock.h>
56 #include <linux/kernel.h>
57 #include <linux/interrupt.h>
58 #include <linux/kref.h>
59 #include <linux/workqueue.h>
60 #include <linux/kthread.h>
61 #include <linux/completion.h>
62 #include <rdma/ib_pack.h>
63 #include <rdma/ib_user_verbs.h>
64 #include <rdma/ib_mad.h>
65 #include <rdma/rdma_vt.h>
66 #include <rdma/rdmavt_qp.h>
67 #include <rdma/rdmavt_cq.h>
70 struct hfi1_pportdata
;
76 #define HFI1_MAX_RDMA_ATOMIC 16
77 #define HFI1_GUIDS_PER_PORT 5
80 * Increment this value if any changes that break userspace ABI
81 * compatibility are made.
83 #define HFI1_UVERBS_ABI_VERSION 2
85 #define IB_SEQ_NAK (3 << 29)
87 /* AETH NAK opcode values */
88 #define IB_RNR_NAK 0x20
89 #define IB_NAK_PSN_ERROR 0x60
90 #define IB_NAK_INVALID_REQUEST 0x61
91 #define IB_NAK_REMOTE_ACCESS_ERROR 0x62
92 #define IB_NAK_REMOTE_OPERATIONAL_ERROR 0x63
93 #define IB_NAK_INVALID_RD_REQUEST 0x64
95 /* IB Performance Manager status values */
96 #define IB_PMA_SAMPLE_STATUS_DONE 0x00
97 #define IB_PMA_SAMPLE_STATUS_STARTED 0x01
98 #define IB_PMA_SAMPLE_STATUS_RUNNING 0x02
100 /* Mandatory IB performance counter select values. */
101 #define IB_PMA_PORT_XMIT_DATA cpu_to_be16(0x0001)
102 #define IB_PMA_PORT_RCV_DATA cpu_to_be16(0x0002)
103 #define IB_PMA_PORT_XMIT_PKTS cpu_to_be16(0x0003)
104 #define IB_PMA_PORT_RCV_PKTS cpu_to_be16(0x0004)
105 #define IB_PMA_PORT_XMIT_WAIT cpu_to_be16(0x0005)
107 #define HFI1_VENDOR_IPG cpu_to_be16(0xFFA0)
109 #define IB_BTH_REQ_ACK BIT(31)
110 #define IB_BTH_SOLICITED BIT(23)
111 #define IB_BTH_MIG_REQ BIT(22)
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 /* flags passed by hfi1_ib_rcv() */
126 HFI1_HAS_GRH
= (1 << 0),
135 struct ib_atomic_eth
{
136 __be32 vaddr
[2]; /* unaligned so access as 2 32-bit words */
153 __be32 atomic_ack_eth
[2];
157 struct ib_atomic_eth atomic_eth
;
160 struct hfi1_other_headers
{
166 * Note that UD packets with a GRH header are 8+40+12+8 = 68 bytes
167 * long (72 w/ imm_data). Only the first 56 bytes of the IB header
168 * will be in the eager header buffer. The remaining 12 or 16 bytes
169 * are in the data buffer.
171 struct hfi1_ib_header
{
176 struct hfi1_other_headers oth
;
178 struct hfi1_other_headers oth
;
182 struct ahg_ib_header
{
183 struct sdma_engine
*sde
;
188 struct hfi1_ib_header ibh
;
191 struct hfi1_pio_header
{
193 struct hfi1_ib_header hdr
;
197 * used for force cacheline alignment for AHG
199 struct tx_pio_header
{
200 struct hfi1_pio_header phdr
;
201 } ____cacheline_aligned
;
204 * hfi1 specific data structures that will be hidden from rvt after the queue
205 * pair is made common
207 struct hfi1_qp_priv
{
208 struct ahg_ib_header
*s_hdr
; /* next packet header to send */
209 struct sdma_engine
*s_sde
; /* current sde */
210 u8 s_sc
; /* SC[0..4] for next packet */
211 u8 r_adefered
; /* number of acks defered */
212 struct iowait s_iowait
;
213 struct rvt_qp
*owner
;
217 * This structure is used to hold commonly lookedup and computed values during
218 * the send engine progress.
220 struct hfi1_pkt_state
{
221 struct hfi1_ibdev
*dev
;
222 struct hfi1_ibport
*ibp
;
223 struct hfi1_pportdata
*ppd
;
226 #define HFI1_PSN_CREDIT 16
228 struct hfi1_opcode_stats
{
229 u64 n_packets
; /* number of packets */
230 u64 n_bytes
; /* total number of bytes */
233 struct hfi1_opcode_stats_perctx
{
234 struct hfi1_opcode_stats stats
[256];
237 static inline void inc_opstats(
239 struct hfi1_opcode_stats
*stats
)
241 #ifdef CONFIG_DEBUG_FS
242 stats
->n_bytes
+= tlen
;
248 struct rvt_qp __rcu
*qp
[2];
249 struct rvt_ibport rvp
;
251 __be64 guids
[HFI1_GUIDS_PER_PORT
- 1]; /* writable GUIDs */
253 /* the first 16 entries are sl_to_vl for !OPA */
259 struct rvt_dev_info rdi
; /* Must be first */
261 /* QP numbers are shared by all IB ports */
262 /* protect wait lists */
263 seqlock_t iowait_lock
;
264 struct list_head txwait
; /* list for wait verbs_txreq */
265 struct list_head memwait
; /* list for wait kernel memory */
266 struct list_head txreq_free
;
267 struct kmem_cache
*verbs_txreq_cache
;
268 struct timer_list mem_timer
;
274 #ifdef CONFIG_DEBUG_FS
275 /* per HFI debugfs */
276 struct dentry
*hfi1_ibdev_dbg
;
277 /* per HFI symlinks to above */
278 struct dentry
*hfi1_ibdev_link
;
282 static inline struct hfi1_ibdev
*to_idev(struct ib_device
*ibdev
)
284 struct rvt_dev_info
*rdi
;
286 rdi
= container_of(ibdev
, struct rvt_dev_info
, ibdev
);
287 return container_of(rdi
, struct hfi1_ibdev
, rdi
);
290 static inline struct rvt_qp
*iowait_to_qp(struct iowait
*s_iowait
)
292 struct hfi1_qp_priv
*priv
;
294 priv
= container_of(s_iowait
, struct hfi1_qp_priv
, s_iowait
);
299 * Send if not busy or waiting for I/O and either
300 * a RC response is pending or we can process send work requests.
302 static inline int hfi1_send_ok(struct rvt_qp
*qp
)
304 return !(qp
->s_flags
& (RVT_S_BUSY
| RVT_S_ANY_WAIT_IO
)) &&
305 (qp
->s_hdrwords
|| (qp
->s_flags
& RVT_S_RESP_PENDING
) ||
306 !(qp
->s_flags
& RVT_S_ANY_WAIT_SEND
));
310 * This must be called with s_lock held.
312 void hfi1_bad_pqkey(struct hfi1_ibport
*ibp
, __be16 trap_num
, u32 key
, u32 sl
,
313 u32 qp1
, u32 qp2
, u16 lid1
, u16 lid2
);
314 void hfi1_cap_mask_chg(struct rvt_dev_info
*rdi
, u8 port_num
);
315 void hfi1_sys_guid_chg(struct hfi1_ibport
*ibp
);
316 void hfi1_node_desc_chg(struct hfi1_ibport
*ibp
);
317 int hfi1_process_mad(struct ib_device
*ibdev
, int mad_flags
, u8 port
,
318 const struct ib_wc
*in_wc
, const struct ib_grh
*in_grh
,
319 const struct ib_mad_hdr
*in_mad
, size_t in_mad_size
,
320 struct ib_mad_hdr
*out_mad
, size_t *out_mad_size
,
321 u16
*out_mad_pkey_index
);
324 * The PSN_MASK and PSN_SHIFT allow for
325 * 1) comparing two PSNs
326 * 2) returning the PSN with any upper bits masked
327 * 3) returning the difference between to PSNs
329 * The number of significant bits in the PSN must
330 * necessarily be at least one bit less than
331 * the container holding the PSN.
333 #ifndef CONFIG_HFI1_VERBS_31BIT_PSN
334 #define PSN_MASK 0xFFFFFF
337 #define PSN_MASK 0x7FFFFFFF
340 #define PSN_MODIFY_MASK 0xFFFFFF
342 /* Number of bits to pay attention to in the opcode for checking qp type */
343 #define OPCODE_QP_MASK 0xE0
346 * Compare the lower 24 bits of the msn values.
347 * Returns an integer <, ==, or > than zero.
349 static inline int cmp_msn(u32 a
, u32 b
)
351 return (((int) a
) - ((int) b
)) << 8;
356 * Returns an integer <, ==, or > than zero.
358 static inline int cmp_psn(u32 a
, u32 b
)
360 return (((int) a
) - ((int) b
)) << PSN_SHIFT
;
366 static inline u32
mask_psn(u32 a
)
372 * Return delta between two PSNs
374 static inline u32
delta_psn(u32 a
, u32 b
)
376 return (((int)a
- (int)b
) << PSN_SHIFT
) >> PSN_SHIFT
;
380 void hfi1_put_txreq(struct verbs_txreq
*tx
);
382 int hfi1_verbs_send(struct rvt_qp
*qp
, struct hfi1_pkt_state
*ps
);
384 void hfi1_copy_sge(struct rvt_sge_state
*ss
, void *data
, u32 length
,
385 int release
, int copy_last
);
387 void hfi1_skip_sge(struct rvt_sge_state
*ss
, u32 length
, int release
);
389 void hfi1_cnp_rcv(struct hfi1_packet
*packet
);
391 void hfi1_uc_rcv(struct hfi1_packet
*packet
);
393 void hfi1_rc_rcv(struct hfi1_packet
*packet
);
396 struct hfi1_ctxtdata
*rcd
,
397 struct hfi1_ib_header
*hdr
,
401 u8
ah_to_sc(struct ib_device
*ibdev
, struct ib_ah_attr
*ah_attr
);
403 struct ib_ah
*hfi1_create_qp0_ah(struct hfi1_ibport
*ibp
, u16 dlid
);
405 void hfi1_rc_rnr_retry(unsigned long arg
);
407 void hfi1_rc_send_complete(struct rvt_qp
*qp
, struct hfi1_ib_header
*hdr
);
409 void hfi1_rc_error(struct rvt_qp
*qp
, enum ib_wc_status err
);
411 void hfi1_ud_rcv(struct hfi1_packet
*packet
);
413 int hfi1_lookup_pkey_idx(struct hfi1_ibport
*ibp
, u16 pkey
);
415 int hfi1_rvt_get_rwqe(struct rvt_qp
*qp
, int wr_id_only
);
417 void hfi1_migrate_qp(struct rvt_qp
*qp
);
419 int hfi1_check_modify_qp(struct rvt_qp
*qp
, struct ib_qp_attr
*attr
,
420 int attr_mask
, struct ib_udata
*udata
);
422 void hfi1_modify_qp(struct rvt_qp
*qp
, struct ib_qp_attr
*attr
,
423 int attr_mask
, struct ib_udata
*udata
);
425 int hfi1_check_send_wr(struct rvt_qp
*qp
, struct ib_send_wr
*wr
);
427 int hfi1_ruc_check_hdr(struct hfi1_ibport
*ibp
, struct hfi1_ib_header
*hdr
,
428 int has_grh
, struct rvt_qp
*qp
, u32 bth0
);
430 u32
hfi1_make_grh(struct hfi1_ibport
*ibp
, struct ib_grh
*hdr
,
431 struct ib_global_route
*grh
, u32 hwords
, u32 nwords
);
433 void hfi1_make_ruc_header(struct rvt_qp
*qp
, struct hfi1_other_headers
*ohdr
,
434 u32 bth0
, u32 bth2
, int middle
);
436 void _hfi1_do_send(struct work_struct
*work
);
438 void hfi1_do_send(struct rvt_qp
*qp
);
440 void hfi1_send_complete(struct rvt_qp
*qp
, struct rvt_swqe
*wqe
,
441 enum ib_wc_status status
);
443 void hfi1_send_rc_ack(struct hfi1_ctxtdata
*, struct rvt_qp
*qp
, int is_fecn
);
445 int hfi1_make_rc_req(struct rvt_qp
*qp
);
447 int hfi1_make_uc_req(struct rvt_qp
*qp
);
449 int hfi1_make_ud_req(struct rvt_qp
*qp
);
451 int hfi1_register_ib_device(struct hfi1_devdata
*);
453 void hfi1_unregister_ib_device(struct hfi1_devdata
*);
455 void hfi1_ib_rcv(struct hfi1_packet
*packet
);
457 unsigned hfi1_get_npkeys(struct hfi1_devdata
*);
459 int hfi1_verbs_send_dma(struct rvt_qp
*qp
, struct hfi1_pkt_state
*ps
,
462 int hfi1_verbs_send_pio(struct rvt_qp
*qp
, struct hfi1_pkt_state
*ps
,
465 struct send_context
*qp_to_send_context(struct rvt_qp
*qp
, u8 sc5
);
467 extern const enum ib_wc_opcode ib_hfi1_wc_opcode
[];
469 extern const u8 hdr_len_by_opcode
[];
471 extern const int ib_rvt_state_ops
[];
473 extern __be64 ib_hfi1_sys_image_guid
; /* in network order */
475 extern unsigned int hfi1_max_cqes
;
477 extern unsigned int hfi1_max_cqs
;
479 extern unsigned int hfi1_max_qp_wrs
;
481 extern unsigned int hfi1_max_qps
;
483 extern unsigned int hfi1_max_sges
;
485 extern unsigned int hfi1_max_mcast_grps
;
487 extern unsigned int hfi1_max_mcast_qp_attached
;
489 extern unsigned int hfi1_max_srqs
;
491 extern unsigned int hfi1_max_srq_sges
;
493 extern unsigned int hfi1_max_srq_wrs
;
495 extern const u32 ib_hfi1_rnr_table
[];
497 #endif /* HFI1_VERBS_H */