2 * Broadcom NetXtreme-E RoCE driver.
4 * Copyright (c) 2016 - 2017, Broadcom. All rights reserved. The term
5 * Broadcom refers to Broadcom Limited and/or its subsidiaries.
7 * This software is available to you under a choice of one of two
8 * licenses. You may choose to be licensed under the terms of the GNU
9 * General Public License (GPL) Version 2, available from the file
10 * COPYING in the main directory of this source tree, or the
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
17 * 1. Redistributions of source code must retain the above copyright
18 * notice, this list of conditions and the following disclaimer.
19 * 2. Redistributions in binary form must reproduce the above copyright
20 * notice, this list of conditions and the following disclaimer in
21 * the documentation and/or other materials provided with the
24 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS''
25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
26 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
27 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS
28 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
31 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
32 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
33 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
34 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 * Description: IB Verbs interpreter
39 #include <linux/interrupt.h>
40 #include <linux/types.h>
41 #include <linux/pci.h>
42 #include <linux/netdevice.h>
43 #include <linux/if_ether.h>
45 #include <rdma/ib_verbs.h>
46 #include <rdma/ib_user_verbs.h>
47 #include <rdma/ib_umem.h>
48 #include <rdma/ib_addr.h>
49 #include <rdma/ib_mad.h>
50 #include <rdma/ib_cache.h>
55 #include "qplib_res.h"
58 #include "qplib_rcfw.h"
62 #include <rdma/bnxt_re-abi.h>
64 static int __from_ib_access_flags(int iflags
)
68 if (iflags
& IB_ACCESS_LOCAL_WRITE
)
69 qflags
|= BNXT_QPLIB_ACCESS_LOCAL_WRITE
;
70 if (iflags
& IB_ACCESS_REMOTE_READ
)
71 qflags
|= BNXT_QPLIB_ACCESS_REMOTE_READ
;
72 if (iflags
& IB_ACCESS_REMOTE_WRITE
)
73 qflags
|= BNXT_QPLIB_ACCESS_REMOTE_WRITE
;
74 if (iflags
& IB_ACCESS_REMOTE_ATOMIC
)
75 qflags
|= BNXT_QPLIB_ACCESS_REMOTE_ATOMIC
;
76 if (iflags
& IB_ACCESS_MW_BIND
)
77 qflags
|= BNXT_QPLIB_ACCESS_MW_BIND
;
78 if (iflags
& IB_ZERO_BASED
)
79 qflags
|= BNXT_QPLIB_ACCESS_ZERO_BASED
;
80 if (iflags
& IB_ACCESS_ON_DEMAND
)
81 qflags
|= BNXT_QPLIB_ACCESS_ON_DEMAND
;
85 static enum ib_access_flags
__to_ib_access_flags(int qflags
)
87 enum ib_access_flags iflags
= 0;
89 if (qflags
& BNXT_QPLIB_ACCESS_LOCAL_WRITE
)
90 iflags
|= IB_ACCESS_LOCAL_WRITE
;
91 if (qflags
& BNXT_QPLIB_ACCESS_REMOTE_WRITE
)
92 iflags
|= IB_ACCESS_REMOTE_WRITE
;
93 if (qflags
& BNXT_QPLIB_ACCESS_REMOTE_READ
)
94 iflags
|= IB_ACCESS_REMOTE_READ
;
95 if (qflags
& BNXT_QPLIB_ACCESS_REMOTE_ATOMIC
)
96 iflags
|= IB_ACCESS_REMOTE_ATOMIC
;
97 if (qflags
& BNXT_QPLIB_ACCESS_MW_BIND
)
98 iflags
|= IB_ACCESS_MW_BIND
;
99 if (qflags
& BNXT_QPLIB_ACCESS_ZERO_BASED
)
100 iflags
|= IB_ZERO_BASED
;
101 if (qflags
& BNXT_QPLIB_ACCESS_ON_DEMAND
)
102 iflags
|= IB_ACCESS_ON_DEMAND
;
106 static int bnxt_re_build_sgl(struct ib_sge
*ib_sg_list
,
107 struct bnxt_qplib_sge
*sg_list
, int num
)
111 for (i
= 0; i
< num
; i
++) {
112 sg_list
[i
].addr
= ib_sg_list
[i
].addr
;
113 sg_list
[i
].lkey
= ib_sg_list
[i
].lkey
;
114 sg_list
[i
].size
= ib_sg_list
[i
].length
;
115 total
+= sg_list
[i
].size
;
121 struct net_device
*bnxt_re_get_netdev(struct ib_device
*ibdev
, u8 port_num
)
123 struct bnxt_re_dev
*rdev
= to_bnxt_re_dev(ibdev
, ibdev
);
124 struct net_device
*netdev
= NULL
;
128 netdev
= rdev
->netdev
;
136 int bnxt_re_query_device(struct ib_device
*ibdev
,
137 struct ib_device_attr
*ib_attr
,
138 struct ib_udata
*udata
)
140 struct bnxt_re_dev
*rdev
= to_bnxt_re_dev(ibdev
, ibdev
);
141 struct bnxt_qplib_dev_attr
*dev_attr
= &rdev
->dev_attr
;
143 memset(ib_attr
, 0, sizeof(*ib_attr
));
145 ib_attr
->fw_ver
= (u64
)(unsigned long)(dev_attr
->fw_ver
);
146 bnxt_qplib_get_guid(rdev
->netdev
->dev_addr
,
147 (u8
*)&ib_attr
->sys_image_guid
);
148 ib_attr
->max_mr_size
= BNXT_RE_MAX_MR_SIZE
;
149 ib_attr
->page_size_cap
= BNXT_RE_PAGE_SIZE_4K
;
151 ib_attr
->vendor_id
= rdev
->en_dev
->pdev
->vendor
;
152 ib_attr
->vendor_part_id
= rdev
->en_dev
->pdev
->device
;
153 ib_attr
->hw_ver
= rdev
->en_dev
->pdev
->subsystem_device
;
154 ib_attr
->max_qp
= dev_attr
->max_qp
;
155 ib_attr
->max_qp_wr
= dev_attr
->max_qp_wqes
;
156 ib_attr
->device_cap_flags
=
157 IB_DEVICE_CURR_QP_STATE_MOD
158 | IB_DEVICE_RC_RNR_NAK_GEN
159 | IB_DEVICE_SHUTDOWN_PORT
160 | IB_DEVICE_SYS_IMAGE_GUID
161 | IB_DEVICE_LOCAL_DMA_LKEY
162 | IB_DEVICE_RESIZE_MAX_WR
163 | IB_DEVICE_PORT_ACTIVE_EVENT
164 | IB_DEVICE_N_NOTIFY_CQ
165 | IB_DEVICE_MEM_WINDOW
166 | IB_DEVICE_MEM_WINDOW_TYPE_2B
167 | IB_DEVICE_MEM_MGT_EXTENSIONS
;
168 ib_attr
->max_sge
= dev_attr
->max_qp_sges
;
169 ib_attr
->max_sge_rd
= dev_attr
->max_qp_sges
;
170 ib_attr
->max_cq
= dev_attr
->max_cq
;
171 ib_attr
->max_cqe
= dev_attr
->max_cq_wqes
;
172 ib_attr
->max_mr
= dev_attr
->max_mr
;
173 ib_attr
->max_pd
= dev_attr
->max_pd
;
174 ib_attr
->max_qp_rd_atom
= dev_attr
->max_qp_rd_atom
;
175 ib_attr
->max_qp_init_rd_atom
= dev_attr
->max_qp_init_rd_atom
;
176 if (dev_attr
->is_atomic
) {
177 ib_attr
->atomic_cap
= IB_ATOMIC_HCA
;
178 ib_attr
->masked_atomic_cap
= IB_ATOMIC_HCA
;
181 ib_attr
->max_ee_rd_atom
= 0;
182 ib_attr
->max_res_rd_atom
= 0;
183 ib_attr
->max_ee_init_rd_atom
= 0;
185 ib_attr
->max_rdd
= 0;
186 ib_attr
->max_mw
= dev_attr
->max_mw
;
187 ib_attr
->max_raw_ipv6_qp
= 0;
188 ib_attr
->max_raw_ethy_qp
= dev_attr
->max_raw_ethy_qp
;
189 ib_attr
->max_mcast_grp
= 0;
190 ib_attr
->max_mcast_qp_attach
= 0;
191 ib_attr
->max_total_mcast_qp_attach
= 0;
192 ib_attr
->max_ah
= dev_attr
->max_ah
;
194 ib_attr
->max_fmr
= 0;
195 ib_attr
->max_map_per_fmr
= 0;
197 ib_attr
->max_srq
= dev_attr
->max_srq
;
198 ib_attr
->max_srq_wr
= dev_attr
->max_srq_wqes
;
199 ib_attr
->max_srq_sge
= dev_attr
->max_srq_sges
;
201 ib_attr
->max_fast_reg_page_list_len
= MAX_PBL_LVL_1_PGS
;
203 ib_attr
->max_pkeys
= 1;
204 ib_attr
->local_ca_ack_delay
= BNXT_RE_DEFAULT_ACK_DELAY
;
208 int bnxt_re_modify_device(struct ib_device
*ibdev
,
209 int device_modify_mask
,
210 struct ib_device_modify
*device_modify
)
212 switch (device_modify_mask
) {
213 case IB_DEVICE_MODIFY_SYS_IMAGE_GUID
:
214 /* Modify the GUID requires the modification of the GID table */
215 /* GUID should be made as READ-ONLY */
217 case IB_DEVICE_MODIFY_NODE_DESC
:
218 /* Node Desc should be made as READ-ONLY */
227 int bnxt_re_query_port(struct ib_device
*ibdev
, u8 port_num
,
228 struct ib_port_attr
*port_attr
)
230 struct bnxt_re_dev
*rdev
= to_bnxt_re_dev(ibdev
, ibdev
);
231 struct bnxt_qplib_dev_attr
*dev_attr
= &rdev
->dev_attr
;
233 memset(port_attr
, 0, sizeof(*port_attr
));
235 if (netif_running(rdev
->netdev
) && netif_carrier_ok(rdev
->netdev
)) {
236 port_attr
->state
= IB_PORT_ACTIVE
;
237 port_attr
->phys_state
= 5;
239 port_attr
->state
= IB_PORT_DOWN
;
240 port_attr
->phys_state
= 3;
242 port_attr
->max_mtu
= IB_MTU_4096
;
243 port_attr
->active_mtu
= iboe_get_mtu(rdev
->netdev
->mtu
);
244 port_attr
->gid_tbl_len
= dev_attr
->max_sgid
;
245 port_attr
->port_cap_flags
= IB_PORT_CM_SUP
| IB_PORT_REINIT_SUP
|
246 IB_PORT_DEVICE_MGMT_SUP
|
247 IB_PORT_VENDOR_CLASS_SUP
|
248 IB_PORT_IP_BASED_GIDS
;
250 /* Max MSG size set to 2G for now */
251 port_attr
->max_msg_sz
= 0x80000000;
252 port_attr
->bad_pkey_cntr
= 0;
253 port_attr
->qkey_viol_cntr
= 0;
254 port_attr
->pkey_tbl_len
= dev_attr
->max_pkey
;
256 port_attr
->sm_lid
= 0;
258 port_attr
->max_vl_num
= 4;
259 port_attr
->sm_sl
= 0;
260 port_attr
->subnet_timeout
= 0;
261 port_attr
->init_type_reply
= 0;
262 port_attr
->active_speed
= rdev
->active_speed
;
263 port_attr
->active_width
= rdev
->active_width
;
268 int bnxt_re_get_port_immutable(struct ib_device
*ibdev
, u8 port_num
,
269 struct ib_port_immutable
*immutable
)
271 struct ib_port_attr port_attr
;
273 if (bnxt_re_query_port(ibdev
, port_num
, &port_attr
))
276 immutable
->pkey_tbl_len
= port_attr
.pkey_tbl_len
;
277 immutable
->gid_tbl_len
= port_attr
.gid_tbl_len
;
278 immutable
->core_cap_flags
= RDMA_CORE_PORT_IBA_ROCE
;
279 immutable
->core_cap_flags
|= RDMA_CORE_CAP_PROT_ROCE_UDP_ENCAP
;
280 immutable
->max_mad_size
= IB_MGMT_MAD_SIZE
;
284 int bnxt_re_query_pkey(struct ib_device
*ibdev
, u8 port_num
,
285 u16 index
, u16
*pkey
)
287 struct bnxt_re_dev
*rdev
= to_bnxt_re_dev(ibdev
, ibdev
);
289 /* Ignore port_num */
291 memset(pkey
, 0, sizeof(*pkey
));
292 return bnxt_qplib_get_pkey(&rdev
->qplib_res
,
293 &rdev
->qplib_res
.pkey_tbl
, index
, pkey
);
296 int bnxt_re_query_gid(struct ib_device
*ibdev
, u8 port_num
,
297 int index
, union ib_gid
*gid
)
299 struct bnxt_re_dev
*rdev
= to_bnxt_re_dev(ibdev
, ibdev
);
302 /* Ignore port_num */
303 memset(gid
, 0, sizeof(*gid
));
304 rc
= bnxt_qplib_get_sgid(&rdev
->qplib_res
,
305 &rdev
->qplib_res
.sgid_tbl
, index
,
306 (struct bnxt_qplib_gid
*)gid
);
310 int bnxt_re_del_gid(struct ib_device
*ibdev
, u8 port_num
,
311 unsigned int index
, void **context
)
314 struct bnxt_re_gid_ctx
*ctx
, **ctx_tbl
;
315 struct bnxt_re_dev
*rdev
= to_bnxt_re_dev(ibdev
, ibdev
);
316 struct bnxt_qplib_sgid_tbl
*sgid_tbl
= &rdev
->qplib_res
.sgid_tbl
;
317 struct bnxt_qplib_gid
*gid_to_del
;
319 /* Delete the entry from the hardware */
324 if (sgid_tbl
&& sgid_tbl
->active
) {
325 if (ctx
->idx
>= sgid_tbl
->max
)
327 gid_to_del
= &sgid_tbl
->tbl
[ctx
->idx
];
328 /* DEL_GID is called in WQ context(netdevice_event_work_handler)
329 * or via the ib_unregister_device path. In the former case QP1
330 * may not be destroyed yet, in which case just return as FW
331 * needs that entry to be present and will fail it's deletion.
332 * We could get invoked again after QP1 is destroyed OR get an
333 * ADD_GID call with a different GID value for the same index
334 * where we issue MODIFY_GID cmd to update the GID entry -- TBD
337 rdma_link_local_addr((struct in6_addr
*)gid_to_del
) &&
338 ctx
->refcnt
== 1 && rdev
->qp1_sqp
) {
339 dev_dbg(rdev_to_dev(rdev
),
340 "Trying to delete GID0 while QP1 is alive\n");
345 rc
= bnxt_qplib_del_sgid(sgid_tbl
, gid_to_del
, true);
347 dev_err(rdev_to_dev(rdev
),
348 "Failed to remove GID: %#x", rc
);
350 ctx_tbl
= sgid_tbl
->ctx
;
351 ctx_tbl
[ctx
->idx
] = NULL
;
361 int bnxt_re_add_gid(struct ib_device
*ibdev
, u8 port_num
,
362 unsigned int index
, const union ib_gid
*gid
,
363 const struct ib_gid_attr
*attr
, void **context
)
367 u16 vlan_id
= 0xFFFF;
368 struct bnxt_re_gid_ctx
*ctx
, **ctx_tbl
;
369 struct bnxt_re_dev
*rdev
= to_bnxt_re_dev(ibdev
, ibdev
);
370 struct bnxt_qplib_sgid_tbl
*sgid_tbl
= &rdev
->qplib_res
.sgid_tbl
;
372 if ((attr
->ndev
) && is_vlan_dev(attr
->ndev
))
373 vlan_id
= vlan_dev_vlan_id(attr
->ndev
);
375 rc
= bnxt_qplib_add_sgid(sgid_tbl
, (struct bnxt_qplib_gid
*)gid
,
376 rdev
->qplib_res
.netdev
->dev_addr
,
377 vlan_id
, true, &tbl_idx
);
378 if (rc
== -EALREADY
) {
379 ctx_tbl
= sgid_tbl
->ctx
;
380 ctx_tbl
[tbl_idx
]->refcnt
++;
381 *context
= ctx_tbl
[tbl_idx
];
386 dev_err(rdev_to_dev(rdev
), "Failed to add GID: %#x", rc
);
390 ctx
= kmalloc(sizeof(*ctx
), GFP_KERNEL
);
393 ctx_tbl
= sgid_tbl
->ctx
;
396 ctx_tbl
[tbl_idx
] = ctx
;
402 enum rdma_link_layer
bnxt_re_get_link_layer(struct ib_device
*ibdev
,
405 return IB_LINK_LAYER_ETHERNET
;
408 #define BNXT_RE_FENCE_PBL_SIZE DIV_ROUND_UP(BNXT_RE_FENCE_BYTES, PAGE_SIZE)
410 static void bnxt_re_create_fence_wqe(struct bnxt_re_pd
*pd
)
412 struct bnxt_re_fence_data
*fence
= &pd
->fence
;
413 struct ib_mr
*ib_mr
= &fence
->mr
->ib_mr
;
414 struct bnxt_qplib_swqe
*wqe
= &fence
->bind_wqe
;
416 memset(wqe
, 0, sizeof(*wqe
));
417 wqe
->type
= BNXT_QPLIB_SWQE_TYPE_BIND_MW
;
418 wqe
->wr_id
= BNXT_QPLIB_FENCE_WRID
;
419 wqe
->flags
|= BNXT_QPLIB_SWQE_FLAGS_SIGNAL_COMP
;
420 wqe
->flags
|= BNXT_QPLIB_SWQE_FLAGS_UC_FENCE
;
421 wqe
->bind
.zero_based
= false;
422 wqe
->bind
.parent_l_key
= ib_mr
->lkey
;
423 wqe
->bind
.va
= (u64
)(unsigned long)fence
->va
;
424 wqe
->bind
.length
= fence
->size
;
425 wqe
->bind
.access_cntl
= __from_ib_access_flags(IB_ACCESS_REMOTE_READ
);
426 wqe
->bind
.mw_type
= SQ_BIND_MW_TYPE_TYPE1
;
428 /* Save the initial rkey in fence structure for now;
429 * wqe->bind.r_key will be set at (re)bind time.
431 fence
->bind_rkey
= ib_inc_rkey(fence
->mw
->rkey
);
434 static int bnxt_re_bind_fence_mw(struct bnxt_qplib_qp
*qplib_qp
)
436 struct bnxt_re_qp
*qp
= container_of(qplib_qp
, struct bnxt_re_qp
,
438 struct ib_pd
*ib_pd
= qp
->ib_qp
.pd
;
439 struct bnxt_re_pd
*pd
= container_of(ib_pd
, struct bnxt_re_pd
, ib_pd
);
440 struct bnxt_re_fence_data
*fence
= &pd
->fence
;
441 struct bnxt_qplib_swqe
*fence_wqe
= &fence
->bind_wqe
;
442 struct bnxt_qplib_swqe wqe
;
445 memcpy(&wqe
, fence_wqe
, sizeof(wqe
));
446 wqe
.bind
.r_key
= fence
->bind_rkey
;
447 fence
->bind_rkey
= ib_inc_rkey(fence
->bind_rkey
);
449 dev_dbg(rdev_to_dev(qp
->rdev
),
450 "Posting bind fence-WQE: rkey: %#x QP: %d PD: %p\n",
451 wqe
.bind
.r_key
, qp
->qplib_qp
.id
, pd
);
452 rc
= bnxt_qplib_post_send(&qp
->qplib_qp
, &wqe
);
454 dev_err(rdev_to_dev(qp
->rdev
), "Failed to bind fence-WQE\n");
457 bnxt_qplib_post_send_db(&qp
->qplib_qp
);
462 static void bnxt_re_destroy_fence_mr(struct bnxt_re_pd
*pd
)
464 struct bnxt_re_fence_data
*fence
= &pd
->fence
;
465 struct bnxt_re_dev
*rdev
= pd
->rdev
;
466 struct device
*dev
= &rdev
->en_dev
->pdev
->dev
;
467 struct bnxt_re_mr
*mr
= fence
->mr
;
470 bnxt_re_dealloc_mw(fence
->mw
);
475 bnxt_qplib_dereg_mrw(&rdev
->qplib_res
, &mr
->qplib_mr
,
478 bnxt_qplib_free_mrw(&rdev
->qplib_res
, &mr
->qplib_mr
);
482 if (fence
->dma_addr
) {
483 dma_unmap_single(dev
, fence
->dma_addr
, BNXT_RE_FENCE_BYTES
,
489 static int bnxt_re_create_fence_mr(struct bnxt_re_pd
*pd
)
491 int mr_access_flags
= IB_ACCESS_LOCAL_WRITE
| IB_ACCESS_MW_BIND
;
492 struct bnxt_re_fence_data
*fence
= &pd
->fence
;
493 struct bnxt_re_dev
*rdev
= pd
->rdev
;
494 struct device
*dev
= &rdev
->en_dev
->pdev
->dev
;
495 struct bnxt_re_mr
*mr
= NULL
;
496 dma_addr_t dma_addr
= 0;
501 dma_addr
= dma_map_single(dev
, fence
->va
, BNXT_RE_FENCE_BYTES
,
503 rc
= dma_mapping_error(dev
, dma_addr
);
505 dev_err(rdev_to_dev(rdev
), "Failed to dma-map fence-MR-mem\n");
510 fence
->dma_addr
= dma_addr
;
513 mr
= kzalloc(sizeof(*mr
), GFP_KERNEL
);
520 mr
->qplib_mr
.pd
= &pd
->qplib_pd
;
521 mr
->qplib_mr
.type
= CMDQ_ALLOCATE_MRW_MRW_FLAGS_PMR
;
522 mr
->qplib_mr
.flags
= __from_ib_access_flags(mr_access_flags
);
523 rc
= bnxt_qplib_alloc_mrw(&rdev
->qplib_res
, &mr
->qplib_mr
);
525 dev_err(rdev_to_dev(rdev
), "Failed to alloc fence-HW-MR\n");
530 mr
->ib_mr
.lkey
= mr
->qplib_mr
.lkey
;
531 mr
->qplib_mr
.va
= (u64
)(unsigned long)fence
->va
;
532 mr
->qplib_mr
.total_size
= BNXT_RE_FENCE_BYTES
;
534 rc
= bnxt_qplib_reg_mr(&rdev
->qplib_res
, &mr
->qplib_mr
, &pbl_tbl
,
535 BNXT_RE_FENCE_PBL_SIZE
, false);
537 dev_err(rdev_to_dev(rdev
), "Failed to register fence-MR\n");
540 mr
->ib_mr
.rkey
= mr
->qplib_mr
.rkey
;
542 /* Create a fence MW only for kernel consumers */
543 mw
= bnxt_re_alloc_mw(&pd
->ib_pd
, IB_MW_TYPE_1
, NULL
);
545 dev_err(rdev_to_dev(rdev
),
546 "Failed to create fence-MW for PD: %p\n", pd
);
552 bnxt_re_create_fence_wqe(pd
);
556 bnxt_re_destroy_fence_mr(pd
);
560 /* Protection Domains */
561 int bnxt_re_dealloc_pd(struct ib_pd
*ib_pd
)
563 struct bnxt_re_pd
*pd
= container_of(ib_pd
, struct bnxt_re_pd
, ib_pd
);
564 struct bnxt_re_dev
*rdev
= pd
->rdev
;
567 bnxt_re_destroy_fence_mr(pd
);
569 if (pd
->qplib_pd
.id
) {
570 rc
= bnxt_qplib_dealloc_pd(&rdev
->qplib_res
,
571 &rdev
->qplib_res
.pd_tbl
,
574 dev_err(rdev_to_dev(rdev
), "Failed to deallocate HW PD");
581 struct ib_pd
*bnxt_re_alloc_pd(struct ib_device
*ibdev
,
582 struct ib_ucontext
*ucontext
,
583 struct ib_udata
*udata
)
585 struct bnxt_re_dev
*rdev
= to_bnxt_re_dev(ibdev
, ibdev
);
586 struct bnxt_re_ucontext
*ucntx
= container_of(ucontext
,
587 struct bnxt_re_ucontext
,
589 struct bnxt_re_pd
*pd
;
592 pd
= kzalloc(sizeof(*pd
), GFP_KERNEL
);
594 return ERR_PTR(-ENOMEM
);
597 if (bnxt_qplib_alloc_pd(&rdev
->qplib_res
.pd_tbl
, &pd
->qplib_pd
)) {
598 dev_err(rdev_to_dev(rdev
), "Failed to allocate HW PD");
604 struct bnxt_re_pd_resp resp
;
606 if (!ucntx
->dpi
.dbr
) {
607 /* Allocate DPI in alloc_pd to avoid failing of
608 * ibv_devinfo and family of application when DPIs
611 if (bnxt_qplib_alloc_dpi(&rdev
->qplib_res
.dpi_tbl
,
612 &ucntx
->dpi
, ucntx
)) {
618 resp
.pdid
= pd
->qplib_pd
.id
;
619 /* Still allow mapping this DBR to the new user PD. */
620 resp
.dpi
= ucntx
->dpi
.dpi
;
621 resp
.dbr
= (u64
)ucntx
->dpi
.umdbr
;
623 rc
= ib_copy_to_udata(udata
, &resp
, sizeof(resp
));
625 dev_err(rdev_to_dev(rdev
),
626 "Failed to copy user response\n");
632 if (bnxt_re_create_fence_mr(pd
))
633 dev_warn(rdev_to_dev(rdev
),
634 "Failed to create Fence-MR\n");
637 (void)bnxt_qplib_dealloc_pd(&rdev
->qplib_res
, &rdev
->qplib_res
.pd_tbl
,
644 /* Address Handles */
645 int bnxt_re_destroy_ah(struct ib_ah
*ib_ah
)
647 struct bnxt_re_ah
*ah
= container_of(ib_ah
, struct bnxt_re_ah
, ib_ah
);
648 struct bnxt_re_dev
*rdev
= ah
->rdev
;
651 rc
= bnxt_qplib_destroy_ah(&rdev
->qplib_res
, &ah
->qplib_ah
);
653 dev_err(rdev_to_dev(rdev
), "Failed to destroy HW AH");
660 struct ib_ah
*bnxt_re_create_ah(struct ib_pd
*ib_pd
,
661 struct rdma_ah_attr
*ah_attr
,
662 struct ib_udata
*udata
)
664 struct bnxt_re_pd
*pd
= container_of(ib_pd
, struct bnxt_re_pd
, ib_pd
);
665 struct bnxt_re_dev
*rdev
= pd
->rdev
;
666 struct bnxt_re_ah
*ah
;
667 const struct ib_global_route
*grh
= rdma_ah_read_grh(ah_attr
);
671 struct ib_gid_attr sgid_attr
;
673 if (!(rdma_ah_get_ah_flags(ah_attr
) & IB_AH_GRH
)) {
674 dev_err(rdev_to_dev(rdev
), "Failed to alloc AH: GRH not set");
675 return ERR_PTR(-EINVAL
);
677 ah
= kzalloc(sizeof(*ah
), GFP_ATOMIC
);
679 return ERR_PTR(-ENOMEM
);
682 ah
->qplib_ah
.pd
= &pd
->qplib_pd
;
684 /* Supply the configuration for the HW */
685 memcpy(ah
->qplib_ah
.dgid
.data
, grh
->dgid
.raw
,
686 sizeof(union ib_gid
));
688 * If RoCE V2 is enabled, stack will have two entries for
689 * each GID entry. Avoiding this duplicte entry in HW. Dividing
690 * the GID index by 2 for RoCE V2
692 ah
->qplib_ah
.sgid_index
= grh
->sgid_index
/ 2;
693 ah
->qplib_ah
.host_sgid_index
= grh
->sgid_index
;
694 ah
->qplib_ah
.traffic_class
= grh
->traffic_class
;
695 ah
->qplib_ah
.flow_label
= grh
->flow_label
;
696 ah
->qplib_ah
.hop_limit
= grh
->hop_limit
;
697 ah
->qplib_ah
.sl
= rdma_ah_get_sl(ah_attr
);
698 if (ib_pd
->uobject
&&
699 !rdma_is_multicast_addr((struct in6_addr
*)
701 !rdma_link_local_addr((struct in6_addr
*)
705 rc
= ib_get_cached_gid(&rdev
->ibdev
, 1,
706 grh
->sgid_index
, &sgid
,
709 dev_err(rdev_to_dev(rdev
),
710 "Failed to query gid at index %d",
715 dev_put(sgid_attr
.ndev
);
716 /* Get network header type for this GID */
717 nw_type
= ib_gid_to_network_type(sgid_attr
.gid_type
, &sgid
);
719 case RDMA_NETWORK_IPV4
:
720 ah
->qplib_ah
.nw_type
= CMDQ_CREATE_AH_TYPE_V2IPV4
;
722 case RDMA_NETWORK_IPV6
:
723 ah
->qplib_ah
.nw_type
= CMDQ_CREATE_AH_TYPE_V2IPV6
;
726 ah
->qplib_ah
.nw_type
= CMDQ_CREATE_AH_TYPE_V1
;
731 memcpy(ah
->qplib_ah
.dmac
, ah_attr
->roce
.dmac
, ETH_ALEN
);
732 rc
= bnxt_qplib_create_ah(&rdev
->qplib_res
, &ah
->qplib_ah
);
734 dev_err(rdev_to_dev(rdev
), "Failed to allocate HW AH");
738 /* Write AVID to shared page. */
739 if (ib_pd
->uobject
) {
740 struct ib_ucontext
*ib_uctx
= ib_pd
->uobject
->context
;
741 struct bnxt_re_ucontext
*uctx
;
745 uctx
= container_of(ib_uctx
, struct bnxt_re_ucontext
, ib_uctx
);
746 spin_lock_irqsave(&uctx
->sh_lock
, flag
);
747 wrptr
= (u32
*)(uctx
->shpg
+ BNXT_RE_AVID_OFFT
);
748 *wrptr
= ah
->qplib_ah
.id
;
749 wmb(); /* make sure cache is updated. */
750 spin_unlock_irqrestore(&uctx
->sh_lock
, flag
);
760 int bnxt_re_modify_ah(struct ib_ah
*ib_ah
, struct rdma_ah_attr
*ah_attr
)
765 int bnxt_re_query_ah(struct ib_ah
*ib_ah
, struct rdma_ah_attr
*ah_attr
)
767 struct bnxt_re_ah
*ah
= container_of(ib_ah
, struct bnxt_re_ah
, ib_ah
);
769 ah_attr
->type
= ib_ah
->type
;
770 rdma_ah_set_sl(ah_attr
, ah
->qplib_ah
.sl
);
771 memcpy(ah_attr
->roce
.dmac
, ah
->qplib_ah
.dmac
, ETH_ALEN
);
772 rdma_ah_set_grh(ah_attr
, NULL
, 0,
773 ah
->qplib_ah
.host_sgid_index
,
774 0, ah
->qplib_ah
.traffic_class
);
775 rdma_ah_set_dgid_raw(ah_attr
, ah
->qplib_ah
.dgid
.data
);
776 rdma_ah_set_port_num(ah_attr
, 1);
777 rdma_ah_set_static_rate(ah_attr
, 0);
782 int bnxt_re_destroy_qp(struct ib_qp
*ib_qp
)
784 struct bnxt_re_qp
*qp
= container_of(ib_qp
, struct bnxt_re_qp
, ib_qp
);
785 struct bnxt_re_dev
*rdev
= qp
->rdev
;
788 bnxt_qplib_flush_cqn_wq(&qp
->qplib_qp
);
789 bnxt_qplib_del_flush_qp(&qp
->qplib_qp
);
790 rc
= bnxt_qplib_destroy_qp(&rdev
->qplib_res
, &qp
->qplib_qp
);
792 dev_err(rdev_to_dev(rdev
), "Failed to destroy HW QP");
795 if (ib_qp
->qp_type
== IB_QPT_GSI
&& rdev
->qp1_sqp
) {
796 rc
= bnxt_qplib_destroy_ah(&rdev
->qplib_res
,
797 &rdev
->sqp_ah
->qplib_ah
);
799 dev_err(rdev_to_dev(rdev
),
800 "Failed to destroy HW AH for shadow QP");
804 bnxt_qplib_del_flush_qp(&qp
->qplib_qp
);
805 rc
= bnxt_qplib_destroy_qp(&rdev
->qplib_res
,
806 &rdev
->qp1_sqp
->qplib_qp
);
808 dev_err(rdev_to_dev(rdev
),
809 "Failed to destroy Shadow QP");
812 mutex_lock(&rdev
->qp_lock
);
813 list_del(&rdev
->qp1_sqp
->list
);
814 atomic_dec(&rdev
->qp_count
);
815 mutex_unlock(&rdev
->qp_lock
);
818 kfree(rdev
->qp1_sqp
);
819 rdev
->qp1_sqp
= NULL
;
823 if (!IS_ERR_OR_NULL(qp
->rumem
))
824 ib_umem_release(qp
->rumem
);
825 if (!IS_ERR_OR_NULL(qp
->sumem
))
826 ib_umem_release(qp
->sumem
);
828 mutex_lock(&rdev
->qp_lock
);
830 atomic_dec(&rdev
->qp_count
);
831 mutex_unlock(&rdev
->qp_lock
);
836 static u8
__from_ib_qp_type(enum ib_qp_type type
)
840 return CMDQ_CREATE_QP1_TYPE_GSI
;
842 return CMDQ_CREATE_QP_TYPE_RC
;
844 return CMDQ_CREATE_QP_TYPE_UD
;
850 static int bnxt_re_init_user_qp(struct bnxt_re_dev
*rdev
, struct bnxt_re_pd
*pd
,
851 struct bnxt_re_qp
*qp
, struct ib_udata
*udata
)
853 struct bnxt_re_qp_req ureq
;
854 struct bnxt_qplib_qp
*qplib_qp
= &qp
->qplib_qp
;
855 struct ib_umem
*umem
;
857 struct ib_ucontext
*context
= pd
->ib_pd
.uobject
->context
;
858 struct bnxt_re_ucontext
*cntx
= container_of(context
,
859 struct bnxt_re_ucontext
,
861 if (ib_copy_from_udata(&ureq
, udata
, sizeof(ureq
)))
864 bytes
= (qplib_qp
->sq
.max_wqe
* BNXT_QPLIB_MAX_SQE_ENTRY_SIZE
);
865 /* Consider mapping PSN search memory only for RC QPs. */
866 if (qplib_qp
->type
== CMDQ_CREATE_QP_TYPE_RC
)
867 bytes
+= (qplib_qp
->sq
.max_wqe
* sizeof(struct sq_psn_search
));
868 bytes
= PAGE_ALIGN(bytes
);
869 umem
= ib_umem_get(context
, ureq
.qpsva
, bytes
,
870 IB_ACCESS_LOCAL_WRITE
, 1);
872 return PTR_ERR(umem
);
875 qplib_qp
->sq
.sglist
= umem
->sg_head
.sgl
;
876 qplib_qp
->sq
.nmap
= umem
->nmap
;
877 qplib_qp
->qp_handle
= ureq
.qp_handle
;
879 if (!qp
->qplib_qp
.srq
) {
880 bytes
= (qplib_qp
->rq
.max_wqe
* BNXT_QPLIB_MAX_RQE_ENTRY_SIZE
);
881 bytes
= PAGE_ALIGN(bytes
);
882 umem
= ib_umem_get(context
, ureq
.qprva
, bytes
,
883 IB_ACCESS_LOCAL_WRITE
, 1);
887 qplib_qp
->rq
.sglist
= umem
->sg_head
.sgl
;
888 qplib_qp
->rq
.nmap
= umem
->nmap
;
891 qplib_qp
->dpi
= &cntx
->dpi
;
894 ib_umem_release(qp
->sumem
);
896 qplib_qp
->sq
.sglist
= NULL
;
897 qplib_qp
->sq
.nmap
= 0;
899 return PTR_ERR(umem
);
902 static struct bnxt_re_ah
*bnxt_re_create_shadow_qp_ah
903 (struct bnxt_re_pd
*pd
,
904 struct bnxt_qplib_res
*qp1_res
,
905 struct bnxt_qplib_qp
*qp1_qp
)
907 struct bnxt_re_dev
*rdev
= pd
->rdev
;
908 struct bnxt_re_ah
*ah
;
912 ah
= kzalloc(sizeof(*ah
), GFP_KERNEL
);
917 ah
->qplib_ah
.pd
= &pd
->qplib_pd
;
919 rc
= bnxt_re_query_gid(&rdev
->ibdev
, 1, 0, &sgid
);
923 /* supply the dgid data same as sgid */
924 memcpy(ah
->qplib_ah
.dgid
.data
, &sgid
.raw
,
925 sizeof(union ib_gid
));
926 ah
->qplib_ah
.sgid_index
= 0;
928 ah
->qplib_ah
.traffic_class
= 0;
929 ah
->qplib_ah
.flow_label
= 0;
930 ah
->qplib_ah
.hop_limit
= 1;
932 /* Have DMAC same as SMAC */
933 ether_addr_copy(ah
->qplib_ah
.dmac
, rdev
->netdev
->dev_addr
);
935 rc
= bnxt_qplib_create_ah(&rdev
->qplib_res
, &ah
->qplib_ah
);
937 dev_err(rdev_to_dev(rdev
),
938 "Failed to allocate HW AH for Shadow QP");
949 static struct bnxt_re_qp
*bnxt_re_create_shadow_qp
950 (struct bnxt_re_pd
*pd
,
951 struct bnxt_qplib_res
*qp1_res
,
952 struct bnxt_qplib_qp
*qp1_qp
)
954 struct bnxt_re_dev
*rdev
= pd
->rdev
;
955 struct bnxt_re_qp
*qp
;
958 qp
= kzalloc(sizeof(*qp
), GFP_KERNEL
);
964 /* Initialize the shadow QP structure from the QP1 values */
965 ether_addr_copy(qp
->qplib_qp
.smac
, rdev
->netdev
->dev_addr
);
967 qp
->qplib_qp
.pd
= &pd
->qplib_pd
;
968 qp
->qplib_qp
.qp_handle
= (u64
)(unsigned long)(&qp
->qplib_qp
);
969 qp
->qplib_qp
.type
= IB_QPT_UD
;
971 qp
->qplib_qp
.max_inline_data
= 0;
972 qp
->qplib_qp
.sig_type
= true;
974 /* Shadow QP SQ depth should be same as QP1 RQ depth */
975 qp
->qplib_qp
.sq
.max_wqe
= qp1_qp
->rq
.max_wqe
;
976 qp
->qplib_qp
.sq
.max_sge
= 2;
977 /* Q full delta can be 1 since it is internal QP */
978 qp
->qplib_qp
.sq
.q_full_delta
= 1;
980 qp
->qplib_qp
.scq
= qp1_qp
->scq
;
981 qp
->qplib_qp
.rcq
= qp1_qp
->rcq
;
983 qp
->qplib_qp
.rq
.max_wqe
= qp1_qp
->rq
.max_wqe
;
984 qp
->qplib_qp
.rq
.max_sge
= qp1_qp
->rq
.max_sge
;
985 /* Q full delta can be 1 since it is internal QP */
986 qp
->qplib_qp
.rq
.q_full_delta
= 1;
988 qp
->qplib_qp
.mtu
= qp1_qp
->mtu
;
990 qp
->qplib_qp
.sq_hdr_buf_size
= 0;
991 qp
->qplib_qp
.rq_hdr_buf_size
= BNXT_QPLIB_MAX_GRH_HDR_SIZE_IPV6
;
992 qp
->qplib_qp
.dpi
= &rdev
->dpi_privileged
;
994 rc
= bnxt_qplib_create_qp(qp1_res
, &qp
->qplib_qp
);
998 rdev
->sqp_id
= qp
->qplib_qp
.id
;
1000 spin_lock_init(&qp
->sq_lock
);
1001 INIT_LIST_HEAD(&qp
->list
);
1002 mutex_lock(&rdev
->qp_lock
);
1003 list_add_tail(&qp
->list
, &rdev
->qp_list
);
1004 atomic_inc(&rdev
->qp_count
);
1005 mutex_unlock(&rdev
->qp_lock
);
1012 struct ib_qp
*bnxt_re_create_qp(struct ib_pd
*ib_pd
,
1013 struct ib_qp_init_attr
*qp_init_attr
,
1014 struct ib_udata
*udata
)
1016 struct bnxt_re_pd
*pd
= container_of(ib_pd
, struct bnxt_re_pd
, ib_pd
);
1017 struct bnxt_re_dev
*rdev
= pd
->rdev
;
1018 struct bnxt_qplib_dev_attr
*dev_attr
= &rdev
->dev_attr
;
1019 struct bnxt_re_qp
*qp
;
1020 struct bnxt_re_cq
*cq
;
1023 if ((qp_init_attr
->cap
.max_send_wr
> dev_attr
->max_qp_wqes
) ||
1024 (qp_init_attr
->cap
.max_recv_wr
> dev_attr
->max_qp_wqes
) ||
1025 (qp_init_attr
->cap
.max_send_sge
> dev_attr
->max_qp_sges
) ||
1026 (qp_init_attr
->cap
.max_recv_sge
> dev_attr
->max_qp_sges
) ||
1027 (qp_init_attr
->cap
.max_inline_data
> dev_attr
->max_inline_data
))
1028 return ERR_PTR(-EINVAL
);
1030 qp
= kzalloc(sizeof(*qp
), GFP_KERNEL
);
1032 return ERR_PTR(-ENOMEM
);
1035 ether_addr_copy(qp
->qplib_qp
.smac
, rdev
->netdev
->dev_addr
);
1036 qp
->qplib_qp
.pd
= &pd
->qplib_pd
;
1037 qp
->qplib_qp
.qp_handle
= (u64
)(unsigned long)(&qp
->qplib_qp
);
1038 qp
->qplib_qp
.type
= __from_ib_qp_type(qp_init_attr
->qp_type
);
1039 if (qp
->qplib_qp
.type
== IB_QPT_MAX
) {
1040 dev_err(rdev_to_dev(rdev
), "QP type 0x%x not supported",
1045 qp
->qplib_qp
.max_inline_data
= qp_init_attr
->cap
.max_inline_data
;
1046 qp
->qplib_qp
.sig_type
= ((qp_init_attr
->sq_sig_type
==
1047 IB_SIGNAL_ALL_WR
) ? true : false);
1049 qp
->qplib_qp
.sq
.max_sge
= qp_init_attr
->cap
.max_send_sge
;
1050 if (qp
->qplib_qp
.sq
.max_sge
> dev_attr
->max_qp_sges
)
1051 qp
->qplib_qp
.sq
.max_sge
= dev_attr
->max_qp_sges
;
1053 if (qp_init_attr
->send_cq
) {
1054 cq
= container_of(qp_init_attr
->send_cq
, struct bnxt_re_cq
,
1057 dev_err(rdev_to_dev(rdev
), "Send CQ not found");
1061 qp
->qplib_qp
.scq
= &cq
->qplib_cq
;
1064 if (qp_init_attr
->recv_cq
) {
1065 cq
= container_of(qp_init_attr
->recv_cq
, struct bnxt_re_cq
,
1068 dev_err(rdev_to_dev(rdev
), "Receive CQ not found");
1072 qp
->qplib_qp
.rcq
= &cq
->qplib_cq
;
1075 if (qp_init_attr
->srq
) {
1076 dev_err(rdev_to_dev(rdev
), "SRQ not supported");
1080 /* Allocate 1 more than what's provided so posting max doesn't
1083 entries
= roundup_pow_of_two(qp_init_attr
->cap
.max_recv_wr
+ 1);
1084 qp
->qplib_qp
.rq
.max_wqe
= min_t(u32
, entries
,
1085 dev_attr
->max_qp_wqes
+ 1);
1087 qp
->qplib_qp
.rq
.q_full_delta
= qp
->qplib_qp
.rq
.max_wqe
-
1088 qp_init_attr
->cap
.max_recv_wr
;
1090 qp
->qplib_qp
.rq
.max_sge
= qp_init_attr
->cap
.max_recv_sge
;
1091 if (qp
->qplib_qp
.rq
.max_sge
> dev_attr
->max_qp_sges
)
1092 qp
->qplib_qp
.rq
.max_sge
= dev_attr
->max_qp_sges
;
1095 qp
->qplib_qp
.mtu
= ib_mtu_enum_to_int(iboe_get_mtu(rdev
->netdev
->mtu
));
1097 if (qp_init_attr
->qp_type
== IB_QPT_GSI
) {
1098 /* Allocate 1 more than what's provided */
1099 entries
= roundup_pow_of_two(qp_init_attr
->cap
.max_send_wr
+ 1);
1100 qp
->qplib_qp
.sq
.max_wqe
= min_t(u32
, entries
,
1101 dev_attr
->max_qp_wqes
+ 1);
1102 qp
->qplib_qp
.sq
.q_full_delta
= qp
->qplib_qp
.sq
.max_wqe
-
1103 qp_init_attr
->cap
.max_send_wr
;
1104 qp
->qplib_qp
.rq
.max_sge
= dev_attr
->max_qp_sges
;
1105 if (qp
->qplib_qp
.rq
.max_sge
> dev_attr
->max_qp_sges
)
1106 qp
->qplib_qp
.rq
.max_sge
= dev_attr
->max_qp_sges
;
1107 qp
->qplib_qp
.sq
.max_sge
++;
1108 if (qp
->qplib_qp
.sq
.max_sge
> dev_attr
->max_qp_sges
)
1109 qp
->qplib_qp
.sq
.max_sge
= dev_attr
->max_qp_sges
;
1111 qp
->qplib_qp
.rq_hdr_buf_size
=
1112 BNXT_QPLIB_MAX_QP1_RQ_HDR_SIZE_V2
;
1114 qp
->qplib_qp
.sq_hdr_buf_size
=
1115 BNXT_QPLIB_MAX_QP1_SQ_HDR_SIZE_V2
;
1116 qp
->qplib_qp
.dpi
= &rdev
->dpi_privileged
;
1117 rc
= bnxt_qplib_create_qp1(&rdev
->qplib_res
, &qp
->qplib_qp
);
1119 dev_err(rdev_to_dev(rdev
), "Failed to create HW QP1");
1122 /* Create a shadow QP to handle the QP1 traffic */
1123 rdev
->qp1_sqp
= bnxt_re_create_shadow_qp(pd
, &rdev
->qplib_res
,
1125 if (!rdev
->qp1_sqp
) {
1127 dev_err(rdev_to_dev(rdev
),
1128 "Failed to create Shadow QP for QP1");
1131 rdev
->sqp_ah
= bnxt_re_create_shadow_qp_ah(pd
, &rdev
->qplib_res
,
1133 if (!rdev
->sqp_ah
) {
1134 bnxt_qplib_destroy_qp(&rdev
->qplib_res
,
1135 &rdev
->qp1_sqp
->qplib_qp
);
1137 dev_err(rdev_to_dev(rdev
),
1138 "Failed to create AH entry for ShadowQP");
1143 /* Allocate 128 + 1 more than what's provided */
1144 entries
= roundup_pow_of_two(qp_init_attr
->cap
.max_send_wr
+
1145 BNXT_QPLIB_RESERVED_QP_WRS
+ 1);
1146 qp
->qplib_qp
.sq
.max_wqe
= min_t(u32
, entries
,
1147 dev_attr
->max_qp_wqes
+
1148 BNXT_QPLIB_RESERVED_QP_WRS
+ 1);
1149 qp
->qplib_qp
.sq
.q_full_delta
= BNXT_QPLIB_RESERVED_QP_WRS
+ 1;
1152 * Reserving one slot for Phantom WQE. Application can
1153 * post one extra entry in this case. But allowing this to avoid
1154 * unexpected Queue full condition
1157 qp
->qplib_qp
.sq
.q_full_delta
-= 1;
1159 qp
->qplib_qp
.max_rd_atomic
= dev_attr
->max_qp_rd_atom
;
1160 qp
->qplib_qp
.max_dest_rd_atomic
= dev_attr
->max_qp_init_rd_atom
;
1162 rc
= bnxt_re_init_user_qp(rdev
, pd
, qp
, udata
);
1166 qp
->qplib_qp
.dpi
= &rdev
->dpi_privileged
;
1169 rc
= bnxt_qplib_create_qp(&rdev
->qplib_res
, &qp
->qplib_qp
);
1171 dev_err(rdev_to_dev(rdev
), "Failed to create HW QP");
1176 qp
->ib_qp
.qp_num
= qp
->qplib_qp
.id
;
1177 spin_lock_init(&qp
->sq_lock
);
1178 spin_lock_init(&qp
->rq_lock
);
1181 struct bnxt_re_qp_resp resp
;
1183 resp
.qpid
= qp
->ib_qp
.qp_num
;
1185 rc
= ib_copy_to_udata(udata
, &resp
, sizeof(resp
));
1187 dev_err(rdev_to_dev(rdev
), "Failed to copy QP udata");
1191 INIT_LIST_HEAD(&qp
->list
);
1192 mutex_lock(&rdev
->qp_lock
);
1193 list_add_tail(&qp
->list
, &rdev
->qp_list
);
1194 atomic_inc(&rdev
->qp_count
);
1195 mutex_unlock(&rdev
->qp_lock
);
1199 bnxt_qplib_destroy_qp(&rdev
->qplib_res
, &qp
->qplib_qp
);
1203 ib_umem_release(qp
->rumem
);
1205 ib_umem_release(qp
->sumem
);
1212 static u8
__from_ib_qp_state(enum ib_qp_state state
)
1216 return CMDQ_MODIFY_QP_NEW_STATE_RESET
;
1218 return CMDQ_MODIFY_QP_NEW_STATE_INIT
;
1220 return CMDQ_MODIFY_QP_NEW_STATE_RTR
;
1222 return CMDQ_MODIFY_QP_NEW_STATE_RTS
;
1224 return CMDQ_MODIFY_QP_NEW_STATE_SQD
;
1226 return CMDQ_MODIFY_QP_NEW_STATE_SQE
;
1229 return CMDQ_MODIFY_QP_NEW_STATE_ERR
;
1233 static enum ib_qp_state
__to_ib_qp_state(u8 state
)
1236 case CMDQ_MODIFY_QP_NEW_STATE_RESET
:
1237 return IB_QPS_RESET
;
1238 case CMDQ_MODIFY_QP_NEW_STATE_INIT
:
1240 case CMDQ_MODIFY_QP_NEW_STATE_RTR
:
1242 case CMDQ_MODIFY_QP_NEW_STATE_RTS
:
1244 case CMDQ_MODIFY_QP_NEW_STATE_SQD
:
1246 case CMDQ_MODIFY_QP_NEW_STATE_SQE
:
1248 case CMDQ_MODIFY_QP_NEW_STATE_ERR
:
1254 static u32
__from_ib_mtu(enum ib_mtu mtu
)
1258 return CMDQ_MODIFY_QP_PATH_MTU_MTU_256
;
1260 return CMDQ_MODIFY_QP_PATH_MTU_MTU_512
;
1262 return CMDQ_MODIFY_QP_PATH_MTU_MTU_1024
;
1264 return CMDQ_MODIFY_QP_PATH_MTU_MTU_2048
;
1266 return CMDQ_MODIFY_QP_PATH_MTU_MTU_4096
;
1268 return CMDQ_MODIFY_QP_PATH_MTU_MTU_2048
;
1272 static enum ib_mtu
__to_ib_mtu(u32 mtu
)
1274 switch (mtu
& CREQ_QUERY_QP_RESP_SB_PATH_MTU_MASK
) {
1275 case CMDQ_MODIFY_QP_PATH_MTU_MTU_256
:
1277 case CMDQ_MODIFY_QP_PATH_MTU_MTU_512
:
1279 case CMDQ_MODIFY_QP_PATH_MTU_MTU_1024
:
1281 case CMDQ_MODIFY_QP_PATH_MTU_MTU_2048
:
1283 case CMDQ_MODIFY_QP_PATH_MTU_MTU_4096
:
1290 static int bnxt_re_modify_shadow_qp(struct bnxt_re_dev
*rdev
,
1291 struct bnxt_re_qp
*qp1_qp
,
1294 struct bnxt_re_qp
*qp
= rdev
->qp1_sqp
;
1297 if (qp_attr_mask
& IB_QP_STATE
) {
1298 qp
->qplib_qp
.modify_flags
|= CMDQ_MODIFY_QP_MODIFY_MASK_STATE
;
1299 qp
->qplib_qp
.state
= qp1_qp
->qplib_qp
.state
;
1301 if (qp_attr_mask
& IB_QP_PKEY_INDEX
) {
1302 qp
->qplib_qp
.modify_flags
|= CMDQ_MODIFY_QP_MODIFY_MASK_PKEY
;
1303 qp
->qplib_qp
.pkey_index
= qp1_qp
->qplib_qp
.pkey_index
;
1306 if (qp_attr_mask
& IB_QP_QKEY
) {
1307 qp
->qplib_qp
.modify_flags
|= CMDQ_MODIFY_QP_MODIFY_MASK_QKEY
;
1308 /* Using a Random QKEY */
1309 qp
->qplib_qp
.qkey
= 0x81818181;
1311 if (qp_attr_mask
& IB_QP_SQ_PSN
) {
1312 qp
->qplib_qp
.modify_flags
|= CMDQ_MODIFY_QP_MODIFY_MASK_SQ_PSN
;
1313 qp
->qplib_qp
.sq
.psn
= qp1_qp
->qplib_qp
.sq
.psn
;
1316 rc
= bnxt_qplib_modify_qp(&rdev
->qplib_res
, &qp
->qplib_qp
);
1318 dev_err(rdev_to_dev(rdev
),
1319 "Failed to modify Shadow QP for QP1");
1323 int bnxt_re_modify_qp(struct ib_qp
*ib_qp
, struct ib_qp_attr
*qp_attr
,
1324 int qp_attr_mask
, struct ib_udata
*udata
)
1326 struct bnxt_re_qp
*qp
= container_of(ib_qp
, struct bnxt_re_qp
, ib_qp
);
1327 struct bnxt_re_dev
*rdev
= qp
->rdev
;
1328 struct bnxt_qplib_dev_attr
*dev_attr
= &rdev
->dev_attr
;
1329 enum ib_qp_state curr_qp_state
, new_qp_state
;
1333 struct ib_gid_attr sgid_attr
;
1336 qp
->qplib_qp
.modify_flags
= 0;
1337 if (qp_attr_mask
& IB_QP_STATE
) {
1338 curr_qp_state
= __to_ib_qp_state(qp
->qplib_qp
.cur_qp_state
);
1339 new_qp_state
= qp_attr
->qp_state
;
1340 if (!ib_modify_qp_is_ok(curr_qp_state
, new_qp_state
,
1341 ib_qp
->qp_type
, qp_attr_mask
,
1342 IB_LINK_LAYER_ETHERNET
)) {
1343 dev_err(rdev_to_dev(rdev
),
1344 "Invalid attribute mask: %#x specified ",
1346 dev_err(rdev_to_dev(rdev
),
1347 "for qpn: %#x type: %#x",
1348 ib_qp
->qp_num
, ib_qp
->qp_type
);
1349 dev_err(rdev_to_dev(rdev
),
1350 "curr_qp_state=0x%x, new_qp_state=0x%x\n",
1351 curr_qp_state
, new_qp_state
);
1354 qp
->qplib_qp
.modify_flags
|= CMDQ_MODIFY_QP_MODIFY_MASK_STATE
;
1355 qp
->qplib_qp
.state
= __from_ib_qp_state(qp_attr
->qp_state
);
1358 qp
->qplib_qp
.state
== CMDQ_MODIFY_QP_NEW_STATE_ERR
) {
1359 dev_dbg(rdev_to_dev(rdev
),
1360 "Move QP = %p to flush list\n",
1362 bnxt_qplib_add_flush_qp(&qp
->qplib_qp
);
1365 qp
->qplib_qp
.state
== CMDQ_MODIFY_QP_NEW_STATE_RESET
) {
1366 dev_dbg(rdev_to_dev(rdev
),
1367 "Move QP = %p out of flush list\n",
1369 bnxt_qplib_del_flush_qp(&qp
->qplib_qp
);
1372 if (qp_attr_mask
& IB_QP_EN_SQD_ASYNC_NOTIFY
) {
1373 qp
->qplib_qp
.modify_flags
|=
1374 CMDQ_MODIFY_QP_MODIFY_MASK_EN_SQD_ASYNC_NOTIFY
;
1375 qp
->qplib_qp
.en_sqd_async_notify
= true;
1377 if (qp_attr_mask
& IB_QP_ACCESS_FLAGS
) {
1378 qp
->qplib_qp
.modify_flags
|= CMDQ_MODIFY_QP_MODIFY_MASK_ACCESS
;
1379 qp
->qplib_qp
.access
=
1380 __from_ib_access_flags(qp_attr
->qp_access_flags
);
1381 /* LOCAL_WRITE access must be set to allow RC receive */
1382 qp
->qplib_qp
.access
|= BNXT_QPLIB_ACCESS_LOCAL_WRITE
;
1384 if (qp_attr_mask
& IB_QP_PKEY_INDEX
) {
1385 qp
->qplib_qp
.modify_flags
|= CMDQ_MODIFY_QP_MODIFY_MASK_PKEY
;
1386 qp
->qplib_qp
.pkey_index
= qp_attr
->pkey_index
;
1388 if (qp_attr_mask
& IB_QP_QKEY
) {
1389 qp
->qplib_qp
.modify_flags
|= CMDQ_MODIFY_QP_MODIFY_MASK_QKEY
;
1390 qp
->qplib_qp
.qkey
= qp_attr
->qkey
;
1392 if (qp_attr_mask
& IB_QP_AV
) {
1393 const struct ib_global_route
*grh
=
1394 rdma_ah_read_grh(&qp_attr
->ah_attr
);
1396 qp
->qplib_qp
.modify_flags
|= CMDQ_MODIFY_QP_MODIFY_MASK_DGID
|
1397 CMDQ_MODIFY_QP_MODIFY_MASK_FLOW_LABEL
|
1398 CMDQ_MODIFY_QP_MODIFY_MASK_SGID_INDEX
|
1399 CMDQ_MODIFY_QP_MODIFY_MASK_HOP_LIMIT
|
1400 CMDQ_MODIFY_QP_MODIFY_MASK_TRAFFIC_CLASS
|
1401 CMDQ_MODIFY_QP_MODIFY_MASK_DEST_MAC
|
1402 CMDQ_MODIFY_QP_MODIFY_MASK_VLAN_ID
;
1403 memcpy(qp
->qplib_qp
.ah
.dgid
.data
, grh
->dgid
.raw
,
1404 sizeof(qp
->qplib_qp
.ah
.dgid
.data
));
1405 qp
->qplib_qp
.ah
.flow_label
= grh
->flow_label
;
1406 /* If RoCE V2 is enabled, stack will have two entries for
1407 * each GID entry. Avoiding this duplicte entry in HW. Dividing
1408 * the GID index by 2 for RoCE V2
1410 qp
->qplib_qp
.ah
.sgid_index
= grh
->sgid_index
/ 2;
1411 qp
->qplib_qp
.ah
.host_sgid_index
= grh
->sgid_index
;
1412 qp
->qplib_qp
.ah
.hop_limit
= grh
->hop_limit
;
1413 qp
->qplib_qp
.ah
.traffic_class
= grh
->traffic_class
;
1414 qp
->qplib_qp
.ah
.sl
= rdma_ah_get_sl(&qp_attr
->ah_attr
);
1415 ether_addr_copy(qp
->qplib_qp
.ah
.dmac
,
1416 qp_attr
->ah_attr
.roce
.dmac
);
1418 status
= ib_get_cached_gid(&rdev
->ibdev
, 1,
1421 if (!status
&& sgid_attr
.ndev
) {
1422 memcpy(qp
->qplib_qp
.smac
, sgid_attr
.ndev
->dev_addr
,
1424 dev_put(sgid_attr
.ndev
);
1425 nw_type
= ib_gid_to_network_type(sgid_attr
.gid_type
,
1428 case RDMA_NETWORK_IPV4
:
1429 qp
->qplib_qp
.nw_type
=
1430 CMDQ_MODIFY_QP_NETWORK_TYPE_ROCEV2_IPV4
;
1432 case RDMA_NETWORK_IPV6
:
1433 qp
->qplib_qp
.nw_type
=
1434 CMDQ_MODIFY_QP_NETWORK_TYPE_ROCEV2_IPV6
;
1437 qp
->qplib_qp
.nw_type
=
1438 CMDQ_MODIFY_QP_NETWORK_TYPE_ROCEV1
;
1444 if (qp_attr_mask
& IB_QP_PATH_MTU
) {
1445 qp
->qplib_qp
.modify_flags
|=
1446 CMDQ_MODIFY_QP_MODIFY_MASK_PATH_MTU
;
1447 qp
->qplib_qp
.path_mtu
= __from_ib_mtu(qp_attr
->path_mtu
);
1448 qp
->qplib_qp
.mtu
= ib_mtu_enum_to_int(qp_attr
->path_mtu
);
1449 } else if (qp_attr
->qp_state
== IB_QPS_RTR
) {
1450 qp
->qplib_qp
.modify_flags
|=
1451 CMDQ_MODIFY_QP_MODIFY_MASK_PATH_MTU
;
1452 qp
->qplib_qp
.path_mtu
=
1453 __from_ib_mtu(iboe_get_mtu(rdev
->netdev
->mtu
));
1455 ib_mtu_enum_to_int(iboe_get_mtu(rdev
->netdev
->mtu
));
1458 if (qp_attr_mask
& IB_QP_TIMEOUT
) {
1459 qp
->qplib_qp
.modify_flags
|= CMDQ_MODIFY_QP_MODIFY_MASK_TIMEOUT
;
1460 qp
->qplib_qp
.timeout
= qp_attr
->timeout
;
1462 if (qp_attr_mask
& IB_QP_RETRY_CNT
) {
1463 qp
->qplib_qp
.modify_flags
|=
1464 CMDQ_MODIFY_QP_MODIFY_MASK_RETRY_CNT
;
1465 qp
->qplib_qp
.retry_cnt
= qp_attr
->retry_cnt
;
1467 if (qp_attr_mask
& IB_QP_RNR_RETRY
) {
1468 qp
->qplib_qp
.modify_flags
|=
1469 CMDQ_MODIFY_QP_MODIFY_MASK_RNR_RETRY
;
1470 qp
->qplib_qp
.rnr_retry
= qp_attr
->rnr_retry
;
1472 if (qp_attr_mask
& IB_QP_MIN_RNR_TIMER
) {
1473 qp
->qplib_qp
.modify_flags
|=
1474 CMDQ_MODIFY_QP_MODIFY_MASK_MIN_RNR_TIMER
;
1475 qp
->qplib_qp
.min_rnr_timer
= qp_attr
->min_rnr_timer
;
1477 if (qp_attr_mask
& IB_QP_RQ_PSN
) {
1478 qp
->qplib_qp
.modify_flags
|= CMDQ_MODIFY_QP_MODIFY_MASK_RQ_PSN
;
1479 qp
->qplib_qp
.rq
.psn
= qp_attr
->rq_psn
;
1481 if (qp_attr_mask
& IB_QP_MAX_QP_RD_ATOMIC
) {
1482 qp
->qplib_qp
.modify_flags
|=
1483 CMDQ_MODIFY_QP_MODIFY_MASK_MAX_RD_ATOMIC
;
1484 /* Cap the max_rd_atomic to device max */
1485 qp
->qplib_qp
.max_rd_atomic
= min_t(u32
, qp_attr
->max_rd_atomic
,
1486 dev_attr
->max_qp_rd_atom
);
1488 if (qp_attr_mask
& IB_QP_SQ_PSN
) {
1489 qp
->qplib_qp
.modify_flags
|= CMDQ_MODIFY_QP_MODIFY_MASK_SQ_PSN
;
1490 qp
->qplib_qp
.sq
.psn
= qp_attr
->sq_psn
;
1492 if (qp_attr_mask
& IB_QP_MAX_DEST_RD_ATOMIC
) {
1493 if (qp_attr
->max_dest_rd_atomic
>
1494 dev_attr
->max_qp_init_rd_atom
) {
1495 dev_err(rdev_to_dev(rdev
),
1496 "max_dest_rd_atomic requested%d is > dev_max%d",
1497 qp_attr
->max_dest_rd_atomic
,
1498 dev_attr
->max_qp_init_rd_atom
);
1502 qp
->qplib_qp
.modify_flags
|=
1503 CMDQ_MODIFY_QP_MODIFY_MASK_MAX_DEST_RD_ATOMIC
;
1504 qp
->qplib_qp
.max_dest_rd_atomic
= qp_attr
->max_dest_rd_atomic
;
1506 if (qp_attr_mask
& IB_QP_CAP
) {
1507 qp
->qplib_qp
.modify_flags
|=
1508 CMDQ_MODIFY_QP_MODIFY_MASK_SQ_SIZE
|
1509 CMDQ_MODIFY_QP_MODIFY_MASK_RQ_SIZE
|
1510 CMDQ_MODIFY_QP_MODIFY_MASK_SQ_SGE
|
1511 CMDQ_MODIFY_QP_MODIFY_MASK_RQ_SGE
|
1512 CMDQ_MODIFY_QP_MODIFY_MASK_MAX_INLINE_DATA
;
1513 if ((qp_attr
->cap
.max_send_wr
>= dev_attr
->max_qp_wqes
) ||
1514 (qp_attr
->cap
.max_recv_wr
>= dev_attr
->max_qp_wqes
) ||
1515 (qp_attr
->cap
.max_send_sge
>= dev_attr
->max_qp_sges
) ||
1516 (qp_attr
->cap
.max_recv_sge
>= dev_attr
->max_qp_sges
) ||
1517 (qp_attr
->cap
.max_inline_data
>=
1518 dev_attr
->max_inline_data
)) {
1519 dev_err(rdev_to_dev(rdev
),
1520 "Create QP failed - max exceeded");
1523 entries
= roundup_pow_of_two(qp_attr
->cap
.max_send_wr
);
1524 qp
->qplib_qp
.sq
.max_wqe
= min_t(u32
, entries
,
1525 dev_attr
->max_qp_wqes
+ 1);
1526 qp
->qplib_qp
.sq
.q_full_delta
= qp
->qplib_qp
.sq
.max_wqe
-
1527 qp_attr
->cap
.max_send_wr
;
1529 * Reserving one slot for Phantom WQE. Some application can
1530 * post one extra entry in this case. Allowing this to avoid
1531 * unexpected Queue full condition
1533 qp
->qplib_qp
.sq
.q_full_delta
-= 1;
1534 qp
->qplib_qp
.sq
.max_sge
= qp_attr
->cap
.max_send_sge
;
1535 if (qp
->qplib_qp
.rq
.max_wqe
) {
1536 entries
= roundup_pow_of_two(qp_attr
->cap
.max_recv_wr
);
1537 qp
->qplib_qp
.rq
.max_wqe
=
1538 min_t(u32
, entries
, dev_attr
->max_qp_wqes
+ 1);
1539 qp
->qplib_qp
.rq
.q_full_delta
= qp
->qplib_qp
.rq
.max_wqe
-
1540 qp_attr
->cap
.max_recv_wr
;
1541 qp
->qplib_qp
.rq
.max_sge
= qp_attr
->cap
.max_recv_sge
;
1543 /* SRQ was used prior, just ignore the RQ caps */
1546 if (qp_attr_mask
& IB_QP_DEST_QPN
) {
1547 qp
->qplib_qp
.modify_flags
|=
1548 CMDQ_MODIFY_QP_MODIFY_MASK_DEST_QP_ID
;
1549 qp
->qplib_qp
.dest_qpn
= qp_attr
->dest_qp_num
;
1551 rc
= bnxt_qplib_modify_qp(&rdev
->qplib_res
, &qp
->qplib_qp
);
1553 dev_err(rdev_to_dev(rdev
), "Failed to modify HW QP");
1556 if (ib_qp
->qp_type
== IB_QPT_GSI
&& rdev
->qp1_sqp
)
1557 rc
= bnxt_re_modify_shadow_qp(rdev
, qp
, qp_attr_mask
);
1561 int bnxt_re_query_qp(struct ib_qp
*ib_qp
, struct ib_qp_attr
*qp_attr
,
1562 int qp_attr_mask
, struct ib_qp_init_attr
*qp_init_attr
)
1564 struct bnxt_re_qp
*qp
= container_of(ib_qp
, struct bnxt_re_qp
, ib_qp
);
1565 struct bnxt_re_dev
*rdev
= qp
->rdev
;
1566 struct bnxt_qplib_qp
*qplib_qp
;
1569 qplib_qp
= kzalloc(sizeof(*qplib_qp
), GFP_KERNEL
);
1573 qplib_qp
->id
= qp
->qplib_qp
.id
;
1574 qplib_qp
->ah
.host_sgid_index
= qp
->qplib_qp
.ah
.host_sgid_index
;
1576 rc
= bnxt_qplib_query_qp(&rdev
->qplib_res
, qplib_qp
);
1578 dev_err(rdev_to_dev(rdev
), "Failed to query HW QP");
1581 qp_attr
->qp_state
= __to_ib_qp_state(qplib_qp
->state
);
1582 qp_attr
->en_sqd_async_notify
= qplib_qp
->en_sqd_async_notify
? 1 : 0;
1583 qp_attr
->qp_access_flags
= __to_ib_access_flags(qplib_qp
->access
);
1584 qp_attr
->pkey_index
= qplib_qp
->pkey_index
;
1585 qp_attr
->qkey
= qplib_qp
->qkey
;
1586 qp_attr
->ah_attr
.type
= RDMA_AH_ATTR_TYPE_ROCE
;
1587 rdma_ah_set_grh(&qp_attr
->ah_attr
, NULL
, qplib_qp
->ah
.flow_label
,
1588 qplib_qp
->ah
.host_sgid_index
,
1589 qplib_qp
->ah
.hop_limit
,
1590 qplib_qp
->ah
.traffic_class
);
1591 rdma_ah_set_dgid_raw(&qp_attr
->ah_attr
, qplib_qp
->ah
.dgid
.data
);
1592 rdma_ah_set_sl(&qp_attr
->ah_attr
, qplib_qp
->ah
.sl
);
1593 ether_addr_copy(qp_attr
->ah_attr
.roce
.dmac
, qplib_qp
->ah
.dmac
);
1594 qp_attr
->path_mtu
= __to_ib_mtu(qplib_qp
->path_mtu
);
1595 qp_attr
->timeout
= qplib_qp
->timeout
;
1596 qp_attr
->retry_cnt
= qplib_qp
->retry_cnt
;
1597 qp_attr
->rnr_retry
= qplib_qp
->rnr_retry
;
1598 qp_attr
->min_rnr_timer
= qplib_qp
->min_rnr_timer
;
1599 qp_attr
->rq_psn
= qplib_qp
->rq
.psn
;
1600 qp_attr
->max_rd_atomic
= qplib_qp
->max_rd_atomic
;
1601 qp_attr
->sq_psn
= qplib_qp
->sq
.psn
;
1602 qp_attr
->max_dest_rd_atomic
= qplib_qp
->max_dest_rd_atomic
;
1603 qp_init_attr
->sq_sig_type
= qplib_qp
->sig_type
? IB_SIGNAL_ALL_WR
:
1605 qp_attr
->dest_qp_num
= qplib_qp
->dest_qpn
;
1607 qp_attr
->cap
.max_send_wr
= qp
->qplib_qp
.sq
.max_wqe
;
1608 qp_attr
->cap
.max_send_sge
= qp
->qplib_qp
.sq
.max_sge
;
1609 qp_attr
->cap
.max_recv_wr
= qp
->qplib_qp
.rq
.max_wqe
;
1610 qp_attr
->cap
.max_recv_sge
= qp
->qplib_qp
.rq
.max_sge
;
1611 qp_attr
->cap
.max_inline_data
= qp
->qplib_qp
.max_inline_data
;
1612 qp_init_attr
->cap
= qp_attr
->cap
;
1619 /* Routine for sending QP1 packets for RoCE V1 an V2
1621 static int bnxt_re_build_qp1_send_v2(struct bnxt_re_qp
*qp
,
1622 struct ib_send_wr
*wr
,
1623 struct bnxt_qplib_swqe
*wqe
,
1626 struct ib_device
*ibdev
= &qp
->rdev
->ibdev
;
1627 struct bnxt_re_ah
*ah
= container_of(ud_wr(wr
)->ah
, struct bnxt_re_ah
,
1629 struct bnxt_qplib_ah
*qplib_ah
= &ah
->qplib_ah
;
1630 struct bnxt_qplib_sge sge
;
1634 struct ib_gid_attr sgid_attr
;
1636 bool is_eth
= false;
1637 bool is_vlan
= false;
1638 bool is_grh
= false;
1639 bool is_udp
= false;
1641 u16 vlan_id
= 0xFFFF;
1645 memset(&qp
->qp1_hdr
, 0, sizeof(qp
->qp1_hdr
));
1647 rc
= ib_get_cached_gid(ibdev
, 1,
1648 qplib_ah
->host_sgid_index
, &sgid
,
1651 dev_err(rdev_to_dev(qp
->rdev
),
1652 "Failed to query gid at index %d",
1653 qplib_ah
->host_sgid_index
);
1656 if (sgid_attr
.ndev
) {
1657 if (is_vlan_dev(sgid_attr
.ndev
))
1658 vlan_id
= vlan_dev_vlan_id(sgid_attr
.ndev
);
1659 dev_put(sgid_attr
.ndev
);
1661 /* Get network header type for this GID */
1662 nw_type
= ib_gid_to_network_type(sgid_attr
.gid_type
, &sgid
);
1664 case RDMA_NETWORK_IPV4
:
1665 nw_type
= BNXT_RE_ROCEV2_IPV4_PACKET
;
1667 case RDMA_NETWORK_IPV6
:
1668 nw_type
= BNXT_RE_ROCEV2_IPV6_PACKET
;
1671 nw_type
= BNXT_RE_ROCE_V1_PACKET
;
1674 memcpy(&dgid
.raw
, &qplib_ah
->dgid
, 16);
1675 is_udp
= sgid_attr
.gid_type
== IB_GID_TYPE_ROCE_UDP_ENCAP
;
1677 if (ipv6_addr_v4mapped((struct in6_addr
*)&sgid
)) {
1679 ether_type
= ETH_P_IP
;
1682 ether_type
= ETH_P_IPV6
;
1686 ether_type
= ETH_P_IBOE
;
1691 is_vlan
= (vlan_id
&& (vlan_id
< 0x1000)) ? true : false;
1693 ib_ud_header_init(payload_size
, !is_eth
, is_eth
, is_vlan
, is_grh
,
1694 ip_version
, is_udp
, 0, &qp
->qp1_hdr
);
1697 ether_addr_copy(qp
->qp1_hdr
.eth
.dmac_h
, ah
->qplib_ah
.dmac
);
1698 ether_addr_copy(qp
->qp1_hdr
.eth
.smac_h
, qp
->qplib_qp
.smac
);
1700 /* For vlan, check the sgid for vlan existence */
1703 qp
->qp1_hdr
.eth
.type
= cpu_to_be16(ether_type
);
1705 qp
->qp1_hdr
.vlan
.type
= cpu_to_be16(ether_type
);
1706 qp
->qp1_hdr
.vlan
.tag
= cpu_to_be16(vlan_id
);
1709 if (is_grh
|| (ip_version
== 6)) {
1710 memcpy(qp
->qp1_hdr
.grh
.source_gid
.raw
, sgid
.raw
, sizeof(sgid
));
1711 memcpy(qp
->qp1_hdr
.grh
.destination_gid
.raw
, qplib_ah
->dgid
.data
,
1713 qp
->qp1_hdr
.grh
.hop_limit
= qplib_ah
->hop_limit
;
1716 if (ip_version
== 4) {
1717 qp
->qp1_hdr
.ip4
.tos
= 0;
1718 qp
->qp1_hdr
.ip4
.id
= 0;
1719 qp
->qp1_hdr
.ip4
.frag_off
= htons(IP_DF
);
1720 qp
->qp1_hdr
.ip4
.ttl
= qplib_ah
->hop_limit
;
1722 memcpy(&qp
->qp1_hdr
.ip4
.saddr
, sgid
.raw
+ 12, 4);
1723 memcpy(&qp
->qp1_hdr
.ip4
.daddr
, qplib_ah
->dgid
.data
+ 12, 4);
1724 qp
->qp1_hdr
.ip4
.check
= ib_ud_ip4_csum(&qp
->qp1_hdr
);
1728 qp
->qp1_hdr
.udp
.dport
= htons(ROCE_V2_UDP_DPORT
);
1729 qp
->qp1_hdr
.udp
.sport
= htons(0x8CD1);
1730 qp
->qp1_hdr
.udp
.csum
= 0;
1734 if (wr
->opcode
== IB_WR_SEND_WITH_IMM
) {
1735 qp
->qp1_hdr
.bth
.opcode
= IB_OPCODE_UD_SEND_ONLY_WITH_IMMEDIATE
;
1736 qp
->qp1_hdr
.immediate_present
= 1;
1738 qp
->qp1_hdr
.bth
.opcode
= IB_OPCODE_UD_SEND_ONLY
;
1740 if (wr
->send_flags
& IB_SEND_SOLICITED
)
1741 qp
->qp1_hdr
.bth
.solicited_event
= 1;
1743 qp
->qp1_hdr
.bth
.pad_count
= (4 - payload_size
) & 3;
1745 /* P_key for QP1 is for all members */
1746 qp
->qp1_hdr
.bth
.pkey
= cpu_to_be16(0xFFFF);
1747 qp
->qp1_hdr
.bth
.destination_qpn
= IB_QP1
;
1748 qp
->qp1_hdr
.bth
.ack_req
= 0;
1750 qp
->send_psn
&= BTH_PSN_MASK
;
1751 qp
->qp1_hdr
.bth
.psn
= cpu_to_be32(qp
->send_psn
);
1753 /* Use the priviledged Q_Key for QP1 */
1754 qp
->qp1_hdr
.deth
.qkey
= cpu_to_be32(IB_QP1_QKEY
);
1755 qp
->qp1_hdr
.deth
.source_qpn
= IB_QP1
;
1757 /* Pack the QP1 to the transmit buffer */
1758 buf
= bnxt_qplib_get_qp1_sq_buf(&qp
->qplib_qp
, &sge
);
1760 ib_ud_header_pack(&qp
->qp1_hdr
, buf
);
1761 for (i
= wqe
->num_sge
; i
; i
--) {
1762 wqe
->sg_list
[i
].addr
= wqe
->sg_list
[i
- 1].addr
;
1763 wqe
->sg_list
[i
].lkey
= wqe
->sg_list
[i
- 1].lkey
;
1764 wqe
->sg_list
[i
].size
= wqe
->sg_list
[i
- 1].size
;
1768 * Max Header buf size for IPV6 RoCE V2 is 86,
1769 * which is same as the QP1 SQ header buffer.
1770 * Header buf size for IPV4 RoCE V2 can be 66.
1771 * ETH(14) + VLAN(4)+ IP(20) + UDP (8) + BTH(20).
1772 * Subtract 20 bytes from QP1 SQ header buf size
1774 if (is_udp
&& ip_version
== 4)
1777 * Max Header buf size for RoCE V1 is 78.
1778 * ETH(14) + VLAN(4) + GRH(40) + BTH(20).
1779 * Subtract 8 bytes from QP1 SQ header buf size
1784 /* Subtract 4 bytes for non vlan packets */
1788 wqe
->sg_list
[0].addr
= sge
.addr
;
1789 wqe
->sg_list
[0].lkey
= sge
.lkey
;
1790 wqe
->sg_list
[0].size
= sge
.size
;
1794 dev_err(rdev_to_dev(qp
->rdev
), "QP1 buffer is empty!");
1800 /* For the MAD layer, it only provides the recv SGE the size of
1801 * ib_grh + MAD datagram. No Ethernet headers, Ethertype, BTH, DETH,
1802 * nor RoCE iCRC. The Cu+ solution must provide buffer for the entire
1803 * receive packet (334 bytes) with no VLAN and then copy the GRH
1804 * and the MAD datagram out to the provided SGE.
1806 static int bnxt_re_build_qp1_shadow_qp_recv(struct bnxt_re_qp
*qp
,
1807 struct ib_recv_wr
*wr
,
1808 struct bnxt_qplib_swqe
*wqe
,
1811 struct bnxt_qplib_sge ref
, sge
;
1813 struct bnxt_re_sqp_entries
*sqp_entry
;
1815 rq_prod_index
= bnxt_qplib_get_rq_prod_index(&qp
->qplib_qp
);
1817 if (!bnxt_qplib_get_qp1_rq_buf(&qp
->qplib_qp
, &sge
))
1820 /* Create 1 SGE to receive the entire
1823 /* Save the reference from ULP */
1824 ref
.addr
= wqe
->sg_list
[0].addr
;
1825 ref
.lkey
= wqe
->sg_list
[0].lkey
;
1826 ref
.size
= wqe
->sg_list
[0].size
;
1828 sqp_entry
= &qp
->rdev
->sqp_tbl
[rq_prod_index
];
1831 wqe
->sg_list
[0].addr
= sge
.addr
;
1832 wqe
->sg_list
[0].lkey
= sge
.lkey
;
1833 wqe
->sg_list
[0].size
= BNXT_QPLIB_MAX_QP1_RQ_HDR_SIZE_V2
;
1834 sge
.size
-= wqe
->sg_list
[0].size
;
1836 sqp_entry
->sge
.addr
= ref
.addr
;
1837 sqp_entry
->sge
.lkey
= ref
.lkey
;
1838 sqp_entry
->sge
.size
= ref
.size
;
1839 /* Store the wrid for reporting completion */
1840 sqp_entry
->wrid
= wqe
->wr_id
;
1841 /* change the wqe->wrid to table index */
1842 wqe
->wr_id
= rq_prod_index
;
1846 static int is_ud_qp(struct bnxt_re_qp
*qp
)
1848 return qp
->qplib_qp
.type
== CMDQ_CREATE_QP_TYPE_UD
;
1851 static int bnxt_re_build_send_wqe(struct bnxt_re_qp
*qp
,
1852 struct ib_send_wr
*wr
,
1853 struct bnxt_qplib_swqe
*wqe
)
1855 struct bnxt_re_ah
*ah
= NULL
;
1858 ah
= container_of(ud_wr(wr
)->ah
, struct bnxt_re_ah
, ib_ah
);
1859 wqe
->send
.q_key
= ud_wr(wr
)->remote_qkey
;
1860 wqe
->send
.dst_qp
= ud_wr(wr
)->remote_qpn
;
1861 wqe
->send
.avid
= ah
->qplib_ah
.id
;
1863 switch (wr
->opcode
) {
1865 wqe
->type
= BNXT_QPLIB_SWQE_TYPE_SEND
;
1867 case IB_WR_SEND_WITH_IMM
:
1868 wqe
->type
= BNXT_QPLIB_SWQE_TYPE_SEND_WITH_IMM
;
1869 wqe
->send
.imm_data
= wr
->ex
.imm_data
;
1871 case IB_WR_SEND_WITH_INV
:
1872 wqe
->type
= BNXT_QPLIB_SWQE_TYPE_SEND_WITH_INV
;
1873 wqe
->send
.inv_key
= wr
->ex
.invalidate_rkey
;
1878 if (wr
->send_flags
& IB_SEND_SIGNALED
)
1879 wqe
->flags
|= BNXT_QPLIB_SWQE_FLAGS_SIGNAL_COMP
;
1880 if (wr
->send_flags
& IB_SEND_FENCE
)
1881 wqe
->flags
|= BNXT_QPLIB_SWQE_FLAGS_UC_FENCE
;
1882 if (wr
->send_flags
& IB_SEND_SOLICITED
)
1883 wqe
->flags
|= BNXT_QPLIB_SWQE_FLAGS_SOLICIT_EVENT
;
1884 if (wr
->send_flags
& IB_SEND_INLINE
)
1885 wqe
->flags
|= BNXT_QPLIB_SWQE_FLAGS_INLINE
;
1890 static int bnxt_re_build_rdma_wqe(struct ib_send_wr
*wr
,
1891 struct bnxt_qplib_swqe
*wqe
)
1893 switch (wr
->opcode
) {
1894 case IB_WR_RDMA_WRITE
:
1895 wqe
->type
= BNXT_QPLIB_SWQE_TYPE_RDMA_WRITE
;
1897 case IB_WR_RDMA_WRITE_WITH_IMM
:
1898 wqe
->type
= BNXT_QPLIB_SWQE_TYPE_RDMA_WRITE_WITH_IMM
;
1899 wqe
->rdma
.imm_data
= wr
->ex
.imm_data
;
1901 case IB_WR_RDMA_READ
:
1902 wqe
->type
= BNXT_QPLIB_SWQE_TYPE_RDMA_READ
;
1903 wqe
->rdma
.inv_key
= wr
->ex
.invalidate_rkey
;
1908 wqe
->rdma
.remote_va
= rdma_wr(wr
)->remote_addr
;
1909 wqe
->rdma
.r_key
= rdma_wr(wr
)->rkey
;
1910 if (wr
->send_flags
& IB_SEND_SIGNALED
)
1911 wqe
->flags
|= BNXT_QPLIB_SWQE_FLAGS_SIGNAL_COMP
;
1912 if (wr
->send_flags
& IB_SEND_FENCE
)
1913 wqe
->flags
|= BNXT_QPLIB_SWQE_FLAGS_UC_FENCE
;
1914 if (wr
->send_flags
& IB_SEND_SOLICITED
)
1915 wqe
->flags
|= BNXT_QPLIB_SWQE_FLAGS_SOLICIT_EVENT
;
1916 if (wr
->send_flags
& IB_SEND_INLINE
)
1917 wqe
->flags
|= BNXT_QPLIB_SWQE_FLAGS_INLINE
;
1922 static int bnxt_re_build_atomic_wqe(struct ib_send_wr
*wr
,
1923 struct bnxt_qplib_swqe
*wqe
)
1925 switch (wr
->opcode
) {
1926 case IB_WR_ATOMIC_CMP_AND_SWP
:
1927 wqe
->type
= BNXT_QPLIB_SWQE_TYPE_ATOMIC_CMP_AND_SWP
;
1928 wqe
->atomic
.cmp_data
= atomic_wr(wr
)->compare_add
;
1929 wqe
->atomic
.swap_data
= atomic_wr(wr
)->swap
;
1931 case IB_WR_ATOMIC_FETCH_AND_ADD
:
1932 wqe
->type
= BNXT_QPLIB_SWQE_TYPE_ATOMIC_FETCH_AND_ADD
;
1933 wqe
->atomic
.cmp_data
= atomic_wr(wr
)->compare_add
;
1938 wqe
->atomic
.remote_va
= atomic_wr(wr
)->remote_addr
;
1939 wqe
->atomic
.r_key
= atomic_wr(wr
)->rkey
;
1940 if (wr
->send_flags
& IB_SEND_SIGNALED
)
1941 wqe
->flags
|= BNXT_QPLIB_SWQE_FLAGS_SIGNAL_COMP
;
1942 if (wr
->send_flags
& IB_SEND_FENCE
)
1943 wqe
->flags
|= BNXT_QPLIB_SWQE_FLAGS_UC_FENCE
;
1944 if (wr
->send_flags
& IB_SEND_SOLICITED
)
1945 wqe
->flags
|= BNXT_QPLIB_SWQE_FLAGS_SOLICIT_EVENT
;
1949 static int bnxt_re_build_inv_wqe(struct ib_send_wr
*wr
,
1950 struct bnxt_qplib_swqe
*wqe
)
1952 wqe
->type
= BNXT_QPLIB_SWQE_TYPE_LOCAL_INV
;
1953 wqe
->local_inv
.inv_l_key
= wr
->ex
.invalidate_rkey
;
1955 /* Need unconditional fence for local invalidate
1956 * opcode to work as expected.
1958 wqe
->flags
|= BNXT_QPLIB_SWQE_FLAGS_UC_FENCE
;
1960 if (wr
->send_flags
& IB_SEND_SIGNALED
)
1961 wqe
->flags
|= BNXT_QPLIB_SWQE_FLAGS_SIGNAL_COMP
;
1962 if (wr
->send_flags
& IB_SEND_SOLICITED
)
1963 wqe
->flags
|= BNXT_QPLIB_SWQE_FLAGS_SOLICIT_EVENT
;
1968 static int bnxt_re_build_reg_wqe(struct ib_reg_wr
*wr
,
1969 struct bnxt_qplib_swqe
*wqe
)
1971 struct bnxt_re_mr
*mr
= container_of(wr
->mr
, struct bnxt_re_mr
, ib_mr
);
1972 struct bnxt_qplib_frpl
*qplib_frpl
= &mr
->qplib_frpl
;
1973 int access
= wr
->access
;
1975 wqe
->frmr
.pbl_ptr
= (__le64
*)qplib_frpl
->hwq
.pbl_ptr
[0];
1976 wqe
->frmr
.pbl_dma_ptr
= qplib_frpl
->hwq
.pbl_dma_ptr
[0];
1977 wqe
->frmr
.page_list
= mr
->pages
;
1978 wqe
->frmr
.page_list_len
= mr
->npages
;
1979 wqe
->frmr
.levels
= qplib_frpl
->hwq
.level
+ 1;
1980 wqe
->type
= BNXT_QPLIB_SWQE_TYPE_REG_MR
;
1982 /* Need unconditional fence for reg_mr
1983 * opcode to function as expected.
1986 wqe
->flags
|= BNXT_QPLIB_SWQE_FLAGS_UC_FENCE
;
1988 if (wr
->wr
.send_flags
& IB_SEND_SIGNALED
)
1989 wqe
->flags
|= BNXT_QPLIB_SWQE_FLAGS_SIGNAL_COMP
;
1991 if (access
& IB_ACCESS_LOCAL_WRITE
)
1992 wqe
->frmr
.access_cntl
|= SQ_FR_PMR_ACCESS_CNTL_LOCAL_WRITE
;
1993 if (access
& IB_ACCESS_REMOTE_READ
)
1994 wqe
->frmr
.access_cntl
|= SQ_FR_PMR_ACCESS_CNTL_REMOTE_READ
;
1995 if (access
& IB_ACCESS_REMOTE_WRITE
)
1996 wqe
->frmr
.access_cntl
|= SQ_FR_PMR_ACCESS_CNTL_REMOTE_WRITE
;
1997 if (access
& IB_ACCESS_REMOTE_ATOMIC
)
1998 wqe
->frmr
.access_cntl
|= SQ_FR_PMR_ACCESS_CNTL_REMOTE_ATOMIC
;
1999 if (access
& IB_ACCESS_MW_BIND
)
2000 wqe
->frmr
.access_cntl
|= SQ_FR_PMR_ACCESS_CNTL_WINDOW_BIND
;
2002 wqe
->frmr
.l_key
= wr
->key
;
2003 wqe
->frmr
.length
= wr
->mr
->length
;
2004 wqe
->frmr
.pbl_pg_sz_log
= (wr
->mr
->page_size
>> PAGE_SHIFT_4K
) - 1;
2005 wqe
->frmr
.va
= wr
->mr
->iova
;
2009 static int bnxt_re_copy_inline_data(struct bnxt_re_dev
*rdev
,
2010 struct ib_send_wr
*wr
,
2011 struct bnxt_qplib_swqe
*wqe
)
2013 /* Copy the inline data to the data field */
2018 in_data
= wqe
->inline_data
;
2019 for (i
= 0; i
< wr
->num_sge
; i
++) {
2020 sge_addr
= (void *)(unsigned long)
2021 wr
->sg_list
[i
].addr
;
2022 sge_len
= wr
->sg_list
[i
].length
;
2024 if ((sge_len
+ wqe
->inline_len
) >
2025 BNXT_QPLIB_SWQE_MAX_INLINE_LENGTH
) {
2026 dev_err(rdev_to_dev(rdev
),
2027 "Inline data size requested > supported value");
2030 sge_len
= wr
->sg_list
[i
].length
;
2032 memcpy(in_data
, sge_addr
, sge_len
);
2033 in_data
+= wr
->sg_list
[i
].length
;
2034 wqe
->inline_len
+= wr
->sg_list
[i
].length
;
2036 return wqe
->inline_len
;
2039 static int bnxt_re_copy_wr_payload(struct bnxt_re_dev
*rdev
,
2040 struct ib_send_wr
*wr
,
2041 struct bnxt_qplib_swqe
*wqe
)
2045 if (wr
->send_flags
& IB_SEND_INLINE
)
2046 payload_sz
= bnxt_re_copy_inline_data(rdev
, wr
, wqe
);
2048 payload_sz
= bnxt_re_build_sgl(wr
->sg_list
, wqe
->sg_list
,
2054 static void bnxt_ud_qp_hw_stall_workaround(struct bnxt_re_qp
*qp
)
2056 if ((qp
->ib_qp
.qp_type
== IB_QPT_UD
||
2057 qp
->ib_qp
.qp_type
== IB_QPT_GSI
||
2058 qp
->ib_qp
.qp_type
== IB_QPT_RAW_ETHERTYPE
) &&
2059 qp
->qplib_qp
.wqe_cnt
== BNXT_RE_UD_QP_HW_STALL
) {
2061 struct ib_qp_attr qp_attr
;
2063 qp_attr_mask
= IB_QP_STATE
;
2064 qp_attr
.qp_state
= IB_QPS_RTS
;
2065 bnxt_re_modify_qp(&qp
->ib_qp
, &qp_attr
, qp_attr_mask
, NULL
);
2066 qp
->qplib_qp
.wqe_cnt
= 0;
2070 static int bnxt_re_post_send_shadow_qp(struct bnxt_re_dev
*rdev
,
2071 struct bnxt_re_qp
*qp
,
2072 struct ib_send_wr
*wr
)
2074 struct bnxt_qplib_swqe wqe
;
2075 int rc
= 0, payload_sz
= 0;
2076 unsigned long flags
;
2078 spin_lock_irqsave(&qp
->sq_lock
, flags
);
2079 memset(&wqe
, 0, sizeof(wqe
));
2082 memset(&wqe
, 0, sizeof(wqe
));
2085 wqe
.num_sge
= wr
->num_sge
;
2086 if (wr
->num_sge
> qp
->qplib_qp
.sq
.max_sge
) {
2087 dev_err(rdev_to_dev(rdev
),
2088 "Limit exceeded for Send SGEs");
2093 payload_sz
= bnxt_re_copy_wr_payload(qp
->rdev
, wr
, &wqe
);
2094 if (payload_sz
< 0) {
2098 wqe
.wr_id
= wr
->wr_id
;
2100 wqe
.type
= BNXT_QPLIB_SWQE_TYPE_SEND
;
2102 rc
= bnxt_re_build_send_wqe(qp
, wr
, &wqe
);
2104 rc
= bnxt_qplib_post_send(&qp
->qplib_qp
, &wqe
);
2107 dev_err(rdev_to_dev(rdev
),
2108 "Post send failed opcode = %#x rc = %d",
2114 bnxt_qplib_post_send_db(&qp
->qplib_qp
);
2115 bnxt_ud_qp_hw_stall_workaround(qp
);
2116 spin_unlock_irqrestore(&qp
->sq_lock
, flags
);
2120 int bnxt_re_post_send(struct ib_qp
*ib_qp
, struct ib_send_wr
*wr
,
2121 struct ib_send_wr
**bad_wr
)
2123 struct bnxt_re_qp
*qp
= container_of(ib_qp
, struct bnxt_re_qp
, ib_qp
);
2124 struct bnxt_qplib_swqe wqe
;
2125 int rc
= 0, payload_sz
= 0;
2126 unsigned long flags
;
2128 spin_lock_irqsave(&qp
->sq_lock
, flags
);
2131 memset(&wqe
, 0, sizeof(wqe
));
2134 wqe
.num_sge
= wr
->num_sge
;
2135 if (wr
->num_sge
> qp
->qplib_qp
.sq
.max_sge
) {
2136 dev_err(rdev_to_dev(qp
->rdev
),
2137 "Limit exceeded for Send SGEs");
2142 payload_sz
= bnxt_re_copy_wr_payload(qp
->rdev
, wr
, &wqe
);
2143 if (payload_sz
< 0) {
2147 wqe
.wr_id
= wr
->wr_id
;
2149 switch (wr
->opcode
) {
2151 case IB_WR_SEND_WITH_IMM
:
2152 if (ib_qp
->qp_type
== IB_QPT_GSI
) {
2153 rc
= bnxt_re_build_qp1_send_v2(qp
, wr
, &wqe
,
2157 wqe
.rawqp1
.lflags
|=
2158 SQ_SEND_RAWETH_QP1_LFLAGS_ROCE_CRC
;
2160 switch (wr
->send_flags
) {
2161 case IB_SEND_IP_CSUM
:
2162 wqe
.rawqp1
.lflags
|=
2163 SQ_SEND_RAWETH_QP1_LFLAGS_IP_CHKSUM
;
2168 /* Fall thru to build the wqe */
2169 case IB_WR_SEND_WITH_INV
:
2170 rc
= bnxt_re_build_send_wqe(qp
, wr
, &wqe
);
2172 case IB_WR_RDMA_WRITE
:
2173 case IB_WR_RDMA_WRITE_WITH_IMM
:
2174 case IB_WR_RDMA_READ
:
2175 rc
= bnxt_re_build_rdma_wqe(wr
, &wqe
);
2177 case IB_WR_ATOMIC_CMP_AND_SWP
:
2178 case IB_WR_ATOMIC_FETCH_AND_ADD
:
2179 rc
= bnxt_re_build_atomic_wqe(wr
, &wqe
);
2181 case IB_WR_RDMA_READ_WITH_INV
:
2182 dev_err(rdev_to_dev(qp
->rdev
),
2183 "RDMA Read with Invalidate is not supported");
2186 case IB_WR_LOCAL_INV
:
2187 rc
= bnxt_re_build_inv_wqe(wr
, &wqe
);
2190 rc
= bnxt_re_build_reg_wqe(reg_wr(wr
), &wqe
);
2193 /* Unsupported WRs */
2194 dev_err(rdev_to_dev(qp
->rdev
),
2195 "WR (%#x) is not supported", wr
->opcode
);
2200 rc
= bnxt_qplib_post_send(&qp
->qplib_qp
, &wqe
);
2203 dev_err(rdev_to_dev(qp
->rdev
),
2204 "post_send failed op:%#x qps = %#x rc = %d\n",
2205 wr
->opcode
, qp
->qplib_qp
.state
, rc
);
2211 bnxt_qplib_post_send_db(&qp
->qplib_qp
);
2212 bnxt_ud_qp_hw_stall_workaround(qp
);
2213 spin_unlock_irqrestore(&qp
->sq_lock
, flags
);
2218 static int bnxt_re_post_recv_shadow_qp(struct bnxt_re_dev
*rdev
,
2219 struct bnxt_re_qp
*qp
,
2220 struct ib_recv_wr
*wr
)
2222 struct bnxt_qplib_swqe wqe
;
2225 memset(&wqe
, 0, sizeof(wqe
));
2228 memset(&wqe
, 0, sizeof(wqe
));
2231 wqe
.num_sge
= wr
->num_sge
;
2232 if (wr
->num_sge
> qp
->qplib_qp
.rq
.max_sge
) {
2233 dev_err(rdev_to_dev(rdev
),
2234 "Limit exceeded for Receive SGEs");
2238 bnxt_re_build_sgl(wr
->sg_list
, wqe
.sg_list
, wr
->num_sge
);
2239 wqe
.wr_id
= wr
->wr_id
;
2240 wqe
.type
= BNXT_QPLIB_SWQE_TYPE_RECV
;
2242 rc
= bnxt_qplib_post_recv(&qp
->qplib_qp
, &wqe
);
2249 bnxt_qplib_post_recv_db(&qp
->qplib_qp
);
2253 int bnxt_re_post_recv(struct ib_qp
*ib_qp
, struct ib_recv_wr
*wr
,
2254 struct ib_recv_wr
**bad_wr
)
2256 struct bnxt_re_qp
*qp
= container_of(ib_qp
, struct bnxt_re_qp
, ib_qp
);
2257 struct bnxt_qplib_swqe wqe
;
2258 int rc
= 0, payload_sz
= 0;
2259 unsigned long flags
;
2262 spin_lock_irqsave(&qp
->rq_lock
, flags
);
2265 memset(&wqe
, 0, sizeof(wqe
));
2268 wqe
.num_sge
= wr
->num_sge
;
2269 if (wr
->num_sge
> qp
->qplib_qp
.rq
.max_sge
) {
2270 dev_err(rdev_to_dev(qp
->rdev
),
2271 "Limit exceeded for Receive SGEs");
2277 payload_sz
= bnxt_re_build_sgl(wr
->sg_list
, wqe
.sg_list
,
2279 wqe
.wr_id
= wr
->wr_id
;
2280 wqe
.type
= BNXT_QPLIB_SWQE_TYPE_RECV
;
2282 if (ib_qp
->qp_type
== IB_QPT_GSI
)
2283 rc
= bnxt_re_build_qp1_shadow_qp_recv(qp
, wr
, &wqe
,
2286 rc
= bnxt_qplib_post_recv(&qp
->qplib_qp
, &wqe
);
2292 /* Ring DB if the RQEs posted reaches a threshold value */
2293 if (++count
>= BNXT_RE_RQ_WQE_THRESHOLD
) {
2294 bnxt_qplib_post_recv_db(&qp
->qplib_qp
);
2302 bnxt_qplib_post_recv_db(&qp
->qplib_qp
);
2304 spin_unlock_irqrestore(&qp
->rq_lock
, flags
);
2309 /* Completion Queues */
2310 int bnxt_re_destroy_cq(struct ib_cq
*ib_cq
)
2312 struct bnxt_re_cq
*cq
= container_of(ib_cq
, struct bnxt_re_cq
, ib_cq
);
2313 struct bnxt_re_dev
*rdev
= cq
->rdev
;
2315 struct bnxt_qplib_nq
*nq
= cq
->qplib_cq
.nq
;
2317 rc
= bnxt_qplib_destroy_cq(&rdev
->qplib_res
, &cq
->qplib_cq
);
2319 dev_err(rdev_to_dev(rdev
), "Failed to destroy HW CQ");
2322 if (!IS_ERR_OR_NULL(cq
->umem
))
2323 ib_umem_release(cq
->umem
);
2329 atomic_dec(&rdev
->cq_count
);
2334 struct ib_cq
*bnxt_re_create_cq(struct ib_device
*ibdev
,
2335 const struct ib_cq_init_attr
*attr
,
2336 struct ib_ucontext
*context
,
2337 struct ib_udata
*udata
)
2339 struct bnxt_re_dev
*rdev
= to_bnxt_re_dev(ibdev
, ibdev
);
2340 struct bnxt_qplib_dev_attr
*dev_attr
= &rdev
->dev_attr
;
2341 struct bnxt_re_cq
*cq
= NULL
;
2343 int cqe
= attr
->cqe
;
2344 struct bnxt_qplib_nq
*nq
= NULL
;
2345 unsigned int nq_alloc_cnt
;
2347 /* Validate CQ fields */
2348 if (cqe
< 1 || cqe
> dev_attr
->max_cq_wqes
) {
2349 dev_err(rdev_to_dev(rdev
), "Failed to create CQ -max exceeded");
2350 return ERR_PTR(-EINVAL
);
2352 cq
= kzalloc(sizeof(*cq
), GFP_KERNEL
);
2354 return ERR_PTR(-ENOMEM
);
2357 cq
->qplib_cq
.cq_handle
= (u64
)(unsigned long)(&cq
->qplib_cq
);
2359 entries
= roundup_pow_of_two(cqe
+ 1);
2360 if (entries
> dev_attr
->max_cq_wqes
+ 1)
2361 entries
= dev_attr
->max_cq_wqes
+ 1;
2364 struct bnxt_re_cq_req req
;
2365 struct bnxt_re_ucontext
*uctx
= container_of
2367 struct bnxt_re_ucontext
,
2369 if (ib_copy_from_udata(&req
, udata
, sizeof(req
))) {
2374 cq
->umem
= ib_umem_get(context
, req
.cq_va
,
2375 entries
* sizeof(struct cq_base
),
2376 IB_ACCESS_LOCAL_WRITE
, 1);
2377 if (IS_ERR(cq
->umem
)) {
2378 rc
= PTR_ERR(cq
->umem
);
2381 cq
->qplib_cq
.sghead
= cq
->umem
->sg_head
.sgl
;
2382 cq
->qplib_cq
.nmap
= cq
->umem
->nmap
;
2383 cq
->qplib_cq
.dpi
= &uctx
->dpi
;
2385 cq
->max_cql
= min_t(u32
, entries
, MAX_CQL_PER_POLL
);
2386 cq
->cql
= kcalloc(cq
->max_cql
, sizeof(struct bnxt_qplib_cqe
),
2393 cq
->qplib_cq
.dpi
= &rdev
->dpi_privileged
;
2394 cq
->qplib_cq
.sghead
= NULL
;
2395 cq
->qplib_cq
.nmap
= 0;
2398 * Allocating the NQ in a round robin fashion. nq_alloc_cnt is a
2399 * used for getting the NQ index.
2401 nq_alloc_cnt
= atomic_inc_return(&rdev
->nq_alloc_cnt
);
2402 nq
= &rdev
->nq
[nq_alloc_cnt
% (rdev
->num_msix
- 1)];
2403 cq
->qplib_cq
.max_wqe
= entries
;
2404 cq
->qplib_cq
.cnq_hw_ring_id
= nq
->ring_id
;
2405 cq
->qplib_cq
.nq
= nq
;
2407 rc
= bnxt_qplib_create_cq(&rdev
->qplib_res
, &cq
->qplib_cq
);
2409 dev_err(rdev_to_dev(rdev
), "Failed to create HW CQ");
2413 cq
->ib_cq
.cqe
= entries
;
2414 cq
->cq_period
= cq
->qplib_cq
.period
;
2417 atomic_inc(&rdev
->cq_count
);
2420 struct bnxt_re_cq_resp resp
;
2422 resp
.cqid
= cq
->qplib_cq
.id
;
2423 resp
.tail
= cq
->qplib_cq
.hwq
.cons
;
2424 resp
.phase
= cq
->qplib_cq
.period
;
2426 rc
= ib_copy_to_udata(udata
, &resp
, sizeof(resp
));
2428 dev_err(rdev_to_dev(rdev
), "Failed to copy CQ udata");
2429 bnxt_qplib_destroy_cq(&rdev
->qplib_res
, &cq
->qplib_cq
);
2438 ib_umem_release(cq
->umem
);
2445 static u8
__req_to_ib_wc_status(u8 qstatus
)
2448 case CQ_REQ_STATUS_OK
:
2449 return IB_WC_SUCCESS
;
2450 case CQ_REQ_STATUS_BAD_RESPONSE_ERR
:
2451 return IB_WC_BAD_RESP_ERR
;
2452 case CQ_REQ_STATUS_LOCAL_LENGTH_ERR
:
2453 return IB_WC_LOC_LEN_ERR
;
2454 case CQ_REQ_STATUS_LOCAL_QP_OPERATION_ERR
:
2455 return IB_WC_LOC_QP_OP_ERR
;
2456 case CQ_REQ_STATUS_LOCAL_PROTECTION_ERR
:
2457 return IB_WC_LOC_PROT_ERR
;
2458 case CQ_REQ_STATUS_MEMORY_MGT_OPERATION_ERR
:
2459 return IB_WC_GENERAL_ERR
;
2460 case CQ_REQ_STATUS_REMOTE_INVALID_REQUEST_ERR
:
2461 return IB_WC_REM_INV_REQ_ERR
;
2462 case CQ_REQ_STATUS_REMOTE_ACCESS_ERR
:
2463 return IB_WC_REM_ACCESS_ERR
;
2464 case CQ_REQ_STATUS_REMOTE_OPERATION_ERR
:
2465 return IB_WC_REM_OP_ERR
;
2466 case CQ_REQ_STATUS_RNR_NAK_RETRY_CNT_ERR
:
2467 return IB_WC_RNR_RETRY_EXC_ERR
;
2468 case CQ_REQ_STATUS_TRANSPORT_RETRY_CNT_ERR
:
2469 return IB_WC_RETRY_EXC_ERR
;
2470 case CQ_REQ_STATUS_WORK_REQUEST_FLUSHED_ERR
:
2471 return IB_WC_WR_FLUSH_ERR
;
2473 return IB_WC_GENERAL_ERR
;
2478 static u8
__rawqp1_to_ib_wc_status(u8 qstatus
)
2481 case CQ_RES_RAWETH_QP1_STATUS_OK
:
2482 return IB_WC_SUCCESS
;
2483 case CQ_RES_RAWETH_QP1_STATUS_LOCAL_ACCESS_ERROR
:
2484 return IB_WC_LOC_ACCESS_ERR
;
2485 case CQ_RES_RAWETH_QP1_STATUS_HW_LOCAL_LENGTH_ERR
:
2486 return IB_WC_LOC_LEN_ERR
;
2487 case CQ_RES_RAWETH_QP1_STATUS_LOCAL_PROTECTION_ERR
:
2488 return IB_WC_LOC_PROT_ERR
;
2489 case CQ_RES_RAWETH_QP1_STATUS_LOCAL_QP_OPERATION_ERR
:
2490 return IB_WC_LOC_QP_OP_ERR
;
2491 case CQ_RES_RAWETH_QP1_STATUS_MEMORY_MGT_OPERATION_ERR
:
2492 return IB_WC_GENERAL_ERR
;
2493 case CQ_RES_RAWETH_QP1_STATUS_WORK_REQUEST_FLUSHED_ERR
:
2494 return IB_WC_WR_FLUSH_ERR
;
2495 case CQ_RES_RAWETH_QP1_STATUS_HW_FLUSH_ERR
:
2496 return IB_WC_WR_FLUSH_ERR
;
2498 return IB_WC_GENERAL_ERR
;
2502 static u8
__rc_to_ib_wc_status(u8 qstatus
)
2505 case CQ_RES_RC_STATUS_OK
:
2506 return IB_WC_SUCCESS
;
2507 case CQ_RES_RC_STATUS_LOCAL_ACCESS_ERROR
:
2508 return IB_WC_LOC_ACCESS_ERR
;
2509 case CQ_RES_RC_STATUS_LOCAL_LENGTH_ERR
:
2510 return IB_WC_LOC_LEN_ERR
;
2511 case CQ_RES_RC_STATUS_LOCAL_PROTECTION_ERR
:
2512 return IB_WC_LOC_PROT_ERR
;
2513 case CQ_RES_RC_STATUS_LOCAL_QP_OPERATION_ERR
:
2514 return IB_WC_LOC_QP_OP_ERR
;
2515 case CQ_RES_RC_STATUS_MEMORY_MGT_OPERATION_ERR
:
2516 return IB_WC_GENERAL_ERR
;
2517 case CQ_RES_RC_STATUS_REMOTE_INVALID_REQUEST_ERR
:
2518 return IB_WC_REM_INV_REQ_ERR
;
2519 case CQ_RES_RC_STATUS_WORK_REQUEST_FLUSHED_ERR
:
2520 return IB_WC_WR_FLUSH_ERR
;
2521 case CQ_RES_RC_STATUS_HW_FLUSH_ERR
:
2522 return IB_WC_WR_FLUSH_ERR
;
2524 return IB_WC_GENERAL_ERR
;
2528 static void bnxt_re_process_req_wc(struct ib_wc
*wc
, struct bnxt_qplib_cqe
*cqe
)
2530 switch (cqe
->type
) {
2531 case BNXT_QPLIB_SWQE_TYPE_SEND
:
2532 wc
->opcode
= IB_WC_SEND
;
2534 case BNXT_QPLIB_SWQE_TYPE_SEND_WITH_IMM
:
2535 wc
->opcode
= IB_WC_SEND
;
2536 wc
->wc_flags
|= IB_WC_WITH_IMM
;
2538 case BNXT_QPLIB_SWQE_TYPE_SEND_WITH_INV
:
2539 wc
->opcode
= IB_WC_SEND
;
2540 wc
->wc_flags
|= IB_WC_WITH_INVALIDATE
;
2542 case BNXT_QPLIB_SWQE_TYPE_RDMA_WRITE
:
2543 wc
->opcode
= IB_WC_RDMA_WRITE
;
2545 case BNXT_QPLIB_SWQE_TYPE_RDMA_WRITE_WITH_IMM
:
2546 wc
->opcode
= IB_WC_RDMA_WRITE
;
2547 wc
->wc_flags
|= IB_WC_WITH_IMM
;
2549 case BNXT_QPLIB_SWQE_TYPE_RDMA_READ
:
2550 wc
->opcode
= IB_WC_RDMA_READ
;
2552 case BNXT_QPLIB_SWQE_TYPE_ATOMIC_CMP_AND_SWP
:
2553 wc
->opcode
= IB_WC_COMP_SWAP
;
2555 case BNXT_QPLIB_SWQE_TYPE_ATOMIC_FETCH_AND_ADD
:
2556 wc
->opcode
= IB_WC_FETCH_ADD
;
2558 case BNXT_QPLIB_SWQE_TYPE_LOCAL_INV
:
2559 wc
->opcode
= IB_WC_LOCAL_INV
;
2561 case BNXT_QPLIB_SWQE_TYPE_REG_MR
:
2562 wc
->opcode
= IB_WC_REG_MR
;
2565 wc
->opcode
= IB_WC_SEND
;
2569 wc
->status
= __req_to_ib_wc_status(cqe
->status
);
2572 static int bnxt_re_check_packet_type(u16 raweth_qp1_flags
,
2573 u16 raweth_qp1_flags2
)
2575 bool is_ipv6
= false, is_ipv4
= false;
2577 /* raweth_qp1_flags Bit 9-6 indicates itype */
2578 if ((raweth_qp1_flags
& CQ_RES_RAWETH_QP1_RAWETH_QP1_FLAGS_ITYPE_ROCE
)
2579 != CQ_RES_RAWETH_QP1_RAWETH_QP1_FLAGS_ITYPE_ROCE
)
2582 if (raweth_qp1_flags2
&
2583 CQ_RES_RAWETH_QP1_RAWETH_QP1_FLAGS2_IP_CS_CALC
&&
2585 CQ_RES_RAWETH_QP1_RAWETH_QP1_FLAGS2_L4_CS_CALC
) {
2586 /* raweth_qp1_flags2 Bit 8 indicates ip_type. 0-v4 1 - v6 */
2587 (raweth_qp1_flags2
&
2588 CQ_RES_RAWETH_QP1_RAWETH_QP1_FLAGS2_IP_TYPE
) ?
2589 (is_ipv6
= true) : (is_ipv4
= true);
2591 BNXT_RE_ROCEV2_IPV6_PACKET
:
2592 BNXT_RE_ROCEV2_IPV4_PACKET
);
2594 return BNXT_RE_ROCE_V1_PACKET
;
2598 static int bnxt_re_to_ib_nw_type(int nw_type
)
2600 u8 nw_hdr_type
= 0xFF;
2603 case BNXT_RE_ROCE_V1_PACKET
:
2604 nw_hdr_type
= RDMA_NETWORK_ROCE_V1
;
2606 case BNXT_RE_ROCEV2_IPV4_PACKET
:
2607 nw_hdr_type
= RDMA_NETWORK_IPV4
;
2609 case BNXT_RE_ROCEV2_IPV6_PACKET
:
2610 nw_hdr_type
= RDMA_NETWORK_IPV6
;
2616 static bool bnxt_re_is_loopback_packet(struct bnxt_re_dev
*rdev
,
2620 struct ethhdr
*eth_hdr
;
2624 tmp_buf
= (u8
*)rq_hdr_buf
;
2626 * If dest mac is not same as I/F mac, this could be a
2627 * loopback address or multicast address, check whether
2628 * it is a loopback packet
2630 if (!ether_addr_equal(tmp_buf
, rdev
->netdev
->dev_addr
)) {
2632 /* Check the ether type */
2633 eth_hdr
= (struct ethhdr
*)tmp_buf
;
2634 eth_type
= ntohs(eth_hdr
->h_proto
);
2642 struct udphdr
*udp_hdr
;
2644 len
= (eth_type
== ETH_P_IP
? sizeof(struct iphdr
) :
2645 sizeof(struct ipv6hdr
));
2646 tmp_buf
+= sizeof(struct ethhdr
) + len
;
2647 udp_hdr
= (struct udphdr
*)tmp_buf
;
2648 if (ntohs(udp_hdr
->dest
) ==
2661 static int bnxt_re_process_raw_qp_pkt_rx(struct bnxt_re_qp
*qp1_qp
,
2662 struct bnxt_qplib_cqe
*cqe
)
2664 struct bnxt_re_dev
*rdev
= qp1_qp
->rdev
;
2665 struct bnxt_re_sqp_entries
*sqp_entry
= NULL
;
2666 struct bnxt_re_qp
*qp
= rdev
->qp1_sqp
;
2667 struct ib_send_wr
*swr
;
2668 struct ib_ud_wr udwr
;
2669 struct ib_recv_wr rwr
;
2673 dma_addr_t rq_hdr_buf_map
;
2674 dma_addr_t shrq_hdr_buf_map
;
2677 struct ib_sge s_sge
[2];
2678 struct ib_sge r_sge
[2];
2681 memset(&udwr
, 0, sizeof(udwr
));
2682 memset(&rwr
, 0, sizeof(rwr
));
2683 memset(&s_sge
, 0, sizeof(s_sge
));
2684 memset(&r_sge
, 0, sizeof(r_sge
));
2687 tbl_idx
= cqe
->wr_id
;
2689 rq_hdr_buf
= qp1_qp
->qplib_qp
.rq_hdr_buf
+
2690 (tbl_idx
* qp1_qp
->qplib_qp
.rq_hdr_buf_size
);
2691 rq_hdr_buf_map
= bnxt_qplib_get_qp_buf_from_index(&qp1_qp
->qplib_qp
,
2694 /* Shadow QP header buffer */
2695 shrq_hdr_buf_map
= bnxt_qplib_get_qp_buf_from_index(&qp
->qplib_qp
,
2697 sqp_entry
= &rdev
->sqp_tbl
[tbl_idx
];
2699 /* Store this cqe */
2700 memcpy(&sqp_entry
->cqe
, cqe
, sizeof(struct bnxt_qplib_cqe
));
2701 sqp_entry
->qp1_qp
= qp1_qp
;
2703 /* Find packet type from the cqe */
2705 pkt_type
= bnxt_re_check_packet_type(cqe
->raweth_qp1_flags
,
2706 cqe
->raweth_qp1_flags2
);
2708 dev_err(rdev_to_dev(rdev
), "Invalid packet\n");
2712 /* Adjust the offset for the user buffer and post in the rq */
2714 if (pkt_type
== BNXT_RE_ROCEV2_IPV4_PACKET
)
2718 * QP1 loopback packet has 4 bytes of internal header before
2719 * ether header. Skip these four bytes.
2721 if (bnxt_re_is_loopback_packet(rdev
, rq_hdr_buf
))
2724 /* First send SGE . Skip the ether header*/
2725 s_sge
[0].addr
= rq_hdr_buf_map
+ BNXT_QPLIB_MAX_QP1_RQ_ETH_HDR_SIZE
2727 s_sge
[0].lkey
= 0xFFFFFFFF;
2728 s_sge
[0].length
= offset
? BNXT_QPLIB_MAX_GRH_HDR_SIZE_IPV4
:
2729 BNXT_QPLIB_MAX_GRH_HDR_SIZE_IPV6
;
2731 /* Second Send SGE */
2732 s_sge
[1].addr
= s_sge
[0].addr
+ s_sge
[0].length
+
2733 BNXT_QPLIB_MAX_QP1_RQ_BDETH_HDR_SIZE
;
2734 if (pkt_type
!= BNXT_RE_ROCE_V1_PACKET
)
2736 s_sge
[1].lkey
= 0xFFFFFFFF;
2737 s_sge
[1].length
= 256;
2739 /* First recv SGE */
2741 r_sge
[0].addr
= shrq_hdr_buf_map
;
2742 r_sge
[0].lkey
= 0xFFFFFFFF;
2743 r_sge
[0].length
= 40;
2745 r_sge
[1].addr
= sqp_entry
->sge
.addr
+ offset
;
2746 r_sge
[1].lkey
= sqp_entry
->sge
.lkey
;
2747 r_sge
[1].length
= BNXT_QPLIB_MAX_GRH_HDR_SIZE_IPV6
+ 256 - offset
;
2749 /* Create receive work request */
2751 rwr
.sg_list
= r_sge
;
2752 rwr
.wr_id
= tbl_idx
;
2755 rc
= bnxt_re_post_recv_shadow_qp(rdev
, qp
, &rwr
);
2757 dev_err(rdev_to_dev(rdev
),
2758 "Failed to post Rx buffers to shadow QP");
2763 swr
->sg_list
= s_sge
;
2764 swr
->wr_id
= tbl_idx
;
2765 swr
->opcode
= IB_WR_SEND
;
2768 udwr
.ah
= &rdev
->sqp_ah
->ib_ah
;
2769 udwr
.remote_qpn
= rdev
->qp1_sqp
->qplib_qp
.id
;
2770 udwr
.remote_qkey
= rdev
->qp1_sqp
->qplib_qp
.qkey
;
2772 /* post data received in the send queue */
2773 rc
= bnxt_re_post_send_shadow_qp(rdev
, qp
, swr
);
2778 static void bnxt_re_process_res_rawqp1_wc(struct ib_wc
*wc
,
2779 struct bnxt_qplib_cqe
*cqe
)
2781 wc
->opcode
= IB_WC_RECV
;
2782 wc
->status
= __rawqp1_to_ib_wc_status(cqe
->status
);
2783 wc
->wc_flags
|= IB_WC_GRH
;
2786 static bool bnxt_re_is_vlan_pkt(struct bnxt_qplib_cqe
*orig_cqe
,
2793 metadata
= orig_cqe
->raweth_qp1_metadata
;
2794 if (orig_cqe
->raweth_qp1_flags2
&
2795 CQ_RES_RAWETH_QP1_RAWETH_QP1_FLAGS2_META_FORMAT_VLAN
) {
2797 CQ_RES_RAWETH_QP1_RAWETH_QP1_METADATA_TPID_MASK
) >>
2798 CQ_RES_RAWETH_QP1_RAWETH_QP1_METADATA_TPID_SFT
);
2799 if (tpid
== ETH_P_8021Q
) {
2801 CQ_RES_RAWETH_QP1_RAWETH_QP1_METADATA_VID_MASK
;
2803 CQ_RES_RAWETH_QP1_RAWETH_QP1_METADATA_PRI_MASK
) >>
2804 CQ_RES_RAWETH_QP1_RAWETH_QP1_METADATA_PRI_SFT
;
2812 static void bnxt_re_process_res_rc_wc(struct ib_wc
*wc
,
2813 struct bnxt_qplib_cqe
*cqe
)
2815 wc
->opcode
= IB_WC_RECV
;
2816 wc
->status
= __rc_to_ib_wc_status(cqe
->status
);
2818 if (cqe
->flags
& CQ_RES_RC_FLAGS_IMM
)
2819 wc
->wc_flags
|= IB_WC_WITH_IMM
;
2820 if (cqe
->flags
& CQ_RES_RC_FLAGS_INV
)
2821 wc
->wc_flags
|= IB_WC_WITH_INVALIDATE
;
2822 if ((cqe
->flags
& (CQ_RES_RC_FLAGS_RDMA
| CQ_RES_RC_FLAGS_IMM
)) ==
2823 (CQ_RES_RC_FLAGS_RDMA
| CQ_RES_RC_FLAGS_IMM
))
2824 wc
->opcode
= IB_WC_RECV_RDMA_WITH_IMM
;
2827 static void bnxt_re_process_res_shadow_qp_wc(struct bnxt_re_qp
*qp
,
2829 struct bnxt_qplib_cqe
*cqe
)
2831 struct bnxt_re_dev
*rdev
= qp
->rdev
;
2832 struct bnxt_re_qp
*qp1_qp
= NULL
;
2833 struct bnxt_qplib_cqe
*orig_cqe
= NULL
;
2834 struct bnxt_re_sqp_entries
*sqp_entry
= NULL
;
2840 tbl_idx
= cqe
->wr_id
;
2842 sqp_entry
= &rdev
->sqp_tbl
[tbl_idx
];
2843 qp1_qp
= sqp_entry
->qp1_qp
;
2844 orig_cqe
= &sqp_entry
->cqe
;
2846 wc
->wr_id
= sqp_entry
->wrid
;
2847 wc
->byte_len
= orig_cqe
->length
;
2848 wc
->qp
= &qp1_qp
->ib_qp
;
2850 wc
->ex
.imm_data
= orig_cqe
->immdata
;
2851 wc
->src_qp
= orig_cqe
->src_qp
;
2852 memcpy(wc
->smac
, orig_cqe
->smac
, ETH_ALEN
);
2853 if (bnxt_re_is_vlan_pkt(orig_cqe
, &vlan_id
, &sl
)) {
2854 wc
->vlan_id
= vlan_id
;
2856 wc
->wc_flags
|= IB_WC_WITH_VLAN
;
2859 wc
->vendor_err
= orig_cqe
->status
;
2861 wc
->opcode
= IB_WC_RECV
;
2862 wc
->status
= __rawqp1_to_ib_wc_status(orig_cqe
->status
);
2863 wc
->wc_flags
|= IB_WC_GRH
;
2865 nw_type
= bnxt_re_check_packet_type(orig_cqe
->raweth_qp1_flags
,
2866 orig_cqe
->raweth_qp1_flags2
);
2868 wc
->network_hdr_type
= bnxt_re_to_ib_nw_type(nw_type
);
2869 wc
->wc_flags
|= IB_WC_WITH_NETWORK_HDR_TYPE
;
2873 static void bnxt_re_process_res_ud_wc(struct ib_wc
*wc
,
2874 struct bnxt_qplib_cqe
*cqe
)
2876 wc
->opcode
= IB_WC_RECV
;
2877 wc
->status
= __rc_to_ib_wc_status(cqe
->status
);
2879 if (cqe
->flags
& CQ_RES_RC_FLAGS_IMM
)
2880 wc
->wc_flags
|= IB_WC_WITH_IMM
;
2881 if (cqe
->flags
& CQ_RES_RC_FLAGS_INV
)
2882 wc
->wc_flags
|= IB_WC_WITH_INVALIDATE
;
2883 if ((cqe
->flags
& (CQ_RES_RC_FLAGS_RDMA
| CQ_RES_RC_FLAGS_IMM
)) ==
2884 (CQ_RES_RC_FLAGS_RDMA
| CQ_RES_RC_FLAGS_IMM
))
2885 wc
->opcode
= IB_WC_RECV_RDMA_WITH_IMM
;
2888 static int send_phantom_wqe(struct bnxt_re_qp
*qp
)
2890 struct bnxt_qplib_qp
*lib_qp
= &qp
->qplib_qp
;
2891 unsigned long flags
;
2894 spin_lock_irqsave(&qp
->sq_lock
, flags
);
2896 rc
= bnxt_re_bind_fence_mw(lib_qp
);
2898 lib_qp
->sq
.phantom_wqe_cnt
++;
2899 dev_dbg(&lib_qp
->sq
.hwq
.pdev
->dev
,
2900 "qp %#x sq->prod %#x sw_prod %#x phantom_wqe_cnt %d\n",
2901 lib_qp
->id
, lib_qp
->sq
.hwq
.prod
,
2902 HWQ_CMP(lib_qp
->sq
.hwq
.prod
, &lib_qp
->sq
.hwq
),
2903 lib_qp
->sq
.phantom_wqe_cnt
);
2906 spin_unlock_irqrestore(&qp
->sq_lock
, flags
);
2910 int bnxt_re_poll_cq(struct ib_cq
*ib_cq
, int num_entries
, struct ib_wc
*wc
)
2912 struct bnxt_re_cq
*cq
= container_of(ib_cq
, struct bnxt_re_cq
, ib_cq
);
2913 struct bnxt_re_qp
*qp
;
2914 struct bnxt_qplib_cqe
*cqe
;
2915 int i
, ncqe
, budget
;
2916 struct bnxt_qplib_q
*sq
;
2917 struct bnxt_qplib_qp
*lib_qp
;
2919 struct bnxt_re_sqp_entries
*sqp_entry
= NULL
;
2920 unsigned long flags
;
2922 spin_lock_irqsave(&cq
->cq_lock
, flags
);
2923 budget
= min_t(u32
, num_entries
, cq
->max_cql
);
2924 num_entries
= budget
;
2926 dev_err(rdev_to_dev(cq
->rdev
), "POLL CQ : no CQL to use");
2932 ncqe
= bnxt_qplib_poll_cq(&cq
->qplib_cq
, cqe
, budget
, &lib_qp
);
2935 if (sq
->send_phantom
) {
2936 qp
= container_of(lib_qp
,
2937 struct bnxt_re_qp
, qplib_qp
);
2938 if (send_phantom_wqe(qp
) == -ENOMEM
)
2939 dev_err(rdev_to_dev(cq
->rdev
),
2940 "Phantom failed! Scheduled to send again\n");
2942 sq
->send_phantom
= false;
2946 ncqe
+= bnxt_qplib_process_flush_list(&cq
->qplib_cq
,
2953 for (i
= 0; i
< ncqe
; i
++, cqe
++) {
2954 /* Transcribe each qplib_wqe back to ib_wc */
2955 memset(wc
, 0, sizeof(*wc
));
2957 wc
->wr_id
= cqe
->wr_id
;
2958 wc
->byte_len
= cqe
->length
;
2960 ((struct bnxt_qplib_qp
*)
2961 (unsigned long)(cqe
->qp_handle
),
2962 struct bnxt_re_qp
, qplib_qp
);
2964 dev_err(rdev_to_dev(cq
->rdev
),
2965 "POLL CQ : bad QP handle");
2968 wc
->qp
= &qp
->ib_qp
;
2969 wc
->ex
.imm_data
= cqe
->immdata
;
2970 wc
->src_qp
= cqe
->src_qp
;
2971 memcpy(wc
->smac
, cqe
->smac
, ETH_ALEN
);
2973 wc
->vendor_err
= cqe
->status
;
2975 switch (cqe
->opcode
) {
2976 case CQ_BASE_CQE_TYPE_REQ
:
2977 if (qp
->qplib_qp
.id
==
2978 qp
->rdev
->qp1_sqp
->qplib_qp
.id
) {
2979 /* Handle this completion with
2980 * the stored completion
2982 memset(wc
, 0, sizeof(*wc
));
2985 bnxt_re_process_req_wc(wc
, cqe
);
2987 case CQ_BASE_CQE_TYPE_RES_RAWETH_QP1
:
2991 rc
= bnxt_re_process_raw_qp_pkt_rx
2994 memset(wc
, 0, sizeof(*wc
));
2999 /* Errors need not be looped back.
3000 * But change the wr_id to the one
3001 * stored in the table
3003 tbl_idx
= cqe
->wr_id
;
3004 sqp_entry
= &cq
->rdev
->sqp_tbl
[tbl_idx
];
3005 wc
->wr_id
= sqp_entry
->wrid
;
3006 bnxt_re_process_res_rawqp1_wc(wc
, cqe
);
3008 case CQ_BASE_CQE_TYPE_RES_RC
:
3009 bnxt_re_process_res_rc_wc(wc
, cqe
);
3011 case CQ_BASE_CQE_TYPE_RES_UD
:
3012 if (qp
->qplib_qp
.id
==
3013 qp
->rdev
->qp1_sqp
->qplib_qp
.id
) {
3014 /* Handle this completion with
3015 * the stored completion
3020 bnxt_re_process_res_shadow_qp_wc
3025 bnxt_re_process_res_ud_wc(wc
, cqe
);
3028 dev_err(rdev_to_dev(cq
->rdev
),
3029 "POLL CQ : type 0x%x not handled",
3038 spin_unlock_irqrestore(&cq
->cq_lock
, flags
);
3039 return num_entries
- budget
;
3042 int bnxt_re_req_notify_cq(struct ib_cq
*ib_cq
,
3043 enum ib_cq_notify_flags ib_cqn_flags
)
3045 struct bnxt_re_cq
*cq
= container_of(ib_cq
, struct bnxt_re_cq
, ib_cq
);
3046 int type
= 0, rc
= 0;
3047 unsigned long flags
;
3049 spin_lock_irqsave(&cq
->cq_lock
, flags
);
3050 /* Trigger on the very next completion */
3051 if (ib_cqn_flags
& IB_CQ_NEXT_COMP
)
3052 type
= DBR_DBR_TYPE_CQ_ARMALL
;
3053 /* Trigger on the next solicited completion */
3054 else if (ib_cqn_flags
& IB_CQ_SOLICITED
)
3055 type
= DBR_DBR_TYPE_CQ_ARMSE
;
3057 /* Poll to see if there are missed events */
3058 if ((ib_cqn_flags
& IB_CQ_REPORT_MISSED_EVENTS
) &&
3059 !(bnxt_qplib_is_cq_empty(&cq
->qplib_cq
))) {
3063 bnxt_qplib_req_notify_cq(&cq
->qplib_cq
, type
);
3066 spin_unlock_irqrestore(&cq
->cq_lock
, flags
);
3070 /* Memory Regions */
3071 struct ib_mr
*bnxt_re_get_dma_mr(struct ib_pd
*ib_pd
, int mr_access_flags
)
3073 struct bnxt_re_pd
*pd
= container_of(ib_pd
, struct bnxt_re_pd
, ib_pd
);
3074 struct bnxt_re_dev
*rdev
= pd
->rdev
;
3075 struct bnxt_re_mr
*mr
;
3079 mr
= kzalloc(sizeof(*mr
), GFP_KERNEL
);
3081 return ERR_PTR(-ENOMEM
);
3084 mr
->qplib_mr
.pd
= &pd
->qplib_pd
;
3085 mr
->qplib_mr
.flags
= __from_ib_access_flags(mr_access_flags
);
3086 mr
->qplib_mr
.type
= CMDQ_ALLOCATE_MRW_MRW_FLAGS_PMR
;
3088 /* Allocate and register 0 as the address */
3089 rc
= bnxt_qplib_alloc_mrw(&rdev
->qplib_res
, &mr
->qplib_mr
);
3093 mr
->qplib_mr
.hwq
.level
= PBL_LVL_MAX
;
3094 mr
->qplib_mr
.total_size
= -1; /* Infinte length */
3095 rc
= bnxt_qplib_reg_mr(&rdev
->qplib_res
, &mr
->qplib_mr
, &pbl
, 0, false);
3099 mr
->ib_mr
.lkey
= mr
->qplib_mr
.lkey
;
3100 if (mr_access_flags
& (IB_ACCESS_REMOTE_WRITE
| IB_ACCESS_REMOTE_READ
|
3101 IB_ACCESS_REMOTE_ATOMIC
))
3102 mr
->ib_mr
.rkey
= mr
->ib_mr
.lkey
;
3103 atomic_inc(&rdev
->mr_count
);
3108 bnxt_qplib_free_mrw(&rdev
->qplib_res
, &mr
->qplib_mr
);
3114 int bnxt_re_dereg_mr(struct ib_mr
*ib_mr
)
3116 struct bnxt_re_mr
*mr
= container_of(ib_mr
, struct bnxt_re_mr
, ib_mr
);
3117 struct bnxt_re_dev
*rdev
= mr
->rdev
;
3120 rc
= bnxt_qplib_free_mrw(&rdev
->qplib_res
, &mr
->qplib_mr
);
3122 dev_err(rdev_to_dev(rdev
), "Dereg MR failed: %#x\n", rc
);
3127 rc
= bnxt_qplib_free_fast_reg_page_list(&rdev
->qplib_res
,
3133 if (!IS_ERR_OR_NULL(mr
->ib_umem
))
3134 ib_umem_release(mr
->ib_umem
);
3137 atomic_dec(&rdev
->mr_count
);
3141 static int bnxt_re_set_page(struct ib_mr
*ib_mr
, u64 addr
)
3143 struct bnxt_re_mr
*mr
= container_of(ib_mr
, struct bnxt_re_mr
, ib_mr
);
3145 if (unlikely(mr
->npages
== mr
->qplib_frpl
.max_pg_ptrs
))
3148 mr
->pages
[mr
->npages
++] = addr
;
3152 int bnxt_re_map_mr_sg(struct ib_mr
*ib_mr
, struct scatterlist
*sg
, int sg_nents
,
3153 unsigned int *sg_offset
)
3155 struct bnxt_re_mr
*mr
= container_of(ib_mr
, struct bnxt_re_mr
, ib_mr
);
3158 return ib_sg_to_pages(ib_mr
, sg
, sg_nents
, sg_offset
, bnxt_re_set_page
);
3161 struct ib_mr
*bnxt_re_alloc_mr(struct ib_pd
*ib_pd
, enum ib_mr_type type
,
3164 struct bnxt_re_pd
*pd
= container_of(ib_pd
, struct bnxt_re_pd
, ib_pd
);
3165 struct bnxt_re_dev
*rdev
= pd
->rdev
;
3166 struct bnxt_re_mr
*mr
= NULL
;
3169 if (type
!= IB_MR_TYPE_MEM_REG
) {
3170 dev_dbg(rdev_to_dev(rdev
), "MR type 0x%x not supported", type
);
3171 return ERR_PTR(-EINVAL
);
3173 if (max_num_sg
> MAX_PBL_LVL_1_PGS
)
3174 return ERR_PTR(-EINVAL
);
3176 mr
= kzalloc(sizeof(*mr
), GFP_KERNEL
);
3178 return ERR_PTR(-ENOMEM
);
3181 mr
->qplib_mr
.pd
= &pd
->qplib_pd
;
3182 mr
->qplib_mr
.flags
= BNXT_QPLIB_FR_PMR
;
3183 mr
->qplib_mr
.type
= CMDQ_ALLOCATE_MRW_MRW_FLAGS_PMR
;
3185 rc
= bnxt_qplib_alloc_mrw(&rdev
->qplib_res
, &mr
->qplib_mr
);
3189 mr
->ib_mr
.lkey
= mr
->qplib_mr
.lkey
;
3190 mr
->ib_mr
.rkey
= mr
->ib_mr
.lkey
;
3192 mr
->pages
= kcalloc(max_num_sg
, sizeof(u64
), GFP_KERNEL
);
3197 rc
= bnxt_qplib_alloc_fast_reg_page_list(&rdev
->qplib_res
,
3198 &mr
->qplib_frpl
, max_num_sg
);
3200 dev_err(rdev_to_dev(rdev
),
3201 "Failed to allocate HW FR page list");
3205 atomic_inc(&rdev
->mr_count
);
3209 bnxt_qplib_free_mrw(&rdev
->qplib_res
, &mr
->qplib_mr
);
3216 struct ib_mw
*bnxt_re_alloc_mw(struct ib_pd
*ib_pd
, enum ib_mw_type type
,
3217 struct ib_udata
*udata
)
3219 struct bnxt_re_pd
*pd
= container_of(ib_pd
, struct bnxt_re_pd
, ib_pd
);
3220 struct bnxt_re_dev
*rdev
= pd
->rdev
;
3221 struct bnxt_re_mw
*mw
;
3224 mw
= kzalloc(sizeof(*mw
), GFP_KERNEL
);
3226 return ERR_PTR(-ENOMEM
);
3228 mw
->qplib_mw
.pd
= &pd
->qplib_pd
;
3230 mw
->qplib_mw
.type
= (type
== IB_MW_TYPE_1
?
3231 CMDQ_ALLOCATE_MRW_MRW_FLAGS_MW_TYPE1
:
3232 CMDQ_ALLOCATE_MRW_MRW_FLAGS_MW_TYPE2B
);
3233 rc
= bnxt_qplib_alloc_mrw(&rdev
->qplib_res
, &mw
->qplib_mw
);
3235 dev_err(rdev_to_dev(rdev
), "Allocate MW failed!");
3238 mw
->ib_mw
.rkey
= mw
->qplib_mw
.rkey
;
3240 atomic_inc(&rdev
->mw_count
);
3248 int bnxt_re_dealloc_mw(struct ib_mw
*ib_mw
)
3250 struct bnxt_re_mw
*mw
= container_of(ib_mw
, struct bnxt_re_mw
, ib_mw
);
3251 struct bnxt_re_dev
*rdev
= mw
->rdev
;
3254 rc
= bnxt_qplib_free_mrw(&rdev
->qplib_res
, &mw
->qplib_mw
);
3256 dev_err(rdev_to_dev(rdev
), "Free MW failed: %#x\n", rc
);
3261 atomic_dec(&rdev
->mw_count
);
3266 struct ib_mr
*bnxt_re_reg_user_mr(struct ib_pd
*ib_pd
, u64 start
, u64 length
,
3267 u64 virt_addr
, int mr_access_flags
,
3268 struct ib_udata
*udata
)
3270 struct bnxt_re_pd
*pd
= container_of(ib_pd
, struct bnxt_re_pd
, ib_pd
);
3271 struct bnxt_re_dev
*rdev
= pd
->rdev
;
3272 struct bnxt_re_mr
*mr
;
3273 struct ib_umem
*umem
;
3274 u64
*pbl_tbl
, *pbl_tbl_orig
;
3275 int i
, umem_pgs
, pages
, rc
;
3276 struct scatterlist
*sg
;
3279 if (length
> BNXT_RE_MAX_MR_SIZE
) {
3280 dev_err(rdev_to_dev(rdev
), "MR Size: %lld > Max supported:%ld\n",
3281 length
, BNXT_RE_MAX_MR_SIZE
);
3282 return ERR_PTR(-ENOMEM
);
3285 mr
= kzalloc(sizeof(*mr
), GFP_KERNEL
);
3287 return ERR_PTR(-ENOMEM
);
3290 mr
->qplib_mr
.pd
= &pd
->qplib_pd
;
3291 mr
->qplib_mr
.flags
= __from_ib_access_flags(mr_access_flags
);
3292 mr
->qplib_mr
.type
= CMDQ_ALLOCATE_MRW_MRW_FLAGS_MR
;
3294 umem
= ib_umem_get(ib_pd
->uobject
->context
, start
, length
,
3295 mr_access_flags
, 0);
3297 dev_err(rdev_to_dev(rdev
), "Failed to get umem");
3303 rc
= bnxt_qplib_alloc_mrw(&rdev
->qplib_res
, &mr
->qplib_mr
);
3305 dev_err(rdev_to_dev(rdev
), "Failed to allocate MR");
3308 /* The fixed portion of the rkey is the same as the lkey */
3309 mr
->ib_mr
.rkey
= mr
->qplib_mr
.rkey
;
3311 mr
->qplib_mr
.va
= virt_addr
;
3312 umem_pgs
= ib_umem_page_count(umem
);
3314 dev_err(rdev_to_dev(rdev
), "umem is invalid!");
3318 mr
->qplib_mr
.total_size
= length
;
3320 pbl_tbl
= kcalloc(umem_pgs
, sizeof(u64
*), GFP_KERNEL
);
3325 pbl_tbl_orig
= pbl_tbl
;
3327 if (umem
->hugetlb
) {
3328 dev_err(rdev_to_dev(rdev
), "umem hugetlb not supported!");
3333 if (umem
->page_shift
!= PAGE_SHIFT
) {
3334 dev_err(rdev_to_dev(rdev
), "umem page shift unsupported!");
3338 /* Map umem buf ptrs to the PBL */
3339 for_each_sg(umem
->sg_head
.sgl
, sg
, umem
->nmap
, entry
) {
3340 pages
= sg_dma_len(sg
) >> umem
->page_shift
;
3341 for (i
= 0; i
< pages
; i
++, pbl_tbl
++)
3342 *pbl_tbl
= sg_dma_address(sg
) + (i
<< umem
->page_shift
);
3344 rc
= bnxt_qplib_reg_mr(&rdev
->qplib_res
, &mr
->qplib_mr
, pbl_tbl_orig
,
3347 dev_err(rdev_to_dev(rdev
), "Failed to register user MR");
3351 kfree(pbl_tbl_orig
);
3353 mr
->ib_mr
.lkey
= mr
->qplib_mr
.lkey
;
3354 mr
->ib_mr
.rkey
= mr
->qplib_mr
.lkey
;
3355 atomic_inc(&rdev
->mr_count
);
3359 kfree(pbl_tbl_orig
);
3361 bnxt_qplib_free_mrw(&rdev
->qplib_res
, &mr
->qplib_mr
);
3363 ib_umem_release(umem
);
3369 struct ib_ucontext
*bnxt_re_alloc_ucontext(struct ib_device
*ibdev
,
3370 struct ib_udata
*udata
)
3372 struct bnxt_re_dev
*rdev
= to_bnxt_re_dev(ibdev
, ibdev
);
3373 struct bnxt_re_uctx_resp resp
;
3374 struct bnxt_re_ucontext
*uctx
;
3375 struct bnxt_qplib_dev_attr
*dev_attr
= &rdev
->dev_attr
;
3378 dev_dbg(rdev_to_dev(rdev
), "ABI version requested %d",
3379 ibdev
->uverbs_abi_ver
);
3381 if (ibdev
->uverbs_abi_ver
!= BNXT_RE_ABI_VERSION
) {
3382 dev_dbg(rdev_to_dev(rdev
), " is different from the device %d ",
3383 BNXT_RE_ABI_VERSION
);
3384 return ERR_PTR(-EPERM
);
3387 uctx
= kzalloc(sizeof(*uctx
), GFP_KERNEL
);
3389 return ERR_PTR(-ENOMEM
);
3393 uctx
->shpg
= (void *)__get_free_page(GFP_KERNEL
);
3398 spin_lock_init(&uctx
->sh_lock
);
3400 resp
.dev_id
= rdev
->en_dev
->pdev
->devfn
; /*Temp, Use idr_alloc instead*/
3401 resp
.max_qp
= rdev
->qplib_ctx
.qpc_count
;
3402 resp
.pg_size
= PAGE_SIZE
;
3403 resp
.cqe_sz
= sizeof(struct cq_base
);
3404 resp
.max_cqd
= dev_attr
->max_cq_wqes
;
3407 rc
= ib_copy_to_udata(udata
, &resp
, sizeof(resp
));
3409 dev_err(rdev_to_dev(rdev
), "Failed to copy user context");
3414 return &uctx
->ib_uctx
;
3416 free_page((unsigned long)uctx
->shpg
);
3423 int bnxt_re_dealloc_ucontext(struct ib_ucontext
*ib_uctx
)
3425 struct bnxt_re_ucontext
*uctx
= container_of(ib_uctx
,
3426 struct bnxt_re_ucontext
,
3429 struct bnxt_re_dev
*rdev
= uctx
->rdev
;
3433 free_page((unsigned long)uctx
->shpg
);
3435 if (uctx
->dpi
.dbr
) {
3436 /* Free DPI only if this is the first PD allocated by the
3437 * application and mark the context dpi as NULL
3439 rc
= bnxt_qplib_dealloc_dpi(&rdev
->qplib_res
,
3440 &rdev
->qplib_res
.dpi_tbl
,
3443 dev_err(rdev_to_dev(rdev
), "Deallocate HW DPI failed!");
3444 /* Don't fail, continue*/
3445 uctx
->dpi
.dbr
= NULL
;
3452 /* Helper function to mmap the virtual memory from user app */
3453 int bnxt_re_mmap(struct ib_ucontext
*ib_uctx
, struct vm_area_struct
*vma
)
3455 struct bnxt_re_ucontext
*uctx
= container_of(ib_uctx
,
3456 struct bnxt_re_ucontext
,
3458 struct bnxt_re_dev
*rdev
= uctx
->rdev
;
3461 if (vma
->vm_end
- vma
->vm_start
!= PAGE_SIZE
)
3464 if (vma
->vm_pgoff
) {
3465 vma
->vm_page_prot
= pgprot_noncached(vma
->vm_page_prot
);
3466 if (io_remap_pfn_range(vma
, vma
->vm_start
, vma
->vm_pgoff
,
3467 PAGE_SIZE
, vma
->vm_page_prot
)) {
3468 dev_err(rdev_to_dev(rdev
), "Failed to map DPI");
3472 pfn
= virt_to_phys(uctx
->shpg
) >> PAGE_SHIFT
;
3473 if (remap_pfn_range(vma
, vma
->vm_start
,
3474 pfn
, PAGE_SIZE
, vma
->vm_page_prot
)) {
3475 dev_err(rdev_to_dev(rdev
),
3476 "Failed to map shared page");