| 1 | /* |
| 2 | * Copyright (c) 2012-2016 VMware, Inc. All rights reserved. |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of EITHER the GNU General Public License |
| 6 | * version 2 as published by the Free Software Foundation or the BSD |
| 7 | * 2-Clause License. This program is distributed in the hope that it |
| 8 | * will be useful, but WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED |
| 9 | * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. |
| 10 | * See the GNU General Public License version 2 for more details at |
| 11 | * http://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html. |
| 12 | * |
| 13 | * You should have received a copy of the GNU General Public License |
| 14 | * along with this program available in the file COPYING in the main |
| 15 | * directory of this source tree. |
| 16 | * |
| 17 | * The BSD 2-Clause License |
| 18 | * |
| 19 | * Redistribution and use in source and binary forms, with or |
| 20 | * without modification, are permitted provided that the following |
| 21 | * conditions are met: |
| 22 | * |
| 23 | * - Redistributions of source code must retain the above |
| 24 | * copyright notice, this list of conditions and the following |
| 25 | * disclaimer. |
| 26 | * |
| 27 | * - Redistributions in binary form must reproduce the above |
| 28 | * copyright notice, this list of conditions and the following |
| 29 | * disclaimer in the documentation and/or other materials |
| 30 | * provided with the distribution. |
| 31 | * |
| 32 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 33 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 34 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
| 35 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
| 36 | * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, |
| 37 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 38 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| 39 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 40 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
| 41 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 42 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED |
| 43 | * OF THE POSSIBILITY OF SUCH DAMAGE. |
| 44 | */ |
| 45 | |
| 46 | #include "pvrdma.h"cxx . . $ `<file>/providers/vmw_pvrdma/pvrdma.h`/ |
| 47 | |
| 48 | static void pvrdma_free_contextcxx . . $ pvrdma_free_context(571ef9bd68226534).(struct ibv_contextcxx . . $ ibv_context# *ibctx); |
| 49 | |
| 50 | /* |
| 51 | * VMware PVRDMA vendor id and PCI device id. |
| 52 | */ |
| 53 | #define PCI_VENDOR_ID_VMWAREcxx . . $ `providers/vmw_pvrdma/pvrdma_main.c:53:9`! 0x15AD |
| 54 | #define PCI_DEVICE_ID_VMWARE_PVRDMAcxx . . $ `providers/vmw_pvrdma/pvrdma_main.c:54:9`! 0x0820 |
| 55 | |
| 56 | static const struct verbs_context_opscxx . . $ verbs_context_ops# pvrdma_ctx_opscxx . . $ pvrdma_ctx_ops. = { |
| 57 | .free_context = pvrdma_free_contextcxx . . $ pvrdma_free_context(571ef9bd68226534)., |
| 58 | .query_device_ex = pvrdma_query_devicecxx . . $ pvrdma_query_device(600f39d3ad8b999d)., |
| 59 | .query_port = pvrdma_query_portcxx . . $ pvrdma_query_port(f4134cca67356677)., |
| 60 | .alloc_pd = pvrdma_alloc_pdcxx . . $ pvrdma_alloc_pd(12046b8d6aa086)., |
| 61 | .dealloc_pd = pvrdma_free_pdcxx . . $ pvrdma_free_pd(4f8183e190a1d873)., |
| 62 | |
| 63 | .reg_mr = pvrdma_reg_mrcxx . . $ pvrdma_reg_mr(1705cf5ff6f324e3)., |
| 64 | .dereg_mr = pvrdma_dereg_mrcxx . . $ pvrdma_dereg_mr(6b7007a84e0fc558)., |
| 65 | .create_cq = pvrdma_create_cqcxx . . $ pvrdma_create_cq(e75e1bd4290ebb9e)., |
| 66 | .poll_cq = pvrdma_poll_cqcxx . . $ pvrdma_poll_cq(857ede731a5bae54)., |
| 67 | .req_notify_cq = pvrdma_req_notify_cqcxx . . $ pvrdma_req_notify_cq(f1ac00dc805d1818)., |
| 68 | .destroy_cq = pvrdma_destroy_cqcxx . . $ pvrdma_destroy_cq(c792dddc4b255f9b)., |
| 69 | |
| 70 | .create_qp = pvrdma_create_qpcxx . . $ pvrdma_create_qp(784fbaaaab3d3bdc)., |
| 71 | .query_qp = pvrdma_query_qpcxx . . $ pvrdma_query_qp(919f82671de84871)., |
| 72 | .modify_qp = pvrdma_modify_qpcxx . . $ pvrdma_modify_qp(e70e15b4f2cf5901)., |
| 73 | .destroy_qp = pvrdma_destroy_qpcxx . . $ pvrdma_destroy_qp(eb82fc4ca8162189)., |
| 74 | |
| 75 | .create_srq = pvrdma_create_srqcxx . . $ pvrdma_create_srq(3dc65caab49aca79)., |
| 76 | .modify_srq = pvrdma_modify_srqcxx . . $ pvrdma_modify_srq(1d3011637b3fbc3d)., |
| 77 | .query_srq = pvrdma_query_srqcxx . . $ pvrdma_query_srq(1676901f1962ceff)., |
| 78 | .destroy_srq = pvrdma_destroy_srqcxx . . $ pvrdma_destroy_srq(b5464b69af41f18d)., |
| 79 | .post_srq_recv = pvrdma_post_srq_recvcxx . . $ pvrdma_post_srq_recv(972af4c2ff8c1d8f)., |
| 80 | |
| 81 | .post_send = pvrdma_post_sendcxx . . $ pvrdma_post_send(524541c024c974a4)., |
| 82 | .post_recv = pvrdma_post_recvcxx . . $ pvrdma_post_recv(f21c02c428e4a8d5)., |
| 83 | .create_ah = pvrdma_create_ahcxx . . $ pvrdma_create_ah(d8ebc3eb89debaba)., |
| 84 | .destroy_ah = pvrdma_destroy_ahcxx . . $ pvrdma_destroy_ah(f0aba3fc303d55c9)., |
| 85 | }; |
| 86 | |
| 87 | int pvrdma_alloc_bufcxx . . $ pvrdma_alloc_buf(c0fb98a7867c47a).(struct pvrdma_bufcxx . . $ pvrdma_buf# *buf, size_t size, int page_size) |
| 88 | { |
| 89 | int ret; |
| 90 | |
| 91 | buf->lengthcxx . . $ pvrdma_buf#length. = aligncxx . . $ align(80bad76eed2d2579).(size, page_size); |
| 92 | buf->bufcxx . . $ pvrdma_buf#buf. = mmapcxx . . $ mmap(ff06c1c904cdf0e2).(NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, buf->lengthcxx . . $ pvrdma_buf#length., PROT_READcxx . . $ `<external>/17226767460805440860/mman-linux.h:32:9`! | PROT_WRITEcxx . . $ `<external>/17226767460805440860/mman-linux.h:33:9`!, |
| 93 | MAP_PRIVATEcxx . . $ `<external>/17226767460805440860/mman-linux.h:43:9`! | MAP_ANONYMOUScxx . . $ `<external>/17226767460805440860/mman-linux.h:55:10`!, -1, 0); |
| 94 | if (buf->bufcxx . . $ pvrdma_buf#buf. == MAP_FAILEDcxx . . $ `<external>/6724834311684550606/mman.h:44:9`!) |
| 95 | return errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!; |
| 96 | |
| 97 | ret = ibv_dontfork_rangecxx . . $ ibv_dontfork_range(c0a5f96701d3f89).(buf->bufcxx . . $ pvrdma_buf#buf., size); |
| 98 | if (ret) |
| 99 | munmapcxx . . $ munmap(c0a5f96701d3f89).(buf->bufcxx . . $ pvrdma_buf#buf., buf->lengthcxx . . $ pvrdma_buf#length.); |
| 100 | |
| 101 | return ret; |
| 102 | } |
| 103 | |
| 104 | void pvrdma_free_bufcxx . . $ pvrdma_free_buf(e61cdbd67054e6ad).(struct pvrdma_bufcxx . . $ pvrdma_buf# *buf) |
| 105 | { |
| 106 | ibv_dofork_rangecxx . . $ ibv_dofork_range(c0a5f96701d3f89).(buf->bufcxx . . $ pvrdma_buf#buf., buf->lengthcxx . . $ pvrdma_buf#length.); |
| 107 | munmapcxx . . $ munmap(c0a5f96701d3f89).(buf->bufcxx . . $ pvrdma_buf#buf., buf->lengthcxx . . $ pvrdma_buf#length.); |
| 108 | } |
| 109 | |
| 110 | static int pvrdma_init_context_sharedcxx . . $ pvrdma_init_context_shared(28417d886d734a46).(struct pvrdma_contextcxx . . $ pvrdma_context# *context, |
| 111 | struct ibv_devicecxx . . $ ibv_device# *ibdev, |
| 112 | int cmd_fd) |
| 113 | { |
| 114 | struct ibv_get_contextcxx . . $ ibv_get_context# cmd; |
| 115 | struct user_pvrdma_alloc_ucontext_respcxx . . $ user_pvrdma_alloc_ucontext_resp# resp = {}; |
| 116 | |
| 117 | context->ibv_ctxcxx . . $ pvrdma_context#ibv_ctx..contextcxx . . $ verbs_context#context..cmd_fdcxx . . $ ibv_context#cmd_fd. = cmd_fd; |
| 118 | if (ibv_cmd_get_contextcxx . . $ ibv_cmd_get_context(6195f5b43dd86318).(&context->ibv_ctxcxx . . $ pvrdma_context#ibv_ctx., &cmd, sizeof(cmd), |
| 119 | NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, &resp.ibv_respcxx . . $ user_pvrdma_alloc_ucontext_resp#ibv_resp., sizeof(resp))) |
| 120 | return errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!; |
| 121 | |
| 122 | context->qp_tblcxx . . $ pvrdma_context#qp_tbl. = calloccxx . . $ calloc(63a7bf2941bfcd7a).(resp.qp_tab_sizecxx . . $ user_pvrdma_alloc_ucontext_resp#$anonymous_type_18#$anonymous_type_19#qp_tab_size. & 0xFFFF, |
| 123 | sizeof(struct pvrdma_qpcxx . . $ pvrdma_qp# *)); |
| 124 | if (!context->qp_tblcxx . . $ pvrdma_context#qp_tbl.) |
| 125 | return -ENOMEMcxx . . $ `<external>/8987895939074593727/errno-base.h:16:9`!; |
| 126 | |
| 127 | context->uarcxx . . $ pvrdma_context#uar. = mmapcxx . . $ mmap(ff06c1c904cdf0e2).(NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, to_vdevcxx . . $ to_vdev(558c0ed9fb116a23).(ibdev)->page_sizecxx . . $ pvrdma_device#page_size., PROT_WRITEcxx . . $ `<external>/17226767460805440860/mman-linux.h:33:9`!, |
| 128 | MAP_SHAREDcxx . . $ `<external>/17226767460805440860/mman-linux.h:42:9`!, cmd_fd, 0); |
| 129 | if (context->uarcxx . . $ pvrdma_context#uar. == MAP_FAILEDcxx . . $ `<external>/6724834311684550606/mman.h:44:9`!) { |
| 130 | freecxx . . $ free(5d22bdacc48458e8).(context->qp_tblcxx . . $ pvrdma_context#qp_tbl.); |
| 131 | return errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!; |
| 132 | } |
| 133 | |
| 134 | pthread_spin_initcxx . . $ pthread_spin_init(e19f4c5c20dbfed5).(&context->uar_lockcxx . . $ pvrdma_context#uar_lock., PTHREAD_PROCESS_PRIVATEcxx . . $ `<external>/14712363683955484316/pthread.h:147:9`!); |
| 135 | |
| 136 | verbs_set_opscxx . . $ verbs_set_ops(15576e233c1422c2).(&context->ibv_ctxcxx . . $ pvrdma_context#ibv_ctx., &pvrdma_ctx_opscxx . . $ pvrdma_ctx_ops.); |
| 137 | |
| 138 | return 0; |
| 139 | } |
| 140 | |
| 141 | static void pvrdma_free_context_sharedcxx . . $ pvrdma_free_context_shared(dbd5fa7f5c8f6b54).(struct pvrdma_contextcxx . . $ pvrdma_context# *context, |
| 142 | struct pvrdma_devicecxx . . $ pvrdma_device# *dev) |
| 143 | { |
| 144 | munmapcxx . . $ munmap(c0a5f96701d3f89).(context->uarcxx . . $ pvrdma_context#uar., dev->page_sizecxx . . $ pvrdma_device#page_size.); |
| 145 | freecxx . . $ free(5d22bdacc48458e8).(context->qp_tblcxx . . $ pvrdma_context#qp_tbl.); |
| 146 | } |
| 147 | |
| 148 | static struct verbs_contextcxx . . $ verbs_context# *pvrdma_alloc_contextcxx . . $ pvrdma_alloc_context(b7929b4a2f25b9b8).(struct ibv_devicecxx . . $ ibv_device# *ibdev, |
| 149 | int cmd_fd, |
| 150 | void *private_data) |
| 151 | { |
| 152 | struct pvrdma_contextcxx . . $ pvrdma_context# *context; |
| 153 | |
| 154 | context = verbs_init_and_alloc_contextcxx . . $ `libibverbs/driver.h:523:9`!(ibdev, cmd_fd, context, ibv_ctx, |
| 155 | RDMA_DRIVER_VMW_PVRDMA); |
| 156 | if (!context) |
| 157 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 158 | |
| 159 | if (pvrdma_init_context_sharedcxx . . $ pvrdma_init_context_shared(28417d886d734a46).(context, ibdev, cmd_fd)) { |
| 160 | verbs_uninit_contextcxx . . $ verbs_uninit_context(f00f969726d2d9a7).(&context->ibv_ctxcxx . . $ pvrdma_context#ibv_ctx.); |
| 161 | freecxx . . $ free(5d22bdacc48458e8).(context); |
| 162 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 163 | } |
| 164 | |
| 165 | return &context->ibv_ctxcxx . . $ pvrdma_context#ibv_ctx.; |
| 166 | } |
| 167 | |
| 168 | static void pvrdma_free_contextcxx . . $ pvrdma_free_context(571ef9bd68226534).(struct ibv_contextcxx . . $ ibv_context# *ibctx) |
| 169 | { |
| 170 | struct pvrdma_contextcxx . . $ pvrdma_context# *context = to_vctxcxx . . $ to_vctx(1f5e75ddebf1e3e).(ibctx); |
| 171 | |
| 172 | pvrdma_free_context_sharedcxx . . $ pvrdma_free_context_shared(dbd5fa7f5c8f6b54).(context, to_vdevcxx . . $ to_vdev(558c0ed9fb116a23).(ibctx->devicecxx . . $ ibv_context#device.)); |
| 173 | verbs_uninit_contextcxx . . $ verbs_uninit_context(f00f969726d2d9a7).(&context->ibv_ctxcxx . . $ pvrdma_context#ibv_ctx.); |
| 174 | freecxx . . $ free(5d22bdacc48458e8).(context); |
| 175 | } |
| 176 | |
| 177 | static void pvrdma_uninit_devicecxx . . $ pvrdma_uninit_device(6559a60bb3ac7ccd).(struct verbs_devicecxx . . $ verbs_device# *verbs_device) |
| 178 | { |
| 179 | struct pvrdma_devicecxx . . $ pvrdma_device# *dev = to_vdevcxx . . $ to_vdev(558c0ed9fb116a23).(&verbs_device->devicecxx . . $ verbs_device#device.); |
| 180 | |
| 181 | freecxx . . $ free(5d22bdacc48458e8).(dev); |
| 182 | } |
| 183 | |
| 184 | static struct verbs_devicecxx . . $ verbs_device# * |
| 185 | pvrdma_device_alloccxx . . $ pvrdma_device_alloc(3483df0af66d2425).(struct verbs_sysfs_devcxx . . $ verbs_sysfs_dev# *sysfs_dev) |
| 186 | { |
| 187 | struct pvrdma_devicecxx . . $ pvrdma_device# *dev; |
| 188 | |
| 189 | dev = calloccxx . . $ calloc(63a7bf2941bfcd7a).(1, sizeof(*dev)); |
| 190 | if (!dev) |
| 191 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 192 | |
| 193 | dev->abi_versioncxx . . $ pvrdma_device#abi_version. = sysfs_dev->abi_vercxx . . $ verbs_sysfs_dev#abi_ver.; |
| 194 | dev->page_sizecxx . . $ pvrdma_device#page_size. = sysconfcxx . . $ sysconf(dc1f09c09fbff20f).(_SC_PAGESIZEcxx . . $ `<external>/6393649343499073842/confname.h:134:9`!); |
| 195 | |
| 196 | return &dev->ibv_devcxx . . $ pvrdma_device#ibv_dev.; |
| 197 | } |
| 198 | |
| 199 | static const struct verbs_match_entcxx . . $ verbs_match_ent# hca_tablecxx . . $ hca_table.[] = { |
| 200 | VERBS_DRIVER_IDcxx . . $ `libibverbs/driver.h:235:9`!(RDMA_DRIVER_VMW_PVRDMA), |
| 201 | VERBS_PCI_MATCHcxx . . $ `libibverbs/driver.h:242:9`!(PCI_VENDOR_ID_VMWAREcxx . . $ `providers/vmw_pvrdma/pvrdma_main.c:53:9`!, PCI_DEVICE_ID_VMWARE_PVRDMAcxx . . $ `providers/vmw_pvrdma/pvrdma_main.c:54:9`!, |
| 202 | NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!), |
| 203 | {} |
| 204 | }; |
| 205 | |
| 206 | static const struct verbs_device_opscxx . . $ verbs_device_ops# pvrdma_dev_opscxx . . $ pvrdma_dev_ops. = { |
| 207 | .name = "pvrdma", |
| 208 | .match_min_abi_version = PVRDMA_UVERBS_ABI_VERSIONcxx . . $ `kernel-headers/rdma/vmw_pvrdma-abi.h:52:9`!, |
| 209 | .match_max_abi_version = PVRDMA_UVERBS_ABI_VERSIONcxx . . $ `kernel-headers/rdma/vmw_pvrdma-abi.h:52:9`!, |
| 210 | .match_table = hca_tablecxx . . $ hca_table., |
| 211 | .alloc_device = pvrdma_device_alloccxx . . $ pvrdma_device_alloc(3483df0af66d2425)., |
| 212 | .uninit_device = pvrdma_uninit_devicecxx . . $ pvrdma_uninit_device(6559a60bb3ac7ccd)., |
| 213 | .alloc_context = pvrdma_alloc_contextcxx . . $ pvrdma_alloc_context(b7929b4a2f25b9b8)., |
| 214 | }; |
| 215 | PROVIDER_DRIVERcxx . . $ `libibverbs/driver.h:510:9`!(vmw_pvrdma, pvrdma_dev_ops); |