1 /*- 2 * BSD LICENSE 3 * 4 * Copyright (c) Intel Corporation. 5 * All rights reserved. 6 * Copyright (c) 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 12 * * Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * * Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in 16 * the documentation and/or other materials provided with the 17 * distribution. 18 * * Neither the name of Intel Corporation nor the names of its 19 * contributors may be used to endorse or promote products derived 20 * from this software without specific prior written permission. 21 * 22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 25 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 26 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 28 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 32 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 */ 34 #include "common/lib/test_env.c" 35 36 const char * 37 spdk_nvme_transport_id_trtype_str(enum spdk_nvme_transport_type trtype) 38 { 39 switch (trtype) { 40 case SPDK_NVME_TRANSPORT_PCIE: 41 return "PCIe"; 42 case SPDK_NVME_TRANSPORT_RDMA: 43 return "RDMA"; 44 case SPDK_NVME_TRANSPORT_FC: 45 return "FC"; 46 default: 47 return NULL; 48 } 49 } 50 51 int 52 spdk_nvme_transport_id_populate_trstring(struct spdk_nvme_transport_id *trid, const char *trstring) 53 { 54 int len, i; 55 56 if (trstring == NULL) { 57 return -EINVAL; 58 } 59 60 len = strnlen(trstring, SPDK_NVMF_TRSTRING_MAX_LEN); 61 if (len == SPDK_NVMF_TRSTRING_MAX_LEN) { 62 return -EINVAL; 63 } 64 65 /* cast official trstring to uppercase version of input. */ 66 for (i = 0; i < len; i++) { 67 trid->trstring[i] = toupper(trstring[i]); 68 } 69 return 0; 70 } 71 72 DEFINE_STUB(nvme_request_check_timeout, int, (struct nvme_request *req, uint16_t cid, 73 struct spdk_nvme_ctrlr_process *active_proc, uint64_t now_tick), 0); 74 DEFINE_STUB_V(nvme_ctrlr_destruct_finish, (struct spdk_nvme_ctrlr *ctrlr)); 75 DEFINE_STUB(nvme_ctrlr_construct, int, (struct spdk_nvme_ctrlr *ctrlr), 0); 76 DEFINE_STUB_V(nvme_ctrlr_destruct, (struct spdk_nvme_ctrlr *ctrlr)); 77 DEFINE_STUB(nvme_ctrlr_get_vs, int, (struct spdk_nvme_ctrlr *ctrlr, 78 union spdk_nvme_vs_register *vs), 0); 79 DEFINE_STUB(nvme_ctrlr_get_cap, int, (struct spdk_nvme_ctrlr *ctrlr, 80 union spdk_nvme_cap_register *cap), 0); 81 DEFINE_STUB_V(nvme_qpair_deinit, (struct spdk_nvme_qpair *qpair)); 82 DEFINE_STUB_V(spdk_nvme_transport_register, (const struct spdk_nvme_transport_ops *ops)); 83 DEFINE_STUB(nvme_transport_ctrlr_connect_qpair, int, (struct spdk_nvme_ctrlr *ctrlr, 84 struct spdk_nvme_qpair *qpair), 0); 85 DEFINE_STUB_V(nvme_transport_ctrlr_disconnect_qpair_done, (struct spdk_nvme_qpair *qpair)); 86 DEFINE_STUB(nvme_ctrlr_get_current_process, struct spdk_nvme_ctrlr_process *, 87 (struct spdk_nvme_ctrlr *ctrlr), (struct spdk_nvme_ctrlr_process *)(uintptr_t)0x1); 88 DEFINE_STUB(nvme_ctrlr_add_process, int, (struct spdk_nvme_ctrlr *ctrlr, void *devhandle), 0); 89 DEFINE_STUB_V(spdk_nvme_trid_populate_transport, (struct spdk_nvme_transport_id *trid, 90 enum spdk_nvme_transport_type trtype)); 91 DEFINE_STUB(nvme_get_transport, const struct spdk_nvme_transport *, (const char *transport_name), 92 NULL); 93 DEFINE_STUB(spdk_nvme_qpair_process_completions, int32_t, (struct spdk_nvme_qpair *qpair, 94 uint32_t max_completions), 0); 95 96 /* Fabric transports only */ 97 DEFINE_STUB_V(nvme_ctrlr_disconnect_qpair, (struct spdk_nvme_qpair *qpair)); 98 DEFINE_STUB(nvme_fabric_ctrlr_set_reg_4, int, (struct spdk_nvme_ctrlr *ctrlr, uint32_t offset, 99 uint32_t value), 0); 100 DEFINE_STUB(nvme_fabric_ctrlr_set_reg_8, int, (struct spdk_nvme_ctrlr *ctrlr, uint32_t offset, 101 uint64_t value), 0); 102 DEFINE_STUB(nvme_fabric_ctrlr_get_reg_4, int, (struct spdk_nvme_ctrlr *ctrlr, uint32_t offset, 103 uint32_t *value), 0); 104 DEFINE_STUB(nvme_fabric_ctrlr_get_reg_8, int, (struct spdk_nvme_ctrlr *ctrlr, uint32_t offset, 105 uint64_t *value), 0); 106 DEFINE_STUB(nvme_fabric_ctrlr_set_reg_4_async, int, (struct spdk_nvme_ctrlr *ctrlr, uint32_t offset, 107 uint32_t value, spdk_nvme_reg_cb cb, void *ctx), 0); 108 DEFINE_STUB(nvme_fabric_ctrlr_set_reg_8_async, int, (struct spdk_nvme_ctrlr *ctrlr, uint32_t offset, 109 uint64_t value, spdk_nvme_reg_cb cb, void *ctx), 0); 110 DEFINE_STUB(nvme_fabric_ctrlr_get_reg_4_async, int, (struct spdk_nvme_ctrlr *ctrlr, 111 uint32_t offset, spdk_nvme_reg_cb cb, void *ctx), 0); 112 DEFINE_STUB(nvme_fabric_ctrlr_get_reg_8_async, int, (struct spdk_nvme_ctrlr *ctrlr, 113 uint32_t offset, spdk_nvme_reg_cb cb, void *ctx), 0); 114 DEFINE_STUB(nvme_fabric_ctrlr_scan, int, (struct spdk_nvme_probe_ctx *probe_ctx, 115 bool direct_connect), 0); 116 DEFINE_STUB(nvme_fabric_qpair_connect, int, (struct spdk_nvme_qpair *qpair, uint32_t num_entries), 117 0); 118 DEFINE_STUB(nvme_fabric_qpair_connect_async, int, (struct spdk_nvme_qpair *qpair, 119 uint32_t num_entries), 0); 120 DEFINE_STUB(nvme_fabric_qpair_connect_poll, int, (struct spdk_nvme_qpair *qpair), 0); 121 DEFINE_STUB_V(nvme_transport_ctrlr_disconnect_qpair, (struct spdk_nvme_ctrlr *ctrlr, 122 struct spdk_nvme_qpair *qpair)); 123 DEFINE_STUB(nvme_poll_group_disconnect_qpair, int, (struct spdk_nvme_qpair *qpair), 0); 124 125 int 126 nvme_qpair_init(struct spdk_nvme_qpair *qpair, uint16_t id, 127 struct spdk_nvme_ctrlr *ctrlr, 128 enum spdk_nvme_qprio qprio, 129 uint32_t num_requests, bool async) 130 { 131 qpair->ctrlr = ctrlr; 132 qpair->id = id; 133 qpair->qprio = qprio; 134 qpair->async = async; 135 qpair->trtype = SPDK_NVME_TRANSPORT_TCP; 136 qpair->poll_group = (void *)0xDEADBEEF; 137 138 return 0; 139 } 140