Skip to content

Commit 9cc4b5f

Browse files
committed
RDMA/hfi2: Add verbs support for CN5000
Add InfiniBand verbs support for the hfi2 driver, which drives the Cornelis Networks CN5000 adapter. Signed-off-by: Dennis Dalessandro <dennis.dalessandro@cornelisnetworks.com>
1 parent 8d91654 commit 9cc4b5f

9 files changed

Lines changed: 1293 additions & 1 deletion

File tree

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -754,7 +754,7 @@ add_subdirectory(providers/vmw_pvrdma)
754754
endif()
755755

756756
add_subdirectory(providers/hfi1verbs)
757-
add_subdirectory(providers/ipathverbs)
757+
add_subdirectory(providers/hfi2verbs)
758758
add_subdirectory(providers/rxe)
759759
add_subdirectory(providers/rxe/man)
760760
add_subdirectory(providers/siw)

MAINTAINERS

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ M: Dennis Dalessandro <dennis.dalessandro@cornelisnetworks.com>
7171
S: Supported
7272
F: providers/hfi1verbs/
7373

74+
HFI2 USERSPACE PROVIDER (for hf2.ko)
75+
M: Dennis Dalessandro <dennis.dalessandro@cornelisnetworks.com>
76+
S: Supported
77+
F: providers/hfi2verbs/
78+
7479
HNS USERSPACE PROVIDER (for hns-roce-hw-v2.ko)
7580
M: Junxian Huang <huangjunxian6@hisilicon.com>
7681
M: Chengchang Tang <tangchengchang@huawei.com>

kernel-boot/rdma-description.rules

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ DRIVERS=="ib_qib", ENV{ID_RDMA_INFINIBAND}="1"
2020

2121
# Hardware that supports OPA
2222
DRIVERS=="hfi1", ENV{ID_RDMA_OPA}="1"
23+
DRIVERS=="hfi2", ENV{ID_RDMA_OPA}="1"
2324

2425
# Hardware that supports iWarp
2526
DRIVERS=="cxgb4", ENV{ID_RDMA_IWARP}="1"

libibverbs/verbs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2322,6 +2322,7 @@ extern const struct verbs_device_ops verbs_provider_cxgb4;
23222322
extern const struct verbs_device_ops verbs_provider_efa;
23232323
extern const struct verbs_device_ops verbs_provider_erdma;
23242324
extern const struct verbs_device_ops verbs_provider_hfi1verbs;
2325+
extern const struct verbs_device_ops verbs_provider_hf21verbs;
23252326
extern const struct verbs_device_ops verbs_provider_hns;
23262327
extern const struct verbs_device_ops verbs_provider_ipathverbs;
23272328
extern const struct verbs_device_ops verbs_provider_irdma;

providers/hfi2verbs/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
rdma_provider(hfi2verbs
2+
hfiverbs.c
3+
verbs.c
4+
)

providers/hfi2verbs/hfi-abi.h

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
/*
2+
3+
This file is provided under a dual BSD/GPLv2 license. When using or
4+
redistributing this file, you may do so under either license.
5+
6+
GPL LICENSE SUMMARY
7+
8+
Copyright(c) 2025 Cornelis Networks
9+
Copyright (c) 2026 Cornelis Networks
10+
11+
This program is free software; you can redistribute it and/or modify
12+
it under the terms of version 2 of the GNU General Public License as
13+
published by the Free Software Foundation.
14+
15+
This program is distributed in the hope that it will be useful, but
16+
WITHOUT ANY WARRANTY; without even the implied warranty of
17+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18+
General Public License for more details.
19+
20+
BSD LICENSE
21+
22+
Copyright(c) 2025 Cornelis Networks
23+
Copyright (c) 2026 Cornelis Networks
24+
25+
Redistribution and use in source and binary forms, with or without
26+
modification, are permitted provided that the following conditions
27+
are met:
28+
29+
* Redistributions of source code must retain the above copyright
30+
notice, this list of conditions and the following disclaimer.
31+
* Redistributions in binary form must reproduce the above copyright
32+
notice, this list of conditions and the following disclaimer in
33+
the documentation and/or other materials provided with the
34+
distribution.
35+
* Neither the name of Intel Corporation nor the names of its
36+
contributors may be used to endorse or promote products derived
37+
from this software without specific prior written permission.
38+
39+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
40+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
41+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
42+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
43+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
45+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
46+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
47+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
48+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
49+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
50+
51+
Copyright (c) 2015 Intel Corporation
52+
Copyright (C) 2006-2007 QLogic Corporation, All rights reserved.
53+
54+
*/
55+
56+
#ifndef HFI2_ABI_H
57+
#define HFI2_ABI_H
58+
59+
#include <infiniband/kern-abi.h>
60+
61+
struct hfi2_get_context_resp {
62+
struct ib_uverbs_get_context_resp ibv_resp;
63+
__u32 version;
64+
};
65+
66+
struct hfi2_create_cq_resp {
67+
struct ib_uverbs_create_cq_resp ibv_resp;
68+
__u64 offset;
69+
};
70+
71+
struct hfi2_resize_cq_resp {
72+
struct ib_uverbs_resize_cq_resp ibv_resp;
73+
__u64 offset;
74+
};
75+
76+
struct hfi2_create_qp_resp {
77+
struct ib_uverbs_create_qp_resp ibv_resp;
78+
__u64 offset;
79+
};
80+
81+
struct hfi2_create_srq_resp {
82+
struct ib_uverbs_create_srq_resp ibv_resp;
83+
__u64 offset;
84+
};
85+
86+
struct hfi2_modify_srq_cmd {
87+
struct ibv_modify_srq ibv_cmd;
88+
__u64 offset_addr;
89+
};
90+
91+
#endif /* HFI2_ABI_H */

providers/hfi2verbs/hfiverbs.c

Lines changed: 207 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,207 @@
1+
/*
2+
3+
This file is provided under a dual BSD/GPLv2 license. When using or
4+
redistributing this file, you may do so under either license.
5+
6+
GPL LICENSE SUMMARY
7+
8+
Copyright(c) 2015 Intel Corporation.
9+
Copyright (c) 2026 Cornelis Networks
10+
11+
This program is free software; you can redistribute it and/or modify
12+
it under the terms of version 2 of the GNU General Public License as
13+
published by the Free Software Foundation.
14+
15+
This program is distributed in the hope that it will be useful, but
16+
WITHOUT ANY WARRANTY; without even the implied warranty of
17+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18+
General Public License for more details.
19+
20+
Contact Information:
21+
Intel Corporation
22+
www.intel.com
23+
24+
BSD LICENSE
25+
26+
Copyright(c) 2015 Intel Corporation.
27+
Copyright (c) 2026 Cornelis Networks
28+
29+
Redistribution and use in source and binary forms, with or without
30+
modification, are permitted provided that the following conditions
31+
are met:
32+
33+
* Redistributions of source code must retain the above copyright
34+
notice, this list of conditions and the following disclaimer.
35+
* Redistributions in binary form must reproduce the above copyright
36+
notice, this list of conditions and the following disclaimer in
37+
the documentation and/or other materials provided with the
38+
distribution.
39+
* Neither the name of Intel Corporation nor the names of its
40+
contributors may be used to endorse or promote products derived
41+
from this software without specific prior written permission.
42+
43+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
44+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
45+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
46+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
47+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
48+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
49+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
50+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
51+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
52+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
53+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
54+
55+
Copyright (C) 2006-2007 QLogic Corporation, All rights reserved.
56+
Copyright (c) 2005. PathScale, Inc. All rights reserved.
57+
58+
*/
59+
60+
#include <config.h>
61+
62+
#include <stdio.h>
63+
#include <stdlib.h>
64+
#include <unistd.h>
65+
#include <string.h>
66+
67+
#include "hfiverbs.h"
68+
#include "hfi-abi.h"
69+
70+
static void hfi2_free_context(struct ibv_context *ibctx);
71+
72+
#ifndef PCI_VENDOR_ID_CORNELIS
73+
#define PCI_VENDOR_ID_CORNELIS 0x434e
74+
#endif
75+
76+
#ifndef PCI_DEVICE_ID_HFI2_0
77+
#define PCI_DEVICE_ID_HFI2_0 0x0001
78+
#endif
79+
80+
#define HFI2(v, d) \
81+
VERBS_PCI_MATCH(PCI_VENDOR_ID_##v, PCI_DEVICE_ID_HFI2_##d, NULL)
82+
static const struct verbs_match_ent hca_table[] = { VERBS_DRIVER_ID(
83+
RDMA_DRIVER_HFI2),
84+
HFI2(CORNELIS, 0),
85+
{} };
86+
87+
static const struct verbs_context_ops hfi2_ctx_common_ops = {
88+
.free_context = hfi2_free_context,
89+
.query_device_ex = hfi2_query_device,
90+
.query_port = hfi2_query_port,
91+
92+
.alloc_pd = hfi2_alloc_pd,
93+
.dealloc_pd = hfi2_free_pd,
94+
95+
.reg_mr = hfi2_reg_mr,
96+
.dereg_mr = hfi2_dereg_mr,
97+
98+
.create_cq = hfi2_create_cq,
99+
.poll_cq = hfi2_poll_cq,
100+
.req_notify_cq = ibv_cmd_req_notify_cq,
101+
.resize_cq = hfi2_resize_cq,
102+
.destroy_cq = hfi2_destroy_cq,
103+
104+
.create_srq = hfi2_create_srq,
105+
.modify_srq = hfi2_modify_srq,
106+
.query_srq = hfi2_query_srq,
107+
.destroy_srq = hfi2_destroy_srq,
108+
.post_srq_recv = hfi2_post_srq_recv,
109+
110+
.create_qp = hfi2_create_qp,
111+
.query_qp = hfi2_query_qp,
112+
.modify_qp = hfi2_modify_qp,
113+
.destroy_qp = hfi2_destroy_qp,
114+
115+
.post_send = hfi2_post_send,
116+
.post_recv = hfi2_post_recv,
117+
118+
.create_ah = hfi2_create_ah,
119+
.destroy_ah = hfi2_destroy_ah,
120+
121+
.attach_mcast = ibv_cmd_attach_mcast,
122+
.detach_mcast = ibv_cmd_detach_mcast
123+
};
124+
125+
static const struct verbs_context_ops hfi2_ctx_v1_ops = {
126+
.create_cq = hfi2_create_cq_v1,
127+
.create_qp = hfi2_create_qp_v1,
128+
.create_srq = hfi2_create_srq_v1,
129+
.destroy_cq = hfi2_destroy_cq_v1,
130+
.destroy_qp = hfi2_destroy_qp_v1,
131+
.destroy_srq = hfi2_destroy_srq_v1,
132+
.modify_srq = hfi2_modify_srq_v1,
133+
.poll_cq = ibv_cmd_poll_cq,
134+
.post_recv = ibv_cmd_post_recv,
135+
.post_srq_recv = ibv_cmd_post_srq_recv,
136+
.resize_cq = hfi2_resize_cq_v1,
137+
};
138+
139+
static struct verbs_context *hfi2_alloc_context(struct ibv_device *ibdev,
140+
int cmd_fd, void *private_data)
141+
{
142+
struct hfi2_context *context;
143+
struct ibv_get_context cmd;
144+
struct ib_uverbs_get_context_resp resp;
145+
struct hfi2_device *dev;
146+
147+
context = verbs_init_and_alloc_context(ibdev, cmd_fd, context, ibv_ctx,
148+
RDMA_DRIVER_HFI2);
149+
if (!context)
150+
return NULL;
151+
152+
if (ibv_cmd_get_context(&context->ibv_ctx, &cmd, sizeof cmd, NULL,
153+
&resp, sizeof resp))
154+
goto err_free;
155+
156+
verbs_set_ops(&context->ibv_ctx, &hfi2_ctx_common_ops);
157+
158+
dev = to_idev(ibdev);
159+
if (dev->abi_version == 1)
160+
verbs_set_ops(&context->ibv_ctx, &hfi2_ctx_v1_ops);
161+
162+
return &context->ibv_ctx;
163+
164+
err_free:
165+
verbs_uninit_context(&context->ibv_ctx);
166+
free(context);
167+
return NULL;
168+
}
169+
170+
static void hfi2_free_context(struct ibv_context *ibctx)
171+
{
172+
struct hfi2_context *context = to_ictx(ibctx);
173+
174+
verbs_uninit_context(&context->ibv_ctx);
175+
free(context);
176+
}
177+
178+
static void hfi2_uninit_device(struct verbs_device *verbs_device)
179+
{
180+
struct hfi2_device *dev = to_idev(&verbs_device->device);
181+
182+
free(dev);
183+
}
184+
185+
static struct verbs_device *hfi2_device_alloc(struct verbs_sysfs_dev *sysfs_dev)
186+
{
187+
struct hfi2_device *dev;
188+
189+
dev = calloc(1, sizeof(*dev));
190+
if (!dev)
191+
return NULL;
192+
193+
dev->abi_version = sysfs_dev->abi_ver;
194+
195+
return &dev->ibv_dev;
196+
}
197+
198+
static const struct verbs_device_ops hfi2_dev_ops = {
199+
.name = "hfi2verbs",
200+
.match_min_abi_version = 0,
201+
.match_max_abi_version = INT_MAX,
202+
.match_table = hca_table,
203+
.alloc_device = hfi2_device_alloc,
204+
.uninit_device = hfi2_uninit_device,
205+
.alloc_context = hfi2_alloc_context,
206+
};
207+
PROVIDER_DRIVER(hfi2verbs, hfi2_dev_ops);

0 commit comments

Comments
 (0)