197549c34SHans Petter Selasky /*
297549c34SHans Petter Selasky * Copyright (c) 2006, 2007 Cisco Systems. All rights reserved.
397549c34SHans Petter Selasky * Copyright (c) 2007, 2008 Mellanox Technologies. All rights reserved.
497549c34SHans Petter Selasky *
597549c34SHans Petter Selasky * This software is available to you under a choice of one of two
697549c34SHans Petter Selasky * licenses. You may choose to be licensed under the terms of the GNU
797549c34SHans Petter Selasky * General Public License (GPL) Version 2, available from the file
897549c34SHans Petter Selasky * COPYING in the main directory of this source tree, or the
997549c34SHans Petter Selasky * OpenIB.org BSD license below:
1097549c34SHans Petter Selasky *
1197549c34SHans Petter Selasky * Redistribution and use in source and binary forms, with or
1297549c34SHans Petter Selasky * without modification, are permitted provided that the following
1397549c34SHans Petter Selasky * conditions are met:
1497549c34SHans Petter Selasky *
1597549c34SHans Petter Selasky * - Redistributions of source code must retain the above
1697549c34SHans Petter Selasky * copyright notice, this list of conditions and the following
1797549c34SHans Petter Selasky * disclaimer.
1897549c34SHans Petter Selasky *
1997549c34SHans Petter Selasky * - Redistributions in binary form must reproduce the above
2097549c34SHans Petter Selasky * copyright notice, this list of conditions and the following
2197549c34SHans Petter Selasky * disclaimer in the documentation and/or other materials
2297549c34SHans Petter Selasky * provided with the distribution.
2397549c34SHans Petter Selasky *
2497549c34SHans Petter Selasky * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
2597549c34SHans Petter Selasky * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
2697549c34SHans Petter Selasky * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
2797549c34SHans Petter Selasky * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
2897549c34SHans Petter Selasky * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
2997549c34SHans Petter Selasky * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
3097549c34SHans Petter Selasky * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
3197549c34SHans Petter Selasky * SOFTWARE.
3297549c34SHans Petter Selasky */
3397549c34SHans Petter Selasky
3497549c34SHans Petter Selasky #ifndef MLX4_IB_H
3597549c34SHans Petter Selasky #define MLX4_IB_H
3697549c34SHans Petter Selasky
3797549c34SHans Petter Selasky #include <linux/compiler.h>
3897549c34SHans Petter Selasky #include <linux/list.h>
3997549c34SHans Petter Selasky #include <linux/mutex.h>
4097549c34SHans Petter Selasky #include <linux/idr.h>
4197549c34SHans Petter Selasky #include <linux/rbtree.h>
4297549c34SHans Petter Selasky #include <linux/notifier.h>
4397549c34SHans Petter Selasky
448cc48704SHans Petter Selasky #include <asm/atomic64.h>
458cc48704SHans Petter Selasky
4697549c34SHans Petter Selasky #include <rdma/ib_verbs.h>
4797549c34SHans Petter Selasky #include <rdma/ib_umem.h>
4897549c34SHans Petter Selasky #include <rdma/ib_mad.h>
4997549c34SHans Petter Selasky #include <rdma/ib_sa.h>
5097549c34SHans Petter Selasky
5197549c34SHans Petter Selasky #include <dev/mlx4/device.h>
5297549c34SHans Petter Selasky #include <dev/mlx4/doorbell.h>
5397549c34SHans Petter Selasky
5497549c34SHans Petter Selasky #define MLX4_IB_DRV_NAME "mlx4_ib"
5597549c34SHans Petter Selasky
5697549c34SHans Petter Selasky #ifdef pr_fmt
5797549c34SHans Petter Selasky #undef pr_fmt
5897549c34SHans Petter Selasky #endif
5997549c34SHans Petter Selasky #define pr_fmt(fmt) "<" MLX4_IB_DRV_NAME "> %s: " fmt, __func__
6097549c34SHans Petter Selasky
6197549c34SHans Petter Selasky #define mlx4_ib_warn(ibdev, format, arg...) \
6297549c34SHans Petter Selasky dev_warn((ibdev)->dma_device, MLX4_IB_DRV_NAME ": " format, ## arg)
6397549c34SHans Petter Selasky
6497549c34SHans Petter Selasky enum {
6597549c34SHans Petter Selasky MLX4_IB_SQ_MIN_WQE_SHIFT = 6,
6697549c34SHans Petter Selasky MLX4_IB_MAX_HEADROOM = 2048
6797549c34SHans Petter Selasky };
6897549c34SHans Petter Selasky
6997549c34SHans Petter Selasky #define MLX4_IB_SQ_HEADROOM(shift) ((MLX4_IB_MAX_HEADROOM >> (shift)) + 1)
7097549c34SHans Petter Selasky #define MLX4_IB_SQ_MAX_SPARE (MLX4_IB_SQ_HEADROOM(MLX4_IB_SQ_MIN_WQE_SHIFT))
7197549c34SHans Petter Selasky
7297549c34SHans Petter Selasky /*module param to indicate if SM assigns the alias_GUID*/
7397549c34SHans Petter Selasky extern int mlx4_ib_sm_guid_assign;
7497549c34SHans Petter Selasky extern struct proc_dir_entry *mlx4_mrs_dir_entry;
7597549c34SHans Petter Selasky
7697549c34SHans Petter Selasky #define MLX4_IB_UC_STEER_QPN_ALIGN 1
778cc48704SHans Petter Selasky #define MLX4_IB_UC_MAX_NUM_QPS 256
7897549c34SHans Petter Selasky
798cc48704SHans Petter Selasky enum hw_bar_type {
808cc48704SHans Petter Selasky HW_BAR_BF,
818cc48704SHans Petter Selasky HW_BAR_DB,
828cc48704SHans Petter Selasky HW_BAR_CLOCK,
838cc48704SHans Petter Selasky HW_BAR_COUNT
848cc48704SHans Petter Selasky };
8597549c34SHans Petter Selasky
8697549c34SHans Petter Selasky struct mlx4_ib_ucontext {
8797549c34SHans Petter Selasky struct ib_ucontext ibucontext;
8897549c34SHans Petter Selasky struct mlx4_uar uar;
8997549c34SHans Petter Selasky struct list_head db_page_list;
9097549c34SHans Petter Selasky struct mutex db_page_mutex;
9197549c34SHans Petter Selasky };
9297549c34SHans Petter Selasky
9397549c34SHans Petter Selasky struct mlx4_ib_pd {
9497549c34SHans Petter Selasky struct ib_pd ibpd;
9597549c34SHans Petter Selasky u32 pdn;
9697549c34SHans Petter Selasky };
9797549c34SHans Petter Selasky
9897549c34SHans Petter Selasky struct mlx4_ib_xrcd {
9997549c34SHans Petter Selasky struct ib_xrcd ibxrcd;
10097549c34SHans Petter Selasky u32 xrcdn;
10197549c34SHans Petter Selasky struct ib_pd *pd;
10297549c34SHans Petter Selasky struct ib_cq *cq;
10397549c34SHans Petter Selasky };
10497549c34SHans Petter Selasky
10597549c34SHans Petter Selasky struct mlx4_ib_cq_buf {
10697549c34SHans Petter Selasky struct mlx4_buf buf;
10797549c34SHans Petter Selasky struct mlx4_mtt mtt;
10897549c34SHans Petter Selasky int entry_size;
10997549c34SHans Petter Selasky };
11097549c34SHans Petter Selasky
11197549c34SHans Petter Selasky struct mlx4_ib_cq_resize {
11297549c34SHans Petter Selasky struct mlx4_ib_cq_buf buf;
11397549c34SHans Petter Selasky int cqe;
11497549c34SHans Petter Selasky };
11597549c34SHans Petter Selasky
11697549c34SHans Petter Selasky struct mlx4_ib_cq {
11797549c34SHans Petter Selasky struct ib_cq ibcq;
11897549c34SHans Petter Selasky struct mlx4_cq mcq;
11997549c34SHans Petter Selasky struct mlx4_ib_cq_buf buf;
12097549c34SHans Petter Selasky struct mlx4_ib_cq_resize *resize_buf;
12197549c34SHans Petter Selasky struct mlx4_db db;
12297549c34SHans Petter Selasky spinlock_t lock;
12397549c34SHans Petter Selasky struct mutex resize_mutex;
12497549c34SHans Petter Selasky struct ib_umem *umem;
12597549c34SHans Petter Selasky struct ib_umem *resize_umem;
12697549c34SHans Petter Selasky int create_flags;
1278cc48704SHans Petter Selasky /* List of qps that it serves.*/
1288cc48704SHans Petter Selasky struct list_head send_qp_list;
1298cc48704SHans Petter Selasky struct list_head recv_qp_list;
13097549c34SHans Petter Selasky };
13197549c34SHans Petter Selasky
1328cc48704SHans Petter Selasky #define MLX4_MR_PAGES_ALIGN 0x40
1338cc48704SHans Petter Selasky
13497549c34SHans Petter Selasky struct mlx4_ib_mr {
13597549c34SHans Petter Selasky struct ib_mr ibmr;
1368cc48704SHans Petter Selasky __be64 *pages;
1378cc48704SHans Petter Selasky dma_addr_t page_map;
1388cc48704SHans Petter Selasky u32 npages;
1398cc48704SHans Petter Selasky u32 max_pages;
14097549c34SHans Petter Selasky struct mlx4_mr mmr;
14197549c34SHans Petter Selasky struct ib_umem *umem;
1428cc48704SHans Petter Selasky size_t page_map_size;
14397549c34SHans Petter Selasky };
14497549c34SHans Petter Selasky
14597549c34SHans Petter Selasky struct mlx4_ib_mw {
14697549c34SHans Petter Selasky struct ib_mw ibmw;
14797549c34SHans Petter Selasky struct mlx4_mw mmw;
14897549c34SHans Petter Selasky };
14997549c34SHans Petter Selasky
15097549c34SHans Petter Selasky struct mlx4_ib_fmr {
15197549c34SHans Petter Selasky struct ib_fmr ibfmr;
15297549c34SHans Petter Selasky struct mlx4_fmr mfmr;
15397549c34SHans Petter Selasky };
15497549c34SHans Petter Selasky
1558cc48704SHans Petter Selasky #define MAX_REGS_PER_FLOW 2
1568cc48704SHans Petter Selasky
1578cc48704SHans Petter Selasky struct mlx4_flow_reg_id {
1588cc48704SHans Petter Selasky u64 id;
1598cc48704SHans Petter Selasky u64 mirror;
1608cc48704SHans Petter Selasky };
1618cc48704SHans Petter Selasky
16297549c34SHans Petter Selasky struct mlx4_ib_flow {
16397549c34SHans Petter Selasky struct ib_flow ibflow;
16497549c34SHans Petter Selasky /* translating DMFS verbs sniffer rule to FW API requires two reg IDs */
1658cc48704SHans Petter Selasky struct mlx4_flow_reg_id reg_id[MAX_REGS_PER_FLOW];
16697549c34SHans Petter Selasky };
16797549c34SHans Petter Selasky
16897549c34SHans Petter Selasky struct mlx4_ib_wq {
16997549c34SHans Petter Selasky u64 *wrid;
17097549c34SHans Petter Selasky spinlock_t lock;
17197549c34SHans Petter Selasky int wqe_cnt;
17297549c34SHans Petter Selasky int max_post;
17397549c34SHans Petter Selasky int max_gs;
17497549c34SHans Petter Selasky int offset;
17597549c34SHans Petter Selasky int wqe_shift;
17697549c34SHans Petter Selasky unsigned head;
17797549c34SHans Petter Selasky unsigned tail;
17897549c34SHans Petter Selasky };
17997549c34SHans Petter Selasky
1808cc48704SHans Petter Selasky enum {
1818cc48704SHans Petter Selasky MLX4_IB_QP_CREATE_ROCE_V2_GSI = IB_QP_CREATE_RESERVED_START
1828cc48704SHans Petter Selasky };
1838cc48704SHans Petter Selasky
18497549c34SHans Petter Selasky enum mlx4_ib_qp_flags {
18597549c34SHans Petter Selasky MLX4_IB_QP_LSO = IB_QP_CREATE_IPOIB_UD_LSO,
18697549c34SHans Petter Selasky MLX4_IB_QP_BLOCK_MULTICAST_LOOPBACK = IB_QP_CREATE_BLOCK_MULTICAST_LOOPBACK,
18797549c34SHans Petter Selasky MLX4_IB_QP_NETIF = IB_QP_CREATE_NETIF_QP,
1888cc48704SHans Petter Selasky MLX4_IB_QP_CREATE_USE_GFP_NOIO = IB_QP_CREATE_USE_GFP_NOIO,
1898cc48704SHans Petter Selasky
1908cc48704SHans Petter Selasky /* Mellanox specific flags start from IB_QP_CREATE_RESERVED_START */
1918cc48704SHans Petter Selasky MLX4_IB_ROCE_V2_GSI_QP = MLX4_IB_QP_CREATE_ROCE_V2_GSI,
19297549c34SHans Petter Selasky MLX4_IB_SRIOV_TUNNEL_QP = 1 << 30,
19302ca39cfSEitan Adler MLX4_IB_SRIOV_SQP = 1U << 31,
19497549c34SHans Petter Selasky };
19597549c34SHans Petter Selasky
19697549c34SHans Petter Selasky struct mlx4_ib_gid_entry {
19797549c34SHans Petter Selasky struct list_head list;
19897549c34SHans Petter Selasky union ib_gid gid;
19997549c34SHans Petter Selasky int added;
20097549c34SHans Petter Selasky u8 port;
20197549c34SHans Petter Selasky };
20297549c34SHans Petter Selasky
20397549c34SHans Petter Selasky enum mlx4_ib_qp_type {
20497549c34SHans Petter Selasky /*
20597549c34SHans Petter Selasky * IB_QPT_SMI and IB_QPT_GSI have to be the first two entries
20697549c34SHans Petter Selasky * here (and in that order) since the MAD layer uses them as
20797549c34SHans Petter Selasky * indices into a 2-entry table.
20897549c34SHans Petter Selasky */
20997549c34SHans Petter Selasky MLX4_IB_QPT_SMI = IB_QPT_SMI,
21097549c34SHans Petter Selasky MLX4_IB_QPT_GSI = IB_QPT_GSI,
21197549c34SHans Petter Selasky
21297549c34SHans Petter Selasky MLX4_IB_QPT_RC = IB_QPT_RC,
21397549c34SHans Petter Selasky MLX4_IB_QPT_UC = IB_QPT_UC,
21497549c34SHans Petter Selasky MLX4_IB_QPT_UD = IB_QPT_UD,
21597549c34SHans Petter Selasky MLX4_IB_QPT_RAW_IPV6 = IB_QPT_RAW_IPV6,
21697549c34SHans Petter Selasky MLX4_IB_QPT_RAW_ETHERTYPE = IB_QPT_RAW_ETHERTYPE,
21797549c34SHans Petter Selasky MLX4_IB_QPT_RAW_PACKET = IB_QPT_RAW_PACKET,
21897549c34SHans Petter Selasky MLX4_IB_QPT_XRC_INI = IB_QPT_XRC_INI,
21997549c34SHans Petter Selasky MLX4_IB_QPT_XRC_TGT = IB_QPT_XRC_TGT,
22097549c34SHans Petter Selasky
22197549c34SHans Petter Selasky MLX4_IB_QPT_PROXY_SMI_OWNER = 1 << 16,
22297549c34SHans Petter Selasky MLX4_IB_QPT_PROXY_SMI = 1 << 17,
22397549c34SHans Petter Selasky MLX4_IB_QPT_PROXY_GSI = 1 << 18,
22497549c34SHans Petter Selasky MLX4_IB_QPT_TUN_SMI_OWNER = 1 << 19,
22597549c34SHans Petter Selasky MLX4_IB_QPT_TUN_SMI = 1 << 20,
22697549c34SHans Petter Selasky MLX4_IB_QPT_TUN_GSI = 1 << 21,
22797549c34SHans Petter Selasky };
22897549c34SHans Petter Selasky
22997549c34SHans Petter Selasky #define MLX4_IB_QPT_ANY_SRIOV (MLX4_IB_QPT_PROXY_SMI_OWNER | \
23097549c34SHans Petter Selasky MLX4_IB_QPT_PROXY_SMI | MLX4_IB_QPT_PROXY_GSI | MLX4_IB_QPT_TUN_SMI_OWNER | \
23197549c34SHans Petter Selasky MLX4_IB_QPT_TUN_SMI | MLX4_IB_QPT_TUN_GSI)
23297549c34SHans Petter Selasky
23397549c34SHans Petter Selasky enum mlx4_ib_mad_ifc_flags {
23497549c34SHans Petter Selasky MLX4_MAD_IFC_IGNORE_MKEY = 1,
23597549c34SHans Petter Selasky MLX4_MAD_IFC_IGNORE_BKEY = 2,
23697549c34SHans Petter Selasky MLX4_MAD_IFC_IGNORE_KEYS = (MLX4_MAD_IFC_IGNORE_MKEY |
23797549c34SHans Petter Selasky MLX4_MAD_IFC_IGNORE_BKEY),
23897549c34SHans Petter Selasky MLX4_MAD_IFC_NET_VIEW = 4,
23997549c34SHans Petter Selasky };
24097549c34SHans Petter Selasky
24197549c34SHans Petter Selasky enum {
24297549c34SHans Petter Selasky MLX4_NUM_TUNNEL_BUFS = 256,
24397549c34SHans Petter Selasky };
24497549c34SHans Petter Selasky
24597549c34SHans Petter Selasky struct mlx4_ib_tunnel_header {
24697549c34SHans Petter Selasky struct mlx4_av av;
24797549c34SHans Petter Selasky __be32 remote_qpn;
24897549c34SHans Petter Selasky __be32 qkey;
24997549c34SHans Petter Selasky __be16 vlan;
25097549c34SHans Petter Selasky u8 mac[6];
25197549c34SHans Petter Selasky __be16 pkey_index;
25297549c34SHans Petter Selasky u8 reserved[6];
25397549c34SHans Petter Selasky };
25497549c34SHans Petter Selasky
25597549c34SHans Petter Selasky struct mlx4_ib_buf {
25697549c34SHans Petter Selasky void *addr;
25797549c34SHans Petter Selasky dma_addr_t map;
25897549c34SHans Petter Selasky };
25997549c34SHans Petter Selasky
26097549c34SHans Petter Selasky struct mlx4_rcv_tunnel_hdr {
26197549c34SHans Petter Selasky __be32 flags_src_qp; /* flags[6:5] is defined for VLANs:
26297549c34SHans Petter Selasky * 0x0 - no vlan was in the packet
26397549c34SHans Petter Selasky * 0x01 - C-VLAN was in the packet */
26497549c34SHans Petter Selasky u8 g_ml_path; /* gid bit stands for ipv6/4 header in RoCE */
26597549c34SHans Petter Selasky u8 reserved;
26697549c34SHans Petter Selasky __be16 pkey_index;
26797549c34SHans Petter Selasky __be16 sl_vid;
26897549c34SHans Petter Selasky __be16 slid_mac_47_32;
26997549c34SHans Petter Selasky __be32 mac_31_0;
27097549c34SHans Petter Selasky };
27197549c34SHans Petter Selasky
27297549c34SHans Petter Selasky struct mlx4_ib_proxy_sqp_hdr {
27397549c34SHans Petter Selasky struct ib_grh grh;
27497549c34SHans Petter Selasky struct mlx4_rcv_tunnel_hdr tun;
27597549c34SHans Petter Selasky } __packed;
27697549c34SHans Petter Selasky
27797549c34SHans Petter Selasky struct mlx4_roce_smac_vlan_info {
27897549c34SHans Petter Selasky u64 smac;
27997549c34SHans Petter Selasky int smac_index;
28097549c34SHans Petter Selasky int smac_port;
28197549c34SHans Petter Selasky u64 candidate_smac;
28297549c34SHans Petter Selasky int candidate_smac_index;
28397549c34SHans Petter Selasky int candidate_smac_port;
28497549c34SHans Petter Selasky u16 vid;
28597549c34SHans Petter Selasky int vlan_index;
28697549c34SHans Petter Selasky int vlan_port;
28797549c34SHans Petter Selasky u16 candidate_vid;
28897549c34SHans Petter Selasky int candidate_vlan_index;
28997549c34SHans Petter Selasky int candidate_vlan_port;
29097549c34SHans Petter Selasky int update_vid;
29197549c34SHans Petter Selasky };
29297549c34SHans Petter Selasky
29397549c34SHans Petter Selasky struct mlx4_ib_qp {
29497549c34SHans Petter Selasky struct ib_qp ibqp;
29597549c34SHans Petter Selasky struct mlx4_qp mqp;
29697549c34SHans Petter Selasky struct mlx4_buf buf;
29797549c34SHans Petter Selasky
29897549c34SHans Petter Selasky struct mlx4_db db;
29997549c34SHans Petter Selasky struct mlx4_ib_wq rq;
30097549c34SHans Petter Selasky
30197549c34SHans Petter Selasky u32 doorbell_qpn;
30297549c34SHans Petter Selasky __be32 sq_signal_bits;
30397549c34SHans Petter Selasky unsigned sq_next_wqe;
30497549c34SHans Petter Selasky int sq_max_wqes_per_wr;
30597549c34SHans Petter Selasky int sq_spare_wqes;
30697549c34SHans Petter Selasky struct mlx4_ib_wq sq;
30797549c34SHans Petter Selasky
30897549c34SHans Petter Selasky enum mlx4_ib_qp_type mlx4_ib_qp_type;
30997549c34SHans Petter Selasky struct ib_umem *umem;
31097549c34SHans Petter Selasky struct mlx4_mtt mtt;
31197549c34SHans Petter Selasky int buf_size;
31297549c34SHans Petter Selasky struct mutex mutex;
31397549c34SHans Petter Selasky u16 xrcdn;
31497549c34SHans Petter Selasky u32 flags;
31597549c34SHans Petter Selasky u8 port;
31697549c34SHans Petter Selasky u8 alt_port;
31797549c34SHans Petter Selasky u8 atomic_rd_en;
31897549c34SHans Petter Selasky u8 resp_depth;
31997549c34SHans Petter Selasky u8 sq_no_prefetch;
32097549c34SHans Petter Selasky u8 state;
32197549c34SHans Petter Selasky int mlx_type;
32297549c34SHans Petter Selasky struct list_head gid_list;
32397549c34SHans Petter Selasky struct list_head steering_rules;
32497549c34SHans Petter Selasky struct mlx4_ib_buf *sqp_proxy_rcv;
32597549c34SHans Petter Selasky struct mlx4_roce_smac_vlan_info pri;
32697549c34SHans Petter Selasky struct mlx4_roce_smac_vlan_info alt;
32797549c34SHans Petter Selasky u64 reg_id;
3288cc48704SHans Petter Selasky struct list_head qps_list;
3298cc48704SHans Petter Selasky struct list_head cq_recv_list;
3308cc48704SHans Petter Selasky struct list_head cq_send_list;
3318cc48704SHans Petter Selasky struct counter_index *counter_index;
33297549c34SHans Petter Selasky };
33397549c34SHans Petter Selasky
33497549c34SHans Petter Selasky struct mlx4_ib_srq {
33597549c34SHans Petter Selasky struct ib_srq ibsrq;
33697549c34SHans Petter Selasky struct mlx4_srq msrq;
33797549c34SHans Petter Selasky struct mlx4_buf buf;
33897549c34SHans Petter Selasky struct mlx4_db db;
33997549c34SHans Petter Selasky u64 *wrid;
34097549c34SHans Petter Selasky spinlock_t lock;
34197549c34SHans Petter Selasky int head;
34297549c34SHans Petter Selasky int tail;
34397549c34SHans Petter Selasky u16 wqe_ctr;
34497549c34SHans Petter Selasky struct ib_umem *umem;
34597549c34SHans Petter Selasky struct mlx4_mtt mtt;
34697549c34SHans Petter Selasky struct mutex mutex;
34797549c34SHans Petter Selasky };
34897549c34SHans Petter Selasky
34997549c34SHans Petter Selasky struct mlx4_ib_ah {
35097549c34SHans Petter Selasky struct ib_ah ibah;
35197549c34SHans Petter Selasky union mlx4_ext_av av;
35297549c34SHans Petter Selasky };
35397549c34SHans Petter Selasky
35497549c34SHans Petter Selasky /****************************************/
35597549c34SHans Petter Selasky /* alias guid support */
35697549c34SHans Petter Selasky /****************************************/
35797549c34SHans Petter Selasky #define NUM_PORT_ALIAS_GUID 2
35897549c34SHans Petter Selasky #define NUM_ALIAS_GUID_IN_REC 8
35997549c34SHans Petter Selasky #define NUM_ALIAS_GUID_REC_IN_PORT 16
36097549c34SHans Petter Selasky #define GUID_REC_SIZE 8
36197549c34SHans Petter Selasky #define NUM_ALIAS_GUID_PER_PORT 128
36297549c34SHans Petter Selasky #define MLX4_NOT_SET_GUID (0x00LL)
36397549c34SHans Petter Selasky #define MLX4_GUID_FOR_DELETE_VAL (~(0x00LL))
36497549c34SHans Petter Selasky
36597549c34SHans Petter Selasky enum mlx4_guid_alias_rec_status {
36697549c34SHans Petter Selasky MLX4_GUID_INFO_STATUS_IDLE,
36797549c34SHans Petter Selasky MLX4_GUID_INFO_STATUS_SET,
36897549c34SHans Petter Selasky };
36997549c34SHans Petter Selasky
3708cc48704SHans Petter Selasky #define GUID_STATE_NEED_PORT_INIT 0x01
37197549c34SHans Petter Selasky
37297549c34SHans Petter Selasky enum mlx4_guid_alias_rec_method {
37397549c34SHans Petter Selasky MLX4_GUID_INFO_RECORD_SET = IB_MGMT_METHOD_SET,
37497549c34SHans Petter Selasky MLX4_GUID_INFO_RECORD_DELETE = IB_SA_METHOD_DELETE,
37597549c34SHans Petter Selasky };
37697549c34SHans Petter Selasky
37797549c34SHans Petter Selasky struct mlx4_sriov_alias_guid_info_rec_det {
37897549c34SHans Petter Selasky u8 all_recs[GUID_REC_SIZE * NUM_ALIAS_GUID_IN_REC];
37997549c34SHans Petter Selasky ib_sa_comp_mask guid_indexes; /*indicates what from the 8 records are valid*/
38097549c34SHans Petter Selasky enum mlx4_guid_alias_rec_status status; /*indicates the administraively status of the record.*/
3818cc48704SHans Petter Selasky unsigned int guids_retry_schedule[NUM_ALIAS_GUID_IN_REC];
3828cc48704SHans Petter Selasky u64 time_to_run;
38397549c34SHans Petter Selasky };
38497549c34SHans Petter Selasky
38597549c34SHans Petter Selasky struct mlx4_sriov_alias_guid_port_rec_det {
38697549c34SHans Petter Selasky struct mlx4_sriov_alias_guid_info_rec_det all_rec_per_port[NUM_ALIAS_GUID_REC_IN_PORT];
38797549c34SHans Petter Selasky struct workqueue_struct *wq;
38897549c34SHans Petter Selasky struct delayed_work alias_guid_work;
38997549c34SHans Petter Selasky u8 port;
3908cc48704SHans Petter Selasky u32 state_flags;
39197549c34SHans Petter Selasky struct mlx4_sriov_alias_guid *parent;
39297549c34SHans Petter Selasky struct list_head cb_list;
39397549c34SHans Petter Selasky };
39497549c34SHans Petter Selasky
39597549c34SHans Petter Selasky struct mlx4_sriov_alias_guid {
39697549c34SHans Petter Selasky struct mlx4_sriov_alias_guid_port_rec_det ports_guid[MLX4_MAX_PORTS];
39797549c34SHans Petter Selasky spinlock_t ag_work_lock;
39897549c34SHans Petter Selasky struct ib_sa_client *sa_client;
39997549c34SHans Petter Selasky };
40097549c34SHans Petter Selasky
40197549c34SHans Petter Selasky struct mlx4_ib_demux_work {
40297549c34SHans Petter Selasky struct work_struct work;
40397549c34SHans Petter Selasky struct mlx4_ib_dev *dev;
40497549c34SHans Petter Selasky int slave;
40597549c34SHans Petter Selasky int do_init;
40697549c34SHans Petter Selasky u8 port;
40797549c34SHans Petter Selasky
40897549c34SHans Petter Selasky };
40997549c34SHans Petter Selasky
41097549c34SHans Petter Selasky struct mlx4_ib_tun_tx_buf {
41197549c34SHans Petter Selasky struct mlx4_ib_buf buf;
41297549c34SHans Petter Selasky struct ib_ah *ah;
41397549c34SHans Petter Selasky };
41497549c34SHans Petter Selasky
41597549c34SHans Petter Selasky struct mlx4_ib_demux_pv_qp {
41697549c34SHans Petter Selasky struct ib_qp *qp;
41797549c34SHans Petter Selasky enum ib_qp_type proxy_qpt;
41897549c34SHans Petter Selasky struct mlx4_ib_buf *ring;
41997549c34SHans Petter Selasky struct mlx4_ib_tun_tx_buf *tx_ring;
42097549c34SHans Petter Selasky spinlock_t tx_lock;
42197549c34SHans Petter Selasky unsigned tx_ix_head;
42297549c34SHans Petter Selasky unsigned tx_ix_tail;
42397549c34SHans Petter Selasky };
42497549c34SHans Petter Selasky
42597549c34SHans Petter Selasky enum mlx4_ib_demux_pv_state {
42697549c34SHans Petter Selasky DEMUX_PV_STATE_DOWN,
42797549c34SHans Petter Selasky DEMUX_PV_STATE_STARTING,
42897549c34SHans Petter Selasky DEMUX_PV_STATE_ACTIVE,
42997549c34SHans Petter Selasky DEMUX_PV_STATE_DOWNING,
43097549c34SHans Petter Selasky };
43197549c34SHans Petter Selasky
43297549c34SHans Petter Selasky struct mlx4_ib_demux_pv_ctx {
43397549c34SHans Petter Selasky int port;
43497549c34SHans Petter Selasky int slave;
43597549c34SHans Petter Selasky enum mlx4_ib_demux_pv_state state;
43697549c34SHans Petter Selasky int has_smi;
43797549c34SHans Petter Selasky struct ib_device *ib_dev;
43897549c34SHans Petter Selasky struct ib_cq *cq;
43997549c34SHans Petter Selasky struct ib_pd *pd;
44097549c34SHans Petter Selasky struct work_struct work;
44197549c34SHans Petter Selasky struct workqueue_struct *wq;
44297549c34SHans Petter Selasky struct mlx4_ib_demux_pv_qp qp[2];
44397549c34SHans Petter Selasky };
44497549c34SHans Petter Selasky
44597549c34SHans Petter Selasky struct mlx4_ib_demux_ctx {
44697549c34SHans Petter Selasky struct ib_device *ib_dev;
44797549c34SHans Petter Selasky int port;
44897549c34SHans Petter Selasky struct workqueue_struct *wq;
44997549c34SHans Petter Selasky struct workqueue_struct *ud_wq;
45097549c34SHans Petter Selasky spinlock_t ud_lock;
4518cc48704SHans Petter Selasky atomic64_t subnet_prefix;
45297549c34SHans Petter Selasky __be64 guid_cache[128];
45397549c34SHans Petter Selasky struct mlx4_ib_dev *dev;
45497549c34SHans Petter Selasky /* the following lock protects both mcg_table and mcg_mgid0_list */
45597549c34SHans Petter Selasky struct mutex mcg_table_lock;
45697549c34SHans Petter Selasky struct rb_root mcg_table;
45797549c34SHans Petter Selasky struct list_head mcg_mgid0_list;
45897549c34SHans Petter Selasky struct workqueue_struct *mcg_wq;
45997549c34SHans Petter Selasky struct mlx4_ib_demux_pv_ctx **tun;
46097549c34SHans Petter Selasky atomic_t tid;
46197549c34SHans Petter Selasky int flushing; /* flushing the work queue */
46297549c34SHans Petter Selasky };
46397549c34SHans Petter Selasky
46497549c34SHans Petter Selasky struct mlx4_ib_sriov {
46597549c34SHans Petter Selasky struct mlx4_ib_demux_ctx demux[MLX4_MAX_PORTS];
46697549c34SHans Petter Selasky struct mlx4_ib_demux_pv_ctx *sqps[MLX4_MAX_PORTS];
46797549c34SHans Petter Selasky /* when using this spinlock you should use "irq" because
46897549c34SHans Petter Selasky * it may be called from interrupt context.*/
46997549c34SHans Petter Selasky spinlock_t going_down_lock;
47097549c34SHans Petter Selasky int is_going_down;
47197549c34SHans Petter Selasky
47297549c34SHans Petter Selasky struct mlx4_sriov_alias_guid alias_guid;
47397549c34SHans Petter Selasky
47497549c34SHans Petter Selasky /* CM paravirtualization fields */
47597549c34SHans Petter Selasky struct list_head cm_list;
47697549c34SHans Petter Selasky spinlock_t id_map_lock;
47797549c34SHans Petter Selasky struct rb_root sl_id_map;
47897549c34SHans Petter Selasky struct idr pv_id_table;
47997549c34SHans Petter Selasky };
48097549c34SHans Petter Selasky
4818cc48704SHans Petter Selasky struct gid_cache_context {
4828cc48704SHans Petter Selasky int real_index;
4838cc48704SHans Petter Selasky int refcount;
4848cc48704SHans Petter Selasky };
4858cc48704SHans Petter Selasky
4868cc48704SHans Petter Selasky struct gid_entry {
4878cc48704SHans Petter Selasky union ib_gid gid;
4888cc48704SHans Petter Selasky enum ib_gid_type gid_type;
4898cc48704SHans Petter Selasky struct gid_cache_context *ctx;
4908cc48704SHans Petter Selasky };
4918cc48704SHans Petter Selasky
4928cc48704SHans Petter Selasky struct mlx4_port_gid_table {
4938cc48704SHans Petter Selasky struct gid_entry gids[MLX4_MAX_PORT_GIDS];
4948cc48704SHans Petter Selasky };
4958cc48704SHans Petter Selasky
49697549c34SHans Petter Selasky struct mlx4_ib_iboe {
49797549c34SHans Petter Selasky spinlock_t lock;
498*0b281376SJustin Hibbits if_t netdevs[MLX4_MAX_PORTS];
4998cc48704SHans Petter Selasky atomic64_t mac[MLX4_MAX_PORTS];
50097549c34SHans Petter Selasky struct notifier_block nb;
5018cc48704SHans Petter Selasky struct mlx4_port_gid_table gids[MLX4_MAX_PORTS];
50297549c34SHans Petter Selasky };
50397549c34SHans Petter Selasky
50497549c34SHans Petter Selasky struct pkey_mgt {
50597549c34SHans Petter Selasky u8 virt2phys_pkey[MLX4_MFUNC_MAX][MLX4_MAX_PORTS][MLX4_MAX_PORT_PKEYS];
50697549c34SHans Petter Selasky u16 phys_pkey_cache[MLX4_MAX_PORTS][MLX4_MAX_PORT_PKEYS];
50797549c34SHans Petter Selasky struct list_head pkey_port_list[MLX4_MFUNC_MAX];
50897549c34SHans Petter Selasky struct kobject *device_parent[MLX4_MFUNC_MAX];
50997549c34SHans Petter Selasky };
51097549c34SHans Petter Selasky
51197549c34SHans Petter Selasky struct mlx4_ib_iov_sysfs_attr {
51297549c34SHans Petter Selasky void *ctx;
51397549c34SHans Petter Selasky struct kobject *kobj;
51497549c34SHans Petter Selasky unsigned long data;
51597549c34SHans Petter Selasky u32 entry_num;
51697549c34SHans Petter Selasky char name[15];
51797549c34SHans Petter Selasky struct device_attribute dentry;
51897549c34SHans Petter Selasky struct device *dev;
51997549c34SHans Petter Selasky };
52097549c34SHans Petter Selasky
52197549c34SHans Petter Selasky struct mlx4_ib_iov_sysfs_attr_ar {
52297549c34SHans Petter Selasky struct mlx4_ib_iov_sysfs_attr dentries[3 * NUM_ALIAS_GUID_PER_PORT + 1];
52397549c34SHans Petter Selasky };
52497549c34SHans Petter Selasky
52597549c34SHans Petter Selasky struct mlx4_ib_iov_port {
52697549c34SHans Petter Selasky char name[100];
52797549c34SHans Petter Selasky u8 num;
52897549c34SHans Petter Selasky struct mlx4_ib_dev *dev;
52997549c34SHans Petter Selasky struct list_head list;
53097549c34SHans Petter Selasky struct mlx4_ib_iov_sysfs_attr_ar *dentr_ar;
53197549c34SHans Petter Selasky struct ib_port_attr attr;
53297549c34SHans Petter Selasky struct kobject *cur_port;
53397549c34SHans Petter Selasky struct kobject *admin_alias_parent;
53497549c34SHans Petter Selasky struct kobject *gids_parent;
53597549c34SHans Petter Selasky struct kobject *pkeys_parent;
53697549c34SHans Petter Selasky struct kobject *mcgs_parent;
53797549c34SHans Petter Selasky struct mlx4_ib_iov_sysfs_attr mcg_dentry;
53897549c34SHans Petter Selasky };
53997549c34SHans Petter Selasky
5408cc48704SHans Petter Selasky struct counter_index {
5418cc48704SHans Petter Selasky struct list_head list;
5428cc48704SHans Petter Selasky u32 index;
5438cc48704SHans Petter Selasky u8 allocated;
5448cc48704SHans Petter Selasky };
5458cc48704SHans Petter Selasky
5468cc48704SHans Petter Selasky struct mlx4_ib_counters {
5478cc48704SHans Petter Selasky struct list_head counters_list;
5488cc48704SHans Petter Selasky struct mutex mutex; /* mutex for accessing counters list */
5498cc48704SHans Petter Selasky u32 default_counter;
5508cc48704SHans Petter Selasky };
5518cc48704SHans Petter Selasky
5528cc48704SHans Petter Selasky #define MLX4_DIAG_COUNTERS_TYPES 2
5538cc48704SHans Petter Selasky
5548cc48704SHans Petter Selasky struct mlx4_ib_diag_counters {
5558cc48704SHans Petter Selasky const char **name;
5568cc48704SHans Petter Selasky u32 *offset;
5578cc48704SHans Petter Selasky u32 num_counters;
55897549c34SHans Petter Selasky };
55997549c34SHans Petter Selasky
56097549c34SHans Petter Selasky struct mlx4_ib_dev {
56197549c34SHans Petter Selasky struct ib_device ib_dev;
56297549c34SHans Petter Selasky struct mlx4_dev *dev;
56397549c34SHans Petter Selasky int num_ports;
5648cc48704SHans Petter Selasky void __iomem *uar_map;
5658cc48704SHans Petter Selasky
56697549c34SHans Petter Selasky struct mlx4_uar priv_uar;
56797549c34SHans Petter Selasky u32 priv_pdn;
56897549c34SHans Petter Selasky MLX4_DECLARE_DOORBELL_LOCK(uar_lock);
56997549c34SHans Petter Selasky
57097549c34SHans Petter Selasky struct ib_mad_agent *send_agent[MLX4_MAX_PORTS][2];
57197549c34SHans Petter Selasky struct ib_ah *sm_ah[MLX4_MAX_PORTS];
57297549c34SHans Petter Selasky spinlock_t sm_lock;
5738cc48704SHans Petter Selasky atomic64_t sl2vl[MLX4_MAX_PORTS];
57497549c34SHans Petter Selasky struct mlx4_ib_sriov sriov;
57597549c34SHans Petter Selasky
57697549c34SHans Petter Selasky struct mutex cap_mask_mutex;
57797549c34SHans Petter Selasky bool ib_active;
57897549c34SHans Petter Selasky struct mlx4_ib_iboe iboe;
5798cc48704SHans Petter Selasky struct mlx4_ib_counters counters_table[MLX4_MAX_PORTS];
58097549c34SHans Petter Selasky int *eq_table;
58197549c34SHans Petter Selasky struct kobject *iov_parent;
58297549c34SHans Petter Selasky struct kobject *ports_parent;
58397549c34SHans Petter Selasky struct kobject *dev_ports_parent[MLX4_MFUNC_MAX];
58497549c34SHans Petter Selasky struct mlx4_ib_iov_port iov_ports[MLX4_MAX_PORTS];
58597549c34SHans Petter Selasky struct pkey_mgt pkeys;
58697549c34SHans Petter Selasky unsigned long *ib_uc_qpns_bitmap;
58797549c34SHans Petter Selasky int steer_qpn_count;
58897549c34SHans Petter Selasky int steer_qpn_base;
5898cc48704SHans Petter Selasky int steering_support;
5908cc48704SHans Petter Selasky struct mlx4_ib_qp *qp1_proxy[MLX4_MAX_PORTS];
5918cc48704SHans Petter Selasky /* lock when destroying qp1_proxy and getting netdev events */
5928cc48704SHans Petter Selasky struct mutex qp1_proxy_lock[MLX4_MAX_PORTS];
5938cc48704SHans Petter Selasky u8 bond_next_port;
5948cc48704SHans Petter Selasky /* protect resources needed as part of reset flow */
5958cc48704SHans Petter Selasky spinlock_t reset_flow_resource_lock;
5968cc48704SHans Petter Selasky struct list_head qp_list;
5978cc48704SHans Petter Selasky struct mlx4_ib_diag_counters diag_counters[MLX4_DIAG_COUNTERS_TYPES];
59897549c34SHans Petter Selasky };
59997549c34SHans Petter Selasky
60097549c34SHans Petter Selasky struct ib_event_work {
60197549c34SHans Petter Selasky struct work_struct work;
60297549c34SHans Petter Selasky struct mlx4_ib_dev *ib_dev;
60397549c34SHans Petter Selasky struct mlx4_eqe ib_eqe;
6048cc48704SHans Petter Selasky int port;
60597549c34SHans Petter Selasky };
60697549c34SHans Petter Selasky
60797549c34SHans Petter Selasky struct mlx4_ib_qp_tunnel_init_attr {
60897549c34SHans Petter Selasky struct ib_qp_init_attr init_attr;
60997549c34SHans Petter Selasky int slave;
61097549c34SHans Petter Selasky enum ib_qp_type proxy_qp_type;
61197549c34SHans Petter Selasky u8 port;
61297549c34SHans Petter Selasky };
61397549c34SHans Petter Selasky
6148cc48704SHans Petter Selasky struct mlx4_uverbs_ex_query_device {
6158cc48704SHans Petter Selasky __u32 comp_mask;
6168cc48704SHans Petter Selasky __u32 reserved;
6178cc48704SHans Petter Selasky };
6188cc48704SHans Petter Selasky
6198cc48704SHans Petter Selasky enum query_device_resp_mask {
6208cc48704SHans Petter Selasky QUERY_DEVICE_RESP_MASK_TIMESTAMP = 1UL << 0,
6218cc48704SHans Petter Selasky };
6228cc48704SHans Petter Selasky
6238cc48704SHans Petter Selasky struct mlx4_uverbs_ex_query_device_resp {
6248cc48704SHans Petter Selasky __u32 comp_mask;
6258cc48704SHans Petter Selasky __u32 response_length;
6268cc48704SHans Petter Selasky __u64 hca_core_clock_offset;
6278cc48704SHans Petter Selasky };
6288cc48704SHans Petter Selasky
to_mdev(struct ib_device * ibdev)62997549c34SHans Petter Selasky static inline struct mlx4_ib_dev *to_mdev(struct ib_device *ibdev)
63097549c34SHans Petter Selasky {
63197549c34SHans Petter Selasky return container_of(ibdev, struct mlx4_ib_dev, ib_dev);
63297549c34SHans Petter Selasky }
63397549c34SHans Petter Selasky
to_mucontext(struct ib_ucontext * ibucontext)63497549c34SHans Petter Selasky static inline struct mlx4_ib_ucontext *to_mucontext(struct ib_ucontext *ibucontext)
63597549c34SHans Petter Selasky {
63697549c34SHans Petter Selasky return container_of(ibucontext, struct mlx4_ib_ucontext, ibucontext);
63797549c34SHans Petter Selasky }
63897549c34SHans Petter Selasky
to_mpd(struct ib_pd * ibpd)63997549c34SHans Petter Selasky static inline struct mlx4_ib_pd *to_mpd(struct ib_pd *ibpd)
64097549c34SHans Petter Selasky {
64197549c34SHans Petter Selasky return container_of(ibpd, struct mlx4_ib_pd, ibpd);
64297549c34SHans Petter Selasky }
64397549c34SHans Petter Selasky
to_mxrcd(struct ib_xrcd * ibxrcd)64497549c34SHans Petter Selasky static inline struct mlx4_ib_xrcd *to_mxrcd(struct ib_xrcd *ibxrcd)
64597549c34SHans Petter Selasky {
64697549c34SHans Petter Selasky return container_of(ibxrcd, struct mlx4_ib_xrcd, ibxrcd);
64797549c34SHans Petter Selasky }
64897549c34SHans Petter Selasky
to_mcq(struct ib_cq * ibcq)64997549c34SHans Petter Selasky static inline struct mlx4_ib_cq *to_mcq(struct ib_cq *ibcq)
65097549c34SHans Petter Selasky {
65197549c34SHans Petter Selasky return container_of(ibcq, struct mlx4_ib_cq, ibcq);
65297549c34SHans Petter Selasky }
65397549c34SHans Petter Selasky
to_mibcq(struct mlx4_cq * mcq)65497549c34SHans Petter Selasky static inline struct mlx4_ib_cq *to_mibcq(struct mlx4_cq *mcq)
65597549c34SHans Petter Selasky {
65697549c34SHans Petter Selasky return container_of(mcq, struct mlx4_ib_cq, mcq);
65797549c34SHans Petter Selasky }
65897549c34SHans Petter Selasky
to_mmr(struct ib_mr * ibmr)65997549c34SHans Petter Selasky static inline struct mlx4_ib_mr *to_mmr(struct ib_mr *ibmr)
66097549c34SHans Petter Selasky {
66197549c34SHans Petter Selasky return container_of(ibmr, struct mlx4_ib_mr, ibmr);
66297549c34SHans Petter Selasky }
66397549c34SHans Petter Selasky
to_mmw(struct ib_mw * ibmw)66497549c34SHans Petter Selasky static inline struct mlx4_ib_mw *to_mmw(struct ib_mw *ibmw)
66597549c34SHans Petter Selasky {
66697549c34SHans Petter Selasky return container_of(ibmw, struct mlx4_ib_mw, ibmw);
66797549c34SHans Petter Selasky }
66897549c34SHans Petter Selasky
to_mfmr(struct ib_fmr * ibfmr)66997549c34SHans Petter Selasky static inline struct mlx4_ib_fmr *to_mfmr(struct ib_fmr *ibfmr)
67097549c34SHans Petter Selasky {
67197549c34SHans Petter Selasky return container_of(ibfmr, struct mlx4_ib_fmr, ibfmr);
67297549c34SHans Petter Selasky }
67397549c34SHans Petter Selasky
to_mflow(struct ib_flow * ibflow)67497549c34SHans Petter Selasky static inline struct mlx4_ib_flow *to_mflow(struct ib_flow *ibflow)
67597549c34SHans Petter Selasky {
67697549c34SHans Petter Selasky return container_of(ibflow, struct mlx4_ib_flow, ibflow);
67797549c34SHans Petter Selasky }
67897549c34SHans Petter Selasky
to_mqp(struct ib_qp * ibqp)67997549c34SHans Petter Selasky static inline struct mlx4_ib_qp *to_mqp(struct ib_qp *ibqp)
68097549c34SHans Petter Selasky {
68197549c34SHans Petter Selasky return container_of(ibqp, struct mlx4_ib_qp, ibqp);
68297549c34SHans Petter Selasky }
68397549c34SHans Petter Selasky
to_mibqp(struct mlx4_qp * mqp)68497549c34SHans Petter Selasky static inline struct mlx4_ib_qp *to_mibqp(struct mlx4_qp *mqp)
68597549c34SHans Petter Selasky {
68697549c34SHans Petter Selasky return container_of(mqp, struct mlx4_ib_qp, mqp);
68797549c34SHans Petter Selasky }
68897549c34SHans Petter Selasky
to_msrq(struct ib_srq * ibsrq)68997549c34SHans Petter Selasky static inline struct mlx4_ib_srq *to_msrq(struct ib_srq *ibsrq)
69097549c34SHans Petter Selasky {
69197549c34SHans Petter Selasky return container_of(ibsrq, struct mlx4_ib_srq, ibsrq);
69297549c34SHans Petter Selasky }
69397549c34SHans Petter Selasky
to_mibsrq(struct mlx4_srq * msrq)69497549c34SHans Petter Selasky static inline struct mlx4_ib_srq *to_mibsrq(struct mlx4_srq *msrq)
69597549c34SHans Petter Selasky {
69697549c34SHans Petter Selasky return container_of(msrq, struct mlx4_ib_srq, msrq);
69797549c34SHans Petter Selasky }
69897549c34SHans Petter Selasky
to_mah(struct ib_ah * ibah)69997549c34SHans Petter Selasky static inline struct mlx4_ib_ah *to_mah(struct ib_ah *ibah)
70097549c34SHans Petter Selasky {
70197549c34SHans Petter Selasky return container_of(ibah, struct mlx4_ib_ah, ibah);
70297549c34SHans Petter Selasky }
70397549c34SHans Petter Selasky
mlx4_ib_bond_next_port(struct mlx4_ib_dev * dev)7048cc48704SHans Petter Selasky static inline u8 mlx4_ib_bond_next_port(struct mlx4_ib_dev *dev)
7058cc48704SHans Petter Selasky {
7068cc48704SHans Petter Selasky dev->bond_next_port = (dev->bond_next_port + 1) % dev->num_ports;
7078cc48704SHans Petter Selasky
7088cc48704SHans Petter Selasky return dev->bond_next_port + 1;
7098cc48704SHans Petter Selasky }
7108cc48704SHans Petter Selasky
71197549c34SHans Petter Selasky int mlx4_ib_init_sriov(struct mlx4_ib_dev *dev);
71297549c34SHans Petter Selasky void mlx4_ib_close_sriov(struct mlx4_ib_dev *dev);
71397549c34SHans Petter Selasky
71497549c34SHans Petter Selasky int mlx4_ib_db_map_user(struct mlx4_ib_ucontext *context, unsigned long virt,
71597549c34SHans Petter Selasky struct mlx4_db *db);
71697549c34SHans Petter Selasky void mlx4_ib_db_unmap_user(struct mlx4_ib_ucontext *context, struct mlx4_db *db);
71797549c34SHans Petter Selasky
71897549c34SHans Petter Selasky struct ib_mr *mlx4_ib_get_dma_mr(struct ib_pd *pd, int acc);
71997549c34SHans Petter Selasky int mlx4_ib_umem_write_mtt(struct mlx4_ib_dev *dev, struct mlx4_mtt *mtt,
72097549c34SHans Petter Selasky struct ib_umem *umem);
72197549c34SHans Petter Selasky struct ib_mr *mlx4_ib_reg_user_mr(struct ib_pd *pd, u64 start, u64 length,
72297549c34SHans Petter Selasky u64 virt_addr, int access_flags,
7238cc48704SHans Petter Selasky struct ib_udata *udata);
724b633e08cSHans Petter Selasky int mlx4_ib_dereg_mr(struct ib_mr *mr, struct ib_udata *udata);
7258cc48704SHans Petter Selasky struct ib_mw *mlx4_ib_alloc_mw(struct ib_pd *pd, enum ib_mw_type type,
7268cc48704SHans Petter Selasky struct ib_udata *udata);
72797549c34SHans Petter Selasky int mlx4_ib_dealloc_mw(struct ib_mw *mw);
728b633e08cSHans Petter Selasky struct ib_mr *mlx4_ib_alloc_mr(struct ib_pd *pd, enum ib_mr_type mr_type,
729b633e08cSHans Petter Selasky u32 max_num_sg, struct ib_udata *udata);
7308cc48704SHans Petter Selasky int mlx4_ib_map_mr_sg(struct ib_mr *ibmr, struct scatterlist *sg, int sg_nents,
7318cc48704SHans Petter Selasky unsigned int *sg_offset);
7328cc48704SHans Petter Selasky int mlx4_ib_modify_cq(struct ib_cq *cq, u16 cq_count, u16 cq_period);
73397549c34SHans Petter Selasky int mlx4_ib_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata);
734b633e08cSHans Petter Selasky int mlx4_ib_create_cq(struct ib_cq *ibcq, const struct ib_cq_init_attr *attr,
73597549c34SHans Petter Selasky struct ib_udata *udata);
736b633e08cSHans Petter Selasky void mlx4_ib_destroy_cq(struct ib_cq *cq, struct ib_udata *udata);
73797549c34SHans Petter Selasky int mlx4_ib_poll_cq(struct ib_cq *ibcq, int num_entries, struct ib_wc *wc);
73897549c34SHans Petter Selasky int mlx4_ib_arm_cq(struct ib_cq *cq, enum ib_cq_notify_flags flags);
73997549c34SHans Petter Selasky void __mlx4_ib_cq_clean(struct mlx4_ib_cq *cq, u32 qpn, struct mlx4_ib_srq *srq);
74097549c34SHans Petter Selasky void mlx4_ib_cq_clean(struct mlx4_ib_cq *cq, u32 qpn, struct mlx4_ib_srq *srq);
74197549c34SHans Petter Selasky
742b633e08cSHans Petter Selasky int mlx4_ib_create_ah(struct ib_ah *ah, struct ib_ah_attr *ah_attr, u32 flags,
7431456d97cSHans Petter Selasky struct ib_udata *udata);
744b633e08cSHans Petter Selasky int mlx4_ib_create_ah_slave(struct ib_ah *ah, struct ib_ah_attr *ah_attr,
745b633e08cSHans Petter Selasky int slave_sgid_index, u8 *s_mac, u16 vlan_tag);
74697549c34SHans Petter Selasky int mlx4_ib_query_ah(struct ib_ah *ibah, struct ib_ah_attr *ah_attr);
747b633e08cSHans Petter Selasky void mlx4_ib_destroy_ah(struct ib_ah *ah, u32 flags);
74897549c34SHans Petter Selasky
749b633e08cSHans Petter Selasky int mlx4_ib_create_srq(struct ib_srq *srq, struct ib_srq_init_attr *init_attr,
75097549c34SHans Petter Selasky struct ib_udata *udata);
75197549c34SHans Petter Selasky int mlx4_ib_modify_srq(struct ib_srq *ibsrq, struct ib_srq_attr *attr,
75297549c34SHans Petter Selasky enum ib_srq_attr_mask attr_mask, struct ib_udata *udata);
75397549c34SHans Petter Selasky int mlx4_ib_query_srq(struct ib_srq *srq, struct ib_srq_attr *srq_attr);
754b633e08cSHans Petter Selasky void mlx4_ib_destroy_srq(struct ib_srq *srq, struct ib_udata *udata);
75597549c34SHans Petter Selasky void mlx4_ib_free_srq_wqe(struct mlx4_ib_srq *srq, int wqe_index);
756c3987b8eSHans Petter Selasky int mlx4_ib_post_srq_recv(struct ib_srq *ibsrq, const struct ib_recv_wr *wr,
757c3987b8eSHans Petter Selasky const struct ib_recv_wr **bad_wr);
75897549c34SHans Petter Selasky
75997549c34SHans Petter Selasky struct ib_qp *mlx4_ib_create_qp(struct ib_pd *pd,
76097549c34SHans Petter Selasky struct ib_qp_init_attr *init_attr,
76197549c34SHans Petter Selasky struct ib_udata *udata);
762b633e08cSHans Petter Selasky int mlx4_ib_destroy_qp(struct ib_qp *qp, struct ib_udata *udata);
76397549c34SHans Petter Selasky int mlx4_ib_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr,
76497549c34SHans Petter Selasky int attr_mask, struct ib_udata *udata);
76597549c34SHans Petter Selasky int mlx4_ib_query_qp(struct ib_qp *ibqp, struct ib_qp_attr *qp_attr, int qp_attr_mask,
76697549c34SHans Petter Selasky struct ib_qp_init_attr *qp_init_attr);
767c3987b8eSHans Petter Selasky int mlx4_ib_post_send(struct ib_qp *ibqp, const struct ib_send_wr *wr,
768c3987b8eSHans Petter Selasky const struct ib_send_wr **bad_wr);
769c3987b8eSHans Petter Selasky int mlx4_ib_post_recv(struct ib_qp *ibqp, const struct ib_recv_wr *wr,
770c3987b8eSHans Petter Selasky const struct ib_recv_wr **bad_wr);
77197549c34SHans Petter Selasky
77297549c34SHans Petter Selasky int mlx4_MAD_IFC(struct mlx4_ib_dev *dev, int mad_ifc_flags,
7738cc48704SHans Petter Selasky int port, const struct ib_wc *in_wc, const struct ib_grh *in_grh,
7748cc48704SHans Petter Selasky const void *in_mad, void *response_mad);
77597549c34SHans Petter Selasky int mlx4_ib_process_mad(struct ib_device *ibdev, int mad_flags, u8 port_num,
7768cc48704SHans Petter Selasky const struct ib_wc *in_wc, const struct ib_grh *in_grh,
7778cc48704SHans Petter Selasky const struct ib_mad_hdr *in, size_t in_mad_size,
7788cc48704SHans Petter Selasky struct ib_mad_hdr *out, size_t *out_mad_size,
7798cc48704SHans Petter Selasky u16 *out_mad_pkey_index);
78097549c34SHans Petter Selasky int mlx4_ib_mad_init(struct mlx4_ib_dev *dev);
78197549c34SHans Petter Selasky void mlx4_ib_mad_cleanup(struct mlx4_ib_dev *dev);
78297549c34SHans Petter Selasky
78397549c34SHans Petter Selasky struct ib_fmr *mlx4_ib_fmr_alloc(struct ib_pd *pd, int mr_access_flags,
78497549c34SHans Petter Selasky struct ib_fmr_attr *fmr_attr);
78597549c34SHans Petter Selasky int mlx4_ib_map_phys_fmr(struct ib_fmr *ibfmr, u64 *page_list, int npages,
78697549c34SHans Petter Selasky u64 iova);
78797549c34SHans Petter Selasky int mlx4_ib_unmap_fmr(struct list_head *fmr_list);
78897549c34SHans Petter Selasky int mlx4_ib_fmr_dealloc(struct ib_fmr *fmr);
78997549c34SHans Petter Selasky int __mlx4_ib_query_port(struct ib_device *ibdev, u8 port,
79097549c34SHans Petter Selasky struct ib_port_attr *props, int netw_view);
79197549c34SHans Petter Selasky int __mlx4_ib_query_pkey(struct ib_device *ibdev, u8 port, u16 index,
79297549c34SHans Petter Selasky u16 *pkey, int netw_view);
79397549c34SHans Petter Selasky
79497549c34SHans Petter Selasky int __mlx4_ib_query_gid(struct ib_device *ibdev, u8 port, int index,
79597549c34SHans Petter Selasky union ib_gid *gid, int netw_view);
79697549c34SHans Petter Selasky
mlx4_ib_ah_grh_present(struct mlx4_ib_ah * ah)7978cc48704SHans Petter Selasky static inline bool mlx4_ib_ah_grh_present(struct mlx4_ib_ah *ah)
79897549c34SHans Petter Selasky {
79997549c34SHans Petter Selasky u8 port = be32_to_cpu(ah->av.ib.port_pd) >> 24 & 3;
80097549c34SHans Petter Selasky
80197549c34SHans Petter Selasky if (rdma_port_get_link_layer(ah->ibah.device, port) == IB_LINK_LAYER_ETHERNET)
8028cc48704SHans Petter Selasky return true;
80397549c34SHans Petter Selasky
80497549c34SHans Petter Selasky return !!(ah->av.ib.g_slid & 0x80);
80597549c34SHans Petter Selasky }
80697549c34SHans Petter Selasky
80797549c34SHans Petter Selasky int mlx4_ib_mcg_port_init(struct mlx4_ib_demux_ctx *ctx);
80897549c34SHans Petter Selasky void mlx4_ib_mcg_port_cleanup(struct mlx4_ib_demux_ctx *ctx, int destroy_wq);
80997549c34SHans Petter Selasky void clean_vf_mcast(struct mlx4_ib_demux_ctx *ctx, int slave);
81097549c34SHans Petter Selasky int mlx4_ib_mcg_init(void);
81197549c34SHans Petter Selasky void mlx4_ib_mcg_destroy(void);
81297549c34SHans Petter Selasky
81397549c34SHans Petter Selasky int mlx4_ib_find_real_gid(struct ib_device *ibdev, u8 port, __be64 guid);
81497549c34SHans Petter Selasky
81597549c34SHans Petter Selasky int mlx4_ib_mcg_multiplex_handler(struct ib_device *ibdev, int port, int slave,
81697549c34SHans Petter Selasky struct ib_sa_mad *sa_mad);
81797549c34SHans Petter Selasky int mlx4_ib_mcg_demux_handler(struct ib_device *ibdev, int port, int slave,
81897549c34SHans Petter Selasky struct ib_sa_mad *mad);
81997549c34SHans Petter Selasky
82097549c34SHans Petter Selasky int mlx4_ib_add_mc(struct mlx4_ib_dev *mdev, struct mlx4_ib_qp *mqp,
82197549c34SHans Petter Selasky union ib_gid *gid);
82297549c34SHans Petter Selasky
82397549c34SHans Petter Selasky void mlx4_ib_dispatch_event(struct mlx4_ib_dev *dev, u8 port_num,
82497549c34SHans Petter Selasky enum ib_event_type type);
82597549c34SHans Petter Selasky
82697549c34SHans Petter Selasky void mlx4_ib_tunnels_update_work(struct work_struct *work);
82797549c34SHans Petter Selasky
82897549c34SHans Petter Selasky int mlx4_ib_send_to_slave(struct mlx4_ib_dev *dev, int slave, u8 port,
82997549c34SHans Petter Selasky enum ib_qp_type qpt, struct ib_wc *wc,
83097549c34SHans Petter Selasky struct ib_grh *grh, struct ib_mad *mad);
8318cc48704SHans Petter Selasky
83297549c34SHans Petter Selasky int mlx4_ib_send_to_wire(struct mlx4_ib_dev *dev, int slave, u8 port,
83397549c34SHans Petter Selasky enum ib_qp_type dest_qpt, u16 pkey_index, u32 remote_qpn,
8348cc48704SHans Petter Selasky u32 qkey, struct ib_ah_attr *attr, u8 *s_mac,
8358cc48704SHans Petter Selasky u16 vlan_id, struct ib_mad *mad);
8368cc48704SHans Petter Selasky
83797549c34SHans Petter Selasky __be64 mlx4_ib_get_new_demux_tid(struct mlx4_ib_demux_ctx *ctx);
83897549c34SHans Petter Selasky
83997549c34SHans Petter Selasky int mlx4_ib_demux_cm_handler(struct ib_device *ibdev, int port, int *slave,
8408cc48704SHans Petter Selasky struct ib_mad *mad);
84197549c34SHans Petter Selasky
84297549c34SHans Petter Selasky int mlx4_ib_multiplex_cm_handler(struct ib_device *ibdev, int port, int slave_id,
84397549c34SHans Petter Selasky struct ib_mad *mad);
84497549c34SHans Petter Selasky
84597549c34SHans Petter Selasky void mlx4_ib_cm_paravirt_init(struct mlx4_ib_dev *dev);
84697549c34SHans Petter Selasky void mlx4_ib_cm_paravirt_clean(struct mlx4_ib_dev *dev, int slave_id);
84797549c34SHans Petter Selasky
84897549c34SHans Petter Selasky /* alias guid support */
84997549c34SHans Petter Selasky void mlx4_ib_init_alias_guid_work(struct mlx4_ib_dev *dev, int port);
85097549c34SHans Petter Selasky int mlx4_ib_init_alias_guid_service(struct mlx4_ib_dev *dev);
85197549c34SHans Petter Selasky void mlx4_ib_destroy_alias_guid_service(struct mlx4_ib_dev *dev);
85297549c34SHans Petter Selasky void mlx4_ib_invalidate_all_guid_record(struct mlx4_ib_dev *dev, int port);
85397549c34SHans Petter Selasky
85497549c34SHans Petter Selasky void mlx4_ib_notify_slaves_on_guid_change(struct mlx4_ib_dev *dev,
85597549c34SHans Petter Selasky int block_num,
85697549c34SHans Petter Selasky u8 port_num, u8 *p_data);
85797549c34SHans Petter Selasky
85897549c34SHans Petter Selasky void mlx4_ib_update_cache_on_guid_change(struct mlx4_ib_dev *dev,
85997549c34SHans Petter Selasky int block_num, u8 port_num,
86097549c34SHans Petter Selasky u8 *p_data);
86197549c34SHans Petter Selasky
86297549c34SHans Petter Selasky int add_sysfs_port_mcg_attr(struct mlx4_ib_dev *device, int port_num,
86397549c34SHans Petter Selasky struct attribute *attr);
86497549c34SHans Petter Selasky void del_sysfs_port_mcg_attr(struct mlx4_ib_dev *device, int port_num,
86597549c34SHans Petter Selasky struct attribute *attr);
86697549c34SHans Petter Selasky ib_sa_comp_mask mlx4_ib_get_aguid_comp_mask_from_ix(int index);
8678cc48704SHans Petter Selasky void mlx4_ib_slave_alias_guid_event(struct mlx4_ib_dev *dev, int slave,
8688cc48704SHans Petter Selasky int port, int slave_init);
86997549c34SHans Petter Selasky
87097549c34SHans Petter Selasky int mlx4_ib_device_register_sysfs(struct mlx4_ib_dev *device) ;
87197549c34SHans Petter Selasky
87297549c34SHans Petter Selasky void mlx4_ib_device_unregister_sysfs(struct mlx4_ib_dev *device);
87397549c34SHans Petter Selasky
87497549c34SHans Petter Selasky __be64 mlx4_ib_gen_node_guid(void);
87597549c34SHans Petter Selasky
87697549c34SHans Petter Selasky int mlx4_ib_steer_qp_alloc(struct mlx4_ib_dev *dev, int count, int *qpn);
87797549c34SHans Petter Selasky void mlx4_ib_steer_qp_free(struct mlx4_ib_dev *dev, u32 qpn, int count);
87897549c34SHans Petter Selasky int mlx4_ib_steer_qp_reg(struct mlx4_ib_dev *mdev, struct mlx4_ib_qp *mqp,
87997549c34SHans Petter Selasky int is_attach);
8808cc48704SHans Petter Selasky int mlx4_ib_rereg_user_mr(struct ib_mr *mr, int flags,
8818cc48704SHans Petter Selasky u64 start, u64 length, u64 virt_addr,
8828cc48704SHans Petter Selasky int mr_access_flags, struct ib_pd *pd,
8838cc48704SHans Petter Selasky struct ib_udata *udata);
8848cc48704SHans Petter Selasky int mlx4_ib_gid_index_to_real_index(struct mlx4_ib_dev *ibdev,
8858cc48704SHans Petter Selasky u8 port_num, int index);
8868cc48704SHans Petter Selasky
8878cc48704SHans Petter Selasky void mlx4_sched_ib_sl2vl_update_work(struct mlx4_ib_dev *ibdev,
8888cc48704SHans Petter Selasky int port);
8898cc48704SHans Petter Selasky
8908cc48704SHans Petter Selasky void mlx4_ib_sl2vl_update(struct mlx4_ib_dev *mdev, int port);
89197549c34SHans Petter Selasky
89297549c34SHans Petter Selasky #endif /* MLX4_IB_H */
893