1fa790ea9SDavid C Somayajulu /*
2fa790ea9SDavid C Somayajulu * Copyright (c) 2018-2019 Cavium, Inc.
3fa790ea9SDavid C Somayajulu * All rights reserved.
4fa790ea9SDavid C Somayajulu *
5fa790ea9SDavid C Somayajulu * Redistribution and use in source and binary forms, with or without
6fa790ea9SDavid C Somayajulu * modification, are permitted provided that the following conditions
7fa790ea9SDavid C Somayajulu * are met:
8fa790ea9SDavid C Somayajulu *
9fa790ea9SDavid C Somayajulu * 1. Redistributions of source code must retain the above copyright
10fa790ea9SDavid C Somayajulu * notice, this list of conditions and the following disclaimer.
11fa790ea9SDavid C Somayajulu * 2. Redistributions in binary form must reproduce the above copyright
12fa790ea9SDavid C Somayajulu * notice, this list of conditions and the following disclaimer in the
13fa790ea9SDavid C Somayajulu * documentation and/or other materials provided with the distribution.
14fa790ea9SDavid C Somayajulu *
15fa790ea9SDavid C Somayajulu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16fa790ea9SDavid C Somayajulu * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17fa790ea9SDavid C Somayajulu * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18fa790ea9SDavid C Somayajulu * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19fa790ea9SDavid C Somayajulu * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20fa790ea9SDavid C Somayajulu * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21fa790ea9SDavid C Somayajulu * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22fa790ea9SDavid C Somayajulu * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23fa790ea9SDavid C Somayajulu * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24fa790ea9SDavid C Somayajulu * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25fa790ea9SDavid C Somayajulu * POSSIBILITY OF SUCH DAMAGE.
26fa790ea9SDavid C Somayajulu */
27fa790ea9SDavid C Somayajulu
28fa790ea9SDavid C Somayajulu /*
29fa790ea9SDavid C Somayajulu * File: qlnxr_def.h
30fa790ea9SDavid C Somayajulu * Author: David C Somayajulu
31fa790ea9SDavid C Somayajulu */
32fa790ea9SDavid C Somayajulu
33fa790ea9SDavid C Somayajulu #ifndef __QLNX_DEF_H_
34fa790ea9SDavid C Somayajulu #define __QLNX_DEF_H_
35fa790ea9SDavid C Somayajulu
36fa790ea9SDavid C Somayajulu #include <sys/ktr.h>
37fa790ea9SDavid C Somayajulu
38fa790ea9SDavid C Somayajulu #include <linux/list.h>
39fa790ea9SDavid C Somayajulu #include <linux/spinlock.h>
40fa790ea9SDavid C Somayajulu #include <linux/idr.h>
41fa790ea9SDavid C Somayajulu #include <linux/completion.h>
42fa790ea9SDavid C Somayajulu #include <linux/sched.h>
43fa790ea9SDavid C Somayajulu #include <linux/pci.h>
44fa790ea9SDavid C Somayajulu #include <linux/dma-mapping.h>
45fa790ea9SDavid C Somayajulu #include <linux/wait.h>
46fa790ea9SDavid C Somayajulu #include <linux/kref.h>
47fa790ea9SDavid C Somayajulu #include <linux/timer.h>
48fa790ea9SDavid C Somayajulu #include <linux/io.h>
49fa790ea9SDavid C Somayajulu #include <linux/fs.h>
50fa790ea9SDavid C Somayajulu #include <sys/vmem.h>
51fa790ea9SDavid C Somayajulu
52fa790ea9SDavid C Somayajulu #include <asm/byteorder.h>
53fa790ea9SDavid C Somayajulu
54fa790ea9SDavid C Somayajulu #include <netinet/in.h>
55fa790ea9SDavid C Somayajulu #include <net/ipv6.h>
56fa790ea9SDavid C Somayajulu #include <netinet/toecore.h>
57fa790ea9SDavid C Somayajulu
58fa790ea9SDavid C Somayajulu #include <rdma/ib_smi.h>
59fa790ea9SDavid C Somayajulu #include <rdma/ib_user_verbs.h>
60fa790ea9SDavid C Somayajulu #include <rdma/ib_addr.h>
61fa790ea9SDavid C Somayajulu #include <rdma/ib_verbs.h>
62fa790ea9SDavid C Somayajulu #include <rdma/iw_cm.h>
63fa790ea9SDavid C Somayajulu #include <rdma/ib_umem.h>
64fa790ea9SDavid C Somayajulu #include <rdma/ib_mad.h>
65fa790ea9SDavid C Somayajulu #include <rdma/ib_sa.h>
66*b633e08cSHans Petter Selasky #include <rdma/uverbs_ioctl.h>
67fa790ea9SDavid C Somayajulu
68fa790ea9SDavid C Somayajulu #include "qlnx_os.h"
69fa790ea9SDavid C Somayajulu #include "bcm_osal.h"
70fa790ea9SDavid C Somayajulu
71fa790ea9SDavid C Somayajulu #include "reg_addr.h"
72fa790ea9SDavid C Somayajulu #include "ecore_gtt_reg_addr.h"
73fa790ea9SDavid C Somayajulu #include "ecore.h"
74fa790ea9SDavid C Somayajulu #include "ecore_chain.h"
75fa790ea9SDavid C Somayajulu #include "ecore_status.h"
76fa790ea9SDavid C Somayajulu #include "ecore_hw.h"
77fa790ea9SDavid C Somayajulu #include "ecore_rt_defs.h"
78fa790ea9SDavid C Somayajulu #include "ecore_init_ops.h"
79fa790ea9SDavid C Somayajulu #include "ecore_int.h"
80fa790ea9SDavid C Somayajulu #include "ecore_cxt.h"
81fa790ea9SDavid C Somayajulu #include "ecore_spq.h"
82fa790ea9SDavid C Somayajulu #include "ecore_init_fw_funcs.h"
83fa790ea9SDavid C Somayajulu #include "ecore_sp_commands.h"
84fa790ea9SDavid C Somayajulu #include "ecore_dev_api.h"
85fa790ea9SDavid C Somayajulu #include "ecore_l2_api.h"
86fa790ea9SDavid C Somayajulu #ifdef CONFIG_ECORE_SRIOV
87fa790ea9SDavid C Somayajulu #include "ecore_sriov.h"
88fa790ea9SDavid C Somayajulu #include "ecore_vf.h"
89fa790ea9SDavid C Somayajulu #endif
90fa790ea9SDavid C Somayajulu #ifdef CONFIG_ECORE_LL2
91fa790ea9SDavid C Somayajulu #include "ecore_ll2.h"
92fa790ea9SDavid C Somayajulu #endif
93fa790ea9SDavid C Somayajulu #ifdef CONFIG_ECORE_FCOE
94fa790ea9SDavid C Somayajulu #include "ecore_fcoe.h"
95fa790ea9SDavid C Somayajulu #endif
96fa790ea9SDavid C Somayajulu #ifdef CONFIG_ECORE_ISCSI
97fa790ea9SDavid C Somayajulu #include "ecore_iscsi.h"
98fa790ea9SDavid C Somayajulu #endif
99fa790ea9SDavid C Somayajulu #include "ecore_mcp.h"
100fa790ea9SDavid C Somayajulu #include "ecore_hw_defs.h"
101fa790ea9SDavid C Somayajulu #include "mcp_public.h"
102fa790ea9SDavid C Somayajulu
103fa790ea9SDavid C Somayajulu #ifdef CONFIG_ECORE_RDMA
104fa790ea9SDavid C Somayajulu #include "ecore_rdma.h"
105fa790ea9SDavid C Somayajulu #include "ecore_rdma_api.h"
106fa790ea9SDavid C Somayajulu #endif
107fa790ea9SDavid C Somayajulu
108fa790ea9SDavid C Somayajulu #ifdef CONFIG_ECORE_ROCE
109fa790ea9SDavid C Somayajulu #include "ecore_roce.h"
110fa790ea9SDavid C Somayajulu #endif
111fa790ea9SDavid C Somayajulu
112fa790ea9SDavid C Somayajulu #ifdef CONFIG_ECORE_IWARP
113fa790ea9SDavid C Somayajulu #include "ecore_iwarp.h"
114fa790ea9SDavid C Somayajulu #endif
115fa790ea9SDavid C Somayajulu
116fa790ea9SDavid C Somayajulu #include "ecore_iro.h"
117fa790ea9SDavid C Somayajulu #include "nvm_cfg.h"
118fa790ea9SDavid C Somayajulu
119fa790ea9SDavid C Somayajulu #include "ecore_dbg_fw_funcs.h"
120fa790ea9SDavid C Somayajulu #include "rdma_common.h"
121fa790ea9SDavid C Somayajulu
122fa790ea9SDavid C Somayajulu #include "qlnx_ioctl.h"
123fa790ea9SDavid C Somayajulu #include "qlnx_def.h"
124fa790ea9SDavid C Somayajulu #include "qlnx_rdma.h"
125fa790ea9SDavid C Somayajulu #include "qlnxr_verbs.h"
126fa790ea9SDavid C Somayajulu #include "qlnxr_user.h"
127fa790ea9SDavid C Somayajulu #include "qlnx_ver.h"
128fa790ea9SDavid C Somayajulu #include <sys/smp.h>
129fa790ea9SDavid C Somayajulu
130fa790ea9SDavid C Somayajulu #define QLNXR_ROCE_INTERFACE_VERSION 1801
131fa790ea9SDavid C Somayajulu
132fa790ea9SDavid C Somayajulu #define QLNXR_MODULE_VERSION "8.18.1.0"
133fa790ea9SDavid C Somayajulu #define QLNXR_NODE_DESC "QLogic 579xx RoCE HCA"
134fa790ea9SDavid C Somayajulu
135fa790ea9SDavid C Somayajulu #define OC_SKH_DEVICE_PF 0x720
136fa790ea9SDavid C Somayajulu #define OC_SKH_DEVICE_VF 0x728
137fa790ea9SDavid C Somayajulu #define QLNXR_MAX_AH 512
138fa790ea9SDavid C Somayajulu
139fa790ea9SDavid C Somayajulu /* QLNXR Limitations */
140fa790ea9SDavid C Somayajulu
141fa790ea9SDavid C Somayajulu /* SQ/RQ Limitations
142fa790ea9SDavid C Somayajulu * An S/RQ PBL contains a list a pointers to pages. Each page contains S/RQE
143fa790ea9SDavid C Somayajulu * elements. Several S/RQE elements make an S/RQE, up to a certain maximum that
144fa790ea9SDavid C Somayajulu * is different between SQ and RQ. The size of the PBL was chosen such as not to
145fa790ea9SDavid C Somayajulu * limit the MAX_WR supported by ECORE, and rounded up to a power of two.
146fa790ea9SDavid C Somayajulu */
147fa790ea9SDavid C Somayajulu /* SQ */
148fa790ea9SDavid C Somayajulu #define QLNXR_MAX_SQ_PBL (0x8000) /* 2^15 bytes */
149fa790ea9SDavid C Somayajulu #define QLNXR_MAX_SQ_PBL_ENTRIES (0x10000 / sizeof(void *)) /* number */
150fa790ea9SDavid C Somayajulu #define QLNXR_SQE_ELEMENT_SIZE (sizeof(struct rdma_sq_sge)) /* bytes */
151fa790ea9SDavid C Somayajulu #define QLNXR_MAX_SQE_ELEMENTS_PER_SQE (ROCE_REQ_MAX_SINGLE_SQ_WQE_SIZE / \
152fa790ea9SDavid C Somayajulu QLNXR_SQE_ELEMENT_SIZE) /* number */
153fa790ea9SDavid C Somayajulu #define QLNXR_MAX_SQE_ELEMENTS_PER_PAGE ((RDMA_RING_PAGE_SIZE) / \
154fa790ea9SDavid C Somayajulu QLNXR_SQE_ELEMENT_SIZE) /* number */
155fa790ea9SDavid C Somayajulu #define QLNXR_MAX_SQE ((QLNXR_MAX_SQ_PBL_ENTRIES) * (RDMA_RING_PAGE_SIZE) / \
156fa790ea9SDavid C Somayajulu (QLNXR_SQE_ELEMENT_SIZE) / (QLNXR_MAX_SQE_ELEMENTS_PER_SQE))
157fa790ea9SDavid C Somayajulu /* RQ */
158fa790ea9SDavid C Somayajulu #define QLNXR_MAX_RQ_PBL (0x2000) /* 2^13 bytes */
159fa790ea9SDavid C Somayajulu #define QLNXR_MAX_RQ_PBL_ENTRIES (0x10000 / sizeof(void *)) /* number */
160fa790ea9SDavid C Somayajulu #define QLNXR_RQE_ELEMENT_SIZE (sizeof(struct rdma_rq_sge)) /* bytes */
161fa790ea9SDavid C Somayajulu #define QLNXR_MAX_RQE_ELEMENTS_PER_RQE (RDMA_MAX_SGE_PER_RQ_WQE) /* number */
162fa790ea9SDavid C Somayajulu #define QLNXR_MAX_RQE_ELEMENTS_PER_PAGE ((RDMA_RING_PAGE_SIZE) / \
163fa790ea9SDavid C Somayajulu QLNXR_RQE_ELEMENT_SIZE) /* number */
164fa790ea9SDavid C Somayajulu #define QLNXR_MAX_RQE ((QLNXR_MAX_RQ_PBL_ENTRIES) * (RDMA_RING_PAGE_SIZE) / \
165fa790ea9SDavid C Somayajulu (QLNXR_RQE_ELEMENT_SIZE) / (QLNXR_MAX_RQE_ELEMENTS_PER_RQE))
166fa790ea9SDavid C Somayajulu
167fa790ea9SDavid C Somayajulu /* CQE Limitation
168fa790ea9SDavid C Somayajulu * Although FW supports two layer PBL we use single layer since it is more
169fa790ea9SDavid C Somayajulu * than enough. For that layer we use a maximum size of 512 kB, again, because
170fa790ea9SDavid C Somayajulu * it reaches the maximum number of page pointers. Notice is the '-1' in the
171fa790ea9SDavid C Somayajulu * calculation that comes from having a u16 for the number of pages i.e. 0xffff
172fa790ea9SDavid C Somayajulu * is the maximum number of pages (in single layer).
173fa790ea9SDavid C Somayajulu */
174fa790ea9SDavid C Somayajulu #define QLNXR_CQE_SIZE (sizeof(union rdma_cqe))
175fa790ea9SDavid C Somayajulu #define QLNXR_MAX_CQE_PBL_SIZE (512*1024) /* 512kB */
176fa790ea9SDavid C Somayajulu #define QLNXR_MAX_CQE_PBL_ENTRIES (((QLNXR_MAX_CQE_PBL_SIZE) / \
177fa790ea9SDavid C Somayajulu sizeof(u64)) - 1) /* 64k -1 */
178fa790ea9SDavid C Somayajulu #define QLNXR_MAX_CQES ((u32)((QLNXR_MAX_CQE_PBL_ENTRIES) * (ECORE_CHAIN_PAGE_SIZE)\
179fa790ea9SDavid C Somayajulu / QLNXR_CQE_SIZE)) /* 8M -4096/32 = 8,388,480 */
180fa790ea9SDavid C Somayajulu
181fa790ea9SDavid C Somayajulu /* CNQ size Limitation
182fa790ea9SDavid C Somayajulu * The maximum CNQ size is not reachable because the FW supports a chain of u16
183fa790ea9SDavid C Somayajulu * (specifically 64k-1). The FW can buffer CNQ elements avoiding an overflow, on
184fa790ea9SDavid C Somayajulu * the expense of performance. Hence we set it to an arbitrarily smaller value
185fa790ea9SDavid C Somayajulu * than the maximum.
186fa790ea9SDavid C Somayajulu */
187fa790ea9SDavid C Somayajulu #define QLNXR_ROCE_MAX_CNQ_SIZE (0x4000) /* 2^16 */
188fa790ea9SDavid C Somayajulu
189fa790ea9SDavid C Somayajulu #define QLNXR_MAX_PORT (1)
190fa790ea9SDavid C Somayajulu #define QLNXR_PORT (1)
191fa790ea9SDavid C Somayajulu
192fa790ea9SDavid C Somayajulu #define QLNXR_UVERBS(CMD_NAME) (1ull << IB_USER_VERBS_CMD_##CMD_NAME)
193fa790ea9SDavid C Somayajulu
194fa790ea9SDavid C Somayajulu #define convert_to_64bit(lo, hi) ((u64)hi << 32 | (u64)lo)
195fa790ea9SDavid C Somayajulu
196fa790ea9SDavid C Somayajulu /* The following number is used to determine if a handle recevied from the FW
197fa790ea9SDavid C Somayajulu * actually point to a CQ/QP.
198fa790ea9SDavid C Somayajulu */
199fa790ea9SDavid C Somayajulu #define QLNXR_CQ_MAGIC_NUMBER (0x11223344)
200fa790ea9SDavid C Somayajulu #define QLNXR_QP_MAGIC_NUMBER (0x77889900)
201fa790ea9SDavid C Somayajulu
202fa790ea9SDavid C Somayajulu /* Fast path debug prints */
203fa790ea9SDavid C Somayajulu #define FP_DP_VERBOSE(...)
204fa790ea9SDavid C Somayajulu /* #define FP_DP_VERBOSE(...) DP_VERBOSE(__VA_ARGS__) */
205fa790ea9SDavid C Somayajulu
206fa790ea9SDavid C Somayajulu #define FW_PAGE_SIZE (RDMA_RING_PAGE_SIZE)
207fa790ea9SDavid C Somayajulu
208fa790ea9SDavid C Somayajulu #define QLNXR_MSG_INIT 0x10000,
209fa790ea9SDavid C Somayajulu #define QLNXR_MSG_FAIL 0x10000,
210fa790ea9SDavid C Somayajulu #define QLNXR_MSG_CQ 0x20000,
211fa790ea9SDavid C Somayajulu #define QLNXR_MSG_RQ 0x40000,
212fa790ea9SDavid C Somayajulu #define QLNXR_MSG_SQ 0x80000,
213fa790ea9SDavid C Somayajulu #define QLNXR_MSG_QP (QLNXR_MSG_SQ | QLNXR_MSG_RQ),
214fa790ea9SDavid C Somayajulu #define QLNXR_MSG_MR 0x100000,
215fa790ea9SDavid C Somayajulu #define QLNXR_MSG_GSI 0x200000,
216fa790ea9SDavid C Somayajulu #define QLNXR_MSG_MISC 0x400000,
217fa790ea9SDavid C Somayajulu #define QLNXR_MSG_SRQ 0x800000,
218fa790ea9SDavid C Somayajulu #define QLNXR_MSG_IWARP 0x1000000,
219fa790ea9SDavid C Somayajulu
220fa790ea9SDavid C Somayajulu #define QLNXR_ROCE_PKEY_MAX 1
221fa790ea9SDavid C Somayajulu #define QLNXR_ROCE_PKEY_TABLE_LEN 1
222fa790ea9SDavid C Somayajulu #define QLNXR_ROCE_PKEY_DEFAULT 0xffff
223fa790ea9SDavid C Somayajulu
224fa790ea9SDavid C Somayajulu #define QLNXR_MAX_SGID 128 /* TBD - add more source gids... */
225fa790ea9SDavid C Somayajulu
226fa790ea9SDavid C Somayajulu #define QLNXR_ENET_STATE_BIT (0)
227fa790ea9SDavid C Somayajulu
228fa790ea9SDavid C Somayajulu #define QLNXR_MAX_MSIX (16)
229fa790ea9SDavid C Somayajulu
230fa790ea9SDavid C Somayajulu struct qlnxr_cnq {
231fa790ea9SDavid C Somayajulu struct qlnxr_dev *dev;
232fa790ea9SDavid C Somayajulu struct ecore_chain pbl;
233fa790ea9SDavid C Somayajulu struct ecore_sb_info *sb;
234fa790ea9SDavid C Somayajulu char name[32];
235fa790ea9SDavid C Somayajulu u64 n_comp;
236fa790ea9SDavid C Somayajulu __le16 *hw_cons_ptr;
237fa790ea9SDavid C Somayajulu u8 index;
238fa790ea9SDavid C Somayajulu int irq_rid;
239fa790ea9SDavid C Somayajulu struct resource *irq;
240fa790ea9SDavid C Somayajulu void *irq_handle;
241fa790ea9SDavid C Somayajulu };
242fa790ea9SDavid C Somayajulu
243fa790ea9SDavid C Somayajulu struct qlnxr_device_attr {
244fa790ea9SDavid C Somayajulu /* Vendor specific information */
245fa790ea9SDavid C Somayajulu u32 vendor_id;
246fa790ea9SDavid C Somayajulu u32 vendor_part_id;
247fa790ea9SDavid C Somayajulu u32 hw_ver;
248fa790ea9SDavid C Somayajulu u64 fw_ver;
249fa790ea9SDavid C Somayajulu
250fa790ea9SDavid C Somayajulu u64 node_guid; /* node GUID */
251fa790ea9SDavid C Somayajulu u64 sys_image_guid; /* System image GUID */
252fa790ea9SDavid C Somayajulu
253fa790ea9SDavid C Somayajulu u8 max_cnq;
254fa790ea9SDavid C Somayajulu u8 max_sge; /* Maximum # of scatter/gather entries
255fa790ea9SDavid C Somayajulu * per Work Request supported
256fa790ea9SDavid C Somayajulu */
257fa790ea9SDavid C Somayajulu u16 max_inline;
258fa790ea9SDavid C Somayajulu u32 max_sqe; /* Maximum number of send outstanding send work
259fa790ea9SDavid C Somayajulu * requests on any Work Queue supported
260fa790ea9SDavid C Somayajulu */
261fa790ea9SDavid C Somayajulu u32 max_rqe; /* Maximum number of receive outstanding receive
262fa790ea9SDavid C Somayajulu * work requests on any Work Queue supported
263fa790ea9SDavid C Somayajulu */
264fa790ea9SDavid C Somayajulu u8 max_qp_resp_rd_atomic_resc; /* Maximum number of RDMA Reads
265fa790ea9SDavid C Somayajulu * & atomic operation that can
266fa790ea9SDavid C Somayajulu * be outstanding per QP
267fa790ea9SDavid C Somayajulu */
268fa790ea9SDavid C Somayajulu
269fa790ea9SDavid C Somayajulu u8 max_qp_req_rd_atomic_resc; /* The maximum depth per QP for
270fa790ea9SDavid C Somayajulu * initiation of RDMA Read
271fa790ea9SDavid C Somayajulu * & atomic operations
272fa790ea9SDavid C Somayajulu */
273fa790ea9SDavid C Somayajulu u64 max_dev_resp_rd_atomic_resc;
274fa790ea9SDavid C Somayajulu u32 max_cq;
275fa790ea9SDavid C Somayajulu u32 max_qp;
276fa790ea9SDavid C Somayajulu u32 max_mr; /* Maximum # of MRs supported */
277fa790ea9SDavid C Somayajulu u64 max_mr_size; /* Size (in bytes) of largest contiguous memory
278fa790ea9SDavid C Somayajulu * block that can be registered by this device
279fa790ea9SDavid C Somayajulu */
280fa790ea9SDavid C Somayajulu u32 max_cqe;
281fa790ea9SDavid C Somayajulu u32 max_mw; /* Maximum # of memory windows supported */
282fa790ea9SDavid C Somayajulu u32 max_fmr;
283fa790ea9SDavid C Somayajulu u32 max_mr_mw_fmr_pbl;
284fa790ea9SDavid C Somayajulu u64 max_mr_mw_fmr_size;
285fa790ea9SDavid C Somayajulu u32 max_pd; /* Maximum # of protection domains supported */
286fa790ea9SDavid C Somayajulu u32 max_ah;
287fa790ea9SDavid C Somayajulu u8 max_pkey;
288fa790ea9SDavid C Somayajulu u32 max_srq; /* Maximum number of SRQs */
289fa790ea9SDavid C Somayajulu u32 max_srq_wr; /* Maximum number of WRs per SRQ */
290fa790ea9SDavid C Somayajulu u8 max_srq_sge; /* Maximum number of SGE per WQE */
291fa790ea9SDavid C Somayajulu u8 max_stats_queues; /* Maximum number of statistics queues */
292fa790ea9SDavid C Somayajulu u32 dev_caps;
293fa790ea9SDavid C Somayajulu
294fa790ea9SDavid C Somayajulu /* Abilty to support RNR-NAK generation */
295fa790ea9SDavid C Somayajulu
296fa790ea9SDavid C Somayajulu #define QLNXR_ROCE_DEV_CAP_RNR_NAK_MASK 0x1
297fa790ea9SDavid C Somayajulu #define QLNXR_ROCE_DEV_CAP_RNR_NAK_SHIFT 0
298fa790ea9SDavid C Somayajulu /* Abilty to support shutdown port */
299fa790ea9SDavid C Somayajulu #define QLNXR_ROCE_DEV_CAP_SHUTDOWN_PORT_MASK 0x1
300fa790ea9SDavid C Somayajulu #define QLNXR_ROCE_DEV_CAP_SHUTDOWN_PORT_SHIFT 1
301fa790ea9SDavid C Somayajulu /* Abilty to support port active event */
302fa790ea9SDavid C Somayajulu #define QLNXR_ROCE_DEV_CAP_PORT_ACTIVE_EVENT_MASK 0x1
303fa790ea9SDavid C Somayajulu #define QLNXR_ROCE_DEV_CAP_PORT_ACTIVE_EVENT_SHIFT 2
304fa790ea9SDavid C Somayajulu /* Abilty to support port change event */
305fa790ea9SDavid C Somayajulu #define QLNXR_ROCE_DEV_CAP_PORT_CHANGE_EVENT_MASK 0x1
306fa790ea9SDavid C Somayajulu #define QLNXR_ROCE_DEV_CAP_PORT_CHANGE_EVENT_SHIFT 3
307fa790ea9SDavid C Somayajulu /* Abilty to support system image GUID */
308fa790ea9SDavid C Somayajulu #define QLNXR_ROCE_DEV_CAP_SYS_IMAGE_MASK 0x1
309fa790ea9SDavid C Somayajulu #define QLNXR_ROCE_DEV_CAP_SYS_IMAGE_SHIFT 4
310fa790ea9SDavid C Somayajulu /* Abilty to support bad P_Key counter support */
311fa790ea9SDavid C Somayajulu #define QLNXR_ROCE_DEV_CAP_BAD_PKEY_CNT_MASK 0x1
312fa790ea9SDavid C Somayajulu #define QLNXR_ROCE_DEV_CAP_BAD_PKEY_CNT_SHIFT 5
313fa790ea9SDavid C Somayajulu /* Abilty to support atomic operations */
314fa790ea9SDavid C Somayajulu #define QLNXR_ROCE_DEV_CAP_ATOMIC_OP_MASK 0x1
315fa790ea9SDavid C Somayajulu #define QLNXR_ROCE_DEV_CAP_ATOMIC_OP_SHIFT 6
316fa790ea9SDavid C Somayajulu #define QLNXR_ROCE_DEV_CAP_RESIZE_CQ_MASK 0x1
317fa790ea9SDavid C Somayajulu #define QLNXR_ROCE_DEV_CAP_RESIZE_CQ_SHIFT 7
318fa790ea9SDavid C Somayajulu /* Abilty to support modifying the maximum number of
319fa790ea9SDavid C Somayajulu * outstanding work requests per QP
320fa790ea9SDavid C Somayajulu */
321fa790ea9SDavid C Somayajulu #define QLNXR_ROCE_DEV_CAP_RESIZE_MAX_WR_MASK 0x1
322fa790ea9SDavid C Somayajulu #define QLNXR_ROCE_DEV_CAP_RESIZE_MAX_WR_SHIFT 8
323fa790ea9SDavid C Somayajulu
324fa790ea9SDavid C Somayajulu /* Abilty to support automatic path migration */
325fa790ea9SDavid C Somayajulu #define QLNXR_ROCE_DEV_CAP_AUTO_PATH_MIG_MASK 0x1
326fa790ea9SDavid C Somayajulu #define QLNXR_ROCE_DEV_CAP_AUTO_PATH_MIG_SHIFT 9
327fa790ea9SDavid C Somayajulu /* Abilty to support the base memory management extensions */
328fa790ea9SDavid C Somayajulu #define QLNXR_ROCE_DEV_CAP_BASE_MEMORY_EXT_MASK 0x1
329fa790ea9SDavid C Somayajulu #define QLNXR_ROCE_DEV_CAP_BASE_MEMORY_EXT_SHIFT 10
330fa790ea9SDavid C Somayajulu #define QLNXR_ROCE_DEV_CAP_BASE_QUEUE_EXT_MASK 0x1
331fa790ea9SDavid C Somayajulu #define QLNXR_ROCE_DEV_CAP_BASE_QUEUE_EXT_SHIFT 11
332fa790ea9SDavid C Somayajulu /* Abilty to support multipile page sizes per memory region */
333fa790ea9SDavid C Somayajulu #define QLNXR_ROCE_DEV_CAP_MULTI_PAGE_PER_MR_EXT_MASK 0x1
334fa790ea9SDavid C Somayajulu #define QLNXR_ROCE_DEV_CAP_MULTI_PAGE_PER_MR_EXT_SHIFT 12
335fa790ea9SDavid C Somayajulu /* Abilty to support block list physical buffer list */
336fa790ea9SDavid C Somayajulu #define QLNXR_ROCE_DEV_CAP_BLOCK_MODE_MASK 0x1
337fa790ea9SDavid C Somayajulu #define QLNXR_ROCE_DEV_CAP_BLOCK_MODE_SHIFT 13
338fa790ea9SDavid C Somayajulu /* Abilty to support zero based virtual addresses */
339fa790ea9SDavid C Somayajulu #define QLNXR_ROCE_DEV_CAP_ZBVA_MASK 0x1
340fa790ea9SDavid C Somayajulu #define QLNXR_ROCE_DEV_CAP_ZBVA_SHIFT 14
341fa790ea9SDavid C Somayajulu /* Abilty to support local invalidate fencing */
342fa790ea9SDavid C Somayajulu #define QLNXR_ROCE_DEV_CAP_LOCAL_INV_FENCE_MASK 0x1
343fa790ea9SDavid C Somayajulu #define QLNXR_ROCE_DEV_CAP_LOCAL_INV_FENCE_SHIFT 15
344fa790ea9SDavid C Somayajulu /* Abilty to support Loopback on QP */
345fa790ea9SDavid C Somayajulu #define QLNXR_ROCE_DEV_CAP_LB_INDICATOR_MASK 0x1
346fa790ea9SDavid C Somayajulu #define QLNXR_ROCE_DEV_CAP_LB_INDICATOR_SHIFT 16
347fa790ea9SDavid C Somayajulu u64 page_size_caps;
348fa790ea9SDavid C Somayajulu u8 dev_ack_delay;
349fa790ea9SDavid C Somayajulu u32 reserved_lkey; /* Value of reserved L_key */
350fa790ea9SDavid C Somayajulu u32 bad_pkey_counter;/* Bad P_key counter support
351fa790ea9SDavid C Somayajulu * indicator
352fa790ea9SDavid C Somayajulu */
353fa790ea9SDavid C Somayajulu struct ecore_rdma_events events;
354fa790ea9SDavid C Somayajulu };
355fa790ea9SDavid C Somayajulu
356fa790ea9SDavid C Somayajulu struct qlnxr_dev {
357fa790ea9SDavid C Somayajulu struct ib_device ibdev;
358fa790ea9SDavid C Somayajulu qlnx_host_t *ha;
359fa790ea9SDavid C Somayajulu struct ecore_dev *cdev;
360fa790ea9SDavid C Somayajulu
361fa790ea9SDavid C Somayajulu /* Added to extend Applications Support */
36256cbd386SMark Johnston struct pci_dev pdev;
363fa790ea9SDavid C Somayajulu uint32_t dp_module;
364fa790ea9SDavid C Somayajulu uint8_t dp_level;
365fa790ea9SDavid C Somayajulu
366fa790ea9SDavid C Somayajulu void *rdma_ctx;
367fa790ea9SDavid C Somayajulu
368fa790ea9SDavid C Somayajulu struct mtx idr_lock;
369fa790ea9SDavid C Somayajulu struct idr qpidr;
370fa790ea9SDavid C Somayajulu
371fa790ea9SDavid C Somayajulu uint32_t wq_multiplier;
372fa790ea9SDavid C Somayajulu int num_cnq;
373fa790ea9SDavid C Somayajulu
374fa790ea9SDavid C Somayajulu struct ecore_sb_info sb_array[QLNXR_MAX_MSIX];
375fa790ea9SDavid C Somayajulu struct qlnxr_cnq cnq_array[QLNXR_MAX_MSIX];
376fa790ea9SDavid C Somayajulu
377fa790ea9SDavid C Somayajulu int sb_start;
378fa790ea9SDavid C Somayajulu
379fa790ea9SDavid C Somayajulu int gsi_qp_created;
380fa790ea9SDavid C Somayajulu struct qlnxr_cq *gsi_sqcq;
381fa790ea9SDavid C Somayajulu struct qlnxr_cq *gsi_rqcq;
382fa790ea9SDavid C Somayajulu struct qlnxr_qp *gsi_qp;
383fa790ea9SDavid C Somayajulu
384fa790ea9SDavid C Somayajulu /* TBD: we'll need an array of these probablly per DPI... */
385fa790ea9SDavid C Somayajulu void __iomem *db_addr;
386fa790ea9SDavid C Somayajulu uint64_t db_phys_addr;
387fa790ea9SDavid C Somayajulu uint32_t db_size;
388fa790ea9SDavid C Somayajulu uint16_t dpi;
389fa790ea9SDavid C Somayajulu
390fa790ea9SDavid C Somayajulu uint64_t guid;
391fa790ea9SDavid C Somayajulu enum ib_atomic_cap atomic_cap;
392fa790ea9SDavid C Somayajulu
393fa790ea9SDavid C Somayajulu union ib_gid sgid_tbl[QLNXR_MAX_SGID];
394fa790ea9SDavid C Somayajulu struct mtx sgid_lock;
395fa790ea9SDavid C Somayajulu struct notifier_block nb_inet;
396fa790ea9SDavid C Somayajulu struct notifier_block nb_inet6;
397fa790ea9SDavid C Somayajulu
398fa790ea9SDavid C Somayajulu uint8_t mr_key;
399fa790ea9SDavid C Somayajulu struct list_head entry;
400fa790ea9SDavid C Somayajulu
401fa790ea9SDavid C Somayajulu struct dentry *dbgfs;
402fa790ea9SDavid C Somayajulu
403fa790ea9SDavid C Somayajulu uint8_t gsi_ll2_mac_address[ETH_ALEN];
404fa790ea9SDavid C Somayajulu uint8_t gsi_ll2_handle;
405fa790ea9SDavid C Somayajulu
406fa790ea9SDavid C Somayajulu unsigned long enet_state;
407fa790ea9SDavid C Somayajulu
408fa790ea9SDavid C Somayajulu struct workqueue_struct *iwarp_wq;
409fa790ea9SDavid C Somayajulu
410fa790ea9SDavid C Somayajulu volatile uint32_t pd_count;
411fa790ea9SDavid C Somayajulu struct qlnxr_device_attr attr;
412fa790ea9SDavid C Somayajulu uint8_t user_dpm_enabled;
413fa790ea9SDavid C Somayajulu };
414fa790ea9SDavid C Somayajulu
415fa790ea9SDavid C Somayajulu typedef struct qlnxr_dev qlnxr_dev_t;
416fa790ea9SDavid C Somayajulu
417fa790ea9SDavid C Somayajulu struct qlnxr_pd {
418fa790ea9SDavid C Somayajulu struct ib_pd ibpd;
419fa790ea9SDavid C Somayajulu u32 pd_id;
420fa790ea9SDavid C Somayajulu struct qlnxr_ucontext *uctx;
421fa790ea9SDavid C Somayajulu };
422fa790ea9SDavid C Somayajulu
423fa790ea9SDavid C Somayajulu struct qlnxr_ucontext {
424fa790ea9SDavid C Somayajulu struct ib_ucontext ibucontext;
425fa790ea9SDavid C Somayajulu struct qlnxr_dev *dev;
426fa790ea9SDavid C Somayajulu struct qlnxr_pd *pd;
427fa790ea9SDavid C Somayajulu u64 dpi_addr;
428fa790ea9SDavid C Somayajulu u64 dpi_phys_addr;
429fa790ea9SDavid C Somayajulu u32 dpi_size;
430fa790ea9SDavid C Somayajulu u16 dpi;
431fa790ea9SDavid C Somayajulu
432fa790ea9SDavid C Somayajulu struct list_head mm_head;
433fa790ea9SDavid C Somayajulu struct mutex mm_list_lock;
434fa790ea9SDavid C Somayajulu };
435fa790ea9SDavid C Somayajulu
436fa790ea9SDavid C Somayajulu struct qlnxr_dev_attr {
437fa790ea9SDavid C Somayajulu struct ib_device_attr ib_attr;
438fa790ea9SDavid C Somayajulu };
439fa790ea9SDavid C Somayajulu
440fa790ea9SDavid C Somayajulu struct qlnxr_dma_mem {
441fa790ea9SDavid C Somayajulu void *va;
442fa790ea9SDavid C Somayajulu dma_addr_t pa;
443fa790ea9SDavid C Somayajulu u32 size;
444fa790ea9SDavid C Somayajulu };
445fa790ea9SDavid C Somayajulu
446fa790ea9SDavid C Somayajulu struct qlnxr_pbl {
447fa790ea9SDavid C Somayajulu struct list_head list_entry;
448fa790ea9SDavid C Somayajulu void *va;
449fa790ea9SDavid C Somayajulu dma_addr_t pa;
450fa790ea9SDavid C Somayajulu };
451fa790ea9SDavid C Somayajulu
452fa790ea9SDavid C Somayajulu struct qlnxr_queue_info {
453fa790ea9SDavid C Somayajulu void *va;
454fa790ea9SDavid C Somayajulu dma_addr_t dma;
455fa790ea9SDavid C Somayajulu u32 size;
456fa790ea9SDavid C Somayajulu u16 len;
457fa790ea9SDavid C Somayajulu u16 entry_size; /* Size of an element in the queue */
458fa790ea9SDavid C Somayajulu u16 id; /* qid, where to ring the doorbell. */
459fa790ea9SDavid C Somayajulu u16 head, tail;
460fa790ea9SDavid C Somayajulu bool created;
461fa790ea9SDavid C Somayajulu };
462fa790ea9SDavid C Somayajulu
463fa790ea9SDavid C Somayajulu struct qlnxr_eq {
464fa790ea9SDavid C Somayajulu struct qlnxr_queue_info q;
465fa790ea9SDavid C Somayajulu u32 vector;
466fa790ea9SDavid C Somayajulu int cq_cnt;
467fa790ea9SDavid C Somayajulu struct qlnxr_dev *dev;
468fa790ea9SDavid C Somayajulu char irq_name[32];
469fa790ea9SDavid C Somayajulu };
470fa790ea9SDavid C Somayajulu
471fa790ea9SDavid C Somayajulu struct qlnxr_mq {
472fa790ea9SDavid C Somayajulu struct qlnxr_queue_info sq;
473fa790ea9SDavid C Somayajulu struct qlnxr_queue_info cq;
474fa790ea9SDavid C Somayajulu bool rearm_cq;
475fa790ea9SDavid C Somayajulu };
476fa790ea9SDavid C Somayajulu
477fa790ea9SDavid C Somayajulu struct phy_info {
478fa790ea9SDavid C Somayajulu u16 auto_speeds_supported;
479fa790ea9SDavid C Somayajulu u16 fixed_speeds_supported;
480fa790ea9SDavid C Somayajulu u16 phy_type;
481fa790ea9SDavid C Somayajulu u16 interface_type;
482fa790ea9SDavid C Somayajulu };
483fa790ea9SDavid C Somayajulu
484fa790ea9SDavid C Somayajulu union db_prod64 {
485fa790ea9SDavid C Somayajulu struct rdma_pwm_val32_data data;
486fa790ea9SDavid C Somayajulu u64 raw;
487fa790ea9SDavid C Somayajulu };
488fa790ea9SDavid C Somayajulu
489fa790ea9SDavid C Somayajulu enum qlnxr_cq_type {
490fa790ea9SDavid C Somayajulu QLNXR_CQ_TYPE_GSI,
491fa790ea9SDavid C Somayajulu QLNXR_CQ_TYPE_KERNEL,
492fa790ea9SDavid C Somayajulu QLNXR_CQ_TYPE_USER
493fa790ea9SDavid C Somayajulu };
494fa790ea9SDavid C Somayajulu
495fa790ea9SDavid C Somayajulu struct qlnxr_pbl_info {
496fa790ea9SDavid C Somayajulu u32 num_pbls;
497fa790ea9SDavid C Somayajulu u32 num_pbes;
498fa790ea9SDavid C Somayajulu u32 pbl_size;
499fa790ea9SDavid C Somayajulu u32 pbe_size;
500fa790ea9SDavid C Somayajulu bool two_layered;
501fa790ea9SDavid C Somayajulu };
502fa790ea9SDavid C Somayajulu
503fa790ea9SDavid C Somayajulu struct qlnxr_userq {
504fa790ea9SDavid C Somayajulu struct ib_umem *umem;
505fa790ea9SDavid C Somayajulu struct qlnxr_pbl_info pbl_info;
506fa790ea9SDavid C Somayajulu struct qlnxr_pbl *pbl_tbl;
507fa790ea9SDavid C Somayajulu u64 buf_addr;
508fa790ea9SDavid C Somayajulu size_t buf_len;
509fa790ea9SDavid C Somayajulu };
510fa790ea9SDavid C Somayajulu
511fa790ea9SDavid C Somayajulu struct qlnxr_cq {
512fa790ea9SDavid C Somayajulu struct ib_cq ibcq; /* must be first */
513fa790ea9SDavid C Somayajulu
514fa790ea9SDavid C Somayajulu enum qlnxr_cq_type cq_type;
515fa790ea9SDavid C Somayajulu uint32_t sig;
516fa790ea9SDavid C Somayajulu uint16_t icid;
517fa790ea9SDavid C Somayajulu
518fa790ea9SDavid C Somayajulu /* relevant to cqs created from kernel space only (ULPs) */
519fa790ea9SDavid C Somayajulu spinlock_t cq_lock;
520fa790ea9SDavid C Somayajulu uint8_t arm_flags;
521fa790ea9SDavid C Somayajulu struct ecore_chain pbl;
522fa790ea9SDavid C Somayajulu
523fa790ea9SDavid C Somayajulu void __iomem *db_addr; /* db address for cons update*/
524fa790ea9SDavid C Somayajulu union db_prod64 db;
525fa790ea9SDavid C Somayajulu
526fa790ea9SDavid C Somayajulu uint8_t pbl_toggle;
527fa790ea9SDavid C Somayajulu union rdma_cqe *latest_cqe;
528fa790ea9SDavid C Somayajulu union rdma_cqe *toggle_cqe;
529fa790ea9SDavid C Somayajulu
530fa790ea9SDavid C Somayajulu /* TODO: remove since it is redundant with 32 bit chains */
531fa790ea9SDavid C Somayajulu uint32_t cq_cons;
532fa790ea9SDavid C Somayajulu
533fa790ea9SDavid C Somayajulu /* relevant to cqs created from user space only (applications) */
534fa790ea9SDavid C Somayajulu struct qlnxr_userq q;
535fa790ea9SDavid C Somayajulu
536fa790ea9SDavid C Somayajulu /* destroy-IRQ handler race prevention */
537fa790ea9SDavid C Somayajulu uint8_t destroyed;
538fa790ea9SDavid C Somayajulu uint16_t cnq_notif;
539fa790ea9SDavid C Somayajulu };
540fa790ea9SDavid C Somayajulu
541fa790ea9SDavid C Somayajulu struct qlnxr_ah {
542fa790ea9SDavid C Somayajulu struct ib_ah ibah;
543fa790ea9SDavid C Somayajulu struct ib_ah_attr attr;
544fa790ea9SDavid C Somayajulu };
545fa790ea9SDavid C Somayajulu
546fa790ea9SDavid C Somayajulu union db_prod32 {
547fa790ea9SDavid C Somayajulu struct rdma_pwm_val16_data data;
548fa790ea9SDavid C Somayajulu u32 raw;
549fa790ea9SDavid C Somayajulu };
550fa790ea9SDavid C Somayajulu
551fa790ea9SDavid C Somayajulu struct qlnxr_qp_hwq_info {
552fa790ea9SDavid C Somayajulu /* WQE Elements*/
553fa790ea9SDavid C Somayajulu struct ecore_chain pbl;
554fa790ea9SDavid C Somayajulu u64 p_phys_addr_tbl;
555fa790ea9SDavid C Somayajulu u32 max_sges;
556fa790ea9SDavid C Somayajulu
557fa790ea9SDavid C Somayajulu /* WQE */
558fa790ea9SDavid C Somayajulu u16 prod; /* WQE prod index for SW ring */
559fa790ea9SDavid C Somayajulu u16 cons; /* WQE cons index for SW ring */
560fa790ea9SDavid C Somayajulu u16 wqe_cons;
561fa790ea9SDavid C Somayajulu u16 gsi_cons; /* filled in by GSI implementation */
562fa790ea9SDavid C Somayajulu u16 max_wr;
563fa790ea9SDavid C Somayajulu
564fa790ea9SDavid C Somayajulu /* DB */
565fa790ea9SDavid C Somayajulu void __iomem *db; /* Doorbell address */
566fa790ea9SDavid C Somayajulu union db_prod32 db_data; /* Doorbell data */
567fa790ea9SDavid C Somayajulu
568fa790ea9SDavid C Somayajulu /* Required for iwarp_only */
569fa790ea9SDavid C Somayajulu void __iomem *iwarp_db2; /* Doorbell address */
570fa790ea9SDavid C Somayajulu union db_prod32 iwarp_db2_data; /* Doorbell data */
571fa790ea9SDavid C Somayajulu };
572fa790ea9SDavid C Somayajulu
573fa790ea9SDavid C Somayajulu #define QLNXR_INC_SW_IDX(p_info, index) \
574fa790ea9SDavid C Somayajulu do { \
575fa790ea9SDavid C Somayajulu p_info->index = (p_info->index + 1) & \
576fa790ea9SDavid C Somayajulu ecore_chain_get_capacity(p_info->pbl) \
577fa790ea9SDavid C Somayajulu } while (0)
578fa790ea9SDavid C Somayajulu
579fa790ea9SDavid C Somayajulu struct qlnxr_srq_hwq_info {
580fa790ea9SDavid C Somayajulu u32 max_sges;
581fa790ea9SDavid C Somayajulu u32 max_wr;
582fa790ea9SDavid C Somayajulu struct ecore_chain pbl;
583fa790ea9SDavid C Somayajulu u64 p_phys_addr_tbl;
584fa790ea9SDavid C Somayajulu u32 wqe_prod; /* WQE prod index in HW ring */
585fa790ea9SDavid C Somayajulu u32 sge_prod; /* SGE prod index in HW ring */
586fa790ea9SDavid C Somayajulu u32 wr_prod_cnt; /* wr producer count */
587fa790ea9SDavid C Somayajulu u32 wr_cons_cnt; /* wr consumer count */
588fa790ea9SDavid C Somayajulu u32 num_elems;
589fa790ea9SDavid C Somayajulu
590fa790ea9SDavid C Somayajulu u32 *virt_prod_pair_addr; /* producer pair virtual address */
591fa790ea9SDavid C Somayajulu dma_addr_t phy_prod_pair_addr; /* producer pair physical address */
592fa790ea9SDavid C Somayajulu };
593fa790ea9SDavid C Somayajulu
594fa790ea9SDavid C Somayajulu struct qlnxr_srq {
595fa790ea9SDavid C Somayajulu struct ib_srq ibsrq;
596fa790ea9SDavid C Somayajulu struct qlnxr_dev *dev;
597fa790ea9SDavid C Somayajulu /* relevant to cqs created from user space only (applications) */
598fa790ea9SDavid C Somayajulu struct qlnxr_userq usrq;
599fa790ea9SDavid C Somayajulu struct qlnxr_srq_hwq_info hw_srq;
600fa790ea9SDavid C Somayajulu struct ib_umem *prod_umem;
601fa790ea9SDavid C Somayajulu u16 srq_id;
602fa790ea9SDavid C Somayajulu /* lock to protect srq recv post */
603fa790ea9SDavid C Somayajulu spinlock_t lock;
604fa790ea9SDavid C Somayajulu };
605fa790ea9SDavid C Somayajulu
606fa790ea9SDavid C Somayajulu enum qlnxr_qp_err_bitmap {
607fa790ea9SDavid C Somayajulu QLNXR_QP_ERR_SQ_FULL = 1 << 0,
608fa790ea9SDavid C Somayajulu QLNXR_QP_ERR_RQ_FULL = 1 << 1,
609fa790ea9SDavid C Somayajulu QLNXR_QP_ERR_BAD_SR = 1 << 2,
610fa790ea9SDavid C Somayajulu QLNXR_QP_ERR_BAD_RR = 1 << 3,
611fa790ea9SDavid C Somayajulu QLNXR_QP_ERR_SQ_PBL_FULL = 1 << 4,
612fa790ea9SDavid C Somayajulu QLNXR_QP_ERR_RQ_PBL_FULL = 1 << 5,
613fa790ea9SDavid C Somayajulu };
614fa790ea9SDavid C Somayajulu
615fa790ea9SDavid C Somayajulu struct mr_info {
616fa790ea9SDavid C Somayajulu struct qlnxr_pbl *pbl_table;
617fa790ea9SDavid C Somayajulu struct qlnxr_pbl_info pbl_info;
618fa790ea9SDavid C Somayajulu struct list_head free_pbl_list;
619fa790ea9SDavid C Somayajulu struct list_head inuse_pbl_list;
620fa790ea9SDavid C Somayajulu u32 completed;
621fa790ea9SDavid C Somayajulu u32 completed_handled;
622fa790ea9SDavid C Somayajulu };
623fa790ea9SDavid C Somayajulu
624fa790ea9SDavid C Somayajulu struct qlnxr_qp {
625fa790ea9SDavid C Somayajulu struct ib_qp ibqp; /* must be first */
626fa790ea9SDavid C Somayajulu struct qlnxr_dev *dev;
627fa790ea9SDavid C Somayajulu struct qlnxr_iw_ep *ep;
628fa790ea9SDavid C Somayajulu struct qlnxr_qp_hwq_info sq;
629fa790ea9SDavid C Somayajulu struct qlnxr_qp_hwq_info rq;
630fa790ea9SDavid C Somayajulu
631fa790ea9SDavid C Somayajulu u32 max_inline_data;
632fa790ea9SDavid C Somayajulu
633fa790ea9SDavid C Somayajulu spinlock_t q_lock ____cacheline_aligned;
634fa790ea9SDavid C Somayajulu
635fa790ea9SDavid C Somayajulu struct qlnxr_cq *sq_cq;
636fa790ea9SDavid C Somayajulu struct qlnxr_cq *rq_cq;
637fa790ea9SDavid C Somayajulu struct qlnxr_srq *srq;
638fa790ea9SDavid C Somayajulu enum ecore_roce_qp_state state; /* QP state */
639fa790ea9SDavid C Somayajulu u32 id;
640fa790ea9SDavid C Somayajulu struct qlnxr_pd *pd;
641fa790ea9SDavid C Somayajulu enum ib_qp_type qp_type;
642fa790ea9SDavid C Somayajulu struct ecore_rdma_qp *ecore_qp;
643fa790ea9SDavid C Somayajulu u32 qp_id;
644fa790ea9SDavid C Somayajulu u16 icid;
645fa790ea9SDavid C Somayajulu u16 mtu;
646fa790ea9SDavid C Somayajulu int sgid_idx;
647fa790ea9SDavid C Somayajulu u32 rq_psn;
648fa790ea9SDavid C Somayajulu u32 sq_psn;
649fa790ea9SDavid C Somayajulu u32 qkey;
650fa790ea9SDavid C Somayajulu u32 dest_qp_num;
651fa790ea9SDavid C Somayajulu u32 sig; /* unique siganture to identify valid QP */
652fa790ea9SDavid C Somayajulu
653fa790ea9SDavid C Somayajulu /* relevant to qps created from kernel space only (ULPs) */
654fa790ea9SDavid C Somayajulu u8 prev_wqe_size;
655fa790ea9SDavid C Somayajulu u16 wqe_cons;
656fa790ea9SDavid C Somayajulu u32 err_bitmap;
657fa790ea9SDavid C Somayajulu bool signaled;
658fa790ea9SDavid C Somayajulu /* SQ shadow */
659fa790ea9SDavid C Somayajulu struct {
660fa790ea9SDavid C Somayajulu u64 wr_id;
661fa790ea9SDavid C Somayajulu enum ib_wc_opcode opcode;
662fa790ea9SDavid C Somayajulu u32 bytes_len;
663fa790ea9SDavid C Somayajulu u8 wqe_size;
664fa790ea9SDavid C Somayajulu bool signaled;
665fa790ea9SDavid C Somayajulu dma_addr_t icrc_mapping;
666fa790ea9SDavid C Somayajulu u32 *icrc;
667fa790ea9SDavid C Somayajulu struct qlnxr_mr *mr;
668fa790ea9SDavid C Somayajulu } *wqe_wr_id;
669fa790ea9SDavid C Somayajulu
670fa790ea9SDavid C Somayajulu /* RQ shadow */
671fa790ea9SDavid C Somayajulu struct {
672fa790ea9SDavid C Somayajulu u64 wr_id;
673fa790ea9SDavid C Somayajulu struct ib_sge sg_list[RDMA_MAX_SGE_PER_RQ_WQE];
674fa790ea9SDavid C Somayajulu uint8_t wqe_size;
675fa790ea9SDavid C Somayajulu
676fa790ea9SDavid C Somayajulu /* for GSI only */
677fa790ea9SDavid C Somayajulu u8 smac[ETH_ALEN];
678fa790ea9SDavid C Somayajulu u16 vlan_id;
679fa790ea9SDavid C Somayajulu int rc;
680fa790ea9SDavid C Somayajulu } *rqe_wr_id;
681fa790ea9SDavid C Somayajulu
682fa790ea9SDavid C Somayajulu /* relevant to qps created from user space only (applications) */
683fa790ea9SDavid C Somayajulu struct qlnxr_userq usq;
684fa790ea9SDavid C Somayajulu struct qlnxr_userq urq;
685fa790ea9SDavid C Somayajulu atomic_t refcnt;
686fa790ea9SDavid C Somayajulu bool destroyed;
687fa790ea9SDavid C Somayajulu };
688fa790ea9SDavid C Somayajulu
689fa790ea9SDavid C Somayajulu enum qlnxr_mr_type {
690fa790ea9SDavid C Somayajulu QLNXR_MR_USER,
691fa790ea9SDavid C Somayajulu QLNXR_MR_KERNEL,
692fa790ea9SDavid C Somayajulu QLNXR_MR_DMA,
693fa790ea9SDavid C Somayajulu QLNXR_MR_FRMR
694fa790ea9SDavid C Somayajulu };
695fa790ea9SDavid C Somayajulu
696fa790ea9SDavid C Somayajulu struct qlnxr_mr {
697fa790ea9SDavid C Somayajulu struct ib_mr ibmr;
698fa790ea9SDavid C Somayajulu struct ib_umem *umem;
699fa790ea9SDavid C Somayajulu
700fa790ea9SDavid C Somayajulu struct ecore_rdma_register_tid_in_params hw_mr;
701fa790ea9SDavid C Somayajulu enum qlnxr_mr_type type;
702fa790ea9SDavid C Somayajulu
703fa790ea9SDavid C Somayajulu struct qlnxr_dev *dev;
704fa790ea9SDavid C Somayajulu struct mr_info info;
705fa790ea9SDavid C Somayajulu
706fa790ea9SDavid C Somayajulu u64 *pages;
707fa790ea9SDavid C Somayajulu u32 npages;
708fa790ea9SDavid C Somayajulu
709fa790ea9SDavid C Somayajulu u64 *iova_start; /* valid only for kernel_mr */
710fa790ea9SDavid C Somayajulu };
711fa790ea9SDavid C Somayajulu
712fa790ea9SDavid C Somayajulu struct qlnxr_mm {
713fa790ea9SDavid C Somayajulu struct {
714fa790ea9SDavid C Somayajulu u64 phy_addr;
715fa790ea9SDavid C Somayajulu unsigned long len;
716fa790ea9SDavid C Somayajulu } key;
717fa790ea9SDavid C Somayajulu struct list_head entry;
718fa790ea9SDavid C Somayajulu };
719fa790ea9SDavid C Somayajulu
720fa790ea9SDavid C Somayajulu struct qlnxr_iw_listener {
721fa790ea9SDavid C Somayajulu struct qlnxr_dev *dev;
722fa790ea9SDavid C Somayajulu struct iw_cm_id *cm_id;
723fa790ea9SDavid C Somayajulu int backlog;
724fa790ea9SDavid C Somayajulu void *ecore_handle;
725fa790ea9SDavid C Somayajulu };
726fa790ea9SDavid C Somayajulu
727fa790ea9SDavid C Somayajulu struct qlnxr_iw_ep {
728fa790ea9SDavid C Somayajulu struct qlnxr_dev *dev;
729fa790ea9SDavid C Somayajulu struct iw_cm_id *cm_id;
730fa790ea9SDavid C Somayajulu struct qlnxr_qp *qp;
731fa790ea9SDavid C Somayajulu void *ecore_context;
732fa790ea9SDavid C Somayajulu u8 during_connect;
733fa790ea9SDavid C Somayajulu };
734fa790ea9SDavid C Somayajulu
735fa790ea9SDavid C Somayajulu static inline void
qlnxr_inc_sw_cons(struct qlnxr_qp_hwq_info * info)736fa790ea9SDavid C Somayajulu qlnxr_inc_sw_cons(struct qlnxr_qp_hwq_info *info)
737fa790ea9SDavid C Somayajulu {
738fa790ea9SDavid C Somayajulu info->cons = (info->cons + 1) % info->max_wr;
739fa790ea9SDavid C Somayajulu info->wqe_cons++;
740fa790ea9SDavid C Somayajulu }
741fa790ea9SDavid C Somayajulu
742fa790ea9SDavid C Somayajulu static inline void
qlnxr_inc_sw_prod(struct qlnxr_qp_hwq_info * info)743fa790ea9SDavid C Somayajulu qlnxr_inc_sw_prod(struct qlnxr_qp_hwq_info *info)
744fa790ea9SDavid C Somayajulu {
745fa790ea9SDavid C Somayajulu info->prod = (info->prod + 1) % info->max_wr;
746fa790ea9SDavid C Somayajulu }
747fa790ea9SDavid C Somayajulu
748fa790ea9SDavid C Somayajulu static inline struct qlnxr_dev *
get_qlnxr_dev(struct ib_device * ibdev)749fa790ea9SDavid C Somayajulu get_qlnxr_dev(struct ib_device *ibdev)
750fa790ea9SDavid C Somayajulu {
751fa790ea9SDavid C Somayajulu return container_of(ibdev, struct qlnxr_dev, ibdev);
752fa790ea9SDavid C Somayajulu }
753fa790ea9SDavid C Somayajulu
754fa790ea9SDavid C Somayajulu static inline struct qlnxr_ucontext *
get_qlnxr_ucontext(struct ib_ucontext * ibucontext)755fa790ea9SDavid C Somayajulu get_qlnxr_ucontext(struct ib_ucontext *ibucontext)
756fa790ea9SDavid C Somayajulu {
757fa790ea9SDavid C Somayajulu return container_of(ibucontext, struct qlnxr_ucontext, ibucontext);
758fa790ea9SDavid C Somayajulu }
759fa790ea9SDavid C Somayajulu
760fa790ea9SDavid C Somayajulu static inline struct qlnxr_pd *
get_qlnxr_pd(struct ib_pd * ibpd)761fa790ea9SDavid C Somayajulu get_qlnxr_pd(struct ib_pd *ibpd)
762fa790ea9SDavid C Somayajulu {
763fa790ea9SDavid C Somayajulu return container_of(ibpd, struct qlnxr_pd, ibpd);
764fa790ea9SDavid C Somayajulu }
765fa790ea9SDavid C Somayajulu
766fa790ea9SDavid C Somayajulu static inline struct qlnxr_cq *
get_qlnxr_cq(struct ib_cq * ibcq)767fa790ea9SDavid C Somayajulu get_qlnxr_cq(struct ib_cq *ibcq)
768fa790ea9SDavid C Somayajulu {
769fa790ea9SDavid C Somayajulu return container_of(ibcq, struct qlnxr_cq, ibcq);
770fa790ea9SDavid C Somayajulu }
771fa790ea9SDavid C Somayajulu
772fa790ea9SDavid C Somayajulu static inline struct qlnxr_qp *
get_qlnxr_qp(struct ib_qp * ibqp)773fa790ea9SDavid C Somayajulu get_qlnxr_qp(struct ib_qp *ibqp)
774fa790ea9SDavid C Somayajulu {
775fa790ea9SDavid C Somayajulu return container_of(ibqp, struct qlnxr_qp, ibqp);
776fa790ea9SDavid C Somayajulu }
777fa790ea9SDavid C Somayajulu
778fa790ea9SDavid C Somayajulu static inline struct qlnxr_mr *
get_qlnxr_mr(struct ib_mr * ibmr)779fa790ea9SDavid C Somayajulu get_qlnxr_mr(struct ib_mr *ibmr)
780fa790ea9SDavid C Somayajulu {
781fa790ea9SDavid C Somayajulu return container_of(ibmr, struct qlnxr_mr, ibmr);
782fa790ea9SDavid C Somayajulu }
783fa790ea9SDavid C Somayajulu
784fa790ea9SDavid C Somayajulu static inline struct qlnxr_ah *
get_qlnxr_ah(struct ib_ah * ibah)785fa790ea9SDavid C Somayajulu get_qlnxr_ah(struct ib_ah *ibah)
786fa790ea9SDavid C Somayajulu {
787fa790ea9SDavid C Somayajulu return container_of(ibah, struct qlnxr_ah, ibah);
788fa790ea9SDavid C Somayajulu }
789fa790ea9SDavid C Somayajulu
790fa790ea9SDavid C Somayajulu static inline struct qlnxr_srq *
get_qlnxr_srq(struct ib_srq * ibsrq)791fa790ea9SDavid C Somayajulu get_qlnxr_srq(struct ib_srq *ibsrq)
792fa790ea9SDavid C Somayajulu {
793fa790ea9SDavid C Somayajulu return container_of(ibsrq, struct qlnxr_srq, ibsrq);
794fa790ea9SDavid C Somayajulu }
795fa790ea9SDavid C Somayajulu
qlnxr_qp_has_srq(struct qlnxr_qp * qp)796fa790ea9SDavid C Somayajulu static inline bool qlnxr_qp_has_srq(struct qlnxr_qp *qp)
797fa790ea9SDavid C Somayajulu {
798fa790ea9SDavid C Somayajulu return !!qp->srq;
799fa790ea9SDavid C Somayajulu }
800fa790ea9SDavid C Somayajulu
qlnxr_qp_has_sq(struct qlnxr_qp * qp)801fa790ea9SDavid C Somayajulu static inline bool qlnxr_qp_has_sq(struct qlnxr_qp *qp)
802fa790ea9SDavid C Somayajulu {
803fa790ea9SDavid C Somayajulu if (qp->qp_type == IB_QPT_GSI)
804fa790ea9SDavid C Somayajulu return 0;
805fa790ea9SDavid C Somayajulu
806fa790ea9SDavid C Somayajulu return 1;
807fa790ea9SDavid C Somayajulu }
808fa790ea9SDavid C Somayajulu
qlnxr_qp_has_rq(struct qlnxr_qp * qp)809fa790ea9SDavid C Somayajulu static inline bool qlnxr_qp_has_rq(struct qlnxr_qp *qp)
810fa790ea9SDavid C Somayajulu {
811fa790ea9SDavid C Somayajulu if (qp->qp_type == IB_QPT_GSI || qlnxr_qp_has_srq(qp))
812fa790ea9SDavid C Somayajulu return 0;
813fa790ea9SDavid C Somayajulu
814fa790ea9SDavid C Somayajulu return 1;
815fa790ea9SDavid C Somayajulu }
816fa790ea9SDavid C Somayajulu
817fa790ea9SDavid C Somayajulu #define SET_FIELD2(value, name, flag) \
818fa790ea9SDavid C Somayajulu do { \
819fa790ea9SDavid C Somayajulu (value) |= ((flag) << (name ## _SHIFT)); \
820fa790ea9SDavid C Somayajulu } while (0)
821fa790ea9SDavid C Somayajulu
822fa790ea9SDavid C Somayajulu #define QLNXR_RESP_IMM (RDMA_CQE_RESPONDER_IMM_FLG_MASK << \
823fa790ea9SDavid C Somayajulu RDMA_CQE_RESPONDER_IMM_FLG_SHIFT)
824fa790ea9SDavid C Somayajulu #define QLNXR_RESP_RDMA (RDMA_CQE_RESPONDER_RDMA_FLG_MASK << \
825fa790ea9SDavid C Somayajulu RDMA_CQE_RESPONDER_RDMA_FLG_SHIFT)
826fa790ea9SDavid C Somayajulu #define QLNXR_RESP_INV (RDMA_CQE_RESPONDER_INV_FLG_MASK << \
827fa790ea9SDavid C Somayajulu RDMA_CQE_RESPONDER_INV_FLG_SHIFT)
828fa790ea9SDavid C Somayajulu
829fa790ea9SDavid C Somayajulu #define QLNXR_RESP_RDMA_IMM (QLNXR_RESP_IMM | QLNXR_RESP_RDMA)
830fa790ea9SDavid C Somayajulu
831fa790ea9SDavid C Somayajulu static inline int
qlnxr_get_dmac(struct qlnxr_dev * dev,struct ib_ah_attr * ah_attr,u8 * mac_addr)832fa790ea9SDavid C Somayajulu qlnxr_get_dmac(struct qlnxr_dev *dev, struct ib_ah_attr *ah_attr, u8 *mac_addr)
833fa790ea9SDavid C Somayajulu {
834fa790ea9SDavid C Somayajulu #ifdef DEFINE_NO_IP_BASED_GIDS
835fa790ea9SDavid C Somayajulu u8 *guid = &ah_attr->grh.dgid.raw[8]; /* GID's 64 MSBs are the GUID */
836fa790ea9SDavid C Somayajulu #endif
837fa790ea9SDavid C Somayajulu union ib_gid zero_sgid = { { 0 } };
838fa790ea9SDavid C Somayajulu struct in6_addr in6;
839fa790ea9SDavid C Somayajulu
840fa790ea9SDavid C Somayajulu if (!memcmp(&ah_attr->grh.dgid, &zero_sgid, sizeof(union ib_gid))) {
841fa790ea9SDavid C Somayajulu memset(mac_addr, 0x00, ETH_ALEN);
842fa790ea9SDavid C Somayajulu return -EINVAL;
843fa790ea9SDavid C Somayajulu }
844fa790ea9SDavid C Somayajulu
845fa790ea9SDavid C Somayajulu memcpy(&in6, ah_attr->grh.dgid.raw, sizeof(in6));
846fa790ea9SDavid C Somayajulu
847fa790ea9SDavid C Somayajulu #ifdef DEFINE_NO_IP_BASED_GIDS
848fa790ea9SDavid C Somayajulu /* get the MAC address from the GUID i.e. EUI-64 to MAC address */
849fa790ea9SDavid C Somayajulu mac_addr[0] = guid[0] ^ 2; /* toggle the local/universal bit to local */
850fa790ea9SDavid C Somayajulu mac_addr[1] = guid[1];
851fa790ea9SDavid C Somayajulu mac_addr[2] = guid[2];
852fa790ea9SDavid C Somayajulu mac_addr[3] = guid[5];
853fa790ea9SDavid C Somayajulu mac_addr[4] = guid[6];
854fa790ea9SDavid C Somayajulu mac_addr[5] = guid[7];
855fa790ea9SDavid C Somayajulu #else
856fa790ea9SDavid C Somayajulu memcpy(mac_addr, ah_attr->dmac, ETH_ALEN);
857fa790ea9SDavid C Somayajulu #endif
858fa790ea9SDavid C Somayajulu return 0;
859fa790ea9SDavid C Somayajulu }
860fa790ea9SDavid C Somayajulu
861fa790ea9SDavid C Somayajulu extern int qlnx_rdma_ll2_set_mac_filter(void *rdma_ctx, uint8_t *old_mac_address,
862fa790ea9SDavid C Somayajulu uint8_t *new_mac_address);
863fa790ea9SDavid C Somayajulu
864fa790ea9SDavid C Somayajulu #define QLNXR_ROCE_PKEY_MAX 1
865fa790ea9SDavid C Somayajulu #define QLNXR_ROCE_PKEY_TABLE_LEN 1
866fa790ea9SDavid C Somayajulu #define QLNXR_ROCE_PKEY_DEFAULT 0xffff
867fa790ea9SDavid C Somayajulu
868fa790ea9SDavid C Somayajulu #define QLNX_IS_IWARP(rdev) IS_IWARP(ECORE_LEADING_HWFN(rdev->cdev))
869fa790ea9SDavid C Somayajulu #define QLNX_IS_ROCE(rdev) IS_ROCE(ECORE_LEADING_HWFN(rdev->cdev))
870fa790ea9SDavid C Somayajulu
871fa790ea9SDavid C Somayajulu #define MAX_RXMIT_CONNS 16
872fa790ea9SDavid C Somayajulu
873fa790ea9SDavid C Somayajulu #endif /* #ifndef __QLNX_DEF_H_ */
874