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 868cc48704SHans Petter Selasky struct mlx4_ib_vma_private_data { 878cc48704SHans Petter Selasky struct vm_area_struct *vma; 888cc48704SHans Petter Selasky }; 8997549c34SHans Petter Selasky 9097549c34SHans Petter Selasky struct mlx4_ib_ucontext { 9197549c34SHans Petter Selasky struct ib_ucontext ibucontext; 9297549c34SHans Petter Selasky struct mlx4_uar uar; 9397549c34SHans Petter Selasky struct list_head db_page_list; 9497549c34SHans Petter Selasky struct mutex db_page_mutex; 958cc48704SHans Petter Selasky struct mlx4_ib_vma_private_data hw_bar_info[HW_BAR_COUNT]; 9697549c34SHans Petter Selasky }; 9797549c34SHans Petter Selasky 9897549c34SHans Petter Selasky struct mlx4_ib_pd { 9997549c34SHans Petter Selasky struct ib_pd ibpd; 10097549c34SHans Petter Selasky u32 pdn; 10197549c34SHans Petter Selasky }; 10297549c34SHans Petter Selasky 10397549c34SHans Petter Selasky struct mlx4_ib_xrcd { 10497549c34SHans Petter Selasky struct ib_xrcd ibxrcd; 10597549c34SHans Petter Selasky u32 xrcdn; 10697549c34SHans Petter Selasky struct ib_pd *pd; 10797549c34SHans Petter Selasky struct ib_cq *cq; 10897549c34SHans Petter Selasky }; 10997549c34SHans Petter Selasky 11097549c34SHans Petter Selasky struct mlx4_ib_cq_buf { 11197549c34SHans Petter Selasky struct mlx4_buf buf; 11297549c34SHans Petter Selasky struct mlx4_mtt mtt; 11397549c34SHans Petter Selasky int entry_size; 11497549c34SHans Petter Selasky }; 11597549c34SHans Petter Selasky 11697549c34SHans Petter Selasky struct mlx4_ib_cq_resize { 11797549c34SHans Petter Selasky struct mlx4_ib_cq_buf buf; 11897549c34SHans Petter Selasky int cqe; 11997549c34SHans Petter Selasky }; 12097549c34SHans Petter Selasky 12197549c34SHans Petter Selasky struct mlx4_ib_cq { 12297549c34SHans Petter Selasky struct ib_cq ibcq; 12397549c34SHans Petter Selasky struct mlx4_cq mcq; 12497549c34SHans Petter Selasky struct mlx4_ib_cq_buf buf; 12597549c34SHans Petter Selasky struct mlx4_ib_cq_resize *resize_buf; 12697549c34SHans Petter Selasky struct mlx4_db db; 12797549c34SHans Petter Selasky spinlock_t lock; 12897549c34SHans Petter Selasky struct mutex resize_mutex; 12997549c34SHans Petter Selasky struct ib_umem *umem; 13097549c34SHans Petter Selasky struct ib_umem *resize_umem; 13197549c34SHans Petter Selasky int create_flags; 1328cc48704SHans Petter Selasky /* List of qps that it serves.*/ 1338cc48704SHans Petter Selasky struct list_head send_qp_list; 1348cc48704SHans Petter Selasky struct list_head recv_qp_list; 13597549c34SHans Petter Selasky }; 13697549c34SHans Petter Selasky 1378cc48704SHans Petter Selasky #define MLX4_MR_PAGES_ALIGN 0x40 1388cc48704SHans Petter Selasky 13997549c34SHans Petter Selasky struct mlx4_ib_mr { 14097549c34SHans Petter Selasky struct ib_mr ibmr; 1418cc48704SHans Petter Selasky __be64 *pages; 1428cc48704SHans Petter Selasky dma_addr_t page_map; 1438cc48704SHans Petter Selasky u32 npages; 1448cc48704SHans Petter Selasky u32 max_pages; 14597549c34SHans Petter Selasky struct mlx4_mr mmr; 14697549c34SHans Petter Selasky struct ib_umem *umem; 1478cc48704SHans Petter Selasky size_t page_map_size; 14897549c34SHans Petter Selasky }; 14997549c34SHans Petter Selasky 15097549c34SHans Petter Selasky struct mlx4_ib_mw { 15197549c34SHans Petter Selasky struct ib_mw ibmw; 15297549c34SHans Petter Selasky struct mlx4_mw mmw; 15397549c34SHans Petter Selasky }; 15497549c34SHans Petter Selasky 15597549c34SHans Petter Selasky struct mlx4_ib_fmr { 15697549c34SHans Petter Selasky struct ib_fmr ibfmr; 15797549c34SHans Petter Selasky struct mlx4_fmr mfmr; 15897549c34SHans Petter Selasky }; 15997549c34SHans Petter Selasky 1608cc48704SHans Petter Selasky #define MAX_REGS_PER_FLOW 2 1618cc48704SHans Petter Selasky 1628cc48704SHans Petter Selasky struct mlx4_flow_reg_id { 1638cc48704SHans Petter Selasky u64 id; 1648cc48704SHans Petter Selasky u64 mirror; 1658cc48704SHans Petter Selasky }; 1668cc48704SHans Petter Selasky 16797549c34SHans Petter Selasky struct mlx4_ib_flow { 16897549c34SHans Petter Selasky struct ib_flow ibflow; 16997549c34SHans Petter Selasky /* translating DMFS verbs sniffer rule to FW API requires two reg IDs */ 1708cc48704SHans Petter Selasky struct mlx4_flow_reg_id reg_id[MAX_REGS_PER_FLOW]; 17197549c34SHans Petter Selasky }; 17297549c34SHans Petter Selasky 17397549c34SHans Petter Selasky struct mlx4_ib_wq { 17497549c34SHans Petter Selasky u64 *wrid; 17597549c34SHans Petter Selasky spinlock_t lock; 17697549c34SHans Petter Selasky int wqe_cnt; 17797549c34SHans Petter Selasky int max_post; 17897549c34SHans Petter Selasky int max_gs; 17997549c34SHans Petter Selasky int offset; 18097549c34SHans Petter Selasky int wqe_shift; 18197549c34SHans Petter Selasky unsigned head; 18297549c34SHans Petter Selasky unsigned tail; 18397549c34SHans Petter Selasky }; 18497549c34SHans Petter Selasky 1858cc48704SHans Petter Selasky enum { 1868cc48704SHans Petter Selasky MLX4_IB_QP_CREATE_ROCE_V2_GSI = IB_QP_CREATE_RESERVED_START 1878cc48704SHans Petter Selasky }; 1888cc48704SHans Petter Selasky 18997549c34SHans Petter Selasky enum mlx4_ib_qp_flags { 19097549c34SHans Petter Selasky MLX4_IB_QP_LSO = IB_QP_CREATE_IPOIB_UD_LSO, 19197549c34SHans Petter Selasky MLX4_IB_QP_BLOCK_MULTICAST_LOOPBACK = IB_QP_CREATE_BLOCK_MULTICAST_LOOPBACK, 19297549c34SHans Petter Selasky MLX4_IB_QP_NETIF = IB_QP_CREATE_NETIF_QP, 1938cc48704SHans Petter Selasky MLX4_IB_QP_CREATE_USE_GFP_NOIO = IB_QP_CREATE_USE_GFP_NOIO, 1948cc48704SHans Petter Selasky 1958cc48704SHans Petter Selasky /* Mellanox specific flags start from IB_QP_CREATE_RESERVED_START */ 1968cc48704SHans Petter Selasky MLX4_IB_ROCE_V2_GSI_QP = MLX4_IB_QP_CREATE_ROCE_V2_GSI, 19797549c34SHans Petter Selasky MLX4_IB_SRIOV_TUNNEL_QP = 1 << 30, 19802ca39cfSEitan Adler MLX4_IB_SRIOV_SQP = 1U << 31, 19997549c34SHans Petter Selasky }; 20097549c34SHans Petter Selasky 20197549c34SHans Petter Selasky struct mlx4_ib_gid_entry { 20297549c34SHans Petter Selasky struct list_head list; 20397549c34SHans Petter Selasky union ib_gid gid; 20497549c34SHans Petter Selasky int added; 20597549c34SHans Petter Selasky u8 port; 20697549c34SHans Petter Selasky }; 20797549c34SHans Petter Selasky 20897549c34SHans Petter Selasky enum mlx4_ib_qp_type { 20997549c34SHans Petter Selasky /* 21097549c34SHans Petter Selasky * IB_QPT_SMI and IB_QPT_GSI have to be the first two entries 21197549c34SHans Petter Selasky * here (and in that order) since the MAD layer uses them as 21297549c34SHans Petter Selasky * indices into a 2-entry table. 21397549c34SHans Petter Selasky */ 21497549c34SHans Petter Selasky MLX4_IB_QPT_SMI = IB_QPT_SMI, 21597549c34SHans Petter Selasky MLX4_IB_QPT_GSI = IB_QPT_GSI, 21697549c34SHans Petter Selasky 21797549c34SHans Petter Selasky MLX4_IB_QPT_RC = IB_QPT_RC, 21897549c34SHans Petter Selasky MLX4_IB_QPT_UC = IB_QPT_UC, 21997549c34SHans Petter Selasky MLX4_IB_QPT_UD = IB_QPT_UD, 22097549c34SHans Petter Selasky MLX4_IB_QPT_RAW_IPV6 = IB_QPT_RAW_IPV6, 22197549c34SHans Petter Selasky MLX4_IB_QPT_RAW_ETHERTYPE = IB_QPT_RAW_ETHERTYPE, 22297549c34SHans Petter Selasky MLX4_IB_QPT_RAW_PACKET = IB_QPT_RAW_PACKET, 22397549c34SHans Petter Selasky MLX4_IB_QPT_XRC_INI = IB_QPT_XRC_INI, 22497549c34SHans Petter Selasky MLX4_IB_QPT_XRC_TGT = IB_QPT_XRC_TGT, 22597549c34SHans Petter Selasky 22697549c34SHans Petter Selasky MLX4_IB_QPT_PROXY_SMI_OWNER = 1 << 16, 22797549c34SHans Petter Selasky MLX4_IB_QPT_PROXY_SMI = 1 << 17, 22897549c34SHans Petter Selasky MLX4_IB_QPT_PROXY_GSI = 1 << 18, 22997549c34SHans Petter Selasky MLX4_IB_QPT_TUN_SMI_OWNER = 1 << 19, 23097549c34SHans Petter Selasky MLX4_IB_QPT_TUN_SMI = 1 << 20, 23197549c34SHans Petter Selasky MLX4_IB_QPT_TUN_GSI = 1 << 21, 23297549c34SHans Petter Selasky }; 23397549c34SHans Petter Selasky 23497549c34SHans Petter Selasky #define MLX4_IB_QPT_ANY_SRIOV (MLX4_IB_QPT_PROXY_SMI_OWNER | \ 23597549c34SHans Petter Selasky MLX4_IB_QPT_PROXY_SMI | MLX4_IB_QPT_PROXY_GSI | MLX4_IB_QPT_TUN_SMI_OWNER | \ 23697549c34SHans Petter Selasky MLX4_IB_QPT_TUN_SMI | MLX4_IB_QPT_TUN_GSI) 23797549c34SHans Petter Selasky 23897549c34SHans Petter Selasky enum mlx4_ib_mad_ifc_flags { 23997549c34SHans Petter Selasky MLX4_MAD_IFC_IGNORE_MKEY = 1, 24097549c34SHans Petter Selasky MLX4_MAD_IFC_IGNORE_BKEY = 2, 24197549c34SHans Petter Selasky MLX4_MAD_IFC_IGNORE_KEYS = (MLX4_MAD_IFC_IGNORE_MKEY | 24297549c34SHans Petter Selasky MLX4_MAD_IFC_IGNORE_BKEY), 24397549c34SHans Petter Selasky MLX4_MAD_IFC_NET_VIEW = 4, 24497549c34SHans Petter Selasky }; 24597549c34SHans Petter Selasky 24697549c34SHans Petter Selasky enum { 24797549c34SHans Petter Selasky MLX4_NUM_TUNNEL_BUFS = 256, 24897549c34SHans Petter Selasky }; 24997549c34SHans Petter Selasky 25097549c34SHans Petter Selasky struct mlx4_ib_tunnel_header { 25197549c34SHans Petter Selasky struct mlx4_av av; 25297549c34SHans Petter Selasky __be32 remote_qpn; 25397549c34SHans Petter Selasky __be32 qkey; 25497549c34SHans Petter Selasky __be16 vlan; 25597549c34SHans Petter Selasky u8 mac[6]; 25697549c34SHans Petter Selasky __be16 pkey_index; 25797549c34SHans Petter Selasky u8 reserved[6]; 25897549c34SHans Petter Selasky }; 25997549c34SHans Petter Selasky 26097549c34SHans Petter Selasky struct mlx4_ib_buf { 26197549c34SHans Petter Selasky void *addr; 26297549c34SHans Petter Selasky dma_addr_t map; 26397549c34SHans Petter Selasky }; 26497549c34SHans Petter Selasky 26597549c34SHans Petter Selasky struct mlx4_rcv_tunnel_hdr { 26697549c34SHans Petter Selasky __be32 flags_src_qp; /* flags[6:5] is defined for VLANs: 26797549c34SHans Petter Selasky * 0x0 - no vlan was in the packet 26897549c34SHans Petter Selasky * 0x01 - C-VLAN was in the packet */ 26997549c34SHans Petter Selasky u8 g_ml_path; /* gid bit stands for ipv6/4 header in RoCE */ 27097549c34SHans Petter Selasky u8 reserved; 27197549c34SHans Petter Selasky __be16 pkey_index; 27297549c34SHans Petter Selasky __be16 sl_vid; 27397549c34SHans Petter Selasky __be16 slid_mac_47_32; 27497549c34SHans Petter Selasky __be32 mac_31_0; 27597549c34SHans Petter Selasky }; 27697549c34SHans Petter Selasky 27797549c34SHans Petter Selasky struct mlx4_ib_proxy_sqp_hdr { 27897549c34SHans Petter Selasky struct ib_grh grh; 27997549c34SHans Petter Selasky struct mlx4_rcv_tunnel_hdr tun; 28097549c34SHans Petter Selasky } __packed; 28197549c34SHans Petter Selasky 28297549c34SHans Petter Selasky struct mlx4_roce_smac_vlan_info { 28397549c34SHans Petter Selasky u64 smac; 28497549c34SHans Petter Selasky int smac_index; 28597549c34SHans Petter Selasky int smac_port; 28697549c34SHans Petter Selasky u64 candidate_smac; 28797549c34SHans Petter Selasky int candidate_smac_index; 28897549c34SHans Petter Selasky int candidate_smac_port; 28997549c34SHans Petter Selasky u16 vid; 29097549c34SHans Petter Selasky int vlan_index; 29197549c34SHans Petter Selasky int vlan_port; 29297549c34SHans Petter Selasky u16 candidate_vid; 29397549c34SHans Petter Selasky int candidate_vlan_index; 29497549c34SHans Petter Selasky int candidate_vlan_port; 29597549c34SHans Petter Selasky int update_vid; 29697549c34SHans Petter Selasky }; 29797549c34SHans Petter Selasky 29897549c34SHans Petter Selasky struct mlx4_ib_qp { 29997549c34SHans Petter Selasky struct ib_qp ibqp; 30097549c34SHans Petter Selasky struct mlx4_qp mqp; 30197549c34SHans Petter Selasky struct mlx4_buf buf; 30297549c34SHans Petter Selasky 30397549c34SHans Petter Selasky struct mlx4_db db; 30497549c34SHans Petter Selasky struct mlx4_ib_wq rq; 30597549c34SHans Petter Selasky 30697549c34SHans Petter Selasky u32 doorbell_qpn; 30797549c34SHans Petter Selasky __be32 sq_signal_bits; 30897549c34SHans Petter Selasky unsigned sq_next_wqe; 30997549c34SHans Petter Selasky int sq_max_wqes_per_wr; 31097549c34SHans Petter Selasky int sq_spare_wqes; 31197549c34SHans Petter Selasky struct mlx4_ib_wq sq; 31297549c34SHans Petter Selasky 31397549c34SHans Petter Selasky enum mlx4_ib_qp_type mlx4_ib_qp_type; 31497549c34SHans Petter Selasky struct ib_umem *umem; 31597549c34SHans Petter Selasky struct mlx4_mtt mtt; 31697549c34SHans Petter Selasky int buf_size; 31797549c34SHans Petter Selasky struct mutex mutex; 31897549c34SHans Petter Selasky u16 xrcdn; 31997549c34SHans Petter Selasky u32 flags; 32097549c34SHans Petter Selasky u8 port; 32197549c34SHans Petter Selasky u8 alt_port; 32297549c34SHans Petter Selasky u8 atomic_rd_en; 32397549c34SHans Petter Selasky u8 resp_depth; 32497549c34SHans Petter Selasky u8 sq_no_prefetch; 32597549c34SHans Petter Selasky u8 state; 32697549c34SHans Petter Selasky int mlx_type; 32797549c34SHans Petter Selasky struct list_head gid_list; 32897549c34SHans Petter Selasky struct list_head steering_rules; 32997549c34SHans Petter Selasky struct mlx4_ib_buf *sqp_proxy_rcv; 33097549c34SHans Petter Selasky struct mlx4_roce_smac_vlan_info pri; 33197549c34SHans Petter Selasky struct mlx4_roce_smac_vlan_info alt; 33297549c34SHans Petter Selasky u64 reg_id; 3338cc48704SHans Petter Selasky struct list_head qps_list; 3348cc48704SHans Petter Selasky struct list_head cq_recv_list; 3358cc48704SHans Petter Selasky struct list_head cq_send_list; 3368cc48704SHans Petter Selasky struct counter_index *counter_index; 33797549c34SHans Petter Selasky }; 33897549c34SHans Petter Selasky 33997549c34SHans Petter Selasky struct mlx4_ib_srq { 34097549c34SHans Petter Selasky struct ib_srq ibsrq; 34197549c34SHans Petter Selasky struct mlx4_srq msrq; 34297549c34SHans Petter Selasky struct mlx4_buf buf; 34397549c34SHans Petter Selasky struct mlx4_db db; 34497549c34SHans Petter Selasky u64 *wrid; 34597549c34SHans Petter Selasky spinlock_t lock; 34697549c34SHans Petter Selasky int head; 34797549c34SHans Petter Selasky int tail; 34897549c34SHans Petter Selasky u16 wqe_ctr; 34997549c34SHans Petter Selasky struct ib_umem *umem; 35097549c34SHans Petter Selasky struct mlx4_mtt mtt; 35197549c34SHans Petter Selasky struct mutex mutex; 35297549c34SHans Petter Selasky }; 35397549c34SHans Petter Selasky 35497549c34SHans Petter Selasky struct mlx4_ib_ah { 35597549c34SHans Petter Selasky struct ib_ah ibah; 35697549c34SHans Petter Selasky union mlx4_ext_av av; 35797549c34SHans Petter Selasky }; 35897549c34SHans Petter Selasky 35997549c34SHans Petter Selasky /****************************************/ 36097549c34SHans Petter Selasky /* alias guid support */ 36197549c34SHans Petter Selasky /****************************************/ 36297549c34SHans Petter Selasky #define NUM_PORT_ALIAS_GUID 2 36397549c34SHans Petter Selasky #define NUM_ALIAS_GUID_IN_REC 8 36497549c34SHans Petter Selasky #define NUM_ALIAS_GUID_REC_IN_PORT 16 36597549c34SHans Petter Selasky #define GUID_REC_SIZE 8 36697549c34SHans Petter Selasky #define NUM_ALIAS_GUID_PER_PORT 128 36797549c34SHans Petter Selasky #define MLX4_NOT_SET_GUID (0x00LL) 36897549c34SHans Petter Selasky #define MLX4_GUID_FOR_DELETE_VAL (~(0x00LL)) 36997549c34SHans Petter Selasky 37097549c34SHans Petter Selasky enum mlx4_guid_alias_rec_status { 37197549c34SHans Petter Selasky MLX4_GUID_INFO_STATUS_IDLE, 37297549c34SHans Petter Selasky MLX4_GUID_INFO_STATUS_SET, 37397549c34SHans Petter Selasky }; 37497549c34SHans Petter Selasky 3758cc48704SHans Petter Selasky #define GUID_STATE_NEED_PORT_INIT 0x01 37697549c34SHans Petter Selasky 37797549c34SHans Petter Selasky enum mlx4_guid_alias_rec_method { 37897549c34SHans Petter Selasky MLX4_GUID_INFO_RECORD_SET = IB_MGMT_METHOD_SET, 37997549c34SHans Petter Selasky MLX4_GUID_INFO_RECORD_DELETE = IB_SA_METHOD_DELETE, 38097549c34SHans Petter Selasky }; 38197549c34SHans Petter Selasky 38297549c34SHans Petter Selasky struct mlx4_sriov_alias_guid_info_rec_det { 38397549c34SHans Petter Selasky u8 all_recs[GUID_REC_SIZE * NUM_ALIAS_GUID_IN_REC]; 38497549c34SHans Petter Selasky ib_sa_comp_mask guid_indexes; /*indicates what from the 8 records are valid*/ 38597549c34SHans Petter Selasky enum mlx4_guid_alias_rec_status status; /*indicates the administraively status of the record.*/ 3868cc48704SHans Petter Selasky unsigned int guids_retry_schedule[NUM_ALIAS_GUID_IN_REC]; 3878cc48704SHans Petter Selasky u64 time_to_run; 38897549c34SHans Petter Selasky }; 38997549c34SHans Petter Selasky 39097549c34SHans Petter Selasky struct mlx4_sriov_alias_guid_port_rec_det { 39197549c34SHans Petter Selasky struct mlx4_sriov_alias_guid_info_rec_det all_rec_per_port[NUM_ALIAS_GUID_REC_IN_PORT]; 39297549c34SHans Petter Selasky struct workqueue_struct *wq; 39397549c34SHans Petter Selasky struct delayed_work alias_guid_work; 39497549c34SHans Petter Selasky u8 port; 3958cc48704SHans Petter Selasky u32 state_flags; 39697549c34SHans Petter Selasky struct mlx4_sriov_alias_guid *parent; 39797549c34SHans Petter Selasky struct list_head cb_list; 39897549c34SHans Petter Selasky }; 39997549c34SHans Petter Selasky 40097549c34SHans Petter Selasky struct mlx4_sriov_alias_guid { 40197549c34SHans Petter Selasky struct mlx4_sriov_alias_guid_port_rec_det ports_guid[MLX4_MAX_PORTS]; 40297549c34SHans Petter Selasky spinlock_t ag_work_lock; 40397549c34SHans Petter Selasky struct ib_sa_client *sa_client; 40497549c34SHans Petter Selasky }; 40597549c34SHans Petter Selasky 40697549c34SHans Petter Selasky struct mlx4_ib_demux_work { 40797549c34SHans Petter Selasky struct work_struct work; 40897549c34SHans Petter Selasky struct mlx4_ib_dev *dev; 40997549c34SHans Petter Selasky int slave; 41097549c34SHans Petter Selasky int do_init; 41197549c34SHans Petter Selasky u8 port; 41297549c34SHans Petter Selasky 41397549c34SHans Petter Selasky }; 41497549c34SHans Petter Selasky 41597549c34SHans Petter Selasky struct mlx4_ib_tun_tx_buf { 41697549c34SHans Petter Selasky struct mlx4_ib_buf buf; 41797549c34SHans Petter Selasky struct ib_ah *ah; 41897549c34SHans Petter Selasky }; 41997549c34SHans Petter Selasky 42097549c34SHans Petter Selasky struct mlx4_ib_demux_pv_qp { 42197549c34SHans Petter Selasky struct ib_qp *qp; 42297549c34SHans Petter Selasky enum ib_qp_type proxy_qpt; 42397549c34SHans Petter Selasky struct mlx4_ib_buf *ring; 42497549c34SHans Petter Selasky struct mlx4_ib_tun_tx_buf *tx_ring; 42597549c34SHans Petter Selasky spinlock_t tx_lock; 42697549c34SHans Petter Selasky unsigned tx_ix_head; 42797549c34SHans Petter Selasky unsigned tx_ix_tail; 42897549c34SHans Petter Selasky }; 42997549c34SHans Petter Selasky 43097549c34SHans Petter Selasky enum mlx4_ib_demux_pv_state { 43197549c34SHans Petter Selasky DEMUX_PV_STATE_DOWN, 43297549c34SHans Petter Selasky DEMUX_PV_STATE_STARTING, 43397549c34SHans Petter Selasky DEMUX_PV_STATE_ACTIVE, 43497549c34SHans Petter Selasky DEMUX_PV_STATE_DOWNING, 43597549c34SHans Petter Selasky }; 43697549c34SHans Petter Selasky 43797549c34SHans Petter Selasky struct mlx4_ib_demux_pv_ctx { 43897549c34SHans Petter Selasky int port; 43997549c34SHans Petter Selasky int slave; 44097549c34SHans Petter Selasky enum mlx4_ib_demux_pv_state state; 44197549c34SHans Petter Selasky int has_smi; 44297549c34SHans Petter Selasky struct ib_device *ib_dev; 44397549c34SHans Petter Selasky struct ib_cq *cq; 44497549c34SHans Petter Selasky struct ib_pd *pd; 44597549c34SHans Petter Selasky struct work_struct work; 44697549c34SHans Petter Selasky struct workqueue_struct *wq; 44797549c34SHans Petter Selasky struct mlx4_ib_demux_pv_qp qp[2]; 44897549c34SHans Petter Selasky }; 44997549c34SHans Petter Selasky 45097549c34SHans Petter Selasky struct mlx4_ib_demux_ctx { 45197549c34SHans Petter Selasky struct ib_device *ib_dev; 45297549c34SHans Petter Selasky int port; 45397549c34SHans Petter Selasky struct workqueue_struct *wq; 45497549c34SHans Petter Selasky struct workqueue_struct *ud_wq; 45597549c34SHans Petter Selasky spinlock_t ud_lock; 4568cc48704SHans Petter Selasky atomic64_t subnet_prefix; 45797549c34SHans Petter Selasky __be64 guid_cache[128]; 45897549c34SHans Petter Selasky struct mlx4_ib_dev *dev; 45997549c34SHans Petter Selasky /* the following lock protects both mcg_table and mcg_mgid0_list */ 46097549c34SHans Petter Selasky struct mutex mcg_table_lock; 46197549c34SHans Petter Selasky struct rb_root mcg_table; 46297549c34SHans Petter Selasky struct list_head mcg_mgid0_list; 46397549c34SHans Petter Selasky struct workqueue_struct *mcg_wq; 46497549c34SHans Petter Selasky struct mlx4_ib_demux_pv_ctx **tun; 46597549c34SHans Petter Selasky atomic_t tid; 46697549c34SHans Petter Selasky int flushing; /* flushing the work queue */ 46797549c34SHans Petter Selasky }; 46897549c34SHans Petter Selasky 46997549c34SHans Petter Selasky struct mlx4_ib_sriov { 47097549c34SHans Petter Selasky struct mlx4_ib_demux_ctx demux[MLX4_MAX_PORTS]; 47197549c34SHans Petter Selasky struct mlx4_ib_demux_pv_ctx *sqps[MLX4_MAX_PORTS]; 47297549c34SHans Petter Selasky /* when using this spinlock you should use "irq" because 47397549c34SHans Petter Selasky * it may be called from interrupt context.*/ 47497549c34SHans Petter Selasky spinlock_t going_down_lock; 47597549c34SHans Petter Selasky int is_going_down; 47697549c34SHans Petter Selasky 47797549c34SHans Petter Selasky struct mlx4_sriov_alias_guid alias_guid; 47897549c34SHans Petter Selasky 47997549c34SHans Petter Selasky /* CM paravirtualization fields */ 48097549c34SHans Petter Selasky struct list_head cm_list; 48197549c34SHans Petter Selasky spinlock_t id_map_lock; 48297549c34SHans Petter Selasky struct rb_root sl_id_map; 48397549c34SHans Petter Selasky struct idr pv_id_table; 48497549c34SHans Petter Selasky }; 48597549c34SHans Petter Selasky 4868cc48704SHans Petter Selasky struct gid_cache_context { 4878cc48704SHans Petter Selasky int real_index; 4888cc48704SHans Petter Selasky int refcount; 4898cc48704SHans Petter Selasky }; 4908cc48704SHans Petter Selasky 4918cc48704SHans Petter Selasky struct gid_entry { 4928cc48704SHans Petter Selasky union ib_gid gid; 4938cc48704SHans Petter Selasky enum ib_gid_type gid_type; 4948cc48704SHans Petter Selasky struct gid_cache_context *ctx; 4958cc48704SHans Petter Selasky }; 4968cc48704SHans Petter Selasky 4978cc48704SHans Petter Selasky struct mlx4_port_gid_table { 4988cc48704SHans Petter Selasky struct gid_entry gids[MLX4_MAX_PORT_GIDS]; 4998cc48704SHans Petter Selasky }; 5008cc48704SHans Petter Selasky 50197549c34SHans Petter Selasky struct mlx4_ib_iboe { 50297549c34SHans Petter Selasky spinlock_t lock; 50397549c34SHans Petter Selasky struct net_device *netdevs[MLX4_MAX_PORTS]; 5048cc48704SHans Petter Selasky atomic64_t mac[MLX4_MAX_PORTS]; 50597549c34SHans Petter Selasky struct notifier_block nb; 5068cc48704SHans Petter Selasky struct mlx4_port_gid_table gids[MLX4_MAX_PORTS]; 50797549c34SHans Petter Selasky }; 50897549c34SHans Petter Selasky 50997549c34SHans Petter Selasky struct pkey_mgt { 51097549c34SHans Petter Selasky u8 virt2phys_pkey[MLX4_MFUNC_MAX][MLX4_MAX_PORTS][MLX4_MAX_PORT_PKEYS]; 51197549c34SHans Petter Selasky u16 phys_pkey_cache[MLX4_MAX_PORTS][MLX4_MAX_PORT_PKEYS]; 51297549c34SHans Petter Selasky struct list_head pkey_port_list[MLX4_MFUNC_MAX]; 51397549c34SHans Petter Selasky struct kobject *device_parent[MLX4_MFUNC_MAX]; 51497549c34SHans Petter Selasky }; 51597549c34SHans Petter Selasky 51697549c34SHans Petter Selasky struct mlx4_ib_iov_sysfs_attr { 51797549c34SHans Petter Selasky void *ctx; 51897549c34SHans Petter Selasky struct kobject *kobj; 51997549c34SHans Petter Selasky unsigned long data; 52097549c34SHans Petter Selasky u32 entry_num; 52197549c34SHans Petter Selasky char name[15]; 52297549c34SHans Petter Selasky struct device_attribute dentry; 52397549c34SHans Petter Selasky struct device *dev; 52497549c34SHans Petter Selasky }; 52597549c34SHans Petter Selasky 52697549c34SHans Petter Selasky struct mlx4_ib_iov_sysfs_attr_ar { 52797549c34SHans Petter Selasky struct mlx4_ib_iov_sysfs_attr dentries[3 * NUM_ALIAS_GUID_PER_PORT + 1]; 52897549c34SHans Petter Selasky }; 52997549c34SHans Petter Selasky 53097549c34SHans Petter Selasky struct mlx4_ib_iov_port { 53197549c34SHans Petter Selasky char name[100]; 53297549c34SHans Petter Selasky u8 num; 53397549c34SHans Petter Selasky struct mlx4_ib_dev *dev; 53497549c34SHans Petter Selasky struct list_head list; 53597549c34SHans Petter Selasky struct mlx4_ib_iov_sysfs_attr_ar *dentr_ar; 53697549c34SHans Petter Selasky struct ib_port_attr attr; 53797549c34SHans Petter Selasky struct kobject *cur_port; 53897549c34SHans Petter Selasky struct kobject *admin_alias_parent; 53997549c34SHans Petter Selasky struct kobject *gids_parent; 54097549c34SHans Petter Selasky struct kobject *pkeys_parent; 54197549c34SHans Petter Selasky struct kobject *mcgs_parent; 54297549c34SHans Petter Selasky struct mlx4_ib_iov_sysfs_attr mcg_dentry; 54397549c34SHans Petter Selasky }; 54497549c34SHans Petter Selasky 5458cc48704SHans Petter Selasky struct counter_index { 5468cc48704SHans Petter Selasky struct list_head list; 5478cc48704SHans Petter Selasky u32 index; 5488cc48704SHans Petter Selasky u8 allocated; 5498cc48704SHans Petter Selasky }; 5508cc48704SHans Petter Selasky 5518cc48704SHans Petter Selasky struct mlx4_ib_counters { 5528cc48704SHans Petter Selasky struct list_head counters_list; 5538cc48704SHans Petter Selasky struct mutex mutex; /* mutex for accessing counters list */ 5548cc48704SHans Petter Selasky u32 default_counter; 5558cc48704SHans Petter Selasky }; 5568cc48704SHans Petter Selasky 5578cc48704SHans Petter Selasky #define MLX4_DIAG_COUNTERS_TYPES 2 5588cc48704SHans Petter Selasky 5598cc48704SHans Petter Selasky struct mlx4_ib_diag_counters { 5608cc48704SHans Petter Selasky const char **name; 5618cc48704SHans Petter Selasky u32 *offset; 5628cc48704SHans Petter Selasky u32 num_counters; 56397549c34SHans Petter Selasky }; 56497549c34SHans Petter Selasky 56597549c34SHans Petter Selasky struct mlx4_ib_dev { 56697549c34SHans Petter Selasky struct ib_device ib_dev; 56797549c34SHans Petter Selasky struct mlx4_dev *dev; 56897549c34SHans Petter Selasky int num_ports; 5698cc48704SHans Petter Selasky void __iomem *uar_map; 5708cc48704SHans Petter Selasky 57197549c34SHans Petter Selasky struct mlx4_uar priv_uar; 57297549c34SHans Petter Selasky u32 priv_pdn; 57397549c34SHans Petter Selasky MLX4_DECLARE_DOORBELL_LOCK(uar_lock); 57497549c34SHans Petter Selasky 57597549c34SHans Petter Selasky struct ib_mad_agent *send_agent[MLX4_MAX_PORTS][2]; 57697549c34SHans Petter Selasky struct ib_ah *sm_ah[MLX4_MAX_PORTS]; 57797549c34SHans Petter Selasky spinlock_t sm_lock; 5788cc48704SHans Petter Selasky atomic64_t sl2vl[MLX4_MAX_PORTS]; 57997549c34SHans Petter Selasky struct mlx4_ib_sriov sriov; 58097549c34SHans Petter Selasky 58197549c34SHans Petter Selasky struct mutex cap_mask_mutex; 58297549c34SHans Petter Selasky bool ib_active; 58397549c34SHans Petter Selasky struct mlx4_ib_iboe iboe; 5848cc48704SHans Petter Selasky struct mlx4_ib_counters counters_table[MLX4_MAX_PORTS]; 58597549c34SHans Petter Selasky int *eq_table; 58697549c34SHans Petter Selasky struct kobject *iov_parent; 58797549c34SHans Petter Selasky struct kobject *ports_parent; 58897549c34SHans Petter Selasky struct kobject *dev_ports_parent[MLX4_MFUNC_MAX]; 58997549c34SHans Petter Selasky struct mlx4_ib_iov_port iov_ports[MLX4_MAX_PORTS]; 59097549c34SHans Petter Selasky struct pkey_mgt pkeys; 59197549c34SHans Petter Selasky unsigned long *ib_uc_qpns_bitmap; 59297549c34SHans Petter Selasky int steer_qpn_count; 59397549c34SHans Petter Selasky int steer_qpn_base; 5948cc48704SHans Petter Selasky int steering_support; 5958cc48704SHans Petter Selasky struct mlx4_ib_qp *qp1_proxy[MLX4_MAX_PORTS]; 5968cc48704SHans Petter Selasky /* lock when destroying qp1_proxy and getting netdev events */ 5978cc48704SHans Petter Selasky struct mutex qp1_proxy_lock[MLX4_MAX_PORTS]; 5988cc48704SHans Petter Selasky u8 bond_next_port; 5998cc48704SHans Petter Selasky /* protect resources needed as part of reset flow */ 6008cc48704SHans Petter Selasky spinlock_t reset_flow_resource_lock; 6018cc48704SHans Petter Selasky struct list_head qp_list; 6028cc48704SHans Petter Selasky struct mlx4_ib_diag_counters diag_counters[MLX4_DIAG_COUNTERS_TYPES]; 60397549c34SHans Petter Selasky }; 60497549c34SHans Petter Selasky 60597549c34SHans Petter Selasky struct ib_event_work { 60697549c34SHans Petter Selasky struct work_struct work; 60797549c34SHans Petter Selasky struct mlx4_ib_dev *ib_dev; 60897549c34SHans Petter Selasky struct mlx4_eqe ib_eqe; 6098cc48704SHans Petter Selasky int port; 61097549c34SHans Petter Selasky }; 61197549c34SHans Petter Selasky 61297549c34SHans Petter Selasky struct mlx4_ib_qp_tunnel_init_attr { 61397549c34SHans Petter Selasky struct ib_qp_init_attr init_attr; 61497549c34SHans Petter Selasky int slave; 61597549c34SHans Petter Selasky enum ib_qp_type proxy_qp_type; 61697549c34SHans Petter Selasky u8 port; 61797549c34SHans Petter Selasky }; 61897549c34SHans Petter Selasky 6198cc48704SHans Petter Selasky struct mlx4_uverbs_ex_query_device { 6208cc48704SHans Petter Selasky __u32 comp_mask; 6218cc48704SHans Petter Selasky __u32 reserved; 6228cc48704SHans Petter Selasky }; 6238cc48704SHans Petter Selasky 6248cc48704SHans Petter Selasky enum query_device_resp_mask { 6258cc48704SHans Petter Selasky QUERY_DEVICE_RESP_MASK_TIMESTAMP = 1UL << 0, 6268cc48704SHans Petter Selasky }; 6278cc48704SHans Petter Selasky 6288cc48704SHans Petter Selasky struct mlx4_uverbs_ex_query_device_resp { 6298cc48704SHans Petter Selasky __u32 comp_mask; 6308cc48704SHans Petter Selasky __u32 response_length; 6318cc48704SHans Petter Selasky __u64 hca_core_clock_offset; 6328cc48704SHans Petter Selasky }; 6338cc48704SHans Petter Selasky 63497549c34SHans Petter Selasky static inline struct mlx4_ib_dev *to_mdev(struct ib_device *ibdev) 63597549c34SHans Petter Selasky { 63697549c34SHans Petter Selasky return container_of(ibdev, struct mlx4_ib_dev, ib_dev); 63797549c34SHans Petter Selasky } 63897549c34SHans Petter Selasky 63997549c34SHans Petter Selasky static inline struct mlx4_ib_ucontext *to_mucontext(struct ib_ucontext *ibucontext) 64097549c34SHans Petter Selasky { 64197549c34SHans Petter Selasky return container_of(ibucontext, struct mlx4_ib_ucontext, ibucontext); 64297549c34SHans Petter Selasky } 64397549c34SHans Petter Selasky 64497549c34SHans Petter Selasky static inline struct mlx4_ib_pd *to_mpd(struct ib_pd *ibpd) 64597549c34SHans Petter Selasky { 64697549c34SHans Petter Selasky return container_of(ibpd, struct mlx4_ib_pd, ibpd); 64797549c34SHans Petter Selasky } 64897549c34SHans Petter Selasky 64997549c34SHans Petter Selasky static inline struct mlx4_ib_xrcd *to_mxrcd(struct ib_xrcd *ibxrcd) 65097549c34SHans Petter Selasky { 65197549c34SHans Petter Selasky return container_of(ibxrcd, struct mlx4_ib_xrcd, ibxrcd); 65297549c34SHans Petter Selasky } 65397549c34SHans Petter Selasky 65497549c34SHans Petter Selasky static inline struct mlx4_ib_cq *to_mcq(struct ib_cq *ibcq) 65597549c34SHans Petter Selasky { 65697549c34SHans Petter Selasky return container_of(ibcq, struct mlx4_ib_cq, ibcq); 65797549c34SHans Petter Selasky } 65897549c34SHans Petter Selasky 65997549c34SHans Petter Selasky static inline struct mlx4_ib_cq *to_mibcq(struct mlx4_cq *mcq) 66097549c34SHans Petter Selasky { 66197549c34SHans Petter Selasky return container_of(mcq, struct mlx4_ib_cq, mcq); 66297549c34SHans Petter Selasky } 66397549c34SHans Petter Selasky 66497549c34SHans Petter Selasky static inline struct mlx4_ib_mr *to_mmr(struct ib_mr *ibmr) 66597549c34SHans Petter Selasky { 66697549c34SHans Petter Selasky return container_of(ibmr, struct mlx4_ib_mr, ibmr); 66797549c34SHans Petter Selasky } 66897549c34SHans Petter Selasky 66997549c34SHans Petter Selasky static inline struct mlx4_ib_mw *to_mmw(struct ib_mw *ibmw) 67097549c34SHans Petter Selasky { 67197549c34SHans Petter Selasky return container_of(ibmw, struct mlx4_ib_mw, ibmw); 67297549c34SHans Petter Selasky } 67397549c34SHans Petter Selasky 67497549c34SHans Petter Selasky static inline struct mlx4_ib_fmr *to_mfmr(struct ib_fmr *ibfmr) 67597549c34SHans Petter Selasky { 67697549c34SHans Petter Selasky return container_of(ibfmr, struct mlx4_ib_fmr, ibfmr); 67797549c34SHans Petter Selasky } 67897549c34SHans Petter Selasky 67997549c34SHans Petter Selasky static inline struct mlx4_ib_flow *to_mflow(struct ib_flow *ibflow) 68097549c34SHans Petter Selasky { 68197549c34SHans Petter Selasky return container_of(ibflow, struct mlx4_ib_flow, ibflow); 68297549c34SHans Petter Selasky } 68397549c34SHans Petter Selasky 68497549c34SHans Petter Selasky static inline struct mlx4_ib_qp *to_mqp(struct ib_qp *ibqp) 68597549c34SHans Petter Selasky { 68697549c34SHans Petter Selasky return container_of(ibqp, struct mlx4_ib_qp, ibqp); 68797549c34SHans Petter Selasky } 68897549c34SHans Petter Selasky 68997549c34SHans Petter Selasky static inline struct mlx4_ib_qp *to_mibqp(struct mlx4_qp *mqp) 69097549c34SHans Petter Selasky { 69197549c34SHans Petter Selasky return container_of(mqp, struct mlx4_ib_qp, mqp); 69297549c34SHans Petter Selasky } 69397549c34SHans Petter Selasky 69497549c34SHans Petter Selasky static inline struct mlx4_ib_srq *to_msrq(struct ib_srq *ibsrq) 69597549c34SHans Petter Selasky { 69697549c34SHans Petter Selasky return container_of(ibsrq, struct mlx4_ib_srq, ibsrq); 69797549c34SHans Petter Selasky } 69897549c34SHans Petter Selasky 69997549c34SHans Petter Selasky static inline struct mlx4_ib_srq *to_mibsrq(struct mlx4_srq *msrq) 70097549c34SHans Petter Selasky { 70197549c34SHans Petter Selasky return container_of(msrq, struct mlx4_ib_srq, msrq); 70297549c34SHans Petter Selasky } 70397549c34SHans Petter Selasky 70497549c34SHans Petter Selasky static inline struct mlx4_ib_ah *to_mah(struct ib_ah *ibah) 70597549c34SHans Petter Selasky { 70697549c34SHans Petter Selasky return container_of(ibah, struct mlx4_ib_ah, ibah); 70797549c34SHans Petter Selasky } 70897549c34SHans Petter Selasky 7098cc48704SHans Petter Selasky static inline u8 mlx4_ib_bond_next_port(struct mlx4_ib_dev *dev) 7108cc48704SHans Petter Selasky { 7118cc48704SHans Petter Selasky dev->bond_next_port = (dev->bond_next_port + 1) % dev->num_ports; 7128cc48704SHans Petter Selasky 7138cc48704SHans Petter Selasky return dev->bond_next_port + 1; 7148cc48704SHans Petter Selasky } 7158cc48704SHans Petter Selasky 71697549c34SHans Petter Selasky int mlx4_ib_init_sriov(struct mlx4_ib_dev *dev); 71797549c34SHans Petter Selasky void mlx4_ib_close_sriov(struct mlx4_ib_dev *dev); 71897549c34SHans Petter Selasky 71997549c34SHans Petter Selasky int mlx4_ib_db_map_user(struct mlx4_ib_ucontext *context, unsigned long virt, 72097549c34SHans Petter Selasky struct mlx4_db *db); 72197549c34SHans Petter Selasky void mlx4_ib_db_unmap_user(struct mlx4_ib_ucontext *context, struct mlx4_db *db); 72297549c34SHans Petter Selasky 72397549c34SHans Petter Selasky struct ib_mr *mlx4_ib_get_dma_mr(struct ib_pd *pd, int acc); 72497549c34SHans Petter Selasky int mlx4_ib_umem_write_mtt(struct mlx4_ib_dev *dev, struct mlx4_mtt *mtt, 72597549c34SHans Petter Selasky struct ib_umem *umem); 72697549c34SHans Petter Selasky struct ib_mr *mlx4_ib_reg_user_mr(struct ib_pd *pd, u64 start, u64 length, 72797549c34SHans Petter Selasky u64 virt_addr, int access_flags, 7288cc48704SHans Petter Selasky struct ib_udata *udata); 72997549c34SHans Petter Selasky int mlx4_ib_dereg_mr(struct ib_mr *mr); 7308cc48704SHans Petter Selasky struct ib_mw *mlx4_ib_alloc_mw(struct ib_pd *pd, enum ib_mw_type type, 7318cc48704SHans Petter Selasky struct ib_udata *udata); 73297549c34SHans Petter Selasky int mlx4_ib_dealloc_mw(struct ib_mw *mw); 7338cc48704SHans Petter Selasky struct ib_mr *mlx4_ib_alloc_mr(struct ib_pd *pd, 7348cc48704SHans Petter Selasky enum ib_mr_type mr_type, 7358cc48704SHans Petter Selasky u32 max_num_sg); 7368cc48704SHans Petter Selasky int mlx4_ib_map_mr_sg(struct ib_mr *ibmr, struct scatterlist *sg, int sg_nents, 7378cc48704SHans Petter Selasky unsigned int *sg_offset); 7388cc48704SHans Petter Selasky int mlx4_ib_modify_cq(struct ib_cq *cq, u16 cq_count, u16 cq_period); 73997549c34SHans Petter Selasky int mlx4_ib_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata); 74097549c34SHans Petter Selasky struct ib_cq *mlx4_ib_create_cq(struct ib_device *ibdev, 7418cc48704SHans Petter Selasky const struct ib_cq_init_attr *attr, 74297549c34SHans Petter Selasky struct ib_ucontext *context, 74397549c34SHans Petter Selasky struct ib_udata *udata); 74497549c34SHans Petter Selasky int mlx4_ib_destroy_cq(struct ib_cq *cq); 74597549c34SHans Petter Selasky int mlx4_ib_poll_cq(struct ib_cq *ibcq, int num_entries, struct ib_wc *wc); 74697549c34SHans Petter Selasky int mlx4_ib_arm_cq(struct ib_cq *cq, enum ib_cq_notify_flags flags); 74797549c34SHans Petter Selasky void __mlx4_ib_cq_clean(struct mlx4_ib_cq *cq, u32 qpn, struct mlx4_ib_srq *srq); 74897549c34SHans Petter Selasky void mlx4_ib_cq_clean(struct mlx4_ib_cq *cq, u32 qpn, struct mlx4_ib_srq *srq); 74997549c34SHans Petter Selasky 750*1456d97cSHans Petter Selasky struct ib_ah *mlx4_ib_create_ah(struct ib_pd *pd, struct ib_ah_attr *ah_attr, 751*1456d97cSHans Petter Selasky struct ib_udata *udata); 75297549c34SHans Petter Selasky int mlx4_ib_query_ah(struct ib_ah *ibah, struct ib_ah_attr *ah_attr); 75397549c34SHans Petter Selasky int mlx4_ib_destroy_ah(struct ib_ah *ah); 75497549c34SHans Petter Selasky 75597549c34SHans Petter Selasky struct ib_srq *mlx4_ib_create_srq(struct ib_pd *pd, 75697549c34SHans Petter Selasky struct ib_srq_init_attr *init_attr, 75797549c34SHans Petter Selasky struct ib_udata *udata); 75897549c34SHans Petter Selasky int mlx4_ib_modify_srq(struct ib_srq *ibsrq, struct ib_srq_attr *attr, 75997549c34SHans Petter Selasky enum ib_srq_attr_mask attr_mask, struct ib_udata *udata); 76097549c34SHans Petter Selasky int mlx4_ib_query_srq(struct ib_srq *srq, struct ib_srq_attr *srq_attr); 76197549c34SHans Petter Selasky int mlx4_ib_destroy_srq(struct ib_srq *srq); 76297549c34SHans Petter Selasky void mlx4_ib_free_srq_wqe(struct mlx4_ib_srq *srq, int wqe_index); 76397549c34SHans Petter Selasky int mlx4_ib_post_srq_recv(struct ib_srq *ibsrq, struct ib_recv_wr *wr, 76497549c34SHans Petter Selasky struct ib_recv_wr **bad_wr); 76597549c34SHans Petter Selasky 76697549c34SHans Petter Selasky struct ib_qp *mlx4_ib_create_qp(struct ib_pd *pd, 76797549c34SHans Petter Selasky struct ib_qp_init_attr *init_attr, 76897549c34SHans Petter Selasky struct ib_udata *udata); 76997549c34SHans Petter Selasky int mlx4_ib_destroy_qp(struct ib_qp *qp); 77097549c34SHans Petter Selasky int mlx4_ib_modify_qp(struct ib_qp *ibqp, struct ib_qp_attr *attr, 77197549c34SHans Petter Selasky int attr_mask, struct ib_udata *udata); 77297549c34SHans Petter Selasky int mlx4_ib_query_qp(struct ib_qp *ibqp, struct ib_qp_attr *qp_attr, int qp_attr_mask, 77397549c34SHans Petter Selasky struct ib_qp_init_attr *qp_init_attr); 77497549c34SHans Petter Selasky int mlx4_ib_post_send(struct ib_qp *ibqp, struct ib_send_wr *wr, 77597549c34SHans Petter Selasky struct ib_send_wr **bad_wr); 77697549c34SHans Petter Selasky int mlx4_ib_post_recv(struct ib_qp *ibqp, struct ib_recv_wr *wr, 77797549c34SHans Petter Selasky struct ib_recv_wr **bad_wr); 77897549c34SHans Petter Selasky 77997549c34SHans Petter Selasky int mlx4_MAD_IFC(struct mlx4_ib_dev *dev, int mad_ifc_flags, 7808cc48704SHans Petter Selasky int port, const struct ib_wc *in_wc, const struct ib_grh *in_grh, 7818cc48704SHans Petter Selasky const void *in_mad, void *response_mad); 78297549c34SHans Petter Selasky int mlx4_ib_process_mad(struct ib_device *ibdev, int mad_flags, u8 port_num, 7838cc48704SHans Petter Selasky const struct ib_wc *in_wc, const struct ib_grh *in_grh, 7848cc48704SHans Petter Selasky const struct ib_mad_hdr *in, size_t in_mad_size, 7858cc48704SHans Petter Selasky struct ib_mad_hdr *out, size_t *out_mad_size, 7868cc48704SHans Petter Selasky u16 *out_mad_pkey_index); 78797549c34SHans Petter Selasky int mlx4_ib_mad_init(struct mlx4_ib_dev *dev); 78897549c34SHans Petter Selasky void mlx4_ib_mad_cleanup(struct mlx4_ib_dev *dev); 78997549c34SHans Petter Selasky 79097549c34SHans Petter Selasky struct ib_fmr *mlx4_ib_fmr_alloc(struct ib_pd *pd, int mr_access_flags, 79197549c34SHans Petter Selasky struct ib_fmr_attr *fmr_attr); 79297549c34SHans Petter Selasky int mlx4_ib_map_phys_fmr(struct ib_fmr *ibfmr, u64 *page_list, int npages, 79397549c34SHans Petter Selasky u64 iova); 79497549c34SHans Petter Selasky int mlx4_ib_unmap_fmr(struct list_head *fmr_list); 79597549c34SHans Petter Selasky int mlx4_ib_fmr_dealloc(struct ib_fmr *fmr); 79697549c34SHans Petter Selasky int __mlx4_ib_query_port(struct ib_device *ibdev, u8 port, 79797549c34SHans Petter Selasky struct ib_port_attr *props, int netw_view); 79897549c34SHans Petter Selasky int __mlx4_ib_query_pkey(struct ib_device *ibdev, u8 port, u16 index, 79997549c34SHans Petter Selasky u16 *pkey, int netw_view); 80097549c34SHans Petter Selasky 80197549c34SHans Petter Selasky int __mlx4_ib_query_gid(struct ib_device *ibdev, u8 port, int index, 80297549c34SHans Petter Selasky union ib_gid *gid, int netw_view); 80397549c34SHans Petter Selasky 8048cc48704SHans Petter Selasky static inline bool mlx4_ib_ah_grh_present(struct mlx4_ib_ah *ah) 80597549c34SHans Petter Selasky { 80697549c34SHans Petter Selasky u8 port = be32_to_cpu(ah->av.ib.port_pd) >> 24 & 3; 80797549c34SHans Petter Selasky 80897549c34SHans Petter Selasky if (rdma_port_get_link_layer(ah->ibah.device, port) == IB_LINK_LAYER_ETHERNET) 8098cc48704SHans Petter Selasky return true; 81097549c34SHans Petter Selasky 81197549c34SHans Petter Selasky return !!(ah->av.ib.g_slid & 0x80); 81297549c34SHans Petter Selasky } 81397549c34SHans Petter Selasky 81497549c34SHans Petter Selasky int mlx4_ib_mcg_port_init(struct mlx4_ib_demux_ctx *ctx); 81597549c34SHans Petter Selasky void mlx4_ib_mcg_port_cleanup(struct mlx4_ib_demux_ctx *ctx, int destroy_wq); 81697549c34SHans Petter Selasky void clean_vf_mcast(struct mlx4_ib_demux_ctx *ctx, int slave); 81797549c34SHans Petter Selasky int mlx4_ib_mcg_init(void); 81897549c34SHans Petter Selasky void mlx4_ib_mcg_destroy(void); 81997549c34SHans Petter Selasky 82097549c34SHans Petter Selasky int mlx4_ib_find_real_gid(struct ib_device *ibdev, u8 port, __be64 guid); 82197549c34SHans Petter Selasky 82297549c34SHans Petter Selasky int mlx4_ib_mcg_multiplex_handler(struct ib_device *ibdev, int port, int slave, 82397549c34SHans Petter Selasky struct ib_sa_mad *sa_mad); 82497549c34SHans Petter Selasky int mlx4_ib_mcg_demux_handler(struct ib_device *ibdev, int port, int slave, 82597549c34SHans Petter Selasky struct ib_sa_mad *mad); 82697549c34SHans Petter Selasky 82797549c34SHans Petter Selasky int mlx4_ib_add_mc(struct mlx4_ib_dev *mdev, struct mlx4_ib_qp *mqp, 82897549c34SHans Petter Selasky union ib_gid *gid); 82997549c34SHans Petter Selasky 83097549c34SHans Petter Selasky void mlx4_ib_dispatch_event(struct mlx4_ib_dev *dev, u8 port_num, 83197549c34SHans Petter Selasky enum ib_event_type type); 83297549c34SHans Petter Selasky 83397549c34SHans Petter Selasky void mlx4_ib_tunnels_update_work(struct work_struct *work); 83497549c34SHans Petter Selasky 83597549c34SHans Petter Selasky int mlx4_ib_send_to_slave(struct mlx4_ib_dev *dev, int slave, u8 port, 83697549c34SHans Petter Selasky enum ib_qp_type qpt, struct ib_wc *wc, 83797549c34SHans Petter Selasky struct ib_grh *grh, struct ib_mad *mad); 8388cc48704SHans Petter Selasky 83997549c34SHans Petter Selasky int mlx4_ib_send_to_wire(struct mlx4_ib_dev *dev, int slave, u8 port, 84097549c34SHans Petter Selasky enum ib_qp_type dest_qpt, u16 pkey_index, u32 remote_qpn, 8418cc48704SHans Petter Selasky u32 qkey, struct ib_ah_attr *attr, u8 *s_mac, 8428cc48704SHans Petter Selasky u16 vlan_id, struct ib_mad *mad); 8438cc48704SHans Petter Selasky 84497549c34SHans Petter Selasky __be64 mlx4_ib_get_new_demux_tid(struct mlx4_ib_demux_ctx *ctx); 84597549c34SHans Petter Selasky 84697549c34SHans Petter Selasky int mlx4_ib_demux_cm_handler(struct ib_device *ibdev, int port, int *slave, 8478cc48704SHans Petter Selasky struct ib_mad *mad); 84897549c34SHans Petter Selasky 84997549c34SHans Petter Selasky int mlx4_ib_multiplex_cm_handler(struct ib_device *ibdev, int port, int slave_id, 85097549c34SHans Petter Selasky struct ib_mad *mad); 85197549c34SHans Petter Selasky 85297549c34SHans Petter Selasky void mlx4_ib_cm_paravirt_init(struct mlx4_ib_dev *dev); 85397549c34SHans Petter Selasky void mlx4_ib_cm_paravirt_clean(struct mlx4_ib_dev *dev, int slave_id); 85497549c34SHans Petter Selasky 85597549c34SHans Petter Selasky /* alias guid support */ 85697549c34SHans Petter Selasky void mlx4_ib_init_alias_guid_work(struct mlx4_ib_dev *dev, int port); 85797549c34SHans Petter Selasky int mlx4_ib_init_alias_guid_service(struct mlx4_ib_dev *dev); 85897549c34SHans Petter Selasky void mlx4_ib_destroy_alias_guid_service(struct mlx4_ib_dev *dev); 85997549c34SHans Petter Selasky void mlx4_ib_invalidate_all_guid_record(struct mlx4_ib_dev *dev, int port); 86097549c34SHans Petter Selasky 86197549c34SHans Petter Selasky void mlx4_ib_notify_slaves_on_guid_change(struct mlx4_ib_dev *dev, 86297549c34SHans Petter Selasky int block_num, 86397549c34SHans Petter Selasky u8 port_num, u8 *p_data); 86497549c34SHans Petter Selasky 86597549c34SHans Petter Selasky void mlx4_ib_update_cache_on_guid_change(struct mlx4_ib_dev *dev, 86697549c34SHans Petter Selasky int block_num, u8 port_num, 86797549c34SHans Petter Selasky u8 *p_data); 86897549c34SHans Petter Selasky 86997549c34SHans Petter Selasky int add_sysfs_port_mcg_attr(struct mlx4_ib_dev *device, int port_num, 87097549c34SHans Petter Selasky struct attribute *attr); 87197549c34SHans Petter Selasky void del_sysfs_port_mcg_attr(struct mlx4_ib_dev *device, int port_num, 87297549c34SHans Petter Selasky struct attribute *attr); 87397549c34SHans Petter Selasky ib_sa_comp_mask mlx4_ib_get_aguid_comp_mask_from_ix(int index); 8748cc48704SHans Petter Selasky void mlx4_ib_slave_alias_guid_event(struct mlx4_ib_dev *dev, int slave, 8758cc48704SHans Petter Selasky int port, int slave_init); 87697549c34SHans Petter Selasky 87797549c34SHans Petter Selasky int mlx4_ib_device_register_sysfs(struct mlx4_ib_dev *device) ; 87897549c34SHans Petter Selasky 87997549c34SHans Petter Selasky void mlx4_ib_device_unregister_sysfs(struct mlx4_ib_dev *device); 88097549c34SHans Petter Selasky 88197549c34SHans Petter Selasky __be64 mlx4_ib_gen_node_guid(void); 88297549c34SHans Petter Selasky 88397549c34SHans Petter Selasky int mlx4_ib_steer_qp_alloc(struct mlx4_ib_dev *dev, int count, int *qpn); 88497549c34SHans Petter Selasky void mlx4_ib_steer_qp_free(struct mlx4_ib_dev *dev, u32 qpn, int count); 88597549c34SHans Petter Selasky int mlx4_ib_steer_qp_reg(struct mlx4_ib_dev *mdev, struct mlx4_ib_qp *mqp, 88697549c34SHans Petter Selasky int is_attach); 8878cc48704SHans Petter Selasky int mlx4_ib_rereg_user_mr(struct ib_mr *mr, int flags, 8888cc48704SHans Petter Selasky u64 start, u64 length, u64 virt_addr, 8898cc48704SHans Petter Selasky int mr_access_flags, struct ib_pd *pd, 8908cc48704SHans Petter Selasky struct ib_udata *udata); 8918cc48704SHans Petter Selasky int mlx4_ib_gid_index_to_real_index(struct mlx4_ib_dev *ibdev, 8928cc48704SHans Petter Selasky u8 port_num, int index); 8938cc48704SHans Petter Selasky 8948cc48704SHans Petter Selasky void mlx4_sched_ib_sl2vl_update_work(struct mlx4_ib_dev *ibdev, 8958cc48704SHans Petter Selasky int port); 8968cc48704SHans Petter Selasky 8978cc48704SHans Petter Selasky void mlx4_ib_sl2vl_update(struct mlx4_ib_dev *mdev, int port); 89897549c34SHans Petter Selasky 89997549c34SHans Petter Selasky #endif /* MLX4_IB_H */ 900