|
| 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