18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Copyright (c) 2013-2020, Mellanox Technologies inc. All rights reserved.
48c2ecf20Sopenharmony_ci */
58c2ecf20Sopenharmony_ci
68c2ecf20Sopenharmony_ci#ifndef MLX5_IB_H
78c2ecf20Sopenharmony_ci#define MLX5_IB_H
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ci#include <linux/kernel.h>
108c2ecf20Sopenharmony_ci#include <linux/sched.h>
118c2ecf20Sopenharmony_ci#include <rdma/ib_verbs.h>
128c2ecf20Sopenharmony_ci#include <rdma/ib_umem.h>
138c2ecf20Sopenharmony_ci#include <rdma/ib_smi.h>
148c2ecf20Sopenharmony_ci#include <linux/mlx5/driver.h>
158c2ecf20Sopenharmony_ci#include <linux/mlx5/cq.h>
168c2ecf20Sopenharmony_ci#include <linux/mlx5/fs.h>
178c2ecf20Sopenharmony_ci#include <linux/mlx5/qp.h>
188c2ecf20Sopenharmony_ci#include <linux/types.h>
198c2ecf20Sopenharmony_ci#include <linux/mlx5/transobj.h>
208c2ecf20Sopenharmony_ci#include <rdma/ib_user_verbs.h>
218c2ecf20Sopenharmony_ci#include <rdma/mlx5-abi.h>
228c2ecf20Sopenharmony_ci#include <rdma/uverbs_ioctl.h>
238c2ecf20Sopenharmony_ci#include <rdma/mlx5_user_ioctl_cmds.h>
248c2ecf20Sopenharmony_ci#include <rdma/mlx5_user_ioctl_verbs.h>
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_ci#include "srq.h"
278c2ecf20Sopenharmony_ci
288c2ecf20Sopenharmony_ci#define mlx5_ib_dbg(_dev, format, arg...)                                      \
298c2ecf20Sopenharmony_ci	dev_dbg(&(_dev)->ib_dev.dev, "%s:%d:(pid %d): " format, __func__,      \
308c2ecf20Sopenharmony_ci		__LINE__, current->pid, ##arg)
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_ci#define mlx5_ib_err(_dev, format, arg...)                                      \
338c2ecf20Sopenharmony_ci	dev_err(&(_dev)->ib_dev.dev, "%s:%d:(pid %d): " format, __func__,      \
348c2ecf20Sopenharmony_ci		__LINE__, current->pid, ##arg)
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_ci#define mlx5_ib_warn(_dev, format, arg...)                                     \
378c2ecf20Sopenharmony_ci	dev_warn(&(_dev)->ib_dev.dev, "%s:%d:(pid %d): " format, __func__,     \
388c2ecf20Sopenharmony_ci		 __LINE__, current->pid, ##arg)
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_ci#define MLX5_IB_DEFAULT_UIDX 0xffffff
418c2ecf20Sopenharmony_ci#define MLX5_USER_ASSIGNED_UIDX_MASK __mlx5_mask(qpc, user_index)
428c2ecf20Sopenharmony_ci
438c2ecf20Sopenharmony_ci#define MLX5_MKEY_PAGE_SHIFT_MASK __mlx5_mask(mkc, log_page_size)
448c2ecf20Sopenharmony_ci
458c2ecf20Sopenharmony_cienum {
468c2ecf20Sopenharmony_ci	MLX5_IB_MMAP_OFFSET_START = 9,
478c2ecf20Sopenharmony_ci	MLX5_IB_MMAP_OFFSET_END = 255,
488c2ecf20Sopenharmony_ci};
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_cienum {
518c2ecf20Sopenharmony_ci	MLX5_IB_MMAP_CMD_SHIFT	= 8,
528c2ecf20Sopenharmony_ci	MLX5_IB_MMAP_CMD_MASK	= 0xff,
538c2ecf20Sopenharmony_ci};
548c2ecf20Sopenharmony_ci
558c2ecf20Sopenharmony_cienum {
568c2ecf20Sopenharmony_ci	MLX5_RES_SCAT_DATA32_CQE	= 0x1,
578c2ecf20Sopenharmony_ci	MLX5_RES_SCAT_DATA64_CQE	= 0x2,
588c2ecf20Sopenharmony_ci	MLX5_REQ_SCAT_DATA32_CQE	= 0x11,
598c2ecf20Sopenharmony_ci	MLX5_REQ_SCAT_DATA64_CQE	= 0x22,
608c2ecf20Sopenharmony_ci};
618c2ecf20Sopenharmony_ci
628c2ecf20Sopenharmony_cienum mlx5_ib_mad_ifc_flags {
638c2ecf20Sopenharmony_ci	MLX5_MAD_IFC_IGNORE_MKEY	= 1,
648c2ecf20Sopenharmony_ci	MLX5_MAD_IFC_IGNORE_BKEY	= 2,
658c2ecf20Sopenharmony_ci	MLX5_MAD_IFC_NET_VIEW		= 4,
668c2ecf20Sopenharmony_ci};
678c2ecf20Sopenharmony_ci
688c2ecf20Sopenharmony_cienum {
698c2ecf20Sopenharmony_ci	MLX5_CROSS_CHANNEL_BFREG         = 0,
708c2ecf20Sopenharmony_ci};
718c2ecf20Sopenharmony_ci
728c2ecf20Sopenharmony_cienum {
738c2ecf20Sopenharmony_ci	MLX5_CQE_VERSION_V0,
748c2ecf20Sopenharmony_ci	MLX5_CQE_VERSION_V1,
758c2ecf20Sopenharmony_ci};
768c2ecf20Sopenharmony_ci
778c2ecf20Sopenharmony_cienum {
788c2ecf20Sopenharmony_ci	MLX5_TM_MAX_RNDV_MSG_SIZE	= 64,
798c2ecf20Sopenharmony_ci	MLX5_TM_MAX_SGE			= 1,
808c2ecf20Sopenharmony_ci};
818c2ecf20Sopenharmony_ci
828c2ecf20Sopenharmony_cienum {
838c2ecf20Sopenharmony_ci	MLX5_IB_INVALID_UAR_INDEX	= BIT(31),
848c2ecf20Sopenharmony_ci	MLX5_IB_INVALID_BFREG		= BIT(31),
858c2ecf20Sopenharmony_ci};
868c2ecf20Sopenharmony_ci
878c2ecf20Sopenharmony_cienum {
888c2ecf20Sopenharmony_ci	MLX5_MAX_MEMIC_PAGES = 0x100,
898c2ecf20Sopenharmony_ci	MLX5_MEMIC_ALLOC_SIZE_MASK = 0x3f,
908c2ecf20Sopenharmony_ci};
918c2ecf20Sopenharmony_ci
928c2ecf20Sopenharmony_cienum {
938c2ecf20Sopenharmony_ci	MLX5_MEMIC_BASE_ALIGN	= 6,
948c2ecf20Sopenharmony_ci	MLX5_MEMIC_BASE_SIZE	= 1 << MLX5_MEMIC_BASE_ALIGN,
958c2ecf20Sopenharmony_ci};
968c2ecf20Sopenharmony_ci
978c2ecf20Sopenharmony_cienum mlx5_ib_mmap_type {
988c2ecf20Sopenharmony_ci	MLX5_IB_MMAP_TYPE_MEMIC = 1,
998c2ecf20Sopenharmony_ci	MLX5_IB_MMAP_TYPE_VAR = 2,
1008c2ecf20Sopenharmony_ci	MLX5_IB_MMAP_TYPE_UAR_WC = 3,
1018c2ecf20Sopenharmony_ci	MLX5_IB_MMAP_TYPE_UAR_NC = 4,
1028c2ecf20Sopenharmony_ci};
1038c2ecf20Sopenharmony_ci
1048c2ecf20Sopenharmony_cistruct mlx5_bfreg_info {
1058c2ecf20Sopenharmony_ci	u32 *sys_pages;
1068c2ecf20Sopenharmony_ci	int num_low_latency_bfregs;
1078c2ecf20Sopenharmony_ci	unsigned int *count;
1088c2ecf20Sopenharmony_ci
1098c2ecf20Sopenharmony_ci	/*
1108c2ecf20Sopenharmony_ci	 * protect bfreg allocation data structs
1118c2ecf20Sopenharmony_ci	 */
1128c2ecf20Sopenharmony_ci	struct mutex lock;
1138c2ecf20Sopenharmony_ci	u32 ver;
1148c2ecf20Sopenharmony_ci	u8 lib_uar_4k : 1;
1158c2ecf20Sopenharmony_ci	u8 lib_uar_dyn : 1;
1168c2ecf20Sopenharmony_ci	u32 num_sys_pages;
1178c2ecf20Sopenharmony_ci	u32 num_static_sys_pages;
1188c2ecf20Sopenharmony_ci	u32 total_num_bfregs;
1198c2ecf20Sopenharmony_ci	u32 num_dyn_bfregs;
1208c2ecf20Sopenharmony_ci};
1218c2ecf20Sopenharmony_ci
1228c2ecf20Sopenharmony_cistruct mlx5_ib_ucontext {
1238c2ecf20Sopenharmony_ci	struct ib_ucontext	ibucontext;
1248c2ecf20Sopenharmony_ci	struct list_head	db_page_list;
1258c2ecf20Sopenharmony_ci
1268c2ecf20Sopenharmony_ci	/* protect doorbell record alloc/free
1278c2ecf20Sopenharmony_ci	 */
1288c2ecf20Sopenharmony_ci	struct mutex		db_page_mutex;
1298c2ecf20Sopenharmony_ci	struct mlx5_bfreg_info	bfregi;
1308c2ecf20Sopenharmony_ci	u8			cqe_version;
1318c2ecf20Sopenharmony_ci	/* Transport Domain number */
1328c2ecf20Sopenharmony_ci	u32			tdn;
1338c2ecf20Sopenharmony_ci
1348c2ecf20Sopenharmony_ci	u64			lib_caps;
1358c2ecf20Sopenharmony_ci	u16			devx_uid;
1368c2ecf20Sopenharmony_ci	/* For RoCE LAG TX affinity */
1378c2ecf20Sopenharmony_ci	atomic_t		tx_port_affinity;
1388c2ecf20Sopenharmony_ci};
1398c2ecf20Sopenharmony_ci
1408c2ecf20Sopenharmony_cistatic inline struct mlx5_ib_ucontext *to_mucontext(struct ib_ucontext *ibucontext)
1418c2ecf20Sopenharmony_ci{
1428c2ecf20Sopenharmony_ci	return container_of(ibucontext, struct mlx5_ib_ucontext, ibucontext);
1438c2ecf20Sopenharmony_ci}
1448c2ecf20Sopenharmony_ci
1458c2ecf20Sopenharmony_cistruct mlx5_ib_pd {
1468c2ecf20Sopenharmony_ci	struct ib_pd		ibpd;
1478c2ecf20Sopenharmony_ci	u32			pdn;
1488c2ecf20Sopenharmony_ci	u16			uid;
1498c2ecf20Sopenharmony_ci};
1508c2ecf20Sopenharmony_ci
1518c2ecf20Sopenharmony_cienum {
1528c2ecf20Sopenharmony_ci	MLX5_IB_FLOW_ACTION_MODIFY_HEADER,
1538c2ecf20Sopenharmony_ci	MLX5_IB_FLOW_ACTION_PACKET_REFORMAT,
1548c2ecf20Sopenharmony_ci	MLX5_IB_FLOW_ACTION_DECAP,
1558c2ecf20Sopenharmony_ci};
1568c2ecf20Sopenharmony_ci
1578c2ecf20Sopenharmony_ci#define MLX5_IB_FLOW_MCAST_PRIO		(MLX5_BY_PASS_NUM_PRIOS - 1)
1588c2ecf20Sopenharmony_ci#define MLX5_IB_FLOW_LAST_PRIO		(MLX5_BY_PASS_NUM_REGULAR_PRIOS - 1)
1598c2ecf20Sopenharmony_ci#if (MLX5_IB_FLOW_LAST_PRIO <= 0)
1608c2ecf20Sopenharmony_ci#error "Invalid number of bypass priorities"
1618c2ecf20Sopenharmony_ci#endif
1628c2ecf20Sopenharmony_ci#define MLX5_IB_FLOW_LEFTOVERS_PRIO	(MLX5_IB_FLOW_MCAST_PRIO + 1)
1638c2ecf20Sopenharmony_ci
1648c2ecf20Sopenharmony_ci#define MLX5_IB_NUM_FLOW_FT		(MLX5_IB_FLOW_LEFTOVERS_PRIO + 1)
1658c2ecf20Sopenharmony_ci#define MLX5_IB_NUM_SNIFFER_FTS		2
1668c2ecf20Sopenharmony_ci#define MLX5_IB_NUM_EGRESS_FTS		1
1678c2ecf20Sopenharmony_cistruct mlx5_ib_flow_prio {
1688c2ecf20Sopenharmony_ci	struct mlx5_flow_table		*flow_table;
1698c2ecf20Sopenharmony_ci	unsigned int			refcount;
1708c2ecf20Sopenharmony_ci};
1718c2ecf20Sopenharmony_ci
1728c2ecf20Sopenharmony_cistruct mlx5_ib_flow_handler {
1738c2ecf20Sopenharmony_ci	struct list_head		list;
1748c2ecf20Sopenharmony_ci	struct ib_flow			ibflow;
1758c2ecf20Sopenharmony_ci	struct mlx5_ib_flow_prio	*prio;
1768c2ecf20Sopenharmony_ci	struct mlx5_flow_handle		*rule;
1778c2ecf20Sopenharmony_ci	struct ib_counters		*ibcounters;
1788c2ecf20Sopenharmony_ci	struct mlx5_ib_dev		*dev;
1798c2ecf20Sopenharmony_ci	struct mlx5_ib_flow_matcher	*flow_matcher;
1808c2ecf20Sopenharmony_ci};
1818c2ecf20Sopenharmony_ci
1828c2ecf20Sopenharmony_cistruct mlx5_ib_flow_matcher {
1838c2ecf20Sopenharmony_ci	struct mlx5_ib_match_params matcher_mask;
1848c2ecf20Sopenharmony_ci	int			mask_len;
1858c2ecf20Sopenharmony_ci	enum mlx5_ib_flow_type	flow_type;
1868c2ecf20Sopenharmony_ci	enum mlx5_flow_namespace_type ns_type;
1878c2ecf20Sopenharmony_ci	u16			priority;
1888c2ecf20Sopenharmony_ci	struct mlx5_core_dev	*mdev;
1898c2ecf20Sopenharmony_ci	atomic_t		usecnt;
1908c2ecf20Sopenharmony_ci	u8			match_criteria_enable;
1918c2ecf20Sopenharmony_ci};
1928c2ecf20Sopenharmony_ci
1938c2ecf20Sopenharmony_cistruct mlx5_ib_pp {
1948c2ecf20Sopenharmony_ci	u16 index;
1958c2ecf20Sopenharmony_ci	struct mlx5_core_dev *mdev;
1968c2ecf20Sopenharmony_ci};
1978c2ecf20Sopenharmony_ci
1988c2ecf20Sopenharmony_cistruct mlx5_ib_flow_db {
1998c2ecf20Sopenharmony_ci	struct mlx5_ib_flow_prio	prios[MLX5_IB_NUM_FLOW_FT];
2008c2ecf20Sopenharmony_ci	struct mlx5_ib_flow_prio	egress_prios[MLX5_IB_NUM_FLOW_FT];
2018c2ecf20Sopenharmony_ci	struct mlx5_ib_flow_prio	sniffer[MLX5_IB_NUM_SNIFFER_FTS];
2028c2ecf20Sopenharmony_ci	struct mlx5_ib_flow_prio	egress[MLX5_IB_NUM_EGRESS_FTS];
2038c2ecf20Sopenharmony_ci	struct mlx5_ib_flow_prio	fdb;
2048c2ecf20Sopenharmony_ci	struct mlx5_ib_flow_prio	rdma_rx[MLX5_IB_NUM_FLOW_FT];
2058c2ecf20Sopenharmony_ci	struct mlx5_ib_flow_prio	rdma_tx[MLX5_IB_NUM_FLOW_FT];
2068c2ecf20Sopenharmony_ci	struct mlx5_flow_table		*lag_demux_ft;
2078c2ecf20Sopenharmony_ci	/* Protect flow steering bypass flow tables
2088c2ecf20Sopenharmony_ci	 * when add/del flow rules.
2098c2ecf20Sopenharmony_ci	 * only single add/removal of flow steering rule could be done
2108c2ecf20Sopenharmony_ci	 * simultaneously.
2118c2ecf20Sopenharmony_ci	 */
2128c2ecf20Sopenharmony_ci	struct mutex			lock;
2138c2ecf20Sopenharmony_ci};
2148c2ecf20Sopenharmony_ci
2158c2ecf20Sopenharmony_ci/* Use macros here so that don't have to duplicate
2168c2ecf20Sopenharmony_ci * enum ib_send_flags and enum ib_qp_type for low-level driver
2178c2ecf20Sopenharmony_ci */
2188c2ecf20Sopenharmony_ci
2198c2ecf20Sopenharmony_ci#define MLX5_IB_SEND_UMR_ENABLE_MR	       (IB_SEND_RESERVED_START << 0)
2208c2ecf20Sopenharmony_ci#define MLX5_IB_SEND_UMR_DISABLE_MR	       (IB_SEND_RESERVED_START << 1)
2218c2ecf20Sopenharmony_ci#define MLX5_IB_SEND_UMR_FAIL_IF_FREE	       (IB_SEND_RESERVED_START << 2)
2228c2ecf20Sopenharmony_ci#define MLX5_IB_SEND_UMR_UPDATE_XLT	       (IB_SEND_RESERVED_START << 3)
2238c2ecf20Sopenharmony_ci#define MLX5_IB_SEND_UMR_UPDATE_TRANSLATION    (IB_SEND_RESERVED_START << 4)
2248c2ecf20Sopenharmony_ci#define MLX5_IB_SEND_UMR_UPDATE_PD_ACCESS       IB_SEND_RESERVED_END
2258c2ecf20Sopenharmony_ci
2268c2ecf20Sopenharmony_ci#define MLX5_IB_QPT_REG_UMR	IB_QPT_RESERVED1
2278c2ecf20Sopenharmony_ci/*
2288c2ecf20Sopenharmony_ci * IB_QPT_GSI creates the software wrapper around GSI, and MLX5_IB_QPT_HW_GSI
2298c2ecf20Sopenharmony_ci * creates the actual hardware QP.
2308c2ecf20Sopenharmony_ci */
2318c2ecf20Sopenharmony_ci#define MLX5_IB_QPT_HW_GSI	IB_QPT_RESERVED2
2328c2ecf20Sopenharmony_ci#define MLX5_IB_QPT_DCI		IB_QPT_RESERVED3
2338c2ecf20Sopenharmony_ci#define MLX5_IB_QPT_DCT		IB_QPT_RESERVED4
2348c2ecf20Sopenharmony_ci#define MLX5_IB_WR_UMR		IB_WR_RESERVED1
2358c2ecf20Sopenharmony_ci
2368c2ecf20Sopenharmony_ci#define MLX5_IB_UMR_OCTOWORD	       16
2378c2ecf20Sopenharmony_ci#define MLX5_IB_UMR_XLT_ALIGNMENT      64
2388c2ecf20Sopenharmony_ci
2398c2ecf20Sopenharmony_ci#define MLX5_IB_UPD_XLT_ZAP	      BIT(0)
2408c2ecf20Sopenharmony_ci#define MLX5_IB_UPD_XLT_ENABLE	      BIT(1)
2418c2ecf20Sopenharmony_ci#define MLX5_IB_UPD_XLT_ATOMIC	      BIT(2)
2428c2ecf20Sopenharmony_ci#define MLX5_IB_UPD_XLT_ADDR	      BIT(3)
2438c2ecf20Sopenharmony_ci#define MLX5_IB_UPD_XLT_PD	      BIT(4)
2448c2ecf20Sopenharmony_ci#define MLX5_IB_UPD_XLT_ACCESS	      BIT(5)
2458c2ecf20Sopenharmony_ci#define MLX5_IB_UPD_XLT_INDIRECT      BIT(6)
2468c2ecf20Sopenharmony_ci
2478c2ecf20Sopenharmony_ci/* Private QP creation flags to be passed in ib_qp_init_attr.create_flags.
2488c2ecf20Sopenharmony_ci *
2498c2ecf20Sopenharmony_ci * These flags are intended for internal use by the mlx5_ib driver, and they
2508c2ecf20Sopenharmony_ci * rely on the range reserved for that use in the ib_qp_create_flags enum.
2518c2ecf20Sopenharmony_ci */
2528c2ecf20Sopenharmony_ci#define MLX5_IB_QP_CREATE_SQPN_QP1	IB_QP_CREATE_RESERVED_START
2538c2ecf20Sopenharmony_ci#define MLX5_IB_QP_CREATE_WC_TEST	(IB_QP_CREATE_RESERVED_START << 1)
2548c2ecf20Sopenharmony_ci
2558c2ecf20Sopenharmony_cistruct wr_list {
2568c2ecf20Sopenharmony_ci	u16	opcode;
2578c2ecf20Sopenharmony_ci	u16	next;
2588c2ecf20Sopenharmony_ci};
2598c2ecf20Sopenharmony_ci
2608c2ecf20Sopenharmony_cienum mlx5_ib_rq_flags {
2618c2ecf20Sopenharmony_ci	MLX5_IB_RQ_CVLAN_STRIPPING	= 1 << 0,
2628c2ecf20Sopenharmony_ci	MLX5_IB_RQ_PCI_WRITE_END_PADDING	= 1 << 1,
2638c2ecf20Sopenharmony_ci};
2648c2ecf20Sopenharmony_ci
2658c2ecf20Sopenharmony_cistruct mlx5_ib_wq {
2668c2ecf20Sopenharmony_ci	struct mlx5_frag_buf_ctrl fbc;
2678c2ecf20Sopenharmony_ci	u64		       *wrid;
2688c2ecf20Sopenharmony_ci	u32		       *wr_data;
2698c2ecf20Sopenharmony_ci	struct wr_list	       *w_list;
2708c2ecf20Sopenharmony_ci	unsigned	       *wqe_head;
2718c2ecf20Sopenharmony_ci	u16		        unsig_count;
2728c2ecf20Sopenharmony_ci
2738c2ecf20Sopenharmony_ci	/* serialize post to the work queue
2748c2ecf20Sopenharmony_ci	 */
2758c2ecf20Sopenharmony_ci	spinlock_t		lock;
2768c2ecf20Sopenharmony_ci	int			wqe_cnt;
2778c2ecf20Sopenharmony_ci	int			max_post;
2788c2ecf20Sopenharmony_ci	int			max_gs;
2798c2ecf20Sopenharmony_ci	int			offset;
2808c2ecf20Sopenharmony_ci	int			wqe_shift;
2818c2ecf20Sopenharmony_ci	unsigned		head;
2828c2ecf20Sopenharmony_ci	unsigned		tail;
2838c2ecf20Sopenharmony_ci	u16			cur_post;
2848c2ecf20Sopenharmony_ci	u16			last_poll;
2858c2ecf20Sopenharmony_ci	void			*cur_edge;
2868c2ecf20Sopenharmony_ci};
2878c2ecf20Sopenharmony_ci
2888c2ecf20Sopenharmony_cienum mlx5_ib_wq_flags {
2898c2ecf20Sopenharmony_ci	MLX5_IB_WQ_FLAGS_DELAY_DROP = 0x1,
2908c2ecf20Sopenharmony_ci	MLX5_IB_WQ_FLAGS_STRIDING_RQ = 0x2,
2918c2ecf20Sopenharmony_ci};
2928c2ecf20Sopenharmony_ci
2938c2ecf20Sopenharmony_ci#define MLX5_MIN_SINGLE_WQE_LOG_NUM_STRIDES 9
2948c2ecf20Sopenharmony_ci#define MLX5_MAX_SINGLE_WQE_LOG_NUM_STRIDES 16
2958c2ecf20Sopenharmony_ci#define MLX5_MIN_SINGLE_STRIDE_LOG_NUM_BYTES 6
2968c2ecf20Sopenharmony_ci#define MLX5_MAX_SINGLE_STRIDE_LOG_NUM_BYTES 13
2978c2ecf20Sopenharmony_ci#define MLX5_EXT_MIN_SINGLE_WQE_LOG_NUM_STRIDES 3
2988c2ecf20Sopenharmony_ci
2998c2ecf20Sopenharmony_cistruct mlx5_ib_rwq {
3008c2ecf20Sopenharmony_ci	struct ib_wq		ibwq;
3018c2ecf20Sopenharmony_ci	struct mlx5_core_qp	core_qp;
3028c2ecf20Sopenharmony_ci	u32			rq_num_pas;
3038c2ecf20Sopenharmony_ci	u32			log_rq_stride;
3048c2ecf20Sopenharmony_ci	u32			log_rq_size;
3058c2ecf20Sopenharmony_ci	u32			rq_page_offset;
3068c2ecf20Sopenharmony_ci	u32			log_page_size;
3078c2ecf20Sopenharmony_ci	u32			log_num_strides;
3088c2ecf20Sopenharmony_ci	u32			two_byte_shift_en;
3098c2ecf20Sopenharmony_ci	u32			single_stride_log_num_of_bytes;
3108c2ecf20Sopenharmony_ci	struct ib_umem		*umem;
3118c2ecf20Sopenharmony_ci	size_t			buf_size;
3128c2ecf20Sopenharmony_ci	unsigned int		page_shift;
3138c2ecf20Sopenharmony_ci	struct mlx5_db		db;
3148c2ecf20Sopenharmony_ci	u32			user_index;
3158c2ecf20Sopenharmony_ci	u32			wqe_count;
3168c2ecf20Sopenharmony_ci	u32			wqe_shift;
3178c2ecf20Sopenharmony_ci	int			wq_sig;
3188c2ecf20Sopenharmony_ci	u32			create_flags; /* Use enum mlx5_ib_wq_flags */
3198c2ecf20Sopenharmony_ci};
3208c2ecf20Sopenharmony_ci
3218c2ecf20Sopenharmony_cistruct mlx5_ib_rwq_ind_table {
3228c2ecf20Sopenharmony_ci	struct ib_rwq_ind_table ib_rwq_ind_tbl;
3238c2ecf20Sopenharmony_ci	u32			rqtn;
3248c2ecf20Sopenharmony_ci	u16			uid;
3258c2ecf20Sopenharmony_ci};
3268c2ecf20Sopenharmony_ci
3278c2ecf20Sopenharmony_cistruct mlx5_ib_ubuffer {
3288c2ecf20Sopenharmony_ci	struct ib_umem	       *umem;
3298c2ecf20Sopenharmony_ci	int			buf_size;
3308c2ecf20Sopenharmony_ci	u64			buf_addr;
3318c2ecf20Sopenharmony_ci};
3328c2ecf20Sopenharmony_ci
3338c2ecf20Sopenharmony_cistruct mlx5_ib_qp_base {
3348c2ecf20Sopenharmony_ci	struct mlx5_ib_qp	*container_mibqp;
3358c2ecf20Sopenharmony_ci	struct mlx5_core_qp	mqp;
3368c2ecf20Sopenharmony_ci	struct mlx5_ib_ubuffer	ubuffer;
3378c2ecf20Sopenharmony_ci};
3388c2ecf20Sopenharmony_ci
3398c2ecf20Sopenharmony_cistruct mlx5_ib_qp_trans {
3408c2ecf20Sopenharmony_ci	struct mlx5_ib_qp_base	base;
3418c2ecf20Sopenharmony_ci	u16			xrcdn;
3428c2ecf20Sopenharmony_ci	u8			alt_port;
3438c2ecf20Sopenharmony_ci	u8			atomic_rd_en;
3448c2ecf20Sopenharmony_ci	u8			resp_depth;
3458c2ecf20Sopenharmony_ci};
3468c2ecf20Sopenharmony_ci
3478c2ecf20Sopenharmony_cistruct mlx5_ib_rss_qp {
3488c2ecf20Sopenharmony_ci	u32	tirn;
3498c2ecf20Sopenharmony_ci};
3508c2ecf20Sopenharmony_ci
3518c2ecf20Sopenharmony_cistruct mlx5_ib_rq {
3528c2ecf20Sopenharmony_ci	struct mlx5_ib_qp_base base;
3538c2ecf20Sopenharmony_ci	struct mlx5_ib_wq	*rq;
3548c2ecf20Sopenharmony_ci	struct mlx5_ib_ubuffer	ubuffer;
3558c2ecf20Sopenharmony_ci	struct mlx5_db		*doorbell;
3568c2ecf20Sopenharmony_ci	u32			tirn;
3578c2ecf20Sopenharmony_ci	u8			state;
3588c2ecf20Sopenharmony_ci	u32			flags;
3598c2ecf20Sopenharmony_ci};
3608c2ecf20Sopenharmony_ci
3618c2ecf20Sopenharmony_cistruct mlx5_ib_sq {
3628c2ecf20Sopenharmony_ci	struct mlx5_ib_qp_base base;
3638c2ecf20Sopenharmony_ci	struct mlx5_ib_wq	*sq;
3648c2ecf20Sopenharmony_ci	struct mlx5_ib_ubuffer  ubuffer;
3658c2ecf20Sopenharmony_ci	struct mlx5_db		*doorbell;
3668c2ecf20Sopenharmony_ci	struct mlx5_flow_handle	*flow_rule;
3678c2ecf20Sopenharmony_ci	u32			tisn;
3688c2ecf20Sopenharmony_ci	u8			state;
3698c2ecf20Sopenharmony_ci};
3708c2ecf20Sopenharmony_ci
3718c2ecf20Sopenharmony_cistruct mlx5_ib_raw_packet_qp {
3728c2ecf20Sopenharmony_ci	struct mlx5_ib_sq sq;
3738c2ecf20Sopenharmony_ci	struct mlx5_ib_rq rq;
3748c2ecf20Sopenharmony_ci};
3758c2ecf20Sopenharmony_ci
3768c2ecf20Sopenharmony_cistruct mlx5_bf {
3778c2ecf20Sopenharmony_ci	int			buf_size;
3788c2ecf20Sopenharmony_ci	unsigned long		offset;
3798c2ecf20Sopenharmony_ci	struct mlx5_sq_bfreg   *bfreg;
3808c2ecf20Sopenharmony_ci};
3818c2ecf20Sopenharmony_ci
3828c2ecf20Sopenharmony_cistruct mlx5_ib_dct {
3838c2ecf20Sopenharmony_ci	struct mlx5_core_dct    mdct;
3848c2ecf20Sopenharmony_ci	u32                     *in;
3858c2ecf20Sopenharmony_ci};
3868c2ecf20Sopenharmony_ci
3878c2ecf20Sopenharmony_cistruct mlx5_ib_gsi_qp {
3888c2ecf20Sopenharmony_ci	struct ib_qp *rx_qp;
3898c2ecf20Sopenharmony_ci	u8 port_num;
3908c2ecf20Sopenharmony_ci	struct ib_qp_cap cap;
3918c2ecf20Sopenharmony_ci	struct ib_cq *cq;
3928c2ecf20Sopenharmony_ci	struct mlx5_ib_gsi_wr *outstanding_wrs;
3938c2ecf20Sopenharmony_ci	u32 outstanding_pi, outstanding_ci;
3948c2ecf20Sopenharmony_ci	int num_qps;
3958c2ecf20Sopenharmony_ci	/* Protects access to the tx_qps. Post send operations synchronize
3968c2ecf20Sopenharmony_ci	 * with tx_qp creation in setup_qp(). Also protects the
3978c2ecf20Sopenharmony_ci	 * outstanding_wrs array and indices.
3988c2ecf20Sopenharmony_ci	 */
3998c2ecf20Sopenharmony_ci	spinlock_t lock;
4008c2ecf20Sopenharmony_ci	struct ib_qp **tx_qps;
4018c2ecf20Sopenharmony_ci};
4028c2ecf20Sopenharmony_ci
4038c2ecf20Sopenharmony_cistruct mlx5_ib_qp {
4048c2ecf20Sopenharmony_ci	struct ib_qp		ibqp;
4058c2ecf20Sopenharmony_ci	union {
4068c2ecf20Sopenharmony_ci		struct mlx5_ib_qp_trans trans_qp;
4078c2ecf20Sopenharmony_ci		struct mlx5_ib_raw_packet_qp raw_packet_qp;
4088c2ecf20Sopenharmony_ci		struct mlx5_ib_rss_qp rss_qp;
4098c2ecf20Sopenharmony_ci		struct mlx5_ib_dct dct;
4108c2ecf20Sopenharmony_ci		struct mlx5_ib_gsi_qp gsi;
4118c2ecf20Sopenharmony_ci	};
4128c2ecf20Sopenharmony_ci	struct mlx5_frag_buf	buf;
4138c2ecf20Sopenharmony_ci
4148c2ecf20Sopenharmony_ci	struct mlx5_db		db;
4158c2ecf20Sopenharmony_ci	struct mlx5_ib_wq	rq;
4168c2ecf20Sopenharmony_ci
4178c2ecf20Sopenharmony_ci	u8			sq_signal_bits;
4188c2ecf20Sopenharmony_ci	u8			next_fence;
4198c2ecf20Sopenharmony_ci	struct mlx5_ib_wq	sq;
4208c2ecf20Sopenharmony_ci
4218c2ecf20Sopenharmony_ci	/* serialize qp state modifications
4228c2ecf20Sopenharmony_ci	 */
4238c2ecf20Sopenharmony_ci	struct mutex		mutex;
4248c2ecf20Sopenharmony_ci	/* cached variant of create_flags from struct ib_qp_init_attr */
4258c2ecf20Sopenharmony_ci	u32			flags;
4268c2ecf20Sopenharmony_ci	u8			port;
4278c2ecf20Sopenharmony_ci	u8			state;
4288c2ecf20Sopenharmony_ci	int			max_inline_data;
4298c2ecf20Sopenharmony_ci	struct mlx5_bf	        bf;
4308c2ecf20Sopenharmony_ci	u8			has_rq:1;
4318c2ecf20Sopenharmony_ci	u8			is_rss:1;
4328c2ecf20Sopenharmony_ci
4338c2ecf20Sopenharmony_ci	/* only for user space QPs. For kernel
4348c2ecf20Sopenharmony_ci	 * we have it from the bf object
4358c2ecf20Sopenharmony_ci	 */
4368c2ecf20Sopenharmony_ci	int			bfregn;
4378c2ecf20Sopenharmony_ci
4388c2ecf20Sopenharmony_ci	struct list_head	qps_list;
4398c2ecf20Sopenharmony_ci	struct list_head	cq_recv_list;
4408c2ecf20Sopenharmony_ci	struct list_head	cq_send_list;
4418c2ecf20Sopenharmony_ci	struct mlx5_rate_limit	rl;
4428c2ecf20Sopenharmony_ci	u32                     underlay_qpn;
4438c2ecf20Sopenharmony_ci	u32			flags_en;
4448c2ecf20Sopenharmony_ci	/*
4458c2ecf20Sopenharmony_ci	 * IB/core doesn't store low-level QP types, so
4468c2ecf20Sopenharmony_ci	 * store both MLX and IBTA types in the field below.
4478c2ecf20Sopenharmony_ci	 * IB_QPT_DRIVER will be break to DCI/DCT subtypes.
4488c2ecf20Sopenharmony_ci	 */
4498c2ecf20Sopenharmony_ci	enum ib_qp_type		type;
4508c2ecf20Sopenharmony_ci	/* A flag to indicate if there's a new counter is configured
4518c2ecf20Sopenharmony_ci	 * but not take effective
4528c2ecf20Sopenharmony_ci	 */
4538c2ecf20Sopenharmony_ci	u32                     counter_pending;
4548c2ecf20Sopenharmony_ci	u16			gsi_lag_port;
4558c2ecf20Sopenharmony_ci};
4568c2ecf20Sopenharmony_ci
4578c2ecf20Sopenharmony_cistruct mlx5_ib_cq_buf {
4588c2ecf20Sopenharmony_ci	struct mlx5_frag_buf_ctrl fbc;
4598c2ecf20Sopenharmony_ci	struct mlx5_frag_buf    frag_buf;
4608c2ecf20Sopenharmony_ci	struct ib_umem		*umem;
4618c2ecf20Sopenharmony_ci	int			cqe_size;
4628c2ecf20Sopenharmony_ci	int			nent;
4638c2ecf20Sopenharmony_ci};
4648c2ecf20Sopenharmony_ci
4658c2ecf20Sopenharmony_cistruct mlx5_umr_wr {
4668c2ecf20Sopenharmony_ci	struct ib_send_wr		wr;
4678c2ecf20Sopenharmony_ci	u64				virt_addr;
4688c2ecf20Sopenharmony_ci	u64				offset;
4698c2ecf20Sopenharmony_ci	struct ib_pd		       *pd;
4708c2ecf20Sopenharmony_ci	unsigned int			page_shift;
4718c2ecf20Sopenharmony_ci	unsigned int			xlt_size;
4728c2ecf20Sopenharmony_ci	u64				length;
4738c2ecf20Sopenharmony_ci	int				access_flags;
4748c2ecf20Sopenharmony_ci	u32				mkey;
4758c2ecf20Sopenharmony_ci	u8				ignore_free_state:1;
4768c2ecf20Sopenharmony_ci};
4778c2ecf20Sopenharmony_ci
4788c2ecf20Sopenharmony_cistatic inline const struct mlx5_umr_wr *umr_wr(const struct ib_send_wr *wr)
4798c2ecf20Sopenharmony_ci{
4808c2ecf20Sopenharmony_ci	return container_of(wr, struct mlx5_umr_wr, wr);
4818c2ecf20Sopenharmony_ci}
4828c2ecf20Sopenharmony_ci
4838c2ecf20Sopenharmony_cistruct mlx5_shared_mr_info {
4848c2ecf20Sopenharmony_ci	int mr_id;
4858c2ecf20Sopenharmony_ci	struct ib_umem		*umem;
4868c2ecf20Sopenharmony_ci};
4878c2ecf20Sopenharmony_ci
4888c2ecf20Sopenharmony_cienum mlx5_ib_cq_pr_flags {
4898c2ecf20Sopenharmony_ci	MLX5_IB_CQ_PR_FLAGS_CQE_128_PAD	= 1 << 0,
4908c2ecf20Sopenharmony_ci};
4918c2ecf20Sopenharmony_ci
4928c2ecf20Sopenharmony_cistruct mlx5_ib_cq {
4938c2ecf20Sopenharmony_ci	struct ib_cq		ibcq;
4948c2ecf20Sopenharmony_ci	struct mlx5_core_cq	mcq;
4958c2ecf20Sopenharmony_ci	struct mlx5_ib_cq_buf	buf;
4968c2ecf20Sopenharmony_ci	struct mlx5_db		db;
4978c2ecf20Sopenharmony_ci
4988c2ecf20Sopenharmony_ci	/* serialize access to the CQ
4998c2ecf20Sopenharmony_ci	 */
5008c2ecf20Sopenharmony_ci	spinlock_t		lock;
5018c2ecf20Sopenharmony_ci
5028c2ecf20Sopenharmony_ci	/* protect resize cq
5038c2ecf20Sopenharmony_ci	 */
5048c2ecf20Sopenharmony_ci	struct mutex		resize_mutex;
5058c2ecf20Sopenharmony_ci	struct mlx5_ib_cq_buf  *resize_buf;
5068c2ecf20Sopenharmony_ci	struct ib_umem	       *resize_umem;
5078c2ecf20Sopenharmony_ci	int			cqe_size;
5088c2ecf20Sopenharmony_ci	struct list_head	list_send_qp;
5098c2ecf20Sopenharmony_ci	struct list_head	list_recv_qp;
5108c2ecf20Sopenharmony_ci	u32			create_flags;
5118c2ecf20Sopenharmony_ci	struct list_head	wc_list;
5128c2ecf20Sopenharmony_ci	enum ib_cq_notify_flags notify_flags;
5138c2ecf20Sopenharmony_ci	struct work_struct	notify_work;
5148c2ecf20Sopenharmony_ci	u16			private_flags; /* Use mlx5_ib_cq_pr_flags */
5158c2ecf20Sopenharmony_ci};
5168c2ecf20Sopenharmony_ci
5178c2ecf20Sopenharmony_cistruct mlx5_ib_wc {
5188c2ecf20Sopenharmony_ci	struct ib_wc wc;
5198c2ecf20Sopenharmony_ci	struct list_head list;
5208c2ecf20Sopenharmony_ci};
5218c2ecf20Sopenharmony_ci
5228c2ecf20Sopenharmony_cistruct mlx5_ib_srq {
5238c2ecf20Sopenharmony_ci	struct ib_srq		ibsrq;
5248c2ecf20Sopenharmony_ci	struct mlx5_core_srq	msrq;
5258c2ecf20Sopenharmony_ci	struct mlx5_frag_buf	buf;
5268c2ecf20Sopenharmony_ci	struct mlx5_db		db;
5278c2ecf20Sopenharmony_ci	struct mlx5_frag_buf_ctrl fbc;
5288c2ecf20Sopenharmony_ci	u64		       *wrid;
5298c2ecf20Sopenharmony_ci	/* protect SRQ hanlding
5308c2ecf20Sopenharmony_ci	 */
5318c2ecf20Sopenharmony_ci	spinlock_t		lock;
5328c2ecf20Sopenharmony_ci	int			head;
5338c2ecf20Sopenharmony_ci	int			tail;
5348c2ecf20Sopenharmony_ci	u16			wqe_ctr;
5358c2ecf20Sopenharmony_ci	struct ib_umem	       *umem;
5368c2ecf20Sopenharmony_ci	/* serialize arming a SRQ
5378c2ecf20Sopenharmony_ci	 */
5388c2ecf20Sopenharmony_ci	struct mutex		mutex;
5398c2ecf20Sopenharmony_ci	int			wq_sig;
5408c2ecf20Sopenharmony_ci};
5418c2ecf20Sopenharmony_ci
5428c2ecf20Sopenharmony_cistruct mlx5_ib_xrcd {
5438c2ecf20Sopenharmony_ci	struct ib_xrcd		ibxrcd;
5448c2ecf20Sopenharmony_ci	u32			xrcdn;
5458c2ecf20Sopenharmony_ci};
5468c2ecf20Sopenharmony_ci
5478c2ecf20Sopenharmony_cienum mlx5_ib_mtt_access_flags {
5488c2ecf20Sopenharmony_ci	MLX5_IB_MTT_READ  = (1 << 0),
5498c2ecf20Sopenharmony_ci	MLX5_IB_MTT_WRITE = (1 << 1),
5508c2ecf20Sopenharmony_ci};
5518c2ecf20Sopenharmony_ci
5528c2ecf20Sopenharmony_cistruct mlx5_user_mmap_entry {
5538c2ecf20Sopenharmony_ci	struct rdma_user_mmap_entry rdma_entry;
5548c2ecf20Sopenharmony_ci	u8 mmap_flag;
5558c2ecf20Sopenharmony_ci	u64 address;
5568c2ecf20Sopenharmony_ci	u32 page_idx;
5578c2ecf20Sopenharmony_ci};
5588c2ecf20Sopenharmony_ci
5598c2ecf20Sopenharmony_cistruct mlx5_ib_dm {
5608c2ecf20Sopenharmony_ci	struct ib_dm		ibdm;
5618c2ecf20Sopenharmony_ci	phys_addr_t		dev_addr;
5628c2ecf20Sopenharmony_ci	u32			type;
5638c2ecf20Sopenharmony_ci	size_t			size;
5648c2ecf20Sopenharmony_ci	union {
5658c2ecf20Sopenharmony_ci		struct {
5668c2ecf20Sopenharmony_ci			u32	obj_id;
5678c2ecf20Sopenharmony_ci		} icm_dm;
5688c2ecf20Sopenharmony_ci		/* other dm types specific params should be added here */
5698c2ecf20Sopenharmony_ci	};
5708c2ecf20Sopenharmony_ci	struct mlx5_user_mmap_entry mentry;
5718c2ecf20Sopenharmony_ci};
5728c2ecf20Sopenharmony_ci
5738c2ecf20Sopenharmony_ci#define MLX5_IB_MTT_PRESENT (MLX5_IB_MTT_READ | MLX5_IB_MTT_WRITE)
5748c2ecf20Sopenharmony_ci
5758c2ecf20Sopenharmony_ci#define MLX5_IB_DM_MEMIC_ALLOWED_ACCESS (IB_ACCESS_LOCAL_WRITE   |\
5768c2ecf20Sopenharmony_ci					 IB_ACCESS_REMOTE_WRITE  |\
5778c2ecf20Sopenharmony_ci					 IB_ACCESS_REMOTE_READ   |\
5788c2ecf20Sopenharmony_ci					 IB_ACCESS_REMOTE_ATOMIC |\
5798c2ecf20Sopenharmony_ci					 IB_ZERO_BASED)
5808c2ecf20Sopenharmony_ci
5818c2ecf20Sopenharmony_ci#define MLX5_IB_DM_SW_ICM_ALLOWED_ACCESS (IB_ACCESS_LOCAL_WRITE   |\
5828c2ecf20Sopenharmony_ci					  IB_ACCESS_REMOTE_WRITE  |\
5838c2ecf20Sopenharmony_ci					  IB_ACCESS_REMOTE_READ   |\
5848c2ecf20Sopenharmony_ci					  IB_ZERO_BASED)
5858c2ecf20Sopenharmony_ci
5868c2ecf20Sopenharmony_ci#define mlx5_update_odp_stats(mr, counter_name, value)		\
5878c2ecf20Sopenharmony_ci	atomic64_add(value, &((mr)->odp_stats.counter_name))
5888c2ecf20Sopenharmony_ci
5898c2ecf20Sopenharmony_cistruct mlx5_ib_mr {
5908c2ecf20Sopenharmony_ci	struct ib_mr		ibmr;
5918c2ecf20Sopenharmony_ci	void			*descs;
5928c2ecf20Sopenharmony_ci	dma_addr_t		desc_map;
5938c2ecf20Sopenharmony_ci	int			ndescs;
5948c2ecf20Sopenharmony_ci	int			data_length;
5958c2ecf20Sopenharmony_ci	int			meta_ndescs;
5968c2ecf20Sopenharmony_ci	int			meta_length;
5978c2ecf20Sopenharmony_ci	int			max_descs;
5988c2ecf20Sopenharmony_ci	int			desc_size;
5998c2ecf20Sopenharmony_ci	int			access_mode;
6008c2ecf20Sopenharmony_ci	struct mlx5_core_mkey	mmkey;
6018c2ecf20Sopenharmony_ci	struct ib_umem	       *umem;
6028c2ecf20Sopenharmony_ci	struct mlx5_shared_mr_info	*smr_info;
6038c2ecf20Sopenharmony_ci	struct list_head	list;
6048c2ecf20Sopenharmony_ci	unsigned int		order;
6058c2ecf20Sopenharmony_ci	struct mlx5_cache_ent  *cache_ent;
6068c2ecf20Sopenharmony_ci	int			npages;
6078c2ecf20Sopenharmony_ci	struct mlx5_ib_dev     *dev;
6088c2ecf20Sopenharmony_ci	u32 out[MLX5_ST_SZ_DW(create_mkey_out)];
6098c2ecf20Sopenharmony_ci	struct mlx5_core_sig_ctx    *sig;
6108c2ecf20Sopenharmony_ci	void			*descs_alloc;
6118c2ecf20Sopenharmony_ci	int			access_flags; /* Needed for rereg MR */
6128c2ecf20Sopenharmony_ci
6138c2ecf20Sopenharmony_ci	struct mlx5_ib_mr      *parent;
6148c2ecf20Sopenharmony_ci	/* Needed for IB_MR_TYPE_INTEGRITY */
6158c2ecf20Sopenharmony_ci	struct mlx5_ib_mr      *pi_mr;
6168c2ecf20Sopenharmony_ci	struct mlx5_ib_mr      *klm_mr;
6178c2ecf20Sopenharmony_ci	struct mlx5_ib_mr      *mtt_mr;
6188c2ecf20Sopenharmony_ci	u64			data_iova;
6198c2ecf20Sopenharmony_ci	u64			pi_iova;
6208c2ecf20Sopenharmony_ci
6218c2ecf20Sopenharmony_ci	/* For ODP and implicit */
6228c2ecf20Sopenharmony_ci	atomic_t		num_deferred_work;
6238c2ecf20Sopenharmony_ci	wait_queue_head_t       q_deferred_work;
6248c2ecf20Sopenharmony_ci	struct xarray		implicit_children;
6258c2ecf20Sopenharmony_ci	union {
6268c2ecf20Sopenharmony_ci		struct rcu_head rcu;
6278c2ecf20Sopenharmony_ci		struct list_head elm;
6288c2ecf20Sopenharmony_ci		struct work_struct work;
6298c2ecf20Sopenharmony_ci	} odp_destroy;
6308c2ecf20Sopenharmony_ci	struct ib_odp_counters	odp_stats;
6318c2ecf20Sopenharmony_ci	bool			is_odp_implicit;
6328c2ecf20Sopenharmony_ci
6338c2ecf20Sopenharmony_ci	struct mlx5_async_work  cb_work;
6348c2ecf20Sopenharmony_ci};
6358c2ecf20Sopenharmony_ci
6368c2ecf20Sopenharmony_cistatic inline bool is_odp_mr(struct mlx5_ib_mr *mr)
6378c2ecf20Sopenharmony_ci{
6388c2ecf20Sopenharmony_ci	return IS_ENABLED(CONFIG_INFINIBAND_ON_DEMAND_PAGING) && mr->umem &&
6398c2ecf20Sopenharmony_ci	       mr->umem->is_odp;
6408c2ecf20Sopenharmony_ci}
6418c2ecf20Sopenharmony_ci
6428c2ecf20Sopenharmony_cistruct mlx5_ib_mw {
6438c2ecf20Sopenharmony_ci	struct ib_mw		ibmw;
6448c2ecf20Sopenharmony_ci	struct mlx5_core_mkey	mmkey;
6458c2ecf20Sopenharmony_ci	int			ndescs;
6468c2ecf20Sopenharmony_ci};
6478c2ecf20Sopenharmony_ci
6488c2ecf20Sopenharmony_cistruct mlx5_ib_devx_mr {
6498c2ecf20Sopenharmony_ci	struct mlx5_core_mkey	mmkey;
6508c2ecf20Sopenharmony_ci	int			ndescs;
6518c2ecf20Sopenharmony_ci};
6528c2ecf20Sopenharmony_ci
6538c2ecf20Sopenharmony_cistruct mlx5_ib_umr_context {
6548c2ecf20Sopenharmony_ci	struct ib_cqe		cqe;
6558c2ecf20Sopenharmony_ci	enum ib_wc_status	status;
6568c2ecf20Sopenharmony_ci	struct completion	done;
6578c2ecf20Sopenharmony_ci};
6588c2ecf20Sopenharmony_ci
6598c2ecf20Sopenharmony_cistruct umr_common {
6608c2ecf20Sopenharmony_ci	struct ib_pd	*pd;
6618c2ecf20Sopenharmony_ci	struct ib_cq	*cq;
6628c2ecf20Sopenharmony_ci	struct ib_qp	*qp;
6638c2ecf20Sopenharmony_ci	/* control access to UMR QP
6648c2ecf20Sopenharmony_ci	 */
6658c2ecf20Sopenharmony_ci	struct semaphore	sem;
6668c2ecf20Sopenharmony_ci};
6678c2ecf20Sopenharmony_ci
6688c2ecf20Sopenharmony_cistruct mlx5_cache_ent {
6698c2ecf20Sopenharmony_ci	struct list_head	head;
6708c2ecf20Sopenharmony_ci	/* sync access to the cahce entry
6718c2ecf20Sopenharmony_ci	 */
6728c2ecf20Sopenharmony_ci	spinlock_t		lock;
6738c2ecf20Sopenharmony_ci
6748c2ecf20Sopenharmony_ci
6758c2ecf20Sopenharmony_ci	char                    name[4];
6768c2ecf20Sopenharmony_ci	u32                     order;
6778c2ecf20Sopenharmony_ci	u32			xlt;
6788c2ecf20Sopenharmony_ci	u32			access_mode;
6798c2ecf20Sopenharmony_ci	u32			page;
6808c2ecf20Sopenharmony_ci
6818c2ecf20Sopenharmony_ci	u8 disabled:1;
6828c2ecf20Sopenharmony_ci	u8 fill_to_high_water:1;
6838c2ecf20Sopenharmony_ci
6848c2ecf20Sopenharmony_ci	/*
6858c2ecf20Sopenharmony_ci	 * - available_mrs is the length of list head, ie the number of MRs
6868c2ecf20Sopenharmony_ci	 *   available for immediate allocation.
6878c2ecf20Sopenharmony_ci	 * - total_mrs is available_mrs plus all in use MRs that could be
6888c2ecf20Sopenharmony_ci	 *   returned to the cache.
6898c2ecf20Sopenharmony_ci	 * - limit is the low water mark for available_mrs, 2* limit is the
6908c2ecf20Sopenharmony_ci	 *   upper water mark.
6918c2ecf20Sopenharmony_ci	 * - pending is the number of MRs currently being created
6928c2ecf20Sopenharmony_ci	 */
6938c2ecf20Sopenharmony_ci	u32 total_mrs;
6948c2ecf20Sopenharmony_ci	u32 available_mrs;
6958c2ecf20Sopenharmony_ci	u32 limit;
6968c2ecf20Sopenharmony_ci	u32 pending;
6978c2ecf20Sopenharmony_ci
6988c2ecf20Sopenharmony_ci	/* Statistics */
6998c2ecf20Sopenharmony_ci	u32                     miss;
7008c2ecf20Sopenharmony_ci
7018c2ecf20Sopenharmony_ci	struct mlx5_ib_dev     *dev;
7028c2ecf20Sopenharmony_ci	struct work_struct	work;
7038c2ecf20Sopenharmony_ci	struct delayed_work	dwork;
7048c2ecf20Sopenharmony_ci};
7058c2ecf20Sopenharmony_ci
7068c2ecf20Sopenharmony_cistruct mlx5_mr_cache {
7078c2ecf20Sopenharmony_ci	struct workqueue_struct *wq;
7088c2ecf20Sopenharmony_ci	struct mlx5_cache_ent	ent[MAX_MR_CACHE_ENTRIES];
7098c2ecf20Sopenharmony_ci	struct dentry		*root;
7108c2ecf20Sopenharmony_ci	unsigned long		last_add;
7118c2ecf20Sopenharmony_ci};
7128c2ecf20Sopenharmony_ci
7138c2ecf20Sopenharmony_cistruct mlx5_ib_port_resources {
7148c2ecf20Sopenharmony_ci	struct mlx5_ib_gsi_qp *gsi;
7158c2ecf20Sopenharmony_ci	struct work_struct pkey_change_work;
7168c2ecf20Sopenharmony_ci};
7178c2ecf20Sopenharmony_ci
7188c2ecf20Sopenharmony_cistruct mlx5_ib_resources {
7198c2ecf20Sopenharmony_ci	struct ib_cq	*c0;
7208c2ecf20Sopenharmony_ci	u32 xrcdn0;
7218c2ecf20Sopenharmony_ci	u32 xrcdn1;
7228c2ecf20Sopenharmony_ci	struct ib_pd	*p0;
7238c2ecf20Sopenharmony_ci	struct ib_srq	*s0;
7248c2ecf20Sopenharmony_ci	struct ib_srq	*s1;
7258c2ecf20Sopenharmony_ci	struct mlx5_ib_port_resources ports[2];
7268c2ecf20Sopenharmony_ci	/* Protects changes to the port resources */
7278c2ecf20Sopenharmony_ci	struct mutex	mutex;
7288c2ecf20Sopenharmony_ci};
7298c2ecf20Sopenharmony_ci
7308c2ecf20Sopenharmony_cistruct mlx5_ib_counters {
7318c2ecf20Sopenharmony_ci	const char **names;
7328c2ecf20Sopenharmony_ci	size_t *offsets;
7338c2ecf20Sopenharmony_ci	u32 num_q_counters;
7348c2ecf20Sopenharmony_ci	u32 num_cong_counters;
7358c2ecf20Sopenharmony_ci	u32 num_ext_ppcnt_counters;
7368c2ecf20Sopenharmony_ci	u16 set_id;
7378c2ecf20Sopenharmony_ci};
7388c2ecf20Sopenharmony_ci
7398c2ecf20Sopenharmony_cistruct mlx5_ib_multiport_info;
7408c2ecf20Sopenharmony_ci
7418c2ecf20Sopenharmony_cistruct mlx5_ib_multiport {
7428c2ecf20Sopenharmony_ci	struct mlx5_ib_multiport_info *mpi;
7438c2ecf20Sopenharmony_ci	/* To be held when accessing the multiport info */
7448c2ecf20Sopenharmony_ci	spinlock_t mpi_lock;
7458c2ecf20Sopenharmony_ci};
7468c2ecf20Sopenharmony_ci
7478c2ecf20Sopenharmony_cistruct mlx5_roce {
7488c2ecf20Sopenharmony_ci	/* Protect mlx5_ib_get_netdev from invoking dev_hold() with a NULL
7498c2ecf20Sopenharmony_ci	 * netdev pointer
7508c2ecf20Sopenharmony_ci	 */
7518c2ecf20Sopenharmony_ci	rwlock_t		netdev_lock;
7528c2ecf20Sopenharmony_ci	struct net_device	*netdev;
7538c2ecf20Sopenharmony_ci	struct notifier_block	nb;
7548c2ecf20Sopenharmony_ci	atomic_t		tx_port_affinity;
7558c2ecf20Sopenharmony_ci	enum ib_port_state last_port_state;
7568c2ecf20Sopenharmony_ci	struct mlx5_ib_dev	*dev;
7578c2ecf20Sopenharmony_ci	u8			native_port_num;
7588c2ecf20Sopenharmony_ci};
7598c2ecf20Sopenharmony_ci
7608c2ecf20Sopenharmony_cistruct mlx5_ib_port {
7618c2ecf20Sopenharmony_ci	struct mlx5_ib_counters cnts;
7628c2ecf20Sopenharmony_ci	struct mlx5_ib_multiport mp;
7638c2ecf20Sopenharmony_ci	struct mlx5_ib_dbg_cc_params *dbg_cc_params;
7648c2ecf20Sopenharmony_ci	struct mlx5_roce roce;
7658c2ecf20Sopenharmony_ci	struct mlx5_eswitch_rep		*rep;
7668c2ecf20Sopenharmony_ci};
7678c2ecf20Sopenharmony_ci
7688c2ecf20Sopenharmony_cistruct mlx5_ib_dbg_param {
7698c2ecf20Sopenharmony_ci	int			offset;
7708c2ecf20Sopenharmony_ci	struct mlx5_ib_dev	*dev;
7718c2ecf20Sopenharmony_ci	struct dentry		*dentry;
7728c2ecf20Sopenharmony_ci	u8			port_num;
7738c2ecf20Sopenharmony_ci};
7748c2ecf20Sopenharmony_ci
7758c2ecf20Sopenharmony_cienum mlx5_ib_dbg_cc_types {
7768c2ecf20Sopenharmony_ci	MLX5_IB_DBG_CC_RP_CLAMP_TGT_RATE,
7778c2ecf20Sopenharmony_ci	MLX5_IB_DBG_CC_RP_CLAMP_TGT_RATE_ATI,
7788c2ecf20Sopenharmony_ci	MLX5_IB_DBG_CC_RP_TIME_RESET,
7798c2ecf20Sopenharmony_ci	MLX5_IB_DBG_CC_RP_BYTE_RESET,
7808c2ecf20Sopenharmony_ci	MLX5_IB_DBG_CC_RP_THRESHOLD,
7818c2ecf20Sopenharmony_ci	MLX5_IB_DBG_CC_RP_AI_RATE,
7828c2ecf20Sopenharmony_ci	MLX5_IB_DBG_CC_RP_MAX_RATE,
7838c2ecf20Sopenharmony_ci	MLX5_IB_DBG_CC_RP_HAI_RATE,
7848c2ecf20Sopenharmony_ci	MLX5_IB_DBG_CC_RP_MIN_DEC_FAC,
7858c2ecf20Sopenharmony_ci	MLX5_IB_DBG_CC_RP_MIN_RATE,
7868c2ecf20Sopenharmony_ci	MLX5_IB_DBG_CC_RP_RATE_TO_SET_ON_FIRST_CNP,
7878c2ecf20Sopenharmony_ci	MLX5_IB_DBG_CC_RP_DCE_TCP_G,
7888c2ecf20Sopenharmony_ci	MLX5_IB_DBG_CC_RP_DCE_TCP_RTT,
7898c2ecf20Sopenharmony_ci	MLX5_IB_DBG_CC_RP_RATE_REDUCE_MONITOR_PERIOD,
7908c2ecf20Sopenharmony_ci	MLX5_IB_DBG_CC_RP_INITIAL_ALPHA_VALUE,
7918c2ecf20Sopenharmony_ci	MLX5_IB_DBG_CC_RP_GD,
7928c2ecf20Sopenharmony_ci	MLX5_IB_DBG_CC_NP_MIN_TIME_BETWEEN_CNPS,
7938c2ecf20Sopenharmony_ci	MLX5_IB_DBG_CC_NP_CNP_DSCP,
7948c2ecf20Sopenharmony_ci	MLX5_IB_DBG_CC_NP_CNP_PRIO_MODE,
7958c2ecf20Sopenharmony_ci	MLX5_IB_DBG_CC_NP_CNP_PRIO,
7968c2ecf20Sopenharmony_ci	MLX5_IB_DBG_CC_MAX,
7978c2ecf20Sopenharmony_ci};
7988c2ecf20Sopenharmony_ci
7998c2ecf20Sopenharmony_cistruct mlx5_ib_dbg_cc_params {
8008c2ecf20Sopenharmony_ci	struct dentry			*root;
8018c2ecf20Sopenharmony_ci	struct mlx5_ib_dbg_param	params[MLX5_IB_DBG_CC_MAX];
8028c2ecf20Sopenharmony_ci};
8038c2ecf20Sopenharmony_ci
8048c2ecf20Sopenharmony_cienum {
8058c2ecf20Sopenharmony_ci	MLX5_MAX_DELAY_DROP_TIMEOUT_MS = 100,
8068c2ecf20Sopenharmony_ci};
8078c2ecf20Sopenharmony_ci
8088c2ecf20Sopenharmony_cistruct mlx5_ib_delay_drop {
8098c2ecf20Sopenharmony_ci	struct mlx5_ib_dev     *dev;
8108c2ecf20Sopenharmony_ci	struct work_struct	delay_drop_work;
8118c2ecf20Sopenharmony_ci	/* serialize setting of delay drop */
8128c2ecf20Sopenharmony_ci	struct mutex		lock;
8138c2ecf20Sopenharmony_ci	u32			timeout;
8148c2ecf20Sopenharmony_ci	bool			activate;
8158c2ecf20Sopenharmony_ci	atomic_t		events_cnt;
8168c2ecf20Sopenharmony_ci	atomic_t		rqs_cnt;
8178c2ecf20Sopenharmony_ci	struct dentry		*dir_debugfs;
8188c2ecf20Sopenharmony_ci};
8198c2ecf20Sopenharmony_ci
8208c2ecf20Sopenharmony_cienum mlx5_ib_stages {
8218c2ecf20Sopenharmony_ci	MLX5_IB_STAGE_INIT,
8228c2ecf20Sopenharmony_ci	MLX5_IB_STAGE_FS,
8238c2ecf20Sopenharmony_ci	MLX5_IB_STAGE_CAPS,
8248c2ecf20Sopenharmony_ci	MLX5_IB_STAGE_NON_DEFAULT_CB,
8258c2ecf20Sopenharmony_ci	MLX5_IB_STAGE_ROCE,
8268c2ecf20Sopenharmony_ci	MLX5_IB_STAGE_QP,
8278c2ecf20Sopenharmony_ci	MLX5_IB_STAGE_SRQ,
8288c2ecf20Sopenharmony_ci	MLX5_IB_STAGE_DEVICE_RESOURCES,
8298c2ecf20Sopenharmony_ci	MLX5_IB_STAGE_DEVICE_NOTIFIER,
8308c2ecf20Sopenharmony_ci	MLX5_IB_STAGE_ODP,
8318c2ecf20Sopenharmony_ci	MLX5_IB_STAGE_COUNTERS,
8328c2ecf20Sopenharmony_ci	MLX5_IB_STAGE_CONG_DEBUGFS,
8338c2ecf20Sopenharmony_ci	MLX5_IB_STAGE_UAR,
8348c2ecf20Sopenharmony_ci	MLX5_IB_STAGE_BFREG,
8358c2ecf20Sopenharmony_ci	MLX5_IB_STAGE_PRE_IB_REG_UMR,
8368c2ecf20Sopenharmony_ci	MLX5_IB_STAGE_WHITELIST_UID,
8378c2ecf20Sopenharmony_ci	MLX5_IB_STAGE_IB_REG,
8388c2ecf20Sopenharmony_ci	MLX5_IB_STAGE_POST_IB_REG_UMR,
8398c2ecf20Sopenharmony_ci	MLX5_IB_STAGE_DELAY_DROP,
8408c2ecf20Sopenharmony_ci	MLX5_IB_STAGE_RESTRACK,
8418c2ecf20Sopenharmony_ci	MLX5_IB_STAGE_MAX,
8428c2ecf20Sopenharmony_ci};
8438c2ecf20Sopenharmony_ci
8448c2ecf20Sopenharmony_cistruct mlx5_ib_stage {
8458c2ecf20Sopenharmony_ci	int (*init)(struct mlx5_ib_dev *dev);
8468c2ecf20Sopenharmony_ci	void (*cleanup)(struct mlx5_ib_dev *dev);
8478c2ecf20Sopenharmony_ci};
8488c2ecf20Sopenharmony_ci
8498c2ecf20Sopenharmony_ci#define STAGE_CREATE(_stage, _init, _cleanup) \
8508c2ecf20Sopenharmony_ci	.stage[_stage] = {.init = _init, .cleanup = _cleanup}
8518c2ecf20Sopenharmony_ci
8528c2ecf20Sopenharmony_cistruct mlx5_ib_profile {
8538c2ecf20Sopenharmony_ci	struct mlx5_ib_stage stage[MLX5_IB_STAGE_MAX];
8548c2ecf20Sopenharmony_ci};
8558c2ecf20Sopenharmony_ci
8568c2ecf20Sopenharmony_cistruct mlx5_ib_multiport_info {
8578c2ecf20Sopenharmony_ci	struct list_head list;
8588c2ecf20Sopenharmony_ci	struct mlx5_ib_dev *ibdev;
8598c2ecf20Sopenharmony_ci	struct mlx5_core_dev *mdev;
8608c2ecf20Sopenharmony_ci	struct notifier_block mdev_events;
8618c2ecf20Sopenharmony_ci	struct completion unref_comp;
8628c2ecf20Sopenharmony_ci	u64 sys_image_guid;
8638c2ecf20Sopenharmony_ci	u32 mdev_refcnt;
8648c2ecf20Sopenharmony_ci	bool is_master;
8658c2ecf20Sopenharmony_ci	bool unaffiliate;
8668c2ecf20Sopenharmony_ci};
8678c2ecf20Sopenharmony_ci
8688c2ecf20Sopenharmony_cistruct mlx5_ib_flow_action {
8698c2ecf20Sopenharmony_ci	struct ib_flow_action		ib_action;
8708c2ecf20Sopenharmony_ci	union {
8718c2ecf20Sopenharmony_ci		struct {
8728c2ecf20Sopenharmony_ci			u64			    ib_flags;
8738c2ecf20Sopenharmony_ci			struct mlx5_accel_esp_xfrm *ctx;
8748c2ecf20Sopenharmony_ci		} esp_aes_gcm;
8758c2ecf20Sopenharmony_ci		struct {
8768c2ecf20Sopenharmony_ci			struct mlx5_ib_dev *dev;
8778c2ecf20Sopenharmony_ci			u32 sub_type;
8788c2ecf20Sopenharmony_ci			union {
8798c2ecf20Sopenharmony_ci				struct mlx5_modify_hdr *modify_hdr;
8808c2ecf20Sopenharmony_ci				struct mlx5_pkt_reformat *pkt_reformat;
8818c2ecf20Sopenharmony_ci			};
8828c2ecf20Sopenharmony_ci		} flow_action_raw;
8838c2ecf20Sopenharmony_ci	};
8848c2ecf20Sopenharmony_ci};
8858c2ecf20Sopenharmony_ci
8868c2ecf20Sopenharmony_cistruct mlx5_dm {
8878c2ecf20Sopenharmony_ci	struct mlx5_core_dev *dev;
8888c2ecf20Sopenharmony_ci	/* This lock is used to protect the access to the shared
8898c2ecf20Sopenharmony_ci	 * allocation map when concurrent requests by different
8908c2ecf20Sopenharmony_ci	 * processes are handled.
8918c2ecf20Sopenharmony_ci	 */
8928c2ecf20Sopenharmony_ci	spinlock_t lock;
8938c2ecf20Sopenharmony_ci	DECLARE_BITMAP(memic_alloc_pages, MLX5_MAX_MEMIC_PAGES);
8948c2ecf20Sopenharmony_ci};
8958c2ecf20Sopenharmony_ci
8968c2ecf20Sopenharmony_cistruct mlx5_read_counters_attr {
8978c2ecf20Sopenharmony_ci	struct mlx5_fc *hw_cntrs_hndl;
8988c2ecf20Sopenharmony_ci	u64 *out;
8998c2ecf20Sopenharmony_ci	u32 flags;
9008c2ecf20Sopenharmony_ci};
9018c2ecf20Sopenharmony_ci
9028c2ecf20Sopenharmony_cienum mlx5_ib_counters_type {
9038c2ecf20Sopenharmony_ci	MLX5_IB_COUNTERS_FLOW,
9048c2ecf20Sopenharmony_ci};
9058c2ecf20Sopenharmony_ci
9068c2ecf20Sopenharmony_cistruct mlx5_ib_mcounters {
9078c2ecf20Sopenharmony_ci	struct ib_counters ibcntrs;
9088c2ecf20Sopenharmony_ci	enum mlx5_ib_counters_type type;
9098c2ecf20Sopenharmony_ci	/* number of counters supported for this counters type */
9108c2ecf20Sopenharmony_ci	u32 counters_num;
9118c2ecf20Sopenharmony_ci	struct mlx5_fc *hw_cntrs_hndl;
9128c2ecf20Sopenharmony_ci	/* read function for this counters type */
9138c2ecf20Sopenharmony_ci	int (*read_counters)(struct ib_device *ibdev,
9148c2ecf20Sopenharmony_ci			     struct mlx5_read_counters_attr *read_attr);
9158c2ecf20Sopenharmony_ci	/* max index set as part of create_flow */
9168c2ecf20Sopenharmony_ci	u32 cntrs_max_index;
9178c2ecf20Sopenharmony_ci	/* number of counters data entries (<description,index> pair) */
9188c2ecf20Sopenharmony_ci	u32 ncounters;
9198c2ecf20Sopenharmony_ci	/* counters data array for descriptions and indexes */
9208c2ecf20Sopenharmony_ci	struct mlx5_ib_flow_counters_desc *counters_data;
9218c2ecf20Sopenharmony_ci	/* protects access to mcounters internal data */
9228c2ecf20Sopenharmony_ci	struct mutex mcntrs_mutex;
9238c2ecf20Sopenharmony_ci};
9248c2ecf20Sopenharmony_ci
9258c2ecf20Sopenharmony_cistatic inline struct mlx5_ib_mcounters *
9268c2ecf20Sopenharmony_cito_mcounters(struct ib_counters *ibcntrs)
9278c2ecf20Sopenharmony_ci{
9288c2ecf20Sopenharmony_ci	return container_of(ibcntrs, struct mlx5_ib_mcounters, ibcntrs);
9298c2ecf20Sopenharmony_ci}
9308c2ecf20Sopenharmony_ci
9318c2ecf20Sopenharmony_ciint parse_flow_flow_action(struct mlx5_ib_flow_action *maction,
9328c2ecf20Sopenharmony_ci			   bool is_egress,
9338c2ecf20Sopenharmony_ci			   struct mlx5_flow_act *action);
9348c2ecf20Sopenharmony_cistruct mlx5_ib_lb_state {
9358c2ecf20Sopenharmony_ci	/* protect the user_td */
9368c2ecf20Sopenharmony_ci	struct mutex		mutex;
9378c2ecf20Sopenharmony_ci	u32			user_td;
9388c2ecf20Sopenharmony_ci	int			qps;
9398c2ecf20Sopenharmony_ci	bool			enabled;
9408c2ecf20Sopenharmony_ci};
9418c2ecf20Sopenharmony_ci
9428c2ecf20Sopenharmony_cistruct mlx5_ib_pf_eq {
9438c2ecf20Sopenharmony_ci	struct notifier_block irq_nb;
9448c2ecf20Sopenharmony_ci	struct mlx5_ib_dev *dev;
9458c2ecf20Sopenharmony_ci	struct mlx5_eq *core;
9468c2ecf20Sopenharmony_ci	struct work_struct work;
9478c2ecf20Sopenharmony_ci	spinlock_t lock; /* Pagefaults spinlock */
9488c2ecf20Sopenharmony_ci	struct workqueue_struct *wq;
9498c2ecf20Sopenharmony_ci	mempool_t *pool;
9508c2ecf20Sopenharmony_ci};
9518c2ecf20Sopenharmony_ci
9528c2ecf20Sopenharmony_cistruct mlx5_devx_event_table {
9538c2ecf20Sopenharmony_ci	struct mlx5_nb devx_nb;
9548c2ecf20Sopenharmony_ci	/* serialize updating the event_xa */
9558c2ecf20Sopenharmony_ci	struct mutex event_xa_lock;
9568c2ecf20Sopenharmony_ci	struct xarray event_xa;
9578c2ecf20Sopenharmony_ci};
9588c2ecf20Sopenharmony_ci
9598c2ecf20Sopenharmony_cistruct mlx5_var_table {
9608c2ecf20Sopenharmony_ci	/* serialize updating the bitmap */
9618c2ecf20Sopenharmony_ci	struct mutex bitmap_lock;
9628c2ecf20Sopenharmony_ci	unsigned long *bitmap;
9638c2ecf20Sopenharmony_ci	u64 hw_start_addr;
9648c2ecf20Sopenharmony_ci	u32 stride_size;
9658c2ecf20Sopenharmony_ci	u64 num_var_hw_entries;
9668c2ecf20Sopenharmony_ci};
9678c2ecf20Sopenharmony_ci
9688c2ecf20Sopenharmony_cistruct mlx5_ib_dev {
9698c2ecf20Sopenharmony_ci	struct ib_device		ib_dev;
9708c2ecf20Sopenharmony_ci	struct mlx5_core_dev		*mdev;
9718c2ecf20Sopenharmony_ci	struct notifier_block		mdev_events;
9728c2ecf20Sopenharmony_ci	int				num_ports;
9738c2ecf20Sopenharmony_ci	/* serialize update of capability mask
9748c2ecf20Sopenharmony_ci	 */
9758c2ecf20Sopenharmony_ci	struct mutex			cap_mask_mutex;
9768c2ecf20Sopenharmony_ci	u8				ib_active:1;
9778c2ecf20Sopenharmony_ci	u8				is_rep:1;
9788c2ecf20Sopenharmony_ci	u8				lag_active:1;
9798c2ecf20Sopenharmony_ci	u8				wc_support:1;
9808c2ecf20Sopenharmony_ci	u8				fill_delay;
9818c2ecf20Sopenharmony_ci	struct umr_common		umrc;
9828c2ecf20Sopenharmony_ci	/* sync used page count stats
9838c2ecf20Sopenharmony_ci	 */
9848c2ecf20Sopenharmony_ci	struct mlx5_ib_resources	devr;
9858c2ecf20Sopenharmony_ci
9868c2ecf20Sopenharmony_ci	atomic_t			mkey_var;
9878c2ecf20Sopenharmony_ci	struct mlx5_mr_cache		cache;
9888c2ecf20Sopenharmony_ci	struct timer_list		delay_timer;
9898c2ecf20Sopenharmony_ci	/* Prevents soft lock on massive reg MRs */
9908c2ecf20Sopenharmony_ci	struct mutex			slow_path_mutex;
9918c2ecf20Sopenharmony_ci	struct ib_odp_caps	odp_caps;
9928c2ecf20Sopenharmony_ci	u64			odp_max_size;
9938c2ecf20Sopenharmony_ci	struct mlx5_ib_pf_eq	odp_pf_eq;
9948c2ecf20Sopenharmony_ci
9958c2ecf20Sopenharmony_ci	/*
9968c2ecf20Sopenharmony_ci	 * Sleepable RCU that prevents destruction of MRs while they are still
9978c2ecf20Sopenharmony_ci	 * being used by a page fault handler.
9988c2ecf20Sopenharmony_ci	 */
9998c2ecf20Sopenharmony_ci	struct srcu_struct      odp_srcu;
10008c2ecf20Sopenharmony_ci	struct xarray		odp_mkeys;
10018c2ecf20Sopenharmony_ci
10028c2ecf20Sopenharmony_ci	u32			null_mkey;
10038c2ecf20Sopenharmony_ci	struct mlx5_ib_flow_db	*flow_db;
10048c2ecf20Sopenharmony_ci	/* protect resources needed as part of reset flow */
10058c2ecf20Sopenharmony_ci	spinlock_t		reset_flow_resource_lock;
10068c2ecf20Sopenharmony_ci	struct list_head	qp_list;
10078c2ecf20Sopenharmony_ci	/* Array with num_ports elements */
10088c2ecf20Sopenharmony_ci	struct mlx5_ib_port	*port;
10098c2ecf20Sopenharmony_ci	struct mlx5_sq_bfreg	bfreg;
10108c2ecf20Sopenharmony_ci	struct mlx5_sq_bfreg	wc_bfreg;
10118c2ecf20Sopenharmony_ci	struct mlx5_sq_bfreg	fp_bfreg;
10128c2ecf20Sopenharmony_ci	struct mlx5_ib_delay_drop	delay_drop;
10138c2ecf20Sopenharmony_ci	const struct mlx5_ib_profile	*profile;
10148c2ecf20Sopenharmony_ci
10158c2ecf20Sopenharmony_ci	struct mlx5_ib_lb_state		lb;
10168c2ecf20Sopenharmony_ci	u8			umr_fence;
10178c2ecf20Sopenharmony_ci	struct list_head	ib_dev_list;
10188c2ecf20Sopenharmony_ci	u64			sys_image_guid;
10198c2ecf20Sopenharmony_ci	struct mlx5_dm		dm;
10208c2ecf20Sopenharmony_ci	u16			devx_whitelist_uid;
10218c2ecf20Sopenharmony_ci	struct mlx5_srq_table   srq_table;
10228c2ecf20Sopenharmony_ci	struct mlx5_qp_table    qp_table;
10238c2ecf20Sopenharmony_ci	struct mlx5_async_ctx   async_ctx;
10248c2ecf20Sopenharmony_ci	struct mlx5_devx_event_table devx_event_table;
10258c2ecf20Sopenharmony_ci	struct mlx5_var_table var_table;
10268c2ecf20Sopenharmony_ci
10278c2ecf20Sopenharmony_ci	struct xarray sig_mrs;
10288c2ecf20Sopenharmony_ci};
10298c2ecf20Sopenharmony_ci
10308c2ecf20Sopenharmony_cistatic inline struct mlx5_ib_cq *to_mibcq(struct mlx5_core_cq *mcq)
10318c2ecf20Sopenharmony_ci{
10328c2ecf20Sopenharmony_ci	return container_of(mcq, struct mlx5_ib_cq, mcq);
10338c2ecf20Sopenharmony_ci}
10348c2ecf20Sopenharmony_ci
10358c2ecf20Sopenharmony_cistatic inline struct mlx5_ib_xrcd *to_mxrcd(struct ib_xrcd *ibxrcd)
10368c2ecf20Sopenharmony_ci{
10378c2ecf20Sopenharmony_ci	return container_of(ibxrcd, struct mlx5_ib_xrcd, ibxrcd);
10388c2ecf20Sopenharmony_ci}
10398c2ecf20Sopenharmony_ci
10408c2ecf20Sopenharmony_cistatic inline struct mlx5_ib_dev *to_mdev(struct ib_device *ibdev)
10418c2ecf20Sopenharmony_ci{
10428c2ecf20Sopenharmony_ci	return container_of(ibdev, struct mlx5_ib_dev, ib_dev);
10438c2ecf20Sopenharmony_ci}
10448c2ecf20Sopenharmony_ci
10458c2ecf20Sopenharmony_cistatic inline struct mlx5_ib_dev *mlx5_udata_to_mdev(struct ib_udata *udata)
10468c2ecf20Sopenharmony_ci{
10478c2ecf20Sopenharmony_ci	struct mlx5_ib_ucontext *context = rdma_udata_to_drv_context(
10488c2ecf20Sopenharmony_ci		udata, struct mlx5_ib_ucontext, ibucontext);
10498c2ecf20Sopenharmony_ci
10508c2ecf20Sopenharmony_ci	return to_mdev(context->ibucontext.device);
10518c2ecf20Sopenharmony_ci}
10528c2ecf20Sopenharmony_ci
10538c2ecf20Sopenharmony_cistatic inline struct mlx5_ib_cq *to_mcq(struct ib_cq *ibcq)
10548c2ecf20Sopenharmony_ci{
10558c2ecf20Sopenharmony_ci	return container_of(ibcq, struct mlx5_ib_cq, ibcq);
10568c2ecf20Sopenharmony_ci}
10578c2ecf20Sopenharmony_ci
10588c2ecf20Sopenharmony_cistatic inline struct mlx5_ib_qp *to_mibqp(struct mlx5_core_qp *mqp)
10598c2ecf20Sopenharmony_ci{
10608c2ecf20Sopenharmony_ci	return container_of(mqp, struct mlx5_ib_qp_base, mqp)->container_mibqp;
10618c2ecf20Sopenharmony_ci}
10628c2ecf20Sopenharmony_ci
10638c2ecf20Sopenharmony_cistatic inline struct mlx5_ib_rwq *to_mibrwq(struct mlx5_core_qp *core_qp)
10648c2ecf20Sopenharmony_ci{
10658c2ecf20Sopenharmony_ci	return container_of(core_qp, struct mlx5_ib_rwq, core_qp);
10668c2ecf20Sopenharmony_ci}
10678c2ecf20Sopenharmony_ci
10688c2ecf20Sopenharmony_cistatic inline struct mlx5_ib_pd *to_mpd(struct ib_pd *ibpd)
10698c2ecf20Sopenharmony_ci{
10708c2ecf20Sopenharmony_ci	return container_of(ibpd, struct mlx5_ib_pd, ibpd);
10718c2ecf20Sopenharmony_ci}
10728c2ecf20Sopenharmony_ci
10738c2ecf20Sopenharmony_cistatic inline struct mlx5_ib_srq *to_msrq(struct ib_srq *ibsrq)
10748c2ecf20Sopenharmony_ci{
10758c2ecf20Sopenharmony_ci	return container_of(ibsrq, struct mlx5_ib_srq, ibsrq);
10768c2ecf20Sopenharmony_ci}
10778c2ecf20Sopenharmony_ci
10788c2ecf20Sopenharmony_cistatic inline struct mlx5_ib_qp *to_mqp(struct ib_qp *ibqp)
10798c2ecf20Sopenharmony_ci{
10808c2ecf20Sopenharmony_ci	return container_of(ibqp, struct mlx5_ib_qp, ibqp);
10818c2ecf20Sopenharmony_ci}
10828c2ecf20Sopenharmony_ci
10838c2ecf20Sopenharmony_cistatic inline struct mlx5_ib_rwq *to_mrwq(struct ib_wq *ibwq)
10848c2ecf20Sopenharmony_ci{
10858c2ecf20Sopenharmony_ci	return container_of(ibwq, struct mlx5_ib_rwq, ibwq);
10868c2ecf20Sopenharmony_ci}
10878c2ecf20Sopenharmony_ci
10888c2ecf20Sopenharmony_cistatic inline struct mlx5_ib_rwq_ind_table *to_mrwq_ind_table(struct ib_rwq_ind_table *ib_rwq_ind_tbl)
10898c2ecf20Sopenharmony_ci{
10908c2ecf20Sopenharmony_ci	return container_of(ib_rwq_ind_tbl, struct mlx5_ib_rwq_ind_table, ib_rwq_ind_tbl);
10918c2ecf20Sopenharmony_ci}
10928c2ecf20Sopenharmony_ci
10938c2ecf20Sopenharmony_cistatic inline struct mlx5_ib_srq *to_mibsrq(struct mlx5_core_srq *msrq)
10948c2ecf20Sopenharmony_ci{
10958c2ecf20Sopenharmony_ci	return container_of(msrq, struct mlx5_ib_srq, msrq);
10968c2ecf20Sopenharmony_ci}
10978c2ecf20Sopenharmony_ci
10988c2ecf20Sopenharmony_cistatic inline struct mlx5_ib_dm *to_mdm(struct ib_dm *ibdm)
10998c2ecf20Sopenharmony_ci{
11008c2ecf20Sopenharmony_ci	return container_of(ibdm, struct mlx5_ib_dm, ibdm);
11018c2ecf20Sopenharmony_ci}
11028c2ecf20Sopenharmony_ci
11038c2ecf20Sopenharmony_cistatic inline struct mlx5_ib_mr *to_mmr(struct ib_mr *ibmr)
11048c2ecf20Sopenharmony_ci{
11058c2ecf20Sopenharmony_ci	return container_of(ibmr, struct mlx5_ib_mr, ibmr);
11068c2ecf20Sopenharmony_ci}
11078c2ecf20Sopenharmony_ci
11088c2ecf20Sopenharmony_cistatic inline struct mlx5_ib_mw *to_mmw(struct ib_mw *ibmw)
11098c2ecf20Sopenharmony_ci{
11108c2ecf20Sopenharmony_ci	return container_of(ibmw, struct mlx5_ib_mw, ibmw);
11118c2ecf20Sopenharmony_ci}
11128c2ecf20Sopenharmony_ci
11138c2ecf20Sopenharmony_cistatic inline struct mlx5_ib_flow_action *
11148c2ecf20Sopenharmony_cito_mflow_act(struct ib_flow_action *ibact)
11158c2ecf20Sopenharmony_ci{
11168c2ecf20Sopenharmony_ci	return container_of(ibact, struct mlx5_ib_flow_action, ib_action);
11178c2ecf20Sopenharmony_ci}
11188c2ecf20Sopenharmony_ci
11198c2ecf20Sopenharmony_cistatic inline struct mlx5_user_mmap_entry *
11208c2ecf20Sopenharmony_cito_mmmap(struct rdma_user_mmap_entry *rdma_entry)
11218c2ecf20Sopenharmony_ci{
11228c2ecf20Sopenharmony_ci	return container_of(rdma_entry,
11238c2ecf20Sopenharmony_ci		struct mlx5_user_mmap_entry, rdma_entry);
11248c2ecf20Sopenharmony_ci}
11258c2ecf20Sopenharmony_ci
11268c2ecf20Sopenharmony_ciint mlx5_ib_db_map_user(struct mlx5_ib_ucontext *context,
11278c2ecf20Sopenharmony_ci			struct ib_udata *udata, unsigned long virt,
11288c2ecf20Sopenharmony_ci			struct mlx5_db *db);
11298c2ecf20Sopenharmony_civoid mlx5_ib_db_unmap_user(struct mlx5_ib_ucontext *context, struct mlx5_db *db);
11308c2ecf20Sopenharmony_civoid __mlx5_ib_cq_clean(struct mlx5_ib_cq *cq, u32 qpn, struct mlx5_ib_srq *srq);
11318c2ecf20Sopenharmony_civoid mlx5_ib_cq_clean(struct mlx5_ib_cq *cq, u32 qpn, struct mlx5_ib_srq *srq);
11328c2ecf20Sopenharmony_civoid mlx5_ib_free_srq_wqe(struct mlx5_ib_srq *srq, int wqe_index);
11338c2ecf20Sopenharmony_ciint mlx5_ib_create_ah(struct ib_ah *ah, struct rdma_ah_init_attr *init_attr,
11348c2ecf20Sopenharmony_ci		      struct ib_udata *udata);
11358c2ecf20Sopenharmony_ciint mlx5_ib_query_ah(struct ib_ah *ibah, struct rdma_ah_attr *ah_attr);
11368c2ecf20Sopenharmony_cistatic inline int mlx5_ib_destroy_ah(struct ib_ah *ah, u32 flags)
11378c2ecf20Sopenharmony_ci{
11388c2ecf20Sopenharmony_ci	return 0;
11398c2ecf20Sopenharmony_ci}
11408c2ecf20Sopenharmony_ciint mlx5_ib_create_srq(struct ib_srq *srq, struct ib_srq_init_attr *init_attr,
11418c2ecf20Sopenharmony_ci		       struct ib_udata *udata);
11428c2ecf20Sopenharmony_ciint mlx5_ib_modify_srq(struct ib_srq *ibsrq, struct ib_srq_attr *attr,
11438c2ecf20Sopenharmony_ci		       enum ib_srq_attr_mask attr_mask, struct ib_udata *udata);
11448c2ecf20Sopenharmony_ciint mlx5_ib_query_srq(struct ib_srq *ibsrq, struct ib_srq_attr *srq_attr);
11458c2ecf20Sopenharmony_ciint mlx5_ib_destroy_srq(struct ib_srq *srq, struct ib_udata *udata);
11468c2ecf20Sopenharmony_ciint mlx5_ib_post_srq_recv(struct ib_srq *ibsrq, const struct ib_recv_wr *wr,
11478c2ecf20Sopenharmony_ci			  const struct ib_recv_wr **bad_wr);
11488c2ecf20Sopenharmony_ciint mlx5_ib_enable_lb(struct mlx5_ib_dev *dev, bool td, bool qp);
11498c2ecf20Sopenharmony_civoid mlx5_ib_disable_lb(struct mlx5_ib_dev *dev, bool td, bool qp);
11508c2ecf20Sopenharmony_cistruct ib_qp *mlx5_ib_create_qp(struct ib_pd *pd,
11518c2ecf20Sopenharmony_ci				struct ib_qp_init_attr *init_attr,
11528c2ecf20Sopenharmony_ci				struct ib_udata *udata);
11538c2ecf20Sopenharmony_ciint mlx5_ib_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr,
11548c2ecf20Sopenharmony_ci		      int attr_mask, struct ib_udata *udata);
11558c2ecf20Sopenharmony_ciint mlx5_ib_query_qp(struct ib_qp *ibqp, struct ib_qp_attr *qp_attr, int qp_attr_mask,
11568c2ecf20Sopenharmony_ci		     struct ib_qp_init_attr *qp_init_attr);
11578c2ecf20Sopenharmony_ciint mlx5_ib_destroy_qp(struct ib_qp *qp, struct ib_udata *udata);
11588c2ecf20Sopenharmony_civoid mlx5_ib_drain_sq(struct ib_qp *qp);
11598c2ecf20Sopenharmony_civoid mlx5_ib_drain_rq(struct ib_qp *qp);
11608c2ecf20Sopenharmony_ciint mlx5_ib_read_wqe_sq(struct mlx5_ib_qp *qp, int wqe_index, void *buffer,
11618c2ecf20Sopenharmony_ci			size_t buflen, size_t *bc);
11628c2ecf20Sopenharmony_ciint mlx5_ib_read_wqe_rq(struct mlx5_ib_qp *qp, int wqe_index, void *buffer,
11638c2ecf20Sopenharmony_ci			size_t buflen, size_t *bc);
11648c2ecf20Sopenharmony_ciint mlx5_ib_read_wqe_srq(struct mlx5_ib_srq *srq, int wqe_index, void *buffer,
11658c2ecf20Sopenharmony_ci			 size_t buflen, size_t *bc);
11668c2ecf20Sopenharmony_ciint mlx5_ib_create_cq(struct ib_cq *ibcq, const struct ib_cq_init_attr *attr,
11678c2ecf20Sopenharmony_ci		      struct ib_udata *udata);
11688c2ecf20Sopenharmony_ciint mlx5_ib_destroy_cq(struct ib_cq *cq, struct ib_udata *udata);
11698c2ecf20Sopenharmony_ciint mlx5_ib_poll_cq(struct ib_cq *ibcq, int num_entries, struct ib_wc *wc);
11708c2ecf20Sopenharmony_ciint mlx5_ib_arm_cq(struct ib_cq *ibcq, enum ib_cq_notify_flags flags);
11718c2ecf20Sopenharmony_ciint mlx5_ib_modify_cq(struct ib_cq *cq, u16 cq_count, u16 cq_period);
11728c2ecf20Sopenharmony_ciint mlx5_ib_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata);
11738c2ecf20Sopenharmony_cistruct ib_mr *mlx5_ib_get_dma_mr(struct ib_pd *pd, int acc);
11748c2ecf20Sopenharmony_cistruct ib_mr *mlx5_ib_reg_user_mr(struct ib_pd *pd, u64 start, u64 length,
11758c2ecf20Sopenharmony_ci				  u64 virt_addr, int access_flags,
11768c2ecf20Sopenharmony_ci				  struct ib_udata *udata);
11778c2ecf20Sopenharmony_ciint mlx5_ib_advise_mr(struct ib_pd *pd,
11788c2ecf20Sopenharmony_ci		      enum ib_uverbs_advise_mr_advice advice,
11798c2ecf20Sopenharmony_ci		      u32 flags,
11808c2ecf20Sopenharmony_ci		      struct ib_sge *sg_list,
11818c2ecf20Sopenharmony_ci		      u32 num_sge,
11828c2ecf20Sopenharmony_ci		      struct uverbs_attr_bundle *attrs);
11838c2ecf20Sopenharmony_ciint mlx5_ib_alloc_mw(struct ib_mw *mw, struct ib_udata *udata);
11848c2ecf20Sopenharmony_ciint mlx5_ib_dealloc_mw(struct ib_mw *mw);
11858c2ecf20Sopenharmony_ciint mlx5_ib_update_xlt(struct mlx5_ib_mr *mr, u64 idx, int npages,
11868c2ecf20Sopenharmony_ci		       int page_shift, int flags);
11878c2ecf20Sopenharmony_cistruct mlx5_ib_mr *mlx5_ib_alloc_implicit_mr(struct mlx5_ib_pd *pd,
11888c2ecf20Sopenharmony_ci					     struct ib_udata *udata,
11898c2ecf20Sopenharmony_ci					     int access_flags);
11908c2ecf20Sopenharmony_civoid mlx5_ib_free_implicit_mr(struct mlx5_ib_mr *mr);
11918c2ecf20Sopenharmony_civoid mlx5_ib_fence_odp_mr(struct mlx5_ib_mr *mr);
11928c2ecf20Sopenharmony_ciint mlx5_ib_rereg_user_mr(struct ib_mr *ib_mr, int flags, u64 start,
11938c2ecf20Sopenharmony_ci			  u64 length, u64 virt_addr, int access_flags,
11948c2ecf20Sopenharmony_ci			  struct ib_pd *pd, struct ib_udata *udata);
11958c2ecf20Sopenharmony_ciint mlx5_ib_dereg_mr(struct ib_mr *ibmr, struct ib_udata *udata);
11968c2ecf20Sopenharmony_cistruct ib_mr *mlx5_ib_alloc_mr(struct ib_pd *pd, enum ib_mr_type mr_type,
11978c2ecf20Sopenharmony_ci			       u32 max_num_sg);
11988c2ecf20Sopenharmony_cistruct ib_mr *mlx5_ib_alloc_mr_integrity(struct ib_pd *pd,
11998c2ecf20Sopenharmony_ci					 u32 max_num_sg,
12008c2ecf20Sopenharmony_ci					 u32 max_num_meta_sg);
12018c2ecf20Sopenharmony_ciint mlx5_ib_map_mr_sg(struct ib_mr *ibmr, struct scatterlist *sg, int sg_nents,
12028c2ecf20Sopenharmony_ci		      unsigned int *sg_offset);
12038c2ecf20Sopenharmony_ciint mlx5_ib_map_mr_sg_pi(struct ib_mr *ibmr, struct scatterlist *data_sg,
12048c2ecf20Sopenharmony_ci			 int data_sg_nents, unsigned int *data_sg_offset,
12058c2ecf20Sopenharmony_ci			 struct scatterlist *meta_sg, int meta_sg_nents,
12068c2ecf20Sopenharmony_ci			 unsigned int *meta_sg_offset);
12078c2ecf20Sopenharmony_ciint mlx5_ib_process_mad(struct ib_device *ibdev, int mad_flags, u8 port_num,
12088c2ecf20Sopenharmony_ci			const struct ib_wc *in_wc, const struct ib_grh *in_grh,
12098c2ecf20Sopenharmony_ci			const struct ib_mad *in, struct ib_mad *out,
12108c2ecf20Sopenharmony_ci			size_t *out_mad_size, u16 *out_mad_pkey_index);
12118c2ecf20Sopenharmony_ciint mlx5_ib_alloc_xrcd(struct ib_xrcd *xrcd, struct ib_udata *udata);
12128c2ecf20Sopenharmony_ciint mlx5_ib_dealloc_xrcd(struct ib_xrcd *xrcd, struct ib_udata *udata);
12138c2ecf20Sopenharmony_ciint mlx5_ib_get_buf_offset(u64 addr, int page_shift, u32 *offset);
12148c2ecf20Sopenharmony_ciint mlx5_query_ext_port_caps(struct mlx5_ib_dev *dev, u8 port);
12158c2ecf20Sopenharmony_ciint mlx5_query_mad_ifc_smp_attr_node_info(struct ib_device *ibdev,
12168c2ecf20Sopenharmony_ci					  struct ib_smp *out_mad);
12178c2ecf20Sopenharmony_ciint mlx5_query_mad_ifc_system_image_guid(struct ib_device *ibdev,
12188c2ecf20Sopenharmony_ci					 __be64 *sys_image_guid);
12198c2ecf20Sopenharmony_ciint mlx5_query_mad_ifc_max_pkeys(struct ib_device *ibdev,
12208c2ecf20Sopenharmony_ci				 u16 *max_pkeys);
12218c2ecf20Sopenharmony_ciint mlx5_query_mad_ifc_vendor_id(struct ib_device *ibdev,
12228c2ecf20Sopenharmony_ci				 u32 *vendor_id);
12238c2ecf20Sopenharmony_ciint mlx5_query_mad_ifc_node_desc(struct mlx5_ib_dev *dev, char *node_desc);
12248c2ecf20Sopenharmony_ciint mlx5_query_mad_ifc_node_guid(struct mlx5_ib_dev *dev, __be64 *node_guid);
12258c2ecf20Sopenharmony_ciint mlx5_query_mad_ifc_pkey(struct ib_device *ibdev, u8 port, u16 index,
12268c2ecf20Sopenharmony_ci			    u16 *pkey);
12278c2ecf20Sopenharmony_ciint mlx5_query_mad_ifc_gids(struct ib_device *ibdev, u8 port, int index,
12288c2ecf20Sopenharmony_ci			    union ib_gid *gid);
12298c2ecf20Sopenharmony_ciint mlx5_query_mad_ifc_port(struct ib_device *ibdev, u8 port,
12308c2ecf20Sopenharmony_ci			    struct ib_port_attr *props);
12318c2ecf20Sopenharmony_ciint mlx5_ib_query_port(struct ib_device *ibdev, u8 port,
12328c2ecf20Sopenharmony_ci		       struct ib_port_attr *props);
12338c2ecf20Sopenharmony_civoid mlx5_ib_cont_pages(struct ib_umem *umem, u64 addr,
12348c2ecf20Sopenharmony_ci			unsigned long max_page_shift,
12358c2ecf20Sopenharmony_ci			int *count, int *shift,
12368c2ecf20Sopenharmony_ci			int *ncont, int *order);
12378c2ecf20Sopenharmony_civoid __mlx5_ib_populate_pas(struct mlx5_ib_dev *dev, struct ib_umem *umem,
12388c2ecf20Sopenharmony_ci			    int page_shift, size_t offset, size_t num_pages,
12398c2ecf20Sopenharmony_ci			    __be64 *pas, int access_flags);
12408c2ecf20Sopenharmony_civoid mlx5_ib_populate_pas(struct mlx5_ib_dev *dev, struct ib_umem *umem,
12418c2ecf20Sopenharmony_ci			  int page_shift, __be64 *pas, int access_flags);
12428c2ecf20Sopenharmony_civoid mlx5_ib_copy_pas(u64 *old, u64 *new, int step, int num);
12438c2ecf20Sopenharmony_ciint mlx5_ib_get_cqe_size(struct ib_cq *ibcq);
12448c2ecf20Sopenharmony_ciint mlx5_mr_cache_init(struct mlx5_ib_dev *dev);
12458c2ecf20Sopenharmony_ciint mlx5_mr_cache_cleanup(struct mlx5_ib_dev *dev);
12468c2ecf20Sopenharmony_ci
12478c2ecf20Sopenharmony_cistruct mlx5_ib_mr *mlx5_mr_cache_alloc(struct mlx5_ib_dev *dev,
12488c2ecf20Sopenharmony_ci				       unsigned int entry, int access_flags);
12498c2ecf20Sopenharmony_civoid mlx5_mr_cache_free(struct mlx5_ib_dev *dev, struct mlx5_ib_mr *mr);
12508c2ecf20Sopenharmony_ciint mlx5_mr_cache_invalidate(struct mlx5_ib_mr *mr);
12518c2ecf20Sopenharmony_ci
12528c2ecf20Sopenharmony_ciint mlx5_ib_check_mr_status(struct ib_mr *ibmr, u32 check_mask,
12538c2ecf20Sopenharmony_ci			    struct ib_mr_status *mr_status);
12548c2ecf20Sopenharmony_cistruct ib_wq *mlx5_ib_create_wq(struct ib_pd *pd,
12558c2ecf20Sopenharmony_ci				struct ib_wq_init_attr *init_attr,
12568c2ecf20Sopenharmony_ci				struct ib_udata *udata);
12578c2ecf20Sopenharmony_ciint mlx5_ib_destroy_wq(struct ib_wq *wq, struct ib_udata *udata);
12588c2ecf20Sopenharmony_ciint mlx5_ib_modify_wq(struct ib_wq *wq, struct ib_wq_attr *wq_attr,
12598c2ecf20Sopenharmony_ci		      u32 wq_attr_mask, struct ib_udata *udata);
12608c2ecf20Sopenharmony_ciint mlx5_ib_create_rwq_ind_table(struct ib_rwq_ind_table *ib_rwq_ind_table,
12618c2ecf20Sopenharmony_ci				 struct ib_rwq_ind_table_init_attr *init_attr,
12628c2ecf20Sopenharmony_ci				 struct ib_udata *udata);
12638c2ecf20Sopenharmony_ciint mlx5_ib_destroy_rwq_ind_table(struct ib_rwq_ind_table *wq_ind_table);
12648c2ecf20Sopenharmony_cistruct ib_dm *mlx5_ib_alloc_dm(struct ib_device *ibdev,
12658c2ecf20Sopenharmony_ci			       struct ib_ucontext *context,
12668c2ecf20Sopenharmony_ci			       struct ib_dm_alloc_attr *attr,
12678c2ecf20Sopenharmony_ci			       struct uverbs_attr_bundle *attrs);
12688c2ecf20Sopenharmony_ciint mlx5_ib_dealloc_dm(struct ib_dm *ibdm, struct uverbs_attr_bundle *attrs);
12698c2ecf20Sopenharmony_cistruct ib_mr *mlx5_ib_reg_dm_mr(struct ib_pd *pd, struct ib_dm *dm,
12708c2ecf20Sopenharmony_ci				struct ib_dm_mr_attr *attr,
12718c2ecf20Sopenharmony_ci				struct uverbs_attr_bundle *attrs);
12728c2ecf20Sopenharmony_ci
12738c2ecf20Sopenharmony_ci#ifdef CONFIG_INFINIBAND_ON_DEMAND_PAGING
12748c2ecf20Sopenharmony_civoid mlx5_ib_internal_fill_odp_caps(struct mlx5_ib_dev *dev);
12758c2ecf20Sopenharmony_ciint mlx5_ib_odp_init_one(struct mlx5_ib_dev *ibdev);
12768c2ecf20Sopenharmony_civoid mlx5_ib_odp_cleanup_one(struct mlx5_ib_dev *ibdev);
12778c2ecf20Sopenharmony_ciint __init mlx5_ib_odp_init(void);
12788c2ecf20Sopenharmony_civoid mlx5_ib_odp_cleanup(void);
12798c2ecf20Sopenharmony_civoid mlx5_odp_init_mr_cache_entry(struct mlx5_cache_ent *ent);
12808c2ecf20Sopenharmony_civoid mlx5_odp_populate_xlt(void *xlt, size_t idx, size_t nentries,
12818c2ecf20Sopenharmony_ci			   struct mlx5_ib_mr *mr, int flags);
12828c2ecf20Sopenharmony_ci
12838c2ecf20Sopenharmony_ciint mlx5_ib_advise_mr_prefetch(struct ib_pd *pd,
12848c2ecf20Sopenharmony_ci			       enum ib_uverbs_advise_mr_advice advice,
12858c2ecf20Sopenharmony_ci			       u32 flags, struct ib_sge *sg_list, u32 num_sge);
12868c2ecf20Sopenharmony_ciint mlx5_ib_init_odp_mr(struct mlx5_ib_mr *mr, bool enable);
12878c2ecf20Sopenharmony_ci#else /* CONFIG_INFINIBAND_ON_DEMAND_PAGING */
12888c2ecf20Sopenharmony_cistatic inline void mlx5_ib_internal_fill_odp_caps(struct mlx5_ib_dev *dev)
12898c2ecf20Sopenharmony_ci{
12908c2ecf20Sopenharmony_ci	return;
12918c2ecf20Sopenharmony_ci}
12928c2ecf20Sopenharmony_ci
12938c2ecf20Sopenharmony_cistatic inline int mlx5_ib_odp_init_one(struct mlx5_ib_dev *ibdev) { return 0; }
12948c2ecf20Sopenharmony_cistatic inline void mlx5_ib_odp_cleanup_one(struct mlx5_ib_dev *ibdev) {}
12958c2ecf20Sopenharmony_cistatic inline int mlx5_ib_odp_init(void) { return 0; }
12968c2ecf20Sopenharmony_cistatic inline void mlx5_ib_odp_cleanup(void)				    {}
12978c2ecf20Sopenharmony_cistatic inline void mlx5_odp_init_mr_cache_entry(struct mlx5_cache_ent *ent) {}
12988c2ecf20Sopenharmony_cistatic inline void mlx5_odp_populate_xlt(void *xlt, size_t idx, size_t nentries,
12998c2ecf20Sopenharmony_ci					 struct mlx5_ib_mr *mr, int flags) {}
13008c2ecf20Sopenharmony_ci
13018c2ecf20Sopenharmony_cistatic inline int
13028c2ecf20Sopenharmony_cimlx5_ib_advise_mr_prefetch(struct ib_pd *pd,
13038c2ecf20Sopenharmony_ci			   enum ib_uverbs_advise_mr_advice advice, u32 flags,
13048c2ecf20Sopenharmony_ci			   struct ib_sge *sg_list, u32 num_sge)
13058c2ecf20Sopenharmony_ci{
13068c2ecf20Sopenharmony_ci	return -EOPNOTSUPP;
13078c2ecf20Sopenharmony_ci}
13088c2ecf20Sopenharmony_cistatic inline int mlx5_ib_init_odp_mr(struct mlx5_ib_mr *mr, bool enable)
13098c2ecf20Sopenharmony_ci{
13108c2ecf20Sopenharmony_ci	return -EOPNOTSUPP;
13118c2ecf20Sopenharmony_ci}
13128c2ecf20Sopenharmony_ci#endif /* CONFIG_INFINIBAND_ON_DEMAND_PAGING */
13138c2ecf20Sopenharmony_ci
13148c2ecf20Sopenharmony_ciextern const struct mmu_interval_notifier_ops mlx5_mn_ops;
13158c2ecf20Sopenharmony_ci
13168c2ecf20Sopenharmony_ci/* Needed for rep profile */
13178c2ecf20Sopenharmony_civoid __mlx5_ib_remove(struct mlx5_ib_dev *dev,
13188c2ecf20Sopenharmony_ci		      const struct mlx5_ib_profile *profile,
13198c2ecf20Sopenharmony_ci		      int stage);
13208c2ecf20Sopenharmony_civoid *__mlx5_ib_add(struct mlx5_ib_dev *dev,
13218c2ecf20Sopenharmony_ci		    const struct mlx5_ib_profile *profile);
13228c2ecf20Sopenharmony_ci
13238c2ecf20Sopenharmony_ciint mlx5_ib_get_vf_config(struct ib_device *device, int vf,
13248c2ecf20Sopenharmony_ci			  u8 port, struct ifla_vf_info *info);
13258c2ecf20Sopenharmony_ciint mlx5_ib_set_vf_link_state(struct ib_device *device, int vf,
13268c2ecf20Sopenharmony_ci			      u8 port, int state);
13278c2ecf20Sopenharmony_ciint mlx5_ib_get_vf_stats(struct ib_device *device, int vf,
13288c2ecf20Sopenharmony_ci			 u8 port, struct ifla_vf_stats *stats);
13298c2ecf20Sopenharmony_ciint mlx5_ib_get_vf_guid(struct ib_device *device, int vf, u8 port,
13308c2ecf20Sopenharmony_ci			struct ifla_vf_guid *node_guid,
13318c2ecf20Sopenharmony_ci			struct ifla_vf_guid *port_guid);
13328c2ecf20Sopenharmony_ciint mlx5_ib_set_vf_guid(struct ib_device *device, int vf, u8 port,
13338c2ecf20Sopenharmony_ci			u64 guid, int type);
13348c2ecf20Sopenharmony_ci
13358c2ecf20Sopenharmony_ci__be16 mlx5_get_roce_udp_sport_min(const struct mlx5_ib_dev *dev,
13368c2ecf20Sopenharmony_ci				   const struct ib_gid_attr *attr);
13378c2ecf20Sopenharmony_ci
13388c2ecf20Sopenharmony_civoid mlx5_ib_cleanup_cong_debugfs(struct mlx5_ib_dev *dev, u8 port_num);
13398c2ecf20Sopenharmony_civoid mlx5_ib_init_cong_debugfs(struct mlx5_ib_dev *dev, u8 port_num);
13408c2ecf20Sopenharmony_ci
13418c2ecf20Sopenharmony_ci/* GSI QP helper functions */
13428c2ecf20Sopenharmony_ciint mlx5_ib_create_gsi(struct ib_pd *pd, struct mlx5_ib_qp *mqp,
13438c2ecf20Sopenharmony_ci		       struct ib_qp_init_attr *attr);
13448c2ecf20Sopenharmony_ciint mlx5_ib_destroy_gsi(struct mlx5_ib_qp *mqp);
13458c2ecf20Sopenharmony_ciint mlx5_ib_gsi_modify_qp(struct ib_qp *qp, struct ib_qp_attr *attr,
13468c2ecf20Sopenharmony_ci			  int attr_mask);
13478c2ecf20Sopenharmony_ciint mlx5_ib_gsi_query_qp(struct ib_qp *qp, struct ib_qp_attr *qp_attr,
13488c2ecf20Sopenharmony_ci			 int qp_attr_mask,
13498c2ecf20Sopenharmony_ci			 struct ib_qp_init_attr *qp_init_attr);
13508c2ecf20Sopenharmony_ciint mlx5_ib_gsi_post_send(struct ib_qp *qp, const struct ib_send_wr *wr,
13518c2ecf20Sopenharmony_ci			  const struct ib_send_wr **bad_wr);
13528c2ecf20Sopenharmony_ciint mlx5_ib_gsi_post_recv(struct ib_qp *qp, const struct ib_recv_wr *wr,
13538c2ecf20Sopenharmony_ci			  const struct ib_recv_wr **bad_wr);
13548c2ecf20Sopenharmony_civoid mlx5_ib_gsi_pkey_change(struct mlx5_ib_gsi_qp *gsi);
13558c2ecf20Sopenharmony_ci
13568c2ecf20Sopenharmony_ciint mlx5_ib_generate_wc(struct ib_cq *ibcq, struct ib_wc *wc);
13578c2ecf20Sopenharmony_ci
13588c2ecf20Sopenharmony_civoid mlx5_ib_free_bfreg(struct mlx5_ib_dev *dev, struct mlx5_bfreg_info *bfregi,
13598c2ecf20Sopenharmony_ci			int bfregn);
13608c2ecf20Sopenharmony_cistruct mlx5_ib_dev *mlx5_ib_get_ibdev_from_mpi(struct mlx5_ib_multiport_info *mpi);
13618c2ecf20Sopenharmony_cistruct mlx5_core_dev *mlx5_ib_get_native_port_mdev(struct mlx5_ib_dev *dev,
13628c2ecf20Sopenharmony_ci						   u8 ib_port_num,
13638c2ecf20Sopenharmony_ci						   u8 *native_port_num);
13648c2ecf20Sopenharmony_civoid mlx5_ib_put_native_port_mdev(struct mlx5_ib_dev *dev,
13658c2ecf20Sopenharmony_ci				  u8 port_num);
13668c2ecf20Sopenharmony_ci
13678c2ecf20Sopenharmony_ciextern const struct uapi_definition mlx5_ib_devx_defs[];
13688c2ecf20Sopenharmony_ciextern const struct uapi_definition mlx5_ib_flow_defs[];
13698c2ecf20Sopenharmony_ciextern const struct uapi_definition mlx5_ib_qos_defs[];
13708c2ecf20Sopenharmony_ciextern const struct uapi_definition mlx5_ib_std_types_defs[];
13718c2ecf20Sopenharmony_ci
13728c2ecf20Sopenharmony_cistatic inline void init_query_mad(struct ib_smp *mad)
13738c2ecf20Sopenharmony_ci{
13748c2ecf20Sopenharmony_ci	mad->base_version  = 1;
13758c2ecf20Sopenharmony_ci	mad->mgmt_class    = IB_MGMT_CLASS_SUBN_LID_ROUTED;
13768c2ecf20Sopenharmony_ci	mad->class_version = 1;
13778c2ecf20Sopenharmony_ci	mad->method	   = IB_MGMT_METHOD_GET;
13788c2ecf20Sopenharmony_ci}
13798c2ecf20Sopenharmony_ci
13808c2ecf20Sopenharmony_cistatic inline int is_qp1(enum ib_qp_type qp_type)
13818c2ecf20Sopenharmony_ci{
13828c2ecf20Sopenharmony_ci	return qp_type == MLX5_IB_QPT_HW_GSI || qp_type == IB_QPT_GSI;
13838c2ecf20Sopenharmony_ci}
13848c2ecf20Sopenharmony_ci
13858c2ecf20Sopenharmony_ci#define MLX5_MAX_UMR_SHIFT 16
13868c2ecf20Sopenharmony_ci#define MLX5_MAX_UMR_PAGES (1 << MLX5_MAX_UMR_SHIFT)
13878c2ecf20Sopenharmony_ci
13888c2ecf20Sopenharmony_cistatic inline u32 check_cq_create_flags(u32 flags)
13898c2ecf20Sopenharmony_ci{
13908c2ecf20Sopenharmony_ci	/*
13918c2ecf20Sopenharmony_ci	 * It returns non-zero value for unsupported CQ
13928c2ecf20Sopenharmony_ci	 * create flags, otherwise it returns zero.
13938c2ecf20Sopenharmony_ci	 */
13948c2ecf20Sopenharmony_ci	return (flags & ~(IB_UVERBS_CQ_FLAGS_IGNORE_OVERRUN |
13958c2ecf20Sopenharmony_ci			  IB_UVERBS_CQ_FLAGS_TIMESTAMP_COMPLETION));
13968c2ecf20Sopenharmony_ci}
13978c2ecf20Sopenharmony_ci
13988c2ecf20Sopenharmony_cistatic inline int verify_assign_uidx(u8 cqe_version, u32 cmd_uidx,
13998c2ecf20Sopenharmony_ci				     u32 *user_index)
14008c2ecf20Sopenharmony_ci{
14018c2ecf20Sopenharmony_ci	if (cqe_version) {
14028c2ecf20Sopenharmony_ci		if ((cmd_uidx == MLX5_IB_DEFAULT_UIDX) ||
14038c2ecf20Sopenharmony_ci		    (cmd_uidx & ~MLX5_USER_ASSIGNED_UIDX_MASK))
14048c2ecf20Sopenharmony_ci			return -EINVAL;
14058c2ecf20Sopenharmony_ci		*user_index = cmd_uidx;
14068c2ecf20Sopenharmony_ci	} else {
14078c2ecf20Sopenharmony_ci		*user_index = MLX5_IB_DEFAULT_UIDX;
14088c2ecf20Sopenharmony_ci	}
14098c2ecf20Sopenharmony_ci
14108c2ecf20Sopenharmony_ci	return 0;
14118c2ecf20Sopenharmony_ci}
14128c2ecf20Sopenharmony_ci
14138c2ecf20Sopenharmony_cistatic inline int get_qp_user_index(struct mlx5_ib_ucontext *ucontext,
14148c2ecf20Sopenharmony_ci				    struct mlx5_ib_create_qp *ucmd,
14158c2ecf20Sopenharmony_ci				    int inlen,
14168c2ecf20Sopenharmony_ci				    u32 *user_index)
14178c2ecf20Sopenharmony_ci{
14188c2ecf20Sopenharmony_ci	u8 cqe_version = ucontext->cqe_version;
14198c2ecf20Sopenharmony_ci
14208c2ecf20Sopenharmony_ci	if ((offsetofend(typeof(*ucmd), uidx) <= inlen) && !cqe_version &&
14218c2ecf20Sopenharmony_ci	    (ucmd->uidx == MLX5_IB_DEFAULT_UIDX))
14228c2ecf20Sopenharmony_ci		return 0;
14238c2ecf20Sopenharmony_ci
14248c2ecf20Sopenharmony_ci	if ((offsetofend(typeof(*ucmd), uidx) <= inlen) != !!cqe_version)
14258c2ecf20Sopenharmony_ci		return -EINVAL;
14268c2ecf20Sopenharmony_ci
14278c2ecf20Sopenharmony_ci	return verify_assign_uidx(cqe_version, ucmd->uidx, user_index);
14288c2ecf20Sopenharmony_ci}
14298c2ecf20Sopenharmony_ci
14308c2ecf20Sopenharmony_cistatic inline int get_srq_user_index(struct mlx5_ib_ucontext *ucontext,
14318c2ecf20Sopenharmony_ci				     struct mlx5_ib_create_srq *ucmd,
14328c2ecf20Sopenharmony_ci				     int inlen,
14338c2ecf20Sopenharmony_ci				     u32 *user_index)
14348c2ecf20Sopenharmony_ci{
14358c2ecf20Sopenharmony_ci	u8 cqe_version = ucontext->cqe_version;
14368c2ecf20Sopenharmony_ci
14378c2ecf20Sopenharmony_ci	if ((offsetofend(typeof(*ucmd), uidx) <= inlen) && !cqe_version &&
14388c2ecf20Sopenharmony_ci	    (ucmd->uidx == MLX5_IB_DEFAULT_UIDX))
14398c2ecf20Sopenharmony_ci		return 0;
14408c2ecf20Sopenharmony_ci
14418c2ecf20Sopenharmony_ci	if ((offsetofend(typeof(*ucmd), uidx) <= inlen) != !!cqe_version)
14428c2ecf20Sopenharmony_ci		return -EINVAL;
14438c2ecf20Sopenharmony_ci
14448c2ecf20Sopenharmony_ci	return verify_assign_uidx(cqe_version, ucmd->uidx, user_index);
14458c2ecf20Sopenharmony_ci}
14468c2ecf20Sopenharmony_ci
14478c2ecf20Sopenharmony_cistatic inline int get_uars_per_sys_page(struct mlx5_ib_dev *dev, bool lib_support)
14488c2ecf20Sopenharmony_ci{
14498c2ecf20Sopenharmony_ci	return lib_support && MLX5_CAP_GEN(dev->mdev, uar_4k) ?
14508c2ecf20Sopenharmony_ci				MLX5_UARS_IN_PAGE : 1;
14518c2ecf20Sopenharmony_ci}
14528c2ecf20Sopenharmony_ci
14538c2ecf20Sopenharmony_cistatic inline int get_num_static_uars(struct mlx5_ib_dev *dev,
14548c2ecf20Sopenharmony_ci				      struct mlx5_bfreg_info *bfregi)
14558c2ecf20Sopenharmony_ci{
14568c2ecf20Sopenharmony_ci	return get_uars_per_sys_page(dev, bfregi->lib_uar_4k) * bfregi->num_static_sys_pages;
14578c2ecf20Sopenharmony_ci}
14588c2ecf20Sopenharmony_ci
14598c2ecf20Sopenharmony_ciunsigned long mlx5_ib_get_xlt_emergency_page(void);
14608c2ecf20Sopenharmony_civoid mlx5_ib_put_xlt_emergency_page(void);
14618c2ecf20Sopenharmony_ci
14628c2ecf20Sopenharmony_ciint bfregn_to_uar_index(struct mlx5_ib_dev *dev,
14638c2ecf20Sopenharmony_ci			struct mlx5_bfreg_info *bfregi, u32 bfregn,
14648c2ecf20Sopenharmony_ci			bool dyn_bfreg);
14658c2ecf20Sopenharmony_ci
14668c2ecf20Sopenharmony_cistatic inline bool mlx5_ib_can_load_pas_with_umr(struct mlx5_ib_dev *dev,
14678c2ecf20Sopenharmony_ci						 size_t length)
14688c2ecf20Sopenharmony_ci{
14698c2ecf20Sopenharmony_ci	/*
14708c2ecf20Sopenharmony_ci	 * umr_check_mkey_mask() rejects MLX5_MKEY_MASK_PAGE_SIZE which is
14718c2ecf20Sopenharmony_ci	 * always set if MLX5_IB_SEND_UMR_UPDATE_TRANSLATION (aka
14728c2ecf20Sopenharmony_ci	 * MLX5_IB_UPD_XLT_ADDR and MLX5_IB_UPD_XLT_ENABLE) is set. Thus, a mkey
14738c2ecf20Sopenharmony_ci	 * can never be enabled without this capability. Simplify this weird
14748c2ecf20Sopenharmony_ci	 * quirky hardware by just saying it can't use PAS lists with UMR at
14758c2ecf20Sopenharmony_ci	 * all.
14768c2ecf20Sopenharmony_ci	 */
14778c2ecf20Sopenharmony_ci	if (MLX5_CAP_GEN(dev->mdev, umr_modify_entity_size_disabled))
14788c2ecf20Sopenharmony_ci		return false;
14798c2ecf20Sopenharmony_ci
14808c2ecf20Sopenharmony_ci	/*
14818c2ecf20Sopenharmony_ci	 * length is the size of the MR in bytes when mlx5_ib_update_xlt() is
14828c2ecf20Sopenharmony_ci	 * used.
14838c2ecf20Sopenharmony_ci	 */
14848c2ecf20Sopenharmony_ci	if (!MLX5_CAP_GEN(dev->mdev, umr_extended_translation_offset) &&
14858c2ecf20Sopenharmony_ci	    length >= MLX5_MAX_UMR_PAGES * PAGE_SIZE)
14868c2ecf20Sopenharmony_ci		return false;
14878c2ecf20Sopenharmony_ci	return true;
14888c2ecf20Sopenharmony_ci}
14898c2ecf20Sopenharmony_ci
14908c2ecf20Sopenharmony_ci/*
14918c2ecf20Sopenharmony_ci * true if an existing MR can be reconfigured to new access_flags using UMR.
14928c2ecf20Sopenharmony_ci * Older HW cannot use UMR to update certain elements of the MKC. See
14938c2ecf20Sopenharmony_ci * umr_check_mkey_mask(), get_umr_update_access_mask() and umr_check_mkey_mask()
14948c2ecf20Sopenharmony_ci */
14958c2ecf20Sopenharmony_cistatic inline bool mlx5_ib_can_reconfig_with_umr(struct mlx5_ib_dev *dev,
14968c2ecf20Sopenharmony_ci						 unsigned int current_access_flags,
14978c2ecf20Sopenharmony_ci						 unsigned int target_access_flags)
14988c2ecf20Sopenharmony_ci{
14998c2ecf20Sopenharmony_ci	unsigned int diffs = current_access_flags ^ target_access_flags;
15008c2ecf20Sopenharmony_ci
15018c2ecf20Sopenharmony_ci	if ((diffs & IB_ACCESS_REMOTE_ATOMIC) &&
15028c2ecf20Sopenharmony_ci	    MLX5_CAP_GEN(dev->mdev, atomic) &&
15038c2ecf20Sopenharmony_ci	    MLX5_CAP_GEN(dev->mdev, umr_modify_atomic_disabled))
15048c2ecf20Sopenharmony_ci		return false;
15058c2ecf20Sopenharmony_ci
15068c2ecf20Sopenharmony_ci	if ((diffs & IB_ACCESS_RELAXED_ORDERING) &&
15078c2ecf20Sopenharmony_ci	    MLX5_CAP_GEN(dev->mdev, relaxed_ordering_write) &&
15088c2ecf20Sopenharmony_ci	    !MLX5_CAP_GEN(dev->mdev, relaxed_ordering_write_umr))
15098c2ecf20Sopenharmony_ci		return false;
15108c2ecf20Sopenharmony_ci
15118c2ecf20Sopenharmony_ci	if ((diffs & IB_ACCESS_RELAXED_ORDERING) &&
15128c2ecf20Sopenharmony_ci	    MLX5_CAP_GEN(dev->mdev, relaxed_ordering_read) &&
15138c2ecf20Sopenharmony_ci	    !MLX5_CAP_GEN(dev->mdev, relaxed_ordering_read_umr))
15148c2ecf20Sopenharmony_ci		return false;
15158c2ecf20Sopenharmony_ci
15168c2ecf20Sopenharmony_ci	return true;
15178c2ecf20Sopenharmony_ci}
15188c2ecf20Sopenharmony_ci
15198c2ecf20Sopenharmony_ciint mlx5_ib_test_wc(struct mlx5_ib_dev *dev);
15208c2ecf20Sopenharmony_ci
15218c2ecf20Sopenharmony_cistatic inline bool mlx5_ib_lag_should_assign_affinity(struct mlx5_ib_dev *dev)
15228c2ecf20Sopenharmony_ci{
15238c2ecf20Sopenharmony_ci	return dev->lag_active ||
15248c2ecf20Sopenharmony_ci		(MLX5_CAP_GEN(dev->mdev, num_lag_ports) > 1 &&
15258c2ecf20Sopenharmony_ci		 MLX5_CAP_GEN(dev->mdev, lag_tx_port_affinity));
15268c2ecf20Sopenharmony_ci}
15278c2ecf20Sopenharmony_ci#endif /* MLX5_IB_H */
1528