162306a36Sopenharmony_ci/*
262306a36Sopenharmony_ci * Copyright (c) 2006, 2007 Cisco Systems.  All rights reserved.
362306a36Sopenharmony_ci * Copyright (c) 2007, 2008 Mellanox Technologies. All rights reserved.
462306a36Sopenharmony_ci *
562306a36Sopenharmony_ci * This software is available to you under a choice of one of two
662306a36Sopenharmony_ci * licenses.  You may choose to be licensed under the terms of the GNU
762306a36Sopenharmony_ci * General Public License (GPL) Version 2, available from the file
862306a36Sopenharmony_ci * COPYING in the main directory of this source tree, or the
962306a36Sopenharmony_ci * OpenIB.org BSD license below:
1062306a36Sopenharmony_ci *
1162306a36Sopenharmony_ci *     Redistribution and use in source and binary forms, with or
1262306a36Sopenharmony_ci *     without modification, are permitted provided that the following
1362306a36Sopenharmony_ci *     conditions are met:
1462306a36Sopenharmony_ci *
1562306a36Sopenharmony_ci *      - Redistributions of source code must retain the above
1662306a36Sopenharmony_ci *        copyright notice, this list of conditions and the following
1762306a36Sopenharmony_ci *        disclaimer.
1862306a36Sopenharmony_ci *
1962306a36Sopenharmony_ci *      - Redistributions in binary form must reproduce the above
2062306a36Sopenharmony_ci *        copyright notice, this list of conditions and the following
2162306a36Sopenharmony_ci *        disclaimer in the documentation and/or other materials
2262306a36Sopenharmony_ci *        provided with the distribution.
2362306a36Sopenharmony_ci *
2462306a36Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
2562306a36Sopenharmony_ci * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
2662306a36Sopenharmony_ci * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
2762306a36Sopenharmony_ci * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
2862306a36Sopenharmony_ci * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
2962306a36Sopenharmony_ci * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
3062306a36Sopenharmony_ci * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
3162306a36Sopenharmony_ci * SOFTWARE.
3262306a36Sopenharmony_ci */
3362306a36Sopenharmony_ci
3462306a36Sopenharmony_ci#ifndef MLX4_IB_H
3562306a36Sopenharmony_ci#define MLX4_IB_H
3662306a36Sopenharmony_ci
3762306a36Sopenharmony_ci#include <linux/compiler.h>
3862306a36Sopenharmony_ci#include <linux/list.h>
3962306a36Sopenharmony_ci#include <linux/mutex.h>
4062306a36Sopenharmony_ci#include <linux/idr.h>
4162306a36Sopenharmony_ci#include <linux/notifier.h>
4262306a36Sopenharmony_ci
4362306a36Sopenharmony_ci#include <rdma/ib_verbs.h>
4462306a36Sopenharmony_ci#include <rdma/ib_umem.h>
4562306a36Sopenharmony_ci#include <rdma/ib_mad.h>
4662306a36Sopenharmony_ci#include <rdma/ib_sa.h>
4762306a36Sopenharmony_ci
4862306a36Sopenharmony_ci#include <linux/mlx4/device.h>
4962306a36Sopenharmony_ci#include <linux/mlx4/doorbell.h>
5062306a36Sopenharmony_ci#include <linux/mlx4/qp.h>
5162306a36Sopenharmony_ci#include <linux/mlx4/cq.h>
5262306a36Sopenharmony_ci
5362306a36Sopenharmony_ci#define MLX4_IB_DRV_NAME	"mlx4_ib"
5462306a36Sopenharmony_ci
5562306a36Sopenharmony_ci#ifdef pr_fmt
5662306a36Sopenharmony_ci#undef pr_fmt
5762306a36Sopenharmony_ci#endif
5862306a36Sopenharmony_ci#define pr_fmt(fmt)	"<" MLX4_IB_DRV_NAME "> %s: " fmt, __func__
5962306a36Sopenharmony_ci
6062306a36Sopenharmony_ci#define mlx4_ib_warn(ibdev, format, arg...) \
6162306a36Sopenharmony_ci	dev_warn((ibdev)->dev.parent, MLX4_IB_DRV_NAME ": " format, ## arg)
6262306a36Sopenharmony_ci
6362306a36Sopenharmony_cienum {
6462306a36Sopenharmony_ci	MLX4_IB_SQ_MIN_WQE_SHIFT = 6,
6562306a36Sopenharmony_ci	MLX4_IB_MAX_HEADROOM	 = 2048
6662306a36Sopenharmony_ci};
6762306a36Sopenharmony_ci
6862306a36Sopenharmony_ci#define MLX4_IB_SQ_HEADROOM(shift)	((MLX4_IB_MAX_HEADROOM >> (shift)) + 1)
6962306a36Sopenharmony_ci#define MLX4_IB_SQ_MAX_SPARE		(MLX4_IB_SQ_HEADROOM(MLX4_IB_SQ_MIN_WQE_SHIFT))
7062306a36Sopenharmony_ci
7162306a36Sopenharmony_ci/*module param to indicate if SM assigns the alias_GUID*/
7262306a36Sopenharmony_ciextern int mlx4_ib_sm_guid_assign;
7362306a36Sopenharmony_ci
7462306a36Sopenharmony_ci#define MLX4_IB_UC_STEER_QPN_ALIGN 1
7562306a36Sopenharmony_ci#define MLX4_IB_UC_MAX_NUM_QPS     256
7662306a36Sopenharmony_ci
7762306a36Sopenharmony_cienum hw_bar_type {
7862306a36Sopenharmony_ci	HW_BAR_BF,
7962306a36Sopenharmony_ci	HW_BAR_DB,
8062306a36Sopenharmony_ci	HW_BAR_CLOCK,
8162306a36Sopenharmony_ci	HW_BAR_COUNT
8262306a36Sopenharmony_ci};
8362306a36Sopenharmony_ci
8462306a36Sopenharmony_cistruct mlx4_ib_ucontext {
8562306a36Sopenharmony_ci	struct ib_ucontext	ibucontext;
8662306a36Sopenharmony_ci	struct mlx4_uar		uar;
8762306a36Sopenharmony_ci	struct list_head	db_page_list;
8862306a36Sopenharmony_ci	struct mutex		db_page_mutex;
8962306a36Sopenharmony_ci	struct list_head	wqn_ranges_list;
9062306a36Sopenharmony_ci	struct mutex		wqn_ranges_mutex; /* protect wqn_ranges_list */
9162306a36Sopenharmony_ci};
9262306a36Sopenharmony_ci
9362306a36Sopenharmony_cistruct mlx4_ib_pd {
9462306a36Sopenharmony_ci	struct ib_pd		ibpd;
9562306a36Sopenharmony_ci	u32			pdn;
9662306a36Sopenharmony_ci};
9762306a36Sopenharmony_ci
9862306a36Sopenharmony_cistruct mlx4_ib_xrcd {
9962306a36Sopenharmony_ci	struct ib_xrcd		ibxrcd;
10062306a36Sopenharmony_ci	u32			xrcdn;
10162306a36Sopenharmony_ci	struct ib_pd	       *pd;
10262306a36Sopenharmony_ci	struct ib_cq	       *cq;
10362306a36Sopenharmony_ci};
10462306a36Sopenharmony_ci
10562306a36Sopenharmony_cistruct mlx4_ib_cq_buf {
10662306a36Sopenharmony_ci	struct mlx4_buf		buf;
10762306a36Sopenharmony_ci	struct mlx4_mtt		mtt;
10862306a36Sopenharmony_ci	int			entry_size;
10962306a36Sopenharmony_ci};
11062306a36Sopenharmony_ci
11162306a36Sopenharmony_cistruct mlx4_ib_cq_resize {
11262306a36Sopenharmony_ci	struct mlx4_ib_cq_buf	buf;
11362306a36Sopenharmony_ci	int			cqe;
11462306a36Sopenharmony_ci};
11562306a36Sopenharmony_ci
11662306a36Sopenharmony_cistruct mlx4_ib_cq {
11762306a36Sopenharmony_ci	struct ib_cq		ibcq;
11862306a36Sopenharmony_ci	struct mlx4_cq		mcq;
11962306a36Sopenharmony_ci	struct mlx4_ib_cq_buf	buf;
12062306a36Sopenharmony_ci	struct mlx4_ib_cq_resize *resize_buf;
12162306a36Sopenharmony_ci	struct mlx4_db		db;
12262306a36Sopenharmony_ci	spinlock_t		lock;
12362306a36Sopenharmony_ci	struct mutex		resize_mutex;
12462306a36Sopenharmony_ci	struct ib_umem	       *umem;
12562306a36Sopenharmony_ci	struct ib_umem	       *resize_umem;
12662306a36Sopenharmony_ci	int			create_flags;
12762306a36Sopenharmony_ci	/* List of qps that it serves.*/
12862306a36Sopenharmony_ci	struct list_head		send_qp_list;
12962306a36Sopenharmony_ci	struct list_head		recv_qp_list;
13062306a36Sopenharmony_ci};
13162306a36Sopenharmony_ci
13262306a36Sopenharmony_ci#define MLX4_MR_PAGES_ALIGN 0x40
13362306a36Sopenharmony_ci
13462306a36Sopenharmony_cistruct mlx4_ib_mr {
13562306a36Sopenharmony_ci	struct ib_mr		ibmr;
13662306a36Sopenharmony_ci	__be64			*pages;
13762306a36Sopenharmony_ci	dma_addr_t		page_map;
13862306a36Sopenharmony_ci	u32			npages;
13962306a36Sopenharmony_ci	u32			max_pages;
14062306a36Sopenharmony_ci	struct mlx4_mr		mmr;
14162306a36Sopenharmony_ci	struct ib_umem	       *umem;
14262306a36Sopenharmony_ci	size_t			page_map_size;
14362306a36Sopenharmony_ci};
14462306a36Sopenharmony_ci
14562306a36Sopenharmony_cistruct mlx4_ib_mw {
14662306a36Sopenharmony_ci	struct ib_mw		ibmw;
14762306a36Sopenharmony_ci	struct mlx4_mw		mmw;
14862306a36Sopenharmony_ci};
14962306a36Sopenharmony_ci
15062306a36Sopenharmony_ci#define MAX_REGS_PER_FLOW 2
15162306a36Sopenharmony_ci
15262306a36Sopenharmony_cistruct mlx4_flow_reg_id {
15362306a36Sopenharmony_ci	u64 id;
15462306a36Sopenharmony_ci	u64 mirror;
15562306a36Sopenharmony_ci};
15662306a36Sopenharmony_ci
15762306a36Sopenharmony_cistruct mlx4_ib_flow {
15862306a36Sopenharmony_ci	struct ib_flow ibflow;
15962306a36Sopenharmony_ci	/* translating DMFS verbs sniffer rule to FW API requires two reg IDs */
16062306a36Sopenharmony_ci	struct mlx4_flow_reg_id reg_id[MAX_REGS_PER_FLOW];
16162306a36Sopenharmony_ci};
16262306a36Sopenharmony_ci
16362306a36Sopenharmony_cistruct mlx4_ib_wq {
16462306a36Sopenharmony_ci	u64		       *wrid;
16562306a36Sopenharmony_ci	spinlock_t		lock;
16662306a36Sopenharmony_ci	int			wqe_cnt;
16762306a36Sopenharmony_ci	int			max_post;
16862306a36Sopenharmony_ci	int			max_gs;
16962306a36Sopenharmony_ci	int			offset;
17062306a36Sopenharmony_ci	int			wqe_shift;
17162306a36Sopenharmony_ci	unsigned		head;
17262306a36Sopenharmony_ci	unsigned		tail;
17362306a36Sopenharmony_ci};
17462306a36Sopenharmony_ci
17562306a36Sopenharmony_cienum {
17662306a36Sopenharmony_ci	MLX4_IB_QP_CREATE_ROCE_V2_GSI = IB_QP_CREATE_RESERVED_START
17762306a36Sopenharmony_ci};
17862306a36Sopenharmony_ci
17962306a36Sopenharmony_cienum mlx4_ib_qp_flags {
18062306a36Sopenharmony_ci	MLX4_IB_QP_LSO = IB_QP_CREATE_IPOIB_UD_LSO,
18162306a36Sopenharmony_ci	MLX4_IB_QP_BLOCK_MULTICAST_LOOPBACK = IB_QP_CREATE_BLOCK_MULTICAST_LOOPBACK,
18262306a36Sopenharmony_ci	MLX4_IB_QP_NETIF = IB_QP_CREATE_NETIF_QP,
18362306a36Sopenharmony_ci	MLX4_IB_QP_SCATTER_FCS = IB_QP_CREATE_SCATTER_FCS,
18462306a36Sopenharmony_ci
18562306a36Sopenharmony_ci	/* Mellanox specific flags start from IB_QP_CREATE_RESERVED_START */
18662306a36Sopenharmony_ci	MLX4_IB_ROCE_V2_GSI_QP = MLX4_IB_QP_CREATE_ROCE_V2_GSI,
18762306a36Sopenharmony_ci	MLX4_IB_SRIOV_TUNNEL_QP = 1 << 30,
18862306a36Sopenharmony_ci	MLX4_IB_SRIOV_SQP = 1 << 31,
18962306a36Sopenharmony_ci};
19062306a36Sopenharmony_ci
19162306a36Sopenharmony_cistruct mlx4_ib_gid_entry {
19262306a36Sopenharmony_ci	struct list_head	list;
19362306a36Sopenharmony_ci	union ib_gid		gid;
19462306a36Sopenharmony_ci	int			added;
19562306a36Sopenharmony_ci	u8			port;
19662306a36Sopenharmony_ci};
19762306a36Sopenharmony_ci
19862306a36Sopenharmony_cienum mlx4_ib_qp_type {
19962306a36Sopenharmony_ci	/*
20062306a36Sopenharmony_ci	 * IB_QPT_SMI and IB_QPT_GSI have to be the first two entries
20162306a36Sopenharmony_ci	 * here (and in that order) since the MAD layer uses them as
20262306a36Sopenharmony_ci	 * indices into a 2-entry table.
20362306a36Sopenharmony_ci	 */
20462306a36Sopenharmony_ci	MLX4_IB_QPT_SMI = IB_QPT_SMI,
20562306a36Sopenharmony_ci	MLX4_IB_QPT_GSI = IB_QPT_GSI,
20662306a36Sopenharmony_ci
20762306a36Sopenharmony_ci	MLX4_IB_QPT_RC = IB_QPT_RC,
20862306a36Sopenharmony_ci	MLX4_IB_QPT_UC = IB_QPT_UC,
20962306a36Sopenharmony_ci	MLX4_IB_QPT_UD = IB_QPT_UD,
21062306a36Sopenharmony_ci	MLX4_IB_QPT_RAW_IPV6 = IB_QPT_RAW_IPV6,
21162306a36Sopenharmony_ci	MLX4_IB_QPT_RAW_ETHERTYPE = IB_QPT_RAW_ETHERTYPE,
21262306a36Sopenharmony_ci	MLX4_IB_QPT_RAW_PACKET = IB_QPT_RAW_PACKET,
21362306a36Sopenharmony_ci	MLX4_IB_QPT_XRC_INI = IB_QPT_XRC_INI,
21462306a36Sopenharmony_ci	MLX4_IB_QPT_XRC_TGT = IB_QPT_XRC_TGT,
21562306a36Sopenharmony_ci
21662306a36Sopenharmony_ci	MLX4_IB_QPT_PROXY_SMI_OWNER	= 1 << 16,
21762306a36Sopenharmony_ci	MLX4_IB_QPT_PROXY_SMI		= 1 << 17,
21862306a36Sopenharmony_ci	MLX4_IB_QPT_PROXY_GSI		= 1 << 18,
21962306a36Sopenharmony_ci	MLX4_IB_QPT_TUN_SMI_OWNER	= 1 << 19,
22062306a36Sopenharmony_ci	MLX4_IB_QPT_TUN_SMI		= 1 << 20,
22162306a36Sopenharmony_ci	MLX4_IB_QPT_TUN_GSI		= 1 << 21,
22262306a36Sopenharmony_ci};
22362306a36Sopenharmony_ci
22462306a36Sopenharmony_ci#define MLX4_IB_QPT_ANY_SRIOV	(MLX4_IB_QPT_PROXY_SMI_OWNER | \
22562306a36Sopenharmony_ci	MLX4_IB_QPT_PROXY_SMI | MLX4_IB_QPT_PROXY_GSI | MLX4_IB_QPT_TUN_SMI_OWNER | \
22662306a36Sopenharmony_ci	MLX4_IB_QPT_TUN_SMI | MLX4_IB_QPT_TUN_GSI)
22762306a36Sopenharmony_ci
22862306a36Sopenharmony_cienum mlx4_ib_mad_ifc_flags {
22962306a36Sopenharmony_ci	MLX4_MAD_IFC_IGNORE_MKEY	= 1,
23062306a36Sopenharmony_ci	MLX4_MAD_IFC_IGNORE_BKEY	= 2,
23162306a36Sopenharmony_ci	MLX4_MAD_IFC_IGNORE_KEYS	= (MLX4_MAD_IFC_IGNORE_MKEY |
23262306a36Sopenharmony_ci					   MLX4_MAD_IFC_IGNORE_BKEY),
23362306a36Sopenharmony_ci	MLX4_MAD_IFC_NET_VIEW		= 4,
23462306a36Sopenharmony_ci};
23562306a36Sopenharmony_ci
23662306a36Sopenharmony_cienum {
23762306a36Sopenharmony_ci	MLX4_NUM_TUNNEL_BUFS		= 512,
23862306a36Sopenharmony_ci	MLX4_NUM_WIRE_BUFS		= 2048,
23962306a36Sopenharmony_ci};
24062306a36Sopenharmony_ci
24162306a36Sopenharmony_cistruct mlx4_ib_tunnel_header {
24262306a36Sopenharmony_ci	struct mlx4_av av;
24362306a36Sopenharmony_ci	__be32 remote_qpn;
24462306a36Sopenharmony_ci	__be32 qkey;
24562306a36Sopenharmony_ci	__be16 vlan;
24662306a36Sopenharmony_ci	u8 mac[6];
24762306a36Sopenharmony_ci	__be16 pkey_index;
24862306a36Sopenharmony_ci	u8 reserved[6];
24962306a36Sopenharmony_ci};
25062306a36Sopenharmony_ci
25162306a36Sopenharmony_cistruct mlx4_ib_buf {
25262306a36Sopenharmony_ci	void *addr;
25362306a36Sopenharmony_ci	dma_addr_t map;
25462306a36Sopenharmony_ci};
25562306a36Sopenharmony_ci
25662306a36Sopenharmony_cistruct mlx4_rcv_tunnel_hdr {
25762306a36Sopenharmony_ci	__be32 flags_src_qp; /* flags[6:5] is defined for VLANs:
25862306a36Sopenharmony_ci			      * 0x0 - no vlan was in the packet
25962306a36Sopenharmony_ci			      * 0x01 - C-VLAN was in the packet */
26062306a36Sopenharmony_ci	u8 g_ml_path; /* gid bit stands for ipv6/4 header in RoCE */
26162306a36Sopenharmony_ci	u8 reserved;
26262306a36Sopenharmony_ci	__be16 pkey_index;
26362306a36Sopenharmony_ci	__be16 sl_vid;
26462306a36Sopenharmony_ci	__be16 slid_mac_47_32;
26562306a36Sopenharmony_ci	__be32 mac_31_0;
26662306a36Sopenharmony_ci};
26762306a36Sopenharmony_ci
26862306a36Sopenharmony_cistruct mlx4_ib_proxy_sqp_hdr {
26962306a36Sopenharmony_ci	struct ib_grh grh;
27062306a36Sopenharmony_ci	struct mlx4_rcv_tunnel_hdr tun;
27162306a36Sopenharmony_ci}  __packed;
27262306a36Sopenharmony_ci
27362306a36Sopenharmony_cistruct mlx4_roce_smac_vlan_info {
27462306a36Sopenharmony_ci	u64 smac;
27562306a36Sopenharmony_ci	int smac_index;
27662306a36Sopenharmony_ci	int smac_port;
27762306a36Sopenharmony_ci	u64 candidate_smac;
27862306a36Sopenharmony_ci	int candidate_smac_index;
27962306a36Sopenharmony_ci	int candidate_smac_port;
28062306a36Sopenharmony_ci	u16 vid;
28162306a36Sopenharmony_ci	int vlan_index;
28262306a36Sopenharmony_ci	int vlan_port;
28362306a36Sopenharmony_ci	u16 candidate_vid;
28462306a36Sopenharmony_ci	int candidate_vlan_index;
28562306a36Sopenharmony_ci	int candidate_vlan_port;
28662306a36Sopenharmony_ci	int update_vid;
28762306a36Sopenharmony_ci};
28862306a36Sopenharmony_ci
28962306a36Sopenharmony_cistruct mlx4_wqn_range {
29062306a36Sopenharmony_ci	int			base_wqn;
29162306a36Sopenharmony_ci	int			size;
29262306a36Sopenharmony_ci	int			refcount;
29362306a36Sopenharmony_ci	bool			dirty;
29462306a36Sopenharmony_ci	struct list_head	list;
29562306a36Sopenharmony_ci};
29662306a36Sopenharmony_ci
29762306a36Sopenharmony_cistruct mlx4_ib_rss {
29862306a36Sopenharmony_ci	unsigned int		base_qpn_tbl_sz;
29962306a36Sopenharmony_ci	u8			flags;
30062306a36Sopenharmony_ci	u8			rss_key[MLX4_EN_RSS_KEY_SIZE];
30162306a36Sopenharmony_ci};
30262306a36Sopenharmony_ci
30362306a36Sopenharmony_cienum {
30462306a36Sopenharmony_ci	/*
30562306a36Sopenharmony_ci	 * Largest possible UD header: send with GRH and immediate
30662306a36Sopenharmony_ci	 * data plus 18 bytes for an Ethernet header with VLAN/802.1Q
30762306a36Sopenharmony_ci	 * tag.  (LRH would only use 8 bytes, so Ethernet is the
30862306a36Sopenharmony_ci	 * biggest case)
30962306a36Sopenharmony_ci	 */
31062306a36Sopenharmony_ci	MLX4_IB_UD_HEADER_SIZE		= 82,
31162306a36Sopenharmony_ci	MLX4_IB_LSO_HEADER_SPARE	= 128,
31262306a36Sopenharmony_ci};
31362306a36Sopenharmony_ci
31462306a36Sopenharmony_cistruct mlx4_ib_sqp {
31562306a36Sopenharmony_ci	int pkey_index;
31662306a36Sopenharmony_ci	u32 qkey;
31762306a36Sopenharmony_ci	u32 send_psn;
31862306a36Sopenharmony_ci	struct ib_ud_header ud_header;
31962306a36Sopenharmony_ci	u8 header_buf[MLX4_IB_UD_HEADER_SIZE];
32062306a36Sopenharmony_ci	struct ib_qp *roce_v2_gsi;
32162306a36Sopenharmony_ci};
32262306a36Sopenharmony_ci
32362306a36Sopenharmony_cistruct mlx4_ib_qp {
32462306a36Sopenharmony_ci	union {
32562306a36Sopenharmony_ci		struct ib_qp	ibqp;
32662306a36Sopenharmony_ci		struct ib_wq	ibwq;
32762306a36Sopenharmony_ci	};
32862306a36Sopenharmony_ci	struct mlx4_qp		mqp;
32962306a36Sopenharmony_ci	struct mlx4_buf		buf;
33062306a36Sopenharmony_ci
33162306a36Sopenharmony_ci	struct mlx4_db		db;
33262306a36Sopenharmony_ci	struct mlx4_ib_wq	rq;
33362306a36Sopenharmony_ci
33462306a36Sopenharmony_ci	u32			doorbell_qpn;
33562306a36Sopenharmony_ci	__be32			sq_signal_bits;
33662306a36Sopenharmony_ci	unsigned		sq_next_wqe;
33762306a36Sopenharmony_ci	int			sq_spare_wqes;
33862306a36Sopenharmony_ci	struct mlx4_ib_wq	sq;
33962306a36Sopenharmony_ci
34062306a36Sopenharmony_ci	enum mlx4_ib_qp_type	mlx4_ib_qp_type;
34162306a36Sopenharmony_ci	struct ib_umem	       *umem;
34262306a36Sopenharmony_ci	struct mlx4_mtt		mtt;
34362306a36Sopenharmony_ci	int			buf_size;
34462306a36Sopenharmony_ci	struct mutex		mutex;
34562306a36Sopenharmony_ci	u16			xrcdn;
34662306a36Sopenharmony_ci	u32			flags;
34762306a36Sopenharmony_ci	u8			port;
34862306a36Sopenharmony_ci	u8			alt_port;
34962306a36Sopenharmony_ci	u8			atomic_rd_en;
35062306a36Sopenharmony_ci	u8			resp_depth;
35162306a36Sopenharmony_ci	u8			sq_no_prefetch;
35262306a36Sopenharmony_ci	u8			state;
35362306a36Sopenharmony_ci	int			mlx_type;
35462306a36Sopenharmony_ci	u32			inl_recv_sz;
35562306a36Sopenharmony_ci	struct list_head	gid_list;
35662306a36Sopenharmony_ci	struct list_head	steering_rules;
35762306a36Sopenharmony_ci	struct mlx4_ib_buf	*sqp_proxy_rcv;
35862306a36Sopenharmony_ci	struct mlx4_roce_smac_vlan_info pri;
35962306a36Sopenharmony_ci	struct mlx4_roce_smac_vlan_info alt;
36062306a36Sopenharmony_ci	u64			reg_id;
36162306a36Sopenharmony_ci	struct list_head	qps_list;
36262306a36Sopenharmony_ci	struct list_head	cq_recv_list;
36362306a36Sopenharmony_ci	struct list_head	cq_send_list;
36462306a36Sopenharmony_ci	struct counter_index	*counter_index;
36562306a36Sopenharmony_ci	struct mlx4_wqn_range	*wqn_range;
36662306a36Sopenharmony_ci	/* Number of RSS QP parents that uses this WQ */
36762306a36Sopenharmony_ci	u32			rss_usecnt;
36862306a36Sopenharmony_ci	union {
36962306a36Sopenharmony_ci		struct mlx4_ib_rss *rss_ctx;
37062306a36Sopenharmony_ci		struct mlx4_ib_sqp *sqp;
37162306a36Sopenharmony_ci	};
37262306a36Sopenharmony_ci};
37362306a36Sopenharmony_ci
37462306a36Sopenharmony_cistruct mlx4_ib_srq {
37562306a36Sopenharmony_ci	struct ib_srq		ibsrq;
37662306a36Sopenharmony_ci	struct mlx4_srq		msrq;
37762306a36Sopenharmony_ci	struct mlx4_buf		buf;
37862306a36Sopenharmony_ci	struct mlx4_db		db;
37962306a36Sopenharmony_ci	u64		       *wrid;
38062306a36Sopenharmony_ci	spinlock_t		lock;
38162306a36Sopenharmony_ci	int			head;
38262306a36Sopenharmony_ci	int			tail;
38362306a36Sopenharmony_ci	u16			wqe_ctr;
38462306a36Sopenharmony_ci	struct ib_umem	       *umem;
38562306a36Sopenharmony_ci	struct mlx4_mtt		mtt;
38662306a36Sopenharmony_ci	struct mutex		mutex;
38762306a36Sopenharmony_ci};
38862306a36Sopenharmony_ci
38962306a36Sopenharmony_cistruct mlx4_ib_ah {
39062306a36Sopenharmony_ci	struct ib_ah		ibah;
39162306a36Sopenharmony_ci	union mlx4_ext_av       av;
39262306a36Sopenharmony_ci};
39362306a36Sopenharmony_ci
39462306a36Sopenharmony_cistruct mlx4_ib_rwq_ind_table {
39562306a36Sopenharmony_ci	struct ib_rwq_ind_table ib_rwq_ind_tbl;
39662306a36Sopenharmony_ci};
39762306a36Sopenharmony_ci
39862306a36Sopenharmony_ci/****************************************/
39962306a36Sopenharmony_ci/* alias guid support */
40062306a36Sopenharmony_ci/****************************************/
40162306a36Sopenharmony_ci#define NUM_PORT_ALIAS_GUID		2
40262306a36Sopenharmony_ci#define NUM_ALIAS_GUID_IN_REC		8
40362306a36Sopenharmony_ci#define NUM_ALIAS_GUID_REC_IN_PORT	16
40462306a36Sopenharmony_ci#define GUID_REC_SIZE			8
40562306a36Sopenharmony_ci#define NUM_ALIAS_GUID_PER_PORT		128
40662306a36Sopenharmony_ci#define MLX4_NOT_SET_GUID		(0x00LL)
40762306a36Sopenharmony_ci#define MLX4_GUID_FOR_DELETE_VAL	(~(0x00LL))
40862306a36Sopenharmony_ci
40962306a36Sopenharmony_cienum mlx4_guid_alias_rec_status {
41062306a36Sopenharmony_ci	MLX4_GUID_INFO_STATUS_IDLE,
41162306a36Sopenharmony_ci	MLX4_GUID_INFO_STATUS_SET,
41262306a36Sopenharmony_ci};
41362306a36Sopenharmony_ci
41462306a36Sopenharmony_ci#define GUID_STATE_NEED_PORT_INIT 0x01
41562306a36Sopenharmony_ci
41662306a36Sopenharmony_cienum mlx4_guid_alias_rec_method {
41762306a36Sopenharmony_ci	MLX4_GUID_INFO_RECORD_SET	= IB_MGMT_METHOD_SET,
41862306a36Sopenharmony_ci	MLX4_GUID_INFO_RECORD_DELETE	= IB_SA_METHOD_DELETE,
41962306a36Sopenharmony_ci};
42062306a36Sopenharmony_ci
42162306a36Sopenharmony_cistruct mlx4_sriov_alias_guid_info_rec_det {
42262306a36Sopenharmony_ci	u8 all_recs[GUID_REC_SIZE * NUM_ALIAS_GUID_IN_REC];
42362306a36Sopenharmony_ci	ib_sa_comp_mask guid_indexes; /*indicates what from the 8 records are valid*/
42462306a36Sopenharmony_ci	enum mlx4_guid_alias_rec_status status; /*indicates the administraively status of the record.*/
42562306a36Sopenharmony_ci	unsigned int guids_retry_schedule[NUM_ALIAS_GUID_IN_REC];
42662306a36Sopenharmony_ci	u64 time_to_run;
42762306a36Sopenharmony_ci};
42862306a36Sopenharmony_ci
42962306a36Sopenharmony_cistruct mlx4_sriov_alias_guid_port_rec_det {
43062306a36Sopenharmony_ci	struct mlx4_sriov_alias_guid_info_rec_det all_rec_per_port[NUM_ALIAS_GUID_REC_IN_PORT];
43162306a36Sopenharmony_ci	struct workqueue_struct *wq;
43262306a36Sopenharmony_ci	struct delayed_work alias_guid_work;
43362306a36Sopenharmony_ci	u32 port;
43462306a36Sopenharmony_ci	u32 state_flags;
43562306a36Sopenharmony_ci	struct mlx4_sriov_alias_guid *parent;
43662306a36Sopenharmony_ci	struct list_head cb_list;
43762306a36Sopenharmony_ci};
43862306a36Sopenharmony_ci
43962306a36Sopenharmony_cistruct mlx4_sriov_alias_guid {
44062306a36Sopenharmony_ci	struct mlx4_sriov_alias_guid_port_rec_det ports_guid[MLX4_MAX_PORTS];
44162306a36Sopenharmony_ci	spinlock_t ag_work_lock;
44262306a36Sopenharmony_ci	struct ib_sa_client *sa_client;
44362306a36Sopenharmony_ci};
44462306a36Sopenharmony_ci
44562306a36Sopenharmony_cistruct mlx4_ib_demux_work {
44662306a36Sopenharmony_ci	struct work_struct	work;
44762306a36Sopenharmony_ci	struct mlx4_ib_dev     *dev;
44862306a36Sopenharmony_ci	int			slave;
44962306a36Sopenharmony_ci	int			do_init;
45062306a36Sopenharmony_ci	u8			port;
45162306a36Sopenharmony_ci
45262306a36Sopenharmony_ci};
45362306a36Sopenharmony_ci
45462306a36Sopenharmony_cistruct mlx4_ib_tun_tx_buf {
45562306a36Sopenharmony_ci	struct mlx4_ib_buf buf;
45662306a36Sopenharmony_ci	struct ib_ah *ah;
45762306a36Sopenharmony_ci};
45862306a36Sopenharmony_ci
45962306a36Sopenharmony_cistruct mlx4_ib_demux_pv_qp {
46062306a36Sopenharmony_ci	struct ib_qp *qp;
46162306a36Sopenharmony_ci	enum ib_qp_type proxy_qpt;
46262306a36Sopenharmony_ci	struct mlx4_ib_buf *ring;
46362306a36Sopenharmony_ci	struct mlx4_ib_tun_tx_buf *tx_ring;
46462306a36Sopenharmony_ci	spinlock_t tx_lock;
46562306a36Sopenharmony_ci	unsigned tx_ix_head;
46662306a36Sopenharmony_ci	unsigned tx_ix_tail;
46762306a36Sopenharmony_ci};
46862306a36Sopenharmony_ci
46962306a36Sopenharmony_cienum mlx4_ib_demux_pv_state {
47062306a36Sopenharmony_ci	DEMUX_PV_STATE_DOWN,
47162306a36Sopenharmony_ci	DEMUX_PV_STATE_STARTING,
47262306a36Sopenharmony_ci	DEMUX_PV_STATE_ACTIVE,
47362306a36Sopenharmony_ci	DEMUX_PV_STATE_DOWNING,
47462306a36Sopenharmony_ci};
47562306a36Sopenharmony_ci
47662306a36Sopenharmony_cistruct mlx4_ib_demux_pv_ctx {
47762306a36Sopenharmony_ci	int port;
47862306a36Sopenharmony_ci	int slave;
47962306a36Sopenharmony_ci	enum mlx4_ib_demux_pv_state state;
48062306a36Sopenharmony_ci	int has_smi;
48162306a36Sopenharmony_ci	struct ib_device *ib_dev;
48262306a36Sopenharmony_ci	struct ib_cq *cq;
48362306a36Sopenharmony_ci	struct ib_pd *pd;
48462306a36Sopenharmony_ci	struct work_struct work;
48562306a36Sopenharmony_ci	struct workqueue_struct *wq;
48662306a36Sopenharmony_ci	struct workqueue_struct *wi_wq;
48762306a36Sopenharmony_ci	struct mlx4_ib_demux_pv_qp qp[2];
48862306a36Sopenharmony_ci};
48962306a36Sopenharmony_ci
49062306a36Sopenharmony_cistruct mlx4_ib_demux_ctx {
49162306a36Sopenharmony_ci	struct ib_device *ib_dev;
49262306a36Sopenharmony_ci	int port;
49362306a36Sopenharmony_ci	struct workqueue_struct *wq;
49462306a36Sopenharmony_ci	struct workqueue_struct *wi_wq;
49562306a36Sopenharmony_ci	struct workqueue_struct *ud_wq;
49662306a36Sopenharmony_ci	spinlock_t ud_lock;
49762306a36Sopenharmony_ci	atomic64_t subnet_prefix;
49862306a36Sopenharmony_ci	__be64 guid_cache[128];
49962306a36Sopenharmony_ci	struct mlx4_ib_dev *dev;
50062306a36Sopenharmony_ci	/* the following lock protects both mcg_table and mcg_mgid0_list */
50162306a36Sopenharmony_ci	struct mutex		mcg_table_lock;
50262306a36Sopenharmony_ci	struct rb_root		mcg_table;
50362306a36Sopenharmony_ci	struct list_head	mcg_mgid0_list;
50462306a36Sopenharmony_ci	struct workqueue_struct	*mcg_wq;
50562306a36Sopenharmony_ci	struct mlx4_ib_demux_pv_ctx **tun;
50662306a36Sopenharmony_ci	atomic_t tid;
50762306a36Sopenharmony_ci	int    flushing; /* flushing the work queue */
50862306a36Sopenharmony_ci};
50962306a36Sopenharmony_ci
51062306a36Sopenharmony_cistruct mlx4_ib_sriov {
51162306a36Sopenharmony_ci	struct mlx4_ib_demux_ctx demux[MLX4_MAX_PORTS];
51262306a36Sopenharmony_ci	struct mlx4_ib_demux_pv_ctx *sqps[MLX4_MAX_PORTS];
51362306a36Sopenharmony_ci	/* when using this spinlock you should use "irq" because
51462306a36Sopenharmony_ci	 * it may be called from interrupt context.*/
51562306a36Sopenharmony_ci	spinlock_t going_down_lock;
51662306a36Sopenharmony_ci	int is_going_down;
51762306a36Sopenharmony_ci
51862306a36Sopenharmony_ci	struct mlx4_sriov_alias_guid alias_guid;
51962306a36Sopenharmony_ci
52062306a36Sopenharmony_ci	/* CM paravirtualization fields */
52162306a36Sopenharmony_ci	struct xarray pv_id_table;
52262306a36Sopenharmony_ci	u32 pv_id_next;
52362306a36Sopenharmony_ci	spinlock_t id_map_lock;
52462306a36Sopenharmony_ci	struct rb_root sl_id_map;
52562306a36Sopenharmony_ci	struct list_head cm_list;
52662306a36Sopenharmony_ci	struct xarray xa_rej_tmout;
52762306a36Sopenharmony_ci};
52862306a36Sopenharmony_ci
52962306a36Sopenharmony_cistruct gid_cache_context {
53062306a36Sopenharmony_ci	int real_index;
53162306a36Sopenharmony_ci	int refcount;
53262306a36Sopenharmony_ci};
53362306a36Sopenharmony_ci
53462306a36Sopenharmony_cistruct gid_entry {
53562306a36Sopenharmony_ci	union ib_gid	gid;
53662306a36Sopenharmony_ci	enum ib_gid_type gid_type;
53762306a36Sopenharmony_ci	struct gid_cache_context *ctx;
53862306a36Sopenharmony_ci	u16 vlan_id;
53962306a36Sopenharmony_ci};
54062306a36Sopenharmony_ci
54162306a36Sopenharmony_cistruct mlx4_port_gid_table {
54262306a36Sopenharmony_ci	struct gid_entry gids[MLX4_MAX_PORT_GIDS];
54362306a36Sopenharmony_ci};
54462306a36Sopenharmony_ci
54562306a36Sopenharmony_cistruct mlx4_ib_iboe {
54662306a36Sopenharmony_ci	spinlock_t		lock;
54762306a36Sopenharmony_ci	struct net_device      *netdevs[MLX4_MAX_PORTS];
54862306a36Sopenharmony_ci	atomic64_t		mac[MLX4_MAX_PORTS];
54962306a36Sopenharmony_ci	struct notifier_block 	nb;
55062306a36Sopenharmony_ci	struct mlx4_port_gid_table gids[MLX4_MAX_PORTS];
55162306a36Sopenharmony_ci	enum ib_port_state	last_port_state[MLX4_MAX_PORTS];
55262306a36Sopenharmony_ci};
55362306a36Sopenharmony_ci
55462306a36Sopenharmony_cistruct pkey_mgt {
55562306a36Sopenharmony_ci	u8			virt2phys_pkey[MLX4_MFUNC_MAX][MLX4_MAX_PORTS][MLX4_MAX_PORT_PKEYS];
55662306a36Sopenharmony_ci	u16			phys_pkey_cache[MLX4_MAX_PORTS][MLX4_MAX_PORT_PKEYS];
55762306a36Sopenharmony_ci	struct list_head	pkey_port_list[MLX4_MFUNC_MAX];
55862306a36Sopenharmony_ci	struct kobject	       *device_parent[MLX4_MFUNC_MAX];
55962306a36Sopenharmony_ci};
56062306a36Sopenharmony_ci
56162306a36Sopenharmony_cistruct mlx4_ib_iov_sysfs_attr {
56262306a36Sopenharmony_ci	void *ctx;
56362306a36Sopenharmony_ci	struct kobject *kobj;
56462306a36Sopenharmony_ci	unsigned long data;
56562306a36Sopenharmony_ci	u32 entry_num;
56662306a36Sopenharmony_ci	char name[15];
56762306a36Sopenharmony_ci	struct device_attribute dentry;
56862306a36Sopenharmony_ci	struct device *dev;
56962306a36Sopenharmony_ci};
57062306a36Sopenharmony_ci
57162306a36Sopenharmony_cistruct mlx4_ib_iov_sysfs_attr_ar {
57262306a36Sopenharmony_ci	struct mlx4_ib_iov_sysfs_attr dentries[3 * NUM_ALIAS_GUID_PER_PORT + 1];
57362306a36Sopenharmony_ci};
57462306a36Sopenharmony_ci
57562306a36Sopenharmony_cistruct mlx4_ib_iov_port {
57662306a36Sopenharmony_ci	char name[100];
57762306a36Sopenharmony_ci	u8 num;
57862306a36Sopenharmony_ci	struct mlx4_ib_dev *dev;
57962306a36Sopenharmony_ci	struct list_head list;
58062306a36Sopenharmony_ci	struct mlx4_ib_iov_sysfs_attr_ar *dentr_ar;
58162306a36Sopenharmony_ci	struct ib_port_attr attr;
58262306a36Sopenharmony_ci	struct kobject	*cur_port;
58362306a36Sopenharmony_ci	struct kobject	*admin_alias_parent;
58462306a36Sopenharmony_ci	struct kobject	*gids_parent;
58562306a36Sopenharmony_ci	struct kobject	*pkeys_parent;
58662306a36Sopenharmony_ci	struct kobject	*mcgs_parent;
58762306a36Sopenharmony_ci	struct mlx4_ib_iov_sysfs_attr mcg_dentry;
58862306a36Sopenharmony_ci};
58962306a36Sopenharmony_ci
59062306a36Sopenharmony_cistruct counter_index {
59162306a36Sopenharmony_ci	struct  list_head       list;
59262306a36Sopenharmony_ci	u32		index;
59362306a36Sopenharmony_ci	u8		allocated;
59462306a36Sopenharmony_ci};
59562306a36Sopenharmony_ci
59662306a36Sopenharmony_cistruct mlx4_ib_counters {
59762306a36Sopenharmony_ci	struct list_head        counters_list;
59862306a36Sopenharmony_ci	struct mutex            mutex; /* mutex for accessing counters list */
59962306a36Sopenharmony_ci	u32			default_counter;
60062306a36Sopenharmony_ci};
60162306a36Sopenharmony_ci
60262306a36Sopenharmony_ci#define MLX4_DIAG_COUNTERS_TYPES 2
60362306a36Sopenharmony_ci
60462306a36Sopenharmony_cistruct mlx4_ib_diag_counters {
60562306a36Sopenharmony_ci	struct rdma_stat_desc *descs;
60662306a36Sopenharmony_ci	u32 *offset;
60762306a36Sopenharmony_ci	u32 num_counters;
60862306a36Sopenharmony_ci};
60962306a36Sopenharmony_ci
61062306a36Sopenharmony_cistruct mlx4_ib_dev {
61162306a36Sopenharmony_ci	struct ib_device	ib_dev;
61262306a36Sopenharmony_ci	struct mlx4_dev	       *dev;
61362306a36Sopenharmony_ci	int			num_ports;
61462306a36Sopenharmony_ci	void __iomem	       *uar_map;
61562306a36Sopenharmony_ci
61662306a36Sopenharmony_ci	struct mlx4_uar		priv_uar;
61762306a36Sopenharmony_ci	u32			priv_pdn;
61862306a36Sopenharmony_ci	MLX4_DECLARE_DOORBELL_LOCK(uar_lock);
61962306a36Sopenharmony_ci
62062306a36Sopenharmony_ci	struct ib_mad_agent    *send_agent[MLX4_MAX_PORTS][2];
62162306a36Sopenharmony_ci	struct ib_ah	       *sm_ah[MLX4_MAX_PORTS];
62262306a36Sopenharmony_ci	spinlock_t		sm_lock;
62362306a36Sopenharmony_ci	atomic64_t		sl2vl[MLX4_MAX_PORTS];
62462306a36Sopenharmony_ci	struct mlx4_ib_sriov	sriov;
62562306a36Sopenharmony_ci
62662306a36Sopenharmony_ci	struct mutex		cap_mask_mutex;
62762306a36Sopenharmony_ci	bool			ib_active;
62862306a36Sopenharmony_ci	struct mlx4_ib_iboe	iboe;
62962306a36Sopenharmony_ci	struct mlx4_ib_counters counters_table[MLX4_MAX_PORTS];
63062306a36Sopenharmony_ci	int		       *eq_table;
63162306a36Sopenharmony_ci	struct kobject	       *iov_parent;
63262306a36Sopenharmony_ci	struct kobject	       *ports_parent;
63362306a36Sopenharmony_ci	struct kobject	       *dev_ports_parent[MLX4_MFUNC_MAX];
63462306a36Sopenharmony_ci	struct mlx4_ib_iov_port	iov_ports[MLX4_MAX_PORTS];
63562306a36Sopenharmony_ci	struct pkey_mgt		pkeys;
63662306a36Sopenharmony_ci	unsigned long *ib_uc_qpns_bitmap;
63762306a36Sopenharmony_ci	int steer_qpn_count;
63862306a36Sopenharmony_ci	int steer_qpn_base;
63962306a36Sopenharmony_ci	int steering_support;
64062306a36Sopenharmony_ci	struct mlx4_ib_qp      *qp1_proxy[MLX4_MAX_PORTS];
64162306a36Sopenharmony_ci	/* lock when destroying qp1_proxy and getting netdev events */
64262306a36Sopenharmony_ci	struct mutex		qp1_proxy_lock[MLX4_MAX_PORTS];
64362306a36Sopenharmony_ci	u8			bond_next_port;
64462306a36Sopenharmony_ci	/* protect resources needed as part of reset flow */
64562306a36Sopenharmony_ci	spinlock_t		reset_flow_resource_lock;
64662306a36Sopenharmony_ci	struct list_head		qp_list;
64762306a36Sopenharmony_ci	struct mlx4_ib_diag_counters diag_counters[MLX4_DIAG_COUNTERS_TYPES];
64862306a36Sopenharmony_ci	struct notifier_block	mlx_nb;
64962306a36Sopenharmony_ci};
65062306a36Sopenharmony_ci
65162306a36Sopenharmony_cistruct ib_event_work {
65262306a36Sopenharmony_ci	struct work_struct	work;
65362306a36Sopenharmony_ci	struct mlx4_ib_dev	*ib_dev;
65462306a36Sopenharmony_ci	struct mlx4_eqe		ib_eqe;
65562306a36Sopenharmony_ci	int			port;
65662306a36Sopenharmony_ci};
65762306a36Sopenharmony_ci
65862306a36Sopenharmony_cistruct mlx4_ib_qp_tunnel_init_attr {
65962306a36Sopenharmony_ci	struct ib_qp_init_attr init_attr;
66062306a36Sopenharmony_ci	int slave;
66162306a36Sopenharmony_ci	enum ib_qp_type proxy_qp_type;
66262306a36Sopenharmony_ci	u32 port;
66362306a36Sopenharmony_ci};
66462306a36Sopenharmony_ci
66562306a36Sopenharmony_cistruct mlx4_uverbs_ex_query_device {
66662306a36Sopenharmony_ci	__u32 comp_mask;
66762306a36Sopenharmony_ci	__u32 reserved;
66862306a36Sopenharmony_ci};
66962306a36Sopenharmony_ci
67062306a36Sopenharmony_cistatic inline struct mlx4_ib_dev *to_mdev(struct ib_device *ibdev)
67162306a36Sopenharmony_ci{
67262306a36Sopenharmony_ci	return container_of(ibdev, struct mlx4_ib_dev, ib_dev);
67362306a36Sopenharmony_ci}
67462306a36Sopenharmony_ci
67562306a36Sopenharmony_cistatic inline struct mlx4_ib_ucontext *to_mucontext(struct ib_ucontext *ibucontext)
67662306a36Sopenharmony_ci{
67762306a36Sopenharmony_ci	return container_of(ibucontext, struct mlx4_ib_ucontext, ibucontext);
67862306a36Sopenharmony_ci}
67962306a36Sopenharmony_ci
68062306a36Sopenharmony_cistatic inline struct mlx4_ib_pd *to_mpd(struct ib_pd *ibpd)
68162306a36Sopenharmony_ci{
68262306a36Sopenharmony_ci	return container_of(ibpd, struct mlx4_ib_pd, ibpd);
68362306a36Sopenharmony_ci}
68462306a36Sopenharmony_ci
68562306a36Sopenharmony_cistatic inline struct mlx4_ib_xrcd *to_mxrcd(struct ib_xrcd *ibxrcd)
68662306a36Sopenharmony_ci{
68762306a36Sopenharmony_ci	return container_of(ibxrcd, struct mlx4_ib_xrcd, ibxrcd);
68862306a36Sopenharmony_ci}
68962306a36Sopenharmony_ci
69062306a36Sopenharmony_cistatic inline struct mlx4_ib_cq *to_mcq(struct ib_cq *ibcq)
69162306a36Sopenharmony_ci{
69262306a36Sopenharmony_ci	return container_of(ibcq, struct mlx4_ib_cq, ibcq);
69362306a36Sopenharmony_ci}
69462306a36Sopenharmony_ci
69562306a36Sopenharmony_cistatic inline struct mlx4_ib_cq *to_mibcq(struct mlx4_cq *mcq)
69662306a36Sopenharmony_ci{
69762306a36Sopenharmony_ci	return container_of(mcq, struct mlx4_ib_cq, mcq);
69862306a36Sopenharmony_ci}
69962306a36Sopenharmony_ci
70062306a36Sopenharmony_cistatic inline struct mlx4_ib_mr *to_mmr(struct ib_mr *ibmr)
70162306a36Sopenharmony_ci{
70262306a36Sopenharmony_ci	return container_of(ibmr, struct mlx4_ib_mr, ibmr);
70362306a36Sopenharmony_ci}
70462306a36Sopenharmony_ci
70562306a36Sopenharmony_cistatic inline struct mlx4_ib_mw *to_mmw(struct ib_mw *ibmw)
70662306a36Sopenharmony_ci{
70762306a36Sopenharmony_ci	return container_of(ibmw, struct mlx4_ib_mw, ibmw);
70862306a36Sopenharmony_ci}
70962306a36Sopenharmony_ci
71062306a36Sopenharmony_cistatic inline struct mlx4_ib_flow *to_mflow(struct ib_flow *ibflow)
71162306a36Sopenharmony_ci{
71262306a36Sopenharmony_ci	return container_of(ibflow, struct mlx4_ib_flow, ibflow);
71362306a36Sopenharmony_ci}
71462306a36Sopenharmony_ci
71562306a36Sopenharmony_cistatic inline struct mlx4_ib_qp *to_mqp(struct ib_qp *ibqp)
71662306a36Sopenharmony_ci{
71762306a36Sopenharmony_ci	return container_of(ibqp, struct mlx4_ib_qp, ibqp);
71862306a36Sopenharmony_ci}
71962306a36Sopenharmony_ci
72062306a36Sopenharmony_cistatic inline struct mlx4_ib_qp *to_mibqp(struct mlx4_qp *mqp)
72162306a36Sopenharmony_ci{
72262306a36Sopenharmony_ci	return container_of(mqp, struct mlx4_ib_qp, mqp);
72362306a36Sopenharmony_ci}
72462306a36Sopenharmony_ci
72562306a36Sopenharmony_cistatic inline struct mlx4_ib_srq *to_msrq(struct ib_srq *ibsrq)
72662306a36Sopenharmony_ci{
72762306a36Sopenharmony_ci	return container_of(ibsrq, struct mlx4_ib_srq, ibsrq);
72862306a36Sopenharmony_ci}
72962306a36Sopenharmony_ci
73062306a36Sopenharmony_cistatic inline struct mlx4_ib_srq *to_mibsrq(struct mlx4_srq *msrq)
73162306a36Sopenharmony_ci{
73262306a36Sopenharmony_ci	return container_of(msrq, struct mlx4_ib_srq, msrq);
73362306a36Sopenharmony_ci}
73462306a36Sopenharmony_ci
73562306a36Sopenharmony_cistatic inline struct mlx4_ib_ah *to_mah(struct ib_ah *ibah)
73662306a36Sopenharmony_ci{
73762306a36Sopenharmony_ci	return container_of(ibah, struct mlx4_ib_ah, ibah);
73862306a36Sopenharmony_ci}
73962306a36Sopenharmony_ci
74062306a36Sopenharmony_cistatic inline u8 mlx4_ib_bond_next_port(struct mlx4_ib_dev *dev)
74162306a36Sopenharmony_ci{
74262306a36Sopenharmony_ci	dev->bond_next_port = (dev->bond_next_port + 1) % dev->num_ports;
74362306a36Sopenharmony_ci
74462306a36Sopenharmony_ci	return dev->bond_next_port + 1;
74562306a36Sopenharmony_ci}
74662306a36Sopenharmony_ci
74762306a36Sopenharmony_ciint mlx4_ib_init_sriov(struct mlx4_ib_dev *dev);
74862306a36Sopenharmony_civoid mlx4_ib_close_sriov(struct mlx4_ib_dev *dev);
74962306a36Sopenharmony_ci
75062306a36Sopenharmony_ciint mlx4_ib_db_map_user(struct ib_udata *udata, unsigned long virt,
75162306a36Sopenharmony_ci			struct mlx4_db *db);
75262306a36Sopenharmony_civoid mlx4_ib_db_unmap_user(struct mlx4_ib_ucontext *context, struct mlx4_db *db);
75362306a36Sopenharmony_ci
75462306a36Sopenharmony_cistruct ib_mr *mlx4_ib_get_dma_mr(struct ib_pd *pd, int acc);
75562306a36Sopenharmony_ciint mlx4_ib_umem_write_mtt(struct mlx4_ib_dev *dev, struct mlx4_mtt *mtt,
75662306a36Sopenharmony_ci			   struct ib_umem *umem);
75762306a36Sopenharmony_cistruct ib_mr *mlx4_ib_reg_user_mr(struct ib_pd *pd, u64 start, u64 length,
75862306a36Sopenharmony_ci				  u64 virt_addr, int access_flags,
75962306a36Sopenharmony_ci				  struct ib_udata *udata);
76062306a36Sopenharmony_ciint mlx4_ib_dereg_mr(struct ib_mr *mr, struct ib_udata *udata);
76162306a36Sopenharmony_ciint mlx4_ib_alloc_mw(struct ib_mw *mw, struct ib_udata *udata);
76262306a36Sopenharmony_ciint mlx4_ib_dealloc_mw(struct ib_mw *mw);
76362306a36Sopenharmony_cistruct ib_mr *mlx4_ib_alloc_mr(struct ib_pd *pd, enum ib_mr_type mr_type,
76462306a36Sopenharmony_ci			       u32 max_num_sg);
76562306a36Sopenharmony_ciint mlx4_ib_map_mr_sg(struct ib_mr *ibmr, struct scatterlist *sg, int sg_nents,
76662306a36Sopenharmony_ci		      unsigned int *sg_offset);
76762306a36Sopenharmony_ciint mlx4_ib_modify_cq(struct ib_cq *cq, u16 cq_count, u16 cq_period);
76862306a36Sopenharmony_ciint mlx4_ib_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata);
76962306a36Sopenharmony_ciint mlx4_ib_create_cq(struct ib_cq *ibcq, const struct ib_cq_init_attr *attr,
77062306a36Sopenharmony_ci		      struct ib_udata *udata);
77162306a36Sopenharmony_ciint mlx4_ib_destroy_cq(struct ib_cq *cq, struct ib_udata *udata);
77262306a36Sopenharmony_ciint mlx4_ib_poll_cq(struct ib_cq *ibcq, int num_entries, struct ib_wc *wc);
77362306a36Sopenharmony_ciint mlx4_ib_arm_cq(struct ib_cq *cq, enum ib_cq_notify_flags flags);
77462306a36Sopenharmony_civoid __mlx4_ib_cq_clean(struct mlx4_ib_cq *cq, u32 qpn, struct mlx4_ib_srq *srq);
77562306a36Sopenharmony_civoid mlx4_ib_cq_clean(struct mlx4_ib_cq *cq, u32 qpn, struct mlx4_ib_srq *srq);
77662306a36Sopenharmony_ci
77762306a36Sopenharmony_ciint mlx4_ib_create_ah(struct ib_ah *ah, struct rdma_ah_init_attr *init_attr,
77862306a36Sopenharmony_ci		      struct ib_udata *udata);
77962306a36Sopenharmony_ciint mlx4_ib_create_ah_slave(struct ib_ah *ah, struct rdma_ah_attr *ah_attr,
78062306a36Sopenharmony_ci			    int slave_sgid_index, u8 *s_mac, u16 vlan_tag);
78162306a36Sopenharmony_ciint mlx4_ib_query_ah(struct ib_ah *ibah, struct rdma_ah_attr *ah_attr);
78262306a36Sopenharmony_cistatic inline int mlx4_ib_destroy_ah(struct ib_ah *ah, u32 flags)
78362306a36Sopenharmony_ci{
78462306a36Sopenharmony_ci	return 0;
78562306a36Sopenharmony_ci}
78662306a36Sopenharmony_ci
78762306a36Sopenharmony_ciint mlx4_ib_create_srq(struct ib_srq *srq, struct ib_srq_init_attr *init_attr,
78862306a36Sopenharmony_ci		       struct ib_udata *udata);
78962306a36Sopenharmony_ciint mlx4_ib_modify_srq(struct ib_srq *ibsrq, struct ib_srq_attr *attr,
79062306a36Sopenharmony_ci		       enum ib_srq_attr_mask attr_mask, struct ib_udata *udata);
79162306a36Sopenharmony_ciint mlx4_ib_query_srq(struct ib_srq *srq, struct ib_srq_attr *srq_attr);
79262306a36Sopenharmony_ciint mlx4_ib_destroy_srq(struct ib_srq *srq, struct ib_udata *udata);
79362306a36Sopenharmony_civoid mlx4_ib_free_srq_wqe(struct mlx4_ib_srq *srq, int wqe_index);
79462306a36Sopenharmony_ciint mlx4_ib_post_srq_recv(struct ib_srq *ibsrq, const struct ib_recv_wr *wr,
79562306a36Sopenharmony_ci			  const struct ib_recv_wr **bad_wr);
79662306a36Sopenharmony_ci
79762306a36Sopenharmony_ciint mlx4_ib_create_qp(struct ib_qp *qp, struct ib_qp_init_attr *init_attr,
79862306a36Sopenharmony_ci		      struct ib_udata *udata);
79962306a36Sopenharmony_ciint mlx4_ib_destroy_qp(struct ib_qp *qp, struct ib_udata *udata);
80062306a36Sopenharmony_civoid mlx4_ib_drain_sq(struct ib_qp *qp);
80162306a36Sopenharmony_civoid mlx4_ib_drain_rq(struct ib_qp *qp);
80262306a36Sopenharmony_ciint mlx4_ib_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr,
80362306a36Sopenharmony_ci		      int attr_mask, struct ib_udata *udata);
80462306a36Sopenharmony_ciint mlx4_ib_query_qp(struct ib_qp *ibqp, struct ib_qp_attr *qp_attr, int qp_attr_mask,
80562306a36Sopenharmony_ci		     struct ib_qp_init_attr *qp_init_attr);
80662306a36Sopenharmony_ciint mlx4_ib_post_send(struct ib_qp *ibqp, const struct ib_send_wr *wr,
80762306a36Sopenharmony_ci		      const struct ib_send_wr **bad_wr);
80862306a36Sopenharmony_ciint mlx4_ib_post_recv(struct ib_qp *ibqp, const struct ib_recv_wr *wr,
80962306a36Sopenharmony_ci		      const struct ib_recv_wr **bad_wr);
81062306a36Sopenharmony_ci
81162306a36Sopenharmony_ciint mlx4_MAD_IFC(struct mlx4_ib_dev *dev, int mad_ifc_flags,
81262306a36Sopenharmony_ci		 int port, const struct ib_wc *in_wc, const struct ib_grh *in_grh,
81362306a36Sopenharmony_ci		 const void *in_mad, void *response_mad);
81462306a36Sopenharmony_ciint mlx4_ib_process_mad(struct ib_device *ibdev, int mad_flags, u32 port_num,
81562306a36Sopenharmony_ci			const struct ib_wc *in_wc, const struct ib_grh *in_grh,
81662306a36Sopenharmony_ci			const struct ib_mad *in, struct ib_mad *out,
81762306a36Sopenharmony_ci			size_t *out_mad_size, u16 *out_mad_pkey_index);
81862306a36Sopenharmony_ciint mlx4_ib_mad_init(struct mlx4_ib_dev *dev);
81962306a36Sopenharmony_civoid mlx4_ib_mad_cleanup(struct mlx4_ib_dev *dev);
82062306a36Sopenharmony_ci
82162306a36Sopenharmony_ciint __mlx4_ib_query_port(struct ib_device *ibdev, u32 port,
82262306a36Sopenharmony_ci			 struct ib_port_attr *props, int netw_view);
82362306a36Sopenharmony_ciint __mlx4_ib_query_pkey(struct ib_device *ibdev, u32 port, u16 index,
82462306a36Sopenharmony_ci			 u16 *pkey, int netw_view);
82562306a36Sopenharmony_ci
82662306a36Sopenharmony_ciint __mlx4_ib_query_gid(struct ib_device *ibdev, u32 port, int index,
82762306a36Sopenharmony_ci			union ib_gid *gid, int netw_view);
82862306a36Sopenharmony_ci
82962306a36Sopenharmony_cistatic inline bool mlx4_ib_ah_grh_present(struct mlx4_ib_ah *ah)
83062306a36Sopenharmony_ci{
83162306a36Sopenharmony_ci	u32 port = be32_to_cpu(ah->av.ib.port_pd) >> 24 & 3;
83262306a36Sopenharmony_ci
83362306a36Sopenharmony_ci	if (rdma_port_get_link_layer(ah->ibah.device, port) == IB_LINK_LAYER_ETHERNET)
83462306a36Sopenharmony_ci		return true;
83562306a36Sopenharmony_ci
83662306a36Sopenharmony_ci	return !!(ah->av.ib.g_slid & 0x80);
83762306a36Sopenharmony_ci}
83862306a36Sopenharmony_ci
83962306a36Sopenharmony_ciint mlx4_ib_mcg_port_init(struct mlx4_ib_demux_ctx *ctx);
84062306a36Sopenharmony_civoid mlx4_ib_mcg_port_cleanup(struct mlx4_ib_demux_ctx *ctx, int destroy_wq);
84162306a36Sopenharmony_civoid clean_vf_mcast(struct mlx4_ib_demux_ctx *ctx, int slave);
84262306a36Sopenharmony_ciint mlx4_ib_mcg_init(void);
84362306a36Sopenharmony_civoid mlx4_ib_mcg_destroy(void);
84462306a36Sopenharmony_ci
84562306a36Sopenharmony_ciint mlx4_ib_find_real_gid(struct ib_device *ibdev, u32 port, __be64 guid);
84662306a36Sopenharmony_ci
84762306a36Sopenharmony_ciint mlx4_ib_mcg_multiplex_handler(struct ib_device *ibdev, int port, int slave,
84862306a36Sopenharmony_ci				  struct ib_sa_mad *sa_mad);
84962306a36Sopenharmony_ciint mlx4_ib_mcg_demux_handler(struct ib_device *ibdev, int port, int slave,
85062306a36Sopenharmony_ci			      struct ib_sa_mad *mad);
85162306a36Sopenharmony_ci
85262306a36Sopenharmony_ciint mlx4_ib_add_mc(struct mlx4_ib_dev *mdev, struct mlx4_ib_qp *mqp,
85362306a36Sopenharmony_ci		   union ib_gid *gid);
85462306a36Sopenharmony_ci
85562306a36Sopenharmony_civoid mlx4_ib_dispatch_event(struct mlx4_ib_dev *dev, u32 port_num,
85662306a36Sopenharmony_ci			    enum ib_event_type type);
85762306a36Sopenharmony_ci
85862306a36Sopenharmony_civoid mlx4_ib_tunnels_update_work(struct work_struct *work);
85962306a36Sopenharmony_ci
86062306a36Sopenharmony_ciint mlx4_ib_send_to_slave(struct mlx4_ib_dev *dev, int slave, u32 port,
86162306a36Sopenharmony_ci			  enum ib_qp_type qpt, struct ib_wc *wc,
86262306a36Sopenharmony_ci			  struct ib_grh *grh, struct ib_mad *mad);
86362306a36Sopenharmony_ci
86462306a36Sopenharmony_ciint mlx4_ib_send_to_wire(struct mlx4_ib_dev *dev, int slave, u32 port,
86562306a36Sopenharmony_ci			 enum ib_qp_type dest_qpt, u16 pkey_index, u32 remote_qpn,
86662306a36Sopenharmony_ci			 u32 qkey, struct rdma_ah_attr *attr, u8 *s_mac,
86762306a36Sopenharmony_ci			 u16 vlan_id, struct ib_mad *mad);
86862306a36Sopenharmony_ci
86962306a36Sopenharmony_ci__be64 mlx4_ib_get_new_demux_tid(struct mlx4_ib_demux_ctx *ctx);
87062306a36Sopenharmony_ci
87162306a36Sopenharmony_ciint mlx4_ib_demux_cm_handler(struct ib_device *ibdev, int port, int *slave,
87262306a36Sopenharmony_ci		struct ib_mad *mad);
87362306a36Sopenharmony_ci
87462306a36Sopenharmony_ciint mlx4_ib_multiplex_cm_handler(struct ib_device *ibdev, int port, int slave_id,
87562306a36Sopenharmony_ci		struct ib_mad *mad);
87662306a36Sopenharmony_ci
87762306a36Sopenharmony_civoid mlx4_ib_cm_paravirt_init(struct mlx4_ib_dev *dev);
87862306a36Sopenharmony_civoid mlx4_ib_cm_paravirt_clean(struct mlx4_ib_dev *dev, int slave_id);
87962306a36Sopenharmony_ci
88062306a36Sopenharmony_ci/* alias guid support */
88162306a36Sopenharmony_civoid mlx4_ib_init_alias_guid_work(struct mlx4_ib_dev *dev, int port);
88262306a36Sopenharmony_ciint mlx4_ib_init_alias_guid_service(struct mlx4_ib_dev *dev);
88362306a36Sopenharmony_civoid mlx4_ib_destroy_alias_guid_service(struct mlx4_ib_dev *dev);
88462306a36Sopenharmony_civoid mlx4_ib_invalidate_all_guid_record(struct mlx4_ib_dev *dev, int port);
88562306a36Sopenharmony_ci
88662306a36Sopenharmony_civoid mlx4_ib_notify_slaves_on_guid_change(struct mlx4_ib_dev *dev,
88762306a36Sopenharmony_ci					  int block_num,
88862306a36Sopenharmony_ci					  u32 port_num, u8 *p_data);
88962306a36Sopenharmony_ci
89062306a36Sopenharmony_civoid mlx4_ib_update_cache_on_guid_change(struct mlx4_ib_dev *dev,
89162306a36Sopenharmony_ci					 int block_num, u32 port_num,
89262306a36Sopenharmony_ci					 u8 *p_data);
89362306a36Sopenharmony_ci
89462306a36Sopenharmony_ciint add_sysfs_port_mcg_attr(struct mlx4_ib_dev *device, int port_num,
89562306a36Sopenharmony_ci			    struct attribute *attr);
89662306a36Sopenharmony_civoid del_sysfs_port_mcg_attr(struct mlx4_ib_dev *device, int port_num,
89762306a36Sopenharmony_ci			     struct attribute *attr);
89862306a36Sopenharmony_ciib_sa_comp_mask mlx4_ib_get_aguid_comp_mask_from_ix(int index);
89962306a36Sopenharmony_civoid mlx4_ib_slave_alias_guid_event(struct mlx4_ib_dev *dev, int slave,
90062306a36Sopenharmony_ci				    int port, int slave_init);
90162306a36Sopenharmony_ci
90262306a36Sopenharmony_ciint mlx4_ib_device_register_sysfs(struct mlx4_ib_dev *device) ;
90362306a36Sopenharmony_ci
90462306a36Sopenharmony_civoid mlx4_ib_device_unregister_sysfs(struct mlx4_ib_dev *device);
90562306a36Sopenharmony_ci
90662306a36Sopenharmony_ci__be64 mlx4_ib_gen_node_guid(void);
90762306a36Sopenharmony_ci
90862306a36Sopenharmony_ciint mlx4_ib_steer_qp_alloc(struct mlx4_ib_dev *dev, int count, int *qpn);
90962306a36Sopenharmony_civoid mlx4_ib_steer_qp_free(struct mlx4_ib_dev *dev, u32 qpn, int count);
91062306a36Sopenharmony_ciint mlx4_ib_steer_qp_reg(struct mlx4_ib_dev *mdev, struct mlx4_ib_qp *mqp,
91162306a36Sopenharmony_ci			 int is_attach);
91262306a36Sopenharmony_cistruct ib_mr *mlx4_ib_rereg_user_mr(struct ib_mr *mr, int flags, u64 start,
91362306a36Sopenharmony_ci				    u64 length, u64 virt_addr,
91462306a36Sopenharmony_ci				    int mr_access_flags, struct ib_pd *pd,
91562306a36Sopenharmony_ci				    struct ib_udata *udata);
91662306a36Sopenharmony_ciint mlx4_ib_gid_index_to_real_index(struct mlx4_ib_dev *ibdev,
91762306a36Sopenharmony_ci				    const struct ib_gid_attr *attr);
91862306a36Sopenharmony_ci
91962306a36Sopenharmony_civoid mlx4_sched_ib_sl2vl_update_work(struct mlx4_ib_dev *ibdev,
92062306a36Sopenharmony_ci				     int port);
92162306a36Sopenharmony_ci
92262306a36Sopenharmony_civoid mlx4_ib_sl2vl_update(struct mlx4_ib_dev *mdev, int port);
92362306a36Sopenharmony_ci
92462306a36Sopenharmony_cistruct ib_wq *mlx4_ib_create_wq(struct ib_pd *pd,
92562306a36Sopenharmony_ci				struct ib_wq_init_attr *init_attr,
92662306a36Sopenharmony_ci				struct ib_udata *udata);
92762306a36Sopenharmony_ciint mlx4_ib_destroy_wq(struct ib_wq *wq, struct ib_udata *udata);
92862306a36Sopenharmony_ciint mlx4_ib_modify_wq(struct ib_wq *wq, struct ib_wq_attr *wq_attr,
92962306a36Sopenharmony_ci		      u32 wq_attr_mask, struct ib_udata *udata);
93062306a36Sopenharmony_ci
93162306a36Sopenharmony_ciint mlx4_ib_create_rwq_ind_table(struct ib_rwq_ind_table *ib_rwq_ind_tbl,
93262306a36Sopenharmony_ci				 struct ib_rwq_ind_table_init_attr *init_attr,
93362306a36Sopenharmony_ci				 struct ib_udata *udata);
93462306a36Sopenharmony_cistatic inline int
93562306a36Sopenharmony_cimlx4_ib_destroy_rwq_ind_table(struct ib_rwq_ind_table *wq_ind_table)
93662306a36Sopenharmony_ci{
93762306a36Sopenharmony_ci	return 0;
93862306a36Sopenharmony_ci}
93962306a36Sopenharmony_ciint mlx4_ib_umem_calc_optimal_mtt_size(struct ib_umem *umem, u64 start_va,
94062306a36Sopenharmony_ci				       int *num_of_mtts);
94162306a36Sopenharmony_ci
94262306a36Sopenharmony_ciint mlx4_ib_cm_init(void);
94362306a36Sopenharmony_civoid mlx4_ib_cm_destroy(void);
94462306a36Sopenharmony_ci
94562306a36Sopenharmony_ciint mlx4_ib_qp_event_init(void);
94662306a36Sopenharmony_civoid mlx4_ib_qp_event_cleanup(void);
94762306a36Sopenharmony_ci
94862306a36Sopenharmony_ci#endif /* MLX4_IB_H */
949