18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Copyright(c) 2016 - 2019 Intel Corporation.
48c2ecf20Sopenharmony_ci */
58c2ecf20Sopenharmony_ci
68c2ecf20Sopenharmony_ci#ifndef DEF_RDMA_VT_H
78c2ecf20Sopenharmony_ci#define DEF_RDMA_VT_H
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ci/*
108c2ecf20Sopenharmony_ci * Structure that low level drivers will populate in order to register with the
118c2ecf20Sopenharmony_ci * rdmavt layer.
128c2ecf20Sopenharmony_ci */
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ci#include <linux/spinlock.h>
158c2ecf20Sopenharmony_ci#include <linux/list.h>
168c2ecf20Sopenharmony_ci#include <linux/hash.h>
178c2ecf20Sopenharmony_ci#include <rdma/ib_verbs.h>
188c2ecf20Sopenharmony_ci#include <rdma/ib_mad.h>
198c2ecf20Sopenharmony_ci#include <rdma/rdmavt_mr.h>
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ci#define RVT_MAX_PKEY_VALUES 16
228c2ecf20Sopenharmony_ci
238c2ecf20Sopenharmony_ci#define RVT_MAX_TRAP_LEN 100 /* Limit pending trap list */
248c2ecf20Sopenharmony_ci#define RVT_MAX_TRAP_LISTS 5 /*((IB_NOTICE_TYPE_INFO & 0x0F) + 1)*/
258c2ecf20Sopenharmony_ci#define RVT_TRAP_TIMEOUT 4096 /* 4.096 usec */
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_cistruct trap_list {
288c2ecf20Sopenharmony_ci	u32 list_len;
298c2ecf20Sopenharmony_ci	struct list_head list;
308c2ecf20Sopenharmony_ci};
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_cistruct rvt_qp;
338c2ecf20Sopenharmony_cistruct rvt_qpn_table;
348c2ecf20Sopenharmony_cistruct rvt_ibport {
358c2ecf20Sopenharmony_ci	struct rvt_qp __rcu *qp[2];
368c2ecf20Sopenharmony_ci	struct ib_mad_agent *send_agent;	/* agent for SMI (traps) */
378c2ecf20Sopenharmony_ci	struct rb_root mcast_tree;
388c2ecf20Sopenharmony_ci	spinlock_t lock;		/* protect changes in this struct */
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_ci	/* non-zero when timer is set */
418c2ecf20Sopenharmony_ci	unsigned long mkey_lease_timeout;
428c2ecf20Sopenharmony_ci	unsigned long trap_timeout;
438c2ecf20Sopenharmony_ci	__be64 gid_prefix;      /* in network order */
448c2ecf20Sopenharmony_ci	__be64 mkey;
458c2ecf20Sopenharmony_ci	u64 tid;
468c2ecf20Sopenharmony_ci	u32 port_cap_flags;
478c2ecf20Sopenharmony_ci	u16 port_cap3_flags;
488c2ecf20Sopenharmony_ci	u32 pma_sample_start;
498c2ecf20Sopenharmony_ci	u32 pma_sample_interval;
508c2ecf20Sopenharmony_ci	__be16 pma_counter_select[5];
518c2ecf20Sopenharmony_ci	u16 pma_tag;
528c2ecf20Sopenharmony_ci	u16 mkey_lease_period;
538c2ecf20Sopenharmony_ci	u32 sm_lid;
548c2ecf20Sopenharmony_ci	u8 sm_sl;
558c2ecf20Sopenharmony_ci	u8 mkeyprot;
568c2ecf20Sopenharmony_ci	u8 subnet_timeout;
578c2ecf20Sopenharmony_ci	u8 vl_high_limit;
588c2ecf20Sopenharmony_ci
598c2ecf20Sopenharmony_ci	/*
608c2ecf20Sopenharmony_ci	 * Driver is expected to keep these up to date. These
618c2ecf20Sopenharmony_ci	 * counters are informational only and not required to be
628c2ecf20Sopenharmony_ci	 * completely accurate.
638c2ecf20Sopenharmony_ci	 */
648c2ecf20Sopenharmony_ci	u64 n_rc_resends;
658c2ecf20Sopenharmony_ci	u64 n_seq_naks;
668c2ecf20Sopenharmony_ci	u64 n_rdma_seq;
678c2ecf20Sopenharmony_ci	u64 n_rnr_naks;
688c2ecf20Sopenharmony_ci	u64 n_other_naks;
698c2ecf20Sopenharmony_ci	u64 n_loop_pkts;
708c2ecf20Sopenharmony_ci	u64 n_pkt_drops;
718c2ecf20Sopenharmony_ci	u64 n_vl15_dropped;
728c2ecf20Sopenharmony_ci	u64 n_rc_timeouts;
738c2ecf20Sopenharmony_ci	u64 n_dmawait;
748c2ecf20Sopenharmony_ci	u64 n_unaligned;
758c2ecf20Sopenharmony_ci	u64 n_rc_dupreq;
768c2ecf20Sopenharmony_ci	u64 n_rc_seqnak;
778c2ecf20Sopenharmony_ci	u64 n_rc_crwaits;
788c2ecf20Sopenharmony_ci	u16 pkey_violations;
798c2ecf20Sopenharmony_ci	u16 qkey_violations;
808c2ecf20Sopenharmony_ci	u16 mkey_violations;
818c2ecf20Sopenharmony_ci
828c2ecf20Sopenharmony_ci	/* Hot-path per CPU counters to avoid cacheline trading to update */
838c2ecf20Sopenharmony_ci	u64 z_rc_acks;
848c2ecf20Sopenharmony_ci	u64 z_rc_qacks;
858c2ecf20Sopenharmony_ci	u64 z_rc_delayed_comp;
868c2ecf20Sopenharmony_ci	u64 __percpu *rc_acks;
878c2ecf20Sopenharmony_ci	u64 __percpu *rc_qacks;
888c2ecf20Sopenharmony_ci	u64 __percpu *rc_delayed_comp;
898c2ecf20Sopenharmony_ci
908c2ecf20Sopenharmony_ci	void *priv; /* driver private data */
918c2ecf20Sopenharmony_ci
928c2ecf20Sopenharmony_ci	/*
938c2ecf20Sopenharmony_ci	 * The pkey table is allocated and maintained by the driver. Drivers
948c2ecf20Sopenharmony_ci	 * need to have access to this before registering with rdmav. However
958c2ecf20Sopenharmony_ci	 * rdmavt will need access to it so drivers need to proviee this during
968c2ecf20Sopenharmony_ci	 * the attach port API call.
978c2ecf20Sopenharmony_ci	 */
988c2ecf20Sopenharmony_ci	u16 *pkey_table;
998c2ecf20Sopenharmony_ci
1008c2ecf20Sopenharmony_ci	struct rvt_ah *sm_ah;
1018c2ecf20Sopenharmony_ci
1028c2ecf20Sopenharmony_ci	/*
1038c2ecf20Sopenharmony_ci	 * Keep a list of traps that have not been repressed.  They will be
1048c2ecf20Sopenharmony_ci	 * resent based on trap_timer.
1058c2ecf20Sopenharmony_ci	 */
1068c2ecf20Sopenharmony_ci	struct trap_list trap_lists[RVT_MAX_TRAP_LISTS];
1078c2ecf20Sopenharmony_ci	struct timer_list trap_timer;
1088c2ecf20Sopenharmony_ci};
1098c2ecf20Sopenharmony_ci
1108c2ecf20Sopenharmony_ci#define RVT_CQN_MAX 16 /* maximum length of cq name */
1118c2ecf20Sopenharmony_ci
1128c2ecf20Sopenharmony_ci#define RVT_SGE_COPY_MEMCPY	0
1138c2ecf20Sopenharmony_ci#define RVT_SGE_COPY_CACHELESS	1
1148c2ecf20Sopenharmony_ci#define RVT_SGE_COPY_ADAPTIVE	2
1158c2ecf20Sopenharmony_ci
1168c2ecf20Sopenharmony_ci/*
1178c2ecf20Sopenharmony_ci * Things that are driver specific, module parameters in hfi1 and qib
1188c2ecf20Sopenharmony_ci */
1198c2ecf20Sopenharmony_cistruct rvt_driver_params {
1208c2ecf20Sopenharmony_ci	struct ib_device_attr props;
1218c2ecf20Sopenharmony_ci
1228c2ecf20Sopenharmony_ci	/*
1238c2ecf20Sopenharmony_ci	 * Anything driver specific that is not covered by props
1248c2ecf20Sopenharmony_ci	 * For instance special module parameters. Goes here.
1258c2ecf20Sopenharmony_ci	 */
1268c2ecf20Sopenharmony_ci	unsigned int lkey_table_size;
1278c2ecf20Sopenharmony_ci	unsigned int qp_table_size;
1288c2ecf20Sopenharmony_ci	unsigned int sge_copy_mode;
1298c2ecf20Sopenharmony_ci	unsigned int wss_threshold;
1308c2ecf20Sopenharmony_ci	unsigned int wss_clean_period;
1318c2ecf20Sopenharmony_ci	int qpn_start;
1328c2ecf20Sopenharmony_ci	int qpn_inc;
1338c2ecf20Sopenharmony_ci	int qpn_res_start;
1348c2ecf20Sopenharmony_ci	int qpn_res_end;
1358c2ecf20Sopenharmony_ci	int nports;
1368c2ecf20Sopenharmony_ci	int npkeys;
1378c2ecf20Sopenharmony_ci	int node;
1388c2ecf20Sopenharmony_ci	int psn_mask;
1398c2ecf20Sopenharmony_ci	int psn_shift;
1408c2ecf20Sopenharmony_ci	int psn_modify_mask;
1418c2ecf20Sopenharmony_ci	u32 core_cap_flags;
1428c2ecf20Sopenharmony_ci	u32 max_mad_size;
1438c2ecf20Sopenharmony_ci	u8 qos_shift;
1448c2ecf20Sopenharmony_ci	u8 max_rdma_atomic;
1458c2ecf20Sopenharmony_ci	u8 extra_rdma_atomic;
1468c2ecf20Sopenharmony_ci	u8 reserved_operations;
1478c2ecf20Sopenharmony_ci};
1488c2ecf20Sopenharmony_ci
1498c2ecf20Sopenharmony_ci/* User context */
1508c2ecf20Sopenharmony_cistruct rvt_ucontext {
1518c2ecf20Sopenharmony_ci	struct ib_ucontext ibucontext;
1528c2ecf20Sopenharmony_ci};
1538c2ecf20Sopenharmony_ci
1548c2ecf20Sopenharmony_ci/* Protection domain */
1558c2ecf20Sopenharmony_cistruct rvt_pd {
1568c2ecf20Sopenharmony_ci	struct ib_pd ibpd;
1578c2ecf20Sopenharmony_ci	bool user;
1588c2ecf20Sopenharmony_ci};
1598c2ecf20Sopenharmony_ci
1608c2ecf20Sopenharmony_ci/* Address handle */
1618c2ecf20Sopenharmony_cistruct rvt_ah {
1628c2ecf20Sopenharmony_ci	struct ib_ah ibah;
1638c2ecf20Sopenharmony_ci	struct rdma_ah_attr attr;
1648c2ecf20Sopenharmony_ci	u8 vl;
1658c2ecf20Sopenharmony_ci	u8 log_pmtu;
1668c2ecf20Sopenharmony_ci};
1678c2ecf20Sopenharmony_ci
1688c2ecf20Sopenharmony_ci/*
1698c2ecf20Sopenharmony_ci * This structure is used by rvt_mmap() to validate an offset
1708c2ecf20Sopenharmony_ci * when an mmap() request is made.  The vm_area_struct then uses
1718c2ecf20Sopenharmony_ci * this as its vm_private_data.
1728c2ecf20Sopenharmony_ci */
1738c2ecf20Sopenharmony_cistruct rvt_mmap_info {
1748c2ecf20Sopenharmony_ci	struct list_head pending_mmaps;
1758c2ecf20Sopenharmony_ci	struct ib_ucontext *context;
1768c2ecf20Sopenharmony_ci	void *obj;
1778c2ecf20Sopenharmony_ci	__u64 offset;
1788c2ecf20Sopenharmony_ci	struct kref ref;
1798c2ecf20Sopenharmony_ci	u32 size;
1808c2ecf20Sopenharmony_ci};
1818c2ecf20Sopenharmony_ci
1828c2ecf20Sopenharmony_ci/* memory working set size */
1838c2ecf20Sopenharmony_cistruct rvt_wss {
1848c2ecf20Sopenharmony_ci	unsigned long *entries;
1858c2ecf20Sopenharmony_ci	atomic_t total_count;
1868c2ecf20Sopenharmony_ci	atomic_t clean_counter;
1878c2ecf20Sopenharmony_ci	atomic_t clean_entry;
1888c2ecf20Sopenharmony_ci
1898c2ecf20Sopenharmony_ci	int threshold;
1908c2ecf20Sopenharmony_ci	int num_entries;
1918c2ecf20Sopenharmony_ci	long pages_mask;
1928c2ecf20Sopenharmony_ci	unsigned int clean_period;
1938c2ecf20Sopenharmony_ci};
1948c2ecf20Sopenharmony_ci
1958c2ecf20Sopenharmony_cistruct rvt_dev_info;
1968c2ecf20Sopenharmony_cistruct rvt_swqe;
1978c2ecf20Sopenharmony_cistruct rvt_driver_provided {
1988c2ecf20Sopenharmony_ci	/*
1998c2ecf20Sopenharmony_ci	 * Which functions are required depends on which verbs rdmavt is
2008c2ecf20Sopenharmony_ci	 * providing and which verbs the driver is overriding. See
2018c2ecf20Sopenharmony_ci	 * check_support() for details.
2028c2ecf20Sopenharmony_ci	 */
2038c2ecf20Sopenharmony_ci
2048c2ecf20Sopenharmony_ci	/* hot path calldowns in a single cacheline */
2058c2ecf20Sopenharmony_ci
2068c2ecf20Sopenharmony_ci	/*
2078c2ecf20Sopenharmony_ci	 * Give the driver a notice that there is send work to do. It is up to
2088c2ecf20Sopenharmony_ci	 * the driver to generally push the packets out, this just queues the
2098c2ecf20Sopenharmony_ci	 * work with the driver. There are two variants here. The no_lock
2108c2ecf20Sopenharmony_ci	 * version requires the s_lock not to be held. The other assumes the
2118c2ecf20Sopenharmony_ci	 * s_lock is held.
2128c2ecf20Sopenharmony_ci	 */
2138c2ecf20Sopenharmony_ci	bool (*schedule_send)(struct rvt_qp *qp);
2148c2ecf20Sopenharmony_ci	bool (*schedule_send_no_lock)(struct rvt_qp *qp);
2158c2ecf20Sopenharmony_ci
2168c2ecf20Sopenharmony_ci	/*
2178c2ecf20Sopenharmony_ci	 * Driver specific work request setup and checking.
2188c2ecf20Sopenharmony_ci	 * This function is allowed to perform any setup, checks, or
2198c2ecf20Sopenharmony_ci	 * adjustments required to the SWQE in order to be usable by
2208c2ecf20Sopenharmony_ci	 * underlying protocols. This includes private data structure
2218c2ecf20Sopenharmony_ci	 * allocations.
2228c2ecf20Sopenharmony_ci	 */
2238c2ecf20Sopenharmony_ci	int (*setup_wqe)(struct rvt_qp *qp, struct rvt_swqe *wqe,
2248c2ecf20Sopenharmony_ci			 bool *call_send);
2258c2ecf20Sopenharmony_ci
2268c2ecf20Sopenharmony_ci	/*
2278c2ecf20Sopenharmony_ci	 * Sometimes rdmavt needs to kick the driver's send progress. That is
2288c2ecf20Sopenharmony_ci	 * done by this call back.
2298c2ecf20Sopenharmony_ci	 */
2308c2ecf20Sopenharmony_ci	void (*do_send)(struct rvt_qp *qp);
2318c2ecf20Sopenharmony_ci
2328c2ecf20Sopenharmony_ci	/*
2338c2ecf20Sopenharmony_ci	 * Returns a pointer to the undelying hardware's PCI device. This is
2348c2ecf20Sopenharmony_ci	 * used to display information as to what hardware is being referenced
2358c2ecf20Sopenharmony_ci	 * in an output message
2368c2ecf20Sopenharmony_ci	 */
2378c2ecf20Sopenharmony_ci	struct pci_dev * (*get_pci_dev)(struct rvt_dev_info *rdi);
2388c2ecf20Sopenharmony_ci
2398c2ecf20Sopenharmony_ci	/*
2408c2ecf20Sopenharmony_ci	 * Allocate a private queue pair data structure for driver specific
2418c2ecf20Sopenharmony_ci	 * information which is opaque to rdmavt.  Errors are returned via
2428c2ecf20Sopenharmony_ci	 * ERR_PTR(err).  The driver is free to return NULL or a valid
2438c2ecf20Sopenharmony_ci	 * pointer.
2448c2ecf20Sopenharmony_ci	 */
2458c2ecf20Sopenharmony_ci	void * (*qp_priv_alloc)(struct rvt_dev_info *rdi, struct rvt_qp *qp);
2468c2ecf20Sopenharmony_ci
2478c2ecf20Sopenharmony_ci	/*
2488c2ecf20Sopenharmony_ci	 * Init a struture allocated with qp_priv_alloc(). This should be
2498c2ecf20Sopenharmony_ci	 * called after all qp fields have been initialized in rdmavt.
2508c2ecf20Sopenharmony_ci	 */
2518c2ecf20Sopenharmony_ci	int (*qp_priv_init)(struct rvt_dev_info *rdi, struct rvt_qp *qp,
2528c2ecf20Sopenharmony_ci			    struct ib_qp_init_attr *init_attr);
2538c2ecf20Sopenharmony_ci
2548c2ecf20Sopenharmony_ci	/*
2558c2ecf20Sopenharmony_ci	 * Free the driver's private qp structure.
2568c2ecf20Sopenharmony_ci	 */
2578c2ecf20Sopenharmony_ci	void (*qp_priv_free)(struct rvt_dev_info *rdi, struct rvt_qp *qp);
2588c2ecf20Sopenharmony_ci
2598c2ecf20Sopenharmony_ci	/*
2608c2ecf20Sopenharmony_ci	 * Inform the driver the particular qp in quesiton has been reset so
2618c2ecf20Sopenharmony_ci	 * that it can clean up anything it needs to.
2628c2ecf20Sopenharmony_ci	 */
2638c2ecf20Sopenharmony_ci	void (*notify_qp_reset)(struct rvt_qp *qp);
2648c2ecf20Sopenharmony_ci
2658c2ecf20Sopenharmony_ci	/*
2668c2ecf20Sopenharmony_ci	 * Get a path mtu from the driver based on qp attributes.
2678c2ecf20Sopenharmony_ci	 */
2688c2ecf20Sopenharmony_ci	int (*get_pmtu_from_attr)(struct rvt_dev_info *rdi, struct rvt_qp *qp,
2698c2ecf20Sopenharmony_ci				  struct ib_qp_attr *attr);
2708c2ecf20Sopenharmony_ci
2718c2ecf20Sopenharmony_ci	/*
2728c2ecf20Sopenharmony_ci	 * Notify driver that it needs to flush any outstanding IO requests that
2738c2ecf20Sopenharmony_ci	 * are waiting on a qp.
2748c2ecf20Sopenharmony_ci	 */
2758c2ecf20Sopenharmony_ci	void (*flush_qp_waiters)(struct rvt_qp *qp);
2768c2ecf20Sopenharmony_ci
2778c2ecf20Sopenharmony_ci	/*
2788c2ecf20Sopenharmony_ci	 * Notify driver to stop its queue of sending packets. Nothing else
2798c2ecf20Sopenharmony_ci	 * should be posted to the queue pair after this has been called.
2808c2ecf20Sopenharmony_ci	 */
2818c2ecf20Sopenharmony_ci	void (*stop_send_queue)(struct rvt_qp *qp);
2828c2ecf20Sopenharmony_ci
2838c2ecf20Sopenharmony_ci	/*
2848c2ecf20Sopenharmony_ci	 * Have the drivr drain any in progress operations
2858c2ecf20Sopenharmony_ci	 */
2868c2ecf20Sopenharmony_ci	void (*quiesce_qp)(struct rvt_qp *qp);
2878c2ecf20Sopenharmony_ci
2888c2ecf20Sopenharmony_ci	/*
2898c2ecf20Sopenharmony_ci	 * Inform the driver a qp has went to error state.
2908c2ecf20Sopenharmony_ci	 */
2918c2ecf20Sopenharmony_ci	void (*notify_error_qp)(struct rvt_qp *qp);
2928c2ecf20Sopenharmony_ci
2938c2ecf20Sopenharmony_ci	/*
2948c2ecf20Sopenharmony_ci	 * Get an MTU for a qp.
2958c2ecf20Sopenharmony_ci	 */
2968c2ecf20Sopenharmony_ci	u32 (*mtu_from_qp)(struct rvt_dev_info *rdi, struct rvt_qp *qp,
2978c2ecf20Sopenharmony_ci			   u32 pmtu);
2988c2ecf20Sopenharmony_ci	/*
2998c2ecf20Sopenharmony_ci	 * Convert an mtu to a path mtu
3008c2ecf20Sopenharmony_ci	 */
3018c2ecf20Sopenharmony_ci	int (*mtu_to_path_mtu)(u32 mtu);
3028c2ecf20Sopenharmony_ci
3038c2ecf20Sopenharmony_ci	/*
3048c2ecf20Sopenharmony_ci	 * Get the guid of a port in big endian byte order
3058c2ecf20Sopenharmony_ci	 */
3068c2ecf20Sopenharmony_ci	int (*get_guid_be)(struct rvt_dev_info *rdi, struct rvt_ibport *rvp,
3078c2ecf20Sopenharmony_ci			   int guid_index, __be64 *guid);
3088c2ecf20Sopenharmony_ci
3098c2ecf20Sopenharmony_ci	/*
3108c2ecf20Sopenharmony_ci	 * Query driver for the state of the port.
3118c2ecf20Sopenharmony_ci	 */
3128c2ecf20Sopenharmony_ci	int (*query_port_state)(struct rvt_dev_info *rdi, u8 port_num,
3138c2ecf20Sopenharmony_ci				struct ib_port_attr *props);
3148c2ecf20Sopenharmony_ci
3158c2ecf20Sopenharmony_ci	/*
3168c2ecf20Sopenharmony_ci	 * Tell driver to shutdown a port
3178c2ecf20Sopenharmony_ci	 */
3188c2ecf20Sopenharmony_ci	int (*shut_down_port)(struct rvt_dev_info *rdi, u8 port_num);
3198c2ecf20Sopenharmony_ci
3208c2ecf20Sopenharmony_ci	/* Tell driver to send a trap for changed  port capabilities */
3218c2ecf20Sopenharmony_ci	void (*cap_mask_chg)(struct rvt_dev_info *rdi, u8 port_num);
3228c2ecf20Sopenharmony_ci
3238c2ecf20Sopenharmony_ci	/*
3248c2ecf20Sopenharmony_ci	 * The following functions can be safely ignored completely. Any use of
3258c2ecf20Sopenharmony_ci	 * these is checked for NULL before blindly calling. Rdmavt should also
3268c2ecf20Sopenharmony_ci	 * be functional if drivers omit these.
3278c2ecf20Sopenharmony_ci	 */
3288c2ecf20Sopenharmony_ci
3298c2ecf20Sopenharmony_ci	/* Called to inform the driver that all qps should now be freed. */
3308c2ecf20Sopenharmony_ci	unsigned (*free_all_qps)(struct rvt_dev_info *rdi);
3318c2ecf20Sopenharmony_ci
3328c2ecf20Sopenharmony_ci	/* Driver specific AH validation */
3338c2ecf20Sopenharmony_ci	int (*check_ah)(struct ib_device *, struct rdma_ah_attr *);
3348c2ecf20Sopenharmony_ci
3358c2ecf20Sopenharmony_ci	/* Inform the driver a new AH has been created */
3368c2ecf20Sopenharmony_ci	void (*notify_new_ah)(struct ib_device *, struct rdma_ah_attr *,
3378c2ecf20Sopenharmony_ci			      struct rvt_ah *);
3388c2ecf20Sopenharmony_ci
3398c2ecf20Sopenharmony_ci	/* Let the driver pick the next queue pair number*/
3408c2ecf20Sopenharmony_ci	int (*alloc_qpn)(struct rvt_dev_info *rdi, struct rvt_qpn_table *qpt,
3418c2ecf20Sopenharmony_ci			 enum ib_qp_type type, u8 port_num);
3428c2ecf20Sopenharmony_ci
3438c2ecf20Sopenharmony_ci	/* Determine if its safe or allowed to modify the qp */
3448c2ecf20Sopenharmony_ci	int (*check_modify_qp)(struct rvt_qp *qp, struct ib_qp_attr *attr,
3458c2ecf20Sopenharmony_ci			       int attr_mask, struct ib_udata *udata);
3468c2ecf20Sopenharmony_ci
3478c2ecf20Sopenharmony_ci	/* Driver specific QP modification/notification-of */
3488c2ecf20Sopenharmony_ci	void (*modify_qp)(struct rvt_qp *qp, struct ib_qp_attr *attr,
3498c2ecf20Sopenharmony_ci			  int attr_mask, struct ib_udata *udata);
3508c2ecf20Sopenharmony_ci
3518c2ecf20Sopenharmony_ci	/* Notify driver a mad agent has been created */
3528c2ecf20Sopenharmony_ci	void (*notify_create_mad_agent)(struct rvt_dev_info *rdi, int port_idx);
3538c2ecf20Sopenharmony_ci
3548c2ecf20Sopenharmony_ci	/* Notify driver a mad agent has been removed */
3558c2ecf20Sopenharmony_ci	void (*notify_free_mad_agent)(struct rvt_dev_info *rdi, int port_idx);
3568c2ecf20Sopenharmony_ci
3578c2ecf20Sopenharmony_ci	/* Notify driver to restart rc */
3588c2ecf20Sopenharmony_ci	void (*notify_restart_rc)(struct rvt_qp *qp, u32 psn, int wait);
3598c2ecf20Sopenharmony_ci
3608c2ecf20Sopenharmony_ci	/* Get and return CPU to pin CQ processing thread */
3618c2ecf20Sopenharmony_ci	int (*comp_vect_cpu_lookup)(struct rvt_dev_info *rdi, int comp_vect);
3628c2ecf20Sopenharmony_ci};
3638c2ecf20Sopenharmony_ci
3648c2ecf20Sopenharmony_cistruct rvt_dev_info {
3658c2ecf20Sopenharmony_ci	struct ib_device ibdev; /* Keep this first. Nothing above here */
3668c2ecf20Sopenharmony_ci
3678c2ecf20Sopenharmony_ci	/*
3688c2ecf20Sopenharmony_ci	 * Prior to calling for registration the driver will be responsible for
3698c2ecf20Sopenharmony_ci	 * allocating space for this structure.
3708c2ecf20Sopenharmony_ci	 *
3718c2ecf20Sopenharmony_ci	 * The driver will also be responsible for filling in certain members of
3728c2ecf20Sopenharmony_ci	 * dparms.props. The driver needs to fill in dparms exactly as it would
3738c2ecf20Sopenharmony_ci	 * want values reported to a ULP. This will be returned to the caller
3748c2ecf20Sopenharmony_ci	 * in rdmavt's device. The driver should also therefore refrain from
3758c2ecf20Sopenharmony_ci	 * modifying this directly after registration with rdmavt.
3768c2ecf20Sopenharmony_ci	 */
3778c2ecf20Sopenharmony_ci
3788c2ecf20Sopenharmony_ci	/* Driver specific properties */
3798c2ecf20Sopenharmony_ci	struct rvt_driver_params dparms;
3808c2ecf20Sopenharmony_ci
3818c2ecf20Sopenharmony_ci	/* post send table */
3828c2ecf20Sopenharmony_ci	const struct rvt_operation_params *post_parms;
3838c2ecf20Sopenharmony_ci
3848c2ecf20Sopenharmony_ci	/* opcode translation table */
3858c2ecf20Sopenharmony_ci	const enum ib_wc_opcode *wc_opcode;
3868c2ecf20Sopenharmony_ci
3878c2ecf20Sopenharmony_ci	/* Driver specific helper functions */
3888c2ecf20Sopenharmony_ci	struct rvt_driver_provided driver_f;
3898c2ecf20Sopenharmony_ci
3908c2ecf20Sopenharmony_ci	struct rvt_mregion __rcu *dma_mr;
3918c2ecf20Sopenharmony_ci	struct rvt_lkey_table lkey_table;
3928c2ecf20Sopenharmony_ci
3938c2ecf20Sopenharmony_ci	/* Internal use */
3948c2ecf20Sopenharmony_ci	int n_pds_allocated;
3958c2ecf20Sopenharmony_ci	spinlock_t n_pds_lock; /* Protect pd allocated count */
3968c2ecf20Sopenharmony_ci
3978c2ecf20Sopenharmony_ci	int n_ahs_allocated;
3988c2ecf20Sopenharmony_ci	spinlock_t n_ahs_lock; /* Protect ah allocated count */
3998c2ecf20Sopenharmony_ci
4008c2ecf20Sopenharmony_ci	u32 n_srqs_allocated;
4018c2ecf20Sopenharmony_ci	spinlock_t n_srqs_lock; /* Protect srqs allocated count */
4028c2ecf20Sopenharmony_ci
4038c2ecf20Sopenharmony_ci	int flags;
4048c2ecf20Sopenharmony_ci	struct rvt_ibport **ports;
4058c2ecf20Sopenharmony_ci
4068c2ecf20Sopenharmony_ci	/* QP */
4078c2ecf20Sopenharmony_ci	struct rvt_qp_ibdev *qp_dev;
4088c2ecf20Sopenharmony_ci	u32 n_qps_allocated;    /* number of QPs allocated for device */
4098c2ecf20Sopenharmony_ci	u32 n_rc_qps;		/* number of RC QPs allocated for device */
4108c2ecf20Sopenharmony_ci	u32 busy_jiffies;	/* timeout scaling based on RC QP count */
4118c2ecf20Sopenharmony_ci	spinlock_t n_qps_lock;	/* protect qps, rc qps and busy jiffy counts */
4128c2ecf20Sopenharmony_ci
4138c2ecf20Sopenharmony_ci	/* memory maps */
4148c2ecf20Sopenharmony_ci	struct list_head pending_mmaps;
4158c2ecf20Sopenharmony_ci	spinlock_t mmap_offset_lock; /* protect mmap_offset */
4168c2ecf20Sopenharmony_ci	u32 mmap_offset;
4178c2ecf20Sopenharmony_ci	spinlock_t pending_lock; /* protect pending mmap list */
4188c2ecf20Sopenharmony_ci
4198c2ecf20Sopenharmony_ci	/* CQ */
4208c2ecf20Sopenharmony_ci	u32 n_cqs_allocated;    /* number of CQs allocated for device */
4218c2ecf20Sopenharmony_ci	spinlock_t n_cqs_lock; /* protect count of in use cqs */
4228c2ecf20Sopenharmony_ci
4238c2ecf20Sopenharmony_ci	/* Multicast */
4248c2ecf20Sopenharmony_ci	u32 n_mcast_grps_allocated; /* number of mcast groups allocated */
4258c2ecf20Sopenharmony_ci	spinlock_t n_mcast_grps_lock;
4268c2ecf20Sopenharmony_ci
4278c2ecf20Sopenharmony_ci	/* Memory Working Set Size */
4288c2ecf20Sopenharmony_ci	struct rvt_wss *wss;
4298c2ecf20Sopenharmony_ci};
4308c2ecf20Sopenharmony_ci
4318c2ecf20Sopenharmony_ci/**
4328c2ecf20Sopenharmony_ci * rvt_set_ibdev_name - Craft an IB device name from client info
4338c2ecf20Sopenharmony_ci * @rdi: pointer to the client rvt_dev_info structure
4348c2ecf20Sopenharmony_ci * @name: client specific name
4358c2ecf20Sopenharmony_ci * @unit: client specific unit number.
4368c2ecf20Sopenharmony_ci */
4378c2ecf20Sopenharmony_cistatic inline void rvt_set_ibdev_name(struct rvt_dev_info *rdi,
4388c2ecf20Sopenharmony_ci				      const char *fmt, const char *name,
4398c2ecf20Sopenharmony_ci				      const int unit)
4408c2ecf20Sopenharmony_ci{
4418c2ecf20Sopenharmony_ci	/*
4428c2ecf20Sopenharmony_ci	 * FIXME: rvt and its users want to touch the ibdev before
4438c2ecf20Sopenharmony_ci	 * registration and have things like the name work. We don't have the
4448c2ecf20Sopenharmony_ci	 * infrastructure in the core to support this directly today, hack it
4458c2ecf20Sopenharmony_ci	 * to work by setting the name manually here.
4468c2ecf20Sopenharmony_ci	 */
4478c2ecf20Sopenharmony_ci	dev_set_name(&rdi->ibdev.dev, fmt, name, unit);
4488c2ecf20Sopenharmony_ci	strlcpy(rdi->ibdev.name, dev_name(&rdi->ibdev.dev), IB_DEVICE_NAME_MAX);
4498c2ecf20Sopenharmony_ci}
4508c2ecf20Sopenharmony_ci
4518c2ecf20Sopenharmony_ci/**
4528c2ecf20Sopenharmony_ci * rvt_get_ibdev_name - return the IB name
4538c2ecf20Sopenharmony_ci * @rdi: rdmavt device
4548c2ecf20Sopenharmony_ci *
4558c2ecf20Sopenharmony_ci * Return the registered name of the device.
4568c2ecf20Sopenharmony_ci */
4578c2ecf20Sopenharmony_cistatic inline const char *rvt_get_ibdev_name(const struct rvt_dev_info *rdi)
4588c2ecf20Sopenharmony_ci{
4598c2ecf20Sopenharmony_ci	return dev_name(&rdi->ibdev.dev);
4608c2ecf20Sopenharmony_ci}
4618c2ecf20Sopenharmony_ci
4628c2ecf20Sopenharmony_cistatic inline struct rvt_pd *ibpd_to_rvtpd(struct ib_pd *ibpd)
4638c2ecf20Sopenharmony_ci{
4648c2ecf20Sopenharmony_ci	return container_of(ibpd, struct rvt_pd, ibpd);
4658c2ecf20Sopenharmony_ci}
4668c2ecf20Sopenharmony_ci
4678c2ecf20Sopenharmony_cistatic inline struct rvt_ah *ibah_to_rvtah(struct ib_ah *ibah)
4688c2ecf20Sopenharmony_ci{
4698c2ecf20Sopenharmony_ci	return container_of(ibah, struct rvt_ah, ibah);
4708c2ecf20Sopenharmony_ci}
4718c2ecf20Sopenharmony_ci
4728c2ecf20Sopenharmony_cistatic inline struct rvt_dev_info *ib_to_rvt(struct ib_device *ibdev)
4738c2ecf20Sopenharmony_ci{
4748c2ecf20Sopenharmony_ci	return  container_of(ibdev, struct rvt_dev_info, ibdev);
4758c2ecf20Sopenharmony_ci}
4768c2ecf20Sopenharmony_ci
4778c2ecf20Sopenharmony_cistatic inline unsigned rvt_get_npkeys(struct rvt_dev_info *rdi)
4788c2ecf20Sopenharmony_ci{
4798c2ecf20Sopenharmony_ci	/*
4808c2ecf20Sopenharmony_ci	 * All ports have same number of pkeys.
4818c2ecf20Sopenharmony_ci	 */
4828c2ecf20Sopenharmony_ci	return rdi->dparms.npkeys;
4838c2ecf20Sopenharmony_ci}
4848c2ecf20Sopenharmony_ci
4858c2ecf20Sopenharmony_ci/*
4868c2ecf20Sopenharmony_ci * Return the max atomic suitable for determining
4878c2ecf20Sopenharmony_ci * the size of the ack ring buffer in a QP.
4888c2ecf20Sopenharmony_ci */
4898c2ecf20Sopenharmony_cistatic inline unsigned int rvt_max_atomic(struct rvt_dev_info *rdi)
4908c2ecf20Sopenharmony_ci{
4918c2ecf20Sopenharmony_ci	return rdi->dparms.max_rdma_atomic +
4928c2ecf20Sopenharmony_ci		rdi->dparms.extra_rdma_atomic + 1;
4938c2ecf20Sopenharmony_ci}
4948c2ecf20Sopenharmony_ci
4958c2ecf20Sopenharmony_cistatic inline unsigned int rvt_size_atomic(struct rvt_dev_info *rdi)
4968c2ecf20Sopenharmony_ci{
4978c2ecf20Sopenharmony_ci	return rdi->dparms.max_rdma_atomic +
4988c2ecf20Sopenharmony_ci		rdi->dparms.extra_rdma_atomic;
4998c2ecf20Sopenharmony_ci}
5008c2ecf20Sopenharmony_ci
5018c2ecf20Sopenharmony_ci/*
5028c2ecf20Sopenharmony_ci * Return the indexed PKEY from the port PKEY table.
5038c2ecf20Sopenharmony_ci */
5048c2ecf20Sopenharmony_cistatic inline u16 rvt_get_pkey(struct rvt_dev_info *rdi,
5058c2ecf20Sopenharmony_ci			       int port_index,
5068c2ecf20Sopenharmony_ci			       unsigned index)
5078c2ecf20Sopenharmony_ci{
5088c2ecf20Sopenharmony_ci	if (index >= rvt_get_npkeys(rdi))
5098c2ecf20Sopenharmony_ci		return 0;
5108c2ecf20Sopenharmony_ci	else
5118c2ecf20Sopenharmony_ci		return rdi->ports[port_index]->pkey_table[index];
5128c2ecf20Sopenharmony_ci}
5138c2ecf20Sopenharmony_ci
5148c2ecf20Sopenharmony_cistruct rvt_dev_info *rvt_alloc_device(size_t size, int nports);
5158c2ecf20Sopenharmony_civoid rvt_dealloc_device(struct rvt_dev_info *rdi);
5168c2ecf20Sopenharmony_ciint rvt_register_device(struct rvt_dev_info *rvd);
5178c2ecf20Sopenharmony_civoid rvt_unregister_device(struct rvt_dev_info *rvd);
5188c2ecf20Sopenharmony_ciint rvt_check_ah(struct ib_device *ibdev, struct rdma_ah_attr *ah_attr);
5198c2ecf20Sopenharmony_ciint rvt_init_port(struct rvt_dev_info *rdi, struct rvt_ibport *port,
5208c2ecf20Sopenharmony_ci		  int port_index, u16 *pkey_table);
5218c2ecf20Sopenharmony_ciint rvt_fast_reg_mr(struct rvt_qp *qp, struct ib_mr *ibmr, u32 key,
5228c2ecf20Sopenharmony_ci		    int access);
5238c2ecf20Sopenharmony_ciint rvt_invalidate_rkey(struct rvt_qp *qp, u32 rkey);
5248c2ecf20Sopenharmony_ciint rvt_rkey_ok(struct rvt_qp *qp, struct rvt_sge *sge,
5258c2ecf20Sopenharmony_ci		u32 len, u64 vaddr, u32 rkey, int acc);
5268c2ecf20Sopenharmony_ciint rvt_lkey_ok(struct rvt_lkey_table *rkt, struct rvt_pd *pd,
5278c2ecf20Sopenharmony_ci		struct rvt_sge *isge, struct rvt_sge *last_sge,
5288c2ecf20Sopenharmony_ci		struct ib_sge *sge, int acc);
5298c2ecf20Sopenharmony_cistruct rvt_mcast *rvt_mcast_find(struct rvt_ibport *ibp, union ib_gid *mgid,
5308c2ecf20Sopenharmony_ci				 u16 lid);
5318c2ecf20Sopenharmony_ci
5328c2ecf20Sopenharmony_ci#endif          /* DEF_RDMA_VT_H */
533