]> git.proxmox.com Git - ceph.git/blob - ceph/src/spdk/lib/nvme/nvme_transport.c
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / spdk / lib / nvme / nvme_transport.c
1 /*-
2 * BSD LICENSE
3 *
4 * Copyright (c) Intel Corporation.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
16 * distribution.
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34 /*
35 * NVMe transport abstraction
36 */
37
38 #include "nvme_internal.h"
39
40 #ifdef DEBUG
41 static __attribute__((noreturn)) void
42 nvme_transport_unknown(enum spdk_nvme_transport_type trtype)
43 {
44 SPDK_ERRLOG("Unknown transport %d\n", (int)trtype);
45 abort();
46 }
47 #define TRANSPORT_DEFAULT(trtype) default: nvme_transport_unknown(trtype);
48 #else
49 #define TRANSPORT_DEFAULT(trtype)
50 #endif
51
52 #define TRANSPORT_PCIE(func_name, args) case SPDK_NVME_TRANSPORT_PCIE: return nvme_pcie_ ## func_name args;
53 #ifdef SPDK_CONFIG_RDMA
54 #define TRANSPORT_FABRICS_RDMA(func_name, args) case SPDK_NVME_TRANSPORT_RDMA: return nvme_rdma_ ## func_name args;
55 #define TRANSPORT_RDMA_AVAILABLE true
56 #else
57 #define TRANSPORT_FABRICS_RDMA(func_name, args) case SPDK_NVME_TRANSPORT_RDMA: SPDK_UNREACHABLE();
58 #define TRANSPORT_RDMA_AVAILABLE false
59 #endif
60 #define NVME_TRANSPORT_CALL(trtype, func_name, args) \
61 do { \
62 switch (trtype) { \
63 TRANSPORT_PCIE(func_name, args) \
64 TRANSPORT_FABRICS_RDMA(func_name, args) \
65 TRANSPORT_DEFAULT(trtype) \
66 } \
67 SPDK_UNREACHABLE(); \
68 } while (0)
69
70 bool
71 spdk_nvme_transport_available(enum spdk_nvme_transport_type trtype)
72 {
73 switch (trtype) {
74 case SPDK_NVME_TRANSPORT_PCIE:
75 return true;
76
77 case SPDK_NVME_TRANSPORT_RDMA:
78 return TRANSPORT_RDMA_AVAILABLE;
79 }
80
81 return false;
82 }
83
84 struct spdk_nvme_ctrlr *nvme_transport_ctrlr_construct(const struct spdk_nvme_transport_id *trid,
85 const struct spdk_nvme_ctrlr_opts *opts,
86 void *devhandle)
87 {
88 NVME_TRANSPORT_CALL(trid->trtype, ctrlr_construct, (trid, opts, devhandle));
89 }
90
91 int
92 nvme_transport_ctrlr_scan(const struct spdk_nvme_transport_id *trid,
93 void *cb_ctx,
94 spdk_nvme_probe_cb probe_cb,
95 spdk_nvme_remove_cb remove_cb)
96 {
97 NVME_TRANSPORT_CALL(trid->trtype, ctrlr_scan, (trid, cb_ctx, probe_cb, remove_cb));
98 }
99
100 int
101 nvme_transport_ctrlr_destruct(struct spdk_nvme_ctrlr *ctrlr)
102 {
103 NVME_TRANSPORT_CALL(ctrlr->trid.trtype, ctrlr_destruct, (ctrlr));
104 }
105
106 int
107 nvme_transport_ctrlr_enable(struct spdk_nvme_ctrlr *ctrlr)
108 {
109 NVME_TRANSPORT_CALL(ctrlr->trid.trtype, ctrlr_enable, (ctrlr));
110 }
111
112 int
113 nvme_transport_ctrlr_set_reg_4(struct spdk_nvme_ctrlr *ctrlr, uint32_t offset, uint32_t value)
114 {
115 NVME_TRANSPORT_CALL(ctrlr->trid.trtype, ctrlr_set_reg_4, (ctrlr, offset, value));
116 }
117
118 int
119 nvme_transport_ctrlr_set_reg_8(struct spdk_nvme_ctrlr *ctrlr, uint32_t offset, uint64_t value)
120 {
121 NVME_TRANSPORT_CALL(ctrlr->trid.trtype, ctrlr_set_reg_8, (ctrlr, offset, value));
122 }
123
124 int
125 nvme_transport_ctrlr_get_reg_4(struct spdk_nvme_ctrlr *ctrlr, uint32_t offset, uint32_t *value)
126 {
127 NVME_TRANSPORT_CALL(ctrlr->trid.trtype, ctrlr_get_reg_4, (ctrlr, offset, value));
128 }
129
130 int
131 nvme_transport_ctrlr_get_reg_8(struct spdk_nvme_ctrlr *ctrlr, uint32_t offset, uint64_t *value)
132 {
133 NVME_TRANSPORT_CALL(ctrlr->trid.trtype, ctrlr_get_reg_8, (ctrlr, offset, value));
134 }
135
136 uint32_t
137 nvme_transport_ctrlr_get_max_xfer_size(struct spdk_nvme_ctrlr *ctrlr)
138 {
139 NVME_TRANSPORT_CALL(ctrlr->trid.trtype, ctrlr_get_max_xfer_size, (ctrlr));
140 }
141
142 uint32_t
143 nvme_transport_ctrlr_get_max_io_queue_size(struct spdk_nvme_ctrlr *ctrlr)
144 {
145 NVME_TRANSPORT_CALL(ctrlr->trid.trtype, ctrlr_get_max_io_queue_size, (ctrlr));
146 }
147
148 struct spdk_nvme_qpair *
149 nvme_transport_ctrlr_create_io_qpair(struct spdk_nvme_ctrlr *ctrlr, uint16_t qid,
150 enum spdk_nvme_qprio qprio)
151 {
152 NVME_TRANSPORT_CALL(ctrlr->trid.trtype, ctrlr_create_io_qpair, (ctrlr, qid, qprio));
153 }
154
155 int
156 nvme_transport_ctrlr_delete_io_qpair(struct spdk_nvme_ctrlr *ctrlr, struct spdk_nvme_qpair *qpair)
157 {
158 NVME_TRANSPORT_CALL(ctrlr->trid.trtype, ctrlr_delete_io_qpair, (ctrlr, qpair));
159 }
160
161 int
162 nvme_transport_ctrlr_reinit_io_qpair(struct spdk_nvme_ctrlr *ctrlr, struct spdk_nvme_qpair *qpair)
163 {
164 NVME_TRANSPORT_CALL(ctrlr->trid.trtype, ctrlr_reinit_io_qpair, (ctrlr, qpair));
165 }
166
167 int
168 nvme_transport_qpair_enable(struct spdk_nvme_qpair *qpair)
169 {
170 NVME_TRANSPORT_CALL(qpair->trtype, qpair_enable, (qpair));
171 }
172
173 int
174 nvme_transport_qpair_disable(struct spdk_nvme_qpair *qpair)
175 {
176 NVME_TRANSPORT_CALL(qpair->trtype, qpair_disable, (qpair));
177 }
178
179 int
180 nvme_transport_qpair_reset(struct spdk_nvme_qpair *qpair)
181 {
182 NVME_TRANSPORT_CALL(qpair->trtype, qpair_reset, (qpair));
183 }
184
185 int
186 nvme_transport_qpair_fail(struct spdk_nvme_qpair *qpair)
187 {
188 NVME_TRANSPORT_CALL(qpair->trtype, qpair_fail, (qpair));
189 }
190
191 int
192 nvme_transport_qpair_submit_request(struct spdk_nvme_qpair *qpair, struct nvme_request *req)
193 {
194 NVME_TRANSPORT_CALL(qpair->trtype, qpair_submit_request, (qpair, req));
195 }
196
197 int32_t
198 nvme_transport_qpair_process_completions(struct spdk_nvme_qpair *qpair, uint32_t max_completions)
199 {
200 NVME_TRANSPORT_CALL(qpair->trtype, qpair_process_completions, (qpair, max_completions));
201 }