blob: 392e76e268406b36000e0e5f165e6a81938d1e74 [file] [log] [blame]
Ram Amrani2e0cbc42016-10-10 13:15:30 +03001/* QLogic qedr NIC Driver
2 * Copyright (c) 2015-2016 QLogic Corporation
3 *
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
9 *
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
12 * conditions are met:
13 *
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer.
17 *
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and /or other materials
21 * provided with the distribution.
22 *
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 * SOFTWARE.
31 */
32#ifndef __QEDR_H__
33#define __QEDR_H__
34
35#include <linux/pci.h>
36#include <rdma/ib_addr.h>
37#include <linux/qed/qed_if.h>
Ram Amraniec72fce2016-10-10 13:15:31 +030038#include <linux/qed/qed_chain.h>
Kalderon, Michal7003cdd2017-06-21 16:22:46 +030039#include <linux/qed/qed_rdma_if.h>
Michal Kalderonb262a062017-06-20 16:00:03 +030040#include <linux/qed/qede_rdma.h>
Mintz, Yuvalbe086e72017-03-11 18:39:18 +020041#include <linux/qed/roce_common.h>
42#include "qedr_hsi_rdma.h"
Ram Amrani2e0cbc42016-10-10 13:15:30 +030043
Ram Amrani2e0cbc42016-10-10 13:15:30 +030044#define QEDR_NODE_DESC "QLogic 579xx RoCE HCA"
45#define DP_NAME(dev) ((dev)->ibdev.name)
46
47#define DP_DEBUG(dev, module, fmt, ...) \
48 pr_debug("(%s) " module ": " fmt, \
49 DP_NAME(dev) ? DP_NAME(dev) : "", ## __VA_ARGS__)
50
51#define QEDR_MSG_INIT "INIT"
Ram Amraniac1b36e2016-10-10 13:15:32 +030052#define QEDR_MSG_MISC "MISC"
Ram Amrania7efd772016-10-10 13:15:33 +030053#define QEDR_MSG_CQ " CQ"
54#define QEDR_MSG_MR " MR"
Ram Amranicecbcdd2016-10-10 13:15:34 +030055#define QEDR_MSG_RQ " RQ"
56#define QEDR_MSG_SQ " SQ"
57#define QEDR_MSG_QP " QP"
Ram Amrani04886772016-10-10 13:15:38 +030058#define QEDR_MSG_GSI " GSI"
Ram Amrania7efd772016-10-10 13:15:33 +030059
Ram Amranie57bb6b2017-06-05 16:32:27 +030060#define QEDR_CQ_MAGIC_NUMBER (0x11223344)
61
62#define FW_PAGE_SIZE (RDMA_RING_PAGE_SIZE)
63#define FW_PAGE_SHIFT (12)
Ram Amrani2e0cbc42016-10-10 13:15:30 +030064
Ram Amraniec72fce2016-10-10 13:15:31 +030065struct qedr_dev;
66
67struct qedr_cnq {
68 struct qedr_dev *dev;
69 struct qed_chain pbl;
70 struct qed_sb_info *sb;
71 char name[32];
72 u64 n_comp;
73 __le16 *hw_cons_ptr;
74 u8 index;
75};
76
77#define QEDR_MAX_SGID 128
78
79struct qedr_device_attr {
80 u32 vendor_id;
81 u32 vendor_part_id;
82 u32 hw_ver;
83 u64 fw_ver;
84 u64 node_guid;
85 u64 sys_image_guid;
86 u8 max_cnq;
87 u8 max_sge;
88 u16 max_inline;
89 u32 max_sqe;
90 u32 max_rqe;
91 u8 max_qp_resp_rd_atomic_resc;
92 u8 max_qp_req_rd_atomic_resc;
93 u64 max_dev_resp_rd_atomic_resc;
94 u32 max_cq;
95 u32 max_qp;
96 u32 max_mr;
97 u64 max_mr_size;
98 u32 max_cqe;
99 u32 max_mw;
100 u32 max_fmr;
101 u32 max_mr_mw_fmr_pbl;
102 u64 max_mr_mw_fmr_size;
103 u32 max_pd;
104 u32 max_ah;
105 u8 max_pkey;
106 u32 max_srq;
107 u32 max_srq_wr;
108 u8 max_srq_sge;
109 u8 max_stats_queues;
110 u32 dev_caps;
111
112 u64 page_size_caps;
113 u8 dev_ack_delay;
114 u32 reserved_lkey;
115 u32 bad_pkey_counter;
116 struct qed_rdma_events events;
117};
118
Ram Amranif449c7a2017-01-24 13:51:43 +0200119#define QEDR_ENET_STATE_BIT (0)
120
Ram Amrani2e0cbc42016-10-10 13:15:30 +0300121struct qedr_dev {
122 struct ib_device ibdev;
123 struct qed_dev *cdev;
124 struct pci_dev *pdev;
125 struct net_device *ndev;
126
127 enum ib_atomic_cap atomic_cap;
128
Ram Amraniec72fce2016-10-10 13:15:31 +0300129 void *rdma_ctx;
130 struct qedr_device_attr attr;
131
132 const struct qed_rdma_ops *ops;
133 struct qed_int_info int_info;
134
135 struct qed_sb_info *sb_array;
136 struct qedr_cnq *cnq_array;
137 int num_cnq;
138 int sb_start;
139
140 void __iomem *db_addr;
141 u64 db_phys_addr;
142 u32 db_size;
143 u16 dpi;
144
145 union ib_gid *sgid_tbl;
146
147 /* Lock for sgid table */
148 spinlock_t sgid_lock;
149
150 u64 guid;
151
Ram Amrani2e0cbc42016-10-10 13:15:30 +0300152 u32 dp_module;
153 u8 dp_level;
Ram Amraniec72fce2016-10-10 13:15:31 +0300154 u8 num_hwfns;
Michal Kalderon0518c122017-06-09 17:13:22 +0300155 u8 gsi_ll2_handle;
156
Ram Amranicecbcdd2016-10-10 13:15:34 +0300157 uint wq_multiplier;
Ram Amrani1d1424c2016-10-10 13:15:37 +0300158 u8 gsi_ll2_mac_address[ETH_ALEN];
Ram Amrani04886772016-10-10 13:15:38 +0300159 int gsi_qp_created;
160 struct qedr_cq *gsi_sqcq;
161 struct qedr_cq *gsi_rqcq;
162 struct qedr_qp *gsi_qp;
Ram Amranif449c7a2017-01-24 13:51:43 +0200163
164 unsigned long enet_state;
Ram Amrani2e0cbc42016-10-10 13:15:30 +0300165};
Ram Amraniec72fce2016-10-10 13:15:31 +0300166
167#define QEDR_MAX_SQ_PBL (0x8000)
168#define QEDR_MAX_SQ_PBL_ENTRIES (0x10000 / sizeof(void *))
169#define QEDR_SQE_ELEMENT_SIZE (sizeof(struct rdma_sq_sge))
170#define QEDR_MAX_SQE_ELEMENTS_PER_SQE (ROCE_REQ_MAX_SINGLE_SQ_WQE_SIZE / \
171 QEDR_SQE_ELEMENT_SIZE)
172#define QEDR_MAX_SQE_ELEMENTS_PER_PAGE ((RDMA_RING_PAGE_SIZE) / \
173 QEDR_SQE_ELEMENT_SIZE)
174#define QEDR_MAX_SQE ((QEDR_MAX_SQ_PBL_ENTRIES) *\
175 (RDMA_RING_PAGE_SIZE) / \
176 (QEDR_SQE_ELEMENT_SIZE) /\
177 (QEDR_MAX_SQE_ELEMENTS_PER_SQE))
178/* RQ */
179#define QEDR_MAX_RQ_PBL (0x2000)
180#define QEDR_MAX_RQ_PBL_ENTRIES (0x10000 / sizeof(void *))
181#define QEDR_RQE_ELEMENT_SIZE (sizeof(struct rdma_rq_sge))
182#define QEDR_MAX_RQE_ELEMENTS_PER_RQE (RDMA_MAX_SGE_PER_RQ_WQE)
183#define QEDR_MAX_RQE_ELEMENTS_PER_PAGE ((RDMA_RING_PAGE_SIZE) / \
184 QEDR_RQE_ELEMENT_SIZE)
185#define QEDR_MAX_RQE ((QEDR_MAX_RQ_PBL_ENTRIES) *\
186 (RDMA_RING_PAGE_SIZE) / \
187 (QEDR_RQE_ELEMENT_SIZE) /\
188 (QEDR_MAX_RQE_ELEMENTS_PER_RQE))
189
190#define QEDR_CQE_SIZE (sizeof(union rdma_cqe))
191#define QEDR_MAX_CQE_PBL_SIZE (512 * 1024)
192#define QEDR_MAX_CQE_PBL_ENTRIES (((QEDR_MAX_CQE_PBL_SIZE) / \
193 sizeof(u64)) - 1)
194#define QEDR_MAX_CQES ((u32)((QEDR_MAX_CQE_PBL_ENTRIES) * \
195 (QED_CHAIN_PAGE_SIZE) / QEDR_CQE_SIZE))
196
197#define QEDR_ROCE_MAX_CNQ_SIZE (0x4000)
198
199#define QEDR_MAX_PORT (1)
Ram Amranif449c7a2017-01-24 13:51:43 +0200200#define QEDR_PORT (1)
Ram Amraniec72fce2016-10-10 13:15:31 +0300201
202#define QEDR_UVERBS(CMD_NAME) (1ull << IB_USER_VERBS_CMD_##CMD_NAME)
203
Ram Amraniac1b36e2016-10-10 13:15:32 +0300204#define QEDR_ROCE_PKEY_MAX 1
205#define QEDR_ROCE_PKEY_TABLE_LEN 1
206#define QEDR_ROCE_PKEY_DEFAULT 0xffff
207
Ram Amrania7efd772016-10-10 13:15:33 +0300208struct qedr_pbl {
209 struct list_head list_entry;
210 void *va;
211 dma_addr_t pa;
212};
213
Ram Amraniac1b36e2016-10-10 13:15:32 +0300214struct qedr_ucontext {
215 struct ib_ucontext ibucontext;
216 struct qedr_dev *dev;
217 struct qedr_pd *pd;
218 u64 dpi_addr;
219 u64 dpi_phys_addr;
220 u32 dpi_size;
221 u16 dpi;
222
223 struct list_head mm_head;
224
225 /* Lock to protect mm list */
226 struct mutex mm_list_lock;
227};
228
Ram Amrania7efd772016-10-10 13:15:33 +0300229union db_prod64 {
230 struct rdma_pwm_val32_data data;
231 u64 raw;
232};
233
234enum qedr_cq_type {
235 QEDR_CQ_TYPE_GSI,
236 QEDR_CQ_TYPE_KERNEL,
237 QEDR_CQ_TYPE_USER,
238};
239
240struct qedr_pbl_info {
241 u32 num_pbls;
242 u32 num_pbes;
243 u32 pbl_size;
244 u32 pbe_size;
245 bool two_layered;
246};
247
248struct qedr_userq {
249 struct ib_umem *umem;
250 struct qedr_pbl_info pbl_info;
251 struct qedr_pbl *pbl_tbl;
252 u64 buf_addr;
253 size_t buf_len;
254};
255
256struct qedr_cq {
257 struct ib_cq ibcq;
258
259 enum qedr_cq_type cq_type;
260 u32 sig;
261
262 u16 icid;
263
264 /* Lock to protect multiplem CQ's */
265 spinlock_t cq_lock;
266 u8 arm_flags;
267 struct qed_chain pbl;
268
269 void __iomem *db_addr;
270 union db_prod64 db;
271
272 u8 pbl_toggle;
273 union rdma_cqe *latest_cqe;
274 union rdma_cqe *toggle_cqe;
275
276 u32 cq_cons;
277
278 struct qedr_userq q;
Amrani, Ram4dd72632017-04-27 13:35:34 +0300279 u8 destroyed;
280 u16 cnq_notif;
Ram Amrania7efd772016-10-10 13:15:33 +0300281};
282
283struct qedr_pd {
284 struct ib_pd ibpd;
285 u32 pd_id;
286 struct qedr_ucontext *uctx;
287};
288
Ram Amraniac1b36e2016-10-10 13:15:32 +0300289struct qedr_mm {
290 struct {
291 u64 phy_addr;
292 unsigned long len;
293 } key;
294 struct list_head entry;
295};
296
Ram Amranicecbcdd2016-10-10 13:15:34 +0300297union db_prod32 {
298 struct rdma_pwm_val16_data data;
299 u32 raw;
300};
301
302struct qedr_qp_hwq_info {
303 /* WQE Elements */
304 struct qed_chain pbl;
305 u64 p_phys_addr_tbl;
306 u32 max_sges;
307
308 /* WQE */
309 u16 prod;
310 u16 cons;
311 u16 wqe_cons;
Ram Amrani04886772016-10-10 13:15:38 +0300312 u16 gsi_cons;
Ram Amranicecbcdd2016-10-10 13:15:34 +0300313 u16 max_wr;
314
315 /* DB */
316 void __iomem *db;
317 union db_prod32 db_data;
318};
319
320#define QEDR_INC_SW_IDX(p_info, index) \
321 do { \
322 p_info->index = (p_info->index + 1) & \
323 qed_chain_get_capacity(p_info->pbl) \
324 } while (0)
325
326enum qedr_qp_err_bitmap {
327 QEDR_QP_ERR_SQ_FULL = 1,
328 QEDR_QP_ERR_RQ_FULL = 2,
329 QEDR_QP_ERR_BAD_SR = 4,
330 QEDR_QP_ERR_BAD_RR = 8,
331 QEDR_QP_ERR_SQ_PBL_FULL = 16,
332 QEDR_QP_ERR_RQ_PBL_FULL = 32,
333};
334
335struct qedr_qp {
336 struct ib_qp ibqp; /* must be first */
337 struct qedr_dev *dev;
338
339 struct qedr_qp_hwq_info sq;
340 struct qedr_qp_hwq_info rq;
341
342 u32 max_inline_data;
343
344 /* Lock for QP's */
345 spinlock_t q_lock;
346 struct qedr_cq *sq_cq;
347 struct qedr_cq *rq_cq;
348 struct qedr_srq *srq;
349 enum qed_roce_qp_state state;
350 u32 id;
351 struct qedr_pd *pd;
352 enum ib_qp_type qp_type;
353 struct qed_rdma_qp *qed_qp;
354 u32 qp_id;
355 u16 icid;
356 u16 mtu;
357 int sgid_idx;
358 u32 rq_psn;
359 u32 sq_psn;
360 u32 qkey;
361 u32 dest_qp_num;
362
363 /* Relevant to qps created from kernel space only (ULPs) */
364 u8 prev_wqe_size;
365 u16 wqe_cons;
366 u32 err_bitmap;
367 bool signaled;
368
369 /* SQ shadow */
370 struct {
371 u64 wr_id;
372 enum ib_wc_opcode opcode;
373 u32 bytes_len;
374 u8 wqe_size;
375 bool signaled;
376 dma_addr_t icrc_mapping;
377 u32 *icrc;
378 struct qedr_mr *mr;
379 } *wqe_wr_id;
380
381 /* RQ shadow */
382 struct {
383 u64 wr_id;
384 struct ib_sge sg_list[RDMA_MAX_SGE_PER_RQ_WQE];
385 u8 wqe_size;
386
Ram Amrani04886772016-10-10 13:15:38 +0300387 u8 smac[ETH_ALEN];
Ram Amranicecbcdd2016-10-10 13:15:34 +0300388 u16 vlan_id;
389 int rc;
390 } *rqe_wr_id;
391
392 /* Relevant to qps created from user space only (applications) */
393 struct qedr_userq usq;
394 struct qedr_userq urq;
395};
396
Ram Amranie0290cc2016-10-10 13:15:35 +0300397struct qedr_ah {
398 struct ib_ah ibah;
Dasaratharaman Chandramouli90898852017-04-29 14:41:18 -0400399 struct rdma_ah_attr attr;
Ram Amranie0290cc2016-10-10 13:15:35 +0300400};
401
402enum qedr_mr_type {
403 QEDR_MR_USER,
404 QEDR_MR_KERNEL,
405 QEDR_MR_DMA,
406 QEDR_MR_FRMR,
407};
408
409struct mr_info {
410 struct qedr_pbl *pbl_table;
411 struct qedr_pbl_info pbl_info;
412 struct list_head free_pbl_list;
413 struct list_head inuse_pbl_list;
414 u32 completed;
415 u32 completed_handled;
416};
417
418struct qedr_mr {
419 struct ib_mr ibmr;
420 struct ib_umem *umem;
421
422 struct qed_rdma_register_tid_in_params hw_mr;
423 enum qedr_mr_type type;
424
425 struct qedr_dev *dev;
426 struct mr_info info;
427
428 u64 *pages;
429 u32 npages;
430};
431
Ram Amraniafa0e132016-10-10 13:15:36 +0300432#define SET_FIELD2(value, name, flag) ((value) |= ((flag) << (name ## _SHIFT)))
433
434#define QEDR_RESP_IMM (RDMA_CQE_RESPONDER_IMM_FLG_MASK << \
435 RDMA_CQE_RESPONDER_IMM_FLG_SHIFT)
436#define QEDR_RESP_RDMA (RDMA_CQE_RESPONDER_RDMA_FLG_MASK << \
437 RDMA_CQE_RESPONDER_RDMA_FLG_SHIFT)
Amrani, Ramb6acd712017-04-27 13:35:35 +0300438#define QEDR_RESP_INV (RDMA_CQE_RESPONDER_INV_FLG_MASK << \
439 RDMA_CQE_RESPONDER_INV_FLG_SHIFT)
Ram Amraniafa0e132016-10-10 13:15:36 +0300440
441static inline void qedr_inc_sw_cons(struct qedr_qp_hwq_info *info)
442{
443 info->cons = (info->cons + 1) % info->max_wr;
444 info->wqe_cons++;
445}
446
447static inline void qedr_inc_sw_prod(struct qedr_qp_hwq_info *info)
448{
449 info->prod = (info->prod + 1) % info->max_wr;
450}
451
Ram Amranicecbcdd2016-10-10 13:15:34 +0300452static inline int qedr_get_dmac(struct qedr_dev *dev,
Dasaratharaman Chandramouli90898852017-04-29 14:41:18 -0400453 struct rdma_ah_attr *ah_attr, u8 *mac_addr)
Ram Amranicecbcdd2016-10-10 13:15:34 +0300454{
455 union ib_gid zero_sgid = { { 0 } };
456 struct in6_addr in6;
Dasaratharaman Chandramoulid8966fc2017-04-29 14:41:28 -0400457 const struct ib_global_route *grh = rdma_ah_read_grh(ah_attr);
458 u8 *dmac;
Ram Amranicecbcdd2016-10-10 13:15:34 +0300459
Dasaratharaman Chandramoulid8966fc2017-04-29 14:41:28 -0400460 if (!memcmp(&grh->dgid, &zero_sgid, sizeof(union ib_gid))) {
Ram Amranicecbcdd2016-10-10 13:15:34 +0300461 DP_ERR(dev, "Local port GID not supported\n");
462 eth_zero_addr(mac_addr);
463 return -EINVAL;
464 }
465
Dasaratharaman Chandramoulid8966fc2017-04-29 14:41:28 -0400466 memcpy(&in6, grh->dgid.raw, sizeof(in6));
467 dmac = rdma_ah_retrieve_dmac(ah_attr);
468 if (!dmac)
469 return -EINVAL;
470 ether_addr_copy(mac_addr, dmac);
Ram Amranicecbcdd2016-10-10 13:15:34 +0300471
472 return 0;
473}
474
Ram Amraniac1b36e2016-10-10 13:15:32 +0300475static inline
476struct qedr_ucontext *get_qedr_ucontext(struct ib_ucontext *ibucontext)
477{
478 return container_of(ibucontext, struct qedr_ucontext, ibucontext);
479}
480
Ram Amraniec72fce2016-10-10 13:15:31 +0300481static inline struct qedr_dev *get_qedr_dev(struct ib_device *ibdev)
482{
483 return container_of(ibdev, struct qedr_dev, ibdev);
484}
485
Ram Amrania7efd772016-10-10 13:15:33 +0300486static inline struct qedr_pd *get_qedr_pd(struct ib_pd *ibpd)
487{
488 return container_of(ibpd, struct qedr_pd, ibpd);
489}
490
491static inline struct qedr_cq *get_qedr_cq(struct ib_cq *ibcq)
492{
493 return container_of(ibcq, struct qedr_cq, ibcq);
494}
495
Ram Amranicecbcdd2016-10-10 13:15:34 +0300496static inline struct qedr_qp *get_qedr_qp(struct ib_qp *ibqp)
497{
498 return container_of(ibqp, struct qedr_qp, ibqp);
499}
Ram Amranie0290cc2016-10-10 13:15:35 +0300500
Ram Amrani04886772016-10-10 13:15:38 +0300501static inline struct qedr_ah *get_qedr_ah(struct ib_ah *ibah)
502{
503 return container_of(ibah, struct qedr_ah, ibah);
504}
505
Ram Amranie0290cc2016-10-10 13:15:35 +0300506static inline struct qedr_mr *get_qedr_mr(struct ib_mr *ibmr)
507{
508 return container_of(ibmr, struct qedr_mr, ibmr);
509}
Ram Amrani2e0cbc42016-10-10 13:15:30 +0300510#endif