18c2ecf20Sopenharmony_ci/*
28c2ecf20Sopenharmony_ci * Copyright(c) 2015 - 2018 Intel Corporation.
38c2ecf20Sopenharmony_ci *
48c2ecf20Sopenharmony_ci * This file is provided under a dual BSD/GPLv2 license.  When using or
58c2ecf20Sopenharmony_ci * redistributing this file, you may do so under either license.
68c2ecf20Sopenharmony_ci *
78c2ecf20Sopenharmony_ci * GPL LICENSE SUMMARY
88c2ecf20Sopenharmony_ci *
98c2ecf20Sopenharmony_ci * This program is free software; you can redistribute it and/or modify
108c2ecf20Sopenharmony_ci * it under the terms of version 2 of the GNU General Public License as
118c2ecf20Sopenharmony_ci * published by the Free Software Foundation.
128c2ecf20Sopenharmony_ci *
138c2ecf20Sopenharmony_ci * This program is distributed in the hope that it will be useful, but
148c2ecf20Sopenharmony_ci * WITHOUT ANY WARRANTY; without even the implied warranty of
158c2ecf20Sopenharmony_ci * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
168c2ecf20Sopenharmony_ci * General Public License for more details.
178c2ecf20Sopenharmony_ci *
188c2ecf20Sopenharmony_ci * BSD LICENSE
198c2ecf20Sopenharmony_ci *
208c2ecf20Sopenharmony_ci * Redistribution and use in source and binary forms, with or without
218c2ecf20Sopenharmony_ci * modification, are permitted provided that the following conditions
228c2ecf20Sopenharmony_ci * are met:
238c2ecf20Sopenharmony_ci *
248c2ecf20Sopenharmony_ci *  - Redistributions of source code must retain the above copyright
258c2ecf20Sopenharmony_ci *    notice, this list of conditions and the following disclaimer.
268c2ecf20Sopenharmony_ci *  - Redistributions in binary form must reproduce the above copyright
278c2ecf20Sopenharmony_ci *    notice, this list of conditions and the following disclaimer in
288c2ecf20Sopenharmony_ci *    the documentation and/or other materials provided with the
298c2ecf20Sopenharmony_ci *    distribution.
308c2ecf20Sopenharmony_ci *  - Neither the name of Intel Corporation nor the names of its
318c2ecf20Sopenharmony_ci *    contributors may be used to endorse or promote products derived
328c2ecf20Sopenharmony_ci *    from this software without specific prior written permission.
338c2ecf20Sopenharmony_ci *
348c2ecf20Sopenharmony_ci * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
358c2ecf20Sopenharmony_ci * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
368c2ecf20Sopenharmony_ci * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
378c2ecf20Sopenharmony_ci * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
388c2ecf20Sopenharmony_ci * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
398c2ecf20Sopenharmony_ci * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
408c2ecf20Sopenharmony_ci * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
418c2ecf20Sopenharmony_ci * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
428c2ecf20Sopenharmony_ci * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
438c2ecf20Sopenharmony_ci * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
448c2ecf20Sopenharmony_ci * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
458c2ecf20Sopenharmony_ci *
468c2ecf20Sopenharmony_ci */
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_ci#ifndef HFI1_VERBS_H
498c2ecf20Sopenharmony_ci#define HFI1_VERBS_H
508c2ecf20Sopenharmony_ci
518c2ecf20Sopenharmony_ci#include <linux/types.h>
528c2ecf20Sopenharmony_ci#include <linux/seqlock.h>
538c2ecf20Sopenharmony_ci#include <linux/kernel.h>
548c2ecf20Sopenharmony_ci#include <linux/interrupt.h>
558c2ecf20Sopenharmony_ci#include <linux/kref.h>
568c2ecf20Sopenharmony_ci#include <linux/workqueue.h>
578c2ecf20Sopenharmony_ci#include <linux/kthread.h>
588c2ecf20Sopenharmony_ci#include <linux/completion.h>
598c2ecf20Sopenharmony_ci#include <linux/slab.h>
608c2ecf20Sopenharmony_ci#include <rdma/ib_pack.h>
618c2ecf20Sopenharmony_ci#include <rdma/ib_user_verbs.h>
628c2ecf20Sopenharmony_ci#include <rdma/ib_mad.h>
638c2ecf20Sopenharmony_ci#include <rdma/ib_hdrs.h>
648c2ecf20Sopenharmony_ci#include <rdma/rdma_vt.h>
658c2ecf20Sopenharmony_ci#include <rdma/rdmavt_qp.h>
668c2ecf20Sopenharmony_ci#include <rdma/rdmavt_cq.h>
678c2ecf20Sopenharmony_ci
688c2ecf20Sopenharmony_cistruct hfi1_ctxtdata;
698c2ecf20Sopenharmony_cistruct hfi1_pportdata;
708c2ecf20Sopenharmony_cistruct hfi1_devdata;
718c2ecf20Sopenharmony_cistruct hfi1_packet;
728c2ecf20Sopenharmony_ci
738c2ecf20Sopenharmony_ci#include "iowait.h"
748c2ecf20Sopenharmony_ci#include "tid_rdma.h"
758c2ecf20Sopenharmony_ci#include "opfn.h"
768c2ecf20Sopenharmony_ci
778c2ecf20Sopenharmony_ci#define HFI1_MAX_RDMA_ATOMIC     16
788c2ecf20Sopenharmony_ci
798c2ecf20Sopenharmony_ci/*
808c2ecf20Sopenharmony_ci * Increment this value if any changes that break userspace ABI
818c2ecf20Sopenharmony_ci * compatibility are made.
828c2ecf20Sopenharmony_ci */
838c2ecf20Sopenharmony_ci#define HFI1_UVERBS_ABI_VERSION       2
848c2ecf20Sopenharmony_ci
858c2ecf20Sopenharmony_ci/* IB Performance Manager status values */
868c2ecf20Sopenharmony_ci#define IB_PMA_SAMPLE_STATUS_DONE       0x00
878c2ecf20Sopenharmony_ci#define IB_PMA_SAMPLE_STATUS_STARTED    0x01
888c2ecf20Sopenharmony_ci#define IB_PMA_SAMPLE_STATUS_RUNNING    0x02
898c2ecf20Sopenharmony_ci
908c2ecf20Sopenharmony_ci/* Mandatory IB performance counter select values. */
918c2ecf20Sopenharmony_ci#define IB_PMA_PORT_XMIT_DATA   cpu_to_be16(0x0001)
928c2ecf20Sopenharmony_ci#define IB_PMA_PORT_RCV_DATA    cpu_to_be16(0x0002)
938c2ecf20Sopenharmony_ci#define IB_PMA_PORT_XMIT_PKTS   cpu_to_be16(0x0003)
948c2ecf20Sopenharmony_ci#define IB_PMA_PORT_RCV_PKTS    cpu_to_be16(0x0004)
958c2ecf20Sopenharmony_ci#define IB_PMA_PORT_XMIT_WAIT   cpu_to_be16(0x0005)
968c2ecf20Sopenharmony_ci
978c2ecf20Sopenharmony_ci#define HFI1_VENDOR_IPG		cpu_to_be16(0xFFA0)
988c2ecf20Sopenharmony_ci
998c2ecf20Sopenharmony_ci#define IB_DEFAULT_GID_PREFIX	cpu_to_be64(0xfe80000000000000ULL)
1008c2ecf20Sopenharmony_ci#define OPA_BTH_MIG_REQ		BIT(31)
1018c2ecf20Sopenharmony_ci
1028c2ecf20Sopenharmony_ci#define RC_OP(x) IB_OPCODE_RC_##x
1038c2ecf20Sopenharmony_ci#define UC_OP(x) IB_OPCODE_UC_##x
1048c2ecf20Sopenharmony_ci
1058c2ecf20Sopenharmony_ci/* flags passed by hfi1_ib_rcv() */
1068c2ecf20Sopenharmony_cienum {
1078c2ecf20Sopenharmony_ci	HFI1_HAS_GRH = (1 << 0),
1088c2ecf20Sopenharmony_ci};
1098c2ecf20Sopenharmony_ci
1108c2ecf20Sopenharmony_ci#define LRH_16B_BYTES (sizeof_field(struct hfi1_16b_header, lrh))
1118c2ecf20Sopenharmony_ci#define LRH_16B_DWORDS (LRH_16B_BYTES / sizeof(u32))
1128c2ecf20Sopenharmony_ci#define LRH_9B_BYTES (sizeof_field(struct ib_header, lrh))
1138c2ecf20Sopenharmony_ci#define LRH_9B_DWORDS (LRH_9B_BYTES / sizeof(u32))
1148c2ecf20Sopenharmony_ci
1158c2ecf20Sopenharmony_ci/* 24Bits for qpn, upper 8Bits reserved */
1168c2ecf20Sopenharmony_cistruct opa_16b_mgmt {
1178c2ecf20Sopenharmony_ci	__be32 dest_qpn;
1188c2ecf20Sopenharmony_ci	__be32 src_qpn;
1198c2ecf20Sopenharmony_ci};
1208c2ecf20Sopenharmony_ci
1218c2ecf20Sopenharmony_cistruct hfi1_16b_header {
1228c2ecf20Sopenharmony_ci	u32 lrh[4];
1238c2ecf20Sopenharmony_ci	union {
1248c2ecf20Sopenharmony_ci		struct {
1258c2ecf20Sopenharmony_ci			struct ib_grh grh;
1268c2ecf20Sopenharmony_ci			struct ib_other_headers oth;
1278c2ecf20Sopenharmony_ci		} l;
1288c2ecf20Sopenharmony_ci		struct ib_other_headers oth;
1298c2ecf20Sopenharmony_ci		struct opa_16b_mgmt mgmt;
1308c2ecf20Sopenharmony_ci	} u;
1318c2ecf20Sopenharmony_ci} __packed;
1328c2ecf20Sopenharmony_ci
1338c2ecf20Sopenharmony_cistruct hfi1_opa_header {
1348c2ecf20Sopenharmony_ci	union {
1358c2ecf20Sopenharmony_ci		struct ib_header ibh; /* 9B header */
1368c2ecf20Sopenharmony_ci		struct hfi1_16b_header opah; /* 16B header */
1378c2ecf20Sopenharmony_ci	};
1388c2ecf20Sopenharmony_ci	u8 hdr_type; /* 9B or 16B */
1398c2ecf20Sopenharmony_ci} __packed;
1408c2ecf20Sopenharmony_ci
1418c2ecf20Sopenharmony_cistruct hfi1_ahg_info {
1428c2ecf20Sopenharmony_ci	u32 ahgdesc[2];
1438c2ecf20Sopenharmony_ci	u16 tx_flags;
1448c2ecf20Sopenharmony_ci	u8 ahgcount;
1458c2ecf20Sopenharmony_ci	u8 ahgidx;
1468c2ecf20Sopenharmony_ci};
1478c2ecf20Sopenharmony_ci
1488c2ecf20Sopenharmony_cistruct hfi1_sdma_header {
1498c2ecf20Sopenharmony_ci	__le64 pbc;
1508c2ecf20Sopenharmony_ci	struct hfi1_opa_header hdr;
1518c2ecf20Sopenharmony_ci} __packed;
1528c2ecf20Sopenharmony_ci
1538c2ecf20Sopenharmony_ci/*
1548c2ecf20Sopenharmony_ci * hfi1 specific data structures that will be hidden from rvt after the queue
1558c2ecf20Sopenharmony_ci * pair is made common
1568c2ecf20Sopenharmony_ci */
1578c2ecf20Sopenharmony_cistruct hfi1_qp_priv {
1588c2ecf20Sopenharmony_ci	struct hfi1_ahg_info *s_ahg;              /* ahg info for next header */
1598c2ecf20Sopenharmony_ci	struct sdma_engine *s_sde;                /* current sde */
1608c2ecf20Sopenharmony_ci	struct send_context *s_sendcontext;       /* current sendcontext */
1618c2ecf20Sopenharmony_ci	struct hfi1_ctxtdata *rcd;                /* QP's receive context */
1628c2ecf20Sopenharmony_ci	struct page **pages;                      /* for TID page scan */
1638c2ecf20Sopenharmony_ci	u32 tid_enqueue;                          /* saved when tid waited */
1648c2ecf20Sopenharmony_ci	u8 s_sc;		                  /* SC[0..4] for next packet */
1658c2ecf20Sopenharmony_ci	struct iowait s_iowait;
1668c2ecf20Sopenharmony_ci	struct timer_list s_tid_timer;            /* for timing tid wait */
1678c2ecf20Sopenharmony_ci	struct timer_list s_tid_retry_timer;      /* for timing tid ack */
1688c2ecf20Sopenharmony_ci	struct list_head tid_wait;                /* for queueing tid space */
1698c2ecf20Sopenharmony_ci	struct hfi1_opfn_data opfn;
1708c2ecf20Sopenharmony_ci	struct tid_flow_state flow_state;
1718c2ecf20Sopenharmony_ci	struct tid_rdma_qp_params tid_rdma;
1728c2ecf20Sopenharmony_ci	struct rvt_qp *owner;
1738c2ecf20Sopenharmony_ci	u16 s_running_pkt_size;
1748c2ecf20Sopenharmony_ci	u8 hdr_type; /* 9B or 16B */
1758c2ecf20Sopenharmony_ci	struct rvt_sge_state tid_ss;       /* SGE state pointer for 2nd leg */
1768c2ecf20Sopenharmony_ci	atomic_t n_requests;               /* # of TID RDMA requests in the */
1778c2ecf20Sopenharmony_ci					   /* queue */
1788c2ecf20Sopenharmony_ci	atomic_t n_tid_requests;            /* # of sent TID RDMA requests */
1798c2ecf20Sopenharmony_ci	unsigned long tid_timer_timeout_jiffies;
1808c2ecf20Sopenharmony_ci	unsigned long tid_retry_timeout_jiffies;
1818c2ecf20Sopenharmony_ci
1828c2ecf20Sopenharmony_ci	/* variables for the TID RDMA SE state machine */
1838c2ecf20Sopenharmony_ci	u8 s_state;
1848c2ecf20Sopenharmony_ci	u8 s_retry;
1858c2ecf20Sopenharmony_ci	u8 rnr_nak_state;       /* RNR NAK state */
1868c2ecf20Sopenharmony_ci	u8 s_nak_state;
1878c2ecf20Sopenharmony_ci	u32 s_nak_psn;
1888c2ecf20Sopenharmony_ci	u32 s_flags;
1898c2ecf20Sopenharmony_ci	u32 s_tid_cur;
1908c2ecf20Sopenharmony_ci	u32 s_tid_head;
1918c2ecf20Sopenharmony_ci	u32 s_tid_tail;
1928c2ecf20Sopenharmony_ci	u32 r_tid_head;     /* Most recently added TID RDMA request */
1938c2ecf20Sopenharmony_ci	u32 r_tid_tail;     /* the last completed TID RDMA request */
1948c2ecf20Sopenharmony_ci	u32 r_tid_ack;      /* the TID RDMA request to be ACK'ed */
1958c2ecf20Sopenharmony_ci	u32 r_tid_alloc;    /* Request for which we are allocating resources */
1968c2ecf20Sopenharmony_ci	u32 pending_tid_w_segs; /* Num of pending tid write segments */
1978c2ecf20Sopenharmony_ci	u32 pending_tid_w_resp; /* Num of pending tid write responses */
1988c2ecf20Sopenharmony_ci	u32 alloc_w_segs;       /* Number of segments for which write */
1998c2ecf20Sopenharmony_ci			       /* resources have been allocated for this QP */
2008c2ecf20Sopenharmony_ci
2018c2ecf20Sopenharmony_ci	/* For TID RDMA READ */
2028c2ecf20Sopenharmony_ci	u32 tid_r_reqs;         /* Num of tid reads requested */
2038c2ecf20Sopenharmony_ci	u32 tid_r_comp;         /* Num of tid reads completed */
2048c2ecf20Sopenharmony_ci	u32 pending_tid_r_segs; /* Num of pending tid read segments */
2058c2ecf20Sopenharmony_ci	u16 pkts_ps;            /* packets per segment */
2068c2ecf20Sopenharmony_ci	u8 timeout_shift;       /* account for number of packets per segment */
2078c2ecf20Sopenharmony_ci
2088c2ecf20Sopenharmony_ci	u32 r_next_psn_kdeth;
2098c2ecf20Sopenharmony_ci	u32 r_next_psn_kdeth_save;
2108c2ecf20Sopenharmony_ci	u32 s_resync_psn;
2118c2ecf20Sopenharmony_ci	u8 sync_pt;           /* Set when QP reaches sync point */
2128c2ecf20Sopenharmony_ci	u8 resync;
2138c2ecf20Sopenharmony_ci};
2148c2ecf20Sopenharmony_ci
2158c2ecf20Sopenharmony_ci#define HFI1_QP_WQE_INVALID   ((u32)-1)
2168c2ecf20Sopenharmony_ci
2178c2ecf20Sopenharmony_cistruct hfi1_swqe_priv {
2188c2ecf20Sopenharmony_ci	struct tid_rdma_request tid_req;
2198c2ecf20Sopenharmony_ci	struct rvt_sge_state ss;  /* Used for TID RDMA READ Request */
2208c2ecf20Sopenharmony_ci};
2218c2ecf20Sopenharmony_ci
2228c2ecf20Sopenharmony_cistruct hfi1_ack_priv {
2238c2ecf20Sopenharmony_ci	struct rvt_sge_state ss;               /* used for TID WRITE RESP */
2248c2ecf20Sopenharmony_ci	struct tid_rdma_request tid_req;
2258c2ecf20Sopenharmony_ci};
2268c2ecf20Sopenharmony_ci
2278c2ecf20Sopenharmony_ci/*
2288c2ecf20Sopenharmony_ci * This structure is used to hold commonly lookedup and computed values during
2298c2ecf20Sopenharmony_ci * the send engine progress.
2308c2ecf20Sopenharmony_ci */
2318c2ecf20Sopenharmony_cistruct iowait_work;
2328c2ecf20Sopenharmony_cistruct hfi1_pkt_state {
2338c2ecf20Sopenharmony_ci	struct hfi1_ibdev *dev;
2348c2ecf20Sopenharmony_ci	struct hfi1_ibport *ibp;
2358c2ecf20Sopenharmony_ci	struct hfi1_pportdata *ppd;
2368c2ecf20Sopenharmony_ci	struct verbs_txreq *s_txreq;
2378c2ecf20Sopenharmony_ci	struct iowait_work *wait;
2388c2ecf20Sopenharmony_ci	unsigned long flags;
2398c2ecf20Sopenharmony_ci	unsigned long timeout;
2408c2ecf20Sopenharmony_ci	unsigned long timeout_int;
2418c2ecf20Sopenharmony_ci	int cpu;
2428c2ecf20Sopenharmony_ci	u8 opcode;
2438c2ecf20Sopenharmony_ci	bool in_thread;
2448c2ecf20Sopenharmony_ci	bool pkts_sent;
2458c2ecf20Sopenharmony_ci};
2468c2ecf20Sopenharmony_ci
2478c2ecf20Sopenharmony_ci#define HFI1_PSN_CREDIT  16
2488c2ecf20Sopenharmony_ci
2498c2ecf20Sopenharmony_cistruct hfi1_opcode_stats {
2508c2ecf20Sopenharmony_ci	u64 n_packets;          /* number of packets */
2518c2ecf20Sopenharmony_ci	u64 n_bytes;            /* total number of bytes */
2528c2ecf20Sopenharmony_ci};
2538c2ecf20Sopenharmony_ci
2548c2ecf20Sopenharmony_cistruct hfi1_opcode_stats_perctx {
2558c2ecf20Sopenharmony_ci	struct hfi1_opcode_stats stats[256];
2568c2ecf20Sopenharmony_ci};
2578c2ecf20Sopenharmony_ci
2588c2ecf20Sopenharmony_cistatic inline void inc_opstats(
2598c2ecf20Sopenharmony_ci	u32 tlen,
2608c2ecf20Sopenharmony_ci	struct hfi1_opcode_stats *stats)
2618c2ecf20Sopenharmony_ci{
2628c2ecf20Sopenharmony_ci#ifdef CONFIG_DEBUG_FS
2638c2ecf20Sopenharmony_ci	stats->n_bytes += tlen;
2648c2ecf20Sopenharmony_ci	stats->n_packets++;
2658c2ecf20Sopenharmony_ci#endif
2668c2ecf20Sopenharmony_ci}
2678c2ecf20Sopenharmony_ci
2688c2ecf20Sopenharmony_cistruct hfi1_ibport {
2698c2ecf20Sopenharmony_ci	struct rvt_qp __rcu *qp[2];
2708c2ecf20Sopenharmony_ci	struct rvt_ibport rvp;
2718c2ecf20Sopenharmony_ci
2728c2ecf20Sopenharmony_ci	/* the first 16 entries are sl_to_vl for !OPA */
2738c2ecf20Sopenharmony_ci	u8 sl_to_sc[32];
2748c2ecf20Sopenharmony_ci	u8 sc_to_sl[32];
2758c2ecf20Sopenharmony_ci};
2768c2ecf20Sopenharmony_ci
2778c2ecf20Sopenharmony_cistruct hfi1_ibdev {
2788c2ecf20Sopenharmony_ci	struct rvt_dev_info rdi; /* Must be first */
2798c2ecf20Sopenharmony_ci
2808c2ecf20Sopenharmony_ci	/* QP numbers are shared by all IB ports */
2818c2ecf20Sopenharmony_ci	/* protect txwait list */
2828c2ecf20Sopenharmony_ci	seqlock_t txwait_lock ____cacheline_aligned_in_smp;
2838c2ecf20Sopenharmony_ci	struct list_head txwait;        /* list for wait verbs_txreq */
2848c2ecf20Sopenharmony_ci	struct list_head memwait;       /* list for wait kernel memory */
2858c2ecf20Sopenharmony_ci	struct kmem_cache *verbs_txreq_cache;
2868c2ecf20Sopenharmony_ci	u64 n_txwait;
2878c2ecf20Sopenharmony_ci	u64 n_kmem_wait;
2888c2ecf20Sopenharmony_ci	u64 n_tidwait;
2898c2ecf20Sopenharmony_ci
2908c2ecf20Sopenharmony_ci	/* protect iowait lists */
2918c2ecf20Sopenharmony_ci	seqlock_t iowait_lock ____cacheline_aligned_in_smp;
2928c2ecf20Sopenharmony_ci	u64 n_piowait;
2938c2ecf20Sopenharmony_ci	u64 n_piodrain;
2948c2ecf20Sopenharmony_ci	struct timer_list mem_timer;
2958c2ecf20Sopenharmony_ci
2968c2ecf20Sopenharmony_ci#ifdef CONFIG_DEBUG_FS
2978c2ecf20Sopenharmony_ci	/* per HFI debugfs */
2988c2ecf20Sopenharmony_ci	struct dentry *hfi1_ibdev_dbg;
2998c2ecf20Sopenharmony_ci	/* per HFI symlinks to above */
3008c2ecf20Sopenharmony_ci	struct dentry *hfi1_ibdev_link;
3018c2ecf20Sopenharmony_ci#ifdef CONFIG_FAULT_INJECTION
3028c2ecf20Sopenharmony_ci	struct fault *fault;
3038c2ecf20Sopenharmony_ci#endif
3048c2ecf20Sopenharmony_ci#endif
3058c2ecf20Sopenharmony_ci};
3068c2ecf20Sopenharmony_ci
3078c2ecf20Sopenharmony_cistatic inline struct hfi1_ibdev *to_idev(struct ib_device *ibdev)
3088c2ecf20Sopenharmony_ci{
3098c2ecf20Sopenharmony_ci	struct rvt_dev_info *rdi;
3108c2ecf20Sopenharmony_ci
3118c2ecf20Sopenharmony_ci	rdi = container_of(ibdev, struct rvt_dev_info, ibdev);
3128c2ecf20Sopenharmony_ci	return container_of(rdi, struct hfi1_ibdev, rdi);
3138c2ecf20Sopenharmony_ci}
3148c2ecf20Sopenharmony_ci
3158c2ecf20Sopenharmony_cistatic inline struct rvt_qp *iowait_to_qp(struct iowait *s_iowait)
3168c2ecf20Sopenharmony_ci{
3178c2ecf20Sopenharmony_ci	struct hfi1_qp_priv *priv;
3188c2ecf20Sopenharmony_ci
3198c2ecf20Sopenharmony_ci	priv = container_of(s_iowait, struct hfi1_qp_priv, s_iowait);
3208c2ecf20Sopenharmony_ci	return priv->owner;
3218c2ecf20Sopenharmony_ci}
3228c2ecf20Sopenharmony_ci
3238c2ecf20Sopenharmony_ci/*
3248c2ecf20Sopenharmony_ci * This must be called with s_lock held.
3258c2ecf20Sopenharmony_ci */
3268c2ecf20Sopenharmony_civoid hfi1_bad_pkey(struct hfi1_ibport *ibp, u32 key, u32 sl,
3278c2ecf20Sopenharmony_ci		   u32 qp1, u32 qp2, u32 lid1, u32 lid2);
3288c2ecf20Sopenharmony_civoid hfi1_cap_mask_chg(struct rvt_dev_info *rdi, u8 port_num);
3298c2ecf20Sopenharmony_civoid hfi1_sys_guid_chg(struct hfi1_ibport *ibp);
3308c2ecf20Sopenharmony_civoid hfi1_node_desc_chg(struct hfi1_ibport *ibp);
3318c2ecf20Sopenharmony_ciint hfi1_process_mad(struct ib_device *ibdev, int mad_flags, u8 port,
3328c2ecf20Sopenharmony_ci		     const struct ib_wc *in_wc, const struct ib_grh *in_grh,
3338c2ecf20Sopenharmony_ci		     const struct ib_mad *in_mad, struct ib_mad *out_mad,
3348c2ecf20Sopenharmony_ci		     size_t *out_mad_size, u16 *out_mad_pkey_index);
3358c2ecf20Sopenharmony_ci
3368c2ecf20Sopenharmony_ci/*
3378c2ecf20Sopenharmony_ci * The PSN_MASK and PSN_SHIFT allow for
3388c2ecf20Sopenharmony_ci * 1) comparing two PSNs
3398c2ecf20Sopenharmony_ci * 2) returning the PSN with any upper bits masked
3408c2ecf20Sopenharmony_ci * 3) returning the difference between to PSNs
3418c2ecf20Sopenharmony_ci *
3428c2ecf20Sopenharmony_ci * The number of significant bits in the PSN must
3438c2ecf20Sopenharmony_ci * necessarily be at least one bit less than
3448c2ecf20Sopenharmony_ci * the container holding the PSN.
3458c2ecf20Sopenharmony_ci */
3468c2ecf20Sopenharmony_ci#define PSN_MASK 0x7FFFFFFF
3478c2ecf20Sopenharmony_ci#define PSN_SHIFT 1
3488c2ecf20Sopenharmony_ci#define PSN_MODIFY_MASK 0xFFFFFF
3498c2ecf20Sopenharmony_ci
3508c2ecf20Sopenharmony_ci/*
3518c2ecf20Sopenharmony_ci * Compare two PSNs
3528c2ecf20Sopenharmony_ci * Returns an integer <, ==, or > than zero.
3538c2ecf20Sopenharmony_ci */
3548c2ecf20Sopenharmony_cistatic inline int cmp_psn(u32 a, u32 b)
3558c2ecf20Sopenharmony_ci{
3568c2ecf20Sopenharmony_ci	return (((int)a) - ((int)b)) << PSN_SHIFT;
3578c2ecf20Sopenharmony_ci}
3588c2ecf20Sopenharmony_ci
3598c2ecf20Sopenharmony_ci/*
3608c2ecf20Sopenharmony_ci * Return masked PSN
3618c2ecf20Sopenharmony_ci */
3628c2ecf20Sopenharmony_cistatic inline u32 mask_psn(u32 a)
3638c2ecf20Sopenharmony_ci{
3648c2ecf20Sopenharmony_ci	return a & PSN_MASK;
3658c2ecf20Sopenharmony_ci}
3668c2ecf20Sopenharmony_ci
3678c2ecf20Sopenharmony_ci/*
3688c2ecf20Sopenharmony_ci * Return delta between two PSNs
3698c2ecf20Sopenharmony_ci */
3708c2ecf20Sopenharmony_cistatic inline u32 delta_psn(u32 a, u32 b)
3718c2ecf20Sopenharmony_ci{
3728c2ecf20Sopenharmony_ci	return (((int)a - (int)b) << PSN_SHIFT) >> PSN_SHIFT;
3738c2ecf20Sopenharmony_ci}
3748c2ecf20Sopenharmony_ci
3758c2ecf20Sopenharmony_cistatic inline struct tid_rdma_request *wqe_to_tid_req(struct rvt_swqe *wqe)
3768c2ecf20Sopenharmony_ci{
3778c2ecf20Sopenharmony_ci	return &((struct hfi1_swqe_priv *)wqe->priv)->tid_req;
3788c2ecf20Sopenharmony_ci}
3798c2ecf20Sopenharmony_ci
3808c2ecf20Sopenharmony_cistatic inline struct tid_rdma_request *ack_to_tid_req(struct rvt_ack_entry *e)
3818c2ecf20Sopenharmony_ci{
3828c2ecf20Sopenharmony_ci	return &((struct hfi1_ack_priv *)e->priv)->tid_req;
3838c2ecf20Sopenharmony_ci}
3848c2ecf20Sopenharmony_ci
3858c2ecf20Sopenharmony_ci/*
3868c2ecf20Sopenharmony_ci * Look through all the active flows for a TID RDMA request and find
3878c2ecf20Sopenharmony_ci * the one (if it exists) that contains the specified PSN.
3888c2ecf20Sopenharmony_ci */
3898c2ecf20Sopenharmony_cistatic inline u32 __full_flow_psn(struct flow_state *state, u32 psn)
3908c2ecf20Sopenharmony_ci{
3918c2ecf20Sopenharmony_ci	return mask_psn((state->generation << HFI1_KDETH_BTH_SEQ_SHIFT) |
3928c2ecf20Sopenharmony_ci			(psn & HFI1_KDETH_BTH_SEQ_MASK));
3938c2ecf20Sopenharmony_ci}
3948c2ecf20Sopenharmony_ci
3958c2ecf20Sopenharmony_cistatic inline u32 full_flow_psn(struct tid_rdma_flow *flow, u32 psn)
3968c2ecf20Sopenharmony_ci{
3978c2ecf20Sopenharmony_ci	return __full_flow_psn(&flow->flow_state, psn);
3988c2ecf20Sopenharmony_ci}
3998c2ecf20Sopenharmony_ci
4008c2ecf20Sopenharmony_cistruct verbs_txreq;
4018c2ecf20Sopenharmony_civoid hfi1_put_txreq(struct verbs_txreq *tx);
4028c2ecf20Sopenharmony_ci
4038c2ecf20Sopenharmony_ciint hfi1_verbs_send(struct rvt_qp *qp, struct hfi1_pkt_state *ps);
4048c2ecf20Sopenharmony_ci
4058c2ecf20Sopenharmony_civoid hfi1_cnp_rcv(struct hfi1_packet *packet);
4068c2ecf20Sopenharmony_ci
4078c2ecf20Sopenharmony_civoid hfi1_uc_rcv(struct hfi1_packet *packet);
4088c2ecf20Sopenharmony_ci
4098c2ecf20Sopenharmony_civoid hfi1_rc_rcv(struct hfi1_packet *packet);
4108c2ecf20Sopenharmony_ci
4118c2ecf20Sopenharmony_civoid hfi1_rc_hdrerr(
4128c2ecf20Sopenharmony_ci	struct hfi1_ctxtdata *rcd,
4138c2ecf20Sopenharmony_ci	struct hfi1_packet *packet,
4148c2ecf20Sopenharmony_ci	struct rvt_qp *qp);
4158c2ecf20Sopenharmony_ci
4168c2ecf20Sopenharmony_ciu8 ah_to_sc(struct ib_device *ibdev, struct rdma_ah_attr *ah_attr);
4178c2ecf20Sopenharmony_ci
4188c2ecf20Sopenharmony_civoid hfi1_rc_verbs_aborted(struct rvt_qp *qp, struct hfi1_opa_header *opah);
4198c2ecf20Sopenharmony_civoid hfi1_rc_send_complete(struct rvt_qp *qp, struct hfi1_opa_header *opah);
4208c2ecf20Sopenharmony_ci
4218c2ecf20Sopenharmony_civoid hfi1_ud_rcv(struct hfi1_packet *packet);
4228c2ecf20Sopenharmony_ci
4238c2ecf20Sopenharmony_ciint hfi1_lookup_pkey_idx(struct hfi1_ibport *ibp, u16 pkey);
4248c2ecf20Sopenharmony_ci
4258c2ecf20Sopenharmony_civoid hfi1_migrate_qp(struct rvt_qp *qp);
4268c2ecf20Sopenharmony_ci
4278c2ecf20Sopenharmony_ciint hfi1_check_modify_qp(struct rvt_qp *qp, struct ib_qp_attr *attr,
4288c2ecf20Sopenharmony_ci			 int attr_mask, struct ib_udata *udata);
4298c2ecf20Sopenharmony_ci
4308c2ecf20Sopenharmony_civoid hfi1_modify_qp(struct rvt_qp *qp, struct ib_qp_attr *attr,
4318c2ecf20Sopenharmony_ci		    int attr_mask, struct ib_udata *udata);
4328c2ecf20Sopenharmony_civoid hfi1_restart_rc(struct rvt_qp *qp, u32 psn, int wait);
4338c2ecf20Sopenharmony_ciint hfi1_setup_wqe(struct rvt_qp *qp, struct rvt_swqe *wqe,
4348c2ecf20Sopenharmony_ci		   bool *call_send);
4358c2ecf20Sopenharmony_ci
4368c2ecf20Sopenharmony_ciextern const u32 rc_only_opcode;
4378c2ecf20Sopenharmony_ciextern const u32 uc_only_opcode;
4388c2ecf20Sopenharmony_ci
4398c2ecf20Sopenharmony_ciint hfi1_ruc_check_hdr(struct hfi1_ibport *ibp, struct hfi1_packet *packet);
4408c2ecf20Sopenharmony_ci
4418c2ecf20Sopenharmony_ciu32 hfi1_make_grh(struct hfi1_ibport *ibp, struct ib_grh *hdr,
4428c2ecf20Sopenharmony_ci		  const struct ib_global_route *grh, u32 hwords, u32 nwords);
4438c2ecf20Sopenharmony_ci
4448c2ecf20Sopenharmony_civoid hfi1_make_ruc_header(struct rvt_qp *qp, struct ib_other_headers *ohdr,
4458c2ecf20Sopenharmony_ci			  u32 bth0, u32 bth1, u32 bth2, int middle,
4468c2ecf20Sopenharmony_ci			  struct hfi1_pkt_state *ps);
4478c2ecf20Sopenharmony_ci
4488c2ecf20Sopenharmony_cibool hfi1_schedule_send_yield(struct rvt_qp *qp, struct hfi1_pkt_state *ps,
4498c2ecf20Sopenharmony_ci			      bool tid);
4508c2ecf20Sopenharmony_ci
4518c2ecf20Sopenharmony_civoid _hfi1_do_send(struct work_struct *work);
4528c2ecf20Sopenharmony_ci
4538c2ecf20Sopenharmony_civoid hfi1_do_send_from_rvt(struct rvt_qp *qp);
4548c2ecf20Sopenharmony_ci
4558c2ecf20Sopenharmony_civoid hfi1_do_send(struct rvt_qp *qp, bool in_thread);
4568c2ecf20Sopenharmony_ci
4578c2ecf20Sopenharmony_civoid hfi1_send_rc_ack(struct hfi1_packet *packet, bool is_fecn);
4588c2ecf20Sopenharmony_ci
4598c2ecf20Sopenharmony_ciint hfi1_make_rc_req(struct rvt_qp *qp, struct hfi1_pkt_state *ps);
4608c2ecf20Sopenharmony_ci
4618c2ecf20Sopenharmony_ciint hfi1_make_uc_req(struct rvt_qp *qp, struct hfi1_pkt_state *ps);
4628c2ecf20Sopenharmony_ci
4638c2ecf20Sopenharmony_ciint hfi1_make_ud_req(struct rvt_qp *qp, struct hfi1_pkt_state *ps);
4648c2ecf20Sopenharmony_ci
4658c2ecf20Sopenharmony_ciint hfi1_register_ib_device(struct hfi1_devdata *);
4668c2ecf20Sopenharmony_ci
4678c2ecf20Sopenharmony_civoid hfi1_unregister_ib_device(struct hfi1_devdata *);
4688c2ecf20Sopenharmony_ci
4698c2ecf20Sopenharmony_civoid hfi1_kdeth_eager_rcv(struct hfi1_packet *packet);
4708c2ecf20Sopenharmony_ci
4718c2ecf20Sopenharmony_civoid hfi1_kdeth_expected_rcv(struct hfi1_packet *packet);
4728c2ecf20Sopenharmony_ci
4738c2ecf20Sopenharmony_civoid hfi1_ib_rcv(struct hfi1_packet *packet);
4748c2ecf20Sopenharmony_ci
4758c2ecf20Sopenharmony_civoid hfi1_16B_rcv(struct hfi1_packet *packet);
4768c2ecf20Sopenharmony_ci
4778c2ecf20Sopenharmony_ciunsigned hfi1_get_npkeys(struct hfi1_devdata *);
4788c2ecf20Sopenharmony_ci
4798c2ecf20Sopenharmony_ciint hfi1_verbs_send_dma(struct rvt_qp *qp, struct hfi1_pkt_state *ps,
4808c2ecf20Sopenharmony_ci			u64 pbc);
4818c2ecf20Sopenharmony_ci
4828c2ecf20Sopenharmony_ciint hfi1_verbs_send_pio(struct rvt_qp *qp, struct hfi1_pkt_state *ps,
4838c2ecf20Sopenharmony_ci			u64 pbc);
4848c2ecf20Sopenharmony_ci
4858c2ecf20Sopenharmony_cistatic inline bool opa_bth_is_migration(struct ib_other_headers *ohdr)
4868c2ecf20Sopenharmony_ci{
4878c2ecf20Sopenharmony_ci	return ohdr->bth[1] & cpu_to_be32(OPA_BTH_MIG_REQ);
4888c2ecf20Sopenharmony_ci}
4898c2ecf20Sopenharmony_ci
4908c2ecf20Sopenharmony_civoid hfi1_wait_kmem(struct rvt_qp *qp);
4918c2ecf20Sopenharmony_ci
4928c2ecf20Sopenharmony_cistatic inline void hfi1_trdma_send_complete(struct rvt_qp *qp,
4938c2ecf20Sopenharmony_ci					    struct rvt_swqe *wqe,
4948c2ecf20Sopenharmony_ci					    enum ib_wc_status status)
4958c2ecf20Sopenharmony_ci{
4968c2ecf20Sopenharmony_ci	trdma_clean_swqe(qp, wqe);
4978c2ecf20Sopenharmony_ci	rvt_send_complete(qp, wqe, status);
4988c2ecf20Sopenharmony_ci}
4998c2ecf20Sopenharmony_ci
5008c2ecf20Sopenharmony_ciextern const enum ib_wc_opcode ib_hfi1_wc_opcode[];
5018c2ecf20Sopenharmony_ci
5028c2ecf20Sopenharmony_ciextern const u8 hdr_len_by_opcode[];
5038c2ecf20Sopenharmony_ci
5048c2ecf20Sopenharmony_ciextern const int ib_rvt_state_ops[];
5058c2ecf20Sopenharmony_ci
5068c2ecf20Sopenharmony_ciextern __be64 ib_hfi1_sys_image_guid;    /* in network order */
5078c2ecf20Sopenharmony_ci
5088c2ecf20Sopenharmony_ciextern unsigned int hfi1_max_cqes;
5098c2ecf20Sopenharmony_ci
5108c2ecf20Sopenharmony_ciextern unsigned int hfi1_max_cqs;
5118c2ecf20Sopenharmony_ci
5128c2ecf20Sopenharmony_ciextern unsigned int hfi1_max_qp_wrs;
5138c2ecf20Sopenharmony_ci
5148c2ecf20Sopenharmony_ciextern unsigned int hfi1_max_qps;
5158c2ecf20Sopenharmony_ci
5168c2ecf20Sopenharmony_ciextern unsigned int hfi1_max_sges;
5178c2ecf20Sopenharmony_ci
5188c2ecf20Sopenharmony_ciextern unsigned int hfi1_max_mcast_grps;
5198c2ecf20Sopenharmony_ci
5208c2ecf20Sopenharmony_ciextern unsigned int hfi1_max_mcast_qp_attached;
5218c2ecf20Sopenharmony_ci
5228c2ecf20Sopenharmony_ciextern unsigned int hfi1_max_srqs;
5238c2ecf20Sopenharmony_ci
5248c2ecf20Sopenharmony_ciextern unsigned int hfi1_max_srq_sges;
5258c2ecf20Sopenharmony_ci
5268c2ecf20Sopenharmony_ciextern unsigned int hfi1_max_srq_wrs;
5278c2ecf20Sopenharmony_ci
5288c2ecf20Sopenharmony_ciextern unsigned short piothreshold;
5298c2ecf20Sopenharmony_ci
5308c2ecf20Sopenharmony_ciextern const u32 ib_hfi1_rnr_table[];
5318c2ecf20Sopenharmony_ci
5328c2ecf20Sopenharmony_ci#endif                          /* HFI1_VERBS_H */
533