xref: /freebsd/sys/dev/mlx4/mlx4_core/mlx4.h (revision b18c5108)
197549c34SHans Petter Selasky /*
297549c34SHans Petter Selasky  * Copyright (c) 2004, 2005 Topspin Communications.  All rights reserved.
397549c34SHans Petter Selasky  * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
497549c34SHans Petter Selasky  * Copyright (c) 2005, 2006, 2007 Cisco Systems.  All rights reserved.
597549c34SHans Petter Selasky  * Copyright (c) 2005, 2006, 2007, 2008, 2014 Mellanox Technologies. All rights reserved.
697549c34SHans Petter Selasky  * Copyright (c) 2004 Voltaire, Inc. All rights reserved.
797549c34SHans Petter Selasky  *
897549c34SHans Petter Selasky  * This software is available to you under a choice of one of two
997549c34SHans Petter Selasky  * licenses.  You may choose to be licensed under the terms of the GNU
1097549c34SHans Petter Selasky  * General Public License (GPL) Version 2, available from the file
1197549c34SHans Petter Selasky  * COPYING in the main directory of this source tree, or the
1297549c34SHans Petter Selasky  * OpenIB.org BSD license below:
1397549c34SHans Petter Selasky  *
1497549c34SHans Petter Selasky  *     Redistribution and use in source and binary forms, with or
1597549c34SHans Petter Selasky  *     without modification, are permitted provided that the following
1697549c34SHans Petter Selasky  *     conditions are met:
1797549c34SHans Petter Selasky  *
1897549c34SHans Petter Selasky  *      - Redistributions of source code must retain the above
1997549c34SHans Petter Selasky  *        copyright notice, this list of conditions and the following
2097549c34SHans Petter Selasky  *        disclaimer.
2197549c34SHans Petter Selasky  *
2297549c34SHans Petter Selasky  *      - Redistributions in binary form must reproduce the above
2397549c34SHans Petter Selasky  *        copyright notice, this list of conditions and the following
2497549c34SHans Petter Selasky  *        disclaimer in the documentation and/or other materials
2597549c34SHans Petter Selasky  *        provided with the distribution.
2697549c34SHans Petter Selasky  *
2797549c34SHans Petter Selasky  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
2897549c34SHans Petter Selasky  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
2997549c34SHans Petter Selasky  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
3097549c34SHans Petter Selasky  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
3197549c34SHans Petter Selasky  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
3297549c34SHans Petter Selasky  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
3397549c34SHans Petter Selasky  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
3497549c34SHans Petter Selasky  * SOFTWARE.
3597549c34SHans Petter Selasky  */
3697549c34SHans Petter Selasky 
3797549c34SHans Petter Selasky #ifndef MLX4_H
3897549c34SHans Petter Selasky #define MLX4_H
3997549c34SHans Petter Selasky 
4097549c34SHans Petter Selasky #include <linux/mutex.h>
4197549c34SHans Petter Selasky #include <linux/radix-tree.h>
4297549c34SHans Petter Selasky #include <linux/rbtree.h>
4397549c34SHans Petter Selasky #include <linux/timer.h>
4497549c34SHans Petter Selasky #include <linux/semaphore.h>
4597549c34SHans Petter Selasky #include <linux/workqueue.h>
4697549c34SHans Petter Selasky #include <linux/device.h>
47c3191c2eSHans Petter Selasky #include <linux/rwsem.h>
4897549c34SHans Petter Selasky #include <dev/mlx4/device.h>
4997549c34SHans Petter Selasky #include <dev/mlx4/driver.h>
5097549c34SHans Petter Selasky #include <dev/mlx4/doorbell.h>
5197549c34SHans Petter Selasky #include <dev/mlx4/cmd.h>
52c3191c2eSHans Petter Selasky #include <dev/mlx4/mlx4_core/fw_qos.h>
5397549c34SHans Petter Selasky 
5497549c34SHans Petter Selasky #define DRV_NAME	"mlx4_core"
5597549c34SHans Petter Selasky #define PFX		DRV_NAME ": "
569a47ae04SHans Petter Selasky #ifndef DRV_VERSION
57b18c5108SHans Petter Selasky #define DRV_VERSION	"3.7.1"
589a47ae04SHans Petter Selasky #endif
59b18c5108SHans Petter Selasky #define DRV_RELDATE	"November 2021"
6097549c34SHans Petter Selasky 
6197549c34SHans Petter Selasky #define MLX4_FS_UDP_UC_EN		(1 << 1)
6297549c34SHans Petter Selasky #define MLX4_FS_TCP_UC_EN		(1 << 2)
6397549c34SHans Petter Selasky #define MLX4_FS_NUM_OF_L2_ADDR		8
6497549c34SHans Petter Selasky #define MLX4_FS_MGM_LOG_ENTRY_SIZE	7
6597549c34SHans Petter Selasky #define MLX4_FS_NUM_MCG			(1 << 17)
6697549c34SHans Petter Selasky 
67c3191c2eSHans Petter Selasky #define INIT_HCA_TPT_MW_ENABLE          (1 << 7)
6897549c34SHans Petter Selasky 
69c3191c2eSHans Petter Selasky #define MLX4_QUERY_IF_STAT_RESET	BIT(31)
7097549c34SHans Petter Selasky 
7197549c34SHans Petter Selasky enum {
7297549c34SHans Petter Selasky 	MLX4_HCR_BASE		= 0x80680,
7397549c34SHans Petter Selasky 	MLX4_HCR_SIZE		= 0x0001c,
7497549c34SHans Petter Selasky 	MLX4_CLR_INT_SIZE	= 0x00008,
7597549c34SHans Petter Selasky 	MLX4_SLAVE_COMM_BASE	= 0x0,
7697549c34SHans Petter Selasky 	MLX4_COMM_PAGESIZE	= 0x1000,
77c3191c2eSHans Petter Selasky 	MLX4_CLOCK_SIZE		= 0x00008,
78c3191c2eSHans Petter Selasky 	MLX4_COMM_CHAN_CAPS	= 0x8,
79c3191c2eSHans Petter Selasky 	MLX4_COMM_CHAN_FLAGS	= 0xc
8097549c34SHans Petter Selasky };
8197549c34SHans Petter Selasky 
8297549c34SHans Petter Selasky enum {
8397549c34SHans Petter Selasky 	MLX4_DEFAULT_MGM_LOG_ENTRY_SIZE = 10,
8497549c34SHans Petter Selasky 	MLX4_MIN_MGM_LOG_ENTRY_SIZE = 7,
8597549c34SHans Petter Selasky 	MLX4_MAX_MGM_LOG_ENTRY_SIZE = 12,
8697549c34SHans Petter Selasky 	MLX4_MAX_QP_PER_MGM = 4 * ((1 << MLX4_MAX_MGM_LOG_ENTRY_SIZE) / 16 - 2),
87c3191c2eSHans Petter Selasky 	MLX4_MTT_ENTRY_PER_SEG	= 8,
8897549c34SHans Petter Selasky };
8997549c34SHans Petter Selasky 
9097549c34SHans Petter Selasky enum {
9197549c34SHans Petter Selasky 	MLX4_NUM_PDS		= 1 << 15
9297549c34SHans Petter Selasky };
9397549c34SHans Petter Selasky 
9497549c34SHans Petter Selasky enum {
9597549c34SHans Petter Selasky 	MLX4_CMPT_TYPE_QP	= 0,
9697549c34SHans Petter Selasky 	MLX4_CMPT_TYPE_SRQ	= 1,
9797549c34SHans Petter Selasky 	MLX4_CMPT_TYPE_CQ	= 2,
9897549c34SHans Petter Selasky 	MLX4_CMPT_TYPE_EQ	= 3,
9997549c34SHans Petter Selasky 	MLX4_CMPT_NUM_TYPE
10097549c34SHans Petter Selasky };
10197549c34SHans Petter Selasky 
10297549c34SHans Petter Selasky enum {
10397549c34SHans Petter Selasky 	MLX4_CMPT_SHIFT		= 24,
10497549c34SHans Petter Selasky 	MLX4_NUM_CMPTS		= MLX4_CMPT_NUM_TYPE << MLX4_CMPT_SHIFT
10597549c34SHans Petter Selasky };
10697549c34SHans Petter Selasky 
10797549c34SHans Petter Selasky enum mlx4_mpt_state {
10897549c34SHans Petter Selasky 	MLX4_MPT_DISABLED = 0,
10997549c34SHans Petter Selasky 	MLX4_MPT_EN_HW,
11097549c34SHans Petter Selasky 	MLX4_MPT_EN_SW
11197549c34SHans Petter Selasky };
11297549c34SHans Petter Selasky 
11397549c34SHans Petter Selasky #define MLX4_COMM_TIME		10000
114c3191c2eSHans Petter Selasky #define MLX4_COMM_OFFLINE_TIME_OUT 30000
115c3191c2eSHans Petter Selasky #define MLX4_COMM_CMD_NA_OP    0x0
116c3191c2eSHans Petter Selasky 
117c3191c2eSHans Petter Selasky 
11897549c34SHans Petter Selasky enum {
11997549c34SHans Petter Selasky 	MLX4_COMM_CMD_RESET,
12097549c34SHans Petter Selasky 	MLX4_COMM_CMD_VHCR0,
12197549c34SHans Petter Selasky 	MLX4_COMM_CMD_VHCR1,
12297549c34SHans Petter Selasky 	MLX4_COMM_CMD_VHCR2,
12397549c34SHans Petter Selasky 	MLX4_COMM_CMD_VHCR_EN,
12497549c34SHans Petter Selasky 	MLX4_COMM_CMD_VHCR_POST,
12597549c34SHans Petter Selasky 	MLX4_COMM_CMD_FLR = 254
12697549c34SHans Petter Selasky };
12797549c34SHans Petter Selasky 
128c3191c2eSHans Petter Selasky enum {
129c3191c2eSHans Petter Selasky 	MLX4_VF_SMI_DISABLED,
130c3191c2eSHans Petter Selasky 	MLX4_VF_SMI_ENABLED
131c3191c2eSHans Petter Selasky };
132c3191c2eSHans Petter Selasky 
13397549c34SHans Petter Selasky /*The flag indicates that the slave should delay the RESET cmd*/
13497549c34SHans Petter Selasky #define MLX4_DELAY_RESET_SLAVE 0xbbbbbbb
13597549c34SHans Petter Selasky /*indicates how many retries will be done if we are in the middle of FLR*/
13697549c34SHans Petter Selasky #define NUM_OF_RESET_RETRIES	10
13797549c34SHans Petter Selasky #define SLEEP_TIME_IN_RESET	(2 * 1000)
13897549c34SHans Petter Selasky enum mlx4_resource {
13997549c34SHans Petter Selasky 	RES_QP,
14097549c34SHans Petter Selasky 	RES_CQ,
14197549c34SHans Petter Selasky 	RES_SRQ,
14297549c34SHans Petter Selasky 	RES_XRCD,
14397549c34SHans Petter Selasky 	RES_MPT,
14497549c34SHans Petter Selasky 	RES_MTT,
14597549c34SHans Petter Selasky 	RES_MAC,
14697549c34SHans Petter Selasky 	RES_VLAN,
14797549c34SHans Petter Selasky 	RES_NPORT_ID,
14897549c34SHans Petter Selasky 	RES_COUNTER,
14997549c34SHans Petter Selasky 	RES_FS_RULE,
15097549c34SHans Petter Selasky 	RES_EQ,
15197549c34SHans Petter Selasky 	MLX4_NUM_OF_RESOURCE_TYPE
15297549c34SHans Petter Selasky };
15397549c34SHans Petter Selasky 
15497549c34SHans Petter Selasky enum mlx4_alloc_mode {
15597549c34SHans Petter Selasky 	RES_OP_RESERVE,
15697549c34SHans Petter Selasky 	RES_OP_RESERVE_AND_MAP,
15797549c34SHans Petter Selasky 	RES_OP_MAP_ICM,
15897549c34SHans Petter Selasky };
15997549c34SHans Petter Selasky 
16097549c34SHans Petter Selasky enum mlx4_res_tracker_free_type {
16197549c34SHans Petter Selasky 	RES_TR_FREE_ALL,
16297549c34SHans Petter Selasky 	RES_TR_FREE_SLAVES_ONLY,
16397549c34SHans Petter Selasky 	RES_TR_FREE_STRUCTS_ONLY,
16497549c34SHans Petter Selasky };
16597549c34SHans Petter Selasky 
16697549c34SHans Petter Selasky /*
16797549c34SHans Petter Selasky  *Virtual HCR structures.
16897549c34SHans Petter Selasky  * mlx4_vhcr is the sw representation, in machine endianness
16997549c34SHans Petter Selasky  *
17097549c34SHans Petter Selasky  * mlx4_vhcr_cmd is the formalized structure, the one that is passed
17197549c34SHans Petter Selasky  * to FW to go through communication channel.
17297549c34SHans Petter Selasky  * It is big endian, and has the same structure as the physical HCR
17397549c34SHans Petter Selasky  * used by command interface
17497549c34SHans Petter Selasky  */
17597549c34SHans Petter Selasky struct mlx4_vhcr {
17697549c34SHans Petter Selasky 	u64	in_param;
17797549c34SHans Petter Selasky 	u64	out_param;
17897549c34SHans Petter Selasky 	u32	in_modifier;
17997549c34SHans Petter Selasky 	u32	errno;
18097549c34SHans Petter Selasky 	u16	op;
18197549c34SHans Petter Selasky 	u16	token;
18297549c34SHans Petter Selasky 	u8	op_modifier;
18397549c34SHans Petter Selasky 	u8	e_bit;
18497549c34SHans Petter Selasky };
18597549c34SHans Petter Selasky 
18697549c34SHans Petter Selasky struct mlx4_vhcr_cmd {
18797549c34SHans Petter Selasky 	__be64 in_param;
18897549c34SHans Petter Selasky 	__be32 in_modifier;
18997549c34SHans Petter Selasky 	u32 reserved1;
19097549c34SHans Petter Selasky 	__be64 out_param;
19197549c34SHans Petter Selasky 	__be16 token;
19297549c34SHans Petter Selasky 	u16 reserved;
19397549c34SHans Petter Selasky 	u8 status;
19497549c34SHans Petter Selasky 	u8 flags;
19597549c34SHans Petter Selasky 	__be16 opcode;
196c3191c2eSHans Petter Selasky };
19797549c34SHans Petter Selasky 
19897549c34SHans Petter Selasky struct mlx4_cmd_info {
19997549c34SHans Petter Selasky 	u16 opcode;
20097549c34SHans Petter Selasky 	bool has_inbox;
20197549c34SHans Petter Selasky 	bool has_outbox;
20297549c34SHans Petter Selasky 	bool out_is_imm;
20397549c34SHans Petter Selasky 	bool encode_slave_id;
20497549c34SHans Petter Selasky 	int (*verify)(struct mlx4_dev *dev, int slave, struct mlx4_vhcr *vhcr,
20597549c34SHans Petter Selasky 		      struct mlx4_cmd_mailbox *inbox);
20697549c34SHans Petter Selasky 	int (*wrapper)(struct mlx4_dev *dev, int slave, struct mlx4_vhcr *vhcr,
20797549c34SHans Petter Selasky 		       struct mlx4_cmd_mailbox *inbox,
20897549c34SHans Petter Selasky 		       struct mlx4_cmd_mailbox *outbox,
20997549c34SHans Petter Selasky 		       struct mlx4_cmd_info *cmd);
21097549c34SHans Petter Selasky };
21197549c34SHans Petter Selasky 
21297549c34SHans Petter Selasky #ifdef CONFIG_MLX4_DEBUG
21397549c34SHans Petter Selasky extern int mlx4_debug_level;
21497549c34SHans Petter Selasky #else /* CONFIG_MLX4_DEBUG */
21597549c34SHans Petter Selasky #define mlx4_debug_level	(0)
21697549c34SHans Petter Selasky #endif /* CONFIG_MLX4_DEBUG */
21797549c34SHans Petter Selasky 
218c3191c2eSHans Petter Selasky #define mlx4_dbg(mdev, format, ...)					\
21997549c34SHans Petter Selasky do {									\
22097549c34SHans Petter Selasky 	if (mlx4_debug_level)						\
221c3191c2eSHans Petter Selasky 		dev_printk(KERN_DEBUG,					\
222c3191c2eSHans Petter Selasky 			   &(mdev)->persist->pdev->dev, format,		\
223c3191c2eSHans Petter Selasky 			   ##__VA_ARGS__);				\
22497549c34SHans Petter Selasky } while (0)
22597549c34SHans Petter Selasky 
226c3191c2eSHans Petter Selasky #define mlx4_err(mdev, format, ...)					\
227c3191c2eSHans Petter Selasky 	dev_err(&(mdev)->persist->pdev->dev, format, ##__VA_ARGS__)
228c3191c2eSHans Petter Selasky #define mlx4_info(mdev, format, ...)					\
229c3191c2eSHans Petter Selasky 	dev_info(&(mdev)->persist->pdev->dev, format, ##__VA_ARGS__)
230c3191c2eSHans Petter Selasky #define mlx4_warn(mdev, format, ...)					\
231c3191c2eSHans Petter Selasky 	dev_warn(&(mdev)->persist->pdev->dev, format, ##__VA_ARGS__)
23297549c34SHans Petter Selasky 
23397549c34SHans Petter Selasky extern int mlx4_log_num_mgm_entry_size;
23497549c34SHans Petter Selasky extern int log_mtts_per_seg;
235c3191c2eSHans Petter Selasky extern int mlx4_internal_err_reset;
23697549c34SHans Petter Selasky 
237c3191c2eSHans Petter Selasky #define MLX4_MAX_NUM_SLAVES	(min(MLX4_MAX_NUM_PF + MLX4_MAX_NUM_VF, \
238c3191c2eSHans Petter Selasky 				     MLX4_MFUNC_MAX))
23997549c34SHans Petter Selasky #define ALL_SLAVES 0xff
24097549c34SHans Petter Selasky 
24197549c34SHans Petter Selasky struct mlx4_bitmap {
24297549c34SHans Petter Selasky 	u32			last;
24397549c34SHans Petter Selasky 	u32			top;
24497549c34SHans Petter Selasky 	u32			max;
24597549c34SHans Petter Selasky 	u32                     reserved_top;
24697549c34SHans Petter Selasky 	u32			mask;
24797549c34SHans Petter Selasky 	u32			avail;
248c3191c2eSHans Petter Selasky 	u32			effective_len;
24997549c34SHans Petter Selasky 	spinlock_t		lock;
25097549c34SHans Petter Selasky 	unsigned long	       *table;
25197549c34SHans Petter Selasky };
25297549c34SHans Petter Selasky 
25397549c34SHans Petter Selasky struct mlx4_buddy {
25497549c34SHans Petter Selasky 	unsigned long	      **bits;
25597549c34SHans Petter Selasky 	unsigned int	       *num_free;
25697549c34SHans Petter Selasky 	u32			max_order;
25797549c34SHans Petter Selasky 	spinlock_t		lock;
25897549c34SHans Petter Selasky };
25997549c34SHans Petter Selasky 
26097549c34SHans Petter Selasky struct mlx4_icm;
26197549c34SHans Petter Selasky 
26297549c34SHans Petter Selasky struct mlx4_icm_table {
26397549c34SHans Petter Selasky 	u64			virt;
26497549c34SHans Petter Selasky 	int			num_icm;
26597549c34SHans Petter Selasky 	u32			num_obj;
26697549c34SHans Petter Selasky 	int			obj_size;
26797549c34SHans Petter Selasky 	int			lowmem;
26897549c34SHans Petter Selasky 	int			coherent;
26997549c34SHans Petter Selasky 	struct mutex		mutex;
27097549c34SHans Petter Selasky 	struct mlx4_icm	      **icm;
27197549c34SHans Petter Selasky };
27297549c34SHans Petter Selasky 
27397549c34SHans Petter Selasky #define MLX4_MPT_FLAG_SW_OWNS	    (0xfUL << 28)
27497549c34SHans Petter Selasky #define MLX4_MPT_FLAG_FREE	    (0x3UL << 28)
27597549c34SHans Petter Selasky #define MLX4_MPT_FLAG_MIO	    (1 << 17)
27697549c34SHans Petter Selasky #define MLX4_MPT_FLAG_BIND_ENABLE   (1 << 15)
27797549c34SHans Petter Selasky #define MLX4_MPT_FLAG_PHYSICAL	    (1 <<  9)
27897549c34SHans Petter Selasky #define MLX4_MPT_FLAG_REGION	    (1 <<  8)
27997549c34SHans Petter Selasky 
280c3191c2eSHans Petter Selasky #define MLX4_MPT_PD_MASK	    (0x1FFFFUL)
281c3191c2eSHans Petter Selasky #define MLX4_MPT_PD_VF_MASK	    (0xFE0000UL)
28297549c34SHans Petter Selasky #define MLX4_MPT_PD_FLAG_FAST_REG   (1 << 27)
28397549c34SHans Petter Selasky #define MLX4_MPT_PD_FLAG_RAE	    (1 << 28)
28497549c34SHans Petter Selasky #define MLX4_MPT_PD_FLAG_EN_INV	    (3 << 24)
28597549c34SHans Petter Selasky 
28697549c34SHans Petter Selasky #define MLX4_MPT_QP_FLAG_BOUND_QP   (1 << 7)
28797549c34SHans Petter Selasky 
28897549c34SHans Petter Selasky #define MLX4_MPT_STATUS_SW		0xF0
28997549c34SHans Petter Selasky #define MLX4_MPT_STATUS_HW		0x00
29097549c34SHans Petter Selasky 
291c3191c2eSHans Petter Selasky #define MLX4_CQE_SIZE_MASK_STRIDE	0x3
292c3191c2eSHans Petter Selasky #define MLX4_EQE_SIZE_MASK_STRIDE	0x30
293c3191c2eSHans Petter Selasky 
294c3191c2eSHans Petter Selasky #define MLX4_EQ_ASYNC			0
295c3191c2eSHans Petter Selasky #define MLX4_EQ_TO_CQ_VECTOR(vector)	((vector) - \
296c3191c2eSHans Petter Selasky 					 !!((int)(vector) >= MLX4_EQ_ASYNC))
297c3191c2eSHans Petter Selasky #define MLX4_CQ_TO_EQ_VECTOR(vector)	((vector) + \
298c3191c2eSHans Petter Selasky 					 !!((int)(vector) >= MLX4_EQ_ASYNC))
299c3191c2eSHans Petter Selasky 
30097549c34SHans Petter Selasky /*
30197549c34SHans Petter Selasky  * Must be packed because mtt_seg is 64 bits but only aligned to 32 bits.
30297549c34SHans Petter Selasky  */
30397549c34SHans Petter Selasky struct mlx4_mpt_entry {
30497549c34SHans Petter Selasky 	__be32 flags;
30597549c34SHans Petter Selasky 	__be32 qpn;
30697549c34SHans Petter Selasky 	__be32 key;
30797549c34SHans Petter Selasky 	__be32 pd_flags;
30897549c34SHans Petter Selasky 	__be64 start;
30997549c34SHans Petter Selasky 	__be64 length;
31097549c34SHans Petter Selasky 	__be32 lkey;
31197549c34SHans Petter Selasky 	__be32 win_cnt;
31297549c34SHans Petter Selasky 	u8	reserved1[3];
31397549c34SHans Petter Selasky 	u8	mtt_rep;
31497549c34SHans Petter Selasky 	__be64 mtt_addr;
31597549c34SHans Petter Selasky 	__be32 mtt_sz;
31697549c34SHans Petter Selasky 	__be32 entity_size;
31797549c34SHans Petter Selasky 	__be32 first_byte_offset;
31897549c34SHans Petter Selasky } __packed;
31997549c34SHans Petter Selasky 
32097549c34SHans Petter Selasky /*
32197549c34SHans Petter Selasky  * Must be packed because start is 64 bits but only aligned to 32 bits.
32297549c34SHans Petter Selasky  */
32397549c34SHans Petter Selasky struct mlx4_eq_context {
32497549c34SHans Petter Selasky 	__be32			flags;
32597549c34SHans Petter Selasky 	u16			reserved1[3];
32697549c34SHans Petter Selasky 	__be16			page_offset;
32797549c34SHans Petter Selasky 	u8			log_eq_size;
32897549c34SHans Petter Selasky 	u8			reserved2[4];
32997549c34SHans Petter Selasky 	u8			eq_period;
33097549c34SHans Petter Selasky 	u8			reserved3;
33197549c34SHans Petter Selasky 	u8			eq_max_count;
33297549c34SHans Petter Selasky 	u8			reserved4[3];
33397549c34SHans Petter Selasky 	u8			intr;
33497549c34SHans Petter Selasky 	u8			log_page_size;
33597549c34SHans Petter Selasky 	u8			reserved5[2];
33697549c34SHans Petter Selasky 	u8			mtt_base_addr_h;
33797549c34SHans Petter Selasky 	__be32			mtt_base_addr_l;
33897549c34SHans Petter Selasky 	u32			reserved6[2];
33997549c34SHans Petter Selasky 	__be32			consumer_index;
34097549c34SHans Petter Selasky 	__be32			producer_index;
34197549c34SHans Petter Selasky 	u32			reserved7[4];
34297549c34SHans Petter Selasky };
34397549c34SHans Petter Selasky 
34497549c34SHans Petter Selasky struct mlx4_cq_context {
34597549c34SHans Petter Selasky 	__be32			flags;
34697549c34SHans Petter Selasky 	u16			reserved1[3];
34797549c34SHans Petter Selasky 	__be16			page_offset;
34897549c34SHans Petter Selasky 	__be32			logsize_usrpage;
34997549c34SHans Petter Selasky 	__be16			cq_period;
35097549c34SHans Petter Selasky 	__be16			cq_max_count;
35197549c34SHans Petter Selasky 	u8			reserved2[3];
35297549c34SHans Petter Selasky 	u8			comp_eqn;
35397549c34SHans Petter Selasky 	u8			log_page_size;
35497549c34SHans Petter Selasky 	u8			reserved3[2];
35597549c34SHans Petter Selasky 	u8			mtt_base_addr_h;
35697549c34SHans Petter Selasky 	__be32			mtt_base_addr_l;
35797549c34SHans Petter Selasky 	__be32			last_notified_index;
35897549c34SHans Petter Selasky 	__be32			solicit_producer_index;
35997549c34SHans Petter Selasky 	__be32			consumer_index;
36097549c34SHans Petter Selasky 	__be32			producer_index;
36197549c34SHans Petter Selasky 	u32			reserved4[2];
36297549c34SHans Petter Selasky 	__be64			db_rec_addr;
36397549c34SHans Petter Selasky };
36497549c34SHans Petter Selasky 
36597549c34SHans Petter Selasky struct mlx4_srq_context {
36697549c34SHans Petter Selasky 	__be32			state_logsize_srqn;
36797549c34SHans Petter Selasky 	u8			logstride;
36897549c34SHans Petter Selasky 	u8			reserved1;
36997549c34SHans Petter Selasky 	__be16			xrcd;
37097549c34SHans Petter Selasky 	__be32			pg_offset_cqn;
37197549c34SHans Petter Selasky 	u32			reserved2;
37297549c34SHans Petter Selasky 	u8			log_page_size;
37397549c34SHans Petter Selasky 	u8			reserved3[2];
37497549c34SHans Petter Selasky 	u8			mtt_base_addr_h;
37597549c34SHans Petter Selasky 	__be32			mtt_base_addr_l;
37697549c34SHans Petter Selasky 	__be32			pd;
37797549c34SHans Petter Selasky 	__be16			limit_watermark;
37897549c34SHans Petter Selasky 	__be16			wqe_cnt;
37997549c34SHans Petter Selasky 	u16			reserved4;
38097549c34SHans Petter Selasky 	__be16			wqe_counter;
38197549c34SHans Petter Selasky 	u32			reserved5;
38297549c34SHans Petter Selasky 	__be64			db_rec_addr;
38397549c34SHans Petter Selasky };
38497549c34SHans Petter Selasky 
38597549c34SHans Petter Selasky struct mlx4_eq {
38697549c34SHans Petter Selasky 	struct mlx4_dev	       *dev;
38797549c34SHans Petter Selasky 	void __iomem	       *doorbell;
38897549c34SHans Petter Selasky 	int			eqn;
38997549c34SHans Petter Selasky 	u32			cons_index;
39097549c34SHans Petter Selasky 	u16			irq;
39197549c34SHans Petter Selasky 	u16			have_irq;
39297549c34SHans Petter Selasky 	int			nent;
39397549c34SHans Petter Selasky 	struct mlx4_buf_list   *page_list;
39497549c34SHans Petter Selasky 	struct mlx4_mtt		mtt;
395c3191c2eSHans Petter Selasky 	u32			ncqs;
396c3191c2eSHans Petter Selasky 	struct mlx4_active_ports actv_ports;
397c3191c2eSHans Petter Selasky 	u32			ref_count;
398c3191c2eSHans Petter Selasky 	int			affinity_cpu_id;
39997549c34SHans Petter Selasky };
40097549c34SHans Petter Selasky 
40197549c34SHans Petter Selasky struct mlx4_slave_eqe {
40297549c34SHans Petter Selasky 	u8 type;
40397549c34SHans Petter Selasky 	u8 port;
40497549c34SHans Petter Selasky 	u32 param;
40597549c34SHans Petter Selasky };
40697549c34SHans Petter Selasky 
40797549c34SHans Petter Selasky struct mlx4_slave_event_eq_info {
40897549c34SHans Petter Selasky 	int eqn;
40997549c34SHans Petter Selasky 	u16 token;
41097549c34SHans Petter Selasky };
41197549c34SHans Petter Selasky 
41297549c34SHans Petter Selasky struct mlx4_profile {
41397549c34SHans Petter Selasky 	int			num_qp;
41497549c34SHans Petter Selasky 	int			rdmarc_per_qp;
41597549c34SHans Petter Selasky 	int			num_srq;
41697549c34SHans Petter Selasky 	int			num_cq;
41797549c34SHans Petter Selasky 	int			num_mcg;
41897549c34SHans Petter Selasky 	int			num_mpt;
419c3191c2eSHans Petter Selasky 	unsigned		num_mtt;
42097549c34SHans Petter Selasky };
42197549c34SHans Petter Selasky 
42297549c34SHans Petter Selasky struct mlx4_fw {
42397549c34SHans Petter Selasky 	u64			clr_int_base;
42497549c34SHans Petter Selasky 	u64			catas_offset;
42597549c34SHans Petter Selasky 	u64			comm_base;
42697549c34SHans Petter Selasky 	u64			clock_offset;
42797549c34SHans Petter Selasky 	struct mlx4_icm	       *fw_icm;
42897549c34SHans Petter Selasky 	struct mlx4_icm	       *aux_icm;
42997549c34SHans Petter Selasky 	u32			catas_size;
43097549c34SHans Petter Selasky 	u16			fw_pages;
43197549c34SHans Petter Selasky 	u8			clr_int_bar;
43297549c34SHans Petter Selasky 	u8			catas_bar;
43397549c34SHans Petter Selasky 	u8			comm_bar;
43497549c34SHans Petter Selasky 	u8			clock_bar;
43597549c34SHans Petter Selasky };
43697549c34SHans Petter Selasky 
43797549c34SHans Petter Selasky struct mlx4_comm {
43897549c34SHans Petter Selasky 	u32			slave_write;
43997549c34SHans Petter Selasky 	u32			slave_read;
44097549c34SHans Petter Selasky };
44197549c34SHans Petter Selasky 
44297549c34SHans Petter Selasky enum {
44397549c34SHans Petter Selasky 	MLX4_MCAST_CONFIG       = 0,
44497549c34SHans Petter Selasky 	MLX4_MCAST_DISABLE      = 1,
44597549c34SHans Petter Selasky 	MLX4_MCAST_ENABLE       = 2,
44697549c34SHans Petter Selasky };
44797549c34SHans Petter Selasky 
44897549c34SHans Petter Selasky #define VLAN_FLTR_SIZE	128
44997549c34SHans Petter Selasky 
45097549c34SHans Petter Selasky struct mlx4_vlan_fltr {
45197549c34SHans Petter Selasky 	__be32 entry[VLAN_FLTR_SIZE];
45297549c34SHans Petter Selasky };
45397549c34SHans Petter Selasky 
45497549c34SHans Petter Selasky struct mlx4_mcast_entry {
45597549c34SHans Petter Selasky 	struct list_head list;
45697549c34SHans Petter Selasky 	u64 addr;
45797549c34SHans Petter Selasky };
45897549c34SHans Petter Selasky 
45997549c34SHans Petter Selasky struct mlx4_promisc_qp {
46097549c34SHans Petter Selasky 	struct list_head list;
46197549c34SHans Petter Selasky 	u32 qpn;
46297549c34SHans Petter Selasky };
46397549c34SHans Petter Selasky 
46497549c34SHans Petter Selasky struct mlx4_steer_index {
46597549c34SHans Petter Selasky 	struct list_head list;
46697549c34SHans Petter Selasky 	unsigned int index;
46797549c34SHans Petter Selasky 	struct list_head duplicates;
46897549c34SHans Petter Selasky };
46997549c34SHans Petter Selasky 
47097549c34SHans Petter Selasky #define MLX4_EVENT_TYPES_NUM 64
47197549c34SHans Petter Selasky 
47297549c34SHans Petter Selasky struct mlx4_slave_state {
47397549c34SHans Petter Selasky 	u8 comm_toggle;
47497549c34SHans Petter Selasky 	u8 last_cmd;
47597549c34SHans Petter Selasky 	u8 init_port_mask;
47697549c34SHans Petter Selasky 	bool active;
47797549c34SHans Petter Selasky 	bool old_vlan_api;
478c3191c2eSHans Petter Selasky 	bool vst_qinq_supported;
47997549c34SHans Petter Selasky 	u8 function;
48097549c34SHans Petter Selasky 	dma_addr_t vhcr_dma;
48197549c34SHans Petter Selasky 	u16 mtu[MLX4_MAX_PORTS + 1];
48297549c34SHans Petter Selasky 	__be32 ib_cap_mask[MLX4_MAX_PORTS + 1];
48397549c34SHans Petter Selasky 	struct mlx4_slave_eqe eq[MLX4_MFUNC_MAX_EQES];
48497549c34SHans Petter Selasky 	struct list_head mcast_filters[MLX4_MAX_PORTS + 1];
48597549c34SHans Petter Selasky 	struct mlx4_vlan_fltr *vlan_filter[MLX4_MAX_PORTS + 1];
48697549c34SHans Petter Selasky 	/* event type to eq number lookup */
48797549c34SHans Petter Selasky 	struct mlx4_slave_event_eq_info event_eq[MLX4_EVENT_TYPES_NUM];
48897549c34SHans Petter Selasky 	u16 eq_pi;
48997549c34SHans Petter Selasky 	u16 eq_ci;
49097549c34SHans Petter Selasky 	spinlock_t lock;
49197549c34SHans Petter Selasky 	/*initialized via the kzalloc*/
49297549c34SHans Petter Selasky 	u8 is_slave_going_down;
49397549c34SHans Petter Selasky 	u32 cookie;
49497549c34SHans Petter Selasky 	enum slave_port_state port_state[MLX4_MAX_PORTS + 1];
49597549c34SHans Petter Selasky };
49697549c34SHans Petter Selasky 
49797549c34SHans Petter Selasky #define MLX4_VGT 4095
49897549c34SHans Petter Selasky #define NO_INDX  (-1)
49997549c34SHans Petter Selasky 
50097549c34SHans Petter Selasky struct mlx4_vport_state {
50197549c34SHans Petter Selasky 	u64 mac;
50297549c34SHans Petter Selasky 	u16 default_vlan;
50397549c34SHans Petter Selasky 	u8  default_qos;
504c3191c2eSHans Petter Selasky 	__be16 vlan_proto;
50597549c34SHans Petter Selasky 	u32 tx_rate;
50697549c34SHans Petter Selasky 	bool spoofchk;
507c3191c2eSHans Petter Selasky 	u8 qos_vport;
508c3191c2eSHans Petter Selasky 	__be64 guid;
50997549c34SHans Petter Selasky };
51097549c34SHans Petter Selasky 
51197549c34SHans Petter Selasky struct mlx4_vf_admin_state {
51297549c34SHans Petter Selasky 	struct mlx4_vport_state vport[MLX4_MAX_PORTS + 1];
513c3191c2eSHans Petter Selasky 	u8 enable_smi[MLX4_MAX_PORTS + 1];
51497549c34SHans Petter Selasky };
51597549c34SHans Petter Selasky 
51697549c34SHans Petter Selasky struct mlx4_vport_oper_state {
51797549c34SHans Petter Selasky 	struct mlx4_vport_state state;
51897549c34SHans Petter Selasky 	int mac_idx;
51997549c34SHans Petter Selasky 	int vlan_idx;
52097549c34SHans Petter Selasky };
521c3191c2eSHans Petter Selasky 
52297549c34SHans Petter Selasky struct mlx4_vf_oper_state {
52397549c34SHans Petter Selasky 	struct mlx4_vport_oper_state vport[MLX4_MAX_PORTS + 1];
524c3191c2eSHans Petter Selasky 	u8 smi_enabled[MLX4_MAX_PORTS + 1];
52597549c34SHans Petter Selasky };
52697549c34SHans Petter Selasky 
52797549c34SHans Petter Selasky struct slave_list {
52897549c34SHans Petter Selasky 	struct mutex mutex;
52997549c34SHans Petter Selasky 	struct list_head res_list[MLX4_NUM_OF_RESOURCE_TYPE];
53097549c34SHans Petter Selasky };
53197549c34SHans Petter Selasky 
53297549c34SHans Petter Selasky struct resource_allocator {
533c3191c2eSHans Petter Selasky 	spinlock_t alloc_lock; /* protect quotas */
53497549c34SHans Petter Selasky 	union {
53597549c34SHans Petter Selasky 		int res_reserved;
53697549c34SHans Petter Selasky 		int res_port_rsvd[MLX4_MAX_PORTS];
53797549c34SHans Petter Selasky 	};
53897549c34SHans Petter Selasky 	union {
53997549c34SHans Petter Selasky 		int res_free;
54097549c34SHans Petter Selasky 		int res_port_free[MLX4_MAX_PORTS];
54197549c34SHans Petter Selasky 	};
54297549c34SHans Petter Selasky 	int *quota;
54397549c34SHans Petter Selasky 	int *allocated;
54497549c34SHans Petter Selasky 	int *guaranteed;
54597549c34SHans Petter Selasky };
54697549c34SHans Petter Selasky 
54797549c34SHans Petter Selasky struct mlx4_resource_tracker {
54897549c34SHans Petter Selasky 	spinlock_t lock;
54997549c34SHans Petter Selasky 	/* tree for each resources */
55097549c34SHans Petter Selasky 	struct rb_root res_tree[MLX4_NUM_OF_RESOURCE_TYPE];
55197549c34SHans Petter Selasky 	/* num_of_slave's lists, one per slave */
55297549c34SHans Petter Selasky 	struct slave_list *slave_list;
55397549c34SHans Petter Selasky 	struct resource_allocator res_alloc[MLX4_NUM_OF_RESOURCE_TYPE];
55497549c34SHans Petter Selasky };
55597549c34SHans Petter Selasky 
55697549c34SHans Petter Selasky #define SLAVE_EVENT_EQ_SIZE	128
55797549c34SHans Petter Selasky struct mlx4_slave_event_eq {
55897549c34SHans Petter Selasky 	u32 eqn;
55997549c34SHans Petter Selasky 	u32 cons;
56097549c34SHans Petter Selasky 	u32 prod;
56197549c34SHans Petter Selasky 	spinlock_t event_lock;
56297549c34SHans Petter Selasky 	struct mlx4_eqe event_eqe[SLAVE_EVENT_EQ_SIZE];
56397549c34SHans Petter Selasky };
56497549c34SHans Petter Selasky 
565c3191c2eSHans Petter Selasky struct mlx4_qos_manager {
566c3191c2eSHans Petter Selasky 	int num_of_qos_vfs;
567c3191c2eSHans Petter Selasky 	DECLARE_BITMAP(priority_bm, MLX4_NUM_UP);
568c3191c2eSHans Petter Selasky };
569c3191c2eSHans Petter Selasky 
57097549c34SHans Petter Selasky struct mlx4_master_qp0_state {
57197549c34SHans Petter Selasky 	int proxy_qp0_active;
57297549c34SHans Petter Selasky 	int qp0_active;
57397549c34SHans Petter Selasky 	int port_active;
57497549c34SHans Petter Selasky };
57597549c34SHans Petter Selasky 
57697549c34SHans Petter Selasky struct mlx4_mfunc_master_ctx {
57797549c34SHans Petter Selasky 	struct mlx4_slave_state *slave_state;
57897549c34SHans Petter Selasky 	struct mlx4_vf_admin_state *vf_admin;
57997549c34SHans Petter Selasky 	struct mlx4_vf_oper_state *vf_oper;
58097549c34SHans Petter Selasky 	struct mlx4_master_qp0_state qp0_state[MLX4_MAX_PORTS + 1];
58197549c34SHans Petter Selasky 	int			init_port_ref[MLX4_MAX_PORTS + 1];
58297549c34SHans Petter Selasky 	u16			max_mtu[MLX4_MAX_PORTS + 1];
583c3191c2eSHans Petter Selasky 	u8			pptx;
584c3191c2eSHans Petter Selasky 	u8			pprx;
58597549c34SHans Petter Selasky 	int			disable_mcast_ref[MLX4_MAX_PORTS + 1];
58697549c34SHans Petter Selasky 	struct mlx4_resource_tracker res_tracker;
58797549c34SHans Petter Selasky 	struct workqueue_struct *comm_wq;
58897549c34SHans Petter Selasky 	struct work_struct	comm_work;
58997549c34SHans Petter Selasky 	struct work_struct	slave_event_work;
59097549c34SHans Petter Selasky 	struct work_struct	slave_flr_event_work;
59197549c34SHans Petter Selasky 	spinlock_t		slave_state_lock;
59297549c34SHans Petter Selasky 	__be32			comm_arm_bit_vector[4];
59397549c34SHans Petter Selasky 	struct mlx4_eqe		cmd_eqe;
59497549c34SHans Petter Selasky 	struct mlx4_slave_event_eq slave_eq;
59597549c34SHans Petter Selasky 	struct mutex		gen_eqe_mutex[MLX4_MFUNC_MAX];
596c3191c2eSHans Petter Selasky 	struct mlx4_qos_manager qos_ctl[MLX4_MAX_PORTS + 1];
59797549c34SHans Petter Selasky };
59897549c34SHans Petter Selasky 
59997549c34SHans Petter Selasky struct mlx4_mfunc {
60097549c34SHans Petter Selasky 	struct mlx4_comm __iomem       *comm;
60197549c34SHans Petter Selasky 	struct mlx4_vhcr_cmd	       *vhcr;
60297549c34SHans Petter Selasky 	dma_addr_t			vhcr_dma;
60397549c34SHans Petter Selasky 
60497549c34SHans Petter Selasky 	struct mlx4_mfunc_master_ctx	master;
60597549c34SHans Petter Selasky };
60697549c34SHans Petter Selasky 
60797549c34SHans Petter Selasky #define MGM_QPN_MASK       0x00FFFFFF
60897549c34SHans Petter Selasky #define MGM_BLCK_LB_BIT    30
60997549c34SHans Petter Selasky 
61097549c34SHans Petter Selasky struct mlx4_mgm {
61197549c34SHans Petter Selasky 	__be32			next_gid_index;
61297549c34SHans Petter Selasky 	__be32			members_count;
61397549c34SHans Petter Selasky 	u32			reserved[2];
61497549c34SHans Petter Selasky 	u8			gid[16];
61597549c34SHans Petter Selasky 	__be32			qp[MLX4_MAX_QP_PER_MGM];
61697549c34SHans Petter Selasky };
61797549c34SHans Petter Selasky 
61897549c34SHans Petter Selasky struct mlx4_cmd {
61997549c34SHans Petter Selasky 	struct pci_pool	       *pool;
62097549c34SHans Petter Selasky 	void __iomem	       *hcr;
62197549c34SHans Petter Selasky 	struct mutex		slave_cmd_mutex;
62297549c34SHans Petter Selasky 	struct semaphore	poll_sem;
62397549c34SHans Petter Selasky 	struct semaphore	event_sem;
624c3191c2eSHans Petter Selasky 	struct rw_semaphore	switch_sem;
62597549c34SHans Petter Selasky 	int			max_cmds;
62697549c34SHans Petter Selasky 	spinlock_t		context_lock;
62797549c34SHans Petter Selasky 	int			free_head;
62897549c34SHans Petter Selasky 	struct mlx4_cmd_context *context;
62997549c34SHans Petter Selasky 	u16			token_mask;
63097549c34SHans Petter Selasky 	u8			use_events;
63197549c34SHans Petter Selasky 	u8			toggle;
63297549c34SHans Petter Selasky 	u8			comm_toggle;
633c3191c2eSHans Petter Selasky 	u8			initialized;
63497549c34SHans Petter Selasky };
63597549c34SHans Petter Selasky 
63697549c34SHans Petter Selasky enum {
63797549c34SHans Petter Selasky 	MLX4_VF_IMMED_VLAN_FLAG_VLAN = 1 << 0,
63897549c34SHans Petter Selasky 	MLX4_VF_IMMED_VLAN_FLAG_QOS = 1 << 1,
639c3191c2eSHans Petter Selasky 	MLX4_VF_IMMED_VLAN_FLAG_LINK_DISABLE = 1 << 2,
64097549c34SHans Petter Selasky };
64197549c34SHans Petter Selasky struct mlx4_vf_immed_vlan_work {
64297549c34SHans Petter Selasky 	struct work_struct	work;
64397549c34SHans Petter Selasky 	struct mlx4_priv	*priv;
64497549c34SHans Petter Selasky 	int			flags;
64597549c34SHans Petter Selasky 	int			slave;
64697549c34SHans Petter Selasky 	int			vlan_ix;
64797549c34SHans Petter Selasky 	int			orig_vlan_ix;
64897549c34SHans Petter Selasky 	u8			port;
64997549c34SHans Petter Selasky 	u8			qos;
650c3191c2eSHans Petter Selasky 	u8                      qos_vport;
65197549c34SHans Petter Selasky 	u16			vlan_id;
65297549c34SHans Petter Selasky 	u16			orig_vlan_id;
653c3191c2eSHans Petter Selasky 	__be16			vlan_proto;
65497549c34SHans Petter Selasky };
65597549c34SHans Petter Selasky 
65697549c34SHans Petter Selasky 
65797549c34SHans Petter Selasky struct mlx4_uar_table {
65897549c34SHans Petter Selasky 	struct mlx4_bitmap	bitmap;
65997549c34SHans Petter Selasky };
66097549c34SHans Petter Selasky 
66197549c34SHans Petter Selasky struct mlx4_mr_table {
66297549c34SHans Petter Selasky 	struct mlx4_bitmap	mpt_bitmap;
66397549c34SHans Petter Selasky 	struct mlx4_buddy	mtt_buddy;
66497549c34SHans Petter Selasky 	u64			mtt_base;
66597549c34SHans Petter Selasky 	u64			mpt_base;
66697549c34SHans Petter Selasky 	struct mlx4_icm_table	mtt_table;
66797549c34SHans Petter Selasky 	struct mlx4_icm_table	dmpt_table;
66897549c34SHans Petter Selasky };
66997549c34SHans Petter Selasky 
67097549c34SHans Petter Selasky struct mlx4_cq_table {
67197549c34SHans Petter Selasky 	struct mlx4_bitmap	bitmap;
67297549c34SHans Petter Selasky 	spinlock_t		lock;
67397549c34SHans Petter Selasky 	struct radix_tree_root	tree;
67497549c34SHans Petter Selasky 	struct mlx4_icm_table	table;
67597549c34SHans Petter Selasky 	struct mlx4_icm_table	cmpt_table;
67697549c34SHans Petter Selasky };
67797549c34SHans Petter Selasky 
67897549c34SHans Petter Selasky struct mlx4_eq_table {
67997549c34SHans Petter Selasky 	struct mlx4_bitmap	bitmap;
68097549c34SHans Petter Selasky 	char		       *irq_names;
68197549c34SHans Petter Selasky 	void __iomem	       *clr_int;
68297549c34SHans Petter Selasky 	void __iomem	      **uar_map;
68397549c34SHans Petter Selasky 	u32			clr_mask;
68497549c34SHans Petter Selasky 	struct mlx4_eq	       *eq;
68597549c34SHans Petter Selasky 	struct mlx4_icm_table	table;
68697549c34SHans Petter Selasky 	struct mlx4_icm_table	cmpt_table;
68797549c34SHans Petter Selasky 	int			have_irq;
68897549c34SHans Petter Selasky 	u8			inta_pin;
68997549c34SHans Petter Selasky };
69097549c34SHans Petter Selasky 
69197549c34SHans Petter Selasky struct mlx4_srq_table {
69297549c34SHans Petter Selasky 	struct mlx4_bitmap	bitmap;
69397549c34SHans Petter Selasky 	spinlock_t		lock;
69497549c34SHans Petter Selasky 	struct radix_tree_root	tree;
69597549c34SHans Petter Selasky 	struct mlx4_icm_table	table;
69697549c34SHans Petter Selasky 	struct mlx4_icm_table	cmpt_table;
69797549c34SHans Petter Selasky };
69897549c34SHans Petter Selasky 
699c3191c2eSHans Petter Selasky enum mlx4_qp_table_zones {
700c3191c2eSHans Petter Selasky 	MLX4_QP_TABLE_ZONE_GENERAL,
701c3191c2eSHans Petter Selasky 	MLX4_QP_TABLE_ZONE_RSS,
702c3191c2eSHans Petter Selasky 	MLX4_QP_TABLE_ZONE_RAW_ETH,
703c3191c2eSHans Petter Selasky 	MLX4_QP_TABLE_ZONE_NUM
704c3191c2eSHans Petter Selasky };
705c3191c2eSHans Petter Selasky 
70697549c34SHans Petter Selasky struct mlx4_qp_table {
707c3191c2eSHans Petter Selasky 	struct mlx4_bitmap	*bitmap_gen;
708c3191c2eSHans Petter Selasky 	struct mlx4_zone_allocator *zones;
709c3191c2eSHans Petter Selasky 	u32			zones_uids[MLX4_QP_TABLE_ZONE_NUM];
71097549c34SHans Petter Selasky 	u32			rdmarc_base;
71197549c34SHans Petter Selasky 	int			rdmarc_shift;
71297549c34SHans Petter Selasky 	spinlock_t		lock;
71397549c34SHans Petter Selasky 	struct mlx4_icm_table	qp_table;
71497549c34SHans Petter Selasky 	struct mlx4_icm_table	auxc_table;
71597549c34SHans Petter Selasky 	struct mlx4_icm_table	altc_table;
71697549c34SHans Petter Selasky 	struct mlx4_icm_table	rdmarc_table;
71797549c34SHans Petter Selasky 	struct mlx4_icm_table	cmpt_table;
71897549c34SHans Petter Selasky };
71997549c34SHans Petter Selasky 
72097549c34SHans Petter Selasky struct mlx4_mcg_table {
72197549c34SHans Petter Selasky 	struct mutex		mutex;
72297549c34SHans Petter Selasky 	struct mlx4_bitmap	bitmap;
72397549c34SHans Petter Selasky 	struct mlx4_icm_table	table;
72497549c34SHans Petter Selasky };
72597549c34SHans Petter Selasky 
72697549c34SHans Petter Selasky struct mlx4_catas_err {
72797549c34SHans Petter Selasky 	u32 __iomem	       *map;
72897549c34SHans Petter Selasky 	struct timer_list	timer;
72997549c34SHans Petter Selasky 	struct list_head	list;
73097549c34SHans Petter Selasky };
73197549c34SHans Petter Selasky 
73297549c34SHans Petter Selasky #define MLX4_MAX_MAC_NUM	128
73397549c34SHans Petter Selasky #define MLX4_MAC_TABLE_SIZE	(MLX4_MAX_MAC_NUM << 3)
73497549c34SHans Petter Selasky 
73597549c34SHans Petter Selasky struct mlx4_mac_table {
73697549c34SHans Petter Selasky 	__be64			entries[MLX4_MAX_MAC_NUM];
73797549c34SHans Petter Selasky 	int			refs[MLX4_MAX_MAC_NUM];
738c3191c2eSHans Petter Selasky 	bool			is_dup[MLX4_MAX_MAC_NUM];
73997549c34SHans Petter Selasky 	struct mutex		mutex;
74097549c34SHans Petter Selasky 	int			total;
74197549c34SHans Petter Selasky 	int			max;
74297549c34SHans Petter Selasky };
74397549c34SHans Petter Selasky 
744c3191c2eSHans Petter Selasky #define MLX4_ROCE_GID_ENTRY_SIZE	16
745c3191c2eSHans Petter Selasky 
746c3191c2eSHans Petter Selasky struct mlx4_roce_gid_entry {
747c3191c2eSHans Petter Selasky 	u8 raw[MLX4_ROCE_GID_ENTRY_SIZE];
748c3191c2eSHans Petter Selasky };
749c3191c2eSHans Petter Selasky 
750c3191c2eSHans Petter Selasky struct mlx4_roce_gid_table {
751c3191c2eSHans Petter Selasky 	struct mlx4_roce_gid_entry	roce_gids[MLX4_ROCE_MAX_GIDS];
752c3191c2eSHans Petter Selasky 	struct mutex			mutex;
753c3191c2eSHans Petter Selasky };
754c3191c2eSHans Petter Selasky 
75597549c34SHans Petter Selasky #define MLX4_MAX_VLAN_NUM	128
75697549c34SHans Petter Selasky #define MLX4_VLAN_TABLE_SIZE	(MLX4_MAX_VLAN_NUM << 2)
75797549c34SHans Petter Selasky 
75897549c34SHans Petter Selasky struct mlx4_vlan_table {
75997549c34SHans Petter Selasky 	__be32			entries[MLX4_MAX_VLAN_NUM];
76097549c34SHans Petter Selasky 	int			refs[MLX4_MAX_VLAN_NUM];
761c3191c2eSHans Petter Selasky 	int			is_dup[MLX4_MAX_VLAN_NUM];
76297549c34SHans Petter Selasky 	struct mutex		mutex;
76397549c34SHans Petter Selasky 	int			total;
76497549c34SHans Petter Selasky 	int			max;
76597549c34SHans Petter Selasky };
76697549c34SHans Petter Selasky 
76797549c34SHans Petter Selasky #define SET_PORT_GEN_ALL_VALID		0x7
76897549c34SHans Petter Selasky #define SET_PORT_PROMISC_SHIFT		31
76997549c34SHans Petter Selasky #define SET_PORT_MC_PROMISC_SHIFT	30
77097549c34SHans Petter Selasky 
77197549c34SHans Petter Selasky enum {
77297549c34SHans Petter Selasky 	MCAST_DIRECT_ONLY	= 0,
77397549c34SHans Petter Selasky 	MCAST_DIRECT		= 1,
77497549c34SHans Petter Selasky 	MCAST_DEFAULT		= 2
77597549c34SHans Petter Selasky };
77697549c34SHans Petter Selasky 
77797549c34SHans Petter Selasky struct mlx4_set_port_general_context {
778c3191c2eSHans Petter Selasky 	u16 reserved1;
779c3191c2eSHans Petter Selasky 	u8 v_ignore_fcs;
78097549c34SHans Petter Selasky 	u8 flags;
781c3191c2eSHans Petter Selasky 	union {
782c3191c2eSHans Petter Selasky 		u8 ignore_fcs;
783c3191c2eSHans Petter Selasky 		u8 roce_mode;
784c3191c2eSHans Petter Selasky 	};
785c3191c2eSHans Petter Selasky 	u8 reserved2;
78697549c34SHans Petter Selasky 	__be16 mtu;
78797549c34SHans Petter Selasky 	u8 pptx;
78897549c34SHans Petter Selasky 	u8 pfctx;
78997549c34SHans Petter Selasky 	u16 reserved3;
79097549c34SHans Petter Selasky 	u8 pprx;
79197549c34SHans Petter Selasky 	u8 pfcrx;
79297549c34SHans Petter Selasky 	u16 reserved4;
793c3191c2eSHans Petter Selasky 	u32 reserved5;
794c3191c2eSHans Petter Selasky 	u8 phv_en;
795c3191c2eSHans Petter Selasky 	u8 reserved6[3];
79697549c34SHans Petter Selasky };
79797549c34SHans Petter Selasky 
79897549c34SHans Petter Selasky struct mlx4_set_port_rqp_calc_context {
79997549c34SHans Petter Selasky 	__be32 base_qpn;
80097549c34SHans Petter Selasky 	u8 rererved;
80197549c34SHans Petter Selasky 	u8 n_mac;
80297549c34SHans Petter Selasky 	u8 n_vlan;
80397549c34SHans Petter Selasky 	u8 n_prio;
80497549c34SHans Petter Selasky 	u8 reserved2[3];
80597549c34SHans Petter Selasky 	u8 mac_miss;
80697549c34SHans Petter Selasky 	u8 intra_no_vlan;
80797549c34SHans Petter Selasky 	u8 no_vlan;
80897549c34SHans Petter Selasky 	u8 intra_vlan_miss;
80997549c34SHans Petter Selasky 	u8 vlan_miss;
81097549c34SHans Petter Selasky 	u8 reserved3[3];
81197549c34SHans Petter Selasky 	u8 no_vlan_prio;
81297549c34SHans Petter Selasky 	__be32 promisc;
81397549c34SHans Petter Selasky 	__be32 mcast;
81497549c34SHans Petter Selasky };
81597549c34SHans Petter Selasky 
81697549c34SHans Petter Selasky struct mlx4_port_info {
81797549c34SHans Petter Selasky 	struct mlx4_dev	       *dev;
81897549c34SHans Petter Selasky 	int			port;
81997549c34SHans Petter Selasky 	char			dev_name[16];
82097549c34SHans Petter Selasky 	struct device_attribute port_attr;
82197549c34SHans Petter Selasky 	enum mlx4_port_type	tmp_type;
82297549c34SHans Petter Selasky 	char			dev_mtu_name[16];
82397549c34SHans Petter Selasky 	struct device_attribute port_mtu_attr;
82497549c34SHans Petter Selasky 	struct mlx4_mac_table	mac_table;
82597549c34SHans Petter Selasky 	struct mlx4_vlan_table	vlan_table;
826c3191c2eSHans Petter Selasky 	struct mlx4_roce_gid_table gid_table;
82797549c34SHans Petter Selasky 	int			base_qpn;
82897549c34SHans Petter Selasky };
82997549c34SHans Petter Selasky 
83097549c34SHans Petter Selasky struct mlx4_sense {
83197549c34SHans Petter Selasky 	struct mlx4_dev		*dev;
83297549c34SHans Petter Selasky 	u8			do_sense_port[MLX4_MAX_PORTS + 1];
83397549c34SHans Petter Selasky 	u8			sense_allowed[MLX4_MAX_PORTS + 1];
83497549c34SHans Petter Selasky 	struct delayed_work	sense_poll;
835c3191c2eSHans Petter Selasky 	int			gone;
83697549c34SHans Petter Selasky };
83797549c34SHans Petter Selasky 
83897549c34SHans Petter Selasky struct mlx4_msix_ctl {
839c3191c2eSHans Petter Selasky 	DECLARE_BITMAP(pool_bm, MAX_MSIX);
84097549c34SHans Petter Selasky 	struct mutex	pool_lock;
84197549c34SHans Petter Selasky };
84297549c34SHans Petter Selasky 
84397549c34SHans Petter Selasky struct mlx4_steer {
84497549c34SHans Petter Selasky 	struct list_head promisc_qps[MLX4_NUM_STEERS];
84597549c34SHans Petter Selasky 	struct list_head steer_entries[MLX4_NUM_STEERS];
84697549c34SHans Petter Selasky };
84797549c34SHans Petter Selasky 
84897549c34SHans Petter Selasky enum {
84997549c34SHans Petter Selasky 	MLX4_PCI_DEV_IS_VF		= 1 << 0,
85097549c34SHans Petter Selasky 	MLX4_PCI_DEV_FORCE_SENSE_PORT	= 1 << 1,
85197549c34SHans Petter Selasky };
85297549c34SHans Petter Selasky 
85397549c34SHans Petter Selasky enum {
85497549c34SHans Petter Selasky 	MLX4_NO_RR	= 0,
85597549c34SHans Petter Selasky 	MLX4_USE_RR	= 1,
85697549c34SHans Petter Selasky };
85797549c34SHans Petter Selasky 
85897549c34SHans Petter Selasky struct mlx4_priv {
85997549c34SHans Petter Selasky 	struct mlx4_dev		dev;
86097549c34SHans Petter Selasky 
86197549c34SHans Petter Selasky 	struct list_head	dev_list;
86297549c34SHans Petter Selasky 	struct list_head	ctx_list;
86397549c34SHans Petter Selasky 	spinlock_t		ctx_lock;
86497549c34SHans Petter Selasky 
86597549c34SHans Petter Selasky 	int			pci_dev_data;
866c3191c2eSHans Petter Selasky 	int                     removed;
86797549c34SHans Petter Selasky 
86897549c34SHans Petter Selasky 	struct list_head        pgdir_list;
86997549c34SHans Petter Selasky 	struct mutex            pgdir_mutex;
87097549c34SHans Petter Selasky 
87197549c34SHans Petter Selasky 	struct mlx4_fw		fw;
87297549c34SHans Petter Selasky 	struct mlx4_cmd		cmd;
87397549c34SHans Petter Selasky 	struct mlx4_mfunc	mfunc;
87497549c34SHans Petter Selasky 
87597549c34SHans Petter Selasky 	struct mlx4_bitmap	pd_bitmap;
87697549c34SHans Petter Selasky 	struct mlx4_bitmap	xrcd_bitmap;
87797549c34SHans Petter Selasky 	struct mlx4_uar_table	uar_table;
87897549c34SHans Petter Selasky 	struct mlx4_mr_table	mr_table;
87997549c34SHans Petter Selasky 	struct mlx4_cq_table	cq_table;
88097549c34SHans Petter Selasky 	struct mlx4_eq_table	eq_table;
88197549c34SHans Petter Selasky 	struct mlx4_srq_table	srq_table;
88297549c34SHans Petter Selasky 	struct mlx4_qp_table	qp_table;
88397549c34SHans Petter Selasky 	struct mlx4_mcg_table	mcg_table;
884c3191c2eSHans Petter Selasky 	struct mlx4_bitmap	counters_bitmap;
885c3191c2eSHans Petter Selasky 	int			def_counter[MLX4_MAX_PORTS];
88697549c34SHans Petter Selasky 
88797549c34SHans Petter Selasky 	struct mlx4_catas_err	catas_err;
88897549c34SHans Petter Selasky 
88997549c34SHans Petter Selasky 	void __iomem	       *clr_base;
89097549c34SHans Petter Selasky 
89197549c34SHans Petter Selasky 	struct mlx4_uar		driver_uar;
89297549c34SHans Petter Selasky 	void __iomem	       *kar;
89397549c34SHans Petter Selasky 	struct mlx4_port_info	port[MLX4_MAX_PORTS + 1];
89497549c34SHans Petter Selasky 	struct mlx4_sense       sense;
89597549c34SHans Petter Selasky 	struct mutex		port_mutex;
89697549c34SHans Petter Selasky 	struct mlx4_msix_ctl	msix_ctl;
89797549c34SHans Petter Selasky 	struct mlx4_steer	*steer;
89897549c34SHans Petter Selasky 	struct list_head	bf_list;
89997549c34SHans Petter Selasky 	struct mutex		bf_mutex;
90097549c34SHans Petter Selasky 	struct io_mapping	*bf_mapping;
90197549c34SHans Petter Selasky 	void __iomem            *clock_mapping;
90297549c34SHans Petter Selasky 	int			reserved_mtts;
90397549c34SHans Petter Selasky 	int			fs_hash_mode;
90497549c34SHans Petter Selasky 	u8 virt2phys_pkey[MLX4_MFUNC_MAX][MLX4_MAX_PORTS][MLX4_MAX_PORT_PKEYS];
905c3191c2eSHans Petter Selasky 	struct mlx4_port_map	v2p; /* cached port mapping configuration */
906c3191c2eSHans Petter Selasky 	struct mutex		bond_mutex; /* for bond mode */
90797549c34SHans Petter Selasky 	__be64			slave_node_guids[MLX4_MFUNC_MAX];
908c3191c2eSHans Petter Selasky 
90997549c34SHans Petter Selasky 	atomic_t		opreq_count;
91097549c34SHans Petter Selasky 	struct work_struct	opreq_task;
91197549c34SHans Petter Selasky };
91297549c34SHans Petter Selasky 
mlx4_priv(struct mlx4_dev * dev)91397549c34SHans Petter Selasky static inline struct mlx4_priv *mlx4_priv(struct mlx4_dev *dev)
91497549c34SHans Petter Selasky {
91597549c34SHans Petter Selasky 	return container_of(dev, struct mlx4_priv, dev);
91697549c34SHans Petter Selasky }
91797549c34SHans Petter Selasky 
91897549c34SHans Petter Selasky #define MLX4_SENSE_RANGE	(HZ * 3)
91997549c34SHans Petter Selasky 
92097549c34SHans Petter Selasky extern struct workqueue_struct *mlx4_wq;
92197549c34SHans Petter Selasky 
92297549c34SHans Petter Selasky u32 mlx4_bitmap_alloc(struct mlx4_bitmap *bitmap);
92397549c34SHans Petter Selasky void mlx4_bitmap_free(struct mlx4_bitmap *bitmap, u32 obj, int use_rr);
92497549c34SHans Petter Selasky u32 mlx4_bitmap_alloc_range(struct mlx4_bitmap *bitmap, int cnt,
92597549c34SHans Petter Selasky 			    int align, u32 skip_mask);
92697549c34SHans Petter Selasky void mlx4_bitmap_free_range(struct mlx4_bitmap *bitmap, u32 obj, int cnt,
92797549c34SHans Petter Selasky 			    int use_rr);
92897549c34SHans Petter Selasky u32 mlx4_bitmap_avail(struct mlx4_bitmap *bitmap);
92997549c34SHans Petter Selasky int mlx4_bitmap_init(struct mlx4_bitmap *bitmap, u32 num, u32 mask,
93097549c34SHans Petter Selasky 		     u32 reserved_bot, u32 resetrved_top);
93197549c34SHans Petter Selasky void mlx4_bitmap_cleanup(struct mlx4_bitmap *bitmap);
93297549c34SHans Petter Selasky 
93397549c34SHans Petter Selasky int mlx4_reset(struct mlx4_dev *dev);
93497549c34SHans Petter Selasky 
93597549c34SHans Petter Selasky int mlx4_alloc_eq_table(struct mlx4_dev *dev);
93697549c34SHans Petter Selasky void mlx4_free_eq_table(struct mlx4_dev *dev);
93797549c34SHans Petter Selasky 
93897549c34SHans Petter Selasky int mlx4_init_pd_table(struct mlx4_dev *dev);
93997549c34SHans Petter Selasky int mlx4_init_xrcd_table(struct mlx4_dev *dev);
94097549c34SHans Petter Selasky int mlx4_init_uar_table(struct mlx4_dev *dev);
94197549c34SHans Petter Selasky int mlx4_init_mr_table(struct mlx4_dev *dev);
94297549c34SHans Petter Selasky int mlx4_init_eq_table(struct mlx4_dev *dev);
94397549c34SHans Petter Selasky int mlx4_init_cq_table(struct mlx4_dev *dev);
94497549c34SHans Petter Selasky int mlx4_init_qp_table(struct mlx4_dev *dev);
94597549c34SHans Petter Selasky int mlx4_init_srq_table(struct mlx4_dev *dev);
94697549c34SHans Petter Selasky int mlx4_init_mcg_table(struct mlx4_dev *dev);
94797549c34SHans Petter Selasky 
94897549c34SHans Petter Selasky void mlx4_cleanup_pd_table(struct mlx4_dev *dev);
94997549c34SHans Petter Selasky void mlx4_cleanup_xrcd_table(struct mlx4_dev *dev);
95097549c34SHans Petter Selasky void mlx4_cleanup_uar_table(struct mlx4_dev *dev);
95197549c34SHans Petter Selasky void mlx4_cleanup_mr_table(struct mlx4_dev *dev);
95297549c34SHans Petter Selasky void mlx4_cleanup_eq_table(struct mlx4_dev *dev);
95397549c34SHans Petter Selasky void mlx4_cleanup_cq_table(struct mlx4_dev *dev);
95497549c34SHans Petter Selasky void mlx4_cleanup_qp_table(struct mlx4_dev *dev);
95597549c34SHans Petter Selasky void mlx4_cleanup_srq_table(struct mlx4_dev *dev);
95697549c34SHans Petter Selasky void mlx4_cleanup_mcg_table(struct mlx4_dev *dev);
957c3191c2eSHans Petter Selasky int __mlx4_qp_alloc_icm(struct mlx4_dev *dev, int qpn, gfp_t gfp);
95897549c34SHans Petter Selasky void __mlx4_qp_free_icm(struct mlx4_dev *dev, int qpn);
95997549c34SHans Petter Selasky int __mlx4_cq_alloc_icm(struct mlx4_dev *dev, int *cqn);
96097549c34SHans Petter Selasky void __mlx4_cq_free_icm(struct mlx4_dev *dev, int cqn);
96197549c34SHans Petter Selasky int __mlx4_srq_alloc_icm(struct mlx4_dev *dev, int *srqn);
96297549c34SHans Petter Selasky void __mlx4_srq_free_icm(struct mlx4_dev *dev, int srqn);
96397549c34SHans Petter Selasky int __mlx4_mpt_reserve(struct mlx4_dev *dev);
96497549c34SHans Petter Selasky void __mlx4_mpt_release(struct mlx4_dev *dev, u32 index);
965c3191c2eSHans Petter Selasky int __mlx4_mpt_alloc_icm(struct mlx4_dev *dev, u32 index, gfp_t gfp);
96697549c34SHans Petter Selasky void __mlx4_mpt_free_icm(struct mlx4_dev *dev, u32 index);
96797549c34SHans Petter Selasky u32 __mlx4_alloc_mtt_range(struct mlx4_dev *dev, int order);
96897549c34SHans Petter Selasky void __mlx4_free_mtt_range(struct mlx4_dev *dev, u32 first_seg, int order);
96997549c34SHans Petter Selasky 
97097549c34SHans Petter Selasky int mlx4_WRITE_MTT_wrapper(struct mlx4_dev *dev, int slave,
97197549c34SHans Petter Selasky 			   struct mlx4_vhcr *vhcr,
97297549c34SHans Petter Selasky 			   struct mlx4_cmd_mailbox *inbox,
97397549c34SHans Petter Selasky 			   struct mlx4_cmd_mailbox *outbox,
97497549c34SHans Petter Selasky 			   struct mlx4_cmd_info *cmd);
97597549c34SHans Petter Selasky int mlx4_SYNC_TPT_wrapper(struct mlx4_dev *dev, int slave,
97697549c34SHans Petter Selasky 			   struct mlx4_vhcr *vhcr,
97797549c34SHans Petter Selasky 			   struct mlx4_cmd_mailbox *inbox,
97897549c34SHans Petter Selasky 			   struct mlx4_cmd_mailbox *outbox,
97997549c34SHans Petter Selasky 			   struct mlx4_cmd_info *cmd);
98097549c34SHans Petter Selasky int mlx4_SW2HW_MPT_wrapper(struct mlx4_dev *dev, int slave,
98197549c34SHans Petter Selasky 			   struct mlx4_vhcr *vhcr,
98297549c34SHans Petter Selasky 			   struct mlx4_cmd_mailbox *inbox,
98397549c34SHans Petter Selasky 			   struct mlx4_cmd_mailbox *outbox,
98497549c34SHans Petter Selasky 			   struct mlx4_cmd_info *cmd);
98597549c34SHans Petter Selasky int mlx4_HW2SW_MPT_wrapper(struct mlx4_dev *dev, int slave,
98697549c34SHans Petter Selasky 			   struct mlx4_vhcr *vhcr,
98797549c34SHans Petter Selasky 			   struct mlx4_cmd_mailbox *inbox,
98897549c34SHans Petter Selasky 			   struct mlx4_cmd_mailbox *outbox,
98997549c34SHans Petter Selasky 			   struct mlx4_cmd_info *cmd);
99097549c34SHans Petter Selasky int mlx4_QUERY_MPT_wrapper(struct mlx4_dev *dev, int slave,
99197549c34SHans Petter Selasky 			   struct mlx4_vhcr *vhcr,
99297549c34SHans Petter Selasky 			   struct mlx4_cmd_mailbox *inbox,
99397549c34SHans Petter Selasky 			   struct mlx4_cmd_mailbox *outbox,
99497549c34SHans Petter Selasky 			   struct mlx4_cmd_info *cmd);
99597549c34SHans Petter Selasky int mlx4_SW2HW_EQ_wrapper(struct mlx4_dev *dev, int slave,
99697549c34SHans Petter Selasky 			  struct mlx4_vhcr *vhcr,
99797549c34SHans Petter Selasky 			  struct mlx4_cmd_mailbox *inbox,
99897549c34SHans Petter Selasky 			  struct mlx4_cmd_mailbox *outbox,
99997549c34SHans Petter Selasky 			  struct mlx4_cmd_info *cmd);
1000c3191c2eSHans Petter Selasky int mlx4_CONFIG_DEV_wrapper(struct mlx4_dev *dev, int slave,
1001c3191c2eSHans Petter Selasky 			    struct mlx4_vhcr *vhcr,
1002c3191c2eSHans Petter Selasky 			    struct mlx4_cmd_mailbox *inbox,
1003c3191c2eSHans Petter Selasky 			    struct mlx4_cmd_mailbox *outbox,
1004c3191c2eSHans Petter Selasky 			    struct mlx4_cmd_info *cmd);
100597549c34SHans Petter Selasky int mlx4_DMA_wrapper(struct mlx4_dev *dev, int slave,
100697549c34SHans Petter Selasky 		     struct mlx4_vhcr *vhcr,
100797549c34SHans Petter Selasky 		     struct mlx4_cmd_mailbox *inbox,
100897549c34SHans Petter Selasky 		     struct mlx4_cmd_mailbox *outbox,
100997549c34SHans Petter Selasky 		     struct mlx4_cmd_info *cmd);
101097549c34SHans Petter Selasky int __mlx4_qp_reserve_range(struct mlx4_dev *dev, int cnt, int align,
101197549c34SHans Petter Selasky 			    int *base, u8 flags);
101297549c34SHans Petter Selasky void __mlx4_qp_release_range(struct mlx4_dev *dev, int base_qpn, int cnt);
101397549c34SHans Petter Selasky int __mlx4_register_mac(struct mlx4_dev *dev, u8 port, u64 mac);
101497549c34SHans Petter Selasky void __mlx4_unregister_mac(struct mlx4_dev *dev, u8 port, u64 mac);
101597549c34SHans Petter Selasky int __mlx4_write_mtt(struct mlx4_dev *dev, struct mlx4_mtt *mtt,
101697549c34SHans Petter Selasky 		     int start_index, int npages, u64 *page_list);
1017c3191c2eSHans Petter Selasky int __mlx4_counter_alloc(struct mlx4_dev *dev, u32 *idx);
1018c3191c2eSHans Petter Selasky void __mlx4_counter_free(struct mlx4_dev *dev, u32 idx);
1019c3191c2eSHans Petter Selasky int mlx4_calc_vf_counters(struct mlx4_dev *dev, int slave, int port,
1020c3191c2eSHans Petter Selasky 			  struct mlx4_counter *data);
102197549c34SHans Petter Selasky int __mlx4_xrcd_alloc(struct mlx4_dev *dev, u32 *xrcdn);
102297549c34SHans Petter Selasky void __mlx4_xrcd_free(struct mlx4_dev *dev, u32 xrcdn);
102397549c34SHans Petter Selasky 
102497549c34SHans Petter Selasky void mlx4_start_catas_poll(struct mlx4_dev *dev);
102597549c34SHans Petter Selasky void mlx4_stop_catas_poll(struct mlx4_dev *dev);
1026c3191c2eSHans Petter Selasky int mlx4_catas_init(struct mlx4_dev *dev);
1027c3191c2eSHans Petter Selasky void mlx4_catas_end(struct mlx4_dev *dev);
102897549c34SHans Petter Selasky int mlx4_restart_one(struct pci_dev *pdev);
102997549c34SHans Petter Selasky int mlx4_register_device(struct mlx4_dev *dev);
103097549c34SHans Petter Selasky void mlx4_unregister_device(struct mlx4_dev *dev);
103197549c34SHans Petter Selasky void mlx4_dispatch_event(struct mlx4_dev *dev, enum mlx4_dev_event type,
103297549c34SHans Petter Selasky 			 unsigned long param);
103397549c34SHans Petter Selasky 
103497549c34SHans Petter Selasky struct mlx4_dev_cap;
103597549c34SHans Petter Selasky struct mlx4_init_hca_param;
103697549c34SHans Petter Selasky 
103797549c34SHans Petter Selasky u64 mlx4_make_profile(struct mlx4_dev *dev,
103897549c34SHans Petter Selasky 		      struct mlx4_profile *request,
103997549c34SHans Petter Selasky 		      struct mlx4_dev_cap *dev_cap,
104097549c34SHans Petter Selasky 		      struct mlx4_init_hca_param *init_hca);
104197549c34SHans Petter Selasky void mlx4_master_comm_channel(struct work_struct *work);
104297549c34SHans Petter Selasky void mlx4_gen_slave_eqe(struct work_struct *work);
104397549c34SHans Petter Selasky void mlx4_master_handle_slave_flr(struct work_struct *work);
104497549c34SHans Petter Selasky 
104597549c34SHans Petter Selasky int mlx4_ALLOC_RES_wrapper(struct mlx4_dev *dev, int slave,
104697549c34SHans Petter Selasky 			   struct mlx4_vhcr *vhcr,
104797549c34SHans Petter Selasky 			   struct mlx4_cmd_mailbox *inbox,
104897549c34SHans Petter Selasky 			   struct mlx4_cmd_mailbox *outbox,
104997549c34SHans Petter Selasky 			   struct mlx4_cmd_info *cmd);
105097549c34SHans Petter Selasky int mlx4_FREE_RES_wrapper(struct mlx4_dev *dev, int slave,
105197549c34SHans Petter Selasky 			  struct mlx4_vhcr *vhcr,
105297549c34SHans Petter Selasky 			  struct mlx4_cmd_mailbox *inbox,
105397549c34SHans Petter Selasky 			  struct mlx4_cmd_mailbox *outbox,
105497549c34SHans Petter Selasky 			  struct mlx4_cmd_info *cmd);
105597549c34SHans Petter Selasky int mlx4_MAP_EQ_wrapper(struct mlx4_dev *dev, int slave,
105697549c34SHans Petter Selasky 			struct mlx4_vhcr *vhcr, struct mlx4_cmd_mailbox *inbox,
105797549c34SHans Petter Selasky 			struct mlx4_cmd_mailbox *outbox,
105897549c34SHans Petter Selasky 			struct mlx4_cmd_info *cmd);
105997549c34SHans Petter Selasky int mlx4_COMM_INT_wrapper(struct mlx4_dev *dev, int slave,
106097549c34SHans Petter Selasky 			  struct mlx4_vhcr *vhcr,
106197549c34SHans Petter Selasky 			  struct mlx4_cmd_mailbox *inbox,
106297549c34SHans Petter Selasky 			  struct mlx4_cmd_mailbox *outbox,
106397549c34SHans Petter Selasky 			  struct mlx4_cmd_info *cmd);
106497549c34SHans Petter Selasky int mlx4_HW2SW_EQ_wrapper(struct mlx4_dev *dev, int slave,
106597549c34SHans Petter Selasky 			    struct mlx4_vhcr *vhcr,
106697549c34SHans Petter Selasky 			    struct mlx4_cmd_mailbox *inbox,
106797549c34SHans Petter Selasky 			    struct mlx4_cmd_mailbox *outbox,
106897549c34SHans Petter Selasky 			  struct mlx4_cmd_info *cmd);
106997549c34SHans Petter Selasky int mlx4_QUERY_EQ_wrapper(struct mlx4_dev *dev, int slave,
107097549c34SHans Petter Selasky 			  struct mlx4_vhcr *vhcr,
107197549c34SHans Petter Selasky 			  struct mlx4_cmd_mailbox *inbox,
107297549c34SHans Petter Selasky 			  struct mlx4_cmd_mailbox *outbox,
107397549c34SHans Petter Selasky 			  struct mlx4_cmd_info *cmd);
107497549c34SHans Petter Selasky int mlx4_SW2HW_CQ_wrapper(struct mlx4_dev *dev, int slave,
107597549c34SHans Petter Selasky 			  struct mlx4_vhcr *vhcr,
107697549c34SHans Petter Selasky 			  struct mlx4_cmd_mailbox *inbox,
107797549c34SHans Petter Selasky 			  struct mlx4_cmd_mailbox *outbox,
107897549c34SHans Petter Selasky 			  struct mlx4_cmd_info *cmd);
107997549c34SHans Petter Selasky int mlx4_HW2SW_CQ_wrapper(struct mlx4_dev *dev, int slave,
108097549c34SHans Petter Selasky 			  struct mlx4_vhcr *vhcr,
108197549c34SHans Petter Selasky 			  struct mlx4_cmd_mailbox *inbox,
108297549c34SHans Petter Selasky 			  struct mlx4_cmd_mailbox *outbox,
108397549c34SHans Petter Selasky 			  struct mlx4_cmd_info *cmd);
108497549c34SHans Petter Selasky int mlx4_QUERY_CQ_wrapper(struct mlx4_dev *dev, int slave,
108597549c34SHans Petter Selasky 			  struct mlx4_vhcr *vhcr,
108697549c34SHans Petter Selasky 			  struct mlx4_cmd_mailbox *inbox,
108797549c34SHans Petter Selasky 			  struct mlx4_cmd_mailbox *outbox,
108897549c34SHans Petter Selasky 			  struct mlx4_cmd_info *cmd);
108997549c34SHans Petter Selasky int mlx4_MODIFY_CQ_wrapper(struct mlx4_dev *dev, int slave,
109097549c34SHans Petter Selasky 			  struct mlx4_vhcr *vhcr,
109197549c34SHans Petter Selasky 			  struct mlx4_cmd_mailbox *inbox,
109297549c34SHans Petter Selasky 			  struct mlx4_cmd_mailbox *outbox,
109397549c34SHans Petter Selasky 			   struct mlx4_cmd_info *cmd);
109497549c34SHans Petter Selasky int mlx4_SW2HW_SRQ_wrapper(struct mlx4_dev *dev, int slave,
109597549c34SHans Petter Selasky 			   struct mlx4_vhcr *vhcr,
109697549c34SHans Petter Selasky 			   struct mlx4_cmd_mailbox *inbox,
109797549c34SHans Petter Selasky 			   struct mlx4_cmd_mailbox *outbox,
109897549c34SHans Petter Selasky 			   struct mlx4_cmd_info *cmd);
109997549c34SHans Petter Selasky int mlx4_HW2SW_SRQ_wrapper(struct mlx4_dev *dev, int slave,
110097549c34SHans Petter Selasky 			   struct mlx4_vhcr *vhcr,
110197549c34SHans Petter Selasky 			   struct mlx4_cmd_mailbox *inbox,
110297549c34SHans Petter Selasky 			   struct mlx4_cmd_mailbox *outbox,
110397549c34SHans Petter Selasky 			   struct mlx4_cmd_info *cmd);
110497549c34SHans Petter Selasky int mlx4_QUERY_SRQ_wrapper(struct mlx4_dev *dev, int slave,
110597549c34SHans Petter Selasky 			   struct mlx4_vhcr *vhcr,
110697549c34SHans Petter Selasky 			   struct mlx4_cmd_mailbox *inbox,
110797549c34SHans Petter Selasky 			   struct mlx4_cmd_mailbox *outbox,
110897549c34SHans Petter Selasky 			   struct mlx4_cmd_info *cmd);
110997549c34SHans Petter Selasky int mlx4_ARM_SRQ_wrapper(struct mlx4_dev *dev, int slave,
111097549c34SHans Petter Selasky 			 struct mlx4_vhcr *vhcr,
111197549c34SHans Petter Selasky 			 struct mlx4_cmd_mailbox *inbox,
111297549c34SHans Petter Selasky 			 struct mlx4_cmd_mailbox *outbox,
111397549c34SHans Petter Selasky 			 struct mlx4_cmd_info *cmd);
111497549c34SHans Petter Selasky int mlx4_GEN_QP_wrapper(struct mlx4_dev *dev, int slave,
111597549c34SHans Petter Selasky 			struct mlx4_vhcr *vhcr,
111697549c34SHans Petter Selasky 			struct mlx4_cmd_mailbox *inbox,
111797549c34SHans Petter Selasky 			struct mlx4_cmd_mailbox *outbox,
111897549c34SHans Petter Selasky 			struct mlx4_cmd_info *cmd);
111997549c34SHans Petter Selasky int mlx4_RST2INIT_QP_wrapper(struct mlx4_dev *dev, int slave,
112097549c34SHans Petter Selasky 			     struct mlx4_vhcr *vhcr,
112197549c34SHans Petter Selasky 			     struct mlx4_cmd_mailbox *inbox,
112297549c34SHans Petter Selasky 			     struct mlx4_cmd_mailbox *outbox,
112397549c34SHans Petter Selasky 			     struct mlx4_cmd_info *cmd);
112497549c34SHans Petter Selasky int mlx4_INIT2INIT_QP_wrapper(struct mlx4_dev *dev, int slave,
112597549c34SHans Petter Selasky 			      struct mlx4_vhcr *vhcr,
112697549c34SHans Petter Selasky 			      struct mlx4_cmd_mailbox *inbox,
112797549c34SHans Petter Selasky 			      struct mlx4_cmd_mailbox *outbox,
112897549c34SHans Petter Selasky 			      struct mlx4_cmd_info *cmd);
112997549c34SHans Petter Selasky int mlx4_INIT2RTR_QP_wrapper(struct mlx4_dev *dev, int slave,
113097549c34SHans Petter Selasky 			     struct mlx4_vhcr *vhcr,
113197549c34SHans Petter Selasky 			     struct mlx4_cmd_mailbox *inbox,
113297549c34SHans Petter Selasky 			     struct mlx4_cmd_mailbox *outbox,
113397549c34SHans Petter Selasky 			     struct mlx4_cmd_info *cmd);
113497549c34SHans Petter Selasky int mlx4_RTR2RTS_QP_wrapper(struct mlx4_dev *dev, int slave,
113597549c34SHans Petter Selasky 			    struct mlx4_vhcr *vhcr,
113697549c34SHans Petter Selasky 			    struct mlx4_cmd_mailbox *inbox,
113797549c34SHans Petter Selasky 			    struct mlx4_cmd_mailbox *outbox,
113897549c34SHans Petter Selasky 			    struct mlx4_cmd_info *cmd);
113997549c34SHans Petter Selasky int mlx4_RTS2RTS_QP_wrapper(struct mlx4_dev *dev, int slave,
114097549c34SHans Petter Selasky 			    struct mlx4_vhcr *vhcr,
114197549c34SHans Petter Selasky 			    struct mlx4_cmd_mailbox *inbox,
114297549c34SHans Petter Selasky 			    struct mlx4_cmd_mailbox *outbox,
114397549c34SHans Petter Selasky 			    struct mlx4_cmd_info *cmd);
114497549c34SHans Petter Selasky int mlx4_SQERR2RTS_QP_wrapper(struct mlx4_dev *dev, int slave,
114597549c34SHans Petter Selasky 			      struct mlx4_vhcr *vhcr,
114697549c34SHans Petter Selasky 			      struct mlx4_cmd_mailbox *inbox,
114797549c34SHans Petter Selasky 			      struct mlx4_cmd_mailbox *outbox,
114897549c34SHans Petter Selasky 			      struct mlx4_cmd_info *cmd);
114997549c34SHans Petter Selasky int mlx4_2ERR_QP_wrapper(struct mlx4_dev *dev, int slave,
115097549c34SHans Petter Selasky 			 struct mlx4_vhcr *vhcr,
115197549c34SHans Petter Selasky 			 struct mlx4_cmd_mailbox *inbox,
115297549c34SHans Petter Selasky 			 struct mlx4_cmd_mailbox *outbox,
115397549c34SHans Petter Selasky 			 struct mlx4_cmd_info *cmd);
115497549c34SHans Petter Selasky int mlx4_RTS2SQD_QP_wrapper(struct mlx4_dev *dev, int slave,
115597549c34SHans Petter Selasky 			    struct mlx4_vhcr *vhcr,
115697549c34SHans Petter Selasky 			    struct mlx4_cmd_mailbox *inbox,
115797549c34SHans Petter Selasky 			    struct mlx4_cmd_mailbox *outbox,
115897549c34SHans Petter Selasky 			    struct mlx4_cmd_info *cmd);
115997549c34SHans Petter Selasky int mlx4_SQD2SQD_QP_wrapper(struct mlx4_dev *dev, int slave,
116097549c34SHans Petter Selasky 			    struct mlx4_vhcr *vhcr,
116197549c34SHans Petter Selasky 			    struct mlx4_cmd_mailbox *inbox,
116297549c34SHans Petter Selasky 			    struct mlx4_cmd_mailbox *outbox,
116397549c34SHans Petter Selasky 			    struct mlx4_cmd_info *cmd);
116497549c34SHans Petter Selasky int mlx4_SQD2RTS_QP_wrapper(struct mlx4_dev *dev, int slave,
116597549c34SHans Petter Selasky 			    struct mlx4_vhcr *vhcr,
116697549c34SHans Petter Selasky 			    struct mlx4_cmd_mailbox *inbox,
116797549c34SHans Petter Selasky 			    struct mlx4_cmd_mailbox *outbox,
116897549c34SHans Petter Selasky 			    struct mlx4_cmd_info *cmd);
116997549c34SHans Petter Selasky int mlx4_2RST_QP_wrapper(struct mlx4_dev *dev, int slave,
117097549c34SHans Petter Selasky 			 struct mlx4_vhcr *vhcr,
117197549c34SHans Petter Selasky 			 struct mlx4_cmd_mailbox *inbox,
117297549c34SHans Petter Selasky 			 struct mlx4_cmd_mailbox *outbox,
117397549c34SHans Petter Selasky 			 struct mlx4_cmd_info *cmd);
117497549c34SHans Petter Selasky int mlx4_QUERY_QP_wrapper(struct mlx4_dev *dev, int slave,
117597549c34SHans Petter Selasky 			  struct mlx4_vhcr *vhcr,
117697549c34SHans Petter Selasky 			  struct mlx4_cmd_mailbox *inbox,
117797549c34SHans Petter Selasky 			  struct mlx4_cmd_mailbox *outbox,
117897549c34SHans Petter Selasky 			  struct mlx4_cmd_info *cmd);
117997549c34SHans Petter Selasky 
118097549c34SHans Petter Selasky int mlx4_GEN_EQE(struct mlx4_dev *dev, int slave, struct mlx4_eqe *eqe);
118197549c34SHans Petter Selasky 
1182c3191c2eSHans Petter Selasky enum {
1183c3191c2eSHans Petter Selasky 	MLX4_CMD_CLEANUP_STRUCT = 1UL << 0,
1184c3191c2eSHans Petter Selasky 	MLX4_CMD_CLEANUP_POOL	= 1UL << 1,
1185c3191c2eSHans Petter Selasky 	MLX4_CMD_CLEANUP_HCR	= 1UL << 2,
1186c3191c2eSHans Petter Selasky 	MLX4_CMD_CLEANUP_VHCR	= 1UL << 3,
1187c3191c2eSHans Petter Selasky 	MLX4_CMD_CLEANUP_ALL	= (MLX4_CMD_CLEANUP_VHCR << 1) - 1
1188c3191c2eSHans Petter Selasky };
1189c3191c2eSHans Petter Selasky 
119097549c34SHans Petter Selasky int mlx4_cmd_init(struct mlx4_dev *dev);
1191c3191c2eSHans Petter Selasky void mlx4_cmd_cleanup(struct mlx4_dev *dev, int cleanup_mask);
119297549c34SHans Petter Selasky int mlx4_multi_func_init(struct mlx4_dev *dev);
1193c3191c2eSHans Petter Selasky int mlx4_ARM_COMM_CHANNEL(struct mlx4_dev *dev);
119497549c34SHans Petter Selasky void mlx4_multi_func_cleanup(struct mlx4_dev *dev);
119597549c34SHans Petter Selasky void mlx4_cmd_event(struct mlx4_dev *dev, u16 token, u8 status, u64 out_param);
119697549c34SHans Petter Selasky int mlx4_cmd_use_events(struct mlx4_dev *dev);
119797549c34SHans Petter Selasky void mlx4_cmd_use_polling(struct mlx4_dev *dev);
119897549c34SHans Petter Selasky 
119997549c34SHans Petter Selasky int mlx4_comm_cmd(struct mlx4_dev *dev, u8 cmd, u16 param,
1200c3191c2eSHans Petter Selasky 		  u16 op, unsigned long timeout);
120197549c34SHans Petter Selasky 
1202c3191c2eSHans Petter Selasky void mlx4_cq_tasklet_cb(unsigned long data);
120397549c34SHans Petter Selasky void mlx4_cq_completion(struct mlx4_dev *dev, u32 cqn);
120497549c34SHans Petter Selasky void mlx4_cq_event(struct mlx4_dev *dev, u32 cqn, int event_type);
120597549c34SHans Petter Selasky 
120697549c34SHans Petter Selasky void mlx4_qp_event(struct mlx4_dev *dev, u32 qpn, int event_type);
120797549c34SHans Petter Selasky 
120897549c34SHans Petter Selasky void mlx4_srq_event(struct mlx4_dev *dev, u32 srqn, int event_type);
120997549c34SHans Petter Selasky 
1210c3191c2eSHans Petter Selasky void mlx4_enter_error_state(struct mlx4_dev_persistent *persist);
121197549c34SHans Petter Selasky 
121297549c34SHans Petter Selasky int mlx4_SENSE_PORT(struct mlx4_dev *dev, int port,
121397549c34SHans Petter Selasky 		    enum mlx4_port_type *type);
121497549c34SHans Petter Selasky void mlx4_do_sense_ports(struct mlx4_dev *dev,
121597549c34SHans Petter Selasky 			 enum mlx4_port_type *stype,
121697549c34SHans Petter Selasky 			 enum mlx4_port_type *defaults);
121797549c34SHans Petter Selasky void mlx4_start_sense(struct mlx4_dev *dev);
121897549c34SHans Petter Selasky void mlx4_stop_sense(struct mlx4_dev *dev);
121997549c34SHans Petter Selasky void mlx4_sense_init(struct mlx4_dev *dev);
122097549c34SHans Petter Selasky int mlx4_check_port_params(struct mlx4_dev *dev,
122197549c34SHans Petter Selasky 			   enum mlx4_port_type *port_type);
122297549c34SHans Petter Selasky int mlx4_change_port_types(struct mlx4_dev *dev,
122397549c34SHans Petter Selasky 			   enum mlx4_port_type *port_types);
122497549c34SHans Petter Selasky 
122597549c34SHans Petter Selasky void mlx4_init_mac_table(struct mlx4_dev *dev, struct mlx4_mac_table *table);
122697549c34SHans Petter Selasky void mlx4_init_vlan_table(struct mlx4_dev *dev, struct mlx4_vlan_table *table);
1227c3191c2eSHans Petter Selasky void mlx4_init_roce_gid_table(struct mlx4_dev *dev,
1228c3191c2eSHans Petter Selasky 			      struct mlx4_roce_gid_table *table);
122997549c34SHans Petter Selasky void __mlx4_unregister_vlan(struct mlx4_dev *dev, u8 port, u16 vlan);
123097549c34SHans Petter Selasky int __mlx4_register_vlan(struct mlx4_dev *dev, u8 port, u16 vlan, int *index);
1231c3191c2eSHans Petter Selasky int mlx4_bond_vlan_table(struct mlx4_dev *dev);
1232c3191c2eSHans Petter Selasky int mlx4_unbond_vlan_table(struct mlx4_dev *dev);
1233c3191c2eSHans Petter Selasky int mlx4_bond_mac_table(struct mlx4_dev *dev);
1234c3191c2eSHans Petter Selasky int mlx4_unbond_mac_table(struct mlx4_dev *dev);
123597549c34SHans Petter Selasky 
123697549c34SHans Petter Selasky int mlx4_SET_PORT(struct mlx4_dev *dev, u8 port, int pkey_tbl_sz);
123797549c34SHans Petter Selasky /* resource tracker functions*/
123897549c34SHans Petter Selasky int mlx4_get_slave_from_resource_id(struct mlx4_dev *dev,
123997549c34SHans Petter Selasky 				    enum mlx4_resource resource_type,
124097549c34SHans Petter Selasky 				    u64 resource_id, int *slave);
124197549c34SHans Petter Selasky void mlx4_delete_all_resources_for_slave(struct mlx4_dev *dev, int slave_id);
1242c3191c2eSHans Petter Selasky void mlx4_reset_roce_gids(struct mlx4_dev *dev, int slave);
124397549c34SHans Petter Selasky int mlx4_init_resource_tracker(struct mlx4_dev *dev);
124497549c34SHans Petter Selasky 
124597549c34SHans Petter Selasky void mlx4_free_resource_tracker(struct mlx4_dev *dev,
124697549c34SHans Petter Selasky 				enum mlx4_res_tracker_free_type type);
124797549c34SHans Petter Selasky 
124897549c34SHans Petter Selasky int mlx4_QUERY_FW_wrapper(struct mlx4_dev *dev, int slave,
124997549c34SHans Petter Selasky 			  struct mlx4_vhcr *vhcr,
125097549c34SHans Petter Selasky 			  struct mlx4_cmd_mailbox *inbox,
125197549c34SHans Petter Selasky 			  struct mlx4_cmd_mailbox *outbox,
125297549c34SHans Petter Selasky 			  struct mlx4_cmd_info *cmd);
125397549c34SHans Petter Selasky int mlx4_SET_PORT_wrapper(struct mlx4_dev *dev, int slave,
125497549c34SHans Petter Selasky 			  struct mlx4_vhcr *vhcr,
125597549c34SHans Petter Selasky 			  struct mlx4_cmd_mailbox *inbox,
125697549c34SHans Petter Selasky 			  struct mlx4_cmd_mailbox *outbox,
125797549c34SHans Petter Selasky 			  struct mlx4_cmd_info *cmd);
125897549c34SHans Petter Selasky int mlx4_INIT_PORT_wrapper(struct mlx4_dev *dev, int slave,
125997549c34SHans Petter Selasky 			   struct mlx4_vhcr *vhcr,
126097549c34SHans Petter Selasky 			   struct mlx4_cmd_mailbox *inbox,
126197549c34SHans Petter Selasky 			   struct mlx4_cmd_mailbox *outbox,
126297549c34SHans Petter Selasky 			   struct mlx4_cmd_info *cmd);
126397549c34SHans Petter Selasky int mlx4_CLOSE_PORT_wrapper(struct mlx4_dev *dev, int slave,
126497549c34SHans Petter Selasky 			    struct mlx4_vhcr *vhcr,
126597549c34SHans Petter Selasky 			    struct mlx4_cmd_mailbox *inbox,
126697549c34SHans Petter Selasky 			    struct mlx4_cmd_mailbox *outbox,
126797549c34SHans Petter Selasky 			    struct mlx4_cmd_info *cmd);
126897549c34SHans Petter Selasky int mlx4_QUERY_DEV_CAP_wrapper(struct mlx4_dev *dev, int slave,
126997549c34SHans Petter Selasky 			       struct mlx4_vhcr *vhcr,
127097549c34SHans Petter Selasky 			       struct mlx4_cmd_mailbox *inbox,
127197549c34SHans Petter Selasky 			       struct mlx4_cmd_mailbox *outbox,
127297549c34SHans Petter Selasky 			       struct mlx4_cmd_info *cmd);
127397549c34SHans Petter Selasky int mlx4_QUERY_PORT_wrapper(struct mlx4_dev *dev, int slave,
127497549c34SHans Petter Selasky 			    struct mlx4_vhcr *vhcr,
127597549c34SHans Petter Selasky 			    struct mlx4_cmd_mailbox *inbox,
127697549c34SHans Petter Selasky 			    struct mlx4_cmd_mailbox *outbox,
127797549c34SHans Petter Selasky 			    struct mlx4_cmd_info *cmd);
127897549c34SHans Petter Selasky int mlx4_get_port_ib_caps(struct mlx4_dev *dev, u8 port, __be32 *caps);
127997549c34SHans Petter Selasky 
128097549c34SHans Petter Selasky int mlx4_get_slave_pkey_gid_tbl_len(struct mlx4_dev *dev, u8 port,
128197549c34SHans Petter Selasky 				    int *gid_tbl_len, int *pkey_tbl_len);
128297549c34SHans Petter Selasky 
128397549c34SHans Petter Selasky int mlx4_QP_ATTACH_wrapper(struct mlx4_dev *dev, int slave,
128497549c34SHans Petter Selasky 			   struct mlx4_vhcr *vhcr,
128597549c34SHans Petter Selasky 			   struct mlx4_cmd_mailbox *inbox,
128697549c34SHans Petter Selasky 			   struct mlx4_cmd_mailbox *outbox,
128797549c34SHans Petter Selasky 			   struct mlx4_cmd_info *cmd);
128897549c34SHans Petter Selasky 
1289c3191c2eSHans Petter Selasky int mlx4_UPDATE_QP_wrapper(struct mlx4_dev *dev, int slave,
1290c3191c2eSHans Petter Selasky 			   struct mlx4_vhcr *vhcr,
1291c3191c2eSHans Petter Selasky 			   struct mlx4_cmd_mailbox *inbox,
1292c3191c2eSHans Petter Selasky 			   struct mlx4_cmd_mailbox *outbox,
1293c3191c2eSHans Petter Selasky 			   struct mlx4_cmd_info *cmd);
1294c3191c2eSHans Petter Selasky 
129597549c34SHans Petter Selasky int mlx4_PROMISC_wrapper(struct mlx4_dev *dev, int slave,
129697549c34SHans Petter Selasky 			 struct mlx4_vhcr *vhcr,
129797549c34SHans Petter Selasky 			 struct mlx4_cmd_mailbox *inbox,
129897549c34SHans Petter Selasky 			 struct mlx4_cmd_mailbox *outbox,
129997549c34SHans Petter Selasky 			 struct mlx4_cmd_info *cmd);
130097549c34SHans Petter Selasky int mlx4_qp_detach_common(struct mlx4_dev *dev, struct mlx4_qp *qp, u8 gid[16],
130197549c34SHans Petter Selasky 			  enum mlx4_protocol prot, enum mlx4_steer_type steer);
130297549c34SHans Petter Selasky int mlx4_qp_attach_common(struct mlx4_dev *dev, struct mlx4_qp *qp, u8 gid[16],
130397549c34SHans Petter Selasky 			  int block_mcast_loopback, enum mlx4_protocol prot,
130497549c34SHans Petter Selasky 			  enum mlx4_steer_type steer);
130597549c34SHans Petter Selasky int mlx4_trans_to_dmfs_attach(struct mlx4_dev *dev, struct mlx4_qp *qp,
130697549c34SHans Petter Selasky 			      u8 gid[16], u8 port,
130797549c34SHans Petter Selasky 			      int block_mcast_loopback,
130897549c34SHans Petter Selasky 			      enum mlx4_protocol prot, u64 *reg_id);
130997549c34SHans Petter Selasky int mlx4_SET_MCAST_FLTR_wrapper(struct mlx4_dev *dev, int slave,
131097549c34SHans Petter Selasky 				struct mlx4_vhcr *vhcr,
131197549c34SHans Petter Selasky 				struct mlx4_cmd_mailbox *inbox,
131297549c34SHans Petter Selasky 				struct mlx4_cmd_mailbox *outbox,
131397549c34SHans Petter Selasky 				struct mlx4_cmd_info *cmd);
131497549c34SHans Petter Selasky int mlx4_SET_VLAN_FLTR_wrapper(struct mlx4_dev *dev, int slave,
131597549c34SHans Petter Selasky 			       struct mlx4_vhcr *vhcr,
131697549c34SHans Petter Selasky 			       struct mlx4_cmd_mailbox *inbox,
131797549c34SHans Petter Selasky 			       struct mlx4_cmd_mailbox *outbox,
131897549c34SHans Petter Selasky 			       struct mlx4_cmd_info *cmd);
131997549c34SHans Petter Selasky int mlx4_common_set_vlan_fltr(struct mlx4_dev *dev, int function,
132097549c34SHans Petter Selasky 				     int port, void *buf);
132197549c34SHans Petter Selasky int mlx4_DUMP_ETH_STATS_wrapper(struct mlx4_dev *dev, int slave,
132297549c34SHans Petter Selasky 				   struct mlx4_vhcr *vhcr,
132397549c34SHans Petter Selasky 				   struct mlx4_cmd_mailbox *inbox,
132497549c34SHans Petter Selasky 				   struct mlx4_cmd_mailbox *outbox,
132597549c34SHans Petter Selasky 				struct mlx4_cmd_info *cmd);
132697549c34SHans Petter Selasky int mlx4_PKEY_TABLE_wrapper(struct mlx4_dev *dev, int slave,
132797549c34SHans Petter Selasky 			    struct mlx4_vhcr *vhcr,
132897549c34SHans Petter Selasky 			    struct mlx4_cmd_mailbox *inbox,
132997549c34SHans Petter Selasky 			    struct mlx4_cmd_mailbox *outbox,
133097549c34SHans Petter Selasky 			    struct mlx4_cmd_info *cmd);
133197549c34SHans Petter Selasky int mlx4_QUERY_IF_STAT_wrapper(struct mlx4_dev *dev, int slave,
133297549c34SHans Petter Selasky 			       struct mlx4_vhcr *vhcr,
133397549c34SHans Petter Selasky 			       struct mlx4_cmd_mailbox *inbox,
133497549c34SHans Petter Selasky 			       struct mlx4_cmd_mailbox *outbox,
133597549c34SHans Petter Selasky 			       struct mlx4_cmd_info *cmd);
133697549c34SHans Petter Selasky int mlx4_QP_FLOW_STEERING_ATTACH_wrapper(struct mlx4_dev *dev, int slave,
133797549c34SHans Petter Selasky 					 struct mlx4_vhcr *vhcr,
133897549c34SHans Petter Selasky 					 struct mlx4_cmd_mailbox *inbox,
133997549c34SHans Petter Selasky 					 struct mlx4_cmd_mailbox *outbox,
134097549c34SHans Petter Selasky 					 struct mlx4_cmd_info *cmd);
134197549c34SHans Petter Selasky int mlx4_QP_FLOW_STEERING_DETACH_wrapper(struct mlx4_dev *dev, int slave,
134297549c34SHans Petter Selasky 					 struct mlx4_vhcr *vhcr,
134397549c34SHans Petter Selasky 					 struct mlx4_cmd_mailbox *inbox,
134497549c34SHans Petter Selasky 					 struct mlx4_cmd_mailbox *outbox,
134597549c34SHans Petter Selasky 					 struct mlx4_cmd_info *cmd);
1346c3191c2eSHans Petter Selasky int mlx4_ACCESS_REG_wrapper(struct mlx4_dev *dev, int slave,
134797549c34SHans Petter Selasky 			    struct mlx4_vhcr *vhcr,
134897549c34SHans Petter Selasky 			    struct mlx4_cmd_mailbox *inbox,
134997549c34SHans Petter Selasky 			    struct mlx4_cmd_mailbox *outbox,
135097549c34SHans Petter Selasky 			    struct mlx4_cmd_info *cmd);
135197549c34SHans Petter Selasky 
135297549c34SHans Petter Selasky int mlx4_get_mgm_entry_size(struct mlx4_dev *dev);
135397549c34SHans Petter Selasky int mlx4_get_qp_per_mgm(struct mlx4_dev *dev);
135497549c34SHans Petter Selasky 
set_param_l(u64 * arg,u32 val)135597549c34SHans Petter Selasky static inline void set_param_l(u64 *arg, u32 val)
135697549c34SHans Petter Selasky {
135797549c34SHans Petter Selasky 	*arg = (*arg & 0xffffffff00000000ULL) | (u64) val;
135897549c34SHans Petter Selasky }
135997549c34SHans Petter Selasky 
set_param_h(u64 * arg,u32 val)136097549c34SHans Petter Selasky static inline void set_param_h(u64 *arg, u32 val)
136197549c34SHans Petter Selasky {
136297549c34SHans Petter Selasky 	*arg = (*arg & 0xffffffff) | ((u64) val << 32);
136397549c34SHans Petter Selasky }
136497549c34SHans Petter Selasky 
get_param_l(u64 * arg)136597549c34SHans Petter Selasky static inline u32 get_param_l(u64 *arg)
136697549c34SHans Petter Selasky {
136797549c34SHans Petter Selasky 	return (u32) (*arg & 0xffffffff);
136897549c34SHans Petter Selasky }
136997549c34SHans Petter Selasky 
get_param_h(u64 * arg)137097549c34SHans Petter Selasky static inline u32 get_param_h(u64 *arg)
137197549c34SHans Petter Selasky {
137297549c34SHans Petter Selasky 	return (u32)(*arg >> 32);
137397549c34SHans Petter Selasky }
137497549c34SHans Petter Selasky 
mlx4_tlock(struct mlx4_dev * dev)137597549c34SHans Petter Selasky static inline spinlock_t *mlx4_tlock(struct mlx4_dev *dev)
137697549c34SHans Petter Selasky {
137797549c34SHans Petter Selasky 	return &mlx4_priv(dev)->mfunc.master.res_tracker.lock;
137897549c34SHans Petter Selasky }
137997549c34SHans Petter Selasky 
138097549c34SHans Petter Selasky #define NOT_MASKED_PD_BITS 17
138197549c34SHans Petter Selasky 
1382c3191c2eSHans Petter Selasky void mlx4_vf_immed_vlan_work_handler(struct work_struct *_work);
138397549c34SHans Petter Selasky 
138497549c34SHans Petter Selasky void mlx4_init_quotas(struct mlx4_dev *dev);
138597549c34SHans Petter Selasky 
1386c3191c2eSHans Petter Selasky /* for VFs, replace zero MACs with randomly-generated MACs at driver start */
1387c3191c2eSHans Petter Selasky void mlx4_replace_zero_macs(struct mlx4_dev *dev);
1388c3191c2eSHans Petter Selasky int mlx4_get_slave_num_gids(struct mlx4_dev *dev, int slave, int port);
1389c3191c2eSHans Petter Selasky /* Returns the VF index of slave */
1390c3191c2eSHans Petter Selasky int mlx4_get_vf_indx(struct mlx4_dev *dev, int slave);
1391c3191c2eSHans Petter Selasky int mlx4_config_mad_demux(struct mlx4_dev *dev);
1392c3191c2eSHans Petter Selasky int mlx4_do_bond(struct mlx4_dev *dev, bool enable);
1393c3191c2eSHans Petter Selasky int mlx4_bond_fs_rules(struct mlx4_dev *dev);
1394c3191c2eSHans Petter Selasky int mlx4_unbond_fs_rules(struct mlx4_dev *dev);
1395c3191c2eSHans Petter Selasky 
1396c3191c2eSHans Petter Selasky enum mlx4_zone_flags {
1397c3191c2eSHans Petter Selasky 	MLX4_ZONE_ALLOW_ALLOC_FROM_LOWER_PRIO	= 1UL << 0,
1398c3191c2eSHans Petter Selasky 	MLX4_ZONE_ALLOW_ALLOC_FROM_EQ_PRIO	= 1UL << 1,
1399c3191c2eSHans Petter Selasky 	MLX4_ZONE_FALLBACK_TO_HIGHER_PRIO	= 1UL << 2,
1400c3191c2eSHans Petter Selasky 	MLX4_ZONE_USE_RR			= 1UL << 3,
1401c3191c2eSHans Petter Selasky };
1402c3191c2eSHans Petter Selasky 
1403c3191c2eSHans Petter Selasky enum mlx4_zone_alloc_flags {
1404c3191c2eSHans Petter Selasky 	/* No two objects could overlap between zones. UID
1405c3191c2eSHans Petter Selasky 	 * could be left unused. If this flag is given and
1406c3191c2eSHans Petter Selasky 	 * two overlapped zones are used, an object will be free'd
1407c3191c2eSHans Petter Selasky 	 * from the smallest possible matching zone.
1408c3191c2eSHans Petter Selasky 	 */
1409c3191c2eSHans Petter Selasky 	MLX4_ZONE_ALLOC_FLAGS_NO_OVERLAP	= 1UL << 0,
1410c3191c2eSHans Petter Selasky };
1411c3191c2eSHans Petter Selasky 
1412c3191c2eSHans Petter Selasky struct mlx4_zone_allocator;
1413c3191c2eSHans Petter Selasky 
1414c3191c2eSHans Petter Selasky /* Create a new zone allocator */
1415c3191c2eSHans Petter Selasky struct mlx4_zone_allocator *mlx4_zone_allocator_create(enum mlx4_zone_alloc_flags flags);
1416c3191c2eSHans Petter Selasky 
1417c3191c2eSHans Petter Selasky /* Attach a mlx4_bitmap <bitmap> of priority <priority> to the zone allocator
1418c3191c2eSHans Petter Selasky  * <zone_alloc>. Allocating an object from this zone adds an offset <offset>.
1419c3191c2eSHans Petter Selasky  * Similarly, when searching for an object to free, this offset it taken into
1420c3191c2eSHans Petter Selasky  * account. The use_rr mlx4_ib parameter for allocating objects from this <bitmap>
1421c3191c2eSHans Petter Selasky  * is given through the MLX4_ZONE_USE_RR flag in <flags>.
1422c3191c2eSHans Petter Selasky  * When an allocation fails, <zone_alloc> tries to allocate from other zones
1423c3191c2eSHans Petter Selasky  * according to the policy set by <flags>. <puid> is the unique identifier
1424c3191c2eSHans Petter Selasky  * received to this zone.
1425c3191c2eSHans Petter Selasky  */
1426c3191c2eSHans Petter Selasky int mlx4_zone_add_one(struct mlx4_zone_allocator *zone_alloc,
1427c3191c2eSHans Petter Selasky 		      struct mlx4_bitmap *bitmap,
1428c3191c2eSHans Petter Selasky 		      u32 flags,
1429c3191c2eSHans Petter Selasky 		      int priority,
1430c3191c2eSHans Petter Selasky 		      int offset,
1431c3191c2eSHans Petter Selasky 		      u32 *puid);
1432c3191c2eSHans Petter Selasky 
1433c3191c2eSHans Petter Selasky /* Remove bitmap indicated by <uid> from <zone_alloc> */
1434c3191c2eSHans Petter Selasky int mlx4_zone_remove_one(struct mlx4_zone_allocator *zone_alloc, u32 uid);
1435c3191c2eSHans Petter Selasky 
1436c3191c2eSHans Petter Selasky /* Delete the zone allocator <zone_alloc. This function doesn't destroy
1437c3191c2eSHans Petter Selasky  * the attached bitmaps.
1438c3191c2eSHans Petter Selasky  */
1439c3191c2eSHans Petter Selasky void mlx4_zone_allocator_destroy(struct mlx4_zone_allocator *zone_alloc);
1440c3191c2eSHans Petter Selasky 
1441c3191c2eSHans Petter Selasky /* Allocate <count> objects with align <align> and skip_mask <skip_mask>
1442c3191c2eSHans Petter Selasky  * from the mlx4_bitmap whose uid is <uid>. The bitmap which we actually
1443c3191c2eSHans Petter Selasky  * allocated from is returned in <puid>. If the allocation fails, a negative
1444c3191c2eSHans Petter Selasky  * number is returned. Otherwise, the offset of the first object is returned.
1445c3191c2eSHans Petter Selasky  */
1446c3191c2eSHans Petter Selasky u32 mlx4_zone_alloc_entries(struct mlx4_zone_allocator *zones, u32 uid, int count,
1447c3191c2eSHans Petter Selasky 			    int align, u32 skip_mask, u32 *puid);
1448c3191c2eSHans Petter Selasky 
1449c3191c2eSHans Petter Selasky /* Free <count> objects, start from <obj> of the uid <uid> from zone_allocator
1450c3191c2eSHans Petter Selasky  * <zones>.
1451c3191c2eSHans Petter Selasky  */
1452c3191c2eSHans Petter Selasky u32 mlx4_zone_free_entries(struct mlx4_zone_allocator *zones,
1453c3191c2eSHans Petter Selasky 			   u32 uid, u32 obj, u32 count);
1454c3191c2eSHans Petter Selasky 
1455c3191c2eSHans Petter Selasky /* If <zones> was allocated with MLX4_ZONE_ALLOC_FLAGS_NO_OVERLAP, instead of
1456c3191c2eSHans Petter Selasky  * specifying the uid when freeing an object, zone allocator could figure it by
1457c3191c2eSHans Petter Selasky  * itself. Other parameters are similar to mlx4_zone_free.
1458c3191c2eSHans Petter Selasky  */
1459c3191c2eSHans Petter Selasky u32 mlx4_zone_free_entries_unique(struct mlx4_zone_allocator *zones, u32 obj, u32 count);
1460c3191c2eSHans Petter Selasky 
1461c3191c2eSHans Petter Selasky /* Returns a pointer to mlx4_bitmap that was attached to <zones> with <uid> */
1462c3191c2eSHans Petter Selasky struct mlx4_bitmap *mlx4_zone_get_bitmap(struct mlx4_zone_allocator *zones, u32 uid);
146397549c34SHans Petter Selasky 
146497549c34SHans Petter Selasky #endif /* MLX4_H */
1465