]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
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; | |
9f95a23c TL |
53 | |
54 | #define TRANSPORT_FABRICS_TCP(func_name, args) case SPDK_NVME_TRANSPORT_TCP: return nvme_tcp_ ## func_name args; | |
55 | ||
7c673cae FG |
56 | #ifdef SPDK_CONFIG_RDMA |
57 | #define TRANSPORT_FABRICS_RDMA(func_name, args) case SPDK_NVME_TRANSPORT_RDMA: return nvme_rdma_ ## func_name args; | |
58 | #define TRANSPORT_RDMA_AVAILABLE true | |
59 | #else | |
60 | #define TRANSPORT_FABRICS_RDMA(func_name, args) case SPDK_NVME_TRANSPORT_RDMA: SPDK_UNREACHABLE(); | |
61 | #define TRANSPORT_RDMA_AVAILABLE false | |
62 | #endif | |
11fdf7f2 | 63 | #define TRANSPORT_FABRICS_FC(func_name, args) case SPDK_NVME_TRANSPORT_FC: SPDK_UNREACHABLE(); |
9f95a23c | 64 | |
11fdf7f2 | 65 | #define NVME_TRANSPORT_CALL(trtype, func_name, args) \ |
7c673cae FG |
66 | do { \ |
67 | switch (trtype) { \ | |
68 | TRANSPORT_PCIE(func_name, args) \ | |
69 | TRANSPORT_FABRICS_RDMA(func_name, args) \ | |
11fdf7f2 | 70 | TRANSPORT_FABRICS_FC(func_name, args) \ |
9f95a23c | 71 | TRANSPORT_FABRICS_TCP(func_name, args) \ |
7c673cae FG |
72 | TRANSPORT_DEFAULT(trtype) \ |
73 | } \ | |
74 | SPDK_UNREACHABLE(); \ | |
75 | } while (0) | |
76 | ||
77 | bool | |
78 | spdk_nvme_transport_available(enum spdk_nvme_transport_type trtype) | |
79 | { | |
80 | switch (trtype) { | |
81 | case SPDK_NVME_TRANSPORT_PCIE: | |
9f95a23c | 82 | case SPDK_NVME_TRANSPORT_TCP: |
7c673cae FG |
83 | return true; |
84 | ||
85 | case SPDK_NVME_TRANSPORT_RDMA: | |
86 | return TRANSPORT_RDMA_AVAILABLE; | |
11fdf7f2 TL |
87 | |
88 | case SPDK_NVME_TRANSPORT_FC: | |
89 | return false; | |
7c673cae FG |
90 | } |
91 | ||
92 | return false; | |
93 | } | |
94 | ||
95 | struct spdk_nvme_ctrlr *nvme_transport_ctrlr_construct(const struct spdk_nvme_transport_id *trid, | |
96 | const struct spdk_nvme_ctrlr_opts *opts, | |
97 | void *devhandle) | |
98 | { | |
99 | NVME_TRANSPORT_CALL(trid->trtype, ctrlr_construct, (trid, opts, devhandle)); | |
100 | } | |
101 | ||
102 | int | |
9f95a23c | 103 | nvme_transport_ctrlr_scan(struct spdk_nvme_probe_ctx *probe_ctx, |
11fdf7f2 | 104 | bool direct_connect) |
7c673cae | 105 | { |
9f95a23c | 106 | NVME_TRANSPORT_CALL(probe_ctx->trid.trtype, ctrlr_scan, (probe_ctx, direct_connect)); |
7c673cae FG |
107 | } |
108 | ||
109 | int | |
110 | nvme_transport_ctrlr_destruct(struct spdk_nvme_ctrlr *ctrlr) | |
111 | { | |
112 | NVME_TRANSPORT_CALL(ctrlr->trid.trtype, ctrlr_destruct, (ctrlr)); | |
113 | } | |
114 | ||
115 | int | |
116 | nvme_transport_ctrlr_enable(struct spdk_nvme_ctrlr *ctrlr) | |
117 | { | |
118 | NVME_TRANSPORT_CALL(ctrlr->trid.trtype, ctrlr_enable, (ctrlr)); | |
119 | } | |
120 | ||
121 | int | |
122 | nvme_transport_ctrlr_set_reg_4(struct spdk_nvme_ctrlr *ctrlr, uint32_t offset, uint32_t value) | |
123 | { | |
124 | NVME_TRANSPORT_CALL(ctrlr->trid.trtype, ctrlr_set_reg_4, (ctrlr, offset, value)); | |
125 | } | |
126 | ||
127 | int | |
128 | nvme_transport_ctrlr_set_reg_8(struct spdk_nvme_ctrlr *ctrlr, uint32_t offset, uint64_t value) | |
129 | { | |
130 | NVME_TRANSPORT_CALL(ctrlr->trid.trtype, ctrlr_set_reg_8, (ctrlr, offset, value)); | |
131 | } | |
132 | ||
133 | int | |
134 | nvme_transport_ctrlr_get_reg_4(struct spdk_nvme_ctrlr *ctrlr, uint32_t offset, uint32_t *value) | |
135 | { | |
136 | NVME_TRANSPORT_CALL(ctrlr->trid.trtype, ctrlr_get_reg_4, (ctrlr, offset, value)); | |
137 | } | |
138 | ||
139 | int | |
140 | nvme_transport_ctrlr_get_reg_8(struct spdk_nvme_ctrlr *ctrlr, uint32_t offset, uint64_t *value) | |
141 | { | |
142 | NVME_TRANSPORT_CALL(ctrlr->trid.trtype, ctrlr_get_reg_8, (ctrlr, offset, value)); | |
143 | } | |
144 | ||
145 | uint32_t | |
146 | nvme_transport_ctrlr_get_max_xfer_size(struct spdk_nvme_ctrlr *ctrlr) | |
147 | { | |
148 | NVME_TRANSPORT_CALL(ctrlr->trid.trtype, ctrlr_get_max_xfer_size, (ctrlr)); | |
149 | } | |
150 | ||
11fdf7f2 TL |
151 | uint16_t |
152 | nvme_transport_ctrlr_get_max_sges(struct spdk_nvme_ctrlr *ctrlr) | |
153 | { | |
154 | NVME_TRANSPORT_CALL(ctrlr->trid.trtype, ctrlr_get_max_sges, (ctrlr)); | |
155 | } | |
156 | ||
157 | void * | |
158 | nvme_transport_ctrlr_alloc_cmb_io_buffer(struct spdk_nvme_ctrlr *ctrlr, size_t size) | |
159 | { | |
160 | NVME_TRANSPORT_CALL(ctrlr->trid.trtype, ctrlr_alloc_cmb_io_buffer, (ctrlr, size)); | |
161 | } | |
162 | ||
163 | int | |
164 | nvme_transport_ctrlr_free_cmb_io_buffer(struct spdk_nvme_ctrlr *ctrlr, void *buf, size_t size) | |
7c673cae | 165 | { |
11fdf7f2 | 166 | NVME_TRANSPORT_CALL(ctrlr->trid.trtype, ctrlr_free_cmb_io_buffer, (ctrlr, buf, size)); |
7c673cae FG |
167 | } |
168 | ||
169 | struct spdk_nvme_qpair * | |
170 | nvme_transport_ctrlr_create_io_qpair(struct spdk_nvme_ctrlr *ctrlr, uint16_t qid, | |
11fdf7f2 | 171 | const struct spdk_nvme_io_qpair_opts *opts) |
7c673cae | 172 | { |
11fdf7f2 | 173 | NVME_TRANSPORT_CALL(ctrlr->trid.trtype, ctrlr_create_io_qpair, (ctrlr, qid, opts)); |
7c673cae FG |
174 | } |
175 | ||
176 | int | |
177 | nvme_transport_ctrlr_delete_io_qpair(struct spdk_nvme_ctrlr *ctrlr, struct spdk_nvme_qpair *qpair) | |
178 | { | |
179 | NVME_TRANSPORT_CALL(ctrlr->trid.trtype, ctrlr_delete_io_qpair, (ctrlr, qpair)); | |
180 | } | |
181 | ||
182 | int | |
9f95a23c | 183 | nvme_transport_ctrlr_connect_qpair(struct spdk_nvme_ctrlr *ctrlr, struct spdk_nvme_qpair *qpair) |
7c673cae | 184 | { |
9f95a23c TL |
185 | if (nvme_qpair_is_admin_queue(qpair)) { |
186 | qpair->is_connecting = 1; | |
187 | } | |
188 | NVME_TRANSPORT_CALL(ctrlr->trid.trtype, ctrlr_connect_qpair, (ctrlr, qpair)); | |
189 | if (nvme_qpair_is_admin_queue(qpair)) { | |
190 | qpair->is_connecting = 0; | |
191 | } | |
7c673cae FG |
192 | } |
193 | ||
9f95a23c TL |
194 | volatile struct spdk_nvme_registers * |
195 | nvme_transport_ctrlr_get_registers(struct spdk_nvme_ctrlr *ctrlr) | |
7c673cae | 196 | { |
9f95a23c | 197 | NVME_TRANSPORT_CALL(ctrlr->trid.trtype, ctrlr_get_registers, (ctrlr)); |
7c673cae FG |
198 | } |
199 | ||
9f95a23c TL |
200 | void |
201 | nvme_transport_ctrlr_disconnect_qpair(struct spdk_nvme_ctrlr *ctrlr, struct spdk_nvme_qpair *qpair) | |
7c673cae | 202 | { |
9f95a23c | 203 | NVME_TRANSPORT_CALL(ctrlr->trid.trtype, ctrlr_disconnect_qpair, (ctrlr, qpair)); |
7c673cae FG |
204 | } |
205 | ||
9f95a23c TL |
206 | void |
207 | nvme_transport_qpair_abort_reqs(struct spdk_nvme_qpair *qpair, uint32_t dnr) | |
7c673cae | 208 | { |
9f95a23c TL |
209 | assert(dnr <= 1); |
210 | NVME_TRANSPORT_CALL(qpair->trtype, qpair_abort_reqs, (qpair, dnr)); | |
7c673cae FG |
211 | } |
212 | ||
213 | int | |
9f95a23c | 214 | nvme_transport_qpair_reset(struct spdk_nvme_qpair *qpair) |
7c673cae | 215 | { |
9f95a23c | 216 | NVME_TRANSPORT_CALL(qpair->trtype, qpair_reset, (qpair)); |
7c673cae FG |
217 | } |
218 | ||
219 | int | |
220 | nvme_transport_qpair_submit_request(struct spdk_nvme_qpair *qpair, struct nvme_request *req) | |
221 | { | |
222 | NVME_TRANSPORT_CALL(qpair->trtype, qpair_submit_request, (qpair, req)); | |
223 | } | |
224 | ||
225 | int32_t | |
226 | nvme_transport_qpair_process_completions(struct spdk_nvme_qpair *qpair, uint32_t max_completions) | |
227 | { | |
228 | NVME_TRANSPORT_CALL(qpair->trtype, qpair_process_completions, (qpair, max_completions)); | |
229 | } | |
9f95a23c TL |
230 | |
231 | void | |
232 | nvme_transport_admin_qpair_abort_aers(struct spdk_nvme_qpair *qpair) | |
233 | { | |
234 | NVME_TRANSPORT_CALL(qpair->trtype, admin_qpair_abort_aers, (qpair)); | |
235 | } |