xref: /freebsd/sys/dev/mlx5/mlx5_ib/mlx5_ib.h (revision e23731db48ef9c6568d4768b1f87d48514339faa)
112515907SHans Petter Selasky /*-
242f719d6SHans Petter Selasky  * Copyright (c) 2013-2020, Mellanox Technologies, Ltd.  All rights reserved.
312515907SHans Petter Selasky  *
412515907SHans Petter Selasky  * Redistribution and use in source and binary forms, with or without
512515907SHans Petter Selasky  * modification, are permitted provided that the following conditions
612515907SHans Petter Selasky  * are met:
712515907SHans Petter Selasky  * 1. Redistributions of source code must retain the above copyright
812515907SHans Petter Selasky  *    notice, this list of conditions and the following disclaimer.
912515907SHans Petter Selasky  * 2. Redistributions in binary form must reproduce the above copyright
1012515907SHans Petter Selasky  *    notice, this list of conditions and the following disclaimer in the
1112515907SHans Petter Selasky  *    documentation and/or other materials provided with the distribution.
1212515907SHans Petter Selasky  *
1312515907SHans Petter Selasky  * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS `AS IS' AND
1412515907SHans Petter Selasky  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1512515907SHans Petter Selasky  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1612515907SHans Petter Selasky  * ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
1712515907SHans Petter Selasky  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1812515907SHans Petter Selasky  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
1912515907SHans Petter Selasky  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2012515907SHans Petter Selasky  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2112515907SHans Petter Selasky  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2212515907SHans Petter Selasky  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2312515907SHans Petter Selasky  * SUCH DAMAGE.
2412515907SHans Petter Selasky  */
2512515907SHans Petter Selasky 
2612515907SHans Petter Selasky #ifndef MLX5_IB_H
2712515907SHans Petter Selasky #define MLX5_IB_H
2812515907SHans Petter Selasky 
2912515907SHans Petter Selasky #include <linux/kernel.h>
3012515907SHans Petter Selasky #include <linux/sched.h>
318e6e287fSHans Petter Selasky #include <linux/printk.h>
324ded022dSBjoern A. Zeeb #include <linux/netdevice.h>
3312515907SHans Petter Selasky #include <rdma/ib_verbs.h>
34b633e08cSHans Petter Selasky #include <rdma/ib_umem.h>
3512515907SHans Petter Selasky #include <rdma/ib_smi.h>
3612515907SHans Petter Selasky #include <dev/mlx5/cq.h>
3712515907SHans Petter Selasky #include <dev/mlx5/qp.h>
3812515907SHans Petter Selasky #include <dev/mlx5/srq.h>
3912515907SHans Petter Selasky #include <linux/types.h>
4012515907SHans Petter Selasky #include <dev/mlx5/mlx5_core/transobj.h>
418e6e287fSHans Petter Selasky #include <rdma/ib_user_verbs.h>
428e6e287fSHans Petter Selasky #include <rdma/mlx5-abi.h>
43b633e08cSHans Petter Selasky #include <rdma/uverbs_ioctl.h>
4412515907SHans Petter Selasky 
4512515907SHans Petter Selasky #define mlx5_ib_dbg(dev, format, arg...)				\
468e6e287fSHans Petter Selasky pr_debug("%s:%s:%d:(pid %d): " format, (dev)->ib_dev.name, __func__,	\
478e6e287fSHans Petter Selasky 	 __LINE__, current->pid, ##arg)
4812515907SHans Petter Selasky 
4912515907SHans Petter Selasky #define mlx5_ib_err(dev, format, arg...)				\
50b6324929SHans Petter Selasky pr_err("%s: ERR: %s:%d:(pid %d): " format, (dev)->ib_dev.name, __func__,	\
518e6e287fSHans Petter Selasky 	__LINE__, current->pid, ##arg)
5212515907SHans Petter Selasky 
5312515907SHans Petter Selasky #define mlx5_ib_warn(dev, format, arg...)				\
54b6324929SHans Petter Selasky pr_warn("%s: WARN: %s:%d:(pid %d): " format, (dev)->ib_dev.name, __func__,	\
558e6e287fSHans Petter Selasky 	__LINE__, current->pid, ##arg)
5612515907SHans Petter Selasky 
578e6e287fSHans Petter Selasky #define field_avail(type, fld, sz) (offsetof(type, fld) +		\
588e6e287fSHans Petter Selasky 				    sizeof(((type *)0)->fld) <= (sz))
598e6e287fSHans Petter Selasky #define MLX5_IB_DEFAULT_UIDX 0xffffff
608e6e287fSHans Petter Selasky #define MLX5_USER_ASSIGNED_UIDX_MASK __mlx5_mask(qpc, user_index)
6112515907SHans Petter Selasky 
62565cb4e8SHans Petter Selasky #define MLX5_MKEY_PAGE_SHIFT_MASK __mlx5_mask(mkc, log_page_size)
63565cb4e8SHans Petter Selasky 
6412515907SHans Petter Selasky enum {
6512515907SHans Petter Selasky 	MLX5_IB_MMAP_CMD_SHIFT	= 8,
6612515907SHans Petter Selasky 	MLX5_IB_MMAP_CMD_MASK	= 0xff,
6712515907SHans Petter Selasky };
6812515907SHans Petter Selasky 
6912515907SHans Petter Selasky enum {
7012515907SHans Petter Selasky 	MLX5_RES_SCAT_DATA32_CQE	= 0x1,
7112515907SHans Petter Selasky 	MLX5_RES_SCAT_DATA64_CQE	= 0x2,
7212515907SHans Petter Selasky 	MLX5_REQ_SCAT_DATA32_CQE	= 0x11,
7312515907SHans Petter Selasky 	MLX5_REQ_SCAT_DATA64_CQE	= 0x22,
7412515907SHans Petter Selasky };
7512515907SHans Petter Selasky 
7612515907SHans Petter Selasky enum mlx5_ib_latency_class {
7712515907SHans Petter Selasky 	MLX5_IB_LATENCY_CLASS_LOW,
7812515907SHans Petter Selasky 	MLX5_IB_LATENCY_CLASS_MEDIUM,
7912515907SHans Petter Selasky 	MLX5_IB_LATENCY_CLASS_HIGH,
8012515907SHans Petter Selasky 	MLX5_IB_LATENCY_CLASS_FAST_PATH
8112515907SHans Petter Selasky };
8212515907SHans Petter Selasky 
8312515907SHans Petter Selasky enum mlx5_ib_mad_ifc_flags {
8412515907SHans Petter Selasky 	MLX5_MAD_IFC_IGNORE_MKEY	= 1,
8512515907SHans Petter Selasky 	MLX5_MAD_IFC_IGNORE_BKEY	= 2,
8612515907SHans Petter Selasky 	MLX5_MAD_IFC_NET_VIEW		= 4,
8712515907SHans Petter Selasky };
8812515907SHans Petter Selasky 
8912515907SHans Petter Selasky enum {
90f8f5b459SHans Petter Selasky 	MLX5_CROSS_CHANNEL_BFREG         = 0,
9112515907SHans Petter Selasky };
9212515907SHans Petter Selasky 
9312515907SHans Petter Selasky enum {
948e6e287fSHans Petter Selasky 	MLX5_CQE_VERSION_V0,
958e6e287fSHans Petter Selasky 	MLX5_CQE_VERSION_V1,
9612515907SHans Petter Selasky };
9712515907SHans Petter Selasky 
98f8f5b459SHans Petter Selasky enum {
99f8f5b459SHans Petter Selasky 	MLX5_IB_INVALID_UAR_INDEX	= BIT(31),
100f8f5b459SHans Petter Selasky 	MLX5_IB_INVALID_BFREG		= BIT(31),
101f8f5b459SHans Petter Selasky };
102f8f5b459SHans Petter Selasky 
103b633e08cSHans Petter Selasky enum mlx5_ib_mmap_type {
104b633e08cSHans Petter Selasky 	MLX5_IB_MMAP_TYPE_MEMIC = 1,
105b633e08cSHans Petter Selasky 	MLX5_IB_MMAP_TYPE_VAR = 2,
106b633e08cSHans Petter Selasky 	MLX5_IB_MMAP_TYPE_UAR_WC = 3,
107b633e08cSHans Petter Selasky 	MLX5_IB_MMAP_TYPE_UAR_NC = 4,
10812515907SHans Petter Selasky };
10912515907SHans Petter Selasky 
110f8f5b459SHans Petter Selasky struct mlx5_bfreg_info {
111f8f5b459SHans Petter Selasky 	u32 *sys_pages;
112f8f5b459SHans Petter Selasky 	int num_low_latency_bfregs;
113f8f5b459SHans Petter Selasky 	unsigned int *count;
114f8f5b459SHans Petter Selasky 
115f8f5b459SHans Petter Selasky 	/*
116f8f5b459SHans Petter Selasky 	 * protect bfreg allocation data structs
117f8f5b459SHans Petter Selasky 	 */
118f8f5b459SHans Petter Selasky 	struct mutex lock;
119f8f5b459SHans Petter Selasky 	u32 ver;
120f8f5b459SHans Petter Selasky 	u8 lib_uar_4k : 1;
121f8f5b459SHans Petter Selasky 	u8 lib_uar_dyn : 1;
122f8f5b459SHans Petter Selasky 	u32 num_sys_pages;
123f8f5b459SHans Petter Selasky 	u32 num_static_sys_pages;
124f8f5b459SHans Petter Selasky 	u32 total_num_bfregs;
125f8f5b459SHans Petter Selasky 	u32 num_dyn_bfregs;
126f8f5b459SHans Petter Selasky };
127f8f5b459SHans Petter Selasky 
12812515907SHans Petter Selasky struct mlx5_ib_ucontext {
12912515907SHans Petter Selasky 	struct ib_ucontext	ibucontext;
13012515907SHans Petter Selasky 	struct list_head	db_page_list;
13112515907SHans Petter Selasky 
13212515907SHans Petter Selasky 	/* protect doorbell record alloc/free
13312515907SHans Petter Selasky 	 */
13412515907SHans Petter Selasky 	struct mutex		db_page_mutex;
135f8f5b459SHans Petter Selasky 	struct mlx5_bfreg_info	bfregi;
1368e6e287fSHans Petter Selasky 	u8			cqe_version;
13712515907SHans Petter Selasky 	/* Transport Domain number */
13812515907SHans Petter Selasky 	u32			tdn;
139b633e08cSHans Petter Selasky 
140b633e08cSHans Petter Selasky 	u64			lib_caps;
141b633e08cSHans Petter Selasky 	u16			devx_uid;
14212515907SHans Petter Selasky };
14312515907SHans Petter Selasky 
14412515907SHans Petter Selasky static inline struct mlx5_ib_ucontext *to_mucontext(struct ib_ucontext *ibucontext)
14512515907SHans Petter Selasky {
14612515907SHans Petter Selasky 	return container_of(ibucontext, struct mlx5_ib_ucontext, ibucontext);
14712515907SHans Petter Selasky }
14812515907SHans Petter Selasky 
14912515907SHans Petter Selasky struct mlx5_ib_pd {
15012515907SHans Petter Selasky 	struct ib_pd		ibpd;
15112515907SHans Petter Selasky 	u32			pdn;
152b633e08cSHans Petter Selasky 	u16			uid;
15312515907SHans Petter Selasky };
15412515907SHans Petter Selasky 
1558e6e287fSHans Petter Selasky #define MLX5_IB_FLOW_MCAST_PRIO		(MLX5_BY_PASS_NUM_PRIOS - 1)
1568e6e287fSHans Petter Selasky #define MLX5_IB_FLOW_LAST_PRIO		(MLX5_BY_PASS_NUM_REGULAR_PRIOS - 1)
1578e6e287fSHans Petter Selasky #if (MLX5_IB_FLOW_LAST_PRIO <= 0)
1588e6e287fSHans Petter Selasky #error "Invalid number of bypass priorities"
1598e6e287fSHans Petter Selasky #endif
1608e6e287fSHans Petter Selasky #define MLX5_IB_FLOW_LEFTOVERS_PRIO	(MLX5_IB_FLOW_MCAST_PRIO + 1)
1618e6e287fSHans Petter Selasky 
1628e6e287fSHans Petter Selasky #define MLX5_IB_NUM_FLOW_FT		(MLX5_IB_FLOW_LEFTOVERS_PRIO + 1)
1638e6e287fSHans Petter Selasky #define MLX5_IB_NUM_SNIFFER_FTS		2
1648e6e287fSHans Petter Selasky struct mlx5_ib_flow_prio {
1658e6e287fSHans Petter Selasky 	struct mlx5_flow_table		*flow_table;
1668e6e287fSHans Petter Selasky 	unsigned int			refcount;
1678e6e287fSHans Petter Selasky };
1688e6e287fSHans Petter Selasky 
1698e6e287fSHans Petter Selasky struct mlx5_ib_flow_handler {
1708e6e287fSHans Petter Selasky 	struct list_head		list;
1718e6e287fSHans Petter Selasky 	struct ib_flow			ibflow;
1728e6e287fSHans Petter Selasky 	struct mlx5_ib_flow_prio	*prio;
173*e23731dbSKonstantin Belousov 	struct mlx5_flow_handle	*rule;
1748e6e287fSHans Petter Selasky };
1758e6e287fSHans Petter Selasky 
1768e6e287fSHans Petter Selasky struct mlx5_ib_flow_db {
1778e6e287fSHans Petter Selasky 	struct mlx5_ib_flow_prio	prios[MLX5_IB_NUM_FLOW_FT];
1788e6e287fSHans Petter Selasky 	struct mlx5_ib_flow_prio	sniffer[MLX5_IB_NUM_SNIFFER_FTS];
1798e6e287fSHans Petter Selasky 	struct mlx5_flow_table		*lag_demux_ft;
1808e6e287fSHans Petter Selasky 	/* Protect flow steering bypass flow tables
1818e6e287fSHans Petter Selasky 	 * when add/del flow rules.
1828e6e287fSHans Petter Selasky 	 * only single add/removal of flow steering rule could be done
1838e6e287fSHans Petter Selasky 	 * simultaneously.
1848e6e287fSHans Petter Selasky 	 */
1858e6e287fSHans Petter Selasky 	struct mutex			lock;
1868e6e287fSHans Petter Selasky };
1878e6e287fSHans Petter Selasky 
1888e6e287fSHans Petter Selasky /* Use macros here so that don't have to duplicate
1898e6e287fSHans Petter Selasky  * enum ib_send_flags and enum ib_qp_type for low-level driver
1908e6e287fSHans Petter Selasky  */
1918e6e287fSHans Petter Selasky 
1928e6e287fSHans Petter Selasky #define MLX5_IB_SEND_UMR_UNREG	IB_SEND_RESERVED_START
1938e6e287fSHans Petter Selasky #define MLX5_IB_SEND_UMR_FAIL_IF_FREE (IB_SEND_RESERVED_START << 1)
1948e6e287fSHans Petter Selasky #define MLX5_IB_SEND_UMR_UPDATE_MTT (IB_SEND_RESERVED_START << 2)
1958e6e287fSHans Petter Selasky 
1968e6e287fSHans Petter Selasky #define MLX5_IB_SEND_UMR_UPDATE_TRANSLATION	(IB_SEND_RESERVED_START << 3)
1978e6e287fSHans Petter Selasky #define MLX5_IB_SEND_UMR_UPDATE_PD		(IB_SEND_RESERVED_START << 4)
1988e6e287fSHans Petter Selasky #define MLX5_IB_SEND_UMR_UPDATE_ACCESS		IB_SEND_RESERVED_END
1998e6e287fSHans Petter Selasky 
2008e6e287fSHans Petter Selasky #define MLX5_IB_QPT_REG_UMR	IB_QPT_RESERVED1
2018e6e287fSHans Petter Selasky /*
2028e6e287fSHans Petter Selasky  * IB_QPT_GSI creates the software wrapper around GSI, and MLX5_IB_QPT_HW_GSI
2038e6e287fSHans Petter Selasky  * creates the actual hardware QP.
2048e6e287fSHans Petter Selasky  */
2058e6e287fSHans Petter Selasky #define MLX5_IB_QPT_HW_GSI	IB_QPT_RESERVED2
206cf88b86eSHans Petter Selasky #define MLX5_IB_QPT_DCI		IB_QPT_RESERVED3
207cf88b86eSHans Petter Selasky #define MLX5_IB_QPT_DCT		IB_QPT_RESERVED4
2088e6e287fSHans Petter Selasky #define MLX5_IB_WR_UMR		IB_WR_RESERVED1
2098e6e287fSHans Petter Selasky 
2108e6e287fSHans Petter Selasky /* Private QP creation flags to be passed in ib_qp_init_attr.create_flags.
2118e6e287fSHans Petter Selasky  *
2128e6e287fSHans Petter Selasky  * These flags are intended for internal use by the mlx5_ib driver, and they
2138e6e287fSHans Petter Selasky  * rely on the range reserved for that use in the ib_qp_create_flags enum.
2148e6e287fSHans Petter Selasky  */
215f8f5b459SHans Petter Selasky #define MLX5_IB_QP_CREATE_SQPN_QP1	IB_QP_CREATE_RESERVED_START
216f8f5b459SHans Petter Selasky #define MLX5_IB_QP_CREATE_WC_TEST	(IB_QP_CREATE_RESERVED_START << 1)
2178e6e287fSHans Petter Selasky 
21812515907SHans Petter Selasky struct wr_list {
21912515907SHans Petter Selasky 	u16	opcode;
22012515907SHans Petter Selasky 	u16	next;
22112515907SHans Petter Selasky };
22212515907SHans Petter Selasky 
22312515907SHans Petter Selasky struct mlx5_ib_wq {
2248e6e287fSHans Petter Selasky 	u64		       *wrid;
2258e6e287fSHans Petter Selasky 	u32		       *wr_data;
2268e6e287fSHans Petter Selasky 	struct wr_list	       *w_list;
2278e6e287fSHans Petter Selasky 	unsigned	       *wqe_head;
22812515907SHans Petter Selasky 	u16		        unsig_count;
22912515907SHans Petter Selasky 
23012515907SHans Petter Selasky 	/* serialize post to the work queue
23112515907SHans Petter Selasky 	 */
23212515907SHans Petter Selasky 	spinlock_t		lock;
23312515907SHans Petter Selasky 	int			wqe_cnt;
23412515907SHans Petter Selasky 	int			max_post;
23512515907SHans Petter Selasky 	int			max_gs;
23612515907SHans Petter Selasky 	int			offset;
23712515907SHans Petter Selasky 	int			wqe_shift;
23812515907SHans Petter Selasky 	unsigned		head;
23912515907SHans Petter Selasky 	unsigned		tail;
24012515907SHans Petter Selasky 	u16			cur_post;
24112515907SHans Petter Selasky 	u16			last_poll;
24212515907SHans Petter Selasky 	void		       *qend;
24312515907SHans Petter Selasky };
24412515907SHans Petter Selasky 
2458e6e287fSHans Petter Selasky struct mlx5_ib_rwq {
2468e6e287fSHans Petter Selasky 	struct ib_wq		ibwq;
2478e6e287fSHans Petter Selasky 	struct mlx5_core_qp	core_qp;
2488e6e287fSHans Petter Selasky 	u32			rq_num_pas;
2498e6e287fSHans Petter Selasky 	u32			log_rq_stride;
2508e6e287fSHans Petter Selasky 	u32			log_rq_size;
2518e6e287fSHans Petter Selasky 	u32			rq_page_offset;
2528e6e287fSHans Petter Selasky 	u32			log_page_size;
2538e6e287fSHans Petter Selasky 	struct ib_umem		*umem;
2548e6e287fSHans Petter Selasky 	size_t			buf_size;
2558e6e287fSHans Petter Selasky 	unsigned int		page_shift;
2568e6e287fSHans Petter Selasky 	int			create_type;
2578e6e287fSHans Petter Selasky 	struct mlx5_db		db;
2588e6e287fSHans Petter Selasky 	u32			user_index;
2598e6e287fSHans Petter Selasky 	u32			wqe_count;
2608e6e287fSHans Petter Selasky 	u32			wqe_shift;
2618e6e287fSHans Petter Selasky 	int			wq_sig;
2628e6e287fSHans Petter Selasky };
2638e6e287fSHans Petter Selasky 
26412515907SHans Petter Selasky enum {
26512515907SHans Petter Selasky 	MLX5_QP_USER,
26612515907SHans Petter Selasky 	MLX5_QP_KERNEL,
26712515907SHans Petter Selasky 	MLX5_QP_EMPTY
26812515907SHans Petter Selasky };
26912515907SHans Petter Selasky 
27012515907SHans Petter Selasky enum {
27112515907SHans Petter Selasky 	MLX5_WQ_USER,
27212515907SHans Petter Selasky 	MLX5_WQ_KERNEL
27312515907SHans Petter Selasky };
27412515907SHans Petter Selasky 
2758e6e287fSHans Petter Selasky struct mlx5_ib_rwq_ind_table {
2768e6e287fSHans Petter Selasky 	struct ib_rwq_ind_table ib_rwq_ind_tbl;
2778e6e287fSHans Petter Selasky 	u32			rqtn;
278b633e08cSHans Petter Selasky 	u16			uid;
27912515907SHans Petter Selasky };
28012515907SHans Petter Selasky 
2818e6e287fSHans Petter Selasky /*
2828e6e287fSHans Petter Selasky  * Connect-IB can trigger up to four concurrent pagefaults
2838e6e287fSHans Petter Selasky  * per-QP.
2848e6e287fSHans Petter Selasky  */
2858e6e287fSHans Petter Selasky enum mlx5_ib_pagefault_context {
2868e6e287fSHans Petter Selasky 	MLX5_IB_PAGEFAULT_RESPONDER_READ,
2878e6e287fSHans Petter Selasky 	MLX5_IB_PAGEFAULT_REQUESTOR_READ,
2888e6e287fSHans Petter Selasky 	MLX5_IB_PAGEFAULT_RESPONDER_WRITE,
2898e6e287fSHans Petter Selasky 	MLX5_IB_PAGEFAULT_REQUESTOR_WRITE,
2908e6e287fSHans Petter Selasky 	MLX5_IB_PAGEFAULT_CONTEXTS
2918e6e287fSHans Petter Selasky };
2928e6e287fSHans Petter Selasky 
2938e6e287fSHans Petter Selasky static inline enum mlx5_ib_pagefault_context
2948e6e287fSHans Petter Selasky 	mlx5_ib_get_pagefault_context(struct mlx5_pagefault *pagefault)
2958e6e287fSHans Petter Selasky {
2968e6e287fSHans Petter Selasky 	return pagefault->flags & (MLX5_PFAULT_REQUESTOR | MLX5_PFAULT_WRITE);
2978e6e287fSHans Petter Selasky }
2988e6e287fSHans Petter Selasky 
2998e6e287fSHans Petter Selasky struct mlx5_ib_pfault {
3008e6e287fSHans Petter Selasky 	struct work_struct	work;
3018e6e287fSHans Petter Selasky 	struct mlx5_pagefault	mpfault;
3028e6e287fSHans Petter Selasky };
3038e6e287fSHans Petter Selasky 
3048e6e287fSHans Petter Selasky struct mlx5_ib_ubuffer {
3058e6e287fSHans Petter Selasky 	struct ib_umem	       *umem;
3068e6e287fSHans Petter Selasky 	int			buf_size;
3078e6e287fSHans Petter Selasky 	u64			buf_addr;
3088e6e287fSHans Petter Selasky };
3098e6e287fSHans Petter Selasky 
3108e6e287fSHans Petter Selasky struct mlx5_ib_qp_base {
3118e6e287fSHans Petter Selasky 	struct mlx5_ib_qp	*container_mibqp;
3128e6e287fSHans Petter Selasky 	struct mlx5_core_qp	mqp;
3138e6e287fSHans Petter Selasky 	struct mlx5_ib_ubuffer	ubuffer;
3148e6e287fSHans Petter Selasky };
3158e6e287fSHans Petter Selasky 
3168e6e287fSHans Petter Selasky struct mlx5_ib_qp_trans {
3178e6e287fSHans Petter Selasky 	struct mlx5_ib_qp_base	base;
3188e6e287fSHans Petter Selasky 	u16			xrcdn;
3198e6e287fSHans Petter Selasky 	u8			alt_port;
3208e6e287fSHans Petter Selasky 	u8			atomic_rd_en;
3218e6e287fSHans Petter Selasky 	u8			resp_depth;
3228e6e287fSHans Petter Selasky };
3238e6e287fSHans Petter Selasky 
3248e6e287fSHans Petter Selasky struct mlx5_ib_rss_qp {
3258e6e287fSHans Petter Selasky 	u32	tirn;
3268e6e287fSHans Petter Selasky };
3278e6e287fSHans Petter Selasky 
3288e6e287fSHans Petter Selasky struct mlx5_ib_rq {
3298e6e287fSHans Petter Selasky 	struct mlx5_ib_qp_base base;
3308e6e287fSHans Petter Selasky 	struct mlx5_ib_wq	*rq;
3318e6e287fSHans Petter Selasky 	struct mlx5_ib_ubuffer	ubuffer;
3328e6e287fSHans Petter Selasky 	struct mlx5_db		*doorbell;
3338e6e287fSHans Petter Selasky 	u32			tirn;
3348e6e287fSHans Petter Selasky 	u8			state;
3358e6e287fSHans Petter Selasky };
3368e6e287fSHans Petter Selasky 
3378e6e287fSHans Petter Selasky struct mlx5_ib_sq {
3388e6e287fSHans Petter Selasky 	struct mlx5_ib_qp_base base;
3398e6e287fSHans Petter Selasky 	struct mlx5_ib_wq	*sq;
3408e6e287fSHans Petter Selasky 	struct mlx5_ib_ubuffer  ubuffer;
3418e6e287fSHans Petter Selasky 	struct mlx5_db		*doorbell;
3428e6e287fSHans Petter Selasky 	u32			tisn;
3438e6e287fSHans Petter Selasky 	u8			state;
3448e6e287fSHans Petter Selasky };
3458e6e287fSHans Petter Selasky 
3468e6e287fSHans Petter Selasky struct mlx5_ib_raw_packet_qp {
3478e6e287fSHans Petter Selasky 	struct mlx5_ib_sq sq;
3488e6e287fSHans Petter Selasky 	struct mlx5_ib_rq rq;
34912515907SHans Petter Selasky };
35012515907SHans Petter Selasky 
351f8f5b459SHans Petter Selasky struct mlx5_bf {
352f8f5b459SHans Petter Selasky 	int			buf_size;
353f8f5b459SHans Petter Selasky 	unsigned long		offset;
354f8f5b459SHans Petter Selasky 	struct mlx5_sq_bfreg   *bfreg;
355f8f5b459SHans Petter Selasky 	spinlock_t		lock32;
356f8f5b459SHans Petter Selasky };
357f8f5b459SHans Petter Selasky 
358b633e08cSHans Petter Selasky struct mlx5_ib_dct {
359b633e08cSHans Petter Selasky 	struct mlx5_core_dct    mdct;
360b633e08cSHans Petter Selasky 	u32                     *in;
361b633e08cSHans Petter Selasky };
362b633e08cSHans Petter Selasky 
36312515907SHans Petter Selasky struct mlx5_ib_qp {
36412515907SHans Petter Selasky 	struct ib_qp		ibqp;
3658e6e287fSHans Petter Selasky 	union {
3668e6e287fSHans Petter Selasky 		struct mlx5_ib_qp_trans trans_qp;
3678e6e287fSHans Petter Selasky 		struct mlx5_ib_raw_packet_qp raw_packet_qp;
3688e6e287fSHans Petter Selasky 		struct mlx5_ib_rss_qp rss_qp;
369b633e08cSHans Petter Selasky 		struct mlx5_ib_dct dct;
3708e6e287fSHans Petter Selasky 	};
37112515907SHans Petter Selasky 	struct mlx5_buf		buf;
37212515907SHans Petter Selasky 
37312515907SHans Petter Selasky 	struct mlx5_db		db;
37412515907SHans Petter Selasky 	struct mlx5_ib_wq	rq;
37512515907SHans Petter Selasky 
37612515907SHans Petter Selasky 	u8			sq_signal_bits;
37712515907SHans Petter Selasky 	u8			fm_cache;
37812515907SHans Petter Selasky 	struct mlx5_ib_wq	sq;
37912515907SHans Petter Selasky 
38012515907SHans Petter Selasky 	/* serialize qp state modifications
38112515907SHans Petter Selasky 	 */
38212515907SHans Petter Selasky 	struct mutex		mutex;
38312515907SHans Petter Selasky 	u32			flags;
38412515907SHans Petter Selasky 	u8			port;
38512515907SHans Petter Selasky 	u8			state;
38612515907SHans Petter Selasky 	int			wq_sig;
38712515907SHans Petter Selasky 	int			scat_cqe;
38812515907SHans Petter Selasky 	int			max_inline_data;
389f8f5b459SHans Petter Selasky 	struct mlx5_bf	        bf;
39012515907SHans Petter Selasky 	int			has_rq;
39112515907SHans Petter Selasky 
39212515907SHans Petter Selasky 	/* only for user space QPs. For kernel
39312515907SHans Petter Selasky 	 * we have it from the bf object
39412515907SHans Petter Selasky 	 */
395f8f5b459SHans Petter Selasky 	int			bfregn;
39612515907SHans Petter Selasky 
39712515907SHans Petter Selasky 	int			create_type;
39812515907SHans Petter Selasky 
39912515907SHans Petter Selasky 	/* Store signature errors */
40012515907SHans Petter Selasky 	bool			signature_en;
40112515907SHans Petter Selasky 
4028e6e287fSHans Petter Selasky #ifdef CONFIG_INFINIBAND_ON_DEMAND_PAGING
4038e6e287fSHans Petter Selasky 	/*
4048e6e287fSHans Petter Selasky 	 * A flag that is true for QP's that are in a state that doesn't
4058e6e287fSHans Petter Selasky 	 * allow page faults, and shouldn't schedule any more faults.
4068e6e287fSHans Petter Selasky 	 */
4078e6e287fSHans Petter Selasky 	int                     disable_page_faults;
4088e6e287fSHans Petter Selasky 	/*
4098e6e287fSHans Petter Selasky 	 * The disable_page_faults_lock protects a QP's disable_page_faults
4108e6e287fSHans Petter Selasky 	 * field, allowing for a thread to atomically check whether the QP
4118e6e287fSHans Petter Selasky 	 * allows page faults, and if so schedule a page fault.
4128e6e287fSHans Petter Selasky 	 */
4138e6e287fSHans Petter Selasky 	spinlock_t              disable_page_faults_lock;
4148e6e287fSHans Petter Selasky 	struct mlx5_ib_pfault	pagefaults[MLX5_IB_PAGEFAULT_CONTEXTS];
4158e6e287fSHans Petter Selasky #endif
41612515907SHans Petter Selasky 	struct list_head	qps_list;
41712515907SHans Petter Selasky 	struct list_head	cq_recv_list;
41812515907SHans Petter Selasky 	struct list_head	cq_send_list;
41912515907SHans Petter Selasky };
42012515907SHans Petter Selasky 
42112515907SHans Petter Selasky struct mlx5_ib_cq_buf {
42212515907SHans Petter Selasky 	struct mlx5_buf		buf;
42312515907SHans Petter Selasky 	struct ib_umem		*umem;
42412515907SHans Petter Selasky 	int			cqe_size;
42512515907SHans Petter Selasky 	int			nent;
42612515907SHans Petter Selasky };
42712515907SHans Petter Selasky 
42812515907SHans Petter Selasky enum mlx5_ib_qp_flags {
4298e6e287fSHans Petter Selasky 	MLX5_IB_QP_LSO                          = IB_QP_CREATE_IPOIB_UD_LSO,
4308e6e287fSHans Petter Selasky 	MLX5_IB_QP_BLOCK_MULTICAST_LOOPBACK     = IB_QP_CREATE_BLOCK_MULTICAST_LOOPBACK,
4318e6e287fSHans Petter Selasky 	MLX5_IB_QP_CROSS_CHANNEL            = IB_QP_CREATE_CROSS_CHANNEL,
4328e6e287fSHans Petter Selasky 	MLX5_IB_QP_MANAGED_SEND             = IB_QP_CREATE_MANAGED_SEND,
4338e6e287fSHans Petter Selasky 	MLX5_IB_QP_MANAGED_RECV             = IB_QP_CREATE_MANAGED_RECV,
4348e6e287fSHans Petter Selasky 	MLX5_IB_QP_SIGNATURE_HANDLING           = 1 << 5,
4358e6e287fSHans Petter Selasky 	/* QP uses 1 as its source QP number */
4368e6e287fSHans Petter Selasky 	MLX5_IB_QP_SQPN_QP1			= 1 << 6,
4378e6e287fSHans Petter Selasky 	MLX5_IB_QP_CAP_SCATTER_FCS		= 1 << 7,
4388e6e287fSHans Petter Selasky 	MLX5_IB_QP_RSS				= 1 << 8,
439b633e08cSHans Petter Selasky 	MLX5_IB_QP_UNDERLAY			= 1 << 10,
44012515907SHans Petter Selasky };
44112515907SHans Petter Selasky 
44212515907SHans Petter Selasky struct mlx5_umr_wr {
4438e6e287fSHans Petter Selasky 	struct ib_send_wr		wr;
44412515907SHans Petter Selasky 	union {
44512515907SHans Petter Selasky 		u64			virt_addr;
44612515907SHans Petter Selasky 		u64			offset;
44712515907SHans Petter Selasky 	} target;
44812515907SHans Petter Selasky 	struct ib_pd		       *pd;
44912515907SHans Petter Selasky 	unsigned int			page_shift;
45012515907SHans Petter Selasky 	unsigned int			npages;
4518e6e287fSHans Petter Selasky 	u32				length;
45212515907SHans Petter Selasky 	int				access_flags;
45312515907SHans Petter Selasky 	u32				mkey;
45412515907SHans Petter Selasky };
45512515907SHans Petter Selasky 
456c3987b8eSHans Petter Selasky static inline const struct mlx5_umr_wr *umr_wr(const struct ib_send_wr *wr)
4578e6e287fSHans Petter Selasky {
4588e6e287fSHans Petter Selasky 	return container_of(wr, struct mlx5_umr_wr, wr);
4598e6e287fSHans Petter Selasky }
4608e6e287fSHans Petter Selasky 
46112515907SHans Petter Selasky struct mlx5_shared_mr_info {
46212515907SHans Petter Selasky 	int mr_id;
46312515907SHans Petter Selasky 	struct ib_umem		*umem;
46412515907SHans Petter Selasky };
46512515907SHans Petter Selasky 
46612515907SHans Petter Selasky struct mlx5_ib_cq {
46712515907SHans Petter Selasky 	struct ib_cq		ibcq;
46812515907SHans Petter Selasky 	struct mlx5_core_cq	mcq;
46912515907SHans Petter Selasky 	struct mlx5_ib_cq_buf	buf;
47012515907SHans Petter Selasky 	struct mlx5_db		db;
47112515907SHans Petter Selasky 
47212515907SHans Petter Selasky 	/* serialize access to the CQ
47312515907SHans Petter Selasky 	 */
47412515907SHans Petter Selasky 	spinlock_t		lock;
47512515907SHans Petter Selasky 
47612515907SHans Petter Selasky 	/* protect resize cq
47712515907SHans Petter Selasky 	 */
47812515907SHans Petter Selasky 	struct mutex		resize_mutex;
47912515907SHans Petter Selasky 	struct mlx5_ib_cq_buf  *resize_buf;
48012515907SHans Petter Selasky 	struct ib_umem	       *resize_umem;
48112515907SHans Petter Selasky 	int			cqe_size;
48212515907SHans Petter Selasky 	struct list_head	list_send_qp;
48312515907SHans Petter Selasky 	struct list_head	list_recv_qp;
4848e6e287fSHans Petter Selasky 	u32			create_flags;
4858e6e287fSHans Petter Selasky 	struct list_head	wc_list;
4868e6e287fSHans Petter Selasky 	enum ib_cq_notify_flags notify_flags;
4878e6e287fSHans Petter Selasky 	struct work_struct	notify_work;
4888e6e287fSHans Petter Selasky };
4898e6e287fSHans Petter Selasky 
4908e6e287fSHans Petter Selasky struct mlx5_ib_wc {
4918e6e287fSHans Petter Selasky 	struct ib_wc wc;
4928e6e287fSHans Petter Selasky 	struct list_head list;
49312515907SHans Petter Selasky };
49412515907SHans Petter Selasky 
49512515907SHans Petter Selasky struct mlx5_ib_srq {
49612515907SHans Petter Selasky 	struct ib_srq		ibsrq;
49712515907SHans Petter Selasky 	struct mlx5_core_srq	msrq;
49812515907SHans Petter Selasky 	struct mlx5_buf		buf;
49912515907SHans Petter Selasky 	struct mlx5_db		db;
50012515907SHans Petter Selasky 	u64		       *wrid;
50112515907SHans Petter Selasky 	/* protect SRQ hanlding
50212515907SHans Petter Selasky 	 */
50312515907SHans Petter Selasky 	spinlock_t		lock;
50412515907SHans Petter Selasky 	int			head;
50512515907SHans Petter Selasky 	int			tail;
50612515907SHans Petter Selasky 	u16			wqe_ctr;
50712515907SHans Petter Selasky 	struct ib_umem	       *umem;
50812515907SHans Petter Selasky 	/* serialize arming a SRQ
50912515907SHans Petter Selasky 	 */
51012515907SHans Petter Selasky 	struct mutex		mutex;
51112515907SHans Petter Selasky 	int			wq_sig;
51212515907SHans Petter Selasky };
51312515907SHans Petter Selasky 
51412515907SHans Petter Selasky struct mlx5_ib_xrcd {
51512515907SHans Petter Selasky 	struct ib_xrcd		ibxrcd;
51612515907SHans Petter Selasky 	u32			xrcdn;
51712515907SHans Petter Selasky };
51812515907SHans Petter Selasky 
51912515907SHans Petter Selasky enum mlx5_ib_mtt_access_flags {
52012515907SHans Petter Selasky 	MLX5_IB_MTT_READ  = (1 << 0),
52112515907SHans Petter Selasky 	MLX5_IB_MTT_WRITE = (1 << 1),
52212515907SHans Petter Selasky };
52312515907SHans Petter Selasky 
524b633e08cSHans Petter Selasky struct mlx5_user_mmap_entry {
525b633e08cSHans Petter Selasky 	struct rdma_user_mmap_entry rdma_entry;
526b633e08cSHans Petter Selasky 	u8 mmap_flag;
527b633e08cSHans Petter Selasky 	u64 address;
528b633e08cSHans Petter Selasky 	u32 page_idx;
529b633e08cSHans Petter Selasky };
530b633e08cSHans Petter Selasky 
53112515907SHans Petter Selasky #define MLX5_IB_MTT_PRESENT (MLX5_IB_MTT_READ | MLX5_IB_MTT_WRITE)
53212515907SHans Petter Selasky 
53312515907SHans Petter Selasky struct mlx5_ib_mr {
53412515907SHans Petter Selasky 	struct ib_mr		ibmr;
5358e6e287fSHans Petter Selasky 	void			*descs;
5368e6e287fSHans Petter Selasky 	dma_addr_t		desc_map;
5378e6e287fSHans Petter Selasky 	int			ndescs;
5388e6e287fSHans Petter Selasky 	int			max_descs;
5398e6e287fSHans Petter Selasky 	int			desc_size;
5408e6e287fSHans Petter Selasky 	int			access_mode;
541b633e08cSHans Petter Selasky 	struct mlx5_core_mkey	mmkey;
54212515907SHans Petter Selasky 	struct ib_umem	       *umem;
54312515907SHans Petter Selasky 	struct mlx5_shared_mr_info	*smr_info;
54412515907SHans Petter Selasky 	struct list_head	list;
54512515907SHans Petter Selasky 	int			order;
54612515907SHans Petter Selasky 	int			umred;
54712515907SHans Petter Selasky 	int			npages;
54812515907SHans Petter Selasky 	struct mlx5_ib_dev     *dev;
5498e6e287fSHans Petter Selasky 	u32 out[MLX5_ST_SZ_DW(create_mkey_out)];
55012515907SHans Petter Selasky 	struct mlx5_core_sig_ctx    *sig;
5518e6e287fSHans Petter Selasky 	int			live;
5528e6e287fSHans Petter Selasky 	void			*descs_alloc;
5538e6e287fSHans Petter Selasky 	int			access_flags; /* Needed for rereg MR */
5547eefcb5eSHans Petter Selasky 	struct mlx5_async_work	cb_work;
55512515907SHans Petter Selasky };
55612515907SHans Petter Selasky 
5578e6e287fSHans Petter Selasky struct mlx5_ib_mw {
5588e6e287fSHans Petter Selasky 	struct ib_mw		ibmw;
559b633e08cSHans Petter Selasky 	struct mlx5_core_mkey	mmkey;
560b633e08cSHans Petter Selasky };
561b633e08cSHans Petter Selasky 
562b633e08cSHans Petter Selasky struct mlx5_ib_devx_mr {
563b633e08cSHans Petter Selasky 	struct mlx5_core_mkey	mmkey;
564b633e08cSHans Petter Selasky 	int			ndescs;
56512515907SHans Petter Selasky };
56612515907SHans Petter Selasky 
56712515907SHans Petter Selasky struct mlx5_ib_umr_context {
5688e6e287fSHans Petter Selasky 	struct ib_cqe		cqe;
56912515907SHans Petter Selasky 	enum ib_wc_status	status;
57012515907SHans Petter Selasky 	struct completion	done;
57112515907SHans Petter Selasky };
57212515907SHans Petter Selasky 
57312515907SHans Petter Selasky struct umr_common {
57412515907SHans Petter Selasky 	struct ib_pd	*pd;
5758e6e287fSHans Petter Selasky 	struct ib_cq	*cq;
5768e6e287fSHans Petter Selasky 	struct ib_qp	*qp;
5778e6e287fSHans Petter Selasky 	/* control access to UMR QP
5788e6e287fSHans Petter Selasky 	 */
5798e6e287fSHans Petter Selasky 	struct semaphore	sem;
58012515907SHans Petter Selasky };
58112515907SHans Petter Selasky 
58212515907SHans Petter Selasky enum {
58312515907SHans Petter Selasky 	MLX5_FMR_INVALID,
58412515907SHans Petter Selasky 	MLX5_FMR_VALID,
58512515907SHans Petter Selasky 	MLX5_FMR_BUSY,
58612515907SHans Petter Selasky };
58712515907SHans Petter Selasky 
58812515907SHans Petter Selasky struct mlx5_cache_ent {
58912515907SHans Petter Selasky 	struct list_head	head;
59012515907SHans Petter Selasky 	/* sync access to the cahce entry
59112515907SHans Petter Selasky 	 */
59212515907SHans Petter Selasky 	spinlock_t		lock;
59312515907SHans Petter Selasky 
59412515907SHans Petter Selasky 
5958e6e287fSHans Petter Selasky 	char                    name[4];
59612515907SHans Petter Selasky 	u32                     order;
59712515907SHans Petter Selasky 	u32			size;
59812515907SHans Petter Selasky 	u32                     cur;
59912515907SHans Petter Selasky 	u32                     miss;
60012515907SHans Petter Selasky 	u32			limit;
60112515907SHans Petter Selasky 
60212515907SHans Petter Selasky 	struct mlx5_ib_dev     *dev;
60312515907SHans Petter Selasky 	struct work_struct	work;
60412515907SHans Petter Selasky 	struct delayed_work	dwork;
60512515907SHans Petter Selasky 	int			pending;
60612515907SHans Petter Selasky };
60712515907SHans Petter Selasky 
60812515907SHans Petter Selasky struct mlx5_mr_cache {
60912515907SHans Petter Selasky 	struct workqueue_struct *wq;
61012515907SHans Petter Selasky 	struct mlx5_cache_ent	ent[MAX_MR_CACHE_ENTRIES];
61112515907SHans Petter Selasky 	int			stopped;
6128e6e287fSHans Petter Selasky 	unsigned long		last_add;
6138e6e287fSHans Petter Selasky };
6148e6e287fSHans Petter Selasky 
6158e6e287fSHans Petter Selasky struct mlx5_ib_gsi_qp;
6168e6e287fSHans Petter Selasky 
6178e6e287fSHans Petter Selasky struct mlx5_ib_port_resources {
6188e6e287fSHans Petter Selasky 	struct mlx5_ib_resources *devr;
6198e6e287fSHans Petter Selasky 	struct mlx5_ib_gsi_qp *gsi;
6208e6e287fSHans Petter Selasky 	struct work_struct pkey_change_work;
62112515907SHans Petter Selasky };
62212515907SHans Petter Selasky 
62312515907SHans Petter Selasky struct mlx5_ib_resources {
62412515907SHans Petter Selasky 	struct ib_cq	*c0;
62512515907SHans Petter Selasky 	struct ib_xrcd	*x0;
62612515907SHans Petter Selasky 	struct ib_xrcd	*x1;
62712515907SHans Petter Selasky 	struct ib_pd	*p0;
62812515907SHans Petter Selasky 	struct ib_srq	*s0;
62912515907SHans Petter Selasky 	struct ib_srq	*s1;
6308e6e287fSHans Petter Selasky 	struct mlx5_ib_port_resources ports[2];
6318e6e287fSHans Petter Selasky 	/* Protects changes to the port resources */
6328e6e287fSHans Petter Selasky 	struct mutex	mutex;
63312515907SHans Petter Selasky };
63412515907SHans Petter Selasky 
63512515907SHans Petter Selasky struct mlx5_ib_port {
63612515907SHans Petter Selasky 	u16 q_cnt_id;
6378e6e287fSHans Petter Selasky };
6388e6e287fSHans Petter Selasky 
6398e6e287fSHans Petter Selasky struct mlx5_roce {
6408e6e287fSHans Petter Selasky 	/* Protect mlx5_ib_get_netdev from invoking dev_hold() with a NULL
6418e6e287fSHans Petter Selasky 	 * netdev pointer
6428e6e287fSHans Petter Selasky 	 */
6438e6e287fSHans Petter Selasky 	rwlock_t		netdev_lock;
6445dc00f00SJustin Hibbits 	if_t netdev;
6458e6e287fSHans Petter Selasky 	struct notifier_block	nb;
6468e6e287fSHans Petter Selasky 	atomic_t		next_port;
64712515907SHans Petter Selasky };
64812515907SHans Petter Selasky 
64942f719d6SHans Petter Selasky #define	MLX5_IB_STATS_COUNT(a,...) a
65042f719d6SHans Petter Selasky #define	MLX5_IB_STATS_VAR(a,b,c,...) b c;
65142f719d6SHans Petter Selasky #define	MLX5_IB_STATS_DESC(a,b,c,d,e,...) d, e,
652118063fbSHans Petter Selasky 
653118063fbSHans Petter Selasky #define	MLX5_IB_CONG_PARAMS(m) \
654118063fbSHans Petter Selasky   /* ECN RP */ \
65542f719d6SHans Petter Selasky   m(+1, u64, rp_clamp_tgt_rate, "rp_clamp_tgt_rate", "If set, whenever a CNP is processed, the target rate is updated to be the current rate") \
65642f719d6SHans Petter Selasky   m(+1, u64, rp_clamp_tgt_rate_ati, "rp_clamp_tgt_rate_ati", "If set, when receiving a CNP, the target rate should be updated if the transission rate was increased due to the timer, and not only due to the byte counter") \
65742f719d6SHans Petter Selasky   m(+1, u64, rp_time_reset, "rp_time_reset", "Time in microseconds between rate increases if no CNPs are received") \
65842f719d6SHans Petter Selasky   m(+1, u64, rp_byte_reset, "rp_byte_reset", "Transmitted data in bytes between rate increases if no CNP's are received. A value of zero means disabled.") \
65942f719d6SHans Petter Selasky   m(+1, u64, rp_threshold, "rp_threshold", "The number of times rpByteStage or rpTimeStage can count before the RP rate control state machine advances states") \
66042f719d6SHans Petter Selasky   m(+1, u64, rp_ai_rate, "rp_ai_rate", "The rate, in Mbits per second, used to increase rpTargetRate in the active increase state") \
66142f719d6SHans Petter Selasky   m(+1, u64, rp_hai_rate, "rp_hai_rate", "The rate, in Mbits per second, used to increase rpTargetRate in the hyper increase state") \
66242f719d6SHans Petter Selasky   m(+1, u64, rp_min_dec_fac, "rp_min_dec_fac", "The minimum factor by which the current transmit rate can be changed when processing a CNP. Value is given as a percentage, [1 .. 100]") \
66342f719d6SHans Petter Selasky   m(+1, u64, rp_min_rate, "rp_min_rate", "The minimum value, in Mbps per second, for rate to limit") \
66442f719d6SHans Petter Selasky   m(+1, u64, rp_rate_to_set_on_first_cnp, "rp_rate_to_set_on_first_cnp", "The rate that is set for the flow when a rate limiter is allocated to it upon first CNP received, in Mbps. A value of zero means use full port speed") \
66542f719d6SHans Petter Selasky   m(+1, u64, rp_dce_tcp_g, "rp_dce_tcp_g", "Used to update the congestion estimator, alpha, once every dce_tcp_rtt once every dce_tcp_rtt microseconds") \
66642f719d6SHans Petter Selasky   m(+1, u64, rp_dce_tcp_rtt, "rp_dce_tcp_rtt", "The time between updates of the aolpha value, in microseconds") \
66742f719d6SHans Petter Selasky   m(+1, u64, rp_rate_reduce_monitor_period, "rp_rate_reduce_monitor_period", "The minimum time between two consecutive rate reductions for a single flow") \
66842f719d6SHans Petter Selasky   m(+1, u64, rp_initial_alpha_value, "rp_initial_alpha_value", "The initial value of alpha to use when receiving the first CNP for a flow") \
66942f719d6SHans Petter Selasky   m(+1, u64, rp_gd, "rp_gd", "If a CNP is received, the flow rate is reduced at the beginning of the next rate_reduce_monitor_period interval") \
670118063fbSHans Petter Selasky   /* ECN NP */ \
67142f719d6SHans Petter Selasky   m(+1, u64, np_cnp_dscp, "np_cnp_dscp", "The DiffServ Code Point of the generated CNP for this port") \
67242f719d6SHans Petter Selasky   m(+1, u64, np_cnp_prio_mode, "np_cnp_prio_mode", "The 802.1p priority value of the generated CNP for this port") \
67342f719d6SHans Petter Selasky   m(+1, u64, np_cnp_prio, "np_cnp_prio", "The 802.1p priority value of the generated CNP for this port")
674118063fbSHans Petter Selasky 
675118063fbSHans Petter Selasky #define	MLX5_IB_CONG_PARAMS_NUM (0 MLX5_IB_CONG_PARAMS(MLX5_IB_STATS_COUNT))
676118063fbSHans Petter Selasky 
677118063fbSHans Petter Selasky #define	MLX5_IB_CONG_STATS(m) \
67842f719d6SHans Petter Selasky   m(+1, u64, syndrome, "syndrome", "Syndrome number") \
67942f719d6SHans Petter Selasky   m(+1, u64, rp_cur_flows, "rp_cur_flows", "Number of flows limited") \
68042f719d6SHans Petter Selasky   m(+1, u64, sum_flows, "sum_flows", "Sum of the number of flows limited over time") \
68142f719d6SHans Petter Selasky   m(+1, u64, rp_cnp_ignored, "rp_cnp_ignored", "Number of CNPs and CNMs ignored") \
68242f719d6SHans Petter Selasky   m(+1, u64, rp_cnp_handled, "rp_cnp_handled", "Number of CNPs and CNMs successfully handled") \
68342f719d6SHans Petter Selasky   m(+1, u64, time_stamp, "time_stamp", "Time stamp in microseconds") \
68442f719d6SHans Petter Selasky   m(+1, u64, accumulators_period, "accumulators_period", "The value of X variable for accumulating counters") \
68542f719d6SHans Petter Selasky   m(+1, u64, np_ecn_marked_roce_packets, "np_ecn_marked_roce_packets", "Number of ECN marked packets seen") \
68642f719d6SHans Petter Selasky   m(+1, u64, np_cnp_sent, "np_cnp_sent", "Number of CNPs sent")
687118063fbSHans Petter Selasky 
688118063fbSHans Petter Selasky #define	MLX5_IB_CONG_STATS_NUM (0 MLX5_IB_CONG_STATS(MLX5_IB_STATS_COUNT))
689118063fbSHans Petter Selasky 
6908abf5ac0SHans Petter Selasky #define	MLX5_IB_CONG_STATUS(m) \
6918abf5ac0SHans Petter Selasky   /* ECN RP */ \
6928abf5ac0SHans Petter Selasky   m(+1, u64, rp_0_enable, "rp_0_enable", "Enable reaction point, priority 0", MLX5_IB_RROCE_ECN_RP, 0, enable) \
6938abf5ac0SHans Petter Selasky   m(+1, u64, rp_1_enable, "rp_1_enable", "Enable reaction point, priority 1", MLX5_IB_RROCE_ECN_RP, 1, enable) \
6948abf5ac0SHans Petter Selasky   m(+1, u64, rp_2_enable, "rp_2_enable", "Enable reaction point, priority 2", MLX5_IB_RROCE_ECN_RP, 2, enable) \
6958abf5ac0SHans Petter Selasky   m(+1, u64, rp_3_enable, "rp_3_enable", "Enable reaction point, priority 3", MLX5_IB_RROCE_ECN_RP, 3, enable) \
6968abf5ac0SHans Petter Selasky   m(+1, u64, rp_4_enable, "rp_4_enable", "Enable reaction point, priority 4", MLX5_IB_RROCE_ECN_RP, 4, enable) \
6978abf5ac0SHans Petter Selasky   m(+1, u64, rp_5_enable, "rp_5_enable", "Enable reaction point, priority 5", MLX5_IB_RROCE_ECN_RP, 5, enable) \
6988abf5ac0SHans Petter Selasky   m(+1, u64, rp_6_enable, "rp_6_enable", "Enable reaction point, priority 6", MLX5_IB_RROCE_ECN_RP, 6, enable) \
6998abf5ac0SHans Petter Selasky   m(+1, u64, rp_7_enable, "rp_7_enable", "Enable reaction point, priority 7", MLX5_IB_RROCE_ECN_RP, 7, enable) \
7008abf5ac0SHans Petter Selasky   m(+1, u64, rp_8_enable, "rp_8_enable", "Enable reaction point, priority 8", MLX5_IB_RROCE_ECN_RP, 8, enable) \
7018abf5ac0SHans Petter Selasky   m(+1, u64, rp_9_enable, "rp_9_enable", "Enable reaction point, priority 9", MLX5_IB_RROCE_ECN_RP, 9, enable) \
7028abf5ac0SHans Petter Selasky   m(+1, u64, rp_10_enable, "rp_10_enable", "Enable reaction point, priority 10", MLX5_IB_RROCE_ECN_RP, 10, enable) \
7038abf5ac0SHans Petter Selasky   m(+1, u64, rp_11_enable, "rp_11_enable", "Enable reaction point, priority 11", MLX5_IB_RROCE_ECN_RP, 11, enable) \
7048abf5ac0SHans Petter Selasky   m(+1, u64, rp_12_enable, "rp_12_enable", "Enable reaction point, priority 12", MLX5_IB_RROCE_ECN_RP, 12, enable) \
7058abf5ac0SHans Petter Selasky   m(+1, u64, rp_13_enable, "rp_13_enable", "Enable reaction point, priority 13", MLX5_IB_RROCE_ECN_RP, 13, enable) \
7068abf5ac0SHans Petter Selasky   m(+1, u64, rp_14_enable, "rp_14_enable", "Enable reaction point, priority 14", MLX5_IB_RROCE_ECN_RP, 14, enable) \
7078abf5ac0SHans Petter Selasky   m(+1, u64, rp_15_enable, "rp_15_enable", "Enable reaction point, priority 15", MLX5_IB_RROCE_ECN_RP, 15, enable) \
7088abf5ac0SHans Petter Selasky   /* ECN NP */ \
7098abf5ac0SHans Petter Selasky   m(+1, u64, np_0_enable, "np_0_enable", "Enable notification point, priority 0", MLX5_IB_RROCE_ECN_NP, 0, enable) \
7108abf5ac0SHans Petter Selasky   m(+1, u64, np_1_enable, "np_1_enable", "Enable notification point, priority 1", MLX5_IB_RROCE_ECN_NP, 1, enable) \
7118abf5ac0SHans Petter Selasky   m(+1, u64, np_2_enable, "np_2_enable", "Enable notification point, priority 2", MLX5_IB_RROCE_ECN_NP, 2, enable) \
7128abf5ac0SHans Petter Selasky   m(+1, u64, np_3_enable, "np_3_enable", "Enable notification point, priority 3", MLX5_IB_RROCE_ECN_NP, 3, enable) \
7138abf5ac0SHans Petter Selasky   m(+1, u64, np_4_enable, "np_4_enable", "Enable notification point, priority 4", MLX5_IB_RROCE_ECN_NP, 4, enable) \
7148abf5ac0SHans Petter Selasky   m(+1, u64, np_5_enable, "np_5_enable", "Enable notification point, priority 5", MLX5_IB_RROCE_ECN_NP, 5, enable) \
7158abf5ac0SHans Petter Selasky   m(+1, u64, np_6_enable, "np_6_enable", "Enable notification point, priority 6", MLX5_IB_RROCE_ECN_NP, 6, enable) \
7168abf5ac0SHans Petter Selasky   m(+1, u64, np_7_enable, "np_7_enable", "Enable notification point, priority 7", MLX5_IB_RROCE_ECN_NP, 7, enable) \
7178abf5ac0SHans Petter Selasky   m(+1, u64, np_8_enable, "np_8_enable", "Enable notification point, priority 8", MLX5_IB_RROCE_ECN_NP, 8, enable) \
7188abf5ac0SHans Petter Selasky   m(+1, u64, np_9_enable, "np_9_enable", "Enable notification point, priority 9", MLX5_IB_RROCE_ECN_NP, 9, enable) \
7198abf5ac0SHans Petter Selasky   m(+1, u64, np_10_enable, "np_10_enable", "Enable notification point, priority 10", MLX5_IB_RROCE_ECN_NP, 10, enable) \
7208abf5ac0SHans Petter Selasky   m(+1, u64, np_11_enable, "np_11_enable", "Enable notification point, priority 11", MLX5_IB_RROCE_ECN_NP, 11, enable) \
7218abf5ac0SHans Petter Selasky   m(+1, u64, np_12_enable, "np_12_enable", "Enable notification point, priority 12", MLX5_IB_RROCE_ECN_NP, 12, enable) \
7228abf5ac0SHans Petter Selasky   m(+1, u64, np_13_enable, "np_13_enable", "Enable notification point, priority 13", MLX5_IB_RROCE_ECN_NP, 13, enable) \
7238abf5ac0SHans Petter Selasky   m(+1, u64, np_14_enable, "np_14_enable", "Enable notification point, priority 14", MLX5_IB_RROCE_ECN_NP, 14, enable) \
7248abf5ac0SHans Petter Selasky   m(+1, u64, np_15_enable, "np_15_enable", "Enable notification point, priority 15", MLX5_IB_RROCE_ECN_NP, 15, enable) \
7258abf5ac0SHans Petter Selasky 
7268abf5ac0SHans Petter Selasky #define	MLX5_IB_CONG_STATUS_NUM (0 MLX5_IB_CONG_STATUS(MLX5_IB_STATS_COUNT))
7278abf5ac0SHans Petter Selasky 
728118063fbSHans Petter Selasky struct mlx5_ib_congestion {
729118063fbSHans Petter Selasky 	struct sysctl_ctx_list ctx;
730118063fbSHans Petter Selasky 	struct sx lock;
731118063fbSHans Petter Selasky 	struct delayed_work dwork;
7329b6e45d4SHans Petter Selasky 	union {
7339b6e45d4SHans Petter Selasky 		u64	arg[1];
7349b6e45d4SHans Petter Selasky 		struct {
735118063fbSHans Petter Selasky 			MLX5_IB_CONG_PARAMS(MLX5_IB_STATS_VAR)
736118063fbSHans Petter Selasky 			MLX5_IB_CONG_STATS(MLX5_IB_STATS_VAR)
7378abf5ac0SHans Petter Selasky 			MLX5_IB_CONG_STATUS(MLX5_IB_STATS_VAR)
738118063fbSHans Petter Selasky 		};
7399b6e45d4SHans Petter Selasky 	};
7409b6e45d4SHans Petter Selasky };
741118063fbSHans Petter Selasky 
742b633e08cSHans Petter Selasky struct mlx5_devx_event_table {
743b633e08cSHans Petter Selasky 	/* serialize updating the event_xa */
744b633e08cSHans Petter Selasky 	struct mutex event_xa_lock;
745b633e08cSHans Petter Selasky 	struct xarray event_xa;
746b633e08cSHans Petter Selasky };
747b633e08cSHans Petter Selasky 
74812515907SHans Petter Selasky struct mlx5_ib_dev {
74912515907SHans Petter Selasky 	struct ib_device		ib_dev;
75012515907SHans Petter Selasky 	struct mlx5_core_dev		*mdev;
7518e6e287fSHans Petter Selasky 	struct mlx5_roce		roce;
75212515907SHans Petter Selasky 	MLX5_DECLARE_DOORBELL_LOCK(uar_lock);
75312515907SHans Petter Selasky 	int				num_ports;
75412515907SHans Petter Selasky 	/* serialize update of capability mask
75512515907SHans Petter Selasky 	 */
75612515907SHans Petter Selasky 	struct mutex			cap_mask_mutex;
757b633e08cSHans Petter Selasky 	u8				ib_active:1;
758b633e08cSHans Petter Selasky 	u8				wc_support:1;
75912515907SHans Petter Selasky 	struct umr_common		umrc;
76012515907SHans Petter Selasky 	/* sync used page count stats
76112515907SHans Petter Selasky 	 */
76212515907SHans Petter Selasky 	struct mlx5_ib_resources	devr;
76312515907SHans Petter Selasky 	struct mlx5_mr_cache		cache;
7648e6e287fSHans Petter Selasky 	struct timer_list		delay_timer;
7658e6e287fSHans Petter Selasky 	/* Prevents soft lock on massive reg MRs */
7668e6e287fSHans Petter Selasky 	struct mutex			slow_path_mutex;
7678e6e287fSHans Petter Selasky 	int				fill_delay;
7688e6e287fSHans Petter Selasky #ifdef CONFIG_INFINIBAND_ON_DEMAND_PAGING
7698e6e287fSHans Petter Selasky 	struct ib_odp_caps	odp_caps;
7708e6e287fSHans Petter Selasky 	/*
7718e6e287fSHans Petter Selasky 	 * Sleepable RCU that prevents destruction of MRs while they are still
7728e6e287fSHans Petter Selasky 	 * being used by a page fault handler.
7738e6e287fSHans Petter Selasky 	 */
7748e6e287fSHans Petter Selasky 	struct srcu_struct      mr_srcu;
7758e6e287fSHans Petter Selasky #endif
7768e6e287fSHans Petter Selasky 	struct mlx5_ib_flow_db	flow_db;
77712515907SHans Petter Selasky 	/* protect resources needed as part of reset flow */
77812515907SHans Petter Selasky 	spinlock_t		reset_flow_resource_lock;
77912515907SHans Petter Selasky 	struct list_head	qp_list;
78012515907SHans Petter Selasky 	/* Array with num_ports elements */
78112515907SHans Petter Selasky 	struct mlx5_ib_port	*port;
782f8f5b459SHans Petter Selasky 	struct mlx5_sq_bfreg	bfreg;
783f8f5b459SHans Petter Selasky 	struct mlx5_sq_bfreg	wc_bfreg;
784f8f5b459SHans Petter Selasky 	struct mlx5_sq_bfreg	fp_bfreg;
785b633e08cSHans Petter Selasky 	struct mlx5_devx_event_table devx_event_table;
786118063fbSHans Petter Selasky 	struct mlx5_ib_congestion congestion;
7877eefcb5eSHans Petter Selasky 
7887eefcb5eSHans Petter Selasky 	struct mlx5_async_ctx	async_ctx;
789ea00d7e8SHans Petter Selasky 
790ea00d7e8SHans Petter Selasky 	/* protect the user_td */
791ea00d7e8SHans Petter Selasky 	struct mutex		lb_mutex;
792ea00d7e8SHans Petter Selasky 	u32			user_td;
79312515907SHans Petter Selasky };
79412515907SHans Petter Selasky 
79512515907SHans Petter Selasky static inline struct mlx5_ib_cq *to_mibcq(struct mlx5_core_cq *mcq)
79612515907SHans Petter Selasky {
79712515907SHans Petter Selasky 	return container_of(mcq, struct mlx5_ib_cq, mcq);
79812515907SHans Petter Selasky }
79912515907SHans Petter Selasky 
80012515907SHans Petter Selasky static inline struct mlx5_ib_xrcd *to_mxrcd(struct ib_xrcd *ibxrcd)
80112515907SHans Petter Selasky {
80212515907SHans Petter Selasky 	return container_of(ibxrcd, struct mlx5_ib_xrcd, ibxrcd);
80312515907SHans Petter Selasky }
80412515907SHans Petter Selasky 
80512515907SHans Petter Selasky static inline struct mlx5_ib_dev *to_mdev(struct ib_device *ibdev)
80612515907SHans Petter Selasky {
80712515907SHans Petter Selasky 	return container_of(ibdev, struct mlx5_ib_dev, ib_dev);
80812515907SHans Petter Selasky }
80912515907SHans Petter Selasky 
810b633e08cSHans Petter Selasky static inline struct mlx5_ib_dev *mlx5_udata_to_mdev(struct ib_udata *udata)
811b633e08cSHans Petter Selasky {
812b633e08cSHans Petter Selasky 	struct mlx5_ib_ucontext *context = rdma_udata_to_drv_context(
813b633e08cSHans Petter Selasky 		udata, struct mlx5_ib_ucontext, ibucontext);
814b633e08cSHans Petter Selasky 
815b633e08cSHans Petter Selasky 	return to_mdev(context->ibucontext.device);
816b633e08cSHans Petter Selasky }
817b633e08cSHans Petter Selasky 
81812515907SHans Petter Selasky static inline struct mlx5_ib_cq *to_mcq(struct ib_cq *ibcq)
81912515907SHans Petter Selasky {
82012515907SHans Petter Selasky 	return container_of(ibcq, struct mlx5_ib_cq, ibcq);
82112515907SHans Petter Selasky }
82212515907SHans Petter Selasky 
82312515907SHans Petter Selasky static inline struct mlx5_ib_qp *to_mibqp(struct mlx5_core_qp *mqp)
82412515907SHans Petter Selasky {
8258e6e287fSHans Petter Selasky 	return container_of(mqp, struct mlx5_ib_qp_base, mqp)->container_mibqp;
82612515907SHans Petter Selasky }
82712515907SHans Petter Selasky 
8288e6e287fSHans Petter Selasky static inline struct mlx5_ib_rwq *to_mibrwq(struct mlx5_core_qp *core_qp)
82912515907SHans Petter Selasky {
8308e6e287fSHans Petter Selasky 	return container_of(core_qp, struct mlx5_ib_rwq, core_qp);
83112515907SHans Petter Selasky }
83212515907SHans Petter Selasky 
833b633e08cSHans Petter Selasky static inline struct mlx5_ib_mr *to_mibmr(struct mlx5_core_mkey *mmkey)
83412515907SHans Petter Selasky {
8358e6e287fSHans Petter Selasky 	return container_of(mmkey, struct mlx5_ib_mr, mmkey);
83612515907SHans Petter Selasky }
83712515907SHans Petter Selasky 
83812515907SHans Petter Selasky static inline struct mlx5_ib_pd *to_mpd(struct ib_pd *ibpd)
83912515907SHans Petter Selasky {
84012515907SHans Petter Selasky 	return container_of(ibpd, struct mlx5_ib_pd, ibpd);
84112515907SHans Petter Selasky }
84212515907SHans Petter Selasky 
84312515907SHans Petter Selasky static inline struct mlx5_ib_srq *to_msrq(struct ib_srq *ibsrq)
84412515907SHans Petter Selasky {
84512515907SHans Petter Selasky 	return container_of(ibsrq, struct mlx5_ib_srq, ibsrq);
84612515907SHans Petter Selasky }
84712515907SHans Petter Selasky 
84812515907SHans Petter Selasky static inline struct mlx5_ib_qp *to_mqp(struct ib_qp *ibqp)
84912515907SHans Petter Selasky {
85012515907SHans Petter Selasky 	return container_of(ibqp, struct mlx5_ib_qp, ibqp);
85112515907SHans Petter Selasky }
85212515907SHans Petter Selasky 
8538e6e287fSHans Petter Selasky static inline struct mlx5_ib_rwq *to_mrwq(struct ib_wq *ibwq)
8548e6e287fSHans Petter Selasky {
8558e6e287fSHans Petter Selasky 	return container_of(ibwq, struct mlx5_ib_rwq, ibwq);
8568e6e287fSHans Petter Selasky }
8578e6e287fSHans Petter Selasky 
8588e6e287fSHans Petter Selasky static inline struct mlx5_ib_rwq_ind_table *to_mrwq_ind_table(struct ib_rwq_ind_table *ib_rwq_ind_tbl)
8598e6e287fSHans Petter Selasky {
8608e6e287fSHans Petter Selasky 	return container_of(ib_rwq_ind_tbl, struct mlx5_ib_rwq_ind_table, ib_rwq_ind_tbl);
8618e6e287fSHans Petter Selasky }
8628e6e287fSHans Petter Selasky 
86312515907SHans Petter Selasky static inline struct mlx5_ib_srq *to_mibsrq(struct mlx5_core_srq *msrq)
86412515907SHans Petter Selasky {
86512515907SHans Petter Selasky 	return container_of(msrq, struct mlx5_ib_srq, msrq);
86612515907SHans Petter Selasky }
86712515907SHans Petter Selasky 
86812515907SHans Petter Selasky static inline struct mlx5_ib_mr *to_mmr(struct ib_mr *ibmr)
86912515907SHans Petter Selasky {
87012515907SHans Petter Selasky 	return container_of(ibmr, struct mlx5_ib_mr, ibmr);
87112515907SHans Petter Selasky }
87212515907SHans Petter Selasky 
8738e6e287fSHans Petter Selasky static inline struct mlx5_ib_mw *to_mmw(struct ib_mw *ibmw)
87412515907SHans Petter Selasky {
8758e6e287fSHans Petter Selasky 	return container_of(ibmw, struct mlx5_ib_mw, ibmw);
87612515907SHans Petter Selasky }
87712515907SHans Petter Selasky 
87812515907SHans Petter Selasky struct mlx5_ib_ah {
87912515907SHans Petter Selasky 	struct ib_ah		ibah;
88012515907SHans Petter Selasky 	struct mlx5_av		av;
88112515907SHans Petter Selasky };
88212515907SHans Petter Selasky 
88312515907SHans Petter Selasky static inline struct mlx5_ib_ah *to_mah(struct ib_ah *ibah)
88412515907SHans Petter Selasky {
88512515907SHans Petter Selasky 	return container_of(ibah, struct mlx5_ib_ah, ibah);
88612515907SHans Petter Selasky }
88712515907SHans Petter Selasky 
888b633e08cSHans Petter Selasky static inline struct mlx5_user_mmap_entry *
889b633e08cSHans Petter Selasky to_mmmap(struct rdma_user_mmap_entry *rdma_entry)
890b633e08cSHans Petter Selasky {
891b633e08cSHans Petter Selasky 	return container_of(rdma_entry,
892b633e08cSHans Petter Selasky 		struct mlx5_user_mmap_entry, rdma_entry);
893b633e08cSHans Petter Selasky }
894b633e08cSHans Petter Selasky 
8958e6e287fSHans Petter Selasky int mlx5_ib_db_map_user(struct mlx5_ib_ucontext *context, unsigned long virt,
89612515907SHans Petter Selasky 			struct mlx5_db *db);
89712515907SHans Petter Selasky void mlx5_ib_db_unmap_user(struct mlx5_ib_ucontext *context, struct mlx5_db *db);
89812515907SHans Petter Selasky void __mlx5_ib_cq_clean(struct mlx5_ib_cq *cq, u32 qpn, struct mlx5_ib_srq *srq);
89912515907SHans Petter Selasky void mlx5_ib_cq_clean(struct mlx5_ib_cq *cq, u32 qpn, struct mlx5_ib_srq *srq);
90012515907SHans Petter Selasky void mlx5_ib_free_srq_wqe(struct mlx5_ib_srq *srq, int wqe_index);
90112515907SHans Petter Selasky int mlx5_MAD_IFC(struct mlx5_ib_dev *dev, int ignore_mkey, int ignore_bkey,
9028e6e287fSHans Petter Selasky 		 u8 port, const struct ib_wc *in_wc, const struct ib_grh *in_grh,
9038e6e287fSHans Petter Selasky 		 const void *in_mad, void *response_mad);
904b633e08cSHans Petter Selasky int mlx5_ib_create_ah(struct ib_ah *ah, struct ib_ah_attr *ah_attr, u32 flags,
9051456d97cSHans Petter Selasky 				struct ib_udata *udata);
90612515907SHans Petter Selasky int mlx5_ib_query_ah(struct ib_ah *ibah, struct ib_ah_attr *ah_attr);
907b633e08cSHans Petter Selasky void mlx5_ib_destroy_ah(struct ib_ah *ah, u32 flags);
908b633e08cSHans Petter Selasky int mlx5_ib_create_srq(struct ib_srq *srq, struct ib_srq_init_attr *init_attr,
90912515907SHans Petter Selasky 		       struct ib_udata *udata);
91012515907SHans Petter Selasky int mlx5_ib_modify_srq(struct ib_srq *ibsrq, struct ib_srq_attr *attr,
91112515907SHans Petter Selasky 		       enum ib_srq_attr_mask attr_mask, struct ib_udata *udata);
91212515907SHans Petter Selasky int mlx5_ib_query_srq(struct ib_srq *ibsrq, struct ib_srq_attr *srq_attr);
913b633e08cSHans Petter Selasky void mlx5_ib_destroy_srq(struct ib_srq *srq, struct ib_udata *udata);
914c3987b8eSHans Petter Selasky int mlx5_ib_post_srq_recv(struct ib_srq *ibsrq, const struct ib_recv_wr *wr,
915c3987b8eSHans Petter Selasky 			  const struct ib_recv_wr **bad_wr);
91612515907SHans Petter Selasky struct ib_qp *mlx5_ib_create_qp(struct ib_pd *pd,
91712515907SHans Petter Selasky 				struct ib_qp_init_attr *init_attr,
91812515907SHans Petter Selasky 				struct ib_udata *udata);
91912515907SHans Petter Selasky int mlx5_ib_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr,
92012515907SHans Petter Selasky 		      int attr_mask, struct ib_udata *udata);
92112515907SHans Petter Selasky int mlx5_ib_query_qp(struct ib_qp *ibqp, struct ib_qp_attr *qp_attr, int qp_attr_mask,
92212515907SHans Petter Selasky 		     struct ib_qp_init_attr *qp_init_attr);
923b633e08cSHans Petter Selasky int mlx5_ib_destroy_qp(struct ib_qp *qp, struct ib_udata *udata);
924c3987b8eSHans Petter Selasky int mlx5_ib_post_send(struct ib_qp *ibqp, const struct ib_send_wr *wr,
925c3987b8eSHans Petter Selasky 		      const struct ib_send_wr **bad_wr);
926c3987b8eSHans Petter Selasky int mlx5_ib_post_recv(struct ib_qp *ibqp, const struct ib_recv_wr *wr,
927c3987b8eSHans Petter Selasky 		      const struct ib_recv_wr **bad_wr);
92812515907SHans Petter Selasky void *mlx5_get_send_wqe(struct mlx5_ib_qp *qp, int n);
9298e6e287fSHans Petter Selasky int mlx5_ib_read_user_wqe(struct mlx5_ib_qp *qp, int send, int wqe_index,
9308e6e287fSHans Petter Selasky 			  void *buffer, u32 length,
9318e6e287fSHans Petter Selasky 			  struct mlx5_ib_qp_base *base);
932b633e08cSHans Petter Selasky int mlx5_ib_create_cq(struct ib_cq *ibcq, const struct ib_cq_init_attr *attr,
93312515907SHans Petter Selasky 		      struct ib_udata *udata);
934b633e08cSHans Petter Selasky void mlx5_ib_destroy_cq(struct ib_cq *cq, struct ib_udata *udata);
93512515907SHans Petter Selasky int mlx5_ib_poll_cq(struct ib_cq *ibcq, int num_entries, struct ib_wc *wc);
93612515907SHans Petter Selasky int mlx5_ib_arm_cq(struct ib_cq *ibcq, enum ib_cq_notify_flags flags);
9378e6e287fSHans Petter Selasky int mlx5_ib_modify_cq(struct ib_cq *cq, u16 cq_count, u16 cq_period);
93812515907SHans Petter Selasky int mlx5_ib_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata);
93912515907SHans Petter Selasky struct ib_mr *mlx5_ib_get_dma_mr(struct ib_pd *pd, int acc);
94012515907SHans Petter Selasky struct ib_mr *mlx5_ib_reg_user_mr(struct ib_pd *pd, u64 start, u64 length,
94112515907SHans Petter Selasky 				  u64 virt_addr, int access_flags,
9428e6e287fSHans Petter Selasky 				  struct ib_udata *udata);
9438e6e287fSHans Petter Selasky struct ib_mw *mlx5_ib_alloc_mw(struct ib_pd *pd, enum ib_mw_type type,
9448e6e287fSHans Petter Selasky 			       struct ib_udata *udata);
9458e6e287fSHans Petter Selasky int mlx5_ib_dealloc_mw(struct ib_mw *mw);
9468e6e287fSHans Petter Selasky int mlx5_ib_update_mtt(struct mlx5_ib_mr *mr, u64 start_page_index,
9478e6e287fSHans Petter Selasky 		       int npages, int zap);
9488e6e287fSHans Petter Selasky int mlx5_ib_rereg_user_mr(struct ib_mr *ib_mr, int flags, u64 start,
9498e6e287fSHans Petter Selasky 			  u64 length, u64 virt_addr, int access_flags,
9508e6e287fSHans Petter Selasky 			  struct ib_pd *pd, struct ib_udata *udata);
951b633e08cSHans Petter Selasky int mlx5_ib_dereg_mr(struct ib_mr *ibmr, struct ib_udata *udata);
952b633e08cSHans Petter Selasky struct ib_mr *mlx5_ib_alloc_mr(struct ib_pd *pd, enum ib_mr_type mr_type,
953b633e08cSHans Petter Selasky 			       u32 max_num_sg, struct ib_udata *udata);
9548e6e287fSHans Petter Selasky int mlx5_ib_map_mr_sg(struct ib_mr *ibmr, struct scatterlist *sg, int sg_nents,
9558e6e287fSHans Petter Selasky 		      unsigned int *sg_offset);
95612515907SHans Petter Selasky int mlx5_ib_process_mad(struct ib_device *ibdev, int mad_flags, u8 port_num,
9578e6e287fSHans Petter Selasky 			const struct ib_wc *in_wc, const struct ib_grh *in_grh,
9588e6e287fSHans Petter Selasky 			const struct ib_mad_hdr *in, size_t in_mad_size,
9598e6e287fSHans Petter Selasky 			struct ib_mad_hdr *out, size_t *out_mad_size,
9608e6e287fSHans Petter Selasky 			u16 *out_mad_pkey_index);
96112515907SHans Petter Selasky struct ib_xrcd *mlx5_ib_alloc_xrcd(struct ib_device *ibdev,
96212515907SHans Petter Selasky 				   struct ib_udata *udata);
963b633e08cSHans Petter Selasky int mlx5_ib_dealloc_xrcd(struct ib_xrcd *xrcd, struct ib_udata *udata);
96412515907SHans Petter Selasky int mlx5_ib_get_buf_offset(u64 addr, int page_shift, u32 *offset);
96512515907SHans Petter Selasky int mlx5_query_ext_port_caps(struct mlx5_ib_dev *dev, u8 port);
9668e6e287fSHans Petter Selasky int mlx5_query_mad_ifc_smp_attr_node_info(struct ib_device *ibdev,
96712515907SHans Petter Selasky 					  struct ib_smp *out_mad);
9688e6e287fSHans Petter Selasky int mlx5_query_mad_ifc_system_image_guid(struct ib_device *ibdev,
96912515907SHans Petter Selasky 					 __be64 *sys_image_guid);
9708e6e287fSHans Petter Selasky int mlx5_query_mad_ifc_max_pkeys(struct ib_device *ibdev,
97112515907SHans Petter Selasky 				 u16 *max_pkeys);
9728e6e287fSHans Petter Selasky int mlx5_query_mad_ifc_vendor_id(struct ib_device *ibdev,
97312515907SHans Petter Selasky 				 u32 *vendor_id);
9748e6e287fSHans Petter Selasky int mlx5_query_mad_ifc_node_desc(struct mlx5_ib_dev *dev, char *node_desc);
9758e6e287fSHans Petter Selasky int mlx5_query_mad_ifc_node_guid(struct mlx5_ib_dev *dev, __be64 *node_guid);
9768e6e287fSHans Petter Selasky int mlx5_query_mad_ifc_pkey(struct ib_device *ibdev, u8 port, u16 index,
97712515907SHans Petter Selasky 			    u16 *pkey);
9788e6e287fSHans Petter Selasky int mlx5_query_mad_ifc_gids(struct ib_device *ibdev, u8 port, int index,
97912515907SHans Petter Selasky 			    union ib_gid *gid);
9808e6e287fSHans Petter Selasky int mlx5_query_mad_ifc_port(struct ib_device *ibdev, u8 port,
98112515907SHans Petter Selasky 			    struct ib_port_attr *props);
98212515907SHans Petter Selasky int mlx5_ib_query_port(struct ib_device *ibdev, u8 port,
98312515907SHans Petter Selasky 		       struct ib_port_attr *props);
98412515907SHans Petter Selasky int mlx5_ib_init_fmr(struct mlx5_ib_dev *dev);
98512515907SHans Petter Selasky void mlx5_ib_cleanup_fmr(struct mlx5_ib_dev *dev);
986565cb4e8SHans Petter Selasky void mlx5_ib_cont_pages(struct ib_umem *umem, u64 addr,
987565cb4e8SHans Petter Selasky 			unsigned long max_page_shift,
988565cb4e8SHans Petter Selasky 			int *count, int *shift,
98912515907SHans Petter Selasky 			int *ncont, int *order);
9908e6e287fSHans Petter Selasky void __mlx5_ib_populate_pas(struct mlx5_ib_dev *dev, struct ib_umem *umem,
9918e6e287fSHans Petter Selasky 			    int page_shift, size_t offset, size_t num_pages,
9928e6e287fSHans Petter Selasky 			    __be64 *pas, int access_flags);
99312515907SHans Petter Selasky void mlx5_ib_populate_pas(struct mlx5_ib_dev *dev, struct ib_umem *umem,
9948e6e287fSHans Petter Selasky 			  int page_shift, __be64 *pas, int access_flags);
99512515907SHans Petter Selasky void mlx5_ib_copy_pas(u64 *old, u64 *new, int step, int num);
99612515907SHans Petter Selasky int mlx5_ib_get_cqe_size(struct mlx5_ib_dev *dev, struct ib_cq *ibcq);
99712515907SHans Petter Selasky int mlx5_mr_cache_init(struct mlx5_ib_dev *dev);
99812515907SHans Petter Selasky int mlx5_mr_cache_cleanup(struct mlx5_ib_dev *dev);
99912515907SHans Petter Selasky int mlx5_mr_ib_cont_pages(struct ib_umem *umem, u64 addr, int *count, int *shift);
10008e6e287fSHans Petter Selasky int mlx5_ib_check_mr_status(struct ib_mr *ibmr, u32 check_mask,
10018e6e287fSHans Petter Selasky 			    struct ib_mr_status *mr_status);
10028e6e287fSHans Petter Selasky struct ib_wq *mlx5_ib_create_wq(struct ib_pd *pd,
10038e6e287fSHans Petter Selasky 				struct ib_wq_init_attr *init_attr,
10048e6e287fSHans Petter Selasky 				struct ib_udata *udata);
1005b633e08cSHans Petter Selasky void mlx5_ib_destroy_wq(struct ib_wq *wq, struct ib_udata *udata);
10068e6e287fSHans Petter Selasky int mlx5_ib_modify_wq(struct ib_wq *wq, struct ib_wq_attr *wq_attr,
10078e6e287fSHans Petter Selasky 		      u32 wq_attr_mask, struct ib_udata *udata);
10088e6e287fSHans Petter Selasky struct ib_rwq_ind_table *mlx5_ib_create_rwq_ind_table(struct ib_device *device,
10098e6e287fSHans Petter Selasky 						      struct ib_rwq_ind_table_init_attr *init_attr,
10108e6e287fSHans Petter Selasky 						      struct ib_udata *udata);
10118e6e287fSHans Petter Selasky int mlx5_ib_destroy_rwq_ind_table(struct ib_rwq_ind_table *wq_ind_table);
10128e6e287fSHans Petter Selasky 
10138e6e287fSHans Petter Selasky #ifdef CONFIG_INFINIBAND_ON_DEMAND_PAGING
10148e6e287fSHans Petter Selasky extern struct workqueue_struct *mlx5_ib_page_fault_wq;
10158e6e287fSHans Petter Selasky 
10168e6e287fSHans Petter Selasky void mlx5_ib_internal_fill_odp_caps(struct mlx5_ib_dev *dev);
10178e6e287fSHans Petter Selasky void mlx5_ib_mr_pfault_handler(struct mlx5_ib_qp *qp,
10188e6e287fSHans Petter Selasky 			       struct mlx5_ib_pfault *pfault);
10198e6e287fSHans Petter Selasky void mlx5_ib_odp_create_qp(struct mlx5_ib_qp *qp);
10208e6e287fSHans Petter Selasky int mlx5_ib_odp_init_one(struct mlx5_ib_dev *ibdev);
10218e6e287fSHans Petter Selasky void mlx5_ib_odp_remove_one(struct mlx5_ib_dev *ibdev);
10228e6e287fSHans Petter Selasky int __init mlx5_ib_odp_init(void);
10238e6e287fSHans Petter Selasky void mlx5_ib_odp_cleanup(void);
10248e6e287fSHans Petter Selasky void mlx5_ib_qp_disable_pagefaults(struct mlx5_ib_qp *qp);
10258e6e287fSHans Petter Selasky void mlx5_ib_qp_enable_pagefaults(struct mlx5_ib_qp *qp);
10268e6e287fSHans Petter Selasky void mlx5_ib_invalidate_range(struct ib_umem *umem, unsigned long start,
10278e6e287fSHans Petter Selasky 			      unsigned long end);
10288e6e287fSHans Petter Selasky #else /* CONFIG_INFINIBAND_ON_DEMAND_PAGING */
10298e6e287fSHans Petter Selasky static inline void mlx5_ib_internal_fill_odp_caps(struct mlx5_ib_dev *dev)
10308e6e287fSHans Petter Selasky {
10318e6e287fSHans Petter Selasky 	return;
10328e6e287fSHans Petter Selasky }
10338e6e287fSHans Petter Selasky 
10348e6e287fSHans Petter Selasky static inline void mlx5_ib_odp_create_qp(struct mlx5_ib_qp *qp)		{}
10358e6e287fSHans Petter Selasky static inline int mlx5_ib_odp_init_one(struct mlx5_ib_dev *ibdev) { return 0; }
10368e6e287fSHans Petter Selasky static inline void mlx5_ib_odp_remove_one(struct mlx5_ib_dev *ibdev)	{}
10378e6e287fSHans Petter Selasky static inline int mlx5_ib_odp_init(void) { return 0; }
10388e6e287fSHans Petter Selasky static inline void mlx5_ib_odp_cleanup(void)				{}
10398e6e287fSHans Petter Selasky static inline void mlx5_ib_qp_disable_pagefaults(struct mlx5_ib_qp *qp) {}
10408e6e287fSHans Petter Selasky static inline void mlx5_ib_qp_enable_pagefaults(struct mlx5_ib_qp *qp)  {}
10418e6e287fSHans Petter Selasky 
10428e6e287fSHans Petter Selasky #endif /* CONFIG_INFINIBAND_ON_DEMAND_PAGING */
10438e6e287fSHans Petter Selasky 
10448e6e287fSHans Petter Selasky int mlx5_ib_get_vf_config(struct ib_device *device, int vf,
10458e6e287fSHans Petter Selasky 			  u8 port, struct ifla_vf_info *info);
10468e6e287fSHans Petter Selasky int mlx5_ib_set_vf_link_state(struct ib_device *device, int vf,
10478e6e287fSHans Petter Selasky 			      u8 port, int state);
10488e6e287fSHans Petter Selasky int mlx5_ib_get_vf_stats(struct ib_device *device, int vf,
10498e6e287fSHans Petter Selasky 			 u8 port, struct ifla_vf_stats *stats);
10508e6e287fSHans Petter Selasky int mlx5_ib_set_vf_guid(struct ib_device *device, int vf, u8 port,
10518e6e287fSHans Petter Selasky 			u64 guid, int type);
10528e6e287fSHans Petter Selasky 
10538e6e287fSHans Petter Selasky __be16 mlx5_get_roce_udp_sport(struct mlx5_ib_dev *dev, u8 port_num,
10548e6e287fSHans Petter Selasky 			       int index);
1055ed0cee0bSHans Petter Selasky int mlx5_get_roce_gid_type(struct mlx5_ib_dev *dev, u8 port_num,
1056ed0cee0bSHans Petter Selasky 			   int index, enum ib_gid_type *gid_type);
10578e6e287fSHans Petter Selasky 
10588e6e287fSHans Petter Selasky /* GSI QP helper functions */
10598e6e287fSHans Petter Selasky struct ib_qp *mlx5_ib_gsi_create_qp(struct ib_pd *pd,
10608e6e287fSHans Petter Selasky 				    struct ib_qp_init_attr *init_attr);
10618e6e287fSHans Petter Selasky int mlx5_ib_gsi_destroy_qp(struct ib_qp *qp);
10628e6e287fSHans Petter Selasky int mlx5_ib_gsi_modify_qp(struct ib_qp *qp, struct ib_qp_attr *attr,
10638e6e287fSHans Petter Selasky 			  int attr_mask);
10648e6e287fSHans Petter Selasky int mlx5_ib_gsi_query_qp(struct ib_qp *qp, struct ib_qp_attr *qp_attr,
10658e6e287fSHans Petter Selasky 			 int qp_attr_mask,
10668e6e287fSHans Petter Selasky 			 struct ib_qp_init_attr *qp_init_attr);
1067c3987b8eSHans Petter Selasky int mlx5_ib_gsi_post_send(struct ib_qp *qp, const struct ib_send_wr *wr,
1068c3987b8eSHans Petter Selasky 			  const struct ib_send_wr **bad_wr);
1069c3987b8eSHans Petter Selasky int mlx5_ib_gsi_post_recv(struct ib_qp *qp, const struct ib_recv_wr *wr,
1070c3987b8eSHans Petter Selasky 			  const struct ib_recv_wr **bad_wr);
10718e6e287fSHans Petter Selasky void mlx5_ib_gsi_pkey_change(struct mlx5_ib_gsi_qp *gsi);
10728e6e287fSHans Petter Selasky 
10738e6e287fSHans Petter Selasky int mlx5_ib_generate_wc(struct ib_cq *ibcq, struct ib_wc *wc);
107412515907SHans Petter Selasky 
1075f8f5b459SHans Petter Selasky void mlx5_ib_free_bfreg(struct mlx5_ib_dev *dev, struct mlx5_bfreg_info *bfregi,
1076f8f5b459SHans Petter Selasky 			int bfregn);
1077b633e08cSHans Petter Selasky 
1078b633e08cSHans Petter Selasky #if 1 /* IS_ENABLED(CONFIG_INFINIBAND_USER_ACCESS) */
1079b633e08cSHans Petter Selasky int mlx5_ib_devx_create(struct mlx5_ib_dev *dev, bool is_user);
1080b633e08cSHans Petter Selasky void mlx5_ib_devx_destroy(struct mlx5_ib_dev *dev, u16 uid);
1081b633e08cSHans Petter Selasky void mlx5_ib_devx_init_event_table(struct mlx5_ib_dev *dev);
1082b633e08cSHans Petter Selasky void mlx5_ib_devx_cleanup_event_table(struct mlx5_ib_dev *dev);
1083b633e08cSHans Petter Selasky bool mlx5_ib_devx_is_flow_dest(void *obj, int *dest_id, int *dest_type);
1084b633e08cSHans Petter Selasky bool mlx5_ib_devx_is_flow_counter(void *obj, u32 offset, u32 *counter_id);
1085b633e08cSHans Petter Selasky #else
1086b633e08cSHans Petter Selasky static inline int
1087b633e08cSHans Petter Selasky mlx5_ib_devx_create(struct mlx5_ib_dev *dev,
1088b633e08cSHans Petter Selasky 			   bool is_user) { return -EOPNOTSUPP; }
1089b633e08cSHans Petter Selasky static inline void mlx5_ib_devx_destroy(struct mlx5_ib_dev *dev, u16 uid) {}
1090b633e08cSHans Petter Selasky static inline void mlx5_ib_devx_init_event_table(struct mlx5_ib_dev *dev) {}
1091b633e08cSHans Petter Selasky static inline void mlx5_ib_devx_cleanup_event_table(struct mlx5_ib_dev *dev) {}
1092b633e08cSHans Petter Selasky static inline bool mlx5_ib_devx_is_flow_dest(void *obj, int *dest_id,
1093b633e08cSHans Petter Selasky 					     int *dest_type)
1094b633e08cSHans Petter Selasky {
1095b633e08cSHans Petter Selasky 	return false;
1096b633e08cSHans Petter Selasky }
1097b633e08cSHans Petter Selasky #endif
1098b633e08cSHans Petter Selasky 
109912515907SHans Petter Selasky static inline void init_query_mad(struct ib_smp *mad)
110012515907SHans Petter Selasky {
110112515907SHans Petter Selasky 	mad->base_version  = 1;
110212515907SHans Petter Selasky 	mad->mgmt_class    = IB_MGMT_CLASS_SUBN_LID_ROUTED;
110312515907SHans Petter Selasky 	mad->class_version = 1;
110412515907SHans Petter Selasky 	mad->method	   = IB_MGMT_METHOD_GET;
110512515907SHans Petter Selasky }
110612515907SHans Petter Selasky 
110712515907SHans Petter Selasky static inline u8 convert_access(int acc)
110812515907SHans Petter Selasky {
110912515907SHans Petter Selasky 	return (acc & IB_ACCESS_REMOTE_ATOMIC ? MLX5_PERM_ATOMIC       : 0) |
111012515907SHans Petter Selasky 	       (acc & IB_ACCESS_REMOTE_WRITE  ? MLX5_PERM_REMOTE_WRITE : 0) |
111112515907SHans Petter Selasky 	       (acc & IB_ACCESS_REMOTE_READ   ? MLX5_PERM_REMOTE_READ  : 0) |
111212515907SHans Petter Selasky 	       (acc & IB_ACCESS_LOCAL_WRITE   ? MLX5_PERM_LOCAL_WRITE  : 0) |
111312515907SHans Petter Selasky 	       MLX5_PERM_LOCAL_READ;
111412515907SHans Petter Selasky }
111512515907SHans Petter Selasky 
11168e6e287fSHans Petter Selasky static inline int is_qp1(enum ib_qp_type qp_type)
11178e6e287fSHans Petter Selasky {
11188e6e287fSHans Petter Selasky 	return qp_type == MLX5_IB_QPT_HW_GSI;
11198e6e287fSHans Petter Selasky }
11208e6e287fSHans Petter Selasky 
112112515907SHans Petter Selasky #define MLX5_MAX_UMR_SHIFT 16
112212515907SHans Petter Selasky #define MLX5_MAX_UMR_PAGES (1 << MLX5_MAX_UMR_SHIFT)
112312515907SHans Petter Selasky 
11248e6e287fSHans Petter Selasky static inline u32 check_cq_create_flags(u32 flags)
11258e6e287fSHans Petter Selasky {
11268e6e287fSHans Petter Selasky 	/*
11278e6e287fSHans Petter Selasky 	 * It returns non-zero value for unsupported CQ
11288e6e287fSHans Petter Selasky 	 * create flags, otherwise it returns zero.
11298e6e287fSHans Petter Selasky 	 */
11308e6e287fSHans Petter Selasky 	return (flags & ~(IB_CQ_FLAGS_IGNORE_OVERRUN |
11318e6e287fSHans Petter Selasky 			  IB_CQ_FLAGS_TIMESTAMP_COMPLETION));
11328e6e287fSHans Petter Selasky }
11338e6e287fSHans Petter Selasky 
11348e6e287fSHans Petter Selasky static inline int verify_assign_uidx(u8 cqe_version, u32 cmd_uidx,
11358e6e287fSHans Petter Selasky 				     u32 *user_index)
11368e6e287fSHans Petter Selasky {
11378e6e287fSHans Petter Selasky 	if (cqe_version) {
11388e6e287fSHans Petter Selasky 		if ((cmd_uidx == MLX5_IB_DEFAULT_UIDX) ||
11398e6e287fSHans Petter Selasky 		    (cmd_uidx & ~MLX5_USER_ASSIGNED_UIDX_MASK))
11408e6e287fSHans Petter Selasky 			return -EINVAL;
11418e6e287fSHans Petter Selasky 		*user_index = cmd_uidx;
11428e6e287fSHans Petter Selasky 	} else {
11438e6e287fSHans Petter Selasky 		*user_index = MLX5_IB_DEFAULT_UIDX;
11448e6e287fSHans Petter Selasky 	}
11458e6e287fSHans Petter Selasky 
11468e6e287fSHans Petter Selasky 	return 0;
11478e6e287fSHans Petter Selasky }
11488e6e287fSHans Petter Selasky 
11498e6e287fSHans Petter Selasky static inline int get_qp_user_index(struct mlx5_ib_ucontext *ucontext,
11508e6e287fSHans Petter Selasky 				    struct mlx5_ib_create_qp *ucmd,
11518e6e287fSHans Petter Selasky 				    int inlen,
11528e6e287fSHans Petter Selasky 				    u32 *user_index)
11538e6e287fSHans Petter Selasky {
11548e6e287fSHans Petter Selasky 	u8 cqe_version = ucontext->cqe_version;
11558e6e287fSHans Petter Selasky 
11568e6e287fSHans Petter Selasky 	if (field_avail(struct mlx5_ib_create_qp, uidx, inlen) &&
11578e6e287fSHans Petter Selasky 	    !cqe_version && (ucmd->uidx == MLX5_IB_DEFAULT_UIDX))
11588e6e287fSHans Petter Selasky 		return 0;
11598e6e287fSHans Petter Selasky 
11608e6e287fSHans Petter Selasky 	if (!!(field_avail(struct mlx5_ib_create_qp, uidx, inlen) !=
11618e6e287fSHans Petter Selasky 	       !!cqe_version))
11628e6e287fSHans Petter Selasky 		return -EINVAL;
11638e6e287fSHans Petter Selasky 
11648e6e287fSHans Petter Selasky 	return verify_assign_uidx(cqe_version, ucmd->uidx, user_index);
11658e6e287fSHans Petter Selasky }
11668e6e287fSHans Petter Selasky 
11678e6e287fSHans Petter Selasky static inline int get_srq_user_index(struct mlx5_ib_ucontext *ucontext,
11688e6e287fSHans Petter Selasky 				     struct mlx5_ib_create_srq *ucmd,
11698e6e287fSHans Petter Selasky 				     int inlen,
11708e6e287fSHans Petter Selasky 				     u32 *user_index)
11718e6e287fSHans Petter Selasky {
11728e6e287fSHans Petter Selasky 	u8 cqe_version = ucontext->cqe_version;
11738e6e287fSHans Petter Selasky 
11748e6e287fSHans Petter Selasky 	if (field_avail(struct mlx5_ib_create_srq, uidx, inlen) &&
11758e6e287fSHans Petter Selasky 	    !cqe_version && (ucmd->uidx == MLX5_IB_DEFAULT_UIDX))
11768e6e287fSHans Petter Selasky 		return 0;
11778e6e287fSHans Petter Selasky 
11788e6e287fSHans Petter Selasky 	if (!!(field_avail(struct mlx5_ib_create_srq, uidx, inlen) !=
11798e6e287fSHans Petter Selasky 	       !!cqe_version))
11808e6e287fSHans Petter Selasky 		return -EINVAL;
11818e6e287fSHans Petter Selasky 
11828e6e287fSHans Petter Selasky 	return verify_assign_uidx(cqe_version, ucmd->uidx, user_index);
11838e6e287fSHans Petter Selasky }
1184118063fbSHans Petter Selasky 
1185118063fbSHans Petter Selasky void mlx5_ib_cleanup_congestion(struct mlx5_ib_dev *);
1186118063fbSHans Petter Selasky int mlx5_ib_init_congestion(struct mlx5_ib_dev *);
1187118063fbSHans Petter Selasky 
1188f8f5b459SHans Petter Selasky static inline int get_uars_per_sys_page(struct mlx5_ib_dev *dev, bool lib_support)
1189f8f5b459SHans Petter Selasky {
1190f8f5b459SHans Petter Selasky 	return lib_support && MLX5_CAP_GEN(dev->mdev, uar_4k) ?
1191f8f5b459SHans Petter Selasky 				MLX5_UARS_IN_PAGE : 1;
1192f8f5b459SHans Petter Selasky }
1193f8f5b459SHans Petter Selasky 
1194f8f5b459SHans Petter Selasky static inline int get_num_static_uars(struct mlx5_ib_dev *dev,
1195f8f5b459SHans Petter Selasky 				      struct mlx5_bfreg_info *bfregi)
1196f8f5b459SHans Petter Selasky {
1197f8f5b459SHans Petter Selasky 	return get_uars_per_sys_page(dev, bfregi->lib_uar_4k) * bfregi->num_static_sys_pages;
1198f8f5b459SHans Petter Selasky }
1199f8f5b459SHans Petter Selasky 
1200f8f5b459SHans Petter Selasky int bfregn_to_uar_index(struct mlx5_ib_dev *dev,
1201f8f5b459SHans Petter Selasky 			struct mlx5_bfreg_info *bfregi, u32 bfregn,
1202f8f5b459SHans Petter Selasky 			bool dyn_bfreg);
1203f8f5b459SHans Petter Selasky 
120412515907SHans Petter Selasky #endif /* MLX5_IB_H */
1205